OLD | NEW |
(Empty) | |
| 1 /****************************************************************************** |
| 2 ** This file is an amalgamation of many separate C source files from SQLite |
| 3 ** version 3.17.0. By combining all the individual C code files into this |
| 4 ** single large file, the entire code can be compiled as a single translation |
| 5 ** unit. This allows many compilers to do optimizations that would not be |
| 6 ** possible if the files were compiled separately. Performance improvements |
| 7 ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 ** translation unit. |
| 9 ** |
| 10 ** This file is all you need to compile SQLite. To use SQLite in other |
| 11 ** programs, you need this file and the "sqlite3.h" header file that defines |
| 12 ** the programming interface to the SQLite library. (If you do not have |
| 13 ** the "sqlite3.h" header file at hand, you will find a copy embedded within |
| 14 ** the text of this file. Search for "Begin file sqlite3.h" to find the start |
| 15 ** of the embedded sqlite3.h header file.) Additional code files may be needed |
| 16 ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 ** separate file. This file contains only code for the core SQLite library. |
| 19 */ |
| 20 #define SQLITE_CORE 1 |
| 21 #define SQLITE_AMALGAMATION 1 |
| 22 #ifndef SQLITE_PRIVATE |
| 23 # define SQLITE_PRIVATE static |
| 24 #endif |
| 25 /************** Begin file sqliteInt.h ***************************************/ |
| 26 /* |
| 27 ** 2001 September 15 |
| 28 ** |
| 29 ** The author disclaims copyright to this source code. In place of |
| 30 ** a legal notice, here is a blessing: |
| 31 ** |
| 32 ** May you do good and not evil. |
| 33 ** May you find forgiveness for yourself and forgive others. |
| 34 ** May you share freely, never taking more than you give. |
| 35 ** |
| 36 ************************************************************************* |
| 37 ** Internal interface definitions for SQLite. |
| 38 ** |
| 39 */ |
| 40 #ifndef SQLITEINT_H |
| 41 #define SQLITEINT_H |
| 42 |
| 43 /* Special Comments: |
| 44 ** |
| 45 ** Some comments have special meaning to the tools that measure test |
| 46 ** coverage: |
| 47 ** |
| 48 ** NO_TEST - The branches on this line are not |
| 49 ** measured by branch coverage. This is |
| 50 ** used on lines of code that actually |
| 51 ** implement parts of coverage testing. |
| 52 ** |
| 53 ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false |
| 54 ** and the correct answer is still obtained, |
| 55 ** though perhaps more slowly. |
| 56 ** |
| 57 ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true |
| 58 ** and the correct answer is still obtained, |
| 59 ** though perhaps more slowly. |
| 60 ** |
| 61 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread |
| 62 ** that would be harmless and undetectable |
| 63 ** if it did occur. |
| 64 ** |
| 65 ** In all cases, the special comment must be enclosed in the usual |
| 66 ** slash-asterisk...asterisk-slash comment marks, with no spaces between the |
| 67 ** asterisks and the comment text. |
| 68 */ |
| 69 |
| 70 /* |
| 71 ** Make sure the Tcl calling convention macro is defined. This macro is |
| 72 ** only used by test code and Tcl integration code. |
| 73 */ |
| 74 #ifndef SQLITE_TCLAPI |
| 75 # define SQLITE_TCLAPI |
| 76 #endif |
| 77 |
| 78 /* |
| 79 ** Make sure that rand_s() is available on Windows systems with MSVC 2005 |
| 80 ** or higher. |
| 81 */ |
| 82 #if defined(_MSC_VER) && _MSC_VER>=1400 |
| 83 /* TODO(shess): Already defined by build/config/win/BUILD.gn */ |
| 84 #ifndef _CRT_RAND_S |
| 85 # define _CRT_RAND_S |
| 86 #endif |
| 87 #endif |
| 88 |
| 89 /* |
| 90 ** Include the header file used to customize the compiler options for MSVC. |
| 91 ** This should be done first so that it can successfully prevent spurious |
| 92 ** compiler warnings due to subsequent content in this file and other files |
| 93 ** that are included by this file. |
| 94 */ |
| 95 /************** Include msvc.h in the middle of sqliteInt.h ******************/ |
| 96 /************** Begin file msvc.h ********************************************/ |
| 97 /* |
| 98 ** 2015 January 12 |
| 99 ** |
| 100 ** The author disclaims copyright to this source code. In place of |
| 101 ** a legal notice, here is a blessing: |
| 102 ** |
| 103 ** May you do good and not evil. |
| 104 ** May you find forgiveness for yourself and forgive others. |
| 105 ** May you share freely, never taking more than you give. |
| 106 ** |
| 107 ****************************************************************************** |
| 108 ** |
| 109 ** This file contains code that is specific to MSVC. |
| 110 */ |
| 111 #ifndef SQLITE_MSVC_H |
| 112 #define SQLITE_MSVC_H |
| 113 |
| 114 #if defined(_MSC_VER) |
| 115 #pragma warning(disable : 4054) |
| 116 #pragma warning(disable : 4055) |
| 117 #pragma warning(disable : 4100) |
| 118 #pragma warning(disable : 4127) |
| 119 #pragma warning(disable : 4130) |
| 120 #pragma warning(disable : 4152) |
| 121 #pragma warning(disable : 4189) |
| 122 #pragma warning(disable : 4206) |
| 123 #pragma warning(disable : 4210) |
| 124 #pragma warning(disable : 4232) |
| 125 #pragma warning(disable : 4244) |
| 126 #pragma warning(disable : 4305) |
| 127 #pragma warning(disable : 4306) |
| 128 #pragma warning(disable : 4702) |
| 129 #pragma warning(disable : 4706) |
| 130 #endif /* defined(_MSC_VER) */ |
| 131 |
| 132 #endif /* SQLITE_MSVC_H */ |
| 133 |
| 134 /************** End of msvc.h ************************************************/ |
| 135 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 136 |
| 137 /* |
| 138 ** Special setup for VxWorks |
| 139 */ |
| 140 /************** Include vxworks.h in the middle of sqliteInt.h ***************/ |
| 141 /************** Begin file vxworks.h *****************************************/ |
| 142 /* |
| 143 ** 2015-03-02 |
| 144 ** |
| 145 ** The author disclaims copyright to this source code. In place of |
| 146 ** a legal notice, here is a blessing: |
| 147 ** |
| 148 ** May you do good and not evil. |
| 149 ** May you find forgiveness for yourself and forgive others. |
| 150 ** May you share freely, never taking more than you give. |
| 151 ** |
| 152 ****************************************************************************** |
| 153 ** |
| 154 ** This file contains code that is specific to Wind River's VxWorks |
| 155 */ |
| 156 #if defined(__RTP__) || defined(_WRS_KERNEL) |
| 157 /* This is VxWorks. Set up things specially for that OS |
| 158 */ |
| 159 #include <vxWorks.h> |
| 160 #include <pthread.h> /* amalgamator: dontcache */ |
| 161 #define OS_VXWORKS 1 |
| 162 #define SQLITE_OS_OTHER 0 |
| 163 #define SQLITE_HOMEGROWN_RECURSIVE_MUTEX 1 |
| 164 #define SQLITE_OMIT_LOAD_EXTENSION 1 |
| 165 #define SQLITE_ENABLE_LOCKING_STYLE 0 |
| 166 #define HAVE_UTIME 1 |
| 167 #else |
| 168 /* This is not VxWorks. */ |
| 169 #define OS_VXWORKS 0 |
| 170 #define HAVE_FCHOWN 1 |
| 171 #define HAVE_READLINK 1 |
| 172 #define HAVE_LSTAT 1 |
| 173 #endif /* defined(_WRS_KERNEL) */ |
| 174 |
| 175 /************** End of vxworks.h *********************************************/ |
| 176 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 177 |
| 178 /* |
| 179 ** These #defines should enable >2GB file support on POSIX if the |
| 180 ** underlying operating system supports it. If the OS lacks |
| 181 ** large file support, or if the OS is windows, these should be no-ops. |
| 182 ** |
| 183 ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any |
| 184 ** system #includes. Hence, this block of code must be the very first |
| 185 ** code in all source files. |
| 186 ** |
| 187 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch |
| 188 ** on the compiler command line. This is necessary if you are compiling |
| 189 ** on a recent machine (ex: Red Hat 7.2) but you want your code to work |
| 190 ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 |
| 191 ** without this option, LFS is enable. But LFS does not exist in the kernel |
| 192 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary |
| 193 ** portability you should omit LFS. |
| 194 ** |
| 195 ** The previous paragraph was written in 2005. (This paragraph is written |
| 196 ** on 2008-11-28.) These days, all Linux kernels support large files, so |
| 197 ** you should probably leave LFS enabled. But some embedded platforms might |
| 198 ** lack LFS in which case the SQLITE_DISABLE_LFS macro might still be useful. |
| 199 ** |
| 200 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. |
| 201 */ |
| 202 #ifndef SQLITE_DISABLE_LFS |
| 203 # define _LARGE_FILE 1 |
| 204 # ifndef _FILE_OFFSET_BITS |
| 205 # define _FILE_OFFSET_BITS 64 |
| 206 # endif |
| 207 # define _LARGEFILE_SOURCE 1 |
| 208 #endif |
| 209 |
| 210 /* The GCC_VERSION, CLANG_VERSION, and MSVC_VERSION macros are used to |
| 211 ** conditionally include optimizations for each of these compilers. A |
| 212 ** value of 0 means that compiler is not being used. The |
| 213 ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific |
| 214 ** optimizations, and hence set all compiler macros to 0 |
| 215 */ |
| 216 #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 217 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 218 #else |
| 219 # define GCC_VERSION 0 |
| 220 #endif |
| 221 #if defined(__clang__) && !defined(_WIN32) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 222 # define CLANG_VERSION \ |
| 223 (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) |
| 224 #else |
| 225 # define CLANG_VERSION 0 |
| 226 #endif |
| 227 #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC) |
| 228 # define MSVC_VERSION _MSC_VER |
| 229 #else |
| 230 # define MSVC_VERSION 0 |
| 231 #endif |
| 232 |
| 233 /* Needed for various definitions... */ |
| 234 #if defined(__GNUC__) && !defined(_GNU_SOURCE) |
| 235 # define _GNU_SOURCE |
| 236 #endif |
| 237 |
| 238 #if defined(__OpenBSD__) && !defined(_BSD_SOURCE) |
| 239 # define _BSD_SOURCE |
| 240 #endif |
| 241 |
| 242 /* |
| 243 ** For MinGW, check to see if we can include the header file containing its |
| 244 ** version information, among other things. Normally, this internal MinGW |
| 245 ** header file would [only] be included automatically by other MinGW header |
| 246 ** files; however, the contained version information is now required by this |
| 247 ** header file to work around binary compatibility issues (see below) and |
| 248 ** this is the only known way to reliably obtain it. This entire #if block |
| 249 ** would be completely unnecessary if there was any other way of detecting |
| 250 ** MinGW via their preprocessor (e.g. if they customized their GCC to define |
| 251 ** some MinGW-specific macros). When compiling for MinGW, either the |
| 252 ** _HAVE_MINGW_H or _HAVE__MINGW_H (note the extra underscore) macro must be |
| 253 ** defined; otherwise, detection of conditions specific to MinGW will be |
| 254 ** disabled. |
| 255 */ |
| 256 #if defined(_HAVE_MINGW_H) |
| 257 # include "mingw.h" |
| 258 #elif defined(_HAVE__MINGW_H) |
| 259 # include "_mingw.h" |
| 260 #endif |
| 261 |
| 262 /* |
| 263 ** For MinGW version 4.x (and higher), check to see if the _USE_32BIT_TIME_T |
| 264 ** define is required to maintain binary compatibility with the MSVC runtime |
| 265 ** library in use (e.g. for Windows XP). |
| 266 */ |
| 267 #if !defined(_USE_32BIT_TIME_T) && !defined(_USE_64BIT_TIME_T) && \ |
| 268 defined(_WIN32) && !defined(_WIN64) && \ |
| 269 defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION >= 4 && \ |
| 270 defined(__MSVCRT__) |
| 271 # define _USE_32BIT_TIME_T |
| 272 #endif |
| 273 |
| 274 /* The public SQLite interface. The _FILE_OFFSET_BITS macro must appear |
| 275 ** first in QNX. Also, the _USE_32BIT_TIME_T macro must appear first for |
| 276 ** MinGW. |
| 277 */ |
| 278 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/ |
| 279 /************** Begin file sqlite3.h *****************************************/ |
| 280 /* |
| 281 ** 2001 September 15 |
| 282 ** |
| 283 ** The author disclaims copyright to this source code. In place of |
| 284 ** a legal notice, here is a blessing: |
| 285 ** |
| 286 ** May you do good and not evil. |
| 287 ** May you find forgiveness for yourself and forgive others. |
| 288 ** May you share freely, never taking more than you give. |
| 289 ** |
| 290 ************************************************************************* |
| 291 ** This header file defines the interface that the SQLite library |
| 292 ** presents to client programs. If a C-function, structure, datatype, |
| 293 ** or constant definition does not appear in this file, then it is |
| 294 ** not a published API of SQLite, is subject to change without |
| 295 ** notice, and should not be referenced by programs that use SQLite. |
| 296 ** |
| 297 ** Some of the definitions that are in this file are marked as |
| 298 ** "experimental". Experimental interfaces are normally new |
| 299 ** features recently added to SQLite. We do not anticipate changes |
| 300 ** to experimental interfaces but reserve the right to make minor changes |
| 301 ** if experience from use "in the wild" suggest such changes are prudent. |
| 302 ** |
| 303 ** The official C-language API documentation for SQLite is derived |
| 304 ** from comments in this file. This file is the authoritative source |
| 305 ** on how SQLite interfaces are supposed to operate. |
| 306 ** |
| 307 ** The name of this file under configuration management is "sqlite.h.in". |
| 308 ** The makefile makes some minor changes to this file (such as inserting |
| 309 ** the version number) and changes its name to "sqlite3.h" as |
| 310 ** part of the build process. |
| 311 */ |
| 312 #ifndef SQLITE3_H |
| 313 #define SQLITE3_H |
| 314 #include <stdarg.h> /* Needed for the definition of va_list */ |
| 315 |
| 316 /* |
| 317 ** Make sure we can call this stuff from C++. |
| 318 */ |
| 319 #if 0 |
| 320 extern "C" { |
| 321 #endif |
| 322 |
| 323 |
| 324 /* |
| 325 ** Provide the ability to override linkage features of the interface. |
| 326 */ |
| 327 #ifndef SQLITE_EXTERN |
| 328 # define SQLITE_EXTERN extern |
| 329 #endif |
| 330 #ifndef SQLITE_API |
| 331 # define SQLITE_API |
| 332 #endif |
| 333 #ifndef SQLITE_CDECL |
| 334 # define SQLITE_CDECL |
| 335 #endif |
| 336 #ifndef SQLITE_APICALL |
| 337 # define SQLITE_APICALL |
| 338 #endif |
| 339 #ifndef SQLITE_STDCALL |
| 340 # define SQLITE_STDCALL SQLITE_APICALL |
| 341 #endif |
| 342 #ifndef SQLITE_CALLBACK |
| 343 # define SQLITE_CALLBACK |
| 344 #endif |
| 345 #ifndef SQLITE_SYSAPI |
| 346 # define SQLITE_SYSAPI |
| 347 #endif |
| 348 |
| 349 /* |
| 350 ** These no-op macros are used in front of interfaces to mark those |
| 351 ** interfaces as either deprecated or experimental. New applications |
| 352 ** should not use deprecated interfaces - they are supported for backwards |
| 353 ** compatibility only. Application writers should be aware that |
| 354 ** experimental interfaces are subject to change in point releases. |
| 355 ** |
| 356 ** These macros used to resolve to various kinds of compiler magic that |
| 357 ** would generate warning messages when they were used. But that |
| 358 ** compiler magic ended up generating such a flurry of bug reports |
| 359 ** that we have taken it all out and gone back to using simple |
| 360 ** noop macros. |
| 361 */ |
| 362 #define SQLITE_DEPRECATED |
| 363 #define SQLITE_EXPERIMENTAL |
| 364 |
| 365 /* |
| 366 ** Ensure these symbols were not defined by some previous header file. |
| 367 */ |
| 368 #ifdef SQLITE_VERSION |
| 369 # undef SQLITE_VERSION |
| 370 #endif |
| 371 #ifdef SQLITE_VERSION_NUMBER |
| 372 # undef SQLITE_VERSION_NUMBER |
| 373 #endif |
| 374 |
| 375 /* |
| 376 ** CAPI3REF: Compile-Time Library Version Numbers |
| 377 ** |
| 378 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header |
| 379 ** evaluates to a string literal that is the SQLite version in the |
| 380 ** format "X.Y.Z" where X is the major version number (always 3 for |
| 381 ** SQLite3) and Y is the minor version number and Z is the release number.)^ |
| 382 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer |
| 383 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same |
| 384 ** numbers used in [SQLITE_VERSION].)^ |
| 385 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also |
| 386 ** be larger than the release from which it is derived. Either Y will |
| 387 ** be held constant and Z will be incremented or else Y will be incremented |
| 388 ** and Z will be reset to zero. |
| 389 ** |
| 390 ** Since [version 3.6.18] ([dateof:3.6.18]), |
| 391 ** SQLite source code has been stored in the |
| 392 ** <a href="http://www.fossil-scm.org/">Fossil configuration management |
| 393 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to |
| 394 ** a string which identifies a particular check-in of SQLite |
| 395 ** within its configuration management system. ^The SQLITE_SOURCE_ID |
| 396 ** string contains the date and time of the check-in (UTC) and an SHA1 |
| 397 ** hash of the entire source tree. |
| 398 ** |
| 399 ** See also: [sqlite3_libversion()], |
| 400 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 401 ** [sqlite_version()] and [sqlite_source_id()]. |
| 402 */ |
| 403 #define SQLITE_VERSION "3.17.0" |
| 404 #define SQLITE_VERSION_NUMBER 3017000 |
| 405 #define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21
c9aa6e57d2c" |
| 406 |
| 407 /* |
| 408 ** CAPI3REF: Run-Time Library Version Numbers |
| 409 ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 410 ** |
| 411 ** These interfaces provide the same information as the [SQLITE_VERSION], |
| 412 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros |
| 413 ** but are associated with the library instead of the header file. ^(Cautious |
| 414 ** programmers might include assert() statements in their application to |
| 415 ** verify that values returned by these interfaces match the macros in |
| 416 ** the header, and thus ensure that the application is |
| 417 ** compiled with matching library and header files. |
| 418 ** |
| 419 ** <blockquote><pre> |
| 420 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); |
| 421 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); |
| 422 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); |
| 423 ** </pre></blockquote>)^ |
| 424 ** |
| 425 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] |
| 426 ** macro. ^The sqlite3_libversion() function returns a pointer to the |
| 427 ** to the sqlite3_version[] string constant. The sqlite3_libversion() |
| 428 ** function is provided for use in DLLs since DLL users usually do not have |
| 429 ** direct access to string constants within the DLL. ^The |
| 430 ** sqlite3_libversion_number() function returns an integer equal to |
| 431 ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns |
| 432 ** a pointer to a string constant whose value is the same as the |
| 433 ** [SQLITE_SOURCE_ID] C preprocessor macro. |
| 434 ** |
| 435 ** See also: [sqlite_version()] and [sqlite_source_id()]. |
| 436 */ |
| 437 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; |
| 438 SQLITE_API const char *sqlite3_libversion(void); |
| 439 SQLITE_API const char *sqlite3_sourceid(void); |
| 440 SQLITE_API int sqlite3_libversion_number(void); |
| 441 |
| 442 /* |
| 443 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics |
| 444 ** |
| 445 ** ^The sqlite3_compileoption_used() function returns 0 or 1 |
| 446 ** indicating whether the specified option was defined at |
| 447 ** compile time. ^The SQLITE_ prefix may be omitted from the |
| 448 ** option name passed to sqlite3_compileoption_used(). |
| 449 ** |
| 450 ** ^The sqlite3_compileoption_get() function allows iterating |
| 451 ** over the list of options that were defined at compile time by |
| 452 ** returning the N-th compile time option string. ^If N is out of range, |
| 453 ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ |
| 454 ** prefix is omitted from any strings returned by |
| 455 ** sqlite3_compileoption_get(). |
| 456 ** |
| 457 ** ^Support for the diagnostic functions sqlite3_compileoption_used() |
| 458 ** and sqlite3_compileoption_get() may be omitted by specifying the |
| 459 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. |
| 460 ** |
| 461 ** See also: SQL functions [sqlite_compileoption_used()] and |
| 462 ** [sqlite_compileoption_get()] and the [compile_options pragma]. |
| 463 */ |
| 464 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 465 SQLITE_API int sqlite3_compileoption_used(const char *zOptName); |
| 466 SQLITE_API const char *sqlite3_compileoption_get(int N); |
| 467 #endif |
| 468 |
| 469 /* |
| 470 ** CAPI3REF: Test To See If The Library Is Threadsafe |
| 471 ** |
| 472 ** ^The sqlite3_threadsafe() function returns zero if and only if |
| 473 ** SQLite was compiled with mutexing code omitted due to the |
| 474 ** [SQLITE_THREADSAFE] compile-time option being set to 0. |
| 475 ** |
| 476 ** SQLite can be compiled with or without mutexes. When |
| 477 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes |
| 478 ** are enabled and SQLite is threadsafe. When the |
| 479 ** [SQLITE_THREADSAFE] macro is 0, |
| 480 ** the mutexes are omitted. Without the mutexes, it is not safe |
| 481 ** to use SQLite concurrently from more than one thread. |
| 482 ** |
| 483 ** Enabling mutexes incurs a measurable performance penalty. |
| 484 ** So if speed is of utmost importance, it makes sense to disable |
| 485 ** the mutexes. But for maximum safety, mutexes should be enabled. |
| 486 ** ^The default behavior is for mutexes to be enabled. |
| 487 ** |
| 488 ** This interface can be used by an application to make sure that the |
| 489 ** version of SQLite that it is linking against was compiled with |
| 490 ** the desired setting of the [SQLITE_THREADSAFE] macro. |
| 491 ** |
| 492 ** This interface only reports on the compile-time mutex setting |
| 493 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with |
| 494 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but |
| 495 ** can be fully or partially disabled using a call to [sqlite3_config()] |
| 496 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], |
| 497 ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the |
| 498 ** sqlite3_threadsafe() function shows only the compile-time setting of |
| 499 ** thread safety, not any run-time changes to that setting made by |
| 500 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() |
| 501 ** is unchanged by calls to sqlite3_config().)^ |
| 502 ** |
| 503 ** See the [threading mode] documentation for additional information. |
| 504 */ |
| 505 SQLITE_API int sqlite3_threadsafe(void); |
| 506 |
| 507 /* |
| 508 ** CAPI3REF: Database Connection Handle |
| 509 ** KEYWORDS: {database connection} {database connections} |
| 510 ** |
| 511 ** Each open SQLite database is represented by a pointer to an instance of |
| 512 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 |
| 513 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and |
| 514 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] |
| 515 ** and [sqlite3_close_v2()] are its destructors. There are many other |
| 516 ** interfaces (such as |
| 517 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and |
| 518 ** [sqlite3_busy_timeout()] to name but three) that are methods on an |
| 519 ** sqlite3 object. |
| 520 */ |
| 521 typedef struct sqlite3 sqlite3; |
| 522 |
| 523 /* |
| 524 ** CAPI3REF: 64-Bit Integer Types |
| 525 ** KEYWORDS: sqlite_int64 sqlite_uint64 |
| 526 ** |
| 527 ** Because there is no cross-platform way to specify 64-bit integer types |
| 528 ** SQLite includes typedefs for 64-bit signed and unsigned integers. |
| 529 ** |
| 530 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. |
| 531 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards |
| 532 ** compatibility only. |
| 533 ** |
| 534 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values |
| 535 ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The |
| 536 ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
| 537 ** between 0 and +18446744073709551615 inclusive. |
| 538 */ |
| 539 #ifdef SQLITE_INT64_TYPE |
| 540 typedef SQLITE_INT64_TYPE sqlite_int64; |
| 541 # ifdef SQLITE_UINT64_TYPE |
| 542 typedef SQLITE_UINT64_TYPE sqlite_uint64; |
| 543 # else |
| 544 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; |
| 545 # endif |
| 546 #elif defined(_MSC_VER) || defined(__BORLANDC__) |
| 547 typedef __int64 sqlite_int64; |
| 548 typedef unsigned __int64 sqlite_uint64; |
| 549 #else |
| 550 typedef long long int sqlite_int64; |
| 551 typedef unsigned long long int sqlite_uint64; |
| 552 #endif |
| 553 typedef sqlite_int64 sqlite3_int64; |
| 554 typedef sqlite_uint64 sqlite3_uint64; |
| 555 |
| 556 /* |
| 557 ** If compiling for a processor that lacks floating point support, |
| 558 ** substitute integer for floating-point. |
| 559 */ |
| 560 #ifdef SQLITE_OMIT_FLOATING_POINT |
| 561 # define double sqlite3_int64 |
| 562 #endif |
| 563 |
| 564 /* |
| 565 ** CAPI3REF: Closing A Database Connection |
| 566 ** DESTRUCTOR: sqlite3 |
| 567 ** |
| 568 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 569 ** for the [sqlite3] object. |
| 570 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 571 ** the [sqlite3] object is successfully destroyed and all associated |
| 572 ** resources are deallocated. |
| 573 ** |
| 574 ** ^If the database connection is associated with unfinalized prepared |
| 575 ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| 576 ** will leave the database connection open and return [SQLITE_BUSY]. |
| 577 ** ^If sqlite3_close_v2() is called with unfinalized prepared statements |
| 578 ** and/or unfinished sqlite3_backups, then the database connection becomes |
| 579 ** an unusable "zombie" which will automatically be deallocated when the |
| 580 ** last prepared statement is finalized or the last sqlite3_backup is |
| 581 ** finished. The sqlite3_close_v2() interface is intended for use with |
| 582 ** host languages that are garbage collected, and where the order in which |
| 583 ** destructors are called is arbitrary. |
| 584 ** |
| 585 ** Applications should [sqlite3_finalize | finalize] all [prepared statements], |
| 586 ** [sqlite3_blob_close | close] all [BLOB handles], and |
| 587 ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 588 ** with the [sqlite3] object prior to attempting to close the object. ^If |
| 589 ** sqlite3_close_v2() is called on a [database connection] that still has |
| 590 ** outstanding [prepared statements], [BLOB handles], and/or |
| 591 ** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation |
| 592 ** of resources is deferred until all [prepared statements], [BLOB handles], |
| 593 ** and [sqlite3_backup] objects are also destroyed. |
| 594 ** |
| 595 ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 596 ** the transaction is automatically rolled back. |
| 597 ** |
| 598 ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)] |
| 599 ** must be either a NULL |
| 600 ** pointer or an [sqlite3] object pointer obtained |
| 601 ** from [sqlite3_open()], [sqlite3_open16()], or |
| 602 ** [sqlite3_open_v2()], and not previously closed. |
| 603 ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer |
| 604 ** argument is a harmless no-op. |
| 605 */ |
| 606 SQLITE_API int sqlite3_close(sqlite3*); |
| 607 SQLITE_API int sqlite3_close_v2(sqlite3*); |
| 608 |
| 609 /* |
| 610 ** The type for a callback function. |
| 611 ** This is legacy and deprecated. It is included for historical |
| 612 ** compatibility and is not documented. |
| 613 */ |
| 614 typedef int (*sqlite3_callback)(void*,int,char**, char**); |
| 615 |
| 616 /* |
| 617 ** CAPI3REF: One-Step Query Execution Interface |
| 618 ** METHOD: sqlite3 |
| 619 ** |
| 620 ** The sqlite3_exec() interface is a convenience wrapper around |
| 621 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], |
| 622 ** that allows an application to run multiple statements of SQL |
| 623 ** without having to use a lot of C code. |
| 624 ** |
| 625 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, |
| 626 ** semicolon-separate SQL statements passed into its 2nd argument, |
| 627 ** in the context of the [database connection] passed in as its 1st |
| 628 ** argument. ^If the callback function of the 3rd argument to |
| 629 ** sqlite3_exec() is not NULL, then it is invoked for each result row |
| 630 ** coming out of the evaluated SQL statements. ^The 4th argument to |
| 631 ** sqlite3_exec() is relayed through to the 1st argument of each |
| 632 ** callback invocation. ^If the callback pointer to sqlite3_exec() |
| 633 ** is NULL, then no callback is ever invoked and result rows are |
| 634 ** ignored. |
| 635 ** |
| 636 ** ^If an error occurs while evaluating the SQL statements passed into |
| 637 ** sqlite3_exec(), then execution of the current statement stops and |
| 638 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() |
| 639 ** is not NULL then any error message is written into memory obtained |
| 640 ** from [sqlite3_malloc()] and passed back through the 5th parameter. |
| 641 ** To avoid memory leaks, the application should invoke [sqlite3_free()] |
| 642 ** on error message strings returned through the 5th parameter of |
| 643 ** sqlite3_exec() after the error message string is no longer needed. |
| 644 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors |
| 645 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to |
| 646 ** NULL before returning. |
| 647 ** |
| 648 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() |
| 649 ** routine returns SQLITE_ABORT without invoking the callback again and |
| 650 ** without running any subsequent SQL statements. |
| 651 ** |
| 652 ** ^The 2nd argument to the sqlite3_exec() callback function is the |
| 653 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() |
| 654 ** callback is an array of pointers to strings obtained as if from |
| 655 ** [sqlite3_column_text()], one for each column. ^If an element of a |
| 656 ** result row is NULL then the corresponding string pointer for the |
| 657 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the |
| 658 ** sqlite3_exec() callback is an array of pointers to strings where each |
| 659 ** entry represents the name of corresponding result column as obtained |
| 660 ** from [sqlite3_column_name()]. |
| 661 ** |
| 662 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer |
| 663 ** to an empty string, or a pointer that contains only whitespace and/or |
| 664 ** SQL comments, then no SQL statements are evaluated and the database |
| 665 ** is not changed. |
| 666 ** |
| 667 ** Restrictions: |
| 668 ** |
| 669 ** <ul> |
| 670 ** <li> The application must ensure that the 1st parameter to sqlite3_exec() |
| 671 ** is a valid and open [database connection]. |
| 672 ** <li> The application must not close the [database connection] specified by |
| 673 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. |
| 674 ** <li> The application must not modify the SQL statement text passed into |
| 675 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. |
| 676 ** </ul> |
| 677 */ |
| 678 SQLITE_API int sqlite3_exec( |
| 679 sqlite3*, /* An open database */ |
| 680 const char *sql, /* SQL to be evaluated */ |
| 681 int (*callback)(void*,int,char**,char**), /* Callback function */ |
| 682 void *, /* 1st argument to callback */ |
| 683 char **errmsg /* Error msg written here */ |
| 684 ); |
| 685 |
| 686 /* |
| 687 ** CAPI3REF: Result Codes |
| 688 ** KEYWORDS: {result code definitions} |
| 689 ** |
| 690 ** Many SQLite functions return an integer result code from the set shown |
| 691 ** here in order to indicate success or failure. |
| 692 ** |
| 693 ** New error codes may be added in future versions of SQLite. |
| 694 ** |
| 695 ** See also: [extended result code definitions] |
| 696 */ |
| 697 #define SQLITE_OK 0 /* Successful result */ |
| 698 /* beginning-of-error-codes */ |
| 699 #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 700 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| 701 #define SQLITE_PERM 3 /* Access permission denied */ |
| 702 #define SQLITE_ABORT 4 /* Callback routine requested an abort */ |
| 703 #define SQLITE_BUSY 5 /* The database file is locked */ |
| 704 #define SQLITE_LOCKED 6 /* A table in the database is locked */ |
| 705 #define SQLITE_NOMEM 7 /* A malloc() failed */ |
| 706 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ |
| 707 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ |
| 708 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ |
| 709 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ |
| 710 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ |
| 711 #define SQLITE_FULL 13 /* Insertion failed because database is full */ |
| 712 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ |
| 713 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ |
| 714 #define SQLITE_EMPTY 16 /* Database is empty */ |
| 715 #define SQLITE_SCHEMA 17 /* The database schema changed */ |
| 716 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ |
| 717 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ |
| 718 #define SQLITE_MISMATCH 20 /* Data type mismatch */ |
| 719 #define SQLITE_MISUSE 21 /* Library used incorrectly */ |
| 720 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ |
| 721 #define SQLITE_AUTH 23 /* Authorization denied */ |
| 722 #define SQLITE_FORMAT 24 /* Auxiliary database format error */ |
| 723 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ |
| 724 #define SQLITE_NOTADB 26 /* File opened that is not a database file */ |
| 725 #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ |
| 726 #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ |
| 727 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ |
| 728 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
| 729 /* end-of-error-codes */ |
| 730 |
| 731 /* |
| 732 ** CAPI3REF: Extended Result Codes |
| 733 ** KEYWORDS: {extended result code definitions} |
| 734 ** |
| 735 ** In its default configuration, SQLite API routines return one of 30 integer |
| 736 ** [result codes]. However, experience has shown that many of |
| 737 ** these result codes are too coarse-grained. They do not provide as |
| 738 ** much information about problems as programmers might like. In an effort to |
| 739 ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8] |
| 740 ** and later) include |
| 741 ** support for additional result codes that provide more detailed information |
| 742 ** about errors. These [extended result codes] are enabled or disabled |
| 743 ** on a per database connection basis using the |
| 744 ** [sqlite3_extended_result_codes()] API. Or, the extended code for |
| 745 ** the most recent error can be obtained using |
| 746 ** [sqlite3_extended_errcode()]. |
| 747 */ |
| 748 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 749 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 750 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 751 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| 752 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) |
| 753 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) |
| 754 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) |
| 755 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) |
| 756 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) |
| 757 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) |
| 758 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) |
| 759 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) |
| 760 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) |
| 761 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) |
| 762 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) |
| 763 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) |
| 764 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) |
| 765 #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) |
| 766 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) |
| 767 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) |
| 768 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) |
| 769 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 770 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) |
| 771 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) |
| 772 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) |
| 773 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) |
| 774 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) |
| 775 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) |
| 776 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 777 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 778 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 779 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 780 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 781 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 782 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 783 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 784 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 785 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 786 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 787 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 788 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 789 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 790 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 791 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 792 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| 793 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) |
| 794 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) |
| 795 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) |
| 796 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) |
| 797 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) |
| 798 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) |
| 799 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
| 800 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 801 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 802 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 803 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| 804 |
| 805 /* |
| 806 ** CAPI3REF: Flags For File Open Operations |
| 807 ** |
| 808 ** These bit values are intended for use in the |
| 809 ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 810 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. |
| 811 */ |
| 812 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 813 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 814 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 815 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| 816 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ |
| 817 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ |
| 818 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ |
| 819 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ |
| 820 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ |
| 821 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ |
| 822 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ |
| 823 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ |
| 824 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ |
| 825 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ |
| 826 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ |
| 827 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ |
| 828 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ |
| 829 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ |
| 830 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ |
| 831 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ |
| 832 |
| 833 /* Reserved: 0x00F00000 */ |
| 834 |
| 835 /* |
| 836 ** CAPI3REF: Device Characteristics |
| 837 ** |
| 838 ** The xDeviceCharacteristics method of the [sqlite3_io_methods] |
| 839 ** object returns an integer which is a vector of these |
| 840 ** bit values expressing I/O characteristics of the mass storage |
| 841 ** device that holds the file that the [sqlite3_io_methods] |
| 842 ** refers to. |
| 843 ** |
| 844 ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 845 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 846 ** mean that writes of blocks that are nnn bytes in size and |
| 847 ** are aligned to an address which is an integer multiple of |
| 848 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means |
| 849 ** that when data is appended to a file, the data is appended |
| 850 ** first then the size of the file is extended, never the other |
| 851 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that |
| 852 ** information is written to disk in the same order as calls |
| 853 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 854 ** after reboot following a crash or power loss, the only bytes in a |
| 855 ** file that were written at the application level might have changed |
| 856 ** and that adjacent bytes, even bytes within the same sector are |
| 857 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 858 ** flag indicates that a file cannot be deleted when open. The |
| 859 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 860 ** read-only media and cannot be changed even by processes with |
| 861 ** elevated privileges. |
| 862 */ |
| 863 #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 864 #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 865 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 866 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| 867 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 |
| 868 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 |
| 869 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 |
| 870 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 |
| 871 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 |
| 872 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 |
| 873 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 |
| 874 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 |
| 875 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 |
| 876 #define SQLITE_IOCAP_IMMUTABLE 0x00002000 |
| 877 |
| 878 /* |
| 879 ** CAPI3REF: File Locking Levels |
| 880 ** |
| 881 ** SQLite uses one of these integer values as the second |
| 882 ** argument to calls it makes to the xLock() and xUnlock() methods |
| 883 ** of an [sqlite3_io_methods] object. |
| 884 */ |
| 885 #define SQLITE_LOCK_NONE 0 |
| 886 #define SQLITE_LOCK_SHARED 1 |
| 887 #define SQLITE_LOCK_RESERVED 2 |
| 888 #define SQLITE_LOCK_PENDING 3 |
| 889 #define SQLITE_LOCK_EXCLUSIVE 4 |
| 890 |
| 891 /* |
| 892 ** CAPI3REF: Synchronization Type Flags |
| 893 ** |
| 894 ** When SQLite invokes the xSync() method of an |
| 895 ** [sqlite3_io_methods] object it uses a combination of |
| 896 ** these integer values as the second argument. |
| 897 ** |
| 898 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the |
| 899 ** sync operation only needs to flush data to mass storage. Inode |
| 900 ** information need not be flushed. If the lower four bits of the flag |
| 901 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. |
| 902 ** If the lower four bits equal SQLITE_SYNC_FULL, that means |
| 903 ** to use Mac OS X style fullsync instead of fsync(). |
| 904 ** |
| 905 ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags |
| 906 ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL |
| 907 ** settings. The [synchronous pragma] determines when calls to the |
| 908 ** xSync VFS method occur and applies uniformly across all platforms. |
| 909 ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how |
| 910 ** energetic or rigorous or forceful the sync operations are and |
| 911 ** only make a difference on Mac OSX for the default SQLite code. |
| 912 ** (Third-party VFS implementations might also make the distinction |
| 913 ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the |
| 914 ** operating systems natively supported by SQLite, only Mac OSX |
| 915 ** cares about the difference.) |
| 916 */ |
| 917 #define SQLITE_SYNC_NORMAL 0x00002 |
| 918 #define SQLITE_SYNC_FULL 0x00003 |
| 919 #define SQLITE_SYNC_DATAONLY 0x00010 |
| 920 |
| 921 /* |
| 922 ** CAPI3REF: OS Interface Open File Handle |
| 923 ** |
| 924 ** An [sqlite3_file] object represents an open file in the |
| 925 ** [sqlite3_vfs | OS interface layer]. Individual OS interface |
| 926 ** implementations will |
| 927 ** want to subclass this object by appending additional fields |
| 928 ** for their own use. The pMethods entry is a pointer to an |
| 929 ** [sqlite3_io_methods] object that defines methods for performing |
| 930 ** I/O operations on the open file. |
| 931 */ |
| 932 typedef struct sqlite3_file sqlite3_file; |
| 933 struct sqlite3_file { |
| 934 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ |
| 935 }; |
| 936 |
| 937 /* |
| 938 ** CAPI3REF: OS Interface File Virtual Methods Object |
| 939 ** |
| 940 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an |
| 941 ** [sqlite3_file] object (or, more commonly, a subclass of the |
| 942 ** [sqlite3_file] object) with a pointer to an instance of this object. |
| 943 ** This object defines the methods used to perform various operations |
| 944 ** against the open file represented by the [sqlite3_file] object. |
| 945 ** |
| 946 ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element |
| 947 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method |
| 948 ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The |
| 949 ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] |
| 950 ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element |
| 951 ** to NULL. |
| 952 ** |
| 953 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or |
| 954 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). |
| 955 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] |
| 956 ** flag may be ORed in to indicate that only the data of the file |
| 957 ** and not its inode needs to be synced. |
| 958 ** |
| 959 ** The integer values to xLock() and xUnlock() are one of |
| 960 ** <ul> |
| 961 ** <li> [SQLITE_LOCK_NONE], |
| 962 ** <li> [SQLITE_LOCK_SHARED], |
| 963 ** <li> [SQLITE_LOCK_RESERVED], |
| 964 ** <li> [SQLITE_LOCK_PENDING], or |
| 965 ** <li> [SQLITE_LOCK_EXCLUSIVE]. |
| 966 ** </ul> |
| 967 ** xLock() increases the lock. xUnlock() decreases the lock. |
| 968 ** The xCheckReservedLock() method checks whether any database connection, |
| 969 ** either in this process or in some other process, is holding a RESERVED, |
| 970 ** PENDING, or EXCLUSIVE lock on the file. It returns true |
| 971 ** if such a lock exists and false otherwise. |
| 972 ** |
| 973 ** The xFileControl() method is a generic interface that allows custom |
| 974 ** VFS implementations to directly control an open file using the |
| 975 ** [sqlite3_file_control()] interface. The second "op" argument is an |
| 976 ** integer opcode. The third argument is a generic pointer intended to |
| 977 ** point to a structure that may contain arguments or space in which to |
| 978 ** write return values. Potential uses for xFileControl() might be |
| 979 ** functions to enable blocking locks with timeouts, to change the |
| 980 ** locking strategy (for example to use dot-file locks), to inquire |
| 981 ** about the status of a lock, or to break stale locks. The SQLite |
| 982 ** core reserves all opcodes less than 100 for its own use. |
| 983 ** A [file control opcodes | list of opcodes] less than 100 is available. |
| 984 ** Applications that define a custom xFileControl method should use opcodes |
| 985 ** greater than 100 to avoid conflicts. VFS implementations should |
| 986 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
| 987 ** recognize. |
| 988 ** |
| 989 ** The xSectorSize() method returns the sector size of the |
| 990 ** device that underlies the file. The sector size is the |
| 991 ** minimum write that can be performed without disturbing |
| 992 ** other bytes in the file. The xDeviceCharacteristics() |
| 993 ** method returns a bit vector describing behaviors of the |
| 994 ** underlying device: |
| 995 ** |
| 996 ** <ul> |
| 997 ** <li> [SQLITE_IOCAP_ATOMIC] |
| 998 ** <li> [SQLITE_IOCAP_ATOMIC512] |
| 999 ** <li> [SQLITE_IOCAP_ATOMIC1K] |
| 1000 ** <li> [SQLITE_IOCAP_ATOMIC2K] |
| 1001 ** <li> [SQLITE_IOCAP_ATOMIC4K] |
| 1002 ** <li> [SQLITE_IOCAP_ATOMIC8K] |
| 1003 ** <li> [SQLITE_IOCAP_ATOMIC16K] |
| 1004 ** <li> [SQLITE_IOCAP_ATOMIC32K] |
| 1005 ** <li> [SQLITE_IOCAP_ATOMIC64K] |
| 1006 ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 1007 ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 1008 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] |
| 1009 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] |
| 1010 ** <li> [SQLITE_IOCAP_IMMUTABLE] |
| 1011 ** </ul> |
| 1012 ** |
| 1013 ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 1014 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 1015 ** mean that writes of blocks that are nnn bytes in size and |
| 1016 ** are aligned to an address which is an integer multiple of |
| 1017 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means |
| 1018 ** that when data is appended to a file, the data is appended |
| 1019 ** first then the size of the file is extended, never the other |
| 1020 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that |
| 1021 ** information is written to disk in the same order as calls |
| 1022 ** to xWrite(). |
| 1023 ** |
| 1024 ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill |
| 1025 ** in the unread portions of the buffer with zeros. A VFS that |
| 1026 ** fails to zero-fill short reads might seem to work. However, |
| 1027 ** failure to zero-fill short reads will eventually lead to |
| 1028 ** database corruption. |
| 1029 */ |
| 1030 typedef struct sqlite3_io_methods sqlite3_io_methods; |
| 1031 struct sqlite3_io_methods { |
| 1032 int iVersion; |
| 1033 int (*xClose)(sqlite3_file*); |
| 1034 int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); |
| 1035 int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); |
| 1036 int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); |
| 1037 int (*xSync)(sqlite3_file*, int flags); |
| 1038 int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); |
| 1039 int (*xLock)(sqlite3_file*, int); |
| 1040 int (*xUnlock)(sqlite3_file*, int); |
| 1041 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); |
| 1042 int (*xFileControl)(sqlite3_file*, int op, void *pArg); |
| 1043 int (*xSectorSize)(sqlite3_file*); |
| 1044 int (*xDeviceCharacteristics)(sqlite3_file*); |
| 1045 /* Methods above are valid for version 1 */ |
| 1046 int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); |
| 1047 int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); |
| 1048 void (*xShmBarrier)(sqlite3_file*); |
| 1049 int (*xShmUnmap)(sqlite3_file*, int deleteFlag); |
| 1050 /* Methods above are valid for version 2 */ |
| 1051 int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); |
| 1052 int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p); |
| 1053 /* Methods above are valid for version 3 */ |
| 1054 /* Additional methods may be added in future releases */ |
| 1055 }; |
| 1056 |
| 1057 /* |
| 1058 ** CAPI3REF: Standard File Control Opcodes |
| 1059 ** KEYWORDS: {file control opcodes} {file control opcode} |
| 1060 ** |
| 1061 ** These integer constants are opcodes for the xFileControl method |
| 1062 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
| 1063 ** interface. |
| 1064 ** |
| 1065 ** <ul> |
| 1066 ** <li>[[SQLITE_FCNTL_LOCKSTATE]] |
| 1067 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This |
| 1068 ** opcode causes the xFileControl method to write the current state of |
| 1069 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], |
| 1070 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) |
| 1071 ** into an integer that the pArg argument points to. This capability |
| 1072 ** is used during testing and is only available when the SQLITE_TEST |
| 1073 ** compile-time option is used. |
| 1074 ** |
| 1075 ** <li>[[SQLITE_FCNTL_SIZE_HINT]] |
| 1076 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS |
| 1077 ** layer a hint of how large the database file will grow to be during the |
| 1078 ** current transaction. This hint is not guaranteed to be accurate but it |
| 1079 ** is often close. The underlying VFS might choose to preallocate database |
| 1080 ** file space based on this hint in order to help writes to the database |
| 1081 ** file run faster. |
| 1082 ** |
| 1083 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]] |
| 1084 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS |
| 1085 ** extends and truncates the database file in chunks of a size specified |
| 1086 ** by the user. The fourth argument to [sqlite3_file_control()] should |
| 1087 ** point to an integer (type int) containing the new chunk-size to use |
| 1088 ** for the nominated database. Allocating database file space in large |
| 1089 ** chunks (say 1MB at a time), may reduce file-system fragmentation and |
| 1090 ** improve performance on some systems. |
| 1091 ** |
| 1092 ** <li>[[SQLITE_FCNTL_FILE_POINTER]] |
| 1093 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer |
| 1094 ** to the [sqlite3_file] object associated with a particular database |
| 1095 ** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER]. |
| 1096 ** |
| 1097 ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]] |
| 1098 ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer |
| 1099 ** to the [sqlite3_file] object associated with the journal file (either |
| 1100 ** the [rollback journal] or the [write-ahead log]) for a particular database |
| 1101 ** connection. See also [SQLITE_FCNTL_FILE_POINTER]. |
| 1102 ** |
| 1103 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 1104 ** No longer in use. |
| 1105 ** |
| 1106 ** <li>[[SQLITE_FCNTL_SYNC]] |
| 1107 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and |
| 1108 ** sent to the VFS immediately before the xSync method is invoked on a |
| 1109 ** database file descriptor. Or, if the xSync method is not invoked |
| 1110 ** because the user has configured SQLite with |
| 1111 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place |
| 1112 ** of the xSync method. In most cases, the pointer argument passed with |
| 1113 ** this file-control is NULL. However, if the database file is being synced |
| 1114 ** as part of a multi-database commit, the argument points to a nul-terminated |
| 1115 ** string containing the transactions master-journal file name. VFSes that |
| 1116 ** do not need this signal should silently ignore this opcode. Applications |
| 1117 ** should not call [sqlite3_file_control()] with this opcode as doing so may |
| 1118 ** disrupt the operation of the specialized VFSes that do require it. |
| 1119 ** |
| 1120 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] |
| 1121 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite |
| 1122 ** and sent to the VFS after a transaction has been committed immediately |
| 1123 ** but before the database is unlocked. VFSes that do not need this signal |
| 1124 ** should silently ignore this opcode. Applications should not call |
| 1125 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the |
| 1126 ** operation of the specialized VFSes that do require it. |
| 1127 ** |
| 1128 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 1129 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 1130 ** retry counts and intervals for certain disk I/O operations for the |
| 1131 ** windows [VFS] in order to provide robustness in the presence of |
| 1132 ** anti-virus programs. By default, the windows VFS will retry file read, |
| 1133 ** file write, and file delete operations up to 10 times, with a delay |
| 1134 ** of 25 milliseconds before the first retry and with the delay increasing |
| 1135 ** by an additional 25 milliseconds with each subsequent retry. This |
| 1136 ** opcode allows these two values (10 retries and 25 milliseconds of delay) |
| 1137 ** to be adjusted. The values are changed for all database connections |
| 1138 ** within the same process. The argument is a pointer to an array of two |
| 1139 ** integers where the first integer i the new retry count and the second |
| 1140 ** integer is the delay. If either integer is negative, then the setting |
| 1141 ** is not changed but instead the prior value of that setting is written |
| 1142 ** into the array entry, allowing the current retry settings to be |
| 1143 ** interrogated. The zDbName parameter is ignored. |
| 1144 ** |
| 1145 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] |
| 1146 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the |
| 1147 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary |
| 1148 ** write ahead log and shared memory files used for transaction control |
| 1149 ** are automatically deleted when the latest connection to the database |
| 1150 ** closes. Setting persistent WAL mode causes those files to persist after |
| 1151 ** close. Persisting the files is useful when other processes that do not |
| 1152 ** have write permission on the directory containing the database file want |
| 1153 ** to read the database file, as the WAL and shared memory files must exist |
| 1154 ** in order for the database to be readable. The fourth parameter to |
| 1155 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
| 1156 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent |
| 1157 ** WAL mode. If the integer is -1, then it is overwritten with the current |
| 1158 ** WAL persistence setting. |
| 1159 ** |
| 1160 ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]] |
| 1161 ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the |
| 1162 ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting |
| 1163 ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the |
| 1164 ** xDeviceCharacteristics methods. The fourth parameter to |
| 1165 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. |
| 1166 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage |
| 1167 ** mode. If the integer is -1, then it is overwritten with the current |
| 1168 ** zero-damage mode setting. |
| 1169 ** |
| 1170 ** <li>[[SQLITE_FCNTL_OVERWRITE]] |
| 1171 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening |
| 1172 ** a write transaction to indicate that, unless it is rolled back for some |
| 1173 ** reason, the entire database file will be overwritten by the current |
| 1174 ** transaction. This is used by VACUUM operations. |
| 1175 ** |
| 1176 ** <li>[[SQLITE_FCNTL_VFSNAME]] |
| 1177 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of |
| 1178 ** all [VFSes] in the VFS stack. The names are of all VFS shims and the |
| 1179 ** final bottom-level VFS are written into memory obtained from |
| 1180 ** [sqlite3_malloc()] and the result is stored in the char* variable |
| 1181 ** that the fourth parameter of [sqlite3_file_control()] points to. |
| 1182 ** The caller is responsible for freeing the memory when done. As with |
| 1183 ** all file-control actions, there is no guarantee that this will actually |
| 1184 ** do anything. Callers should initialize the char* variable to a NULL |
| 1185 ** pointer in case this file-control is not implemented. This file-control |
| 1186 ** is intended for diagnostic use only. |
| 1187 ** |
| 1188 ** <li>[[SQLITE_FCNTL_VFS_POINTER]] |
| 1189 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level |
| 1190 ** [VFSes] currently in use. ^(The argument X in |
| 1191 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be |
| 1192 ** of type "[sqlite3_vfs] **". This opcodes will set *X |
| 1193 ** to a pointer to the top-level VFS.)^ |
| 1194 ** ^When there are multiple VFS shims in the stack, this opcode finds the |
| 1195 ** upper-most shim only. |
| 1196 ** |
| 1197 ** <li>[[SQLITE_FCNTL_PRAGMA]] |
| 1198 ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] |
| 1199 ** file control is sent to the open [sqlite3_file] object corresponding |
| 1200 ** to the database file to which the pragma statement refers. ^The argument |
| 1201 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of |
| 1202 ** pointers to strings (char**) in which the second element of the array |
| 1203 ** is the name of the pragma and the third element is the argument to the |
| 1204 ** pragma or NULL if the pragma has no argument. ^The handler for an |
| 1205 ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element |
| 1206 ** of the char** argument point to a string obtained from [sqlite3_mprintf()] |
| 1207 ** or the equivalent and that string will become the result of the pragma or |
| 1208 ** the error message if the pragma fails. ^If the |
| 1209 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal |
| 1210 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA] |
| 1211 ** file control returns [SQLITE_OK], then the parser assumes that the |
| 1212 ** VFS has handled the PRAGMA itself and the parser generates a no-op |
| 1213 ** prepared statement if result string is NULL, or that returns a copy |
| 1214 ** of the result string if the string is non-NULL. |
| 1215 ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns |
| 1216 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means |
| 1217 ** that the VFS encountered an error while handling the [PRAGMA] and the |
| 1218 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] |
| 1219 ** file control occurs at the beginning of pragma statement analysis and so |
| 1220 ** it is able to override built-in [PRAGMA] statements. |
| 1221 ** |
| 1222 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] |
| 1223 ** ^The [SQLITE_FCNTL_BUSYHANDLER] |
| 1224 ** file-control may be invoked by SQLite on the database file handle |
| 1225 ** shortly after it is opened in order to provide a custom VFS with access |
| 1226 ** to the connections busy-handler callback. The argument is of type (void **) |
| 1227 ** - an array of two (void *) values. The first (void *) actually points |
| 1228 ** to a function of type (int (*)(void *)). In order to invoke the connections |
| 1229 ** busy-handler, this function should be invoked with the second (void *) in |
| 1230 ** the array as the only argument. If it returns non-zero, then the operation |
| 1231 ** should be retried. If it returns zero, the custom VFS should abandon the |
| 1232 ** current operation. |
| 1233 ** |
| 1234 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]] |
| 1235 ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control |
| 1236 ** to have SQLite generate a |
| 1237 ** temporary filename using the same algorithm that is followed to generate |
| 1238 ** temporary filenames for TEMP tables and other internal uses. The |
| 1239 ** argument should be a char** which will be filled with the filename |
| 1240 ** written into memory obtained from [sqlite3_malloc()]. The caller should |
| 1241 ** invoke [sqlite3_free()] on the result to avoid a memory leak. |
| 1242 ** |
| 1243 ** <li>[[SQLITE_FCNTL_MMAP_SIZE]] |
| 1244 ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the |
| 1245 ** maximum number of bytes that will be used for memory-mapped I/O. |
| 1246 ** The argument is a pointer to a value of type sqlite3_int64 that |
| 1247 ** is an advisory maximum number of bytes in the file to memory map. The |
| 1248 ** pointer is overwritten with the old value. The limit is not changed if |
| 1249 ** the value originally pointed to is negative, and so the current limit |
| 1250 ** can be queried by passing in a pointer to a negative number. This |
| 1251 ** file-control is used internally to implement [PRAGMA mmap_size]. |
| 1252 ** |
| 1253 ** <li>[[SQLITE_FCNTL_TRACE]] |
| 1254 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information |
| 1255 ** to the VFS about what the higher layers of the SQLite stack are doing. |
| 1256 ** This file control is used by some VFS activity tracing [shims]. |
| 1257 ** The argument is a zero-terminated string. Higher layers in the |
| 1258 ** SQLite stack may generate instances of this file control if |
| 1259 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 1260 ** |
| 1261 ** <li>[[SQLITE_FCNTL_HAS_MOVED]] |
| 1262 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a |
| 1263 ** pointer to an integer and it writes a boolean into that integer depending |
| 1264 ** on whether or not the file has been renamed, moved, or deleted since it |
| 1265 ** was first opened. |
| 1266 ** |
| 1267 ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]] |
| 1268 ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the |
| 1269 ** underlying native file handle associated with a file handle. This file |
| 1270 ** control interprets its argument as a pointer to a native file handle and |
| 1271 ** writes the resulting value there. |
| 1272 ** |
| 1273 ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]] |
| 1274 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This |
| 1275 ** opcode causes the xFileControl method to swap the file handle with the one |
| 1276 ** pointed to by the pArg argument. This capability is used during testing |
| 1277 ** and only needs to be supported when SQLITE_TEST is defined. |
| 1278 ** |
| 1279 ** <li>[[SQLITE_FCNTL_WAL_BLOCK]] |
| 1280 ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might |
| 1281 ** be advantageous to block on the next WAL lock if the lock is not immediately |
| 1282 ** available. The WAL subsystem issues this signal during rare |
| 1283 ** circumstances in order to fix a problem with priority inversion. |
| 1284 ** Applications should <em>not</em> use this file-control. |
| 1285 ** |
| 1286 ** <li>[[SQLITE_FCNTL_ZIPVFS]] |
| 1287 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other |
| 1288 ** VFS should return SQLITE_NOTFOUND for this opcode. |
| 1289 ** |
| 1290 ** <li>[[SQLITE_FCNTL_RBU]] |
| 1291 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by |
| 1292 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for |
| 1293 ** this opcode. |
| 1294 ** </ul> |
| 1295 */ |
| 1296 #define SQLITE_FCNTL_LOCKSTATE 1 |
| 1297 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 |
| 1298 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 |
| 1299 #define SQLITE_FCNTL_LAST_ERRNO 4 |
| 1300 #define SQLITE_FCNTL_SIZE_HINT 5 |
| 1301 #define SQLITE_FCNTL_CHUNK_SIZE 6 |
| 1302 #define SQLITE_FCNTL_FILE_POINTER 7 |
| 1303 #define SQLITE_FCNTL_SYNC_OMITTED 8 |
| 1304 #define SQLITE_FCNTL_WIN32_AV_RETRY 9 |
| 1305 #define SQLITE_FCNTL_PERSIST_WAL 10 |
| 1306 #define SQLITE_FCNTL_OVERWRITE 11 |
| 1307 #define SQLITE_FCNTL_VFSNAME 12 |
| 1308 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 |
| 1309 #define SQLITE_FCNTL_PRAGMA 14 |
| 1310 #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 1311 #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 1312 #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 1313 #define SQLITE_FCNTL_TRACE 19 |
| 1314 #define SQLITE_FCNTL_HAS_MOVED 20 |
| 1315 #define SQLITE_FCNTL_SYNC 21 |
| 1316 #define SQLITE_FCNTL_COMMIT_PHASETWO 22 |
| 1317 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 |
| 1318 #define SQLITE_FCNTL_WAL_BLOCK 24 |
| 1319 #define SQLITE_FCNTL_ZIPVFS 25 |
| 1320 #define SQLITE_FCNTL_RBU 26 |
| 1321 #define SQLITE_FCNTL_VFS_POINTER 27 |
| 1322 #define SQLITE_FCNTL_JOURNAL_POINTER 28 |
| 1323 #define SQLITE_FCNTL_WIN32_GET_HANDLE 29 |
| 1324 #define SQLITE_FCNTL_PDB 30 |
| 1325 |
| 1326 /* deprecated names */ |
| 1327 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1328 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1329 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| 1330 |
| 1331 |
| 1332 /* |
| 1333 ** CAPI3REF: Mutex Handle |
| 1334 ** |
| 1335 ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| 1336 ** abstract type for a mutex object. The SQLite core never looks |
| 1337 ** at the internal representation of an [sqlite3_mutex]. It only |
| 1338 ** deals with pointers to the [sqlite3_mutex] object. |
| 1339 ** |
| 1340 ** Mutexes are created using [sqlite3_mutex_alloc()]. |
| 1341 */ |
| 1342 typedef struct sqlite3_mutex sqlite3_mutex; |
| 1343 |
| 1344 /* |
| 1345 ** CAPI3REF: Loadable Extension Thunk |
| 1346 ** |
| 1347 ** A pointer to the opaque sqlite3_api_routines structure is passed as |
| 1348 ** the third parameter to entry points of [loadable extensions]. This |
| 1349 ** structure must be typedefed in order to work around compiler warnings |
| 1350 ** on some platforms. |
| 1351 */ |
| 1352 typedef struct sqlite3_api_routines sqlite3_api_routines; |
| 1353 |
| 1354 /* |
| 1355 ** CAPI3REF: OS Interface Object |
| 1356 ** |
| 1357 ** An instance of the sqlite3_vfs object defines the interface between |
| 1358 ** the SQLite core and the underlying operating system. The "vfs" |
| 1359 ** in the name of the object stands for "virtual file system". See |
| 1360 ** the [VFS | VFS documentation] for further information. |
| 1361 ** |
| 1362 ** The value of the iVersion field is initially 1 but may be larger in |
| 1363 ** future versions of SQLite. Additional fields may be appended to this |
| 1364 ** object when the iVersion value is increased. Note that the structure |
| 1365 ** of the sqlite3_vfs object changes in the transaction between |
| 1366 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not |
| 1367 ** modified. |
| 1368 ** |
| 1369 ** The szOsFile field is the size of the subclassed [sqlite3_file] |
| 1370 ** structure used by this VFS. mxPathname is the maximum length of |
| 1371 ** a pathname in this VFS. |
| 1372 ** |
| 1373 ** Registered sqlite3_vfs objects are kept on a linked list formed by |
| 1374 ** the pNext pointer. The [sqlite3_vfs_register()] |
| 1375 ** and [sqlite3_vfs_unregister()] interfaces manage this list |
| 1376 ** in a thread-safe way. The [sqlite3_vfs_find()] interface |
| 1377 ** searches the list. Neither the application code nor the VFS |
| 1378 ** implementation should use the pNext pointer. |
| 1379 ** |
| 1380 ** The pNext field is the only field in the sqlite3_vfs |
| 1381 ** structure that SQLite will ever modify. SQLite will only access |
| 1382 ** or modify this field while holding a particular static mutex. |
| 1383 ** The application should never modify anything within the sqlite3_vfs |
| 1384 ** object once the object has been registered. |
| 1385 ** |
| 1386 ** The zName field holds the name of the VFS module. The name must |
| 1387 ** be unique across all VFS modules. |
| 1388 ** |
| 1389 ** [[sqlite3_vfs.xOpen]] |
| 1390 ** ^SQLite guarantees that the zFilename parameter to xOpen |
| 1391 ** is either a NULL pointer or string obtained |
| 1392 ** from xFullPathname() with an optional suffix added. |
| 1393 ** ^If a suffix is added to the zFilename parameter, it will |
| 1394 ** consist of a single "-" character followed by no more than |
| 1395 ** 11 alphanumeric and/or "-" characters. |
| 1396 ** ^SQLite further guarantees that |
| 1397 ** the string will be valid and unchanged until xClose() is |
| 1398 ** called. Because of the previous sentence, |
| 1399 ** the [sqlite3_file] can safely store a pointer to the |
| 1400 ** filename if it needs to remember the filename for some reason. |
| 1401 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen |
| 1402 ** must invent its own temporary name for the file. ^Whenever the |
| 1403 ** xFilename parameter is NULL it will also be the case that the |
| 1404 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. |
| 1405 ** |
| 1406 ** The flags argument to xOpen() includes all bits set in |
| 1407 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] |
| 1408 ** or [sqlite3_open16()] is used, then flags includes at least |
| 1409 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. |
| 1410 ** If xOpen() opens a file read-only then it sets *pOutFlags to |
| 1411 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. |
| 1412 ** |
| 1413 ** ^(SQLite will also add one of the following flags to the xOpen() |
| 1414 ** call, depending on the object being opened: |
| 1415 ** |
| 1416 ** <ul> |
| 1417 ** <li> [SQLITE_OPEN_MAIN_DB] |
| 1418 ** <li> [SQLITE_OPEN_MAIN_JOURNAL] |
| 1419 ** <li> [SQLITE_OPEN_TEMP_DB] |
| 1420 ** <li> [SQLITE_OPEN_TEMP_JOURNAL] |
| 1421 ** <li> [SQLITE_OPEN_TRANSIENT_DB] |
| 1422 ** <li> [SQLITE_OPEN_SUBJOURNAL] |
| 1423 ** <li> [SQLITE_OPEN_MASTER_JOURNAL] |
| 1424 ** <li> [SQLITE_OPEN_WAL] |
| 1425 ** </ul>)^ |
| 1426 ** |
| 1427 ** The file I/O implementation can use the object type flags to |
| 1428 ** change the way it deals with files. For example, an application |
| 1429 ** that does not care about crash recovery or rollback might make |
| 1430 ** the open of a journal file a no-op. Writes to this journal would |
| 1431 ** also be no-ops, and any attempt to read the journal would return |
| 1432 ** SQLITE_IOERR. Or the implementation might recognize that a database |
| 1433 ** file will be doing page-aligned sector reads and writes in a random |
| 1434 ** order and set up its I/O subsystem accordingly. |
| 1435 ** |
| 1436 ** SQLite might also add one of the following flags to the xOpen method: |
| 1437 ** |
| 1438 ** <ul> |
| 1439 ** <li> [SQLITE_OPEN_DELETEONCLOSE] |
| 1440 ** <li> [SQLITE_OPEN_EXCLUSIVE] |
| 1441 ** </ul> |
| 1442 ** |
| 1443 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be |
| 1444 ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] |
| 1445 ** will be set for TEMP databases and their journals, transient |
| 1446 ** databases, and subjournals. |
| 1447 ** |
| 1448 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction |
| 1449 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly |
| 1450 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() |
| 1451 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the |
| 1452 ** SQLITE_OPEN_CREATE, is used to indicate that file should always |
| 1453 ** be created, and that it is an error if it already exists. |
| 1454 ** It is <i>not</i> used to indicate the file should be opened |
| 1455 ** for exclusive access. |
| 1456 ** |
| 1457 ** ^At least szOsFile bytes of memory are allocated by SQLite |
| 1458 ** to hold the [sqlite3_file] structure passed as the third |
| 1459 ** argument to xOpen. The xOpen method does not have to |
| 1460 ** allocate the structure; it should just fill it in. Note that |
| 1461 ** the xOpen method must set the sqlite3_file.pMethods to either |
| 1462 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do |
| 1463 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods |
| 1464 ** element will be valid after xOpen returns regardless of the success |
| 1465 ** or failure of the xOpen call. |
| 1466 ** |
| 1467 ** [[sqlite3_vfs.xAccess]] |
| 1468 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] |
| 1469 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to |
| 1470 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] |
| 1471 ** to test whether a file is at least readable. The file can be a |
| 1472 ** directory. |
| 1473 ** |
| 1474 ** ^SQLite will always allocate at least mxPathname+1 bytes for the |
| 1475 ** output buffer xFullPathname. The exact size of the output buffer |
| 1476 ** is also passed as a parameter to both methods. If the output buffer |
| 1477 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is |
| 1478 ** handled as a fatal error by SQLite, vfs implementations should endeavor |
| 1479 ** to prevent this by setting mxPathname to a sufficiently large value. |
| 1480 ** |
| 1481 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() |
| 1482 ** interfaces are not strictly a part of the filesystem, but they are |
| 1483 ** included in the VFS structure for completeness. |
| 1484 ** The xRandomness() function attempts to return nBytes bytes |
| 1485 ** of good-quality randomness into zOut. The return value is |
| 1486 ** the actual number of bytes of randomness obtained. |
| 1487 ** The xSleep() method causes the calling thread to sleep for at |
| 1488 ** least the number of microseconds given. ^The xCurrentTime() |
| 1489 ** method returns a Julian Day Number for the current date and time as |
| 1490 ** a floating point value. |
| 1491 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian |
| 1492 ** Day Number multiplied by 86400000 (the number of milliseconds in |
| 1493 ** a 24-hour day). |
| 1494 ** ^SQLite will use the xCurrentTimeInt64() method to get the current |
| 1495 ** date and time if that method is available (if iVersion is 2 or |
| 1496 ** greater and the function pointer is not NULL) and will fall back |
| 1497 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. |
| 1498 ** |
| 1499 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces |
| 1500 ** are not used by the SQLite core. These optional interfaces are provided |
| 1501 ** by some VFSes to facilitate testing of the VFS code. By overriding |
| 1502 ** system calls with functions under its control, a test program can |
| 1503 ** simulate faults and error conditions that would otherwise be difficult |
| 1504 ** or impossible to induce. The set of system calls that can be overridden |
| 1505 ** varies from one VFS to another, and from one version of the same VFS to the |
| 1506 ** next. Applications that use these interfaces must be prepared for any |
| 1507 ** or all of these interfaces to be NULL or for their behavior to change |
| 1508 ** from one release to the next. Applications must not attempt to access |
| 1509 ** any of these methods if the iVersion of the VFS is less than 3. |
| 1510 */ |
| 1511 typedef struct sqlite3_vfs sqlite3_vfs; |
| 1512 typedef void (*sqlite3_syscall_ptr)(void); |
| 1513 struct sqlite3_vfs { |
| 1514 int iVersion; /* Structure version number (currently 3) */ |
| 1515 int szOsFile; /* Size of subclassed sqlite3_file */ |
| 1516 int mxPathname; /* Maximum file pathname length */ |
| 1517 sqlite3_vfs *pNext; /* Next registered VFS */ |
| 1518 const char *zName; /* Name of this virtual file system */ |
| 1519 void *pAppData; /* Pointer to application-specific data */ |
| 1520 int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, |
| 1521 int flags, int *pOutFlags); |
| 1522 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); |
| 1523 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); |
| 1524 int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); |
| 1525 void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); |
| 1526 void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); |
| 1527 void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); |
| 1528 void (*xDlClose)(sqlite3_vfs*, void*); |
| 1529 int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); |
| 1530 int (*xSleep)(sqlite3_vfs*, int microseconds); |
| 1531 int (*xCurrentTime)(sqlite3_vfs*, double*); |
| 1532 int (*xGetLastError)(sqlite3_vfs*, int, char *); |
| 1533 /* |
| 1534 ** The methods above are in version 1 of the sqlite_vfs object |
| 1535 ** definition. Those that follow are added in version 2 or later |
| 1536 */ |
| 1537 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); |
| 1538 /* |
| 1539 ** The methods above are in versions 1 and 2 of the sqlite_vfs object. |
| 1540 ** Those below are for version 3 and greater. |
| 1541 */ |
| 1542 int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); |
| 1543 sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); |
| 1544 const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); |
| 1545 /* |
| 1546 ** The methods above are in versions 1 through 3 of the sqlite_vfs object. |
| 1547 ** New fields may be appended in future versions. The iVersion |
| 1548 ** value will increment whenever this happens. |
| 1549 */ |
| 1550 }; |
| 1551 |
| 1552 /* |
| 1553 ** CAPI3REF: Flags for the xAccess VFS method |
| 1554 ** |
| 1555 ** These integer constants can be used as the third parameter to |
| 1556 ** the xAccess method of an [sqlite3_vfs] object. They determine |
| 1557 ** what kind of permissions the xAccess method is looking for. |
| 1558 ** With SQLITE_ACCESS_EXISTS, the xAccess method |
| 1559 ** simply checks whether the file exists. |
| 1560 ** With SQLITE_ACCESS_READWRITE, the xAccess method |
| 1561 ** checks whether the named directory is both readable and writable |
| 1562 ** (in other words, if files can be added, removed, and renamed within |
| 1563 ** the directory). |
| 1564 ** The SQLITE_ACCESS_READWRITE constant is currently used only by the |
| 1565 ** [temp_store_directory pragma], though this could change in a future |
| 1566 ** release of SQLite. |
| 1567 ** With SQLITE_ACCESS_READ, the xAccess method |
| 1568 ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is |
| 1569 ** currently unused, though it might be used in a future release of |
| 1570 ** SQLite. |
| 1571 */ |
| 1572 #define SQLITE_ACCESS_EXISTS 0 |
| 1573 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ |
| 1574 #define SQLITE_ACCESS_READ 2 /* Unused */ |
| 1575 |
| 1576 /* |
| 1577 ** CAPI3REF: Flags for the xShmLock VFS method |
| 1578 ** |
| 1579 ** These integer constants define the various locking operations |
| 1580 ** allowed by the xShmLock method of [sqlite3_io_methods]. The |
| 1581 ** following are the only legal combinations of flags to the |
| 1582 ** xShmLock method: |
| 1583 ** |
| 1584 ** <ul> |
| 1585 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED |
| 1586 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE |
| 1587 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED |
| 1588 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE |
| 1589 ** </ul> |
| 1590 ** |
| 1591 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as |
| 1592 ** was given on the corresponding lock. |
| 1593 ** |
| 1594 ** The xShmLock method can transition between unlocked and SHARED or |
| 1595 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED |
| 1596 ** and EXCLUSIVE. |
| 1597 */ |
| 1598 #define SQLITE_SHM_UNLOCK 1 |
| 1599 #define SQLITE_SHM_LOCK 2 |
| 1600 #define SQLITE_SHM_SHARED 4 |
| 1601 #define SQLITE_SHM_EXCLUSIVE 8 |
| 1602 |
| 1603 /* |
| 1604 ** CAPI3REF: Maximum xShmLock index |
| 1605 ** |
| 1606 ** The xShmLock method on [sqlite3_io_methods] may use values |
| 1607 ** between 0 and this upper bound as its "offset" argument. |
| 1608 ** The SQLite core will never attempt to acquire or release a |
| 1609 ** lock outside of this range |
| 1610 */ |
| 1611 #define SQLITE_SHM_NLOCK 8 |
| 1612 |
| 1613 |
| 1614 /* |
| 1615 ** CAPI3REF: Initialize The SQLite Library |
| 1616 ** |
| 1617 ** ^The sqlite3_initialize() routine initializes the |
| 1618 ** SQLite library. ^The sqlite3_shutdown() routine |
| 1619 ** deallocates any resources that were allocated by sqlite3_initialize(). |
| 1620 ** These routines are designed to aid in process initialization and |
| 1621 ** shutdown on embedded systems. Workstation applications using |
| 1622 ** SQLite normally do not need to invoke either of these routines. |
| 1623 ** |
| 1624 ** A call to sqlite3_initialize() is an "effective" call if it is |
| 1625 ** the first time sqlite3_initialize() is invoked during the lifetime of |
| 1626 ** the process, or if it is the first time sqlite3_initialize() is invoked |
| 1627 ** following a call to sqlite3_shutdown(). ^(Only an effective call |
| 1628 ** of sqlite3_initialize() does any initialization. All other calls |
| 1629 ** are harmless no-ops.)^ |
| 1630 ** |
| 1631 ** A call to sqlite3_shutdown() is an "effective" call if it is the first |
| 1632 ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only |
| 1633 ** an effective call to sqlite3_shutdown() does any deinitialization. |
| 1634 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ |
| 1635 ** |
| 1636 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() |
| 1637 ** is not. The sqlite3_shutdown() interface must only be called from a |
| 1638 ** single thread. All open [database connections] must be closed and all |
| 1639 ** other SQLite resources must be deallocated prior to invoking |
| 1640 ** sqlite3_shutdown(). |
| 1641 ** |
| 1642 ** Among other things, ^sqlite3_initialize() will invoke |
| 1643 ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() |
| 1644 ** will invoke sqlite3_os_end(). |
| 1645 ** |
| 1646 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. |
| 1647 ** ^If for some reason, sqlite3_initialize() is unable to initialize |
| 1648 ** the library (perhaps it is unable to allocate a needed resource such |
| 1649 ** as a mutex) it returns an [error code] other than [SQLITE_OK]. |
| 1650 ** |
| 1651 ** ^The sqlite3_initialize() routine is called internally by many other |
| 1652 ** SQLite interfaces so that an application usually does not need to |
| 1653 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] |
| 1654 ** calls sqlite3_initialize() so the SQLite library will be automatically |
| 1655 ** initialized when [sqlite3_open()] is called if it has not be initialized |
| 1656 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] |
| 1657 ** compile-time option, then the automatic calls to sqlite3_initialize() |
| 1658 ** are omitted and the application must call sqlite3_initialize() directly |
| 1659 ** prior to using any other SQLite interface. For maximum portability, |
| 1660 ** it is recommended that applications always invoke sqlite3_initialize() |
| 1661 ** directly prior to using any other SQLite interface. Future releases |
| 1662 ** of SQLite may require this. In other words, the behavior exhibited |
| 1663 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the |
| 1664 ** default behavior in some future release of SQLite. |
| 1665 ** |
| 1666 ** The sqlite3_os_init() routine does operating-system specific |
| 1667 ** initialization of the SQLite library. The sqlite3_os_end() |
| 1668 ** routine undoes the effect of sqlite3_os_init(). Typical tasks |
| 1669 ** performed by these routines include allocation or deallocation |
| 1670 ** of static resources, initialization of global variables, |
| 1671 ** setting up a default [sqlite3_vfs] module, or setting up |
| 1672 ** a default configuration using [sqlite3_config()]. |
| 1673 ** |
| 1674 ** The application should never invoke either sqlite3_os_init() |
| 1675 ** or sqlite3_os_end() directly. The application should only invoke |
| 1676 ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() |
| 1677 ** interface is called automatically by sqlite3_initialize() and |
| 1678 ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate |
| 1679 ** implementations for sqlite3_os_init() and sqlite3_os_end() |
| 1680 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. |
| 1681 ** When [custom builds | built for other platforms] |
| 1682 ** (using the [SQLITE_OS_OTHER=1] compile-time |
| 1683 ** option) the application must supply a suitable implementation for |
| 1684 ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied |
| 1685 ** implementation of sqlite3_os_init() or sqlite3_os_end() |
| 1686 ** must return [SQLITE_OK] on success and some other [error code] upon |
| 1687 ** failure. |
| 1688 */ |
| 1689 SQLITE_API int sqlite3_initialize(void); |
| 1690 SQLITE_API int sqlite3_shutdown(void); |
| 1691 SQLITE_API int sqlite3_os_init(void); |
| 1692 SQLITE_API int sqlite3_os_end(void); |
| 1693 |
| 1694 /* |
| 1695 ** CAPI3REF: Configuring The SQLite Library |
| 1696 ** |
| 1697 ** The sqlite3_config() interface is used to make global configuration |
| 1698 ** changes to SQLite in order to tune SQLite to the specific needs of |
| 1699 ** the application. The default configuration is recommended for most |
| 1700 ** applications and so this routine is usually not necessary. It is |
| 1701 ** provided to support rare applications with unusual needs. |
| 1702 ** |
| 1703 ** <b>The sqlite3_config() interface is not threadsafe. The application |
| 1704 ** must ensure that no other SQLite interfaces are invoked by other |
| 1705 ** threads while sqlite3_config() is running.</b> |
| 1706 ** |
| 1707 ** The sqlite3_config() interface |
| 1708 ** may only be invoked prior to library initialization using |
| 1709 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. |
| 1710 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before |
| 1711 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. |
| 1712 ** Note, however, that ^sqlite3_config() can be called as part of the |
| 1713 ** implementation of an application-defined [sqlite3_os_init()]. |
| 1714 ** |
| 1715 ** The first argument to sqlite3_config() is an integer |
| 1716 ** [configuration option] that determines |
| 1717 ** what property of SQLite is to be configured. Subsequent arguments |
| 1718 ** vary depending on the [configuration option] |
| 1719 ** in the first argument. |
| 1720 ** |
| 1721 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. |
| 1722 ** ^If the option is unknown or SQLite is unable to set the option |
| 1723 ** then this routine returns a non-zero [error code]. |
| 1724 */ |
| 1725 SQLITE_API int sqlite3_config(int, ...); |
| 1726 |
| 1727 /* |
| 1728 ** CAPI3REF: Configure database connections |
| 1729 ** METHOD: sqlite3 |
| 1730 ** |
| 1731 ** The sqlite3_db_config() interface is used to make configuration |
| 1732 ** changes to a [database connection]. The interface is similar to |
| 1733 ** [sqlite3_config()] except that the changes apply to a single |
| 1734 ** [database connection] (specified in the first argument). |
| 1735 ** |
| 1736 ** The second argument to sqlite3_db_config(D,V,...) is the |
| 1737 ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code |
| 1738 ** that indicates what aspect of the [database connection] is being configured. |
| 1739 ** Subsequent arguments vary depending on the configuration verb. |
| 1740 ** |
| 1741 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1742 ** the call is considered successful. |
| 1743 */ |
| 1744 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); |
| 1745 |
| 1746 /* |
| 1747 ** CAPI3REF: Memory Allocation Routines |
| 1748 ** |
| 1749 ** An instance of this object defines the interface between SQLite |
| 1750 ** and low-level memory allocation routines. |
| 1751 ** |
| 1752 ** This object is used in only one place in the SQLite interface. |
| 1753 ** A pointer to an instance of this object is the argument to |
| 1754 ** [sqlite3_config()] when the configuration option is |
| 1755 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. |
| 1756 ** By creating an instance of this object |
| 1757 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) |
| 1758 ** during configuration, an application can specify an alternative |
| 1759 ** memory allocation subsystem for SQLite to use for all of its |
| 1760 ** dynamic memory needs. |
| 1761 ** |
| 1762 ** Note that SQLite comes with several [built-in memory allocators] |
| 1763 ** that are perfectly adequate for the overwhelming majority of applications |
| 1764 ** and that this object is only useful to a tiny minority of applications |
| 1765 ** with specialized memory allocation requirements. This object is |
| 1766 ** also used during testing of SQLite in order to specify an alternative |
| 1767 ** memory allocator that simulates memory out-of-memory conditions in |
| 1768 ** order to verify that SQLite recovers gracefully from such |
| 1769 ** conditions. |
| 1770 ** |
| 1771 ** The xMalloc, xRealloc, and xFree methods must work like the |
| 1772 ** malloc(), realloc() and free() functions from the standard C library. |
| 1773 ** ^SQLite guarantees that the second argument to |
| 1774 ** xRealloc is always a value returned by a prior call to xRoundup. |
| 1775 ** |
| 1776 ** xSize should return the allocated size of a memory allocation |
| 1777 ** previously obtained from xMalloc or xRealloc. The allocated size |
| 1778 ** is always at least as big as the requested size but may be larger. |
| 1779 ** |
| 1780 ** The xRoundup method returns what would be the allocated size of |
| 1781 ** a memory allocation given a particular requested size. Most memory |
| 1782 ** allocators round up memory allocations at least to the next multiple |
| 1783 ** of 8. Some allocators round up to a larger multiple or to a power of 2. |
| 1784 ** Every memory allocation request coming in through [sqlite3_malloc()] |
| 1785 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, |
| 1786 ** that causes the corresponding memory allocation to fail. |
| 1787 ** |
| 1788 ** The xInit method initializes the memory allocator. For example, |
| 1789 ** it might allocate any require mutexes or initialize internal data |
| 1790 ** structures. The xShutdown method is invoked (indirectly) by |
| 1791 ** [sqlite3_shutdown()] and should deallocate any resources acquired |
| 1792 ** by xInit. The pAppData pointer is used as the only parameter to |
| 1793 ** xInit and xShutdown. |
| 1794 ** |
| 1795 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes |
| 1796 ** the xInit method, so the xInit method need not be threadsafe. The |
| 1797 ** xShutdown method is only called from [sqlite3_shutdown()] so it does |
| 1798 ** not need to be threadsafe either. For all other methods, SQLite |
| 1799 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the |
| 1800 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which |
| 1801 ** it is by default) and so the methods are automatically serialized. |
| 1802 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other |
| 1803 ** methods must be threadsafe or else make their own arrangements for |
| 1804 ** serialization. |
| 1805 ** |
| 1806 ** SQLite will never invoke xInit() more than once without an intervening |
| 1807 ** call to xShutdown(). |
| 1808 */ |
| 1809 typedef struct sqlite3_mem_methods sqlite3_mem_methods; |
| 1810 struct sqlite3_mem_methods { |
| 1811 void *(*xMalloc)(int); /* Memory allocation function */ |
| 1812 void (*xFree)(void*); /* Free a prior allocation */ |
| 1813 void *(*xRealloc)(void*,int); /* Resize an allocation */ |
| 1814 int (*xSize)(void*); /* Return the size of an allocation */ |
| 1815 int (*xRoundup)(int); /* Round up request size to allocation size */ |
| 1816 int (*xInit)(void*); /* Initialize the memory allocator */ |
| 1817 void (*xShutdown)(void*); /* Deinitialize the memory allocator */ |
| 1818 void *pAppData; /* Argument to xInit() and xShutdown() */ |
| 1819 }; |
| 1820 |
| 1821 /* |
| 1822 ** CAPI3REF: Configuration Options |
| 1823 ** KEYWORDS: {configuration option} |
| 1824 ** |
| 1825 ** These constants are the available integer configuration options that |
| 1826 ** can be passed as the first argument to the [sqlite3_config()] interface. |
| 1827 ** |
| 1828 ** New configuration options may be added in future releases of SQLite. |
| 1829 ** Existing configuration options might be discontinued. Applications |
| 1830 ** should check the return code from [sqlite3_config()] to make sure that |
| 1831 ** the call worked. The [sqlite3_config()] interface will return a |
| 1832 ** non-zero [error code] if a discontinued or unsupported configuration option |
| 1833 ** is invoked. |
| 1834 ** |
| 1835 ** <dl> |
| 1836 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> |
| 1837 ** <dd>There are no arguments to this option. ^This option sets the |
| 1838 ** [threading mode] to Single-thread. In other words, it disables |
| 1839 ** all mutexing and puts SQLite into a mode where it can only be used |
| 1840 ** by a single thread. ^If SQLite is compiled with |
| 1841 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1842 ** it is not possible to change the [threading mode] from its default |
| 1843 ** value of Single-thread and so [sqlite3_config()] will return |
| 1844 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD |
| 1845 ** configuration option.</dd> |
| 1846 ** |
| 1847 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> |
| 1848 ** <dd>There are no arguments to this option. ^This option sets the |
| 1849 ** [threading mode] to Multi-thread. In other words, it disables |
| 1850 ** mutexing on [database connection] and [prepared statement] objects. |
| 1851 ** The application is responsible for serializing access to |
| 1852 ** [database connections] and [prepared statements]. But other mutexes |
| 1853 ** are enabled so that SQLite will be safe to use in a multi-threaded |
| 1854 ** environment as long as no two threads attempt to use the same |
| 1855 ** [database connection] at the same time. ^If SQLite is compiled with |
| 1856 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1857 ** it is not possible to set the Multi-thread [threading mode] and |
| 1858 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1859 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> |
| 1860 ** |
| 1861 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> |
| 1862 ** <dd>There are no arguments to this option. ^This option sets the |
| 1863 ** [threading mode] to Serialized. In other words, this option enables |
| 1864 ** all mutexes including the recursive |
| 1865 ** mutexes on [database connection] and [prepared statement] objects. |
| 1866 ** In this mode (which is the default when SQLite is compiled with |
| 1867 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access |
| 1868 ** to [database connections] and [prepared statements] so that the |
| 1869 ** application is free to use the same [database connection] or the |
| 1870 ** same [prepared statement] in different threads at the same time. |
| 1871 ** ^If SQLite is compiled with |
| 1872 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1873 ** it is not possible to set the Serialized [threading mode] and |
| 1874 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the |
| 1875 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> |
| 1876 ** |
| 1877 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> |
| 1878 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is |
| 1879 ** a pointer to an instance of the [sqlite3_mem_methods] structure. |
| 1880 ** The argument specifies |
| 1881 ** alternative low-level memory allocation routines to be used in place of |
| 1882 ** the memory allocation routines built into SQLite.)^ ^SQLite makes |
| 1883 ** its own private copy of the content of the [sqlite3_mem_methods] structure |
| 1884 ** before the [sqlite3_config()] call returns.</dd> |
| 1885 ** |
| 1886 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> |
| 1887 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which |
| 1888 ** is a pointer to an instance of the [sqlite3_mem_methods] structure. |
| 1889 ** The [sqlite3_mem_methods] |
| 1890 ** structure is filled with the currently defined memory allocation routines.)^ |
| 1891 ** This option can be used to overload the default memory allocation |
| 1892 ** routines with a wrapper that simulations memory allocation failure or |
| 1893 ** tracks memory usage, for example. </dd> |
| 1894 ** |
| 1895 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> |
| 1896 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int, |
| 1897 ** interpreted as a boolean, which enables or disables the collection of |
| 1898 ** memory allocation statistics. ^(When memory allocation statistics are |
| 1899 ** disabled, the following SQLite interfaces become non-operational: |
| 1900 ** <ul> |
| 1901 ** <li> [sqlite3_memory_used()] |
| 1902 ** <li> [sqlite3_memory_highwater()] |
| 1903 ** <li> [sqlite3_soft_heap_limit64()] |
| 1904 ** <li> [sqlite3_status64()] |
| 1905 ** </ul>)^ |
| 1906 ** ^Memory allocation statistics are enabled by default unless SQLite is |
| 1907 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory |
| 1908 ** allocation statistics are disabled by default. |
| 1909 ** </dd> |
| 1910 ** |
| 1911 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> |
| 1912 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer |
| 1913 ** that SQLite can use for scratch memory. ^(There are three arguments |
| 1914 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte |
| 1915 ** aligned memory buffer from which the scratch allocations will be |
| 1916 ** drawn, the size of each scratch allocation (sz), |
| 1917 ** and the maximum number of scratch allocations (N).)^ |
| 1918 ** The first argument must be a pointer to an 8-byte aligned buffer |
| 1919 ** of at least sz*N bytes of memory. |
| 1920 ** ^SQLite will not use more than one scratch buffers per thread. |
| 1921 ** ^SQLite will never request a scratch buffer that is more than 6 |
| 1922 ** times the database page size. |
| 1923 ** ^If SQLite needs needs additional |
| 1924 ** scratch memory beyond what is provided by this configuration option, then |
| 1925 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p> |
| 1926 ** ^When the application provides any amount of scratch memory using |
| 1927 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large |
| 1928 ** [sqlite3_malloc|heap allocations]. |
| 1929 ** This can help [Robson proof|prevent memory allocation failures] due to heap |
| 1930 ** fragmentation in low-memory embedded systems. |
| 1931 ** </dd> |
| 1932 ** |
| 1933 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> |
| 1934 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool |
| 1935 ** that SQLite can use for the database page cache with the default page |
| 1936 ** cache implementation. |
| 1937 ** This configuration option is a no-op if an application-define page |
| 1938 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]. |
| 1939 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to |
| 1940 ** 8-byte aligned memory (pMem), the size of each page cache line (sz), |
| 1941 ** and the number of cache lines (N). |
| 1942 ** The sz argument should be the size of the largest database page |
| 1943 ** (a power of two between 512 and 65536) plus some extra bytes for each |
| 1944 ** page header. ^The number of extra bytes needed by the page header |
| 1945 ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ]. |
| 1946 ** ^It is harmless, apart from the wasted memory, |
| 1947 ** for the sz parameter to be larger than necessary. The pMem |
| 1948 ** argument must be either a NULL pointer or a pointer to an 8-byte |
| 1949 ** aligned block of memory of at least sz*N bytes, otherwise |
| 1950 ** subsequent behavior is undefined. |
| 1951 ** ^When pMem is not NULL, SQLite will strive to use the memory provided |
| 1952 ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if |
| 1953 ** a page cache line is larger than sz bytes or if all of the pMem buffer |
| 1954 ** is exhausted. |
| 1955 ** ^If pMem is NULL and N is non-zero, then each database connection |
| 1956 ** does an initial bulk allocation for page cache memory |
| 1957 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or |
| 1958 ** of -1024*N bytes if N is negative, . ^If additional |
| 1959 ** page cache memory is needed beyond what is provided by the initial |
| 1960 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each |
| 1961 ** additional cache line. </dd> |
| 1962 ** |
| 1963 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> |
| 1964 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer |
| 1965 ** that SQLite will use for all of its dynamic memory allocation needs |
| 1966 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and |
| 1967 ** [SQLITE_CONFIG_PAGECACHE]. |
| 1968 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled |
| 1969 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns |
| 1970 ** [SQLITE_ERROR] if invoked otherwise. |
| 1971 ** ^There are three arguments to SQLITE_CONFIG_HEAP: |
| 1972 ** An 8-byte aligned pointer to the memory, |
| 1973 ** the number of bytes in the memory buffer, and the minimum allocation size. |
| 1974 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts |
| 1975 ** to using its default memory allocator (the system malloc() implementation), |
| 1976 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the |
| 1977 ** memory pointer is not NULL then the alternative memory |
| 1978 ** allocator is engaged to handle all of SQLites memory allocation needs. |
| 1979 ** The first pointer (the memory pointer) must be aligned to an 8-byte |
| 1980 ** boundary or subsequent behavior of SQLite will be undefined. |
| 1981 ** The minimum allocation size is capped at 2**12. Reasonable values |
| 1982 ** for the minimum allocation size are 2**5 through 2**8.</dd> |
| 1983 ** |
| 1984 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> |
| 1985 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a |
| 1986 ** pointer to an instance of the [sqlite3_mutex_methods] structure. |
| 1987 ** The argument specifies alternative low-level mutex routines to be used |
| 1988 ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of |
| 1989 ** the content of the [sqlite3_mutex_methods] structure before the call to |
| 1990 ** [sqlite3_config()] returns. ^If SQLite is compiled with |
| 1991 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 1992 ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 1993 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will |
| 1994 ** return [SQLITE_ERROR].</dd> |
| 1995 ** |
| 1996 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> |
| 1997 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which |
| 1998 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The |
| 1999 ** [sqlite3_mutex_methods] |
| 2000 ** structure is filled with the currently defined mutex routines.)^ |
| 2001 ** This option can be used to overload the default mutex allocation |
| 2002 ** routines with a wrapper used to track mutex usage for performance |
| 2003 ** profiling or testing, for example. ^If SQLite is compiled with |
| 2004 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then |
| 2005 ** the entire mutexing subsystem is omitted from the build and hence calls to |
| 2006 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 2007 ** return [SQLITE_ERROR].</dd> |
| 2008 ** |
| 2009 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 2010 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine |
| 2011 ** the default size of lookaside memory on each [database connection]. |
| 2012 ** The first argument is the |
| 2013 ** size of each lookaside buffer slot and the second is the number of |
| 2014 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE |
| 2015 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] |
| 2016 ** option to [sqlite3_db_config()] can be used to change the lookaside |
| 2017 ** configuration on individual connections.)^ </dd> |
| 2018 ** |
| 2019 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 2020 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is |
| 2021 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies |
| 2022 ** the interface to a custom page cache implementation.)^ |
| 2023 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> |
| 2024 ** |
| 2025 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> |
| 2026 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which |
| 2027 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of |
| 2028 ** the current page cache implementation into that object.)^ </dd> |
| 2029 ** |
| 2030 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> |
| 2031 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite |
| 2032 ** global [error log]. |
| 2033 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a |
| 2034 ** function with a call signature of void(*)(void*,int,const char*), |
| 2035 ** and a pointer to void. ^If the function pointer is not NULL, it is |
| 2036 ** invoked by [sqlite3_log()] to process each logging event. ^If the |
| 2037 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. |
| 2038 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is |
| 2039 ** passed through as the first parameter to the application-defined logger |
| 2040 ** function whenever that function is invoked. ^The second parameter to |
| 2041 ** the logger function is a copy of the first parameter to the corresponding |
| 2042 ** [sqlite3_log()] call and is intended to be a [result code] or an |
| 2043 ** [extended result code]. ^The third parameter passed to the logger is |
| 2044 ** log message after formatting via [sqlite3_snprintf()]. |
| 2045 ** The SQLite logging interface is not reentrant; the logger function |
| 2046 ** supplied by the application must not invoke any SQLite interface. |
| 2047 ** In a multi-threaded application, the application-defined logger |
| 2048 ** function must be threadsafe. </dd> |
| 2049 ** |
| 2050 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI |
| 2051 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. |
| 2052 ** If non-zero, then URI handling is globally enabled. If the parameter is zero, |
| 2053 ** then URI handling is globally disabled.)^ ^If URI handling is globally |
| 2054 ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], |
| 2055 ** [sqlite3_open16()] or |
| 2056 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless |
| 2057 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database |
| 2058 ** connection is opened. ^If it is globally disabled, filenames are |
| 2059 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the |
| 2060 ** database connection is opened. ^(By default, URI handling is globally |
| 2061 ** disabled. The default value may be changed by compiling with the |
| 2062 ** [SQLITE_USE_URI] symbol defined.)^ |
| 2063 ** |
| 2064 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN |
| 2065 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer |
| 2066 ** argument which is interpreted as a boolean in order to enable or disable |
| 2067 ** the use of covering indices for full table scans in the query optimizer. |
| 2068 ** ^The default setting is determined |
| 2069 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" |
| 2070 ** if that compile-time option is omitted. |
| 2071 ** The ability to disable the use of covering indices for full table scans |
| 2072 ** is because some incorrectly coded legacy applications might malfunction |
| 2073 ** when the optimization is enabled. Providing the ability to |
| 2074 ** disable the optimization allows the older, buggy application code to work |
| 2075 ** without change even with newer versions of SQLite. |
| 2076 ** |
| 2077 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] |
| 2078 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE |
| 2079 ** <dd> These options are obsolete and should not be used by new code. |
| 2080 ** They are retained for backwards compatibility but are now no-ops. |
| 2081 ** </dd> |
| 2082 ** |
| 2083 ** [[SQLITE_CONFIG_SQLLOG]] |
| 2084 ** <dt>SQLITE_CONFIG_SQLLOG |
| 2085 ** <dd>This option is only available if sqlite is compiled with the |
| 2086 ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should |
| 2087 ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int). |
| 2088 ** The second should be of type (void*). The callback is invoked by the library |
| 2089 ** in three separate circumstances, identified by the value passed as the |
| 2090 ** fourth parameter. If the fourth parameter is 0, then the database connection |
| 2091 ** passed as the second argument has just been opened. The third argument |
| 2092 ** points to a buffer containing the name of the main database file. If the |
| 2093 ** fourth parameter is 1, then the SQL statement that the third parameter |
| 2094 ** points to has just been executed. Or, if the fourth parameter is 2, then |
| 2095 ** the connection being passed as the second parameter is being closed. The |
| 2096 ** third parameter is passed NULL In this case. An example of using this |
| 2097 ** configuration option can be seen in the "test_sqllog.c" source file in |
| 2098 ** the canonical SQLite source tree.</dd> |
| 2099 ** |
| 2100 ** [[SQLITE_CONFIG_MMAP_SIZE]] |
| 2101 ** <dt>SQLITE_CONFIG_MMAP_SIZE |
| 2102 ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values |
| 2103 ** that are the default mmap size limit (the default setting for |
| 2104 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. |
| 2105 ** ^The default setting can be overridden by each database connection using |
| 2106 ** either the [PRAGMA mmap_size] command, or by using the |
| 2107 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size |
| 2108 ** will be silently truncated if necessary so that it does not exceed the |
| 2109 ** compile-time maximum mmap size set by the |
| 2110 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ |
| 2111 ** ^If either argument to this option is negative, then that argument is |
| 2112 ** changed to its compile-time default. |
| 2113 ** |
| 2114 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] |
| 2115 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE |
| 2116 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is |
| 2117 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro |
| 2118 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value |
| 2119 ** that specifies the maximum size of the created heap. |
| 2120 ** |
| 2121 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] |
| 2122 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ |
| 2123 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which |
| 2124 ** is a pointer to an integer and writes into that integer the number of extra |
| 2125 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. |
| 2126 ** The amount of extra space required can change depending on the compiler, |
| 2127 ** target platform, and SQLite version. |
| 2128 ** |
| 2129 ** [[SQLITE_CONFIG_PMASZ]] |
| 2130 ** <dt>SQLITE_CONFIG_PMASZ |
| 2131 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which |
| 2132 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded |
| 2133 ** sorter to that integer. The default minimum PMA Size is set by the |
| 2134 ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched |
| 2135 ** to help with sort operations when multithreaded sorting |
| 2136 ** is enabled (using the [PRAGMA threads] command) and the amount of content |
| 2137 ** to be sorted exceeds the page size times the minimum of the |
| 2138 ** [PRAGMA cache_size] setting and this value. |
| 2139 ** |
| 2140 ** [[SQLITE_CONFIG_STMTJRNL_SPILL]] |
| 2141 ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL |
| 2142 ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which |
| 2143 ** becomes the [statement journal] spill-to-disk threshold. |
| 2144 ** [Statement journals] are held in memory until their size (in bytes) |
| 2145 ** exceeds this threshold, at which point they are written to disk. |
| 2146 ** Or if the threshold is -1, statement journals are always held |
| 2147 ** exclusively in memory. |
| 2148 ** Since many statement journals never become large, setting the spill |
| 2149 ** threshold to a value such as 64KiB can greatly reduce the amount of |
| 2150 ** I/O required to support statement rollback. |
| 2151 ** The default value for this setting is controlled by the |
| 2152 ** [SQLITE_STMTJRNL_SPILL] compile-time option. |
| 2153 ** </dl> |
| 2154 */ |
| 2155 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 2156 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 2157 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 2158 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| 2159 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ |
| 2160 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ |
| 2161 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ |
| 2162 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ |
| 2163 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ |
| 2164 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ |
| 2165 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ |
| 2166 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ |
| 2167 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ |
| 2168 #define SQLITE_CONFIG_PCACHE 14 /* no-op */ |
| 2169 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ |
| 2170 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 2171 #define SQLITE_CONFIG_URI 17 /* int */ |
| 2172 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ |
| 2173 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 2174 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 2175 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 2176 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ |
| 2177 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ |
| 2178 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ |
| 2179 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ |
| 2180 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ |
| 2181 |
| 2182 /* |
| 2183 ** CAPI3REF: Database Connection Configuration Options |
| 2184 ** |
| 2185 ** These constants are the available integer configuration options that |
| 2186 ** can be passed as the second argument to the [sqlite3_db_config()] interface. |
| 2187 ** |
| 2188 ** New configuration options may be added in future releases of SQLite. |
| 2189 ** Existing configuration options might be discontinued. Applications |
| 2190 ** should check the return code from [sqlite3_db_config()] to make sure that |
| 2191 ** the call worked. ^The [sqlite3_db_config()] interface will return a |
| 2192 ** non-zero [error code] if a discontinued or unsupported configuration option |
| 2193 ** is invoked. |
| 2194 ** |
| 2195 ** <dl> |
| 2196 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> |
| 2197 ** <dd> ^This option takes three additional arguments that determine the |
| 2198 ** [lookaside memory allocator] configuration for the [database connection]. |
| 2199 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a |
| 2200 ** pointer to a memory buffer to use for lookaside memory. |
| 2201 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb |
| 2202 ** may be NULL in which case SQLite will allocate the |
| 2203 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the |
| 2204 ** size of each lookaside buffer slot. ^The third argument is the number of |
| 2205 ** slots. The size of the buffer in the first argument must be greater than |
| 2206 ** or equal to the product of the second and third arguments. The buffer |
| 2207 ** must be aligned to an 8-byte boundary. ^If the second argument to |
| 2208 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally |
| 2209 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory |
| 2210 ** configuration for a database connection can only be changed when that |
| 2211 ** connection is not currently using lookaside memory, or in other words |
| 2212 ** when the "current value" returned by |
| 2213 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. |
| 2214 ** Any attempt to change the lookaside memory configuration when lookaside |
| 2215 ** memory is in use leaves the configuration unchanged and returns |
| 2216 ** [SQLITE_BUSY].)^</dd> |
| 2217 ** |
| 2218 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> |
| 2219 ** <dd> ^This option is used to enable or disable the enforcement of |
| 2220 ** [foreign key constraints]. There should be two additional arguments. |
| 2221 ** The first argument is an integer which is 0 to disable FK enforcement, |
| 2222 ** positive to enable FK enforcement or negative to leave FK enforcement |
| 2223 ** unchanged. The second parameter is a pointer to an integer into which |
| 2224 ** is written 0 or 1 to indicate whether FK enforcement is off or on |
| 2225 ** following this call. The second parameter may be a NULL pointer, in |
| 2226 ** which case the FK enforcement setting is not reported back. </dd> |
| 2227 ** |
| 2228 ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> |
| 2229 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. |
| 2230 ** There should be two additional arguments. |
| 2231 ** The first argument is an integer which is 0 to disable triggers, |
| 2232 ** positive to enable triggers or negative to leave the setting unchanged. |
| 2233 ** The second parameter is a pointer to an integer into which |
| 2234 ** is written 0 or 1 to indicate whether triggers are disabled or enabled |
| 2235 ** following this call. The second parameter may be a NULL pointer, in |
| 2236 ** which case the trigger setting is not reported back. </dd> |
| 2237 ** |
| 2238 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> |
| 2239 ** <dd> ^This option is used to enable or disable the two-argument |
| 2240 ** version of the [fts3_tokenizer()] function which is part of the |
| 2241 ** [FTS3] full-text search engine extension. |
| 2242 ** There should be two additional arguments. |
| 2243 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or |
| 2244 ** positive to enable fts3_tokenizer() or negative to leave the setting |
| 2245 ** unchanged. |
| 2246 ** The second parameter is a pointer to an integer into which |
| 2247 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled |
| 2248 ** following this call. The second parameter may be a NULL pointer, in |
| 2249 ** which case the new setting is not reported back. </dd> |
| 2250 ** |
| 2251 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> |
| 2252 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] |
| 2253 ** interface independently of the [load_extension()] SQL function. |
| 2254 ** The [sqlite3_enable_load_extension()] API enables or disables both the |
| 2255 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()]. |
| 2256 ** There should be two additional arguments. |
| 2257 ** When the first argument to this interface is 1, then only the C-API is |
| 2258 ** enabled and the SQL function remains disabled. If the first argument to |
| 2259 ** this interface is 0, then both the C-API and the SQL function are disabled. |
| 2260 ** If the first argument is -1, then no changes are made to state of either the |
| 2261 ** C-API or the SQL function. |
| 2262 ** The second parameter is a pointer to an integer into which |
| 2263 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface |
| 2264 ** is disabled or enabled following this call. The second parameter may |
| 2265 ** be a NULL pointer, in which case the new setting is not reported back. |
| 2266 ** </dd> |
| 2267 ** |
| 2268 ** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt> |
| 2269 ** <dd> ^This option is used to change the name of the "main" database |
| 2270 ** schema. ^The sole argument is a pointer to a constant UTF8 string |
| 2271 ** which will become the new schema name in place of "main". ^SQLite |
| 2272 ** does not make a copy of the new main schema name string, so the application |
| 2273 ** must ensure that the argument passed into this DBCONFIG option is unchanged |
| 2274 ** until after the database connection closes. |
| 2275 ** </dd> |
| 2276 ** |
| 2277 ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt> |
| 2278 ** <dd> Usually, when a database in wal mode is closed or detached from a |
| 2279 ** database handle, SQLite checks if this will mean that there are now no |
| 2280 ** connections at all to the database. If so, it performs a checkpoint |
| 2281 ** operation before closing the connection. This option may be used to |
| 2282 ** override this behaviour. The first parameter passed to this operation |
| 2283 ** is an integer - non-zero to disable checkpoints-on-close, or zero (the |
| 2284 ** default) to enable them. The second parameter is a pointer to an integer |
| 2285 ** into which is written 0 or 1 to indicate whether checkpoints-on-close |
| 2286 ** have been disabled - 0 if they are not disabled, 1 if they are. |
| 2287 ** </dd> |
| 2288 ** |
| 2289 ** </dl> |
| 2290 */ |
| 2291 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ |
| 2292 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ |
| 2293 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ |
| 2294 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 2295 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */ |
| 2296 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ |
| 2297 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ |
| 2298 |
| 2299 |
| 2300 /* |
| 2301 ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 2302 ** METHOD: sqlite3 |
| 2303 ** |
| 2304 ** ^The sqlite3_extended_result_codes() routine enables or disables the |
| 2305 ** [extended result codes] feature of SQLite. ^The extended result |
| 2306 ** codes are disabled by default for historical compatibility. |
| 2307 */ |
| 2308 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); |
| 2309 |
| 2310 /* |
| 2311 ** CAPI3REF: Last Insert Rowid |
| 2312 ** METHOD: sqlite3 |
| 2313 ** |
| 2314 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) |
| 2315 ** has a unique 64-bit signed |
| 2316 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available |
| 2317 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| 2318 ** names are not also used by explicitly declared columns. ^If |
| 2319 ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 2320 ** is another alias for the rowid. |
| 2321 ** |
| 2322 ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the |
| 2323 ** most recent successful [INSERT] into a rowid table or [virtual table] |
| 2324 ** on database connection D. |
| 2325 ** ^Inserts into [WITHOUT ROWID] tables are not recorded. |
| 2326 ** ^If no successful [INSERT]s into rowid tables |
| 2327 ** have ever occurred on the database connection D, |
| 2328 ** then sqlite3_last_insert_rowid(D) returns zero. |
| 2329 ** |
| 2330 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table] |
| 2331 ** method, then this routine will return the [rowid] of the inserted |
| 2332 ** row as long as the trigger or virtual table method is running. |
| 2333 ** But once the trigger or virtual table method ends, the value returned |
| 2334 ** by this routine reverts to what it was before the trigger or virtual |
| 2335 ** table method began.)^ |
| 2336 ** |
| 2337 ** ^An [INSERT] that fails due to a constraint violation is not a |
| 2338 ** successful [INSERT] and does not change the value returned by this |
| 2339 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 2340 ** and INSERT OR ABORT make no changes to the return value of this |
| 2341 ** routine when their insertion fails. ^(When INSERT OR REPLACE |
| 2342 ** encounters a constraint violation, it does not fail. The |
| 2343 ** INSERT continues to completion after deleting rows that caused |
| 2344 ** the constraint problem so INSERT OR REPLACE will always change |
| 2345 ** the return value of this interface.)^ |
| 2346 ** |
| 2347 ** ^For the purposes of this routine, an [INSERT] is considered to |
| 2348 ** be successful even if it is subsequently rolled back. |
| 2349 ** |
| 2350 ** This function is accessible to SQL statements via the |
| 2351 ** [last_insert_rowid() SQL function]. |
| 2352 ** |
| 2353 ** If a separate thread performs a new [INSERT] on the same |
| 2354 ** database connection while the [sqlite3_last_insert_rowid()] |
| 2355 ** function is running and thus changes the last insert [rowid], |
| 2356 ** then the value returned by [sqlite3_last_insert_rowid()] is |
| 2357 ** unpredictable and might not equal either the old or the new |
| 2358 ** last insert [rowid]. |
| 2359 */ |
| 2360 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 2361 |
| 2362 /* |
| 2363 ** CAPI3REF: Count The Number Of Rows Modified |
| 2364 ** METHOD: sqlite3 |
| 2365 ** |
| 2366 ** ^This function returns the number of rows modified, inserted or |
| 2367 ** deleted by the most recently completed INSERT, UPDATE or DELETE |
| 2368 ** statement on the database connection specified by the only parameter. |
| 2369 ** ^Executing any other type of SQL statement does not modify the value |
| 2370 ** returned by this function. |
| 2371 ** |
| 2372 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are |
| 2373 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], |
| 2374 ** [foreign key actions] or [REPLACE] constraint resolution are not counted. |
| 2375 ** |
| 2376 ** Changes to a view that are intercepted by |
| 2377 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value |
| 2378 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or |
| 2379 ** DELETE statement run on a view is always zero. Only changes made to real |
| 2380 ** tables are counted. |
| 2381 ** |
| 2382 ** Things are more complicated if the sqlite3_changes() function is |
| 2383 ** executed while a trigger program is running. This may happen if the |
| 2384 ** program uses the [changes() SQL function], or if some other callback |
| 2385 ** function invokes sqlite3_changes() directly. Essentially: |
| 2386 ** |
| 2387 ** <ul> |
| 2388 ** <li> ^(Before entering a trigger program the value returned by |
| 2389 ** sqlite3_changes() function is saved. After the trigger program |
| 2390 ** has finished, the original value is restored.)^ |
| 2391 ** |
| 2392 ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE |
| 2393 ** statement sets the value returned by sqlite3_changes() |
| 2394 ** upon completion as normal. Of course, this value will not include |
| 2395 ** any changes performed by sub-triggers, as the sqlite3_changes() |
| 2396 ** value will be saved and restored after each sub-trigger has run.)^ |
| 2397 ** </ul> |
| 2398 ** |
| 2399 ** ^This means that if the changes() SQL function (or similar) is used |
| 2400 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it |
| 2401 ** returns the value as set when the calling statement began executing. |
| 2402 ** ^If it is used by the second or subsequent such statement within a trigger |
| 2403 ** program, the value returned reflects the number of rows modified by the |
| 2404 ** previous INSERT, UPDATE or DELETE statement within the same trigger. |
| 2405 ** |
| 2406 ** See also the [sqlite3_total_changes()] interface, the |
| 2407 ** [count_changes pragma], and the [changes() SQL function]. |
| 2408 ** |
| 2409 ** If a separate thread makes changes on the same database connection |
| 2410 ** while [sqlite3_changes()] is running then the value returned |
| 2411 ** is unpredictable and not meaningful. |
| 2412 */ |
| 2413 SQLITE_API int sqlite3_changes(sqlite3*); |
| 2414 |
| 2415 /* |
| 2416 ** CAPI3REF: Total Number Of Rows Modified |
| 2417 ** METHOD: sqlite3 |
| 2418 ** |
| 2419 ** ^This function returns the total number of rows inserted, modified or |
| 2420 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed |
| 2421 ** since the database connection was opened, including those executed as |
| 2422 ** part of trigger programs. ^Executing any other type of SQL statement |
| 2423 ** does not affect the value returned by sqlite3_total_changes(). |
| 2424 ** |
| 2425 ** ^Changes made as part of [foreign key actions] are included in the |
| 2426 ** count, but those made as part of REPLACE constraint resolution are |
| 2427 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers |
| 2428 ** are not counted. |
| 2429 ** |
| 2430 ** See also the [sqlite3_changes()] interface, the |
| 2431 ** [count_changes pragma], and the [total_changes() SQL function]. |
| 2432 ** |
| 2433 ** If a separate thread makes changes on the same database connection |
| 2434 ** while [sqlite3_total_changes()] is running then the value |
| 2435 ** returned is unpredictable and not meaningful. |
| 2436 */ |
| 2437 SQLITE_API int sqlite3_total_changes(sqlite3*); |
| 2438 |
| 2439 /* |
| 2440 ** CAPI3REF: Interrupt A Long-Running Query |
| 2441 ** METHOD: sqlite3 |
| 2442 ** |
| 2443 ** ^This function causes any pending database operation to abort and |
| 2444 ** return at its earliest opportunity. This routine is typically |
| 2445 ** called in response to a user action such as pressing "Cancel" |
| 2446 ** or Ctrl-C where the user wants a long query operation to halt |
| 2447 ** immediately. |
| 2448 ** |
| 2449 ** ^It is safe to call this routine from a thread different from the |
| 2450 ** thread that is currently running the database operation. But it |
| 2451 ** is not safe to call this routine with a [database connection] that |
| 2452 ** is closed or might close before sqlite3_interrupt() returns. |
| 2453 ** |
| 2454 ** ^If an SQL operation is very nearly finished at the time when |
| 2455 ** sqlite3_interrupt() is called, then it might not have an opportunity |
| 2456 ** to be interrupted and might continue to completion. |
| 2457 ** |
| 2458 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. |
| 2459 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE |
| 2460 ** that is inside an explicit transaction, then the entire transaction |
| 2461 ** will be rolled back automatically. |
| 2462 ** |
| 2463 ** ^The sqlite3_interrupt(D) call is in effect until all currently running |
| 2464 ** SQL statements on [database connection] D complete. ^Any new SQL statements |
| 2465 ** that are started after the sqlite3_interrupt() call and before the |
| 2466 ** running statements reaches zero are interrupted as if they had been |
| 2467 ** running prior to the sqlite3_interrupt() call. ^New SQL statements |
| 2468 ** that are started after the running statement count reaches zero are |
| 2469 ** not effected by the sqlite3_interrupt(). |
| 2470 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running |
| 2471 ** SQL statements is a no-op and has no effect on SQL statements |
| 2472 ** that are started after the sqlite3_interrupt() call returns. |
| 2473 ** |
| 2474 ** If the database connection closes while [sqlite3_interrupt()] |
| 2475 ** is running then bad things will likely happen. |
| 2476 */ |
| 2477 SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 2478 |
| 2479 /* |
| 2480 ** CAPI3REF: Determine If An SQL Statement Is Complete |
| 2481 ** |
| 2482 ** These routines are useful during command-line input to determine if the |
| 2483 ** currently entered text seems to form a complete SQL statement or |
| 2484 ** if additional input is needed before sending the text into |
| 2485 ** SQLite for parsing. ^These routines return 1 if the input string |
| 2486 ** appears to be a complete SQL statement. ^A statement is judged to be |
| 2487 ** complete if it ends with a semicolon token and is not a prefix of a |
| 2488 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within |
| 2489 ** string literals or quoted identifier names or comments are not |
| 2490 ** independent tokens (they are part of the token in which they are |
| 2491 ** embedded) and thus do not count as a statement terminator. ^Whitespace |
| 2492 ** and comments that follow the final semicolon are ignored. |
| 2493 ** |
| 2494 ** ^These routines return 0 if the statement is incomplete. ^If a |
| 2495 ** memory allocation fails, then SQLITE_NOMEM is returned. |
| 2496 ** |
| 2497 ** ^These routines do not parse the SQL statements thus |
| 2498 ** will not detect syntactically incorrect SQL. |
| 2499 ** |
| 2500 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior |
| 2501 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked |
| 2502 ** automatically by sqlite3_complete16(). If that initialization fails, |
| 2503 ** then the return value from sqlite3_complete16() will be non-zero |
| 2504 ** regardless of whether or not the input SQL is complete.)^ |
| 2505 ** |
| 2506 ** The input to [sqlite3_complete()] must be a zero-terminated |
| 2507 ** UTF-8 string. |
| 2508 ** |
| 2509 ** The input to [sqlite3_complete16()] must be a zero-terminated |
| 2510 ** UTF-16 string in native byte order. |
| 2511 */ |
| 2512 SQLITE_API int sqlite3_complete(const char *sql); |
| 2513 SQLITE_API int sqlite3_complete16(const void *sql); |
| 2514 |
| 2515 /* |
| 2516 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors |
| 2517 ** KEYWORDS: {busy-handler callback} {busy handler} |
| 2518 ** METHOD: sqlite3 |
| 2519 ** |
| 2520 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X |
| 2521 ** that might be invoked with argument P whenever |
| 2522 ** an attempt is made to access a database table associated with |
| 2523 ** [database connection] D when another thread |
| 2524 ** or process has the table locked. |
| 2525 ** The sqlite3_busy_handler() interface is used to implement |
| 2526 ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
| 2527 ** |
| 2528 ** ^If the busy callback is NULL, then [SQLITE_BUSY] |
| 2529 ** is returned immediately upon encountering the lock. ^If the busy callback |
| 2530 ** is not NULL, then the callback might be invoked with two arguments. |
| 2531 ** |
| 2532 ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2533 ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2534 ** the busy handler callback is the number of times that the busy handler has |
| 2535 ** been invoked previously for the same locking event. ^If the |
| 2536 ** busy callback returns 0, then no additional attempts are made to |
| 2537 ** access the database and [SQLITE_BUSY] is returned |
| 2538 ** to the application. |
| 2539 ** ^If the callback returns non-zero, then another attempt |
| 2540 ** is made to access the database and the cycle repeats. |
| 2541 ** |
| 2542 ** The presence of a busy handler does not guarantee that it will be invoked |
| 2543 ** when there is lock contention. ^If SQLite determines that invoking the busy |
| 2544 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
| 2545 ** to the application instead of invoking the |
| 2546 ** busy handler. |
| 2547 ** Consider a scenario where one process is holding a read lock that |
| 2548 ** it is trying to promote to a reserved lock and |
| 2549 ** a second process is holding a reserved lock that it is trying |
| 2550 ** to promote to an exclusive lock. The first process cannot proceed |
| 2551 ** because it is blocked by the second and the second process cannot |
| 2552 ** proceed because it is blocked by the first. If both processes |
| 2553 ** invoke the busy handlers, neither will make any progress. Therefore, |
| 2554 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this |
| 2555 ** will induce the first process to release its read lock and allow |
| 2556 ** the second process to proceed. |
| 2557 ** |
| 2558 ** ^The default busy callback is NULL. |
| 2559 ** |
| 2560 ** ^(There can only be a single busy handler defined for each |
| 2561 ** [database connection]. Setting a new busy handler clears any |
| 2562 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
| 2563 ** or evaluating [PRAGMA busy_timeout=N] will change the |
| 2564 ** busy handler and thus clear any previously set busy handler. |
| 2565 ** |
| 2566 ** The busy callback should not take any actions which modify the |
| 2567 ** database connection that invoked the busy handler. In other words, |
| 2568 ** the busy handler is not reentrant. Any such actions |
| 2569 ** result in undefined behavior. |
| 2570 ** |
| 2571 ** A busy handler must not close the database connection |
| 2572 ** or [prepared statement] that invoked the busy handler. |
| 2573 */ |
| 2574 SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); |
| 2575 |
| 2576 /* |
| 2577 ** CAPI3REF: Set A Busy Timeout |
| 2578 ** METHOD: sqlite3 |
| 2579 ** |
| 2580 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2581 ** for a specified amount of time when a table is locked. ^The handler |
| 2582 ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2583 ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| 2584 ** the handler returns 0 which causes [sqlite3_step()] to return |
| 2585 ** [SQLITE_BUSY]. |
| 2586 ** |
| 2587 ** ^Calling this routine with an argument less than or equal to zero |
| 2588 ** turns off all busy handlers. |
| 2589 ** |
| 2590 ** ^(There can only be a single busy handler for a particular |
| 2591 ** [database connection] at any given moment. If another busy handler |
| 2592 ** was defined (using [sqlite3_busy_handler()]) prior to calling |
| 2593 ** this routine, that other busy handler is cleared.)^ |
| 2594 ** |
| 2595 ** See also: [PRAGMA busy_timeout] |
| 2596 */ |
| 2597 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); |
| 2598 |
| 2599 /* |
| 2600 ** CAPI3REF: Convenience Routines For Running Queries |
| 2601 ** METHOD: sqlite3 |
| 2602 ** |
| 2603 ** This is a legacy interface that is preserved for backwards compatibility. |
| 2604 ** Use of this interface is not recommended. |
| 2605 ** |
| 2606 ** Definition: A <b>result table</b> is memory data structure created by the |
| 2607 ** [sqlite3_get_table()] interface. A result table records the |
| 2608 ** complete query results from one or more queries. |
| 2609 ** |
| 2610 ** The table conceptually has a number of rows and columns. But |
| 2611 ** these numbers are not part of the result table itself. These |
| 2612 ** numbers are obtained separately. Let N be the number of rows |
| 2613 ** and M be the number of columns. |
| 2614 ** |
| 2615 ** A result table is an array of pointers to zero-terminated UTF-8 strings. |
| 2616 ** There are (N+1)*M elements in the array. The first M pointers point |
| 2617 ** to zero-terminated strings that contain the names of the columns. |
| 2618 ** The remaining entries all point to query results. NULL values result |
| 2619 ** in NULL pointers. All other values are in their UTF-8 zero-terminated |
| 2620 ** string representation as returned by [sqlite3_column_text()]. |
| 2621 ** |
| 2622 ** A result table might consist of one or more memory allocations. |
| 2623 ** It is not safe to pass a result table directly to [sqlite3_free()]. |
| 2624 ** A result table should be deallocated using [sqlite3_free_table()]. |
| 2625 ** |
| 2626 ** ^(As an example of the result table format, suppose a query result |
| 2627 ** is as follows: |
| 2628 ** |
| 2629 ** <blockquote><pre> |
| 2630 ** Name | Age |
| 2631 ** ----------------------- |
| 2632 ** Alice | 43 |
| 2633 ** Bob | 28 |
| 2634 ** Cindy | 21 |
| 2635 ** </pre></blockquote> |
| 2636 ** |
| 2637 ** There are two column (M==2) and three rows (N==3). Thus the |
| 2638 ** result table has 8 entries. Suppose the result table is stored |
| 2639 ** in an array names azResult. Then azResult holds this content: |
| 2640 ** |
| 2641 ** <blockquote><pre> |
| 2642 ** azResult[0] = "Name"; |
| 2643 ** azResult[1] = "Age"; |
| 2644 ** azResult[2] = "Alice"; |
| 2645 ** azResult[3] = "43"; |
| 2646 ** azResult[4] = "Bob"; |
| 2647 ** azResult[5] = "28"; |
| 2648 ** azResult[6] = "Cindy"; |
| 2649 ** azResult[7] = "21"; |
| 2650 ** </pre></blockquote>)^ |
| 2651 ** |
| 2652 ** ^The sqlite3_get_table() function evaluates one or more |
| 2653 ** semicolon-separated SQL statements in the zero-terminated UTF-8 |
| 2654 ** string of its 2nd parameter and returns a result table to the |
| 2655 ** pointer given in its 3rd parameter. |
| 2656 ** |
| 2657 ** After the application has finished with the result from sqlite3_get_table(), |
| 2658 ** it must pass the result table pointer to sqlite3_free_table() in order to |
| 2659 ** release the memory that was malloced. Because of the way the |
| 2660 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling |
| 2661 ** function must not try to call [sqlite3_free()] directly. Only |
| 2662 ** [sqlite3_free_table()] is able to release the memory properly and safely. |
| 2663 ** |
| 2664 ** The sqlite3_get_table() interface is implemented as a wrapper around |
| 2665 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access |
| 2666 ** to any internal data structures of SQLite. It uses only the public |
| 2667 ** interface defined here. As a consequence, errors that occur in the |
| 2668 ** wrapper layer outside of the internal [sqlite3_exec()] call are not |
| 2669 ** reflected in subsequent calls to [sqlite3_errcode()] or |
| 2670 ** [sqlite3_errmsg()]. |
| 2671 */ |
| 2672 SQLITE_API int sqlite3_get_table( |
| 2673 sqlite3 *db, /* An open database */ |
| 2674 const char *zSql, /* SQL to be evaluated */ |
| 2675 char ***pazResult, /* Results of the query */ |
| 2676 int *pnRow, /* Number of result rows written here */ |
| 2677 int *pnColumn, /* Number of result columns written here */ |
| 2678 char **pzErrmsg /* Error msg written here */ |
| 2679 ); |
| 2680 SQLITE_API void sqlite3_free_table(char **result); |
| 2681 |
| 2682 /* |
| 2683 ** CAPI3REF: Formatted String Printing Functions |
| 2684 ** |
| 2685 ** These routines are work-alikes of the "printf()" family of functions |
| 2686 ** from the standard C library. |
| 2687 ** These routines understand most of the common K&R formatting options, |
| 2688 ** plus some additional non-standard formats, detailed below. |
| 2689 ** Note that some of the more obscure formatting options from recent |
| 2690 ** C-library standards are omitted from this implementation. |
| 2691 ** |
| 2692 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their |
| 2693 ** results into memory obtained from [sqlite3_malloc()]. |
| 2694 ** The strings returned by these two routines should be |
| 2695 ** released by [sqlite3_free()]. ^Both routines return a |
| 2696 ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough |
| 2697 ** memory to hold the resulting string. |
| 2698 ** |
| 2699 ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from |
| 2700 ** the standard C library. The result is written into the |
| 2701 ** buffer supplied as the second parameter whose size is given by |
| 2702 ** the first parameter. Note that the order of the |
| 2703 ** first two parameters is reversed from snprintf().)^ This is an |
| 2704 ** historical accident that cannot be fixed without breaking |
| 2705 ** backwards compatibility. ^(Note also that sqlite3_snprintf() |
| 2706 ** returns a pointer to its buffer instead of the number of |
| 2707 ** characters actually written into the buffer.)^ We admit that |
| 2708 ** the number of characters written would be a more useful return |
| 2709 ** value but we cannot change the implementation of sqlite3_snprintf() |
| 2710 ** now without breaking compatibility. |
| 2711 ** |
| 2712 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() |
| 2713 ** guarantees that the buffer is always zero-terminated. ^The first |
| 2714 ** parameter "n" is the total size of the buffer, including space for |
| 2715 ** the zero terminator. So the longest string that can be completely |
| 2716 ** written will be n-1 characters. |
| 2717 ** |
| 2718 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). |
| 2719 ** |
| 2720 ** These routines all implement some additional formatting |
| 2721 ** options that are useful for constructing SQL statements. |
| 2722 ** All of the usual printf() formatting options apply. In addition, there |
| 2723 ** is are "%q", "%Q", "%w" and "%z" options. |
| 2724 ** |
| 2725 ** ^(The %q option works like %s in that it substitutes a nul-terminated |
| 2726 ** string from the argument list. But %q also doubles every '\'' character. |
| 2727 ** %q is designed for use inside a string literal.)^ By doubling each '\'' |
| 2728 ** character it escapes that character and allows it to be inserted into |
| 2729 ** the string. |
| 2730 ** |
| 2731 ** For example, assume the string variable zText contains text as follows: |
| 2732 ** |
| 2733 ** <blockquote><pre> |
| 2734 ** char *zText = "It's a happy day!"; |
| 2735 ** </pre></blockquote> |
| 2736 ** |
| 2737 ** One can use this text in an SQL statement as follows: |
| 2738 ** |
| 2739 ** <blockquote><pre> |
| 2740 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); |
| 2741 ** sqlite3_exec(db, zSQL, 0, 0, 0); |
| 2742 ** sqlite3_free(zSQL); |
| 2743 ** </pre></blockquote> |
| 2744 ** |
| 2745 ** Because the %q format string is used, the '\'' character in zText |
| 2746 ** is escaped and the SQL generated is as follows: |
| 2747 ** |
| 2748 ** <blockquote><pre> |
| 2749 ** INSERT INTO table1 VALUES('It''s a happy day!') |
| 2750 ** </pre></blockquote> |
| 2751 ** |
| 2752 ** This is correct. Had we used %s instead of %q, the generated SQL |
| 2753 ** would have looked like this: |
| 2754 ** |
| 2755 ** <blockquote><pre> |
| 2756 ** INSERT INTO table1 VALUES('It's a happy day!'); |
| 2757 ** </pre></blockquote> |
| 2758 ** |
| 2759 ** This second example is an SQL syntax error. As a general rule you should |
| 2760 ** always use %q instead of %s when inserting text into a string literal. |
| 2761 ** |
| 2762 ** ^(The %Q option works like %q except it also adds single quotes around |
| 2763 ** the outside of the total string. Additionally, if the parameter in the |
| 2764 ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without |
| 2765 ** single quotes).)^ So, for example, one could say: |
| 2766 ** |
| 2767 ** <blockquote><pre> |
| 2768 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); |
| 2769 ** sqlite3_exec(db, zSQL, 0, 0, 0); |
| 2770 ** sqlite3_free(zSQL); |
| 2771 ** </pre></blockquote> |
| 2772 ** |
| 2773 ** The code above will render a correct SQL statement in the zSQL |
| 2774 ** variable even if the zText variable is a NULL pointer. |
| 2775 ** |
| 2776 ** ^(The "%w" formatting option is like "%q" except that it expects to |
| 2777 ** be contained within double-quotes instead of single quotes, and it |
| 2778 ** escapes the double-quote character instead of the single-quote |
| 2779 ** character.)^ The "%w" formatting option is intended for safely inserting |
| 2780 ** table and column names into a constructed SQL statement. |
| 2781 ** |
| 2782 ** ^(The "%z" formatting option works like "%s" but with the |
| 2783 ** addition that after the string has been read and copied into |
| 2784 ** the result, [sqlite3_free()] is called on the input string.)^ |
| 2785 */ |
| 2786 SQLITE_API char *sqlite3_mprintf(const char*,...); |
| 2787 SQLITE_API char *sqlite3_vmprintf(const char*, va_list); |
| 2788 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); |
| 2789 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); |
| 2790 |
| 2791 /* |
| 2792 ** CAPI3REF: Memory Allocation Subsystem |
| 2793 ** |
| 2794 ** The SQLite core uses these three routines for all of its own |
| 2795 ** internal memory allocation needs. "Core" in the previous sentence |
| 2796 ** does not include operating-system specific VFS implementation. The |
| 2797 ** Windows VFS uses native malloc() and free() for some operations. |
| 2798 ** |
| 2799 ** ^The sqlite3_malloc() routine returns a pointer to a block |
| 2800 ** of memory at least N bytes in length, where N is the parameter. |
| 2801 ** ^If sqlite3_malloc() is unable to obtain sufficient free |
| 2802 ** memory, it returns a NULL pointer. ^If the parameter N to |
| 2803 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns |
| 2804 ** a NULL pointer. |
| 2805 ** |
| 2806 ** ^The sqlite3_malloc64(N) routine works just like |
| 2807 ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead |
| 2808 ** of a signed 32-bit integer. |
| 2809 ** |
| 2810 ** ^Calling sqlite3_free() with a pointer previously returned |
| 2811 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so |
| 2812 ** that it might be reused. ^The sqlite3_free() routine is |
| 2813 ** a no-op if is called with a NULL pointer. Passing a NULL pointer |
| 2814 ** to sqlite3_free() is harmless. After being freed, memory |
| 2815 ** should neither be read nor written. Even reading previously freed |
| 2816 ** memory might result in a segmentation fault or other severe error. |
| 2817 ** Memory corruption, a segmentation fault, or other severe error |
| 2818 ** might result if sqlite3_free() is called with a non-NULL pointer that |
| 2819 ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). |
| 2820 ** |
| 2821 ** ^The sqlite3_realloc(X,N) interface attempts to resize a |
| 2822 ** prior memory allocation X to be at least N bytes. |
| 2823 ** ^If the X parameter to sqlite3_realloc(X,N) |
| 2824 ** is a NULL pointer then its behavior is identical to calling |
| 2825 ** sqlite3_malloc(N). |
| 2826 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or |
| 2827 ** negative then the behavior is exactly the same as calling |
| 2828 ** sqlite3_free(X). |
| 2829 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation |
| 2830 ** of at least N bytes in size or NULL if insufficient memory is available. |
| 2831 ** ^If M is the size of the prior allocation, then min(N,M) bytes |
| 2832 ** of the prior allocation are copied into the beginning of buffer returned |
| 2833 ** by sqlite3_realloc(X,N) and the prior allocation is freed. |
| 2834 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the |
| 2835 ** prior allocation is not freed. |
| 2836 ** |
| 2837 ** ^The sqlite3_realloc64(X,N) interfaces works the same as |
| 2838 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead |
| 2839 ** of a 32-bit signed integer. |
| 2840 ** |
| 2841 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(), |
| 2842 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then |
| 2843 ** sqlite3_msize(X) returns the size of that memory allocation in bytes. |
| 2844 ** ^The value returned by sqlite3_msize(X) might be larger than the number |
| 2845 ** of bytes requested when X was allocated. ^If X is a NULL pointer then |
| 2846 ** sqlite3_msize(X) returns zero. If X points to something that is not |
| 2847 ** the beginning of memory allocation, or if it points to a formerly |
| 2848 ** valid memory allocation that has now been freed, then the behavior |
| 2849 ** of sqlite3_msize(X) is undefined and possibly harmful. |
| 2850 ** |
| 2851 ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(), |
| 2852 ** sqlite3_malloc64(), and sqlite3_realloc64() |
| 2853 ** is always aligned to at least an 8 byte boundary, or to a |
| 2854 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time |
| 2855 ** option is used. |
| 2856 ** |
| 2857 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define |
| 2858 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in |
| 2859 ** implementation of these routines to be omitted. That capability |
| 2860 ** is no longer provided. Only built-in memory allocators can be used. |
| 2861 ** |
| 2862 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called |
| 2863 ** the system malloc() and free() directly when converting |
| 2864 ** filenames between the UTF-8 encoding used by SQLite |
| 2865 ** and whatever filename encoding is used by the particular Windows |
| 2866 ** installation. Memory allocation errors were detected, but |
| 2867 ** they were reported back as [SQLITE_CANTOPEN] or |
| 2868 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. |
| 2869 ** |
| 2870 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] |
| 2871 ** must be either NULL or else pointers obtained from a prior |
| 2872 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have |
| 2873 ** not yet been released. |
| 2874 ** |
| 2875 ** The application must not read or write any part of |
| 2876 ** a block of memory after it has been released using |
| 2877 ** [sqlite3_free()] or [sqlite3_realloc()]. |
| 2878 */ |
| 2879 SQLITE_API void *sqlite3_malloc(int); |
| 2880 SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); |
| 2881 SQLITE_API void *sqlite3_realloc(void*, int); |
| 2882 SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); |
| 2883 SQLITE_API void sqlite3_free(void*); |
| 2884 SQLITE_API sqlite3_uint64 sqlite3_msize(void*); |
| 2885 |
| 2886 /* |
| 2887 ** CAPI3REF: Memory Allocator Statistics |
| 2888 ** |
| 2889 ** SQLite provides these two interfaces for reporting on the status |
| 2890 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] |
| 2891 ** routines, which form the built-in memory allocation subsystem. |
| 2892 ** |
| 2893 ** ^The [sqlite3_memory_used()] routine returns the number of bytes |
| 2894 ** of memory currently outstanding (malloced but not freed). |
| 2895 ** ^The [sqlite3_memory_highwater()] routine returns the maximum |
| 2896 ** value of [sqlite3_memory_used()] since the high-water mark |
| 2897 ** was last reset. ^The values returned by [sqlite3_memory_used()] and |
| 2898 ** [sqlite3_memory_highwater()] include any overhead |
| 2899 ** added by SQLite in its implementation of [sqlite3_malloc()], |
| 2900 ** but not overhead added by the any underlying system library |
| 2901 ** routines that [sqlite3_malloc()] may call. |
| 2902 ** |
| 2903 ** ^The memory high-water mark is reset to the current value of |
| 2904 ** [sqlite3_memory_used()] if and only if the parameter to |
| 2905 ** [sqlite3_memory_highwater()] is true. ^The value returned |
| 2906 ** by [sqlite3_memory_highwater(1)] is the high-water mark |
| 2907 ** prior to the reset. |
| 2908 */ |
| 2909 SQLITE_API sqlite3_int64 sqlite3_memory_used(void); |
| 2910 SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); |
| 2911 |
| 2912 /* |
| 2913 ** CAPI3REF: Pseudo-Random Number Generator |
| 2914 ** |
| 2915 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to |
| 2916 ** select random [ROWID | ROWIDs] when inserting new records into a table that |
| 2917 ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2918 ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2919 ** applications to access the same PRNG for other purposes. |
| 2920 ** |
| 2921 ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2922 ** ^The P parameter can be a NULL pointer. |
| 2923 ** |
| 2924 ** ^If this routine has not been previously called or if the previous |
| 2925 ** call had N less than one or a NULL pointer for P, then the PRNG is |
| 2926 ** seeded using randomness obtained from the xRandomness method of |
| 2927 ** the default [sqlite3_vfs] object. |
| 2928 ** ^If the previous call to this routine had an N of 1 or more and a |
| 2929 ** non-NULL P then the pseudo-randomness is generated |
| 2930 ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2931 ** method. |
| 2932 */ |
| 2933 SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2934 |
| 2935 /* |
| 2936 ** CAPI3REF: Compile-Time Authorization Callbacks |
| 2937 ** METHOD: sqlite3 |
| 2938 ** |
| 2939 ** ^This routine registers an authorizer callback with a particular |
| 2940 ** [database connection], supplied in the first argument. |
| 2941 ** ^The authorizer callback is invoked as SQL statements are being compiled |
| 2942 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], |
| 2943 ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various |
| 2944 ** points during the compilation process, as logic is being created |
| 2945 ** to perform various actions, the authorizer callback is invoked to |
| 2946 ** see if those actions are allowed. ^The authorizer callback should |
| 2947 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the |
| 2948 ** specific action but allow the SQL statement to continue to be |
| 2949 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be |
| 2950 ** rejected with an error. ^If the authorizer callback returns |
| 2951 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] |
| 2952 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered |
| 2953 ** the authorizer will fail with an error message. |
| 2954 ** |
| 2955 ** When the callback returns [SQLITE_OK], that means the operation |
| 2956 ** requested is ok. ^When the callback returns [SQLITE_DENY], the |
| 2957 ** [sqlite3_prepare_v2()] or equivalent call that triggered the |
| 2958 ** authorizer will fail with an error message explaining that |
| 2959 ** access is denied. |
| 2960 ** |
| 2961 ** ^The first parameter to the authorizer callback is a copy of the third |
| 2962 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter |
| 2963 ** to the callback is an integer [SQLITE_COPY | action code] that specifies |
| 2964 ** the particular action to be authorized. ^The third through sixth parameters |
| 2965 ** to the callback are zero-terminated strings that contain additional |
| 2966 ** details about the action to be authorized. |
| 2967 ** |
| 2968 ** ^If the action code is [SQLITE_READ] |
| 2969 ** and the callback returns [SQLITE_IGNORE] then the |
| 2970 ** [prepared statement] statement is constructed to substitute |
| 2971 ** a NULL value in place of the table column that would have |
| 2972 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] |
| 2973 ** return can be used to deny an untrusted user access to individual |
| 2974 ** columns of a table. |
| 2975 ** ^If the action code is [SQLITE_DELETE] and the callback returns |
| 2976 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the |
| 2977 ** [truncate optimization] is disabled and all rows are deleted individually. |
| 2978 ** |
| 2979 ** An authorizer is used when [sqlite3_prepare | preparing] |
| 2980 ** SQL statements from an untrusted source, to ensure that the SQL statements |
| 2981 ** do not try to access data they are not allowed to see, or that they do not |
| 2982 ** try to execute malicious statements that damage the database. For |
| 2983 ** example, an application may allow a user to enter arbitrary |
| 2984 ** SQL queries for evaluation by a database. But the application does |
| 2985 ** not want the user to be able to make arbitrary changes to the |
| 2986 ** database. An authorizer could then be put in place while the |
| 2987 ** user-entered SQL is being [sqlite3_prepare | prepared] that |
| 2988 ** disallows everything except [SELECT] statements. |
| 2989 ** |
| 2990 ** Applications that need to process SQL from untrusted sources |
| 2991 ** might also consider lowering resource limits using [sqlite3_limit()] |
| 2992 ** and limiting database size using the [max_page_count] [PRAGMA] |
| 2993 ** in addition to using an authorizer. |
| 2994 ** |
| 2995 ** ^(Only a single authorizer can be in place on a database connection |
| 2996 ** at a time. Each call to sqlite3_set_authorizer overrides the |
| 2997 ** previous call.)^ ^Disable the authorizer by installing a NULL callback. |
| 2998 ** The authorizer is disabled by default. |
| 2999 ** |
| 3000 ** The authorizer callback must not do anything that will modify |
| 3001 ** the database connection that invoked the authorizer callback. |
| 3002 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
| 3003 ** database connections for the meaning of "modify" in this paragraph. |
| 3004 ** |
| 3005 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the |
| 3006 ** statement might be re-prepared during [sqlite3_step()] due to a |
| 3007 ** schema change. Hence, the application should ensure that the |
| 3008 ** correct authorizer callback remains in place during the [sqlite3_step()]. |
| 3009 ** |
| 3010 ** ^Note that the authorizer callback is invoked only during |
| 3011 ** [sqlite3_prepare()] or its variants. Authorization is not |
| 3012 ** performed during statement evaluation in [sqlite3_step()], unless |
| 3013 ** as stated in the previous paragraph, sqlite3_step() invokes |
| 3014 ** sqlite3_prepare_v2() to reprepare a statement after a schema change. |
| 3015 */ |
| 3016 SQLITE_API int sqlite3_set_authorizer( |
| 3017 sqlite3*, |
| 3018 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), |
| 3019 void *pUserData |
| 3020 ); |
| 3021 |
| 3022 /* |
| 3023 ** CAPI3REF: Authorizer Return Codes |
| 3024 ** |
| 3025 ** The [sqlite3_set_authorizer | authorizer callback function] must |
| 3026 ** return either [SQLITE_OK] or one of these two constants in order |
| 3027 ** to signal SQLite whether or not the action is permitted. See the |
| 3028 ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 3029 ** information. |
| 3030 ** |
| 3031 ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] |
| 3032 ** returned from the [sqlite3_vtab_on_conflict()] interface. |
| 3033 */ |
| 3034 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 3035 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 3036 |
| 3037 /* |
| 3038 ** CAPI3REF: Authorizer Action Codes |
| 3039 ** |
| 3040 ** The [sqlite3_set_authorizer()] interface registers a callback function |
| 3041 ** that is invoked to authorize certain SQL statement actions. The |
| 3042 ** second parameter to the callback is an integer code that specifies |
| 3043 ** what action is being authorized. These are the integer action codes that |
| 3044 ** the authorizer callback may be passed. |
| 3045 ** |
| 3046 ** These action code values signify what kind of operation is to be |
| 3047 ** authorized. The 3rd and 4th parameters to the authorization |
| 3048 ** callback function will be parameters or NULL depending on which of these |
| 3049 ** codes is used as the second parameter. ^(The 5th parameter to the |
| 3050 ** authorizer callback is the name of the database ("main", "temp", |
| 3051 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback |
| 3052 ** is the name of the inner-most trigger or view that is responsible for |
| 3053 ** the access attempt or NULL if this access attempt is directly from |
| 3054 ** top-level SQL code. |
| 3055 */ |
| 3056 /******************************************* 3rd ************ 4th ***********/ |
| 3057 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ |
| 3058 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ |
| 3059 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ |
| 3060 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ |
| 3061 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ |
| 3062 #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ |
| 3063 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ |
| 3064 #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ |
| 3065 #define SQLITE_DELETE 9 /* Table Name NULL */ |
| 3066 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ |
| 3067 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ |
| 3068 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ |
| 3069 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ |
| 3070 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ |
| 3071 #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ |
| 3072 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ |
| 3073 #define SQLITE_DROP_VIEW 17 /* View Name NULL */ |
| 3074 #define SQLITE_INSERT 18 /* Table Name NULL */ |
| 3075 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ |
| 3076 #define SQLITE_READ 20 /* Table Name Column Name */ |
| 3077 #define SQLITE_SELECT 21 /* NULL NULL */ |
| 3078 #define SQLITE_TRANSACTION 22 /* Operation NULL */ |
| 3079 #define SQLITE_UPDATE 23 /* Table Name Column Name */ |
| 3080 #define SQLITE_ATTACH 24 /* Filename NULL */ |
| 3081 #define SQLITE_DETACH 25 /* Database Name NULL */ |
| 3082 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ |
| 3083 #define SQLITE_REINDEX 27 /* Index Name NULL */ |
| 3084 #define SQLITE_ANALYZE 28 /* Table Name NULL */ |
| 3085 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ |
| 3086 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ |
| 3087 #define SQLITE_FUNCTION 31 /* NULL Function Name */ |
| 3088 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ |
| 3089 #define SQLITE_COPY 0 /* No longer used */ |
| 3090 #define SQLITE_RECURSIVE 33 /* NULL NULL */ |
| 3091 |
| 3092 /* |
| 3093 ** CAPI3REF: Tracing And Profiling Functions |
| 3094 ** METHOD: sqlite3 |
| 3095 ** |
| 3096 ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface |
| 3097 ** instead of the routines described here. |
| 3098 ** |
| 3099 ** These routines register callback functions that can be used for |
| 3100 ** tracing and profiling the execution of SQL statements. |
| 3101 ** |
| 3102 ** ^The callback function registered by sqlite3_trace() is invoked at |
| 3103 ** various times when an SQL statement is being run by [sqlite3_step()]. |
| 3104 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the |
| 3105 ** SQL statement text as the statement first begins executing. |
| 3106 ** ^(Additional sqlite3_trace() callbacks might occur |
| 3107 ** as each triggered subprogram is entered. The callbacks for triggers |
| 3108 ** contain a UTF-8 SQL comment that identifies the trigger.)^ |
| 3109 ** |
| 3110 ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit |
| 3111 ** the length of [bound parameter] expansion in the output of sqlite3_trace(). |
| 3112 ** |
| 3113 ** ^The callback function registered by sqlite3_profile() is invoked |
| 3114 ** as each SQL statement finishes. ^The profile callback contains |
| 3115 ** the original statement text and an estimate of wall-clock time |
| 3116 ** of how long that statement took to run. ^The profile callback |
| 3117 ** time is in units of nanoseconds, however the current implementation |
| 3118 ** is only capable of millisecond resolution so the six least significant |
| 3119 ** digits in the time are meaningless. Future versions of SQLite |
| 3120 ** might provide greater resolution on the profiler callback. The |
| 3121 ** sqlite3_profile() function is considered experimental and is |
| 3122 ** subject to change in future versions of SQLite. |
| 3123 */ |
| 3124 SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*, |
| 3125 void(*xTrace)(void*,const char*), void*); |
| 3126 SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, |
| 3127 void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
| 3128 |
| 3129 /* |
| 3130 ** CAPI3REF: SQL Trace Event Codes |
| 3131 ** KEYWORDS: SQLITE_TRACE |
| 3132 ** |
| 3133 ** These constants identify classes of events that can be monitored |
| 3134 ** using the [sqlite3_trace_v2()] tracing logic. The third argument |
| 3135 ** to [sqlite3_trace_v2()] is an OR-ed combination of one or more of |
| 3136 ** the following constants. ^The first argument to the trace callback |
| 3137 ** is one of the following constants. |
| 3138 ** |
| 3139 ** New tracing constants may be added in future releases. |
| 3140 ** |
| 3141 ** ^A trace callback has four arguments: xCallback(T,C,P,X). |
| 3142 ** ^The T argument is one of the integer type codes above. |
| 3143 ** ^The C argument is a copy of the context pointer passed in as the |
| 3144 ** fourth argument to [sqlite3_trace_v2()]. |
| 3145 ** The P and X arguments are pointers whose meanings depend on T. |
| 3146 ** |
| 3147 ** <dl> |
| 3148 ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt> |
| 3149 ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement |
| 3150 ** first begins running and possibly at other times during the |
| 3151 ** execution of the prepared statement, such as at the start of each |
| 3152 ** trigger subprogram. ^The P argument is a pointer to the |
| 3153 ** [prepared statement]. ^The X argument is a pointer to a string which |
| 3154 ** is the unexpanded SQL text of the prepared statement or an SQL comment |
| 3155 ** that indicates the invocation of a trigger. ^The callback can compute |
| 3156 ** the same text that would have been returned by the legacy [sqlite3_trace()] |
| 3157 ** interface by using the X argument when X begins with "--" and invoking |
| 3158 ** [sqlite3_expanded_sql(P)] otherwise. |
| 3159 ** |
| 3160 ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt> |
| 3161 ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same |
| 3162 ** information as is provided by the [sqlite3_profile()] callback. |
| 3163 ** ^The P argument is a pointer to the [prepared statement] and the |
| 3164 ** X argument points to a 64-bit integer which is the estimated of |
| 3165 ** the number of nanosecond that the prepared statement took to run. |
| 3166 ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes. |
| 3167 ** |
| 3168 ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt> |
| 3169 ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared |
| 3170 ** statement generates a single row of result. |
| 3171 ** ^The P argument is a pointer to the [prepared statement] and the |
| 3172 ** X argument is unused. |
| 3173 ** |
| 3174 ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt> |
| 3175 ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database |
| 3176 ** connection closes. |
| 3177 ** ^The P argument is a pointer to the [database connection] object |
| 3178 ** and the X argument is unused. |
| 3179 ** </dl> |
| 3180 */ |
| 3181 #define SQLITE_TRACE_STMT 0x01 |
| 3182 #define SQLITE_TRACE_PROFILE 0x02 |
| 3183 #define SQLITE_TRACE_ROW 0x04 |
| 3184 #define SQLITE_TRACE_CLOSE 0x08 |
| 3185 |
| 3186 /* |
| 3187 ** CAPI3REF: SQL Trace Hook |
| 3188 ** METHOD: sqlite3 |
| 3189 ** |
| 3190 ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback |
| 3191 ** function X against [database connection] D, using property mask M |
| 3192 ** and context pointer P. ^If the X callback is |
| 3193 ** NULL or if the M mask is zero, then tracing is disabled. The |
| 3194 ** M argument should be the bitwise OR-ed combination of |
| 3195 ** zero or more [SQLITE_TRACE] constants. |
| 3196 ** |
| 3197 ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides |
| 3198 ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2(). |
| 3199 ** |
| 3200 ** ^The X callback is invoked whenever any of the events identified by |
| 3201 ** mask M occur. ^The integer return value from the callback is currently |
| 3202 ** ignored, though this may change in future releases. Callback |
| 3203 ** implementations should return zero to ensure future compatibility. |
| 3204 ** |
| 3205 ** ^A trace callback is invoked with four arguments: callback(T,C,P,X). |
| 3206 ** ^The T argument is one of the [SQLITE_TRACE] |
| 3207 ** constants to indicate why the callback was invoked. |
| 3208 ** ^The C argument is a copy of the context pointer. |
| 3209 ** The P and X arguments are pointers whose meanings depend on T. |
| 3210 ** |
| 3211 ** The sqlite3_trace_v2() interface is intended to replace the legacy |
| 3212 ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which |
| 3213 ** are deprecated. |
| 3214 */ |
| 3215 SQLITE_API int sqlite3_trace_v2( |
| 3216 sqlite3*, |
| 3217 unsigned uMask, |
| 3218 int(*xCallback)(unsigned,void*,void*,void*), |
| 3219 void *pCtx |
| 3220 ); |
| 3221 |
| 3222 /* |
| 3223 ** CAPI3REF: Query Progress Callbacks |
| 3224 ** METHOD: sqlite3 |
| 3225 ** |
| 3226 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 3227 ** function X to be invoked periodically during long running calls to |
| 3228 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 3229 ** database connection D. An example use for this |
| 3230 ** interface is to keep a GUI updated during a large query. |
| 3231 ** |
| 3232 ** ^The parameter P is passed through as the only parameter to the |
| 3233 ** callback function X. ^The parameter N is the approximate number of |
| 3234 ** [virtual machine instructions] that are evaluated between successive |
| 3235 ** invocations of the callback X. ^If N is less than one then the progress |
| 3236 ** handler is disabled. |
| 3237 ** |
| 3238 ** ^Only a single progress handler may be defined at one time per |
| 3239 ** [database connection]; setting a new progress handler cancels the |
| 3240 ** old one. ^Setting parameter X to NULL disables the progress handler. |
| 3241 ** ^The progress handler is also disabled by setting N to a value less |
| 3242 ** than 1. |
| 3243 ** |
| 3244 ** ^If the progress callback returns non-zero, the operation is |
| 3245 ** interrupted. This feature can be used to implement a |
| 3246 ** "Cancel" button on a GUI progress dialog box. |
| 3247 ** |
| 3248 ** The progress handler callback must not do anything that will modify |
| 3249 ** the database connection that invoked the progress handler. |
| 3250 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
| 3251 ** database connections for the meaning of "modify" in this paragraph. |
| 3252 ** |
| 3253 */ |
| 3254 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 3255 |
| 3256 /* |
| 3257 ** CAPI3REF: Opening A New Database Connection |
| 3258 ** CONSTRUCTOR: sqlite3 |
| 3259 ** |
| 3260 ** ^These routines open an SQLite database file as specified by the |
| 3261 ** filename argument. ^The filename argument is interpreted as UTF-8 for |
| 3262 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte |
| 3263 ** order for sqlite3_open16(). ^(A [database connection] handle is usually |
| 3264 ** returned in *ppDb, even if an error occurs. The only exception is that |
| 3265 ** if SQLite is unable to allocate memory to hold the [sqlite3] object, |
| 3266 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] |
| 3267 ** object.)^ ^(If the database is opened (and/or created) successfully, then |
| 3268 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The |
| 3269 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain |
| 3270 ** an English language description of the error following a failure of any |
| 3271 ** of the sqlite3_open() routines. |
| 3272 ** |
| 3273 ** ^The default encoding will be UTF-8 for databases created using |
| 3274 ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases |
| 3275 ** created using sqlite3_open16() will be UTF-16 in the native byte order. |
| 3276 ** |
| 3277 ** Whether or not an error occurs when it is opened, resources |
| 3278 ** associated with the [database connection] handle should be released by |
| 3279 ** passing it to [sqlite3_close()] when it is no longer required. |
| 3280 ** |
| 3281 ** The sqlite3_open_v2() interface works like sqlite3_open() |
| 3282 ** except that it accepts two additional parameters for additional control |
| 3283 ** over the new database connection. ^(The flags parameter to |
| 3284 ** sqlite3_open_v2() can take one of |
| 3285 ** the following three values, optionally combined with the |
| 3286 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 3287 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ |
| 3288 ** |
| 3289 ** <dl> |
| 3290 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 3291 ** <dd>The database is opened in read-only mode. If the database does not |
| 3292 ** already exist, an error is returned.</dd>)^ |
| 3293 ** |
| 3294 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> |
| 3295 ** <dd>The database is opened for reading and writing if possible, or reading |
| 3296 ** only if the file is write protected by the operating system. In either |
| 3297 ** case the database must already exist, otherwise an error is returned.</dd>)^ |
| 3298 ** |
| 3299 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> |
| 3300 ** <dd>The database is opened for reading and writing, and is created if |
| 3301 ** it does not already exist. This is the behavior that is always used for |
| 3302 ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 3303 ** </dl> |
| 3304 ** |
| 3305 ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 3306 ** combinations shown above optionally combined with other |
| 3307 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
| 3308 ** then the behavior is undefined. |
| 3309 ** |
| 3310 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 3311 ** opens in the multi-thread [threading mode] as long as the single-thread |
| 3312 ** mode has not been set at compile-time or start-time. ^If the |
| 3313 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens |
| 3314 ** in the serialized [threading mode] unless single-thread was |
| 3315 ** previously selected at compile-time or start-time. |
| 3316 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 3317 ** eligible to use [shared cache mode], regardless of whether or not shared |
| 3318 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 3319 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 3320 ** participate in [shared cache mode] even if it is enabled. |
| 3321 ** |
| 3322 ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 3323 ** [sqlite3_vfs] object that defines the operating system interface that |
| 3324 ** the new database connection should use. ^If the fourth parameter is |
| 3325 ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| 3326 ** |
| 3327 ** ^If the filename is ":memory:", then a private, temporary in-memory database |
| 3328 ** is created for the connection. ^This in-memory database will vanish when |
| 3329 ** the database connection is closed. Future versions of SQLite might |
| 3330 ** make use of additional special filenames that begin with the ":" character. |
| 3331 ** It is recommended that when a database filename actually does begin with |
| 3332 ** a ":" character you should prefix the filename with a pathname such as |
| 3333 ** "./" to avoid ambiguity. |
| 3334 ** |
| 3335 ** ^If the filename is an empty string, then a private, temporary |
| 3336 ** on-disk database will be created. ^This private database will be |
| 3337 ** automatically deleted as soon as the database connection is closed. |
| 3338 ** |
| 3339 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> |
| 3340 ** |
| 3341 ** ^If [URI filename] interpretation is enabled, and the filename argument |
| 3342 ** begins with "file:", then the filename is interpreted as a URI. ^URI |
| 3343 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is |
| 3344 ** set in the fourth argument to sqlite3_open_v2(), or if it has |
| 3345 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the |
| 3346 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. |
| 3347 ** As of SQLite version 3.7.7, URI filename interpretation is turned off |
| 3348 ** by default, but future releases of SQLite might enable URI filename |
| 3349 ** interpretation by default. See "[URI filenames]" for additional |
| 3350 ** information. |
| 3351 ** |
| 3352 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an |
| 3353 ** authority, then it must be either an empty string or the string |
| 3354 ** "localhost". ^If the authority is not an empty string or "localhost", an |
| 3355 ** error is returned to the caller. ^The fragment component of a URI, if |
| 3356 ** present, is ignored. |
| 3357 ** |
| 3358 ** ^SQLite uses the path component of the URI as the name of the disk file |
| 3359 ** which contains the database. ^If the path begins with a '/' character, |
| 3360 ** then it is interpreted as an absolute path. ^If the path does not begin |
| 3361 ** with a '/' (meaning that the authority section is omitted from the URI) |
| 3362 ** then the path is interpreted as a relative path. |
| 3363 ** ^(On windows, the first component of an absolute path |
| 3364 ** is a drive specification (e.g. "C:").)^ |
| 3365 ** |
| 3366 ** [[core URI query parameters]] |
| 3367 ** The query component of a URI may contain parameters that are interpreted |
| 3368 ** either by SQLite itself, or by a [VFS | custom VFS implementation]. |
| 3369 ** SQLite and its built-in [VFSes] interpret the |
| 3370 ** following query parameters: |
| 3371 ** |
| 3372 ** <ul> |
| 3373 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of |
| 3374 ** a VFS object that provides the operating system interface that should |
| 3375 ** be used to access the database file on disk. ^If this option is set to |
| 3376 ** an empty string the default VFS object is used. ^Specifying an unknown |
| 3377 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is |
| 3378 ** present, then the VFS specified by the option takes precedence over |
| 3379 ** the value passed as the fourth parameter to sqlite3_open_v2(). |
| 3380 ** |
| 3381 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", |
| 3382 ** "rwc", or "memory". Attempting to set it to any other value is |
| 3383 ** an error)^. |
| 3384 ** ^If "ro" is specified, then the database is opened for read-only |
| 3385 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the |
| 3386 ** third argument to sqlite3_open_v2(). ^If the mode option is set to |
| 3387 ** "rw", then the database is opened for read-write (but not create) |
| 3388 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had |
| 3389 ** been set. ^Value "rwc" is equivalent to setting both |
| 3390 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is |
| 3391 ** set to "memory" then a pure [in-memory database] that never reads |
| 3392 ** or writes from disk is used. ^It is an error to specify a value for |
| 3393 ** the mode parameter that is less restrictive than that specified by |
| 3394 ** the flags passed in the third parameter to sqlite3_open_v2(). |
| 3395 ** |
| 3396 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or |
| 3397 ** "private". ^Setting it to "shared" is equivalent to setting the |
| 3398 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to |
| 3399 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is |
| 3400 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. |
| 3401 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in |
| 3402 ** a URI filename, its value overrides any behavior requested by setting |
| 3403 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. |
| 3404 ** |
| 3405 ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the |
| 3406 ** [powersafe overwrite] property does or does not apply to the |
| 3407 ** storage media on which the database file resides. |
| 3408 ** |
| 3409 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter |
| 3410 ** which if set disables file locking in rollback journal modes. This |
| 3411 ** is useful for accessing a database on a filesystem that does not |
| 3412 ** support locking. Caution: Database corruption might result if two |
| 3413 ** or more processes write to the same database and any one of those |
| 3414 ** processes uses nolock=1. |
| 3415 ** |
| 3416 ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query |
| 3417 ** parameter that indicates that the database file is stored on |
| 3418 ** read-only media. ^When immutable is set, SQLite assumes that the |
| 3419 ** database file cannot be changed, even by a process with higher |
| 3420 ** privilege, and so the database is opened read-only and all locking |
| 3421 ** and change detection is disabled. Caution: Setting the immutable |
| 3422 ** property on a database file that does in fact change can result |
| 3423 ** in incorrect query results and/or [SQLITE_CORRUPT] errors. |
| 3424 ** See also: [SQLITE_IOCAP_IMMUTABLE]. |
| 3425 ** |
| 3426 ** </ul> |
| 3427 ** |
| 3428 ** ^Specifying an unknown parameter in the query component of a URI is not an |
| 3429 ** error. Future versions of SQLite might understand additional query |
| 3430 ** parameters. See "[query parameters with special meaning to SQLite]" for |
| 3431 ** additional information. |
| 3432 ** |
| 3433 ** [[URI filename examples]] <h3>URI filename examples</h3> |
| 3434 ** |
| 3435 ** <table border="1" align=center cellpadding=5> |
| 3436 ** <tr><th> URI filenames <th> Results |
| 3437 ** <tr><td> file:data.db <td> |
| 3438 ** Open the file "data.db" in the current directory. |
| 3439 ** <tr><td> file:/home/fred/data.db<br> |
| 3440 ** file:///home/fred/data.db <br> |
| 3441 ** file://localhost/home/fred/data.db <br> <td> |
| 3442 ** Open the database file "/home/fred/data.db". |
| 3443 ** <tr><td> file://darkstar/home/fred/data.db <td> |
| 3444 ** An error. "darkstar" is not a recognized authority. |
| 3445 ** <tr><td style="white-space:nowrap"> |
| 3446 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db |
| 3447 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive |
| 3448 ** C:. Note that the %20 escaping in this example is not strictly |
| 3449 ** necessary - space characters can be used literally |
| 3450 ** in URI filenames. |
| 3451 ** <tr><td> file:data.db?mode=ro&cache=private <td> |
| 3452 ** Open file "data.db" in the current directory for read-only access. |
| 3453 ** Regardless of whether or not shared-cache mode is enabled by |
| 3454 ** default, use a private cache. |
| 3455 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td> |
| 3456 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile" |
| 3457 ** that uses dot-files in place of posix advisory locking. |
| 3458 ** <tr><td> file:data.db?mode=readonly <td> |
| 3459 ** An error. "readonly" is not a valid option for the "mode" parameter. |
| 3460 ** </table> |
| 3461 ** |
| 3462 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and |
| 3463 ** query components of a URI. A hexadecimal escape sequence consists of a |
| 3464 ** percent sign - "%" - followed by exactly two hexadecimal digits |
| 3465 ** specifying an octet value. ^Before the path or query components of a |
| 3466 ** URI filename are interpreted, they are encoded using UTF-8 and all |
| 3467 ** hexadecimal escape sequences replaced by a single byte containing the |
| 3468 ** corresponding octet. If this process generates an invalid UTF-8 encoding, |
| 3469 ** the results are undefined. |
| 3470 ** |
| 3471 ** <b>Note to Windows users:</b> The encoding used for the filename argument |
| 3472 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever |
| 3473 ** codepage is currently defined. Filenames containing international |
| 3474 ** characters must be converted to UTF-8 prior to passing them into |
| 3475 ** sqlite3_open() or sqlite3_open_v2(). |
| 3476 ** |
| 3477 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set |
| 3478 ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various |
| 3479 ** features that require the use of temporary files may fail. |
| 3480 ** |
| 3481 ** See also: [sqlite3_temp_directory] |
| 3482 */ |
| 3483 SQLITE_API int sqlite3_open( |
| 3484 const char *filename, /* Database filename (UTF-8) */ |
| 3485 sqlite3 **ppDb /* OUT: SQLite db handle */ |
| 3486 ); |
| 3487 SQLITE_API int sqlite3_open16( |
| 3488 const void *filename, /* Database filename (UTF-16) */ |
| 3489 sqlite3 **ppDb /* OUT: SQLite db handle */ |
| 3490 ); |
| 3491 SQLITE_API int sqlite3_open_v2( |
| 3492 const char *filename, /* Database filename (UTF-8) */ |
| 3493 sqlite3 **ppDb, /* OUT: SQLite db handle */ |
| 3494 int flags, /* Flags */ |
| 3495 const char *zVfs /* Name of VFS module to use */ |
| 3496 ); |
| 3497 |
| 3498 /* |
| 3499 ** CAPI3REF: Obtain Values For URI Parameters |
| 3500 ** |
| 3501 ** These are utility routines, useful to VFS implementations, that check |
| 3502 ** to see if a database file was a URI that contained a specific query |
| 3503 ** parameter, and if so obtains the value of that query parameter. |
| 3504 ** |
| 3505 ** If F is the database filename pointer passed into the xOpen() method of |
| 3506 ** a VFS implementation when the flags parameter to xOpen() has one or |
| 3507 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and |
| 3508 ** P is the name of the query parameter, then |
| 3509 ** sqlite3_uri_parameter(F,P) returns the value of the P |
| 3510 ** parameter if it exists or a NULL pointer if P does not appear as a |
| 3511 ** query parameter on F. If P is a query parameter of F |
| 3512 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns |
| 3513 ** a pointer to an empty string. |
| 3514 ** |
| 3515 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean |
| 3516 ** parameter and returns true (1) or false (0) according to the value |
| 3517 ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the |
| 3518 ** value of query parameter P is one of "yes", "true", or "on" in any |
| 3519 ** case or if the value begins with a non-zero number. The |
| 3520 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of |
| 3521 ** query parameter P is one of "no", "false", or "off" in any case or |
| 3522 ** if the value begins with a numeric zero. If P is not a query |
| 3523 ** parameter on F or if the value of P is does not match any of the |
| 3524 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). |
| 3525 ** |
| 3526 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 3527 ** 64-bit signed integer and returns that integer, or D if P does not |
| 3528 ** exist. If the value of P is something other than an integer, then |
| 3529 ** zero is returned. |
| 3530 ** |
| 3531 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and |
| 3532 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and |
| 3533 ** is not a database file pathname pointer that SQLite passed into the xOpen |
| 3534 ** VFS method, then the behavior of this routine is undefined and probably |
| 3535 ** undesirable. |
| 3536 */ |
| 3537 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *
zParam); |
| 3538 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bD
efault); |
| 3539 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int
64); |
| 3540 |
| 3541 |
| 3542 /* |
| 3543 ** CAPI3REF: Error Codes And Messages |
| 3544 ** METHOD: sqlite3 |
| 3545 ** |
| 3546 ** ^If the most recent sqlite3_* API call associated with |
| 3547 ** [database connection] D failed, then the sqlite3_errcode(D) interface |
| 3548 ** returns the numeric [result code] or [extended result code] for that |
| 3549 ** API call. |
| 3550 ** If the most recent API call was successful, |
| 3551 ** then the return value from sqlite3_errcode() is undefined. |
| 3552 ** ^The sqlite3_extended_errcode() |
| 3553 ** interface is the same except that it always returns the |
| 3554 ** [extended result code] even when extended result codes are |
| 3555 ** disabled. |
| 3556 ** |
| 3557 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language |
| 3558 ** text that describes the error, as either UTF-8 or UTF-16 respectively. |
| 3559 ** ^(Memory to hold the error message string is managed internally. |
| 3560 ** The application does not need to worry about freeing the result. |
| 3561 ** However, the error string might be overwritten or deallocated by |
| 3562 ** subsequent calls to other SQLite interface functions.)^ |
| 3563 ** |
| 3564 ** ^The sqlite3_errstr() interface returns the English-language text |
| 3565 ** that describes the [result code], as UTF-8. |
| 3566 ** ^(Memory to hold the error message string is managed internally |
| 3567 ** and must not be freed by the application)^. |
| 3568 ** |
| 3569 ** When the serialized [threading mode] is in use, it might be the |
| 3570 ** case that a second error occurs on a separate thread in between |
| 3571 ** the time of the first error and the call to these interfaces. |
| 3572 ** When that happens, the second error will be reported since these |
| 3573 ** interfaces always report the most recent result. To avoid |
| 3574 ** this, each thread can obtain exclusive use of the [database connection] D |
| 3575 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning |
| 3576 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after |
| 3577 ** all calls to the interfaces listed here are completed. |
| 3578 ** |
| 3579 ** If an interface fails with SQLITE_MISUSE, that means the interface |
| 3580 ** was invoked incorrectly by the application. In that case, the |
| 3581 ** error code and message may or may not be set. |
| 3582 */ |
| 3583 SQLITE_API int sqlite3_errcode(sqlite3 *db); |
| 3584 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); |
| 3585 SQLITE_API const char *sqlite3_errmsg(sqlite3*); |
| 3586 SQLITE_API const void *sqlite3_errmsg16(sqlite3*); |
| 3587 SQLITE_API const char *sqlite3_errstr(int); |
| 3588 |
| 3589 /* |
| 3590 ** CAPI3REF: Prepared Statement Object |
| 3591 ** KEYWORDS: {prepared statement} {prepared statements} |
| 3592 ** |
| 3593 ** An instance of this object represents a single SQL statement that |
| 3594 ** has been compiled into binary form and is ready to be evaluated. |
| 3595 ** |
| 3596 ** Think of each SQL statement as a separate computer program. The |
| 3597 ** original SQL text is source code. A prepared statement object |
| 3598 ** is the compiled object code. All SQL must be converted into a |
| 3599 ** prepared statement before it can be run. |
| 3600 ** |
| 3601 ** The life-cycle of a prepared statement object usually goes like this: |
| 3602 ** |
| 3603 ** <ol> |
| 3604 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. |
| 3605 ** <li> Bind values to [parameters] using the sqlite3_bind_*() |
| 3606 ** interfaces. |
| 3607 ** <li> Run the SQL by calling [sqlite3_step()] one or more times. |
| 3608 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back |
| 3609 ** to step 2. Do this zero or more times. |
| 3610 ** <li> Destroy the object using [sqlite3_finalize()]. |
| 3611 ** </ol> |
| 3612 */ |
| 3613 typedef struct sqlite3_stmt sqlite3_stmt; |
| 3614 |
| 3615 /* |
| 3616 ** CAPI3REF: Run-time Limits |
| 3617 ** METHOD: sqlite3 |
| 3618 ** |
| 3619 ** ^(This interface allows the size of various constructs to be limited |
| 3620 ** on a connection by connection basis. The first parameter is the |
| 3621 ** [database connection] whose limit is to be set or queried. The |
| 3622 ** second parameter is one of the [limit categories] that define a |
| 3623 ** class of constructs to be size limited. The third parameter is the |
| 3624 ** new limit for that construct.)^ |
| 3625 ** |
| 3626 ** ^If the new limit is a negative number, the limit is unchanged. |
| 3627 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a |
| 3628 ** [limits | hard upper bound] |
| 3629 ** set at compile-time by a C preprocessor macro called |
| 3630 ** [limits | SQLITE_MAX_<i>NAME</i>]. |
| 3631 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ |
| 3632 ** ^Attempts to increase a limit above its hard upper bound are |
| 3633 ** silently truncated to the hard upper bound. |
| 3634 ** |
| 3635 ** ^Regardless of whether or not the limit was changed, the |
| 3636 ** [sqlite3_limit()] interface returns the prior value of the limit. |
| 3637 ** ^Hence, to find the current value of a limit without changing it, |
| 3638 ** simply invoke this interface with the third parameter set to -1. |
| 3639 ** |
| 3640 ** Run-time limits are intended for use in applications that manage |
| 3641 ** both their own internal database and also databases that are controlled |
| 3642 ** by untrusted external sources. An example application might be a |
| 3643 ** web browser that has its own databases for storing history and |
| 3644 ** separate databases controlled by JavaScript applications downloaded |
| 3645 ** off the Internet. The internal databases can be given the |
| 3646 ** large, default limits. Databases managed by external sources can |
| 3647 ** be given much smaller limits designed to prevent a denial of service |
| 3648 ** attack. Developers might also want to use the [sqlite3_set_authorizer()] |
| 3649 ** interface to further control untrusted SQL. The size of the database |
| 3650 ** created by an untrusted script can be contained using the |
| 3651 ** [max_page_count] [PRAGMA]. |
| 3652 ** |
| 3653 ** New run-time limit categories may be added in future releases. |
| 3654 */ |
| 3655 SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); |
| 3656 |
| 3657 /* |
| 3658 ** CAPI3REF: Run-Time Limit Categories |
| 3659 ** KEYWORDS: {limit category} {*limit categories} |
| 3660 ** |
| 3661 ** These constants define various performance limits |
| 3662 ** that can be lowered at run-time using [sqlite3_limit()]. |
| 3663 ** The synopsis of the meanings of the various limits is shown below. |
| 3664 ** Additional information is available at [limits | Limits in SQLite]. |
| 3665 ** |
| 3666 ** <dl> |
| 3667 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> |
| 3668 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ |
| 3669 ** |
| 3670 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> |
| 3671 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ |
| 3672 ** |
| 3673 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> |
| 3674 ** <dd>The maximum number of columns in a table definition or in the |
| 3675 ** result set of a [SELECT] or the maximum number of columns in an index |
| 3676 ** or in an ORDER BY or GROUP BY clause.</dd>)^ |
| 3677 ** |
| 3678 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> |
| 3679 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ |
| 3680 ** |
| 3681 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
| 3682 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 3683 ** |
| 3684 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
| 3685 ** <dd>The maximum number of instructions in a virtual machine program |
| 3686 ** used to implement an SQL statement. This limit is not currently |
| 3687 ** enforced, though that might be added in some future release of |
| 3688 ** SQLite.</dd>)^ |
| 3689 ** |
| 3690 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
| 3691 ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 3692 ** |
| 3693 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
| 3694 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> |
| 3695 ** |
| 3696 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] |
| 3697 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> |
| 3698 ** <dd>The maximum length of the pattern argument to the [LIKE] or |
| 3699 ** [GLOB] operators.</dd>)^ |
| 3700 ** |
| 3701 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] |
| 3702 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> |
| 3703 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ |
| 3704 ** |
| 3705 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> |
| 3706 ** <dd>The maximum depth of recursion for triggers.</dd>)^ |
| 3707 ** |
| 3708 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> |
| 3709 ** <dd>The maximum number of auxiliary worker threads that a single |
| 3710 ** [prepared statement] may start.</dd>)^ |
| 3711 ** </dl> |
| 3712 */ |
| 3713 #define SQLITE_LIMIT_LENGTH 0 |
| 3714 #define SQLITE_LIMIT_SQL_LENGTH 1 |
| 3715 #define SQLITE_LIMIT_COLUMN 2 |
| 3716 #define SQLITE_LIMIT_EXPR_DEPTH 3 |
| 3717 #define SQLITE_LIMIT_COMPOUND_SELECT 4 |
| 3718 #define SQLITE_LIMIT_VDBE_OP 5 |
| 3719 #define SQLITE_LIMIT_FUNCTION_ARG 6 |
| 3720 #define SQLITE_LIMIT_ATTACHED 7 |
| 3721 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 |
| 3722 #define SQLITE_LIMIT_VARIABLE_NUMBER 9 |
| 3723 #define SQLITE_LIMIT_TRIGGER_DEPTH 10 |
| 3724 #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3725 |
| 3726 /* |
| 3727 ** CAPI3REF: Compiling An SQL Statement |
| 3728 ** KEYWORDS: {SQL statement compiler} |
| 3729 ** METHOD: sqlite3 |
| 3730 ** CONSTRUCTOR: sqlite3_stmt |
| 3731 ** |
| 3732 ** To execute an SQL query, it must first be compiled into a byte-code |
| 3733 ** program using one of these routines. |
| 3734 ** |
| 3735 ** The first argument, "db", is a [database connection] obtained from a |
| 3736 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or |
| 3737 ** [sqlite3_open16()]. The database connection must not have been closed. |
| 3738 ** |
| 3739 ** The second argument, "zSql", is the statement to be compiled, encoded |
| 3740 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() |
| 3741 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() |
| 3742 ** use UTF-16. |
| 3743 ** |
| 3744 ** ^If the nByte argument is negative, then zSql is read up to the |
| 3745 ** first zero terminator. ^If nByte is positive, then it is the |
| 3746 ** number of bytes read from zSql. ^If nByte is zero, then no prepared |
| 3747 ** statement is generated. |
| 3748 ** If the caller knows that the supplied string is nul-terminated, then |
| 3749 ** there is a small performance advantage to passing an nByte parameter that |
| 3750 ** is the number of bytes in the input string <i>including</i> |
| 3751 ** the nul-terminator. |
| 3752 ** |
| 3753 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte |
| 3754 ** past the end of the first SQL statement in zSql. These routines only |
| 3755 ** compile the first statement in zSql, so *pzTail is left pointing to |
| 3756 ** what remains uncompiled. |
| 3757 ** |
| 3758 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be |
| 3759 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set |
| 3760 ** to NULL. ^If the input text contains no SQL (if the input is an empty |
| 3761 ** string or a comment) then *ppStmt is set to NULL. |
| 3762 ** The calling procedure is responsible for deleting the compiled |
| 3763 ** SQL statement using [sqlite3_finalize()] after it has finished with it. |
| 3764 ** ppStmt may not be NULL. |
| 3765 ** |
| 3766 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; |
| 3767 ** otherwise an [error code] is returned. |
| 3768 ** |
| 3769 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are |
| 3770 ** recommended for all new programs. The two older interfaces are retained |
| 3771 ** for backwards compatibility, but their use is discouraged. |
| 3772 ** ^In the "v2" interfaces, the prepared statement |
| 3773 ** that is returned (the [sqlite3_stmt] object) contains a copy of the |
| 3774 ** original SQL text. This causes the [sqlite3_step()] interface to |
| 3775 ** behave differently in three ways: |
| 3776 ** |
| 3777 ** <ol> |
| 3778 ** <li> |
| 3779 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it |
| 3780 ** always used to do, [sqlite3_step()] will automatically recompile the SQL |
| 3781 ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY] |
| 3782 ** retries will occur before sqlite3_step() gives up and returns an error. |
| 3783 ** </li> |
| 3784 ** |
| 3785 ** <li> |
| 3786 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed |
| 3787 ** [error codes] or [extended error codes]. ^The legacy behavior was that |
| 3788 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code |
| 3789 ** and the application would have to make a second call to [sqlite3_reset()] |
| 3790 ** in order to find the underlying cause of the problem. With the "v2" prepare |
| 3791 ** interfaces, the underlying reason for the error is returned immediately. |
| 3792 ** </li> |
| 3793 ** |
| 3794 ** <li> |
| 3795 ** ^If the specific value bound to [parameter | host parameter] in the |
| 3796 ** WHERE clause might influence the choice of query plan for a statement, |
| 3797 ** then the statement will be automatically recompiled, as if there had been |
| 3798 ** a schema change, on the first [sqlite3_step()] call following any change |
| 3799 ** to the [sqlite3_bind_text | bindings] of that [parameter]. |
| 3800 ** ^The specific value of WHERE-clause [parameter] might influence the |
| 3801 ** choice of query plan if the parameter is the left-hand side of a [LIKE] |
| 3802 ** or [GLOB] operator or if the parameter is compared to an indexed column |
| 3803 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. |
| 3804 ** </li> |
| 3805 ** </ol> |
| 3806 */ |
| 3807 SQLITE_API int sqlite3_prepare( |
| 3808 sqlite3 *db, /* Database handle */ |
| 3809 const char *zSql, /* SQL statement, UTF-8 encoded */ |
| 3810 int nByte, /* Maximum length of zSql in bytes. */ |
| 3811 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3812 const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3813 ); |
| 3814 SQLITE_API int sqlite3_prepare_v2( |
| 3815 sqlite3 *db, /* Database handle */ |
| 3816 const char *zSql, /* SQL statement, UTF-8 encoded */ |
| 3817 int nByte, /* Maximum length of zSql in bytes. */ |
| 3818 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3819 const char **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3820 ); |
| 3821 SQLITE_API int sqlite3_prepare16( |
| 3822 sqlite3 *db, /* Database handle */ |
| 3823 const void *zSql, /* SQL statement, UTF-16 encoded */ |
| 3824 int nByte, /* Maximum length of zSql in bytes. */ |
| 3825 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3826 const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3827 ); |
| 3828 SQLITE_API int sqlite3_prepare16_v2( |
| 3829 sqlite3 *db, /* Database handle */ |
| 3830 const void *zSql, /* SQL statement, UTF-16 encoded */ |
| 3831 int nByte, /* Maximum length of zSql in bytes. */ |
| 3832 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ |
| 3833 const void **pzTail /* OUT: Pointer to unused portion of zSql */ |
| 3834 ); |
| 3835 |
| 3836 /* |
| 3837 ** CAPI3REF: Retrieving Statement SQL |
| 3838 ** METHOD: sqlite3_stmt |
| 3839 ** |
| 3840 ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8 |
| 3841 ** SQL text used to create [prepared statement] P if P was |
| 3842 ** created by either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. |
| 3843 ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8 |
| 3844 ** string containing the SQL text of prepared statement P with |
| 3845 ** [bound parameters] expanded. |
| 3846 ** |
| 3847 ** ^(For example, if a prepared statement is created using the SQL |
| 3848 ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345 |
| 3849 ** and parameter :xyz is unbound, then sqlite3_sql() will return |
| 3850 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql() |
| 3851 ** will return "SELECT 2345,NULL".)^ |
| 3852 ** |
| 3853 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory |
| 3854 ** is available to hold the result, or if the result would exceed the |
| 3855 ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH]. |
| 3856 ** |
| 3857 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of |
| 3858 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time |
| 3859 ** option causes sqlite3_expanded_sql() to always return NULL. |
| 3860 ** |
| 3861 ** ^The string returned by sqlite3_sql(P) is managed by SQLite and is |
| 3862 ** automatically freed when the prepared statement is finalized. |
| 3863 ** ^The string returned by sqlite3_expanded_sql(P), on the other hand, |
| 3864 ** is obtained from [sqlite3_malloc()] and must be free by the application |
| 3865 ** by passing it to [sqlite3_free()]. |
| 3866 */ |
| 3867 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); |
| 3868 SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); |
| 3869 |
| 3870 /* |
| 3871 ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 3872 ** METHOD: sqlite3_stmt |
| 3873 ** |
| 3874 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if |
| 3875 ** and only if the [prepared statement] X makes no direct changes to |
| 3876 ** the content of the database file. |
| 3877 ** |
| 3878 ** Note that [application-defined SQL functions] or |
| 3879 ** [virtual tables] might change the database indirectly as a side effect. |
| 3880 ** ^(For example, if an application defines a function "eval()" that |
| 3881 ** calls [sqlite3_exec()], then the following SQL statement would |
| 3882 ** change the database file through side-effects: |
| 3883 ** |
| 3884 ** <blockquote><pre> |
| 3885 ** SELECT eval('DELETE FROM t1') FROM t2; |
| 3886 ** </pre></blockquote> |
| 3887 ** |
| 3888 ** But because the [SELECT] statement does not change the database file |
| 3889 ** directly, sqlite3_stmt_readonly() would still return true.)^ |
| 3890 ** |
| 3891 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], |
| 3892 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, |
| 3893 ** since the statements themselves do not actually modify the database but |
| 3894 ** rather they control the timing of when other statements modify the |
| 3895 ** database. ^The [ATTACH] and [DETACH] statements also cause |
| 3896 ** sqlite3_stmt_readonly() to return true since, while those statements |
| 3897 ** change the configuration of a database connection, they do not make |
| 3898 ** changes to the content of the database files on disk. |
| 3899 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since |
| 3900 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and |
| 3901 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so |
| 3902 ** sqlite3_stmt_readonly() returns false for those commands. |
| 3903 */ |
| 3904 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3905 |
| 3906 /* |
| 3907 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| 3908 ** METHOD: sqlite3_stmt |
| 3909 ** |
| 3910 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the |
| 3911 ** [prepared statement] S has been stepped at least once using |
| 3912 ** [sqlite3_step(S)] but has neither run to completion (returned |
| 3913 ** [SQLITE_DONE] from [sqlite3_step(S)]) nor |
| 3914 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) |
| 3915 ** interface returns false if S is a NULL pointer. If S is not a |
| 3916 ** NULL pointer and is not a pointer to a valid [prepared statement] |
| 3917 ** object, then the behavior is undefined and probably undesirable. |
| 3918 ** |
| 3919 ** This interface can be used in combination [sqlite3_next_stmt()] |
| 3920 ** to locate all prepared statements associated with a database |
| 3921 ** connection that are in need of being reset. This can be used, |
| 3922 ** for example, in diagnostic routines to search for prepared |
| 3923 ** statements that are holding a transaction open. |
| 3924 */ |
| 3925 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); |
| 3926 |
| 3927 /* |
| 3928 ** CAPI3REF: Dynamically Typed Value Object |
| 3929 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} |
| 3930 ** |
| 3931 ** SQLite uses the sqlite3_value object to represent all values |
| 3932 ** that can be stored in a database table. SQLite uses dynamic typing |
| 3933 ** for the values it stores. ^Values stored in sqlite3_value objects |
| 3934 ** can be integers, floating point values, strings, BLOBs, or NULL. |
| 3935 ** |
| 3936 ** An sqlite3_value object may be either "protected" or "unprotected". |
| 3937 ** Some interfaces require a protected sqlite3_value. Other interfaces |
| 3938 ** will accept either a protected or an unprotected sqlite3_value. |
| 3939 ** Every interface that accepts sqlite3_value arguments specifies |
| 3940 ** whether or not it requires a protected sqlite3_value. The |
| 3941 ** [sqlite3_value_dup()] interface can be used to construct a new |
| 3942 ** protected sqlite3_value from an unprotected sqlite3_value. |
| 3943 ** |
| 3944 ** The terms "protected" and "unprotected" refer to whether or not |
| 3945 ** a mutex is held. An internal mutex is held for a protected |
| 3946 ** sqlite3_value object but no mutex is held for an unprotected |
| 3947 ** sqlite3_value object. If SQLite is compiled to be single-threaded |
| 3948 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) |
| 3949 ** or if SQLite is run in one of reduced mutex modes |
| 3950 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] |
| 3951 ** then there is no distinction between protected and unprotected |
| 3952 ** sqlite3_value objects and they can be used interchangeably. However, |
| 3953 ** for maximum code portability it is recommended that applications |
| 3954 ** still make the distinction between protected and unprotected |
| 3955 ** sqlite3_value objects even when not strictly required. |
| 3956 ** |
| 3957 ** ^The sqlite3_value objects that are passed as parameters into the |
| 3958 ** implementation of [application-defined SQL functions] are protected. |
| 3959 ** ^The sqlite3_value object returned by |
| 3960 ** [sqlite3_column_value()] is unprotected. |
| 3961 ** Unprotected sqlite3_value objects may only be used with |
| 3962 ** [sqlite3_result_value()] and [sqlite3_bind_value()]. |
| 3963 ** The [sqlite3_value_blob | sqlite3_value_type()] family of |
| 3964 ** interfaces require protected sqlite3_value objects. |
| 3965 */ |
| 3966 typedef struct Mem sqlite3_value; |
| 3967 |
| 3968 /* |
| 3969 ** CAPI3REF: SQL Function Context Object |
| 3970 ** |
| 3971 ** The context in which an SQL function executes is stored in an |
| 3972 ** sqlite3_context object. ^A pointer to an sqlite3_context object |
| 3973 ** is always first parameter to [application-defined SQL functions]. |
| 3974 ** The application-defined SQL function implementation will pass this |
| 3975 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], |
| 3976 ** [sqlite3_aggregate_context()], [sqlite3_user_data()], |
| 3977 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], |
| 3978 ** and/or [sqlite3_set_auxdata()]. |
| 3979 */ |
| 3980 typedef struct sqlite3_context sqlite3_context; |
| 3981 |
| 3982 /* |
| 3983 ** CAPI3REF: Binding Values To Prepared Statements |
| 3984 ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 3985 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 3986 ** METHOD: sqlite3_stmt |
| 3987 ** |
| 3988 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 3989 ** literals may be replaced by a [parameter] that matches one of following |
| 3990 ** templates: |
| 3991 ** |
| 3992 ** <ul> |
| 3993 ** <li> ? |
| 3994 ** <li> ?NNN |
| 3995 ** <li> :VVV |
| 3996 ** <li> @VVV |
| 3997 ** <li> $VVV |
| 3998 ** </ul> |
| 3999 ** |
| 4000 ** In the templates above, NNN represents an integer literal, |
| 4001 ** and VVV represents an alphanumeric identifier.)^ ^The values of these |
| 4002 ** parameters (also called "host parameter names" or "SQL parameters") |
| 4003 ** can be set using the sqlite3_bind_*() routines defined here. |
| 4004 ** |
| 4005 ** ^The first argument to the sqlite3_bind_*() routines is always |
| 4006 ** a pointer to the [sqlite3_stmt] object returned from |
| 4007 ** [sqlite3_prepare_v2()] or its variants. |
| 4008 ** |
| 4009 ** ^The second argument is the index of the SQL parameter to be set. |
| 4010 ** ^The leftmost SQL parameter has an index of 1. ^When the same named |
| 4011 ** SQL parameter is used more than once, second and subsequent |
| 4012 ** occurrences have the same index as the first occurrence. |
| 4013 ** ^The index for named parameters can be looked up using the |
| 4014 ** [sqlite3_bind_parameter_index()] API if desired. ^The index |
| 4015 ** for "?NNN" parameters is the value of NNN. |
| 4016 ** ^The NNN value must be between 1 and the [sqlite3_limit()] |
| 4017 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). |
| 4018 ** |
| 4019 ** ^The third argument is the value to bind to the parameter. |
| 4020 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 4021 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter |
| 4022 ** is ignored and the end result is the same as sqlite3_bind_null(). |
| 4023 ** |
| 4024 ** ^(In those routines that have a fourth argument, its value is the |
| 4025 ** number of bytes in the parameter. To be clear: the value is the |
| 4026 ** number of <u>bytes</u> in the value, not the number of characters.)^ |
| 4027 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 4028 ** is negative, then the length of the string is |
| 4029 ** the number of bytes up to the first zero terminator. |
| 4030 ** If the fourth parameter to sqlite3_bind_blob() is negative, then |
| 4031 ** the behavior is undefined. |
| 4032 ** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
| 4033 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then |
| 4034 ** that parameter must be the byte offset |
| 4035 ** where the NUL terminator would occur assuming the string were NUL |
| 4036 ** terminated. If any NUL characters occur at byte offsets less than |
| 4037 ** the value of the fourth parameter then the resulting string value will |
| 4038 ** contain embedded NULs. The result of expressions involving strings |
| 4039 ** with embedded NULs is undefined. |
| 4040 ** |
| 4041 ** ^The fifth argument to the BLOB and string binding interfaces |
| 4042 ** is a destructor used to dispose of the BLOB or |
| 4043 ** string after SQLite has finished with it. ^The destructor is called |
| 4044 ** to dispose of the BLOB or string even if the call to bind API fails. |
| 4045 ** ^If the fifth argument is |
| 4046 ** the special value [SQLITE_STATIC], then SQLite assumes that the |
| 4047 ** information is in static, unmanaged space and does not need to be freed. |
| 4048 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then |
| 4049 ** SQLite makes its own private copy of the data immediately, before |
| 4050 ** the sqlite3_bind_*() routine returns. |
| 4051 ** |
| 4052 ** ^The sixth argument to sqlite3_bind_text64() must be one of |
| 4053 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE] |
| 4054 ** to specify the encoding of the text in the third parameter. If |
| 4055 ** the sixth argument to sqlite3_bind_text64() is not one of the |
| 4056 ** allowed values shown above, or if the text encoding is different |
| 4057 ** from the encoding specified by the sixth parameter, then the behavior |
| 4058 ** is undefined. |
| 4059 ** |
| 4060 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that |
| 4061 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory |
| 4062 ** (just an integer to hold its size) while it is being processed. |
| 4063 ** Zeroblobs are intended to serve as placeholders for BLOBs whose |
| 4064 ** content is later written using |
| 4065 ** [sqlite3_blob_open | incremental BLOB I/O] routines. |
| 4066 ** ^A negative value for the zeroblob results in a zero-length BLOB. |
| 4067 ** |
| 4068 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer |
| 4069 ** for the [prepared statement] or with a prepared statement for which |
| 4070 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], |
| 4071 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() |
| 4072 ** routine is passed a [prepared statement] that has been finalized, the |
| 4073 ** result is undefined and probably harmful. |
| 4074 ** |
| 4075 ** ^Bindings are not cleared by the [sqlite3_reset()] routine. |
| 4076 ** ^Unbound parameters are interpreted as NULL. |
| 4077 ** |
| 4078 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an |
| 4079 ** [error code] if anything goes wrong. |
| 4080 ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB |
| 4081 ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or |
| 4082 ** [SQLITE_MAX_LENGTH]. |
| 4083 ** ^[SQLITE_RANGE] is returned if the parameter |
| 4084 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. |
| 4085 ** |
| 4086 ** See also: [sqlite3_bind_parameter_count()], |
| 4087 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. |
| 4088 */ |
| 4089 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)
(void*)); |
| 4090 SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint
64, |
| 4091 void(*)(void*)); |
| 4092 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); |
| 4093 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); |
| 4094 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); |
| 4095 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); |
| 4096 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*
)); |
| 4097 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)
(void*)); |
| 4098 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint
64, |
| 4099 void(*)(void*), unsigned char encoding); |
| 4100 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); |
| 4101 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); |
| 4102 SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64); |
| 4103 |
| 4104 /* |
| 4105 ** CAPI3REF: Number Of SQL Parameters |
| 4106 ** METHOD: sqlite3_stmt |
| 4107 ** |
| 4108 ** ^This routine can be used to find the number of [SQL parameters] |
| 4109 ** in a [prepared statement]. SQL parameters are tokens of the |
| 4110 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as |
| 4111 ** placeholders for values that are [sqlite3_bind_blob | bound] |
| 4112 ** to the parameters at a later time. |
| 4113 ** |
| 4114 ** ^(This routine actually returns the index of the largest (rightmost) |
| 4115 ** parameter. For all forms except ?NNN, this will correspond to the |
| 4116 ** number of unique parameters. If parameters of the ?NNN form are used, |
| 4117 ** there may be gaps in the list.)^ |
| 4118 ** |
| 4119 ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 4120 ** [sqlite3_bind_parameter_name()], and |
| 4121 ** [sqlite3_bind_parameter_index()]. |
| 4122 */ |
| 4123 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); |
| 4124 |
| 4125 /* |
| 4126 ** CAPI3REF: Name Of A Host Parameter |
| 4127 ** METHOD: sqlite3_stmt |
| 4128 ** |
| 4129 ** ^The sqlite3_bind_parameter_name(P,N) interface returns |
| 4130 ** the name of the N-th [SQL parameter] in the [prepared statement] P. |
| 4131 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 4132 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" |
| 4133 ** respectively. |
| 4134 ** In other words, the initial ":" or "$" or "@" or "?" |
| 4135 ** is included as part of the name.)^ |
| 4136 ** ^Parameters of the form "?" without a following integer have no name |
| 4137 ** and are referred to as "nameless" or "anonymous parameters". |
| 4138 ** |
| 4139 ** ^The first host parameter has an index of 1, not 0. |
| 4140 ** |
| 4141 ** ^If the value N is out of range or if the N-th parameter is |
| 4142 ** nameless, then NULL is returned. ^The returned string is |
| 4143 ** always in UTF-8 encoding even if the named parameter was |
| 4144 ** originally specified as UTF-16 in [sqlite3_prepare16()] or |
| 4145 ** [sqlite3_prepare16_v2()]. |
| 4146 ** |
| 4147 ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 4148 ** [sqlite3_bind_parameter_count()], and |
| 4149 ** [sqlite3_bind_parameter_index()]. |
| 4150 */ |
| 4151 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); |
| 4152 |
| 4153 /* |
| 4154 ** CAPI3REF: Index Of A Parameter With A Given Name |
| 4155 ** METHOD: sqlite3_stmt |
| 4156 ** |
| 4157 ** ^Return the index of an SQL parameter given its name. ^The |
| 4158 ** index value returned is suitable for use as the second |
| 4159 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero |
| 4160 ** is returned if no matching parameter is found. ^The parameter |
| 4161 ** name must be given in UTF-8 even if the original statement |
| 4162 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. |
| 4163 ** |
| 4164 ** See also: [sqlite3_bind_blob|sqlite3_bind()], |
| 4165 ** [sqlite3_bind_parameter_count()], and |
| 4166 ** [sqlite3_bind_parameter_name()]. |
| 4167 */ |
| 4168 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); |
| 4169 |
| 4170 /* |
| 4171 ** CAPI3REF: Reset All Bindings On A Prepared Statement |
| 4172 ** METHOD: sqlite3_stmt |
| 4173 ** |
| 4174 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset |
| 4175 ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. |
| 4176 ** ^Use this routine to reset all host parameters to NULL. |
| 4177 */ |
| 4178 SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); |
| 4179 |
| 4180 /* |
| 4181 ** CAPI3REF: Number Of Columns In A Result Set |
| 4182 ** METHOD: sqlite3_stmt |
| 4183 ** |
| 4184 ** ^Return the number of columns in the result set returned by the |
| 4185 ** [prepared statement]. ^If this routine returns 0, that means the |
| 4186 ** [prepared statement] returns no data (for example an [UPDATE]). |
| 4187 ** ^However, just because this routine returns a positive number does not |
| 4188 ** mean that one or more rows of data will be returned. ^A SELECT statement |
| 4189 ** will always have a positive sqlite3_column_count() but depending on the |
| 4190 ** WHERE clause constraints and the table content, it might return no rows. |
| 4191 ** |
| 4192 ** See also: [sqlite3_data_count()] |
| 4193 */ |
| 4194 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); |
| 4195 |
| 4196 /* |
| 4197 ** CAPI3REF: Column Names In A Result Set |
| 4198 ** METHOD: sqlite3_stmt |
| 4199 ** |
| 4200 ** ^These routines return the name assigned to a particular column |
| 4201 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() |
| 4202 ** interface returns a pointer to a zero-terminated UTF-8 string |
| 4203 ** and sqlite3_column_name16() returns a pointer to a zero-terminated |
| 4204 ** UTF-16 string. ^The first parameter is the [prepared statement] |
| 4205 ** that implements the [SELECT] statement. ^The second parameter is the |
| 4206 ** column number. ^The leftmost column is number 0. |
| 4207 ** |
| 4208 ** ^The returned string pointer is valid until either the [prepared statement] |
| 4209 ** is destroyed by [sqlite3_finalize()] or until the statement is automatically |
| 4210 ** reprepared by the first call to [sqlite3_step()] for a particular run |
| 4211 ** or until the next call to |
| 4212 ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
| 4213 ** |
| 4214 ** ^If sqlite3_malloc() fails during the processing of either routine |
| 4215 ** (for example during a conversion from UTF-8 to UTF-16) then a |
| 4216 ** NULL pointer is returned. |
| 4217 ** |
| 4218 ** ^The name of a result column is the value of the "AS" clause for |
| 4219 ** that column, if there is an AS clause. If there is no AS clause |
| 4220 ** then the name of the column is unspecified and may change from |
| 4221 ** one release of SQLite to the next. |
| 4222 */ |
| 4223 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); |
| 4224 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); |
| 4225 |
| 4226 /* |
| 4227 ** CAPI3REF: Source Of Data In A Query Result |
| 4228 ** METHOD: sqlite3_stmt |
| 4229 ** |
| 4230 ** ^These routines provide a means to determine the database, table, and |
| 4231 ** table column that is the origin of a particular result column in |
| 4232 ** [SELECT] statement. |
| 4233 ** ^The name of the database or table or column can be returned as |
| 4234 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 4235 ** the database name, the _table_ routines return the table name, and |
| 4236 ** the origin_ routines return the column name. |
| 4237 ** ^The returned string is valid until the [prepared statement] is destroyed |
| 4238 ** using [sqlite3_finalize()] or until the statement is automatically |
| 4239 ** reprepared by the first call to [sqlite3_step()] for a particular run |
| 4240 ** or until the same information is requested |
| 4241 ** again in a different encoding. |
| 4242 ** |
| 4243 ** ^The names returned are the original un-aliased names of the |
| 4244 ** database, table, and column. |
| 4245 ** |
| 4246 ** ^The first argument to these interfaces is a [prepared statement]. |
| 4247 ** ^These functions return information about the Nth result column returned by |
| 4248 ** the statement, where N is the second function argument. |
| 4249 ** ^The left-most column is column 0 for these routines. |
| 4250 ** |
| 4251 ** ^If the Nth column returned by the statement is an expression or |
| 4252 ** subquery and is not a column value, then all of these functions return |
| 4253 ** NULL. ^These routine might also return NULL if a memory allocation error |
| 4254 ** occurs. ^Otherwise, they return the name of the attached database, table, |
| 4255 ** or column that query result column was extracted from. |
| 4256 ** |
| 4257 ** ^As with all other SQLite APIs, those whose names end with "16" return |
| 4258 ** UTF-16 encoded strings and the other functions return UTF-8. |
| 4259 ** |
| 4260 ** ^These APIs are only available if the library was compiled with the |
| 4261 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. |
| 4262 ** |
| 4263 ** If two or more threads call one or more of these routines against the same |
| 4264 ** prepared statement and column at the same time then the results are |
| 4265 ** undefined. |
| 4266 ** |
| 4267 ** If two or more threads call one or more |
| 4268 ** [sqlite3_column_database_name | column metadata interfaces] |
| 4269 ** for the same [prepared statement] and result column |
| 4270 ** at the same time then the results are undefined. |
| 4271 */ |
| 4272 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); |
| 4273 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); |
| 4274 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); |
| 4275 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); |
| 4276 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); |
| 4277 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); |
| 4278 |
| 4279 /* |
| 4280 ** CAPI3REF: Declared Datatype Of A Query Result |
| 4281 ** METHOD: sqlite3_stmt |
| 4282 ** |
| 4283 ** ^(The first parameter is a [prepared statement]. |
| 4284 ** If this statement is a [SELECT] statement and the Nth column of the |
| 4285 ** returned result set of that [SELECT] is a table column (not an |
| 4286 ** expression or subquery) then the declared type of the table |
| 4287 ** column is returned.)^ ^If the Nth column of the result set is an |
| 4288 ** expression or subquery, then a NULL pointer is returned. |
| 4289 ** ^The returned string is always UTF-8 encoded. |
| 4290 ** |
| 4291 ** ^(For example, given the database schema: |
| 4292 ** |
| 4293 ** CREATE TABLE t1(c1 VARIANT); |
| 4294 ** |
| 4295 ** and the following statement to be compiled: |
| 4296 ** |
| 4297 ** SELECT c1 + 1, c1 FROM t1; |
| 4298 ** |
| 4299 ** this routine would return the string "VARIANT" for the second result |
| 4300 ** column (i==1), and a NULL pointer for the first result column (i==0).)^ |
| 4301 ** |
| 4302 ** ^SQLite uses dynamic run-time typing. ^So just because a column |
| 4303 ** is declared to contain a particular type does not mean that the |
| 4304 ** data stored in that column is of the declared type. SQLite is |
| 4305 ** strongly typed, but the typing is dynamic not static. ^Type |
| 4306 ** is associated with individual values, not with the containers |
| 4307 ** used to hold those values. |
| 4308 */ |
| 4309 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); |
| 4310 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); |
| 4311 |
| 4312 /* |
| 4313 ** CAPI3REF: Evaluate An SQL Statement |
| 4314 ** METHOD: sqlite3_stmt |
| 4315 ** |
| 4316 ** After a [prepared statement] has been prepared using either |
| 4317 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy |
| 4318 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function |
| 4319 ** must be called one or more times to evaluate the statement. |
| 4320 ** |
| 4321 ** The details of the behavior of the sqlite3_step() interface depend |
| 4322 ** on whether the statement was prepared using the newer "v2" interface |
| 4323 ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy |
| 4324 ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the |
| 4325 ** new "v2" interface is recommended for new applications but the legacy |
| 4326 ** interface will continue to be supported. |
| 4327 ** |
| 4328 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], |
| 4329 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. |
| 4330 ** ^With the "v2" interface, any of the other [result codes] or |
| 4331 ** [extended result codes] might be returned as well. |
| 4332 ** |
| 4333 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the |
| 4334 ** database locks it needs to do its job. ^If the statement is a [COMMIT] |
| 4335 ** or occurs outside of an explicit transaction, then you can retry the |
| 4336 ** statement. If the statement is not a [COMMIT] and occurs within an |
| 4337 ** explicit transaction then you should rollback the transaction before |
| 4338 ** continuing. |
| 4339 ** |
| 4340 ** ^[SQLITE_DONE] means that the statement has finished executing |
| 4341 ** successfully. sqlite3_step() should not be called again on this virtual |
| 4342 ** machine without first calling [sqlite3_reset()] to reset the virtual |
| 4343 ** machine back to its initial state. |
| 4344 ** |
| 4345 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] |
| 4346 ** is returned each time a new row of data is ready for processing by the |
| 4347 ** caller. The values may be accessed using the [column access functions]. |
| 4348 ** sqlite3_step() is called again to retrieve the next row of data. |
| 4349 ** |
| 4350 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint |
| 4351 ** violation) has occurred. sqlite3_step() should not be called again on |
| 4352 ** the VM. More information may be found by calling [sqlite3_errmsg()]. |
| 4353 ** ^With the legacy interface, a more specific error code (for example, |
| 4354 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) |
| 4355 ** can be obtained by calling [sqlite3_reset()] on the |
| 4356 ** [prepared statement]. ^In the "v2" interface, |
| 4357 ** the more specific error code is returned directly by sqlite3_step(). |
| 4358 ** |
| 4359 ** [SQLITE_MISUSE] means that the this routine was called inappropriately. |
| 4360 ** Perhaps it was called on a [prepared statement] that has |
| 4361 ** already been [sqlite3_finalize | finalized] or on one that had |
| 4362 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could |
| 4363 ** be the case that the same database connection is being used by two or |
| 4364 ** more threads at the same moment in time. |
| 4365 ** |
| 4366 ** For all versions of SQLite up to and including 3.6.23.1, a call to |
| 4367 ** [sqlite3_reset()] was required after sqlite3_step() returned anything |
| 4368 ** other than [SQLITE_ROW] before any subsequent invocation of |
| 4369 ** sqlite3_step(). Failure to reset the prepared statement using |
| 4370 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from |
| 4371 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1], |
| 4372 ** sqlite3_step() began |
| 4373 ** calling [sqlite3_reset()] automatically in this circumstance rather |
| 4374 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility |
| 4375 ** break because any application that ever receives an SQLITE_MISUSE error |
| 4376 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option |
| 4377 ** can be used to restore the legacy behavior. |
| 4378 ** |
| 4379 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() |
| 4380 ** API always returns a generic error code, [SQLITE_ERROR], following any |
| 4381 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call |
| 4382 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the |
| 4383 ** specific [error codes] that better describes the error. |
| 4384 ** We admit that this is a goofy design. The problem has been fixed |
| 4385 ** with the "v2" interface. If you prepare all of your SQL statements |
| 4386 ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead |
| 4387 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, |
| 4388 ** then the more specific [error codes] are returned directly |
| 4389 ** by sqlite3_step(). The use of the "v2" interface is recommended. |
| 4390 */ |
| 4391 SQLITE_API int sqlite3_step(sqlite3_stmt*); |
| 4392 |
| 4393 /* |
| 4394 ** CAPI3REF: Number of columns in a result set |
| 4395 ** METHOD: sqlite3_stmt |
| 4396 ** |
| 4397 ** ^The sqlite3_data_count(P) interface returns the number of columns in the |
| 4398 ** current row of the result set of [prepared statement] P. |
| 4399 ** ^If prepared statement P does not have results ready to return |
| 4400 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of |
| 4401 ** interfaces) then sqlite3_data_count(P) returns 0. |
| 4402 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. |
| 4403 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to |
| 4404 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P) |
| 4405 ** will return non-zero if previous call to [sqlite3_step](P) returned |
| 4406 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum] |
| 4407 ** where it always returns zero since each step of that multi-step |
| 4408 ** pragma returns 0 columns of data. |
| 4409 ** |
| 4410 ** See also: [sqlite3_column_count()] |
| 4411 */ |
| 4412 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); |
| 4413 |
| 4414 /* |
| 4415 ** CAPI3REF: Fundamental Datatypes |
| 4416 ** KEYWORDS: SQLITE_TEXT |
| 4417 ** |
| 4418 ** ^(Every value in SQLite has one of five fundamental datatypes: |
| 4419 ** |
| 4420 ** <ul> |
| 4421 ** <li> 64-bit signed integer |
| 4422 ** <li> 64-bit IEEE floating point number |
| 4423 ** <li> string |
| 4424 ** <li> BLOB |
| 4425 ** <li> NULL |
| 4426 ** </ul>)^ |
| 4427 ** |
| 4428 ** These constants are codes for each of those types. |
| 4429 ** |
| 4430 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 |
| 4431 ** for a completely different meaning. Software that links against both |
| 4432 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not |
| 4433 ** SQLITE_TEXT. |
| 4434 */ |
| 4435 #define SQLITE_INTEGER 1 |
| 4436 #define SQLITE_FLOAT 2 |
| 4437 #define SQLITE_BLOB 4 |
| 4438 #define SQLITE_NULL 5 |
| 4439 #ifdef SQLITE_TEXT |
| 4440 # undef SQLITE_TEXT |
| 4441 #else |
| 4442 # define SQLITE_TEXT 3 |
| 4443 #endif |
| 4444 #define SQLITE3_TEXT 3 |
| 4445 |
| 4446 /* |
| 4447 ** CAPI3REF: Result Values From A Query |
| 4448 ** KEYWORDS: {column access functions} |
| 4449 ** METHOD: sqlite3_stmt |
| 4450 ** |
| 4451 ** ^These routines return information about a single column of the current |
| 4452 ** result row of a query. ^In every case the first argument is a pointer |
| 4453 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] |
| 4454 ** that was returned from [sqlite3_prepare_v2()] or one of its variants) |
| 4455 ** and the second argument is the index of the column for which information |
| 4456 ** should be returned. ^The leftmost column of the result set has the index 0. |
| 4457 ** ^The number of columns in the result can be determined using |
| 4458 ** [sqlite3_column_count()]. |
| 4459 ** |
| 4460 ** If the SQL statement does not currently point to a valid row, or if the |
| 4461 ** column index is out of range, the result is undefined. |
| 4462 ** These routines may only be called when the most recent call to |
| 4463 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither |
| 4464 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. |
| 4465 ** If any of these routines are called after [sqlite3_reset()] or |
| 4466 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned |
| 4467 ** something other than [SQLITE_ROW], the results are undefined. |
| 4468 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] |
| 4469 ** are called from a different thread while any of these routines |
| 4470 ** are pending, then the results are undefined. |
| 4471 ** |
| 4472 ** ^The sqlite3_column_type() routine returns the |
| 4473 ** [SQLITE_INTEGER | datatype code] for the initial data type |
| 4474 ** of the result column. ^The returned value is one of [SQLITE_INTEGER], |
| 4475 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value |
| 4476 ** returned by sqlite3_column_type() is only meaningful if no type |
| 4477 ** conversions have occurred as described below. After a type conversion, |
| 4478 ** the value returned by sqlite3_column_type() is undefined. Future |
| 4479 ** versions of SQLite may change the behavior of sqlite3_column_type() |
| 4480 ** following a type conversion. |
| 4481 ** |
| 4482 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() |
| 4483 ** routine returns the number of bytes in that BLOB or string. |
| 4484 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts |
| 4485 ** the string to UTF-8 and then returns the number of bytes. |
| 4486 ** ^If the result is a numeric value then sqlite3_column_bytes() uses |
| 4487 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns |
| 4488 ** the number of bytes in that string. |
| 4489 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero. |
| 4490 ** |
| 4491 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() |
| 4492 ** routine returns the number of bytes in that BLOB or string. |
| 4493 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts |
| 4494 ** the string to UTF-16 and then returns the number of bytes. |
| 4495 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses |
| 4496 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns |
| 4497 ** the number of bytes in that string. |
| 4498 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. |
| 4499 ** |
| 4500 ** ^The values returned by [sqlite3_column_bytes()] and |
| 4501 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end |
| 4502 ** of the string. ^For clarity: the values returned by |
| 4503 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of |
| 4504 ** bytes in the string, not the number of characters. |
| 4505 ** |
| 4506 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), |
| 4507 ** even empty strings, are always zero-terminated. ^The return |
| 4508 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. |
| 4509 ** |
| 4510 ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an |
| 4511 ** [unprotected sqlite3_value] object. In a multithreaded environment, |
| 4512 ** an unprotected sqlite3_value object may only be used safely with |
| 4513 ** [sqlite3_bind_value()] and [sqlite3_result_value()]. |
| 4514 ** If the [unprotected sqlite3_value] object returned by |
| 4515 ** [sqlite3_column_value()] is used in any other way, including calls |
| 4516 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], |
| 4517 ** or [sqlite3_value_bytes()], the behavior is not threadsafe. |
| 4518 ** |
| 4519 ** These routines attempt to convert the value where appropriate. ^For |
| 4520 ** example, if the internal representation is FLOAT and a text result |
| 4521 ** is requested, [sqlite3_snprintf()] is used internally to perform the |
| 4522 ** conversion automatically. ^(The following table details the conversions |
| 4523 ** that are applied: |
| 4524 ** |
| 4525 ** <blockquote> |
| 4526 ** <table border="1"> |
| 4527 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion |
| 4528 ** |
| 4529 ** <tr><td> NULL <td> INTEGER <td> Result is 0 |
| 4530 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 |
| 4531 ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer |
| 4532 ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer |
| 4533 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float |
| 4534 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer |
| 4535 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT |
| 4536 ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER |
| 4537 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float |
| 4538 ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB |
| 4539 ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER |
| 4540 ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL |
| 4541 ** <tr><td> TEXT <td> BLOB <td> No change |
| 4542 ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER |
| 4543 ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL |
| 4544 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed |
| 4545 ** </table> |
| 4546 ** </blockquote>)^ |
| 4547 ** |
| 4548 ** Note that when type conversions occur, pointers returned by prior |
| 4549 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or |
| 4550 ** sqlite3_column_text16() may be invalidated. |
| 4551 ** Type conversions and pointer invalidations might occur |
| 4552 ** in the following cases: |
| 4553 ** |
| 4554 ** <ul> |
| 4555 ** <li> The initial content is a BLOB and sqlite3_column_text() or |
| 4556 ** sqlite3_column_text16() is called. A zero-terminator might |
| 4557 ** need to be added to the string.</li> |
| 4558 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or |
| 4559 ** sqlite3_column_text16() is called. The content must be converted |
| 4560 ** to UTF-16.</li> |
| 4561 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or |
| 4562 ** sqlite3_column_text() is called. The content must be converted |
| 4563 ** to UTF-8.</li> |
| 4564 ** </ul> |
| 4565 ** |
| 4566 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do |
| 4567 ** not invalidate a prior pointer, though of course the content of the buffer |
| 4568 ** that the prior pointer references will have been modified. Other kinds |
| 4569 ** of conversion are done in place when it is possible, but sometimes they |
| 4570 ** are not possible and in those cases prior pointers are invalidated. |
| 4571 ** |
| 4572 ** The safest policy is to invoke these routines |
| 4573 ** in one of the following ways: |
| 4574 ** |
| 4575 ** <ul> |
| 4576 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> |
| 4577 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> |
| 4578 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> |
| 4579 ** </ul> |
| 4580 ** |
| 4581 ** In other words, you should call sqlite3_column_text(), |
| 4582 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result |
| 4583 ** into the desired format, then invoke sqlite3_column_bytes() or |
| 4584 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls |
| 4585 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to |
| 4586 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() |
| 4587 ** with calls to sqlite3_column_bytes(). |
| 4588 ** |
| 4589 ** ^The pointers returned are valid until a type conversion occurs as |
| 4590 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or |
| 4591 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings |
| 4592 ** and BLOBs is freed automatically. Do <em>not</em> pass the pointers returned |
| 4593 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into |
| 4594 ** [sqlite3_free()]. |
| 4595 ** |
| 4596 ** ^(If a memory allocation error occurs during the evaluation of any |
| 4597 ** of these routines, a default value is returned. The default value |
| 4598 ** is either the integer 0, the floating point number 0.0, or a NULL |
| 4599 ** pointer. Subsequent calls to [sqlite3_errcode()] will return |
| 4600 ** [SQLITE_NOMEM].)^ |
| 4601 */ |
| 4602 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); |
| 4603 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); |
| 4604 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); |
| 4605 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); |
| 4606 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); |
| 4607 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); |
| 4608 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); |
| 4609 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); |
| 4610 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); |
| 4611 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); |
| 4612 |
| 4613 /* |
| 4614 ** CAPI3REF: Destroy A Prepared Statement Object |
| 4615 ** DESTRUCTOR: sqlite3_stmt |
| 4616 ** |
| 4617 ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. |
| 4618 ** ^If the most recent evaluation of the statement encountered no errors |
| 4619 ** or if the statement is never been evaluated, then sqlite3_finalize() returns |
| 4620 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then |
| 4621 ** sqlite3_finalize(S) returns the appropriate [error code] or |
| 4622 ** [extended error code]. |
| 4623 ** |
| 4624 ** ^The sqlite3_finalize(S) routine can be called at any point during |
| 4625 ** the life cycle of [prepared statement] S: |
| 4626 ** before statement S is ever evaluated, after |
| 4627 ** one or more calls to [sqlite3_reset()], or after any call |
| 4628 ** to [sqlite3_step()] regardless of whether or not the statement has |
| 4629 ** completed execution. |
| 4630 ** |
| 4631 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. |
| 4632 ** |
| 4633 ** The application must finalize every [prepared statement] in order to avoid |
| 4634 ** resource leaks. It is a grievous error for the application to try to use |
| 4635 ** a prepared statement after it has been finalized. Any use of a prepared |
| 4636 ** statement after it has been finalized can result in undefined and |
| 4637 ** undesirable behavior such as segfaults and heap corruption. |
| 4638 */ |
| 4639 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); |
| 4640 |
| 4641 /* |
| 4642 ** CAPI3REF: Reset A Prepared Statement Object |
| 4643 ** METHOD: sqlite3_stmt |
| 4644 ** |
| 4645 ** The sqlite3_reset() function is called to reset a [prepared statement] |
| 4646 ** object back to its initial state, ready to be re-executed. |
| 4647 ** ^Any SQL statement variables that had values bound to them using |
| 4648 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. |
| 4649 ** Use [sqlite3_clear_bindings()] to reset the bindings. |
| 4650 ** |
| 4651 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
| 4652 ** back to the beginning of its program. |
| 4653 ** |
| 4654 ** ^If the most recent call to [sqlite3_step(S)] for the |
| 4655 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], |
| 4656 ** or if [sqlite3_step(S)] has never before been called on S, |
| 4657 ** then [sqlite3_reset(S)] returns [SQLITE_OK]. |
| 4658 ** |
| 4659 ** ^If the most recent call to [sqlite3_step(S)] for the |
| 4660 ** [prepared statement] S indicated an error, then |
| 4661 ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 4662 ** |
| 4663 ** ^The [sqlite3_reset(S)] interface does not change the values |
| 4664 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 4665 */ |
| 4666 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| 4667 |
| 4668 /* |
| 4669 ** CAPI3REF: Create Or Redefine SQL Functions |
| 4670 ** KEYWORDS: {function creation routines} |
| 4671 ** KEYWORDS: {application-defined SQL function} |
| 4672 ** KEYWORDS: {application-defined SQL functions} |
| 4673 ** METHOD: sqlite3 |
| 4674 ** |
| 4675 ** ^These functions (collectively known as "function creation routines") |
| 4676 ** are used to add SQL functions or aggregates or to redefine the behavior |
| 4677 ** of existing SQL functions or aggregates. The only differences between |
| 4678 ** these routines are the text encoding expected for |
| 4679 ** the second parameter (the name of the function being created) |
| 4680 ** and the presence or absence of a destructor callback for |
| 4681 ** the application data pointer. |
| 4682 ** |
| 4683 ** ^The first parameter is the [database connection] to which the SQL |
| 4684 ** function is to be added. ^If an application uses more than one database |
| 4685 ** connection then application-defined SQL functions must be added |
| 4686 ** to each database connection separately. |
| 4687 ** |
| 4688 ** ^The second parameter is the name of the SQL function to be created or |
| 4689 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 |
| 4690 ** representation, exclusive of the zero-terminator. ^Note that the name |
| 4691 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. |
| 4692 ** ^Any attempt to create a function with a longer name |
| 4693 ** will result in [SQLITE_MISUSE] being returned. |
| 4694 ** |
| 4695 ** ^The third parameter (nArg) |
| 4696 ** is the number of arguments that the SQL function or |
| 4697 ** aggregate takes. ^If this parameter is -1, then the SQL function or |
| 4698 ** aggregate may take any number of arguments between 0 and the limit |
| 4699 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third |
| 4700 ** parameter is less than -1 or greater than 127 then the behavior is |
| 4701 ** undefined. |
| 4702 ** |
| 4703 ** ^The fourth parameter, eTextRep, specifies what |
| 4704 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 4705 ** its parameters. The application should set this parameter to |
| 4706 ** [SQLITE_UTF16LE] if the function implementation invokes |
| 4707 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the |
| 4708 ** implementation invokes [sqlite3_value_text16be()] on an input, or |
| 4709 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] |
| 4710 ** otherwise. ^The same SQL function may be registered multiple times using |
| 4711 ** different preferred text encodings, with different implementations for |
| 4712 ** each encoding. |
| 4713 ** ^When multiple implementations of the same function are available, SQLite |
| 4714 ** will pick the one that involves the least amount of data conversion. |
| 4715 ** |
| 4716 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] |
| 4717 ** to signal that the function will always return the same result given |
| 4718 ** the same inputs within a single SQL statement. Most SQL functions are |
| 4719 ** deterministic. The built-in [random()] SQL function is an example of a |
| 4720 ** function that is not deterministic. The SQLite query planner is able to |
| 4721 ** perform additional optimizations on deterministic functions, so use |
| 4722 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. |
| 4723 ** |
| 4724 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 4725 ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 4726 ** |
| 4727 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| 4728 ** pointers to C-language functions that implement the SQL function or |
| 4729 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc |
| 4730 ** callback only; NULL pointers must be passed as the xStep and xFinal |
| 4731 ** parameters. ^An aggregate SQL function requires an implementation of xStep |
| 4732 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing |
| 4733 ** SQL function or aggregate, pass NULL pointers for all three function |
| 4734 ** callbacks. |
| 4735 ** |
| 4736 ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL, |
| 4737 ** then it is destructor for the application data pointer. |
| 4738 ** The destructor is invoked when the function is deleted, either by being |
| 4739 ** overloaded or when the database connection closes.)^ |
| 4740 ** ^The destructor is also invoked if the call to |
| 4741 ** sqlite3_create_function_v2() fails. |
| 4742 ** ^When the destructor callback of the tenth parameter is invoked, it |
| 4743 ** is passed a single argument which is a copy of the application data |
| 4744 ** pointer which was the fifth parameter to sqlite3_create_function_v2(). |
| 4745 ** |
| 4746 ** ^It is permitted to register multiple implementations of the same |
| 4747 ** functions with the same name but with either differing numbers of |
| 4748 ** arguments or differing preferred text encodings. ^SQLite will use |
| 4749 ** the implementation that most closely matches the way in which the |
| 4750 ** SQL function is used. ^A function implementation with a non-negative |
| 4751 ** nArg parameter is a better match than a function implementation with |
| 4752 ** a negative nArg. ^A function where the preferred text encoding |
| 4753 ** matches the database encoding is a better |
| 4754 ** match than a function where the encoding is different. |
| 4755 ** ^A function where the encoding difference is between UTF16le and UTF16be |
| 4756 ** is a closer match than a function where the encoding difference is |
| 4757 ** between UTF8 and UTF16. |
| 4758 ** |
| 4759 ** ^Built-in functions may be overloaded by new application-defined functions. |
| 4760 ** |
| 4761 ** ^An application-defined function is permitted to call other |
| 4762 ** SQLite interfaces. However, such calls must not |
| 4763 ** close the database connection nor finalize or reset the prepared |
| 4764 ** statement in which the function is running. |
| 4765 */ |
| 4766 SQLITE_API int sqlite3_create_function( |
| 4767 sqlite3 *db, |
| 4768 const char *zFunctionName, |
| 4769 int nArg, |
| 4770 int eTextRep, |
| 4771 void *pApp, |
| 4772 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4773 void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 4774 void (*xFinal)(sqlite3_context*) |
| 4775 ); |
| 4776 SQLITE_API int sqlite3_create_function16( |
| 4777 sqlite3 *db, |
| 4778 const void *zFunctionName, |
| 4779 int nArg, |
| 4780 int eTextRep, |
| 4781 void *pApp, |
| 4782 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4783 void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 4784 void (*xFinal)(sqlite3_context*) |
| 4785 ); |
| 4786 SQLITE_API int sqlite3_create_function_v2( |
| 4787 sqlite3 *db, |
| 4788 const char *zFunctionName, |
| 4789 int nArg, |
| 4790 int eTextRep, |
| 4791 void *pApp, |
| 4792 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), |
| 4793 void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 4794 void (*xFinal)(sqlite3_context*), |
| 4795 void(*xDestroy)(void*) |
| 4796 ); |
| 4797 |
| 4798 /* |
| 4799 ** CAPI3REF: Text Encodings |
| 4800 ** |
| 4801 ** These constant define integer codes that represent the various |
| 4802 ** text encodings supported by SQLite. |
| 4803 */ |
| 4804 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */ |
| 4805 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */ |
| 4806 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */ |
| 4807 #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4808 #define SQLITE_ANY 5 /* Deprecated */ |
| 4809 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4810 |
| 4811 /* |
| 4812 ** CAPI3REF: Function Flags |
| 4813 ** |
| 4814 ** These constants may be ORed together with the |
| 4815 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
| 4816 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
| 4817 ** [sqlite3_create_function_v2()]. |
| 4818 */ |
| 4819 #define SQLITE_DETERMINISTIC 0x800 |
| 4820 |
| 4821 /* |
| 4822 ** CAPI3REF: Deprecated Functions |
| 4823 ** DEPRECATED |
| 4824 ** |
| 4825 ** These functions are [deprecated]. In order to maintain |
| 4826 ** backwards compatibility with older code, these functions continue |
| 4827 ** to be supported. However, new applications should avoid |
| 4828 ** the use of these functions. To encourage programmers to avoid |
| 4829 ** these functions, we will not explain what they do. |
| 4830 */ |
| 4831 #ifndef SQLITE_OMIT_DEPRECATED |
| 4832 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); |
| 4833 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); |
| 4834 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite
3_stmt*); |
| 4835 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); |
| 4836 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); |
| 4837 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6
4,int), |
| 4838 void*,sqlite3_int64); |
| 4839 #endif |
| 4840 |
| 4841 /* |
| 4842 ** CAPI3REF: Obtaining SQL Values |
| 4843 ** METHOD: sqlite3_value |
| 4844 ** |
| 4845 ** The C-language implementation of SQL functions and aggregates uses |
| 4846 ** this set of interface routines to access the parameter values on |
| 4847 ** the function or aggregate. |
| 4848 ** |
| 4849 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters |
| 4850 ** to [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4851 ** define callbacks that implement the SQL functions and aggregates. |
| 4852 ** The 3rd parameter to these callbacks is an array of pointers to |
| 4853 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for |
| 4854 ** each parameter to the SQL function. These routines are used to |
| 4855 ** extract values from the [sqlite3_value] objects. |
| 4856 ** |
| 4857 ** These routines work only with [protected sqlite3_value] objects. |
| 4858 ** Any attempt to use these routines on an [unprotected sqlite3_value] |
| 4859 ** object results in undefined behavior. |
| 4860 ** |
| 4861 ** ^These routines work just like the corresponding [column access functions] |
| 4862 ** except that these routines take a single [protected sqlite3_value] object |
| 4863 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. |
| 4864 ** |
| 4865 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string |
| 4866 ** in the native byte-order of the host machine. ^The |
| 4867 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces |
| 4868 ** extract UTF-16 strings as big-endian and little-endian respectively. |
| 4869 ** |
| 4870 ** ^(The sqlite3_value_numeric_type() interface attempts to apply |
| 4871 ** numeric affinity to the value. This means that an attempt is |
| 4872 ** made to convert the value to an integer or floating point. If |
| 4873 ** such a conversion is possible without loss of information (in other |
| 4874 ** words, if the value is a string that looks like a number) |
| 4875 ** then the conversion is performed. Otherwise no conversion occurs. |
| 4876 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ |
| 4877 ** |
| 4878 ** Please pay particular attention to the fact that the pointer returned |
| 4879 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or |
| 4880 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to |
| 4881 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], |
| 4882 ** or [sqlite3_value_text16()]. |
| 4883 ** |
| 4884 ** These routines must be called from the same thread as |
| 4885 ** the SQL function that supplied the [sqlite3_value*] parameters. |
| 4886 */ |
| 4887 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); |
| 4888 SQLITE_API int sqlite3_value_bytes(sqlite3_value*); |
| 4889 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); |
| 4890 SQLITE_API double sqlite3_value_double(sqlite3_value*); |
| 4891 SQLITE_API int sqlite3_value_int(sqlite3_value*); |
| 4892 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); |
| 4893 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); |
| 4894 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); |
| 4895 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); |
| 4896 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); |
| 4897 SQLITE_API int sqlite3_value_type(sqlite3_value*); |
| 4898 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); |
| 4899 |
| 4900 /* |
| 4901 ** CAPI3REF: Finding The Subtype Of SQL Values |
| 4902 ** METHOD: sqlite3_value |
| 4903 ** |
| 4904 ** The sqlite3_value_subtype(V) function returns the subtype for |
| 4905 ** an [application-defined SQL function] argument V. The subtype |
| 4906 ** information can be used to pass a limited amount of context from |
| 4907 ** one SQL function to another. Use the [sqlite3_result_subtype()] |
| 4908 ** routine to set the subtype for the return value of an SQL function. |
| 4909 ** |
| 4910 ** SQLite makes no use of subtype itself. It merely passes the subtype |
| 4911 ** from the result of one [application-defined SQL function] into the |
| 4912 ** input of another. |
| 4913 */ |
| 4914 SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*); |
| 4915 |
| 4916 /* |
| 4917 ** CAPI3REF: Copy And Free SQL Values |
| 4918 ** METHOD: sqlite3_value |
| 4919 ** |
| 4920 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value] |
| 4921 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned |
| 4922 ** is a [protected sqlite3_value] object even if the input is not. |
| 4923 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a |
| 4924 ** memory allocation fails. |
| 4925 ** |
| 4926 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object |
| 4927 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer |
| 4928 ** then sqlite3_value_free(V) is a harmless no-op. |
| 4929 */ |
| 4930 SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*); |
| 4931 SQLITE_API void sqlite3_value_free(sqlite3_value*); |
| 4932 |
| 4933 /* |
| 4934 ** CAPI3REF: Obtain Aggregate Function Context |
| 4935 ** METHOD: sqlite3_context |
| 4936 ** |
| 4937 ** Implementations of aggregate SQL functions use this |
| 4938 ** routine to allocate memory for storing their state. |
| 4939 ** |
| 4940 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called |
| 4941 ** for a particular aggregate function, SQLite |
| 4942 ** allocates N of memory, zeroes out that memory, and returns a pointer |
| 4943 ** to the new memory. ^On second and subsequent calls to |
| 4944 ** sqlite3_aggregate_context() for the same aggregate function instance, |
| 4945 ** the same buffer is returned. Sqlite3_aggregate_context() is normally |
| 4946 ** called once for each invocation of the xStep callback and then one |
| 4947 ** last time when the xFinal callback is invoked. ^(When no rows match |
| 4948 ** an aggregate query, the xStep() callback of the aggregate function |
| 4949 ** implementation is never called and xFinal() is called exactly once. |
| 4950 ** In those cases, sqlite3_aggregate_context() might be called for the |
| 4951 ** first time from within xFinal().)^ |
| 4952 ** |
| 4953 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer |
| 4954 ** when first called if N is less than or equal to zero or if a memory |
| 4955 ** allocate error occurs. |
| 4956 ** |
| 4957 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is |
| 4958 ** determined by the N parameter on first successful call. Changing the |
| 4959 ** value of N in subsequent call to sqlite3_aggregate_context() within |
| 4960 ** the same aggregate function instance will not resize the memory |
| 4961 ** allocation.)^ Within the xFinal callback, it is customary to set |
| 4962 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no |
| 4963 ** pointless memory allocations occur. |
| 4964 ** |
| 4965 ** ^SQLite automatically frees the memory allocated by |
| 4966 ** sqlite3_aggregate_context() when the aggregate query concludes. |
| 4967 ** |
| 4968 ** The first parameter must be a copy of the |
| 4969 ** [sqlite3_context | SQL function context] that is the first parameter |
| 4970 ** to the xStep or xFinal callback routine that implements the aggregate |
| 4971 ** function. |
| 4972 ** |
| 4973 ** This routine must be called from the same thread in which |
| 4974 ** the aggregate SQL function is running. |
| 4975 */ |
| 4976 SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); |
| 4977 |
| 4978 /* |
| 4979 ** CAPI3REF: User Data For Functions |
| 4980 ** METHOD: sqlite3_context |
| 4981 ** |
| 4982 ** ^The sqlite3_user_data() interface returns a copy of |
| 4983 ** the pointer that was the pUserData parameter (the 5th parameter) |
| 4984 ** of the [sqlite3_create_function()] |
| 4985 ** and [sqlite3_create_function16()] routines that originally |
| 4986 ** registered the application defined function. |
| 4987 ** |
| 4988 ** This routine must be called from the same thread in which |
| 4989 ** the application-defined function is running. |
| 4990 */ |
| 4991 SQLITE_API void *sqlite3_user_data(sqlite3_context*); |
| 4992 |
| 4993 /* |
| 4994 ** CAPI3REF: Database Connection For Functions |
| 4995 ** METHOD: sqlite3_context |
| 4996 ** |
| 4997 ** ^The sqlite3_context_db_handle() interface returns a copy of |
| 4998 ** the pointer to the [database connection] (the 1st parameter) |
| 4999 ** of the [sqlite3_create_function()] |
| 5000 ** and [sqlite3_create_function16()] routines that originally |
| 5001 ** registered the application defined function. |
| 5002 */ |
| 5003 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); |
| 5004 |
| 5005 /* |
| 5006 ** CAPI3REF: Function Auxiliary Data |
| 5007 ** METHOD: sqlite3_context |
| 5008 ** |
| 5009 ** These functions may be used by (non-aggregate) SQL functions to |
| 5010 ** associate metadata with argument values. If the same value is passed to |
| 5011 ** multiple invocations of the same SQL function during query execution, under |
| 5012 ** some circumstances the associated metadata may be preserved. An example |
| 5013 ** of where this might be useful is in a regular-expression matching |
| 5014 ** function. The compiled version of the regular expression can be stored as |
| 5015 ** metadata associated with the pattern string. |
| 5016 ** Then as long as the pattern string remains the same, |
| 5017 ** the compiled regular expression can be reused on multiple |
| 5018 ** invocations of the same function. |
| 5019 ** |
| 5020 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata |
| 5021 ** associated by the sqlite3_set_auxdata() function with the Nth argument |
| 5022 ** value to the application-defined function. ^If there is no metadata |
| 5023 ** associated with the function argument, this sqlite3_get_auxdata() interface |
| 5024 ** returns a NULL pointer. |
| 5025 ** |
| 5026 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th |
| 5027 ** argument of the application-defined function. ^Subsequent |
| 5028 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent |
| 5029 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or |
| 5030 ** NULL if the metadata has been discarded. |
| 5031 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL, |
| 5032 ** SQLite will invoke the destructor function X with parameter P exactly |
| 5033 ** once, when the metadata is discarded. |
| 5034 ** SQLite is free to discard the metadata at any time, including: <ul> |
| 5035 ** <li> ^(when the corresponding function parameter changes)^, or |
| 5036 ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the |
| 5037 ** SQL statement)^, or |
| 5038 ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same |
| 5039 ** parameter)^, or |
| 5040 ** <li> ^(during the original sqlite3_set_auxdata() call when a memory |
| 5041 ** allocation error occurs.)^ </ul> |
| 5042 ** |
| 5043 ** Note the last bullet in particular. The destructor X in |
| 5044 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the |
| 5045 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata() |
| 5046 ** should be called near the end of the function implementation and the |
| 5047 ** function implementation should not make any use of P after |
| 5048 ** sqlite3_set_auxdata() has been called. |
| 5049 ** |
| 5050 ** ^(In practice, metadata is preserved between function calls for |
| 5051 ** function parameters that are compile-time constants, including literal |
| 5052 ** values and [parameters] and expressions composed from the same.)^ |
| 5053 ** |
| 5054 ** These routines must be called from the same thread in which |
| 5055 ** the SQL function is running. |
| 5056 */ |
| 5057 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); |
| 5058 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(voi
d*)); |
| 5059 |
| 5060 |
| 5061 /* |
| 5062 ** CAPI3REF: Constants Defining Special Destructor Behavior |
| 5063 ** |
| 5064 ** These are special values for the destructor that is passed in as the |
| 5065 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor |
| 5066 ** argument is SQLITE_STATIC, it means that the content pointer is constant |
| 5067 ** and will never change. It does not need to be destroyed. ^The |
| 5068 ** SQLITE_TRANSIENT value means that the content will likely change in |
| 5069 ** the near future and that SQLite should make its own private copy of |
| 5070 ** the content before returning. |
| 5071 ** |
| 5072 ** The typedef is necessary to work around problems in certain |
| 5073 ** C++ compilers. |
| 5074 */ |
| 5075 typedef void (*sqlite3_destructor_type)(void*); |
| 5076 #define SQLITE_STATIC ((sqlite3_destructor_type)0) |
| 5077 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) |
| 5078 |
| 5079 /* |
| 5080 ** CAPI3REF: Setting The Result Of An SQL Function |
| 5081 ** METHOD: sqlite3_context |
| 5082 ** |
| 5083 ** These routines are used by the xFunc or xFinal callbacks that |
| 5084 ** implement SQL functions and aggregates. See |
| 5085 ** [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 5086 ** for additional information. |
| 5087 ** |
| 5088 ** These functions work very much like the [parameter binding] family of |
| 5089 ** functions used to bind values to host parameters in prepared statements. |
| 5090 ** Refer to the [SQL parameter] documentation for additional information. |
| 5091 ** |
| 5092 ** ^The sqlite3_result_blob() interface sets the result from |
| 5093 ** an application-defined function to be the BLOB whose content is pointed |
| 5094 ** to by the second parameter and which is N bytes long where N is the |
| 5095 ** third parameter. |
| 5096 ** |
| 5097 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N) |
| 5098 ** interfaces set the result of the application-defined function to be |
| 5099 ** a BLOB containing all zero bytes and N bytes in size. |
| 5100 ** |
| 5101 ** ^The sqlite3_result_double() interface sets the result from |
| 5102 ** an application-defined function to be a floating point value specified |
| 5103 ** by its 2nd argument. |
| 5104 ** |
| 5105 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions |
| 5106 ** cause the implemented SQL function to throw an exception. |
| 5107 ** ^SQLite uses the string pointed to by the |
| 5108 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() |
| 5109 ** as the text of an error message. ^SQLite interprets the error |
| 5110 ** message string from sqlite3_result_error() as UTF-8. ^SQLite |
| 5111 ** interprets the string from sqlite3_result_error16() as UTF-16 in native |
| 5112 ** byte order. ^If the third parameter to sqlite3_result_error() |
| 5113 ** or sqlite3_result_error16() is negative then SQLite takes as the error |
| 5114 ** message all text up through the first zero character. |
| 5115 ** ^If the third parameter to sqlite3_result_error() or |
| 5116 ** sqlite3_result_error16() is non-negative then SQLite takes that many |
| 5117 ** bytes (not characters) from the 2nd parameter as the error message. |
| 5118 ** ^The sqlite3_result_error() and sqlite3_result_error16() |
| 5119 ** routines make a private copy of the error message text before |
| 5120 ** they return. Hence, the calling function can deallocate or |
| 5121 ** modify the text after they return without harm. |
| 5122 ** ^The sqlite3_result_error_code() function changes the error code |
| 5123 ** returned by SQLite as a result of an error in a function. ^By default, |
| 5124 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() |
| 5125 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. |
| 5126 ** |
| 5127 ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an |
| 5128 ** error indicating that a string or BLOB is too long to represent. |
| 5129 ** |
| 5130 ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an |
| 5131 ** error indicating that a memory allocation failed. |
| 5132 ** |
| 5133 ** ^The sqlite3_result_int() interface sets the return value |
| 5134 ** of the application-defined function to be the 32-bit signed integer |
| 5135 ** value given in the 2nd argument. |
| 5136 ** ^The sqlite3_result_int64() interface sets the return value |
| 5137 ** of the application-defined function to be the 64-bit signed integer |
| 5138 ** value given in the 2nd argument. |
| 5139 ** |
| 5140 ** ^The sqlite3_result_null() interface sets the return value |
| 5141 ** of the application-defined function to be NULL. |
| 5142 ** |
| 5143 ** ^The sqlite3_result_text(), sqlite3_result_text16(), |
| 5144 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces |
| 5145 ** set the return value of the application-defined function to be |
| 5146 ** a text string which is represented as UTF-8, UTF-16 native byte order, |
| 5147 ** UTF-16 little endian, or UTF-16 big endian, respectively. |
| 5148 ** ^The sqlite3_result_text64() interface sets the return value of an |
| 5149 ** application-defined function to be a text string in an encoding |
| 5150 ** specified by the fifth (and last) parameter, which must be one |
| 5151 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]. |
| 5152 ** ^SQLite takes the text result from the application from |
| 5153 ** the 2nd parameter of the sqlite3_result_text* interfaces. |
| 5154 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
| 5155 ** is negative, then SQLite takes result text from the 2nd parameter |
| 5156 ** through the first zero character. |
| 5157 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
| 5158 ** is non-negative, then as many bytes (not characters) of the text |
| 5159 ** pointed to by the 2nd parameter are taken as the application-defined |
| 5160 ** function result. If the 3rd parameter is non-negative, then it |
| 5161 ** must be the byte offset into the string where the NUL terminator would |
| 5162 ** appear if the string where NUL terminated. If any NUL characters occur |
| 5163 ** in the string at a byte offset that is less than the value of the 3rd |
| 5164 ** parameter, then the resulting string will contain embedded NULs and the |
| 5165 ** result of expressions operating on strings with embedded NULs is undefined. |
| 5166 ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
| 5167 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that |
| 5168 ** function as the destructor on the text or BLOB result when it has |
| 5169 ** finished using that result. |
| 5170 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to |
| 5171 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite |
| 5172 ** assumes that the text or BLOB result is in constant space and does not |
| 5173 ** copy the content of the parameter nor call a destructor on the content |
| 5174 ** when it has finished using that result. |
| 5175 ** ^If the 4th parameter to the sqlite3_result_text* interfaces |
| 5176 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT |
| 5177 ** then SQLite makes a copy of the result into space obtained from |
| 5178 ** from [sqlite3_malloc()] before it returns. |
| 5179 ** |
| 5180 ** ^The sqlite3_result_value() interface sets the result of |
| 5181 ** the application-defined function to be a copy of the |
| 5182 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The |
| 5183 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] |
| 5184 ** so that the [sqlite3_value] specified in the parameter may change or |
| 5185 ** be deallocated after sqlite3_result_value() returns without harm. |
| 5186 ** ^A [protected sqlite3_value] object may always be used where an |
| 5187 ** [unprotected sqlite3_value] object is required, so either |
| 5188 ** kind of [sqlite3_value] object can be used with this interface. |
| 5189 ** |
| 5190 ** If these routines are called from within the different thread |
| 5191 ** than the one containing the application-defined function that received |
| 5192 ** the [sqlite3_context] pointer, the results are undefined. |
| 5193 */ |
| 5194 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(
void*)); |
| 5195 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, |
| 5196 sqlite3_uint64,void(*)(void*)); |
| 5197 SQLITE_API void sqlite3_result_double(sqlite3_context*, double); |
| 5198 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); |
| 5199 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); |
| 5200 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); |
| 5201 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); |
| 5202 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); |
| 5203 SQLITE_API void sqlite3_result_int(sqlite3_context*, int); |
| 5204 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); |
| 5205 SQLITE_API void sqlite3_result_null(sqlite3_context*); |
| 5206 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(
void*)); |
| 5207 SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint
64, |
| 5208 void(*)(void*), unsigned char encoding); |
| 5209 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*
)(void*)); |
| 5210 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(
*)(void*)); |
| 5211 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(
*)(void*)); |
| 5212 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); |
| 5213 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); |
| 5214 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); |
| 5215 |
| 5216 |
| 5217 /* |
| 5218 ** CAPI3REF: Setting The Subtype Of An SQL Function |
| 5219 ** METHOD: sqlite3_context |
| 5220 ** |
| 5221 ** The sqlite3_result_subtype(C,T) function causes the subtype of |
| 5222 ** the result from the [application-defined SQL function] with |
| 5223 ** [sqlite3_context] C to be the value T. Only the lower 8 bits |
| 5224 ** of the subtype T are preserved in current versions of SQLite; |
| 5225 ** higher order bits are discarded. |
| 5226 ** The number of subtype bytes preserved by SQLite might increase |
| 5227 ** in future releases of SQLite. |
| 5228 */ |
| 5229 SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int); |
| 5230 |
| 5231 /* |
| 5232 ** CAPI3REF: Define New Collating Sequences |
| 5233 ** METHOD: sqlite3 |
| 5234 ** |
| 5235 ** ^These functions add, remove, or modify a [collation] associated |
| 5236 ** with the [database connection] specified as the first argument. |
| 5237 ** |
| 5238 ** ^The name of the collation is a UTF-8 string |
| 5239 ** for sqlite3_create_collation() and sqlite3_create_collation_v2() |
| 5240 ** and a UTF-16 string in native byte order for sqlite3_create_collation16(). |
| 5241 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are |
| 5242 ** considered to be the same name. |
| 5243 ** |
| 5244 ** ^(The third argument (eTextRep) must be one of the constants: |
| 5245 ** <ul> |
| 5246 ** <li> [SQLITE_UTF8], |
| 5247 ** <li> [SQLITE_UTF16LE], |
| 5248 ** <li> [SQLITE_UTF16BE], |
| 5249 ** <li> [SQLITE_UTF16], or |
| 5250 ** <li> [SQLITE_UTF16_ALIGNED]. |
| 5251 ** </ul>)^ |
| 5252 ** ^The eTextRep argument determines the encoding of strings passed |
| 5253 ** to the collating function callback, xCallback. |
| 5254 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep |
| 5255 ** force strings to be UTF16 with native byte order. |
| 5256 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin |
| 5257 ** on an even byte address. |
| 5258 ** |
| 5259 ** ^The fourth argument, pArg, is an application data pointer that is passed |
| 5260 ** through as the first argument to the collating function callback. |
| 5261 ** |
| 5262 ** ^The fifth argument, xCallback, is a pointer to the collating function. |
| 5263 ** ^Multiple collating functions can be registered using the same name but |
| 5264 ** with different eTextRep parameters and SQLite will use whichever |
| 5265 ** function requires the least amount of data transformation. |
| 5266 ** ^If the xCallback argument is NULL then the collating function is |
| 5267 ** deleted. ^When all collating functions having the same name are deleted, |
| 5268 ** that collation is no longer usable. |
| 5269 ** |
| 5270 ** ^The collating function callback is invoked with a copy of the pArg |
| 5271 ** application data pointer and with two strings in the encoding specified |
| 5272 ** by the eTextRep argument. The collating function must return an |
| 5273 ** integer that is negative, zero, or positive |
| 5274 ** if the first string is less than, equal to, or greater than the second, |
| 5275 ** respectively. A collating function must always return the same answer |
| 5276 ** given the same inputs. If two or more collating functions are registered |
| 5277 ** to the same collation name (using different eTextRep values) then all |
| 5278 ** must give an equivalent answer when invoked with equivalent strings. |
| 5279 ** The collating function must obey the following properties for all |
| 5280 ** strings A, B, and C: |
| 5281 ** |
| 5282 ** <ol> |
| 5283 ** <li> If A==B then B==A. |
| 5284 ** <li> If A==B and B==C then A==C. |
| 5285 ** <li> If A<B THEN B>A. |
| 5286 ** <li> If A<B and B<C then A<C. |
| 5287 ** </ol> |
| 5288 ** |
| 5289 ** If a collating function fails any of the above constraints and that |
| 5290 ** collating function is registered and used, then the behavior of SQLite |
| 5291 ** is undefined. |
| 5292 ** |
| 5293 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() |
| 5294 ** with the addition that the xDestroy callback is invoked on pArg when |
| 5295 ** the collating function is deleted. |
| 5296 ** ^Collating functions are deleted when they are overridden by later |
| 5297 ** calls to the collation creation functions or when the |
| 5298 ** [database connection] is closed using [sqlite3_close()]. |
| 5299 ** |
| 5300 ** ^The xDestroy callback is <u>not</u> called if the |
| 5301 ** sqlite3_create_collation_v2() function fails. Applications that invoke |
| 5302 ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should |
| 5303 ** check the return code and dispose of the application data pointer |
| 5304 ** themselves rather than expecting SQLite to deal with it for them. |
| 5305 ** This is different from every other SQLite interface. The inconsistency |
| 5306 ** is unfortunate but cannot be changed without breaking backwards |
| 5307 ** compatibility. |
| 5308 ** |
| 5309 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. |
| 5310 */ |
| 5311 SQLITE_API int sqlite3_create_collation( |
| 5312 sqlite3*, |
| 5313 const char *zName, |
| 5314 int eTextRep, |
| 5315 void *pArg, |
| 5316 int(*xCompare)(void*,int,const void*,int,const void*) |
| 5317 ); |
| 5318 SQLITE_API int sqlite3_create_collation_v2( |
| 5319 sqlite3*, |
| 5320 const char *zName, |
| 5321 int eTextRep, |
| 5322 void *pArg, |
| 5323 int(*xCompare)(void*,int,const void*,int,const void*), |
| 5324 void(*xDestroy)(void*) |
| 5325 ); |
| 5326 SQLITE_API int sqlite3_create_collation16( |
| 5327 sqlite3*, |
| 5328 const void *zName, |
| 5329 int eTextRep, |
| 5330 void *pArg, |
| 5331 int(*xCompare)(void*,int,const void*,int,const void*) |
| 5332 ); |
| 5333 |
| 5334 /* |
| 5335 ** CAPI3REF: Collation Needed Callbacks |
| 5336 ** METHOD: sqlite3 |
| 5337 ** |
| 5338 ** ^To avoid having to register all collation sequences before a database |
| 5339 ** can be used, a single callback function may be registered with the |
| 5340 ** [database connection] to be invoked whenever an undefined collation |
| 5341 ** sequence is required. |
| 5342 ** |
| 5343 ** ^If the function is registered using the sqlite3_collation_needed() API, |
| 5344 ** then it is passed the names of undefined collation sequences as strings |
| 5345 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, |
| 5346 ** the names are passed as UTF-16 in machine native byte order. |
| 5347 ** ^A call to either function replaces the existing collation-needed callback. |
| 5348 ** |
| 5349 ** ^(When the callback is invoked, the first argument passed is a copy |
| 5350 ** of the second argument to sqlite3_collation_needed() or |
| 5351 ** sqlite3_collation_needed16(). The second argument is the database |
| 5352 ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], |
| 5353 ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation |
| 5354 ** sequence function required. The fourth parameter is the name of the |
| 5355 ** required collation sequence.)^ |
| 5356 ** |
| 5357 ** The callback function should register the desired collation using |
| 5358 ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or |
| 5359 ** [sqlite3_create_collation_v2()]. |
| 5360 */ |
| 5361 SQLITE_API int sqlite3_collation_needed( |
| 5362 sqlite3*, |
| 5363 void*, |
| 5364 void(*)(void*,sqlite3*,int eTextRep,const char*) |
| 5365 ); |
| 5366 SQLITE_API int sqlite3_collation_needed16( |
| 5367 sqlite3*, |
| 5368 void*, |
| 5369 void(*)(void*,sqlite3*,int eTextRep,const void*) |
| 5370 ); |
| 5371 |
| 5372 #ifdef SQLITE_HAS_CODEC |
| 5373 /* |
| 5374 ** Specify the key for an encrypted database. This routine should be |
| 5375 ** called right after sqlite3_open(). |
| 5376 ** |
| 5377 ** The code to implement this API is not available in the public release |
| 5378 ** of SQLite. |
| 5379 */ |
| 5380 SQLITE_API int sqlite3_key( |
| 5381 sqlite3 *db, /* Database to be rekeyed */ |
| 5382 const void *pKey, int nKey /* The key */ |
| 5383 ); |
| 5384 SQLITE_API int sqlite3_key_v2( |
| 5385 sqlite3 *db, /* Database to be rekeyed */ |
| 5386 const char *zDbName, /* Name of the database */ |
| 5387 const void *pKey, int nKey /* The key */ |
| 5388 ); |
| 5389 |
| 5390 /* |
| 5391 ** Change the key on an open database. If the current database is not |
| 5392 ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the |
| 5393 ** database is decrypted. |
| 5394 ** |
| 5395 ** The code to implement this API is not available in the public release |
| 5396 ** of SQLite. |
| 5397 */ |
| 5398 SQLITE_API int sqlite3_rekey( |
| 5399 sqlite3 *db, /* Database to be rekeyed */ |
| 5400 const void *pKey, int nKey /* The new key */ |
| 5401 ); |
| 5402 SQLITE_API int sqlite3_rekey_v2( |
| 5403 sqlite3 *db, /* Database to be rekeyed */ |
| 5404 const char *zDbName, /* Name of the database */ |
| 5405 const void *pKey, int nKey /* The new key */ |
| 5406 ); |
| 5407 |
| 5408 /* |
| 5409 ** Specify the activation key for a SEE database. Unless |
| 5410 ** activated, none of the SEE routines will work. |
| 5411 */ |
| 5412 SQLITE_API void sqlite3_activate_see( |
| 5413 const char *zPassPhrase /* Activation phrase */ |
| 5414 ); |
| 5415 #endif |
| 5416 |
| 5417 #ifdef SQLITE_ENABLE_CEROD |
| 5418 /* |
| 5419 ** Specify the activation key for a CEROD database. Unless |
| 5420 ** activated, none of the CEROD routines will work. |
| 5421 */ |
| 5422 SQLITE_API void sqlite3_activate_cerod( |
| 5423 const char *zPassPhrase /* Activation phrase */ |
| 5424 ); |
| 5425 #endif |
| 5426 |
| 5427 /* |
| 5428 ** CAPI3REF: Suspend Execution For A Short Time |
| 5429 ** |
| 5430 ** The sqlite3_sleep() function causes the current thread to suspend execution |
| 5431 ** for at least a number of milliseconds specified in its parameter. |
| 5432 ** |
| 5433 ** If the operating system does not support sleep requests with |
| 5434 ** millisecond time resolution, then the time will be rounded up to |
| 5435 ** the nearest second. The number of milliseconds of sleep actually |
| 5436 ** requested from the operating system is returned. |
| 5437 ** |
| 5438 ** ^SQLite implements this interface by calling the xSleep() |
| 5439 ** method of the default [sqlite3_vfs] object. If the xSleep() method |
| 5440 ** of the default VFS is not implemented correctly, or not implemented at |
| 5441 ** all, then the behavior of sqlite3_sleep() may deviate from the description |
| 5442 ** in the previous paragraphs. |
| 5443 */ |
| 5444 SQLITE_API int sqlite3_sleep(int); |
| 5445 |
| 5446 /* |
| 5447 ** CAPI3REF: Name Of The Folder Holding Temporary Files |
| 5448 ** |
| 5449 ** ^(If this global variable is made to point to a string which is |
| 5450 ** the name of a folder (a.k.a. directory), then all temporary files |
| 5451 ** created by SQLite when using a built-in [sqlite3_vfs | VFS] |
| 5452 ** will be placed in that directory.)^ ^If this variable |
| 5453 ** is a NULL pointer, then SQLite performs a search for an appropriate |
| 5454 ** temporary file directory. |
| 5455 ** |
| 5456 ** Applications are strongly discouraged from using this global variable. |
| 5457 ** It is required to set a temporary folder on Windows Runtime (WinRT). |
| 5458 ** But for all other platforms, it is highly recommended that applications |
| 5459 ** neither read nor write this variable. This global variable is a relic |
| 5460 ** that exists for backwards compatibility of legacy applications and should |
| 5461 ** be avoided in new projects. |
| 5462 ** |
| 5463 ** It is not safe to read or modify this variable in more than one |
| 5464 ** thread at a time. It is not safe to read or modify this variable |
| 5465 ** if a [database connection] is being used at the same time in a separate |
| 5466 ** thread. |
| 5467 ** It is intended that this variable be set once |
| 5468 ** as part of process initialization and before any SQLite interface |
| 5469 ** routines have been called and that this variable remain unchanged |
| 5470 ** thereafter. |
| 5471 ** |
| 5472 ** ^The [temp_store_directory pragma] may modify this variable and cause |
| 5473 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, |
| 5474 ** the [temp_store_directory pragma] always assumes that any string |
| 5475 ** that this variable points to is held in memory obtained from |
| 5476 ** [sqlite3_malloc] and the pragma may attempt to free that memory |
| 5477 ** using [sqlite3_free]. |
| 5478 ** Hence, if this variable is modified directly, either it should be |
| 5479 ** made NULL or made to point to memory obtained from [sqlite3_malloc] |
| 5480 ** or else the use of the [temp_store_directory pragma] should be avoided. |
| 5481 ** Except when requested by the [temp_store_directory pragma], SQLite |
| 5482 ** does not free the memory that sqlite3_temp_directory points to. If |
| 5483 ** the application wants that memory to be freed, it must do |
| 5484 ** so itself, taking care to only do so after all [database connection] |
| 5485 ** objects have been destroyed. |
| 5486 ** |
| 5487 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set |
| 5488 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various |
| 5489 ** features that require the use of temporary files may fail. Here is an |
| 5490 ** example of how to do this using C++ with the Windows Runtime: |
| 5491 ** |
| 5492 ** <blockquote><pre> |
| 5493 ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current-> |
| 5494 ** TemporaryFolder->Path->Data(); |
| 5495 ** char zPathBuf[MAX_PATH + 1]; |
| 5496 ** memset(zPathBuf, 0, sizeof(zPathBuf)); |
| 5497 ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf), |
| 5498 ** NULL, NULL); |
| 5499 ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf); |
| 5500 ** </pre></blockquote> |
| 5501 */ |
| 5502 SQLITE_API char *sqlite3_temp_directory; |
| 5503 |
| 5504 /* |
| 5505 ** CAPI3REF: Name Of The Folder Holding Database Files |
| 5506 ** |
| 5507 ** ^(If this global variable is made to point to a string which is |
| 5508 ** the name of a folder (a.k.a. directory), then all database files |
| 5509 ** specified with a relative pathname and created or accessed by |
| 5510 ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed |
| 5511 ** to be relative to that directory.)^ ^If this variable is a NULL |
| 5512 ** pointer, then SQLite assumes that all database files specified |
| 5513 ** with a relative pathname are relative to the current directory |
| 5514 ** for the process. Only the windows VFS makes use of this global |
| 5515 ** variable; it is ignored by the unix VFS. |
| 5516 ** |
| 5517 ** Changing the value of this variable while a database connection is |
| 5518 ** open can result in a corrupt database. |
| 5519 ** |
| 5520 ** It is not safe to read or modify this variable in more than one |
| 5521 ** thread at a time. It is not safe to read or modify this variable |
| 5522 ** if a [database connection] is being used at the same time in a separate |
| 5523 ** thread. |
| 5524 ** It is intended that this variable be set once |
| 5525 ** as part of process initialization and before any SQLite interface |
| 5526 ** routines have been called and that this variable remain unchanged |
| 5527 ** thereafter. |
| 5528 ** |
| 5529 ** ^The [data_store_directory pragma] may modify this variable and cause |
| 5530 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, |
| 5531 ** the [data_store_directory pragma] always assumes that any string |
| 5532 ** that this variable points to is held in memory obtained from |
| 5533 ** [sqlite3_malloc] and the pragma may attempt to free that memory |
| 5534 ** using [sqlite3_free]. |
| 5535 ** Hence, if this variable is modified directly, either it should be |
| 5536 ** made NULL or made to point to memory obtained from [sqlite3_malloc] |
| 5537 ** or else the use of the [data_store_directory pragma] should be avoided. |
| 5538 */ |
| 5539 SQLITE_API char *sqlite3_data_directory; |
| 5540 |
| 5541 /* |
| 5542 ** CAPI3REF: Test For Auto-Commit Mode |
| 5543 ** KEYWORDS: {autocommit mode} |
| 5544 ** METHOD: sqlite3 |
| 5545 ** |
| 5546 ** ^The sqlite3_get_autocommit() interface returns non-zero or |
| 5547 ** zero if the given database connection is or is not in autocommit mode, |
| 5548 ** respectively. ^Autocommit mode is on by default. |
| 5549 ** ^Autocommit mode is disabled by a [BEGIN] statement. |
| 5550 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. |
| 5551 ** |
| 5552 ** If certain kinds of errors occur on a statement within a multi-statement |
| 5553 ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], |
| 5554 ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the |
| 5555 ** transaction might be rolled back automatically. The only way to |
| 5556 ** find out whether SQLite automatically rolled back the transaction after |
| 5557 ** an error is to use this function. |
| 5558 ** |
| 5559 ** If another thread changes the autocommit status of the database |
| 5560 ** connection while this routine is running, then the return value |
| 5561 ** is undefined. |
| 5562 */ |
| 5563 SQLITE_API int sqlite3_get_autocommit(sqlite3*); |
| 5564 |
| 5565 /* |
| 5566 ** CAPI3REF: Find The Database Handle Of A Prepared Statement |
| 5567 ** METHOD: sqlite3_stmt |
| 5568 ** |
| 5569 ** ^The sqlite3_db_handle interface returns the [database connection] handle |
| 5570 ** to which a [prepared statement] belongs. ^The [database connection] |
| 5571 ** returned by sqlite3_db_handle is the same [database connection] |
| 5572 ** that was the first argument |
| 5573 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to |
| 5574 ** create the statement in the first place. |
| 5575 */ |
| 5576 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); |
| 5577 |
| 5578 /* |
| 5579 ** CAPI3REF: Return The Filename For A Database Connection |
| 5580 ** METHOD: sqlite3 |
| 5581 ** |
| 5582 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename |
| 5583 ** associated with database N of connection D. ^The main database file |
| 5584 ** has the name "main". If there is no attached database N on the database |
| 5585 ** connection D, or if database N is a temporary or in-memory database, then |
| 5586 ** a NULL pointer is returned. |
| 5587 ** |
| 5588 ** ^The filename returned by this function is the output of the |
| 5589 ** xFullPathname method of the [VFS]. ^In other words, the filename |
| 5590 ** will be an absolute pathname, even if the filename used |
| 5591 ** to open the database originally was a URI or relative pathname. |
| 5592 */ |
| 5593 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 5594 |
| 5595 /* |
| 5596 ** CAPI3REF: Determine if a database is read-only |
| 5597 ** METHOD: sqlite3 |
| 5598 ** |
| 5599 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N |
| 5600 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not |
| 5601 ** the name of a database on connection D. |
| 5602 */ |
| 5603 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); |
| 5604 |
| 5605 /* |
| 5606 ** CAPI3REF: Find the next prepared statement |
| 5607 ** METHOD: sqlite3 |
| 5608 ** |
| 5609 ** ^This interface returns a pointer to the next [prepared statement] after |
| 5610 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL |
| 5611 ** then this interface returns a pointer to the first prepared statement |
| 5612 ** associated with the database connection pDb. ^If no prepared statement |
| 5613 ** satisfies the conditions of this routine, it returns NULL. |
| 5614 ** |
| 5615 ** The [database connection] pointer D in a call to |
| 5616 ** [sqlite3_next_stmt(D,S)] must refer to an open database |
| 5617 ** connection and in particular must not be a NULL pointer. |
| 5618 */ |
| 5619 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); |
| 5620 |
| 5621 /* |
| 5622 ** CAPI3REF: Commit And Rollback Notification Callbacks |
| 5623 ** METHOD: sqlite3 |
| 5624 ** |
| 5625 ** ^The sqlite3_commit_hook() interface registers a callback |
| 5626 ** function to be invoked whenever a transaction is [COMMIT | committed]. |
| 5627 ** ^Any callback set by a previous call to sqlite3_commit_hook() |
| 5628 ** for the same database connection is overridden. |
| 5629 ** ^The sqlite3_rollback_hook() interface registers a callback |
| 5630 ** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. |
| 5631 ** ^Any callback set by a previous call to sqlite3_rollback_hook() |
| 5632 ** for the same database connection is overridden. |
| 5633 ** ^The pArg argument is passed through to the callback. |
| 5634 ** ^If the callback on a commit hook function returns non-zero, |
| 5635 ** then the commit is converted into a rollback. |
| 5636 ** |
| 5637 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions |
| 5638 ** return the P argument from the previous call of the same function |
| 5639 ** on the same [database connection] D, or NULL for |
| 5640 ** the first call for each function on D. |
| 5641 ** |
| 5642 ** The commit and rollback hook callbacks are not reentrant. |
| 5643 ** The callback implementation must not do anything that will modify |
| 5644 ** the database connection that invoked the callback. Any actions |
| 5645 ** to modify the database connection must be deferred until after the |
| 5646 ** completion of the [sqlite3_step()] call that triggered the commit |
| 5647 ** or rollback hook in the first place. |
| 5648 ** Note that running any other SQL statements, including SELECT statements, |
| 5649 ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify |
| 5650 ** the database connections for the meaning of "modify" in this paragraph. |
| 5651 ** |
| 5652 ** ^Registering a NULL function disables the callback. |
| 5653 ** |
| 5654 ** ^When the commit hook callback routine returns zero, the [COMMIT] |
| 5655 ** operation is allowed to continue normally. ^If the commit hook |
| 5656 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. |
| 5657 ** ^The rollback hook is invoked on a rollback that results from a commit |
| 5658 ** hook returning non-zero, just as it would be with any other rollback. |
| 5659 ** |
| 5660 ** ^For the purposes of this API, a transaction is said to have been |
| 5661 ** rolled back if an explicit "ROLLBACK" statement is executed, or |
| 5662 ** an error or constraint causes an implicit rollback to occur. |
| 5663 ** ^The rollback callback is not invoked if a transaction is |
| 5664 ** automatically rolled back because the database connection is closed. |
| 5665 ** |
| 5666 ** See also the [sqlite3_update_hook()] interface. |
| 5667 */ |
| 5668 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); |
| 5669 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); |
| 5670 |
| 5671 /* |
| 5672 ** CAPI3REF: Data Change Notification Callbacks |
| 5673 ** METHOD: sqlite3 |
| 5674 ** |
| 5675 ** ^The sqlite3_update_hook() interface registers a callback function |
| 5676 ** with the [database connection] identified by the first argument |
| 5677 ** to be invoked whenever a row is updated, inserted or deleted in |
| 5678 ** a [rowid table]. |
| 5679 ** ^Any callback set by a previous call to this function |
| 5680 ** for the same database connection is overridden. |
| 5681 ** |
| 5682 ** ^The second argument is a pointer to the function to invoke when a |
| 5683 ** row is updated, inserted or deleted in a rowid table. |
| 5684 ** ^The first argument to the callback is a copy of the third argument |
| 5685 ** to sqlite3_update_hook(). |
| 5686 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], |
| 5687 ** or [SQLITE_UPDATE], depending on the operation that caused the callback |
| 5688 ** to be invoked. |
| 5689 ** ^The third and fourth arguments to the callback contain pointers to the |
| 5690 ** database and table name containing the affected row. |
| 5691 ** ^The final callback parameter is the [rowid] of the row. |
| 5692 ** ^In the case of an update, this is the [rowid] after the update takes place. |
| 5693 ** |
| 5694 ** ^(The update hook is not invoked when internal system tables are |
| 5695 ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 5696 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 5697 ** |
| 5698 ** ^In the current implementation, the update hook |
| 5699 ** is not invoked when conflicting rows are deleted because of an |
| 5700 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| 5701 ** invoked when rows are deleted using the [truncate optimization]. |
| 5702 ** The exceptions defined in this paragraph might change in a future |
| 5703 ** release of SQLite. |
| 5704 ** |
| 5705 ** The update hook implementation must not do anything that will modify |
| 5706 ** the database connection that invoked the update hook. Any actions |
| 5707 ** to modify the database connection must be deferred until after the |
| 5708 ** completion of the [sqlite3_step()] call that triggered the update hook. |
| 5709 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
| 5710 ** database connections for the meaning of "modify" in this paragraph. |
| 5711 ** |
| 5712 ** ^The sqlite3_update_hook(D,C,P) function |
| 5713 ** returns the P argument from the previous call |
| 5714 ** on the same [database connection] D, or NULL for |
| 5715 ** the first call on D. |
| 5716 ** |
| 5717 ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()], |
| 5718 ** and [sqlite3_preupdate_hook()] interfaces. |
| 5719 */ |
| 5720 SQLITE_API void *sqlite3_update_hook( |
| 5721 sqlite3*, |
| 5722 void(*)(void *,int ,char const *,char const *,sqlite3_int64), |
| 5723 void* |
| 5724 ); |
| 5725 |
| 5726 /* |
| 5727 ** CAPI3REF: Enable Or Disable Shared Pager Cache |
| 5728 ** |
| 5729 ** ^(This routine enables or disables the sharing of the database cache |
| 5730 ** and schema data structures between [database connection | connections] |
| 5731 ** to the same database. Sharing is enabled if the argument is true |
| 5732 ** and disabled if the argument is false.)^ |
| 5733 ** |
| 5734 ** ^Cache sharing is enabled and disabled for an entire process. |
| 5735 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). |
| 5736 ** In prior versions of SQLite, |
| 5737 ** sharing was enabled or disabled for each thread separately. |
| 5738 ** |
| 5739 ** ^(The cache sharing mode set by this interface effects all subsequent |
| 5740 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. |
| 5741 ** Existing database connections continue use the sharing mode |
| 5742 ** that was in effect at the time they were opened.)^ |
| 5743 ** |
| 5744 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled |
| 5745 ** successfully. An [error code] is returned otherwise.)^ |
| 5746 ** |
| 5747 ** ^Shared cache is disabled by default. But this might change in |
| 5748 ** future releases of SQLite. Applications that care about shared |
| 5749 ** cache setting should set it explicitly. |
| 5750 ** |
| 5751 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 |
| 5752 ** and will always return SQLITE_MISUSE. On those systems, |
| 5753 ** shared cache mode should be enabled per-database connection via |
| 5754 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE]. |
| 5755 ** |
| 5756 ** This interface is threadsafe on processors where writing a |
| 5757 ** 32-bit integer is atomic. |
| 5758 ** |
| 5759 ** See Also: [SQLite Shared-Cache Mode] |
| 5760 */ |
| 5761 SQLITE_API int sqlite3_enable_shared_cache(int); |
| 5762 |
| 5763 /* |
| 5764 ** CAPI3REF: Attempt To Free Heap Memory |
| 5765 ** |
| 5766 ** ^The sqlite3_release_memory() interface attempts to free N bytes |
| 5767 ** of heap memory by deallocating non-essential memory allocations |
| 5768 ** held by the database library. Memory used to cache database |
| 5769 ** pages to improve performance is an example of non-essential memory. |
| 5770 ** ^sqlite3_release_memory() returns the number of bytes actually freed, |
| 5771 ** which might be more or less than the amount requested. |
| 5772 ** ^The sqlite3_release_memory() routine is a no-op returning zero |
| 5773 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. |
| 5774 ** |
| 5775 ** See also: [sqlite3_db_release_memory()] |
| 5776 */ |
| 5777 SQLITE_API int sqlite3_release_memory(int); |
| 5778 |
| 5779 /* |
| 5780 ** CAPI3REF: Free Memory Used By A Database Connection |
| 5781 ** METHOD: sqlite3 |
| 5782 ** |
| 5783 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap |
| 5784 ** memory as possible from database connection D. Unlike the |
| 5785 ** [sqlite3_release_memory()] interface, this interface is in effect even |
| 5786 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is |
| 5787 ** omitted. |
| 5788 ** |
| 5789 ** See also: [sqlite3_release_memory()] |
| 5790 */ |
| 5791 SQLITE_API int sqlite3_db_release_memory(sqlite3*); |
| 5792 |
| 5793 /* |
| 5794 ** CAPI3REF: Impose A Limit On Heap Size |
| 5795 ** |
| 5796 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the |
| 5797 ** soft limit on the amount of heap memory that may be allocated by SQLite. |
| 5798 ** ^SQLite strives to keep heap memory utilization below the soft heap |
| 5799 ** limit by reducing the number of pages held in the page cache |
| 5800 ** as heap memory usages approaches the limit. |
| 5801 ** ^The soft heap limit is "soft" because even though SQLite strives to stay |
| 5802 ** below the limit, it will exceed the limit rather than generate |
| 5803 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit |
| 5804 ** is advisory only. |
| 5805 ** |
| 5806 ** ^The return value from sqlite3_soft_heap_limit64() is the size of |
| 5807 ** the soft heap limit prior to the call, or negative in the case of an |
| 5808 ** error. ^If the argument N is negative |
| 5809 ** then no change is made to the soft heap limit. Hence, the current |
| 5810 ** size of the soft heap limit can be determined by invoking |
| 5811 ** sqlite3_soft_heap_limit64() with a negative argument. |
| 5812 ** |
| 5813 ** ^If the argument N is zero then the soft heap limit is disabled. |
| 5814 ** |
| 5815 ** ^(The soft heap limit is not enforced in the current implementation |
| 5816 ** if one or more of following conditions are true: |
| 5817 ** |
| 5818 ** <ul> |
| 5819 ** <li> The soft heap limit is set to zero. |
| 5820 ** <li> Memory accounting is disabled using a combination of the |
| 5821 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and |
| 5822 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. |
| 5823 ** <li> An alternative page cache implementation is specified using |
| 5824 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...). |
| 5825 ** <li> The page cache allocates from its own memory pool supplied |
| 5826 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than |
| 5827 ** from the heap. |
| 5828 ** </ul>)^ |
| 5829 ** |
| 5830 ** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]), |
| 5831 ** the soft heap limit is enforced |
| 5832 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] |
| 5833 ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], |
| 5834 ** the soft heap limit is enforced on every memory allocation. Without |
| 5835 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced |
| 5836 ** when memory is allocated by the page cache. Testing suggests that because |
| 5837 ** the page cache is the predominate memory user in SQLite, most |
| 5838 ** applications will achieve adequate soft heap limit enforcement without |
| 5839 ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. |
| 5840 ** |
| 5841 ** The circumstances under which SQLite will enforce the soft heap limit may |
| 5842 ** changes in future releases of SQLite. |
| 5843 */ |
| 5844 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); |
| 5845 |
| 5846 /* |
| 5847 ** CAPI3REF: Deprecated Soft Heap Limit Interface |
| 5848 ** DEPRECATED |
| 5849 ** |
| 5850 ** This is a deprecated version of the [sqlite3_soft_heap_limit64()] |
| 5851 ** interface. This routine is provided for historical compatibility |
| 5852 ** only. All new applications should use the |
| 5853 ** [sqlite3_soft_heap_limit64()] interface rather than this one. |
| 5854 */ |
| 5855 SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); |
| 5856 |
| 5857 |
| 5858 /* |
| 5859 ** CAPI3REF: Extract Metadata About A Column Of A Table |
| 5860 ** METHOD: sqlite3 |
| 5861 ** |
| 5862 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns |
| 5863 ** information about column C of table T in database D |
| 5864 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() |
| 5865 ** interface returns SQLITE_OK and fills in the non-NULL pointers in |
| 5866 ** the final five arguments with appropriate values if the specified |
| 5867 ** column exists. ^The sqlite3_table_column_metadata() interface returns |
| 5868 ** SQLITE_ERROR and if the specified column does not exist. |
| 5869 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a |
| 5870 ** NULL pointer, then this routine simply checks for the existence of the |
| 5871 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it |
| 5872 ** does not. |
| 5873 ** |
| 5874 ** ^The column is identified by the second, third and fourth parameters to |
| 5875 ** this function. ^(The second parameter is either the name of the database |
| 5876 ** (i.e. "main", "temp", or an attached database) containing the specified |
| 5877 ** table or NULL.)^ ^If it is NULL, then all attached databases are searched |
| 5878 ** for the table using the same algorithm used by the database engine to |
| 5879 ** resolve unqualified table references. |
| 5880 ** |
| 5881 ** ^The third and fourth parameters to this function are the table and column |
| 5882 ** name of the desired column, respectively. |
| 5883 ** |
| 5884 ** ^Metadata is returned by writing to the memory locations passed as the 5th |
| 5885 ** and subsequent parameters to this function. ^Any of these arguments may be |
| 5886 ** NULL, in which case the corresponding element of metadata is omitted. |
| 5887 ** |
| 5888 ** ^(<blockquote> |
| 5889 ** <table border="1"> |
| 5890 ** <tr><th> Parameter <th> Output<br>Type <th> Description |
| 5891 ** |
| 5892 ** <tr><td> 5th <td> const char* <td> Data type |
| 5893 ** <tr><td> 6th <td> const char* <td> Name of default collation sequence |
| 5894 ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint |
| 5895 ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY |
| 5896 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] |
| 5897 ** </table> |
| 5898 ** </blockquote>)^ |
| 5899 ** |
| 5900 ** ^The memory pointed to by the character pointers returned for the |
| 5901 ** declaration type and collation sequence is valid until the next |
| 5902 ** call to any SQLite API function. |
| 5903 ** |
| 5904 ** ^If the specified table is actually a view, an [error code] is returned. |
| 5905 ** |
| 5906 ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table |
| 5907 ** is not a [WITHOUT ROWID] table and an |
| 5908 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output |
| 5909 ** parameters are set for the explicitly declared column. ^(If there is no |
| 5910 ** [INTEGER PRIMARY KEY] column, then the outputs |
| 5911 ** for the [rowid] are set as follows: |
| 5912 ** |
| 5913 ** <pre> |
| 5914 ** data type: "INTEGER" |
| 5915 ** collation sequence: "BINARY" |
| 5916 ** not null: 0 |
| 5917 ** primary key: 1 |
| 5918 ** auto increment: 0 |
| 5919 ** </pre>)^ |
| 5920 ** |
| 5921 ** ^This function causes all database schemas to be read from disk and |
| 5922 ** parsed, if that has not already been done, and returns an error if |
| 5923 ** any errors are encountered while loading the schema. |
| 5924 */ |
| 5925 SQLITE_API int sqlite3_table_column_metadata( |
| 5926 sqlite3 *db, /* Connection handle */ |
| 5927 const char *zDbName, /* Database name or NULL */ |
| 5928 const char *zTableName, /* Table name */ |
| 5929 const char *zColumnName, /* Column name */ |
| 5930 char const **pzDataType, /* OUTPUT: Declared data type */ |
| 5931 char const **pzCollSeq, /* OUTPUT: Collation sequence name */ |
| 5932 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ |
| 5933 int *pPrimaryKey, /* OUTPUT: True if column part of PK */ |
| 5934 int *pAutoinc /* OUTPUT: True if column is auto-increment */ |
| 5935 ); |
| 5936 |
| 5937 /* |
| 5938 ** CAPI3REF: Load An Extension |
| 5939 ** METHOD: sqlite3 |
| 5940 ** |
| 5941 ** ^This interface loads an SQLite extension library from the named file. |
| 5942 ** |
| 5943 ** ^The sqlite3_load_extension() interface attempts to load an |
| 5944 ** [SQLite extension] library contained in the file zFile. If |
| 5945 ** the file cannot be loaded directly, attempts are made to load |
| 5946 ** with various operating-system specific extensions added. |
| 5947 ** So for example, if "samplelib" cannot be loaded, then names like |
| 5948 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might |
| 5949 ** be tried also. |
| 5950 ** |
| 5951 ** ^The entry point is zProc. |
| 5952 ** ^(zProc may be 0, in which case SQLite will try to come up with an |
| 5953 ** entry point name on its own. It first tries "sqlite3_extension_init". |
| 5954 ** If that does not work, it constructs a name "sqlite3_X_init" where the |
| 5955 ** X is consists of the lower-case equivalent of all ASCII alphabetic |
| 5956 ** characters in the filename from the last "/" to the first following |
| 5957 ** "." and omitting any initial "lib".)^ |
| 5958 ** ^The sqlite3_load_extension() interface returns |
| 5959 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. |
| 5960 ** ^If an error occurs and pzErrMsg is not 0, then the |
| 5961 ** [sqlite3_load_extension()] interface shall attempt to |
| 5962 ** fill *pzErrMsg with error message text stored in memory |
| 5963 ** obtained from [sqlite3_malloc()]. The calling function |
| 5964 ** should free this memory by calling [sqlite3_free()]. |
| 5965 ** |
| 5966 ** ^Extension loading must be enabled using |
| 5967 ** [sqlite3_enable_load_extension()] or |
| 5968 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL) |
| 5969 ** prior to calling this API, |
| 5970 ** otherwise an error will be returned. |
| 5971 ** |
| 5972 ** <b>Security warning:</b> It is recommended that the |
| 5973 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this |
| 5974 ** interface. The use of the [sqlite3_enable_load_extension()] interface |
| 5975 ** should be avoided. This will keep the SQL function [load_extension()] |
| 5976 ** disabled and prevent SQL injections from giving attackers |
| 5977 ** access to extension loading capabilities. |
| 5978 ** |
| 5979 ** See also the [load_extension() SQL function]. |
| 5980 */ |
| 5981 SQLITE_API int sqlite3_load_extension( |
| 5982 sqlite3 *db, /* Load the extension into this database connection */ |
| 5983 const char *zFile, /* Name of the shared library containing extension */ |
| 5984 const char *zProc, /* Entry point. Derived from zFile if 0 */ |
| 5985 char **pzErrMsg /* Put error message here if not 0 */ |
| 5986 ); |
| 5987 |
| 5988 /* |
| 5989 ** CAPI3REF: Enable Or Disable Extension Loading |
| 5990 ** METHOD: sqlite3 |
| 5991 ** |
| 5992 ** ^So as not to open security holes in older applications that are |
| 5993 ** unprepared to deal with [extension loading], and as a means of disabling |
| 5994 ** [extension loading] while evaluating user-entered SQL, the following API |
| 5995 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. |
| 5996 ** |
| 5997 ** ^Extension loading is off by default. |
| 5998 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 |
| 5999 ** to turn extension loading on and call it with onoff==0 to turn |
| 6000 ** it back off again. |
| 6001 ** |
| 6002 ** ^This interface enables or disables both the C-API |
| 6003 ** [sqlite3_load_extension()] and the SQL function [load_extension()]. |
| 6004 ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..) |
| 6005 ** to enable or disable only the C-API.)^ |
| 6006 ** |
| 6007 ** <b>Security warning:</b> It is recommended that extension loading |
| 6008 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method |
| 6009 ** rather than this interface, so the [load_extension()] SQL function |
| 6010 ** remains disabled. This will prevent SQL injections from giving attackers |
| 6011 ** access to extension loading capabilities. |
| 6012 */ |
| 6013 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); |
| 6014 |
| 6015 /* |
| 6016 ** CAPI3REF: Automatically Load Statically Linked Extensions |
| 6017 ** |
| 6018 ** ^This interface causes the xEntryPoint() function to be invoked for |
| 6019 ** each new [database connection] that is created. The idea here is that |
| 6020 ** xEntryPoint() is the entry point for a statically linked [SQLite extension] |
| 6021 ** that is to be automatically loaded into all new database connections. |
| 6022 ** |
| 6023 ** ^(Even though the function prototype shows that xEntryPoint() takes |
| 6024 ** no arguments and returns void, SQLite invokes xEntryPoint() with three |
| 6025 ** arguments and expects an integer result as if the signature of the |
| 6026 ** entry point where as follows: |
| 6027 ** |
| 6028 ** <blockquote><pre> |
| 6029 ** int xEntryPoint( |
| 6030 ** sqlite3 *db, |
| 6031 ** const char **pzErrMsg, |
| 6032 ** const struct sqlite3_api_routines *pThunk |
| 6033 ** ); |
| 6034 ** </pre></blockquote>)^ |
| 6035 ** |
| 6036 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg |
| 6037 ** point to an appropriate error message (obtained from [sqlite3_mprintf()]) |
| 6038 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg |
| 6039 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke |
| 6040 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any |
| 6041 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], |
| 6042 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. |
| 6043 ** |
| 6044 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already |
| 6045 ** on the list of automatic extensions is a harmless no-op. ^No entry point |
| 6046 ** will be called more than once for each database connection that is opened. |
| 6047 ** |
| 6048 ** See also: [sqlite3_reset_auto_extension()] |
| 6049 ** and [sqlite3_cancel_auto_extension()] |
| 6050 */ |
| 6051 SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void)); |
| 6052 |
| 6053 /* |
| 6054 ** CAPI3REF: Cancel Automatic Extension Loading |
| 6055 ** |
| 6056 ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the |
| 6057 ** initialization routine X that was registered using a prior call to |
| 6058 ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)] |
| 6059 ** routine returns 1 if initialization routine X was successfully |
| 6060 ** unregistered and it returns 0 if X was not on the list of initialization |
| 6061 ** routines. |
| 6062 */ |
| 6063 SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void)); |
| 6064 |
| 6065 /* |
| 6066 ** CAPI3REF: Reset Automatic Extension Loading |
| 6067 ** |
| 6068 ** ^This interface disables all automatic extensions previously |
| 6069 ** registered using [sqlite3_auto_extension()]. |
| 6070 */ |
| 6071 SQLITE_API void sqlite3_reset_auto_extension(void); |
| 6072 |
| 6073 /* |
| 6074 ** The interface to the virtual-table mechanism is currently considered |
| 6075 ** to be experimental. The interface might change in incompatible ways. |
| 6076 ** If this is a problem for you, do not use the interface at this time. |
| 6077 ** |
| 6078 ** When the virtual-table mechanism stabilizes, we will declare the |
| 6079 ** interface fixed, support it indefinitely, and remove this comment. |
| 6080 */ |
| 6081 |
| 6082 /* |
| 6083 ** Structures used by the virtual table interface |
| 6084 */ |
| 6085 typedef struct sqlite3_vtab sqlite3_vtab; |
| 6086 typedef struct sqlite3_index_info sqlite3_index_info; |
| 6087 typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; |
| 6088 typedef struct sqlite3_module sqlite3_module; |
| 6089 |
| 6090 /* |
| 6091 ** CAPI3REF: Virtual Table Object |
| 6092 ** KEYWORDS: sqlite3_module {virtual table module} |
| 6093 ** |
| 6094 ** This structure, sometimes called a "virtual table module", |
| 6095 ** defines the implementation of a [virtual tables]. |
| 6096 ** This structure consists mostly of methods for the module. |
| 6097 ** |
| 6098 ** ^A virtual table module is created by filling in a persistent |
| 6099 ** instance of this structure and passing a pointer to that instance |
| 6100 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. |
| 6101 ** ^The registration remains valid until it is replaced by a different |
| 6102 ** module or until the [database connection] closes. The content |
| 6103 ** of this structure must not change while it is registered with |
| 6104 ** any database connection. |
| 6105 */ |
| 6106 struct sqlite3_module { |
| 6107 int iVersion; |
| 6108 int (*xCreate)(sqlite3*, void *pAux, |
| 6109 int argc, const char *const*argv, |
| 6110 sqlite3_vtab **ppVTab, char**); |
| 6111 int (*xConnect)(sqlite3*, void *pAux, |
| 6112 int argc, const char *const*argv, |
| 6113 sqlite3_vtab **ppVTab, char**); |
| 6114 int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); |
| 6115 int (*xDisconnect)(sqlite3_vtab *pVTab); |
| 6116 int (*xDestroy)(sqlite3_vtab *pVTab); |
| 6117 int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); |
| 6118 int (*xClose)(sqlite3_vtab_cursor*); |
| 6119 int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, |
| 6120 int argc, sqlite3_value **argv); |
| 6121 int (*xNext)(sqlite3_vtab_cursor*); |
| 6122 int (*xEof)(sqlite3_vtab_cursor*); |
| 6123 int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); |
| 6124 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); |
| 6125 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); |
| 6126 int (*xBegin)(sqlite3_vtab *pVTab); |
| 6127 int (*xSync)(sqlite3_vtab *pVTab); |
| 6128 int (*xCommit)(sqlite3_vtab *pVTab); |
| 6129 int (*xRollback)(sqlite3_vtab *pVTab); |
| 6130 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, |
| 6131 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), |
| 6132 void **ppArg); |
| 6133 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); |
| 6134 /* The methods above are in version 1 of the sqlite_module object. Those |
| 6135 ** below are for version 2 and greater. */ |
| 6136 int (*xSavepoint)(sqlite3_vtab *pVTab, int); |
| 6137 int (*xRelease)(sqlite3_vtab *pVTab, int); |
| 6138 int (*xRollbackTo)(sqlite3_vtab *pVTab, int); |
| 6139 }; |
| 6140 |
| 6141 /* |
| 6142 ** CAPI3REF: Virtual Table Indexing Information |
| 6143 ** KEYWORDS: sqlite3_index_info |
| 6144 ** |
| 6145 ** The sqlite3_index_info structure and its substructures is used as part |
| 6146 ** of the [virtual table] interface to |
| 6147 ** pass information into and receive the reply from the [xBestIndex] |
| 6148 ** method of a [virtual table module]. The fields under **Inputs** are the |
| 6149 ** inputs to xBestIndex and are read-only. xBestIndex inserts its |
| 6150 ** results into the **Outputs** fields. |
| 6151 ** |
| 6152 ** ^(The aConstraint[] array records WHERE clause constraints of the form: |
| 6153 ** |
| 6154 ** <blockquote>column OP expr</blockquote> |
| 6155 ** |
| 6156 ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is |
| 6157 ** stored in aConstraint[].op using one of the |
| 6158 ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ |
| 6159 ** ^(The index of the column is stored in |
| 6160 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the |
| 6161 ** expr on the right-hand side can be evaluated (and thus the constraint |
| 6162 ** is usable) and false if it cannot.)^ |
| 6163 ** |
| 6164 ** ^The optimizer automatically inverts terms of the form "expr OP column" |
| 6165 ** and makes other simplifications to the WHERE clause in an attempt to |
| 6166 ** get as many WHERE clause terms into the form shown above as possible. |
| 6167 ** ^The aConstraint[] array only reports WHERE clause terms that are |
| 6168 ** relevant to the particular virtual table being queried. |
| 6169 ** |
| 6170 ** ^Information about the ORDER BY clause is stored in aOrderBy[]. |
| 6171 ** ^Each term of aOrderBy records a column of the ORDER BY clause. |
| 6172 ** |
| 6173 ** The colUsed field indicates which columns of the virtual table may be |
| 6174 ** required by the current scan. Virtual table columns are numbered from |
| 6175 ** zero in the order in which they appear within the CREATE TABLE statement |
| 6176 ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), |
| 6177 ** the corresponding bit is set within the colUsed mask if the column may be |
| 6178 ** required by SQLite. If the table has at least 64 columns and any column |
| 6179 ** to the right of the first 63 is required, then bit 63 of colUsed is also |
| 6180 ** set. In other words, column iCol may be required if the expression |
| 6181 ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to |
| 6182 ** non-zero. |
| 6183 ** |
| 6184 ** The [xBestIndex] method must fill aConstraintUsage[] with information |
| 6185 ** about what parameters to pass to xFilter. ^If argvIndex>0 then |
| 6186 ** the right-hand side of the corresponding aConstraint[] is evaluated |
| 6187 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit |
| 6188 ** is true, then the constraint is assumed to be fully handled by the |
| 6189 ** virtual table and is not checked again by SQLite.)^ |
| 6190 ** |
| 6191 ** ^The idxNum and idxPtr values are recorded and passed into the |
| 6192 ** [xFilter] method. |
| 6193 ** ^[sqlite3_free()] is used to free idxPtr if and only if |
| 6194 ** needToFreeIdxPtr is true. |
| 6195 ** |
| 6196 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in |
| 6197 ** the correct order to satisfy the ORDER BY clause so that no separate |
| 6198 ** sorting step is required. |
| 6199 ** |
| 6200 ** ^The estimatedCost value is an estimate of the cost of a particular |
| 6201 ** strategy. A cost of N indicates that the cost of the strategy is similar |
| 6202 ** to a linear scan of an SQLite table with N rows. A cost of log(N) |
| 6203 ** indicates that the expense of the operation is similar to that of a |
| 6204 ** binary search on a unique indexed field of an SQLite table with N rows. |
| 6205 ** |
| 6206 ** ^The estimatedRows value is an estimate of the number of rows that |
| 6207 ** will be returned by the strategy. |
| 6208 ** |
| 6209 ** The xBestIndex method may optionally populate the idxFlags field with a |
| 6210 ** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag - |
| 6211 ** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite |
| 6212 ** assumes that the strategy may visit at most one row. |
| 6213 ** |
| 6214 ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then |
| 6215 ** SQLite also assumes that if a call to the xUpdate() method is made as |
| 6216 ** part of the same statement to delete or update a virtual table row and the |
| 6217 ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback |
| 6218 ** any database changes. In other words, if the xUpdate() returns |
| 6219 ** SQLITE_CONSTRAINT, the database contents must be exactly as they were |
| 6220 ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not |
| 6221 ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by |
| 6222 ** the xUpdate method are automatically rolled back by SQLite. |
| 6223 ** |
| 6224 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info |
| 6225 ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). |
| 6226 ** If a virtual table extension is |
| 6227 ** used with an SQLite version earlier than 3.8.2, the results of attempting |
| 6228 ** to read or write the estimatedRows field are undefined (but are likely |
| 6229 ** to included crashing the application). The estimatedRows field should |
| 6230 ** therefore only be used if [sqlite3_libversion_number()] returns a |
| 6231 ** value greater than or equal to 3008002. Similarly, the idxFlags field |
| 6232 ** was added for [version 3.9.0] ([dateof:3.9.0]). |
| 6233 ** It may therefore only be used if |
| 6234 ** sqlite3_libversion_number() returns a value greater than or equal to |
| 6235 ** 3009000. |
| 6236 */ |
| 6237 struct sqlite3_index_info { |
| 6238 /* Inputs */ |
| 6239 int nConstraint; /* Number of entries in aConstraint */ |
| 6240 struct sqlite3_index_constraint { |
| 6241 int iColumn; /* Column constrained. -1 for ROWID */ |
| 6242 unsigned char op; /* Constraint operator */ |
| 6243 unsigned char usable; /* True if this constraint is usable */ |
| 6244 int iTermOffset; /* Used internally - xBestIndex should ignore */ |
| 6245 } *aConstraint; /* Table of WHERE clause constraints */ |
| 6246 int nOrderBy; /* Number of terms in the ORDER BY clause */ |
| 6247 struct sqlite3_index_orderby { |
| 6248 int iColumn; /* Column number */ |
| 6249 unsigned char desc; /* True for DESC. False for ASC. */ |
| 6250 } *aOrderBy; /* The ORDER BY clause */ |
| 6251 /* Outputs */ |
| 6252 struct sqlite3_index_constraint_usage { |
| 6253 int argvIndex; /* if >0, constraint is part of argv to xFilter */ |
| 6254 unsigned char omit; /* Do not code a test for this constraint */ |
| 6255 } *aConstraintUsage; |
| 6256 int idxNum; /* Number used to identify the index */ |
| 6257 char *idxStr; /* String, possibly obtained from sqlite3_malloc */ |
| 6258 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ |
| 6259 int orderByConsumed; /* True if output is already ordered */ |
| 6260 double estimatedCost; /* Estimated cost of using this index */ |
| 6261 /* Fields below are only available in SQLite 3.8.2 and later */ |
| 6262 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ |
| 6263 /* Fields below are only available in SQLite 3.9.0 and later */ |
| 6264 int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ |
| 6265 /* Fields below are only available in SQLite 3.10.0 and later */ |
| 6266 sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ |
| 6267 }; |
| 6268 |
| 6269 /* |
| 6270 ** CAPI3REF: Virtual Table Scan Flags |
| 6271 */ |
| 6272 #define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */ |
| 6273 |
| 6274 /* |
| 6275 ** CAPI3REF: Virtual Table Constraint Operator Codes |
| 6276 ** |
| 6277 ** These macros defined the allowed values for the |
| 6278 ** [sqlite3_index_info].aConstraint[].op field. Each value represents |
| 6279 ** an operator that is part of a constraint term in the wHERE clause of |
| 6280 ** a query that uses a [virtual table]. |
| 6281 */ |
| 6282 #define SQLITE_INDEX_CONSTRAINT_EQ 2 |
| 6283 #define SQLITE_INDEX_CONSTRAINT_GT 4 |
| 6284 #define SQLITE_INDEX_CONSTRAINT_LE 8 |
| 6285 #define SQLITE_INDEX_CONSTRAINT_LT 16 |
| 6286 #define SQLITE_INDEX_CONSTRAINT_GE 32 |
| 6287 #define SQLITE_INDEX_CONSTRAINT_MATCH 64 |
| 6288 #define SQLITE_INDEX_CONSTRAINT_LIKE 65 |
| 6289 #define SQLITE_INDEX_CONSTRAINT_GLOB 66 |
| 6290 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67 |
| 6291 |
| 6292 /* |
| 6293 ** CAPI3REF: Register A Virtual Table Implementation |
| 6294 ** METHOD: sqlite3 |
| 6295 ** |
| 6296 ** ^These routines are used to register a new [virtual table module] name. |
| 6297 ** ^Module names must be registered before |
| 6298 ** creating a new [virtual table] using the module and before using a |
| 6299 ** preexisting [virtual table] for the module. |
| 6300 ** |
| 6301 ** ^The module name is registered on the [database connection] specified |
| 6302 ** by the first parameter. ^The name of the module is given by the |
| 6303 ** second parameter. ^The third parameter is a pointer to |
| 6304 ** the implementation of the [virtual table module]. ^The fourth |
| 6305 ** parameter is an arbitrary client data pointer that is passed through |
| 6306 ** into the [xCreate] and [xConnect] methods of the virtual table module |
| 6307 ** when a new virtual table is be being created or reinitialized. |
| 6308 ** |
| 6309 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which |
| 6310 ** is a pointer to a destructor for the pClientData. ^SQLite will |
| 6311 ** invoke the destructor function (if it is not NULL) when SQLite |
| 6312 ** no longer needs the pClientData pointer. ^The destructor will also |
| 6313 ** be invoked if the call to sqlite3_create_module_v2() fails. |
| 6314 ** ^The sqlite3_create_module() |
| 6315 ** interface is equivalent to sqlite3_create_module_v2() with a NULL |
| 6316 ** destructor. |
| 6317 */ |
| 6318 SQLITE_API int sqlite3_create_module( |
| 6319 sqlite3 *db, /* SQLite connection to register module with */ |
| 6320 const char *zName, /* Name of the module */ |
| 6321 const sqlite3_module *p, /* Methods for the module */ |
| 6322 void *pClientData /* Client data for xCreate/xConnect */ |
| 6323 ); |
| 6324 SQLITE_API int sqlite3_create_module_v2( |
| 6325 sqlite3 *db, /* SQLite connection to register module with */ |
| 6326 const char *zName, /* Name of the module */ |
| 6327 const sqlite3_module *p, /* Methods for the module */ |
| 6328 void *pClientData, /* Client data for xCreate/xConnect */ |
| 6329 void(*xDestroy)(void*) /* Module destructor function */ |
| 6330 ); |
| 6331 |
| 6332 /* |
| 6333 ** CAPI3REF: Virtual Table Instance Object |
| 6334 ** KEYWORDS: sqlite3_vtab |
| 6335 ** |
| 6336 ** Every [virtual table module] implementation uses a subclass |
| 6337 ** of this object to describe a particular instance |
| 6338 ** of the [virtual table]. Each subclass will |
| 6339 ** be tailored to the specific needs of the module implementation. |
| 6340 ** The purpose of this superclass is to define certain fields that are |
| 6341 ** common to all module implementations. |
| 6342 ** |
| 6343 ** ^Virtual tables methods can set an error message by assigning a |
| 6344 ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should |
| 6345 ** take care that any prior string is freed by a call to [sqlite3_free()] |
| 6346 ** prior to assigning a new string to zErrMsg. ^After the error message |
| 6347 ** is delivered up to the client application, the string will be automatically |
| 6348 ** freed by sqlite3_free() and the zErrMsg field will be zeroed. |
| 6349 */ |
| 6350 struct sqlite3_vtab { |
| 6351 const sqlite3_module *pModule; /* The module for this virtual table */ |
| 6352 int nRef; /* Number of open cursors */ |
| 6353 char *zErrMsg; /* Error message from sqlite3_mprintf() */ |
| 6354 /* Virtual table implementations will typically add additional fields */ |
| 6355 }; |
| 6356 |
| 6357 /* |
| 6358 ** CAPI3REF: Virtual Table Cursor Object |
| 6359 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} |
| 6360 ** |
| 6361 ** Every [virtual table module] implementation uses a subclass of the |
| 6362 ** following structure to describe cursors that point into the |
| 6363 ** [virtual table] and are used |
| 6364 ** to loop through the virtual table. Cursors are created using the |
| 6365 ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed |
| 6366 ** by the [sqlite3_module.xClose | xClose] method. Cursors are used |
| 6367 ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods |
| 6368 ** of the module. Each module implementation will define |
| 6369 ** the content of a cursor structure to suit its own needs. |
| 6370 ** |
| 6371 ** This superclass exists in order to define fields of the cursor that |
| 6372 ** are common to all implementations. |
| 6373 */ |
| 6374 struct sqlite3_vtab_cursor { |
| 6375 sqlite3_vtab *pVtab; /* Virtual table of this cursor */ |
| 6376 /* Virtual table implementations will typically add additional fields */ |
| 6377 }; |
| 6378 |
| 6379 /* |
| 6380 ** CAPI3REF: Declare The Schema Of A Virtual Table |
| 6381 ** |
| 6382 ** ^The [xCreate] and [xConnect] methods of a |
| 6383 ** [virtual table module] call this interface |
| 6384 ** to declare the format (the names and datatypes of the columns) of |
| 6385 ** the virtual tables they implement. |
| 6386 */ |
| 6387 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); |
| 6388 |
| 6389 /* |
| 6390 ** CAPI3REF: Overload A Function For A Virtual Table |
| 6391 ** METHOD: sqlite3 |
| 6392 ** |
| 6393 ** ^(Virtual tables can provide alternative implementations of functions |
| 6394 ** using the [xFindFunction] method of the [virtual table module]. |
| 6395 ** But global versions of those functions |
| 6396 ** must exist in order to be overloaded.)^ |
| 6397 ** |
| 6398 ** ^(This API makes sure a global version of a function with a particular |
| 6399 ** name and number of parameters exists. If no such function exists |
| 6400 ** before this API is called, a new function is created.)^ ^The implementation |
| 6401 ** of the new function always causes an exception to be thrown. So |
| 6402 ** the new function is not good for anything by itself. Its only |
| 6403 ** purpose is to be a placeholder function that can be overloaded |
| 6404 ** by a [virtual table]. |
| 6405 */ |
| 6406 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nA
rg); |
| 6407 |
| 6408 /* |
| 6409 ** The interface to the virtual-table mechanism defined above (back up |
| 6410 ** to a comment remarkably similar to this one) is currently considered |
| 6411 ** to be experimental. The interface might change in incompatible ways. |
| 6412 ** If this is a problem for you, do not use the interface at this time. |
| 6413 ** |
| 6414 ** When the virtual-table mechanism stabilizes, we will declare the |
| 6415 ** interface fixed, support it indefinitely, and remove this comment. |
| 6416 */ |
| 6417 |
| 6418 /* |
| 6419 ** CAPI3REF: A Handle To An Open BLOB |
| 6420 ** KEYWORDS: {BLOB handle} {BLOB handles} |
| 6421 ** |
| 6422 ** An instance of this object represents an open BLOB on which |
| 6423 ** [sqlite3_blob_open | incremental BLOB I/O] can be performed. |
| 6424 ** ^Objects of this type are created by [sqlite3_blob_open()] |
| 6425 ** and destroyed by [sqlite3_blob_close()]. |
| 6426 ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces |
| 6427 ** can be used to read or write small subsections of the BLOB. |
| 6428 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. |
| 6429 */ |
| 6430 typedef struct sqlite3_blob sqlite3_blob; |
| 6431 |
| 6432 /* |
| 6433 ** CAPI3REF: Open A BLOB For Incremental I/O |
| 6434 ** METHOD: sqlite3 |
| 6435 ** CONSTRUCTOR: sqlite3_blob |
| 6436 ** |
| 6437 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located |
| 6438 ** in row iRow, column zColumn, table zTable in database zDb; |
| 6439 ** in other words, the same BLOB that would be selected by: |
| 6440 ** |
| 6441 ** <pre> |
| 6442 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; |
| 6443 ** </pre>)^ |
| 6444 ** |
| 6445 ** ^(Parameter zDb is not the filename that contains the database, but |
| 6446 ** rather the symbolic name of the database. For attached databases, this is |
| 6447 ** the name that appears after the AS keyword in the [ATTACH] statement. |
| 6448 ** For the main database file, the database name is "main". For TEMP |
| 6449 ** tables, the database name is "temp".)^ |
| 6450 ** |
| 6451 ** ^If the flags parameter is non-zero, then the BLOB is opened for read |
| 6452 ** and write access. ^If the flags parameter is zero, the BLOB is opened for |
| 6453 ** read-only access. |
| 6454 ** |
| 6455 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored |
| 6456 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error |
| 6457 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided |
| 6458 ** the API is not misused, it is always safe to call [sqlite3_blob_close()] |
| 6459 ** on *ppBlob after this function it returns. |
| 6460 ** |
| 6461 ** This function fails with SQLITE_ERROR if any of the following are true: |
| 6462 ** <ul> |
| 6463 ** <li> ^(Database zDb does not exist)^, |
| 6464 ** <li> ^(Table zTable does not exist within database zDb)^, |
| 6465 ** <li> ^(Table zTable is a WITHOUT ROWID table)^, |
| 6466 ** <li> ^(Column zColumn does not exist)^, |
| 6467 ** <li> ^(Row iRow is not present in the table)^, |
| 6468 ** <li> ^(The specified column of row iRow contains a value that is not |
| 6469 ** a TEXT or BLOB value)^, |
| 6470 ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE |
| 6471 ** constraint and the blob is being opened for read/write access)^, |
| 6472 ** <li> ^([foreign key constraints | Foreign key constraints] are enabled, |
| 6473 ** column zColumn is part of a [child key] definition and the blob is |
| 6474 ** being opened for read/write access)^. |
| 6475 ** </ul> |
| 6476 ** |
| 6477 ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 6478 ** [database connection] error code and message accessible via |
| 6479 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6480 ** |
| 6481 ** A BLOB referenced by sqlite3_blob_open() may be read using the |
| 6482 ** [sqlite3_blob_read()] interface and modified by using |
| 6483 ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a |
| 6484 ** different row of the same table using the [sqlite3_blob_reopen()] |
| 6485 ** interface. However, the column, table, or database of a [BLOB handle] |
| 6486 ** cannot be changed after the [BLOB handle] is opened. |
| 6487 ** |
| 6488 ** ^(If the row that a BLOB handle points to is modified by an |
| 6489 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 6490 ** then the BLOB handle is marked as "expired". |
| 6491 ** This is true if any column of the row is changed, even a column |
| 6492 ** other than the one the BLOB handle is open on.)^ |
| 6493 ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for |
| 6494 ** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. |
| 6495 ** ^(Changes written into a BLOB prior to the BLOB expiring are not |
| 6496 ** rolled back by the expiration of the BLOB. Such changes will eventually |
| 6497 ** commit if the transaction continues to completion.)^ |
| 6498 ** |
| 6499 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of |
| 6500 ** the opened blob. ^The size of a blob may not be changed by this |
| 6501 ** interface. Use the [UPDATE] SQL command to change the size of a |
| 6502 ** blob. |
| 6503 ** |
| 6504 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces |
| 6505 ** and the built-in [zeroblob] SQL function may be used to create a |
| 6506 ** zero-filled blob to read or write using the incremental-blob interface. |
| 6507 ** |
| 6508 ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 6509 ** be released by a call to [sqlite3_blob_close()]. |
| 6510 ** |
| 6511 ** See also: [sqlite3_blob_close()], |
| 6512 ** [sqlite3_blob_reopen()], [sqlite3_blob_read()], |
| 6513 ** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. |
| 6514 */ |
| 6515 SQLITE_API int sqlite3_blob_open( |
| 6516 sqlite3*, |
| 6517 const char *zDb, |
| 6518 const char *zTable, |
| 6519 const char *zColumn, |
| 6520 sqlite3_int64 iRow, |
| 6521 int flags, |
| 6522 sqlite3_blob **ppBlob |
| 6523 ); |
| 6524 |
| 6525 /* |
| 6526 ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6527 ** METHOD: sqlite3_blob |
| 6528 ** |
| 6529 ** ^This function is used to move an existing [BLOB handle] so that it points |
| 6530 ** to a different row of the same database table. ^The new row is identified |
| 6531 ** by the rowid value passed as the second argument. Only the row can be |
| 6532 ** changed. ^The database, table and column on which the blob handle is open |
| 6533 ** remain the same. Moving an existing [BLOB handle] to a new row is |
| 6534 ** faster than closing the existing handle and opening a new one. |
| 6535 ** |
| 6536 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
| 6537 ** it must exist and there must be either a blob or text value stored in |
| 6538 ** the nominated column.)^ ^If the new row is not present in the table, or if |
| 6539 ** it does not contain a blob or text value, or if another error occurs, an |
| 6540 ** SQLite error code is returned and the blob handle is considered aborted. |
| 6541 ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or |
| 6542 ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return |
| 6543 ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle |
| 6544 ** always returns zero. |
| 6545 ** |
| 6546 ** ^This function sets the database handle error code and message. |
| 6547 */ |
| 6548 SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); |
| 6549 |
| 6550 /* |
| 6551 ** CAPI3REF: Close A BLOB Handle |
| 6552 ** DESTRUCTOR: sqlite3_blob |
| 6553 ** |
| 6554 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed |
| 6555 ** unconditionally. Even if this routine returns an error code, the |
| 6556 ** handle is still closed.)^ |
| 6557 ** |
| 6558 ** ^If the blob handle being closed was opened for read-write access, and if |
| 6559 ** the database is in auto-commit mode and there are no other open read-write |
| 6560 ** blob handles or active write statements, the current transaction is |
| 6561 ** committed. ^If an error occurs while committing the transaction, an error |
| 6562 ** code is returned and the transaction rolled back. |
| 6563 ** |
| 6564 ** Calling this function with an argument that is not a NULL pointer or an |
| 6565 ** open blob handle results in undefined behaviour. ^Calling this routine |
| 6566 ** with a null pointer (such as would be returned by a failed call to |
| 6567 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function |
| 6568 ** is passed a valid open blob handle, the values returned by the |
| 6569 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. |
| 6570 */ |
| 6571 SQLITE_API int sqlite3_blob_close(sqlite3_blob *); |
| 6572 |
| 6573 /* |
| 6574 ** CAPI3REF: Return The Size Of An Open BLOB |
| 6575 ** METHOD: sqlite3_blob |
| 6576 ** |
| 6577 ** ^Returns the size in bytes of the BLOB accessible via the |
| 6578 ** successfully opened [BLOB handle] in its only argument. ^The |
| 6579 ** incremental blob I/O routines can only read or overwriting existing |
| 6580 ** blob content; they cannot change the size of a blob. |
| 6581 ** |
| 6582 ** This routine only works on a [BLOB handle] which has been created |
| 6583 ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 6584 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 6585 ** to this routine results in undefined and probably undesirable behavior. |
| 6586 */ |
| 6587 SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); |
| 6588 |
| 6589 /* |
| 6590 ** CAPI3REF: Read Data From A BLOB Incrementally |
| 6591 ** METHOD: sqlite3_blob |
| 6592 ** |
| 6593 ** ^(This function is used to read data from an open [BLOB handle] into a |
| 6594 ** caller-supplied buffer. N bytes of data are copied into buffer Z |
| 6595 ** from the open BLOB, starting at offset iOffset.)^ |
| 6596 ** |
| 6597 ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
| 6598 ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is |
| 6599 ** less than zero, [SQLITE_ERROR] is returned and no data is read. |
| 6600 ** ^The size of the blob (and hence the maximum value of N+iOffset) |
| 6601 ** can be determined using the [sqlite3_blob_bytes()] interface. |
| 6602 ** |
| 6603 ** ^An attempt to read from an expired [BLOB handle] fails with an |
| 6604 ** error code of [SQLITE_ABORT]. |
| 6605 ** |
| 6606 ** ^(On success, sqlite3_blob_read() returns SQLITE_OK. |
| 6607 ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
| 6608 ** |
| 6609 ** This routine only works on a [BLOB handle] which has been created |
| 6610 ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 6611 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 6612 ** to this routine results in undefined and probably undesirable behavior. |
| 6613 ** |
| 6614 ** See also: [sqlite3_blob_write()]. |
| 6615 */ |
| 6616 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); |
| 6617 |
| 6618 /* |
| 6619 ** CAPI3REF: Write Data Into A BLOB Incrementally |
| 6620 ** METHOD: sqlite3_blob |
| 6621 ** |
| 6622 ** ^(This function is used to write data into an open [BLOB handle] from a |
| 6623 ** caller-supplied buffer. N bytes of data are copied from the buffer Z |
| 6624 ** into the open BLOB, starting at offset iOffset.)^ |
| 6625 ** |
| 6626 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. |
| 6627 ** Otherwise, an [error code] or an [extended error code] is returned.)^ |
| 6628 ** ^Unless SQLITE_MISUSE is returned, this function sets the |
| 6629 ** [database connection] error code and message accessible via |
| 6630 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6631 ** |
| 6632 ** ^If the [BLOB handle] passed as the first argument was not opened for |
| 6633 ** writing (the flags parameter to [sqlite3_blob_open()] was zero), |
| 6634 ** this function returns [SQLITE_READONLY]. |
| 6635 ** |
| 6636 ** This function may only modify the contents of the BLOB; it is |
| 6637 ** not possible to increase the size of a BLOB using this API. |
| 6638 ** ^If offset iOffset is less than N bytes from the end of the BLOB, |
| 6639 ** [SQLITE_ERROR] is returned and no data is written. The size of the |
| 6640 ** BLOB (and hence the maximum value of N+iOffset) can be determined |
| 6641 ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less |
| 6642 ** than zero [SQLITE_ERROR] is returned and no data is written. |
| 6643 ** |
| 6644 ** ^An attempt to write to an expired [BLOB handle] fails with an |
| 6645 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred |
| 6646 ** before the [BLOB handle] expired are not rolled back by the |
| 6647 ** expiration of the handle, though of course those changes might |
| 6648 ** have been overwritten by the statement that expired the BLOB handle |
| 6649 ** or by other independent statements. |
| 6650 ** |
| 6651 ** This routine only works on a [BLOB handle] which has been created |
| 6652 ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 6653 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| 6654 ** to this routine results in undefined and probably undesirable behavior. |
| 6655 ** |
| 6656 ** See also: [sqlite3_blob_read()]. |
| 6657 */ |
| 6658 SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOff
set); |
| 6659 |
| 6660 /* |
| 6661 ** CAPI3REF: Virtual File System Objects |
| 6662 ** |
| 6663 ** A virtual filesystem (VFS) is an [sqlite3_vfs] object |
| 6664 ** that SQLite uses to interact |
| 6665 ** with the underlying operating system. Most SQLite builds come with a |
| 6666 ** single default VFS that is appropriate for the host computer. |
| 6667 ** New VFSes can be registered and existing VFSes can be unregistered. |
| 6668 ** The following interfaces are provided. |
| 6669 ** |
| 6670 ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. |
| 6671 ** ^Names are case sensitive. |
| 6672 ** ^Names are zero-terminated UTF-8 strings. |
| 6673 ** ^If there is no match, a NULL pointer is returned. |
| 6674 ** ^If zVfsName is NULL then the default VFS is returned. |
| 6675 ** |
| 6676 ** ^New VFSes are registered with sqlite3_vfs_register(). |
| 6677 ** ^Each new VFS becomes the default VFS if the makeDflt flag is set. |
| 6678 ** ^The same VFS can be registered multiple times without injury. |
| 6679 ** ^To make an existing VFS into the default VFS, register it again |
| 6680 ** with the makeDflt flag set. If two different VFSes with the |
| 6681 ** same name are registered, the behavior is undefined. If a |
| 6682 ** VFS is registered with a name that is NULL or an empty string, |
| 6683 ** then the behavior is undefined. |
| 6684 ** |
| 6685 ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. |
| 6686 ** ^(If the default VFS is unregistered, another VFS is chosen as |
| 6687 ** the default. The choice for the new VFS is arbitrary.)^ |
| 6688 */ |
| 6689 SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); |
| 6690 SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); |
| 6691 SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); |
| 6692 |
| 6693 /* |
| 6694 ** CAPI3REF: Mutexes |
| 6695 ** |
| 6696 ** The SQLite core uses these routines for thread |
| 6697 ** synchronization. Though they are intended for internal |
| 6698 ** use by SQLite, code that links against SQLite is |
| 6699 ** permitted to use any of these routines. |
| 6700 ** |
| 6701 ** The SQLite source code contains multiple implementations |
| 6702 ** of these mutex routines. An appropriate implementation |
| 6703 ** is selected automatically at compile-time. The following |
| 6704 ** implementations are available in the SQLite core: |
| 6705 ** |
| 6706 ** <ul> |
| 6707 ** <li> SQLITE_MUTEX_PTHREADS |
| 6708 ** <li> SQLITE_MUTEX_W32 |
| 6709 ** <li> SQLITE_MUTEX_NOOP |
| 6710 ** </ul> |
| 6711 ** |
| 6712 ** The SQLITE_MUTEX_NOOP implementation is a set of routines |
| 6713 ** that does no real locking and is appropriate for use in |
| 6714 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and |
| 6715 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix |
| 6716 ** and Windows. |
| 6717 ** |
| 6718 ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor |
| 6719 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex |
| 6720 ** implementation is included with the library. In this case the |
| 6721 ** application must supply a custom mutex implementation using the |
| 6722 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function |
| 6723 ** before calling sqlite3_initialize() or any other public sqlite3_ |
| 6724 ** function that calls sqlite3_initialize(). |
| 6725 ** |
| 6726 ** ^The sqlite3_mutex_alloc() routine allocates a new |
| 6727 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc() |
| 6728 ** routine returns NULL if it is unable to allocate the requested |
| 6729 ** mutex. The argument to sqlite3_mutex_alloc() must one of these |
| 6730 ** integer constants: |
| 6731 ** |
| 6732 ** <ul> |
| 6733 ** <li> SQLITE_MUTEX_FAST |
| 6734 ** <li> SQLITE_MUTEX_RECURSIVE |
| 6735 ** <li> SQLITE_MUTEX_STATIC_MASTER |
| 6736 ** <li> SQLITE_MUTEX_STATIC_MEM |
| 6737 ** <li> SQLITE_MUTEX_STATIC_OPEN |
| 6738 ** <li> SQLITE_MUTEX_STATIC_PRNG |
| 6739 ** <li> SQLITE_MUTEX_STATIC_LRU |
| 6740 ** <li> SQLITE_MUTEX_STATIC_PMEM |
| 6741 ** <li> SQLITE_MUTEX_STATIC_APP1 |
| 6742 ** <li> SQLITE_MUTEX_STATIC_APP2 |
| 6743 ** <li> SQLITE_MUTEX_STATIC_APP3 |
| 6744 ** <li> SQLITE_MUTEX_STATIC_VFS1 |
| 6745 ** <li> SQLITE_MUTEX_STATIC_VFS2 |
| 6746 ** <li> SQLITE_MUTEX_STATIC_VFS3 |
| 6747 ** </ul> |
| 6748 ** |
| 6749 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) |
| 6750 ** cause sqlite3_mutex_alloc() to create |
| 6751 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE |
| 6752 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. |
| 6753 ** The mutex implementation does not need to make a distinction |
| 6754 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does |
| 6755 ** not want to. SQLite will only request a recursive mutex in |
| 6756 ** cases where it really needs one. If a faster non-recursive mutex |
| 6757 ** implementation is available on the host platform, the mutex subsystem |
| 6758 ** might return such a mutex in response to SQLITE_MUTEX_FAST. |
| 6759 ** |
| 6760 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other |
| 6761 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return |
| 6762 ** a pointer to a static preexisting mutex. ^Nine static mutexes are |
| 6763 ** used by the current version of SQLite. Future versions of SQLite |
| 6764 ** may add additional static mutexes. Static mutexes are for internal |
| 6765 ** use by SQLite only. Applications that use SQLite mutexes should |
| 6766 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or |
| 6767 ** SQLITE_MUTEX_RECURSIVE. |
| 6768 ** |
| 6769 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST |
| 6770 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() |
| 6771 ** returns a different mutex on every call. ^For the static |
| 6772 ** mutex types, the same mutex is returned on every call that has |
| 6773 ** the same type number. |
| 6774 ** |
| 6775 ** ^The sqlite3_mutex_free() routine deallocates a previously |
| 6776 ** allocated dynamic mutex. Attempting to deallocate a static |
| 6777 ** mutex results in undefined behavior. |
| 6778 ** |
| 6779 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt |
| 6780 ** to enter a mutex. ^If another thread is already within the mutex, |
| 6781 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return |
| 6782 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] |
| 6783 ** upon successful entry. ^(Mutexes created using |
| 6784 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. |
| 6785 ** In such cases, the |
| 6786 ** mutex must be exited an equal number of times before another thread |
| 6787 ** can enter.)^ If the same thread tries to enter any mutex other |
| 6788 ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined. |
| 6789 ** |
| 6790 ** ^(Some systems (for example, Windows 95) do not support the operation |
| 6791 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() |
| 6792 ** will always return SQLITE_BUSY. The SQLite core only ever uses |
| 6793 ** sqlite3_mutex_try() as an optimization so this is acceptable |
| 6794 ** behavior.)^ |
| 6795 ** |
| 6796 ** ^The sqlite3_mutex_leave() routine exits a mutex that was |
| 6797 ** previously entered by the same thread. The behavior |
| 6798 ** is undefined if the mutex is not currently entered by the |
| 6799 ** calling thread or is not currently allocated. |
| 6800 ** |
| 6801 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or |
| 6802 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines |
| 6803 ** behave as no-ops. |
| 6804 ** |
| 6805 ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. |
| 6806 */ |
| 6807 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); |
| 6808 SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); |
| 6809 SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); |
| 6810 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); |
| 6811 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); |
| 6812 |
| 6813 /* |
| 6814 ** CAPI3REF: Mutex Methods Object |
| 6815 ** |
| 6816 ** An instance of this structure defines the low-level routines |
| 6817 ** used to allocate and use mutexes. |
| 6818 ** |
| 6819 ** Usually, the default mutex implementations provided by SQLite are |
| 6820 ** sufficient, however the application has the option of substituting a custom |
| 6821 ** implementation for specialized deployments or systems for which SQLite |
| 6822 ** does not provide a suitable implementation. In this case, the application |
| 6823 ** creates and populates an instance of this structure to pass |
| 6824 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. |
| 6825 ** Additionally, an instance of this structure can be used as an |
| 6826 ** output variable when querying the system for the current mutex |
| 6827 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. |
| 6828 ** |
| 6829 ** ^The xMutexInit method defined by this structure is invoked as |
| 6830 ** part of system initialization by the sqlite3_initialize() function. |
| 6831 ** ^The xMutexInit routine is called by SQLite exactly once for each |
| 6832 ** effective call to [sqlite3_initialize()]. |
| 6833 ** |
| 6834 ** ^The xMutexEnd method defined by this structure is invoked as |
| 6835 ** part of system shutdown by the sqlite3_shutdown() function. The |
| 6836 ** implementation of this method is expected to release all outstanding |
| 6837 ** resources obtained by the mutex methods implementation, especially |
| 6838 ** those obtained by the xMutexInit method. ^The xMutexEnd() |
| 6839 ** interface is invoked exactly once for each call to [sqlite3_shutdown()]. |
| 6840 ** |
| 6841 ** ^(The remaining seven methods defined by this structure (xMutexAlloc, |
| 6842 ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and |
| 6843 ** xMutexNotheld) implement the following interfaces (respectively): |
| 6844 ** |
| 6845 ** <ul> |
| 6846 ** <li> [sqlite3_mutex_alloc()] </li> |
| 6847 ** <li> [sqlite3_mutex_free()] </li> |
| 6848 ** <li> [sqlite3_mutex_enter()] </li> |
| 6849 ** <li> [sqlite3_mutex_try()] </li> |
| 6850 ** <li> [sqlite3_mutex_leave()] </li> |
| 6851 ** <li> [sqlite3_mutex_held()] </li> |
| 6852 ** <li> [sqlite3_mutex_notheld()] </li> |
| 6853 ** </ul>)^ |
| 6854 ** |
| 6855 ** The only difference is that the public sqlite3_XXX functions enumerated |
| 6856 ** above silently ignore any invocations that pass a NULL pointer instead |
| 6857 ** of a valid mutex handle. The implementations of the methods defined |
| 6858 ** by this structure are not required to handle this case, the results |
| 6859 ** of passing a NULL pointer instead of a valid mutex handle are undefined |
| 6860 ** (i.e. it is acceptable to provide an implementation that segfaults if |
| 6861 ** it is passed a NULL pointer). |
| 6862 ** |
| 6863 ** The xMutexInit() method must be threadsafe. It must be harmless to |
| 6864 ** invoke xMutexInit() multiple times within the same process and without |
| 6865 ** intervening calls to xMutexEnd(). Second and subsequent calls to |
| 6866 ** xMutexInit() must be no-ops. |
| 6867 ** |
| 6868 ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] |
| 6869 ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory |
| 6870 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite |
| 6871 ** memory allocation for a fast or recursive mutex. |
| 6872 ** |
| 6873 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is |
| 6874 ** called, but only if the prior call to xMutexInit returned SQLITE_OK. |
| 6875 ** If xMutexInit fails in any way, it is expected to clean up after itself |
| 6876 ** prior to returning. |
| 6877 */ |
| 6878 typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; |
| 6879 struct sqlite3_mutex_methods { |
| 6880 int (*xMutexInit)(void); |
| 6881 int (*xMutexEnd)(void); |
| 6882 sqlite3_mutex *(*xMutexAlloc)(int); |
| 6883 void (*xMutexFree)(sqlite3_mutex *); |
| 6884 void (*xMutexEnter)(sqlite3_mutex *); |
| 6885 int (*xMutexTry)(sqlite3_mutex *); |
| 6886 void (*xMutexLeave)(sqlite3_mutex *); |
| 6887 int (*xMutexHeld)(sqlite3_mutex *); |
| 6888 int (*xMutexNotheld)(sqlite3_mutex *); |
| 6889 }; |
| 6890 |
| 6891 /* |
| 6892 ** CAPI3REF: Mutex Verification Routines |
| 6893 ** |
| 6894 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines |
| 6895 ** are intended for use inside assert() statements. The SQLite core |
| 6896 ** never uses these routines except inside an assert() and applications |
| 6897 ** are advised to follow the lead of the core. The SQLite core only |
| 6898 ** provides implementations for these routines when it is compiled |
| 6899 ** with the SQLITE_DEBUG flag. External mutex implementations |
| 6900 ** are only required to provide these routines if SQLITE_DEBUG is |
| 6901 ** defined and if NDEBUG is not defined. |
| 6902 ** |
| 6903 ** These routines should return true if the mutex in their argument |
| 6904 ** is held or not held, respectively, by the calling thread. |
| 6905 ** |
| 6906 ** The implementation is not required to provide versions of these |
| 6907 ** routines that actually work. If the implementation does not provide working |
| 6908 ** versions of these routines, it should at least provide stubs that always |
| 6909 ** return true so that one does not get spurious assertion failures. |
| 6910 ** |
| 6911 ** If the argument to sqlite3_mutex_held() is a NULL pointer then |
| 6912 ** the routine should return 1. This seems counter-intuitive since |
| 6913 ** clearly the mutex cannot be held if it does not exist. But |
| 6914 ** the reason the mutex does not exist is because the build is not |
| 6915 ** using mutexes. And we do not want the assert() containing the |
| 6916 ** call to sqlite3_mutex_held() to fail, so a non-zero return is |
| 6917 ** the appropriate thing to do. The sqlite3_mutex_notheld() |
| 6918 ** interface should also return 1 when given a NULL pointer. |
| 6919 */ |
| 6920 #ifndef NDEBUG |
| 6921 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); |
| 6922 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); |
| 6923 #endif |
| 6924 |
| 6925 /* |
| 6926 ** CAPI3REF: Mutex Types |
| 6927 ** |
| 6928 ** The [sqlite3_mutex_alloc()] interface takes a single argument |
| 6929 ** which is one of these integer constants. |
| 6930 ** |
| 6931 ** The set of static mutexes may change from one SQLite release to the |
| 6932 ** next. Applications that override the built-in mutex logic must be |
| 6933 ** prepared to accommodate additional static mutexes. |
| 6934 */ |
| 6935 #define SQLITE_MUTEX_FAST 0 |
| 6936 #define SQLITE_MUTEX_RECURSIVE 1 |
| 6937 #define SQLITE_MUTEX_STATIC_MASTER 2 |
| 6938 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ |
| 6939 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ |
| 6940 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ |
| 6941 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ |
| 6942 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ |
| 6943 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ |
| 6944 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ |
| 6945 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */ |
| 6946 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ |
| 6947 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ |
| 6948 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ |
| 6949 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ |
| 6950 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ |
| 6951 |
| 6952 /* |
| 6953 ** CAPI3REF: Retrieve the mutex for a database connection |
| 6954 ** METHOD: sqlite3 |
| 6955 ** |
| 6956 ** ^This interface returns a pointer the [sqlite3_mutex] object that |
| 6957 ** serializes access to the [database connection] given in the argument |
| 6958 ** when the [threading mode] is Serialized. |
| 6959 ** ^If the [threading mode] is Single-thread or Multi-thread then this |
| 6960 ** routine returns a NULL pointer. |
| 6961 */ |
| 6962 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); |
| 6963 |
| 6964 /* |
| 6965 ** CAPI3REF: Low-Level Control Of Database Files |
| 6966 ** METHOD: sqlite3 |
| 6967 ** |
| 6968 ** ^The [sqlite3_file_control()] interface makes a direct call to the |
| 6969 ** xFileControl method for the [sqlite3_io_methods] object associated |
| 6970 ** with a particular database identified by the second argument. ^The |
| 6971 ** name of the database is "main" for the main database or "temp" for the |
| 6972 ** TEMP database, or the name that appears after the AS keyword for |
| 6973 ** databases that are added using the [ATTACH] SQL command. |
| 6974 ** ^A NULL pointer can be used in place of "main" to refer to the |
| 6975 ** main database file. |
| 6976 ** ^The third and fourth parameters to this routine |
| 6977 ** are passed directly through to the second and third parameters of |
| 6978 ** the xFileControl method. ^The return value of the xFileControl |
| 6979 ** method becomes the return value of this routine. |
| 6980 ** |
| 6981 ** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes |
| 6982 ** a pointer to the underlying [sqlite3_file] object to be written into |
| 6983 ** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER |
| 6984 ** case is a short-circuit path which does not actually invoke the |
| 6985 ** underlying sqlite3_io_methods.xFileControl method. |
| 6986 ** |
| 6987 ** ^If the second parameter (zDbName) does not match the name of any |
| 6988 ** open database file, then SQLITE_ERROR is returned. ^This error |
| 6989 ** code is not remembered and will not be recalled by [sqlite3_errcode()] |
| 6990 ** or [sqlite3_errmsg()]. The underlying xFileControl method might |
| 6991 ** also return SQLITE_ERROR. There is no way to distinguish between |
| 6992 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying |
| 6993 ** xFileControl method. |
| 6994 ** |
| 6995 ** See also: [SQLITE_FCNTL_LOCKSTATE] |
| 6996 */ |
| 6997 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*
); |
| 6998 |
| 6999 /* |
| 7000 ** CAPI3REF: Testing Interface |
| 7001 ** |
| 7002 ** ^The sqlite3_test_control() interface is used to read out internal |
| 7003 ** state of SQLite and to inject faults into SQLite for testing |
| 7004 ** purposes. ^The first parameter is an operation code that determines |
| 7005 ** the number, meaning, and operation of all subsequent parameters. |
| 7006 ** |
| 7007 ** This interface is not for use by applications. It exists solely |
| 7008 ** for verifying the correct operation of the SQLite library. Depending |
| 7009 ** on how the SQLite library is compiled, this interface might not exist. |
| 7010 ** |
| 7011 ** The details of the operation codes, their meanings, the parameters |
| 7012 ** they take, and what they do are all subject to change without notice. |
| 7013 ** Unlike most of the SQLite API, this function is not guaranteed to |
| 7014 ** operate consistently from one release to the next. |
| 7015 */ |
| 7016 SQLITE_API int sqlite3_test_control(int op, ...); |
| 7017 |
| 7018 /* |
| 7019 ** CAPI3REF: Testing Interface Operation Codes |
| 7020 ** |
| 7021 ** These constants are the valid operation code parameters used |
| 7022 ** as the first argument to [sqlite3_test_control()]. |
| 7023 ** |
| 7024 ** These parameters and their meanings are subject to change |
| 7025 ** without notice. These values are for testing purposes only. |
| 7026 ** Applications should not use any of these parameters or the |
| 7027 ** [sqlite3_test_control()] interface. |
| 7028 */ |
| 7029 #define SQLITE_TESTCTRL_FIRST 5 |
| 7030 #define SQLITE_TESTCTRL_PRNG_SAVE 5 |
| 7031 #define SQLITE_TESTCTRL_PRNG_RESTORE 6 |
| 7032 #define SQLITE_TESTCTRL_PRNG_RESET 7 |
| 7033 #define SQLITE_TESTCTRL_BITVEC_TEST 8 |
| 7034 #define SQLITE_TESTCTRL_FAULT_INSTALL 9 |
| 7035 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 |
| 7036 #define SQLITE_TESTCTRL_PENDING_BYTE 11 |
| 7037 #define SQLITE_TESTCTRL_ASSERT 12 |
| 7038 #define SQLITE_TESTCTRL_ALWAYS 13 |
| 7039 #define SQLITE_TESTCTRL_RESERVE 14 |
| 7040 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 |
| 7041 #define SQLITE_TESTCTRL_ISKEYWORD 16 |
| 7042 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 |
| 7043 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 |
| 7044 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ |
| 7045 #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 |
| 7046 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 |
| 7047 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21 |
| 7048 #define SQLITE_TESTCTRL_BYTEORDER 22 |
| 7049 #define SQLITE_TESTCTRL_ISINIT 23 |
| 7050 #define SQLITE_TESTCTRL_SORTER_MMAP 24 |
| 7051 #define SQLITE_TESTCTRL_IMPOSTER 25 |
| 7052 #define SQLITE_TESTCTRL_LAST 25 |
| 7053 |
| 7054 /* |
| 7055 ** CAPI3REF: SQLite Runtime Status |
| 7056 ** |
| 7057 ** ^These interfaces are used to retrieve runtime status information |
| 7058 ** about the performance of SQLite, and optionally to reset various |
| 7059 ** highwater marks. ^The first argument is an integer code for |
| 7060 ** the specific parameter to measure. ^(Recognized integer codes |
| 7061 ** are of the form [status parameters | SQLITE_STATUS_...].)^ |
| 7062 ** ^The current value of the parameter is returned into *pCurrent. |
| 7063 ** ^The highest recorded value is returned in *pHighwater. ^If the |
| 7064 ** resetFlag is true, then the highest record value is reset after |
| 7065 ** *pHighwater is written. ^(Some parameters do not record the highest |
| 7066 ** value. For those parameters |
| 7067 ** nothing is written into *pHighwater and the resetFlag is ignored.)^ |
| 7068 ** ^(Other parameters record only the highwater mark and not the current |
| 7069 ** value. For these latter parameters nothing is written into *pCurrent.)^ |
| 7070 ** |
| 7071 ** ^The sqlite3_status() and sqlite3_status64() routines return |
| 7072 ** SQLITE_OK on success and a non-zero [error code] on failure. |
| 7073 ** |
| 7074 ** If either the current value or the highwater mark is too large to |
| 7075 ** be represented by a 32-bit integer, then the values returned by |
| 7076 ** sqlite3_status() are undefined. |
| 7077 ** |
| 7078 ** See also: [sqlite3_db_status()] |
| 7079 */ |
| 7080 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
lag); |
| 7081 SQLITE_API int sqlite3_status64( |
| 7082 int op, |
| 7083 sqlite3_int64 *pCurrent, |
| 7084 sqlite3_int64 *pHighwater, |
| 7085 int resetFlag |
| 7086 ); |
| 7087 |
| 7088 |
| 7089 /* |
| 7090 ** CAPI3REF: Status Parameters |
| 7091 ** KEYWORDS: {status parameters} |
| 7092 ** |
| 7093 ** These integer constants designate various run-time status parameters |
| 7094 ** that can be returned by [sqlite3_status()]. |
| 7095 ** |
| 7096 ** <dl> |
| 7097 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> |
| 7098 ** <dd>This parameter is the current amount of memory checked out |
| 7099 ** using [sqlite3_malloc()], either directly or indirectly. The |
| 7100 ** figure includes calls made to [sqlite3_malloc()] by the application |
| 7101 ** and internal memory usage by the SQLite library. Scratch memory |
| 7102 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache |
| 7103 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in |
| 7104 ** this parameter. The amount returned is the sum of the allocation |
| 7105 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ |
| 7106 ** |
| 7107 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> |
| 7108 ** <dd>This parameter records the largest memory allocation request |
| 7109 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their |
| 7110 ** internal equivalents). Only the value returned in the |
| 7111 ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 7112 ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 7113 ** |
| 7114 ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> |
| 7115 ** <dd>This parameter records the number of separate memory allocations |
| 7116 ** currently checked out.</dd>)^ |
| 7117 ** |
| 7118 ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> |
| 7119 ** <dd>This parameter returns the number of pages used out of the |
| 7120 ** [pagecache memory allocator] that was configured using |
| 7121 ** [SQLITE_CONFIG_PAGECACHE]. The |
| 7122 ** value returned is in pages, not in bytes.</dd>)^ |
| 7123 ** |
| 7124 ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] |
| 7125 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> |
| 7126 ** <dd>This parameter returns the number of bytes of page cache |
| 7127 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] |
| 7128 ** buffer and where forced to overflow to [sqlite3_malloc()]. The |
| 7129 ** returned value includes allocations that overflowed because they |
| 7130 ** where too large (they were larger than the "sz" parameter to |
| 7131 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because |
| 7132 ** no space was left in the page cache.</dd>)^ |
| 7133 ** |
| 7134 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> |
| 7135 ** <dd>This parameter records the largest memory allocation request |
| 7136 ** handed to [pagecache memory allocator]. Only the value returned in the |
| 7137 ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 7138 ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 7139 ** |
| 7140 ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> |
| 7141 ** <dd>This parameter returns the number of allocations used out of the |
| 7142 ** [scratch memory allocator] configured using |
| 7143 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not |
| 7144 ** in bytes. Since a single thread may only have one scratch allocation |
| 7145 ** outstanding at time, this parameter also reports the number of threads |
| 7146 ** using scratch memory at the same time.</dd>)^ |
| 7147 ** |
| 7148 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> |
| 7149 ** <dd>This parameter returns the number of bytes of scratch memory |
| 7150 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] |
| 7151 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values |
| 7152 ** returned include overflows because the requested allocation was too |
| 7153 ** larger (that is, because the requested allocation was larger than the |
| 7154 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer |
| 7155 ** slots were available. |
| 7156 ** </dd>)^ |
| 7157 ** |
| 7158 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> |
| 7159 ** <dd>This parameter records the largest memory allocation request |
| 7160 ** handed to [scratch memory allocator]. Only the value returned in the |
| 7161 ** *pHighwater parameter to [sqlite3_status()] is of interest. |
| 7162 ** The value written into the *pCurrent parameter is undefined.</dd>)^ |
| 7163 ** |
| 7164 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> |
| 7165 ** <dd>The *pHighwater parameter records the deepest parser stack. |
| 7166 ** The *pCurrent value is undefined. The *pHighwater value is only |
| 7167 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ |
| 7168 ** </dl> |
| 7169 ** |
| 7170 ** New status parameters may be added from time to time. |
| 7171 */ |
| 7172 #define SQLITE_STATUS_MEMORY_USED 0 |
| 7173 #define SQLITE_STATUS_PAGECACHE_USED 1 |
| 7174 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 |
| 7175 #define SQLITE_STATUS_SCRATCH_USED 3 |
| 7176 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 |
| 7177 #define SQLITE_STATUS_MALLOC_SIZE 5 |
| 7178 #define SQLITE_STATUS_PARSER_STACK 6 |
| 7179 #define SQLITE_STATUS_PAGECACHE_SIZE 7 |
| 7180 #define SQLITE_STATUS_SCRATCH_SIZE 8 |
| 7181 #define SQLITE_STATUS_MALLOC_COUNT 9 |
| 7182 |
| 7183 /* |
| 7184 ** CAPI3REF: Database Connection Status |
| 7185 ** METHOD: sqlite3 |
| 7186 ** |
| 7187 ** ^This interface is used to retrieve runtime status information |
| 7188 ** about a single [database connection]. ^The first argument is the |
| 7189 ** database connection object to be interrogated. ^The second argument |
| 7190 ** is an integer constant, taken from the set of |
| 7191 ** [SQLITE_DBSTATUS options], that |
| 7192 ** determines the parameter to interrogate. The set of |
| 7193 ** [SQLITE_DBSTATUS options] is likely |
| 7194 ** to grow in future releases of SQLite. |
| 7195 ** |
| 7196 ** ^The current value of the requested parameter is written into *pCur |
| 7197 ** and the highest instantaneous value is written into *pHiwtr. ^If |
| 7198 ** the resetFlg is true, then the highest instantaneous value is |
| 7199 ** reset back down to the current value. |
| 7200 ** |
| 7201 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a |
| 7202 ** non-zero [error code] on failure. |
| 7203 ** |
| 7204 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. |
| 7205 */ |
| 7206 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
esetFlg); |
| 7207 |
| 7208 /* |
| 7209 ** CAPI3REF: Status Parameters for database connections |
| 7210 ** KEYWORDS: {SQLITE_DBSTATUS options} |
| 7211 ** |
| 7212 ** These constants are the available integer "verbs" that can be passed as |
| 7213 ** the second argument to the [sqlite3_db_status()] interface. |
| 7214 ** |
| 7215 ** New verbs may be added in future releases of SQLite. Existing verbs |
| 7216 ** might be discontinued. Applications should check the return code from |
| 7217 ** [sqlite3_db_status()] to make sure that the call worked. |
| 7218 ** The [sqlite3_db_status()] interface will return a non-zero error code |
| 7219 ** if a discontinued or unsupported verb is invoked. |
| 7220 ** |
| 7221 ** <dl> |
| 7222 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> |
| 7223 ** <dd>This parameter returns the number of lookaside memory slots currently |
| 7224 ** checked out.</dd>)^ |
| 7225 ** |
| 7226 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> |
| 7227 ** <dd>This parameter returns the number malloc attempts that were |
| 7228 ** satisfied using lookaside memory. Only the high-water value is meaningful; |
| 7229 ** the current value is always zero.)^ |
| 7230 ** |
| 7231 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] |
| 7232 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> |
| 7233 ** <dd>This parameter returns the number malloc attempts that might have |
| 7234 ** been satisfied using lookaside memory but failed due to the amount of |
| 7235 ** memory requested being larger than the lookaside slot size. |
| 7236 ** Only the high-water value is meaningful; |
| 7237 ** the current value is always zero.)^ |
| 7238 ** |
| 7239 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] |
| 7240 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> |
| 7241 ** <dd>This parameter returns the number malloc attempts that might have |
| 7242 ** been satisfied using lookaside memory but failed due to all lookaside |
| 7243 ** memory already being in use. |
| 7244 ** Only the high-water value is meaningful; |
| 7245 ** the current value is always zero.)^ |
| 7246 ** |
| 7247 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> |
| 7248 ** <dd>This parameter returns the approximate number of bytes of heap |
| 7249 ** memory used by all pager caches associated with the database connection.)^ |
| 7250 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. |
| 7251 ** |
| 7252 ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]] |
| 7253 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt> |
| 7254 ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a |
| 7255 ** pager cache is shared between two or more connections the bytes of heap |
| 7256 ** memory used by that pager cache is divided evenly between the attached |
| 7257 ** connections.)^ In other words, if none of the pager caches associated |
| 7258 ** with the database connection are shared, this request returns the same |
| 7259 ** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are |
| 7260 ** shared, the value returned by this call will be smaller than that returned |
| 7261 ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with |
| 7262 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0. |
| 7263 ** |
| 7264 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> |
| 7265 ** <dd>This parameter returns the approximate number of bytes of heap |
| 7266 ** memory used to store the schema for all databases associated |
| 7267 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ |
| 7268 ** ^The full amount of memory used by the schemas is reported, even if the |
| 7269 ** schema memory is shared with other database connections due to |
| 7270 ** [shared cache mode] being enabled. |
| 7271 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. |
| 7272 ** |
| 7273 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> |
| 7274 ** <dd>This parameter returns the approximate number of bytes of heap |
| 7275 ** and lookaside memory used by all prepared statements associated with |
| 7276 ** the database connection.)^ |
| 7277 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. |
| 7278 ** </dd> |
| 7279 ** |
| 7280 ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt> |
| 7281 ** <dd>This parameter returns the number of pager cache hits that have |
| 7282 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT |
| 7283 ** is always 0. |
| 7284 ** </dd> |
| 7285 ** |
| 7286 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> |
| 7287 ** <dd>This parameter returns the number of pager cache misses that have |
| 7288 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS |
| 7289 ** is always 0. |
| 7290 ** </dd> |
| 7291 ** |
| 7292 ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt> |
| 7293 ** <dd>This parameter returns the number of dirty cache entries that have |
| 7294 ** been written to disk. Specifically, the number of pages written to the |
| 7295 ** wal file in wal mode databases, or the number of pages written to the |
| 7296 ** database file in rollback mode databases. Any pages written as part of |
| 7297 ** transaction rollback or database recovery operations are not included. |
| 7298 ** If an IO or other error occurs while writing a page to disk, the effect |
| 7299 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The |
| 7300 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. |
| 7301 ** </dd> |
| 7302 ** |
| 7303 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt> |
| 7304 ** <dd>This parameter returns zero for the current value if and only if |
| 7305 ** all foreign key constraints (deferred or immediate) have been |
| 7306 ** resolved.)^ ^The highwater mark is always 0. |
| 7307 ** </dd> |
| 7308 ** </dl> |
| 7309 */ |
| 7310 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 |
| 7311 #define SQLITE_DBSTATUS_CACHE_USED 1 |
| 7312 #define SQLITE_DBSTATUS_SCHEMA_USED 2 |
| 7313 #define SQLITE_DBSTATUS_STMT_USED 3 |
| 7314 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 |
| 7315 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 |
| 7316 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 |
| 7317 #define SQLITE_DBSTATUS_CACHE_HIT 7 |
| 7318 #define SQLITE_DBSTATUS_CACHE_MISS 8 |
| 7319 #define SQLITE_DBSTATUS_CACHE_WRITE 9 |
| 7320 #define SQLITE_DBSTATUS_DEFERRED_FKS 10 |
| 7321 #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 |
| 7322 #define SQLITE_DBSTATUS_MAX 11 /* Largest defined DBSTATUS */ |
| 7323 |
| 7324 |
| 7325 /* |
| 7326 ** CAPI3REF: Prepared Statement Status |
| 7327 ** METHOD: sqlite3_stmt |
| 7328 ** |
| 7329 ** ^(Each prepared statement maintains various |
| 7330 ** [SQLITE_STMTSTATUS counters] that measure the number |
| 7331 ** of times it has performed specific operations.)^ These counters can |
| 7332 ** be used to monitor the performance characteristics of the prepared |
| 7333 ** statements. For example, if the number of table steps greatly exceeds |
| 7334 ** the number of table searches or result rows, that would tend to indicate |
| 7335 ** that the prepared statement is using a full table scan rather than |
| 7336 ** an index. |
| 7337 ** |
| 7338 ** ^(This interface is used to retrieve and reset counter values from |
| 7339 ** a [prepared statement]. The first argument is the prepared statement |
| 7340 ** object to be interrogated. The second argument |
| 7341 ** is an integer code for a specific [SQLITE_STMTSTATUS counter] |
| 7342 ** to be interrogated.)^ |
| 7343 ** ^The current value of the requested counter is returned. |
| 7344 ** ^If the resetFlg is true, then the counter is reset to zero after this |
| 7345 ** interface call returns. |
| 7346 ** |
| 7347 ** See also: [sqlite3_status()] and [sqlite3_db_status()]. |
| 7348 */ |
| 7349 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); |
| 7350 |
| 7351 /* |
| 7352 ** CAPI3REF: Status Parameters for prepared statements |
| 7353 ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} |
| 7354 ** |
| 7355 ** These preprocessor macros define integer codes that name counter |
| 7356 ** values associated with the [sqlite3_stmt_status()] interface. |
| 7357 ** The meanings of the various counters are as follows: |
| 7358 ** |
| 7359 ** <dl> |
| 7360 ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> |
| 7361 ** <dd>^This is the number of times that SQLite has stepped forward in |
| 7362 ** a table as part of a full table scan. Large numbers for this counter |
| 7363 ** may indicate opportunities for performance improvement through |
| 7364 ** careful use of indices.</dd> |
| 7365 ** |
| 7366 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> |
| 7367 ** <dd>^This is the number of sort operations that have occurred. |
| 7368 ** A non-zero value in this counter may indicate an opportunity to |
| 7369 ** improvement performance through careful use of indices.</dd> |
| 7370 ** |
| 7371 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> |
| 7372 ** <dd>^This is the number of rows inserted into transient indices that |
| 7373 ** were created automatically in order to help joins run faster. |
| 7374 ** A non-zero value in this counter may indicate an opportunity to |
| 7375 ** improvement performance by adding permanent indices that do not |
| 7376 ** need to be reinitialized each time the statement is run.</dd> |
| 7377 ** |
| 7378 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt> |
| 7379 ** <dd>^This is the number of virtual machine operations executed |
| 7380 ** by the prepared statement if that number is less than or equal |
| 7381 ** to 2147483647. The number of virtual machine operations can be |
| 7382 ** used as a proxy for the total work done by the prepared statement. |
| 7383 ** If the number of virtual machine operations exceeds 2147483647 |
| 7384 ** then the value returned by this statement status code is undefined. |
| 7385 ** </dd> |
| 7386 ** </dl> |
| 7387 */ |
| 7388 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 |
| 7389 #define SQLITE_STMTSTATUS_SORT 2 |
| 7390 #define SQLITE_STMTSTATUS_AUTOINDEX 3 |
| 7391 #define SQLITE_STMTSTATUS_VM_STEP 4 |
| 7392 |
| 7393 /* |
| 7394 ** CAPI3REF: Custom Page Cache Object |
| 7395 ** |
| 7396 ** The sqlite3_pcache type is opaque. It is implemented by |
| 7397 ** the pluggable module. The SQLite core has no knowledge of |
| 7398 ** its size or internal structure and never deals with the |
| 7399 ** sqlite3_pcache object except by holding and passing pointers |
| 7400 ** to the object. |
| 7401 ** |
| 7402 ** See [sqlite3_pcache_methods2] for additional information. |
| 7403 */ |
| 7404 typedef struct sqlite3_pcache sqlite3_pcache; |
| 7405 |
| 7406 /* |
| 7407 ** CAPI3REF: Custom Page Cache Object |
| 7408 ** |
| 7409 ** The sqlite3_pcache_page object represents a single page in the |
| 7410 ** page cache. The page cache will allocate instances of this |
| 7411 ** object. Various methods of the page cache use pointers to instances |
| 7412 ** of this object as parameters or as their return value. |
| 7413 ** |
| 7414 ** See [sqlite3_pcache_methods2] for additional information. |
| 7415 */ |
| 7416 typedef struct sqlite3_pcache_page sqlite3_pcache_page; |
| 7417 struct sqlite3_pcache_page { |
| 7418 void *pBuf; /* The content of the page */ |
| 7419 void *pExtra; /* Extra information associated with the page */ |
| 7420 }; |
| 7421 |
| 7422 /* |
| 7423 ** CAPI3REF: Application Defined Page Cache. |
| 7424 ** KEYWORDS: {page cache} |
| 7425 ** |
| 7426 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can |
| 7427 ** register an alternative page cache implementation by passing in an |
| 7428 ** instance of the sqlite3_pcache_methods2 structure.)^ |
| 7429 ** In many applications, most of the heap memory allocated by |
| 7430 ** SQLite is used for the page cache. |
| 7431 ** By implementing a |
| 7432 ** custom page cache using this API, an application can better control |
| 7433 ** the amount of memory consumed by SQLite, the way in which |
| 7434 ** that memory is allocated and released, and the policies used to |
| 7435 ** determine exactly which parts of a database file are cached and for |
| 7436 ** how long. |
| 7437 ** |
| 7438 ** The alternative page cache mechanism is an |
| 7439 ** extreme measure that is only needed by the most demanding applications. |
| 7440 ** The built-in page cache is recommended for most uses. |
| 7441 ** |
| 7442 ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an |
| 7443 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence |
| 7444 ** the application may discard the parameter after the call to |
| 7445 ** [sqlite3_config()] returns.)^ |
| 7446 ** |
| 7447 ** [[the xInit() page cache method]] |
| 7448 ** ^(The xInit() method is called once for each effective |
| 7449 ** call to [sqlite3_initialize()])^ |
| 7450 ** (usually only once during the lifetime of the process). ^(The xInit() |
| 7451 ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^ |
| 7452 ** The intent of the xInit() method is to set up global data structures |
| 7453 ** required by the custom page cache implementation. |
| 7454 ** ^(If the xInit() method is NULL, then the |
| 7455 ** built-in default page cache is used instead of the application defined |
| 7456 ** page cache.)^ |
| 7457 ** |
| 7458 ** [[the xShutdown() page cache method]] |
| 7459 ** ^The xShutdown() method is called by [sqlite3_shutdown()]. |
| 7460 ** It can be used to clean up |
| 7461 ** any outstanding resources before process shutdown, if required. |
| 7462 ** ^The xShutdown() method may be NULL. |
| 7463 ** |
| 7464 ** ^SQLite automatically serializes calls to the xInit method, |
| 7465 ** so the xInit method need not be threadsafe. ^The |
| 7466 ** xShutdown method is only called from [sqlite3_shutdown()] so it does |
| 7467 ** not need to be threadsafe either. All other methods must be threadsafe |
| 7468 ** in multithreaded applications. |
| 7469 ** |
| 7470 ** ^SQLite will never invoke xInit() more than once without an intervening |
| 7471 ** call to xShutdown(). |
| 7472 ** |
| 7473 ** [[the xCreate() page cache methods]] |
| 7474 ** ^SQLite invokes the xCreate() method to construct a new cache instance. |
| 7475 ** SQLite will typically create one cache instance for each open database file, |
| 7476 ** though this is not guaranteed. ^The |
| 7477 ** first parameter, szPage, is the size in bytes of the pages that must |
| 7478 ** be allocated by the cache. ^szPage will always a power of two. ^The |
| 7479 ** second parameter szExtra is a number of bytes of extra storage |
| 7480 ** associated with each page cache entry. ^The szExtra parameter will |
| 7481 ** a number less than 250. SQLite will use the |
| 7482 ** extra szExtra bytes on each page to store metadata about the underlying |
| 7483 ** database page on disk. The value passed into szExtra depends |
| 7484 ** on the SQLite version, the target platform, and how SQLite was compiled. |
| 7485 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being |
| 7486 ** created will be used to cache database pages of a file stored on disk, or |
| 7487 ** false if it is used for an in-memory database. The cache implementation |
| 7488 ** does not have to do anything special based with the value of bPurgeable; |
| 7489 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will |
| 7490 ** never invoke xUnpin() except to deliberately delete a page. |
| 7491 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to |
| 7492 ** false will always have the "discard" flag set to true. |
| 7493 ** ^Hence, a cache created with bPurgeable false will |
| 7494 ** never contain any unpinned pages. |
| 7495 ** |
| 7496 ** [[the xCachesize() page cache method]] |
| 7497 ** ^(The xCachesize() method may be called at any time by SQLite to set the |
| 7498 ** suggested maximum cache-size (number of pages stored by) the cache |
| 7499 ** instance passed as the first argument. This is the value configured using |
| 7500 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable |
| 7501 ** parameter, the implementation is not required to do anything with this |
| 7502 ** value; it is advisory only. |
| 7503 ** |
| 7504 ** [[the xPagecount() page cache methods]] |
| 7505 ** The xPagecount() method must return the number of pages currently |
| 7506 ** stored in the cache, both pinned and unpinned. |
| 7507 ** |
| 7508 ** [[the xFetch() page cache methods]] |
| 7509 ** The xFetch() method locates a page in the cache and returns a pointer to |
| 7510 ** an sqlite3_pcache_page object associated with that page, or a NULL pointer. |
| 7511 ** The pBuf element of the returned sqlite3_pcache_page object will be a |
| 7512 ** pointer to a buffer of szPage bytes used to store the content of a |
| 7513 ** single database page. The pExtra element of sqlite3_pcache_page will be |
| 7514 ** a pointer to the szExtra bytes of extra storage that SQLite has requested |
| 7515 ** for each entry in the page cache. |
| 7516 ** |
| 7517 ** The page to be fetched is determined by the key. ^The minimum key value |
| 7518 ** is 1. After it has been retrieved using xFetch, the page is considered |
| 7519 ** to be "pinned". |
| 7520 ** |
| 7521 ** If the requested page is already in the page cache, then the page cache |
| 7522 ** implementation must return a pointer to the page buffer with its content |
| 7523 ** intact. If the requested page is not already in the cache, then the |
| 7524 ** cache implementation should use the value of the createFlag |
| 7525 ** parameter to help it determined what action to take: |
| 7526 ** |
| 7527 ** <table border=1 width=85% align=center> |
| 7528 ** <tr><th> createFlag <th> Behavior when page is not already in cache |
| 7529 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. |
| 7530 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. |
| 7531 ** Otherwise return NULL. |
| 7532 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return |
| 7533 ** NULL if allocating a new page is effectively impossible. |
| 7534 ** </table> |
| 7535 ** |
| 7536 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite |
| 7537 ** will only use a createFlag of 2 after a prior call with a createFlag of 1 |
| 7538 ** failed.)^ In between the to xFetch() calls, SQLite may |
| 7539 ** attempt to unpin one or more cache pages by spilling the content of |
| 7540 ** pinned pages to disk and synching the operating system disk cache. |
| 7541 ** |
| 7542 ** [[the xUnpin() page cache method]] |
| 7543 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page |
| 7544 ** as its second argument. If the third parameter, discard, is non-zero, |
| 7545 ** then the page must be evicted from the cache. |
| 7546 ** ^If the discard parameter is |
| 7547 ** zero, then the page may be discarded or retained at the discretion of |
| 7548 ** page cache implementation. ^The page cache implementation |
| 7549 ** may choose to evict unpinned pages at any time. |
| 7550 ** |
| 7551 ** The cache must not perform any reference counting. A single |
| 7552 ** call to xUnpin() unpins the page regardless of the number of prior calls |
| 7553 ** to xFetch(). |
| 7554 ** |
| 7555 ** [[the xRekey() page cache methods]] |
| 7556 ** The xRekey() method is used to change the key value associated with the |
| 7557 ** page passed as the second argument. If the cache |
| 7558 ** previously contains an entry associated with newKey, it must be |
| 7559 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not |
| 7560 ** to be pinned. |
| 7561 ** |
| 7562 ** When SQLite calls the xTruncate() method, the cache must discard all |
| 7563 ** existing cache entries with page numbers (keys) greater than or equal |
| 7564 ** to the value of the iLimit parameter passed to xTruncate(). If any |
| 7565 ** of these pages are pinned, they are implicitly unpinned, meaning that |
| 7566 ** they can be safely discarded. |
| 7567 ** |
| 7568 ** [[the xDestroy() page cache method]] |
| 7569 ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). |
| 7570 ** All resources associated with the specified cache should be freed. ^After |
| 7571 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] |
| 7572 ** handle invalid, and will not use it with any other sqlite3_pcache_methods2 |
| 7573 ** functions. |
| 7574 ** |
| 7575 ** [[the xShrink() page cache method]] |
| 7576 ** ^SQLite invokes the xShrink() method when it wants the page cache to |
| 7577 ** free up as much of heap memory as possible. The page cache implementation |
| 7578 ** is not obligated to free any memory, but well-behaved implementations should |
| 7579 ** do their best. |
| 7580 */ |
| 7581 typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2; |
| 7582 struct sqlite3_pcache_methods2 { |
| 7583 int iVersion; |
| 7584 void *pArg; |
| 7585 int (*xInit)(void*); |
| 7586 void (*xShutdown)(void*); |
| 7587 sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable); |
| 7588 void (*xCachesize)(sqlite3_pcache*, int nCachesize); |
| 7589 int (*xPagecount)(sqlite3_pcache*); |
| 7590 sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); |
| 7591 void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard); |
| 7592 void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, |
| 7593 unsigned oldKey, unsigned newKey); |
| 7594 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); |
| 7595 void (*xDestroy)(sqlite3_pcache*); |
| 7596 void (*xShrink)(sqlite3_pcache*); |
| 7597 }; |
| 7598 |
| 7599 /* |
| 7600 ** This is the obsolete pcache_methods object that has now been replaced |
| 7601 ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is |
| 7602 ** retained in the header file for backwards compatibility only. |
| 7603 */ |
| 7604 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; |
| 7605 struct sqlite3_pcache_methods { |
| 7606 void *pArg; |
| 7607 int (*xInit)(void*); |
| 7608 void (*xShutdown)(void*); |
| 7609 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); |
| 7610 void (*xCachesize)(sqlite3_pcache*, int nCachesize); |
| 7611 int (*xPagecount)(sqlite3_pcache*); |
| 7612 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); |
| 7613 void (*xUnpin)(sqlite3_pcache*, void*, int discard); |
| 7614 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); |
| 7615 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); |
| 7616 void (*xDestroy)(sqlite3_pcache*); |
| 7617 }; |
| 7618 |
| 7619 |
| 7620 /* |
| 7621 ** CAPI3REF: Online Backup Object |
| 7622 ** |
| 7623 ** The sqlite3_backup object records state information about an ongoing |
| 7624 ** online backup operation. ^The sqlite3_backup object is created by |
| 7625 ** a call to [sqlite3_backup_init()] and is destroyed by a call to |
| 7626 ** [sqlite3_backup_finish()]. |
| 7627 ** |
| 7628 ** See Also: [Using the SQLite Online Backup API] |
| 7629 */ |
| 7630 typedef struct sqlite3_backup sqlite3_backup; |
| 7631 |
| 7632 /* |
| 7633 ** CAPI3REF: Online Backup API. |
| 7634 ** |
| 7635 ** The backup API copies the content of one database into another. |
| 7636 ** It is useful either for creating backups of databases or |
| 7637 ** for copying in-memory databases to or from persistent files. |
| 7638 ** |
| 7639 ** See Also: [Using the SQLite Online Backup API] |
| 7640 ** |
| 7641 ** ^SQLite holds a write transaction open on the destination database file |
| 7642 ** for the duration of the backup operation. |
| 7643 ** ^The source database is read-locked only while it is being read; |
| 7644 ** it is not locked continuously for the entire backup operation. |
| 7645 ** ^Thus, the backup may be performed on a live source database without |
| 7646 ** preventing other database connections from |
| 7647 ** reading or writing to the source database while the backup is underway. |
| 7648 ** |
| 7649 ** ^(To perform a backup operation: |
| 7650 ** <ol> |
| 7651 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the |
| 7652 ** backup, |
| 7653 ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer |
| 7654 ** the data between the two databases, and finally |
| 7655 ** <li><b>sqlite3_backup_finish()</b> is called to release all resources |
| 7656 ** associated with the backup operation. |
| 7657 ** </ol>)^ |
| 7658 ** There should be exactly one call to sqlite3_backup_finish() for each |
| 7659 ** successful call to sqlite3_backup_init(). |
| 7660 ** |
| 7661 ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> |
| 7662 ** |
| 7663 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the |
| 7664 ** [database connection] associated with the destination database |
| 7665 ** and the database name, respectively. |
| 7666 ** ^The database name is "main" for the main database, "temp" for the |
| 7667 ** temporary database, or the name specified after the AS keyword in |
| 7668 ** an [ATTACH] statement for an attached database. |
| 7669 ** ^The S and M arguments passed to |
| 7670 ** sqlite3_backup_init(D,N,S,M) identify the [database connection] |
| 7671 ** and database name of the source database, respectively. |
| 7672 ** ^The source and destination [database connections] (parameters S and D) |
| 7673 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with |
| 7674 ** an error. |
| 7675 ** |
| 7676 ** ^A call to sqlite3_backup_init() will fail, returning NULL, if |
| 7677 ** there is already a read or read-write transaction open on the |
| 7678 ** destination database. |
| 7679 ** |
| 7680 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is |
| 7681 ** returned and an error code and error message are stored in the |
| 7682 ** destination [database connection] D. |
| 7683 ** ^The error code and message for the failed call to sqlite3_backup_init() |
| 7684 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or |
| 7685 ** [sqlite3_errmsg16()] functions. |
| 7686 ** ^A successful call to sqlite3_backup_init() returns a pointer to an |
| 7687 ** [sqlite3_backup] object. |
| 7688 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and |
| 7689 ** sqlite3_backup_finish() functions to perform the specified backup |
| 7690 ** operation. |
| 7691 ** |
| 7692 ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> |
| 7693 ** |
| 7694 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between |
| 7695 ** the source and destination databases specified by [sqlite3_backup] object B. |
| 7696 ** ^If N is negative, all remaining source pages are copied. |
| 7697 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there |
| 7698 ** are still more pages to be copied, then the function returns [SQLITE_OK]. |
| 7699 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages |
| 7700 ** from source to destination, then it returns [SQLITE_DONE]. |
| 7701 ** ^If an error occurs while running sqlite3_backup_step(B,N), |
| 7702 ** then an [error code] is returned. ^As well as [SQLITE_OK] and |
| 7703 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], |
| 7704 ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an |
| 7705 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. |
| 7706 ** |
| 7707 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if |
| 7708 ** <ol> |
| 7709 ** <li> the destination database was opened read-only, or |
| 7710 ** <li> the destination database is using write-ahead-log journaling |
| 7711 ** and the destination and source page sizes differ, or |
| 7712 ** <li> the destination database is an in-memory database and the |
| 7713 ** destination and source page sizes differ. |
| 7714 ** </ol>)^ |
| 7715 ** |
| 7716 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then |
| 7717 ** the [sqlite3_busy_handler | busy-handler function] |
| 7718 ** is invoked (if one is specified). ^If the |
| 7719 ** busy-handler returns non-zero before the lock is available, then |
| 7720 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to |
| 7721 ** sqlite3_backup_step() can be retried later. ^If the source |
| 7722 ** [database connection] |
| 7723 ** is being used to write to the source database when sqlite3_backup_step() |
| 7724 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this |
| 7725 ** case the call to sqlite3_backup_step() can be retried later on. ^(If |
| 7726 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or |
| 7727 ** [SQLITE_READONLY] is returned, then |
| 7728 ** there is no point in retrying the call to sqlite3_backup_step(). These |
| 7729 ** errors are considered fatal.)^ The application must accept |
| 7730 ** that the backup operation has failed and pass the backup operation handle |
| 7731 ** to the sqlite3_backup_finish() to release associated resources. |
| 7732 ** |
| 7733 ** ^The first call to sqlite3_backup_step() obtains an exclusive lock |
| 7734 ** on the destination file. ^The exclusive lock is not released until either |
| 7735 ** sqlite3_backup_finish() is called or the backup operation is complete |
| 7736 ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to |
| 7737 ** sqlite3_backup_step() obtains a [shared lock] on the source database that |
| 7738 ** lasts for the duration of the sqlite3_backup_step() call. |
| 7739 ** ^Because the source database is not locked between calls to |
| 7740 ** sqlite3_backup_step(), the source database may be modified mid-way |
| 7741 ** through the backup process. ^If the source database is modified by an |
| 7742 ** external process or via a database connection other than the one being |
| 7743 ** used by the backup operation, then the backup will be automatically |
| 7744 ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 7745 ** database is modified by the using the same database connection as is used |
| 7746 ** by the backup operation, then the backup database is automatically |
| 7747 ** updated at the same time. |
| 7748 ** |
| 7749 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> |
| 7750 ** |
| 7751 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the |
| 7752 ** application wishes to abandon the backup operation, the application |
| 7753 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). |
| 7754 ** ^The sqlite3_backup_finish() interfaces releases all |
| 7755 ** resources associated with the [sqlite3_backup] object. |
| 7756 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any |
| 7757 ** active write-transaction on the destination database is rolled back. |
| 7758 ** The [sqlite3_backup] object is invalid |
| 7759 ** and may not be used following a call to sqlite3_backup_finish(). |
| 7760 ** |
| 7761 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no |
| 7762 ** sqlite3_backup_step() errors occurred, regardless or whether or not |
| 7763 ** sqlite3_backup_step() completed. |
| 7764 ** ^If an out-of-memory condition or IO error occurred during any prior |
| 7765 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then |
| 7766 ** sqlite3_backup_finish() returns the corresponding [error code]. |
| 7767 ** |
| 7768 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() |
| 7769 ** is not a permanent error and does not affect the return value of |
| 7770 ** sqlite3_backup_finish(). |
| 7771 ** |
| 7772 ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]] |
| 7773 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> |
| 7774 ** |
| 7775 ** ^The sqlite3_backup_remaining() routine returns the number of pages still |
| 7776 ** to be backed up at the conclusion of the most recent sqlite3_backup_step(). |
| 7777 ** ^The sqlite3_backup_pagecount() routine returns the total number of pages |
| 7778 ** in the source database at the conclusion of the most recent |
| 7779 ** sqlite3_backup_step(). |
| 7780 ** ^(The values returned by these functions are only updated by |
| 7781 ** sqlite3_backup_step(). If the source database is modified in a way that |
| 7782 ** changes the size of the source database or the number of pages remaining, |
| 7783 ** those changes are not reflected in the output of sqlite3_backup_pagecount() |
| 7784 ** and sqlite3_backup_remaining() until after the next |
| 7785 ** sqlite3_backup_step().)^ |
| 7786 ** |
| 7787 ** <b>Concurrent Usage of Database Handles</b> |
| 7788 ** |
| 7789 ** ^The source [database connection] may be used by the application for other |
| 7790 ** purposes while a backup operation is underway or being initialized. |
| 7791 ** ^If SQLite is compiled and configured to support threadsafe database |
| 7792 ** connections, then the source database connection may be used concurrently |
| 7793 ** from within other threads. |
| 7794 ** |
| 7795 ** However, the application must guarantee that the destination |
| 7796 ** [database connection] is not passed to any other API (by any thread) after |
| 7797 ** sqlite3_backup_init() is called and before the corresponding call to |
| 7798 ** sqlite3_backup_finish(). SQLite does not currently check to see |
| 7799 ** if the application incorrectly accesses the destination [database connection] |
| 7800 ** and so no error code is reported, but the operations may malfunction |
| 7801 ** nevertheless. Use of the destination database connection while a |
| 7802 ** backup is in progress might also also cause a mutex deadlock. |
| 7803 ** |
| 7804 ** If running in [shared cache mode], the application must |
| 7805 ** guarantee that the shared cache used by the destination database |
| 7806 ** is not accessed while the backup is running. In practice this means |
| 7807 ** that the application must guarantee that the disk file being |
| 7808 ** backed up to is not accessed by any connection within the process, |
| 7809 ** not just the specific connection that was passed to sqlite3_backup_init(). |
| 7810 ** |
| 7811 ** The [sqlite3_backup] object itself is partially threadsafe. Multiple |
| 7812 ** threads may safely make multiple concurrent calls to sqlite3_backup_step(). |
| 7813 ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() |
| 7814 ** APIs are not strictly speaking threadsafe. If they are invoked at the |
| 7815 ** same time as another thread is invoking sqlite3_backup_step() it is |
| 7816 ** possible that they return invalid values. |
| 7817 */ |
| 7818 SQLITE_API sqlite3_backup *sqlite3_backup_init( |
| 7819 sqlite3 *pDest, /* Destination database handle */ |
| 7820 const char *zDestName, /* Destination database name */ |
| 7821 sqlite3 *pSource, /* Source database handle */ |
| 7822 const char *zSourceName /* Source database name */ |
| 7823 ); |
| 7824 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); |
| 7825 SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); |
| 7826 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); |
| 7827 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); |
| 7828 |
| 7829 /* |
| 7830 ** CAPI3REF: Unlock Notification |
| 7831 ** METHOD: sqlite3 |
| 7832 ** |
| 7833 ** ^When running in shared-cache mode, a database operation may fail with |
| 7834 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or |
| 7835 ** individual tables within the shared-cache cannot be obtained. See |
| 7836 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. |
| 7837 ** ^This API may be used to register a callback that SQLite will invoke |
| 7838 ** when the connection currently holding the required lock relinquishes it. |
| 7839 ** ^This API is only available if the library was compiled with the |
| 7840 ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. |
| 7841 ** |
| 7842 ** See Also: [Using the SQLite Unlock Notification Feature]. |
| 7843 ** |
| 7844 ** ^Shared-cache locks are released when a database connection concludes |
| 7845 ** its current transaction, either by committing it or rolling it back. |
| 7846 ** |
| 7847 ** ^When a connection (known as the blocked connection) fails to obtain a |
| 7848 ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the |
| 7849 ** identity of the database connection (the blocking connection) that |
| 7850 ** has locked the required resource is stored internally. ^After an |
| 7851 ** application receives an SQLITE_LOCKED error, it may call the |
| 7852 ** sqlite3_unlock_notify() method with the blocked connection handle as |
| 7853 ** the first argument to register for a callback that will be invoked |
| 7854 ** when the blocking connections current transaction is concluded. ^The |
| 7855 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close] |
| 7856 ** call that concludes the blocking connections transaction. |
| 7857 ** |
| 7858 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, |
| 7859 ** there is a chance that the blocking connection will have already |
| 7860 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked. |
| 7861 ** If this happens, then the specified callback is invoked immediately, |
| 7862 ** from within the call to sqlite3_unlock_notify().)^ |
| 7863 ** |
| 7864 ** ^If the blocked connection is attempting to obtain a write-lock on a |
| 7865 ** shared-cache table, and more than one other connection currently holds |
| 7866 ** a read-lock on the same table, then SQLite arbitrarily selects one of |
| 7867 ** the other connections to use as the blocking connection. |
| 7868 ** |
| 7869 ** ^(There may be at most one unlock-notify callback registered by a |
| 7870 ** blocked connection. If sqlite3_unlock_notify() is called when the |
| 7871 ** blocked connection already has a registered unlock-notify callback, |
| 7872 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is |
| 7873 ** called with a NULL pointer as its second argument, then any existing |
| 7874 ** unlock-notify callback is canceled. ^The blocked connections |
| 7875 ** unlock-notify callback may also be canceled by closing the blocked |
| 7876 ** connection using [sqlite3_close()]. |
| 7877 ** |
| 7878 ** The unlock-notify callback is not reentrant. If an application invokes |
| 7879 ** any sqlite3_xxx API functions from within an unlock-notify callback, a |
| 7880 ** crash or deadlock may be the result. |
| 7881 ** |
| 7882 ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always |
| 7883 ** returns SQLITE_OK. |
| 7884 ** |
| 7885 ** <b>Callback Invocation Details</b> |
| 7886 ** |
| 7887 ** When an unlock-notify callback is registered, the application provides a |
| 7888 ** single void* pointer that is passed to the callback when it is invoked. |
| 7889 ** However, the signature of the callback function allows SQLite to pass |
| 7890 ** it an array of void* context pointers. The first argument passed to |
| 7891 ** an unlock-notify callback is a pointer to an array of void* pointers, |
| 7892 ** and the second is the number of entries in the array. |
| 7893 ** |
| 7894 ** When a blocking connections transaction is concluded, there may be |
| 7895 ** more than one blocked connection that has registered for an unlock-notify |
| 7896 ** callback. ^If two or more such blocked connections have specified the |
| 7897 ** same callback function, then instead of invoking the callback function |
| 7898 ** multiple times, it is invoked once with the set of void* context pointers |
| 7899 ** specified by the blocked connections bundled together into an array. |
| 7900 ** This gives the application an opportunity to prioritize any actions |
| 7901 ** related to the set of unblocked database connections. |
| 7902 ** |
| 7903 ** <b>Deadlock Detection</b> |
| 7904 ** |
| 7905 ** Assuming that after registering for an unlock-notify callback a |
| 7906 ** database waits for the callback to be issued before taking any further |
| 7907 ** action (a reasonable assumption), then using this API may cause the |
| 7908 ** application to deadlock. For example, if connection X is waiting for |
| 7909 ** connection Y's transaction to be concluded, and similarly connection |
| 7910 ** Y is waiting on connection X's transaction, then neither connection |
| 7911 ** will proceed and the system may remain deadlocked indefinitely. |
| 7912 ** |
| 7913 ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock |
| 7914 ** detection. ^If a given call to sqlite3_unlock_notify() would put the |
| 7915 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no |
| 7916 ** unlock-notify callback is registered. The system is said to be in |
| 7917 ** a deadlocked state if connection A has registered for an unlock-notify |
| 7918 ** callback on the conclusion of connection B's transaction, and connection |
| 7919 ** B has itself registered for an unlock-notify callback when connection |
| 7920 ** A's transaction is concluded. ^Indirect deadlock is also detected, so |
| 7921 ** the system is also considered to be deadlocked if connection B has |
| 7922 ** registered for an unlock-notify callback on the conclusion of connection |
| 7923 ** C's transaction, where connection C is waiting on connection A. ^Any |
| 7924 ** number of levels of indirection are allowed. |
| 7925 ** |
| 7926 ** <b>The "DROP TABLE" Exception</b> |
| 7927 ** |
| 7928 ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost |
| 7929 ** always appropriate to call sqlite3_unlock_notify(). There is however, |
| 7930 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, |
| 7931 ** SQLite checks if there are any currently executing SELECT statements |
| 7932 ** that belong to the same connection. If there are, SQLITE_LOCKED is |
| 7933 ** returned. In this case there is no "blocking connection", so invoking |
| 7934 ** sqlite3_unlock_notify() results in the unlock-notify callback being |
| 7935 ** invoked immediately. If the application then re-attempts the "DROP TABLE" |
| 7936 ** or "DROP INDEX" query, an infinite loop might be the result. |
| 7937 ** |
| 7938 ** One way around this problem is to check the extended error code returned |
| 7939 ** by an sqlite3_step() call. ^(If there is a blocking connection, then the |
| 7940 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in |
| 7941 ** the special "DROP TABLE/INDEX" case, the extended error code is just |
| 7942 ** SQLITE_LOCKED.)^ |
| 7943 */ |
| 7944 SQLITE_API int sqlite3_unlock_notify( |
| 7945 sqlite3 *pBlocked, /* Waiting connection */ |
| 7946 void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ |
| 7947 void *pNotifyArg /* Argument to pass to xNotify */ |
| 7948 ); |
| 7949 |
| 7950 |
| 7951 /* |
| 7952 ** CAPI3REF: String Comparison |
| 7953 ** |
| 7954 ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications |
| 7955 ** and extensions to compare the contents of two buffers containing UTF-8 |
| 7956 ** strings in a case-independent fashion, using the same definition of "case |
| 7957 ** independence" that SQLite uses internally when comparing identifiers. |
| 7958 */ |
| 7959 SQLITE_API int sqlite3_stricmp(const char *, const char *); |
| 7960 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); |
| 7961 |
| 7962 /* |
| 7963 ** CAPI3REF: String Globbing |
| 7964 * |
| 7965 ** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if |
| 7966 ** string X matches the [GLOB] pattern P. |
| 7967 ** ^The definition of [GLOB] pattern matching used in |
| 7968 ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the |
| 7969 ** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function |
| 7970 ** is case sensitive. |
| 7971 ** |
| 7972 ** Note that this routine returns zero on a match and non-zero if the strings |
| 7973 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. |
| 7974 ** |
| 7975 ** See also: [sqlite3_strlike()]. |
| 7976 */ |
| 7977 SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr); |
| 7978 |
| 7979 /* Begin WebDatabase patch for Chromium */ |
| 7980 /* Expose some SQLite internals for the WebDatabase vfs. |
| 7981 ** DO NOT EXTEND THE USE OF THIS. |
| 7982 */ |
| 7983 #ifndef CHROMIUM_SQLITE_API |
| 7984 #define CHROMIUM_SQLITE_API SQLITE_API |
| 7985 #endif |
| 7986 #if defined(CHROMIUM_SQLITE_INTERNALS) |
| 7987 #ifdef _WIN32 |
| 7988 CHROMIUM_SQLITE_API |
| 7989 void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE han
dle); |
| 7990 #else /* _WIN32 */ |
| 7991 CHROMIUM_SQLITE_API |
| 7992 int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* pVfs, |
| 7993 int fd, |
| 7994 sqlite3_file* pFile, |
| 7995 const char* zPath, |
| 7996 int noLock, |
| 7997 int flags); |
| 7998 #endif /* _WIN32 */ |
| 7999 #endif /* CHROMIUM_SQLITE_INTERNALS */ |
| 8000 /* End WebDatabase patch for Chromium */ |
| 8001 |
| 8002 /* |
| 8003 ** CAPI3REF: String LIKE Matching |
| 8004 * |
| 8005 ** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if |
| 8006 ** string X matches the [LIKE] pattern P with escape character E. |
| 8007 ** ^The definition of [LIKE] pattern matching used in |
| 8008 ** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E" |
| 8009 ** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without |
| 8010 ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0. |
| 8011 ** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case |
| 8012 ** insensitive - equivalent upper and lower case ASCII characters match |
| 8013 ** one another. |
| 8014 ** |
| 8015 ** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though |
| 8016 ** only ASCII characters are case folded. |
| 8017 ** |
| 8018 ** Note that this routine returns zero on a match and non-zero if the strings |
| 8019 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. |
| 8020 ** |
| 8021 ** See also: [sqlite3_strglob()]. |
| 8022 */ |
| 8023 SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int
cEsc); |
| 8024 |
| 8025 /* |
| 8026 ** CAPI3REF: Error Logging Interface |
| 8027 ** |
| 8028 ** ^The [sqlite3_log()] interface writes a message into the [error log] |
| 8029 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. |
| 8030 ** ^If logging is enabled, the zFormat string and subsequent arguments are |
| 8031 ** used with [sqlite3_snprintf()] to generate the final output string. |
| 8032 ** |
| 8033 ** The sqlite3_log() interface is intended for use by extensions such as |
| 8034 ** virtual tables, collating functions, and SQL functions. While there is |
| 8035 ** nothing to prevent an application from calling sqlite3_log(), doing so |
| 8036 ** is considered bad form. |
| 8037 ** |
| 8038 ** The zFormat string must not be NULL. |
| 8039 ** |
| 8040 ** To avoid deadlocks and other threading problems, the sqlite3_log() routine |
| 8041 ** will not use dynamically allocated memory. The log message is stored in |
| 8042 ** a fixed-length buffer on the stack. If the log message is longer than |
| 8043 ** a few hundred characters, it will be truncated to the length of the |
| 8044 ** buffer. |
| 8045 */ |
| 8046 SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); |
| 8047 |
| 8048 /* |
| 8049 ** CAPI3REF: Write-Ahead Log Commit Hook |
| 8050 ** METHOD: sqlite3 |
| 8051 ** |
| 8052 ** ^The [sqlite3_wal_hook()] function is used to register a callback that |
| 8053 ** is invoked each time data is committed to a database in wal mode. |
| 8054 ** |
| 8055 ** ^(The callback is invoked by SQLite after the commit has taken place and |
| 8056 ** the associated write-lock on the database released)^, so the implementation |
| 8057 ** may read, write or [checkpoint] the database as required. |
| 8058 ** |
| 8059 ** ^The first parameter passed to the callback function when it is invoked |
| 8060 ** is a copy of the third parameter passed to sqlite3_wal_hook() when |
| 8061 ** registering the callback. ^The second is a copy of the database handle. |
| 8062 ** ^The third parameter is the name of the database that was written to - |
| 8063 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter |
| 8064 ** is the number of pages currently in the write-ahead log file, |
| 8065 ** including those that were just committed. |
| 8066 ** |
| 8067 ** The callback function should normally return [SQLITE_OK]. ^If an error |
| 8068 ** code is returned, that error will propagate back up through the |
| 8069 ** SQLite code base to cause the statement that provoked the callback |
| 8070 ** to report an error, though the commit will have still occurred. If the |
| 8071 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value |
| 8072 ** that does not correspond to any valid SQLite error code, the results |
| 8073 ** are undefined. |
| 8074 ** |
| 8075 ** A single database handle may have at most a single write-ahead log callback |
| 8076 ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any |
| 8077 ** previously registered write-ahead log callback. ^Note that the |
| 8078 ** [sqlite3_wal_autocheckpoint()] interface and the |
| 8079 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will |
| 8080 ** overwrite any prior [sqlite3_wal_hook()] settings. |
| 8081 */ |
| 8082 SQLITE_API void *sqlite3_wal_hook( |
| 8083 sqlite3*, |
| 8084 int(*)(void *,sqlite3*,const char*,int), |
| 8085 void* |
| 8086 ); |
| 8087 |
| 8088 /* |
| 8089 ** CAPI3REF: Configure an auto-checkpoint |
| 8090 ** METHOD: sqlite3 |
| 8091 ** |
| 8092 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 8093 ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 8094 ** to automatically [checkpoint] |
| 8095 ** after committing a transaction if there are N or |
| 8096 ** more frames in the [write-ahead log] file. ^Passing zero or |
| 8097 ** a negative value as the nFrame parameter disables automatic |
| 8098 ** checkpoints entirely. |
| 8099 ** |
| 8100 ** ^The callback registered by this function replaces any existing callback |
| 8101 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback |
| 8102 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism |
| 8103 ** configured by this function. |
| 8104 ** |
| 8105 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface |
| 8106 ** from SQL. |
| 8107 ** |
| 8108 ** ^Checkpoints initiated by this mechanism are |
| 8109 ** [sqlite3_wal_checkpoint_v2|PASSIVE]. |
| 8110 ** |
| 8111 ** ^Every new [database connection] defaults to having the auto-checkpoint |
| 8112 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] |
| 8113 ** pages. The use of this interface |
| 8114 ** is only necessary if the default setting is found to be suboptimal |
| 8115 ** for a particular application. |
| 8116 */ |
| 8117 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 8118 |
| 8119 /* |
| 8120 ** CAPI3REF: Checkpoint a database |
| 8121 ** METHOD: sqlite3 |
| 8122 ** |
| 8123 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to |
| 8124 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ |
| 8125 ** |
| 8126 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the |
| 8127 ** [write-ahead log] for database X on [database connection] D to be |
| 8128 ** transferred into the database file and for the write-ahead log to |
| 8129 ** be reset. See the [checkpointing] documentation for addition |
| 8130 ** information. |
| 8131 ** |
| 8132 ** This interface used to be the only way to cause a checkpoint to |
| 8133 ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()] |
| 8134 ** interface was added. This interface is retained for backwards |
| 8135 ** compatibility and as a convenience for applications that need to manually |
| 8136 ** start a callback but which do not need the full power (and corresponding |
| 8137 ** complication) of [sqlite3_wal_checkpoint_v2()]. |
| 8138 */ |
| 8139 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); |
| 8140 |
| 8141 /* |
| 8142 ** CAPI3REF: Checkpoint a database |
| 8143 ** METHOD: sqlite3 |
| 8144 ** |
| 8145 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint |
| 8146 ** operation on database X of [database connection] D in mode M. Status |
| 8147 ** information is written back into integers pointed to by L and C.)^ |
| 8148 ** ^(The M parameter must be a valid [checkpoint mode]:)^ |
| 8149 ** |
| 8150 ** <dl> |
| 8151 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> |
| 8152 ** ^Checkpoint as many frames as possible without waiting for any database |
| 8153 ** readers or writers to finish, then sync the database file if all frames |
| 8154 ** in the log were checkpointed. ^The [busy-handler callback] |
| 8155 ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode. |
| 8156 ** ^On the other hand, passive mode might leave the checkpoint unfinished |
| 8157 ** if there are concurrent readers or writers. |
| 8158 ** |
| 8159 ** <dt>SQLITE_CHECKPOINT_FULL<dd> |
| 8160 ** ^This mode blocks (it invokes the |
| 8161 ** [sqlite3_busy_handler|busy-handler callback]) until there is no |
| 8162 ** database writer and all readers are reading from the most recent database |
| 8163 ** snapshot. ^It then checkpoints all frames in the log file and syncs the |
| 8164 ** database file. ^This mode blocks new database writers while it is pending, |
| 8165 ** but new database readers are allowed to continue unimpeded. |
| 8166 ** |
| 8167 ** <dt>SQLITE_CHECKPOINT_RESTART<dd> |
| 8168 ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition |
| 8169 ** that after checkpointing the log file it blocks (calls the |
| 8170 ** [busy-handler callback]) |
| 8171 ** until all readers are reading from the database file only. ^This ensures |
| 8172 ** that the next writer will restart the log file from the beginning. |
| 8173 ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new |
| 8174 ** database writer attempts while it is pending, but does not impede readers. |
| 8175 ** |
| 8176 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> |
| 8177 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the |
| 8178 ** addition that it also truncates the log file to zero bytes just prior |
| 8179 ** to a successful return. |
| 8180 ** </dl> |
| 8181 ** |
| 8182 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in |
| 8183 ** the log file or to -1 if the checkpoint could not run because |
| 8184 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not |
| 8185 ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the |
| 8186 ** log file (including any that were already checkpointed before the function |
| 8187 ** was called) or to -1 if the checkpoint could not run due to an error or |
| 8188 ** because the database is not in WAL mode. ^Note that upon successful |
| 8189 ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been |
| 8190 ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero. |
| 8191 ** |
| 8192 ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If |
| 8193 ** any other process is running a checkpoint operation at the same time, the |
| 8194 ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a |
| 8195 ** busy-handler configured, it will not be invoked in this case. |
| 8196 ** |
| 8197 ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the |
| 8198 ** exclusive "writer" lock on the database file. ^If the writer lock cannot be |
| 8199 ** obtained immediately, and a busy-handler is configured, it is invoked and |
| 8200 ** the writer lock retried until either the busy-handler returns 0 or the lock |
| 8201 ** is successfully obtained. ^The busy-handler is also invoked while waiting for |
| 8202 ** database readers as described above. ^If the busy-handler returns 0 before |
| 8203 ** the writer lock is obtained or while waiting for database readers, the |
| 8204 ** checkpoint operation proceeds from that point in the same way as |
| 8205 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible |
| 8206 ** without blocking any further. ^SQLITE_BUSY is returned in this case. |
| 8207 ** |
| 8208 ** ^If parameter zDb is NULL or points to a zero length string, then the |
| 8209 ** specified operation is attempted on all WAL databases [attached] to |
| 8210 ** [database connection] db. In this case the |
| 8211 ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If |
| 8212 ** an SQLITE_BUSY error is encountered when processing one or more of the |
| 8213 ** attached WAL databases, the operation is still attempted on any remaining |
| 8214 ** attached databases and SQLITE_BUSY is returned at the end. ^If any other |
| 8215 ** error occurs while processing an attached database, processing is abandoned |
| 8216 ** and the error code is returned to the caller immediately. ^If no error |
| 8217 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached |
| 8218 ** databases, SQLITE_OK is returned. |
| 8219 ** |
| 8220 ** ^If database zDb is the name of an attached database that is not in WAL |
| 8221 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If |
| 8222 ** zDb is not NULL (or a zero length string) and is not the name of any |
| 8223 ** attached database, SQLITE_ERROR is returned to the caller. |
| 8224 ** |
| 8225 ** ^Unless it returns SQLITE_MISUSE, |
| 8226 ** the sqlite3_wal_checkpoint_v2() interface |
| 8227 ** sets the error information that is queried by |
| 8228 ** [sqlite3_errcode()] and [sqlite3_errmsg()]. |
| 8229 ** |
| 8230 ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface |
| 8231 ** from SQL. |
| 8232 */ |
| 8233 SQLITE_API int sqlite3_wal_checkpoint_v2( |
| 8234 sqlite3 *db, /* Database handle */ |
| 8235 const char *zDb, /* Name of attached database (or NULL) */ |
| 8236 int eMode, /* SQLITE_CHECKPOINT_* value */ |
| 8237 int *pnLog, /* OUT: Size of WAL log in frames */ |
| 8238 int *pnCkpt /* OUT: Total number of frames checkpointed */ |
| 8239 ); |
| 8240 |
| 8241 /* |
| 8242 ** CAPI3REF: Checkpoint Mode Values |
| 8243 ** KEYWORDS: {checkpoint mode} |
| 8244 ** |
| 8245 ** These constants define all valid values for the "checkpoint mode" passed |
| 8246 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. |
| 8247 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the |
| 8248 ** meaning of each of these checkpoint modes. |
| 8249 */ |
| 8250 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ |
| 8251 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ |
| 8252 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */ |
| 8253 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ |
| 8254 |
| 8255 /* |
| 8256 ** CAPI3REF: Virtual Table Interface Configuration |
| 8257 ** |
| 8258 ** This function may be called by either the [xConnect] or [xCreate] method |
| 8259 ** of a [virtual table] implementation to configure |
| 8260 ** various facets of the virtual table interface. |
| 8261 ** |
| 8262 ** If this interface is invoked outside the context of an xConnect or |
| 8263 ** xCreate virtual table method then the behavior is undefined. |
| 8264 ** |
| 8265 ** At present, there is only one option that may be configured using |
| 8266 ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options |
| 8267 ** may be added in the future. |
| 8268 */ |
| 8269 SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); |
| 8270 |
| 8271 /* |
| 8272 ** CAPI3REF: Virtual Table Configuration Options |
| 8273 ** |
| 8274 ** These macros define the various options to the |
| 8275 ** [sqlite3_vtab_config()] interface that [virtual table] implementations |
| 8276 ** can use to customize and optimize their behavior. |
| 8277 ** |
| 8278 ** <dl> |
| 8279 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT |
| 8280 ** <dd>Calls of the form |
| 8281 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, |
| 8282 ** where X is an integer. If X is zero, then the [virtual table] whose |
| 8283 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not |
| 8284 ** support constraints. In this configuration (which is the default) if |
| 8285 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire |
| 8286 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been |
| 8287 ** specified as part of the users SQL statement, regardless of the actual |
| 8288 ** ON CONFLICT mode specified. |
| 8289 ** |
| 8290 ** If X is non-zero, then the virtual table implementation guarantees |
| 8291 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before |
| 8292 ** any modifications to internal or persistent data structures have been made. |
| 8293 ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite |
| 8294 ** is able to roll back a statement or database transaction, and abandon |
| 8295 ** or continue processing the current SQL statement as appropriate. |
| 8296 ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns |
| 8297 ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode |
| 8298 ** had been ABORT. |
| 8299 ** |
| 8300 ** Virtual table implementations that are required to handle OR REPLACE |
| 8301 ** must do so within the [xUpdate] method. If a call to the |
| 8302 ** [sqlite3_vtab_on_conflict()] function indicates that the current ON |
| 8303 ** CONFLICT policy is REPLACE, the virtual table implementation should |
| 8304 ** silently replace the appropriate rows within the xUpdate callback and |
| 8305 ** return SQLITE_OK. Or, if this is not possible, it may return |
| 8306 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT |
| 8307 ** constraint handling. |
| 8308 ** </dl> |
| 8309 */ |
| 8310 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 |
| 8311 |
| 8312 /* |
| 8313 ** CAPI3REF: Determine The Virtual Table Conflict Policy |
| 8314 ** |
| 8315 ** This function may only be called from within a call to the [xUpdate] method |
| 8316 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The |
| 8317 ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], |
| 8318 ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode |
| 8319 ** of the SQL statement that triggered the call to the [xUpdate] method of the |
| 8320 ** [virtual table]. |
| 8321 */ |
| 8322 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 8323 |
| 8324 /* |
| 8325 ** CAPI3REF: Conflict resolution modes |
| 8326 ** KEYWORDS: {conflict resolution mode} |
| 8327 ** |
| 8328 ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 8329 ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 8330 ** is for the SQL statement being evaluated. |
| 8331 ** |
| 8332 ** Note that the [SQLITE_IGNORE] constant is also used as a potential |
| 8333 ** return value from the [sqlite3_set_authorizer()] callback and that |
| 8334 ** [SQLITE_ABORT] is also a [result code]. |
| 8335 */ |
| 8336 #define SQLITE_ROLLBACK 1 |
| 8337 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ |
| 8338 #define SQLITE_FAIL 3 |
| 8339 /* #define SQLITE_ABORT 4 // Also an error code */ |
| 8340 #define SQLITE_REPLACE 5 |
| 8341 |
| 8342 /* |
| 8343 ** CAPI3REF: Prepared Statement Scan Status Opcodes |
| 8344 ** KEYWORDS: {scanstatus options} |
| 8345 ** |
| 8346 ** The following constants can be used for the T parameter to the |
| 8347 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a |
| 8348 ** different metric for sqlite3_stmt_scanstatus() to return. |
| 8349 ** |
| 8350 ** When the value returned to V is a string, space to hold that string is |
| 8351 ** managed by the prepared statement S and will be automatically freed when |
| 8352 ** S is finalized. |
| 8353 ** |
| 8354 ** <dl> |
| 8355 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> |
| 8356 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be |
| 8357 ** set to the total number of times that the X-th loop has run.</dd> |
| 8358 ** |
| 8359 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> |
| 8360 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set |
| 8361 ** to the total number of rows examined by all iterations of the X-th loop.</dd> |
| 8362 ** |
| 8363 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> |
| 8364 ** <dd>^The "double" variable pointed to by the T parameter will be set to the |
| 8365 ** query planner's estimate for the average number of rows output from each |
| 8366 ** iteration of the X-th loop. If the query planner's estimates was accurate, |
| 8367 ** then this value will approximate the quotient NVISIT/NLOOP and the |
| 8368 ** product of this value for all prior loops with the same SELECTID will |
| 8369 ** be the NLOOP value for the current loop. |
| 8370 ** |
| 8371 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> |
| 8372 ** <dd>^The "const char *" variable pointed to by the T parameter will be set |
| 8373 ** to a zero-terminated UTF-8 string containing the name of the index or table |
| 8374 ** used for the X-th loop. |
| 8375 ** |
| 8376 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> |
| 8377 ** <dd>^The "const char *" variable pointed to by the T parameter will be set |
| 8378 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] |
| 8379 ** description for the X-th loop. |
| 8380 ** |
| 8381 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt> |
| 8382 ** <dd>^The "int" variable pointed to by the T parameter will be set to the |
| 8383 ** "select-id" for the X-th loop. The select-id identifies which query or |
| 8384 ** subquery the loop is part of. The main query has a select-id of zero. |
| 8385 ** The select-id is the same value as is output in the first column |
| 8386 ** of an [EXPLAIN QUERY PLAN] query. |
| 8387 ** </dl> |
| 8388 */ |
| 8389 #define SQLITE_SCANSTAT_NLOOP 0 |
| 8390 #define SQLITE_SCANSTAT_NVISIT 1 |
| 8391 #define SQLITE_SCANSTAT_EST 2 |
| 8392 #define SQLITE_SCANSTAT_NAME 3 |
| 8393 #define SQLITE_SCANSTAT_EXPLAIN 4 |
| 8394 #define SQLITE_SCANSTAT_SELECTID 5 |
| 8395 |
| 8396 /* |
| 8397 ** CAPI3REF: Prepared Statement Scan Status |
| 8398 ** METHOD: sqlite3_stmt |
| 8399 ** |
| 8400 ** This interface returns information about the predicted and measured |
| 8401 ** performance for pStmt. Advanced applications can use this |
| 8402 ** interface to compare the predicted and the measured performance and |
| 8403 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. |
| 8404 ** |
| 8405 ** Since this interface is expected to be rarely used, it is only |
| 8406 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS] |
| 8407 ** compile-time option. |
| 8408 ** |
| 8409 ** The "iScanStatusOp" parameter determines which status information to return. |
| 8410 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior |
| 8411 ** of this interface is undefined. |
| 8412 ** ^The requested measurement is written into a variable pointed to by |
| 8413 ** the "pOut" parameter. |
| 8414 ** Parameter "idx" identifies the specific loop to retrieve statistics for. |
| 8415 ** Loops are numbered starting from zero. ^If idx is out of range - less than |
| 8416 ** zero or greater than or equal to the total number of loops used to implement |
| 8417 ** the statement - a non-zero value is returned and the variable that pOut |
| 8418 ** points to is unchanged. |
| 8419 ** |
| 8420 ** ^Statistics might not be available for all loops in all statements. ^In cases |
| 8421 ** where there exist loops with no available statistics, this function behaves |
| 8422 ** as if the loop did not exist - it returns non-zero and leave the variable |
| 8423 ** that pOut points to unchanged. |
| 8424 ** |
| 8425 ** See also: [sqlite3_stmt_scanstatus_reset()] |
| 8426 */ |
| 8427 SQLITE_API int sqlite3_stmt_scanstatus( |
| 8428 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ |
| 8429 int idx, /* Index of loop to report on */ |
| 8430 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ |
| 8431 void *pOut /* Result written here */ |
| 8432 ); |
| 8433 |
| 8434 /* |
| 8435 ** CAPI3REF: Zero Scan-Status Counters |
| 8436 ** METHOD: sqlite3_stmt |
| 8437 ** |
| 8438 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. |
| 8439 ** |
| 8440 ** This API is only available if the library is built with pre-processor |
| 8441 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. |
| 8442 */ |
| 8443 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); |
| 8444 |
| 8445 /* |
| 8446 ** CAPI3REF: Flush caches to disk mid-transaction |
| 8447 ** |
| 8448 ** ^If a write-transaction is open on [database connection] D when the |
| 8449 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty |
| 8450 ** pages in the pager-cache that are not currently in use are written out |
| 8451 ** to disk. A dirty page may be in use if a database cursor created by an |
| 8452 ** active SQL statement is reading from it, or if it is page 1 of a database |
| 8453 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)] |
| 8454 ** interface flushes caches for all schemas - "main", "temp", and |
| 8455 ** any [attached] databases. |
| 8456 ** |
| 8457 ** ^If this function needs to obtain extra database locks before dirty pages |
| 8458 ** can be flushed to disk, it does so. ^If those locks cannot be obtained |
| 8459 ** immediately and there is a busy-handler callback configured, it is invoked |
| 8460 ** in the usual manner. ^If the required lock still cannot be obtained, then |
| 8461 ** the database is skipped and an attempt made to flush any dirty pages |
| 8462 ** belonging to the next (if any) database. ^If any databases are skipped |
| 8463 ** because locks cannot be obtained, but no other error occurs, this |
| 8464 ** function returns SQLITE_BUSY. |
| 8465 ** |
| 8466 ** ^If any other error occurs while flushing dirty pages to disk (for |
| 8467 ** example an IO error or out-of-memory condition), then processing is |
| 8468 ** abandoned and an SQLite [error code] is returned to the caller immediately. |
| 8469 ** |
| 8470 ** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK. |
| 8471 ** |
| 8472 ** ^This function does not set the database handle error code or message |
| 8473 ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions. |
| 8474 */ |
| 8475 SQLITE_API int sqlite3_db_cacheflush(sqlite3*); |
| 8476 |
| 8477 /* |
| 8478 ** CAPI3REF: The pre-update hook. |
| 8479 ** |
| 8480 ** ^These interfaces are only available if SQLite is compiled using the |
| 8481 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. |
| 8482 ** |
| 8483 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function |
| 8484 ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation |
| 8485 ** on a database table. |
| 8486 ** ^At most one preupdate hook may be registered at a time on a single |
| 8487 ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides |
| 8488 ** the previous setting. |
| 8489 ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] |
| 8490 ** with a NULL pointer as the second parameter. |
| 8491 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 8492 ** the first parameter to callbacks. |
| 8493 ** |
| 8494 ** ^The preupdate hook only fires for changes to real database tables; the |
| 8495 ** preupdate hook is not invoked for changes to [virtual tables] or to |
| 8496 ** system tables like sqlite_master or sqlite_stat1. |
| 8497 ** |
| 8498 ** ^The second parameter to the preupdate callback is a pointer to |
| 8499 ** the [database connection] that registered the preupdate hook. |
| 8500 ** ^The third parameter to the preupdate callback is one of the constants |
| 8501 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| 8502 ** kind of update operation that is about to occur. |
| 8503 ** ^(The fourth parameter to the preupdate callback is the name of the |
| 8504 ** database within the database connection that is being modified. This |
| 8505 ** will be "main" for the main database or "temp" for TEMP tables or |
| 8506 ** the name given after the AS keyword in the [ATTACH] statement for attached |
| 8507 ** databases.)^ |
| 8508 ** ^The fifth parameter to the preupdate callback is the name of the |
| 8509 ** table that is being modified. |
| 8510 ** |
| 8511 ** For an UPDATE or DELETE operation on a [rowid table], the sixth |
| 8512 ** parameter passed to the preupdate callback is the initial [rowid] of the |
| 8513 ** row being modified or deleted. For an INSERT operation on a rowid table, |
| 8514 ** or any operation on a WITHOUT ROWID table, the value of the sixth |
| 8515 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the |
| 8516 ** seventh parameter is the final rowid value of the row being inserted |
| 8517 ** or updated. The value of the seventh parameter passed to the callback |
| 8518 ** function is not defined for operations on WITHOUT ROWID tables, or for |
| 8519 ** INSERT operations on rowid tables. |
| 8520 ** |
| 8521 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 8522 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 8523 ** provide additional information about a preupdate event. These routines |
| 8524 ** may only be called from within a preupdate callback. Invoking any of |
| 8525 ** these routines from outside of a preupdate callback or with a |
| 8526 ** [database connection] pointer that is different from the one supplied |
| 8527 ** to the preupdate callback results in undefined and probably undesirable |
| 8528 ** behavior. |
| 8529 ** |
| 8530 ** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns |
| 8531 ** in the row that is being inserted, updated, or deleted. |
| 8532 ** |
| 8533 ** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to |
| 8534 ** a [protected sqlite3_value] that contains the value of the Nth column of |
| 8535 ** the table row before it is updated. The N parameter must be between 0 |
| 8536 ** and one less than the number of columns or the behavior will be |
| 8537 ** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE |
| 8538 ** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the |
| 8539 ** behavior is undefined. The [sqlite3_value] that P points to |
| 8540 ** will be destroyed when the preupdate callback returns. |
| 8541 ** |
| 8542 ** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to |
| 8543 ** a [protected sqlite3_value] that contains the value of the Nth column of |
| 8544 ** the table row after it is updated. The N parameter must be between 0 |
| 8545 ** and one less than the number of columns or the behavior will be |
| 8546 ** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE |
| 8547 ** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the |
| 8548 ** behavior is undefined. The [sqlite3_value] that P points to |
| 8549 ** will be destroyed when the preupdate callback returns. |
| 8550 ** |
| 8551 ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate |
| 8552 ** callback was invoked as a result of a direct insert, update, or delete |
| 8553 ** operation; or 1 for inserts, updates, or deletes invoked by top-level |
| 8554 ** triggers; or 2 for changes resulting from triggers called by top-level |
| 8555 ** triggers; and so forth. |
| 8556 ** |
| 8557 ** See also: [sqlite3_update_hook()] |
| 8558 */ |
| 8559 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK) |
| 8560 SQLITE_API void *sqlite3_preupdate_hook( |
| 8561 sqlite3 *db, |
| 8562 void(*xPreUpdate)( |
| 8563 void *pCtx, /* Copy of third arg to preupdate_hook() */ |
| 8564 sqlite3 *db, /* Database handle */ |
| 8565 int op, /* SQLITE_UPDATE, DELETE or INSERT */ |
| 8566 char const *zDb, /* Database name */ |
| 8567 char const *zName, /* Table name */ |
| 8568 sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */ |
| 8569 sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */ |
| 8570 ), |
| 8571 void* |
| 8572 ); |
| 8573 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **); |
| 8574 SQLITE_API int sqlite3_preupdate_count(sqlite3 *); |
| 8575 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *); |
| 8576 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **); |
| 8577 #endif |
| 8578 |
| 8579 /* |
| 8580 ** CAPI3REF: Low-level system error code |
| 8581 ** |
| 8582 ** ^Attempt to return the underlying operating system error code or error |
| 8583 ** number that caused the most recent I/O error or failure to open a file. |
| 8584 ** The return value is OS-dependent. For example, on unix systems, after |
| 8585 ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be |
| 8586 ** called to get back the underlying "errno" that caused the problem, such |
| 8587 ** as ENOSPC, EAUTH, EISDIR, and so forth. |
| 8588 */ |
| 8589 SQLITE_API int sqlite3_system_errno(sqlite3*); |
| 8590 |
| 8591 /* |
| 8592 ** CAPI3REF: Database Snapshot |
| 8593 ** KEYWORDS: {snapshot} {sqlite3_snapshot} |
| 8594 ** EXPERIMENTAL |
| 8595 ** |
| 8596 ** An instance of the snapshot object records the state of a [WAL mode] |
| 8597 ** database for some specific point in history. |
| 8598 ** |
| 8599 ** In [WAL mode], multiple [database connections] that are open on the |
| 8600 ** same database file can each be reading a different historical version |
| 8601 ** of the database file. When a [database connection] begins a read |
| 8602 ** transaction, that connection sees an unchanging copy of the database |
| 8603 ** as it existed for the point in time when the transaction first started. |
| 8604 ** Subsequent changes to the database from other connections are not seen |
| 8605 ** by the reader until a new read transaction is started. |
| 8606 ** |
| 8607 ** The sqlite3_snapshot object records state information about an historical |
| 8608 ** version of the database file so that it is possible to later open a new read |
| 8609 ** transaction that sees that historical version of the database rather than |
| 8610 ** the most recent version. |
| 8611 ** |
| 8612 ** The constructor for this object is [sqlite3_snapshot_get()]. The |
| 8613 ** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer |
| 8614 ** to an historical snapshot (if possible). The destructor for |
| 8615 ** sqlite3_snapshot objects is [sqlite3_snapshot_free()]. |
| 8616 */ |
| 8617 typedef struct sqlite3_snapshot { |
| 8618 unsigned char hidden[48]; |
| 8619 } sqlite3_snapshot; |
| 8620 |
| 8621 /* |
| 8622 ** CAPI3REF: Record A Database Snapshot |
| 8623 ** EXPERIMENTAL |
| 8624 ** |
| 8625 ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a |
| 8626 ** new [sqlite3_snapshot] object that records the current state of |
| 8627 ** schema S in database connection D. ^On success, the |
| 8628 ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly |
| 8629 ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK. |
| 8630 ** If there is not already a read-transaction open on schema S when |
| 8631 ** this function is called, one is opened automatically. |
| 8632 ** |
| 8633 ** The following must be true for this function to succeed. If any of |
| 8634 ** the following statements are false when sqlite3_snapshot_get() is |
| 8635 ** called, SQLITE_ERROR is returned. The final value of *P is undefined |
| 8636 ** in this case. |
| 8637 ** |
| 8638 ** <ul> |
| 8639 ** <li> The database handle must be in [autocommit mode]. |
| 8640 ** |
| 8641 ** <li> Schema S of [database connection] D must be a [WAL mode] database. |
| 8642 ** |
| 8643 ** <li> There must not be a write transaction open on schema S of database |
| 8644 ** connection D. |
| 8645 ** |
| 8646 ** <li> One or more transactions must have been written to the current wal |
| 8647 ** file since it was created on disk (by any connection). This means |
| 8648 ** that a snapshot cannot be taken on a wal mode database with no wal |
| 8649 ** file immediately after it is first opened. At least one transaction |
| 8650 ** must be written to it first. |
| 8651 ** </ul> |
| 8652 ** |
| 8653 ** This function may also return SQLITE_NOMEM. If it is called with the |
| 8654 ** database handle in autocommit mode but fails for some other reason, |
| 8655 ** whether or not a read transaction is opened on schema S is undefined. |
| 8656 ** |
| 8657 ** The [sqlite3_snapshot] object returned from a successful call to |
| 8658 ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()] |
| 8659 ** to avoid a memory leak. |
| 8660 ** |
| 8661 ** The [sqlite3_snapshot_get()] interface is only available when the |
| 8662 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used. |
| 8663 */ |
| 8664 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get( |
| 8665 sqlite3 *db, |
| 8666 const char *zSchema, |
| 8667 sqlite3_snapshot **ppSnapshot |
| 8668 ); |
| 8669 |
| 8670 /* |
| 8671 ** CAPI3REF: Start a read transaction on an historical snapshot |
| 8672 ** EXPERIMENTAL |
| 8673 ** |
| 8674 ** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a |
| 8675 ** read transaction for schema S of |
| 8676 ** [database connection] D such that the read transaction |
| 8677 ** refers to historical [snapshot] P, rather than the most |
| 8678 ** recent change to the database. |
| 8679 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success |
| 8680 ** or an appropriate [error code] if it fails. |
| 8681 ** |
| 8682 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be |
| 8683 ** the first operation following the [BEGIN] that takes the schema S |
| 8684 ** out of [autocommit mode]. |
| 8685 ** ^In other words, schema S must not currently be in |
| 8686 ** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the |
| 8687 ** database connection D must be out of [autocommit mode]. |
| 8688 ** ^A [snapshot] will fail to open if it has been overwritten by a |
| 8689 ** [checkpoint]. |
| 8690 ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the |
| 8691 ** database connection D does not know that the database file for |
| 8692 ** schema S is in [WAL mode]. A database connection might not know |
| 8693 ** that the database file is in [WAL mode] if there has been no prior |
| 8694 ** I/O on that database connection, or if the database entered [WAL mode] |
| 8695 ** after the most recent I/O on the database connection.)^ |
| 8696 ** (Hint: Run "[PRAGMA application_id]" against a newly opened |
| 8697 ** database connection in order to make it ready to use snapshots.) |
| 8698 ** |
| 8699 ** The [sqlite3_snapshot_open()] interface is only available when the |
| 8700 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used. |
| 8701 */ |
| 8702 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open( |
| 8703 sqlite3 *db, |
| 8704 const char *zSchema, |
| 8705 sqlite3_snapshot *pSnapshot |
| 8706 ); |
| 8707 |
| 8708 /* |
| 8709 ** CAPI3REF: Destroy a snapshot |
| 8710 ** EXPERIMENTAL |
| 8711 ** |
| 8712 ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P. |
| 8713 ** The application must eventually free every [sqlite3_snapshot] object |
| 8714 ** using this routine to avoid a memory leak. |
| 8715 ** |
| 8716 ** The [sqlite3_snapshot_free()] interface is only available when the |
| 8717 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used. |
| 8718 */ |
| 8719 SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*); |
| 8720 |
| 8721 /* |
| 8722 ** CAPI3REF: Compare the ages of two snapshot handles. |
| 8723 ** EXPERIMENTAL |
| 8724 ** |
| 8725 ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages |
| 8726 ** of two valid snapshot handles. |
| 8727 ** |
| 8728 ** If the two snapshot handles are not associated with the same database |
| 8729 ** file, the result of the comparison is undefined. |
| 8730 ** |
| 8731 ** Additionally, the result of the comparison is only valid if both of the |
| 8732 ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the |
| 8733 ** last time the wal file was deleted. The wal file is deleted when the |
| 8734 ** database is changed back to rollback mode or when the number of database |
| 8735 ** clients drops to zero. If either snapshot handle was obtained before the |
| 8736 ** wal file was last deleted, the value returned by this function |
| 8737 ** is undefined. |
| 8738 ** |
| 8739 ** Otherwise, this API returns a negative value if P1 refers to an older |
| 8740 ** snapshot than P2, zero if the two handles refer to the same database |
| 8741 ** snapshot, and a positive value if P1 is a newer snapshot than P2. |
| 8742 */ |
| 8743 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( |
| 8744 sqlite3_snapshot *p1, |
| 8745 sqlite3_snapshot *p2 |
| 8746 ); |
| 8747 |
| 8748 /* |
| 8749 ** CAPI3REF: Recover snapshots from a wal file |
| 8750 ** EXPERIMENTAL |
| 8751 ** |
| 8752 ** If all connections disconnect from a database file but do not perform |
| 8753 ** a checkpoint, the existing wal file is opened along with the database |
| 8754 ** file the next time the database is opened. At this point it is only |
| 8755 ** possible to successfully call sqlite3_snapshot_open() to open the most |
| 8756 ** recent snapshot of the database (the one at the head of the wal file), |
| 8757 ** even though the wal file may contain other valid snapshots for which |
| 8758 ** clients have sqlite3_snapshot handles. |
| 8759 ** |
| 8760 ** This function attempts to scan the wal file associated with database zDb |
| 8761 ** of database handle db and make all valid snapshots available to |
| 8762 ** sqlite3_snapshot_open(). It is an error if there is already a read |
| 8763 ** transaction open on the database, or if the database is not a wal mode |
| 8764 ** database. |
| 8765 ** |
| 8766 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 8767 */ |
| 8768 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const c
har *zDb); |
| 8769 |
| 8770 /* |
| 8771 ** Undo the hack that converts floating point types to integer for |
| 8772 ** builds on processors without floating point support. |
| 8773 */ |
| 8774 #ifdef SQLITE_OMIT_FLOATING_POINT |
| 8775 # undef double |
| 8776 #endif |
| 8777 |
| 8778 #if 0 |
| 8779 } /* End of the 'extern "C"' block */ |
| 8780 #endif |
| 8781 #endif /* SQLITE3_H */ |
| 8782 |
| 8783 /******** Begin file sqlite3rtree.h *********/ |
| 8784 /* |
| 8785 ** 2010 August 30 |
| 8786 ** |
| 8787 ** The author disclaims copyright to this source code. In place of |
| 8788 ** a legal notice, here is a blessing: |
| 8789 ** |
| 8790 ** May you do good and not evil. |
| 8791 ** May you find forgiveness for yourself and forgive others. |
| 8792 ** May you share freely, never taking more than you give. |
| 8793 ** |
| 8794 ************************************************************************* |
| 8795 */ |
| 8796 |
| 8797 #ifndef _SQLITE3RTREE_H_ |
| 8798 #define _SQLITE3RTREE_H_ |
| 8799 |
| 8800 |
| 8801 #if 0 |
| 8802 extern "C" { |
| 8803 #endif |
| 8804 |
| 8805 typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; |
| 8806 typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info; |
| 8807 |
| 8808 /* The double-precision datatype used by RTree depends on the |
| 8809 ** SQLITE_RTREE_INT_ONLY compile-time option. |
| 8810 */ |
| 8811 #ifdef SQLITE_RTREE_INT_ONLY |
| 8812 typedef sqlite3_int64 sqlite3_rtree_dbl; |
| 8813 #else |
| 8814 typedef double sqlite3_rtree_dbl; |
| 8815 #endif |
| 8816 |
| 8817 /* |
| 8818 ** Register a geometry callback named zGeom that can be used as part of an |
| 8819 ** R-Tree geometry query as follows: |
| 8820 ** |
| 8821 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) |
| 8822 */ |
| 8823 SQLITE_API int sqlite3_rtree_geometry_callback( |
| 8824 sqlite3 *db, |
| 8825 const char *zGeom, |
| 8826 int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*), |
| 8827 void *pContext |
| 8828 ); |
| 8829 |
| 8830 |
| 8831 /* |
| 8832 ** A pointer to a structure of the following type is passed as the first |
| 8833 ** argument to callbacks registered using rtree_geometry_callback(). |
| 8834 */ |
| 8835 struct sqlite3_rtree_geometry { |
| 8836 void *pContext; /* Copy of pContext passed to s_r_g_c() */ |
| 8837 int nParam; /* Size of array aParam[] */ |
| 8838 sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */ |
| 8839 void *pUser; /* Callback implementation user data */ |
| 8840 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ |
| 8841 }; |
| 8842 |
| 8843 /* |
| 8844 ** Register a 2nd-generation geometry callback named zScore that can be |
| 8845 ** used as part of an R-Tree geometry query as follows: |
| 8846 ** |
| 8847 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...) |
| 8848 */ |
| 8849 SQLITE_API int sqlite3_rtree_query_callback( |
| 8850 sqlite3 *db, |
| 8851 const char *zQueryFunc, |
| 8852 int (*xQueryFunc)(sqlite3_rtree_query_info*), |
| 8853 void *pContext, |
| 8854 void (*xDestructor)(void*) |
| 8855 ); |
| 8856 |
| 8857 |
| 8858 /* |
| 8859 ** A pointer to a structure of the following type is passed as the |
| 8860 ** argument to scored geometry callback registered using |
| 8861 ** sqlite3_rtree_query_callback(). |
| 8862 ** |
| 8863 ** Note that the first 5 fields of this structure are identical to |
| 8864 ** sqlite3_rtree_geometry. This structure is a subclass of |
| 8865 ** sqlite3_rtree_geometry. |
| 8866 */ |
| 8867 struct sqlite3_rtree_query_info { |
| 8868 void *pContext; /* pContext from when function registered */ |
| 8869 int nParam; /* Number of function parameters */ |
| 8870 sqlite3_rtree_dbl *aParam; /* value of function parameters */ |
| 8871 void *pUser; /* callback can use this, if desired */ |
| 8872 void (*xDelUser)(void*); /* function to free pUser */ |
| 8873 sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */ |
| 8874 unsigned int *anQueue; /* Number of pending entries in the queue */ |
| 8875 int nCoord; /* Number of coordinates */ |
| 8876 int iLevel; /* Level of current node or entry */ |
| 8877 int mxLevel; /* The largest iLevel value in the tree */ |
| 8878 sqlite3_int64 iRowid; /* Rowid for current entry */ |
| 8879 sqlite3_rtree_dbl rParentScore; /* Score of parent node */ |
| 8880 int eParentWithin; /* Visibility of parent node */ |
| 8881 int eWithin; /* OUT: Visiblity */ |
| 8882 sqlite3_rtree_dbl rScore; /* OUT: Write the score here */ |
| 8883 /* The following fields are only available in 3.8.11 and later */ |
| 8884 sqlite3_value **apSqlParam; /* Original SQL values of parameters */ |
| 8885 }; |
| 8886 |
| 8887 /* |
| 8888 ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin. |
| 8889 */ |
| 8890 #define NOT_WITHIN 0 /* Object completely outside of query region */ |
| 8891 #define PARTLY_WITHIN 1 /* Object partially overlaps query region */ |
| 8892 #define FULLY_WITHIN 2 /* Object fully contained within query region */ |
| 8893 |
| 8894 |
| 8895 #if 0 |
| 8896 } /* end of the 'extern "C"' block */ |
| 8897 #endif |
| 8898 |
| 8899 #endif /* ifndef _SQLITE3RTREE_H_ */ |
| 8900 |
| 8901 /******** End of sqlite3rtree.h *********/ |
| 8902 /******** Begin file sqlite3session.h *********/ |
| 8903 |
| 8904 #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) |
| 8905 #define __SQLITESESSION_H_ 1 |
| 8906 |
| 8907 /* |
| 8908 ** Make sure we can call this stuff from C++. |
| 8909 */ |
| 8910 #if 0 |
| 8911 extern "C" { |
| 8912 #endif |
| 8913 |
| 8914 |
| 8915 /* |
| 8916 ** CAPI3REF: Session Object Handle |
| 8917 */ |
| 8918 typedef struct sqlite3_session sqlite3_session; |
| 8919 |
| 8920 /* |
| 8921 ** CAPI3REF: Changeset Iterator Handle |
| 8922 */ |
| 8923 typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; |
| 8924 |
| 8925 /* |
| 8926 ** CAPI3REF: Create A New Session Object |
| 8927 ** |
| 8928 ** Create a new session object attached to database handle db. If successful, |
| 8929 ** a pointer to the new object is written to *ppSession and SQLITE_OK is |
| 8930 ** returned. If an error occurs, *ppSession is set to NULL and an SQLite |
| 8931 ** error code (e.g. SQLITE_NOMEM) is returned. |
| 8932 ** |
| 8933 ** It is possible to create multiple session objects attached to a single |
| 8934 ** database handle. |
| 8935 ** |
| 8936 ** Session objects created using this function should be deleted using the |
| 8937 ** [sqlite3session_delete()] function before the database handle that they |
| 8938 ** are attached to is itself closed. If the database handle is closed before |
| 8939 ** the session object is deleted, then the results of calling any session |
| 8940 ** module function, including [sqlite3session_delete()] on the session object |
| 8941 ** are undefined. |
| 8942 ** |
| 8943 ** Because the session module uses the [sqlite3_preupdate_hook()] API, it |
| 8944 ** is not possible for an application to register a pre-update hook on a |
| 8945 ** database handle that has one or more session objects attached. Nor is |
| 8946 ** it possible to create a session object attached to a database handle for |
| 8947 ** which a pre-update hook is already defined. The results of attempting |
| 8948 ** either of these things are undefined. |
| 8949 ** |
| 8950 ** The session object will be used to create changesets for tables in |
| 8951 ** database zDb, where zDb is either "main", or "temp", or the name of an |
| 8952 ** attached database. It is not an error if database zDb is not attached |
| 8953 ** to the database when the session object is created. |
| 8954 */ |
| 8955 SQLITE_API int sqlite3session_create( |
| 8956 sqlite3 *db, /* Database handle */ |
| 8957 const char *zDb, /* Name of db (e.g. "main") */ |
| 8958 sqlite3_session **ppSession /* OUT: New session object */ |
| 8959 ); |
| 8960 |
| 8961 /* |
| 8962 ** CAPI3REF: Delete A Session Object |
| 8963 ** |
| 8964 ** Delete a session object previously allocated using |
| 8965 ** [sqlite3session_create()]. Once a session object has been deleted, the |
| 8966 ** results of attempting to use pSession with any other session module |
| 8967 ** function are undefined. |
| 8968 ** |
| 8969 ** Session objects must be deleted before the database handle to which they |
| 8970 ** are attached is closed. Refer to the documentation for |
| 8971 ** [sqlite3session_create()] for details. |
| 8972 */ |
| 8973 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); |
| 8974 |
| 8975 |
| 8976 /* |
| 8977 ** CAPI3REF: Enable Or Disable A Session Object |
| 8978 ** |
| 8979 ** Enable or disable the recording of changes by a session object. When |
| 8980 ** enabled, a session object records changes made to the database. When |
| 8981 ** disabled - it does not. A newly created session object is enabled. |
| 8982 ** Refer to the documentation for [sqlite3session_changeset()] for further |
| 8983 ** details regarding how enabling and disabling a session object affects |
| 8984 ** the eventual changesets. |
| 8985 ** |
| 8986 ** Passing zero to this function disables the session. Passing a value |
| 8987 ** greater than zero enables it. Passing a value less than zero is a |
| 8988 ** no-op, and may be used to query the current state of the session. |
| 8989 ** |
| 8990 ** The return value indicates the final state of the session object: 0 if |
| 8991 ** the session is disabled, or 1 if it is enabled. |
| 8992 */ |
| 8993 SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable); |
| 8994 |
| 8995 /* |
| 8996 ** CAPI3REF: Set Or Clear the Indirect Change Flag |
| 8997 ** |
| 8998 ** Each change recorded by a session object is marked as either direct or |
| 8999 ** indirect. A change is marked as indirect if either: |
| 9000 ** |
| 9001 ** <ul> |
| 9002 ** <li> The session object "indirect" flag is set when the change is |
| 9003 ** made, or |
| 9004 ** <li> The change is made by an SQL trigger or foreign key action |
| 9005 ** instead of directly as a result of a users SQL statement. |
| 9006 ** </ul> |
| 9007 ** |
| 9008 ** If a single row is affected by more than one operation within a session, |
| 9009 ** then the change is considered indirect if all operations meet the criteria |
| 9010 ** for an indirect change above, or direct otherwise. |
| 9011 ** |
| 9012 ** This function is used to set, clear or query the session object indirect |
| 9013 ** flag. If the second argument passed to this function is zero, then the |
| 9014 ** indirect flag is cleared. If it is greater than zero, the indirect flag |
| 9015 ** is set. Passing a value less than zero does not modify the current value |
| 9016 ** of the indirect flag, and may be used to query the current state of the |
| 9017 ** indirect flag for the specified session object. |
| 9018 ** |
| 9019 ** The return value indicates the final state of the indirect flag: 0 if |
| 9020 ** it is clear, or 1 if it is set. |
| 9021 */ |
| 9022 SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect)
; |
| 9023 |
| 9024 /* |
| 9025 ** CAPI3REF: Attach A Table To A Session Object |
| 9026 ** |
| 9027 ** If argument zTab is not NULL, then it is the name of a table to attach |
| 9028 ** to the session object passed as the first argument. All subsequent changes |
| 9029 ** made to the table while the session object is enabled will be recorded. See |
| 9030 ** documentation for [sqlite3session_changeset()] for further details. |
| 9031 ** |
| 9032 ** Or, if argument zTab is NULL, then changes are recorded for all tables |
| 9033 ** in the database. If additional tables are added to the database (by |
| 9034 ** executing "CREATE TABLE" statements) after this call is made, changes for |
| 9035 ** the new tables are also recorded. |
| 9036 ** |
| 9037 ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly |
| 9038 ** defined as part of their CREATE TABLE statement. It does not matter if the |
| 9039 ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY |
| 9040 ** KEY may consist of a single column, or may be a composite key. |
| 9041 ** |
| 9042 ** It is not an error if the named table does not exist in the database. Nor |
| 9043 ** is it an error if the named table does not have a PRIMARY KEY. However, |
| 9044 ** no changes will be recorded in either of these scenarios. |
| 9045 ** |
| 9046 ** Changes are not recorded for individual rows that have NULL values stored |
| 9047 ** in one or more of their PRIMARY KEY columns. |
| 9048 ** |
| 9049 ** SQLITE_OK is returned if the call completes without error. Or, if an error |
| 9050 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned. |
| 9051 */ |
| 9052 SQLITE_API int sqlite3session_attach( |
| 9053 sqlite3_session *pSession, /* Session object */ |
| 9054 const char *zTab /* Table name */ |
| 9055 ); |
| 9056 |
| 9057 /* |
| 9058 ** CAPI3REF: Set a table filter on a Session Object. |
| 9059 ** |
| 9060 ** The second argument (xFilter) is the "filter callback". For changes to rows |
| 9061 ** in tables that are not attached to the Session object, the filter is called |
| 9062 ** to determine whether changes to the table's rows should be tracked or not. |
| 9063 ** If xFilter returns 0, changes is not tracked. Note that once a table is |
| 9064 ** attached, xFilter will not be called again. |
| 9065 */ |
| 9066 SQLITE_API void sqlite3session_table_filter( |
| 9067 sqlite3_session *pSession, /* Session object */ |
| 9068 int(*xFilter)( |
| 9069 void *pCtx, /* Copy of third arg to _filter_table() */ |
| 9070 const char *zTab /* Table name */ |
| 9071 ), |
| 9072 void *pCtx /* First argument passed to xFilter */ |
| 9073 ); |
| 9074 |
| 9075 /* |
| 9076 ** CAPI3REF: Generate A Changeset From A Session Object |
| 9077 ** |
| 9078 ** Obtain a changeset containing changes to the tables attached to the |
| 9079 ** session object passed as the first argument. If successful, |
| 9080 ** set *ppChangeset to point to a buffer containing the changeset |
| 9081 ** and *pnChangeset to the size of the changeset in bytes before returning |
| 9082 ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to |
| 9083 ** zero and return an SQLite error code. |
| 9084 ** |
| 9085 ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes, |
| 9086 ** each representing a change to a single row of an attached table. An INSERT |
| 9087 ** change contains the values of each field of a new database row. A DELETE |
| 9088 ** contains the original values of each field of a deleted database row. An |
| 9089 ** UPDATE change contains the original values of each field of an updated |
| 9090 ** database row along with the updated values for each updated non-primary-key |
| 9091 ** column. It is not possible for an UPDATE change to represent a change that |
| 9092 ** modifies the values of primary key columns. If such a change is made, it |
| 9093 ** is represented in a changeset as a DELETE followed by an INSERT. |
| 9094 ** |
| 9095 ** Changes are not recorded for rows that have NULL values stored in one or |
| 9096 ** more of their PRIMARY KEY columns. If such a row is inserted or deleted, |
| 9097 ** no corresponding change is present in the changesets returned by this |
| 9098 ** function. If an existing row with one or more NULL values stored in |
| 9099 ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL, |
| 9100 ** only an INSERT is appears in the changeset. Similarly, if an existing row |
| 9101 ** with non-NULL PRIMARY KEY values is updated so that one or more of its |
| 9102 ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a |
| 9103 ** DELETE change only. |
| 9104 ** |
| 9105 ** The contents of a changeset may be traversed using an iterator created |
| 9106 ** using the [sqlite3changeset_start()] API. A changeset may be applied to |
| 9107 ** a database with a compatible schema using the [sqlite3changeset_apply()] |
| 9108 ** API. |
| 9109 ** |
| 9110 ** Within a changeset generated by this function, all changes related to a |
| 9111 ** single table are grouped together. In other words, when iterating through |
| 9112 ** a changeset or when applying a changeset to a database, all changes related |
| 9113 ** to a single table are processed before moving on to the next table. Tables |
| 9114 ** are sorted in the same order in which they were attached (or auto-attached) |
| 9115 ** to the sqlite3_session object. The order in which the changes related to |
| 9116 ** a single table are stored is undefined. |
| 9117 ** |
| 9118 ** Following a successful call to this function, it is the responsibility of |
| 9119 ** the caller to eventually free the buffer that *ppChangeset points to using |
| 9120 ** [sqlite3_free()]. |
| 9121 ** |
| 9122 ** <h3>Changeset Generation</h3> |
| 9123 ** |
| 9124 ** Once a table has been attached to a session object, the session object |
| 9125 ** records the primary key values of all new rows inserted into the table. |
| 9126 ** It also records the original primary key and other column values of any |
| 9127 ** deleted or updated rows. For each unique primary key value, data is only |
| 9128 ** recorded once - the first time a row with said primary key is inserted, |
| 9129 ** updated or deleted in the lifetime of the session. |
| 9130 ** |
| 9131 ** There is one exception to the previous paragraph: when a row is inserted, |
| 9132 ** updated or deleted, if one or more of its primary key columns contain a |
| 9133 ** NULL value, no record of the change is made. |
| 9134 ** |
| 9135 ** The session object therefore accumulates two types of records - those |
| 9136 ** that consist of primary key values only (created when the user inserts |
| 9137 ** a new record) and those that consist of the primary key values and the |
| 9138 ** original values of other table columns (created when the users deletes |
| 9139 ** or updates a record). |
| 9140 ** |
| 9141 ** When this function is called, the requested changeset is created using |
| 9142 ** both the accumulated records and the current contents of the database |
| 9143 ** file. Specifically: |
| 9144 ** |
| 9145 ** <ul> |
| 9146 ** <li> For each record generated by an insert, the database is queried |
| 9147 ** for a row with a matching primary key. If one is found, an INSERT |
| 9148 ** change is added to the changeset. If no such row is found, no change |
| 9149 ** is added to the changeset. |
| 9150 ** |
| 9151 ** <li> For each record generated by an update or delete, the database is |
| 9152 ** queried for a row with a matching primary key. If such a row is |
| 9153 ** found and one or more of the non-primary key fields have been |
| 9154 ** modified from their original values, an UPDATE change is added to |
| 9155 ** the changeset. Or, if no such row is found in the table, a DELETE |
| 9156 ** change is added to the changeset. If there is a row with a matching |
| 9157 ** primary key in the database, but all fields contain their original |
| 9158 ** values, no change is added to the changeset. |
| 9159 ** </ul> |
| 9160 ** |
| 9161 ** This means, amongst other things, that if a row is inserted and then later |
| 9162 ** deleted while a session object is active, neither the insert nor the delete |
| 9163 ** will be present in the changeset. Or if a row is deleted and then later a |
| 9164 ** row with the same primary key values inserted while a session object is |
| 9165 ** active, the resulting changeset will contain an UPDATE change instead of |
| 9166 ** a DELETE and an INSERT. |
| 9167 ** |
| 9168 ** When a session object is disabled (see the [sqlite3session_enable()] API), |
| 9169 ** it does not accumulate records when rows are inserted, updated or deleted. |
| 9170 ** This may appear to have some counter-intuitive effects if a single row |
| 9171 ** is written to more than once during a session. For example, if a row |
| 9172 ** is inserted while a session object is enabled, then later deleted while |
| 9173 ** the same session object is disabled, no INSERT record will appear in the |
| 9174 ** changeset, even though the delete took place while the session was disabled. |
| 9175 ** Or, if one field of a row is updated while a session is disabled, and |
| 9176 ** another field of the same row is updated while the session is enabled, the |
| 9177 ** resulting changeset will contain an UPDATE change that updates both fields. |
| 9178 */ |
| 9179 SQLITE_API int sqlite3session_changeset( |
| 9180 sqlite3_session *pSession, /* Session object */ |
| 9181 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ |
| 9182 void **ppChangeset /* OUT: Buffer containing changeset */ |
| 9183 ); |
| 9184 |
| 9185 /* |
| 9186 ** CAPI3REF: Load The Difference Between Tables Into A Session |
| 9187 ** |
| 9188 ** If it is not already attached to the session object passed as the first |
| 9189 ** argument, this function attaches table zTbl in the same manner as the |
| 9190 ** [sqlite3session_attach()] function. If zTbl does not exist, or if it |
| 9191 ** does not have a primary key, this function is a no-op (but does not return |
| 9192 ** an error). |
| 9193 ** |
| 9194 ** Argument zFromDb must be the name of a database ("main", "temp" etc.) |
| 9195 ** attached to the same database handle as the session object that contains |
| 9196 ** a table compatible with the table attached to the session by this function. |
| 9197 ** A table is considered compatible if it: |
| 9198 ** |
| 9199 ** <ul> |
| 9200 ** <li> Has the same name, |
| 9201 ** <li> Has the same set of columns declared in the same order, and |
| 9202 ** <li> Has the same PRIMARY KEY definition. |
| 9203 ** </ul> |
| 9204 ** |
| 9205 ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables |
| 9206 ** are compatible but do not have any PRIMARY KEY columns, it is not an error |
| 9207 ** but no changes are added to the session object. As with other session |
| 9208 ** APIs, tables without PRIMARY KEYs are simply ignored. |
| 9209 ** |
| 9210 ** This function adds a set of changes to the session object that could be |
| 9211 ** used to update the table in database zFrom (call this the "from-table") |
| 9212 ** so that its content is the same as the table attached to the session |
| 9213 ** object (call this the "to-table"). Specifically: |
| 9214 ** |
| 9215 ** <ul> |
| 9216 ** <li> For each row (primary key) that exists in the to-table but not in |
| 9217 ** the from-table, an INSERT record is added to the session object. |
| 9218 ** |
| 9219 ** <li> For each row (primary key) that exists in the to-table but not in |
| 9220 ** the from-table, a DELETE record is added to the session object. |
| 9221 ** |
| 9222 ** <li> For each row (primary key) that exists in both tables, but features |
| 9223 ** different non-PK values in each, an UPDATE record is added to the |
| 9224 ** session. |
| 9225 ** </ul> |
| 9226 ** |
| 9227 ** To clarify, if this function is called and then a changeset constructed |
| 9228 ** using [sqlite3session_changeset()], then after applying that changeset to |
| 9229 ** database zFrom the contents of the two compatible tables would be |
| 9230 ** identical. |
| 9231 ** |
| 9232 ** It an error if database zFrom does not exist or does not contain the |
| 9233 ** required compatible table. |
| 9234 ** |
| 9235 ** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite |
| 9236 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg |
| 9237 ** may be set to point to a buffer containing an English language error |
| 9238 ** message. It is the responsibility of the caller to free this buffer using |
| 9239 ** sqlite3_free(). |
| 9240 */ |
| 9241 SQLITE_API int sqlite3session_diff( |
| 9242 sqlite3_session *pSession, |
| 9243 const char *zFromDb, |
| 9244 const char *zTbl, |
| 9245 char **pzErrMsg |
| 9246 ); |
| 9247 |
| 9248 |
| 9249 /* |
| 9250 ** CAPI3REF: Generate A Patchset From A Session Object |
| 9251 ** |
| 9252 ** The differences between a patchset and a changeset are that: |
| 9253 ** |
| 9254 ** <ul> |
| 9255 ** <li> DELETE records consist of the primary key fields only. The |
| 9256 ** original values of other fields are omitted. |
| 9257 ** <li> The original values of any modified fields are omitted from |
| 9258 ** UPDATE records. |
| 9259 ** </ul> |
| 9260 ** |
| 9261 ** A patchset blob may be used with up to date versions of all |
| 9262 ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(), |
| 9263 ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly, |
| 9264 ** attempting to use a patchset blob with old versions of the |
| 9265 ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error. |
| 9266 ** |
| 9267 ** Because the non-primary key "old.*" fields are omitted, no |
| 9268 ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset |
| 9269 ** is passed to the sqlite3changeset_apply() API. Other conflict types work |
| 9270 ** in the same way as for changesets. |
| 9271 ** |
| 9272 ** Changes within a patchset are ordered in the same way as for changesets |
| 9273 ** generated by the sqlite3session_changeset() function (i.e. all changes for |
| 9274 ** a single table are grouped together, tables appear in the order in which |
| 9275 ** they were attached to the session object). |
| 9276 */ |
| 9277 SQLITE_API int sqlite3session_patchset( |
| 9278 sqlite3_session *pSession, /* Session object */ |
| 9279 int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */ |
| 9280 void **ppPatchset /* OUT: Buffer containing changeset */ |
| 9281 ); |
| 9282 |
| 9283 /* |
| 9284 ** CAPI3REF: Test if a changeset has recorded any changes. |
| 9285 ** |
| 9286 ** Return non-zero if no changes to attached tables have been recorded by |
| 9287 ** the session object passed as the first argument. Otherwise, if one or |
| 9288 ** more changes have been recorded, return zero. |
| 9289 ** |
| 9290 ** Even if this function returns zero, it is possible that calling |
| 9291 ** [sqlite3session_changeset()] on the session handle may still return a |
| 9292 ** changeset that contains no changes. This can happen when a row in |
| 9293 ** an attached table is modified and then later on the original values |
| 9294 ** are restored. However, if this function returns non-zero, then it is |
| 9295 ** guaranteed that a call to sqlite3session_changeset() will return a |
| 9296 ** changeset containing zero changes. |
| 9297 */ |
| 9298 SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession); |
| 9299 |
| 9300 /* |
| 9301 ** CAPI3REF: Create An Iterator To Traverse A Changeset |
| 9302 ** |
| 9303 ** Create an iterator used to iterate through the contents of a changeset. |
| 9304 ** If successful, *pp is set to point to the iterator handle and SQLITE_OK |
| 9305 ** is returned. Otherwise, if an error occurs, *pp is set to zero and an |
| 9306 ** SQLite error code is returned. |
| 9307 ** |
| 9308 ** The following functions can be used to advance and query a changeset |
| 9309 ** iterator created by this function: |
| 9310 ** |
| 9311 ** <ul> |
| 9312 ** <li> [sqlite3changeset_next()] |
| 9313 ** <li> [sqlite3changeset_op()] |
| 9314 ** <li> [sqlite3changeset_new()] |
| 9315 ** <li> [sqlite3changeset_old()] |
| 9316 ** </ul> |
| 9317 ** |
| 9318 ** It is the responsibility of the caller to eventually destroy the iterator |
| 9319 ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the |
| 9320 ** changeset (pChangeset) must remain valid until after the iterator is |
| 9321 ** destroyed. |
| 9322 ** |
| 9323 ** Assuming the changeset blob was created by one of the |
| 9324 ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or |
| 9325 ** [sqlite3changeset_invert()] functions, all changes within the changeset |
| 9326 ** that apply to a single table are grouped together. This means that when |
| 9327 ** an application iterates through a changeset using an iterator created by |
| 9328 ** this function, all changes that relate to a single table are visited |
| 9329 ** consecutively. There is no chance that the iterator will visit a change |
| 9330 ** the applies to table X, then one for table Y, and then later on visit |
| 9331 ** another change for table X. |
| 9332 */ |
| 9333 SQLITE_API int sqlite3changeset_start( |
| 9334 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ |
| 9335 int nChangeset, /* Size of changeset blob in bytes */ |
| 9336 void *pChangeset /* Pointer to blob containing changeset */ |
| 9337 ); |
| 9338 |
| 9339 |
| 9340 /* |
| 9341 ** CAPI3REF: Advance A Changeset Iterator |
| 9342 ** |
| 9343 ** This function may only be used with iterators created by function |
| 9344 ** [sqlite3changeset_start()]. If it is called on an iterator passed to |
| 9345 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE |
| 9346 ** is returned and the call has no effect. |
| 9347 ** |
| 9348 ** Immediately after an iterator is created by sqlite3changeset_start(), it |
| 9349 ** does not point to any change in the changeset. Assuming the changeset |
| 9350 ** is not empty, the first call to this function advances the iterator to |
| 9351 ** point to the first change in the changeset. Each subsequent call advances |
| 9352 ** the iterator to point to the next change in the changeset (if any). If |
| 9353 ** no error occurs and the iterator points to a valid change after a call |
| 9354 ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned. |
| 9355 ** Otherwise, if all changes in the changeset have already been visited, |
| 9356 ** SQLITE_DONE is returned. |
| 9357 ** |
| 9358 ** If an error occurs, an SQLite error code is returned. Possible error |
| 9359 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or |
| 9360 ** SQLITE_NOMEM. |
| 9361 */ |
| 9362 SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter); |
| 9363 |
| 9364 /* |
| 9365 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator |
| 9366 ** |
| 9367 ** The pIter argument passed to this function may either be an iterator |
| 9368 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator |
| 9369 ** created by [sqlite3changeset_start()]. In the latter case, the most recent |
| 9370 ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this |
| 9371 ** is not the case, this function returns [SQLITE_MISUSE]. |
| 9372 ** |
| 9373 ** If argument pzTab is not NULL, then *pzTab is set to point to a |
| 9374 ** nul-terminated utf-8 encoded string containing the name of the table |
| 9375 ** affected by the current change. The buffer remains valid until either |
| 9376 ** sqlite3changeset_next() is called on the iterator or until the |
| 9377 ** conflict-handler function returns. If pnCol is not NULL, then *pnCol is |
| 9378 ** set to the number of columns in the table affected by the change. If |
| 9379 ** pbIncorrect is not NULL, then *pbIndirect is set to true (1) if the change |
| 9380 ** is an indirect change, or false (0) otherwise. See the documentation for |
| 9381 ** [sqlite3session_indirect()] for a description of direct and indirect |
| 9382 ** changes. Finally, if pOp is not NULL, then *pOp is set to one of |
| 9383 ** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the |
| 9384 ** type of change that the iterator currently points to. |
| 9385 ** |
| 9386 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an |
| 9387 ** SQLite error code is returned. The values of the output variables may not |
| 9388 ** be trusted in this case. |
| 9389 */ |
| 9390 SQLITE_API int sqlite3changeset_op( |
| 9391 sqlite3_changeset_iter *pIter, /* Iterator object */ |
| 9392 const char **pzTab, /* OUT: Pointer to table name */ |
| 9393 int *pnCol, /* OUT: Number of columns in table */ |
| 9394 int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */ |
| 9395 int *pbIndirect /* OUT: True for an 'indirect' change */ |
| 9396 ); |
| 9397 |
| 9398 /* |
| 9399 ** CAPI3REF: Obtain The Primary Key Definition Of A Table |
| 9400 ** |
| 9401 ** For each modified table, a changeset includes the following: |
| 9402 ** |
| 9403 ** <ul> |
| 9404 ** <li> The number of columns in the table, and |
| 9405 ** <li> Which of those columns make up the tables PRIMARY KEY. |
| 9406 ** </ul> |
| 9407 ** |
| 9408 ** This function is used to find which columns comprise the PRIMARY KEY of |
| 9409 ** the table modified by the change that iterator pIter currently points to. |
| 9410 ** If successful, *pabPK is set to point to an array of nCol entries, where |
| 9411 ** nCol is the number of columns in the table. Elements of *pabPK are set to |
| 9412 ** 0x01 if the corresponding column is part of the tables primary key, or |
| 9413 ** 0x00 if it is not. |
| 9414 ** |
| 9415 ** If argument pnCol is not NULL, then *pnCol is set to the number of columns |
| 9416 ** in the table. |
| 9417 ** |
| 9418 ** If this function is called when the iterator does not point to a valid |
| 9419 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise, |
| 9420 ** SQLITE_OK is returned and the output variables populated as described |
| 9421 ** above. |
| 9422 */ |
| 9423 SQLITE_API int sqlite3changeset_pk( |
| 9424 sqlite3_changeset_iter *pIter, /* Iterator object */ |
| 9425 unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */ |
| 9426 int *pnCol /* OUT: Number of entries in output array */ |
| 9427 ); |
| 9428 |
| 9429 /* |
| 9430 ** CAPI3REF: Obtain old.* Values From A Changeset Iterator |
| 9431 ** |
| 9432 ** The pIter argument passed to this function may either be an iterator |
| 9433 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator |
| 9434 ** created by [sqlite3changeset_start()]. In the latter case, the most recent |
| 9435 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. |
| 9436 ** Furthermore, it may only be called if the type of change that the iterator |
| 9437 ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise, |
| 9438 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL. |
| 9439 ** |
| 9440 ** Argument iVal must be greater than or equal to 0, and less than the number |
| 9441 ** of columns in the table affected by the current change. Otherwise, |
| 9442 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL. |
| 9443 ** |
| 9444 ** If successful, this function sets *ppValue to point to a protected |
| 9445 ** sqlite3_value object containing the iVal'th value from the vector of |
| 9446 ** original row values stored as part of the UPDATE or DELETE change and |
| 9447 ** returns SQLITE_OK. The name of the function comes from the fact that this |
| 9448 ** is similar to the "old.*" columns available to update or delete triggers. |
| 9449 ** |
| 9450 ** If some other error occurs (e.g. an OOM condition), an SQLite error code |
| 9451 ** is returned and *ppValue is set to NULL. |
| 9452 */ |
| 9453 SQLITE_API int sqlite3changeset_old( |
| 9454 sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 9455 int iVal, /* Column number */ |
| 9456 sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */ |
| 9457 ); |
| 9458 |
| 9459 /* |
| 9460 ** CAPI3REF: Obtain new.* Values From A Changeset Iterator |
| 9461 ** |
| 9462 ** The pIter argument passed to this function may either be an iterator |
| 9463 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator |
| 9464 ** created by [sqlite3changeset_start()]. In the latter case, the most recent |
| 9465 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. |
| 9466 ** Furthermore, it may only be called if the type of change that the iterator |
| 9467 ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise, |
| 9468 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL. |
| 9469 ** |
| 9470 ** Argument iVal must be greater than or equal to 0, and less than the number |
| 9471 ** of columns in the table affected by the current change. Otherwise, |
| 9472 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL. |
| 9473 ** |
| 9474 ** If successful, this function sets *ppValue to point to a protected |
| 9475 ** sqlite3_value object containing the iVal'th value from the vector of |
| 9476 ** new row values stored as part of the UPDATE or INSERT change and |
| 9477 ** returns SQLITE_OK. If the change is an UPDATE and does not include |
| 9478 ** a new value for the requested column, *ppValue is set to NULL and |
| 9479 ** SQLITE_OK returned. The name of the function comes from the fact that |
| 9480 ** this is similar to the "new.*" columns available to update or delete |
| 9481 ** triggers. |
| 9482 ** |
| 9483 ** If some other error occurs (e.g. an OOM condition), an SQLite error code |
| 9484 ** is returned and *ppValue is set to NULL. |
| 9485 */ |
| 9486 SQLITE_API int sqlite3changeset_new( |
| 9487 sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 9488 int iVal, /* Column number */ |
| 9489 sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */ |
| 9490 ); |
| 9491 |
| 9492 /* |
| 9493 ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator |
| 9494 ** |
| 9495 ** This function should only be used with iterator objects passed to a |
| 9496 ** conflict-handler callback by [sqlite3changeset_apply()] with either |
| 9497 ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function |
| 9498 ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue |
| 9499 ** is set to NULL. |
| 9500 ** |
| 9501 ** Argument iVal must be greater than or equal to 0, and less than the number |
| 9502 ** of columns in the table affected by the current change. Otherwise, |
| 9503 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL. |
| 9504 ** |
| 9505 ** If successful, this function sets *ppValue to point to a protected |
| 9506 ** sqlite3_value object containing the iVal'th value from the |
| 9507 ** "conflicting row" associated with the current conflict-handler callback |
| 9508 ** and returns SQLITE_OK. |
| 9509 ** |
| 9510 ** If some other error occurs (e.g. an OOM condition), an SQLite error code |
| 9511 ** is returned and *ppValue is set to NULL. |
| 9512 */ |
| 9513 SQLITE_API int sqlite3changeset_conflict( |
| 9514 sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 9515 int iVal, /* Column number */ |
| 9516 sqlite3_value **ppValue /* OUT: Value from conflicting row */ |
| 9517 ); |
| 9518 |
| 9519 /* |
| 9520 ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations |
| 9521 ** |
| 9522 ** This function may only be called with an iterator passed to an |
| 9523 ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case |
| 9524 ** it sets the output variable to the total number of known foreign key |
| 9525 ** violations in the destination database and returns SQLITE_OK. |
| 9526 ** |
| 9527 ** In all other cases this function returns SQLITE_MISUSE. |
| 9528 */ |
| 9529 SQLITE_API int sqlite3changeset_fk_conflicts( |
| 9530 sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 9531 int *pnOut /* OUT: Number of FK violations */ |
| 9532 ); |
| 9533 |
| 9534 |
| 9535 /* |
| 9536 ** CAPI3REF: Finalize A Changeset Iterator |
| 9537 ** |
| 9538 ** This function is used to finalize an iterator allocated with |
| 9539 ** [sqlite3changeset_start()]. |
| 9540 ** |
| 9541 ** This function should only be called on iterators created using the |
| 9542 ** [sqlite3changeset_start()] function. If an application calls this |
| 9543 ** function with an iterator passed to a conflict-handler by |
| 9544 ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the |
| 9545 ** call has no effect. |
| 9546 ** |
| 9547 ** If an error was encountered within a call to an sqlite3changeset_xxx() |
| 9548 ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an |
| 9549 ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding |
| 9550 ** to that error is returned by this function. Otherwise, SQLITE_OK is |
| 9551 ** returned. This is to allow the following pattern (pseudo-code): |
| 9552 ** |
| 9553 ** sqlite3changeset_start(); |
| 9554 ** while( SQLITE_ROW==sqlite3changeset_next() ){ |
| 9555 ** // Do something with change. |
| 9556 ** } |
| 9557 ** rc = sqlite3changeset_finalize(); |
| 9558 ** if( rc!=SQLITE_OK ){ |
| 9559 ** // An error has occurred |
| 9560 ** } |
| 9561 */ |
| 9562 SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); |
| 9563 |
| 9564 /* |
| 9565 ** CAPI3REF: Invert A Changeset |
| 9566 ** |
| 9567 ** This function is used to "invert" a changeset object. Applying an inverted |
| 9568 ** changeset to a database reverses the effects of applying the uninverted |
| 9569 ** changeset. Specifically: |
| 9570 ** |
| 9571 ** <ul> |
| 9572 ** <li> Each DELETE change is changed to an INSERT, and |
| 9573 ** <li> Each INSERT change is changed to a DELETE, and |
| 9574 ** <li> For each UPDATE change, the old.* and new.* values are exchanged. |
| 9575 ** </ul> |
| 9576 ** |
| 9577 ** This function does not change the order in which changes appear within |
| 9578 ** the changeset. It merely reverses the sense of each individual change. |
| 9579 ** |
| 9580 ** If successful, a pointer to a buffer containing the inverted changeset |
| 9581 ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and |
| 9582 ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are |
| 9583 ** zeroed and an SQLite error code returned. |
| 9584 ** |
| 9585 ** It is the responsibility of the caller to eventually call sqlite3_free() |
| 9586 ** on the *ppOut pointer to free the buffer allocation following a successful |
| 9587 ** call to this function. |
| 9588 ** |
| 9589 ** WARNING/TODO: This function currently assumes that the input is a valid |
| 9590 ** changeset. If it is not, the results are undefined. |
| 9591 */ |
| 9592 SQLITE_API int sqlite3changeset_invert( |
| 9593 int nIn, const void *pIn, /* Input changeset */ |
| 9594 int *pnOut, void **ppOut /* OUT: Inverse of input */ |
| 9595 ); |
| 9596 |
| 9597 /* |
| 9598 ** CAPI3REF: Concatenate Two Changeset Objects |
| 9599 ** |
| 9600 ** This function is used to concatenate two changesets, A and B, into a |
| 9601 ** single changeset. The result is a changeset equivalent to applying |
| 9602 ** changeset A followed by changeset B. |
| 9603 ** |
| 9604 ** This function combines the two input changesets using an |
| 9605 ** sqlite3_changegroup object. Calling it produces similar results as the |
| 9606 ** following code fragment: |
| 9607 ** |
| 9608 ** sqlite3_changegroup *pGrp; |
| 9609 ** rc = sqlite3_changegroup_new(&pGrp); |
| 9610 ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA); |
| 9611 ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB); |
| 9612 ** if( rc==SQLITE_OK ){ |
| 9613 ** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut); |
| 9614 ** }else{ |
| 9615 ** *ppOut = 0; |
| 9616 ** *pnOut = 0; |
| 9617 ** } |
| 9618 ** |
| 9619 ** Refer to the sqlite3_changegroup documentation below for details. |
| 9620 */ |
| 9621 SQLITE_API int sqlite3changeset_concat( |
| 9622 int nA, /* Number of bytes in buffer pA */ |
| 9623 void *pA, /* Pointer to buffer containing changeset A */ |
| 9624 int nB, /* Number of bytes in buffer pB */ |
| 9625 void *pB, /* Pointer to buffer containing changeset B */ |
| 9626 int *pnOut, /* OUT: Number of bytes in output changeset */ |
| 9627 void **ppOut /* OUT: Buffer containing output changeset */ |
| 9628 ); |
| 9629 |
| 9630 |
| 9631 /* |
| 9632 ** CAPI3REF: Changegroup Handle |
| 9633 */ |
| 9634 typedef struct sqlite3_changegroup sqlite3_changegroup; |
| 9635 |
| 9636 /* |
| 9637 ** CAPI3REF: Create A New Changegroup Object |
| 9638 ** |
| 9639 ** An sqlite3_changegroup object is used to combine two or more changesets |
| 9640 ** (or patchsets) into a single changeset (or patchset). A single changegroup |
| 9641 ** object may combine changesets or patchsets, but not both. The output is |
| 9642 ** always in the same format as the input. |
| 9643 ** |
| 9644 ** If successful, this function returns SQLITE_OK and populates (*pp) with |
| 9645 ** a pointer to a new sqlite3_changegroup object before returning. The caller |
| 9646 ** should eventually free the returned object using a call to |
| 9647 ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code |
| 9648 ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL. |
| 9649 ** |
| 9650 ** The usual usage pattern for an sqlite3_changegroup object is as follows: |
| 9651 ** |
| 9652 ** <ul> |
| 9653 ** <li> It is created using a call to sqlite3changegroup_new(). |
| 9654 ** |
| 9655 ** <li> Zero or more changesets (or patchsets) are added to the object |
| 9656 ** by calling sqlite3changegroup_add(). |
| 9657 ** |
| 9658 ** <li> The result of combining all input changesets together is obtained |
| 9659 ** by the application via a call to sqlite3changegroup_output(). |
| 9660 ** |
| 9661 ** <li> The object is deleted using a call to sqlite3changegroup_delete(). |
| 9662 ** </ul> |
| 9663 ** |
| 9664 ** Any number of calls to add() and output() may be made between the calls to |
| 9665 ** new() and delete(), and in any order. |
| 9666 ** |
| 9667 ** As well as the regular sqlite3changegroup_add() and |
| 9668 ** sqlite3changegroup_output() functions, also available are the streaming |
| 9669 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm(). |
| 9670 */ |
| 9671 int sqlite3changegroup_new(sqlite3_changegroup **pp); |
| 9672 |
| 9673 /* |
| 9674 ** CAPI3REF: Add A Changeset To A Changegroup |
| 9675 ** |
| 9676 ** Add all changes within the changeset (or patchset) in buffer pData (size |
| 9677 ** nData bytes) to the changegroup. |
| 9678 ** |
| 9679 ** If the buffer contains a patchset, then all prior calls to this function |
| 9680 ** on the same changegroup object must also have specified patchsets. Or, if |
| 9681 ** the buffer contains a changeset, so must have the earlier calls to this |
| 9682 ** function. Otherwise, SQLITE_ERROR is returned and no changes are added |
| 9683 ** to the changegroup. |
| 9684 ** |
| 9685 ** Rows within the changeset and changegroup are identified by the values in |
| 9686 ** their PRIMARY KEY columns. A change in the changeset is considered to |
| 9687 ** apply to the same row as a change already present in the changegroup if |
| 9688 ** the two rows have the same primary key. |
| 9689 ** |
| 9690 ** Changes to rows that do not already appear in the changegroup are |
| 9691 ** simply copied into it. Or, if both the new changeset and the changegroup |
| 9692 ** contain changes that apply to a single row, the final contents of the |
| 9693 ** changegroup depends on the type of each change, as follows: |
| 9694 ** |
| 9695 ** <table border=1 style="margin-left:8ex;margin-right:8ex"> |
| 9696 ** <tr><th style="white-space:pre">Existing Change </th> |
| 9697 ** <th style="white-space:pre">New Change </th> |
| 9698 ** <th>Output Change |
| 9699 ** <tr><td>INSERT <td>INSERT <td> |
| 9700 ** The new change is ignored. This case does not occur if the new |
| 9701 ** changeset was recorded immediately after the changesets already |
| 9702 ** added to the changegroup. |
| 9703 ** <tr><td>INSERT <td>UPDATE <td> |
| 9704 ** The INSERT change remains in the changegroup. The values in the |
| 9705 ** INSERT change are modified as if the row was inserted by the |
| 9706 ** existing change and then updated according to the new change. |
| 9707 ** <tr><td>INSERT <td>DELETE <td> |
| 9708 ** The existing INSERT is removed from the changegroup. The DELETE is |
| 9709 ** not added. |
| 9710 ** <tr><td>UPDATE <td>INSERT <td> |
| 9711 ** The new change is ignored. This case does not occur if the new |
| 9712 ** changeset was recorded immediately after the changesets already |
| 9713 ** added to the changegroup. |
| 9714 ** <tr><td>UPDATE <td>UPDATE <td> |
| 9715 ** The existing UPDATE remains within the changegroup. It is amended |
| 9716 ** so that the accompanying values are as if the row was updated once |
| 9717 ** by the existing change and then again by the new change. |
| 9718 ** <tr><td>UPDATE <td>DELETE <td> |
| 9719 ** The existing UPDATE is replaced by the new DELETE within the |
| 9720 ** changegroup. |
| 9721 ** <tr><td>DELETE <td>INSERT <td> |
| 9722 ** If one or more of the column values in the row inserted by the |
| 9723 ** new change differ from those in the row deleted by the existing |
| 9724 ** change, the existing DELETE is replaced by an UPDATE within the |
| 9725 ** changegroup. Otherwise, if the inserted row is exactly the same |
| 9726 ** as the deleted row, the existing DELETE is simply discarded. |
| 9727 ** <tr><td>DELETE <td>UPDATE <td> |
| 9728 ** The new change is ignored. This case does not occur if the new |
| 9729 ** changeset was recorded immediately after the changesets already |
| 9730 ** added to the changegroup. |
| 9731 ** <tr><td>DELETE <td>DELETE <td> |
| 9732 ** The new change is ignored. This case does not occur if the new |
| 9733 ** changeset was recorded immediately after the changesets already |
| 9734 ** added to the changegroup. |
| 9735 ** </table> |
| 9736 ** |
| 9737 ** If the new changeset contains changes to a table that is already present |
| 9738 ** in the changegroup, then the number of columns and the position of the |
| 9739 ** primary key columns for the table must be consistent. If this is not the |
| 9740 ** case, this function fails with SQLITE_SCHEMA. If the input changeset |
| 9741 ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is |
| 9742 ** returned. Or, if an out-of-memory condition occurs during processing, this |
| 9743 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the |
| 9744 ** final contents of the changegroup is undefined. |
| 9745 ** |
| 9746 ** If no error occurs, SQLITE_OK is returned. |
| 9747 */ |
| 9748 int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); |
| 9749 |
| 9750 /* |
| 9751 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup |
| 9752 ** |
| 9753 ** Obtain a buffer containing a changeset (or patchset) representing the |
| 9754 ** current contents of the changegroup. If the inputs to the changegroup |
| 9755 ** were themselves changesets, the output is a changeset. Or, if the |
| 9756 ** inputs were patchsets, the output is also a patchset. |
| 9757 ** |
| 9758 ** As with the output of the sqlite3session_changeset() and |
| 9759 ** sqlite3session_patchset() functions, all changes related to a single |
| 9760 ** table are grouped together in the output of this function. Tables appear |
| 9761 ** in the same order as for the very first changeset added to the changegroup. |
| 9762 ** If the second or subsequent changesets added to the changegroup contain |
| 9763 ** changes for tables that do not appear in the first changeset, they are |
| 9764 ** appended onto the end of the output changeset, again in the order in |
| 9765 ** which they are first encountered. |
| 9766 ** |
| 9767 ** If an error occurs, an SQLite error code is returned and the output |
| 9768 ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK |
| 9769 ** is returned and the output variables are set to the size of and a |
| 9770 ** pointer to the output buffer, respectively. In this case it is the |
| 9771 ** responsibility of the caller to eventually free the buffer using a |
| 9772 ** call to sqlite3_free(). |
| 9773 */ |
| 9774 int sqlite3changegroup_output( |
| 9775 sqlite3_changegroup*, |
| 9776 int *pnData, /* OUT: Size of output buffer in bytes */ |
| 9777 void **ppData /* OUT: Pointer to output buffer */ |
| 9778 ); |
| 9779 |
| 9780 /* |
| 9781 ** CAPI3REF: Delete A Changegroup Object |
| 9782 */ |
| 9783 void sqlite3changegroup_delete(sqlite3_changegroup*); |
| 9784 |
| 9785 /* |
| 9786 ** CAPI3REF: Apply A Changeset To A Database |
| 9787 ** |
| 9788 ** Apply a changeset to a database. This function attempts to update the |
| 9789 ** "main" database attached to handle db with the changes found in the |
| 9790 ** changeset passed via the second and third arguments. |
| 9791 ** |
| 9792 ** The fourth argument (xFilter) passed to this function is the "filter |
| 9793 ** callback". If it is not NULL, then for each table affected by at least one |
| 9794 ** change in the changeset, the filter callback is invoked with |
| 9795 ** the table name as the second argument, and a copy of the context pointer |
| 9796 ** passed as the sixth argument to this function as the first. If the "filter |
| 9797 ** callback" returns zero, then no attempt is made to apply any changes to |
| 9798 ** the table. Otherwise, if the return value is non-zero or the xFilter |
| 9799 ** argument to this function is NULL, all changes related to the table are |
| 9800 ** attempted. |
| 9801 ** |
| 9802 ** For each table that is not excluded by the filter callback, this function |
| 9803 ** tests that the target database contains a compatible table. A table is |
| 9804 ** considered compatible if all of the following are true: |
| 9805 ** |
| 9806 ** <ul> |
| 9807 ** <li> The table has the same name as the name recorded in the |
| 9808 ** changeset, and |
| 9809 ** <li> The table has at least as many columns as recorded in the |
| 9810 ** changeset, and |
| 9811 ** <li> The table has primary key columns in the same position as |
| 9812 ** recorded in the changeset. |
| 9813 ** </ul> |
| 9814 ** |
| 9815 ** If there is no compatible table, it is not an error, but none of the |
| 9816 ** changes associated with the table are applied. A warning message is issued |
| 9817 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most |
| 9818 ** one such warning is issued for each table in the changeset. |
| 9819 ** |
| 9820 ** For each change for which there is a compatible table, an attempt is made |
| 9821 ** to modify the table contents according to the UPDATE, INSERT or DELETE |
| 9822 ** change. If a change cannot be applied cleanly, the conflict handler |
| 9823 ** function passed as the fifth argument to sqlite3changeset_apply() may be |
| 9824 ** invoked. A description of exactly when the conflict handler is invoked for |
| 9825 ** each type of change is below. |
| 9826 ** |
| 9827 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results |
| 9828 ** of passing anything other than a valid function pointer as the xConflict |
| 9829 ** argument are undefined. |
| 9830 ** |
| 9831 ** Each time the conflict handler function is invoked, it must return one |
| 9832 ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or |
| 9833 ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned |
| 9834 ** if the second argument passed to the conflict handler is either |
| 9835 ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler |
| 9836 ** returns an illegal value, any changes already made are rolled back and |
| 9837 ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different |
| 9838 ** actions are taken by sqlite3changeset_apply() depending on the value |
| 9839 ** returned by each invocation of the conflict-handler function. Refer to |
| 9840 ** the documentation for the three |
| 9841 ** [SQLITE_CHANGESET_OMIT|available return values] for details. |
| 9842 ** |
| 9843 ** <dl> |
| 9844 ** <dt>DELETE Changes<dd> |
| 9845 ** For each DELETE change, this function checks if the target database |
| 9846 ** contains a row with the same primary key value (or values) as the |
| 9847 ** original row values stored in the changeset. If it does, and the values |
| 9848 ** stored in all non-primary key columns also match the values stored in |
| 9849 ** the changeset the row is deleted from the target database. |
| 9850 ** |
| 9851 ** If a row with matching primary key values is found, but one or more of |
| 9852 ** the non-primary key fields contains a value different from the original |
| 9853 ** row value stored in the changeset, the conflict-handler function is |
| 9854 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the |
| 9855 ** database table has more columns than are recorded in the changeset, |
| 9856 ** only the values of those non-primary key fields are compared against |
| 9857 ** the current database contents - any trailing database table columns |
| 9858 ** are ignored. |
| 9859 ** |
| 9860 ** If no row with matching primary key values is found in the database, |
| 9861 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9862 ** passed as the second argument. |
| 9863 ** |
| 9864 ** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT |
| 9865 ** (which can only happen if a foreign key constraint is violated), the |
| 9866 ** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT] |
| 9867 ** passed as the second argument. This includes the case where the DELETE |
| 9868 ** operation is attempted because an earlier call to the conflict handler |
| 9869 ** function returned [SQLITE_CHANGESET_REPLACE]. |
| 9870 ** |
| 9871 ** <dt>INSERT Changes<dd> |
| 9872 ** For each INSERT change, an attempt is made to insert the new row into |
| 9873 ** the database. If the changeset row contains fewer fields than the |
| 9874 ** database table, the trailing fields are populated with their default |
| 9875 ** values. |
| 9876 ** |
| 9877 ** If the attempt to insert the row fails because the database already |
| 9878 ** contains a row with the same primary key values, the conflict handler |
| 9879 ** function is invoked with the second argument set to |
| 9880 ** [SQLITE_CHANGESET_CONFLICT]. |
| 9881 ** |
| 9882 ** If the attempt to insert the row fails because of some other constraint |
| 9883 ** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is |
| 9884 ** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT]. |
| 9885 ** This includes the case where the INSERT operation is re-attempted because |
| 9886 ** an earlier call to the conflict handler function returned |
| 9887 ** [SQLITE_CHANGESET_REPLACE]. |
| 9888 ** |
| 9889 ** <dt>UPDATE Changes<dd> |
| 9890 ** For each UPDATE change, this function checks if the target database |
| 9891 ** contains a row with the same primary key value (or values) as the |
| 9892 ** original row values stored in the changeset. If it does, and the values |
| 9893 ** stored in all modified non-primary key columns also match the values |
| 9894 ** stored in the changeset the row is updated within the target database. |
| 9895 ** |
| 9896 ** If a row with matching primary key values is found, but one or more of |
| 9897 ** the modified non-primary key fields contains a value different from an |
| 9898 ** original row value stored in the changeset, the conflict-handler function |
| 9899 ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since |
| 9900 ** UPDATE changes only contain values for non-primary key fields that are |
| 9901 ** to be modified, only those fields need to match the original values to |
| 9902 ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. |
| 9903 ** |
| 9904 ** If no row with matching primary key values is found in the database, |
| 9905 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9906 ** passed as the second argument. |
| 9907 ** |
| 9908 ** If the UPDATE operation is attempted, but SQLite returns |
| 9909 ** SQLITE_CONSTRAINT, the conflict-handler function is invoked with |
| 9910 ** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument. |
| 9911 ** This includes the case where the UPDATE operation is attempted after |
| 9912 ** an earlier call to the conflict handler function returned |
| 9913 ** [SQLITE_CHANGESET_REPLACE]. |
| 9914 ** </dl> |
| 9915 ** |
| 9916 ** It is safe to execute SQL statements, including those that write to the |
| 9917 ** table that the callback related to, from within the xConflict callback. |
| 9918 ** This can be used to further customize the applications conflict |
| 9919 ** resolution strategy. |
| 9920 ** |
| 9921 ** All changes made by this function are enclosed in a savepoint transaction. |
| 9922 ** If any other error (aside from a constraint failure when attempting to |
| 9923 ** write to the target database) occurs, then the savepoint transaction is |
| 9924 ** rolled back, restoring the target database to its original state, and an |
| 9925 ** SQLite error code returned. |
| 9926 */ |
| 9927 SQLITE_API int sqlite3changeset_apply( |
| 9928 sqlite3 *db, /* Apply change to "main" db of this handle */ |
| 9929 int nChangeset, /* Size of changeset in bytes */ |
| 9930 void *pChangeset, /* Changeset blob */ |
| 9931 int(*xFilter)( |
| 9932 void *pCtx, /* Copy of sixth arg to _apply() */ |
| 9933 const char *zTab /* Table name */ |
| 9934 ), |
| 9935 int(*xConflict)( |
| 9936 void *pCtx, /* Copy of sixth arg to _apply() */ |
| 9937 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ |
| 9938 sqlite3_changeset_iter *p /* Handle describing change and conflict */ |
| 9939 ), |
| 9940 void *pCtx /* First argument passed to xConflict */ |
| 9941 ); |
| 9942 |
| 9943 /* |
| 9944 ** CAPI3REF: Constants Passed To The Conflict Handler |
| 9945 ** |
| 9946 ** Values that may be passed as the second argument to a conflict-handler. |
| 9947 ** |
| 9948 ** <dl> |
| 9949 ** <dt>SQLITE_CHANGESET_DATA<dd> |
| 9950 ** The conflict handler is invoked with CHANGESET_DATA as the second argument |
| 9951 ** when processing a DELETE or UPDATE change if a row with the required |
| 9952 ** PRIMARY KEY fields is present in the database, but one or more other |
| 9953 ** (non primary-key) fields modified by the update do not contain the |
| 9954 ** expected "before" values. |
| 9955 ** |
| 9956 ** The conflicting row, in this case, is the database row with the matching |
| 9957 ** primary key. |
| 9958 ** |
| 9959 ** <dt>SQLITE_CHANGESET_NOTFOUND<dd> |
| 9960 ** The conflict handler is invoked with CHANGESET_NOTFOUND as the second |
| 9961 ** argument when processing a DELETE or UPDATE change if a row with the |
| 9962 ** required PRIMARY KEY fields is not present in the database. |
| 9963 ** |
| 9964 ** There is no conflicting row in this case. The results of invoking the |
| 9965 ** sqlite3changeset_conflict() API are undefined. |
| 9966 ** |
| 9967 ** <dt>SQLITE_CHANGESET_CONFLICT<dd> |
| 9968 ** CHANGESET_CONFLICT is passed as the second argument to the conflict |
| 9969 ** handler while processing an INSERT change if the operation would result |
| 9970 ** in duplicate primary key values. |
| 9971 ** |
| 9972 ** The conflicting row in this case is the database row with the matching |
| 9973 ** primary key. |
| 9974 ** |
| 9975 ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd> |
| 9976 ** If foreign key handling is enabled, and applying a changeset leaves the |
| 9977 ** database in a state containing foreign key violations, the conflict |
| 9978 ** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument |
| 9979 ** exactly once before the changeset is committed. If the conflict handler |
| 9980 ** returns CHANGESET_OMIT, the changes, including those that caused the |
| 9981 ** foreign key constraint violation, are committed. Or, if it returns |
| 9982 ** CHANGESET_ABORT, the changeset is rolled back. |
| 9983 ** |
| 9984 ** No current or conflicting row information is provided. The only function |
| 9985 ** it is possible to call on the supplied sqlite3_changeset_iter handle |
| 9986 ** is sqlite3changeset_fk_conflicts(). |
| 9987 ** |
| 9988 ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd> |
| 9989 ** If any other constraint violation occurs while applying a change (i.e. |
| 9990 ** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is |
| 9991 ** invoked with CHANGESET_CONSTRAINT as the second argument. |
| 9992 ** |
| 9993 ** There is no conflicting row in this case. The results of invoking the |
| 9994 ** sqlite3changeset_conflict() API are undefined. |
| 9995 ** |
| 9996 ** </dl> |
| 9997 */ |
| 9998 #define SQLITE_CHANGESET_DATA 1 |
| 9999 #define SQLITE_CHANGESET_NOTFOUND 2 |
| 10000 #define SQLITE_CHANGESET_CONFLICT 3 |
| 10001 #define SQLITE_CHANGESET_CONSTRAINT 4 |
| 10002 #define SQLITE_CHANGESET_FOREIGN_KEY 5 |
| 10003 |
| 10004 /* |
| 10005 ** CAPI3REF: Constants Returned By The Conflict Handler |
| 10006 ** |
| 10007 ** A conflict handler callback must return one of the following three values. |
| 10008 ** |
| 10009 ** <dl> |
| 10010 ** <dt>SQLITE_CHANGESET_OMIT<dd> |
| 10011 ** If a conflict handler returns this value no special action is taken. The |
| 10012 ** change that caused the conflict is not applied. The session module |
| 10013 ** continues to the next change in the changeset. |
| 10014 ** |
| 10015 ** <dt>SQLITE_CHANGESET_REPLACE<dd> |
| 10016 ** This value may only be returned if the second argument to the conflict |
| 10017 ** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this |
| 10018 ** is not the case, any changes applied so far are rolled back and the |
| 10019 ** call to sqlite3changeset_apply() returns SQLITE_MISUSE. |
| 10020 ** |
| 10021 ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict |
| 10022 ** handler, then the conflicting row is either updated or deleted, depending |
| 10023 ** on the type of change. |
| 10024 ** |
| 10025 ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict |
| 10026 ** handler, then the conflicting row is removed from the database and a |
| 10027 ** second attempt to apply the change is made. If this second attempt fails, |
| 10028 ** the original row is restored to the database before continuing. |
| 10029 ** |
| 10030 ** <dt>SQLITE_CHANGESET_ABORT<dd> |
| 10031 ** If this value is returned, any changes applied so far are rolled back |
| 10032 ** and the call to sqlite3changeset_apply() returns SQLITE_ABORT. |
| 10033 ** </dl> |
| 10034 */ |
| 10035 #define SQLITE_CHANGESET_OMIT 0 |
| 10036 #define SQLITE_CHANGESET_REPLACE 1 |
| 10037 #define SQLITE_CHANGESET_ABORT 2 |
| 10038 |
| 10039 /* |
| 10040 ** CAPI3REF: Streaming Versions of API functions. |
| 10041 ** |
| 10042 ** The six streaming API xxx_strm() functions serve similar purposes to the |
| 10043 ** corresponding non-streaming API functions: |
| 10044 ** |
| 10045 ** <table border=1 style="margin-left:8ex;margin-right:8ex"> |
| 10046 ** <tr><th>Streaming function<th>Non-streaming equivalent</th> |
| 10047 ** <tr><td>sqlite3changeset_apply_str<td>[sqlite3changeset_apply] |
| 10048 ** <tr><td>sqlite3changeset_concat_str<td>[sqlite3changeset_concat] |
| 10049 ** <tr><td>sqlite3changeset_invert_str<td>[sqlite3changeset_invert] |
| 10050 ** <tr><td>sqlite3changeset_start_str<td>[sqlite3changeset_start] |
| 10051 ** <tr><td>sqlite3session_changeset_str<td>[sqlite3session_changeset] |
| 10052 ** <tr><td>sqlite3session_patchset_str<td>[sqlite3session_patchset] |
| 10053 ** </table> |
| 10054 ** |
| 10055 ** Non-streaming functions that accept changesets (or patchsets) as input |
| 10056 ** require that the entire changeset be stored in a single buffer in memory. |
| 10057 ** Similarly, those that return a changeset or patchset do so by returning |
| 10058 ** a pointer to a single large buffer allocated using sqlite3_malloc(). |
| 10059 ** Normally this is convenient. However, if an application running in a |
| 10060 ** low-memory environment is required to handle very large changesets, the |
| 10061 ** large contiguous memory allocations required can become onerous. |
| 10062 ** |
| 10063 ** In order to avoid this problem, instead of a single large buffer, input |
| 10064 ** is passed to a streaming API functions by way of a callback function that |
| 10065 ** the sessions module invokes to incrementally request input data as it is |
| 10066 ** required. In all cases, a pair of API function parameters such as |
| 10067 ** |
| 10068 ** <pre> |
| 10069 ** int nChangeset, |
| 10070 ** void *pChangeset, |
| 10071 ** </pre> |
| 10072 ** |
| 10073 ** Is replaced by: |
| 10074 ** |
| 10075 ** <pre> |
| 10076 ** int (*xInput)(void *pIn, void *pData, int *pnData), |
| 10077 ** void *pIn, |
| 10078 ** </pre> |
| 10079 ** |
| 10080 ** Each time the xInput callback is invoked by the sessions module, the first |
| 10081 ** argument passed is a copy of the supplied pIn context pointer. The second |
| 10082 ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no |
| 10083 ** error occurs the xInput method should copy up to (*pnData) bytes of data |
| 10084 ** into the buffer and set (*pnData) to the actual number of bytes copied |
| 10085 ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData) |
| 10086 ** should be set to zero to indicate this. Or, if an error occurs, an SQLite |
| 10087 ** error code should be returned. In all cases, if an xInput callback returns |
| 10088 ** an error, all processing is abandoned and the streaming API function |
| 10089 ** returns a copy of the error code to the caller. |
| 10090 ** |
| 10091 ** In the case of sqlite3changeset_start_strm(), the xInput callback may be |
| 10092 ** invoked by the sessions module at any point during the lifetime of the |
| 10093 ** iterator. If such an xInput callback returns an error, the iterator enters |
| 10094 ** an error state, whereby all subsequent calls to iterator functions |
| 10095 ** immediately fail with the same error code as returned by xInput. |
| 10096 ** |
| 10097 ** Similarly, streaming API functions that return changesets (or patchsets) |
| 10098 ** return them in chunks by way of a callback function instead of via a |
| 10099 ** pointer to a single large buffer. In this case, a pair of parameters such |
| 10100 ** as: |
| 10101 ** |
| 10102 ** <pre> |
| 10103 ** int *pnChangeset, |
| 10104 ** void **ppChangeset, |
| 10105 ** </pre> |
| 10106 ** |
| 10107 ** Is replaced by: |
| 10108 ** |
| 10109 ** <pre> |
| 10110 ** int (*xOutput)(void *pOut, const void *pData, int nData), |
| 10111 ** void *pOut |
| 10112 ** </pre> |
| 10113 ** |
| 10114 ** The xOutput callback is invoked zero or more times to return data to |
| 10115 ** the application. The first parameter passed to each call is a copy of the |
| 10116 ** pOut pointer supplied by the application. The second parameter, pData, |
| 10117 ** points to a buffer nData bytes in size containing the chunk of output |
| 10118 ** data being returned. If the xOutput callback successfully processes the |
| 10119 ** supplied data, it should return SQLITE_OK to indicate success. Otherwise, |
| 10120 ** it should return some other SQLite error code. In this case processing |
| 10121 ** is immediately abandoned and the streaming API function returns a copy |
| 10122 ** of the xOutput error code to the application. |
| 10123 ** |
| 10124 ** The sessions module never invokes an xOutput callback with the third |
| 10125 ** parameter set to a value less than or equal to zero. Other than this, |
| 10126 ** no guarantees are made as to the size of the chunks of data returned. |
| 10127 */ |
| 10128 SQLITE_API int sqlite3changeset_apply_strm( |
| 10129 sqlite3 *db, /* Apply change to "main" db of this handle */ |
| 10130 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ |
| 10131 void *pIn, /* First arg for xInput */ |
| 10132 int(*xFilter)( |
| 10133 void *pCtx, /* Copy of sixth arg to _apply() */ |
| 10134 const char *zTab /* Table name */ |
| 10135 ), |
| 10136 int(*xConflict)( |
| 10137 void *pCtx, /* Copy of sixth arg to _apply() */ |
| 10138 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ |
| 10139 sqlite3_changeset_iter *p /* Handle describing change and conflict */ |
| 10140 ), |
| 10141 void *pCtx /* First argument passed to xConflict */ |
| 10142 ); |
| 10143 SQLITE_API int sqlite3changeset_concat_strm( |
| 10144 int (*xInputA)(void *pIn, void *pData, int *pnData), |
| 10145 void *pInA, |
| 10146 int (*xInputB)(void *pIn, void *pData, int *pnData), |
| 10147 void *pInB, |
| 10148 int (*xOutput)(void *pOut, const void *pData, int nData), |
| 10149 void *pOut |
| 10150 ); |
| 10151 SQLITE_API int sqlite3changeset_invert_strm( |
| 10152 int (*xInput)(void *pIn, void *pData, int *pnData), |
| 10153 void *pIn, |
| 10154 int (*xOutput)(void *pOut, const void *pData, int nData), |
| 10155 void *pOut |
| 10156 ); |
| 10157 SQLITE_API int sqlite3changeset_start_strm( |
| 10158 sqlite3_changeset_iter **pp, |
| 10159 int (*xInput)(void *pIn, void *pData, int *pnData), |
| 10160 void *pIn |
| 10161 ); |
| 10162 SQLITE_API int sqlite3session_changeset_strm( |
| 10163 sqlite3_session *pSession, |
| 10164 int (*xOutput)(void *pOut, const void *pData, int nData), |
| 10165 void *pOut |
| 10166 ); |
| 10167 SQLITE_API int sqlite3session_patchset_strm( |
| 10168 sqlite3_session *pSession, |
| 10169 int (*xOutput)(void *pOut, const void *pData, int nData), |
| 10170 void *pOut |
| 10171 ); |
| 10172 int sqlite3changegroup_add_strm(sqlite3_changegroup*, |
| 10173 int (*xInput)(void *pIn, void *pData, int *pnData), |
| 10174 void *pIn |
| 10175 ); |
| 10176 int sqlite3changegroup_output_strm(sqlite3_changegroup*, |
| 10177 int (*xOutput)(void *pOut, const void *pData, int nData), |
| 10178 void *pOut |
| 10179 ); |
| 10180 |
| 10181 |
| 10182 /* |
| 10183 ** Make sure we can call this stuff from C++. |
| 10184 */ |
| 10185 #if 0 |
| 10186 } |
| 10187 #endif |
| 10188 |
| 10189 #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */ |
| 10190 |
| 10191 /******** End of sqlite3session.h *********/ |
| 10192 /******** Begin file fts5.h *********/ |
| 10193 /* |
| 10194 ** 2014 May 31 |
| 10195 ** |
| 10196 ** The author disclaims copyright to this source code. In place of |
| 10197 ** a legal notice, here is a blessing: |
| 10198 ** |
| 10199 ** May you do good and not evil. |
| 10200 ** May you find forgiveness for yourself and forgive others. |
| 10201 ** May you share freely, never taking more than you give. |
| 10202 ** |
| 10203 ****************************************************************************** |
| 10204 ** |
| 10205 ** Interfaces to extend FTS5. Using the interfaces defined in this file, |
| 10206 ** FTS5 may be extended with: |
| 10207 ** |
| 10208 ** * custom tokenizers, and |
| 10209 ** * custom auxiliary functions. |
| 10210 */ |
| 10211 |
| 10212 |
| 10213 #ifndef _FTS5_H |
| 10214 #define _FTS5_H |
| 10215 |
| 10216 |
| 10217 #if 0 |
| 10218 extern "C" { |
| 10219 #endif |
| 10220 |
| 10221 /************************************************************************* |
| 10222 ** CUSTOM AUXILIARY FUNCTIONS |
| 10223 ** |
| 10224 ** Virtual table implementations may overload SQL functions by implementing |
| 10225 ** the sqlite3_module.xFindFunction() method. |
| 10226 */ |
| 10227 |
| 10228 typedef struct Fts5ExtensionApi Fts5ExtensionApi; |
| 10229 typedef struct Fts5Context Fts5Context; |
| 10230 typedef struct Fts5PhraseIter Fts5PhraseIter; |
| 10231 |
| 10232 typedef void (*fts5_extension_function)( |
| 10233 const Fts5ExtensionApi *pApi, /* API offered by current FTS version */ |
| 10234 Fts5Context *pFts, /* First arg to pass to pApi functions */ |
| 10235 sqlite3_context *pCtx, /* Context for returning result/error */ |
| 10236 int nVal, /* Number of values in apVal[] array */ |
| 10237 sqlite3_value **apVal /* Array of trailing arguments */ |
| 10238 ); |
| 10239 |
| 10240 struct Fts5PhraseIter { |
| 10241 const unsigned char *a; |
| 10242 const unsigned char *b; |
| 10243 }; |
| 10244 |
| 10245 /* |
| 10246 ** EXTENSION API FUNCTIONS |
| 10247 ** |
| 10248 ** xUserData(pFts): |
| 10249 ** Return a copy of the context pointer the extension function was |
| 10250 ** registered with. |
| 10251 ** |
| 10252 ** xColumnTotalSize(pFts, iCol, pnToken): |
| 10253 ** If parameter iCol is less than zero, set output variable *pnToken |
| 10254 ** to the total number of tokens in the FTS5 table. Or, if iCol is |
| 10255 ** non-negative but less than the number of columns in the table, return |
| 10256 ** the total number of tokens in column iCol, considering all rows in |
| 10257 ** the FTS5 table. |
| 10258 ** |
| 10259 ** If parameter iCol is greater than or equal to the number of columns |
| 10260 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. |
| 10261 ** an OOM condition or IO error), an appropriate SQLite error code is |
| 10262 ** returned. |
| 10263 ** |
| 10264 ** xColumnCount(pFts): |
| 10265 ** Return the number of columns in the table. |
| 10266 ** |
| 10267 ** xColumnSize(pFts, iCol, pnToken): |
| 10268 ** If parameter iCol is less than zero, set output variable *pnToken |
| 10269 ** to the total number of tokens in the current row. Or, if iCol is |
| 10270 ** non-negative but less than the number of columns in the table, set |
| 10271 ** *pnToken to the number of tokens in column iCol of the current row. |
| 10272 ** |
| 10273 ** If parameter iCol is greater than or equal to the number of columns |
| 10274 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. |
| 10275 ** an OOM condition or IO error), an appropriate SQLite error code is |
| 10276 ** returned. |
| 10277 ** |
| 10278 ** This function may be quite inefficient if used with an FTS5 table |
| 10279 ** created with the "columnsize=0" option. |
| 10280 ** |
| 10281 ** xColumnText: |
| 10282 ** This function attempts to retrieve the text of column iCol of the |
| 10283 ** current document. If successful, (*pz) is set to point to a buffer |
| 10284 ** containing the text in utf-8 encoding, (*pn) is set to the size in bytes |
| 10285 ** (not characters) of the buffer and SQLITE_OK is returned. Otherwise, |
| 10286 ** if an error occurs, an SQLite error code is returned and the final values |
| 10287 ** of (*pz) and (*pn) are undefined. |
| 10288 ** |
| 10289 ** xPhraseCount: |
| 10290 ** Returns the number of phrases in the current query expression. |
| 10291 ** |
| 10292 ** xPhraseSize: |
| 10293 ** Returns the number of tokens in phrase iPhrase of the query. Phrases |
| 10294 ** are numbered starting from zero. |
| 10295 ** |
| 10296 ** xInstCount: |
| 10297 ** Set *pnInst to the total number of occurrences of all phrases within |
| 10298 ** the query within the current row. Return SQLITE_OK if successful, or |
| 10299 ** an error code (i.e. SQLITE_NOMEM) if an error occurs. |
| 10300 ** |
| 10301 ** This API can be quite slow if used with an FTS5 table created with the |
| 10302 ** "detail=none" or "detail=column" option. If the FTS5 table is created |
| 10303 ** with either "detail=none" or "detail=column" and "content=" option |
| 10304 ** (i.e. if it is a contentless table), then this API always returns 0. |
| 10305 ** |
| 10306 ** xInst: |
| 10307 ** Query for the details of phrase match iIdx within the current row. |
| 10308 ** Phrase matches are numbered starting from zero, so the iIdx argument |
| 10309 ** should be greater than or equal to zero and smaller than the value |
| 10310 ** output by xInstCount(). |
| 10311 ** |
| 10312 ** Usually, output parameter *piPhrase is set to the phrase number, *piCol |
| 10313 ** to the column in which it occurs and *piOff the token offset of the |
| 10314 ** first token of the phrase. The exception is if the table was created |
| 10315 ** with the offsets=0 option specified. In this case *piOff is always |
| 10316 ** set to -1. |
| 10317 ** |
| 10318 ** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM) |
| 10319 ** if an error occurs. |
| 10320 ** |
| 10321 ** This API can be quite slow if used with an FTS5 table created with the |
| 10322 ** "detail=none" or "detail=column" option. |
| 10323 ** |
| 10324 ** xRowid: |
| 10325 ** Returns the rowid of the current row. |
| 10326 ** |
| 10327 ** xTokenize: |
| 10328 ** Tokenize text using the tokenizer belonging to the FTS5 table. |
| 10329 ** |
| 10330 ** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback): |
| 10331 ** This API function is used to query the FTS table for phrase iPhrase |
| 10332 ** of the current query. Specifically, a query equivalent to: |
| 10333 ** |
| 10334 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid |
| 10335 ** |
| 10336 ** with $p set to a phrase equivalent to the phrase iPhrase of the |
| 10337 ** current query is executed. Any column filter that applies to |
| 10338 ** phrase iPhrase of the current query is included in $p. For each |
| 10339 ** row visited, the callback function passed as the fourth argument |
| 10340 ** is invoked. The context and API objects passed to the callback |
| 10341 ** function may be used to access the properties of each matched row. |
| 10342 ** Invoking Api.xUserData() returns a copy of the pointer passed as |
| 10343 ** the third argument to pUserData. |
| 10344 ** |
| 10345 ** If the callback function returns any value other than SQLITE_OK, the |
| 10346 ** query is abandoned and the xQueryPhrase function returns immediately. |
| 10347 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK. |
| 10348 ** Otherwise, the error code is propagated upwards. |
| 10349 ** |
| 10350 ** If the query runs to completion without incident, SQLITE_OK is returned. |
| 10351 ** Or, if some error occurs before the query completes or is aborted by |
| 10352 ** the callback, an SQLite error code is returned. |
| 10353 ** |
| 10354 ** |
| 10355 ** xSetAuxdata(pFts5, pAux, xDelete) |
| 10356 ** |
| 10357 ** Save the pointer passed as the second argument as the extension functions |
| 10358 ** "auxiliary data". The pointer may then be retrieved by the current or any |
| 10359 ** future invocation of the same fts5 extension function made as part of |
| 10360 ** of the same MATCH query using the xGetAuxdata() API. |
| 10361 ** |
| 10362 ** Each extension function is allocated a single auxiliary data slot for |
| 10363 ** each FTS query (MATCH expression). If the extension function is invoked |
| 10364 ** more than once for a single FTS query, then all invocations share a |
| 10365 ** single auxiliary data context. |
| 10366 ** |
| 10367 ** If there is already an auxiliary data pointer when this function is |
| 10368 ** invoked, then it is replaced by the new pointer. If an xDelete callback |
| 10369 ** was specified along with the original pointer, it is invoked at this |
| 10370 ** point. |
| 10371 ** |
| 10372 ** The xDelete callback, if one is specified, is also invoked on the |
| 10373 ** auxiliary data pointer after the FTS5 query has finished. |
| 10374 ** |
| 10375 ** If an error (e.g. an OOM condition) occurs within this function, an |
| 10376 ** the auxiliary data is set to NULL and an error code returned. If the |
| 10377 ** xDelete parameter was not NULL, it is invoked on the auxiliary data |
| 10378 ** pointer before returning. |
| 10379 ** |
| 10380 ** |
| 10381 ** xGetAuxdata(pFts5, bClear) |
| 10382 ** |
| 10383 ** Returns the current auxiliary data pointer for the fts5 extension |
| 10384 ** function. See the xSetAuxdata() method for details. |
| 10385 ** |
| 10386 ** If the bClear argument is non-zero, then the auxiliary data is cleared |
| 10387 ** (set to NULL) before this function returns. In this case the xDelete, |
| 10388 ** if any, is not invoked. |
| 10389 ** |
| 10390 ** |
| 10391 ** xRowCount(pFts5, pnRow) |
| 10392 ** |
| 10393 ** This function is used to retrieve the total number of rows in the table. |
| 10394 ** In other words, the same value that would be returned by: |
| 10395 ** |
| 10396 ** SELECT count(*) FROM ftstable; |
| 10397 ** |
| 10398 ** xPhraseFirst() |
| 10399 ** This function is used, along with type Fts5PhraseIter and the xPhraseNext |
| 10400 ** method, to iterate through all instances of a single query phrase within |
| 10401 ** the current row. This is the same information as is accessible via the |
| 10402 ** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient |
| 10403 ** to use, this API may be faster under some circumstances. To iterate |
| 10404 ** through instances of phrase iPhrase, use the following code: |
| 10405 ** |
| 10406 ** Fts5PhraseIter iter; |
| 10407 ** int iCol, iOff; |
| 10408 ** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff); |
| 10409 ** iCol>=0; |
| 10410 ** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff) |
| 10411 ** ){ |
| 10412 ** // An instance of phrase iPhrase at offset iOff of column iCol |
| 10413 ** } |
| 10414 ** |
| 10415 ** The Fts5PhraseIter structure is defined above. Applications should not |
| 10416 ** modify this structure directly - it should only be used as shown above |
| 10417 ** with the xPhraseFirst() and xPhraseNext() API methods (and by |
| 10418 ** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below). |
| 10419 ** |
| 10420 ** This API can be quite slow if used with an FTS5 table created with the |
| 10421 ** "detail=none" or "detail=column" option. If the FTS5 table is created |
| 10422 ** with either "detail=none" or "detail=column" and "content=" option |
| 10423 ** (i.e. if it is a contentless table), then this API always iterates |
| 10424 ** through an empty set (all calls to xPhraseFirst() set iCol to -1). |
| 10425 ** |
| 10426 ** xPhraseNext() |
| 10427 ** See xPhraseFirst above. |
| 10428 ** |
| 10429 ** xPhraseFirstColumn() |
| 10430 ** This function and xPhraseNextColumn() are similar to the xPhraseFirst() |
| 10431 ** and xPhraseNext() APIs described above. The difference is that instead |
| 10432 ** of iterating through all instances of a phrase in the current row, these |
| 10433 ** APIs are used to iterate through the set of columns in the current row |
| 10434 ** that contain one or more instances of a specified phrase. For example: |
| 10435 ** |
| 10436 ** Fts5PhraseIter iter; |
| 10437 ** int iCol; |
| 10438 ** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol); |
| 10439 ** iCol>=0; |
| 10440 ** pApi->xPhraseNextColumn(pFts, &iter, &iCol) |
| 10441 ** ){ |
| 10442 ** // Column iCol contains at least one instance of phrase iPhrase |
| 10443 ** } |
| 10444 ** |
| 10445 ** This API can be quite slow if used with an FTS5 table created with the |
| 10446 ** "detail=none" option. If the FTS5 table is created with either |
| 10447 ** "detail=none" "content=" option (i.e. if it is a contentless table), |
| 10448 ** then this API always iterates through an empty set (all calls to |
| 10449 ** xPhraseFirstColumn() set iCol to -1). |
| 10450 ** |
| 10451 ** The information accessed using this API and its companion |
| 10452 ** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext |
| 10453 ** (or xInst/xInstCount). The chief advantage of this API is that it is |
| 10454 ** significantly more efficient than those alternatives when used with |
| 10455 ** "detail=column" tables. |
| 10456 ** |
| 10457 ** xPhraseNextColumn() |
| 10458 ** See xPhraseFirstColumn above. |
| 10459 */ |
| 10460 struct Fts5ExtensionApi { |
| 10461 int iVersion; /* Currently always set to 3 */ |
| 10462 |
| 10463 void *(*xUserData)(Fts5Context*); |
| 10464 |
| 10465 int (*xColumnCount)(Fts5Context*); |
| 10466 int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow); |
| 10467 int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken); |
| 10468 |
| 10469 int (*xTokenize)(Fts5Context*, |
| 10470 const char *pText, int nText, /* Text to tokenize */ |
| 10471 void *pCtx, /* Context passed to xToken() */ |
| 10472 int (*xToken)(void*, int, const char*, int, int, int) /* Callback */ |
| 10473 ); |
| 10474 |
| 10475 int (*xPhraseCount)(Fts5Context*); |
| 10476 int (*xPhraseSize)(Fts5Context*, int iPhrase); |
| 10477 |
| 10478 int (*xInstCount)(Fts5Context*, int *pnInst); |
| 10479 int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff); |
| 10480 |
| 10481 sqlite3_int64 (*xRowid)(Fts5Context*); |
| 10482 int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn); |
| 10483 int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken); |
| 10484 |
| 10485 int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData, |
| 10486 int(*)(const Fts5ExtensionApi*,Fts5Context*,void*) |
| 10487 ); |
| 10488 int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*)); |
| 10489 void *(*xGetAuxdata)(Fts5Context*, int bClear); |
| 10490 |
| 10491 int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*); |
| 10492 void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff); |
| 10493 |
| 10494 int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*); |
| 10495 void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol); |
| 10496 }; |
| 10497 |
| 10498 /* |
| 10499 ** CUSTOM AUXILIARY FUNCTIONS |
| 10500 *************************************************************************/ |
| 10501 |
| 10502 /************************************************************************* |
| 10503 ** CUSTOM TOKENIZERS |
| 10504 ** |
| 10505 ** Applications may also register custom tokenizer types. A tokenizer |
| 10506 ** is registered by providing fts5 with a populated instance of the |
| 10507 ** following structure. All structure methods must be defined, setting |
| 10508 ** any member of the fts5_tokenizer struct to NULL leads to undefined |
| 10509 ** behaviour. The structure methods are expected to function as follows: |
| 10510 ** |
| 10511 ** xCreate: |
| 10512 ** This function is used to allocate and initialize a tokenizer instance. |
| 10513 ** A tokenizer instance is required to actually tokenize text. |
| 10514 ** |
| 10515 ** The first argument passed to this function is a copy of the (void*) |
| 10516 ** pointer provided by the application when the fts5_tokenizer object |
| 10517 ** was registered with FTS5 (the third argument to xCreateTokenizer()). |
| 10518 ** The second and third arguments are an array of nul-terminated strings |
| 10519 ** containing the tokenizer arguments, if any, specified following the |
| 10520 ** tokenizer name as part of the CREATE VIRTUAL TABLE statement used |
| 10521 ** to create the FTS5 table. |
| 10522 ** |
| 10523 ** The final argument is an output variable. If successful, (*ppOut) |
| 10524 ** should be set to point to the new tokenizer handle and SQLITE_OK |
| 10525 ** returned. If an error occurs, some value other than SQLITE_OK should |
| 10526 ** be returned. In this case, fts5 assumes that the final value of *ppOut |
| 10527 ** is undefined. |
| 10528 ** |
| 10529 ** xDelete: |
| 10530 ** This function is invoked to delete a tokenizer handle previously |
| 10531 ** allocated using xCreate(). Fts5 guarantees that this function will |
| 10532 ** be invoked exactly once for each successful call to xCreate(). |
| 10533 ** |
| 10534 ** xTokenize: |
| 10535 ** This function is expected to tokenize the nText byte string indicated |
| 10536 ** by argument pText. pText may or may not be nul-terminated. The first |
| 10537 ** argument passed to this function is a pointer to an Fts5Tokenizer object |
| 10538 ** returned by an earlier call to xCreate(). |
| 10539 ** |
| 10540 ** The second argument indicates the reason that FTS5 is requesting |
| 10541 ** tokenization of the supplied text. This is always one of the following |
| 10542 ** four values: |
| 10543 ** |
| 10544 ** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into |
| 10545 ** or removed from the FTS table. The tokenizer is being invoked to |
| 10546 ** determine the set of tokens to add to (or delete from) the |
| 10547 ** FTS index. |
| 10548 ** |
| 10549 ** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed |
| 10550 ** against the FTS index. The tokenizer is being called to tokenize |
| 10551 ** a bareword or quoted string specified as part of the query. |
| 10552 ** |
| 10553 ** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as |
| 10554 ** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is |
| 10555 ** followed by a "*" character, indicating that the last token |
| 10556 ** returned by the tokenizer will be treated as a token prefix. |
| 10557 ** |
| 10558 ** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to |
| 10559 ** satisfy an fts5_api.xTokenize() request made by an auxiliary |
| 10560 ** function. Or an fts5_api.xColumnSize() request made by the same |
| 10561 ** on a columnsize=0 database. |
| 10562 ** </ul> |
| 10563 ** |
| 10564 ** For each token in the input string, the supplied callback xToken() must |
| 10565 ** be invoked. The first argument to it should be a copy of the pointer |
| 10566 ** passed as the second argument to xTokenize(). The third and fourth |
| 10567 ** arguments are a pointer to a buffer containing the token text, and the |
| 10568 ** size of the token in bytes. The 4th and 5th arguments are the byte offsets |
| 10569 ** of the first byte of and first byte immediately following the text from |
| 10570 ** which the token is derived within the input. |
| 10571 ** |
| 10572 ** The second argument passed to the xToken() callback ("tflags") should |
| 10573 ** normally be set to 0. The exception is if the tokenizer supports |
| 10574 ** synonyms. In this case see the discussion below for details. |
| 10575 ** |
| 10576 ** FTS5 assumes the xToken() callback is invoked for each token in the |
| 10577 ** order that they occur within the input text. |
| 10578 ** |
| 10579 ** If an xToken() callback returns any value other than SQLITE_OK, then |
| 10580 ** the tokenization should be abandoned and the xTokenize() method should |
| 10581 ** immediately return a copy of the xToken() return value. Or, if the |
| 10582 ** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally, |
| 10583 ** if an error occurs with the xTokenize() implementation itself, it |
| 10584 ** may abandon the tokenization and return any error code other than |
| 10585 ** SQLITE_OK or SQLITE_DONE. |
| 10586 ** |
| 10587 ** SYNONYM SUPPORT |
| 10588 ** |
| 10589 ** Custom tokenizers may also support synonyms. Consider a case in which a |
| 10590 ** user wishes to query for a phrase such as "first place". Using the |
| 10591 ** built-in tokenizers, the FTS5 query 'first + place' will match instances |
| 10592 ** of "first place" within the document set, but not alternative forms |
| 10593 ** such as "1st place". In some applications, it would be better to match |
| 10594 ** all instances of "first place" or "1st place" regardless of which form |
| 10595 ** the user specified in the MATCH query text. |
| 10596 ** |
| 10597 ** There are several ways to approach this in FTS5: |
| 10598 ** |
| 10599 ** <ol><li> By mapping all synonyms to a single token. In this case, the |
| 10600 ** In the above example, this means that the tokenizer returns the |
| 10601 ** same token for inputs "first" and "1st". Say that token is in |
| 10602 ** fact "first", so that when the user inserts the document "I won |
| 10603 ** 1st place" entries are added to the index for tokens "i", "won", |
| 10604 ** "first" and "place". If the user then queries for '1st + place', |
| 10605 ** the tokenizer substitutes "first" for "1st" and the query works |
| 10606 ** as expected. |
| 10607 ** |
| 10608 ** <li> By adding multiple synonyms for a single term to the FTS index. |
| 10609 ** In this case, when tokenizing query text, the tokenizer may |
| 10610 ** provide multiple synonyms for a single term within the document. |
| 10611 ** FTS5 then queries the index for each synonym individually. For |
| 10612 ** example, faced with the query: |
| 10613 ** |
| 10614 ** <codeblock> |
| 10615 ** ... MATCH 'first place'</codeblock> |
| 10616 ** |
| 10617 ** the tokenizer offers both "1st" and "first" as synonyms for the |
| 10618 ** first token in the MATCH query and FTS5 effectively runs a query |
| 10619 ** similar to: |
| 10620 ** |
| 10621 ** <codeblock> |
| 10622 ** ... MATCH '(first OR 1st) place'</codeblock> |
| 10623 ** |
| 10624 ** except that, for the purposes of auxiliary functions, the query |
| 10625 ** still appears to contain just two phrases - "(first OR 1st)" |
| 10626 ** being treated as a single phrase. |
| 10627 ** |
| 10628 ** <li> By adding multiple synonyms for a single term to the FTS index. |
| 10629 ** Using this method, when tokenizing document text, the tokenizer |
| 10630 ** provides multiple synonyms for each token. So that when a |
| 10631 ** document such as "I won first place" is tokenized, entries are |
| 10632 ** added to the FTS index for "i", "won", "first", "1st" and |
| 10633 ** "place". |
| 10634 ** |
| 10635 ** This way, even if the tokenizer does not provide synonyms |
| 10636 ** when tokenizing query text (it should not - to do would be |
| 10637 ** inefficient), it doesn't matter if the user queries for |
| 10638 ** 'first + place' or '1st + place', as there are entires in the |
| 10639 ** FTS index corresponding to both forms of the first token. |
| 10640 ** </ol> |
| 10641 ** |
| 10642 ** Whether it is parsing document or query text, any call to xToken that |
| 10643 ** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit |
| 10644 ** is considered to supply a synonym for the previous token. For example, |
| 10645 ** when parsing the document "I won first place", a tokenizer that supports |
| 10646 ** synonyms would call xToken() 5 times, as follows: |
| 10647 ** |
| 10648 ** <codeblock> |
| 10649 ** xToken(pCtx, 0, "i", 1, 0, 1); |
| 10650 ** xToken(pCtx, 0, "won", 3, 2, 5); |
| 10651 ** xToken(pCtx, 0, "first", 5, 6, 11); |
| 10652 ** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11); |
| 10653 ** xToken(pCtx, 0, "place", 5, 12, 17); |
| 10654 **</codeblock> |
| 10655 ** |
| 10656 ** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time |
| 10657 ** xToken() is called. Multiple synonyms may be specified for a single token |
| 10658 ** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence. |
| 10659 ** There is no limit to the number of synonyms that may be provided for a |
| 10660 ** single token. |
| 10661 ** |
| 10662 ** In many cases, method (1) above is the best approach. It does not add |
| 10663 ** extra data to the FTS index or require FTS5 to query for multiple terms, |
| 10664 ** so it is efficient in terms of disk space and query speed. However, it |
| 10665 ** does not support prefix queries very well. If, as suggested above, the |
| 10666 ** token "first" is subsituted for "1st" by the tokenizer, then the query: |
| 10667 ** |
| 10668 ** <codeblock> |
| 10669 ** ... MATCH '1s*'</codeblock> |
| 10670 ** |
| 10671 ** will not match documents that contain the token "1st" (as the tokenizer |
| 10672 ** will probably not map "1s" to any prefix of "first"). |
| 10673 ** |
| 10674 ** For full prefix support, method (3) may be preferred. In this case, |
| 10675 ** because the index contains entries for both "first" and "1st", prefix |
| 10676 ** queries such as 'fi*' or '1s*' will match correctly. However, because |
| 10677 ** extra entries are added to the FTS index, this method uses more space |
| 10678 ** within the database. |
| 10679 ** |
| 10680 ** Method (2) offers a midpoint between (1) and (3). Using this method, |
| 10681 ** a query such as '1s*' will match documents that contain the literal |
| 10682 ** token "1st", but not "first" (assuming the tokenizer is not able to |
| 10683 ** provide synonyms for prefixes). However, a non-prefix query like '1st' |
| 10684 ** will match against "1st" and "first". This method does not require |
| 10685 ** extra disk space, as no extra entries are added to the FTS index. |
| 10686 ** On the other hand, it may require more CPU cycles to run MATCH queries, |
| 10687 ** as separate queries of the FTS index are required for each synonym. |
| 10688 ** |
| 10689 ** When using methods (2) or (3), it is important that the tokenizer only |
| 10690 ** provide synonyms when tokenizing document text (method (2)) or query |
| 10691 ** text (method (3)), not both. Doing so will not cause any errors, but is |
| 10692 ** inefficient. |
| 10693 */ |
| 10694 typedef struct Fts5Tokenizer Fts5Tokenizer; |
| 10695 typedef struct fts5_tokenizer fts5_tokenizer; |
| 10696 struct fts5_tokenizer { |
| 10697 int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut); |
| 10698 void (*xDelete)(Fts5Tokenizer*); |
| 10699 int (*xTokenize)(Fts5Tokenizer*, |
| 10700 void *pCtx, |
| 10701 int flags, /* Mask of FTS5_TOKENIZE_* flags */ |
| 10702 const char *pText, int nText, |
| 10703 int (*xToken)( |
| 10704 void *pCtx, /* Copy of 2nd argument to xTokenize() */ |
| 10705 int tflags, /* Mask of FTS5_TOKEN_* flags */ |
| 10706 const char *pToken, /* Pointer to buffer containing token */ |
| 10707 int nToken, /* Size of token in bytes */ |
| 10708 int iStart, /* Byte offset of token within input text */ |
| 10709 int iEnd /* Byte offset of end of token within input text */ |
| 10710 ) |
| 10711 ); |
| 10712 }; |
| 10713 |
| 10714 /* Flags that may be passed as the third argument to xTokenize() */ |
| 10715 #define FTS5_TOKENIZE_QUERY 0x0001 |
| 10716 #define FTS5_TOKENIZE_PREFIX 0x0002 |
| 10717 #define FTS5_TOKENIZE_DOCUMENT 0x0004 |
| 10718 #define FTS5_TOKENIZE_AUX 0x0008 |
| 10719 |
| 10720 /* Flags that may be passed by the tokenizer implementation back to FTS5 |
| 10721 ** as the third argument to the supplied xToken callback. */ |
| 10722 #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */ |
| 10723 |
| 10724 /* |
| 10725 ** END OF CUSTOM TOKENIZERS |
| 10726 *************************************************************************/ |
| 10727 |
| 10728 /************************************************************************* |
| 10729 ** FTS5 EXTENSION REGISTRATION API |
| 10730 */ |
| 10731 typedef struct fts5_api fts5_api; |
| 10732 struct fts5_api { |
| 10733 int iVersion; /* Currently always set to 2 */ |
| 10734 |
| 10735 /* Create a new tokenizer */ |
| 10736 int (*xCreateTokenizer)( |
| 10737 fts5_api *pApi, |
| 10738 const char *zName, |
| 10739 void *pContext, |
| 10740 fts5_tokenizer *pTokenizer, |
| 10741 void (*xDestroy)(void*) |
| 10742 ); |
| 10743 |
| 10744 /* Find an existing tokenizer */ |
| 10745 int (*xFindTokenizer)( |
| 10746 fts5_api *pApi, |
| 10747 const char *zName, |
| 10748 void **ppContext, |
| 10749 fts5_tokenizer *pTokenizer |
| 10750 ); |
| 10751 |
| 10752 /* Create a new auxiliary function */ |
| 10753 int (*xCreateFunction)( |
| 10754 fts5_api *pApi, |
| 10755 const char *zName, |
| 10756 void *pContext, |
| 10757 fts5_extension_function xFunction, |
| 10758 void (*xDestroy)(void*) |
| 10759 ); |
| 10760 }; |
| 10761 |
| 10762 /* |
| 10763 ** END OF REGISTRATION API |
| 10764 *************************************************************************/ |
| 10765 |
| 10766 #if 0 |
| 10767 } /* end of the 'extern "C"' block */ |
| 10768 #endif |
| 10769 |
| 10770 #endif /* _FTS5_H */ |
| 10771 |
| 10772 /******** End of fts5.h *********/ |
| 10773 |
| 10774 /************** End of sqlite3.h *********************************************/ |
| 10775 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 10776 |
| 10777 /* |
| 10778 ** Include the configuration header output by 'configure' if we're using the |
| 10779 ** autoconf-based build |
| 10780 */ |
| 10781 #ifdef _HAVE_SQLITE_CONFIG_H |
| 10782 #include "config.h" |
| 10783 #endif |
| 10784 |
| 10785 /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/ |
| 10786 /************** Begin file sqliteLimit.h *************************************/ |
| 10787 /* |
| 10788 ** 2007 May 7 |
| 10789 ** |
| 10790 ** The author disclaims copyright to this source code. In place of |
| 10791 ** a legal notice, here is a blessing: |
| 10792 ** |
| 10793 ** May you do good and not evil. |
| 10794 ** May you find forgiveness for yourself and forgive others. |
| 10795 ** May you share freely, never taking more than you give. |
| 10796 ** |
| 10797 ************************************************************************* |
| 10798 ** |
| 10799 ** This file defines various limits of what SQLite can process. |
| 10800 */ |
| 10801 |
| 10802 /* |
| 10803 ** The maximum length of a TEXT or BLOB in bytes. This also |
| 10804 ** limits the size of a row in a table or index. |
| 10805 ** |
| 10806 ** The hard limit is the ability of a 32-bit signed integer |
| 10807 ** to count the size: 2^31-1 or 2147483647. |
| 10808 */ |
| 10809 #ifndef SQLITE_MAX_LENGTH |
| 10810 # define SQLITE_MAX_LENGTH 1000000000 |
| 10811 #endif |
| 10812 |
| 10813 /* |
| 10814 ** This is the maximum number of |
| 10815 ** |
| 10816 ** * Columns in a table |
| 10817 ** * Columns in an index |
| 10818 ** * Columns in a view |
| 10819 ** * Terms in the SET clause of an UPDATE statement |
| 10820 ** * Terms in the result set of a SELECT statement |
| 10821 ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. |
| 10822 ** * Terms in the VALUES clause of an INSERT statement |
| 10823 ** |
| 10824 ** The hard upper limit here is 32676. Most database people will |
| 10825 ** tell you that in a well-normalized database, you usually should |
| 10826 ** not have more than a dozen or so columns in any table. And if |
| 10827 ** that is the case, there is no point in having more than a few |
| 10828 ** dozen values in any of the other situations described above. |
| 10829 */ |
| 10830 #ifndef SQLITE_MAX_COLUMN |
| 10831 # define SQLITE_MAX_COLUMN 2000 |
| 10832 #endif |
| 10833 |
| 10834 /* |
| 10835 ** The maximum length of a single SQL statement in bytes. |
| 10836 ** |
| 10837 ** It used to be the case that setting this value to zero would |
| 10838 ** turn the limit off. That is no longer true. It is not possible |
| 10839 ** to turn this limit off. |
| 10840 */ |
| 10841 #ifndef SQLITE_MAX_SQL_LENGTH |
| 10842 # define SQLITE_MAX_SQL_LENGTH 1000000000 |
| 10843 #endif |
| 10844 |
| 10845 /* |
| 10846 ** The maximum depth of an expression tree. This is limited to |
| 10847 ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might |
| 10848 ** want to place more severe limits on the complexity of an |
| 10849 ** expression. |
| 10850 ** |
| 10851 ** A value of 0 used to mean that the limit was not enforced. |
| 10852 ** But that is no longer true. The limit is now strictly enforced |
| 10853 ** at all times. |
| 10854 */ |
| 10855 #ifndef SQLITE_MAX_EXPR_DEPTH |
| 10856 # define SQLITE_MAX_EXPR_DEPTH 1000 |
| 10857 #endif |
| 10858 |
| 10859 /* |
| 10860 ** The maximum number of terms in a compound SELECT statement. |
| 10861 ** The code generator for compound SELECT statements does one |
| 10862 ** level of recursion for each term. A stack overflow can result |
| 10863 ** if the number of terms is too large. In practice, most SQL |
| 10864 ** never has more than 3 or 4 terms. Use a value of 0 to disable |
| 10865 ** any limit on the number of terms in a compount SELECT. |
| 10866 */ |
| 10867 #ifndef SQLITE_MAX_COMPOUND_SELECT |
| 10868 # define SQLITE_MAX_COMPOUND_SELECT 500 |
| 10869 #endif |
| 10870 |
| 10871 /* |
| 10872 ** The maximum number of opcodes in a VDBE program. |
| 10873 ** Not currently enforced. |
| 10874 */ |
| 10875 #ifndef SQLITE_MAX_VDBE_OP |
| 10876 # define SQLITE_MAX_VDBE_OP 25000 |
| 10877 #endif |
| 10878 |
| 10879 /* |
| 10880 ** The maximum number of arguments to an SQL function. |
| 10881 */ |
| 10882 #ifndef SQLITE_MAX_FUNCTION_ARG |
| 10883 # define SQLITE_MAX_FUNCTION_ARG 127 |
| 10884 #endif |
| 10885 |
| 10886 /* |
| 10887 ** The suggested maximum number of in-memory pages to use for |
| 10888 ** the main database table and for temporary tables. |
| 10889 ** |
| 10890 ** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000, |
| 10891 ** which means the cache size is limited to 2048000 bytes of memory. |
| 10892 ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be |
| 10893 ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options. |
| 10894 */ |
| 10895 #ifndef SQLITE_DEFAULT_CACHE_SIZE |
| 10896 # define SQLITE_DEFAULT_CACHE_SIZE -2000 |
| 10897 #endif |
| 10898 |
| 10899 /* |
| 10900 ** The default number of frames to accumulate in the log file before |
| 10901 ** checkpointing the database in WAL mode. |
| 10902 */ |
| 10903 #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT |
| 10904 # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 |
| 10905 #endif |
| 10906 |
| 10907 /* |
| 10908 ** The maximum number of attached databases. This must be between 0 |
| 10909 ** and 125. The upper bound of 125 is because the attached databases are |
| 10910 ** counted using a signed 8-bit integer which has a maximum value of 127 |
| 10911 ** and we have to allow 2 extra counts for the "main" and "temp" databases. |
| 10912 */ |
| 10913 #ifndef SQLITE_MAX_ATTACHED |
| 10914 # define SQLITE_MAX_ATTACHED 10 |
| 10915 #endif |
| 10916 |
| 10917 |
| 10918 /* |
| 10919 ** The maximum value of a ?nnn wildcard that the parser will accept. |
| 10920 */ |
| 10921 #ifndef SQLITE_MAX_VARIABLE_NUMBER |
| 10922 # define SQLITE_MAX_VARIABLE_NUMBER 999 |
| 10923 #endif |
| 10924 |
| 10925 /* Maximum page size. The upper bound on this value is 65536. This a limit |
| 10926 ** imposed by the use of 16-bit offsets within each page. |
| 10927 ** |
| 10928 ** Earlier versions of SQLite allowed the user to change this value at |
| 10929 ** compile time. This is no longer permitted, on the grounds that it creates |
| 10930 ** a library that is technically incompatible with an SQLite library |
| 10931 ** compiled with a different limit. If a process operating on a database |
| 10932 ** with a page-size of 65536 bytes crashes, then an instance of SQLite |
| 10933 ** compiled with the default page-size limit will not be able to rollback |
| 10934 ** the aborted transaction. This could lead to database corruption. |
| 10935 */ |
| 10936 #ifdef SQLITE_MAX_PAGE_SIZE |
| 10937 # undef SQLITE_MAX_PAGE_SIZE |
| 10938 #endif |
| 10939 #define SQLITE_MAX_PAGE_SIZE 65536 |
| 10940 |
| 10941 |
| 10942 /* |
| 10943 ** The default size of a database page. |
| 10944 */ |
| 10945 #ifndef SQLITE_DEFAULT_PAGE_SIZE |
| 10946 # define SQLITE_DEFAULT_PAGE_SIZE 4096 |
| 10947 #endif |
| 10948 #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 10949 # undef SQLITE_DEFAULT_PAGE_SIZE |
| 10950 # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 10951 #endif |
| 10952 |
| 10953 /* |
| 10954 ** Ordinarily, if no value is explicitly provided, SQLite creates databases |
| 10955 ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain |
| 10956 ** device characteristics (sector-size and atomic write() support), |
| 10957 ** SQLite may choose a larger value. This constant is the maximum value |
| 10958 ** SQLite will choose on its own. |
| 10959 */ |
| 10960 #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 10961 # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 |
| 10962 #endif |
| 10963 #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE |
| 10964 # undef SQLITE_MAX_DEFAULT_PAGE_SIZE |
| 10965 # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE |
| 10966 #endif |
| 10967 |
| 10968 |
| 10969 /* |
| 10970 ** Maximum number of pages in one database file. |
| 10971 ** |
| 10972 ** This is really just the default value for the max_page_count pragma. |
| 10973 ** This value can be lowered (or raised) at run-time using that the |
| 10974 ** max_page_count macro. |
| 10975 */ |
| 10976 #ifndef SQLITE_MAX_PAGE_COUNT |
| 10977 # define SQLITE_MAX_PAGE_COUNT 1073741823 |
| 10978 #endif |
| 10979 |
| 10980 /* |
| 10981 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB |
| 10982 ** operator. |
| 10983 */ |
| 10984 #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| 10985 # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 |
| 10986 #endif |
| 10987 |
| 10988 /* |
| 10989 ** Maximum depth of recursion for triggers. |
| 10990 ** |
| 10991 ** A value of 1 means that a trigger program will not be able to itself |
| 10992 ** fire any triggers. A value of 0 means that no trigger programs at all |
| 10993 ** may be executed. |
| 10994 */ |
| 10995 #ifndef SQLITE_MAX_TRIGGER_DEPTH |
| 10996 # define SQLITE_MAX_TRIGGER_DEPTH 1000 |
| 10997 #endif |
| 10998 |
| 10999 /************** End of sqliteLimit.h *****************************************/ |
| 11000 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 11001 |
| 11002 /* Disable nuisance warnings on Borland compilers */ |
| 11003 #if defined(__BORLANDC__) |
| 11004 #pragma warn -rch /* unreachable code */ |
| 11005 #pragma warn -ccc /* Condition is always true or false */ |
| 11006 #pragma warn -aus /* Assigned value is never used */ |
| 11007 #pragma warn -csu /* Comparing signed and unsigned */ |
| 11008 #pragma warn -spa /* Suspicious pointer arithmetic */ |
| 11009 #endif |
| 11010 |
| 11011 /* |
| 11012 ** Include standard header files as necessary |
| 11013 */ |
| 11014 #ifdef HAVE_STDINT_H |
| 11015 #include <stdint.h> |
| 11016 #endif |
| 11017 #ifdef HAVE_INTTYPES_H |
| 11018 #include <inttypes.h> |
| 11019 #endif |
| 11020 |
| 11021 /* |
| 11022 ** The following macros are used to cast pointers to integers and |
| 11023 ** integers to pointers. The way you do this varies from one compiler |
| 11024 ** to the next, so we have developed the following set of #if statements |
| 11025 ** to generate appropriate macros for a wide range of compilers. |
| 11026 ** |
| 11027 ** The correct "ANSI" way to do this is to use the intptr_t type. |
| 11028 ** Unfortunately, that typedef is not available on all compilers, or |
| 11029 ** if it is available, it requires an #include of specific headers |
| 11030 ** that vary from one machine to the next. |
| 11031 ** |
| 11032 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on |
| 11033 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). |
| 11034 ** So we have to define the macros in different ways depending on the |
| 11035 ** compiler. |
| 11036 */ |
| 11037 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ |
| 11038 # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) |
| 11039 # define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) |
| 11040 #elif !defined(__GNUC__) /* Works for compilers other than LLVM */ |
| 11041 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) |
| 11042 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) |
| 11043 #elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */ |
| 11044 # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) |
| 11045 # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) |
| 11046 #else /* Generates a warning - but it always works */ |
| 11047 # define SQLITE_INT_TO_PTR(X) ((void*)(X)) |
| 11048 # define SQLITE_PTR_TO_INT(X) ((int)(X)) |
| 11049 #endif |
| 11050 |
| 11051 /* |
| 11052 ** A macro to hint to the compiler that a function should not be |
| 11053 ** inlined. |
| 11054 */ |
| 11055 #if defined(__GNUC__) |
| 11056 # define SQLITE_NOINLINE __attribute__((noinline)) |
| 11057 #elif defined(_MSC_VER) && _MSC_VER>=1310 |
| 11058 # define SQLITE_NOINLINE __declspec(noinline) |
| 11059 #else |
| 11060 # define SQLITE_NOINLINE |
| 11061 #endif |
| 11062 |
| 11063 /* |
| 11064 ** Make sure that the compiler intrinsics we desire are enabled when |
| 11065 ** compiling with an appropriate version of MSVC unless prevented by |
| 11066 ** the SQLITE_DISABLE_INTRINSIC define. |
| 11067 */ |
| 11068 #if !defined(SQLITE_DISABLE_INTRINSIC) |
| 11069 # if defined(_MSC_VER) && _MSC_VER>=1400 |
| 11070 # if !defined(_WIN32_WCE) |
| 11071 # include <intrin.h> |
| 11072 # pragma intrinsic(_byteswap_ushort) |
| 11073 # pragma intrinsic(_byteswap_ulong) |
| 11074 # pragma intrinsic(_byteswap_uint64) |
| 11075 # pragma intrinsic(_ReadWriteBarrier) |
| 11076 # else |
| 11077 # include <cmnintrin.h> |
| 11078 # endif |
| 11079 # endif |
| 11080 #endif |
| 11081 |
| 11082 /* |
| 11083 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. |
| 11084 ** 0 means mutexes are permanently disable and the library is never |
| 11085 ** threadsafe. 1 means the library is serialized which is the highest |
| 11086 ** level of threadsafety. 2 means the library is multithreaded - multiple |
| 11087 ** threads can use SQLite as long as no two threads try to use the same |
| 11088 ** database connection at the same time. |
| 11089 ** |
| 11090 ** Older versions of SQLite used an optional THREADSAFE macro. |
| 11091 ** We support that for legacy. |
| 11092 */ |
| 11093 #if !defined(SQLITE_THREADSAFE) |
| 11094 # if defined(THREADSAFE) |
| 11095 # define SQLITE_THREADSAFE THREADSAFE |
| 11096 # else |
| 11097 # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ |
| 11098 # endif |
| 11099 #endif |
| 11100 |
| 11101 /* |
| 11102 ** Powersafe overwrite is on by default. But can be turned off using |
| 11103 ** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option. |
| 11104 */ |
| 11105 #ifndef SQLITE_POWERSAFE_OVERWRITE |
| 11106 # define SQLITE_POWERSAFE_OVERWRITE 1 |
| 11107 #endif |
| 11108 |
| 11109 /* |
| 11110 ** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by |
| 11111 ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in |
| 11112 ** which case memory allocation statistics are disabled by default. |
| 11113 */ |
| 11114 #if !defined(SQLITE_DEFAULT_MEMSTATUS) |
| 11115 # define SQLITE_DEFAULT_MEMSTATUS 1 |
| 11116 #endif |
| 11117 |
| 11118 /* |
| 11119 ** Exactly one of the following macros must be defined in order to |
| 11120 ** specify which memory allocation subsystem to use. |
| 11121 ** |
| 11122 ** SQLITE_SYSTEM_MALLOC // Use normal system malloc() |
| 11123 ** SQLITE_WIN32_MALLOC // Use Win32 native heap API |
| 11124 ** SQLITE_ZERO_MALLOC // Use a stub allocator that always fails |
| 11125 ** SQLITE_MEMDEBUG // Debugging version of system malloc() |
| 11126 ** |
| 11127 ** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the |
| 11128 ** assert() macro is enabled, each call into the Win32 native heap subsystem |
| 11129 ** will cause HeapValidate to be called. If heap validation should fail, an |
| 11130 ** assertion will be triggered. |
| 11131 ** |
| 11132 ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as |
| 11133 ** the default. |
| 11134 */ |
| 11135 #if defined(SQLITE_SYSTEM_MALLOC) \ |
| 11136 + defined(SQLITE_WIN32_MALLOC) \ |
| 11137 + defined(SQLITE_ZERO_MALLOC) \ |
| 11138 + defined(SQLITE_MEMDEBUG)>1 |
| 11139 # error "Two or more of the following compile-time configuration options\ |
| 11140 are defined but at most one is allowed:\ |
| 11141 SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG,\ |
| 11142 SQLITE_ZERO_MALLOC" |
| 11143 #endif |
| 11144 #if defined(SQLITE_SYSTEM_MALLOC) \ |
| 11145 + defined(SQLITE_WIN32_MALLOC) \ |
| 11146 + defined(SQLITE_ZERO_MALLOC) \ |
| 11147 + defined(SQLITE_MEMDEBUG)==0 |
| 11148 # define SQLITE_SYSTEM_MALLOC 1 |
| 11149 #endif |
| 11150 |
| 11151 /* |
| 11152 ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the |
| 11153 ** sizes of memory allocations below this value where possible. |
| 11154 */ |
| 11155 #if !defined(SQLITE_MALLOC_SOFT_LIMIT) |
| 11156 # define SQLITE_MALLOC_SOFT_LIMIT 1024 |
| 11157 #endif |
| 11158 |
| 11159 /* |
| 11160 ** We need to define _XOPEN_SOURCE as follows in order to enable |
| 11161 ** recursive mutexes on most Unix systems and fchmod() on OpenBSD. |
| 11162 ** But _XOPEN_SOURCE define causes problems for Mac OS X, so omit |
| 11163 ** it. |
| 11164 */ |
| 11165 #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) |
| 11166 # define _XOPEN_SOURCE 600 |
| 11167 #endif |
| 11168 |
| 11169 /* |
| 11170 ** NDEBUG and SQLITE_DEBUG are opposites. It should always be true that |
| 11171 ** defined(NDEBUG)==!defined(SQLITE_DEBUG). If this is not currently true, |
| 11172 ** make it true by defining or undefining NDEBUG. |
| 11173 ** |
| 11174 ** Setting NDEBUG makes the code smaller and faster by disabling the |
| 11175 ** assert() statements in the code. So we want the default action |
| 11176 ** to be for NDEBUG to be set and NDEBUG to be undefined only if SQLITE_DEBUG |
| 11177 ** is set. Thus NDEBUG becomes an opt-in rather than an opt-out |
| 11178 ** feature. |
| 11179 */ |
| 11180 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
| 11181 # define NDEBUG 1 |
| 11182 #endif |
| 11183 #if defined(NDEBUG) && defined(SQLITE_DEBUG) |
| 11184 # undef NDEBUG |
| 11185 #endif |
| 11186 |
| 11187 /* |
| 11188 ** Enable SQLITE_ENABLE_EXPLAIN_COMMENTS if SQLITE_DEBUG is turned on. |
| 11189 */ |
| 11190 #if !defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) && defined(SQLITE_DEBUG) |
| 11191 # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1 |
| 11192 #endif |
| 11193 |
| 11194 /* |
| 11195 ** The testcase() macro is used to aid in coverage testing. When |
| 11196 ** doing coverage testing, the condition inside the argument to |
| 11197 ** testcase() must be evaluated both true and false in order to |
| 11198 ** get full branch coverage. The testcase() macro is inserted |
| 11199 ** to help ensure adequate test coverage in places where simple |
| 11200 ** condition/decision coverage is inadequate. For example, testcase() |
| 11201 ** can be used to make sure boundary values are tested. For |
| 11202 ** bitmask tests, testcase() can be used to make sure each bit |
| 11203 ** is significant and used at least once. On switch statements |
| 11204 ** where multiple cases go to the same block of code, testcase() |
| 11205 ** can insure that all cases are evaluated. |
| 11206 ** |
| 11207 */ |
| 11208 #ifdef SQLITE_COVERAGE_TEST |
| 11209 SQLITE_PRIVATE void sqlite3Coverage(int); |
| 11210 # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } |
| 11211 #else |
| 11212 # define testcase(X) |
| 11213 #endif |
| 11214 |
| 11215 /* |
| 11216 ** The TESTONLY macro is used to enclose variable declarations or |
| 11217 ** other bits of code that are needed to support the arguments |
| 11218 ** within testcase() and assert() macros. |
| 11219 */ |
| 11220 #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) |
| 11221 # define TESTONLY(X) X |
| 11222 #else |
| 11223 # define TESTONLY(X) |
| 11224 #endif |
| 11225 |
| 11226 /* |
| 11227 ** Sometimes we need a small amount of code such as a variable initialization |
| 11228 ** to setup for a later assert() statement. We do not want this code to |
| 11229 ** appear when assert() is disabled. The following macro is therefore |
| 11230 ** used to contain that setup code. The "VVA" acronym stands for |
| 11231 ** "Verification, Validation, and Accreditation". In other words, the |
| 11232 ** code within VVA_ONLY() will only run during verification processes. |
| 11233 */ |
| 11234 #ifndef NDEBUG |
| 11235 # define VVA_ONLY(X) X |
| 11236 #else |
| 11237 # define VVA_ONLY(X) |
| 11238 #endif |
| 11239 |
| 11240 /* |
| 11241 ** The ALWAYS and NEVER macros surround boolean expressions which |
| 11242 ** are intended to always be true or false, respectively. Such |
| 11243 ** expressions could be omitted from the code completely. But they |
| 11244 ** are included in a few cases in order to enhance the resilience |
| 11245 ** of SQLite to unexpected behavior - to make the code "self-healing" |
| 11246 ** or "ductile" rather than being "brittle" and crashing at the first |
| 11247 ** hint of unplanned behavior. |
| 11248 ** |
| 11249 ** In other words, ALWAYS and NEVER are added for defensive code. |
| 11250 ** |
| 11251 ** When doing coverage testing ALWAYS and NEVER are hard-coded to |
| 11252 ** be true and false so that the unreachable code they specify will |
| 11253 ** not be counted as untested code. |
| 11254 */ |
| 11255 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 11256 # define ALWAYS(X) (1) |
| 11257 # define NEVER(X) (0) |
| 11258 #elif !defined(NDEBUG) |
| 11259 # define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 11260 # define NEVER(X) ((X)?(assert(0),1):0) |
| 11261 #else |
| 11262 # define ALWAYS(X) (X) |
| 11263 # define NEVER(X) (X) |
| 11264 #endif |
| 11265 |
| 11266 /* |
| 11267 ** Some malloc failures are only possible if SQLITE_TEST_REALLOC_STRESS is |
| 11268 ** defined. We need to defend against those failures when testing with |
| 11269 ** SQLITE_TEST_REALLOC_STRESS, but we don't want the unreachable branches |
| 11270 ** during a normal build. The following macro can be used to disable tests |
| 11271 ** that are always false except when SQLITE_TEST_REALLOC_STRESS is set. |
| 11272 */ |
| 11273 #if defined(SQLITE_TEST_REALLOC_STRESS) |
| 11274 # define ONLY_IF_REALLOC_STRESS(X) (X) |
| 11275 #elif !defined(NDEBUG) |
| 11276 # define ONLY_IF_REALLOC_STRESS(X) ((X)?(assert(0),1):0) |
| 11277 #else |
| 11278 # define ONLY_IF_REALLOC_STRESS(X) (0) |
| 11279 #endif |
| 11280 |
| 11281 /* |
| 11282 ** Declarations used for tracing the operating system interfaces. |
| 11283 */ |
| 11284 #if defined(SQLITE_FORCE_OS_TRACE) || defined(SQLITE_TEST) || \ |
| 11285 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) |
| 11286 extern int sqlite3OSTrace; |
| 11287 # define OSTRACE(X) if( sqlite3OSTrace ) sqlite3DebugPrintf X |
| 11288 # define SQLITE_HAVE_OS_TRACE |
| 11289 #else |
| 11290 # define OSTRACE(X) |
| 11291 # undef SQLITE_HAVE_OS_TRACE |
| 11292 #endif |
| 11293 |
| 11294 /* |
| 11295 ** Is the sqlite3ErrName() function needed in the build? Currently, |
| 11296 ** it is needed by "mutex_w32.c" (when debugging), "os_win.c" (when |
| 11297 ** OSTRACE is enabled), and by several "test*.c" files (which are |
| 11298 ** compiled using SQLITE_TEST). |
| 11299 */ |
| 11300 #if defined(SQLITE_HAVE_OS_TRACE) || defined(SQLITE_TEST) || \ |
| 11301 (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) |
| 11302 # define SQLITE_NEED_ERR_NAME |
| 11303 #else |
| 11304 # undef SQLITE_NEED_ERR_NAME |
| 11305 #endif |
| 11306 |
| 11307 /* |
| 11308 ** SQLITE_ENABLE_EXPLAIN_COMMENTS is incompatible with SQLITE_OMIT_EXPLAIN |
| 11309 */ |
| 11310 #ifdef SQLITE_OMIT_EXPLAIN |
| 11311 # undef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 11312 #endif |
| 11313 |
| 11314 /* |
| 11315 ** Return true (non-zero) if the input is an integer that is too large |
| 11316 ** to fit in 32-bits. This macro is used inside of various testcase() |
| 11317 ** macros to verify that we have tested SQLite for large-file support. |
| 11318 */ |
| 11319 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) |
| 11320 |
| 11321 /* |
| 11322 ** The macro unlikely() is a hint that surrounds a boolean |
| 11323 ** expression that is usually false. Macro likely() surrounds |
| 11324 ** a boolean expression that is usually true. These hints could, |
| 11325 ** in theory, be used by the compiler to generate better code, but |
| 11326 ** currently they are just comments for human readers. |
| 11327 */ |
| 11328 #define likely(X) (X) |
| 11329 #define unlikely(X) (X) |
| 11330 |
| 11331 /************** Include hash.h in the middle of sqliteInt.h ******************/ |
| 11332 /************** Begin file hash.h ********************************************/ |
| 11333 /* |
| 11334 ** 2001 September 22 |
| 11335 ** |
| 11336 ** The author disclaims copyright to this source code. In place of |
| 11337 ** a legal notice, here is a blessing: |
| 11338 ** |
| 11339 ** May you do good and not evil. |
| 11340 ** May you find forgiveness for yourself and forgive others. |
| 11341 ** May you share freely, never taking more than you give. |
| 11342 ** |
| 11343 ************************************************************************* |
| 11344 ** This is the header file for the generic hash-table implementation |
| 11345 ** used in SQLite. |
| 11346 */ |
| 11347 #ifndef SQLITE_HASH_H |
| 11348 #define SQLITE_HASH_H |
| 11349 |
| 11350 /* Forward declarations of structures. */ |
| 11351 typedef struct Hash Hash; |
| 11352 typedef struct HashElem HashElem; |
| 11353 |
| 11354 /* A complete hash table is an instance of the following structure. |
| 11355 ** The internals of this structure are intended to be opaque -- client |
| 11356 ** code should not attempt to access or modify the fields of this structure |
| 11357 ** directly. Change this structure only by using the routines below. |
| 11358 ** However, some of the "procedures" and "functions" for modifying and |
| 11359 ** accessing this structure are really macros, so we can't really make |
| 11360 ** this structure opaque. |
| 11361 ** |
| 11362 ** All elements of the hash table are on a single doubly-linked list. |
| 11363 ** Hash.first points to the head of this list. |
| 11364 ** |
| 11365 ** There are Hash.htsize buckets. Each bucket points to a spot in |
| 11366 ** the global doubly-linked list. The contents of the bucket are the |
| 11367 ** element pointed to plus the next _ht.count-1 elements in the list. |
| 11368 ** |
| 11369 ** Hash.htsize and Hash.ht may be zero. In that case lookup is done |
| 11370 ** by a linear search of the global list. For small tables, the |
| 11371 ** Hash.ht table is never allocated because if there are few elements |
| 11372 ** in the table, it is faster to do a linear search than to manage |
| 11373 ** the hash table. |
| 11374 */ |
| 11375 struct Hash { |
| 11376 unsigned int htsize; /* Number of buckets in the hash table */ |
| 11377 unsigned int count; /* Number of entries in this table */ |
| 11378 HashElem *first; /* The first element of the array */ |
| 11379 struct _ht { /* the hash table */ |
| 11380 int count; /* Number of entries with this hash */ |
| 11381 HashElem *chain; /* Pointer to first entry with this hash */ |
| 11382 } *ht; |
| 11383 }; |
| 11384 |
| 11385 /* Each element in the hash table is an instance of the following |
| 11386 ** structure. All elements are stored on a single doubly-linked list. |
| 11387 ** |
| 11388 ** Again, this structure is intended to be opaque, but it can't really |
| 11389 ** be opaque because it is used by macros. |
| 11390 */ |
| 11391 struct HashElem { |
| 11392 HashElem *next, *prev; /* Next and previous elements in the table */ |
| 11393 void *data; /* Data associated with this element */ |
| 11394 const char *pKey; /* Key associated with this element */ |
| 11395 }; |
| 11396 |
| 11397 /* |
| 11398 ** Access routines. To delete, insert a NULL pointer. |
| 11399 */ |
| 11400 SQLITE_PRIVATE void sqlite3HashInit(Hash*); |
| 11401 SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const char *pKey, void *pData); |
| 11402 SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const char *pKey); |
| 11403 SQLITE_PRIVATE void sqlite3HashClear(Hash*); |
| 11404 |
| 11405 /* |
| 11406 ** Macros for looping over all elements of a hash table. The idiom is |
| 11407 ** like this: |
| 11408 ** |
| 11409 ** Hash h; |
| 11410 ** HashElem *p; |
| 11411 ** ... |
| 11412 ** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){ |
| 11413 ** SomeStructure *pData = sqliteHashData(p); |
| 11414 ** // do something with pData |
| 11415 ** } |
| 11416 */ |
| 11417 #define sqliteHashFirst(H) ((H)->first) |
| 11418 #define sqliteHashNext(E) ((E)->next) |
| 11419 #define sqliteHashData(E) ((E)->data) |
| 11420 /* #define sqliteHashKey(E) ((E)->pKey) // NOT USED */ |
| 11421 /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ |
| 11422 |
| 11423 /* |
| 11424 ** Number of entries in a hash table |
| 11425 */ |
| 11426 /* #define sqliteHashCount(H) ((H)->count) // NOT USED */ |
| 11427 |
| 11428 #endif /* SQLITE_HASH_H */ |
| 11429 |
| 11430 /************** End of hash.h ************************************************/ |
| 11431 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 11432 /************** Include parse.h in the middle of sqliteInt.h *****************/ |
| 11433 /************** Begin file parse.h *******************************************/ |
| 11434 #define TK_SEMI 1 |
| 11435 #define TK_EXPLAIN 2 |
| 11436 #define TK_QUERY 3 |
| 11437 #define TK_PLAN 4 |
| 11438 #define TK_BEGIN 5 |
| 11439 #define TK_TRANSACTION 6 |
| 11440 #define TK_DEFERRED 7 |
| 11441 #define TK_IMMEDIATE 8 |
| 11442 #define TK_EXCLUSIVE 9 |
| 11443 #define TK_COMMIT 10 |
| 11444 #define TK_END 11 |
| 11445 #define TK_ROLLBACK 12 |
| 11446 #define TK_SAVEPOINT 13 |
| 11447 #define TK_RELEASE 14 |
| 11448 #define TK_TO 15 |
| 11449 #define TK_TABLE 16 |
| 11450 #define TK_CREATE 17 |
| 11451 #define TK_IF 18 |
| 11452 #define TK_NOT 19 |
| 11453 #define TK_EXISTS 20 |
| 11454 #define TK_TEMP 21 |
| 11455 #define TK_LP 22 |
| 11456 #define TK_RP 23 |
| 11457 #define TK_AS 24 |
| 11458 #define TK_WITHOUT 25 |
| 11459 #define TK_COMMA 26 |
| 11460 #define TK_OR 27 |
| 11461 #define TK_AND 28 |
| 11462 #define TK_IS 29 |
| 11463 #define TK_MATCH 30 |
| 11464 #define TK_LIKE_KW 31 |
| 11465 #define TK_BETWEEN 32 |
| 11466 #define TK_IN 33 |
| 11467 #define TK_ISNULL 34 |
| 11468 #define TK_NOTNULL 35 |
| 11469 #define TK_NE 36 |
| 11470 #define TK_EQ 37 |
| 11471 #define TK_GT 38 |
| 11472 #define TK_LE 39 |
| 11473 #define TK_LT 40 |
| 11474 #define TK_GE 41 |
| 11475 #define TK_ESCAPE 42 |
| 11476 #define TK_BITAND 43 |
| 11477 #define TK_BITOR 44 |
| 11478 #define TK_LSHIFT 45 |
| 11479 #define TK_RSHIFT 46 |
| 11480 #define TK_PLUS 47 |
| 11481 #define TK_MINUS 48 |
| 11482 #define TK_STAR 49 |
| 11483 #define TK_SLASH 50 |
| 11484 #define TK_REM 51 |
| 11485 #define TK_CONCAT 52 |
| 11486 #define TK_COLLATE 53 |
| 11487 #define TK_BITNOT 54 |
| 11488 #define TK_ID 55 |
| 11489 #define TK_INDEXED 56 |
| 11490 #define TK_ABORT 57 |
| 11491 #define TK_ACTION 58 |
| 11492 #define TK_AFTER 59 |
| 11493 #define TK_ANALYZE 60 |
| 11494 #define TK_ASC 61 |
| 11495 #define TK_ATTACH 62 |
| 11496 #define TK_BEFORE 63 |
| 11497 #define TK_BY 64 |
| 11498 #define TK_CASCADE 65 |
| 11499 #define TK_CAST 66 |
| 11500 #define TK_COLUMNKW 67 |
| 11501 #define TK_CONFLICT 68 |
| 11502 #define TK_DATABASE 69 |
| 11503 #define TK_DESC 70 |
| 11504 #define TK_DETACH 71 |
| 11505 #define TK_EACH 72 |
| 11506 #define TK_FAIL 73 |
| 11507 #define TK_FOR 74 |
| 11508 #define TK_IGNORE 75 |
| 11509 #define TK_INITIALLY 76 |
| 11510 #define TK_INSTEAD 77 |
| 11511 #define TK_NO 78 |
| 11512 #define TK_KEY 79 |
| 11513 #define TK_OF 80 |
| 11514 #define TK_OFFSET 81 |
| 11515 #define TK_PRAGMA 82 |
| 11516 #define TK_RAISE 83 |
| 11517 #define TK_RECURSIVE 84 |
| 11518 #define TK_REPLACE 85 |
| 11519 #define TK_RESTRICT 86 |
| 11520 #define TK_ROW 87 |
| 11521 #define TK_TRIGGER 88 |
| 11522 #define TK_VACUUM 89 |
| 11523 #define TK_VIEW 90 |
| 11524 #define TK_VIRTUAL 91 |
| 11525 #define TK_WITH 92 |
| 11526 #define TK_REINDEX 93 |
| 11527 #define TK_RENAME 94 |
| 11528 #define TK_CTIME_KW 95 |
| 11529 #define TK_ANY 96 |
| 11530 #define TK_STRING 97 |
| 11531 #define TK_JOIN_KW 98 |
| 11532 #define TK_CONSTRAINT 99 |
| 11533 #define TK_DEFAULT 100 |
| 11534 #define TK_NULL 101 |
| 11535 #define TK_PRIMARY 102 |
| 11536 #define TK_UNIQUE 103 |
| 11537 #define TK_CHECK 104 |
| 11538 #define TK_REFERENCES 105 |
| 11539 #define TK_AUTOINCR 106 |
| 11540 #define TK_ON 107 |
| 11541 #define TK_INSERT 108 |
| 11542 #define TK_DELETE 109 |
| 11543 #define TK_UPDATE 110 |
| 11544 #define TK_SET 111 |
| 11545 #define TK_DEFERRABLE 112 |
| 11546 #define TK_FOREIGN 113 |
| 11547 #define TK_DROP 114 |
| 11548 #define TK_UNION 115 |
| 11549 #define TK_ALL 116 |
| 11550 #define TK_EXCEPT 117 |
| 11551 #define TK_INTERSECT 118 |
| 11552 #define TK_SELECT 119 |
| 11553 #define TK_VALUES 120 |
| 11554 #define TK_DISTINCT 121 |
| 11555 #define TK_DOT 122 |
| 11556 #define TK_FROM 123 |
| 11557 #define TK_JOIN 124 |
| 11558 #define TK_USING 125 |
| 11559 #define TK_ORDER 126 |
| 11560 #define TK_GROUP 127 |
| 11561 #define TK_HAVING 128 |
| 11562 #define TK_LIMIT 129 |
| 11563 #define TK_WHERE 130 |
| 11564 #define TK_INTO 131 |
| 11565 #define TK_FLOAT 132 |
| 11566 #define TK_BLOB 133 |
| 11567 #define TK_INTEGER 134 |
| 11568 #define TK_VARIABLE 135 |
| 11569 #define TK_CASE 136 |
| 11570 #define TK_WHEN 137 |
| 11571 #define TK_THEN 138 |
| 11572 #define TK_ELSE 139 |
| 11573 #define TK_INDEX 140 |
| 11574 #define TK_ALTER 141 |
| 11575 #define TK_ADD 142 |
| 11576 #define TK_TO_TEXT 143 |
| 11577 #define TK_TO_BLOB 144 |
| 11578 #define TK_TO_NUMERIC 145 |
| 11579 #define TK_TO_INT 146 |
| 11580 #define TK_TO_REAL 147 |
| 11581 #define TK_ISNOT 148 |
| 11582 #define TK_END_OF_FILE 149 |
| 11583 #define TK_UNCLOSED_STRING 150 |
| 11584 #define TK_FUNCTION 151 |
| 11585 #define TK_COLUMN 152 |
| 11586 #define TK_AGG_FUNCTION 153 |
| 11587 #define TK_AGG_COLUMN 154 |
| 11588 #define TK_UMINUS 155 |
| 11589 #define TK_UPLUS 156 |
| 11590 #define TK_REGISTER 157 |
| 11591 #define TK_VECTOR 158 |
| 11592 #define TK_SELECT_COLUMN 159 |
| 11593 #define TK_ASTERISK 160 |
| 11594 #define TK_SPAN 161 |
| 11595 #define TK_SPACE 162 |
| 11596 #define TK_ILLEGAL 163 |
| 11597 |
| 11598 /* The token codes above must all fit in 8 bits */ |
| 11599 #define TKFLG_MASK 0xff |
| 11600 |
| 11601 /* Flags that can be added to a token code when it is not |
| 11602 ** being stored in a u8: */ |
| 11603 #define TKFLG_DONTFOLD 0x100 /* Omit constant folding optimizations */ |
| 11604 |
| 11605 /************** End of parse.h ***********************************************/ |
| 11606 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 11607 #include <stdio.h> |
| 11608 #include <stdlib.h> |
| 11609 #include <string.h> |
| 11610 #include <assert.h> |
| 11611 #include <stddef.h> |
| 11612 |
| 11613 /* |
| 11614 ** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY. |
| 11615 ** This allows better measurements of where memcpy() is used when running |
| 11616 ** cachegrind. But this macro version of memcpy() is very slow so it |
| 11617 ** should not be used in production. This is a performance measurement |
| 11618 ** hack only. |
| 11619 */ |
| 11620 #ifdef SQLITE_INLINE_MEMCPY |
| 11621 # define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\ |
| 11622 int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);} |
| 11623 #endif |
| 11624 |
| 11625 /* |
| 11626 ** If compiling for a processor that lacks floating point support, |
| 11627 ** substitute integer for floating-point |
| 11628 */ |
| 11629 #ifdef SQLITE_OMIT_FLOATING_POINT |
| 11630 # define double sqlite_int64 |
| 11631 # define float sqlite_int64 |
| 11632 # define LONGDOUBLE_TYPE sqlite_int64 |
| 11633 # ifndef SQLITE_BIG_DBL |
| 11634 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) |
| 11635 # endif |
| 11636 # define SQLITE_OMIT_DATETIME_FUNCS 1 |
| 11637 # define SQLITE_OMIT_TRACE 1 |
| 11638 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
| 11639 # undef SQLITE_HAVE_ISNAN |
| 11640 #endif |
| 11641 #ifndef SQLITE_BIG_DBL |
| 11642 # define SQLITE_BIG_DBL (1e99) |
| 11643 #endif |
| 11644 |
| 11645 /* |
| 11646 ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 |
| 11647 ** afterward. Having this macro allows us to cause the C compiler |
| 11648 ** to omit code used by TEMP tables without messy #ifndef statements. |
| 11649 */ |
| 11650 #ifdef SQLITE_OMIT_TEMPDB |
| 11651 #define OMIT_TEMPDB 1 |
| 11652 #else |
| 11653 #define OMIT_TEMPDB 0 |
| 11654 #endif |
| 11655 |
| 11656 /* |
| 11657 ** The "file format" number is an integer that is incremented whenever |
| 11658 ** the VDBE-level file format changes. The following macros define the |
| 11659 ** the default file format for new databases and the maximum file format |
| 11660 ** that the library can read. |
| 11661 */ |
| 11662 #define SQLITE_MAX_FILE_FORMAT 4 |
| 11663 #ifndef SQLITE_DEFAULT_FILE_FORMAT |
| 11664 # define SQLITE_DEFAULT_FILE_FORMAT 4 |
| 11665 #endif |
| 11666 |
| 11667 /* |
| 11668 ** Determine whether triggers are recursive by default. This can be |
| 11669 ** changed at run-time using a pragma. |
| 11670 */ |
| 11671 #ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS |
| 11672 # define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0 |
| 11673 #endif |
| 11674 |
| 11675 /* |
| 11676 ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified |
| 11677 ** on the command-line |
| 11678 */ |
| 11679 #ifndef SQLITE_TEMP_STORE |
| 11680 # define SQLITE_TEMP_STORE 1 |
| 11681 # define SQLITE_TEMP_STORE_xc 1 /* Exclude from ctime.c */ |
| 11682 #endif |
| 11683 |
| 11684 /* |
| 11685 ** If no value has been provided for SQLITE_MAX_WORKER_THREADS, or if |
| 11686 ** SQLITE_TEMP_STORE is set to 3 (never use temporary files), set it |
| 11687 ** to zero. |
| 11688 */ |
| 11689 #if SQLITE_TEMP_STORE==3 || SQLITE_THREADSAFE==0 |
| 11690 # undef SQLITE_MAX_WORKER_THREADS |
| 11691 # define SQLITE_MAX_WORKER_THREADS 0 |
| 11692 #endif |
| 11693 #ifndef SQLITE_MAX_WORKER_THREADS |
| 11694 # define SQLITE_MAX_WORKER_THREADS 8 |
| 11695 #endif |
| 11696 #ifndef SQLITE_DEFAULT_WORKER_THREADS |
| 11697 # define SQLITE_DEFAULT_WORKER_THREADS 0 |
| 11698 #endif |
| 11699 #if SQLITE_DEFAULT_WORKER_THREADS>SQLITE_MAX_WORKER_THREADS |
| 11700 # undef SQLITE_MAX_WORKER_THREADS |
| 11701 # define SQLITE_MAX_WORKER_THREADS SQLITE_DEFAULT_WORKER_THREADS |
| 11702 #endif |
| 11703 |
| 11704 /* |
| 11705 ** The default initial allocation for the pagecache when using separate |
| 11706 ** pagecaches for each database connection. A positive number is the |
| 11707 ** number of pages. A negative number N translations means that a buffer |
| 11708 ** of -1024*N bytes is allocated and used for as many pages as it will hold. |
| 11709 ** |
| 11710 ** The default value of "20" was choosen to minimize the run-time of the |
| 11711 ** speedtest1 test program with options: --shrink-memory --reprepare |
| 11712 */ |
| 11713 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ |
| 11714 # define SQLITE_DEFAULT_PCACHE_INITSZ 20 |
| 11715 #endif |
| 11716 |
| 11717 /* |
| 11718 ** GCC does not define the offsetof() macro so we'll have to do it |
| 11719 ** ourselves. |
| 11720 */ |
| 11721 #ifndef offsetof |
| 11722 #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) |
| 11723 #endif |
| 11724 |
| 11725 /* |
| 11726 ** Macros to compute minimum and maximum of two numbers. |
| 11727 */ |
| 11728 #ifndef MIN |
| 11729 # define MIN(A,B) ((A)<(B)?(A):(B)) |
| 11730 #endif |
| 11731 #ifndef MAX |
| 11732 # define MAX(A,B) ((A)>(B)?(A):(B)) |
| 11733 #endif |
| 11734 |
| 11735 /* |
| 11736 ** Swap two objects of type TYPE. |
| 11737 */ |
| 11738 #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} |
| 11739 |
| 11740 /* |
| 11741 ** Check to see if this machine uses EBCDIC. (Yes, believe it or |
| 11742 ** not, there are still machines out there that use EBCDIC.) |
| 11743 */ |
| 11744 #if 'A' == '\301' |
| 11745 # define SQLITE_EBCDIC 1 |
| 11746 #else |
| 11747 # define SQLITE_ASCII 1 |
| 11748 #endif |
| 11749 |
| 11750 /* |
| 11751 ** Integers of known sizes. These typedefs might change for architectures |
| 11752 ** where the sizes very. Preprocessor macros are available so that the |
| 11753 ** types can be conveniently redefined at compile-type. Like this: |
| 11754 ** |
| 11755 ** cc '-DUINTPTR_TYPE=long long int' ... |
| 11756 */ |
| 11757 #ifndef UINT32_TYPE |
| 11758 # ifdef HAVE_UINT32_T |
| 11759 # define UINT32_TYPE uint32_t |
| 11760 # else |
| 11761 # define UINT32_TYPE unsigned int |
| 11762 # endif |
| 11763 #endif |
| 11764 #ifndef UINT16_TYPE |
| 11765 # ifdef HAVE_UINT16_T |
| 11766 # define UINT16_TYPE uint16_t |
| 11767 # else |
| 11768 # define UINT16_TYPE unsigned short int |
| 11769 # endif |
| 11770 #endif |
| 11771 #ifndef INT16_TYPE |
| 11772 # ifdef HAVE_INT16_T |
| 11773 # define INT16_TYPE int16_t |
| 11774 # else |
| 11775 # define INT16_TYPE short int |
| 11776 # endif |
| 11777 #endif |
| 11778 #ifndef UINT8_TYPE |
| 11779 # ifdef HAVE_UINT8_T |
| 11780 # define UINT8_TYPE uint8_t |
| 11781 # else |
| 11782 # define UINT8_TYPE unsigned char |
| 11783 # endif |
| 11784 #endif |
| 11785 #ifndef INT8_TYPE |
| 11786 # ifdef HAVE_INT8_T |
| 11787 # define INT8_TYPE int8_t |
| 11788 # else |
| 11789 # define INT8_TYPE signed char |
| 11790 # endif |
| 11791 #endif |
| 11792 #ifndef LONGDOUBLE_TYPE |
| 11793 # define LONGDOUBLE_TYPE long double |
| 11794 #endif |
| 11795 typedef sqlite_int64 i64; /* 8-byte signed integer */ |
| 11796 typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ |
| 11797 typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ |
| 11798 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ |
| 11799 typedef INT16_TYPE i16; /* 2-byte signed integer */ |
| 11800 typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ |
| 11801 typedef INT8_TYPE i8; /* 1-byte signed integer */ |
| 11802 |
| 11803 /* |
| 11804 ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value |
| 11805 ** that can be stored in a u32 without loss of data. The value |
| 11806 ** is 0x00000000ffffffff. But because of quirks of some compilers, we |
| 11807 ** have to specify the value in the less intuitive manner shown: |
| 11808 */ |
| 11809 #define SQLITE_MAX_U32 ((((u64)1)<<32)-1) |
| 11810 |
| 11811 /* |
| 11812 ** The datatype used to store estimates of the number of rows in a |
| 11813 ** table or index. This is an unsigned integer type. For 99.9% of |
| 11814 ** the world, a 32-bit integer is sufficient. But a 64-bit integer |
| 11815 ** can be used at compile-time if desired. |
| 11816 */ |
| 11817 #ifdef SQLITE_64BIT_STATS |
| 11818 typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */ |
| 11819 #else |
| 11820 typedef u32 tRowcnt; /* 32-bit is the default */ |
| 11821 #endif |
| 11822 |
| 11823 /* |
| 11824 ** Estimated quantities used for query planning are stored as 16-bit |
| 11825 ** logarithms. For quantity X, the value stored is 10*log2(X). This |
| 11826 ** gives a possible range of values of approximately 1.0e986 to 1e-986. |
| 11827 ** But the allowed values are "grainy". Not every value is representable. |
| 11828 ** For example, quantities 16 and 17 are both represented by a LogEst |
| 11829 ** of 40. However, since LogEst quantities are suppose to be estimates, |
| 11830 ** not exact values, this imprecision is not a problem. |
| 11831 ** |
| 11832 ** "LogEst" is short for "Logarithmic Estimate". |
| 11833 ** |
| 11834 ** Examples: |
| 11835 ** 1 -> 0 20 -> 43 10000 -> 132 |
| 11836 ** 2 -> 10 25 -> 46 25000 -> 146 |
| 11837 ** 3 -> 16 100 -> 66 1000000 -> 199 |
| 11838 ** 4 -> 20 1000 -> 99 1048576 -> 200 |
| 11839 ** 10 -> 33 1024 -> 100 4294967296 -> 320 |
| 11840 ** |
| 11841 ** The LogEst can be negative to indicate fractional values. |
| 11842 ** Examples: |
| 11843 ** |
| 11844 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40 |
| 11845 */ |
| 11846 typedef INT16_TYPE LogEst; |
| 11847 |
| 11848 /* |
| 11849 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer |
| 11850 */ |
| 11851 #ifndef SQLITE_PTRSIZE |
| 11852 # if defined(__SIZEOF_POINTER__) |
| 11853 # define SQLITE_PTRSIZE __SIZEOF_POINTER__ |
| 11854 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \ |
| 11855 defined(_M_ARM) || defined(__arm__) || defined(__x86) |
| 11856 # define SQLITE_PTRSIZE 4 |
| 11857 # else |
| 11858 # define SQLITE_PTRSIZE 8 |
| 11859 # endif |
| 11860 #endif |
| 11861 |
| 11862 /* The uptr type is an unsigned integer large enough to hold a pointer |
| 11863 */ |
| 11864 #if defined(HAVE_STDINT_H) |
| 11865 typedef uintptr_t uptr; |
| 11866 #elif SQLITE_PTRSIZE==4 |
| 11867 typedef u32 uptr; |
| 11868 #else |
| 11869 typedef u64 uptr; |
| 11870 #endif |
| 11871 |
| 11872 /* |
| 11873 ** The SQLITE_WITHIN(P,S,E) macro checks to see if pointer P points to |
| 11874 ** something between S (inclusive) and E (exclusive). |
| 11875 ** |
| 11876 ** In other words, S is a buffer and E is a pointer to the first byte after |
| 11877 ** the end of buffer S. This macro returns true if P points to something |
| 11878 ** contained within the buffer S. |
| 11879 */ |
| 11880 #define SQLITE_WITHIN(P,S,E) (((uptr)(P)>=(uptr)(S))&&((uptr)(P)<(uptr)(E))) |
| 11881 |
| 11882 |
| 11883 /* |
| 11884 ** Macros to determine whether the machine is big or little endian, |
| 11885 ** and whether or not that determination is run-time or compile-time. |
| 11886 ** |
| 11887 ** For best performance, an attempt is made to guess at the byte-order |
| 11888 ** using C-preprocessor macros. If that is unsuccessful, or if |
| 11889 ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined |
| 11890 ** at run-time. |
| 11891 */ |
| 11892 #ifndef SQLITE_BYTEORDER |
| 11893 # if defined(i386) || defined(__i386__) || defined(_M_IX86) || \ |
| 11894 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ |
| 11895 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \ |
| 11896 defined(__arm__) |
| 11897 # define SQLITE_BYTEORDER 1234 |
| 11898 # elif defined(sparc) || defined(__ppc__) |
| 11899 # define SQLITE_BYTEORDER 4321 |
| 11900 # else |
| 11901 # define SQLITE_BYTEORDER 0 |
| 11902 # endif |
| 11903 #endif |
| 11904 #if SQLITE_BYTEORDER==4321 |
| 11905 # define SQLITE_BIGENDIAN 1 |
| 11906 # define SQLITE_LITTLEENDIAN 0 |
| 11907 # define SQLITE_UTF16NATIVE SQLITE_UTF16BE |
| 11908 #elif SQLITE_BYTEORDER==1234 |
| 11909 # define SQLITE_BIGENDIAN 0 |
| 11910 # define SQLITE_LITTLEENDIAN 1 |
| 11911 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE |
| 11912 #else |
| 11913 # ifdef SQLITE_AMALGAMATION |
| 11914 const int sqlite3one = 1; |
| 11915 # else |
| 11916 extern const int sqlite3one; |
| 11917 # endif |
| 11918 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) |
| 11919 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) |
| 11920 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) |
| 11921 #endif |
| 11922 |
| 11923 /* |
| 11924 ** Constants for the largest and smallest possible 64-bit signed integers. |
| 11925 ** These macros are designed to work correctly on both 32-bit and 64-bit |
| 11926 ** compilers. |
| 11927 */ |
| 11928 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) |
| 11929 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) |
| 11930 |
| 11931 /* |
| 11932 ** Round up a number to the next larger multiple of 8. This is used |
| 11933 ** to force 8-byte alignment on 64-bit architectures. |
| 11934 */ |
| 11935 #define ROUND8(x) (((x)+7)&~7) |
| 11936 |
| 11937 /* |
| 11938 ** Round down to the nearest multiple of 8 |
| 11939 */ |
| 11940 #define ROUNDDOWN8(x) ((x)&~7) |
| 11941 |
| 11942 /* |
| 11943 ** Assert that the pointer X is aligned to an 8-byte boundary. This |
| 11944 ** macro is used only within assert() to verify that the code gets |
| 11945 ** all alignment restrictions correct. |
| 11946 ** |
| 11947 ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the |
| 11948 ** underlying malloc() implementation might return us 4-byte aligned |
| 11949 ** pointers. In that case, only verify 4-byte alignment. |
| 11950 */ |
| 11951 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC |
| 11952 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0) |
| 11953 #else |
| 11954 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0) |
| 11955 #endif |
| 11956 |
| 11957 /* |
| 11958 ** Disable MMAP on platforms where it is known to not work |
| 11959 */ |
| 11960 #if defined(__OpenBSD__) || defined(__QNXNTO__) |
| 11961 # undef SQLITE_MAX_MMAP_SIZE |
| 11962 # define SQLITE_MAX_MMAP_SIZE 0 |
| 11963 #endif |
| 11964 |
| 11965 /* |
| 11966 ** Default maximum size of memory used by memory-mapped I/O in the VFS |
| 11967 */ |
| 11968 #ifdef __APPLE__ |
| 11969 # include <TargetConditionals.h> |
| 11970 #endif |
| 11971 #ifndef SQLITE_MAX_MMAP_SIZE |
| 11972 # if defined(__linux__) \ |
| 11973 || defined(_WIN32) \ |
| 11974 || (defined(__APPLE__) && defined(__MACH__)) \ |
| 11975 || defined(__sun) \ |
| 11976 || defined(__FreeBSD__) \ |
| 11977 || defined(__DragonFly__) |
| 11978 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */ |
| 11979 # else |
| 11980 # define SQLITE_MAX_MMAP_SIZE 0 |
| 11981 # endif |
| 11982 # define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */ |
| 11983 #endif |
| 11984 |
| 11985 /* |
| 11986 ** The default MMAP_SIZE is zero on all platforms. Or, even if a larger |
| 11987 ** default MMAP_SIZE is specified at compile-time, make sure that it does |
| 11988 ** not exceed the maximum mmap size. |
| 11989 */ |
| 11990 #ifndef SQLITE_DEFAULT_MMAP_SIZE |
| 11991 # define SQLITE_DEFAULT_MMAP_SIZE 0 |
| 11992 # define SQLITE_DEFAULT_MMAP_SIZE_xc 1 /* Exclude from ctime.c */ |
| 11993 #endif |
| 11994 #if SQLITE_DEFAULT_MMAP_SIZE>SQLITE_MAX_MMAP_SIZE |
| 11995 # undef SQLITE_DEFAULT_MMAP_SIZE |
| 11996 # define SQLITE_DEFAULT_MMAP_SIZE SQLITE_MAX_MMAP_SIZE |
| 11997 #endif |
| 11998 |
| 11999 /* |
| 12000 ** Only one of SQLITE_ENABLE_STAT3 or SQLITE_ENABLE_STAT4 can be defined. |
| 12001 ** Priority is given to SQLITE_ENABLE_STAT4. If either are defined, also |
| 12002 ** define SQLITE_ENABLE_STAT3_OR_STAT4 |
| 12003 */ |
| 12004 #ifdef SQLITE_ENABLE_STAT4 |
| 12005 # undef SQLITE_ENABLE_STAT3 |
| 12006 # define SQLITE_ENABLE_STAT3_OR_STAT4 1 |
| 12007 #elif SQLITE_ENABLE_STAT3 |
| 12008 # define SQLITE_ENABLE_STAT3_OR_STAT4 1 |
| 12009 #elif SQLITE_ENABLE_STAT3_OR_STAT4 |
| 12010 # undef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 12011 #endif |
| 12012 |
| 12013 /* |
| 12014 ** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not |
| 12015 ** the Select query generator tracing logic is turned on. |
| 12016 */ |
| 12017 #if defined(SQLITE_DEBUG) || defined(SQLITE_ENABLE_SELECTTRACE) |
| 12018 # define SELECTTRACE_ENABLED 1 |
| 12019 #else |
| 12020 # define SELECTTRACE_ENABLED 0 |
| 12021 #endif |
| 12022 |
| 12023 /* |
| 12024 ** An instance of the following structure is used to store the busy-handler |
| 12025 ** callback for a given sqlite handle. |
| 12026 ** |
| 12027 ** The sqlite.busyHandler member of the sqlite struct contains the busy |
| 12028 ** callback for the database handle. Each pager opened via the sqlite |
| 12029 ** handle is passed a pointer to sqlite.busyHandler. The busy-handler |
| 12030 ** callback is currently invoked only from within pager.c. |
| 12031 */ |
| 12032 typedef struct BusyHandler BusyHandler; |
| 12033 struct BusyHandler { |
| 12034 int (*xFunc)(void *,int); /* The busy callback */ |
| 12035 void *pArg; /* First arg to busy callback */ |
| 12036 int nBusy; /* Incremented with each busy call */ |
| 12037 }; |
| 12038 |
| 12039 /* |
| 12040 ** Name of the master database table. The master database table |
| 12041 ** is a special table that holds the names and attributes of all |
| 12042 ** user tables and indices. |
| 12043 */ |
| 12044 #define MASTER_NAME "sqlite_master" |
| 12045 #define TEMP_MASTER_NAME "sqlite_temp_master" |
| 12046 |
| 12047 /* |
| 12048 ** The root-page of the master database table. |
| 12049 */ |
| 12050 #define MASTER_ROOT 1 |
| 12051 |
| 12052 /* |
| 12053 ** The name of the schema table. |
| 12054 */ |
| 12055 #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) |
| 12056 |
| 12057 /* |
| 12058 ** A convenience macro that returns the number of elements in |
| 12059 ** an array. |
| 12060 */ |
| 12061 #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0]))) |
| 12062 |
| 12063 /* |
| 12064 ** Determine if the argument is a power of two |
| 12065 */ |
| 12066 #define IsPowerOfTwo(X) (((X)&((X)-1))==0) |
| 12067 |
| 12068 /* |
| 12069 ** The following value as a destructor means to use sqlite3DbFree(). |
| 12070 ** The sqlite3DbFree() routine requires two parameters instead of the |
| 12071 ** one parameter that destructors normally want. So we have to introduce |
| 12072 ** this magic value that the code knows to handle differently. Any |
| 12073 ** pointer will work here as long as it is distinct from SQLITE_STATIC |
| 12074 ** and SQLITE_TRANSIENT. |
| 12075 */ |
| 12076 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3MallocSize) |
| 12077 |
| 12078 /* |
| 12079 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does |
| 12080 ** not support Writable Static Data (WSD) such as global and static variables. |
| 12081 ** All variables must either be on the stack or dynamically allocated from |
| 12082 ** the heap. When WSD is unsupported, the variable declarations scattered |
| 12083 ** throughout the SQLite code must become constants instead. The SQLITE_WSD |
| 12084 ** macro is used for this purpose. And instead of referencing the variable |
| 12085 ** directly, we use its constant as a key to lookup the run-time allocated |
| 12086 ** buffer that holds real variable. The constant is also the initializer |
| 12087 ** for the run-time allocated buffer. |
| 12088 ** |
| 12089 ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL |
| 12090 ** macros become no-ops and have zero performance impact. |
| 12091 */ |
| 12092 #ifdef SQLITE_OMIT_WSD |
| 12093 #define SQLITE_WSD const |
| 12094 #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) |
| 12095 #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) |
| 12096 SQLITE_API int sqlite3_wsd_init(int N, int J); |
| 12097 SQLITE_API void *sqlite3_wsd_find(void *K, int L); |
| 12098 #else |
| 12099 #define SQLITE_WSD |
| 12100 #define GLOBAL(t,v) v |
| 12101 #define sqlite3GlobalConfig sqlite3Config |
| 12102 #endif |
| 12103 |
| 12104 /* |
| 12105 ** The following macros are used to suppress compiler warnings and to |
| 12106 ** make it clear to human readers when a function parameter is deliberately |
| 12107 ** left unused within the body of a function. This usually happens when |
| 12108 ** a function is called via a function pointer. For example the |
| 12109 ** implementation of an SQL aggregate step callback may not use the |
| 12110 ** parameter indicating the number of arguments passed to the aggregate, |
| 12111 ** if it knows that this is enforced elsewhere. |
| 12112 ** |
| 12113 ** When a function parameter is not used at all within the body of a function, |
| 12114 ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer. |
| 12115 ** However, these macros may also be used to suppress warnings related to |
| 12116 ** parameters that may or may not be used depending on compilation options. |
| 12117 ** For example those parameters only used in assert() statements. In these |
| 12118 ** cases the parameters are named as per the usual conventions. |
| 12119 */ |
| 12120 #define UNUSED_PARAMETER(x) (void)(x) |
| 12121 #define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y) |
| 12122 |
| 12123 /* |
| 12124 ** Forward references to structures |
| 12125 */ |
| 12126 typedef struct AggInfo AggInfo; |
| 12127 typedef struct AuthContext AuthContext; |
| 12128 typedef struct AutoincInfo AutoincInfo; |
| 12129 typedef struct Bitvec Bitvec; |
| 12130 typedef struct CollSeq CollSeq; |
| 12131 typedef struct Column Column; |
| 12132 typedef struct Db Db; |
| 12133 typedef struct Schema Schema; |
| 12134 typedef struct Expr Expr; |
| 12135 typedef struct ExprList ExprList; |
| 12136 typedef struct ExprSpan ExprSpan; |
| 12137 typedef struct FKey FKey; |
| 12138 typedef struct FuncDestructor FuncDestructor; |
| 12139 typedef struct FuncDef FuncDef; |
| 12140 typedef struct FuncDefHash FuncDefHash; |
| 12141 typedef struct IdList IdList; |
| 12142 typedef struct Index Index; |
| 12143 typedef struct IndexSample IndexSample; |
| 12144 typedef struct KeyClass KeyClass; |
| 12145 typedef struct KeyInfo KeyInfo; |
| 12146 typedef struct Lookaside Lookaside; |
| 12147 typedef struct LookasideSlot LookasideSlot; |
| 12148 typedef struct Module Module; |
| 12149 typedef struct NameContext NameContext; |
| 12150 typedef struct Parse Parse; |
| 12151 typedef struct PreUpdate PreUpdate; |
| 12152 typedef struct PrintfArguments PrintfArguments; |
| 12153 typedef struct RowSet RowSet; |
| 12154 typedef struct Savepoint Savepoint; |
| 12155 typedef struct Select Select; |
| 12156 typedef struct SQLiteThread SQLiteThread; |
| 12157 typedef struct SelectDest SelectDest; |
| 12158 typedef struct SrcList SrcList; |
| 12159 typedef struct StrAccum StrAccum; |
| 12160 typedef struct Table Table; |
| 12161 typedef struct TableLock TableLock; |
| 12162 typedef struct Token Token; |
| 12163 typedef struct TreeView TreeView; |
| 12164 typedef struct Trigger Trigger; |
| 12165 typedef struct TriggerPrg TriggerPrg; |
| 12166 typedef struct TriggerStep TriggerStep; |
| 12167 typedef struct UnpackedRecord UnpackedRecord; |
| 12168 typedef struct VTable VTable; |
| 12169 typedef struct VtabCtx VtabCtx; |
| 12170 typedef struct Walker Walker; |
| 12171 typedef struct WhereInfo WhereInfo; |
| 12172 typedef struct With With; |
| 12173 |
| 12174 /* A VList object records a mapping between parameters/variables/wildcards |
| 12175 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer |
| 12176 ** variable number associated with that parameter. See the format description |
| 12177 ** on the sqlite3VListAdd() routine for more information. A VList is really |
| 12178 ** just an array of integers. |
| 12179 */ |
| 12180 typedef int VList; |
| 12181 |
| 12182 /* |
| 12183 ** Defer sourcing vdbe.h and btree.h until after the "u8" and |
| 12184 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque |
| 12185 ** pointer types (i.e. FuncDef) defined above. |
| 12186 */ |
| 12187 /************** Include btree.h in the middle of sqliteInt.h *****************/ |
| 12188 /************** Begin file btree.h *******************************************/ |
| 12189 /* |
| 12190 ** 2001 September 15 |
| 12191 ** |
| 12192 ** The author disclaims copyright to this source code. In place of |
| 12193 ** a legal notice, here is a blessing: |
| 12194 ** |
| 12195 ** May you do good and not evil. |
| 12196 ** May you find forgiveness for yourself and forgive others. |
| 12197 ** May you share freely, never taking more than you give. |
| 12198 ** |
| 12199 ************************************************************************* |
| 12200 ** This header file defines the interface that the sqlite B-Tree file |
| 12201 ** subsystem. See comments in the source code for a detailed description |
| 12202 ** of what each interface routine does. |
| 12203 */ |
| 12204 #ifndef SQLITE_BTREE_H |
| 12205 #define SQLITE_BTREE_H |
| 12206 |
| 12207 /* TODO: This definition is just included so other modules compile. It |
| 12208 ** needs to be revisited. |
| 12209 */ |
| 12210 #define SQLITE_N_BTREE_META 16 |
| 12211 |
| 12212 /* |
| 12213 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise |
| 12214 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1". |
| 12215 */ |
| 12216 #ifndef SQLITE_DEFAULT_AUTOVACUUM |
| 12217 #define SQLITE_DEFAULT_AUTOVACUUM 0 |
| 12218 #endif |
| 12219 |
| 12220 #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */ |
| 12221 #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */ |
| 12222 #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */ |
| 12223 |
| 12224 /* |
| 12225 ** Forward declarations of structure |
| 12226 */ |
| 12227 typedef struct Btree Btree; |
| 12228 typedef struct BtCursor BtCursor; |
| 12229 typedef struct BtShared BtShared; |
| 12230 typedef struct BtreePayload BtreePayload; |
| 12231 |
| 12232 |
| 12233 SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 12234 sqlite3_vfs *pVfs, /* VFS to use with this b-tree */ |
| 12235 const char *zFilename, /* Name of database file to open */ |
| 12236 sqlite3 *db, /* Associated database connection */ |
| 12237 Btree **ppBtree, /* Return open Btree* here */ |
| 12238 int flags, /* Flags */ |
| 12239 int vfsFlags /* Flags passed through to VFS open */ |
| 12240 ); |
| 12241 |
| 12242 /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the |
| 12243 ** following values. |
| 12244 ** |
| 12245 ** NOTE: These values must match the corresponding PAGER_ values in |
| 12246 ** pager.h. |
| 12247 */ |
| 12248 #define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */ |
| 12249 #define BTREE_MEMORY 2 /* This is an in-memory DB */ |
| 12250 #define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */ |
| 12251 #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */ |
| 12252 |
| 12253 SQLITE_PRIVATE int sqlite3BtreeClose(Btree*); |
| 12254 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int); |
| 12255 SQLITE_PRIVATE int sqlite3BtreeSetSpillSize(Btree*,int); |
| 12256 #if SQLITE_MAX_MMAP_SIZE>0 |
| 12257 SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64); |
| 12258 #endif |
| 12259 SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned); |
| 12260 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve
, int eFix); |
| 12261 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*); |
| 12262 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int); |
| 12263 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*); |
| 12264 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int); |
| 12265 SQLITE_PRIVATE int sqlite3BtreeGetOptimalReserve(Btree*); |
| 12266 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p); |
| 12267 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int); |
| 12268 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); |
| 12269 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int); |
| 12270 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); |
| 12271 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int); |
| 12272 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); |
| 12273 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int); |
| 12274 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); |
| 12275 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
| 12276 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*); |
| 12277 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*); |
| 12278 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*); |
| 12279 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *)); |
| 12280 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree); |
| 12281 #ifndef SQLITE_OMIT_SHARED_CACHE |
| 12282 SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock
); |
| 12283 #endif |
| 12284 SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int); |
| 12285 |
| 12286 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *); |
| 12287 SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *); |
| 12288 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *); |
| 12289 |
| 12290 SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *); |
| 12291 |
| 12292 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR |
| 12293 ** of the flags shown below. |
| 12294 ** |
| 12295 ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set. |
| 12296 ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data |
| 12297 ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With |
| 12298 ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored |
| 12299 ** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL |
| 12300 ** indices.) |
| 12301 */ |
| 12302 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */ |
| 12303 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */ |
| 12304 |
| 12305 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*); |
| 12306 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*); |
| 12307 SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*); |
| 12308 SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree*, int, int); |
| 12309 |
| 12310 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue); |
| 12311 SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); |
| 12312 |
| 12313 SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p); |
| 12314 |
| 12315 /* |
| 12316 ** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta |
| 12317 ** should be one of the following values. The integer values are assigned |
| 12318 ** to constants so that the offset of the corresponding field in an |
| 12319 ** SQLite database header may be found using the following formula: |
| 12320 ** |
| 12321 ** offset = 36 + (idx * 4) |
| 12322 ** |
| 12323 ** For example, the free-page-count field is located at byte offset 36 of |
| 12324 ** the database file header. The incr-vacuum-flag field is located at |
| 12325 ** byte offset 64 (== 36+4*7). |
| 12326 ** |
| 12327 ** The BTREE_DATA_VERSION value is not really a value stored in the header. |
| 12328 ** It is a read-only number computed by the pager. But we merge it with |
| 12329 ** the header value access routines since its access pattern is the same. |
| 12330 ** Call it a "virtual meta value". |
| 12331 */ |
| 12332 #define BTREE_FREE_PAGE_COUNT 0 |
| 12333 #define BTREE_SCHEMA_VERSION 1 |
| 12334 #define BTREE_FILE_FORMAT 2 |
| 12335 #define BTREE_DEFAULT_CACHE_SIZE 3 |
| 12336 #define BTREE_LARGEST_ROOT_PAGE 4 |
| 12337 #define BTREE_TEXT_ENCODING 5 |
| 12338 #define BTREE_USER_VERSION 6 |
| 12339 #define BTREE_INCR_VACUUM 7 |
| 12340 #define BTREE_APPLICATION_ID 8 |
| 12341 #define BTREE_DATA_VERSION 15 /* A virtual meta-value */ |
| 12342 |
| 12343 /* |
| 12344 ** Kinds of hints that can be passed into the sqlite3BtreeCursorHint() |
| 12345 ** interface. |
| 12346 ** |
| 12347 ** BTREE_HINT_RANGE (arguments: Expr*, Mem*) |
| 12348 ** |
| 12349 ** The first argument is an Expr* (which is guaranteed to be constant for |
| 12350 ** the lifetime of the cursor) that defines constraints on which rows |
| 12351 ** might be fetched with this cursor. The Expr* tree may contain |
| 12352 ** TK_REGISTER nodes that refer to values stored in the array of registers |
| 12353 ** passed as the second parameter. In other words, if Expr.op==TK_REGISTER |
| 12354 ** then the value of the node is the value in Mem[pExpr.iTable]. Any |
| 12355 ** TK_COLUMN node in the expression tree refers to the Expr.iColumn-th |
| 12356 ** column of the b-tree of the cursor. The Expr tree will not contain |
| 12357 ** any function calls nor subqueries nor references to b-trees other than |
| 12358 ** the cursor being hinted. |
| 12359 ** |
| 12360 ** The design of the _RANGE hint is aid b-tree implementations that try |
| 12361 ** to prefetch content from remote machines - to provide those |
| 12362 ** implementations with limits on what needs to be prefetched and thereby |
| 12363 ** reduce network bandwidth. |
| 12364 ** |
| 12365 ** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by |
| 12366 ** standard SQLite. The other hints are provided for extentions that use |
| 12367 ** the SQLite parser and code generator but substitute their own storage |
| 12368 ** engine. |
| 12369 */ |
| 12370 #define BTREE_HINT_RANGE 0 /* Range constraints on queries */ |
| 12371 |
| 12372 /* |
| 12373 ** Values that may be OR'd together to form the argument to the |
| 12374 ** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint(): |
| 12375 ** |
| 12376 ** The BTREE_BULKLOAD flag is set on index cursors when the index is going |
| 12377 ** to be filled with content that is already in sorted order. |
| 12378 ** |
| 12379 ** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or |
| 12380 ** OP_SeekLE opcodes for a range search, but where the range of entries |
| 12381 ** selected will all have the same key. In other words, the cursor will |
| 12382 ** be used only for equality key searches. |
| 12383 ** |
| 12384 */ |
| 12385 #define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */ |
| 12386 #define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */ |
| 12387 |
| 12388 /* |
| 12389 ** Flags passed as the third argument to sqlite3BtreeCursor(). |
| 12390 ** |
| 12391 ** For read-only cursors the wrFlag argument is always zero. For read-write |
| 12392 ** cursors it may be set to either (BTREE_WRCSR|BTREE_FORDELETE) or just |
| 12393 ** (BTREE_WRCSR). If the BTREE_FORDELETE bit is set, then the cursor will |
| 12394 ** only be used by SQLite for the following: |
| 12395 ** |
| 12396 ** * to seek to and then delete specific entries, and/or |
| 12397 ** |
| 12398 ** * to read values that will be used to create keys that other |
| 12399 ** BTREE_FORDELETE cursors will seek to and delete. |
| 12400 ** |
| 12401 ** The BTREE_FORDELETE flag is an optimization hint. It is not used by |
| 12402 ** by this, the native b-tree engine of SQLite, but it is available to |
| 12403 ** alternative storage engines that might be substituted in place of this |
| 12404 ** b-tree system. For alternative storage engines in which a delete of |
| 12405 ** the main table row automatically deletes corresponding index rows, |
| 12406 ** the FORDELETE flag hint allows those alternative storage engines to |
| 12407 ** skip a lot of work. Namely: FORDELETE cursors may treat all SEEK |
| 12408 ** and DELETE operations as no-ops, and any READ operation against a |
| 12409 ** FORDELETE cursor may return a null row: 0x01 0x00. |
| 12410 */ |
| 12411 #define BTREE_WRCSR 0x00000004 /* read-write cursor */ |
| 12412 #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */ |
| 12413 |
| 12414 SQLITE_PRIVATE int sqlite3BtreeCursor( |
| 12415 Btree*, /* BTree containing table to open */ |
| 12416 int iTable, /* Index of root page */ |
| 12417 int wrFlag, /* 1 for writing. 0 for read-only */ |
| 12418 struct KeyInfo*, /* First argument to compare function */ |
| 12419 BtCursor *pCursor /* Space to write cursor structure */ |
| 12420 ); |
| 12421 SQLITE_PRIVATE int sqlite3BtreeCursorSize(void); |
| 12422 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*); |
| 12423 SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned); |
| 12424 #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 12425 SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...); |
| 12426 #endif |
| 12427 |
| 12428 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*); |
| 12429 SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( |
| 12430 BtCursor*, |
| 12431 UnpackedRecord *pUnKey, |
| 12432 i64 intKey, |
| 12433 int bias, |
| 12434 int *pRes |
| 12435 ); |
| 12436 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 12437 SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 12438 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags); |
| 12439 |
| 12440 /* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */ |
| 12441 #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ |
| 12442 #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */ |
| 12443 #define BTREE_APPEND 0x08 /* Insert is likely an append */ |
| 12444 |
| 12445 /* An instance of the BtreePayload object describes the content of a single |
| 12446 ** entry in either an index or table btree. |
| 12447 ** |
| 12448 ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain |
| 12449 ** an arbitrary key and no data. These btrees have pKey,nKey set to their |
| 12450 ** key and pData,nData,nZero set to zero. |
| 12451 ** |
| 12452 ** Table btrees (used for rowid tables) contain an integer rowid used as |
| 12453 ** the key and passed in the nKey field. The pKey field is zero. |
| 12454 ** pData,nData hold the content of the new entry. nZero extra zero bytes |
| 12455 ** are appended to the end of the content when constructing the entry. |
| 12456 ** |
| 12457 ** This object is used to pass information into sqlite3BtreeInsert(). The |
| 12458 ** same information used to be passed as five separate parameters. But placing |
| 12459 ** the information into this object helps to keep the interface more |
| 12460 ** organized and understandable, and it also helps the resulting code to |
| 12461 ** run a little faster by using fewer registers for parameter passing. |
| 12462 */ |
| 12463 struct BtreePayload { |
| 12464 const void *pKey; /* Key content for indexes. NULL for tables */ |
| 12465 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */ |
| 12466 const void *pData; /* Data for tables. NULL for indexes */ |
| 12467 struct Mem *aMem; /* First of nMem value in the unpacked pKey */ |
| 12468 u16 nMem; /* Number of aMem[] value. Might be zero */ |
| 12469 int nData; /* Size of pData. 0 if none. */ |
| 12470 int nZero; /* Extra zero data appended after pData,nData */ |
| 12471 }; |
| 12472 |
| 12473 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload, |
| 12474 int flags, int seekResult); |
| 12475 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 12476 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| 12477 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes); |
| 12478 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); |
| 12479 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes); |
| 12480 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*); |
| 12481 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); |
| 12482 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); |
| 12483 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*); |
| 12484 |
| 12485 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, i
nt, int*); |
| 12486 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); |
| 12487 |
| 12488 #ifndef SQLITE_OMIT_INCRBLOB |
| 12489 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, vo
id*); |
| 12490 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); |
| 12491 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); |
| 12492 #endif |
| 12493 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); |
| 12494 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); |
| 12495 SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask); |
| 12496 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt); |
| 12497 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void); |
| 12498 |
| 12499 #ifndef NDEBUG |
| 12500 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); |
| 12501 #endif |
| 12502 SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*); |
| 12503 |
| 12504 #ifndef SQLITE_OMIT_BTREECOUNT |
| 12505 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *); |
| 12506 #endif |
| 12507 |
| 12508 #ifdef SQLITE_TEST |
| 12509 SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int); |
| 12510 SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*); |
| 12511 #endif |
| 12512 |
| 12513 #ifndef SQLITE_OMIT_WAL |
| 12514 SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *); |
| 12515 #endif |
| 12516 |
| 12517 /* |
| 12518 ** If we are not using shared cache, then there is no need to |
| 12519 ** use mutexes to access the BtShared structures. So make the |
| 12520 ** Enter and Leave procedures no-ops. |
| 12521 */ |
| 12522 #ifndef SQLITE_OMIT_SHARED_CACHE |
| 12523 SQLITE_PRIVATE void sqlite3BtreeEnter(Btree*); |
| 12524 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3*); |
| 12525 SQLITE_PRIVATE int sqlite3BtreeSharable(Btree*); |
| 12526 SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*); |
| 12527 SQLITE_PRIVATE int sqlite3BtreeConnectionCount(Btree*); |
| 12528 #else |
| 12529 # define sqlite3BtreeEnter(X) |
| 12530 # define sqlite3BtreeEnterAll(X) |
| 12531 # define sqlite3BtreeSharable(X) 0 |
| 12532 # define sqlite3BtreeEnterCursor(X) |
| 12533 # define sqlite3BtreeConnectionCount(X) 1 |
| 12534 #endif |
| 12535 |
| 12536 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE |
| 12537 SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*); |
| 12538 SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*); |
| 12539 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); |
| 12540 #ifndef NDEBUG |
| 12541 /* These routines are used inside assert() statements only. */ |
| 12542 SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); |
| 12543 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); |
| 12544 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); |
| 12545 #endif |
| 12546 #else |
| 12547 |
| 12548 # define sqlite3BtreeLeave(X) |
| 12549 # define sqlite3BtreeLeaveCursor(X) |
| 12550 # define sqlite3BtreeLeaveAll(X) |
| 12551 |
| 12552 # define sqlite3BtreeHoldsMutex(X) 1 |
| 12553 # define sqlite3BtreeHoldsAllMutexes(X) 1 |
| 12554 # define sqlite3SchemaMutexHeld(X,Y,Z) 1 |
| 12555 #endif |
| 12556 |
| 12557 |
| 12558 #endif /* SQLITE_BTREE_H */ |
| 12559 |
| 12560 /************** End of btree.h ***********************************************/ |
| 12561 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 12562 /************** Include vdbe.h in the middle of sqliteInt.h ******************/ |
| 12563 /************** Begin file vdbe.h ********************************************/ |
| 12564 /* |
| 12565 ** 2001 September 15 |
| 12566 ** |
| 12567 ** The author disclaims copyright to this source code. In place of |
| 12568 ** a legal notice, here is a blessing: |
| 12569 ** |
| 12570 ** May you do good and not evil. |
| 12571 ** May you find forgiveness for yourself and forgive others. |
| 12572 ** May you share freely, never taking more than you give. |
| 12573 ** |
| 12574 ************************************************************************* |
| 12575 ** Header file for the Virtual DataBase Engine (VDBE) |
| 12576 ** |
| 12577 ** This header defines the interface to the virtual database engine |
| 12578 ** or VDBE. The VDBE implements an abstract machine that runs a |
| 12579 ** simple program to access and modify the underlying database. |
| 12580 */ |
| 12581 #ifndef SQLITE_VDBE_H |
| 12582 #define SQLITE_VDBE_H |
| 12583 /* #include <stdio.h> */ |
| 12584 |
| 12585 /* |
| 12586 ** A single VDBE is an opaque structure named "Vdbe". Only routines |
| 12587 ** in the source file sqliteVdbe.c are allowed to see the insides |
| 12588 ** of this structure. |
| 12589 */ |
| 12590 typedef struct Vdbe Vdbe; |
| 12591 |
| 12592 /* |
| 12593 ** The names of the following types declared in vdbeInt.h are required |
| 12594 ** for the VdbeOp definition. |
| 12595 */ |
| 12596 typedef struct Mem Mem; |
| 12597 typedef struct SubProgram SubProgram; |
| 12598 |
| 12599 /* |
| 12600 ** A single instruction of the virtual machine has an opcode |
| 12601 ** and as many as three operands. The instruction is recorded |
| 12602 ** as an instance of the following structure: |
| 12603 */ |
| 12604 struct VdbeOp { |
| 12605 u8 opcode; /* What operation to perform */ |
| 12606 signed char p4type; /* One of the P4_xxx constants for p4 */ |
| 12607 u16 p5; /* Fifth parameter is an unsigned 16-bit integer */ |
| 12608 int p1; /* First operand */ |
| 12609 int p2; /* Second parameter (often the jump destination) */ |
| 12610 int p3; /* The third parameter */ |
| 12611 union p4union { /* fourth parameter */ |
| 12612 int i; /* Integer value if p4type==P4_INT32 */ |
| 12613 void *p; /* Generic pointer */ |
| 12614 char *z; /* Pointer to data for string (char array) types */ |
| 12615 i64 *pI64; /* Used when p4type is P4_INT64 */ |
| 12616 double *pReal; /* Used when p4type is P4_REAL */ |
| 12617 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */ |
| 12618 sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */ |
| 12619 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */ |
| 12620 Mem *pMem; /* Used when p4type is P4_MEM */ |
| 12621 VTable *pVtab; /* Used when p4type is P4_VTAB */ |
| 12622 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ |
| 12623 int *ai; /* Used when p4type is P4_INTARRAY */ |
| 12624 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ |
| 12625 Table *pTab; /* Used when p4type is P4_TABLE */ |
| 12626 #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 12627 Expr *pExpr; /* Used when p4type is P4_EXPR */ |
| 12628 #endif |
| 12629 int (*xAdvance)(BtCursor *, int *); |
| 12630 } p4; |
| 12631 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 12632 char *zComment; /* Comment to improve readability */ |
| 12633 #endif |
| 12634 #ifdef VDBE_PROFILE |
| 12635 u32 cnt; /* Number of times this instruction was executed */ |
| 12636 u64 cycles; /* Total time spent executing this instruction */ |
| 12637 #endif |
| 12638 #ifdef SQLITE_VDBE_COVERAGE |
| 12639 int iSrcLine; /* Source-code line that generated this opcode */ |
| 12640 #endif |
| 12641 }; |
| 12642 typedef struct VdbeOp VdbeOp; |
| 12643 |
| 12644 |
| 12645 /* |
| 12646 ** A sub-routine used to implement a trigger program. |
| 12647 */ |
| 12648 struct SubProgram { |
| 12649 VdbeOp *aOp; /* Array of opcodes for sub-program */ |
| 12650 int nOp; /* Elements in aOp[] */ |
| 12651 int nMem; /* Number of memory cells required */ |
| 12652 int nCsr; /* Number of cursors required */ |
| 12653 void *token; /* id that may be used to recursive triggers */ |
| 12654 SubProgram *pNext; /* Next sub-program already visited */ |
| 12655 }; |
| 12656 |
| 12657 /* |
| 12658 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because |
| 12659 ** it takes up less space. |
| 12660 */ |
| 12661 struct VdbeOpList { |
| 12662 u8 opcode; /* What operation to perform */ |
| 12663 signed char p1; /* First operand */ |
| 12664 signed char p2; /* Second parameter (often the jump destination) */ |
| 12665 signed char p3; /* Third parameter */ |
| 12666 }; |
| 12667 typedef struct VdbeOpList VdbeOpList; |
| 12668 |
| 12669 /* |
| 12670 ** Allowed values of VdbeOp.p4type |
| 12671 */ |
| 12672 #define P4_NOTUSED 0 /* The P4 parameter is not used */ |
| 12673 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */ |
| 12674 #define P4_STATIC (-2) /* Pointer to a static string */ |
| 12675 #define P4_COLLSEQ (-3) /* P4 is a pointer to a CollSeq structure */ |
| 12676 #define P4_FUNCDEF (-4) /* P4 is a pointer to a FuncDef structure */ |
| 12677 #define P4_KEYINFO (-5) /* P4 is a pointer to a KeyInfo structure */ |
| 12678 #define P4_EXPR (-6) /* P4 is a pointer to an Expr tree */ |
| 12679 #define P4_MEM (-7) /* P4 is a pointer to a Mem* structure */ |
| 12680 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 12681 #define P4_VTAB (-8) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 12682 #define P4_REAL (-9) /* P4 is a 64-bit floating point value */ |
| 12683 #define P4_INT64 (-10) /* P4 is a 64-bit signed integer */ |
| 12684 #define P4_INT32 (-11) /* P4 is a 32-bit signed integer */ |
| 12685 #define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */ |
| 12686 #define P4_SUBPROGRAM (-13) /* P4 is a pointer to a SubProgram structure */ |
| 12687 #define P4_ADVANCE (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */ |
| 12688 #define P4_TABLE (-15) /* P4 is a pointer to a Table structure */ |
| 12689 #define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ |
| 12690 |
| 12691 /* Error message codes for OP_Halt */ |
| 12692 #define P5_ConstraintNotNull 1 |
| 12693 #define P5_ConstraintUnique 2 |
| 12694 #define P5_ConstraintCheck 3 |
| 12695 #define P5_ConstraintFK 4 |
| 12696 |
| 12697 /* |
| 12698 ** The Vdbe.aColName array contains 5n Mem structures, where n is the |
| 12699 ** number of columns of data returned by the statement. |
| 12700 */ |
| 12701 #define COLNAME_NAME 0 |
| 12702 #define COLNAME_DECLTYPE 1 |
| 12703 #define COLNAME_DATABASE 2 |
| 12704 #define COLNAME_TABLE 3 |
| 12705 #define COLNAME_COLUMN 4 |
| 12706 #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 12707 # define COLNAME_N 5 /* Number of COLNAME_xxx symbols */ |
| 12708 #else |
| 12709 # ifdef SQLITE_OMIT_DECLTYPE |
| 12710 # define COLNAME_N 1 /* Store only the name */ |
| 12711 # else |
| 12712 # define COLNAME_N 2 /* Store the name and decltype */ |
| 12713 # endif |
| 12714 #endif |
| 12715 |
| 12716 /* |
| 12717 ** The following macro converts a relative address in the p2 field |
| 12718 ** of a VdbeOp structure into a negative number so that |
| 12719 ** sqlite3VdbeAddOpList() knows that the address is relative. Calling |
| 12720 ** the macro again restores the address. |
| 12721 */ |
| 12722 #define ADDR(X) (-1-(X)) |
| 12723 |
| 12724 /* |
| 12725 ** The makefile scans the vdbe.c source file and creates the "opcodes.h" |
| 12726 ** header file that defines a number for each opcode used by the VDBE. |
| 12727 */ |
| 12728 /************** Include opcodes.h in the middle of vdbe.h ********************/ |
| 12729 /************** Begin file opcodes.h *****************************************/ |
| 12730 /* Automatically generated. Do not edit */ |
| 12731 /* See the tool/mkopcodeh.tcl script for details */ |
| 12732 #define OP_Savepoint 0 |
| 12733 #define OP_AutoCommit 1 |
| 12734 #define OP_Transaction 2 |
| 12735 #define OP_SorterNext 3 |
| 12736 #define OP_PrevIfOpen 4 |
| 12737 #define OP_NextIfOpen 5 |
| 12738 #define OP_Prev 6 |
| 12739 #define OP_Next 7 |
| 12740 #define OP_Checkpoint 8 |
| 12741 #define OP_JournalMode 9 |
| 12742 #define OP_Vacuum 10 |
| 12743 #define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */ |
| 12744 #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */ |
| 12745 #define OP_Goto 13 |
| 12746 #define OP_Gosub 14 |
| 12747 #define OP_InitCoroutine 15 |
| 12748 #define OP_Yield 16 |
| 12749 #define OP_MustBeInt 17 |
| 12750 #define OP_Jump 18 |
| 12751 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 12752 #define OP_Once 20 |
| 12753 #define OP_If 21 |
| 12754 #define OP_IfNot 22 |
| 12755 #define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */ |
| 12756 #define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */ |
| 12757 #define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */ |
| 12758 #define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */ |
| 12759 #define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2])
*/ |
| 12760 #define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2])
*/ |
| 12761 #define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */ |
| 12762 #define OP_NotFound 30 /* synopsis: key=r[P3@P4] */ |
| 12763 #define OP_Found 31 /* synopsis: key=r[P3@P4] */ |
| 12764 #define OP_SeekRowid 32 /* synopsis: intkey=r[P3] */ |
| 12765 #define OP_NotExists 33 /* synopsis: intkey=r[P3] */ |
| 12766 #define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto
P2 */ |
| 12767 #define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL got
o P2 */ |
| 12768 #define OP_Ne 36 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */ |
| 12769 #define OP_Eq 37 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */ |
| 12770 #define OP_Gt 38 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */ |
| 12771 #define OP_Le 39 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */ |
| 12772 #define OP_Lt 40 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */ |
| 12773 #define OP_Ge 41 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */ |
| 12774 #define OP_ElseNotEq 42 /* same as TK_ESCAPE */ |
| 12775 #define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] *
/ |
| 12776 #define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 12777 #define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1]
*/ |
| 12778 #define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1]
*/ |
| 12779 #define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| 12780 #define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 12781 #define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 12782 #define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 12783 #define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 12784 #define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] *
/ |
| 12785 #define OP_Last 53 |
| 12786 #define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 12787 #define OP_SorterSort 55 |
| 12788 #define OP_Sort 56 |
| 12789 #define OP_Rewind 57 |
| 12790 #define OP_IdxLE 58 /* synopsis: key=r[P3@P4] */ |
| 12791 #define OP_IdxGT 59 /* synopsis: key=r[P3@P4] */ |
| 12792 #define OP_IdxLT 60 /* synopsis: key=r[P3@P4] */ |
| 12793 #define OP_IdxGE 61 /* synopsis: key=r[P3@P4] */ |
| 12794 #define OP_RowSetRead 62 /* synopsis: r[P3]=rowset(P1) */ |
| 12795 #define OP_RowSetTest 63 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 12796 #define OP_Program 64 |
| 12797 #define OP_FkIfZero 65 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 12798 #define OP_IfPos 66 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 12799 #define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 12800 #define OP_DecrJumpZero 68 /* synopsis: if (--r[P1])==0 goto P2 */ |
| 12801 #define OP_IncrVacuum 69 |
| 12802 #define OP_VNext 70 |
| 12803 #define OP_Init 71 /* synopsis: Start at P2 */ |
| 12804 #define OP_Return 72 |
| 12805 #define OP_EndCoroutine 73 |
| 12806 #define OP_HaltIfNull 74 /* synopsis: if r[P3]=null halt */ |
| 12807 #define OP_Halt 75 |
| 12808 #define OP_Integer 76 /* synopsis: r[P2]=P1 */ |
| 12809 #define OP_Int64 77 /* synopsis: r[P2]=P4 */ |
| 12810 #define OP_String 78 /* synopsis: r[P2]='P4' (len=P1) */ |
| 12811 #define OP_Null 79 /* synopsis: r[P2..P3]=NULL */ |
| 12812 #define OP_SoftNull 80 /* synopsis: r[P1]=NULL */ |
| 12813 #define OP_Blob 81 /* synopsis: r[P2]=P4 (len=P1) */ |
| 12814 #define OP_Variable 82 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 12815 #define OP_Move 83 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 12816 #define OP_Copy 84 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 12817 #define OP_SCopy 85 /* synopsis: r[P2]=r[P1] */ |
| 12818 #define OP_IntCopy 86 /* synopsis: r[P2]=r[P1] */ |
| 12819 #define OP_ResultRow 87 /* synopsis: output=r[P1@P2] */ |
| 12820 #define OP_CollSeq 88 |
| 12821 #define OP_Function0 89 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12822 #define OP_Function 90 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12823 #define OP_AddImm 91 /* synopsis: r[P1]=r[P1]+P2 */ |
| 12824 #define OP_RealAffinity 92 |
| 12825 #define OP_Cast 93 /* synopsis: affinity(r[P1]) */ |
| 12826 #define OP_Permutation 94 |
| 12827 #define OP_Compare 95 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 12828 #define OP_Column 96 /* synopsis: r[P3]=PX */ |
| 12829 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 12830 #define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */ |
| 12831 #define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 12832 #define OP_Count 100 /* synopsis: r[P2]=count() */ |
| 12833 #define OP_ReadCookie 101 |
| 12834 #define OP_SetCookie 102 |
| 12835 #define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */ |
| 12836 #define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */ |
| 12837 #define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */ |
| 12838 #define OP_OpenAutoindex 106 /* synopsis: nColumn=P2 */ |
| 12839 #define OP_OpenEphemeral 107 /* synopsis: nColumn=P2 */ |
| 12840 #define OP_SorterOpen 108 |
| 12841 #define OP_SequenceTest 109 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 12842 #define OP_OpenPseudo 110 /* synopsis: P3 columns in r[P2] */ |
| 12843 #define OP_Close 111 |
| 12844 #define OP_ColumnsUsed 112 |
| 12845 #define OP_Sequence 113 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 12846 #define OP_NewRowid 114 /* synopsis: r[P2]=rowid */ |
| 12847 #define OP_Insert 115 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 12848 #define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */ |
| 12849 #define OP_Delete 117 |
| 12850 #define OP_ResetCount 118 |
| 12851 #define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 12852 #define OP_SorterData 120 /* synopsis: r[P2]=data */ |
| 12853 #define OP_RowData 121 /* synopsis: r[P2]=data */ |
| 12854 #define OP_Rowid 122 /* synopsis: r[P2]=rowid */ |
| 12855 #define OP_NullRow 123 |
| 12856 #define OP_SorterInsert 124 /* synopsis: key=r[P2] */ |
| 12857 #define OP_IdxInsert 125 /* synopsis: key=r[P2] */ |
| 12858 #define OP_IdxDelete 126 /* synopsis: key=r[P2@P3] */ |
| 12859 #define OP_Seek 127 /* synopsis: Move P3 to P1.rowid */ |
| 12860 #define OP_IdxRowid 128 /* synopsis: r[P2]=rowid */ |
| 12861 #define OP_Destroy 129 |
| 12862 #define OP_Clear 130 |
| 12863 #define OP_ResetSorter 131 |
| 12864 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 12865 #define OP_CreateIndex 133 /* synopsis: r[P2]=root iDb=P1 */ |
| 12866 #define OP_CreateTable 134 /* synopsis: r[P2]=root iDb=P1 */ |
| 12867 #define OP_ParseSchema 135 |
| 12868 #define OP_LoadAnalysis 136 |
| 12869 #define OP_DropTable 137 |
| 12870 #define OP_DropIndex 138 |
| 12871 #define OP_DropTrigger 139 |
| 12872 #define OP_IntegrityCk 140 |
| 12873 #define OP_RowSetAdd 141 /* synopsis: rowset(P1)=r[P2] */ |
| 12874 #define OP_Param 142 |
| 12875 #define OP_FkCounter 143 /* synopsis: fkctr[P1]+=P2 */ |
| 12876 #define OP_MemMax 144 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 12877 #define OP_OffsetLimit 145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3
]) else r[P2]=(-1) */ |
| 12878 #define OP_AggStep0 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12879 #define OP_AggStep 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12880 #define OP_AggFinal 148 /* synopsis: accum=r[P1] N=P2 */ |
| 12881 #define OP_Expire 149 |
| 12882 #define OP_TableLock 150 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 12883 #define OP_VBegin 151 |
| 12884 #define OP_VCreate 152 |
| 12885 #define OP_VDestroy 153 |
| 12886 #define OP_VOpen 154 |
| 12887 #define OP_VColumn 155 /* synopsis: r[P3]=vcolumn(P2) */ |
| 12888 #define OP_VRename 156 |
| 12889 #define OP_Pagecount 157 |
| 12890 #define OP_MaxPgcnt 158 |
| 12891 #define OP_CursorHint 159 |
| 12892 #define OP_Noop 160 |
| 12893 #define OP_Explain 161 |
| 12894 |
| 12895 /* Properties such as "out2" or "jump" that are specified in |
| 12896 ** comments following the "case" for each opcode in the vdbe.c |
| 12897 ** are encoded into bitvectors as follows: |
| 12898 */ |
| 12899 #define OPFLG_JUMP 0x01 /* jump: P2 holds jmp target */ |
| 12900 #define OPFLG_IN1 0x02 /* in1: P1 is an input */ |
| 12901 #define OPFLG_IN2 0x04 /* in2: P2 is an input */ |
| 12902 #define OPFLG_IN3 0x08 /* in3: P3 is an input */ |
| 12903 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */ |
| 12904 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 12905 #define OPFLG_INITIALIZER {\ |
| 12906 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 12907 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\ |
| 12908 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\ |
| 12909 /* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\ |
| 12910 /* 32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 12911 /* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\ |
| 12912 /* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\ |
| 12913 /* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b,\ |
| 12914 /* 64 */ 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01,\ |
| 12915 /* 72 */ 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10,\ |
| 12916 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 12917 /* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\ |
| 12918 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 12919 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12920 /* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12921 /* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\ |
| 12922 /* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\ |
| 12923 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\ |
| 12924 /* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12925 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 12926 /* 160 */ 0x00, 0x00,} |
| 12927 |
| 12928 /* The sqlite3P2Values() routine is able to run faster if it knows |
| 12929 ** the value of the largest JUMP opcode. The smaller the maximum |
| 12930 ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 12931 ** generated this include file strives to group all JUMP opcodes |
| 12932 ** together near the beginning of the list. |
| 12933 */ |
| 12934 #define SQLITE_MX_JUMP_OPCODE 71 /* Maximum JUMP opcode */ |
| 12935 |
| 12936 /************** End of opcodes.h *********************************************/ |
| 12937 /************** Continuing where we left off in vdbe.h ***********************/ |
| 12938 |
| 12939 /* |
| 12940 ** Prototypes for the VDBE interface. See comments on the implementation |
| 12941 ** for a description of what each of these routines does. |
| 12942 */ |
| 12943 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*); |
| 12944 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int); |
| 12945 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int); |
| 12946 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int); |
| 12947 SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int); |
| 12948 SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*); |
| 12949 SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...); |
| 12950 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 12951 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| 12952 SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int); |
| 12953 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int); |
| 12954 SQLITE_PRIVATE void sqlite3VdbeEndCoroutine(Vdbe*,int); |
| 12955 #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS) |
| 12956 SQLITE_PRIVATE void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N); |
| 12957 SQLITE_PRIVATE void sqlite3VdbeVerifyNoResultRow(Vdbe *p); |
| 12958 #else |
| 12959 # define sqlite3VdbeVerifyNoMallocRequired(A,B) |
| 12960 # define sqlite3VdbeVerifyNoResultRow(A) |
| 12961 #endif |
| 12962 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aO
p, int iLineno); |
| 12963 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 12964 SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8); |
| 12965 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 12966 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 12967 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 12968 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); |
| 12969 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 12970 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 12971 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 12972 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N)
; |
| 12973 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type); |
| 12974 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 12975 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 12976 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 12977 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| 12978 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*); |
| 12979 SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe*); |
| 12980 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*); |
| 12981 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3*,Vdbe*); |
| 12982 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*); |
| 12983 SQLITE_PRIVATE int sqlite3VdbeFinalize(Vdbe*); |
| 12984 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe*, int); |
| 12985 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe*); |
| 12986 #ifdef SQLITE_DEBUG |
| 12987 SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *, int); |
| 12988 #endif |
| 12989 SQLITE_PRIVATE void sqlite3VdbeResetStepResult(Vdbe*); |
| 12990 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe*); |
| 12991 SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe*); |
| 12992 SQLITE_PRIVATE void sqlite3VdbeSetNumCols(Vdbe*,int); |
| 12993 SQLITE_PRIVATE int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(
void*)); |
| 12994 SQLITE_PRIVATE void sqlite3VdbeCountChanges(Vdbe*); |
| 12995 SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe*); |
| 12996 SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, int); |
| 12997 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe*,Vdbe*); |
| 12998 SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*); |
| 12999 SQLITE_PRIVATE sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe*, int, u8); |
| 13000 SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe*, int); |
| 13001 #ifndef SQLITE_OMIT_TRACE |
| 13002 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*); |
| 13003 #endif |
| 13004 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| 13005 |
| 13006 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRec
ord*); |
| 13007 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); |
| 13008 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedR
ecord *, int); |
| 13009 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*); |
| 13010 |
| 13011 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); |
| 13012 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*); |
| 13013 |
| 13014 #ifndef SQLITE_OMIT_TRIGGER |
| 13015 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *); |
| 13016 #endif |
| 13017 |
| 13018 /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on |
| 13019 ** each VDBE opcode. |
| 13020 ** |
| 13021 ** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op |
| 13022 ** comments in VDBE programs that show key decision points in the code |
| 13023 ** generator. |
| 13024 */ |
| 13025 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 13026 SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe*, const char*, ...); |
| 13027 # define VdbeComment(X) sqlite3VdbeComment X |
| 13028 SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe*, const char*, ...); |
| 13029 # define VdbeNoopComment(X) sqlite3VdbeNoopComment X |
| 13030 # ifdef SQLITE_ENABLE_MODULE_COMMENTS |
| 13031 # define VdbeModuleComment(X) sqlite3VdbeNoopComment X |
| 13032 # else |
| 13033 # define VdbeModuleComment(X) |
| 13034 # endif |
| 13035 #else |
| 13036 # define VdbeComment(X) |
| 13037 # define VdbeNoopComment(X) |
| 13038 # define VdbeModuleComment(X) |
| 13039 #endif |
| 13040 |
| 13041 /* |
| 13042 ** The VdbeCoverage macros are used to set a coverage testing point |
| 13043 ** for VDBE branch instructions. The coverage testing points are line |
| 13044 ** numbers in the sqlite3.c source file. VDBE branch coverage testing |
| 13045 ** only works with an amalagmation build. That's ok since a VDBE branch |
| 13046 ** coverage build designed for testing the test suite only. No application |
| 13047 ** should ever ship with VDBE branch coverage measuring turned on. |
| 13048 ** |
| 13049 ** VdbeCoverage(v) // Mark the previously coded instruction |
| 13050 ** // as a branch |
| 13051 ** |
| 13052 ** VdbeCoverageIf(v, conditional) // Mark previous if conditional true |
| 13053 ** |
| 13054 ** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken |
| 13055 ** |
| 13056 ** VdbeCoverageNeverTaken(v) // Previous branch is never taken |
| 13057 ** |
| 13058 ** Every VDBE branch operation must be tagged with one of the macros above. |
| 13059 ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and |
| 13060 ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch() |
| 13061 ** routine in vdbe.c, alerting the developer to the missed tag. |
| 13062 */ |
| 13063 #ifdef SQLITE_VDBE_COVERAGE |
| 13064 SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe*,int); |
| 13065 # define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__) |
| 13066 # define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__) |
| 13067 # define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2); |
| 13068 # define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1); |
| 13069 # define VDBE_OFFSET_LINENO(x) (__LINE__+x) |
| 13070 #else |
| 13071 # define VdbeCoverage(v) |
| 13072 # define VdbeCoverageIf(v,x) |
| 13073 # define VdbeCoverageAlwaysTaken(v) |
| 13074 # define VdbeCoverageNeverTaken(v) |
| 13075 # define VDBE_OFFSET_LINENO(x) 0 |
| 13076 #endif |
| 13077 |
| 13078 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 13079 SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const ch
ar*); |
| 13080 #else |
| 13081 # define sqlite3VdbeScanStatus(a,b,c,d,e) |
| 13082 #endif |
| 13083 |
| 13084 #endif /* SQLITE_VDBE_H */ |
| 13085 |
| 13086 /************** End of vdbe.h ************************************************/ |
| 13087 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 13088 /************** Include pager.h in the middle of sqliteInt.h *****************/ |
| 13089 /************** Begin file pager.h *******************************************/ |
| 13090 /* |
| 13091 ** 2001 September 15 |
| 13092 ** |
| 13093 ** The author disclaims copyright to this source code. In place of |
| 13094 ** a legal notice, here is a blessing: |
| 13095 ** |
| 13096 ** May you do good and not evil. |
| 13097 ** May you find forgiveness for yourself and forgive others. |
| 13098 ** May you share freely, never taking more than you give. |
| 13099 ** |
| 13100 ************************************************************************* |
| 13101 ** This header file defines the interface that the sqlite page cache |
| 13102 ** subsystem. The page cache subsystem reads and writes a file a page |
| 13103 ** at a time and provides a journal for rollback. |
| 13104 */ |
| 13105 |
| 13106 #ifndef SQLITE_PAGER_H |
| 13107 #define SQLITE_PAGER_H |
| 13108 |
| 13109 /* |
| 13110 ** Default maximum size for persistent journal files. A negative |
| 13111 ** value means no limit. This value may be overridden using the |
| 13112 ** sqlite3PagerJournalSizeLimit() API. See also "PRAGMA journal_size_limit". |
| 13113 */ |
| 13114 #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT |
| 13115 #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1 |
| 13116 #endif |
| 13117 |
| 13118 /* |
| 13119 ** The type used to represent a page number. The first page in a file |
| 13120 ** is called page 1. 0 is used to represent "not a page". |
| 13121 */ |
| 13122 typedef u32 Pgno; |
| 13123 |
| 13124 /* |
| 13125 ** Each open file is managed by a separate instance of the "Pager" structure. |
| 13126 */ |
| 13127 typedef struct Pager Pager; |
| 13128 |
| 13129 /* |
| 13130 ** Handle type for pages. |
| 13131 */ |
| 13132 typedef struct PgHdr DbPage; |
| 13133 |
| 13134 /* |
| 13135 ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is |
| 13136 ** reserved for working around a windows/posix incompatibility). It is |
| 13137 ** used in the journal to signify that the remainder of the journal file |
| 13138 ** is devoted to storing a master journal name - there are no more pages to |
| 13139 ** roll back. See comments for function writeMasterJournal() in pager.c |
| 13140 ** for details. |
| 13141 */ |
| 13142 #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) |
| 13143 |
| 13144 /* |
| 13145 ** Allowed values for the flags parameter to sqlite3PagerOpen(). |
| 13146 ** |
| 13147 ** NOTE: These values must match the corresponding BTREE_ values in btree.h. |
| 13148 */ |
| 13149 #define PAGER_OMIT_JOURNAL 0x0001 /* Do not use a rollback journal */ |
| 13150 #define PAGER_MEMORY 0x0002 /* In-memory database */ |
| 13151 |
| 13152 /* |
| 13153 ** Valid values for the second argument to sqlite3PagerLockingMode(). |
| 13154 */ |
| 13155 #define PAGER_LOCKINGMODE_QUERY -1 |
| 13156 #define PAGER_LOCKINGMODE_NORMAL 0 |
| 13157 #define PAGER_LOCKINGMODE_EXCLUSIVE 1 |
| 13158 |
| 13159 /* |
| 13160 ** Numeric constants that encode the journalmode. |
| 13161 ** |
| 13162 ** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY) |
| 13163 ** are exposed in the API via the "PRAGMA journal_mode" command and |
| 13164 ** therefore cannot be changed without a compatibility break. |
| 13165 */ |
| 13166 #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */ |
| 13167 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */ |
| 13168 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */ |
| 13169 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */ |
| 13170 #define PAGER_JOURNALMODE_TRUNCATE 3 /* Commit by truncating journal */ |
| 13171 #define PAGER_JOURNALMODE_MEMORY 4 /* In-memory journal file */ |
| 13172 #define PAGER_JOURNALMODE_WAL 5 /* Use write-ahead logging */ |
| 13173 |
| 13174 /* |
| 13175 ** Flags that make up the mask passed to sqlite3PagerGet(). |
| 13176 */ |
| 13177 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */ |
| 13178 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */ |
| 13179 |
| 13180 /* |
| 13181 ** Flags for sqlite3PagerSetFlags() |
| 13182 ** |
| 13183 ** Value constraints (enforced via assert()): |
| 13184 ** PAGER_FULLFSYNC == SQLITE_FullFSync |
| 13185 ** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync |
| 13186 ** PAGER_CACHE_SPILL == SQLITE_CacheSpill |
| 13187 */ |
| 13188 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */ |
| 13189 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */ |
| 13190 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */ |
| 13191 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */ |
| 13192 #define PAGER_SYNCHRONOUS_MASK 0x07 /* Mask for four values above */ |
| 13193 #define PAGER_FULLFSYNC 0x08 /* PRAGMA fullfsync=ON */ |
| 13194 #define PAGER_CKPT_FULLFSYNC 0x10 /* PRAGMA checkpoint_fullfsync=ON */ |
| 13195 #define PAGER_CACHESPILL 0x20 /* PRAGMA cache_spill=ON */ |
| 13196 #define PAGER_FLAGS_MASK 0x38 /* All above except SYNCHRONOUS */ |
| 13197 |
| 13198 /* |
| 13199 ** The remainder of this file contains the declarations of the functions |
| 13200 ** that make up the Pager sub-system API. See source code comments for |
| 13201 ** a detailed description of each routine. |
| 13202 */ |
| 13203 |
| 13204 /* Open and close a Pager connection. */ |
| 13205 SQLITE_PRIVATE int sqlite3PagerOpen( |
| 13206 sqlite3_vfs*, |
| 13207 Pager **ppPager, |
| 13208 const char*, |
| 13209 int, |
| 13210 int, |
| 13211 int, |
| 13212 void(*)(DbPage*) |
| 13213 ); |
| 13214 SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*); |
| 13215 SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 13216 |
| 13217 /* Functions used to configure a Pager object. */ |
| 13218 SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); |
| 13219 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 13220 #ifdef SQLITE_HAS_CODEC |
| 13221 SQLITE_PRIVATE void sqlite3PagerAlignReserve(Pager*,Pager*); |
| 13222 #endif |
| 13223 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 13224 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 13225 SQLITE_PRIVATE int sqlite3PagerSetSpillsize(Pager*, int); |
| 13226 SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 13227 SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| 13228 SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned); |
| 13229 SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int); |
| 13230 SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int); |
| 13231 SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*); |
| 13232 SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*); |
| 13233 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64); |
| 13234 SQLITE_PRIVATE sqlite3_backup **sqlite3PagerBackupPtr(Pager*); |
| 13235 SQLITE_PRIVATE int sqlite3PagerFlush(Pager*); |
| 13236 |
| 13237 /* Functions used to obtain and release page references. */ |
| 13238 SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, in
t clrFlag); |
| 13239 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); |
| 13240 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*); |
| 13241 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*); |
| 13242 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*); |
| 13243 |
| 13244 /* Operations on page references. */ |
| 13245 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); |
| 13246 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*); |
| 13247 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); |
| 13248 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*); |
| 13249 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *); |
| 13250 SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *); |
| 13251 |
| 13252 /* Functions used to manage pager transactions and savepoints. */ |
| 13253 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*); |
| 13254 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int); |
| 13255 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int); |
| 13256 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*); |
| 13257 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster); |
| 13258 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*); |
| 13259 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*); |
| 13260 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n); |
| 13261 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); |
| 13262 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager); |
| 13263 |
| 13264 #ifndef SQLITE_OMIT_WAL |
| 13265 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*,
int*); |
| 13266 SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 13267 SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 13268 SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 13269 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 13270 # ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 13271 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno); |
| 13272 # endif |
| 13273 # ifdef SQLITE_ENABLE_SNAPSHOT |
| 13274 SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **p
pSnapshot); |
| 13275 SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *p
Snapshot); |
| 13276 SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 13277 # endif |
| 13278 #else |
| 13279 # define sqlite3PagerUseWal(x,y) 0 |
| 13280 #endif |
| 13281 |
| 13282 #ifdef SQLITE_ENABLE_ZIPVFS |
| 13283 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 13284 #endif |
| 13285 |
| 13286 /* Functions used to query pager state and configuration. */ |
| 13287 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*); |
| 13288 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*); |
| 13289 #ifdef SQLITE_DEBUG |
| 13290 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); |
| 13291 #endif |
| 13292 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); |
| 13293 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int); |
| 13294 SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*); |
| 13295 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); |
| 13296 SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*); |
| 13297 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*); |
| 13298 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); |
| 13299 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); |
| 13300 SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); |
| 13301 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*); |
| 13302 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 13303 |
| 13304 /* Functions used to truncate the database file. */ |
| 13305 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 13306 |
| 13307 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| 13308 |
| 13309 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL) |
| 13310 SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *); |
| 13311 #endif |
| 13312 |
| 13313 /* Functions to support testing and debugging. */ |
| 13314 #if !defined(NDEBUG) || defined(SQLITE_TEST) |
| 13315 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*); |
| 13316 SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*); |
| 13317 #endif |
| 13318 #ifdef SQLITE_TEST |
| 13319 SQLITE_PRIVATE int *sqlite3PagerStats(Pager*); |
| 13320 SQLITE_PRIVATE void sqlite3PagerRefdump(Pager*); |
| 13321 void disable_simulated_io_errors(void); |
| 13322 void enable_simulated_io_errors(void); |
| 13323 #else |
| 13324 # define disable_simulated_io_errors() |
| 13325 # define enable_simulated_io_errors() |
| 13326 #endif |
| 13327 |
| 13328 #endif /* SQLITE_PAGER_H */ |
| 13329 |
| 13330 /************** End of pager.h ***********************************************/ |
| 13331 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 13332 /************** Include pcache.h in the middle of sqliteInt.h ****************/ |
| 13333 /************** Begin file pcache.h ******************************************/ |
| 13334 /* |
| 13335 ** 2008 August 05 |
| 13336 ** |
| 13337 ** The author disclaims copyright to this source code. In place of |
| 13338 ** a legal notice, here is a blessing: |
| 13339 ** |
| 13340 ** May you do good and not evil. |
| 13341 ** May you find forgiveness for yourself and forgive others. |
| 13342 ** May you share freely, never taking more than you give. |
| 13343 ** |
| 13344 ************************************************************************* |
| 13345 ** This header file defines the interface that the sqlite page cache |
| 13346 ** subsystem. |
| 13347 */ |
| 13348 |
| 13349 #ifndef _PCACHE_H_ |
| 13350 |
| 13351 typedef struct PgHdr PgHdr; |
| 13352 typedef struct PCache PCache; |
| 13353 |
| 13354 /* |
| 13355 ** Every page in the cache is controlled by an instance of the following |
| 13356 ** structure. |
| 13357 */ |
| 13358 struct PgHdr { |
| 13359 sqlite3_pcache_page *pPage; /* Pcache object page handle */ |
| 13360 void *pData; /* Page data */ |
| 13361 void *pExtra; /* Extra content */ |
| 13362 PgHdr *pDirty; /* Transient list of dirty sorted by pgno */ |
| 13363 Pager *pPager; /* The pager this page is part of */ |
| 13364 Pgno pgno; /* Page number for this page */ |
| 13365 #ifdef SQLITE_CHECK_PAGES |
| 13366 u32 pageHash; /* Hash of page content */ |
| 13367 #endif |
| 13368 u16 flags; /* PGHDR flags defined below */ |
| 13369 |
| 13370 /********************************************************************** |
| 13371 ** Elements above are public. All that follows is private to pcache.c |
| 13372 ** and should not be accessed by other modules. |
| 13373 */ |
| 13374 i16 nRef; /* Number of users of this page */ |
| 13375 PCache *pCache; /* Cache that owns this page */ |
| 13376 |
| 13377 PgHdr *pDirtyNext; /* Next element in list of dirty pages */ |
| 13378 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */ |
| 13379 }; |
| 13380 |
| 13381 /* Bit values for PgHdr.flags */ |
| 13382 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */ |
| 13383 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */ |
| 13384 #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */ |
| 13385 #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before |
| 13386 ** writing this page to the database */ |
| 13387 #define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */ |
| 13388 #define PGHDR_MMAP 0x020 /* This is an mmap page object */ |
| 13389 |
| 13390 #define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */ |
| 13391 |
| 13392 /* Initialize and shutdown the page cache subsystem */ |
| 13393 SQLITE_PRIVATE int sqlite3PcacheInitialize(void); |
| 13394 SQLITE_PRIVATE void sqlite3PcacheShutdown(void); |
| 13395 |
| 13396 /* Page cache buffer management: |
| 13397 ** These routines implement SQLITE_CONFIG_PAGECACHE. |
| 13398 */ |
| 13399 SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *, int sz, int n); |
| 13400 |
| 13401 /* Create a new pager cache. |
| 13402 ** Under memory stress, invoke xStress to try to make pages clean. |
| 13403 ** Only clean and unpinned pages can be reclaimed. |
| 13404 */ |
| 13405 SQLITE_PRIVATE int sqlite3PcacheOpen( |
| 13406 int szPage, /* Size of every page */ |
| 13407 int szExtra, /* Extra space associated with each page */ |
| 13408 int bPurgeable, /* True if pages are on backing store */ |
| 13409 int (*xStress)(void*, PgHdr*), /* Call to try to make pages clean */ |
| 13410 void *pStress, /* Argument to xStress */ |
| 13411 PCache *pToInit /* Preallocated space for the PCache */ |
| 13412 ); |
| 13413 |
| 13414 /* Modify the page-size after the cache has been created. */ |
| 13415 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *, int); |
| 13416 |
| 13417 /* Return the size in bytes of a PCache object. Used to preallocate |
| 13418 ** storage space. |
| 13419 */ |
| 13420 SQLITE_PRIVATE int sqlite3PcacheSize(void); |
| 13421 |
| 13422 /* One release per successful fetch. Page is pinned until released. |
| 13423 ** Reference counted. |
| 13424 */ |
| 13425 SQLITE_PRIVATE sqlite3_pcache_page *sqlite3PcacheFetch(PCache*, Pgno, int create
Flag); |
| 13426 SQLITE_PRIVATE int sqlite3PcacheFetchStress(PCache*, Pgno, sqlite3_pcache_page**
); |
| 13427 SQLITE_PRIVATE PgHdr *sqlite3PcacheFetchFinish(PCache*, Pgno, sqlite3_pcache_pag
e *pPage); |
| 13428 SQLITE_PRIVATE void sqlite3PcacheRelease(PgHdr*); |
| 13429 |
| 13430 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache
*/ |
| 13431 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is mark
ed dirty */ |
| 13432 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as
clean */ |
| 13433 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pa
ges as clean */ |
| 13434 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache*); |
| 13435 |
| 13436 /* Change a page number. Used by incr-vacuum. */ |
| 13437 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno); |
| 13438 |
| 13439 /* Remove all pages with pgno>x. Reset the cache if x==0 */ |
| 13440 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache*, Pgno x); |
| 13441 |
| 13442 /* Get a list of all dirty pages in the cache, sorted by page number */ |
| 13443 SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache*); |
| 13444 |
| 13445 /* Reset and close the cache object */ |
| 13446 SQLITE_PRIVATE void sqlite3PcacheClose(PCache*); |
| 13447 |
| 13448 /* Clear flags from pages of the page cache */ |
| 13449 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *); |
| 13450 |
| 13451 /* Discard the contents of the cache */ |
| 13452 SQLITE_PRIVATE void sqlite3PcacheClear(PCache*); |
| 13453 |
| 13454 /* Return the total number of outstanding page references */ |
| 13455 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*); |
| 13456 |
| 13457 /* Increment the reference count of an existing page */ |
| 13458 SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr*); |
| 13459 |
| 13460 SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr*); |
| 13461 |
| 13462 /* Return the total number of pages stored in the cache */ |
| 13463 SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*); |
| 13464 |
| 13465 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 13466 /* Iterate through all dirty pages currently stored in the cache. This |
| 13467 ** interface is only available if SQLITE_CHECK_PAGES is defined when the |
| 13468 ** library is built. |
| 13469 */ |
| 13470 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHd
r *)); |
| 13471 #endif |
| 13472 |
| 13473 #if defined(SQLITE_DEBUG) |
| 13474 /* Check invariants on a PgHdr object */ |
| 13475 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr*); |
| 13476 #endif |
| 13477 |
| 13478 /* Set and get the suggested cache-size for the specified pager-cache. |
| 13479 ** |
| 13480 ** If no global maximum is configured, then the system attempts to limit |
| 13481 ** the total number of pages cached by purgeable pager-caches to the sum |
| 13482 ** of the suggested cache-sizes. |
| 13483 */ |
| 13484 SQLITE_PRIVATE void sqlite3PcacheSetCachesize(PCache *, int); |
| 13485 #ifdef SQLITE_TEST |
| 13486 SQLITE_PRIVATE int sqlite3PcacheGetCachesize(PCache *); |
| 13487 #endif |
| 13488 |
| 13489 /* Set or get the suggested spill-size for the specified pager-cache. |
| 13490 ** |
| 13491 ** The spill-size is the minimum number of pages in cache before the cache |
| 13492 ** will attempt to spill dirty pages by calling xStress. |
| 13493 */ |
| 13494 SQLITE_PRIVATE int sqlite3PcacheSetSpillsize(PCache *, int); |
| 13495 |
| 13496 /* Free up as much memory as possible from the page cache */ |
| 13497 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache*); |
| 13498 |
| 13499 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 13500 /* Try to return memory used by the pcache module to the main memory heap */ |
| 13501 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int); |
| 13502 #endif |
| 13503 |
| 13504 #ifdef SQLITE_TEST |
| 13505 SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*); |
| 13506 #endif |
| 13507 |
| 13508 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void); |
| 13509 |
| 13510 /* Return the header size */ |
| 13511 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void); |
| 13512 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void); |
| 13513 |
| 13514 /* Number of dirty pages as a percentage of the configured cache size */ |
| 13515 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache*); |
| 13516 |
| 13517 #endif /* _PCACHE_H_ */ |
| 13518 |
| 13519 /************** End of pcache.h **********************************************/ |
| 13520 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 13521 /************** Include os.h in the middle of sqliteInt.h ********************/ |
| 13522 /************** Begin file os.h **********************************************/ |
| 13523 /* |
| 13524 ** 2001 September 16 |
| 13525 ** |
| 13526 ** The author disclaims copyright to this source code. In place of |
| 13527 ** a legal notice, here is a blessing: |
| 13528 ** |
| 13529 ** May you do good and not evil. |
| 13530 ** May you find forgiveness for yourself and forgive others. |
| 13531 ** May you share freely, never taking more than you give. |
| 13532 ** |
| 13533 ****************************************************************************** |
| 13534 ** |
| 13535 ** This header file (together with is companion C source-code file |
| 13536 ** "os.c") attempt to abstract the underlying operating system so that |
| 13537 ** the SQLite library will work on both POSIX and windows systems. |
| 13538 ** |
| 13539 ** This header file is #include-ed by sqliteInt.h and thus ends up |
| 13540 ** being included by every source file. |
| 13541 */ |
| 13542 #ifndef _SQLITE_OS_H_ |
| 13543 #define _SQLITE_OS_H_ |
| 13544 |
| 13545 /* |
| 13546 ** Attempt to automatically detect the operating system and setup the |
| 13547 ** necessary pre-processor macros for it. |
| 13548 */ |
| 13549 /************** Include os_setup.h in the middle of os.h *********************/ |
| 13550 /************** Begin file os_setup.h ****************************************/ |
| 13551 /* |
| 13552 ** 2013 November 25 |
| 13553 ** |
| 13554 ** The author disclaims copyright to this source code. In place of |
| 13555 ** a legal notice, here is a blessing: |
| 13556 ** |
| 13557 ** May you do good and not evil. |
| 13558 ** May you find forgiveness for yourself and forgive others. |
| 13559 ** May you share freely, never taking more than you give. |
| 13560 ** |
| 13561 ****************************************************************************** |
| 13562 ** |
| 13563 ** This file contains pre-processor directives related to operating system |
| 13564 ** detection and/or setup. |
| 13565 */ |
| 13566 #ifndef SQLITE_OS_SETUP_H |
| 13567 #define SQLITE_OS_SETUP_H |
| 13568 |
| 13569 /* |
| 13570 ** Figure out if we are dealing with Unix, Windows, or some other operating |
| 13571 ** system. |
| 13572 ** |
| 13573 ** After the following block of preprocess macros, all of SQLITE_OS_UNIX, |
| 13574 ** SQLITE_OS_WIN, and SQLITE_OS_OTHER will defined to either 1 or 0. One of |
| 13575 ** the three will be 1. The other two will be 0. |
| 13576 */ |
| 13577 #if defined(SQLITE_OS_OTHER) |
| 13578 # if SQLITE_OS_OTHER==1 |
| 13579 # undef SQLITE_OS_UNIX |
| 13580 # define SQLITE_OS_UNIX 0 |
| 13581 # undef SQLITE_OS_WIN |
| 13582 # define SQLITE_OS_WIN 0 |
| 13583 # else |
| 13584 # undef SQLITE_OS_OTHER |
| 13585 # endif |
| 13586 #endif |
| 13587 #if !defined(SQLITE_OS_UNIX) && !defined(SQLITE_OS_OTHER) |
| 13588 # define SQLITE_OS_OTHER 0 |
| 13589 # ifndef SQLITE_OS_WIN |
| 13590 # if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || \ |
| 13591 defined(__MINGW32__) || defined(__BORLANDC__) |
| 13592 # define SQLITE_OS_WIN 1 |
| 13593 # define SQLITE_OS_UNIX 0 |
| 13594 # else |
| 13595 # define SQLITE_OS_WIN 0 |
| 13596 # define SQLITE_OS_UNIX 1 |
| 13597 # endif |
| 13598 # else |
| 13599 # define SQLITE_OS_UNIX 0 |
| 13600 # endif |
| 13601 #else |
| 13602 # ifndef SQLITE_OS_WIN |
| 13603 # define SQLITE_OS_WIN 0 |
| 13604 # endif |
| 13605 #endif |
| 13606 |
| 13607 #endif /* SQLITE_OS_SETUP_H */ |
| 13608 |
| 13609 /************** End of os_setup.h ********************************************/ |
| 13610 /************** Continuing where we left off in os.h *************************/ |
| 13611 |
| 13612 /* If the SET_FULLSYNC macro is not defined above, then make it |
| 13613 ** a no-op |
| 13614 */ |
| 13615 #ifndef SET_FULLSYNC |
| 13616 # define SET_FULLSYNC(x,y) |
| 13617 #endif |
| 13618 |
| 13619 /* |
| 13620 ** The default size of a disk sector |
| 13621 */ |
| 13622 #ifndef SQLITE_DEFAULT_SECTOR_SIZE |
| 13623 # define SQLITE_DEFAULT_SECTOR_SIZE 4096 |
| 13624 #endif |
| 13625 |
| 13626 /* |
| 13627 ** Temporary files are named starting with this prefix followed by 16 random |
| 13628 ** alphanumeric characters, and no file extension. They are stored in the |
| 13629 ** OS's standard temporary file directory, and are deleted prior to exit. |
| 13630 ** If sqlite is being embedded in another program, you may wish to change the |
| 13631 ** prefix to reflect your program's name, so that if your program exits |
| 13632 ** prematurely, old temporary files can be easily identified. This can be done |
| 13633 ** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line. |
| 13634 ** |
| 13635 ** 2006-10-31: The default prefix used to be "sqlite_". But then |
| 13636 ** Mcafee started using SQLite in their anti-virus product and it |
| 13637 ** started putting files with the "sqlite" name in the c:/temp folder. |
| 13638 ** This annoyed many windows users. Those users would then do a |
| 13639 ** Google search for "sqlite", find the telephone numbers of the |
| 13640 ** developers and call to wake them up at night and complain. |
| 13641 ** For this reason, the default name prefix is changed to be "sqlite" |
| 13642 ** spelled backwards. So the temp files are still identified, but |
| 13643 ** anybody smart enough to figure out the code is also likely smart |
| 13644 ** enough to know that calling the developer will not help get rid |
| 13645 ** of the file. |
| 13646 */ |
| 13647 #ifndef SQLITE_TEMP_FILE_PREFIX |
| 13648 # define SQLITE_TEMP_FILE_PREFIX "etilqs_" |
| 13649 #endif |
| 13650 |
| 13651 /* |
| 13652 ** The following values may be passed as the second argument to |
| 13653 ** sqlite3OsLock(). The various locks exhibit the following semantics: |
| 13654 ** |
| 13655 ** SHARED: Any number of processes may hold a SHARED lock simultaneously. |
| 13656 ** RESERVED: A single process may hold a RESERVED lock on a file at |
| 13657 ** any time. Other processes may hold and obtain new SHARED locks. |
| 13658 ** PENDING: A single process may hold a PENDING lock on a file at |
| 13659 ** any one time. Existing SHARED locks may persist, but no new |
| 13660 ** SHARED locks may be obtained by other processes. |
| 13661 ** EXCLUSIVE: An EXCLUSIVE lock precludes all other locks. |
| 13662 ** |
| 13663 ** PENDING_LOCK may not be passed directly to sqlite3OsLock(). Instead, a |
| 13664 ** process that requests an EXCLUSIVE lock may actually obtain a PENDING |
| 13665 ** lock. This can be upgraded to an EXCLUSIVE lock by a subsequent call to |
| 13666 ** sqlite3OsLock(). |
| 13667 */ |
| 13668 #define NO_LOCK 0 |
| 13669 #define SHARED_LOCK 1 |
| 13670 #define RESERVED_LOCK 2 |
| 13671 #define PENDING_LOCK 3 |
| 13672 #define EXCLUSIVE_LOCK 4 |
| 13673 |
| 13674 /* |
| 13675 ** File Locking Notes: (Mostly about windows but also some info for Unix) |
| 13676 ** |
| 13677 ** We cannot use LockFileEx() or UnlockFileEx() on Win95/98/ME because |
| 13678 ** those functions are not available. So we use only LockFile() and |
| 13679 ** UnlockFile(). |
| 13680 ** |
| 13681 ** LockFile() prevents not just writing but also reading by other processes. |
| 13682 ** A SHARED_LOCK is obtained by locking a single randomly-chosen |
| 13683 ** byte out of a specific range of bytes. The lock byte is obtained at |
| 13684 ** random so two separate readers can probably access the file at the |
| 13685 ** same time, unless they are unlucky and choose the same lock byte. |
| 13686 ** An EXCLUSIVE_LOCK is obtained by locking all bytes in the range. |
| 13687 ** There can only be one writer. A RESERVED_LOCK is obtained by locking |
| 13688 ** a single byte of the file that is designated as the reserved lock byte. |
| 13689 ** A PENDING_LOCK is obtained by locking a designated byte different from |
| 13690 ** the RESERVED_LOCK byte. |
| 13691 ** |
| 13692 ** On WinNT/2K/XP systems, LockFileEx() and UnlockFileEx() are available, |
| 13693 ** which means we can use reader/writer locks. When reader/writer locks |
| 13694 ** are used, the lock is placed on the same range of bytes that is used |
| 13695 ** for probabilistic locking in Win95/98/ME. Hence, the locking scheme |
| 13696 ** will support two or more Win95 readers or two or more WinNT readers. |
| 13697 ** But a single Win95 reader will lock out all WinNT readers and a single |
| 13698 ** WinNT reader will lock out all other Win95 readers. |
| 13699 ** |
| 13700 ** The following #defines specify the range of bytes used for locking. |
| 13701 ** SHARED_SIZE is the number of bytes available in the pool from which |
| 13702 ** a random byte is selected for a shared lock. The pool of bytes for |
| 13703 ** shared locks begins at SHARED_FIRST. |
| 13704 ** |
| 13705 ** The same locking strategy and |
| 13706 ** byte ranges are used for Unix. This leaves open the possibility of having |
| 13707 ** clients on win95, winNT, and unix all talking to the same shared file |
| 13708 ** and all locking correctly. To do so would require that samba (or whatever |
| 13709 ** tool is being used for file sharing) implements locks correctly between |
| 13710 ** windows and unix. I'm guessing that isn't likely to happen, but by |
| 13711 ** using the same locking range we are at least open to the possibility. |
| 13712 ** |
| 13713 ** Locking in windows is manditory. For this reason, we cannot store |
| 13714 ** actual data in the bytes used for locking. The pager never allocates |
| 13715 ** the pages involved in locking therefore. SHARED_SIZE is selected so |
| 13716 ** that all locks will fit on a single page even at the minimum page size. |
| 13717 ** PENDING_BYTE defines the beginning of the locks. By default PENDING_BYTE |
| 13718 ** is set high so that we don't have to allocate an unused page except |
| 13719 ** for very large databases. But one should test the page skipping logic |
| 13720 ** by setting PENDING_BYTE low and running the entire regression suite. |
| 13721 ** |
| 13722 ** Changing the value of PENDING_BYTE results in a subtly incompatible |
| 13723 ** file format. Depending on how it is changed, you might not notice |
| 13724 ** the incompatibility right away, even running a full regression test. |
| 13725 ** The default location of PENDING_BYTE is the first byte past the |
| 13726 ** 1GB boundary. |
| 13727 ** |
| 13728 */ |
| 13729 #ifdef SQLITE_OMIT_WSD |
| 13730 # define PENDING_BYTE (0x40000000) |
| 13731 #else |
| 13732 # define PENDING_BYTE sqlite3PendingByte |
| 13733 #endif |
| 13734 #define RESERVED_BYTE (PENDING_BYTE+1) |
| 13735 #define SHARED_FIRST (PENDING_BYTE+2) |
| 13736 #define SHARED_SIZE 510 |
| 13737 |
| 13738 /* |
| 13739 ** Wrapper around OS specific sqlite3_os_init() function. |
| 13740 */ |
| 13741 SQLITE_PRIVATE int sqlite3OsInit(void); |
| 13742 |
| 13743 /* |
| 13744 ** Functions for accessing sqlite3_file methods |
| 13745 */ |
| 13746 SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*); |
| 13747 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset); |
| 13748 SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offse
t); |
| 13749 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size); |
| 13750 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int); |
| 13751 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); |
| 13752 SQLITE_PRIVATE int sqlite3OsLock(sqlite3_file*, int); |
| 13753 SQLITE_PRIVATE int sqlite3OsUnlock(sqlite3_file*, int); |
| 13754 SQLITE_PRIVATE int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut); |
| 13755 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file*,int,void*); |
| 13756 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file*,int,void*); |
| 13757 #define SQLITE_FCNTL_DB_UNCHANGED 0xca093fa0 |
| 13758 SQLITE_PRIVATE int sqlite3OsSectorSize(sqlite3_file *id); |
| 13759 SQLITE_PRIVATE int sqlite3OsDeviceCharacteristics(sqlite3_file *id); |
| 13760 SQLITE_PRIVATE int sqlite3OsShmMap(sqlite3_file *,int,int,int,void volatile **); |
| 13761 SQLITE_PRIVATE int sqlite3OsShmLock(sqlite3_file *id, int, int, int); |
| 13762 SQLITE_PRIVATE void sqlite3OsShmBarrier(sqlite3_file *id); |
| 13763 SQLITE_PRIVATE int sqlite3OsShmUnmap(sqlite3_file *id, int); |
| 13764 SQLITE_PRIVATE int sqlite3OsFetch(sqlite3_file *id, i64, int, void **); |
| 13765 SQLITE_PRIVATE int sqlite3OsUnfetch(sqlite3_file *, i64, void *); |
| 13766 |
| 13767 |
| 13768 /* |
| 13769 ** Functions for accessing sqlite3_vfs methods |
| 13770 */ |
| 13771 SQLITE_PRIVATE int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int
, int *); |
| 13772 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *, const char *, int); |
| 13773 SQLITE_PRIVATE int sqlite3OsAccess(sqlite3_vfs *, const char *, int, int *pResOu
t); |
| 13774 SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char
*); |
| 13775 #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 13776 SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *); |
| 13777 SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *); |
| 13778 SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void)
; |
| 13779 SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *); |
| 13780 #endif /* SQLITE_OMIT_LOAD_EXTENSION */ |
| 13781 SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *); |
| 13782 SQLITE_PRIVATE int sqlite3OsSleep(sqlite3_vfs *, int); |
| 13783 SQLITE_PRIVATE int sqlite3OsGetLastError(sqlite3_vfs*); |
| 13784 SQLITE_PRIVATE int sqlite3OsCurrentTimeInt64(sqlite3_vfs *, sqlite3_int64*); |
| 13785 |
| 13786 /* |
| 13787 ** Convenience functions for opening and closing files using |
| 13788 ** sqlite3_malloc() to obtain space for the file-handle structure. |
| 13789 */ |
| 13790 SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file
**, int,int*); |
| 13791 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *); |
| 13792 |
| 13793 #endif /* _SQLITE_OS_H_ */ |
| 13794 |
| 13795 /************** End of os.h **************************************************/ |
| 13796 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 13797 /************** Include mutex.h in the middle of sqliteInt.h *****************/ |
| 13798 /************** Begin file mutex.h *******************************************/ |
| 13799 /* |
| 13800 ** 2007 August 28 |
| 13801 ** |
| 13802 ** The author disclaims copyright to this source code. In place of |
| 13803 ** a legal notice, here is a blessing: |
| 13804 ** |
| 13805 ** May you do good and not evil. |
| 13806 ** May you find forgiveness for yourself and forgive others. |
| 13807 ** May you share freely, never taking more than you give. |
| 13808 ** |
| 13809 ************************************************************************* |
| 13810 ** |
| 13811 ** This file contains the common header for all mutex implementations. |
| 13812 ** The sqliteInt.h header #includes this file so that it is available |
| 13813 ** to all source files. We break it out in an effort to keep the code |
| 13814 ** better organized. |
| 13815 ** |
| 13816 ** NOTE: source files should *not* #include this header file directly. |
| 13817 ** Source files should #include the sqliteInt.h file and let that file |
| 13818 ** include this one indirectly. |
| 13819 */ |
| 13820 |
| 13821 |
| 13822 /* |
| 13823 ** Figure out what version of the code to use. The choices are |
| 13824 ** |
| 13825 ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The |
| 13826 ** mutexes implementation cannot be overridden |
| 13827 ** at start-time. |
| 13828 ** |
| 13829 ** SQLITE_MUTEX_NOOP For single-threaded applications. No |
| 13830 ** mutual exclusion is provided. But this |
| 13831 ** implementation can be overridden at |
| 13832 ** start-time. |
| 13833 ** |
| 13834 ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix. |
| 13835 ** |
| 13836 ** SQLITE_MUTEX_W32 For multi-threaded applications on Win32. |
| 13837 */ |
| 13838 #if !SQLITE_THREADSAFE |
| 13839 # define SQLITE_MUTEX_OMIT |
| 13840 #endif |
| 13841 #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP) |
| 13842 # if SQLITE_OS_UNIX |
| 13843 # define SQLITE_MUTEX_PTHREADS |
| 13844 # elif SQLITE_OS_WIN |
| 13845 # define SQLITE_MUTEX_W32 |
| 13846 # else |
| 13847 # define SQLITE_MUTEX_NOOP |
| 13848 # endif |
| 13849 #endif |
| 13850 |
| 13851 #ifdef SQLITE_MUTEX_OMIT |
| 13852 /* |
| 13853 ** If this is a no-op implementation, implement everything as macros. |
| 13854 */ |
| 13855 #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8) |
| 13856 #define sqlite3_mutex_free(X) |
| 13857 #define sqlite3_mutex_enter(X) |
| 13858 #define sqlite3_mutex_try(X) SQLITE_OK |
| 13859 #define sqlite3_mutex_leave(X) |
| 13860 #define sqlite3_mutex_held(X) ((void)(X),1) |
| 13861 #define sqlite3_mutex_notheld(X) ((void)(X),1) |
| 13862 #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8) |
| 13863 #define sqlite3MutexInit() SQLITE_OK |
| 13864 #define sqlite3MutexEnd() |
| 13865 #define MUTEX_LOGIC(X) |
| 13866 #else |
| 13867 #define MUTEX_LOGIC(X) X |
| 13868 #endif /* defined(SQLITE_MUTEX_OMIT) */ |
| 13869 |
| 13870 /************** End of mutex.h ***********************************************/ |
| 13871 /************** Continuing where we left off in sqliteInt.h ******************/ |
| 13872 |
| 13873 /* The SQLITE_EXTRA_DURABLE compile-time option used to set the default |
| 13874 ** synchronous setting to EXTRA. It is no longer supported. |
| 13875 */ |
| 13876 #ifdef SQLITE_EXTRA_DURABLE |
| 13877 # warning Use SQLITE_DEFAULT_SYNCHRONOUS=3 instead of SQLITE_EXTRA_DURABLE |
| 13878 # define SQLITE_DEFAULT_SYNCHRONOUS 3 |
| 13879 #endif |
| 13880 |
| 13881 /* |
| 13882 ** Default synchronous levels. |
| 13883 ** |
| 13884 ** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ |
| 13885 ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1. |
| 13886 ** |
| 13887 ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS |
| 13888 ** OFF 1 0 |
| 13889 ** NORMAL 2 1 |
| 13890 ** FULL 3 2 |
| 13891 ** EXTRA 4 3 |
| 13892 ** |
| 13893 ** The "PRAGMA synchronous" statement also uses the zero-based numbers. |
| 13894 ** In other words, the zero-based numbers are used for all external interfaces |
| 13895 ** and the one-based values are used internally. |
| 13896 */ |
| 13897 #ifndef SQLITE_DEFAULT_SYNCHRONOUS |
| 13898 # define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1) |
| 13899 #endif |
| 13900 #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS |
| 13901 # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS |
| 13902 #endif |
| 13903 |
| 13904 /* |
| 13905 ** Each database file to be accessed by the system is an instance |
| 13906 ** of the following structure. There are normally two of these structures |
| 13907 ** in the sqlite.aDb[] array. aDb[0] is the main database file and |
| 13908 ** aDb[1] is the database file used to hold temporary tables. Additional |
| 13909 ** databases may be attached. |
| 13910 */ |
| 13911 struct Db { |
| 13912 char *zDbSName; /* Name of this database. (schema name, not filename) */ |
| 13913 Btree *pBt; /* The B*Tree structure for this database file */ |
| 13914 u8 safety_level; /* How aggressive at syncing data to disk */ |
| 13915 u8 bSyncSet; /* True if "PRAGMA synchronous=N" has been run */ |
| 13916 Schema *pSchema; /* Pointer to database schema (possibly shared) */ |
| 13917 }; |
| 13918 |
| 13919 /* |
| 13920 ** An instance of the following structure stores a database schema. |
| 13921 ** |
| 13922 ** Most Schema objects are associated with a Btree. The exception is |
| 13923 ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing. |
| 13924 ** In shared cache mode, a single Schema object can be shared by multiple |
| 13925 ** Btrees that refer to the same underlying BtShared object. |
| 13926 ** |
| 13927 ** Schema objects are automatically deallocated when the last Btree that |
| 13928 ** references them is destroyed. The TEMP Schema is manually freed by |
| 13929 ** sqlite3_close(). |
| 13930 * |
| 13931 ** A thread must be holding a mutex on the corresponding Btree in order |
| 13932 ** to access Schema content. This implies that the thread must also be |
| 13933 ** holding a mutex on the sqlite3 connection pointer that owns the Btree. |
| 13934 ** For a TEMP Schema, only the connection mutex is required. |
| 13935 */ |
| 13936 struct Schema { |
| 13937 int schema_cookie; /* Database schema version number for this file */ |
| 13938 int iGeneration; /* Generation counter. Incremented with each change */ |
| 13939 Hash tblHash; /* All tables indexed by name */ |
| 13940 Hash idxHash; /* All (named) indices indexed by name */ |
| 13941 Hash trigHash; /* All triggers indexed by name */ |
| 13942 Hash fkeyHash; /* All foreign keys by referenced table name */ |
| 13943 Table *pSeqTab; /* The sqlite_sequence table used by AUTOINCREMENT */ |
| 13944 u8 file_format; /* Schema format version for this file */ |
| 13945 u8 enc; /* Text encoding used by this database */ |
| 13946 u16 schemaFlags; /* Flags associated with this schema */ |
| 13947 int cache_size; /* Number of pages to use in the cache */ |
| 13948 }; |
| 13949 |
| 13950 /* |
| 13951 ** These macros can be used to test, set, or clear bits in the |
| 13952 ** Db.pSchema->flags field. |
| 13953 */ |
| 13954 #define DbHasProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))==(P)) |
| 13955 #define DbHasAnyProperty(D,I,P) (((D)->aDb[I].pSchema->schemaFlags&(P))!=0) |
| 13956 #define DbSetProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags|=(P) |
| 13957 #define DbClearProperty(D,I,P) (D)->aDb[I].pSchema->schemaFlags&=~(P) |
| 13958 |
| 13959 /* |
| 13960 ** Allowed values for the DB.pSchema->flags field. |
| 13961 ** |
| 13962 ** The DB_SchemaLoaded flag is set after the database schema has been |
| 13963 ** read into internal hash tables. |
| 13964 ** |
| 13965 ** DB_UnresetViews means that one or more views have column names that |
| 13966 ** have been filled out. If the schema changes, these column names might |
| 13967 ** changes and so the view will need to be reset. |
| 13968 */ |
| 13969 #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */ |
| 13970 #define DB_UnresetViews 0x0002 /* Some views have defined column names */ |
| 13971 #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */ |
| 13972 |
| 13973 /* |
| 13974 ** The number of different kinds of things that can be limited |
| 13975 ** using the sqlite3_limit() interface. |
| 13976 */ |
| 13977 #define SQLITE_N_LIMIT (SQLITE_LIMIT_WORKER_THREADS+1) |
| 13978 |
| 13979 /* |
| 13980 ** Lookaside malloc is a set of fixed-size buffers that can be used |
| 13981 ** to satisfy small transient memory allocation requests for objects |
| 13982 ** associated with a particular database connection. The use of |
| 13983 ** lookaside malloc provides a significant performance enhancement |
| 13984 ** (approx 10%) by avoiding numerous malloc/free requests while parsing |
| 13985 ** SQL statements. |
| 13986 ** |
| 13987 ** The Lookaside structure holds configuration information about the |
| 13988 ** lookaside malloc subsystem. Each available memory allocation in |
| 13989 ** the lookaside subsystem is stored on a linked list of LookasideSlot |
| 13990 ** objects. |
| 13991 ** |
| 13992 ** Lookaside allocations are only allowed for objects that are associated |
| 13993 ** with a particular database connection. Hence, schema information cannot |
| 13994 ** be stored in lookaside because in shared cache mode the schema information |
| 13995 ** is shared by multiple database connections. Therefore, while parsing |
| 13996 ** schema information, the Lookaside.bEnabled flag is cleared so that |
| 13997 ** lookaside allocations are not used to construct the schema objects. |
| 13998 */ |
| 13999 struct Lookaside { |
| 14000 u32 bDisable; /* Only operate the lookaside when zero */ |
| 14001 u16 sz; /* Size of each buffer in bytes */ |
| 14002 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */ |
| 14003 int nOut; /* Number of buffers currently checked out */ |
| 14004 int mxOut; /* Highwater mark for nOut */ |
| 14005 int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ |
| 14006 LookasideSlot *pFree; /* List of available buffers */ |
| 14007 void *pStart; /* First byte of available memory space */ |
| 14008 void *pEnd; /* First byte past end of available space */ |
| 14009 }; |
| 14010 struct LookasideSlot { |
| 14011 LookasideSlot *pNext; /* Next buffer in the list of free buffers */ |
| 14012 }; |
| 14013 |
| 14014 /* |
| 14015 ** A hash table for built-in function definitions. (Application-defined |
| 14016 ** functions use a regular table table from hash.h.) |
| 14017 ** |
| 14018 ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots. |
| 14019 ** Collisions are on the FuncDef.u.pHash chain. |
| 14020 */ |
| 14021 #define SQLITE_FUNC_HASH_SZ 23 |
| 14022 struct FuncDefHash { |
| 14023 FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */ |
| 14024 }; |
| 14025 |
| 14026 #ifdef SQLITE_USER_AUTHENTICATION |
| 14027 /* |
| 14028 ** Information held in the "sqlite3" database connection object and used |
| 14029 ** to manage user authentication. |
| 14030 */ |
| 14031 typedef struct sqlite3_userauth sqlite3_userauth; |
| 14032 struct sqlite3_userauth { |
| 14033 u8 authLevel; /* Current authentication level */ |
| 14034 int nAuthPW; /* Size of the zAuthPW in bytes */ |
| 14035 char *zAuthPW; /* Password used to authenticate */ |
| 14036 char *zAuthUser; /* User name used to authenticate */ |
| 14037 }; |
| 14038 |
| 14039 /* Allowed values for sqlite3_userauth.authLevel */ |
| 14040 #define UAUTH_Unknown 0 /* Authentication not yet checked */ |
| 14041 #define UAUTH_Fail 1 /* User authentication failed */ |
| 14042 #define UAUTH_User 2 /* Authenticated as a normal user */ |
| 14043 #define UAUTH_Admin 3 /* Authenticated as an administrator */ |
| 14044 |
| 14045 /* Functions used only by user authorization logic */ |
| 14046 SQLITE_PRIVATE int sqlite3UserAuthTable(const char*); |
| 14047 SQLITE_PRIVATE int sqlite3UserAuthCheckLogin(sqlite3*,const char*,u8*); |
| 14048 SQLITE_PRIVATE void sqlite3UserAuthInit(sqlite3*); |
| 14049 SQLITE_PRIVATE void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**); |
| 14050 |
| 14051 #endif /* SQLITE_USER_AUTHENTICATION */ |
| 14052 |
| 14053 /* |
| 14054 ** typedef for the authorization callback function. |
| 14055 */ |
| 14056 #ifdef SQLITE_USER_AUTHENTICATION |
| 14057 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, |
| 14058 const char*, const char*); |
| 14059 #else |
| 14060 typedef int (*sqlite3_xauth)(void*,int,const char*,const char*,const char*, |
| 14061 const char*); |
| 14062 #endif |
| 14063 |
| 14064 #ifndef SQLITE_OMIT_DEPRECATED |
| 14065 /* This is an extra SQLITE_TRACE macro that indicates "legacy" tracing |
| 14066 ** in the style of sqlite3_trace() |
| 14067 */ |
| 14068 #define SQLITE_TRACE_LEGACY 0x80 |
| 14069 #else |
| 14070 #define SQLITE_TRACE_LEGACY 0 |
| 14071 #endif /* SQLITE_OMIT_DEPRECATED */ |
| 14072 |
| 14073 |
| 14074 /* |
| 14075 ** Each database connection is an instance of the following structure. |
| 14076 */ |
| 14077 struct sqlite3 { |
| 14078 sqlite3_vfs *pVfs; /* OS Interface */ |
| 14079 struct Vdbe *pVdbe; /* List of active virtual machines */ |
| 14080 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
| 14081 sqlite3_mutex *mutex; /* Connection mutex */ |
| 14082 Db *aDb; /* All backends */ |
| 14083 int nDb; /* Number of backends currently in use */ |
| 14084 int flags; /* Miscellaneous flags. See below */ |
| 14085 i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 14086 i64 szMmap; /* Default mmap_size setting */ |
| 14087 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 14088 int errCode; /* Most recent error code (SQLITE_*) */ |
| 14089 int errMask; /* & result codes with this before returning */ |
| 14090 int iSysErrno; /* Errno value from last system error */ |
| 14091 u16 dbOptFlags; /* Flags to enable/disable optimizations */ |
| 14092 u8 enc; /* Text encoding */ |
| 14093 u8 autoCommit; /* The auto-commit flag. */ |
| 14094 u8 temp_store; /* 1: file 2: memory 0: default */ |
| 14095 u8 mallocFailed; /* True if we have seen a malloc failure */ |
| 14096 u8 bBenignMalloc; /* Do not require OOMs if true */ |
| 14097 u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 14098 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| 14099 u8 suppressErr; /* Do not issue error messages if true */ |
| 14100 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ |
| 14101 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */ |
| 14102 u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 14103 u8 skipBtreeMutex; /* True if no shared-cache backends */ |
| 14104 int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 14105 u32 magic; /* Magic number for detect library misuse */ |
| 14106 int nChange; /* Value returned by sqlite3_changes() */ |
| 14107 int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 14108 int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| 14109 int nMaxSorterMmap; /* Maximum size of regions mapped by sorter */ |
| 14110 struct sqlite3InitInfo { /* Information used during initialization */ |
| 14111 int newTnum; /* Rootpage of table being initialized */ |
| 14112 u8 iDb; /* Which db file is being initialized */ |
| 14113 u8 busy; /* TRUE if currently initializing */ |
| 14114 u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */ |
| 14115 u8 imposterTable; /* Building an imposter table */ |
| 14116 } init; |
| 14117 int nVdbeActive; /* Number of VDBEs currently running */ |
| 14118 int nVdbeRead; /* Number of active VDBEs that read or write */ |
| 14119 int nVdbeWrite; /* Number of active VDBEs that read and write */ |
| 14120 int nVdbeExec; /* Number of nested calls to VdbeExec() */ |
| 14121 int nVDestroy; /* Number of active OP_VDestroy operations */ |
| 14122 int nExtension; /* Number of loaded extensions */ |
| 14123 void **aExtension; /* Array of shared library handles */ |
| 14124 int (*xTrace)(u32,void*,void*,void*); /* Trace function */ |
| 14125 void *pTraceArg; /* Argument to the trace function */ |
| 14126 void (*xProfile)(void*,const char*,u64); /* Profiling function */ |
| 14127 void *pProfileArg; /* Argument to profile function */ |
| 14128 void *pCommitArg; /* Argument to xCommitCallback() */ |
| 14129 int (*xCommitCallback)(void*); /* Invoked at every commit. */ |
| 14130 void *pRollbackArg; /* Argument to xRollbackCallback() */ |
| 14131 void (*xRollbackCallback)(void*); /* Invoked at every commit. */ |
| 14132 void *pUpdateArg; |
| 14133 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64); |
| 14134 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 14135 void *pPreUpdateArg; /* First argument to xPreUpdateCallback */ |
| 14136 void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */ |
| 14137 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64 |
| 14138 ); |
| 14139 PreUpdate *pPreUpdate; /* Context for active pre-update callback */ |
| 14140 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 14141 #ifndef SQLITE_OMIT_WAL |
| 14142 int (*xWalCallback)(void *, sqlite3 *, const char *, int); |
| 14143 void *pWalArg; |
| 14144 #endif |
| 14145 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*); |
| 14146 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*); |
| 14147 void *pCollNeededArg; |
| 14148 sqlite3_value *pErr; /* Most recent error message */ |
| 14149 union { |
| 14150 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */ |
| 14151 double notUsed1; /* Spacer */ |
| 14152 } u1; |
| 14153 Lookaside lookaside; /* Lookaside malloc configuration */ |
| 14154 #ifndef SQLITE_OMIT_AUTHORIZATION |
| 14155 sqlite3_xauth xAuth; /* Access authorization function */ |
| 14156 void *pAuthArg; /* 1st argument to the access auth function */ |
| 14157 #endif |
| 14158 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 14159 int (*xProgress)(void *); /* The progress callback */ |
| 14160 void *pProgressArg; /* Argument to the progress callback */ |
| 14161 unsigned nProgressOps; /* Number of opcodes for progress callback */ |
| 14162 #endif |
| 14163 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 14164 int nVTrans; /* Allocated size of aVTrans */ |
| 14165 Hash aModule; /* populated by sqlite3_create_module() */ |
| 14166 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */ |
| 14167 VTable **aVTrans; /* Virtual tables with open transactions */ |
| 14168 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */ |
| 14169 #endif |
| 14170 Hash aFunc; /* Hash table of connection functions */ |
| 14171 Hash aCollSeq; /* All collating sequences */ |
| 14172 BusyHandler busyHandler; /* Busy callback */ |
| 14173 Db aDbStatic[2]; /* Static space for the 2 default backends */ |
| 14174 Savepoint *pSavepoint; /* List of active savepoints */ |
| 14175 int busyTimeout; /* Busy handler timeout, in msec */ |
| 14176 int nSavepoint; /* Number of non-transaction savepoints */ |
| 14177 int nStatement; /* Number of nested statement-transactions */ |
| 14178 i64 nDeferredCons; /* Net deferred constraints this transaction. */ |
| 14179 i64 nDeferredImmCons; /* Net deferred immediate constraints */ |
| 14180 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */ |
| 14181 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 14182 /* The following variables are all protected by the STATIC_MASTER |
| 14183 ** mutex, not by sqlite3.mutex. They are used by code in notify.c. |
| 14184 ** |
| 14185 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to |
| 14186 ** unlock so that it can proceed. |
| 14187 ** |
| 14188 ** When X.pBlockingConnection==Y, that means that something that X tried |
| 14189 ** tried to do recently failed with an SQLITE_LOCKED error due to locks |
| 14190 ** held by Y. |
| 14191 */ |
| 14192 sqlite3 *pBlockingConnection; /* Connection that caused SQLITE_LOCKED */ |
| 14193 sqlite3 *pUnlockConnection; /* Connection to watch for unlock */ |
| 14194 void *pUnlockArg; /* Argument to xUnlockNotify */ |
| 14195 void (*xUnlockNotify)(void **, int); /* Unlock notify callback */ |
| 14196 sqlite3 *pNextBlocked; /* Next in list of all blocked connections */ |
| 14197 #endif |
| 14198 #ifdef SQLITE_USER_AUTHENTICATION |
| 14199 sqlite3_userauth auth; /* User authentication information */ |
| 14200 #endif |
| 14201 }; |
| 14202 |
| 14203 /* |
| 14204 ** A macro to discover the encoding of a database. |
| 14205 */ |
| 14206 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc) |
| 14207 #define ENC(db) ((db)->enc) |
| 14208 |
| 14209 /* |
| 14210 ** Possible values for the sqlite3.flags. |
| 14211 ** |
| 14212 ** Value constraints (enforced via assert()): |
| 14213 ** SQLITE_FullFSync == PAGER_FULLFSYNC |
| 14214 ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC |
| 14215 ** SQLITE_CacheSpill == PAGER_CACHE_SPILL |
| 14216 */ |
| 14217 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ |
| 14218 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */ |
| 14219 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ |
| 14220 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */ |
| 14221 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */ |
| 14222 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */ |
| 14223 #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ |
| 14224 #define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ |
| 14225 /* DELETE, or UPDATE and return */ |
| 14226 /* the count using a callback. */ |
| 14227 #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ |
| 14228 /* result set is empty */ |
| 14229 #define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */ |
| 14230 #define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */ |
| 14231 #define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */ |
| 14232 #define SQLITE_VdbeAddopTrace 0x00001000 /* Trace sqlite3VdbeAddOp() calls */ |
| 14233 #define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */ |
| 14234 #define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */ |
| 14235 #define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */ |
| 14236 #define SQLITE_RecoveryMode 0x00010000 /* Ignore schema errors */ |
| 14237 #define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */ |
| 14238 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */ |
| 14239 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */ |
| 14240 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */ |
| 14241 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */ |
| 14242 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ |
| 14243 #define SQLITE_LoadExtFunc 0x00800000 /* Enable load_extension() SQL func */ |
| 14244 #define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */ |
| 14245 #define SQLITE_DeferFKs 0x02000000 /* Defer all FK constraints */ |
| 14246 #define SQLITE_QueryOnly 0x04000000 /* Disable database changes */ |
| 14247 #define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */ |
| 14248 #define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */ |
| 14249 #define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */ |
| 14250 #define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */ |
| 14251 #define SQLITE_NoCkptOnClose 0x80000000 /* No checkpoint on close()/DETACH */ |
| 14252 |
| 14253 |
| 14254 /* |
| 14255 ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 14256 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| 14257 ** selectively disable various optimizations. |
| 14258 */ |
| 14259 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ |
| 14260 #define SQLITE_ColumnCache 0x0002 /* Column cache */ |
| 14261 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ |
| 14262 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 14263 /* not used 0x0010 // Was: SQLITE_IdxRealAsInt */ |
| 14264 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 14265 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 14266 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 14267 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 14268 #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| 14269 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ |
| 14270 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */ |
| 14271 #define SQLITE_CursorHints 0x2000 /* Add OP_CursorHint opcodes */ |
| 14272 #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 14273 |
| 14274 /* |
| 14275 ** Macros for testing whether or not optimizations are enabled or disabled. |
| 14276 */ |
| 14277 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0) |
| 14278 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0) |
| 14279 |
| 14280 /* |
| 14281 ** Return true if it OK to factor constant expressions into the initialization |
| 14282 ** code. The argument is a Parse object for the code generator. |
| 14283 */ |
| 14284 #define ConstFactorOk(P) ((P)->okConstFactor) |
| 14285 |
| 14286 /* |
| 14287 ** Possible values for the sqlite.magic field. |
| 14288 ** The numbers are obtained at random and have no special meaning, other |
| 14289 ** than being distinct from one another. |
| 14290 */ |
| 14291 #define SQLITE_MAGIC_OPEN 0xa029a697 /* Database is open */ |
| 14292 #define SQLITE_MAGIC_CLOSED 0x9f3c2d33 /* Database is closed */ |
| 14293 #define SQLITE_MAGIC_SICK 0x4b771290 /* Error and awaiting close */ |
| 14294 #define SQLITE_MAGIC_BUSY 0xf03b7906 /* Database currently in use */ |
| 14295 #define SQLITE_MAGIC_ERROR 0xb5357930 /* An SQLITE_MISUSE error occurred */ |
| 14296 #define SQLITE_MAGIC_ZOMBIE 0x64cffc7f /* Close with last statement close */ |
| 14297 |
| 14298 /* |
| 14299 ** Each SQL function is defined by an instance of the following |
| 14300 ** structure. For global built-in functions (ex: substr(), max(), count()) |
| 14301 ** a pointer to this structure is held in the sqlite3BuiltinFunctions object. |
| 14302 ** For per-connection application-defined functions, a pointer to this |
| 14303 ** structure is held in the db->aHash hash table. |
| 14304 ** |
| 14305 ** The u.pHash field is used by the global built-ins. The u.pDestructor |
| 14306 ** field is used by per-connection app-def functions. |
| 14307 */ |
| 14308 struct FuncDef { |
| 14309 i8 nArg; /* Number of arguments. -1 means unlimited */ |
| 14310 u16 funcFlags; /* Some combination of SQLITE_FUNC_* */ |
| 14311 void *pUserData; /* User data parameter */ |
| 14312 FuncDef *pNext; /* Next function with same name */ |
| 14313 void (*xSFunc)(sqlite3_context*,int,sqlite3_value**); /* func or agg-step */ |
| 14314 void (*xFinalize)(sqlite3_context*); /* Agg finalizer */ |
| 14315 const char *zName; /* SQL name of the function. */ |
| 14316 union { |
| 14317 FuncDef *pHash; /* Next with a different name but the same hash */ |
| 14318 FuncDestructor *pDestructor; /* Reference counted destructor function */ |
| 14319 } u; |
| 14320 }; |
| 14321 |
| 14322 /* |
| 14323 ** This structure encapsulates a user-function destructor callback (as |
| 14324 ** configured using create_function_v2()) and a reference counter. When |
| 14325 ** create_function_v2() is called to create a function with a destructor, |
| 14326 ** a single object of this type is allocated. FuncDestructor.nRef is set to |
| 14327 ** the number of FuncDef objects created (either 1 or 3, depending on whether |
| 14328 ** or not the specified encoding is SQLITE_ANY). The FuncDef.pDestructor |
| 14329 ** member of each of the new FuncDef objects is set to point to the allocated |
| 14330 ** FuncDestructor. |
| 14331 ** |
| 14332 ** Thereafter, when one of the FuncDef objects is deleted, the reference |
| 14333 ** count on this object is decremented. When it reaches 0, the destructor |
| 14334 ** is invoked and the FuncDestructor structure freed. |
| 14335 */ |
| 14336 struct FuncDestructor { |
| 14337 int nRef; |
| 14338 void (*xDestroy)(void *); |
| 14339 void *pUserData; |
| 14340 }; |
| 14341 |
| 14342 /* |
| 14343 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF |
| 14344 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And |
| 14345 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There |
| 14346 ** are assert() statements in the code to verify this. |
| 14347 ** |
| 14348 ** Value constraints (enforced via assert()): |
| 14349 ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg |
| 14350 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG |
| 14351 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG |
| 14352 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API |
| 14353 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 14354 */ |
| 14355 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 14356 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| 14357 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ |
| 14358 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ |
| 14359 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/ |
| 14360 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */ |
| 14361 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */ |
| 14362 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */ |
| 14363 #define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */ |
| 14364 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ |
| 14365 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ |
| 14366 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ |
| 14367 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a |
| 14368 ** single query - might change over time */ |
| 14369 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */ |
| 14370 |
| 14371 /* |
| 14372 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 14373 ** used to create the initializers for the FuncDef structures. |
| 14374 ** |
| 14375 ** FUNCTION(zName, nArg, iArg, bNC, xFunc) |
| 14376 ** Used to create a scalar function definition of a function zName |
| 14377 ** implemented by C function xFunc that accepts nArg arguments. The |
| 14378 ** value passed as iArg is cast to a (void*) and made available |
| 14379 ** as the user-data (sqlite3_user_data()) for the function. If |
| 14380 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set. |
| 14381 ** |
| 14382 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc) |
| 14383 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag. |
| 14384 ** |
| 14385 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc) |
| 14386 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and |
| 14387 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions |
| 14388 ** and functions like sqlite_version() that can change, but not during |
| 14389 ** a single query. |
| 14390 ** |
| 14391 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) |
| 14392 ** Used to create an aggregate function definition implemented by |
| 14393 ** the C functions xStep and xFinal. The first four parameters |
| 14394 ** are interpreted in the same way as the first 4 parameters to |
| 14395 ** FUNCTION(). |
| 14396 ** |
| 14397 ** LIKEFUNC(zName, nArg, pArg, flags) |
| 14398 ** Used to create a scalar function definition of a function zName |
| 14399 ** that accepts nArg arguments and is implemented by a call to C |
| 14400 ** function likeFunc. Argument pArg is cast to a (void *) and made |
| 14401 ** available as the function user-data (sqlite3_user_data()). The |
| 14402 ** FuncDef.flags variable is set to the value passed as the flags |
| 14403 ** parameter. |
| 14404 */ |
| 14405 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 14406 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 14407 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} } |
| 14408 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 14409 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 14410 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} } |
| 14411 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 14412 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 14413 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} } |
| 14414 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ |
| 14415 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ |
| 14416 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, #zName, {0} } |
| 14417 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ |
| 14418 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 14419 pArg, 0, xFunc, 0, #zName, } |
| 14420 #define LIKEFUNC(zName, nArg, arg, flags) \ |
| 14421 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 14422 (void *)arg, 0, likeFunc, 0, #zName, {0} } |
| 14423 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ |
| 14424 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ |
| 14425 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}} |
| 14426 #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \ |
| 14427 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ |
| 14428 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,#zName, {0}} |
| 14429 |
| 14430 /* |
| 14431 ** All current savepoints are stored in a linked list starting at |
| 14432 ** sqlite3.pSavepoint. The first element in the list is the most recently |
| 14433 ** opened savepoint. Savepoints are added to the list by the vdbe |
| 14434 ** OP_Savepoint instruction. |
| 14435 */ |
| 14436 struct Savepoint { |
| 14437 char *zName; /* Savepoint name (nul-terminated) */ |
| 14438 i64 nDeferredCons; /* Number of deferred fk violations */ |
| 14439 i64 nDeferredImmCons; /* Number of deferred imm fk. */ |
| 14440 Savepoint *pNext; /* Parent savepoint (if any) */ |
| 14441 }; |
| 14442 |
| 14443 /* |
| 14444 ** The following are used as the second parameter to sqlite3Savepoint(), |
| 14445 ** and as the P1 argument to the OP_Savepoint instruction. |
| 14446 */ |
| 14447 #define SAVEPOINT_BEGIN 0 |
| 14448 #define SAVEPOINT_RELEASE 1 |
| 14449 #define SAVEPOINT_ROLLBACK 2 |
| 14450 |
| 14451 |
| 14452 /* |
| 14453 ** Each SQLite module (virtual table definition) is defined by an |
| 14454 ** instance of the following structure, stored in the sqlite3.aModule |
| 14455 ** hash table. |
| 14456 */ |
| 14457 struct Module { |
| 14458 const sqlite3_module *pModule; /* Callback pointers */ |
| 14459 const char *zName; /* Name passed to create_module() */ |
| 14460 void *pAux; /* pAux passed to create_module() */ |
| 14461 void (*xDestroy)(void *); /* Module destructor function */ |
| 14462 Table *pEpoTab; /* Eponymous table for this module */ |
| 14463 }; |
| 14464 |
| 14465 /* |
| 14466 ** information about each column of an SQL table is held in an instance |
| 14467 ** of this structure. |
| 14468 */ |
| 14469 struct Column { |
| 14470 char *zName; /* Name of this column, \000, then the type */ |
| 14471 Expr *pDflt; /* Default value of this column */ |
| 14472 char *zColl; /* Collating sequence. If NULL, use the default */ |
| 14473 u8 notNull; /* An OE_ code for handling a NOT NULL constraint */ |
| 14474 char affinity; /* One of the SQLITE_AFF_... values */ |
| 14475 u8 szEst; /* Estimated size of value in this column. sizeof(INT)==1 */ |
| 14476 u8 colFlags; /* Boolean properties. See COLFLAG_ defines below */ |
| 14477 }; |
| 14478 |
| 14479 /* Allowed values for Column.colFlags: |
| 14480 */ |
| 14481 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */ |
| 14482 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */ |
| 14483 #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */ |
| 14484 |
| 14485 /* |
| 14486 ** A "Collating Sequence" is defined by an instance of the following |
| 14487 ** structure. Conceptually, a collating sequence consists of a name and |
| 14488 ** a comparison routine that defines the order of that sequence. |
| 14489 ** |
| 14490 ** If CollSeq.xCmp is NULL, it means that the |
| 14491 ** collating sequence is undefined. Indices built on an undefined |
| 14492 ** collating sequence may not be read or written. |
| 14493 */ |
| 14494 struct CollSeq { |
| 14495 char *zName; /* Name of the collating sequence, UTF-8 encoded */ |
| 14496 u8 enc; /* Text encoding handled by xCmp() */ |
| 14497 void *pUser; /* First argument to xCmp() */ |
| 14498 int (*xCmp)(void*,int, const void*, int, const void*); |
| 14499 void (*xDel)(void*); /* Destructor for pUser */ |
| 14500 }; |
| 14501 |
| 14502 /* |
| 14503 ** A sort order can be either ASC or DESC. |
| 14504 */ |
| 14505 #define SQLITE_SO_ASC 0 /* Sort in ascending order */ |
| 14506 #define SQLITE_SO_DESC 1 /* Sort in ascending order */ |
| 14507 #define SQLITE_SO_UNDEFINED -1 /* No sort order specified */ |
| 14508 |
| 14509 /* |
| 14510 ** Column affinity types. |
| 14511 ** |
| 14512 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and |
| 14513 ** 't' for SQLITE_AFF_TEXT. But we can save a little space and improve |
| 14514 ** the speed a little by numbering the values consecutively. |
| 14515 ** |
| 14516 ** But rather than start with 0 or 1, we begin with 'A'. That way, |
| 14517 ** when multiple affinity types are concatenated into a string and |
| 14518 ** used as the P4 operand, they will be more readable. |
| 14519 ** |
| 14520 ** Note also that the numeric types are grouped together so that testing |
| 14521 ** for a numeric type is a single comparison. And the BLOB type is first. |
| 14522 */ |
| 14523 #define SQLITE_AFF_BLOB 'A' |
| 14524 #define SQLITE_AFF_TEXT 'B' |
| 14525 #define SQLITE_AFF_NUMERIC 'C' |
| 14526 #define SQLITE_AFF_INTEGER 'D' |
| 14527 #define SQLITE_AFF_REAL 'E' |
| 14528 |
| 14529 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) |
| 14530 |
| 14531 /* |
| 14532 ** The SQLITE_AFF_MASK values masks off the significant bits of an |
| 14533 ** affinity value. |
| 14534 */ |
| 14535 #define SQLITE_AFF_MASK 0x47 |
| 14536 |
| 14537 /* |
| 14538 ** Additional bit values that can be ORed with an affinity without |
| 14539 ** changing the affinity. |
| 14540 ** |
| 14541 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL. |
| 14542 ** It causes an assert() to fire if either operand to a comparison |
| 14543 ** operator is NULL. It is added to certain comparison operators to |
| 14544 ** prove that the operands are always NOT NULL. |
| 14545 */ |
| 14546 #define SQLITE_KEEPNULL 0x08 /* Used by vector == or <> */ |
| 14547 #define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */ |
| 14548 #define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */ |
| 14549 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */ |
| 14550 #define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */ |
| 14551 |
| 14552 /* |
| 14553 ** An object of this type is created for each virtual table present in |
| 14554 ** the database schema. |
| 14555 ** |
| 14556 ** If the database schema is shared, then there is one instance of this |
| 14557 ** structure for each database connection (sqlite3*) that uses the shared |
| 14558 ** schema. This is because each database connection requires its own unique |
| 14559 ** instance of the sqlite3_vtab* handle used to access the virtual table |
| 14560 ** implementation. sqlite3_vtab* handles can not be shared between |
| 14561 ** database connections, even when the rest of the in-memory database |
| 14562 ** schema is shared, as the implementation often stores the database |
| 14563 ** connection handle passed to it via the xConnect() or xCreate() method |
| 14564 ** during initialization internally. This database connection handle may |
| 14565 ** then be used by the virtual table implementation to access real tables |
| 14566 ** within the database. So that they appear as part of the callers |
| 14567 ** transaction, these accesses need to be made via the same database |
| 14568 ** connection as that used to execute SQL operations on the virtual table. |
| 14569 ** |
| 14570 ** All VTable objects that correspond to a single table in a shared |
| 14571 ** database schema are initially stored in a linked-list pointed to by |
| 14572 ** the Table.pVTable member variable of the corresponding Table object. |
| 14573 ** When an sqlite3_prepare() operation is required to access the virtual |
| 14574 ** table, it searches the list for the VTable that corresponds to the |
| 14575 ** database connection doing the preparing so as to use the correct |
| 14576 ** sqlite3_vtab* handle in the compiled query. |
| 14577 ** |
| 14578 ** When an in-memory Table object is deleted (for example when the |
| 14579 ** schema is being reloaded for some reason), the VTable objects are not |
| 14580 ** deleted and the sqlite3_vtab* handles are not xDisconnect()ed |
| 14581 ** immediately. Instead, they are moved from the Table.pVTable list to |
| 14582 ** another linked list headed by the sqlite3.pDisconnect member of the |
| 14583 ** corresponding sqlite3 structure. They are then deleted/xDisconnected |
| 14584 ** next time a statement is prepared using said sqlite3*. This is done |
| 14585 ** to avoid deadlock issues involving multiple sqlite3.mutex mutexes. |
| 14586 ** Refer to comments above function sqlite3VtabUnlockList() for an |
| 14587 ** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect |
| 14588 ** list without holding the corresponding sqlite3.mutex mutex. |
| 14589 ** |
| 14590 ** The memory for objects of this type is always allocated by |
| 14591 ** sqlite3DbMalloc(), using the connection handle stored in VTable.db as |
| 14592 ** the first argument. |
| 14593 */ |
| 14594 struct VTable { |
| 14595 sqlite3 *db; /* Database connection associated with this table */ |
| 14596 Module *pMod; /* Pointer to module implementation */ |
| 14597 sqlite3_vtab *pVtab; /* Pointer to vtab instance */ |
| 14598 int nRef; /* Number of pointers to this structure */ |
| 14599 u8 bConstraint; /* True if constraints are supported */ |
| 14600 int iSavepoint; /* Depth of the SAVEPOINT stack */ |
| 14601 VTable *pNext; /* Next in linked list (see above) */ |
| 14602 }; |
| 14603 |
| 14604 /* |
| 14605 ** The schema for each SQL table and view is represented in memory |
| 14606 ** by an instance of the following structure. |
| 14607 */ |
| 14608 struct Table { |
| 14609 char *zName; /* Name of the table or view */ |
| 14610 Column *aCol; /* Information about each column */ |
| 14611 Index *pIndex; /* List of SQL indexes on this table. */ |
| 14612 Select *pSelect; /* NULL for tables. Points to definition if a view. */ |
| 14613 FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 14614 char *zColAff; /* String defining the affinity of each column */ |
| 14615 ExprList *pCheck; /* All CHECK constraints */ |
| 14616 /* ... also used as column name list in a VIEW */ |
| 14617 int tnum; /* Root BTree page for this table */ |
| 14618 u32 nTabRef; /* Number of pointers to this Table */ |
| 14619 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ |
| 14620 i16 nCol; /* Number of columns in this table */ |
| 14621 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 14622 LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 14623 #ifdef SQLITE_ENABLE_COSTMULT |
| 14624 LogEst costMult; /* Cost multiplier for using this table */ |
| 14625 #endif |
| 14626 u8 tabFlags; /* Mask of TF_* values */ |
| 14627 u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 14628 #ifndef SQLITE_OMIT_ALTERTABLE |
| 14629 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 14630 #endif |
| 14631 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 14632 int nModuleArg; /* Number of arguments to the module */ |
| 14633 char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */ |
| 14634 VTable *pVTable; /* List of VTable objects. */ |
| 14635 #endif |
| 14636 Trigger *pTrigger; /* List of triggers stored in pSchema */ |
| 14637 Schema *pSchema; /* Schema that contains this table */ |
| 14638 Table *pNextZombie; /* Next on the Parse.pZombieTab list */ |
| 14639 }; |
| 14640 |
| 14641 /* |
| 14642 ** Allowed values for Table.tabFlags. |
| 14643 ** |
| 14644 ** TF_OOOHidden applies to tables or view that have hidden columns that are |
| 14645 ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING |
| 14646 ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, |
| 14647 ** the TF_OOOHidden attribute would apply in this case. Such tables require |
| 14648 ** special handling during INSERT processing. |
| 14649 */ |
| 14650 #define TF_Readonly 0x01 /* Read-only system table */ |
| 14651 #define TF_Ephemeral 0x02 /* An ephemeral table */ |
| 14652 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */ |
| 14653 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ |
| 14654 #define TF_Virtual 0x10 /* Is a virtual table */ |
| 14655 #define TF_WithoutRowid 0x20 /* No rowid. PRIMARY KEY is the key */ |
| 14656 #define TF_NoVisibleRowid 0x40 /* No user-visible "rowid" column */ |
| 14657 #define TF_OOOHidden 0x80 /* Out-of-Order hidden columns */ |
| 14658 |
| 14659 |
| 14660 /* |
| 14661 ** Test to see whether or not a table is a virtual table. This is |
| 14662 ** done as a macro so that it will be optimized out when virtual |
| 14663 ** table support is omitted from the build. |
| 14664 */ |
| 14665 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 14666 # define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0) |
| 14667 #else |
| 14668 # define IsVirtual(X) 0 |
| 14669 #endif |
| 14670 |
| 14671 /* |
| 14672 ** Macros to determine if a column is hidden. IsOrdinaryHiddenColumn() |
| 14673 ** only works for non-virtual tables (ordinary tables and views) and is |
| 14674 ** always false unless SQLITE_ENABLE_HIDDEN_COLUMNS is defined. The |
| 14675 ** IsHiddenColumn() macro is general purpose. |
| 14676 */ |
| 14677 #if defined(SQLITE_ENABLE_HIDDEN_COLUMNS) |
| 14678 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) |
| 14679 # define IsOrdinaryHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) |
| 14680 #elif !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 14681 # define IsHiddenColumn(X) (((X)->colFlags & COLFLAG_HIDDEN)!=0) |
| 14682 # define IsOrdinaryHiddenColumn(X) 0 |
| 14683 #else |
| 14684 # define IsHiddenColumn(X) 0 |
| 14685 # define IsOrdinaryHiddenColumn(X) 0 |
| 14686 #endif |
| 14687 |
| 14688 |
| 14689 /* Does the table have a rowid */ |
| 14690 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0) |
| 14691 #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0) |
| 14692 |
| 14693 /* |
| 14694 ** Each foreign key constraint is an instance of the following structure. |
| 14695 ** |
| 14696 ** A foreign key is associated with two tables. The "from" table is |
| 14697 ** the table that contains the REFERENCES clause that creates the foreign |
| 14698 ** key. The "to" table is the table that is named in the REFERENCES clause. |
| 14699 ** Consider this example: |
| 14700 ** |
| 14701 ** CREATE TABLE ex1( |
| 14702 ** a INTEGER PRIMARY KEY, |
| 14703 ** b INTEGER CONSTRAINT fk1 REFERENCES ex2(x) |
| 14704 ** ); |
| 14705 ** |
| 14706 ** For foreign key "fk1", the from-table is "ex1" and the to-table is "ex2". |
| 14707 ** Equivalent names: |
| 14708 ** |
| 14709 ** from-table == child-table |
| 14710 ** to-table == parent-table |
| 14711 ** |
| 14712 ** Each REFERENCES clause generates an instance of the following structure |
| 14713 ** which is attached to the from-table. The to-table need not exist when |
| 14714 ** the from-table is created. The existence of the to-table is not checked. |
| 14715 ** |
| 14716 ** The list of all parents for child Table X is held at X.pFKey. |
| 14717 ** |
| 14718 ** A list of all children for a table named Z (which might not even exist) |
| 14719 ** is held in Schema.fkeyHash with a hash key of Z. |
| 14720 */ |
| 14721 struct FKey { |
| 14722 Table *pFrom; /* Table containing the REFERENCES clause (aka: Child) */ |
| 14723 FKey *pNextFrom; /* Next FKey with the same in pFrom. Next parent of pFrom */ |
| 14724 char *zTo; /* Name of table that the key points to (aka: Parent) */ |
| 14725 FKey *pNextTo; /* Next with the same zTo. Next child of zTo. */ |
| 14726 FKey *pPrevTo; /* Previous with the same zTo */ |
| 14727 int nCol; /* Number of columns in this key */ |
| 14728 /* EV: R-30323-21917 */ |
| 14729 u8 isDeferred; /* True if constraint checking is deferred till COMMIT */ |
| 14730 u8 aAction[2]; /* ON DELETE and ON UPDATE actions, respectively */ |
| 14731 Trigger *apTrigger[2];/* Triggers for aAction[] actions */ |
| 14732 struct sColMap { /* Mapping of columns in pFrom to columns in zTo */ |
| 14733 int iFrom; /* Index of column in pFrom */ |
| 14734 char *zCol; /* Name of column in zTo. If NULL use PRIMARY KEY */ |
| 14735 } aCol[1]; /* One entry for each of nCol columns */ |
| 14736 }; |
| 14737 |
| 14738 /* |
| 14739 ** SQLite supports many different ways to resolve a constraint |
| 14740 ** error. ROLLBACK processing means that a constraint violation |
| 14741 ** causes the operation in process to fail and for the current transaction |
| 14742 ** to be rolled back. ABORT processing means the operation in process |
| 14743 ** fails and any prior changes from that one operation are backed out, |
| 14744 ** but the transaction is not rolled back. FAIL processing means that |
| 14745 ** the operation in progress stops and returns an error code. But prior |
| 14746 ** changes due to the same operation are not backed out and no rollback |
| 14747 ** occurs. IGNORE means that the particular row that caused the constraint |
| 14748 ** error is not inserted or updated. Processing continues and no error |
| 14749 ** is returned. REPLACE means that preexisting database rows that caused |
| 14750 ** a UNIQUE constraint violation are removed so that the new insert or |
| 14751 ** update can proceed. Processing continues and no error is reported. |
| 14752 ** |
| 14753 ** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys. |
| 14754 ** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the |
| 14755 ** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign |
| 14756 ** key is set to NULL. CASCADE means that a DELETE or UPDATE of the |
| 14757 ** referenced table row is propagated into the row that holds the |
| 14758 ** foreign key. |
| 14759 ** |
| 14760 ** The following symbolic values are used to record which type |
| 14761 ** of action to take. |
| 14762 */ |
| 14763 #define OE_None 0 /* There is no constraint to check */ |
| 14764 #define OE_Rollback 1 /* Fail the operation and rollback the transaction */ |
| 14765 #define OE_Abort 2 /* Back out changes but do no rollback transaction */ |
| 14766 #define OE_Fail 3 /* Stop the operation but leave all prior changes */ |
| 14767 #define OE_Ignore 4 /* Ignore the error. Do not do the INSERT or UPDATE */ |
| 14768 #define OE_Replace 5 /* Delete existing record, then do INSERT or UPDATE */ |
| 14769 |
| 14770 #define OE_Restrict 6 /* OE_Abort for IMMEDIATE, OE_Rollback for DEFERRED */ |
| 14771 #define OE_SetNull 7 /* Set the foreign key value to NULL */ |
| 14772 #define OE_SetDflt 8 /* Set the foreign key value to its default */ |
| 14773 #define OE_Cascade 9 /* Cascade the changes */ |
| 14774 |
| 14775 #define OE_Default 10 /* Do whatever the default action is */ |
| 14776 |
| 14777 |
| 14778 /* |
| 14779 ** An instance of the following structure is passed as the first |
| 14780 ** argument to sqlite3VdbeKeyCompare and is used to control the |
| 14781 ** comparison of the two index keys. |
| 14782 ** |
| 14783 ** Note that aSortOrder[] and aColl[] have nField+1 slots. There |
| 14784 ** are nField slots for the columns of an index then one extra slot |
| 14785 ** for the rowid at the end. |
| 14786 */ |
| 14787 struct KeyInfo { |
| 14788 u32 nRef; /* Number of references to this KeyInfo object */ |
| 14789 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */ |
| 14790 u16 nField; /* Number of key columns in the index */ |
| 14791 u16 nXField; /* Number of columns beyond the key columns */ |
| 14792 sqlite3 *db; /* The database connection */ |
| 14793 u8 *aSortOrder; /* Sort order for each column. */ |
| 14794 CollSeq *aColl[1]; /* Collating sequence for each term of the key */ |
| 14795 }; |
| 14796 |
| 14797 /* |
| 14798 ** This object holds a record which has been parsed out into individual |
| 14799 ** fields, for the purposes of doing a comparison. |
| 14800 ** |
| 14801 ** A record is an object that contains one or more fields of data. |
| 14802 ** Records are used to store the content of a table row and to store |
| 14803 ** the key of an index. A blob encoding of a record is created by |
| 14804 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the |
| 14805 ** OP_Column opcode. |
| 14806 ** |
| 14807 ** An instance of this object serves as a "key" for doing a search on |
| 14808 ** an index b+tree. The goal of the search is to find the entry that |
| 14809 ** is closed to the key described by this object. This object might hold |
| 14810 ** just a prefix of the key. The number of fields is given by |
| 14811 ** pKeyInfo->nField. |
| 14812 ** |
| 14813 ** The r1 and r2 fields are the values to return if this key is less than |
| 14814 ** or greater than a key in the btree, respectively. These are normally |
| 14815 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree |
| 14816 ** is in DESC order. |
| 14817 ** |
| 14818 ** The key comparison functions actually return default_rc when they find |
| 14819 ** an equals comparison. default_rc can be -1, 0, or +1. If there are |
| 14820 ** multiple entries in the b-tree with the same key (when only looking |
| 14821 ** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to |
| 14822 ** cause the search to find the last match, or +1 to cause the search to |
| 14823 ** find the first match. |
| 14824 ** |
| 14825 ** The key comparison functions will set eqSeen to true if they ever |
| 14826 ** get and equal results when comparing this structure to a b-tree record. |
| 14827 ** When default_rc!=0, the search might end up on the record immediately |
| 14828 ** before the first match or immediately after the last match. The |
| 14829 ** eqSeen field will indicate whether or not an exact match exists in the |
| 14830 ** b-tree. |
| 14831 */ |
| 14832 struct UnpackedRecord { |
| 14833 KeyInfo *pKeyInfo; /* Collation and sort-order information */ |
| 14834 Mem *aMem; /* Values */ |
| 14835 u16 nField; /* Number of entries in apMem[] */ |
| 14836 i8 default_rc; /* Comparison result if keys are equal */ |
| 14837 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ |
| 14838 i8 r1; /* Value to return if (lhs > rhs) */ |
| 14839 i8 r2; /* Value to return if (rhs < lhs) */ |
| 14840 u8 eqSeen; /* True if an equality comparison has been seen */ |
| 14841 }; |
| 14842 |
| 14843 |
| 14844 /* |
| 14845 ** Each SQL index is represented in memory by an |
| 14846 ** instance of the following structure. |
| 14847 ** |
| 14848 ** The columns of the table that are to be indexed are described |
| 14849 ** by the aiColumn[] field of this structure. For example, suppose |
| 14850 ** we have the following table and index: |
| 14851 ** |
| 14852 ** CREATE TABLE Ex1(c1 int, c2 int, c3 text); |
| 14853 ** CREATE INDEX Ex2 ON Ex1(c3,c1); |
| 14854 ** |
| 14855 ** In the Table structure describing Ex1, nCol==3 because there are |
| 14856 ** three columns in the table. In the Index structure describing |
| 14857 ** Ex2, nColumn==2 since 2 of the 3 columns of Ex1 are indexed. |
| 14858 ** The value of aiColumn is {2, 0}. aiColumn[0]==2 because the |
| 14859 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[]. |
| 14860 ** The second column to be indexed (c1) has an index of 0 in |
| 14861 ** Ex1.aCol[], hence Ex2.aiColumn[1]==0. |
| 14862 ** |
| 14863 ** The Index.onError field determines whether or not the indexed columns |
| 14864 ** must be unique and what to do if they are not. When Index.onError=OE_None, |
| 14865 ** it means this is not a unique index. Otherwise it is a unique index |
| 14866 ** and the value of Index.onError indicate the which conflict resolution |
| 14867 ** algorithm to employ whenever an attempt is made to insert a non-unique |
| 14868 ** element. |
| 14869 ** |
| 14870 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to |
| 14871 ** generate VDBE code (as opposed to parsing one read from an sqlite_master |
| 14872 ** table as part of parsing an existing database schema), transient instances |
| 14873 ** of this structure may be created. In this case the Index.tnum variable is |
| 14874 ** used to store the address of a VDBE instruction, not a database page |
| 14875 ** number (it cannot - the database page is not allocated until the VDBE |
| 14876 ** program is executed). See convertToWithoutRowidTable() for details. |
| 14877 */ |
| 14878 struct Index { |
| 14879 char *zName; /* Name of this index */ |
| 14880 i16 *aiColumn; /* Which columns are used by this index. 1st is 0 */ |
| 14881 LogEst *aiRowLogEst; /* From ANALYZE: Est. rows selected by each column */ |
| 14882 Table *pTable; /* The SQL table being indexed */ |
| 14883 char *zColAff; /* String defining the affinity of each column */ |
| 14884 Index *pNext; /* The next index associated with the same table */ |
| 14885 Schema *pSchema; /* Schema containing this index */ |
| 14886 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */ |
| 14887 const char **azColl; /* Array of collation sequence names for index */ |
| 14888 Expr *pPartIdxWhere; /* WHERE clause for partial indices */ |
| 14889 ExprList *aColExpr; /* Column expressions */ |
| 14890 int tnum; /* DB Page containing root of this index */ |
| 14891 LogEst szIdxRow; /* Estimated average row size in bytes */ |
| 14892 u16 nKeyCol; /* Number of columns forming the key */ |
| 14893 u16 nColumn; /* Number of columns stored in the index */ |
| 14894 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
| 14895 unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */ |
| 14896 unsigned bUnordered:1; /* Use this index for == or IN queries only */ |
| 14897 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ |
| 14898 unsigned isResized:1; /* True if resizeIndexObject() has been called */ |
| 14899 unsigned isCovering:1; /* True if this is a covering index */ |
| 14900 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ |
| 14901 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 14902 int nSample; /* Number of elements in aSample[] */ |
| 14903 int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 14904 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 14905 IndexSample *aSample; /* Samples of the left-most key */ |
| 14906 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */ |
| 14907 tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */ |
| 14908 #endif |
| 14909 }; |
| 14910 |
| 14911 /* |
| 14912 ** Allowed values for Index.idxType |
| 14913 */ |
| 14914 #define SQLITE_IDXTYPE_APPDEF 0 /* Created using CREATE INDEX */ |
| 14915 #define SQLITE_IDXTYPE_UNIQUE 1 /* Implements a UNIQUE constraint */ |
| 14916 #define SQLITE_IDXTYPE_PRIMARYKEY 2 /* Is the PRIMARY KEY for the table */ |
| 14917 |
| 14918 /* Return true if index X is a PRIMARY KEY index */ |
| 14919 #define IsPrimaryKeyIndex(X) ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY) |
| 14920 |
| 14921 /* Return true if index X is a UNIQUE index */ |
| 14922 #define IsUniqueIndex(X) ((X)->onError!=OE_None) |
| 14923 |
| 14924 /* The Index.aiColumn[] values are normally positive integer. But |
| 14925 ** there are some negative values that have special meaning: |
| 14926 */ |
| 14927 #define XN_ROWID (-1) /* Indexed column is the rowid */ |
| 14928 #define XN_EXPR (-2) /* Indexed column is an expression */ |
| 14929 |
| 14930 /* |
| 14931 ** Each sample stored in the sqlite_stat3 table is represented in memory |
| 14932 ** using a structure of this type. See documentation at the top of the |
| 14933 ** analyze.c source file for additional information. |
| 14934 */ |
| 14935 struct IndexSample { |
| 14936 void *p; /* Pointer to sampled record */ |
| 14937 int n; /* Size of record in bytes */ |
| 14938 tRowcnt *anEq; /* Est. number of rows where the key equals this sample */ |
| 14939 tRowcnt *anLt; /* Est. number of rows where key is less than this sample */ |
| 14940 tRowcnt *anDLt; /* Est. number of distinct keys less than this sample */ |
| 14941 }; |
| 14942 |
| 14943 /* |
| 14944 ** Each token coming out of the lexer is an instance of |
| 14945 ** this structure. Tokens are also used as part of an expression. |
| 14946 ** |
| 14947 ** Note if Token.z==0 then Token.dyn and Token.n are undefined and |
| 14948 ** may contain random values. Do not make any assumptions about Token.dyn |
| 14949 ** and Token.n when Token.z==0. |
| 14950 */ |
| 14951 struct Token { |
| 14952 const char *z; /* Text of the token. Not NULL-terminated! */ |
| 14953 unsigned int n; /* Number of characters in this token */ |
| 14954 }; |
| 14955 |
| 14956 /* |
| 14957 ** An instance of this structure contains information needed to generate |
| 14958 ** code for a SELECT that contains aggregate functions. |
| 14959 ** |
| 14960 ** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a |
| 14961 ** pointer to this structure. The Expr.iColumn field is the index in |
| 14962 ** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate |
| 14963 ** code for that node. |
| 14964 ** |
| 14965 ** AggInfo.pGroupBy and AggInfo.aFunc.pExpr point to fields within the |
| 14966 ** original Select structure that describes the SELECT statement. These |
| 14967 ** fields do not need to be freed when deallocating the AggInfo structure. |
| 14968 */ |
| 14969 struct AggInfo { |
| 14970 u8 directMode; /* Direct rendering mode means take data directly |
| 14971 ** from source tables rather than from accumulators */ |
| 14972 u8 useSortingIdx; /* In direct mode, reference the sorting index rather |
| 14973 ** than the source table */ |
| 14974 int sortingIdx; /* Cursor number of the sorting index */ |
| 14975 int sortingIdxPTab; /* Cursor number of pseudo-table */ |
| 14976 int nSortingColumn; /* Number of columns in the sorting index */ |
| 14977 int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */ |
| 14978 ExprList *pGroupBy; /* The group by clause */ |
| 14979 struct AggInfo_col { /* For each column used in source tables */ |
| 14980 Table *pTab; /* Source table */ |
| 14981 int iTable; /* Cursor number of the source table */ |
| 14982 int iColumn; /* Column number within the source table */ |
| 14983 int iSorterColumn; /* Column number in the sorting index */ |
| 14984 int iMem; /* Memory location that acts as accumulator */ |
| 14985 Expr *pExpr; /* The original expression */ |
| 14986 } *aCol; |
| 14987 int nColumn; /* Number of used entries in aCol[] */ |
| 14988 int nAccumulator; /* Number of columns that show through to the output. |
| 14989 ** Additional columns are used only as parameters to |
| 14990 ** aggregate functions */ |
| 14991 struct AggInfo_func { /* For each aggregate function */ |
| 14992 Expr *pExpr; /* Expression encoding the function */ |
| 14993 FuncDef *pFunc; /* The aggregate function implementation */ |
| 14994 int iMem; /* Memory location that acts as accumulator */ |
| 14995 int iDistinct; /* Ephemeral table used to enforce DISTINCT */ |
| 14996 } *aFunc; |
| 14997 int nFunc; /* Number of entries in aFunc[] */ |
| 14998 }; |
| 14999 |
| 15000 /* |
| 15001 ** The datatype ynVar is a signed integer, either 16-bit or 32-bit. |
| 15002 ** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater |
| 15003 ** than 32767 we have to make it 32-bit. 16-bit is preferred because |
| 15004 ** it uses less memory in the Expr object, which is a big memory user |
| 15005 ** in systems with lots of prepared statements. And few applications |
| 15006 ** need more than about 10 or 20 variables. But some extreme users want |
| 15007 ** to have prepared statements with over 32767 variables, and for them |
| 15008 ** the option is available (at compile-time). |
| 15009 */ |
| 15010 #if SQLITE_MAX_VARIABLE_NUMBER<=32767 |
| 15011 typedef i16 ynVar; |
| 15012 #else |
| 15013 typedef int ynVar; |
| 15014 #endif |
| 15015 |
| 15016 /* |
| 15017 ** Each node of an expression in the parse tree is an instance |
| 15018 ** of this structure. |
| 15019 ** |
| 15020 ** Expr.op is the opcode. The integer parser token codes are reused |
| 15021 ** as opcodes here. For example, the parser defines TK_GE to be an integer |
| 15022 ** code representing the ">=" operator. This same integer code is reused |
| 15023 ** to represent the greater-than-or-equal-to operator in the expression |
| 15024 ** tree. |
| 15025 ** |
| 15026 ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB, |
| 15027 ** or TK_STRING), then Expr.token contains the text of the SQL literal. If |
| 15028 ** the expression is a variable (TK_VARIABLE), then Expr.token contains the |
| 15029 ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION), |
| 15030 ** then Expr.token contains the name of the function. |
| 15031 ** |
| 15032 ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a |
| 15033 ** binary operator. Either or both may be NULL. |
| 15034 ** |
| 15035 ** Expr.x.pList is a list of arguments if the expression is an SQL function, |
| 15036 ** a CASE expression or an IN expression of the form "<lhs> IN (<y>, <z>...)". |
| 15037 ** Expr.x.pSelect is used if the expression is a sub-select or an expression of |
| 15038 ** the form "<lhs> IN (SELECT ...)". If the EP_xIsSelect bit is set in the |
| 15039 ** Expr.flags mask, then Expr.x.pSelect is valid. Otherwise, Expr.x.pList is |
| 15040 ** valid. |
| 15041 ** |
| 15042 ** An expression of the form ID or ID.ID refers to a column in a table. |
| 15043 ** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is |
| 15044 ** the integer cursor number of a VDBE cursor pointing to that table and |
| 15045 ** Expr.iColumn is the column number for the specific column. If the |
| 15046 ** expression is used as a result in an aggregate SELECT, then the |
| 15047 ** value is also stored in the Expr.iAgg column in the aggregate so that |
| 15048 ** it can be accessed after all aggregates are computed. |
| 15049 ** |
| 15050 ** If the expression is an unbound variable marker (a question mark |
| 15051 ** character '?' in the original SQL) then the Expr.iTable holds the index |
| 15052 ** number for that variable. |
| 15053 ** |
| 15054 ** If the expression is a subquery then Expr.iColumn holds an integer |
| 15055 ** register number containing the result of the subquery. If the |
| 15056 ** subquery gives a constant result, then iTable is -1. If the subquery |
| 15057 ** gives a different answer at different times during statement processing |
| 15058 ** then iTable is the address of a subroutine that computes the subquery. |
| 15059 ** |
| 15060 ** If the Expr is of type OP_Column, and the table it is selecting from |
| 15061 ** is a disk table or the "old.*" pseudo-table, then pTab points to the |
| 15062 ** corresponding table definition. |
| 15063 ** |
| 15064 ** ALLOCATION NOTES: |
| 15065 ** |
| 15066 ** Expr objects can use a lot of memory space in database schema. To |
| 15067 ** help reduce memory requirements, sometimes an Expr object will be |
| 15068 ** truncated. And to reduce the number of memory allocations, sometimes |
| 15069 ** two or more Expr objects will be stored in a single memory allocation, |
| 15070 ** together with Expr.zToken strings. |
| 15071 ** |
| 15072 ** If the EP_Reduced and EP_TokenOnly flags are set when |
| 15073 ** an Expr object is truncated. When EP_Reduced is set, then all |
| 15074 ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees |
| 15075 ** are contained within the same memory allocation. Note, however, that |
| 15076 ** the subtrees in Expr.x.pList or Expr.x.pSelect are always separately |
| 15077 ** allocated, regardless of whether or not EP_Reduced is set. |
| 15078 */ |
| 15079 struct Expr { |
| 15080 u8 op; /* Operation performed by this node */ |
| 15081 char affinity; /* The affinity of the column or 0 if not a column */ |
| 15082 u32 flags; /* Various flags. EP_* See below */ |
| 15083 union { |
| 15084 char *zToken; /* Token value. Zero terminated and dequoted */ |
| 15085 int iValue; /* Non-negative integer value if EP_IntValue */ |
| 15086 } u; |
| 15087 |
| 15088 /* If the EP_TokenOnly flag is set in the Expr.flags mask, then no |
| 15089 ** space is allocated for the fields below this point. An attempt to |
| 15090 ** access them will result in a segfault or malfunction. |
| 15091 *********************************************************************/ |
| 15092 |
| 15093 Expr *pLeft; /* Left subnode */ |
| 15094 Expr *pRight; /* Right subnode */ |
| 15095 union { |
| 15096 ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */ |
| 15097 Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */ |
| 15098 } x; |
| 15099 |
| 15100 /* If the EP_Reduced flag is set in the Expr.flags mask, then no |
| 15101 ** space is allocated for the fields below this point. An attempt to |
| 15102 ** access them will result in a segfault or malfunction. |
| 15103 *********************************************************************/ |
| 15104 |
| 15105 #if SQLITE_MAX_EXPR_DEPTH>0 |
| 15106 int nHeight; /* Height of the tree headed by this node */ |
| 15107 #endif |
| 15108 int iTable; /* TK_COLUMN: cursor number of table holding column |
| 15109 ** TK_REGISTER: register number |
| 15110 ** TK_TRIGGER: 1 -> new, 0 -> old |
| 15111 ** EP_Unlikely: 134217728 times likelihood |
| 15112 ** TK_SELECT: 1st register of result vector */ |
| 15113 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 15114 ** TK_VARIABLE: variable number (always >= 1). |
| 15115 ** TK_SELECT_COLUMN: column of the result vector */ |
| 15116 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 15117 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 15118 u8 op2; /* TK_REGISTER: original value of Expr.op |
| 15119 ** TK_COLUMN: the value of p5 for OP_Column |
| 15120 ** TK_AGG_FUNCTION: nesting depth */ |
| 15121 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 15122 Table *pTab; /* Table for TK_COLUMN expressions. */ |
| 15123 }; |
| 15124 |
| 15125 /* |
| 15126 ** The following are the meanings of bits in the Expr.flags field. |
| 15127 */ |
| 15128 #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */ |
| 15129 #define EP_Agg 0x000002 /* Contains one or more aggregate functions */ |
| 15130 #define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */ |
| 15131 #define EP_Error 0x000008 /* Expression contains one or more errors */ |
| 15132 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */ |
| 15133 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */ |
| 15134 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */ |
| 15135 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */ |
| 15136 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */ |
| 15137 #define EP_Generic 0x000200 /* Ignore COLLATE or affinity on this tree */ |
| 15138 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */ |
| 15139 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */ |
| 15140 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */ |
| 15141 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */ |
| 15142 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ |
| 15143 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */ |
| 15144 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ |
| 15145 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 15146 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 15147 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ |
| 15148 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ |
| 15149 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ |
| 15150 #define EP_Alias 0x400000 /* Is an alias for a result set column */ |
| 15151 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ |
| 15152 |
| 15153 /* |
| 15154 ** Combinations of two or more EP_* flags |
| 15155 */ |
| 15156 #define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */ |
| 15157 |
| 15158 /* |
| 15159 ** These macros can be used to test, set, or clear bits in the |
| 15160 ** Expr.flags field. |
| 15161 */ |
| 15162 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0) |
| 15163 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P)) |
| 15164 #define ExprSetProperty(E,P) (E)->flags|=(P) |
| 15165 #define ExprClearProperty(E,P) (E)->flags&=~(P) |
| 15166 |
| 15167 /* The ExprSetVVAProperty() macro is used for Verification, Validation, |
| 15168 ** and Accreditation only. It works like ExprSetProperty() during VVA |
| 15169 ** processes but is a no-op for delivery. |
| 15170 */ |
| 15171 #ifdef SQLITE_DEBUG |
| 15172 # define ExprSetVVAProperty(E,P) (E)->flags|=(P) |
| 15173 #else |
| 15174 # define ExprSetVVAProperty(E,P) |
| 15175 #endif |
| 15176 |
| 15177 /* |
| 15178 ** Macros to determine the number of bytes required by a normal Expr |
| 15179 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags |
| 15180 ** and an Expr struct with the EP_TokenOnly flag set. |
| 15181 */ |
| 15182 #define EXPR_FULLSIZE sizeof(Expr) /* Full size */ |
| 15183 #define EXPR_REDUCEDSIZE offsetof(Expr,iTable) /* Common features */ |
| 15184 #define EXPR_TOKENONLYSIZE offsetof(Expr,pLeft) /* Fewer features */ |
| 15185 |
| 15186 /* |
| 15187 ** Flags passed to the sqlite3ExprDup() function. See the header comment |
| 15188 ** above sqlite3ExprDup() for details. |
| 15189 */ |
| 15190 #define EXPRDUP_REDUCE 0x0001 /* Used reduced-size Expr nodes */ |
| 15191 |
| 15192 /* |
| 15193 ** A list of expressions. Each expression may optionally have a |
| 15194 ** name. An expr/name combination can be used in several ways, such |
| 15195 ** as the list of "expr AS ID" fields following a "SELECT" or in the |
| 15196 ** list of "ID = expr" items in an UPDATE. A list of expressions can |
| 15197 ** also be used as the argument to a function, in which case the a.zName |
| 15198 ** field is not used. |
| 15199 ** |
| 15200 ** By default the Expr.zSpan field holds a human-readable description of |
| 15201 ** the expression that is used in the generation of error messages and |
| 15202 ** column labels. In this case, Expr.zSpan is typically the text of a |
| 15203 ** column expression as it exists in a SELECT statement. However, if |
| 15204 ** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name |
| 15205 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later |
| 15206 ** form is used for name resolution with nested FROM clauses. |
| 15207 */ |
| 15208 struct ExprList { |
| 15209 int nExpr; /* Number of expressions on the list */ |
| 15210 struct ExprList_item { /* For each expression in the list */ |
| 15211 Expr *pExpr; /* The list of expressions */ |
| 15212 char *zName; /* Token associated with this expression */ |
| 15213 char *zSpan; /* Original text of the expression */ |
| 15214 u8 sortOrder; /* 1 for DESC or 0 for ASC */ |
| 15215 unsigned done :1; /* A flag to indicate when processing is finished */ |
| 15216 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */ |
| 15217 unsigned reusable :1; /* Constant expression is reusable */ |
| 15218 union { |
| 15219 struct { |
| 15220 u16 iOrderByCol; /* For ORDER BY, column number in result set */ |
| 15221 u16 iAlias; /* Index into Parse.aAlias[] for zName */ |
| 15222 } x; |
| 15223 int iConstExprReg; /* Register in which Expr value is cached */ |
| 15224 } u; |
| 15225 } *a; /* Alloc a power of two greater or equal to nExpr */ |
| 15226 }; |
| 15227 |
| 15228 /* |
| 15229 ** An instance of this structure is used by the parser to record both |
| 15230 ** the parse tree for an expression and the span of input text for an |
| 15231 ** expression. |
| 15232 */ |
| 15233 struct ExprSpan { |
| 15234 Expr *pExpr; /* The expression parse tree */ |
| 15235 const char *zStart; /* First character of input text */ |
| 15236 const char *zEnd; /* One character past the end of input text */ |
| 15237 }; |
| 15238 |
| 15239 /* |
| 15240 ** An instance of this structure can hold a simple list of identifiers, |
| 15241 ** such as the list "a,b,c" in the following statements: |
| 15242 ** |
| 15243 ** INSERT INTO t(a,b,c) VALUES ...; |
| 15244 ** CREATE INDEX idx ON t(a,b,c); |
| 15245 ** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...; |
| 15246 ** |
| 15247 ** The IdList.a.idx field is used when the IdList represents the list of |
| 15248 ** column names after a table name in an INSERT statement. In the statement |
| 15249 ** |
| 15250 ** INSERT INTO t(a,b,c) ... |
| 15251 ** |
| 15252 ** If "a" is the k-th column of table "t", then IdList.a[0].idx==k. |
| 15253 */ |
| 15254 struct IdList { |
| 15255 struct IdList_item { |
| 15256 char *zName; /* Name of the identifier */ |
| 15257 int idx; /* Index in some Table.aCol[] of a column named zName */ |
| 15258 } *a; |
| 15259 int nId; /* Number of identifiers on the list */ |
| 15260 }; |
| 15261 |
| 15262 /* |
| 15263 ** The bitmask datatype defined below is used for various optimizations. |
| 15264 ** |
| 15265 ** Changing this from a 64-bit to a 32-bit type limits the number of |
| 15266 ** tables in a join to 32 instead of 64. But it also reduces the size |
| 15267 ** of the library by 738 bytes on ix86. |
| 15268 */ |
| 15269 #ifdef SQLITE_BITMASK_TYPE |
| 15270 typedef SQLITE_BITMASK_TYPE Bitmask; |
| 15271 #else |
| 15272 typedef u64 Bitmask; |
| 15273 #endif |
| 15274 |
| 15275 /* |
| 15276 ** The number of bits in a Bitmask. "BMS" means "BitMask Size". |
| 15277 */ |
| 15278 #define BMS ((int)(sizeof(Bitmask)*8)) |
| 15279 |
| 15280 /* |
| 15281 ** A bit in a Bitmask |
| 15282 */ |
| 15283 #define MASKBIT(n) (((Bitmask)1)<<(n)) |
| 15284 #define MASKBIT32(n) (((unsigned int)1)<<(n)) |
| 15285 #define ALLBITS ((Bitmask)-1) |
| 15286 |
| 15287 /* |
| 15288 ** The following structure describes the FROM clause of a SELECT statement. |
| 15289 ** Each table or subquery in the FROM clause is a separate element of |
| 15290 ** the SrcList.a[] array. |
| 15291 ** |
| 15292 ** With the addition of multiple database support, the following structure |
| 15293 ** can also be used to describe a particular table such as the table that |
| 15294 ** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL, |
| 15295 ** such a table must be a simple name: ID. But in SQLite, the table can |
| 15296 ** now be identified by a database name, a dot, then the table name: ID.ID. |
| 15297 ** |
| 15298 ** The jointype starts out showing the join type between the current table |
| 15299 ** and the next table on the list. The parser builds the list this way. |
| 15300 ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each |
| 15301 ** jointype expresses the join between the table and the previous table. |
| 15302 ** |
| 15303 ** In the colUsed field, the high-order bit (bit 63) is set if the table |
| 15304 ** contains more than 63 columns and the 64-th or later column is used. |
| 15305 */ |
| 15306 struct SrcList { |
| 15307 int nSrc; /* Number of tables or subqueries in the FROM clause */ |
| 15308 u32 nAlloc; /* Number of entries allocated in a[] below */ |
| 15309 struct SrcList_item { |
| 15310 Schema *pSchema; /* Schema to which this item is fixed */ |
| 15311 char *zDatabase; /* Name of database holding this table */ |
| 15312 char *zName; /* Name of the table */ |
| 15313 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ |
| 15314 Table *pTab; /* An SQL table corresponding to zName */ |
| 15315 Select *pSelect; /* A SELECT statement used in place of a table name */ |
| 15316 int addrFillSub; /* Address of subroutine to manifest a subquery */ |
| 15317 int regReturn; /* Register holding return address of addrFillSub */ |
| 15318 int regResult; /* Registers holding results of a co-routine */ |
| 15319 struct { |
| 15320 u8 jointype; /* Type of join between this table and the previous */ |
| 15321 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */ |
| 15322 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */ |
| 15323 unsigned isTabFunc :1; /* True if table-valued-function syntax */ |
| 15324 unsigned isCorrelated :1; /* True if sub-query is correlated */ |
| 15325 unsigned viaCoroutine :1; /* Implemented as a co-routine */ |
| 15326 unsigned isRecursive :1; /* True for recursive reference in WITH */ |
| 15327 } fg; |
| 15328 #ifndef SQLITE_OMIT_EXPLAIN |
| 15329 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */ |
| 15330 #endif |
| 15331 int iCursor; /* The VDBE cursor number used to access this table */ |
| 15332 Expr *pOn; /* The ON clause of a join */ |
| 15333 IdList *pUsing; /* The USING clause of a join */ |
| 15334 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */ |
| 15335 union { |
| 15336 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */ |
| 15337 ExprList *pFuncArg; /* Arguments to table-valued-function */ |
| 15338 } u1; |
| 15339 Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */ |
| 15340 } a[1]; /* One entry for each identifier on the list */ |
| 15341 }; |
| 15342 |
| 15343 /* |
| 15344 ** Permitted values of the SrcList.a.jointype field |
| 15345 */ |
| 15346 #define JT_INNER 0x0001 /* Any kind of inner or cross join */ |
| 15347 #define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */ |
| 15348 #define JT_NATURAL 0x0004 /* True for a "natural" join */ |
| 15349 #define JT_LEFT 0x0008 /* Left outer join */ |
| 15350 #define JT_RIGHT 0x0010 /* Right outer join */ |
| 15351 #define JT_OUTER 0x0020 /* The "OUTER" keyword is present */ |
| 15352 #define JT_ERROR 0x0040 /* unknown or unsupported join type */ |
| 15353 |
| 15354 |
| 15355 /* |
| 15356 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin() |
| 15357 ** and the WhereInfo.wctrlFlags member. |
| 15358 ** |
| 15359 ** Value constraints (enforced via assert()): |
| 15360 ** WHERE_USE_LIMIT == SF_FixedLimit |
| 15361 */ |
| 15362 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */ |
| 15363 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */ |
| 15364 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */ |
| 15365 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */ |
| 15366 #define WHERE_ONEPASS_MULTIROW 0x0008 /* ONEPASS is ok with multiple rows */ |
| 15367 #define WHERE_DUPLICATES_OK 0x0010 /* Ok to return a row more than once */ |
| 15368 #define WHERE_OR_SUBCLAUSE 0x0020 /* Processing a sub-WHERE as part of |
| 15369 ** the OR optimization */ |
| 15370 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */ |
| 15371 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */ |
| 15372 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */ |
| 15373 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */ |
| 15374 #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */ |
| 15375 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ |
| 15376 #define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */ |
| 15377 /* 0x2000 not currently used */ |
| 15378 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ |
| 15379 /* 0x8000 not currently used */ |
| 15380 |
| 15381 /* Allowed return values from sqlite3WhereIsDistinct() |
| 15382 */ |
| 15383 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */ |
| 15384 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */ |
| 15385 #define WHERE_DISTINCT_ORDERED 2 /* All duplicates are adjacent */ |
| 15386 #define WHERE_DISTINCT_UNORDERED 3 /* Duplicates are scattered */ |
| 15387 |
| 15388 /* |
| 15389 ** A NameContext defines a context in which to resolve table and column |
| 15390 ** names. The context consists of a list of tables (the pSrcList) field and |
| 15391 ** a list of named expression (pEList). The named expression list may |
| 15392 ** be NULL. The pSrc corresponds to the FROM clause of a SELECT or |
| 15393 ** to the table being operated on by INSERT, UPDATE, or DELETE. The |
| 15394 ** pEList corresponds to the result set of a SELECT and is NULL for |
| 15395 ** other statements. |
| 15396 ** |
| 15397 ** NameContexts can be nested. When resolving names, the inner-most |
| 15398 ** context is searched first. If no match is found, the next outer |
| 15399 ** context is checked. If there is still no match, the next context |
| 15400 ** is checked. This process continues until either a match is found |
| 15401 ** or all contexts are check. When a match is found, the nRef member of |
| 15402 ** the context containing the match is incremented. |
| 15403 ** |
| 15404 ** Each subquery gets a new NameContext. The pNext field points to the |
| 15405 ** NameContext in the parent query. Thus the process of scanning the |
| 15406 ** NameContext list corresponds to searching through successively outer |
| 15407 ** subqueries looking for a match. |
| 15408 */ |
| 15409 struct NameContext { |
| 15410 Parse *pParse; /* The parser */ |
| 15411 SrcList *pSrcList; /* One or more tables used to resolve names */ |
| 15412 ExprList *pEList; /* Optional list of result-set columns */ |
| 15413 AggInfo *pAggInfo; /* Information about aggregates at this level */ |
| 15414 NameContext *pNext; /* Next outer name context. NULL for outermost */ |
| 15415 int nRef; /* Number of names resolved by this context */ |
| 15416 int nErr; /* Number of errors encountered while resolving names */ |
| 15417 u16 ncFlags; /* Zero or more NC_* flags defined below */ |
| 15418 }; |
| 15419 |
| 15420 /* |
| 15421 ** Allowed values for the NameContext, ncFlags field. |
| 15422 ** |
| 15423 ** Value constraints (all checked via assert()): |
| 15424 ** NC_HasAgg == SF_HasAgg |
| 15425 ** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 15426 ** |
| 15427 */ |
| 15428 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */ |
| 15429 #define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */ |
| 15430 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */ |
| 15431 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */ |
| 15432 #define NC_HasAgg 0x0010 /* One or more aggregate functions seen */ |
| 15433 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */ |
| 15434 #define NC_VarSelect 0x0040 /* A correlated subquery has been seen */ |
| 15435 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */ |
| 15436 |
| 15437 /* |
| 15438 ** An instance of the following structure contains all information |
| 15439 ** needed to generate code for a single SELECT statement. |
| 15440 ** |
| 15441 ** nLimit is set to -1 if there is no LIMIT clause. nOffset is set to 0. |
| 15442 ** If there is a LIMIT clause, the parser sets nLimit to the value of the |
| 15443 ** limit and nOffset to the value of the offset (or 0 if there is not |
| 15444 ** offset). But later on, nLimit and nOffset become the memory locations |
| 15445 ** in the VDBE that record the limit and offset counters. |
| 15446 ** |
| 15447 ** addrOpenEphm[] entries contain the address of OP_OpenEphemeral opcodes. |
| 15448 ** These addresses must be stored so that we can go back and fill in |
| 15449 ** the P4_KEYINFO and P2 parameters later. Neither the KeyInfo nor |
| 15450 ** the number of columns in P2 can be computed at the same time |
| 15451 ** as the OP_OpenEphm instruction is coded because not |
| 15452 ** enough information about the compound query is known at that point. |
| 15453 ** The KeyInfo for addrOpenTran[0] and [1] contains collating sequences |
| 15454 ** for the result set. The KeyInfo for addrOpenEphm[2] contains collating |
| 15455 ** sequences for the ORDER BY clause. |
| 15456 */ |
| 15457 struct Select { |
| 15458 ExprList *pEList; /* The fields of the result */ |
| 15459 u8 op; /* One of: TK_UNION TK_ALL TK_INTERSECT TK_EXCEPT */ |
| 15460 LogEst nSelectRow; /* Estimated number of result rows */ |
| 15461 u32 selFlags; /* Various SF_* values */ |
| 15462 int iLimit, iOffset; /* Memory registers holding LIMIT & OFFSET counters */ |
| 15463 #if SELECTTRACE_ENABLED |
| 15464 char zSelName[12]; /* Symbolic name of this SELECT use for debugging */ |
| 15465 #endif |
| 15466 int addrOpenEphm[2]; /* OP_OpenEphem opcodes related to this select */ |
| 15467 SrcList *pSrc; /* The FROM clause */ |
| 15468 Expr *pWhere; /* The WHERE clause */ |
| 15469 ExprList *pGroupBy; /* The GROUP BY clause */ |
| 15470 Expr *pHaving; /* The HAVING clause */ |
| 15471 ExprList *pOrderBy; /* The ORDER BY clause */ |
| 15472 Select *pPrior; /* Prior select in a compound select statement */ |
| 15473 Select *pNext; /* Next select to the left in a compound */ |
| 15474 Expr *pLimit; /* LIMIT expression. NULL means not used. */ |
| 15475 Expr *pOffset; /* OFFSET expression. NULL means not used. */ |
| 15476 With *pWith; /* WITH clause attached to this select. Or NULL. */ |
| 15477 }; |
| 15478 |
| 15479 /* |
| 15480 ** Allowed values for Select.selFlags. The "SF" prefix stands for |
| 15481 ** "Select Flag". |
| 15482 ** |
| 15483 ** Value constraints (all checked via assert()) |
| 15484 ** SF_HasAgg == NC_HasAgg |
| 15485 ** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 15486 ** SF_FixedLimit == WHERE_USE_LIMIT |
| 15487 */ |
| 15488 #define SF_Distinct 0x00001 /* Output should be DISTINCT */ |
| 15489 #define SF_All 0x00002 /* Includes the ALL keyword */ |
| 15490 #define SF_Resolved 0x00004 /* Identifiers have been resolved */ |
| 15491 #define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */ |
| 15492 #define SF_HasAgg 0x00010 /* Contains aggregate functions */ |
| 15493 #define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */ |
| 15494 #define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */ |
| 15495 #define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */ |
| 15496 #define SF_Compound 0x00100 /* Part of a compound query */ |
| 15497 #define SF_Values 0x00200 /* Synthesized from VALUES clause */ |
| 15498 #define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */ |
| 15499 #define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */ |
| 15500 #define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */ |
| 15501 #define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */ |
| 15502 #define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */ |
| 15503 #define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */ |
| 15504 #define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */ |
| 15505 #define SF_IncludeHidden 0x20000 /* Include hidden columns in output */ |
| 15506 |
| 15507 |
| 15508 /* |
| 15509 ** The results of a SELECT can be distributed in several ways, as defined |
| 15510 ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| 15511 ** Type". |
| 15512 ** |
| 15513 ** SRT_Union Store results as a key in a temporary index |
| 15514 ** identified by pDest->iSDParm. |
| 15515 ** |
| 15516 ** SRT_Except Remove results from the temporary index pDest->iSDParm. |
| 15517 ** |
| 15518 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result |
| 15519 ** set is not empty. |
| 15520 ** |
| 15521 ** SRT_Discard Throw the results away. This is used by SELECT |
| 15522 ** statements within triggers whose only purpose is |
| 15523 ** the side-effects of functions. |
| 15524 ** |
| 15525 ** All of the above are free to ignore their ORDER BY clause. Those that |
| 15526 ** follow must honor the ORDER BY clause. |
| 15527 ** |
| 15528 ** SRT_Output Generate a row of output (using the OP_ResultRow |
| 15529 ** opcode) for each row in the result set. |
| 15530 ** |
| 15531 ** SRT_Mem Only valid if the result is a single column. |
| 15532 ** Store the first column of the first result row |
| 15533 ** in register pDest->iSDParm then abandon the rest |
| 15534 ** of the query. This destination implies "LIMIT 1". |
| 15535 ** |
| 15536 ** SRT_Set The result must be a single column. Store each |
| 15537 ** row of result as the key in table pDest->iSDParm. |
| 15538 ** Apply the affinity pDest->affSdst before storing |
| 15539 ** results. Used to implement "IN (SELECT ...)". |
| 15540 ** |
| 15541 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store |
| 15542 ** the result there. The cursor is left open after |
| 15543 ** returning. This is like SRT_Table except that |
| 15544 ** this destination uses OP_OpenEphemeral to create |
| 15545 ** the table first. |
| 15546 ** |
| 15547 ** SRT_Coroutine Generate a co-routine that returns a new row of |
| 15548 ** results each time it is invoked. The entry point |
| 15549 ** of the co-routine is stored in register pDest->iSDParm |
| 15550 ** and the result row is stored in pDest->nDest registers |
| 15551 ** starting with pDest->iSdst. |
| 15552 ** |
| 15553 ** SRT_Table Store results in temporary table pDest->iSDParm. |
| 15554 ** SRT_Fifo This is like SRT_EphemTab except that the table |
| 15555 ** is assumed to already be open. SRT_Fifo has |
| 15556 ** the additional property of being able to ignore |
| 15557 ** the ORDER BY clause. |
| 15558 ** |
| 15559 ** SRT_DistFifo Store results in a temporary table pDest->iSDParm. |
| 15560 ** But also use temporary table pDest->iSDParm+1 as |
| 15561 ** a record of all prior results and ignore any duplicate |
| 15562 ** rows. Name means: "Distinct Fifo". |
| 15563 ** |
| 15564 ** SRT_Queue Store results in priority queue pDest->iSDParm (really |
| 15565 ** an index). Append a sequence number so that all entries |
| 15566 ** are distinct. |
| 15567 ** |
| 15568 ** SRT_DistQueue Store results in priority queue pDest->iSDParm only if |
| 15569 ** the same record has never been stored before. The |
| 15570 ** index at pDest->iSDParm+1 hold all prior stores. |
| 15571 */ |
| 15572 #define SRT_Union 1 /* Store result as keys in an index */ |
| 15573 #define SRT_Except 2 /* Remove result from a UNION index */ |
| 15574 #define SRT_Exists 3 /* Store 1 if the result is not empty */ |
| 15575 #define SRT_Discard 4 /* Do not save the results anywhere */ |
| 15576 #define SRT_Fifo 5 /* Store result as data with an automatic rowid */ |
| 15577 #define SRT_DistFifo 6 /* Like SRT_Fifo, but unique results only */ |
| 15578 #define SRT_Queue 7 /* Store result in an queue */ |
| 15579 #define SRT_DistQueue 8 /* Like SRT_Queue, but unique results only */ |
| 15580 |
| 15581 /* The ORDER BY clause is ignored for all of the above */ |
| 15582 #define IgnorableOrderby(X) ((X->eDest)<=SRT_DistQueue) |
| 15583 |
| 15584 #define SRT_Output 9 /* Output each row of result */ |
| 15585 #define SRT_Mem 10 /* Store result in a memory cell */ |
| 15586 #define SRT_Set 11 /* Store results as keys in an index */ |
| 15587 #define SRT_EphemTab 12 /* Create transient tab and store like SRT_Table */ |
| 15588 #define SRT_Coroutine 13 /* Generate a single row of result */ |
| 15589 #define SRT_Table 14 /* Store result as data with an automatic rowid */ |
| 15590 |
| 15591 /* |
| 15592 ** An instance of this object describes where to put of the results of |
| 15593 ** a SELECT statement. |
| 15594 */ |
| 15595 struct SelectDest { |
| 15596 u8 eDest; /* How to dispose of the results. On of SRT_* above. */ |
| 15597 char *zAffSdst; /* Affinity used when eDest==SRT_Set */ |
| 15598 int iSDParm; /* A parameter used by the eDest disposal method */ |
| 15599 int iSdst; /* Base register where results are written */ |
| 15600 int nSdst; /* Number of registers allocated */ |
| 15601 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */ |
| 15602 }; |
| 15603 |
| 15604 /* |
| 15605 ** During code generation of statements that do inserts into AUTOINCREMENT |
| 15606 ** tables, the following information is attached to the Table.u.autoInc.p |
| 15607 ** pointer of each autoincrement table to record some side information that |
| 15608 ** the code generator needs. We have to keep per-table autoincrement |
| 15609 ** information in case inserts are done within triggers. Triggers do not |
| 15610 ** normally coordinate their activities, but we do need to coordinate the |
| 15611 ** loading and saving of autoincrement information. |
| 15612 */ |
| 15613 struct AutoincInfo { |
| 15614 AutoincInfo *pNext; /* Next info block in a list of them all */ |
| 15615 Table *pTab; /* Table this info block refers to */ |
| 15616 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */ |
| 15617 int regCtr; /* Memory register holding the rowid counter */ |
| 15618 }; |
| 15619 |
| 15620 /* |
| 15621 ** Size of the column cache |
| 15622 */ |
| 15623 #ifndef SQLITE_N_COLCACHE |
| 15624 # define SQLITE_N_COLCACHE 10 |
| 15625 #endif |
| 15626 |
| 15627 /* |
| 15628 ** At least one instance of the following structure is created for each |
| 15629 ** trigger that may be fired while parsing an INSERT, UPDATE or DELETE |
| 15630 ** statement. All such objects are stored in the linked list headed at |
| 15631 ** Parse.pTriggerPrg and deleted once statement compilation has been |
| 15632 ** completed. |
| 15633 ** |
| 15634 ** A Vdbe sub-program that implements the body and WHEN clause of trigger |
| 15635 ** TriggerPrg.pTrigger, assuming a default ON CONFLICT clause of |
| 15636 ** TriggerPrg.orconf, is stored in the TriggerPrg.pProgram variable. |
| 15637 ** The Parse.pTriggerPrg list never contains two entries with the same |
| 15638 ** values for both pTrigger and orconf. |
| 15639 ** |
| 15640 ** The TriggerPrg.aColmask[0] variable is set to a mask of old.* columns |
| 15641 ** accessed (or set to 0 for triggers fired as a result of INSERT |
| 15642 ** statements). Similarly, the TriggerPrg.aColmask[1] variable is set to |
| 15643 ** a mask of new.* columns used by the program. |
| 15644 */ |
| 15645 struct TriggerPrg { |
| 15646 Trigger *pTrigger; /* Trigger this program was coded from */ |
| 15647 TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */ |
| 15648 SubProgram *pProgram; /* Program implementing pTrigger/orconf */ |
| 15649 int orconf; /* Default ON CONFLICT policy */ |
| 15650 u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */ |
| 15651 }; |
| 15652 |
| 15653 /* |
| 15654 ** The yDbMask datatype for the bitmask of all attached databases. |
| 15655 */ |
| 15656 #if SQLITE_MAX_ATTACHED>30 |
| 15657 typedef unsigned char yDbMask[(SQLITE_MAX_ATTACHED+9)/8]; |
| 15658 # define DbMaskTest(M,I) (((M)[(I)/8]&(1<<((I)&7)))!=0) |
| 15659 # define DbMaskZero(M) memset((M),0,sizeof(M)) |
| 15660 # define DbMaskSet(M,I) (M)[(I)/8]|=(1<<((I)&7)) |
| 15661 # define DbMaskAllZero(M) sqlite3DbMaskAllZero(M) |
| 15662 # define DbMaskNonZero(M) (sqlite3DbMaskAllZero(M)==0) |
| 15663 #else |
| 15664 typedef unsigned int yDbMask; |
| 15665 # define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0) |
| 15666 # define DbMaskZero(M) (M)=0 |
| 15667 # define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I)) |
| 15668 # define DbMaskAllZero(M) (M)==0 |
| 15669 # define DbMaskNonZero(M) (M)!=0 |
| 15670 #endif |
| 15671 |
| 15672 /* |
| 15673 ** An SQL parser context. A copy of this structure is passed through |
| 15674 ** the parser and down into all the parser action routine in order to |
| 15675 ** carry around information that is global to the entire parse. |
| 15676 ** |
| 15677 ** The structure is divided into two parts. When the parser and code |
| 15678 ** generate call themselves recursively, the first part of the structure |
| 15679 ** is constant but the second part is reset at the beginning and end of |
| 15680 ** each recursion. |
| 15681 ** |
| 15682 ** The nTableLock and aTableLock variables are only used if the shared-cache |
| 15683 ** feature is enabled (if sqlite3Tsd()->useSharedData is true). They are |
| 15684 ** used to store the set of table-locks required by the statement being |
| 15685 ** compiled. Function sqlite3TableLock() is used to add entries to the |
| 15686 ** list. |
| 15687 */ |
| 15688 struct Parse { |
| 15689 sqlite3 *db; /* The main database structure */ |
| 15690 char *zErrMsg; /* An error message */ |
| 15691 Vdbe *pVdbe; /* An engine for executing database bytecode */ |
| 15692 int rc; /* Return code from execution */ |
| 15693 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ |
| 15694 u8 checkSchema; /* Causes schema cookie check after an error */ |
| 15695 u8 nested; /* Number of nested calls to the parser/code generator */ |
| 15696 u8 nTempReg; /* Number of temporary registers in aTempReg[] */ |
| 15697 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ |
| 15698 u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 15699 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ |
| 15700 u8 okConstFactor; /* OK to factor out constants */ |
| 15701 u8 disableLookaside; /* Number of times lookaside has been disabled */ |
| 15702 u8 nColCache; /* Number of entries in aColCache[] */ |
| 15703 int nRangeReg; /* Size of the temporary register block */ |
| 15704 int iRangeReg; /* First register in temporary register block */ |
| 15705 int nErr; /* Number of errors seen */ |
| 15706 int nTab; /* Number of previously allocated VDBE cursors */ |
| 15707 int nMem; /* Number of memory cells used so far */ |
| 15708 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ |
| 15709 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ |
| 15710 int ckBase; /* Base register of data during check constraints */ |
| 15711 int iSelfTab; /* Table of an index whose exprs are being coded */ |
| 15712 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 15713 int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 15714 int nLabel; /* Number of labels used */ |
| 15715 int *aLabel; /* Space to hold the labels */ |
| 15716 ExprList *pConstExpr;/* Constant expressions */ |
| 15717 Token constraintName;/* Name of the constraint currently being parsed */ |
| 15718 yDbMask writeMask; /* Start a write transaction on these databases */ |
| 15719 yDbMask cookieMask; /* Bitmask of schema verified databases */ |
| 15720 int regRowid; /* Register holding rowid of CREATE TABLE entry */ |
| 15721 int regRoot; /* Register holding root page number for new objects */ |
| 15722 int nMaxArg; /* Max args passed to user function by sub-program */ |
| 15723 #if SELECTTRACE_ENABLED |
| 15724 int nSelect; /* Number of SELECT statements seen */ |
| 15725 int nSelectIndent; /* How far to indent SELECTTRACE() output */ |
| 15726 #endif |
| 15727 #ifndef SQLITE_OMIT_SHARED_CACHE |
| 15728 int nTableLock; /* Number of locks in aTableLock */ |
| 15729 TableLock *aTableLock; /* Required table locks for shared-cache mode */ |
| 15730 #endif |
| 15731 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 15732 Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 15733 Table *pTriggerTab; /* Table triggers are being coded for */ |
| 15734 int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */ |
| 15735 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| 15736 u32 oldmask; /* Mask of old.* columns referenced */ |
| 15737 u32 newmask; /* Mask of new.* columns referenced */ |
| 15738 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 15739 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ |
| 15740 u8 disableTriggers; /* True to disable triggers */ |
| 15741 |
| 15742 /************************************************************************** |
| 15743 ** Fields above must be initialized to zero. The fields that follow, |
| 15744 ** down to the beginning of the recursive section, do not need to be |
| 15745 ** initialized as they will be set before being used. The boundary is |
| 15746 ** determined by offsetof(Parse,aColCache). |
| 15747 **************************************************************************/ |
| 15748 |
| 15749 struct yColCache { |
| 15750 int iTable; /* Table cursor number */ |
| 15751 i16 iColumn; /* Table column number */ |
| 15752 u8 tempReg; /* iReg is a temp register that needs to be freed */ |
| 15753 int iLevel; /* Nesting level */ |
| 15754 int iReg; /* Reg with value of this column. 0 means none. */ |
| 15755 int lru; /* Least recently used entry has the smallest value */ |
| 15756 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */ |
| 15757 int aTempReg[8]; /* Holding area for temporary registers */ |
| 15758 Token sNameToken; /* Token with unqualified schema object name */ |
| 15759 |
| 15760 /************************************************************************ |
| 15761 ** Above is constant between recursions. Below is reset before and after |
| 15762 ** each recursion. The boundary between these two regions is determined |
| 15763 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the |
| 15764 ** first field in the recursive region. |
| 15765 ************************************************************************/ |
| 15766 |
| 15767 Token sLastToken; /* The last token parsed */ |
| 15768 ynVar nVar; /* Number of '?' variables seen in the SQL so far */ |
| 15769 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */ |
| 15770 u8 explain; /* True if the EXPLAIN flag is found on the query */ |
| 15771 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 15772 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ |
| 15773 int nVtabLock; /* Number of virtual tables to lock */ |
| 15774 #endif |
| 15775 int nHeight; /* Expression tree height of current sub-select */ |
| 15776 #ifndef SQLITE_OMIT_EXPLAIN |
| 15777 int iSelectId; /* ID of current select for EXPLAIN output */ |
| 15778 int iNextSelectId; /* Next available select ID for EXPLAIN output */ |
| 15779 #endif |
| 15780 VList *pVList; /* Mapping between variable names and numbers */ |
| 15781 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */ |
| 15782 const char *zTail; /* All SQL text past the last semicolon parsed */ |
| 15783 Table *pNewTable; /* A table being constructed by CREATE TABLE */ |
| 15784 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ |
| 15785 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ |
| 15786 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 15787 Token sArg; /* Complete text of a module argument */ |
| 15788 Table **apVtabLock; /* Pointer to virtual tables needing locking */ |
| 15789 #endif |
| 15790 Table *pZombieTab; /* List of Table objects to delete after code gen */ |
| 15791 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ |
| 15792 With *pWith; /* Current WITH clause, or NULL */ |
| 15793 With *pWithToFree; /* Free this WITH object at the end of the parse */ |
| 15794 }; |
| 15795 |
| 15796 /* |
| 15797 ** Sizes and pointers of various parts of the Parse object. |
| 15798 */ |
| 15799 #define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/ |
| 15800 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */ |
| 15801 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */ |
| 15802 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */ |
| 15803 |
| 15804 /* |
| 15805 ** Return true if currently inside an sqlite3_declare_vtab() call. |
| 15806 */ |
| 15807 #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 15808 #define IN_DECLARE_VTAB 0 |
| 15809 #else |
| 15810 #define IN_DECLARE_VTAB (pParse->declareVtab) |
| 15811 #endif |
| 15812 |
| 15813 /* |
| 15814 ** An instance of the following structure can be declared on a stack and used |
| 15815 ** to save the Parse.zAuthContext value so that it can be restored later. |
| 15816 */ |
| 15817 struct AuthContext { |
| 15818 const char *zAuthContext; /* Put saved Parse.zAuthContext here */ |
| 15819 Parse *pParse; /* The Parse structure */ |
| 15820 }; |
| 15821 |
| 15822 /* |
| 15823 ** Bitfield flags for P5 value in various opcodes. |
| 15824 ** |
| 15825 ** Value constraints (enforced via assert()): |
| 15826 ** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH |
| 15827 ** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF |
| 15828 ** OPFLAG_BULKCSR == BTREE_BULKLOAD |
| 15829 ** OPFLAG_SEEKEQ == BTREE_SEEK_EQ |
| 15830 ** OPFLAG_FORDELETE == BTREE_FORDELETE |
| 15831 ** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION |
| 15832 ** OPFLAG_AUXDELETE == BTREE_AUXDELETE |
| 15833 */ |
| 15834 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ |
| 15835 /* Also used in P2 (not P5) of OP_Delete */ |
| 15836 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ |
| 15837 #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */ |
| 15838 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ |
| 15839 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ |
| 15840 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ |
| 15841 #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */ |
| 15842 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 15843 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 15844 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ |
| 15845 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ |
| 15846 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */ |
| 15847 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ |
| 15848 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ |
| 15849 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */ |
| 15850 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */ |
| 15851 |
| 15852 /* |
| 15853 * Each trigger present in the database schema is stored as an instance of |
| 15854 * struct Trigger. |
| 15855 * |
| 15856 * Pointers to instances of struct Trigger are stored in two ways. |
| 15857 * 1. In the "trigHash" hash table (part of the sqlite3* that represents the |
| 15858 * database). This allows Trigger structures to be retrieved by name. |
| 15859 * 2. All triggers associated with a single table form a linked list, using the |
| 15860 * pNext member of struct Trigger. A pointer to the first element of the |
| 15861 * linked list is stored as the "pTrigger" member of the associated |
| 15862 * struct Table. |
| 15863 * |
| 15864 * The "step_list" member points to the first element of a linked list |
| 15865 * containing the SQL statements specified as the trigger program. |
| 15866 */ |
| 15867 struct Trigger { |
| 15868 char *zName; /* The name of the trigger */ |
| 15869 char *table; /* The table or view to which the trigger applies */ |
| 15870 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */ |
| 15871 u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */ |
| 15872 Expr *pWhen; /* The WHEN clause of the expression (may be NULL) */ |
| 15873 IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger, |
| 15874 the <column-list> is stored here */ |
| 15875 Schema *pSchema; /* Schema containing the trigger */ |
| 15876 Schema *pTabSchema; /* Schema containing the table */ |
| 15877 TriggerStep *step_list; /* Link list of trigger program steps */ |
| 15878 Trigger *pNext; /* Next trigger associated with the table */ |
| 15879 }; |
| 15880 |
| 15881 /* |
| 15882 ** A trigger is either a BEFORE or an AFTER trigger. The following constants |
| 15883 ** determine which. |
| 15884 ** |
| 15885 ** If there are multiple triggers, you might of some BEFORE and some AFTER. |
| 15886 ** In that cases, the constants below can be ORed together. |
| 15887 */ |
| 15888 #define TRIGGER_BEFORE 1 |
| 15889 #define TRIGGER_AFTER 2 |
| 15890 |
| 15891 /* |
| 15892 * An instance of struct TriggerStep is used to store a single SQL statement |
| 15893 * that is a part of a trigger-program. |
| 15894 * |
| 15895 * Instances of struct TriggerStep are stored in a singly linked list (linked |
| 15896 * using the "pNext" member) referenced by the "step_list" member of the |
| 15897 * associated struct Trigger instance. The first element of the linked list is |
| 15898 * the first step of the trigger-program. |
| 15899 * |
| 15900 * The "op" member indicates whether this is a "DELETE", "INSERT", "UPDATE" or |
| 15901 * "SELECT" statement. The meanings of the other members is determined by the |
| 15902 * value of "op" as follows: |
| 15903 * |
| 15904 * (op == TK_INSERT) |
| 15905 * orconf -> stores the ON CONFLICT algorithm |
| 15906 * pSelect -> If this is an INSERT INTO ... SELECT ... statement, then |
| 15907 * this stores a pointer to the SELECT statement. Otherwise NULL. |
| 15908 * zTarget -> Dequoted name of the table to insert into. |
| 15909 * pExprList -> If this is an INSERT INTO ... VALUES ... statement, then |
| 15910 * this stores values to be inserted. Otherwise NULL. |
| 15911 * pIdList -> If this is an INSERT INTO ... (<column-names>) VALUES ... |
| 15912 * statement, then this stores the column-names to be |
| 15913 * inserted into. |
| 15914 * |
| 15915 * (op == TK_DELETE) |
| 15916 * zTarget -> Dequoted name of the table to delete from. |
| 15917 * pWhere -> The WHERE clause of the DELETE statement if one is specified. |
| 15918 * Otherwise NULL. |
| 15919 * |
| 15920 * (op == TK_UPDATE) |
| 15921 * zTarget -> Dequoted name of the table to update. |
| 15922 * pWhere -> The WHERE clause of the UPDATE statement if one is specified. |
| 15923 * Otherwise NULL. |
| 15924 * pExprList -> A list of the columns to update and the expressions to update |
| 15925 * them to. See sqlite3Update() documentation of "pChanges" |
| 15926 * argument. |
| 15927 * |
| 15928 */ |
| 15929 struct TriggerStep { |
| 15930 u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */ |
| 15931 u8 orconf; /* OE_Rollback etc. */ |
| 15932 Trigger *pTrig; /* The trigger that this step is a part of */ |
| 15933 Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */ |
| 15934 char *zTarget; /* Target table for DELETE, UPDATE, INSERT */ |
| 15935 Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */ |
| 15936 ExprList *pExprList; /* SET clause for UPDATE. */ |
| 15937 IdList *pIdList; /* Column names for INSERT */ |
| 15938 TriggerStep *pNext; /* Next in the link-list */ |
| 15939 TriggerStep *pLast; /* Last element in link-list. Valid for 1st elem only */ |
| 15940 }; |
| 15941 |
| 15942 /* |
| 15943 ** The following structure contains information used by the sqliteFix... |
| 15944 ** routines as they walk the parse tree to make database references |
| 15945 ** explicit. |
| 15946 */ |
| 15947 typedef struct DbFixer DbFixer; |
| 15948 struct DbFixer { |
| 15949 Parse *pParse; /* The parsing context. Error messages written here */ |
| 15950 Schema *pSchema; /* Fix items to this schema */ |
| 15951 int bVarOnly; /* Check for variable references only */ |
| 15952 const char *zDb; /* Make sure all objects are contained in this database */ |
| 15953 const char *zType; /* Type of the container - used for error messages */ |
| 15954 const Token *pName; /* Name of the container - used for error messages */ |
| 15955 }; |
| 15956 |
| 15957 /* |
| 15958 ** An objected used to accumulate the text of a string where we |
| 15959 ** do not necessarily know how big the string will be in the end. |
| 15960 */ |
| 15961 struct StrAccum { |
| 15962 sqlite3 *db; /* Optional database for lookaside. Can be NULL */ |
| 15963 char *zBase; /* A base allocation. Not from malloc. */ |
| 15964 char *zText; /* The string collected so far */ |
| 15965 u32 nChar; /* Length of the string so far */ |
| 15966 u32 nAlloc; /* Amount of space allocated in zText */ |
| 15967 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */ |
| 15968 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ |
| 15969 u8 printfFlags; /* SQLITE_PRINTF flags below */ |
| 15970 }; |
| 15971 #define STRACCUM_NOMEM 1 |
| 15972 #define STRACCUM_TOOBIG 2 |
| 15973 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */ |
| 15974 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */ |
| 15975 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */ |
| 15976 |
| 15977 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0) |
| 15978 |
| 15979 |
| 15980 /* |
| 15981 ** A pointer to this structure is used to communicate information |
| 15982 ** from sqlite3Init and OP_ParseSchema into the sqlite3InitCallback. |
| 15983 */ |
| 15984 typedef struct { |
| 15985 sqlite3 *db; /* The database being initialized */ |
| 15986 char **pzErrMsg; /* Error message stored here */ |
| 15987 int iDb; /* 0 for main database. 1 for TEMP, 2.. for ATTACHed */ |
| 15988 int rc; /* Result code stored here */ |
| 15989 } InitData; |
| 15990 |
| 15991 /* |
| 15992 ** Structure containing global configuration data for the SQLite library. |
| 15993 ** |
| 15994 ** This structure also contains some state information. |
| 15995 */ |
| 15996 struct Sqlite3Config { |
| 15997 int bMemstat; /* True to enable memory status */ |
| 15998 int bCoreMutex; /* True to enable core mutexing */ |
| 15999 int bFullMutex; /* True to enable full mutexing */ |
| 16000 int bOpenUri; /* True to interpret filenames as URIs */ |
| 16001 int bUseCis; /* Use covering indices for full-scans */ |
| 16002 int mxStrlen; /* Maximum string length */ |
| 16003 int neverCorrupt; /* Database is always well-formed */ |
| 16004 int szLookaside; /* Default lookaside buffer size */ |
| 16005 int nLookaside; /* Default lookaside buffer count */ |
| 16006 int nStmtSpill; /* Stmt-journal spill-to-disk threshold */ |
| 16007 sqlite3_mem_methods m; /* Low-level memory allocation interface */ |
| 16008 sqlite3_mutex_methods mutex; /* Low-level mutex interface */ |
| 16009 sqlite3_pcache_methods2 pcache2; /* Low-level page-cache interface */ |
| 16010 void *pHeap; /* Heap storage space */ |
| 16011 int nHeap; /* Size of pHeap[] */ |
| 16012 int mnReq, mxReq; /* Min and max heap requests sizes */ |
| 16013 sqlite3_int64 szMmap; /* mmap() space per open file */ |
| 16014 sqlite3_int64 mxMmap; /* Maximum value for szMmap */ |
| 16015 void *pScratch; /* Scratch memory */ |
| 16016 int szScratch; /* Size of each scratch buffer */ |
| 16017 int nScratch; /* Number of scratch buffers */ |
| 16018 void *pPage; /* Page cache memory */ |
| 16019 int szPage; /* Size of each page in pPage[] */ |
| 16020 int nPage; /* Number of pages in pPage[] */ |
| 16021 int mxParserStack; /* maximum depth of the parser stack */ |
| 16022 int sharedCacheEnabled; /* true if shared-cache mode enabled */ |
| 16023 u32 szPma; /* Maximum Sorter PMA size */ |
| 16024 /* The above might be initialized to non-zero. The following need to always |
| 16025 ** initially be zero, however. */ |
| 16026 int isInit; /* True after initialization has finished */ |
| 16027 int inProgress; /* True while initialization in progress */ |
| 16028 int isMutexInit; /* True after mutexes are initialized */ |
| 16029 int isMallocInit; /* True after malloc is initialized */ |
| 16030 int isPCacheInit; /* True after malloc is initialized */ |
| 16031 int nRefInitMutex; /* Number of users of pInitMutex */ |
| 16032 sqlite3_mutex *pInitMutex; /* Mutex used by sqlite3_initialize() */ |
| 16033 void (*xLog)(void*,int,const char*); /* Function for logging */ |
| 16034 void *pLogArg; /* First argument to xLog() */ |
| 16035 #ifdef SQLITE_ENABLE_SQLLOG |
| 16036 void(*xSqllog)(void*,sqlite3*,const char*, int); |
| 16037 void *pSqllogArg; |
| 16038 #endif |
| 16039 #ifdef SQLITE_VDBE_COVERAGE |
| 16040 /* The following callback (if not NULL) is invoked on every VDBE branch |
| 16041 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. |
| 16042 */ |
| 16043 void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */ |
| 16044 void *pVdbeBranchArg; /* 1st argument */ |
| 16045 #endif |
| 16046 #ifndef SQLITE_UNTESTABLE |
| 16047 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ |
| 16048 #endif |
| 16049 int bLocaltimeFault; /* True to fail localtime() calls */ |
| 16050 int iOnceResetThreshold; /* When to reset OP_Once counters */ |
| 16051 }; |
| 16052 |
| 16053 /* |
| 16054 ** This macro is used inside of assert() statements to indicate that |
| 16055 ** the assert is only valid on a well-formed database. Instead of: |
| 16056 ** |
| 16057 ** assert( X ); |
| 16058 ** |
| 16059 ** One writes: |
| 16060 ** |
| 16061 ** assert( X || CORRUPT_DB ); |
| 16062 ** |
| 16063 ** CORRUPT_DB is true during normal operation. CORRUPT_DB does not indicate |
| 16064 ** that the database is definitely corrupt, only that it might be corrupt. |
| 16065 ** For most test cases, CORRUPT_DB is set to false using a special |
| 16066 ** sqlite3_test_control(). This enables assert() statements to prove |
| 16067 ** things that are always true for well-formed databases. |
| 16068 */ |
| 16069 #define CORRUPT_DB (sqlite3Config.neverCorrupt==0) |
| 16070 |
| 16071 /* |
| 16072 ** Context pointer passed down through the tree-walk. |
| 16073 */ |
| 16074 struct Walker { |
| 16075 Parse *pParse; /* Parser context. */ |
| 16076 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 16077 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 16078 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 16079 int walkerDepth; /* Number of subqueries */ |
| 16080 u8 eCode; /* A small processing code */ |
| 16081 union { /* Extra data for callback */ |
| 16082 NameContext *pNC; /* Naming context */ |
| 16083 int n; /* A counter */ |
| 16084 int iCur; /* A cursor number */ |
| 16085 SrcList *pSrcList; /* FROM clause */ |
| 16086 struct SrcCount *pSrcCount; /* Counting column references */ |
| 16087 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */ |
| 16088 int *aiCol; /* array of column indexes */ |
| 16089 struct IdxCover *pIdxCover; /* Check for index coverage */ |
| 16090 } u; |
| 16091 }; |
| 16092 |
| 16093 /* Forward declarations */ |
| 16094 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*); |
| 16095 SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*); |
| 16096 SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*); |
| 16097 SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*); |
| 16098 SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*); |
| 16099 SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*); |
| 16100 |
| 16101 /* |
| 16102 ** Return code from the parse-tree walking primitives and their |
| 16103 ** callbacks. |
| 16104 */ |
| 16105 #define WRC_Continue 0 /* Continue down into children */ |
| 16106 #define WRC_Prune 1 /* Omit children but continue walking siblings */ |
| 16107 #define WRC_Abort 2 /* Abandon the tree walk */ |
| 16108 |
| 16109 /* |
| 16110 ** An instance of this structure represents a set of one or more CTEs |
| 16111 ** (common table expressions) created by a single WITH clause. |
| 16112 */ |
| 16113 struct With { |
| 16114 int nCte; /* Number of CTEs in the WITH clause */ |
| 16115 With *pOuter; /* Containing WITH clause, or NULL */ |
| 16116 struct Cte { /* For each CTE in the WITH clause.... */ |
| 16117 char *zName; /* Name of this CTE */ |
| 16118 ExprList *pCols; /* List of explicit column names, or NULL */ |
| 16119 Select *pSelect; /* The definition of this CTE */ |
| 16120 const char *zCteErr; /* Error message for circular references */ |
| 16121 } a[1]; |
| 16122 }; |
| 16123 |
| 16124 #ifdef SQLITE_DEBUG |
| 16125 /* |
| 16126 ** An instance of the TreeView object is used for printing the content of |
| 16127 ** data structures on sqlite3DebugPrintf() using a tree-like view. |
| 16128 */ |
| 16129 struct TreeView { |
| 16130 int iLevel; /* Which level of the tree we are on */ |
| 16131 u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */ |
| 16132 }; |
| 16133 #endif /* SQLITE_DEBUG */ |
| 16134 |
| 16135 /* |
| 16136 ** Assuming zIn points to the first byte of a UTF-8 character, |
| 16137 ** advance zIn to point to the first byte of the next UTF-8 character. |
| 16138 */ |
| 16139 #define SQLITE_SKIP_UTF8(zIn) { \ |
| 16140 if( (*(zIn++))>=0xc0 ){ \ |
| 16141 while( (*zIn & 0xc0)==0x80 ){ zIn++; } \ |
| 16142 } \ |
| 16143 } |
| 16144 |
| 16145 /* |
| 16146 ** The SQLITE_*_BKPT macros are substitutes for the error codes with |
| 16147 ** the same name but without the _BKPT suffix. These macros invoke |
| 16148 ** routines that report the line-number on which the error originated |
| 16149 ** using sqlite3_log(). The routines also provide a convenient place |
| 16150 ** to set a debugger breakpoint. |
| 16151 */ |
| 16152 SQLITE_PRIVATE int sqlite3CorruptError(int); |
| 16153 SQLITE_PRIVATE int sqlite3MisuseError(int); |
| 16154 SQLITE_PRIVATE int sqlite3CantopenError(int); |
| 16155 #define SQLITE_CORRUPT_BKPT sqlite3CorruptError(__LINE__) |
| 16156 #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) |
| 16157 #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) |
| 16158 #ifdef SQLITE_DEBUG |
| 16159 SQLITE_PRIVATE int sqlite3NomemError(int); |
| 16160 SQLITE_PRIVATE int sqlite3IoerrnomemError(int); |
| 16161 # define SQLITE_NOMEM_BKPT sqlite3NomemError(__LINE__) |
| 16162 # define SQLITE_IOERR_NOMEM_BKPT sqlite3IoerrnomemError(__LINE__) |
| 16163 #else |
| 16164 # define SQLITE_NOMEM_BKPT SQLITE_NOMEM |
| 16165 # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM |
| 16166 #endif |
| 16167 |
| 16168 /* |
| 16169 ** FTS3 and FTS4 both require virtual table support |
| 16170 */ |
| 16171 #if defined(SQLITE_OMIT_VIRTUALTABLE) |
| 16172 # undef SQLITE_ENABLE_FTS3 |
| 16173 # undef SQLITE_ENABLE_FTS4 |
| 16174 #endif |
| 16175 |
| 16176 /* |
| 16177 ** FTS4 is really an extension for FTS3. It is enabled using the |
| 16178 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also call |
| 16179 ** the SQLITE_ENABLE_FTS4 macro to serve as an alias for SQLITE_ENABLE_FTS3. |
| 16180 */ |
| 16181 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3) |
| 16182 # define SQLITE_ENABLE_FTS3 1 |
| 16183 #endif |
| 16184 |
| 16185 /* |
| 16186 ** The ctype.h header is needed for non-ASCII systems. It is also |
| 16187 ** needed by FTS3 when FTS3 is included in the amalgamation. |
| 16188 */ |
| 16189 #if !defined(SQLITE_ASCII) || \ |
| 16190 (defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_AMALGAMATION)) |
| 16191 # include <ctype.h> |
| 16192 #endif |
| 16193 |
| 16194 /* |
| 16195 ** The following macros mimic the standard library functions toupper(), |
| 16196 ** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The |
| 16197 ** sqlite versions only work for ASCII characters, regardless of locale. |
| 16198 */ |
| 16199 #ifdef SQLITE_ASCII |
| 16200 # define sqlite3Toupper(x) ((x)&~(sqlite3CtypeMap[(unsigned char)(x)]&0x20)) |
| 16201 # define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01) |
| 16202 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06) |
| 16203 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02) |
| 16204 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04) |
| 16205 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08) |
| 16206 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)]) |
| 16207 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80) |
| 16208 #else |
| 16209 # define sqlite3Toupper(x) toupper((unsigned char)(x)) |
| 16210 # define sqlite3Isspace(x) isspace((unsigned char)(x)) |
| 16211 # define sqlite3Isalnum(x) isalnum((unsigned char)(x)) |
| 16212 # define sqlite3Isalpha(x) isalpha((unsigned char)(x)) |
| 16213 # define sqlite3Isdigit(x) isdigit((unsigned char)(x)) |
| 16214 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x)) |
| 16215 # define sqlite3Tolower(x) tolower((unsigned char)(x)) |
| 16216 # define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`') |
| 16217 #endif |
| 16218 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 16219 SQLITE_PRIVATE int sqlite3IsIdChar(u8); |
| 16220 #endif |
| 16221 |
| 16222 /* |
| 16223 ** Internal function prototypes |
| 16224 */ |
| 16225 SQLITE_PRIVATE int sqlite3StrICmp(const char*,const char*); |
| 16226 SQLITE_PRIVATE int sqlite3Strlen30(const char*); |
| 16227 SQLITE_PRIVATE char *sqlite3ColumnType(Column*,char*); |
| 16228 #define sqlite3StrNICmp sqlite3_strnicmp |
| 16229 |
| 16230 SQLITE_PRIVATE int sqlite3MallocInit(void); |
| 16231 SQLITE_PRIVATE void sqlite3MallocEnd(void); |
| 16232 SQLITE_PRIVATE void *sqlite3Malloc(u64); |
| 16233 SQLITE_PRIVATE void *sqlite3MallocZero(u64); |
| 16234 SQLITE_PRIVATE void *sqlite3DbMallocZero(sqlite3*, u64); |
| 16235 SQLITE_PRIVATE void *sqlite3DbMallocRaw(sqlite3*, u64); |
| 16236 SQLITE_PRIVATE void *sqlite3DbMallocRawNN(sqlite3*, u64); |
| 16237 SQLITE_PRIVATE char *sqlite3DbStrDup(sqlite3*,const char*); |
| 16238 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64); |
| 16239 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64); |
| 16240 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64); |
| 16241 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64); |
| 16242 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*); |
| 16243 SQLITE_PRIVATE int sqlite3MallocSize(void*); |
| 16244 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*); |
| 16245 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int); |
| 16246 SQLITE_PRIVATE void sqlite3ScratchFree(void*); |
| 16247 SQLITE_PRIVATE void *sqlite3PageMalloc(int); |
| 16248 SQLITE_PRIVATE void sqlite3PageFree(void*); |
| 16249 SQLITE_PRIVATE void sqlite3MemSetDefault(void); |
| 16250 #ifndef SQLITE_UNTESTABLE |
| 16251 SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void)); |
| 16252 #endif |
| 16253 SQLITE_PRIVATE int sqlite3HeapNearlyFull(void); |
| 16254 |
| 16255 /* |
| 16256 ** On systems with ample stack space and that support alloca(), make |
| 16257 ** use of alloca() to obtain space for large automatic objects. By default, |
| 16258 ** obtain space from malloc(). |
| 16259 ** |
| 16260 ** The alloca() routine never returns NULL. This will cause code paths |
| 16261 ** that deal with sqlite3StackAlloc() failures to be unreachable. |
| 16262 */ |
| 16263 #ifdef SQLITE_USE_ALLOCA |
| 16264 # define sqlite3StackAllocRaw(D,N) alloca(N) |
| 16265 # define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N) |
| 16266 # define sqlite3StackFree(D,P) |
| 16267 #else |
| 16268 # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N) |
| 16269 # define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N) |
| 16270 # define sqlite3StackFree(D,P) sqlite3DbFree(D,P) |
| 16271 #endif |
| 16272 |
| 16273 /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they |
| 16274 ** are, disable MEMSYS3 |
| 16275 */ |
| 16276 #ifdef SQLITE_ENABLE_MEMSYS5 |
| 16277 SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void); |
| 16278 #undef SQLITE_ENABLE_MEMSYS3 |
| 16279 #endif |
| 16280 #ifdef SQLITE_ENABLE_MEMSYS3 |
| 16281 SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys3(void); |
| 16282 #endif |
| 16283 |
| 16284 |
| 16285 #ifndef SQLITE_MUTEX_OMIT |
| 16286 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void); |
| 16287 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3NoopMutex(void); |
| 16288 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int); |
| 16289 SQLITE_PRIVATE int sqlite3MutexInit(void); |
| 16290 SQLITE_PRIVATE int sqlite3MutexEnd(void); |
| 16291 #endif |
| 16292 #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP) |
| 16293 SQLITE_PRIVATE void sqlite3MemoryBarrier(void); |
| 16294 #else |
| 16295 # define sqlite3MemoryBarrier() |
| 16296 #endif |
| 16297 |
| 16298 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int); |
| 16299 SQLITE_PRIVATE void sqlite3StatusUp(int, int); |
| 16300 SQLITE_PRIVATE void sqlite3StatusDown(int, int); |
| 16301 SQLITE_PRIVATE void sqlite3StatusHighwater(int, int); |
| 16302 |
| 16303 /* Access to mutexes used by sqlite3_status() */ |
| 16304 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void); |
| 16305 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void); |
| 16306 |
| 16307 #ifndef SQLITE_OMIT_FLOATING_POINT |
| 16308 SQLITE_PRIVATE int sqlite3IsNaN(double); |
| 16309 #else |
| 16310 # define sqlite3IsNaN(X) 0 |
| 16311 #endif |
| 16312 |
| 16313 /* |
| 16314 ** An instance of the following structure holds information about SQL |
| 16315 ** functions arguments that are the parameters to the printf() function. |
| 16316 */ |
| 16317 struct PrintfArguments { |
| 16318 int nArg; /* Total number of arguments */ |
| 16319 int nUsed; /* Number of arguments used so far */ |
| 16320 sqlite3_value **apArg; /* The argument values */ |
| 16321 }; |
| 16322 |
| 16323 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, const char*, va_list); |
| 16324 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...); |
| 16325 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 16326 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 16327 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 16328 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| 16329 #endif |
| 16330 #if defined(SQLITE_TEST) |
| 16331 SQLITE_PRIVATE void *sqlite3TestTextToPtr(const char*); |
| 16332 #endif |
| 16333 |
| 16334 #if defined(SQLITE_DEBUG) |
| 16335 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); |
| 16336 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, co
nst char*); |
| 16337 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, co
nst char*); |
| 16338 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8); |
| 16339 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8); |
| 16340 #endif |
| 16341 |
| 16342 |
| 16343 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); |
| 16344 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); |
| 16345 SQLITE_PRIVATE void sqlite3Dequote(char*); |
| 16346 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*); |
| 16347 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); |
| 16348 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **); |
| 16349 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*); |
| 16350 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*); |
| 16351 SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse*,int); |
| 16352 SQLITE_PRIVATE int sqlite3GetTempRange(Parse*,int); |
| 16353 SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse*,int,int); |
| 16354 SQLITE_PRIVATE void sqlite3ClearTempRegCache(Parse*); |
| 16355 #ifdef SQLITE_DEBUG |
| 16356 SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse*,int,int); |
| 16357 #endif |
| 16358 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); |
| 16359 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*); |
| 16360 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); |
| 16361 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*); |
| 16362 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*); |
| 16363 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); |
| 16364 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); |
| 16365 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32); |
| 16366 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*); |
| 16367 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); |
| 16368 SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Ex
pr*); |
| 16369 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int); |
| 16370 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); |
| 16371 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*); |
| 16372 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*); |
| 16373 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*); |
| 16374 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**); |
| 16375 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**); |
| 16376 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int); |
| 16377 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 16378 SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName); |
| 16379 #endif |
| 16380 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*); |
| 16381 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int); |
| 16382 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*); |
| 16383 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*); |
| 16384 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*); |
| 16385 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); |
| 16386 SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*
); |
| 16387 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*); |
| 16388 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int); |
| 16389 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*); |
| 16390 SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16); |
| 16391 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int); |
| 16392 #if SQLITE_ENABLE_HIDDEN_COLUMNS |
| 16393 SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*); |
| 16394 #else |
| 16395 # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ |
| 16396 #endif |
| 16397 SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*); |
| 16398 SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); |
| 16399 SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); |
| 16400 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); |
| 16401 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*); |
| 16402 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 16403 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 16404 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 16405 sqlite3_vfs**,char**,char **); |
| 16406 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*); |
| 16407 |
| 16408 #ifdef SQLITE_UNTESTABLE |
| 16409 # define sqlite3FaultSim(X) SQLITE_OK |
| 16410 #else |
| 16411 SQLITE_PRIVATE int sqlite3FaultSim(int); |
| 16412 #endif |
| 16413 |
| 16414 SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32); |
| 16415 SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32); |
| 16416 SQLITE_PRIVATE int sqlite3BitvecTestNotNull(Bitvec*, u32); |
| 16417 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); |
| 16418 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*); |
| 16419 SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*); |
| 16420 SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*); |
| 16421 #ifndef SQLITE_UNTESTABLE |
| 16422 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*); |
| 16423 #endif |
| 16424 |
| 16425 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int); |
| 16426 SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*); |
| 16427 SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64); |
| 16428 SQLITE_PRIVATE int sqlite3RowSetTest(RowSet*, int iBatch, i64); |
| 16429 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*); |
| 16430 |
| 16431 SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Sele
ct*,int,int); |
| 16432 |
| 16433 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 16434 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*); |
| 16435 #else |
| 16436 # define sqlite3ViewGetColumnNames(A,B) 0 |
| 16437 #endif |
| 16438 |
| 16439 #if SQLITE_MAX_ATTACHED>30 |
| 16440 SQLITE_PRIVATE int sqlite3DbMaskAllZero(yDbMask); |
| 16441 #endif |
| 16442 SQLITE_PRIVATE void sqlite3DropTable(Parse*, SrcList*, int, int); |
| 16443 SQLITE_PRIVATE void sqlite3CodeDropTable(Parse*, Table*, int, int); |
| 16444 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3*, Table*); |
| 16445 #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 16446 SQLITE_PRIVATE void sqlite3AutoincrementBegin(Parse *pParse); |
| 16447 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse); |
| 16448 #else |
| 16449 # define sqlite3AutoincrementBegin(X) |
| 16450 # define sqlite3AutoincrementEnd(X) |
| 16451 #endif |
| 16452 SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int); |
| 16453 SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*); |
| 16454 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*); |
| 16455 SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*); |
| 16456 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int); |
| 16457 SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*)
; |
| 16458 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, T
oken*, |
| 16459 Token*, Select*, Expr*, IdList*); |
| 16460 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *); |
| 16461 SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*); |
| 16462 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *); |
| 16463 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*); |
| 16464 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*); |
| 16465 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*); |
| 16466 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*); |
| 16467 SQLITE_PRIVATE Index *sqlite3AllocateIndexObject(sqlite3*,i16,int,char**); |
| 16468 SQLITE_PRIVATE void sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,i
nt,Token*, |
| 16469 Expr*, int, int, u8); |
| 16470 SQLITE_PRIVATE void sqlite3DropIndex(Parse*, SrcList*, int); |
| 16471 SQLITE_PRIVATE int sqlite3Select(Parse*, Select*, SelectDest*); |
| 16472 SQLITE_PRIVATE Select *sqlite3SelectNew(Parse*,ExprList*,SrcList*,Expr*,ExprList
*, |
| 16473 Expr*,ExprList*,u32,Expr*,Expr*); |
| 16474 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3*, Select*); |
| 16475 SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse*, SrcList*); |
| 16476 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse*, Table*, int); |
| 16477 SQLITE_PRIVATE void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int); |
| 16478 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) |
| 16479 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse*,SrcList*,Expr*,ExprList*,Expr*,Exp
r*,char*); |
| 16480 #endif |
| 16481 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); |
| 16482 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); |
| 16483 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*,SrcList*,Expr*,ExprList*,Expr
List*,u16,int); |
| 16484 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); |
| 16485 SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*); |
| 16486 SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*); |
| 16487 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*); |
| 16488 SQLITE_PRIVATE int sqlite3WhereOrderedInnerLoop(WhereInfo*); |
| 16489 SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*); |
| 16490 SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*); |
| 16491 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*); |
| 16492 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*); |
| 16493 #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ |
| 16494 #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */ |
| 16495 #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */ |
| 16496 SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int
); |
| 16497 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 16498 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnToReg(Parse*, Table*, int, int, int)
; |
| 16499 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int
); |
| 16500 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 16501 SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int); |
| 16502 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*); |
| 16503 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*); |
| 16504 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int); |
| 16505 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*); |
| 16506 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int); |
| 16507 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| 16508 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); |
| 16509 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 16510 SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int); |
| 16511 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| 16512 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
| 16513 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
| 16514 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); |
| 16515 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ |
| 16516 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ |
| 16517 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */ |
| 16518 #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */ |
| 16519 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int); |
| 16520 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int); |
| 16521 SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int); |
| 16522 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*); |
| 16523 #define LOCATE_VIEW 0x01 |
| 16524 #define LOCATE_NOERR 0x02 |
| 16525 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const cha
r*); |
| 16526 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_ite
m *); |
| 16527 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*); |
| 16528 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*); |
| 16529 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); |
| 16530 SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*); |
| 16531 SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int); |
| 16532 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*); |
| 16533 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int); |
| 16534 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int); |
| 16535 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int); |
| 16536 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 16537 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 16538 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| 16539 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 16540 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 16541 #ifndef SQLITE_UNTESTABLE |
| 16542 SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 16543 SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 16544 #endif |
| 16545 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 16546 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 16547 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 16548 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 16549 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| 16550 SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse*); |
| 16551 SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*); |
| 16552 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); |
| 16553 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); |
| 16554 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 16555 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 16556 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 16557 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 16558 #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 16559 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); |
| 16560 #endif |
| 16561 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 16562 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 16563 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 16564 SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 16565 SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 16566 Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); |
| 16567 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*
, int); |
| 16568 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,I
ndex*,int); |
| 16569 SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 16570 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,i
nt,int, |
| 16571 u8,u8,int,int*,int*); |
| 16572 #ifdef SQLITE_ENABLE_NULL_TRIM |
| 16573 SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe*,Table*); |
| 16574 #else |
| 16575 # define sqlite3SetMakeRecordP5(A,B) |
| 16576 #endif |
| 16577 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,
int,int); |
| 16578 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*,
int*, int*); |
| 16579 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int); |
| 16580 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*); |
| 16581 SQLITE_PRIVATE void sqlite3MayAbort(Parse*); |
| 16582 SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, i8, u8); |
| 16583 SQLITE_PRIVATE void sqlite3UniqueConstraint(Parse*, int, Index*); |
| 16584 SQLITE_PRIVATE void sqlite3RowidConstraint(Parse*, int, Table*); |
| 16585 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int); |
| 16586 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); |
| 16587 SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); |
| 16588 SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*); |
| 16589 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int); |
| 16590 #if SELECTTRACE_ENABLED |
| 16591 SQLITE_PRIVATE void sqlite3SelectSetName(Select*,const char*); |
| 16592 #else |
| 16593 # define sqlite3SelectSetName(A,B) |
| 16594 #endif |
| 16595 SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs(FuncDef*,int); |
| 16596 SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8); |
| 16597 SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void); |
| 16598 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void); |
| 16599 SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*); |
| 16600 SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*); |
| 16601 SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*); |
| 16602 SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int); |
| 16603 |
| 16604 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) |
| 16605 SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, int); |
| 16606 #endif |
| 16607 |
| 16608 #ifndef SQLITE_OMIT_TRIGGER |
| 16609 SQLITE_PRIVATE void sqlite3BeginTrigger(Parse*, Token*,Token*,int,int,IdList*,
SrcList*, |
| 16610 Expr*,int, int); |
| 16611 SQLITE_PRIVATE void sqlite3FinishTrigger(Parse*, TriggerStep*, Token*); |
| 16612 SQLITE_PRIVATE void sqlite3DropTrigger(Parse*, SrcList*, int); |
| 16613 SQLITE_PRIVATE void sqlite3DropTriggerPtr(Parse*, Trigger*); |
| 16614 SQLITE_PRIVATE Trigger *sqlite3TriggersExist(Parse *, Table*, int, ExprList*,
int *pMask); |
| 16615 SQLITE_PRIVATE Trigger *sqlite3TriggerList(Parse *, Table *); |
| 16616 SQLITE_PRIVATE void sqlite3CodeRowTrigger(Parse*, Trigger *, int, ExprList*, i
nt, Table *, |
| 16617 int, int, int); |
| 16618 SQLITE_PRIVATE void sqlite3CodeRowTriggerDirect(Parse *, Trigger *, Table *, i
nt, int, int); |
| 16619 void sqliteViewTriggers(Parse*, Table*, Expr*, int, ExprList*); |
| 16620 SQLITE_PRIVATE void sqlite3DeleteTriggerStep(sqlite3*, TriggerStep*); |
| 16621 SQLITE_PRIVATE TriggerStep *sqlite3TriggerSelectStep(sqlite3*,Select*); |
| 16622 SQLITE_PRIVATE TriggerStep *sqlite3TriggerInsertStep(sqlite3*,Token*, IdList*, |
| 16623 Select*,u8); |
| 16624 SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(sqlite3*,Token*,ExprList*
, Expr*, u8); |
| 16625 SQLITE_PRIVATE TriggerStep *sqlite3TriggerDeleteStep(sqlite3*,Token*, Expr*); |
| 16626 SQLITE_PRIVATE void sqlite3DeleteTrigger(sqlite3*, Trigger*); |
| 16627 SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3*,int,const char*); |
| 16628 SQLITE_PRIVATE u32 sqlite3TriggerColmask(Parse*,Trigger*,ExprList*,int,int,Tab
le*,int); |
| 16629 # define sqlite3ParseToplevel(p) ((p)->pToplevel ? (p)->pToplevel : (p)) |
| 16630 # define sqlite3IsToplevel(p) ((p)->pToplevel==0) |
| 16631 #else |
| 16632 # define sqlite3TriggersExist(B,C,D,E,F) 0 |
| 16633 # define sqlite3DeleteTrigger(A,B) |
| 16634 # define sqlite3DropTriggerPtr(A,B) |
| 16635 # define sqlite3UnlinkAndDeleteTrigger(A,B,C) |
| 16636 # define sqlite3CodeRowTrigger(A,B,C,D,E,F,G,H,I) |
| 16637 # define sqlite3CodeRowTriggerDirect(A,B,C,D,E,F) |
| 16638 # define sqlite3TriggerList(X, Y) 0 |
| 16639 # define sqlite3ParseToplevel(p) p |
| 16640 # define sqlite3IsToplevel(p) 1 |
| 16641 # define sqlite3TriggerColmask(A,B,C,D,E,F,G) 0 |
| 16642 #endif |
| 16643 |
| 16644 SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*); |
| 16645 SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*
, int); |
| 16646 SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int); |
| 16647 #ifndef SQLITE_OMIT_AUTHORIZATION |
| 16648 SQLITE_PRIVATE void sqlite3AuthRead(Parse*,Expr*,Schema*,SrcList*); |
| 16649 SQLITE_PRIVATE int sqlite3AuthCheck(Parse*,int, const char*, const char*, cons
t char*); |
| 16650 SQLITE_PRIVATE void sqlite3AuthContextPush(Parse*, AuthContext*, const char*); |
| 16651 SQLITE_PRIVATE void sqlite3AuthContextPop(AuthContext*); |
| 16652 SQLITE_PRIVATE int sqlite3AuthReadCol(Parse*, const char *, const char *, int)
; |
| 16653 #else |
| 16654 # define sqlite3AuthRead(a,b,c,d) |
| 16655 # define sqlite3AuthCheck(a,b,c,d,e) SQLITE_OK |
| 16656 # define sqlite3AuthContextPush(a,b,c) |
| 16657 # define sqlite3AuthContextPop(a) ((void)(a)) |
| 16658 #endif |
| 16659 SQLITE_PRIVATE void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); |
| 16660 SQLITE_PRIVATE void sqlite3Detach(Parse*, Expr*); |
| 16661 SQLITE_PRIVATE void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Tok
en*); |
| 16662 SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*); |
| 16663 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*); |
| 16664 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*); |
| 16665 SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*); |
| 16666 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); |
| 16667 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8); |
| 16668 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*); |
| 16669 SQLITE_PRIVATE int sqlite3Atoi(const char*); |
| 16670 SQLITE_PRIVATE int sqlite3Utf16ByteLen(const void *pData, int nChar); |
| 16671 SQLITE_PRIVATE int sqlite3Utf8CharLen(const char *pData, int nByte); |
| 16672 SQLITE_PRIVATE u32 sqlite3Utf8Read(const u8**); |
| 16673 SQLITE_PRIVATE LogEst sqlite3LogEst(u64); |
| 16674 SQLITE_PRIVATE LogEst sqlite3LogEstAdd(LogEst,LogEst); |
| 16675 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 16676 SQLITE_PRIVATE LogEst sqlite3LogEstFromDouble(double); |
| 16677 #endif |
| 16678 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \ |
| 16679 defined(SQLITE_ENABLE_STAT3_OR_STAT4) || \ |
| 16680 defined(SQLITE_EXPLAIN_ESTIMATED_ROWS) |
| 16681 SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst); |
| 16682 #endif |
| 16683 SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int); |
| 16684 SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int); |
| 16685 SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int); |
| 16686 |
| 16687 /* |
| 16688 ** Routines to read and write variable-length integers. These used to |
| 16689 ** be defined locally, but now we use the varint routines in the util.c |
| 16690 ** file. |
| 16691 */ |
| 16692 SQLITE_PRIVATE int sqlite3PutVarint(unsigned char*, u64); |
| 16693 SQLITE_PRIVATE u8 sqlite3GetVarint(const unsigned char *, u64 *); |
| 16694 SQLITE_PRIVATE u8 sqlite3GetVarint32(const unsigned char *, u32 *); |
| 16695 SQLITE_PRIVATE int sqlite3VarintLen(u64 v); |
| 16696 |
| 16697 /* |
| 16698 ** The common case is for a varint to be a single byte. They following |
| 16699 ** macros handle the common case without a procedure call, but then call |
| 16700 ** the procedure for larger varints. |
| 16701 */ |
| 16702 #define getVarint32(A,B) \ |
| 16703 (u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3GetVarint32((A),(u32 *)&(B))) |
| 16704 #define putVarint32(A,B) \ |
| 16705 (u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\ |
| 16706 sqlite3PutVarint((A),(B))) |
| 16707 #define getVarint sqlite3GetVarint |
| 16708 #define putVarint sqlite3PutVarint |
| 16709 |
| 16710 |
| 16711 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*); |
| 16712 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int); |
| 16713 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2); |
| 16714 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity); |
| 16715 SQLITE_PRIVATE char sqlite3TableColumnAffinity(Table*,int); |
| 16716 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr); |
| 16717 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8); |
| 16718 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*); |
| 16719 SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...); |
| 16720 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int); |
| 16721 SQLITE_PRIVATE void sqlite3SystemError(sqlite3*,int); |
| 16722 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 16723 SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 16724 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 16725 |
| 16726 #if defined(SQLITE_NEED_ERR_NAME) |
| 16727 SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 16728 #endif |
| 16729 |
| 16730 SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 16731 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| 16732 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); |
| 16733 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); |
| 16734 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); |
| 16735 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Toke
n*, int); |
| 16736 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); |
| 16737 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*); |
| 16738 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 16739 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 16740 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 16741 SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 16742 SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| 16743 SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); |
| 16744 SQLITE_PRIVATE int sqlite3AbsInt32(int); |
| 16745 #ifdef SQLITE_ENABLE_8_3_NAMES |
| 16746 SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*); |
| 16747 #else |
| 16748 # define sqlite3FileSuffix3(X,Y) |
| 16749 #endif |
| 16750 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z,u8); |
| 16751 |
| 16752 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 16753 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 16754 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 16755 void(*)(void*)); |
| 16756 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*); |
| 16757 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*); |
| 16758 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 16759 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); |
| 16760 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value
**); |
| 16761 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| 16762 #ifndef SQLITE_AMALGAMATION |
| 16763 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[]; |
| 16764 SQLITE_PRIVATE const char sqlite3StrBINARY[]; |
| 16765 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[]; |
| 16766 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[]; |
| 16767 SQLITE_PRIVATE const Token sqlite3IntTokens[]; |
| 16768 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config; |
| 16769 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 16770 #ifndef SQLITE_OMIT_WSD |
| 16771 SQLITE_PRIVATE int sqlite3PendingByte; |
| 16772 #endif |
| 16773 #endif |
| 16774 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int); |
| 16775 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 16776 SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 16777 SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 16778 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *); |
| 16779 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| 16780 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*); |
| 16781 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr *, int, int); |
| 16782 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*); |
| 16783 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p); |
| 16784 SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, c
onst char*); |
| 16785 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*); |
| 16786 SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*); |
| 16787 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); |
| 16788 SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList
*); |
| 16789 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const
char*); |
| 16790 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int); |
| 16791 SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *); |
| 16792 SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *); |
| 16793 SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); |
| 16794 SQLITE_PRIVATE char sqlite3AffinityType(const char*, u8*); |
| 16795 SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*); |
| 16796 SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*); |
| 16797 SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*); |
| 16798 SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *); |
| 16799 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB); |
| 16800 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*); |
| 16801 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*); |
| 16802 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int); |
| 16803 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); |
| 16804 SQLITE_PRIVATE void sqlite3SchemaClear(void *); |
| 16805 SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *); |
| 16806 SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *); |
| 16807 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3*,int,int); |
| 16808 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*); |
| 16809 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*); |
| 16810 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*); |
| 16811 #ifdef SQLITE_DEBUG |
| 16812 SQLITE_PRIVATE int sqlite3KeyInfoIsWriteable(KeyInfo*); |
| 16813 #endif |
| 16814 SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, |
| 16815 void (*)(sqlite3_context*,int,sqlite3_value **), |
| 16816 void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*), |
| 16817 FuncDestructor *pDestructor |
| 16818 ); |
| 16819 SQLITE_PRIVATE void sqlite3OomFault(sqlite3*); |
| 16820 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*); |
| 16821 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 16822 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 16823 |
| 16824 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int); |
| 16825 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 16826 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); |
| 16827 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char); |
| 16828 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 16829 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| 16830 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 16831 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| 16832 |
| 16833 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *); |
| 16834 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *); |
| 16835 |
| 16836 #ifndef SQLITE_OMIT_SUBQUERY |
| 16837 SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse*, Expr*); |
| 16838 #else |
| 16839 # define sqlite3ExprCheckIN(x,y) SQLITE_OK |
| 16840 #endif |
| 16841 |
| 16842 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 16843 SQLITE_PRIVATE void sqlite3AnalyzeFunctions(void); |
| 16844 SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue( |
| 16845 Parse*,Index*,UnpackedRecord**,Expr*,int,int,int*); |
| 16846 SQLITE_PRIVATE int sqlite3Stat4ValueFromExpr(Parse*, Expr*, u8, sqlite3_value**)
; |
| 16847 SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord*); |
| 16848 SQLITE_PRIVATE int sqlite3Stat4Column(sqlite3*, const void*, int, int, sqlite3_v
alue**); |
| 16849 SQLITE_PRIVATE char sqlite3IndexColumnAffinity(sqlite3*, Index*, int); |
| 16850 #endif |
| 16851 |
| 16852 /* |
| 16853 ** The interface to the LEMON-generated parser |
| 16854 */ |
| 16855 #ifndef SQLITE_AMALGAMATION |
| 16856 SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64)); |
| 16857 SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*)); |
| 16858 #endif |
| 16859 SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*); |
| 16860 #ifdef YYTRACKMAXSTACKDEPTH |
| 16861 SQLITE_PRIVATE int sqlite3ParserStackPeak(void*); |
| 16862 #endif |
| 16863 |
| 16864 SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3*); |
| 16865 #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 16866 SQLITE_PRIVATE void sqlite3CloseExtensions(sqlite3*); |
| 16867 #else |
| 16868 # define sqlite3CloseExtensions(X) |
| 16869 #endif |
| 16870 |
| 16871 #ifndef SQLITE_OMIT_SHARED_CACHE |
| 16872 SQLITE_PRIVATE void sqlite3TableLock(Parse *, int, int, u8, const char *); |
| 16873 #else |
| 16874 #define sqlite3TableLock(v,w,x,y,z) |
| 16875 #endif |
| 16876 |
| 16877 #ifdef SQLITE_TEST |
| 16878 SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char*); |
| 16879 #endif |
| 16880 |
| 16881 #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 16882 # define sqlite3VtabClear(Y) |
| 16883 # define sqlite3VtabSync(X,Y) SQLITE_OK |
| 16884 # define sqlite3VtabRollback(X) |
| 16885 # define sqlite3VtabCommit(X) |
| 16886 # define sqlite3VtabInSync(db) 0 |
| 16887 # define sqlite3VtabLock(X) |
| 16888 # define sqlite3VtabUnlock(X) |
| 16889 # define sqlite3VtabUnlockList(X) |
| 16890 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK |
| 16891 # define sqlite3GetVTable(X,Y) ((VTable*)0) |
| 16892 #else |
| 16893 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*); |
| 16894 SQLITE_PRIVATE void sqlite3VtabDisconnect(sqlite3 *db, Table *p); |
| 16895 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, Vdbe*); |
| 16896 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db); |
| 16897 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db); |
| 16898 SQLITE_PRIVATE void sqlite3VtabLock(VTable *); |
| 16899 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *); |
| 16900 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*); |
| 16901 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int); |
| 16902 SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*); |
| 16903 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*); |
| 16904 SQLITE_PRIVATE Module *sqlite3VtabCreateModule( |
| 16905 sqlite3*, |
| 16906 const char*, |
| 16907 const sqlite3_module*, |
| 16908 void*, |
| 16909 void(*)(void*) |
| 16910 ); |
| 16911 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0) |
| 16912 #endif |
| 16913 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*); |
| 16914 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*); |
| 16915 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*); |
| 16916 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int); |
| 16917 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*); |
| 16918 SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*); |
| 16919 SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*); |
| 16920 SQLITE_PRIVATE int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **); |
| 16921 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*); |
| 16922 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *); |
| 16923 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *); |
| 16924 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg
, Expr*); |
| 16925 SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**)
; |
| 16926 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); |
| 16927 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); |
| 16928 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); |
| 16929 SQLITE_PRIVATE void sqlite3ParserReset(Parse*); |
| 16930 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*); |
| 16931 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); |
| 16932 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); |
| 16933 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*); |
| 16934 SQLITE_PRIVATE const char *sqlite3JournalModename(int); |
| 16935 #ifndef SQLITE_OMIT_WAL |
| 16936 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*); |
| 16937 SQLITE_PRIVATE int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); |
| 16938 #endif |
| 16939 #ifndef SQLITE_OMIT_CTE |
| 16940 SQLITE_PRIVATE With *sqlite3WithAdd(Parse*,With*,Token*,ExprList*,Select*); |
| 16941 SQLITE_PRIVATE void sqlite3WithDelete(sqlite3*,With*); |
| 16942 SQLITE_PRIVATE void sqlite3WithPush(Parse*, With*, u8); |
| 16943 #else |
| 16944 #define sqlite3WithPush(x,y,z) |
| 16945 #define sqlite3WithDelete(x,y) |
| 16946 #endif |
| 16947 |
| 16948 /* Declarations for functions in fkey.c. All of these are replaced by |
| 16949 ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign |
| 16950 ** key functionality is available. If OMIT_TRIGGER is defined but |
| 16951 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In |
| 16952 ** this case foreign keys are parsed, but no other functionality is |
| 16953 ** provided (enforcement of FK constraints requires the triggers sub-system). |
| 16954 */ |
| 16955 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 16956 SQLITE_PRIVATE void sqlite3FkCheck(Parse*, Table*, int, int, int*, int); |
| 16957 SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*); |
| 16958 SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int
); |
| 16959 SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int); |
| 16960 SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*); |
| 16961 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *); |
| 16962 #else |
| 16963 #define sqlite3FkActions(a,b,c,d,e,f) |
| 16964 #define sqlite3FkCheck(a,b,c,d,e,f) |
| 16965 #define sqlite3FkDropTable(a,b,c) |
| 16966 #define sqlite3FkOldmask(a,b) 0 |
| 16967 #define sqlite3FkRequired(a,b,c,d) 0 |
| 16968 #define sqlite3FkReferences(a) 0 |
| 16969 #endif |
| 16970 #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 16971 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*); |
| 16972 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); |
| 16973 #else |
| 16974 #define sqlite3FkDelete(a,b) |
| 16975 #define sqlite3FkLocateIndex(a,b,c,d,e) |
| 16976 #endif |
| 16977 |
| 16978 |
| 16979 /* |
| 16980 ** Available fault injectors. Should be numbered beginning with 0. |
| 16981 */ |
| 16982 #define SQLITE_FAULTINJECTOR_MALLOC 0 |
| 16983 #define SQLITE_FAULTINJECTOR_COUNT 1 |
| 16984 |
| 16985 /* |
| 16986 ** The interface to the code in fault.c used for identifying "benign" |
| 16987 ** malloc failures. This is only present if SQLITE_UNTESTABLE |
| 16988 ** is not defined. |
| 16989 */ |
| 16990 #ifndef SQLITE_UNTESTABLE |
| 16991 SQLITE_PRIVATE void sqlite3BeginBenignMalloc(void); |
| 16992 SQLITE_PRIVATE void sqlite3EndBenignMalloc(void); |
| 16993 #else |
| 16994 #define sqlite3BeginBenignMalloc() |
| 16995 #define sqlite3EndBenignMalloc() |
| 16996 #endif |
| 16997 |
| 16998 /* |
| 16999 ** Allowed return values from sqlite3FindInIndex() |
| 17000 */ |
| 17001 #define IN_INDEX_ROWID 1 /* Search the rowid of the table */ |
| 17002 #define IN_INDEX_EPH 2 /* Search an ephemeral b-tree */ |
| 17003 #define IN_INDEX_INDEX_ASC 3 /* Existing index ASCENDING */ |
| 17004 #define IN_INDEX_INDEX_DESC 4 /* Existing index DESCENDING */ |
| 17005 #define IN_INDEX_NOOP 5 /* No table available. Use comparisons */ |
| 17006 /* |
| 17007 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex(). |
| 17008 */ |
| 17009 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */ |
| 17010 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */ |
| 17011 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */ |
| 17012 SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*); |
| 17013 |
| 17014 SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file
*, int, int); |
| 17015 SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *); |
| 17016 #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 17017 SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *); |
| 17018 #endif |
| 17019 |
| 17020 SQLITE_PRIVATE int sqlite3JournalIsInMemory(sqlite3_file *p); |
| 17021 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *); |
| 17022 |
| 17023 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p); |
| 17024 #if SQLITE_MAX_EXPR_DEPTH>0 |
| 17025 SQLITE_PRIVATE int sqlite3SelectExprHeight(Select *); |
| 17026 SQLITE_PRIVATE int sqlite3ExprCheckHeight(Parse*, int); |
| 17027 #else |
| 17028 #define sqlite3SelectExprHeight(x) 0 |
| 17029 #define sqlite3ExprCheckHeight(x,y) |
| 17030 #endif |
| 17031 |
| 17032 SQLITE_PRIVATE u32 sqlite3Get4byte(const u8*); |
| 17033 SQLITE_PRIVATE void sqlite3Put4byte(u8*, u32); |
| 17034 |
| 17035 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY |
| 17036 SQLITE_PRIVATE void sqlite3ConnectionBlocked(sqlite3 *, sqlite3 *); |
| 17037 SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db); |
| 17038 SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db); |
| 17039 #else |
| 17040 #define sqlite3ConnectionBlocked(x,y) |
| 17041 #define sqlite3ConnectionUnlocked(x) |
| 17042 #define sqlite3ConnectionClosed(x) |
| 17043 #endif |
| 17044 |
| 17045 #ifdef SQLITE_DEBUG |
| 17046 SQLITE_PRIVATE void sqlite3ParserTrace(FILE*, char *); |
| 17047 #endif |
| 17048 |
| 17049 /* |
| 17050 ** If the SQLITE_ENABLE IOTRACE exists then the global variable |
| 17051 ** sqlite3IoTrace is a pointer to a printf-like routine used to |
| 17052 ** print I/O tracing messages. |
| 17053 */ |
| 17054 #ifdef SQLITE_ENABLE_IOTRACE |
| 17055 # define IOTRACE(A) if( sqlite3IoTrace ){ sqlite3IoTrace A; } |
| 17056 SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe*); |
| 17057 SQLITE_API SQLITE_EXTERN void (SQLITE_CDECL *sqlite3IoTrace)(const char*,...); |
| 17058 #else |
| 17059 # define IOTRACE(A) |
| 17060 # define sqlite3VdbeIOTraceSql(X) |
| 17061 #endif |
| 17062 |
| 17063 /* |
| 17064 ** These routines are available for the mem2.c debugging memory allocator |
| 17065 ** only. They are used to verify that different "types" of memory |
| 17066 ** allocations are properly tracked by the system. |
| 17067 ** |
| 17068 ** sqlite3MemdebugSetType() sets the "type" of an allocation to one of |
| 17069 ** the MEMTYPE_* macros defined below. The type must be a bitmask with |
| 17070 ** a single bit set. |
| 17071 ** |
| 17072 ** sqlite3MemdebugHasType() returns true if any of the bits in its second |
| 17073 ** argument match the type set by the previous sqlite3MemdebugSetType(). |
| 17074 ** sqlite3MemdebugHasType() is intended for use inside assert() statements. |
| 17075 ** |
| 17076 ** sqlite3MemdebugNoType() returns true if none of the bits in its second |
| 17077 ** argument match the type set by the previous sqlite3MemdebugSetType(). |
| 17078 ** |
| 17079 ** Perhaps the most important point is the difference between MEMTYPE_HEAP |
| 17080 ** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means |
| 17081 ** it might have been allocated by lookaside, except the allocation was |
| 17082 ** too large or lookaside was already full. It is important to verify |
| 17083 ** that allocations that might have been satisfied by lookaside are not |
| 17084 ** passed back to non-lookaside free() routines. Asserts such as the |
| 17085 ** example above are placed on the non-lookaside free() routines to verify |
| 17086 ** this constraint. |
| 17087 ** |
| 17088 ** All of this is no-op for a production build. It only comes into |
| 17089 ** play when the SQLITE_MEMDEBUG compile-time option is used. |
| 17090 */ |
| 17091 #ifdef SQLITE_MEMDEBUG |
| 17092 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8); |
| 17093 SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8); |
| 17094 SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8); |
| 17095 #else |
| 17096 # define sqlite3MemdebugSetType(X,Y) /* no-op */ |
| 17097 # define sqlite3MemdebugHasType(X,Y) 1 |
| 17098 # define sqlite3MemdebugNoType(X,Y) 1 |
| 17099 #endif |
| 17100 #define MEMTYPE_HEAP 0x01 /* General heap allocations */ |
| 17101 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */ |
| 17102 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */ |
| 17103 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */ |
| 17104 |
| 17105 /* |
| 17106 ** Threading interface |
| 17107 */ |
| 17108 #if SQLITE_MAX_WORKER_THREADS>0 |
| 17109 SQLITE_PRIVATE int sqlite3ThreadCreate(SQLiteThread**,void*(*)(void*),void*); |
| 17110 SQLITE_PRIVATE int sqlite3ThreadJoin(SQLiteThread*, void**); |
| 17111 #endif |
| 17112 |
| 17113 #if defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST) |
| 17114 SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3*); |
| 17115 #endif |
| 17116 |
| 17117 SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr); |
| 17118 SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr); |
| 17119 SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int); |
| 17120 SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int); |
| 17121 SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*); |
| 17122 |
| 17123 #endif /* SQLITEINT_H */ |
| 17124 |
| 17125 /************** End of sqliteInt.h *******************************************/ |
| 17126 /************** Begin file global.c ******************************************/ |
| 17127 /* |
| 17128 ** 2008 June 13 |
| 17129 ** |
| 17130 ** The author disclaims copyright to this source code. In place of |
| 17131 ** a legal notice, here is a blessing: |
| 17132 ** |
| 17133 ** May you do good and not evil. |
| 17134 ** May you find forgiveness for yourself and forgive others. |
| 17135 ** May you share freely, never taking more than you give. |
| 17136 ** |
| 17137 ************************************************************************* |
| 17138 ** |
| 17139 ** This file contains definitions of global variables and constants. |
| 17140 */ |
| 17141 /* #include "sqliteInt.h" */ |
| 17142 |
| 17143 /* An array to map all upper-case characters into their corresponding |
| 17144 ** lower-case character. |
| 17145 ** |
| 17146 ** SQLite only considers US-ASCII (or EBCDIC) characters. We do not |
| 17147 ** handle case conversions for the UTF character set since the tables |
| 17148 ** involved are nearly as big or bigger than SQLite itself. |
| 17149 */ |
| 17150 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[] = { |
| 17151 #ifdef SQLITE_ASCII |
| 17152 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, |
| 17153 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, |
| 17154 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 17155 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103, |
| 17156 104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121, |
| 17157 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107, |
| 17158 108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125, |
| 17159 126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, |
| 17160 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161, |
| 17161 162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179, |
| 17162 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197, |
| 17163 198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215, |
| 17164 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233, |
| 17165 234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251, |
| 17166 252,253,254,255 |
| 17167 #endif |
| 17168 #ifdef SQLITE_EBCDIC |
| 17169 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */ |
| 17170 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, /* 1x */ |
| 17171 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 2x */ |
| 17172 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, /* 3x */ |
| 17173 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, /* 4x */ |
| 17174 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* 5x */ |
| 17175 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, /* 6x */ |
| 17176 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, /* 7x */ |
| 17177 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, /* 8x */ |
| 17178 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, /* 9x */ |
| 17179 160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175, /* Ax */ |
| 17180 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, /* Bx */ |
| 17181 192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207, /* Cx */ |
| 17182 208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223, /* Dx */ |
| 17183 224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */ |
| 17184 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */ |
| 17185 #endif |
| 17186 }; |
| 17187 |
| 17188 /* |
| 17189 ** The following 256 byte lookup table is used to support SQLites built-in |
| 17190 ** equivalents to the following standard library functions: |
| 17191 ** |
| 17192 ** isspace() 0x01 |
| 17193 ** isalpha() 0x02 |
| 17194 ** isdigit() 0x04 |
| 17195 ** isalnum() 0x06 |
| 17196 ** isxdigit() 0x08 |
| 17197 ** toupper() 0x20 |
| 17198 ** SQLite identifier character 0x40 |
| 17199 ** Quote character 0x80 |
| 17200 ** |
| 17201 ** Bit 0x20 is set if the mapped character requires translation to upper |
| 17202 ** case. i.e. if the character is a lower-case ASCII character. |
| 17203 ** If x is a lower-case ASCII character, then its upper-case equivalent |
| 17204 ** is (x - 0x20). Therefore toupper() can be implemented as: |
| 17205 ** |
| 17206 ** (x & ~(map[x]&0x20)) |
| 17207 ** |
| 17208 ** The equivalent of tolower() is implemented using the sqlite3UpperToLower[] |
| 17209 ** array. tolower() is used more often than toupper() by SQLite. |
| 17210 ** |
| 17211 ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an |
| 17212 ** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any |
| 17213 ** non-ASCII UTF character. Hence the test for whether or not a character is |
| 17214 ** part of an identifier is 0x46. |
| 17215 */ |
| 17216 #ifdef SQLITE_ASCII |
| 17217 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = { |
| 17218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */ |
| 17219 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */ |
| 17220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */ |
| 17221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */ |
| 17222 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */ |
| 17223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */ |
| 17224 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */ |
| 17225 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */ |
| 17226 |
| 17227 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */ |
| 17228 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */ |
| 17229 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */ |
| 17230 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */ |
| 17231 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */ |
| 17232 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */ |
| 17233 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */ |
| 17234 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */ |
| 17235 |
| 17236 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */ |
| 17237 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 88..8f ........ */ |
| 17238 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 90..97 ........ */ |
| 17239 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 98..9f ........ */ |
| 17240 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a0..a7 ........ */ |
| 17241 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* a8..af ........ */ |
| 17242 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b0..b7 ........ */ |
| 17243 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* b8..bf ........ */ |
| 17244 |
| 17245 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c0..c7 ........ */ |
| 17246 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* c8..cf ........ */ |
| 17247 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d0..d7 ........ */ |
| 17248 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* d8..df ........ */ |
| 17249 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */ |
| 17250 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */ |
| 17251 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */ |
| 17252 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */ |
| 17253 }; |
| 17254 #endif |
| 17255 |
| 17256 /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards |
| 17257 ** compatibility for legacy applications, the URI filename capability is |
| 17258 ** disabled by default. |
| 17259 ** |
| 17260 ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled |
| 17261 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 17262 ** |
| 17263 ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 17264 ** disabled. The default value may be changed by compiling with the |
| 17265 ** SQLITE_USE_URI symbol defined. |
| 17266 */ |
| 17267 #ifndef SQLITE_USE_URI |
| 17268 # define SQLITE_USE_URI 0 |
| 17269 #endif |
| 17270 |
| 17271 /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 17272 ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 17273 ** that compile-time option is omitted. |
| 17274 */ |
| 17275 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN |
| 17276 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1 |
| 17277 #endif |
| 17278 |
| 17279 /* The minimum PMA size is set to this value multiplied by the database |
| 17280 ** page size in bytes. |
| 17281 */ |
| 17282 #ifndef SQLITE_SORTER_PMASZ |
| 17283 # define SQLITE_SORTER_PMASZ 250 |
| 17284 #endif |
| 17285 |
| 17286 /* Statement journals spill to disk when their size exceeds the following |
| 17287 ** threshold (in bytes). 0 means that statement journals are created and |
| 17288 ** written to disk immediately (the default behavior for SQLite versions |
| 17289 ** before 3.12.0). -1 means always keep the entire statement journal in |
| 17290 ** memory. (The statement journal is also always held entirely in memory |
| 17291 ** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this |
| 17292 ** setting.) |
| 17293 */ |
| 17294 #ifndef SQLITE_STMTJRNL_SPILL |
| 17295 # define SQLITE_STMTJRNL_SPILL (64*1024) |
| 17296 #endif |
| 17297 |
| 17298 /* |
| 17299 ** The default lookaside-configuration, the format "SZ,N". SZ is the |
| 17300 ** number of bytes in each lookaside slot (should be a multiple of 8) |
| 17301 ** and N is the number of slots. The lookaside-configuration can be |
| 17302 ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE) |
| 17303 ** or at run-time for an individual database connection using |
| 17304 ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE); |
| 17305 */ |
| 17306 #ifndef SQLITE_DEFAULT_LOOKASIDE |
| 17307 # define SQLITE_DEFAULT_LOOKASIDE 1200,100 |
| 17308 #endif |
| 17309 |
| 17310 |
| 17311 /* |
| 17312 ** The following singleton contains the global configuration for |
| 17313 ** the SQLite library. |
| 17314 */ |
| 17315 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { |
| 17316 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */ |
| 17317 1, /* bCoreMutex */ |
| 17318 SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 17319 SQLITE_USE_URI, /* bOpenUri */ |
| 17320 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
| 17321 0x7ffffffe, /* mxStrlen */ |
| 17322 0, /* neverCorrupt */ |
| 17323 SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */ |
| 17324 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */ |
| 17325 {0,0,0,0,0,0,0,0}, /* m */ |
| 17326 {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| 17327 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */ |
| 17328 (void*)0, /* pHeap */ |
| 17329 0, /* nHeap */ |
| 17330 0, 0, /* mnHeap, mxHeap */ |
| 17331 SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */ |
| 17332 SQLITE_MAX_MMAP_SIZE, /* mxMmap */ |
| 17333 (void*)0, /* pScratch */ |
| 17334 0, /* szScratch */ |
| 17335 0, /* nScratch */ |
| 17336 (void*)0, /* pPage */ |
| 17337 0, /* szPage */ |
| 17338 SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */ |
| 17339 0, /* mxParserStack */ |
| 17340 0, /* sharedCacheEnabled */ |
| 17341 SQLITE_SORTER_PMASZ, /* szPma */ |
| 17342 /* All the rest should always be initialized to zero */ |
| 17343 0, /* isInit */ |
| 17344 0, /* inProgress */ |
| 17345 0, /* isMutexInit */ |
| 17346 0, /* isMallocInit */ |
| 17347 0, /* isPCacheInit */ |
| 17348 0, /* nRefInitMutex */ |
| 17349 0, /* pInitMutex */ |
| 17350 0, /* xLog */ |
| 17351 0, /* pLogArg */ |
| 17352 #ifdef SQLITE_ENABLE_SQLLOG |
| 17353 0, /* xSqllog */ |
| 17354 0, /* pSqllogArg */ |
| 17355 #endif |
| 17356 #ifdef SQLITE_VDBE_COVERAGE |
| 17357 0, /* xVdbeBranch */ |
| 17358 0, /* pVbeBranchArg */ |
| 17359 #endif |
| 17360 #ifndef SQLITE_UNTESTABLE |
| 17361 0, /* xTestCallback */ |
| 17362 #endif |
| 17363 0, /* bLocaltimeFault */ |
| 17364 0x7ffffffe /* iOnceResetThreshold */ |
| 17365 }; |
| 17366 |
| 17367 /* |
| 17368 ** Hash table for global functions - functions common to all |
| 17369 ** database connections. After initialization, this table is |
| 17370 ** read-only. |
| 17371 */ |
| 17372 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions; |
| 17373 |
| 17374 /* |
| 17375 ** Constant tokens for values 0 and 1. |
| 17376 */ |
| 17377 SQLITE_PRIVATE const Token sqlite3IntTokens[] = { |
| 17378 { "0", 1 }, |
| 17379 { "1", 1 } |
| 17380 }; |
| 17381 |
| 17382 |
| 17383 /* |
| 17384 ** The value of the "pending" byte must be 0x40000000 (1 byte past the |
| 17385 ** 1-gibabyte boundary) in a compatible database. SQLite never uses |
| 17386 ** the database page that contains the pending byte. It never attempts |
| 17387 ** to read or write that page. The pending byte page is set aside |
| 17388 ** for use by the VFS layers as space for managing file locks. |
| 17389 ** |
| 17390 ** During testing, it is often desirable to move the pending byte to |
| 17391 ** a different position in the file. This allows code that has to |
| 17392 ** deal with the pending byte to run on files that are much smaller |
| 17393 ** than 1 GiB. The sqlite3_test_control() interface can be used to |
| 17394 ** move the pending byte. |
| 17395 ** |
| 17396 ** IMPORTANT: Changing the pending byte to any value other than |
| 17397 ** 0x40000000 results in an incompatible database file format! |
| 17398 ** Changing the pending byte during operation will result in undefined |
| 17399 ** and incorrect behavior. |
| 17400 */ |
| 17401 #ifndef SQLITE_OMIT_WSD |
| 17402 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000; |
| 17403 #endif |
| 17404 |
| 17405 /* #include "opcodes.h" */ |
| 17406 /* |
| 17407 ** Properties of opcodes. The OPFLG_INITIALIZER macro is |
| 17408 ** created by mkopcodeh.awk during compilation. Data is obtained |
| 17409 ** from the comments following the "case OP_xxxx:" statements in |
| 17410 ** the vdbe.c file. |
| 17411 */ |
| 17412 SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[] = OPFLG_INITIALIZER; |
| 17413 |
| 17414 /* |
| 17415 ** Name of the default collating sequence |
| 17416 */ |
| 17417 SQLITE_PRIVATE const char sqlite3StrBINARY[] = "BINARY"; |
| 17418 |
| 17419 /************** End of global.c **********************************************/ |
| 17420 /************** Begin file ctime.c *******************************************/ |
| 17421 /* |
| 17422 ** 2010 February 23 |
| 17423 ** |
| 17424 ** The author disclaims copyright to this source code. In place of |
| 17425 ** a legal notice, here is a blessing: |
| 17426 ** |
| 17427 ** May you do good and not evil. |
| 17428 ** May you find forgiveness for yourself and forgive others. |
| 17429 ** May you share freely, never taking more than you give. |
| 17430 ** |
| 17431 ************************************************************************* |
| 17432 ** |
| 17433 ** This file implements routines used to report what compile-time options |
| 17434 ** SQLite was built with. |
| 17435 */ |
| 17436 |
| 17437 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 17438 |
| 17439 /* #include "sqliteInt.h" */ |
| 17440 |
| 17441 /* |
| 17442 ** An array of names of all compile-time options. This array should |
| 17443 ** be sorted A-Z. |
| 17444 ** |
| 17445 ** This array looks large, but in a typical installation actually uses |
| 17446 ** only a handful of compile-time options, so most times this array is usually |
| 17447 ** rather short and uses little memory space. |
| 17448 */ |
| 17449 static const char * const azCompileOpt[] = { |
| 17450 |
| 17451 /* These macros are provided to "stringify" the value of the define |
| 17452 ** for those options in which the value is meaningful. */ |
| 17453 #define CTIMEOPT_VAL_(opt) #opt |
| 17454 #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt) |
| 17455 |
| 17456 #if SQLITE_32BIT_ROWID |
| 17457 "32BIT_ROWID", |
| 17458 #endif |
| 17459 #if SQLITE_4_BYTE_ALIGNED_MALLOC |
| 17460 "4_BYTE_ALIGNED_MALLOC", |
| 17461 #endif |
| 17462 #if SQLITE_CASE_SENSITIVE_LIKE |
| 17463 "CASE_SENSITIVE_LIKE", |
| 17464 #endif |
| 17465 #if SQLITE_CHECK_PAGES |
| 17466 "CHECK_PAGES", |
| 17467 #endif |
| 17468 #if defined(__clang__) && defined(__clang_major__) |
| 17469 "COMPILER=clang-" CTIMEOPT_VAL(__clang_major__) "." |
| 17470 CTIMEOPT_VAL(__clang_minor__) "." |
| 17471 CTIMEOPT_VAL(__clang_patchlevel__), |
| 17472 #elif defined(_MSC_VER) |
| 17473 "COMPILER=msvc-" CTIMEOPT_VAL(_MSC_VER), |
| 17474 #elif defined(__GNUC__) && defined(__VERSION__) |
| 17475 "COMPILER=gcc-" __VERSION__, |
| 17476 #endif |
| 17477 #if SQLITE_COVERAGE_TEST |
| 17478 "COVERAGE_TEST", |
| 17479 #endif |
| 17480 #if SQLITE_DEBUG |
| 17481 "DEBUG", |
| 17482 #endif |
| 17483 #if SQLITE_DEFAULT_LOCKING_MODE |
| 17484 "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), |
| 17485 #endif |
| 17486 #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc) |
| 17487 "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), |
| 17488 #endif |
| 17489 #if SQLITE_DIRECT_OVERFLOW_READ |
| 17490 "DIRECT_OVERFLOW_READ", |
| 17491 #endif |
| 17492 #if SQLITE_DISABLE_DIRSYNC |
| 17493 "DISABLE_DIRSYNC", |
| 17494 #endif |
| 17495 #if SQLITE_DISABLE_LFS |
| 17496 "DISABLE_LFS", |
| 17497 #endif |
| 17498 #if SQLITE_ENABLE_8_3_NAMES |
| 17499 "ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES), |
| 17500 #endif |
| 17501 #if SQLITE_ENABLE_API_ARMOR |
| 17502 "ENABLE_API_ARMOR", |
| 17503 #endif |
| 17504 #if SQLITE_ENABLE_ATOMIC_WRITE |
| 17505 "ENABLE_ATOMIC_WRITE", |
| 17506 #endif |
| 17507 #if SQLITE_ENABLE_CEROD |
| 17508 "ENABLE_CEROD", |
| 17509 #endif |
| 17510 #if SQLITE_ENABLE_COLUMN_METADATA |
| 17511 "ENABLE_COLUMN_METADATA", |
| 17512 #endif |
| 17513 #if SQLITE_ENABLE_DBSTAT_VTAB |
| 17514 "ENABLE_DBSTAT_VTAB", |
| 17515 #endif |
| 17516 #if SQLITE_ENABLE_EXPENSIVE_ASSERT |
| 17517 "ENABLE_EXPENSIVE_ASSERT", |
| 17518 #endif |
| 17519 #if SQLITE_ENABLE_FTS1 |
| 17520 "ENABLE_FTS1", |
| 17521 #endif |
| 17522 #if SQLITE_ENABLE_FTS2 |
| 17523 "ENABLE_FTS2", |
| 17524 #endif |
| 17525 #if SQLITE_ENABLE_FTS3 |
| 17526 "ENABLE_FTS3", |
| 17527 #endif |
| 17528 #if SQLITE_ENABLE_FTS3_PARENTHESIS |
| 17529 "ENABLE_FTS3_PARENTHESIS", |
| 17530 #endif |
| 17531 #if SQLITE_ENABLE_FTS4 |
| 17532 "ENABLE_FTS4", |
| 17533 #endif |
| 17534 #if SQLITE_ENABLE_FTS5 |
| 17535 "ENABLE_FTS5", |
| 17536 #endif |
| 17537 #if SQLITE_ENABLE_ICU |
| 17538 "ENABLE_ICU", |
| 17539 #endif |
| 17540 #if SQLITE_ENABLE_IOTRACE |
| 17541 "ENABLE_IOTRACE", |
| 17542 #endif |
| 17543 #if SQLITE_ENABLE_JSON1 |
| 17544 "ENABLE_JSON1", |
| 17545 #endif |
| 17546 #if SQLITE_ENABLE_LOAD_EXTENSION |
| 17547 "ENABLE_LOAD_EXTENSION", |
| 17548 #endif |
| 17549 #if SQLITE_ENABLE_LOCKING_STYLE |
| 17550 "ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE), |
| 17551 #endif |
| 17552 #if SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 17553 "ENABLE_MEMORY_MANAGEMENT", |
| 17554 #endif |
| 17555 #if SQLITE_ENABLE_MEMSYS3 |
| 17556 "ENABLE_MEMSYS3", |
| 17557 #endif |
| 17558 #if SQLITE_ENABLE_MEMSYS5 |
| 17559 "ENABLE_MEMSYS5", |
| 17560 #endif |
| 17561 #if SQLITE_ENABLE_OVERSIZE_CELL_CHECK |
| 17562 "ENABLE_OVERSIZE_CELL_CHECK", |
| 17563 #endif |
| 17564 #if SQLITE_ENABLE_RTREE |
| 17565 "ENABLE_RTREE", |
| 17566 #endif |
| 17567 #if defined(SQLITE_ENABLE_STAT4) |
| 17568 "ENABLE_STAT4", |
| 17569 #elif defined(SQLITE_ENABLE_STAT3) |
| 17570 "ENABLE_STAT3", |
| 17571 #endif |
| 17572 #if SQLITE_ENABLE_UNLOCK_NOTIFY |
| 17573 "ENABLE_UNLOCK_NOTIFY", |
| 17574 #endif |
| 17575 #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 17576 "ENABLE_UPDATE_DELETE_LIMIT", |
| 17577 #endif |
| 17578 #if defined(SQLITE_ENABLE_URI_00_ERROR) |
| 17579 "ENABLE_URI_00_ERROR", |
| 17580 #endif |
| 17581 #if SQLITE_HAS_CODEC |
| 17582 "HAS_CODEC", |
| 17583 #endif |
| 17584 #if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| 17585 "HAVE_ISNAN", |
| 17586 #endif |
| 17587 #if SQLITE_HOMEGROWN_RECURSIVE_MUTEX |
| 17588 "HOMEGROWN_RECURSIVE_MUTEX", |
| 17589 #endif |
| 17590 #if SQLITE_IGNORE_AFP_LOCK_ERRORS |
| 17591 "IGNORE_AFP_LOCK_ERRORS", |
| 17592 #endif |
| 17593 #if SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 17594 "IGNORE_FLOCK_LOCK_ERRORS", |
| 17595 #endif |
| 17596 #ifdef SQLITE_INT64_TYPE |
| 17597 "INT64_TYPE", |
| 17598 #endif |
| 17599 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 17600 "LIKE_DOESNT_MATCH_BLOBS", |
| 17601 #endif |
| 17602 #if SQLITE_LOCK_TRACE |
| 17603 "LOCK_TRACE", |
| 17604 #endif |
| 17605 #if defined(SQLITE_MAX_MMAP_SIZE) && !defined(SQLITE_MAX_MMAP_SIZE_xc) |
| 17606 "MAX_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_MAX_MMAP_SIZE), |
| 17607 #endif |
| 17608 #ifdef SQLITE_MAX_SCHEMA_RETRY |
| 17609 "MAX_SCHEMA_RETRY=" CTIMEOPT_VAL(SQLITE_MAX_SCHEMA_RETRY), |
| 17610 #endif |
| 17611 #if SQLITE_MEMDEBUG |
| 17612 "MEMDEBUG", |
| 17613 #endif |
| 17614 #if SQLITE_MIXED_ENDIAN_64BIT_FLOAT |
| 17615 "MIXED_ENDIAN_64BIT_FLOAT", |
| 17616 #endif |
| 17617 #if SQLITE_NO_SYNC |
| 17618 "NO_SYNC", |
| 17619 #endif |
| 17620 #if SQLITE_OMIT_ALTERTABLE |
| 17621 "OMIT_ALTERTABLE", |
| 17622 #endif |
| 17623 #if SQLITE_OMIT_ANALYZE |
| 17624 "OMIT_ANALYZE", |
| 17625 #endif |
| 17626 #if SQLITE_OMIT_ATTACH |
| 17627 "OMIT_ATTACH", |
| 17628 #endif |
| 17629 #if SQLITE_OMIT_AUTHORIZATION |
| 17630 "OMIT_AUTHORIZATION", |
| 17631 #endif |
| 17632 #if SQLITE_OMIT_AUTOINCREMENT |
| 17633 "OMIT_AUTOINCREMENT", |
| 17634 #endif |
| 17635 #if SQLITE_OMIT_AUTOINIT |
| 17636 "OMIT_AUTOINIT", |
| 17637 #endif |
| 17638 #if SQLITE_OMIT_AUTOMATIC_INDEX |
| 17639 "OMIT_AUTOMATIC_INDEX", |
| 17640 #endif |
| 17641 #if SQLITE_OMIT_AUTORESET |
| 17642 "OMIT_AUTORESET", |
| 17643 #endif |
| 17644 #if SQLITE_OMIT_AUTOVACUUM |
| 17645 "OMIT_AUTOVACUUM", |
| 17646 #endif |
| 17647 #if SQLITE_OMIT_BETWEEN_OPTIMIZATION |
| 17648 "OMIT_BETWEEN_OPTIMIZATION", |
| 17649 #endif |
| 17650 #if SQLITE_OMIT_BLOB_LITERAL |
| 17651 "OMIT_BLOB_LITERAL", |
| 17652 #endif |
| 17653 #if SQLITE_OMIT_BTREECOUNT |
| 17654 "OMIT_BTREECOUNT", |
| 17655 #endif |
| 17656 #if SQLITE_OMIT_CAST |
| 17657 "OMIT_CAST", |
| 17658 #endif |
| 17659 #if SQLITE_OMIT_CHECK |
| 17660 "OMIT_CHECK", |
| 17661 #endif |
| 17662 #if SQLITE_OMIT_COMPLETE |
| 17663 "OMIT_COMPLETE", |
| 17664 #endif |
| 17665 #if SQLITE_OMIT_COMPOUND_SELECT |
| 17666 "OMIT_COMPOUND_SELECT", |
| 17667 #endif |
| 17668 #if SQLITE_OMIT_CTE |
| 17669 "OMIT_CTE", |
| 17670 #endif |
| 17671 #if SQLITE_OMIT_DATETIME_FUNCS |
| 17672 "OMIT_DATETIME_FUNCS", |
| 17673 #endif |
| 17674 #if SQLITE_OMIT_DECLTYPE |
| 17675 "OMIT_DECLTYPE", |
| 17676 #endif |
| 17677 #if SQLITE_OMIT_DEPRECATED |
| 17678 "OMIT_DEPRECATED", |
| 17679 #endif |
| 17680 #if SQLITE_OMIT_DISKIO |
| 17681 "OMIT_DISKIO", |
| 17682 #endif |
| 17683 #if SQLITE_OMIT_EXPLAIN |
| 17684 "OMIT_EXPLAIN", |
| 17685 #endif |
| 17686 #if SQLITE_OMIT_FLAG_PRAGMAS |
| 17687 "OMIT_FLAG_PRAGMAS", |
| 17688 #endif |
| 17689 #if SQLITE_OMIT_FLOATING_POINT |
| 17690 "OMIT_FLOATING_POINT", |
| 17691 #endif |
| 17692 #if SQLITE_OMIT_FOREIGN_KEY |
| 17693 "OMIT_FOREIGN_KEY", |
| 17694 #endif |
| 17695 #if SQLITE_OMIT_GET_TABLE |
| 17696 "OMIT_GET_TABLE", |
| 17697 #endif |
| 17698 #if SQLITE_OMIT_INCRBLOB |
| 17699 "OMIT_INCRBLOB", |
| 17700 #endif |
| 17701 #if SQLITE_OMIT_INTEGRITY_CHECK |
| 17702 "OMIT_INTEGRITY_CHECK", |
| 17703 #endif |
| 17704 #if SQLITE_OMIT_LIKE_OPTIMIZATION |
| 17705 "OMIT_LIKE_OPTIMIZATION", |
| 17706 #endif |
| 17707 #if SQLITE_OMIT_LOAD_EXTENSION |
| 17708 "OMIT_LOAD_EXTENSION", |
| 17709 #endif |
| 17710 #if SQLITE_OMIT_LOCALTIME |
| 17711 "OMIT_LOCALTIME", |
| 17712 #endif |
| 17713 #if SQLITE_OMIT_LOOKASIDE |
| 17714 "OMIT_LOOKASIDE", |
| 17715 #endif |
| 17716 #if SQLITE_OMIT_MEMORYDB |
| 17717 "OMIT_MEMORYDB", |
| 17718 #endif |
| 17719 #if SQLITE_OMIT_OR_OPTIMIZATION |
| 17720 "OMIT_OR_OPTIMIZATION", |
| 17721 #endif |
| 17722 #if SQLITE_OMIT_PAGER_PRAGMAS |
| 17723 "OMIT_PAGER_PRAGMAS", |
| 17724 #endif |
| 17725 #if SQLITE_OMIT_PRAGMA |
| 17726 "OMIT_PRAGMA", |
| 17727 #endif |
| 17728 #if SQLITE_OMIT_PROGRESS_CALLBACK |
| 17729 "OMIT_PROGRESS_CALLBACK", |
| 17730 #endif |
| 17731 #if SQLITE_OMIT_QUICKBALANCE |
| 17732 "OMIT_QUICKBALANCE", |
| 17733 #endif |
| 17734 #if SQLITE_OMIT_REINDEX |
| 17735 "OMIT_REINDEX", |
| 17736 #endif |
| 17737 #if SQLITE_OMIT_SCHEMA_PRAGMAS |
| 17738 "OMIT_SCHEMA_PRAGMAS", |
| 17739 #endif |
| 17740 #if SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS |
| 17741 "OMIT_SCHEMA_VERSION_PRAGMAS", |
| 17742 #endif |
| 17743 #if SQLITE_OMIT_SHARED_CACHE |
| 17744 "OMIT_SHARED_CACHE", |
| 17745 #endif |
| 17746 #if SQLITE_OMIT_SUBQUERY |
| 17747 "OMIT_SUBQUERY", |
| 17748 #endif |
| 17749 #if SQLITE_OMIT_TCL_VARIABLE |
| 17750 "OMIT_TCL_VARIABLE", |
| 17751 #endif |
| 17752 #if SQLITE_OMIT_TEMPDB |
| 17753 "OMIT_TEMPDB", |
| 17754 #endif |
| 17755 #if SQLITE_OMIT_TRACE |
| 17756 "OMIT_TRACE", |
| 17757 #endif |
| 17758 #if SQLITE_OMIT_TRIGGER |
| 17759 "OMIT_TRIGGER", |
| 17760 #endif |
| 17761 #if SQLITE_OMIT_TRUNCATE_OPTIMIZATION |
| 17762 "OMIT_TRUNCATE_OPTIMIZATION", |
| 17763 #endif |
| 17764 #if SQLITE_OMIT_UTF16 |
| 17765 "OMIT_UTF16", |
| 17766 #endif |
| 17767 #if SQLITE_OMIT_VACUUM |
| 17768 "OMIT_VACUUM", |
| 17769 #endif |
| 17770 #if SQLITE_OMIT_VIEW |
| 17771 "OMIT_VIEW", |
| 17772 #endif |
| 17773 #if SQLITE_OMIT_VIRTUALTABLE |
| 17774 "OMIT_VIRTUALTABLE", |
| 17775 #endif |
| 17776 #if SQLITE_OMIT_WAL |
| 17777 "OMIT_WAL", |
| 17778 #endif |
| 17779 #if SQLITE_OMIT_WSD |
| 17780 "OMIT_WSD", |
| 17781 #endif |
| 17782 #if SQLITE_OMIT_XFER_OPT |
| 17783 "OMIT_XFER_OPT", |
| 17784 #endif |
| 17785 #if SQLITE_PERFORMANCE_TRACE |
| 17786 "PERFORMANCE_TRACE", |
| 17787 #endif |
| 17788 #if SQLITE_PROXY_DEBUG |
| 17789 "PROXY_DEBUG", |
| 17790 #endif |
| 17791 #if SQLITE_RTREE_INT_ONLY |
| 17792 "RTREE_INT_ONLY", |
| 17793 #endif |
| 17794 #if SQLITE_SECURE_DELETE |
| 17795 "SECURE_DELETE", |
| 17796 #endif |
| 17797 #if SQLITE_SMALL_STACK |
| 17798 "SMALL_STACK", |
| 17799 #endif |
| 17800 #if SQLITE_SOUNDEX |
| 17801 "SOUNDEX", |
| 17802 #endif |
| 17803 #if SQLITE_SYSTEM_MALLOC |
| 17804 "SYSTEM_MALLOC", |
| 17805 #endif |
| 17806 #if SQLITE_TCL |
| 17807 "TCL", |
| 17808 #endif |
| 17809 #if defined(SQLITE_TEMP_STORE) && !defined(SQLITE_TEMP_STORE_xc) |
| 17810 "TEMP_STORE=" CTIMEOPT_VAL(SQLITE_TEMP_STORE), |
| 17811 #endif |
| 17812 #if SQLITE_TEST |
| 17813 "TEST", |
| 17814 #endif |
| 17815 #if defined(SQLITE_THREADSAFE) |
| 17816 "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
| 17817 #endif |
| 17818 #if SQLITE_UNTESTABLE |
| 17819 "UNTESTABLE" |
| 17820 #endif |
| 17821 #if SQLITE_USE_ALLOCA |
| 17822 "USE_ALLOCA", |
| 17823 #endif |
| 17824 #if SQLITE_USER_AUTHENTICATION |
| 17825 "USER_AUTHENTICATION", |
| 17826 #endif |
| 17827 #if SQLITE_WIN32_MALLOC |
| 17828 "WIN32_MALLOC", |
| 17829 #endif |
| 17830 #if SQLITE_ZERO_MALLOC |
| 17831 "ZERO_MALLOC" |
| 17832 #endif |
| 17833 }; |
| 17834 |
| 17835 /* |
| 17836 ** Given the name of a compile-time option, return true if that option |
| 17837 ** was used and false if not. |
| 17838 ** |
| 17839 ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix |
| 17840 ** is not required for a match. |
| 17841 */ |
| 17842 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){ |
| 17843 int i, n; |
| 17844 |
| 17845 #if SQLITE_ENABLE_API_ARMOR |
| 17846 if( zOptName==0 ){ |
| 17847 (void)SQLITE_MISUSE_BKPT; |
| 17848 return 0; |
| 17849 } |
| 17850 #endif |
| 17851 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7; |
| 17852 n = sqlite3Strlen30(zOptName); |
| 17853 |
| 17854 /* Since ArraySize(azCompileOpt) is normally in single digits, a |
| 17855 ** linear search is adequate. No need for a binary search. */ |
| 17856 for(i=0; i<ArraySize(azCompileOpt); i++){ |
| 17857 if( sqlite3StrNICmp(zOptName, azCompileOpt[i], n)==0 |
| 17858 && sqlite3IsIdChar((unsigned char)azCompileOpt[i][n])==0 |
| 17859 ){ |
| 17860 return 1; |
| 17861 } |
| 17862 } |
| 17863 return 0; |
| 17864 } |
| 17865 |
| 17866 /* |
| 17867 ** Return the N-th compile-time option string. If N is out of range, |
| 17868 ** return a NULL pointer. |
| 17869 */ |
| 17870 SQLITE_API const char *sqlite3_compileoption_get(int N){ |
| 17871 if( N>=0 && N<ArraySize(azCompileOpt) ){ |
| 17872 return azCompileOpt[N]; |
| 17873 } |
| 17874 return 0; |
| 17875 } |
| 17876 |
| 17877 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 17878 |
| 17879 /************** End of ctime.c ***********************************************/ |
| 17880 /************** Begin file status.c ******************************************/ |
| 17881 /* |
| 17882 ** 2008 June 18 |
| 17883 ** |
| 17884 ** The author disclaims copyright to this source code. In place of |
| 17885 ** a legal notice, here is a blessing: |
| 17886 ** |
| 17887 ** May you do good and not evil. |
| 17888 ** May you find forgiveness for yourself and forgive others. |
| 17889 ** May you share freely, never taking more than you give. |
| 17890 ** |
| 17891 ************************************************************************* |
| 17892 ** |
| 17893 ** This module implements the sqlite3_status() interface and related |
| 17894 ** functionality. |
| 17895 */ |
| 17896 /* #include "sqliteInt.h" */ |
| 17897 /************** Include vdbeInt.h in the middle of status.c ******************/ |
| 17898 /************** Begin file vdbeInt.h *****************************************/ |
| 17899 /* |
| 17900 ** 2003 September 6 |
| 17901 ** |
| 17902 ** The author disclaims copyright to this source code. In place of |
| 17903 ** a legal notice, here is a blessing: |
| 17904 ** |
| 17905 ** May you do good and not evil. |
| 17906 ** May you find forgiveness for yourself and forgive others. |
| 17907 ** May you share freely, never taking more than you give. |
| 17908 ** |
| 17909 ************************************************************************* |
| 17910 ** This is the header file for information that is private to the |
| 17911 ** VDBE. This information used to all be at the top of the single |
| 17912 ** source code file "vdbe.c". When that file became too big (over |
| 17913 ** 6000 lines long) it was split up into several smaller files and |
| 17914 ** this header information was factored out. |
| 17915 */ |
| 17916 #ifndef SQLITE_VDBEINT_H |
| 17917 #define SQLITE_VDBEINT_H |
| 17918 |
| 17919 /* |
| 17920 ** The maximum number of times that a statement will try to reparse |
| 17921 ** itself before giving up and returning SQLITE_SCHEMA. |
| 17922 */ |
| 17923 #ifndef SQLITE_MAX_SCHEMA_RETRY |
| 17924 # define SQLITE_MAX_SCHEMA_RETRY 50 |
| 17925 #endif |
| 17926 |
| 17927 /* |
| 17928 ** VDBE_DISPLAY_P4 is true or false depending on whether or not the |
| 17929 ** "explain" P4 display logic is enabled. |
| 17930 */ |
| 17931 #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \ |
| 17932 || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) |
| 17933 # define VDBE_DISPLAY_P4 1 |
| 17934 #else |
| 17935 # define VDBE_DISPLAY_P4 0 |
| 17936 #endif |
| 17937 |
| 17938 /* |
| 17939 ** SQL is translated into a sequence of instructions to be |
| 17940 ** executed by a virtual machine. Each instruction is an instance |
| 17941 ** of the following structure. |
| 17942 */ |
| 17943 typedef struct VdbeOp Op; |
| 17944 |
| 17945 /* |
| 17946 ** Boolean values |
| 17947 */ |
| 17948 typedef unsigned Bool; |
| 17949 |
| 17950 /* Opaque type used by code in vdbesort.c */ |
| 17951 typedef struct VdbeSorter VdbeSorter; |
| 17952 |
| 17953 /* Elements of the linked list at Vdbe.pAuxData */ |
| 17954 typedef struct AuxData AuxData; |
| 17955 |
| 17956 /* Types of VDBE cursors */ |
| 17957 #define CURTYPE_BTREE 0 |
| 17958 #define CURTYPE_SORTER 1 |
| 17959 #define CURTYPE_VTAB 2 |
| 17960 #define CURTYPE_PSEUDO 3 |
| 17961 |
| 17962 /* |
| 17963 ** A VdbeCursor is an superclass (a wrapper) for various cursor objects: |
| 17964 ** |
| 17965 ** * A b-tree cursor |
| 17966 ** - In the main database or in an ephemeral database |
| 17967 ** - On either an index or a table |
| 17968 ** * A sorter |
| 17969 ** * A virtual table |
| 17970 ** * A one-row "pseudotable" stored in a single register |
| 17971 */ |
| 17972 typedef struct VdbeCursor VdbeCursor; |
| 17973 struct VdbeCursor { |
| 17974 u8 eCurType; /* One of the CURTYPE_* values above */ |
| 17975 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ |
| 17976 u8 nullRow; /* True if pointing to a row with no data */ |
| 17977 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 17978 u8 isTable; /* True for rowid tables. False for indexes */ |
| 17979 #ifdef SQLITE_DEBUG |
| 17980 u8 seekOp; /* Most recent seek operation on this cursor */ |
| 17981 u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */ |
| 17982 #endif |
| 17983 Bool isEphemeral:1; /* True for an ephemeral table */ |
| 17984 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */ |
| 17985 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */ |
| 17986 Btree *pBtx; /* Separate file holding temporary table */ |
| 17987 i64 seqCount; /* Sequence counter */ |
| 17988 int *aAltMap; /* Mapping from table to index column numbers */ |
| 17989 |
| 17990 /* Cached OP_Column parse information is only valid if cacheStatus matches |
| 17991 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of |
| 17992 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that |
| 17993 ** the cache is out of date. */ |
| 17994 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */ |
| 17995 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0 |
| 17996 ** if there have been no prior seeks on the cursor. */ |
| 17997 /* NB: seekResult does not distinguish between "no seeks have ever occurred |
| 17998 ** on this cursor" and "the most recent seek was an exact match". */ |
| 17999 |
| 18000 /* When a new VdbeCursor is allocated, only the fields above are zeroed. |
| 18001 ** The fields that follow are uninitialized, and must be individually |
| 18002 ** initialized prior to first use. */ |
| 18003 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */ |
| 18004 union { |
| 18005 BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */ |
| 18006 sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */ |
| 18007 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */ |
| 18008 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */ |
| 18009 } uc; |
| 18010 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ |
| 18011 u32 iHdrOffset; /* Offset to next unparsed byte of the header */ |
| 18012 Pgno pgnoRoot; /* Root page of the open btree cursor */ |
| 18013 i16 nField; /* Number of fields in the header */ |
| 18014 u16 nHdrParsed; /* Number of header fields parsed so far */ |
| 18015 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ |
| 18016 u32 *aOffset; /* Pointer to aType[nField] */ |
| 18017 const u8 *aRow; /* Data for the current row, if all on one page */ |
| 18018 u32 payloadSize; /* Total number of bytes in the record */ |
| 18019 u32 szRow; /* Byte available in aRow */ |
| 18020 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK |
| 18021 u64 maskUsed; /* Mask of columns used by this cursor */ |
| 18022 #endif |
| 18023 |
| 18024 /* 2*nField extra array elements allocated for aType[], beyond the one |
| 18025 ** static element declared in the structure. nField total array slots for |
| 18026 ** aType[] and nField+1 array slots for aOffset[] */ |
| 18027 u32 aType[1]; /* Type values record decode. MUST BE LAST */ |
| 18028 }; |
| 18029 |
| 18030 |
| 18031 /* |
| 18032 ** A value for VdbeCursor.cacheStatus that means the cache is always invalid. |
| 18033 */ |
| 18034 #define CACHE_STALE 0 |
| 18035 |
| 18036 /* |
| 18037 ** When a sub-program is executed (OP_Program), a structure of this type |
| 18038 ** is allocated to store the current value of the program counter, as |
| 18039 ** well as the current memory cell array and various other frame specific |
| 18040 ** values stored in the Vdbe struct. When the sub-program is finished, |
| 18041 ** these values are copied back to the Vdbe from the VdbeFrame structure, |
| 18042 ** restoring the state of the VM to as it was before the sub-program |
| 18043 ** began executing. |
| 18044 ** |
| 18045 ** The memory for a VdbeFrame object is allocated and managed by a memory |
| 18046 ** cell in the parent (calling) frame. When the memory cell is deleted or |
| 18047 ** overwritten, the VdbeFrame object is not freed immediately. Instead, it |
| 18048 ** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame |
| 18049 ** list is deleted when the VM is reset in VdbeHalt(). The reason for doing |
| 18050 ** this instead of deleting the VdbeFrame immediately is to avoid recursive |
| 18051 ** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the |
| 18052 ** child frame are released. |
| 18053 ** |
| 18054 ** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is |
| 18055 ** set to NULL if the currently executing frame is the main program. |
| 18056 */ |
| 18057 typedef struct VdbeFrame VdbeFrame; |
| 18058 struct VdbeFrame { |
| 18059 Vdbe *v; /* VM this frame belongs to */ |
| 18060 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */ |
| 18061 Op *aOp; /* Program instructions for parent frame */ |
| 18062 i64 *anExec; /* Event counters from parent frame */ |
| 18063 Mem *aMem; /* Array of memory cells for parent frame */ |
| 18064 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ |
| 18065 void *token; /* Copy of SubProgram.token */ |
| 18066 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ |
| 18067 AuxData *pAuxData; /* Linked list of auxdata allocations */ |
| 18068 int nCursor; /* Number of entries in apCsr */ |
| 18069 int pc; /* Program Counter in parent (calling) frame */ |
| 18070 int nOp; /* Size of aOp array */ |
| 18071 int nMem; /* Number of entries in aMem */ |
| 18072 int nChildMem; /* Number of memory cells for child frame */ |
| 18073 int nChildCsr; /* Number of cursors for child frame */ |
| 18074 int nChange; /* Statement changes (Vdbe.nChange) */ |
| 18075 int nDbChange; /* Value of db->nChange */ |
| 18076 }; |
| 18077 |
| 18078 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) |
| 18079 |
| 18080 /* |
| 18081 ** Internally, the vdbe manipulates nearly all SQL values as Mem |
| 18082 ** structures. Each Mem struct may cache multiple representations (string, |
| 18083 ** integer etc.) of the same value. |
| 18084 */ |
| 18085 struct Mem { |
| 18086 union MemValue { |
| 18087 double r; /* Real value used when MEM_Real is set in flags */ |
| 18088 i64 i; /* Integer value used when MEM_Int is set in flags */ |
| 18089 int nZero; /* Used when bit MEM_Zero is set in flags */ |
| 18090 FuncDef *pDef; /* Used only when flags==MEM_Agg */ |
| 18091 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */ |
| 18092 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */ |
| 18093 } u; |
| 18094 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 18095 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 18096 u8 eSubtype; /* Subtype for this value */ |
| 18097 int n; /* Number of characters in string value, excluding '\0' */ |
| 18098 char *z; /* String or BLOB value */ |
| 18099 /* ShallowCopy only needs to copy the information above */ |
| 18100 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ |
| 18101 int szMalloc; /* Size of the zMalloc allocation */ |
| 18102 u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ |
| 18103 sqlite3 *db; /* The associated database connection */ |
| 18104 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ |
| 18105 #ifdef SQLITE_DEBUG |
| 18106 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ |
| 18107 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */ |
| 18108 #endif |
| 18109 }; |
| 18110 |
| 18111 /* |
| 18112 ** Size of struct Mem not including the Mem.zMalloc member or anything that |
| 18113 ** follows. |
| 18114 */ |
| 18115 #define MEMCELLSIZE offsetof(Mem,zMalloc) |
| 18116 |
| 18117 /* One or more of the following flags are set to indicate the validOK |
| 18118 ** representations of the value stored in the Mem struct. |
| 18119 ** |
| 18120 ** If the MEM_Null flag is set, then the value is an SQL NULL value. |
| 18121 ** No other flags may be set in this case. |
| 18122 ** |
| 18123 ** If the MEM_Str flag is set then Mem.z points at a string representation. |
| 18124 ** Usually this is encoded in the same unicode encoding as the main |
| 18125 ** database (see below for exceptions). If the MEM_Term flag is also |
| 18126 ** set, then the string is nul terminated. The MEM_Int and MEM_Real |
| 18127 ** flags may coexist with the MEM_Str flag. |
| 18128 */ |
| 18129 #define MEM_Null 0x0001 /* Value is NULL */ |
| 18130 #define MEM_Str 0x0002 /* Value is a string */ |
| 18131 #define MEM_Int 0x0004 /* Value is an integer */ |
| 18132 #define MEM_Real 0x0008 /* Value is a real number */ |
| 18133 #define MEM_Blob 0x0010 /* Value is a BLOB */ |
| 18134 #define MEM_AffMask 0x001f /* Mask of affinity bits */ |
| 18135 #define MEM_RowSet 0x0020 /* Value is a RowSet object */ |
| 18136 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */ |
| 18137 #define MEM_Undefined 0x0080 /* Value is undefined */ |
| 18138 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ |
| 18139 #define MEM_TypeMask 0x81ff /* Mask of type bits */ |
| 18140 |
| 18141 |
| 18142 /* Whenever Mem contains a valid string or blob representation, one of |
| 18143 ** the following flags must be set to determine the memory management |
| 18144 ** policy for Mem.z. The MEM_Term flag tells us whether or not the |
| 18145 ** string is \000 or \u0000 terminated |
| 18146 */ |
| 18147 #define MEM_Term 0x0200 /* String rep is nul terminated */ |
| 18148 #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */ |
| 18149 #define MEM_Static 0x0800 /* Mem.z points to a static string */ |
| 18150 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ |
| 18151 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */ |
| 18152 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */ |
| 18153 #define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */ |
| 18154 #ifdef SQLITE_OMIT_INCRBLOB |
| 18155 #undef MEM_Zero |
| 18156 #define MEM_Zero 0x0000 |
| 18157 #endif |
| 18158 |
| 18159 /* Return TRUE if Mem X contains dynamically allocated content - anything |
| 18160 ** that needs to be deallocated to avoid a leak. |
| 18161 */ |
| 18162 #define VdbeMemDynamic(X) \ |
| 18163 (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0) |
| 18164 |
| 18165 /* |
| 18166 ** Clear any existing type flags from a Mem and replace them with f |
| 18167 */ |
| 18168 #define MemSetTypeFlag(p, f) \ |
| 18169 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f) |
| 18170 |
| 18171 /* |
| 18172 ** Return true if a memory cell is not marked as invalid. This macro |
| 18173 ** is for use inside assert() statements only. |
| 18174 */ |
| 18175 #ifdef SQLITE_DEBUG |
| 18176 #define memIsValid(M) ((M)->flags & MEM_Undefined)==0 |
| 18177 #endif |
| 18178 |
| 18179 /* |
| 18180 ** Each auxiliary data pointer stored by a user defined function |
| 18181 ** implementation calling sqlite3_set_auxdata() is stored in an instance |
| 18182 ** of this structure. All such structures associated with a single VM |
| 18183 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed |
| 18184 ** when the VM is halted (if not before). |
| 18185 */ |
| 18186 struct AuxData { |
| 18187 int iOp; /* Instruction number of OP_Function opcode */ |
| 18188 int iArg; /* Index of function argument. */ |
| 18189 void *pAux; /* Aux data pointer */ |
| 18190 void (*xDelete)(void *); /* Destructor for the aux data */ |
| 18191 AuxData *pNext; /* Next element in list */ |
| 18192 }; |
| 18193 |
| 18194 /* |
| 18195 ** The "context" argument for an installable function. A pointer to an |
| 18196 ** instance of this structure is the first argument to the routines used |
| 18197 ** implement the SQL functions. |
| 18198 ** |
| 18199 ** There is a typedef for this structure in sqlite.h. So all routines, |
| 18200 ** even the public interface to SQLite, can use a pointer to this structure. |
| 18201 ** But this file is the only place where the internal details of this |
| 18202 ** structure are known. |
| 18203 ** |
| 18204 ** This structure is defined inside of vdbeInt.h because it uses substructures |
| 18205 ** (Mem) which are only defined there. |
| 18206 */ |
| 18207 struct sqlite3_context { |
| 18208 Mem *pOut; /* The return value is stored here */ |
| 18209 FuncDef *pFunc; /* Pointer to function information */ |
| 18210 Mem *pMem; /* Memory cell used to store aggregate context */ |
| 18211 Vdbe *pVdbe; /* The VM that owns this context */ |
| 18212 int iOp; /* Instruction number of OP_Function */ |
| 18213 int isError; /* Error code returned by the function. */ |
| 18214 u8 skipFlag; /* Skip accumulator loading if true */ |
| 18215 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ |
| 18216 u8 argc; /* Number of arguments */ |
| 18217 sqlite3_value *argv[1]; /* Argument set */ |
| 18218 }; |
| 18219 |
| 18220 /* A bitfield type for use inside of structures. Always follow with :N where |
| 18221 ** N is the number of bits. |
| 18222 */ |
| 18223 typedef unsigned bft; /* Bit Field Type */ |
| 18224 |
| 18225 typedef struct ScanStatus ScanStatus; |
| 18226 struct ScanStatus { |
| 18227 int addrExplain; /* OP_Explain for loop */ |
| 18228 int addrLoop; /* Address of "loops" counter */ |
| 18229 int addrVisit; /* Address of "rows visited" counter */ |
| 18230 int iSelectID; /* The "Select-ID" for this loop */ |
| 18231 LogEst nEst; /* Estimated output rows per loop */ |
| 18232 char *zName; /* Name of table or index */ |
| 18233 }; |
| 18234 |
| 18235 /* |
| 18236 ** An instance of the virtual machine. This structure contains the complete |
| 18237 ** state of the virtual machine. |
| 18238 ** |
| 18239 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() |
| 18240 ** is really a pointer to an instance of this structure. |
| 18241 */ |
| 18242 struct Vdbe { |
| 18243 sqlite3 *db; /* The database connection that owns this statement */ |
| 18244 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 18245 Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 18246 ynVar nVar; /* Number of entries in aVar[] */ |
| 18247 u32 magic; /* Magic number for sanity checking */ |
| 18248 int nMem; /* Number of memory locations currently allocated */ |
| 18249 int nCursor; /* Number of slots in apCsr[] */ |
| 18250 u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 18251 int pc; /* The program counter */ |
| 18252 int rc; /* Value to return */ |
| 18253 int nChange; /* Number of db changes made since last reset */ |
| 18254 int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 18255 i64 iCurrentTime; /* Value of julianday('now') for this statement */ |
| 18256 i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 18257 i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| 18258 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */ |
| 18259 |
| 18260 /* When allocating a new Vdbe object, all of the fields below should be |
| 18261 ** initialized to zero or NULL */ |
| 18262 |
| 18263 Op *aOp; /* Space to hold the virtual machine's program */ |
| 18264 Mem *aMem; /* The memory locations */ |
| 18265 Mem **apArg; /* Arguments to currently executing user function */ |
| 18266 Mem *aColName; /* Column names to return */ |
| 18267 Mem *pResultSet; /* Pointer to an array of results */ |
| 18268 char *zErrMsg; /* Error message written here */ |
| 18269 VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| 18270 Mem *aVar; /* Values for the OP_Variable opcode. */ |
| 18271 VList *pVList; /* Name of variables */ |
| 18272 #ifndef SQLITE_OMIT_TRACE |
| 18273 i64 startTime; /* Time when query started - used for profiling */ |
| 18274 #endif |
| 18275 int nOp; /* Number of instructions in the program */ |
| 18276 #ifdef SQLITE_DEBUG |
| 18277 int rcApp; /* errcode set by sqlite3_result_error_code() */ |
| 18278 #endif |
| 18279 u16 nResColumn; /* Number of columns in one row of the result set */ |
| 18280 u8 errorAction; /* Recovery action to do in case of an error */ |
| 18281 u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 18282 bft expired:1; /* True if the VM needs to be recompiled */ |
| 18283 bft doingRerun:1; /* True if rerunning after an auto-reprepare */ |
| 18284 bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 18285 bft changeCntOn:1; /* True to update the change-counter */ |
| 18286 bft runOnlyOnce:1; /* Automatically expire on reset */ |
| 18287 bft usesStmtJournal:1; /* True if uses a statement journal */ |
| 18288 bft readOnly:1; /* True for statements that do not write */ |
| 18289 bft bIsReader:1; /* True for statements that read */ |
| 18290 bft isPrepareV2:1; /* True if prepared with prepare_v2() */ |
| 18291 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 18292 yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| 18293 u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */ |
| 18294 char *zSql; /* Text of the SQL statement that generated this */ |
| 18295 void *pFree; /* Free this when deleting the vdbe */ |
| 18296 VdbeFrame *pFrame; /* Parent frame */ |
| 18297 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */ |
| 18298 int nFrame; /* Number of frames in pFrame list */ |
| 18299 u32 expmask; /* Binding to these vars invalidates VM */ |
| 18300 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ |
| 18301 AuxData *pAuxData; /* Linked list of auxdata allocations */ |
| 18302 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 18303 i64 *anExec; /* Number of times each op has been executed */ |
| 18304 int nScan; /* Entries in aScan[] */ |
| 18305 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */ |
| 18306 #endif |
| 18307 }; |
| 18308 |
| 18309 /* |
| 18310 ** The following are allowed values for Vdbe.magic |
| 18311 */ |
| 18312 #define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */ |
| 18313 #define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */ |
| 18314 #define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */ |
| 18315 #define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */ |
| 18316 #define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */ |
| 18317 |
| 18318 /* |
| 18319 ** Structure used to store the context required by the |
| 18320 ** sqlite3_preupdate_*() API functions. |
| 18321 */ |
| 18322 struct PreUpdate { |
| 18323 Vdbe *v; |
| 18324 VdbeCursor *pCsr; /* Cursor to read old values from */ |
| 18325 int op; /* One of SQLITE_INSERT, UPDATE, DELETE */ |
| 18326 u8 *aRecord; /* old.* database record */ |
| 18327 KeyInfo keyinfo; |
| 18328 UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */ |
| 18329 UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */ |
| 18330 int iNewReg; /* Register for new.* values */ |
| 18331 i64 iKey1; /* First key value passed to hook */ |
| 18332 i64 iKey2; /* Second key value passed to hook */ |
| 18333 Mem *aNew; /* Array of new.* values */ |
| 18334 Table *pTab; /* Schema object being upated */ |
| 18335 Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 18336 }; |
| 18337 |
| 18338 /* |
| 18339 ** Function prototypes |
| 18340 */ |
| 18341 SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| 18342 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); |
| 18343 void sqliteVdbePopStack(Vdbe*,int); |
| 18344 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*); |
| 18345 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); |
| 18346 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 18347 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*); |
| 18348 #endif |
| 18349 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 18350 SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); |
| 18351 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int, u32*); |
| 18352 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 18353 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 18354 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int); |
| 18355 |
| 18356 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 18357 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*
,int*); |
| 18358 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*); |
| 18359 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*); |
| 18360 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*); |
| 18361 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*); |
| 18362 SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int); |
| 18363 SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*); |
| 18364 SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*); |
| 18365 SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int); |
| 18366 SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem*, Mem*); |
| 18367 SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*); |
| 18368 SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void
*)); |
| 18369 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64); |
| 18370 #ifdef SQLITE_OMIT_FLOATING_POINT |
| 18371 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64 |
| 18372 #else |
| 18373 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem*, double); |
| 18374 #endif |
| 18375 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem*,sqlite3*,u16); |
| 18376 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem*); |
| 18377 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem*,int); |
| 18378 SQLITE_PRIVATE void sqlite3VdbeMemSetRowSet(Mem*); |
| 18379 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem*); |
| 18380 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem*, u8, u8); |
| 18381 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem*); |
| 18382 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*); |
| 18383 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); |
| 18384 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 18385 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 18386 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 18387 SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8); |
| 18388 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); |
| 18389 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 18390 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 18391 SQLITE_PRIVATE const char *sqlite3OpcodeName(int); |
| 18392 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 18393 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n); |
| 18394 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 18395 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 18396 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 18397 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 18398 SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(Vdbe*,VdbeCursor*,int,const char*,T
able*,i64,int); |
| 18399 #endif |
| 18400 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p); |
| 18401 |
| 18402 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *); |
| 18403 SQLITE_PRIVATE void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *); |
| 18404 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *); |
| 18405 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *); |
| 18406 SQLITE_PRIVATE int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *); |
| 18407 SQLITE_PRIVATE int sqlite3VdbeSorterRewind(const VdbeCursor *, int *); |
| 18408 SQLITE_PRIVATE int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *); |
| 18409 SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int
*); |
| 18410 |
| 18411 #if !defined(SQLITE_OMIT_SHARED_CACHE) |
| 18412 SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*); |
| 18413 #else |
| 18414 # define sqlite3VdbeEnter(X) |
| 18415 #endif |
| 18416 |
| 18417 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 |
| 18418 SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); |
| 18419 #else |
| 18420 # define sqlite3VdbeLeave(X) |
| 18421 #endif |
| 18422 |
| 18423 #ifdef SQLITE_DEBUG |
| 18424 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*); |
| 18425 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem*); |
| 18426 #endif |
| 18427 |
| 18428 #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 18429 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int); |
| 18430 #else |
| 18431 # define sqlite3VdbeCheckFk(p,i) 0 |
| 18432 #endif |
| 18433 |
| 18434 SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8); |
| 18435 #ifdef SQLITE_DEBUG |
| 18436 SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*); |
| 18437 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); |
| 18438 #endif |
| 18439 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem); |
| 18440 |
| 18441 #ifndef SQLITE_OMIT_INCRBLOB |
| 18442 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *); |
| 18443 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) |
| 18444 #else |
| 18445 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK |
| 18446 #define ExpandBlob(P) SQLITE_OK |
| 18447 #endif |
| 18448 |
| 18449 #endif /* !defined(SQLITE_VDBEINT_H) */ |
| 18450 |
| 18451 /************** End of vdbeInt.h *********************************************/ |
| 18452 /************** Continuing where we left off in status.c *********************/ |
| 18453 |
| 18454 /* |
| 18455 ** Variables in which to record status information. |
| 18456 */ |
| 18457 #if SQLITE_PTRSIZE>4 |
| 18458 typedef sqlite3_int64 sqlite3StatValueType; |
| 18459 #else |
| 18460 typedef u32 sqlite3StatValueType; |
| 18461 #endif |
| 18462 typedef struct sqlite3StatType sqlite3StatType; |
| 18463 static SQLITE_WSD struct sqlite3StatType { |
| 18464 sqlite3StatValueType nowValue[10]; /* Current value */ |
| 18465 sqlite3StatValueType mxValue[10]; /* Maximum value */ |
| 18466 } sqlite3Stat = { {0,}, {0,} }; |
| 18467 |
| 18468 /* |
| 18469 ** Elements of sqlite3Stat[] are protected by either the memory allocator |
| 18470 ** mutex, or by the pcache1 mutex. The following array determines which. |
| 18471 */ |
| 18472 static const char statMutex[] = { |
| 18473 0, /* SQLITE_STATUS_MEMORY_USED */ |
| 18474 1, /* SQLITE_STATUS_PAGECACHE_USED */ |
| 18475 1, /* SQLITE_STATUS_PAGECACHE_OVERFLOW */ |
| 18476 0, /* SQLITE_STATUS_SCRATCH_USED */ |
| 18477 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */ |
| 18478 0, /* SQLITE_STATUS_MALLOC_SIZE */ |
| 18479 0, /* SQLITE_STATUS_PARSER_STACK */ |
| 18480 1, /* SQLITE_STATUS_PAGECACHE_SIZE */ |
| 18481 0, /* SQLITE_STATUS_SCRATCH_SIZE */ |
| 18482 0, /* SQLITE_STATUS_MALLOC_COUNT */ |
| 18483 }; |
| 18484 |
| 18485 |
| 18486 /* The "wsdStat" macro will resolve to the status information |
| 18487 ** state vector. If writable static data is unsupported on the target, |
| 18488 ** we have to locate the state vector at run-time. In the more common |
| 18489 ** case where writable static data is supported, wsdStat can refer directly |
| 18490 ** to the "sqlite3Stat" state vector declared above. |
| 18491 */ |
| 18492 #ifdef SQLITE_OMIT_WSD |
| 18493 # define wsdStatInit sqlite3StatType *x = &GLOBAL(sqlite3StatType,sqlite3Stat) |
| 18494 # define wsdStat x[0] |
| 18495 #else |
| 18496 # define wsdStatInit |
| 18497 # define wsdStat sqlite3Stat |
| 18498 #endif |
| 18499 |
| 18500 /* |
| 18501 ** Return the current value of a status parameter. The caller must |
| 18502 ** be holding the appropriate mutex. |
| 18503 */ |
| 18504 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int op){ |
| 18505 wsdStatInit; |
| 18506 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); |
| 18507 assert( op>=0 && op<ArraySize(statMutex) ); |
| 18508 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex() |
| 18509 : sqlite3MallocMutex()) ); |
| 18510 return wsdStat.nowValue[op]; |
| 18511 } |
| 18512 |
| 18513 /* |
| 18514 ** Add N to the value of a status record. The caller must hold the |
| 18515 ** appropriate mutex. (Locking is checked by assert()). |
| 18516 ** |
| 18517 ** The StatusUp() routine can accept positive or negative values for N. |
| 18518 ** The value of N is added to the current status value and the high-water |
| 18519 ** mark is adjusted if necessary. |
| 18520 ** |
| 18521 ** The StatusDown() routine lowers the current value by N. The highwater |
| 18522 ** mark is unchanged. N must be non-negative for StatusDown(). |
| 18523 */ |
| 18524 SQLITE_PRIVATE void sqlite3StatusUp(int op, int N){ |
| 18525 wsdStatInit; |
| 18526 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); |
| 18527 assert( op>=0 && op<ArraySize(statMutex) ); |
| 18528 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex() |
| 18529 : sqlite3MallocMutex()) ); |
| 18530 wsdStat.nowValue[op] += N; |
| 18531 if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){ |
| 18532 wsdStat.mxValue[op] = wsdStat.nowValue[op]; |
| 18533 } |
| 18534 } |
| 18535 SQLITE_PRIVATE void sqlite3StatusDown(int op, int N){ |
| 18536 wsdStatInit; |
| 18537 assert( N>=0 ); |
| 18538 assert( op>=0 && op<ArraySize(statMutex) ); |
| 18539 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex() |
| 18540 : sqlite3MallocMutex()) ); |
| 18541 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); |
| 18542 wsdStat.nowValue[op] -= N; |
| 18543 } |
| 18544 |
| 18545 /* |
| 18546 ** Adjust the highwater mark if necessary. |
| 18547 ** The caller must hold the appropriate mutex. |
| 18548 */ |
| 18549 SQLITE_PRIVATE void sqlite3StatusHighwater(int op, int X){ |
| 18550 sqlite3StatValueType newValue; |
| 18551 wsdStatInit; |
| 18552 assert( X>=0 ); |
| 18553 newValue = (sqlite3StatValueType)X; |
| 18554 assert( op>=0 && op<ArraySize(wsdStat.nowValue) ); |
| 18555 assert( op>=0 && op<ArraySize(statMutex) ); |
| 18556 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex() |
| 18557 : sqlite3MallocMutex()) ); |
| 18558 assert( op==SQLITE_STATUS_MALLOC_SIZE |
| 18559 || op==SQLITE_STATUS_PAGECACHE_SIZE |
| 18560 || op==SQLITE_STATUS_SCRATCH_SIZE |
| 18561 || op==SQLITE_STATUS_PARSER_STACK ); |
| 18562 if( newValue>wsdStat.mxValue[op] ){ |
| 18563 wsdStat.mxValue[op] = newValue; |
| 18564 } |
| 18565 } |
| 18566 |
| 18567 /* |
| 18568 ** Query status information. |
| 18569 */ |
| 18570 SQLITE_API int sqlite3_status64( |
| 18571 int op, |
| 18572 sqlite3_int64 *pCurrent, |
| 18573 sqlite3_int64 *pHighwater, |
| 18574 int resetFlag |
| 18575 ){ |
| 18576 sqlite3_mutex *pMutex; |
| 18577 wsdStatInit; |
| 18578 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){ |
| 18579 return SQLITE_MISUSE_BKPT; |
| 18580 } |
| 18581 #ifdef SQLITE_ENABLE_API_ARMOR |
| 18582 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; |
| 18583 #endif |
| 18584 pMutex = statMutex[op] ? sqlite3Pcache1Mutex() : sqlite3MallocMutex(); |
| 18585 sqlite3_mutex_enter(pMutex); |
| 18586 *pCurrent = wsdStat.nowValue[op]; |
| 18587 *pHighwater = wsdStat.mxValue[op]; |
| 18588 if( resetFlag ){ |
| 18589 wsdStat.mxValue[op] = wsdStat.nowValue[op]; |
| 18590 } |
| 18591 sqlite3_mutex_leave(pMutex); |
| 18592 (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */ |
| 18593 return SQLITE_OK; |
| 18594 } |
| 18595 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
lag){ |
| 18596 sqlite3_int64 iCur = 0, iHwtr = 0; |
| 18597 int rc; |
| 18598 #ifdef SQLITE_ENABLE_API_ARMOR |
| 18599 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT; |
| 18600 #endif |
| 18601 rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag); |
| 18602 if( rc==0 ){ |
| 18603 *pCurrent = (int)iCur; |
| 18604 *pHighwater = (int)iHwtr; |
| 18605 } |
| 18606 return rc; |
| 18607 } |
| 18608 |
| 18609 /* |
| 18610 ** Query status information for a single database connection |
| 18611 */ |
| 18612 SQLITE_API int sqlite3_db_status( |
| 18613 sqlite3 *db, /* The database connection whose status is desired */ |
| 18614 int op, /* Status verb */ |
| 18615 int *pCurrent, /* Write current value here */ |
| 18616 int *pHighwater, /* Write high-water mark here */ |
| 18617 int resetFlag /* Reset high-water mark if true */ |
| 18618 ){ |
| 18619 int rc = SQLITE_OK; /* Return code */ |
| 18620 #ifdef SQLITE_ENABLE_API_ARMOR |
| 18621 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){ |
| 18622 return SQLITE_MISUSE_BKPT; |
| 18623 } |
| 18624 #endif |
| 18625 sqlite3_mutex_enter(db->mutex); |
| 18626 switch( op ){ |
| 18627 case SQLITE_DBSTATUS_LOOKASIDE_USED: { |
| 18628 *pCurrent = db->lookaside.nOut; |
| 18629 *pHighwater = db->lookaside.mxOut; |
| 18630 if( resetFlag ){ |
| 18631 db->lookaside.mxOut = db->lookaside.nOut; |
| 18632 } |
| 18633 break; |
| 18634 } |
| 18635 |
| 18636 case SQLITE_DBSTATUS_LOOKASIDE_HIT: |
| 18637 case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE: |
| 18638 case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: { |
| 18639 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT ); |
| 18640 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE ); |
| 18641 testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL ); |
| 18642 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 ); |
| 18643 assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 ); |
| 18644 *pCurrent = 0; |
| 18645 *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT]; |
| 18646 if( resetFlag ){ |
| 18647 db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0; |
| 18648 } |
| 18649 break; |
| 18650 } |
| 18651 |
| 18652 /* |
| 18653 ** Return an approximation for the amount of memory currently used |
| 18654 ** by all pagers associated with the given database connection. The |
| 18655 ** highwater mark is meaningless and is returned as zero. |
| 18656 */ |
| 18657 case SQLITE_DBSTATUS_CACHE_USED_SHARED: |
| 18658 case SQLITE_DBSTATUS_CACHE_USED: { |
| 18659 int totalUsed = 0; |
| 18660 int i; |
| 18661 sqlite3BtreeEnterAll(db); |
| 18662 for(i=0; i<db->nDb; i++){ |
| 18663 Btree *pBt = db->aDb[i].pBt; |
| 18664 if( pBt ){ |
| 18665 Pager *pPager = sqlite3BtreePager(pBt); |
| 18666 int nByte = sqlite3PagerMemUsed(pPager); |
| 18667 if( op==SQLITE_DBSTATUS_CACHE_USED_SHARED ){ |
| 18668 nByte = nByte / sqlite3BtreeConnectionCount(pBt); |
| 18669 } |
| 18670 totalUsed += nByte; |
| 18671 } |
| 18672 } |
| 18673 sqlite3BtreeLeaveAll(db); |
| 18674 *pCurrent = totalUsed; |
| 18675 *pHighwater = 0; |
| 18676 break; |
| 18677 } |
| 18678 |
| 18679 /* |
| 18680 ** *pCurrent gets an accurate estimate of the amount of memory used |
| 18681 ** to store the schema for all databases (main, temp, and any ATTACHed |
| 18682 ** databases. *pHighwater is set to zero. |
| 18683 */ |
| 18684 case SQLITE_DBSTATUS_SCHEMA_USED: { |
| 18685 int i; /* Used to iterate through schemas */ |
| 18686 int nByte = 0; /* Used to accumulate return value */ |
| 18687 |
| 18688 sqlite3BtreeEnterAll(db); |
| 18689 db->pnBytesFreed = &nByte; |
| 18690 for(i=0; i<db->nDb; i++){ |
| 18691 Schema *pSchema = db->aDb[i].pSchema; |
| 18692 if( ALWAYS(pSchema!=0) ){ |
| 18693 HashElem *p; |
| 18694 |
| 18695 nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * ( |
| 18696 pSchema->tblHash.count |
| 18697 + pSchema->trigHash.count |
| 18698 + pSchema->idxHash.count |
| 18699 + pSchema->fkeyHash.count |
| 18700 ); |
| 18701 nByte += sqlite3_msize(pSchema->tblHash.ht); |
| 18702 nByte += sqlite3_msize(pSchema->trigHash.ht); |
| 18703 nByte += sqlite3_msize(pSchema->idxHash.ht); |
| 18704 nByte += sqlite3_msize(pSchema->fkeyHash.ht); |
| 18705 |
| 18706 for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){ |
| 18707 sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p)); |
| 18708 } |
| 18709 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){ |
| 18710 sqlite3DeleteTable(db, (Table *)sqliteHashData(p)); |
| 18711 } |
| 18712 } |
| 18713 } |
| 18714 db->pnBytesFreed = 0; |
| 18715 sqlite3BtreeLeaveAll(db); |
| 18716 |
| 18717 *pHighwater = 0; |
| 18718 *pCurrent = nByte; |
| 18719 break; |
| 18720 } |
| 18721 |
| 18722 /* |
| 18723 ** *pCurrent gets an accurate estimate of the amount of memory used |
| 18724 ** to store all prepared statements. |
| 18725 ** *pHighwater is set to zero. |
| 18726 */ |
| 18727 case SQLITE_DBSTATUS_STMT_USED: { |
| 18728 struct Vdbe *pVdbe; /* Used to iterate through VMs */ |
| 18729 int nByte = 0; /* Used to accumulate return value */ |
| 18730 |
| 18731 db->pnBytesFreed = &nByte; |
| 18732 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){ |
| 18733 sqlite3VdbeClearObject(db, pVdbe); |
| 18734 sqlite3DbFree(db, pVdbe); |
| 18735 } |
| 18736 db->pnBytesFreed = 0; |
| 18737 |
| 18738 *pHighwater = 0; /* IMP: R-64479-57858 */ |
| 18739 *pCurrent = nByte; |
| 18740 |
| 18741 break; |
| 18742 } |
| 18743 |
| 18744 /* |
| 18745 ** Set *pCurrent to the total cache hits or misses encountered by all |
| 18746 ** pagers the database handle is connected to. *pHighwater is always set |
| 18747 ** to zero. |
| 18748 */ |
| 18749 case SQLITE_DBSTATUS_CACHE_HIT: |
| 18750 case SQLITE_DBSTATUS_CACHE_MISS: |
| 18751 case SQLITE_DBSTATUS_CACHE_WRITE:{ |
| 18752 int i; |
| 18753 int nRet = 0; |
| 18754 assert( SQLITE_DBSTATUS_CACHE_MISS==SQLITE_DBSTATUS_CACHE_HIT+1 ); |
| 18755 assert( SQLITE_DBSTATUS_CACHE_WRITE==SQLITE_DBSTATUS_CACHE_HIT+2 ); |
| 18756 |
| 18757 for(i=0; i<db->nDb; i++){ |
| 18758 if( db->aDb[i].pBt ){ |
| 18759 Pager *pPager = sqlite3BtreePager(db->aDb[i].pBt); |
| 18760 sqlite3PagerCacheStat(pPager, op, resetFlag, &nRet); |
| 18761 } |
| 18762 } |
| 18763 *pHighwater = 0; /* IMP: R-42420-56072 */ |
| 18764 /* IMP: R-54100-20147 */ |
| 18765 /* IMP: R-29431-39229 */ |
| 18766 *pCurrent = nRet; |
| 18767 break; |
| 18768 } |
| 18769 |
| 18770 /* Set *pCurrent to non-zero if there are unresolved deferred foreign |
| 18771 ** key constraints. Set *pCurrent to zero if all foreign key constraints |
| 18772 ** have been satisfied. The *pHighwater is always set to zero. |
| 18773 */ |
| 18774 case SQLITE_DBSTATUS_DEFERRED_FKS: { |
| 18775 *pHighwater = 0; /* IMP: R-11967-56545 */ |
| 18776 *pCurrent = db->nDeferredImmCons>0 || db->nDeferredCons>0; |
| 18777 break; |
| 18778 } |
| 18779 |
| 18780 default: { |
| 18781 rc = SQLITE_ERROR; |
| 18782 } |
| 18783 } |
| 18784 sqlite3_mutex_leave(db->mutex); |
| 18785 return rc; |
| 18786 } |
| 18787 |
| 18788 /************** End of status.c **********************************************/ |
| 18789 |
| 18790 /* Chain include. */ |
| 18791 #include "sqlite3.01.c" |
OLD | NEW |