sqlite3-binding.h (690206B)
1 #ifndef USE_LIBSQLITE3 2 /* 3 ** 2001-09-15 4 ** 5 ** The author disclaims copyright to this source code. In place of 6 ** a legal notice, here is a blessing: 7 ** 8 ** May you do good and not evil. 9 ** May you find forgiveness for yourself and forgive others. 10 ** May you share freely, never taking more than you give. 11 ** 12 ************************************************************************* 13 ** This header file defines the interface that the SQLite library 14 ** presents to client programs. If a C-function, structure, datatype, 15 ** or constant definition does not appear in this file, then it is 16 ** not a published API of SQLite, is subject to change without 17 ** notice, and should not be referenced by programs that use SQLite. 18 ** 19 ** Some of the definitions that are in this file are marked as 20 ** "experimental". Experimental interfaces are normally new 21 ** features recently added to SQLite. We do not anticipate changes 22 ** to experimental interfaces but reserve the right to make minor changes 23 ** if experience from use "in the wild" suggest such changes are prudent. 24 ** 25 ** The official C-language API documentation for SQLite is derived 26 ** from comments in this file. This file is the authoritative source 27 ** on how SQLite interfaces are supposed to operate. 28 ** 29 ** The name of this file under configuration management is "sqlite.h.in". 30 ** The makefile makes some minor changes to this file (such as inserting 31 ** the version number) and changes its name to "sqlite3.h" as 32 ** part of the build process. 33 */ 34 #ifndef SQLITE3_H 35 #define SQLITE3_H 36 #include <stdarg.h> /* Needed for the definition of va_list */ 37 38 /* 39 ** Make sure we can call this stuff from C++. 40 */ 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 46 /* 47 ** Facilitate override of interface linkage and calling conventions. 48 ** Be aware that these macros may not be used within this particular 49 ** translation of the amalgamation and its associated header file. 50 ** 51 ** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the 52 ** compiler that the target identifier should have external linkage. 53 ** 54 ** The SQLITE_CDECL macro is used to set the calling convention for 55 ** public functions that accept a variable number of arguments. 56 ** 57 ** The SQLITE_APICALL macro is used to set the calling convention for 58 ** public functions that accept a fixed number of arguments. 59 ** 60 ** The SQLITE_STDCALL macro is no longer used and is now deprecated. 61 ** 62 ** The SQLITE_CALLBACK macro is used to set the calling convention for 63 ** function pointers. 64 ** 65 ** The SQLITE_SYSAPI macro is used to set the calling convention for 66 ** functions provided by the operating system. 67 ** 68 ** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and 69 ** SQLITE_SYSAPI macros are used only when building for environments 70 ** that require non-default calling conventions. 71 */ 72 #ifndef SQLITE_EXTERN 73 # define SQLITE_EXTERN extern 74 #endif 75 #ifndef SQLITE_API 76 # define SQLITE_API 77 #endif 78 #ifndef SQLITE_CDECL 79 # define SQLITE_CDECL 80 #endif 81 #ifndef SQLITE_APICALL 82 # define SQLITE_APICALL 83 #endif 84 #ifndef SQLITE_STDCALL 85 # define SQLITE_STDCALL SQLITE_APICALL 86 #endif 87 #ifndef SQLITE_CALLBACK 88 # define SQLITE_CALLBACK 89 #endif 90 #ifndef SQLITE_SYSAPI 91 # define SQLITE_SYSAPI 92 #endif 93 94 /* 95 ** These no-op macros are used in front of interfaces to mark those 96 ** interfaces as either deprecated or experimental. New applications 97 ** should not use deprecated interfaces - they are supported for backwards 98 ** compatibility only. Application writers should be aware that 99 ** experimental interfaces are subject to change in point releases. 100 ** 101 ** These macros used to resolve to various kinds of compiler magic that 102 ** would generate warning messages when they were used. But that 103 ** compiler magic ended up generating such a flurry of bug reports 104 ** that we have taken it all out and gone back to using simple 105 ** noop macros. 106 */ 107 #define SQLITE_DEPRECATED 108 #define SQLITE_EXPERIMENTAL 109 110 /* 111 ** Ensure these symbols were not defined by some previous header file. 112 */ 113 #ifdef SQLITE_VERSION 114 # undef SQLITE_VERSION 115 #endif 116 #ifdef SQLITE_VERSION_NUMBER 117 # undef SQLITE_VERSION_NUMBER 118 #endif 119 120 /* 121 ** CAPI3REF: Compile-Time Library Version Numbers 122 ** 123 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header 124 ** evaluates to a string literal that is the SQLite version in the 125 ** format "X.Y.Z" where X is the major version number (always 3 for 126 ** SQLite3) and Y is the minor version number and Z is the release number.)^ 127 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer 128 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same 129 ** numbers used in [SQLITE_VERSION].)^ 130 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also 131 ** be larger than the release from which it is derived. Either Y will 132 ** be held constant and Z will be incremented or else Y will be incremented 133 ** and Z will be reset to zero. 134 ** 135 ** Since [version 3.6.18] ([dateof:3.6.18]), 136 ** SQLite source code has been stored in the 137 ** <a href="http://fossil-scm.org/">Fossil configuration management 138 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to 139 ** a string which identifies a particular check-in of SQLite 140 ** within its configuration management system. ^The SQLITE_SOURCE_ID 141 ** string contains the date and time of the check-in (UTC) and a SHA1 142 ** or SHA3-256 hash of the entire source tree. If the source code has 143 ** been edited in any way since it was last checked in, then the last 144 ** four hexadecimal digits of the hash may be modified. 145 ** 146 ** See also: [sqlite3_libversion()], 147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 148 ** [sqlite_version()] and [sqlite_source_id()]. 149 */ 150 #define SQLITE_VERSION "3.53.0" 151 #define SQLITE_VERSION_NUMBER 3053000 152 #define SQLITE_SOURCE_ID "2026-04-09 11:41:38 4525003a53a7fc63ca75c59b22c79608659ca12f0131f52c18637f829977f20b" 153 #define SQLITE_SCM_BRANCH "trunk" 154 #define SQLITE_SCM_TAGS "release major-release version-3.53.0" 155 #define SQLITE_SCM_DATETIME "2026-04-09T11:41:38.498Z" 156 157 /* 158 ** CAPI3REF: Run-Time Library Version Numbers 159 ** KEYWORDS: sqlite3_version sqlite3_sourceid 160 ** 161 ** These interfaces provide the same information as the [SQLITE_VERSION], 162 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 163 ** but are associated with the library instead of the header file. ^(Cautious 164 ** programmers might include assert() statements in their application to 165 ** verify that values returned by these interfaces match the macros in 166 ** the header, and thus ensure that the application is 167 ** compiled with matching library and header files. 168 ** 169 ** <blockquote><pre> 170 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); 171 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 ); 172 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); 173 ** </pre></blockquote>)^ 174 ** 175 ** ^The sqlite3_version[] string constant contains the text of the 176 ** [SQLITE_VERSION] macro. ^The sqlite3_libversion() function returns a 177 ** pointer to the sqlite3_version[] string constant. The sqlite3_libversion() 178 ** function is provided for use in DLLs since DLL users usually do not have 179 ** direct access to string constants within the DLL. ^The 180 ** sqlite3_libversion_number() function returns an integer equal to 181 ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns 182 ** a pointer to a string constant whose value is the same as the 183 ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built 184 ** using an edited copy of [the amalgamation], then the last four characters 185 ** of the hash might be different from [SQLITE_SOURCE_ID].)^ 186 ** 187 ** See also: [sqlite_version()] and [sqlite_source_id()]. 188 */ 189 SQLITE_API SQLITE_EXTERN const char sqlite3_version[]; 190 SQLITE_API const char *sqlite3_libversion(void); 191 SQLITE_API const char *sqlite3_sourceid(void); 192 SQLITE_API int sqlite3_libversion_number(void); 193 194 /* 195 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics 196 ** 197 ** ^The sqlite3_compileoption_used() function returns 0 or 1 198 ** indicating whether the specified option was defined at 199 ** compile time. ^The SQLITE_ prefix may be omitted from the 200 ** option name passed to sqlite3_compileoption_used(). 201 ** 202 ** ^The sqlite3_compileoption_get() function allows iterating 203 ** over the list of options that were defined at compile time by 204 ** returning the N-th compile time option string. ^If N is out of range, 205 ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ 206 ** prefix is omitted from any strings returned by 207 ** sqlite3_compileoption_get(). 208 ** 209 ** ^Support for the diagnostic functions sqlite3_compileoption_used() 210 ** and sqlite3_compileoption_get() may be omitted by specifying the 211 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. 212 ** 213 ** See also: SQL functions [sqlite_compileoption_used()] and 214 ** [sqlite_compileoption_get()] and the [compile_options pragma]. 215 */ 216 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 217 SQLITE_API int sqlite3_compileoption_used(const char *zOptName); 218 SQLITE_API const char *sqlite3_compileoption_get(int N); 219 #else 220 # define sqlite3_compileoption_used(X) 0 221 # define sqlite3_compileoption_get(X) ((void*)0) 222 #endif 223 224 /* 225 ** CAPI3REF: Test To See If The Library Is Threadsafe 226 ** 227 ** ^The sqlite3_threadsafe() function returns zero if and only if 228 ** SQLite was compiled with mutexing code omitted due to the 229 ** [SQLITE_THREADSAFE] compile-time option being set to 0. 230 ** 231 ** SQLite can be compiled with or without mutexes. When 232 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 233 ** are enabled and SQLite is threadsafe. When the 234 ** [SQLITE_THREADSAFE] macro is 0, 235 ** the mutexes are omitted. Without the mutexes, it is not safe 236 ** to use SQLite concurrently from more than one thread. 237 ** 238 ** Enabling mutexes incurs a measurable performance penalty. 239 ** So if speed is of utmost importance, it makes sense to disable 240 ** the mutexes. But for maximum safety, mutexes should be enabled. 241 ** ^The default behavior is for mutexes to be enabled. 242 ** 243 ** This interface can be used by an application to make sure that the 244 ** version of SQLite that it is linking against was compiled with 245 ** the desired setting of the [SQLITE_THREADSAFE] macro. 246 ** 247 ** This interface only reports on the compile-time mutex setting 248 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with 249 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but 250 ** can be fully or partially disabled using a call to [sqlite3_config()] 251 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], 252 ** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the 253 ** sqlite3_threadsafe() function shows only the compile-time setting of 254 ** thread safety, not any run-time changes to that setting made by 255 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() 256 ** is unchanged by calls to sqlite3_config().)^ 257 ** 258 ** See the [threading mode] documentation for additional information. 259 */ 260 SQLITE_API int sqlite3_threadsafe(void); 261 262 /* 263 ** CAPI3REF: Database Connection Handle 264 ** KEYWORDS: {database connection} {database connections} 265 ** 266 ** Each open SQLite database is represented by a pointer to an instance of 267 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 268 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and 269 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] 270 ** and [sqlite3_close_v2()] are its destructors. There are many other 271 ** interfaces (such as 272 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and 273 ** [sqlite3_busy_timeout()] to name but three) that are methods on an 274 ** sqlite3 object. 275 */ 276 typedef struct sqlite3 sqlite3; 277 278 /* 279 ** CAPI3REF: 64-Bit Integer Types 280 ** KEYWORDS: sqlite_int64 sqlite_uint64 281 ** 282 ** Because there is no cross-platform way to specify 64-bit integer types 283 ** SQLite includes typedefs for 64-bit signed and unsigned integers. 284 ** 285 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. 286 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards 287 ** compatibility only. 288 ** 289 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values 290 ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The 291 ** sqlite3_uint64 and sqlite_uint64 types can store integer values 292 ** between 0 and +18446744073709551615 inclusive. 293 */ 294 #ifdef SQLITE_INT64_TYPE 295 typedef SQLITE_INT64_TYPE sqlite_int64; 296 # ifdef SQLITE_UINT64_TYPE 297 typedef SQLITE_UINT64_TYPE sqlite_uint64; 298 # else 299 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; 300 # endif 301 #elif defined(_MSC_VER) || defined(__BORLANDC__) 302 typedef __int64 sqlite_int64; 303 typedef unsigned __int64 sqlite_uint64; 304 #else 305 typedef long long int sqlite_int64; 306 typedef unsigned long long int sqlite_uint64; 307 #endif 308 typedef sqlite_int64 sqlite3_int64; 309 typedef sqlite_uint64 sqlite3_uint64; 310 311 /* 312 ** If compiling for a processor that lacks floating point support, 313 ** substitute integer for floating-point. 314 */ 315 #ifdef SQLITE_OMIT_FLOATING_POINT 316 # define double sqlite3_int64 317 #endif 318 319 /* 320 ** CAPI3REF: Closing A Database Connection 321 ** DESTRUCTOR: sqlite3 322 ** 323 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors 324 ** for the [sqlite3] object. 325 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if 326 ** the [sqlite3] object is successfully destroyed and all associated 327 ** resources are deallocated. 328 ** 329 ** Ideally, applications should [sqlite3_finalize | finalize] all 330 ** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and 331 ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated 332 ** with the [sqlite3] object prior to attempting to close the object. 333 ** ^If the database connection is associated with unfinalized prepared 334 ** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then 335 ** sqlite3_close() will leave the database connection open and return 336 ** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared 337 ** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups, 338 ** it returns [SQLITE_OK] regardless, but instead of deallocating the database 339 ** connection immediately, it marks the database connection as an unusable 340 ** "zombie" and makes arrangements to automatically deallocate the database 341 ** connection after all prepared statements are finalized, all BLOB handles 342 ** are closed, and all backups have finished. The sqlite3_close_v2() interface 343 ** is intended for use with host languages that are garbage collected, and 344 ** where the order in which destructors are called is arbitrary. 345 ** 346 ** ^If an [sqlite3] object is destroyed while a transaction is open, 347 ** the transaction is automatically rolled back. 348 ** 349 ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)] 350 ** must be either a NULL 351 ** pointer or an [sqlite3] object pointer obtained 352 ** from [sqlite3_open()], [sqlite3_open16()], or 353 ** [sqlite3_open_v2()], and not previously closed. 354 ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer 355 ** argument is a harmless no-op. 356 */ 357 SQLITE_API int sqlite3_close(sqlite3*); 358 SQLITE_API int sqlite3_close_v2(sqlite3*); 359 360 /* 361 ** The type for a callback function. 362 ** This is legacy and deprecated. It is included for historical 363 ** compatibility and is not documented. 364 */ 365 typedef int (*sqlite3_callback)(void*,int,char**, char**); 366 367 /* 368 ** CAPI3REF: One-Step Query Execution Interface 369 ** METHOD: sqlite3 370 ** 371 ** The sqlite3_exec() interface is a convenience wrapper around 372 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], 373 ** that allows an application to run multiple statements of SQL 374 ** without having to use a lot of C code. 375 ** 376 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, 377 ** semicolon-separated SQL statements passed into its 2nd argument, 378 ** in the context of the [database connection] passed in as its 1st 379 ** argument. ^If the callback function of the 3rd argument to 380 ** sqlite3_exec() is not NULL, then it is invoked for each result row 381 ** coming out of the evaluated SQL statements. ^The 4th argument to 382 ** sqlite3_exec() is relayed through to the 1st argument of each 383 ** callback invocation. ^If the callback pointer to sqlite3_exec() 384 ** is NULL, then no callback is ever invoked and result rows are 385 ** ignored. 386 ** 387 ** ^If an error occurs while evaluating the SQL statements passed into 388 ** sqlite3_exec(), then execution of the current statement stops and 389 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() 390 ** is not NULL then any error message is written into memory obtained 391 ** from [sqlite3_malloc()] and passed back through the 5th parameter. 392 ** To avoid memory leaks, the application should invoke [sqlite3_free()] 393 ** on error message strings returned through the 5th parameter of 394 ** sqlite3_exec() after the error message string is no longer needed. 395 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors 396 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to 397 ** NULL before returning. 398 ** 399 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() 400 ** routine returns SQLITE_ABORT without invoking the callback again and 401 ** without running any subsequent SQL statements. 402 ** 403 ** ^The 2nd argument to the sqlite3_exec() callback function is the 404 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() 405 ** callback is an array of pointers to strings obtained as if from 406 ** [sqlite3_column_text()], one for each column. ^If an element of a 407 ** result row is NULL then the corresponding string pointer for the 408 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the 409 ** sqlite3_exec() callback is an array of pointers to strings where each 410 ** entry represents the name of a corresponding result column as obtained 411 ** from [sqlite3_column_name()]. 412 ** 413 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer 414 ** to an empty string, or a pointer that contains only whitespace and/or 415 ** SQL comments, then no SQL statements are evaluated and the database 416 ** is not changed. 417 ** 418 ** Restrictions: 419 ** 420 ** <ul> 421 ** <li> The application must ensure that the 1st parameter to sqlite3_exec() 422 ** is a valid and open [database connection]. 423 ** <li> The application must not close the [database connection] specified by 424 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. 425 ** <li> The application must not modify the SQL statement text passed into 426 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. 427 ** <li> The application must not dereference the arrays or string pointers 428 ** passed as the 3rd and 4th callback parameters after it returns. 429 ** </ul> 430 */ 431 SQLITE_API int sqlite3_exec( 432 sqlite3*, /* An open database */ 433 const char *sql, /* SQL to be evaluated */ 434 int (*callback)(void*,int,char**,char**), /* Callback function */ 435 void *, /* 1st argument to callback */ 436 char **errmsg /* Error msg written here */ 437 ); 438 439 /* 440 ** CAPI3REF: Result Codes 441 ** KEYWORDS: {result code definitions} 442 ** 443 ** Many SQLite functions return an integer result code from the set shown 444 ** here in order to indicate success or failure. 445 ** 446 ** New error codes may be added in future versions of SQLite. 447 ** 448 ** See also: [extended result code definitions] 449 */ 450 #define SQLITE_OK 0 /* Successful result */ 451 /* beginning-of-error-codes */ 452 #define SQLITE_ERROR 1 /* Generic error */ 453 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 454 #define SQLITE_PERM 3 /* Access permission denied */ 455 #define SQLITE_ABORT 4 /* Callback routine requested an abort */ 456 #define SQLITE_BUSY 5 /* The database file is locked */ 457 #define SQLITE_LOCKED 6 /* A table in the database is locked */ 458 #define SQLITE_NOMEM 7 /* A malloc() failed */ 459 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 460 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 461 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 462 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 463 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ 464 #define SQLITE_FULL 13 /* Insertion failed because database is full */ 465 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 466 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 467 #define SQLITE_EMPTY 16 /* Internal use only */ 468 #define SQLITE_SCHEMA 17 /* The database schema changed */ 469 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 470 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 471 #define SQLITE_MISMATCH 20 /* Data type mismatch */ 472 #define SQLITE_MISUSE 21 /* Library used incorrectly */ 473 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 474 #define SQLITE_AUTH 23 /* Authorization denied */ 475 #define SQLITE_FORMAT 24 /* Not used */ 476 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 477 #define SQLITE_NOTADB 26 /* File opened that is not a database file */ 478 #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ 479 #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ 480 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 481 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 482 /* end-of-error-codes */ 483 484 /* 485 ** CAPI3REF: Extended Result Codes 486 ** KEYWORDS: {extended result code definitions} 487 ** 488 ** In its default configuration, SQLite API routines return one of 30 integer 489 ** [result codes]. However, experience has shown that many of 490 ** these result codes are too coarse-grained. They do not provide as 491 ** much information about problems as programmers might like. In an effort to 492 ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8] 493 ** and later) include 494 ** support for additional result codes that provide more detailed information 495 ** about errors. These [extended result codes] are enabled or disabled 496 ** on a per database connection basis using the 497 ** [sqlite3_extended_result_codes()] API. Or, the extended code for 498 ** the most recent error can be obtained using 499 ** [sqlite3_extended_errcode()]. 500 */ 501 #define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) 502 #define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) 503 #define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8)) 504 #define SQLITE_ERROR_RESERVESIZE (SQLITE_ERROR | (4<<8)) 505 #define SQLITE_ERROR_KEY (SQLITE_ERROR | (5<<8)) 506 #define SQLITE_ERROR_UNABLE (SQLITE_ERROR | (6<<8)) 507 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 508 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 509 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 510 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 511 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 512 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 513 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 514 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 515 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 516 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 517 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 518 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 519 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 520 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 521 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 522 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 523 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 524 #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) 525 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 526 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 527 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) 528 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) 529 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) 530 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) 531 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) 532 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) 533 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) 534 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) 535 #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8)) 536 #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8)) 537 #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8)) 538 #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) 539 #define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8)) 540 #define SQLITE_IOERR_IN_PAGE (SQLITE_IOERR | (34<<8)) 541 #define SQLITE_IOERR_BADKEY (SQLITE_IOERR | (35<<8)) 542 #define SQLITE_IOERR_CODEC (SQLITE_IOERR | (36<<8)) 543 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 544 #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) 545 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 546 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) 547 #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8)) 548 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 549 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) 550 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) 551 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) 552 #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ 553 #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) 554 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 555 #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) 556 #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) 557 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 558 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 559 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) 560 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) 561 #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) 562 #define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) 563 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) 564 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) 565 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) 566 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) 567 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) 568 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) 569 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) 570 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) 571 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) 572 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) 573 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) 574 #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8)) 575 #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8)) 576 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) 577 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) 578 #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8)) 579 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) 580 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) 581 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) 582 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal only */ 583 584 /* 585 ** CAPI3REF: Flags For File Open Operations 586 ** 587 ** These bit values are intended for use in the 588 ** 3rd parameter to the [sqlite3_open_v2()] interface and 589 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. 590 ** 591 ** Only those flags marked as "Ok for sqlite3_open_v2()" may be 592 ** used as the third argument to the [sqlite3_open_v2()] interface. 593 ** The other flags have historically been ignored by sqlite3_open_v2(), 594 ** though future versions of SQLite might change so that an error is 595 ** raised if any of the disallowed bits are passed into sqlite3_open_v2(). 596 ** Applications should not depend on the historical behavior. 597 ** 598 ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into 599 ** [sqlite3_open_v2()] does *not* cause the underlying database file 600 ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into 601 ** [sqlite3_open_v2()] has historically been a no-op and might become an 602 ** error in future versions of SQLite. 603 */ 604 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 605 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 606 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 607 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 608 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 609 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 610 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ 611 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ 612 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 613 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 614 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 615 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 616 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 617 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 618 #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */ 619 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 620 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 621 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 622 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 623 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ 624 #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ 625 #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ 626 627 /* Reserved: 0x00F00000 */ 628 /* Legacy compatibility: */ 629 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 630 631 632 /* 633 ** CAPI3REF: Device Characteristics 634 ** 635 ** The xDeviceCharacteristics method of the [sqlite3_io_methods] 636 ** object returns an integer which is a vector of these 637 ** bit values expressing I/O characteristics of the mass storage 638 ** device that holds the file that the [sqlite3_io_methods] 639 ** refers to. 640 ** 641 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 642 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 643 ** mean that writes of blocks that are nnn bytes in size and 644 ** are aligned to an address which is an integer multiple of 645 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 646 ** that when data is appended to a file, the data is appended 647 ** first then the size of the file is extended, never the other 648 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 649 ** information is written to disk in the same order as calls 650 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that 651 ** after reboot following a crash or power loss, the only bytes in a 652 ** file that were written at the application level might have changed 653 ** and that adjacent bytes, even bytes within the same sector are 654 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 655 ** flag indicates that a file cannot be deleted when open. The 656 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on 657 ** read-only media and cannot be changed even by processes with 658 ** elevated privileges. 659 ** 660 ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying 661 ** filesystem supports doing multiple write operations atomically when those 662 ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and 663 ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. 664 ** 665 ** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read 666 ** from the database file in amounts that are not a multiple of the 667 ** page size and that do not begin at a page boundary. Without this 668 ** property, SQLite is careful to only do full-page reads and write 669 ** on aligned pages, with the one exception that it will do a sub-page 670 ** read of the first page to access the database header. 671 */ 672 #define SQLITE_IOCAP_ATOMIC 0x00000001 673 #define SQLITE_IOCAP_ATOMIC512 0x00000002 674 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 675 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 676 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 677 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 678 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 679 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 680 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 681 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 682 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 683 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 684 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 685 #define SQLITE_IOCAP_IMMUTABLE 0x00002000 686 #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000 687 #define SQLITE_IOCAP_SUBPAGE_READ 0x00008000 688 689 /* 690 ** CAPI3REF: File Locking Levels 691 ** 692 ** SQLite uses one of these integer values as the second 693 ** argument to calls it makes to the xLock() and xUnlock() methods 694 ** of an [sqlite3_io_methods] object. These values are ordered from 695 ** least restrictive to most restrictive. 696 ** 697 ** The argument to xLock() is always SHARED or higher. The argument to 698 ** xUnlock is either SHARED or NONE. 699 */ 700 #define SQLITE_LOCK_NONE 0 /* xUnlock() only */ 701 #define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */ 702 #define SQLITE_LOCK_RESERVED 2 /* xLock() only */ 703 #define SQLITE_LOCK_PENDING 3 /* xLock() only */ 704 #define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */ 705 706 /* 707 ** CAPI3REF: Synchronization Type Flags 708 ** 709 ** When SQLite invokes the xSync() method of an 710 ** [sqlite3_io_methods] object it uses a combination of 711 ** these integer values as the second argument. 712 ** 713 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the 714 ** sync operation only needs to flush data to mass storage. Inode 715 ** information need not be flushed. If the lower four bits of the flag 716 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. 717 ** If the lower four bits equal SQLITE_SYNC_FULL, that means 718 ** to use Mac OS X style fullsync instead of fsync(). 719 ** 720 ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags 721 ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL 722 ** settings. The [synchronous pragma] determines when calls to the 723 ** xSync VFS method occur and applies uniformly across all platforms. 724 ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how 725 ** energetic or rigorous or forceful the sync operations are and 726 ** only make a difference on Mac OSX for the default SQLite code. 727 ** (Third-party VFS implementations might also make the distinction 728 ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the 729 ** operating systems natively supported by SQLite, only Mac OSX 730 ** cares about the difference.) 731 */ 732 #define SQLITE_SYNC_NORMAL 0x00002 733 #define SQLITE_SYNC_FULL 0x00003 734 #define SQLITE_SYNC_DATAONLY 0x00010 735 736 /* 737 ** CAPI3REF: OS Interface Open File Handle 738 ** 739 ** An [sqlite3_file] object represents an open file in the 740 ** [sqlite3_vfs | OS interface layer]. Individual OS interface 741 ** implementations will 742 ** want to subclass this object by appending additional fields 743 ** for their own use. The pMethods entry is a pointer to an 744 ** [sqlite3_io_methods] object that defines methods for performing 745 ** I/O operations on the open file. 746 */ 747 typedef struct sqlite3_file sqlite3_file; 748 struct sqlite3_file { 749 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 750 }; 751 752 /* 753 ** CAPI3REF: OS Interface File Virtual Methods Object 754 ** 755 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an 756 ** [sqlite3_file] object (or, more commonly, a subclass of the 757 ** [sqlite3_file] object) with a pointer to an instance of this object. 758 ** This object defines the methods used to perform various operations 759 ** against the open file represented by the [sqlite3_file] object. 760 ** 761 ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element 762 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 763 ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The 764 ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] 765 ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element 766 ** to NULL. 767 ** 768 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 769 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 770 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 771 ** flag may be ORed in to indicate that only the data of the file 772 ** and not its inode needs to be synced. 773 ** 774 ** The integer values to xLock() and xUnlock() are one of 775 ** <ul> 776 ** <li> [SQLITE_LOCK_NONE], 777 ** <li> [SQLITE_LOCK_SHARED], 778 ** <li> [SQLITE_LOCK_RESERVED], 779 ** <li> [SQLITE_LOCK_PENDING], or 780 ** <li> [SQLITE_LOCK_EXCLUSIVE]. 781 ** </ul> 782 ** xLock() upgrades the database file lock. In other words, xLock() moves the 783 ** database file lock in the direction NONE toward EXCLUSIVE. The argument to 784 ** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never 785 ** SQLITE_LOCK_NONE. If the database file lock is already at or above the 786 ** requested lock, then the call to xLock() is a no-op. 787 ** xUnlock() downgrades the database file lock to either SHARED or NONE. 788 ** If the lock is already at or below the requested lock state, then the call 789 ** to xUnlock() is a no-op. 790 ** The xCheckReservedLock() method checks whether any database connection, 791 ** either in this process or in some other process, is holding a RESERVED, 792 ** PENDING, or EXCLUSIVE lock on the file. It returns, via its output 793 ** pointer parameter, true if such a lock exists and false otherwise. 794 ** 795 ** The xFileControl() method is a generic interface that allows custom 796 ** VFS implementations to directly control an open file using the 797 ** [sqlite3_file_control()] interface. The second "op" argument is an 798 ** integer opcode. The third argument is a generic pointer intended to 799 ** point to a structure that may contain arguments or space in which to 800 ** write return values. Potential uses for xFileControl() might be 801 ** functions to enable blocking locks with timeouts, to change the 802 ** locking strategy (for example to use dot-file locks), to inquire 803 ** about the status of a lock, or to break stale locks. The SQLite 804 ** core reserves all opcodes less than 100 for its own use. 805 ** A [file control opcodes | list of opcodes] less than 100 is available. 806 ** Applications that define a custom xFileControl method should use opcodes 807 ** greater than 100 to avoid conflicts. VFS implementations should 808 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not 809 ** recognize. 810 ** 811 ** The xSectorSize() method returns the sector size of the 812 ** device that underlies the file. The sector size is the 813 ** minimum write that can be performed without disturbing 814 ** other bytes in the file. The xDeviceCharacteristics() 815 ** method returns a bit vector describing behaviors of the 816 ** underlying device: 817 ** 818 ** <ul> 819 ** <li> [SQLITE_IOCAP_ATOMIC] 820 ** <li> [SQLITE_IOCAP_ATOMIC512] 821 ** <li> [SQLITE_IOCAP_ATOMIC1K] 822 ** <li> [SQLITE_IOCAP_ATOMIC2K] 823 ** <li> [SQLITE_IOCAP_ATOMIC4K] 824 ** <li> [SQLITE_IOCAP_ATOMIC8K] 825 ** <li> [SQLITE_IOCAP_ATOMIC16K] 826 ** <li> [SQLITE_IOCAP_ATOMIC32K] 827 ** <li> [SQLITE_IOCAP_ATOMIC64K] 828 ** <li> [SQLITE_IOCAP_SAFE_APPEND] 829 ** <li> [SQLITE_IOCAP_SEQUENTIAL] 830 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] 831 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] 832 ** <li> [SQLITE_IOCAP_IMMUTABLE] 833 ** <li> [SQLITE_IOCAP_BATCH_ATOMIC] 834 ** <li> [SQLITE_IOCAP_SUBPAGE_READ] 835 ** </ul> 836 ** 837 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 838 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 839 ** mean that writes of blocks that are nnn bytes in size and 840 ** are aligned to an address which is an integer multiple of 841 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 842 ** that when data is appended to a file, the data is appended 843 ** first then the size of the file is extended, never the other 844 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 845 ** information is written to disk in the same order as calls 846 ** to xWrite(). 847 ** 848 ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill 849 ** in the unread portions of the buffer with zeros. A VFS that 850 ** fails to zero-fill short reads might seem to work. However, 851 ** failure to zero-fill short reads will eventually lead to 852 ** database corruption. 853 */ 854 typedef struct sqlite3_io_methods sqlite3_io_methods; 855 struct sqlite3_io_methods { 856 int iVersion; 857 int (*xClose)(sqlite3_file*); 858 int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 859 int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); 860 int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); 861 int (*xSync)(sqlite3_file*, int flags); 862 int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); 863 int (*xLock)(sqlite3_file*, int); 864 int (*xUnlock)(sqlite3_file*, int); 865 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 866 int (*xFileControl)(sqlite3_file*, int op, void *pArg); 867 int (*xSectorSize)(sqlite3_file*); 868 int (*xDeviceCharacteristics)(sqlite3_file*); 869 /* Methods above are valid for version 1 */ 870 int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); 871 int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); 872 void (*xShmBarrier)(sqlite3_file*); 873 int (*xShmUnmap)(sqlite3_file*, int deleteFlag); 874 /* Methods above are valid for version 2 */ 875 int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); 876 int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p); 877 /* Methods above are valid for version 3 */ 878 /* Additional methods may be added in future releases */ 879 }; 880 881 /* 882 ** CAPI3REF: Standard File Control Opcodes 883 ** KEYWORDS: {file control opcodes} {file control opcode} 884 ** 885 ** These integer constants are opcodes for the xFileControl method 886 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 887 ** interface. 888 ** 889 ** <ul> 890 ** <li>[[SQLITE_FCNTL_LOCKSTATE]] 891 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 892 ** opcode causes the xFileControl method to write the current state of 893 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 894 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 895 ** into an integer that the pArg argument points to. 896 ** This capability is only available if SQLite is compiled with [SQLITE_DEBUG]. 897 ** 898 ** <li>[[SQLITE_FCNTL_SIZE_HINT]] 899 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS 900 ** layer a hint of how large the database file will grow to be during the 901 ** current transaction. This hint is not guaranteed to be accurate but it 902 ** is often close. The underlying VFS might choose to preallocate database 903 ** file space based on this hint in order to help writes to the database 904 ** file run faster. 905 ** 906 ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]] 907 ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that 908 ** implements [sqlite3_deserialize()] to set an upper bound on the size 909 ** of the in-memory database. The argument is a pointer to a [sqlite3_int64]. 910 ** If the integer pointed to is negative, then it is filled in with the 911 ** current limit. Otherwise the limit is set to the larger of the value 912 ** of the integer pointed to and the current database size. The integer 913 ** pointed to is set to the new limit. 914 ** 915 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]] 916 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS 917 ** extends and truncates the database file in chunks of a size specified 918 ** by the user. The fourth argument to [sqlite3_file_control()] should 919 ** point to an integer (type int) containing the new chunk-size to use 920 ** for the nominated database. Allocating database file space in large 921 ** chunks (say 1MB at a time), may reduce file-system fragmentation and 922 ** improve performance on some systems. 923 ** 924 ** <li>[[SQLITE_FCNTL_FILE_POINTER]] 925 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer 926 ** to the [sqlite3_file] object associated with a particular database 927 ** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER]. 928 ** 929 ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]] 930 ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer 931 ** to the [sqlite3_file] object associated with the journal file (either 932 ** the [rollback journal] or the [write-ahead log]) for a particular database 933 ** connection. See also [SQLITE_FCNTL_FILE_POINTER]. 934 ** 935 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] 936 ** The SQLITE_FCNTL_SYNC_OMITTED file-control is no longer used. 937 ** 938 ** <li>[[SQLITE_FCNTL_SYNC]] 939 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and 940 ** sent to the VFS immediately before the xSync method is invoked on a 941 ** database file descriptor. Or, if the xSync method is not invoked 942 ** because the user has configured SQLite with 943 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place 944 ** of the xSync method. In most cases, the pointer argument passed with 945 ** this file-control is NULL. However, if the database file is being synced 946 ** as part of a multi-database commit, the argument points to a nul-terminated 947 ** string containing the transactions super-journal file name. VFSes that 948 ** do not need this signal should silently ignore this opcode. Applications 949 ** should not call [sqlite3_file_control()] with this opcode as doing so may 950 ** disrupt the operation of the specialized VFSes that do require it. 951 ** 952 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] 953 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite 954 ** and sent to the VFS after a transaction has been committed immediately 955 ** but before the database is unlocked. VFSes that do not need this signal 956 ** should silently ignore this opcode. Applications should not call 957 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the 958 ** operation of the specialized VFSes that do require it. 959 ** 960 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] 961 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic 962 ** retry counts and intervals for certain disk I/O operations for the 963 ** windows [VFS] in order to provide robustness in the presence of 964 ** anti-virus programs. By default, the windows VFS will retry file read, 965 ** file write, and file delete operations up to 10 times, with a delay 966 ** of 25 milliseconds before the first retry and with the delay increasing 967 ** by an additional 25 milliseconds with each subsequent retry. This 968 ** opcode allows these two values (10 retries and 25 milliseconds of delay) 969 ** to be adjusted. The values are changed for all database connections 970 ** within the same process. The argument is a pointer to an array of two 971 ** integers where the first integer is the new retry count and the second 972 ** integer is the delay. If either integer is negative, then the setting 973 ** is not changed but instead the prior value of that setting is written 974 ** into the array entry, allowing the current retry settings to be 975 ** interrogated. The zDbName parameter is ignored. 976 ** 977 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 978 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 979 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary 980 ** write ahead log ([WAL file]) and shared memory 981 ** files used for transaction control 982 ** are automatically deleted when the latest connection to the database 983 ** closes. Setting persistent WAL mode causes those files to persist after 984 ** close. Persisting the files is useful when other processes that do not 985 ** have write permission on the directory containing the database file want 986 ** to read the database file, as the WAL and shared memory files must exist 987 ** in order for the database to be readable. The fourth parameter to 988 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. 989 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent 990 ** WAL mode. If the integer is -1, then it is overwritten with the current 991 ** WAL persistence setting. 992 ** 993 ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]] 994 ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the 995 ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting 996 ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the 997 ** xDeviceCharacteristics methods. The fourth parameter to 998 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. 999 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage 1000 ** mode. If the integer is -1, then it is overwritten with the current 1001 ** zero-damage mode setting. 1002 ** 1003 ** <li>[[SQLITE_FCNTL_OVERWRITE]] 1004 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening 1005 ** a write transaction to indicate that, unless it is rolled back for some 1006 ** reason, the entire database file will be overwritten by the current 1007 ** transaction. This is used by VACUUM operations. 1008 ** 1009 ** <li>[[SQLITE_FCNTL_VFSNAME]] 1010 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of 1011 ** all [VFSes] in the VFS stack. The names of all VFS shims and the 1012 ** final bottom-level VFS are written into memory obtained from 1013 ** [sqlite3_malloc()] and the result is stored in the char* variable 1014 ** that the fourth parameter of [sqlite3_file_control()] points to. 1015 ** The caller is responsible for freeing the memory when done. As with 1016 ** all file-control actions, there is no guarantee that this will actually 1017 ** do anything. Callers should initialize the char* variable to a NULL 1018 ** pointer in case this file-control is not implemented. This file-control 1019 ** is intended for diagnostic use only. 1020 ** 1021 ** <li>[[SQLITE_FCNTL_VFS_POINTER]] 1022 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level 1023 ** [VFSes] currently in use. ^(The argument X in 1024 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be 1025 ** of type "[sqlite3_vfs] **". This opcode will set *X 1026 ** to a pointer to the top-level VFS.)^ 1027 ** ^When there are multiple VFS shims in the stack, this opcode finds the 1028 ** upper-most shim only. 1029 ** 1030 ** <li>[[SQLITE_FCNTL_PRAGMA]] 1031 ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] 1032 ** file control is sent to the open [sqlite3_file] object corresponding 1033 ** to the database file to which the pragma statement refers. ^The argument 1034 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of 1035 ** pointers to strings (char**) in which the second element of the array 1036 ** is the name of the pragma and the third element is the argument to the 1037 ** pragma or NULL if the pragma has no argument. ^The handler for an 1038 ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element 1039 ** of the char** argument point to a string obtained from [sqlite3_mprintf()] 1040 ** or the equivalent and that string will become the result of the pragma or 1041 ** the error message if the pragma fails. ^If the 1042 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal 1043 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA] 1044 ** file control returns [SQLITE_OK], then the parser assumes that the 1045 ** VFS has handled the PRAGMA itself and the parser generates a no-op 1046 ** prepared statement if result string is NULL, or that returns a copy 1047 ** of the result string if the string is non-NULL. 1048 ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns 1049 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means 1050 ** that the VFS encountered an error while handling the [PRAGMA] and the 1051 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] 1052 ** file control occurs at the beginning of pragma statement analysis and so 1053 ** it is able to override built-in [PRAGMA] statements. 1054 ** 1055 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] 1056 ** ^The [SQLITE_FCNTL_BUSYHANDLER] 1057 ** file-control may be invoked by SQLite on the database file handle 1058 ** shortly after it is opened in order to provide a custom VFS with access 1059 ** to the connection's busy-handler callback. The argument is of type (void**) 1060 ** - an array of two (void *) values. The first (void *) actually points 1061 ** to a function of type (int (*)(void *)). In order to invoke the connection's 1062 ** busy-handler, this function should be invoked with the second (void *) in 1063 ** the array as the only argument. If it returns non-zero, then the operation 1064 ** should be retried. If it returns zero, the custom VFS should abandon the 1065 ** current operation. 1066 ** 1067 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]] 1068 ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control 1069 ** to have SQLite generate a 1070 ** temporary filename using the same algorithm that is followed to generate 1071 ** temporary filenames for TEMP tables and other internal uses. The 1072 ** argument should be a char** which will be filled with the filename 1073 ** written into memory obtained from [sqlite3_malloc()]. The caller should 1074 ** invoke [sqlite3_free()] on the result to avoid a memory leak. 1075 ** 1076 ** <li>[[SQLITE_FCNTL_MMAP_SIZE]] 1077 ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the 1078 ** maximum number of bytes that will be used for memory-mapped I/O. 1079 ** The argument is a pointer to a value of type sqlite3_int64 that 1080 ** is an advisory maximum number of bytes in the file to memory map. The 1081 ** pointer is overwritten with the old value. The limit is not changed if 1082 ** the value originally pointed to is negative, and so the current limit 1083 ** can be queried by passing in a pointer to a negative number. This 1084 ** file-control is used internally to implement [PRAGMA mmap_size]. 1085 ** 1086 ** <li>[[SQLITE_FCNTL_TRACE]] 1087 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information 1088 ** to the VFS about what the higher layers of the SQLite stack are doing. 1089 ** This file control is used by some VFS activity tracing [shims]. 1090 ** The argument is a zero-terminated string. Higher layers in the 1091 ** SQLite stack may generate instances of this file control if 1092 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. 1093 ** 1094 ** <li>[[SQLITE_FCNTL_HAS_MOVED]] 1095 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a 1096 ** pointer to an integer and it writes a boolean into that integer depending 1097 ** on whether or not the file has been renamed, moved, or deleted since it 1098 ** was first opened. 1099 ** 1100 ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]] 1101 ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the 1102 ** underlying native file handle associated with a file handle. This file 1103 ** control interprets its argument as a pointer to a native file handle and 1104 ** writes the resulting value there. 1105 ** 1106 ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]] 1107 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This 1108 ** opcode causes the xFileControl method to swap the file handle with the one 1109 ** pointed to by the pArg argument. This capability is used during testing 1110 ** and only needs to be supported when SQLITE_TEST is defined. 1111 ** 1112 ** <li>[[SQLITE_FCNTL_NULL_IO]] 1113 ** The [SQLITE_FCNTL_NULL_IO] opcode sets the low-level file descriptor 1114 ** or file handle for the [sqlite3_file] object such that it will no longer 1115 ** read or write to the database file. 1116 ** 1117 ** <li>[[SQLITE_FCNTL_WAL_BLOCK]] 1118 ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might 1119 ** be advantageous to block on the next WAL lock if the lock is not immediately 1120 ** available. The WAL subsystem issues this signal during rare 1121 ** circumstances in order to fix a problem with priority inversion. 1122 ** Applications should <em>not</em> use this file-control. 1123 ** 1124 ** <li>[[SQLITE_FCNTL_ZIPVFS]] 1125 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other 1126 ** VFS should return SQLITE_NOTFOUND for this opcode. 1127 ** 1128 ** <li>[[SQLITE_FCNTL_RBU]] 1129 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by 1130 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for 1131 ** this opcode. 1132 ** 1133 ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]] 1134 ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then 1135 ** the file descriptor is placed in "batch write mode", which 1136 ** means all subsequent write operations will be deferred and done 1137 ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems 1138 ** that do not support batch atomic writes will return SQLITE_NOTFOUND. 1139 ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to 1140 ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or 1141 ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make 1142 ** no VFS interface calls on the same [sqlite3_file] file descriptor 1143 ** except for calls to the xWrite method and the xFileControl method 1144 ** with [SQLITE_FCNTL_SIZE_HINT]. 1145 ** 1146 ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]] 1147 ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write 1148 ** operations since the previous successful call to 1149 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically. 1150 ** This file control returns [SQLITE_OK] if and only if the writes were 1151 ** all performed successfully and have been committed to persistent storage. 1152 ** ^Regardless of whether or not it is successful, this file control takes 1153 ** the file descriptor out of batch write mode so that all subsequent 1154 ** write operations are independent. 1155 ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without 1156 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. 1157 ** 1158 ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]] 1159 ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write 1160 ** operations since the previous successful call to 1161 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back. 1162 ** ^This file control takes the file descriptor out of batch write mode 1163 ** so that all subsequent write operations are independent. 1164 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without 1165 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]. 1166 ** 1167 ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]] 1168 ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS 1169 ** to block for up to M milliseconds before failing when attempting to 1170 ** obtain a file lock using the xLock or xShmLock methods of the VFS. 1171 ** The parameter is a pointer to a 32-bit signed integer that contains 1172 ** the value that M is to be set to. Before returning, the 32-bit signed 1173 ** integer is overwritten with the previous value of M. 1174 ** 1175 ** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]] 1176 ** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the 1177 ** VFS to block when taking a SHARED lock to connect to a wal mode database. 1178 ** This is used to implement the functionality associated with 1179 ** SQLITE_SETLK_BLOCK_ON_CONNECT. 1180 ** 1181 ** <li>[[SQLITE_FCNTL_DATA_VERSION]] 1182 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to 1183 ** a database file. The argument is a pointer to a 32-bit unsigned integer. 1184 ** The "data version" for the pager is written into the pointer. The 1185 ** "data version" changes whenever any change occurs to the corresponding 1186 ** database file, either through SQL statements on the same database 1187 ** connection or through transactions committed by separate database 1188 ** connections possibly in other processes. The [sqlite3_total_changes()] 1189 ** interface can be used to find if any database on the connection has changed, 1190 ** but that interface responds to changes on TEMP as well as MAIN and does 1191 ** not provide a mechanism to detect changes to MAIN only. Also, the 1192 ** [sqlite3_total_changes()] interface responds to internal changes only and 1193 ** omits changes made by other database connections. The 1194 ** [PRAGMA data_version] command provides a mechanism to detect changes to 1195 ** a single attached database that occur due to other database connections, 1196 ** but omits changes implemented by the database connection on which it is 1197 ** called. This file control is the only mechanism to detect changes that 1198 ** happen either internally or externally and that are associated with 1199 ** a particular attached database. 1200 ** 1201 ** <li>[[SQLITE_FCNTL_CKPT_START]] 1202 ** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint 1203 ** in wal mode before the client starts to copy pages from the wal 1204 ** file to the database file. 1205 ** 1206 ** <li>[[SQLITE_FCNTL_CKPT_DONE]] 1207 ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint 1208 ** in wal mode after the client has finished copying pages from the wal 1209 ** file to the database file, but before the *-shm file is updated to 1210 ** record the fact that the pages have been checkpointed. 1211 ** 1212 ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]] 1213 ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect 1214 ** whether or not there is a database client in another process with a wal-mode 1215 ** transaction open on the database or not. It is only available on unix. The 1216 ** (void*) argument passed with this file-control should be a pointer to a 1217 ** value of type (int). The integer value is set to 1 if the database is a wal 1218 ** mode database and there exists at least one client in another process that 1219 ** currently has an SQL transaction open on the database. It is set to 0 if 1220 ** the database is not a wal-mode db, or if there is no such connection in any 1221 ** other process. This opcode cannot be used to detect transactions opened 1222 ** by clients within the current process, only within other processes. 1223 ** 1224 ** <li>[[SQLITE_FCNTL_CKSM_FILE]] 1225 ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the 1226 ** [checksum VFS shim] only. 1227 ** 1228 ** <li>[[SQLITE_FCNTL_RESET_CACHE]] 1229 ** If there is currently no transaction open on the database, and the 1230 ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control 1231 ** purges the contents of the in-memory page cache. If there is an open 1232 ** transaction, or if the db is a temp-db, this opcode is a no-op, not an error. 1233 ** 1234 ** <li>[[SQLITE_FCNTL_FILESTAT]] 1235 ** The [SQLITE_FCNTL_FILESTAT] opcode returns low-level diagnostic information 1236 ** about the [sqlite3_file] objects used access the database and journal files 1237 ** for the given schema. The fourth parameter to [sqlite3_file_control()] 1238 ** should be an initialized [sqlite3_str] pointer. JSON text describing 1239 ** various aspects of the sqlite3_file object is appended to the sqlite3_str. 1240 ** The SQLITE_FCNTL_FILESTAT opcode is usually a no-op, unless compile-time 1241 ** options are used to enable it. 1242 ** </ul> 1243 */ 1244 #define SQLITE_FCNTL_LOCKSTATE 1 1245 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 1246 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 1247 #define SQLITE_FCNTL_LAST_ERRNO 4 1248 #define SQLITE_FCNTL_SIZE_HINT 5 1249 #define SQLITE_FCNTL_CHUNK_SIZE 6 1250 #define SQLITE_FCNTL_FILE_POINTER 7 1251 #define SQLITE_FCNTL_SYNC_OMITTED 8 1252 #define SQLITE_FCNTL_WIN32_AV_RETRY 9 1253 #define SQLITE_FCNTL_PERSIST_WAL 10 1254 #define SQLITE_FCNTL_OVERWRITE 11 1255 #define SQLITE_FCNTL_VFSNAME 12 1256 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 1257 #define SQLITE_FCNTL_PRAGMA 14 1258 #define SQLITE_FCNTL_BUSYHANDLER 15 1259 #define SQLITE_FCNTL_TEMPFILENAME 16 1260 #define SQLITE_FCNTL_MMAP_SIZE 18 1261 #define SQLITE_FCNTL_TRACE 19 1262 #define SQLITE_FCNTL_HAS_MOVED 20 1263 #define SQLITE_FCNTL_SYNC 21 1264 #define SQLITE_FCNTL_COMMIT_PHASETWO 22 1265 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23 1266 #define SQLITE_FCNTL_WAL_BLOCK 24 1267 #define SQLITE_FCNTL_ZIPVFS 25 1268 #define SQLITE_FCNTL_RBU 26 1269 #define SQLITE_FCNTL_VFS_POINTER 27 1270 #define SQLITE_FCNTL_JOURNAL_POINTER 28 1271 #define SQLITE_FCNTL_WIN32_GET_HANDLE 29 1272 #define SQLITE_FCNTL_PDB 30 1273 #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31 1274 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 1275 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 1276 #define SQLITE_FCNTL_LOCK_TIMEOUT 34 1277 #define SQLITE_FCNTL_DATA_VERSION 35 1278 #define SQLITE_FCNTL_SIZE_LIMIT 36 1279 #define SQLITE_FCNTL_CKPT_DONE 37 1280 #define SQLITE_FCNTL_RESERVE_BYTES 38 1281 #define SQLITE_FCNTL_CKPT_START 39 1282 #define SQLITE_FCNTL_EXTERNAL_READER 40 1283 #define SQLITE_FCNTL_CKSM_FILE 41 1284 #define SQLITE_FCNTL_RESET_CACHE 42 1285 #define SQLITE_FCNTL_NULL_IO 43 1286 #define SQLITE_FCNTL_BLOCK_ON_CONNECT 44 1287 #define SQLITE_FCNTL_FILESTAT 45 1288 1289 /* deprecated names */ 1290 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE 1291 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE 1292 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO 1293 1294 /* reserved file-control numbers: 1295 ** 101 1296 ** 102 1297 ** 103 1298 */ 1299 1300 1301 /* 1302 ** CAPI3REF: Mutex Handle 1303 ** 1304 ** The mutex module within SQLite defines [sqlite3_mutex] to be an 1305 ** abstract type for a mutex object. The SQLite core never looks 1306 ** at the internal representation of an [sqlite3_mutex]. It only 1307 ** deals with pointers to the [sqlite3_mutex] object. 1308 ** 1309 ** Mutexes are created using [sqlite3_mutex_alloc()]. 1310 */ 1311 typedef struct sqlite3_mutex sqlite3_mutex; 1312 1313 /* 1314 ** CAPI3REF: Loadable Extension Thunk 1315 ** 1316 ** A pointer to the opaque sqlite3_api_routines structure is passed as 1317 ** the third parameter to entry points of [loadable extensions]. This 1318 ** structure must be typedefed in order to work around compiler warnings 1319 ** on some platforms. 1320 */ 1321 typedef struct sqlite3_api_routines sqlite3_api_routines; 1322 1323 /* 1324 ** CAPI3REF: File Name 1325 ** 1326 ** Type [sqlite3_filename] is used by SQLite to pass filenames to the 1327 ** xOpen method of a [VFS]. It may be cast to (const char*) and treated 1328 ** as a normal, nul-terminated, UTF-8 buffer containing the filename, but 1329 ** may also be passed to special APIs such as: 1330 ** 1331 ** <ul> 1332 ** <li> sqlite3_filename_database() 1333 ** <li> sqlite3_filename_journal() 1334 ** <li> sqlite3_filename_wal() 1335 ** <li> sqlite3_uri_parameter() 1336 ** <li> sqlite3_uri_boolean() 1337 ** <li> sqlite3_uri_int64() 1338 ** <li> sqlite3_uri_key() 1339 ** </ul> 1340 */ 1341 typedef const char *sqlite3_filename; 1342 1343 /* 1344 ** CAPI3REF: OS Interface Object 1345 ** 1346 ** An instance of the sqlite3_vfs object defines the interface between 1347 ** the SQLite core and the underlying operating system. The "vfs" 1348 ** in the name of the object stands for "virtual file system". See 1349 ** the [VFS | VFS documentation] for further information. 1350 ** 1351 ** The VFS interface is sometimes extended by adding new methods onto 1352 ** the end. Each time such an extension occurs, the iVersion field 1353 ** is incremented. The iVersion value started out as 1 in 1354 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2 1355 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased 1356 ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields 1357 ** may be appended to the sqlite3_vfs object and the iVersion value 1358 ** may increase again in future versions of SQLite. 1359 ** Note that due to an oversight, the structure 1360 ** of the sqlite3_vfs object changed in the transition from 1361 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0] 1362 ** and yet the iVersion field was not increased. 1363 ** 1364 ** The szOsFile field is the size of the subclassed [sqlite3_file] 1365 ** structure used by this VFS. mxPathname is the maximum length of 1366 ** a pathname in this VFS. 1367 ** 1368 ** Registered sqlite3_vfs objects are kept on a linked list formed by 1369 ** the pNext pointer. The [sqlite3_vfs_register()] 1370 ** and [sqlite3_vfs_unregister()] interfaces manage this list 1371 ** in a thread-safe way. The [sqlite3_vfs_find()] interface 1372 ** searches the list. Neither the application code nor the VFS 1373 ** implementation should use the pNext pointer. 1374 ** 1375 ** The pNext field is the only field in the sqlite3_vfs 1376 ** structure that SQLite will ever modify. SQLite will only access 1377 ** or modify this field while holding a particular static mutex. 1378 ** The application should never modify anything within the sqlite3_vfs 1379 ** object once the object has been registered. 1380 ** 1381 ** The zName field holds the name of the VFS module. The name must 1382 ** be unique across all VFS modules. 1383 ** 1384 ** [[sqlite3_vfs.xOpen]] 1385 ** ^SQLite guarantees that the zFilename parameter to xOpen 1386 ** is either a NULL pointer or string obtained 1387 ** from xFullPathname() with an optional suffix added. 1388 ** ^If a suffix is added to the zFilename parameter, it will 1389 ** consist of a single "-" character followed by no more than 1390 ** 11 alphanumeric and/or "-" characters. 1391 ** ^SQLite further guarantees that 1392 ** the string will be valid and unchanged until xClose() is 1393 ** called. Because of the previous sentence, 1394 ** the [sqlite3_file] can safely store a pointer to the 1395 ** filename if it needs to remember the filename for some reason. 1396 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen 1397 ** must invent its own temporary name for the file. ^Whenever the 1398 ** xFilename parameter is NULL it will also be the case that the 1399 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 1400 ** 1401 ** The flags argument to xOpen() includes all bits set in 1402 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] 1403 ** or [sqlite3_open16()] is used, then flags includes at least 1404 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 1405 ** If xOpen() opens a file read-only then it sets *pOutFlags to 1406 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. 1407 ** 1408 ** ^(SQLite will also add one of the following flags to the xOpen() 1409 ** call, depending on the object being opened: 1410 ** 1411 ** <ul> 1412 ** <li> [SQLITE_OPEN_MAIN_DB] 1413 ** <li> [SQLITE_OPEN_MAIN_JOURNAL] 1414 ** <li> [SQLITE_OPEN_TEMP_DB] 1415 ** <li> [SQLITE_OPEN_TEMP_JOURNAL] 1416 ** <li> [SQLITE_OPEN_TRANSIENT_DB] 1417 ** <li> [SQLITE_OPEN_SUBJOURNAL] 1418 ** <li> [SQLITE_OPEN_SUPER_JOURNAL] 1419 ** <li> [SQLITE_OPEN_WAL] 1420 ** </ul>)^ 1421 ** 1422 ** The file I/O implementation can use the object type flags to 1423 ** change the way it deals with files. For example, an application 1424 ** that does not care about crash recovery or rollback might make 1425 ** the open of a journal file a no-op. Writes to this journal would 1426 ** also be no-ops, and any attempt to read the journal would return 1427 ** SQLITE_IOERR. Or the implementation might recognize that a database 1428 ** file will be doing page-aligned sector reads and writes in a random 1429 ** order and set up its I/O subsystem accordingly. 1430 ** 1431 ** SQLite might also add one of the following flags to the xOpen method: 1432 ** 1433 ** <ul> 1434 ** <li> [SQLITE_OPEN_DELETEONCLOSE] 1435 ** <li> [SQLITE_OPEN_EXCLUSIVE] 1436 ** </ul> 1437 ** 1438 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be 1439 ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] 1440 ** will be set for TEMP databases and their journals, transient 1441 ** databases, and subjournals. 1442 ** 1443 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction 1444 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly 1445 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() 1446 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 1447 ** SQLITE_OPEN_CREATE, is used to indicate that file should always 1448 ** be created, and that it is an error if it already exists. 1449 ** It is <i>not</i> used to indicate the file should be opened 1450 ** for exclusive access. 1451 ** 1452 ** ^At least szOsFile bytes of memory are allocated by SQLite 1453 ** to hold the [sqlite3_file] structure passed as the third 1454 ** argument to xOpen. The xOpen method does not have to 1455 ** allocate the structure; it should just fill it in. Note that 1456 ** the xOpen method must set the sqlite3_file.pMethods to either 1457 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 1458 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 1459 ** element will be valid after xOpen returns regardless of the success 1460 ** or failure of the xOpen call. 1461 ** 1462 ** [[sqlite3_vfs.xAccess]] 1463 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 1464 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 1465 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 1466 ** to test whether a file is at least readable. The SQLITE_ACCESS_READ 1467 ** flag is never actually used and is not implemented in the built-in 1468 ** VFSes of SQLite. The file is named by the second argument and can be a 1469 ** directory. The xAccess method returns [SQLITE_OK] on success or some 1470 ** non-zero error code if there is an I/O error or if the name of 1471 ** the file given in the second argument is illegal. If SQLITE_OK 1472 ** is returned, then non-zero or zero is written into *pResOut to indicate 1473 ** whether or not the file is accessible. 1474 ** 1475 ** ^SQLite will always allocate at least mxPathname+1 bytes for the 1476 ** output buffer xFullPathname. The exact size of the output buffer 1477 ** is also passed as a parameter to both methods. If the output buffer 1478 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 1479 ** handled as a fatal error by SQLite, vfs implementations should endeavor 1480 ** to prevent this by setting mxPathname to a sufficiently large value. 1481 ** 1482 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() 1483 ** interfaces are not strictly a part of the filesystem, but they are 1484 ** included in the VFS structure for completeness. 1485 ** The xRandomness() function attempts to return nBytes bytes 1486 ** of good-quality randomness into zOut. The return value is 1487 ** the actual number of bytes of randomness obtained. 1488 ** The xSleep() method causes the calling thread to sleep for at 1489 ** least the number of microseconds given. ^The xCurrentTime() 1490 ** method returns a Julian Day Number for the current date and time as 1491 ** a floating point value. 1492 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian 1493 ** Day Number multiplied by 86400000 (the number of milliseconds in 1494 ** a 24-hour day). 1495 ** ^SQLite will use the xCurrentTimeInt64() method to get the current 1496 ** date and time if that method is available (if iVersion is 2 or 1497 ** greater and the function pointer is not NULL) and will fall back 1498 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. 1499 ** 1500 ** ^The xSetSystemCall(), xGetSystemCall(), and xNextSystemCall() interfaces 1501 ** are not used by the SQLite core. These optional interfaces are provided 1502 ** by some VFSes to facilitate testing of the VFS code. By overriding 1503 ** system calls with functions under its control, a test program can 1504 ** simulate faults and error conditions that would otherwise be difficult 1505 ** or impossible to induce. The set of system calls that can be overridden 1506 ** varies from one VFS to another, and from one version of the same VFS to the 1507 ** next. Applications that use these interfaces must be prepared for any 1508 ** or all of these interfaces to be NULL or for their behavior to change 1509 ** from one release to the next. Applications must not attempt to access 1510 ** any of these methods if the iVersion of the VFS is less than 3. 1511 */ 1512 typedef struct sqlite3_vfs sqlite3_vfs; 1513 typedef void (*sqlite3_syscall_ptr)(void); 1514 struct sqlite3_vfs { 1515 int iVersion; /* Structure version number (currently 3) */ 1516 int szOsFile; /* Size of subclassed sqlite3_file */ 1517 int mxPathname; /* Maximum file pathname length */ 1518 sqlite3_vfs *pNext; /* Next registered VFS */ 1519 const char *zName; /* Name of this virtual file system */ 1520 void *pAppData; /* Pointer to application-specific data */ 1521 int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*, 1522 int flags, int *pOutFlags); 1523 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); 1524 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); 1525 int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); 1526 void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); 1527 void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); 1528 void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); 1529 void (*xDlClose)(sqlite3_vfs*, void*); 1530 int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); 1531 int (*xSleep)(sqlite3_vfs*, int microseconds); 1532 int (*xCurrentTime)(sqlite3_vfs*, double*); 1533 int (*xGetLastError)(sqlite3_vfs*, int, char *); 1534 /* 1535 ** The methods above are in version 1 of the sqlite_vfs object 1536 ** definition. Those that follow are added in version 2 or later 1537 */ 1538 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); 1539 /* 1540 ** The methods above are in versions 1 and 2 of the sqlite_vfs object. 1541 ** Those below are for version 3 and greater. 1542 */ 1543 int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); 1544 sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); 1545 const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); 1546 /* 1547 ** The methods above are in versions 1 through 3 of the sqlite_vfs object. 1548 ** New fields may be appended in future versions. The iVersion 1549 ** value will increment whenever this happens. 1550 */ 1551 }; 1552 1553 /* 1554 ** CAPI3REF: Flags for the xAccess VFS method 1555 ** 1556 ** These integer constants can be used as the third parameter to 1557 ** the xAccess method of an [sqlite3_vfs] object. They determine 1558 ** what kind of permissions the xAccess method is looking for. 1559 ** With SQLITE_ACCESS_EXISTS, the xAccess method 1560 ** simply checks whether the file exists. 1561 ** With SQLITE_ACCESS_READWRITE, the xAccess method 1562 ** checks whether the named directory is both readable and writable 1563 ** (in other words, if files can be added, removed, and renamed within 1564 ** the directory). 1565 ** The SQLITE_ACCESS_READWRITE constant is currently used only by the 1566 ** [temp_store_directory pragma], though this could change in a future 1567 ** release of SQLite. 1568 ** With SQLITE_ACCESS_READ, the xAccess method 1569 ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is 1570 ** currently unused, though it might be used in a future release of 1571 ** SQLite. 1572 */ 1573 #define SQLITE_ACCESS_EXISTS 0 1574 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ 1575 #define SQLITE_ACCESS_READ 2 /* Unused */ 1576 1577 /* 1578 ** CAPI3REF: Flags for the xShmLock VFS method 1579 ** 1580 ** These integer constants define the various locking operations 1581 ** allowed by the xShmLock method of [sqlite3_io_methods]. The 1582 ** following are the only legal combinations of flags to the 1583 ** xShmLock method: 1584 ** 1585 ** <ul> 1586 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED 1587 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE 1588 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED 1589 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE 1590 ** </ul> 1591 ** 1592 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as 1593 ** was given on the corresponding lock. 1594 ** 1595 ** The xShmLock method can transition between unlocked and SHARED or 1596 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED 1597 ** and EXCLUSIVE. 1598 */ 1599 #define SQLITE_SHM_UNLOCK 1 1600 #define SQLITE_SHM_LOCK 2 1601 #define SQLITE_SHM_SHARED 4 1602 #define SQLITE_SHM_EXCLUSIVE 8 1603 1604 /* 1605 ** CAPI3REF: Maximum xShmLock index 1606 ** 1607 ** The xShmLock method on [sqlite3_io_methods] may use values 1608 ** between 0 and this upper bound as its "offset" argument. 1609 ** The SQLite core will never attempt to acquire or release a 1610 ** lock outside of this range 1611 */ 1612 #define SQLITE_SHM_NLOCK 8 1613 1614 1615 /* 1616 ** CAPI3REF: Initialize The SQLite Library 1617 ** 1618 ** ^The sqlite3_initialize() routine initializes the 1619 ** SQLite library. ^The sqlite3_shutdown() routine 1620 ** deallocates any resources that were allocated by sqlite3_initialize(). 1621 ** These routines are designed to aid in process initialization and 1622 ** shutdown on embedded systems. Workstation applications using 1623 ** SQLite normally do not need to invoke either of these routines. 1624 ** 1625 ** A call to sqlite3_initialize() is an "effective" call if it is 1626 ** the first time sqlite3_initialize() is invoked during the lifetime of 1627 ** the process, or if it is the first time sqlite3_initialize() is invoked 1628 ** following a call to sqlite3_shutdown(). ^(Only an effective call 1629 ** of sqlite3_initialize() does any initialization. All other calls 1630 ** are harmless no-ops.)^ 1631 ** 1632 ** A call to sqlite3_shutdown() is an "effective" call if it is the first 1633 ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only 1634 ** an effective call to sqlite3_shutdown() does any deinitialization. 1635 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ 1636 ** 1637 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() 1638 ** is not. The sqlite3_shutdown() interface must only be called from a 1639 ** single thread. All open [database connections] must be closed and all 1640 ** other SQLite resources must be deallocated prior to invoking 1641 ** sqlite3_shutdown(). 1642 ** 1643 ** Among other things, ^sqlite3_initialize() will invoke 1644 ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() 1645 ** will invoke sqlite3_os_end(). 1646 ** 1647 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. 1648 ** ^If for some reason, sqlite3_initialize() is unable to initialize 1649 ** the library (perhaps it is unable to allocate a needed resource such 1650 ** as a mutex) it returns an [error code] other than [SQLITE_OK]. 1651 ** 1652 ** ^The sqlite3_initialize() routine is called internally by many other 1653 ** SQLite interfaces so that an application usually does not need to 1654 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] 1655 ** calls sqlite3_initialize() so the SQLite library will be automatically 1656 ** initialized when [sqlite3_open()] is called if it has not been initialized 1657 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] 1658 ** compile-time option, then the automatic calls to sqlite3_initialize() 1659 ** are omitted and the application must call sqlite3_initialize() directly 1660 ** prior to using any other SQLite interface. For maximum portability, 1661 ** it is recommended that applications always invoke sqlite3_initialize() 1662 ** directly prior to using any other SQLite interface. Future releases 1663 ** of SQLite may require this. In other words, the behavior exhibited 1664 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the 1665 ** default behavior in some future release of SQLite. 1666 ** 1667 ** The sqlite3_os_init() routine does operating-system specific 1668 ** initialization of the SQLite library. The sqlite3_os_end() 1669 ** routine undoes the effect of sqlite3_os_init(). Typical tasks 1670 ** performed by these routines include allocation or deallocation 1671 ** of static resources, initialization of global variables, 1672 ** setting up a default [sqlite3_vfs] module, or setting up 1673 ** a default configuration using [sqlite3_config()]. 1674 ** 1675 ** The application should never invoke either sqlite3_os_init() 1676 ** or sqlite3_os_end() directly. The application should only invoke 1677 ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() 1678 ** interface is called automatically by sqlite3_initialize() and 1679 ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate 1680 ** implementations for sqlite3_os_init() and sqlite3_os_end() 1681 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. 1682 ** When [custom builds | built for other platforms] 1683 ** (using the [SQLITE_OS_OTHER=1] compile-time 1684 ** option) the application must supply a suitable implementation for 1685 ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied 1686 ** implementation of sqlite3_os_init() or sqlite3_os_end() 1687 ** must return [SQLITE_OK] on success and some other [error code] upon 1688 ** failure. 1689 */ 1690 SQLITE_API int sqlite3_initialize(void); 1691 SQLITE_API int sqlite3_shutdown(void); 1692 SQLITE_API int sqlite3_os_init(void); 1693 SQLITE_API int sqlite3_os_end(void); 1694 1695 /* 1696 ** CAPI3REF: Configuring The SQLite Library 1697 ** 1698 ** The sqlite3_config() interface is used to make global configuration 1699 ** changes to SQLite in order to tune SQLite to the specific needs of 1700 ** the application. The default configuration is recommended for most 1701 ** applications and so this routine is usually not necessary. It is 1702 ** provided to support rare applications with unusual needs. 1703 ** 1704 ** <b>The sqlite3_config() interface is not threadsafe. The application 1705 ** must ensure that no other SQLite interfaces are invoked by other 1706 ** threads while sqlite3_config() is running.</b> 1707 ** 1708 ** The first argument to sqlite3_config() is an integer 1709 ** [configuration option] that determines 1710 ** what property of SQLite is to be configured. Subsequent arguments 1711 ** vary depending on the [configuration option] 1712 ** in the first argument. 1713 ** 1714 ** For most configuration options, the sqlite3_config() interface 1715 ** may only be invoked prior to library initialization using 1716 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 1717 ** The exceptional configuration options that may be invoked at any time 1718 ** are called "anytime configuration options". 1719 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 1720 ** [sqlite3_shutdown()] with a first argument that is not an anytime 1721 ** configuration option, then the sqlite3_config() call will 1722 ** return SQLITE_MISUSE. 1723 ** Note, however, that ^sqlite3_config() can be called as part of the 1724 ** implementation of an application-defined [sqlite3_os_init()]. 1725 ** 1726 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 1727 ** ^If the option is unknown or SQLite is unable to set the option 1728 ** then this routine returns a non-zero [error code]. 1729 */ 1730 SQLITE_API int sqlite3_config(int, ...); 1731 1732 /* 1733 ** CAPI3REF: Configure database connections 1734 ** METHOD: sqlite3 1735 ** 1736 ** The sqlite3_db_config() interface is used to make configuration 1737 ** changes to a [database connection]. The interface is similar to 1738 ** [sqlite3_config()] except that the changes apply to a single 1739 ** [database connection] (specified in the first argument). 1740 ** 1741 ** The second argument to sqlite3_db_config(D,V,...) is the 1742 ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 1743 ** that indicates what aspect of the [database connection] is being configured. 1744 ** Subsequent arguments vary depending on the configuration verb. 1745 ** 1746 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if 1747 ** the call is considered successful. 1748 */ 1749 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); 1750 1751 /* 1752 ** CAPI3REF: Memory Allocation Routines 1753 ** 1754 ** An instance of this object defines the interface between SQLite 1755 ** and low-level memory allocation routines. 1756 ** 1757 ** This object is used in only one place in the SQLite interface. 1758 ** A pointer to an instance of this object is the argument to 1759 ** [sqlite3_config()] when the configuration option is 1760 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. 1761 ** By creating an instance of this object 1762 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) 1763 ** during configuration, an application can specify an alternative 1764 ** memory allocation subsystem for SQLite to use for all of its 1765 ** dynamic memory needs. 1766 ** 1767 ** Note that SQLite comes with several [built-in memory allocators] 1768 ** that are perfectly adequate for the overwhelming majority of applications 1769 ** and that this object is only useful to a tiny minority of applications 1770 ** with specialized memory allocation requirements. This object is 1771 ** also used during testing of SQLite in order to specify an alternative 1772 ** memory allocator that simulates memory out-of-memory conditions in 1773 ** order to verify that SQLite recovers gracefully from such 1774 ** conditions. 1775 ** 1776 ** The xMalloc, xRealloc, and xFree methods must work like the 1777 ** malloc(), realloc() and free() functions from the standard C library. 1778 ** ^SQLite guarantees that the second argument to 1779 ** xRealloc is always a value returned by a prior call to xRoundup. 1780 ** 1781 ** xSize should return the allocated size of a memory allocation 1782 ** previously obtained from xMalloc or xRealloc. The allocated size 1783 ** is always at least as big as the requested size but may be larger. 1784 ** 1785 ** The xRoundup method returns what would be the allocated size of 1786 ** a memory allocation given a particular requested size. Most memory 1787 ** allocators round up memory allocations at least to the next multiple 1788 ** of 8. Some allocators round up to a larger multiple or to a power of 2. 1789 ** Every memory allocation request coming in through [sqlite3_malloc()] 1790 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 1791 ** that causes the corresponding memory allocation to fail. 1792 ** 1793 ** The xInit method initializes the memory allocator. For example, 1794 ** it might allocate any required mutexes or initialize internal data 1795 ** structures. The xShutdown method is invoked (indirectly) by 1796 ** [sqlite3_shutdown()] and should deallocate any resources acquired 1797 ** by xInit. The pAppData pointer is used as the only parameter to 1798 ** xInit and xShutdown. 1799 ** 1800 ** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes 1801 ** the xInit method, so the xInit method need not be threadsafe. The 1802 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 1803 ** not need to be threadsafe either. For all other methods, SQLite 1804 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the 1805 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which 1806 ** it is by default) and so the methods are automatically serialized. 1807 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other 1808 ** methods must be threadsafe or else make their own arrangements for 1809 ** serialization. 1810 ** 1811 ** SQLite will never invoke xInit() more than once without an intervening 1812 ** call to xShutdown(). 1813 */ 1814 typedef struct sqlite3_mem_methods sqlite3_mem_methods; 1815 struct sqlite3_mem_methods { 1816 void *(*xMalloc)(int); /* Memory allocation function */ 1817 void (*xFree)(void*); /* Free a prior allocation */ 1818 void *(*xRealloc)(void*,int); /* Resize an allocation */ 1819 int (*xSize)(void*); /* Return the size of an allocation */ 1820 int (*xRoundup)(int); /* Round up request size to allocation size */ 1821 int (*xInit)(void*); /* Initialize the memory allocator */ 1822 void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 1823 void *pAppData; /* Argument to xInit() and xShutdown() */ 1824 }; 1825 1826 /* 1827 ** CAPI3REF: Configuration Options 1828 ** KEYWORDS: {configuration option} 1829 ** 1830 ** These constants are the available integer configuration options that 1831 ** can be passed as the first argument to the [sqlite3_config()] interface. 1832 ** 1833 ** Most of the configuration options for sqlite3_config() 1834 ** will only work if invoked prior to [sqlite3_initialize()] or after 1835 ** [sqlite3_shutdown()]. The few exceptions to this rule are called 1836 ** "anytime configuration options". 1837 ** ^Calling [sqlite3_config()] with a first argument that is not an 1838 ** anytime configuration option in between calls to [sqlite3_initialize()] and 1839 ** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE. 1840 ** 1841 ** The set of anytime configuration options can change (by insertions 1842 ** and/or deletions) from one release of SQLite to the next. 1843 ** As of SQLite version 3.42.0, the complete set of anytime configuration 1844 ** options is: 1845 ** <ul> 1846 ** <li> SQLITE_CONFIG_LOG 1847 ** <li> SQLITE_CONFIG_PCACHE_HDRSZ 1848 ** </ul> 1849 ** 1850 ** New configuration options may be added in future releases of SQLite. 1851 ** Existing configuration options might be discontinued. Applications 1852 ** should check the return code from [sqlite3_config()] to make sure that 1853 ** the call worked. The [sqlite3_config()] interface will return a 1854 ** non-zero [error code] if a discontinued or unsupported configuration option 1855 ** is invoked. 1856 ** 1857 ** <dl> 1858 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 1859 ** <dd>There are no arguments to this option. ^This option sets the 1860 ** [threading mode] to Single-thread. In other words, it disables 1861 ** all mutexing and puts SQLite into a mode where it can only be used 1862 ** by a single thread. ^If SQLite is compiled with 1863 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1864 ** it is not possible to change the [threading mode] from its default 1865 ** value of Single-thread and so [sqlite3_config()] will return 1866 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 1867 ** configuration option.</dd> 1868 ** 1869 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> 1870 ** <dd>There are no arguments to this option. ^This option sets the 1871 ** [threading mode] to Multi-thread. In other words, it disables 1872 ** mutexing on [database connection] and [prepared statement] objects. 1873 ** The application is responsible for serializing access to 1874 ** [database connections] and [prepared statements]. But other mutexes 1875 ** are enabled so that SQLite will be safe to use in a multi-threaded 1876 ** environment as long as no two threads attempt to use the same 1877 ** [database connection] at the same time. ^If SQLite is compiled with 1878 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1879 ** it is not possible to set the Multi-thread [threading mode] and 1880 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1881 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 1882 ** 1883 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> 1884 ** <dd>There are no arguments to this option. ^This option sets the 1885 ** [threading mode] to Serialized. In other words, this option enables 1886 ** all mutexes including the recursive 1887 ** mutexes on [database connection] and [prepared statement] objects. 1888 ** In this mode (which is the default when SQLite is compiled with 1889 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 1890 ** to [database connections] and [prepared statements] so that the 1891 ** application is free to use the same [database connection] or the 1892 ** same [prepared statement] in different threads at the same time. 1893 ** ^If SQLite is compiled with 1894 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1895 ** it is not possible to set the Serialized [threading mode] and 1896 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1897 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 1898 ** 1899 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> 1900 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is 1901 ** a pointer to an instance of the [sqlite3_mem_methods] structure. 1902 ** The argument specifies 1903 ** alternative low-level memory allocation routines to be used in place of 1904 ** the memory allocation routines built into SQLite.)^ ^SQLite makes 1905 ** its own private copy of the content of the [sqlite3_mem_methods] structure 1906 ** before the [sqlite3_config()] call returns.</dd> 1907 ** 1908 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> 1909 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which 1910 ** is a pointer to an instance of the [sqlite3_mem_methods] structure. 1911 ** The [sqlite3_mem_methods] 1912 ** structure is filled with the currently defined memory allocation routines.)^ 1913 ** This option can be used to overload the default memory allocation 1914 ** routines with a wrapper that simulates memory allocation failure or 1915 ** tracks memory usage, for example. </dd> 1916 ** 1917 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt> 1918 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes a single argument of 1919 ** type int, interpreted as a boolean, which if true provides a hint to 1920 ** SQLite that it should avoid large memory allocations if possible. 1921 ** SQLite will run faster if it is free to make large memory allocations, 1922 ** but some applications might prefer to run slower in exchange for 1923 ** guarantees about memory fragmentation that are possible if large 1924 ** allocations are avoided. This hint is normally off. 1925 ** </dd> 1926 ** 1927 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> 1928 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes a single argument of type int, 1929 ** interpreted as a boolean, which enables or disables the collection of 1930 ** memory allocation statistics. ^(When memory allocation statistics are 1931 ** disabled, the following SQLite interfaces become non-operational: 1932 ** <ul> 1933 ** <li> [sqlite3_hard_heap_limit64()] 1934 ** <li> [sqlite3_memory_used()] 1935 ** <li> [sqlite3_memory_highwater()] 1936 ** <li> [sqlite3_soft_heap_limit64()] 1937 ** <li> [sqlite3_status64()] 1938 ** </ul>)^ 1939 ** ^Memory allocation statistics are enabled by default unless SQLite is 1940 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 1941 ** allocation statistics are disabled by default. 1942 ** </dd> 1943 ** 1944 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> 1945 ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used. 1946 ** </dd> 1947 ** 1948 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> 1949 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool 1950 ** that SQLite can use for the database page cache with the default page 1951 ** cache implementation. 1952 ** This configuration option is a no-op if an application-defined page 1953 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]. 1954 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to 1955 ** 8-byte aligned memory (pMem), the size of each page cache line (sz), 1956 ** and the number of cache lines (N). 1957 ** The sz argument should be the size of the largest database page 1958 ** (a power of two between 512 and 65536) plus some extra bytes for each 1959 ** page header. ^The number of extra bytes needed by the page header 1960 ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ]. 1961 ** ^It is harmless, apart from the wasted memory, 1962 ** for the sz parameter to be larger than necessary. The pMem 1963 ** argument must be either a NULL pointer or a pointer to an 8-byte 1964 ** aligned block of memory of at least sz*N bytes, otherwise 1965 ** subsequent behavior is undefined. 1966 ** ^When pMem is not NULL, SQLite will strive to use the memory provided 1967 ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if 1968 ** a page cache line is larger than sz bytes or if all of the pMem buffer 1969 ** is exhausted. 1970 ** ^If pMem is NULL and N is non-zero, then each database connection 1971 ** does an initial bulk allocation for page cache memory 1972 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or 1973 ** of -1024*N bytes if N is negative. ^If additional 1974 ** page cache memory is needed beyond what is provided by the initial 1975 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each 1976 ** additional cache line. </dd> 1977 ** 1978 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> 1979 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer 1980 ** that SQLite will use for all of its dynamic memory allocation needs 1981 ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE]. 1982 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled 1983 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns 1984 ** [SQLITE_ERROR] if invoked otherwise. 1985 ** ^There are three arguments to SQLITE_CONFIG_HEAP: 1986 ** An 8-byte aligned pointer to the memory, 1987 ** the number of bytes in the memory buffer, and the minimum allocation size. 1988 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 1989 ** to using its default memory allocator (the system malloc() implementation), 1990 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 1991 ** memory pointer is not NULL then the alternative memory 1992 ** allocator is engaged to handle all of SQLites memory allocation needs. 1993 ** The first pointer (the memory pointer) must be aligned to an 8-byte 1994 ** boundary or subsequent behavior of SQLite will be undefined. 1995 ** The minimum allocation size is capped at 2**12. Reasonable values 1996 ** for the minimum allocation size are 2**5 through 2**8.</dd> 1997 ** 1998 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> 1999 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a 2000 ** pointer to an instance of the [sqlite3_mutex_methods] structure. 2001 ** The argument specifies alternative low-level mutex routines to be used 2002 ** in place of the mutex routines built into SQLite.)^ ^SQLite makes a copy of 2003 ** the content of the [sqlite3_mutex_methods] structure before the call to 2004 ** [sqlite3_config()] returns. ^If SQLite is compiled with 2005 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 2006 ** the entire mutexing subsystem is omitted from the build and hence calls to 2007 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 2008 ** return [SQLITE_ERROR].</dd> 2009 ** 2010 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> 2011 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which 2012 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The 2013 ** [sqlite3_mutex_methods] 2014 ** structure is filled with the currently defined mutex routines.)^ 2015 ** This option can be used to overload the default mutex allocation 2016 ** routines with a wrapper used to track mutex usage for performance 2017 ** profiling or testing, for example. ^If SQLite is compiled with 2018 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 2019 ** the entire mutexing subsystem is omitted from the build and hence calls to 2020 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 2021 ** return [SQLITE_ERROR].</dd> 2022 ** 2023 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> 2024 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine 2025 ** the default size of [lookaside memory] on each [database connection]. 2026 ** The first argument is the 2027 ** size of each lookaside buffer slot ("sz") and the second is the number of 2028 ** slots allocated to each database connection ("cnt").)^ 2029 ** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size. 2030 ** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can 2031 ** be used to change the lookaside configuration on individual connections.)^ 2032 ** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the 2033 ** default lookaside configuration at compile-time. 2034 ** </dd> 2035 ** 2036 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> 2037 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is 2038 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies 2039 ** the interface to a custom page cache implementation.)^ 2040 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd> 2041 ** 2042 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> 2043 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which 2044 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies off 2045 ** the current page cache implementation into that object.)^ </dd> 2046 ** 2047 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> 2048 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite 2049 ** global [error log]. 2050 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 2051 ** function with a call signature of void(*)(void*,int,const char*), 2052 ** and a pointer to void. ^If the function pointer is not NULL, it is 2053 ** invoked by [sqlite3_log()] to process each logging event. ^If the 2054 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. 2055 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is 2056 ** passed through as the first parameter to the application-defined logger 2057 ** function whenever that function is invoked. ^The second parameter to 2058 ** the logger function is a copy of the first parameter to the corresponding 2059 ** [sqlite3_log()] call and is intended to be a [result code] or an 2060 ** [extended result code]. ^The third parameter passed to the logger is 2061 ** a log message after formatting via [sqlite3_snprintf()]. 2062 ** The SQLite logging interface is not reentrant; the logger function 2063 ** supplied by the application must not invoke any SQLite interface. 2064 ** In a multi-threaded application, the application-defined logger 2065 ** function must be threadsafe. </dd> 2066 ** 2067 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI 2068 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int. 2069 ** If non-zero, then URI handling is globally enabled. If the parameter is zero, 2070 ** then URI handling is globally disabled.)^ ^If URI handling is globally 2071 ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()], 2072 ** [sqlite3_open16()] or 2073 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless 2074 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database 2075 ** connection is opened. ^If it is globally disabled, filenames are 2076 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 2077 ** database connection is opened. ^(By default, URI handling is globally 2078 ** disabled. The default value may be changed by compiling with the 2079 ** [SQLITE_USE_URI] symbol defined.)^ 2080 ** 2081 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN 2082 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer 2083 ** argument which is interpreted as a boolean in order to enable or disable 2084 ** the use of covering indices for full table scans in the query optimizer. 2085 ** ^The default setting is determined 2086 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" 2087 ** if that compile-time option is omitted. 2088 ** The ability to disable the use of covering indices for full table scans 2089 ** is because some incorrectly coded legacy applications might malfunction 2090 ** when the optimization is enabled. Providing the ability to 2091 ** disable the optimization allows the older, buggy application code to work 2092 ** without change even with newer versions of SQLite. 2093 ** 2094 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] 2095 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE 2096 ** <dd> These options are obsolete and should not be used by new code. 2097 ** They are retained for backwards compatibility but are now no-ops. 2098 ** </dd> 2099 ** 2100 ** [[SQLITE_CONFIG_SQLLOG]] 2101 ** <dt>SQLITE_CONFIG_SQLLOG 2102 ** <dd>This option is only available if sqlite is compiled with the 2103 ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should 2104 ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int). 2105 ** The second should be of type (void*). The callback is invoked by the library 2106 ** in three separate circumstances, identified by the value passed as the 2107 ** fourth parameter. If the fourth parameter is 0, then the database connection 2108 ** passed as the second argument has just been opened. The third argument 2109 ** points to a buffer containing the name of the main database file. If the 2110 ** fourth parameter is 1, then the SQL statement that the third parameter 2111 ** points to has just been executed. Or, if the fourth parameter is 2, then 2112 ** the connection being passed as the second parameter is being closed. The 2113 ** third parameter is passed NULL In this case. An example of using this 2114 ** configuration option can be seen in the "test_sqllog.c" source file in 2115 ** the canonical SQLite source tree.</dd> 2116 ** 2117 ** [[SQLITE_CONFIG_MMAP_SIZE]] 2118 ** <dt>SQLITE_CONFIG_MMAP_SIZE 2119 ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values 2120 ** that are the default mmap size limit (the default setting for 2121 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. 2122 ** ^The default setting can be overridden by each database connection using 2123 ** either the [PRAGMA mmap_size] command, or by using the 2124 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size 2125 ** will be silently truncated if necessary so that it does not exceed the 2126 ** compile-time maximum mmap size set by the 2127 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ 2128 ** ^If either argument to this option is negative, then that argument is 2129 ** changed to its compile-time default. 2130 ** 2131 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] 2132 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE 2133 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is 2134 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro 2135 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value 2136 ** that specifies the maximum size of the created heap. 2137 ** 2138 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]] 2139 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ 2140 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which 2141 ** is a pointer to an integer and writes into that integer the number of extra 2142 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE]. 2143 ** The amount of extra space required can change depending on the compiler, 2144 ** target platform, and SQLite version. 2145 ** 2146 ** [[SQLITE_CONFIG_PMASZ]] 2147 ** <dt>SQLITE_CONFIG_PMASZ 2148 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which 2149 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded 2150 ** sorter to that integer. The default minimum PMA Size is set by the 2151 ** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched 2152 ** to help with sort operations when multithreaded sorting 2153 ** is enabled (using the [PRAGMA threads] command) and the amount of content 2154 ** to be sorted exceeds the page size times the minimum of the 2155 ** [PRAGMA cache_size] setting and this value. 2156 ** 2157 ** [[SQLITE_CONFIG_STMTJRNL_SPILL]] 2158 ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL 2159 ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which 2160 ** becomes the [statement journal] spill-to-disk threshold. 2161 ** [Statement journals] are held in memory until their size (in bytes) 2162 ** exceeds this threshold, at which point they are written to disk. 2163 ** Or if the threshold is -1, statement journals are always held 2164 ** exclusively in memory. 2165 ** Since many statement journals never become large, setting the spill 2166 ** threshold to a value such as 64KiB can greatly reduce the amount of 2167 ** I/O required to support statement rollback. 2168 ** The default value for this setting is controlled by the 2169 ** [SQLITE_STMTJRNL_SPILL] compile-time option. 2170 ** 2171 ** [[SQLITE_CONFIG_SORTERREF_SIZE]] 2172 ** <dt>SQLITE_CONFIG_SORTERREF_SIZE 2173 ** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter 2174 ** of type (int) - the new value of the sorter-reference size threshold. 2175 ** Usually, when SQLite uses an external sort to order records according 2176 ** to an ORDER BY clause, all fields required by the caller are present in the 2177 ** sorted records. However, if SQLite determines based on the declared type 2178 ** of a table column that its values are likely to be very large - larger 2179 ** than the configured sorter-reference size threshold - then a reference 2180 ** is stored in each sorted record and the required column values loaded 2181 ** from the database as records are returned in sorted order. The default 2182 ** value for this option is to never use this optimization. Specifying a 2183 ** negative value for this option restores the default behavior. 2184 ** This option is only available if SQLite is compiled with the 2185 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option. 2186 ** 2187 ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]] 2188 ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE 2189 ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter 2190 ** [sqlite3_int64] parameter which is the default maximum size for an in-memory 2191 ** database created using [sqlite3_deserialize()]. This default maximum 2192 ** size can be adjusted up or down for individual databases using the 2193 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this 2194 ** configuration setting is never used, then the default maximum is determined 2195 ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that 2196 ** compile-time option is not set, then the default maximum is 1073741824. 2197 ** 2198 ** [[SQLITE_CONFIG_ROWID_IN_VIEW]] 2199 ** <dt>SQLITE_CONFIG_ROWID_IN_VIEW 2200 ** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability 2201 ** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is 2202 ** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability 2203 ** defaults to on. This configuration option queries the current setting or 2204 ** changes the setting to off or on. The argument is a pointer to an integer. 2205 ** If that integer initially holds a value of 1, then the ability for VIEWs to 2206 ** have ROWIDs is activated. If the integer initially holds zero, then the 2207 ** ability is deactivated. Any other initial value for the integer leaves the 2208 ** setting unchanged. After changes, if any, the integer is written with 2209 ** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite 2210 ** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and 2211 ** recommended case) then the integer is always filled with zero, regardless 2212 ** if its initial value. 2213 ** </dl> 2214 */ 2215 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 2216 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 2217 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 2218 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 2219 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 2220 #define SQLITE_CONFIG_SCRATCH 6 /* No longer used */ 2221 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 2222 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 2223 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 2224 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 2225 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 2226 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 2227 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 2228 #define SQLITE_CONFIG_PCACHE 14 /* no-op */ 2229 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ 2230 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 2231 #define SQLITE_CONFIG_URI 17 /* int */ 2232 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ 2233 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ 2234 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ 2235 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ 2236 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ 2237 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ 2238 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */ 2239 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */ 2240 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */ 2241 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */ 2242 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ 2243 #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ 2244 #define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */ 2245 2246 /* 2247 ** CAPI3REF: Database Connection Configuration Options 2248 ** 2249 ** These constants are the available integer configuration options that 2250 ** can be passed as the second parameter to the [sqlite3_db_config()] interface. 2251 ** 2252 ** The [sqlite3_db_config()] interface is a var-args function. It takes a 2253 ** variable number of parameters, though always at least two. The number of 2254 ** parameters passed into sqlite3_db_config() depends on which of these 2255 ** constants is given as the second parameter. This documentation page 2256 ** refers to parameters beyond the second as "arguments". Thus, when this 2257 ** page says "the N-th argument" it means "the N-th parameter past the 2258 ** configuration option" or "the (N+2)-th parameter to sqlite3_db_config()". 2259 ** 2260 ** New configuration options may be added in future releases of SQLite. 2261 ** Existing configuration options might be discontinued. Applications 2262 ** should check the return code from [sqlite3_db_config()] to make sure that 2263 ** the call worked. ^The [sqlite3_db_config()] interface will return a 2264 ** non-zero [error code] if a discontinued or unsupported configuration option 2265 ** is invoked. 2266 ** 2267 ** <dl> 2268 ** [[SQLITE_DBCONFIG_LOOKASIDE]] 2269 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> 2270 ** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the 2271 ** configuration of the [lookaside memory allocator] within a database 2272 ** connection. 2273 ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i> 2274 ** in the [DBCONFIG arguments|usual format]. 2275 ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two, 2276 ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE 2277 ** should have a total of five parameters. 2278 ** <ol> 2279 ** <li><p>The first argument ("buf") is a 2280 ** pointer to a memory buffer to use for lookaside memory. 2281 ** The first argument may be NULL in which case SQLite will allocate the 2282 ** lookaside buffer itself using [sqlite3_malloc()]. 2283 ** <li><P>The second argument ("sz") is the 2284 ** size of each lookaside buffer slot. Lookaside is disabled if "sz" 2285 ** is less than 8. The "sz" argument should be a multiple of 8 less than 2286 ** 65536. If "sz" does not meet this constraint, it is reduced in size until 2287 ** it does. 2288 ** <li><p>The third argument ("cnt") is the number of slots. 2289 ** Lookaside is disabled if "cnt"is less than 1. 2290 * The "cnt" value will be reduced, if necessary, so 2291 ** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt" 2292 ** parameter is usually chosen so that the product of "sz" and "cnt" is less 2293 ** than 1,000,000. 2294 ** </ol> 2295 ** <p>If the "buf" argument is not NULL, then it must 2296 ** point to a memory buffer with a size that is greater than 2297 ** or equal to the product of "sz" and "cnt". 2298 ** The buffer must be aligned to an 8-byte boundary. 2299 ** The lookaside memory 2300 ** configuration for a database connection can only be changed when that 2301 ** connection is not currently using lookaside memory, or in other words 2302 ** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero. 2303 ** Any attempt to change the lookaside memory configuration when lookaside 2304 ** memory is in use leaves the configuration unchanged and returns 2305 ** [SQLITE_BUSY]. 2306 ** If the "buf" argument is NULL and an attempt 2307 ** to allocate memory based on "sz" and "cnt" fails, then 2308 ** lookaside is silently disabled. 2309 ** <p> 2310 ** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the 2311 ** default lookaside configuration at initialization. The 2312 ** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside 2313 ** configuration at compile-time. Typical values for lookaside are 1200 for 2314 ** "sz" and 40 to 100 for "cnt". 2315 ** </dd> 2316 ** 2317 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]] 2318 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> 2319 ** <dd> ^This option is used to enable or disable the enforcement of 2320 ** [foreign key constraints]. This is the same setting that is 2321 ** enabled or disabled by the [PRAGMA foreign_keys] statement. 2322 ** The first argument is an integer which is 0 to disable FK enforcement, 2323 ** positive to enable FK enforcement or negative to leave FK enforcement 2324 ** unchanged. The second parameter is a pointer to an integer into which 2325 ** is written 0 or 1 to indicate whether FK enforcement is off or on 2326 ** following this call. The second parameter may be a NULL pointer, in 2327 ** which case the FK enforcement setting is not reported back. </dd> 2328 ** 2329 ** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]] 2330 ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> 2331 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. 2332 ** There should be two additional arguments. 2333 ** The first argument is an integer which is 0 to disable triggers, 2334 ** positive to enable triggers or negative to leave the setting unchanged. 2335 ** The second parameter is a pointer to an integer into which 2336 ** is written 0 or 1 to indicate whether triggers are disabled or enabled 2337 ** following this call. The second parameter may be a NULL pointer, in 2338 ** which case the trigger setting is not reported back. 2339 ** 2340 ** <p>Originally this option disabled all triggers. ^(However, since 2341 ** SQLite version 3.35.0, TEMP triggers are still allowed even if 2342 ** this option is off. So, in other words, this option now only disables 2343 ** triggers in the main database schema or in the schemas of [ATTACH]-ed 2344 ** databases.)^ </dd> 2345 ** 2346 ** [[SQLITE_DBCONFIG_ENABLE_VIEW]] 2347 ** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt> 2348 ** <dd> ^This option is used to enable or disable [CREATE VIEW | views]. 2349 ** There must be two additional arguments. 2350 ** The first argument is an integer which is 0 to disable views, 2351 ** positive to enable views or negative to leave the setting unchanged. 2352 ** The second parameter is a pointer to an integer into which 2353 ** is written 0 or 1 to indicate whether views are disabled or enabled 2354 ** following this call. The second parameter may be a NULL pointer, in 2355 ** which case the view setting is not reported back. 2356 ** 2357 ** <p>Originally this option disabled all views. ^(However, since 2358 ** SQLite version 3.35.0, TEMP views are still allowed even if 2359 ** this option is off. So, in other words, this option now only disables 2360 ** views in the main database schema or in the schemas of ATTACH-ed 2361 ** databases.)^ </dd> 2362 ** 2363 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] 2364 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> 2365 ** <dd> ^This option is used to enable or disable using the 2366 ** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine 2367 ** extension - without using bound parameters as the parameters. Doing so 2368 ** is disabled by default. There must be two additional arguments. The first 2369 ** argument is an integer. If it is passed 0, then using fts3_tokenizer() 2370 ** without bound parameters is disabled. If it is passed a positive value, 2371 ** then calling fts3_tokenizer without bound parameters is enabled. If it 2372 ** is passed a negative value, this setting is not modified - this can be 2373 ** used to query for the current setting. The second parameter is a pointer 2374 ** to an integer into which is written 0 or 1 to indicate the current value 2375 ** of this setting (after it is modified, if applicable). The second 2376 ** parameter may be a NULL pointer, in which case the value of the setting 2377 ** is not reported back. Refer to [FTS3] documentation for further details. 2378 ** </dd> 2379 ** 2380 ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]] 2381 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> 2382 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] 2383 ** interface independently of the [load_extension()] SQL function. 2384 ** The [sqlite3_enable_load_extension()] API enables or disables both the 2385 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()]. 2386 ** There must be two additional arguments. 2387 ** When the first argument to this interface is 1, then only the C-API is 2388 ** enabled and the SQL function remains disabled. If the first argument to 2389 ** this interface is 0, then both the C-API and the SQL function are disabled. 2390 ** If the first argument is -1, then no changes are made to the state of either 2391 ** the C-API or the SQL function. 2392 ** The second parameter is a pointer to an integer into which 2393 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface 2394 ** is disabled or enabled following this call. The second parameter may 2395 ** be a NULL pointer, in which case the new setting is not reported back. 2396 ** </dd> 2397 ** 2398 ** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt> 2399 ** <dd> ^This option is used to change the name of the "main" database 2400 ** schema. This option does not follow the 2401 ** [DBCONFIG arguments|usual SQLITE_DBCONFIG argument format]. 2402 ** This option takes exactly one additional argument so that the 2403 ** [sqlite3_db_config()] call has a total of three parameters. The 2404 ** extra argument must be a pointer to a constant UTF8 string which 2405 ** will become the new schema name in place of "main". ^SQLite does 2406 ** not make a copy of the new main schema name string, so the application 2407 ** must ensure that the argument passed into SQLITE_DBCONFIG MAINDBNAME 2408 ** is unchanged until after the database connection closes. 2409 ** </dd> 2410 ** 2411 ** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] 2412 ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt> 2413 ** <dd> Usually, when a database in [WAL mode] is closed or detached from a 2414 ** database handle, SQLite checks if if there are other connections to the 2415 ** same database, and if there are no other database connection (if the 2416 ** connection being closed is the last open connection to the database), 2417 ** then SQLite performs a [checkpoint] before closing the connection and 2418 ** deletes the WAL file. The SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE option can 2419 ** be used to override that behavior. The first argument passed to this 2420 ** operation (the third parameter to [sqlite3_db_config()]) is an integer 2421 ** which is positive to disable checkpoints-on-close, or zero (the default) 2422 ** to enable them, and negative to leave the setting unchanged. 2423 ** The second argument (the fourth parameter) is a pointer to an integer 2424 ** into which is written 0 or 1 to indicate whether checkpoints-on-close 2425 ** have been disabled - 0 if they are not disabled, 1 if they are. 2426 ** </dd> 2427 ** 2428 ** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt> 2429 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates 2430 ** the [query planner stability guarantee] (QPSG). When the QPSG is active, 2431 ** a single SQL query statement will always use the same algorithm regardless 2432 ** of values of [bound parameters].)^ The QPSG disables some query optimizations 2433 ** that look at the values of bound parameters, which can make some queries 2434 ** slower. But the QPSG has the advantage of more predictable behavior. With 2435 ** the QPSG active, SQLite will always use the same query plan in the field as 2436 ** was used during testing in the lab. 2437 ** The first argument to this setting is an integer which is 0 to disable 2438 ** the QPSG, positive to enable QPSG, or negative to leave the setting 2439 ** unchanged. The second parameter is a pointer to an integer into which 2440 ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled 2441 ** following this call. 2442 ** </dd> 2443 ** 2444 ** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt> 2445 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not 2446 ** include output for any operations performed by trigger programs. This 2447 ** option is used to set or clear (the default) a flag that governs this 2448 ** behavior. The first parameter passed to this operation is an integer - 2449 ** positive to enable output for trigger programs, or zero to disable it, 2450 ** or negative to leave the setting unchanged. 2451 ** The second parameter is a pointer to an integer into which is written 2452 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if 2453 ** it is not disabled, 1 if it is. 2454 ** </dd> 2455 ** 2456 ** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt> 2457 ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run 2458 ** [VACUUM] in order to reset a database back to an empty database 2459 ** with no schema and no content. The following process works even for 2460 ** a badly corrupted database file: 2461 ** <ol> 2462 ** <li> If the database connection is newly opened, make sure it has read the 2463 ** database schema by preparing then discarding some query against the 2464 ** database, or calling sqlite3_table_column_metadata(), ignoring any 2465 ** errors. This step is only necessary if the application desires to keep 2466 ** the database in WAL mode after the reset if it was in WAL mode before 2467 ** the reset. 2468 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0); 2469 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0); 2470 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0); 2471 ** </ol> 2472 ** Because resetting a database is destructive and irreversible, the 2473 ** process requires the use of this obscure API and multiple steps to 2474 ** help ensure that it does not happen by accident. Because this 2475 ** feature must be capable of resetting corrupt databases, and 2476 ** shutting down virtual tables may require access to that corrupt 2477 ** storage, the library must abandon any installed virtual tables 2478 ** without calling their xDestroy() methods. 2479 ** 2480 ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt> 2481 ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the 2482 ** "defensive" flag for a database connection. When the defensive 2483 ** flag is enabled, language features that allow ordinary SQL to 2484 ** deliberately corrupt the database file are disabled. The disabled 2485 ** features include but are not limited to the following: 2486 ** <ul> 2487 ** <li> The [PRAGMA writable_schema=ON] statement. 2488 ** <li> The [PRAGMA journal_mode=OFF] statement. 2489 ** <li> The [PRAGMA schema_version=N] statement. 2490 ** <li> Writes to the [sqlite_dbpage] virtual table. 2491 ** <li> Direct writes to [shadow tables]. 2492 ** </ul> 2493 ** </dd> 2494 ** 2495 ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt> 2496 ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the 2497 ** "writable_schema" flag. This has the same effect and is logically equivalent 2498 ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF]. 2499 ** The first argument to this setting is an integer which is 0 to disable 2500 ** the writable_schema, positive to enable writable_schema, or negative to 2501 ** leave the setting unchanged. The second parameter is a pointer to an 2502 ** integer into which is written 0 or 1 to indicate whether the writable_schema 2503 ** is enabled or disabled following this call. 2504 ** </dd> 2505 ** 2506 ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]] 2507 ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt> 2508 ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates 2509 ** the legacy behavior of the [ALTER TABLE RENAME] command such that it 2510 ** behaves as it did prior to [version 3.24.0] (2018-06-04). See the 2511 ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for 2512 ** additional information. This feature can also be turned on and off 2513 ** using the [PRAGMA legacy_alter_table] statement. 2514 ** </dd> 2515 ** 2516 ** [[SQLITE_DBCONFIG_DQS_DML]] 2517 ** <dt>SQLITE_DBCONFIG_DQS_DML</dt> 2518 ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates 2519 ** the legacy [double-quoted string literal] misfeature for DML statements 2520 ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The 2521 ** default value of this setting is determined by the [-DSQLITE_DQS] 2522 ** compile-time option. 2523 ** </dd> 2524 ** 2525 ** [[SQLITE_DBCONFIG_DQS_DDL]] 2526 ** <dt>SQLITE_DBCONFIG_DQS_DDL</dt> 2527 ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates 2528 ** the legacy [double-quoted string literal] misfeature for DDL statements, 2529 ** such as CREATE TABLE and CREATE INDEX. The 2530 ** default value of this setting is determined by the [-DSQLITE_DQS] 2531 ** compile-time option. 2532 ** </dd> 2533 ** 2534 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]] 2535 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt> 2536 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to 2537 ** assume that database schemas are untainted by malicious content. 2538 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite 2539 ** takes additional defensive steps to protect the application from harm 2540 ** including: 2541 ** <ul> 2542 ** <li> Prohibit the use of SQL functions inside triggers, views, 2543 ** CHECK constraints, DEFAULT clauses, expression indexes, 2544 ** partial indexes, or generated columns 2545 ** unless those functions are tagged with [SQLITE_INNOCUOUS]. 2546 ** <li> Prohibit the use of virtual tables inside of triggers or views 2547 ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS]. 2548 ** </ul> 2549 ** This setting defaults to "on" for legacy compatibility, however 2550 ** all applications are advised to turn it off if possible. This setting 2551 ** can also be controlled using the [PRAGMA trusted_schema] statement. 2552 ** </dd> 2553 ** 2554 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]] 2555 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt> 2556 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates 2557 ** the legacy file format flag. When activated, this flag causes all newly 2558 ** created database files to have a schema format version number (the 4-byte 2559 ** integer found at offset 44 into the database header) of 1. This in turn 2560 ** means that the resulting database file will be readable and writable by 2561 ** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting, 2562 ** newly created databases are generally not understandable by SQLite versions 2563 ** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there 2564 ** is now scarcely any need to generate database files that are compatible 2565 ** all the way back to version 3.0.0, and so this setting is of little 2566 ** practical use, but is provided so that SQLite can continue to claim the 2567 ** ability to generate new database files that are compatible with version 2568 ** 3.0.0. 2569 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, 2570 ** the [VACUUM] command will fail with an obscure error when attempting to 2571 ** process a table with generated columns and a descending index. This is 2572 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support 2573 ** either generated columns or descending indexes. 2574 ** </dd> 2575 ** 2576 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] 2577 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> 2578 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in 2579 ** [SQLITE_ENABLE_STMT_SCANSTATUS] builds. In this case, it sets or clears 2580 ** a flag that enables collection of run-time performance statistics 2581 ** used by [sqlite3_stmt_scanstatus_v2()] and the [nexec and ncycle] 2582 ** columns of the [bytecode virtual table]. 2583 ** For statistics to be collected, the flag must be set on 2584 ** the database handle both when the SQL statement is 2585 ** [sqlite3_prepare|prepared] and when it is [sqlite3_step|stepped]. 2586 ** The flag is set (collection of statistics is enabled) by default. 2587 ** <p>This option takes two arguments: an integer and a pointer to 2588 ** an integer. The first argument is 1, 0, or -1 to enable, disable, or 2589 ** leave unchanged the statement scanstatus option. If the second argument 2590 ** is not NULL, then the value of the statement scanstatus setting after 2591 ** processing the first argument is written into the integer that the second 2592 ** argument points to. 2593 ** </dd> 2594 ** 2595 ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]] 2596 ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt> 2597 ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order 2598 ** in which tables and indexes are scanned so that the scans start at the end 2599 ** and work toward the beginning rather than starting at the beginning and 2600 ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the 2601 ** same as setting [PRAGMA reverse_unordered_selects]. <p>This option takes 2602 ** two arguments which are an integer and a pointer to an integer. The first 2603 ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the 2604 ** reverse scan order flag, respectively. If the second argument is not NULL, 2605 ** then 0 or 1 is written into the integer that the second argument points to 2606 ** depending on if the reverse scan order flag is set after processing the 2607 ** first argument. 2608 ** </dd> 2609 ** 2610 ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]] 2611 ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt> 2612 ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables or disables 2613 ** the ability of the [ATTACH DATABASE] SQL command to create a new database 2614 ** file if the database filed named in the ATTACH command does not already 2615 ** exist. This ability of ATTACH to create a new database is enabled by 2616 ** default. Applications can disable or reenable the ability for ATTACH to 2617 ** create new database files using this DBCONFIG option.<p> 2618 ** This option takes two arguments which are an integer and a pointer 2619 ** to an integer. The first argument is 1, 0, or -1 to enable, disable, or 2620 ** leave unchanged the attach-create flag, respectively. If the second 2621 ** argument is not NULL, then 0 or 1 is written into the integer that the 2622 ** second argument points to depending on if the attach-create flag is set 2623 ** after processing the first argument. 2624 ** </dd> 2625 ** 2626 ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]] 2627 ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt> 2628 ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the 2629 ** ability of the [ATTACH DATABASE] SQL command to open a database for writing. 2630 ** This capability is enabled by default. Applications can disable or 2631 ** reenable this capability using the current DBCONFIG option. If 2632 ** this capability is disabled, the [ATTACH] command will still work, 2633 ** but the database will be opened read-only. If this option is disabled, 2634 ** then the ability to create a new database using [ATTACH] is also disabled, 2635 ** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE] 2636 ** option.<p> 2637 ** This option takes two arguments which are an integer and a pointer 2638 ** to an integer. The first argument is 1, 0, or -1 to enable, disable, or 2639 ** leave unchanged the ability to ATTACH another database for writing, 2640 ** respectively. If the second argument is not NULL, then 0 or 1 is written 2641 ** into the integer to which the second argument points, depending on whether 2642 ** the ability to ATTACH a read/write database is enabled or disabled 2643 ** after processing the first argument. 2644 ** </dd> 2645 ** 2646 ** [[SQLITE_DBCONFIG_ENABLE_COMMENTS]] 2647 ** <dt>SQLITE_DBCONFIG_ENABLE_COMMENTS</dt> 2648 ** <dd>The SQLITE_DBCONFIG_ENABLE_COMMENTS option enables or disables the 2649 ** ability to include comments in SQL text. Comments are enabled by default. 2650 ** An application can disable or reenable comments in SQL text using this 2651 ** DBCONFIG option.<p> 2652 ** This option takes two arguments which are an integer and a pointer 2653 ** to an integer. The first argument is 1, 0, or -1 to enable, disable, or 2654 ** leave unchanged the ability to use comments in SQL text, 2655 ** respectively. If the second argument is not NULL, then 0 or 1 is written 2656 ** into the integer that the second argument points to depending on if 2657 ** comments are allowed in SQL text after processing the first argument. 2658 ** </dd> 2659 ** 2660 ** [[SQLITE_DBCONFIG_FP_DIGITS]] 2661 ** <dt>SQLITE_DBCONFIG_FP_DIGITS</dt> 2662 ** <dd>The SQLITE_DBCONFIG_FP_DIGITS setting is a small integer that determines 2663 ** the number of significant digits that SQLite will attempt to preserve when 2664 ** converting floating point numbers (IEEE 754 "doubles") into text. The 2665 ** default value 17, as of SQLite version 3.52.0. The value was 15 in all 2666 ** prior versions.<p> 2667 ** This option takes two arguments which are an integer and a pointer 2668 ** to an integer. The first argument is a small integer, between 3 and 23, or 2669 ** zero. The FP_DIGITS setting is changed to that small integer, or left 2670 ** unaltered if the first argument is zero or out of range. The second argument 2671 ** is a pointer to an integer. If the pointer is not NULL, then the value of 2672 ** the FP_DIGITS setting, after possibly being modified by the first 2673 ** arguments, is written into the integer to which the second argument points. 2674 ** </dd> 2675 ** 2676 ** </dl> 2677 ** 2678 ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3> 2679 ** 2680 ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the 2681 ** overall call to [sqlite3_db_config()] has a total of four parameters. 2682 ** The first argument (the third parameter to sqlite3_db_config()) is 2683 ** an integer. 2684 ** The second argument is a pointer to an integer. If the first argument is 1, 2685 ** then the option becomes enabled. If the first integer argument is 0, 2686 ** then the option is disabled. 2687 ** If the first argument is -1, then the option setting 2688 ** is unchanged. The second argument, the pointer to an integer, may be NULL. 2689 ** If the second argument is not NULL, then a value of 0 or 1 is written into 2690 ** the integer to which the second argument points, depending on whether the 2691 ** setting is disabled or enabled after applying any changes specified by 2692 ** the first argument. 2693 ** 2694 ** <p>While most SQLITE_DBCONFIG options use the argument format 2695 ** described in the previous paragraph, the [SQLITE_DBCONFIG_MAINDBNAME], 2696 ** [SQLITE_DBCONFIG_LOOKASIDE], and [SQLITE_DBCONFIG_FP_DIGITS] options 2697 ** are different. See the documentation of those exceptional options for 2698 ** details. 2699 */ 2700 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ 2701 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ 2702 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ 2703 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ 2704 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */ 2705 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ 2706 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ 2707 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */ 2708 #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */ 2709 #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */ 2710 #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */ 2711 #define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */ 2712 #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */ 2713 #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */ 2714 #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */ 2715 #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */ 2716 #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */ 2717 #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */ 2718 #define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */ 2719 #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */ 2720 #define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE 1020 /* int int* */ 2721 #define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE 1021 /* int int* */ 2722 #define SQLITE_DBCONFIG_ENABLE_COMMENTS 1022 /* int int* */ 2723 #define SQLITE_DBCONFIG_FP_DIGITS 1023 /* int int* */ 2724 #define SQLITE_DBCONFIG_MAX 1023 /* Largest DBCONFIG */ 2725 2726 /* 2727 ** CAPI3REF: Enable Or Disable Extended Result Codes 2728 ** METHOD: sqlite3 2729 ** 2730 ** ^The sqlite3_extended_result_codes() routine enables or disables the 2731 ** [extended result codes] feature of SQLite. ^The extended result 2732 ** codes are disabled by default for historical compatibility. 2733 */ 2734 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); 2735 2736 /* 2737 ** CAPI3REF: Last Insert Rowid 2738 ** METHOD: sqlite3 2739 ** 2740 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) 2741 ** has a unique 64-bit signed 2742 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available 2743 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 2744 ** names are not also used by explicitly declared columns. ^If 2745 ** the table has a column of type [INTEGER PRIMARY KEY] then that column 2746 ** is another alias for the rowid. 2747 ** 2748 ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of 2749 ** the most recent successful [INSERT] into a rowid table or [virtual table] 2750 ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not 2751 ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred 2752 ** on the database connection D, then sqlite3_last_insert_rowid(D) returns 2753 ** zero. 2754 ** 2755 ** As well as being set automatically as rows are inserted into database 2756 ** tables, the value returned by this function may be set explicitly by 2757 ** [sqlite3_set_last_insert_rowid()] 2758 ** 2759 ** Some virtual table implementations may INSERT rows into rowid tables as 2760 ** part of committing a transaction (e.g. to flush data accumulated in memory 2761 ** to disk). In this case subsequent calls to this function return the rowid 2762 ** associated with these internal INSERT operations, which leads to 2763 ** unintuitive results. Virtual table implementations that do write to rowid 2764 ** tables in this way can avoid this problem by restoring the original 2765 ** rowid value using [sqlite3_set_last_insert_rowid()] before returning 2766 ** control to the user. 2767 ** 2768 ** ^(If an [INSERT] occurs within a trigger then this routine will 2769 ** return the [rowid] of the inserted row as long as the trigger is 2770 ** running. Once the trigger program ends, the value returned 2771 ** by this routine reverts to what it was before the trigger was fired.)^ 2772 ** 2773 ** ^An [INSERT] that fails due to a constraint violation is not a 2774 ** successful [INSERT] and does not change the value returned by this 2775 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 2776 ** and INSERT OR ABORT make no changes to the return value of this 2777 ** routine when their insertion fails. ^(When INSERT OR REPLACE 2778 ** encounters a constraint violation, it does not fail. The 2779 ** INSERT continues to completion after deleting rows that caused 2780 ** the constraint problem so INSERT OR REPLACE will always change 2781 ** the return value of this interface.)^ 2782 ** 2783 ** ^For the purposes of this routine, an [INSERT] is considered to 2784 ** be successful even if it is subsequently rolled back. 2785 ** 2786 ** This function is accessible to SQL statements via the 2787 ** [last_insert_rowid() SQL function]. 2788 ** 2789 ** If a separate thread performs a new [INSERT] on the same 2790 ** database connection while the [sqlite3_last_insert_rowid()] 2791 ** function is running and thus changes the last insert [rowid], 2792 ** then the value returned by [sqlite3_last_insert_rowid()] is 2793 ** unpredictable and might not equal either the old or the new 2794 ** last insert [rowid]. 2795 */ 2796 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 2797 2798 /* 2799 ** CAPI3REF: Set the Last Insert Rowid value. 2800 ** METHOD: sqlite3 2801 ** 2802 ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to 2803 ** set the value returned by calling sqlite3_last_insert_rowid(D) to R 2804 ** without inserting a row into the database. 2805 */ 2806 SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); 2807 2808 /* 2809 ** CAPI3REF: Count The Number Of Rows Modified 2810 ** METHOD: sqlite3 2811 ** 2812 ** ^These functions return the number of rows modified, inserted or 2813 ** deleted by the most recently completed INSERT, UPDATE or DELETE 2814 ** statement on the database connection specified by the only parameter. 2815 ** The two functions are identical except for the type of the return value 2816 ** and that if the number of rows modified by the most recent INSERT, UPDATE, 2817 ** or DELETE is greater than the maximum value supported by type "int", then 2818 ** the return value of sqlite3_changes() is undefined. ^Executing any other 2819 ** type of SQL statement does not modify the value returned by these functions. 2820 ** For the purposes of this interface, a CREATE TABLE AS SELECT statement 2821 ** does not count as an INSERT, UPDATE or DELETE statement and hence the rows 2822 ** added to the new table by the CREATE TABLE AS SELECT statement are not 2823 ** counted. 2824 ** 2825 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are 2826 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers], 2827 ** [foreign key actions] or [REPLACE] constraint resolution are not counted. 2828 ** 2829 ** Changes to a view that are intercepted by 2830 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value 2831 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or 2832 ** DELETE statement run on a view is always zero. Only changes made to real 2833 ** tables are counted. 2834 ** 2835 ** Things are more complicated if the sqlite3_changes() function is 2836 ** executed while a trigger program is running. This may happen if the 2837 ** program uses the [changes() SQL function], or if some other callback 2838 ** function invokes sqlite3_changes() directly. Essentially: 2839 ** 2840 ** <ul> 2841 ** <li> ^(Before entering a trigger program the value returned by 2842 ** sqlite3_changes() function is saved. After the trigger program 2843 ** has finished, the original value is restored.)^ 2844 ** 2845 ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE 2846 ** statement sets the value returned by sqlite3_changes() 2847 ** upon completion as normal. Of course, this value will not include 2848 ** any changes performed by sub-triggers, as the sqlite3_changes() 2849 ** value will be saved and restored after each sub-trigger has run.)^ 2850 ** </ul> 2851 ** 2852 ** ^This means that if the changes() SQL function (or similar) is used 2853 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it 2854 ** returns the value as set when the calling statement began executing. 2855 ** ^If it is used by the second or subsequent such statement within a trigger 2856 ** program, the value returned reflects the number of rows modified by the 2857 ** previous INSERT, UPDATE or DELETE statement within the same trigger. 2858 ** 2859 ** If a separate thread makes changes on the same database connection 2860 ** while [sqlite3_changes()] is running then the value returned 2861 ** is unpredictable and not meaningful. 2862 ** 2863 ** See also: 2864 ** <ul> 2865 ** <li> the [sqlite3_total_changes()] interface 2866 ** <li> the [count_changes pragma] 2867 ** <li> the [changes() SQL function] 2868 ** <li> the [data_version pragma] 2869 ** </ul> 2870 */ 2871 SQLITE_API int sqlite3_changes(sqlite3*); 2872 SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*); 2873 2874 /* 2875 ** CAPI3REF: Total Number Of Rows Modified 2876 ** METHOD: sqlite3 2877 ** 2878 ** ^These functions return the total number of rows inserted, modified or 2879 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed 2880 ** since the database connection was opened, including those executed as 2881 ** part of trigger programs. The two functions are identical except for the 2882 ** type of the return value and that if the number of rows modified by the 2883 ** connection exceeds the maximum value supported by type "int", then 2884 ** the return value of sqlite3_total_changes() is undefined. ^Executing 2885 ** any other type of SQL statement does not affect the value returned by 2886 ** sqlite3_total_changes(). 2887 ** 2888 ** ^Changes made as part of [foreign key actions] are included in the 2889 ** count, but those made as part of REPLACE constraint resolution are 2890 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers 2891 ** are not counted. 2892 ** 2893 ** The [sqlite3_total_changes(D)] interface only reports the number 2894 ** of rows that changed due to SQL statement run against database 2895 ** connection D. Any changes by other database connections are ignored. 2896 ** To detect changes against a database file from other database 2897 ** connections use the [PRAGMA data_version] command or the 2898 ** [SQLITE_FCNTL_DATA_VERSION] [file control]. 2899 ** 2900 ** If a separate thread makes changes on the same database connection 2901 ** while [sqlite3_total_changes()] is running then the value 2902 ** returned is unpredictable and not meaningful. 2903 ** 2904 ** See also: 2905 ** <ul> 2906 ** <li> the [sqlite3_changes()] interface 2907 ** <li> the [count_changes pragma] 2908 ** <li> the [changes() SQL function] 2909 ** <li> the [data_version pragma] 2910 ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control] 2911 ** </ul> 2912 */ 2913 SQLITE_API int sqlite3_total_changes(sqlite3*); 2914 SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*); 2915 2916 /* 2917 ** CAPI3REF: Interrupt A Long-Running Query 2918 ** METHOD: sqlite3 2919 ** 2920 ** ^This function causes any pending database operation to abort and 2921 ** return at its earliest opportunity. This routine is typically 2922 ** called in response to a user action such as pressing "Cancel" 2923 ** or Ctrl-C where the user wants a long query operation to halt 2924 ** immediately. 2925 ** 2926 ** ^It is safe to call this routine from a thread different from the 2927 ** thread that is currently running the database operation. But it 2928 ** is not safe to call this routine with a [database connection] that 2929 ** is closed or might close before sqlite3_interrupt() returns. 2930 ** 2931 ** ^If an SQL operation is very nearly finished at the time when 2932 ** sqlite3_interrupt() is called, then it might not have an opportunity 2933 ** to be interrupted and might continue to completion. 2934 ** 2935 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. 2936 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE 2937 ** that is inside an explicit transaction, then the entire transaction 2938 ** will be rolled back automatically. 2939 ** 2940 ** ^The sqlite3_interrupt(D) call is in effect until all currently running 2941 ** SQL statements on [database connection] D complete. ^Any new SQL statements 2942 ** that are started after the sqlite3_interrupt() call and before the 2943 ** running statement count reaches zero are interrupted as if they had been 2944 ** running prior to the sqlite3_interrupt() call. ^New SQL statements 2945 ** that are started after the running statement count reaches zero are 2946 ** not effected by the sqlite3_interrupt(). 2947 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running 2948 ** SQL statements is a no-op and has no effect on SQL statements 2949 ** that are started after the sqlite3_interrupt() call returns. 2950 ** 2951 ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether 2952 ** or not an interrupt is currently in effect for [database connection] D. 2953 ** It returns 1 if an interrupt is currently in effect, or 0 otherwise. 2954 */ 2955 SQLITE_API void sqlite3_interrupt(sqlite3*); 2956 SQLITE_API int sqlite3_is_interrupted(sqlite3*); 2957 2958 /* 2959 ** CAPI3REF: Determine If An SQL Statement Is Complete 2960 ** 2961 ** These routines are useful during command-line input to determine if the 2962 ** currently entered text seems to form a complete SQL statement or 2963 ** if additional input is needed before sending the text into 2964 ** SQLite for parsing. ^These routines return 1 if the input string 2965 ** appears to be a complete SQL statement. ^A statement is judged to be 2966 ** complete if it ends with a semicolon token and is not a prefix of a 2967 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within 2968 ** string literals or quoted identifier names or comments are not 2969 ** independent tokens (they are part of the token in which they are 2970 ** embedded) and thus do not count as a statement terminator. ^Whitespace 2971 ** and comments that follow the final semicolon are ignored. 2972 ** 2973 ** ^These routines return 0 if the statement is incomplete. ^If a 2974 ** memory allocation fails, then SQLITE_NOMEM is returned. 2975 ** 2976 ** ^These routines do not parse the SQL statements and thus 2977 ** will not detect syntactically incorrect SQL. 2978 ** 2979 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 2980 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked 2981 ** automatically by sqlite3_complete16(). If that initialization fails, 2982 ** then the return value from sqlite3_complete16() will be non-zero 2983 ** regardless of whether or not the input SQL is complete.)^ 2984 ** 2985 ** The input to [sqlite3_complete()] must be a zero-terminated 2986 ** UTF-8 string. 2987 ** 2988 ** The input to [sqlite3_complete16()] must be a zero-terminated 2989 ** UTF-16 string in native byte order. 2990 */ 2991 SQLITE_API int sqlite3_complete(const char *sql); 2992 SQLITE_API int sqlite3_complete16(const void *sql); 2993 2994 /* 2995 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 2996 ** KEYWORDS: {busy-handler callback} {busy handler} 2997 ** METHOD: sqlite3 2998 ** 2999 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X 3000 ** that might be invoked with argument P whenever 3001 ** an attempt is made to access a database table associated with 3002 ** [database connection] D when another thread 3003 ** or process has the table locked. 3004 ** The sqlite3_busy_handler() interface is used to implement 3005 ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. 3006 ** 3007 ** ^If the busy callback is NULL, then [SQLITE_BUSY] 3008 ** is returned immediately upon encountering the lock. ^If the busy callback 3009 ** is not NULL, then the callback might be invoked with two arguments. 3010 ** 3011 ** ^The first argument to the busy handler is a copy of the void* pointer which 3012 ** is the third argument to sqlite3_busy_handler(). ^The second argument to 3013 ** the busy handler callback is the number of times that the busy handler has 3014 ** been invoked previously for the same locking event. ^If the 3015 ** busy callback returns 0, then no additional attempts are made to 3016 ** access the database and [SQLITE_BUSY] is returned 3017 ** to the application. 3018 ** ^If the callback returns non-zero, then another attempt 3019 ** is made to access the database and the cycle repeats. 3020 ** 3021 ** The presence of a busy handler does not guarantee that it will be invoked 3022 ** when there is lock contention. ^If SQLite determines that invoking the busy 3023 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 3024 ** to the application instead of invoking the 3025 ** busy handler. 3026 ** Consider a scenario where one process is holding a read lock that 3027 ** it is trying to promote to a reserved lock and 3028 ** a second process is holding a reserved lock that it is trying 3029 ** to promote to an exclusive lock. The first process cannot proceed 3030 ** because it is blocked by the second and the second process cannot 3031 ** proceed because it is blocked by the first. If both processes 3032 ** invoke the busy handlers, neither will make any progress. Therefore, 3033 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 3034 ** will induce the first process to release its read lock and allow 3035 ** the second process to proceed. 3036 ** 3037 ** ^The default busy callback is NULL. 3038 ** 3039 ** ^(There can only be a single busy handler defined for each 3040 ** [database connection]. Setting a new busy handler clears any 3041 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 3042 ** or evaluating [PRAGMA busy_timeout=N] will change the 3043 ** busy handler and thus clear any previously set busy handler. 3044 ** 3045 ** The busy callback should not take any actions which modify the 3046 ** database connection that invoked the busy handler. In other words, 3047 ** the busy handler is not reentrant. Any such actions 3048 ** result in undefined behavior. 3049 ** 3050 ** A busy handler must not close the database connection 3051 ** or [prepared statement] that invoked the busy handler. 3052 */ 3053 SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*); 3054 3055 /* 3056 ** CAPI3REF: Set A Busy Timeout 3057 ** METHOD: sqlite3 3058 ** 3059 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 3060 ** for a specified amount of time when a table is locked. ^The handler 3061 ** will sleep multiple times until at least "ms" milliseconds of sleeping 3062 ** have accumulated. ^After at least "ms" milliseconds of sleeping, 3063 ** the handler returns 0 which causes [sqlite3_step()] to return 3064 ** [SQLITE_BUSY]. 3065 ** 3066 ** ^Calling this routine with an argument less than or equal to zero 3067 ** turns off all busy handlers. 3068 ** 3069 ** ^(There can only be a single busy handler for a particular 3070 ** [database connection] at any given moment. If another busy handler 3071 ** was defined (using [sqlite3_busy_handler()]) prior to calling 3072 ** this routine, that other busy handler is cleared.)^ 3073 ** 3074 ** See also: [PRAGMA busy_timeout] 3075 */ 3076 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); 3077 3078 /* 3079 ** CAPI3REF: Set the Setlk Timeout 3080 ** METHOD: sqlite3 3081 ** 3082 ** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If 3083 ** the VFS supports blocking locks, it sets the timeout in ms used by 3084 ** eligible locks taken on wal mode databases by the specified database 3085 ** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does 3086 ** not support blocking locks, this function is a no-op. 3087 ** 3088 ** Passing 0 to this function disables blocking locks altogether. Passing 3089 ** -1 to this function requests that the VFS blocks for a long time - 3090 ** indefinitely if possible. The results of passing any other negative value 3091 ** are undefined. 3092 ** 3093 ** Internally, each SQLite database handle stores two timeout values - the 3094 ** busy-timeout (used for rollback mode databases, or if the VFS does not 3095 ** support blocking locks) and the setlk-timeout (used for blocking locks 3096 ** on wal-mode databases). The sqlite3_busy_timeout() method sets both 3097 ** values, this function sets only the setlk-timeout value. Therefore, 3098 ** to configure separate busy-timeout and setlk-timeout values for a single 3099 ** database handle, call sqlite3_busy_timeout() followed by this function. 3100 ** 3101 ** Whenever the number of connections to a wal mode database falls from 3102 ** 1 to 0, the last connection takes an exclusive lock on the database, 3103 ** then checkpoints and deletes the wal file. While it is doing this, any 3104 ** new connection that tries to read from the database fails with an 3105 ** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is 3106 ** passed to this API, the new connection blocks until the exclusive lock 3107 ** has been released. 3108 */ 3109 SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags); 3110 3111 /* 3112 ** CAPI3REF: Flags for sqlite3_setlk_timeout() 3113 */ 3114 #define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01 3115 3116 /* 3117 ** CAPI3REF: Convenience Routines For Running Queries 3118 ** METHOD: sqlite3 3119 ** 3120 ** This is a legacy interface that is preserved for backwards compatibility. 3121 ** Use of this interface is not recommended. 3122 ** 3123 ** Definition: A <b>result table</b> is a memory data structure created by the 3124 ** [sqlite3_get_table()] interface. A result table records the 3125 ** complete query results from one or more queries. 3126 ** 3127 ** The table conceptually has a number of rows and columns. But 3128 ** these numbers are not part of the result table itself. These 3129 ** numbers are obtained separately. Let N be the number of rows 3130 ** and M be the number of columns. 3131 ** 3132 ** A result table is an array of pointers to zero-terminated UTF-8 strings. 3133 ** There are (N+1)*M elements in the array. The first M pointers point 3134 ** to zero-terminated strings that contain the names of the columns. 3135 ** The remaining entries all point to query results. NULL values result 3136 ** in NULL pointers. All other values are in their UTF-8 zero-terminated 3137 ** string representation as returned by [sqlite3_column_text()]. 3138 ** 3139 ** A result table might consist of one or more memory allocations. 3140 ** It is not safe to pass a result table directly to [sqlite3_free()]. 3141 ** A result table should be deallocated using [sqlite3_free_table()]. 3142 ** 3143 ** ^(As an example of the result table format, suppose a query result 3144 ** is as follows: 3145 ** 3146 ** <blockquote><pre> 3147 ** Name | Age 3148 ** ----------------------- 3149 ** Alice | 43 3150 ** Bob | 28 3151 ** Cindy | 21 3152 ** </pre></blockquote> 3153 ** 3154 ** There are two columns (M==2) and three rows (N==3). Thus the 3155 ** result table has 8 entries. Suppose the result table is stored 3156 ** in an array named azResult. Then azResult holds this content: 3157 ** 3158 ** <blockquote><pre> 3159 ** azResult[0] = "Name"; 3160 ** azResult[1] = "Age"; 3161 ** azResult[2] = "Alice"; 3162 ** azResult[3] = "43"; 3163 ** azResult[4] = "Bob"; 3164 ** azResult[5] = "28"; 3165 ** azResult[6] = "Cindy"; 3166 ** azResult[7] = "21"; 3167 ** </pre></blockquote>)^ 3168 ** 3169 ** ^The sqlite3_get_table() function evaluates one or more 3170 ** semicolon-separated SQL statements in the zero-terminated UTF-8 3171 ** string of its 2nd parameter and returns a result table to the 3172 ** pointer given in its 3rd parameter. 3173 ** 3174 ** After the application has finished with the result from sqlite3_get_table(), 3175 ** it must pass the result table pointer to sqlite3_free_table() in order to 3176 ** release the memory that was malloced. Because of the way the 3177 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling 3178 ** function must not try to call [sqlite3_free()] directly. Only 3179 ** [sqlite3_free_table()] is able to release the memory properly and safely. 3180 ** 3181 ** The sqlite3_get_table() interface is implemented as a wrapper around 3182 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access 3183 ** to any internal data structures of SQLite. It uses only the public 3184 ** interface defined here. As a consequence, errors that occur in the 3185 ** wrapper layer outside of the internal [sqlite3_exec()] call are not 3186 ** reflected in subsequent calls to [sqlite3_errcode()] or 3187 ** [sqlite3_errmsg()]. 3188 */ 3189 SQLITE_API int sqlite3_get_table( 3190 sqlite3 *db, /* An open database */ 3191 const char *zSql, /* SQL to be evaluated */ 3192 char ***pazResult, /* Results of the query */ 3193 int *pnRow, /* Number of result rows written here */ 3194 int *pnColumn, /* Number of result columns written here */ 3195 char **pzErrmsg /* Error msg written here */ 3196 ); 3197 SQLITE_API void sqlite3_free_table(char **result); 3198 3199 /* 3200 ** CAPI3REF: Formatted String Printing Functions 3201 ** 3202 ** These routines are work-alikes of the "printf()" family of functions 3203 ** from the standard C library. 3204 ** These routines understand most of the common formatting options from 3205 ** the standard library printf() 3206 ** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]). 3207 ** See the [built-in printf()] documentation for details. 3208 ** 3209 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their 3210 ** results into memory obtained from [sqlite3_malloc64()]. 3211 ** The strings returned by these two routines should be 3212 ** released by [sqlite3_free()]. ^Both routines return a 3213 ** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough 3214 ** memory to hold the resulting string. 3215 ** 3216 ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from 3217 ** the standard C library. The result is written into the 3218 ** buffer supplied as the second parameter whose size is given by 3219 ** the first parameter. Note that the order of the 3220 ** first two parameters is reversed from snprintf().)^ This is an 3221 ** historical accident that cannot be fixed without breaking 3222 ** backwards compatibility. ^(Note also that sqlite3_snprintf() 3223 ** returns a pointer to its buffer instead of the number of 3224 ** characters actually written into the buffer.)^ We admit that 3225 ** the number of characters written would be a more useful return 3226 ** value but we cannot change the implementation of sqlite3_snprintf() 3227 ** now without breaking compatibility. 3228 ** 3229 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() 3230 ** guarantees that the buffer is always zero-terminated. ^The first 3231 ** parameter "n" is the total size of the buffer, including space for 3232 ** the zero terminator. So the longest string that can be completely 3233 ** written will be n-1 characters. 3234 ** 3235 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 3236 ** 3237 ** See also: [built-in printf()], [printf() SQL function] 3238 */ 3239 SQLITE_API char *sqlite3_mprintf(const char*,...); 3240 SQLITE_API char *sqlite3_vmprintf(const char*, va_list); 3241 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); 3242 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); 3243 3244 /* 3245 ** CAPI3REF: Memory Allocation Subsystem 3246 ** 3247 ** The SQLite core uses these three routines for all of its own 3248 ** internal memory allocation needs. "Core" in the previous sentence 3249 ** does not include operating-system specific [VFS] implementation. The 3250 ** Windows VFS uses native malloc() and free() for some operations. 3251 ** 3252 ** ^The sqlite3_malloc() routine returns a pointer to a block 3253 ** of memory at least N bytes in length, where N is the parameter. 3254 ** ^If sqlite3_malloc() is unable to obtain sufficient free 3255 ** memory, it returns a NULL pointer. ^If the parameter N to 3256 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 3257 ** a NULL pointer. 3258 ** 3259 ** ^The sqlite3_malloc64(N) routine works just like 3260 ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead 3261 ** of a signed 32-bit integer. 3262 ** 3263 ** ^Calling sqlite3_free() with a pointer previously returned 3264 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 3265 ** that it might be reused. ^The sqlite3_free() routine is 3266 ** a no-op if it is called with a NULL pointer. Passing a NULL pointer 3267 ** to sqlite3_free() is harmless. After being freed, memory 3268 ** should neither be read nor written. Even reading previously freed 3269 ** memory might result in a segmentation fault or other severe error. 3270 ** Memory corruption, a segmentation fault, or other severe error 3271 ** might result if sqlite3_free() is called with a non-NULL pointer that 3272 ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 3273 ** 3274 ** ^The sqlite3_realloc(X,N) interface attempts to resize a 3275 ** prior memory allocation X to be at least N bytes. 3276 ** ^If the X parameter to sqlite3_realloc(X,N) 3277 ** is a NULL pointer then its behavior is identical to calling 3278 ** sqlite3_malloc(N). 3279 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or 3280 ** negative then the behavior is exactly the same as calling 3281 ** sqlite3_free(X). 3282 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation 3283 ** of at least N bytes in size or NULL if insufficient memory is available. 3284 ** ^If M is the size of the prior allocation, then min(N,M) bytes of the 3285 ** prior allocation are copied into the beginning of the buffer returned 3286 ** by sqlite3_realloc(X,N) and the prior allocation is freed. 3287 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the 3288 ** prior allocation is not freed. 3289 ** 3290 ** ^The sqlite3_realloc64(X,N) interface works the same as 3291 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead 3292 ** of a 32-bit signed integer. 3293 ** 3294 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(), 3295 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then 3296 ** sqlite3_msize(X) returns the size of that memory allocation in bytes. 3297 ** ^The value returned by sqlite3_msize(X) might be larger than the number 3298 ** of bytes requested when X was allocated. ^If X is a NULL pointer then 3299 ** sqlite3_msize(X) returns zero. If X points to something that is not 3300 ** the beginning of memory allocation, or if it points to a formerly 3301 ** valid memory allocation that has now been freed, then the behavior 3302 ** of sqlite3_msize(X) is undefined and possibly harmful. 3303 ** 3304 ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(), 3305 ** sqlite3_malloc64(), and sqlite3_realloc64() 3306 ** is always aligned to at least an 8 byte boundary, or to a 3307 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time 3308 ** option is used. 3309 ** 3310 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 3311 ** must be either NULL or else pointers obtained from a prior 3312 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 3313 ** not yet been released. 3314 ** 3315 ** The application must not read or write any part of 3316 ** a block of memory after it has been released using 3317 ** [sqlite3_free()] or [sqlite3_realloc()]. 3318 */ 3319 SQLITE_API void *sqlite3_malloc(int); 3320 SQLITE_API void *sqlite3_malloc64(sqlite3_uint64); 3321 SQLITE_API void *sqlite3_realloc(void*, int); 3322 SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64); 3323 SQLITE_API void sqlite3_free(void*); 3324 SQLITE_API sqlite3_uint64 sqlite3_msize(void*); 3325 3326 /* 3327 ** CAPI3REF: Memory Allocator Statistics 3328 ** 3329 ** SQLite provides these two interfaces for reporting on the status 3330 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 3331 ** routines, which form the built-in memory allocation subsystem. 3332 ** 3333 ** ^The [sqlite3_memory_used()] routine returns the number of bytes 3334 ** of memory currently outstanding (malloced but not freed). 3335 ** ^The [sqlite3_memory_highwater()] routine returns the maximum 3336 ** value of [sqlite3_memory_used()] since the high-water mark 3337 ** was last reset. ^The values returned by [sqlite3_memory_used()] and 3338 ** [sqlite3_memory_highwater()] include any overhead 3339 ** added by SQLite in its implementation of [sqlite3_malloc()], 3340 ** but not overhead added by any underlying system library 3341 ** routines that [sqlite3_malloc()] may call. 3342 ** 3343 ** ^The memory high-water mark is reset to the current value of 3344 ** [sqlite3_memory_used()] if and only if the parameter to 3345 ** [sqlite3_memory_highwater()] is true. ^The value returned 3346 ** by [sqlite3_memory_highwater(1)] is the high-water mark 3347 ** prior to the reset. 3348 */ 3349 SQLITE_API sqlite3_int64 sqlite3_memory_used(void); 3350 SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); 3351 3352 /* 3353 ** CAPI3REF: Pseudo-Random Number Generator 3354 ** 3355 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 3356 ** select random [ROWID | ROWIDs] when inserting new records into a table that 3357 ** already uses the largest possible [ROWID]. The PRNG is also used for 3358 ** the built-in random() and randomblob() SQL functions. This interface allows 3359 ** applications to access the same PRNG for other purposes. 3360 ** 3361 ** ^A call to this routine stores N bytes of randomness into buffer P. 3362 ** ^The P parameter can be a NULL pointer. 3363 ** 3364 ** ^If this routine has not been previously called or if the previous 3365 ** call had N less than one or a NULL pointer for P, then the PRNG is 3366 ** seeded using randomness obtained from the xRandomness method of 3367 ** the default [sqlite3_vfs] object. 3368 ** ^If the previous call to this routine had an N of 1 or more and a 3369 ** non-NULL P then the pseudo-randomness is generated 3370 ** internally and without recourse to the [sqlite3_vfs] xRandomness 3371 ** method. 3372 */ 3373 SQLITE_API void sqlite3_randomness(int N, void *P); 3374 3375 /* 3376 ** CAPI3REF: Compile-Time Authorization Callbacks 3377 ** METHOD: sqlite3 3378 ** KEYWORDS: {authorizer callback} 3379 ** 3380 ** ^This routine registers an authorizer callback with a particular 3381 ** [database connection], supplied in the first argument. 3382 ** ^The authorizer callback is invoked as SQL statements are being compiled 3383 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], 3384 ** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()], 3385 ** and [sqlite3_prepare16_v3()]. ^At various 3386 ** points during the compilation process, as logic is being created 3387 ** to perform various actions, the authorizer callback is invoked to 3388 ** see if those actions are allowed. ^The authorizer callback should 3389 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the 3390 ** specific action but allow the SQL statement to continue to be 3391 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be 3392 ** rejected with an error. ^If the authorizer callback returns 3393 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] 3394 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered 3395 ** the authorizer will fail with an error message. 3396 ** 3397 ** When the callback returns [SQLITE_OK], that means the operation 3398 ** requested is ok. ^When the callback returns [SQLITE_DENY], the 3399 ** [sqlite3_prepare_v2()] or equivalent call that triggered the 3400 ** authorizer will fail with an error message explaining that 3401 ** access is denied. 3402 ** 3403 ** ^The first parameter to the authorizer callback is a copy of the third 3404 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter 3405 ** to the callback is an integer [SQLITE_COPY | action code] that specifies 3406 ** the particular action to be authorized. ^The third through sixth parameters 3407 ** to the callback are either NULL pointers or zero-terminated strings 3408 ** that contain additional details about the action to be authorized. 3409 ** Applications must always be prepared to encounter a NULL pointer in any 3410 ** of the third through the sixth parameters of the authorization callback. 3411 ** 3412 ** ^If the action code is [SQLITE_READ] 3413 ** and the callback returns [SQLITE_IGNORE] then the 3414 ** [prepared statement] statement is constructed to substitute 3415 ** a NULL value in place of the table column that would have 3416 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] 3417 ** return can be used to deny an untrusted user access to individual 3418 ** columns of a table. 3419 ** ^When a table is referenced by a [SELECT] but no column values are 3420 ** extracted from that table (for example in a query like 3421 ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback 3422 ** is invoked once for that table with a column name that is an empty string. 3423 ** ^If the action code is [SQLITE_DELETE] and the callback returns 3424 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the 3425 ** [truncate optimization] is disabled and all rows are deleted individually. 3426 ** 3427 ** An authorizer is used when [sqlite3_prepare | preparing] 3428 ** SQL statements from an untrusted source, to ensure that the SQL statements 3429 ** do not try to access data they are not allowed to see, or that they do not 3430 ** try to execute malicious statements that damage the database. For 3431 ** example, an application may allow a user to enter arbitrary 3432 ** SQL queries for evaluation by a database. But the application does 3433 ** not want the user to be able to make arbitrary changes to the 3434 ** database. An authorizer could then be put in place while the 3435 ** user-entered SQL is being [sqlite3_prepare | prepared] that 3436 ** disallows everything except [SELECT] statements. 3437 ** 3438 ** Applications that need to process SQL from untrusted sources 3439 ** might also consider lowering resource limits using [sqlite3_limit()] 3440 ** and limiting database size using the [max_page_count] [PRAGMA] 3441 ** in addition to using an authorizer. 3442 ** 3443 ** ^(Only a single authorizer can be in place on a database connection 3444 ** at a time. Each call to sqlite3_set_authorizer overrides the 3445 ** previous call.)^ ^Disable the authorizer by installing a NULL callback. 3446 ** The authorizer is disabled by default. 3447 ** 3448 ** The authorizer callback must not do anything that will modify 3449 ** the database connection that invoked the authorizer callback. 3450 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 3451 ** database connections for the meaning of "modify" in this paragraph. 3452 ** 3453 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the 3454 ** statement might be re-prepared during [sqlite3_step()] due to a 3455 ** schema change. Hence, the application should ensure that the 3456 ** correct authorizer callback remains in place during the [sqlite3_step()]. 3457 ** 3458 ** ^Note that the authorizer callback is invoked only during 3459 ** [sqlite3_prepare()] or its variants. Authorization is not 3460 ** performed during statement evaluation in [sqlite3_step()], unless 3461 ** as stated in the previous paragraph, sqlite3_step() invokes 3462 ** sqlite3_prepare_v2() to reprepare a statement after a schema change. 3463 */ 3464 SQLITE_API int sqlite3_set_authorizer( 3465 sqlite3*, 3466 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 3467 void *pUserData 3468 ); 3469 3470 /* 3471 ** CAPI3REF: Authorizer Return Codes 3472 ** 3473 ** The [sqlite3_set_authorizer | authorizer callback function] must 3474 ** return either [SQLITE_OK] or one of these two constants in order 3475 ** to signal SQLite whether or not the action is permitted. See the 3476 ** [sqlite3_set_authorizer | authorizer documentation] for additional 3477 ** information. 3478 ** 3479 ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] 3480 ** returned from the [sqlite3_vtab_on_conflict()] interface. 3481 */ 3482 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 3483 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 3484 3485 /* 3486 ** CAPI3REF: Authorizer Action Codes 3487 ** 3488 ** The [sqlite3_set_authorizer()] interface registers a callback function 3489 ** that is invoked to authorize certain SQL statement actions. The 3490 ** second parameter to the callback is an integer code that specifies 3491 ** what action is being authorized. These are the integer action codes that 3492 ** the authorizer callback may be passed. 3493 ** 3494 ** These action code values signify what kind of operation is to be 3495 ** authorized. The 3rd and 4th parameters to the authorization 3496 ** callback function will be parameters or NULL depending on which of these 3497 ** codes is used as the second parameter. ^(The 5th parameter to the 3498 ** authorizer callback is the name of the database ("main", "temp", 3499 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback 3500 ** is the name of the inner-most trigger or view that is responsible for 3501 ** the access attempt or NULL if this access attempt is directly from 3502 ** top-level SQL code. 3503 */ 3504 /******************************************* 3rd ************ 4th ***********/ 3505 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 3506 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 3507 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 3508 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 3509 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 3510 #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 3511 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 3512 #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 3513 #define SQLITE_DELETE 9 /* Table Name NULL */ 3514 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 3515 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 3516 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 3517 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 3518 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 3519 #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 3520 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 3521 #define SQLITE_DROP_VIEW 17 /* View Name NULL */ 3522 #define SQLITE_INSERT 18 /* Table Name NULL */ 3523 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 3524 #define SQLITE_READ 20 /* Table Name Column Name */ 3525 #define SQLITE_SELECT 21 /* NULL NULL */ 3526 #define SQLITE_TRANSACTION 22 /* Operation NULL */ 3527 #define SQLITE_UPDATE 23 /* Table Name Column Name */ 3528 #define SQLITE_ATTACH 24 /* Filename NULL */ 3529 #define SQLITE_DETACH 25 /* Database Name NULL */ 3530 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 3531 #define SQLITE_REINDEX 27 /* Index Name NULL */ 3532 #define SQLITE_ANALYZE 28 /* Table Name NULL */ 3533 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 3534 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 3535 #define SQLITE_FUNCTION 31 /* NULL Function Name */ 3536 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 3537 #define SQLITE_COPY 0 /* No longer used */ 3538 #define SQLITE_RECURSIVE 33 /* NULL NULL */ 3539 3540 /* 3541 ** CAPI3REF: Deprecated Tracing And Profiling Functions 3542 ** DEPRECATED 3543 ** 3544 ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface 3545 ** instead of the routines described here. 3546 ** 3547 ** These routines register callback functions that can be used for 3548 ** tracing and profiling the execution of SQL statements. 3549 ** 3550 ** ^The callback function registered by sqlite3_trace() is invoked at 3551 ** various times when an SQL statement is being run by [sqlite3_step()]. 3552 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 3553 ** SQL statement text as the statement first begins executing. 3554 ** ^(Additional sqlite3_trace() callbacks might occur 3555 ** as each triggered subprogram is entered. The callbacks for triggers 3556 ** contain a UTF-8 SQL comment that identifies the trigger.)^ 3557 ** 3558 ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit 3559 ** the length of [bound parameter] expansion in the output of sqlite3_trace(). 3560 ** 3561 ** ^The callback function registered by sqlite3_profile() is invoked 3562 ** as each SQL statement finishes. ^The profile callback contains 3563 ** the original statement text and an estimate of wall-clock time 3564 ** of how long that statement took to run. ^The profile callback 3565 ** time is in units of nanoseconds, however the current implementation 3566 ** is only capable of millisecond resolution so the six least significant 3567 ** digits in the time are meaningless. Future versions of SQLite 3568 ** might provide greater resolution on the profiler callback. Invoking 3569 ** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the 3570 ** profile callback. 3571 */ 3572 SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*, 3573 void(*xTrace)(void*,const char*), void*); 3574 SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*, 3575 void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 3576 3577 /* 3578 ** CAPI3REF: SQL Trace Event Codes 3579 ** KEYWORDS: SQLITE_TRACE 3580 ** 3581 ** These constants identify classes of events that can be monitored 3582 ** using the [sqlite3_trace_v2()] tracing logic. The M argument 3583 ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of 3584 ** the following constants. ^The first argument to the trace callback 3585 ** is one of the following constants. 3586 ** 3587 ** New tracing constants may be added in future releases. 3588 ** 3589 ** ^A trace callback has four arguments: xCallback(T,C,P,X). 3590 ** ^The T argument is one of the integer type codes above. 3591 ** ^The C argument is a copy of the context pointer passed in as the 3592 ** fourth argument to [sqlite3_trace_v2()]. 3593 ** The P and X arguments are pointers whose meanings depend on T. 3594 ** 3595 ** <dl> 3596 ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt> 3597 ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement 3598 ** first begins running and possibly at other times during the 3599 ** execution of the prepared statement, such as at the start of each 3600 ** trigger subprogram. ^The P argument is a pointer to the 3601 ** [prepared statement]. ^The X argument is a pointer to a string which 3602 ** is the unexpanded SQL text of the prepared statement or an SQL comment 3603 ** that indicates the invocation of a trigger. ^The callback can compute 3604 ** the same text that would have been returned by the legacy [sqlite3_trace()] 3605 ** interface by using the X argument when X begins with "--" and invoking 3606 ** [sqlite3_expanded_sql(P)] otherwise. 3607 ** 3608 ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt> 3609 ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same 3610 ** information as is provided by the [sqlite3_profile()] callback. 3611 ** ^The P argument is a pointer to the [prepared statement] and the 3612 ** X argument points to a 64-bit integer which is approximately 3613 ** the number of nanoseconds that the prepared statement took to run. 3614 ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes. 3615 ** 3616 ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt> 3617 ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared 3618 ** statement generates a single row of result. 3619 ** ^The P argument is a pointer to the [prepared statement] and the 3620 ** X argument is unused. 3621 ** 3622 ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt> 3623 ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database 3624 ** connection closes. 3625 ** ^The P argument is a pointer to the [database connection] object 3626 ** and the X argument is unused. 3627 ** </dl> 3628 */ 3629 #define SQLITE_TRACE_STMT 0x01 3630 #define SQLITE_TRACE_PROFILE 0x02 3631 #define SQLITE_TRACE_ROW 0x04 3632 #define SQLITE_TRACE_CLOSE 0x08 3633 3634 /* 3635 ** CAPI3REF: SQL Trace Hook 3636 ** METHOD: sqlite3 3637 ** 3638 ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback 3639 ** function X against [database connection] D, using property mask M 3640 ** and context pointer P. ^If the X callback is 3641 ** NULL or if the M mask is zero, then tracing is disabled. The 3642 ** M argument should be the bitwise OR-ed combination of 3643 ** zero or more [SQLITE_TRACE] constants. 3644 ** 3645 ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P) 3646 ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or 3647 ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each 3648 ** database connection may have at most one trace callback. 3649 ** 3650 ** ^The X callback is invoked whenever any of the events identified by 3651 ** mask M occur. ^The integer return value from the callback is currently 3652 ** ignored, though this may change in future releases. Callback 3653 ** implementations should return zero to ensure future compatibility. 3654 ** 3655 ** ^A trace callback is invoked with four arguments: callback(T,C,P,X). 3656 ** ^The T argument is one of the [SQLITE_TRACE] 3657 ** constants to indicate why the callback was invoked. 3658 ** ^The C argument is a copy of the context pointer. 3659 ** The P and X arguments are pointers whose meanings depend on T. 3660 ** 3661 ** The sqlite3_trace_v2() interface is intended to replace the legacy 3662 ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which 3663 ** are deprecated. 3664 */ 3665 SQLITE_API int sqlite3_trace_v2( 3666 sqlite3*, 3667 unsigned uMask, 3668 int(*xCallback)(unsigned,void*,void*,void*), 3669 void *pCtx 3670 ); 3671 3672 /* 3673 ** CAPI3REF: Query Progress Callbacks 3674 ** METHOD: sqlite3 3675 ** 3676 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback 3677 ** function X to be invoked periodically during long running calls to 3678 ** [sqlite3_step()] and [sqlite3_prepare()] and similar for 3679 ** database connection D. An example use for this 3680 ** interface is to keep a GUI updated during a large query. 3681 ** 3682 ** ^The parameter P is passed through as the only parameter to the 3683 ** callback function X. ^The parameter N is the approximate number of 3684 ** [virtual machine instructions] that are evaluated between successive 3685 ** invocations of the callback X. ^If N is less than one then the progress 3686 ** handler is disabled. 3687 ** 3688 ** ^Only a single progress handler may be defined at one time per 3689 ** [database connection]; setting a new progress handler cancels the 3690 ** old one. ^Setting parameter X to NULL disables the progress handler. 3691 ** ^The progress handler is also disabled by setting N to a value less 3692 ** than 1. 3693 ** 3694 ** ^If the progress callback returns non-zero, the operation is 3695 ** interrupted. This feature can be used to implement a 3696 ** "Cancel" button on a GUI progress dialog box. 3697 ** 3698 ** The progress handler callback must not do anything that will modify 3699 ** the database connection that invoked the progress handler. 3700 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 3701 ** database connections for the meaning of "modify" in this paragraph. 3702 ** 3703 ** The progress handler callback would originally only be invoked from the 3704 ** bytecode engine. It still might be invoked during [sqlite3_prepare()] 3705 ** and similar because those routines might force a reparse of the schema 3706 ** which involves running the bytecode engine. However, beginning with 3707 ** SQLite version 3.41.0, the progress handler callback might also be 3708 ** invoked directly from [sqlite3_prepare()] while analyzing and generating 3709 ** code for complex queries. 3710 */ 3711 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 3712 3713 /* 3714 ** CAPI3REF: Opening A New Database Connection 3715 ** CONSTRUCTOR: sqlite3 3716 ** 3717 ** ^These routines open an SQLite database file as specified by the 3718 ** filename argument. ^The filename argument is interpreted as UTF-8 for 3719 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 3720 ** order for sqlite3_open16(). ^(A [database connection] handle is usually 3721 ** returned in *ppDb, even if an error occurs. The only exception is that 3722 ** if SQLite is unable to allocate memory to hold the [sqlite3] object, 3723 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 3724 ** object.)^ ^(If the database is opened (and/or created) successfully, then 3725 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 3726 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 3727 ** an English language description of the error following a failure of any 3728 ** of the sqlite3_open() routines. 3729 ** 3730 ** ^The default encoding will be UTF-8 for databases created using 3731 ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases 3732 ** created using sqlite3_open16() will be UTF-16 in the native byte order. 3733 ** 3734 ** Whether or not an error occurs when it is opened, resources 3735 ** associated with the [database connection] handle should be released by 3736 ** passing it to [sqlite3_close()] when it is no longer required. 3737 ** 3738 ** The sqlite3_open_v2() interface works like sqlite3_open() 3739 ** except that it accepts two additional parameters for additional control 3740 ** over the new database connection. ^(The flags parameter to 3741 ** sqlite3_open_v2() must include, at a minimum, one of the following 3742 ** three flag combinations:)^ 3743 ** 3744 ** <dl> 3745 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 3746 ** <dd>The database is opened in read-only mode. If the database does 3747 ** not already exist, an error is returned.</dd>)^ 3748 ** 3749 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 3750 ** <dd>The database is opened for reading and writing if possible, or 3751 ** reading only if the file is write protected by the operating 3752 ** system. In either case the database must already exist, otherwise 3753 ** an error is returned. For historical reasons, if opening in 3754 ** read-write mode fails due to OS-level permissions, an attempt is 3755 ** made to open it in read-only mode. [sqlite3_db_readonly()] can be 3756 ** used to determine whether the database is actually 3757 ** read-write.</dd>)^ 3758 ** 3759 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 3760 ** <dd>The database is opened for reading and writing, and is created if 3761 ** it does not already exist. This is the behavior that is always used for 3762 ** sqlite3_open() and sqlite3_open16().</dd>)^ 3763 ** </dl> 3764 ** 3765 ** In addition to the required flags, the following optional flags are 3766 ** also supported: 3767 ** 3768 ** <dl> 3769 ** ^(<dt>[SQLITE_OPEN_URI]</dt> 3770 ** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^ 3771 ** 3772 ** ^(<dt>[SQLITE_OPEN_MEMORY]</dt> 3773 ** <dd>The database will be opened as an in-memory database. The database 3774 ** is named by the "filename" argument for the purposes of cache-sharing, 3775 ** if shared cache mode is enabled, but the "filename" is otherwise ignored. 3776 ** </dd>)^ 3777 ** 3778 ** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt> 3779 ** <dd>The new database connection will use the "multi-thread" 3780 ** [threading mode].)^ This means that separate threads are allowed 3781 ** to use SQLite at the same time, as long as each thread is using 3782 ** a different [database connection]. 3783 ** 3784 ** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt> 3785 ** <dd>The new database connection will use the "serialized" 3786 ** [threading mode].)^ This means the multiple threads can safely 3787 ** attempt to use the same database connection at the same time. 3788 ** (Mutexes will block any actual concurrency, but in this mode 3789 ** there is no harm in trying.) 3790 ** 3791 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt> 3792 ** <dd>The database is opened with [shared cache] enabled, overriding 3793 ** the default shared cache setting provided by 3794 ** [sqlite3_enable_shared_cache()].)^ 3795 ** The [use of shared cache mode is discouraged] and hence shared cache 3796 ** capabilities may be omitted from many builds of SQLite. In such cases, 3797 ** this option is a no-op. 3798 ** 3799 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt> 3800 ** <dd>The database is opened with [shared cache] disabled, overriding 3801 ** the default shared cache setting provided by 3802 ** [sqlite3_enable_shared_cache()].)^ 3803 ** 3804 ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt> 3805 ** <dd>The database connection comes up in "extended result code mode". 3806 ** In other words, the database behaves as if 3807 ** [sqlite3_extended_result_codes(db,1)] were called on the database 3808 ** connection as soon as the connection is created. In addition to setting 3809 ** the extended result code mode, this flag also causes [sqlite3_open_v2()] 3810 ** to return an extended result code.</dd> 3811 ** 3812 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt> 3813 ** <dd>The database filename is not allowed to contain a symbolic link</dd> 3814 ** </dl>)^ 3815 ** 3816 ** If the 3rd parameter to sqlite3_open_v2() is not one of the 3817 ** required combinations shown above optionally combined with other 3818 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] 3819 ** then the behavior is undefined. Historic versions of SQLite 3820 ** have silently ignored surplus bits in the flags parameter to 3821 ** sqlite3_open_v2(), however that behavior might not be carried through 3822 ** into future versions of SQLite and so applications should not rely 3823 ** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op 3824 ** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause 3825 ** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE 3826 ** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not 3827 ** by sqlite3_open_v2(). 3828 ** 3829 ** ^The fourth parameter to sqlite3_open_v2() is the name of the 3830 ** [sqlite3_vfs] object that defines the operating system interface that 3831 ** the new database connection should use. ^If the fourth parameter is 3832 ** a NULL pointer then the default [sqlite3_vfs] object is used. 3833 ** 3834 ** ^If the filename is ":memory:", then a private, temporary in-memory database 3835 ** is created for the connection. ^This in-memory database will vanish when 3836 ** the database connection is closed. Future versions of SQLite might 3837 ** make use of additional special filenames that begin with the ":" character. 3838 ** It is recommended that when a database filename actually does begin with 3839 ** a ":" character you should prefix the filename with a pathname such as 3840 ** "./" to avoid ambiguity. 3841 ** 3842 ** ^If the filename is an empty string, then a private, temporary 3843 ** on-disk database will be created. ^This private database will be 3844 ** automatically deleted as soon as the database connection is closed. 3845 ** 3846 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> 3847 ** 3848 ** ^If [URI filename] interpretation is enabled, and the filename argument 3849 ** begins with "file:", then the filename is interpreted as a URI. ^URI 3850 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is 3851 ** set in the third argument to sqlite3_open_v2(), or if it has 3852 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the 3853 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. 3854 ** URI filename interpretation is turned off 3855 ** by default, but future releases of SQLite might enable URI filename 3856 ** interpretation by default. See "[URI filenames]" for additional 3857 ** information. 3858 ** 3859 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an 3860 ** authority, then it must be either an empty string or the string 3861 ** "localhost". ^If the authority is not an empty string or "localhost", an 3862 ** error is returned to the caller. ^The fragment component of a URI, if 3863 ** present, is ignored. 3864 ** 3865 ** ^SQLite uses the path component of the URI as the name of the disk file 3866 ** which contains the database. ^If the path begins with a '/' character, 3867 ** then it is interpreted as an absolute path. ^If the path does not begin 3868 ** with a '/' (meaning that the authority section is omitted from the URI) 3869 ** then the path is interpreted as a relative path. 3870 ** ^(On windows, the first component of an absolute path 3871 ** is a drive specification (e.g. "C:").)^ 3872 ** 3873 ** [[core URI query parameters]] 3874 ** The query component of a URI may contain parameters that are interpreted 3875 ** either by SQLite itself, or by a [VFS | custom VFS implementation]. 3876 ** SQLite and its built-in [VFSes] interpret the 3877 ** following query parameters: 3878 ** 3879 ** <ul> 3880 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of 3881 ** a VFS object that provides the operating system interface that should 3882 ** be used to access the database file on disk. ^If this option is set to 3883 ** an empty string the default VFS object is used. ^Specifying an unknown 3884 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 3885 ** present, then the VFS specified by the option takes precedence over 3886 ** the value passed as the fourth parameter to sqlite3_open_v2(). 3887 ** 3888 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", 3889 ** "rwc", or "memory". Attempting to set it to any other value is 3890 ** an error)^. 3891 ** ^If "ro" is specified, then the database is opened for read-only 3892 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 3893 ** third argument to sqlite3_open_v2(). ^If the mode option is set to 3894 ** "rw", then the database is opened for read-write (but not create) 3895 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 3896 ** been set. ^Value "rwc" is equivalent to setting both 3897 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is 3898 ** set to "memory" then a pure [in-memory database] that never reads 3899 ** or writes from disk is used. ^It is an error to specify a value for 3900 ** the mode parameter that is less restrictive than that specified by 3901 ** the flags passed in the third parameter to sqlite3_open_v2(). 3902 ** 3903 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 3904 ** "private". ^Setting it to "shared" is equivalent to setting the 3905 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 3906 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 3907 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 3908 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in 3909 ** a URI filename, its value overrides any behavior requested by setting 3910 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. 3911 ** 3912 ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the 3913 ** [powersafe overwrite] property does or does not apply to the 3914 ** storage media on which the database file resides. 3915 ** 3916 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter 3917 ** which if set disables file locking in rollback journal modes. This 3918 ** is useful for accessing a database on a filesystem that does not 3919 ** support locking. Caution: Database corruption might result if two 3920 ** or more processes write to the same database and any one of those 3921 ** processes uses nolock=1. 3922 ** 3923 ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query 3924 ** parameter that indicates that the database file is stored on 3925 ** read-only media. ^When immutable is set, SQLite assumes that the 3926 ** database file cannot be changed, even by a process with higher 3927 ** privilege, and so the database is opened read-only and all locking 3928 ** and change detection is disabled. Caution: Setting the immutable 3929 ** property on a database file that does in fact change can result 3930 ** in incorrect query results and/or [SQLITE_CORRUPT] errors. 3931 ** See also: [SQLITE_IOCAP_IMMUTABLE]. 3932 ** 3933 ** </ul> 3934 ** 3935 ** ^Specifying an unknown parameter in the query component of a URI is not an 3936 ** error. Future versions of SQLite might understand additional query 3937 ** parameters. See "[query parameters with special meaning to SQLite]" for 3938 ** additional information. 3939 ** 3940 ** [[URI filename examples]] <h3>URI filename examples</h3> 3941 ** 3942 ** <table border="1" align=center cellpadding=5> 3943 ** <tr><th> URI filenames <th> Results 3944 ** <tr><td> file:data.db <td> 3945 ** Open the file "data.db" in the current directory. 3946 ** <tr><td> file:/home/fred/data.db<br> 3947 ** file:///home/fred/data.db <br> 3948 ** file://localhost/home/fred/data.db <br> <td> 3949 ** Open the database file "/home/fred/data.db". 3950 ** <tr><td> file://darkstar/home/fred/data.db <td> 3951 ** An error. "darkstar" is not a recognized authority. 3952 ** <tr><td style="white-space:nowrap"> 3953 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db 3954 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive 3955 ** C:. Note that the %20 escaping in this example is not strictly 3956 ** necessary - space characters can be used literally 3957 ** in URI filenames. 3958 ** <tr><td> file:data.db?mode=ro&cache=private <td> 3959 ** Open file "data.db" in the current directory for read-only access. 3960 ** Regardless of whether or not shared-cache mode is enabled by 3961 ** default, use a private cache. 3962 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td> 3963 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile" 3964 ** that uses dot-files in place of posix advisory locking. 3965 ** <tr><td> file:data.db?mode=readonly <td> 3966 ** An error. "readonly" is not a valid option for the "mode" parameter. 3967 ** Use "ro" instead: "file:data.db?mode=ro". 3968 ** </table> 3969 ** 3970 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and 3971 ** query components of a URI. A hexadecimal escape sequence consists of a 3972 ** percent sign - "%" - followed by exactly two hexadecimal digits 3973 ** specifying an octet value. ^Before the path or query components of a 3974 ** URI filename are interpreted, they are encoded using UTF-8 and all 3975 ** hexadecimal escape sequences replaced by a single byte containing the 3976 ** corresponding octet. If this process generates an invalid UTF-8 encoding, 3977 ** the results are undefined. 3978 ** 3979 ** <b>Note to Windows users:</b> The encoding used for the filename argument 3980 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 3981 ** codepage is currently defined. Filenames containing international 3982 ** characters must be converted to UTF-8 prior to passing them into 3983 ** sqlite3_open() or sqlite3_open_v2(). 3984 ** 3985 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set 3986 ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various 3987 ** features that require the use of temporary files may fail. 3988 ** 3989 ** See also: [sqlite3_temp_directory] 3990 */ 3991 SQLITE_API int sqlite3_open( 3992 const char *filename, /* Database filename (UTF-8) */ 3993 sqlite3 **ppDb /* OUT: SQLite db handle */ 3994 ); 3995 SQLITE_API int sqlite3_open16( 3996 const void *filename, /* Database filename (UTF-16) */ 3997 sqlite3 **ppDb /* OUT: SQLite db handle */ 3998 ); 3999 SQLITE_API int sqlite3_open_v2( 4000 const char *filename, /* Database filename (UTF-8) */ 4001 sqlite3 **ppDb, /* OUT: SQLite db handle */ 4002 int flags, /* Flags */ 4003 const char *zVfs /* Name of VFS module to use */ 4004 ); 4005 4006 /* 4007 ** CAPI3REF: Obtain Values For URI Parameters 4008 ** 4009 ** These are utility routines, useful to [VFS|custom VFS implementations], 4010 ** that check if a database file was a URI that contained a specific query 4011 ** parameter, and if so obtains the value of that query parameter. 4012 ** 4013 ** The first parameter to these interfaces (hereafter referred to 4014 ** as F) must be one of: 4015 ** <ul> 4016 ** <li> A database filename pointer created by the SQLite core and 4017 ** passed into the xOpen() method of a VFS implementation, or 4018 ** <li> A filename obtained from [sqlite3_db_filename()], or 4019 ** <li> A new filename constructed using [sqlite3_create_filename()]. 4020 ** </ul> 4021 ** If the F parameter is not one of the above, then the behavior is 4022 ** undefined and probably undesirable. Older versions of SQLite were 4023 ** more tolerant of invalid F parameters than newer versions. 4024 ** 4025 ** If F is a suitable filename (as described in the previous paragraph) 4026 ** and if P is the name of the query parameter, then 4027 ** sqlite3_uri_parameter(F,P) returns the value of the P 4028 ** parameter if it exists or a NULL pointer if P does not appear as a 4029 ** query parameter on F. If P is a query parameter of F and it 4030 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns 4031 ** a pointer to an empty string. 4032 ** 4033 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean 4034 ** parameter and returns true (1) or false (0) according to the value 4035 ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the 4036 ** value of query parameter P is one of "yes", "true", or "on" in any 4037 ** case or if the value begins with a non-zero number. The 4038 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of 4039 ** query parameter P is one of "no", "false", or "off" in any case or 4040 ** if the value begins with a numeric zero. If P is not a query 4041 ** parameter on F or if the value of P does not match any of the 4042 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). 4043 ** 4044 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a 4045 ** 64-bit signed integer and returns that integer, or D if P does not 4046 ** exist. If the value of P is something other than an integer, then 4047 ** zero is returned. 4048 ** 4049 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not 4050 ** the value) of the N-th query parameter for filename F, or a NULL 4051 ** pointer if N is less than zero or greater than the number of query 4052 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain 4053 ** the name of the first query parameter, 1 for the second parameter, and 4054 ** so forth. 4055 ** 4056 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and 4057 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and 4058 ** is not a database file pathname pointer that the SQLite core passed 4059 ** into the xOpen VFS method, then the behavior of this routine is undefined 4060 ** and probably undesirable. 4061 ** 4062 ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F 4063 ** parameter can also be the name of a rollback journal file or WAL file 4064 ** in addition to the main database file. Prior to version 3.31.0, these 4065 ** routines would only work if F was the name of the main database file. 4066 ** When the F parameter is the name of the rollback journal or WAL file, 4067 ** it has access to all the same query parameters as were found on the 4068 ** main database file. 4069 ** 4070 ** See the [URI filename] documentation for additional information. 4071 */ 4072 SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam); 4073 SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault); 4074 SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64); 4075 SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N); 4076 4077 /* 4078 ** CAPI3REF: Translate filenames 4079 ** 4080 ** These routines are available to [VFS|custom VFS implementations] for 4081 ** translating filenames between the main database file, the journal file, 4082 ** and the WAL file. 4083 ** 4084 ** If F is the name of an sqlite database file, journal file, or WAL file 4085 ** passed by the SQLite core into the VFS, then sqlite3_filename_database(F) 4086 ** returns the name of the corresponding database file. 4087 ** 4088 ** If F is the name of an sqlite database file, journal file, or WAL file 4089 ** passed by the SQLite core into the VFS, or if F is a database filename 4090 ** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F) 4091 ** returns the name of the corresponding rollback journal file. 4092 ** 4093 ** If F is the name of an sqlite database file, journal file, or WAL file 4094 ** that was passed by the SQLite core into the VFS, or if F is a database 4095 ** filename obtained from [sqlite3_db_filename()], then 4096 ** sqlite3_filename_wal(F) returns the name of the corresponding 4097 ** WAL file. 4098 ** 4099 ** In all of the above, if F is not the name of a database, journal or WAL 4100 ** filename passed into the VFS from the SQLite core and F is not the 4101 ** return value from [sqlite3_db_filename()], then the result is 4102 ** undefined and is likely a memory access violation. 4103 */ 4104 SQLITE_API const char *sqlite3_filename_database(sqlite3_filename); 4105 SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename); 4106 SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename); 4107 4108 /* 4109 ** CAPI3REF: Database File Corresponding To A Journal 4110 ** 4111 ** ^If X is the name of a rollback or WAL-mode journal file that is 4112 ** passed into the xOpen method of [sqlite3_vfs], then 4113 ** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file] 4114 ** object that represents the main database file. 4115 ** 4116 ** This routine is intended for use in custom [VFS] implementations 4117 ** only. It is not a general-purpose interface. 4118 ** The argument sqlite3_file_object(X) must be a filename pointer that 4119 ** has been passed into [sqlite3_vfs].xOpen method where the 4120 ** flags parameter to xOpen contains one of the bits 4121 ** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use 4122 ** of this routine results in undefined and probably undesirable 4123 ** behavior. 4124 */ 4125 SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); 4126 4127 /* 4128 ** CAPI3REF: Create and Destroy VFS Filenames 4129 ** 4130 ** These interfaces are provided for use by [VFS shim] implementations and 4131 ** are not useful outside of that context. 4132 ** 4133 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of 4134 ** database filename D with corresponding journal file J and WAL file W and 4135 ** an array P of N URI Key/Value pairs. The result from 4136 ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that 4137 ** is safe to pass to routines like: 4138 ** <ul> 4139 ** <li> [sqlite3_uri_parameter()], 4140 ** <li> [sqlite3_uri_boolean()], 4141 ** <li> [sqlite3_uri_int64()], 4142 ** <li> [sqlite3_uri_key()], 4143 ** <li> [sqlite3_filename_database()], 4144 ** <li> [sqlite3_filename_journal()], or 4145 ** <li> [sqlite3_filename_wal()]. 4146 ** </ul> 4147 ** If a memory allocation error occurs, sqlite3_create_filename() might 4148 ** return a NULL pointer. The memory obtained from sqlite3_create_filename(X) 4149 ** must be released by a corresponding call to sqlite3_free_filename(Y). 4150 ** 4151 ** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array 4152 ** of 2*N pointers to strings. Each pair of pointers in this array corresponds 4153 ** to a key and value for a query parameter. The P parameter may be a NULL 4154 ** pointer if N is zero. None of the 2*N pointers in the P array may be 4155 ** NULL pointers and key pointers should not be empty strings. 4156 ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may 4157 ** be NULL pointers, though they can be empty strings. 4158 ** 4159 ** The sqlite3_free_filename(Y) routine releases a memory allocation 4160 ** previously obtained from sqlite3_create_filename(). Invoking 4161 ** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op. 4162 ** 4163 ** If the Y parameter to sqlite3_free_filename(Y) is anything other 4164 ** than a NULL pointer or a pointer previously acquired from 4165 ** sqlite3_create_filename(), then bad things such as heap 4166 ** corruption or segfaults may occur. The value Y should not be 4167 ** used again after sqlite3_free_filename(Y) has been called. This means 4168 ** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y, 4169 ** then the corresponding [sqlite3_module.xClose() method should also be 4170 ** invoked prior to calling sqlite3_free_filename(Y). 4171 */ 4172 SQLITE_API sqlite3_filename sqlite3_create_filename( 4173 const char *zDatabase, 4174 const char *zJournal, 4175 const char *zWal, 4176 int nParam, 4177 const char **azParam 4178 ); 4179 SQLITE_API void sqlite3_free_filename(sqlite3_filename); 4180 4181 /* 4182 ** CAPI3REF: Error Codes And Messages 4183 ** METHOD: sqlite3 4184 ** 4185 ** ^If the most recent sqlite3_* API call associated with 4186 ** [database connection] D failed, then the sqlite3_errcode(D) interface 4187 ** returns the numeric [result code] or [extended result code] for that 4188 ** API call. 4189 ** ^The sqlite3_extended_errcode() 4190 ** interface is the same except that it always returns the 4191 ** [extended result code] even when extended result codes are 4192 ** disabled. 4193 ** 4194 ** The values returned by sqlite3_errcode() and/or 4195 ** sqlite3_extended_errcode() might change with each API call. 4196 ** Except, there are some interfaces that are guaranteed to never 4197 ** change the value of the error code. The error-code preserving 4198 ** interfaces include the following: 4199 ** 4200 ** <ul> 4201 ** <li> sqlite3_errcode() 4202 ** <li> sqlite3_extended_errcode() 4203 ** <li> sqlite3_errmsg() 4204 ** <li> sqlite3_errmsg16() 4205 ** <li> sqlite3_error_offset() 4206 ** <li> sqlite3_db_handle() 4207 ** </ul> 4208 ** 4209 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 4210 ** text that describes the error, as either UTF-8 or UTF-16 respectively, 4211 ** or NULL if no error message is available. 4212 ** (See how SQLite handles [invalid UTF] for exceptions to this rule.) 4213 ** ^(Memory to hold the error message string is managed internally. 4214 ** The application does not need to worry about freeing the result. 4215 ** However, the error string might be overwritten or deallocated by 4216 ** subsequent calls to other SQLite interface functions.)^ 4217 ** 4218 ** ^The sqlite3_errstr(E) interface returns the English-language text 4219 ** that describes the [result code] E, as UTF-8, or NULL if E is not a 4220 ** result code for which a text error message is available. 4221 ** ^(Memory to hold the error message string is managed internally 4222 ** and must not be freed by the application)^. 4223 ** 4224 ** ^If the most recent error references a specific token in the input 4225 ** SQL, the sqlite3_error_offset() interface returns the byte offset 4226 ** of the start of that token. ^The byte offset returned by 4227 ** sqlite3_error_offset() assumes that the input SQL is UTF-8. 4228 ** ^If the most recent error does not reference a specific token in the input 4229 ** SQL, then the sqlite3_error_offset() function returns -1. 4230 ** 4231 ** When the serialized [threading mode] is in use, it might be the 4232 ** case that a second error occurs on a separate thread in between 4233 ** the time of the first error and the call to these interfaces. 4234 ** When that happens, the second error will be reported since these 4235 ** interfaces always report the most recent result. To avoid 4236 ** this, each thread can obtain exclusive use of the [database connection] D 4237 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 4238 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 4239 ** all calls to the interfaces listed here are completed. 4240 ** 4241 ** If an interface fails with SQLITE_MISUSE, that means the interface 4242 ** was invoked incorrectly by the application. In that case, the 4243 ** error code and message may or may not be set. 4244 */ 4245 SQLITE_API int sqlite3_errcode(sqlite3 *db); 4246 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); 4247 SQLITE_API const char *sqlite3_errmsg(sqlite3*); 4248 SQLITE_API const void *sqlite3_errmsg16(sqlite3*); 4249 SQLITE_API const char *sqlite3_errstr(int); 4250 SQLITE_API int sqlite3_error_offset(sqlite3 *db); 4251 4252 /* 4253 ** CAPI3REF: Set Error Code And Message 4254 ** METHOD: sqlite3 4255 ** 4256 ** Set the error code of the database handle passed as the first argument 4257 ** to errcode, and the error message to a copy of nul-terminated string 4258 ** zErrMsg. If zErrMsg is passed NULL, then the error message is set to 4259 ** the default message associated with the supplied error code. Subsequent 4260 ** calls to [sqlite3_errcode()] and [sqlite3_errmsg()] and similar will 4261 ** return the values set by this routine in place of what was previously 4262 ** set by SQLite itself. 4263 ** 4264 ** This function returns SQLITE_OK if the error code and error message are 4265 ** successfully set, SQLITE_NOMEM if an OOM occurs, and SQLITE_MISUSE if 4266 ** the database handle is NULL or invalid. 4267 ** 4268 ** The error code and message set by this routine remains in effect until 4269 ** they are changed, either by another call to this routine or until they are 4270 ** changed to by SQLite itself to reflect the result of some subsquent 4271 ** API call. 4272 ** 4273 ** This function is intended for use by SQLite extensions or wrappers. The 4274 ** idea is that an extension or wrapper can use this routine to set error 4275 ** messages and error codes and thus behave more like a core SQLite 4276 ** feature from the point of view of an application. 4277 */ 4278 SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg); 4279 4280 /* 4281 ** CAPI3REF: Prepared Statement Object 4282 ** KEYWORDS: {prepared statement} {prepared statements} 4283 ** 4284 ** An instance of this object represents a single SQL statement that 4285 ** has been compiled into binary form and is ready to be evaluated. 4286 ** 4287 ** Think of each SQL statement as a separate computer program. The 4288 ** original SQL text is source code. A prepared statement object 4289 ** is the compiled object code. All SQL must be converted into a 4290 ** prepared statement before it can be run. 4291 ** 4292 ** The life-cycle of a prepared statement object usually goes like this: 4293 ** 4294 ** <ol> 4295 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()]. 4296 ** <li> Bind values to [parameters] using the sqlite3_bind_*() 4297 ** interfaces. 4298 ** <li> Run the SQL by calling [sqlite3_step()] one or more times. 4299 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back 4300 ** to step 2. Do this zero or more times. 4301 ** <li> Destroy the object using [sqlite3_finalize()]. 4302 ** </ol> 4303 */ 4304 typedef struct sqlite3_stmt sqlite3_stmt; 4305 4306 /* 4307 ** CAPI3REF: Run-time Limits 4308 ** METHOD: sqlite3 4309 ** 4310 ** ^(This interface allows the size of various constructs to be limited 4311 ** on a connection by connection basis. The first parameter is the 4312 ** [database connection] whose limit is to be set or queried. The 4313 ** second parameter is one of the [limit categories] that define a 4314 ** class of constructs to be size limited. The third parameter is the 4315 ** new limit for that construct.)^ 4316 ** 4317 ** ^If the new limit is a negative number, the limit is unchanged. 4318 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a 4319 ** [limits | hard upper bound] 4320 ** set at compile-time by a C preprocessor macro called 4321 ** [limits | SQLITE_MAX_<i>NAME</i>]. 4322 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ 4323 ** ^Attempts to increase a limit above its hard upper bound are 4324 ** silently truncated to the hard upper bound. 4325 ** 4326 ** ^Regardless of whether or not the limit was changed, the 4327 ** [sqlite3_limit()] interface returns the prior value of the limit. 4328 ** ^Hence, to find the current value of a limit without changing it, 4329 ** simply invoke this interface with the third parameter set to -1. 4330 ** 4331 ** Run-time limits are intended for use in applications that manage 4332 ** both their own internal database and also databases that are controlled 4333 ** by untrusted external sources. An example application might be a 4334 ** web browser that has its own databases for storing history and 4335 ** separate databases controlled by JavaScript applications downloaded 4336 ** off the Internet. The internal databases can be given the 4337 ** large, default limits. Databases managed by external sources can 4338 ** be given much smaller limits designed to prevent a denial of service 4339 ** attack. Developers might also want to use the [sqlite3_set_authorizer()] 4340 ** interface to further control untrusted SQL. The size of the database 4341 ** created by an untrusted script can be contained using the 4342 ** [max_page_count] [PRAGMA]. 4343 ** 4344 ** New run-time limit categories may be added in future releases. 4345 */ 4346 SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); 4347 4348 /* 4349 ** CAPI3REF: Run-Time Limit Categories 4350 ** KEYWORDS: {limit category} {*limit categories} 4351 ** 4352 ** These constants define various performance limits 4353 ** that can be lowered at run-time using [sqlite3_limit()]. 4354 ** A concise description of these limits follows, and additional information 4355 ** is available at [limits | Limits in SQLite]. 4356 ** 4357 ** <dl> 4358 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> 4359 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ 4360 ** 4361 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 4362 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 4363 ** 4364 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> 4365 ** <dd>The maximum number of columns in a table definition or in the 4366 ** result set of a [SELECT] or the maximum number of columns in an index 4367 ** or in an ORDER BY or GROUP BY clause.</dd>)^ 4368 ** 4369 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 4370 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 4371 ** 4372 ** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt> 4373 ** <dd>The maximum depth of the LALR(1) parser stack used to analyze 4374 ** input SQL statements.</dd>)^ 4375 ** 4376 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 4377 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 4378 ** 4379 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 4380 ** <dd>The maximum number of instructions in a virtual machine program 4381 ** used to implement an SQL statement. If [sqlite3_prepare_v2()] or 4382 ** the equivalent tries to allocate space for more than this many opcodes 4383 ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^ 4384 ** 4385 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 4386 ** <dd>The maximum number of arguments on a function.</dd>)^ 4387 ** 4388 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 4389 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 4390 ** 4391 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] 4392 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 4393 ** <dd>The maximum length of the pattern argument to the [LIKE] or 4394 ** [GLOB] operators.</dd>)^ 4395 ** 4396 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] 4397 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 4398 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ 4399 ** 4400 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 4401 ** <dd>The maximum depth of recursion for triggers.</dd>)^ 4402 ** 4403 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt> 4404 ** <dd>The maximum number of auxiliary worker threads that a single 4405 ** [prepared statement] may start.</dd>)^ 4406 ** </dl> 4407 */ 4408 #define SQLITE_LIMIT_LENGTH 0 4409 #define SQLITE_LIMIT_SQL_LENGTH 1 4410 #define SQLITE_LIMIT_COLUMN 2 4411 #define SQLITE_LIMIT_EXPR_DEPTH 3 4412 #define SQLITE_LIMIT_COMPOUND_SELECT 4 4413 #define SQLITE_LIMIT_VDBE_OP 5 4414 #define SQLITE_LIMIT_FUNCTION_ARG 6 4415 #define SQLITE_LIMIT_ATTACHED 7 4416 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 4417 #define SQLITE_LIMIT_VARIABLE_NUMBER 9 4418 #define SQLITE_LIMIT_TRIGGER_DEPTH 10 4419 #define SQLITE_LIMIT_WORKER_THREADS 11 4420 #define SQLITE_LIMIT_PARSER_DEPTH 12 4421 4422 /* 4423 ** CAPI3REF: Prepare Flags 4424 ** 4425 ** These constants define various flags that can be passed into the 4426 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and 4427 ** [sqlite3_prepare16_v3()] interfaces. 4428 ** 4429 ** New flags may be added in future releases of SQLite. 4430 ** 4431 ** <dl> 4432 ** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt> 4433 ** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner 4434 ** that the prepared statement will be retained for a long time and 4435 ** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()] 4436 ** and [sqlite3_prepare16_v3()] assume that the prepared statement will 4437 ** be used just once or at most a few times and then destroyed using 4438 ** [sqlite3_finalize()] relatively soon. The current implementation acts 4439 ** on this hint by avoiding the use of [lookaside memory] so as not to 4440 ** deplete the limited store of lookaside memory. Future versions of 4441 ** SQLite may act on this hint differently. 4442 ** 4443 ** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt> 4444 ** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used 4445 ** to be required for any prepared statement that wanted to use the 4446 ** [sqlite3_normalized_sql()] interface. However, the 4447 ** [sqlite3_normalized_sql()] interface is now available to all 4448 ** prepared statements, regardless of whether or not they use this 4449 ** flag. 4450 ** 4451 ** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt> 4452 ** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler 4453 ** to return an error (error code SQLITE_ERROR) if the statement uses 4454 ** any virtual tables. 4455 ** 4456 ** [[SQLITE_PREPARE_DONT_LOG]] <dt>SQLITE_PREPARE_DONT_LOG</dt> 4457 ** <dd>The SQLITE_PREPARE_DONT_LOG flag prevents SQL compiler 4458 ** errors from being sent to the error log defined by 4459 ** [SQLITE_CONFIG_LOG]. This can be used, for example, to do test 4460 ** compiles to see if some SQL syntax is well-formed, without generating 4461 ** messages on the global error log when it is not. If the test compile 4462 ** fails, the sqlite3_prepare_v3() call returns the same error indications 4463 ** with or without this flag; it just omits the call to [sqlite3_log()] that 4464 ** logs the error. 4465 ** 4466 ** [[SQLITE_PREPARE_FROM_DDL]] <dt>SQLITE_PREPARE_FROM_DDL</dt> 4467 ** <dd>The SQLITE_PREPARE_FROM_DDL flag causes the SQL compiler to enforce 4468 ** security constraints that would otherwise only be enforced when parsing 4469 ** the database schema. In other words, the SQLITE_PREPARE_FROM_DDL flag 4470 ** causes the SQL compiler to treat the SQL statement being prepared as if 4471 ** it had come from an attacker. When SQLITE_PREPARE_FROM_DDL is used and 4472 ** [SQLITE_DBCONFIG_TRUSTED_SCHEMA] is off, SQL functions may only be called 4473 ** if they are tagged with [SQLITE_INNOCUOUS] and virtual tables may only 4474 ** be used if they are tagged with [SQLITE_VTAB_INNOCUOUS]. Best practice 4475 ** is to use the SQLITE_PREPARE_FROM_DDL option when preparing any SQL that 4476 ** is derived from parts of the database schema. In particular, virtual 4477 ** table implementations that run SQL statements that are derived from 4478 ** arguments to their CREATE VIRTUAL TABLE statement should always use 4479 ** [sqlite3_prepare_v3()] and set the SQLITE_PREPARE_FROM_DDL flag to 4480 ** prevent bypass of the [SQLITE_DBCONFIG_TRUSTED_SCHEMA] security checks. 4481 ** </dl> 4482 */ 4483 #define SQLITE_PREPARE_PERSISTENT 0x01 4484 #define SQLITE_PREPARE_NORMALIZE 0x02 4485 #define SQLITE_PREPARE_NO_VTAB 0x04 4486 #define SQLITE_PREPARE_DONT_LOG 0x10 4487 #define SQLITE_PREPARE_FROM_DDL 0x20 4488 4489 /* 4490 ** CAPI3REF: Compiling An SQL Statement 4491 ** KEYWORDS: {SQL statement compiler} 4492 ** METHOD: sqlite3 4493 ** CONSTRUCTOR: sqlite3_stmt 4494 ** 4495 ** To execute an SQL statement, it must first be compiled into a byte-code 4496 ** program using one of these routines. Or, in other words, these routines 4497 ** are constructors for the [prepared statement] object. 4498 ** 4499 ** The preferred routine to use is [sqlite3_prepare_v2()]. The 4500 ** [sqlite3_prepare()] interface is legacy and should be avoided. 4501 ** [sqlite3_prepare_v3()] has an extra 4502 ** [SQLITE_PREPARE_FROM_DDL|"prepFlags" option] that is sometimes 4503 ** needed for special purpose or to pass along security restrictions. 4504 ** 4505 ** The use of the UTF-8 interfaces is preferred, as SQLite currently 4506 ** does all parsing using UTF-8. The UTF-16 interfaces are provided 4507 ** as a convenience. The UTF-16 interfaces work by converting the 4508 ** input text into UTF-8, then invoking the corresponding UTF-8 interface. 4509 ** 4510 ** The first argument, "db", is a [database connection] obtained from a 4511 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 4512 ** [sqlite3_open16()]. The database connection must not have been closed. 4513 ** 4514 ** The second argument, "zSql", is the statement to be compiled, encoded 4515 ** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(), 4516 ** and sqlite3_prepare_v3() 4517 ** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(), 4518 ** and sqlite3_prepare16_v3() use UTF-16. 4519 ** 4520 ** ^If the nByte argument is negative, then zSql is read up to the 4521 ** first zero terminator. ^If nByte is positive, then it is the maximum 4522 ** number of bytes read from zSql. When nByte is positive, zSql is read 4523 ** up to the first zero terminator or until the nByte bytes have been read, 4524 ** whichever comes first. ^If nByte is zero, then no prepared 4525 ** statement is generated. 4526 ** If the caller knows that the supplied string is nul-terminated, then 4527 ** there is a small performance advantage to passing an nByte parameter that 4528 ** is the number of bytes in the input string <i>including</i> 4529 ** the nul-terminator. 4530 ** Note that nByte measures the length of the input in bytes, not 4531 ** characters, even for the UTF-16 interfaces. 4532 ** 4533 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte 4534 ** past the end of the first SQL statement in zSql. These routines only 4535 ** compile the first statement in zSql, so *pzTail is left pointing to 4536 ** what remains uncompiled. 4537 ** 4538 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 4539 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 4540 ** to NULL. ^If the input text contains no SQL (if the input is an empty 4541 ** string or a comment) then *ppStmt is set to NULL. 4542 ** The calling procedure is responsible for deleting the compiled 4543 ** SQL statement using [sqlite3_finalize()] after it has finished with it. 4544 ** ppStmt may not be NULL. 4545 ** 4546 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 4547 ** otherwise an [error code] is returned. 4548 ** 4549 ** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(), 4550 ** and sqlite3_prepare16_v3() interfaces are recommended for all new programs. 4551 ** The older interfaces (sqlite3_prepare() and sqlite3_prepare16()) 4552 ** are retained for backwards compatibility, but their use is discouraged. 4553 ** ^In the "vX" interfaces, the prepared statement 4554 ** that is returned (the [sqlite3_stmt] object) contains a copy of the 4555 ** original SQL text. This causes the [sqlite3_step()] interface to 4556 ** behave differently in three ways: 4557 ** 4558 ** <ol> 4559 ** <li> 4560 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 4561 ** always used to do, [sqlite3_step()] will automatically recompile the SQL 4562 ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY] 4563 ** retries will occur before sqlite3_step() gives up and returns an error. 4564 ** </li> 4565 ** 4566 ** <li> 4567 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed 4568 ** [error codes] or [extended error codes]. ^The legacy behavior was that 4569 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 4570 ** and the application would have to make a second call to [sqlite3_reset()] 4571 ** in order to find the underlying cause of the problem. With the "v2" prepare 4572 ** interfaces, the underlying reason for the error is returned immediately. 4573 ** </li> 4574 ** 4575 ** <li> 4576 ** ^If the specific value bound to a [parameter | host parameter] in the 4577 ** WHERE clause might influence the choice of query plan for a statement, 4578 ** then the statement will be automatically recompiled, as if there had been 4579 ** a schema change, on the first [sqlite3_step()] call following any change 4580 ** to the [sqlite3_bind_text | bindings] of that [parameter]. 4581 ** ^The specific value of a WHERE-clause [parameter] might influence the 4582 ** choice of query plan if the parameter is the left-hand side of a [LIKE] 4583 ** or [GLOB] operator or if the parameter is compared to an indexed column 4584 ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled. 4585 ** </li> 4586 ** </ol> 4587 ** 4588 ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having 4589 ** the extra prepFlags parameter, which is a bit array consisting of zero or 4590 ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The 4591 ** sqlite3_prepare_v2() interface works exactly the same as 4592 ** sqlite3_prepare_v3() with a zero prepFlags parameter. 4593 */ 4594 SQLITE_API int sqlite3_prepare( 4595 sqlite3 *db, /* Database handle */ 4596 const char *zSql, /* SQL statement, UTF-8 encoded */ 4597 int nByte, /* Maximum length of zSql in bytes. */ 4598 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 4599 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 4600 ); 4601 SQLITE_API int sqlite3_prepare_v2( 4602 sqlite3 *db, /* Database handle */ 4603 const char *zSql, /* SQL statement, UTF-8 encoded */ 4604 int nByte, /* Maximum length of zSql in bytes. */ 4605 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 4606 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 4607 ); 4608 SQLITE_API int sqlite3_prepare_v3( 4609 sqlite3 *db, /* Database handle */ 4610 const char *zSql, /* SQL statement, UTF-8 encoded */ 4611 int nByte, /* Maximum length of zSql in bytes. */ 4612 unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ 4613 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 4614 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 4615 ); 4616 SQLITE_API int sqlite3_prepare16( 4617 sqlite3 *db, /* Database handle */ 4618 const void *zSql, /* SQL statement, UTF-16 encoded */ 4619 int nByte, /* Maximum length of zSql in bytes. */ 4620 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 4621 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 4622 ); 4623 SQLITE_API int sqlite3_prepare16_v2( 4624 sqlite3 *db, /* Database handle */ 4625 const void *zSql, /* SQL statement, UTF-16 encoded */ 4626 int nByte, /* Maximum length of zSql in bytes. */ 4627 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 4628 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 4629 ); 4630 SQLITE_API int sqlite3_prepare16_v3( 4631 sqlite3 *db, /* Database handle */ 4632 const void *zSql, /* SQL statement, UTF-16 encoded */ 4633 int nByte, /* Maximum length of zSql in bytes. */ 4634 unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */ 4635 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 4636 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 4637 ); 4638 4639 /* 4640 ** CAPI3REF: Retrieving Statement SQL 4641 ** METHOD: sqlite3_stmt 4642 ** 4643 ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8 4644 ** SQL text used to create [prepared statement] P if P was 4645 ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], 4646 ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. 4647 ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8 4648 ** string containing the SQL text of prepared statement P with 4649 ** [bound parameters] expanded. 4650 ** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8 4651 ** string containing the normalized SQL text of prepared statement P. The 4652 ** semantics used to normalize a SQL statement are unspecified and subject 4653 ** to change. At a minimum, literal values will be replaced with suitable 4654 ** placeholders. 4655 ** 4656 ** ^(For example, if a prepared statement is created using the SQL 4657 ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345 4658 ** and parameter :xyz is unbound, then sqlite3_sql() will return 4659 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql() 4660 ** will return "SELECT 2345,NULL".)^ 4661 ** 4662 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory 4663 ** is available to hold the result, or if the result would exceed the 4664 ** maximum string length determined by the [SQLITE_LIMIT_LENGTH]. 4665 ** 4666 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of 4667 ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time 4668 ** option causes sqlite3_expanded_sql() to always return NULL. 4669 ** 4670 ** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P) 4671 ** are managed by SQLite and are automatically freed when the prepared 4672 ** statement is finalized. 4673 ** ^The string returned by sqlite3_expanded_sql(P), on the other hand, 4674 ** is obtained from [sqlite3_malloc()] and must be freed by the application 4675 ** by passing it to [sqlite3_free()]. 4676 ** 4677 ** ^The sqlite3_normalized_sql() interface is only available if 4678 ** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined. 4679 */ 4680 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); 4681 SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); 4682 #ifdef SQLITE_ENABLE_NORMALIZE 4683 SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt); 4684 #endif 4685 4686 /* 4687 ** CAPI3REF: Determine If An SQL Statement Writes The Database 4688 ** METHOD: sqlite3_stmt 4689 ** 4690 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 4691 ** and only if the [prepared statement] X makes no direct changes to 4692 ** the content of the database file. 4693 ** 4694 ** Note that [application-defined SQL functions] or 4695 ** [virtual tables] might change the database indirectly as a side effect. 4696 ** ^(For example, if an application defines a function "eval()" that 4697 ** calls [sqlite3_exec()], then the following SQL statement would 4698 ** change the database file through side-effects: 4699 ** 4700 ** <blockquote><pre> 4701 ** SELECT eval('DELETE FROM t1') FROM t2; 4702 ** </pre></blockquote> 4703 ** 4704 ** But because the [SELECT] statement does not change the database file 4705 ** directly, sqlite3_stmt_readonly() would still return true.)^ 4706 ** 4707 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], 4708 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, 4709 ** since the statements themselves do not actually modify the database but 4710 ** rather they control the timing of when other statements modify the 4711 ** database. ^The [ATTACH] and [DETACH] statements also cause 4712 ** sqlite3_stmt_readonly() to return true since, while those statements 4713 ** change the configuration of a database connection, they do not make 4714 ** changes to the content of the database files on disk. 4715 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since 4716 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and 4717 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so 4718 ** sqlite3_stmt_readonly() returns false for those commands. 4719 ** 4720 ** ^This routine returns false if there is any possibility that the 4721 ** statement might change the database file. ^A false return does 4722 ** not guarantee that the statement will change the database file. 4723 ** ^For example, an UPDATE statement might have a WHERE clause that 4724 ** makes it a no-op, but the sqlite3_stmt_readonly() result would still 4725 ** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a 4726 ** read-only no-op if the table already exists, but 4727 ** sqlite3_stmt_readonly() still returns false for such a statement. 4728 ** 4729 ** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN] 4730 ** statement, then sqlite3_stmt_readonly(X) returns the same value as 4731 ** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted. 4732 */ 4733 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 4734 4735 /* 4736 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement 4737 ** METHOD: sqlite3_stmt 4738 ** 4739 ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the 4740 ** prepared statement S is an EXPLAIN statement, or 2 if the 4741 ** statement S is an EXPLAIN QUERY PLAN. 4742 ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is 4743 ** an ordinary statement or a NULL pointer. 4744 */ 4745 SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt); 4746 4747 /* 4748 ** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement 4749 ** METHOD: sqlite3_stmt 4750 ** 4751 ** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN 4752 ** setting for [prepared statement] S. If E is zero, then S becomes 4753 ** a normal prepared statement. If E is 1, then S behaves as if 4754 ** its SQL text began with "[EXPLAIN]". If E is 2, then S behaves as if 4755 ** its SQL text began with "[EXPLAIN QUERY PLAN]". 4756 ** 4757 ** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared. 4758 ** SQLite tries to avoid a reprepare, but a reprepare might be necessary 4759 ** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode. 4760 ** 4761 ** Because of the potential need to reprepare, a call to 4762 ** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be 4763 ** reprepared because it was created using [sqlite3_prepare()] instead of 4764 ** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and 4765 ** hence has no saved SQL text with which to reprepare. 4766 ** 4767 ** Changing the explain setting for a prepared statement does not change 4768 ** the original SQL text for the statement. Hence, if the SQL text originally 4769 ** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0) 4770 ** is called to convert the statement into an ordinary statement, the EXPLAIN 4771 ** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S) 4772 ** output, even though the statement now acts like a normal SQL statement. 4773 ** 4774 ** This routine returns SQLITE_OK if the explain mode is successfully 4775 ** changed, or an error code if the explain mode could not be changed. 4776 ** The explain mode cannot be changed while a statement is active. 4777 ** Hence, it is good practice to call [sqlite3_reset(S)] 4778 ** immediately prior to calling sqlite3_stmt_explain(S,E). 4779 */ 4780 SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode); 4781 4782 /* 4783 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset 4784 ** METHOD: sqlite3_stmt 4785 ** 4786 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the 4787 ** [prepared statement] S has been stepped at least once using 4788 ** [sqlite3_step(S)] but has neither run to completion (returned 4789 ** [SQLITE_DONE] from [sqlite3_step(S)]) nor 4790 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) 4791 ** interface returns false if S is a NULL pointer. If S is not a 4792 ** NULL pointer and is not a pointer to a valid [prepared statement] 4793 ** object, then the behavior is undefined and probably undesirable. 4794 ** 4795 ** This interface can be used in combination [sqlite3_next_stmt()] 4796 ** to locate all prepared statements associated with a database 4797 ** connection that are in need of being reset. This can be used, 4798 ** for example, in diagnostic routines to search for prepared 4799 ** statements that are holding a transaction open. 4800 */ 4801 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); 4802 4803 /* 4804 ** CAPI3REF: Dynamically Typed Value Object 4805 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 4806 ** 4807 ** SQLite uses the sqlite3_value object to represent all values 4808 ** that can be stored in a database table. SQLite uses dynamic typing 4809 ** for the values it stores. ^Values stored in sqlite3_value objects 4810 ** can be integers, floating point values, strings, BLOBs, or NULL. 4811 ** 4812 ** An sqlite3_value object may be either "protected" or "unprotected". 4813 ** Some interfaces require a protected sqlite3_value. Other interfaces 4814 ** will accept either a protected or an unprotected sqlite3_value. 4815 ** Every interface that accepts sqlite3_value arguments specifies 4816 ** whether or not it requires a protected sqlite3_value. The 4817 ** [sqlite3_value_dup()] interface can be used to construct a new 4818 ** protected sqlite3_value from an unprotected sqlite3_value. 4819 ** 4820 ** The terms "protected" and "unprotected" refer to whether or not 4821 ** a mutex is held. An internal mutex is held for a protected 4822 ** sqlite3_value object but no mutex is held for an unprotected 4823 ** sqlite3_value object. If SQLite is compiled to be single-threaded 4824 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) 4825 ** or if SQLite is run in one of reduced mutex modes 4826 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] 4827 ** then there is no distinction between protected and unprotected 4828 ** sqlite3_value objects and they can be used interchangeably. However, 4829 ** for maximum code portability it is recommended that applications 4830 ** still make the distinction between protected and unprotected 4831 ** sqlite3_value objects even when not strictly required. 4832 ** 4833 ** ^The sqlite3_value objects that are passed as parameters into the 4834 ** implementation of [application-defined SQL functions] are protected. 4835 ** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()] 4836 ** are protected. 4837 ** ^The sqlite3_value object returned by 4838 ** [sqlite3_column_value()] is unprotected. 4839 ** Unprotected sqlite3_value objects may only be used as arguments 4840 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and 4841 ** [sqlite3_value_dup()]. 4842 ** The [sqlite3_value_blob | sqlite3_value_type()] family of 4843 ** interfaces require protected sqlite3_value objects. 4844 */ 4845 typedef struct sqlite3_value sqlite3_value; 4846 4847 /* 4848 ** CAPI3REF: SQL Function Context Object 4849 ** 4850 ** The context in which an SQL function executes is stored in an 4851 ** sqlite3_context object. ^A pointer to an sqlite3_context object 4852 ** is always the first parameter to [application-defined SQL functions]. 4853 ** The application-defined SQL function implementation will pass this 4854 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], 4855 ** [sqlite3_aggregate_context()], [sqlite3_user_data()], 4856 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], 4857 ** and/or [sqlite3_set_auxdata()]. 4858 */ 4859 typedef struct sqlite3_context sqlite3_context; 4860 4861 /* 4862 ** CAPI3REF: Binding Values To Prepared Statements 4863 ** KEYWORDS: {host parameter} {host parameters} {host parameter name} 4864 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} 4865 ** METHOD: sqlite3_stmt 4866 ** 4867 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, 4868 ** literals may be replaced by a [parameter] that matches one of the following 4869 ** templates: 4870 ** 4871 ** <ul> 4872 ** <li> ? 4873 ** <li> ?NNN 4874 ** <li> :VVV 4875 ** <li> @VVV 4876 ** <li> $VVV 4877 ** </ul> 4878 ** 4879 ** In the templates above, NNN represents an integer literal, 4880 ** and VVV represents an alphanumeric identifier.)^ ^The values of these 4881 ** parameters (also called "host parameter names" or "SQL parameters") 4882 ** can be set using the sqlite3_bind_*() routines defined here. 4883 ** 4884 ** ^The first argument to the sqlite3_bind_*() routines is always 4885 ** a pointer to the [sqlite3_stmt] object returned from 4886 ** [sqlite3_prepare_v2()] or its variants. 4887 ** 4888 ** ^The second argument is the index of the SQL parameter to be set. 4889 ** ^The leftmost SQL parameter has an index of 1. ^When the same named 4890 ** SQL parameter is used more than once, second and subsequent 4891 ** occurrences have the same index as the first occurrence. 4892 ** ^The index for named parameters can be looked up using the 4893 ** [sqlite3_bind_parameter_index()] API if desired. ^The index 4894 ** for "?NNN" parameters is the value of NNN. 4895 ** ^The NNN value must be between 1 and the [sqlite3_limit()] 4896 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766). 4897 ** 4898 ** ^The third argument is the value to bind to the parameter. 4899 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() 4900 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter 4901 ** is ignored and the end result is the same as sqlite3_bind_null(). 4902 ** ^If the third parameter to sqlite3_bind_text() is not NULL, then 4903 ** it should be a pointer to well-formed UTF8 text. 4904 ** ^If the third parameter to sqlite3_bind_text16() is not NULL, then 4905 ** it should be a pointer to well-formed UTF16 text. 4906 ** ^If the third parameter to sqlite3_bind_text64() is not NULL, then 4907 ** it should be a pointer to a well-formed unicode string that is 4908 ** either UTF8 if the sixth parameter is SQLITE_UTF8 or SQLITE_UTF8_ZT, 4909 ** or UTF16 otherwise. 4910 ** 4911 ** [[byte-order determination rules]] ^The byte-order of 4912 ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF) 4913 ** found in the first character, which is removed, or in the absence of a BOM 4914 ** the byte order is the native byte order of the host 4915 ** machine for sqlite3_bind_text16() or the byte order specified in 4916 ** the 6th parameter for sqlite3_bind_text64().)^ 4917 ** ^If UTF16 input text contains invalid unicode 4918 ** characters, then SQLite might change those invalid characters 4919 ** into the unicode replacement character: U+FFFD. 4920 ** 4921 ** ^(In those routines that have a fourth argument, its value is the 4922 ** number of bytes in the parameter. To be clear: the value is the 4923 ** number of <u>bytes</u> in the value, not the number of characters.)^ 4924 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() 4925 ** is negative, then the length of the string is 4926 ** the number of bytes up to the first zero terminator. 4927 ** If the fourth parameter to sqlite3_bind_blob() is negative, then 4928 ** the behavior is undefined. 4929 ** If a non-negative fourth parameter is provided to sqlite3_bind_text() 4930 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then 4931 ** that parameter must be the byte offset 4932 ** where the NUL terminator would occur assuming the string were NUL 4933 ** terminated. If any NUL characters occur at byte offsets less than 4934 ** the value of the fourth parameter then the resulting string value will 4935 ** contain embedded NULs. The result of expressions involving strings 4936 ** with embedded NULs is undefined. 4937 ** 4938 ** ^The fifth argument to the BLOB and string binding interfaces controls 4939 ** or indicates the lifetime of the object referenced by the third parameter. 4940 ** These three options exist: 4941 ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished 4942 ** with it may be passed. ^It is called to dispose of the BLOB or string even 4943 ** if the call to the bind API fails, except the destructor is not called if 4944 ** the third parameter is a NULL pointer or the fourth parameter is negative. 4945 ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that 4946 ** the application remains responsible for disposing of the object. ^In this 4947 ** case, the object and the provided pointer to it must remain valid until 4948 ** either the prepared statement is finalized or the same SQL parameter is 4949 ** bound to something else, whichever occurs sooner. 4950 ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the 4951 ** object is to be copied prior to the return from sqlite3_bind_*(). ^The 4952 ** object and pointer to it must remain valid until then. ^SQLite will then 4953 ** manage the lifetime of its private copy. 4954 ** 4955 ** ^The sixth argument (the E argument) 4956 ** to sqlite3_bind_text64(S,K,Z,N,D,E) must be one of 4957 ** [SQLITE_UTF8], [SQLITE_UTF8_ZT], [SQLITE_UTF16], [SQLITE_UTF16BE], 4958 ** or [SQLITE_UTF16LE] to specify the encoding of the text in the 4959 ** third parameter, Z. The special value [SQLITE_UTF8_ZT] means that the 4960 ** string argument is both UTF-8 encoded and is zero-terminated. In other 4961 ** words, SQLITE_UTF8_ZT means that the Z array is allocated to hold at 4962 ** least N+1 bytes and that the Z[N] byte is zero. If 4963 ** the E argument to sqlite3_bind_text64(S,K,Z,N,D,E) is not one of the 4964 ** allowed values shown above, or if the text encoding is different 4965 ** from the encoding specified by the sixth parameter, then the behavior 4966 ** is undefined. 4967 ** 4968 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 4969 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 4970 ** (just an integer to hold its size) while it is being processed. 4971 ** Zeroblobs are intended to serve as placeholders for BLOBs whose 4972 ** content is later written using 4973 ** [sqlite3_blob_open | incremental BLOB I/O] routines. 4974 ** ^A negative value for the zeroblob results in a zero-length BLOB. 4975 ** 4976 ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in 4977 ** [prepared statement] S to have an SQL value of NULL, but to also be 4978 ** associated with the pointer P of type T. ^D is either a NULL pointer or 4979 ** a pointer to a destructor function for P. ^SQLite will invoke the 4980 ** destructor D with a single argument of P when it is finished using 4981 ** P, even if the call to sqlite3_bind_pointer() fails. Due to a 4982 ** historical design quirk, results are undefined if D is 4983 ** SQLITE_TRANSIENT. The T parameter should be a static string, 4984 ** preferably a string literal. The sqlite3_bind_pointer() routine is 4985 ** part of the [pointer passing interface] added for SQLite 3.20.0. 4986 ** 4987 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 4988 ** for the [prepared statement] or with a prepared statement for which 4989 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 4990 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 4991 ** routine is passed a [prepared statement] that has been finalized, the 4992 ** result is undefined and probably harmful. 4993 ** 4994 ** ^Bindings are not cleared by the [sqlite3_reset()] routine. 4995 ** ^Unbound parameters are interpreted as NULL. 4996 ** 4997 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 4998 ** [error code] if anything goes wrong. 4999 ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB 5000 ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or 5001 ** [SQLITE_MAX_LENGTH]. 5002 ** ^[SQLITE_RANGE] is returned if the parameter 5003 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 5004 ** 5005 ** See also: [sqlite3_bind_parameter_count()], 5006 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 5007 */ 5008 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 5009 SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64, 5010 void(*)(void*)); 5011 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); 5012 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); 5013 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 5014 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); 5015 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); 5016 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); 5017 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64, 5018 void(*)(void*), unsigned char encoding); 5019 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 5020 SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*)); 5021 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 5022 SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64); 5023 5024 /* 5025 ** CAPI3REF: Number Of SQL Parameters 5026 ** METHOD: sqlite3_stmt 5027 ** 5028 ** ^This routine can be used to find the number of [SQL parameters] 5029 ** in a [prepared statement]. SQL parameters are tokens of the 5030 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 5031 ** placeholders for values that are [sqlite3_bind_blob | bound] 5032 ** to the parameters at a later time. 5033 ** 5034 ** ^(This routine actually returns the index of the largest (rightmost) 5035 ** parameter. For all forms except ?NNN, this will correspond to the 5036 ** number of unique parameters. If parameters of the ?NNN form are used, 5037 ** there may be gaps in the list.)^ 5038 ** 5039 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 5040 ** [sqlite3_bind_parameter_name()], and 5041 ** [sqlite3_bind_parameter_index()]. 5042 */ 5043 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); 5044 5045 /* 5046 ** CAPI3REF: Name Of A Host Parameter 5047 ** METHOD: sqlite3_stmt 5048 ** 5049 ** ^The sqlite3_bind_parameter_name(P,N) interface returns 5050 ** the name of the N-th [SQL parameter] in the [prepared statement] P. 5051 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" 5052 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" 5053 ** respectively. 5054 ** In other words, the initial ":" or "$" or "@" or "?" 5055 ** is included as part of the name.)^ 5056 ** ^Parameters of the form "?" without a following integer have no name 5057 ** and are referred to as "nameless" or "anonymous parameters". 5058 ** 5059 ** ^The first host parameter has an index of 1, not 0. 5060 ** 5061 ** ^If the value N is out of range or if the N-th parameter is 5062 ** nameless, then NULL is returned. ^The returned string is 5063 ** always in UTF-8 encoding even if the named parameter was 5064 ** originally specified as UTF-16 in [sqlite3_prepare16()], 5065 ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. 5066 ** 5067 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 5068 ** [sqlite3_bind_parameter_count()], and 5069 ** [sqlite3_bind_parameter_index()]. 5070 */ 5071 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); 5072 5073 /* 5074 ** CAPI3REF: Index Of A Parameter With A Given Name 5075 ** METHOD: sqlite3_stmt 5076 ** 5077 ** ^Return the index of an SQL parameter given its name. ^The 5078 ** index value returned is suitable for use as the second 5079 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero 5080 ** is returned if no matching parameter is found. ^The parameter 5081 ** name must be given in UTF-8 even if the original statement 5082 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or 5083 ** [sqlite3_prepare16_v3()]. 5084 ** 5085 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 5086 ** [sqlite3_bind_parameter_count()], and 5087 ** [sqlite3_bind_parameter_name()]. 5088 */ 5089 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); 5090 5091 /* 5092 ** CAPI3REF: Reset All Bindings On A Prepared Statement 5093 ** METHOD: sqlite3_stmt 5094 ** 5095 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset 5096 ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. 5097 ** ^Use this routine to reset all host parameters to NULL. 5098 */ 5099 SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); 5100 5101 /* 5102 ** CAPI3REF: Number Of Columns In A Result Set 5103 ** METHOD: sqlite3_stmt 5104 ** 5105 ** ^Return the number of columns in the result set returned by the 5106 ** [prepared statement]. ^If this routine returns 0, that means the 5107 ** [prepared statement] returns no data (for example an [UPDATE]). 5108 ** ^However, just because this routine returns a positive number does not 5109 ** mean that one or more rows of data will be returned. ^A SELECT statement 5110 ** will always have a positive sqlite3_column_count() but depending on the 5111 ** WHERE clause constraints and the table content, it might return no rows. 5112 ** 5113 ** See also: [sqlite3_data_count()] 5114 */ 5115 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); 5116 5117 /* 5118 ** CAPI3REF: Column Names In A Result Set 5119 ** METHOD: sqlite3_stmt 5120 ** 5121 ** ^These routines return the name assigned to a particular column 5122 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() 5123 ** interface returns a pointer to a zero-terminated UTF-8 string 5124 ** and sqlite3_column_name16() returns a pointer to a zero-terminated 5125 ** UTF-16 string. ^The first parameter is the [prepared statement] 5126 ** that implements the [SELECT] statement. ^The second parameter is the 5127 ** column number. ^The leftmost column is number 0. 5128 ** 5129 ** ^The returned string pointer is valid until either the [prepared statement] 5130 ** is destroyed by [sqlite3_finalize()] or until the statement is automatically 5131 ** reprepared by the first call to [sqlite3_step()] for a particular run 5132 ** or until the next call to 5133 ** sqlite3_column_name() or sqlite3_column_name16() on the same column. 5134 ** 5135 ** ^If sqlite3_malloc() fails during the processing of either routine 5136 ** (for example during a conversion from UTF-8 to UTF-16) then a 5137 ** NULL pointer is returned. 5138 ** 5139 ** ^The name of a result column is the value of the "AS" clause for 5140 ** that column, if there is an AS clause. If there is no AS clause 5141 ** then the name of the column is unspecified and may change from 5142 ** one release of SQLite to the next. 5143 */ 5144 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); 5145 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); 5146 5147 /* 5148 ** CAPI3REF: Source Of Data In A Query Result 5149 ** METHOD: sqlite3_stmt 5150 ** 5151 ** ^These routines provide a means to determine the database, table, and 5152 ** table column that is the origin of a particular result column in a 5153 ** [SELECT] statement. 5154 ** ^The name of the database or table or column can be returned as 5155 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return 5156 ** the database name, the _table_ routines return the table name, and 5157 ** the origin_ routines return the column name. 5158 ** ^The returned string is valid until the [prepared statement] is destroyed 5159 ** using [sqlite3_finalize()] or until the statement is automatically 5160 ** reprepared by the first call to [sqlite3_step()] for a particular run 5161 ** or until the same information is requested 5162 ** again in a different encoding. 5163 ** 5164 ** ^The names returned are the original un-aliased names of the 5165 ** database, table, and column. 5166 ** 5167 ** ^The first argument to these interfaces is a [prepared statement]. 5168 ** ^These functions return information about the Nth result column returned by 5169 ** the statement, where N is the second function argument. 5170 ** ^The left-most column is column 0 for these routines. 5171 ** 5172 ** ^If the Nth column returned by the statement is an expression or 5173 ** subquery and is not a column value, then all of these functions return 5174 ** NULL. ^These routines might also return NULL if a memory allocation error 5175 ** occurs. ^Otherwise, they return the name of the attached database, table, 5176 ** or column that query result column was extracted from. 5177 ** 5178 ** ^As with all other SQLite APIs, those whose names end with "16" return 5179 ** UTF-16 encoded strings and the other functions return UTF-8. 5180 ** 5181 ** ^These APIs are only available if the library was compiled with the 5182 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. 5183 ** 5184 ** If two or more threads call one or more 5185 ** [sqlite3_column_database_name | column metadata interfaces] 5186 ** for the same [prepared statement] and result column 5187 ** at the same time then the results are undefined. 5188 */ 5189 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); 5190 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); 5191 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); 5192 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); 5193 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); 5194 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); 5195 5196 /* 5197 ** CAPI3REF: Declared Datatype Of A Query Result 5198 ** METHOD: sqlite3_stmt 5199 ** 5200 ** ^(The first parameter is a [prepared statement]. 5201 ** If this statement is a [SELECT] statement and the Nth column of the 5202 ** returned result set of that [SELECT] is a table column (not an 5203 ** expression or subquery) then the declared type of the table 5204 ** column is returned.)^ ^If the Nth column of the result set is an 5205 ** expression or subquery, then a NULL pointer is returned. 5206 ** ^The returned string is always UTF-8 encoded. 5207 ** 5208 ** ^(For example, given the database schema: 5209 ** 5210 ** CREATE TABLE t1(c1 VARIANT); 5211 ** 5212 ** and the following statement to be compiled: 5213 ** 5214 ** SELECT c1 + 1, c1 FROM t1; 5215 ** 5216 ** this routine would return the string "VARIANT" for the second result 5217 ** column (i==1), and a NULL pointer for the first result column (i==0).)^ 5218 ** 5219 ** ^SQLite uses dynamic run-time typing. ^So just because a column 5220 ** is declared to contain a particular type does not mean that the 5221 ** data stored in that column is of the declared type. SQLite is 5222 ** strongly typed, but the typing is dynamic not static. ^Type 5223 ** is associated with individual values, not with the containers 5224 ** used to hold those values. 5225 */ 5226 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); 5227 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); 5228 5229 /* 5230 ** CAPI3REF: Evaluate An SQL Statement 5231 ** METHOD: sqlite3_stmt 5232 ** 5233 ** After a [prepared statement] has been prepared using any of 5234 ** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()], 5235 ** or [sqlite3_prepare16_v3()] or one of the legacy 5236 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function 5237 ** must be called one or more times to evaluate the statement. 5238 ** 5239 ** The details of the behavior of the sqlite3_step() interface depend 5240 ** on whether the statement was prepared using the newer "vX" interfaces 5241 ** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()], 5242 ** [sqlite3_prepare16_v2()] or the older legacy 5243 ** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the 5244 ** new "vX" interface is recommended for new applications but the legacy 5245 ** interface will continue to be supported. 5246 ** 5247 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 5248 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 5249 ** ^With the "v2" interface, any of the other [result codes] or 5250 ** [extended result codes] might be returned as well. 5251 ** 5252 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 5253 ** database locks it needs to do its job. ^If the statement is a [COMMIT] 5254 ** or occurs outside of an explicit transaction, then you can retry the 5255 ** statement. If the statement is not a [COMMIT] and occurs within an 5256 ** explicit transaction then you should rollback the transaction before 5257 ** continuing. 5258 ** 5259 ** ^[SQLITE_DONE] means that the statement has finished executing 5260 ** successfully. sqlite3_step() should not be called again on this virtual 5261 ** machine without first calling [sqlite3_reset()] to reset the virtual 5262 ** machine back to its initial state. 5263 ** 5264 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 5265 ** is returned each time a new row of data is ready for processing by the 5266 ** caller. The values may be accessed using the [column access functions]. 5267 ** sqlite3_step() is called again to retrieve the next row of data. 5268 ** 5269 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint 5270 ** violation) has occurred. sqlite3_step() should not be called again on 5271 ** the VM. More information may be found by calling [sqlite3_errmsg()]. 5272 ** ^With the legacy interface, a more specific error code (for example, 5273 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) 5274 ** can be obtained by calling [sqlite3_reset()] on the 5275 ** [prepared statement]. ^In the "v2" interface, 5276 ** the more specific error code is returned directly by sqlite3_step(). 5277 ** 5278 ** [SQLITE_MISUSE] means that the this routine was called inappropriately. 5279 ** Perhaps it was called on a [prepared statement] that has 5280 ** already been [sqlite3_finalize | finalized] or on one that had 5281 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could 5282 ** be the case that the same database connection is being used by two or 5283 ** more threads at the same moment in time. 5284 ** 5285 ** For all versions of SQLite up to and including 3.6.23.1, a call to 5286 ** [sqlite3_reset()] was required after sqlite3_step() returned anything 5287 ** other than [SQLITE_ROW] before any subsequent invocation of 5288 ** sqlite3_step(). Failure to reset the prepared statement using 5289 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from 5290 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]), 5291 ** sqlite3_step() began 5292 ** calling [sqlite3_reset()] automatically in this circumstance rather 5293 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility 5294 ** break because any application that ever receives an SQLITE_MISUSE error 5295 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option 5296 ** can be used to restore the legacy behavior. 5297 ** 5298 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() 5299 ** API always returns a generic error code, [SQLITE_ERROR], following any 5300 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call 5301 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the 5302 ** specific [error codes] that better describes the error. 5303 ** We admit that this is a goofy design. The problem has been fixed 5304 ** with the "v2" interface. If you prepare all of your SQL statements 5305 ** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()] 5306 ** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead 5307 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, 5308 ** then the more specific [error codes] are returned directly 5309 ** by sqlite3_step(). The use of the "vX" interfaces is recommended. 5310 */ 5311 SQLITE_API int sqlite3_step(sqlite3_stmt*); 5312 5313 /* 5314 ** CAPI3REF: Number of columns in a result set 5315 ** METHOD: sqlite3_stmt 5316 ** 5317 ** ^The sqlite3_data_count(P) interface returns the number of columns in the 5318 ** current row of the result set of [prepared statement] P. 5319 ** ^If prepared statement P does not have results ready to return 5320 ** (via calls to the [sqlite3_column_int | sqlite3_column()] family of 5321 ** interfaces) then sqlite3_data_count(P) returns 0. 5322 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. 5323 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to 5324 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P) 5325 ** will return non-zero if previous call to [sqlite3_step](P) returned 5326 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum] 5327 ** where it always returns zero since each step of that multi-step 5328 ** pragma returns 0 columns of data. 5329 ** 5330 ** See also: [sqlite3_column_count()] 5331 */ 5332 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); 5333 5334 /* 5335 ** CAPI3REF: Fundamental Datatypes 5336 ** KEYWORDS: SQLITE_TEXT 5337 ** 5338 ** ^(Every value in SQLite has one of five fundamental datatypes: 5339 ** 5340 ** <ul> 5341 ** <li> 64-bit signed integer 5342 ** <li> 64-bit IEEE floating point number 5343 ** <li> string 5344 ** <li> BLOB 5345 ** <li> NULL 5346 ** </ul>)^ 5347 ** 5348 ** These constants are codes for each of those types. 5349 ** 5350 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 5351 ** for a completely different meaning. Software that links against both 5352 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not 5353 ** SQLITE_TEXT. 5354 */ 5355 #define SQLITE_INTEGER 1 5356 #define SQLITE_FLOAT 2 5357 #define SQLITE_BLOB 4 5358 #define SQLITE_NULL 5 5359 #ifdef SQLITE_TEXT 5360 # undef SQLITE_TEXT 5361 #else 5362 # define SQLITE_TEXT 3 5363 #endif 5364 #define SQLITE3_TEXT 3 5365 5366 /* 5367 ** CAPI3REF: Result Values From A Query 5368 ** KEYWORDS: {column access functions} 5369 ** METHOD: sqlite3_stmt 5370 ** 5371 ** <b>Summary:</b> 5372 ** <blockquote><table border=0 cellpadding=0 cellspacing=0> 5373 ** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result 5374 ** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result 5375 ** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result 5376 ** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result 5377 ** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result 5378 ** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result 5379 ** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an 5380 ** [sqlite3_value|unprotected sqlite3_value] object. 5381 ** <tr><td> <td> <td> 5382 ** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB 5383 ** or a UTF-8 TEXT result in bytes 5384 ** <tr><td><b>sqlite3_column_bytes16 </b> 5385 ** <td>→ <td>Size of UTF-16 5386 ** TEXT in bytes 5387 ** <tr><td><b>sqlite3_column_type</b><td>→<td>Default 5388 ** datatype of the result 5389 ** </table></blockquote> 5390 ** 5391 ** <b>Details:</b> 5392 ** 5393 ** ^These routines return information about a single column of the current 5394 ** result row of a query. ^In every case the first argument is a pointer 5395 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] 5396 ** that was returned from [sqlite3_prepare_v2()] or one of its variants) 5397 ** and the second argument is the index of the column for which information 5398 ** should be returned. ^The leftmost column of the result set has the index 0. 5399 ** ^The number of columns in the result can be determined using 5400 ** [sqlite3_column_count()]. 5401 ** 5402 ** If the SQL statement does not currently point to a valid row, or if the 5403 ** column index is out of range, the result is undefined. 5404 ** These routines may only be called when the most recent call to 5405 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither 5406 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. 5407 ** If any of these routines are called after [sqlite3_reset()] or 5408 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned 5409 ** something other than [SQLITE_ROW], the results are undefined. 5410 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] 5411 ** are called from a different thread while any of these routines 5412 ** are pending, then the results are undefined. 5413 ** 5414 ** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16) 5415 ** each return the value of a result column in a specific data format. If 5416 ** the result column is not initially in the requested format (for example, 5417 ** if the query returns an integer but the sqlite3_column_text() interface 5418 ** is used to extract the value) then an automatic type conversion is performed. 5419 ** 5420 ** ^The sqlite3_column_type() routine returns the 5421 ** [SQLITE_INTEGER | datatype code] for the initial data type 5422 ** of the result column. ^The returned value is one of [SQLITE_INTEGER], 5423 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. 5424 ** The return value of sqlite3_column_type() can be used to decide which 5425 ** of the first six interface should be used to extract the column value. 5426 ** The value returned by sqlite3_column_type() is only meaningful if no 5427 ** automatic type conversions have occurred for the value in question. 5428 ** After a type conversion, the result of calling sqlite3_column_type() 5429 ** is undefined, though harmless. Future 5430 ** versions of SQLite may change the behavior of sqlite3_column_type() 5431 ** following a type conversion. 5432 ** 5433 ** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes() 5434 ** or sqlite3_column_bytes16() interfaces can be used to determine the size 5435 ** of that BLOB or string. 5436 ** 5437 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 5438 ** routine returns the number of bytes in that BLOB or string. 5439 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts 5440 ** the string to UTF-8 and then returns the number of bytes. 5441 ** ^If the result is a numeric value then sqlite3_column_bytes() uses 5442 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns 5443 ** the number of bytes in that string. 5444 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero. 5445 ** 5446 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() 5447 ** routine returns the number of bytes in that BLOB or string. 5448 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts 5449 ** the string to UTF-16 and then returns the number of bytes. 5450 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses 5451 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns 5452 ** the number of bytes in that string. 5453 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. 5454 ** 5455 ** ^The values returned by [sqlite3_column_bytes()] and 5456 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end 5457 ** of the string. ^For clarity: the values returned by 5458 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 5459 ** bytes in the string, not the number of characters. 5460 ** 5461 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 5462 ** even empty strings, are always zero-terminated. ^The return 5463 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 5464 ** 5465 ** ^Strings returned by sqlite3_column_text16() always have the endianness 5466 ** which is native to the platform, regardless of the text encoding set 5467 ** for the database. 5468 ** 5469 ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an 5470 ** [unprotected sqlite3_value] object. In a multithreaded environment, 5471 ** an unprotected sqlite3_value object may only be used safely with 5472 ** [sqlite3_bind_value()] and [sqlite3_result_value()]. 5473 ** If the [unprotected sqlite3_value] object returned by 5474 ** [sqlite3_column_value()] is used in any other way, including calls 5475 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 5476 ** or [sqlite3_value_bytes()], the behavior is not threadsafe. 5477 ** Hence, the sqlite3_column_value() interface 5478 ** is normally only useful within the implementation of 5479 ** [application-defined SQL functions] or [virtual tables], not within 5480 ** top-level application code. 5481 ** 5482 ** These routines may attempt to convert the datatype of the result. 5483 ** ^For example, if the internal representation is FLOAT and a text result 5484 ** is requested, [sqlite3_snprintf()] is used internally to perform the 5485 ** conversion automatically. ^(The following table details the conversions 5486 ** that are applied: 5487 ** 5488 ** <blockquote> 5489 ** <table border="1"> 5490 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 5491 ** 5492 ** <tr><td> NULL <td> INTEGER <td> Result is 0 5493 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 5494 ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer 5495 ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer 5496 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 5497 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 5498 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 5499 ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER 5500 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 5501 ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB 5502 ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER 5503 ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL 5504 ** <tr><td> TEXT <td> BLOB <td> No change 5505 ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER 5506 ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL 5507 ** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator 5508 ** </table> 5509 ** </blockquote>)^ 5510 ** 5511 ** Note that when type conversions occur, pointers returned by prior 5512 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or 5513 ** sqlite3_column_text16() may be invalidated. 5514 ** Type conversions and pointer invalidations might occur 5515 ** in the following cases: 5516 ** 5517 ** <ul> 5518 ** <li> The initial content is a BLOB and sqlite3_column_text() or 5519 ** sqlite3_column_text16() is called. A zero-terminator might 5520 ** need to be added to the string.</li> 5521 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or 5522 ** sqlite3_column_text16() is called. The content must be converted 5523 ** to UTF-16.</li> 5524 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or 5525 ** sqlite3_column_text() is called. The content must be converted 5526 ** to UTF-8.</li> 5527 ** </ul> 5528 ** 5529 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do 5530 ** not invalidate a prior pointer, though of course the content of the buffer 5531 ** that the prior pointer references will have been modified. Other kinds 5532 ** of conversion are done in place when it is possible, but sometimes they 5533 ** are not possible and in those cases prior pointers are invalidated. 5534 ** 5535 ** The safest policy is to invoke these routines 5536 ** in one of the following ways: 5537 ** 5538 ** <ul> 5539 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> 5540 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> 5541 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> 5542 ** </ul> 5543 ** 5544 ** In other words, you should call sqlite3_column_text(), 5545 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result 5546 ** into the desired format, then invoke sqlite3_column_bytes() or 5547 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 5548 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to 5549 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 5550 ** with calls to sqlite3_column_bytes(). 5551 ** 5552 ** ^The pointers returned are valid until a type conversion occurs as 5553 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 5554 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings 5555 ** and BLOBs is freed automatically. Do not pass the pointers returned 5556 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 5557 ** [sqlite3_free()]. 5558 ** 5559 ** As long as the input parameters are correct, these routines will only 5560 ** fail if an out-of-memory error occurs during a format conversion. 5561 ** Only the following subset of interfaces are subject to out-of-memory 5562 ** errors: 5563 ** 5564 ** <ul> 5565 ** <li> sqlite3_column_blob() 5566 ** <li> sqlite3_column_text() 5567 ** <li> sqlite3_column_text16() 5568 ** <li> sqlite3_column_bytes() 5569 ** <li> sqlite3_column_bytes16() 5570 ** </ul> 5571 ** 5572 ** If an out-of-memory error occurs, then the return value from these 5573 ** routines is the same as if the column had contained an SQL NULL value. 5574 ** Valid SQL NULL returns can be distinguished from out-of-memory errors 5575 ** by invoking the [sqlite3_errcode()] immediately after the suspect 5576 ** return value is obtained and before any 5577 ** other SQLite interface is called on the same [database connection]. 5578 */ 5579 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 5580 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); 5581 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); 5582 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 5583 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 5584 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 5585 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 5586 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 5587 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 5588 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); 5589 5590 /* 5591 ** CAPI3REF: Destroy A Prepared Statement Object 5592 ** DESTRUCTOR: sqlite3_stmt 5593 ** 5594 ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 5595 ** ^If the most recent evaluation of the statement encountered no errors 5596 ** or if the statement has never been evaluated, then sqlite3_finalize() returns 5597 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then 5598 ** sqlite3_finalize(S) returns the appropriate [error code] or 5599 ** [extended error code]. 5600 ** 5601 ** ^The sqlite3_finalize(S) routine can be called at any point during 5602 ** the life cycle of [prepared statement] S: 5603 ** before statement S is ever evaluated, after 5604 ** one or more calls to [sqlite3_reset()], or after any call 5605 ** to [sqlite3_step()] regardless of whether or not the statement has 5606 ** completed execution. 5607 ** 5608 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. 5609 ** 5610 ** The application must finalize every [prepared statement] in order to avoid 5611 ** resource leaks. It is a grievous error for the application to try to use 5612 ** a prepared statement after it has been finalized. Any use of a prepared 5613 ** statement after it has been finalized can result in undefined and 5614 ** undesirable behavior such as segfaults and heap corruption. 5615 */ 5616 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); 5617 5618 /* 5619 ** CAPI3REF: Reset A Prepared Statement Object 5620 ** METHOD: sqlite3_stmt 5621 ** 5622 ** The sqlite3_reset() function is called to reset a [prepared statement] 5623 ** object back to its initial state, ready to be re-executed. 5624 ** ^Any SQL statement variables that had values bound to them using 5625 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. 5626 ** Use [sqlite3_clear_bindings()] to reset the bindings. 5627 ** 5628 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S 5629 ** back to the beginning of its program. 5630 ** 5631 ** ^The return code from [sqlite3_reset(S)] indicates whether or not 5632 ** the previous evaluation of prepared statement S completed successfully. 5633 ** ^If [sqlite3_step(S)] has never before been called on S or if 5634 ** [sqlite3_step(S)] has not been called since the previous call 5635 ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return 5636 ** [SQLITE_OK]. 5637 ** 5638 ** ^If the most recent call to [sqlite3_step(S)] for the 5639 ** [prepared statement] S indicated an error, then 5640 ** [sqlite3_reset(S)] returns an appropriate [error code]. 5641 ** ^The [sqlite3_reset(S)] interface might also return an [error code] 5642 ** if there were no prior errors but the process of resetting 5643 ** the prepared statement caused a new error. ^For example, if an 5644 ** [INSERT] statement with a [RETURNING] clause is only stepped one time, 5645 ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but 5646 ** the overall statement might still fail and the [sqlite3_reset(S)] call 5647 ** might return SQLITE_BUSY if locking constraints prevent the 5648 ** database change from committing. Therefore, it is important that 5649 ** applications check the return code from [sqlite3_reset(S)] even if 5650 ** no prior call to [sqlite3_step(S)] indicated a problem. 5651 ** 5652 ** ^The [sqlite3_reset(S)] interface does not change the values 5653 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. 5654 */ 5655 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); 5656 5657 5658 /* 5659 ** CAPI3REF: Create Or Redefine SQL Functions 5660 ** KEYWORDS: {function creation routines} 5661 ** METHOD: sqlite3 5662 ** 5663 ** ^These functions (collectively known as "function creation routines") 5664 ** are used to add SQL functions or aggregates or to redefine the behavior 5665 ** of existing SQL functions or aggregates. The only differences between 5666 ** the three "sqlite3_create_function*" routines are the text encoding 5667 ** expected for the second parameter (the name of the function being 5668 ** created) and the presence or absence of a destructor callback for 5669 ** the application data pointer. Function sqlite3_create_window_function() 5670 ** is similar, but allows the user to supply the extra callback functions 5671 ** needed by [aggregate window functions]. 5672 ** 5673 ** ^The first parameter is the [database connection] to which the SQL 5674 ** function is to be added. ^If an application uses more than one database 5675 ** connection then application-defined SQL functions must be added 5676 ** to each database connection separately. 5677 ** 5678 ** ^The second parameter is the name of the SQL function to be created or 5679 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 5680 ** representation, exclusive of the zero-terminator. ^Note that the name 5681 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. 5682 ** ^Any attempt to create a function with a longer name 5683 ** will result in [SQLITE_MISUSE] being returned. 5684 ** 5685 ** ^The third parameter (nArg) 5686 ** is the number of arguments that the SQL function or 5687 ** aggregate takes. ^If this parameter is -1, then the SQL function or 5688 ** aggregate may take any number of arguments between 0 and the limit 5689 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 5690 ** parameter is less than -1 or greater than 127 then the behavior is 5691 ** undefined. 5692 ** 5693 ** ^The fourth parameter, eTextRep, specifies what 5694 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for 5695 ** its parameters. The application should set this parameter to 5696 ** [SQLITE_UTF16LE] if the function implementation invokes 5697 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the 5698 ** implementation invokes [sqlite3_value_text16be()] on an input, or 5699 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] 5700 ** otherwise. ^The same SQL function may be registered multiple times using 5701 ** different preferred text encodings, with different implementations for 5702 ** each encoding. 5703 ** ^When multiple implementations of the same function are available, SQLite 5704 ** will pick the one that involves the least amount of data conversion. 5705 ** 5706 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] 5707 ** to signal that the function will always return the same result given 5708 ** the same inputs within a single SQL statement. Most SQL functions are 5709 ** deterministic. The built-in [random()] SQL function is an example of a 5710 ** function that is not deterministic. The SQLite query planner is able to 5711 ** perform additional optimizations on deterministic functions, so use 5712 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. 5713 ** 5714 ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY] 5715 ** flag, which if present prevents the function from being invoked from 5716 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions, 5717 ** index expressions, or the WHERE clause of partial indexes. 5718 ** 5719 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for 5720 ** all application-defined SQL functions that do not need to be 5721 ** used inside of triggers, views, CHECK constraints, or other elements of 5722 ** the database schema. This flag is especially recommended for SQL 5723 ** functions that have side effects or reveal internal application state. 5724 ** Without this flag, an attacker might be able to modify the schema of 5725 ** a database file to include invocations of the function with parameters 5726 ** chosen by the attacker, which the application will then execute when 5727 ** the database file is opened and read. 5728 ** 5729 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the 5730 ** function can gain access to this pointer using [sqlite3_user_data()].)^ 5731 ** 5732 ** ^The sixth, seventh and eighth parameters passed to the three 5733 ** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are 5734 ** pointers to C-language functions that implement the SQL function or 5735 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc 5736 ** callback only; NULL pointers must be passed as the xStep and xFinal 5737 ** parameters. ^An aggregate SQL function requires an implementation of xStep 5738 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing 5739 ** SQL function or aggregate, pass NULL pointers for all three function 5740 ** callbacks. 5741 ** 5742 ** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue 5743 ** and xInverse) passed to sqlite3_create_window_function are pointers to 5744 ** C-language callbacks that implement the new function. xStep and xFinal 5745 ** must both be non-NULL. xValue and xInverse may either both be NULL, in 5746 ** which case a regular aggregate function is created, or must both be 5747 ** non-NULL, in which case the new function may be used as either an aggregate 5748 ** or aggregate window function. More details regarding the implementation 5749 ** of aggregate window functions are 5750 ** [user-defined window functions|available here]. 5751 ** 5752 ** ^(If the final parameter to sqlite3_create_function_v2() or 5753 ** sqlite3_create_window_function() is not NULL, then it is the destructor for 5754 ** the application data pointer. The destructor is invoked when the function 5755 ** is deleted, either by being overloaded or when the database connection 5756 ** closes.)^ ^The destructor is also invoked if the call to 5757 ** sqlite3_create_function_v2() fails. ^When the destructor callback is 5758 ** invoked, it is passed a single argument which is a copy of the application 5759 ** data pointer which was the fifth parameter to sqlite3_create_function_v2(). 5760 ** 5761 ** ^It is permitted to register multiple implementations of the same 5762 ** functions with the same name but with either differing numbers of 5763 ** arguments or differing preferred text encodings. ^SQLite will use 5764 ** the implementation that most closely matches the way in which the 5765 ** SQL function is used. ^A function implementation with a non-negative 5766 ** nArg parameter is a better match than a function implementation with 5767 ** a negative nArg. ^A function where the preferred text encoding 5768 ** matches the database encoding is a better 5769 ** match than a function where the encoding is different. 5770 ** ^A function where the encoding difference is between UTF16le and UTF16be 5771 ** is a closer match than a function where the encoding difference is 5772 ** between UTF8 and UTF16. 5773 ** 5774 ** ^Built-in functions may be overloaded by new application-defined functions. 5775 ** 5776 ** ^An application-defined function is permitted to call other 5777 ** SQLite interfaces. However, such calls must not 5778 ** close the database connection nor finalize or reset the prepared 5779 ** statement in which the function is running. 5780 */ 5781 SQLITE_API int sqlite3_create_function( 5782 sqlite3 *db, 5783 const char *zFunctionName, 5784 int nArg, 5785 int eTextRep, 5786 void *pApp, 5787 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 5788 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 5789 void (*xFinal)(sqlite3_context*) 5790 ); 5791 SQLITE_API int sqlite3_create_function16( 5792 sqlite3 *db, 5793 const void *zFunctionName, 5794 int nArg, 5795 int eTextRep, 5796 void *pApp, 5797 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 5798 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 5799 void (*xFinal)(sqlite3_context*) 5800 ); 5801 SQLITE_API int sqlite3_create_function_v2( 5802 sqlite3 *db, 5803 const char *zFunctionName, 5804 int nArg, 5805 int eTextRep, 5806 void *pApp, 5807 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 5808 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 5809 void (*xFinal)(sqlite3_context*), 5810 void(*xDestroy)(void*) 5811 ); 5812 SQLITE_API int sqlite3_create_window_function( 5813 sqlite3 *db, 5814 const char *zFunctionName, 5815 int nArg, 5816 int eTextRep, 5817 void *pApp, 5818 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 5819 void (*xFinal)(sqlite3_context*), 5820 void (*xValue)(sqlite3_context*), 5821 void (*xInverse)(sqlite3_context*,int,sqlite3_value**), 5822 void(*xDestroy)(void*) 5823 ); 5824 5825 /* 5826 ** CAPI3REF: Text Encodings 5827 ** 5828 ** These constants define integer codes that represent the various 5829 ** text encodings supported by SQLite. 5830 ** 5831 ** <dl> 5832 ** [[SQLITE_UTF8]] <dt>SQLITE_UTF8</dt><dd>Text is encoding as UTF-8</dd> 5833 ** 5834 ** [[SQLITE_UTF16LE]] <dt>SQLITE_UTF16LE</dt><dd>Text is encoding as UTF-16 5835 ** with each code point being expressed "little endian" - the least significant 5836 ** byte first. This is the usual encoding, for example on Windows.</dd> 5837 ** 5838 ** [[SQLITE_UTF16BE]] <dt>SQLITE_UTF16BE</dt><dd>Text is encoding as UTF-16 5839 ** with each code point being expressed "big endian" - the most significant 5840 ** byte first. This encoding is less common, but is still sometimes seen, 5841 ** specially on older systems. 5842 ** 5843 ** [[SQLITE_UTF16]] <dt>SQLITE_UTF16</dt><dd>Text is encoding as UTF-16 5844 ** with each code point being expressed either little endian or as big 5845 ** endian, according to the native endianness of the host computer. 5846 ** 5847 ** [[SQLITE_ANY]] <dt>SQLITE_ANY</dt><dd>This encoding value may only be used 5848 ** to declare the preferred text for [application-defined SQL functions] 5849 ** created using [sqlite3_create_function()] and similar. If the preferred 5850 ** encoding (the 4th parameter to sqlite3_create_function() - the eTextRep 5851 ** parameter) is SQLITE_ANY, that indicates that the function does not have 5852 ** a preference regarding the text encoding of its parameters and can take 5853 ** any text encoding that the SQLite core find convenient to supply. This 5854 ** option is deprecated. Please do not use it in new applications. 5855 ** 5856 ** [[SQLITE_UTF16_ALIGNED]] <dt>SQLITE_UTF16_ALIGNED</dt><dd>This encoding 5857 ** value may be used as the 3rd parameter (the eTextRep parameter) to 5858 ** [sqlite3_create_collation()] and similar. This encoding value means 5859 ** that the application-defined collating sequence created expects its 5860 ** input strings to be in UTF16 in native byte order, and that the start 5861 ** of the strings must be aligned to a 2-byte boundary. 5862 ** 5863 ** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be 5864 ** used to specify the text encoding to strings input to 5865 ** [sqlite3_result_text64()] and [sqlite3_bind_text64()]. 5866 ** The SQLITE_UTF8_ZT encoding means that the input string (call it "z") 5867 ** is UTF-8 encoded and that it is zero-terminated. If the length parameter 5868 ** (call it "n") is non-negative, this encoding option means that the caller 5869 ** guarantees that z array contains at least n+1 bytes and that the z[n] 5870 ** byte has a value of zero. 5871 ** This option gives the same output as SQLITE_UTF8, but can be more efficient 5872 ** by avoiding the need to make a copy of the input string, in some cases. 5873 ** However, if z is allocated to hold fewer than n+1 bytes or if the 5874 ** z[n] byte is not zero, undefined behavior may result. 5875 ** </dl> 5876 */ 5877 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */ 5878 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */ 5879 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */ 5880 #define SQLITE_UTF16 4 /* Use native byte order */ 5881 #define SQLITE_ANY 5 /* Deprecated */ 5882 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 5883 #define SQLITE_UTF8_ZT 16 /* Zero-terminated UTF8 */ 5884 5885 /* 5886 ** CAPI3REF: Function Flags 5887 ** 5888 ** These constants may be ORed together with the 5889 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument 5890 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or 5891 ** [sqlite3_create_function_v2()]. 5892 ** 5893 ** <dl> 5894 ** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd> 5895 ** The SQLITE_DETERMINISTIC flag means that the new function always gives 5896 ** the same output when the input parameters are the same. 5897 ** The [abs|abs() function] is deterministic, for example, but 5898 ** [randomblob|randomblob()] is not. Functions must 5899 ** be deterministic in order to be used in certain contexts such as 5900 ** with the WHERE clause of [partial indexes] or in [generated columns]. 5901 ** SQLite might also optimize deterministic functions by factoring them 5902 ** out of inner loops. 5903 ** </dd> 5904 ** 5905 ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd> 5906 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked 5907 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in 5908 ** schema structures such as [CHECK constraints], [DEFAULT clauses], 5909 ** [expression indexes], [partial indexes], or [generated columns]. 5910 ** <p> 5911 ** The SQLITE_DIRECTONLY flag is recommended for any 5912 ** [application-defined SQL function] 5913 ** that has side-effects or that could potentially leak sensitive information. 5914 ** This will prevent attacks in which an application is tricked 5915 ** into using a database file that has had its schema surreptitiously 5916 ** modified to invoke the application-defined function in ways that are 5917 ** harmful. 5918 ** <p> 5919 ** Some people say it is good practice to set SQLITE_DIRECTONLY on all 5920 ** [application-defined SQL functions], regardless of whether or not they 5921 ** are security sensitive, as doing so prevents those functions from being used 5922 ** inside of the database schema, and thus ensures that the database 5923 ** can be inspected and modified using generic tools (such as the [CLI]) 5924 ** that do not have access to the application-defined functions. 5925 ** </dd> 5926 ** 5927 ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd> 5928 ** The SQLITE_INNOCUOUS flag means that the function is unlikely 5929 ** to cause problems even if misused. An innocuous function should have 5930 ** no side effects and should not depend on any values other than its 5931 ** input parameters. The [abs|abs() function] is an example of an 5932 ** innocuous function. 5933 ** The [load_extension() SQL function] is not innocuous because of its 5934 ** side effects. 5935 ** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not 5936 ** exactly the same. The [random|random() function] is an example of a 5937 ** function that is innocuous but not deterministic. 5938 ** <p>Some heightened security settings 5939 ** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF]) 5940 ** disable the use of SQL functions inside views and triggers and in 5941 ** schema structures such as [CHECK constraints], [DEFAULT clauses], 5942 ** [expression indexes], [partial indexes], and [generated columns] unless 5943 ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions 5944 ** are innocuous. Developers are advised to avoid using the 5945 ** SQLITE_INNOCUOUS flag for application-defined functions unless the 5946 ** function has been carefully audited and found to be free of potentially 5947 ** security-adverse side-effects and information-leaks. 5948 ** </dd> 5949 ** 5950 ** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd> 5951 ** The SQLITE_SUBTYPE flag indicates to SQLite that a function might call 5952 ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments. 5953 ** This flag instructs SQLite to omit some corner-case optimizations that 5954 ** might disrupt the operation of the [sqlite3_value_subtype()] function, 5955 ** causing it to return zero rather than the correct subtype(). 5956 ** All SQL functions that invoke [sqlite3_value_subtype()] should have this 5957 ** property. If the SQLITE_SUBTYPE property is omitted, then the return 5958 ** value from [sqlite3_value_subtype()] might sometimes be zero even though 5959 ** a non-zero subtype was specified by the function argument expression. 5960 ** 5961 ** [[SQLITE_RESULT_SUBTYPE]] <dt>SQLITE_RESULT_SUBTYPE</dt><dd> 5962 ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call 5963 ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its 5964 ** result. 5965 ** Every function that invokes [sqlite3_result_subtype()] should have this 5966 ** property. If it does not, then the call to [sqlite3_result_subtype()] 5967 ** might become a no-op if the function is used as a term in an 5968 ** [expression index]. On the other hand, SQL functions that never invoke 5969 ** [sqlite3_result_subtype()] should avoid setting this property, as the 5970 ** purpose of this property is to disable certain optimizations that are 5971 ** incompatible with subtypes. 5972 ** 5973 ** [[SQLITE_SELFORDER1]] <dt>SQLITE_SELFORDER1</dt><dd> 5974 ** The SQLITE_SELFORDER1 flag indicates that the function is an aggregate 5975 ** that internally orders the values provided to the first argument. The 5976 ** ordered-set aggregate SQL notation with a single ORDER BY term can be 5977 ** used to invoke this function. If the ordered-set aggregate notation is 5978 ** used on a function that lacks this flag, then an error is raised. Note 5979 ** that the ordered-set aggregate syntax is only available if SQLite is 5980 ** built using the -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES compile-time option. 5981 ** </dd> 5982 ** </dl> 5983 */ 5984 #define SQLITE_DETERMINISTIC 0x000000800 5985 #define SQLITE_DIRECTONLY 0x000080000 5986 #define SQLITE_SUBTYPE 0x000100000 5987 #define SQLITE_INNOCUOUS 0x000200000 5988 #define SQLITE_RESULT_SUBTYPE 0x001000000 5989 #define SQLITE_SELFORDER1 0x002000000 5990 5991 /* 5992 ** CAPI3REF: Deprecated Functions 5993 ** DEPRECATED 5994 ** 5995 ** These functions are [deprecated]. In order to maintain 5996 ** backwards compatibility with older code, these functions continue 5997 ** to be supported. However, new applications should avoid 5998 ** the use of these functions. To encourage programmers to avoid 5999 ** these functions, we will not explain what they do. 6000 */ 6001 #ifndef SQLITE_OMIT_DEPRECATED 6002 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 6003 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 6004 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); 6005 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); 6006 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 6007 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), 6008 void*,sqlite3_int64); 6009 #endif 6010 6011 /* 6012 ** CAPI3REF: Obtaining SQL Values 6013 ** METHOD: sqlite3_value 6014 ** 6015 ** <b>Summary:</b> 6016 ** <blockquote><table border=0 cellpadding=0 cellspacing=0> 6017 ** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value 6018 ** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value 6019 ** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value 6020 ** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value 6021 ** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value 6022 ** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value 6023 ** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in 6024 ** the native byteorder 6025 ** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value 6026 ** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value 6027 ** <tr><td> <td> <td> 6028 ** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB 6029 ** or a UTF-8 TEXT in bytes 6030 ** <tr><td><b>sqlite3_value_bytes16 </b> 6031 ** <td>→ <td>Size of UTF-16 6032 ** TEXT in bytes 6033 ** <tr><td><b>sqlite3_value_type</b><td>→<td>Default 6034 ** datatype of the value 6035 ** <tr><td><b>sqlite3_value_numeric_type </b> 6036 ** <td>→ <td>Best numeric datatype of the value 6037 ** <tr><td><b>sqlite3_value_nochange </b> 6038 ** <td>→ <td>True if the column is unchanged in an UPDATE 6039 ** against a virtual table. 6040 ** <tr><td><b>sqlite3_value_frombind </b> 6041 ** <td>→ <td>True if value originated from a [bound parameter] 6042 ** </table></blockquote> 6043 ** 6044 ** <b>Details:</b> 6045 ** 6046 ** These routines extract type, size, and content information from 6047 ** [protected sqlite3_value] objects. Protected sqlite3_value objects 6048 ** are used to pass parameter information into the functions that 6049 ** implement [application-defined SQL functions] and [virtual tables]. 6050 ** 6051 ** These routines work only with [protected sqlite3_value] objects. 6052 ** Any attempt to use these routines on an [unprotected sqlite3_value] 6053 ** is not threadsafe. 6054 ** 6055 ** ^These routines work just like the corresponding [column access functions] 6056 ** except that these routines take a single [protected sqlite3_value] object 6057 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 6058 ** 6059 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string 6060 ** in the native byte-order of the host machine. ^The 6061 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 6062 ** extract UTF-16 strings as big-endian and little-endian respectively. 6063 ** 6064 ** ^If [sqlite3_value] object V was initialized 6065 ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)] 6066 ** and if X and Y are strings that compare equal according to strcmp(X,Y), 6067 ** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise, 6068 ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer() 6069 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0. 6070 ** 6071 ** ^(The sqlite3_value_type(V) interface returns the 6072 ** [SQLITE_INTEGER | datatype code] for the initial datatype of the 6073 ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER], 6074 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^ 6075 ** Other interfaces might change the datatype for an sqlite3_value object. 6076 ** For example, if the datatype is initially SQLITE_INTEGER and 6077 ** sqlite3_value_text(V) is called to extract a text value for that 6078 ** integer, then subsequent calls to sqlite3_value_type(V) might return 6079 ** SQLITE_TEXT. Whether or not a persistent internal datatype conversion 6080 ** occurs is undefined and may change from one release of SQLite to the next. 6081 ** 6082 ** ^(The sqlite3_value_numeric_type() interface attempts to apply 6083 ** numeric affinity to the value. This means that an attempt is 6084 ** made to convert the value to an integer or floating point. If 6085 ** such a conversion is possible without loss of information (in other 6086 ** words, if the value is a string that looks like a number) 6087 ** then the conversion is performed. Otherwise no conversion occurs. 6088 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ 6089 ** 6090 ** ^Within the [xUpdate] method of a [virtual table], the 6091 ** sqlite3_value_nochange(X) interface returns true if and only if 6092 ** the column corresponding to X is unchanged by the UPDATE operation 6093 ** that the xUpdate method call was invoked to implement and if 6094 ** the prior [xColumn] method call that was invoked to extract 6095 ** the value for that column returned without setting a result (probably 6096 ** because it queried [sqlite3_vtab_nochange()] and found that the column 6097 ** was unchanging). ^Within an [xUpdate] method, any value for which 6098 ** sqlite3_value_nochange(X) is true will in all other respects appear 6099 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other 6100 ** than within an [xUpdate] method call for an UPDATE statement, then 6101 ** the return value is arbitrary and meaningless. 6102 ** 6103 ** ^The sqlite3_value_frombind(X) interface returns non-zero if the 6104 ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()] 6105 ** interfaces. ^If X comes from an SQL literal value, or a table column, 6106 ** or an expression, then sqlite3_value_frombind(X) returns zero. 6107 ** 6108 ** Please pay particular attention to the fact that the pointer returned 6109 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or 6110 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to 6111 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], 6112 ** or [sqlite3_value_text16()]. 6113 ** 6114 ** These routines must be called from the same thread as 6115 ** the SQL function that supplied the [sqlite3_value*] parameters. 6116 ** 6117 ** As long as the input parameter is correct, these routines can only 6118 ** fail if an out-of-memory error occurs while trying to do a 6119 ** UTF8→UTF16 or UTF16→UTF8 conversion. 6120 ** If an out-of-memory error occurs, then the return value from these 6121 ** routines is the same as if the column had contained an SQL NULL value. 6122 ** If the input sqlite3_value was not obtained from [sqlite3_value_dup()], 6123 ** then valid SQL NULL returns can also be distinguished from 6124 ** out-of-memory errors after extracting the value 6125 ** by invoking the [sqlite3_errcode()] immediately after the suspicious 6126 ** return value is obtained and before any 6127 ** other SQLite interface is called on the same [database connection]. 6128 ** If the input sqlite3_value was obtained from sqlite3_value_dup() then 6129 ** it is disconnected from the database connection and so sqlite3_errcode() 6130 ** will not work. 6131 ** In that case, the only way to distinguish an out-of-memory 6132 ** condition from a true SQL NULL is to invoke sqlite3_value_type() on the 6133 ** input to see if it is NULL prior to trying to extract the value. 6134 */ 6135 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); 6136 SQLITE_API double sqlite3_value_double(sqlite3_value*); 6137 SQLITE_API int sqlite3_value_int(sqlite3_value*); 6138 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); 6139 SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*); 6140 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); 6141 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); 6142 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); 6143 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); 6144 SQLITE_API int sqlite3_value_bytes(sqlite3_value*); 6145 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); 6146 SQLITE_API int sqlite3_value_type(sqlite3_value*); 6147 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); 6148 SQLITE_API int sqlite3_value_nochange(sqlite3_value*); 6149 SQLITE_API int sqlite3_value_frombind(sqlite3_value*); 6150 6151 /* 6152 ** CAPI3REF: Report the internal text encoding state of an sqlite3_value object 6153 ** METHOD: sqlite3_value 6154 ** 6155 ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8], 6156 ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding 6157 ** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X) 6158 ** returns something other than SQLITE_TEXT, then the return value from 6159 ** sqlite3_value_encoding(X) is meaningless. ^Calls to 6160 ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], 6161 ** [sqlite3_value_text16be(X)], 6162 ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or 6163 ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and 6164 ** thus change the return from subsequent calls to sqlite3_value_encoding(X). 6165 ** 6166 ** This routine is intended for used by applications that test and validate 6167 ** the SQLite implementation. This routine is inquiring about the opaque 6168 ** internal state of an [sqlite3_value] object. Ordinary applications should 6169 ** not need to know what the internal state of an sqlite3_value object is and 6170 ** hence should not need to use this interface. 6171 */ 6172 SQLITE_API int sqlite3_value_encoding(sqlite3_value*); 6173 6174 /* 6175 ** CAPI3REF: Finding The Subtype Of SQL Values 6176 ** METHOD: sqlite3_value 6177 ** 6178 ** The sqlite3_value_subtype(V) function returns the subtype for 6179 ** an [application-defined SQL function] argument V. The subtype 6180 ** information can be used to pass a limited amount of context from 6181 ** one SQL function to another. Use the [sqlite3_result_subtype()] 6182 ** routine to set the subtype for the return value of an SQL function. 6183 ** 6184 ** Every [application-defined SQL function] that invokes this interface 6185 ** should include the [SQLITE_SUBTYPE] property in the text 6186 ** encoding argument when the function is [sqlite3_create_function|registered]. 6187 ** If the [SQLITE_SUBTYPE] property is omitted, then sqlite3_value_subtype() 6188 ** might return zero instead of the upstream subtype in some corner cases. 6189 */ 6190 SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*); 6191 6192 /* 6193 ** CAPI3REF: Copy And Free SQL Values 6194 ** METHOD: sqlite3_value 6195 ** 6196 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value] 6197 ** object V and returns a pointer to that copy. ^The [sqlite3_value] returned 6198 ** is a [protected sqlite3_value] object even if the input is not. 6199 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a 6200 ** memory allocation fails. ^If V is a [pointer value], then the result 6201 ** of sqlite3_value_dup(V) is a NULL value. 6202 ** 6203 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object 6204 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer 6205 ** then sqlite3_value_free(V) is a harmless no-op. 6206 */ 6207 SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*); 6208 SQLITE_API void sqlite3_value_free(sqlite3_value*); 6209 6210 /* 6211 ** CAPI3REF: Obtain Aggregate Function Context 6212 ** METHOD: sqlite3_context 6213 ** 6214 ** Implementations of aggregate SQL functions use this 6215 ** routine to allocate memory for storing their state. 6216 ** 6217 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called 6218 ** for a particular aggregate function, SQLite allocates 6219 ** N bytes of memory, zeroes out that memory, and returns a pointer 6220 ** to the new memory. ^On second and subsequent calls to 6221 ** sqlite3_aggregate_context() for the same aggregate function instance, 6222 ** the same buffer is returned. Sqlite3_aggregate_context() is normally 6223 ** called once for each invocation of the xStep callback and then one 6224 ** last time when the xFinal callback is invoked. ^(When no rows match 6225 ** an aggregate query, the xStep() callback of the aggregate function 6226 ** implementation is never called and xFinal() is called exactly once. 6227 ** In those cases, sqlite3_aggregate_context() might be called for the 6228 ** first time from within xFinal().)^ 6229 ** 6230 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer 6231 ** when first called if N is less than or equal to zero or if a memory 6232 ** allocation error occurs. 6233 ** 6234 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 6235 ** determined by the N parameter on the first successful call. Changing the 6236 ** value of N in any subsequent call to sqlite3_aggregate_context() within 6237 ** the same aggregate function instance will not resize the memory 6238 ** allocation.)^ Within the xFinal callback, it is customary to set 6239 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no 6240 ** pointless memory allocations occur. 6241 ** 6242 ** ^SQLite automatically frees the memory allocated by 6243 ** sqlite3_aggregate_context() when the aggregate query concludes. 6244 ** 6245 ** The first parameter must be a copy of the 6246 ** [sqlite3_context | SQL function context] that is the first parameter 6247 ** to the xStep or xFinal callback routine that implements the aggregate 6248 ** function. 6249 ** 6250 ** This routine must be called from the same thread in which 6251 ** the aggregate SQL function is running. 6252 */ 6253 SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); 6254 6255 /* 6256 ** CAPI3REF: User Data For Functions 6257 ** METHOD: sqlite3_context 6258 ** 6259 ** ^The sqlite3_user_data() interface returns a copy of 6260 ** the pointer that was the pUserData parameter (the 5th parameter) 6261 ** of the [sqlite3_create_function()] 6262 ** and [sqlite3_create_function16()] routines that originally 6263 ** registered the application defined function. 6264 ** 6265 ** This routine must be called from the same thread in which 6266 ** the application-defined function is running. 6267 */ 6268 SQLITE_API void *sqlite3_user_data(sqlite3_context*); 6269 6270 /* 6271 ** CAPI3REF: Database Connection For Functions 6272 ** METHOD: sqlite3_context 6273 ** 6274 ** ^The sqlite3_context_db_handle() interface returns a copy of 6275 ** the pointer to the [database connection] (the 1st parameter) 6276 ** of the [sqlite3_create_function()] 6277 ** and [sqlite3_create_function16()] routines that originally 6278 ** registered the application defined function. 6279 */ 6280 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 6281 6282 /* 6283 ** CAPI3REF: Function Auxiliary Data 6284 ** METHOD: sqlite3_context 6285 ** 6286 ** These functions may be used by (non-aggregate) SQL functions to 6287 ** associate auxiliary data with argument values. If the same argument 6288 ** value is passed to multiple invocations of the same SQL function during 6289 ** query execution, under some circumstances the associated auxiliary data 6290 ** might be preserved. An example of where this might be useful is in a 6291 ** regular-expression matching function. The compiled version of the regular 6292 ** expression can be stored as auxiliary data associated with the pattern 6293 ** string. Then as long as the pattern string remains the same, 6294 ** the compiled regular expression can be reused on multiple 6295 ** invocations of the same function. 6296 ** 6297 ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary 6298 ** data associated by the sqlite3_set_auxdata(C,N,P,X) function with the 6299 ** Nth argument value to the application-defined function. ^N is zero 6300 ** for the left-most function argument. ^If there is no auxiliary data 6301 ** associated with the function argument, the sqlite3_get_auxdata(C,N) 6302 ** interface returns a NULL pointer. 6303 ** 6304 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the 6305 ** N-th argument of the application-defined function. ^Subsequent 6306 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent 6307 ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or 6308 ** NULL if the auxiliary data has been discarded. 6309 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL, 6310 ** SQLite will invoke the destructor function X with parameter P exactly 6311 ** once, when the auxiliary data is discarded. 6312 ** SQLite is free to discard the auxiliary data at any time, including: <ul> 6313 ** <li> ^(when the corresponding function parameter changes)^, or 6314 ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the 6315 ** SQL statement)^, or 6316 ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same 6317 ** parameter)^, or 6318 ** <li> ^(during the original sqlite3_set_auxdata() call when a memory 6319 ** allocation error occurs.)^ 6320 ** <li> ^(during the original sqlite3_set_auxdata() call if the function 6321 ** is evaluated during query planning instead of during query execution, 6322 ** as sometimes happens with [SQLITE_ENABLE_STAT4].)^ </ul> 6323 ** 6324 ** Note the last two bullets in particular. The destructor X in 6325 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the 6326 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata() 6327 ** should be called near the end of the function implementation and the 6328 ** function implementation should not make any use of P after 6329 ** sqlite3_set_auxdata() has been called. Furthermore, a call to 6330 ** sqlite3_get_auxdata() that occurs immediately after a corresponding call 6331 ** to sqlite3_set_auxdata() might still return NULL if an out-of-memory 6332 ** condition occurred during the sqlite3_set_auxdata() call or if the 6333 ** function is being evaluated during query planning rather than during 6334 ** query execution. 6335 ** 6336 ** ^(In practice, auxiliary data is preserved between function calls for 6337 ** function parameters that are compile-time constants, including literal 6338 ** values and [parameters] and expressions composed from the same.)^ 6339 ** 6340 ** The value of the N parameter to these interfaces should be non-negative. 6341 ** Future enhancements may make use of negative N values to define new 6342 ** kinds of function caching behavior. 6343 ** 6344 ** These routines must be called from the same thread in which 6345 ** the SQL function is running. 6346 ** 6347 ** See also: [sqlite3_get_clientdata()] and [sqlite3_set_clientdata()]. 6348 */ 6349 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); 6350 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); 6351 6352 /* 6353 ** CAPI3REF: Database Connection Client Data 6354 ** METHOD: sqlite3 6355 ** 6356 ** These functions are used to associate one or more named pointers 6357 ** with a [database connection]. 6358 ** A call to sqlite3_set_clientdata(D,N,P,X) causes the pointer P 6359 ** to be attached to [database connection] D using name N. Subsequent 6360 ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P 6361 ** or a NULL pointer if there were no prior calls to 6362 ** sqlite3_set_clientdata() with the same values of D and N. 6363 ** Names are compared using strcmp() and are thus case sensitive. 6364 ** It returns 0 on success and SQLITE_NOMEM on allocation failure. 6365 ** 6366 ** If P and X are both non-NULL, then the destructor X is invoked with 6367 ** argument P on the first of the following occurrences: 6368 ** <ul> 6369 ** <li> An out-of-memory error occurs during the call to 6370 ** sqlite3_set_clientdata() which attempts to register pointer P. 6371 ** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made 6372 ** with the same D and N parameters. 6373 ** <li> The database connection closes. SQLite does not make any guarantees 6374 ** about the order in which destructors are called, only that all 6375 ** destructors will be called exactly once at some point during the 6376 ** database connection closing process. 6377 ** </ul> 6378 ** 6379 ** SQLite does not do anything with client data other than invoke 6380 ** destructors on the client data at the appropriate time. The intended 6381 ** use for client data is to provide a mechanism for wrapper libraries 6382 ** to store additional information about an SQLite database connection. 6383 ** 6384 ** There is no limit (other than available memory) on the number of different 6385 ** client data pointers (with different names) that can be attached to a 6386 ** single database connection. However, the current implementation stores 6387 ** the content on a linked list. Insert and retrieval performance will 6388 ** be proportional to the number of entries. The design use case, and 6389 ** the use case for which the implementation is optimized, is 6390 ** that an application will store only small number of client data names, 6391 ** typically just one or two. This interface is not intended to be a 6392 ** generalized key/value store for thousands or millions of keys. It 6393 ** will work for that, but performance might be disappointing. 6394 ** 6395 ** There is no way to enumerate the client data pointers 6396 ** associated with a database connection. The N parameter can be thought 6397 ** of as a secret key such that only code that knows the secret key is able 6398 ** to access the associated data. 6399 ** 6400 ** Security Warning: These interfaces should not be exposed in scripting 6401 ** languages or in other circumstances where it might be possible for an 6402 ** attacker to invoke them. Any agent that can invoke these interfaces 6403 ** can probably also take control of the process. 6404 ** 6405 ** Database connection client data is only available for SQLite 6406 ** version 3.44.0 ([dateof:3.44.0]) and later. 6407 ** 6408 ** See also: [sqlite3_set_auxdata()] and [sqlite3_get_auxdata()]. 6409 */ 6410 SQLITE_API void *sqlite3_get_clientdata(sqlite3*,const char*); 6411 SQLITE_API int sqlite3_set_clientdata(sqlite3*, const char*, void*, void(*)(void*)); 6412 6413 /* 6414 ** CAPI3REF: Constants Defining Special Destructor Behavior 6415 ** 6416 ** These are special values for the destructor that is passed in as the 6417 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 6418 ** argument is SQLITE_STATIC, it means that the content pointer is constant 6419 ** and will never change. It does not need to be destroyed. ^The 6420 ** SQLITE_TRANSIENT value means that the content will likely change in 6421 ** the near future and that SQLite should make its own private copy of 6422 ** the content before returning. 6423 ** 6424 ** The typedef is necessary to work around problems in certain 6425 ** C++ compilers. 6426 */ 6427 typedef void (*sqlite3_destructor_type)(void*); 6428 #define SQLITE_STATIC ((sqlite3_destructor_type)0) 6429 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 6430 6431 /* 6432 ** CAPI3REF: Setting The Result Of An SQL Function 6433 ** METHOD: sqlite3_context 6434 ** 6435 ** These routines are used by the xFunc or xFinal callbacks that 6436 ** implement SQL functions and aggregates. See 6437 ** [sqlite3_create_function()] and [sqlite3_create_function16()] 6438 ** for additional information. 6439 ** 6440 ** These functions work very much like the [parameter binding] family of 6441 ** functions used to bind values to host parameters in prepared statements. 6442 ** Refer to the [SQL parameter] documentation for additional information. 6443 ** 6444 ** ^The sqlite3_result_blob() interface sets the result from 6445 ** an application-defined function to be the BLOB whose content is pointed 6446 ** to by the second parameter and which is N bytes long where N is the 6447 ** third parameter. 6448 ** 6449 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N) 6450 ** interfaces set the result of the application-defined function to be 6451 ** a BLOB containing all zero bytes and N bytes in size. 6452 ** 6453 ** ^The sqlite3_result_double() interface sets the result from 6454 ** an application-defined function to be a floating point value specified 6455 ** by its 2nd argument. 6456 ** 6457 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions 6458 ** cause the implemented SQL function to throw an exception. 6459 ** ^SQLite uses the string pointed to by the 6460 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() 6461 ** as the text of an error message. ^SQLite interprets the error 6462 ** message string from sqlite3_result_error() as UTF-8. ^SQLite 6463 ** interprets the string from sqlite3_result_error16() as UTF-16 using 6464 ** the same [byte-order determination rules] as [sqlite3_bind_text16()]. 6465 ** ^If the third parameter to sqlite3_result_error() 6466 ** or sqlite3_result_error16() is negative then SQLite takes as the error 6467 ** message all text up through the first zero character. 6468 ** ^If the third parameter to sqlite3_result_error() or 6469 ** sqlite3_result_error16() is non-negative then SQLite takes that many 6470 ** bytes (not characters) from the 2nd parameter as the error message. 6471 ** ^The sqlite3_result_error() and sqlite3_result_error16() 6472 ** routines make a private copy of the error message text before 6473 ** they return. Hence, the calling function can deallocate or 6474 ** modify the text after they return without harm. 6475 ** ^The sqlite3_result_error_code() function changes the error code 6476 ** returned by SQLite as a result of an error in a function. ^By default, 6477 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 6478 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 6479 ** 6480 ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an 6481 ** error indicating that a string or BLOB is too long to represent. 6482 ** 6483 ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an 6484 ** error indicating that a memory allocation failed. 6485 ** 6486 ** ^The sqlite3_result_int() interface sets the return value 6487 ** of the application-defined function to be the 32-bit signed integer 6488 ** value given in the 2nd argument. 6489 ** ^The sqlite3_result_int64() interface sets the return value 6490 ** of the application-defined function to be the 64-bit signed integer 6491 ** value given in the 2nd argument. 6492 ** 6493 ** ^The sqlite3_result_null() interface sets the return value 6494 ** of the application-defined function to be NULL. 6495 ** 6496 ** ^The sqlite3_result_text(), sqlite3_result_text16(), 6497 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 6498 ** set the return value of the application-defined function to be 6499 ** a text string which is represented as UTF-8, UTF-16 native byte order, 6500 ** UTF-16 little endian, or UTF-16 big endian, respectively. 6501 ** ^The sqlite3_result_text64(C,Z,N,D,E) interface sets the return value of an 6502 ** application-defined function to be a text string in an encoding 6503 ** specified the E parameter, which must be one 6504 ** of [SQLITE_UTF8], [SQLITE_UTF8_ZT], [SQLITE_UTF16], [SQLITE_UTF16BE], 6505 ** or [SQLITE_UTF16LE]. ^The special value [SQLITE_UTF8_ZT] means that 6506 ** the result text is both UTF-8 and zero-terminated. In other words, 6507 ** SQLITE_UTF8_ZT means that the Z array holds at least N+1 bytes and that 6508 ** the Z[N] is zero. 6509 ** ^SQLite takes the text result from the application from 6510 ** the 2nd parameter of the sqlite3_result_text* interfaces. 6511 ** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces 6512 ** other than sqlite3_result_text64() is negative, then SQLite computes 6513 ** the string length itself by searching the 2nd parameter for the first 6514 ** zero character. 6515 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 6516 ** is non-negative, then as many bytes (not characters) of the text 6517 ** pointed to by the 2nd parameter are taken as the application-defined 6518 ** function result. If the 3rd parameter is non-negative, then it 6519 ** must be the byte offset into the string where the NUL terminator would 6520 ** appear if the string were NUL terminated. If any NUL characters occur 6521 ** in the string at a byte offset that is less than the value of the 3rd 6522 ** parameter, then the resulting string will contain embedded NULs and the 6523 ** result of expressions operating on strings with embedded NULs is undefined. 6524 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 6525 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 6526 ** function as the destructor on the text or BLOB result when it has 6527 ** finished using that result. 6528 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 6529 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 6530 ** assumes that the text or BLOB result is in constant space and does not 6531 ** copy the content of the parameter nor call a destructor on the content 6532 ** when it has finished using that result. 6533 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 6534 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 6535 ** then SQLite makes a copy of the result into space obtained 6536 ** from [sqlite3_malloc()] before it returns. 6537 ** 6538 ** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and 6539 ** sqlite3_result_text16be() routines, and for sqlite3_result_text64() 6540 ** when the encoding is not UTF8, if the input UTF16 begins with a 6541 ** byte-order mark (BOM, U+FEFF) then the BOM is removed from the 6542 ** string and the rest of the string is interpreted according to the 6543 ** byte-order specified by the BOM. ^The byte-order specified by 6544 ** the BOM at the beginning of the text overrides the byte-order 6545 ** specified by the interface procedure. ^So, for example, if 6546 ** sqlite3_result_text16le() is invoked with text that begins 6547 ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the 6548 ** first two bytes of input are skipped and the remaining input 6549 ** is interpreted as UTF16BE text. 6550 ** 6551 ** ^For UTF16 input text to the sqlite3_result_text16(), 6552 ** sqlite3_result_text16be(), sqlite3_result_text16le(), and 6553 ** sqlite3_result_text64() routines, if the text contains invalid 6554 ** UTF16 characters, the invalid characters might be converted 6555 ** into the unicode replacement character, U+FFFD. 6556 ** 6557 ** ^The sqlite3_result_value() interface sets the result of 6558 ** the application-defined function to be a copy of the 6559 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 6560 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 6561 ** so that the [sqlite3_value] specified in the parameter may change or 6562 ** be deallocated after sqlite3_result_value() returns without harm. 6563 ** ^A [protected sqlite3_value] object may always be used where an 6564 ** [unprotected sqlite3_value] object is required, so either 6565 ** kind of [sqlite3_value] object can be used with this interface. 6566 ** 6567 ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an 6568 ** SQL NULL value, just like [sqlite3_result_null(C)], except that it 6569 ** also associates the host-language pointer P or type T with that 6570 ** NULL value such that the pointer can be retrieved within an 6571 ** [application-defined SQL function] using [sqlite3_value_pointer()]. 6572 ** ^If the D parameter is not NULL, then it is a pointer to a destructor 6573 ** for the P parameter. ^SQLite invokes D with P as its only argument 6574 ** when SQLite is finished with P. The T parameter should be a static 6575 ** string and preferably a string literal. The sqlite3_result_pointer() 6576 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0. 6577 ** 6578 ** If these routines are called from within a different thread 6579 ** than the one containing the application-defined function that received 6580 ** the [sqlite3_context] pointer, the results are undefined. 6581 */ 6582 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); 6583 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*, 6584 sqlite3_uint64,void(*)(void*)); 6585 SQLITE_API void sqlite3_result_double(sqlite3_context*, double); 6586 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); 6587 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); 6588 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); 6589 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); 6590 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); 6591 SQLITE_API void sqlite3_result_int(sqlite3_context*, int); 6592 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 6593 SQLITE_API void sqlite3_result_null(sqlite3_context*); 6594 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); 6595 SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char *z, sqlite3_uint64 n, 6596 void(*)(void*), unsigned char encoding); 6597 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); 6598 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); 6599 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); 6600 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 6601 SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*)); 6602 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); 6603 SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); 6604 6605 6606 /* 6607 ** CAPI3REF: Setting The Subtype Of An SQL Function 6608 ** METHOD: sqlite3_context 6609 ** 6610 ** The sqlite3_result_subtype(C,T) function causes the subtype of 6611 ** the result from the [application-defined SQL function] with 6612 ** [sqlite3_context] C to be the value T. Only the lower 8 bits 6613 ** of the subtype T are preserved in current versions of SQLite; 6614 ** higher order bits are discarded. 6615 ** The number of subtype bytes preserved by SQLite might increase 6616 ** in future releases of SQLite. 6617 ** 6618 ** Every [application-defined SQL function] that invokes this interface 6619 ** should include the [SQLITE_RESULT_SUBTYPE] property in its 6620 ** text encoding argument when the SQL function is 6621 ** [sqlite3_create_function|registered]. If the [SQLITE_RESULT_SUBTYPE] 6622 ** property is omitted from the function that invokes sqlite3_result_subtype(), 6623 ** then in some cases the sqlite3_result_subtype() might fail to set 6624 ** the result subtype. 6625 ** 6626 ** If SQLite is compiled with -DSQLITE_STRICT_SUBTYPE=1, then any 6627 ** SQL function that invokes the sqlite3_result_subtype() interface 6628 ** and that does not have the SQLITE_RESULT_SUBTYPE property will raise 6629 ** an error. Future versions of SQLite might enable -DSQLITE_STRICT_SUBTYPE=1 6630 ** by default. 6631 */ 6632 SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int); 6633 6634 /* 6635 ** CAPI3REF: Define New Collating Sequences 6636 ** METHOD: sqlite3 6637 ** 6638 ** ^These functions add, remove, or modify a [collation] associated 6639 ** with the [database connection] specified as the first argument. 6640 ** 6641 ** ^The name of the collation is a UTF-8 string 6642 ** for sqlite3_create_collation() and sqlite3_create_collation_v2() 6643 ** and a UTF-16 string in native byte order for sqlite3_create_collation16(). 6644 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are 6645 ** considered to be the same name. 6646 ** 6647 ** ^(The third argument (eTextRep) must be one of the constants: 6648 ** <ul> 6649 ** <li> [SQLITE_UTF8], 6650 ** <li> [SQLITE_UTF16LE], 6651 ** <li> [SQLITE_UTF16BE], 6652 ** <li> [SQLITE_UTF16], or 6653 ** <li> [SQLITE_UTF16_ALIGNED]. 6654 ** </ul>)^ 6655 ** ^The eTextRep argument determines the encoding of strings passed 6656 ** to the collating function callback, xCompare. 6657 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep 6658 ** force strings to be UTF16 with native byte order. 6659 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin 6660 ** on an even byte address. 6661 ** 6662 ** ^The fourth argument, pArg, is an application data pointer that is passed 6663 ** through as the first argument to the collating function callback. 6664 ** 6665 ** ^The fifth argument, xCompare, is a pointer to the collating function. 6666 ** ^Multiple collating functions can be registered using the same name but 6667 ** with different eTextRep parameters and SQLite will use whichever 6668 ** function requires the least amount of data transformation. 6669 ** ^If the xCompare argument is NULL then the collating function is 6670 ** deleted. ^When all collating functions having the same name are deleted, 6671 ** that collation is no longer usable. 6672 ** 6673 ** ^The collating function callback is invoked with a copy of the pArg 6674 ** application data pointer and with two strings in the encoding specified 6675 ** by the eTextRep argument. The two integer parameters to the collating 6676 ** function callback are the length of the two strings, in bytes. The collating 6677 ** function must return an integer that is negative, zero, or positive 6678 ** if the first string is less than, equal to, or greater than the second, 6679 ** respectively. A collating function must always return the same answer 6680 ** given the same inputs. If two or more collating functions are registered 6681 ** to the same collation name (using different eTextRep values) then all 6682 ** must give an equivalent answer when invoked with equivalent strings. 6683 ** The collating function must obey the following properties for all 6684 ** strings A, B, and C: 6685 ** 6686 ** <ol> 6687 ** <li> If A==B then B==A. 6688 ** <li> If A==B and B==C then A==C. 6689 ** <li> If A<B THEN B>A. 6690 ** <li> If A<B and B<C then A<C. 6691 ** </ol> 6692 ** 6693 ** If a collating function fails any of the above constraints and that 6694 ** collating function is registered and used, then the behavior of SQLite 6695 ** is undefined. 6696 ** 6697 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() 6698 ** with the addition that the xDestroy callback is invoked on pArg when 6699 ** the collating function is deleted. 6700 ** ^Collating functions are deleted when they are overridden by later 6701 ** calls to the collation creation functions or when the 6702 ** [database connection] is closed using [sqlite3_close()]. 6703 ** 6704 ** ^The xDestroy callback is <u>not</u> called if the 6705 ** sqlite3_create_collation_v2() function fails. Applications that invoke 6706 ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should 6707 ** check the return code and dispose of the application data pointer 6708 ** themselves rather than expecting SQLite to deal with it for them. 6709 ** This is different from every other SQLite interface. The inconsistency 6710 ** is unfortunate but cannot be changed without breaking backwards 6711 ** compatibility. 6712 ** 6713 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. 6714 */ 6715 SQLITE_API int sqlite3_create_collation( 6716 sqlite3*, 6717 const char *zName, 6718 int eTextRep, 6719 void *pArg, 6720 int(*xCompare)(void*,int,const void*,int,const void*) 6721 ); 6722 SQLITE_API int sqlite3_create_collation_v2( 6723 sqlite3*, 6724 const char *zName, 6725 int eTextRep, 6726 void *pArg, 6727 int(*xCompare)(void*,int,const void*,int,const void*), 6728 void(*xDestroy)(void*) 6729 ); 6730 SQLITE_API int sqlite3_create_collation16( 6731 sqlite3*, 6732 const void *zName, 6733 int eTextRep, 6734 void *pArg, 6735 int(*xCompare)(void*,int,const void*,int,const void*) 6736 ); 6737 6738 /* 6739 ** CAPI3REF: Collation Needed Callbacks 6740 ** METHOD: sqlite3 6741 ** 6742 ** ^To avoid having to register all collation sequences before a database 6743 ** can be used, a single callback function may be registered with the 6744 ** [database connection] to be invoked whenever an undefined collation 6745 ** sequence is required. 6746 ** 6747 ** ^If the function is registered using the sqlite3_collation_needed() API, 6748 ** then it is passed the names of undefined collation sequences as strings 6749 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, 6750 ** the names are passed as UTF-16 in machine native byte order. 6751 ** ^A call to either function replaces the existing collation-needed callback. 6752 ** 6753 ** ^(When the callback is invoked, the first argument passed is a copy 6754 ** of the second argument to sqlite3_collation_needed() or 6755 ** sqlite3_collation_needed16(). The second argument is the database 6756 ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], 6757 ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation 6758 ** sequence function required. The fourth parameter is the name of the 6759 ** required collation sequence.)^ 6760 ** 6761 ** The callback function should register the desired collation using 6762 ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or 6763 ** [sqlite3_create_collation_v2()]. 6764 */ 6765 SQLITE_API int sqlite3_collation_needed( 6766 sqlite3*, 6767 void*, 6768 void(*)(void*,sqlite3*,int eTextRep,const char*) 6769 ); 6770 SQLITE_API int sqlite3_collation_needed16( 6771 sqlite3*, 6772 void*, 6773 void(*)(void*,sqlite3*,int eTextRep,const void*) 6774 ); 6775 6776 #ifdef SQLITE_ENABLE_CEROD 6777 /* 6778 ** Specify the activation key for a CEROD database. Unless 6779 ** activated, none of the CEROD routines will work. 6780 */ 6781 SQLITE_API void sqlite3_activate_cerod( 6782 const char *zPassPhrase /* Activation phrase */ 6783 ); 6784 #endif 6785 6786 /* 6787 ** CAPI3REF: Suspend Execution For A Short Time 6788 ** 6789 ** The sqlite3_sleep() function causes the current thread to suspend execution 6790 ** for at least a number of milliseconds specified in its parameter. 6791 ** 6792 ** If the operating system does not support sleep requests with 6793 ** millisecond time resolution, then the time will be rounded up to 6794 ** the nearest second. The number of milliseconds of sleep actually 6795 ** requested from the operating system is returned. 6796 ** 6797 ** ^SQLite implements this interface by calling the xSleep() 6798 ** method of the default [sqlite3_vfs] object. If the xSleep() method 6799 ** of the default VFS is not implemented correctly, or not implemented at 6800 ** all, then the behavior of sqlite3_sleep() may deviate from the description 6801 ** in the previous paragraphs. 6802 ** 6803 ** If a negative argument is passed to sqlite3_sleep() the results vary by 6804 ** VFS and operating system. Some system treat a negative argument as an 6805 ** instruction to sleep forever. Others understand it to mean do not sleep 6806 ** at all. ^In SQLite version 3.42.0 and later, a negative 6807 ** argument passed into sqlite3_sleep() is changed to zero before it is relayed 6808 ** down into the xSleep method of the VFS. 6809 */ 6810 SQLITE_API int sqlite3_sleep(int); 6811 6812 /* 6813 ** CAPI3REF: Name Of The Folder Holding Temporary Files 6814 ** 6815 ** ^(If this global variable is made to point to a string which is 6816 ** the name of a folder (a.k.a. directory), then all temporary files 6817 ** created by SQLite when using a built-in [sqlite3_vfs | VFS] 6818 ** will be placed in that directory.)^ ^If this variable 6819 ** is a NULL pointer, then SQLite performs a search for an appropriate 6820 ** temporary file directory. 6821 ** 6822 ** Applications are strongly discouraged from using this global variable. 6823 ** It is required to set a temporary folder on Windows Runtime (WinRT). 6824 ** But for all other platforms, it is highly recommended that applications 6825 ** neither read nor write this variable. This global variable is a relic 6826 ** that exists for backwards compatibility of legacy applications and should 6827 ** be avoided in new projects. 6828 ** 6829 ** It is not safe to read or modify this variable in more than one 6830 ** thread at a time. It is not safe to read or modify this variable 6831 ** if a [database connection] is being used at the same time in a separate 6832 ** thread. 6833 ** It is intended that this variable be set once 6834 ** as part of process initialization and before any SQLite interface 6835 ** routines have been called and that this variable remain unchanged 6836 ** thereafter. 6837 ** 6838 ** ^The [temp_store_directory pragma] may modify this variable and cause 6839 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 6840 ** the [temp_store_directory pragma] always assumes that any string 6841 ** that this variable points to is held in memory obtained from 6842 ** [sqlite3_malloc] and the pragma may attempt to free that memory 6843 ** using [sqlite3_free]. 6844 ** Hence, if this variable is modified directly, either it should be 6845 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 6846 ** or else the use of the [temp_store_directory pragma] should be avoided. 6847 ** Except when requested by the [temp_store_directory pragma], SQLite 6848 ** does not free the memory that sqlite3_temp_directory points to. If 6849 ** the application wants that memory to be freed, it must do 6850 ** so itself, taking care to only do so after all [database connection] 6851 ** objects have been destroyed. 6852 ** 6853 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set 6854 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various 6855 ** features that require the use of temporary files may fail. Here is an 6856 ** example of how to do this using C++ with the Windows Runtime: 6857 ** 6858 ** <blockquote><pre> 6859 ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current-> 6860 ** TemporaryFolder->Path->Data(); 6861 ** char zPathBuf[MAX_PATH + 1]; 6862 ** memset(zPathBuf, 0, sizeof(zPathBuf)); 6863 ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf), 6864 ** NULL, NULL); 6865 ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf); 6866 ** </pre></blockquote> 6867 */ 6868 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory; 6869 6870 /* 6871 ** CAPI3REF: Name Of The Folder Holding Database Files 6872 ** 6873 ** ^(If this global variable is made to point to a string which is 6874 ** the name of a folder (a.k.a. directory), then all database files 6875 ** specified with a relative pathname and created or accessed by 6876 ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed 6877 ** to be relative to that directory.)^ ^If this variable is a NULL 6878 ** pointer, then SQLite assumes that all database files specified 6879 ** with a relative pathname are relative to the current directory 6880 ** for the process. Only the windows VFS makes use of this global 6881 ** variable; it is ignored by the unix VFS. 6882 ** 6883 ** Changing the value of this variable while a database connection is 6884 ** open can result in a corrupt database. 6885 ** 6886 ** It is not safe to read or modify this variable in more than one 6887 ** thread at a time. It is not safe to read or modify this variable 6888 ** if a [database connection] is being used at the same time in a separate 6889 ** thread. 6890 ** It is intended that this variable be set once 6891 ** as part of process initialization and before any SQLite interface 6892 ** routines have been called and that this variable remain unchanged 6893 ** thereafter. 6894 ** 6895 ** ^The [data_store_directory pragma] may modify this variable and cause 6896 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 6897 ** the [data_store_directory pragma] always assumes that any string 6898 ** that this variable points to is held in memory obtained from 6899 ** [sqlite3_malloc] and the pragma may attempt to free that memory 6900 ** using [sqlite3_free]. 6901 ** Hence, if this variable is modified directly, either it should be 6902 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 6903 ** or else the use of the [data_store_directory pragma] should be avoided. 6904 */ 6905 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; 6906 6907 /* 6908 ** CAPI3REF: Win32 Specific Interface 6909 ** 6910 ** These interfaces are available only on Windows. The 6911 ** [sqlite3_win32_set_directory] interface is used to set the value associated 6912 ** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to 6913 ** zValue, depending on the value of the type parameter. The zValue parameter 6914 ** should be NULL to cause the previous value to be freed via [sqlite3_free]; 6915 ** a non-NULL value will be copied into memory obtained from [sqlite3_malloc] 6916 ** prior to being used. The [sqlite3_win32_set_directory] interface returns 6917 ** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported, 6918 ** or [SQLITE_NOMEM] if memory could not be allocated. The value of the 6919 ** [sqlite3_data_directory] variable is intended to act as a replacement for 6920 ** the current directory on the sub-platforms of Win32 where that concept is 6921 ** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and 6922 ** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the 6923 ** sqlite3_win32_set_directory interface except the string parameter must be 6924 ** UTF-8 or UTF-16, respectively. 6925 */ 6926 SQLITE_API int sqlite3_win32_set_directory( 6927 unsigned long type, /* Identifier for directory being set or reset */ 6928 void *zValue /* New value for directory being set or reset */ 6929 ); 6930 SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue); 6931 SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue); 6932 6933 /* 6934 ** CAPI3REF: Win32 Directory Types 6935 ** 6936 ** These macros are only available on Windows. They define the allowed values 6937 ** for the type argument to the [sqlite3_win32_set_directory] interface. 6938 */ 6939 #define SQLITE_WIN32_DATA_DIRECTORY_TYPE 1 6940 #define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 2 6941 6942 /* 6943 ** CAPI3REF: Test For Auto-Commit Mode 6944 ** KEYWORDS: {autocommit mode} 6945 ** METHOD: sqlite3 6946 ** 6947 ** ^The sqlite3_get_autocommit() interface returns non-zero or 6948 ** zero if the given database connection is or is not in autocommit mode, 6949 ** respectively. ^Autocommit mode is on by default. 6950 ** ^Autocommit mode is disabled by a [BEGIN] statement. 6951 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. 6952 ** 6953 ** If certain kinds of errors occur on a statement within a multi-statement 6954 ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], 6955 ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the 6956 ** transaction might be rolled back automatically. The only way to 6957 ** find out whether SQLite automatically rolled back the transaction after 6958 ** an error is to use this function. 6959 ** 6960 ** If another thread changes the autocommit status of the database 6961 ** connection while this routine is running, then the return value 6962 ** is undefined. 6963 */ 6964 SQLITE_API int sqlite3_get_autocommit(sqlite3*); 6965 6966 /* 6967 ** CAPI3REF: Find The Database Handle Of A Prepared Statement 6968 ** METHOD: sqlite3_stmt 6969 ** 6970 ** ^The sqlite3_db_handle interface returns the [database connection] handle 6971 ** to which a [prepared statement] belongs. ^The [database connection] 6972 ** returned by sqlite3_db_handle is the same [database connection] 6973 ** that was the first argument 6974 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 6975 ** create the statement in the first place. 6976 */ 6977 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 6978 6979 /* 6980 ** CAPI3REF: Return The Schema Name For A Database Connection 6981 ** METHOD: sqlite3 6982 ** 6983 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name 6984 ** for the N-th database on database connection D, or a NULL pointer if N is 6985 ** out of range. An N value of 0 means the main database file. An N of 1 is 6986 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed 6987 ** databases. 6988 ** 6989 ** Space to hold the string that is returned by sqlite3_db_name() is managed 6990 ** by SQLite itself. The string might be deallocated by any operation that 6991 ** changes the schema, including [ATTACH] or [DETACH] or calls to 6992 ** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that 6993 ** occur on a different thread. Applications that need to 6994 ** remember the string long-term should make their own copy. Applications that 6995 ** are accessing the same database connection simultaneously on multiple 6996 ** threads should mutex-protect calls to this API and should make their own 6997 ** private copy of the result prior to releasing the mutex. 6998 */ 6999 SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N); 7000 7001 /* 7002 ** CAPI3REF: Return The Filename For A Database Connection 7003 ** METHOD: sqlite3 7004 ** 7005 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename 7006 ** associated with database N of connection D. 7007 ** ^If there is no attached database N on the database 7008 ** connection D, or if database N is a temporary or in-memory database, then 7009 ** this function will return either a NULL pointer or an empty string. 7010 ** 7011 ** ^The string value returned by this routine is owned and managed by 7012 ** the database connection. ^The value will be valid until the database N 7013 ** is [DETACH]-ed or until the database connection closes. 7014 ** 7015 ** ^The filename returned by this function is the output of the 7016 ** xFullPathname method of the [VFS]. ^In other words, the filename 7017 ** will be an absolute pathname, even if the filename used 7018 ** to open the database originally was a URI or relative pathname. 7019 ** 7020 ** If the filename pointer returned by this routine is not NULL, then it 7021 ** can be used as the filename input parameter to these routines: 7022 ** <ul> 7023 ** <li> [sqlite3_uri_parameter()] 7024 ** <li> [sqlite3_uri_boolean()] 7025 ** <li> [sqlite3_uri_int64()] 7026 ** <li> [sqlite3_filename_database()] 7027 ** <li> [sqlite3_filename_journal()] 7028 ** <li> [sqlite3_filename_wal()] 7029 ** </ul> 7030 */ 7031 SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName); 7032 7033 /* 7034 ** CAPI3REF: Determine if a database is read-only 7035 ** METHOD: sqlite3 7036 ** 7037 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N 7038 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not 7039 ** the name of a database on connection D. 7040 */ 7041 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); 7042 7043 /* 7044 ** CAPI3REF: Determine the transaction state of a database 7045 ** METHOD: sqlite3 7046 ** 7047 ** ^The sqlite3_txn_state(D,S) interface returns the current 7048 ** [transaction state] of schema S in database connection D. ^If S is NULL, 7049 ** then the highest transaction state of any schema on database connection D 7050 ** is returned. Transaction states are (in order of lowest to highest): 7051 ** <ol> 7052 ** <li value="0"> SQLITE_TXN_NONE 7053 ** <li value="1"> SQLITE_TXN_READ 7054 ** <li value="2"> SQLITE_TXN_WRITE 7055 ** </ol> 7056 ** ^If the S argument to sqlite3_txn_state(D,S) is not the name of 7057 ** a valid schema, then -1 is returned. 7058 */ 7059 SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema); 7060 7061 /* 7062 ** CAPI3REF: Allowed return values from sqlite3_txn_state() 7063 ** KEYWORDS: {transaction state} 7064 ** 7065 ** These constants define the current transaction state of a database file. 7066 ** ^The [sqlite3_txn_state(D,S)] interface returns one of these 7067 ** constants in order to describe the transaction state of schema S 7068 ** in [database connection] D. 7069 ** 7070 ** <dl> 7071 ** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt> 7072 ** <dd>The SQLITE_TXN_NONE state means that no transaction is currently 7073 ** pending.</dd> 7074 ** 7075 ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt> 7076 ** <dd>The SQLITE_TXN_READ state means that the database is currently 7077 ** in a read transaction. Content has been read from the database file 7078 ** but nothing in the database file has changed. The transaction state 7079 ** will be advanced to SQLITE_TXN_WRITE if any changes occur and there are 7080 ** no other conflicting concurrent write transactions. The transaction 7081 ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or 7082 ** [COMMIT].</dd> 7083 ** 7084 ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt> 7085 ** <dd>The SQLITE_TXN_WRITE state means that the database is currently 7086 ** in a write transaction. Content has been written to the database file 7087 ** but has not yet committed. The transaction state will change to 7088 ** SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd> 7089 */ 7090 #define SQLITE_TXN_NONE 0 7091 #define SQLITE_TXN_READ 1 7092 #define SQLITE_TXN_WRITE 2 7093 7094 /* 7095 ** CAPI3REF: Find the next prepared statement 7096 ** METHOD: sqlite3 7097 ** 7098 ** ^This interface returns a pointer to the next [prepared statement] after 7099 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 7100 ** then this interface returns a pointer to the first prepared statement 7101 ** associated with the database connection pDb. ^If no prepared statement 7102 ** satisfies the conditions of this routine, it returns NULL. 7103 ** 7104 ** The [database connection] pointer D in a call to 7105 ** [sqlite3_next_stmt(D,S)] must refer to an open database 7106 ** connection and in particular must not be a NULL pointer. 7107 */ 7108 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); 7109 7110 /* 7111 ** CAPI3REF: Commit And Rollback Notification Callbacks 7112 ** METHOD: sqlite3 7113 ** 7114 ** ^The sqlite3_commit_hook() interface registers a callback 7115 ** function to be invoked whenever a transaction is [COMMIT | committed]. 7116 ** ^Any callback set by a previous call to sqlite3_commit_hook() 7117 ** for the same database connection is overridden. 7118 ** ^The sqlite3_rollback_hook() interface registers a callback 7119 ** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. 7120 ** ^Any callback set by a previous call to sqlite3_rollback_hook() 7121 ** for the same database connection is overridden. 7122 ** ^The pArg argument is passed through to the callback. 7123 ** ^If the callback on a commit hook function returns non-zero, 7124 ** then the commit is converted into a rollback. 7125 ** 7126 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 7127 ** return the P argument from the previous call of the same function 7128 ** on the same [database connection] D, or NULL for 7129 ** the first call for each function on D. 7130 ** 7131 ** The commit and rollback hook callbacks are not reentrant. 7132 ** The callback implementation must not do anything that will modify 7133 ** the database connection that invoked the callback. Any actions 7134 ** to modify the database connection must be deferred until after the 7135 ** completion of the [sqlite3_step()] call that triggered the commit 7136 ** or rollback hook in the first place. 7137 ** Note that running any other SQL statements, including SELECT statements, 7138 ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify 7139 ** the database connections for the meaning of "modify" in this paragraph. 7140 ** 7141 ** ^Registering a NULL function disables the callback. 7142 ** 7143 ** ^When the commit hook callback routine returns zero, the [COMMIT] 7144 ** operation is allowed to continue normally. ^If the commit hook 7145 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 7146 ** ^The rollback hook is invoked on a rollback that results from a commit 7147 ** hook returning non-zero, just as it would be with any other rollback. 7148 ** 7149 ** ^For the purposes of this API, a transaction is said to have been 7150 ** rolled back if an explicit "ROLLBACK" statement is executed, or 7151 ** an error or constraint causes an implicit rollback to occur. 7152 ** ^The rollback callback is not invoked if a transaction is 7153 ** automatically rolled back because the database connection is closed. 7154 ** 7155 ** See also the [sqlite3_update_hook()] interface. 7156 */ 7157 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); 7158 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); 7159 7160 /* 7161 ** CAPI3REF: Autovacuum Compaction Amount Callback 7162 ** METHOD: sqlite3 7163 ** 7164 ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback 7165 ** function C that is invoked prior to each autovacuum of the database 7166 ** file. ^The callback is passed a copy of the generic data pointer (P), 7167 ** the schema-name of the attached database that is being autovacuumed, 7168 ** the size of the database file in pages, the number of free pages, 7169 ** and the number of bytes per page, respectively. The callback should 7170 ** return the number of free pages that should be removed by the 7171 ** autovacuum. ^If the callback returns zero, then no autovacuum happens. 7172 ** ^If the value returned is greater than or equal to the number of 7173 ** free pages, then a complete autovacuum happens. 7174 ** 7175 ** <p>^If there are multiple ATTACH-ed database files that are being 7176 ** modified as part of a transaction commit, then the autovacuum pages 7177 ** callback is invoked separately for each file. 7178 ** 7179 ** <p><b>The callback is not reentrant.</b> The callback function should 7180 ** not attempt to invoke any other SQLite interface. If it does, bad 7181 ** things may happen, including segmentation faults and corrupt database 7182 ** files. The callback function should be a simple function that 7183 ** does some arithmetic on its input parameters and returns a result. 7184 ** 7185 ** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional 7186 ** destructor for the P parameter. ^If X is not NULL, then X(P) is 7187 ** invoked whenever the database connection closes or when the callback 7188 ** is overwritten by another invocation of sqlite3_autovacuum_pages(). 7189 ** 7190 ** <p>^There is only one autovacuum pages callback per database connection. 7191 ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all 7192 ** previous invocations for that database connection. ^If the callback 7193 ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer, 7194 ** then the autovacuum steps callback is canceled. The return value 7195 ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might 7196 ** be some other error code if something goes wrong. The current 7197 ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other 7198 ** return codes might be added in future releases. 7199 ** 7200 ** <p>If no autovacuum pages callback is specified (the usual case) or 7201 ** a NULL pointer is provided for the callback, 7202 ** then the default behavior is to vacuum all free pages. So, in other 7203 ** words, the default behavior is the same as if the callback function 7204 ** were something like this: 7205 ** 7206 ** <blockquote><pre> 7207 ** unsigned int demonstration_autovac_pages_callback( 7208 ** void *pClientData, 7209 ** const char *zSchema, 7210 ** unsigned int nDbPage, 7211 ** unsigned int nFreePage, 7212 ** unsigned int nBytePerPage 7213 ** ){ 7214 ** return nFreePage; 7215 ** } 7216 ** </pre></blockquote> 7217 */ 7218 SQLITE_API int sqlite3_autovacuum_pages( 7219 sqlite3 *db, 7220 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int), 7221 void*, 7222 void(*)(void*) 7223 ); 7224 7225 7226 /* 7227 ** CAPI3REF: Data Change Notification Callbacks 7228 ** METHOD: sqlite3 7229 ** 7230 ** ^The sqlite3_update_hook() interface registers a callback function 7231 ** with the [database connection] identified by the first argument 7232 ** to be invoked whenever a row is updated, inserted or deleted in 7233 ** a [rowid table]. 7234 ** ^Any callback set by a previous call to this function 7235 ** for the same database connection is overridden. 7236 ** 7237 ** ^The second argument is a pointer to the function to invoke when a 7238 ** row is updated, inserted or deleted in a rowid table. 7239 ** ^The update hook is disabled by invoking sqlite3_update_hook() 7240 ** with a NULL pointer as the second parameter. 7241 ** ^The first argument to the callback is a copy of the third argument 7242 ** to sqlite3_update_hook(). 7243 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], 7244 ** or [SQLITE_UPDATE], depending on the operation that caused the callback 7245 ** to be invoked. 7246 ** ^The third and fourth arguments to the callback contain pointers to the 7247 ** database and table name containing the affected row. 7248 ** ^The final callback parameter is the [rowid] of the row. 7249 ** ^In the case of an update, this is the [rowid] after the update takes place. 7250 ** 7251 ** ^(The update hook is not invoked when internal system tables are 7252 ** modified (i.e. sqlite_sequence).)^ 7253 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. 7254 ** 7255 ** ^In the current implementation, the update hook 7256 ** is not invoked when conflicting rows are deleted because of an 7257 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook 7258 ** invoked when rows are deleted using the [truncate optimization]. 7259 ** The exceptions defined in this paragraph might change in a future 7260 ** release of SQLite. 7261 ** 7262 ** Whether the update hook is invoked before or after the 7263 ** corresponding change is currently unspecified and may differ 7264 ** depending on the type of change. Do not rely on the order of the 7265 ** hook call with regards to the final result of the operation which 7266 ** triggers the hook. 7267 ** 7268 ** The update hook implementation must not do anything that will modify 7269 ** the database connection that invoked the update hook. Any actions 7270 ** to modify the database connection must be deferred until after the 7271 ** completion of the [sqlite3_step()] call that triggered the update hook. 7272 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 7273 ** database connections for the meaning of "modify" in this paragraph. 7274 ** 7275 ** ^The sqlite3_update_hook(D,C,P) function 7276 ** returns the P argument from the previous call 7277 ** on the same [database connection] D, or NULL for 7278 ** the first call on D. 7279 ** 7280 ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()], 7281 ** and [sqlite3_preupdate_hook()] interfaces. 7282 */ 7283 SQLITE_API void *sqlite3_update_hook( 7284 sqlite3*, 7285 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 7286 void* 7287 ); 7288 7289 /* 7290 ** CAPI3REF: Enable Or Disable Shared Pager Cache 7291 ** 7292 ** ^(This routine enables or disables the sharing of the database cache 7293 ** and schema data structures between [database connection | connections] 7294 ** to the same database. Sharing is enabled if the argument is true 7295 ** and disabled if the argument is false.)^ 7296 ** 7297 ** This interface is omitted if SQLite is compiled with 7298 ** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE] 7299 ** compile-time option is recommended because the 7300 ** [use of shared cache mode is discouraged]. 7301 ** 7302 ** ^Cache sharing is enabled and disabled for an entire process. 7303 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]). 7304 ** In prior versions of SQLite, 7305 ** sharing was enabled or disabled for each thread separately. 7306 ** 7307 ** ^(The cache sharing mode set by this interface effects all subsequent 7308 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. 7309 ** Existing database connections continue to use the sharing mode 7310 ** that was in effect at the time they were opened.)^ 7311 ** 7312 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled 7313 ** successfully. An [error code] is returned otherwise.)^ 7314 ** 7315 ** ^Shared cache is disabled by default. It is recommended that it stay 7316 ** that way. In other words, do not use this routine. This interface 7317 ** continues to be provided for historical compatibility, but its use is 7318 ** discouraged. Any use of shared cache is discouraged. If shared cache 7319 ** must be used, it is recommended that shared cache only be enabled for 7320 ** individual database connections using the [sqlite3_open_v2()] interface 7321 ** with the [SQLITE_OPEN_SHAREDCACHE] flag. 7322 ** 7323 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 7324 ** and will always return SQLITE_MISUSE. On those systems, 7325 ** shared cache mode should be enabled per-database connection via 7326 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE]. 7327 ** 7328 ** This interface is threadsafe on processors where writing a 7329 ** 32-bit integer is atomic. 7330 ** 7331 ** See Also: [SQLite Shared-Cache Mode] 7332 */ 7333 SQLITE_API int sqlite3_enable_shared_cache(int); 7334 7335 /* 7336 ** CAPI3REF: Attempt To Free Heap Memory 7337 ** 7338 ** ^The sqlite3_release_memory() interface attempts to free N bytes 7339 ** of heap memory by deallocating non-essential memory allocations 7340 ** held by the database library. Memory used to cache database 7341 ** pages to improve performance is an example of non-essential memory. 7342 ** ^sqlite3_release_memory() returns the number of bytes actually freed, 7343 ** which might be more or less than the amount requested. 7344 ** ^The sqlite3_release_memory() routine is a no-op returning zero 7345 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 7346 ** 7347 ** See also: [sqlite3_db_release_memory()] 7348 */ 7349 SQLITE_API int sqlite3_release_memory(int); 7350 7351 /* 7352 ** CAPI3REF: Free Memory Used By A Database Connection 7353 ** METHOD: sqlite3 7354 ** 7355 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap 7356 ** memory as possible from database connection D. Unlike the 7357 ** [sqlite3_release_memory()] interface, this interface is in effect even 7358 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is 7359 ** omitted. 7360 ** 7361 ** See also: [sqlite3_release_memory()] 7362 */ 7363 SQLITE_API int sqlite3_db_release_memory(sqlite3*); 7364 7365 /* 7366 ** CAPI3REF: Impose A Limit On Heap Size 7367 ** 7368 ** These interfaces impose limits on the amount of heap memory that will be 7369 ** used by all database connections within a single process. 7370 ** 7371 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 7372 ** soft limit on the amount of heap memory that may be allocated by SQLite. 7373 ** ^SQLite strives to keep heap memory utilization below the soft heap 7374 ** limit by reducing the number of pages held in the page cache 7375 ** as heap memory usages approaches the limit. 7376 ** ^The soft heap limit is "soft" because even though SQLite strives to stay 7377 ** below the limit, it will exceed the limit rather than generate 7378 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit 7379 ** is advisory only. 7380 ** 7381 ** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of 7382 ** N bytes on the amount of memory that will be allocated. ^The 7383 ** sqlite3_hard_heap_limit64(N) interface is similar to 7384 ** sqlite3_soft_heap_limit64(N) except that memory allocations will fail 7385 ** when the hard heap limit is reached. 7386 ** 7387 ** ^The return value from both sqlite3_soft_heap_limit64() and 7388 ** sqlite3_hard_heap_limit64() is the size of 7389 ** the heap limit prior to the call, or negative in the case of an 7390 ** error. ^If the argument N is negative 7391 ** then no change is made to the heap limit. Hence, the current 7392 ** size of heap limits can be determined by invoking 7393 ** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1). 7394 ** 7395 ** ^Setting the heap limits to zero disables the heap limiter mechanism. 7396 ** 7397 ** ^The soft heap limit may not be greater than the hard heap limit. 7398 ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N) 7399 ** is invoked with a value of N that is greater than the hard heap limit, 7400 ** the soft heap limit is set to the value of the hard heap limit. 7401 ** ^The soft heap limit is automatically enabled whenever the hard heap 7402 ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and 7403 ** the soft heap limit is outside the range of 1..N, then the soft heap 7404 ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the 7405 ** hard heap limit is enabled makes the soft heap limit equal to the 7406 ** hard heap limit. 7407 ** 7408 ** The memory allocation limits can also be adjusted using 7409 ** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit]. 7410 ** 7411 ** ^(The heap limits are not enforced in the current implementation 7412 ** if one or more of following conditions are true: 7413 ** 7414 ** <ul> 7415 ** <li> The limit value is set to zero. 7416 ** <li> Memory accounting is disabled using a combination of the 7417 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 7418 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 7419 ** <li> An alternative page cache implementation is specified using 7420 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...). 7421 ** <li> The page cache allocates from its own memory pool supplied 7422 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 7423 ** from the heap. 7424 ** </ul>)^ 7425 ** 7426 ** The circumstances under which SQLite will enforce the heap limits may 7427 ** change in future releases of SQLite. 7428 */ 7429 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); 7430 SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N); 7431 7432 /* 7433 ** CAPI3REF: Deprecated Soft Heap Limit Interface 7434 ** DEPRECATED 7435 ** 7436 ** This is a deprecated version of the [sqlite3_soft_heap_limit64()] 7437 ** interface. This routine is provided for historical compatibility 7438 ** only. All new applications should use the 7439 ** [sqlite3_soft_heap_limit64()] interface rather than this one. 7440 */ 7441 SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); 7442 7443 7444 /* 7445 ** CAPI3REF: Extract Metadata About A Column Of A Table 7446 ** METHOD: sqlite3 7447 ** 7448 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns 7449 ** information about column C of table T in database D 7450 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata() 7451 ** interface returns SQLITE_OK and fills in the non-NULL pointers in 7452 ** the final five arguments with appropriate values if the specified 7453 ** column exists. ^The sqlite3_table_column_metadata() interface returns 7454 ** SQLITE_ERROR if the specified column does not exist. 7455 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a 7456 ** NULL pointer, then this routine simply checks for the existence of the 7457 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it 7458 ** does not. If the table name parameter T in a call to 7459 ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is 7460 ** undefined behavior. 7461 ** 7462 ** ^The column is identified by the second, third and fourth parameters to 7463 ** this function. ^(The second parameter is either the name of the database 7464 ** (i.e. "main", "temp", or an attached database) containing the specified 7465 ** table or NULL.)^ ^If it is NULL, then all attached databases are searched 7466 ** for the table using the same algorithm used by the database engine to 7467 ** resolve unqualified table references. 7468 ** 7469 ** ^The third and fourth parameters to this function are the table and column 7470 ** name of the desired column, respectively. 7471 ** 7472 ** ^Metadata is returned by writing to the memory locations passed as the 5th 7473 ** and subsequent parameters to this function. ^Any of these arguments may be 7474 ** NULL, in which case the corresponding element of metadata is omitted. 7475 ** 7476 ** ^(<blockquote> 7477 ** <table border="1"> 7478 ** <tr><th> Parameter <th> Output<br>Type <th> Description 7479 ** 7480 ** <tr><td> 5th <td> const char* <td> Data type 7481 ** <tr><td> 6th <td> const char* <td> Name of default collation sequence 7482 ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint 7483 ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY 7484 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] 7485 ** </table> 7486 ** </blockquote>)^ 7487 ** 7488 ** ^The memory pointed to by the character pointers returned for the 7489 ** declaration type and collation sequence is valid until the next 7490 ** call to any SQLite API function. 7491 ** 7492 ** ^If the specified table is actually a view, an [error code] is returned. 7493 ** 7494 ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table 7495 ** is not a [WITHOUT ROWID] table and an 7496 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output 7497 ** parameters are set for the explicitly declared column. ^(If there is no 7498 ** [INTEGER PRIMARY KEY] column, then the outputs 7499 ** for the [rowid] are set as follows: 7500 ** 7501 ** <pre> 7502 ** data type: "INTEGER" 7503 ** collation sequence: "BINARY" 7504 ** not null: 0 7505 ** primary key: 1 7506 ** auto increment: 0 7507 ** </pre>)^ 7508 ** 7509 ** ^This function causes all database schemas to be read from disk and 7510 ** parsed, if that has not already been done, and returns an error if 7511 ** any errors are encountered while loading the schema. 7512 */ 7513 SQLITE_API int sqlite3_table_column_metadata( 7514 sqlite3 *db, /* Connection handle */ 7515 const char *zDbName, /* Database name or NULL */ 7516 const char *zTableName, /* Table name */ 7517 const char *zColumnName, /* Column name */ 7518 char const **pzDataType, /* OUTPUT: Declared data type */ 7519 char const **pzCollSeq, /* OUTPUT: Collation sequence name */ 7520 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ 7521 int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 7522 int *pAutoinc /* OUTPUT: True if column is auto-increment */ 7523 ); 7524 7525 /* 7526 ** CAPI3REF: Load An Extension 7527 ** METHOD: sqlite3 7528 ** 7529 ** ^This interface loads an SQLite extension library from the named file. 7530 ** 7531 ** ^The sqlite3_load_extension() interface attempts to load an 7532 ** [SQLite extension] library contained in the file zFile. If 7533 ** the file cannot be loaded directly, attempts are made to load 7534 ** with various operating-system specific filename extensions added. 7535 ** So for example, if "samplelib" cannot be loaded, then names like 7536 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might 7537 ** be tried also. 7538 ** 7539 ** ^The entry point is zProc. 7540 ** ^(zProc may be 0, in which case SQLite will try to come up with an 7541 ** entry point name on its own. It first tries "sqlite3_extension_init". 7542 ** If that does not work, it tries names of the form "sqlite3_X_init" 7543 ** where X consists of the lower-case equivalent of all ASCII alphabetic 7544 ** characters or all ASCII alphanumeric characters in the filename from 7545 ** the last "/" to the first following "." and omitting any initial "lib".)^ 7546 ** ^The sqlite3_load_extension() interface returns 7547 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. 7548 ** ^If an error occurs and pzErrMsg is not 0, then the 7549 ** [sqlite3_load_extension()] interface shall attempt to 7550 ** fill *pzErrMsg with error message text stored in memory 7551 ** obtained from [sqlite3_malloc()]. The calling function 7552 ** should free this memory by calling [sqlite3_free()]. 7553 ** 7554 ** ^Extension loading must be enabled using 7555 ** [sqlite3_enable_load_extension()] or 7556 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL) 7557 ** prior to calling this API, 7558 ** otherwise an error will be returned. 7559 ** 7560 ** <b>Security warning:</b> It is recommended that the 7561 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this 7562 ** interface. The use of the [sqlite3_enable_load_extension()] interface 7563 ** should be avoided. This will keep the SQL function [load_extension()] 7564 ** disabled and prevent SQL injections from giving attackers 7565 ** access to extension loading capabilities. 7566 ** 7567 ** See also the [load_extension() SQL function]. 7568 */ 7569 SQLITE_API int sqlite3_load_extension( 7570 sqlite3 *db, /* Load the extension into this database connection */ 7571 const char *zFile, /* Name of the shared library containing extension */ 7572 const char *zProc, /* Entry point. Derived from zFile if 0 */ 7573 char **pzErrMsg /* Put error message here if not 0 */ 7574 ); 7575 7576 /* 7577 ** CAPI3REF: Enable Or Disable Extension Loading 7578 ** METHOD: sqlite3 7579 ** 7580 ** ^So as not to open security holes in older applications that are 7581 ** unprepared to deal with [extension loading], and as a means of disabling 7582 ** [extension loading] while evaluating user-entered SQL, the following API 7583 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. 7584 ** 7585 ** ^Extension loading is off by default. 7586 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 7587 ** to turn extension loading on and call it with onoff==0 to turn 7588 ** it back off again. 7589 ** 7590 ** ^This interface enables or disables both the C-API 7591 ** [sqlite3_load_extension()] and the SQL function [load_extension()]. 7592 ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..) 7593 ** to enable or disable only the C-API.)^ 7594 ** 7595 ** <b>Security warning:</b> It is recommended that extension loading 7596 ** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method 7597 ** rather than this interface, so the [load_extension()] SQL function 7598 ** remains disabled. This will prevent SQL injections from giving attackers 7599 ** access to extension loading capabilities. 7600 */ 7601 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); 7602 7603 /* 7604 ** CAPI3REF: Automatically Load Statically Linked Extensions 7605 ** 7606 ** ^This interface causes the xEntryPoint() function to be invoked for 7607 ** each new [database connection] that is created. The idea here is that 7608 ** xEntryPoint() is the entry point for a statically linked [SQLite extension] 7609 ** that is to be automatically loaded into all new database connections. 7610 ** 7611 ** ^(Even though the function prototype shows that xEntryPoint() takes 7612 ** no arguments and returns void, SQLite invokes xEntryPoint() with three 7613 ** arguments and expects an integer result as if the signature of the 7614 ** entry point were as follows: 7615 ** 7616 ** <blockquote><pre> 7617 ** int xEntryPoint( 7618 ** sqlite3 *db, 7619 ** char **pzErrMsg, 7620 ** const struct sqlite3_api_routines *pThunk 7621 ** ); 7622 ** </pre></blockquote>)^ 7623 ** 7624 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg 7625 ** point to an appropriate error message (obtained from [sqlite3_mprintf()]) 7626 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg 7627 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke 7628 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any 7629 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], 7630 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. 7631 ** 7632 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already 7633 ** on the list of automatic extensions is a harmless no-op. ^No entry point 7634 ** will be called more than once for each database connection that is opened. 7635 ** 7636 ** See also: [sqlite3_reset_auto_extension()] 7637 ** and [sqlite3_cancel_auto_extension()] 7638 */ 7639 SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void)); 7640 7641 /* 7642 ** CAPI3REF: Cancel Automatic Extension Loading 7643 ** 7644 ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the 7645 ** initialization routine X that was registered using a prior call to 7646 ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)] 7647 ** routine returns 1 if initialization routine X was successfully 7648 ** unregistered and it returns 0 if X was not on the list of initialization 7649 ** routines. 7650 */ 7651 SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void)); 7652 7653 /* 7654 ** CAPI3REF: Reset Automatic Extension Loading 7655 ** 7656 ** ^This interface disables all automatic extensions previously 7657 ** registered using [sqlite3_auto_extension()]. 7658 */ 7659 SQLITE_API void sqlite3_reset_auto_extension(void); 7660 7661 /* 7662 ** Structures used by the virtual table interface 7663 */ 7664 typedef struct sqlite3_vtab sqlite3_vtab; 7665 typedef struct sqlite3_index_info sqlite3_index_info; 7666 typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; 7667 typedef struct sqlite3_module sqlite3_module; 7668 7669 /* 7670 ** CAPI3REF: Virtual Table Object 7671 ** KEYWORDS: sqlite3_module {virtual table module} 7672 ** 7673 ** This structure, sometimes called a "virtual table module", 7674 ** defines the implementation of a [virtual table]. 7675 ** This structure consists mostly of methods for the module. 7676 ** 7677 ** ^A virtual table module is created by filling in a persistent 7678 ** instance of this structure and passing a pointer to that instance 7679 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. 7680 ** ^The registration remains valid until it is replaced by a different 7681 ** module or until the [database connection] closes. The content 7682 ** of this structure must not change while it is registered with 7683 ** any database connection. 7684 */ 7685 struct sqlite3_module { 7686 int iVersion; 7687 int (*xCreate)(sqlite3*, void *pAux, 7688 int argc, const char *const*argv, 7689 sqlite3_vtab **ppVTab, char**); 7690 int (*xConnect)(sqlite3*, void *pAux, 7691 int argc, const char *const*argv, 7692 sqlite3_vtab **ppVTab, char**); 7693 int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); 7694 int (*xDisconnect)(sqlite3_vtab *pVTab); 7695 int (*xDestroy)(sqlite3_vtab *pVTab); 7696 int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); 7697 int (*xClose)(sqlite3_vtab_cursor*); 7698 int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, 7699 int argc, sqlite3_value **argv); 7700 int (*xNext)(sqlite3_vtab_cursor*); 7701 int (*xEof)(sqlite3_vtab_cursor*); 7702 int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); 7703 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); 7704 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); 7705 int (*xBegin)(sqlite3_vtab *pVTab); 7706 int (*xSync)(sqlite3_vtab *pVTab); 7707 int (*xCommit)(sqlite3_vtab *pVTab); 7708 int (*xRollback)(sqlite3_vtab *pVTab); 7709 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, 7710 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), 7711 void **ppArg); 7712 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); 7713 /* The methods above are in version 1 of the sqlite_module object. Those 7714 ** below are for version 2 and greater. */ 7715 int (*xSavepoint)(sqlite3_vtab *pVTab, int); 7716 int (*xRelease)(sqlite3_vtab *pVTab, int); 7717 int (*xRollbackTo)(sqlite3_vtab *pVTab, int); 7718 /* The methods above are in versions 1 and 2 of the sqlite_module object. 7719 ** Those below are for version 3 and greater. */ 7720 int (*xShadowName)(const char*); 7721 /* The methods above are in versions 1 through 3 of the sqlite_module object. 7722 ** Those below are for version 4 and greater. */ 7723 int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema, 7724 const char *zTabName, int mFlags, char **pzErr); 7725 }; 7726 7727 /* 7728 ** CAPI3REF: Virtual Table Indexing Information 7729 ** KEYWORDS: sqlite3_index_info 7730 ** 7731 ** The sqlite3_index_info structure and its substructures is used as part 7732 ** of the [virtual table] interface to 7733 ** pass information into and receive the reply from the [xBestIndex] 7734 ** method of a [virtual table module]. The fields under **Inputs** are the 7735 ** inputs to xBestIndex and are read-only. xBestIndex inserts its 7736 ** results into the **Outputs** fields. 7737 ** 7738 ** ^(The aConstraint[] array records WHERE clause constraints of the form: 7739 ** 7740 ** <blockquote>column OP expr</blockquote> 7741 ** 7742 ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is 7743 ** stored in aConstraint[].op using one of the 7744 ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ 7745 ** ^(The index of the column is stored in 7746 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the 7747 ** expr on the right-hand side can be evaluated (and thus the constraint 7748 ** is usable) and false if it cannot.)^ 7749 ** 7750 ** ^The optimizer automatically inverts terms of the form "expr OP column" 7751 ** and makes other simplifications to the WHERE clause in an attempt to 7752 ** get as many WHERE clause terms into the form shown above as possible. 7753 ** ^The aConstraint[] array only reports WHERE clause terms that are 7754 ** relevant to the particular virtual table being queried. 7755 ** 7756 ** ^Information about the ORDER BY clause is stored in aOrderBy[]. 7757 ** ^Each term of aOrderBy records a column of the ORDER BY clause. 7758 ** 7759 ** The colUsed field indicates which columns of the virtual table may be 7760 ** required by the current scan. Virtual table columns are numbered from 7761 ** zero in the order in which they appear within the CREATE TABLE statement 7762 ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), 7763 ** the corresponding bit is set within the colUsed mask if the column may be 7764 ** required by SQLite. If the table has at least 64 columns and any column 7765 ** to the right of the first 63 is required, then bit 63 of colUsed is also 7766 ** set. In other words, column iCol may be required if the expression 7767 ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to 7768 ** non-zero. 7769 ** 7770 ** The [xBestIndex] method must fill aConstraintUsage[] with information 7771 ** about what parameters to pass to xFilter. ^If argvIndex>0 then 7772 ** the right-hand side of the corresponding aConstraint[] is evaluated 7773 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit 7774 ** is true, then the constraint is assumed to be fully handled by the 7775 ** virtual table and might not be checked again by the byte code.)^ ^(The 7776 ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag 7777 ** is left in its default setting of false, the constraint will always be 7778 ** checked separately in byte code. If the omit flag is changed to true, then 7779 ** the constraint may or may not be checked in byte code. In other words, 7780 ** when the omit flag is true there is no guarantee that the constraint will 7781 ** not be checked again using byte code.)^ 7782 ** 7783 ** ^The idxNum and idxStr values are recorded and passed into the 7784 ** [xFilter] method. 7785 ** ^[sqlite3_free()] is used to free idxStr if and only if 7786 ** needToFreeIdxStr is true. 7787 ** 7788 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in 7789 ** the correct order to satisfy the ORDER BY clause so that no separate 7790 ** sorting step is required. 7791 ** 7792 ** ^The estimatedCost value is an estimate of the cost of a particular 7793 ** strategy. A cost of N indicates that the cost of the strategy is similar 7794 ** to a linear scan of an SQLite table with N rows. A cost of log(N) 7795 ** indicates that the expense of the operation is similar to that of a 7796 ** binary search on a unique indexed field of an SQLite table with N rows. 7797 ** 7798 ** ^The estimatedRows value is an estimate of the number of rows that 7799 ** will be returned by the strategy. 7800 ** 7801 ** The xBestIndex method may optionally populate the idxFlags field with a 7802 ** mask of SQLITE_INDEX_SCAN_* flags. One such flag is 7803 ** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN] 7804 ** output to show the idxNum as hex instead of as decimal. Another flag is 7805 ** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will 7806 ** return at most one row. 7807 ** 7808 ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then 7809 ** SQLite also assumes that if a call to the xUpdate() method is made as 7810 ** part of the same statement to delete or update a virtual table row and the 7811 ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback 7812 ** any database changes. In other words, if the xUpdate() returns 7813 ** SQLITE_CONSTRAINT, the database contents must be exactly as they were 7814 ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not 7815 ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by 7816 ** the xUpdate method are automatically rolled back by SQLite. 7817 ** 7818 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info 7819 ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]). 7820 ** If a virtual table extension is 7821 ** used with an SQLite version earlier than 3.8.2, the results of attempting 7822 ** to read or write the estimatedRows field are undefined (but are likely 7823 ** to include crashing the application). The estimatedRows field should 7824 ** therefore only be used if [sqlite3_libversion_number()] returns a 7825 ** value greater than or equal to 3008002. Similarly, the idxFlags field 7826 ** was added for [version 3.9.0] ([dateof:3.9.0]). 7827 ** It may therefore only be used if 7828 ** sqlite3_libversion_number() returns a value greater than or equal to 7829 ** 3009000. 7830 */ 7831 struct sqlite3_index_info { 7832 /* Inputs */ 7833 int nConstraint; /* Number of entries in aConstraint */ 7834 struct sqlite3_index_constraint { 7835 int iColumn; /* Column constrained. -1 for ROWID */ 7836 unsigned char op; /* Constraint operator */ 7837 unsigned char usable; /* True if this constraint is usable */ 7838 int iTermOffset; /* Used internally - xBestIndex should ignore */ 7839 } *aConstraint; /* Table of WHERE clause constraints */ 7840 int nOrderBy; /* Number of terms in the ORDER BY clause */ 7841 struct sqlite3_index_orderby { 7842 int iColumn; /* Column number */ 7843 unsigned char desc; /* True for DESC. False for ASC. */ 7844 } *aOrderBy; /* The ORDER BY clause */ 7845 /* Outputs */ 7846 struct sqlite3_index_constraint_usage { 7847 int argvIndex; /* if >0, constraint is part of argv to xFilter */ 7848 unsigned char omit; /* Do not code a test for this constraint */ 7849 } *aConstraintUsage; 7850 int idxNum; /* Number used to identify the index */ 7851 char *idxStr; /* String, possibly obtained from sqlite3_malloc */ 7852 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 7853 int orderByConsumed; /* True if output is already ordered */ 7854 double estimatedCost; /* Estimated cost of using this index */ 7855 /* Fields below are only available in SQLite 3.8.2 and later */ 7856 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ 7857 /* Fields below are only available in SQLite 3.9.0 and later */ 7858 int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */ 7859 /* Fields below are only available in SQLite 3.10.0 and later */ 7860 sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */ 7861 }; 7862 7863 /* 7864 ** CAPI3REF: Virtual Table Scan Flags 7865 ** 7866 ** Virtual table implementations are allowed to set the 7867 ** [sqlite3_index_info].idxFlags field to some combination of 7868 ** these bits. 7869 */ 7870 #define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */ 7871 #define SQLITE_INDEX_SCAN_HEX 0x00000002 /* Display idxNum as hex */ 7872 /* in EXPLAIN QUERY PLAN */ 7873 7874 /* 7875 ** CAPI3REF: Virtual Table Constraint Operator Codes 7876 ** 7877 ** These macros define the allowed values for the 7878 ** [sqlite3_index_info].aConstraint[].op field. Each value represents 7879 ** an operator that is part of a constraint term in the WHERE clause of 7880 ** a query that uses a [virtual table]. 7881 ** 7882 ** ^The left-hand operand of the operator is given by the corresponding 7883 ** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand 7884 ** operand is the rowid. 7885 ** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET 7886 ** operators have no left-hand operand, and so for those operators the 7887 ** corresponding aConstraint[].iColumn is meaningless and should not be 7888 ** used. 7889 ** 7890 ** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through 7891 ** value 255 are reserved to represent functions that are overloaded 7892 ** by the [xFindFunction|xFindFunction method] of the virtual table 7893 ** implementation. 7894 ** 7895 ** The right-hand operands for each constraint might be accessible using 7896 ** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand 7897 ** operand is only available if it appears as a single constant literal 7898 ** in the input SQL. If the right-hand operand is another column or an 7899 ** expression (even a constant expression) or a parameter, then the 7900 ** sqlite3_vtab_rhs_value() probably will not be able to extract it. 7901 ** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and 7902 ** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand 7903 ** and hence calls to sqlite3_vtab_rhs_value() for those operators will 7904 ** always return SQLITE_NOTFOUND. 7905 ** 7906 ** The collating sequence to be used for comparison can be found using 7907 ** the [sqlite3_vtab_collation()] interface. For most real-world virtual 7908 ** tables, the collating sequence of constraints does not matter (for example 7909 ** because the constraints are numeric) and so the sqlite3_vtab_collation() 7910 ** interface is not commonly needed. 7911 */ 7912 #define SQLITE_INDEX_CONSTRAINT_EQ 2 7913 #define SQLITE_INDEX_CONSTRAINT_GT 4 7914 #define SQLITE_INDEX_CONSTRAINT_LE 8 7915 #define SQLITE_INDEX_CONSTRAINT_LT 16 7916 #define SQLITE_INDEX_CONSTRAINT_GE 32 7917 #define SQLITE_INDEX_CONSTRAINT_MATCH 64 7918 #define SQLITE_INDEX_CONSTRAINT_LIKE 65 7919 #define SQLITE_INDEX_CONSTRAINT_GLOB 66 7920 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67 7921 #define SQLITE_INDEX_CONSTRAINT_NE 68 7922 #define SQLITE_INDEX_CONSTRAINT_ISNOT 69 7923 #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70 7924 #define SQLITE_INDEX_CONSTRAINT_ISNULL 71 7925 #define SQLITE_INDEX_CONSTRAINT_IS 72 7926 #define SQLITE_INDEX_CONSTRAINT_LIMIT 73 7927 #define SQLITE_INDEX_CONSTRAINT_OFFSET 74 7928 #define SQLITE_INDEX_CONSTRAINT_FUNCTION 150 7929 7930 /* 7931 ** CAPI3REF: Register A Virtual Table Implementation 7932 ** METHOD: sqlite3 7933 ** 7934 ** ^These routines are used to register a new [virtual table module] name. 7935 ** ^Module names must be registered before 7936 ** creating a new [virtual table] using the module and before using a 7937 ** preexisting [virtual table] for the module. 7938 ** 7939 ** ^The module name is registered on the [database connection] specified 7940 ** by the first parameter. ^The name of the module is given by the 7941 ** second parameter. ^The third parameter is a pointer to 7942 ** the implementation of the [virtual table module]. ^The fourth 7943 ** parameter is an arbitrary client data pointer that is passed through 7944 ** into the [xCreate] and [xConnect] methods of the virtual table module 7945 ** when a new virtual table is being created or reinitialized. 7946 ** 7947 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which 7948 ** is a pointer to a destructor for the pClientData. ^SQLite will 7949 ** invoke the destructor function (if it is not NULL) when SQLite 7950 ** no longer needs the pClientData pointer. ^The destructor will also 7951 ** be invoked if the call to sqlite3_create_module_v2() fails. 7952 ** ^The sqlite3_create_module() 7953 ** interface is equivalent to sqlite3_create_module_v2() with a NULL 7954 ** destructor. 7955 ** 7956 ** ^If the third parameter (the pointer to the sqlite3_module object) is 7957 ** NULL then no new module is created and any existing modules with the 7958 ** same name are dropped. 7959 ** 7960 ** See also: [sqlite3_drop_modules()] 7961 */ 7962 SQLITE_API int sqlite3_create_module( 7963 sqlite3 *db, /* SQLite connection to register module with */ 7964 const char *zName, /* Name of the module */ 7965 const sqlite3_module *p, /* Methods for the module */ 7966 void *pClientData /* Client data for xCreate/xConnect */ 7967 ); 7968 SQLITE_API int sqlite3_create_module_v2( 7969 sqlite3 *db, /* SQLite connection to register module with */ 7970 const char *zName, /* Name of the module */ 7971 const sqlite3_module *p, /* Methods for the module */ 7972 void *pClientData, /* Client data for xCreate/xConnect */ 7973 void(*xDestroy)(void*) /* Module destructor function */ 7974 ); 7975 7976 /* 7977 ** CAPI3REF: Remove Unnecessary Virtual Table Implementations 7978 ** METHOD: sqlite3 7979 ** 7980 ** ^The sqlite3_drop_modules(D,L) interface removes all virtual 7981 ** table modules from database connection D except those named on list L. 7982 ** The L parameter must be either NULL or a pointer to an array of pointers 7983 ** to strings where the array is terminated by a single NULL pointer. 7984 ** ^If the L parameter is NULL, then all virtual table modules are removed. 7985 ** 7986 ** See also: [sqlite3_create_module()] 7987 */ 7988 SQLITE_API int sqlite3_drop_modules( 7989 sqlite3 *db, /* Remove modules from this connection */ 7990 const char **azKeep /* Except, do not remove the ones named here */ 7991 ); 7992 7993 /* 7994 ** CAPI3REF: Virtual Table Instance Object 7995 ** KEYWORDS: sqlite3_vtab 7996 ** 7997 ** Every [virtual table module] implementation uses a subclass 7998 ** of this object to describe a particular instance 7999 ** of the [virtual table]. Each subclass will 8000 ** be tailored to the specific needs of the module implementation. 8001 ** The purpose of this superclass is to define certain fields that are 8002 ** common to all module implementations. 8003 ** 8004 ** ^Virtual tables methods can set an error message by assigning a 8005 ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should 8006 ** take care that any prior string is freed by a call to [sqlite3_free()] 8007 ** prior to assigning a new string to zErrMsg. ^After the error message 8008 ** is delivered up to the client application, the string will be automatically 8009 ** freed by sqlite3_free() and the zErrMsg field will be zeroed. 8010 */ 8011 struct sqlite3_vtab { 8012 const sqlite3_module *pModule; /* The module for this virtual table */ 8013 int nRef; /* Number of open cursors */ 8014 char *zErrMsg; /* Error message from sqlite3_mprintf() */ 8015 /* Virtual table implementations will typically add additional fields */ 8016 }; 8017 8018 /* 8019 ** CAPI3REF: Virtual Table Cursor Object 8020 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} 8021 ** 8022 ** Every [virtual table module] implementation uses a subclass of the 8023 ** following structure to describe cursors that point into the 8024 ** [virtual table] and are used 8025 ** to loop through the virtual table. Cursors are created using the 8026 ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed 8027 ** by the [sqlite3_module.xClose | xClose] method. Cursors are used 8028 ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods 8029 ** of the module. Each module implementation will define 8030 ** the content of a cursor structure to suit its own needs. 8031 ** 8032 ** This superclass exists in order to define fields of the cursor that 8033 ** are common to all implementations. 8034 */ 8035 struct sqlite3_vtab_cursor { 8036 sqlite3_vtab *pVtab; /* Virtual table of this cursor */ 8037 /* Virtual table implementations will typically add additional fields */ 8038 }; 8039 8040 /* 8041 ** CAPI3REF: Declare The Schema Of A Virtual Table 8042 ** 8043 ** ^The [xCreate] and [xConnect] methods of a 8044 ** [virtual table module] call this interface 8045 ** to declare the format (the names and datatypes of the columns) of 8046 ** the virtual tables they implement. 8047 */ 8048 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); 8049 8050 /* 8051 ** CAPI3REF: Overload A Function For A Virtual Table 8052 ** METHOD: sqlite3 8053 ** 8054 ** ^(Virtual tables can provide alternative implementations of functions 8055 ** using the [xFindFunction] method of the [virtual table module]. 8056 ** But global versions of those functions 8057 ** must exist in order to be overloaded.)^ 8058 ** 8059 ** ^(This API makes sure a global version of a function with a particular 8060 ** name and number of parameters exists. If no such function exists 8061 ** before this API is called, a new function is created.)^ ^The implementation 8062 ** of the new function always causes an exception to be thrown. So 8063 ** the new function is not good for anything by itself. Its only 8064 ** purpose is to be a placeholder function that can be overloaded 8065 ** by a [virtual table]. 8066 */ 8067 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); 8068 8069 /* 8070 ** CAPI3REF: A Handle To An Open BLOB 8071 ** KEYWORDS: {BLOB handle} {BLOB handles} 8072 ** 8073 ** An instance of this object represents an open BLOB on which 8074 ** [sqlite3_blob_open | incremental BLOB I/O] can be performed. 8075 ** ^Objects of this type are created by [sqlite3_blob_open()] 8076 ** and destroyed by [sqlite3_blob_close()]. 8077 ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces 8078 ** can be used to read or write small subsections of the BLOB. 8079 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. 8080 */ 8081 typedef struct sqlite3_blob sqlite3_blob; 8082 8083 /* 8084 ** CAPI3REF: Open A BLOB For Incremental I/O 8085 ** METHOD: sqlite3 8086 ** CONSTRUCTOR: sqlite3_blob 8087 ** 8088 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located 8089 ** in row iRow, column zColumn, table zTable in database zDb; 8090 ** in other words, the same BLOB that would be selected by: 8091 ** 8092 ** <pre> 8093 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; 8094 ** </pre>)^ 8095 ** 8096 ** ^(Parameter zDb is not the filename that contains the database, but 8097 ** rather the symbolic name of the database. For attached databases, this is 8098 ** the name that appears after the AS keyword in the [ATTACH] statement. 8099 ** For the main database file, the database name is "main". For TEMP 8100 ** tables, the database name is "temp".)^ 8101 ** 8102 ** ^If the flags parameter is non-zero, then the BLOB is opened for read 8103 ** and write access. ^If the flags parameter is zero, the BLOB is opened for 8104 ** read-only access. 8105 ** 8106 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored 8107 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error 8108 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided 8109 ** the API is not misused, it is always safe to call [sqlite3_blob_close()] 8110 ** on *ppBlob after this function returns. 8111 ** 8112 ** This function fails with SQLITE_ERROR if any of the following are true: 8113 ** <ul> 8114 ** <li> ^(Database zDb does not exist)^, 8115 ** <li> ^(Table zTable does not exist within database zDb)^, 8116 ** <li> ^(Table zTable is a WITHOUT ROWID table)^, 8117 ** <li> ^(Column zColumn does not exist)^, 8118 ** <li> ^(Row iRow is not present in the table)^, 8119 ** <li> ^(The specified column of row iRow contains a value that is not 8120 ** a TEXT or BLOB value)^, 8121 ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE 8122 ** constraint and the blob is being opened for read/write access)^, 8123 ** <li> ^([foreign key constraints | Foreign key constraints] are enabled, 8124 ** column zColumn is part of a [child key] definition and the blob is 8125 ** being opened for read/write access)^. 8126 ** </ul> 8127 ** 8128 ** ^Unless it returns SQLITE_MISUSE, this function sets the 8129 ** [database connection] error code and message accessible via 8130 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. 8131 ** 8132 ** A BLOB referenced by sqlite3_blob_open() may be read using the 8133 ** [sqlite3_blob_read()] interface and modified by using 8134 ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a 8135 ** different row of the same table using the [sqlite3_blob_reopen()] 8136 ** interface. However, the column, table, or database of a [BLOB handle] 8137 ** cannot be changed after the [BLOB handle] is opened. 8138 ** 8139 ** ^(If the row that a BLOB handle points to is modified by an 8140 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects 8141 ** then the BLOB handle is marked as "expired". 8142 ** This is true if any column of the row is changed, even a column 8143 ** other than the one the BLOB handle is open on.)^ 8144 ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for 8145 ** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. 8146 ** ^(Changes written into a BLOB prior to the BLOB expiring are not 8147 ** rolled back by the expiration of the BLOB. Such changes will eventually 8148 ** commit if the transaction continues to completion.)^ 8149 ** 8150 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of 8151 ** the opened blob. ^The size of a blob may not be changed by this 8152 ** interface. Use the [UPDATE] SQL command to change the size of a 8153 ** blob. 8154 ** 8155 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces 8156 ** and the built-in [zeroblob] SQL function may be used to create a 8157 ** zero-filled blob to read or write using the incremental-blob interface. 8158 ** 8159 ** To avoid a resource leak, every open [BLOB handle] should eventually 8160 ** be released by a call to [sqlite3_blob_close()]. 8161 ** 8162 ** See also: [sqlite3_blob_close()], 8163 ** [sqlite3_blob_reopen()], [sqlite3_blob_read()], 8164 ** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. 8165 */ 8166 SQLITE_API int sqlite3_blob_open( 8167 sqlite3*, 8168 const char *zDb, 8169 const char *zTable, 8170 const char *zColumn, 8171 sqlite3_int64 iRow, 8172 int flags, 8173 sqlite3_blob **ppBlob 8174 ); 8175 8176 /* 8177 ** CAPI3REF: Move a BLOB Handle to a New Row 8178 ** METHOD: sqlite3_blob 8179 ** 8180 ** ^This function is used to move an existing [BLOB handle] so that it points 8181 ** to a different row of the same database table. ^The new row is identified 8182 ** by the rowid value passed as the second argument. Only the row can be 8183 ** changed. ^The database, table and column on which the blob handle is open 8184 ** remain the same. Moving an existing [BLOB handle] to a new row is 8185 ** faster than closing the existing handle and opening a new one. 8186 ** 8187 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - 8188 ** it must exist and there must be either a blob or text value stored in 8189 ** the nominated column.)^ ^If the new row is not present in the table, or if 8190 ** it does not contain a blob or text value, or if another error occurs, an 8191 ** SQLite error code is returned and the blob handle is considered aborted. 8192 ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or 8193 ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return 8194 ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle 8195 ** always returns zero. 8196 ** 8197 ** ^This function sets the database handle error code and message. 8198 */ 8199 SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); 8200 8201 /* 8202 ** CAPI3REF: Close A BLOB Handle 8203 ** DESTRUCTOR: sqlite3_blob 8204 ** 8205 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed 8206 ** unconditionally. Even if this routine returns an error code, the 8207 ** handle is still closed.)^ 8208 ** 8209 ** ^If the blob handle being closed was opened for read-write access, and if 8210 ** the database is in auto-commit mode and there are no other open read-write 8211 ** blob handles or active write statements, the current transaction is 8212 ** committed. ^If an error occurs while committing the transaction, an error 8213 ** code is returned and the transaction rolled back. 8214 ** 8215 ** Calling this function with an argument that is not a NULL pointer or an 8216 ** open blob handle results in undefined behavior. ^Calling this routine 8217 ** with a null pointer (such as would be returned by a failed call to 8218 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function 8219 ** is passed a valid open blob handle, the values returned by the 8220 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning. 8221 */ 8222 SQLITE_API int sqlite3_blob_close(sqlite3_blob *); 8223 8224 /* 8225 ** CAPI3REF: Return The Size Of An Open BLOB 8226 ** METHOD: sqlite3_blob 8227 ** 8228 ** ^Returns the size in bytes of the BLOB accessible via the 8229 ** successfully opened [BLOB handle] in its only argument. ^The 8230 ** incremental blob I/O routines can only read or overwrite existing 8231 ** blob content; they cannot change the size of a blob. 8232 ** 8233 ** This routine only works on a [BLOB handle] which has been created 8234 ** by a prior successful call to [sqlite3_blob_open()] and which has not 8235 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 8236 ** to this routine results in undefined and probably undesirable behavior. 8237 */ 8238 SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); 8239 8240 /* 8241 ** CAPI3REF: Read Data From A BLOB Incrementally 8242 ** METHOD: sqlite3_blob 8243 ** 8244 ** ^(This function is used to read data from an open [BLOB handle] into a 8245 ** caller-supplied buffer. N bytes of data are copied into buffer Z 8246 ** from the open BLOB, starting at offset iOffset.)^ 8247 ** 8248 ** ^If offset iOffset is less than N bytes from the end of the BLOB, 8249 ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is 8250 ** less than zero, [SQLITE_ERROR] is returned and no data is read. 8251 ** ^The size of the blob (and hence the maximum value of N+iOffset) 8252 ** can be determined using the [sqlite3_blob_bytes()] interface. 8253 ** 8254 ** ^An attempt to read from an expired [BLOB handle] fails with an 8255 ** error code of [SQLITE_ABORT]. 8256 ** 8257 ** ^(On success, sqlite3_blob_read() returns SQLITE_OK. 8258 ** Otherwise, an [error code] or an [extended error code] is returned.)^ 8259 ** 8260 ** This routine only works on a [BLOB handle] which has been created 8261 ** by a prior successful call to [sqlite3_blob_open()] and which has not 8262 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 8263 ** to this routine results in undefined and probably undesirable behavior. 8264 ** 8265 ** See also: [sqlite3_blob_write()]. 8266 */ 8267 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); 8268 8269 /* 8270 ** CAPI3REF: Write Data Into A BLOB Incrementally 8271 ** METHOD: sqlite3_blob 8272 ** 8273 ** ^(This function is used to write data into an open [BLOB handle] from a 8274 ** caller-supplied buffer. N bytes of data are copied from the buffer Z 8275 ** into the open BLOB, starting at offset iOffset.)^ 8276 ** 8277 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. 8278 ** Otherwise, an [error code] or an [extended error code] is returned.)^ 8279 ** ^Unless SQLITE_MISUSE is returned, this function sets the 8280 ** [database connection] error code and message accessible via 8281 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. 8282 ** 8283 ** ^If the [BLOB handle] passed as the first argument was not opened for 8284 ** writing (the flags parameter to [sqlite3_blob_open()] was zero), 8285 ** this function returns [SQLITE_READONLY]. 8286 ** 8287 ** This function may only modify the contents of the BLOB; it is 8288 ** not possible to increase the size of a BLOB using this API. 8289 ** ^If offset iOffset is less than N bytes from the end of the BLOB, 8290 ** [SQLITE_ERROR] is returned and no data is written. The size of the 8291 ** BLOB (and hence the maximum value of N+iOffset) can be determined 8292 ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less 8293 ** than zero [SQLITE_ERROR] is returned and no data is written. 8294 ** 8295 ** ^An attempt to write to an expired [BLOB handle] fails with an 8296 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred 8297 ** before the [BLOB handle] expired are not rolled back by the 8298 ** expiration of the handle, though of course those changes might 8299 ** have been overwritten by the statement that expired the BLOB handle 8300 ** or by other independent statements. 8301 ** 8302 ** This routine only works on a [BLOB handle] which has been created 8303 ** by a prior successful call to [sqlite3_blob_open()] and which has not 8304 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 8305 ** to this routine results in undefined and probably undesirable behavior. 8306 ** 8307 ** See also: [sqlite3_blob_read()]. 8308 */ 8309 SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); 8310 8311 /* 8312 ** CAPI3REF: Virtual File System Objects 8313 ** 8314 ** A virtual filesystem (VFS) is an [sqlite3_vfs] object 8315 ** that SQLite uses to interact 8316 ** with the underlying operating system. Most SQLite builds come with a 8317 ** single default VFS that is appropriate for the host computer. 8318 ** New VFSes can be registered and existing VFSes can be unregistered. 8319 ** The following interfaces are provided. 8320 ** 8321 ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. 8322 ** ^Names are case sensitive. 8323 ** ^Names are zero-terminated UTF-8 strings. 8324 ** ^If there is no match, a NULL pointer is returned. 8325 ** ^If zVfsName is NULL then the default VFS is returned. 8326 ** 8327 ** ^New VFSes are registered with sqlite3_vfs_register(). 8328 ** ^Each new VFS becomes the default VFS if the makeDflt flag is set. 8329 ** ^The same VFS can be registered multiple times without injury. 8330 ** ^To make an existing VFS into the default VFS, register it again 8331 ** with the makeDflt flag set. If two different VFSes with the 8332 ** same name are registered, the behavior is undefined. If a 8333 ** VFS is registered with a name that is NULL or an empty string, 8334 ** then the behavior is undefined. 8335 ** 8336 ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. 8337 ** ^(If the default VFS is unregistered, another VFS is chosen as 8338 ** the default. The choice for the new VFS is arbitrary.)^ 8339 */ 8340 SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); 8341 SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); 8342 SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); 8343 8344 /* 8345 ** CAPI3REF: Mutexes 8346 ** 8347 ** The SQLite core uses these routines for thread 8348 ** synchronization. Though they are intended for internal 8349 ** use by SQLite, code that links against SQLite is 8350 ** permitted to use any of these routines. 8351 ** 8352 ** The SQLite source code contains multiple implementations 8353 ** of these mutex routines. An appropriate implementation 8354 ** is selected automatically at compile-time. The following 8355 ** implementations are available in the SQLite core: 8356 ** 8357 ** <ul> 8358 ** <li> SQLITE_MUTEX_PTHREADS 8359 ** <li> SQLITE_MUTEX_W32 8360 ** <li> SQLITE_MUTEX_NOOP 8361 ** </ul> 8362 ** 8363 ** The SQLITE_MUTEX_NOOP implementation is a set of routines 8364 ** that does no real locking and is appropriate for use in 8365 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and 8366 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix 8367 ** and Windows. 8368 ** 8369 ** 8370 ** ^The sqlite3_mutex_alloc() routine allocates a new 8371 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc() 8372 ** routine returns NULL if it is unable to allocate the requested 8373 ** mutex. The argument to sqlite3_mutex_alloc() must be one of these 8374 ** integer constants: 8375 ** 8376 ** <ul> 8377 ** <li> SQLITE_MUTEX_FAST 8378 ** <li> SQLITE_MUTEX_RECURSIVE 8379 ** <li> SQLITE_MUTEX_STATIC_MAIN 8380 ** <li> SQLITE_MUTEX_STATIC_MEM 8381 ** <li> SQLITE_MUTEX_STATIC_OPEN 8382 ** <li> SQLITE_MUTEX_STATIC_PRNG 8383 ** <li> SQLITE_MUTEX_STATIC_LRU 8384 ** <li> SQLITE_MUTEX_STATIC_PMEM 8385 ** <li> SQLITE_MUTEX_STATIC_APP1 8386 ** <li> SQLITE_MUTEX_STATIC_APP2 8387 ** <li> SQLITE_MUTEX_STATIC_APP3 8388 ** <li> SQLITE_MUTEX_STATIC_VFS1 8389 ** <li> SQLITE_MUTEX_STATIC_VFS2 8390 ** <li> SQLITE_MUTEX_STATIC_VFS3 8391 ** </ul> 8392 ** 8393 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) 8394 ** cause sqlite3_mutex_alloc() to create 8395 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 8396 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 8397 ** The mutex implementation does not need to make a distinction 8398 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 8399 ** not want to. SQLite will only request a recursive mutex in 8400 ** cases where it really needs one. If a faster non-recursive mutex 8401 ** implementation is available on the host platform, the mutex subsystem 8402 ** might return such a mutex in response to SQLITE_MUTEX_FAST. 8403 ** 8404 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other 8405 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return 8406 ** a pointer to a static preexisting mutex. ^Nine static mutexes are 8407 ** used by the current version of SQLite. Future versions of SQLite 8408 ** may add additional static mutexes. Static mutexes are for internal 8409 ** use by SQLite only. Applications that use SQLite mutexes should 8410 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or 8411 ** SQLITE_MUTEX_RECURSIVE. 8412 ** 8413 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST 8414 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() 8415 ** returns a different mutex on every call. ^For the static 8416 ** mutex types, the same mutex is returned on every call that has 8417 ** the same type number. 8418 ** 8419 ** ^The sqlite3_mutex_free() routine deallocates a previously 8420 ** allocated dynamic mutex. Attempting to deallocate a static 8421 ** mutex results in undefined behavior. 8422 ** 8423 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 8424 ** to enter a mutex. ^If another thread is already within the mutex, 8425 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 8426 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] 8427 ** upon successful entry. ^(Mutexes created using 8428 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. 8429 ** In such cases, the 8430 ** mutex must be exited an equal number of times before another thread 8431 ** can enter.)^ If the same thread tries to enter any mutex other 8432 ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined. 8433 ** 8434 ** ^(Some systems (for example, Windows 95) do not support the operation 8435 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() 8436 ** will always return SQLITE_BUSY. In most cases the SQLite core only uses 8437 ** sqlite3_mutex_try() as an optimization, so this is acceptable 8438 ** behavior. The exceptions are unix builds that set the 8439 ** SQLITE_ENABLE_SETLK_TIMEOUT build option. In that case a working 8440 ** sqlite3_mutex_try() is required.)^ 8441 ** 8442 ** ^The sqlite3_mutex_leave() routine exits a mutex that was 8443 ** previously entered by the same thread. The behavior 8444 ** is undefined if the mutex is not currently entered by the 8445 ** calling thread or is not currently allocated. 8446 ** 8447 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), 8448 ** sqlite3_mutex_leave(), or sqlite3_mutex_free() is a NULL pointer, 8449 ** then any of the four routines behaves as a no-op. 8450 ** 8451 ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. 8452 */ 8453 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); 8454 SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); 8455 SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); 8456 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); 8457 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); 8458 8459 /* 8460 ** CAPI3REF: Mutex Methods Object 8461 ** 8462 ** An instance of this structure defines the low-level routines 8463 ** used to allocate and use mutexes. 8464 ** 8465 ** Usually, the default mutex implementations provided by SQLite are 8466 ** sufficient, however the application has the option of substituting a custom 8467 ** implementation for specialized deployments or systems for which SQLite 8468 ** does not provide a suitable implementation. In this case, the application 8469 ** creates and populates an instance of this structure to pass 8470 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. 8471 ** Additionally, an instance of this structure can be used as an 8472 ** output variable when querying the system for the current mutex 8473 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. 8474 ** 8475 ** ^The xMutexInit method defined by this structure is invoked as 8476 ** part of system initialization by the sqlite3_initialize() function. 8477 ** ^The xMutexInit routine is called by SQLite exactly once for each 8478 ** effective call to [sqlite3_initialize()]. 8479 ** 8480 ** ^The xMutexEnd method defined by this structure is invoked as 8481 ** part of system shutdown by the sqlite3_shutdown() function. The 8482 ** implementation of this method is expected to release all outstanding 8483 ** resources obtained by the mutex methods implementation, especially 8484 ** those obtained by the xMutexInit method. ^The xMutexEnd() 8485 ** interface is invoked exactly once for each call to [sqlite3_shutdown()]. 8486 ** 8487 ** ^(The remaining seven methods defined by this structure (xMutexAlloc, 8488 ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and 8489 ** xMutexNotheld) implement the following interfaces (respectively): 8490 ** 8491 ** <ul> 8492 ** <li> [sqlite3_mutex_alloc()] </li> 8493 ** <li> [sqlite3_mutex_free()] </li> 8494 ** <li> [sqlite3_mutex_enter()] </li> 8495 ** <li> [sqlite3_mutex_try()] </li> 8496 ** <li> [sqlite3_mutex_leave()] </li> 8497 ** <li> [sqlite3_mutex_held()] </li> 8498 ** <li> [sqlite3_mutex_notheld()] </li> 8499 ** </ul>)^ 8500 ** 8501 ** The only difference is that the public sqlite3_XXX functions enumerated 8502 ** above silently ignore any invocations that pass a NULL pointer instead 8503 ** of a valid mutex handle. The implementations of the methods defined 8504 ** by this structure are not required to handle this case. The results 8505 ** of passing a NULL pointer instead of a valid mutex handle are undefined 8506 ** (i.e. it is acceptable to provide an implementation that segfaults if 8507 ** it is passed a NULL pointer). 8508 ** 8509 ** The xMutexInit() method must be threadsafe. It must be harmless to 8510 ** invoke xMutexInit() multiple times within the same process and without 8511 ** intervening calls to xMutexEnd(). Second and subsequent calls to 8512 ** xMutexInit() must be no-ops. 8513 ** 8514 ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] 8515 ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory 8516 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite 8517 ** memory allocation for a fast or recursive mutex. 8518 ** 8519 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is 8520 ** called, but only if the prior call to xMutexInit returned SQLITE_OK. 8521 ** If xMutexInit fails in any way, it is expected to clean up after itself 8522 ** prior to returning. 8523 */ 8524 typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; 8525 struct sqlite3_mutex_methods { 8526 int (*xMutexInit)(void); 8527 int (*xMutexEnd)(void); 8528 sqlite3_mutex *(*xMutexAlloc)(int); 8529 void (*xMutexFree)(sqlite3_mutex *); 8530 void (*xMutexEnter)(sqlite3_mutex *); 8531 int (*xMutexTry)(sqlite3_mutex *); 8532 void (*xMutexLeave)(sqlite3_mutex *); 8533 int (*xMutexHeld)(sqlite3_mutex *); 8534 int (*xMutexNotheld)(sqlite3_mutex *); 8535 }; 8536 8537 /* 8538 ** CAPI3REF: Mutex Verification Routines 8539 ** 8540 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines 8541 ** are intended for use inside assert() statements. The SQLite core 8542 ** never uses these routines except inside an assert() and applications 8543 ** are advised to follow the lead of the core. The SQLite core only 8544 ** provides implementations for these routines when it is compiled 8545 ** with the SQLITE_DEBUG flag. External mutex implementations 8546 ** are only required to provide these routines if SQLITE_DEBUG is 8547 ** defined and if NDEBUG is not defined. 8548 ** 8549 ** These routines should return true if the mutex in their argument 8550 ** is held or not held, respectively, by the calling thread. 8551 ** 8552 ** The implementation is not required to provide versions of these 8553 ** routines that actually work. If the implementation does not provide working 8554 ** versions of these routines, it should at least provide stubs that always 8555 ** return true so that one does not get spurious assertion failures. 8556 ** 8557 ** If the argument to sqlite3_mutex_held() is a NULL pointer then 8558 ** the routine should return 1. This seems counter-intuitive since 8559 ** clearly the mutex cannot be held if it does not exist. But 8560 ** the reason the mutex does not exist is because the build is not 8561 ** using mutexes. And we do not want the assert() containing the 8562 ** call to sqlite3_mutex_held() to fail, so a non-zero return is 8563 ** the appropriate thing to do. The sqlite3_mutex_notheld() 8564 ** interface should also return 1 when given a NULL pointer. 8565 */ 8566 #ifndef NDEBUG 8567 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); 8568 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); 8569 #endif 8570 8571 /* 8572 ** CAPI3REF: Mutex Types 8573 ** 8574 ** The [sqlite3_mutex_alloc()] interface takes a single argument 8575 ** which is one of these integer constants. 8576 ** 8577 ** The set of static mutexes may change from one SQLite release to the 8578 ** next. Applications that override the built-in mutex logic must be 8579 ** prepared to accommodate additional static mutexes. 8580 */ 8581 #define SQLITE_MUTEX_FAST 0 8582 #define SQLITE_MUTEX_RECURSIVE 1 8583 #define SQLITE_MUTEX_STATIC_MAIN 2 8584 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ 8585 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ 8586 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ 8587 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */ 8588 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ 8589 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ 8590 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ 8591 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */ 8592 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */ 8593 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */ 8594 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */ 8595 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */ 8596 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */ 8597 8598 /* Legacy compatibility: */ 8599 #define SQLITE_MUTEX_STATIC_MASTER 2 8600 8601 8602 /* 8603 ** CAPI3REF: Retrieve the mutex for a database connection 8604 ** METHOD: sqlite3 8605 ** 8606 ** ^This interface returns a pointer to the [sqlite3_mutex] object that 8607 ** serializes access to the [database connection] given in the argument 8608 ** when the [threading mode] is Serialized. 8609 ** ^If the [threading mode] is Single-thread or Multi-thread then this 8610 ** routine returns a NULL pointer. 8611 */ 8612 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); 8613 8614 /* 8615 ** CAPI3REF: Low-Level Control Of Database Files 8616 ** METHOD: sqlite3 8617 ** KEYWORDS: {file control} 8618 ** 8619 ** ^The [sqlite3_file_control()] interface makes a direct call to the 8620 ** xFileControl method for the [sqlite3_io_methods] object associated 8621 ** with a particular database identified by the second argument. ^The 8622 ** name of the database is "main" for the main database or "temp" for the 8623 ** TEMP database, or the name that appears after the AS keyword for 8624 ** databases that are added using the [ATTACH] SQL command. 8625 ** ^A NULL pointer can be used in place of "main" to refer to the 8626 ** main database file. 8627 ** ^The third and fourth parameters to this routine 8628 ** are passed directly through to the second and third parameters of 8629 ** the xFileControl method. ^The return value of the xFileControl 8630 ** method becomes the return value of this routine. 8631 ** 8632 ** A few opcodes for [sqlite3_file_control()] are handled directly 8633 ** by the SQLite core and never invoke the 8634 ** sqlite3_io_methods.xFileControl method. 8635 ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes 8636 ** a pointer to the underlying [sqlite3_file] object to be written into 8637 ** the space pointed to by the 4th parameter. The 8638 ** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns 8639 ** the [sqlite3_file] object associated with the journal file instead of 8640 ** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns 8641 ** a pointer to the underlying [sqlite3_vfs] object for the file. 8642 ** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter 8643 ** from the pager. 8644 ** 8645 ** ^If the second parameter (zDbName) does not match the name of any 8646 ** open database file, then SQLITE_ERROR is returned. ^This error 8647 ** code is not remembered and will not be recalled by [sqlite3_errcode()] 8648 ** or [sqlite3_errmsg()]. The underlying xFileControl method might 8649 ** also return SQLITE_ERROR. There is no way to distinguish between 8650 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying 8651 ** xFileControl method. 8652 ** 8653 ** See also: [file control opcodes] 8654 */ 8655 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); 8656 8657 /* 8658 ** CAPI3REF: Testing Interface 8659 ** 8660 ** ^The sqlite3_test_control() interface is used to read out internal 8661 ** state of SQLite and to inject faults into SQLite for testing 8662 ** purposes. ^The first parameter is an operation code that determines 8663 ** the number, meaning, and operation of all subsequent parameters. 8664 ** 8665 ** This interface is not for use by applications. It exists solely 8666 ** for verifying the correct operation of the SQLite library. Depending 8667 ** on how the SQLite library is compiled, this interface might not exist. 8668 ** 8669 ** The details of the operation codes, their meanings, the parameters 8670 ** they take, and what they do are all subject to change without notice. 8671 ** Unlike most of the SQLite API, this function is not guaranteed to 8672 ** operate consistently from one release to the next. 8673 */ 8674 SQLITE_API int sqlite3_test_control(int op, ...); 8675 8676 /* 8677 ** CAPI3REF: Testing Interface Operation Codes 8678 ** 8679 ** These constants are the valid operation code parameters used 8680 ** as the first argument to [sqlite3_test_control()]. 8681 ** 8682 ** These parameters and their meanings are subject to change 8683 ** without notice. These values are for testing purposes only. 8684 ** Applications should not use any of these parameters or the 8685 ** [sqlite3_test_control()] interface. 8686 */ 8687 #define SQLITE_TESTCTRL_FIRST 5 8688 #define SQLITE_TESTCTRL_PRNG_SAVE 5 8689 #define SQLITE_TESTCTRL_PRNG_RESTORE 6 8690 #define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */ 8691 #define SQLITE_TESTCTRL_FK_NO_ACTION 7 8692 #define SQLITE_TESTCTRL_BITVEC_TEST 8 8693 #define SQLITE_TESTCTRL_FAULT_INSTALL 9 8694 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 8695 #define SQLITE_TESTCTRL_PENDING_BYTE 11 8696 #define SQLITE_TESTCTRL_ASSERT 12 8697 #define SQLITE_TESTCTRL_ALWAYS 13 8698 #define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */ 8699 #define SQLITE_TESTCTRL_JSON_SELFCHECK 14 8700 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 8701 #define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */ 8702 #define SQLITE_TESTCTRL_GETOPT 16 8703 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */ 8704 #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 17 8705 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 8706 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */ 8707 #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19 8708 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 8709 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21 8710 #define SQLITE_TESTCTRL_BYTEORDER 22 8711 #define SQLITE_TESTCTRL_ISINIT 23 8712 #define SQLITE_TESTCTRL_SORTER_MMAP 24 8713 #define SQLITE_TESTCTRL_IMPOSTER 25 8714 #define SQLITE_TESTCTRL_PARSER_COVERAGE 26 8715 #define SQLITE_TESTCTRL_RESULT_INTREAL 27 8716 #define SQLITE_TESTCTRL_PRNG_SEED 28 8717 #define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29 8718 #define SQLITE_TESTCTRL_SEEK_COUNT 30 8719 #define SQLITE_TESTCTRL_TRACEFLAGS 31 8720 #define SQLITE_TESTCTRL_TUNE 32 8721 #define SQLITE_TESTCTRL_LOGEST 33 8722 #define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */ 8723 #define SQLITE_TESTCTRL_ATOF 34 8724 #define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */ 8725 8726 /* 8727 ** CAPI3REF: SQL Keyword Checking 8728 ** 8729 ** These routines provide access to the set of SQL language keywords 8730 ** recognized by SQLite. Applications can use these routines to determine 8731 ** whether or not a specific identifier needs to be escaped (for example, 8732 ** by enclosing in double-quotes) so as not to confuse the parser. 8733 ** 8734 ** The sqlite3_keyword_count() interface returns the number of distinct 8735 ** keywords understood by SQLite. 8736 ** 8737 ** The sqlite3_keyword_name(N,Z,L) interface finds the 0-based N-th keyword and 8738 ** makes *Z point to that keyword expressed as UTF8 and writes the number 8739 ** of bytes in the keyword into *L. The string that *Z points to is not 8740 ** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns 8741 ** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z 8742 ** or L are NULL or invalid pointers then calls to 8743 ** sqlite3_keyword_name(N,Z,L) result in undefined behavior. 8744 ** 8745 ** The sqlite3_keyword_check(Z,L) interface checks to see whether or not 8746 ** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero 8747 ** if it is and zero if not. 8748 ** 8749 ** The parser used by SQLite is forgiving. It is often possible to use 8750 ** a keyword as an identifier as long as such use does not result in a 8751 ** parsing ambiguity. For example, the statement 8752 ** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and 8753 ** creates a new table named "BEGIN" with three columns named 8754 ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid 8755 ** using keywords as identifiers. Common techniques used to avoid keyword 8756 ** name collisions include: 8757 ** <ul> 8758 ** <li> Put all identifier names inside double-quotes. This is the official 8759 ** SQL way to escape identifier names. 8760 ** <li> Put identifier names inside [...]. This is not standard SQL, 8761 ** but it is what SQL Server does and so lots of programmers use this 8762 ** technique. 8763 ** <li> Begin every identifier with the letter "Z" as no SQL keywords start 8764 ** with "Z". 8765 ** <li> Include a digit somewhere in every identifier name. 8766 ** </ul> 8767 ** 8768 ** Note that the number of keywords understood by SQLite can depend on 8769 ** compile-time options. For example, "VACUUM" is not a keyword if 8770 ** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also, 8771 ** new keywords may be added to future releases of SQLite. 8772 */ 8773 SQLITE_API int sqlite3_keyword_count(void); 8774 SQLITE_API int sqlite3_keyword_name(int,const char**,int*); 8775 SQLITE_API int sqlite3_keyword_check(const char*,int); 8776 8777 /* 8778 ** CAPI3REF: Dynamic String Object 8779 ** KEYWORDS: {dynamic string} 8780 ** 8781 ** An instance of the sqlite3_str object contains a dynamically-sized 8782 ** string under construction. 8783 ** 8784 ** The lifecycle of an sqlite3_str object is as follows: 8785 ** <ol> 8786 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()]. 8787 ** <li> ^Text is appended to the sqlite3_str object using various 8788 ** methods, such as [sqlite3_str_appendf()]. 8789 ** <li> ^The sqlite3_str object is destroyed and the string it created 8790 ** is returned using the [sqlite3_str_finish()] interface. 8791 ** </ol> 8792 */ 8793 typedef struct sqlite3_str sqlite3_str; 8794 8795 /* 8796 ** CAPI3REF: Create A New Dynamic String Object 8797 ** CONSTRUCTOR: sqlite3_str 8798 ** 8799 ** ^The [sqlite3_str_new(D)] interface allocates and initializes 8800 ** a new [sqlite3_str] object. To avoid memory leaks, the object returned by 8801 ** [sqlite3_str_new()] must be freed by a subsequent call to 8802 ** [sqlite3_str_finish(X)]. 8803 ** 8804 ** ^The [sqlite3_str_new(D)] interface always returns a pointer to a 8805 ** valid [sqlite3_str] object, though in the event of an out-of-memory 8806 ** error the returned object might be a special singleton that will 8807 ** silently reject new text, always return SQLITE_NOMEM from 8808 ** [sqlite3_str_errcode()], always return 0 for 8809 ** [sqlite3_str_length()], and always return NULL from 8810 ** [sqlite3_str_finish(X)]. It is always safe to use the value 8811 ** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter 8812 ** to any of the other [sqlite3_str] methods. 8813 ** 8814 ** The D parameter to [sqlite3_str_new(D)] may be NULL. If the 8815 ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum 8816 ** length of the string contained in the [sqlite3_str] object will be 8817 ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead 8818 ** of [SQLITE_MAX_LENGTH]. 8819 */ 8820 SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*); 8821 8822 /* 8823 ** CAPI3REF: Finalize A Dynamic String 8824 ** DESTRUCTOR: sqlite3_str 8825 ** 8826 ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X 8827 ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()] 8828 ** that contains the constructed string. The calling application should 8829 ** pass the returned value to [sqlite3_free()] to avoid a memory leak. 8830 ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any 8831 ** errors were encountered during construction of the string. ^The 8832 ** [sqlite3_str_finish(X)] interface might also return a NULL pointer if the 8833 ** string in [sqlite3_str] object X is zero bytes long. 8834 ** 8835 ** ^The [sqlite3_str_free(X)] interface destroys both the sqlite3_str object 8836 ** X and the string content it contains. Calling sqlite3_str_free(X) is 8837 ** the equivalent of calling [sqlite3_free](sqlite3_str_finish(X)). 8838 */ 8839 SQLITE_API char *sqlite3_str_finish(sqlite3_str*); 8840 SQLITE_API void sqlite3_str_free(sqlite3_str*); 8841 8842 /* 8843 ** CAPI3REF: Add Content To A Dynamic String 8844 ** METHOD: sqlite3_str 8845 ** 8846 ** These interfaces add or remove content to an sqlite3_str object 8847 ** previously obtained from [sqlite3_str_new()]. 8848 ** 8849 ** ^The [sqlite3_str_appendf(X,F,...)] and 8850 ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf] 8851 ** functionality of SQLite to append formatted text onto the end of 8852 ** [sqlite3_str] object X. 8853 ** 8854 ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S 8855 ** onto the end of the [sqlite3_str] object X. N must be non-negative. 8856 ** S must contain at least N non-zero bytes of content. To append a 8857 ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()] 8858 ** method instead. 8859 ** 8860 ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of 8861 ** zero-terminated string S onto the end of [sqlite3_str] object X. 8862 ** 8863 ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the 8864 ** single-byte character C onto the end of [sqlite3_str] object X. 8865 ** ^This method can be used, for example, to add whitespace indentation. 8866 ** 8867 ** ^The [sqlite3_str_reset(X)] method resets the string under construction 8868 ** inside [sqlite3_str] object X back to zero bytes in length. 8869 ** 8870 ** ^The [sqlite3_str_truncate(X,N)] method changes the length of the string 8871 ** under construction to be N bytes or less. This routine is a no-op if 8872 ** N is negative or if the string is already N bytes or smaller in size. 8873 ** 8874 ** These methods do not return a result code. ^If an error occurs, that fact 8875 ** is recorded in the [sqlite3_str] object and can be recovered by a 8876 ** subsequent call to [sqlite3_str_errcode(X)]. 8877 */ 8878 SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...); 8879 SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list); 8880 SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N); 8881 SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn); 8882 SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C); 8883 SQLITE_API void sqlite3_str_reset(sqlite3_str*); 8884 SQLITE_API void sqlite3_str_truncate(sqlite3_str*,int N); 8885 8886 /* 8887 ** CAPI3REF: Status Of A Dynamic String 8888 ** METHOD: sqlite3_str 8889 ** 8890 ** These interfaces return the current status of an [sqlite3_str] object. 8891 ** 8892 ** ^If any prior errors have occurred while constructing the dynamic string 8893 ** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return 8894 ** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns 8895 ** [SQLITE_NOMEM] following any out-of-memory error, or 8896 ** [SQLITE_TOOBIG] if the size of the dynamic string exceeds 8897 ** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors. 8898 ** 8899 ** ^The [sqlite3_str_length(X)] method returns the current length, in bytes, 8900 ** of the dynamic string under construction in [sqlite3_str] object X. 8901 ** ^The length returned by [sqlite3_str_length(X)] does not include the 8902 ** zero-termination byte. 8903 ** 8904 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current 8905 ** content of the dynamic string under construction in X. The value 8906 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X 8907 ** and might be freed or altered by any subsequent method on the same 8908 ** [sqlite3_str] object. Applications must not use the pointer returned by 8909 ** [sqlite3_str_value(X)] after any subsequent method call on the same 8910 ** object. ^Applications may change the content of the string returned 8911 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes 8912 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or 8913 ** write any byte after any subsequent sqlite3_str method call. 8914 */ 8915 SQLITE_API int sqlite3_str_errcode(sqlite3_str*); 8916 SQLITE_API int sqlite3_str_length(sqlite3_str*); 8917 SQLITE_API char *sqlite3_str_value(sqlite3_str*); 8918 8919 /* 8920 ** CAPI3REF: SQLite Runtime Status 8921 ** 8922 ** ^These interfaces are used to retrieve runtime status information 8923 ** about the performance of SQLite, and optionally to reset various 8924 ** highwater marks. ^The first argument is an integer code for 8925 ** the specific parameter to measure. ^(Recognized integer codes 8926 ** are of the form [status parameters | SQLITE_STATUS_...].)^ 8927 ** ^The current value of the parameter is returned into *pCurrent. 8928 ** ^The highest recorded value is returned in *pHighwater. ^If the 8929 ** resetFlag is true, then the highest record value is reset after 8930 ** *pHighwater is written. ^(Some parameters do not record the highest 8931 ** value. For those parameters 8932 ** nothing is written into *pHighwater and the resetFlag is ignored.)^ 8933 ** ^(Other parameters record only the highwater mark and not the current 8934 ** value. For these latter parameters nothing is written into *pCurrent.)^ 8935 ** 8936 ** ^The sqlite3_status() and sqlite3_status64() routines return 8937 ** SQLITE_OK on success and a non-zero [error code] on failure. 8938 ** 8939 ** If either the current value or the highwater mark is too large to 8940 ** be represented by a 32-bit integer, then the values returned by 8941 ** sqlite3_status() are undefined. 8942 ** 8943 ** See also: [sqlite3_db_status()] 8944 */ 8945 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); 8946 SQLITE_API int sqlite3_status64( 8947 int op, 8948 sqlite3_int64 *pCurrent, 8949 sqlite3_int64 *pHighwater, 8950 int resetFlag 8951 ); 8952 8953 8954 /* 8955 ** CAPI3REF: Status Parameters 8956 ** KEYWORDS: {status parameters} 8957 ** 8958 ** These integer constants designate various run-time status parameters 8959 ** that can be returned by [sqlite3_status()]. 8960 ** 8961 ** <dl> 8962 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> 8963 ** <dd>This parameter is the current amount of memory checked out 8964 ** using [sqlite3_malloc()], either directly or indirectly. The 8965 ** figure includes calls made to [sqlite3_malloc()] by the application 8966 ** and internal memory usage by the SQLite library. Auxiliary page-cache 8967 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in 8968 ** this parameter. The amount returned is the sum of the allocation 8969 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ 8970 ** 8971 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> 8972 ** <dd>This parameter records the largest memory allocation request 8973 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their 8974 ** internal equivalents). Only the value returned in the 8975 ** *pHighwater parameter to [sqlite3_status()] is of interest. 8976 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 8977 ** 8978 ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> 8979 ** <dd>This parameter records the number of separate memory allocations 8980 ** currently checked out.</dd>)^ 8981 ** 8982 ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> 8983 ** <dd>This parameter returns the number of pages used out of the 8984 ** [pagecache memory allocator] that was configured using 8985 ** [SQLITE_CONFIG_PAGECACHE]. The 8986 ** value returned is in pages, not in bytes.</dd>)^ 8987 ** 8988 ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] 8989 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> 8990 ** <dd>This parameter returns the number of bytes of page cache 8991 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] 8992 ** buffer and where forced to overflow to [sqlite3_malloc()]. The 8993 ** returned value includes allocations that overflowed because they 8994 ** were too large (they were larger than the "sz" parameter to 8995 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because 8996 ** no space was left in the page cache.</dd>)^ 8997 ** 8998 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> 8999 ** <dd>This parameter records the largest memory allocation request 9000 ** handed to the [pagecache memory allocator]. Only the value returned in the 9001 ** *pHighwater parameter to [sqlite3_status()] is of interest. 9002 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 9003 ** 9004 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt> 9005 ** <dd>No longer used.</dd> 9006 ** 9007 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> 9008 ** <dd>No longer used.</dd> 9009 ** 9010 ** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 9011 ** <dd>No longer used.</dd> 9012 ** 9013 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 9014 ** <dd>The *pHighwater parameter records the deepest parser stack. 9015 ** The *pCurrent value is undefined. The *pHighwater value is only 9016 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 9017 ** </dl> 9018 ** 9019 ** New status parameters may be added from time to time. 9020 */ 9021 #define SQLITE_STATUS_MEMORY_USED 0 9022 #define SQLITE_STATUS_PAGECACHE_USED 1 9023 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 9024 #define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */ 9025 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */ 9026 #define SQLITE_STATUS_MALLOC_SIZE 5 9027 #define SQLITE_STATUS_PARSER_STACK 6 9028 #define SQLITE_STATUS_PAGECACHE_SIZE 7 9029 #define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */ 9030 #define SQLITE_STATUS_MALLOC_COUNT 9 9031 9032 /* 9033 ** CAPI3REF: Database Connection Status 9034 ** METHOD: sqlite3 9035 ** 9036 ** ^This interface is used to retrieve runtime status information 9037 ** about a single [database connection]. ^The first argument is the 9038 ** database connection object to be interrogated. ^The second argument 9039 ** is an integer constant, taken from the set of 9040 ** [SQLITE_DBSTATUS options], that 9041 ** determines the parameter to interrogate. The set of 9042 ** [SQLITE_DBSTATUS options] is likely 9043 ** to grow in future releases of SQLite. 9044 ** 9045 ** ^The current value of the requested parameter is written into *pCur 9046 ** and the highest instantaneous value is written into *pHiwtr. ^If 9047 ** the resetFlg is true, then the highest instantaneous value is 9048 ** reset back down to the current value. 9049 ** 9050 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a 9051 ** non-zero [error code] on failure. 9052 ** 9053 ** ^The sqlite3_db_status64(D,O,C,H,R) routine works exactly the same 9054 ** way as sqlite3_db_status(D,O,C,H,R) routine except that the C and H 9055 ** parameters are pointer to 64-bit integers (type: sqlite3_int64) instead 9056 ** of pointers to 32-bit integers, which allows larger status values 9057 ** to be returned. If a status value exceeds 2,147,483,647 then 9058 ** sqlite3_db_status() will truncate the value whereas sqlite3_db_status64() 9059 ** will return the full value. 9060 ** 9061 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. 9062 */ 9063 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); 9064 SQLITE_API int sqlite3_db_status64(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int); 9065 9066 /* 9067 ** CAPI3REF: Status Parameters for database connections 9068 ** KEYWORDS: {SQLITE_DBSTATUS options} 9069 ** 9070 ** These constants are the available integer "verbs" that can be passed as 9071 ** the second argument to the [sqlite3_db_status()] interface. 9072 ** 9073 ** New verbs may be added in future releases of SQLite. Existing verbs 9074 ** might be discontinued. Applications should check the return code from 9075 ** [sqlite3_db_status()] to make sure that the call worked. 9076 ** The [sqlite3_db_status()] interface will return a non-zero error code 9077 ** if a discontinued or unsupported verb is invoked. 9078 ** 9079 ** <dl> 9080 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> 9081 ** <dd>This parameter returns the number of lookaside memory slots currently 9082 ** checked out.</dd>)^ 9083 ** 9084 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> 9085 ** <dd>This parameter returns the number of malloc attempts that were 9086 ** satisfied using lookaside memory. Only the high-water value is meaningful; 9087 ** the current value is always zero.</dd>)^ 9088 ** 9089 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] 9090 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> 9091 ** <dd>This parameter returns the number of malloc attempts that might have 9092 ** been satisfied using lookaside memory but failed due to the amount of 9093 ** memory requested being larger than the lookaside slot size. 9094 ** Only the high-water value is meaningful; 9095 ** the current value is always zero.</dd>)^ 9096 ** 9097 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] 9098 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> 9099 ** <dd>This parameter returns the number of malloc attempts that might have 9100 ** been satisfied using lookaside memory but failed due to all lookaside 9101 ** memory already being in use. 9102 ** Only the high-water value is meaningful; 9103 ** the current value is always zero.</dd>)^ 9104 ** 9105 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> 9106 ** <dd>This parameter returns the approximate number of bytes of heap 9107 ** memory used by all pager caches associated with the database connection.)^ 9108 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. 9109 ** </dd> 9110 ** 9111 ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]] 9112 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt> 9113 ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a 9114 ** pager cache is shared between two or more connections the bytes of heap 9115 ** memory used by that pager cache is divided evenly between the attached 9116 ** connections.)^ In other words, if none of the pager caches associated 9117 ** with the database connection are shared, this request returns the same 9118 ** value as DBSTATUS_CACHE_USED. Or, if one or more of the pager caches are 9119 ** shared, the value returned by this call will be smaller than that returned 9120 ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with 9121 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd> 9122 ** 9123 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> 9124 ** <dd>This parameter returns the approximate number of bytes of heap 9125 ** memory used to store the schema for all databases associated 9126 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 9127 ** ^The full amount of memory used by the schemas is reported, even if the 9128 ** schema memory is shared with other database connections due to 9129 ** [shared cache mode] being enabled. 9130 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. 9131 ** </dd> 9132 ** 9133 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> 9134 ** <dd>This parameter returns the approximate number of bytes of heap 9135 ** and lookaside memory used by all prepared statements associated with 9136 ** the database connection.)^ 9137 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. 9138 ** </dd> 9139 ** 9140 ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt> 9141 ** <dd>This parameter returns the number of pager cache hits that have 9142 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT 9143 ** is always 0. 9144 ** </dd> 9145 ** 9146 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> 9147 ** <dd>This parameter returns the number of pager cache misses that have 9148 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS 9149 ** is always 0. 9150 ** </dd> 9151 ** 9152 ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt> 9153 ** <dd>This parameter returns the number of dirty cache entries that have 9154 ** been written to disk. Specifically, the number of pages written to the 9155 ** wal file in wal mode databases, or the number of pages written to the 9156 ** database file in rollback mode databases. Any pages written as part of 9157 ** transaction rollback or database recovery operations are not included. 9158 ** If an IO or other error occurs while writing a page to disk, the effect 9159 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The 9160 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. 9161 ** <p> 9162 ** ^(There is overlap between the quantities measured by this parameter 9163 ** (SQLITE_DBSTATUS_CACHE_WRITE) and SQLITE_DBSTATUS_TEMPBUF_SPILL. 9164 ** Resetting one will reduce the other.)^ 9165 ** </dd> 9166 ** 9167 ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt> 9168 ** <dd>This parameter returns the number of dirty cache entries that have 9169 ** been written to disk in the middle of a transaction due to the page 9170 ** cache overflowing. Transactions are more efficient if they are written 9171 ** to disk all at once. When pages spill mid-transaction, that introduces 9172 ** additional overhead. This parameter can be used to help identify 9173 ** inefficiencies that can be resolved by increasing the cache size. 9174 ** </dd> 9175 ** 9176 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt> 9177 ** <dd>This parameter returns zero for the current value if and only if 9178 ** all foreign key constraints (deferred or immediate) have been 9179 ** resolved.)^ ^The highwater mark is always 0. 9180 ** 9181 ** [[SQLITE_DBSTATUS_TEMPBUF_SPILL] ^(<dt>SQLITE_DBSTATUS_TEMPBUF_SPILL</dt> 9182 ** <dd>^(This parameter returns the number of bytes written to temporary 9183 ** files on disk that could have been kept in memory had sufficient memory 9184 ** been available. This value includes writes to intermediate tables that 9185 ** are part of complex queries, external sorts that spill to disk, and 9186 ** writes to TEMP tables.)^ 9187 ** ^The highwater mark is always 0. 9188 ** <p> 9189 ** ^(There is overlap between the quantities measured by this parameter 9190 ** (SQLITE_DBSTATUS_TEMPBUF_SPILL) and SQLITE_DBSTATUS_CACHE_WRITE. 9191 ** Resetting one will reduce the other.)^ 9192 ** </dd> 9193 ** </dl> 9194 */ 9195 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 9196 #define SQLITE_DBSTATUS_CACHE_USED 1 9197 #define SQLITE_DBSTATUS_SCHEMA_USED 2 9198 #define SQLITE_DBSTATUS_STMT_USED 3 9199 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 9200 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 9201 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 9202 #define SQLITE_DBSTATUS_CACHE_HIT 7 9203 #define SQLITE_DBSTATUS_CACHE_MISS 8 9204 #define SQLITE_DBSTATUS_CACHE_WRITE 9 9205 #define SQLITE_DBSTATUS_DEFERRED_FKS 10 9206 #define SQLITE_DBSTATUS_CACHE_USED_SHARED 11 9207 #define SQLITE_DBSTATUS_CACHE_SPILL 12 9208 #define SQLITE_DBSTATUS_TEMPBUF_SPILL 13 9209 #define SQLITE_DBSTATUS_MAX 13 /* Largest defined DBSTATUS */ 9210 9211 9212 /* 9213 ** CAPI3REF: Prepared Statement Status 9214 ** METHOD: sqlite3_stmt 9215 ** 9216 ** ^(Each prepared statement maintains various 9217 ** [SQLITE_STMTSTATUS counters] that measure the number 9218 ** of times it has performed specific operations.)^ These counters can 9219 ** be used to monitor the performance characteristics of the prepared 9220 ** statements. For example, if the number of table steps greatly exceeds 9221 ** the number of table searches or result rows, that would tend to indicate 9222 ** that the prepared statement is using a full table scan rather than 9223 ** an index. 9224 ** 9225 ** ^(This interface is used to retrieve and reset counter values from 9226 ** a [prepared statement]. The first argument is the prepared statement 9227 ** object to be interrogated. The second argument 9228 ** is an integer code for a specific [SQLITE_STMTSTATUS counter] 9229 ** to be interrogated.)^ 9230 ** ^The current value of the requested counter is returned. 9231 ** ^If the resetFlg is true, then the counter is reset to zero after this 9232 ** interface call returns. 9233 ** 9234 ** See also: [sqlite3_status()] and [sqlite3_db_status()]. 9235 */ 9236 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); 9237 9238 /* 9239 ** CAPI3REF: Status Parameters for prepared statements 9240 ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} 9241 ** 9242 ** These preprocessor macros define integer codes that name counter 9243 ** values associated with the [sqlite3_stmt_status()] interface. 9244 ** The meanings of the various counters are as follows: 9245 ** 9246 ** <dl> 9247 ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> 9248 ** <dd>^This is the number of times that SQLite has stepped forward in 9249 ** a table as part of a full table scan. Large numbers for this counter 9250 ** may indicate opportunities for performance improvement through 9251 ** careful use of indices.</dd> 9252 ** 9253 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> 9254 ** <dd>^This is the number of sort operations that have occurred. 9255 ** A non-zero value in this counter may indicate an opportunity to 9256 ** improve performance through careful use of indices.</dd> 9257 ** 9258 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> 9259 ** <dd>^This is the number of rows inserted into transient indices that 9260 ** were created automatically in order to help joins run faster. 9261 ** A non-zero value in this counter may indicate an opportunity to 9262 ** improve performance by adding permanent indices that do not 9263 ** need to be reinitialized each time the statement is run.</dd> 9264 ** 9265 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt> 9266 ** <dd>^This is the number of virtual machine operations executed 9267 ** by the prepared statement if that number is less than or equal 9268 ** to 2147483647. The number of virtual machine operations can be 9269 ** used as a proxy for the total work done by the prepared statement. 9270 ** If the number of virtual machine operations exceeds 2147483647 9271 ** then the value returned by this statement status code is undefined.</dd> 9272 ** 9273 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt> 9274 ** <dd>^This is the number of times that the prepare statement has been 9275 ** automatically regenerated due to schema changes or changes to 9276 ** [bound parameters] that might affect the query plan.</dd> 9277 ** 9278 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt> 9279 ** <dd>^This is the number of times that the prepared statement has 9280 ** been run. A single "run" for the purposes of this counter is one 9281 ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()]. 9282 ** The counter is incremented on the first [sqlite3_step()] call of each 9283 ** cycle.</dd> 9284 ** 9285 ** [[SQLITE_STMTSTATUS_FILTER_MISS]] 9286 ** [[SQLITE_STMTSTATUS_FILTER HIT]] 9287 ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br> 9288 ** SQLITE_STMTSTATUS_FILTER_MISS</dt> 9289 ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join 9290 ** step was bypassed because a Bloom filter returned not-found. The 9291 ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of 9292 ** times that the Bloom filter returned a find, and thus the join step 9293 ** had to be processed as normal.</dd> 9294 ** 9295 ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt> 9296 ** <dd>^This is the approximate number of bytes of heap memory 9297 ** used to store the prepared statement. ^This value is not actually 9298 ** a counter, and so the resetFlg parameter to sqlite3_stmt_status() 9299 ** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED. 9300 ** </dd> 9301 ** </dl> 9302 */ 9303 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 9304 #define SQLITE_STMTSTATUS_SORT 2 9305 #define SQLITE_STMTSTATUS_AUTOINDEX 3 9306 #define SQLITE_STMTSTATUS_VM_STEP 4 9307 #define SQLITE_STMTSTATUS_REPREPARE 5 9308 #define SQLITE_STMTSTATUS_RUN 6 9309 #define SQLITE_STMTSTATUS_FILTER_MISS 7 9310 #define SQLITE_STMTSTATUS_FILTER_HIT 8 9311 #define SQLITE_STMTSTATUS_MEMUSED 99 9312 9313 /* 9314 ** CAPI3REF: Custom Page Cache Object 9315 ** 9316 ** The sqlite3_pcache type is opaque. It is implemented by 9317 ** the pluggable module. The SQLite core has no knowledge of 9318 ** its size or internal structure and never deals with the 9319 ** sqlite3_pcache object except by holding and passing pointers 9320 ** to the object. 9321 ** 9322 ** See [sqlite3_pcache_methods2] for additional information. 9323 */ 9324 typedef struct sqlite3_pcache sqlite3_pcache; 9325 9326 /* 9327 ** CAPI3REF: Custom Page Cache Object 9328 ** 9329 ** The sqlite3_pcache_page object represents a single page in the 9330 ** page cache. The page cache will allocate instances of this 9331 ** object. Various methods of the page cache use pointers to instances 9332 ** of this object as parameters or as their return value. 9333 ** 9334 ** See [sqlite3_pcache_methods2] for additional information. 9335 */ 9336 typedef struct sqlite3_pcache_page sqlite3_pcache_page; 9337 struct sqlite3_pcache_page { 9338 void *pBuf; /* The content of the page */ 9339 void *pExtra; /* Extra information associated with the page */ 9340 }; 9341 9342 /* 9343 ** CAPI3REF: Application Defined Page Cache. 9344 ** KEYWORDS: {page cache} 9345 ** 9346 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can 9347 ** register an alternative page cache implementation by passing in an 9348 ** instance of the sqlite3_pcache_methods2 structure.)^ 9349 ** In many applications, most of the heap memory allocated by 9350 ** SQLite is used for the page cache. 9351 ** By implementing a 9352 ** custom page cache using this API, an application can better control 9353 ** the amount of memory consumed by SQLite, the way in which 9354 ** that memory is allocated and released, and the policies used to 9355 ** determine exactly which parts of a database file are cached and for 9356 ** how long. 9357 ** 9358 ** The alternative page cache mechanism is an 9359 ** extreme measure that is only needed by the most demanding applications. 9360 ** The built-in page cache is recommended for most uses. 9361 ** 9362 ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an 9363 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence 9364 ** the application may discard the parameter after the call to 9365 ** [sqlite3_config()] returns.)^ 9366 ** 9367 ** [[the xInit() page cache method]] 9368 ** ^(The xInit() method is called once for each effective 9369 ** call to [sqlite3_initialize()])^ 9370 ** (usually only once during the lifetime of the process). ^(The xInit() 9371 ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^ 9372 ** The intent of the xInit() method is to set up global data structures 9373 ** required by the custom page cache implementation. 9374 ** ^(If the xInit() method is NULL, then the 9375 ** built-in default page cache is used instead of the application defined 9376 ** page cache.)^ 9377 ** 9378 ** [[the xShutdown() page cache method]] 9379 ** ^The xShutdown() method is called by [sqlite3_shutdown()]. 9380 ** It can be used to clean up 9381 ** any outstanding resources before process shutdown, if required. 9382 ** ^The xShutdown() method may be NULL. 9383 ** 9384 ** ^SQLite automatically serializes calls to the xInit method, 9385 ** so the xInit method need not be threadsafe. ^The 9386 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 9387 ** not need to be threadsafe either. All other methods must be threadsafe 9388 ** in multithreaded applications. 9389 ** 9390 ** ^SQLite will never invoke xInit() more than once without an intervening 9391 ** call to xShutdown(). 9392 ** 9393 ** [[the xCreate() page cache methods]] 9394 ** ^SQLite invokes the xCreate() method to construct a new cache instance. 9395 ** SQLite will typically create one cache instance for each open database file, 9396 ** though this is not guaranteed. ^The 9397 ** first parameter, szPage, is the size in bytes of the pages that must 9398 ** be allocated by the cache. ^szPage will always be a power of two. ^The 9399 ** second parameter szExtra is a number of bytes of extra storage 9400 ** associated with each page cache entry. ^The szExtra parameter will be 9401 ** a number less than 250. SQLite will use the 9402 ** extra szExtra bytes on each page to store metadata about the underlying 9403 ** database page on disk. The value passed into szExtra depends 9404 ** on the SQLite version, the target platform, and how SQLite was compiled. 9405 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being 9406 ** created will be used to cache database pages of a file stored on disk, or 9407 ** false if it is used for an in-memory database. The cache implementation 9408 ** does not have to do anything special based upon the value of bPurgeable; 9409 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 9410 ** never invoke xUnpin() except to deliberately delete a page. 9411 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 9412 ** false will always have the "discard" flag set to true. 9413 ** ^Hence, a cache created with bPurgeable set to false will 9414 ** never contain any unpinned pages. 9415 ** 9416 ** [[the xCachesize() page cache method]] 9417 ** ^(The xCachesize() method may be called at any time by SQLite to set the 9418 ** suggested maximum cache-size (number of pages stored) for the cache 9419 ** instance passed as the first argument. This is the value configured using 9420 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable 9421 ** parameter, the implementation is not required to do anything with this 9422 ** value; it is advisory only. 9423 ** 9424 ** [[the xPagecount() page cache methods]] 9425 ** The xPagecount() method must return the number of pages currently 9426 ** stored in the cache, both pinned and unpinned. 9427 ** 9428 ** [[the xFetch() page cache methods]] 9429 ** The xFetch() method locates a page in the cache and returns a pointer to 9430 ** an sqlite3_pcache_page object associated with that page, or a NULL pointer. 9431 ** The pBuf element of the returned sqlite3_pcache_page object will be a 9432 ** pointer to a buffer of szPage bytes used to store the content of a 9433 ** single database page. The pExtra element of sqlite3_pcache_page will be 9434 ** a pointer to the szExtra bytes of extra storage that SQLite has requested 9435 ** for each entry in the page cache. 9436 ** 9437 ** The page to be fetched is determined by the key. ^The minimum key value 9438 ** is 1. After it has been retrieved using xFetch, the page is considered 9439 ** to be "pinned". 9440 ** 9441 ** If the requested page is already in the page cache, then the page cache 9442 ** implementation must return a pointer to the page buffer with its content 9443 ** intact. If the requested page is not already in the cache, then the 9444 ** cache implementation should use the value of the createFlag 9445 ** parameter to help it determine what action to take: 9446 ** 9447 ** <table border=1 width=85% align=center> 9448 ** <tr><th> createFlag <th> Behavior when page is not already in cache 9449 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. 9450 ** <tr><td> 1 <td> Allocate a new page if it is easy and convenient to do so. 9451 ** Otherwise return NULL. 9452 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return 9453 ** NULL if allocating a new page is effectively impossible. 9454 ** </table> 9455 ** 9456 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite 9457 ** will only use a createFlag of 2 after a prior call with a createFlag of 1 9458 ** failed.)^ In between the xFetch() calls, SQLite may 9459 ** attempt to unpin one or more cache pages by spilling the content of 9460 ** pinned pages to disk and synching the operating system disk cache. 9461 ** 9462 ** [[the xUnpin() page cache method]] 9463 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page 9464 ** as its second argument. If the third parameter, discard, is non-zero, 9465 ** then the page must be evicted from the cache. 9466 ** ^If the discard parameter is 9467 ** zero, then the page may be discarded or retained at the discretion of the 9468 ** page cache implementation. ^The page cache implementation 9469 ** may choose to evict unpinned pages at any time. 9470 ** 9471 ** The cache must not perform any reference counting. A single 9472 ** call to xUnpin() unpins the page regardless of the number of prior calls 9473 ** to xFetch(). 9474 ** 9475 ** [[the xRekey() page cache methods]] 9476 ** The xRekey() method is used to change the key value associated with the 9477 ** page passed as the second argument. If the cache 9478 ** previously contains an entry associated with newKey, it must be 9479 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not 9480 ** to be pinned. 9481 ** 9482 ** When SQLite calls the xTruncate() method, the cache must discard all 9483 ** existing cache entries with page numbers (keys) greater than or equal 9484 ** to the value of the iLimit parameter passed to xTruncate(). If any 9485 ** of these pages are pinned, they become implicitly unpinned, meaning that 9486 ** they can be safely discarded. 9487 ** 9488 ** [[the xDestroy() page cache method]] 9489 ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 9490 ** All resources associated with the specified cache should be freed. ^After 9491 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 9492 ** handle invalid, and will not use it with any other sqlite3_pcache_methods2 9493 ** functions. 9494 ** 9495 ** [[the xShrink() page cache method]] 9496 ** ^SQLite invokes the xShrink() method when it wants the page cache to 9497 ** free up as much of heap memory as possible. The page cache implementation 9498 ** is not obligated to free any memory, but well-behaved implementations should 9499 ** do their best. 9500 */ 9501 typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2; 9502 struct sqlite3_pcache_methods2 { 9503 int iVersion; 9504 void *pArg; 9505 int (*xInit)(void*); 9506 void (*xShutdown)(void*); 9507 sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable); 9508 void (*xCachesize)(sqlite3_pcache*, int nCachesize); 9509 int (*xPagecount)(sqlite3_pcache*); 9510 sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 9511 void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard); 9512 void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, 9513 unsigned oldKey, unsigned newKey); 9514 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 9515 void (*xDestroy)(sqlite3_pcache*); 9516 void (*xShrink)(sqlite3_pcache*); 9517 }; 9518 9519 /* 9520 ** This is the obsolete pcache_methods object that has now been replaced 9521 ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is 9522 ** retained in the header file for backwards compatibility only. 9523 */ 9524 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 9525 struct sqlite3_pcache_methods { 9526 void *pArg; 9527 int (*xInit)(void*); 9528 void (*xShutdown)(void*); 9529 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 9530 void (*xCachesize)(sqlite3_pcache*, int nCachesize); 9531 int (*xPagecount)(sqlite3_pcache*); 9532 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 9533 void (*xUnpin)(sqlite3_pcache*, void*, int discard); 9534 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 9535 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 9536 void (*xDestroy)(sqlite3_pcache*); 9537 }; 9538 9539 9540 /* 9541 ** CAPI3REF: Online Backup Object 9542 ** 9543 ** The sqlite3_backup object records state information about an ongoing 9544 ** online backup operation. ^The sqlite3_backup object is created by 9545 ** a call to [sqlite3_backup_init()] and is destroyed by a call to 9546 ** [sqlite3_backup_finish()]. 9547 ** 9548 ** See Also: [Using the SQLite Online Backup API] 9549 */ 9550 typedef struct sqlite3_backup sqlite3_backup; 9551 9552 /* 9553 ** CAPI3REF: Online Backup API. 9554 ** 9555 ** The backup API copies the content of one database into another. 9556 ** It is useful either for creating backups of databases or 9557 ** for copying in-memory databases to or from persistent files. 9558 ** 9559 ** See Also: [Using the SQLite Online Backup API] 9560 ** 9561 ** ^SQLite holds a write transaction open on the destination database file 9562 ** for the duration of the backup operation. 9563 ** ^The source database is read-locked only while it is being read; 9564 ** it is not locked continuously for the entire backup operation. 9565 ** ^Thus, the backup may be performed on a live source database without 9566 ** preventing other database connections from 9567 ** reading or writing to the source database while the backup is underway. 9568 ** 9569 ** ^(To perform a backup operation: 9570 ** <ol> 9571 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the 9572 ** backup, 9573 ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 9574 ** the data between the two databases, and finally 9575 ** <li><b>sqlite3_backup_finish()</b> is called to release all resources 9576 ** associated with the backup operation. 9577 ** </ol>)^ 9578 ** There should be exactly one call to sqlite3_backup_finish() for each 9579 ** successful call to sqlite3_backup_init(). 9580 ** 9581 ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> 9582 ** 9583 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 9584 ** [database connection] associated with the destination database 9585 ** and the database name, respectively. 9586 ** ^The database name is "main" for the main database, "temp" for the 9587 ** temporary database, or the name specified after the AS keyword in 9588 ** an [ATTACH] statement for an attached database. 9589 ** ^The S and M arguments passed to 9590 ** sqlite3_backup_init(D,N,S,M) identify the [database connection] 9591 ** and database name of the source database, respectively. 9592 ** ^The source and destination [database connections] (parameters S and D) 9593 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with 9594 ** an error. 9595 ** 9596 ** ^A call to sqlite3_backup_init() will fail, returning NULL, if 9597 ** there is already a read or read-write transaction open on the 9598 ** destination database. 9599 ** 9600 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is 9601 ** returned and an error code and error message are stored in the 9602 ** destination [database connection] D. 9603 ** ^The error code and message for the failed call to sqlite3_backup_init() 9604 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or 9605 ** [sqlite3_errmsg16()] functions. 9606 ** ^A successful call to sqlite3_backup_init() returns a pointer to an 9607 ** [sqlite3_backup] object. 9608 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and 9609 ** sqlite3_backup_finish() functions to perform the specified backup 9610 ** operation. 9611 ** 9612 ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> 9613 ** 9614 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 9615 ** the source and destination databases specified by [sqlite3_backup] object B. 9616 ** ^If N is negative, all remaining source pages are copied. 9617 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there 9618 ** are still more pages to be copied, then the function returns [SQLITE_OK]. 9619 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages 9620 ** from source to destination, then it returns [SQLITE_DONE]. 9621 ** ^If an error occurs while running sqlite3_backup_step(B,N), 9622 ** then an [error code] is returned. ^As well as [SQLITE_OK] and 9623 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], 9624 ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an 9625 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. 9626 ** 9627 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if 9628 ** <ol> 9629 ** <li> the destination database was opened read-only, or 9630 ** <li> the destination database is using write-ahead-log journaling 9631 ** and the destination and source page sizes differ, or 9632 ** <li> the destination database is an in-memory database and the 9633 ** destination and source page sizes differ. 9634 ** </ol>)^ 9635 ** 9636 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then 9637 ** the [sqlite3_busy_handler | busy-handler function] 9638 ** is invoked (if one is specified). ^If the 9639 ** busy-handler returns non-zero before the lock is available, then 9640 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to 9641 ** sqlite3_backup_step() can be retried later. ^If the source 9642 ** [database connection] 9643 ** is being used to write to the source database when sqlite3_backup_step() 9644 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this 9645 ** case the call to sqlite3_backup_step() can be retried later on. ^(If 9646 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or 9647 ** [SQLITE_READONLY] is returned, then 9648 ** there is no point in retrying the call to sqlite3_backup_step(). These 9649 ** errors are considered fatal.)^ The application must accept 9650 ** that the backup operation has failed and pass the backup operation handle 9651 ** to the sqlite3_backup_finish() to release associated resources. 9652 ** 9653 ** ^The first call to sqlite3_backup_step() obtains an exclusive lock 9654 ** on the destination file. ^The exclusive lock is not released until either 9655 ** sqlite3_backup_finish() is called or the backup operation is complete 9656 ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to 9657 ** sqlite3_backup_step() obtains a [shared lock] on the source database that 9658 ** lasts for the duration of the sqlite3_backup_step() call. 9659 ** ^Because the source database is not locked between calls to 9660 ** sqlite3_backup_step(), the source database may be modified mid-way 9661 ** through the backup process. ^If the source database is modified by an 9662 ** external process or via a database connection other than the one being 9663 ** used by the backup operation, then the backup will be automatically 9664 ** restarted by the next call to sqlite3_backup_step(). ^If the source 9665 ** database is modified by using the same database connection as is used 9666 ** by the backup operation, then the backup database is automatically 9667 ** updated at the same time. 9668 ** 9669 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> 9670 ** 9671 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 9672 ** application wishes to abandon the backup operation, the application 9673 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). 9674 ** ^The sqlite3_backup_finish() interfaces releases all 9675 ** resources associated with the [sqlite3_backup] object. 9676 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any 9677 ** active write-transaction on the destination database is rolled back. 9678 ** The [sqlite3_backup] object is invalid 9679 ** and may not be used following a call to sqlite3_backup_finish(). 9680 ** 9681 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no 9682 ** sqlite3_backup_step() errors occurred, regardless of whether or not 9683 ** sqlite3_backup_step() completed. 9684 ** ^If an out-of-memory condition or IO error occurred during any prior 9685 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then 9686 ** sqlite3_backup_finish() returns the corresponding [error code]. 9687 ** 9688 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() 9689 ** is not a permanent error and does not affect the return value of 9690 ** sqlite3_backup_finish(). 9691 ** 9692 ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]] 9693 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> 9694 ** 9695 ** ^The sqlite3_backup_remaining() routine returns the number of pages still 9696 ** to be backed up at the conclusion of the most recent sqlite3_backup_step(). 9697 ** ^The sqlite3_backup_pagecount() routine returns the total number of pages 9698 ** in the source database at the conclusion of the most recent 9699 ** sqlite3_backup_step(). 9700 ** ^(The values returned by these functions are only updated by 9701 ** sqlite3_backup_step(). If the source database is modified in a way that 9702 ** changes the size of the source database or the number of pages remaining, 9703 ** those changes are not reflected in the output of sqlite3_backup_pagecount() 9704 ** and sqlite3_backup_remaining() until after the next 9705 ** sqlite3_backup_step().)^ 9706 ** 9707 ** <b>Concurrent Usage of Database Handles</b> 9708 ** 9709 ** ^The source [database connection] may be used by the application for other 9710 ** purposes while a backup operation is underway or being initialized. 9711 ** ^If SQLite is compiled and configured to support threadsafe database 9712 ** connections, then the source database connection may be used concurrently 9713 ** from within other threads. 9714 ** 9715 ** However, the application must guarantee that the destination 9716 ** [database connection] is not passed to any other API (by any thread) after 9717 ** sqlite3_backup_init() is called and before the corresponding call to 9718 ** sqlite3_backup_finish(). SQLite does not currently check to see 9719 ** if the application incorrectly accesses the destination [database connection] 9720 ** and so no error code is reported, but the operations may malfunction 9721 ** nevertheless. Use of the destination database connection while a 9722 ** backup is in progress might also cause a mutex deadlock. 9723 ** 9724 ** If running in [shared cache mode], the application must 9725 ** guarantee that the shared cache used by the destination database 9726 ** is not accessed while the backup is running. In practice this means 9727 ** that the application must guarantee that the disk file being 9728 ** backed up to is not accessed by any connection within the process, 9729 ** not just the specific connection that was passed to sqlite3_backup_init(). 9730 ** 9731 ** The [sqlite3_backup] object itself is partially threadsafe. Multiple 9732 ** threads may safely make multiple concurrent calls to sqlite3_backup_step(). 9733 ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() 9734 ** APIs are not strictly speaking threadsafe. If they are invoked at the 9735 ** same time as another thread is invoking sqlite3_backup_step() it is 9736 ** possible that they return invalid values. 9737 ** 9738 ** <b>Alternatives To Using The Backup API</b> 9739 ** 9740 ** Other techniques for safely creating a consistent backup of an SQLite 9741 ** database include: 9742 ** 9743 ** <ul> 9744 ** <li> The [VACUUM INTO] command. 9745 ** <li> The [sqlite3_rsync] utility program. 9746 ** </ul> 9747 */ 9748 SQLITE_API sqlite3_backup *sqlite3_backup_init( 9749 sqlite3 *pDest, /* Destination database handle */ 9750 const char *zDestName, /* Destination database name */ 9751 sqlite3 *pSource, /* Source database handle */ 9752 const char *zSourceName /* Source database name */ 9753 ); 9754 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); 9755 SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); 9756 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); 9757 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); 9758 9759 /* 9760 ** CAPI3REF: Unlock Notification 9761 ** METHOD: sqlite3 9762 ** 9763 ** ^When running in shared-cache mode, a database operation may fail with 9764 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or 9765 ** individual tables within the shared-cache cannot be obtained. See 9766 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 9767 ** ^This API may be used to register a callback that SQLite will invoke 9768 ** when the connection currently holding the required lock relinquishes it. 9769 ** ^This API is only available if the library was compiled with the 9770 ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. 9771 ** 9772 ** See Also: [Using the SQLite Unlock Notification Feature]. 9773 ** 9774 ** ^Shared-cache locks are released when a database connection concludes 9775 ** its current transaction, either by committing it or rolling it back. 9776 ** 9777 ** ^When a connection (known as the blocked connection) fails to obtain a 9778 ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the 9779 ** identity of the database connection (the blocking connection) that 9780 ** has locked the required resource is stored internally. ^After an 9781 ** application receives an SQLITE_LOCKED error, it may call the 9782 ** sqlite3_unlock_notify() method with the blocked connection handle as 9783 ** the first argument to register for a callback that will be invoked 9784 ** when the blocking connection's current transaction is concluded. ^The 9785 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close] 9786 ** call that concludes the blocking connection's transaction. 9787 ** 9788 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, 9789 ** there is a chance that the blocking connection will have already 9790 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked. 9791 ** If this happens, then the specified callback is invoked immediately, 9792 ** from within the call to sqlite3_unlock_notify().)^ 9793 ** 9794 ** ^If the blocked connection is attempting to obtain a write-lock on a 9795 ** shared-cache table, and more than one other connection currently holds 9796 ** a read-lock on the same table, then SQLite arbitrarily selects one of 9797 ** the other connections to use as the blocking connection. 9798 ** 9799 ** ^(There may be at most one unlock-notify callback registered by a 9800 ** blocked connection. If sqlite3_unlock_notify() is called when the 9801 ** blocked connection already has a registered unlock-notify callback, 9802 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is 9803 ** called with a NULL pointer as its second argument, then any existing 9804 ** unlock-notify callback is canceled. ^The blocked connection's 9805 ** unlock-notify callback may also be canceled by closing the blocked 9806 ** connection using [sqlite3_close()]. 9807 ** 9808 ** The unlock-notify callback is not reentrant. If an application invokes 9809 ** any sqlite3_xxx API functions from within an unlock-notify callback, a 9810 ** crash or deadlock may be the result. 9811 ** 9812 ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always 9813 ** returns SQLITE_OK. 9814 ** 9815 ** <b>Callback Invocation Details</b> 9816 ** 9817 ** When an unlock-notify callback is registered, the application provides a 9818 ** single void* pointer that is passed to the callback when it is invoked. 9819 ** However, the signature of the callback function allows SQLite to pass 9820 ** it an array of void* context pointers. The first argument passed to 9821 ** an unlock-notify callback is a pointer to an array of void* pointers, 9822 ** and the second is the number of entries in the array. 9823 ** 9824 ** When a blocking connection's transaction is concluded, there may be 9825 ** more than one blocked connection that has registered for an unlock-notify 9826 ** callback. ^If two or more such blocked connections have specified the 9827 ** same callback function, then instead of invoking the callback function 9828 ** multiple times, it is invoked once with the set of void* context pointers 9829 ** specified by the blocked connections bundled together into an array. 9830 ** This gives the application an opportunity to prioritize any actions 9831 ** related to the set of unblocked database connections. 9832 ** 9833 ** <b>Deadlock Detection</b> 9834 ** 9835 ** Assuming that after registering for an unlock-notify callback a 9836 ** database waits for the callback to be issued before taking any further 9837 ** action (a reasonable assumption), then using this API may cause the 9838 ** application to deadlock. For example, if connection X is waiting for 9839 ** connection Y's transaction to be concluded, and similarly connection 9840 ** Y is waiting on connection X's transaction, then neither connection 9841 ** will proceed and the system may remain deadlocked indefinitely. 9842 ** 9843 ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock 9844 ** detection. ^If a given call to sqlite3_unlock_notify() would put the 9845 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no 9846 ** unlock-notify callback is registered. The system is said to be in 9847 ** a deadlocked state if connection A has registered for an unlock-notify 9848 ** callback on the conclusion of connection B's transaction, and connection 9849 ** B has itself registered for an unlock-notify callback when connection 9850 ** A's transaction is concluded. ^Indirect deadlock is also detected, so 9851 ** the system is also considered to be deadlocked if connection B has 9852 ** registered for an unlock-notify callback on the conclusion of connection 9853 ** C's transaction, where connection C is waiting on connection A. ^Any 9854 ** number of levels of indirection are allowed. 9855 ** 9856 ** <b>The "DROP TABLE" Exception</b> 9857 ** 9858 ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 9859 ** always appropriate to call sqlite3_unlock_notify(). There is however, 9860 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, 9861 ** SQLite checks if there are any currently executing SELECT statements 9862 ** that belong to the same connection. If there are, SQLITE_LOCKED is 9863 ** returned. In this case there is no "blocking connection", so invoking 9864 ** sqlite3_unlock_notify() results in the unlock-notify callback being 9865 ** invoked immediately. If the application then re-attempts the "DROP TABLE" 9866 ** or "DROP INDEX" query, an infinite loop might be the result. 9867 ** 9868 ** One way around this problem is to check the extended error code returned 9869 ** by an sqlite3_step() call. ^(If there is a blocking connection, then the 9870 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in 9871 ** the special "DROP TABLE/INDEX" case, the extended error code is just 9872 ** SQLITE_LOCKED.)^ 9873 */ 9874 SQLITE_API int sqlite3_unlock_notify( 9875 sqlite3 *pBlocked, /* Waiting connection */ 9876 void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ 9877 void *pNotifyArg /* Argument to pass to xNotify */ 9878 ); 9879 9880 9881 /* 9882 ** CAPI3REF: String Comparison 9883 ** 9884 ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications 9885 ** and extensions to compare the contents of two buffers containing UTF-8 9886 ** strings in a case-independent fashion, using the same definition of "case 9887 ** independence" that SQLite uses internally when comparing identifiers. 9888 */ 9889 SQLITE_API int sqlite3_stricmp(const char *, const char *); 9890 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); 9891 9892 /* 9893 ** CAPI3REF: String Globbing 9894 * 9895 ** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if 9896 ** string X matches the [GLOB] pattern P. 9897 ** ^The definition of [GLOB] pattern matching used in 9898 ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the 9899 ** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function 9900 ** is case sensitive. 9901 ** 9902 ** Note that this routine returns zero on a match and non-zero if the strings 9903 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. 9904 ** 9905 ** See also: [sqlite3_strlike()]. 9906 */ 9907 SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr); 9908 9909 /* 9910 ** CAPI3REF: String LIKE Matching 9911 * 9912 ** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if 9913 ** string X matches the [LIKE] pattern P with escape character E. 9914 ** ^The definition of [LIKE] pattern matching used in 9915 ** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E" 9916 ** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without 9917 ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0. 9918 ** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case 9919 ** insensitive - equivalent upper and lower case ASCII characters match 9920 ** one another. 9921 ** 9922 ** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though 9923 ** only ASCII characters are case folded. 9924 ** 9925 ** Note that this routine returns zero on a match and non-zero if the strings 9926 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. 9927 ** 9928 ** See also: [sqlite3_strglob()]. 9929 */ 9930 SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc); 9931 9932 /* 9933 ** CAPI3REF: Error Logging Interface 9934 ** 9935 ** ^The [sqlite3_log()] interface writes a message into the [error log] 9936 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 9937 ** ^If logging is enabled, the zFormat string and subsequent arguments are 9938 ** used with [sqlite3_snprintf()] to generate the final output string. 9939 ** 9940 ** The sqlite3_log() interface is intended for use by extensions such as 9941 ** virtual tables, collating functions, and SQL functions. While there is 9942 ** nothing to prevent an application from calling sqlite3_log(), doing so 9943 ** is considered bad form. 9944 ** 9945 ** The zFormat string must not be NULL. 9946 ** 9947 ** To avoid deadlocks and other threading problems, the sqlite3_log() routine 9948 ** will not use dynamically allocated memory. The log message is stored in 9949 ** a fixed-length buffer on the stack. If the log message is longer than 9950 ** a few hundred characters, it will be truncated to the length of the 9951 ** buffer. 9952 */ 9953 SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); 9954 9955 /* 9956 ** CAPI3REF: Write-Ahead Log Commit Hook 9957 ** METHOD: sqlite3 9958 ** 9959 ** ^The [sqlite3_wal_hook()] function is used to register a callback that 9960 ** is invoked each time data is committed to a database in wal mode. 9961 ** 9962 ** ^(The callback is invoked by SQLite after the commit has taken place and 9963 ** the associated write-lock on the database released)^, so the implementation 9964 ** may read, write or [checkpoint] the database as required. 9965 ** 9966 ** ^The first parameter passed to the callback function when it is invoked 9967 ** is a copy of the third parameter passed to sqlite3_wal_hook() when 9968 ** registering the callback. ^The second is a copy of the database handle. 9969 ** ^The third parameter is the name of the database that was written to - 9970 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter 9971 ** is the number of pages currently in the write-ahead log file, 9972 ** including those that were just committed. 9973 ** 9974 ** ^The callback function should normally return [SQLITE_OK]. ^If an error 9975 ** code is returned, that error will propagate back up through the 9976 ** SQLite code base to cause the statement that provoked the callback 9977 ** to report an error, though the commit will have still occurred. If the 9978 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value 9979 ** that does not correspond to any valid SQLite error code, the results 9980 ** are undefined. 9981 ** 9982 ** ^A single database handle may have at most a single write-ahead log 9983 ** callback registered at one time. ^Calling [sqlite3_wal_hook()] 9984 ** replaces the default behavior or previously registered write-ahead 9985 ** log callback. 9986 ** 9987 ** ^The return value is a copy of the third parameter from the 9988 ** previous call, if any, or 0. 9989 ** 9990 ** ^The [sqlite3_wal_autocheckpoint()] interface and the 9991 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and 9992 ** will overwrite any prior [sqlite3_wal_hook()] settings. 9993 ** 9994 ** ^If a write-ahead log callback is set using this function then 9995 ** [sqlite3_wal_checkpoint_v2()] or [PRAGMA wal_checkpoint] 9996 ** should be invoked periodically to keep the write-ahead log file 9997 ** from growing without bound. 9998 ** 9999 ** ^Passing a NULL pointer for the callback disables automatic 10000 ** checkpointing entirely. To re-enable the default behavior, call 10001 ** sqlite3_wal_autocheckpoint(db,1000) or use [PRAGMA wal_checkpoint]. 10002 */ 10003 SQLITE_API void *sqlite3_wal_hook( 10004 sqlite3*, 10005 int(*)(void *,sqlite3*,const char*,int), 10006 void* 10007 ); 10008 10009 /* 10010 ** CAPI3REF: Configure an auto-checkpoint 10011 ** METHOD: sqlite3 10012 ** 10013 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around 10014 ** [sqlite3_wal_hook()] that causes any database on [database connection] D 10015 ** to automatically [checkpoint] 10016 ** after committing a transaction if there are N or 10017 ** more frames in the [write-ahead log] file. ^Passing zero or 10018 ** a negative value as the N parameter disables automatic 10019 ** checkpoints entirely. 10020 ** 10021 ** ^The callback registered by this function replaces any existing callback 10022 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback 10023 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism 10024 ** configured by this function. 10025 ** 10026 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface 10027 ** from SQL. 10028 ** 10029 ** ^Checkpoints initiated by this mechanism are 10030 ** [sqlite3_wal_checkpoint_v2|PASSIVE]. 10031 ** 10032 ** ^Every new [database connection] defaults to having the auto-checkpoint 10033 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] 10034 ** pages. 10035 ** 10036 ** ^The use of this interface is only necessary if the default setting 10037 ** is found to be suboptimal for a particular application. 10038 */ 10039 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); 10040 10041 /* 10042 ** CAPI3REF: Checkpoint a database 10043 ** METHOD: sqlite3 10044 ** 10045 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to 10046 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^ 10047 ** 10048 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the 10049 ** [write-ahead log] for database X on [database connection] D to be 10050 ** transferred into the database file and for the write-ahead log to 10051 ** be reset. See the [checkpointing] documentation for addition 10052 ** information. 10053 ** 10054 ** This interface used to be the only way to cause a checkpoint to 10055 ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()] 10056 ** interface was added. This interface is retained for backwards 10057 ** compatibility and as a convenience for applications that need to manually 10058 ** start a callback but which do not need the full power (and corresponding 10059 ** complication) of [sqlite3_wal_checkpoint_v2()]. 10060 */ 10061 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); 10062 10063 /* 10064 ** CAPI3REF: Checkpoint a database 10065 ** METHOD: sqlite3 10066 ** 10067 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint 10068 ** operation on database X of [database connection] D in mode M. Status 10069 ** information is written back into integers pointed to by L and C.)^ 10070 ** ^(The M parameter must be a valid [checkpoint mode]:)^ 10071 ** 10072 ** <dl> 10073 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> 10074 ** ^Checkpoint as many frames as possible without waiting for any database 10075 ** readers or writers to finish, then sync the database file if all frames 10076 ** in the log were checkpointed. ^The [busy-handler callback] 10077 ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode. 10078 ** ^On the other hand, passive mode might leave the checkpoint unfinished 10079 ** if there are concurrent readers or writers. 10080 ** 10081 ** <dt>SQLITE_CHECKPOINT_FULL<dd> 10082 ** ^This mode blocks (it invokes the 10083 ** [sqlite3_busy_handler|busy-handler callback]) until there is no 10084 ** database writer and all readers are reading from the most recent database 10085 ** snapshot. ^It then checkpoints all frames in the log file and syncs the 10086 ** database file. ^This mode blocks new database writers while it is pending, 10087 ** but new database readers are allowed to continue unimpeded. 10088 ** 10089 ** <dt>SQLITE_CHECKPOINT_RESTART<dd> 10090 ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition 10091 ** that after checkpointing the log file it blocks (calls the 10092 ** [busy-handler callback]) 10093 ** until all readers are reading from the database file only. ^This ensures 10094 ** that the next writer will restart the log file from the beginning. 10095 ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new 10096 ** database writer attempts while it is pending, but does not impede readers. 10097 ** 10098 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> 10099 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the 10100 ** addition that it also truncates the log file to zero bytes just prior 10101 ** to a successful return. 10102 ** 10103 ** <dt>SQLITE_CHECKPOINT_NOOP<dd> 10104 ** ^This mode always checkpoints zero frames. The only reason to invoke 10105 ** a NOOP checkpoint is to access the values returned by 10106 ** sqlite3_wal_checkpoint_v2() via output parameters *pnLog and *pnCkpt. 10107 ** </dl> 10108 ** 10109 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in 10110 ** the log file or to -1 if the checkpoint could not run because 10111 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not 10112 ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the 10113 ** log file (including any that were already checkpointed before the function 10114 ** was called) or to -1 if the checkpoint could not run due to an error or 10115 ** because the database is not in WAL mode. ^Note that upon successful 10116 ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been 10117 ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero. 10118 ** 10119 ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If 10120 ** any other process is running a checkpoint operation at the same time, the 10121 ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a 10122 ** busy-handler configured, it will not be invoked in this case. 10123 ** 10124 ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the 10125 ** exclusive "writer" lock on the database file. ^If the writer lock cannot be 10126 ** obtained immediately, and a busy-handler is configured, it is invoked and 10127 ** the writer lock retried until either the busy-handler returns 0 or the lock 10128 ** is successfully obtained. ^The busy-handler is also invoked while waiting for 10129 ** database readers as described above. ^If the busy-handler returns 0 before 10130 ** the writer lock is obtained or while waiting for database readers, the 10131 ** checkpoint operation proceeds from that point in the same way as 10132 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible 10133 ** without blocking any further. ^SQLITE_BUSY is returned in this case. 10134 ** 10135 ** ^If parameter zDb is NULL or points to a zero length string, then the 10136 ** specified operation is attempted on all WAL databases [attached] to 10137 ** [database connection] db. In this case the 10138 ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If 10139 ** an SQLITE_BUSY error is encountered when processing one or more of the 10140 ** attached WAL databases, the operation is still attempted on any remaining 10141 ** attached databases and SQLITE_BUSY is returned at the end. ^If any other 10142 ** error occurs while processing an attached database, processing is abandoned 10143 ** and the error code is returned to the caller immediately. ^If no error 10144 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached 10145 ** databases, SQLITE_OK is returned. 10146 ** 10147 ** ^If database zDb is the name of an attached database that is not in WAL 10148 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If 10149 ** zDb is not NULL (or a zero length string) and is not the name of any 10150 ** attached database, SQLITE_ERROR is returned to the caller. 10151 ** 10152 ** ^Unless it returns SQLITE_MISUSE, 10153 ** the sqlite3_wal_checkpoint_v2() interface 10154 ** sets the error information that is queried by 10155 ** [sqlite3_errcode()] and [sqlite3_errmsg()]. 10156 ** 10157 ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface 10158 ** from SQL. 10159 */ 10160 SQLITE_API int sqlite3_wal_checkpoint_v2( 10161 sqlite3 *db, /* Database handle */ 10162 const char *zDb, /* Name of attached database (or NULL) */ 10163 int eMode, /* SQLITE_CHECKPOINT_* value */ 10164 int *pnLog, /* OUT: Size of WAL log in frames */ 10165 int *pnCkpt /* OUT: Total number of frames checkpointed */ 10166 ); 10167 10168 /* 10169 ** CAPI3REF: Checkpoint Mode Values 10170 ** KEYWORDS: {checkpoint mode} 10171 ** 10172 ** These constants define all valid values for the "checkpoint mode" passed 10173 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. 10174 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the 10175 ** meaning of each of these checkpoint modes. 10176 */ 10177 #define SQLITE_CHECKPOINT_NOOP -1 /* Do no work at all */ 10178 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ 10179 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ 10180 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */ 10181 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ 10182 10183 /* 10184 ** CAPI3REF: Virtual Table Interface Configuration 10185 ** 10186 ** This function may be called by either the [xConnect] or [xCreate] method 10187 ** of a [virtual table] implementation to configure 10188 ** various facets of the virtual table interface. 10189 ** 10190 ** If this interface is invoked outside the context of an xConnect or 10191 ** xCreate virtual table method then the behavior is undefined. 10192 ** 10193 ** In the call sqlite3_vtab_config(D,C,...) the D parameter is the 10194 ** [database connection] in which the virtual table is being created and 10195 ** which is passed in as the first argument to the [xConnect] or [xCreate] 10196 ** method that is invoking sqlite3_vtab_config(). The C parameter is one 10197 ** of the [virtual table configuration options]. The presence and meaning 10198 ** of parameters after C depend on which [virtual table configuration option] 10199 ** is used. 10200 */ 10201 SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); 10202 10203 /* 10204 ** CAPI3REF: Virtual Table Configuration Options 10205 ** KEYWORDS: {virtual table configuration options} 10206 ** KEYWORDS: {virtual table configuration option} 10207 ** 10208 ** These macros define the various options to the 10209 ** [sqlite3_vtab_config()] interface that [virtual table] implementations 10210 ** can use to customize and optimize their behavior. 10211 ** 10212 ** <dl> 10213 ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]] 10214 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt> 10215 ** <dd>Calls of the form 10216 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, 10217 ** where X is an integer. If X is zero, then the [virtual table] whose 10218 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not 10219 ** support constraints. In this configuration (which is the default) if 10220 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire 10221 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been 10222 ** specified as part of the user's SQL statement, regardless of the actual 10223 ** ON CONFLICT mode specified. 10224 ** 10225 ** If X is non-zero, then the virtual table implementation guarantees 10226 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before 10227 ** any modifications to internal or persistent data structures have been made. 10228 ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite 10229 ** is able to roll back a statement or database transaction, and abandon 10230 ** or continue processing the current SQL statement as appropriate. 10231 ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns 10232 ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode 10233 ** had been ABORT. 10234 ** 10235 ** Virtual table implementations that are required to handle OR REPLACE 10236 ** must do so within the [xUpdate] method. If a call to the 10237 ** [sqlite3_vtab_on_conflict()] function indicates that the current ON 10238 ** CONFLICT policy is REPLACE, the virtual table implementation should 10239 ** silently replace the appropriate rows within the xUpdate callback and 10240 ** return SQLITE_OK. Or, if this is not possible, it may return 10241 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT 10242 ** constraint handling. 10243 ** </dd> 10244 ** 10245 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> 10246 ** <dd>Calls of the form 10247 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the 10248 ** the [xConnect] or [xCreate] methods of a [virtual table] implementation 10249 ** prohibits that virtual table from being used from within triggers and 10250 ** views. 10251 ** </dd> 10252 ** 10253 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> 10254 ** <dd>Calls of the form 10255 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the 10256 ** [xConnect] or [xCreate] methods of a [virtual table] implementation 10257 ** identify that virtual table as being safe to use from within triggers 10258 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the 10259 ** virtual table can do no serious harm even if it is controlled by a 10260 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS 10261 ** flag unless absolutely necessary. 10262 ** </dd> 10263 ** 10264 ** [[SQLITE_VTAB_USES_ALL_SCHEMAS]]<dt>SQLITE_VTAB_USES_ALL_SCHEMAS</dt> 10265 ** <dd>Calls of the form 10266 ** [sqlite3_vtab_config](db,SQLITE_VTAB_USES_ALL_SCHEMA) from within the 10267 ** the [xConnect] or [xCreate] methods of a [virtual table] implementation 10268 ** instruct the query planner to begin at least a read transaction on 10269 ** all schemas ("main", "temp", and any ATTACH-ed databases) whenever the 10270 ** virtual table is used. 10271 ** </dd> 10272 ** </dl> 10273 */ 10274 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 10275 #define SQLITE_VTAB_INNOCUOUS 2 10276 #define SQLITE_VTAB_DIRECTONLY 3 10277 #define SQLITE_VTAB_USES_ALL_SCHEMAS 4 10278 10279 /* 10280 ** CAPI3REF: Determine The Virtual Table Conflict Policy 10281 ** 10282 ** This function may only be called from within a call to the [xUpdate] method 10283 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The 10284 ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], 10285 ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode 10286 ** of the SQL statement that triggered the call to the [xUpdate] method of the 10287 ** [virtual table]. 10288 */ 10289 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); 10290 10291 /* 10292 ** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE 10293 ** 10294 ** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn] 10295 ** method of a [virtual table], then it might return true if the 10296 ** column is being fetched as part of an UPDATE operation during which the 10297 ** column value will not change. The virtual table implementation can use 10298 ** this hint as permission to substitute a return value that is less 10299 ** expensive to compute and that the corresponding 10300 ** [xUpdate] method understands as a "no-change" value. 10301 ** 10302 ** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that 10303 ** the column is not changed by the UPDATE statement, then the xColumn 10304 ** method can optionally return without setting a result, without calling 10305 ** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces]. 10306 ** In that case, [sqlite3_value_nochange(X)] will return true for the 10307 ** same column in the [xUpdate] method. 10308 ** 10309 ** The sqlite3_vtab_nochange() routine is an optimization. Virtual table 10310 ** implementations should continue to give a correct answer even if the 10311 ** sqlite3_vtab_nochange() interface were to always return false. In the 10312 ** current implementation, the sqlite3_vtab_nochange() interface does always 10313 ** returns false for the enhanced [UPDATE FROM] statement. 10314 */ 10315 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*); 10316 10317 /* 10318 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint 10319 ** METHOD: sqlite3_index_info 10320 ** 10321 ** This function may only be called from within a call to the [xBestIndex] 10322 ** method of a [virtual table]. This function returns a pointer to a string 10323 ** that is the name of the appropriate collation sequence to use for text 10324 ** comparisons on the constraint identified by its arguments. 10325 ** 10326 ** The first argument must be the pointer to the [sqlite3_index_info] object 10327 ** that is the first parameter to the xBestIndex() method. The second argument 10328 ** must be an index into the aConstraint[] array belonging to the 10329 ** sqlite3_index_info structure passed to xBestIndex. 10330 ** 10331 ** Important: 10332 ** The first parameter must be the same pointer that is passed into the 10333 ** xBestMethod() method. The first parameter may not be a pointer to a 10334 ** different [sqlite3_index_info] object, even an exact copy. 10335 ** 10336 ** The return value is computed as follows: 10337 ** 10338 ** <ol> 10339 ** <li><p> If the constraint comes from a WHERE clause expression that contains 10340 ** a [COLLATE operator], then the name of the collation specified by 10341 ** that COLLATE operator is returned. 10342 ** <li><p> If there is no COLLATE operator, but the column that is the subject 10343 ** of the constraint specifies an alternative collating sequence via 10344 ** a [COLLATE clause] on the column definition within the CREATE TABLE 10345 ** statement that was passed into [sqlite3_declare_vtab()], then the 10346 ** name of that alternative collating sequence is returned. 10347 ** <li><p> Otherwise, "BINARY" is returned. 10348 ** </ol> 10349 */ 10350 SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int); 10351 10352 /* 10353 ** CAPI3REF: Determine if a virtual table query is DISTINCT 10354 ** METHOD: sqlite3_index_info 10355 ** 10356 ** This API may only be used from within an [xBestIndex|xBestIndex method] 10357 ** of a [virtual table] implementation. The result of calling this 10358 ** interface from outside of xBestIndex() is undefined and probably harmful. 10359 ** 10360 ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and 10361 ** 3. The integer returned by sqlite3_vtab_distinct() 10362 ** gives the virtual table additional information about how the query 10363 ** planner wants the output to be ordered. As long as the virtual table 10364 ** can meet the ordering requirements of the query planner, it may set 10365 ** the "orderByConsumed" flag. 10366 ** 10367 ** <ol><li value="0"><p> 10368 ** ^If the sqlite3_vtab_distinct() interface returns 0, that means 10369 ** that the query planner needs the virtual table to return all rows in the 10370 ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the 10371 ** [sqlite3_index_info] object. This is the default expectation. If the 10372 ** virtual table outputs all rows in sorted order, then it is always safe for 10373 ** the xBestIndex method to set the "orderByConsumed" flag, regardless of 10374 ** the return value from sqlite3_vtab_distinct(). 10375 ** <li value="1"><p> 10376 ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means 10377 ** that the query planner does not need the rows to be returned in sorted order 10378 ** as long as all rows with the same values in all columns identified by the 10379 ** "aOrderBy" field are adjacent.)^ This mode is used when the query planner 10380 ** is doing a GROUP BY. 10381 ** <li value="2"><p> 10382 ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means 10383 ** that the query planner does not need the rows returned in any particular 10384 ** order, as long as rows with the same values in all columns identified 10385 ** by "aOrderBy" are adjacent.)^ ^(Furthermore, when two or more rows 10386 ** contain the same values for all columns identified by "colUsed", all but 10387 ** one such row may optionally be omitted from the result.)^ 10388 ** The virtual table is not required to omit rows that are duplicates 10389 ** over the "colUsed" columns, but if the virtual table can do that without 10390 ** too much extra effort, it could potentially help the query to run faster. 10391 ** This mode is used for a DISTINCT query. 10392 ** <li value="3"><p> 10393 ** ^(If the sqlite3_vtab_distinct() interface returns 3, that means the 10394 ** virtual table must return rows in the order defined by "aOrderBy" as 10395 ** if the sqlite3_vtab_distinct() interface had returned 0. However if 10396 ** two or more rows in the result have the same values for all columns 10397 ** identified by "colUsed", then all but one such row may optionally be 10398 ** omitted.)^ Like when the return value is 2, the virtual table 10399 ** is not required to omit rows that are duplicates over the "colUsed" 10400 ** columns, but if the virtual table can do that without 10401 ** too much extra effort, it could potentially help the query to run faster. 10402 ** This mode is used for queries 10403 ** that have both DISTINCT and ORDER BY clauses. 10404 ** </ol> 10405 ** 10406 ** <p>The following table summarizes the conditions under which the 10407 ** virtual table is allowed to set the "orderByConsumed" flag based on 10408 ** the value returned by sqlite3_vtab_distinct(). This table is a 10409 ** restatement of the previous four paragraphs: 10410 ** 10411 ** <table border=1 cellspacing=0 cellpadding=10 width="90%"> 10412 ** <tr> 10413 ** <td valign="top">sqlite3_vtab_distinct() return value 10414 ** <td valign="top">Rows are returned in aOrderBy order 10415 ** <td valign="top">Rows with the same value in all aOrderBy columns are 10416 ** adjacent 10417 ** <td valign="top">Duplicates over all colUsed columns may be omitted 10418 ** <tr><td>0<td>yes<td>yes<td>no 10419 ** <tr><td>1<td>no<td>yes<td>no 10420 ** <tr><td>2<td>no<td>yes<td>yes 10421 ** <tr><td>3<td>yes<td>yes<td>yes 10422 ** </table> 10423 ** 10424 ** ^For the purposes of comparing virtual table output values to see if the 10425 ** values are the same value for sorting purposes, two NULL values are 10426 ** considered to be the same. In other words, the comparison operator is "IS" 10427 ** (or "IS NOT DISTINCT FROM") and not "==". 10428 ** 10429 ** If a virtual table implementation is unable to meet the requirements 10430 ** specified above, then it must not set the "orderByConsumed" flag in the 10431 ** [sqlite3_index_info] object or an incorrect answer may result. 10432 ** 10433 ** ^A virtual table implementation is always free to return rows in any order 10434 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the 10435 ** "orderByConsumed" flag is unset, the query planner will add extra 10436 ** [bytecode] to ensure that the final results returned by the SQL query are 10437 ** ordered correctly. The use of the "orderByConsumed" flag and the 10438 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful 10439 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed" 10440 ** flag might help queries against a virtual table to run faster. Being 10441 ** overly aggressive and setting the "orderByConsumed" flag when it is not 10442 ** valid to do so, on the other hand, might cause SQLite to return incorrect 10443 ** results. 10444 */ 10445 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*); 10446 10447 /* 10448 ** CAPI3REF: Identify and handle IN constraints in xBestIndex 10449 ** 10450 ** This interface may only be used from within an 10451 ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation. 10452 ** The result of invoking this interface from any other context is 10453 ** undefined and probably harmful. 10454 ** 10455 ** ^(A constraint on a virtual table of the form 10456 ** "[IN operator|column IN (...)]" is 10457 ** communicated to the xBestIndex method as a 10458 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use 10459 ** this constraint, it must set the corresponding 10460 ** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under 10461 ** the usual mode of handling IN operators, SQLite generates [bytecode] 10462 ** that invokes the [xFilter|xFilter() method] once for each value 10463 ** on the right-hand side of the IN operator.)^ Thus the virtual table 10464 ** only sees a single value from the right-hand side of the IN operator 10465 ** at a time. 10466 ** 10467 ** In some cases, however, it would be advantageous for the virtual 10468 ** table to see all values on the right-hand of the IN operator all at 10469 ** once. The sqlite3_vtab_in() interfaces facilitates this in two ways: 10470 ** 10471 ** <ol> 10472 ** <li><p> 10473 ** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero) 10474 ** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint 10475 ** is an [IN operator] that can be processed all at once. ^In other words, 10476 ** sqlite3_vtab_in() with -1 in the third argument is a mechanism 10477 ** by which the virtual table can ask SQLite if all-at-once processing 10478 ** of the IN operator is even possible. 10479 ** 10480 ** <li><p> 10481 ** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates 10482 ** to SQLite that the virtual table does or does not want to process 10483 ** the IN operator all-at-once, respectively. ^Thus when the third 10484 ** parameter (F) is non-negative, this interface is the mechanism by 10485 ** which the virtual table tells SQLite how it wants to process the 10486 ** IN operator. 10487 ** </ol> 10488 ** 10489 ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times 10490 ** within the same xBestIndex method call. ^For any given P,N pair, 10491 ** the return value from sqlite3_vtab_in(P,N,F) will always be the same 10492 ** within the same xBestIndex call. ^If the interface returns true 10493 ** (non-zero), that means that the constraint is an IN operator 10494 ** that can be processed all-at-once. ^If the constraint is not an IN 10495 ** operator or cannot be processed all-at-once, then the interface returns 10496 ** false. 10497 ** 10498 ** ^(All-at-once processing of the IN operator is selected if both of the 10499 ** following conditions are met: 10500 ** 10501 ** <ol> 10502 ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive 10503 ** integer. This is how the virtual table tells SQLite that it wants to 10504 ** use the N-th constraint. 10505 ** 10506 ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was 10507 ** non-negative had F>=1. 10508 ** </ol>)^ 10509 ** 10510 ** ^If either or both of the conditions above are false, then SQLite uses 10511 ** the traditional one-at-a-time processing strategy for the IN constraint. 10512 ** ^If both conditions are true, then the argvIndex-th parameter to the 10513 ** xFilter method will be an [sqlite3_value] that appears to be NULL, 10514 ** but which can be passed to [sqlite3_vtab_in_first()] and 10515 ** [sqlite3_vtab_in_next()] to find all values on the right-hand side 10516 ** of the IN constraint. 10517 */ 10518 SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle); 10519 10520 /* 10521 ** CAPI3REF: Find all elements on the right-hand side of an IN constraint. 10522 ** 10523 ** These interfaces are only useful from within the 10524 ** [xFilter|xFilter() method] of a [virtual table] implementation. 10525 ** The result of invoking these interfaces from any other context 10526 ** is undefined and probably harmful. 10527 ** 10528 ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or 10529 ** sqlite3_vtab_in_next(X,P) should be one of the parameters to the 10530 ** xFilter method which invokes these routines, and specifically 10531 ** a parameter that was previously selected for all-at-once IN constraint 10532 ** processing using the [sqlite3_vtab_in()] interface in the 10533 ** [xBestIndex|xBestIndex method]. ^(If the X parameter is not 10534 ** an xFilter argument that was selected for all-at-once IN constraint 10535 ** processing, then these routines return [SQLITE_ERROR].)^ 10536 ** 10537 ** ^(Use these routines to access all values on the right-hand side 10538 ** of the IN constraint using code like the following: 10539 ** 10540 ** <blockquote><pre> 10541 ** for(rc=sqlite3_vtab_in_first(pList, &pVal); 10542 ** rc==SQLITE_OK && pVal; 10543 ** rc=sqlite3_vtab_in_next(pList, &pVal) 10544 ** ){ 10545 ** // do something with pVal 10546 ** } 10547 ** if( rc!=SQLITE_DONE ){ 10548 ** // an error has occurred 10549 ** } 10550 ** </pre></blockquote>)^ 10551 ** 10552 ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P) 10553 ** routines return SQLITE_OK and set *P to point to the first or next value 10554 ** on the RHS of the IN constraint. ^If there are no more values on the 10555 ** right hand side of the IN constraint, then *P is set to NULL and these 10556 ** routines return [SQLITE_DONE]. ^The return value might be 10557 ** some other value, such as SQLITE_NOMEM, in the event of a malfunction. 10558 ** 10559 ** The *ppOut values returned by these routines are only valid until the 10560 ** next call to either of these routines or until the end of the xFilter 10561 ** method from which these routines were called. If the virtual table 10562 ** implementation needs to retain the *ppOut values for longer, it must make 10563 ** copies. The *ppOut values are [protected sqlite3_value|protected]. 10564 */ 10565 SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut); 10566 SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut); 10567 10568 /* 10569 ** CAPI3REF: Constraint values in xBestIndex() 10570 ** METHOD: sqlite3_index_info 10571 ** 10572 ** This API may only be used from within the [xBestIndex|xBestIndex method] 10573 ** of a [virtual table] implementation. The result of calling this interface 10574 ** from outside of an xBestIndex method are undefined and probably harmful. 10575 ** 10576 ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within 10577 ** the [xBestIndex] method of a [virtual table] implementation, with P being 10578 ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and 10579 ** J being a 0-based index into P->aConstraint[], then this routine 10580 ** attempts to set *V to the value of the right-hand operand of 10581 ** that constraint if the right-hand operand is known. ^If the 10582 ** right-hand operand is not known, then *V is set to a NULL pointer. 10583 ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if 10584 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V) 10585 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th 10586 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface 10587 ** can return a result code other than SQLITE_OK or SQLITE_NOTFOUND if 10588 ** something goes wrong. 10589 ** 10590 ** The sqlite3_vtab_rhs_value() interface is usually only successful if 10591 ** the right-hand operand of a constraint is a literal value in the original 10592 ** SQL statement. If the right-hand operand is an expression or a reference 10593 ** to some other column or a [host parameter], then sqlite3_vtab_rhs_value() 10594 ** will probably return [SQLITE_NOTFOUND]. 10595 ** 10596 ** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and 10597 ** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such 10598 ** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^ 10599 ** 10600 ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value 10601 ** and remains valid for the duration of the xBestIndex method call. 10602 ** ^When xBestIndex returns, the sqlite3_value object returned by 10603 ** sqlite3_vtab_rhs_value() is automatically deallocated. 10604 ** 10605 ** The "_rhs_" in the name of this routine is an abbreviation for 10606 ** "Right-Hand Side". 10607 */ 10608 SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); 10609 10610 /* 10611 ** CAPI3REF: Conflict resolution modes 10612 ** KEYWORDS: {conflict resolution mode} 10613 ** 10614 ** These constants are returned by [sqlite3_vtab_on_conflict()] to 10615 ** inform a [virtual table] implementation of the [ON CONFLICT] mode 10616 ** for the SQL statement being evaluated. 10617 ** 10618 ** Note that the [SQLITE_IGNORE] constant is also used as a potential 10619 ** return value from the [sqlite3_set_authorizer()] callback and that 10620 ** [SQLITE_ABORT] is also a [result code]. 10621 */ 10622 #define SQLITE_ROLLBACK 1 10623 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ 10624 #define SQLITE_FAIL 3 10625 /* #define SQLITE_ABORT 4 // Also an error code */ 10626 #define SQLITE_REPLACE 5 10627 10628 /* 10629 ** CAPI3REF: Prepared Statement Scan Status Opcodes 10630 ** KEYWORDS: {scanstatus options} 10631 ** 10632 ** The following constants can be used for the T parameter to the 10633 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a 10634 ** different metric for sqlite3_stmt_scanstatus() to return. 10635 ** 10636 ** When the value returned to V is a string, space to hold that string is 10637 ** managed by the prepared statement S and will be automatically freed when 10638 ** S is finalized. 10639 ** 10640 ** Not all values are available for all query elements. When a value is 10641 ** not available, the output variable is set to -1 if the value is numeric, 10642 ** or to NULL if it is a string (SQLITE_SCANSTAT_NAME). 10643 ** 10644 ** <dl> 10645 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt> 10646 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be 10647 ** set to the total number of times that the X-th loop has run.</dd> 10648 ** 10649 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt> 10650 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set 10651 ** to the total number of rows examined by all iterations of the X-th loop.</dd> 10652 ** 10653 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt> 10654 ** <dd>^The "double" variable pointed to by the V parameter will be set to the 10655 ** query planner's estimate for the average number of rows output from each 10656 ** iteration of the X-th loop. If the query planner's estimate was accurate, 10657 ** then this value will approximate the quotient NVISIT/NLOOP and the 10658 ** product of this value for all prior loops with the same SELECTID will 10659 ** be the NLOOP value for the current loop.</dd> 10660 ** 10661 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt> 10662 ** <dd>^The "const char *" variable pointed to by the V parameter will be set 10663 ** to a zero-terminated UTF-8 string containing the name of the index or table 10664 ** used for the X-th loop.</dd> 10665 ** 10666 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt> 10667 ** <dd>^The "const char *" variable pointed to by the V parameter will be set 10668 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN] 10669 ** description for the X-th loop.</dd> 10670 ** 10671 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt> 10672 ** <dd>^The "int" variable pointed to by the V parameter will be set to the 10673 ** id for the X-th query plan element. The id value is unique within the 10674 ** statement. The select-id is the same value as is output in the first 10675 ** column of an [EXPLAIN QUERY PLAN] query.</dd> 10676 ** 10677 ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt> 10678 ** <dd>The "int" variable pointed to by the V parameter will be set to the 10679 ** id of the parent of the current query element, if applicable, or 10680 ** to zero if the query element has no parent. This is the same value as 10681 ** returned in the second column of an [EXPLAIN QUERY PLAN] query.</dd> 10682 ** 10683 ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt> 10684 ** <dd>The sqlite3_int64 output value is set to the number of cycles, 10685 ** according to the processor time-stamp counter, that elapsed while the 10686 ** query element was being processed. This value is not available for 10687 ** all query elements - if it is unavailable the output variable is 10688 ** set to -1.</dd> 10689 ** </dl> 10690 */ 10691 #define SQLITE_SCANSTAT_NLOOP 0 10692 #define SQLITE_SCANSTAT_NVISIT 1 10693 #define SQLITE_SCANSTAT_EST 2 10694 #define SQLITE_SCANSTAT_NAME 3 10695 #define SQLITE_SCANSTAT_EXPLAIN 4 10696 #define SQLITE_SCANSTAT_SELECTID 5 10697 #define SQLITE_SCANSTAT_PARENTID 6 10698 #define SQLITE_SCANSTAT_NCYCLE 7 10699 10700 /* 10701 ** CAPI3REF: Prepared Statement Scan Status 10702 ** METHOD: sqlite3_stmt 10703 ** 10704 ** These interfaces return information about the predicted and measured 10705 ** performance for pStmt. Advanced applications can use this 10706 ** interface to compare the predicted and the measured performance and 10707 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found. 10708 ** 10709 ** Since this interface is expected to be rarely used, it is only 10710 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS] 10711 ** compile-time option. 10712 ** 10713 ** The "iScanStatusOp" parameter determines which status information to return. 10714 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior 10715 ** of this interface is undefined. ^The requested measurement is written into 10716 ** a variable pointed to by the "pOut" parameter. 10717 ** 10718 ** The "flags" parameter must be passed a mask of flags. At present only 10719 ** one flag is defined - [SQLITE_SCANSTAT_COMPLEX]. If SQLITE_SCANSTAT_COMPLEX 10720 ** is specified, then status information is available for all elements 10721 ** of a query plan that are reported by "[EXPLAIN QUERY PLAN]" output. If 10722 ** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements 10723 ** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of 10724 ** the EXPLAIN QUERY PLAN output) are available. Invoking API 10725 ** sqlite3_stmt_scanstatus() is equivalent to calling 10726 ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter. 10727 ** 10728 ** Parameter "idx" identifies the specific query element to retrieve statistics 10729 ** for. Query elements are numbered starting from zero. A value of -1 may 10730 ** retrieve statistics for the entire query. ^If idx is out of range 10731 ** - less than -1 or greater than or equal to the total number of query 10732 ** elements used to implement the statement - a non-zero value is returned and 10733 ** the variable that pOut points to is unchanged. 10734 ** 10735 ** See also: [sqlite3_stmt_scanstatus_reset()] and the 10736 ** [nexec and ncycle] columns of the [bytecode virtual table]. 10737 */ 10738 SQLITE_API int sqlite3_stmt_scanstatus( 10739 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ 10740 int idx, /* Index of loop to report on */ 10741 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ 10742 void *pOut /* Result written here */ 10743 ); 10744 SQLITE_API int sqlite3_stmt_scanstatus_v2( 10745 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ 10746 int idx, /* Index of loop to report on */ 10747 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ 10748 int flags, /* Mask of flags defined below */ 10749 void *pOut /* Result written here */ 10750 ); 10751 10752 /* 10753 ** CAPI3REF: Prepared Statement Scan Status 10754 ** KEYWORDS: {scan status flags} 10755 */ 10756 #define SQLITE_SCANSTAT_COMPLEX 0x0001 10757 10758 /* 10759 ** CAPI3REF: Zero Scan-Status Counters 10760 ** METHOD: sqlite3_stmt 10761 ** 10762 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters. 10763 ** 10764 ** This API is only available if the library is built with pre-processor 10765 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. 10766 */ 10767 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); 10768 10769 /* 10770 ** CAPI3REF: Flush caches to disk mid-transaction 10771 ** METHOD: sqlite3 10772 ** 10773 ** ^If a write-transaction is open on [database connection] D when the 10774 ** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty 10775 ** pages in the pager-cache that are not currently in use are written out 10776 ** to disk. A dirty page may be in use if a database cursor created by an 10777 ** active SQL statement is reading from it, or if it is page 1 of a database 10778 ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)] 10779 ** interface flushes caches for all schemas - "main", "temp", and 10780 ** any [attached] databases. 10781 ** 10782 ** ^If this function needs to obtain extra database locks before dirty pages 10783 ** can be flushed to disk, it does so. ^If those locks cannot be obtained 10784 ** immediately and there is a busy-handler callback configured, it is invoked 10785 ** in the usual manner. ^If the required lock still cannot be obtained, then 10786 ** the database is skipped and an attempt made to flush any dirty pages 10787 ** belonging to the next (if any) database. ^If any databases are skipped 10788 ** because locks cannot be obtained, but no other error occurs, this 10789 ** function returns SQLITE_BUSY. 10790 ** 10791 ** ^If any other error occurs while flushing dirty pages to disk (for 10792 ** example an IO error or out-of-memory condition), then processing is 10793 ** abandoned and an SQLite [error code] is returned to the caller immediately. 10794 ** 10795 ** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK. 10796 ** 10797 ** ^This function does not set the database handle error code or message 10798 ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions. 10799 */ 10800 SQLITE_API int sqlite3_db_cacheflush(sqlite3*); 10801 10802 /* 10803 ** CAPI3REF: The pre-update hook. 10804 ** METHOD: sqlite3 10805 ** 10806 ** ^These interfaces are only available if SQLite is compiled using the 10807 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. 10808 ** 10809 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function 10810 ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation 10811 ** on a database table. 10812 ** ^At most one preupdate hook may be registered at a time on a single 10813 ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides 10814 ** the previous setting. 10815 ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] 10816 ** with a NULL pointer as the second parameter. 10817 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as 10818 ** the first parameter to callbacks. 10819 ** 10820 ** ^The preupdate hook only fires for changes to real database tables; the 10821 ** preupdate hook is not invoked for changes to [virtual tables] or to 10822 ** system tables like sqlite_sequence or sqlite_stat1. 10823 ** 10824 ** ^The second parameter to the preupdate callback is a pointer to 10825 ** the [database connection] that registered the preupdate hook. 10826 ** ^The third parameter to the preupdate callback is one of the constants 10827 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the 10828 ** kind of update operation that is about to occur. 10829 ** ^(The fourth parameter to the preupdate callback is the name of the 10830 ** database within the database connection that is being modified. This 10831 ** will be "main" for the main database or "temp" for TEMP tables or 10832 ** the name given after the AS keyword in the [ATTACH] statement for attached 10833 ** databases.)^ 10834 ** ^The fifth parameter to the preupdate callback is the name of the 10835 ** table that is being modified. 10836 ** 10837 ** For an UPDATE or DELETE operation on a [rowid table], the sixth 10838 ** parameter passed to the preupdate callback is the initial [rowid] of the 10839 ** row being modified or deleted. For an INSERT operation on a rowid table, 10840 ** or any operation on a WITHOUT ROWID table, the value of the sixth 10841 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the 10842 ** seventh parameter is the final rowid value of the row being inserted 10843 ** or updated. The value of the seventh parameter passed to the callback 10844 ** function is not defined for operations on WITHOUT ROWID tables, or for 10845 ** DELETE operations on rowid tables. 10846 ** 10847 ** ^The sqlite3_preupdate_hook(D,C,P) function returns the P argument from 10848 ** the previous call on the same [database connection] D, or NULL for 10849 ** the first call on D. 10850 ** 10851 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], 10852 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces 10853 ** provide additional information about a preupdate event. These routines 10854 ** may only be called from within a preupdate callback. Invoking any of 10855 ** these routines from outside of a preupdate callback or with a 10856 ** [database connection] pointer that is different from the one supplied 10857 ** to the preupdate callback results in undefined and probably undesirable 10858 ** behavior. 10859 ** 10860 ** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns 10861 ** in the row that is being inserted, updated, or deleted. 10862 ** 10863 ** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to 10864 ** a [protected sqlite3_value] that contains the value of the Nth column of 10865 ** the table row before it is updated. The N parameter must be between 0 10866 ** and one less than the number of columns or the behavior will be 10867 ** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE 10868 ** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the 10869 ** behavior is undefined. The [sqlite3_value] that P points to 10870 ** will be destroyed when the preupdate callback returns. 10871 ** 10872 ** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to 10873 ** a [protected sqlite3_value] that contains the value of the Nth column of 10874 ** the table row after it is updated. The N parameter must be between 0 10875 ** and one less than the number of columns or the behavior will be 10876 ** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE 10877 ** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the 10878 ** behavior is undefined. The [sqlite3_value] that P points to 10879 ** will be destroyed when the preupdate callback returns. 10880 ** 10881 ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate 10882 ** callback was invoked as a result of a direct insert, update, or delete 10883 ** operation; or 1 for inserts, updates, or deletes invoked by top-level 10884 ** triggers; or 2 for changes resulting from triggers called by top-level 10885 ** triggers; and so forth. 10886 ** 10887 ** When the [sqlite3_blob_write()] API is used to update a blob column, 10888 ** the pre-update hook is invoked with SQLITE_DELETE, because 10889 ** the new values are not yet available. In this case, when a 10890 ** callback made with op==SQLITE_DELETE is actually a write using the 10891 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns 10892 ** the index of the column being written. In other cases, where the 10893 ** pre-update hook is being invoked for some other reason, including a 10894 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. 10895 ** 10896 ** See also: [sqlite3_update_hook()] 10897 */ 10898 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK) 10899 SQLITE_API void *sqlite3_preupdate_hook( 10900 sqlite3 *db, 10901 void(*xPreUpdate)( 10902 void *pCtx, /* Copy of third arg to preupdate_hook() */ 10903 sqlite3 *db, /* Database handle */ 10904 int op, /* SQLITE_UPDATE, DELETE or INSERT */ 10905 char const *zDb, /* Database name */ 10906 char const *zName, /* Table name */ 10907 sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */ 10908 sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */ 10909 ), 10910 void* 10911 ); 10912 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **); 10913 SQLITE_API int sqlite3_preupdate_count(sqlite3 *); 10914 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *); 10915 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **); 10916 SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *); 10917 #endif 10918 10919 /* 10920 ** CAPI3REF: Low-level system error code 10921 ** METHOD: sqlite3 10922 ** 10923 ** ^Attempt to return the underlying operating system error code or error 10924 ** number that caused the most recent I/O error or failure to open a file. 10925 ** The return value is OS-dependent. For example, on unix systems, after 10926 ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be 10927 ** called to get back the underlying "errno" that caused the problem, such 10928 ** as ENOSPC, EAUTH, EISDIR, and so forth. 10929 */ 10930 SQLITE_API int sqlite3_system_errno(sqlite3*); 10931 10932 /* 10933 ** CAPI3REF: Database Snapshot 10934 ** KEYWORDS: {snapshot} {sqlite3_snapshot} 10935 ** 10936 ** An instance of the snapshot object records the state of a [WAL mode] 10937 ** database for some specific point in history. 10938 ** 10939 ** In [WAL mode], multiple [database connections] that are open on the 10940 ** same database file can each be reading a different historical version 10941 ** of the database file. When a [database connection] begins a read 10942 ** transaction, that connection sees an unchanging copy of the database 10943 ** as it existed for the point in time when the transaction first started. 10944 ** Subsequent changes to the database from other connections are not seen 10945 ** by the reader until a new read transaction is started. 10946 ** 10947 ** The sqlite3_snapshot object records state information about an historical 10948 ** version of the database file so that it is possible to later open a new read 10949 ** transaction that sees that historical version of the database rather than 10950 ** the most recent version. 10951 */ 10952 typedef struct sqlite3_snapshot { 10953 unsigned char hidden[48]; 10954 } sqlite3_snapshot; 10955 10956 /* 10957 ** CAPI3REF: Record A Database Snapshot 10958 ** CONSTRUCTOR: sqlite3_snapshot 10959 ** 10960 ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a 10961 ** new [sqlite3_snapshot] object that records the current state of 10962 ** schema S in database connection D. ^On success, the 10963 ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly 10964 ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK. 10965 ** If there is not already a read-transaction open on schema S when 10966 ** this function is called, one is opened automatically. 10967 ** 10968 ** If a read-transaction is opened by this function, then it is guaranteed 10969 ** that the returned snapshot object may not be invalidated by a database 10970 ** writer or checkpointer until after the read-transaction is closed. This 10971 ** is not guaranteed if a read-transaction is already open when this 10972 ** function is called. In that case, any subsequent write or checkpoint 10973 ** operation on the database may invalidate the returned snapshot handle, 10974 ** even while the read-transaction remains open. 10975 ** 10976 ** The following must be true for this function to succeed. If any of 10977 ** the following statements are false when sqlite3_snapshot_get() is 10978 ** called, SQLITE_ERROR is returned. The final value of *P is undefined 10979 ** in this case. 10980 ** 10981 ** <ul> 10982 ** <li> The database handle must not be in [autocommit mode]. 10983 ** 10984 ** <li> Schema S of [database connection] D must be a [WAL mode] database. 10985 ** 10986 ** <li> There must not be a write transaction open on schema S of database 10987 ** connection D. 10988 ** 10989 ** <li> One or more transactions must have been written to the current wal 10990 ** file since it was created on disk (by any connection). This means 10991 ** that a snapshot cannot be taken on a wal mode database with no wal 10992 ** file immediately after it is first opened. At least one transaction 10993 ** must be written to it first. 10994 ** </ul> 10995 ** 10996 ** This function may also return SQLITE_NOMEM. If it is called with the 10997 ** database handle in autocommit mode but fails for some other reason, 10998 ** whether or not a read transaction is opened on schema S is undefined. 10999 ** 11000 ** The [sqlite3_snapshot] object returned from a successful call to 11001 ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()] 11002 ** to avoid a memory leak. 11003 ** 11004 ** The [sqlite3_snapshot_get()] interface is only available when the 11005 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. 11006 */ 11007 SQLITE_API int sqlite3_snapshot_get( 11008 sqlite3 *db, 11009 const char *zSchema, 11010 sqlite3_snapshot **ppSnapshot 11011 ); 11012 11013 /* 11014 ** CAPI3REF: Start a read transaction on an historical snapshot 11015 ** METHOD: sqlite3_snapshot 11016 ** 11017 ** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read 11018 ** transaction or upgrades an existing one for schema S of 11019 ** [database connection] D such that the read transaction refers to 11020 ** historical [snapshot] P, rather than the most recent change to the 11021 ** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK 11022 ** on success or an appropriate [error code] if it fails. 11023 ** 11024 ** ^In order to succeed, the database connection must not be in 11025 ** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there 11026 ** is already a read transaction open on schema S, then the database handle 11027 ** must have no active statements (SELECT statements that have been passed 11028 ** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()). 11029 ** SQLITE_ERROR is returned if either of these conditions is violated, or 11030 ** if schema S does not exist, or if the snapshot object is invalid. 11031 ** 11032 ** ^A call to sqlite3_snapshot_open() will fail to open if the specified 11033 ** snapshot has been overwritten by a [checkpoint]. In this case 11034 ** SQLITE_ERROR_SNAPSHOT is returned. 11035 ** 11036 ** If there is already a read transaction open when this function is 11037 ** invoked, then the same read transaction remains open (on the same 11038 ** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT 11039 ** is returned. If another error code - for example SQLITE_PROTOCOL or an 11040 ** SQLITE_IOERR error code - is returned, then the final state of the 11041 ** read transaction is undefined. If SQLITE_OK is returned, then the 11042 ** read transaction is now open on database snapshot P. 11043 ** 11044 ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the 11045 ** database connection D does not know that the database file for 11046 ** schema S is in [WAL mode]. A database connection might not know 11047 ** that the database file is in [WAL mode] if there has been no prior 11048 ** I/O on that database connection, or if the database entered [WAL mode] 11049 ** after the most recent I/O on the database connection.)^ 11050 ** (Hint: Run "[PRAGMA application_id]" against a newly opened 11051 ** database connection in order to make it ready to use snapshots.) 11052 ** 11053 ** The [sqlite3_snapshot_open()] interface is only available when the 11054 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. 11055 */ 11056 SQLITE_API int sqlite3_snapshot_open( 11057 sqlite3 *db, 11058 const char *zSchema, 11059 sqlite3_snapshot *pSnapshot 11060 ); 11061 11062 /* 11063 ** CAPI3REF: Destroy a snapshot 11064 ** DESTRUCTOR: sqlite3_snapshot 11065 ** 11066 ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P. 11067 ** The application must eventually free every [sqlite3_snapshot] object 11068 ** using this routine to avoid a memory leak. 11069 ** 11070 ** The [sqlite3_snapshot_free()] interface is only available when the 11071 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. 11072 */ 11073 SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*); 11074 11075 /* 11076 ** CAPI3REF: Compare the ages of two snapshot handles. 11077 ** METHOD: sqlite3_snapshot 11078 ** 11079 ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages 11080 ** of two valid snapshot handles. 11081 ** 11082 ** If the two snapshot handles are not associated with the same database 11083 ** file, the result of the comparison is undefined. 11084 ** 11085 ** Additionally, the result of the comparison is only valid if both of the 11086 ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the 11087 ** last time the wal file was deleted. The wal file is deleted when the 11088 ** database is changed back to rollback mode or when the number of database 11089 ** clients drops to zero. If either snapshot handle was obtained before the 11090 ** wal file was last deleted, the value returned by this function 11091 ** is undefined. 11092 ** 11093 ** Otherwise, this API returns a negative value if P1 refers to an older 11094 ** snapshot than P2, zero if the two handles refer to the same database 11095 ** snapshot, and a positive value if P1 is a newer snapshot than P2. 11096 ** 11097 ** This interface is only available if SQLite is compiled with the 11098 ** [SQLITE_ENABLE_SNAPSHOT] option. 11099 */ 11100 SQLITE_API int sqlite3_snapshot_cmp( 11101 sqlite3_snapshot *p1, 11102 sqlite3_snapshot *p2 11103 ); 11104 11105 /* 11106 ** CAPI3REF: Recover snapshots from a wal file 11107 ** METHOD: sqlite3_snapshot 11108 ** 11109 ** If a [WAL file] remains on disk after all database connections close 11110 ** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control] 11111 ** or because the last process to have the database opened exited without 11112 ** calling [sqlite3_close()]) and a new connection is subsequently opened 11113 ** on that database and [WAL file], the [sqlite3_snapshot_open()] interface 11114 ** will only be able to open the last transaction added to the WAL file 11115 ** even though the WAL file contains other valid transactions. 11116 ** 11117 ** This function attempts to scan the WAL file associated with database zDb 11118 ** of database handle db and make all valid snapshots available to 11119 ** sqlite3_snapshot_open(). It is an error if there is already a read 11120 ** transaction open on the database, or if the database is not a WAL mode 11121 ** database. 11122 ** 11123 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. 11124 ** 11125 ** This interface is only available if SQLite is compiled with the 11126 ** [SQLITE_ENABLE_SNAPSHOT] option. 11127 */ 11128 SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); 11129 11130 /* 11131 ** CAPI3REF: Serialize a database 11132 ** 11133 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to 11134 ** memory that is a serialization of the S database on 11135 ** [database connection] D. If S is a NULL pointer, the main database is used. 11136 ** If P is not a NULL pointer, then the size of the database in bytes 11137 ** is written into *P. 11138 ** 11139 ** For an ordinary on-disk database file, the serialization is just a 11140 ** copy of the disk file. For an in-memory database or a "TEMP" database, 11141 ** the serialization is the same sequence of bytes which would be written 11142 ** to disk if that database were backed up to disk. 11143 ** 11144 ** The usual case is that sqlite3_serialize() copies the serialization of 11145 ** the database into memory obtained from [sqlite3_malloc64()] and returns 11146 ** a pointer to that memory. The caller is responsible for freeing the 11147 ** returned value to avoid a memory leak. However, if the F argument 11148 ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations 11149 ** are made, and the sqlite3_serialize() function will return a pointer 11150 ** to the contiguous memory representation of the database that SQLite 11151 ** is currently using for that database, or NULL if no such contiguous 11152 ** memory representation of the database exists. A contiguous memory 11153 ** representation of the database will usually only exist if there has 11154 ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same 11155 ** values of D and S. 11156 ** The size of the database is written into *P even if the 11157 ** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy 11158 ** of the database exists. 11159 ** 11160 ** After the call, if the SQLITE_SERIALIZE_NOCOPY bit had been set, 11161 ** the returned buffer content will remain accessible and unchanged 11162 ** until either the next write operation on the connection or when 11163 ** the connection is closed, and applications must not modify the 11164 ** buffer. If the bit had been clear, the returned buffer will not 11165 ** be accessed by SQLite after the call. 11166 ** 11167 ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the 11168 ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory 11169 ** allocation error occurs. 11170 ** 11171 ** This interface is omitted if SQLite is compiled with the 11172 ** [SQLITE_OMIT_DESERIALIZE] option. 11173 */ 11174 SQLITE_API unsigned char *sqlite3_serialize( 11175 sqlite3 *db, /* The database connection */ 11176 const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */ 11177 sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */ 11178 unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */ 11179 ); 11180 11181 /* 11182 ** CAPI3REF: Flags for sqlite3_serialize 11183 ** 11184 ** Zero or more of the following constants can be OR-ed together for 11185 ** the F argument to [sqlite3_serialize(D,S,P,F)]. 11186 ** 11187 ** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return 11188 ** a pointer to contiguous in-memory database that it is currently using, 11189 ** without making a copy of the database. If SQLite is not currently using 11190 ** a contiguous in-memory database, then this option causes 11191 ** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be 11192 ** using a contiguous in-memory database if it has been initialized by a 11193 ** prior call to [sqlite3_deserialize()]. 11194 */ 11195 #define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */ 11196 11197 /* 11198 ** CAPI3REF: Deserialize a database 11199 ** 11200 ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the 11201 ** [database connection] D to disconnect from database S and then 11202 ** reopen S as an in-memory database based on the serialization 11203 ** contained in P. If S is a NULL pointer, the main database is 11204 ** used. The serialized database P is N bytes in size. M is the size 11205 ** of the buffer P, which might be larger than N. If M is larger than 11206 ** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then 11207 ** SQLite is permitted to add content to the in-memory database as 11208 ** long as the total size does not exceed M bytes. 11209 ** 11210 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will 11211 ** invoke sqlite3_free() on the serialization buffer when the database 11212 ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then 11213 ** SQLite will try to increase the buffer size using sqlite3_realloc64() 11214 ** if writes on the database cause it to grow larger than M bytes. 11215 ** 11216 ** Applications must not modify the buffer P or invalidate it before 11217 ** the database connection D is closed. 11218 ** 11219 ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the 11220 ** database is currently in a read transaction or is involved in a backup 11221 ** operation. 11222 ** 11223 ** It is not possible to deserialize into the TEMP database. If the 11224 ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the 11225 ** function returns SQLITE_ERROR. 11226 ** 11227 ** The deserialized database should not be in [WAL mode]. If the database 11228 ** is in WAL mode, then any attempt to use the database file will result 11229 ** in an [SQLITE_CANTOPEN] error. The application can set the 11230 ** [file format version numbers] (bytes 18 and 19) of the input database P 11231 ** to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the 11232 ** database file into rollback mode and work around this limitation. 11233 ** 11234 ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the 11235 ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then 11236 ** [sqlite3_free()] is invoked on argument P prior to returning. 11237 ** 11238 ** This interface is omitted if SQLite is compiled with the 11239 ** [SQLITE_OMIT_DESERIALIZE] option. 11240 */ 11241 SQLITE_API int sqlite3_deserialize( 11242 sqlite3 *db, /* The database connection */ 11243 const char *zSchema, /* Which DB to reopen with the deserialization */ 11244 unsigned char *pData, /* The serialized database content */ 11245 sqlite3_int64 szDb, /* Number of bytes in the deserialization */ 11246 sqlite3_int64 szBuf, /* Total size of buffer pData[] */ 11247 unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */ 11248 ); 11249 11250 /* 11251 ** CAPI3REF: Flags for sqlite3_deserialize() 11252 ** 11253 ** The following are allowed values for the 6th argument (the F argument) to 11254 ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface. 11255 ** 11256 ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization 11257 ** in the P argument is held in memory obtained from [sqlite3_malloc64()] 11258 ** and that SQLite should take ownership of this memory and automatically 11259 ** free it when it has finished using it. Without this flag, the caller 11260 ** is responsible for freeing any dynamically allocated memory. 11261 ** 11262 ** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to 11263 ** grow the size of the database using calls to [sqlite3_realloc64()]. This 11264 ** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used. 11265 ** Without this flag, the deserialized database cannot increase in size beyond 11266 ** the number of bytes specified by the M parameter. 11267 ** 11268 ** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database 11269 ** should be treated as read-only. 11270 */ 11271 #define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */ 11272 #define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */ 11273 #define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */ 11274 11275 /* 11276 ** CAPI3REF: Bind array values to the CARRAY table-valued function 11277 ** 11278 ** The sqlite3_carray_bind_v2(S,I,P,N,F,X,D) interface binds an array value to 11279 ** parameter that is the first argument of the [carray() table-valued function]. 11280 ** The S parameter is a pointer to the [prepared statement] that uses the 11281 ** carray() functions. I is the parameter index to be bound. I must be the 11282 ** index of the parameter that is the first argument to the carray() 11283 ** table-valued function. P is a pointer to the array to be bound, and N 11284 ** is the number of elements in the array. The F argument is one of 11285 ** constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64], 11286 ** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], 11287 ** or [SQLITE_CARRAY_BLOB] to indicate the datatype of the array P. 11288 ** 11289 ** If the X argument is not a NULL pointer or one of the special 11290 ** values [SQLITE_STATIC] or [SQLITE_TRANSIENT], then SQLite will invoke 11291 ** the function X with argument D when it is finished using the data in P. 11292 ** The call to X(D) is a destructor for the array P. The destructor X(D) 11293 ** is invoked even if the call to sqlite3_carray_bind_v2() fails. If the X 11294 ** parameter is the special-case value [SQLITE_STATIC], then SQLite assumes 11295 ** that the data static and the destructor is never invoked. If the X 11296 ** parameter is the special-case value [SQLITE_TRANSIENT], then 11297 ** sqlite3_carray_bind_v2() makes its own private copy of the data prior 11298 ** to returning and never invokes the destructor X. 11299 ** 11300 ** The sqlite3_carray_bind() function works the same as sqlite3_carray_bind_v2() 11301 ** with a D parameter set to P. In other words, 11302 ** sqlite3_carray_bind(S,I,P,N,F,X) is same as 11303 ** sqlite3_carray_bind_v2(S,I,P,N,F,X,P). 11304 */ 11305 SQLITE_API int sqlite3_carray_bind_v2( 11306 sqlite3_stmt *pStmt, /* Statement to be bound */ 11307 int i, /* Parameter index */ 11308 void *aData, /* Pointer to array data */ 11309 int nData, /* Number of data elements */ 11310 int mFlags, /* CARRAY flags */ 11311 void (*xDel)(void*), /* Destructor for aData */ 11312 void *pDel /* Optional argument to xDel() */ 11313 ); 11314 SQLITE_API int sqlite3_carray_bind( 11315 sqlite3_stmt *pStmt, /* Statement to be bound */ 11316 int i, /* Parameter index */ 11317 void *aData, /* Pointer to array data */ 11318 int nData, /* Number of data elements */ 11319 int mFlags, /* CARRAY flags */ 11320 void (*xDel)(void*) /* Destructor for aData */ 11321 ); 11322 11323 /* 11324 ** CAPI3REF: Datatypes for the CARRAY table-valued function 11325 ** 11326 ** The fifth argument to the [sqlite3_carray_bind()] interface musts be 11327 ** one of the following constants, to specify the datatype of the array 11328 ** that is being bound into the [carray table-valued function]. 11329 */ 11330 #define SQLITE_CARRAY_INT32 0 /* Data is 32-bit signed integers */ 11331 #define SQLITE_CARRAY_INT64 1 /* Data is 64-bit signed integers */ 11332 #define SQLITE_CARRAY_DOUBLE 2 /* Data is doubles */ 11333 #define SQLITE_CARRAY_TEXT 3 /* Data is char* */ 11334 #define SQLITE_CARRAY_BLOB 4 /* Data is struct iovec */ 11335 11336 /* 11337 ** Versions of the above #defines that omit the initial SQLITE_, for 11338 ** legacy compatibility. 11339 */ 11340 #define CARRAY_INT32 0 /* Data is 32-bit signed integers */ 11341 #define CARRAY_INT64 1 /* Data is 64-bit signed integers */ 11342 #define CARRAY_DOUBLE 2 /* Data is doubles */ 11343 #define CARRAY_TEXT 3 /* Data is char* */ 11344 #define CARRAY_BLOB 4 /* Data is struct iovec */ 11345 11346 /* 11347 ** Undo the hack that converts floating point types to integer for 11348 ** builds on processors without floating point support. 11349 */ 11350 #ifdef SQLITE_OMIT_FLOATING_POINT 11351 # undef double 11352 #endif 11353 11354 #if defined(__wasi__) 11355 # undef SQLITE_WASI 11356 # define SQLITE_WASI 1 11357 # ifndef SQLITE_OMIT_LOAD_EXTENSION 11358 # define SQLITE_OMIT_LOAD_EXTENSION 11359 # endif 11360 # ifndef SQLITE_THREADSAFE 11361 # define SQLITE_THREADSAFE 0 11362 # endif 11363 #endif 11364 11365 #ifdef __cplusplus 11366 } /* End of the 'extern "C"' block */ 11367 #endif 11368 /* #endif for SQLITE3_H will be added by mksqlite3.tcl */ 11369 11370 /******** Begin file sqlite3rtree.h *********/ 11371 /* 11372 ** 2010 August 30 11373 ** 11374 ** The author disclaims copyright to this source code. In place of 11375 ** a legal notice, here is a blessing: 11376 ** 11377 ** May you do good and not evil. 11378 ** May you find forgiveness for yourself and forgive others. 11379 ** May you share freely, never taking more than you give. 11380 ** 11381 ************************************************************************* 11382 */ 11383 11384 #ifndef _SQLITE3RTREE_H_ 11385 #define _SQLITE3RTREE_H_ 11386 11387 11388 #ifdef __cplusplus 11389 extern "C" { 11390 #endif 11391 11392 typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; 11393 typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info; 11394 11395 /* The double-precision datatype used by RTree depends on the 11396 ** SQLITE_RTREE_INT_ONLY compile-time option. 11397 */ 11398 #ifdef SQLITE_RTREE_INT_ONLY 11399 typedef sqlite3_int64 sqlite3_rtree_dbl; 11400 #else 11401 typedef double sqlite3_rtree_dbl; 11402 #endif 11403 11404 /* 11405 ** Register a geometry callback named zGeom that can be used as part of an 11406 ** R-Tree geometry query as follows: 11407 ** 11408 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 11409 */ 11410 SQLITE_API int sqlite3_rtree_geometry_callback( 11411 sqlite3 *db, 11412 const char *zGeom, 11413 int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*), 11414 void *pContext 11415 ); 11416 11417 11418 /* 11419 ** A pointer to a structure of the following type is passed as the first 11420 ** argument to callbacks registered using rtree_geometry_callback(). 11421 */ 11422 struct sqlite3_rtree_geometry { 11423 void *pContext; /* Copy of pContext passed to s_r_g_c() */ 11424 int nParam; /* Size of array aParam[] */ 11425 sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */ 11426 void *pUser; /* Callback implementation user data */ 11427 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ 11428 }; 11429 11430 /* 11431 ** Register a 2nd-generation geometry callback named zScore that can be 11432 ** used as part of an R-Tree geometry query as follows: 11433 ** 11434 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...) 11435 */ 11436 SQLITE_API int sqlite3_rtree_query_callback( 11437 sqlite3 *db, 11438 const char *zQueryFunc, 11439 int (*xQueryFunc)(sqlite3_rtree_query_info*), 11440 void *pContext, 11441 void (*xDestructor)(void*) 11442 ); 11443 11444 11445 /* 11446 ** A pointer to a structure of the following type is passed as the 11447 ** argument to scored geometry callback registered using 11448 ** sqlite3_rtree_query_callback(). 11449 ** 11450 ** Note that the first 5 fields of this structure are identical to 11451 ** sqlite3_rtree_geometry. This structure is a subclass of 11452 ** sqlite3_rtree_geometry. 11453 */ 11454 struct sqlite3_rtree_query_info { 11455 void *pContext; /* pContext from when function registered */ 11456 int nParam; /* Number of function parameters */ 11457 sqlite3_rtree_dbl *aParam; /* value of function parameters */ 11458 void *pUser; /* callback can use this, if desired */ 11459 void (*xDelUser)(void*); /* function to free pUser */ 11460 sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */ 11461 unsigned int *anQueue; /* Number of pending entries in the queue */ 11462 int nCoord; /* Number of coordinates */ 11463 int iLevel; /* Level of current node or entry */ 11464 int mxLevel; /* The largest iLevel value in the tree */ 11465 sqlite3_int64 iRowid; /* Rowid for current entry */ 11466 sqlite3_rtree_dbl rParentScore; /* Score of parent node */ 11467 int eParentWithin; /* Visibility of parent node */ 11468 int eWithin; /* OUT: Visibility */ 11469 sqlite3_rtree_dbl rScore; /* OUT: Write the score here */ 11470 /* The following fields are only available in 3.8.11 and later */ 11471 sqlite3_value **apSqlParam; /* Original SQL values of parameters */ 11472 }; 11473 11474 /* 11475 ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin. 11476 */ 11477 #define NOT_WITHIN 0 /* Object completely outside of query region */ 11478 #define PARTLY_WITHIN 1 /* Object partially overlaps query region */ 11479 #define FULLY_WITHIN 2 /* Object fully contained within query region */ 11480 11481 11482 #ifdef __cplusplus 11483 } /* end of the 'extern "C"' block */ 11484 #endif 11485 11486 #endif /* ifndef _SQLITE3RTREE_H_ */ 11487 11488 /******** End of sqlite3rtree.h *********/ 11489 /******** Begin file sqlite3session.h *********/ 11490 11491 #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) 11492 #define __SQLITESESSION_H_ 1 11493 11494 /* 11495 ** Make sure we can call this stuff from C++. 11496 */ 11497 #ifdef __cplusplus 11498 extern "C" { 11499 #endif 11500 11501 11502 /* 11503 ** CAPI3REF: Session Object Handle 11504 ** 11505 ** An instance of this object is a [session] that can be used to 11506 ** record changes to a database. 11507 */ 11508 typedef struct sqlite3_session sqlite3_session; 11509 11510 /* 11511 ** CAPI3REF: Changeset Iterator Handle 11512 ** 11513 ** An instance of this object acts as a cursor for iterating 11514 ** over the elements of a [changeset] or [patchset]. 11515 */ 11516 typedef struct sqlite3_changeset_iter sqlite3_changeset_iter; 11517 11518 /* 11519 ** CAPI3REF: Create A New Session Object 11520 ** CONSTRUCTOR: sqlite3_session 11521 ** 11522 ** Create a new session object attached to database handle db. If successful, 11523 ** a pointer to the new object is written to *ppSession and SQLITE_OK is 11524 ** returned. If an error occurs, *ppSession is set to NULL and an SQLite 11525 ** error code (e.g. SQLITE_NOMEM) is returned. 11526 ** 11527 ** It is possible to create multiple session objects attached to a single 11528 ** database handle. 11529 ** 11530 ** Session objects created using this function should be deleted using the 11531 ** [sqlite3session_delete()] function before the database handle that they 11532 ** are attached to is itself closed. If the database handle is closed before 11533 ** the session object is deleted, then the results of calling any session 11534 ** module function, including [sqlite3session_delete()] on the session object 11535 ** are undefined. 11536 ** 11537 ** Because the session module uses the [sqlite3_preupdate_hook()] API, it 11538 ** is not possible for an application to register a pre-update hook on a 11539 ** database handle that has one or more session objects attached. Nor is 11540 ** it possible to create a session object attached to a database handle for 11541 ** which a pre-update hook is already defined. The results of attempting 11542 ** either of these things are undefined. 11543 ** 11544 ** The session object will be used to create changesets for tables in 11545 ** database zDb, where zDb is either "main", or "temp", or the name of an 11546 ** attached database. It is not an error if database zDb is not attached 11547 ** to the database when the session object is created. 11548 */ 11549 SQLITE_API int sqlite3session_create( 11550 sqlite3 *db, /* Database handle */ 11551 const char *zDb, /* Name of db (e.g. "main") */ 11552 sqlite3_session **ppSession /* OUT: New session object */ 11553 ); 11554 11555 /* 11556 ** CAPI3REF: Delete A Session Object 11557 ** DESTRUCTOR: sqlite3_session 11558 ** 11559 ** Delete a session object previously allocated using 11560 ** [sqlite3session_create()]. Once a session object has been deleted, the 11561 ** results of attempting to use pSession with any other session module 11562 ** function are undefined. 11563 ** 11564 ** Session objects must be deleted before the database handle to which they 11565 ** are attached is closed. Refer to the documentation for 11566 ** [sqlite3session_create()] for details. 11567 */ 11568 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession); 11569 11570 /* 11571 ** CAPI3REF: Configure a Session Object 11572 ** METHOD: sqlite3_session 11573 ** 11574 ** This method is used to configure a session object after it has been 11575 ** created. At present the only valid values for the second parameter are 11576 ** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID]. 11577 ** 11578 */ 11579 SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg); 11580 11581 /* 11582 ** CAPI3REF: Options for sqlite3session_object_config 11583 ** 11584 ** The following values may passed as the the 2nd parameter to 11585 ** sqlite3session_object_config(). 11586 ** 11587 ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd> 11588 ** This option is used to set, clear or query the flag that enables 11589 ** the [sqlite3session_changeset_size()] API. Because it imposes some 11590 ** computational overhead, this API is disabled by default. Argument 11591 ** pArg must point to a value of type (int). If the value is initially 11592 ** 0, then the sqlite3session_changeset_size() API is disabled. If it 11593 ** is greater than 0, then the same API is enabled. Or, if the initial 11594 ** value is less than zero, no change is made. In all cases the (int) 11595 ** variable is set to 1 if the sqlite3session_changeset_size() API is 11596 ** enabled following the current call, or 0 otherwise. 11597 ** 11598 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after 11599 ** the first table has been attached to the session object. 11600 ** 11601 ** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd> 11602 ** This option is used to set, clear or query the flag that enables 11603 ** collection of data for tables with no explicit PRIMARY KEY. 11604 ** 11605 ** Normally, tables with no explicit PRIMARY KEY are simply ignored 11606 ** by the sessions module. However, if this flag is set, it behaves 11607 ** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted 11608 ** as their leftmost columns. 11609 ** 11610 ** It is an error (SQLITE_MISUSE) to attempt to modify this setting after 11611 ** the first table has been attached to the session object. 11612 */ 11613 #define SQLITE_SESSION_OBJCONFIG_SIZE 1 11614 #define SQLITE_SESSION_OBJCONFIG_ROWID 2 11615 11616 /* 11617 ** CAPI3REF: Enable Or Disable A Session Object 11618 ** METHOD: sqlite3_session 11619 ** 11620 ** Enable or disable the recording of changes by a session object. When 11621 ** enabled, a session object records changes made to the database. When 11622 ** disabled - it does not. A newly created session object is enabled. 11623 ** Refer to the documentation for [sqlite3session_changeset()] for further 11624 ** details regarding how enabling and disabling a session object affects 11625 ** the eventual changesets. 11626 ** 11627 ** Passing zero to this function disables the session. Passing a value 11628 ** greater than zero enables it. Passing a value less than zero is a 11629 ** no-op, and may be used to query the current state of the session. 11630 ** 11631 ** The return value indicates the final state of the session object: 0 if 11632 ** the session is disabled, or 1 if it is enabled. 11633 */ 11634 SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable); 11635 11636 /* 11637 ** CAPI3REF: Set Or Clear the Indirect Change Flag 11638 ** METHOD: sqlite3_session 11639 ** 11640 ** Each change recorded by a session object is marked as either direct or 11641 ** indirect. A change is marked as indirect if either: 11642 ** 11643 ** <ul> 11644 ** <li> The session object "indirect" flag is set when the change is 11645 ** made, or 11646 ** <li> The change is made by an SQL trigger or foreign key action 11647 ** instead of directly as a result of a users SQL statement. 11648 ** </ul> 11649 ** 11650 ** If a single row is affected by more than one operation within a session, 11651 ** then the change is considered indirect if all operations meet the criteria 11652 ** for an indirect change above, or direct otherwise. 11653 ** 11654 ** This function is used to set, clear or query the session object indirect 11655 ** flag. If the second argument passed to this function is zero, then the 11656 ** indirect flag is cleared. If it is greater than zero, the indirect flag 11657 ** is set. Passing a value less than zero does not modify the current value 11658 ** of the indirect flag, and may be used to query the current state of the 11659 ** indirect flag for the specified session object. 11660 ** 11661 ** The return value indicates the final state of the indirect flag: 0 if 11662 ** it is clear, or 1 if it is set. 11663 */ 11664 SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect); 11665 11666 /* 11667 ** CAPI3REF: Attach A Table To A Session Object 11668 ** METHOD: sqlite3_session 11669 ** 11670 ** If argument zTab is not NULL, then it is the name of a table to attach 11671 ** to the session object passed as the first argument. All subsequent changes 11672 ** made to the table while the session object is enabled will be recorded. See 11673 ** documentation for [sqlite3session_changeset()] for further details. 11674 ** 11675 ** Or, if argument zTab is NULL, then changes are recorded for all tables 11676 ** in the database. If additional tables are added to the database (by 11677 ** executing "CREATE TABLE" statements) after this call is made, changes for 11678 ** the new tables are also recorded. 11679 ** 11680 ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly 11681 ** defined as part of their CREATE TABLE statement. It does not matter if the 11682 ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY 11683 ** KEY may consist of a single column, or may be a composite key. 11684 ** 11685 ** It is not an error if the named table does not exist in the database. Nor 11686 ** is it an error if the named table does not have a PRIMARY KEY. However, 11687 ** no changes will be recorded in either of these scenarios. 11688 ** 11689 ** Changes are not recorded for individual rows that have NULL values stored 11690 ** in one or more of their PRIMARY KEY columns. 11691 ** 11692 ** SQLITE_OK is returned if the call completes without error. Or, if an error 11693 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned. 11694 ** 11695 ** <h3>Special sqlite_stat1 Handling</h3> 11696 ** 11697 ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to 11698 ** some of the rules above. In SQLite, the schema of sqlite_stat1 is: 11699 ** <pre> 11700 ** CREATE TABLE sqlite_stat1(tbl,idx,stat) 11701 ** </pre> 11702 ** 11703 ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are 11704 ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes 11705 ** are recorded for rows for which (idx IS NULL) is true. However, for such 11706 ** rows a zero-length blob (SQL value X'') is stored in the changeset or 11707 ** patchset instead of a NULL value. This allows such changesets to be 11708 ** manipulated by legacy implementations of sqlite3changeset_invert(), 11709 ** concat() and similar. 11710 ** 11711 ** The sqlite3changeset_apply() function automatically converts the 11712 ** zero-length blob back to a NULL value when updating the sqlite_stat1 11713 ** table. However, if the application calls sqlite3changeset_new(), 11714 ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset 11715 ** iterator directly (including on a changeset iterator passed to a 11716 ** conflict-handler callback) then the X'' value is returned. The application 11717 ** must translate X'' to NULL itself if required. 11718 ** 11719 ** Legacy (older than 3.22.0) versions of the sessions module cannot capture 11720 ** changes made to the sqlite_stat1 table. Legacy versions of the 11721 ** sqlite3changeset_apply() function silently ignore any modifications to the 11722 ** sqlite_stat1 table that are part of a changeset or patchset. 11723 */ 11724 SQLITE_API int sqlite3session_attach( 11725 sqlite3_session *pSession, /* Session object */ 11726 const char *zTab /* Table name */ 11727 ); 11728 11729 /* 11730 ** CAPI3REF: Set a table filter on a Session Object. 11731 ** METHOD: sqlite3_session 11732 ** 11733 ** The second argument (xFilter) is the "filter callback". For changes to rows 11734 ** in tables that are not attached to the Session object, the filter is called 11735 ** to determine whether changes to the table's rows should be tracked or not. 11736 ** If xFilter returns 0, changes are not tracked. Note that once a table is 11737 ** attached, xFilter will not be called again. 11738 */ 11739 SQLITE_API void sqlite3session_table_filter( 11740 sqlite3_session *pSession, /* Session object */ 11741 int(*xFilter)( 11742 void *pCtx, /* Copy of third arg to _filter_table() */ 11743 const char *zTab /* Table name */ 11744 ), 11745 void *pCtx /* First argument passed to xFilter */ 11746 ); 11747 11748 /* 11749 ** CAPI3REF: Generate A Changeset From A Session Object 11750 ** METHOD: sqlite3_session 11751 ** 11752 ** Obtain a changeset containing changes to the tables attached to the 11753 ** session object passed as the first argument. If successful, 11754 ** set *ppChangeset to point to a buffer containing the changeset 11755 ** and *pnChangeset to the size of the changeset in bytes before returning 11756 ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to 11757 ** zero and return an SQLite error code. 11758 ** 11759 ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes, 11760 ** each representing a change to a single row of an attached table. An INSERT 11761 ** change contains the values of each field of a new database row. A DELETE 11762 ** contains the original values of each field of a deleted database row. An 11763 ** UPDATE change contains the original values of each field of an updated 11764 ** database row along with the updated values for each updated non-primary-key 11765 ** column. It is not possible for an UPDATE change to represent a change that 11766 ** modifies the values of primary key columns. If such a change is made, it 11767 ** is represented in a changeset as a DELETE followed by an INSERT. 11768 ** 11769 ** Changes are not recorded for rows that have NULL values stored in one or 11770 ** more of their PRIMARY KEY columns. If such a row is inserted or deleted, 11771 ** no corresponding change is present in the changesets returned by this 11772 ** function. If an existing row with one or more NULL values stored in 11773 ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL, 11774 ** only an INSERT is appears in the changeset. Similarly, if an existing row 11775 ** with non-NULL PRIMARY KEY values is updated so that one or more of its 11776 ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a 11777 ** DELETE change only. 11778 ** 11779 ** The contents of a changeset may be traversed using an iterator created 11780 ** using the [sqlite3changeset_start()] API. A changeset may be applied to 11781 ** a database with a compatible schema using the [sqlite3changeset_apply()] 11782 ** API. 11783 ** 11784 ** Within a changeset generated by this function, all changes related to a 11785 ** single table are grouped together. In other words, when iterating through 11786 ** a changeset or when applying a changeset to a database, all changes related 11787 ** to a single table are processed before moving on to the next table. Tables 11788 ** are sorted in the same order in which they were attached (or auto-attached) 11789 ** to the sqlite3_session object. The order in which the changes related to 11790 ** a single table are stored is undefined. 11791 ** 11792 ** Following a successful call to this function, it is the responsibility of 11793 ** the caller to eventually free the buffer that *ppChangeset points to using 11794 ** [sqlite3_free()]. 11795 ** 11796 ** <h3>Changeset Generation</h3> 11797 ** 11798 ** Once a table has been attached to a session object, the session object 11799 ** records the primary key values of all new rows inserted into the table. 11800 ** It also records the original primary key and other column values of any 11801 ** deleted or updated rows. For each unique primary key value, data is only 11802 ** recorded once - the first time a row with said primary key is inserted, 11803 ** updated or deleted in the lifetime of the session. 11804 ** 11805 ** There is one exception to the previous paragraph: when a row is inserted, 11806 ** updated or deleted, if one or more of its primary key columns contain a 11807 ** NULL value, no record of the change is made. 11808 ** 11809 ** The session object therefore accumulates two types of records - those 11810 ** that consist of primary key values only (created when the user inserts 11811 ** a new record) and those that consist of the primary key values and the 11812 ** original values of other table columns (created when the users deletes 11813 ** or updates a record). 11814 ** 11815 ** When this function is called, the requested changeset is created using 11816 ** both the accumulated records and the current contents of the database 11817 ** file. Specifically: 11818 ** 11819 ** <ul> 11820 ** <li> For each record generated by an insert, the database is queried 11821 ** for a row with a matching primary key. If one is found, an INSERT 11822 ** change is added to the changeset. If no such row is found, no change 11823 ** is added to the changeset. 11824 ** 11825 ** <li> For each record generated by an update or delete, the database is 11826 ** queried for a row with a matching primary key. If such a row is 11827 ** found and one or more of the non-primary key fields have been 11828 ** modified from their original values, an UPDATE change is added to 11829 ** the changeset. Or, if no such row is found in the table, a DELETE 11830 ** change is added to the changeset. If there is a row with a matching 11831 ** primary key in the database, but all fields contain their original 11832 ** values, no change is added to the changeset. 11833 ** </ul> 11834 ** 11835 ** This means, amongst other things, that if a row is inserted and then later 11836 ** deleted while a session object is active, neither the insert nor the delete 11837 ** will be present in the changeset. Or if a row is deleted and then later a 11838 ** row with the same primary key values inserted while a session object is 11839 ** active, the resulting changeset will contain an UPDATE change instead of 11840 ** a DELETE and an INSERT. 11841 ** 11842 ** When a session object is disabled (see the [sqlite3session_enable()] API), 11843 ** it does not accumulate records when rows are inserted, updated or deleted. 11844 ** This may appear to have some counter-intuitive effects if a single row 11845 ** is written to more than once during a session. For example, if a row 11846 ** is inserted while a session object is enabled, then later deleted while 11847 ** the same session object is disabled, no INSERT record will appear in the 11848 ** changeset, even though the delete took place while the session was disabled. 11849 ** Or, if one field of a row is updated while a session is enabled, and 11850 ** then another field of the same row is updated while the session is disabled, 11851 ** the resulting changeset will contain an UPDATE change that updates both 11852 ** fields. 11853 */ 11854 SQLITE_API int sqlite3session_changeset( 11855 sqlite3_session *pSession, /* Session object */ 11856 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ 11857 void **ppChangeset /* OUT: Buffer containing changeset */ 11858 ); 11859 11860 /* 11861 ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset 11862 ** METHOD: sqlite3_session 11863 ** 11864 ** By default, this function always returns 0. For it to return 11865 ** a useful result, the sqlite3_session object must have been configured 11866 ** to enable this API using sqlite3session_object_config() with the 11867 ** SQLITE_SESSION_OBJCONFIG_SIZE verb. 11868 ** 11869 ** When enabled, this function returns an upper limit, in bytes, for the size 11870 ** of the changeset that might be produced if sqlite3session_changeset() were 11871 ** called. The final changeset size might be equal to or smaller than the 11872 ** size in bytes returned by this function. 11873 */ 11874 SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession); 11875 11876 /* 11877 ** CAPI3REF: Load The Difference Between Tables Into A Session 11878 ** METHOD: sqlite3_session 11879 ** 11880 ** If it is not already attached to the session object passed as the first 11881 ** argument, this function attaches table zTbl in the same manner as the 11882 ** [sqlite3session_attach()] function. If zTbl does not exist, or if it 11883 ** does not have a primary key, this function is a no-op (but does not return 11884 ** an error). 11885 ** 11886 ** Argument zFromDb must be the name of a database ("main", "temp" etc.) 11887 ** attached to the same database handle as the session object that contains 11888 ** a table compatible with the table attached to the session by this function. 11889 ** A table is considered compatible if it: 11890 ** 11891 ** <ul> 11892 ** <li> Has the same name, 11893 ** <li> Has the same set of columns declared in the same order, and 11894 ** <li> Has the same PRIMARY KEY definition. 11895 ** </ul> 11896 ** 11897 ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables 11898 ** are compatible but do not have any PRIMARY KEY columns, it is not an error 11899 ** but no changes are added to the session object. As with other session 11900 ** APIs, tables without PRIMARY KEYs are simply ignored. 11901 ** 11902 ** This function adds a set of changes to the session object that could be 11903 ** used to update the table in database zFrom (call this the "from-table") 11904 ** so that its content is the same as the table attached to the session 11905 ** object (call this the "to-table"). Specifically: 11906 ** 11907 ** <ul> 11908 ** <li> For each row (primary key) that exists in the to-table but not in 11909 ** the from-table, an INSERT record is added to the session object. 11910 ** 11911 ** <li> For each row (primary key) that exists in the to-table but not in 11912 ** the from-table, a DELETE record is added to the session object. 11913 ** 11914 ** <li> For each row (primary key) that exists in both tables, but features 11915 ** different non-PK values in each, an UPDATE record is added to the 11916 ** session. 11917 ** </ul> 11918 ** 11919 ** To clarify, if this function is called and then a changeset constructed 11920 ** using [sqlite3session_changeset()], then after applying that changeset to 11921 ** database zFrom the contents of the two compatible tables would be 11922 ** identical. 11923 ** 11924 ** Unless the call to this function is a no-op as described above, it is an 11925 ** error if database zFrom does not exist or does not contain the required 11926 ** compatible table. 11927 ** 11928 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite 11929 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg 11930 ** may be set to point to a buffer containing an English language error 11931 ** message. It is the responsibility of the caller to free this buffer using 11932 ** sqlite3_free(). 11933 */ 11934 SQLITE_API int sqlite3session_diff( 11935 sqlite3_session *pSession, 11936 const char *zFromDb, 11937 const char *zTbl, 11938 char **pzErrMsg 11939 ); 11940 11941 11942 /* 11943 ** CAPI3REF: Generate A Patchset From A Session Object 11944 ** METHOD: sqlite3_session 11945 ** 11946 ** The differences between a patchset and a changeset are that: 11947 ** 11948 ** <ul> 11949 ** <li> DELETE records consist of the primary key fields only. The 11950 ** original values of other fields are omitted. 11951 ** <li> The original values of any modified fields are omitted from 11952 ** UPDATE records. 11953 ** </ul> 11954 ** 11955 ** A patchset blob may be used with up to date versions of all 11956 ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(), 11957 ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly, 11958 ** attempting to use a patchset blob with old versions of the 11959 ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error. 11960 ** 11961 ** Because the non-primary key "old.*" fields are omitted, no 11962 ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset 11963 ** is passed to the sqlite3changeset_apply() API. Other conflict types work 11964 ** in the same way as for changesets. 11965 ** 11966 ** Changes within a patchset are ordered in the same way as for changesets 11967 ** generated by the sqlite3session_changeset() function (i.e. all changes for 11968 ** a single table are grouped together, tables appear in the order in which 11969 ** they were attached to the session object). 11970 */ 11971 SQLITE_API int sqlite3session_patchset( 11972 sqlite3_session *pSession, /* Session object */ 11973 int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */ 11974 void **ppPatchset /* OUT: Buffer containing patchset */ 11975 ); 11976 11977 /* 11978 ** CAPI3REF: Test if a changeset has recorded any changes. 11979 ** 11980 ** Return non-zero if no changes to attached tables have been recorded by 11981 ** the session object passed as the first argument. Otherwise, if one or 11982 ** more changes have been recorded, return zero. 11983 ** 11984 ** Even if this function returns zero, it is possible that calling 11985 ** [sqlite3session_changeset()] on the session handle may still return a 11986 ** changeset that contains no changes. This can happen when a row in 11987 ** an attached table is modified and then later on the original values 11988 ** are restored. However, if this function returns non-zero, then it is 11989 ** guaranteed that a call to sqlite3session_changeset() will return a 11990 ** changeset containing zero changes. 11991 */ 11992 SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession); 11993 11994 /* 11995 ** CAPI3REF: Query for the amount of heap memory used by a session object. 11996 ** 11997 ** This API returns the total amount of heap memory in bytes currently 11998 ** used by the session object passed as the only argument. 11999 */ 12000 SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession); 12001 12002 /* 12003 ** CAPI3REF: Create An Iterator To Traverse A Changeset 12004 ** CONSTRUCTOR: sqlite3_changeset_iter 12005 ** 12006 ** Create an iterator used to iterate through the contents of a changeset. 12007 ** If successful, *pp is set to point to the iterator handle and SQLITE_OK 12008 ** is returned. Otherwise, if an error occurs, *pp is set to zero and an 12009 ** SQLite error code is returned. 12010 ** 12011 ** The following functions can be used to advance and query a changeset 12012 ** iterator created by this function: 12013 ** 12014 ** <ul> 12015 ** <li> [sqlite3changeset_next()] 12016 ** <li> [sqlite3changeset_op()] 12017 ** <li> [sqlite3changeset_new()] 12018 ** <li> [sqlite3changeset_old()] 12019 ** </ul> 12020 ** 12021 ** It is the responsibility of the caller to eventually destroy the iterator 12022 ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the 12023 ** changeset (pChangeset) must remain valid until after the iterator is 12024 ** destroyed. 12025 ** 12026 ** Assuming the changeset blob was created by one of the 12027 ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or 12028 ** [sqlite3changeset_invert()] functions, all changes within the changeset 12029 ** that apply to a single table are grouped together. This means that when 12030 ** an application iterates through a changeset using an iterator created by 12031 ** this function, all changes that relate to a single table are visited 12032 ** consecutively. There is no chance that the iterator will visit a change 12033 ** the applies to table X, then one for table Y, and then later on visit 12034 ** another change for table X. 12035 ** 12036 ** The behavior of sqlite3changeset_start_v2() and its streaming equivalent 12037 ** may be modified by passing a combination of 12038 ** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter. 12039 ** 12040 ** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b> 12041 ** and therefore subject to change. 12042 */ 12043 SQLITE_API int sqlite3changeset_start( 12044 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ 12045 int nChangeset, /* Size of changeset blob in bytes */ 12046 void *pChangeset /* Pointer to blob containing changeset */ 12047 ); 12048 SQLITE_API int sqlite3changeset_start_v2( 12049 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ 12050 int nChangeset, /* Size of changeset blob in bytes */ 12051 void *pChangeset, /* Pointer to blob containing changeset */ 12052 int flags /* SESSION_CHANGESETSTART_* flags */ 12053 ); 12054 12055 /* 12056 ** CAPI3REF: Flags for sqlite3changeset_start_v2 12057 ** 12058 ** The following flags may passed via the 4th parameter to 12059 ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]: 12060 ** 12061 ** <dt>SQLITE_CHANGESETSTART_INVERT <dd> 12062 ** Invert the changeset while iterating through it. This is equivalent to 12063 ** inverting a changeset using sqlite3changeset_invert() before applying it. 12064 ** It is an error to specify this flag with a patchset. 12065 */ 12066 #define SQLITE_CHANGESETSTART_INVERT 0x0002 12067 12068 12069 /* 12070 ** CAPI3REF: Advance A Changeset Iterator 12071 ** METHOD: sqlite3_changeset_iter 12072 ** 12073 ** This function may only be used with iterators created by the function 12074 ** [sqlite3changeset_start()]. If it is called on an iterator passed to 12075 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE 12076 ** is returned and the call has no effect. 12077 ** 12078 ** Immediately after an iterator is created by sqlite3changeset_start(), it 12079 ** does not point to any change in the changeset. Assuming the changeset 12080 ** is not empty, the first call to this function advances the iterator to 12081 ** point to the first change in the changeset. Each subsequent call advances 12082 ** the iterator to point to the next change in the changeset (if any). If 12083 ** no error occurs and the iterator points to a valid change after a call 12084 ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned. 12085 ** Otherwise, if all changes in the changeset have already been visited, 12086 ** SQLITE_DONE is returned. 12087 ** 12088 ** If an error occurs, an SQLite error code is returned. Possible error 12089 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or 12090 ** SQLITE_NOMEM. 12091 */ 12092 SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter); 12093 12094 /* 12095 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator 12096 ** METHOD: sqlite3_changeset_iter 12097 ** 12098 ** The pIter argument passed to this function may either be an iterator 12099 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator 12100 ** created by [sqlite3changeset_start()]. In the latter case, the most recent 12101 ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this 12102 ** is not the case, this function returns [SQLITE_MISUSE]. 12103 ** 12104 ** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three 12105 ** outputs are set through these pointers: 12106 ** 12107 ** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], 12108 ** depending on the type of change that the iterator currently points to; 12109 ** 12110 ** *pnCol is set to the number of columns in the table affected by the change; and 12111 ** 12112 ** *pzTab is set to point to a nul-terminated utf-8 encoded string containing 12113 ** the name of the table affected by the current change. The buffer remains 12114 ** valid until either sqlite3changeset_next() is called on the iterator 12115 ** or until the conflict-handler function returns. 12116 ** 12117 ** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change 12118 ** is an indirect change, or false (0) otherwise. See the documentation for 12119 ** [sqlite3session_indirect()] for a description of direct and indirect 12120 ** changes. 12121 ** 12122 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an 12123 ** SQLite error code is returned. The values of the output variables may not 12124 ** be trusted in this case. 12125 */ 12126 SQLITE_API int sqlite3changeset_op( 12127 sqlite3_changeset_iter *pIter, /* Iterator object */ 12128 const char **pzTab, /* OUT: Pointer to table name */ 12129 int *pnCol, /* OUT: Number of columns in table */ 12130 int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */ 12131 int *pbIndirect /* OUT: True for an 'indirect' change */ 12132 ); 12133 12134 /* 12135 ** CAPI3REF: Obtain The Primary Key Definition Of A Table 12136 ** METHOD: sqlite3_changeset_iter 12137 ** 12138 ** For each modified table, a changeset includes the following: 12139 ** 12140 ** <ul> 12141 ** <li> The number of columns in the table, and 12142 ** <li> Which of those columns make up the tables PRIMARY KEY. 12143 ** </ul> 12144 ** 12145 ** This function is used to find which columns comprise the PRIMARY KEY of 12146 ** the table modified by the change that iterator pIter currently points to. 12147 ** If successful, *pabPK is set to point to an array of nCol entries, where 12148 ** nCol is the number of columns in the table. Elements of *pabPK are set to 12149 ** 0x01 if the corresponding column is part of the tables primary key, or 12150 ** 0x00 if it is not. 12151 ** 12152 ** If argument pnCol is not NULL, then *pnCol is set to the number of columns 12153 ** in the table. 12154 ** 12155 ** If this function is called when the iterator does not point to a valid 12156 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise, 12157 ** SQLITE_OK is returned and the output variables populated as described 12158 ** above. 12159 */ 12160 SQLITE_API int sqlite3changeset_pk( 12161 sqlite3_changeset_iter *pIter, /* Iterator object */ 12162 unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */ 12163 int *pnCol /* OUT: Number of entries in output array */ 12164 ); 12165 12166 /* 12167 ** CAPI3REF: Obtain old.* Values From A Changeset Iterator 12168 ** METHOD: sqlite3_changeset_iter 12169 ** 12170 ** The pIter argument passed to this function may either be an iterator 12171 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator 12172 ** created by [sqlite3changeset_start()]. In the latter case, the most recent 12173 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. 12174 ** Furthermore, it may only be called if the type of change that the iterator 12175 ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise, 12176 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL. 12177 ** 12178 ** Argument iVal must be greater than or equal to 0, and less than the number 12179 ** of columns in the table affected by the current change. Otherwise, 12180 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL. 12181 ** 12182 ** If successful, this function sets *ppValue to point to a protected 12183 ** sqlite3_value object containing the iVal'th value from the vector of 12184 ** original row values stored as part of the UPDATE or DELETE change and 12185 ** returns SQLITE_OK. The name of the function comes from the fact that this 12186 ** is similar to the "old.*" columns available to update or delete triggers. 12187 ** 12188 ** If some other error occurs (e.g. an OOM condition), an SQLite error code 12189 ** is returned and *ppValue is set to NULL. 12190 */ 12191 SQLITE_API int sqlite3changeset_old( 12192 sqlite3_changeset_iter *pIter, /* Changeset iterator */ 12193 int iVal, /* Column number */ 12194 sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */ 12195 ); 12196 12197 /* 12198 ** CAPI3REF: Obtain new.* Values From A Changeset Iterator 12199 ** METHOD: sqlite3_changeset_iter 12200 ** 12201 ** The pIter argument passed to this function may either be an iterator 12202 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator 12203 ** created by [sqlite3changeset_start()]. In the latter case, the most recent 12204 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW. 12205 ** Furthermore, it may only be called if the type of change that the iterator 12206 ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise, 12207 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL. 12208 ** 12209 ** Argument iVal must be greater than or equal to 0, and less than the number 12210 ** of columns in the table affected by the current change. Otherwise, 12211 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL. 12212 ** 12213 ** If successful, this function sets *ppValue to point to a protected 12214 ** sqlite3_value object containing the iVal'th value from the vector of 12215 ** new row values stored as part of the UPDATE or INSERT change and 12216 ** returns SQLITE_OK. If the change is an UPDATE and does not include 12217 ** a new value for the requested column, *ppValue is set to NULL and 12218 ** SQLITE_OK returned. The name of the function comes from the fact that 12219 ** this is similar to the "new.*" columns available to update or delete 12220 ** triggers. 12221 ** 12222 ** If some other error occurs (e.g. an OOM condition), an SQLite error code 12223 ** is returned and *ppValue is set to NULL. 12224 */ 12225 SQLITE_API int sqlite3changeset_new( 12226 sqlite3_changeset_iter *pIter, /* Changeset iterator */ 12227 int iVal, /* Column number */ 12228 sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */ 12229 ); 12230 12231 /* 12232 ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator 12233 ** METHOD: sqlite3_changeset_iter 12234 ** 12235 ** This function should only be used with iterator objects passed to a 12236 ** conflict-handler callback by [sqlite3changeset_apply()] with either 12237 ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function 12238 ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue 12239 ** is set to NULL. 12240 ** 12241 ** Argument iVal must be greater than or equal to 0, and less than the number 12242 ** of columns in the table affected by the current change. Otherwise, 12243 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL. 12244 ** 12245 ** If successful, this function sets *ppValue to point to a protected 12246 ** sqlite3_value object containing the iVal'th value from the 12247 ** "conflicting row" associated with the current conflict-handler callback 12248 ** and returns SQLITE_OK. 12249 ** 12250 ** If some other error occurs (e.g. an OOM condition), an SQLite error code 12251 ** is returned and *ppValue is set to NULL. 12252 */ 12253 SQLITE_API int sqlite3changeset_conflict( 12254 sqlite3_changeset_iter *pIter, /* Changeset iterator */ 12255 int iVal, /* Column number */ 12256 sqlite3_value **ppValue /* OUT: Value from conflicting row */ 12257 ); 12258 12259 /* 12260 ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations 12261 ** METHOD: sqlite3_changeset_iter 12262 ** 12263 ** This function may only be called with an iterator passed to an 12264 ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case 12265 ** it sets the output variable to the total number of known foreign key 12266 ** violations in the destination database and returns SQLITE_OK. 12267 ** 12268 ** In all other cases this function returns SQLITE_MISUSE. 12269 */ 12270 SQLITE_API int sqlite3changeset_fk_conflicts( 12271 sqlite3_changeset_iter *pIter, /* Changeset iterator */ 12272 int *pnOut /* OUT: Number of FK violations */ 12273 ); 12274 12275 12276 /* 12277 ** CAPI3REF: Finalize A Changeset Iterator 12278 ** METHOD: sqlite3_changeset_iter 12279 ** 12280 ** This function is used to finalize an iterator allocated with 12281 ** [sqlite3changeset_start()]. 12282 ** 12283 ** This function should only be called on iterators created using the 12284 ** [sqlite3changeset_start()] function. If an application calls this 12285 ** function with an iterator passed to a conflict-handler by 12286 ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the 12287 ** call has no effect. 12288 ** 12289 ** If an error was encountered within a call to an sqlite3changeset_xxx() 12290 ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an 12291 ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding 12292 ** to that error is returned by this function. Otherwise, SQLITE_OK is 12293 ** returned. This is to allow the following pattern (pseudo-code): 12294 ** 12295 ** <pre> 12296 ** sqlite3changeset_start(); 12297 ** while( SQLITE_ROW==sqlite3changeset_next() ){ 12298 ** // Do something with change. 12299 ** } 12300 ** rc = sqlite3changeset_finalize(); 12301 ** if( rc!=SQLITE_OK ){ 12302 ** // An error has occurred 12303 ** } 12304 ** </pre> 12305 */ 12306 SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter); 12307 12308 /* 12309 ** CAPI3REF: Invert A Changeset 12310 ** 12311 ** This function is used to "invert" a changeset object. Applying an inverted 12312 ** changeset to a database reverses the effects of applying the uninverted 12313 ** changeset. Specifically: 12314 ** 12315 ** <ul> 12316 ** <li> Each DELETE change is changed to an INSERT, and 12317 ** <li> Each INSERT change is changed to a DELETE, and 12318 ** <li> For each UPDATE change, the old.* and new.* values are exchanged. 12319 ** </ul> 12320 ** 12321 ** This function does not change the order in which changes appear within 12322 ** the changeset. It merely reverses the sense of each individual change. 12323 ** 12324 ** If successful, a pointer to a buffer containing the inverted changeset 12325 ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and 12326 ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are 12327 ** zeroed and an SQLite error code returned. 12328 ** 12329 ** It is the responsibility of the caller to eventually call sqlite3_free() 12330 ** on the *ppOut pointer to free the buffer allocation following a successful 12331 ** call to this function. 12332 ** 12333 ** WARNING/TODO: This function currently assumes that the input is a valid 12334 ** changeset. If it is not, the results are undefined. 12335 */ 12336 SQLITE_API int sqlite3changeset_invert( 12337 int nIn, const void *pIn, /* Input changeset */ 12338 int *pnOut, void **ppOut /* OUT: Inverse of input */ 12339 ); 12340 12341 /* 12342 ** CAPI3REF: Concatenate Two Changeset Objects 12343 ** 12344 ** This function is used to concatenate two changesets, A and B, into a 12345 ** single changeset. The result is a changeset equivalent to applying 12346 ** changeset A followed by changeset B. 12347 ** 12348 ** This function combines the two input changesets using an 12349 ** sqlite3_changegroup object. Calling it produces similar results as the 12350 ** following code fragment: 12351 ** 12352 ** <pre> 12353 ** sqlite3_changegroup *pGrp; 12354 ** rc = sqlite3_changegroup_new(&pGrp); 12355 ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA); 12356 ** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB); 12357 ** if( rc==SQLITE_OK ){ 12358 ** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut); 12359 ** }else{ 12360 ** *ppOut = 0; 12361 ** *pnOut = 0; 12362 ** } 12363 ** </pre> 12364 ** 12365 ** Refer to the sqlite3_changegroup documentation below for details. 12366 */ 12367 SQLITE_API int sqlite3changeset_concat( 12368 int nA, /* Number of bytes in buffer pA */ 12369 void *pA, /* Pointer to buffer containing changeset A */ 12370 int nB, /* Number of bytes in buffer pB */ 12371 void *pB, /* Pointer to buffer containing changeset B */ 12372 int *pnOut, /* OUT: Number of bytes in output changeset */ 12373 void **ppOut /* OUT: Buffer containing output changeset */ 12374 ); 12375 12376 /* 12377 ** CAPI3REF: Changegroup Handle 12378 ** 12379 ** A changegroup is an object used to combine two or more 12380 ** [changesets] or [patchsets] 12381 */ 12382 typedef struct sqlite3_changegroup sqlite3_changegroup; 12383 12384 /* 12385 ** CAPI3REF: Create A New Changegroup Object 12386 ** CONSTRUCTOR: sqlite3_changegroup 12387 ** 12388 ** An sqlite3_changegroup object is used to combine two or more changesets 12389 ** (or patchsets) into a single changeset (or patchset). A single changegroup 12390 ** object may combine changesets or patchsets, but not both. The output is 12391 ** always in the same format as the input. 12392 ** 12393 ** If successful, this function returns SQLITE_OK and populates (*pp) with 12394 ** a pointer to a new sqlite3_changegroup object before returning. The caller 12395 ** should eventually free the returned object using a call to 12396 ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code 12397 ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL. 12398 ** 12399 ** The usual usage pattern for an sqlite3_changegroup object is as follows: 12400 ** 12401 ** <ul> 12402 ** <li> It is created using a call to sqlite3changegroup_new(). 12403 ** 12404 ** <li> Zero or more changesets (or patchsets) are added to the object 12405 ** by calling sqlite3changegroup_add(). 12406 ** 12407 ** <li> The result of combining all input changesets together is obtained 12408 ** by the application via a call to sqlite3changegroup_output(). 12409 ** 12410 ** <li> The object is deleted using a call to sqlite3changegroup_delete(). 12411 ** </ul> 12412 ** 12413 ** Any number of calls to add() and output() may be made between the calls to 12414 ** new() and delete(), and in any order. 12415 ** 12416 ** As well as the regular sqlite3changegroup_add() and 12417 ** sqlite3changegroup_output() functions, also available are the streaming 12418 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm(). 12419 */ 12420 SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp); 12421 12422 /* 12423 ** CAPI3REF: Add a Schema to a Changegroup 12424 ** METHOD: sqlite3_changegroup_schema 12425 ** 12426 ** This method may be used to optionally enforce the rule that the changesets 12427 ** added to the changegroup handle must match the schema of database zDb 12428 ** ("main", "temp", or the name of an attached database). If 12429 ** sqlite3changegroup_add() is called to add a changeset that is not compatible 12430 ** with the configured schema, SQLITE_SCHEMA is returned and the changegroup 12431 ** object is left in an undefined state. 12432 ** 12433 ** A changeset schema is considered compatible with the database schema in 12434 ** the same way as for sqlite3changeset_apply(). Specifically, for each 12435 ** table in the changeset, there exists a database table with: 12436 ** 12437 ** <ul> 12438 ** <li> The name identified by the changeset, and 12439 ** <li> at least as many columns as recorded in the changeset, and 12440 ** <li> the primary key columns in the same position as recorded in 12441 ** the changeset. 12442 ** </ul> 12443 ** 12444 ** The output of the changegroup object always has the same schema as the 12445 ** database nominated using this function. In cases where changesets passed 12446 ** to sqlite3changegroup_add() have fewer columns than the corresponding table 12447 ** in the database schema, these are filled in using the default column 12448 ** values from the database schema. This makes it possible to combined 12449 ** changesets that have different numbers of columns for a single table 12450 ** within a changegroup, provided that they are otherwise compatible. 12451 */ 12452 SQLITE_API int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb); 12453 12454 /* 12455 ** CAPI3REF: Add A Changeset To A Changegroup 12456 ** METHOD: sqlite3_changegroup 12457 ** 12458 ** Add all changes within the changeset (or patchset) in buffer pData (size 12459 ** nData bytes) to the changegroup. 12460 ** 12461 ** If the buffer contains a patchset, then all prior calls to this function 12462 ** on the same changegroup object must also have specified patchsets. Or, if 12463 ** the buffer contains a changeset, so must have the earlier calls to this 12464 ** function. Otherwise, SQLITE_ERROR is returned and no changes are added 12465 ** to the changegroup. 12466 ** 12467 ** Rows within the changeset and changegroup are identified by the values in 12468 ** their PRIMARY KEY columns. A change in the changeset is considered to 12469 ** apply to the same row as a change already present in the changegroup if 12470 ** the two rows have the same primary key. 12471 ** 12472 ** Changes to rows that do not already appear in the changegroup are 12473 ** simply copied into it. Or, if both the new changeset and the changegroup 12474 ** contain changes that apply to a single row, the final contents of the 12475 ** changegroup depends on the type of each change, as follows: 12476 ** 12477 ** <table border=1 style="margin-left:8ex;margin-right:8ex"> 12478 ** <tr><th style="white-space:pre">Existing Change </th> 12479 ** <th style="white-space:pre">New Change </th> 12480 ** <th>Output Change 12481 ** <tr><td>INSERT <td>INSERT <td> 12482 ** The new change is ignored. This case does not occur if the new 12483 ** changeset was recorded immediately after the changesets already 12484 ** added to the changegroup. 12485 ** <tr><td>INSERT <td>UPDATE <td> 12486 ** The INSERT change remains in the changegroup. The values in the 12487 ** INSERT change are modified as if the row was inserted by the 12488 ** existing change and then updated according to the new change. 12489 ** <tr><td>INSERT <td>DELETE <td> 12490 ** The existing INSERT is removed from the changegroup. The DELETE is 12491 ** not added. 12492 ** <tr><td>UPDATE <td>INSERT <td> 12493 ** The new change is ignored. This case does not occur if the new 12494 ** changeset was recorded immediately after the changesets already 12495 ** added to the changegroup. 12496 ** <tr><td>UPDATE <td>UPDATE <td> 12497 ** The existing UPDATE remains within the changegroup. It is amended 12498 ** so that the accompanying values are as if the row was updated once 12499 ** by the existing change and then again by the new change. 12500 ** <tr><td>UPDATE <td>DELETE <td> 12501 ** The existing UPDATE is replaced by the new DELETE within the 12502 ** changegroup. 12503 ** <tr><td>DELETE <td>INSERT <td> 12504 ** If one or more of the column values in the row inserted by the 12505 ** new change differ from those in the row deleted by the existing 12506 ** change, the existing DELETE is replaced by an UPDATE within the 12507 ** changegroup. Otherwise, if the inserted row is exactly the same 12508 ** as the deleted row, the existing DELETE is simply discarded. 12509 ** <tr><td>DELETE <td>UPDATE <td> 12510 ** The new change is ignored. This case does not occur if the new 12511 ** changeset was recorded immediately after the changesets already 12512 ** added to the changegroup. 12513 ** <tr><td>DELETE <td>DELETE <td> 12514 ** The new change is ignored. This case does not occur if the new 12515 ** changeset was recorded immediately after the changesets already 12516 ** added to the changegroup. 12517 ** </table> 12518 ** 12519 ** If the new changeset contains changes to a table that is already present 12520 ** in the changegroup, then the number of columns and the position of the 12521 ** primary key columns for the table must be consistent. If this is not the 12522 ** case, this function fails with SQLITE_SCHEMA. Except, if the changegroup 12523 ** object has been configured with a database schema using the 12524 ** sqlite3changegroup_schema() API, then it is possible to combine changesets 12525 ** with different numbers of columns for a single table, provided that 12526 ** they are otherwise compatible. 12527 ** 12528 ** If the input changeset appears to be corrupt and the corruption is 12529 ** detected, SQLITE_CORRUPT is returned. Or, if an out-of-memory condition 12530 ** occurs during processing, this function returns SQLITE_NOMEM. 12531 ** 12532 ** In all cases, if an error occurs the state of the final contents of the 12533 ** changegroup is undefined. If no error occurs, SQLITE_OK is returned. 12534 */ 12535 SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData); 12536 12537 /* 12538 ** CAPI3REF: Add A Single Change To A Changegroup 12539 ** METHOD: sqlite3_changegroup 12540 ** 12541 ** This function adds the single change currently indicated by the iterator 12542 ** passed as the second argument to the changegroup object. The rules for 12543 ** adding the change are just as described for [sqlite3changegroup_add()]. 12544 ** 12545 ** If the change is successfully added to the changegroup, SQLITE_OK is 12546 ** returned. Otherwise, an SQLite error code is returned. 12547 ** 12548 ** The iterator must point to a valid entry when this function is called. 12549 ** If it does not, SQLITE_ERROR is returned and no change is added to the 12550 ** changegroup. Additionally, the iterator must not have been opened with 12551 ** the SQLITE_CHANGESETAPPLY_INVERT flag. In this case SQLITE_ERROR is also 12552 ** returned. 12553 */ 12554 SQLITE_API int sqlite3changegroup_add_change( 12555 sqlite3_changegroup*, 12556 sqlite3_changeset_iter* 12557 ); 12558 12559 12560 12561 /* 12562 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup 12563 ** METHOD: sqlite3_changegroup 12564 ** 12565 ** Obtain a buffer containing a changeset (or patchset) representing the 12566 ** current contents of the changegroup. If the inputs to the changegroup 12567 ** were themselves changesets, the output is a changeset. Or, if the 12568 ** inputs were patchsets, the output is also a patchset. 12569 ** 12570 ** As with the output of the sqlite3session_changeset() and 12571 ** sqlite3session_patchset() functions, all changes related to a single 12572 ** table are grouped together in the output of this function. Tables appear 12573 ** in the same order as for the very first changeset added to the changegroup. 12574 ** If the second or subsequent changesets added to the changegroup contain 12575 ** changes for tables that do not appear in the first changeset, they are 12576 ** appended onto the end of the output changeset, again in the order in 12577 ** which they are first encountered. 12578 ** 12579 ** If an error occurs, an SQLite error code is returned and the output 12580 ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK 12581 ** is returned and the output variables are set to the size of and a 12582 ** pointer to the output buffer, respectively. In this case it is the 12583 ** responsibility of the caller to eventually free the buffer using a 12584 ** call to sqlite3_free(). 12585 */ 12586 SQLITE_API int sqlite3changegroup_output( 12587 sqlite3_changegroup*, 12588 int *pnData, /* OUT: Size of output buffer in bytes */ 12589 void **ppData /* OUT: Pointer to output buffer */ 12590 ); 12591 12592 /* 12593 ** CAPI3REF: Delete A Changegroup Object 12594 ** DESTRUCTOR: sqlite3_changegroup 12595 */ 12596 SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*); 12597 12598 /* 12599 ** CAPI3REF: Apply A Changeset To A Database 12600 ** 12601 ** Apply a changeset or patchset to a database. These functions attempt to 12602 ** update the "main" database attached to handle db with the changes found in 12603 ** the changeset passed via the second and third arguments. 12604 ** 12605 ** All changes made by these functions are enclosed in a savepoint transaction. 12606 ** If any other error (aside from a constraint failure when attempting to 12607 ** write to the target database) occurs, then the savepoint transaction is 12608 ** rolled back, restoring the target database to its original state, and an 12609 ** SQLite error code returned. Additionally, starting with version 3.51.0, 12610 ** an error code and error message that may be accessed using the 12611 ** [sqlite3_errcode()] and [sqlite3_errmsg()] APIs are left in the database 12612 ** handle. 12613 ** 12614 ** The fourth argument (xFilter) passed to these functions is the "filter 12615 ** callback". This may be passed NULL, in which case all changes in the 12616 ** changeset are applied to the database. For sqlite3changeset_apply() and 12617 ** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once 12618 ** for each table affected by at least one change in the changeset. In this 12619 ** case the table name is passed as the second argument, and a copy of 12620 ** the context pointer passed as the sixth argument to apply() or apply_v2() 12621 ** as the first. If the "filter callback" returns zero, then no attempt is 12622 ** made to apply any changes to the table. Otherwise, if the return value is 12623 ** non-zero, all changes related to the table are attempted. 12624 ** 12625 ** For sqlite3_changeset_apply_v3(), the xFilter callback is invoked once 12626 ** per change. The second argument in this case is an sqlite3_changeset_iter 12627 ** that may be queried using the usual APIs for the details of the current 12628 ** change. If the "filter callback" returns zero in this case, then no attempt 12629 ** is made to apply the current change. If it returns non-zero, the change 12630 ** is applied. 12631 ** 12632 ** For each table that is not excluded by the filter callback, this function 12633 ** tests that the target database contains a compatible table. A table is 12634 ** considered compatible if all of the following are true: 12635 ** 12636 ** <ul> 12637 ** <li> The table has the same name as the name recorded in the 12638 ** changeset, and 12639 ** <li> The table has at least as many columns as recorded in the 12640 ** changeset, and 12641 ** <li> The table has primary key columns in the same position as 12642 ** recorded in the changeset. 12643 ** </ul> 12644 ** 12645 ** If there is no compatible table, it is not an error, but none of the 12646 ** changes associated with the table are applied. A warning message is issued 12647 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most 12648 ** one such warning is issued for each table in the changeset. 12649 ** 12650 ** For each change for which there is a compatible table, an attempt is made 12651 ** to modify the table contents according to each UPDATE, INSERT or DELETE 12652 ** change that is not excluded by a filter callback. If a change cannot be 12653 ** applied cleanly, the conflict handler function passed as the fifth argument 12654 ** to sqlite3changeset_apply() may be invoked. A description of exactly when 12655 ** the conflict handler is invoked for each type of change is below. 12656 ** 12657 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results 12658 ** of passing anything other than a valid function pointer as the xConflict 12659 ** argument are undefined. 12660 ** 12661 ** Each time the conflict handler function is invoked, it must return one 12662 ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or 12663 ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned 12664 ** if the second argument passed to the conflict handler is either 12665 ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler 12666 ** returns an illegal value, any changes already made are rolled back and 12667 ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different 12668 ** actions are taken by sqlite3changeset_apply() depending on the value 12669 ** returned by each invocation of the conflict-handler function. Refer to 12670 ** the documentation for the three 12671 ** [SQLITE_CHANGESET_OMIT|available return values] for details. 12672 ** 12673 ** <dl> 12674 ** <dt>DELETE Changes<dd> 12675 ** For each DELETE change, the function checks if the target database 12676 ** contains a row with the same primary key value (or values) as the 12677 ** original row values stored in the changeset. If it does, and the values 12678 ** stored in all non-primary key columns also match the values stored in 12679 ** the changeset the row is deleted from the target database. 12680 ** 12681 ** If a row with matching primary key values is found, but one or more of 12682 ** the non-primary key fields contains a value different from the original 12683 ** row value stored in the changeset, the conflict-handler function is 12684 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the 12685 ** database table has more columns than are recorded in the changeset, 12686 ** only the values of those non-primary key fields are compared against 12687 ** the current database contents - any trailing database table columns 12688 ** are ignored. 12689 ** 12690 ** If no row with matching primary key values is found in the database, 12691 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] 12692 ** passed as the second argument. 12693 ** 12694 ** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT 12695 ** (which can only happen if a foreign key constraint is violated), the 12696 ** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT] 12697 ** passed as the second argument. This includes the case where the DELETE 12698 ** operation is attempted because an earlier call to the conflict handler 12699 ** function returned [SQLITE_CHANGESET_REPLACE]. 12700 ** 12701 ** <dt>INSERT Changes<dd> 12702 ** For each INSERT change, an attempt is made to insert the new row into 12703 ** the database. If the changeset row contains fewer fields than the 12704 ** database table, the trailing fields are populated with their default 12705 ** values. 12706 ** 12707 ** If the attempt to insert the row fails because the database already 12708 ** contains a row with the same primary key values, the conflict handler 12709 ** function is invoked with the second argument set to 12710 ** [SQLITE_CHANGESET_CONFLICT]. 12711 ** 12712 ** If the attempt to insert the row fails because of some other constraint 12713 ** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is 12714 ** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT]. 12715 ** This includes the case where the INSERT operation is re-attempted because 12716 ** an earlier call to the conflict handler function returned 12717 ** [SQLITE_CHANGESET_REPLACE]. 12718 ** 12719 ** <dt>UPDATE Changes<dd> 12720 ** For each UPDATE change, the function checks if the target database 12721 ** contains a row with the same primary key value (or values) as the 12722 ** original row values stored in the changeset. If it does, and the values 12723 ** stored in all modified non-primary key columns also match the values 12724 ** stored in the changeset the row is updated within the target database. 12725 ** 12726 ** If a row with matching primary key values is found, but one or more of 12727 ** the modified non-primary key fields contains a value different from an 12728 ** original row value stored in the changeset, the conflict-handler function 12729 ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since 12730 ** UPDATE changes only contain values for non-primary key fields that are 12731 ** to be modified, only those fields need to match the original values to 12732 ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. 12733 ** 12734 ** If no row with matching primary key values is found in the database, 12735 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] 12736 ** passed as the second argument. 12737 ** 12738 ** If the UPDATE operation is attempted, but SQLite returns 12739 ** SQLITE_CONSTRAINT, the conflict-handler function is invoked with 12740 ** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument. 12741 ** This includes the case where the UPDATE operation is attempted after 12742 ** an earlier call to the conflict handler function returned 12743 ** [SQLITE_CHANGESET_REPLACE]. 12744 ** </dl> 12745 ** 12746 ** It is safe to execute SQL statements, including those that write to the 12747 ** table that the callback related to, from within the xConflict callback. 12748 ** This can be used to further customize the application's conflict 12749 ** resolution strategy. 12750 ** 12751 ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and 12752 ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2() 12753 ** may set (*ppRebase) to point to a "rebase" that may be used with the 12754 ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase) 12755 ** is set to the size of the buffer in bytes. It is the responsibility of the 12756 ** caller to eventually free any such buffer using sqlite3_free(). The buffer 12757 ** is only allocated and populated if one or more conflicts were encountered 12758 ** while applying the patchset. See comments surrounding the sqlite3_rebaser 12759 ** APIs for further details. 12760 ** 12761 ** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent 12762 ** may be modified by passing a combination of 12763 ** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter. 12764 ** 12765 ** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b> 12766 ** and therefore subject to change. 12767 */ 12768 SQLITE_API int sqlite3changeset_apply( 12769 sqlite3 *db, /* Apply change to "main" db of this handle */ 12770 int nChangeset, /* Size of changeset in bytes */ 12771 void *pChangeset, /* Changeset blob */ 12772 int(*xFilter)( 12773 void *pCtx, /* Copy of sixth arg to _apply() */ 12774 const char *zTab /* Table name */ 12775 ), 12776 int(*xConflict)( 12777 void *pCtx, /* Copy of sixth arg to _apply() */ 12778 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ 12779 sqlite3_changeset_iter *p /* Handle describing change and conflict */ 12780 ), 12781 void *pCtx /* First argument passed to xConflict */ 12782 ); 12783 SQLITE_API int sqlite3changeset_apply_v2( 12784 sqlite3 *db, /* Apply change to "main" db of this handle */ 12785 int nChangeset, /* Size of changeset in bytes */ 12786 void *pChangeset, /* Changeset blob */ 12787 int(*xFilter)( 12788 void *pCtx, /* Copy of sixth arg to _apply() */ 12789 const char *zTab /* Table name */ 12790 ), 12791 int(*xConflict)( 12792 void *pCtx, /* Copy of sixth arg to _apply() */ 12793 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ 12794 sqlite3_changeset_iter *p /* Handle describing change and conflict */ 12795 ), 12796 void *pCtx, /* First argument passed to xConflict */ 12797 void **ppRebase, int *pnRebase, /* OUT: Rebase data */ 12798 int flags /* SESSION_CHANGESETAPPLY_* flags */ 12799 ); 12800 SQLITE_API int sqlite3changeset_apply_v3( 12801 sqlite3 *db, /* Apply change to "main" db of this handle */ 12802 int nChangeset, /* Size of changeset in bytes */ 12803 void *pChangeset, /* Changeset blob */ 12804 int(*xFilter)( 12805 void *pCtx, /* Copy of sixth arg to _apply() */ 12806 sqlite3_changeset_iter *p /* Handle describing change */ 12807 ), 12808 int(*xConflict)( 12809 void *pCtx, /* Copy of sixth arg to _apply() */ 12810 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ 12811 sqlite3_changeset_iter *p /* Handle describing change and conflict */ 12812 ), 12813 void *pCtx, /* First argument passed to xConflict */ 12814 void **ppRebase, int *pnRebase, /* OUT: Rebase data */ 12815 int flags /* SESSION_CHANGESETAPPLY_* flags */ 12816 ); 12817 12818 /* 12819 ** CAPI3REF: Flags for sqlite3changeset_apply_v2 12820 ** 12821 ** The following flags may passed via the 9th parameter to 12822 ** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]: 12823 ** 12824 ** <dl> 12825 ** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd> 12826 ** Usually, the sessions module encloses all operations performed by 12827 ** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The 12828 ** SAVEPOINT is committed if the changeset or patchset is successfully 12829 ** applied, or rolled back if an error occurs. Specifying this flag 12830 ** causes the sessions module to omit this savepoint. In this case, if the 12831 ** caller has an open transaction or savepoint when apply_v2() is called, 12832 ** it may revert the partially applied changeset by rolling it back. 12833 ** 12834 ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd> 12835 ** Invert the changeset before applying it. This is equivalent to inverting 12836 ** a changeset using sqlite3changeset_invert() before applying it. It is 12837 ** an error to specify this flag with a patchset. 12838 ** 12839 ** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd> 12840 ** Do not invoke the conflict handler callback for any changes that 12841 ** would not actually modify the database even if they were applied. 12842 ** Specifically, this means that the conflict handler is not invoked 12843 ** for: 12844 ** <ul> 12845 ** <li>a delete change if the row being deleted cannot be found, 12846 ** <li>an update change if the modified fields are already set to 12847 ** their new values in the conflicting row, or 12848 ** <li>an insert change if all fields of the conflicting row match 12849 ** the row being inserted. 12850 ** </ul> 12851 ** 12852 ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd> 12853 ** If this flag it set, then all foreign key constraints in the target 12854 ** database behave as if they were declared with "ON UPDATE NO ACTION ON 12855 ** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL 12856 ** or SET DEFAULT. 12857 */ 12858 #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 12859 #define SQLITE_CHANGESETAPPLY_INVERT 0x0002 12860 #define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004 12861 #define SQLITE_CHANGESETAPPLY_FKNOACTION 0x0008 12862 12863 /* 12864 ** CAPI3REF: Constants Passed To The Conflict Handler 12865 ** 12866 ** Values that may be passed as the second argument to a conflict-handler. 12867 ** 12868 ** <dl> 12869 ** <dt>SQLITE_CHANGESET_DATA<dd> 12870 ** The conflict handler is invoked with CHANGESET_DATA as the second argument 12871 ** when processing a DELETE or UPDATE change if a row with the required 12872 ** PRIMARY KEY fields is present in the database, but one or more other 12873 ** (non primary-key) fields modified by the update do not contain the 12874 ** expected "before" values. 12875 ** 12876 ** The conflicting row, in this case, is the database row with the matching 12877 ** primary key. 12878 ** 12879 ** <dt>SQLITE_CHANGESET_NOTFOUND<dd> 12880 ** The conflict handler is invoked with CHANGESET_NOTFOUND as the second 12881 ** argument when processing a DELETE or UPDATE change if a row with the 12882 ** required PRIMARY KEY fields is not present in the database. 12883 ** 12884 ** There is no conflicting row in this case. The results of invoking the 12885 ** sqlite3changeset_conflict() API are undefined. 12886 ** 12887 ** <dt>SQLITE_CHANGESET_CONFLICT<dd> 12888 ** CHANGESET_CONFLICT is passed as the second argument to the conflict 12889 ** handler while processing an INSERT change if the operation would result 12890 ** in duplicate primary key values. 12891 ** 12892 ** The conflicting row in this case is the database row with the matching 12893 ** primary key. 12894 ** 12895 ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd> 12896 ** If foreign key handling is enabled, and applying a changeset leaves the 12897 ** database in a state containing foreign key violations, the conflict 12898 ** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument 12899 ** exactly once before the changeset is committed. If the conflict handler 12900 ** returns CHANGESET_OMIT, the changes, including those that caused the 12901 ** foreign key constraint violation, are committed. Or, if it returns 12902 ** CHANGESET_ABORT, the changeset is rolled back. 12903 ** 12904 ** No current or conflicting row information is provided. The only function 12905 ** it is possible to call on the supplied sqlite3_changeset_iter handle 12906 ** is sqlite3changeset_fk_conflicts(). 12907 ** 12908 ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd> 12909 ** If any other constraint violation occurs while applying a change (i.e. 12910 ** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is 12911 ** invoked with CHANGESET_CONSTRAINT as the second argument. 12912 ** 12913 ** There is no conflicting row in this case. The results of invoking the 12914 ** sqlite3changeset_conflict() API are undefined. 12915 ** 12916 ** </dl> 12917 */ 12918 #define SQLITE_CHANGESET_DATA 1 12919 #define SQLITE_CHANGESET_NOTFOUND 2 12920 #define SQLITE_CHANGESET_CONFLICT 3 12921 #define SQLITE_CHANGESET_CONSTRAINT 4 12922 #define SQLITE_CHANGESET_FOREIGN_KEY 5 12923 12924 /* 12925 ** CAPI3REF: Constants Returned By The Conflict Handler 12926 ** 12927 ** A conflict handler callback must return one of the following three values. 12928 ** 12929 ** <dl> 12930 ** <dt>SQLITE_CHANGESET_OMIT<dd> 12931 ** If a conflict handler returns this value no special action is taken. The 12932 ** change that caused the conflict is not applied. The session module 12933 ** continues to the next change in the changeset. 12934 ** 12935 ** <dt>SQLITE_CHANGESET_REPLACE<dd> 12936 ** This value may only be returned if the second argument to the conflict 12937 ** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this 12938 ** is not the case, any changes applied so far are rolled back and the 12939 ** call to sqlite3changeset_apply() returns SQLITE_MISUSE. 12940 ** 12941 ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict 12942 ** handler, then the conflicting row is either updated or deleted, depending 12943 ** on the type of change. 12944 ** 12945 ** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict 12946 ** handler, then the conflicting row is removed from the database and a 12947 ** second attempt to apply the change is made. If this second attempt fails, 12948 ** the original row is restored to the database before continuing. 12949 ** 12950 ** <dt>SQLITE_CHANGESET_ABORT<dd> 12951 ** If this value is returned, any changes applied so far are rolled back 12952 ** and the call to sqlite3changeset_apply() returns SQLITE_ABORT. 12953 ** </dl> 12954 */ 12955 #define SQLITE_CHANGESET_OMIT 0 12956 #define SQLITE_CHANGESET_REPLACE 1 12957 #define SQLITE_CHANGESET_ABORT 2 12958 12959 /* 12960 ** CAPI3REF: Rebasing changesets 12961 ** EXPERIMENTAL 12962 ** 12963 ** Suppose there is a site hosting a database in state S0. And that 12964 ** modifications are made that move that database to state S1 and a 12965 ** changeset recorded (the "local" changeset). Then, a changeset based 12966 ** on S0 is received from another site (the "remote" changeset) and 12967 ** applied to the database. The database is then in state 12968 ** (S1+"remote"), where the exact state depends on any conflict 12969 ** resolution decisions (OMIT or REPLACE) made while applying "remote". 12970 ** Rebasing a changeset is to update it to take those conflict 12971 ** resolution decisions into account, so that the same conflicts 12972 ** do not have to be resolved elsewhere in the network. 12973 ** 12974 ** For example, if both the local and remote changesets contain an 12975 ** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)": 12976 ** 12977 ** local: INSERT INTO t1 VALUES(1, 'v1'); 12978 ** remote: INSERT INTO t1 VALUES(1, 'v2'); 12979 ** 12980 ** and the conflict resolution is REPLACE, then the INSERT change is 12981 ** removed from the local changeset (it was overridden). Or, if the 12982 ** conflict resolution was "OMIT", then the local changeset is modified 12983 ** to instead contain: 12984 ** 12985 ** UPDATE t1 SET b = 'v2' WHERE a=1; 12986 ** 12987 ** Changes within the local changeset are rebased as follows: 12988 ** 12989 ** <dl> 12990 ** <dt>Local INSERT<dd> 12991 ** This may only conflict with a remote INSERT. If the conflict 12992 ** resolution was OMIT, then add an UPDATE change to the rebased 12993 ** changeset. Or, if the conflict resolution was REPLACE, add 12994 ** nothing to the rebased changeset. 12995 ** 12996 ** <dt>Local DELETE<dd> 12997 ** This may conflict with a remote UPDATE or DELETE. In both cases the 12998 ** only possible resolution is OMIT. If the remote operation was a 12999 ** DELETE, then add no change to the rebased changeset. If the remote 13000 ** operation was an UPDATE, then the old.* fields of change are updated 13001 ** to reflect the new.* values in the UPDATE. 13002 ** 13003 ** <dt>Local UPDATE<dd> 13004 ** This may conflict with a remote UPDATE or DELETE. If it conflicts 13005 ** with a DELETE, and the conflict resolution was OMIT, then the update 13006 ** is changed into an INSERT. Any undefined values in the new.* record 13007 ** from the update change are filled in using the old.* values from 13008 ** the conflicting DELETE. Or, if the conflict resolution was REPLACE, 13009 ** the UPDATE change is simply omitted from the rebased changeset. 13010 ** 13011 ** If conflict is with a remote UPDATE and the resolution is OMIT, then 13012 ** the old.* values are rebased using the new.* values in the remote 13013 ** change. Or, if the resolution is REPLACE, then the change is copied 13014 ** into the rebased changeset with updates to columns also updated by 13015 ** the conflicting remote UPDATE removed. If this means no columns would 13016 ** be updated, the change is omitted. 13017 ** </dl> 13018 ** 13019 ** A local change may be rebased against multiple remote changes 13020 ** simultaneously. If a single key is modified by multiple remote 13021 ** changesets, they are combined as follows before the local changeset 13022 ** is rebased: 13023 ** 13024 ** <ul> 13025 ** <li> If there has been one or more REPLACE resolutions on a 13026 ** key, it is rebased according to a REPLACE. 13027 ** 13028 ** <li> If there have been no REPLACE resolutions on a key, then 13029 ** the local changeset is rebased according to the most recent 13030 ** of the OMIT resolutions. 13031 ** </ul> 13032 ** 13033 ** Note that conflict resolutions from multiple remote changesets are 13034 ** combined on a per-field basis, not per-row. This means that in the 13035 ** case of multiple remote UPDATE operations, some fields of a single 13036 ** local change may be rebased for REPLACE while others are rebased for 13037 ** OMIT. 13038 ** 13039 ** In order to rebase a local changeset, the remote changeset must first 13040 ** be applied to the local database using sqlite3changeset_apply_v2() and 13041 ** the buffer of rebase information captured. Then: 13042 ** 13043 ** <ol> 13044 ** <li> An sqlite3_rebaser object is created by calling 13045 ** sqlite3rebaser_create(). 13046 ** <li> The new object is configured with the rebase buffer obtained from 13047 ** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure(). 13048 ** If the local changeset is to be rebased against multiple remote 13049 ** changesets, then sqlite3rebaser_configure() should be called 13050 ** multiple times, in the same order that the multiple 13051 ** sqlite3changeset_apply_v2() calls were made. 13052 ** <li> Each local changeset is rebased by calling sqlite3rebaser_rebase(). 13053 ** <li> The sqlite3_rebaser object is deleted by calling 13054 ** sqlite3rebaser_delete(). 13055 ** </ol> 13056 */ 13057 typedef struct sqlite3_rebaser sqlite3_rebaser; 13058 13059 /* 13060 ** CAPI3REF: Create a changeset rebaser object. 13061 ** EXPERIMENTAL 13062 ** 13063 ** Allocate a new changeset rebaser object. If successful, set (*ppNew) to 13064 ** point to the new object and return SQLITE_OK. Otherwise, if an error 13065 ** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew) 13066 ** to NULL. 13067 */ 13068 SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew); 13069 13070 /* 13071 ** CAPI3REF: Configure a changeset rebaser object. 13072 ** EXPERIMENTAL 13073 ** 13074 ** Configure the changeset rebaser object to rebase changesets according 13075 ** to the conflict resolutions described by buffer pRebase (size nRebase 13076 ** bytes), which must have been obtained from a previous call to 13077 ** sqlite3changeset_apply_v2(). 13078 */ 13079 SQLITE_API int sqlite3rebaser_configure( 13080 sqlite3_rebaser*, 13081 int nRebase, const void *pRebase 13082 ); 13083 13084 /* 13085 ** CAPI3REF: Rebase a changeset 13086 ** EXPERIMENTAL 13087 ** 13088 ** Argument pIn must point to a buffer containing a changeset nIn bytes 13089 ** in size. This function allocates and populates a buffer with a copy 13090 ** of the changeset rebased according to the configuration of the 13091 ** rebaser object passed as the first argument. If successful, (*ppOut) 13092 ** is set to point to the new buffer containing the rebased changeset and 13093 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the 13094 ** responsibility of the caller to eventually free the new buffer using 13095 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut) 13096 ** are set to zero and an SQLite error code returned. 13097 */ 13098 SQLITE_API int sqlite3rebaser_rebase( 13099 sqlite3_rebaser*, 13100 int nIn, const void *pIn, 13101 int *pnOut, void **ppOut 13102 ); 13103 13104 /* 13105 ** CAPI3REF: Delete a changeset rebaser object. 13106 ** EXPERIMENTAL 13107 ** 13108 ** Delete the changeset rebaser object and all associated resources. There 13109 ** should be one call to this function for each successful invocation 13110 ** of sqlite3rebaser_create(). 13111 */ 13112 SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p); 13113 13114 /* 13115 ** CAPI3REF: Streaming Versions of API functions. 13116 ** 13117 ** The six streaming API xxx_strm() functions serve similar purposes to the 13118 ** corresponding non-streaming API functions: 13119 ** 13120 ** <table border=1 style="margin-left:8ex;margin-right:8ex"> 13121 ** <tr><th>Streaming function<th>Non-streaming equivalent</th> 13122 ** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply] 13123 ** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2] 13124 ** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat] 13125 ** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert] 13126 ** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start] 13127 ** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset] 13128 ** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset] 13129 ** </table> 13130 ** 13131 ** Non-streaming functions that accept changesets (or patchsets) as input 13132 ** require that the entire changeset be stored in a single buffer in memory. 13133 ** Similarly, those that return a changeset or patchset do so by returning 13134 ** a pointer to a single large buffer allocated using sqlite3_malloc(). 13135 ** Normally this is convenient. However, if an application running in a 13136 ** low-memory environment is required to handle very large changesets, the 13137 ** large contiguous memory allocations required can become onerous. 13138 ** 13139 ** In order to avoid this problem, instead of a single large buffer, input 13140 ** is passed to a streaming API functions by way of a callback function that 13141 ** the sessions module invokes to incrementally request input data as it is 13142 ** required. In all cases, a pair of API function parameters such as 13143 ** 13144 ** <pre> 13145 ** int nChangeset, 13146 ** void *pChangeset, 13147 ** </pre> 13148 ** 13149 ** Is replaced by: 13150 ** 13151 ** <pre> 13152 ** int (*xInput)(void *pIn, void *pData, int *pnData), 13153 ** void *pIn, 13154 ** </pre> 13155 ** 13156 ** Each time the xInput callback is invoked by the sessions module, the first 13157 ** argument passed is a copy of the supplied pIn context pointer. The second 13158 ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no 13159 ** error occurs the xInput method should copy up to (*pnData) bytes of data 13160 ** into the buffer and set (*pnData) to the actual number of bytes copied 13161 ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData) 13162 ** should be set to zero to indicate this. Or, if an error occurs, an SQLite 13163 ** error code should be returned. In all cases, if an xInput callback returns 13164 ** an error, all processing is abandoned and the streaming API function 13165 ** returns a copy of the error code to the caller. 13166 ** 13167 ** In the case of sqlite3changeset_start_strm(), the xInput callback may be 13168 ** invoked by the sessions module at any point during the lifetime of the 13169 ** iterator. If such an xInput callback returns an error, the iterator enters 13170 ** an error state, whereby all subsequent calls to iterator functions 13171 ** immediately fail with the same error code as returned by xInput. 13172 ** 13173 ** Similarly, streaming API functions that return changesets (or patchsets) 13174 ** return them in chunks by way of a callback function instead of via a 13175 ** pointer to a single large buffer. In this case, a pair of parameters such 13176 ** as: 13177 ** 13178 ** <pre> 13179 ** int *pnChangeset, 13180 ** void **ppChangeset, 13181 ** </pre> 13182 ** 13183 ** Is replaced by: 13184 ** 13185 ** <pre> 13186 ** int (*xOutput)(void *pOut, const void *pData, int nData), 13187 ** void *pOut 13188 ** </pre> 13189 ** 13190 ** The xOutput callback is invoked zero or more times to return data to 13191 ** the application. The first parameter passed to each call is a copy of the 13192 ** pOut pointer supplied by the application. The second parameter, pData, 13193 ** points to a buffer nData bytes in size containing the chunk of output 13194 ** data being returned. If the xOutput callback successfully processes the 13195 ** supplied data, it should return SQLITE_OK to indicate success. Otherwise, 13196 ** it should return some other SQLite error code. In this case processing 13197 ** is immediately abandoned and the streaming API function returns a copy 13198 ** of the xOutput error code to the application. 13199 ** 13200 ** The sessions module never invokes an xOutput callback with the third 13201 ** parameter set to a value less than or equal to zero. Other than this, 13202 ** no guarantees are made as to the size of the chunks of data returned. 13203 */ 13204 SQLITE_API int sqlite3changeset_apply_strm( 13205 sqlite3 *db, /* Apply change to "main" db of this handle */ 13206 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ 13207 void *pIn, /* First arg for xInput */ 13208 int(*xFilter)( 13209 void *pCtx, /* Copy of sixth arg to _apply() */ 13210 const char *zTab /* Table name */ 13211 ), 13212 int(*xConflict)( 13213 void *pCtx, /* Copy of sixth arg to _apply() */ 13214 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ 13215 sqlite3_changeset_iter *p /* Handle describing change and conflict */ 13216 ), 13217 void *pCtx /* First argument passed to xConflict */ 13218 ); 13219 SQLITE_API int sqlite3changeset_apply_v2_strm( 13220 sqlite3 *db, /* Apply change to "main" db of this handle */ 13221 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ 13222 void *pIn, /* First arg for xInput */ 13223 int(*xFilter)( 13224 void *pCtx, /* Copy of sixth arg to _apply() */ 13225 const char *zTab /* Table name */ 13226 ), 13227 int(*xConflict)( 13228 void *pCtx, /* Copy of sixth arg to _apply() */ 13229 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ 13230 sqlite3_changeset_iter *p /* Handle describing change and conflict */ 13231 ), 13232 void *pCtx, /* First argument passed to xConflict */ 13233 void **ppRebase, int *pnRebase, 13234 int flags 13235 ); 13236 SQLITE_API int sqlite3changeset_apply_v3_strm( 13237 sqlite3 *db, /* Apply change to "main" db of this handle */ 13238 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */ 13239 void *pIn, /* First arg for xInput */ 13240 int(*xFilter)( 13241 void *pCtx, /* Copy of sixth arg to _apply() */ 13242 sqlite3_changeset_iter *p 13243 ), 13244 int(*xConflict)( 13245 void *pCtx, /* Copy of sixth arg to _apply() */ 13246 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ 13247 sqlite3_changeset_iter *p /* Handle describing change and conflict */ 13248 ), 13249 void *pCtx, /* First argument passed to xConflict */ 13250 void **ppRebase, int *pnRebase, 13251 int flags 13252 ); 13253 SQLITE_API int sqlite3changeset_concat_strm( 13254 int (*xInputA)(void *pIn, void *pData, int *pnData), 13255 void *pInA, 13256 int (*xInputB)(void *pIn, void *pData, int *pnData), 13257 void *pInB, 13258 int (*xOutput)(void *pOut, const void *pData, int nData), 13259 void *pOut 13260 ); 13261 SQLITE_API int sqlite3changeset_invert_strm( 13262 int (*xInput)(void *pIn, void *pData, int *pnData), 13263 void *pIn, 13264 int (*xOutput)(void *pOut, const void *pData, int nData), 13265 void *pOut 13266 ); 13267 SQLITE_API int sqlite3changeset_start_strm( 13268 sqlite3_changeset_iter **pp, 13269 int (*xInput)(void *pIn, void *pData, int *pnData), 13270 void *pIn 13271 ); 13272 SQLITE_API int sqlite3changeset_start_v2_strm( 13273 sqlite3_changeset_iter **pp, 13274 int (*xInput)(void *pIn, void *pData, int *pnData), 13275 void *pIn, 13276 int flags 13277 ); 13278 SQLITE_API int sqlite3session_changeset_strm( 13279 sqlite3_session *pSession, 13280 int (*xOutput)(void *pOut, const void *pData, int nData), 13281 void *pOut 13282 ); 13283 SQLITE_API int sqlite3session_patchset_strm( 13284 sqlite3_session *pSession, 13285 int (*xOutput)(void *pOut, const void *pData, int nData), 13286 void *pOut 13287 ); 13288 SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*, 13289 int (*xInput)(void *pIn, void *pData, int *pnData), 13290 void *pIn 13291 ); 13292 SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*, 13293 int (*xOutput)(void *pOut, const void *pData, int nData), 13294 void *pOut 13295 ); 13296 SQLITE_API int sqlite3rebaser_rebase_strm( 13297 sqlite3_rebaser *pRebaser, 13298 int (*xInput)(void *pIn, void *pData, int *pnData), 13299 void *pIn, 13300 int (*xOutput)(void *pOut, const void *pData, int nData), 13301 void *pOut 13302 ); 13303 13304 /* 13305 ** CAPI3REF: Configure global parameters 13306 ** 13307 ** The sqlite3session_config() interface is used to make global configuration 13308 ** changes to the sessions module in order to tune it to the specific needs 13309 ** of the application. 13310 ** 13311 ** The sqlite3session_config() interface is not threadsafe. If it is invoked 13312 ** while any other thread is inside any other sessions method then the 13313 ** results are undefined. Furthermore, if it is invoked after any sessions 13314 ** related objects have been created, the results are also undefined. 13315 ** 13316 ** The first argument to the sqlite3session_config() function must be one 13317 ** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The 13318 ** interpretation of the (void*) value passed as the second parameter and 13319 ** the effect of calling this function depends on the value of the first 13320 ** parameter. 13321 ** 13322 ** <dl> 13323 ** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd> 13324 ** By default, the sessions module streaming interfaces attempt to input 13325 ** and output data in approximately 1 KiB chunks. This operand may be used 13326 ** to set and query the value of this configuration setting. The pointer 13327 ** passed as the second argument must point to a value of type (int). 13328 ** If this value is greater than 0, it is used as the new streaming data 13329 ** chunk size for both input and output. Before returning, the (int) value 13330 ** pointed to by pArg is set to the final value of the streaming interface 13331 ** chunk size. 13332 ** </dl> 13333 ** 13334 ** This function returns SQLITE_OK if successful, or an SQLite error code 13335 ** otherwise. 13336 */ 13337 SQLITE_API int sqlite3session_config(int op, void *pArg); 13338 13339 /* 13340 ** CAPI3REF: Values for sqlite3session_config(). 13341 */ 13342 #define SQLITE_SESSION_CONFIG_STRMSIZE 1 13343 13344 /* 13345 ** CAPI3REF: Configure a changegroup object 13346 ** 13347 ** Configure the changegroup object passed as the first argument. 13348 ** At present the only valid value for the second parameter is 13349 ** [SQLITE_CHANGEGROUP_CONFIG_PATCHSET]. 13350 */ 13351 SQLITE_API int sqlite3changegroup_config(sqlite3_changegroup*, int, void *pArg); 13352 13353 /* 13354 ** CAPI3REF: Options for sqlite3changegroup_config(). 13355 ** 13356 ** The following values may be passed as the 2nd parameter to 13357 ** sqlite3changegroup_config(). 13358 ** 13359 ** <dt>SQLITE_CHANGEGROUP_CONFIG_PATCHSET <dd> 13360 ** A changegroup object generates either a changeset or patchset. Usually, 13361 ** this is determined by whether the first call to sqlite3changegroup_add() 13362 ** is passed a changeset or a patchset. Or, if the first changes are added 13363 ** to the changegroup object using the sqlite3changegroup_change_xxx() 13364 ** APIs, then this option may be used to configure whether the changegroup 13365 ** object generates a changeset or patchset. 13366 ** 13367 ** When this option is invoked, parameter pArg must point to a value of 13368 ** type int. If the changegroup currently contains zero changes, and the 13369 ** value of the int variable is zero or greater than zero, then the 13370 ** changegroup is configured to generate a changeset or patchset, 13371 ** respectively. It is a no-op, not an error, if the changegroup is not 13372 ** configured because it has already started accumulating changes. 13373 ** 13374 ** Before returning, the int variable is set to 0 if the changegroup is 13375 ** configured to generate a changeset, or 1 if it is configured to generate 13376 ** a patchset. 13377 */ 13378 #define SQLITE_CHANGEGROUP_CONFIG_PATCHSET 1 13379 13380 13381 /* 13382 ** CAPI3REF: Begin adding a change to a changegroup 13383 ** 13384 ** This API is used, in concert with other sqlite3changegroup_change_xxx() 13385 ** APIs, to add changes to a changegroup object one at a time. To add a 13386 ** single change, the caller must: 13387 ** 13388 ** 1. Invoke sqlite3changegroup_change_begin() to indicate the type of 13389 ** change (INSERT, UPDATE or DELETE), the affected table and whether 13390 ** or not the change should be marked as indirect. 13391 ** 13392 ** 2. Invoke sqlite3changegroup_change_int64() or one of the other four 13393 ** value functions - _null(), _double(), _text() or _blob() - one or 13394 ** more times to specify old.* and new.* values for the change being 13395 ** constructed. 13396 ** 13397 ** 3. Invoke sqlite3changegroup_change_finish() to either finish adding 13398 ** the change to the group, or to discard the change altogether. 13399 ** 13400 ** The first argument to this function must be a pointer to the existing 13401 ** changegroup object that the change will be added to. The second argument 13402 ** must be SQLITE_INSERT, SQLITE_UPDATE or SQLITE_DELETE. The third is the 13403 ** name of the table that the change affects, and the fourth is a boolean 13404 ** flag specifying whether the change should be marked as "indirect" (if 13405 ** bIndirect is non-zero) or not indirect (if bIndirect is zero). 13406 ** 13407 ** Following a successful call to this function, this function may not be 13408 ** called again on the same changegroup object until after 13409 ** sqlite3changegroup_change_finish() has been called. Doing so is an 13410 ** SQLITE_MISUSE error. 13411 ** 13412 ** The changegroup object passed as the first argument must be already 13413 ** configured with schema data for the specified table. It may be configured 13414 ** either by calling sqlite3changegroup_schema() with a database that contains 13415 ** the table, or sqlite3changegroup_add() with a changeset that contains the 13416 ** table. If the changegroup object has not been configured with a schema for 13417 ** the specified table when this function is called, SQLITE_ERROR is returned. 13418 ** 13419 ** If successful, SQLITE_OK is returned. Otherwise, if an error occurs, an 13420 ** SQLite error code is returned. In this case, if argument pzErr is non-NULL, 13421 ** then (*pzErr) may be set to point to a buffer containing a utf-8 formated, 13422 ** nul-terminated, English language error message. It is the responsibility 13423 ** of the caller to eventually free this buffer using sqlite3_free(). 13424 */ 13425 SQLITE_API int sqlite3changegroup_change_begin( 13426 sqlite3_changegroup*, 13427 int eOp, 13428 const char *zTab, 13429 int bIndirect, 13430 char **pzErr 13431 ); 13432 13433 /* 13434 ** CAPI3REF: Add a 64-bit integer to a changegroup 13435 ** 13436 ** This function may only be called between a successful call to 13437 ** sqlite3changegroup_change_begin() and its matching 13438 ** sqlite3changegroup_change_finish() call. If it is called at any 13439 ** other time, it is an SQLITE_MISUSE error. Calling this function 13440 ** specifies a 64-bit integer value to be used in the change currently being 13441 ** added to the changegroup object passed as the first argument. 13442 ** 13443 ** The second parameter, bNew, specifies whether the value is to be part of 13444 ** the new.* (if bNew is non-zero) or old.* (if bNew is zero) record of 13445 ** the change under construction. If this does not match the type of change 13446 ** specified by the preceding call to sqlite3changegroup_change_begin() (i.e. 13447 ** an old.* value for an SQLITE_INSERT change, or a new.* value for an 13448 ** SQLITE_DELETE), then SQLITE_ERROR is returned. 13449 ** 13450 ** The third parameter specifies the column of the old.* or new.* record that 13451 ** the value will be a part of. If the specified table has an explicit primary 13452 ** key, then this is the index of the table column, numbered from 0 in the order 13453 ** specified within the CREATE TABLE statement. Or, if the table uses an 13454 ** implicit rowid key, then the column 0 is the rowid and the explicit columns 13455 ** are numbered starting from 1. If the iCol parameter is less than 0 or greater 13456 ** than the index of the last column in the table, SQLITE_RANGE is returned. 13457 ** 13458 ** The fourth parameter is the integer value to use as part of the old.* or 13459 ** new.* record. 13460 ** 13461 ** If this call is successful, SQLITE_OK is returned. Otherwise, if an 13462 ** error occurs, an SQLite error code is returned. 13463 */ 13464 SQLITE_API int sqlite3changegroup_change_int64( 13465 sqlite3_changegroup*, 13466 int bNew, 13467 int iCol, 13468 sqlite3_int64 iVal 13469 ); 13470 13471 /* 13472 ** CAPI3REF: Add a NULL to a changegroup 13473 ** 13474 ** This function is similar to sqlite3changegroup_change_int64(). Except that 13475 ** it configures the change currently under construction with a NULL value 13476 ** instead of a 64-bit integer. 13477 */ 13478 SQLITE_API int sqlite3changegroup_change_null(sqlite3_changegroup*, int, int); 13479 13480 /* 13481 ** CAPI3REF: Add an double to a changegroup 13482 ** 13483 ** This function is similar to sqlite3changegroup_change_int64(). Except that 13484 ** it configures the change currently being constructed with a real value 13485 ** instead of a 64-bit integer. 13486 */ 13487 SQLITE_API int sqlite3changegroup_change_double(sqlite3_changegroup*, int, int, double); 13488 13489 /* 13490 ** CAPI3REF: Add a text value to a changegroup 13491 ** 13492 ** This function is similar to sqlite3changegroup_change_int64(). It configures 13493 ** the currently accumulated change with a text value instead of a 64-bit 13494 ** integer. Parameter pVal points to a buffer containing the text encoded using 13495 ** utf-8. Parameter nVal may either be the size of the text value in bytes, or 13496 ** else a negative value, in which case the buffer pVal points to is assumed to 13497 ** be nul-terminated. 13498 */ 13499 SQLITE_API int sqlite3changegroup_change_text( 13500 sqlite3_changegroup*, int, int, const char *pVal, int nVal 13501 ); 13502 13503 /* 13504 ** CAPI3REF: Add a blob to a changegroup 13505 ** 13506 ** This function is similar to sqlite3changegroup_change_int64(). It configures 13507 ** the currently accumulated change with a blob value instead of a 64-bit 13508 ** integer. Parameter pVal points to a buffer containing the blob. Parameter 13509 ** nVal is the size of the blob in bytes. 13510 */ 13511 SQLITE_API int sqlite3changegroup_change_blob( 13512 sqlite3_changegroup*, int, int, const void *pVal, int nVal 13513 ); 13514 13515 /* 13516 ** CAPI3REF: Finish adding one-at-at-time changes to a changegroup 13517 ** 13518 ** This function may only be called following a successful call to 13519 ** sqlite3changegroup_change_begin(). Otherwise, it is an SQLITE_MISUSE error. 13520 ** 13521 ** If parameter bDiscard is non-zero, then the current change is simply 13522 ** discarded. In this case this function is always successful and SQLITE_OK 13523 ** returned. 13524 ** 13525 ** If parameter bDiscard is zero, then an attempt is made to add the current 13526 ** change to the changegroup. Assuming the changegroup is configured to 13527 ** produce a changeset (not a patchset), this requires that: 13528 ** 13529 ** * If the change is an INSERT or DELETE, then a value must be specified 13530 ** for all columns of the new.* or old.* record, respectively. 13531 ** 13532 ** * If the change is an UPDATE record, then values must be provided for 13533 ** the PRIMARY KEY columns of the old.* record, but must not be provided 13534 ** for PRIMARY KEY columns of the new.* record. 13535 ** 13536 ** * If the change is an UPDATE record, then for each non-PRIMARY KEY 13537 ** column in the old.* record for which a value has been provided, a 13538 ** value must also be provided for the same column in the new.* record. 13539 ** Similarly, for each non-PK column in the old.* record for which 13540 ** a value is not provided, a value must not be provided for the same 13541 ** column in the new.* record. 13542 ** 13543 ** * All values specified for PRIMARY KEY columns must be non-NULL. 13544 ** 13545 ** Otherwise, it is an error. 13546 ** 13547 ** If the changegroup already contains a change for the same row (identified 13548 ** by PRIMARY KEY columns), then the current change is combined with the 13549 ** existing change in the same way as for sqlite3changegroup_add(). 13550 ** 13551 ** For a patchset, all of the above rules apply except that it doesn't matter 13552 ** whether or not values are provided for the non-PK old.* record columns 13553 ** for an UPDATE or DELETE change. This means that code used to produce 13554 ** a changeset using the sqlite3changegroup_change_xxx() APIs may also 13555 ** be used to produce patchsets. 13556 ** 13557 ** If the call is successful, SQLITE_OK is returned. Otherwise, if an error 13558 ** occurs, an SQLite error code is returned. If an error is returned and 13559 ** parameter pzErr is not NULL, then (*pzErr) may be set to point to a buffer 13560 ** containing a nul-terminated, utf-8 encoded, English language error message. 13561 ** It is the responsibility of the caller to eventually free any such error 13562 ** message buffer using sqlite3_free(). 13563 */ 13564 SQLITE_API int sqlite3changegroup_change_finish( 13565 sqlite3_changegroup*, 13566 int bDiscard, 13567 char **pzErr 13568 ); 13569 13570 /* 13571 ** Make sure we can call this stuff from C++. 13572 */ 13573 #ifdef __cplusplus 13574 } 13575 #endif 13576 13577 #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */ 13578 13579 /******** End of sqlite3session.h *********/ 13580 /******** Begin file fts5.h *********/ 13581 /* 13582 ** 2014 May 31 13583 ** 13584 ** The author disclaims copyright to this source code. In place of 13585 ** a legal notice, here is a blessing: 13586 ** 13587 ** May you do good and not evil. 13588 ** May you find forgiveness for yourself and forgive others. 13589 ** May you share freely, never taking more than you give. 13590 ** 13591 ****************************************************************************** 13592 ** 13593 ** Interfaces to extend FTS5. Using the interfaces defined in this file, 13594 ** FTS5 may be extended with: 13595 ** 13596 ** * custom tokenizers, and 13597 ** * custom auxiliary functions. 13598 */ 13599 13600 13601 #ifndef _FTS5_H 13602 #define _FTS5_H 13603 13604 13605 #ifdef __cplusplus 13606 extern "C" { 13607 #endif 13608 13609 /************************************************************************* 13610 ** CUSTOM AUXILIARY FUNCTIONS 13611 ** 13612 ** Virtual table implementations may overload SQL functions by implementing 13613 ** the sqlite3_module.xFindFunction() method. 13614 */ 13615 13616 typedef struct Fts5ExtensionApi Fts5ExtensionApi; 13617 typedef struct Fts5Context Fts5Context; 13618 typedef struct Fts5PhraseIter Fts5PhraseIter; 13619 13620 typedef void (*fts5_extension_function)( 13621 const Fts5ExtensionApi *pApi, /* API offered by current FTS version */ 13622 Fts5Context *pFts, /* First arg to pass to pApi functions */ 13623 sqlite3_context *pCtx, /* Context for returning result/error */ 13624 int nVal, /* Number of values in apVal[] array */ 13625 sqlite3_value **apVal /* Array of trailing arguments */ 13626 ); 13627 13628 struct Fts5PhraseIter { 13629 const unsigned char *a; 13630 const unsigned char *b; 13631 }; 13632 13633 /* 13634 ** EXTENSION API FUNCTIONS 13635 ** 13636 ** xUserData(pFts): 13637 ** Return a copy of the pUserData pointer passed to the xCreateFunction() 13638 ** API when the extension function was registered. 13639 ** 13640 ** xColumnTotalSize(pFts, iCol, pnToken): 13641 ** If parameter iCol is less than zero, set output variable *pnToken 13642 ** to the total number of tokens in the FTS5 table. Or, if iCol is 13643 ** non-negative but less than the number of columns in the table, return 13644 ** the total number of tokens in column iCol, considering all rows in 13645 ** the FTS5 table. 13646 ** 13647 ** If parameter iCol is greater than or equal to the number of columns 13648 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. 13649 ** an OOM condition or IO error), an appropriate SQLite error code is 13650 ** returned. 13651 ** 13652 ** xColumnCount(pFts): 13653 ** Return the number of columns in the table. 13654 ** 13655 ** xColumnSize(pFts, iCol, pnToken): 13656 ** If parameter iCol is less than zero, set output variable *pnToken 13657 ** to the total number of tokens in the current row. Or, if iCol is 13658 ** non-negative but less than the number of columns in the table, set 13659 ** *pnToken to the number of tokens in column iCol of the current row. 13660 ** 13661 ** If parameter iCol is greater than or equal to the number of columns 13662 ** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g. 13663 ** an OOM condition or IO error), an appropriate SQLite error code is 13664 ** returned. 13665 ** 13666 ** This function may be quite inefficient if used with an FTS5 table 13667 ** created with the "columnsize=0" option. 13668 ** 13669 ** xColumnText: 13670 ** If parameter iCol is less than zero, or greater than or equal to the 13671 ** number of columns in the table, SQLITE_RANGE is returned. 13672 ** 13673 ** Otherwise, this function attempts to retrieve the text of column iCol of 13674 ** the current document. If successful, (*pz) is set to point to a buffer 13675 ** containing the text in utf-8 encoding, (*pn) is set to the size in bytes 13676 ** (not characters) of the buffer and SQLITE_OK is returned. Otherwise, 13677 ** if an error occurs, an SQLite error code is returned and the final values 13678 ** of (*pz) and (*pn) are undefined. 13679 ** 13680 ** xPhraseCount: 13681 ** Returns the number of phrases in the current query expression. 13682 ** 13683 ** xPhraseSize: 13684 ** If parameter iCol is less than zero, or greater than or equal to the 13685 ** number of phrases in the current query, as returned by xPhraseCount, 13686 ** 0 is returned. Otherwise, this function returns the number of tokens in 13687 ** phrase iPhrase of the query. Phrases are numbered starting from zero. 13688 ** 13689 ** xInstCount: 13690 ** Set *pnInst to the total number of occurrences of all phrases within 13691 ** the query within the current row. Return SQLITE_OK if successful, or 13692 ** an error code (i.e. SQLITE_NOMEM) if an error occurs. 13693 ** 13694 ** This API can be quite slow if used with an FTS5 table created with the 13695 ** "detail=none" or "detail=column" option. If the FTS5 table is created 13696 ** with either "detail=none" or "detail=column" and "content=" option 13697 ** (i.e. if it is a contentless table), then this API always returns 0. 13698 ** 13699 ** xInst: 13700 ** Query for the details of phrase match iIdx within the current row. 13701 ** Phrase matches are numbered starting from zero, so the iIdx argument 13702 ** should be greater than or equal to zero and smaller than the value 13703 ** output by xInstCount(). If iIdx is less than zero or greater than 13704 ** or equal to the value returned by xInstCount(), SQLITE_RANGE is returned. 13705 ** 13706 ** Otherwise, output parameter *piPhrase is set to the phrase number, *piCol 13707 ** to the column in which it occurs and *piOff the token offset of the 13708 ** first token of the phrase. SQLITE_OK is returned if successful, or an 13709 ** error code (i.e. SQLITE_NOMEM) if an error occurs. 13710 ** 13711 ** This API can be quite slow if used with an FTS5 table created with the 13712 ** "detail=none" or "detail=column" option. 13713 ** 13714 ** xRowid: 13715 ** Returns the rowid of the current row. 13716 ** 13717 ** xTokenize: 13718 ** Tokenize text using the tokenizer belonging to the FTS5 table. 13719 ** 13720 ** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback): 13721 ** This API function is used to query the FTS table for phrase iPhrase 13722 ** of the current query. Specifically, a query equivalent to: 13723 ** 13724 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid 13725 ** 13726 ** with $p set to a phrase equivalent to the phrase iPhrase of the 13727 ** current query is executed. Any column filter that applies to 13728 ** phrase iPhrase of the current query is included in $p. For each 13729 ** row visited, the callback function passed as the fourth argument 13730 ** is invoked. The context and API objects passed to the callback 13731 ** function may be used to access the properties of each matched row. 13732 ** Invoking Api.xUserData() returns a copy of the pointer passed as 13733 ** the third argument to pUserData. 13734 ** 13735 ** If parameter iPhrase is less than zero, or greater than or equal to 13736 ** the number of phrases in the query, as returned by xPhraseCount(), 13737 ** this function returns SQLITE_RANGE. 13738 ** 13739 ** If the callback function returns any value other than SQLITE_OK, the 13740 ** query is abandoned and the xQueryPhrase function returns immediately. 13741 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK. 13742 ** Otherwise, the error code is propagated upwards. 13743 ** 13744 ** If the query runs to completion without incident, SQLITE_OK is returned. 13745 ** Or, if some error occurs before the query completes or is aborted by 13746 ** the callback, an SQLite error code is returned. 13747 ** 13748 ** 13749 ** xSetAuxdata(pFts5, pAux, xDelete) 13750 ** 13751 ** Save the pointer passed as the second argument as the extension function's 13752 ** "auxiliary data". The pointer may then be retrieved by the current or any 13753 ** future invocation of the same fts5 extension function made as part of 13754 ** the same MATCH query using the xGetAuxdata() API. 13755 ** 13756 ** Each extension function is allocated a single auxiliary data slot for 13757 ** each FTS query (MATCH expression). If the extension function is invoked 13758 ** more than once for a single FTS query, then all invocations share a 13759 ** single auxiliary data context. 13760 ** 13761 ** If there is already an auxiliary data pointer when this function is 13762 ** invoked, then it is replaced by the new pointer. If an xDelete callback 13763 ** was specified along with the original pointer, it is invoked at this 13764 ** point. 13765 ** 13766 ** The xDelete callback, if one is specified, is also invoked on the 13767 ** auxiliary data pointer after the FTS5 query has finished. 13768 ** 13769 ** If an error (e.g. an OOM condition) occurs within this function, 13770 ** the auxiliary data is set to NULL and an error code returned. If the 13771 ** xDelete parameter was not NULL, it is invoked on the auxiliary data 13772 ** pointer before returning. 13773 ** 13774 ** 13775 ** xGetAuxdata(pFts5, bClear) 13776 ** 13777 ** Returns the current auxiliary data pointer for the fts5 extension 13778 ** function. See the xSetAuxdata() method for details. 13779 ** 13780 ** If the bClear argument is non-zero, then the auxiliary data is cleared 13781 ** (set to NULL) before this function returns. In this case the xDelete, 13782 ** if any, is not invoked. 13783 ** 13784 ** 13785 ** xRowCount(pFts5, pnRow) 13786 ** 13787 ** This function is used to retrieve the total number of rows in the table. 13788 ** In other words, the same value that would be returned by: 13789 ** 13790 ** SELECT count(*) FROM ftstable; 13791 ** 13792 ** xPhraseFirst() 13793 ** This function is used, along with type Fts5PhraseIter and the xPhraseNext 13794 ** method, to iterate through all instances of a single query phrase within 13795 ** the current row. This is the same information as is accessible via the 13796 ** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient 13797 ** to use, this API may be faster under some circumstances. To iterate 13798 ** through instances of phrase iPhrase, use the following code: 13799 ** 13800 ** Fts5PhraseIter iter; 13801 ** int iCol, iOff; 13802 ** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff); 13803 ** iCol>=0; 13804 ** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff) 13805 ** ){ 13806 ** // An instance of phrase iPhrase at offset iOff of column iCol 13807 ** } 13808 ** 13809 ** The Fts5PhraseIter structure is defined above. Applications should not 13810 ** modify this structure directly - it should only be used as shown above 13811 ** with the xPhraseFirst() and xPhraseNext() API methods (and by 13812 ** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below). 13813 ** 13814 ** This API can be quite slow if used with an FTS5 table created with the 13815 ** "detail=none" or "detail=column" option. If the FTS5 table is created 13816 ** with either "detail=none" or "detail=column" and "content=" option 13817 ** (i.e. if it is a contentless table), then this API always iterates 13818 ** through an empty set (all calls to xPhraseFirst() set iCol to -1). 13819 ** 13820 ** In all cases, matches are visited in (column ASC, offset ASC) order. 13821 ** i.e. all those in column 0, sorted by offset, followed by those in 13822 ** column 1, etc. 13823 ** 13824 ** xPhraseNext() 13825 ** See xPhraseFirst above. 13826 ** 13827 ** xPhraseFirstColumn() 13828 ** This function and xPhraseNextColumn() are similar to the xPhraseFirst() 13829 ** and xPhraseNext() APIs described above. The difference is that instead 13830 ** of iterating through all instances of a phrase in the current row, these 13831 ** APIs are used to iterate through the set of columns in the current row 13832 ** that contain one or more instances of a specified phrase. For example: 13833 ** 13834 ** Fts5PhraseIter iter; 13835 ** int iCol; 13836 ** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol); 13837 ** iCol>=0; 13838 ** pApi->xPhraseNextColumn(pFts, &iter, &iCol) 13839 ** ){ 13840 ** // Column iCol contains at least one instance of phrase iPhrase 13841 ** } 13842 ** 13843 ** This API can be quite slow if used with an FTS5 table created with the 13844 ** "detail=none" option. If the FTS5 table is created with either 13845 ** "detail=none" "content=" option (i.e. if it is a contentless table), 13846 ** then this API always iterates through an empty set (all calls to 13847 ** xPhraseFirstColumn() set iCol to -1). 13848 ** 13849 ** The information accessed using this API and its companion 13850 ** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext 13851 ** (or xInst/xInstCount). The chief advantage of this API is that it is 13852 ** significantly more efficient than those alternatives when used with 13853 ** "detail=column" tables. 13854 ** 13855 ** xPhraseNextColumn() 13856 ** See xPhraseFirstColumn above. 13857 ** 13858 ** xQueryToken(pFts5, iPhrase, iToken, ppToken, pnToken) 13859 ** This is used to access token iToken of phrase iPhrase of the current 13860 ** query. Before returning, output parameter *ppToken is set to point 13861 ** to a buffer containing the requested token, and *pnToken to the 13862 ** size of this buffer in bytes. 13863 ** 13864 ** If iPhrase or iToken are less than zero, or if iPhrase is greater than 13865 ** or equal to the number of phrases in the query as reported by 13866 ** xPhraseCount(), or if iToken is equal to or greater than the number of 13867 ** tokens in the phrase, SQLITE_RANGE is returned and *ppToken and *pnToken 13868 are both zeroed. 13869 ** 13870 ** The output text is not a copy of the query text that specified the 13871 ** token. It is the output of the tokenizer module. For tokendata=1 13872 ** tables, this includes any embedded 0x00 and trailing data. 13873 ** 13874 ** xInstToken(pFts5, iIdx, iToken, ppToken, pnToken) 13875 ** This is used to access token iToken of phrase hit iIdx within the 13876 ** current row. If iIdx is less than zero or greater than or equal to the 13877 ** value returned by xInstCount(), SQLITE_RANGE is returned. Otherwise, 13878 ** output variable (*ppToken) is set to point to a buffer containing the 13879 ** matching document token, and (*pnToken) to the size of that buffer in 13880 ** bytes. 13881 ** 13882 ** The output text is not a copy of the document text that was tokenized. 13883 ** It is the output of the tokenizer module. For tokendata=1 tables, this 13884 ** includes any embedded 0x00 and trailing data. 13885 ** 13886 ** This API may be slow in some cases if the token identified by parameters 13887 ** iIdx and iToken matched a prefix token in the query. In most cases, the 13888 ** first call to this API for each prefix token in the query is forced 13889 ** to scan the portion of the full-text index that matches the prefix 13890 ** token to collect the extra data required by this API. If the prefix 13891 ** token matches a large number of token instances in the document set, 13892 ** this may be a performance problem. 13893 ** 13894 ** If the user knows in advance that a query may use this API for a 13895 ** prefix token, FTS5 may be configured to collect all required data as part 13896 ** of the initial querying of the full-text index, avoiding the second scan 13897 ** entirely. This also causes prefix queries that do not use this API to 13898 ** run more slowly and use more memory. FTS5 may be configured in this way 13899 ** either on a per-table basis using the [FTS5 insttoken | 'insttoken'] 13900 ** option, or on a per-query basis using the 13901 ** [fts5_insttoken | fts5_insttoken()] user function. 13902 ** 13903 ** This API can be quite slow if used with an FTS5 table created with the 13904 ** "detail=none" or "detail=column" option. 13905 ** 13906 ** xColumnLocale(pFts5, iIdx, pzLocale, pnLocale) 13907 ** If parameter iCol is less than zero, or greater than or equal to the 13908 ** number of columns in the table, SQLITE_RANGE is returned. 13909 ** 13910 ** Otherwise, this function attempts to retrieve the locale associated 13911 ** with column iCol of the current row. Usually, there is no associated 13912 ** locale, and output parameters (*pzLocale) and (*pnLocale) are set 13913 ** to NULL and 0, respectively. However, if the fts5_locale() function 13914 ** was used to associate a locale with the value when it was inserted 13915 ** into the fts5 table, then (*pzLocale) is set to point to a nul-terminated 13916 ** buffer containing the name of the locale in utf-8 encoding. (*pnLocale) 13917 ** is set to the size in bytes of the buffer, not including the 13918 ** nul-terminator. 13919 ** 13920 ** If successful, SQLITE_OK is returned. Or, if an error occurs, an 13921 ** SQLite error code is returned. The final value of the output parameters 13922 ** is undefined in this case. 13923 ** 13924 ** xTokenize_v2: 13925 ** Tokenize text using the tokenizer belonging to the FTS5 table. This 13926 ** API is the same as the xTokenize() API, except that it allows a tokenizer 13927 ** locale to be specified. 13928 */ 13929 struct Fts5ExtensionApi { 13930 int iVersion; /* Currently always set to 4 */ 13931 13932 void *(*xUserData)(Fts5Context*); 13933 13934 int (*xColumnCount)(Fts5Context*); 13935 int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow); 13936 int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken); 13937 13938 int (*xTokenize)(Fts5Context*, 13939 const char *pText, int nText, /* Text to tokenize */ 13940 void *pCtx, /* Context passed to xToken() */ 13941 int (*xToken)(void*, int, const char*, int, int, int) /* Callback */ 13942 ); 13943 13944 int (*xPhraseCount)(Fts5Context*); 13945 int (*xPhraseSize)(Fts5Context*, int iPhrase); 13946 13947 int (*xInstCount)(Fts5Context*, int *pnInst); 13948 int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff); 13949 13950 sqlite3_int64 (*xRowid)(Fts5Context*); 13951 int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn); 13952 int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken); 13953 13954 int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData, 13955 int(*)(const Fts5ExtensionApi*,Fts5Context*,void*) 13956 ); 13957 int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*)); 13958 void *(*xGetAuxdata)(Fts5Context*, int bClear); 13959 13960 int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*); 13961 void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff); 13962 13963 int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*); 13964 void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol); 13965 13966 /* Below this point are iVersion>=3 only */ 13967 int (*xQueryToken)(Fts5Context*, 13968 int iPhrase, int iToken, 13969 const char **ppToken, int *pnToken 13970 ); 13971 int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*); 13972 13973 /* Below this point are iVersion>=4 only */ 13974 int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn); 13975 int (*xTokenize_v2)(Fts5Context*, 13976 const char *pText, int nText, /* Text to tokenize */ 13977 const char *pLocale, int nLocale, /* Locale to pass to tokenizer */ 13978 void *pCtx, /* Context passed to xToken() */ 13979 int (*xToken)(void*, int, const char*, int, int, int) /* Callback */ 13980 ); 13981 }; 13982 13983 /* 13984 ** CUSTOM AUXILIARY FUNCTIONS 13985 *************************************************************************/ 13986 13987 /************************************************************************* 13988 ** CUSTOM TOKENIZERS 13989 ** 13990 ** Applications may also register custom tokenizer types. A tokenizer 13991 ** is registered by providing fts5 with a populated instance of the 13992 ** following structure. All structure methods must be defined, setting 13993 ** any member of the fts5_tokenizer struct to NULL leads to undefined 13994 ** behaviour. The structure methods are expected to function as follows: 13995 ** 13996 ** xCreate: 13997 ** This function is used to allocate and initialize a tokenizer instance. 13998 ** A tokenizer instance is required to actually tokenize text. 13999 ** 14000 ** The first argument passed to this function is a copy of the (void*) 14001 ** pointer provided by the application when the fts5_tokenizer_v2 object 14002 ** was registered with FTS5 (the third argument to xCreateTokenizer()). 14003 ** The second and third arguments are an array of nul-terminated strings 14004 ** containing the tokenizer arguments, if any, specified following the 14005 ** tokenizer name as part of the CREATE VIRTUAL TABLE statement used 14006 ** to create the FTS5 table. 14007 ** 14008 ** The final argument is an output variable. If successful, (*ppOut) 14009 ** should be set to point to the new tokenizer handle and SQLITE_OK 14010 ** returned. If an error occurs, some value other than SQLITE_OK should 14011 ** be returned. In this case, fts5 assumes that the final value of *ppOut 14012 ** is undefined. 14013 ** 14014 ** xDelete: 14015 ** This function is invoked to delete a tokenizer handle previously 14016 ** allocated using xCreate(). Fts5 guarantees that this function will 14017 ** be invoked exactly once for each successful call to xCreate(). 14018 ** 14019 ** xTokenize: 14020 ** This function is expected to tokenize the nText byte string indicated 14021 ** by argument pText. pText may or may not be nul-terminated. The first 14022 ** argument passed to this function is a pointer to an Fts5Tokenizer object 14023 ** returned by an earlier call to xCreate(). 14024 ** 14025 ** The third argument indicates the reason that FTS5 is requesting 14026 ** tokenization of the supplied text. This is always one of the following 14027 ** four values: 14028 ** 14029 ** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into 14030 ** or removed from the FTS table. The tokenizer is being invoked to 14031 ** determine the set of tokens to add to (or delete from) the 14032 ** FTS index. 14033 ** 14034 ** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed 14035 ** against the FTS index. The tokenizer is being called to tokenize 14036 ** a bareword or quoted string specified as part of the query. 14037 ** 14038 ** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as 14039 ** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is 14040 ** followed by a "*" character, indicating that the last token 14041 ** returned by the tokenizer will be treated as a token prefix. 14042 ** 14043 ** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to 14044 ** satisfy an fts5_api.xTokenize() request made by an auxiliary 14045 ** function. Or an fts5_api.xColumnSize() request made by the same 14046 ** on a columnsize=0 database. 14047 ** </ul> 14048 ** 14049 ** The sixth and seventh arguments passed to xTokenize() - pLocale and 14050 ** nLocale - are a pointer to a buffer containing the locale to use for 14051 ** tokenization (e.g. "en_US") and its size in bytes, respectively. The 14052 ** pLocale buffer is not nul-terminated. pLocale may be passed NULL (in 14053 ** which case nLocale is always 0) to indicate that the tokenizer should 14054 ** use its default locale. 14055 ** 14056 ** For each token in the input string, the supplied callback xToken() must 14057 ** be invoked. The first argument to it should be a copy of the pointer 14058 ** passed as the second argument to xTokenize(). The third and fourth 14059 ** arguments are a pointer to a buffer containing the token text, and the 14060 ** size of the token in bytes. The 4th and 5th arguments are the byte offsets 14061 ** of the first byte of and first byte immediately following the text from 14062 ** which the token is derived within the input. 14063 ** 14064 ** The second argument passed to the xToken() callback ("tflags") should 14065 ** normally be set to 0. The exception is if the tokenizer supports 14066 ** synonyms. In this case see the discussion below for details. 14067 ** 14068 ** FTS5 assumes the xToken() callback is invoked for each token in the 14069 ** order that they occur within the input text. 14070 ** 14071 ** If an xToken() callback returns any value other than SQLITE_OK, then 14072 ** the tokenization should be abandoned and the xTokenize() method should 14073 ** immediately return a copy of the xToken() return value. Or, if the 14074 ** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally, 14075 ** if an error occurs with the xTokenize() implementation itself, it 14076 ** may abandon the tokenization and return any error code other than 14077 ** SQLITE_OK or SQLITE_DONE. 14078 ** 14079 ** If the tokenizer is registered using an fts5_tokenizer_v2 object, 14080 ** then the xTokenize() method has two additional arguments - pLocale 14081 ** and nLocale. These specify the locale that the tokenizer should use 14082 ** for the current request. If pLocale and nLocale are both 0, then the 14083 ** tokenizer should use its default locale. Otherwise, pLocale points to 14084 ** an nLocale byte buffer containing the name of the locale to use as utf-8 14085 ** text. pLocale is not nul-terminated. 14086 ** 14087 ** FTS5_TOKENIZER 14088 ** 14089 ** There is also an fts5_tokenizer object. This is an older, deprecated, 14090 ** version of fts5_tokenizer_v2. It is similar except that: 14091 ** 14092 ** <ul> 14093 ** <li> There is no "iVersion" field, and 14094 ** <li> The xTokenize() method does not take a locale argument. 14095 ** </ul> 14096 ** 14097 ** Legacy fts5_tokenizer tokenizers must be registered using the 14098 ** legacy xCreateTokenizer() function, instead of xCreateTokenizer_v2(). 14099 ** 14100 ** Tokenizer implementations registered using either API may be retrieved 14101 ** using both xFindTokenizer() and xFindTokenizer_v2(). 14102 ** 14103 ** SYNONYM SUPPORT 14104 ** 14105 ** Custom tokenizers may also support synonyms. Consider a case in which a 14106 ** user wishes to query for a phrase such as "first place". Using the 14107 ** built-in tokenizers, the FTS5 query 'first + place' will match instances 14108 ** of "first place" within the document set, but not alternative forms 14109 ** such as "1st place". In some applications, it would be better to match 14110 ** all instances of "first place" or "1st place" regardless of which form 14111 ** the user specified in the MATCH query text. 14112 ** 14113 ** There are several ways to approach this in FTS5: 14114 ** 14115 ** <ol><li> By mapping all synonyms to a single token. In this case, using 14116 ** the above example, this means that the tokenizer returns the 14117 ** same token for inputs "first" and "1st". Say that token is in 14118 ** fact "first", so that when the user inserts the document "I won 14119 ** 1st place" entries are added to the index for tokens "i", "won", 14120 ** "first" and "place". If the user then queries for '1st + place', 14121 ** the tokenizer substitutes "first" for "1st" and the query works 14122 ** as expected. 14123 ** 14124 ** <li> By querying the index for all synonyms of each query term 14125 ** separately. In this case, when tokenizing query text, the 14126 ** tokenizer may provide multiple synonyms for a single term 14127 ** within the document. FTS5 then queries the index for each 14128 ** synonym individually. For example, faced with the query: 14129 ** 14130 ** <codeblock> 14131 ** ... MATCH 'first place'</codeblock> 14132 ** 14133 ** the tokenizer offers both "1st" and "first" as synonyms for the 14134 ** first token in the MATCH query and FTS5 effectively runs a query 14135 ** similar to: 14136 ** 14137 ** <codeblock> 14138 ** ... MATCH '(first OR 1st) place'</codeblock> 14139 ** 14140 ** except that, for the purposes of auxiliary functions, the query 14141 ** still appears to contain just two phrases - "(first OR 1st)" 14142 ** being treated as a single phrase. 14143 ** 14144 ** <li> By adding multiple synonyms for a single term to the FTS index. 14145 ** Using this method, when tokenizing document text, the tokenizer 14146 ** provides multiple synonyms for each token. So that when a 14147 ** document such as "I won first place" is tokenized, entries are 14148 ** added to the FTS index for "i", "won", "first", "1st" and 14149 ** "place". 14150 ** 14151 ** This way, even if the tokenizer does not provide synonyms 14152 ** when tokenizing query text (it should not - to do so would be 14153 ** inefficient), it doesn't matter if the user queries for 14154 ** 'first + place' or '1st + place', as there are entries in the 14155 ** FTS index corresponding to both forms of the first token. 14156 ** </ol> 14157 ** 14158 ** Whether it is parsing document or query text, any call to xToken that 14159 ** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit 14160 ** is considered to supply a synonym for the previous token. For example, 14161 ** when parsing the document "I won first place", a tokenizer that supports 14162 ** synonyms would call xToken() 5 times, as follows: 14163 ** 14164 ** <codeblock> 14165 ** xToken(pCtx, 0, "i", 1, 0, 1); 14166 ** xToken(pCtx, 0, "won", 3, 2, 5); 14167 ** xToken(pCtx, 0, "first", 5, 6, 11); 14168 ** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11); 14169 ** xToken(pCtx, 0, "place", 5, 12, 17); 14170 **</codeblock> 14171 ** 14172 ** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time 14173 ** xToken() is called. Multiple synonyms may be specified for a single token 14174 ** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence. 14175 ** There is no limit to the number of synonyms that may be provided for a 14176 ** single token. 14177 ** 14178 ** In many cases, method (1) above is the best approach. It does not add 14179 ** extra data to the FTS index or require FTS5 to query for multiple terms, 14180 ** so it is efficient in terms of disk space and query speed. However, it 14181 ** does not support prefix queries very well. If, as suggested above, the 14182 ** token "first" is substituted for "1st" by the tokenizer, then the query: 14183 ** 14184 ** <codeblock> 14185 ** ... MATCH '1s*'</codeblock> 14186 ** 14187 ** will not match documents that contain the token "1st" (as the tokenizer 14188 ** will probably not map "1s" to any prefix of "first"). 14189 ** 14190 ** For full prefix support, method (3) may be preferred. In this case, 14191 ** because the index contains entries for both "first" and "1st", prefix 14192 ** queries such as 'fi*' or '1s*' will match correctly. However, because 14193 ** extra entries are added to the FTS index, this method uses more space 14194 ** within the database. 14195 ** 14196 ** Method (2) offers a midpoint between (1) and (3). Using this method, 14197 ** a query such as '1s*' will match documents that contain the literal 14198 ** token "1st", but not "first" (assuming the tokenizer is not able to 14199 ** provide synonyms for prefixes). However, a non-prefix query like '1st' 14200 ** will match against "1st" and "first". This method does not require 14201 ** extra disk space, as no extra entries are added to the FTS index. 14202 ** On the other hand, it may require more CPU cycles to run MATCH queries, 14203 ** as separate queries of the FTS index are required for each synonym. 14204 ** 14205 ** When using methods (2) or (3), it is important that the tokenizer only 14206 ** provide synonyms when tokenizing document text (method (3)) or query 14207 ** text (method (2)), not both. Doing so will not cause any errors, but is 14208 ** inefficient. 14209 */ 14210 typedef struct Fts5Tokenizer Fts5Tokenizer; 14211 typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2; 14212 struct fts5_tokenizer_v2 { 14213 int iVersion; /* Currently always 2 */ 14214 14215 int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut); 14216 void (*xDelete)(Fts5Tokenizer*); 14217 int (*xTokenize)(Fts5Tokenizer*, 14218 void *pCtx, 14219 int flags, /* Mask of FTS5_TOKENIZE_* flags */ 14220 const char *pText, int nText, 14221 const char *pLocale, int nLocale, 14222 int (*xToken)( 14223 void *pCtx, /* Copy of 2nd argument to xTokenize() */ 14224 int tflags, /* Mask of FTS5_TOKEN_* flags */ 14225 const char *pToken, /* Pointer to buffer containing token */ 14226 int nToken, /* Size of token in bytes */ 14227 int iStart, /* Byte offset of token within input text */ 14228 int iEnd /* Byte offset of end of token within input text */ 14229 ) 14230 ); 14231 }; 14232 14233 /* 14234 ** New code should use the fts5_tokenizer_v2 type to define tokenizer 14235 ** implementations. The following type is included for legacy applications 14236 ** that still use it. 14237 */ 14238 typedef struct fts5_tokenizer fts5_tokenizer; 14239 struct fts5_tokenizer { 14240 int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut); 14241 void (*xDelete)(Fts5Tokenizer*); 14242 int (*xTokenize)(Fts5Tokenizer*, 14243 void *pCtx, 14244 int flags, /* Mask of FTS5_TOKENIZE_* flags */ 14245 const char *pText, int nText, 14246 int (*xToken)( 14247 void *pCtx, /* Copy of 2nd argument to xTokenize() */ 14248 int tflags, /* Mask of FTS5_TOKEN_* flags */ 14249 const char *pToken, /* Pointer to buffer containing token */ 14250 int nToken, /* Size of token in bytes */ 14251 int iStart, /* Byte offset of token within input text */ 14252 int iEnd /* Byte offset of end of token within input text */ 14253 ) 14254 ); 14255 }; 14256 14257 14258 /* Flags that may be passed as the third argument to xTokenize() */ 14259 #define FTS5_TOKENIZE_QUERY 0x0001 14260 #define FTS5_TOKENIZE_PREFIX 0x0002 14261 #define FTS5_TOKENIZE_DOCUMENT 0x0004 14262 #define FTS5_TOKENIZE_AUX 0x0008 14263 14264 /* Flags that may be passed by the tokenizer implementation back to FTS5 14265 ** as the third argument to the supplied xToken callback. */ 14266 #define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */ 14267 14268 /* 14269 ** END OF CUSTOM TOKENIZERS 14270 *************************************************************************/ 14271 14272 /************************************************************************* 14273 ** FTS5 EXTENSION REGISTRATION API 14274 */ 14275 typedef struct fts5_api fts5_api; 14276 struct fts5_api { 14277 int iVersion; /* Currently always set to 3 */ 14278 14279 /* Create a new tokenizer */ 14280 int (*xCreateTokenizer)( 14281 fts5_api *pApi, 14282 const char *zName, 14283 void *pUserData, 14284 fts5_tokenizer *pTokenizer, 14285 void (*xDestroy)(void*) 14286 ); 14287 14288 /* Find an existing tokenizer */ 14289 int (*xFindTokenizer)( 14290 fts5_api *pApi, 14291 const char *zName, 14292 void **ppUserData, 14293 fts5_tokenizer *pTokenizer 14294 ); 14295 14296 /* Create a new auxiliary function */ 14297 int (*xCreateFunction)( 14298 fts5_api *pApi, 14299 const char *zName, 14300 void *pUserData, 14301 fts5_extension_function xFunction, 14302 void (*xDestroy)(void*) 14303 ); 14304 14305 /* APIs below this point are only available if iVersion>=3 */ 14306 14307 /* Create a new tokenizer */ 14308 int (*xCreateTokenizer_v2)( 14309 fts5_api *pApi, 14310 const char *zName, 14311 void *pUserData, 14312 fts5_tokenizer_v2 *pTokenizer, 14313 void (*xDestroy)(void*) 14314 ); 14315 14316 /* Find an existing tokenizer */ 14317 int (*xFindTokenizer_v2)( 14318 fts5_api *pApi, 14319 const char *zName, 14320 void **ppUserData, 14321 fts5_tokenizer_v2 **ppTokenizer 14322 ); 14323 }; 14324 14325 /* 14326 ** END OF REGISTRATION API 14327 *************************************************************************/ 14328 14329 #ifdef __cplusplus 14330 } /* end of the 'extern "C"' block */ 14331 #endif 14332 14333 #endif /* _FTS5_H */ 14334 14335 /******** End of fts5.h *********/ 14336 #endif /* SQLITE3_H */ 14337 #else // USE_LIBSQLITE3 14338 // If users really want to link against the system sqlite3 we 14339 // need to make this file a noop. 14340 #endif