1#if defined(_MSC_VER) && _MSC_VER < 1300 2#pragma optimize("", off) 3#endif 4 5/****************************************************************************** 6** This file is an amalgamation of many separate C source files from SQLite 7** version 3.7.7.1. By combining all the individual C code files into this 8** single large file, the entire code can be compiled as a single translation 9** unit. This allows many compilers to do optimizations that would not be 10** possible if the files were compiled separately. Performance improvements 11** of 5% or more are commonly seen when SQLite is compiled as a single 12** translation unit. 13** 14** This file is all you need to compile SQLite. To use SQLite in other 15** programs, you need this file and the "sqlite3.h" header file that defines 16** the programming interface to the SQLite library. (If you do not have 17** the "sqlite3.h" header file at hand, you will find a copy embedded within 18** the text of this file. Search for "Begin file sqlite3.h" to find the start 19** of the embedded sqlite3.h header file.) Additional code files may be needed 20** if you want a wrapper to interface SQLite with your choice of programming 21** language. The code for the "sqlite3" command-line shell is also in a 22** separate file. This file contains only code for the core SQLite library. 23*/ 24#define SQLITE_CORE 1 25#define SQLITE_AMALGAMATION 1 26#ifndef SQLITE_PRIVATE 27# define SQLITE_PRIVATE static 28#endif 29#ifndef SQLITE_API 30# define SQLITE_API 31#endif 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 62. The upper bound on 62 is because a 64-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 468SQLITE_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 588extern "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.7.1" 658#define SQLITE_VERSION_NUMBER 3007007 659#define SQLITE_SOURCE_ID "2011-06-28 17:39:05 af0d91adf497f5f36ec3813f04235a6e195a605f" 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*/ 691SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; 692SQLITE_API const char *sqlite3_libversion(void); 693SQLITE_API const char *sqlite3_sourceid(void); 694SQLITE_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 719SQLITE_API int sqlite3_compileoption_used(const char *zOptName); 720SQLITE_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*/ 759SQLITE_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*/ 774typedef 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 802typedef sqlite_int64 sqlite3_int64; 803typedef 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*/ 837SQLITE_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*/ 844typedef 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** 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*/ 907SQLITE_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** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. 927*/ 928#define SQLITE_OK 0 /* Successful result */ 929/* beginning-of-error-codes */ 930#define SQLITE_ERROR 1 /* SQL error or missing database */ 931#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 932#define SQLITE_PERM 3 /* Access permission denied */ 933#define SQLITE_ABORT 4 /* Callback routine requested an abort */ 934#define SQLITE_BUSY 5 /* The database file is locked */ 935#define SQLITE_LOCKED 6 /* A table in the database is locked */ 936#define SQLITE_NOMEM 7 /* A malloc() failed */ 937#define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 938#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 939#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 940#define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 941#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ 942#define SQLITE_FULL 13 /* Insertion failed because database is full */ 943#define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 944#define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 945#define SQLITE_EMPTY 16 /* Database is empty */ 946#define SQLITE_SCHEMA 17 /* The database schema changed */ 947#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 948#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 949#define SQLITE_MISMATCH 20 /* Data type mismatch */ 950#define SQLITE_MISUSE 21 /* Library used incorrectly */ 951#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 952#define SQLITE_AUTH 23 /* Authorization denied */ 953#define SQLITE_FORMAT 24 /* Auxiliary database format error */ 954#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 955#define SQLITE_NOTADB 26 /* File opened that is not a database file */ 956#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 957#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 958/* end-of-error-codes */ 959 960/* 961** CAPI3REF: Extended Result Codes 962** KEYWORDS: {extended error code} {extended error codes} 963** KEYWORDS: {extended result code} {extended result codes} 964** 965** In its default configuration, SQLite API routines return one of 26 integer 966** [SQLITE_OK | result codes]. However, experience has shown that many of 967** these result codes are too coarse-grained. They do not provide as 968** much information about problems as programmers might like. In an effort to 969** address this, newer versions of SQLite (version 3.3.8 and later) include 970** support for additional result codes that provide more detailed information 971** about errors. The extended result codes are enabled or disabled 972** on a per database connection basis using the 973** [sqlite3_extended_result_codes()] API. 974** 975** Some of the available extended result codes are listed here. 976** One may expect the number of extended result codes will be expand 977** over time. Software that uses extended result codes should expect 978** to see new result codes in future releases of SQLite. 979** 980** The SQLITE_OK result code will never be extended. It will always 981** be exactly zero. 982*/ 983#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 984#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 985#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 986#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 987#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 988#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 989#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 990#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 991#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 992#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 993#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 994#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 995#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 996#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 997#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 998#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 999#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 1000#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) 1001#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 1002#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 1003#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) 1004#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<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#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 1009#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 1010#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 1011 1012/* 1013** CAPI3REF: Flags For File Open Operations 1014** 1015** These bit values are intended for use in the 1016** 3rd parameter to the [sqlite3_open_v2()] interface and 1017** in the 4th parameter to the [sqlite3_vfs.xOpen] method. 1018*/ 1019#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 1020#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 1021#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 1022#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 1023#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 1024#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 1025#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ 1026#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 1027#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 1028#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 1029#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 1030#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 1031#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 1032#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 1033#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 1034#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 1035#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 1036#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 1037#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ 1038 1039/* Reserved: 0x00F00000 */ 1040 1041/* 1042** CAPI3REF: Device Characteristics 1043** 1044** The xDeviceCharacteristics method of the [sqlite3_io_methods] 1045** object returns an integer which is a vector of the these 1046** bit values expressing I/O characteristics of the mass storage 1047** device that holds the file that the [sqlite3_io_methods] 1048** refers to. 1049** 1050** The SQLITE_IOCAP_ATOMIC property means that all writes of 1051** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 1052** mean that writes of blocks that are nnn bytes in size and 1053** are aligned to an address which is an integer multiple of 1054** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 1055** that when data is appended to a file, the data is appended 1056** first then the size of the file is extended, never the other 1057** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 1058** information is written to disk in the same order as calls 1059** to xWrite(). 1060*/ 1061#define SQLITE_IOCAP_ATOMIC 0x00000001 1062#define SQLITE_IOCAP_ATOMIC512 0x00000002 1063#define SQLITE_IOCAP_ATOMIC1K 0x00000004 1064#define SQLITE_IOCAP_ATOMIC2K 0x00000008 1065#define SQLITE_IOCAP_ATOMIC4K 0x00000010 1066#define SQLITE_IOCAP_ATOMIC8K 0x00000020 1067#define SQLITE_IOCAP_ATOMIC16K 0x00000040 1068#define SQLITE_IOCAP_ATOMIC32K 0x00000080 1069#define SQLITE_IOCAP_ATOMIC64K 0x00000100 1070#define SQLITE_IOCAP_SAFE_APPEND 0x00000200 1071#define SQLITE_IOCAP_SEQUENTIAL 0x00000400 1072#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 1073 1074/* 1075** CAPI3REF: File Locking Levels 1076** 1077** SQLite uses one of these integer values as the second 1078** argument to calls it makes to the xLock() and xUnlock() methods 1079** of an [sqlite3_io_methods] object. 1080*/ 1081#define SQLITE_LOCK_NONE 0 1082#define SQLITE_LOCK_SHARED 1 1083#define SQLITE_LOCK_RESERVED 2 1084#define SQLITE_LOCK_PENDING 3 1085#define SQLITE_LOCK_EXCLUSIVE 4 1086 1087/* 1088** CAPI3REF: Synchronization Type Flags 1089** 1090** When SQLite invokes the xSync() method of an 1091** [sqlite3_io_methods] object it uses a combination of 1092** these integer values as the second argument. 1093** 1094** When the SQLITE_SYNC_DATAONLY flag is used, it means that the 1095** sync operation only needs to flush data to mass storage. Inode 1096** information need not be flushed. If the lower four bits of the flag 1097** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. 1098** If the lower four bits equal SQLITE_SYNC_FULL, that means 1099** to use Mac OS X style fullsync instead of fsync(). 1100** 1101** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags 1102** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL 1103** settings. The [synchronous pragma] determines when calls to the 1104** xSync VFS method occur and applies uniformly across all platforms. 1105** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how 1106** energetic or rigorous or forceful the sync operations are and 1107** only make a difference on Mac OSX for the default SQLite code. 1108** (Third-party VFS implementations might also make the distinction 1109** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the 1110** operating systems natively supported by SQLite, only Mac OSX 1111** cares about the difference.) 1112*/ 1113#define SQLITE_SYNC_NORMAL 0x00002 1114#define SQLITE_SYNC_FULL 0x00003 1115#define SQLITE_SYNC_DATAONLY 0x00010 1116 1117/* 1118** CAPI3REF: OS Interface Open File Handle 1119** 1120** An [sqlite3_file] object represents an open file in the 1121** [sqlite3_vfs | OS interface layer]. Individual OS interface 1122** implementations will 1123** want to subclass this object by appending additional fields 1124** for their own use. The pMethods entry is a pointer to an 1125** [sqlite3_io_methods] object that defines methods for performing 1126** I/O operations on the open file. 1127*/ 1128typedef struct sqlite3_file sqlite3_file; 1129struct sqlite3_file { 1130 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 1131}; 1132 1133/* 1134** CAPI3REF: OS Interface File Virtual Methods Object 1135** 1136** Every file opened by the [sqlite3_vfs.xOpen] method populates an 1137** [sqlite3_file] object (or, more commonly, a subclass of the 1138** [sqlite3_file] object) with a pointer to an instance of this object. 1139** This object defines the methods used to perform various operations 1140** against the open file represented by the [sqlite3_file] object. 1141** 1142** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element 1143** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 1144** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The 1145** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] 1146** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element 1147** to NULL. 1148** 1149** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 1150** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 1151** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 1152** flag may be ORed in to indicate that only the data of the file 1153** and not its inode needs to be synced. 1154** 1155** The integer values to xLock() and xUnlock() are one of 1156** <ul> 1157** <li> [SQLITE_LOCK_NONE], 1158** <li> [SQLITE_LOCK_SHARED], 1159** <li> [SQLITE_LOCK_RESERVED], 1160** <li> [SQLITE_LOCK_PENDING], or 1161** <li> [SQLITE_LOCK_EXCLUSIVE]. 1162** </ul> 1163** xLock() increases the lock. xUnlock() decreases the lock. 1164** The xCheckReservedLock() method checks whether any database connection, 1165** either in this process or in some other process, is holding a RESERVED, 1166** PENDING, or EXCLUSIVE lock on the file. It returns true 1167** if such a lock exists and false otherwise. 1168** 1169** The xFileControl() method is a generic interface that allows custom 1170** VFS implementations to directly control an open file using the 1171** [sqlite3_file_control()] interface. The second "op" argument is an 1172** integer opcode. The third argument is a generic pointer intended to 1173** point to a structure that may contain arguments or space in which to 1174** write return values. Potential uses for xFileControl() might be 1175** functions to enable blocking locks with timeouts, to change the 1176** locking strategy (for example to use dot-file locks), to inquire 1177** about the status of a lock, or to break stale locks. The SQLite 1178** core reserves all opcodes less than 100 for its own use. 1179** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. 1180** Applications that define a custom xFileControl method should use opcodes 1181** greater than 100 to avoid conflicts. VFS implementations should 1182** return [SQLITE_NOTFOUND] for file control opcodes that they do not 1183** recognize. 1184** 1185** The xSectorSize() method returns the sector size of the 1186** device that underlies the file. The sector size is the 1187** minimum write that can be performed without disturbing 1188** other bytes in the file. The xDeviceCharacteristics() 1189** method returns a bit vector describing behaviors of the 1190** underlying device: 1191** 1192** <ul> 1193** <li> [SQLITE_IOCAP_ATOMIC] 1194** <li> [SQLITE_IOCAP_ATOMIC512] 1195** <li> [SQLITE_IOCAP_ATOMIC1K] 1196** <li> [SQLITE_IOCAP_ATOMIC2K] 1197** <li> [SQLITE_IOCAP_ATOMIC4K] 1198** <li> [SQLITE_IOCAP_ATOMIC8K] 1199** <li> [SQLITE_IOCAP_ATOMIC16K] 1200** <li> [SQLITE_IOCAP_ATOMIC32K] 1201** <li> [SQLITE_IOCAP_ATOMIC64K] 1202** <li> [SQLITE_IOCAP_SAFE_APPEND] 1203** <li> [SQLITE_IOCAP_SEQUENTIAL] 1204** </ul> 1205** 1206** The SQLITE_IOCAP_ATOMIC property means that all writes of 1207** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 1208** mean that writes of blocks that are nnn bytes in size and 1209** are aligned to an address which is an integer multiple of 1210** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 1211** that when data is appended to a file, the data is appended 1212** first then the size of the file is extended, never the other 1213** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 1214** information is written to disk in the same order as calls 1215** to xWrite(). 1216** 1217** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill 1218** in the unread portions of the buffer with zeros. A VFS that 1219** fails to zero-fill short reads might seem to work. However, 1220** failure to zero-fill short reads will eventually lead to 1221** database corruption. 1222*/ 1223typedef struct sqlite3_io_methods sqlite3_io_methods; 1224struct sqlite3_io_methods { 1225 int iVersion; 1226 int (*xClose)(sqlite3_file*); 1227 int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 1228 int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); 1229 int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); 1230 int (*xSync)(sqlite3_file*, int flags); 1231 int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); 1232 int (*xLock)(sqlite3_file*, int); 1233 int (*xUnlock)(sqlite3_file*, int); 1234 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 1235 int (*xFileControl)(sqlite3_file*, int op, void *pArg); 1236 int (*xSectorSize)(sqlite3_file*); 1237 int (*xDeviceCharacteristics)(sqlite3_file*); 1238 /* Methods above are valid for version 1 */ 1239 int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); 1240 int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); 1241 void (*xShmBarrier)(sqlite3_file*); 1242 int (*xShmUnmap)(sqlite3_file*, int deleteFlag); 1243 /* Methods above are valid for version 2 */ 1244 /* Additional methods may be added in future releases */ 1245}; 1246 1247/* 1248** CAPI3REF: Standard File Control Opcodes 1249** 1250** These integer constants are opcodes for the xFileControl method 1251** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 1252** interface. 1253** 1254** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 1255** opcode causes the xFileControl method to write the current state of 1256** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 1257** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 1258** into an integer that the pArg argument points to. This capability 1259** is used during testing and only needs to be supported when SQLITE_TEST 1260** is defined. 1261** 1262** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS 1263** layer a hint of how large the database file will grow to be during the 1264** current transaction. This hint is not guaranteed to be accurate but it 1265** is often close. The underlying VFS might choose to preallocate database 1266** file space based on this hint in order to help writes to the database 1267** file run faster. 1268** 1269** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS 1270** extends and truncates the database file in chunks of a size specified 1271** by the user. The fourth argument to [sqlite3_file_control()] should 1272** point to an integer (type int) containing the new chunk-size to use 1273** for the nominated database. Allocating database file space in large 1274** chunks (say 1MB at a time), may reduce file-system fragmentation and 1275** improve performance on some systems. 1276** 1277** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer 1278** to the [sqlite3_file] object associated with a particular database 1279** connection. See the [sqlite3_file_control()] documentation for 1280** additional information. 1281** 1282** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by 1283** SQLite and sent to all VFSes in place of a call to the xSync method 1284** when the database connection has [PRAGMA synchronous] set to OFF.)^ 1285** Some specialized VFSes need this signal in order to operate correctly 1286** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 1287** VFSes do not need this signal and should silently ignore this opcode. 1288** Applications should not call [sqlite3_file_control()] with this 1289** opcode as doing so may disrupt the operation of the specialized VFSes 1290** that do require it. 1291*/ 1292#define SQLITE_FCNTL_LOCKSTATE 1 1293#define SQLITE_GET_LOCKPROXYFILE 2 1294#define SQLITE_SET_LOCKPROXYFILE 3 1295#define SQLITE_LAST_ERRNO 4 1296#define SQLITE_FCNTL_SIZE_HINT 5 1297#define SQLITE_FCNTL_CHUNK_SIZE 6 1298#define SQLITE_FCNTL_FILE_POINTER 7 1299#define SQLITE_FCNTL_SYNC_OMITTED 8 1300 1301 1302/* 1303** CAPI3REF: Mutex Handle 1304** 1305** The mutex module within SQLite defines [sqlite3_mutex] to be an 1306** abstract type for a mutex object. The SQLite core never looks 1307** at the internal representation of an [sqlite3_mutex]. It only 1308** deals with pointers to the [sqlite3_mutex] object. 1309** 1310** Mutexes are created using [sqlite3_mutex_alloc()]. 1311*/ 1312typedef struct sqlite3_mutex sqlite3_mutex; 1313 1314/* 1315** CAPI3REF: OS Interface Object 1316** 1317** An instance of the sqlite3_vfs object defines the interface between 1318** the SQLite core and the underlying operating system. The "vfs" 1319** in the name of the object stands for "virtual file system". See 1320** the [VFS | VFS documentation] for further information. 1321** 1322** The value of the iVersion field is initially 1 but may be larger in 1323** future versions of SQLite. Additional fields may be appended to this 1324** object when the iVersion value is increased. Note that the structure 1325** of the sqlite3_vfs object changes in the transaction between 1326** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not 1327** modified. 1328** 1329** The szOsFile field is the size of the subclassed [sqlite3_file] 1330** structure used by this VFS. mxPathname is the maximum length of 1331** a pathname in this VFS. 1332** 1333** Registered sqlite3_vfs objects are kept on a linked list formed by 1334** the pNext pointer. The [sqlite3_vfs_register()] 1335** and [sqlite3_vfs_unregister()] interfaces manage this list 1336** in a thread-safe way. The [sqlite3_vfs_find()] interface 1337** searches the list. Neither the application code nor the VFS 1338** implementation should use the pNext pointer. 1339** 1340** The pNext field is the only field in the sqlite3_vfs 1341** structure that SQLite will ever modify. SQLite will only access 1342** or modify this field while holding a particular static mutex. 1343** The application should never modify anything within the sqlite3_vfs 1344** object once the object has been registered. 1345** 1346** The zName field holds the name of the VFS module. The name must 1347** be unique across all VFS modules. 1348** 1349** [[sqlite3_vfs.xOpen]] 1350** ^SQLite guarantees that the zFilename parameter to xOpen 1351** is either a NULL pointer or string obtained 1352** from xFullPathname() with an optional suffix added. 1353** ^If a suffix is added to the zFilename parameter, it will 1354** consist of a single "-" character followed by no more than 1355** 10 alphanumeric and/or "-" characters. 1356** ^SQLite further guarantees that 1357** the string will be valid and unchanged until xClose() is 1358** called. Because of the previous sentence, 1359** the [sqlite3_file] can safely store a pointer to the 1360** filename if it needs to remember the filename for some reason. 1361** If the zFilename parameter to xOpen is a NULL pointer then xOpen 1362** must invent its own temporary name for the file. ^Whenever the 1363** xFilename parameter is NULL it will also be the case that the 1364** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 1365** 1366** The flags argument to xOpen() includes all bits set in 1367** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] 1368** or [sqlite3_open16()] is used, then flags includes at least 1369** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 1370** If xOpen() opens a file read-only then it sets *pOutFlags to 1371** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. 1372** 1373** ^(SQLite will also add one of the following flags to the xOpen() 1374** call, depending on the object being opened: 1375** 1376** <ul> 1377** <li> [SQLITE_OPEN_MAIN_DB] 1378** <li> [SQLITE_OPEN_MAIN_JOURNAL] 1379** <li> [SQLITE_OPEN_TEMP_DB] 1380** <li> [SQLITE_OPEN_TEMP_JOURNAL] 1381** <li> [SQLITE_OPEN_TRANSIENT_DB] 1382** <li> [SQLITE_OPEN_SUBJOURNAL] 1383** <li> [SQLITE_OPEN_MASTER_JOURNAL] 1384** <li> [SQLITE_OPEN_WAL] 1385** </ul>)^ 1386** 1387** The file I/O implementation can use the object type flags to 1388** change the way it deals with files. For example, an application 1389** that does not care about crash recovery or rollback might make 1390** the open of a journal file a no-op. Writes to this journal would 1391** also be no-ops, and any attempt to read the journal would return 1392** SQLITE_IOERR. Or the implementation might recognize that a database 1393** file will be doing page-aligned sector reads and writes in a random 1394** order and set up its I/O subsystem accordingly. 1395** 1396** SQLite might also add one of the following flags to the xOpen method: 1397** 1398** <ul> 1399** <li> [SQLITE_OPEN_DELETEONCLOSE] 1400** <li> [SQLITE_OPEN_EXCLUSIVE] 1401** </ul> 1402** 1403** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be 1404** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] 1405** will be set for TEMP databases and their journals, transient 1406** databases, and subjournals. 1407** 1408** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction 1409** with the [SQLITE_OPEN_CREATE] flag, which are both directly 1410** analogous to the O_EXCL and O_CREAT flags of the POSIX open() 1411** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 1412** SQLITE_OPEN_CREATE, is used to indicate that file should always 1413** be created, and that it is an error if it already exists. 1414** It is <i>not</i> used to indicate the file should be opened 1415** for exclusive access. 1416** 1417** ^At least szOsFile bytes of memory are allocated by SQLite 1418** to hold the [sqlite3_file] structure passed as the third 1419** argument to xOpen. The xOpen method does not have to 1420** allocate the structure; it should just fill it in. Note that 1421** the xOpen method must set the sqlite3_file.pMethods to either 1422** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 1423** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 1424** element will be valid after xOpen returns regardless of the success 1425** or failure of the xOpen call. 1426** 1427** [[sqlite3_vfs.xAccess]] 1428** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 1429** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 1430** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 1431** to test whether a file is at least readable. The file can be a 1432** directory. 1433** 1434** ^SQLite will always allocate at least mxPathname+1 bytes for the 1435** output buffer xFullPathname. The exact size of the output buffer 1436** is also passed as a parameter to both methods. If the output buffer 1437** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 1438** handled as a fatal error by SQLite, vfs implementations should endeavor 1439** to prevent this by setting mxPathname to a sufficiently large value. 1440** 1441** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() 1442** interfaces are not strictly a part of the filesystem, but they are 1443** included in the VFS structure for completeness. 1444** The xRandomness() function attempts to return nBytes bytes 1445** of good-quality randomness into zOut. The return value is 1446** the actual number of bytes of randomness obtained. 1447** The xSleep() method causes the calling thread to sleep for at 1448** least the number of microseconds given. ^The xCurrentTime() 1449** method returns a Julian Day Number for the current date and time as 1450** a floating point value. 1451** ^The xCurrentTimeInt64() method returns, as an integer, the Julian 1452** Day Number multiplied by 86400000 (the number of milliseconds in 1453** a 24-hour day). 1454** ^SQLite will use the xCurrentTimeInt64() method to get the current 1455** date and time if that method is available (if iVersion is 2 or 1456** greater and the function pointer is not NULL) and will fall back 1457** to xCurrentTime() if xCurrentTimeInt64() is unavailable. 1458** 1459** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces 1460** are not used by the SQLite core. These optional interfaces are provided 1461** by some VFSes to facilitate testing of the VFS code. By overriding 1462** system calls with functions under its control, a test program can 1463** simulate faults and error conditions that would otherwise be difficult 1464** or impossible to induce. The set of system calls that can be overridden 1465** varies from one VFS to another, and from one version of the same VFS to the 1466** next. Applications that use these interfaces must be prepared for any 1467** or all of these interfaces to be NULL or for their behavior to change 1468** from one release to the next. Applications must not attempt to access 1469** any of these methods if the iVersion of the VFS is less than 3. 1470*/ 1471typedef struct sqlite3_vfs sqlite3_vfs; 1472typedef void (*sqlite3_syscall_ptr)(void); 1473struct sqlite3_vfs { 1474 int iVersion; /* Structure version number (currently 3) */ 1475 int szOsFile; /* Size of subclassed sqlite3_file */ 1476 int mxPathname; /* Maximum file pathname length */ 1477 sqlite3_vfs *pNext; /* Next registered VFS */ 1478 const char *zName; /* Name of this virtual file system */ 1479 void *pAppData; /* Pointer to application-specific data */ 1480 int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, 1481 int flags, int *pOutFlags); 1482 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); 1483 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); 1484 int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); 1485 void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); 1486 void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); 1487 void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); 1488 void (*xDlClose)(sqlite3_vfs*, void*); 1489 int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); 1490 int (*xSleep)(sqlite3_vfs*, int microseconds); 1491 int (*xCurrentTime)(sqlite3_vfs*, double*); 1492 int (*xGetLastError)(sqlite3_vfs*, int, char *); 1493 /* 1494 ** The methods above are in version 1 of the sqlite_vfs object 1495 ** definition. Those that follow are added in version 2 or later 1496 */ 1497 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); 1498 /* 1499 ** The methods above are in versions 1 and 2 of the sqlite_vfs object. 1500 ** Those below are for version 3 and greater. 1501 */ 1502 int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); 1503 sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); 1504 const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); 1505 /* 1506 ** The methods above are in versions 1 through 3 of the sqlite_vfs object. 1507 ** New fields may be appended in figure versions. The iVersion 1508 ** value will increment whenever this happens. 1509 */ 1510}; 1511 1512/* 1513** CAPI3REF: Flags for the xAccess VFS method 1514** 1515** These integer constants can be used as the third parameter to 1516** the xAccess method of an [sqlite3_vfs] object. They determine 1517** what kind of permissions the xAccess method is looking for. 1518** With SQLITE_ACCESS_EXISTS, the xAccess method 1519** simply checks whether the file exists. 1520** With SQLITE_ACCESS_READWRITE, the xAccess method 1521** checks whether the named directory is both readable and writable 1522** (in other words, if files can be added, removed, and renamed within 1523** the directory). 1524** The SQLITE_ACCESS_READWRITE constant is currently used only by the 1525** [temp_store_directory pragma], though this could change in a future 1526** release of SQLite. 1527** With SQLITE_ACCESS_READ, the xAccess method 1528** checks whether the file is readable. The SQLITE_ACCESS_READ constant is 1529** currently unused, though it might be used in a future release of 1530** SQLite. 1531*/ 1532#define SQLITE_ACCESS_EXISTS 0 1533#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ 1534#define SQLITE_ACCESS_READ 2 /* Unused */ 1535 1536/* 1537** CAPI3REF: Flags for the xShmLock VFS method 1538** 1539** These integer constants define the various locking operations 1540** allowed by the xShmLock method of [sqlite3_io_methods]. The 1541** following are the only legal combinations of flags to the 1542** xShmLock method: 1543** 1544** <ul> 1545** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED 1546** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE 1547** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED 1548** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE 1549** </ul> 1550** 1551** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as 1552** was given no the corresponding lock. 1553** 1554** The xShmLock method can transition between unlocked and SHARED or 1555** between unlocked and EXCLUSIVE. It cannot transition between SHARED 1556** and EXCLUSIVE. 1557*/ 1558#define SQLITE_SHM_UNLOCK 1 1559#define SQLITE_SHM_LOCK 2 1560#define SQLITE_SHM_SHARED 4 1561#define SQLITE_SHM_EXCLUSIVE 8 1562 1563/* 1564** CAPI3REF: Maximum xShmLock index 1565** 1566** The xShmLock method on [sqlite3_io_methods] may use values 1567** between 0 and this upper bound as its "offset" argument. 1568** The SQLite core will never attempt to acquire or release a 1569** lock outside of this range 1570*/ 1571#define SQLITE_SHM_NLOCK 8 1572 1573 1574/* 1575** CAPI3REF: Initialize The SQLite Library 1576** 1577** ^The sqlite3_initialize() routine initializes the 1578** SQLite library. ^The sqlite3_shutdown() routine 1579** deallocates any resources that were allocated by sqlite3_initialize(). 1580** These routines are designed to aid in process initialization and 1581** shutdown on embedded systems. Workstation applications using 1582** SQLite normally do not need to invoke either of these routines. 1583** 1584** A call to sqlite3_initialize() is an "effective" call if it is 1585** the first time sqlite3_initialize() is invoked during the lifetime of 1586** the process, or if it is the first time sqlite3_initialize() is invoked 1587** following a call to sqlite3_shutdown(). ^(Only an effective call 1588** of sqlite3_initialize() does any initialization. All other calls 1589** are harmless no-ops.)^ 1590** 1591** A call to sqlite3_shutdown() is an "effective" call if it is the first 1592** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only 1593** an effective call to sqlite3_shutdown() does any deinitialization. 1594** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ 1595** 1596** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() 1597** is not. The sqlite3_shutdown() interface must only be called from a 1598** single thread. All open [database connections] must be closed and all 1599** other SQLite resources must be deallocated prior to invoking 1600** sqlite3_shutdown(). 1601** 1602** Among other things, ^sqlite3_initialize() will invoke 1603** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() 1604** will invoke sqlite3_os_end(). 1605** 1606** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. 1607** ^If for some reason, sqlite3_initialize() is unable to initialize 1608** the library (perhaps it is unable to allocate a needed resource such 1609** as a mutex) it returns an [error code] other than [SQLITE_OK]. 1610** 1611** ^The sqlite3_initialize() routine is called internally by many other 1612** SQLite interfaces so that an application usually does not need to 1613** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] 1614** calls sqlite3_initialize() so the SQLite library will be automatically 1615** initialized when [sqlite3_open()] is called if it has not be initialized 1616** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] 1617** compile-time option, then the automatic calls to sqlite3_initialize() 1618** are omitted and the application must call sqlite3_initialize() directly 1619** prior to using any other SQLite interface. For maximum portability, 1620** it is recommended that applications always invoke sqlite3_initialize() 1621** directly prior to using any other SQLite interface. Future releases 1622** of SQLite may require this. In other words, the behavior exhibited 1623** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the 1624** default behavior in some future release of SQLite. 1625** 1626** The sqlite3_os_init() routine does operating-system specific 1627** initialization of the SQLite library. The sqlite3_os_end() 1628** routine undoes the effect of sqlite3_os_init(). Typical tasks 1629** performed by these routines include allocation or deallocation 1630** of static resources, initialization of global variables, 1631** setting up a default [sqlite3_vfs] module, or setting up 1632** a default configuration using [sqlite3_config()]. 1633** 1634** The application should never invoke either sqlite3_os_init() 1635** or sqlite3_os_end() directly. The application should only invoke 1636** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() 1637** interface is called automatically by sqlite3_initialize() and 1638** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate 1639** implementations for sqlite3_os_init() and sqlite3_os_end() 1640** are built into SQLite when it is compiled for Unix, Windows, or OS/2. 1641** When [custom builds | built for other platforms] 1642** (using the [SQLITE_OS_OTHER=1] compile-time 1643** option) the application must supply a suitable implementation for 1644** sqlite3_os_init() and sqlite3_os_end(). An application-supplied 1645** implementation of sqlite3_os_init() or sqlite3_os_end() 1646** must return [SQLITE_OK] on success and some other [error code] upon 1647** failure. 1648*/ 1649SQLITE_API int sqlite3_initialize(void); 1650SQLITE_API int sqlite3_shutdown(void); 1651SQLITE_API int sqlite3_os_init(void); 1652SQLITE_API int sqlite3_os_end(void); 1653 1654/* 1655** CAPI3REF: Configuring The SQLite Library 1656** 1657** The sqlite3_config() interface is used to make global configuration 1658** changes to SQLite in order to tune SQLite to the specific needs of 1659** the application. The default configuration is recommended for most 1660** applications and so this routine is usually not necessary. It is 1661** provided to support rare applications with unusual needs. 1662** 1663** The sqlite3_config() interface is not threadsafe. The application 1664** must insure that no other SQLite interfaces are invoked by other 1665** threads while sqlite3_config() is running. Furthermore, sqlite3_config() 1666** may only be invoked prior to library initialization using 1667** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 1668** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 1669** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. 1670** Note, however, that ^sqlite3_config() can be called as part of the 1671** implementation of an application-defined [sqlite3_os_init()]. 1672** 1673** The first argument to sqlite3_config() is an integer 1674** [configuration option] that determines 1675** what property of SQLite is to be configured. Subsequent arguments 1676** vary depending on the [configuration option] 1677** in the first argument. 1678** 1679** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 1680** ^If the option is unknown or SQLite is unable to set the option 1681** then this routine returns a non-zero [error code]. 1682*/ 1683SQLITE_API int sqlite3_config(int, ...); 1684 1685/* 1686** CAPI3REF: Configure database connections 1687** 1688** The sqlite3_db_config() interface is used to make configuration 1689** changes to a [database connection]. The interface is similar to 1690** [sqlite3_config()] except that the changes apply to a single 1691** [database connection] (specified in the first argument). 1692** 1693** The second argument to sqlite3_db_config(D,V,...) is the 1694** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 1695** that indicates what aspect of the [database connection] is being configured. 1696** Subsequent arguments vary depending on the configuration verb. 1697** 1698** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if 1699** the call is considered successful. 1700*/ 1701SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); 1702 1703/* 1704** CAPI3REF: Memory Allocation Routines 1705** 1706** An instance of this object defines the interface between SQLite 1707** and low-level memory allocation routines. 1708** 1709** This object is used in only one place in the SQLite interface. 1710** A pointer to an instance of this object is the argument to 1711** [sqlite3_config()] when the configuration option is 1712** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. 1713** By creating an instance of this object 1714** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) 1715** during configuration, an application can specify an alternative 1716** memory allocation subsystem for SQLite to use for all of its 1717** dynamic memory needs. 1718** 1719** Note that SQLite comes with several [built-in memory allocators] 1720** that are perfectly adequate for the overwhelming majority of applications 1721** and that this object is only useful to a tiny minority of applications 1722** with specialized memory allocation requirements. This object is 1723** also used during testing of SQLite in order to specify an alternative 1724** memory allocator that simulates memory out-of-memory conditions in 1725** order to verify that SQLite recovers gracefully from such 1726** conditions. 1727** 1728** The xMalloc and xFree methods must work like the 1729** malloc() and free() functions from the standard C library. 1730** The xRealloc method must work like realloc() from the standard C library 1731** with the exception that if the second argument to xRealloc is zero, 1732** xRealloc must be a no-op - it must not perform any allocation or 1733** deallocation. ^SQLite guarantees that the second argument to 1734** xRealloc is always a value returned by a prior call to xRoundup. 1735** And so in cases where xRoundup always returns a positive number, 1736** xRealloc can perform exactly as the standard library realloc() and 1737** still be in compliance with this specification. 1738** 1739** xSize should return the allocated size of a memory allocation 1740** previously obtained from xMalloc or xRealloc. The allocated size 1741** is always at least as big as the requested size but may be larger. 1742** 1743** The xRoundup method returns what would be the allocated size of 1744** a memory allocation given a particular requested size. Most memory 1745** allocators round up memory allocations at least to the next multiple 1746** of 8. Some allocators round up to a larger multiple or to a power of 2. 1747** Every memory allocation request coming in through [sqlite3_malloc()] 1748** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 1749** that causes the corresponding memory allocation to fail. 1750** 1751** The xInit method initializes the memory allocator. (For example, 1752** it might allocate any require mutexes or initialize internal data 1753** structures. The xShutdown method is invoked (indirectly) by 1754** [sqlite3_shutdown()] and should deallocate any resources acquired 1755** by xInit. The pAppData pointer is used as the only parameter to 1756** xInit and xShutdown. 1757** 1758** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes 1759** the xInit method, so the xInit method need not be threadsafe. The 1760** xShutdown method is only called from [sqlite3_shutdown()] so it does 1761** not need to be threadsafe either. For all other methods, SQLite 1762** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the 1763** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which 1764** it is by default) and so the methods are automatically serialized. 1765** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other 1766** methods must be threadsafe or else make their own arrangements for 1767** serialization. 1768** 1769** SQLite will never invoke xInit() more than once without an intervening 1770** call to xShutdown(). 1771*/ 1772typedef struct sqlite3_mem_methods sqlite3_mem_methods; 1773struct sqlite3_mem_methods { 1774 void *(*xMalloc)(int); /* Memory allocation function */ 1775 void (*xFree)(void*); /* Free a prior allocation */ 1776 void *(*xRealloc)(void*,int); /* Resize an allocation */ 1777 int (*xSize)(void*); /* Return the size of an allocation */ 1778 int (*xRoundup)(int); /* Round up request size to allocation size */ 1779 int (*xInit)(void*); /* Initialize the memory allocator */ 1780 void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 1781 void *pAppData; /* Argument to xInit() and xShutdown() */ 1782}; 1783 1784/* 1785** CAPI3REF: Configuration Options 1786** KEYWORDS: {configuration option} 1787** 1788** These constants are the available integer configuration options that 1789** can be passed as the first argument to the [sqlite3_config()] interface. 1790** 1791** New configuration options may be added in future releases of SQLite. 1792** Existing configuration options might be discontinued. Applications 1793** should check the return code from [sqlite3_config()] to make sure that 1794** the call worked. The [sqlite3_config()] interface will return a 1795** non-zero [error code] if a discontinued or unsupported configuration option 1796** is invoked. 1797** 1798** <dl> 1799** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 1800** <dd>There are no arguments to this option. ^This option sets the 1801** [threading mode] to Single-thread. In other words, it disables 1802** all mutexing and puts SQLite into a mode where it can only be used 1803** by a single thread. ^If SQLite is compiled with 1804** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1805** it is not possible to change the [threading mode] from its default 1806** value of Single-thread and so [sqlite3_config()] will return 1807** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 1808** configuration option.</dd> 1809** 1810** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> 1811** <dd>There are no arguments to this option. ^This option sets the 1812** [threading mode] to Multi-thread. In other words, it disables 1813** mutexing on [database connection] and [prepared statement] objects. 1814** The application is responsible for serializing access to 1815** [database connections] and [prepared statements]. But other mutexes 1816** are enabled so that SQLite will be safe to use in a multi-threaded 1817** environment as long as no two threads attempt to use the same 1818** [database connection] at the same time. ^If SQLite is compiled with 1819** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1820** it is not possible to set the Multi-thread [threading mode] and 1821** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1822** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 1823** 1824** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> 1825** <dd>There are no arguments to this option. ^This option sets the 1826** [threading mode] to Serialized. In other words, this option enables 1827** all mutexes including the recursive 1828** mutexes on [database connection] and [prepared statement] objects. 1829** In this mode (which is the default when SQLite is compiled with 1830** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 1831** to [database connections] and [prepared statements] so that the 1832** application is free to use the same [database connection] or the 1833** same [prepared statement] in different threads at the same time. 1834** ^If SQLite is compiled with 1835** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1836** it is not possible to set the Serialized [threading mode] and 1837** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1838** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 1839** 1840** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> 1841** <dd> ^(This option takes a single argument which is a pointer to an 1842** instance of the [sqlite3_mem_methods] structure. The argument specifies 1843** alternative low-level memory allocation routines to be used in place of 1844** the memory allocation routines built into SQLite.)^ ^SQLite makes 1845** its own private copy of the content of the [sqlite3_mem_methods] structure 1846** before the [sqlite3_config()] call returns.</dd> 1847** 1848** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> 1849** <dd> ^(This option takes a single argument which is a pointer to an 1850** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] 1851** structure is filled with the currently defined memory allocation routines.)^ 1852** This option can be used to overload the default memory allocation 1853** routines with a wrapper that simulations memory allocation failure or 1854** tracks memory usage, for example. </dd> 1855** 1856** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> 1857** <dd> ^This option takes single argument of type int, interpreted as a 1858** boolean, which enables or disables the collection of memory allocation 1859** statistics. ^(When memory allocation statistics are disabled, the 1860** following SQLite interfaces become non-operational: 1861** <ul> 1862** <li> [sqlite3_memory_used()] 1863** <li> [sqlite3_memory_highwater()] 1864** <li> [sqlite3_soft_heap_limit64()] 1865** <li> [sqlite3_status()] 1866** </ul>)^ 1867** ^Memory allocation statistics are enabled by default unless SQLite is 1868** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 1869** allocation statistics are disabled by default. 1870** </dd> 1871** 1872** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> 1873** <dd> ^This option specifies a static memory buffer that SQLite can use for 1874** scratch memory. There are three arguments: A pointer an 8-byte 1875** aligned memory buffer from which the scratch allocations will be 1876** drawn, the size of each scratch allocation (sz), 1877** and the maximum number of scratch allocations (N). The sz 1878** argument must be a multiple of 16. 1879** The first argument must be a pointer to an 8-byte aligned buffer 1880** of at least sz*N bytes of memory. 1881** ^SQLite will use no more than two scratch buffers per thread. So 1882** N should be set to twice the expected maximum number of threads. 1883** ^SQLite will never require a scratch buffer that is more than 6 1884** times the database page size. ^If SQLite needs needs additional 1885** scratch memory beyond what is provided by this configuration option, then 1886** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 1887** 1888** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> 1889** <dd> ^This option specifies a static memory buffer that SQLite can use for 1890** the database page cache with the default page cache implementation. 1891** This configuration should not be used if an application-define page 1892** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. 1893** There are three arguments to this option: A pointer to 8-byte aligned 1894** memory, the size of each page buffer (sz), and the number of pages (N). 1895** The sz argument should be the size of the largest database page 1896** (a power of two between 512 and 32768) plus a little extra for each 1897** page header. ^The page header size is 20 to 40 bytes depending on 1898** the host architecture. ^It is harmless, apart from the wasted memory, 1899** to make sz a little too large. The first 1900** argument should point to an allocation of at least sz*N bytes of memory. 1901** ^SQLite will use the memory provided by the first argument to satisfy its 1902** memory needs for the first N pages that it adds to cache. ^If additional 1903** page cache memory is needed beyond what is provided by this option, then 1904** SQLite goes to [sqlite3_malloc()] for the additional storage space. 1905** The pointer in the first argument must 1906** be aligned to an 8-byte boundary or subsequent behavior of SQLite 1907** will be undefined.</dd> 1908** 1909** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> 1910** <dd> ^This option specifies a static memory buffer that SQLite will use 1911** for all of its dynamic memory allocation needs beyond those provided 1912** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. 1913** There are three arguments: An 8-byte aligned pointer to the memory, 1914** the number of bytes in the memory buffer, and the minimum allocation size. 1915** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 1916** to using its default memory allocator (the system malloc() implementation), 1917** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 1918** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or 1919** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory 1920** allocator is engaged to handle all of SQLites memory allocation needs. 1921** The first pointer (the memory pointer) must be aligned to an 8-byte 1922** boundary or subsequent behavior of SQLite will be undefined. 1923** The minimum allocation size is capped at 2^12. Reasonable values 1924** for the minimum allocation size are 2^5 through 2^8.</dd> 1925** 1926** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> 1927** <dd> ^(This option takes a single argument which is a pointer to an 1928** instance of the [sqlite3_mutex_methods] structure. The argument specifies 1929** alternative low-level mutex routines to be used in place 1930** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the 1931** content of the [sqlite3_mutex_methods] structure before the call to 1932** [sqlite3_config()] returns. ^If SQLite is compiled with 1933** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1934** the entire mutexing subsystem is omitted from the build and hence calls to 1935** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 1936** return [SQLITE_ERROR].</dd> 1937** 1938** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> 1939** <dd> ^(This option takes a single argument which is a pointer to an 1940** instance of the [sqlite3_mutex_methods] structure. The 1941** [sqlite3_mutex_methods] 1942** structure is filled with the currently defined mutex routines.)^ 1943** This option can be used to overload the default mutex allocation 1944** routines with a wrapper used to track mutex usage for performance 1945** profiling or testing, for example. ^If SQLite is compiled with 1946** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1947** the entire mutexing subsystem is omitted from the build and hence calls to 1948** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 1949** return [SQLITE_ERROR].</dd> 1950** 1951** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> 1952** <dd> ^(This option takes two arguments that determine the default 1953** memory allocation for the lookaside memory allocator on each 1954** [database connection]. The first argument is the 1955** size of each lookaside buffer slot and the second is the number of 1956** slots allocated to each database connection.)^ ^(This option sets the 1957** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 1958** verb to [sqlite3_db_config()] can be used to change the lookaside 1959** configuration on individual connections.)^ </dd> 1960** 1961** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt> 1962** <dd> ^(This option takes a single argument which is a pointer to 1963** an [sqlite3_pcache_methods] object. This object specifies the interface 1964** to a custom page cache implementation.)^ ^SQLite makes a copy of the 1965** object and uses it for page cache memory allocations.</dd> 1966** 1967** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt> 1968** <dd> ^(This option takes a single argument which is a pointer to an 1969** [sqlite3_pcache_methods] object. SQLite copies of the current 1970** page cache implementation into that object.)^ </dd> 1971** 1972** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> 1973** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 1974** function with a call signature of void(*)(void*,int,const char*), 1975** and a pointer to void. ^If the function pointer is not NULL, it is 1976** invoked by [sqlite3_log()] to process each logging event. ^If the 1977** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. 1978** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is 1979** passed through as the first parameter to the application-defined logger 1980** function whenever that function is invoked. ^The second parameter to 1981** the logger function is a copy of the first parameter to the corresponding 1982** [sqlite3_log()] call and is intended to be a [result code] or an 1983** [extended result code]. ^The third parameter passed to the logger is 1984** log message after formatting via [sqlite3_snprintf()]. 1985** The SQLite logging interface is not reentrant; the logger function 1986** supplied by the application must not invoke any SQLite interface. 1987** In a multi-threaded application, the application-defined logger 1988** function must be threadsafe. </dd> 1989** 1990** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI 1991** <dd> This option takes a single argument of type int. If non-zero, then 1992** URI handling is globally enabled. If the parameter is zero, then URI handling 1993** is globally disabled. If URI handling is globally enabled, all filenames 1994** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or 1995** specified as part of [ATTACH] commands are interpreted as URIs, regardless 1996** of whether or not the [SQLITE_OPEN_URI] flag is set when the database 1997** connection is opened. If it is globally disabled, filenames are 1998** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 1999** database connection is opened. By default, URI handling is globally 2000** disabled. The default value may be changed by compiling with the 2001** [SQLITE_USE_URI] symbol defined. 2002** </dl> 2003*/ 2004#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 2005#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 2006#define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 2007#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 2008#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 2009#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ 2010#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 2011#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 2012#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 2013#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 2014#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 2015/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 2016#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 2017#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ 2018#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ 2019#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 2020#define SQLITE_CONFIG_URI 17 /* int */ 2021 2022/* 2023** CAPI3REF: Database Connection Configuration Options 2024** 2025** These constants are the available integer configuration options that 2026** can be passed as the second argument to the [sqlite3_db_config()] interface. 2027** 2028** New configuration options may be added in future releases of SQLite. 2029** Existing configuration options might be discontinued. Applications 2030** should check the return code from [sqlite3_db_config()] to make sure that 2031** the call worked. ^The [sqlite3_db_config()] interface will return a 2032** non-zero [error code] if a discontinued or unsupported configuration option 2033** is invoked. 2034** 2035** <dl> 2036** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> 2037** <dd> ^This option takes three additional arguments that determine the 2038** [lookaside memory allocator] configuration for the [database connection]. 2039** ^The first argument (the third parameter to [sqlite3_db_config()] is a 2040** pointer to a memory buffer to use for lookaside memory. 2041** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb 2042** may be NULL in which case SQLite will allocate the 2043** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the 2044** size of each lookaside buffer slot. ^The third argument is the number of 2045** slots. The size of the buffer in the first argument must be greater than 2046** or equal to the product of the second and third arguments. The buffer 2047** must be aligned to an 8-byte boundary. ^If the second argument to 2048** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally 2049** rounded down to the next smaller multiple of 8. ^(The lookaside memory 2050** configuration for a database connection can only be changed when that 2051** connection is not currently using lookaside memory, or in other words 2052** when the "current value" returned by 2053** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. 2054** Any attempt to change the lookaside memory configuration when lookaside 2055** memory is in use leaves the configuration unchanged and returns 2056** [SQLITE_BUSY].)^</dd> 2057** 2058** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> 2059** <dd> ^This option is used to enable or disable the enforcement of 2060** [foreign key constraints]. There should be two additional arguments. 2061** The first argument is an integer which is 0 to disable FK enforcement, 2062** positive to enable FK enforcement or negative to leave FK enforcement 2063** unchanged. The second parameter is a pointer to an integer into which 2064** is written 0 or 1 to indicate whether FK enforcement is off or on 2065** following this call. The second parameter may be a NULL pointer, in 2066** which case the FK enforcement setting is not reported back. </dd> 2067** 2068** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> 2069** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. 2070** There should be two additional arguments. 2071** The first argument is an integer which is 0 to disable triggers, 2072** positive to enable triggers or negative to leave the setting unchanged. 2073** The second parameter is a pointer to an integer into which 2074** is written 0 or 1 to indicate whether triggers are disabled or enabled 2075** following this call. The second parameter may be a NULL pointer, in 2076** which case the trigger setting is not reported back. </dd> 2077** 2078** </dl> 2079*/ 2080#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ 2081#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ 2082#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ 2083 2084 2085/* 2086** CAPI3REF: Enable Or Disable Extended Result Codes 2087** 2088** ^The sqlite3_extended_result_codes() routine enables or disables the 2089** [extended result codes] feature of SQLite. ^The extended result 2090** codes are disabled by default for historical compatibility. 2091*/ 2092SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); 2093 2094/* 2095** CAPI3REF: Last Insert Rowid 2096** 2097** ^Each entry in an SQLite table has a unique 64-bit signed 2098** integer key called the [ROWID | "rowid"]. ^The rowid is always available 2099** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 2100** names are not also used by explicitly declared columns. ^If 2101** the table has a column of type [INTEGER PRIMARY KEY] then that column 2102** is another alias for the rowid. 2103** 2104** ^This routine returns the [rowid] of the most recent 2105** successful [INSERT] into the database from the [database connection] 2106** in the first argument. ^As of SQLite version 3.7.7, this routines 2107** records the last insert rowid of both ordinary tables and [virtual tables]. 2108** ^If no successful [INSERT]s 2109** have ever occurred on that database connection, zero is returned. 2110** 2111** ^(If an [INSERT] occurs within a trigger or within a [virtual table] 2112** method, then this routine will return the [rowid] of the inserted 2113** row as long as the trigger or virtual table method is running. 2114** But once the trigger or virtual table method ends, the value returned 2115** by this routine reverts to what it was before the trigger or virtual 2116** table method began.)^ 2117** 2118** ^An [INSERT] that fails due to a constraint violation is not a 2119** successful [INSERT] and does not change the value returned by this 2120** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 2121** and INSERT OR ABORT make no changes to the return value of this 2122** routine when their insertion fails. ^(When INSERT OR REPLACE 2123** encounters a constraint violation, it does not fail. The 2124** INSERT continues to completion after deleting rows that caused 2125** the constraint problem so INSERT OR REPLACE will always change 2126** the return value of this interface.)^ 2127** 2128** ^For the purposes of this routine, an [INSERT] is considered to 2129** be successful even if it is subsequently rolled back. 2130** 2131** This function is accessible to SQL statements via the 2132** [last_insert_rowid() SQL function]. 2133** 2134** If a separate thread performs a new [INSERT] on the same 2135** database connection while the [sqlite3_last_insert_rowid()] 2136** function is running and thus changes the last insert [rowid], 2137** then the value returned by [sqlite3_last_insert_rowid()] is 2138** unpredictable and might not equal either the old or the new 2139** last insert [rowid]. 2140*/ 2141SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 2142 2143/* 2144** CAPI3REF: Count The Number Of Rows Modified 2145** 2146** ^This function returns the number of database rows that were changed 2147** or inserted or deleted by the most recently completed SQL statement 2148** on the [database connection] specified by the first parameter. 2149** ^(Only changes that are directly specified by the [INSERT], [UPDATE], 2150** or [DELETE] statement are counted. Auxiliary changes caused by 2151** triggers or [foreign key actions] are not counted.)^ Use the 2152** [sqlite3_total_changes()] function to find the total number of changes 2153** including changes caused by triggers and foreign key actions. 2154** 2155** ^Changes to a view that are simulated by an [INSTEAD OF trigger] 2156** are not counted. Only real table changes are counted. 2157** 2158** ^(A "row change" is a change to a single row of a single table 2159** caused by an INSERT, DELETE, or UPDATE statement. Rows that 2160** are changed as side effects of [REPLACE] constraint resolution, 2161** rollback, ABORT processing, [DROP TABLE], or by any other 2162** mechanisms do not count as direct row changes.)^ 2163** 2164** A "trigger context" is a scope of execution that begins and 2165** ends with the script of a [CREATE TRIGGER | trigger]. 2166** Most SQL statements are 2167** evaluated outside of any trigger. This is the "top level" 2168** trigger context. If a trigger fires from the top level, a 2169** new trigger context is entered for the duration of that one 2170** trigger. Subtriggers create subcontexts for their duration. 2171** 2172** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does 2173** not create a new trigger context. 2174** 2175** ^This function returns the number of direct row changes in the 2176** most recent INSERT, UPDATE, or DELETE statement within the same 2177** trigger context. 2178** 2179** ^Thus, when called from the top level, this function returns the 2180** number of changes in the most recent INSERT, UPDATE, or DELETE 2181** that also occurred at the top level. ^(Within the body of a trigger, 2182** the sqlite3_changes() interface can be called to find the number of 2183** changes in the most recently completed INSERT, UPDATE, or DELETE 2184** statement within the body of the same trigger. 2185** However, the number returned does not include changes 2186** caused by subtriggers since those have their own context.)^ 2187** 2188** See also the [sqlite3_total_changes()] interface, the 2189** [count_changes pragma], and the [changes() SQL function]. 2190** 2191** If a separate thread makes changes on the same database connection 2192** while [sqlite3_changes()] is running then the value returned 2193** is unpredictable and not meaningful. 2194*/ 2195SQLITE_API int sqlite3_changes(sqlite3*); 2196 2197/* 2198** CAPI3REF: Total Number Of Rows Modified 2199** 2200** ^This function returns the number of row changes caused by [INSERT], 2201** [UPDATE] or [DELETE] statements since the [database connection] was opened. 2202** ^(The count returned by sqlite3_total_changes() includes all changes 2203** from all [CREATE TRIGGER | trigger] contexts and changes made by 2204** [foreign key actions]. However, 2205** the count does not include changes used to implement [REPLACE] constraints, 2206** do rollbacks or ABORT processing, or [DROP TABLE] processing. The 2207** count does not include rows of views that fire an [INSTEAD OF trigger], 2208** though if the INSTEAD OF trigger makes changes of its own, those changes 2209** are counted.)^ 2210** ^The sqlite3_total_changes() function counts the changes as soon as 2211** the statement that makes them is completed (when the statement handle 2212** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). 2213** 2214** See also the [sqlite3_changes()] interface, the 2215** [count_changes pragma], and the [total_changes() SQL function]. 2216** 2217** If a separate thread makes changes on the same database connection 2218** while [sqlite3_total_changes()] is running then the value 2219** returned is unpredictable and not meaningful. 2220*/ 2221SQLITE_API int sqlite3_total_changes(sqlite3*); 2222 2223/* 2224** CAPI3REF: Interrupt A Long-Running Query 2225** 2226** ^This function causes any pending database operation to abort and 2227** return at its earliest opportunity. This routine is typically 2228** called in response to a user action such as pressing "Cancel" 2229** or Ctrl-C where the user wants a long query operation to halt 2230** immediately. 2231** 2232** ^It is safe to call this routine from a thread different from the 2233** thread that is currently running the database operation. But it 2234** is not safe to call this routine with a [database connection] that 2235** is closed or might close before sqlite3_interrupt() returns. 2236** 2237** ^If an SQL operation is very nearly finished at the time when 2238** sqlite3_interrupt() is called, then it might not have an opportunity 2239** to be interrupted and might continue to completion. 2240** 2241** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. 2242** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE 2243** that is inside an explicit transaction, then the entire transaction 2244** will be rolled back automatically. 2245** 2246** ^The sqlite3_interrupt(D) call is in effect until all currently running 2247** SQL statements on [database connection] D complete. ^Any new SQL statements 2248** that are started after the sqlite3_interrupt() call and before the 2249** running statements reaches zero are interrupted as if they had been 2250** running prior to the sqlite3_interrupt() call. ^New SQL statements 2251** that are started after the running statement count reaches zero are 2252** not effected by the sqlite3_interrupt(). 2253** ^A call to sqlite3_interrupt(D) that occurs when there are no running 2254** SQL statements is a no-op and has no effect on SQL statements 2255** that are started after the sqlite3_interrupt() call returns. 2256** 2257** If the database connection closes while [sqlite3_interrupt()] 2258** is running then bad things will likely happen. 2259*/ 2260SQLITE_API void sqlite3_interrupt(sqlite3*); 2261 2262/* 2263** CAPI3REF: Determine If An SQL Statement Is Complete 2264** 2265** These routines are useful during command-line input to determine if the 2266** currently entered text seems to form a complete SQL statement or 2267** if additional input is needed before sending the text into 2268** SQLite for parsing. ^These routines return 1 if the input string 2269** appears to be a complete SQL statement. ^A statement is judged to be 2270** complete if it ends with a semicolon token and is not a prefix of a 2271** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within 2272** string literals or quoted identifier names or comments are not 2273** independent tokens (they are part of the token in which they are 2274** embedded) and thus do not count as a statement terminator. ^Whitespace 2275** and comments that follow the final semicolon are ignored. 2276** 2277** ^These routines return 0 if the statement is incomplete. ^If a 2278** memory allocation fails, then SQLITE_NOMEM is returned. 2279** 2280** ^These routines do not parse the SQL statements thus 2281** will not detect syntactically incorrect SQL. 2282** 2283** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 2284** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked 2285** automatically by sqlite3_complete16(). If that initialization fails, 2286** then the return value from sqlite3_complete16() will be non-zero 2287** regardless of whether or not the input SQL is complete.)^ 2288** 2289** The input to [sqlite3_complete()] must be a zero-terminated 2290** UTF-8 string. 2291** 2292** The input to [sqlite3_complete16()] must be a zero-terminated 2293** UTF-16 string in native byte order. 2294*/ 2295SQLITE_API int sqlite3_complete(const char *sql); 2296SQLITE_API int sqlite3_complete16(const void *sql); 2297 2298/* 2299** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 2300** 2301** ^This routine sets a callback function that might be invoked whenever 2302** an attempt is made to open a database table that another thread 2303** or process has locked. 2304** 2305** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] 2306** is returned immediately upon encountering the lock. ^If the busy callback 2307** is not NULL, then the callback might be invoked with two arguments. 2308** 2309** ^The first argument to the busy handler is a copy of the void* pointer which 2310** is the third argument to sqlite3_busy_handler(). ^The second argument to 2311** the busy handler callback is the number of times that the busy handler has 2312** been invoked for this locking event. ^If the 2313** busy callback returns 0, then no additional attempts are made to 2314** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. 2315** ^If the callback returns non-zero, then another attempt 2316** is made to open the database for reading and the cycle repeats. 2317** 2318** The presence of a busy handler does not guarantee that it will be invoked 2319** when there is lock contention. ^If SQLite determines that invoking the busy 2320** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 2321** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. 2322** Consider a scenario where one process is holding a read lock that 2323** it is trying to promote to a reserved lock and 2324** a second process is holding a reserved lock that it is trying 2325** to promote to an exclusive lock. The first process cannot proceed 2326** because it is blocked by the second and the second process cannot 2327** proceed because it is blocked by the first. If both processes 2328** invoke the busy handlers, neither will make any progress. Therefore, 2329** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 2330** will induce the first process to release its read lock and allow 2331** the second process to proceed. 2332** 2333** ^The default busy callback is NULL. 2334** 2335** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] 2336** when SQLite is in the middle of a large transaction where all the 2337** changes will not fit into the in-memory cache. SQLite will 2338** already hold a RESERVED lock on the database file, but it needs 2339** to promote this lock to EXCLUSIVE so that it can spill cache 2340** pages into the database file without harm to concurrent 2341** readers. ^If it is unable to promote the lock, then the in-memory 2342** cache will be left in an inconsistent state and so the error 2343** code is promoted from the relatively benign [SQLITE_BUSY] to 2344** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion 2345** forces an automatic rollback of the changes. See the 2346** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> 2347** CorruptionFollowingBusyError</a> wiki page for a discussion of why 2348** this is important. 2349** 2350** ^(There can only be a single busy handler defined for each 2351** [database connection]. Setting a new busy handler clears any 2352** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 2353** will also set or clear the busy handler. 2354** 2355** The busy callback should not take any actions which modify the 2356** database connection that invoked the busy handler. Any such actions 2357** result in undefined behavior. 2358** 2359** A busy handler must not close the database connection 2360** or [prepared statement] that invoked the busy handler. 2361*/ 2362SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); 2363 2364/* 2365** CAPI3REF: Set A Busy Timeout 2366** 2367** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 2368** for a specified amount of time when a table is locked. ^The handler 2369** will sleep multiple times until at least "ms" milliseconds of sleeping 2370** have accumulated. ^After at least "ms" milliseconds of sleeping, 2371** the handler returns 0 which causes [sqlite3_step()] to return 2372** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. 2373** 2374** ^Calling this routine with an argument less than or equal to zero 2375** turns off all busy handlers. 2376** 2377** ^(There can only be a single busy handler for a particular 2378** [database connection] any any given moment. If another busy handler 2379** was defined (using [sqlite3_busy_handler()]) prior to calling 2380** this routine, that other busy handler is cleared.)^ 2381*/ 2382SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); 2383 2384/* 2385** CAPI3REF: Convenience Routines For Running Queries 2386** 2387** This is a legacy interface that is preserved for backwards compatibility. 2388** Use of this interface is not recommended. 2389** 2390** Definition: A <b>result table</b> is memory data structure created by the 2391** [sqlite3_get_table()] interface. A result table records the 2392** complete query results from one or more queries. 2393** 2394** The table conceptually has a number of rows and columns. But 2395** these numbers are not part of the result table itself. These 2396** numbers are obtained separately. Let N be the number of rows 2397** and M be the number of columns. 2398** 2399** A result table is an array of pointers to zero-terminated UTF-8 strings. 2400** There are (N+1)*M elements in the array. The first M pointers point 2401** to zero-terminated strings that contain the names of the columns. 2402** The remaining entries all point to query results. NULL values result 2403** in NULL pointers. All other values are in their UTF-8 zero-terminated 2404** string representation as returned by [sqlite3_column_text()]. 2405** 2406** A result table might consist of one or more memory allocations. 2407** It is not safe to pass a result table directly to [sqlite3_free()]. 2408** A result table should be deallocated using [sqlite3_free_table()]. 2409** 2410** ^(As an example of the result table format, suppose a query result 2411** is as follows: 2412** 2413** <blockquote><pre> 2414** Name | Age 2415** ----------------------- 2416** Alice | 43 2417** Bob | 28 2418** Cindy | 21 2419** </pre></blockquote> 2420** 2421** There are two column (M==2) and three rows (N==3). Thus the 2422** result table has 8 entries. Suppose the result table is stored 2423** in an array names azResult. Then azResult holds this content: 2424** 2425** <blockquote><pre> 2426** azResult[0] = "Name"; 2427** azResult[1] = "Age"; 2428** azResult[2] = "Alice"; 2429** azResult[3] = "43"; 2430** azResult[4] = "Bob"; 2431** azResult[5] = "28"; 2432** azResult[6] = "Cindy"; 2433** azResult[7] = "21"; 2434** </pre></blockquote>)^ 2435** 2436** ^The sqlite3_get_table() function evaluates one or more 2437** semicolon-separated SQL statements in the zero-terminated UTF-8 2438** string of its 2nd parameter and returns a result table to the 2439** pointer given in its 3rd parameter. 2440** 2441** After the application has finished with the result from sqlite3_get_table(), 2442** it must pass the result table pointer to sqlite3_free_table() in order to 2443** release the memory that was malloced. Because of the way the 2444** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling 2445** function must not try to call [sqlite3_free()] directly. Only 2446** [sqlite3_free_table()] is able to release the memory properly and safely. 2447** 2448** The sqlite3_get_table() interface is implemented as a wrapper around 2449** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access 2450** to any internal data structures of SQLite. It uses only the public 2451** interface defined here. As a consequence, errors that occur in the 2452** wrapper layer outside of the internal [sqlite3_exec()] call are not 2453** reflected in subsequent calls to [sqlite3_errcode()] or 2454** [sqlite3_errmsg()]. 2455*/ 2456SQLITE_API int sqlite3_get_table( 2457 sqlite3 *db, /* An open database */ 2458 const char *zSql, /* SQL to be evaluated */ 2459 char ***pazResult, /* Results of the query */ 2460 int *pnRow, /* Number of result rows written here */ 2461 int *pnColumn, /* Number of result columns written here */ 2462 char **pzErrmsg /* Error msg written here */ 2463); 2464SQLITE_API void sqlite3_free_table(char **result); 2465 2466/* 2467** CAPI3REF: Formatted String Printing Functions 2468** 2469** These routines are work-alikes of the "printf()" family of functions 2470** from the standard C library. 2471** 2472** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their 2473** results into memory obtained from [sqlite3_malloc()]. 2474** The strings returned by these two routines should be 2475** released by [sqlite3_free()]. ^Both routines return a 2476** NULL pointer if [sqlite3_malloc()] is unable to allocate enough 2477** memory to hold the resulting string. 2478** 2479** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from 2480** the standard C library. The result is written into the 2481** buffer supplied as the second parameter whose size is given by 2482** the first parameter. Note that the order of the 2483** first two parameters is reversed from snprintf().)^ This is an 2484** historical accident that cannot be fixed without breaking 2485** backwards compatibility. ^(Note also that sqlite3_snprintf() 2486** returns a pointer to its buffer instead of the number of 2487** characters actually written into the buffer.)^ We admit that 2488** the number of characters written would be a more useful return 2489** value but we cannot change the implementation of sqlite3_snprintf() 2490** now without breaking compatibility. 2491** 2492** ^As long as the buffer size is greater than zero, sqlite3_snprintf() 2493** guarantees that the buffer is always zero-terminated. ^The first 2494** parameter "n" is the total size of the buffer, including space for 2495** the zero terminator. So the longest string that can be completely 2496** written will be n-1 characters. 2497** 2498** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 2499** 2500** These routines all implement some additional formatting 2501** options that are useful for constructing SQL statements. 2502** All of the usual printf() formatting options apply. In addition, there 2503** is are "%q", "%Q", and "%z" options. 2504** 2505** ^(The %q option works like %s in that it substitutes a null-terminated 2506** string from the argument list. But %q also doubles every '\'' character. 2507** %q is designed for use inside a string literal.)^ By doubling each '\'' 2508** character it escapes that character and allows it to be inserted into 2509** the string. 2510** 2511** For example, assume the string variable zText contains text as follows: 2512** 2513** <blockquote><pre> 2514** char *zText = "It's a happy day!"; 2515** </pre></blockquote> 2516** 2517** One can use this text in an SQL statement as follows: 2518** 2519** <blockquote><pre> 2520** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); 2521** sqlite3_exec(db, zSQL, 0, 0, 0); 2522** sqlite3_free(zSQL); 2523** </pre></blockquote> 2524** 2525** Because the %q format string is used, the '\'' character in zText 2526** is escaped and the SQL generated is as follows: 2527** 2528** <blockquote><pre> 2529** INSERT INTO table1 VALUES('It''s a happy day!') 2530** </pre></blockquote> 2531** 2532** This is correct. Had we used %s instead of %q, the generated SQL 2533** would have looked like this: 2534** 2535** <blockquote><pre> 2536** INSERT INTO table1 VALUES('It's a happy day!'); 2537** </pre></blockquote> 2538** 2539** This second example is an SQL syntax error. As a general rule you should 2540** always use %q instead of %s when inserting text into a string literal. 2541** 2542** ^(The %Q option works like %q except it also adds single quotes around 2543** the outside of the total string. Additionally, if the parameter in the 2544** argument list is a NULL pointer, %Q substitutes the text "NULL" (without 2545** single quotes).)^ So, for example, one could say: 2546** 2547** <blockquote><pre> 2548** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); 2549** sqlite3_exec(db, zSQL, 0, 0, 0); 2550** sqlite3_free(zSQL); 2551** </pre></blockquote> 2552** 2553** The code above will render a correct SQL statement in the zSQL 2554** variable even if the zText variable is a NULL pointer. 2555** 2556** ^(The "%z" formatting option works like "%s" but with the 2557** addition that after the string has been read and copied into 2558** the result, [sqlite3_free()] is called on the input string.)^ 2559*/ 2560SQLITE_API char *sqlite3_mprintf(const char*,...); 2561SQLITE_API char *sqlite3_vmprintf(const char*, va_list); 2562SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); 2563SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); 2564 2565/* 2566** CAPI3REF: Memory Allocation Subsystem 2567** 2568** The SQLite core uses these three routines for all of its own 2569** internal memory allocation needs. "Core" in the previous sentence 2570** does not include operating-system specific VFS implementation. The 2571** Windows VFS uses native malloc() and free() for some operations. 2572** 2573** ^The sqlite3_malloc() routine returns a pointer to a block 2574** of memory at least N bytes in length, where N is the parameter. 2575** ^If sqlite3_malloc() is unable to obtain sufficient free 2576** memory, it returns a NULL pointer. ^If the parameter N to 2577** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 2578** a NULL pointer. 2579** 2580** ^Calling sqlite3_free() with a pointer previously returned 2581** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 2582** that it might be reused. ^The sqlite3_free() routine is 2583** a no-op if is called with a NULL pointer. Passing a NULL pointer 2584** to sqlite3_free() is harmless. After being freed, memory 2585** should neither be read nor written. Even reading previously freed 2586** memory might result in a segmentation fault or other severe error. 2587** Memory corruption, a segmentation fault, or other severe error 2588** might result if sqlite3_free() is called with a non-NULL pointer that 2589** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 2590** 2591** ^(The sqlite3_realloc() interface attempts to resize a 2592** prior memory allocation to be at least N bytes, where N is the 2593** second parameter. The memory allocation to be resized is the first 2594** parameter.)^ ^ If the first parameter to sqlite3_realloc() 2595** is a NULL pointer then its behavior is identical to calling 2596** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). 2597** ^If the second parameter to sqlite3_realloc() is zero or 2598** negative then the behavior is exactly the same as calling 2599** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). 2600** ^sqlite3_realloc() returns a pointer to a memory allocation 2601** of at least N bytes in size or NULL if sufficient memory is unavailable. 2602** ^If M is the size of the prior allocation, then min(N,M) bytes 2603** of the prior allocation are copied into the beginning of buffer returned 2604** by sqlite3_realloc() and the prior allocation is freed. 2605** ^If sqlite3_realloc() returns NULL, then the prior allocation 2606** is not freed. 2607** 2608** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() 2609** is always aligned to at least an 8 byte boundary, or to a 2610** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time 2611** option is used. 2612** 2613** In SQLite version 3.5.0 and 3.5.1, it was possible to define 2614** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 2615** implementation of these routines to be omitted. That capability 2616** is no longer provided. Only built-in memory allocators can be used. 2617** 2618** The Windows OS interface layer calls 2619** the system malloc() and free() directly when converting 2620** filenames between the UTF-8 encoding used by SQLite 2621** and whatever filename encoding is used by the particular Windows 2622** installation. Memory allocation errors are detected, but 2623** they are reported back as [SQLITE_CANTOPEN] or 2624** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 2625** 2626** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 2627** must be either NULL or else pointers obtained from a prior 2628** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 2629** not yet been released. 2630** 2631** The application must not read or write any part of 2632** a block of memory after it has been released using 2633** [sqlite3_free()] or [sqlite3_realloc()]. 2634*/ 2635SQLITE_API void *sqlite3_malloc(int); 2636SQLITE_API void *sqlite3_realloc(void*, int); 2637SQLITE_API void sqlite3_free(void*); 2638 2639/* 2640** CAPI3REF: Memory Allocator Statistics 2641** 2642** SQLite provides these two interfaces for reporting on the status 2643** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 2644** routines, which form the built-in memory allocation subsystem. 2645** 2646** ^The [sqlite3_memory_used()] routine returns the number of bytes 2647** of memory currently outstanding (malloced but not freed). 2648** ^The [sqlite3_memory_highwater()] routine returns the maximum 2649** value of [sqlite3_memory_used()] since the high-water mark 2650** was last reset. ^The values returned by [sqlite3_memory_used()] and 2651** [sqlite3_memory_highwater()] include any overhead 2652** added by SQLite in its implementation of [sqlite3_malloc()], 2653** but not overhead added by the any underlying system library 2654** routines that [sqlite3_malloc()] may call. 2655** 2656** ^The memory high-water mark is reset to the current value of 2657** [sqlite3_memory_used()] if and only if the parameter to 2658** [sqlite3_memory_highwater()] is true. ^The value returned 2659** by [sqlite3_memory_highwater(1)] is the high-water mark 2660** prior to the reset. 2661*/ 2662SQLITE_API sqlite3_int64 sqlite3_memory_used(void); 2663SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); 2664 2665/* 2666** CAPI3REF: Pseudo-Random Number Generator 2667** 2668** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 2669** select random [ROWID | ROWIDs] when inserting new records into a table that 2670** already uses the largest possible [ROWID]. The PRNG is also used for 2671** the build-in random() and randomblob() SQL functions. This interface allows 2672** applications to access the same PRNG for other purposes. 2673** 2674** ^A call to this routine stores N bytes of randomness into buffer P. 2675** 2676** ^The first time this routine is invoked (either internally or by 2677** the application) the PRNG is seeded using randomness obtained 2678** from the xRandomness method of the default [sqlite3_vfs] object. 2679** ^On all subsequent invocations, the pseudo-randomness is generated 2680** internally and without recourse to the [sqlite3_vfs] xRandomness 2681** method. 2682*/ 2683SQLITE_API void sqlite3_randomness(int N, void *P); 2684 2685/* 2686** CAPI3REF: Compile-Time Authorization Callbacks 2687** 2688** ^This routine registers an authorizer callback with a particular 2689** [database connection], supplied in the first argument. 2690** ^The authorizer callback is invoked as SQL statements are being compiled 2691** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], 2692** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various 2693** points during the compilation process, as logic is being created 2694** to perform various actions, the authorizer callback is invoked to 2695** see if those actions are allowed. ^The authorizer callback should 2696** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the 2697** specific action but allow the SQL statement to continue to be 2698** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be 2699** rejected with an error. ^If the authorizer callback returns 2700** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] 2701** then the [sqlite3_prepare_v2()] or equivalent call that triggered 2702** the authorizer will fail with an error message. 2703** 2704** When the callback returns [SQLITE_OK], that means the operation 2705** requested is ok. ^When the callback returns [SQLITE_DENY], the 2706** [sqlite3_prepare_v2()] or equivalent call that triggered the 2707** authorizer will fail with an error message explaining that 2708** access is denied. 2709** 2710** ^The first parameter to the authorizer callback is a copy of the third 2711** parameter to the sqlite3_set_authorizer() interface. ^The second parameter 2712** to the callback is an integer [SQLITE_COPY | action code] that specifies 2713** the particular action to be authorized. ^The third through sixth parameters 2714** to the callback are zero-terminated strings that contain additional 2715** details about the action to be authorized. 2716** 2717** ^If the action code is [SQLITE_READ] 2718** and the callback returns [SQLITE_IGNORE] then the 2719** [prepared statement] statement is constructed to substitute 2720** a NULL value in place of the table column that would have 2721** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] 2722** return can be used to deny an untrusted user access to individual 2723** columns of a table. 2724** ^If the action code is [SQLITE_DELETE] and the callback returns 2725** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the 2726** [truncate optimization] is disabled and all rows are deleted individually. 2727** 2728** An authorizer is used when [sqlite3_prepare | preparing] 2729** SQL statements from an untrusted source, to ensure that the SQL statements 2730** do not try to access data they are not allowed to see, or that they do not 2731** try to execute malicious statements that damage the database. For 2732** example, an application may allow a user to enter arbitrary 2733** SQL queries for evaluation by a database. But the application does 2734** not want the user to be able to make arbitrary changes to the 2735** database. An authorizer could then be put in place while the 2736** user-entered SQL is being [sqlite3_prepare | prepared] that 2737** disallows everything except [SELECT] statements. 2738** 2739** Applications that need to process SQL from untrusted sources 2740** might also consider lowering resource limits using [sqlite3_limit()] 2741** and limiting database size using the [max_page_count] [PRAGMA] 2742** in addition to using an authorizer. 2743** 2744** ^(Only a single authorizer can be in place on a database connection 2745** at a time. Each call to sqlite3_set_authorizer overrides the 2746** previous call.)^ ^Disable the authorizer by installing a NULL callback. 2747** The authorizer is disabled by default. 2748** 2749** The authorizer callback must not do anything that will modify 2750** the database connection that invoked the authorizer callback. 2751** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 2752** database connections for the meaning of "modify" in this paragraph. 2753** 2754** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the 2755** statement might be re-prepared during [sqlite3_step()] due to a 2756** schema change. Hence, the application should ensure that the 2757** correct authorizer callback remains in place during the [sqlite3_step()]. 2758** 2759** ^Note that the authorizer callback is invoked only during 2760** [sqlite3_prepare()] or its variants. Authorization is not 2761** performed during statement evaluation in [sqlite3_step()], unless 2762** as stated in the previous paragraph, sqlite3_step() invokes 2763** sqlite3_prepare_v2() to reprepare a statement after a schema change. 2764*/ 2765SQLITE_API int sqlite3_set_authorizer( 2766 sqlite3*, 2767 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 2768 void *pUserData 2769); 2770 2771/* 2772** CAPI3REF: Authorizer Return Codes 2773** 2774** The [sqlite3_set_authorizer | authorizer callback function] must 2775** return either [SQLITE_OK] or one of these two constants in order 2776** to signal SQLite whether or not the action is permitted. See the 2777** [sqlite3_set_authorizer | authorizer documentation] for additional 2778** information. 2779** 2780** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] 2781** from the [sqlite3_vtab_on_conflict()] interface. 2782*/ 2783#define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 2784#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 2785 2786/* 2787** CAPI3REF: Authorizer Action Codes 2788** 2789** The [sqlite3_set_authorizer()] interface registers a callback function 2790** that is invoked to authorize certain SQL statement actions. The 2791** second parameter to the callback is an integer code that specifies 2792** what action is being authorized. These are the integer action codes that 2793** the authorizer callback may be passed. 2794** 2795** These action code values signify what kind of operation is to be 2796** authorized. The 3rd and 4th parameters to the authorization 2797** callback function will be parameters or NULL depending on which of these 2798** codes is used as the second parameter. ^(The 5th parameter to the 2799** authorizer callback is the name of the database ("main", "temp", 2800** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback 2801** is the name of the inner-most trigger or view that is responsible for 2802** the access attempt or NULL if this access attempt is directly from 2803** top-level SQL code. 2804*/ 2805/******************************************* 3rd ************ 4th ***********/ 2806#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 2807#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 2808#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 2809#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 2810#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 2811#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 2812#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 2813#define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 2814#define SQLITE_DELETE 9 /* Table Name NULL */ 2815#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 2816#define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 2817#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 2818#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 2819#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 2820#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 2821#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 2822#define SQLITE_DROP_VIEW 17 /* View Name NULL */ 2823#define SQLITE_INSERT 18 /* Table Name NULL */ 2824#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 2825#define SQLITE_READ 20 /* Table Name Column Name */ 2826#define SQLITE_SELECT 21 /* NULL NULL */ 2827#define SQLITE_TRANSACTION 22 /* Operation NULL */ 2828#define SQLITE_UPDATE 23 /* Table Name Column Name */ 2829#define SQLITE_ATTACH 24 /* Filename NULL */ 2830#define SQLITE_DETACH 25 /* Database Name NULL */ 2831#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 2832#define SQLITE_REINDEX 27 /* Index Name NULL */ 2833#define SQLITE_ANALYZE 28 /* Table Name NULL */ 2834#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 2835#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 2836#define SQLITE_FUNCTION 31 /* NULL Function Name */ 2837#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 2838#define SQLITE_COPY 0 /* No longer used */ 2839 2840/* 2841** CAPI3REF: Tracing And Profiling Functions 2842** 2843** These routines register callback functions that can be used for 2844** tracing and profiling the execution of SQL statements. 2845** 2846** ^The callback function registered by sqlite3_trace() is invoked at 2847** various times when an SQL statement is being run by [sqlite3_step()]. 2848** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 2849** SQL statement text as the statement first begins executing. 2850** ^(Additional sqlite3_trace() callbacks might occur 2851** as each triggered subprogram is entered. The callbacks for triggers 2852** contain a UTF-8 SQL comment that identifies the trigger.)^ 2853** 2854** ^The callback function registered by sqlite3_profile() is invoked 2855** as each SQL statement finishes. ^The profile callback contains 2856** the original statement text and an estimate of wall-clock time 2857** of how long that statement took to run. ^The profile callback 2858** time is in units of nanoseconds, however the current implementation 2859** is only capable of millisecond resolution so the six least significant 2860** digits in the time are meaningless. Future versions of SQLite 2861** might provide greater resolution on the profiler callback. The 2862** sqlite3_profile() function is considered experimental and is 2863** subject to change in future versions of SQLite. 2864*/ 2865SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); 2866SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, 2867 void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 2868 2869/* 2870** CAPI3REF: Query Progress Callbacks 2871** 2872** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback 2873** function X to be invoked periodically during long running calls to 2874** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for 2875** database connection D. An example use for this 2876** interface is to keep a GUI updated during a large query. 2877** 2878** ^The parameter P is passed through as the only parameter to the 2879** callback function X. ^The parameter N is the number of 2880** [virtual machine instructions] that are evaluated between successive 2881** invocations of the callback X. 2882** 2883** ^Only a single progress handler may be defined at one time per 2884** [database connection]; setting a new progress handler cancels the 2885** old one. ^Setting parameter X to NULL disables the progress handler. 2886** ^The progress handler is also disabled by setting N to a value less 2887** than 1. 2888** 2889** ^If the progress callback returns non-zero, the operation is 2890** interrupted. This feature can be used to implement a 2891** "Cancel" button on a GUI progress dialog box. 2892** 2893** The progress handler callback must not do anything that will modify 2894** the database connection that invoked the progress handler. 2895** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 2896** database connections for the meaning of "modify" in this paragraph. 2897** 2898*/ 2899SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 2900 2901/* 2902** CAPI3REF: Opening A New Database Connection 2903** 2904** ^These routines open an SQLite database file as specified by the 2905** filename argument. ^The filename argument is interpreted as UTF-8 for 2906** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 2907** order for sqlite3_open16(). ^(A [database connection] handle is usually 2908** returned in *ppDb, even if an error occurs. The only exception is that 2909** if SQLite is unable to allocate memory to hold the [sqlite3] object, 2910** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 2911** object.)^ ^(If the database is opened (and/or created) successfully, then 2912** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 2913** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 2914** an English language description of the error following a failure of any 2915** of the sqlite3_open() routines. 2916** 2917** ^The default encoding for the database will be UTF-8 if 2918** sqlite3_open() or sqlite3_open_v2() is called and 2919** UTF-16 in the native byte order if sqlite3_open16() is used. 2920** 2921** Whether or not an error occurs when it is opened, resources 2922** associated with the [database connection] handle should be released by 2923** passing it to [sqlite3_close()] when it is no longer required. 2924** 2925** The sqlite3_open_v2() interface works like sqlite3_open() 2926** except that it accepts two additional parameters for additional control 2927** over the new database connection. ^(The flags parameter to 2928** sqlite3_open_v2() can take one of 2929** the following three values, optionally combined with the 2930** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], 2931** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ 2932** 2933** <dl> 2934** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 2935** <dd>The database is opened in read-only mode. If the database does not 2936** already exist, an error is returned.</dd>)^ 2937** 2938** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 2939** <dd>The database is opened for reading and writing if possible, or reading 2940** only if the file is write protected by the operating system. In either 2941** case the database must already exist, otherwise an error is returned.</dd>)^ 2942** 2943** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 2944** <dd>The database is opened for reading and writing, and is created if 2945** it does not already exist. This is the behavior that is always used for 2946** sqlite3_open() and sqlite3_open16().</dd>)^ 2947** </dl> 2948** 2949** If the 3rd parameter to sqlite3_open_v2() is not one of the 2950** combinations shown above optionally combined with other 2951** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] 2952** then the behavior is undefined. 2953** 2954** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection 2955** opens in the multi-thread [threading mode] as long as the single-thread 2956** mode has not been set at compile-time or start-time. ^If the 2957** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens 2958** in the serialized [threading mode] unless single-thread was 2959** previously selected at compile-time or start-time. 2960** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be 2961** eligible to use [shared cache mode], regardless of whether or not shared 2962** cache is enabled using [sqlite3_enable_shared_cache()]. ^The 2963** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not 2964** participate in [shared cache mode] even if it is enabled. 2965** 2966** ^The fourth parameter to sqlite3_open_v2() is the name of the 2967** [sqlite3_vfs] object that defines the operating system interface that 2968** the new database connection should use. ^If the fourth parameter is 2969** a NULL pointer then the default [sqlite3_vfs] object is used. 2970** 2971** ^If the filename is ":memory:", then a private, temporary in-memory database 2972** is created for the connection. ^This in-memory database will vanish when 2973** the database connection is closed. Future versions of SQLite might 2974** make use of additional special filenames that begin with the ":" character. 2975** It is recommended that when a database filename actually does begin with 2976** a ":" character you should prefix the filename with a pathname such as 2977** "./" to avoid ambiguity. 2978** 2979** ^If the filename is an empty string, then a private, temporary 2980** on-disk database will be created. ^This private database will be 2981** automatically deleted as soon as the database connection is closed. 2982** 2983** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> 2984** 2985** ^If [URI filename] interpretation is enabled, and the filename argument 2986** begins with "file:", then the filename is interpreted as a URI. ^URI 2987** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is 2988** set in the fourth argument to sqlite3_open_v2(), or if it has 2989** been enabled globally using the [SQLITE_CONFIG_URI] option with the 2990** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. 2991** As of SQLite version 3.7.7, URI filename interpretation is turned off 2992** by default, but future releases of SQLite might enable URI filename 2993** interpretation by default. See "[URI filenames]" for additional 2994** information. 2995** 2996** URI filenames are parsed according to RFC 3986. ^If the URI contains an 2997** authority, then it must be either an empty string or the string 2998** "localhost". ^If the authority is not an empty string or "localhost", an 2999** error is returned to the caller. ^The fragment component of a URI, if 3000** present, is ignored. 3001** 3002** ^SQLite uses the path component of the URI as the name of the disk file 3003** which contains the database. ^If the path begins with a '/' character, 3004** then it is interpreted as an absolute path. ^If the path does not begin 3005** with a '/' (meaning that the authority section is omitted from the URI) 3006** then the path is interpreted as a relative path. 3007** ^On windows, the first component of an absolute path 3008** is a drive specification (e.g. "C:"). 3009** 3010** [[core URI query parameters]] 3011** The query component of a URI may contain parameters that are interpreted 3012** either by SQLite itself, or by a [VFS | custom VFS implementation]. 3013** SQLite interprets the following three query parameters: 3014** 3015** <ul> 3016** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of 3017** a VFS object that provides the operating system interface that should 3018** be used to access the database file on disk. ^If this option is set to 3019** an empty string the default VFS object is used. ^Specifying an unknown 3020** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 3021** present, then the VFS specified by the option takes precedence over 3022** the value passed as the fourth parameter to sqlite3_open_v2(). 3023** 3024** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or 3025** "rwc". Attempting to set it to any other value is an error)^. 3026** ^If "ro" is specified, then the database is opened for read-only 3027** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 3028** third argument to sqlite3_prepare_v2(). ^If the mode option is set to 3029** "rw", then the database is opened for read-write (but not create) 3030** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 3031** been set. ^Value "rwc" is equivalent to setting both 3032** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is 3033** used, it is an error to specify a value for the mode parameter that is 3034** less restrictive than that specified by the flags passed as the third 3035** parameter. 3036** 3037** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 3038** "private". ^Setting it to "shared" is equivalent to setting the 3039** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 3040** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 3041** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 3042** ^If sqlite3_open_v2() is used and the "cache" parameter is present in 3043** a URI filename, its value overrides any behaviour requested by setting 3044** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. 3045** </ul> 3046** 3047** ^Specifying an unknown parameter in the query component of a URI is not an 3048** error. Future versions of SQLite might understand additional query 3049** parameters. See "[query parameters with special meaning to SQLite]" for 3050** additional information. 3051** 3052** [[URI filename examples]] <h3>URI filename examples</h3> 3053** 3054** <table border="1" align=center cellpadding=5> 3055** <tr><th> URI filenames <th> Results 3056** <tr><td> file:data.db <td> 3057** Open the file "data.db" in the current directory. 3058** <tr><td> file:/home/fred/data.db<br> 3059** file:///home/fred/data.db <br> 3060** file://localhost/home/fred/data.db <br> <td> 3061** Open the database file "/home/fred/data.db". 3062** <tr><td> file://darkstar/home/fred/data.db <td> 3063** An error. "darkstar" is not a recognized authority. 3064** <tr><td style="white-space:nowrap"> 3065** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db 3066** <td> Windows only: Open the file "data.db" on fred's desktop on drive 3067** C:. Note that the %20 escaping in this example is not strictly 3068** necessary - space characters can be used literally 3069** in URI filenames. 3070** <tr><td> file:data.db?mode=ro&cache=private <td> 3071** Open file "data.db" in the current directory for read-only access. 3072** Regardless of whether or not shared-cache mode is enabled by 3073** default, use a private cache. 3074** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> 3075** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". 3076** <tr><td> file:data.db?mode=readonly <td> 3077** An error. "readonly" is not a valid option for the "mode" parameter. 3078** </table> 3079** 3080** ^URI hexadecimal escape sequences (%HH) are supported within the path and 3081** query components of a URI. A hexadecimal escape sequence consists of a 3082** percent sign - "%" - followed by exactly two hexadecimal digits 3083** specifying an octet value. ^Before the path or query components of a 3084** URI filename are interpreted, they are encoded using UTF-8 and all 3085** hexadecimal escape sequences replaced by a single byte containing the 3086** corresponding octet. If this process generates an invalid UTF-8 encoding, 3087** the results are undefined. 3088** 3089** <b>Note to Windows users:</b> The encoding used for the filename argument 3090** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 3091** codepage is currently defined. Filenames containing international 3092** characters must be converted to UTF-8 prior to passing them into 3093** sqlite3_open() or sqlite3_open_v2(). 3094*/ 3095SQLITE_API int sqlite3_open( 3096 const char *filename, /* Database filename (UTF-8) */ 3097 sqlite3 **ppDb /* OUT: SQLite db handle */ 3098); 3099SQLITE_API int sqlite3_open16( 3100 const void *filename, /* Database filename (UTF-16) */ 3101 sqlite3 **ppDb /* OUT: SQLite db handle */ 3102); 3103SQLITE_API int sqlite3_open_v2( 3104 const char *filename, /* Database filename (UTF-8) */ 3105 sqlite3 **ppDb, /* OUT: SQLite db handle */ 3106 int flags, /* Flags */ 3107 const char *zVfs /* Name of VFS module to use */ 3108); 3109 3110/* 3111** CAPI3REF: Obtain Values For URI Parameters 3112** 3113** This is a utility routine, useful to VFS implementations, that checks 3114** to see if a database file was a URI that contained a specific query 3115** parameter, and if so obtains the value of the query parameter. 3116** 3117** The zFilename argument is the filename pointer passed into the xOpen() 3118** method of a VFS implementation. The zParam argument is the name of the 3119** query parameter we seek. This routine returns the value of the zParam 3120** parameter if it exists. If the parameter does not exist, this routine 3121** returns a NULL pointer. 3122** 3123** If the zFilename argument to this function is not a pointer that SQLite 3124** passed into the xOpen VFS method, then the behavior of this routine 3125** is undefined and probably undesirable. 3126*/ 3127SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); 3128 3129 3130/* 3131** CAPI3REF: Error Codes And Messages 3132** 3133** ^The sqlite3_errcode() interface returns the numeric [result code] or 3134** [extended result code] for the most recent failed sqlite3_* API call 3135** associated with a [database connection]. If a prior API call failed 3136** but the most recent API call succeeded, the return value from 3137** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() 3138** interface is the same except that it always returns the 3139** [extended result code] even when extended result codes are 3140** disabled. 3141** 3142** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 3143** text that describes the error, as either UTF-8 or UTF-16 respectively. 3144** ^(Memory to hold the error message string is managed internally. 3145** The application does not need to worry about freeing the result. 3146** However, the error string might be overwritten or deallocated by 3147** subsequent calls to other SQLite interface functions.)^ 3148** 3149** When the serialized [threading mode] is in use, it might be the 3150** case that a second error occurs on a separate thread in between 3151** the time of the first error and the call to these interfaces. 3152** When that happens, the second error will be reported since these 3153** interfaces always report the most recent result. To avoid 3154** this, each thread can obtain exclusive use of the [database connection] D 3155** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 3156** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 3157** all calls to the interfaces listed here are completed. 3158** 3159** If an interface fails with SQLITE_MISUSE, that means the interface 3160** was invoked incorrectly by the application. In that case, the 3161** error code and message may or may not be set. 3162*/ 3163SQLITE_API int sqlite3_errcode(sqlite3 *db); 3164SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); 3165SQLITE_API const char *sqlite3_errmsg(sqlite3*); 3166SQLITE_API const void *sqlite3_errmsg16(sqlite3*); 3167 3168/* 3169** CAPI3REF: SQL Statement Object 3170** KEYWORDS: {prepared statement} {prepared statements} 3171** 3172** An instance of this object represents a single SQL statement. 3173** This object is variously known as a "prepared statement" or a 3174** "compiled SQL statement" or simply as a "statement". 3175** 3176** The life of a statement object goes something like this: 3177** 3178** <ol> 3179** <li> Create the object using [sqlite3_prepare_v2()] or a related 3180** function. 3181** <li> Bind values to [host parameters] using the sqlite3_bind_*() 3182** interfaces. 3183** <li> Run the SQL by calling [sqlite3_step()] one or more times. 3184** <li> Reset the statement using [sqlite3_reset()] then go back 3185** to step 2. Do this zero or more times. 3186** <li> Destroy the object using [sqlite3_finalize()]. 3187** </ol> 3188** 3189** Refer to documentation on individual methods above for additional 3190** information. 3191*/ 3192typedef struct sqlite3_stmt sqlite3_stmt; 3193 3194/* 3195** CAPI3REF: Run-time Limits 3196** 3197** ^(This interface allows the size of various constructs to be limited 3198** on a connection by connection basis. The first parameter is the 3199** [database connection] whose limit is to be set or queried. The 3200** second parameter is one of the [limit categories] that define a 3201** class of constructs to be size limited. The third parameter is the 3202** new limit for that construct.)^ 3203** 3204** ^If the new limit is a negative number, the limit is unchanged. 3205** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a 3206** [limits | hard upper bound] 3207** set at compile-time by a C preprocessor macro called 3208** [limits | SQLITE_MAX_<i>NAME</i>]. 3209** (The "_LIMIT_" in the name is changed to "_MAX_".))^ 3210** ^Attempts to increase a limit above its hard upper bound are 3211** silently truncated to the hard upper bound. 3212** 3213** ^Regardless of whether or not the limit was changed, the 3214** [sqlite3_limit()] interface returns the prior value of the limit. 3215** ^Hence, to find the current value of a limit without changing it, 3216** simply invoke this interface with the third parameter set to -1. 3217** 3218** Run-time limits are intended for use in applications that manage 3219** both their own internal database and also databases that are controlled 3220** by untrusted external sources. An example application might be a 3221** web browser that has its own databases for storing history and 3222** separate databases controlled by JavaScript applications downloaded 3223** off the Internet. The internal databases can be given the 3224** large, default limits. Databases managed by external sources can 3225** be given much smaller limits designed to prevent a denial of service 3226** attack. Developers might also want to use the [sqlite3_set_authorizer()] 3227** interface to further control untrusted SQL. The size of the database 3228** created by an untrusted script can be contained using the 3229** [max_page_count] [PRAGMA]. 3230** 3231** New run-time limit categories may be added in future releases. 3232*/ 3233SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); 3234 3235/* 3236** CAPI3REF: Run-Time Limit Categories 3237** KEYWORDS: {limit category} {*limit categories} 3238** 3239** These constants define various performance limits 3240** that can be lowered at run-time using [sqlite3_limit()]. 3241** The synopsis of the meanings of the various limits is shown below. 3242** Additional information is available at [limits | Limits in SQLite]. 3243** 3244** <dl> 3245** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> 3246** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ 3247** 3248** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 3249** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 3250** 3251** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> 3252** <dd>The maximum number of columns in a table definition or in the 3253** result set of a [SELECT] or the maximum number of columns in an index 3254** or in an ORDER BY or GROUP BY clause.</dd>)^ 3255** 3256** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 3257** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 3258** 3259** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 3260** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 3261** 3262** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 3263** <dd>The maximum number of instructions in a virtual machine program 3264** used to implement an SQL statement. This limit is not currently 3265** enforced, though that might be added in some future release of 3266** SQLite.</dd>)^ 3267** 3268** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 3269** <dd>The maximum number of arguments on a function.</dd>)^ 3270** 3271** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 3272** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 3273** 3274** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] 3275** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 3276** <dd>The maximum length of the pattern argument to the [LIKE] or 3277** [GLOB] operators.</dd>)^ 3278** 3279** [[SQLITE_LIMIT_VARIABLE_NUMBER]] 3280** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 3281** <dd>The maximum index number of any [parameter] in an SQL statement.)^ 3282** 3283** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 3284** <dd>The maximum depth of recursion for triggers.</dd>)^ 3285** </dl> 3286*/ 3287#define SQLITE_LIMIT_LENGTH 0 3288#define SQLITE_LIMIT_SQL_LENGTH 1 3289#define SQLITE_LIMIT_COLUMN 2 3290#define SQLITE_LIMIT_EXPR_DEPTH 3 3291#define SQLITE_LIMIT_COMPOUND_SELECT 4 3292#define SQLITE_LIMIT_VDBE_OP 5 3293#define SQLITE_LIMIT_FUNCTION_ARG 6 3294#define SQLITE_LIMIT_ATTACHED 7 3295#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 3296#define SQLITE_LIMIT_VARIABLE_NUMBER 9 3297#define SQLITE_LIMIT_TRIGGER_DEPTH 10 3298 3299/* 3300** CAPI3REF: Compiling An SQL Statement 3301** KEYWORDS: {SQL statement compiler} 3302** 3303** To execute an SQL query, it must first be compiled into a byte-code 3304** program using one of these routines. 3305** 3306** The first argument, "db", is a [database connection] obtained from a 3307** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 3308** [sqlite3_open16()]. The database connection must not have been closed. 3309** 3310** The second argument, "zSql", is the statement to be compiled, encoded 3311** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() 3312** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() 3313** use UTF-16. 3314** 3315** ^If the nByte argument is less than zero, then zSql is read up to the 3316** first zero terminator. ^If nByte is non-negative, then it is the maximum 3317** number of bytes read from zSql. ^When nByte is non-negative, the 3318** zSql string ends at either the first '\000' or '\u0000' character or 3319** the nByte-th byte, whichever comes first. If the caller knows 3320** that the supplied string is nul-terminated, then there is a small 3321** performance advantage to be gained by passing an nByte parameter that 3322** is equal to the number of bytes in the input string <i>including</i> 3323** the nul-terminator bytes. 3324** 3325** ^If pzTail is not NULL then *pzTail is made to point to the first byte 3326** past the end of the first SQL statement in zSql. These routines only 3327** compile the first statement in zSql, so *pzTail is left pointing to 3328** what remains uncompiled. 3329** 3330** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 3331** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 3332** to NULL. ^If the input text contains no SQL (if the input is an empty 3333** string or a comment) then *ppStmt is set to NULL. 3334** The calling procedure is responsible for deleting the compiled 3335** SQL statement using [sqlite3_finalize()] after it has finished with it. 3336** ppStmt may not be NULL. 3337** 3338** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 3339** otherwise an [error code] is returned. 3340** 3341** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 3342** recommended for all new programs. The two older interfaces are retained 3343** for backwards compatibility, but their use is discouraged. 3344** ^In the "v2" interfaces, the prepared statement 3345** that is returned (the [sqlite3_stmt] object) contains a copy of the 3346** original SQL text. This causes the [sqlite3_step()] interface to 3347** behave differently in three ways: 3348** 3349** <ol> 3350** <li> 3351** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 3352** always used to do, [sqlite3_step()] will automatically recompile the SQL 3353** statement and try to run it again. 3354** </li> 3355** 3356** <li> 3357** ^When an error occurs, [sqlite3_step()] will return one of the detailed 3358** [error codes] or [extended error codes]. ^The legacy behavior was that 3359** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 3360** and the application would have to make a second call to [sqlite3_reset()] 3361** in order to find the underlying cause of the problem. With the "v2" prepare 3362** interfaces, the underlying reason for the error is returned immediately. 3363** </li> 3364** 3365** <li> 3366** ^If the specific value bound to [parameter | host parameter] in the 3367** WHERE clause might influence the choice of query plan for a statement, 3368** then the statement will be automatically recompiled, as if there had been 3369** a schema change, on the first [sqlite3_step()] call following any change 3370** to the [sqlite3_bind_text | bindings] of that [parameter]. 3371** ^The specific value of WHERE-clause [parameter] might influence the 3372** choice of query plan if the parameter is the left-hand side of a [LIKE] 3373** or [GLOB] operator or if the parameter is compared to an indexed column 3374** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled. 3375** the 3376** </li> 3377** </ol> 3378*/ 3379SQLITE_API int sqlite3_prepare( 3380 sqlite3 *db, /* Database handle */ 3381 const char *zSql, /* SQL statement, UTF-8 encoded */ 3382 int nByte, /* Maximum length of zSql in bytes. */ 3383 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3384 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 3385); 3386SQLITE_API int sqlite3_prepare_v2( 3387 sqlite3 *db, /* Database handle */ 3388 const char *zSql, /* SQL statement, UTF-8 encoded */ 3389 int nByte, /* Maximum length of zSql in bytes. */ 3390 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3391 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 3392); 3393SQLITE_API int sqlite3_prepare16( 3394 sqlite3 *db, /* Database handle */ 3395 const void *zSql, /* SQL statement, UTF-16 encoded */ 3396 int nByte, /* Maximum length of zSql in bytes. */ 3397 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3398 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 3399); 3400SQLITE_API int sqlite3_prepare16_v2( 3401 sqlite3 *db, /* Database handle */ 3402 const void *zSql, /* SQL statement, UTF-16 encoded */ 3403 int nByte, /* Maximum length of zSql in bytes. */ 3404 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3405 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 3406); 3407 3408/* 3409** CAPI3REF: Retrieving Statement SQL 3410** 3411** ^This interface can be used to retrieve a saved copy of the original 3412** SQL text used to create a [prepared statement] if that statement was 3413** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. 3414*/ 3415SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); 3416 3417/* 3418** CAPI3REF: Determine If An SQL Statement Writes The Database 3419** 3420** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 3421** and only if the [prepared statement] X makes no direct changes to 3422** the content of the database file. 3423** 3424** Note that [application-defined SQL functions] or 3425** [virtual tables] might change the database indirectly as a side effect. 3426** ^(For example, if an application defines a function "eval()" that 3427** calls [sqlite3_exec()], then the following SQL statement would 3428** change the database file through side-effects: 3429** 3430** <blockquote><pre> 3431** SELECT eval('DELETE FROM t1') FROM t2; 3432** </pre></blockquote> 3433** 3434** But because the [SELECT] statement does not change the database file 3435** directly, sqlite3_stmt_readonly() would still return true.)^ 3436** 3437** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], 3438** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, 3439** since the statements themselves do not actually modify the database but 3440** rather they control the timing of when other statements modify the 3441** database. ^The [ATTACH] and [DETACH] statements also cause 3442** sqlite3_stmt_readonly() to return true since, while those statements 3443** change the configuration of a database connection, they do not make 3444** changes to the content of the database files on disk. 3445*/ 3446SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 3447 3448/* 3449** CAPI3REF: Dynamically Typed Value Object 3450** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 3451** 3452** SQLite uses the sqlite3_value object to represent all values 3453** that can be stored in a database table. SQLite uses dynamic typing 3454** for the values it stores. ^Values stored in sqlite3_value objects 3455** can be integers, floating point values, strings, BLOBs, or NULL. 3456** 3457** An sqlite3_value object may be either "protected" or "unprotected". 3458** Some interfaces require a protected sqlite3_value. Other interfaces 3459** will accept either a protected or an unprotected sqlite3_value. 3460** Every interface that accepts sqlite3_value arguments specifies 3461** whether or not it requires a protected sqlite3_value. 3462** 3463** The terms "protected" and "unprotected" refer to whether or not 3464** a mutex is held. An internal mutex is held for a protected 3465** sqlite3_value object but no mutex is held for an unprotected 3466** sqlite3_value object. If SQLite is compiled to be single-threaded 3467** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) 3468** or if SQLite is run in one of reduced mutex modes 3469** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] 3470** then there is no distinction between protected and unprotected 3471** sqlite3_value objects and they can be used interchangeably. However, 3472** for maximum code portability it is recommended that applications 3473** still make the distinction between protected and unprotected 3474** sqlite3_value objects even when not strictly required. 3475** 3476** ^The sqlite3_value objects that are passed as parameters into the 3477** implementation of [application-defined SQL functions] are protected. 3478** ^The sqlite3_value object returned by 3479** [sqlite3_column_value()] is unprotected. 3480** Unprotected sqlite3_value objects may only be used with 3481** [sqlite3_result_value()] and [sqlite3_bind_value()]. 3482** The [sqlite3_value_blob | sqlite3_value_type()] family of 3483** interfaces require protected sqlite3_value objects. 3484*/ 3485typedef struct Mem sqlite3_value; 3486 3487/* 3488** CAPI3REF: SQL Function Context Object 3489** 3490** The context in which an SQL function executes is stored in an 3491** sqlite3_context object. ^A pointer to an sqlite3_context object 3492** is always first parameter to [application-defined SQL functions]. 3493** The application-defined SQL function implementation will pass this 3494** pointer through into calls to [sqlite3_result_int | sqlite3_result()], 3495** [sqlite3_aggregate_context()], [sqlite3_user_data()], 3496** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], 3497** and/or [sqlite3_set_auxdata()]. 3498*/ 3499typedef struct sqlite3_context sqlite3_context; 3500 3501/* 3502** CAPI3REF: Binding Values To Prepared Statements 3503** KEYWORDS: {host parameter} {host parameters} {host parameter name} 3504** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} 3505** 3506** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, 3507** literals may be replaced by a [parameter] that matches one of following 3508** templates: 3509** 3510** <ul> 3511** <li> ? 3512** <li> ?NNN 3513** <li> :VVV 3514** <li> @VVV 3515** <li> $VVV 3516** </ul> 3517** 3518** In the templates above, NNN represents an integer literal, 3519** and VVV represents an alphanumeric identifier.)^ ^The values of these 3520** parameters (also called "host parameter names" or "SQL parameters") 3521** can be set using the sqlite3_bind_*() routines defined here. 3522** 3523** ^The first argument to the sqlite3_bind_*() routines is always 3524** a pointer to the [sqlite3_stmt] object returned from 3525** [sqlite3_prepare_v2()] or its variants. 3526** 3527** ^The second argument is the index of the SQL parameter to be set. 3528** ^The leftmost SQL parameter has an index of 1. ^When the same named 3529** SQL parameter is used more than once, second and subsequent 3530** occurrences have the same index as the first occurrence. 3531** ^The index for named parameters can be looked up using the 3532** [sqlite3_bind_parameter_index()] API if desired. ^The index 3533** for "?NNN" parameters is the value of NNN. 3534** ^The NNN value must be between 1 and the [sqlite3_limit()] 3535** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). 3536** 3537** ^The third argument is the value to bind to the parameter. 3538** 3539** ^(In those routines that have a fourth argument, its value is the 3540** number of bytes in the parameter. To be clear: the value is the 3541** number of <u>bytes</u> in the value, not the number of characters.)^ 3542** ^If the fourth parameter is negative, the length of the string is 3543** the number of bytes up to the first zero terminator. 3544** 3545** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and 3546** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or 3547** string after SQLite has finished with it. ^The destructor is called 3548** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(), 3549** sqlite3_bind_text(), or sqlite3_bind_text16() fails. 3550** ^If the fifth argument is 3551** the special value [SQLITE_STATIC], then SQLite assumes that the 3552** information is in static, unmanaged space and does not need to be freed. 3553** ^If the fifth argument has the value [SQLITE_TRANSIENT], then 3554** SQLite makes its own private copy of the data immediately, before 3555** the sqlite3_bind_*() routine returns. 3556** 3557** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 3558** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 3559** (just an integer to hold its size) while it is being processed. 3560** Zeroblobs are intended to serve as placeholders for BLOBs whose 3561** content is later written using 3562** [sqlite3_blob_open | incremental BLOB I/O] routines. 3563** ^A negative value for the zeroblob results in a zero-length BLOB. 3564** 3565** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 3566** for the [prepared statement] or with a prepared statement for which 3567** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 3568** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 3569** routine is passed a [prepared statement] that has been finalized, the 3570** result is undefined and probably harmful. 3571** 3572** ^Bindings are not cleared by the [sqlite3_reset()] routine. 3573** ^Unbound parameters are interpreted as NULL. 3574** 3575** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 3576** [error code] if anything goes wrong. 3577** ^[SQLITE_RANGE] is returned if the parameter 3578** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 3579** 3580** See also: [sqlite3_bind_parameter_count()], 3581** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 3582*/ 3583SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 3584SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); 3585SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); 3586SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 3587SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); 3588SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); 3589SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); 3590SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 3591SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 3592 3593/* 3594** CAPI3REF: Number Of SQL Parameters 3595** 3596** ^This routine can be used to find the number of [SQL parameters] 3597** in a [prepared statement]. SQL parameters are tokens of the 3598** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 3599** placeholders for values that are [sqlite3_bind_blob | bound] 3600** to the parameters at a later time. 3601** 3602** ^(This routine actually returns the index of the largest (rightmost) 3603** parameter. For all forms except ?NNN, this will correspond to the 3604** number of unique parameters. If parameters of the ?NNN form are used, 3605** there may be gaps in the list.)^ 3606** 3607** See also: [sqlite3_bind_blob|sqlite3_bind()], 3608** [sqlite3_bind_parameter_name()], and 3609** [sqlite3_bind_parameter_index()]. 3610*/ 3611SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); 3612 3613/* 3614** CAPI3REF: Name Of A Host Parameter 3615** 3616** ^The sqlite3_bind_parameter_name(P,N) interface returns 3617** the name of the N-th [SQL parameter] in the [prepared statement] P. 3618** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" 3619** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" 3620** respectively. 3621** In other words, the initial ":" or "$" or "@" or "?" 3622** is included as part of the name.)^ 3623** ^Parameters of the form "?" without a following integer have no name 3624** and are referred to as "nameless" or "anonymous parameters". 3625** 3626** ^The first host parameter has an index of 1, not 0. 3627** 3628** ^If the value N is out of range or if the N-th parameter is 3629** nameless, then NULL is returned. ^The returned string is 3630** always in UTF-8 encoding even if the named parameter was 3631** originally specified as UTF-16 in [sqlite3_prepare16()] or 3632** [sqlite3_prepare16_v2()]. 3633** 3634** See also: [sqlite3_bind_blob|sqlite3_bind()], 3635** [sqlite3_bind_parameter_count()], and 3636** [sqlite3_bind_parameter_index()]. 3637*/ 3638SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); 3639 3640/* 3641** CAPI3REF: Index Of A Parameter With A Given Name 3642** 3643** ^Return the index of an SQL parameter given its name. ^The 3644** index value returned is suitable for use as the second 3645** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero 3646** is returned if no matching parameter is found. ^The parameter 3647** name must be given in UTF-8 even if the original statement 3648** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. 3649** 3650** See also: [sqlite3_bind_blob|sqlite3_bind()], 3651** [sqlite3_bind_parameter_count()], and 3652** [sqlite3_bind_parameter_index()]. 3653*/ 3654SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); 3655 3656/* 3657** CAPI3REF: Reset All Bindings On A Prepared Statement 3658** 3659** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset 3660** the [sqlite3_bind_blob | bindings] on a [prepared statement]. 3661** ^Use this routine to reset all host parameters to NULL. 3662*/ 3663SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); 3664 3665/* 3666** CAPI3REF: Number Of Columns In A Result Set 3667** 3668** ^Return the number of columns in the result set returned by the 3669** [prepared statement]. ^This routine returns 0 if pStmt is an SQL 3670** statement that does not return data (for example an [UPDATE]). 3671** 3672** See also: [sqlite3_data_count()] 3673*/ 3674SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); 3675 3676/* 3677** CAPI3REF: Column Names In A Result Set 3678** 3679** ^These routines return the name assigned to a particular column 3680** in the result set of a [SELECT] statement. ^The sqlite3_column_name() 3681** interface returns a pointer to a zero-terminated UTF-8 string 3682** and sqlite3_column_name16() returns a pointer to a zero-terminated 3683** UTF-16 string. ^The first parameter is the [prepared statement] 3684** that implements the [SELECT] statement. ^The second parameter is the 3685** column number. ^The leftmost column is number 0. 3686** 3687** ^The returned string pointer is valid until either the [prepared statement] 3688** is destroyed by [sqlite3_finalize()] or until the statement is automatically 3689** reprepared by the first call to [sqlite3_step()] for a particular run 3690** or until the next call to 3691** sqlite3_column_name() or sqlite3_column_name16() on the same column. 3692** 3693** ^If sqlite3_malloc() fails during the processing of either routine 3694** (for example during a conversion from UTF-8 to UTF-16) then a 3695** NULL pointer is returned. 3696** 3697** ^The name of a result column is the value of the "AS" clause for 3698** that column, if there is an AS clause. If there is no AS clause 3699** then the name of the column is unspecified and may change from 3700** one release of SQLite to the next. 3701*/ 3702SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); 3703SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); 3704 3705/* 3706** CAPI3REF: Source Of Data In A Query Result 3707** 3708** ^These routines provide a means to determine the database, table, and 3709** table column that is the origin of a particular result column in 3710** [SELECT] statement. 3711** ^The name of the database or table or column can be returned as 3712** either a UTF-8 or UTF-16 string. ^The _database_ routines return 3713** the database name, the _table_ routines return the table name, and 3714** the origin_ routines return the column name. 3715** ^The returned string is valid until the [prepared statement] is destroyed 3716** using [sqlite3_finalize()] or until the statement is automatically 3717** reprepared by the first call to [sqlite3_step()] for a particular run 3718** or until the same information is requested 3719** again in a different encoding. 3720** 3721** ^The names returned are the original un-aliased names of the 3722** database, table, and column. 3723** 3724** ^The first argument to these interfaces is a [prepared statement]. 3725** ^These functions return information about the Nth result column returned by 3726** the statement, where N is the second function argument. 3727** ^The left-most column is column 0 for these routines. 3728** 3729** ^If the Nth column returned by the statement is an expression or 3730** subquery and is not a column value, then all of these functions return 3731** NULL. ^These routine might also return NULL if a memory allocation error 3732** occurs. ^Otherwise, they return the name of the attached database, table, 3733** or column that query result column was extracted from. 3734** 3735** ^As with all other SQLite APIs, those whose names end with "16" return 3736** UTF-16 encoded strings and the other functions return UTF-8. 3737** 3738** ^These APIs are only available if the library was compiled with the 3739** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. 3740** 3741** If two or more threads call one or more of these routines against the same 3742** prepared statement and column at the same time then the results are 3743** undefined. 3744** 3745** If two or more threads call one or more 3746** [sqlite3_column_database_name | column metadata interfaces] 3747** for the same [prepared statement] and result column 3748** at the same time then the results are undefined. 3749*/ 3750SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); 3751SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); 3752SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); 3753SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); 3754SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); 3755SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); 3756 3757/* 3758** CAPI3REF: Declared Datatype Of A Query Result 3759** 3760** ^(The first parameter is a [prepared statement]. 3761** If this statement is a [SELECT] statement and the Nth column of the 3762** returned result set of that [SELECT] is a table column (not an 3763** expression or subquery) then the declared type of the table 3764** column is returned.)^ ^If the Nth column of the result set is an 3765** expression or subquery, then a NULL pointer is returned. 3766** ^The returned string is always UTF-8 encoded. 3767** 3768** ^(For example, given the database schema: 3769** 3770** CREATE TABLE t1(c1 VARIANT); 3771** 3772** and the following statement to be compiled: 3773** 3774** SELECT c1 + 1, c1 FROM t1; 3775** 3776** this routine would return the string "VARIANT" for the second result 3777** column (i==1), and a NULL pointer for the first result column (i==0).)^ 3778** 3779** ^SQLite uses dynamic run-time typing. ^So just because a column 3780** is declared to contain a particular type does not mean that the 3781** data stored in that column is of the declared type. SQLite is 3782** strongly typed, but the typing is dynamic not static. ^Type 3783** is associated with individual values, not with the containers 3784** used to hold those values. 3785*/ 3786SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); 3787SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); 3788 3789/* 3790** CAPI3REF: Evaluate An SQL Statement 3791** 3792** After a [prepared statement] has been prepared using either 3793** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy 3794** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function 3795** must be called one or more times to evaluate the statement. 3796** 3797** The details of the behavior of the sqlite3_step() interface depend 3798** on whether the statement was prepared using the newer "v2" interface 3799** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy 3800** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the 3801** new "v2" interface is recommended for new applications but the legacy 3802** interface will continue to be supported. 3803** 3804** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 3805** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 3806** ^With the "v2" interface, any of the other [result codes] or 3807** [extended result codes] might be returned as well. 3808** 3809** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 3810** database locks it needs to do its job. ^If the statement is a [COMMIT] 3811** or occurs outside of an explicit transaction, then you can retry the 3812** statement. If the statement is not a [COMMIT] and occurs within an 3813** explicit transaction then you should rollback the transaction before 3814** continuing. 3815** 3816** ^[SQLITE_DONE] means that the statement has finished executing 3817** successfully. sqlite3_step() should not be called again on this virtual 3818** machine without first calling [sqlite3_reset()] to reset the virtual 3819** machine back to its initial state. 3820** 3821** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 3822** is returned each time a new row of data is ready for processing by the 3823** caller. The values may be accessed using the [column access functions]. 3824** sqlite3_step() is called again to retrieve the next row of data. 3825** 3826** ^[SQLITE_ERROR] means that a run-time error (such as a constraint 3827** violation) has occurred. sqlite3_step() should not be called again on 3828** the VM. More information may be found by calling [sqlite3_errmsg()]. 3829** ^With the legacy interface, a more specific error code (for example, 3830** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) 3831** can be obtained by calling [sqlite3_reset()] on the 3832** [prepared statement]. ^In the "v2" interface, 3833** the more specific error code is returned directly by sqlite3_step(). 3834** 3835** [SQLITE_MISUSE] means that the this routine was called inappropriately. 3836** Perhaps it was called on a [prepared statement] that has 3837** already been [sqlite3_finalize | finalized] or on one that had 3838** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could 3839** be the case that the same database connection is being used by two or 3840** more threads at the same moment in time. 3841** 3842** For all versions of SQLite up to and including 3.6.23.1, a call to 3843** [sqlite3_reset()] was required after sqlite3_step() returned anything 3844** other than [SQLITE_ROW] before any subsequent invocation of 3845** sqlite3_step(). Failure to reset the prepared statement using 3846** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from 3847** sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began 3848** calling [sqlite3_reset()] automatically in this circumstance rather 3849** than returning [SQLITE_MISUSE]. This is not considered a compatibility 3850** break because any application that ever receives an SQLITE_MISUSE error 3851** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option 3852** can be used to restore the legacy behavior. 3853** 3854** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() 3855** API always returns a generic error code, [SQLITE_ERROR], following any 3856** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call 3857** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the 3858** specific [error codes] that better describes the error. 3859** We admit that this is a goofy design. The problem has been fixed 3860** with the "v2" interface. If you prepare all of your SQL statements 3861** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead 3862** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, 3863** then the more specific [error codes] are returned directly 3864** by sqlite3_step(). The use of the "v2" interface is recommended. 3865*/ 3866SQLITE_API int sqlite3_step(sqlite3_stmt*); 3867 3868/* 3869** CAPI3REF: Number of columns in a result set 3870** 3871** ^The sqlite3_data_count(P) interface returns the number of columns in the 3872** current row of the result set of [prepared statement] P. 3873** ^If prepared statement P does not have results ready to return 3874** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of 3875** interfaces) then sqlite3_data_count(P) returns 0. 3876** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. 3877** 3878** See also: [sqlite3_column_count()] 3879*/ 3880SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); 3881 3882/* 3883** CAPI3REF: Fundamental Datatypes 3884** KEYWORDS: SQLITE_TEXT 3885** 3886** ^(Every value in SQLite has one of five fundamental datatypes: 3887** 3888** <ul> 3889** <li> 64-bit signed integer 3890** <li> 64-bit IEEE floating point number 3891** <li> string 3892** <li> BLOB 3893** <li> NULL 3894** </ul>)^ 3895** 3896** These constants are codes for each of those types. 3897** 3898** Note that the SQLITE_TEXT constant was also used in SQLite version 2 3899** for a completely different meaning. Software that links against both 3900** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not 3901** SQLITE_TEXT. 3902*/ 3903#define SQLITE_INTEGER 1 3904#define SQLITE_FLOAT 2 3905#define SQLITE_BLOB 4 3906#define SQLITE_NULL 5 3907#ifdef SQLITE_TEXT 3908# undef SQLITE_TEXT 3909#else 3910# define SQLITE_TEXT 3 3911#endif 3912#define SQLITE3_TEXT 3 3913 3914/* 3915** CAPI3REF: Result Values From A Query 3916** KEYWORDS: {column access functions} 3917** 3918** These routines form the "result set" interface. 3919** 3920** ^These routines return information about a single column of the current 3921** result row of a query. ^In every case the first argument is a pointer 3922** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] 3923** that was returned from [sqlite3_prepare_v2()] or one of its variants) 3924** and the second argument is the index of the column for which information 3925** should be returned. ^The leftmost column of the result set has the index 0. 3926** ^The number of columns in the result can be determined using 3927** [sqlite3_column_count()]. 3928** 3929** If the SQL statement does not currently point to a valid row, or if the 3930** column index is out of range, the result is undefined. 3931** These routines may only be called when the most recent call to 3932** [sqlite3_step()] has returned [SQLITE_ROW] and neither 3933** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. 3934** If any of these routines are called after [sqlite3_reset()] or 3935** [sqlite3_finalize()] or after [sqlite3_step()] has returned 3936** something other than [SQLITE_ROW], the results are undefined. 3937** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] 3938** are called from a different thread while any of these routines 3939** are pending, then the results are undefined. 3940** 3941** ^The sqlite3_column_type() routine returns the 3942** [SQLITE_INTEGER | datatype code] for the initial data type 3943** of the result column. ^The returned value is one of [SQLITE_INTEGER], 3944** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value 3945** returned by sqlite3_column_type() is only meaningful if no type 3946** conversions have occurred as described below. After a type conversion, 3947** the value returned by sqlite3_column_type() is undefined. Future 3948** versions of SQLite may change the behavior of sqlite3_column_type() 3949** following a type conversion. 3950** 3951** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 3952** routine returns the number of bytes in that BLOB or string. 3953** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts 3954** the string to UTF-8 and then returns the number of bytes. 3955** ^If the result is a numeric value then sqlite3_column_bytes() uses 3956** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns 3957** the number of bytes in that string. 3958** ^If the result is NULL, then sqlite3_column_bytes() returns zero. 3959** 3960** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() 3961** routine returns the number of bytes in that BLOB or string. 3962** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts 3963** the string to UTF-16 and then returns the number of bytes. 3964** ^If the result is a numeric value then sqlite3_column_bytes16() uses 3965** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns 3966** the number of bytes in that string. 3967** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. 3968** 3969** ^The values returned by [sqlite3_column_bytes()] and 3970** [sqlite3_column_bytes16()] do not include the zero terminators at the end 3971** of the string. ^For clarity: the values returned by 3972** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 3973** bytes in the string, not the number of characters. 3974** 3975** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 3976** even empty strings, are always zero terminated. ^The return 3977** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 3978** 3979** ^The object returned by [sqlite3_column_value()] is an 3980** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 3981** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 3982** If the [unprotected sqlite3_value] object returned by 3983** [sqlite3_column_value()] is used in any other way, including calls 3984** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 3985** or [sqlite3_value_bytes()], then the behavior is undefined. 3986** 3987** These routines attempt to convert the value where appropriate. ^For 3988** example, if the internal representation is FLOAT and a text result 3989** is requested, [sqlite3_snprintf()] is used internally to perform the 3990** conversion automatically. ^(The following table details the conversions 3991** that are applied: 3992** 3993** <blockquote> 3994** <table border="1"> 3995** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 3996** 3997** <tr><td> NULL <td> INTEGER <td> Result is 0 3998** <tr><td> NULL <td> FLOAT <td> Result is 0.0 3999** <tr><td> NULL <td> TEXT <td> Result is NULL pointer 4000** <tr><td> NULL <td> BLOB <td> Result is NULL pointer 4001** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 4002** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 4003** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 4004** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer 4005** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 4006** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT 4007** <tr><td> TEXT <td> INTEGER <td> Use atoi() 4008** <tr><td> TEXT <td> FLOAT <td> Use atof() 4009** <tr><td> TEXT <td> BLOB <td> No change 4010** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() 4011** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() 4012** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed 4013** </table> 4014** </blockquote>)^ 4015** 4016** The table above makes reference to standard C library functions atoi() 4017** and atof(). SQLite does not really use these functions. It has its 4018** own equivalent internal routines. The atoi() and atof() names are 4019** used in the table for brevity and because they are familiar to most 4020** C programmers. 4021** 4022** Note that when type conversions occur, pointers returned by prior 4023** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or 4024** sqlite3_column_text16() may be invalidated. 4025** Type conversions and pointer invalidations might occur 4026** in the following cases: 4027** 4028** <ul> 4029** <li> The initial content is a BLOB and sqlite3_column_text() or 4030** sqlite3_column_text16() is called. A zero-terminator might 4031** need to be added to the string.</li> 4032** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or 4033** sqlite3_column_text16() is called. The content must be converted 4034** to UTF-16.</li> 4035** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or 4036** sqlite3_column_text() is called. The content must be converted 4037** to UTF-8.</li> 4038** </ul> 4039** 4040** ^Conversions between UTF-16be and UTF-16le are always done in place and do 4041** not invalidate a prior pointer, though of course the content of the buffer 4042** that the prior pointer references will have been modified. Other kinds 4043** of conversion are done in place when it is possible, but sometimes they 4044** are not possible and in those cases prior pointers are invalidated. 4045** 4046** The safest and easiest to remember policy is to invoke these routines 4047** in one of the following ways: 4048** 4049** <ul> 4050** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> 4051** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> 4052** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> 4053** </ul> 4054** 4055** In other words, you should call sqlite3_column_text(), 4056** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result 4057** into the desired format, then invoke sqlite3_column_bytes() or 4058** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 4059** to sqlite3_column_text() or sqlite3_column_blob() with calls to 4060** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 4061** with calls to sqlite3_column_bytes(). 4062** 4063** ^The pointers returned are valid until a type conversion occurs as 4064** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 4065** [sqlite3_finalize()] is called. ^The memory space used to hold strings 4066** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned 4067** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 4068** [sqlite3_free()]. 4069** 4070** ^(If a memory allocation error occurs during the evaluation of any 4071** of these routines, a default value is returned. The default value 4072** is either the integer 0, the floating point number 0.0, or a NULL 4073** pointer. Subsequent calls to [sqlite3_errcode()] will return 4074** [SQLITE_NOMEM].)^ 4075*/ 4076SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 4077SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 4078SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 4079SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); 4080SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); 4081SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 4082SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 4083SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 4084SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); 4085SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 4086 4087/* 4088** CAPI3REF: Destroy A Prepared Statement Object 4089** 4090** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 4091** ^If the most recent evaluation of the statement encountered no errors 4092** or if the statement is never been evaluated, then sqlite3_finalize() returns 4093** SQLITE_OK. ^If the most recent evaluation of statement S failed, then 4094** sqlite3_finalize(S) returns the appropriate [error code] or 4095** [extended error code]. 4096** 4097** ^The sqlite3_finalize(S) routine can be called at any point during 4098** the life cycle of [prepared statement] S: 4099** before statement S is ever evaluated, after 4100** one or more calls to [sqlite3_reset()], or after any call 4101** to [sqlite3_step()] regardless of whether or not the statement has 4102** completed execution. 4103** 4104** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. 4105** 4106** The application must finalize every [prepared statement] in order to avoid 4107** resource leaks. It is a grievous error for the application to try to use 4108** a prepared statement after it has been finalized. Any use of a prepared 4109** statement after it has been finalized can result in undefined and 4110** undesirable behavior such as segfaults and heap corruption. 4111*/ 4112SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); 4113 4114/* 4115** CAPI3REF: Reset A Prepared Statement Object 4116** 4117** The sqlite3_reset() function is called to reset a [prepared statement] 4118** object back to its initial state, ready to be re-executed. 4119** ^Any SQL statement variables that had values bound to them using 4120** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. 4121** Use [sqlite3_clear_bindings()] to reset the bindings. 4122** 4123** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S 4124** back to the beginning of its program. 4125** 4126** ^If the most recent call to [sqlite3_step(S)] for the 4127** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], 4128** or if [sqlite3_step(S)] has never before been called on S, 4129** then [sqlite3_reset(S)] returns [SQLITE_OK]. 4130** 4131** ^If the most recent call to [sqlite3_step(S)] for the 4132** [prepared statement] S indicated an error, then 4133** [sqlite3_reset(S)] returns an appropriate [error code]. 4134** 4135** ^The [sqlite3_reset(S)] interface does not change the values 4136** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. 4137*/ 4138SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); 4139 4140/* 4141** CAPI3REF: Create Or Redefine SQL Functions 4142** KEYWORDS: {function creation routines} 4143** KEYWORDS: {application-defined SQL function} 4144** KEYWORDS: {application-defined SQL functions} 4145** 4146** ^These functions (collectively known as "function creation routines") 4147** are used to add SQL functions or aggregates or to redefine the behavior 4148** of existing SQL functions or aggregates. The only differences between 4149** these routines are the text encoding expected for 4150** the second parameter (the name of the function being created) 4151** and the presence or absence of a destructor callback for 4152** the application data pointer. 4153** 4154** ^The first parameter is the [database connection] to which the SQL 4155** function is to be added. ^If an application uses more than one database 4156** connection then application-defined SQL functions must be added 4157** to each database connection separately. 4158** 4159** ^The second parameter is the name of the SQL function to be created or 4160** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 4161** representation, exclusive of the zero-terminator. ^Note that the name 4162** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. 4163** ^Any attempt to create a function with a longer name 4164** will result in [SQLITE_MISUSE] being returned. 4165** 4166** ^The third parameter (nArg) 4167** is the number of arguments that the SQL function or 4168** aggregate takes. ^If this parameter is -1, then the SQL function or 4169** aggregate may take any number of arguments between 0 and the limit 4170** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 4171** parameter is less than -1 or greater than 127 then the behavior is 4172** undefined. 4173** 4174** ^The fourth parameter, eTextRep, specifies what 4175** [SQLITE_UTF8 | text encoding] this SQL function prefers for 4176** its parameters. Every SQL function implementation must be able to work 4177** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be 4178** more efficient with one encoding than another. ^An application may 4179** invoke sqlite3_create_function() or sqlite3_create_function16() multiple 4180** times with the same function but with different values of eTextRep. 4181** ^When multiple implementations of the same function are available, SQLite 4182** will pick the one that involves the least amount of data conversion. 4183** If there is only a single implementation which does not care what text 4184** encoding is used, then the fourth argument should be [SQLITE_ANY]. 4185** 4186** ^(The fifth parameter is an arbitrary pointer. The implementation of the 4187** function can gain access to this pointer using [sqlite3_user_data()].)^ 4188** 4189** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are 4190** pointers to C-language functions that implement the SQL function or 4191** aggregate. ^A scalar SQL function requires an implementation of the xFunc 4192** callback only; NULL pointers must be passed as the xStep and xFinal 4193** parameters. ^An aggregate SQL function requires an implementation of xStep 4194** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing 4195** SQL function or aggregate, pass NULL pointers for all three function 4196** callbacks. 4197** 4198** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL, 4199** then it is destructor for the application data pointer. 4200** The destructor is invoked when the function is deleted, either by being 4201** overloaded or when the database connection closes.)^ 4202** ^The destructor is also invoked if the call to 4203** sqlite3_create_function_v2() fails. 4204** ^When the destructor callback of the tenth parameter is invoked, it 4205** is passed a single argument which is a copy of the application data 4206** pointer which was the fifth parameter to sqlite3_create_function_v2(). 4207** 4208** ^It is permitted to register multiple implementations of the same 4209** functions with the same name but with either differing numbers of 4210** arguments or differing preferred text encodings. ^SQLite will use 4211** the implementation that most closely matches the way in which the 4212** SQL function is used. ^A function implementation with a non-negative 4213** nArg parameter is a better match than a function implementation with 4214** a negative nArg. ^A function where the preferred text encoding 4215** matches the database encoding is a better 4216** match than a function where the encoding is different. 4217** ^A function where the encoding difference is between UTF16le and UTF16be 4218** is a closer match than a function where the encoding difference is 4219** between UTF8 and UTF16. 4220** 4221** ^Built-in functions may be overloaded by new application-defined functions. 4222** 4223** ^An application-defined function is permitted to call other 4224** SQLite interfaces. However, such calls must not 4225** close the database connection nor finalize or reset the prepared 4226** statement in which the function is running. 4227*/ 4228SQLITE_API int sqlite3_create_function( 4229 sqlite3 *db, 4230 const char *zFunctionName, 4231 int nArg, 4232 int eTextRep, 4233 void *pApp, 4234 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 4235 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 4236 void (*xFinal)(sqlite3_context*) 4237); 4238SQLITE_API int sqlite3_create_function16( 4239 sqlite3 *db, 4240 const void *zFunctionName, 4241 int nArg, 4242 int eTextRep, 4243 void *pApp, 4244 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 4245 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 4246 void (*xFinal)(sqlite3_context*) 4247); 4248SQLITE_API int sqlite3_create_function_v2( 4249 sqlite3 *db, 4250 const char *zFunctionName, 4251 int nArg, 4252 int eTextRep, 4253 void *pApp, 4254 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 4255 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 4256 void (*xFinal)(sqlite3_context*), 4257 void(*xDestroy)(void*) 4258); 4259 4260/* 4261** CAPI3REF: Text Encodings 4262** 4263** These constant define integer codes that represent the various 4264** text encodings supported by SQLite. 4265*/ 4266#define SQLITE_UTF8 1 4267#define SQLITE_UTF16LE 2 4268#define SQLITE_UTF16BE 3 4269#define SQLITE_UTF16 4 /* Use native byte order */ 4270#define SQLITE_ANY 5 /* sqlite3_create_function only */ 4271#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 4272 4273/* 4274** CAPI3REF: Deprecated Functions 4275** DEPRECATED 4276** 4277** These functions are [deprecated]. In order to maintain 4278** backwards compatibility with older code, these functions continue 4279** to be supported. However, new applications should avoid 4280** the use of these functions. To help encourage people to avoid 4281** using these functions, we are not going to tell you what they do. 4282*/ 4283#ifndef SQLITE_OMIT_DEPRECATED 4284SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 4285SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 4286SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); 4287SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); 4288SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 4289SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); 4290#endif 4291 4292/* 4293** CAPI3REF: Obtaining SQL Function Parameter Values 4294** 4295** The C-language implementation of SQL functions and aggregates uses 4296** this set of interface routines to access the parameter values on 4297** the function or aggregate. 4298** 4299** The xFunc (for scalar functions) or xStep (for aggregates) parameters 4300** to [sqlite3_create_function()] and [sqlite3_create_function16()] 4301** define callbacks that implement the SQL functions and aggregates. 4302** The 3rd parameter to these callbacks is an array of pointers to 4303** [protected sqlite3_value] objects. There is one [sqlite3_value] object for 4304** each parameter to the SQL function. These routines are used to 4305** extract values from the [sqlite3_value] objects. 4306** 4307** These routines work only with [protected sqlite3_value] objects. 4308** Any attempt to use these routines on an [unprotected sqlite3_value] 4309** object results in undefined behavior. 4310** 4311** ^These routines work just like the corresponding [column access functions] 4312** except that these routines take a single [protected sqlite3_value] object 4313** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 4314** 4315** ^The sqlite3_value_text16() interface extracts a UTF-16 string 4316** in the native byte-order of the host machine. ^The 4317** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 4318** extract UTF-16 strings as big-endian and little-endian respectively. 4319** 4320** ^(The sqlite3_value_numeric_type() interface attempts to apply 4321** numeric affinity to the value. This means that an attempt is 4322** made to convert the value to an integer or floating point. If 4323** such a conversion is possible without loss of information (in other 4324** words, if the value is a string that looks like a number) 4325** then the conversion is performed. Otherwise no conversion occurs. 4326** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ 4327** 4328** Please pay particular attention to the fact that the pointer returned 4329** from [sqlite3_value_blob()], [sqlite3_value_text()], or 4330** [sqlite3_value_text16()] can be invalidated by a subsequent call to 4331** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], 4332** or [sqlite3_value_text16()]. 4333** 4334** These routines must be called from the same thread as 4335** the SQL function that supplied the [sqlite3_value*] parameters. 4336*/ 4337SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); 4338SQLITE_API int sqlite3_value_bytes(sqlite3_value*); 4339SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); 4340SQLITE_API double sqlite3_value_double(sqlite3_value*); 4341SQLITE_API int sqlite3_value_int(sqlite3_value*); 4342SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); 4343SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); 4344SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); 4345SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); 4346SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); 4347SQLITE_API int sqlite3_value_type(sqlite3_value*); 4348SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); 4349 4350/* 4351** CAPI3REF: Obtain Aggregate Function Context 4352** 4353** Implementations of aggregate SQL functions use this 4354** routine to allocate memory for storing their state. 4355** 4356** ^The first time the sqlite3_aggregate_context(C,N) routine is called 4357** for a particular aggregate function, SQLite 4358** allocates N of memory, zeroes out that memory, and returns a pointer 4359** to the new memory. ^On second and subsequent calls to 4360** sqlite3_aggregate_context() for the same aggregate function instance, 4361** the same buffer is returned. Sqlite3_aggregate_context() is normally 4362** called once for each invocation of the xStep callback and then one 4363** last time when the xFinal callback is invoked. ^(When no rows match 4364** an aggregate query, the xStep() callback of the aggregate function 4365** implementation is never called and xFinal() is called exactly once. 4366** In those cases, sqlite3_aggregate_context() might be called for the 4367** first time from within xFinal().)^ 4368** 4369** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is 4370** less than or equal to zero or if a memory allocate error occurs. 4371** 4372** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 4373** determined by the N parameter on first successful call. Changing the 4374** value of N in subsequent call to sqlite3_aggregate_context() within 4375** the same aggregate function instance will not resize the memory 4376** allocation.)^ 4377** 4378** ^SQLite automatically frees the memory allocated by 4379** sqlite3_aggregate_context() when the aggregate query concludes. 4380** 4381** The first parameter must be a copy of the 4382** [sqlite3_context | SQL function context] that is the first parameter 4383** to the xStep or xFinal callback routine that implements the aggregate 4384** function. 4385** 4386** This routine must be called from the same thread in which 4387** the aggregate SQL function is running. 4388*/ 4389SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); 4390 4391/* 4392** CAPI3REF: User Data For Functions 4393** 4394** ^The sqlite3_user_data() interface returns a copy of 4395** the pointer that was the pUserData parameter (the 5th parameter) 4396** of the [sqlite3_create_function()] 4397** and [sqlite3_create_function16()] routines that originally 4398** registered the application defined function. 4399** 4400** This routine must be called from the same thread in which 4401** the application-defined function is running. 4402*/ 4403SQLITE_API void *sqlite3_user_data(sqlite3_context*); 4404 4405/* 4406** CAPI3REF: Database Connection For Functions 4407** 4408** ^The sqlite3_context_db_handle() interface returns a copy of 4409** the pointer to the [database connection] (the 1st parameter) 4410** of the [sqlite3_create_function()] 4411** and [sqlite3_create_function16()] routines that originally 4412** registered the application defined function. 4413*/ 4414SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 4415 4416/* 4417** CAPI3REF: Function Auxiliary Data 4418** 4419** The following two functions may be used by scalar SQL functions to 4420** associate metadata with argument values. If the same value is passed to 4421** multiple invocations of the same SQL function during query execution, under 4422** some circumstances the associated metadata may be preserved. This may 4423** be used, for example, to add a regular-expression matching scalar 4424** function. The compiled version of the regular expression is stored as 4425** metadata associated with the SQL value passed as the regular expression 4426** pattern. The compiled regular expression can be reused on multiple 4427** invocations of the same function so that the original pattern string 4428** does not need to be recompiled on each invocation. 4429** 4430** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata 4431** associated by the sqlite3_set_auxdata() function with the Nth argument 4432** value to the application-defined function. ^If no metadata has been ever 4433** been set for the Nth argument of the function, or if the corresponding 4434** function parameter has changed since the meta-data was set, 4435** then sqlite3_get_auxdata() returns a NULL pointer. 4436** 4437** ^The sqlite3_set_auxdata() interface saves the metadata 4438** pointed to by its 3rd parameter as the metadata for the N-th 4439** argument of the application-defined function. Subsequent 4440** calls to sqlite3_get_auxdata() might return this data, if it has 4441** not been destroyed. 4442** ^If it is not NULL, SQLite will invoke the destructor 4443** function given by the 4th parameter to sqlite3_set_auxdata() on 4444** the metadata when the corresponding function parameter changes 4445** or when the SQL statement completes, whichever comes first. 4446** 4447** SQLite is free to call the destructor and drop metadata on any 4448** parameter of any function at any time. ^The only guarantee is that 4449** the destructor will be called before the metadata is dropped. 4450** 4451** ^(In practice, metadata is preserved between function calls for 4452** expressions that are constant at compile time. This includes literal 4453** values and [parameters].)^ 4454** 4455** These routines must be called from the same thread in which 4456** the SQL function is running. 4457*/ 4458SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); 4459SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); 4460 4461 4462/* 4463** CAPI3REF: Constants Defining Special Destructor Behavior 4464** 4465** These are special values for the destructor that is passed in as the 4466** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 4467** argument is SQLITE_STATIC, it means that the content pointer is constant 4468** and will never change. It does not need to be destroyed. ^The 4469** SQLITE_TRANSIENT value means that the content will likely change in 4470** the near future and that SQLite should make its own private copy of 4471** the content before returning. 4472** 4473** The typedef is necessary to work around problems in certain 4474** C++ compilers. See ticket #2191. 4475*/ 4476typedef void (*sqlite3_destructor_type)(void*); 4477#define SQLITE_STATIC ((sqlite3_destructor_type)0) 4478#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 4479 4480/* 4481** CAPI3REF: Setting The Result Of An SQL Function 4482** 4483** These routines are used by the xFunc or xFinal callbacks that 4484** implement SQL functions and aggregates. See 4485** [sqlite3_create_function()] and [sqlite3_create_function16()] 4486** for additional information. 4487** 4488** These functions work very much like the [parameter binding] family of 4489** functions used to bind values to host parameters in prepared statements. 4490** Refer to the [SQL parameter] documentation for additional information. 4491** 4492** ^The sqlite3_result_blob() interface sets the result from 4493** an application-defined function to be the BLOB whose content is pointed 4494** to by the second parameter and which is N bytes long where N is the 4495** third parameter. 4496** 4497** ^The sqlite3_result_zeroblob() interfaces set the result of 4498** the application-defined function to be a BLOB containing all zero 4499** bytes and N bytes in size, where N is the value of the 2nd parameter. 4500** 4501** ^The sqlite3_result_double() interface sets the result from 4502** an application-defined function to be a floating point value specified 4503** by its 2nd argument. 4504** 4505** ^The sqlite3_result_error() and sqlite3_result_error16() functions 4506** cause the implemented SQL function to throw an exception. 4507** ^SQLite uses the string pointed to by the 4508** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() 4509** as the text of an error message. ^SQLite interprets the error 4510** message string from sqlite3_result_error() as UTF-8. ^SQLite 4511** interprets the string from sqlite3_result_error16() as UTF-16 in native 4512** byte order. ^If the third parameter to sqlite3_result_error() 4513** or sqlite3_result_error16() is negative then SQLite takes as the error 4514** message all text up through the first zero character. 4515** ^If the third parameter to sqlite3_result_error() or 4516** sqlite3_result_error16() is non-negative then SQLite takes that many 4517** bytes (not characters) from the 2nd parameter as the error message. 4518** ^The sqlite3_result_error() and sqlite3_result_error16() 4519** routines make a private copy of the error message text before 4520** they return. Hence, the calling function can deallocate or 4521** modify the text after they return without harm. 4522** ^The sqlite3_result_error_code() function changes the error code 4523** returned by SQLite as a result of an error in a function. ^By default, 4524** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 4525** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 4526** 4527** ^The sqlite3_result_toobig() interface causes SQLite to throw an error 4528** indicating that a string or BLOB is too long to represent. 4529** 4530** ^The sqlite3_result_nomem() interface causes SQLite to throw an error 4531** indicating that a memory allocation failed. 4532** 4533** ^The sqlite3_result_int() interface sets the return value 4534** of the application-defined function to be the 32-bit signed integer 4535** value given in the 2nd argument. 4536** ^The sqlite3_result_int64() interface sets the return value 4537** of the application-defined function to be the 64-bit signed integer 4538** value given in the 2nd argument. 4539** 4540** ^The sqlite3_result_null() interface sets the return value 4541** of the application-defined function to be NULL. 4542** 4543** ^The sqlite3_result_text(), sqlite3_result_text16(), 4544** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 4545** set the return value of the application-defined function to be 4546** a text string which is represented as UTF-8, UTF-16 native byte order, 4547** UTF-16 little endian, or UTF-16 big endian, respectively. 4548** ^SQLite takes the text result from the application from 4549** the 2nd parameter of the sqlite3_result_text* interfaces. 4550** ^If the 3rd parameter to the sqlite3_result_text* interfaces 4551** is negative, then SQLite takes result text from the 2nd parameter 4552** through the first zero character. 4553** ^If the 3rd parameter to the sqlite3_result_text* interfaces 4554** is non-negative, then as many bytes (not characters) of the text 4555** pointed to by the 2nd parameter are taken as the application-defined 4556** function result. 4557** ^If the 4th parameter to the sqlite3_result_text* interfaces 4558** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 4559** function as the destructor on the text or BLOB result when it has 4560** finished using that result. 4561** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 4562** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 4563** assumes that the text or BLOB result is in constant space and does not 4564** copy the content of the parameter nor call a destructor on the content 4565** when it has finished using that result. 4566** ^If the 4th parameter to the sqlite3_result_text* interfaces 4567** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 4568** then SQLite makes a copy of the result into space obtained from 4569** from [sqlite3_malloc()] before it returns. 4570** 4571** ^The sqlite3_result_value() interface sets the result of 4572** the application-defined function to be a copy the 4573** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 4574** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 4575** so that the [sqlite3_value] specified in the parameter may change or 4576** be deallocated after sqlite3_result_value() returns without harm. 4577** ^A [protected sqlite3_value] object may always be used where an 4578** [unprotected sqlite3_value] object is required, so either 4579** kind of [sqlite3_value] object can be used with this interface. 4580** 4581** If these routines are called from within the different thread 4582** than the one containing the application-defined function that received 4583** the [sqlite3_context] pointer, the results are undefined. 4584*/ 4585SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); 4586SQLITE_API void sqlite3_result_double(sqlite3_context*, double); 4587SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); 4588SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); 4589SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); 4590SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); 4591SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); 4592SQLITE_API void sqlite3_result_int(sqlite3_context*, int); 4593SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 4594SQLITE_API void sqlite3_result_null(sqlite3_context*); 4595SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); 4596SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); 4597SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); 4598SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); 4599SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 4600SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); 4601 4602/* 4603** CAPI3REF: Define New Collating Sequences 4604** 4605** ^These functions add, remove, or modify a [collation] associated 4606** with the [database connection] specified as the first argument. 4607** 4608** ^The name of the collation is a UTF-8 string 4609** for sqlite3_create_collation() and sqlite3_create_collation_v2() 4610** and a UTF-16 string in native byte order for sqlite3_create_collation16(). 4611** ^Collation names that compare equal according to [sqlite3_strnicmp()] are 4612** considered to be the same name. 4613** 4614** ^(The third argument (eTextRep) must be one of the constants: 4615** <ul> 4616** <li> [SQLITE_UTF8], 4617** <li> [SQLITE_UTF16LE], 4618** <li> [SQLITE_UTF16BE], 4619** <li> [SQLITE_UTF16], or 4620** <li> [SQLITE_UTF16_ALIGNED]. 4621** </ul>)^ 4622** ^The eTextRep argument determines the encoding of strings passed 4623** to the collating function callback, xCallback. 4624** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep 4625** force strings to be UTF16 with native byte order. 4626** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin 4627** on an even byte address. 4628** 4629** ^The fourth argument, pArg, is an application data pointer that is passed 4630** through as the first argument to the collating function callback. 4631** 4632** ^The fifth argument, xCallback, is a pointer to the collating function. 4633** ^Multiple collating functions can be registered using the same name but 4634** with different eTextRep parameters and SQLite will use whichever 4635** function requires the least amount of data transformation. 4636** ^If the xCallback argument is NULL then the collating function is 4637** deleted. ^When all collating functions having the same name are deleted, 4638** that collation is no longer usable. 4639** 4640** ^The collating function callback is invoked with a copy of the pArg 4641** application data pointer and with two strings in the encoding specified 4642** by the eTextRep argument. The collating function must return an 4643** integer that is negative, zero, or positive 4644** if the first string is less than, equal to, or greater than the second, 4645** respectively. A collating function must always return the same answer 4646** given the same inputs. If two or more collating functions are registered 4647** to the same collation name (using different eTextRep values) then all 4648** must give an equivalent answer when invoked with equivalent strings. 4649** The collating function must obey the following properties for all 4650** strings A, B, and C: 4651** 4652** <ol> 4653** <li> If A==B then B==A. 4654** <li> If A==B and B==C then A==C. 4655** <li> If A<B THEN B>A. 4656** <li> If A<B and B<C then A<C. 4657** </ol> 4658** 4659** If a collating function fails any of the above constraints and that 4660** collating function is registered and used, then the behavior of SQLite 4661** is undefined. 4662** 4663** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() 4664** with the addition that the xDestroy callback is invoked on pArg when 4665** the collating function is deleted. 4666** ^Collating functions are deleted when they are overridden by later 4667** calls to the collation creation functions or when the 4668** [database connection] is closed using [sqlite3_close()]. 4669** 4670** ^The xDestroy callback is <u>not</u> called if the 4671** sqlite3_create_collation_v2() function fails. Applications that invoke 4672** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should 4673** check the return code and dispose of the application data pointer 4674** themselves rather than expecting SQLite to deal with it for them. 4675** This is different from every other SQLite interface. The inconsistency 4676** is unfortunate but cannot be changed without breaking backwards 4677** compatibility. 4678** 4679** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. 4680*/ 4681SQLITE_API int sqlite3_create_collation( 4682 sqlite3*, 4683 const char *zName, 4684 int eTextRep, 4685 void *pArg, 4686 int(*xCompare)(void*,int,const void*,int,const void*) 4687); 4688SQLITE_API int sqlite3_create_collation_v2( 4689 sqlite3*, 4690 const char *zName, 4691 int eTextRep, 4692 void *pArg, 4693 int(*xCompare)(void*,int,const void*,int,const void*), 4694 void(*xDestroy)(void*) 4695); 4696SQLITE_API int sqlite3_create_collation16( 4697 sqlite3*, 4698 const void *zName, 4699 int eTextRep, 4700 void *pArg, 4701 int(*xCompare)(void*,int,const void*,int,const void*) 4702); 4703 4704/* 4705** CAPI3REF: Collation Needed Callbacks 4706** 4707** ^To avoid having to register all collation sequences before a database 4708** can be used, a single callback function may be registered with the 4709** [database connection] to be invoked whenever an undefined collation 4710** sequence is required. 4711** 4712** ^If the function is registered using the sqlite3_collation_needed() API, 4713** then it is passed the names of undefined collation sequences as strings 4714** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, 4715** the names are passed as UTF-16 in machine native byte order. 4716** ^A call to either function replaces the existing collation-needed callback. 4717** 4718** ^(When the callback is invoked, the first argument passed is a copy 4719** of the second argument to sqlite3_collation_needed() or 4720** sqlite3_collation_needed16(). The second argument is the database 4721** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], 4722** or [SQLITE_UTF16LE], indicating the most desirable form of the collation 4723** sequence function required. The fourth parameter is the name of the 4724** required collation sequence.)^ 4725** 4726** The callback function should register the desired collation using 4727** [sqlite3_create_collation()], [sqlite3_create_collation16()], or 4728** [sqlite3_create_collation_v2()]. 4729*/ 4730SQLITE_API int sqlite3_collation_needed( 4731 sqlite3*, 4732 void*, 4733 void(*)(void*,sqlite3*,int eTextRep,const char*) 4734); 4735SQLITE_API int sqlite3_collation_needed16( 4736 sqlite3*, 4737 void*, 4738 void(*)(void*,sqlite3*,int eTextRep,const void*) 4739); 4740 4741#ifdef SQLITE_HAS_CODEC 4742/* 4743** Specify the key for an encrypted database. This routine should be 4744** called right after sqlite3_open(). 4745** 4746** The code to implement this API is not available in the public release 4747** of SQLite. 4748*/ 4749SQLITE_API int sqlite3_key( 4750 sqlite3 *db, /* Database to be rekeyed */ 4751 const void *pKey, int nKey /* The key */ 4752); 4753 4754/* 4755** Change the key on an open database. If the current database is not 4756** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the 4757** database is decrypted. 4758** 4759** The code to implement this API is not available in the public release 4760** of SQLite. 4761*/ 4762SQLITE_API int sqlite3_rekey( 4763 sqlite3 *db, /* Database to be rekeyed */ 4764 const void *pKey, int nKey /* The new key */ 4765); 4766 4767/* 4768** Specify the activation key for a SEE database. Unless 4769** activated, none of the SEE routines will work. 4770*/ 4771SQLITE_API void sqlite3_activate_see( 4772 const char *zPassPhrase /* Activation phrase */ 4773); 4774#endif 4775 4776#ifdef SQLITE_ENABLE_CEROD 4777/* 4778** Specify the activation key for a CEROD database. Unless 4779** activated, none of the CEROD routines will work. 4780*/ 4781SQLITE_API void sqlite3_activate_cerod( 4782 const char *zPassPhrase /* Activation phrase */ 4783); 4784#endif 4785 4786/* 4787** CAPI3REF: Suspend Execution For A Short Time 4788** 4789** The sqlite3_sleep() function causes the current thread to suspend execution 4790** for at least a number of milliseconds specified in its parameter. 4791** 4792** If the operating system does not support sleep requests with 4793** millisecond time resolution, then the time will be rounded up to 4794** the nearest second. The number of milliseconds of sleep actually 4795** requested from the operating system is returned. 4796** 4797** ^SQLite implements this interface by calling the xSleep() 4798** method of the default [sqlite3_vfs] object. If the xSleep() method 4799** of the default VFS is not implemented correctly, or not implemented at 4800** all, then the behavior of sqlite3_sleep() may deviate from the description 4801** in the previous paragraphs. 4802*/ 4803SQLITE_API int sqlite3_sleep(int); 4804 4805/* 4806** CAPI3REF: Name Of The Folder Holding Temporary Files 4807** 4808** ^(If this global variable is made to point to a string which is 4809** the name of a folder (a.k.a. directory), then all temporary files 4810** created by SQLite when using a built-in [sqlite3_vfs | VFS] 4811** will be placed in that directory.)^ ^If this variable 4812** is a NULL pointer, then SQLite performs a search for an appropriate 4813** temporary file directory. 4814** 4815** It is not safe to read or modify this variable in more than one 4816** thread at a time. It is not safe to read or modify this variable 4817** if a [database connection] is being used at the same time in a separate 4818** thread. 4819** It is intended that this variable be set once 4820** as part of process initialization and before any SQLite interface 4821** routines have been called and that this variable remain unchanged 4822** thereafter. 4823** 4824** ^The [temp_store_directory pragma] may modify this variable and cause 4825** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 4826** the [temp_store_directory pragma] always assumes that any string 4827** that this variable points to is held in memory obtained from 4828** [sqlite3_malloc] and the pragma may attempt to free that memory 4829** using [sqlite3_free]. 4830** Hence, if this variable is modified directly, either it should be 4831** made NULL or made to point to memory obtained from [sqlite3_malloc] 4832** or else the use of the [temp_store_directory pragma] should be avoided. 4833*/ 4834SQLITE_API char *sqlite3_temp_directory; 4835 4836/* 4837** CAPI3REF: Test For Auto-Commit Mode 4838** KEYWORDS: {autocommit mode} 4839** 4840** ^The sqlite3_get_autocommit() interface returns non-zero or 4841** zero if the given database connection is or is not in autocommit mode, 4842** respectively. ^Autocommit mode is on by default. 4843** ^Autocommit mode is disabled by a [BEGIN] statement. 4844** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. 4845** 4846** If certain kinds of errors occur on a statement within a multi-statement 4847** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], 4848** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the 4849** transaction might be rolled back automatically. The only way to 4850** find out whether SQLite automatically rolled back the transaction after 4851** an error is to use this function. 4852** 4853** If another thread changes the autocommit status of the database 4854** connection while this routine is running, then the return value 4855** is undefined. 4856*/ 4857SQLITE_API int sqlite3_get_autocommit(sqlite3*); 4858 4859/* 4860** CAPI3REF: Find The Database Handle Of A Prepared Statement 4861** 4862** ^The sqlite3_db_handle interface returns the [database connection] handle 4863** to which a [prepared statement] belongs. ^The [database connection] 4864** returned by sqlite3_db_handle is the same [database connection] 4865** that was the first argument 4866** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 4867** create the statement in the first place. 4868*/ 4869SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 4870 4871/* 4872** CAPI3REF: Find the next prepared statement 4873** 4874** ^This interface returns a pointer to the next [prepared statement] after 4875** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 4876** then this interface returns a pointer to the first prepared statement 4877** associated with the database connection pDb. ^If no prepared statement 4878** satisfies the conditions of this routine, it returns NULL. 4879** 4880** The [database connection] pointer D in a call to 4881** [sqlite3_next_stmt(D,S)] must refer to an open database 4882** connection and in particular must not be a NULL pointer. 4883*/ 4884SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); 4885 4886/* 4887** CAPI3REF: Commit And Rollback Notification Callbacks 4888** 4889** ^The sqlite3_commit_hook() interface registers a callback 4890** function to be invoked whenever a transaction is [COMMIT | committed]. 4891** ^Any callback set by a previous call to sqlite3_commit_hook() 4892** for the same database connection is overridden. 4893** ^The sqlite3_rollback_hook() interface registers a callback 4894** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. 4895** ^Any callback set by a previous call to sqlite3_rollback_hook() 4896** for the same database connection is overridden. 4897** ^The pArg argument is passed through to the callback. 4898** ^If the callback on a commit hook function returns non-zero, 4899** then the commit is converted into a rollback. 4900** 4901** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 4902** return the P argument from the previous call of the same function 4903** on the same [database connection] D, or NULL for 4904** the first call for each function on D. 4905** 4906** The callback implementation must not do anything that will modify 4907** the database connection that invoked the callback. Any actions 4908** to modify the database connection must be deferred until after the 4909** completion of the [sqlite3_step()] call that triggered the commit 4910** or rollback hook in the first place. 4911** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 4912** database connections for the meaning of "modify" in this paragraph. 4913** 4914** ^Registering a NULL function disables the callback. 4915** 4916** ^When the commit hook callback routine returns zero, the [COMMIT] 4917** operation is allowed to continue normally. ^If the commit hook 4918** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 4919** ^The rollback hook is invoked on a rollback that results from a commit 4920** hook returning non-zero, just as it would be with any other rollback. 4921** 4922** ^For the purposes of this API, a transaction is said to have been 4923** rolled back if an explicit "ROLLBACK" statement is executed, or 4924** an error or constraint causes an implicit rollback to occur. 4925** ^The rollback callback is not invoked if a transaction is 4926** automatically rolled back because the database connection is closed. 4927** 4928** See also the [sqlite3_update_hook()] interface. 4929*/ 4930SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); 4931SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); 4932 4933/* 4934** CAPI3REF: Data Change Notification Callbacks 4935** 4936** ^The sqlite3_update_hook() interface registers a callback function 4937** with the [database connection] identified by the first argument 4938** to be invoked whenever a row is updated, inserted or deleted. 4939** ^Any callback set by a previous call to this function 4940** for the same database connection is overridden. 4941** 4942** ^The second argument is a pointer to the function to invoke when a 4943** row is updated, inserted or deleted. 4944** ^The first argument to the callback is a copy of the third argument 4945** to sqlite3_update_hook(). 4946** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], 4947** or [SQLITE_UPDATE], depending on the operation that caused the callback 4948** to be invoked. 4949** ^The third and fourth arguments to the callback contain pointers to the 4950** database and table name containing the affected row. 4951** ^The final callback parameter is the [rowid] of the row. 4952** ^In the case of an update, this is the [rowid] after the update takes place. 4953** 4954** ^(The update hook is not invoked when internal system tables are 4955** modified (i.e. sqlite_master and sqlite_sequence).)^ 4956** 4957** ^In the current implementation, the update hook 4958** is not invoked when duplication rows are deleted because of an 4959** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook 4960** invoked when rows are deleted using the [truncate optimization]. 4961** The exceptions defined in this paragraph might change in a future 4962** release of SQLite. 4963** 4964** The update hook implementation must not do anything that will modify 4965** the database connection that invoked the update hook. Any actions 4966** to modify the database connection must be deferred until after the 4967** completion of the [sqlite3_step()] call that triggered the update hook. 4968** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 4969** database connections for the meaning of "modify" in this paragraph. 4970** 4971** ^The sqlite3_update_hook(D,C,P) function 4972** returns the P argument from the previous call 4973** on the same [database connection] D, or NULL for 4974** the first call on D. 4975** 4976** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()] 4977** interfaces. 4978*/ 4979SQLITE_API void *sqlite3_update_hook( 4980 sqlite3*, 4981 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 4982 void* 4983); 4984 4985/* 4986** CAPI3REF: Enable Or Disable Shared Pager Cache 4987** KEYWORDS: {shared cache} 4988** 4989** ^(This routine enables or disables the sharing of the database cache 4990** and schema data structures between [database connection | connections] 4991** to the same database. Sharing is enabled if the argument is true 4992** and disabled if the argument is false.)^ 4993** 4994** ^Cache sharing is enabled and disabled for an entire process. 4995** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, 4996** sharing was enabled or disabled for each thread separately. 4997** 4998** ^(The cache sharing mode set by this interface effects all subsequent 4999** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. 5000** Existing database connections continue use the sharing mode 5001** that was in effect at the time they were opened.)^ 5002** 5003** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled 5004** successfully. An [error code] is returned otherwise.)^ 5005** 5006** ^Shared cache is disabled by default. But this might change in 5007** future releases of SQLite. Applications that care about shared 5008** cache setting should set it explicitly. 5009** 5010** See Also: [SQLite Shared-Cache Mode] 5011*/ 5012SQLITE_API int sqlite3_enable_shared_cache(int); 5013 5014/* 5015** CAPI3REF: Attempt To Free Heap Memory 5016** 5017** ^The sqlite3_release_memory() interface attempts to free N bytes 5018** of heap memory by deallocating non-essential memory allocations 5019** held by the database library. Memory used to cache database 5020** pages to improve performance is an example of non-essential memory. 5021** ^sqlite3_release_memory() returns the number of bytes actually freed, 5022** which might be more or less than the amount requested. 5023** ^The sqlite3_release_memory() routine is a no-op returning zero 5024** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 5025*/ 5026SQLITE_API int sqlite3_release_memory(int); 5027 5028/* 5029** CAPI3REF: Impose A Limit On Heap Size 5030** 5031** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 5032** soft limit on the amount of heap memory that may be allocated by SQLite. 5033** ^SQLite strives to keep heap memory utilization below the soft heap 5034** limit by reducing the number of pages held in the page cache 5035** as heap memory usages approaches the limit. 5036** ^The soft heap limit is "soft" because even though SQLite strives to stay 5037** below the limit, it will exceed the limit rather than generate 5038** an [SQLITE_NOMEM] error. In other words, the soft heap limit 5039** is advisory only. 5040** 5041** ^The return value from sqlite3_soft_heap_limit64() is the size of 5042** the soft heap limit prior to the call. ^If the argument N is negative 5043** then no change is made to the soft heap limit. Hence, the current 5044** size of the soft heap limit can be determined by invoking 5045** sqlite3_soft_heap_limit64() with a negative argument. 5046** 5047** ^If the argument N is zero then the soft heap limit is disabled. 5048** 5049** ^(The soft heap limit is not enforced in the current implementation 5050** if one or more of following conditions are true: 5051** 5052** <ul> 5053** <li> The soft heap limit is set to zero. 5054** <li> Memory accounting is disabled using a combination of the 5055** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 5056** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 5057** <li> An alternative page cache implementation is specified using 5058** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...). 5059** <li> The page cache allocates from its own memory pool supplied 5060** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 5061** from the heap. 5062** </ul>)^ 5063** 5064** Beginning with SQLite version 3.7.3, the soft heap limit is enforced 5065** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] 5066** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], 5067** the soft heap limit is enforced on every memory allocation. Without 5068** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced 5069** when memory is allocated by the page cache. Testing suggests that because 5070** the page cache is the predominate memory user in SQLite, most 5071** applications will achieve adequate soft heap limit enforcement without 5072** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 5073** 5074** The circumstances under which SQLite will enforce the soft heap limit may 5075** changes in future releases of SQLite. 5076*/ 5077SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); 5078 5079/* 5080** CAPI3REF: Deprecated Soft Heap Limit Interface 5081** DEPRECATED 5082** 5083** This is a deprecated version of the [sqlite3_soft_heap_limit64()] 5084** interface. This routine is provided for historical compatibility 5085** only. All new applications should use the 5086** [sqlite3_soft_heap_limit64()] interface rather than this one. 5087*/ 5088SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); 5089 5090 5091/* 5092** CAPI3REF: Extract Metadata About A Column Of A Table 5093** 5094** ^This routine returns metadata about a specific column of a specific 5095** database table accessible using the [database connection] handle 5096** passed as the first function argument. 5097** 5098** ^The column is identified by the second, third and fourth parameters to 5099** this function. ^The second parameter is either the name of the database 5100** (i.e. "main", "temp", or an attached database) containing the specified 5101** table or NULL. ^If it is NULL, then all attached databases are searched 5102** for the table using the same algorithm used by the database engine to 5103** resolve unqualified table references. 5104** 5105** ^The third and fourth parameters to this function are the table and column 5106** name of the desired column, respectively. Neither of these parameters 5107** may be NULL. 5108** 5109** ^Metadata is returned by writing to the memory locations passed as the 5th 5110** and subsequent parameters to this function. ^Any of these arguments may be 5111** NULL, in which case the corresponding element of metadata is omitted. 5112** 5113** ^(<blockquote> 5114** <table border="1"> 5115** <tr><th> Parameter <th> Output<br>Type <th> Description 5116** 5117** <tr><td> 5th <td> const char* <td> Data type 5118** <tr><td> 6th <td> const char* <td> Name of default collation sequence 5119** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint 5120** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY 5121** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] 5122** </table> 5123** </blockquote>)^ 5124** 5125** ^The memory pointed to by the character pointers returned for the 5126** declaration type and collation sequence is valid only until the next 5127** call to any SQLite API function. 5128** 5129** ^If the specified table is actually a view, an [error code] is returned. 5130** 5131** ^If the specified column is "rowid", "oid" or "_rowid_" and an 5132** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output 5133** parameters are set for the explicitly declared column. ^(If there is no 5134** explicitly declared [INTEGER PRIMARY KEY] column, then the output 5135** parameters are set as follows: 5136** 5137** <pre> 5138** data type: "INTEGER" 5139** collation sequence: "BINARY" 5140** not null: 0 5141** primary key: 1 5142** auto increment: 0 5143** </pre>)^ 5144** 5145** ^(This function may load one or more schemas from database files. If an 5146** error occurs during this process, or if the requested table or column 5147** cannot be found, an [error code] is returned and an error message left 5148** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^ 5149** 5150** ^This API is only available if the library was compiled with the 5151** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. 5152*/ 5153SQLITE_API int sqlite3_table_column_metadata( 5154 sqlite3 *db, /* Connection handle */ 5155 const char *zDbName, /* Database name or NULL */ 5156 const char *zTableName, /* Table name */ 5157 const char *zColumnName, /* Column name */ 5158 char const **pzDataType, /* OUTPUT: Declared data type */ 5159 char const **pzCollSeq, /* OUTPUT: Collation sequence name */ 5160 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ 5161 int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 5162 int *pAutoinc /* OUTPUT: True if column is auto-increment */ 5163); 5164 5165/* 5166** CAPI3REF: Load An Extension 5167** 5168** ^This interface loads an SQLite extension library from the named file. 5169** 5170** ^The sqlite3_load_extension() interface attempts to load an 5171** SQLite extension library contained in the file zFile. 5172** 5173** ^The entry point is zProc. 5174** ^zProc may be 0, in which case the name of the entry point 5175** defaults to "sqlite3_extension_init". 5176** ^The sqlite3_load_extension() interface returns 5177** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. 5178** ^If an error occurs and pzErrMsg is not 0, then the 5179** [sqlite3_load_extension()] interface shall attempt to 5180** fill *pzErrMsg with error message text stored in memory 5181** obtained from [sqlite3_malloc()]. The calling function 5182** should free this memory by calling [sqlite3_free()]. 5183** 5184** ^Extension loading must be enabled using 5185** [sqlite3_enable_load_extension()] prior to calling this API, 5186** otherwise an error will be returned. 5187** 5188** See also the [load_extension() SQL function]. 5189*/ 5190SQLITE_API int sqlite3_load_extension( 5191 sqlite3 *db, /* Load the extension into this database connection */ 5192 const char *zFile, /* Name of the shared library containing extension */ 5193 const char *zProc, /* Entry point. Derived from zFile if 0 */ 5194 char **pzErrMsg /* Put error message here if not 0 */ 5195); 5196 5197/* 5198** CAPI3REF: Enable Or Disable Extension Loading 5199** 5200** ^So as not to open security holes in older applications that are 5201** unprepared to deal with extension loading, and as a means of disabling 5202** extension loading while evaluating user-entered SQL, the following API 5203** is provided to turn the [sqlite3_load_extension()] mechanism on and off. 5204** 5205** ^Extension loading is off by default. See ticket #1863. 5206** ^Call the sqlite3_enable_load_extension() routine with onoff==1 5207** to turn extension loading on and call it with onoff==0 to turn 5208** it back off again. 5209*/ 5210SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); 5211 5212/* 5213** CAPI3REF: Automatically Load Statically Linked Extensions 5214** 5215** ^This interface causes the xEntryPoint() function to be invoked for 5216** each new [database connection] that is created. The idea here is that 5217** xEntryPoint() is the entry point for a statically linked SQLite extension 5218** that is to be automatically loaded into all new database connections. 5219** 5220** ^(Even though the function prototype shows that xEntryPoint() takes 5221** no arguments and returns void, SQLite invokes xEntryPoint() with three 5222** arguments and expects and integer result as if the signature of the 5223** entry point where as follows: 5224** 5225** <blockquote><pre> 5226** int xEntryPoint( 5227** sqlite3 *db, 5228** const char **pzErrMsg, 5229** const struct sqlite3_api_routines *pThunk 5230** ); 5231** </pre></blockquote>)^ 5232** 5233** If the xEntryPoint routine encounters an error, it should make *pzErrMsg 5234** point to an appropriate error message (obtained from [sqlite3_mprintf()]) 5235** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg 5236** is NULL before calling the xEntryPoint(). ^SQLite will invoke 5237** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any 5238** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], 5239** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. 5240** 5241** ^Calling sqlite3_auto_extension(X) with an entry point X that is already 5242** on the list of automatic extensions is a harmless no-op. ^No entry point 5243** will be called more than once for each database connection that is opened. 5244** 5245** See also: [sqlite3_reset_auto_extension()]. 5246*/ 5247SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void)); 5248 5249/* 5250** CAPI3REF: Reset Automatic Extension Loading 5251** 5252** ^This interface disables all automatic extensions previously 5253** registered using [sqlite3_auto_extension()]. 5254*/ 5255SQLITE_API void sqlite3_reset_auto_extension(void); 5256 5257/* 5258** The interface to the virtual-table mechanism is currently considered 5259** to be experimental. The interface might change in incompatible ways. 5260** If this is a problem for you, do not use the interface at this time. 5261** 5262** When the virtual-table mechanism stabilizes, we will declare the 5263** interface fixed, support it indefinitely, and remove this comment. 5264*/ 5265 5266/* 5267** Structures used by the virtual table interface 5268*/ 5269typedef struct sqlite3_vtab sqlite3_vtab; 5270typedef struct sqlite3_index_info sqlite3_index_info; 5271typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; 5272typedef struct sqlite3_module sqlite3_module; 5273 5274/* 5275** CAPI3REF: Virtual Table Object 5276** KEYWORDS: sqlite3_module {virtual table module} 5277** 5278** This structure, sometimes called a "virtual table module", 5279** defines the implementation of a [virtual tables]. 5280** This structure consists mostly of methods for the module. 5281** 5282** ^A virtual table module is created by filling in a persistent 5283** instance of this structure and passing a pointer to that instance 5284** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. 5285** ^The registration remains valid until it is replaced by a different 5286** module or until the [database connection] closes. The content 5287** of this structure must not change while it is registered with 5288** any database connection. 5289*/ 5290struct sqlite3_module { 5291 int iVersion; 5292 int (*xCreate)(sqlite3*, void *pAux, 5293 int argc, const char *const*argv, 5294 sqlite3_vtab **ppVTab, char**); 5295 int (*xConnect)(sqlite3*, void *pAux, 5296 int argc, const char *const*argv, 5297 sqlite3_vtab **ppVTab, char**); 5298 int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); 5299 int (*xDisconnect)(sqlite3_vtab *pVTab); 5300 int (*xDestroy)(sqlite3_vtab *pVTab); 5301 int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); 5302 int (*xClose)(sqlite3_vtab_cursor*); 5303 int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, 5304 int argc, sqlite3_value **argv); 5305 int (*xNext)(sqlite3_vtab_cursor*); 5306 int (*xEof)(sqlite3_vtab_cursor*); 5307 int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); 5308 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); 5309 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); 5310 int (*xBegin)(sqlite3_vtab *pVTab); 5311 int (*xSync)(sqlite3_vtab *pVTab); 5312 int (*xCommit)(sqlite3_vtab *pVTab); 5313 int (*xRollback)(sqlite3_vtab *pVTab); 5314 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, 5315 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), 5316 void **ppArg); 5317 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); 5318 /* The methods above are in version 1 of the sqlite_module object. Those 5319 ** below are for version 2 and greater. */ 5320 int (*xSavepoint)(sqlite3_vtab *pVTab, int); 5321 int (*xRelease)(sqlite3_vtab *pVTab, int); 5322 int (*xRollbackTo)(sqlite3_vtab *pVTab, int); 5323}; 5324 5325/* 5326** CAPI3REF: Virtual Table Indexing Information 5327** KEYWORDS: sqlite3_index_info 5328** 5329** The sqlite3_index_info structure and its substructures is used as part 5330** of the [virtual table] interface to 5331** pass information into and receive the reply from the [xBestIndex] 5332** method of a [virtual table module]. The fields under **Inputs** are the 5333** inputs to xBestIndex and are read-only. xBestIndex inserts its 5334** results into the **Outputs** fields. 5335** 5336** ^(The aConstraint[] array records WHERE clause constraints of the form: 5337** 5338** <blockquote>column OP expr</blockquote> 5339** 5340** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is 5341** stored in aConstraint[].op using one of the 5342** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ 5343** ^(The index of the column is stored in 5344** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the 5345** expr on the right-hand side can be evaluated (and thus the constraint 5346** is usable) and false if it cannot.)^ 5347** 5348** ^The optimizer automatically inverts terms of the form "expr OP column" 5349** and makes other simplifications to the WHERE clause in an attempt to 5350** get as many WHERE clause terms into the form shown above as possible. 5351** ^The aConstraint[] array only reports WHERE clause terms that are 5352** relevant to the particular virtual table being queried. 5353** 5354** ^Information about the ORDER BY clause is stored in aOrderBy[]. 5355** ^Each term of aOrderBy records a column of the ORDER BY clause. 5356** 5357** The [xBestIndex] method must fill aConstraintUsage[] with information 5358** about what parameters to pass to xFilter. ^If argvIndex>0 then 5359** the right-hand side of the corresponding aConstraint[] is evaluated 5360** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit 5361** is true, then the constraint is assumed to be fully handled by the 5362** virtual table and is not checked again by SQLite.)^ 5363** 5364** ^The idxNum and idxPtr values are recorded and passed into the 5365** [xFilter] method. 5366** ^[sqlite3_free()] is used to free idxPtr if and only if 5367** needToFreeIdxPtr is true. 5368** 5369** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in 5370** the correct order to satisfy the ORDER BY clause so that no separate 5371** sorting step is required. 5372** 5373** ^The estimatedCost value is an estimate of the cost of doing the 5374** particular lookup. A full scan of a table with N entries should have 5375** a cost of N. A binary search of a table of N entries should have a 5376** cost of approximately log(N). 5377*/ 5378struct sqlite3_index_info { 5379 /* Inputs */ 5380 int nConstraint; /* Number of entries in aConstraint */ 5381 struct sqlite3_index_constraint { 5382 int iColumn; /* Column on left-hand side of constraint */ 5383 unsigned char op; /* Constraint operator */ 5384 unsigned char usable; /* True if this constraint is usable */ 5385 int iTermOffset; /* Used internally - xBestIndex should ignore */ 5386 } *aConstraint; /* Table of WHERE clause constraints */ 5387 int nOrderBy; /* Number of terms in the ORDER BY clause */ 5388 struct sqlite3_index_orderby { 5389 int iColumn; /* Column number */ 5390 unsigned char desc; /* True for DESC. False for ASC. */ 5391 } *aOrderBy; /* The ORDER BY clause */ 5392 /* Outputs */ 5393 struct sqlite3_index_constraint_usage { 5394 int argvIndex; /* if >0, constraint is part of argv to xFilter */ 5395 unsigned char omit; /* Do not code a test for this constraint */ 5396 } *aConstraintUsage; 5397 int idxNum; /* Number used to identify the index */ 5398 char *idxStr; /* String, possibly obtained from sqlite3_malloc */ 5399 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 5400 int orderByConsumed; /* True if output is already ordered */ 5401 double estimatedCost; /* Estimated cost of using this index */ 5402}; 5403 5404/* 5405** CAPI3REF: Virtual Table Constraint Operator Codes 5406** 5407** These macros defined the allowed values for the 5408** [sqlite3_index_info].aConstraint[].op field. Each value represents 5409** an operator that is part of a constraint term in the wHERE clause of 5410** a query that uses a [virtual table]. 5411*/ 5412#define SQLITE_INDEX_CONSTRAINT_EQ 2 5413#define SQLITE_INDEX_CONSTRAINT_GT 4 5414#define SQLITE_INDEX_CONSTRAINT_LE 8 5415#define SQLITE_INDEX_CONSTRAINT_LT 16 5416#define SQLITE_INDEX_CONSTRAINT_GE 32 5417#define SQLITE_INDEX_CONSTRAINT_MATCH 64 5418 5419/* 5420** CAPI3REF: Register A Virtual Table Implementation 5421** 5422** ^These routines are used to register a new [virtual table module] name. 5423** ^Module names must be registered before 5424** creating a new [virtual table] using the module and before using a 5425** preexisting [virtual table] for the module. 5426** 5427** ^The module name is registered on the [database connection] specified 5428** by the first parameter. ^The name of the module is given by the 5429** second parameter. ^The third parameter is a pointer to 5430** the implementation of the [virtual table module]. ^The fourth 5431** parameter is an arbitrary client data pointer that is passed through 5432** into the [xCreate] and [xConnect] methods of the virtual table module 5433** when a new virtual table is be being created or reinitialized. 5434** 5435** ^The sqlite3_create_module_v2() interface has a fifth parameter which 5436** is a pointer to a destructor for the pClientData. ^SQLite will 5437** invoke the destructor function (if it is not NULL) when SQLite 5438** no longer needs the pClientData pointer. ^The destructor will also 5439** be invoked if the call to sqlite3_create_module_v2() fails. 5440** ^The sqlite3_create_module() 5441** interface is equivalent to sqlite3_create_module_v2() with a NULL 5442** destructor. 5443*/ 5444SQLITE_API int sqlite3_create_module( 5445 sqlite3 *db, /* SQLite connection to register module with */ 5446 const char *zName, /* Name of the module */ 5447 const sqlite3_module *p, /* Methods for the module */ 5448 void *pClientData /* Client data for xCreate/xConnect */ 5449); 5450SQLITE_API int sqlite3_create_module_v2( 5451 sqlite3 *db, /* SQLite connection to register module with */ 5452 const char *zName, /* Name of the module */ 5453 const sqlite3_module *p, /* Methods for the module */ 5454 void *pClientData, /* Client data for xCreate/xConnect */ 5455 void(*xDestroy)(void*) /* Module destructor function */ 5456); 5457 5458/* 5459** CAPI3REF: Virtual Table Instance Object 5460** KEYWORDS: sqlite3_vtab 5461** 5462** Every [virtual table module] implementation uses a subclass 5463** of this object to describe a particular instance 5464** of the [virtual table]. Each subclass will 5465** be tailored to the specific needs of the module implementation. 5466** The purpose of this superclass is to define certain fields that are 5467** common to all module implementations. 5468** 5469** ^Virtual tables methods can set an error message by assigning a 5470** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should 5471** take care that any prior string is freed by a call to [sqlite3_free()] 5472** prior to assigning a new string to zErrMsg. ^After the error message 5473** is delivered up to the client application, the string will be automatically 5474** freed by sqlite3_free() and the zErrMsg field will be zeroed. 5475*/ 5476struct sqlite3_vtab { 5477 const sqlite3_module *pModule; /* The module for this virtual table */ 5478 int nRef; /* NO LONGER USED */ 5479 char *zErrMsg; /* Error message from sqlite3_mprintf() */ 5480 /* Virtual table implementations will typically add additional fields */ 5481}; 5482 5483/* 5484** CAPI3REF: Virtual Table Cursor Object 5485** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} 5486** 5487** Every [virtual table module] implementation uses a subclass of the 5488** following structure to describe cursors that point into the 5489** [virtual table] and are used 5490** to loop through the virtual table. Cursors are created using the 5491** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed 5492** by the [sqlite3_module.xClose | xClose] method. Cursors are used 5493** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods 5494** of the module. Each module implementation will define 5495** the content of a cursor structure to suit its own needs. 5496** 5497** This superclass exists in order to define fields of the cursor that 5498** are common to all implementations. 5499*/ 5500struct sqlite3_vtab_cursor { 5501 sqlite3_vtab *pVtab; /* Virtual table of this cursor */ 5502 /* Virtual table implementations will typically add additional fields */ 5503}; 5504 5505/* 5506** CAPI3REF: Declare The Schema Of A Virtual Table 5507** 5508** ^The [xCreate] and [xConnect] methods of a 5509** [virtual table module] call this interface 5510** to declare the format (the names and datatypes of the columns) of 5511** the virtual tables they implement. 5512*/ 5513SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); 5514 5515/* 5516** CAPI3REF: Overload A Function For A Virtual Table 5517** 5518** ^(Virtual tables can provide alternative implementations of functions 5519** using the [xFindFunction] method of the [virtual table module]. 5520** But global versions of those functions 5521** must exist in order to be overloaded.)^ 5522** 5523** ^(This API makes sure a global version of a function with a particular 5524** name and number of parameters exists. If no such function exists 5525** before this API is called, a new function is created.)^ ^The implementation 5526** of the new function always causes an exception to be thrown. So 5527** the new function is not good for anything by itself. Its only 5528** purpose is to be a placeholder function that can be overloaded 5529** by a [virtual table]. 5530*/ 5531SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); 5532 5533/* 5534** The interface to the virtual-table mechanism defined above (back up 5535** to a comment remarkably similar to this one) is currently considered 5536** to be experimental. The interface might change in incompatible ways. 5537** If this is a problem for you, do not use the interface at this time. 5538** 5539** When the virtual-table mechanism stabilizes, we will declare the 5540** interface fixed, support it indefinitely, and remove this comment. 5541*/ 5542 5543/* 5544** CAPI3REF: A Handle To An Open BLOB 5545** KEYWORDS: {BLOB handle} {BLOB handles} 5546** 5547** An instance of this object represents an open BLOB on which 5548** [sqlite3_blob_open | incremental BLOB I/O] can be performed. 5549** ^Objects of this type are created by [sqlite3_blob_open()] 5550** and destroyed by [sqlite3_blob_close()]. 5551** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces 5552** can be used to read or write small subsections of the BLOB. 5553** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. 5554*/ 5555typedef struct sqlite3_blob sqlite3_blob; 5556 5557/* 5558** CAPI3REF: Open A BLOB For Incremental I/O 5559** 5560** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located 5561** in row iRow, column zColumn, table zTable in database zDb; 5562** in other words, the same BLOB that would be selected by: 5563** 5564** <pre> 5565** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; 5566** </pre>)^ 5567** 5568** ^If the flags parameter is non-zero, then the BLOB is opened for read 5569** and write access. ^If it is zero, the BLOB is opened for read access. 5570** ^It is not possible to open a column that is part of an index or primary 5571** key for writing. ^If [foreign key constraints] are enabled, it is 5572** not possible to open a column that is part of a [child key] for writing. 5573** 5574** ^Note that the database name is not the filename that contains 5575** the database but rather the symbolic name of the database that 5576** appears after the AS keyword when the database is connected using [ATTACH]. 5577** ^For the main database file, the database name is "main". 5578** ^For TEMP tables, the database name is "temp". 5579** 5580** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written 5581** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set 5582** to be a null pointer.)^ 5583** ^This function sets the [database connection] error code and message 5584** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related 5585** functions. ^Note that the *ppBlob variable is always initialized in a 5586** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob 5587** regardless of the success or failure of this routine. 5588** 5589** ^(If the row that a BLOB handle points to is modified by an 5590** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects 5591** then the BLOB handle is marked as "expired". 5592** This is true if any column of the row is changed, even a column 5593** other than the one the BLOB handle is open on.)^ 5594** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for 5595** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. 5596** ^(Changes written into a BLOB prior to the BLOB expiring are not 5597** rolled back by the expiration of the BLOB. Such changes will eventually 5598** commit if the transaction continues to completion.)^ 5599** 5600** ^Use the [sqlite3_blob_bytes()] interface to determine the size of 5601** the opened blob. ^The size of a blob may not be changed by this 5602** interface. Use the [UPDATE] SQL command to change the size of a 5603** blob. 5604** 5605** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces 5606** and the built-in [zeroblob] SQL function can be used, if desired, 5607** to create an empty, zero-filled blob in which to read or write using 5608** this interface. 5609** 5610** To avoid a resource leak, every open [BLOB handle] should eventually 5611** be released by a call to [sqlite3_blob_close()]. 5612*/ 5613SQLITE_API int sqlite3_blob_open( 5614 sqlite3*, 5615 const char *zDb, 5616 const char *zTable, 5617 const char *zColumn, 5618 sqlite3_int64 iRow, 5619 int flags, 5620 sqlite3_blob **ppBlob 5621); 5622 5623/* 5624** CAPI3REF: Move a BLOB Handle to a New Row 5625** 5626** ^This function is used to move an existing blob handle so that it points 5627** to a different row of the same database table. ^The new row is identified 5628** by the rowid value passed as the second argument. Only the row can be 5629** changed. ^The database, table and column on which the blob handle is open 5630** remain the same. Moving an existing blob handle to a new row can be 5631** faster than closing the existing handle and opening a new one. 5632** 5633** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - 5634** it must exist and there must be either a blob or text value stored in 5635** the nominated column.)^ ^If the new row is not present in the table, or if 5636** it does not contain a blob or text value, or if another error occurs, an 5637** SQLite error code is returned and the blob handle is considered aborted. 5638** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or 5639** [sqlite3_blob_reopen()] on an aborted blob handle immediately return 5640** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle 5641** always returns zero. 5642** 5643** ^This function sets the database handle error code and message. 5644*/ 5645SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); 5646 5647/* 5648** CAPI3REF: Close A BLOB Handle 5649** 5650** ^Closes an open [BLOB handle]. 5651** 5652** ^Closing a BLOB shall cause the current transaction to commit 5653** if there are no other BLOBs, no pending prepared statements, and the 5654** database connection is in [autocommit mode]. 5655** ^If any writes were made to the BLOB, they might be held in cache 5656** until the close operation if they will fit. 5657** 5658** ^(Closing the BLOB often forces the changes 5659** out to disk and so if any I/O errors occur, they will likely occur 5660** at the time when the BLOB is closed. Any errors that occur during 5661** closing are reported as a non-zero return value.)^ 5662** 5663** ^(The BLOB is closed unconditionally. Even if this routine returns 5664** an error code, the BLOB is still closed.)^ 5665** 5666** ^Calling this routine with a null pointer (such as would be returned 5667** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. 5668*/ 5669SQLITE_API int sqlite3_blob_close(sqlite3_blob *); 5670 5671/* 5672** CAPI3REF: Return The Size Of An Open BLOB 5673** 5674** ^Returns the size in bytes of the BLOB accessible via the 5675** successfully opened [BLOB handle] in its only argument. ^The 5676** incremental blob I/O routines can only read or overwriting existing 5677** blob content; they cannot change the size of a blob. 5678** 5679** This routine only works on a [BLOB handle] which has been created 5680** by a prior successful call to [sqlite3_blob_open()] and which has not 5681** been closed by [sqlite3_blob_close()]. Passing any other pointer in 5682** to this routine results in undefined and probably undesirable behavior. 5683*/ 5684SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); 5685 5686/* 5687** CAPI3REF: Read Data From A BLOB Incrementally 5688** 5689** ^(This function is used to read data from an open [BLOB handle] into a 5690** caller-supplied buffer. N bytes of data are copied into buffer Z 5691** from the open BLOB, starting at offset iOffset.)^ 5692** 5693** ^If offset iOffset is less than N bytes from the end of the BLOB, 5694** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is 5695** less than zero, [SQLITE_ERROR] is returned and no data is read. 5696** ^The size of the blob (and hence the maximum value of N+iOffset) 5697** can be determined using the [sqlite3_blob_bytes()] interface. 5698** 5699** ^An attempt to read from an expired [BLOB handle] fails with an 5700** error code of [SQLITE_ABORT]. 5701** 5702** ^(On success, sqlite3_blob_read() returns SQLITE_OK. 5703** Otherwise, an [error code] or an [extended error code] is returned.)^ 5704** 5705** This routine only works on a [BLOB handle] which has been created 5706** by a prior successful call to [sqlite3_blob_open()] and which has not 5707** been closed by [sqlite3_blob_close()]. Passing any other pointer in 5708** to this routine results in undefined and probably undesirable behavior. 5709** 5710** See also: [sqlite3_blob_write()]. 5711*/ 5712SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); 5713 5714/* 5715** CAPI3REF: Write Data Into A BLOB Incrementally 5716** 5717** ^This function is used to write data into an open [BLOB handle] from a 5718** caller-supplied buffer. ^N bytes of data are copied from the buffer Z 5719** into the open BLOB, starting at offset iOffset. 5720** 5721** ^If the [BLOB handle] passed as the first argument was not opened for 5722** writing (the flags parameter to [sqlite3_blob_open()] was zero), 5723** this function returns [SQLITE_READONLY]. 5724** 5725** ^This function may only modify the contents of the BLOB; it is 5726** not possible to increase the size of a BLOB using this API. 5727** ^If offset iOffset is less than N bytes from the end of the BLOB, 5728** [SQLITE_ERROR] is returned and no data is written. ^If N is 5729** less than zero [SQLITE_ERROR] is returned and no data is written. 5730** The size of the BLOB (and hence the maximum value of N+iOffset) 5731** can be determined using the [sqlite3_blob_bytes()] interface. 5732** 5733** ^An attempt to write to an expired [BLOB handle] fails with an 5734** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred 5735** before the [BLOB handle] expired are not rolled back by the 5736** expiration of the handle, though of course those changes might 5737** have been overwritten by the statement that expired the BLOB handle 5738** or by other independent statements. 5739** 5740** ^(On success, sqlite3_blob_write() returns SQLITE_OK. 5741** Otherwise, an [error code] or an [extended error code] is returned.)^ 5742** 5743** This routine only works on a [BLOB handle] which has been created 5744** by a prior successful call to [sqlite3_blob_open()] and which has not 5745** been closed by [sqlite3_blob_close()]. Passing any other pointer in 5746** to this routine results in undefined and probably undesirable behavior. 5747** 5748** See also: [sqlite3_blob_read()]. 5749*/ 5750SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); 5751 5752/* 5753** CAPI3REF: Virtual File System Objects 5754** 5755** A virtual filesystem (VFS) is an [sqlite3_vfs] object 5756** that SQLite uses to interact 5757** with the underlying operating system. Most SQLite builds come with a 5758** single default VFS that is appropriate for the host computer. 5759** New VFSes can be registered and existing VFSes can be unregistered. 5760** The following interfaces are provided. 5761** 5762** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. 5763** ^Names are case sensitive. 5764** ^Names are zero-terminated UTF-8 strings. 5765** ^If there is no match, a NULL pointer is returned. 5766** ^If zVfsName is NULL then the default VFS is returned. 5767** 5768** ^New VFSes are registered with sqlite3_vfs_register(). 5769** ^Each new VFS becomes the default VFS if the makeDflt flag is set. 5770** ^The same VFS can be registered multiple times without injury. 5771** ^To make an existing VFS into the default VFS, register it again 5772** with the makeDflt flag set. If two different VFSes with the 5773** same name are registered, the behavior is undefined. If a 5774** VFS is registered with a name that is NULL or an empty string, 5775** then the behavior is undefined. 5776** 5777** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. 5778** ^(If the default VFS is unregistered, another VFS is chosen as 5779** the default. The choice for the new VFS is arbitrary.)^ 5780*/ 5781SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); 5782SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); 5783SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); 5784 5785/* 5786** CAPI3REF: Mutexes 5787** 5788** The SQLite core uses these routines for thread 5789** synchronization. Though they are intended for internal 5790** use by SQLite, code that links against SQLite is 5791** permitted to use any of these routines. 5792** 5793** The SQLite source code contains multiple implementations 5794** of these mutex routines. An appropriate implementation 5795** is selected automatically at compile-time. ^(The following 5796** implementations are available in the SQLite core: 5797** 5798** <ul> 5799** <li> SQLITE_MUTEX_OS2 5800** <li> SQLITE_MUTEX_PTHREAD 5801** <li> SQLITE_MUTEX_W32 5802** <li> SQLITE_MUTEX_NOOP 5803** </ul>)^ 5804** 5805** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 5806** that does no real locking and is appropriate for use in 5807** a single-threaded application. ^The SQLITE_MUTEX_OS2, 5808** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations 5809** are appropriate for use on OS/2, Unix, and Windows. 5810** 5811** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 5812** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 5813** implementation is included with the library. In this case the 5814** application must supply a custom mutex implementation using the 5815** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function 5816** before calling sqlite3_initialize() or any other public sqlite3_ 5817** function that calls sqlite3_initialize().)^ 5818** 5819** ^The sqlite3_mutex_alloc() routine allocates a new 5820** mutex and returns a pointer to it. ^If it returns NULL 5821** that means that a mutex could not be allocated. ^SQLite 5822** will unwind its stack and return an error. ^(The argument 5823** to sqlite3_mutex_alloc() is one of these integer constants: 5824** 5825** <ul> 5826** <li> SQLITE_MUTEX_FAST 5827** <li> SQLITE_MUTEX_RECURSIVE 5828** <li> SQLITE_MUTEX_STATIC_MASTER 5829** <li> SQLITE_MUTEX_STATIC_MEM 5830** <li> SQLITE_MUTEX_STATIC_MEM2 5831** <li> SQLITE_MUTEX_STATIC_PRNG 5832** <li> SQLITE_MUTEX_STATIC_LRU 5833** <li> SQLITE_MUTEX_STATIC_LRU2 5834** </ul>)^ 5835** 5836** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) 5837** cause sqlite3_mutex_alloc() to create 5838** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 5839** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 5840** The mutex implementation does not need to make a distinction 5841** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 5842** not want to. ^SQLite will only request a recursive mutex in 5843** cases where it really needs one. ^If a faster non-recursive mutex 5844** implementation is available on the host platform, the mutex subsystem 5845** might return such a mutex in response to SQLITE_MUTEX_FAST. 5846** 5847** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other 5848** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return 5849** a pointer to a static preexisting mutex. ^Six static mutexes are 5850** used by the current version of SQLite. Future versions of SQLite 5851** may add additional static mutexes. Static mutexes are for internal 5852** use by SQLite only. Applications that use SQLite mutexes should 5853** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or 5854** SQLITE_MUTEX_RECURSIVE. 5855** 5856** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST 5857** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() 5858** returns a different mutex on every call. ^But for the static 5859** mutex types, the same mutex is returned on every call that has 5860** the same type number. 5861** 5862** ^The sqlite3_mutex_free() routine deallocates a previously 5863** allocated dynamic mutex. ^SQLite is careful to deallocate every 5864** dynamic mutex that it allocates. The dynamic mutexes must not be in 5865** use when they are deallocated. Attempting to deallocate a static 5866** mutex results in undefined behavior. ^SQLite never deallocates 5867** a static mutex. 5868** 5869** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 5870** to enter a mutex. ^If another thread is already within the mutex, 5871** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 5872** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] 5873** upon successful entry. ^(Mutexes created using 5874** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. 5875** In such cases the, 5876** mutex must be exited an equal number of times before another thread 5877** can enter.)^ ^(If the same thread tries to enter any other 5878** kind of mutex more than once, the behavior is undefined. 5879** SQLite will never exhibit 5880** such behavior in its own use of mutexes.)^ 5881** 5882** ^(Some systems (for example, Windows 95) do not support the operation 5883** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() 5884** will always return SQLITE_BUSY. The SQLite core only ever uses 5885** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^ 5886** 5887** ^The sqlite3_mutex_leave() routine exits a mutex that was 5888** previously entered by the same thread. ^(The behavior 5889** is undefined if the mutex is not currently entered by the 5890** calling thread or is not currently allocated. SQLite will 5891** never do either.)^ 5892** 5893** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or 5894** sqlite3_mutex_leave() is a NULL pointer, then all three routines 5895** behave as no-ops. 5896** 5897** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. 5898*/ 5899SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); 5900SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); 5901SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); 5902SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); 5903SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); 5904 5905/* 5906** CAPI3REF: Mutex Methods Object 5907** 5908** An instance of this structure defines the low-level routines 5909** used to allocate and use mutexes. 5910** 5911** Usually, the default mutex implementations provided by SQLite are 5912** sufficient, however the user has the option of substituting a custom 5913** implementation for specialized deployments or systems for which SQLite 5914** does not provide a suitable implementation. In this case, the user 5915** creates and populates an instance of this structure to pass 5916** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. 5917** Additionally, an instance of this structure can be used as an 5918** output variable when querying the system for the current mutex 5919** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. 5920** 5921** ^The xMutexInit method defined by this structure is invoked as 5922** part of system initialization by the sqlite3_initialize() function. 5923** ^The xMutexInit routine is called by SQLite exactly once for each 5924** effective call to [sqlite3_initialize()]. 5925** 5926** ^The xMutexEnd method defined by this structure is invoked as 5927** part of system shutdown by the sqlite3_shutdown() function. The 5928** implementation of this method is expected to release all outstanding 5929** resources obtained by the mutex methods implementation, especially 5930** those obtained by the xMutexInit method. ^The xMutexEnd() 5931** interface is invoked exactly once for each call to [sqlite3_shutdown()]. 5932** 5933** ^(The remaining seven methods defined by this structure (xMutexAlloc, 5934** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and 5935** xMutexNotheld) implement the following interfaces (respectively): 5936** 5937** <ul> 5938** <li> [sqlite3_mutex_alloc()] </li> 5939** <li> [sqlite3_mutex_free()] </li> 5940** <li> [sqlite3_mutex_enter()] </li> 5941** <li> [sqlite3_mutex_try()] </li> 5942** <li> [sqlite3_mutex_leave()] </li> 5943** <li> [sqlite3_mutex_held()] </li> 5944** <li> [sqlite3_mutex_notheld()] </li> 5945** </ul>)^ 5946** 5947** The only difference is that the public sqlite3_XXX functions enumerated 5948** above silently ignore any invocations that pass a NULL pointer instead 5949** of a valid mutex handle. The implementations of the methods defined 5950** by this structure are not required to handle this case, the results 5951** of passing a NULL pointer instead of a valid mutex handle are undefined 5952** (i.e. it is acceptable to provide an implementation that segfaults if 5953** it is passed a NULL pointer). 5954** 5955** The xMutexInit() method must be threadsafe. ^It must be harmless to 5956** invoke xMutexInit() multiple times within the same process and without 5957** intervening calls to xMutexEnd(). Second and subsequent calls to 5958** xMutexInit() must be no-ops. 5959** 5960** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] 5961** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory 5962** allocation for a static mutex. ^However xMutexAlloc() may use SQLite 5963** memory allocation for a fast or recursive mutex. 5964** 5965** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is 5966** called, but only if the prior call to xMutexInit returned SQLITE_OK. 5967** If xMutexInit fails in any way, it is expected to clean up after itself 5968** prior to returning. 5969*/ 5970typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; 5971struct sqlite3_mutex_methods { 5972 int (*xMutexInit)(void); 5973 int (*xMutexEnd)(void); 5974 sqlite3_mutex *(*xMutexAlloc)(int); 5975 void (*xMutexFree)(sqlite3_mutex *); 5976 void (*xMutexEnter)(sqlite3_mutex *); 5977 int (*xMutexTry)(sqlite3_mutex *); 5978 void (*xMutexLeave)(sqlite3_mutex *); 5979 int (*xMutexHeld)(sqlite3_mutex *); 5980 int (*xMutexNotheld)(sqlite3_mutex *); 5981}; 5982 5983/* 5984** CAPI3REF: Mutex Verification Routines 5985** 5986** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines 5987** are intended for use inside assert() statements. ^The SQLite core 5988** never uses these routines except inside an assert() and applications 5989** are advised to follow the lead of the core. ^The SQLite core only 5990** provides implementations for these routines when it is compiled 5991** with the SQLITE_DEBUG flag. ^External mutex implementations 5992** are only required to provide these routines if SQLITE_DEBUG is 5993** defined and if NDEBUG is not defined. 5994** 5995** ^These routines should return true if the mutex in their argument 5996** is held or not held, respectively, by the calling thread. 5997** 5998** ^The implementation is not required to provided versions of these 5999** routines that actually work. If the implementation does not provide working 6000** versions of these routines, it should at least provide stubs that always 6001** return true so that one does not get spurious assertion failures. 6002** 6003** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 6004** the routine should return 1. This seems counter-intuitive since 6005** clearly the mutex cannot be held if it does not exist. But 6006** the reason the mutex does not exist is because the build is not 6007** using mutexes. And we do not want the assert() containing the 6008** call to sqlite3_mutex_held() to fail, so a non-zero return is 6009** the appropriate thing to do. ^The sqlite3_mutex_notheld() 6010** interface should also return 1 when given a NULL pointer. 6011*/ 6012#ifndef NDEBUG 6013SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); 6014SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); 6015#endif 6016 6017/* 6018** CAPI3REF: Mutex Types 6019** 6020** The [sqlite3_mutex_alloc()] interface takes a single argument 6021** which is one of these integer constants. 6022** 6023** The set of static mutexes may change from one SQLite release to the 6024** next. Applications that override the built-in mutex logic must be 6025** prepared to accommodate additional static mutexes. 6026*/ 6027#define SQLITE_MUTEX_FAST 0 6028#define SQLITE_MUTEX_RECURSIVE 1 6029#define SQLITE_MUTEX_STATIC_MASTER 2 6030#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ 6031#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ 6032#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ 6033#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ 6034#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ 6035#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ 6036#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ 6037 6038/* 6039** CAPI3REF: Retrieve the mutex for a database connection 6040** 6041** ^This interface returns a pointer the [sqlite3_mutex] object that 6042** serializes access to the [database connection] given in the argument 6043** when the [threading mode] is Serialized. 6044** ^If the [threading mode] is Single-thread or Multi-thread then this 6045** routine returns a NULL pointer. 6046*/ 6047SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); 6048 6049/* 6050** CAPI3REF: Low-Level Control Of Database Files 6051** 6052** ^The [sqlite3_file_control()] interface makes a direct call to the 6053** xFileControl method for the [sqlite3_io_methods] object associated 6054** with a particular database identified by the second argument. ^The 6055** name of the database is "main" for the main database or "temp" for the 6056** TEMP database, or the name that appears after the AS keyword for 6057** databases that are added using the [ATTACH] SQL command. 6058** ^A NULL pointer can be used in place of "main" to refer to the 6059** main database file. 6060** ^The third and fourth parameters to this routine 6061** are passed directly through to the second and third parameters of 6062** the xFileControl method. ^The return value of the xFileControl 6063** method becomes the return value of this routine. 6064** 6065** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes 6066** a pointer to the underlying [sqlite3_file] object to be written into 6067** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER 6068** case is a short-circuit path which does not actually invoke the 6069** underlying sqlite3_io_methods.xFileControl method. 6070** 6071** ^If the second parameter (zDbName) does not match the name of any 6072** open database file, then SQLITE_ERROR is returned. ^This error 6073** code is not remembered and will not be recalled by [sqlite3_errcode()] 6074** or [sqlite3_errmsg()]. The underlying xFileControl method might 6075** also return SQLITE_ERROR. There is no way to distinguish between 6076** an incorrect zDbName and an SQLITE_ERROR return from the underlying 6077** xFileControl method. 6078** 6079** See also: [SQLITE_FCNTL_LOCKSTATE] 6080*/ 6081SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); 6082 6083/* 6084** CAPI3REF: Testing Interface 6085** 6086** ^The sqlite3_test_control() interface is used to read out internal 6087** state of SQLite and to inject faults into SQLite for testing 6088** purposes. ^The first parameter is an operation code that determines 6089** the number, meaning, and operation of all subsequent parameters. 6090** 6091** This interface is not for use by applications. It exists solely 6092** for verifying the correct operation of the SQLite library. Depending 6093** on how the SQLite library is compiled, this interface might not exist. 6094** 6095** The details of the operation codes, their meanings, the parameters 6096** they take, and what they do are all subject to change without notice. 6097** Unlike most of the SQLite API, this function is not guaranteed to 6098** operate consistently from one release to the next. 6099*/ 6100SQLITE_API int sqlite3_test_control(int op, ...); 6101 6102/* 6103** CAPI3REF: Testing Interface Operation Codes 6104** 6105** These constants are the valid operation code parameters used 6106** as the first argument to [sqlite3_test_control()]. 6107** 6108** These parameters and their meanings are subject to change 6109** without notice. These values are for testing purposes only. 6110** Applications should not use any of these parameters or the 6111** [sqlite3_test_control()] interface. 6112*/ 6113#define SQLITE_TESTCTRL_FIRST 5 6114#define SQLITE_TESTCTRL_PRNG_SAVE 5 6115#define SQLITE_TESTCTRL_PRNG_RESTORE 6 6116#define SQLITE_TESTCTRL_PRNG_RESET 7 6117#define SQLITE_TESTCTRL_BITVEC_TEST 8 6118#define SQLITE_TESTCTRL_FAULT_INSTALL 9 6119#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 6120#define SQLITE_TESTCTRL_PENDING_BYTE 11 6121#define SQLITE_TESTCTRL_ASSERT 12 6122#define SQLITE_TESTCTRL_ALWAYS 13 6123#define SQLITE_TESTCTRL_RESERVE 14 6124#define SQLITE_TESTCTRL_OPTIMIZATIONS 15 6125#define SQLITE_TESTCTRL_ISKEYWORD 16 6126#define SQLITE_TESTCTRL_PGHDRSZ 17 6127#define SQLITE_TESTCTRL_SCRATCHMALLOC 18 6128#define SQLITE_TESTCTRL_LOCALTIME_FAULT 19 6129#define SQLITE_TESTCTRL_LAST 19 6130 6131/* 6132** CAPI3REF: SQLite Runtime Status 6133** 6134** ^This interface is used to retrieve runtime status information 6135** about the performance of SQLite, and optionally to reset various 6136** highwater marks. ^The first argument is an integer code for 6137** the specific parameter to measure. ^(Recognized integer codes 6138** are of the form [status parameters | SQLITE_STATUS_...].)^ 6139** ^The current value of the parameter is returned into *pCurrent. 6140** ^The highest recorded value is returned in *pHighwater. ^If the 6141** resetFlag is true, then the highest record value is reset after 6142** *pHighwater is written. ^(Some parameters do not record the highest 6143** value. For those parameters 6144** nothing is written into *pHighwater and the resetFlag is ignored.)^ 6145** ^(Other parameters record only the highwater mark and not the current 6146** value. For these latter parameters nothing is written into *pCurrent.)^ 6147** 6148** ^The sqlite3_status() routine returns SQLITE_OK on success and a 6149** non-zero [error code] on failure. 6150** 6151** This routine is threadsafe but is not atomic. This routine can be 6152** called while other threads are running the same or different SQLite 6153** interfaces. However the values returned in *pCurrent and 6154** *pHighwater reflect the status of SQLite at different points in time 6155** and it is possible that another thread might change the parameter 6156** in between the times when *pCurrent and *pHighwater are written. 6157** 6158** See also: [sqlite3_db_status()] 6159*/ 6160SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); 6161 6162 6163/* 6164** CAPI3REF: Status Parameters 6165** KEYWORDS: {status parameters} 6166** 6167** These integer constants designate various run-time status parameters 6168** that can be returned by [sqlite3_status()]. 6169** 6170** <dl> 6171** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> 6172** <dd>This parameter is the current amount of memory checked out 6173** using [sqlite3_malloc()], either directly or indirectly. The 6174** figure includes calls made to [sqlite3_malloc()] by the application 6175** and internal memory usage by the SQLite library. Scratch memory 6176** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache 6177** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in 6178** this parameter. The amount returned is the sum of the allocation 6179** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ 6180** 6181** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> 6182** <dd>This parameter records the largest memory allocation request 6183** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their 6184** internal equivalents). Only the value returned in the 6185** *pHighwater parameter to [sqlite3_status()] is of interest. 6186** The value written into the *pCurrent parameter is undefined.</dd>)^ 6187** 6188** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> 6189** <dd>This parameter records the number of separate memory allocations 6190** currently checked out.</dd>)^ 6191** 6192** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> 6193** <dd>This parameter returns the number of pages used out of the 6194** [pagecache memory allocator] that was configured using 6195** [SQLITE_CONFIG_PAGECACHE]. The 6196** value returned is in pages, not in bytes.</dd>)^ 6197** 6198** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] 6199** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> 6200** <dd>This parameter returns the number of bytes of page cache 6201** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] 6202** buffer and where forced to overflow to [sqlite3_malloc()]. The 6203** returned value includes allocations that overflowed because they 6204** where too large (they were larger than the "sz" parameter to 6205** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because 6206** no space was left in the page cache.</dd>)^ 6207** 6208** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> 6209** <dd>This parameter records the largest memory allocation request 6210** handed to [pagecache memory allocator]. Only the value returned in the 6211** *pHighwater parameter to [sqlite3_status()] is of interest. 6212** The value written into the *pCurrent parameter is undefined.</dd>)^ 6213** 6214** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> 6215** <dd>This parameter returns the number of allocations used out of the 6216** [scratch memory allocator] configured using 6217** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not 6218** in bytes. Since a single thread may only have one scratch allocation 6219** outstanding at time, this parameter also reports the number of threads 6220** using scratch memory at the same time.</dd>)^ 6221** 6222** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> 6223** <dd>This parameter returns the number of bytes of scratch memory 6224** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] 6225** buffer and where forced to overflow to [sqlite3_malloc()]. The values 6226** returned include overflows because the requested allocation was too 6227** larger (that is, because the requested allocation was larger than the 6228** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer 6229** slots were available. 6230** </dd>)^ 6231** 6232** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 6233** <dd>This parameter records the largest memory allocation request 6234** handed to [scratch memory allocator]. Only the value returned in the 6235** *pHighwater parameter to [sqlite3_status()] is of interest. 6236** The value written into the *pCurrent parameter is undefined.</dd>)^ 6237** 6238** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 6239** <dd>This parameter records the deepest parser stack. It is only 6240** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 6241** </dl> 6242** 6243** New status parameters may be added from time to time. 6244*/ 6245#define SQLITE_STATUS_MEMORY_USED 0 6246#define SQLITE_STATUS_PAGECACHE_USED 1 6247#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 6248#define SQLITE_STATUS_SCRATCH_USED 3 6249#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 6250#define SQLITE_STATUS_MALLOC_SIZE 5 6251#define SQLITE_STATUS_PARSER_STACK 6 6252#define SQLITE_STATUS_PAGECACHE_SIZE 7 6253#define SQLITE_STATUS_SCRATCH_SIZE 8 6254#define SQLITE_STATUS_MALLOC_COUNT 9 6255 6256/* 6257** CAPI3REF: Database Connection Status 6258** 6259** ^This interface is used to retrieve runtime status information 6260** about a single [database connection]. ^The first argument is the 6261** database connection object to be interrogated. ^The second argument 6262** is an integer constant, taken from the set of 6263** [SQLITE_DBSTATUS options], that 6264** determines the parameter to interrogate. The set of 6265** [SQLITE_DBSTATUS options] is likely 6266** to grow in future releases of SQLite. 6267** 6268** ^The current value of the requested parameter is written into *pCur 6269** and the highest instantaneous value is written into *pHiwtr. ^If 6270** the resetFlg is true, then the highest instantaneous value is 6271** reset back down to the current value. 6272** 6273** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a 6274** non-zero [error code] on failure. 6275** 6276** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. 6277*/ 6278SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); 6279 6280/* 6281** CAPI3REF: Status Parameters for database connections 6282** KEYWORDS: {SQLITE_DBSTATUS options} 6283** 6284** These constants are the available integer "verbs" that can be passed as 6285** the second argument to the [sqlite3_db_status()] interface. 6286** 6287** New verbs may be added in future releases of SQLite. Existing verbs 6288** might be discontinued. Applications should check the return code from 6289** [sqlite3_db_status()] to make sure that the call worked. 6290** The [sqlite3_db_status()] interface will return a non-zero error code 6291** if a discontinued or unsupported verb is invoked. 6292** 6293** <dl> 6294** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> 6295** <dd>This parameter returns the number of lookaside memory slots currently 6296** checked out.</dd>)^ 6297** 6298** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> 6299** <dd>This parameter returns the number malloc attempts that were 6300** satisfied using lookaside memory. Only the high-water value is meaningful; 6301** the current value is always zero.)^ 6302** 6303** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] 6304** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> 6305** <dd>This parameter returns the number malloc attempts that might have 6306** been satisfied using lookaside memory but failed due to the amount of 6307** memory requested being larger than the lookaside slot size. 6308** Only the high-water value is meaningful; 6309** the current value is always zero.)^ 6310** 6311** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] 6312** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> 6313** <dd>This parameter returns the number malloc attempts that might have 6314** been satisfied using lookaside memory but failed due to all lookaside 6315** memory already being in use. 6316** Only the high-water value is meaningful; 6317** the current value is always zero.)^ 6318** 6319** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> 6320** <dd>This parameter returns the approximate number of of bytes of heap 6321** memory used by all pager caches associated with the database connection.)^ 6322** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. 6323** 6324** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> 6325** <dd>This parameter returns the approximate number of of bytes of heap 6326** memory used to store the schema for all databases associated 6327** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 6328** ^The full amount of memory used by the schemas is reported, even if the 6329** schema memory is shared with other database connections due to 6330** [shared cache mode] being enabled. 6331** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. 6332** 6333** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> 6334** <dd>This parameter returns the approximate number of of bytes of heap 6335** and lookaside memory used by all prepared statements associated with 6336** the database connection.)^ 6337** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. 6338** </dd> 6339** </dl> 6340*/ 6341#define SQLITE_DBSTATUS_LOOKASIDE_USED 0 6342#define SQLITE_DBSTATUS_CACHE_USED 1 6343#define SQLITE_DBSTATUS_SCHEMA_USED 2 6344#define SQLITE_DBSTATUS_STMT_USED 3 6345#define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 6346#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 6347#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 6348#define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */ 6349 6350 6351/* 6352** CAPI3REF: Prepared Statement Status 6353** 6354** ^(Each prepared statement maintains various 6355** [SQLITE_STMTSTATUS counters] that measure the number 6356** of times it has performed specific operations.)^ These counters can 6357** be used to monitor the performance characteristics of the prepared 6358** statements. For example, if the number of table steps greatly exceeds 6359** the number of table searches or result rows, that would tend to indicate 6360** that the prepared statement is using a full table scan rather than 6361** an index. 6362** 6363** ^(This interface is used to retrieve and reset counter values from 6364** a [prepared statement]. The first argument is the prepared statement 6365** object to be interrogated. The second argument 6366** is an integer code for a specific [SQLITE_STMTSTATUS counter] 6367** to be interrogated.)^ 6368** ^The current value of the requested counter is returned. 6369** ^If the resetFlg is true, then the counter is reset to zero after this 6370** interface call returns. 6371** 6372** See also: [sqlite3_status()] and [sqlite3_db_status()]. 6373*/ 6374SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); 6375 6376/* 6377** CAPI3REF: Status Parameters for prepared statements 6378** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} 6379** 6380** These preprocessor macros define integer codes that name counter 6381** values associated with the [sqlite3_stmt_status()] interface. 6382** The meanings of the various counters are as follows: 6383** 6384** <dl> 6385** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> 6386** <dd>^This is the number of times that SQLite has stepped forward in 6387** a table as part of a full table scan. Large numbers for this counter 6388** may indicate opportunities for performance improvement through 6389** careful use of indices.</dd> 6390** 6391** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> 6392** <dd>^This is the number of sort operations that have occurred. 6393** A non-zero value in this counter may indicate an opportunity to 6394** improvement performance through careful use of indices.</dd> 6395** 6396** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> 6397** <dd>^This is the number of rows inserted into transient indices that 6398** were created automatically in order to help joins run faster. 6399** A non-zero value in this counter may indicate an opportunity to 6400** improvement performance by adding permanent indices that do not 6401** need to be reinitialized each time the statement is run.</dd> 6402** 6403** </dl> 6404*/ 6405#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 6406#define SQLITE_STMTSTATUS_SORT 2 6407#define SQLITE_STMTSTATUS_AUTOINDEX 3 6408 6409/* 6410** CAPI3REF: Custom Page Cache Object 6411** 6412** The sqlite3_pcache type is opaque. It is implemented by 6413** the pluggable module. The SQLite core has no knowledge of 6414** its size or internal structure and never deals with the 6415** sqlite3_pcache object except by holding and passing pointers 6416** to the object. 6417** 6418** See [sqlite3_pcache_methods] for additional information. 6419*/ 6420typedef struct sqlite3_pcache sqlite3_pcache; 6421 6422/* 6423** CAPI3REF: Application Defined Page Cache. 6424** KEYWORDS: {page cache} 6425** 6426** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can 6427** register an alternative page cache implementation by passing in an 6428** instance of the sqlite3_pcache_methods structure.)^ 6429** In many applications, most of the heap memory allocated by 6430** SQLite is used for the page cache. 6431** By implementing a 6432** custom page cache using this API, an application can better control 6433** the amount of memory consumed by SQLite, the way in which 6434** that memory is allocated and released, and the policies used to 6435** determine exactly which parts of a database file are cached and for 6436** how long. 6437** 6438** The alternative page cache mechanism is an 6439** extreme measure that is only needed by the most demanding applications. 6440** The built-in page cache is recommended for most uses. 6441** 6442** ^(The contents of the sqlite3_pcache_methods structure are copied to an 6443** internal buffer by SQLite within the call to [sqlite3_config]. Hence 6444** the application may discard the parameter after the call to 6445** [sqlite3_config()] returns.)^ 6446** 6447** [[the xInit() page cache method]] 6448** ^(The xInit() method is called once for each effective 6449** call to [sqlite3_initialize()])^ 6450** (usually only once during the lifetime of the process). ^(The xInit() 6451** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ 6452** The intent of the xInit() method is to set up global data structures 6453** required by the custom page cache implementation. 6454** ^(If the xInit() method is NULL, then the 6455** built-in default page cache is used instead of the application defined 6456** page cache.)^ 6457** 6458** [[the xShutdown() page cache method]] 6459** ^The xShutdown() method is called by [sqlite3_shutdown()]. 6460** It can be used to clean up 6461** any outstanding resources before process shutdown, if required. 6462** ^The xShutdown() method may be NULL. 6463** 6464** ^SQLite automatically serializes calls to the xInit method, 6465** so the xInit method need not be threadsafe. ^The 6466** xShutdown method is only called from [sqlite3_shutdown()] so it does 6467** not need to be threadsafe either. All other methods must be threadsafe 6468** in multithreaded applications. 6469** 6470** ^SQLite will never invoke xInit() more than once without an intervening 6471** call to xShutdown(). 6472** 6473** [[the xCreate() page cache methods]] 6474** ^SQLite invokes the xCreate() method to construct a new cache instance. 6475** SQLite will typically create one cache instance for each open database file, 6476** though this is not guaranteed. ^The 6477** first parameter, szPage, is the size in bytes of the pages that must 6478** be allocated by the cache. ^szPage will not be a power of two. ^szPage 6479** will the page size of the database file that is to be cached plus an 6480** increment (here called "R") of less than 250. SQLite will use the 6481** extra R bytes on each page to store metadata about the underlying 6482** database page on disk. The value of R depends 6483** on the SQLite version, the target platform, and how SQLite was compiled. 6484** ^(R is constant for a particular build of SQLite. Except, there are two 6485** distinct values of R when SQLite is compiled with the proprietary 6486** ZIPVFS extension.)^ ^The second argument to 6487** xCreate(), bPurgeable, is true if the cache being created will 6488** be used to cache database pages of a file stored on disk, or 6489** false if it is used for an in-memory database. The cache implementation 6490** does not have to do anything special based with the value of bPurgeable; 6491** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 6492** never invoke xUnpin() except to deliberately delete a page. 6493** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 6494** false will always have the "discard" flag set to true. 6495** ^Hence, a cache created with bPurgeable false will 6496** never contain any unpinned pages. 6497** 6498** [[the xCachesize() page cache method]] 6499** ^(The xCachesize() method may be called at any time by SQLite to set the 6500** suggested maximum cache-size (number of pages stored by) the cache 6501** instance passed as the first argument. This is the value configured using 6502** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable 6503** parameter, the implementation is not required to do anything with this 6504** value; it is advisory only. 6505** 6506** [[the xPagecount() page cache methods]] 6507** The xPagecount() method must return the number of pages currently 6508** stored in the cache, both pinned and unpinned. 6509** 6510** [[the xFetch() page cache methods]] 6511** The xFetch() method locates a page in the cache and returns a pointer to 6512** the page, or a NULL pointer. 6513** A "page", in this context, means a buffer of szPage bytes aligned at an 6514** 8-byte boundary. The page to be fetched is determined by the key. ^The 6515** minimum key value is 1. After it has been retrieved using xFetch, the page 6516** is considered to be "pinned". 6517** 6518** If the requested page is already in the page cache, then the page cache 6519** implementation must return a pointer to the page buffer with its content 6520** intact. If the requested page is not already in the cache, then the 6521** cache implementation should use the value of the createFlag 6522** parameter to help it determined what action to take: 6523** 6524** <table border=1 width=85% align=center> 6525** <tr><th> createFlag <th> Behaviour when page is not already in cache 6526** <tr><td> 0 <td> Do not allocate a new page. Return NULL. 6527** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. 6528** Otherwise return NULL. 6529** <tr><td> 2 <td> Make every effort to allocate a new page. Only return 6530** NULL if allocating a new page is effectively impossible. 6531** </table> 6532** 6533** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite 6534** will only use a createFlag of 2 after a prior call with a createFlag of 1 6535** failed.)^ In between the to xFetch() calls, SQLite may 6536** attempt to unpin one or more cache pages by spilling the content of 6537** pinned pages to disk and synching the operating system disk cache. 6538** 6539** [[the xUnpin() page cache method]] 6540** ^xUnpin() is called by SQLite with a pointer to a currently pinned page 6541** as its second argument. If the third parameter, discard, is non-zero, 6542** then the page must be evicted from the cache. 6543** ^If the discard parameter is 6544** zero, then the page may be discarded or retained at the discretion of 6545** page cache implementation. ^The page cache implementation 6546** may choose to evict unpinned pages at any time. 6547** 6548** The cache must not perform any reference counting. A single 6549** call to xUnpin() unpins the page regardless of the number of prior calls 6550** to xFetch(). 6551** 6552** [[the xRekey() page cache methods]] 6553** The xRekey() method is used to change the key value associated with the 6554** page passed as the second argument. If the cache 6555** previously contains an entry associated with newKey, it must be 6556** discarded. ^Any prior cache entry associated with newKey is guaranteed not 6557** to be pinned. 6558** 6559** When SQLite calls the xTruncate() method, the cache must discard all 6560** existing cache entries with page numbers (keys) greater than or equal 6561** to the value of the iLimit parameter passed to xTruncate(). If any 6562** of these pages are pinned, they are implicitly unpinned, meaning that 6563** they can be safely discarded. 6564** 6565** [[the xDestroy() page cache method]] 6566** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 6567** All resources associated with the specified cache should be freed. ^After 6568** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 6569** handle invalid, and will not use it with any other sqlite3_pcache_methods 6570** functions. 6571*/ 6572typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 6573struct sqlite3_pcache_methods { 6574 void *pArg; 6575 int (*xInit)(void*); 6576 void (*xShutdown)(void*); 6577 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 6578 void (*xCachesize)(sqlite3_pcache*, int nCachesize); 6579 int (*xPagecount)(sqlite3_pcache*); 6580 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 6581 void (*xUnpin)(sqlite3_pcache*, void*, int discard); 6582 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 6583 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 6584 void (*xDestroy)(sqlite3_pcache*); 6585}; 6586 6587/* 6588** CAPI3REF: Online Backup Object 6589** 6590** The sqlite3_backup object records state information about an ongoing 6591** online backup operation. ^The sqlite3_backup object is created by 6592** a call to [sqlite3_backup_init()] and is destroyed by a call to 6593** [sqlite3_backup_finish()]. 6594** 6595** See Also: [Using the SQLite Online Backup API] 6596*/ 6597typedef struct sqlite3_backup sqlite3_backup; 6598 6599/* 6600** CAPI3REF: Online Backup API. 6601** 6602** The backup API copies the content of one database into another. 6603** It is useful either for creating backups of databases or 6604** for copying in-memory databases to or from persistent files. 6605** 6606** See Also: [Using the SQLite Online Backup API] 6607** 6608** ^SQLite holds a write transaction open on the destination database file 6609** for the duration of the backup operation. 6610** ^The source database is read-locked only while it is being read; 6611** it is not locked continuously for the entire backup operation. 6612** ^Thus, the backup may be performed on a live source database without 6613** preventing other database connections from 6614** reading or writing to the source database while the backup is underway. 6615** 6616** ^(To perform a backup operation: 6617** <ol> 6618** <li><b>sqlite3_backup_init()</b> is called once to initialize the 6619** backup, 6620** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 6621** the data between the two databases, and finally 6622** <li><b>sqlite3_backup_finish()</b> is called to release all resources 6623** associated with the backup operation. 6624** </ol>)^ 6625** There should be exactly one call to sqlite3_backup_finish() for each 6626** successful call to sqlite3_backup_init(). 6627** 6628** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> 6629** 6630** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 6631** [database connection] associated with the destination database 6632** and the database name, respectively. 6633** ^The database name is "main" for the main database, "temp" for the 6634** temporary database, or the name specified after the AS keyword in 6635** an [ATTACH] statement for an attached database. 6636** ^The S and M arguments passed to 6637** sqlite3_backup_init(D,N,S,M) identify the [database connection] 6638** and database name of the source database, respectively. 6639** ^The source and destination [database connections] (parameters S and D) 6640** must be different or else sqlite3_backup_init(D,N,S,M) will fail with 6641** an error. 6642** 6643** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is 6644** returned and an error code and error message are stored in the 6645** destination [database connection] D. 6646** ^The error code and message for the failed call to sqlite3_backup_init() 6647** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or 6648** [sqlite3_errmsg16()] functions. 6649** ^A successful call to sqlite3_backup_init() returns a pointer to an 6650** [sqlite3_backup] object. 6651** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and 6652** sqlite3_backup_finish() functions to perform the specified backup 6653** operation. 6654** 6655** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> 6656** 6657** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 6658** the source and destination databases specified by [sqlite3_backup] object B. 6659** ^If N is negative, all remaining source pages are copied. 6660** ^If sqlite3_backup_step(B,N) successfully copies N pages and there 6661** are still more pages to be copied, then the function returns [SQLITE_OK]. 6662** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages 6663** from source to destination, then it returns [SQLITE_DONE]. 6664** ^If an error occurs while running sqlite3_backup_step(B,N), 6665** then an [error code] is returned. ^As well as [SQLITE_OK] and 6666** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], 6667** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an 6668** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. 6669** 6670** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if 6671** <ol> 6672** <li> the destination database was opened read-only, or 6673** <li> the destination database is using write-ahead-log journaling 6674** and the destination and source page sizes differ, or 6675** <li> the destination database is an in-memory database and the 6676** destination and source page sizes differ. 6677** </ol>)^ 6678** 6679** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then 6680** the [sqlite3_busy_handler | busy-handler function] 6681** is invoked (if one is specified). ^If the 6682** busy-handler returns non-zero before the lock is available, then 6683** [SQLITE_BUSY] is returned to the caller. ^In this case the call to 6684** sqlite3_backup_step() can be retried later. ^If the source 6685** [database connection] 6686** is being used to write to the source database when sqlite3_backup_step() 6687** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this 6688** case the call to sqlite3_backup_step() can be retried later on. ^(If 6689** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or 6690** [SQLITE_READONLY] is returned, then 6691** there is no point in retrying the call to sqlite3_backup_step(). These 6692** errors are considered fatal.)^ The application must accept 6693** that the backup operation has failed and pass the backup operation handle 6694** to the sqlite3_backup_finish() to release associated resources. 6695** 6696** ^The first call to sqlite3_backup_step() obtains an exclusive lock 6697** on the destination file. ^The exclusive lock is not released until either 6698** sqlite3_backup_finish() is called or the backup operation is complete 6699** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to 6700** sqlite3_backup_step() obtains a [shared lock] on the source database that 6701** lasts for the duration of the sqlite3_backup_step() call. 6702** ^Because the source database is not locked between calls to 6703** sqlite3_backup_step(), the source database may be modified mid-way 6704** through the backup process. ^If the source database is modified by an 6705** external process or via a database connection other than the one being 6706** used by the backup operation, then the backup will be automatically 6707** restarted by the next call to sqlite3_backup_step(). ^If the source 6708** database is modified by the using the same database connection as is used 6709** by the backup operation, then the backup database is automatically 6710** updated at the same time. 6711** 6712** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> 6713** 6714** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 6715** application wishes to abandon the backup operation, the application 6716** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). 6717** ^The sqlite3_backup_finish() interfaces releases all 6718** resources associated with the [sqlite3_backup] object. 6719** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any 6720** active write-transaction on the destination database is rolled back. 6721** The [sqlite3_backup] object is invalid 6722** and may not be used following a call to sqlite3_backup_finish(). 6723** 6724** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no 6725** sqlite3_backup_step() errors occurred, regardless or whether or not 6726** sqlite3_backup_step() completed. 6727** ^If an out-of-memory condition or IO error occurred during any prior 6728** sqlite3_backup_step() call on the same [sqlite3_backup] object, then 6729** sqlite3_backup_finish() returns the corresponding [error code]. 6730** 6731** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() 6732** is not a permanent error and does not affect the return value of 6733** sqlite3_backup_finish(). 6734** 6735** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]] 6736** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> 6737** 6738** ^Each call to sqlite3_backup_step() sets two values inside 6739** the [sqlite3_backup] object: the number of pages still to be backed 6740** up and the total number of pages in the source database file. 6741** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces 6742** retrieve these two values, respectively. 6743** 6744** ^The values returned by these functions are only updated by 6745** sqlite3_backup_step(). ^If the source database is modified during a backup 6746** operation, then the values are not updated to account for any extra 6747** pages that need to be updated or the size of the source database file 6748** changing. 6749** 6750** <b>Concurrent Usage of Database Handles</b> 6751** 6752** ^The source [database connection] may be used by the application for other 6753** purposes while a backup operation is underway or being initialized. 6754** ^If SQLite is compiled and configured to support threadsafe database 6755** connections, then the source database connection may be used concurrently 6756** from within other threads. 6757** 6758** However, the application must guarantee that the destination 6759** [database connection] is not passed to any other API (by any thread) after 6760** sqlite3_backup_init() is called and before the corresponding call to 6761** sqlite3_backup_finish(). SQLite does not currently check to see 6762** if the application incorrectly accesses the destination [database connection] 6763** and so no error code is reported, but the operations may malfunction 6764** nevertheless. Use of the destination database connection while a 6765** backup is in progress might also also cause a mutex deadlock. 6766** 6767** If running in [shared cache mode], the application must 6768** guarantee that the shared cache used by the destination database 6769** is not accessed while the backup is running. In practice this means 6770** that the application must guarantee that the disk file being 6771** backed up to is not accessed by any connection within the process, 6772** not just the specific connection that was passed to sqlite3_backup_init(). 6773** 6774** The [sqlite3_backup] object itself is partially threadsafe. Multiple 6775** threads may safely make multiple concurrent calls to sqlite3_backup_step(). 6776** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() 6777** APIs are not strictly speaking threadsafe. If they are invoked at the 6778** same time as another thread is invoking sqlite3_backup_step() it is 6779** possible that they return invalid values. 6780*/ 6781SQLITE_API sqlite3_backup *sqlite3_backup_init( 6782 sqlite3 *pDest, /* Destination database handle */ 6783 const char *zDestName, /* Destination database name */ 6784 sqlite3 *pSource, /* Source database handle */ 6785 const char *zSourceName /* Source database name */ 6786); 6787SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); 6788SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); 6789SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); 6790SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); 6791 6792/* 6793** CAPI3REF: Unlock Notification 6794** 6795** ^When running in shared-cache mode, a database operation may fail with 6796** an [SQLITE_LOCKED] error if the required locks on the shared-cache or 6797** individual tables within the shared-cache cannot be obtained. See 6798** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 6799** ^This API may be used to register a callback that SQLite will invoke 6800** when the connection currently holding the required lock relinquishes it. 6801** ^This API is only available if the library was compiled with the 6802** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. 6803** 6804** See Also: [Using the SQLite Unlock Notification Feature]. 6805** 6806** ^Shared-cache locks are released when a database connection concludes 6807** its current transaction, either by committing it or rolling it back. 6808** 6809** ^When a connection (known as the blocked connection) fails to obtain a 6810** shared-cache lock and SQLITE_LOCKED is returned to the caller, the 6811** identity of the database connection (the blocking connection) that 6812** has locked the required resource is stored internally. ^After an 6813** application receives an SQLITE_LOCKED error, it may call the 6814** sqlite3_unlock_notify() method with the blocked connection handle as 6815** the first argument to register for a callback that will be invoked 6816** when the blocking connections current transaction is concluded. ^The 6817** callback is invoked from within the [sqlite3_step] or [sqlite3_close] 6818** call that concludes the blocking connections transaction. 6819** 6820** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, 6821** there is a chance that the blocking connection will have already 6822** concluded its transaction by the time sqlite3_unlock_notify() is invoked. 6823** If this happens, then the specified callback is invoked immediately, 6824** from within the call to sqlite3_unlock_notify().)^ 6825** 6826** ^If the blocked connection is attempting to obtain a write-lock on a 6827** shared-cache table, and more than one other connection currently holds 6828** a read-lock on the same table, then SQLite arbitrarily selects one of 6829** the other connections to use as the blocking connection. 6830** 6831** ^(There may be at most one unlock-notify callback registered by a 6832** blocked connection. If sqlite3_unlock_notify() is called when the 6833** blocked connection already has a registered unlock-notify callback, 6834** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is 6835** called with a NULL pointer as its second argument, then any existing 6836** unlock-notify callback is canceled. ^The blocked connections 6837** unlock-notify callback may also be canceled by closing the blocked 6838** connection using [sqlite3_close()]. 6839** 6840** The unlock-notify callback is not reentrant. If an application invokes 6841** any sqlite3_xxx API functions from within an unlock-notify callback, a 6842** crash or deadlock may be the result. 6843** 6844** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always 6845** returns SQLITE_OK. 6846** 6847** <b>Callback Invocation Details</b> 6848** 6849** When an unlock-notify callback is registered, the application provides a 6850** single void* pointer that is passed to the callback when it is invoked. 6851** However, the signature of the callback function allows SQLite to pass 6852** it an array of void* context pointers. The first argument passed to 6853** an unlock-notify callback is a pointer to an array of void* pointers, 6854** and the second is the number of entries in the array. 6855** 6856** When a blocking connections transaction is concluded, there may be 6857** more than one blocked connection that has registered for an unlock-notify 6858** callback. ^If two or more such blocked connections have specified the 6859** same callback function, then instead of invoking the callback function 6860** multiple times, it is invoked once with the set of void* context pointers 6861** specified by the blocked connections bundled together into an array. 6862** This gives the application an opportunity to prioritize any actions 6863** related to the set of unblocked database connections. 6864** 6865** <b>Deadlock Detection</b> 6866** 6867** Assuming that after registering for an unlock-notify callback a 6868** database waits for the callback to be issued before taking any further 6869** action (a reasonable assumption), then using this API may cause the 6870** application to deadlock. For example, if connection X is waiting for 6871** connection Y's transaction to be concluded, and similarly connection 6872** Y is waiting on connection X's transaction, then neither connection 6873** will proceed and the system may remain deadlocked indefinitely. 6874** 6875** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock 6876** detection. ^If a given call to sqlite3_unlock_notify() would put the 6877** system in a deadlocked state, then SQLITE_LOCKED is returned and no 6878** unlock-notify callback is registered. The system is said to be in 6879** a deadlocked state if connection A has registered for an unlock-notify 6880** callback on the conclusion of connection B's transaction, and connection 6881** B has itself registered for an unlock-notify callback when connection 6882** A's transaction is concluded. ^Indirect deadlock is also detected, so 6883** the system is also considered to be deadlocked if connection B has 6884** registered for an unlock-notify callback on the conclusion of connection 6885** C's transaction, where connection C is waiting on connection A. ^Any 6886** number of levels of indirection are allowed. 6887** 6888** <b>The "DROP TABLE" Exception</b> 6889** 6890** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 6891** always appropriate to call sqlite3_unlock_notify(). There is however, 6892** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, 6893** SQLite checks if there are any currently executing SELECT statements 6894** that belong to the same connection. If there are, SQLITE_LOCKED is 6895** returned. In this case there is no "blocking connection", so invoking 6896** sqlite3_unlock_notify() results in the unlock-notify callback being 6897** invoked immediately. If the application then re-attempts the "DROP TABLE" 6898** or "DROP INDEX" query, an infinite loop might be the result. 6899** 6900** One way around this problem is to check the extended error code returned 6901** by an sqlite3_step() call. ^(If there is a blocking connection, then the 6902** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in 6903** the special "DROP TABLE/INDEX" case, the extended error code is just 6904** SQLITE_LOCKED.)^ 6905*/ 6906SQLITE_API int sqlite3_unlock_notify( 6907 sqlite3 *pBlocked, /* Waiting connection */ 6908 void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ 6909 void *pNotifyArg /* Argument to pass to xNotify */ 6910); 6911 6912 6913/* 6914** CAPI3REF: String Comparison 6915** 6916** ^The [sqlite3_strnicmp()] API allows applications and extensions to 6917** compare the contents of two buffers containing UTF-8 strings in a 6918** case-independent fashion, using the same definition of case independence 6919** that SQLite uses internally when comparing identifiers. 6920*/ 6921SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); 6922 6923/* 6924** CAPI3REF: Error Logging Interface 6925** 6926** ^The [sqlite3_log()] interface writes a message into the error log 6927** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 6928** ^If logging is enabled, the zFormat string and subsequent arguments are 6929** used with [sqlite3_snprintf()] to generate the final output string. 6930** 6931** The sqlite3_log() interface is intended for use by extensions such as 6932** virtual tables, collating functions, and SQL functions. While there is 6933** nothing to prevent an application from calling sqlite3_log(), doing so 6934** is considered bad form. 6935** 6936** The zFormat string must not be NULL. 6937** 6938** To avoid deadlocks and other threading problems, the sqlite3_log() routine 6939** will not use dynamically allocated memory. The log message is stored in 6940** a fixed-length buffer on the stack. If the log message is longer than 6941** a few hundred characters, it will be truncated to the length of the 6942** buffer. 6943*/ 6944SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); 6945 6946/* 6947** CAPI3REF: Write-Ahead Log Commit Hook 6948** 6949** ^The [sqlite3_wal_hook()] function is used to register a callback that 6950** will be invoked each time a database connection commits data to a 6951** [write-ahead log] (i.e. whenever a transaction is committed in 6952** [journal_mode | journal_mode=WAL mode]). 6953** 6954** ^The callback is invoked by SQLite after the commit has taken place and 6955** the associated write-lock on the database released, so the implementation 6956** may read, write or [checkpoint] the database as required. 6957** 6958** ^The first parameter passed to the callback function when it is invoked 6959** is a copy of the third parameter passed to sqlite3_wal_hook() when 6960** registering the callback. ^The second is a copy of the database handle. 6961** ^The third parameter is the name of the database that was written to - 6962** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter 6963** is the number of pages currently in the write-ahead log file, 6964** including those that were just committed. 6965** 6966** The callback function should normally return [SQLITE_OK]. ^If an error 6967** code is returned, that error will propagate back up through the 6968** SQLite code base to cause the statement that provoked the callback 6969** to report an error, though the commit will have still occurred. If the 6970** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value 6971** that does not correspond to any valid SQLite error code, the results 6972** are undefined. 6973** 6974** A single database handle may have at most a single write-ahead log callback 6975** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any 6976** previously registered write-ahead log callback. ^Note that the 6977** [sqlite3_wal_autocheckpoint()] interface and the 6978** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will 6979** those overwrite any prior [sqlite3_wal_hook()] settings. 6980*/ 6981SQLITE_API void *sqlite3_wal_hook( 6982 sqlite3*, 6983 int(*)(void *,sqlite3*,const char*,int), 6984 void* 6985); 6986 6987/* 6988** CAPI3REF: Configure an auto-checkpoint 6989** 6990** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around 6991** [sqlite3_wal_hook()] that causes any database on [database connection] D 6992** to automatically [checkpoint] 6993** after committing a transaction if there are N or 6994** more frames in the [write-ahead log] file. ^Passing zero or 6995** a negative value as the nFrame parameter disables automatic 6996** checkpoints entirely. 6997** 6998** ^The callback registered by this function replaces any existing callback 6999** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback 7000** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism 7001** configured by this function. 7002** 7003** ^The [wal_autocheckpoint pragma] can be used to invoke this interface 7004** from SQL. 7005** 7006** ^Every new [database connection] defaults to having the auto-checkpoint 7007** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] 7008** pages. The use of this interface 7009** is only necessary if the default setting is found to be suboptimal 7010** for a particular application. 7011*/ 7012SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); 7013 7014/* 7015** CAPI3REF: Checkpoint a database 7016** 7017** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X 7018** on [database connection] D to be [checkpointed]. ^If X is NULL or an 7019** empty string, then a checkpoint is run on all databases of 7020** connection D. ^If the database connection D is not in 7021** [WAL | write-ahead log mode] then this interface is a harmless no-op. 7022** 7023** ^The [wal_checkpoint pragma] can be used to invoke this interface 7024** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the 7025** [wal_autocheckpoint pragma] can be used to cause this interface to be 7026** run whenever the WAL reaches a certain size threshold. 7027** 7028** See also: [sqlite3_wal_checkpoint_v2()] 7029*/ 7030SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); 7031 7032/* 7033** CAPI3REF: Checkpoint a database 7034** 7035** Run a checkpoint operation on WAL database zDb attached to database 7036** handle db. The specific operation is determined by the value of the 7037** eMode parameter: 7038** 7039** <dl> 7040** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> 7041** Checkpoint as many frames as possible without waiting for any database 7042** readers or writers to finish. Sync the db file if all frames in the log 7043** are checkpointed. This mode is the same as calling 7044** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked. 7045** 7046** <dt>SQLITE_CHECKPOINT_FULL<dd> 7047** This mode blocks (calls the busy-handler callback) until there is no 7048** database writer and all readers are reading from the most recent database 7049** snapshot. It then checkpoints all frames in the log file and syncs the 7050** database file. This call blocks database writers while it is running, 7051** but not database readers. 7052** 7053** <dt>SQLITE_CHECKPOINT_RESTART<dd> 7054** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after 7055** checkpointing the log file it blocks (calls the busy-handler callback) 7056** until all readers are reading from the database file only. This ensures 7057** that the next client to write to the database file restarts the log file 7058** from the beginning. This call blocks database writers while it is running, 7059** but not database readers. 7060** </dl> 7061** 7062** If pnLog is not NULL, then *pnLog is set to the total number of frames in 7063** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to 7064** the total number of checkpointed frames (including any that were already 7065** checkpointed when this function is called). *pnLog and *pnCkpt may be 7066** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. 7067** If no values are available because of an error, they are both set to -1 7068** before returning to communicate this to the caller. 7069** 7070** All calls obtain an exclusive "checkpoint" lock on the database file. If 7071** any other process is running a checkpoint operation at the same time, the 7072** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a 7073** busy-handler configured, it will not be invoked in this case. 7074** 7075** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive 7076** "writer" lock on the database file. If the writer lock cannot be obtained 7077** immediately, and a busy-handler is configured, it is invoked and the writer 7078** lock retried until either the busy-handler returns 0 or the lock is 7079** successfully obtained. The busy-handler is also invoked while waiting for 7080** database readers as described above. If the busy-handler returns 0 before 7081** the writer lock is obtained or while waiting for database readers, the 7082** checkpoint operation proceeds from that point in the same way as 7083** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible 7084** without blocking any further. SQLITE_BUSY is returned in this case. 7085** 7086** If parameter zDb is NULL or points to a zero length string, then the 7087** specified operation is attempted on all WAL databases. In this case the 7088** values written to output parameters *pnLog and *pnCkpt are undefined. If 7089** an SQLITE_BUSY error is encountered when processing one or more of the 7090** attached WAL databases, the operation is still attempted on any remaining 7091** attached databases and SQLITE_BUSY is returned to the caller. If any other 7092** error occurs while processing an attached database, processing is abandoned 7093** and the error code returned to the caller immediately. If no error 7094** (SQLITE_BUSY or otherwise) is encountered while processing the attached 7095** databases, SQLITE_OK is returned. 7096** 7097** If database zDb is the name of an attached database that is not in WAL 7098** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If 7099** zDb is not NULL (or a zero length string) and is not the name of any 7100** attached database, SQLITE_ERROR is returned to the caller. 7101*/ 7102SQLITE_API int sqlite3_wal_checkpoint_v2( 7103 sqlite3 *db, /* Database handle */ 7104 const char *zDb, /* Name of attached database (or NULL) */ 7105 int eMode, /* SQLITE_CHECKPOINT_* value */ 7106 int *pnLog, /* OUT: Size of WAL log in frames */ 7107 int *pnCkpt /* OUT: Total number of frames checkpointed */ 7108); 7109 7110/* 7111** CAPI3REF: Checkpoint operation parameters 7112** 7113** These constants can be used as the 3rd parameter to 7114** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] 7115** documentation for additional information about the meaning and use of 7116** each of these values. 7117*/ 7118#define SQLITE_CHECKPOINT_PASSIVE 0 7119#define SQLITE_CHECKPOINT_FULL 1 7120#define SQLITE_CHECKPOINT_RESTART 2 7121 7122/* 7123** CAPI3REF: Virtual Table Interface Configuration 7124** 7125** This function may be called by either the [xConnect] or [xCreate] method 7126** of a [virtual table] implementation to configure 7127** various facets of the virtual table interface. 7128** 7129** If this interface is invoked outside the context of an xConnect or 7130** xCreate virtual table method then the behavior is undefined. 7131** 7132** At present, there is only one option that may be configured using 7133** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options 7134** may be added in the future. 7135*/ 7136SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); 7137 7138/* 7139** CAPI3REF: Virtual Table Configuration Options 7140** 7141** These macros define the various options to the 7142** [sqlite3_vtab_config()] interface that [virtual table] implementations 7143** can use to customize and optimize their behavior. 7144** 7145** <dl> 7146** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT 7147** <dd>Calls of the form 7148** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, 7149** where X is an integer. If X is zero, then the [virtual table] whose 7150** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not 7151** support constraints. In this configuration (which is the default) if 7152** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire 7153** statement is rolled back as if [ON CONFLICT | OR ABORT] had been 7154** specified as part of the users SQL statement, regardless of the actual 7155** ON CONFLICT mode specified. 7156** 7157** If X is non-zero, then the virtual table implementation guarantees 7158** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before 7159** any modifications to internal or persistent data structures have been made. 7160** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite 7161** is able to roll back a statement or database transaction, and abandon 7162** or continue processing the current SQL statement as appropriate. 7163** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns 7164** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode 7165** had been ABORT. 7166** 7167** Virtual table implementations that are required to handle OR REPLACE 7168** must do so within the [xUpdate] method. If a call to the 7169** [sqlite3_vtab_on_conflict()] function indicates that the current ON 7170** CONFLICT policy is REPLACE, the virtual table implementation should 7171** silently replace the appropriate rows within the xUpdate callback and 7172** return SQLITE_OK. Or, if this is not possible, it may return 7173** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT 7174** constraint handling. 7175** </dl> 7176*/ 7177#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 7178 7179/* 7180** CAPI3REF: Determine The Virtual Table Conflict Policy 7181** 7182** This function may only be called from within a call to the [xUpdate] method 7183** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The 7184** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], 7185** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode 7186** of the SQL statement that triggered the call to the [xUpdate] method of the 7187** [virtual table]. 7188*/ 7189SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); 7190 7191/* 7192** CAPI3REF: Conflict resolution modes 7193** 7194** These constants are returned by [sqlite3_vtab_on_conflict()] to 7195** inform a [virtual table] implementation what the [ON CONFLICT] mode 7196** is for the SQL statement being evaluated. 7197** 7198** Note that the [SQLITE_IGNORE] constant is also used as a potential 7199** return value from the [sqlite3_set_authorizer()] callback and that 7200** [SQLITE_ABORT] is also a [result code]. 7201*/ 7202#define SQLITE_ROLLBACK 1 7203/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ 7204#define SQLITE_FAIL 3 7205/* #define SQLITE_ABORT 4 // Also an error code */ 7206#define SQLITE_REPLACE 5 7207 7208 7209 7210/* 7211** Undo the hack that converts floating point types to integer for 7212** builds on processors without floating point support. 7213*/ 7214#ifdef SQLITE_OMIT_FLOATING_POINT 7215# undef double 7216#endif 7217 7218#if 0 7219} /* End of the 'extern "C"' block */ 7220#endif 7221#endif 7222 7223/* 7224** 2010 August 30 7225** 7226** The author disclaims copyright to this source code. In place of 7227** a legal notice, here is a blessing: 7228** 7229** May you do good and not evil. 7230** May you find forgiveness for yourself and forgive others. 7231** May you share freely, never taking more than you give. 7232** 7233************************************************************************* 7234*/ 7235 7236#ifndef _SQLITE3RTREE_H_ 7237#define _SQLITE3RTREE_H_ 7238 7239 7240#if 0 7241extern "C" { 7242#endif 7243 7244typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; 7245 7246/* 7247** Register a geometry callback named zGeom that can be used as part of an 7248** R-Tree geometry query as follows: 7249** 7250** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 7251*/ 7252SQLITE_API int sqlite3_rtree_geometry_callback( 7253 sqlite3 *db, 7254 const char *zGeom, 7255 int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes), 7256 void *pContext 7257); 7258 7259 7260/* 7261** A pointer to a structure of the following type is passed as the first 7262** argument to callbacks registered using rtree_geometry_callback(). 7263*/ 7264struct sqlite3_rtree_geometry { 7265 void *pContext; /* Copy of pContext passed to s_r_g_c() */ 7266 int nParam; /* Size of array aParam[] */ 7267 double *aParam; /* Parameters passed to SQL geom function */ 7268 void *pUser; /* Callback implementation user data */ 7269 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ 7270}; 7271 7272 7273#if 0 7274} /* end of the 'extern "C"' block */ 7275#endif 7276 7277#endif /* ifndef _SQLITE3RTREE_H_ */ 7278 7279 7280/************** End of sqlite3.h *********************************************/ 7281/************** Continuing where we left off in sqliteInt.h ******************/ 7282/************** Include hash.h in the middle of sqliteInt.h ******************/ 7283/************** Begin file hash.h ********************************************/ 7284/* 7285** 2001 September 22 7286** 7287** The author disclaims copyright to this source code. In place of 7288** a legal notice, here is a blessing: 7289** 7290** May you do good and not evil. 7291** May you find forgiveness for yourself and forgive others. 7292** May you share freely, never taking more than you give. 7293** 7294************************************************************************* 7295** This is the header file for the generic hash-table implemenation 7296** used in SQLite. 7297*/ 7298#ifndef _SQLITE_HASH_H_ 7299#define _SQLITE_HASH_H_ 7300 7301/* Forward declarations of structures. */ 7302typedef struct Hash Hash; 7303typedef struct HashElem HashElem; 7304 7305/* A complete hash table is an instance of the following structure. 7306** The internals of this structure are intended to be opaque -- client 7307** code should not attempt to access or modify the fields of this structure 7308** directly. Change this structure only by using the routines below. 7309** However, some of the "procedures" and "functions" for modifying and 7310** accessing this structure are really macros, so we can't really make 7311** this structure opaque. 7312** 7313** All elements of the hash table are on a single doubly-linked list. 7314** Hash.first points to the head of this list. 7315** 7316** There are Hash.htsize buckets. Each bucket points to a spot in 7317** the global doubly-linked list. The contents of the bucket are the 7318** element pointed to plus the next _ht.count-1 elements in the list. 7319** 7320** Hash.htsize and Hash.ht may be zero. In that case lookup is done 7321** by a linear search of the global list. For small tables, the 7322** Hash.ht table is never allocated because if there are few elements 7323** in the table, it is faster to do a linear search than to manage 7324** the hash table. 7325*/ 7326struct Hash { 7327 unsigned int htsize; /* Number of buckets in the hash table */ 7328 unsigned int count; /* Number of entries in this table */ 7329 HashElem *first; /* The first element of the array */ 7330 struct _ht { /* the hash table */ 7331 int count; /* Number of entries with this hash */ 7332 HashElem *chain; /* Pointer to first entry with this hash */ 7333 } *ht; 7334}; 7335 7336/* Each element in the hash table is an instance of the following 7337** structure. All elements are stored on a single doubly-linked list. 7338** 7339** Again, this structure is intended to be opaque, but it can't really 7340** be opaque because it is used by macros. 7341*/ 7342struct HashElem { 7343 HashElem *next, *prev; /* Next and previous elements in the table */ 7344 void *data; /* Data associated with this element */ 7345 const char *pKey; int nKey; /* Key associated with this element */ 7346}; 7347 7348/* 7349** Access routines. To delete, insert a NULL pointer. 7350*/ 7351SQLITE_PRIVATE void sqlite3HashInit(Hash*); 7352SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const char *pKey, int nKey, void *pData); 7353SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const char *pKey, int nKey); 7354SQLITE_PRIVATE void sqlite3HashClear(Hash*); 7355 7356/* 7357** Macros for looping over all elements of a hash table. The idiom is 7358** like this: 7359** 7360** Hash h; 7361** HashElem *p; 7362** ... 7363** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){ 7364** SomeStructure *pData = sqliteHashData(p); 7365** // do something with pData 7366** } 7367*/ 7368#define sqliteHashFirst(H) ((H)->first) 7369#define sqliteHashNext(E) ((E)->next) 7370#define sqliteHashData(E) ((E)->data) 7371/* #define sqliteHashKey(E) ((E)->pKey) // NOT USED */ 7372/* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ 7373 7374/* 7375** Number of entries in a hash table 7376*/ 7377/* #define sqliteHashCount(H) ((H)->count) // NOT USED */ 7378 7379#endif /* _SQLITE_HASH_H_ */ 7380 7381/************** End of hash.h ************************************************/ 7382/************** Continuing where we left off in sqliteInt.h ******************/ 7383/************** Include parse.h in the middle of sqliteInt.h *****************/ 7384/************** Begin file parse.h *******************************************/ 7385#define TK_SEMI 1 7386#define TK_EXPLAIN 2 7387#define TK_QUERY 3 7388#define TK_PLAN 4 7389#define TK_BEGIN 5 7390#define TK_TRANSACTION 6 7391#define TK_DEFERRED 7 7392#define TK_IMMEDIATE 8 7393#define TK_EXCLUSIVE 9 7394#define TK_COMMIT 10 7395#define TK_END 11 7396#define TK_ROLLBACK 12 7397#define TK_SAVEPOINT 13 7398#define TK_RELEASE 14 7399#define TK_TO 15 7400#define TK_TABLE 16 7401#define TK_CREATE 17 7402#define TK_IF 18 7403#define TK_NOT 19 7404#define TK_EXISTS 20 7405#define TK_TEMP 21 7406#define TK_LP 22 7407#define TK_RP 23 7408#define TK_AS 24 7409#define TK_COMMA 25 7410#define TK_ID 26 7411#define TK_INDEXED 27 7412#define TK_ABORT 28 7413#define TK_ACTION 29 7414#define TK_AFTER 30 7415#define TK_ANALYZE 31 7416#define TK_ASC 32 7417#define TK_ATTACH 33 7418#define TK_BEFORE 34 7419#define TK_BY 35 7420#define TK_CASCADE 36 7421#define TK_CAST 37 7422#define TK_COLUMNKW 38 7423#define TK_CONFLICT 39 7424#define TK_DATABASE 40 7425#define TK_DESC 41 7426#define TK_DETACH 42 7427#define TK_EACH 43 7428#define TK_FAIL 44 7429#define TK_FOR 45 7430#define TK_IGNORE 46 7431#define TK_INITIALLY 47 7432#define TK_INSTEAD 48 7433#define TK_LIKE_KW 49 7434#define TK_MATCH 50 7435#define TK_NO 51 7436#define TK_KEY 52 7437#define TK_OF 53 7438#define TK_OFFSET 54 7439#define TK_PRAGMA 55 7440#define TK_RAISE 56 7441#define TK_REPLACE 57 7442#define TK_RESTRICT 58 7443#define TK_ROW 59 7444#define TK_TRIGGER 60 7445#define TK_VACUUM 61 7446#define TK_VIEW 62 7447#define TK_VIRTUAL 63 7448#define TK_REINDEX 64 7449#define TK_RENAME 65 7450#define TK_CTIME_KW 66 7451#define TK_ANY 67 7452#define TK_OR 68 7453#define TK_AND 69 7454#define TK_IS 70 7455#define TK_BETWEEN 71 7456#define TK_IN 72 7457#define TK_ISNULL 73 7458#define TK_NOTNULL 74 7459#define TK_NE 75 7460#define TK_EQ 76 7461#define TK_GT 77 7462#define TK_LE 78 7463#define TK_LT 79 7464#define TK_GE 80 7465#define TK_ESCAPE 81 7466#define TK_BITAND 82 7467#define TK_BITOR 83 7468#define TK_LSHIFT 84 7469#define TK_RSHIFT 85 7470#define TK_PLUS 86 7471#define TK_MINUS 87 7472#define TK_STAR 88 7473#define TK_SLASH 89 7474#define TK_REM 90 7475#define TK_CONCAT 91 7476#define TK_COLLATE 92 7477#define TK_BITNOT 93 7478#define TK_STRING 94 7479#define TK_JOIN_KW 95 7480#define TK_CONSTRAINT 96 7481#define TK_DEFAULT 97 7482#define TK_NULL 98 7483#define TK_PRIMARY 99 7484#define TK_UNIQUE 100 7485#define TK_CHECK 101 7486#define TK_REFERENCES 102 7487#define TK_AUTOINCR 103 7488#define TK_ON 104 7489#define TK_INSERT 105 7490#define TK_DELETE 106 7491#define TK_UPDATE 107 7492#define TK_SET 108 7493#define TK_DEFERRABLE 109 7494#define TK_FOREIGN 110 7495#define TK_DROP 111 7496#define TK_UNION 112 7497#define TK_ALL 113 7498#define TK_EXCEPT 114 7499#define TK_INTERSECT 115 7500#define TK_SELECT 116 7501#define TK_DISTINCT 117 7502#define TK_DOT 118 7503#define TK_FROM 119 7504#define TK_JOIN 120 7505#define TK_USING 121 7506#define TK_ORDER 122 7507#define TK_GROUP 123 7508#define TK_HAVING 124 7509#define TK_LIMIT 125 7510#define TK_WHERE 126 7511#define TK_INTO 127 7512#define TK_VALUES 128 7513#define TK_INTEGER 129 7514#define TK_FLOAT 130 7515#define TK_BLOB 131 7516#define TK_REGISTER 132 7517#define TK_VARIABLE 133 7518#define TK_CASE 134 7519#define TK_WHEN 135 7520#define TK_THEN 136 7521#define TK_ELSE 137 7522#define TK_INDEX 138 7523#define TK_ALTER 139 7524#define TK_ADD 140 7525#define TK_TO_TEXT 141 7526#define TK_TO_BLOB 142 7527#define TK_TO_NUMERIC 143 7528#define TK_TO_INT 144 7529#define TK_TO_REAL 145 7530#define TK_ISNOT 146 7531#define TK_END_OF_FILE 147 7532#define TK_ILLEGAL 148 7533#define TK_SPACE 149 7534#define TK_UNCLOSED_STRING 150 7535#define TK_FUNCTION 151 7536#define TK_COLUMN 152 7537#define TK_AGG_FUNCTION 153 7538#define TK_AGG_COLUMN 154 7539#define TK_CONST_FUNC 155 7540#define TK_UMINUS 156 7541#define TK_UPLUS 157 7542 7543/************** End of parse.h ***********************************************/ 7544/************** Continuing where we left off in sqliteInt.h ******************/ 7545#include <stdio.h> 7546#include <stdlib.h> 7547#include <string.h> 7548#include <assert.h> 7549#include <stddef.h> 7550 7551/* 7552** If compiling for a processor that lacks floating point support, 7553** substitute integer for floating-point 7554*/ 7555#ifdef SQLITE_OMIT_FLOATING_POINT 7556# define double sqlite_int64 7557# define float sqlite_int64 7558# define LONGDOUBLE_TYPE sqlite_int64 7559# ifndef SQLITE_BIG_DBL 7560# define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) 7561# endif 7562# define SQLITE_OMIT_DATETIME_FUNCS 1 7563# define SQLITE_OMIT_TRACE 1 7564# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT 7565# undef SQLITE_HAVE_ISNAN 7566#endif 7567#ifndef SQLITE_BIG_DBL 7568# define SQLITE_BIG_DBL (1e99) 7569#endif 7570 7571/* 7572** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 7573** afterward. Having this macro allows us to cause the C compiler 7574** to omit code used by TEMP tables without messy #ifndef statements. 7575*/ 7576#ifdef SQLITE_OMIT_TEMPDB 7577#define OMIT_TEMPDB 1 7578#else 7579#define OMIT_TEMPDB 0 7580#endif 7581 7582/* 7583** The "file format" number is an integer that is incremented whenever 7584** the VDBE-level file format changes. The following macros define the 7585** the default file format for new databases and the maximum file format 7586** that the library can read. 7587*/ 7588#define SQLITE_MAX_FILE_FORMAT 4 7589#ifndef SQLITE_DEFAULT_FILE_FORMAT 7590# define SQLITE_DEFAULT_FILE_FORMAT 1 7591#endif 7592 7593/* 7594** Determine whether triggers are recursive by default. This can be 7595** changed at run-time using a pragma. 7596*/ 7597#ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS 7598# define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0 7599#endif 7600 7601/* 7602** Provide a default value for SQLITE_TEMP_STORE in case it is not specified 7603** on the command-line 7604*/ 7605#ifndef SQLITE_TEMP_STORE 7606# define SQLITE_TEMP_STORE 1 7607#endif 7608 7609/* 7610** GCC does not define the offsetof() macro so we'll have to do it 7611** ourselves. 7612*/ 7613#ifndef offsetof 7614#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) 7615#endif 7616 7617/* 7618** Check to see if this machine uses EBCDIC. (Yes, believe it or 7619** not, there are still machines out there that use EBCDIC.) 7620*/ 7621#if 'A' == '\301' 7622# define SQLITE_EBCDIC 1 7623#else 7624# define SQLITE_ASCII 1 7625#endif 7626 7627/* 7628** Integers of known sizes. These typedefs might change for architectures 7629** where the sizes very. Preprocessor macros are available so that the 7630** types can be conveniently redefined at compile-type. Like this: 7631** 7632** cc '-DUINTPTR_TYPE=long long int' ... 7633*/ 7634#ifndef UINT32_TYPE 7635# ifdef HAVE_UINT32_T 7636# define UINT32_TYPE uint32_t 7637# else 7638# define UINT32_TYPE unsigned int 7639# endif 7640#endif 7641#ifndef UINT16_TYPE 7642# ifdef HAVE_UINT16_T 7643# define UINT16_TYPE uint16_t 7644# else 7645# define UINT16_TYPE unsigned short int 7646# endif 7647#endif 7648#ifndef INT16_TYPE 7649# ifdef HAVE_INT16_T 7650# define INT16_TYPE int16_t 7651# else 7652# define INT16_TYPE short int 7653# endif 7654#endif 7655#ifndef UINT8_TYPE 7656# ifdef HAVE_UINT8_T 7657# define UINT8_TYPE uint8_t 7658# else 7659# define UINT8_TYPE unsigned char 7660# endif 7661#endif 7662#ifndef INT8_TYPE 7663# ifdef HAVE_INT8_T 7664# define INT8_TYPE int8_t 7665# else 7666# define INT8_TYPE signed char 7667# endif 7668#endif 7669#ifndef LONGDOUBLE_TYPE 7670# define LONGDOUBLE_TYPE long double 7671#endif 7672typedef sqlite_int64 i64; /* 8-byte signed integer */ 7673typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ 7674typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ 7675typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ 7676typedef INT16_TYPE i16; /* 2-byte signed integer */ 7677typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ 7678typedef INT8_TYPE i8; /* 1-byte signed integer */ 7679 7680/* 7681** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value 7682** that can be stored in a u32 without loss of data. The value 7683** is 0x00000000ffffffff. But because of quirks of some compilers, we 7684** have to specify the value in the less intuitive manner shown: 7685*/ 7686#define SQLITE_MAX_U32 ((((u64)1)<<32)-1) 7687 7688/* 7689** Macros to determine whether the machine is big or little endian, 7690** evaluated at runtime. 7691*/ 7692#ifdef SQLITE_AMALGAMATION 7693SQLITE_PRIVATE const int sqlite3one = 1; 7694#else 7695SQLITE_PRIVATE const int sqlite3one; 7696#endif 7697#if defined(i386) || defined(__i386__) || defined(_M_IX86)\ 7698 || defined(__x86_64) || defined(__x86_64__) 7699# define SQLITE_BIGENDIAN 0 7700# define SQLITE_LITTLEENDIAN 1 7701# define SQLITE_UTF16NATIVE SQLITE_UTF16LE 7702#else 7703# define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) 7704# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) 7705# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) 7706#endif 7707 7708/* 7709** Constants for the largest and smallest possible 64-bit signed integers. 7710** These macros are designed to work correctly on both 32-bit and 64-bit 7711** compilers. 7712*/ 7713#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) 7714#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) 7715 7716/* 7717** Round up a number to the next larger multiple of 8. This is used 7718** to force 8-byte alignment on 64-bit architectures. 7719*/ 7720#define ROUND8(x) (((x)+7)&~7) 7721 7722/* 7723** Round down to the nearest multiple of 8 7724*/ 7725#define ROUNDDOWN8(x) ((x)&~7) 7726 7727/* 7728** Assert that the pointer X is aligned to an 8-byte boundary. This 7729** macro is used only within assert() to verify that the code gets 7730** all alignment restrictions correct. 7731** 7732** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the 7733** underlying malloc() implemention might return us 4-byte aligned 7734** pointers. In that case, only verify 4-byte alignment. 7735*/ 7736#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC 7737# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0) 7738#else 7739# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0) 7740#endif 7741 7742 7743/* 7744** An instance of the following structure is used to store the busy-handler 7745** callback for a given sqlite handle. 7746** 7747** The sqlite.busyHandler member of the sqlite struct contains the busy 7748** callback for the database handle. Each pager opened via the sqlite 7749** handle is passed a pointer to sqlite.busyHandler. The busy-handler 7750** callback is currently invoked only from within pager.c. 7751*/ 7752typedef struct BusyHandler BusyHandler; 7753struct BusyHandler { 7754 int (*xFunc)(void *,int); /* The busy callback */ 7755 void *pArg; /* First arg to busy callback */ 7756 int nBusy; /* Incremented with each busy call */ 7757}; 7758 7759/* 7760** Name of the master database table. The master database table 7761** is a special table that holds the names and attributes of all 7762** user tables and indices. 7763*/ 7764#define MASTER_NAME "sqlite_master" 7765#define TEMP_MASTER_NAME "sqlite_temp_master" 7766 7767/* 7768** The root-page of the master database table. 7769*/ 7770#define MASTER_ROOT 1 7771 7772/* 7773** The name of the schema table. 7774*/ 7775#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) 7776 7777/* 7778** A convenience macro that returns the number of elements in 7779** an array. 7780*/ 7781#define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0]))) 7782 7783/* 7784** The following value as a destructor means to use sqlite3DbFree(). 7785** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT. 7786*/ 7787#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree) 7788 7789/* 7790** When SQLITE_OMIT_WSD is defined, it means that the target platform does 7791** not support Writable Static Data (WSD) such as global and static variables. 7792** All variables must either be on the stack or dynamically allocated from 7793** the heap. When WSD is unsupported, the variable declarations scattered 7794** throughout the SQLite code must become constants instead. The SQLITE_WSD 7795** macro is used for this purpose. And instead of referencing the variable 7796** directly, we use its constant as a key to lookup the run-time allocated 7797** buffer that holds real variable. The constant is also the initializer 7798** for the run-time allocated buffer. 7799** 7800** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL 7801** macros become no-ops and have zero performance impact. 7802*/ 7803#ifdef SQLITE_OMIT_WSD 7804 #define SQLITE_WSD const 7805 #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) 7806 #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) 7807SQLITE_API int sqlite3_wsd_init(int N, int J); 7808SQLITE_API void *sqlite3_wsd_find(void *K, int L); 7809#else 7810 #define SQLITE_WSD 7811 #define GLOBAL(t,v) v 7812 #define sqlite3GlobalConfig sqlite3Config 7813#endif 7814 7815/* 7816** The following macros are used to suppress compiler warnings and to 7817** make it clear to human readers when a function parameter is deliberately 7818** left unused within the body of a function. This usually happens when 7819** a function is called via a function pointer. For example the 7820** implementation of an SQL aggregate step callback may not use the 7821** parameter indicating the number of arguments passed to the aggregate, 7822** if it knows that this is enforced elsewhere. 7823** 7824** When a function parameter is not used at all within the body of a function, 7825** it is generally named "NotUsed" or "NotUsed2" to make things even clearer. 7826** However, these macros may also be used to suppress warnings related to 7827** parameters that may or may not be used depending on compilation options. 7828** For example those parameters only used in assert() statements. In these 7829** cases the parameters are named as per the usual conventions. 7830*/ 7831#define UNUSED_PARAMETER(x) (void)(x) 7832#define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y) 7833 7834/* 7835** Forward references to structures 7836*/ 7837typedef struct AggInfo AggInfo; 7838typedef struct AuthContext AuthContext; 7839typedef struct AutoincInfo AutoincInfo; 7840typedef struct Bitvec Bitvec; 7841typedef struct CollSeq CollSeq; 7842typedef struct Column Column; 7843typedef struct Db Db; 7844typedef struct Schema Schema; 7845typedef struct Expr Expr; 7846typedef struct ExprList ExprList; 7847typedef struct ExprSpan ExprSpan; 7848typedef struct FKey FKey; 7849typedef struct FuncDestructor FuncDestructor; 7850typedef struct