1 /****************************************************************************** 2 ** This file is an amalgamation of many separate C source files from SQLite 3 ** version 3.7.4. By combining all the individual C code files into this 4 ** single large file, the entire code can be compiled as a one translation 5 ** unit. This allows many compilers to do optimizations that would not be 6 ** possible if the files were compiled separately. Performance improvements 7 ** of 5% or more are commonly seen when SQLite is compiled as a single 8 ** translation unit. 9 ** 10 ** This file is all you need to compile SQLite. To use SQLite in other 11 ** programs, you need this file and the "sqlite3.h" header file that defines 12 ** the programming interface to the SQLite library. (If you do not have 13 ** the "sqlite3.h" header file at hand, you will find a copy embedded within 14 ** the text of this file. Search for "Begin file sqlite3.h" to find the start 15 ** of the embedded sqlite3.h header file.) Additional code files may be needed 16 ** if you want a wrapper to interface SQLite with your choice of programming 17 ** language. The code for the "sqlite3" command-line shell is also in a 18 ** separate file. This file contains only code for the core SQLite library. 19 */ 20 #define SQLITE_CORE 1 21 #define SQLITE_AMALGAMATION 1 22 #ifndef SQLITE_PRIVATE 23 # define SQLITE_PRIVATE static 24 #endif 25 #ifndef SQLITE_API 26 # define SQLITE_API 27 #endif 28 // Begin Android Add 29 #define fdatasync fsync 30 #undef __APPLE__ 31 // End Android Add 32 /************** Begin file sqliteInt.h ***************************************/ 33 /* 34 ** 2001 September 15 35 ** 36 ** The author disclaims copyright to this source code. In place of 37 ** a legal notice, here is a blessing: 38 ** 39 ** May you do good and not evil. 40 ** May you find forgiveness for yourself and forgive others. 41 ** May you share freely, never taking more than you give. 42 ** 43 ************************************************************************* 44 ** Internal interface definitions for SQLite. 45 ** 46 */ 47 #ifndef _SQLITEINT_H_ 48 #define _SQLITEINT_H_ 49 50 /* 51 ** These #defines should enable >2GB file support on POSIX if the 52 ** underlying operating system supports it. If the OS lacks 53 ** large file support, or if the OS is windows, these should be no-ops. 54 ** 55 ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any 56 ** system #includes. Hence, this block of code must be the very first 57 ** code in all source files. 58 ** 59 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch 60 ** on the compiler command line. This is necessary if you are compiling 61 ** on a recent machine (ex: Red Hat 7.2) but you want your code to work 62 ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 63 ** without this option, LFS is enable. But LFS does not exist in the kernel 64 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary 65 ** portability you should omit LFS. 66 ** 67 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. 68 */ 69 #ifndef SQLITE_DISABLE_LFS 70 # define _LARGE_FILE 1 71 # ifndef _FILE_OFFSET_BITS 72 # define _FILE_OFFSET_BITS 64 73 # endif 74 # define _LARGEFILE_SOURCE 1 75 #endif 76 77 /* 78 ** Include the configuration header output by 'configure' if we're using the 79 ** autoconf-based build 80 */ 81 #ifdef _HAVE_SQLITE_CONFIG_H 82 #include "config.h" 83 #endif 84 85 /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/ 86 /************** Begin file sqliteLimit.h *************************************/ 87 /* 88 ** 2007 May 7 89 ** 90 ** The author disclaims copyright to this source code. In place of 91 ** a legal notice, here is a blessing: 92 ** 93 ** May you do good and not evil. 94 ** May you find forgiveness for yourself and forgive others. 95 ** May you share freely, never taking more than you give. 96 ** 97 ************************************************************************* 98 ** 99 ** This file defines various limits of what SQLite can process. 100 */ 101 102 /* 103 ** The maximum length of a TEXT or BLOB in bytes. This also 104 ** limits the size of a row in a table or index. 105 ** 106 ** The hard limit is the ability of a 32-bit signed integer 107 ** to count the size: 2^31-1 or 2147483647. 108 */ 109 #ifndef SQLITE_MAX_LENGTH 110 # define SQLITE_MAX_LENGTH 1000000000 111 #endif 112 113 /* 114 ** This is the maximum number of 115 ** 116 ** * Columns in a table 117 ** * Columns in an index 118 ** * Columns in a view 119 ** * Terms in the SET clause of an UPDATE statement 120 ** * Terms in the result set of a SELECT statement 121 ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. 122 ** * Terms in the VALUES clause of an INSERT statement 123 ** 124 ** The hard upper limit here is 32676. Most database people will 125 ** tell you that in a well-normalized database, you usually should 126 ** not have more than a dozen or so columns in any table. And if 127 ** that is the case, there is no point in having more than a few 128 ** dozen values in any of the other situations described above. 129 */ 130 #ifndef SQLITE_MAX_COLUMN 131 # define SQLITE_MAX_COLUMN 2000 132 #endif 133 134 /* 135 ** The maximum length of a single SQL statement in bytes. 136 ** 137 ** It used to be the case that setting this value to zero would 138 ** turn the limit off. That is no longer true. It is not possible 139 ** to turn this limit off. 140 */ 141 #ifndef SQLITE_MAX_SQL_LENGTH 142 # define SQLITE_MAX_SQL_LENGTH 1000000000 143 #endif 144 145 /* 146 ** The maximum depth of an expression tree. This is limited to 147 ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might 148 ** want to place more severe limits on the complexity of an 149 ** expression. 150 ** 151 ** A value of 0 used to mean that the limit was not enforced. 152 ** But that is no longer true. The limit is now strictly enforced 153 ** at all times. 154 */ 155 #ifndef SQLITE_MAX_EXPR_DEPTH 156 # define SQLITE_MAX_EXPR_DEPTH 1000 157 #endif 158 159 /* 160 ** The maximum number of terms in a compound SELECT statement. 161 ** The code generator for compound SELECT statements does one 162 ** level of recursion for each term. A stack overflow can result 163 ** if the number of terms is too large. In practice, most SQL 164 ** never has more than 3 or 4 terms. Use a value of 0 to disable 165 ** any limit on the number of terms in a compount SELECT. 166 */ 167 #ifndef SQLITE_MAX_COMPOUND_SELECT 168 # define SQLITE_MAX_COMPOUND_SELECT 500 169 #endif 170 171 /* 172 ** The maximum number of opcodes in a VDBE program. 173 ** Not currently enforced. 174 */ 175 #ifndef SQLITE_MAX_VDBE_OP 176 # define SQLITE_MAX_VDBE_OP 25000 177 #endif 178 179 /* 180 ** The maximum number of arguments to an SQL function. 181 */ 182 #ifndef SQLITE_MAX_FUNCTION_ARG 183 # define SQLITE_MAX_FUNCTION_ARG 127 184 #endif 185 186 /* 187 ** The maximum number of in-memory pages to use for the main database 188 ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE 189 */ 190 #ifndef SQLITE_DEFAULT_CACHE_SIZE 191 # define SQLITE_DEFAULT_CACHE_SIZE 2000 192 #endif 193 #ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE 194 # define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500 195 #endif 196 197 /* 198 ** The default number of frames to accumulate in the log file before 199 ** checkpointing the database in WAL mode. 200 */ 201 #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 202 # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 203 #endif 204 205 /* 206 ** The maximum number of attached databases. This must be between 0 207 ** and 30. The upper bound on 30 is because a 32-bit integer bitmap 208 ** is used internally to track attached databases. 209 */ 210 #ifndef SQLITE_MAX_ATTACHED 211 # define SQLITE_MAX_ATTACHED 10 212 #endif 213 214 215 /* 216 ** The maximum value of a ?nnn wildcard that the parser will accept. 217 */ 218 #ifndef SQLITE_MAX_VARIABLE_NUMBER 219 # define SQLITE_MAX_VARIABLE_NUMBER 999 220 #endif 221 222 /* Maximum page size. The upper bound on this value is 65536. This a limit 223 ** imposed by the use of 16-bit offsets within each page. 224 ** 225 ** Earlier versions of SQLite allowed the user to change this value at 226 ** compile time. This is no longer permitted, on the grounds that it creates 227 ** a library that is technically incompatible with an SQLite library 228 ** compiled with a different limit. If a process operating on a database 229 ** with a page-size of 65536 bytes crashes, then an instance of SQLite 230 ** compiled with the default page-size limit will not be able to rollback 231 ** the aborted transaction. This could lead to database corruption. 232 */ 233 #ifdef SQLITE_MAX_PAGE_SIZE 234 # undef SQLITE_MAX_PAGE_SIZE 235 #endif 236 #define SQLITE_MAX_PAGE_SIZE 65536 237 238 239 /* 240 ** The default size of a database page. 241 */ 242 #ifndef SQLITE_DEFAULT_PAGE_SIZE 243 # define SQLITE_DEFAULT_PAGE_SIZE 1024 244 #endif 245 #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE 246 # undef SQLITE_DEFAULT_PAGE_SIZE 247 # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE 248 #endif 249 250 /* 251 ** Ordinarily, if no value is explicitly provided, SQLite creates databases 252 ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain 253 ** device characteristics (sector-size and atomic write() support), 254 ** SQLite may choose a larger value. This constant is the maximum value 255 ** SQLite will choose on its own. 256 */ 257 #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE 258 # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 259 #endif 260 #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE 261 # undef SQLITE_MAX_DEFAULT_PAGE_SIZE 262 # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE 263 #endif 264 265 266 /* 267 ** Maximum number of pages in one database file. 268 ** 269 ** This is really just the default value for the max_page_count pragma. 270 ** This value can be lowered (or raised) at run-time using that the 271 ** max_page_count macro. 272 */ 273 #ifndef SQLITE_MAX_PAGE_COUNT 274 # define SQLITE_MAX_PAGE_COUNT 1073741823 275 #endif 276 277 /* 278 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB 279 ** operator. 280 */ 281 #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH 282 # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 283 #endif 284 285 /* 286 ** Maximum depth of recursion for triggers. 287 ** 288 ** A value of 1 means that a trigger program will not be able to itself 289 ** fire any triggers. A value of 0 means that no trigger programs at all 290 ** may be executed. 291 */ 292 #ifndef SQLITE_MAX_TRIGGER_DEPTH 293 # define SQLITE_MAX_TRIGGER_DEPTH 1000 294 #endif 295 296 /************** End of sqliteLimit.h *****************************************/ 297 /************** Continuing where we left off in sqliteInt.h ******************/ 298 299 /* Disable nuisance warnings on Borland compilers */ 300 #if defined(__BORLANDC__) 301 #pragma warn -rch /* unreachable code */ 302 #pragma warn -ccc /* Condition is always true or false */ 303 #pragma warn -aus /* Assigned value is never used */ 304 #pragma warn -csu /* Comparing signed and unsigned */ 305 #pragma warn -spa /* Suspicious pointer arithmetic */ 306 #endif 307 308 /* Needed for various definitions... */ 309 #ifndef _GNU_SOURCE 310 # define _GNU_SOURCE 311 #endif 312 313 /* 314 ** Include standard header files as necessary 315 */ 316 #ifdef HAVE_STDINT_H 317 #include <stdint.h> 318 #endif 319 #ifdef HAVE_INTTYPES_H 320 #include <inttypes.h> 321 #endif 322 323 /* 324 ** The number of samples of an index that SQLite takes in order to 325 ** construct a histogram of the table content when running ANALYZE 326 ** and with SQLITE_ENABLE_STAT2 327 */ 328 #define SQLITE_INDEX_SAMPLES 10 329 330 /* 331 ** The following macros are used to cast pointers to integers and 332 ** integers to pointers. The way you do this varies from one compiler 333 ** to the next, so we have developed the following set of #if statements 334 ** to generate appropriate macros for a wide range of compilers. 335 ** 336 ** The correct "ANSI" way to do this is to use the intptr_t type. 337 ** Unfortunately, that typedef is not available on all compilers, or 338 ** if it is available, it requires an #include of specific headers 339 ** that vary from one machine to the next. 340 ** 341 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on 342 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). 343 ** So we have to define the macros in different ways depending on the 344 ** compiler. 345 */ 346 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ 347 # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) 348 # define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) 349 #elif !defined(__GNUC__) /* Works for compilers other than LLVM */ 350 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) 351 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) 352 #elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */ 353 # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) 354 # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) 355 #else /* Generates a warning - but it always works */ 356 # define SQLITE_INT_TO_PTR(X) ((void*)(X)) 357 # define SQLITE_PTR_TO_INT(X) ((int)(X)) 358 #endif 359 360 /* 361 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. 362 ** 0 means mutexes are permanently disable and the library is never 363 ** threadsafe. 1 means the library is serialized which is the highest 364 ** level of threadsafety. 2 means the libary is multithreaded - multiple 365 ** threads can use SQLite as long as no two threads try to use the same 366 ** database connection at the same time. 367 ** 368 ** Older versions of SQLite used an optional THREADSAFE macro. 369 ** We support that for legacy. 370 */ 371 #if !defined(SQLITE_THREADSAFE) 372 #if defined(THREADSAFE) 373 # define SQLITE_THREADSAFE THREADSAFE 374 #else 375 # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ 376 #endif 377 #endif 378 379 /* 380 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. 381 ** It determines whether or not the features related to 382 ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can 383 ** be overridden at runtime using the sqlite3_config() API. 384 */ 385 #if !defined(SQLITE_DEFAULT_MEMSTATUS) 386 # define SQLITE_DEFAULT_MEMSTATUS 1 387 #endif 388 389 /* 390 ** Exactly one of the following macros must be defined in order to 391 ** specify which memory allocation subsystem to use. 392 ** 393 ** SQLITE_SYSTEM_MALLOC // Use normal system malloc() 394 ** SQLITE_MEMDEBUG // Debugging version of system malloc() 395 ** 396 ** (Historical note: There used to be several other options, but we've 397 ** pared it down to just these two.) 398 ** 399 ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as 400 ** the default. 401 */ 402 #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)>1 403 # error "At most one of the following compile-time configuration options\ 404 is allows: SQLITE_SYSTEM_MALLOC, SQLITE_MEMDEBUG" 405 #endif 406 #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_MEMDEBUG)==0 407 # define SQLITE_SYSTEM_MALLOC 1 408 #endif 409 410 /* 411 ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the 412 ** sizes of memory allocations below this value where possible. 413 */ 414 #if !defined(SQLITE_MALLOC_SOFT_LIMIT) 415 # define SQLITE_MALLOC_SOFT_LIMIT 1024 416 #endif 417 418 /* 419 ** We need to define _XOPEN_SOURCE as follows in order to enable 420 ** recursive mutexes on most Unix systems. But Mac OS X is different. 421 ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told, 422 ** so it is omitted there. See ticket #2673. 423 ** 424 ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly 425 ** implemented on some systems. So we avoid defining it at all 426 ** if it is already defined or if it is unneeded because we are 427 ** not doing a threadsafe build. Ticket #2681. 428 ** 429 ** See also ticket #2741. 430 */ 431 #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE 432 # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */ 433 #endif 434 435 /* 436 ** The TCL headers are only needed when compiling the TCL bindings. 437 */ 438 #if defined(SQLITE_TCL) || defined(TCLSH) 439 # include <tcl.h> 440 #endif 441 442 /* 443 ** Many people are failing to set -DNDEBUG=1 when compiling SQLite. 444 ** Setting NDEBUG makes the code smaller and run faster. So the following 445 ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 446 ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out 447 ** feature. 448 */ 449 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 450 # define NDEBUG 1 451 #endif 452 453 /* 454 ** The testcase() macro is used to aid in coverage testing. When 455 ** doing coverage testing, the condition inside the argument to 456 ** testcase() must be evaluated both true and false in order to 457 ** get full branch coverage. The testcase() macro is inserted 458 ** to help ensure adequate test coverage in places where simple 459 ** condition/decision coverage is inadequate. For example, testcase() 460 ** can be used to make sure boundary values are tested. For 461 ** bitmask tests, testcase() can be used to make sure each bit 462 ** is significant and used at least once. On switch statements 463 ** where multiple cases go to the same block of code, testcase() 464 ** can insure that all cases are evaluated. 465 ** 466 */ 467 #ifdef SQLITE_COVERAGE_TEST 468 SQLITE_PRIVATE void sqlite3Coverage(int); 469 # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } 470 #else 471 # define testcase(X) 472 #endif 473 474 /* 475 ** The TESTONLY macro is used to enclose variable declarations or 476 ** other bits of code that are needed to support the arguments 477 ** within testcase() and assert() macros. 478 */ 479 #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) 480 # define TESTONLY(X) X 481 #else 482 # define TESTONLY(X) 483 #endif 484 485 /* 486 ** Sometimes we need a small amount of code such as a variable initialization 487 ** to setup for a later assert() statement. We do not want this code to 488 ** appear when assert() is disabled. The following macro is therefore 489 ** used to contain that setup code. The "VVA" acronym stands for 490 ** "Verification, Validation, and Accreditation". In other words, the 491 ** code within VVA_ONLY() will only run during verification processes. 492 */ 493 #ifndef NDEBUG 494 # define VVA_ONLY(X) X 495 #else 496 # define VVA_ONLY(X) 497 #endif 498 499 /* 500 ** The ALWAYS and NEVER macros surround boolean expressions which 501 ** are intended to always be true or false, respectively. Such 502 ** expressions could be omitted from the code completely. But they 503 ** are included in a few cases in order to enhance the resilience 504 ** of SQLite to unexpected behavior - to make the code "self-healing" 505 ** or "ductile" rather than being "brittle" and crashing at the first 506 ** hint of unplanned behavior. 507 ** 508 ** In other words, ALWAYS and NEVER are added for defensive code. 509 ** 510 ** When doing coverage testing ALWAYS and NEVER are hard-coded to 511 ** be true and false so that the unreachable code then specify will 512 ** not be counted as untested code. 513 */ 514 #if defined(SQLITE_COVERAGE_TEST) 515 # define ALWAYS(X) (1) 516 # define NEVER(X) (0) 517 #elif !defined(NDEBUG) 518 # define ALWAYS(X) ((X)?1:(assert(0),0)) 519 # define NEVER(X) ((X)?(assert(0),1):0) 520 #else 521 # define ALWAYS(X) (X) 522 # define NEVER(X) (X) 523 #endif 524 525 /* 526 ** Return true (non-zero) if the input is a integer that is too large 527 ** to fit in 32-bits. This macro is used inside of various testcase() 528 ** macros to verify that we have tested SQLite for large-file support. 529 */ 530 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) 531 532 /* 533 ** The macro unlikely() is a hint that surrounds a boolean 534 ** expression that is usually false. Macro likely() surrounds 535 ** a boolean expression that is usually true. GCC is able to 536 ** use these hints to generate better code, sometimes. 537 */ 538 #if defined(__GNUC__) && 0 539 # define likely(X) __builtin_expect((X),1) 540 # define unlikely(X) __builtin_expect((X),0) 541 #else 542 # define likely(X) !!(X) 543 # define unlikely(X) !!(X) 544 #endif 545 546 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/ 547 /************** Begin file sqlite3.h *****************************************/ 548 /* 549 ** 2001 September 15 550 ** 551 ** The author disclaims copyright to this source code. In place of 552 ** a legal notice, here is a blessing: 553 ** 554 ** May you do good and not evil. 555 ** May you find forgiveness for yourself and forgive others. 556 ** May you share freely, never taking more than you give. 557 ** 558 ************************************************************************* 559 ** This header file defines the interface that the SQLite library 560 ** presents to client programs. If a C-function, structure, datatype, 561 ** or constant definition does not appear in this file, then it is 562 ** not a published API of SQLite, is subject to change without 563 ** notice, and should not be referenced by programs that use SQLite. 564 ** 565 ** Some of the definitions that are in this file are marked as 566 ** "experimental". Experimental interfaces are normally new 567 ** features recently added to SQLite. We do not anticipate changes 568 ** to experimental interfaces but reserve the right to make minor changes 569 ** if experience from use "in the wild" suggest such changes are prudent. 570 ** 571 ** The official C-language API documentation for SQLite is derived 572 ** from comments in this file. This file is the authoritative source 573 ** on how SQLite interfaces are suppose to operate. 574 ** 575 ** The name of this file under configuration management is "sqlite.h.in". 576 ** The makefile makes some minor changes to this file (such as inserting 577 ** the version number) and changes its name to "sqlite3.h" as 578 ** part of the build process. 579 */ 580 #ifndef _SQLITE3_H_ 581 #define _SQLITE3_H_ 582 #include <stdarg.h> /* Needed for the definition of va_list */ 583 584 /* 585 ** Make sure we can call this stuff from C++. 586 */ 587 #if 0 588 extern "C" { 589 #endif 590 591 592 /* 593 ** Add the ability to override 'extern' 594 */ 595 #ifndef SQLITE_EXTERN 596 # define SQLITE_EXTERN extern 597 #endif 598 599 #ifndef SQLITE_API 600 # define SQLITE_API 601 #endif 602 603 604 /* 605 ** These no-op macros are used in front of interfaces to mark those 606 ** interfaces as either deprecated or experimental. New applications 607 ** should not use deprecated interfaces - they are support for backwards 608 ** compatibility only. Application writers should be aware that 609 ** experimental interfaces are subject to change in point releases. 610 ** 611 ** These macros used to resolve to various kinds of compiler magic that 612 ** would generate warning messages when they were used. But that 613 ** compiler magic ended up generating such a flurry of bug reports 614 ** that we have taken it all out and gone back to using simple 615 ** noop macros. 616 */ 617 #define SQLITE_DEPRECATED 618 #define SQLITE_EXPERIMENTAL 619 620 /* 621 ** Ensure these symbols were not defined by some previous header file. 622 */ 623 #ifdef SQLITE_VERSION 624 # undef SQLITE_VERSION 625 #endif 626 #ifdef SQLITE_VERSION_NUMBER 627 # undef SQLITE_VERSION_NUMBER 628 #endif 629 630 /* 631 ** CAPI3REF: Compile-Time Library Version Numbers 632 ** 633 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header 634 ** evaluates to a string literal that is the SQLite version in the 635 ** format "X.Y.Z" where X is the major version number (always 3 for 636 ** SQLite3) and Y is the minor version number and Z is the release number.)^ 637 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer 638 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same 639 ** numbers used in [SQLITE_VERSION].)^ 640 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also 641 ** be larger than the release from which it is derived. Either Y will 642 ** be held constant and Z will be incremented or else Y will be incremented 643 ** and Z will be reset to zero. 644 ** 645 ** Since version 3.6.18, SQLite source code has been stored in the 646 ** <a href="http://www.fossil-scm.org/">Fossil configuration management 647 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to 648 ** a string which identifies a particular check-in of SQLite 649 ** within its configuration management system. ^The SQLITE_SOURCE_ID 650 ** string contains the date and time of the check-in (UTC) and an SHA1 651 ** hash of the entire source tree. 652 ** 653 ** See also: [sqlite3_libversion()], 654 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 655 ** [sqlite_version()] and [sqlite_source_id()]. 656 */ 657 #define SQLITE_VERSION "3.7.4" 658 #define SQLITE_VERSION_NUMBER 3007004 659 #define SQLITE_SOURCE_ID "2011-02-23 14:33:31 8609a15dfad23a7c5311b52617d5c4818c0b8d1e" 660 661 /* 662 ** CAPI3REF: Run-Time Library Version Numbers 663 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 664 ** 665 ** These interfaces provide the same information as the [SQLITE_VERSION], 666 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 667 ** but are associated with the library instead of the header file. ^(Cautious 668 ** programmers might include assert() statements in their application to 669 ** verify that values returned by these interfaces match the macros in 670 ** the header, and thus insure that the application is 671 ** compiled with matching library and header files. 672 ** 673 ** <blockquote><pre> 674 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); 675 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); 676 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); 677 ** </pre></blockquote>)^ 678 ** 679 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] 680 ** macro. ^The sqlite3_libversion() function returns a pointer to the 681 ** to the sqlite3_version[] string constant. The sqlite3_libversion() 682 ** function is provided for use in DLLs since DLL users usually do not have 683 ** direct access to string constants within the DLL. ^The 684 ** sqlite3_libversion_number() function returns an integer equal to 685 ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns 686 ** a pointer to a string constant whose value is the same as the 687 ** [SQLITE_SOURCE_ID] C preprocessor macro. 688 ** 689 ** See also: [sqlite_version()] and [sqlite_source_id()]. 690 */ 691 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; 692 SQLITE_API const char *sqlite3_libversion(void); 693 SQLITE_API const char *sqlite3_sourceid(void); 694 SQLITE_API int sqlite3_libversion_number(void); 695 696 /* 697 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics 698 ** 699 ** ^The sqlite3_compileoption_used() function returns 0 or 1 700 ** indicating whether the specified option was defined at 701 ** compile time. ^The SQLITE_ prefix may be omitted from the 702 ** option name passed to sqlite3_compileoption_used(). 703 ** 704 ** ^The sqlite3_compileoption_get() function allows iterating 705 ** over the list of options that were defined at compile time by 706 ** returning the N-th compile time option string. ^If N is out of range, 707 ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ 708 ** prefix is omitted from any strings returned by 709 ** sqlite3_compileoption_get(). 710 ** 711 ** ^Support for the diagnostic functions sqlite3_compileoption_used() 712 ** and sqlite3_compileoption_get() may be omitted by specifying the 713 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. 714 ** 715 ** See also: SQL functions [sqlite_compileoption_used()] and 716 ** [sqlite_compileoption_get()] and the [compile_options pragma]. 717 */ 718 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 719 SQLITE_API int sqlite3_compileoption_used(const char *zOptName); 720 SQLITE_API const char *sqlite3_compileoption_get(int N); 721 #endif 722 723 /* 724 ** CAPI3REF: Test To See If The Library Is Threadsafe 725 ** 726 ** ^The sqlite3_threadsafe() function returns zero if and only if 727 ** SQLite was compiled mutexing code omitted due to the 728 ** [SQLITE_THREADSAFE] compile-time option being set to 0. 729 ** 730 ** SQLite can be compiled with or without mutexes. When 731 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 732 ** are enabled and SQLite is threadsafe. When the 733 ** [SQLITE_THREADSAFE] macro is 0, 734 ** the mutexes are omitted. Without the mutexes, it is not safe 735 ** to use SQLite concurrently from more than one thread. 736 ** 737 ** Enabling mutexes incurs a measurable performance penalty. 738 ** So if speed is of utmost importance, it makes sense to disable 739 ** the mutexes. But for maximum safety, mutexes should be enabled. 740 ** ^The default behavior is for mutexes to be enabled. 741 ** 742 ** This interface can be used by an application to make sure that the 743 ** version of SQLite that it is linking against was compiled with 744 ** the desired setting of the [SQLITE_THREADSAFE] macro. 745 ** 746 ** This interface only reports on the compile-time mutex setting 747 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with 748 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but 749 ** can be fully or partially disabled using a call to [sqlite3_config()] 750 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], 751 ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the 752 ** sqlite3_threadsafe() function shows only the compile-time setting of 753 ** thread safety, not any run-time changes to that setting made by 754 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() 755 ** is unchanged by calls to sqlite3_config().)^ 756 ** 757 ** See the [threading mode] documentation for additional information. 758 */ 759 SQLITE_API int sqlite3_threadsafe(void); 760 761 /* 762 ** CAPI3REF: Database Connection Handle 763 ** KEYWORDS: {database connection} {database connections} 764 ** 765 ** Each open SQLite database is represented by a pointer to an instance of 766 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 767 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and 768 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] 769 ** is its destructor. There are many other interfaces (such as 770 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and 771 ** [sqlite3_busy_timeout()] to name but three) that are methods on an 772 ** sqlite3 object. 773 */ 774 typedef struct sqlite3 sqlite3; 775 776 /* 777 ** CAPI3REF: 64-Bit Integer Types 778 ** KEYWORDS: sqlite_int64 sqlite_uint64 779 ** 780 ** Because there is no cross-platform way to specify 64-bit integer types 781 ** SQLite includes typedefs for 64-bit signed and unsigned integers. 782 ** 783 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. 784 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards 785 ** compatibility only. 786 ** 787 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values 788 ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The 789 ** sqlite3_uint64 and sqlite_uint64 types can store integer values 790 ** between 0 and +18446744073709551615 inclusive. 791 */ 792 #ifdef SQLITE_INT64_TYPE 793 typedef SQLITE_INT64_TYPE sqlite_int64; 794 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; 795 #elif defined(_MSC_VER) || defined(__BORLANDC__) 796 typedef __int64 sqlite_int64; 797 typedef unsigned __int64 sqlite_uint64; 798 #else 799 typedef long long int sqlite_int64; 800 typedef unsigned long long int sqlite_uint64; 801 #endif 802 typedef sqlite_int64 sqlite3_int64; 803 typedef sqlite_uint64 sqlite3_uint64; 804 805 /* 806 ** If compiling for a processor that lacks floating point support, 807 ** substitute integer for floating-point. 808 */ 809 #ifdef SQLITE_OMIT_FLOATING_POINT 810 # define double sqlite3_int64 811 #endif 812 813 /* 814 ** CAPI3REF: Closing A Database Connection 815 ** 816 ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object. 817 ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is 818 ** successfully destroyed and all associated resources are deallocated. 819 ** 820 ** Applications must [sqlite3_finalize | finalize] all [prepared statements] 821 ** and [sqlite3_blob_close | close] all [BLOB handles] associated with 822 ** the [sqlite3] object prior to attempting to close the object. ^If 823 ** sqlite3_close() is called on a [database connection] that still has 824 ** outstanding [prepared statements] or [BLOB handles], then it returns 825 ** SQLITE_BUSY. 826 ** 827 ** ^If [sqlite3_close()] is invoked while a transaction is open, 828 ** the transaction is automatically rolled back. 829 ** 830 ** The C parameter to [sqlite3_close(C)] must be either a NULL 831 ** pointer or an [sqlite3] object pointer obtained 832 ** from [sqlite3_open()], [sqlite3_open16()], or 833 ** [sqlite3_open_v2()], and not previously closed. 834 ** ^Calling sqlite3_close() with a NULL pointer argument is a 835 ** harmless no-op. 836 */ 837 SQLITE_API int sqlite3_close(sqlite3 *); 838 839 /* 840 ** The type for a callback function. 841 ** This is legacy and deprecated. It is included for historical 842 ** compatibility and is not documented. 843 */ 844 typedef int (*sqlite3_callback)(void*,int,char**, char**); 845 846 /* 847 ** CAPI3REF: One-Step Query Execution Interface 848 ** 849 ** The sqlite3_exec() interface is a convenience wrapper around 850 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], 851 ** that allows an application to run multiple statements of SQL 852 ** without having to use a lot of C code. 853 ** 854 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, 855 ** semicolon-separate SQL statements passed into its 2nd argument, 856 ** in the context of the [database connection] passed in as its 1st 857 ** argument. ^If the callback function of the 3rd argument to 858 ** sqlite3_exec() is not NULL, then it is invoked for each result row 859 ** coming out of the evaluated SQL statements. ^The 4th argument to 860 ** to sqlite3_exec() is relayed through to the 1st argument of each 861 ** callback invocation. ^If the callback pointer to sqlite3_exec() 862 ** is NULL, then no callback is ever invoked and result rows are 863 ** ignored. 864 ** 865 ** ^If an error occurs while evaluating the SQL statements passed into 866 ** sqlite3_exec(), then execution of the current statement stops and 867 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() 868 ** is not NULL then any error message is written into memory obtained 869 ** from [sqlite3_malloc()] and passed back through the 5th parameter. 870 ** To avoid memory leaks, the application should invoke [sqlite3_free()] 871 ** on error message strings returned through the 5th parameter of 872 ** of sqlite3_exec() after the error message string is no longer needed. 873 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors 874 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to 875 ** NULL before returning. 876 ** 877 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() 878 ** routine returns SQLITE_ABORT without invoking the callback again and 879 ** without running any subsequent SQL statements. 880 ** 881 ** ^The 2nd argument to the sqlite3_exec() callback function is the 882 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() 883 ** callback is an array of pointers to strings obtained as if from 884 ** [sqlite3_column_text()], one for each column. ^If an element of a 885 ** result row is NULL then the corresponding string pointer for the 886 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the 887 ** sqlite3_exec() callback is an array of pointers to strings where each 888 ** entry represents the name of corresponding result column as obtained 889 ** from [sqlite3_column_name()]. 890 ** 891 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer 892 ** to an empty string, or a pointer that contains only whitespace and/or 893 ** SQL comments, then no SQL statements are evaluated and the database 894 ** is not changed. 895 ** 896 ** Restrictions: 897 ** 898 ** <ul> 899 ** <li> The application must insure that the 1st parameter to sqlite3_exec() 900 ** is a valid and open [database connection]. 901 ** <li> The application must not close [database connection] specified by 902 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. 903 ** <li> The application must not modify the SQL statement text passed into 904 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. 905 ** </ul> 906 */ 907 SQLITE_API int sqlite3_exec( 908 sqlite3*, /* An open database */ 909 const char *sql, /* SQL to be evaluated */ 910 int (*callback)(void*,int,char**,char**), /* Callback function */ 911 void *, /* 1st argument to callback */ 912 char **errmsg /* Error msg written here */ 913 ); 914 915 /* 916 ** CAPI3REF: Result Codes 917 ** KEYWORDS: SQLITE_OK {error code} {error codes} 918 ** KEYWORDS: {result code} {result codes} 919 ** 920 ** Many SQLite functions return an integer result code from the set shown 921 ** here in order to indicates success or failure. 922 ** 923 ** New error codes may be added in future versions of SQLite. 924 ** 925 ** See also: [SQLITE_IOERR_READ | extended result codes] 926 */ 927 #define SQLITE_OK 0 /* Successful result */ 928 /* beginning-of-error-codes */ 929 #define SQLITE_ERROR 1 /* SQL error or missing database */ 930 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 931 #define SQLITE_PERM 3 /* Access permission denied */ 932 #define SQLITE_ABORT 4 /* Callback routine requested an abort */ 933 #define SQLITE_BUSY 5 /* The database file is locked */ 934 #define SQLITE_LOCKED 6 /* A table in the database is locked */ 935 #define SQLITE_NOMEM 7 /* A malloc() failed */ 936 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 937 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 938 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 939 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 940 #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */ 941 #define SQLITE_FULL 13 /* Insertion failed because database is full */ 942 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 943 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 944 #define SQLITE_EMPTY 16 /* Database is empty */ 945 #define SQLITE_SCHEMA 17 /* The database schema changed */ 946 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 947 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 948 #define SQLITE_MISMATCH 20 /* Data type mismatch */ 949 #define SQLITE_MISUSE 21 /* Library used incorrectly */ 950 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 951 #define SQLITE_AUTH 23 /* Authorization denied */ 952 #define SQLITE_FORMAT 24 /* Auxiliary database format error */ 953 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 954 #define SQLITE_NOTADB 26 /* File opened that is not a database file */ 955 // Begin Android Add 956 #define SQLITE_UNCLOSED 27 /* db can't be closed due unfinalized stmts */ 957 // End Android Add 958 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 959 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 960 /* end-of-error-codes */ 961 962 /* 963 ** CAPI3REF: Extended Result Codes 964 ** KEYWORDS: {extended error code} {extended error codes} 965 ** KEYWORDS: {extended result code} {extended result codes} 966 ** 967 ** In its default configuration, SQLite API routines return one of 26 integer 968 ** [SQLITE_OK | result codes]. However, experience has shown that many of 969 ** these result codes are too coarse-grained. They do not provide as 970 ** much information about problems as programmers might like. In an effort to 971 ** address this, newer versions of SQLite (version 3.3.8 and later) include 972 ** support for additional result codes that provide more detailed information 973 ** about errors. The extended result codes are enabled or disabled 974 ** on a per database connection basis using the 975 ** [sqlite3_extended_result_codes()] API. 976 ** 977 ** Some of the available extended result codes are listed here. 978 ** One may expect the number of extended result codes will be expand 979 ** over time. Software that uses extended result codes should expect 980 ** to see new result codes in future releases of SQLite. 981 ** 982 ** The SQLITE_OK result code will never be extended. It will always 983 ** be exactly zero. 984 */ 985 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 986 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 987 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 988 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 989 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 990 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 991 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 992 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 993 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 994 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 995 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 996 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 997 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 998 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 999 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 1000 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 1001 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 1002 #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) 1003 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 1004 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 1005 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 1006 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 1007 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 1008 1009 /* 1010 ** CAPI3REF: Flags For File Open Operations 1011 ** 1012 ** These bit values are intended for use in the 1013 ** 3rd parameter to the [sqlite3_open_v2()] interface and 1014 ** in the 4th parameter to the xOpen method of the 1015 ** [sqlite3_vfs] object. 1016 */ 1017 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 1018 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 1019 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 1020 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 1021 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 1022 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 1023 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 1024 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 1025 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 1026 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 1027 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 1028 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 1029 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 1030 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 1031 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 1032 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 1033 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 1034 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ 1035 1036 /* 1037 ** CAPI3REF: Device Characteristics 1038 ** 1039 ** The xDeviceCharacteristics method of the [sqlite3_io_methods] 1040 ** object returns an integer which is a vector of the these 1041 ** bit values expressing I/O characteristics of the mass storage 1042 ** device that holds the file that the [sqlite3_io_methods] 1043 ** refers to. 1044 ** 1045 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 1046 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 1047 ** mean that writes of blocks that are nnn bytes in size and 1048 ** are aligned to an address which is an integer multiple of 1049 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 1050 ** that when data is appended to a file, the data is appended 1051 ** first then the size of the file is extended, never the other 1052 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 1053 ** information is written to disk in the same order as calls 1054 ** to xWrite(). 1055 */ 1056 #define SQLITE_IOCAP_ATOMIC 0x00000001 1057 #define SQLITE_IOCAP_ATOMIC512 0x00000002 1058 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 1059 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 1060 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 1061 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 1062 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 1063 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 1064 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 1065 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 1066 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 1067 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 1068 1069 /* 1070 ** CAPI3REF: File Locking Levels 1071 ** 1072 ** SQLite uses one of these integer values as the second 1073 ** argument to calls it makes to the xLock() and xUnlock() methods 1074 ** of an [sqlite3_io_methods] object. 1075 */ 1076 #define SQLITE_LOCK_NONE 0 1077 #define SQLITE_LOCK_SHARED 1 1078 #define SQLITE_LOCK_RESERVED 2 1079 #define SQLITE_LOCK_PENDING 3 1080 #define SQLITE_LOCK_EXCLUSIVE 4 1081 1082 /* 1083 ** CAPI3REF: Synchronization Type Flags 1084 ** 1085 ** When SQLite invokes the xSync() method of an 1086 ** [sqlite3_io_methods] object it uses a combination of 1087 ** these integer values as the second argument. 1088 ** 1089 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the 1090 ** sync operation only needs to flush data to mass storage. Inode 1091 ** information need not be flushed. If the lower four bits of the flag 1092 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. 1093 ** If the lower four bits equal SQLITE_SYNC_FULL, that means 1094 ** to use Mac OS X style fullsync instead of fsync(). 1095 ** 1096 ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags 1097 ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL 1098 ** settings. The [synchronous pragma] determines when calls to the 1099 ** xSync VFS method occur and applies uniformly across all platforms. 1100 ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how 1101 ** energetic or rigorous or forceful the sync operations are and 1102 ** only make a difference on Mac OSX for the default SQLite code. 1103 ** (Third-party VFS implementations might also make the distinction 1104 ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the 1105 ** operating systems natively supported by SQLite, only Mac OSX 1106 ** cares about the difference.) 1107 */ 1108 #define SQLITE_SYNC_NORMAL 0x00002 1109 #define SQLITE_SYNC_FULL 0x00003 1110 #define SQLITE_SYNC_DATAONLY 0x00010 1111 1112 /* 1113 ** CAPI3REF: OS Interface Open File Handle 1114 ** 1115 ** An [sqlite3_file] object represents an open file in the 1116 ** [sqlite3_vfs | OS interface layer]. Individual OS interface 1117 ** implementations will 1118 ** want to subclass this object by appending additional fields 1119 ** for their own use. The pMethods entry is a pointer to an 1120 ** [sqlite3_io_methods] object that defines methods for performing 1121 ** I/O operations on the open file. 1122 */ 1123 typedef struct sqlite3_file sqlite3_file; 1124 struct sqlite3_file { 1125 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 1126 }; 1127 1128 /* 1129 ** CAPI3REF: OS Interface File Virtual Methods Object 1130 ** 1131 ** Every file opened by the [sqlite3_vfs] xOpen method populates an 1132 ** [sqlite3_file] object (or, more commonly, a subclass of the 1133 ** [sqlite3_file] object) with a pointer to an instance of this object. 1134 ** This object defines the methods used to perform various operations 1135 ** against the open file represented by the [sqlite3_file] object. 1136 ** 1137 ** If the xOpen method sets the sqlite3_file.pMethods element 1138 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 1139 ** may be invoked even if the xOpen reported that it failed. The 1140 ** only way to prevent a call to xClose following a failed xOpen 1141 ** is for the xOpen to set the sqlite3_file.pMethods element to NULL. 1142 ** 1143 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 1144 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 1145 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 1146 ** flag may be ORed in to indicate that only the data of the file 1147 ** and not its inode needs to be synced. 1148 ** 1149 ** The integer values to xLock() and xUnlock() are one of 1150 ** <ul> 1151 ** <li> [SQLITE_LOCK_NONE], 1152 ** <li> [SQLITE_LOCK_SHARED], 1153 ** <li> [SQLITE_LOCK_RESERVED], 1154 ** <li> [SQLITE_LOCK_PENDING], or 1155 ** <li> [SQLITE_LOCK_EXCLUSIVE]. 1156 ** </ul> 1157 ** xLock() increases the lock. xUnlock() decreases the lock. 1158 ** The xCheckReservedLock() method checks whether any database connection, 1159 ** either in this process or in some other process, is holding a RESERVED, 1160 ** PENDING, or EXCLUSIVE lock on the file. It returns true 1161 ** if such a lock exists and false otherwise. 1162 ** 1163 ** The xFileControl() method is a generic interface that allows custom 1164 ** VFS implementations to directly control an open file using the 1165 ** [sqlite3_file_control()] interface. The second "op" argument is an 1166 ** integer opcode. The third argument is a generic pointer intended to 1167 ** point to a structure that may contain arguments or space in which to 1168 ** write return values. Potential uses for xFileControl() might be 1169 ** functions to enable blocking locks with timeouts, to change the 1170 ** locking strategy (for example to use dot-file locks), to inquire 1171 ** about the status of a lock, or to break stale locks. The SQLite 1172 ** core reserves all opcodes less than 100 for its own use. 1173 ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. 1174 ** Applications that define a custom xFileControl method should use opcodes 1175 ** greater than 100 to avoid conflicts. 1176 ** 1177 ** The xSectorSize() method returns the sector size of the 1178 ** device that underlies the file. The sector size is the 1179 ** minimum write that can be performed without disturbing 1180 ** other bytes in the file. The xDeviceCharacteristics() 1181 ** method returns a bit vector describing behaviors of the 1182 ** underlying device: 1183 ** 1184 ** <ul> 1185 ** <li> [SQLITE_IOCAP_ATOMIC] 1186 ** <li> [SQLITE_IOCAP_ATOMIC512] 1187 ** <li> [SQLITE_IOCAP_ATOMIC1K] 1188 ** <li> [SQLITE_IOCAP_ATOMIC2K] 1189 ** <li> [SQLITE_IOCAP_ATOMIC4K] 1190 ** <li> [SQLITE_IOCAP_ATOMIC8K] 1191 ** <li> [SQLITE_IOCAP_ATOMIC16K] 1192 ** <li> [SQLITE_IOCAP_ATOMIC32K] 1193 ** <li> [SQLITE_IOCAP_ATOMIC64K] 1194 ** <li> [SQLITE_IOCAP_SAFE_APPEND] 1195 ** <li> [SQLITE_IOCAP_SEQUENTIAL] 1196 ** </ul> 1197 ** 1198 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 1199 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 1200 ** mean that writes of blocks that are nnn bytes in size and 1201 ** are aligned to an address which is an integer multiple of 1202 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 1203 ** that when data is appended to a file, the data is appended 1204 ** first then the size of the file is extended, never the other 1205 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 1206 ** information is written to disk in the same order as calls 1207 ** to xWrite(). 1208 ** 1209 ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill 1210 ** in the unread portions of the buffer with zeros. A VFS that 1211 ** fails to zero-fill short reads might seem to work. However, 1212 ** failure to zero-fill short reads will eventually lead to 1213 ** database corruption. 1214 */ 1215 typedef struct sqlite3_io_methods sqlite3_io_methods; 1216 struct sqlite3_io_methods { 1217 int iVersion; 1218 int (*xClose)(sqlite3_file*); 1219 int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 1220 int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); 1221 int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); 1222 int (*xSync)(sqlite3_file*, int flags); 1223 int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); 1224 int (*xLock)(sqlite3_file*, int); 1225 int (*xUnlock)(sqlite3_file*, int); 1226 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 1227 int (*xFileControl)(sqlite3_file*, int op, void *pArg); 1228 int (*xSectorSize)(sqlite3_file*); 1229 int (*xDeviceCharacteristics)(sqlite3_file*); 1230 /* Methods above are valid for version 1 */ 1231 int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); 1232 int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); 1233 void (*xShmBarrier)(sqlite3_file*); 1234 int (*xShmUnmap)(sqlite3_file*, int deleteFlag); 1235 /* Methods above are valid for version 2 */ 1236 /* Additional methods may be added in future releases */ 1237 }; 1238 1239 /* 1240 ** CAPI3REF: Standard File Control Opcodes 1241 ** 1242 ** These integer constants are opcodes for the xFileControl method 1243 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 1244 ** interface. 1245 ** 1246 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 1247 ** opcode causes the xFileControl method to write the current state of 1248 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 1249 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 1250 ** into an integer that the pArg argument points to. This capability 1251 ** is used during testing and only needs to be supported when SQLITE_TEST 1252 ** is defined. 1253 ** 1254 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS 1255 ** layer a hint of how large the database file will grow to be during the 1256 ** current transaction. This hint is not guaranteed to be accurate but it 1257 ** is often close. The underlying VFS might choose to preallocate database 1258 ** file space based on this hint in order to help writes to the database 1259 ** file run faster. 1260 ** 1261 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS 1262 ** extends and truncates the database file in chunks of a size specified 1263 ** by the user. The fourth argument to [sqlite3_file_control()] should 1264 ** point to an integer (type int) containing the new chunk-size to use 1265 ** for the nominated database. Allocating database file space in large 1266 ** chunks (say 1MB at a time), may reduce file-system fragmentation and 1267 ** improve performance on some systems. 1268 */ 1269 #define SQLITE_FCNTL_LOCKSTATE 1 1270 #define SQLITE_GET_LOCKPROXYFILE 2 1271 #define SQLITE_SET_LOCKPROXYFILE 3 1272 #define SQLITE_LAST_ERRNO 4 1273 #define SQLITE_FCNTL_SIZE_HINT 5 1274 #define SQLITE_FCNTL_CHUNK_SIZE 6 1275 #define SQLITE_FCNTL_FILE_POINTER 7 1276 1277 1278 /* 1279 ** CAPI3REF: Mutex Handle 1280 ** 1281 ** The mutex module within SQLite defines [sqlite3_mutex] to be an 1282 ** abstract type for a mutex object. The SQLite core never looks 1283 ** at the internal representation of an [sqlite3_mutex]. It only 1284 ** deals with pointers to the [sqlite3_mutex] object. 1285 ** 1286 ** Mutexes are created using [sqlite3_mutex_alloc()]. 1287 */ 1288 typedef struct sqlite3_mutex sqlite3_mutex; 1289 1290 /* 1291 ** CAPI3REF: OS Interface Object 1292 ** 1293 ** An instance of the sqlite3_vfs object defines the interface between 1294 ** the SQLite core and the underlying operating system. The "vfs" 1295 ** in the name of the object stands for "virtual file system". 1296 ** 1297 ** The value of the iVersion field is initially 1 but may be larger in 1298 ** future versions of SQLite. Additional fields may be appended to this 1299 ** object when the iVersion value is increased. Note that the structure 1300 ** of the sqlite3_vfs object changes in the transaction between 1301 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not 1302 ** modified. 1303 ** 1304 ** The szOsFile field is the size of the subclassed [sqlite3_file] 1305 ** structure used by this VFS. mxPathname is the maximum length of 1306 ** a pathname in this VFS. 1307 ** 1308 ** Registered sqlite3_vfs objects are kept on a linked list formed by 1309 ** the pNext pointer. The [sqlite3_vfs_register()] 1310 ** and [sqlite3_vfs_unregister()] interfaces manage this list 1311 ** in a thread-safe way. The [sqlite3_vfs_find()] interface 1312 ** searches the list. Neither the application code nor the VFS 1313 ** implementation should use the pNext pointer. 1314 ** 1315 ** The pNext field is the only field in the sqlite3_vfs 1316 ** structure that SQLite will ever modify. SQLite will only access 1317 ** or modify this field while holding a particular static mutex. 1318 ** The application should never modify anything within the sqlite3_vfs 1319 ** object once the object has been registered. 1320 ** 1321 ** The zName field holds the name of the VFS module. The name must 1322 ** be unique across all VFS modules. 1323 ** 1324 ** ^SQLite guarantees that the zFilename parameter to xOpen 1325 ** is either a NULL pointer or string obtained 1326 ** from xFullPathname() with an optional suffix added. 1327 ** ^If a suffix is added to the zFilename parameter, it will 1328 ** consist of a single "-" character followed by no more than 1329 ** 10 alphanumeric and/or "-" characters. 1330 ** ^SQLite further guarantees that 1331 ** the string will be valid and unchanged until xClose() is 1332 ** called. Because of the previous sentence, 1333 ** the [sqlite3_file] can safely store a pointer to the 1334 ** filename if it needs to remember the filename for some reason. 1335 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen 1336 ** must invent its own temporary name for the file. ^Whenever the 1337 ** xFilename parameter is NULL it will also be the case that the 1338 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 1339 ** 1340 ** The flags argument to xOpen() includes all bits set in 1341 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] 1342 ** or [sqlite3_open16()] is used, then flags includes at least 1343 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 1344 ** If xOpen() opens a file read-only then it sets *pOutFlags to 1345 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. 1346 ** 1347 ** ^(SQLite will also add one of the following flags to the xOpen() 1348 ** call, depending on the object being opened: 1349 ** 1350 ** <ul> 1351 ** <li> [SQLITE_OPEN_MAIN_DB] 1352 ** <li> [SQLITE_OPEN_MAIN_JOURNAL] 1353 ** <li> [SQLITE_OPEN_TEMP_DB] 1354 ** <li> [SQLITE_OPEN_TEMP_JOURNAL] 1355 ** <li> [SQLITE_OPEN_TRANSIENT_DB] 1356 ** <li> [SQLITE_OPEN_SUBJOURNAL] 1357 ** <li> [SQLITE_OPEN_MASTER_JOURNAL] 1358 ** <li> [SQLITE_OPEN_WAL] 1359 ** </ul>)^ 1360 ** 1361 ** The file I/O implementation can use the object type flags to 1362 ** change the way it deals with files. For example, an application 1363 ** that does not care about crash recovery or rollback might make 1364 ** the open of a journal file a no-op. Writes to this journal would 1365 ** also be no-ops, and any attempt to read the journal would return 1366 ** SQLITE_IOERR. Or the implementation might recognize that a database 1367 ** file will be doing page-aligned sector reads and writes in a random 1368 ** order and set up its I/O subsystem accordingly. 1369 ** 1370 ** SQLite might also add one of the following flags to the xOpen method: 1371 ** 1372 ** <ul> 1373 ** <li> [SQLITE_OPEN_DELETEONCLOSE] 1374 ** <li> [SQLITE_OPEN_EXCLUSIVE] 1375 ** </ul> 1376 ** 1377 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be 1378 ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] 1379 ** will be set for TEMP databases and their journals, transient 1380 ** databases, and subjournals. 1381 ** 1382 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction 1383 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly 1384 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() 1385 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 1386 ** SQLITE_OPEN_CREATE, is used to indicate that file should always 1387 ** be created, and that it is an error if it already exists. 1388 ** It is <i>not</i> used to indicate the file should be opened 1389 ** for exclusive access. 1390 ** 1391 ** ^At least szOsFile bytes of memory are allocated by SQLite 1392 ** to hold the [sqlite3_file] structure passed as the third 1393 ** argument to xOpen. The xOpen method does not have to 1394 ** allocate the structure; it should just fill it in. Note that 1395 ** the xOpen method must set the sqlite3_file.pMethods to either 1396 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 1397 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 1398 ** element will be valid after xOpen returns regardless of the success 1399 ** or failure of the xOpen call. 1400 ** 1401 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 1402 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 1403 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 1404 ** to test whether a file is at least readable. The file can be a 1405 ** directory. 1406 ** 1407 ** ^SQLite will always allocate at least mxPathname+1 bytes for the 1408 ** output buffer xFullPathname. The exact size of the output buffer 1409 ** is also passed as a parameter to both methods. If the output buffer 1410 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 1411 ** handled as a fatal error by SQLite, vfs implementations should endeavor 1412 ** to prevent this by setting mxPathname to a sufficiently large value. 1413 ** 1414 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() 1415 ** interfaces are not strictly a part of the filesystem, but they are 1416 ** included in the VFS structure for completeness. 1417 ** The xRandomness() function attempts to return nBytes bytes 1418 ** of good-quality randomness into zOut. The return value is 1419 ** the actual number of bytes of randomness obtained. 1420 ** The xSleep() method causes the calling thread to sleep for at 1421 ** least the number of microseconds given. ^The xCurrentTime() 1422 ** method returns a Julian Day Number for the current date and time as 1423 ** a floating point value. 1424 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian 1425 ** Day Number multipled by 86400000 (the number of milliseconds in 1426 ** a 24-hour day). 1427 ** ^SQLite will use the xCurrentTimeInt64() method to get the current 1428 ** date and time if that method is available (if iVersion is 2 or 1429 ** greater and the function pointer is not NULL) and will fall back 1430 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. 1431 */ 1432 typedef struct sqlite3_vfs sqlite3_vfs; 1433 struct sqlite3_vfs { 1434 int iVersion; /* Structure version number (currently 2) */ 1435 int szOsFile; /* Size of subclassed sqlite3_file */ 1436 int mxPathname; /* Maximum file pathname length */ 1437 sqlite3_vfs *pNext; /* Next registered VFS */ 1438 const char *zName; /* Name of this virtual file system */ 1439 void *pAppData; /* Pointer to application-specific data */ 1440 int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, 1441 int flags, int *pOutFlags); 1442 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); 1443 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); 1444 int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); 1445 void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); 1446 void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); 1447 void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); 1448 void (*xDlClose)(sqlite3_vfs*, void*); 1449 int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); 1450 int (*xSleep)(sqlite3_vfs*, int microseconds); 1451 int (*xCurrentTime)(sqlite3_vfs*, double*); 1452 int (*xGetLastError)(sqlite3_vfs*, int, char *); 1453 /* 1454 ** The methods above are in version 1 of the sqlite_vfs object 1455 ** definition. Those that follow are added in version 2 or later 1456 */ 1457 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); 1458 /* 1459 ** The methods above are in versions 1 and 2 of the sqlite_vfs object. 1460 ** New fields may be appended in figure versions. The iVersion 1461 ** value will increment whenever this happens. 1462 */ 1463 }; 1464 1465 /* 1466 ** CAPI3REF: Flags for the xAccess VFS method 1467 ** 1468 ** These integer constants can be used as the third parameter to 1469 ** the xAccess method of an [sqlite3_vfs] object. They determine 1470 ** what kind of permissions the xAccess method is looking for. 1471 ** With SQLITE_ACCESS_EXISTS, the xAccess method 1472 ** simply checks whether the file exists. 1473 ** With SQLITE_ACCESS_READWRITE, the xAccess method 1474 ** checks whether the named directory is both readable and writable 1475 ** (in other words, if files can be added, removed, and renamed within 1476 ** the directory). 1477 ** The SQLITE_ACCESS_READWRITE constant is currently used only by the 1478 ** [temp_store_directory pragma], though this could change in a future 1479 ** release of SQLite. 1480 ** With SQLITE_ACCESS_READ, the xAccess method 1481 ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is 1482 ** currently unused, though it might be used in a future release of 1483 ** SQLite. 1484 */ 1485 #define SQLITE_ACCESS_EXISTS 0 1486 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ 1487 #define SQLITE_ACCESS_READ 2 /* Unused */ 1488 1489 /* 1490 ** CAPI3REF: Flags for the xShmLock VFS method 1491 ** 1492 ** These integer constants define the various locking operations 1493 ** allowed by the xShmLock method of [sqlite3_io_methods]. The 1494 ** following are the only legal combinations of flags to the 1495 ** xShmLock method: 1496 ** 1497 ** <ul> 1498 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED 1499 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE 1500 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED 1501 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE 1502 ** </ul> 1503 ** 1504 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as 1505 ** was given no the corresponding lock. 1506 ** 1507 ** The xShmLock method can transition between unlocked and SHARED or 1508 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED 1509 ** and EXCLUSIVE. 1510 */ 1511 #define SQLITE_SHM_UNLOCK 1 1512 #define SQLITE_SHM_LOCK 2 1513 #define SQLITE_SHM_SHARED 4 1514 #define SQLITE_SHM_EXCLUSIVE 8 1515 1516 /* 1517 ** CAPI3REF: Maximum xShmLock index 1518 ** 1519 ** The xShmLock method on [sqlite3_io_methods] may use values 1520 ** between 0 and this upper bound as its "offset" argument. 1521 ** The SQLite core will never attempt to acquire or release a 1522 ** lock outside of this range 1523 */ 1524 #define SQLITE_SHM_NLOCK 8 1525 1526 1527 /* 1528 ** CAPI3REF: Initialize The SQLite Library 1529 ** 1530 ** ^The sqlite3_initialize() routine initializes the 1531 ** SQLite library. ^The sqlite3_shutdown() routine 1532 ** deallocates any resources that were allocated by sqlite3_initialize(). 1533 ** These routines are designed to aid in process initialization and 1534 ** shutdown on embedded systems. Workstation applications using 1535 ** SQLite normally do not need to invoke either of these routines. 1536 ** 1537 ** A call to sqlite3_initialize() is an "effective" call if it is 1538 ** the first time sqlite3_initialize() is invoked during the lifetime of 1539 ** the process, or if it is the first time sqlite3_initialize() is invoked 1540 ** following a call to sqlite3_shutdown(). ^(Only an effective call 1541 ** of sqlite3_initialize() does any initialization. All other calls 1542 ** are harmless no-ops.)^ 1543 ** 1544 ** A call to sqlite3_shutdown() is an "effective" call if it is the first 1545 ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only 1546 ** an effective call to sqlite3_shutdown() does any deinitialization. 1547 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ 1548 ** 1549 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() 1550 ** is not. The sqlite3_shutdown() interface must only be called from a 1551 ** single thread. All open [database connections] must be closed and all 1552 ** other SQLite resources must be deallocated prior to invoking 1553 ** sqlite3_shutdown(). 1554 ** 1555 ** Among other things, ^sqlite3_initialize() will invoke 1556 ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() 1557 ** will invoke sqlite3_os_end(). 1558 ** 1559 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. 1560 ** ^If for some reason, sqlite3_initialize() is unable to initialize 1561 ** the library (perhaps it is unable to allocate a needed resource such 1562 ** as a mutex) it returns an [error code] other than [SQLITE_OK]. 1563 ** 1564 ** ^The sqlite3_initialize() routine is called internally by many other 1565 ** SQLite interfaces so that an application usually does not need to 1566 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] 1567 ** calls sqlite3_initialize() so the SQLite library will be automatically 1568 ** initialized when [sqlite3_open()] is called if it has not be initialized 1569 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] 1570 ** compile-time option, then the automatic calls to sqlite3_initialize() 1571 ** are omitted and the application must call sqlite3_initialize() directly 1572 ** prior to using any other SQLite interface. For maximum portability, 1573 ** it is recommended that applications always invoke sqlite3_initialize() 1574 ** directly prior to using any other SQLite interface. Future releases 1575 ** of SQLite may require this. In other words, the behavior exhibited 1576 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the 1577 ** default behavior in some future release of SQLite. 1578 ** 1579 ** The sqlite3_os_init() routine does operating-system specific 1580 ** initialization of the SQLite library. The sqlite3_os_end() 1581 ** routine undoes the effect of sqlite3_os_init(). Typical tasks 1582 ** performed by these routines include allocation or deallocation 1583 ** of static resources, initialization of global variables, 1584 ** setting up a default [sqlite3_vfs] module, or setting up 1585 ** a default configuration using [sqlite3_config()]. 1586 ** 1587 ** The application should never invoke either sqlite3_os_init() 1588 ** or sqlite3_os_end() directly. The application should only invoke 1589 ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() 1590 ** interface is called automatically by sqlite3_initialize() and 1591 ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate 1592 ** implementations for sqlite3_os_init() and sqlite3_os_end() 1593 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. 1594 ** When [custom builds | built for other platforms] 1595 ** (using the [SQLITE_OS_OTHER=1] compile-time 1596 ** option) the application must supply a suitable implementation for 1597 ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied 1598 ** implementation of sqlite3_os_init() or sqlite3_os_end() 1599 ** must return [SQLITE_OK] on success and some other [error code] upon 1600 ** failure. 1601 */ 1602 SQLITE_API int sqlite3_initialize(void); 1603 SQLITE_API int sqlite3_shutdown(void); 1604 SQLITE_API int sqlite3_os_init(void); 1605 SQLITE_API int sqlite3_os_end(void); 1606 1607 /* 1608 ** CAPI3REF: Configuring The SQLite Library 1609 ** 1610 ** The sqlite3_config() interface is used to make global configuration 1611 ** changes to SQLite in order to tune SQLite to the specific needs of 1612 ** the application. The default configuration is recommended for most 1613 ** applications and so this routine is usually not necessary. It is 1614 ** provided to support rare applications with unusual needs. 1615 ** 1616 ** The sqlite3_config() interface is not threadsafe. The application 1617 ** must insure that no other SQLite interfaces are invoked by other 1618 ** threads while sqlite3_config() is running. Furthermore, sqlite3_config() 1619 ** may only be invoked prior to library initialization using 1620 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 1621 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 1622 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. 1623 ** Note, however, that ^sqlite3_config() can be called as part of the 1624 ** implementation of an application-defined [sqlite3_os_init()]. 1625 ** 1626 ** The first argument to sqlite3_config() is an integer 1627 ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines 1628 ** what property of SQLite is to be configured. Subsequent arguments 1629 ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] 1630 ** in the first argument. 1631 ** 1632 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 1633 ** ^If the option is unknown or SQLite is unable to set the option 1634 ** then this routine returns a non-zero [error code]. 1635 */ 1636 SQLITE_API int sqlite3_config(int, ...); 1637 1638 /* 1639 ** CAPI3REF: Configure database connections 1640 ** 1641 ** The sqlite3_db_config() interface is used to make configuration 1642 ** changes to a [database connection]. The interface is similar to 1643 ** [sqlite3_config()] except that the changes apply to a single 1644 ** [database connection] (specified in the first argument). The 1645 ** sqlite3_db_config() interface should only be used immediately after 1646 ** the database connection is created using [sqlite3_open()], 1647 ** [sqlite3_open16()], or [sqlite3_open_v2()]. 1648 ** 1649 ** The second argument to sqlite3_db_config(D,V,...) is the 1650 ** configuration verb - an integer code that indicates what 1651 ** aspect of the [database connection] is being configured. 1652 ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE]. 1653 ** New verbs are likely to be added in future releases of SQLite. 1654 ** Additional arguments depend on the verb. 1655 ** 1656 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if 1657 ** the call is considered successful. 1658 */ 1659 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); 1660 1661 /* 1662 ** CAPI3REF: Memory Allocation Routines 1663 ** 1664 ** An instance of this object defines the interface between SQLite 1665 ** and low-level memory allocation routines. 1666 ** 1667 ** This object is used in only one place in the SQLite interface. 1668 ** A pointer to an instance of this object is the argument to 1669 ** [sqlite3_config()] when the configuration option is 1670 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. 1671 ** By creating an instance of this object 1672 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) 1673 ** during configuration, an application can specify an alternative 1674 ** memory allocation subsystem for SQLite to use for all of its 1675 ** dynamic memory needs. 1676 ** 1677 ** Note that SQLite comes with several [built-in memory allocators] 1678 ** that are perfectly adequate for the overwhelming majority of applications 1679 ** and that this object is only useful to a tiny minority of applications 1680 ** with specialized memory allocation requirements. This object is 1681 ** also used during testing of SQLite in order to specify an alternative 1682 ** memory allocator that simulates memory out-of-memory conditions in 1683 ** order to verify that SQLite recovers gracefully from such 1684 ** conditions. 1685 ** 1686 ** The xMalloc and xFree methods must work like the 1687 ** malloc() and free() functions from the standard C library. 1688 ** The xRealloc method must work like realloc() from the standard C library 1689 ** with the exception that if the second argument to xRealloc is zero, 1690 ** xRealloc must be a no-op - it must not perform any allocation or 1691 ** deallocation. ^SQLite guarantees that the second argument to 1692 ** xRealloc is always a value returned by a prior call to xRoundup. 1693 ** And so in cases where xRoundup always returns a positive number, 1694 ** xRealloc can perform exactly as the standard library realloc() and 1695 ** still be in compliance with this specification. 1696 ** 1697 ** xSize should return the allocated size of a memory allocation 1698 ** previously obtained from xMalloc or xRealloc. The allocated size 1699 ** is always at least as big as the requested size but may be larger. 1700 ** 1701 ** The xRoundup method returns what would be the allocated size of 1702 ** a memory allocation given a particular requested size. Most memory 1703 ** allocators round up memory allocations at least to the next multiple 1704 ** of 8. Some allocators round up to a larger multiple or to a power of 2. 1705 ** Every memory allocation request coming in through [sqlite3_malloc()] 1706 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 1707 ** that causes the corresponding memory allocation to fail. 1708 ** 1709 ** The xInit method initializes the memory allocator. (For example, 1710 ** it might allocate any require mutexes or initialize internal data 1711 ** structures. The xShutdown method is invoked (indirectly) by 1712 ** [sqlite3_shutdown()] and should deallocate any resources acquired 1713 ** by xInit. The pAppData pointer is used as the only parameter to 1714 ** xInit and xShutdown. 1715 ** 1716 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes 1717 ** the xInit method, so the xInit method need not be threadsafe. The 1718 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 1719 ** not need to be threadsafe either. For all other methods, SQLite 1720 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the 1721 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which 1722 ** it is by default) and so the methods are automatically serialized. 1723 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other 1724 ** methods must be threadsafe or else make their own arrangements for 1725 ** serialization. 1726 ** 1727 ** SQLite will never invoke xInit() more than once without an intervening 1728 ** call to xShutdown(). 1729 */ 1730 typedef struct sqlite3_mem_methods sqlite3_mem_methods; 1731 struct sqlite3_mem_methods { 1732 void *(*xMalloc)(int); /* Memory allocation function */ 1733 void (*xFree)(void*); /* Free a prior allocation */ 1734 void *(*xRealloc)(void*,int); /* Resize an allocation */ 1735 int (*xSize)(void*); /* Return the size of an allocation */ 1736 int (*xRoundup)(int); /* Round up request size to allocation size */ 1737 int (*xInit)(void*); /* Initialize the memory allocator */ 1738 void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 1739 void *pAppData; /* Argument to xInit() and xShutdown() */ 1740 }; 1741 1742 /* 1743 ** CAPI3REF: Configuration Options 1744 ** 1745 ** These constants are the available integer configuration options that 1746 ** can be passed as the first argument to the [sqlite3_config()] interface. 1747 ** 1748 ** New configuration options may be added in future releases of SQLite. 1749 ** Existing configuration options might be discontinued. Applications 1750 ** should check the return code from [sqlite3_config()] to make sure that 1751 ** the call worked. The [sqlite3_config()] interface will return a 1752 ** non-zero [error code] if a discontinued or unsupported configuration option 1753 ** is invoked. 1754 ** 1755 ** <dl> 1756 ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 1757 ** <dd>There are no arguments to this option. ^This option sets the 1758 ** [threading mode] to Single-thread. In other words, it disables 1759 ** all mutexing and puts SQLite into a mode where it can only be used 1760 ** by a single thread. ^If SQLite is compiled with 1761 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1762 ** it is not possible to change the [threading mode] from its default 1763 ** value of Single-thread and so [sqlite3_config()] will return 1764 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 1765 ** configuration option.</dd> 1766 ** 1767 ** <dt>SQLITE_CONFIG_MULTITHREAD</dt> 1768 ** <dd>There are no arguments to this option. ^This option sets the 1769 ** [threading mode] to Multi-thread. In other words, it disables 1770 ** mutexing on [database connection] and [prepared statement] objects. 1771 ** The application is responsible for serializing access to 1772 ** [database connections] and [prepared statements]. But other mutexes 1773 ** are enabled so that SQLite will be safe to use in a multi-threaded 1774 ** environment as long as no two threads attempt to use the same 1775 ** [database connection] at the same time. ^If SQLite is compiled with 1776 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1777 ** it is not possible to set the Multi-thread [threading mode] and 1778 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1779 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 1780 ** 1781 ** <dt>SQLITE_CONFIG_SERIALIZED</dt> 1782 ** <dd>There are no arguments to this option. ^This option sets the 1783 ** [threading mode] to Serialized. In other words, this option enables 1784 ** all mutexes including the recursive 1785 ** mutexes on [database connection] and [prepared statement] objects. 1786 ** In this mode (which is the default when SQLite is compiled with 1787 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 1788 ** to [database connections] and [prepared statements] so that the 1789 ** application is free to use the same [database connection] or the 1790 ** same [prepared statement] in different threads at the same time. 1791 ** ^If SQLite is compiled with 1792 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1793 ** it is not possible to set the Serialized [threading mode] and 1794 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1795 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 1796 ** 1797 ** <dt>SQLITE_CONFIG_MALLOC</dt> 1798 ** <dd> ^(This option takes a single argument which is a pointer to an 1799 ** instance of the [sqlite3_mem_methods] structure. The argument specifies 1800 ** alternative low-level memory allocation routines to be used in place of 1801 ** the memory allocation routines built into SQLite.)^ ^SQLite makes 1802 ** its own private copy of the content of the [sqlite3_mem_methods] structure 1803 ** before the [sqlite3_config()] call returns.</dd> 1804 ** 1805 ** <dt>SQLITE_CONFIG_GETMALLOC</dt> 1806 ** <dd> ^(This option takes a single argument which is a pointer to an 1807 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] 1808 ** structure is filled with the currently defined memory allocation routines.)^ 1809 ** This option can be used to overload the default memory allocation 1810 ** routines with a wrapper that simulations memory allocation failure or 1811 ** tracks memory usage, for example. </dd> 1812 ** 1813 ** <dt>SQLITE_CONFIG_MEMSTATUS</dt> 1814 ** <dd> ^This option takes single argument of type int, interpreted as a 1815 ** boolean, which enables or disables the collection of memory allocation 1816 ** statistics. ^(When memory allocation statistics are disabled, the 1817 ** following SQLite interfaces become non-operational: 1818 ** <ul> 1819 ** <li> [sqlite3_memory_used()] 1820 ** <li> [sqlite3_memory_highwater()] 1821 ** <li> [sqlite3_soft_heap_limit64()] 1822 ** <li> [sqlite3_status()] 1823 ** </ul>)^ 1824 ** ^Memory allocation statistics are enabled by default unless SQLite is 1825 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 1826 ** allocation statistics are disabled by default. 1827 ** </dd> 1828 ** 1829 ** <dt>SQLITE_CONFIG_SCRATCH</dt> 1830 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 1831 ** scratch memory. There are three arguments: A pointer an 8-byte 1832 ** aligned memory buffer from which the scrach allocations will be 1833 ** drawn, the size of each scratch allocation (sz), 1834 ** and the maximum number of scratch allocations (N). The sz 1835 ** argument must be a multiple of 16. 1836 ** The first argument must be a pointer to an 8-byte aligned buffer 1837 ** of at least sz*N bytes of memory. 1838 ** ^SQLite will use no more than two scratch buffers per thread. So 1839 ** N should be set to twice the expected maximum number of threads. 1840 ** ^SQLite will never require a scratch buffer that is more than 6 1841 ** times the database page size. ^If SQLite needs needs additional 1842 ** scratch memory beyond what is provided by this configuration option, then 1843 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 1844 ** 1845 ** <dt>SQLITE_CONFIG_PAGECACHE</dt> 1846 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 1847 ** the database page cache with the default page cache implemenation. 1848 ** This configuration should not be used if an application-define page 1849 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. 1850 ** There are three arguments to this option: A pointer to 8-byte aligned 1851 ** memory, the size of each page buffer (sz), and the number of pages (N). 1852 ** The sz argument should be the size of the largest database page 1853 ** (a power of two between 512 and 32768) plus a little extra for each 1854 ** page header. ^The page header size is 20 to 40 bytes depending on 1855 ** the host architecture. ^It is harmless, apart from the wasted memory, 1856 ** to make sz a little too large. The first 1857 ** argument should point to an allocation of at least sz*N bytes of memory. 1858 ** ^SQLite will use the memory provided by the first argument to satisfy its 1859 ** memory needs for the first N pages that it adds to cache. ^If additional 1860 ** page cache memory is needed beyond what is provided by this option, then 1861 ** SQLite goes to [sqlite3_malloc()] for the additional storage space. 1862 ** The pointer in the first argument must 1863 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite 1864 ** will be undefined.</dd> 1865 ** 1866 ** <dt>SQLITE_CONFIG_HEAP</dt> 1867 ** <dd> ^This option specifies a static memory buffer that SQLite will use 1868 ** for all of its dynamic memory allocation needs beyond those provided 1869 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. 1870 ** There are three arguments: An 8-byte aligned pointer to the memory, 1871 ** the number of bytes in the memory buffer, and the minimum allocation size. 1872 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 1873 ** to using its default memory allocator (the system malloc() implementation), 1874 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 1875 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or 1876 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory 1877 ** allocator is engaged to handle all of SQLites memory allocation needs. 1878 ** The first pointer (the memory pointer) must be aligned to an 8-byte 1879 ** boundary or subsequent behavior of SQLite will be undefined.</dd> 1880 ** 1881 ** <dt>SQLITE_CONFIG_MUTEX</dt> 1882 ** <dd> ^(This option takes a single argument which is a pointer to an 1883 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies 1884 ** alternative low-level mutex routines to be used in place 1885 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the 1886 ** content of the [sqlite3_mutex_methods] structure before the call to 1887 ** [sqlite3_config()] returns. ^If SQLite is compiled with 1888 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1889 ** the entire mutexing subsystem is omitted from the build and hence calls to 1890 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 1891 ** return [SQLITE_ERROR].</dd> 1892 ** 1893 ** <dt>SQLITE_CONFIG_GETMUTEX</dt> 1894 ** <dd> ^(This option takes a single argument which is a pointer to an 1895 ** instance of the [sqlite3_mutex_methods] structure. The 1896 ** [sqlite3_mutex_methods] 1897 ** structure is filled with the currently defined mutex routines.)^ 1898 ** This option can be used to overload the default mutex allocation 1899 ** routines with a wrapper used to track mutex usage for performance 1900 ** profiling or testing, for example. ^If SQLite is compiled with 1901 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1902 ** the entire mutexing subsystem is omitted from the build and hence calls to 1903 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 1904 ** return [SQLITE_ERROR].</dd> 1905 ** 1906 ** <dt>SQLITE_CONFIG_LOOKASIDE</dt> 1907 ** <dd> ^(This option takes two arguments that determine the default 1908 ** memory allocation for the lookaside memory allocator on each 1909 ** [database connection]. The first argument is the 1910 ** size of each lookaside buffer slot and the second is the number of 1911 ** slots allocated to each database connection.)^ ^(This option sets the 1912 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 1913 ** verb to [sqlite3_db_config()] can be used to change the lookaside 1914 ** configuration on individual connections.)^ </dd> 1915 ** 1916 ** <dt>SQLITE_CONFIG_PCACHE</dt> 1917 ** <dd> ^(This option takes a single argument which is a pointer to 1918 ** an [sqlite3_pcache_methods] object. This object specifies the interface 1919 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the 1920 ** object and uses it for page cache memory allocations.</dd> 1921 ** 1922 ** <dt>SQLITE_CONFIG_GETPCACHE</dt> 1923 ** <dd> ^(This option takes a single argument which is a pointer to an 1924 ** [sqlite3_pcache_methods] object. SQLite copies of the current 1925 ** page cache implementation into that object.)^ </dd> 1926 ** 1927 ** <dt>SQLITE_CONFIG_LOG</dt> 1928 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 1929 ** function with a call signature of void(*)(void*,int,const char*), 1930 ** and a pointer to void. ^If the function pointer is not NULL, it is 1931 ** invoked by [sqlite3_log()] to process each logging event. ^If the 1932 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. 1933 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is 1934 ** passed through as the first parameter to the application-defined logger 1935 ** function whenever that function is invoked. ^The second parameter to 1936 ** the logger function is a copy of the first parameter to the corresponding 1937 ** [sqlite3_log()] call and is intended to be a [result code] or an 1938 ** [extended result code]. ^The third parameter passed to the logger is 1939 ** log message after formatting via [sqlite3_snprintf()]. 1940 ** The SQLite logging interface is not reentrant; the logger function 1941 ** supplied by the application must not invoke any SQLite interface. 1942 ** In a multi-threaded application, the application-defined logger 1943 ** function must be threadsafe. </dd> 1944 ** 1945 ** </dl> 1946 */ 1947 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 1948 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 1949 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 1950 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 1951 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 1952 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ 1953 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 1954 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 1955 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 1956 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 1957 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 1958 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 1959 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 1960 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ 1961 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ 1962 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 1963 1964 /* 1965 ** CAPI3REF: Database Connection Configuration Options 1966 ** 1967 ** These constants are the available integer configuration options that 1968 ** can be passed as the second argument to the [sqlite3_db_config()] interface. 1969 ** 1970 ** New configuration options may be added in future releases of SQLite. 1971 ** Existing configuration options might be discontinued. Applications 1972 ** should check the return code from [sqlite3_db_config()] to make sure that 1973 ** the call worked. ^The [sqlite3_db_config()] interface will return a 1974 ** non-zero [error code] if a discontinued or unsupported configuration option 1975 ** is invoked. 1976 ** 1977 ** <dl> 1978 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> 1979 ** <dd> ^This option takes three additional arguments that determine the 1980 ** [lookaside memory allocator] configuration for the [database connection]. 1981 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a 1982 ** pointer to an memory buffer to use for lookaside memory. 1983 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb 1984 ** may be NULL in which case SQLite will allocate the 1985 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the 1986 ** size of each lookaside buffer slot. ^The third argument is the number of 1987 ** slots. The size of the buffer in the first argument must be greater than 1988 ** or equal to the product of the second and third arguments. The buffer 1989 ** must be aligned to an 8-byte boundary. ^If the second argument to 1990 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally 1991 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory 1992 ** configuration for a database connection can only be changed when that 1993 ** connection is not currently using lookaside memory, or in other words 1994 ** when the "current value" returned by 1995 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. 1996 ** Any attempt to change the lookaside memory configuration when lookaside 1997 ** memory is in use leaves the configuration unchanged and returns 1998 ** [SQLITE_BUSY].)^</dd> 1999 ** 2000 ** </dl> 2001 */ 2002 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ 2003 2004 2005 /* 2006 ** CAPI3REF: Enable Or Disable Extended Result Codes 2007 ** 2008 ** ^The sqlite3_extended_result_codes() routine enables or disables the 2009 ** [extended result codes] feature of SQLite. ^The extended result 2010 ** codes are disabled by default for historical compatibility. 2011 */ 2012 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); 2013 2014 /* 2015 ** CAPI3REF: Last Insert Rowid 2016 ** 2017 ** ^Each entry in an SQLite table has a unique 64-bit signed 2018 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available 2019 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 2020 ** names are not also used by explicitly declared columns. ^If 2021 ** the table has a column of type [INTEGER PRIMARY KEY] then that column 2022 ** is another alias for the rowid. 2023 ** 2024 ** ^This routine returns the [rowid] of the most recent 2025 ** successful [INSERT] into the database from the [database connection] 2026 ** in the first argument. ^If no successful [INSERT]s 2027 ** have ever occurred on that database connection, zero is returned. 2028 ** 2029 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted 2030 ** row is returned by this routine as long as the trigger is running. 2031 ** But once the trigger terminates, the value returned by this routine 2032 ** reverts to the last value inserted before the trigger fired.)^ 2033 ** 2034 ** ^An [INSERT] that fails due to a constraint violation is not a 2035 ** successful [INSERT] and does not change the value returned by this 2036 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 2037 ** and INSERT OR ABORT make no changes to the return value of this 2038 ** routine when their insertion fails. ^(When INSERT OR REPLACE 2039 ** encounters a constraint violation, it does not fail. The 2040 ** INSERT continues to completion after deleting rows that caused 2041 ** the constraint problem so INSERT OR REPLACE will always change 2042 ** the return value of this interface.)^ 2043 ** 2044 ** ^For the purposes of this routine, an [INSERT] is considered to 2045 ** be successful even if it is subsequently rolled back. 2046 ** 2047 ** This function is accessible to SQL statements via the 2048 ** [last_insert_rowid() SQL function]. 2049 ** 2050 ** If a separate thread performs a new [INSERT] on the same 2051 ** database connection while the [sqlite3_last_insert_rowid()] 2052 ** function is running and thus changes the last insert [rowid], 2053 ** then the value returned by [sqlite3_last_insert_rowid()] is 2054 ** unpredictable and might not equal either the old or the new 2055 ** last insert [rowid]. 2056 */ 2057 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 2058 2059 /* 2060 ** CAPI3REF: Count The Number Of Rows Modified 2061 ** 2062 ** ^This function returns the number of database rows that were changed 2063 ** or inserted or deleted by the most recently completed SQL statement 2064 ** on the [database connection] specified by the first parameter. 2065 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE], 2066 ** or [DELETE] statement are counted. Auxiliary changes caused by 2067 ** triggers or [foreign key actions] are not counted.)^ Use the 2068 ** [sqlite3_total_changes()] function to find the total number of changes 2069 ** including changes caused by triggers and foreign key actions. 2070 ** 2071 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger] 2072 ** are not counted. Only real table changes are counted. 2073 ** 2074 ** ^(A "row change" is a change to a single row of a single table 2075 ** caused by an INSERT, DELETE, or UPDATE statement. Rows that 2076 ** are changed as side effects of [REPLACE] constraint resolution, 2077 ** rollback, ABORT processing, [DROP TABLE], or by any other 2078 ** mechanisms do not count as direct row changes.)^ 2079 ** 2080 ** A "trigger context" is a scope of execution that begins and 2081 ** ends with the script of a [CREATE TRIGGER | trigger]. 2082 ** Most SQL statements are 2083 ** evaluated outside of any trigger. This is the "top level" 2084 ** trigger context. If a trigger fires from the top level, a 2085 ** new trigger context is entered for the duration of that one 2086 ** trigger. Subtriggers create subcontexts for their duration. 2087 ** 2088 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does 2089 ** not create a new trigger context. 2090 ** 2091 ** ^This function returns the number of direct row changes in the 2092 ** most recent INSERT, UPDATE, or DELETE statement within the same 2093 ** trigger context. 2094 ** 2095 ** ^Thus, when called from the top level, this function returns the 2096 ** number of changes in the most recent INSERT, UPDATE, or DELETE 2097 ** that also occurred at the top level. ^(Within the body of a trigger, 2098 ** the sqlite3_changes() interface can be called to find the number of 2099 ** changes in the most recently completed INSERT, UPDATE, or DELETE 2100 ** statement within the body of the same trigger. 2101 ** However, the number returned does not include changes 2102 ** caused by subtriggers since those have their own context.)^ 2103 ** 2104 ** See also the [sqlite3_total_changes()] interface, the 2105 ** [count_changes pragma], and the [changes() SQL function]. 2106 ** 2107 ** If a separate thread makes changes on the same database connection 2108 ** while [sqlite3_changes()] is running then the value returned 2109 ** is unpredictable and not meaningful. 2110 */ 2111 SQLITE_API int sqlite3_changes(sqlite3*); 2112 2113 /* 2114 ** CAPI3REF: Total Number Of Rows Modified 2115 ** 2116 ** ^This function returns the number of row changes caused by [INSERT], 2117 ** [UPDATE] or [DELETE] statements since the [database connection] was opened. 2118 ** ^(The count returned by sqlite3_total_changes() includes all changes 2119 ** from all [CREATE TRIGGER | trigger] contexts and changes made by 2120 ** [foreign key actions]. However, 2121 ** the count does not include changes used to implement [REPLACE] constraints, 2122 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The 2123 ** count does not include rows of views that fire an [INSTEAD OF trigger], 2124 ** though if the INSTEAD OF trigger makes changes of its own, those changes 2125 ** are counted.)^ 2126 ** ^The sqlite3_total_changes() function counts the changes as soon as 2127 ** the statement that makes them is completed (when the statement handle 2128 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). 2129 ** 2130 ** See also the [sqlite3_changes()] interface, the 2131 ** [count_changes pragma], and the [total_changes() SQL function]. 2132 ** 2133 ** If a separate thread makes changes on the same database connection 2134 ** while [sqlite3_total_changes()] is running then the value 2135 ** returned is unpredictable and not meaningful. 2136 */ 2137 SQLITE_API int sqlite3_total_changes(sqlite3*); 2138 2139 /* 2140 ** CAPI3REF: Interrupt A Long-Running Query 2141 ** 2142 ** ^This function causes any pending database operation to abort and 2143 ** return at its earliest opportunity. This routine is typically 2144 ** called in response to a user action such as pressing "Cancel" 2145 ** or Ctrl-C where the user wants a long query operation to halt 2146 ** immediately. 2147 ** 2148 ** ^It is safe to call this routine from a thread different from the 2149 ** thread that is currently running the database operation. But it 2150 ** is not safe to call this routine with a [database connection] that 2151 ** is closed or might close before sqlite3_interrupt() returns. 2152 ** 2153 ** ^If an SQL operation is very nearly finished at the time when 2154 ** sqlite3_interrupt() is called, then it might not have an opportunity 2155 ** to be interrupted and might continue to completion. 2156 ** 2157 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. 2158 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE 2159 ** that is inside an explicit transaction, then the entire transaction 2160 ** will be rolled back automatically. 2161 ** 2162 ** ^The sqlite3_interrupt(D) call is in effect until all currently running 2163 ** SQL statements on [database connection] D complete. ^Any new SQL statements 2164 ** that are started after the sqlite3_interrupt() call and before the 2165 ** running statements reaches zero are interrupted as if they had been 2166 ** running prior to the sqlite3_interrupt() call. ^New SQL statements 2167 ** that are started after the running statement count reaches zero are 2168 ** not effected by the sqlite3_interrupt(). 2169 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running 2170 ** SQL statements is a no-op and has no effect on SQL statements 2171 ** that are started after the sqlite3_interrupt() call returns. 2172 ** 2173 ** If the database connection closes while [sqlite3_interrupt()] 2174 ** is running then bad things will likely happen. 2175 */ 2176 SQLITE_API void sqlite3_interrupt(sqlite3*); 2177 2178 /* 2179 ** CAPI3REF: Determine If An SQL Statement Is Complete 2180 ** 2181 ** These routines are useful during command-line input to determine if the 2182 ** currently entered text seems to form a complete SQL statement or 2183 ** if additional input is needed before sending the text into 2184 ** SQLite for parsing. ^These routines return 1 if the input string 2185 ** appears to be a complete SQL statement. ^A statement is judged to be 2186 ** complete if it ends with a semicolon token and is not a prefix of a 2187 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within 2188 ** string literals or quoted identifier names or comments are not 2189 ** independent tokens (they are part of the token in which they are 2190 ** embedded) and thus do not count as a statement terminator. ^Whitespace 2191 ** and comments that follow the final semicolon are ignored. 2192 ** 2193 ** ^These routines return 0 if the statement is incomplete. ^If a 2194 ** memory allocation fails, then SQLITE_NOMEM is returned. 2195 ** 2196 ** ^These routines do not parse the SQL statements thus 2197 ** will not detect syntactically incorrect SQL. 2198 ** 2199 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 2200 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked 2201 ** automatically by sqlite3_complete16(). If that initialization fails, 2202 ** then the return value from sqlite3_complete16() will be non-zero 2203 ** regardless of whether or not the input SQL is complete.)^ 2204 ** 2205 ** The input to [sqlite3_complete()] must be a zero-terminated 2206 ** UTF-8 string. 2207 ** 2208 ** The input to [sqlite3_complete16()] must be a zero-terminated 2209 ** UTF-16 string in native byte order. 2210 */ 2211 SQLITE_API int sqlite3_complete(const char *sql); 2212 SQLITE_API int sqlite3_complete16(const void *sql); 2213 2214 /* 2215 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 2216 ** 2217 ** ^This routine sets a callback function that might be invoked whenever 2218 ** an attempt is made to open a database table that another thread 2219 ** or process has locked. 2220 ** 2221 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] 2222 ** is returned immediately upon encountering the lock. ^If the busy callback 2223 ** is not NULL, then the callback might be invoked with two arguments. 2224 ** 2225 ** ^The first argument to the busy handler is a copy of the void* pointer which 2226 ** is the third argument to sqlite3_busy_handler(). ^The second argument to 2227 ** the busy handler callback is the number of times that the busy handler has 2228 ** been invoked for this locking event. ^If the 2229 ** busy callback returns 0, then no additional attempts are made to 2230 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. 2231 ** ^If the callback returns non-zero, then another attempt 2232 ** is made to open the database for reading and the cycle repeats. 2233 ** 2234 ** The presence of a busy handler does not guarantee that it will be invoked 2235 ** when there is lock contention. ^If SQLite determines that invoking the busy 2236 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 2237 ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. 2238 ** Consider a scenario where one process is holding a read lock that 2239 ** it is trying to promote to a reserved lock and 2240 ** a second process is holding a reserved lock that it is trying 2241 ** to promote to an exclusive lock. The first process cannot proceed 2242 ** because it is blocked by the second and the second process cannot 2243 ** proceed because it is blocked by the first. If both processes 2244 ** invoke the busy handlers, neither will make any progress. Therefore, 2245 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 2246 ** will induce the first process to release its read lock and allow 2247 ** the second process to proceed. 2248 ** 2249 ** ^The default busy callback is NULL. 2250 ** 2251 ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] 2252 ** when SQLite is in the middle of a large transaction where all the 2253 ** changes will not fit into the in-memory cache. SQLite will 2254 ** already hold a RESERVED lock on the database file, but it needs 2255 ** to promote this lock to EXCLUSIVE so that it can spill cache 2256 ** pages into the database file without harm to concurrent 2257 ** readers. ^If it is unable to promote the lock, then the in-memory 2258 ** cache will be left in an inconsistent state and so the error 2259 ** code is promoted from the relatively benign [SQLITE_BUSY] to 2260 ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion 2261 ** forces an automatic rollback of the changes. See the 2262 ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> 2263 ** CorruptionFollowingBusyError</a> wiki page for a discussion of why 2264 ** this is important. 2265 ** 2266 ** ^(There can only be a single busy handler defined for each 2267 ** [database connection]. Setting a new busy handler clears any 2268 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 2269 ** will also set or clear the busy handler. 2270 ** 2271 ** The busy callback should not take any actions which modify the 2272 ** database connection that invoked the busy handler. Any such actions 2273 ** result in undefined behavior. 2274 ** 2275 ** A busy handler must not close the database connection 2276 ** or [prepared statement] that invoked the busy handler. 2277 */ 2278 SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); 2279 2280 /* 2281 ** CAPI3REF: Set A Busy Timeout 2282 ** 2283 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 2284 ** for a specified amount of time when a table is locked. ^The handler 2285 ** will sleep multiple times until at least "ms" milliseconds of sleeping 2286 ** have accumulated. ^After at least "ms" milliseconds of sleeping, 2287 ** the handler returns 0 which causes [sqlite3_step()] to return 2288 ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. 2289 ** 2290 ** ^Calling this routine with an argument less than or equal to zero 2291 ** turns off all busy handlers. 2292 ** 2293 ** ^(There can only be a single busy handler for a particular 2294 ** [database connection] any any given moment. If another busy handler 2295 ** was defined (using [sqlite3_busy_handler()]) prior to calling 2296 ** this routine, that other busy handler is cleared.)^ 2297 */ 2298 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); 2299 2300 /* 2301 ** CAPI3REF: Convenience Routines For Running Queries 2302 ** 2303 ** This is a legacy interface that is preserved for backwards compatibility. 2304 ** Use of this interface is not recommended. 2305 ** 2306 ** Definition: A <b>result table</b> is memory data structure created by the 2307 ** [sqlite3_get_table()] interface. A result table records the 2308 ** complete query results from one or more queries. 2309 ** 2310 ** The table conceptually has a number of rows and columns. But 2311 ** these numbers are not part of the result table itself. These 2312 ** numbers are obtained separately. Let N be the number of rows 2313 ** and M be the number of columns. 2314 ** 2315 ** A result table is an array of pointers to zero-terminated UTF-8 strings. 2316 ** There are (N+1)*M elements in the array. The first M pointers point 2317 ** to zero-terminated strings that contain the names of the columns. 2318 ** The remaining entries all point to query results. NULL values result 2319 ** in NULL pointers. All other values are in their UTF-8 zero-terminated 2320 ** string representation as returned by [sqlite3_column_text()]. 2321 ** 2322 ** A result table might consist of one or more memory allocations. 2323 ** It is not safe to pass a result table directly to [sqlite3_free()]. 2324 ** A result table should be deallocated using [sqlite3_free_table()]. 2325 ** 2326 ** ^(As an example of the result table format, suppose a query result 2327 ** is as follows: 2328 ** 2329 ** <blockquote><pre> 2330 ** Name | Age 2331 ** ----------------------- 2332 ** Alice | 43 2333 ** Bob | 28 2334 ** Cindy | 21 2335 ** </pre></blockquote> 2336 ** 2337 ** There are two column (M==2) and three rows (N==3). Thus the 2338 ** result table has 8 entries. Suppose the result table is stored 2339 ** in an array names azResult. Then azResult holds this content: 2340 ** 2341 ** <blockquote><pre> 2342 ** azResult[0] = "Name"; 2343 ** azResult[1] = "Age"; 2344 ** azResult[2] = "Alice"; 2345 ** azResult[3] = "43"; 2346 ** azResult[4] = "Bob"; 2347 ** azResult[5] = "28"; 2348 ** azResult[6] = "Cindy"; 2349 ** azResult[7] = "21"; 2350 ** </pre></blockquote>)^ 2351 ** 2352 ** ^The sqlite3_get_table() function evaluates one or more 2353 ** semicolon-separated SQL statements in the zero-terminated UTF-8 2354 ** string of its 2nd parameter and returns a result table to the 2355 ** pointer given in its 3rd parameter. 2356 ** 2357 ** After the application has finished with the result from sqlite3_get_table(), 2358 ** it must pass the result table pointer to sqlite3_free_table() in order to 2359 ** release the memory that was malloced. Because of the way the 2360 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling 2361 ** function must not try to call [sqlite3_free()] directly. Only 2362 ** [sqlite3_free_table()] is able to release the memory properly and safely. 2363 ** 2364 ** The sqlite3_get_table() interface is implemented as a wrapper around 2365 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access 2366 ** to any internal data structures of SQLite. It uses only the public 2367 ** interface defined here. As a consequence, errors that occur in the 2368 ** wrapper layer outside of the internal [sqlite3_exec()] call are not 2369 ** reflected in subsequent calls to [sqlite3_errcode()] or 2370 ** [sqlite3_errmsg()]. 2371 */ 2372 SQLITE_API int sqlite3_get_table( 2373 sqlite3 *db, /* An open database */ 2374 const char *zSql, /* SQL to be evaluated */ 2375 char ***pazResult, /* Results of the query */ 2376 int *pnRow, /* Number of result rows written here */ 2377 int *pnColumn, /* Number of result columns written here */ 2378 char **pzErrmsg /* Error msg written here */ 2379 ); 2380 SQLITE_API void sqlite3_free_table(char **result); 2381 2382 /* 2383 ** CAPI3REF: Formatted String Printing Functions 2384 ** 2385 ** These routines are work-alikes of the "printf()" family of functions 2386 ** from the standard C library. 2387 ** 2388 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their 2389 ** results into memory obtained from [sqlite3_malloc()]. 2390 ** The strings returned by these two routines should be 2391 ** released by [sqlite3_free()]. ^Both routines return a 2392 ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough 2393 ** memory to hold the resulting string. 2394 ** 2395 ** ^(In sqlite3_snprintf() routine is similar to "snprintf()" from 2396 ** the standard C library. The result is written into the 2397 ** buffer supplied as the second parameter whose size is given by 2398 ** the first parameter. Note that the order of the 2399 ** first two parameters is reversed from snprintf().)^ This is an 2400 ** historical accident that cannot be fixed without breaking 2401 ** backwards compatibility. ^(Note also that sqlite3_snprintf() 2402 ** returns a pointer to its buffer instead of the number of 2403 ** characters actually written into the buffer.)^ We admit that 2404 ** the number of characters written would be a more useful return 2405 ** value but we cannot change the implementation of sqlite3_snprintf() 2406 ** now without breaking compatibility. 2407 ** 2408 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() 2409 ** guarantees that the buffer is always zero-terminated. ^The first 2410 ** parameter "n" is the total size of the buffer, including space for 2411 ** the zero terminator. So the longest string that can be completely 2412 ** written will be n-1 characters. 2413 ** 2414 ** These routines all implement some additional formatting 2415 ** options that are useful for constructing SQL statements. 2416 ** All of the usual printf() formatting options apply. In addition, there 2417 ** is are "%q", "%Q", and "%z" options. 2418 ** 2419 ** ^(The %q option works like %s in that it substitutes a null-terminated 2420 ** string from the argument list. But %q also doubles every '\'' character. 2421 ** %q is designed for use inside a string literal.)^ By doubling each '\'' 2422 ** character it escapes that character and allows it to be inserted into 2423 ** the string. 2424 ** 2425 ** For example, assume the string variable zText contains text as follows: 2426 ** 2427 ** <blockquote><pre> 2428 ** char *zText = "It's a happy day!"; 2429 ** </pre></blockquote> 2430 ** 2431 ** One can use this text in an SQL statement as follows: 2432 ** 2433 ** <blockquote><pre> 2434 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); 2435 ** sqlite3_exec(db, zSQL, 0, 0, 0); 2436 ** sqlite3_free(zSQL); 2437 ** </pre></blockquote> 2438 ** 2439 ** Because the %q format string is used, the '\'' character in zText 2440 ** is escaped and the SQL generated is as follows: 2441 ** 2442 ** <blockquote><pre> 2443 ** INSERT INTO table1 VALUES('It''s a happy day!') 2444 ** </pre></blockquote> 2445 ** 2446 ** This is correct. Had we used %s instead of %q, the generated SQL 2447 ** would have looked like this: 2448 ** 2449 ** <blockquote><pre> 2450 ** INSERT INTO table1 VALUES('It's a happy day!'); 2451 ** </pre></blockquote> 2452 ** 2453 ** This second example is an SQL syntax error. As a general rule you should 2454 ** always use %q instead of %s when inserting text into a string literal. 2455 ** 2456 ** ^(The %Q option works like %q except it also adds single quotes around 2457 ** the outside of the total string. Additionally, if the parameter in the 2458 ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without 2459 ** single quotes).)^ So, for example, one could say: 2460 ** 2461 ** <blockquote><pre> 2462 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); 2463 ** sqlite3_exec(db, zSQL, 0, 0, 0); 2464 ** sqlite3_free(zSQL); 2465 ** </pre></blockquote> 2466 ** 2467 ** The code above will render a correct SQL statement in the zSQL 2468 ** variable even if the zText variable is a NULL pointer. 2469 ** 2470 ** ^(The "%z" formatting option works like "%s" but with the 2471 ** addition that after the string has been read and copied into 2472 ** the result, [sqlite3_free()] is called on the input string.)^ 2473 */ 2474 SQLITE_API char *sqlite3_mprintf(const char*,...); 2475 SQLITE_API char *sqlite3_vmprintf(const char*, va_list); 2476 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); 2477 2478 /* 2479 ** CAPI3REF: Memory Allocation Subsystem 2480 ** 2481 ** The SQLite core uses these three routines for all of its own 2482 ** internal memory allocation needs. "Core" in the previous sentence 2483 ** does not include operating-system specific VFS implementation. The 2484 ** Windows VFS uses native malloc() and free() for some operations. 2485 ** 2486 ** ^The sqlite3_malloc() routine returns a pointer to a block 2487 ** of memory at least N bytes in length, where N is the parameter. 2488 ** ^If sqlite3_malloc() is unable to obtain sufficient free 2489 ** memory, it returns a NULL pointer. ^If the parameter N to 2490 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 2491 ** a NULL pointer. 2492 ** 2493 ** ^Calling sqlite3_free() with a pointer previously returned 2494 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 2495 ** that it might be reused. ^The sqlite3_free() routine is 2496 ** a no-op if is called with a NULL pointer. Passing a NULL pointer 2497 ** to sqlite3_free() is harmless. After being freed, memory 2498 ** should neither be read nor written. Even reading previously freed 2499 ** memory might result in a segmentation fault or other severe error. 2500 ** Memory corruption, a segmentation fault, or other severe error 2501 ** might result if sqlite3_free() is called with a non-NULL pointer that 2502 ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 2503 ** 2504 ** ^(The sqlite3_realloc() interface attempts to resize a 2505 ** prior memory allocation to be at least N bytes, where N is the 2506 ** second parameter. The memory allocation to be resized is the first 2507 ** parameter.)^ ^ If the first parameter to sqlite3_realloc() 2508 ** is a NULL pointer then its behavior is identical to calling 2509 ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). 2510 ** ^If the second parameter to sqlite3_realloc() is zero or 2511 ** negative then the behavior is exactly the same as calling 2512 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). 2513 ** ^sqlite3_realloc() returns a pointer to a memory allocation 2514 ** of at least N bytes in size or NULL if sufficient memory is unavailable. 2515 ** ^If M is the size of the prior allocation, then min(N,M) bytes 2516 ** of the prior allocation are copied into the beginning of buffer returned 2517 ** by sqlite3_realloc() and the prior allocation is freed. 2518 ** ^If sqlite3_realloc() returns NULL, then the prior allocation 2519 ** is not freed. 2520 ** 2521 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() 2522 ** is always aligned to at least an 8 byte boundary, or to a 2523 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time 2524 ** option is used. 2525 ** 2526 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 2527 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 2528 ** implementation of these routines to be omitted. That capability 2529 ** is no longer provided. Only built-in memory allocators can be used. 2530 ** 2531 ** The Windows OS interface layer calls 2532 ** the system malloc() and free() directly when converting 2533 ** filenames between the UTF-8 encoding used by SQLite 2534 ** and whatever filename encoding is used by the particular Windows 2535 ** installation. Memory allocation errors are detected, but 2536 ** they are reported back as [SQLITE_CANTOPEN] or 2537 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 2538 ** 2539 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 2540 ** must be either NULL or else pointers obtained from a prior 2541 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 2542 ** not yet been released. 2543 ** 2544 ** The application must not read or write any part of 2545 ** a block of memory after it has been released using 2546 ** [sqlite3_free()] or [sqlite3_realloc()]. 2547 */ 2548 SQLITE_API void *sqlite3_malloc(int); 2549 SQLITE_API void *sqlite3_realloc(void*, int); 2550 SQLITE_API void sqlite3_free(void*); 2551 2552 /* 2553 ** CAPI3REF: Memory Allocator Statistics 2554 ** 2555 ** SQLite provides these two interfaces for reporting on the status 2556 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 2557 ** routines, which form the built-in memory allocation subsystem. 2558 ** 2559 ** ^The [sqlite3_memory_used()] routine returns the number of bytes 2560 ** of memory currently outstanding (malloced but not freed). 2561 ** ^The [sqlite3_memory_highwater()] routine returns the maximum 2562 ** value of [sqlite3_memory_used()] since the high-water mark 2563 ** was last reset. ^The values returned by [sqlite3_memory_used()] and 2564 ** [sqlite3_memory_highwater()] include any overhead 2565 ** added by SQLite in its implementation of [sqlite3_malloc()], 2566 ** but not overhead added by the any underlying system library 2567 ** routines that [sqlite3_malloc()] may call. 2568 ** 2569 ** ^The memory high-water mark is reset to the current value of 2570 ** [sqlite3_memory_used()] if and only if the parameter to 2571 ** [sqlite3_memory_highwater()] is true. ^The value returned 2572 ** by [sqlite3_memory_highwater(1)] is the high-water mark 2573 ** prior to the reset. 2574 */ 2575 SQLITE_API sqlite3_int64 sqlite3_memory_used(void); 2576 SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); 2577 2578 /* 2579 ** CAPI3REF: Pseudo-Random Number Generator 2580 ** 2581 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 2582 ** select random [ROWID | ROWIDs] when inserting new records into a table that 2583 ** already uses the largest possible [ROWID]. The PRNG is also used for 2584 ** the build-in random() and randomblob() SQL functions. This interface allows 2585 ** applications to access the same PRNG for other purposes. 2586 ** 2587 ** ^A call to this routine stores N bytes of randomness into buffer P. 2588 ** 2589 ** ^The first time this routine is invoked (either internally or by 2590 ** the application) the PRNG is seeded using randomness obtained 2591 ** from the xRandomness method of the default [sqlite3_vfs] object. 2592 ** ^On all subsequent invocations, the pseudo-randomness is generated 2593 ** internally and without recourse to the [sqlite3_vfs] xRandomness 2594 ** method. 2595 */ 2596 SQLITE_API void sqlite3_randomness(int N, void *P); 2597 2598 /* 2599 ** CAPI3REF: Compile-Time Authorization Callbacks 2600 ** 2601 ** ^This routine registers a authorizer callback with a particular 2602 ** [database connection], supplied in the first argument. 2603 ** ^The authorizer callback is invoked as SQL statements are being compiled 2604 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], 2605 ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various 2606 ** points during the compilation process, as logic is being created 2607 ** to perform various actions, the authorizer callback is invoked to 2608 ** see if those actions are allowed. ^The authorizer callback should 2609 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the 2610 ** specific action but allow the SQL statement to continue to be 2611 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be 2612 ** rejected with an error. ^If the authorizer callback returns 2613 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] 2614 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered 2615 ** the authorizer will fail with an error message. 2616 ** 2617 ** When the callback returns [SQLITE_OK], that means the operation 2618 ** requested is ok. ^When the callback returns [SQLITE_DENY], the 2619 ** [sqlite3_prepare_v2()] or equivalent call that triggered the 2620 ** authorizer will fail with an error message explaining that 2621 ** access is denied. 2622 ** 2623 ** ^The first parameter to the authorizer callback is a copy of the third 2624 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter 2625 ** to the callback is an integer [SQLITE_COPY | action code] that specifies 2626 ** the particular action to be authorized. ^The third through sixth parameters 2627 ** to the callback are zero-terminated strings that contain additional 2628 ** details about the action to be authorized. 2629 ** 2630 ** ^If the action code is [SQLITE_READ] 2631 ** and the callback returns [SQLITE_IGNORE] then the 2632 ** [prepared statement] statement is constructed to substitute 2633 ** a NULL value in place of the table column that would have 2634 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] 2635 ** return can be used to deny an untrusted user access to individual 2636 ** columns of a table. 2637 ** ^If the action code is [SQLITE_DELETE] and the callback returns 2638 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the 2639 ** [truncate optimization] is disabled and all rows are deleted individually. 2640 ** 2641 ** An authorizer is used when [sqlite3_prepare | preparing] 2642 ** SQL statements from an untrusted source, to ensure that the SQL statements 2643 ** do not try to access data they are not allowed to see, or that they do not 2644 ** try to execute malicious statements that damage the database. For 2645 ** example, an application may allow a user to enter arbitrary 2646 ** SQL queries for evaluation by a database. But the application does 2647 ** not want the user to be able to make arbitrary changes to the 2648 ** database. An authorizer could then be put in place while the 2649 ** user-entered SQL is being [sqlite3_prepare | prepared] that 2650 ** disallows everything except [SELECT] statements. 2651 ** 2652 ** Applications that need to process SQL from untrusted sources 2653 ** might also consider lowering resource limits using [sqlite3_limit()] 2654 ** and limiting database size using the [max_page_count] [PRAGMA] 2655 ** in addition to using an authorizer. 2656 ** 2657 ** ^(Only a single authorizer can be in place on a database connection 2658 ** at a time. Each call to sqlite3_set_authorizer overrides the 2659 ** previous call.)^ ^Disable the authorizer by installing a NULL callback. 2660 ** The authorizer is disabled by default. 2661 ** 2662 ** The authorizer callback must not do anything that will modify 2663 ** the database connection that invoked the authorizer callback. 2664 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 2665 ** database connections for the meaning of "modify" in this paragraph. 2666 ** 2667 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the 2668 ** statement might be re-prepared during [sqlite3_step()] due to a 2669 ** schema change. Hence, the application should ensure that the 2670 ** correct authorizer callback remains in place during the [sqlite3_step()]. 2671 ** 2672 ** ^Note that the authorizer callback is invoked only during 2673 ** [sqlite3_prepare()] or its variants. Authorization is not 2674 ** performed during statement evaluation in [sqlite3_step()], unless 2675 ** as stated in the previous paragraph, sqlite3_step() invokes 2676 ** sqlite3_prepare_v2() to reprepare a statement after a schema change. 2677 */ 2678 SQLITE_API int sqlite3_set_authorizer( 2679 sqlite3*, 2680 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 2681 void *pUserData 2682 ); 2683 2684 /* 2685 ** CAPI3REF: Authorizer Return Codes 2686 ** 2687 ** The [sqlite3_set_authorizer | authorizer callback function] must 2688 ** return either [SQLITE_OK] or one of these two constants in order 2689 ** to signal SQLite whether or not the action is permitted. See the 2690 ** [sqlite3_set_authorizer | authorizer documentation] for additional 2691 ** information. 2692 */ 2693 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 2694 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 2695 2696 /* 2697 ** CAPI3REF: Authorizer Action Codes 2698 ** 2699 ** The [sqlite3_set_authorizer()] interface registers a callback function 2700 ** that is invoked to authorize certain SQL statement actions. The 2701 ** second parameter to the callback is an integer code that specifies 2702 ** what action is being authorized. These are the integer action codes that 2703 ** the authorizer callback may be passed. 2704 ** 2705 ** These action code values signify what kind of operation is to be 2706 ** authorized. The 3rd and 4th parameters to the authorization 2707 ** callback function will be parameters or NULL depending on which of these 2708 ** codes is used as the second parameter. ^(The 5th parameter to the 2709 ** authorizer callback is the name of the database ("main", "temp", 2710 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback 2711 ** is the name of the inner-most trigger or view that is responsible for 2712 ** the access attempt or NULL if this access attempt is directly from 2713 ** top-level SQL code. 2714 */ 2715 /******************************************* 3rd ************ 4th ***********/ 2716 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 2717 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 2718 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 2719 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 2720 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 2721 #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 2722 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 2723 #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 2724 #define SQLITE_DELETE 9 /* Table Name NULL */ 2725 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 2726 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 2727 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 2728 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 2729 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 2730 #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 2731 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 2732 #define SQLITE_DROP_VIEW 17 /* View Name NULL */ 2733 #define SQLITE_INSERT 18 /* Table Name NULL */ 2734 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 2735 #define SQLITE_READ 20 /* Table Name Column Name */ 2736 #define SQLITE_SELECT 21 /* NULL NULL */ 2737 #define SQLITE_TRANSACTION 22 /* Operation NULL */ 2738 #define SQLITE_UPDATE 23 /* Table Name Column Name */ 2739 #define SQLITE_ATTACH 24 /* Filename NULL */ 2740 #define SQLITE_DETACH 25 /* Database Name NULL */ 2741 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 2742 #define SQLITE_REINDEX 27 /* Index Name NULL */ 2743 #define SQLITE_ANALYZE 28 /* Table Name NULL */ 2744 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 2745 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 2746 #define SQLITE_FUNCTION 31 /* NULL Function Name */ 2747 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 2748 #define SQLITE_COPY 0 /* No longer used */ 2749 2750 /* 2751 ** CAPI3REF: Tracing And Profiling Functions 2752 ** 2753 ** These routines register callback functions that can be used for 2754 ** tracing and profiling the execution of SQL statements. 2755 ** 2756 ** ^The callback function registered by sqlite3_trace() is invoked at 2757 ** various times when an SQL statement is being run by [sqlite3_step()]. 2758 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 2759 ** SQL statement text as the statement first begins executing. 2760 ** ^(Additional sqlite3_trace() callbacks might occur 2761 ** as each triggered subprogram is entered. The callbacks for triggers 2762 ** contain a UTF-8 SQL comment that identifies the trigger.)^ 2763 ** 2764 ** ^The callback function registered by sqlite3_profile() is invoked 2765 ** as each SQL statement finishes. ^The profile callback contains 2766 ** the original statement text and an estimate of wall-clock time 2767 ** of how long that statement took to run. ^The profile callback 2768 ** time is in units of nanoseconds, however the current implementation 2769 ** is only capable of millisecond resolution so the six least significant 2770 ** digits in the time are meaningless. Future versions of SQLite 2771 ** might provide greater resolution on the profiler callback. The 2772 ** sqlite3_profile() function is considered experimental and is 2773 ** subject to change in future versions of SQLite. 2774 */ 2775 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); 2776 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, 2777 void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 2778 2779 /* 2780 ** CAPI3REF: Query Progress Callbacks 2781 ** 2782 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback 2783 ** function X to be invoked periodically during long running calls to 2784 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for 2785 ** database connection D. An example use for this 2786 ** interface is to keep a GUI updated during a large query. 2787 ** 2788 ** ^The parameter P is passed through as the only parameter to the 2789 ** callback function X. ^The parameter N is the number of 2790 ** [virtual machine instructions] that are evaluated between successive 2791 ** invocations of the callback X. 2792 ** 2793 ** ^Only a single progress handler may be defined at one time per 2794 ** [database connection]; setting a new progress handler cancels the 2795 ** old one. ^Setting parameter X to NULL disables the progress handler. 2796 ** ^The progress handler is also disabled by setting N to a value less 2797 ** than 1. 2798 ** 2799 ** ^If the progress callback returns non-zero, the operation is 2800 ** interrupted. This feature can be used to implement a 2801 ** "Cancel" button on a GUI progress dialog box. 2802 ** 2803 ** The progress handler callback must not do anything that will modify 2804 ** the database connection that invoked the progress handler. 2805 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 2806 ** database connections for the meaning of "modify" in this paragraph. 2807 ** 2808 */ 2809 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 2810 2811 /* 2812 ** CAPI3REF: Opening A New Database Connection 2813 ** 2814 ** ^These routines open an SQLite database file whose name is given by the 2815 ** filename argument. ^The filename argument is interpreted as UTF-8 for 2816 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 2817 ** order for sqlite3_open16(). ^(A [database connection] handle is usually 2818 ** returned in *ppDb, even if an error occurs. The only exception is that 2819 ** if SQLite is unable to allocate memory to hold the [sqlite3] object, 2820 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 2821 ** object.)^ ^(If the database is opened (and/or created) successfully, then 2822 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 2823 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 2824 ** an English language description of the error following a failure of any 2825 ** of the sqlite3_open() routines. 2826 ** 2827 ** ^The default encoding for the database will be UTF-8 if 2828 ** sqlite3_open() or sqlite3_open_v2() is called and 2829 ** UTF-16 in the native byte order if sqlite3_open16() is used. 2830 ** 2831 ** Whether or not an error occurs when it is opened, resources 2832 ** associated with the [database connection] handle should be released by 2833 ** passing it to [sqlite3_close()] when it is no longer required. 2834 ** 2835 ** The sqlite3_open_v2() interface works like sqlite3_open() 2836 ** except that it accepts two additional parameters for additional control 2837 ** over the new database connection. ^(The flags parameter to 2838 ** sqlite3_open_v2() can take one of 2839 ** the following three values, optionally combined with the 2840 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], 2841 ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ 2842 ** 2843 ** <dl> 2844 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 2845 ** <dd>The database is opened in read-only mode. If the database does not 2846 ** already exist, an error is returned.</dd>)^ 2847 ** 2848 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 2849 ** <dd>The database is opened for reading and writing if possible, or reading 2850 ** only if the file is write protected by the operating system. In either 2851 ** case the database must already exist, otherwise an error is returned.</dd>)^ 2852 ** 2853 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 2854 ** <dd>The database is opened for reading and writing, and is creates it if 2855 ** it does not already exist. This is the behavior that is always used for 2856 ** sqlite3_open() and sqlite3_open16().</dd>)^ 2857 ** </dl> 2858 ** 2859 ** If the 3rd parameter to sqlite3_open_v2() is not one of the 2860 ** combinations shown above or one of the combinations shown above combined 2861 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], 2862 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags, 2863 ** then the behavior is undefined. 2864 ** 2865 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection 2866 ** opens in the multi-thread [threading mode] as long as the single-thread 2867 ** mode has not been set at compile-time or start-time. ^If the 2868 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens 2869 ** in the serialized [threading mode] unless single-thread was 2870 ** previously selected at compile-time or start-time. 2871 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be 2872 ** eligible to use [shared cache mode], regardless of whether or not shared 2873 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The 2874 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not 2875 ** participate in [shared cache mode] even if it is enabled. 2876 ** 2877 ** ^If the filename is ":memory:", then a private, temporary in-memory database 2878 ** is created for the connection. ^This in-memory database will vanish when 2879 ** the database connection is closed. Future versions of SQLite might 2880 ** make use of additional special filenames that begin with the ":" character. 2881 ** It is recommended that when a database filename actually does begin with 2882 ** a ":" character you should prefix the filename with a pathname such as 2883 ** "./" to avoid ambiguity. 2884 ** 2885 ** ^If the filename is an empty string, then a private, temporary 2886 ** on-disk database will be created. ^This private database will be 2887 ** automatically deleted as soon as the database connection is closed. 2888 ** 2889 ** ^The fourth parameter to sqlite3_open_v2() is the name of the 2890 ** [sqlite3_vfs] object that defines the operating system interface that 2891 ** the new database connection should use. ^If the fourth parameter is 2892 ** a NULL pointer then the default [sqlite3_vfs] object is used. 2893 ** 2894 ** <b>Note to Windows users:</b> The encoding used for the filename argument 2895 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 2896 ** codepage is currently defined. Filenames containing international 2897 ** characters must be converted to UTF-8 prior to passing them into 2898 ** sqlite3_open() or sqlite3_open_v2(). 2899 */ 2900 SQLITE_API int sqlite3_open( 2901 const char *filename, /* Database filename (UTF-8) */ 2902 sqlite3 **ppDb /* OUT: SQLite db handle */ 2903 ); 2904 SQLITE_API int sqlite3_open16( 2905 const void *filename, /* Database filename (UTF-16) */ 2906 sqlite3 **ppDb /* OUT: SQLite db handle */ 2907 ); 2908 SQLITE_API int sqlite3_open_v2( 2909 const char *filename, /* Database filename (UTF-8) */ 2910 sqlite3 **ppDb, /* OUT: SQLite db handle */ 2911 int flags, /* Flags */ 2912 const char *zVfs /* Name of VFS module to use */ 2913 ); 2914 2915 /* 2916 ** CAPI3REF: Error Codes And Messages 2917 ** 2918 ** ^The sqlite3_errcode() interface returns the numeric [result code] or 2919 ** [extended result code] for the most recent failed sqlite3_* API call 2920 ** associated with a [database connection]. If a prior API call failed 2921 ** but the most recent API call succeeded, the return value from 2922 ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() 2923 ** interface is the same except that it always returns the 2924 ** [extended result code] even when extended result codes are 2925 ** disabled. 2926 ** 2927 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 2928 ** text that describes the error, as either UTF-8 or UTF-16 respectively. 2929 ** ^(Memory to hold the error message string is managed internally. 2930 ** The application does not need to worry about freeing the result. 2931 ** However, the error string might be overwritten or deallocated by 2932 ** subsequent calls to other SQLite interface functions.)^ 2933 ** 2934 ** When the serialized [threading mode] is in use, it might be the 2935 ** case that a second error occurs on a separate thread in between 2936 ** the time of the first error and the call to these interfaces. 2937 ** When that happens, the second error will be reported since these 2938 ** interfaces always report the most recent result. To avoid 2939 ** this, each thread can obtain exclusive use of the [database connection] D 2940 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 2941 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 2942 ** all calls to the interfaces listed here are completed. 2943 ** 2944 ** If an interface fails with SQLITE_MISUSE, that means the interface 2945 ** was invoked incorrectly by the application. In that case, the 2946 ** error code and message may or may not be set. 2947 */ 2948 SQLITE_API int sqlite3_errcode(sqlite3 *db); 2949 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); 2950 SQLITE_API const char *sqlite3_errmsg(sqlite3*); 2951 SQLITE_API const void *sqlite3_errmsg16(sqlite3*); 2952 2953 /* 2954 ** CAPI3REF: SQL Statement Object 2955 ** KEYWORDS: {prepared statement} {prepared statements} 2956 ** 2957 ** An instance of this object represents a single SQL statement. 2958 ** This object is variously known as a "prepared statement" or a 2959 ** "compiled SQL statement" or simply as a "statement". 2960 ** 2961 ** The life of a statement object goes something like this: 2962 ** 2963 ** <ol> 2964 ** <li> Create the object using [sqlite3_prepare_v2()] or a related 2965 ** function. 2966 ** <li> Bind values to [host parameters] using the sqlite3_bind_*() 2967 ** interfaces. 2968 ** <li> Run the SQL by calling [sqlite3_step()] one or more times. 2969 ** <li> Reset the statement using [sqlite3_reset()] then go back 2970 ** to step 2. Do this zero or more times. 2971 ** <li> Destroy the object using [sqlite3_finalize()]. 2972 ** </ol> 2973 ** 2974 ** Refer to documentation on individual methods above for additional 2975 ** information. 2976 */ 2977 typedef struct sqlite3_stmt sqlite3_stmt; 2978 2979 /* 2980 ** CAPI3REF: Run-time Limits 2981 ** 2982 ** ^(This interface allows the size of various constructs to be limited 2983 ** on a connection by connection basis. The first parameter is the 2984 ** [database connection] whose limit is to be set or queried. The 2985 ** second parameter is one of the [limit categories] that define a 2986 ** class of constructs to be size limited. The third parameter is the 2987 ** new limit for that construct.)^ 2988 ** 2989 ** ^If the new limit is a negative number, the limit is unchanged. 2990 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a 2991 ** [limits | hard upper bound] 2992 ** set at compile-time by a C preprocessor macro called 2993 ** [limits | SQLITE_MAX_<i>NAME</i>]. 2994 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ 2995 ** ^Attempts to increase a limit above its hard upper bound are 2996 ** silently truncated to the hard upper bound. 2997 ** 2998 ** ^Regardless of whether or not the limit was changed, the 2999 ** [sqlite3_limit()] interface returns the prior value of the limit. 3000 ** ^Hence, to find the current value of a limit without changing it, 3001 ** simply invoke this interface with the third parameter set to -1. 3002 ** 3003 ** Run-time limits are intended for use in applications that manage 3004 ** both their own internal database and also databases that are controlled 3005 ** by untrusted external sources. An example application might be a 3006 ** web browser that has its own databases for storing history and 3007 ** separate databases controlled by JavaScript applications downloaded 3008 ** off the Internet. The internal databases can be given the 3009 ** large, default limits. Databases managed by external sources can 3010 ** be given much smaller limits designed to prevent a denial of service 3011 ** attack. Developers might also want to use the [sqlite3_set_authorizer()] 3012 ** interface to further control untrusted SQL. The size of the database 3013 ** created by an untrusted script can be contained using the 3014 ** [max_page_count] [PRAGMA]. 3015 ** 3016 ** New run-time limit categories may be added in future releases. 3017 */ 3018 SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); 3019 3020 /* 3021 ** CAPI3REF: Run-Time Limit Categories 3022 ** KEYWORDS: {limit category} {*limit categories} 3023 ** 3024 ** These constants define various performance limits 3025 ** that can be lowered at run-time using [sqlite3_limit()]. 3026 ** The synopsis of the meanings of the various limits is shown below. 3027 ** Additional information is available at [limits | Limits in SQLite]. 3028 ** 3029 ** <dl> 3030 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt> 3031 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ 3032 ** 3033 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 3034 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 3035 ** 3036 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt> 3037 ** <dd>The maximum number of columns in a table definition or in the 3038 ** result set of a [SELECT] or the maximum number of columns in an index 3039 ** or in an ORDER BY or GROUP BY clause.</dd>)^ 3040 ** 3041 ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 3042 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 3043 ** 3044 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 3045 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 3046 ** 3047 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 3048 ** <dd>The maximum number of instructions in a virtual machine program 3049 ** used to implement an SQL statement. This limit is not currently 3050 ** enforced, though that might be added in some future release of 3051 ** SQLite.</dd>)^ 3052 ** 3053 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 3054 ** <dd>The maximum number of arguments on a function.</dd>)^ 3055 ** 3056 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 3057 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 3058 ** 3059 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 3060 ** <dd>The maximum length of the pattern argument to the [LIKE] or 3061 ** [GLOB] operators.</dd>)^ 3062 ** 3063 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 3064 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ 3065 ** 3066 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 3067 ** <dd>The maximum depth of recursion for triggers.</dd>)^ 3068 ** </dl> 3069 */ 3070 #define SQLITE_LIMIT_LENGTH 0 3071 #define SQLITE_LIMIT_SQL_LENGTH 1 3072 #define SQLITE_LIMIT_COLUMN 2 3073 #define SQLITE_LIMIT_EXPR_DEPTH 3 3074 #define SQLITE_LIMIT_COMPOUND_SELECT 4 3075 #define SQLITE_LIMIT_VDBE_OP 5 3076 #define SQLITE_LIMIT_FUNCTION_ARG 6 3077 #define SQLITE_LIMIT_ATTACHED 7 3078 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 3079 #define SQLITE_LIMIT_VARIABLE_NUMBER 9 3080 #define SQLITE_LIMIT_TRIGGER_DEPTH 10 3081 3082 /* 3083 ** CAPI3REF: Compiling An SQL Statement 3084 ** KEYWORDS: {SQL statement compiler} 3085 ** 3086 ** To execute an SQL query, it must first be compiled into a byte-code 3087 ** program using one of these routines. 3088 ** 3089 ** The first argument, "db", is a [database connection] obtained from a 3090 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 3091 ** [sqlite3_open16()]. The database connection must not have been closed. 3092 ** 3093 ** The second argument, "zSql", is the statement to be compiled, encoded 3094 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() 3095 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() 3096 ** use UTF-16. 3097 ** 3098 ** ^If the nByte argument is less than zero, then zSql is read up to the 3099 ** first zero terminator. ^If nByte is non-negative, then it is the maximum 3100 ** number of bytes read from zSql. ^When nByte is non-negative, the 3101 ** zSql string ends at either the first '\000' or '\u0000' character or 3102 ** the nByte-th byte, whichever comes first. If the caller knows 3103 ** that the supplied string is nul-terminated, then there is a small 3104 ** performance advantage to be gained by passing an nByte parameter that 3105 ** is equal to the number of bytes in the input string <i>including</i> 3106 ** the nul-terminator bytes. 3107 ** 3108 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte 3109 ** past the end of the first SQL statement in zSql. These routines only 3110 ** compile the first statement in zSql, so *pzTail is left pointing to 3111 ** what remains uncompiled. 3112 ** 3113 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 3114 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 3115 ** to NULL. ^If the input text contains no SQL (if the input is an empty 3116 ** string or a comment) then *ppStmt is set to NULL. 3117 ** The calling procedure is responsible for deleting the compiled 3118 ** SQL statement using [sqlite3_finalize()] after it has finished with it. 3119 ** ppStmt may not be NULL. 3120 ** 3121 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 3122 ** otherwise an [error code] is returned. 3123 ** 3124 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 3125 ** recommended for all new programs. The two older interfaces are retained 3126 ** for backwards compatibility, but their use is discouraged. 3127 ** ^In the "v2" interfaces, the prepared statement 3128 ** that is returned (the [sqlite3_stmt] object) contains a copy of the 3129 ** original SQL text. This causes the [sqlite3_step()] interface to 3130 ** behave differently in three ways: 3131 ** 3132 ** <ol> 3133 ** <li> 3134 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 3135 ** always used to do, [sqlite3_step()] will automatically recompile the SQL 3136 ** statement and try to run it again. 3137 ** </li> 3138 ** 3139 ** <li> 3140 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed 3141 ** [error codes] or [extended error codes]. ^The legacy behavior was that 3142 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 3143 ** and the application would have to make a second call to [sqlite3_reset()] 3144 ** in order to find the underlying cause of the problem. With the "v2" prepare 3145 ** interfaces, the underlying reason for the error is returned immediately. 3146 ** </li> 3147 ** 3148 ** <li> 3149 ** ^If the specific value bound to [parameter | host parameter] in the 3150 ** WHERE clause might influence the choice of query plan for a statement, 3151 ** then the statement will be automatically recompiled, as if there had been 3152 ** a schema change, on the first [sqlite3_step()] call following any change 3153 ** to the [sqlite3_bind_text | bindings] of that [parameter]. 3154 ** ^The specific value of WHERE-clause [parameter] might influence the 3155 ** choice of query plan if the parameter is the left-hand side of a [LIKE] 3156 ** or [GLOB] operator or if the parameter is compared to an indexed column 3157 ** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled. 3158 ** the 3159 ** </li> 3160 ** </ol> 3161 */ 3162 SQLITE_API int sqlite3_prepare( 3163 sqlite3 *db, /* Database handle */ 3164 const char *zSql, /* SQL statement, UTF-8 encoded */ 3165 int nByte, /* Maximum length of zSql in bytes. */ 3166 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3167 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 3168 ); 3169 SQLITE_API int sqlite3_prepare_v2( 3170 sqlite3 *db, /* Database handle */ 3171 const char *zSql, /* SQL statement, UTF-8 encoded */ 3172 int nByte, /* Maximum length of zSql in bytes. */ 3173 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3174 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 3175 ); 3176 SQLITE_API int sqlite3_prepare16( 3177 sqlite3 *db, /* Database handle */ 3178 const void *zSql, /* SQL statement, UTF-16 encoded */ 3179 int nByte, /* Maximum length of zSql in bytes. */ 3180 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3181 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 3182 ); 3183 SQLITE_API int sqlite3_prepare16_v2( 3184 sqlite3 *db, /* Database handle */ 3185 const void *zSql, /* SQL statement, UTF-16 encoded */ 3186 int nByte, /* Maximum length of zSql in bytes. */ 3187 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3188 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 3189 ); 3190 3191 /* 3192 ** CAPI3REF: Retrieving Statement SQL 3193 ** 3194 ** ^This interface can be used to retrieve a saved copy of the original 3195 ** SQL text used to create a [prepared statement] if that statement was 3196 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. 3197 */ 3198 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); 3199 3200 /* 3201 ** CAPI3REF: Determine If An SQL Statement Writes The Database 3202 ** 3203 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 3204 ** the [prepared statement] X is [SELECT] statement and false (zero) if 3205 ** X is an [INSERT], [UPDATE], [DELETE], CREATE, DROP, [ANALYZE], 3206 ** [ALTER], or [REINDEX] statement. 3207 ** If X is a NULL pointer or any other kind of statement, including but 3208 ** not limited to [ATTACH], [DETACH], [COMMIT], [ROLLBACK], [RELEASE], 3209 ** [SAVEPOINT], [PRAGMA], or [VACUUM] the result of sqlite3_stmt_readonly(X) is 3210 ** undefined. 3211 */ 3212 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 3213 3214 /* 3215 ** CAPI3REF: Dynamically Typed Value Object 3216 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 3217 ** 3218 ** SQLite uses the sqlite3_value object to represent all values 3219 ** that can be stored in a database table. SQLite uses dynamic typing 3220 ** for the values it stores. ^Values stored in sqlite3_value objects 3221 ** can be integers, floating point values, strings, BLOBs, or NULL. 3222 ** 3223 ** An sqlite3_value object may be either "protected" or "unprotected". 3224 ** Some interfaces require a protected sqlite3_value. Other interfaces 3225 ** will accept either a protected or an unprotected sqlite3_value. 3226 ** Every interface that accepts sqlite3_value arguments specifies 3227 ** whether or not it requires a protected sqlite3_value. 3228 ** 3229 ** The terms "protected" and "unprotected" refer to whether or not 3230 ** a mutex is held. A internal mutex is held for a protected 3231 ** sqlite3_value object but no mutex is held for an unprotected 3232 ** sqlite3_value object. If SQLite is compiled to be single-threaded 3233 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) 3234 ** or if SQLite is run in one of reduced mutex modes 3235 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] 3236 ** then there is no distinction between protected and unprotected 3237 ** sqlite3_value objects and they can be used interchangeably. However, 3238 ** for maximum code portability it is recommended that applications 3239 ** still make the distinction between protected and unprotected 3240 ** sqlite3_value objects even when not strictly required. 3241 ** 3242 ** ^The sqlite3_value objects that are passed as parameters into the 3243 ** implementation of [application-defined SQL functions] are protected. 3244 ** ^The sqlite3_value object returned by 3245 ** [sqlite3_column_value()] is unprotected. 3246 ** Unprotected sqlite3_value objects may only be used with 3247 ** [sqlite3_result_value()] and [sqlite3_bind_value()]. 3248 ** The [sqlite3_value_blob | sqlite3_value_type()] family of 3249 ** interfaces require protected sqlite3_value objects. 3250 */ 3251 typedef struct Mem sqlite3_value; 3252 3253 /* 3254 ** CAPI3REF: SQL Function Context Object 3255 ** 3256 ** The context in which an SQL function executes is stored in an 3257 ** sqlite3_context object. ^A pointer to an sqlite3_context object 3258 ** is always first parameter to [application-defined SQL functions]. 3259 ** The application-defined SQL function implementation will pass this 3260 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], 3261 ** [sqlite3_aggregate_context()], [sqlite3_user_data()], 3262 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], 3263 ** and/or [sqlite3_set_auxdata()]. 3264 */ 3265 typedef struct sqlite3_context sqlite3_context; 3266 3267 /* 3268 ** CAPI3REF: Binding Values To Prepared Statements 3269 ** KEYWORDS: {host parameter} {host parameters} {host parameter name} 3270 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} 3271 ** 3272 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, 3273 ** literals may be replaced by a [parameter] that matches one of following 3274 ** templates: 3275 ** 3276 ** <ul> 3277 ** <li> ? 3278 ** <li> ?NNN 3279 ** <li> :VVV 3280 ** <li> @VVV 3281 ** <li> $VVV 3282 ** </ul> 3283 ** 3284 ** In the templates above, NNN represents an integer literal, 3285 ** and VVV represents an alphanumeric identifier.)^ ^The values of these 3286 ** parameters (also called "host parameter names" or "SQL parameters") 3287 ** can be set using the sqlite3_bind_*() routines defined here. 3288 ** 3289 ** ^The first argument to the sqlite3_bind_*() routines is always 3290 ** a pointer to the [sqlite3_stmt] object returned from 3291 ** [sqlite3_prepare_v2()] or its variants. 3292 ** 3293 ** ^The second argument is the index of the SQL parameter to be set. 3294 ** ^The leftmost SQL parameter has an index of 1. ^When the same named 3295 ** SQL parameter is used more than once, second and subsequent 3296 ** occurrences have the same index as the first occurrence. 3297 ** ^The index for named parameters can be looked up using the 3298 ** [sqlite3_bind_parameter_index()] API if desired. ^The index 3299 ** for "?NNN" parameters is the value of NNN. 3300 ** ^The NNN value must be between 1 and the [sqlite3_limit()] 3301 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). 3302 ** 3303 ** ^The third argument is the value to bind to the parameter. 3304 ** 3305 ** ^(In those routines that have a fourth argument, its value is the 3306 ** number of bytes in the parameter. To be clear: the value is the 3307 ** number of <u>bytes</u> in the value, not the number of characters.)^ 3308 ** ^If the fourth parameter is negative, the length of the string is 3309 ** the number of bytes up to the first zero terminator. 3310 ** 3311 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and 3312 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or 3313 ** string after SQLite has finished with it. ^The destructor is called 3314 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(), 3315 ** sqlite3_bind_text(), or sqlite3_bind_text16() fails. 3316 ** ^If the fifth argument is 3317 ** the special value [SQLITE_STATIC], then SQLite assumes that the 3318 ** information is in static, unmanaged space and does not need to be freed. 3319 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then 3320 ** SQLite makes its own private copy of the data immediately, before 3321 ** the sqlite3_bind_*() routine returns. 3322 ** 3323 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 3324 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 3325 ** (just an integer to hold its size) while it is being processed. 3326 ** Zeroblobs are intended to serve as placeholders for BLOBs whose 3327 ** content is later written using 3328 ** [sqlite3_blob_open | incremental BLOB I/O] routines. 3329 ** ^A negative value for the zeroblob results in a zero-length BLOB. 3330 ** 3331 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 3332 ** for the [prepared statement] or with a prepared statement for which 3333 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 3334 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 3335 ** routine is passed a [prepared statement] that has been finalized, the 3336 ** result is undefined and probably harmful. 3337 ** 3338 ** ^Bindings are not cleared by the [sqlite3_reset()] routine. 3339 ** ^Unbound parameters are interpreted as NULL. 3340 ** 3341 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 3342 ** [error code] if anything goes wrong. 3343 ** ^[SQLITE_RANGE] is returned if the parameter 3344 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 3345 ** 3346 ** See also: [sqlite3_bind_parameter_count()], 3347 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 3348 */ 3349 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 3350 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); 3351 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); 3352 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 3353 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); 3354 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); 3355 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); 3356 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 3357 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 3358 3359 /* 3360 ** CAPI3REF: Number Of SQL Parameters 3361 ** 3362 ** ^This routine can be used to find the number of [SQL parameters] 3363 ** in a [prepared statement]. SQL parameters are tokens of the 3364 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 3365 ** placeholders for values that are [sqlite3_bind_blob | bound] 3366 ** to the parameters at a later time. 3367 ** 3368 ** ^(This routine actually returns the index of the largest (rightmost) 3369 ** parameter. For all forms except ?NNN, this will correspond to the 3370 ** number of unique parameters. If parameters of the ?NNN form are used, 3371 ** there may be gaps in the list.)^ 3372 ** 3373 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 3374 ** [sqlite3_bind_parameter_name()], and 3375 ** [sqlite3_bind_parameter_index()]. 3376 */ 3377 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); 3378 3379 /* 3380 ** CAPI3REF: Name Of A Host Parameter 3381 ** 3382 ** ^The sqlite3_bind_parameter_name(P,N) interface returns 3383 ** the name of the N-th [SQL parameter] in the [prepared statement] P. 3384 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" 3385 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" 3386 ** respectively. 3387 ** In other words, the initial ":" or "$" or "@" or "?" 3388 ** is included as part of the name.)^ 3389 ** ^Parameters of the form "?" without a following integer have no name 3390 ** and are referred to as "nameless" or "anonymous parameters". 3391 ** 3392 ** ^The first host parameter has an index of 1, not 0. 3393 ** 3394 ** ^If the value N is out of range or if the N-th parameter is 3395 ** nameless, then NULL is returned. ^The returned string is 3396 ** always in UTF-8 encoding even if the named parameter was 3397 ** originally specified as UTF-16 in [sqlite3_prepare16()] or 3398 ** [sqlite3_prepare16_v2()]. 3399 ** 3400 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 3401 ** [sqlite3_bind_parameter_count()], and 3402 ** [sqlite3_bind_parameter_index()]. 3403 */ 3404 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); 3405 3406 /* 3407 ** CAPI3REF: Index Of A Parameter With A Given Name 3408 ** 3409 ** ^Return the index of an SQL parameter given its name. ^The 3410 ** index value returned is suitable for use as the second 3411 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero 3412 ** is returned if no matching parameter is found. ^The parameter 3413 ** name must be given in UTF-8 even if the original statement 3414 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. 3415 ** 3416 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 3417 ** [sqlite3_bind_parameter_count()], and 3418 ** [sqlite3_bind_parameter_index()]. 3419 */ 3420 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); 3421 3422 /* 3423 ** CAPI3REF: Reset All Bindings On A Prepared Statement 3424 ** 3425 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset 3426 ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. 3427 ** ^Use this routine to reset all host parameters to NULL. 3428 */ 3429 SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); 3430 3431 /* 3432 ** CAPI3REF: Number Of Columns In A Result Set 3433 ** 3434 ** ^Return the number of columns in the result set returned by the 3435 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL 3436 ** statement that does not return data (for example an [UPDATE]). 3437 ** 3438 ** See also: [sqlite3_data_count()] 3439 */ 3440 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); 3441 3442 /* 3443 ** CAPI3REF: Column Names In A Result Set 3444 ** 3445 ** ^These routines return the name assigned to a particular column 3446 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() 3447 ** interface returns a pointer to a zero-terminated UTF-8 string 3448 ** and sqlite3_column_name16() returns a pointer to a zero-terminated 3449 ** UTF-16 string. ^The first parameter is the [prepared statement] 3450 ** that implements the [SELECT] statement. ^The second parameter is the 3451 ** column number. ^The leftmost column is number 0. 3452 ** 3453 ** ^The returned string pointer is valid until either the [prepared statement] 3454 ** is destroyed by [sqlite3_finalize()] or until the next call to 3455 ** sqlite3_column_name() or sqlite3_column_name16() on the same column. 3456 ** 3457 ** ^If sqlite3_malloc() fails during the processing of either routine 3458 ** (for example during a conversion from UTF-8 to UTF-16) then a 3459 ** NULL pointer is returned. 3460 ** 3461 ** ^The name of a result column is the value of the "AS" clause for 3462 ** that column, if there is an AS clause. If there is no AS clause 3463 ** then the name of the column is unspecified and may change from 3464 ** one release of SQLite to the next. 3465 */ 3466 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); 3467 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); 3468 3469 /* 3470 ** CAPI3REF: Source Of Data In A Query Result 3471 ** 3472 ** ^These routines provide a means to determine the database, table, and 3473 ** table column that is the origin of a particular result column in 3474 ** [SELECT] statement. 3475 ** ^The name of the database or table or column can be returned as 3476 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return 3477 ** the database name, the _table_ routines return the table name, and 3478 ** the origin_ routines return the column name. 3479 ** ^The returned string is valid until the [prepared statement] is destroyed 3480 ** using [sqlite3_finalize()] or until the same information is requested 3481 ** again in a different encoding. 3482 ** 3483 ** ^The names returned are the original un-aliased names of the 3484 ** database, table, and column. 3485 ** 3486 ** ^The first argument to these interfaces is a [prepared statement]. 3487 ** ^These functions return information about the Nth result column returned by 3488 ** the statement, where N is the second function argument. 3489 ** ^The left-most column is column 0 for these routines. 3490 ** 3491 ** ^If the Nth column returned by the statement is an expression or 3492 ** subquery and is not a column value, then all of these functions return 3493 ** NULL. ^These routine might also return NULL if a memory allocation error 3494 ** occurs. ^Otherwise, they return the name of the attached database, table, 3495 ** or column that query result column was extracted from. 3496 ** 3497 ** ^As with all other SQLite APIs, those whose names end with "16" return 3498 ** UTF-16 encoded strings and the other functions return UTF-8. 3499 ** 3500 ** ^These APIs are only available if the library was compiled with the 3501 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. 3502 ** 3503 ** If two or more threads call one or more of these routines against the same 3504 ** prepared statement and column at the same time then the results are 3505 ** undefined. 3506 ** 3507 ** If two or more threads call one or more 3508 ** [sqlite3_column_database_name | column metadata interfaces] 3509 ** for the same [prepared statement] and result column 3510 ** at the same time then the results are undefined. 3511 */ 3512 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); 3513 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); 3514 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); 3515 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); 3516 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); 3517 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); 3518 3519 /* 3520 ** CAPI3REF: Declared Datatype Of A Query Result 3521 ** 3522 ** ^(The first parameter is a [prepared statement]. 3523 ** If this statement is a [SELECT] statement and the Nth column of the 3524 ** returned result set of that [SELECT] is a table column (not an 3525 ** expression or subquery) then the declared type of the table 3526 ** column is returned.)^ ^If the Nth column of the result set is an 3527 ** expression or subquery, then a NULL pointer is returned. 3528 ** ^The returned string is always UTF-8 encoded. 3529 ** 3530 ** ^(For example, given the database schema: 3531 ** 3532 ** CREATE TABLE t1(c1 VARIANT); 3533 ** 3534 ** and the following statement to be compiled: 3535 ** 3536 ** SELECT c1 + 1, c1 FROM t1; 3537 ** 3538 ** this routine would return the string "VARIANT" for the second result 3539 ** column (i==1), and a NULL pointer for the first result column (i==0).)^ 3540 ** 3541 ** ^SQLite uses dynamic run-time typing. ^So just because a column 3542 ** is declared to contain a particular type does not mean that the 3543 ** data stored in that column is of the declared type. SQLite is 3544 ** strongly typed, but the typing is dynamic not static. ^Type 3545 ** is associated with individual values, not with the containers 3546 ** used to hold those values. 3547 */ 3548 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); 3549 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); 3550 3551 /* 3552 ** CAPI3REF: Evaluate An SQL Statement 3553 ** 3554 ** After a [prepared statement] has been prepared using either 3555 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy 3556 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function 3557 ** must be called one or more times to evaluate the statement. 3558 ** 3559 ** The details of the behavior of the sqlite3_step() interface depend 3560 ** on whether the statement was prepared using the newer "v2" interface 3561 ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy 3562 ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the 3563 ** new "v2" interface is recommended for new applications but the legacy 3564 ** interface will continue to be supported. 3565 ** 3566 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 3567 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 3568 ** ^With the "v2" interface, any of the other [result codes] or 3569 ** [extended result codes] might be returned as well. 3570 ** 3571 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 3572 ** database locks it needs to do its job. ^If the statement is a [COMMIT] 3573 ** or occurs outside of an explicit transaction, then you can retry the 3574 ** statement. If the statement is not a [COMMIT] and occurs within a 3575 ** explicit transaction then you should rollback the transaction before 3576 ** continuing. 3577 ** 3578 ** ^[SQLITE_DONE] means that the statement has finished executing 3579 ** successfully. sqlite3_step() should not be called again on this virtual 3580 ** machine without first calling [sqlite3_reset()] to reset the virtual 3581 ** machine back to its initial state. 3582 ** 3583 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 3584 ** is returned each time a new row of data is ready for processing by the 3585 ** caller. The values may be accessed using the [column access functions]. 3586 ** sqlite3_step() is called again to retrieve the next row of data. 3587 ** 3588 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint 3589 ** violation) has occurred. sqlite3_step() should not be called again on 3590 ** the VM. More information may be found by calling [sqlite3_errmsg()]. 3591 ** ^With the legacy interface, a more specific error code (for example, 3592 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) 3593 ** can be obtained by calling [sqlite3_reset()] on the 3594 ** [prepared statement]. ^In the "v2" interface, 3595 ** the more specific error code is returned directly by sqlite3_step(). 3596 ** 3597 ** [SQLITE_MISUSE] means that the this routine was called inappropriately. 3598 ** Perhaps it was called on a [prepared statement] that has 3599 ** already been [sqlite3_finalize | finalized] or on one that had 3600 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could 3601 ** be the case that the same database connection is being used by two or 3602 ** more threads at the same moment in time. 3603 ** 3604 ** For all versions of SQLite up to and including 3.6.23.1, it was required 3605 ** after sqlite3_step() returned anything other than [SQLITE_ROW] that 3606 ** [sqlite3_reset()] be called before any subsequent invocation of 3607 ** sqlite3_step(). Failure to invoke [sqlite3_reset()] in this way would 3608 ** result in an [SQLITE_MISUSE] return from sqlite3_step(). But after 3609 ** version 3.6.23.1, sqlite3_step() began calling [sqlite3_reset()] 3610 ** automatically in this circumstance rather than returning [SQLITE_MISUSE]. 3611 ** 3612 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() 3613 ** API always returns a generic error code, [SQLITE_ERROR], following any 3614 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call 3615 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the 3616 ** specific [error codes] that better describes the error. 3617 ** We admit that this is a goofy design. The problem has been fixed 3618 ** with the "v2" interface. If you prepare all of your SQL statements 3619 ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead 3620 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, 3621 ** then the more specific [error codes] are returned directly 3622 ** by sqlite3_step(). The use of the "v2" interface is recommended. 3623 */ 3624 SQLITE_API int sqlite3_step(sqlite3_stmt*); 3625 3626 /* 3627 ** CAPI3REF: Number of columns in a result set 3628 ** 3629 ** ^The sqlite3_data_count(P) interface returns the number of columns in the 3630 ** current row of the result set of [prepared statement] P. 3631 ** ^If prepared statement P does not have results ready to return 3632 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of 3633 ** interfaces) then sqlite3_data_count(P) returns 0. 3634 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. 3635 ** 3636 ** See also: [sqlite3_column_count()] 3637 */ 3638 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); 3639 3640 /* 3641 ** CAPI3REF: Fundamental Datatypes 3642 ** KEYWORDS: SQLITE_TEXT 3643 ** 3644 ** ^(Every value in SQLite has one of five fundamental datatypes: 3645 ** 3646 ** <ul> 3647 ** <li> 64-bit signed integer 3648 ** <li> 64-bit IEEE floating point number 3649 ** <li> string 3650 ** <li> BLOB 3651 ** <li> NULL 3652 ** </ul>)^ 3653 ** 3654 ** These constants are codes for each of those types. 3655 ** 3656 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 3657 ** for a completely different meaning. Software that links against both 3658 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not 3659 ** SQLITE_TEXT. 3660 */ 3661 #define SQLITE_INTEGER 1 3662 #define SQLITE_FLOAT 2 3663 #define SQLITE_BLOB 4 3664 #define SQLITE_NULL 5 3665 #ifdef SQLITE_TEXT 3666 # undef SQLITE_TEXT 3667 #else 3668 # define SQLITE_TEXT 3 3669 #endif 3670 #define SQLITE3_TEXT 3 3671 3672 /* 3673 ** CAPI3REF: Result Values From A Query 3674 ** KEYWORDS: {column access functions} 3675 ** 3676 ** These routines form the "result set" interface. 3677 ** 3678 ** ^These routines return information about a single column of the current 3679 ** result row of a query. ^In every case the first argument is a pointer 3680 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] 3681 ** that was returned from [sqlite3_prepare_v2()] or one of its variants) 3682 ** and the second argument is the index of the column for which information 3683 ** should be returned. ^The leftmost column of the result set has the index 0. 3684 ** ^The number of columns in the result can be determined using 3685 ** [sqlite3_column_count()]. 3686 ** 3687 ** If the SQL statement does not currently point to a valid row, or if the 3688 ** column index is out of range, the result is undefined. 3689 ** These routines may only be called when the most recent call to 3690 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither 3691 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. 3692 ** If any of these routines are called after [sqlite3_reset()] or 3693 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned 3694 ** something other than [SQLITE_ROW], the results are undefined. 3695 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] 3696 ** are called from a different thread while any of these routines 3697 ** are pending, then the results are undefined. 3698 ** 3699 ** ^The sqlite3_column_type() routine returns the 3700 ** [SQLITE_INTEGER | datatype code] for the initial data type 3701 ** of the result column. ^The returned value is one of [SQLITE_INTEGER], 3702 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value 3703 ** returned by sqlite3_column_type() is only meaningful if no type 3704 ** conversions have occurred as described below. After a type conversion, 3705 ** the value returned by sqlite3_column_type() is undefined. Future 3706 ** versions of SQLite may change the behavior of sqlite3_column_type() 3707 ** following a type conversion. 3708 ** 3709 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 3710 ** routine returns the number of bytes in that BLOB or string. 3711 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts 3712 ** the string to UTF-8 and then returns the number of bytes. 3713 ** ^If the result is a numeric value then sqlite3_column_bytes() uses 3714 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns 3715 ** the number of bytes in that string. 3716 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero. 3717 ** 3718 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() 3719 ** routine returns the number of bytes in that BLOB or string. 3720 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts 3721 ** the string to UTF-16 and then returns the number of bytes. 3722 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses 3723 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns 3724 ** the number of bytes in that string. 3725 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. 3726 ** 3727 ** ^The values returned by [sqlite3_column_bytes()] and 3728 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end 3729 ** of the string. ^For clarity: the values returned by 3730 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 3731 ** bytes in the string, not the number of characters. 3732 ** 3733 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 3734 ** even empty strings, are always zero terminated. ^The return 3735 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 3736 ** 3737 ** ^The object returned by [sqlite3_column_value()] is an 3738 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 3739 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 3740 ** If the [unprotected sqlite3_value] object returned by 3741 ** [sqlite3_column_value()] is used in any other way, including calls 3742 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 3743 ** or [sqlite3_value_bytes()], then the behavior is undefined. 3744 ** 3745 ** These routines attempt to convert the value where appropriate. ^For 3746 ** example, if the internal representation is FLOAT and a text result 3747 ** is requested, [sqlite3_snprintf()] is used internally to perform the 3748 ** conversion automatically. ^(The following table details the conversions 3749 ** that are applied: 3750 ** 3751 ** <blockquote> 3752 ** <table border="1"> 3753 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 3754 ** 3755 ** <tr><td> NULL <td> INTEGER <td> Result is 0 3756 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 3757 ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer 3758 ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer 3759 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 3760 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 3761 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 3762 ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer 3763 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 3764 ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT 3765 ** <tr><td> TEXT <td> INTEGER <td> Use atoi() 3766 ** <tr><td> TEXT <td> FLOAT <td> Use atof() 3767 ** <tr><td> TEXT <td> BLOB <td> No change 3768 ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() 3769 ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() 3770 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed 3771 ** </table> 3772 ** </blockquote>)^ 3773 ** 3774 ** The table above makes reference to standard C library functions atoi() 3775 ** and atof(). SQLite does not really use these functions. It has its 3776 ** own equivalent internal routines. The atoi() and atof() names are 3777 ** used in the table for brevity and because they are familiar to most 3778 ** C programmers. 3779 ** 3780 ** Note that when type conversions occur, pointers returned by prior 3781 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or 3782 ** sqlite3_column_text16() may be invalidated. 3783 ** Type conversions and pointer invalidations might occur 3784 ** in the following cases: 3785 ** 3786 ** <ul> 3787 ** <li> The initial content is a BLOB and sqlite3_column_text() or 3788 ** sqlite3_column_text16() is called. A zero-terminator might 3789 ** need to be added to the string.</li> 3790 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or 3791 ** sqlite3_column_text16() is called. The content must be converted 3792 ** to UTF-16.</li> 3793 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or 3794 ** sqlite3_column_text() is called. The content must be converted 3795 ** to UTF-8.</li> 3796 ** </ul> 3797 ** 3798 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do 3799 ** not invalidate a prior pointer, though of course the content of the buffer 3800 ** that the prior pointer references will have been modified. Other kinds 3801 ** of conversion are done in place when it is possible, but sometimes they 3802 ** are not possible and in those cases prior pointers are invalidated. 3803 ** 3804 ** The safest and easiest to remember policy is to invoke these routines 3805 ** in one of the following ways: 3806 ** 3807 ** <ul> 3808 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> 3809 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> 3810 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> 3811 ** </ul> 3812 ** 3813 ** In other words, you should call sqlite3_column_text(), 3814 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result 3815 ** into the desired format, then invoke sqlite3_column_bytes() or 3816 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 3817 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to 3818 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 3819 ** with calls to sqlite3_column_bytes(). 3820 ** 3821 ** ^The pointers returned are valid until a type conversion occurs as 3822 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 3823 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings 3824 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned 3825 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 3826 ** [sqlite3_free()]. 3827 ** 3828 ** ^(If a memory allocation error occurs during the evaluation of any 3829 ** of these routines, a default value is returned. The default value 3830 ** is either the integer 0, the floating point number 0.0, or a NULL 3831 ** pointer. Subsequent calls to [sqlite3_errcode()] will return 3832 ** [SQLITE_NOMEM].)^ 3833 */ 3834 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 3835 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 3836 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 3837 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); 3838 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); 3839 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 3840 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 3841 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 3842 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); 3843 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 3844 3845 /* 3846 ** CAPI3REF: Destroy A Prepared Statement Object 3847 ** 3848 ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 3849 ** ^If the most recent evaluation of the statement encountered no errors or 3850 ** or if the statement is never been evaluated, then sqlite3_finalize() returns 3851 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then 3852 ** sqlite3_finalize(S) returns the appropriate [error code] or 3853 ** [extended error code]. 3854 ** 3855 ** ^The sqlite3_finalize(S) routine can be called at any point during 3856 ** the life cycle of [prepared statement] S: 3857 ** before statement S is ever evaluated, after 3858 ** one or more calls to [sqlite3_reset()], or after any call 3859 ** to [sqlite3_step()] regardless of whether or not the statement has 3860 ** completed execution. 3861 ** 3862 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. 3863 ** 3864 ** The application must finalize every [prepared statement] in order to avoid 3865 ** resource leaks. It is a grievous error for the application to try to use 3866 ** a prepared statement after it has been finalized. Any use of a prepared 3867 ** statement after it has been finalized can result in undefined and 3868 ** undesirable behavior such as segfaults and heap corruption. 3869 */ 3870 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); 3871 3872 /* 3873 ** CAPI3REF: Reset A Prepared Statement Object 3874 ** 3875 ** The sqlite3_reset() function is called to reset a [prepared statement] 3876 ** object back to its initial state, ready to be re-executed. 3877 ** ^Any SQL statement variables that had values bound to them using 3878 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. 3879 ** Use [sqlite3_clear_bindings()] to reset the bindings. 3880 ** 3881 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S 3882 ** back to the beginning of its program. 3883 ** 3884 ** ^If the most recent call to [sqlite3_step(S)] for the 3885 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], 3886 ** or if [sqlite3_step(S)] has never before been called on S, 3887 ** then [sqlite3_reset(S)] returns [SQLITE_OK]. 3888 ** 3889 ** ^If the most recent call to [sqlite3_step(S)] for the 3890 ** [prepared statement] S indicated an error, then 3891 ** [sqlite3_reset(S)] returns an appropriate [error code]. 3892 ** 3893 ** ^The [sqlite3_reset(S)] interface does not change the values 3894 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. 3895 */ 3896 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); 3897 3898 /* 3899 ** CAPI3REF: Create Or Redefine SQL Functions 3900 ** KEYWORDS: {function creation routines} 3901 ** KEYWORDS: {application-defined SQL function} 3902 ** KEYWORDS: {application-defined SQL functions} 3903 ** 3904 ** ^These functions (collectively known as "function creation routines") 3905 ** are used to add SQL functions or aggregates or to redefine the behavior 3906 ** of existing SQL functions or aggregates. The only differences between 3907 ** these routines are the text encoding expected for 3908 ** the the second parameter (the name of the function being created) 3909 ** and the presence or absence of a destructor callback for 3910 ** the application data pointer. 3911 ** 3912 ** ^The first parameter is the [database connection] to which the SQL 3913 ** function is to be added. ^If an application uses more than one database 3914 ** connection then application-defined SQL functions must be added 3915 ** to each database connection separately. 3916 ** 3917 ** ^The second parameter is the name of the SQL function to be created or 3918 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 3919 ** representation, exclusive of the zero-terminator. ^Note that the name 3920 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. 3921 ** ^Any attempt to create a function with a longer name 3922 ** will result in [SQLITE_MISUSE] being returned. 3923 ** 3924 ** ^The third parameter (nArg) 3925 ** is the number of arguments that the SQL function or 3926 ** aggregate takes. ^If this parameter is -1, then the SQL function or 3927 ** aggregate may take any number of arguments between 0 and the limit 3928 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 3929 ** parameter is less than -1 or greater than 127 then the behavior is 3930 ** undefined. 3931 ** 3932 ** ^The fourth parameter, eTextRep, specifies what 3933 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for 3934 ** its parameters. Every SQL function implementation must be able to work 3935 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be 3936 ** more efficient with one encoding than another. ^An application may 3937 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple 3938 ** times with the same function but with different values of eTextRep. 3939 ** ^When multiple implementations of the same function are available, SQLite 3940 ** will pick the one that involves the least amount of data conversion. 3941 ** If there is only a single implementation which does not care what text 3942 ** encoding is used, then the fourth argument should be [SQLITE_ANY]. 3943 ** 3944 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the 3945 ** function can gain access to this pointer using [sqlite3_user_data()].)^ 3946 ** 3947 ** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are 3948 ** pointers to C-language functions that implement the SQL function or 3949 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc 3950 ** callback only; NULL pointers must be passed as the xStep and xFinal 3951 ** parameters. ^An aggregate SQL function requires an implementation of xStep 3952 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing 3953 ** SQL function or aggregate, pass NULL poiners for all three function 3954 ** callbacks. 3955 ** 3956 ** ^(If the tenth parameter to sqlite3_create_function_v2() is not NULL, 3957 ** then it is destructor for the application data pointer. 3958 ** The destructor is invoked when the function is deleted, either by being 3959 ** overloaded or when the database connection closes.)^ 3960 ** ^The destructor is also invoked if the call to 3961 ** sqlite3_create_function_v2() fails. 3962 ** ^When the destructor callback of the tenth parameter is invoked, it 3963 ** is passed a single argument which is a copy of the application data 3964 ** pointer which was the fifth parameter to sqlite3_create_function_v2(). 3965 ** 3966 ** ^It is permitted to register multiple implementations of the same 3967 ** functions with the same name but with either differing numbers of 3968 ** arguments or differing preferred text encodings. ^SQLite will use 3969 ** the implementation that most closely matches the way in which the 3970 ** SQL function is used. ^A function implementation with a non-negative 3971 ** nArg parameter is a better match than a function implementation with 3972 ** a negative nArg. ^A function where the preferred text encoding 3973 ** matches the database encoding is a better 3974 ** match than a function where the encoding is different. 3975 ** ^A function where the encoding difference is between UTF16le and UTF16be 3976 ** is a closer match than a function where the encoding difference is 3977 ** between UTF8 and UTF16. 3978 ** 3979 ** ^Built-in functions may be overloaded by new application-defined functions. 3980 ** 3981 ** ^An application-defined function is permitted to call other 3982 ** SQLite interfaces. However, such calls must not 3983 ** close the database connection nor finalize or reset the prepared 3984 ** statement in which the function is running. 3985 */ 3986 SQLITE_API int sqlite3_create_function( 3987 sqlite3 *db, 3988 const char *zFunctionName, 3989 int nArg, 3990 int eTextRep, 3991 void *pApp, 3992 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 3993 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 3994 void (*xFinal)(sqlite3_context*) 3995 ); 3996 SQLITE_API int sqlite3_create_function16( 3997 sqlite3 *db, 3998 const void *zFunctionName, 3999 int nArg, 4000 int eTextRep, 4001 void *pApp, 4002 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 4003 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 4004 void (*xFinal)(sqlite3_context*) 4005 ); 4006 SQLITE_API int sqlite3_create_function_v2( 4007 sqlite3 *db, 4008 const char *zFunctionName, 4009 int nArg, 4010 int eTextRep, 4011 void *pApp, 4012 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 4013 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 4014 void (*xFinal)(sqlite3_context*), 4015 void(*xDestroy)(void*) 4016 ); 4017 4018 /* 4019 ** CAPI3REF: Text Encodings 4020 ** 4021 ** These constant define integer codes that represent the various 4022 ** text encodings supported by SQLite. 4023 */ 4024 #define SQLITE_UTF8 1 4025 #define SQLITE_UTF16LE 2 4026 #define SQLITE_UTF16BE 3 4027 #define SQLITE_UTF16 4 /* Use native byte order */ 4028 #define SQLITE_ANY 5 /* sqlite3_create_function only */ 4029 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 4030 4031 /* 4032 ** CAPI3REF: Deprecated Functions 4033 ** DEPRECATED 4034 ** 4035 ** These functions are [deprecated]. In order to maintain 4036 ** backwards compatibility with older code, these functions continue 4037 ** to be supported. However, new applications should avoid 4038 ** the use of these functions. To help encourage people to avoid 4039 ** using these functions, we are not going to tell you what they do. 4040 */ 4041 #ifndef SQLITE_OMIT_DEPRECATED 4042 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 4043 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 4044 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); 4045 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); 4046 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 4047 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); 4048 #endif 4049 4050 /* 4051 ** CAPI3REF: Obtaining SQL Function Parameter Values 4052 ** 4053 ** The C-language implementation of SQL functions and aggregates uses 4054 ** this set of interface routines to access the parameter values on 4055 ** the function or aggregate. 4056 ** 4057 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters 4058 ** to [sqlite3_create_function()] and [sqlite3_create_function16()] 4059 ** define callbacks that implement the SQL functions and aggregates. 4060 ** The 4th parameter to these callbacks is an array of pointers to 4061 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for 4062 ** each parameter to the SQL function. These routines are used to 4063 ** extract values from the [sqlite3_value] objects. 4064 ** 4065 ** These routines work only with [protected sqlite3_value] objects. 4066 ** Any attempt to use these routines on an [unprotected sqlite3_value] 4067 ** object results in undefined behavior. 4068 ** 4069 ** ^These routines work just like the corresponding [column access functions] 4070 ** except that these routines take a single [protected sqlite3_value] object 4071 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 4072 ** 4073 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string 4074 ** in the native byte-order of the host machine. ^The 4075 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 4076 ** extract UTF-16 strings as big-endian and little-endian respectively. 4077 ** 4078 ** ^(The sqlite3_value_numeric_type() interface attempts to apply 4079 ** numeric affinity to the value. This means that an attempt is 4080 ** made to convert the value to an integer or floating point. If 4081 ** such a conversion is possible without loss of information (in other 4082 ** words, if the value is a string that looks like a number) 4083 ** then the conversion is performed. Otherwise no conversion occurs. 4084 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ 4085 ** 4086 ** Please pay particular attention to the fact that the pointer returned 4087 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or 4088 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to 4089 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], 4090 ** or [sqlite3_value_text16()]. 4091 ** 4092 ** These routines must be called from the same thread as 4093 ** the SQL function that supplied the [sqlite3_value*] parameters. 4094 */ 4095 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); 4096 SQLITE_API int sqlite3_value_bytes(sqlite3_value*); 4097 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); 4098 SQLITE_API double sqlite3_value_double(sqlite3_value*); 4099 SQLITE_API int sqlite3_value_int(sqlite3_value*); 4100 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); 4101 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); 4102 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); 4103 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); 4104 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); 4105 SQLITE_API int sqlite3_value_type(sqlite3_value*); 4106 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); 4107 4108 /* 4109 ** CAPI3REF: Obtain Aggregate Function Context 4110 ** 4111 ** Implementations of aggregate SQL functions use this 4112 ** routine to allocate memory for storing their state. 4113 ** 4114 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called 4115 ** for a particular aggregate function, SQLite 4116 ** allocates N of memory, zeroes out that memory, and returns a pointer 4117 ** to the new memory. ^On second and subsequent calls to 4118 ** sqlite3_aggregate_context() for the same aggregate function instance, 4119 ** the same buffer is returned. Sqlite3_aggregate_context() is normally 4120 ** called once for each invocation of the xStep callback and then one 4121 ** last time when the xFinal callback is invoked. ^(When no rows match 4122 ** an aggregate query, the xStep() callback of the aggregate function 4123 ** implementation is never called and xFinal() is called exactly once. 4124 ** In those cases, sqlite3_aggregate_context() might be called for the 4125 ** first time from within xFinal().)^ 4126 ** 4127 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is 4128 ** less than or equal to zero or if a memory allocate error occurs. 4129 ** 4130 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 4131 ** determined by the N parameter on first successful call. Changing the 4132 ** value of N in subsequent call to sqlite3_aggregate_context() within 4133 ** the same aggregate function instance will not resize the memory 4134 ** allocation.)^ 4135 ** 4136 ** ^SQLite automatically frees the memory allocated by 4137 ** sqlite3_aggregate_context() when the aggregate query concludes. 4138 ** 4139 ** The first parameter must be a copy of the 4140 ** [sqlite3_context | SQL function context] that is the first parameter 4141 ** to the xStep or xFinal callback routine that implements the aggregate 4142 ** function. 4143 ** 4144 ** This routine must be called from the same thread in which 4145 ** the aggregate SQL function is running. 4146 */ 4147 SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); 4148 4149 /* 4150 ** CAPI3REF: User Data For Functions 4151 ** 4152 ** ^The sqlite3_user_data() interface returns a copy of 4153 ** the pointer that was the pUserData parameter (the 5th parameter) 4154 ** of the [sqlite3_create_function()] 4155 ** and [sqlite3_create_function16()] routines that originally 4156 ** registered the application defined function. 4157 ** 4158 ** This routine must be called from the same thread in which 4159 ** the application-defined function is running. 4160 */ 4161 SQLITE_API void *sqlite3_user_data(sqlite3_context*); 4162 4163 /* 4164 ** CAPI3REF: Database Connection For Functions 4165 ** 4166 ** ^The sqlite3_context_db_handle() interface returns a copy of 4167 ** the pointer to the [database connection] (the 1st parameter) 4168 ** of the [sqlite3_create_function()] 4169 ** and [sqlite3_create_function16()] routines that originally 4170 ** registered the application defined function. 4171 */ 4172 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 4173 4174 /* 4175 ** CAPI3REF: Function Auxiliary Data 4176 ** 4177 ** The following two functions may be used by scalar SQL functions to 4178 ** associate metadata with argument values. If the same value is passed to 4179 ** multiple invocations of the same SQL function during query execution, under 4180 ** some circumstances the associated metadata may be preserved. This may 4181 ** be used, for example, to add a regular-expression matching scalar 4182 ** function. The compiled version of the regular expression is stored as 4183 ** metadata associated with the SQL value passed as the regular expression 4184 ** pattern. The compiled regular expression can be reused on multiple 4185 ** invocations of the same function so that the original pattern string 4186 ** does not need to be recompiled on each invocation. 4187 ** 4188 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata 4189 ** associated by the sqlite3_set_auxdata() function with the Nth argument 4190 ** value to the application-defined function. ^If no metadata has been ever 4191 ** been set for the Nth argument of the function, or if the corresponding 4192 ** function parameter has changed since the meta-data was set, 4193 ** then sqlite3_get_auxdata() returns a NULL pointer. 4194 ** 4195 ** ^The sqlite3_set_auxdata() interface saves the metadata 4196 ** pointed to by its 3rd parameter as the metadata for the N-th 4197 ** argument of the application-defined function. Subsequent 4198 ** calls to sqlite3_get_auxdata() might return this data, if it has 4199 ** not been destroyed. 4200 ** ^If it is not NULL, SQLite will invoke the destructor 4201 ** function given by the 4th parameter to sqlite3_set_auxdata() on 4202 ** the metadata when the corresponding function parameter changes 4203 ** or when the SQL statement completes, whichever comes first. 4204 ** 4205 ** SQLite is free to call the destructor and drop metadata on any 4206 ** parameter of any function at any time. ^The only guarantee is that 4207 ** the destructor will be called before the metadata is dropped. 4208 ** 4209 ** ^(In practice, metadata is preserved between function calls for 4210 ** expressions that are constant at compile time. This includes literal 4211 ** values and [parameters].)^ 4212 ** 4213 ** These routines must be called from the same thread in which 4214 ** the SQL function is running. 4215 */ 4216 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); 4217 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); 4218 4219 4220 /* 4221 ** CAPI3REF: Constants Defining Special Destructor Behavior 4222 ** 4223 ** These are special values for the destructor that is passed in as the 4224 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 4225 ** argument is SQLITE_STATIC, it means that the content pointer is constant 4226 ** and will never change. It does not need to be destroyed. ^The 4227 ** SQLITE_TRANSIENT value means that the content will likely change in 4228 ** the near future and that SQLite should make its own private copy of 4229 ** the content before returning. 4230 ** 4231 ** The typedef is necessary to work around problems in certain 4232 ** C++ compilers. See ticket #2191. 4233 */ 4234 typedef void (*sqlite3_destructor_type)(void*); 4235 #define SQLITE_STATIC ((sqlite3_destructor_type)0) 4236 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 4237 4238 /* 4239 ** CAPI3REF: Setting The Result Of An SQL Function 4240 ** 4241 ** These routines are used by the xFunc or xFinal callbacks that 4242 ** implement SQL functions and aggregates. See 4243 ** [sqlite3_create_function()] and [sqlite3_create_function16()] 4244 ** for additional information. 4245 ** 4246 ** These functions work very much like the [parameter binding] family of 4247 ** functions used to bind values to host parameters in prepared statements. 4248 ** Refer to the [SQL parameter] documentation for additional information. 4249 ** 4250 ** ^The sqlite3_result_blob() interface sets the result from 4251 ** an application-defined function to be the BLOB whose content is pointed 4252 ** to by the second parameter and which is N bytes long where N is the 4253 ** third parameter. 4254 ** 4255 ** ^The sqlite3_result_zeroblob() interfaces set the result of 4256 ** the application-defined function to be a BLOB containing all zero 4257 ** bytes and N bytes in size, where N is the value of the 2nd parameter. 4258 ** 4259 ** ^The sqlite3_result_double() interface sets the result from 4260 ** an application-defined function to be a floating point value specified 4261 ** by its 2nd argument. 4262 ** 4263 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions 4264 ** cause the implemented SQL function to throw an exception. 4265 ** ^SQLite uses the string pointed to by the 4266 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() 4267 ** as the text of an error message. ^SQLite interprets the error 4268 ** message string from sqlite3_result_error() as UTF-8. ^SQLite 4269 ** interprets the string from sqlite3_result_error16() as UTF-16 in native 4270 ** byte order. ^If the third parameter to sqlite3_result_error() 4271 ** or sqlite3_result_error16() is negative then SQLite takes as the error 4272 ** message all text up through the first zero character. 4273 ** ^If the third parameter to sqlite3_result_error() or 4274 ** sqlite3_result_error16() is non-negative then SQLite takes that many 4275 ** bytes (not characters) from the 2nd parameter as the error message. 4276 ** ^The sqlite3_result_error() and sqlite3_result_error16() 4277 ** routines make a private copy of the error message text before 4278 ** they return. Hence, the calling function can deallocate or 4279 ** modify the text after they return without harm. 4280 ** ^The sqlite3_result_error_code() function changes the error code 4281 ** returned by SQLite as a result of an error in a function. ^By default, 4282 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 4283 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 4284 ** 4285 ** ^The sqlite3_result_toobig() interface causes SQLite to throw an error 4286 ** indicating that a string or BLOB is too long to represent. 4287 ** 4288 ** ^The sqlite3_result_nomem() interface causes SQLite to throw an error 4289 ** indicating that a memory allocation failed. 4290 ** 4291 ** ^The sqlite3_result_int() interface sets the return value 4292 ** of the application-defined function to be the 32-bit signed integer 4293 ** value given in the 2nd argument. 4294 ** ^The sqlite3_result_int64() interface sets the return value 4295 ** of the application-defined function to be the 64-bit signed integer 4296 ** value given in the 2nd argument. 4297 ** 4298 ** ^The sqlite3_result_null() interface sets the return value 4299 ** of the application-defined function to be NULL. 4300 ** 4301 ** ^The sqlite3_result_text(), sqlite3_result_text16(), 4302 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 4303 ** set the return value of the application-defined function to be 4304 ** a text string which is represented as UTF-8, UTF-16 native byte order, 4305 ** UTF-16 little endian, or UTF-16 big endian, respectively. 4306 ** ^SQLite takes the text result from the application from 4307 ** the 2nd parameter of the sqlite3_result_text* interfaces. 4308 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 4309 ** is negative, then SQLite takes result text from the 2nd parameter 4310 ** through the first zero character. 4311 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 4312 ** is non-negative, then as many bytes (not characters) of the text 4313 ** pointed to by the 2nd parameter are taken as the application-defined 4314 ** function result. 4315 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 4316 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 4317 ** function as the destructor on the text or BLOB result when it has 4318 ** finished using that result. 4319 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 4320 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 4321 ** assumes that the text or BLOB result is in constant space and does not 4322 ** copy the content of the parameter nor call a destructor on the content 4323 ** when it has finished using that result. 4324 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 4325 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 4326 ** then SQLite makes a copy of the result into space obtained from 4327 ** from [sqlite3_malloc()] before it returns. 4328 ** 4329 ** ^The sqlite3_result_value() interface sets the result of 4330 ** the application-defined function to be a copy the 4331 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 4332 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 4333 ** so that the [sqlite3_value] specified in the parameter may change or 4334 ** be deallocated after sqlite3_result_value() returns without harm. 4335 ** ^A [protected sqlite3_value] object may always be used where an 4336 ** [unprotected sqlite3_value] object is required, so either 4337 ** kind of [sqlite3_value] object can be used with this interface. 4338 ** 4339 ** If these routines are called from within the different thread 4340 ** than the one containing the application-defined function that received 4341 ** the [sqlite3_context] pointer, the results are undefined. 4342 */ 4343 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); 4344 SQLITE_API void sqlite3_result_double(sqlite3_context*, double); 4345 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); 4346 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); 4347 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); 4348 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); 4349 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); 4350 SQLITE_API void sqlite3_result_int(sqlite3_context*, int); 4351 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 4352 SQLITE_API void sqlite3_result_null(sqlite3_context*); 4353 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); 4354 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); 4355 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); 4356 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); 4357 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 4358 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); 4359 4360 /* 4361 ** CAPI3REF: Define New Collating Sequences 4362 ** 4363 ** ^These functions add, remove, or modify a [collation] associated 4364 ** with the [database connection] specified as the first argument. 4365 ** 4366 ** ^The name of the collation is a UTF-8 string 4367 ** for sqlite3_create_collation() and sqlite3_create_collation_v2() 4368 ** and a UTF-16 string in native byte order for sqlite3_create_collation16(). 4369 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are 4370 ** considered to be the same name. 4371 ** 4372 ** ^(The third argument (eTextRep) must be one of the constants: 4373 ** <ul> 4374 ** <li> [SQLITE_UTF8], 4375 ** <li> [SQLITE_UTF16LE], 4376 ** <li> [SQLITE_UTF16BE], 4377 ** <li> [SQLITE_UTF16], or 4378 ** <li> [SQLITE_UTF16_ALIGNED]. 4379 ** </ul>)^ 4380 ** ^The eTextRep argument determines the encoding of strings passed 4381 ** to the collating function callback, xCallback. 4382 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep 4383 ** force strings to be UTF16 with native byte order. 4384 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin 4385 ** on an even byte address. 4386 ** 4387 ** ^The fourth argument, pArg, is a application data pointer that is passed 4388 ** through as the first argument to the collating function callback. 4389 ** 4390 ** ^The fifth argument, xCallback, is a pointer to the collating function. 4391 ** ^Multiple collating functions can be registered using the same name but 4392 ** with different eTextRep parameters and SQLite will use whichever 4393 ** function requires the least amount of data transformation. 4394 ** ^If the xCallback argument is NULL then the collating function is 4395 ** deleted. ^When all collating functions having the same name are deleted, 4396 ** that collation is no longer usable. 4397 ** 4398 ** ^The collating function callback is invoked with a copy of the pArg 4399 ** application data pointer and with two strings in the encoding specified 4400 ** by the eTextRep argument. The collating function must return an 4401 ** integer that is negative, zero, or positive 4402 ** if the first string is less than, equal to, or greater than the second, 4403 ** respectively. A collating function must alway return the same answer 4404 ** given the same inputs. If two or more collating functions are registered 4405 ** to the same collation name (using different eTextRep values) then all 4406 ** must give an equivalent answer when invoked with equivalent strings. 4407 ** The collating function must obey the following properties for all 4408 ** strings A, B, and C: 4409 ** 4410 ** <ol> 4411 ** <li> If A==B then B==A. 4412 ** <li> If A==B and B==C then A==C. 4413 ** <li> If A<B THEN B>A. 4414 ** <li> If A<B and B<C then A<C. 4415 ** </ol> 4416 ** 4417 ** If a collating function fails any of the above constraints and that 4418 ** collating function is registered and used, then the behavior of SQLite 4419 ** is undefined. 4420 ** 4421 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() 4422 ** with the addition that the xDestroy callback is invoked on pArg when 4423 ** the collating function is deleted. 4424 ** ^Collating functions are deleted when they are overridden by later 4425 ** calls to the collation creation functions or when the 4426 ** [database connection] is closed using [sqlite3_close()]. 4427 ** 4428 ** ^The xDestroy callback is <u>not</u> called if the 4429 ** sqlite3_create_collation_v2() function fails. Applications that invoke 4430 ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should 4431 ** check the return code and dispose of the application data pointer 4432 ** themselves rather than expecting SQLite to deal with it for them. 4433 ** This is different from every other SQLite interface. The inconsistency 4434 ** is unfortunate but cannot be changed without breaking backwards 4435 ** compatibility. 4436 ** 4437 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. 4438 */ 4439 SQLITE_API int sqlite3_create_collation( 4440 sqlite3*, 4441 const char *zName, 4442 int eTextRep, 4443 void *pArg, 4444 int(*xC