Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: third_party/sqlite/amalgamation/sqlite3.h

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2001 September 15 2 ** 2001 September 15
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to 100 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
101 ** a string which identifies a particular check-in of SQLite 101 ** a string which identifies a particular check-in of SQLite
102 ** within its configuration management system. ^The SQLITE_SOURCE_ID 102 ** within its configuration management system. ^The SQLITE_SOURCE_ID
103 ** string contains the date and time of the check-in (UTC) and an SHA1 103 ** string contains the date and time of the check-in (UTC) and an SHA1
104 ** hash of the entire source tree. 104 ** hash of the entire source tree.
105 ** 105 **
106 ** See also: [sqlite3_libversion()], 106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()]. 108 ** [sqlite_version()] and [sqlite_source_id()].
109 */ 109 */
110 #define SQLITE_VERSION "3.7.6.3" 110 #define SQLITE_VERSION "3.8.7.4"
111 #define SQLITE_VERSION_NUMBER 3007006 111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2011-05-19 13:26:54 ed1da510a239ea767a01dc332b667 119fa3c908e" 112 #define SQLITE_SOURCE_ID "2014-12-09 01:34:36 f66f7a17b78ba617acde90fc81010 7f34f1a1f2e"
113 113
114 /* 114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers 115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 ** 117 **
118 ** These interfaces provide the same information as the [SQLITE_VERSION], 118 ** These interfaces provide the same information as the [SQLITE_VERSION],
119 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 119 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
120 ** but are associated with the library instead of the header file. ^(Cautious 120 ** but are associated with the library instead of the header file. ^(Cautious
121 ** programmers might include assert() statements in their application to 121 ** programmers might include assert() statements in their application to
122 ** verify that values returned by these interfaces match the macros in 122 ** verify that values returned by these interfaces match the macros in
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 */ 170 */
171 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 171 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName); 172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
173 SQLITE_API const char *sqlite3_compileoption_get(int N); 173 SQLITE_API const char *sqlite3_compileoption_get(int N);
174 #endif 174 #endif
175 175
176 /* 176 /*
177 ** CAPI3REF: Test To See If The Library Is Threadsafe 177 ** CAPI3REF: Test To See If The Library Is Threadsafe
178 ** 178 **
179 ** ^The sqlite3_threadsafe() function returns zero if and only if 179 ** ^The sqlite3_threadsafe() function returns zero if and only if
180 ** SQLite was compiled mutexing code omitted due to the 180 ** SQLite was compiled with mutexing code omitted due to the
181 ** [SQLITE_THREADSAFE] compile-time option being set to 0. 181 ** [SQLITE_THREADSAFE] compile-time option being set to 0.
182 ** 182 **
183 ** SQLite can be compiled with or without mutexes. When 183 ** SQLite can be compiled with or without mutexes. When
184 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 184 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
185 ** are enabled and SQLite is threadsafe. When the 185 ** are enabled and SQLite is threadsafe. When the
186 ** [SQLITE_THREADSAFE] macro is 0, 186 ** [SQLITE_THREADSAFE] macro is 0,
187 ** the mutexes are omitted. Without the mutexes, it is not safe 187 ** the mutexes are omitted. Without the mutexes, it is not safe
188 ** to use SQLite concurrently from more than one thread. 188 ** to use SQLite concurrently from more than one thread.
189 ** 189 **
190 ** Enabling mutexes incurs a measurable performance penalty. 190 ** Enabling mutexes incurs a measurable performance penalty.
(...skipping 21 matching lines...) Expand all
212 SQLITE_API int sqlite3_threadsafe(void); 212 SQLITE_API int sqlite3_threadsafe(void);
213 213
214 /* 214 /*
215 ** CAPI3REF: Database Connection Handle 215 ** CAPI3REF: Database Connection Handle
216 ** KEYWORDS: {database connection} {database connections} 216 ** KEYWORDS: {database connection} {database connections}
217 ** 217 **
218 ** Each open SQLite database is represented by a pointer to an instance of 218 ** Each open SQLite database is represented by a pointer to an instance of
219 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 219 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
220 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and 220 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
221 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] 221 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
222 ** is its destructor. There are many other interfaces (such as 222 ** and [sqlite3_close_v2()] are its destructors. There are many other
223 ** interfaces (such as
223 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and 224 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
224 ** [sqlite3_busy_timeout()] to name but three) that are methods on an 225 ** [sqlite3_busy_timeout()] to name but three) that are methods on an
225 ** sqlite3 object. 226 ** sqlite3 object.
226 */ 227 */
227 typedef struct sqlite3 sqlite3; 228 typedef struct sqlite3 sqlite3;
228 229
229 /* 230 /*
230 ** CAPI3REF: 64-Bit Integer Types 231 ** CAPI3REF: 64-Bit Integer Types
231 ** KEYWORDS: sqlite_int64 sqlite_uint64 232 ** KEYWORDS: sqlite_int64 sqlite_uint64
232 ** 233 **
(...skipping 26 matching lines...) Expand all
259 ** If compiling for a processor that lacks floating point support, 260 ** If compiling for a processor that lacks floating point support,
260 ** substitute integer for floating-point. 261 ** substitute integer for floating-point.
261 */ 262 */
262 #ifdef SQLITE_OMIT_FLOATING_POINT 263 #ifdef SQLITE_OMIT_FLOATING_POINT
263 # define double sqlite3_int64 264 # define double sqlite3_int64
264 #endif 265 #endif
265 266
266 /* 267 /*
267 ** CAPI3REF: Closing A Database Connection 268 ** CAPI3REF: Closing A Database Connection
268 ** 269 **
269 ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object. 270 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
270 ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is 271 ** for the [sqlite3] object.
271 ** successfully destroyed and all associated resources are deallocated. 272 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
273 ** the [sqlite3] object is successfully destroyed and all associated
274 ** resources are deallocated.
272 ** 275 **
273 ** Applications must [sqlite3_finalize | finalize] all [prepared statements] 276 ** ^If the database connection is associated with unfinalized prepared
274 ** and [sqlite3_blob_close | close] all [BLOB handles] associated with 277 ** statements or unfinished sqlite3_backup objects then sqlite3_close()
275 ** the [sqlite3] object prior to attempting to close the object. ^If 278 ** will leave the database connection open and return [SQLITE_BUSY].
276 ** sqlite3_close() is called on a [database connection] that still has 279 ** ^If sqlite3_close_v2() is called with unfinalized prepared statements
277 ** outstanding [prepared statements] or [BLOB handles], then it returns 280 ** and/or unfinished sqlite3_backups, then the database connection becomes
278 ** SQLITE_BUSY. 281 ** an unusable "zombie" which will automatically be deallocated when the
282 ** last prepared statement is finalized or the last sqlite3_backup is
283 ** finished. The sqlite3_close_v2() interface is intended for use with
284 ** host languages that are garbage collected, and where the order in which
285 ** destructors are called is arbitrary.
279 ** 286 **
280 ** ^If [sqlite3_close()] is invoked while a transaction is open, 287 ** Applications should [sqlite3_finalize | finalize] all [prepared statements],
288 ** [sqlite3_blob_close | close] all [BLOB handles], and
289 ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
290 ** with the [sqlite3] object prior to attempting to close the object. ^If
291 ** sqlite3_close_v2() is called on a [database connection] that still has
292 ** outstanding [prepared statements], [BLOB handles], and/or
293 ** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
294 ** of resources is deferred until all [prepared statements], [BLOB handles],
295 ** and [sqlite3_backup] objects are also destroyed.
296 **
297 ** ^If an [sqlite3] object is destroyed while a transaction is open,
281 ** the transaction is automatically rolled back. 298 ** the transaction is automatically rolled back.
282 ** 299 **
283 ** The C parameter to [sqlite3_close(C)] must be either a NULL 300 ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
301 ** must be either a NULL
284 ** pointer or an [sqlite3] object pointer obtained 302 ** pointer or an [sqlite3] object pointer obtained
285 ** from [sqlite3_open()], [sqlite3_open16()], or 303 ** from [sqlite3_open()], [sqlite3_open16()], or
286 ** [sqlite3_open_v2()], and not previously closed. 304 ** [sqlite3_open_v2()], and not previously closed.
287 ** ^Calling sqlite3_close() with a NULL pointer argument is a 305 ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
288 ** harmless no-op. 306 ** argument is a harmless no-op.
289 */ 307 */
290 SQLITE_API int sqlite3_close(sqlite3 *); 308 SQLITE_API int sqlite3_close(sqlite3*);
309 SQLITE_API int sqlite3_close_v2(sqlite3*);
291 310
292 /* 311 /*
293 ** The type for a callback function. 312 ** The type for a callback function.
294 ** This is legacy and deprecated. It is included for historical 313 ** This is legacy and deprecated. It is included for historical
295 ** compatibility and is not documented. 314 ** compatibility and is not documented.
296 */ 315 */
297 typedef int (*sqlite3_callback)(void*,int,char**, char**); 316 typedef int (*sqlite3_callback)(void*,int,char**, char**);
298 317
299 /* 318 /*
300 ** CAPI3REF: One-Step Query Execution Interface 319 ** CAPI3REF: One-Step Query Execution Interface
301 ** 320 **
302 ** The sqlite3_exec() interface is a convenience wrapper around 321 ** The sqlite3_exec() interface is a convenience wrapper around
303 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], 322 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
304 ** that allows an application to run multiple statements of SQL 323 ** that allows an application to run multiple statements of SQL
305 ** without having to use a lot of C code. 324 ** without having to use a lot of C code.
306 ** 325 **
307 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, 326 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
308 ** semicolon-separate SQL statements passed into its 2nd argument, 327 ** semicolon-separate SQL statements passed into its 2nd argument,
309 ** in the context of the [database connection] passed in as its 1st 328 ** in the context of the [database connection] passed in as its 1st
310 ** argument. ^If the callback function of the 3rd argument to 329 ** argument. ^If the callback function of the 3rd argument to
311 ** sqlite3_exec() is not NULL, then it is invoked for each result row 330 ** sqlite3_exec() is not NULL, then it is invoked for each result row
312 ** coming out of the evaluated SQL statements. ^The 4th argument to 331 ** coming out of the evaluated SQL statements. ^The 4th argument to
313 ** to sqlite3_exec() is relayed through to the 1st argument of each 332 ** sqlite3_exec() is relayed through to the 1st argument of each
314 ** callback invocation. ^If the callback pointer to sqlite3_exec() 333 ** callback invocation. ^If the callback pointer to sqlite3_exec()
315 ** is NULL, then no callback is ever invoked and result rows are 334 ** is NULL, then no callback is ever invoked and result rows are
316 ** ignored. 335 ** ignored.
317 ** 336 **
318 ** ^If an error occurs while evaluating the SQL statements passed into 337 ** ^If an error occurs while evaluating the SQL statements passed into
319 ** sqlite3_exec(), then execution of the current statement stops and 338 ** sqlite3_exec(), then execution of the current statement stops and
320 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() 339 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
321 ** is not NULL then any error message is written into memory obtained 340 ** is not NULL then any error message is written into memory obtained
322 ** from [sqlite3_malloc()] and passed back through the 5th parameter. 341 ** from [sqlite3_malloc()] and passed back through the 5th parameter.
323 ** To avoid memory leaks, the application should invoke [sqlite3_free()] 342 ** To avoid memory leaks, the application should invoke [sqlite3_free()]
(...skipping 20 matching lines...) Expand all
344 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer 363 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
345 ** to an empty string, or a pointer that contains only whitespace and/or 364 ** to an empty string, or a pointer that contains only whitespace and/or
346 ** SQL comments, then no SQL statements are evaluated and the database 365 ** SQL comments, then no SQL statements are evaluated and the database
347 ** is not changed. 366 ** is not changed.
348 ** 367 **
349 ** Restrictions: 368 ** Restrictions:
350 ** 369 **
351 ** <ul> 370 ** <ul>
352 ** <li> The application must insure that the 1st parameter to sqlite3_exec() 371 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
353 ** is a valid and open [database connection]. 372 ** is a valid and open [database connection].
354 ** <li> The application must not close [database connection] specified by 373 ** <li> The application must not close the [database connection] specified by
355 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. 374 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
356 ** <li> The application must not modify the SQL statement text passed into 375 ** <li> The application must not modify the SQL statement text passed into
357 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. 376 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
358 ** </ul> 377 ** </ul>
359 */ 378 */
360 SQLITE_API int sqlite3_exec( 379 SQLITE_API int sqlite3_exec(
361 sqlite3*, /* An open database */ 380 sqlite3*, /* An open database */
362 const char *sql, /* SQL to be evaluated */ 381 const char *sql, /* SQL to be evaluated */
363 int (*callback)(void*,int,char**,char**), /* Callback function */ 382 int (*callback)(void*,int,char**,char**), /* Callback function */
364 void *, /* 1st argument to callback */ 383 void *, /* 1st argument to callback */
365 char **errmsg /* Error msg written here */ 384 char **errmsg /* Error msg written here */
366 ); 385 );
367 386
368 /* 387 /*
369 ** CAPI3REF: Result Codes 388 ** CAPI3REF: Result Codes
370 ** KEYWORDS: SQLITE_OK {error code} {error codes} 389 ** KEYWORDS: {result code definitions}
371 ** KEYWORDS: {result code} {result codes}
372 ** 390 **
373 ** Many SQLite functions return an integer result code from the set shown 391 ** Many SQLite functions return an integer result code from the set shown
374 ** here in order to indicates success or failure. 392 ** here in order to indicate success or failure.
375 ** 393 **
376 ** New error codes may be added in future versions of SQLite. 394 ** New error codes may be added in future versions of SQLite.
377 ** 395 **
378 ** See also: [SQLITE_IOERR_READ | extended result codes] 396 ** See also: [extended result code definitions]
379 */ 397 */
380 #define SQLITE_OK 0 /* Successful result */ 398 #define SQLITE_OK 0 /* Successful result */
381 /* beginning-of-error-codes */ 399 /* beginning-of-error-codes */
382 #define SQLITE_ERROR 1 /* SQL error or missing database */ 400 #define SQLITE_ERROR 1 /* SQL error or missing database */
383 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 401 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
384 #define SQLITE_PERM 3 /* Access permission denied */ 402 #define SQLITE_PERM 3 /* Access permission denied */
385 #define SQLITE_ABORT 4 /* Callback routine requested an abort */ 403 #define SQLITE_ABORT 4 /* Callback routine requested an abort */
386 #define SQLITE_BUSY 5 /* The database file is locked */ 404 #define SQLITE_BUSY 5 /* The database file is locked */
387 #define SQLITE_LOCKED 6 /* A table in the database is locked */ 405 #define SQLITE_LOCKED 6 /* A table in the database is locked */
388 #define SQLITE_NOMEM 7 /* A malloc() failed */ 406 #define SQLITE_NOMEM 7 /* A malloc() failed */
389 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 407 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */
390 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 408 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
391 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 409 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
392 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 410 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
393 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ 411 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
394 #define SQLITE_FULL 13 /* Insertion failed because database is full */ 412 #define SQLITE_FULL 13 /* Insertion failed because database is full */
395 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 413 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
396 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 414 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
397 #define SQLITE_EMPTY 16 /* Database is empty */ 415 #define SQLITE_EMPTY 16 /* Database is empty */
398 #define SQLITE_SCHEMA 17 /* The database schema changed */ 416 #define SQLITE_SCHEMA 17 /* The database schema changed */
399 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 417 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
400 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 418 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
401 #define SQLITE_MISMATCH 20 /* Data type mismatch */ 419 #define SQLITE_MISMATCH 20 /* Data type mismatch */
402 #define SQLITE_MISUSE 21 /* Library used incorrectly */ 420 #define SQLITE_MISUSE 21 /* Library used incorrectly */
403 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 421 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
404 #define SQLITE_AUTH 23 /* Authorization denied */ 422 #define SQLITE_AUTH 23 /* Authorization denied */
405 #define SQLITE_FORMAT 24 /* Auxiliary database format error */ 423 #define SQLITE_FORMAT 24 /* Auxiliary database format error */
406 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 424 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
407 #define SQLITE_NOTADB 26 /* File opened that is not a database file */ 425 #define SQLITE_NOTADB 26 /* File opened that is not a database file */
426 #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
427 #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
408 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 428 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
409 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 429 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
410 /* end-of-error-codes */ 430 /* end-of-error-codes */
411 431
412 /* 432 /*
413 ** CAPI3REF: Extended Result Codes 433 ** CAPI3REF: Extended Result Codes
414 ** KEYWORDS: {extended error code} {extended error codes} 434 ** KEYWORDS: {extended result code definitions}
415 ** KEYWORDS: {extended result code} {extended result codes}
416 ** 435 **
417 ** In its default configuration, SQLite API routines return one of 26 integer 436 ** In its default configuration, SQLite API routines return one of 30 integer
418 ** [SQLITE_OK | result codes]. However, experience has shown that many of 437 ** [result codes]. However, experience has shown that many of
419 ** these result codes are too coarse-grained. They do not provide as 438 ** these result codes are too coarse-grained. They do not provide as
420 ** much information about problems as programmers might like. In an effort to 439 ** much information about problems as programmers might like. In an effort to
421 ** address this, newer versions of SQLite (version 3.3.8 and later) include 440 ** address this, newer versions of SQLite (version 3.3.8 and later) include
422 ** support for additional result codes that provide more detailed information 441 ** support for additional result codes that provide more detailed information
423 ** about errors. The extended result codes are enabled or disabled 442 ** about errors. These [extended result codes] are enabled or disabled
424 ** on a per database connection basis using the 443 ** on a per database connection basis using the
425 ** [sqlite3_extended_result_codes()] API. 444 ** [sqlite3_extended_result_codes()] API. Or, the extended code for
426 ** 445 ** the most recent error can be obtained using
427 ** Some of the available extended result codes are listed here. 446 ** [sqlite3_extended_errcode()].
428 ** One may expect the number of extended result codes will be expand
429 ** over time. Software that uses extended result codes should expect
430 ** to see new result codes in future releases of SQLite.
431 **
432 ** The SQLITE_OK result code will never be extended. It will always
433 ** be exactly zero.
434 */ 447 */
435 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 448 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
436 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 449 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
437 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 450 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
438 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 451 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
439 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 452 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
440 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 453 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
441 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 454 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
442 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 455 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
443 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 456 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
444 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 457 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
445 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 458 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
446 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 459 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
447 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 460 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
448 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 461 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
449 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 462 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
450 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 463 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
451 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 464 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
452 #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) 465 #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
453 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 466 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
454 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 467 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
468 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
469 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
470 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
471 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
472 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
473 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
455 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 474 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
456 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 475 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
476 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
457 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 477 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
478 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
479 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
480 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
481 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
482 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
483 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
484 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
485 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
486 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
487 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
488 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
489 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
490 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
491 #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
492 #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
493 #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
494 #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
495 #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
496 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
497 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
498 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
499 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
500 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
458 501
459 /* 502 /*
460 ** CAPI3REF: Flags For File Open Operations 503 ** CAPI3REF: Flags For File Open Operations
461 ** 504 **
462 ** These bit values are intended for use in the 505 ** These bit values are intended for use in the
463 ** 3rd parameter to the [sqlite3_open_v2()] interface and 506 ** 3rd parameter to the [sqlite3_open_v2()] interface and
464 ** in the 4th parameter to the xOpen method of the 507 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
465 ** [sqlite3_vfs] object.
466 */ 508 */
467 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 509 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
468 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 510 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
469 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 511 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
470 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 512 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
471 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 513 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
472 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 514 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
515 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
516 #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
473 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 517 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
474 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 518 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
475 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 519 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
476 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 520 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
477 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 521 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
478 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 522 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
479 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 523 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
480 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 524 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
481 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 525 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
482 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 526 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
483 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 527 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
484 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ 528 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
485 529
486 /* Reserved: 0x00F00000 */ 530 /* Reserved: 0x00F00000 */
487 531
488 /* 532 /*
489 ** CAPI3REF: Device Characteristics 533 ** CAPI3REF: Device Characteristics
490 ** 534 **
491 ** The xDeviceCharacteristics method of the [sqlite3_io_methods] 535 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
492 ** object returns an integer which is a vector of the these 536 ** object returns an integer which is a vector of these
493 ** bit values expressing I/O characteristics of the mass storage 537 ** bit values expressing I/O characteristics of the mass storage
494 ** device that holds the file that the [sqlite3_io_methods] 538 ** device that holds the file that the [sqlite3_io_methods]
495 ** refers to. 539 ** refers to.
496 ** 540 **
497 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 541 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
498 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 542 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
499 ** mean that writes of blocks that are nnn bytes in size and 543 ** mean that writes of blocks that are nnn bytes in size and
500 ** are aligned to an address which is an integer multiple of 544 ** are aligned to an address which is an integer multiple of
501 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 545 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
502 ** that when data is appended to a file, the data is appended 546 ** that when data is appended to a file, the data is appended
503 ** first then the size of the file is extended, never the other 547 ** first then the size of the file is extended, never the other
504 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 548 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
505 ** information is written to disk in the same order as calls 549 ** information is written to disk in the same order as calls
506 ** to xWrite(). 550 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
551 ** after reboot following a crash or power loss, the only bytes in a
552 ** file that were written at the application level might have changed
553 ** and that adjacent bytes, even bytes within the same sector are
554 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
555 ** flag indicate that a file cannot be deleted when open. The
556 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
557 ** read-only media and cannot be changed even by processes with
558 ** elevated privileges.
507 */ 559 */
508 #define SQLITE_IOCAP_ATOMIC 0x00000001 560 #define SQLITE_IOCAP_ATOMIC 0x00000001
509 #define SQLITE_IOCAP_ATOMIC512 0x00000002 561 #define SQLITE_IOCAP_ATOMIC512 0x00000002
510 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 562 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
511 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 563 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
512 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 564 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
513 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 565 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
514 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 566 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
515 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 567 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
516 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 568 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
517 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 569 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
518 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 570 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
519 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 571 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
572 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
573 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
520 574
521 /* 575 /*
522 ** CAPI3REF: File Locking Levels 576 ** CAPI3REF: File Locking Levels
523 ** 577 **
524 ** SQLite uses one of these integer values as the second 578 ** SQLite uses one of these integer values as the second
525 ** argument to calls it makes to the xLock() and xUnlock() methods 579 ** argument to calls it makes to the xLock() and xUnlock() methods
526 ** of an [sqlite3_io_methods] object. 580 ** of an [sqlite3_io_methods] object.
527 */ 581 */
528 #define SQLITE_LOCK_NONE 0 582 #define SQLITE_LOCK_NONE 0
529 #define SQLITE_LOCK_SHARED 1 583 #define SQLITE_LOCK_SHARED 1
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 ** I/O operations on the open file. 627 ** I/O operations on the open file.
574 */ 628 */
575 typedef struct sqlite3_file sqlite3_file; 629 typedef struct sqlite3_file sqlite3_file;
576 struct sqlite3_file { 630 struct sqlite3_file {
577 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 631 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
578 }; 632 };
579 633
580 /* 634 /*
581 ** CAPI3REF: OS Interface File Virtual Methods Object 635 ** CAPI3REF: OS Interface File Virtual Methods Object
582 ** 636 **
583 ** Every file opened by the [sqlite3_vfs] xOpen method populates an 637 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
584 ** [sqlite3_file] object (or, more commonly, a subclass of the 638 ** [sqlite3_file] object (or, more commonly, a subclass of the
585 ** [sqlite3_file] object) with a pointer to an instance of this object. 639 ** [sqlite3_file] object) with a pointer to an instance of this object.
586 ** This object defines the methods used to perform various operations 640 ** This object defines the methods used to perform various operations
587 ** against the open file represented by the [sqlite3_file] object. 641 ** against the open file represented by the [sqlite3_file] object.
588 ** 642 **
589 ** If the xOpen method sets the sqlite3_file.pMethods element 643 ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
590 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 644 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
591 ** may be invoked even if the xOpen reported that it failed. The 645 ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
592 ** only way to prevent a call to xClose following a failed xOpen 646 ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
593 ** is for the xOpen to set the sqlite3_file.pMethods element to NULL. 647 ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
648 ** to NULL.
594 ** 649 **
595 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 650 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
596 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 651 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
597 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 652 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
598 ** flag may be ORed in to indicate that only the data of the file 653 ** flag may be ORed in to indicate that only the data of the file
599 ** and not its inode needs to be synced. 654 ** and not its inode needs to be synced.
600 ** 655 **
601 ** The integer values to xLock() and xUnlock() are one of 656 ** The integer values to xLock() and xUnlock() are one of
602 ** <ul> 657 ** <ul>
603 ** <li> [SQLITE_LOCK_NONE], 658 ** <li> [SQLITE_LOCK_NONE],
(...skipping 11 matching lines...) Expand all
615 ** The xFileControl() method is a generic interface that allows custom 670 ** The xFileControl() method is a generic interface that allows custom
616 ** VFS implementations to directly control an open file using the 671 ** VFS implementations to directly control an open file using the
617 ** [sqlite3_file_control()] interface. The second "op" argument is an 672 ** [sqlite3_file_control()] interface. The second "op" argument is an
618 ** integer opcode. The third argument is a generic pointer intended to 673 ** integer opcode. The third argument is a generic pointer intended to
619 ** point to a structure that may contain arguments or space in which to 674 ** point to a structure that may contain arguments or space in which to
620 ** write return values. Potential uses for xFileControl() might be 675 ** write return values. Potential uses for xFileControl() might be
621 ** functions to enable blocking locks with timeouts, to change the 676 ** functions to enable blocking locks with timeouts, to change the
622 ** locking strategy (for example to use dot-file locks), to inquire 677 ** locking strategy (for example to use dot-file locks), to inquire
623 ** about the status of a lock, or to break stale locks. The SQLite 678 ** about the status of a lock, or to break stale locks. The SQLite
624 ** core reserves all opcodes less than 100 for its own use. 679 ** core reserves all opcodes less than 100 for its own use.
625 ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. 680 ** A [file control opcodes | list of opcodes] less than 100 is available.
626 ** Applications that define a custom xFileControl method should use opcodes 681 ** Applications that define a custom xFileControl method should use opcodes
627 ** greater than 100 to avoid conflicts. VFS implementations should 682 ** greater than 100 to avoid conflicts. VFS implementations should
628 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not 683 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
629 ** recognize. 684 ** recognize.
630 ** 685 **
631 ** The xSectorSize() method returns the sector size of the 686 ** The xSectorSize() method returns the sector size of the
632 ** device that underlies the file. The sector size is the 687 ** device that underlies the file. The sector size is the
633 ** minimum write that can be performed without disturbing 688 ** minimum write that can be performed without disturbing
634 ** other bytes in the file. The xDeviceCharacteristics() 689 ** other bytes in the file. The xDeviceCharacteristics()
635 ** method returns a bit vector describing behaviors of the 690 ** method returns a bit vector describing behaviors of the
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 735 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
681 int (*xFileControl)(sqlite3_file*, int op, void *pArg); 736 int (*xFileControl)(sqlite3_file*, int op, void *pArg);
682 int (*xSectorSize)(sqlite3_file*); 737 int (*xSectorSize)(sqlite3_file*);
683 int (*xDeviceCharacteristics)(sqlite3_file*); 738 int (*xDeviceCharacteristics)(sqlite3_file*);
684 /* Methods above are valid for version 1 */ 739 /* Methods above are valid for version 1 */
685 int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); 740 int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
686 int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); 741 int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
687 void (*xShmBarrier)(sqlite3_file*); 742 void (*xShmBarrier)(sqlite3_file*);
688 int (*xShmUnmap)(sqlite3_file*, int deleteFlag); 743 int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
689 /* Methods above are valid for version 2 */ 744 /* Methods above are valid for version 2 */
745 int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
746 int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
747 /* Methods above are valid for version 3 */
690 /* Additional methods may be added in future releases */ 748 /* Additional methods may be added in future releases */
691 }; 749 };
692 750
693 /* 751 /*
694 ** CAPI3REF: Standard File Control Opcodes 752 ** CAPI3REF: Standard File Control Opcodes
753 ** KEYWORDS: {file control opcodes} {file control opcode}
695 ** 754 **
696 ** These integer constants are opcodes for the xFileControl method 755 ** These integer constants are opcodes for the xFileControl method
697 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 756 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
698 ** interface. 757 ** interface.
699 ** 758 **
700 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 759 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
701 ** opcode causes the xFileControl method to write the current state of 760 ** opcode causes the xFileControl method to write the current state of
702 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 761 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
703 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 762 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
704 ** into an integer that the pArg argument points to. This capability 763 ** into an integer that the pArg argument points to. This capability
705 ** is used during testing and only needs to be supported when SQLITE_TEST 764 ** is used during testing and only needs to be supported when SQLITE_TEST
706 ** is defined. 765 ** is defined.
707 ** 766 ** <ul>
767 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
708 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS 768 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
709 ** layer a hint of how large the database file will grow to be during the 769 ** layer a hint of how large the database file will grow to be during the
710 ** current transaction. This hint is not guaranteed to be accurate but it 770 ** current transaction. This hint is not guaranteed to be accurate but it
711 ** is often close. The underlying VFS might choose to preallocate database 771 ** is often close. The underlying VFS might choose to preallocate database
712 ** file space based on this hint in order to help writes to the database 772 ** file space based on this hint in order to help writes to the database
713 ** file run faster. 773 ** file run faster.
714 ** 774 **
775 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
715 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS 776 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
716 ** extends and truncates the database file in chunks of a size specified 777 ** extends and truncates the database file in chunks of a size specified
717 ** by the user. The fourth argument to [sqlite3_file_control()] should 778 ** by the user. The fourth argument to [sqlite3_file_control()] should
718 ** point to an integer (type int) containing the new chunk-size to use 779 ** point to an integer (type int) containing the new chunk-size to use
719 ** for the nominated database. Allocating database file space in large 780 ** for the nominated database. Allocating database file space in large
720 ** chunks (say 1MB at a time), may reduce file-system fragmentation and 781 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
721 ** improve performance on some systems. 782 ** improve performance on some systems.
722 ** 783 **
784 ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
723 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer 785 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
724 ** to the [sqlite3_file] object associated with a particular database 786 ** to the [sqlite3_file] object associated with a particular database
725 ** connection. See the [sqlite3_file_control()] documentation for 787 ** connection. See the [sqlite3_file_control()] documentation for
726 ** additional information. 788 ** additional information.
727 ** 789 **
728 ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by 790 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
729 ** SQLite and sent to all VFSes in place of a call to the xSync method 791 ** No longer in use.
730 ** when the database connection has [PRAGMA synchronous] set to OFF.)^ 792 **
731 ** Some specialized VFSes need this signal in order to operate correctly 793 ** <li>[[SQLITE_FCNTL_SYNC]]
732 ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 794 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
733 ** VFSes do not need this signal and should silently ignore this opcode. 795 ** sent to the VFS immediately before the xSync method is invoked on a
734 ** Applications should not call [sqlite3_file_control()] with this 796 ** database file descriptor. Or, if the xSync method is not invoked
735 ** opcode as doing so may disrupt the operation of the specialized VFSes 797 ** because the user has configured SQLite with
736 ** that do require it. 798 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
799 ** of the xSync method. In most cases, the pointer argument passed with
800 ** this file-control is NULL. However, if the database file is being synced
801 ** as part of a multi-database commit, the argument points to a nul-terminated
802 ** string containing the transactions master-journal file name. VFSes that
803 ** do not need this signal should silently ignore this opcode. Applications
804 ** should not call [sqlite3_file_control()] with this opcode as doing so may
805 ** disrupt the operation of the specialized VFSes that do require it.
806 **
807 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
808 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
809 ** and sent to the VFS after a transaction has been committed immediately
810 ** but before the database is unlocked. VFSes that do not need this signal
811 ** should silently ignore this opcode. Applications should not call
812 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
813 ** operation of the specialized VFSes that do require it.
814 **
815 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
816 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
817 ** retry counts and intervals for certain disk I/O operations for the
818 ** windows [VFS] in order to provide robustness in the presence of
819 ** anti-virus programs. By default, the windows VFS will retry file read,
820 ** file write, and file delete operations up to 10 times, with a delay
821 ** of 25 milliseconds before the first retry and with the delay increasing
822 ** by an additional 25 milliseconds with each subsequent retry. This
823 ** opcode allows these two values (10 retries and 25 milliseconds of delay)
824 ** to be adjusted. The values are changed for all database connections
825 ** within the same process. The argument is a pointer to an array of two
826 ** integers where the first integer i the new retry count and the second
827 ** integer is the delay. If either integer is negative, then the setting
828 ** is not changed but instead the prior value of that setting is written
829 ** into the array entry, allowing the current retry settings to be
830 ** interrogated. The zDbName parameter is ignored.
831 **
832 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
833 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
834 ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
835 ** write ahead log and shared memory files used for transaction control
836 ** are automatically deleted when the latest connection to the database
837 ** closes. Setting persistent WAL mode causes those files to persist after
838 ** close. Persisting the files is useful when other processes that do not
839 ** have write permission on the directory containing the database file want
840 ** to read the database file, as the WAL and shared memory files must exist
841 ** in order for the database to be readable. The fourth parameter to
842 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
843 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
844 ** WAL mode. If the integer is -1, then it is overwritten with the current
845 ** WAL persistence setting.
846 **
847 ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
848 ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
849 ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
850 ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
851 ** xDeviceCharacteristics methods. The fourth parameter to
852 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
853 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
854 ** mode. If the integer is -1, then it is overwritten with the current
855 ** zero-damage mode setting.
856 **
857 ** <li>[[SQLITE_FCNTL_OVERWRITE]]
858 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
859 ** a write transaction to indicate that, unless it is rolled back for some
860 ** reason, the entire database file will be overwritten by the current
861 ** transaction. This is used by VACUUM operations.
862 **
863 ** <li>[[SQLITE_FCNTL_VFSNAME]]
864 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
865 ** all [VFSes] in the VFS stack. The names are of all VFS shims and the
866 ** final bottom-level VFS are written into memory obtained from
867 ** [sqlite3_malloc()] and the result is stored in the char* variable
868 ** that the fourth parameter of [sqlite3_file_control()] points to.
869 ** The caller is responsible for freeing the memory when done. As with
870 ** all file-control actions, there is no guarantee that this will actually
871 ** do anything. Callers should initialize the char* variable to a NULL
872 ** pointer in case this file-control is not implemented. This file-control
873 ** is intended for diagnostic use only.
874 **
875 ** <li>[[SQLITE_FCNTL_PRAGMA]]
876 ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
877 ** file control is sent to the open [sqlite3_file] object corresponding
878 ** to the database file to which the pragma statement refers. ^The argument
879 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
880 ** pointers to strings (char**) in which the second element of the array
881 ** is the name of the pragma and the third element is the argument to the
882 ** pragma or NULL if the pragma has no argument. ^The handler for an
883 ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
884 ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
885 ** or the equivalent and that string will become the result of the pragma or
886 ** the error message if the pragma fails. ^If the
887 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
888 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
889 ** file control returns [SQLITE_OK], then the parser assumes that the
890 ** VFS has handled the PRAGMA itself and the parser generates a no-op
891 ** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns
892 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
893 ** that the VFS encountered an error while handling the [PRAGMA] and the
894 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
895 ** file control occurs at the beginning of pragma statement analysis and so
896 ** it is able to override built-in [PRAGMA] statements.
897 **
898 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
899 ** ^The [SQLITE_FCNTL_BUSYHANDLER]
900 ** file-control may be invoked by SQLite on the database file handle
901 ** shortly after it is opened in order to provide a custom VFS with access
902 ** to the connections busy-handler callback. The argument is of type (void **)
903 ** - an array of two (void *) values. The first (void *) actually points
904 ** to a function of type (int (*)(void *)). In order to invoke the connections
905 ** busy-handler, this function should be invoked with the second (void *) in
906 ** the array as the only argument. If it returns non-zero, then the operation
907 ** should be retried. If it returns zero, the custom VFS should abandon the
908 ** current operation.
909 **
910 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
911 ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
912 ** to have SQLite generate a
913 ** temporary filename using the same algorithm that is followed to generate
914 ** temporary filenames for TEMP tables and other internal uses. The
915 ** argument should be a char** which will be filled with the filename
916 ** written into memory obtained from [sqlite3_malloc()]. The caller should
917 ** invoke [sqlite3_free()] on the result to avoid a memory leak.
918 **
919 ** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
920 ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
921 ** maximum number of bytes that will be used for memory-mapped I/O.
922 ** The argument is a pointer to a value of type sqlite3_int64 that
923 ** is an advisory maximum number of bytes in the file to memory map. The
924 ** pointer is overwritten with the old value. The limit is not changed if
925 ** the value originally pointed to is negative, and so the current limit
926 ** can be queried by passing in a pointer to a negative number. This
927 ** file-control is used internally to implement [PRAGMA mmap_size].
928 **
929 ** <li>[[SQLITE_FCNTL_TRACE]]
930 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
931 ** to the VFS about what the higher layers of the SQLite stack are doing.
932 ** This file control is used by some VFS activity tracing [shims].
933 ** The argument is a zero-terminated string. Higher layers in the
934 ** SQLite stack may generate instances of this file control if
935 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
936 **
937 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
938 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
939 ** pointer to an integer and it writes a boolean into that integer depending
940 ** on whether or not the file has been renamed, moved, or deleted since it
941 ** was first opened.
942 **
943 ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
944 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
945 ** opcode causes the xFileControl method to swap the file handle with the one
946 ** pointed to by the pArg argument. This capability is used during testing
947 ** and only needs to be supported when SQLITE_TEST is defined.
948 **
949 ** </ul>
737 */ 950 */
738 #define SQLITE_FCNTL_LOCKSTATE 1 951 #define SQLITE_FCNTL_LOCKSTATE 1
739 #define SQLITE_GET_LOCKPROXYFILE 2 952 #define SQLITE_GET_LOCKPROXYFILE 2
740 #define SQLITE_SET_LOCKPROXYFILE 3 953 #define SQLITE_SET_LOCKPROXYFILE 3
741 #define SQLITE_LAST_ERRNO 4 954 #define SQLITE_LAST_ERRNO 4
742 #define SQLITE_FCNTL_SIZE_HINT 5 955 #define SQLITE_FCNTL_SIZE_HINT 5
743 #define SQLITE_FCNTL_CHUNK_SIZE 6 956 #define SQLITE_FCNTL_CHUNK_SIZE 6
744 #define SQLITE_FCNTL_FILE_POINTER 7 957 #define SQLITE_FCNTL_FILE_POINTER 7
745 #define SQLITE_FCNTL_SYNC_OMITTED 8 958 #define SQLITE_FCNTL_SYNC_OMITTED 8
746 959 #define SQLITE_FCNTL_WIN32_AV_RETRY 9
960 #define SQLITE_FCNTL_PERSIST_WAL 10
961 #define SQLITE_FCNTL_OVERWRITE 11
962 #define SQLITE_FCNTL_VFSNAME 12
963 #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
964 #define SQLITE_FCNTL_PRAGMA 14
965 #define SQLITE_FCNTL_BUSYHANDLER 15
966 #define SQLITE_FCNTL_TEMPFILENAME 16
967 #define SQLITE_FCNTL_MMAP_SIZE 18
968 #define SQLITE_FCNTL_TRACE 19
969 #define SQLITE_FCNTL_HAS_MOVED 20
970 #define SQLITE_FCNTL_SYNC 21
971 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
972 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
747 973
748 /* 974 /*
749 ** CAPI3REF: Mutex Handle 975 ** CAPI3REF: Mutex Handle
750 ** 976 **
751 ** The mutex module within SQLite defines [sqlite3_mutex] to be an 977 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
752 ** abstract type for a mutex object. The SQLite core never looks 978 ** abstract type for a mutex object. The SQLite core never looks
753 ** at the internal representation of an [sqlite3_mutex]. It only 979 ** at the internal representation of an [sqlite3_mutex]. It only
754 ** deals with pointers to the [sqlite3_mutex] object. 980 ** deals with pointers to the [sqlite3_mutex] object.
755 ** 981 **
756 ** Mutexes are created using [sqlite3_mutex_alloc()]. 982 ** Mutexes are created using [sqlite3_mutex_alloc()].
757 */ 983 */
758 typedef struct sqlite3_mutex sqlite3_mutex; 984 typedef struct sqlite3_mutex sqlite3_mutex;
759 985
760 /* 986 /*
761 ** CAPI3REF: OS Interface Object 987 ** CAPI3REF: OS Interface Object
762 ** 988 **
763 ** An instance of the sqlite3_vfs object defines the interface between 989 ** An instance of the sqlite3_vfs object defines the interface between
764 ** the SQLite core and the underlying operating system. The "vfs" 990 ** the SQLite core and the underlying operating system. The "vfs"
765 ** in the name of the object stands for "virtual file system". 991 ** in the name of the object stands for "virtual file system". See
992 ** the [VFS | VFS documentation] for further information.
766 ** 993 **
767 ** The value of the iVersion field is initially 1 but may be larger in 994 ** The value of the iVersion field is initially 1 but may be larger in
768 ** future versions of SQLite. Additional fields may be appended to this 995 ** future versions of SQLite. Additional fields may be appended to this
769 ** object when the iVersion value is increased. Note that the structure 996 ** object when the iVersion value is increased. Note that the structure
770 ** of the sqlite3_vfs object changes in the transaction between 997 ** of the sqlite3_vfs object changes in the transaction between
771 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not 998 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
772 ** modified. 999 ** modified.
773 ** 1000 **
774 ** The szOsFile field is the size of the subclassed [sqlite3_file] 1001 ** The szOsFile field is the size of the subclassed [sqlite3_file]
775 ** structure used by this VFS. mxPathname is the maximum length of 1002 ** structure used by this VFS. mxPathname is the maximum length of
776 ** a pathname in this VFS. 1003 ** a pathname in this VFS.
777 ** 1004 **
778 ** Registered sqlite3_vfs objects are kept on a linked list formed by 1005 ** Registered sqlite3_vfs objects are kept on a linked list formed by
779 ** the pNext pointer. The [sqlite3_vfs_register()] 1006 ** the pNext pointer. The [sqlite3_vfs_register()]
780 ** and [sqlite3_vfs_unregister()] interfaces manage this list 1007 ** and [sqlite3_vfs_unregister()] interfaces manage this list
781 ** in a thread-safe way. The [sqlite3_vfs_find()] interface 1008 ** in a thread-safe way. The [sqlite3_vfs_find()] interface
782 ** searches the list. Neither the application code nor the VFS 1009 ** searches the list. Neither the application code nor the VFS
783 ** implementation should use the pNext pointer. 1010 ** implementation should use the pNext pointer.
784 ** 1011 **
785 ** The pNext field is the only field in the sqlite3_vfs 1012 ** The pNext field is the only field in the sqlite3_vfs
786 ** structure that SQLite will ever modify. SQLite will only access 1013 ** structure that SQLite will ever modify. SQLite will only access
787 ** or modify this field while holding a particular static mutex. 1014 ** or modify this field while holding a particular static mutex.
788 ** The application should never modify anything within the sqlite3_vfs 1015 ** The application should never modify anything within the sqlite3_vfs
789 ** object once the object has been registered. 1016 ** object once the object has been registered.
790 ** 1017 **
791 ** The zName field holds the name of the VFS module. The name must 1018 ** The zName field holds the name of the VFS module. The name must
792 ** be unique across all VFS modules. 1019 ** be unique across all VFS modules.
793 ** 1020 **
1021 ** [[sqlite3_vfs.xOpen]]
794 ** ^SQLite guarantees that the zFilename parameter to xOpen 1022 ** ^SQLite guarantees that the zFilename parameter to xOpen
795 ** is either a NULL pointer or string obtained 1023 ** is either a NULL pointer or string obtained
796 ** from xFullPathname() with an optional suffix added. 1024 ** from xFullPathname() with an optional suffix added.
797 ** ^If a suffix is added to the zFilename parameter, it will 1025 ** ^If a suffix is added to the zFilename parameter, it will
798 ** consist of a single "-" character followed by no more than 1026 ** consist of a single "-" character followed by no more than
799 ** 10 alphanumeric and/or "-" characters. 1027 ** 11 alphanumeric and/or "-" characters.
800 ** ^SQLite further guarantees that 1028 ** ^SQLite further guarantees that
801 ** the string will be valid and unchanged until xClose() is 1029 ** the string will be valid and unchanged until xClose() is
802 ** called. Because of the previous sentence, 1030 ** called. Because of the previous sentence,
803 ** the [sqlite3_file] can safely store a pointer to the 1031 ** the [sqlite3_file] can safely store a pointer to the
804 ** filename if it needs to remember the filename for some reason. 1032 ** filename if it needs to remember the filename for some reason.
805 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen 1033 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
806 ** must invent its own temporary name for the file. ^Whenever the 1034 ** must invent its own temporary name for the file. ^Whenever the
807 ** xFilename parameter is NULL it will also be the case that the 1035 ** xFilename parameter is NULL it will also be the case that the
808 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 1036 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
809 ** 1037 **
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 ** ^At least szOsFile bytes of memory are allocated by SQLite 1089 ** ^At least szOsFile bytes of memory are allocated by SQLite
862 ** to hold the [sqlite3_file] structure passed as the third 1090 ** to hold the [sqlite3_file] structure passed as the third
863 ** argument to xOpen. The xOpen method does not have to 1091 ** argument to xOpen. The xOpen method does not have to
864 ** allocate the structure; it should just fill it in. Note that 1092 ** allocate the structure; it should just fill it in. Note that
865 ** the xOpen method must set the sqlite3_file.pMethods to either 1093 ** the xOpen method must set the sqlite3_file.pMethods to either
866 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 1094 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
867 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 1095 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
868 ** element will be valid after xOpen returns regardless of the success 1096 ** element will be valid after xOpen returns regardless of the success
869 ** or failure of the xOpen call. 1097 ** or failure of the xOpen call.
870 ** 1098 **
1099 ** [[sqlite3_vfs.xAccess]]
871 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 1100 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
872 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 1101 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
873 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 1102 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
874 ** to test whether a file is at least readable. The file can be a 1103 ** to test whether a file is at least readable. The file can be a
875 ** directory. 1104 ** directory.
876 ** 1105 **
877 ** ^SQLite will always allocate at least mxPathname+1 bytes for the 1106 ** ^SQLite will always allocate at least mxPathname+1 bytes for the
878 ** output buffer xFullPathname. The exact size of the output buffer 1107 ** output buffer xFullPathname. The exact size of the output buffer
879 ** is also passed as a parameter to both methods. If the output buffer 1108 ** is also passed as a parameter to both methods. If the output buffer
880 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 1109 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
881 ** handled as a fatal error by SQLite, vfs implementations should endeavor 1110 ** handled as a fatal error by SQLite, vfs implementations should endeavor
882 ** to prevent this by setting mxPathname to a sufficiently large value. 1111 ** to prevent this by setting mxPathname to a sufficiently large value.
883 ** 1112 **
884 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() 1113 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
885 ** interfaces are not strictly a part of the filesystem, but they are 1114 ** interfaces are not strictly a part of the filesystem, but they are
886 ** included in the VFS structure for completeness. 1115 ** included in the VFS structure for completeness.
887 ** The xRandomness() function attempts to return nBytes bytes 1116 ** The xRandomness() function attempts to return nBytes bytes
888 ** of good-quality randomness into zOut. The return value is 1117 ** of good-quality randomness into zOut. The return value is
889 ** the actual number of bytes of randomness obtained. 1118 ** the actual number of bytes of randomness obtained.
890 ** The xSleep() method causes the calling thread to sleep for at 1119 ** The xSleep() method causes the calling thread to sleep for at
891 ** least the number of microseconds given. ^The xCurrentTime() 1120 ** least the number of microseconds given. ^The xCurrentTime()
892 ** method returns a Julian Day Number for the current date and time as 1121 ** method returns a Julian Day Number for the current date and time as
893 ** a floating point value. 1122 ** a floating point value.
894 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian 1123 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
895 ** Day Number multipled by 86400000 (the number of milliseconds in 1124 ** Day Number multiplied by 86400000 (the number of milliseconds in
896 ** a 24-hour day). 1125 ** a 24-hour day).
897 ** ^SQLite will use the xCurrentTimeInt64() method to get the current 1126 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
898 ** date and time if that method is available (if iVersion is 2 or 1127 ** date and time if that method is available (if iVersion is 2 or
899 ** greater and the function pointer is not NULL) and will fall back 1128 ** greater and the function pointer is not NULL) and will fall back
900 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. 1129 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
901 ** 1130 **
902 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces 1131 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
903 ** are not used by the SQLite core. These optional interfaces are provided 1132 ** are not used by the SQLite core. These optional interfaces are provided
904 ** by some VFSes to facilitate testing of the VFS code. By overriding 1133 ** by some VFSes to facilitate testing of the VFS code. By overriding
905 ** system calls with functions under its control, a test program can 1134 ** system calls with functions under its control, a test program can
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 ** must insure that no other SQLite interfaces are invoked by other 1336 ** must insure that no other SQLite interfaces are invoked by other
1108 ** threads while sqlite3_config() is running. Furthermore, sqlite3_config() 1337 ** threads while sqlite3_config() is running. Furthermore, sqlite3_config()
1109 ** may only be invoked prior to library initialization using 1338 ** may only be invoked prior to library initialization using
1110 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 1339 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
1111 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 1340 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
1112 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. 1341 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1113 ** Note, however, that ^sqlite3_config() can be called as part of the 1342 ** Note, however, that ^sqlite3_config() can be called as part of the
1114 ** implementation of an application-defined [sqlite3_os_init()]. 1343 ** implementation of an application-defined [sqlite3_os_init()].
1115 ** 1344 **
1116 ** The first argument to sqlite3_config() is an integer 1345 ** The first argument to sqlite3_config() is an integer
1117 ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines 1346 ** [configuration option] that determines
1118 ** what property of SQLite is to be configured. Subsequent arguments 1347 ** what property of SQLite is to be configured. Subsequent arguments
1119 ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] 1348 ** vary depending on the [configuration option]
1120 ** in the first argument. 1349 ** in the first argument.
1121 ** 1350 **
1122 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 1351 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1123 ** ^If the option is unknown or SQLite is unable to set the option 1352 ** ^If the option is unknown or SQLite is unable to set the option
1124 ** then this routine returns a non-zero [error code]. 1353 ** then this routine returns a non-zero [error code].
1125 */ 1354 */
1126 SQLITE_API int sqlite3_config(int, ...); 1355 SQLITE_API int sqlite3_config(int, ...);
1127 1356
1128 /* 1357 /*
1129 ** CAPI3REF: Configure database connections 1358 ** CAPI3REF: Configure database connections
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 ** 1390 **
1162 ** Note that SQLite comes with several [built-in memory allocators] 1391 ** Note that SQLite comes with several [built-in memory allocators]
1163 ** that are perfectly adequate for the overwhelming majority of applications 1392 ** that are perfectly adequate for the overwhelming majority of applications
1164 ** and that this object is only useful to a tiny minority of applications 1393 ** and that this object is only useful to a tiny minority of applications
1165 ** with specialized memory allocation requirements. This object is 1394 ** with specialized memory allocation requirements. This object is
1166 ** also used during testing of SQLite in order to specify an alternative 1395 ** also used during testing of SQLite in order to specify an alternative
1167 ** memory allocator that simulates memory out-of-memory conditions in 1396 ** memory allocator that simulates memory out-of-memory conditions in
1168 ** order to verify that SQLite recovers gracefully from such 1397 ** order to verify that SQLite recovers gracefully from such
1169 ** conditions. 1398 ** conditions.
1170 ** 1399 **
1171 ** The xMalloc and xFree methods must work like the 1400 ** The xMalloc, xRealloc, and xFree methods must work like the
1172 ** malloc() and free() functions from the standard C library. 1401 ** malloc(), realloc() and free() functions from the standard C library.
1173 ** The xRealloc method must work like realloc() from the standard C library 1402 ** ^SQLite guarantees that the second argument to
1174 ** with the exception that if the second argument to xRealloc is zero,
1175 ** xRealloc must be a no-op - it must not perform any allocation or
1176 ** deallocation. ^SQLite guarantees that the second argument to
1177 ** xRealloc is always a value returned by a prior call to xRoundup. 1403 ** xRealloc is always a value returned by a prior call to xRoundup.
1178 ** And so in cases where xRoundup always returns a positive number,
1179 ** xRealloc can perform exactly as the standard library realloc() and
1180 ** still be in compliance with this specification.
1181 ** 1404 **
1182 ** xSize should return the allocated size of a memory allocation 1405 ** xSize should return the allocated size of a memory allocation
1183 ** previously obtained from xMalloc or xRealloc. The allocated size 1406 ** previously obtained from xMalloc or xRealloc. The allocated size
1184 ** is always at least as big as the requested size but may be larger. 1407 ** is always at least as big as the requested size but may be larger.
1185 ** 1408 **
1186 ** The xRoundup method returns what would be the allocated size of 1409 ** The xRoundup method returns what would be the allocated size of
1187 ** a memory allocation given a particular requested size. Most memory 1410 ** a memory allocation given a particular requested size. Most memory
1188 ** allocators round up memory allocations at least to the next multiple 1411 ** allocators round up memory allocations at least to the next multiple
1189 ** of 8. Some allocators round up to a larger multiple or to a power of 2. 1412 ** of 8. Some allocators round up to a larger multiple or to a power of 2.
1190 ** Every memory allocation request coming in through [sqlite3_malloc()] 1413 ** Every memory allocation request coming in through [sqlite3_malloc()]
1191 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 1414 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1192 ** that causes the corresponding memory allocation to fail. 1415 ** that causes the corresponding memory allocation to fail.
1193 ** 1416 **
1194 ** The xInit method initializes the memory allocator. (For example, 1417 ** The xInit method initializes the memory allocator. For example,
1195 ** it might allocate any require mutexes or initialize internal data 1418 ** it might allocate any require mutexes or initialize internal data
1196 ** structures. The xShutdown method is invoked (indirectly) by 1419 ** structures. The xShutdown method is invoked (indirectly) by
1197 ** [sqlite3_shutdown()] and should deallocate any resources acquired 1420 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1198 ** by xInit. The pAppData pointer is used as the only parameter to 1421 ** by xInit. The pAppData pointer is used as the only parameter to
1199 ** xInit and xShutdown. 1422 ** xInit and xShutdown.
1200 ** 1423 **
1201 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes 1424 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
1202 ** the xInit method, so the xInit method need not be threadsafe. The 1425 ** the xInit method, so the xInit method need not be threadsafe. The
1203 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 1426 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
1204 ** not need to be threadsafe either. For all other methods, SQLite 1427 ** not need to be threadsafe either. For all other methods, SQLite
(...skipping 14 matching lines...) Expand all
1219 void *(*xRealloc)(void*,int); /* Resize an allocation */ 1442 void *(*xRealloc)(void*,int); /* Resize an allocation */
1220 int (*xSize)(void*); /* Return the size of an allocation */ 1443 int (*xSize)(void*); /* Return the size of an allocation */
1221 int (*xRoundup)(int); /* Round up request size to allocation size */ 1444 int (*xRoundup)(int); /* Round up request size to allocation size */
1222 int (*xInit)(void*); /* Initialize the memory allocator */ 1445 int (*xInit)(void*); /* Initialize the memory allocator */
1223 void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 1446 void (*xShutdown)(void*); /* Deinitialize the memory allocator */
1224 void *pAppData; /* Argument to xInit() and xShutdown() */ 1447 void *pAppData; /* Argument to xInit() and xShutdown() */
1225 }; 1448 };
1226 1449
1227 /* 1450 /*
1228 ** CAPI3REF: Configuration Options 1451 ** CAPI3REF: Configuration Options
1452 ** KEYWORDS: {configuration option}
1229 ** 1453 **
1230 ** These constants are the available integer configuration options that 1454 ** These constants are the available integer configuration options that
1231 ** can be passed as the first argument to the [sqlite3_config()] interface. 1455 ** can be passed as the first argument to the [sqlite3_config()] interface.
1232 ** 1456 **
1233 ** New configuration options may be added in future releases of SQLite. 1457 ** New configuration options may be added in future releases of SQLite.
1234 ** Existing configuration options might be discontinued. Applications 1458 ** Existing configuration options might be discontinued. Applications
1235 ** should check the return code from [sqlite3_config()] to make sure that 1459 ** should check the return code from [sqlite3_config()] to make sure that
1236 ** the call worked. The [sqlite3_config()] interface will return a 1460 ** the call worked. The [sqlite3_config()] interface will return a
1237 ** non-zero [error code] if a discontinued or unsupported configuration option 1461 ** non-zero [error code] if a discontinued or unsupported configuration option
1238 ** is invoked. 1462 ** is invoked.
1239 ** 1463 **
1240 ** <dl> 1464 ** <dl>
1241 ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 1465 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1242 ** <dd>There are no arguments to this option. ^This option sets the 1466 ** <dd>There are no arguments to this option. ^This option sets the
1243 ** [threading mode] to Single-thread. In other words, it disables 1467 ** [threading mode] to Single-thread. In other words, it disables
1244 ** all mutexing and puts SQLite into a mode where it can only be used 1468 ** all mutexing and puts SQLite into a mode where it can only be used
1245 ** by a single thread. ^If SQLite is compiled with 1469 ** by a single thread. ^If SQLite is compiled with
1246 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1470 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1247 ** it is not possible to change the [threading mode] from its default 1471 ** it is not possible to change the [threading mode] from its default
1248 ** value of Single-thread and so [sqlite3_config()] will return 1472 ** value of Single-thread and so [sqlite3_config()] will return
1249 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 1473 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1250 ** configuration option.</dd> 1474 ** configuration option.</dd>
1251 ** 1475 **
1252 ** <dt>SQLITE_CONFIG_MULTITHREAD</dt> 1476 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1253 ** <dd>There are no arguments to this option. ^This option sets the 1477 ** <dd>There are no arguments to this option. ^This option sets the
1254 ** [threading mode] to Multi-thread. In other words, it disables 1478 ** [threading mode] to Multi-thread. In other words, it disables
1255 ** mutexing on [database connection] and [prepared statement] objects. 1479 ** mutexing on [database connection] and [prepared statement] objects.
1256 ** The application is responsible for serializing access to 1480 ** The application is responsible for serializing access to
1257 ** [database connections] and [prepared statements]. But other mutexes 1481 ** [database connections] and [prepared statements]. But other mutexes
1258 ** are enabled so that SQLite will be safe to use in a multi-threaded 1482 ** are enabled so that SQLite will be safe to use in a multi-threaded
1259 ** environment as long as no two threads attempt to use the same 1483 ** environment as long as no two threads attempt to use the same
1260 ** [database connection] at the same time. ^If SQLite is compiled with 1484 ** [database connection] at the same time. ^If SQLite is compiled with
1261 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1485 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1262 ** it is not possible to set the Multi-thread [threading mode] and 1486 ** it is not possible to set the Multi-thread [threading mode] and
1263 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1487 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1264 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 1488 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1265 ** 1489 **
1266 ** <dt>SQLITE_CONFIG_SERIALIZED</dt> 1490 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1267 ** <dd>There are no arguments to this option. ^This option sets the 1491 ** <dd>There are no arguments to this option. ^This option sets the
1268 ** [threading mode] to Serialized. In other words, this option enables 1492 ** [threading mode] to Serialized. In other words, this option enables
1269 ** all mutexes including the recursive 1493 ** all mutexes including the recursive
1270 ** mutexes on [database connection] and [prepared statement] objects. 1494 ** mutexes on [database connection] and [prepared statement] objects.
1271 ** In this mode (which is the default when SQLite is compiled with 1495 ** In this mode (which is the default when SQLite is compiled with
1272 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 1496 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
1273 ** to [database connections] and [prepared statements] so that the 1497 ** to [database connections] and [prepared statements] so that the
1274 ** application is free to use the same [database connection] or the 1498 ** application is free to use the same [database connection] or the
1275 ** same [prepared statement] in different threads at the same time. 1499 ** same [prepared statement] in different threads at the same time.
1276 ** ^If SQLite is compiled with 1500 ** ^If SQLite is compiled with
1277 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1501 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1278 ** it is not possible to set the Serialized [threading mode] and 1502 ** it is not possible to set the Serialized [threading mode] and
1279 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 1503 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1280 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 1504 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1281 ** 1505 **
1282 ** <dt>SQLITE_CONFIG_MALLOC</dt> 1506 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1283 ** <dd> ^(This option takes a single argument which is a pointer to an 1507 ** <dd> ^(This option takes a single argument which is a pointer to an
1284 ** instance of the [sqlite3_mem_methods] structure. The argument specifies 1508 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
1285 ** alternative low-level memory allocation routines to be used in place of 1509 ** alternative low-level memory allocation routines to be used in place of
1286 ** the memory allocation routines built into SQLite.)^ ^SQLite makes 1510 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1287 ** its own private copy of the content of the [sqlite3_mem_methods] structure 1511 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1288 ** before the [sqlite3_config()] call returns.</dd> 1512 ** before the [sqlite3_config()] call returns.</dd>
1289 ** 1513 **
1290 ** <dt>SQLITE_CONFIG_GETMALLOC</dt> 1514 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1291 ** <dd> ^(This option takes a single argument which is a pointer to an 1515 ** <dd> ^(This option takes a single argument which is a pointer to an
1292 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] 1516 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1293 ** structure is filled with the currently defined memory allocation routines.)^ 1517 ** structure is filled with the currently defined memory allocation routines.)^
1294 ** This option can be used to overload the default memory allocation 1518 ** This option can be used to overload the default memory allocation
1295 ** routines with a wrapper that simulations memory allocation failure or 1519 ** routines with a wrapper that simulations memory allocation failure or
1296 ** tracks memory usage, for example. </dd> 1520 ** tracks memory usage, for example. </dd>
1297 ** 1521 **
1298 ** <dt>SQLITE_CONFIG_MEMSTATUS</dt> 1522 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1299 ** <dd> ^This option takes single argument of type int, interpreted as a 1523 ** <dd> ^This option takes single argument of type int, interpreted as a
1300 ** boolean, which enables or disables the collection of memory allocation 1524 ** boolean, which enables or disables the collection of memory allocation
1301 ** statistics. ^(When memory allocation statistics are disabled, the 1525 ** statistics. ^(When memory allocation statistics are disabled, the
1302 ** following SQLite interfaces become non-operational: 1526 ** following SQLite interfaces become non-operational:
1303 ** <ul> 1527 ** <ul>
1304 ** <li> [sqlite3_memory_used()] 1528 ** <li> [sqlite3_memory_used()]
1305 ** <li> [sqlite3_memory_highwater()] 1529 ** <li> [sqlite3_memory_highwater()]
1306 ** <li> [sqlite3_soft_heap_limit64()] 1530 ** <li> [sqlite3_soft_heap_limit64()]
1307 ** <li> [sqlite3_status()] 1531 ** <li> [sqlite3_status()]
1308 ** </ul>)^ 1532 ** </ul>)^
1309 ** ^Memory allocation statistics are enabled by default unless SQLite is 1533 ** ^Memory allocation statistics are enabled by default unless SQLite is
1310 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 1534 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1311 ** allocation statistics are disabled by default. 1535 ** allocation statistics are disabled by default.
1312 ** </dd> 1536 ** </dd>
1313 ** 1537 **
1314 ** <dt>SQLITE_CONFIG_SCRATCH</dt> 1538 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1315 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 1539 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1316 ** scratch memory. There are three arguments: A pointer an 8-byte 1540 ** scratch memory. There are three arguments: A pointer an 8-byte
1317 ** aligned memory buffer from which the scratch allocations will be 1541 ** aligned memory buffer from which the scratch allocations will be
1318 ** drawn, the size of each scratch allocation (sz), 1542 ** drawn, the size of each scratch allocation (sz),
1319 ** and the maximum number of scratch allocations (N). The sz 1543 ** and the maximum number of scratch allocations (N). The sz
1320 ** argument must be a multiple of 16. 1544 ** argument must be a multiple of 16.
1321 ** The first argument must be a pointer to an 8-byte aligned buffer 1545 ** The first argument must be a pointer to an 8-byte aligned buffer
1322 ** of at least sz*N bytes of memory. 1546 ** of at least sz*N bytes of memory.
1323 ** ^SQLite will use no more than two scratch buffers per thread. So 1547 ** ^SQLite will use no more than two scratch buffers per thread. So
1324 ** N should be set to twice the expected maximum number of threads. 1548 ** N should be set to twice the expected maximum number of threads.
1325 ** ^SQLite will never require a scratch buffer that is more than 6 1549 ** ^SQLite will never require a scratch buffer that is more than 6
1326 ** times the database page size. ^If SQLite needs needs additional 1550 ** times the database page size. ^If SQLite needs needs additional
1327 ** scratch memory beyond what is provided by this configuration option, then 1551 ** scratch memory beyond what is provided by this configuration option, then
1328 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 1552 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1329 ** 1553 **
1330 ** <dt>SQLITE_CONFIG_PAGECACHE</dt> 1554 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1331 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 1555 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1332 ** the database page cache with the default page cache implemenation. 1556 ** the database page cache with the default page cache implementation.
1333 ** This configuration should not be used if an application-define page 1557 ** This configuration should not be used if an application-define page
1334 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. 1558 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1335 ** There are three arguments to this option: A pointer to 8-byte aligned 1559 ** There are three arguments to this option: A pointer to 8-byte aligned
1336 ** memory, the size of each page buffer (sz), and the number of pages (N). 1560 ** memory, the size of each page buffer (sz), and the number of pages (N).
1337 ** The sz argument should be the size of the largest database page 1561 ** The sz argument should be the size of the largest database page
1338 ** (a power of two between 512 and 32768) plus a little extra for each 1562 ** (a power of two between 512 and 32768) plus a little extra for each
1339 ** page header. ^The page header size is 20 to 40 bytes depending on 1563 ** page header. ^The page header size is 20 to 40 bytes depending on
1340 ** the host architecture. ^It is harmless, apart from the wasted memory, 1564 ** the host architecture. ^It is harmless, apart from the wasted memory,
1341 ** to make sz a little too large. The first 1565 ** to make sz a little too large. The first
1342 ** argument should point to an allocation of at least sz*N bytes of memory. 1566 ** argument should point to an allocation of at least sz*N bytes of memory.
1343 ** ^SQLite will use the memory provided by the first argument to satisfy its 1567 ** ^SQLite will use the memory provided by the first argument to satisfy its
1344 ** memory needs for the first N pages that it adds to cache. ^If additional 1568 ** memory needs for the first N pages that it adds to cache. ^If additional
1345 ** page cache memory is needed beyond what is provided by this option, then 1569 ** page cache memory is needed beyond what is provided by this option, then
1346 ** SQLite goes to [sqlite3_malloc()] for the additional storage space. 1570 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1347 ** The pointer in the first argument must 1571 ** The pointer in the first argument must
1348 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite 1572 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1349 ** will be undefined.</dd> 1573 ** will be undefined.</dd>
1350 ** 1574 **
1351 ** <dt>SQLITE_CONFIG_HEAP</dt> 1575 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1352 ** <dd> ^This option specifies a static memory buffer that SQLite will use 1576 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1353 ** for all of its dynamic memory allocation needs beyond those provided 1577 ** for all of its dynamic memory allocation needs beyond those provided
1354 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. 1578 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1355 ** There are three arguments: An 8-byte aligned pointer to the memory, 1579 ** There are three arguments: An 8-byte aligned pointer to the memory,
1356 ** the number of bytes in the memory buffer, and the minimum allocation size. 1580 ** the number of bytes in the memory buffer, and the minimum allocation size.
1357 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 1581 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1358 ** to using its default memory allocator (the system malloc() implementation), 1582 ** to using its default memory allocator (the system malloc() implementation),
1359 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 1583 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1360 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or 1584 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1361 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory 1585 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1362 ** allocator is engaged to handle all of SQLites memory allocation needs. 1586 ** allocator is engaged to handle all of SQLites memory allocation needs.
1363 ** The first pointer (the memory pointer) must be aligned to an 8-byte 1587 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1364 ** boundary or subsequent behavior of SQLite will be undefined. 1588 ** boundary or subsequent behavior of SQLite will be undefined.
1365 ** The minimum allocation size is capped at 2^12. Reasonable values 1589 ** The minimum allocation size is capped at 2**12. Reasonable values
1366 ** for the minimum allocation size are 2^5 through 2^8.</dd> 1590 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1367 ** 1591 **
1368 ** <dt>SQLITE_CONFIG_MUTEX</dt> 1592 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1369 ** <dd> ^(This option takes a single argument which is a pointer to an 1593 ** <dd> ^(This option takes a single argument which is a pointer to an
1370 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies 1594 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1371 ** alternative low-level mutex routines to be used in place 1595 ** alternative low-level mutex routines to be used in place
1372 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the 1596 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1373 ** content of the [sqlite3_mutex_methods] structure before the call to 1597 ** content of the [sqlite3_mutex_methods] structure before the call to
1374 ** [sqlite3_config()] returns. ^If SQLite is compiled with 1598 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1375 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1599 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1376 ** the entire mutexing subsystem is omitted from the build and hence calls to 1600 ** the entire mutexing subsystem is omitted from the build and hence calls to
1377 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 1601 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1378 ** return [SQLITE_ERROR].</dd> 1602 ** return [SQLITE_ERROR].</dd>
1379 ** 1603 **
1380 ** <dt>SQLITE_CONFIG_GETMUTEX</dt> 1604 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1381 ** <dd> ^(This option takes a single argument which is a pointer to an 1605 ** <dd> ^(This option takes a single argument which is a pointer to an
1382 ** instance of the [sqlite3_mutex_methods] structure. The 1606 ** instance of the [sqlite3_mutex_methods] structure. The
1383 ** [sqlite3_mutex_methods] 1607 ** [sqlite3_mutex_methods]
1384 ** structure is filled with the currently defined mutex routines.)^ 1608 ** structure is filled with the currently defined mutex routines.)^
1385 ** This option can be used to overload the default mutex allocation 1609 ** This option can be used to overload the default mutex allocation
1386 ** routines with a wrapper used to track mutex usage for performance 1610 ** routines with a wrapper used to track mutex usage for performance
1387 ** profiling or testing, for example. ^If SQLite is compiled with 1611 ** profiling or testing, for example. ^If SQLite is compiled with
1388 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 1612 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1389 ** the entire mutexing subsystem is omitted from the build and hence calls to 1613 ** the entire mutexing subsystem is omitted from the build and hence calls to
1390 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 1614 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1391 ** return [SQLITE_ERROR].</dd> 1615 ** return [SQLITE_ERROR].</dd>
1392 ** 1616 **
1393 ** <dt>SQLITE_CONFIG_LOOKASIDE</dt> 1617 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1394 ** <dd> ^(This option takes two arguments that determine the default 1618 ** <dd> ^(This option takes two arguments that determine the default
1395 ** memory allocation for the lookaside memory allocator on each 1619 ** memory allocation for the lookaside memory allocator on each
1396 ** [database connection]. The first argument is the 1620 ** [database connection]. The first argument is the
1397 ** size of each lookaside buffer slot and the second is the number of 1621 ** size of each lookaside buffer slot and the second is the number of
1398 ** slots allocated to each database connection.)^ ^(This option sets the 1622 ** slots allocated to each database connection.)^ ^(This option sets the
1399 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 1623 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1400 ** verb to [sqlite3_db_config()] can be used to change the lookaside 1624 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1401 ** configuration on individual connections.)^ </dd> 1625 ** configuration on individual connections.)^ </dd>
1402 ** 1626 **
1403 ** <dt>SQLITE_CONFIG_PCACHE</dt> 1627 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1404 ** <dd> ^(This option takes a single argument which is a pointer to 1628 ** <dd> ^(This option takes a single argument which is a pointer to
1405 ** an [sqlite3_pcache_methods] object. This object specifies the interface 1629 ** an [sqlite3_pcache_methods2] object. This object specifies the interface
1406 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the 1630 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1407 ** object and uses it for page cache memory allocations.</dd> 1631 ** object and uses it for page cache memory allocations.</dd>
1408 ** 1632 **
1409 ** <dt>SQLITE_CONFIG_GETPCACHE</dt> 1633 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1410 ** <dd> ^(This option takes a single argument which is a pointer to an 1634 ** <dd> ^(This option takes a single argument which is a pointer to an
1411 ** [sqlite3_pcache_methods] object. SQLite copies of the current 1635 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1412 ** page cache implementation into that object.)^ </dd> 1636 ** page cache implementation into that object.)^ </dd>
1413 ** 1637 **
1414 ** <dt>SQLITE_CONFIG_LOG</dt> 1638 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1415 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 1639 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1640 ** global [error log].
1641 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1416 ** function with a call signature of void(*)(void*,int,const char*), 1642 ** function with a call signature of void(*)(void*,int,const char*),
1417 ** and a pointer to void. ^If the function pointer is not NULL, it is 1643 ** and a pointer to void. ^If the function pointer is not NULL, it is
1418 ** invoked by [sqlite3_log()] to process each logging event. ^If the 1644 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1419 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. 1645 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1420 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is 1646 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1421 ** passed through as the first parameter to the application-defined logger 1647 ** passed through as the first parameter to the application-defined logger
1422 ** function whenever that function is invoked. ^The second parameter to 1648 ** function whenever that function is invoked. ^The second parameter to
1423 ** the logger function is a copy of the first parameter to the corresponding 1649 ** the logger function is a copy of the first parameter to the corresponding
1424 ** [sqlite3_log()] call and is intended to be a [result code] or an 1650 ** [sqlite3_log()] call and is intended to be a [result code] or an
1425 ** [extended result code]. ^The third parameter passed to the logger is 1651 ** [extended result code]. ^The third parameter passed to the logger is
1426 ** log message after formatting via [sqlite3_snprintf()]. 1652 ** log message after formatting via [sqlite3_snprintf()].
1427 ** The SQLite logging interface is not reentrant; the logger function 1653 ** The SQLite logging interface is not reentrant; the logger function
1428 ** supplied by the application must not invoke any SQLite interface. 1654 ** supplied by the application must not invoke any SQLite interface.
1429 ** In a multi-threaded application, the application-defined logger 1655 ** In a multi-threaded application, the application-defined logger
1430 ** function must be threadsafe. </dd> 1656 ** function must be threadsafe. </dd>
1431 ** 1657 **
1658 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1659 ** <dd>^(This option takes a single argument of type int. If non-zero, then
1660 ** URI handling is globally enabled. If the parameter is zero, then URI handling
1661 ** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1662 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1663 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1664 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1665 ** connection is opened. ^If it is globally disabled, filenames are
1666 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1667 ** database connection is opened. ^(By default, URI handling is globally
1668 ** disabled. The default value may be changed by compiling with the
1669 ** [SQLITE_USE_URI] symbol defined.)^
1670 **
1671 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1672 ** <dd>^This option takes a single integer argument which is interpreted as
1673 ** a boolean in order to enable or disable the use of covering indices for
1674 ** full table scans in the query optimizer. ^The default setting is determined
1675 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1676 ** if that compile-time option is omitted.
1677 ** The ability to disable the use of covering indices for full table scans
1678 ** is because some incorrectly coded legacy applications might malfunction
1679 ** when the optimization is enabled. Providing the ability to
1680 ** disable the optimization allows the older, buggy application code to work
1681 ** without change even with newer versions of SQLite.
1682 **
1683 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
1684 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
1685 ** <dd> These options are obsolete and should not be used by new code.
1686 ** They are retained for backwards compatibility but are now no-ops.
1687 ** </dd>
1688 **
1689 ** [[SQLITE_CONFIG_SQLLOG]]
1690 ** <dt>SQLITE_CONFIG_SQLLOG
1691 ** <dd>This option is only available if sqlite is compiled with the
1692 ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
1693 ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
1694 ** The second should be of type (void*). The callback is invoked by the library
1695 ** in three separate circumstances, identified by the value passed as the
1696 ** fourth parameter. If the fourth parameter is 0, then the database connection
1697 ** passed as the second argument has just been opened. The third argument
1698 ** points to a buffer containing the name of the main database file. If the
1699 ** fourth parameter is 1, then the SQL statement that the third parameter
1700 ** points to has just been executed. Or, if the fourth parameter is 2, then
1701 ** the connection being passed as the second parameter is being closed. The
1702 ** third parameter is passed NULL In this case. An example of using this
1703 ** configuration option can be seen in the "test_sqllog.c" source file in
1704 ** the canonical SQLite source tree.</dd>
1705 **
1706 ** [[SQLITE_CONFIG_MMAP_SIZE]]
1707 ** <dt>SQLITE_CONFIG_MMAP_SIZE
1708 ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
1709 ** that are the default mmap size limit (the default setting for
1710 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1711 ** ^The default setting can be overridden by each database connection using
1712 ** either the [PRAGMA mmap_size] command, or by using the
1713 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1714 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1715 ** exceed the compile-time maximum mmap size set by the
1716 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1717 ** ^If either argument to this option is negative, then that argument is
1718 ** changed to its compile-time default.
1719 **
1720 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1721 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1722 ** <dd>^This option is only available if SQLite is compiled for Windows
1723 ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1724 ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1725 ** that specifies the maximum size of the created heap.
1432 ** </dl> 1726 ** </dl>
1433 */ 1727 */
1434 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 1728 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1435 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 1729 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1436 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 1730 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1437 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 1731 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
1438 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 1732 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
1439 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ 1733 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
1440 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 1734 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
1441 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 1735 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
1442 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 1736 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
1443 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 1737 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
1444 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 1738 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
1445 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 1739 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
1446 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 1740 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
1447 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ 1741 #define SQLITE_CONFIG_PCACHE 14 /* no-op */
1448 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ 1742 #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
1449 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 1743 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1744 #define SQLITE_CONFIG_URI 17 /* int */
1745 #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
1746 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1747 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1748 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1749 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1750 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1450 1751
1451 /* 1752 /*
1452 ** CAPI3REF: Database Connection Configuration Options 1753 ** CAPI3REF: Database Connection Configuration Options
1453 ** 1754 **
1454 ** These constants are the available integer configuration options that 1755 ** These constants are the available integer configuration options that
1455 ** can be passed as the second argument to the [sqlite3_db_config()] interface. 1756 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1456 ** 1757 **
1457 ** New configuration options may be added in future releases of SQLite. 1758 ** New configuration options may be added in future releases of SQLite.
1458 ** Existing configuration options might be discontinued. Applications 1759 ** Existing configuration options might be discontinued. Applications
1459 ** should check the return code from [sqlite3_db_config()] to make sure that 1760 ** should check the return code from [sqlite3_db_config()] to make sure that
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 ** 1817 **
1517 ** ^The sqlite3_extended_result_codes() routine enables or disables the 1818 ** ^The sqlite3_extended_result_codes() routine enables or disables the
1518 ** [extended result codes] feature of SQLite. ^The extended result 1819 ** [extended result codes] feature of SQLite. ^The extended result
1519 ** codes are disabled by default for historical compatibility. 1820 ** codes are disabled by default for historical compatibility.
1520 */ 1821 */
1521 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); 1822 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
1522 1823
1523 /* 1824 /*
1524 ** CAPI3REF: Last Insert Rowid 1825 ** CAPI3REF: Last Insert Rowid
1525 ** 1826 **
1526 ** ^Each entry in an SQLite table has a unique 64-bit signed 1827 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
1828 ** has a unique 64-bit signed
1527 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available 1829 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1528 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 1830 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1529 ** names are not also used by explicitly declared columns. ^If 1831 ** names are not also used by explicitly declared columns. ^If
1530 ** the table has a column of type [INTEGER PRIMARY KEY] then that column 1832 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1531 ** is another alias for the rowid. 1833 ** is another alias for the rowid.
1532 ** 1834 **
1533 ** ^This routine returns the [rowid] of the most recent 1835 ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
1534 ** successful [INSERT] into the database from the [database connection] 1836 ** most recent successful [INSERT] into a rowid table or [virtual table]
1535 ** in the first argument. ^If no successful [INSERT]s 1837 ** on database connection D.
1536 ** have ever occurred on that database connection, zero is returned. 1838 ** ^Inserts into [WITHOUT ROWID] tables are not recorded.
1839 ** ^If no successful [INSERT]s into rowid tables
1840 ** have ever occurred on the database connection D,
1841 ** then sqlite3_last_insert_rowid(D) returns zero.
1537 ** 1842 **
1538 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted 1843 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1539 ** row is returned by this routine as long as the trigger is running. 1844 ** method, then this routine will return the [rowid] of the inserted
1540 ** But once the trigger terminates, the value returned by this routine 1845 ** row as long as the trigger or virtual table method is running.
1541 ** reverts to the last value inserted before the trigger fired.)^ 1846 ** But once the trigger or virtual table method ends, the value returned
1847 ** by this routine reverts to what it was before the trigger or virtual
1848 ** table method began.)^
1542 ** 1849 **
1543 ** ^An [INSERT] that fails due to a constraint violation is not a 1850 ** ^An [INSERT] that fails due to a constraint violation is not a
1544 ** successful [INSERT] and does not change the value returned by this 1851 ** successful [INSERT] and does not change the value returned by this
1545 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 1852 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
1546 ** and INSERT OR ABORT make no changes to the return value of this 1853 ** and INSERT OR ABORT make no changes to the return value of this
1547 ** routine when their insertion fails. ^(When INSERT OR REPLACE 1854 ** routine when their insertion fails. ^(When INSERT OR REPLACE
1548 ** encounters a constraint violation, it does not fail. The 1855 ** encounters a constraint violation, it does not fail. The
1549 ** INSERT continues to completion after deleting rows that caused 1856 ** INSERT continues to completion after deleting rows that caused
1550 ** the constraint problem so INSERT OR REPLACE will always change 1857 ** the constraint problem so INSERT OR REPLACE will always change
1551 ** the return value of this interface.)^ 1858 ** the return value of this interface.)^
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 ** 2023 **
1717 ** The input to [sqlite3_complete16()] must be a zero-terminated 2024 ** The input to [sqlite3_complete16()] must be a zero-terminated
1718 ** UTF-16 string in native byte order. 2025 ** UTF-16 string in native byte order.
1719 */ 2026 */
1720 SQLITE_API int sqlite3_complete(const char *sql); 2027 SQLITE_API int sqlite3_complete(const char *sql);
1721 SQLITE_API int sqlite3_complete16(const void *sql); 2028 SQLITE_API int sqlite3_complete16(const void *sql);
1722 2029
1723 /* 2030 /*
1724 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 2031 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
1725 ** 2032 **
1726 ** ^This routine sets a callback function that might be invoked whenever 2033 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
1727 ** an attempt is made to open a database table that another thread 2034 ** that might be invoked with argument P whenever
1728 ** or process has locked. 2035 ** an attempt is made to access a database table associated with
2036 ** [database connection] D when another thread
2037 ** or process has the table locked.
2038 ** The sqlite3_busy_handler() interface is used to implement
2039 ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
1729 ** 2040 **
1730 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] 2041 ** ^If the busy callback is NULL, then [SQLITE_BUSY]
1731 ** is returned immediately upon encountering the lock. ^If the busy callback 2042 ** is returned immediately upon encountering the lock. ^If the busy callback
1732 ** is not NULL, then the callback might be invoked with two arguments. 2043 ** is not NULL, then the callback might be invoked with two arguments.
1733 ** 2044 **
1734 ** ^The first argument to the busy handler is a copy of the void* pointer which 2045 ** ^The first argument to the busy handler is a copy of the void* pointer which
1735 ** is the third argument to sqlite3_busy_handler(). ^The second argument to 2046 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
1736 ** the busy handler callback is the number of times that the busy handler has 2047 ** the busy handler callback is the number of times that the busy handler has
1737 ** been invoked for this locking event. ^If the 2048 ** been invoked for the same locking event. ^If the
1738 ** busy callback returns 0, then no additional attempts are made to 2049 ** busy callback returns 0, then no additional attempts are made to
1739 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. 2050 ** access the database and [SQLITE_BUSY] is returned
2051 ** to the application.
1740 ** ^If the callback returns non-zero, then another attempt 2052 ** ^If the callback returns non-zero, then another attempt
1741 ** is made to open the database for reading and the cycle repeats. 2053 ** is made to access the database and the cycle repeats.
1742 ** 2054 **
1743 ** The presence of a busy handler does not guarantee that it will be invoked 2055 ** The presence of a busy handler does not guarantee that it will be invoked
1744 ** when there is lock contention. ^If SQLite determines that invoking the busy 2056 ** when there is lock contention. ^If SQLite determines that invoking the busy
1745 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 2057 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
1746 ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. 2058 ** to the application instead of invoking the
2059 ** busy handler.
1747 ** Consider a scenario where one process is holding a read lock that 2060 ** Consider a scenario where one process is holding a read lock that
1748 ** it is trying to promote to a reserved lock and 2061 ** it is trying to promote to a reserved lock and
1749 ** a second process is holding a reserved lock that it is trying 2062 ** a second process is holding a reserved lock that it is trying
1750 ** to promote to an exclusive lock. The first process cannot proceed 2063 ** to promote to an exclusive lock. The first process cannot proceed
1751 ** because it is blocked by the second and the second process cannot 2064 ** because it is blocked by the second and the second process cannot
1752 ** proceed because it is blocked by the first. If both processes 2065 ** proceed because it is blocked by the first. If both processes
1753 ** invoke the busy handlers, neither will make any progress. Therefore, 2066 ** invoke the busy handlers, neither will make any progress. Therefore,
1754 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 2067 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
1755 ** will induce the first process to release its read lock and allow 2068 ** will induce the first process to release its read lock and allow
1756 ** the second process to proceed. 2069 ** the second process to proceed.
1757 ** 2070 **
1758 ** ^The default busy callback is NULL. 2071 ** ^The default busy callback is NULL.
1759 ** 2072 **
1760 ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
1761 ** when SQLite is in the middle of a large transaction where all the
1762 ** changes will not fit into the in-memory cache. SQLite will
1763 ** already hold a RESERVED lock on the database file, but it needs
1764 ** to promote this lock to EXCLUSIVE so that it can spill cache
1765 ** pages into the database file without harm to concurrent
1766 ** readers. ^If it is unable to promote the lock, then the in-memory
1767 ** cache will be left in an inconsistent state and so the error
1768 ** code is promoted from the relatively benign [SQLITE_BUSY] to
1769 ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion
1770 ** forces an automatic rollback of the changes. See the
1771 ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
1772 ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
1773 ** this is important.
1774 **
1775 ** ^(There can only be a single busy handler defined for each 2073 ** ^(There can only be a single busy handler defined for each
1776 ** [database connection]. Setting a new busy handler clears any 2074 ** [database connection]. Setting a new busy handler clears any
1777 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 2075 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
1778 ** will also set or clear the busy handler. 2076 ** or evaluating [PRAGMA busy_timeout=N] will change the
2077 ** busy handler and thus clear any previously set busy handler.
1779 ** 2078 **
1780 ** The busy callback should not take any actions which modify the 2079 ** The busy callback should not take any actions which modify the
1781 ** database connection that invoked the busy handler. Any such actions 2080 ** database connection that invoked the busy handler. In other words,
2081 ** the busy handler is not reentrant. Any such actions
1782 ** result in undefined behavior. 2082 ** result in undefined behavior.
1783 ** 2083 **
1784 ** A busy handler must not close the database connection 2084 ** A busy handler must not close the database connection
1785 ** or [prepared statement] that invoked the busy handler. 2085 ** or [prepared statement] that invoked the busy handler.
1786 */ 2086 */
1787 SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); 2087 SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
1788 2088
1789 /* 2089 /*
1790 ** CAPI3REF: Set A Busy Timeout 2090 ** CAPI3REF: Set A Busy Timeout
1791 ** 2091 **
1792 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 2092 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
1793 ** for a specified amount of time when a table is locked. ^The handler 2093 ** for a specified amount of time when a table is locked. ^The handler
1794 ** will sleep multiple times until at least "ms" milliseconds of sleeping 2094 ** will sleep multiple times until at least "ms" milliseconds of sleeping
1795 ** have accumulated. ^After at least "ms" milliseconds of sleeping, 2095 ** have accumulated. ^After at least "ms" milliseconds of sleeping,
1796 ** the handler returns 0 which causes [sqlite3_step()] to return 2096 ** the handler returns 0 which causes [sqlite3_step()] to return
1797 ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. 2097 ** [SQLITE_BUSY].
1798 ** 2098 **
1799 ** ^Calling this routine with an argument less than or equal to zero 2099 ** ^Calling this routine with an argument less than or equal to zero
1800 ** turns off all busy handlers. 2100 ** turns off all busy handlers.
1801 ** 2101 **
1802 ** ^(There can only be a single busy handler for a particular 2102 ** ^(There can only be a single busy handler for a particular
1803 ** [database connection] any any given moment. If another busy handler 2103 ** [database connection] at any given moment. If another busy handler
1804 ** was defined (using [sqlite3_busy_handler()]) prior to calling 2104 ** was defined (using [sqlite3_busy_handler()]) prior to calling
1805 ** this routine, that other busy handler is cleared.)^ 2105 ** this routine, that other busy handler is cleared.)^
2106 **
2107 ** See also: [PRAGMA busy_timeout]
1806 */ 2108 */
1807 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); 2109 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
1808 2110
1809 /* 2111 /*
1810 ** CAPI3REF: Convenience Routines For Running Queries 2112 ** CAPI3REF: Convenience Routines For Running Queries
1811 ** 2113 **
1812 ** This is a legacy interface that is preserved for backwards compatibility. 2114 ** This is a legacy interface that is preserved for backwards compatibility.
1813 ** Use of this interface is not recommended. 2115 ** Use of this interface is not recommended.
1814 ** 2116 **
1815 ** Definition: A <b>result table</b> is memory data structure created by the 2117 ** Definition: A <b>result table</b> is memory data structure created by the
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 ** the zero terminator. So the longest string that can be completely 2222 ** the zero terminator. So the longest string that can be completely
1921 ** written will be n-1 characters. 2223 ** written will be n-1 characters.
1922 ** 2224 **
1923 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 2225 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
1924 ** 2226 **
1925 ** These routines all implement some additional formatting 2227 ** These routines all implement some additional formatting
1926 ** options that are useful for constructing SQL statements. 2228 ** options that are useful for constructing SQL statements.
1927 ** All of the usual printf() formatting options apply. In addition, there 2229 ** All of the usual printf() formatting options apply. In addition, there
1928 ** is are "%q", "%Q", and "%z" options. 2230 ** is are "%q", "%Q", and "%z" options.
1929 ** 2231 **
1930 ** ^(The %q option works like %s in that it substitutes a null-terminated 2232 ** ^(The %q option works like %s in that it substitutes a nul-terminated
1931 ** string from the argument list. But %q also doubles every '\'' character. 2233 ** string from the argument list. But %q also doubles every '\'' character.
1932 ** %q is designed for use inside a string literal.)^ By doubling each '\'' 2234 ** %q is designed for use inside a string literal.)^ By doubling each '\''
1933 ** character it escapes that character and allows it to be inserted into 2235 ** character it escapes that character and allows it to be inserted into
1934 ** the string. 2236 ** the string.
1935 ** 2237 **
1936 ** For example, assume the string variable zText contains text as follows: 2238 ** For example, assume the string variable zText contains text as follows:
1937 ** 2239 **
1938 ** <blockquote><pre> 2240 ** <blockquote><pre>
1939 ** char *zText = "It's a happy day!"; 2241 ** char *zText = "It's a happy day!";
1940 ** </pre></blockquote> 2242 ** </pre></blockquote>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 ** does not include operating-system specific VFS implementation. The 2297 ** does not include operating-system specific VFS implementation. The
1996 ** Windows VFS uses native malloc() and free() for some operations. 2298 ** Windows VFS uses native malloc() and free() for some operations.
1997 ** 2299 **
1998 ** ^The sqlite3_malloc() routine returns a pointer to a block 2300 ** ^The sqlite3_malloc() routine returns a pointer to a block
1999 ** of memory at least N bytes in length, where N is the parameter. 2301 ** of memory at least N bytes in length, where N is the parameter.
2000 ** ^If sqlite3_malloc() is unable to obtain sufficient free 2302 ** ^If sqlite3_malloc() is unable to obtain sufficient free
2001 ** memory, it returns a NULL pointer. ^If the parameter N to 2303 ** memory, it returns a NULL pointer. ^If the parameter N to
2002 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 2304 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2003 ** a NULL pointer. 2305 ** a NULL pointer.
2004 ** 2306 **
2307 ** ^The sqlite3_malloc64(N) routine works just like
2308 ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
2309 ** of a signed 32-bit integer.
2310 **
2005 ** ^Calling sqlite3_free() with a pointer previously returned 2311 ** ^Calling sqlite3_free() with a pointer previously returned
2006 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 2312 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2007 ** that it might be reused. ^The sqlite3_free() routine is 2313 ** that it might be reused. ^The sqlite3_free() routine is
2008 ** a no-op if is called with a NULL pointer. Passing a NULL pointer 2314 ** a no-op if is called with a NULL pointer. Passing a NULL pointer
2009 ** to sqlite3_free() is harmless. After being freed, memory 2315 ** to sqlite3_free() is harmless. After being freed, memory
2010 ** should neither be read nor written. Even reading previously freed 2316 ** should neither be read nor written. Even reading previously freed
2011 ** memory might result in a segmentation fault or other severe error. 2317 ** memory might result in a segmentation fault or other severe error.
2012 ** Memory corruption, a segmentation fault, or other severe error 2318 ** Memory corruption, a segmentation fault, or other severe error
2013 ** might result if sqlite3_free() is called with a non-NULL pointer that 2319 ** might result if sqlite3_free() is called with a non-NULL pointer that
2014 ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 2320 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2015 ** 2321 **
2016 ** ^(The sqlite3_realloc() interface attempts to resize a 2322 ** ^The sqlite3_realloc(X,N) interface attempts to resize a
2017 ** prior memory allocation to be at least N bytes, where N is the 2323 ** prior memory allocation X to be at least N bytes.
2018 ** second parameter. The memory allocation to be resized is the first 2324 ** ^If the X parameter to sqlite3_realloc(X,N)
2019 ** parameter.)^ ^ If the first parameter to sqlite3_realloc()
2020 ** is a NULL pointer then its behavior is identical to calling 2325 ** is a NULL pointer then its behavior is identical to calling
2021 ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). 2326 ** sqlite3_malloc(N).
2022 ** ^If the second parameter to sqlite3_realloc() is zero or 2327 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
2023 ** negative then the behavior is exactly the same as calling 2328 ** negative then the behavior is exactly the same as calling
2024 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). 2329 ** sqlite3_free(X).
2025 ** ^sqlite3_realloc() returns a pointer to a memory allocation 2330 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2026 ** of at least N bytes in size or NULL if sufficient memory is unavailable. 2331 ** of at least N bytes in size or NULL if insufficient memory is available.
2027 ** ^If M is the size of the prior allocation, then min(N,M) bytes 2332 ** ^If M is the size of the prior allocation, then min(N,M) bytes
2028 ** of the prior allocation are copied into the beginning of buffer returned 2333 ** of the prior allocation are copied into the beginning of buffer returned
2029 ** by sqlite3_realloc() and the prior allocation is freed. 2334 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
2030 ** ^If sqlite3_realloc() returns NULL, then the prior allocation 2335 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2031 ** is not freed. 2336 ** prior allocation is not freed.
2032 ** 2337 **
2033 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() 2338 ** ^The sqlite3_realloc64(X,N) interfaces works the same as
2339 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
2340 ** of a 32-bit signed integer.
2341 **
2342 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
2343 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
2344 ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2345 ** ^The value returned by sqlite3_msize(X) might be larger than the number
2346 ** of bytes requested when X was allocated. ^If X is a NULL pointer then
2347 ** sqlite3_msize(X) returns zero. If X points to something that is not
2348 ** the beginning of memory allocation, or if it points to a formerly
2349 ** valid memory allocation that has now been freed, then the behavior
2350 ** of sqlite3_msize(X) is undefined and possibly harmful.
2351 **
2352 ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
2353 ** sqlite3_malloc64(), and sqlite3_realloc64()
2034 ** is always aligned to at least an 8 byte boundary, or to a 2354 ** is always aligned to at least an 8 byte boundary, or to a
2035 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time 2355 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2036 ** option is used. 2356 ** option is used.
2037 ** 2357 **
2038 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 2358 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2039 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 2359 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2040 ** implementation of these routines to be omitted. That capability 2360 ** implementation of these routines to be omitted. That capability
2041 ** is no longer provided. Only built-in memory allocators can be used. 2361 ** is no longer provided. Only built-in memory allocators can be used.
2042 ** 2362 **
2043 ** The Windows OS interface layer calls 2363 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2044 ** the system malloc() and free() directly when converting 2364 ** the system malloc() and free() directly when converting
2045 ** filenames between the UTF-8 encoding used by SQLite 2365 ** filenames between the UTF-8 encoding used by SQLite
2046 ** and whatever filename encoding is used by the particular Windows 2366 ** and whatever filename encoding is used by the particular Windows
2047 ** installation. Memory allocation errors are detected, but 2367 ** installation. Memory allocation errors were detected, but
2048 ** they are reported back as [SQLITE_CANTOPEN] or 2368 ** they were reported back as [SQLITE_CANTOPEN] or
2049 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 2369 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2050 ** 2370 **
2051 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 2371 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2052 ** must be either NULL or else pointers obtained from a prior 2372 ** must be either NULL or else pointers obtained from a prior
2053 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 2373 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
2054 ** not yet been released. 2374 ** not yet been released.
2055 ** 2375 **
2056 ** The application must not read or write any part of 2376 ** The application must not read or write any part of
2057 ** a block of memory after it has been released using 2377 ** a block of memory after it has been released using
2058 ** [sqlite3_free()] or [sqlite3_realloc()]. 2378 ** [sqlite3_free()] or [sqlite3_realloc()].
2059 */ 2379 */
2060 SQLITE_API void *sqlite3_malloc(int); 2380 SQLITE_API void *sqlite3_malloc(int);
2381 SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
2061 SQLITE_API void *sqlite3_realloc(void*, int); 2382 SQLITE_API void *sqlite3_realloc(void*, int);
2383 SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
2062 SQLITE_API void sqlite3_free(void*); 2384 SQLITE_API void sqlite3_free(void*);
2385 SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
2063 2386
2064 /* 2387 /*
2065 ** CAPI3REF: Memory Allocator Statistics 2388 ** CAPI3REF: Memory Allocator Statistics
2066 ** 2389 **
2067 ** SQLite provides these two interfaces for reporting on the status 2390 ** SQLite provides these two interfaces for reporting on the status
2068 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 2391 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
2069 ** routines, which form the built-in memory allocation subsystem. 2392 ** routines, which form the built-in memory allocation subsystem.
2070 ** 2393 **
2071 ** ^The [sqlite3_memory_used()] routine returns the number of bytes 2394 ** ^The [sqlite3_memory_used()] routine returns the number of bytes
2072 ** of memory currently outstanding (malloced but not freed). 2395 ** of memory currently outstanding (malloced but not freed).
(...skipping 17 matching lines...) Expand all
2090 /* 2413 /*
2091 ** CAPI3REF: Pseudo-Random Number Generator 2414 ** CAPI3REF: Pseudo-Random Number Generator
2092 ** 2415 **
2093 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 2416 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2094 ** select random [ROWID | ROWIDs] when inserting new records into a table that 2417 ** select random [ROWID | ROWIDs] when inserting new records into a table that
2095 ** already uses the largest possible [ROWID]. The PRNG is also used for 2418 ** already uses the largest possible [ROWID]. The PRNG is also used for
2096 ** the build-in random() and randomblob() SQL functions. This interface allows 2419 ** the build-in random() and randomblob() SQL functions. This interface allows
2097 ** applications to access the same PRNG for other purposes. 2420 ** applications to access the same PRNG for other purposes.
2098 ** 2421 **
2099 ** ^A call to this routine stores N bytes of randomness into buffer P. 2422 ** ^A call to this routine stores N bytes of randomness into buffer P.
2423 ** ^If N is less than one, then P can be a NULL pointer.
2100 ** 2424 **
2101 ** ^The first time this routine is invoked (either internally or by 2425 ** ^If this routine has not been previously called or if the previous
2102 ** the application) the PRNG is seeded using randomness obtained 2426 ** call had N less than one, then the PRNG is seeded using randomness
2103 ** from the xRandomness method of the default [sqlite3_vfs] object. 2427 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2104 ** ^On all subsequent invocations, the pseudo-randomness is generated 2428 ** ^If the previous call to this routine had an N of 1 or more then
2429 ** the pseudo-randomness is generated
2105 ** internally and without recourse to the [sqlite3_vfs] xRandomness 2430 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2106 ** method. 2431 ** method.
2107 */ 2432 */
2108 SQLITE_API void sqlite3_randomness(int N, void *P); 2433 SQLITE_API void sqlite3_randomness(int N, void *P);
2109 2434
2110 /* 2435 /*
2111 ** CAPI3REF: Compile-Time Authorization Callbacks 2436 ** CAPI3REF: Compile-Time Authorization Callbacks
2112 ** 2437 **
2113 ** ^This routine registers an authorizer callback with a particular 2438 ** ^This routine registers an authorizer callback with a particular
2114 ** [database connection], supplied in the first argument. 2439 ** [database connection], supplied in the first argument.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2194 ); 2519 );
2195 2520
2196 /* 2521 /*
2197 ** CAPI3REF: Authorizer Return Codes 2522 ** CAPI3REF: Authorizer Return Codes
2198 ** 2523 **
2199 ** The [sqlite3_set_authorizer | authorizer callback function] must 2524 ** The [sqlite3_set_authorizer | authorizer callback function] must
2200 ** return either [SQLITE_OK] or one of these two constants in order 2525 ** return either [SQLITE_OK] or one of these two constants in order
2201 ** to signal SQLite whether or not the action is permitted. See the 2526 ** to signal SQLite whether or not the action is permitted. See the
2202 ** [sqlite3_set_authorizer | authorizer documentation] for additional 2527 ** [sqlite3_set_authorizer | authorizer documentation] for additional
2203 ** information. 2528 ** information.
2529 **
2530 ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
2531 ** returned from the [sqlite3_vtab_on_conflict()] interface.
2204 */ 2532 */
2205 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 2533 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2206 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 2534 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
2207 2535
2208 /* 2536 /*
2209 ** CAPI3REF: Authorizer Action Codes 2537 ** CAPI3REF: Authorizer Action Codes
2210 ** 2538 **
2211 ** The [sqlite3_set_authorizer()] interface registers a callback function 2539 ** The [sqlite3_set_authorizer()] interface registers a callback function
2212 ** that is invoked to authorize certain SQL statement actions. The 2540 ** that is invoked to authorize certain SQL statement actions. The
2213 ** second parameter to the callback is an integer code that specifies 2541 ** second parameter to the callback is an integer code that specifies
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 #define SQLITE_ATTACH 24 /* Filename NULL */ 2579 #define SQLITE_ATTACH 24 /* Filename NULL */
2252 #define SQLITE_DETACH 25 /* Database Name NULL */ 2580 #define SQLITE_DETACH 25 /* Database Name NULL */
2253 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 2581 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
2254 #define SQLITE_REINDEX 27 /* Index Name NULL */ 2582 #define SQLITE_REINDEX 27 /* Index Name NULL */
2255 #define SQLITE_ANALYZE 28 /* Table Name NULL */ 2583 #define SQLITE_ANALYZE 28 /* Table Name NULL */
2256 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 2584 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
2257 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 2585 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
2258 #define SQLITE_FUNCTION 31 /* NULL Function Name */ 2586 #define SQLITE_FUNCTION 31 /* NULL Function Name */
2259 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 2587 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2260 #define SQLITE_COPY 0 /* No longer used */ 2588 #define SQLITE_COPY 0 /* No longer used */
2589 #define SQLITE_RECURSIVE 33 /* NULL NULL */
2261 2590
2262 /* 2591 /*
2263 ** CAPI3REF: Tracing And Profiling Functions 2592 ** CAPI3REF: Tracing And Profiling Functions
2264 ** 2593 **
2265 ** These routines register callback functions that can be used for 2594 ** These routines register callback functions that can be used for
2266 ** tracing and profiling the execution of SQL statements. 2595 ** tracing and profiling the execution of SQL statements.
2267 ** 2596 **
2268 ** ^The callback function registered by sqlite3_trace() is invoked at 2597 ** ^The callback function registered by sqlite3_trace() is invoked at
2269 ** various times when an SQL statement is being run by [sqlite3_step()]. 2598 ** various times when an SQL statement is being run by [sqlite3_step()].
2270 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 2599 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
2271 ** SQL statement text as the statement first begins executing. 2600 ** SQL statement text as the statement first begins executing.
2272 ** ^(Additional sqlite3_trace() callbacks might occur 2601 ** ^(Additional sqlite3_trace() callbacks might occur
2273 ** as each triggered subprogram is entered. The callbacks for triggers 2602 ** as each triggered subprogram is entered. The callbacks for triggers
2274 ** contain a UTF-8 SQL comment that identifies the trigger.)^ 2603 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2275 ** 2604 **
2605 ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
2606 ** the length of [bound parameter] expansion in the output of sqlite3_trace().
2607 **
2276 ** ^The callback function registered by sqlite3_profile() is invoked 2608 ** ^The callback function registered by sqlite3_profile() is invoked
2277 ** as each SQL statement finishes. ^The profile callback contains 2609 ** as each SQL statement finishes. ^The profile callback contains
2278 ** the original statement text and an estimate of wall-clock time 2610 ** the original statement text and an estimate of wall-clock time
2279 ** of how long that statement took to run. ^The profile callback 2611 ** of how long that statement took to run. ^The profile callback
2280 ** time is in units of nanoseconds, however the current implementation 2612 ** time is in units of nanoseconds, however the current implementation
2281 ** is only capable of millisecond resolution so the six least significant 2613 ** is only capable of millisecond resolution so the six least significant
2282 ** digits in the time are meaningless. Future versions of SQLite 2614 ** digits in the time are meaningless. Future versions of SQLite
2283 ** might provide greater resolution on the profiler callback. The 2615 ** might provide greater resolution on the profiler callback. The
2284 ** sqlite3_profile() function is considered experimental and is 2616 ** sqlite3_profile() function is considered experimental and is
2285 ** subject to change in future versions of SQLite. 2617 ** subject to change in future versions of SQLite.
2286 */ 2618 */
2287 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void* ); 2619 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void* );
2288 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, 2620 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2289 void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 2621 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2290 2622
2291 /* 2623 /*
2292 ** CAPI3REF: Query Progress Callbacks 2624 ** CAPI3REF: Query Progress Callbacks
2293 ** 2625 **
2294 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback 2626 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
2295 ** function X to be invoked periodically during long running calls to 2627 ** function X to be invoked periodically during long running calls to
2296 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for 2628 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
2297 ** database connection D. An example use for this 2629 ** database connection D. An example use for this
2298 ** interface is to keep a GUI updated during a large query. 2630 ** interface is to keep a GUI updated during a large query.
2299 ** 2631 **
2300 ** ^The parameter P is passed through as the only parameter to the 2632 ** ^The parameter P is passed through as the only parameter to the
2301 ** callback function X. ^The parameter N is the number of 2633 ** callback function X. ^The parameter N is the approximate number of
2302 ** [virtual machine instructions] that are evaluated between successive 2634 ** [virtual machine instructions] that are evaluated between successive
2303 ** invocations of the callback X. 2635 ** invocations of the callback X. ^If N is less than one then the progress
2636 ** handler is disabled.
2304 ** 2637 **
2305 ** ^Only a single progress handler may be defined at one time per 2638 ** ^Only a single progress handler may be defined at one time per
2306 ** [database connection]; setting a new progress handler cancels the 2639 ** [database connection]; setting a new progress handler cancels the
2307 ** old one. ^Setting parameter X to NULL disables the progress handler. 2640 ** old one. ^Setting parameter X to NULL disables the progress handler.
2308 ** ^The progress handler is also disabled by setting N to a value less 2641 ** ^The progress handler is also disabled by setting N to a value less
2309 ** than 1. 2642 ** than 1.
2310 ** 2643 **
2311 ** ^If the progress callback returns non-zero, the operation is 2644 ** ^If the progress callback returns non-zero, the operation is
2312 ** interrupted. This feature can be used to implement a 2645 ** interrupted. This feature can be used to implement a
2313 ** "Cancel" button on a GUI progress dialog box. 2646 ** "Cancel" button on a GUI progress dialog box.
2314 ** 2647 **
2315 ** The progress handler callback must not do anything that will modify 2648 ** The progress handler callback must not do anything that will modify
2316 ** the database connection that invoked the progress handler. 2649 ** the database connection that invoked the progress handler.
2317 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 2650 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2318 ** database connections for the meaning of "modify" in this paragraph. 2651 ** database connections for the meaning of "modify" in this paragraph.
2319 ** 2652 **
2320 */ 2653 */
2321 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 2654 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2322 2655
2323 /* 2656 /*
2324 ** CAPI3REF: Opening A New Database Connection 2657 ** CAPI3REF: Opening A New Database Connection
2325 ** 2658 **
2326 ** ^These routines open an SQLite database file whose name is given by the 2659 ** ^These routines open an SQLite database file as specified by the
2327 ** filename argument. ^The filename argument is interpreted as UTF-8 for 2660 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2328 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 2661 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2329 ** order for sqlite3_open16(). ^(A [database connection] handle is usually 2662 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
2330 ** returned in *ppDb, even if an error occurs. The only exception is that 2663 ** returned in *ppDb, even if an error occurs. The only exception is that
2331 ** if SQLite is unable to allocate memory to hold the [sqlite3] object, 2664 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
2332 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 2665 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
2333 ** object.)^ ^(If the database is opened (and/or created) successfully, then 2666 ** object.)^ ^(If the database is opened (and/or created) successfully, then
2334 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 2667 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
2335 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 2668 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
2336 ** an English language description of the error following a failure of any 2669 ** an English language description of the error following a failure of any
2337 ** of the sqlite3_open() routines. 2670 ** of the sqlite3_open() routines.
2338 ** 2671 **
2339 ** ^The default encoding for the database will be UTF-8 if 2672 ** ^The default encoding will be UTF-8 for databases created using
2340 ** sqlite3_open() or sqlite3_open_v2() is called and 2673 ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
2341 ** UTF-16 in the native byte order if sqlite3_open16() is used. 2674 ** created using sqlite3_open16() will be UTF-16 in the native byte order.
2342 ** 2675 **
2343 ** Whether or not an error occurs when it is opened, resources 2676 ** Whether or not an error occurs when it is opened, resources
2344 ** associated with the [database connection] handle should be released by 2677 ** associated with the [database connection] handle should be released by
2345 ** passing it to [sqlite3_close()] when it is no longer required. 2678 ** passing it to [sqlite3_close()] when it is no longer required.
2346 ** 2679 **
2347 ** The sqlite3_open_v2() interface works like sqlite3_open() 2680 ** The sqlite3_open_v2() interface works like sqlite3_open()
2348 ** except that it accepts two additional parameters for additional control 2681 ** except that it accepts two additional parameters for additional control
2349 ** over the new database connection. ^(The flags parameter to 2682 ** over the new database connection. ^(The flags parameter to
2350 ** sqlite3_open_v2() can take one of 2683 ** sqlite3_open_v2() can take one of
2351 ** the following three values, optionally combined with the 2684 ** the following three values, optionally combined with the
2352 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], 2685 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2353 ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ 2686 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
2354 ** 2687 **
2355 ** <dl> 2688 ** <dl>
2356 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 2689 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
2357 ** <dd>The database is opened in read-only mode. If the database does not 2690 ** <dd>The database is opened in read-only mode. If the database does not
2358 ** already exist, an error is returned.</dd>)^ 2691 ** already exist, an error is returned.</dd>)^
2359 ** 2692 **
2360 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 2693 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
2361 ** <dd>The database is opened for reading and writing if possible, or reading 2694 ** <dd>The database is opened for reading and writing if possible, or reading
2362 ** only if the file is write protected by the operating system. In either 2695 ** only if the file is write protected by the operating system. In either
2363 ** case the database must already exist, otherwise an error is returned.</dd>)^ 2696 ** case the database must already exist, otherwise an error is returned.</dd>)^
2364 ** 2697 **
2365 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 2698 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2366 ** <dd>The database is opened for reading and writing, and is created if 2699 ** <dd>The database is opened for reading and writing, and is created if
2367 ** it does not already exist. This is the behavior that is always used for 2700 ** it does not already exist. This is the behavior that is always used for
2368 ** sqlite3_open() and sqlite3_open16().</dd>)^ 2701 ** sqlite3_open() and sqlite3_open16().</dd>)^
2369 ** </dl> 2702 ** </dl>
2370 ** 2703 **
2371 ** If the 3rd parameter to sqlite3_open_v2() is not one of the 2704 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2372 ** combinations shown above or one of the combinations shown above combined 2705 ** combinations shown above optionally combined with other
2373 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], 2706 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
2374 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2375 ** then the behavior is undefined. 2707 ** then the behavior is undefined.
2376 ** 2708 **
2377 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection 2709 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2378 ** opens in the multi-thread [threading mode] as long as the single-thread 2710 ** opens in the multi-thread [threading mode] as long as the single-thread
2379 ** mode has not been set at compile-time or start-time. ^If the 2711 ** mode has not been set at compile-time or start-time. ^If the
2380 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens 2712 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
2381 ** in the serialized [threading mode] unless single-thread was 2713 ** in the serialized [threading mode] unless single-thread was
2382 ** previously selected at compile-time or start-time. 2714 ** previously selected at compile-time or start-time.
2383 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be 2715 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
2384 ** eligible to use [shared cache mode], regardless of whether or not shared 2716 ** eligible to use [shared cache mode], regardless of whether or not shared
2385 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The 2717 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
2386 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not 2718 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2387 ** participate in [shared cache mode] even if it is enabled. 2719 ** participate in [shared cache mode] even if it is enabled.
2388 ** 2720 **
2721 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
2722 ** [sqlite3_vfs] object that defines the operating system interface that
2723 ** the new database connection should use. ^If the fourth parameter is
2724 ** a NULL pointer then the default [sqlite3_vfs] object is used.
2725 **
2389 ** ^If the filename is ":memory:", then a private, temporary in-memory database 2726 ** ^If the filename is ":memory:", then a private, temporary in-memory database
2390 ** is created for the connection. ^This in-memory database will vanish when 2727 ** is created for the connection. ^This in-memory database will vanish when
2391 ** the database connection is closed. Future versions of SQLite might 2728 ** the database connection is closed. Future versions of SQLite might
2392 ** make use of additional special filenames that begin with the ":" character. 2729 ** make use of additional special filenames that begin with the ":" character.
2393 ** It is recommended that when a database filename actually does begin with 2730 ** It is recommended that when a database filename actually does begin with
2394 ** a ":" character you should prefix the filename with a pathname such as 2731 ** a ":" character you should prefix the filename with a pathname such as
2395 ** "./" to avoid ambiguity. 2732 ** "./" to avoid ambiguity.
2396 ** 2733 **
2397 ** ^If the filename is an empty string, then a private, temporary 2734 ** ^If the filename is an empty string, then a private, temporary
2398 ** on-disk database will be created. ^This private database will be 2735 ** on-disk database will be created. ^This private database will be
2399 ** automatically deleted as soon as the database connection is closed. 2736 ** automatically deleted as soon as the database connection is closed.
2400 ** 2737 **
2401 ** ^The fourth parameter to sqlite3_open_v2() is the name of the 2738 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
2402 ** [sqlite3_vfs] object that defines the operating system interface that 2739 **
2403 ** the new database connection should use. ^If the fourth parameter is 2740 ** ^If [URI filename] interpretation is enabled, and the filename argument
2404 ** a NULL pointer then the default [sqlite3_vfs] object is used. 2741 ** begins with "file:", then the filename is interpreted as a URI. ^URI
2742 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
2743 ** set in the fourth argument to sqlite3_open_v2(), or if it has
2744 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
2745 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
2746 ** As of SQLite version 3.7.7, URI filename interpretation is turned off
2747 ** by default, but future releases of SQLite might enable URI filename
2748 ** interpretation by default. See "[URI filenames]" for additional
2749 ** information.
2750 **
2751 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
2752 ** authority, then it must be either an empty string or the string
2753 ** "localhost". ^If the authority is not an empty string or "localhost", an
2754 ** error is returned to the caller. ^The fragment component of a URI, if
2755 ** present, is ignored.
2756 **
2757 ** ^SQLite uses the path component of the URI as the name of the disk file
2758 ** which contains the database. ^If the path begins with a '/' character,
2759 ** then it is interpreted as an absolute path. ^If the path does not begin
2760 ** with a '/' (meaning that the authority section is omitted from the URI)
2761 ** then the path is interpreted as a relative path.
2762 ** ^(On windows, the first component of an absolute path
2763 ** is a drive specification (e.g. "C:").)^
2764 **
2765 ** [[core URI query parameters]]
2766 ** The query component of a URI may contain parameters that are interpreted
2767 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
2768 ** SQLite and its built-in [VFSes] interpret the
2769 ** following query parameters:
2770 **
2771 ** <ul>
2772 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
2773 ** a VFS object that provides the operating system interface that should
2774 ** be used to access the database file on disk. ^If this option is set to
2775 ** an empty string the default VFS object is used. ^Specifying an unknown
2776 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
2777 ** present, then the VFS specified by the option takes precedence over
2778 ** the value passed as the fourth parameter to sqlite3_open_v2().
2779 **
2780 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
2781 ** "rwc", or "memory". Attempting to set it to any other value is
2782 ** an error)^.
2783 ** ^If "ro" is specified, then the database is opened for read-only
2784 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2785 ** third argument to sqlite3_open_v2(). ^If the mode option is set to
2786 ** "rw", then the database is opened for read-write (but not create)
2787 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
2788 ** been set. ^Value "rwc" is equivalent to setting both
2789 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
2790 ** set to "memory" then a pure [in-memory database] that never reads
2791 ** or writes from disk is used. ^It is an error to specify a value for
2792 ** the mode parameter that is less restrictive than that specified by
2793 ** the flags passed in the third parameter to sqlite3_open_v2().
2794 **
2795 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
2796 ** "private". ^Setting it to "shared" is equivalent to setting the
2797 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2798 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
2799 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2800 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2801 ** a URI filename, its value overrides any behavior requested by setting
2802 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2803 **
2804 ** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
2805 ** [powersafe overwrite] property does or does not apply to the
2806 ** storage media on which the database file resides.
2807 **
2808 ** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
2809 ** which if set disables file locking in rollback journal modes. This
2810 ** is useful for accessing a database on a filesystem that does not
2811 ** support locking. Caution: Database corruption might result if two
2812 ** or more processes write to the same database and any one of those
2813 ** processes uses nolock=1.
2814 **
2815 ** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
2816 ** parameter that indicates that the database file is stored on
2817 ** read-only media. ^When immutable is set, SQLite assumes that the
2818 ** database file cannot be changed, even by a process with higher
2819 ** privilege, and so the database is opened read-only and all locking
2820 ** and change detection is disabled. Caution: Setting the immutable
2821 ** property on a database file that does in fact change can result
2822 ** in incorrect query results and/or [SQLITE_CORRUPT] errors.
2823 ** See also: [SQLITE_IOCAP_IMMUTABLE].
2824 **
2825 ** </ul>
2826 **
2827 ** ^Specifying an unknown parameter in the query component of a URI is not an
2828 ** error. Future versions of SQLite might understand additional query
2829 ** parameters. See "[query parameters with special meaning to SQLite]" for
2830 ** additional information.
2831 **
2832 ** [[URI filename examples]] <h3>URI filename examples</h3>
2833 **
2834 ** <table border="1" align=center cellpadding=5>
2835 ** <tr><th> URI filenames <th> Results
2836 ** <tr><td> file:data.db <td>
2837 ** Open the file "data.db" in the current directory.
2838 ** <tr><td> file:/home/fred/data.db<br>
2839 ** file:///home/fred/data.db <br>
2840 ** file://localhost/home/fred/data.db <br> <td>
2841 ** Open the database file "/home/fred/data.db".
2842 ** <tr><td> file://darkstar/home/fred/data.db <td>
2843 ** An error. "darkstar" is not a recognized authority.
2844 ** <tr><td style="white-space:nowrap">
2845 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
2846 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
2847 ** C:. Note that the %20 escaping in this example is not strictly
2848 ** necessary - space characters can be used literally
2849 ** in URI filenames.
2850 ** <tr><td> file:data.db?mode=ro&cache=private <td>
2851 ** Open file "data.db" in the current directory for read-only access.
2852 ** Regardless of whether or not shared-cache mode is enabled by
2853 ** default, use a private cache.
2854 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
2855 ** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
2856 ** that uses dot-files in place of posix advisory locking.
2857 ** <tr><td> file:data.db?mode=readonly <td>
2858 ** An error. "readonly" is not a valid option for the "mode" parameter.
2859 ** </table>
2860 **
2861 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
2862 ** query components of a URI. A hexadecimal escape sequence consists of a
2863 ** percent sign - "%" - followed by exactly two hexadecimal digits
2864 ** specifying an octet value. ^Before the path or query components of a
2865 ** URI filename are interpreted, they are encoded using UTF-8 and all
2866 ** hexadecimal escape sequences replaced by a single byte containing the
2867 ** corresponding octet. If this process generates an invalid UTF-8 encoding,
2868 ** the results are undefined.
2405 ** 2869 **
2406 ** <b>Note to Windows users:</b> The encoding used for the filename argument 2870 ** <b>Note to Windows users:</b> The encoding used for the filename argument
2407 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 2871 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
2408 ** codepage is currently defined. Filenames containing international 2872 ** codepage is currently defined. Filenames containing international
2409 ** characters must be converted to UTF-8 prior to passing them into 2873 ** characters must be converted to UTF-8 prior to passing them into
2410 ** sqlite3_open() or sqlite3_open_v2(). 2874 ** sqlite3_open() or sqlite3_open_v2().
2875 **
2876 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
2877 ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
2878 ** features that require the use of temporary files may fail.
2879 **
2880 ** See also: [sqlite3_temp_directory]
2411 */ 2881 */
2412 SQLITE_API int sqlite3_open( 2882 SQLITE_API int sqlite3_open(
2413 const char *filename, /* Database filename (UTF-8) */ 2883 const char *filename, /* Database filename (UTF-8) */
2414 sqlite3 **ppDb /* OUT: SQLite db handle */ 2884 sqlite3 **ppDb /* OUT: SQLite db handle */
2415 ); 2885 );
2416 SQLITE_API int sqlite3_open16( 2886 SQLITE_API int sqlite3_open16(
2417 const void *filename, /* Database filename (UTF-16) */ 2887 const void *filename, /* Database filename (UTF-16) */
2418 sqlite3 **ppDb /* OUT: SQLite db handle */ 2888 sqlite3 **ppDb /* OUT: SQLite db handle */
2419 ); 2889 );
2420 SQLITE_API int sqlite3_open_v2( 2890 SQLITE_API int sqlite3_open_v2(
2421 const char *filename, /* Database filename (UTF-8) */ 2891 const char *filename, /* Database filename (UTF-8) */
2422 sqlite3 **ppDb, /* OUT: SQLite db handle */ 2892 sqlite3 **ppDb, /* OUT: SQLite db handle */
2423 int flags, /* Flags */ 2893 int flags, /* Flags */
2424 const char *zVfs /* Name of VFS module to use */ 2894 const char *zVfs /* Name of VFS module to use */
2425 ); 2895 );
2426 2896
2427 /* 2897 /*
2898 ** CAPI3REF: Obtain Values For URI Parameters
2899 **
2900 ** These are utility routines, useful to VFS implementations, that check
2901 ** to see if a database file was a URI that contained a specific query
2902 ** parameter, and if so obtains the value of that query parameter.
2903 **
2904 ** If F is the database filename pointer passed into the xOpen() method of
2905 ** a VFS implementation when the flags parameter to xOpen() has one or
2906 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
2907 ** P is the name of the query parameter, then
2908 ** sqlite3_uri_parameter(F,P) returns the value of the P
2909 ** parameter if it exists or a NULL pointer if P does not appear as a
2910 ** query parameter on F. If P is a query parameter of F
2911 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
2912 ** a pointer to an empty string.
2913 **
2914 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
2915 ** parameter and returns true (1) or false (0) according to the value
2916 ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
2917 ** value of query parameter P is one of "yes", "true", or "on" in any
2918 ** case or if the value begins with a non-zero number. The
2919 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
2920 ** query parameter P is one of "no", "false", or "off" in any case or
2921 ** if the value begins with a numeric zero. If P is not a query
2922 ** parameter on F or if the value of P is does not match any of the
2923 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
2924 **
2925 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
2926 ** 64-bit signed integer and returns that integer, or D if P does not
2927 ** exist. If the value of P is something other than an integer, then
2928 ** zero is returned.
2929 **
2930 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
2931 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
2932 ** is not a database file pathname pointer that SQLite passed into the xOpen
2933 ** VFS method, then the behavior of this routine is undefined and probably
2934 ** undesirable.
2935 */
2936 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char * zParam);
2937 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bD efault);
2938 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int 64);
2939
2940
2941 /*
2428 ** CAPI3REF: Error Codes And Messages 2942 ** CAPI3REF: Error Codes And Messages
2429 ** 2943 **
2430 ** ^The sqlite3_errcode() interface returns the numeric [result code] or 2944 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
2431 ** [extended result code] for the most recent failed sqlite3_* API call 2945 ** [extended result code] for the most recent failed sqlite3_* API call
2432 ** associated with a [database connection]. If a prior API call failed 2946 ** associated with a [database connection]. If a prior API call failed
2433 ** but the most recent API call succeeded, the return value from 2947 ** but the most recent API call succeeded, the return value from
2434 ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() 2948 ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode()
2435 ** interface is the same except that it always returns the 2949 ** interface is the same except that it always returns the
2436 ** [extended result code] even when extended result codes are 2950 ** [extended result code] even when extended result codes are
2437 ** disabled. 2951 ** disabled.
2438 ** 2952 **
2439 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 2953 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
2440 ** text that describes the error, as either UTF-8 or UTF-16 respectively. 2954 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
2441 ** ^(Memory to hold the error message string is managed internally. 2955 ** ^(Memory to hold the error message string is managed internally.
2442 ** The application does not need to worry about freeing the result. 2956 ** The application does not need to worry about freeing the result.
2443 ** However, the error string might be overwritten or deallocated by 2957 ** However, the error string might be overwritten or deallocated by
2444 ** subsequent calls to other SQLite interface functions.)^ 2958 ** subsequent calls to other SQLite interface functions.)^
2445 ** 2959 **
2960 ** ^The sqlite3_errstr() interface returns the English-language text
2961 ** that describes the [result code], as UTF-8.
2962 ** ^(Memory to hold the error message string is managed internally
2963 ** and must not be freed by the application)^.
2964 **
2446 ** When the serialized [threading mode] is in use, it might be the 2965 ** When the serialized [threading mode] is in use, it might be the
2447 ** case that a second error occurs on a separate thread in between 2966 ** case that a second error occurs on a separate thread in between
2448 ** the time of the first error and the call to these interfaces. 2967 ** the time of the first error and the call to these interfaces.
2449 ** When that happens, the second error will be reported since these 2968 ** When that happens, the second error will be reported since these
2450 ** interfaces always report the most recent result. To avoid 2969 ** interfaces always report the most recent result. To avoid
2451 ** this, each thread can obtain exclusive use of the [database connection] D 2970 ** this, each thread can obtain exclusive use of the [database connection] D
2452 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 2971 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
2453 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 2972 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
2454 ** all calls to the interfaces listed here are completed. 2973 ** all calls to the interfaces listed here are completed.
2455 ** 2974 **
2456 ** If an interface fails with SQLITE_MISUSE, that means the interface 2975 ** If an interface fails with SQLITE_MISUSE, that means the interface
2457 ** was invoked incorrectly by the application. In that case, the 2976 ** was invoked incorrectly by the application. In that case, the
2458 ** error code and message may or may not be set. 2977 ** error code and message may or may not be set.
2459 */ 2978 */
2460 SQLITE_API int sqlite3_errcode(sqlite3 *db); 2979 SQLITE_API int sqlite3_errcode(sqlite3 *db);
2461 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); 2980 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
2462 SQLITE_API const char *sqlite3_errmsg(sqlite3*); 2981 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
2463 SQLITE_API const void *sqlite3_errmsg16(sqlite3*); 2982 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
2983 SQLITE_API const char *sqlite3_errstr(int);
2464 2984
2465 /* 2985 /*
2466 ** CAPI3REF: SQL Statement Object 2986 ** CAPI3REF: SQL Statement Object
2467 ** KEYWORDS: {prepared statement} {prepared statements} 2987 ** KEYWORDS: {prepared statement} {prepared statements}
2468 ** 2988 **
2469 ** An instance of this object represents a single SQL statement. 2989 ** An instance of this object represents a single SQL statement.
2470 ** This object is variously known as a "prepared statement" or a 2990 ** This object is variously known as a "prepared statement" or a
2471 ** "compiled SQL statement" or simply as a "statement". 2991 ** "compiled SQL statement" or simply as a "statement".
2472 ** 2992 **
2473 ** The life of a statement object goes something like this: 2993 ** The life of a statement object goes something like this:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2532 /* 3052 /*
2533 ** CAPI3REF: Run-Time Limit Categories 3053 ** CAPI3REF: Run-Time Limit Categories
2534 ** KEYWORDS: {limit category} {*limit categories} 3054 ** KEYWORDS: {limit category} {*limit categories}
2535 ** 3055 **
2536 ** These constants define various performance limits 3056 ** These constants define various performance limits
2537 ** that can be lowered at run-time using [sqlite3_limit()]. 3057 ** that can be lowered at run-time using [sqlite3_limit()].
2538 ** The synopsis of the meanings of the various limits is shown below. 3058 ** The synopsis of the meanings of the various limits is shown below.
2539 ** Additional information is available at [limits | Limits in SQLite]. 3059 ** Additional information is available at [limits | Limits in SQLite].
2540 ** 3060 **
2541 ** <dl> 3061 ** <dl>
2542 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt> 3062 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2543 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ 3063 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
2544 ** 3064 **
2545 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 3065 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2546 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 3066 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
2547 ** 3067 **
2548 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt> 3068 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
2549 ** <dd>The maximum number of columns in a table definition or in the 3069 ** <dd>The maximum number of columns in a table definition or in the
2550 ** result set of a [SELECT] or the maximum number of columns in an index 3070 ** result set of a [SELECT] or the maximum number of columns in an index
2551 ** or in an ORDER BY or GROUP BY clause.</dd>)^ 3071 ** or in an ORDER BY or GROUP BY clause.</dd>)^
2552 ** 3072 **
2553 ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 3073 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
2554 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 3074 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
2555 ** 3075 **
2556 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 3076 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2557 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 3077 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
2558 ** 3078 **
2559 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 3079 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2560 ** <dd>The maximum number of instructions in a virtual machine program 3080 ** <dd>The maximum number of instructions in a virtual machine program
2561 ** used to implement an SQL statement. This limit is not currently 3081 ** used to implement an SQL statement. This limit is not currently
2562 ** enforced, though that might be added in some future release of 3082 ** enforced, though that might be added in some future release of
2563 ** SQLite.</dd>)^ 3083 ** SQLite.</dd>)^
2564 ** 3084 **
2565 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 3085 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2566 ** <dd>The maximum number of arguments on a function.</dd>)^ 3086 ** <dd>The maximum number of arguments on a function.</dd>)^
2567 ** 3087 **
2568 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 3088 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
2569 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 3089 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
2570 ** 3090 **
3091 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
2571 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 3092 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2572 ** <dd>The maximum length of the pattern argument to the [LIKE] or 3093 ** <dd>The maximum length of the pattern argument to the [LIKE] or
2573 ** [GLOB] operators.</dd>)^ 3094 ** [GLOB] operators.</dd>)^
2574 ** 3095 **
3096 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
2575 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 3097 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2576 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ 3098 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
2577 ** 3099 **
2578 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 3100 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2579 ** <dd>The maximum depth of recursion for triggers.</dd>)^ 3101 ** <dd>The maximum depth of recursion for triggers.</dd>)^
3102 **
3103 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
3104 ** <dd>The maximum number of auxiliary worker threads that a single
3105 ** [prepared statement] may start.</dd>)^
2580 ** </dl> 3106 ** </dl>
2581 */ 3107 */
2582 #define SQLITE_LIMIT_LENGTH 0 3108 #define SQLITE_LIMIT_LENGTH 0
2583 #define SQLITE_LIMIT_SQL_LENGTH 1 3109 #define SQLITE_LIMIT_SQL_LENGTH 1
2584 #define SQLITE_LIMIT_COLUMN 2 3110 #define SQLITE_LIMIT_COLUMN 2
2585 #define SQLITE_LIMIT_EXPR_DEPTH 3 3111 #define SQLITE_LIMIT_EXPR_DEPTH 3
2586 #define SQLITE_LIMIT_COMPOUND_SELECT 4 3112 #define SQLITE_LIMIT_COMPOUND_SELECT 4
2587 #define SQLITE_LIMIT_VDBE_OP 5 3113 #define SQLITE_LIMIT_VDBE_OP 5
2588 #define SQLITE_LIMIT_FUNCTION_ARG 6 3114 #define SQLITE_LIMIT_FUNCTION_ARG 6
2589 #define SQLITE_LIMIT_ATTACHED 7 3115 #define SQLITE_LIMIT_ATTACHED 7
2590 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 3116 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
2591 #define SQLITE_LIMIT_VARIABLE_NUMBER 9 3117 #define SQLITE_LIMIT_VARIABLE_NUMBER 9
2592 #define SQLITE_LIMIT_TRIGGER_DEPTH 10 3118 #define SQLITE_LIMIT_TRIGGER_DEPTH 10
3119 #define SQLITE_LIMIT_WORKER_THREADS 11
2593 3120
2594 /* 3121 /*
2595 ** CAPI3REF: Compiling An SQL Statement 3122 ** CAPI3REF: Compiling An SQL Statement
2596 ** KEYWORDS: {SQL statement compiler} 3123 ** KEYWORDS: {SQL statement compiler}
2597 ** 3124 **
2598 ** To execute an SQL query, it must first be compiled into a byte-code 3125 ** To execute an SQL query, it must first be compiled into a byte-code
2599 ** program using one of these routines. 3126 ** program using one of these routines.
2600 ** 3127 **
2601 ** The first argument, "db", is a [database connection] obtained from a 3128 ** The first argument, "db", is a [database connection] obtained from a
2602 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 3129 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
2603 ** [sqlite3_open16()]. The database connection must not have been closed. 3130 ** [sqlite3_open16()]. The database connection must not have been closed.
2604 ** 3131 **
2605 ** The second argument, "zSql", is the statement to be compiled, encoded 3132 ** The second argument, "zSql", is the statement to be compiled, encoded
2606 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() 3133 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
2607 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() 3134 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
2608 ** use UTF-16. 3135 ** use UTF-16.
2609 ** 3136 **
2610 ** ^If the nByte argument is less than zero, then zSql is read up to the 3137 ** ^If the nByte argument is less than zero, then zSql is read up to the
2611 ** first zero terminator. ^If nByte is non-negative, then it is the maximum 3138 ** first zero terminator. ^If nByte is non-negative, then it is the maximum
2612 ** number of bytes read from zSql. ^When nByte is non-negative, the 3139 ** number of bytes read from zSql. ^When nByte is non-negative, the
2613 ** zSql string ends at either the first '\000' or '\u0000' character or 3140 ** zSql string ends at either the first '\000' or '\u0000' character or
2614 ** the nByte-th byte, whichever comes first. If the caller knows 3141 ** the nByte-th byte, whichever comes first. If the caller knows
2615 ** that the supplied string is nul-terminated, then there is a small 3142 ** that the supplied string is nul-terminated, then there is a small
2616 ** performance advantage to be gained by passing an nByte parameter that 3143 ** performance advantage to be gained by passing an nByte parameter that
2617 ** is equal to the number of bytes in the input string <i>including</i> 3144 ** is equal to the number of bytes in the input string <i>including</i>
2618 ** the nul-terminator bytes. 3145 ** the nul-terminator bytes as this saves SQLite from having to
3146 ** make a copy of the input string.
2619 ** 3147 **
2620 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte 3148 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
2621 ** past the end of the first SQL statement in zSql. These routines only 3149 ** past the end of the first SQL statement in zSql. These routines only
2622 ** compile the first statement in zSql, so *pzTail is left pointing to 3150 ** compile the first statement in zSql, so *pzTail is left pointing to
2623 ** what remains uncompiled. 3151 ** what remains uncompiled.
2624 ** 3152 **
2625 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 3153 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
2626 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 3154 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
2627 ** to NULL. ^If the input text contains no SQL (if the input is an empty 3155 ** to NULL. ^If the input text contains no SQL (if the input is an empty
2628 ** string or a comment) then *ppStmt is set to NULL. 3156 ** string or a comment) then *ppStmt is set to NULL.
2629 ** The calling procedure is responsible for deleting the compiled 3157 ** The calling procedure is responsible for deleting the compiled
2630 ** SQL statement using [sqlite3_finalize()] after it has finished with it. 3158 ** SQL statement using [sqlite3_finalize()] after it has finished with it.
2631 ** ppStmt may not be NULL. 3159 ** ppStmt may not be NULL.
2632 ** 3160 **
2633 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 3161 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
2634 ** otherwise an [error code] is returned. 3162 ** otherwise an [error code] is returned.
2635 ** 3163 **
2636 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 3164 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
2637 ** recommended for all new programs. The two older interfaces are retained 3165 ** recommended for all new programs. The two older interfaces are retained
2638 ** for backwards compatibility, but their use is discouraged. 3166 ** for backwards compatibility, but their use is discouraged.
2639 ** ^In the "v2" interfaces, the prepared statement 3167 ** ^In the "v2" interfaces, the prepared statement
2640 ** that is returned (the [sqlite3_stmt] object) contains a copy of the 3168 ** that is returned (the [sqlite3_stmt] object) contains a copy of the
2641 ** original SQL text. This causes the [sqlite3_step()] interface to 3169 ** original SQL text. This causes the [sqlite3_step()] interface to
2642 ** behave differently in three ways: 3170 ** behave differently in three ways:
2643 ** 3171 **
2644 ** <ol> 3172 ** <ol>
2645 ** <li> 3173 ** <li>
2646 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 3174 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
2647 ** always used to do, [sqlite3_step()] will automatically recompile the SQL 3175 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
2648 ** statement and try to run it again. 3176 ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
3177 ** retries will occur before sqlite3_step() gives up and returns an error.
2649 ** </li> 3178 ** </li>
2650 ** 3179 **
2651 ** <li> 3180 ** <li>
2652 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed 3181 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
2653 ** [error codes] or [extended error codes]. ^The legacy behavior was that 3182 ** [error codes] or [extended error codes]. ^The legacy behavior was that
2654 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 3183 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
2655 ** and the application would have to make a second call to [sqlite3_reset()] 3184 ** and the application would have to make a second call to [sqlite3_reset()]
2656 ** in order to find the underlying cause of the problem. With the "v2" prepare 3185 ** in order to find the underlying cause of the problem. With the "v2" prepare
2657 ** interfaces, the underlying reason for the error is returned immediately. 3186 ** interfaces, the underlying reason for the error is returned immediately.
2658 ** </li> 3187 ** </li>
2659 ** 3188 **
2660 ** <li> 3189 ** <li>
2661 ** ^If the specific value bound to [parameter | host parameter] in the 3190 ** ^If the specific value bound to [parameter | host parameter] in the
2662 ** WHERE clause might influence the choice of query plan for a statement, 3191 ** WHERE clause might influence the choice of query plan for a statement,
2663 ** then the statement will be automatically recompiled, as if there had been 3192 ** then the statement will be automatically recompiled, as if there had been
2664 ** a schema change, on the first [sqlite3_step()] call following any change 3193 ** a schema change, on the first [sqlite3_step()] call following any change
2665 ** to the [sqlite3_bind_text | bindings] of that [parameter]. 3194 ** to the [sqlite3_bind_text | bindings] of that [parameter].
2666 ** ^The specific value of WHERE-clause [parameter] might influence the 3195 ** ^The specific value of WHERE-clause [parameter] might influence the
2667 ** choice of query plan if the parameter is the left-hand side of a [LIKE] 3196 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
2668 ** or [GLOB] operator or if the parameter is compared to an indexed column 3197 ** or [GLOB] operator or if the parameter is compared to an indexed column
2669 ** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled. 3198 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
2670 ** the
2671 ** </li> 3199 ** </li>
2672 ** </ol> 3200 ** </ol>
2673 */ 3201 */
2674 SQLITE_API int sqlite3_prepare( 3202 SQLITE_API int sqlite3_prepare(
2675 sqlite3 *db, /* Database handle */ 3203 sqlite3 *db, /* Database handle */
2676 const char *zSql, /* SQL statement, UTF-8 encoded */ 3204 const char *zSql, /* SQL statement, UTF-8 encoded */
2677 int nByte, /* Maximum length of zSql in bytes. */ 3205 int nByte, /* Maximum length of zSql in bytes. */
2678 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 3206 sqlite3_stmt **ppStmt, /* OUT: Statement handle */
2679 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 3207 const char **pzTail /* OUT: Pointer to unused portion of zSql */
2680 ); 3208 );
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 ** since the statements themselves do not actually modify the database but 3262 ** since the statements themselves do not actually modify the database but
2735 ** rather they control the timing of when other statements modify the 3263 ** rather they control the timing of when other statements modify the
2736 ** database. ^The [ATTACH] and [DETACH] statements also cause 3264 ** database. ^The [ATTACH] and [DETACH] statements also cause
2737 ** sqlite3_stmt_readonly() to return true since, while those statements 3265 ** sqlite3_stmt_readonly() to return true since, while those statements
2738 ** change the configuration of a database connection, they do not make 3266 ** change the configuration of a database connection, they do not make
2739 ** changes to the content of the database files on disk. 3267 ** changes to the content of the database files on disk.
2740 */ 3268 */
2741 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 3269 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
2742 3270
2743 /* 3271 /*
3272 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3273 **
3274 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3275 ** [prepared statement] S has been stepped at least once using
3276 ** [sqlite3_step(S)] but has not run to completion and/or has not
3277 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
3278 ** interface returns false if S is a NULL pointer. If S is not a
3279 ** NULL pointer and is not a pointer to a valid [prepared statement]
3280 ** object, then the behavior is undefined and probably undesirable.
3281 **
3282 ** This interface can be used in combination [sqlite3_next_stmt()]
3283 ** to locate all prepared statements associated with a database
3284 ** connection that are in need of being reset. This can be used,
3285 ** for example, in diagnostic routines to search for prepared
3286 ** statements that are holding a transaction open.
3287 */
3288 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
3289
3290 /*
2744 ** CAPI3REF: Dynamically Typed Value Object 3291 ** CAPI3REF: Dynamically Typed Value Object
2745 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 3292 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
2746 ** 3293 **
2747 ** SQLite uses the sqlite3_value object to represent all values 3294 ** SQLite uses the sqlite3_value object to represent all values
2748 ** that can be stored in a database table. SQLite uses dynamic typing 3295 ** that can be stored in a database table. SQLite uses dynamic typing
2749 ** for the values it stores. ^Values stored in sqlite3_value objects 3296 ** for the values it stores. ^Values stored in sqlite3_value objects
2750 ** can be integers, floating point values, strings, BLOBs, or NULL. 3297 ** can be integers, floating point values, strings, BLOBs, or NULL.
2751 ** 3298 **
2752 ** An sqlite3_value object may be either "protected" or "unprotected". 3299 ** An sqlite3_value object may be either "protected" or "unprotected".
2753 ** Some interfaces require a protected sqlite3_value. Other interfaces 3300 ** Some interfaces require a protected sqlite3_value. Other interfaces
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2823 ** ^The leftmost SQL parameter has an index of 1. ^When the same named 3370 ** ^The leftmost SQL parameter has an index of 1. ^When the same named
2824 ** SQL parameter is used more than once, second and subsequent 3371 ** SQL parameter is used more than once, second and subsequent
2825 ** occurrences have the same index as the first occurrence. 3372 ** occurrences have the same index as the first occurrence.
2826 ** ^The index for named parameters can be looked up using the 3373 ** ^The index for named parameters can be looked up using the
2827 ** [sqlite3_bind_parameter_index()] API if desired. ^The index 3374 ** [sqlite3_bind_parameter_index()] API if desired. ^The index
2828 ** for "?NNN" parameters is the value of NNN. 3375 ** for "?NNN" parameters is the value of NNN.
2829 ** ^The NNN value must be between 1 and the [sqlite3_limit()] 3376 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
2830 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). 3377 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
2831 ** 3378 **
2832 ** ^The third argument is the value to bind to the parameter. 3379 ** ^The third argument is the value to bind to the parameter.
3380 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3381 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
3382 ** is ignored and the end result is the same as sqlite3_bind_null().
2833 ** 3383 **
2834 ** ^(In those routines that have a fourth argument, its value is the 3384 ** ^(In those routines that have a fourth argument, its value is the
2835 ** number of bytes in the parameter. To be clear: the value is the 3385 ** number of bytes in the parameter. To be clear: the value is the
2836 ** number of <u>bytes</u> in the value, not the number of characters.)^ 3386 ** number of <u>bytes</u> in the value, not the number of characters.)^
2837 ** ^If the fourth parameter is negative, the length of the string is 3387 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3388 ** is negative, then the length of the string is
2838 ** the number of bytes up to the first zero terminator. 3389 ** the number of bytes up to the first zero terminator.
3390 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3391 ** the behavior is undefined.
3392 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3393 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
3394 ** that parameter must be the byte offset
3395 ** where the NUL terminator would occur assuming the string were NUL
3396 ** terminated. If any NUL characters occur at byte offsets less than
3397 ** the value of the fourth parameter then the resulting string value will
3398 ** contain embedded NULs. The result of expressions involving strings
3399 ** with embedded NULs is undefined.
2839 ** 3400 **
2840 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and 3401 ** ^The fifth argument to the BLOB and string binding interfaces
2841 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or 3402 ** is a destructor used to dispose of the BLOB or
2842 ** string after SQLite has finished with it. ^The destructor is called 3403 ** string after SQLite has finished with it. ^The destructor is called
2843 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(), 3404 ** to dispose of the BLOB or string even if the call to bind API fails.
2844 ** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
2845 ** ^If the fifth argument is 3405 ** ^If the fifth argument is
2846 ** the special value [SQLITE_STATIC], then SQLite assumes that the 3406 ** the special value [SQLITE_STATIC], then SQLite assumes that the
2847 ** information is in static, unmanaged space and does not need to be freed. 3407 ** information is in static, unmanaged space and does not need to be freed.
2848 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then 3408 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
2849 ** SQLite makes its own private copy of the data immediately, before 3409 ** SQLite makes its own private copy of the data immediately, before
2850 ** the sqlite3_bind_*() routine returns. 3410 ** the sqlite3_bind_*() routine returns.
2851 ** 3411 **
3412 ** ^The sixth argument to sqlite3_bind_text64() must be one of
3413 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
3414 ** to specify the encoding of the text in the third parameter. If
3415 ** the sixth argument to sqlite3_bind_text64() is not one of the
3416 ** allowed values shown above, or if the text encoding is different
3417 ** from the encoding specified by the sixth parameter, then the behavior
3418 ** is undefined.
3419 **
2852 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 3420 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
2853 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 3421 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
2854 ** (just an integer to hold its size) while it is being processed. 3422 ** (just an integer to hold its size) while it is being processed.
2855 ** Zeroblobs are intended to serve as placeholders for BLOBs whose 3423 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
2856 ** content is later written using 3424 ** content is later written using
2857 ** [sqlite3_blob_open | incremental BLOB I/O] routines. 3425 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
2858 ** ^A negative value for the zeroblob results in a zero-length BLOB. 3426 ** ^A negative value for the zeroblob results in a zero-length BLOB.
2859 ** 3427 **
2860 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 3428 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
2861 ** for the [prepared statement] or with a prepared statement for which 3429 ** for the [prepared statement] or with a prepared statement for which
2862 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 3430 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
2863 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 3431 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
2864 ** routine is passed a [prepared statement] that has been finalized, the 3432 ** routine is passed a [prepared statement] that has been finalized, the
2865 ** result is undefined and probably harmful. 3433 ** result is undefined and probably harmful.
2866 ** 3434 **
2867 ** ^Bindings are not cleared by the [sqlite3_reset()] routine. 3435 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
2868 ** ^Unbound parameters are interpreted as NULL. 3436 ** ^Unbound parameters are interpreted as NULL.
2869 ** 3437 **
2870 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 3438 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
2871 ** [error code] if anything goes wrong. 3439 ** [error code] if anything goes wrong.
3440 ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
3441 ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
3442 ** [SQLITE_MAX_LENGTH].
2872 ** ^[SQLITE_RANGE] is returned if the parameter 3443 ** ^[SQLITE_RANGE] is returned if the parameter
2873 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 3444 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
2874 ** 3445 **
2875 ** See also: [sqlite3_bind_parameter_count()], 3446 ** See also: [sqlite3_bind_parameter_count()],
2876 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 3447 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
2877 */ 3448 */
2878 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*) (void*)); 3449 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*) (void*));
3450 SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint 64,
3451 void(*)(void*));
2879 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); 3452 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
2880 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); 3453 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
2881 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 3454 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
2882 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); 3455 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
2883 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*) (void*)); 3456 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void* ));
2884 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*) (void*)); 3457 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*) (void*));
3458 SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint 64,
3459 void(*)(void*), unsigned char encoding);
2885 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 3460 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
2886 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 3461 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
2887 3462
2888 /* 3463 /*
2889 ** CAPI3REF: Number Of SQL Parameters 3464 ** CAPI3REF: Number Of SQL Parameters
2890 ** 3465 **
2891 ** ^This routine can be used to find the number of [SQL parameters] 3466 ** ^This routine can be used to find the number of [SQL parameters]
2892 ** in a [prepared statement]. SQL parameters are tokens of the 3467 ** in a [prepared statement]. SQL parameters are tokens of the
2893 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 3468 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
2894 ** placeholders for values that are [sqlite3_bind_blob | bound] 3469 ** placeholders for values that are [sqlite3_bind_blob | bound]
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3097 ** interface will continue to be supported. 3672 ** interface will continue to be supported.
3098 ** 3673 **
3099 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 3674 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
3100 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 3675 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
3101 ** ^With the "v2" interface, any of the other [result codes] or 3676 ** ^With the "v2" interface, any of the other [result codes] or
3102 ** [extended result codes] might be returned as well. 3677 ** [extended result codes] might be returned as well.
3103 ** 3678 **
3104 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 3679 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
3105 ** database locks it needs to do its job. ^If the statement is a [COMMIT] 3680 ** database locks it needs to do its job. ^If the statement is a [COMMIT]
3106 ** or occurs outside of an explicit transaction, then you can retry the 3681 ** or occurs outside of an explicit transaction, then you can retry the
3107 ** statement. If the statement is not a [COMMIT] and occurs within a 3682 ** statement. If the statement is not a [COMMIT] and occurs within an
3108 ** explicit transaction then you should rollback the transaction before 3683 ** explicit transaction then you should rollback the transaction before
3109 ** continuing. 3684 ** continuing.
3110 ** 3685 **
3111 ** ^[SQLITE_DONE] means that the statement has finished executing 3686 ** ^[SQLITE_DONE] means that the statement has finished executing
3112 ** successfully. sqlite3_step() should not be called again on this virtual 3687 ** successfully. sqlite3_step() should not be called again on this virtual
3113 ** machine without first calling [sqlite3_reset()] to reset the virtual 3688 ** machine without first calling [sqlite3_reset()] to reset the virtual
3114 ** machine back to its initial state. 3689 ** machine back to its initial state.
3115 ** 3690 **
3116 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 3691 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
3117 ** is returned each time a new row of data is ready for processing by the 3692 ** is returned each time a new row of data is ready for processing by the
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3162 3737
3163 /* 3738 /*
3164 ** CAPI3REF: Number of columns in a result set 3739 ** CAPI3REF: Number of columns in a result set
3165 ** 3740 **
3166 ** ^The sqlite3_data_count(P) interface returns the number of columns in the 3741 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
3167 ** current row of the result set of [prepared statement] P. 3742 ** current row of the result set of [prepared statement] P.
3168 ** ^If prepared statement P does not have results ready to return 3743 ** ^If prepared statement P does not have results ready to return
3169 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of 3744 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3170 ** interfaces) then sqlite3_data_count(P) returns 0. 3745 ** interfaces) then sqlite3_data_count(P) returns 0.
3171 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. 3746 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
3747 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
3748 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
3749 ** will return non-zero if previous call to [sqlite3_step](P) returned
3750 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
3751 ** where it always returns zero since each step of that multi-step
3752 ** pragma returns 0 columns of data.
3172 ** 3753 **
3173 ** See also: [sqlite3_column_count()] 3754 ** See also: [sqlite3_column_count()]
3174 */ 3755 */
3175 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); 3756 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3176 3757
3177 /* 3758 /*
3178 ** CAPI3REF: Fundamental Datatypes 3759 ** CAPI3REF: Fundamental Datatypes
3179 ** KEYWORDS: SQLITE_TEXT 3760 ** KEYWORDS: SQLITE_TEXT
3180 ** 3761 **
3181 ** ^(Every value in SQLite has one of five fundamental datatypes: 3762 ** ^(Every value in SQLite has one of five fundamental datatypes:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3261 ** the number of bytes in that string. 3842 ** the number of bytes in that string.
3262 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. 3843 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
3263 ** 3844 **
3264 ** ^The values returned by [sqlite3_column_bytes()] and 3845 ** ^The values returned by [sqlite3_column_bytes()] and
3265 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end 3846 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
3266 ** of the string. ^For clarity: the values returned by 3847 ** of the string. ^For clarity: the values returned by
3267 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 3848 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
3268 ** bytes in the string, not the number of characters. 3849 ** bytes in the string, not the number of characters.
3269 ** 3850 **
3270 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 3851 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
3271 ** even empty strings, are always zero terminated. ^The return 3852 ** even empty strings, are always zero-terminated. ^The return
3272 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 3853 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
3273 ** 3854 **
3274 ** ^The object returned by [sqlite3_column_value()] is an 3855 ** ^The object returned by [sqlite3_column_value()] is an
3275 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 3856 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object
3276 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 3857 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
3277 ** If the [unprotected sqlite3_value] object returned by 3858 ** If the [unprotected sqlite3_value] object returned by
3278 ** [sqlite3_column_value()] is used in any other way, including calls 3859 ** [sqlite3_column_value()] is used in any other way, including calls
3279 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 3860 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
3280 ** or [sqlite3_value_bytes()], then the behavior is undefined. 3861 ** or [sqlite3_value_bytes()], then the behavior is undefined.
3281 ** 3862 **
3282 ** These routines attempt to convert the value where appropriate. ^For 3863 ** These routines attempt to convert the value where appropriate. ^For
3283 ** example, if the internal representation is FLOAT and a text result 3864 ** example, if the internal representation is FLOAT and a text result
3284 ** is requested, [sqlite3_snprintf()] is used internally to perform the 3865 ** is requested, [sqlite3_snprintf()] is used internally to perform the
3285 ** conversion automatically. ^(The following table details the conversions 3866 ** conversion automatically. ^(The following table details the conversions
3286 ** that are applied: 3867 ** that are applied:
3287 ** 3868 **
3288 ** <blockquote> 3869 ** <blockquote>
3289 ** <table border="1"> 3870 ** <table border="1">
3290 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 3871 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
3291 ** 3872 **
3292 ** <tr><td> NULL <td> INTEGER <td> Result is 0 3873 ** <tr><td> NULL <td> INTEGER <td> Result is 0
3293 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 3874 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3294 ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer 3875 ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
3295 ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer 3876 ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
3296 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 3877 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
3297 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 3878 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
3298 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 3879 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3299 ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer 3880 ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
3300 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 3881 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3301 ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT 3882 ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
3302 ** <tr><td> TEXT <td> INTEGER <td> Use atoi() 3883 ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
3303 ** <tr><td> TEXT <td> FLOAT <td> Use atof() 3884 ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
3304 ** <tr><td> TEXT <td> BLOB <td> No change 3885 ** <tr><td> TEXT <td> BLOB <td> No change
3305 ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() 3886 ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
3306 ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() 3887 ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
3307 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed 3888 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
3308 ** </table> 3889 ** </table>
3309 ** </blockquote>)^ 3890 ** </blockquote>)^
3310 ** 3891 **
3311 ** The table above makes reference to standard C library functions atoi() 3892 ** The table above makes reference to standard C library functions atoi()
3312 ** and atof(). SQLite does not really use these functions. It has its 3893 ** and atof(). SQLite does not really use these functions. It has its
3313 ** own equivalent internal routines. The atoi() and atof() names are 3894 ** own equivalent internal routines. The atoi() and atof() names are
3314 ** used in the table for brevity and because they are familiar to most 3895 ** used in the table for brevity and because they are familiar to most
3315 ** C programmers. 3896 ** C programmers.
3316 ** 3897 **
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3352 ** into the desired format, then invoke sqlite3_column_bytes() or 3933 ** into the desired format, then invoke sqlite3_column_bytes() or
3353 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 3934 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
3354 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to 3935 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
3355 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 3936 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
3356 ** with calls to sqlite3_column_bytes(). 3937 ** with calls to sqlite3_column_bytes().
3357 ** 3938 **
3358 ** ^The pointers returned are valid until a type conversion occurs as 3939 ** ^The pointers returned are valid until a type conversion occurs as
3359 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 3940 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3360 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings 3941 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3361 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned 3942 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3362 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 3943 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3363 ** [sqlite3_free()]. 3944 ** [sqlite3_free()].
3364 ** 3945 **
3365 ** ^(If a memory allocation error occurs during the evaluation of any 3946 ** ^(If a memory allocation error occurs during the evaluation of any
3366 ** of these routines, a default value is returned. The default value 3947 ** of these routines, a default value is returned. The default value
3367 ** is either the integer 0, the floating point number 0.0, or a NULL 3948 ** is either the integer 0, the floating point number 0.0, or a NULL
3368 ** pointer. Subsequent calls to [sqlite3_errcode()] will return 3949 ** pointer. Subsequent calls to [sqlite3_errcode()] will return
3369 ** [SQLITE_NOMEM].)^ 3950 ** [SQLITE_NOMEM].)^
3370 */ 3951 */
3371 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 3952 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
3372 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 3953 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
3373 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 3954 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
3374 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); 3955 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
3375 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); 3956 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
3376 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 3957 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
3377 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 3958 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
3378 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 3959 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
3379 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); 3960 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
3380 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 3961 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
3381 3962
3382 /* 3963 /*
3383 ** CAPI3REF: Destroy A Prepared Statement Object 3964 ** CAPI3REF: Destroy A Prepared Statement Object
3384 ** 3965 **
3385 ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 3966 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3386 ** ^If the most recent evaluation of the statement encountered no errors or 3967 ** ^If the most recent evaluation of the statement encountered no errors
3387 ** or if the statement is never been evaluated, then sqlite3_finalize() returns 3968 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
3388 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then 3969 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
3389 ** sqlite3_finalize(S) returns the appropriate [error code] or 3970 ** sqlite3_finalize(S) returns the appropriate [error code] or
3390 ** [extended error code]. 3971 ** [extended error code].
3391 ** 3972 **
3392 ** ^The sqlite3_finalize(S) routine can be called at any point during 3973 ** ^The sqlite3_finalize(S) routine can be called at any point during
3393 ** the life cycle of [prepared statement] S: 3974 ** the life cycle of [prepared statement] S:
3394 ** before statement S is ever evaluated, after 3975 ** before statement S is ever evaluated, after
3395 ** one or more calls to [sqlite3_reset()], or after any call 3976 ** one or more calls to [sqlite3_reset()], or after any call
3396 ** to [sqlite3_step()] regardless of whether or not the statement has 3977 ** to [sqlite3_step()] regardless of whether or not the statement has
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3461 ** ^The third parameter (nArg) 4042 ** ^The third parameter (nArg)
3462 ** is the number of arguments that the SQL function or 4043 ** is the number of arguments that the SQL function or
3463 ** aggregate takes. ^If this parameter is -1, then the SQL function or 4044 ** aggregate takes. ^If this parameter is -1, then the SQL function or
3464 ** aggregate may take any number of arguments between 0 and the limit 4045 ** aggregate may take any number of arguments between 0 and the limit
3465 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 4046 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
3466 ** parameter is less than -1 or greater than 127 then the behavior is 4047 ** parameter is less than -1 or greater than 127 then the behavior is
3467 ** undefined. 4048 ** undefined.
3468 ** 4049 **
3469 ** ^The fourth parameter, eTextRep, specifies what 4050 ** ^The fourth parameter, eTextRep, specifies what
3470 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for 4051 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3471 ** its parameters. Every SQL function implementation must be able to work 4052 ** its parameters. The application should set this parameter to
3472 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be 4053 ** [SQLITE_UTF16LE] if the function implementation invokes
3473 ** more efficient with one encoding than another. ^An application may 4054 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
3474 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple 4055 ** implementation invokes [sqlite3_value_text16be()] on an input, or
3475 ** times with the same function but with different values of eTextRep. 4056 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
4057 ** otherwise. ^The same SQL function may be registered multiple times using
4058 ** different preferred text encodings, with different implementations for
4059 ** each encoding.
3476 ** ^When multiple implementations of the same function are available, SQLite 4060 ** ^When multiple implementations of the same function are available, SQLite
3477 ** will pick the one that involves the least amount of data conversion. 4061 ** will pick the one that involves the least amount of data conversion.
3478 ** If there is only a single implementation which does not care what text 4062 **
3479 ** encoding is used, then the fourth argument should be [SQLITE_ANY]. 4063 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
4064 ** to signal that the function will always return the same result given
4065 ** the same inputs within a single SQL statement. Most SQL functions are
4066 ** deterministic. The built-in [random()] SQL function is an example of a
4067 ** function that is not deterministic. The SQLite query planner is able to
4068 ** perform additional optimizations on deterministic functions, so use
4069 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
3480 ** 4070 **
3481 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the 4071 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3482 ** function can gain access to this pointer using [sqlite3_user_data()].)^ 4072 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3483 ** 4073 **
3484 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are 4074 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
3485 ** pointers to C-language functions that implement the SQL function or 4075 ** pointers to C-language functions that implement the SQL function or
3486 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc 4076 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3487 ** callback only; NULL pointers must be passed as the xStep and xFinal 4077 ** callback only; NULL pointers must be passed as the xStep and xFinal
3488 ** parameters. ^An aggregate SQL function requires an implementation of xStep 4078 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3489 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing 4079 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3555 /* 4145 /*
3556 ** CAPI3REF: Text Encodings 4146 ** CAPI3REF: Text Encodings
3557 ** 4147 **
3558 ** These constant define integer codes that represent the various 4148 ** These constant define integer codes that represent the various
3559 ** text encodings supported by SQLite. 4149 ** text encodings supported by SQLite.
3560 */ 4150 */
3561 #define SQLITE_UTF8 1 4151 #define SQLITE_UTF8 1
3562 #define SQLITE_UTF16LE 2 4152 #define SQLITE_UTF16LE 2
3563 #define SQLITE_UTF16BE 3 4153 #define SQLITE_UTF16BE 3
3564 #define SQLITE_UTF16 4 /* Use native byte order */ 4154 #define SQLITE_UTF16 4 /* Use native byte order */
3565 #define SQLITE_ANY 5 /* sqlite3_create_function only */ 4155 #define SQLITE_ANY 5 /* Deprecated */
3566 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 4156 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
3567 4157
3568 /* 4158 /*
4159 ** CAPI3REF: Function Flags
4160 **
4161 ** These constants may be ORed together with the
4162 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4163 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4164 ** [sqlite3_create_function_v2()].
4165 */
4166 #define SQLITE_DETERMINISTIC 0x800
4167
4168 /*
3569 ** CAPI3REF: Deprecated Functions 4169 ** CAPI3REF: Deprecated Functions
3570 ** DEPRECATED 4170 ** DEPRECATED
3571 ** 4171 **
3572 ** These functions are [deprecated]. In order to maintain 4172 ** These functions are [deprecated]. In order to maintain
3573 ** backwards compatibility with older code, these functions continue 4173 ** backwards compatibility with older code, these functions continue
3574 ** to be supported. However, new applications should avoid 4174 ** to be supported. However, new applications should avoid
3575 ** the use of these functions. To help encourage people to avoid 4175 ** the use of these functions. To help encourage people to avoid
3576 ** using these functions, we are not going to tell you what they do. 4176 ** using these functions, we are not going to tell you what they do.
3577 */ 4177 */
3578 #ifndef SQLITE_OMIT_DEPRECATED 4178 #ifndef SQLITE_OMIT_DEPRECATED
3579 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 4179 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
3580 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 4180 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
3581 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite 3_stmt*); 4181 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite 3_stmt*);
3582 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); 4182 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
3583 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 4183 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
3584 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 4,int),void*,sqlite3_int64); 4184 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6 4,int),
4185 void*,sqlite3_int64);
3585 #endif 4186 #endif
3586 4187
3587 /* 4188 /*
3588 ** CAPI3REF: Obtaining SQL Function Parameter Values 4189 ** CAPI3REF: Obtaining SQL Function Parameter Values
3589 ** 4190 **
3590 ** The C-language implementation of SQL functions and aggregates uses 4191 ** The C-language implementation of SQL functions and aggregates uses
3591 ** this set of interface routines to access the parameter values on 4192 ** this set of interface routines to access the parameter values on
3592 ** the function or aggregate. 4193 ** the function or aggregate.
3593 ** 4194 **
3594 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters 4195 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
3595 ** to [sqlite3_create_function()] and [sqlite3_create_function16()] 4196 ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
3596 ** define callbacks that implement the SQL functions and aggregates. 4197 ** define callbacks that implement the SQL functions and aggregates.
3597 ** The 3rd parameter to these callbacks is an array of pointers to 4198 ** The 3rd parameter to these callbacks is an array of pointers to
3598 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for 4199 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
3599 ** each parameter to the SQL function. These routines are used to 4200 ** each parameter to the SQL function. These routines are used to
3600 ** extract values from the [sqlite3_value] objects. 4201 ** extract values from the [sqlite3_value] objects.
3601 ** 4202 **
3602 ** These routines work only with [protected sqlite3_value] objects. 4203 ** These routines work only with [protected sqlite3_value] objects.
3603 ** Any attempt to use these routines on an [unprotected sqlite3_value] 4204 ** Any attempt to use these routines on an [unprotected sqlite3_value]
3604 ** object results in undefined behavior. 4205 ** object results in undefined behavior.
3605 ** 4206 **
3606 ** ^These routines work just like the corresponding [column access functions] 4207 ** ^These routines work just like the corresponding [column access functions]
3607 ** except that these routines take a single [protected sqlite3_value] object 4208 ** except that these routines take a single [protected sqlite3_value] object
3608 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 4209 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
3609 ** 4210 **
3610 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string 4211 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
3611 ** in the native byte-order of the host machine. ^The 4212 ** in the native byte-order of the host machine. ^The
3612 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 4213 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
3613 ** extract UTF-16 strings as big-endian and little-endian respectively. 4214 ** extract UTF-16 strings as big-endian and little-endian respectively.
3614 ** 4215 **
3615 ** ^(The sqlite3_value_numeric_type() interface attempts to apply 4216 ** ^(The sqlite3_value_numeric_type() interface attempts to apply
3616 ** numeric affinity to the value. This means that an attempt is 4217 ** numeric affinity to the value. This means that an attempt is
3617 ** made to convert the value to an integer or floating point. If 4218 ** made to convert the value to an integer or floating point. If
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3654 ** to the new memory. ^On second and subsequent calls to 4255 ** to the new memory. ^On second and subsequent calls to
3655 ** sqlite3_aggregate_context() for the same aggregate function instance, 4256 ** sqlite3_aggregate_context() for the same aggregate function instance,
3656 ** the same buffer is returned. Sqlite3_aggregate_context() is normally 4257 ** the same buffer is returned. Sqlite3_aggregate_context() is normally
3657 ** called once for each invocation of the xStep callback and then one 4258 ** called once for each invocation of the xStep callback and then one
3658 ** last time when the xFinal callback is invoked. ^(When no rows match 4259 ** last time when the xFinal callback is invoked. ^(When no rows match
3659 ** an aggregate query, the xStep() callback of the aggregate function 4260 ** an aggregate query, the xStep() callback of the aggregate function
3660 ** implementation is never called and xFinal() is called exactly once. 4261 ** implementation is never called and xFinal() is called exactly once.
3661 ** In those cases, sqlite3_aggregate_context() might be called for the 4262 ** In those cases, sqlite3_aggregate_context() might be called for the
3662 ** first time from within xFinal().)^ 4263 ** first time from within xFinal().)^
3663 ** 4264 **
3664 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is 4265 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
3665 ** less than or equal to zero or if a memory allocate error occurs. 4266 ** when first called if N is less than or equal to zero or if a memory
4267 ** allocate error occurs.
3666 ** 4268 **
3667 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 4269 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
3668 ** determined by the N parameter on first successful call. Changing the 4270 ** determined by the N parameter on first successful call. Changing the
3669 ** value of N in subsequent call to sqlite3_aggregate_context() within 4271 ** value of N in subsequent call to sqlite3_aggregate_context() within
3670 ** the same aggregate function instance will not resize the memory 4272 ** the same aggregate function instance will not resize the memory
3671 ** allocation.)^ 4273 ** allocation.)^ Within the xFinal callback, it is customary to set
4274 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
4275 ** pointless memory allocations occur.
3672 ** 4276 **
3673 ** ^SQLite automatically frees the memory allocated by 4277 ** ^SQLite automatically frees the memory allocated by
3674 ** sqlite3_aggregate_context() when the aggregate query concludes. 4278 ** sqlite3_aggregate_context() when the aggregate query concludes.
3675 ** 4279 **
3676 ** The first parameter must be a copy of the 4280 ** The first parameter must be a copy of the
3677 ** [sqlite3_context | SQL function context] that is the first parameter 4281 ** [sqlite3_context | SQL function context] that is the first parameter
3678 ** to the xStep or xFinal callback routine that implements the aggregate 4282 ** to the xStep or xFinal callback routine that implements the aggregate
3679 ** function. 4283 ** function.
3680 ** 4284 **
3681 ** This routine must be called from the same thread in which 4285 ** This routine must be called from the same thread in which
(...skipping 22 matching lines...) Expand all
3704 ** the pointer to the [database connection] (the 1st parameter) 4308 ** the pointer to the [database connection] (the 1st parameter)
3705 ** of the [sqlite3_create_function()] 4309 ** of the [sqlite3_create_function()]
3706 ** and [sqlite3_create_function16()] routines that originally 4310 ** and [sqlite3_create_function16()] routines that originally
3707 ** registered the application defined function. 4311 ** registered the application defined function.
3708 */ 4312 */
3709 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 4313 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
3710 4314
3711 /* 4315 /*
3712 ** CAPI3REF: Function Auxiliary Data 4316 ** CAPI3REF: Function Auxiliary Data
3713 ** 4317 **
3714 ** The following two functions may be used by scalar SQL functions to 4318 ** These functions may be used by (non-aggregate) SQL functions to
3715 ** associate metadata with argument values. If the same value is passed to 4319 ** associate metadata with argument values. If the same value is passed to
3716 ** multiple invocations of the same SQL function during query execution, under 4320 ** multiple invocations of the same SQL function during query execution, under
3717 ** some circumstances the associated metadata may be preserved. This may 4321 ** some circumstances the associated metadata may be preserved. An example
3718 ** be used, for example, to add a regular-expression matching scalar 4322 ** of where this might be useful is in a regular-expression matching
3719 ** function. The compiled version of the regular expression is stored as 4323 ** function. The compiled version of the regular expression can be stored as
3720 ** metadata associated with the SQL value passed as the regular expression 4324 ** metadata associated with the pattern string.
3721 ** pattern. The compiled regular expression can be reused on multiple 4325 ** Then as long as the pattern string remains the same,
3722 ** invocations of the same function so that the original pattern string 4326 ** the compiled regular expression can be reused on multiple
3723 ** does not need to be recompiled on each invocation. 4327 ** invocations of the same function.
3724 ** 4328 **
3725 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata 4329 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
3726 ** associated by the sqlite3_set_auxdata() function with the Nth argument 4330 ** associated by the sqlite3_set_auxdata() function with the Nth argument
3727 ** value to the application-defined function. ^If no metadata has been ever 4331 ** value to the application-defined function. ^If there is no metadata
3728 ** been set for the Nth argument of the function, or if the corresponding 4332 ** associated with the function argument, this sqlite3_get_auxdata() interface
3729 ** function parameter has changed since the meta-data was set, 4333 ** returns a NULL pointer.
3730 ** then sqlite3_get_auxdata() returns a NULL pointer.
3731 ** 4334 **
3732 ** ^The sqlite3_set_auxdata() interface saves the metadata 4335 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
3733 ** pointed to by its 3rd parameter as the metadata for the N-th 4336 ** argument of the application-defined function. ^Subsequent
3734 ** argument of the application-defined function. Subsequent 4337 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
3735 ** calls to sqlite3_get_auxdata() might return this data, if it has 4338 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
3736 ** not been destroyed. 4339 ** NULL if the metadata has been discarded.
3737 ** ^If it is not NULL, SQLite will invoke the destructor 4340 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
3738 ** function given by the 4th parameter to sqlite3_set_auxdata() on 4341 ** SQLite will invoke the destructor function X with parameter P exactly
3739 ** the metadata when the corresponding function parameter changes 4342 ** once, when the metadata is discarded.
3740 ** or when the SQL statement completes, whichever comes first. 4343 ** SQLite is free to discard the metadata at any time, including: <ul>
4344 ** <li> when the corresponding function parameter changes, or
4345 ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
4346 ** SQL statement, or
4347 ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or
4348 ** <li> during the original sqlite3_set_auxdata() call when a memory
4349 ** allocation error occurs. </ul>)^
3741 ** 4350 **
3742 ** SQLite is free to call the destructor and drop metadata on any 4351 ** Note the last bullet in particular. The destructor X in
3743 ** parameter of any function at any time. ^The only guarantee is that 4352 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
3744 ** the destructor will be called before the metadata is dropped. 4353 ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()
4354 ** should be called near the end of the function implementation and the
4355 ** function implementation should not make any use of P after
4356 ** sqlite3_set_auxdata() has been called.
3745 ** 4357 **
3746 ** ^(In practice, metadata is preserved between function calls for 4358 ** ^(In practice, metadata is preserved between function calls for
3747 ** expressions that are constant at compile time. This includes literal 4359 ** function parameters that are compile-time constants, including literal
3748 ** values and [parameters].)^ 4360 ** values and [parameters] and expressions composed from the same.)^
3749 ** 4361 **
3750 ** These routines must be called from the same thread in which 4362 ** These routines must be called from the same thread in which
3751 ** the SQL function is running. 4363 ** the SQL function is running.
3752 */ 4364 */
3753 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); 4365 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
3754 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(voi d*)); 4366 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(voi d*));
3755 4367
3756 4368
3757 /* 4369 /*
3758 ** CAPI3REF: Constants Defining Special Destructor Behavior 4370 ** CAPI3REF: Constants Defining Special Destructor Behavior
3759 ** 4371 **
3760 ** These are special values for the destructor that is passed in as the 4372 ** These are special values for the destructor that is passed in as the
3761 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 4373 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor
3762 ** argument is SQLITE_STATIC, it means that the content pointer is constant 4374 ** argument is SQLITE_STATIC, it means that the content pointer is constant
3763 ** and will never change. It does not need to be destroyed. ^The 4375 ** and will never change. It does not need to be destroyed. ^The
3764 ** SQLITE_TRANSIENT value means that the content will likely change in 4376 ** SQLITE_TRANSIENT value means that the content will likely change in
3765 ** the near future and that SQLite should make its own private copy of 4377 ** the near future and that SQLite should make its own private copy of
3766 ** the content before returning. 4378 ** the content before returning.
3767 ** 4379 **
3768 ** The typedef is necessary to work around problems in certain 4380 ** The typedef is necessary to work around problems in certain
3769 ** C++ compilers. See ticket #2191. 4381 ** C++ compilers.
3770 */ 4382 */
3771 typedef void (*sqlite3_destructor_type)(void*); 4383 typedef void (*sqlite3_destructor_type)(void*);
3772 #define SQLITE_STATIC ((sqlite3_destructor_type)0) 4384 #define SQLITE_STATIC ((sqlite3_destructor_type)0)
3773 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 4385 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
3774 4386
3775 /* 4387 /*
3776 ** CAPI3REF: Setting The Result Of An SQL Function 4388 ** CAPI3REF: Setting The Result Of An SQL Function
3777 ** 4389 **
3778 ** These routines are used by the xFunc or xFinal callbacks that 4390 ** These routines are used by the xFunc or xFinal callbacks that
3779 ** implement SQL functions and aggregates. See 4391 ** implement SQL functions and aggregates. See
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3812 ** bytes (not characters) from the 2nd parameter as the error message. 4424 ** bytes (not characters) from the 2nd parameter as the error message.
3813 ** ^The sqlite3_result_error() and sqlite3_result_error16() 4425 ** ^The sqlite3_result_error() and sqlite3_result_error16()
3814 ** routines make a private copy of the error message text before 4426 ** routines make a private copy of the error message text before
3815 ** they return. Hence, the calling function can deallocate or 4427 ** they return. Hence, the calling function can deallocate or
3816 ** modify the text after they return without harm. 4428 ** modify the text after they return without harm.
3817 ** ^The sqlite3_result_error_code() function changes the error code 4429 ** ^The sqlite3_result_error_code() function changes the error code
3818 ** returned by SQLite as a result of an error in a function. ^By default, 4430 ** returned by SQLite as a result of an error in a function. ^By default,
3819 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 4431 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
3820 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 4432 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
3821 ** 4433 **
3822 ** ^The sqlite3_result_toobig() interface causes SQLite to throw an error 4434 ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
3823 ** indicating that a string or BLOB is too long to represent. 4435 ** error indicating that a string or BLOB is too long to represent.
3824 ** 4436 **
3825 ** ^The sqlite3_result_nomem() interface causes SQLite to throw an error 4437 ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
3826 ** indicating that a memory allocation failed. 4438 ** error indicating that a memory allocation failed.
3827 ** 4439 **
3828 ** ^The sqlite3_result_int() interface sets the return value 4440 ** ^The sqlite3_result_int() interface sets the return value
3829 ** of the application-defined function to be the 32-bit signed integer 4441 ** of the application-defined function to be the 32-bit signed integer
3830 ** value given in the 2nd argument. 4442 ** value given in the 2nd argument.
3831 ** ^The sqlite3_result_int64() interface sets the return value 4443 ** ^The sqlite3_result_int64() interface sets the return value
3832 ** of the application-defined function to be the 64-bit signed integer 4444 ** of the application-defined function to be the 64-bit signed integer
3833 ** value given in the 2nd argument. 4445 ** value given in the 2nd argument.
3834 ** 4446 **
3835 ** ^The sqlite3_result_null() interface sets the return value 4447 ** ^The sqlite3_result_null() interface sets the return value
3836 ** of the application-defined function to be NULL. 4448 ** of the application-defined function to be NULL.
3837 ** 4449 **
3838 ** ^The sqlite3_result_text(), sqlite3_result_text16(), 4450 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
3839 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 4451 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
3840 ** set the return value of the application-defined function to be 4452 ** set the return value of the application-defined function to be
3841 ** a text string which is represented as UTF-8, UTF-16 native byte order, 4453 ** a text string which is represented as UTF-8, UTF-16 native byte order,
3842 ** UTF-16 little endian, or UTF-16 big endian, respectively. 4454 ** UTF-16 little endian, or UTF-16 big endian, respectively.
4455 ** ^The sqlite3_result_text64() interface sets the return value of an
4456 ** application-defined function to be a text string in an encoding
4457 ** specified by the fifth (and last) parameter, which must be one
4458 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
3843 ** ^SQLite takes the text result from the application from 4459 ** ^SQLite takes the text result from the application from
3844 ** the 2nd parameter of the sqlite3_result_text* interfaces. 4460 ** the 2nd parameter of the sqlite3_result_text* interfaces.
3845 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 4461 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
3846 ** is negative, then SQLite takes result text from the 2nd parameter 4462 ** is negative, then SQLite takes result text from the 2nd parameter
3847 ** through the first zero character. 4463 ** through the first zero character.
3848 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 4464 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
3849 ** is non-negative, then as many bytes (not characters) of the text 4465 ** is non-negative, then as many bytes (not characters) of the text
3850 ** pointed to by the 2nd parameter are taken as the application-defined 4466 ** pointed to by the 2nd parameter are taken as the application-defined
3851 ** function result. 4467 ** function result. If the 3rd parameter is non-negative, then it
4468 ** must be the byte offset into the string where the NUL terminator would
4469 ** appear if the string where NUL terminated. If any NUL characters occur
4470 ** in the string at a byte offset that is less than the value of the 3rd
4471 ** parameter, then the resulting string will contain embedded NULs and the
4472 ** result of expressions operating on strings with embedded NULs is undefined.
3852 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 4473 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
3853 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 4474 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
3854 ** function as the destructor on the text or BLOB result when it has 4475 ** function as the destructor on the text or BLOB result when it has
3855 ** finished using that result. 4476 ** finished using that result.
3856 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 4477 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
3857 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 4478 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
3858 ** assumes that the text or BLOB result is in constant space and does not 4479 ** assumes that the text or BLOB result is in constant space and does not
3859 ** copy the content of the parameter nor call a destructor on the content 4480 ** copy the content of the parameter nor call a destructor on the content
3860 ** when it has finished using that result. 4481 ** when it has finished using that result.
3861 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 4482 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
3862 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 4483 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
3863 ** then SQLite makes a copy of the result into space obtained from 4484 ** then SQLite makes a copy of the result into space obtained from
3864 ** from [sqlite3_malloc()] before it returns. 4485 ** from [sqlite3_malloc()] before it returns.
3865 ** 4486 **
3866 ** ^The sqlite3_result_value() interface sets the result of 4487 ** ^The sqlite3_result_value() interface sets the result of
3867 ** the application-defined function to be a copy the 4488 ** the application-defined function to be a copy the
3868 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 4489 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The
3869 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 4490 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
3870 ** so that the [sqlite3_value] specified in the parameter may change or 4491 ** so that the [sqlite3_value] specified in the parameter may change or
3871 ** be deallocated after sqlite3_result_value() returns without harm. 4492 ** be deallocated after sqlite3_result_value() returns without harm.
3872 ** ^A [protected sqlite3_value] object may always be used where an 4493 ** ^A [protected sqlite3_value] object may always be used where an
3873 ** [unprotected sqlite3_value] object is required, so either 4494 ** [unprotected sqlite3_value] object is required, so either
3874 ** kind of [sqlite3_value] object can be used with this interface. 4495 ** kind of [sqlite3_value] object can be used with this interface.
3875 ** 4496 **
3876 ** If these routines are called from within the different thread 4497 ** If these routines are called from within the different thread
3877 ** than the one containing the application-defined function that received 4498 ** than the one containing the application-defined function that received
3878 ** the [sqlite3_context] pointer, the results are undefined. 4499 ** the [sqlite3_context] pointer, the results are undefined.
3879 */ 4500 */
3880 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)( void*)); 4501 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)( void*));
4502 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint6 4,void(*)(void*));
3881 SQLITE_API void sqlite3_result_double(sqlite3_context*, double); 4503 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
3882 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); 4504 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
3883 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); 4505 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
3884 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); 4506 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
3885 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); 4507 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
3886 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); 4508 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
3887 SQLITE_API void sqlite3_result_int(sqlite3_context*, int); 4509 SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
3888 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 4510 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
3889 SQLITE_API void sqlite3_result_null(sqlite3_context*); 4511 SQLITE_API void sqlite3_result_null(sqlite3_context*);
3890 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)( void*)); 4512 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)( void*));
4513 SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint 64,
4514 void(*)(void*), unsigned char encoding);
3891 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(* )(void*)); 4515 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(* )(void*));
3892 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void( *)(void*)); 4516 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void( *)(void*));
3893 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void( *)(void*)); 4517 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void( *)(void*));
3894 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 4518 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
3895 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); 4519 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
3896 4520
3897 /* 4521 /*
3898 ** CAPI3REF: Define New Collating Sequences 4522 ** CAPI3REF: Define New Collating Sequences
3899 ** 4523 **
3900 ** ^These functions add, remove, or modify a [collation] associated 4524 ** ^These functions add, remove, or modify a [collation] associated
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4038 ** Specify the key for an encrypted database. This routine should be 4662 ** Specify the key for an encrypted database. This routine should be
4039 ** called right after sqlite3_open(). 4663 ** called right after sqlite3_open().
4040 ** 4664 **
4041 ** The code to implement this API is not available in the public release 4665 ** The code to implement this API is not available in the public release
4042 ** of SQLite. 4666 ** of SQLite.
4043 */ 4667 */
4044 SQLITE_API int sqlite3_key( 4668 SQLITE_API int sqlite3_key(
4045 sqlite3 *db, /* Database to be rekeyed */ 4669 sqlite3 *db, /* Database to be rekeyed */
4046 const void *pKey, int nKey /* The key */ 4670 const void *pKey, int nKey /* The key */
4047 ); 4671 );
4672 SQLITE_API int sqlite3_key_v2(
4673 sqlite3 *db, /* Database to be rekeyed */
4674 const char *zDbName, /* Name of the database */
4675 const void *pKey, int nKey /* The key */
4676 );
4048 4677
4049 /* 4678 /*
4050 ** Change the key on an open database. If the current database is not 4679 ** Change the key on an open database. If the current database is not
4051 ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the 4680 ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
4052 ** database is decrypted. 4681 ** database is decrypted.
4053 ** 4682 **
4054 ** The code to implement this API is not available in the public release 4683 ** The code to implement this API is not available in the public release
4055 ** of SQLite. 4684 ** of SQLite.
4056 */ 4685 */
4057 SQLITE_API int sqlite3_rekey( 4686 SQLITE_API int sqlite3_rekey(
4058 sqlite3 *db, /* Database to be rekeyed */ 4687 sqlite3 *db, /* Database to be rekeyed */
4059 const void *pKey, int nKey /* The new key */ 4688 const void *pKey, int nKey /* The new key */
4060 ); 4689 );
4690 SQLITE_API int sqlite3_rekey_v2(
4691 sqlite3 *db, /* Database to be rekeyed */
4692 const char *zDbName, /* Name of the database */
4693 const void *pKey, int nKey /* The new key */
4694 );
4061 4695
4062 /* 4696 /*
4063 ** Specify the activation key for a SEE database. Unless 4697 ** Specify the activation key for a SEE database. Unless
4064 ** activated, none of the SEE routines will work. 4698 ** activated, none of the SEE routines will work.
4065 */ 4699 */
4066 SQLITE_API void sqlite3_activate_see( 4700 SQLITE_API void sqlite3_activate_see(
4067 const char *zPassPhrase /* Activation phrase */ 4701 const char *zPassPhrase /* Activation phrase */
4068 ); 4702 );
4069 #endif 4703 #endif
4070 4704
(...skipping 29 matching lines...) Expand all
4100 /* 4734 /*
4101 ** CAPI3REF: Name Of The Folder Holding Temporary Files 4735 ** CAPI3REF: Name Of The Folder Holding Temporary Files
4102 ** 4736 **
4103 ** ^(If this global variable is made to point to a string which is 4737 ** ^(If this global variable is made to point to a string which is
4104 ** the name of a folder (a.k.a. directory), then all temporary files 4738 ** the name of a folder (a.k.a. directory), then all temporary files
4105 ** created by SQLite when using a built-in [sqlite3_vfs | VFS] 4739 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
4106 ** will be placed in that directory.)^ ^If this variable 4740 ** will be placed in that directory.)^ ^If this variable
4107 ** is a NULL pointer, then SQLite performs a search for an appropriate 4741 ** is a NULL pointer, then SQLite performs a search for an appropriate
4108 ** temporary file directory. 4742 ** temporary file directory.
4109 ** 4743 **
4744 ** Applications are strongly discouraged from using this global variable.
4745 ** It is required to set a temporary folder on Windows Runtime (WinRT).
4746 ** But for all other platforms, it is highly recommended that applications
4747 ** neither read nor write this variable. This global variable is a relic
4748 ** that exists for backwards compatibility of legacy applications and should
4749 ** be avoided in new projects.
4750 **
4110 ** It is not safe to read or modify this variable in more than one 4751 ** It is not safe to read or modify this variable in more than one
4111 ** thread at a time. It is not safe to read or modify this variable 4752 ** thread at a time. It is not safe to read or modify this variable
4112 ** if a [database connection] is being used at the same time in a separate 4753 ** if a [database connection] is being used at the same time in a separate
4113 ** thread. 4754 ** thread.
4114 ** It is intended that this variable be set once 4755 ** It is intended that this variable be set once
4115 ** as part of process initialization and before any SQLite interface 4756 ** as part of process initialization and before any SQLite interface
4116 ** routines have been called and that this variable remain unchanged 4757 ** routines have been called and that this variable remain unchanged
4117 ** thereafter. 4758 ** thereafter.
4118 ** 4759 **
4119 ** ^The [temp_store_directory pragma] may modify this variable and cause 4760 ** ^The [temp_store_directory pragma] may modify this variable and cause
4120 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 4761 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
4121 ** the [temp_store_directory pragma] always assumes that any string 4762 ** the [temp_store_directory pragma] always assumes that any string
4122 ** that this variable points to is held in memory obtained from 4763 ** that this variable points to is held in memory obtained from
4123 ** [sqlite3_malloc] and the pragma may attempt to free that memory 4764 ** [sqlite3_malloc] and the pragma may attempt to free that memory
4124 ** using [sqlite3_free]. 4765 ** using [sqlite3_free].
4125 ** Hence, if this variable is modified directly, either it should be 4766 ** Hence, if this variable is modified directly, either it should be
4126 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 4767 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4127 ** or else the use of the [temp_store_directory pragma] should be avoided. 4768 ** or else the use of the [temp_store_directory pragma] should be avoided.
4769 ** Except when requested by the [temp_store_directory pragma], SQLite
4770 ** does not free the memory that sqlite3_temp_directory points to. If
4771 ** the application wants that memory to be freed, it must do
4772 ** so itself, taking care to only do so after all [database connection]
4773 ** objects have been destroyed.
4774 **
4775 ** <b>Note to Windows Runtime users:</b> The temporary directory must be set
4776 ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various
4777 ** features that require the use of temporary files may fail. Here is an
4778 ** example of how to do this using C++ with the Windows Runtime:
4779 **
4780 ** <blockquote><pre>
4781 ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
4782 ** &nbsp; TemporaryFolder->Path->Data();
4783 ** char zPathBuf&#91;MAX_PATH + 1&#93;;
4784 ** memset(zPathBuf, 0, sizeof(zPathBuf));
4785 ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
4786 ** &nbsp; NULL, NULL);
4787 ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
4788 ** </pre></blockquote>
4128 */ 4789 */
4129 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory; 4790 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
4130 4791
4131 /* 4792 /*
4793 ** CAPI3REF: Name Of The Folder Holding Database Files
4794 **
4795 ** ^(If this global variable is made to point to a string which is
4796 ** the name of a folder (a.k.a. directory), then all database files
4797 ** specified with a relative pathname and created or accessed by
4798 ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
4799 ** to be relative to that directory.)^ ^If this variable is a NULL
4800 ** pointer, then SQLite assumes that all database files specified
4801 ** with a relative pathname are relative to the current directory
4802 ** for the process. Only the windows VFS makes use of this global
4803 ** variable; it is ignored by the unix VFS.
4804 **
4805 ** Changing the value of this variable while a database connection is
4806 ** open can result in a corrupt database.
4807 **
4808 ** It is not safe to read or modify this variable in more than one
4809 ** thread at a time. It is not safe to read or modify this variable
4810 ** if a [database connection] is being used at the same time in a separate
4811 ** thread.
4812 ** It is intended that this variable be set once
4813 ** as part of process initialization and before any SQLite interface
4814 ** routines have been called and that this variable remain unchanged
4815 ** thereafter.
4816 **
4817 ** ^The [data_store_directory pragma] may modify this variable and cause
4818 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,
4819 ** the [data_store_directory pragma] always assumes that any string
4820 ** that this variable points to is held in memory obtained from
4821 ** [sqlite3_malloc] and the pragma may attempt to free that memory
4822 ** using [sqlite3_free].
4823 ** Hence, if this variable is modified directly, either it should be
4824 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4825 ** or else the use of the [data_store_directory pragma] should be avoided.
4826 */
4827 SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
4828
4829 /*
4132 ** CAPI3REF: Test For Auto-Commit Mode 4830 ** CAPI3REF: Test For Auto-Commit Mode
4133 ** KEYWORDS: {autocommit mode} 4831 ** KEYWORDS: {autocommit mode}
4134 ** 4832 **
4135 ** ^The sqlite3_get_autocommit() interface returns non-zero or 4833 ** ^The sqlite3_get_autocommit() interface returns non-zero or
4136 ** zero if the given database connection is or is not in autocommit mode, 4834 ** zero if the given database connection is or is not in autocommit mode,
4137 ** respectively. ^Autocommit mode is on by default. 4835 ** respectively. ^Autocommit mode is on by default.
4138 ** ^Autocommit mode is disabled by a [BEGIN] statement. 4836 ** ^Autocommit mode is disabled by a [BEGIN] statement.
4139 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. 4837 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
4140 ** 4838 **
4141 ** If certain kinds of errors occur on a statement within a multi-statement 4839 ** If certain kinds of errors occur on a statement within a multi-statement
(...skipping 15 matching lines...) Expand all
4157 ** ^The sqlite3_db_handle interface returns the [database connection] handle 4855 ** ^The sqlite3_db_handle interface returns the [database connection] handle
4158 ** to which a [prepared statement] belongs. ^The [database connection] 4856 ** to which a [prepared statement] belongs. ^The [database connection]
4159 ** returned by sqlite3_db_handle is the same [database connection] 4857 ** returned by sqlite3_db_handle is the same [database connection]
4160 ** that was the first argument 4858 ** that was the first argument
4161 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 4859 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
4162 ** create the statement in the first place. 4860 ** create the statement in the first place.
4163 */ 4861 */
4164 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 4862 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
4165 4863
4166 /* 4864 /*
4865 ** CAPI3REF: Return The Filename For A Database Connection
4866 **
4867 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
4868 ** associated with database N of connection D. ^The main database file
4869 ** has the name "main". If there is no attached database N on the database
4870 ** connection D, or if database N is a temporary or in-memory database, then
4871 ** a NULL pointer is returned.
4872 **
4873 ** ^The filename returned by this function is the output of the
4874 ** xFullPathname method of the [VFS]. ^In other words, the filename
4875 ** will be an absolute pathname, even if the filename used
4876 ** to open the database originally was a URI or relative pathname.
4877 */
4878 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
4879
4880 /*
4881 ** CAPI3REF: Determine if a database is read-only
4882 **
4883 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
4884 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
4885 ** the name of a database on connection D.
4886 */
4887 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
4888
4889 /*
4167 ** CAPI3REF: Find the next prepared statement 4890 ** CAPI3REF: Find the next prepared statement
4168 ** 4891 **
4169 ** ^This interface returns a pointer to the next [prepared statement] after 4892 ** ^This interface returns a pointer to the next [prepared statement] after
4170 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 4893 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL
4171 ** then this interface returns a pointer to the first prepared statement 4894 ** then this interface returns a pointer to the first prepared statement
4172 ** associated with the database connection pDb. ^If no prepared statement 4895 ** associated with the database connection pDb. ^If no prepared statement
4173 ** satisfies the conditions of this routine, it returns NULL. 4896 ** satisfies the conditions of this routine, it returns NULL.
4174 ** 4897 **
4175 ** The [database connection] pointer D in a call to 4898 ** The [database connection] pointer D in a call to
4176 ** [sqlite3_next_stmt(D,S)] must refer to an open database 4899 ** [sqlite3_next_stmt(D,S)] must refer to an open database
(...skipping 14 matching lines...) Expand all
4191 ** for the same database connection is overridden. 4914 ** for the same database connection is overridden.
4192 ** ^The pArg argument is passed through to the callback. 4915 ** ^The pArg argument is passed through to the callback.
4193 ** ^If the callback on a commit hook function returns non-zero, 4916 ** ^If the callback on a commit hook function returns non-zero,
4194 ** then the commit is converted into a rollback. 4917 ** then the commit is converted into a rollback.
4195 ** 4918 **
4196 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 4919 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
4197 ** return the P argument from the previous call of the same function 4920 ** return the P argument from the previous call of the same function
4198 ** on the same [database connection] D, or NULL for 4921 ** on the same [database connection] D, or NULL for
4199 ** the first call for each function on D. 4922 ** the first call for each function on D.
4200 ** 4923 **
4924 ** The commit and rollback hook callbacks are not reentrant.
4201 ** The callback implementation must not do anything that will modify 4925 ** The callback implementation must not do anything that will modify
4202 ** the database connection that invoked the callback. Any actions 4926 ** the database connection that invoked the callback. Any actions
4203 ** to modify the database connection must be deferred until after the 4927 ** to modify the database connection must be deferred until after the
4204 ** completion of the [sqlite3_step()] call that triggered the commit 4928 ** completion of the [sqlite3_step()] call that triggered the commit
4205 ** or rollback hook in the first place. 4929 ** or rollback hook in the first place.
4206 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 4930 ** Note that running any other SQL statements, including SELECT statements,
4207 ** database connections for the meaning of "modify" in this paragraph. 4931 ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
4932 ** the database connections for the meaning of "modify" in this paragraph.
4208 ** 4933 **
4209 ** ^Registering a NULL function disables the callback. 4934 ** ^Registering a NULL function disables the callback.
4210 ** 4935 **
4211 ** ^When the commit hook callback routine returns zero, the [COMMIT] 4936 ** ^When the commit hook callback routine returns zero, the [COMMIT]
4212 ** operation is allowed to continue normally. ^If the commit hook 4937 ** operation is allowed to continue normally. ^If the commit hook
4213 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 4938 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
4214 ** ^The rollback hook is invoked on a rollback that results from a commit 4939 ** ^The rollback hook is invoked on a rollback that results from a commit
4215 ** hook returning non-zero, just as it would be with any other rollback. 4940 ** hook returning non-zero, just as it would be with any other rollback.
4216 ** 4941 **
4217 ** ^For the purposes of this API, a transaction is said to have been 4942 ** ^For the purposes of this API, a transaction is said to have been
4218 ** rolled back if an explicit "ROLLBACK" statement is executed, or 4943 ** rolled back if an explicit "ROLLBACK" statement is executed, or
4219 ** an error or constraint causes an implicit rollback to occur. 4944 ** an error or constraint causes an implicit rollback to occur.
4220 ** ^The rollback callback is not invoked if a transaction is 4945 ** ^The rollback callback is not invoked if a transaction is
4221 ** automatically rolled back because the database connection is closed. 4946 ** automatically rolled back because the database connection is closed.
4222 ** 4947 **
4223 ** See also the [sqlite3_update_hook()] interface. 4948 ** See also the [sqlite3_update_hook()] interface.
4224 */ 4949 */
4225 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); 4950 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
4226 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); 4951 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
4227 4952
4228 /* 4953 /*
4229 ** CAPI3REF: Data Change Notification Callbacks 4954 ** CAPI3REF: Data Change Notification Callbacks
4230 ** 4955 **
4231 ** ^The sqlite3_update_hook() interface registers a callback function 4956 ** ^The sqlite3_update_hook() interface registers a callback function
4232 ** with the [database connection] identified by the first argument 4957 ** with the [database connection] identified by the first argument
4233 ** to be invoked whenever a row is updated, inserted or deleted. 4958 ** to be invoked whenever a row is updated, inserted or deleted in
4959 ** a rowid table.
4234 ** ^Any callback set by a previous call to this function 4960 ** ^Any callback set by a previous call to this function
4235 ** for the same database connection is overridden. 4961 ** for the same database connection is overridden.
4236 ** 4962 **
4237 ** ^The second argument is a pointer to the function to invoke when a 4963 ** ^The second argument is a pointer to the function to invoke when a
4238 ** row is updated, inserted or deleted. 4964 ** row is updated, inserted or deleted in a rowid table.
4239 ** ^The first argument to the callback is a copy of the third argument 4965 ** ^The first argument to the callback is a copy of the third argument
4240 ** to sqlite3_update_hook(). 4966 ** to sqlite3_update_hook().
4241 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], 4967 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
4242 ** or [SQLITE_UPDATE], depending on the operation that caused the callback 4968 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
4243 ** to be invoked. 4969 ** to be invoked.
4244 ** ^The third and fourth arguments to the callback contain pointers to the 4970 ** ^The third and fourth arguments to the callback contain pointers to the
4245 ** database and table name containing the affected row. 4971 ** database and table name containing the affected row.
4246 ** ^The final callback parameter is the [rowid] of the row. 4972 ** ^The final callback parameter is the [rowid] of the row.
4247 ** ^In the case of an update, this is the [rowid] after the update takes place. 4973 ** ^In the case of an update, this is the [rowid] after the update takes place.
4248 ** 4974 **
4249 ** ^(The update hook is not invoked when internal system tables are 4975 ** ^(The update hook is not invoked when internal system tables are
4250 ** modified (i.e. sqlite_master and sqlite_sequence).)^ 4976 ** modified (i.e. sqlite_master and sqlite_sequence).)^
4977 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
4251 ** 4978 **
4252 ** ^In the current implementation, the update hook 4979 ** ^In the current implementation, the update hook
4253 ** is not invoked when duplication rows are deleted because of an 4980 ** is not invoked when duplication rows are deleted because of an
4254 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook 4981 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
4255 ** invoked when rows are deleted using the [truncate optimization]. 4982 ** invoked when rows are deleted using the [truncate optimization].
4256 ** The exceptions defined in this paragraph might change in a future 4983 ** The exceptions defined in this paragraph might change in a future
4257 ** release of SQLite. 4984 ** release of SQLite.
4258 ** 4985 **
4259 ** The update hook implementation must not do anything that will modify 4986 ** The update hook implementation must not do anything that will modify
4260 ** the database connection that invoked the update hook. Any actions 4987 ** the database connection that invoked the update hook. Any actions
(...skipping 11 matching lines...) Expand all
4272 ** interfaces. 4999 ** interfaces.
4273 */ 5000 */
4274 SQLITE_API void *sqlite3_update_hook( 5001 SQLITE_API void *sqlite3_update_hook(
4275 sqlite3*, 5002 sqlite3*,
4276 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 5003 void(*)(void *,int ,char const *,char const *,sqlite3_int64),
4277 void* 5004 void*
4278 ); 5005 );
4279 5006
4280 /* 5007 /*
4281 ** CAPI3REF: Enable Or Disable Shared Pager Cache 5008 ** CAPI3REF: Enable Or Disable Shared Pager Cache
4282 ** KEYWORDS: {shared cache}
4283 ** 5009 **
4284 ** ^(This routine enables or disables the sharing of the database cache 5010 ** ^(This routine enables or disables the sharing of the database cache
4285 ** and schema data structures between [database connection | connections] 5011 ** and schema data structures between [database connection | connections]
4286 ** to the same database. Sharing is enabled if the argument is true 5012 ** to the same database. Sharing is enabled if the argument is true
4287 ** and disabled if the argument is false.)^ 5013 ** and disabled if the argument is false.)^
4288 ** 5014 **
4289 ** ^Cache sharing is enabled and disabled for an entire process. 5015 ** ^Cache sharing is enabled and disabled for an entire process.
4290 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, 5016 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
4291 ** sharing was enabled or disabled for each thread separately. 5017 ** sharing was enabled or disabled for each thread separately.
4292 ** 5018 **
4293 ** ^(The cache sharing mode set by this interface effects all subsequent 5019 ** ^(The cache sharing mode set by this interface effects all subsequent
4294 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. 5020 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
4295 ** Existing database connections continue use the sharing mode 5021 ** Existing database connections continue use the sharing mode
4296 ** that was in effect at the time they were opened.)^ 5022 ** that was in effect at the time they were opened.)^
4297 ** 5023 **
4298 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled 5024 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
4299 ** successfully. An [error code] is returned otherwise.)^ 5025 ** successfully. An [error code] is returned otherwise.)^
4300 ** 5026 **
4301 ** ^Shared cache is disabled by default. But this might change in 5027 ** ^Shared cache is disabled by default. But this might change in
4302 ** future releases of SQLite. Applications that care about shared 5028 ** future releases of SQLite. Applications that care about shared
4303 ** cache setting should set it explicitly. 5029 ** cache setting should set it explicitly.
4304 ** 5030 **
5031 ** This interface is threadsafe on processors where writing a
5032 ** 32-bit integer is atomic.
5033 **
4305 ** See Also: [SQLite Shared-Cache Mode] 5034 ** See Also: [SQLite Shared-Cache Mode]
4306 */ 5035 */
4307 SQLITE_API int sqlite3_enable_shared_cache(int); 5036 SQLITE_API int sqlite3_enable_shared_cache(int);
4308 5037
4309 /* 5038 /*
4310 ** CAPI3REF: Attempt To Free Heap Memory 5039 ** CAPI3REF: Attempt To Free Heap Memory
4311 ** 5040 **
4312 ** ^The sqlite3_release_memory() interface attempts to free N bytes 5041 ** ^The sqlite3_release_memory() interface attempts to free N bytes
4313 ** of heap memory by deallocating non-essential memory allocations 5042 ** of heap memory by deallocating non-essential memory allocations
4314 ** held by the database library. Memory used to cache database 5043 ** held by the database library. Memory used to cache database
4315 ** pages to improve performance is an example of non-essential memory. 5044 ** pages to improve performance is an example of non-essential memory.
4316 ** ^sqlite3_release_memory() returns the number of bytes actually freed, 5045 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
4317 ** which might be more or less than the amount requested. 5046 ** which might be more or less than the amount requested.
4318 ** ^The sqlite3_release_memory() routine is a no-op returning zero 5047 ** ^The sqlite3_release_memory() routine is a no-op returning zero
4319 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 5048 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
5049 **
5050 ** See also: [sqlite3_db_release_memory()]
4320 */ 5051 */
4321 SQLITE_API int sqlite3_release_memory(int); 5052 SQLITE_API int sqlite3_release_memory(int);
4322 5053
4323 /* 5054 /*
5055 ** CAPI3REF: Free Memory Used By A Database Connection
5056 **
5057 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5058 ** memory as possible from database connection D. Unlike the
5059 ** [sqlite3_release_memory()] interface, this interface is in effect even
5060 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
5061 ** omitted.
5062 **
5063 ** See also: [sqlite3_release_memory()]
5064 */
5065 SQLITE_API int sqlite3_db_release_memory(sqlite3*);
5066
5067 /*
4324 ** CAPI3REF: Impose A Limit On Heap Size 5068 ** CAPI3REF: Impose A Limit On Heap Size
4325 ** 5069 **
4326 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 5070 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
4327 ** soft limit on the amount of heap memory that may be allocated by SQLite. 5071 ** soft limit on the amount of heap memory that may be allocated by SQLite.
4328 ** ^SQLite strives to keep heap memory utilization below the soft heap 5072 ** ^SQLite strives to keep heap memory utilization below the soft heap
4329 ** limit by reducing the number of pages held in the page cache 5073 ** limit by reducing the number of pages held in the page cache
4330 ** as heap memory usages approaches the limit. 5074 ** as heap memory usages approaches the limit.
4331 ** ^The soft heap limit is "soft" because even though SQLite strives to stay 5075 ** ^The soft heap limit is "soft" because even though SQLite strives to stay
4332 ** below the limit, it will exceed the limit rather than generate 5076 ** below the limit, it will exceed the limit rather than generate
4333 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit 5077 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit
4334 ** is advisory only. 5078 ** is advisory only.
4335 ** 5079 **
4336 ** ^The return value from sqlite3_soft_heap_limit64() is the size of 5080 ** ^The return value from sqlite3_soft_heap_limit64() is the size of
4337 ** the soft heap limit prior to the call. ^If the argument N is negative 5081 ** the soft heap limit prior to the call, or negative in the case of an
5082 ** error. ^If the argument N is negative
4338 ** then no change is made to the soft heap limit. Hence, the current 5083 ** then no change is made to the soft heap limit. Hence, the current
4339 ** size of the soft heap limit can be determined by invoking 5084 ** size of the soft heap limit can be determined by invoking
4340 ** sqlite3_soft_heap_limit64() with a negative argument. 5085 ** sqlite3_soft_heap_limit64() with a negative argument.
4341 ** 5086 **
4342 ** ^If the argument N is zero then the soft heap limit is disabled. 5087 ** ^If the argument N is zero then the soft heap limit is disabled.
4343 ** 5088 **
4344 ** ^(The soft heap limit is not enforced in the current implementation 5089 ** ^(The soft heap limit is not enforced in the current implementation
4345 ** if one or more of following conditions are true: 5090 ** if one or more of following conditions are true:
4346 ** 5091 **
4347 ** <ul> 5092 ** <ul>
4348 ** <li> The soft heap limit is set to zero. 5093 ** <li> The soft heap limit is set to zero.
4349 ** <li> Memory accounting is disabled using a combination of the 5094 ** <li> Memory accounting is disabled using a combination of the
4350 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 5095 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
4351 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 5096 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
4352 ** <li> An alternative page cache implementation is specified using 5097 ** <li> An alternative page cache implementation is specified using
4353 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...). 5098 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
4354 ** <li> The page cache allocates from its own memory pool supplied 5099 ** <li> The page cache allocates from its own memory pool supplied
4355 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 5100 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
4356 ** from the heap. 5101 ** from the heap.
4357 ** </ul>)^ 5102 ** </ul>)^
4358 ** 5103 **
4359 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced 5104 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
4360 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] 5105 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
4361 ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], 5106 ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
4362 ** the soft heap limit is enforced on every memory allocation. Without 5107 ** the soft heap limit is enforced on every memory allocation. Without
4363 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced 5108 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
4456 int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 5201 int *pPrimaryKey, /* OUTPUT: True if column part of PK */
4457 int *pAutoinc /* OUTPUT: True if column is auto-increment */ 5202 int *pAutoinc /* OUTPUT: True if column is auto-increment */
4458 ); 5203 );
4459 5204
4460 /* 5205 /*
4461 ** CAPI3REF: Load An Extension 5206 ** CAPI3REF: Load An Extension
4462 ** 5207 **
4463 ** ^This interface loads an SQLite extension library from the named file. 5208 ** ^This interface loads an SQLite extension library from the named file.
4464 ** 5209 **
4465 ** ^The sqlite3_load_extension() interface attempts to load an 5210 ** ^The sqlite3_load_extension() interface attempts to load an
4466 ** SQLite extension library contained in the file zFile. 5211 ** [SQLite extension] library contained in the file zFile. If
5212 ** the file cannot be loaded directly, attempts are made to load
5213 ** with various operating-system specific extensions added.
5214 ** So for example, if "samplelib" cannot be loaded, then names like
5215 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
5216 ** be tried also.
4467 ** 5217 **
4468 ** ^The entry point is zProc. 5218 ** ^The entry point is zProc.
4469 ** ^zProc may be 0, in which case the name of the entry point 5219 ** ^(zProc may be 0, in which case SQLite will try to come up with an
4470 ** defaults to "sqlite3_extension_init". 5220 ** entry point name on its own. It first tries "sqlite3_extension_init".
5221 ** If that does not work, it constructs a name "sqlite3_X_init" where the
5222 ** X is consists of the lower-case equivalent of all ASCII alphabetic
5223 ** characters in the filename from the last "/" to the first following
5224 ** "." and omitting any initial "lib".)^
4471 ** ^The sqlite3_load_extension() interface returns 5225 ** ^The sqlite3_load_extension() interface returns
4472 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. 5226 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
4473 ** ^If an error occurs and pzErrMsg is not 0, then the 5227 ** ^If an error occurs and pzErrMsg is not 0, then the
4474 ** [sqlite3_load_extension()] interface shall attempt to 5228 ** [sqlite3_load_extension()] interface shall attempt to
4475 ** fill *pzErrMsg with error message text stored in memory 5229 ** fill *pzErrMsg with error message text stored in memory
4476 ** obtained from [sqlite3_malloc()]. The calling function 5230 ** obtained from [sqlite3_malloc()]. The calling function
4477 ** should free this memory by calling [sqlite3_free()]. 5231 ** should free this memory by calling [sqlite3_free()].
4478 ** 5232 **
4479 ** ^Extension loading must be enabled using 5233 ** ^Extension loading must be enabled using
4480 ** [sqlite3_enable_load_extension()] prior to calling this API, 5234 ** [sqlite3_enable_load_extension()] prior to calling this API,
4481 ** otherwise an error will be returned. 5235 ** otherwise an error will be returned.
4482 ** 5236 **
4483 ** See also the [load_extension() SQL function]. 5237 ** See also the [load_extension() SQL function].
4484 */ 5238 */
4485 SQLITE_API int sqlite3_load_extension( 5239 SQLITE_API int sqlite3_load_extension(
4486 sqlite3 *db, /* Load the extension into this database connection */ 5240 sqlite3 *db, /* Load the extension into this database connection */
4487 const char *zFile, /* Name of the shared library containing extension */ 5241 const char *zFile, /* Name of the shared library containing extension */
4488 const char *zProc, /* Entry point. Derived from zFile if 0 */ 5242 const char *zProc, /* Entry point. Derived from zFile if 0 */
4489 char **pzErrMsg /* Put error message here if not 0 */ 5243 char **pzErrMsg /* Put error message here if not 0 */
4490 ); 5244 );
4491 5245
4492 /* 5246 /*
4493 ** CAPI3REF: Enable Or Disable Extension Loading 5247 ** CAPI3REF: Enable Or Disable Extension Loading
4494 ** 5248 **
4495 ** ^So as not to open security holes in older applications that are 5249 ** ^So as not to open security holes in older applications that are
4496 ** unprepared to deal with extension loading, and as a means of disabling 5250 ** unprepared to deal with [extension loading], and as a means of disabling
4497 ** extension loading while evaluating user-entered SQL, the following API 5251 ** [extension loading] while evaluating user-entered SQL, the following API
4498 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. 5252 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
4499 ** 5253 **
4500 ** ^Extension loading is off by default. See ticket #1863. 5254 ** ^Extension loading is off by default.
4501 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 5255 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
4502 ** to turn extension loading on and call it with onoff==0 to turn 5256 ** to turn extension loading on and call it with onoff==0 to turn
4503 ** it back off again. 5257 ** it back off again.
4504 */ 5258 */
4505 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); 5259 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4506 5260
4507 /* 5261 /*
4508 ** CAPI3REF: Automatically Load Statically Linked Extensions 5262 ** CAPI3REF: Automatically Load Statically Linked Extensions
4509 ** 5263 **
4510 ** ^This interface causes the xEntryPoint() function to be invoked for 5264 ** ^This interface causes the xEntryPoint() function to be invoked for
4511 ** each new [database connection] that is created. The idea here is that 5265 ** each new [database connection] that is created. The idea here is that
4512 ** xEntryPoint() is the entry point for a statically linked SQLite extension 5266 ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
4513 ** that is to be automatically loaded into all new database connections. 5267 ** that is to be automatically loaded into all new database connections.
4514 ** 5268 **
4515 ** ^(Even though the function prototype shows that xEntryPoint() takes 5269 ** ^(Even though the function prototype shows that xEntryPoint() takes
4516 ** no arguments and returns void, SQLite invokes xEntryPoint() with three 5270 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
4517 ** arguments and expects and integer result as if the signature of the 5271 ** arguments and expects and integer result as if the signature of the
4518 ** entry point where as follows: 5272 ** entry point where as follows:
4519 ** 5273 **
4520 ** <blockquote><pre> 5274 ** <blockquote><pre>
4521 ** &nbsp; int xEntryPoint( 5275 ** &nbsp; int xEntryPoint(
4522 ** &nbsp; sqlite3 *db, 5276 ** &nbsp; sqlite3 *db,
4523 ** &nbsp; const char **pzErrMsg, 5277 ** &nbsp; const char **pzErrMsg,
4524 ** &nbsp; const struct sqlite3_api_routines *pThunk 5278 ** &nbsp; const struct sqlite3_api_routines *pThunk
4525 ** &nbsp; ); 5279 ** &nbsp; );
4526 ** </pre></blockquote>)^ 5280 ** </pre></blockquote>)^
4527 ** 5281 **
4528 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg 5282 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
4529 ** point to an appropriate error message (obtained from [sqlite3_mprintf()]) 5283 ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
4530 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg 5284 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg
4531 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke 5285 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke
4532 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any 5286 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any
4533 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], 5287 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
4534 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. 5288 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
4535 ** 5289 **
4536 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already 5290 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
4537 ** on the list of automatic extensions is a harmless no-op. ^No entry point 5291 ** on the list of automatic extensions is a harmless no-op. ^No entry point
4538 ** will be called more than once for each database connection that is opened. 5292 ** will be called more than once for each database connection that is opened.
4539 ** 5293 **
4540 ** See also: [sqlite3_reset_auto_extension()]. 5294 ** See also: [sqlite3_reset_auto_extension()]
5295 ** and [sqlite3_cancel_auto_extension()]
4541 */ 5296 */
4542 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void)); 5297 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
4543 5298
4544 /* 5299 /*
5300 ** CAPI3REF: Cancel Automatic Extension Loading
5301 **
5302 ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
5303 ** initialization routine X that was registered using a prior call to
5304 ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]
5305 ** routine returns 1 if initialization routine X was successfully
5306 ** unregistered and it returns 0 if X was not on the list of initialization
5307 ** routines.
5308 */
5309 SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void));
5310
5311 /*
4545 ** CAPI3REF: Reset Automatic Extension Loading 5312 ** CAPI3REF: Reset Automatic Extension Loading
4546 ** 5313 **
4547 ** ^This interface disables all automatic extensions previously 5314 ** ^This interface disables all automatic extensions previously
4548 ** registered using [sqlite3_auto_extension()]. 5315 ** registered using [sqlite3_auto_extension()].
4549 */ 5316 */
4550 SQLITE_API void sqlite3_reset_auto_extension(void); 5317 SQLITE_API void sqlite3_reset_auto_extension(void);
4551 5318
4552 /* 5319 /*
4553 ** The interface to the virtual-table mechanism is currently considered 5320 ** The interface to the virtual-table mechanism is currently considered
4554 ** to be experimental. The interface might change in incompatible ways. 5321 ** to be experimental. The interface might change in incompatible ways.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4603 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); 5370 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
4604 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); 5371 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
4605 int (*xBegin)(sqlite3_vtab *pVTab); 5372 int (*xBegin)(sqlite3_vtab *pVTab);
4606 int (*xSync)(sqlite3_vtab *pVTab); 5373 int (*xSync)(sqlite3_vtab *pVTab);
4607 int (*xCommit)(sqlite3_vtab *pVTab); 5374 int (*xCommit)(sqlite3_vtab *pVTab);
4608 int (*xRollback)(sqlite3_vtab *pVTab); 5375 int (*xRollback)(sqlite3_vtab *pVTab);
4609 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, 5376 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
4610 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), 5377 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
4611 void **ppArg); 5378 void **ppArg);
4612 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); 5379 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
5380 /* The methods above are in version 1 of the sqlite_module object. Those
5381 ** below are for version 2 and greater. */
5382 int (*xSavepoint)(sqlite3_vtab *pVTab, int);
5383 int (*xRelease)(sqlite3_vtab *pVTab, int);
5384 int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
4613 }; 5385 };
4614 5386
4615 /* 5387 /*
4616 ** CAPI3REF: Virtual Table Indexing Information 5388 ** CAPI3REF: Virtual Table Indexing Information
4617 ** KEYWORDS: sqlite3_index_info 5389 ** KEYWORDS: sqlite3_index_info
4618 ** 5390 **
4619 ** The sqlite3_index_info structure and its substructures is used as part 5391 ** The sqlite3_index_info structure and its substructures is used as part
4620 ** of the [virtual table] interface to 5392 ** of the [virtual table] interface to
4621 ** pass information into and receive the reply from the [xBestIndex] 5393 ** pass information into and receive the reply from the [xBestIndex]
4622 ** method of a [virtual table module]. The fields under **Inputs** are the 5394 ** method of a [virtual table module]. The fields under **Inputs** are the
(...skipping 30 matching lines...) Expand all
4653 ** 5425 **
4654 ** ^The idxNum and idxPtr values are recorded and passed into the 5426 ** ^The idxNum and idxPtr values are recorded and passed into the
4655 ** [xFilter] method. 5427 ** [xFilter] method.
4656 ** ^[sqlite3_free()] is used to free idxPtr if and only if 5428 ** ^[sqlite3_free()] is used to free idxPtr if and only if
4657 ** needToFreeIdxPtr is true. 5429 ** needToFreeIdxPtr is true.
4658 ** 5430 **
4659 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in 5431 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
4660 ** the correct order to satisfy the ORDER BY clause so that no separate 5432 ** the correct order to satisfy the ORDER BY clause so that no separate
4661 ** sorting step is required. 5433 ** sorting step is required.
4662 ** 5434 **
4663 ** ^The estimatedCost value is an estimate of the cost of doing the 5435 ** ^The estimatedCost value is an estimate of the cost of a particular
4664 ** particular lookup. A full scan of a table with N entries should have 5436 ** strategy. A cost of N indicates that the cost of the strategy is similar
4665 ** a cost of N. A binary search of a table of N entries should have a 5437 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
4666 ** cost of approximately log(N). 5438 ** indicates that the expense of the operation is similar to that of a
5439 ** binary search on a unique indexed field of an SQLite table with N rows.
5440 **
5441 ** ^The estimatedRows value is an estimate of the number of rows that
5442 ** will be returned by the strategy.
5443 **
5444 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5445 ** structure for SQLite version 3.8.2. If a virtual table extension is
5446 ** used with an SQLite version earlier than 3.8.2, the results of attempting
5447 ** to read or write the estimatedRows field are undefined (but are likely
5448 ** to included crashing the application). The estimatedRows field should
5449 ** therefore only be used if [sqlite3_libversion_number()] returns a
5450 ** value greater than or equal to 3008002.
4667 */ 5451 */
4668 struct sqlite3_index_info { 5452 struct sqlite3_index_info {
4669 /* Inputs */ 5453 /* Inputs */
4670 int nConstraint; /* Number of entries in aConstraint */ 5454 int nConstraint; /* Number of entries in aConstraint */
4671 struct sqlite3_index_constraint { 5455 struct sqlite3_index_constraint {
4672 int iColumn; /* Column on left-hand side of constraint */ 5456 int iColumn; /* Column on left-hand side of constraint */
4673 unsigned char op; /* Constraint operator */ 5457 unsigned char op; /* Constraint operator */
4674 unsigned char usable; /* True if this constraint is usable */ 5458 unsigned char usable; /* True if this constraint is usable */
4675 int iTermOffset; /* Used internally - xBestIndex should ignore */ 5459 int iTermOffset; /* Used internally - xBestIndex should ignore */
4676 } *aConstraint; /* Table of WHERE clause constraints */ 5460 } *aConstraint; /* Table of WHERE clause constraints */
4677 int nOrderBy; /* Number of terms in the ORDER BY clause */ 5461 int nOrderBy; /* Number of terms in the ORDER BY clause */
4678 struct sqlite3_index_orderby { 5462 struct sqlite3_index_orderby {
4679 int iColumn; /* Column number */ 5463 int iColumn; /* Column number */
4680 unsigned char desc; /* True for DESC. False for ASC. */ 5464 unsigned char desc; /* True for DESC. False for ASC. */
4681 } *aOrderBy; /* The ORDER BY clause */ 5465 } *aOrderBy; /* The ORDER BY clause */
4682 /* Outputs */ 5466 /* Outputs */
4683 struct sqlite3_index_constraint_usage { 5467 struct sqlite3_index_constraint_usage {
4684 int argvIndex; /* if >0, constraint is part of argv to xFilter */ 5468 int argvIndex; /* if >0, constraint is part of argv to xFilter */
4685 unsigned char omit; /* Do not code a test for this constraint */ 5469 unsigned char omit; /* Do not code a test for this constraint */
4686 } *aConstraintUsage; 5470 } *aConstraintUsage;
4687 int idxNum; /* Number used to identify the index */ 5471 int idxNum; /* Number used to identify the index */
4688 char *idxStr; /* String, possibly obtained from sqlite3_malloc */ 5472 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
4689 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 5473 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
4690 int orderByConsumed; /* True if output is already ordered */ 5474 int orderByConsumed; /* True if output is already ordered */
4691 double estimatedCost; /* Estimated cost of using this index */ 5475 double estimatedCost; /* Estimated cost of using this index */
5476 /* Fields below are only available in SQLite 3.8.2 and later */
5477 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
4692 }; 5478 };
4693 5479
4694 /* 5480 /*
4695 ** CAPI3REF: Virtual Table Constraint Operator Codes 5481 ** CAPI3REF: Virtual Table Constraint Operator Codes
4696 ** 5482 **
4697 ** These macros defined the allowed values for the 5483 ** These macros defined the allowed values for the
4698 ** [sqlite3_index_info].aConstraint[].op field. Each value represents 5484 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
4699 ** an operator that is part of a constraint term in the wHERE clause of 5485 ** an operator that is part of a constraint term in the wHERE clause of
4700 ** a query that uses a [virtual table]. 5486 ** a query that uses a [virtual table].
4701 */ 5487 */
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
4885 ** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. 5671 ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
4886 ** ^(Changes written into a BLOB prior to the BLOB expiring are not 5672 ** ^(Changes written into a BLOB prior to the BLOB expiring are not
4887 ** rolled back by the expiration of the BLOB. Such changes will eventually 5673 ** rolled back by the expiration of the BLOB. Such changes will eventually
4888 ** commit if the transaction continues to completion.)^ 5674 ** commit if the transaction continues to completion.)^
4889 ** 5675 **
4890 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of 5676 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
4891 ** the opened blob. ^The size of a blob may not be changed by this 5677 ** the opened blob. ^The size of a blob may not be changed by this
4892 ** interface. Use the [UPDATE] SQL command to change the size of a 5678 ** interface. Use the [UPDATE] SQL command to change the size of a
4893 ** blob. 5679 ** blob.
4894 ** 5680 **
5681 ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5682 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5683 **
4895 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces 5684 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
4896 ** and the built-in [zeroblob] SQL function can be used, if desired, 5685 ** and the built-in [zeroblob] SQL function can be used, if desired,
4897 ** to create an empty, zero-filled blob in which to read or write using 5686 ** to create an empty, zero-filled blob in which to read or write using
4898 ** this interface. 5687 ** this interface.
4899 ** 5688 **
4900 ** To avoid a resource leak, every open [BLOB handle] should eventually 5689 ** To avoid a resource leak, every open [BLOB handle] should eventually
4901 ** be released by a call to [sqlite3_blob_close()]. 5690 ** be released by a call to [sqlite3_blob_close()].
4902 */ 5691 */
4903 SQLITE_API int sqlite3_blob_open( 5692 SQLITE_API int sqlite3_blob_open(
4904 sqlite3*, 5693 sqlite3*,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
5079 ** synchronization. Though they are intended for internal 5868 ** synchronization. Though they are intended for internal
5080 ** use by SQLite, code that links against SQLite is 5869 ** use by SQLite, code that links against SQLite is
5081 ** permitted to use any of these routines. 5870 ** permitted to use any of these routines.
5082 ** 5871 **
5083 ** The SQLite source code contains multiple implementations 5872 ** The SQLite source code contains multiple implementations
5084 ** of these mutex routines. An appropriate implementation 5873 ** of these mutex routines. An appropriate implementation
5085 ** is selected automatically at compile-time. ^(The following 5874 ** is selected automatically at compile-time. ^(The following
5086 ** implementations are available in the SQLite core: 5875 ** implementations are available in the SQLite core:
5087 ** 5876 **
5088 ** <ul> 5877 ** <ul>
5089 ** <li> SQLITE_MUTEX_OS2 5878 ** <li> SQLITE_MUTEX_PTHREADS
5090 ** <li> SQLITE_MUTEX_PTHREAD
5091 ** <li> SQLITE_MUTEX_W32 5879 ** <li> SQLITE_MUTEX_W32
5092 ** <li> SQLITE_MUTEX_NOOP 5880 ** <li> SQLITE_MUTEX_NOOP
5093 ** </ul>)^ 5881 ** </ul>)^
5094 ** 5882 **
5095 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 5883 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
5096 ** that does no real locking and is appropriate for use in 5884 ** that does no real locking and is appropriate for use in
5097 ** a single-threaded application. ^The SQLITE_MUTEX_OS2, 5885 ** a single-threaded application. ^The SQLITE_MUTEX_PTHREADS and
5098 ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations 5886 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
5099 ** are appropriate for use on OS/2, Unix, and Windows. 5887 ** and Windows.
5100 ** 5888 **
5101 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 5889 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
5102 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 5890 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
5103 ** implementation is included with the library. In this case the 5891 ** implementation is included with the library. In this case the
5104 ** application must supply a custom mutex implementation using the 5892 ** application must supply a custom mutex implementation using the
5105 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function 5893 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
5106 ** before calling sqlite3_initialize() or any other public sqlite3_ 5894 ** before calling sqlite3_initialize() or any other public sqlite3_
5107 ** function that calls sqlite3_initialize().)^ 5895 ** function that calls sqlite3_initialize().)^
5108 ** 5896 **
5109 ** ^The sqlite3_mutex_alloc() routine allocates a new 5897 ** ^The sqlite3_mutex_alloc() routine allocates a new
5110 ** mutex and returns a pointer to it. ^If it returns NULL 5898 ** mutex and returns a pointer to it. ^If it returns NULL
5111 ** that means that a mutex could not be allocated. ^SQLite 5899 ** that means that a mutex could not be allocated. ^SQLite
5112 ** will unwind its stack and return an error. ^(The argument 5900 ** will unwind its stack and return an error. ^(The argument
5113 ** to sqlite3_mutex_alloc() is one of these integer constants: 5901 ** to sqlite3_mutex_alloc() is one of these integer constants:
5114 ** 5902 **
5115 ** <ul> 5903 ** <ul>
5116 ** <li> SQLITE_MUTEX_FAST 5904 ** <li> SQLITE_MUTEX_FAST
5117 ** <li> SQLITE_MUTEX_RECURSIVE 5905 ** <li> SQLITE_MUTEX_RECURSIVE
5118 ** <li> SQLITE_MUTEX_STATIC_MASTER 5906 ** <li> SQLITE_MUTEX_STATIC_MASTER
5119 ** <li> SQLITE_MUTEX_STATIC_MEM 5907 ** <li> SQLITE_MUTEX_STATIC_MEM
5120 ** <li> SQLITE_MUTEX_STATIC_MEM2 5908 ** <li> SQLITE_MUTEX_STATIC_OPEN
5121 ** <li> SQLITE_MUTEX_STATIC_PRNG 5909 ** <li> SQLITE_MUTEX_STATIC_PRNG
5122 ** <li> SQLITE_MUTEX_STATIC_LRU 5910 ** <li> SQLITE_MUTEX_STATIC_LRU
5123 ** <li> SQLITE_MUTEX_STATIC_LRU2 5911 ** <li> SQLITE_MUTEX_STATIC_PMEM
5912 ** <li> SQLITE_MUTEX_STATIC_APP1
5913 ** <li> SQLITE_MUTEX_STATIC_APP2
5124 ** </ul>)^ 5914 ** </ul>)^
5125 ** 5915 **
5126 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) 5916 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
5127 ** cause sqlite3_mutex_alloc() to create 5917 ** cause sqlite3_mutex_alloc() to create
5128 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 5918 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
5129 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 5919 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
5130 ** The mutex implementation does not need to make a distinction 5920 ** The mutex implementation does not need to make a distinction
5131 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 5921 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
5132 ** not want to. ^SQLite will only request a recursive mutex in 5922 ** not want to. ^SQLite will only request a recursive mutex in
5133 ** cases where it really needs one. ^If a faster non-recursive mutex 5923 ** cases where it really needs one. ^If a faster non-recursive mutex
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
5278 ** never uses these routines except inside an assert() and applications 6068 ** never uses these routines except inside an assert() and applications
5279 ** are advised to follow the lead of the core. ^The SQLite core only 6069 ** are advised to follow the lead of the core. ^The SQLite core only
5280 ** provides implementations for these routines when it is compiled 6070 ** provides implementations for these routines when it is compiled
5281 ** with the SQLITE_DEBUG flag. ^External mutex implementations 6071 ** with the SQLITE_DEBUG flag. ^External mutex implementations
5282 ** are only required to provide these routines if SQLITE_DEBUG is 6072 ** are only required to provide these routines if SQLITE_DEBUG is
5283 ** defined and if NDEBUG is not defined. 6073 ** defined and if NDEBUG is not defined.
5284 ** 6074 **
5285 ** ^These routines should return true if the mutex in their argument 6075 ** ^These routines should return true if the mutex in their argument
5286 ** is held or not held, respectively, by the calling thread. 6076 ** is held or not held, respectively, by the calling thread.
5287 ** 6077 **
5288 ** ^The implementation is not required to provided versions of these 6078 ** ^The implementation is not required to provide versions of these
5289 ** routines that actually work. If the implementation does not provide working 6079 ** routines that actually work. If the implementation does not provide working
5290 ** versions of these routines, it should at least provide stubs that always 6080 ** versions of these routines, it should at least provide stubs that always
5291 ** return true so that one does not get spurious assertion failures. 6081 ** return true so that one does not get spurious assertion failures.
5292 ** 6082 **
5293 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 6083 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
5294 ** the routine should return 1. This seems counter-intuitive since 6084 ** the routine should return 1. This seems counter-intuitive since
5295 ** clearly the mutex cannot be held if it does not exist. But the 6085 ** clearly the mutex cannot be held if it does not exist. But
5296 ** the reason the mutex does not exist is because the build is not 6086 ** the reason the mutex does not exist is because the build is not
5297 ** using mutexes. And we do not want the assert() containing the 6087 ** using mutexes. And we do not want the assert() containing the
5298 ** call to sqlite3_mutex_held() to fail, so a non-zero return is 6088 ** call to sqlite3_mutex_held() to fail, so a non-zero return is
5299 ** the appropriate thing to do. ^The sqlite3_mutex_notheld() 6089 ** the appropriate thing to do. ^The sqlite3_mutex_notheld()
5300 ** interface should also return 1 when given a NULL pointer. 6090 ** interface should also return 1 when given a NULL pointer.
5301 */ 6091 */
5302 #ifndef NDEBUG 6092 #ifndef NDEBUG
5303 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); 6093 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
5304 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); 6094 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
5305 #endif 6095 #endif
(...skipping 11 matching lines...) Expand all
5317 #define SQLITE_MUTEX_FAST 0 6107 #define SQLITE_MUTEX_FAST 0
5318 #define SQLITE_MUTEX_RECURSIVE 1 6108 #define SQLITE_MUTEX_RECURSIVE 1
5319 #define SQLITE_MUTEX_STATIC_MASTER 2 6109 #define SQLITE_MUTEX_STATIC_MASTER 2
5320 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ 6110 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
5321 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ 6111 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
5322 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ 6112 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
5323 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ 6113 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */
5324 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ 6114 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
5325 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ 6115 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
5326 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ 6116 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */
6117 #define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */
6118 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
6119 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
5327 6120
5328 /* 6121 /*
5329 ** CAPI3REF: Retrieve the mutex for a database connection 6122 ** CAPI3REF: Retrieve the mutex for a database connection
5330 ** 6123 **
5331 ** ^This interface returns a pointer the [sqlite3_mutex] object that 6124 ** ^This interface returns a pointer the [sqlite3_mutex] object that
5332 ** serializes access to the [database connection] given in the argument 6125 ** serializes access to the [database connection] given in the argument
5333 ** when the [threading mode] is Serialized. 6126 ** when the [threading mode] is Serialized.
5334 ** ^If the [threading mode] is Single-thread or Multi-thread then this 6127 ** ^If the [threading mode] is Single-thread or Multi-thread then this
5335 ** routine returns a NULL pointer. 6128 ** routine returns a NULL pointer.
5336 */ 6129 */
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5406 #define SQLITE_TESTCTRL_PRNG_RESET 7 6199 #define SQLITE_TESTCTRL_PRNG_RESET 7
5407 #define SQLITE_TESTCTRL_BITVEC_TEST 8 6200 #define SQLITE_TESTCTRL_BITVEC_TEST 8
5408 #define SQLITE_TESTCTRL_FAULT_INSTALL 9 6201 #define SQLITE_TESTCTRL_FAULT_INSTALL 9
5409 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 6202 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
5410 #define SQLITE_TESTCTRL_PENDING_BYTE 11 6203 #define SQLITE_TESTCTRL_PENDING_BYTE 11
5411 #define SQLITE_TESTCTRL_ASSERT 12 6204 #define SQLITE_TESTCTRL_ASSERT 12
5412 #define SQLITE_TESTCTRL_ALWAYS 13 6205 #define SQLITE_TESTCTRL_ALWAYS 13
5413 #define SQLITE_TESTCTRL_RESERVE 14 6206 #define SQLITE_TESTCTRL_RESERVE 14
5414 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 6207 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
5415 #define SQLITE_TESTCTRL_ISKEYWORD 16 6208 #define SQLITE_TESTCTRL_ISKEYWORD 16
5416 #define SQLITE_TESTCTRL_PGHDRSZ 17 6209 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
5417 #define SQLITE_TESTCTRL_SCRATCHMALLOC 18 6210 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
5418 #define SQLITE_TESTCTRL_LAST 18 6211 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
6212 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6213 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6214 #define SQLITE_TESTCTRL_BYTEORDER 22
6215 #define SQLITE_TESTCTRL_ISINIT 23
6216 #define SQLITE_TESTCTRL_SORTER_MMAP 24
6217 #define SQLITE_TESTCTRL_LAST 24
5419 6218
5420 /* 6219 /*
5421 ** CAPI3REF: SQLite Runtime Status 6220 ** CAPI3REF: SQLite Runtime Status
5422 ** 6221 **
5423 ** ^This interface is used to retrieve runtime status information 6222 ** ^This interface is used to retrieve runtime status information
5424 ** about the performance of SQLite, and optionally to reset various 6223 ** about the performance of SQLite, and optionally to reset various
5425 ** highwater marks. ^The first argument is an integer code for 6224 ** highwater marks. ^The first argument is an integer code for
5426 ** the specific parameter to measure. ^(Recognized integer codes 6225 ** the specific parameter to measure. ^(Recognized integer codes
5427 ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^ 6226 ** are of the form [status parameters | SQLITE_STATUS_...].)^
5428 ** ^The current value of the parameter is returned into *pCurrent. 6227 ** ^The current value of the parameter is returned into *pCurrent.
5429 ** ^The highest recorded value is returned in *pHighwater. ^If the 6228 ** ^The highest recorded value is returned in *pHighwater. ^If the
5430 ** resetFlag is true, then the highest record value is reset after 6229 ** resetFlag is true, then the highest record value is reset after
5431 ** *pHighwater is written. ^(Some parameters do not record the highest 6230 ** *pHighwater is written. ^(Some parameters do not record the highest
5432 ** value. For those parameters 6231 ** value. For those parameters
5433 ** nothing is written into *pHighwater and the resetFlag is ignored.)^ 6232 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
5434 ** ^(Other parameters record only the highwater mark and not the current 6233 ** ^(Other parameters record only the highwater mark and not the current
5435 ** value. For these latter parameters nothing is written into *pCurrent.)^ 6234 ** value. For these latter parameters nothing is written into *pCurrent.)^
5436 ** 6235 **
5437 ** ^The sqlite3_status() routine returns SQLITE_OK on success and a 6236 ** ^The sqlite3_status() routine returns SQLITE_OK on success and a
5438 ** non-zero [error code] on failure. 6237 ** non-zero [error code] on failure.
5439 ** 6238 **
5440 ** This routine is threadsafe but is not atomic. This routine can be 6239 ** This routine is threadsafe but is not atomic. This routine can be
5441 ** called while other threads are running the same or different SQLite 6240 ** called while other threads are running the same or different SQLite
5442 ** interfaces. However the values returned in *pCurrent and 6241 ** interfaces. However the values returned in *pCurrent and
5443 ** *pHighwater reflect the status of SQLite at different points in time 6242 ** *pHighwater reflect the status of SQLite at different points in time
5444 ** and it is possible that another thread might change the parameter 6243 ** and it is possible that another thread might change the parameter
5445 ** in between the times when *pCurrent and *pHighwater are written. 6244 ** in between the times when *pCurrent and *pHighwater are written.
5446 ** 6245 **
5447 ** See also: [sqlite3_db_status()] 6246 ** See also: [sqlite3_db_status()]
5448 */ 6247 */
5449 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF lag); 6248 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF lag);
5450 6249
5451 6250
5452 /* 6251 /*
5453 ** CAPI3REF: Status Parameters 6252 ** CAPI3REF: Status Parameters
6253 ** KEYWORDS: {status parameters}
5454 ** 6254 **
5455 ** These integer constants designate various run-time status parameters 6255 ** These integer constants designate various run-time status parameters
5456 ** that can be returned by [sqlite3_status()]. 6256 ** that can be returned by [sqlite3_status()].
5457 ** 6257 **
5458 ** <dl> 6258 ** <dl>
5459 ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> 6259 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
5460 ** <dd>This parameter is the current amount of memory checked out 6260 ** <dd>This parameter is the current amount of memory checked out
5461 ** using [sqlite3_malloc()], either directly or indirectly. The 6261 ** using [sqlite3_malloc()], either directly or indirectly. The
5462 ** figure includes calls made to [sqlite3_malloc()] by the application 6262 ** figure includes calls made to [sqlite3_malloc()] by the application
5463 ** and internal memory usage by the SQLite library. Scratch memory 6263 ** and internal memory usage by the SQLite library. Scratch memory
5464 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache 6264 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
5465 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in 6265 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
5466 ** this parameter. The amount returned is the sum of the allocation 6266 ** this parameter. The amount returned is the sum of the allocation
5467 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ 6267 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
5468 ** 6268 **
5469 ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> 6269 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
5470 ** <dd>This parameter records the largest memory allocation request 6270 ** <dd>This parameter records the largest memory allocation request
5471 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their 6271 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5472 ** internal equivalents). Only the value returned in the 6272 ** internal equivalents). Only the value returned in the
5473 ** *pHighwater parameter to [sqlite3_status()] is of interest. 6273 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5474 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 6274 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5475 ** 6275 **
5476 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> 6276 ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5477 ** <dd>This parameter records the number of separate memory allocations 6277 ** <dd>This parameter records the number of separate memory allocations
5478 ** currently checked out.</dd>)^ 6278 ** currently checked out.</dd>)^
5479 ** 6279 **
5480 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> 6280 ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5481 ** <dd>This parameter returns the number of pages used out of the 6281 ** <dd>This parameter returns the number of pages used out of the
5482 ** [pagecache memory allocator] that was configured using 6282 ** [pagecache memory allocator] that was configured using
5483 ** [SQLITE_CONFIG_PAGECACHE]. The 6283 ** [SQLITE_CONFIG_PAGECACHE]. The
5484 ** value returned is in pages, not in bytes.</dd>)^ 6284 ** value returned is in pages, not in bytes.</dd>)^
5485 ** 6285 **
6286 ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
5486 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> 6287 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5487 ** <dd>This parameter returns the number of bytes of page cache 6288 ** <dd>This parameter returns the number of bytes of page cache
5488 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] 6289 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
5489 ** buffer and where forced to overflow to [sqlite3_malloc()]. The 6290 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
5490 ** returned value includes allocations that overflowed because they 6291 ** returned value includes allocations that overflowed because they
5491 ** where too large (they were larger than the "sz" parameter to 6292 ** where too large (they were larger than the "sz" parameter to
5492 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because 6293 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5493 ** no space was left in the page cache.</dd>)^ 6294 ** no space was left in the page cache.</dd>)^
5494 ** 6295 **
5495 ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> 6296 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
5496 ** <dd>This parameter records the largest memory allocation request 6297 ** <dd>This parameter records the largest memory allocation request
5497 ** handed to [pagecache memory allocator]. Only the value returned in the 6298 ** handed to [pagecache memory allocator]. Only the value returned in the
5498 ** *pHighwater parameter to [sqlite3_status()] is of interest. 6299 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5499 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 6300 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5500 ** 6301 **
5501 ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> 6302 ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
5502 ** <dd>This parameter returns the number of allocations used out of the 6303 ** <dd>This parameter returns the number of allocations used out of the
5503 ** [scratch memory allocator] configured using 6304 ** [scratch memory allocator] configured using
5504 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not 6305 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
5505 ** in bytes. Since a single thread may only have one scratch allocation 6306 ** in bytes. Since a single thread may only have one scratch allocation
5506 ** outstanding at time, this parameter also reports the number of threads 6307 ** outstanding at time, this parameter also reports the number of threads
5507 ** using scratch memory at the same time.</dd>)^ 6308 ** using scratch memory at the same time.</dd>)^
5508 ** 6309 **
5509 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> 6310 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5510 ** <dd>This parameter returns the number of bytes of scratch memory 6311 ** <dd>This parameter returns the number of bytes of scratch memory
5511 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] 6312 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
5512 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values 6313 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
5513 ** returned include overflows because the requested allocation was too 6314 ** returned include overflows because the requested allocation was too
5514 ** larger (that is, because the requested allocation was larger than the 6315 ** larger (that is, because the requested allocation was larger than the
5515 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer 6316 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5516 ** slots were available. 6317 ** slots were available.
5517 ** </dd>)^ 6318 ** </dd>)^
5518 ** 6319 **
5519 ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 6320 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
5520 ** <dd>This parameter records the largest memory allocation request 6321 ** <dd>This parameter records the largest memory allocation request
5521 ** handed to [scratch memory allocator]. Only the value returned in the 6322 ** handed to [scratch memory allocator]. Only the value returned in the
5522 ** *pHighwater parameter to [sqlite3_status()] is of interest. 6323 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5523 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 6324 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5524 ** 6325 **
5525 ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 6326 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
5526 ** <dd>This parameter records the deepest parser stack. It is only 6327 ** <dd>This parameter records the deepest parser stack. It is only
5527 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 6328 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
5528 ** </dl> 6329 ** </dl>
5529 ** 6330 **
5530 ** New status parameters may be added from time to time. 6331 ** New status parameters may be added from time to time.
5531 */ 6332 */
5532 #define SQLITE_STATUS_MEMORY_USED 0 6333 #define SQLITE_STATUS_MEMORY_USED 0
5533 #define SQLITE_STATUS_PAGECACHE_USED 1 6334 #define SQLITE_STATUS_PAGECACHE_USED 1
5534 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 6335 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
5535 #define SQLITE_STATUS_SCRATCH_USED 3 6336 #define SQLITE_STATUS_SCRATCH_USED 3
5536 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 6337 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
5537 #define SQLITE_STATUS_MALLOC_SIZE 5 6338 #define SQLITE_STATUS_MALLOC_SIZE 5
5538 #define SQLITE_STATUS_PARSER_STACK 6 6339 #define SQLITE_STATUS_PARSER_STACK 6
5539 #define SQLITE_STATUS_PAGECACHE_SIZE 7 6340 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5540 #define SQLITE_STATUS_SCRATCH_SIZE 8 6341 #define SQLITE_STATUS_SCRATCH_SIZE 8
5541 #define SQLITE_STATUS_MALLOC_COUNT 9 6342 #define SQLITE_STATUS_MALLOC_COUNT 9
5542 6343
5543 /* 6344 /*
5544 ** CAPI3REF: Database Connection Status 6345 ** CAPI3REF: Database Connection Status
5545 ** 6346 **
5546 ** ^This interface is used to retrieve runtime status information 6347 ** ^This interface is used to retrieve runtime status information
5547 ** about a single [database connection]. ^The first argument is the 6348 ** about a single [database connection]. ^The first argument is the
5548 ** database connection object to be interrogated. ^The second argument 6349 ** database connection object to be interrogated. ^The second argument
5549 ** is an integer constant, taken from the set of 6350 ** is an integer constant, taken from the set of
5550 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that 6351 ** [SQLITE_DBSTATUS options], that
5551 ** determines the parameter to interrogate. The set of 6352 ** determines the parameter to interrogate. The set of
5552 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely 6353 ** [SQLITE_DBSTATUS options] is likely
5553 ** to grow in future releases of SQLite. 6354 ** to grow in future releases of SQLite.
5554 ** 6355 **
5555 ** ^The current value of the requested parameter is written into *pCur 6356 ** ^The current value of the requested parameter is written into *pCur
5556 ** and the highest instantaneous value is written into *pHiwtr. ^If 6357 ** and the highest instantaneous value is written into *pHiwtr. ^If
5557 ** the resetFlg is true, then the highest instantaneous value is 6358 ** the resetFlg is true, then the highest instantaneous value is
5558 ** reset back down to the current value. 6359 ** reset back down to the current value.
5559 ** 6360 **
5560 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a 6361 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
5561 ** non-zero [error code] on failure. 6362 ** non-zero [error code] on failure.
5562 ** 6363 **
5563 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. 6364 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5564 */ 6365 */
5565 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r esetFlg); 6366 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r esetFlg);
5566 6367
5567 /* 6368 /*
5568 ** CAPI3REF: Status Parameters for database connections 6369 ** CAPI3REF: Status Parameters for database connections
6370 ** KEYWORDS: {SQLITE_DBSTATUS options}
5569 ** 6371 **
5570 ** These constants are the available integer "verbs" that can be passed as 6372 ** These constants are the available integer "verbs" that can be passed as
5571 ** the second argument to the [sqlite3_db_status()] interface. 6373 ** the second argument to the [sqlite3_db_status()] interface.
5572 ** 6374 **
5573 ** New verbs may be added in future releases of SQLite. Existing verbs 6375 ** New verbs may be added in future releases of SQLite. Existing verbs
5574 ** might be discontinued. Applications should check the return code from 6376 ** might be discontinued. Applications should check the return code from
5575 ** [sqlite3_db_status()] to make sure that the call worked. 6377 ** [sqlite3_db_status()] to make sure that the call worked.
5576 ** The [sqlite3_db_status()] interface will return a non-zero error code 6378 ** The [sqlite3_db_status()] interface will return a non-zero error code
5577 ** if a discontinued or unsupported verb is invoked. 6379 ** if a discontinued or unsupported verb is invoked.
5578 ** 6380 **
5579 ** <dl> 6381 ** <dl>
5580 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> 6382 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5581 ** <dd>This parameter returns the number of lookaside memory slots currently 6383 ** <dd>This parameter returns the number of lookaside memory slots currently
5582 ** checked out.</dd>)^ 6384 ** checked out.</dd>)^
5583 ** 6385 **
5584 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> 6386 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5585 ** <dd>This parameter returns the number malloc attempts that were 6387 ** <dd>This parameter returns the number malloc attempts that were
5586 ** satisfied using lookaside memory. Only the high-water value is meaningful; 6388 ** satisfied using lookaside memory. Only the high-water value is meaningful;
5587 ** the current value is always zero.)^ 6389 ** the current value is always zero.)^
5588 ** 6390 **
6391 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
5589 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> 6392 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5590 ** <dd>This parameter returns the number malloc attempts that might have 6393 ** <dd>This parameter returns the number malloc attempts that might have
5591 ** been satisfied using lookaside memory but failed due to the amount of 6394 ** been satisfied using lookaside memory but failed due to the amount of
5592 ** memory requested being larger than the lookaside slot size. 6395 ** memory requested being larger than the lookaside slot size.
5593 ** Only the high-water value is meaningful; 6396 ** Only the high-water value is meaningful;
5594 ** the current value is always zero.)^ 6397 ** the current value is always zero.)^
5595 ** 6398 **
6399 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
5596 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> 6400 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5597 ** <dd>This parameter returns the number malloc attempts that might have 6401 ** <dd>This parameter returns the number malloc attempts that might have
5598 ** been satisfied using lookaside memory but failed due to all lookaside 6402 ** been satisfied using lookaside memory but failed due to all lookaside
5599 ** memory already being in use. 6403 ** memory already being in use.
5600 ** Only the high-water value is meaningful; 6404 ** Only the high-water value is meaningful;
5601 ** the current value is always zero.)^ 6405 ** the current value is always zero.)^
5602 ** 6406 **
5603 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> 6407 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5604 ** <dd>This parameter returns the approximate number of of bytes of heap 6408 ** <dd>This parameter returns the approximate number of bytes of heap
5605 ** memory used by all pager caches associated with the database connection.)^ 6409 ** memory used by all pager caches associated with the database connection.)^
5606 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. 6410 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5607 ** 6411 **
5608 ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> 6412 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5609 ** <dd>This parameter returns the approximate number of of bytes of heap 6413 ** <dd>This parameter returns the approximate number of bytes of heap
5610 ** memory used to store the schema for all databases associated 6414 ** memory used to store the schema for all databases associated
5611 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 6415 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5612 ** ^The full amount of memory used by the schemas is reported, even if the 6416 ** ^The full amount of memory used by the schemas is reported, even if the
5613 ** schema memory is shared with other database connections due to 6417 ** schema memory is shared with other database connections due to
5614 ** [shared cache mode] being enabled. 6418 ** [shared cache mode] being enabled.
5615 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. 6419 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5616 ** 6420 **
5617 ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> 6421 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5618 ** <dd>This parameter returns the approximate number of of bytes of heap 6422 ** <dd>This parameter returns the approximate number of bytes of heap
5619 ** and lookaside memory used by all prepared statements associated with 6423 ** and lookaside memory used by all prepared statements associated with
5620 ** the database connection.)^ 6424 ** the database connection.)^
5621 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. 6425 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5622 ** </dd> 6426 ** </dd>
6427 **
6428 ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
6429 ** <dd>This parameter returns the number of pager cache hits that have
6430 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
6431 ** is always 0.
6432 ** </dd>
6433 **
6434 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
6435 ** <dd>This parameter returns the number of pager cache misses that have
6436 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
6437 ** is always 0.
6438 ** </dd>
6439 **
6440 ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
6441 ** <dd>This parameter returns the number of dirty cache entries that have
6442 ** been written to disk. Specifically, the number of pages written to the
6443 ** wal file in wal mode databases, or the number of pages written to the
6444 ** database file in rollback mode databases. Any pages written as part of
6445 ** transaction rollback or database recovery operations are not included.
6446 ** If an IO or other error occurs while writing a page to disk, the effect
6447 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
6448 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
6449 ** </dd>
6450 **
6451 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
6452 ** <dd>This parameter returns zero for the current value if and only if
6453 ** all foreign key constraints (deferred or immediate) have been
6454 ** resolved.)^ ^The highwater mark is always 0.
6455 ** </dd>
5623 ** </dl> 6456 ** </dl>
5624 */ 6457 */
5625 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 6458 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5626 #define SQLITE_DBSTATUS_CACHE_USED 1 6459 #define SQLITE_DBSTATUS_CACHE_USED 1
5627 #define SQLITE_DBSTATUS_SCHEMA_USED 2 6460 #define SQLITE_DBSTATUS_SCHEMA_USED 2
5628 #define SQLITE_DBSTATUS_STMT_USED 3 6461 #define SQLITE_DBSTATUS_STMT_USED 3
5629 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 6462 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5630 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 6463 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5631 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 6464 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5632 #define SQLITE_DBSTATUS_MAX 6 /* Largest defined DBSTATUS */ 6465 #define SQLITE_DBSTATUS_CACHE_HIT 7
6466 #define SQLITE_DBSTATUS_CACHE_MISS 8
6467 #define SQLITE_DBSTATUS_CACHE_WRITE 9
6468 #define SQLITE_DBSTATUS_DEFERRED_FKS 10
6469 #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */
5633 6470
5634 6471
5635 /* 6472 /*
5636 ** CAPI3REF: Prepared Statement Status 6473 ** CAPI3REF: Prepared Statement Status
5637 ** 6474 **
5638 ** ^(Each prepared statement maintains various 6475 ** ^(Each prepared statement maintains various
5639 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number 6476 ** [SQLITE_STMTSTATUS counters] that measure the number
5640 ** of times it has performed specific operations.)^ These counters can 6477 ** of times it has performed specific operations.)^ These counters can
5641 ** be used to monitor the performance characteristics of the prepared 6478 ** be used to monitor the performance characteristics of the prepared
5642 ** statements. For example, if the number of table steps greatly exceeds 6479 ** statements. For example, if the number of table steps greatly exceeds
5643 ** the number of table searches or result rows, that would tend to indicate 6480 ** the number of table searches or result rows, that would tend to indicate
5644 ** that the prepared statement is using a full table scan rather than 6481 ** that the prepared statement is using a full table scan rather than
5645 ** an index. 6482 ** an index.
5646 ** 6483 **
5647 ** ^(This interface is used to retrieve and reset counter values from 6484 ** ^(This interface is used to retrieve and reset counter values from
5648 ** a [prepared statement]. The first argument is the prepared statement 6485 ** a [prepared statement]. The first argument is the prepared statement
5649 ** object to be interrogated. The second argument 6486 ** object to be interrogated. The second argument
5650 ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] 6487 ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
5651 ** to be interrogated.)^ 6488 ** to be interrogated.)^
5652 ** ^The current value of the requested counter is returned. 6489 ** ^The current value of the requested counter is returned.
5653 ** ^If the resetFlg is true, then the counter is reset to zero after this 6490 ** ^If the resetFlg is true, then the counter is reset to zero after this
5654 ** interface call returns. 6491 ** interface call returns.
5655 ** 6492 **
5656 ** See also: [sqlite3_status()] and [sqlite3_db_status()]. 6493 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5657 */ 6494 */
5658 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); 6495 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5659 6496
5660 /* 6497 /*
5661 ** CAPI3REF: Status Parameters for prepared statements 6498 ** CAPI3REF: Status Parameters for prepared statements
6499 ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
5662 ** 6500 **
5663 ** These preprocessor macros define integer codes that name counter 6501 ** These preprocessor macros define integer codes that name counter
5664 ** values associated with the [sqlite3_stmt_status()] interface. 6502 ** values associated with the [sqlite3_stmt_status()] interface.
5665 ** The meanings of the various counters are as follows: 6503 ** The meanings of the various counters are as follows:
5666 ** 6504 **
5667 ** <dl> 6505 ** <dl>
5668 ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> 6506 ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
5669 ** <dd>^This is the number of times that SQLite has stepped forward in 6507 ** <dd>^This is the number of times that SQLite has stepped forward in
5670 ** a table as part of a full table scan. Large numbers for this counter 6508 ** a table as part of a full table scan. Large numbers for this counter
5671 ** may indicate opportunities for performance improvement through 6509 ** may indicate opportunities for performance improvement through
5672 ** careful use of indices.</dd> 6510 ** careful use of indices.</dd>
5673 ** 6511 **
5674 ** <dt>SQLITE_STMTSTATUS_SORT</dt> 6512 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
5675 ** <dd>^This is the number of sort operations that have occurred. 6513 ** <dd>^This is the number of sort operations that have occurred.
5676 ** A non-zero value in this counter may indicate an opportunity to 6514 ** A non-zero value in this counter may indicate an opportunity to
5677 ** improvement performance through careful use of indices.</dd> 6515 ** improvement performance through careful use of indices.</dd>
5678 ** 6516 **
5679 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> 6517 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5680 ** <dd>^This is the number of rows inserted into transient indices that 6518 ** <dd>^This is the number of rows inserted into transient indices that
5681 ** were created automatically in order to help joins run faster. 6519 ** were created automatically in order to help joins run faster.
5682 ** A non-zero value in this counter may indicate an opportunity to 6520 ** A non-zero value in this counter may indicate an opportunity to
5683 ** improvement performance by adding permanent indices that do not 6521 ** improvement performance by adding permanent indices that do not
5684 ** need to be reinitialized each time the statement is run.</dd> 6522 ** need to be reinitialized each time the statement is run.</dd>
5685 ** 6523 **
6524 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6525 ** <dd>^This is the number of virtual machine operations executed
6526 ** by the prepared statement if that number is less than or equal
6527 ** to 2147483647. The number of virtual machine operations can be
6528 ** used as a proxy for the total work done by the prepared statement.
6529 ** If the number of virtual machine operations exceeds 2147483647
6530 ** then the value returned by this statement status code is undefined.
6531 ** </dd>
5686 ** </dl> 6532 ** </dl>
5687 */ 6533 */
5688 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 6534 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5689 #define SQLITE_STMTSTATUS_SORT 2 6535 #define SQLITE_STMTSTATUS_SORT 2
5690 #define SQLITE_STMTSTATUS_AUTOINDEX 3 6536 #define SQLITE_STMTSTATUS_AUTOINDEX 3
6537 #define SQLITE_STMTSTATUS_VM_STEP 4
5691 6538
5692 /* 6539 /*
5693 ** CAPI3REF: Custom Page Cache Object 6540 ** CAPI3REF: Custom Page Cache Object
5694 ** 6541 **
5695 ** The sqlite3_pcache type is opaque. It is implemented by 6542 ** The sqlite3_pcache type is opaque. It is implemented by
5696 ** the pluggable module. The SQLite core has no knowledge of 6543 ** the pluggable module. The SQLite core has no knowledge of
5697 ** its size or internal structure and never deals with the 6544 ** its size or internal structure and never deals with the
5698 ** sqlite3_pcache object except by holding and passing pointers 6545 ** sqlite3_pcache object except by holding and passing pointers
5699 ** to the object. 6546 ** to the object.
5700 ** 6547 **
5701 ** See [sqlite3_pcache_methods] for additional information. 6548 ** See [sqlite3_pcache_methods2] for additional information.
5702 */ 6549 */
5703 typedef struct sqlite3_pcache sqlite3_pcache; 6550 typedef struct sqlite3_pcache sqlite3_pcache;
5704 6551
5705 /* 6552 /*
6553 ** CAPI3REF: Custom Page Cache Object
6554 **
6555 ** The sqlite3_pcache_page object represents a single page in the
6556 ** page cache. The page cache will allocate instances of this
6557 ** object. Various methods of the page cache use pointers to instances
6558 ** of this object as parameters or as their return value.
6559 **
6560 ** See [sqlite3_pcache_methods2] for additional information.
6561 */
6562 typedef struct sqlite3_pcache_page sqlite3_pcache_page;
6563 struct sqlite3_pcache_page {
6564 void *pBuf; /* The content of the page */
6565 void *pExtra; /* Extra information associated with the page */
6566 };
6567
6568 /*
5706 ** CAPI3REF: Application Defined Page Cache. 6569 ** CAPI3REF: Application Defined Page Cache.
5707 ** KEYWORDS: {page cache} 6570 ** KEYWORDS: {page cache}
5708 ** 6571 **
5709 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can 6572 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
5710 ** register an alternative page cache implementation by passing in an 6573 ** register an alternative page cache implementation by passing in an
5711 ** instance of the sqlite3_pcache_methods structure.)^ 6574 ** instance of the sqlite3_pcache_methods2 structure.)^
5712 ** In many applications, most of the heap memory allocated by 6575 ** In many applications, most of the heap memory allocated by
5713 ** SQLite is used for the page cache. 6576 ** SQLite is used for the page cache.
5714 ** By implementing a 6577 ** By implementing a
5715 ** custom page cache using this API, an application can better control 6578 ** custom page cache using this API, an application can better control
5716 ** the amount of memory consumed by SQLite, the way in which 6579 ** the amount of memory consumed by SQLite, the way in which
5717 ** that memory is allocated and released, and the policies used to 6580 ** that memory is allocated and released, and the policies used to
5718 ** determine exactly which parts of a database file are cached and for 6581 ** determine exactly which parts of a database file are cached and for
5719 ** how long. 6582 ** how long.
5720 ** 6583 **
5721 ** The alternative page cache mechanism is an 6584 ** The alternative page cache mechanism is an
5722 ** extreme measure that is only needed by the most demanding applications. 6585 ** extreme measure that is only needed by the most demanding applications.
5723 ** The built-in page cache is recommended for most uses. 6586 ** The built-in page cache is recommended for most uses.
5724 ** 6587 **
5725 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an 6588 ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
5726 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence 6589 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
5727 ** the application may discard the parameter after the call to 6590 ** the application may discard the parameter after the call to
5728 ** [sqlite3_config()] returns.)^ 6591 ** [sqlite3_config()] returns.)^
5729 ** 6592 **
6593 ** [[the xInit() page cache method]]
5730 ** ^(The xInit() method is called once for each effective 6594 ** ^(The xInit() method is called once for each effective
5731 ** call to [sqlite3_initialize()])^ 6595 ** call to [sqlite3_initialize()])^
5732 ** (usually only once during the lifetime of the process). ^(The xInit() 6596 ** (usually only once during the lifetime of the process). ^(The xInit()
5733 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ 6597 ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
5734 ** The intent of the xInit() method is to set up global data structures 6598 ** The intent of the xInit() method is to set up global data structures
5735 ** required by the custom page cache implementation. 6599 ** required by the custom page cache implementation.
5736 ** ^(If the xInit() method is NULL, then the 6600 ** ^(If the xInit() method is NULL, then the
5737 ** built-in default page cache is used instead of the application defined 6601 ** built-in default page cache is used instead of the application defined
5738 ** page cache.)^ 6602 ** page cache.)^
5739 ** 6603 **
6604 ** [[the xShutdown() page cache method]]
5740 ** ^The xShutdown() method is called by [sqlite3_shutdown()]. 6605 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
5741 ** It can be used to clean up 6606 ** It can be used to clean up
5742 ** any outstanding resources before process shutdown, if required. 6607 ** any outstanding resources before process shutdown, if required.
5743 ** ^The xShutdown() method may be NULL. 6608 ** ^The xShutdown() method may be NULL.
5744 ** 6609 **
5745 ** ^SQLite automatically serializes calls to the xInit method, 6610 ** ^SQLite automatically serializes calls to the xInit method,
5746 ** so the xInit method need not be threadsafe. ^The 6611 ** so the xInit method need not be threadsafe. ^The
5747 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 6612 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
5748 ** not need to be threadsafe either. All other methods must be threadsafe 6613 ** not need to be threadsafe either. All other methods must be threadsafe
5749 ** in multithreaded applications. 6614 ** in multithreaded applications.
5750 ** 6615 **
5751 ** ^SQLite will never invoke xInit() more than once without an intervening 6616 ** ^SQLite will never invoke xInit() more than once without an intervening
5752 ** call to xShutdown(). 6617 ** call to xShutdown().
5753 ** 6618 **
6619 ** [[the xCreate() page cache methods]]
5754 ** ^SQLite invokes the xCreate() method to construct a new cache instance. 6620 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
5755 ** SQLite will typically create one cache instance for each open database file, 6621 ** SQLite will typically create one cache instance for each open database file,
5756 ** though this is not guaranteed. ^The 6622 ** though this is not guaranteed. ^The
5757 ** first parameter, szPage, is the size in bytes of the pages that must 6623 ** first parameter, szPage, is the size in bytes of the pages that must
5758 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage 6624 ** be allocated by the cache. ^szPage will always a power of two. ^The
5759 ** will the page size of the database file that is to be cached plus an 6625 ** second parameter szExtra is a number of bytes of extra storage
5760 ** increment (here called "R") of less than 250. SQLite will use the 6626 ** associated with each page cache entry. ^The szExtra parameter will
5761 ** extra R bytes on each page to store metadata about the underlying 6627 ** a number less than 250. SQLite will use the
5762 ** database page on disk. The value of R depends 6628 ** extra szExtra bytes on each page to store metadata about the underlying
6629 ** database page on disk. The value passed into szExtra depends
5763 ** on the SQLite version, the target platform, and how SQLite was compiled. 6630 ** on the SQLite version, the target platform, and how SQLite was compiled.
5764 ** ^(R is constant for a particular build of SQLite. Except, there are two 6631 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
5765 ** distinct values of R when SQLite is compiled with the proprietary 6632 ** created will be used to cache database pages of a file stored on disk, or
5766 ** ZIPVFS extension.)^ ^The second argument to
5767 ** xCreate(), bPurgeable, is true if the cache being created will
5768 ** be used to cache database pages of a file stored on disk, or
5769 ** false if it is used for an in-memory database. The cache implementation 6633 ** false if it is used for an in-memory database. The cache implementation
5770 ** does not have to do anything special based with the value of bPurgeable; 6634 ** does not have to do anything special based with the value of bPurgeable;
5771 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 6635 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
5772 ** never invoke xUnpin() except to deliberately delete a page. 6636 ** never invoke xUnpin() except to deliberately delete a page.
5773 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 6637 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
5774 ** false will always have the "discard" flag set to true. 6638 ** false will always have the "discard" flag set to true.
5775 ** ^Hence, a cache created with bPurgeable false will 6639 ** ^Hence, a cache created with bPurgeable false will
5776 ** never contain any unpinned pages. 6640 ** never contain any unpinned pages.
5777 ** 6641 **
6642 ** [[the xCachesize() page cache method]]
5778 ** ^(The xCachesize() method may be called at any time by SQLite to set the 6643 ** ^(The xCachesize() method may be called at any time by SQLite to set the
5779 ** suggested maximum cache-size (number of pages stored by) the cache 6644 ** suggested maximum cache-size (number of pages stored by) the cache
5780 ** instance passed as the first argument. This is the value configured using 6645 ** instance passed as the first argument. This is the value configured using
5781 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable 6646 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
5782 ** parameter, the implementation is not required to do anything with this 6647 ** parameter, the implementation is not required to do anything with this
5783 ** value; it is advisory only. 6648 ** value; it is advisory only.
5784 ** 6649 **
6650 ** [[the xPagecount() page cache methods]]
5785 ** The xPagecount() method must return the number of pages currently 6651 ** The xPagecount() method must return the number of pages currently
5786 ** stored in the cache, both pinned and unpinned. 6652 ** stored in the cache, both pinned and unpinned.
5787 ** 6653 **
6654 ** [[the xFetch() page cache methods]]
5788 ** The xFetch() method locates a page in the cache and returns a pointer to 6655 ** The xFetch() method locates a page in the cache and returns a pointer to
5789 ** the page, or a NULL pointer. 6656 ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
5790 ** A "page", in this context, means a buffer of szPage bytes aligned at an 6657 ** The pBuf element of the returned sqlite3_pcache_page object will be a
5791 ** 8-byte boundary. The page to be fetched is determined by the key. ^The 6658 ** pointer to a buffer of szPage bytes used to store the content of a
5792 ** mimimum key value is 1. After it has been retrieved using xFetch, the page 6659 ** single database page. The pExtra element of sqlite3_pcache_page will be
5793 ** is considered to be "pinned". 6660 ** a pointer to the szExtra bytes of extra storage that SQLite has requested
6661 ** for each entry in the page cache.
6662 **
6663 ** The page to be fetched is determined by the key. ^The minimum key value
6664 ** is 1. After it has been retrieved using xFetch, the page is considered
6665 ** to be "pinned".
5794 ** 6666 **
5795 ** If the requested page is already in the page cache, then the page cache 6667 ** If the requested page is already in the page cache, then the page cache
5796 ** implementation must return a pointer to the page buffer with its content 6668 ** implementation must return a pointer to the page buffer with its content
5797 ** intact. If the requested page is not already in the cache, then the 6669 ** intact. If the requested page is not already in the cache, then the
5798 ** cache implementation should use the value of the createFlag 6670 ** cache implementation should use the value of the createFlag
5799 ** parameter to help it determined what action to take: 6671 ** parameter to help it determined what action to take:
5800 ** 6672 **
5801 ** <table border=1 width=85% align=center> 6673 ** <table border=1 width=85% align=center>
5802 ** <tr><th> createFlag <th> Behaviour when page is not already in cache 6674 ** <tr><th> createFlag <th> Behavior when page is not already in cache
5803 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. 6675 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
5804 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. 6676 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
5805 ** Otherwise return NULL. 6677 ** Otherwise return NULL.
5806 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return 6678 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return
5807 ** NULL if allocating a new page is effectively impossible. 6679 ** NULL if allocating a new page is effectively impossible.
5808 ** </table> 6680 ** </table>
5809 ** 6681 **
5810 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite 6682 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite
5811 ** will only use a createFlag of 2 after a prior call with a createFlag of 1 6683 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
5812 ** failed.)^ In between the to xFetch() calls, SQLite may 6684 ** failed.)^ In between the to xFetch() calls, SQLite may
5813 ** attempt to unpin one or more cache pages by spilling the content of 6685 ** attempt to unpin one or more cache pages by spilling the content of
5814 ** pinned pages to disk and synching the operating system disk cache. 6686 ** pinned pages to disk and synching the operating system disk cache.
5815 ** 6687 **
6688 ** [[the xUnpin() page cache method]]
5816 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page 6689 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
5817 ** as its second argument. If the third parameter, discard, is non-zero, 6690 ** as its second argument. If the third parameter, discard, is non-zero,
5818 ** then the page must be evicted from the cache. 6691 ** then the page must be evicted from the cache.
5819 ** ^If the discard parameter is 6692 ** ^If the discard parameter is
5820 ** zero, then the page may be discarded or retained at the discretion of 6693 ** zero, then the page may be discarded or retained at the discretion of
5821 ** page cache implementation. ^The page cache implementation 6694 ** page cache implementation. ^The page cache implementation
5822 ** may choose to evict unpinned pages at any time. 6695 ** may choose to evict unpinned pages at any time.
5823 ** 6696 **
5824 ** The cache must not perform any reference counting. A single 6697 ** The cache must not perform any reference counting. A single
5825 ** call to xUnpin() unpins the page regardless of the number of prior calls 6698 ** call to xUnpin() unpins the page regardless of the number of prior calls
5826 ** to xFetch(). 6699 ** to xFetch().
5827 ** 6700 **
6701 ** [[the xRekey() page cache methods]]
5828 ** The xRekey() method is used to change the key value associated with the 6702 ** The xRekey() method is used to change the key value associated with the
5829 ** page passed as the second argument. If the cache 6703 ** page passed as the second argument. If the cache
5830 ** previously contains an entry associated with newKey, it must be 6704 ** previously contains an entry associated with newKey, it must be
5831 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not 6705 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
5832 ** to be pinned. 6706 ** to be pinned.
5833 ** 6707 **
5834 ** When SQLite calls the xTruncate() method, the cache must discard all 6708 ** When SQLite calls the xTruncate() method, the cache must discard all
5835 ** existing cache entries with page numbers (keys) greater than or equal 6709 ** existing cache entries with page numbers (keys) greater than or equal
5836 ** to the value of the iLimit parameter passed to xTruncate(). If any 6710 ** to the value of the iLimit parameter passed to xTruncate(). If any
5837 ** of these pages are pinned, they are implicitly unpinned, meaning that 6711 ** of these pages are pinned, they are implicitly unpinned, meaning that
5838 ** they can be safely discarded. 6712 ** they can be safely discarded.
5839 ** 6713 **
6714 ** [[the xDestroy() page cache method]]
5840 ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 6715 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
5841 ** All resources associated with the specified cache should be freed. ^After 6716 ** All resources associated with the specified cache should be freed. ^After
5842 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 6717 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
5843 ** handle invalid, and will not use it with any other sqlite3_pcache_methods 6718 ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
5844 ** functions. 6719 ** functions.
6720 **
6721 ** [[the xShrink() page cache method]]
6722 ** ^SQLite invokes the xShrink() method when it wants the page cache to
6723 ** free up as much of heap memory as possible. The page cache implementation
6724 ** is not obligated to free any memory, but well-behaved implementations should
6725 ** do their best.
6726 */
6727 typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
6728 struct sqlite3_pcache_methods2 {
6729 int iVersion;
6730 void *pArg;
6731 int (*xInit)(void*);
6732 void (*xShutdown)(void*);
6733 sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
6734 void (*xCachesize)(sqlite3_pcache*, int nCachesize);
6735 int (*xPagecount)(sqlite3_pcache*);
6736 sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
6737 void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
6738 void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,
6739 unsigned oldKey, unsigned newKey);
6740 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
6741 void (*xDestroy)(sqlite3_pcache*);
6742 void (*xShrink)(sqlite3_pcache*);
6743 };
6744
6745 /*
6746 ** This is the obsolete pcache_methods object that has now been replaced
6747 ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is
6748 ** retained in the header file for backwards compatibility only.
5845 */ 6749 */
5846 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 6750 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
5847 struct sqlite3_pcache_methods { 6751 struct sqlite3_pcache_methods {
5848 void *pArg; 6752 void *pArg;
5849 int (*xInit)(void*); 6753 int (*xInit)(void*);
5850 void (*xShutdown)(void*); 6754 void (*xShutdown)(void*);
5851 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 6755 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
5852 void (*xCachesize)(sqlite3_pcache*, int nCachesize); 6756 void (*xCachesize)(sqlite3_pcache*, int nCachesize);
5853 int (*xPagecount)(sqlite3_pcache*); 6757 int (*xPagecount)(sqlite3_pcache*);
5854 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 6758 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
5855 void (*xUnpin)(sqlite3_pcache*, void*, int discard); 6759 void (*xUnpin)(sqlite3_pcache*, void*, int discard);
5856 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 6760 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
5857 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 6761 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
5858 void (*xDestroy)(sqlite3_pcache*); 6762 void (*xDestroy)(sqlite3_pcache*);
5859 }; 6763 };
5860 6764
6765
5861 /* 6766 /*
5862 ** CAPI3REF: Online Backup Object 6767 ** CAPI3REF: Online Backup Object
5863 ** 6768 **
5864 ** The sqlite3_backup object records state information about an ongoing 6769 ** The sqlite3_backup object records state information about an ongoing
5865 ** online backup operation. ^The sqlite3_backup object is created by 6770 ** online backup operation. ^The sqlite3_backup object is created by
5866 ** a call to [sqlite3_backup_init()] and is destroyed by a call to 6771 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5867 ** [sqlite3_backup_finish()]. 6772 ** [sqlite3_backup_finish()].
5868 ** 6773 **
5869 ** See Also: [Using the SQLite Online Backup API] 6774 ** See Also: [Using the SQLite Online Backup API]
5870 */ 6775 */
(...skipping 21 matching lines...) Expand all
5892 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the 6797 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the
5893 ** backup, 6798 ** backup,
5894 ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 6799 ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
5895 ** the data between the two databases, and finally 6800 ** the data between the two databases, and finally
5896 ** <li><b>sqlite3_backup_finish()</b> is called to release all resources 6801 ** <li><b>sqlite3_backup_finish()</b> is called to release all resources
5897 ** associated with the backup operation. 6802 ** associated with the backup operation.
5898 ** </ol>)^ 6803 ** </ol>)^
5899 ** There should be exactly one call to sqlite3_backup_finish() for each 6804 ** There should be exactly one call to sqlite3_backup_finish() for each
5900 ** successful call to sqlite3_backup_init(). 6805 ** successful call to sqlite3_backup_init().
5901 ** 6806 **
5902 ** <b>sqlite3_backup_init()</b> 6807 ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
5903 ** 6808 **
5904 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 6809 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
5905 ** [database connection] associated with the destination database 6810 ** [database connection] associated with the destination database
5906 ** and the database name, respectively. 6811 ** and the database name, respectively.
5907 ** ^The database name is "main" for the main database, "temp" for the 6812 ** ^The database name is "main" for the main database, "temp" for the
5908 ** temporary database, or the name specified after the AS keyword in 6813 ** temporary database, or the name specified after the AS keyword in
5909 ** an [ATTACH] statement for an attached database. 6814 ** an [ATTACH] statement for an attached database.
5910 ** ^The S and M arguments passed to 6815 ** ^The S and M arguments passed to
5911 ** sqlite3_backup_init(D,N,S,M) identify the [database connection] 6816 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
5912 ** and database name of the source database, respectively. 6817 ** and database name of the source database, respectively.
5913 ** ^The source and destination [database connections] (parameters S and D) 6818 ** ^The source and destination [database connections] (parameters S and D)
5914 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with 6819 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
5915 ** an error. 6820 ** an error.
5916 ** 6821 **
5917 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is 6822 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
5918 ** returned and an error code and error message are stored in the 6823 ** returned and an error code and error message are stored in the
5919 ** destination [database connection] D. 6824 ** destination [database connection] D.
5920 ** ^The error code and message for the failed call to sqlite3_backup_init() 6825 ** ^The error code and message for the failed call to sqlite3_backup_init()
5921 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or 6826 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
5922 ** [sqlite3_errmsg16()] functions. 6827 ** [sqlite3_errmsg16()] functions.
5923 ** ^A successful call to sqlite3_backup_init() returns a pointer to an 6828 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
5924 ** [sqlite3_backup] object. 6829 ** [sqlite3_backup] object.
5925 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and 6830 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
5926 ** sqlite3_backup_finish() functions to perform the specified backup 6831 ** sqlite3_backup_finish() functions to perform the specified backup
5927 ** operation. 6832 ** operation.
5928 ** 6833 **
5929 ** <b>sqlite3_backup_step()</b> 6834 ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
5930 ** 6835 **
5931 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 6836 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
5932 ** the source and destination databases specified by [sqlite3_backup] object B. 6837 ** the source and destination databases specified by [sqlite3_backup] object B.
5933 ** ^If N is negative, all remaining source pages are copied. 6838 ** ^If N is negative, all remaining source pages are copied.
5934 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there 6839 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
5935 ** are still more pages to be copied, then the function returns [SQLITE_OK]. 6840 ** are still more pages to be copied, then the function returns [SQLITE_OK].
5936 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages 6841 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
5937 ** from source to destination, then it returns [SQLITE_DONE]. 6842 ** from source to destination, then it returns [SQLITE_DONE].
5938 ** ^If an error occurs while running sqlite3_backup_step(B,N), 6843 ** ^If an error occurs while running sqlite3_backup_step(B,N),
5939 ** then an [error code] is returned. ^As well as [SQLITE_OK] and 6844 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5976 ** ^Because the source database is not locked between calls to 6881 ** ^Because the source database is not locked between calls to
5977 ** sqlite3_backup_step(), the source database may be modified mid-way 6882 ** sqlite3_backup_step(), the source database may be modified mid-way
5978 ** through the backup process. ^If the source database is modified by an 6883 ** through the backup process. ^If the source database is modified by an
5979 ** external process or via a database connection other than the one being 6884 ** external process or via a database connection other than the one being
5980 ** used by the backup operation, then the backup will be automatically 6885 ** used by the backup operation, then the backup will be automatically
5981 ** restarted by the next call to sqlite3_backup_step(). ^If the source 6886 ** restarted by the next call to sqlite3_backup_step(). ^If the source
5982 ** database is modified by the using the same database connection as is used 6887 ** database is modified by the using the same database connection as is used
5983 ** by the backup operation, then the backup database is automatically 6888 ** by the backup operation, then the backup database is automatically
5984 ** updated at the same time. 6889 ** updated at the same time.
5985 ** 6890 **
5986 ** <b>sqlite3_backup_finish()</b> 6891 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
5987 ** 6892 **
5988 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 6893 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
5989 ** application wishes to abandon the backup operation, the application 6894 ** application wishes to abandon the backup operation, the application
5990 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). 6895 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
5991 ** ^The sqlite3_backup_finish() interfaces releases all 6896 ** ^The sqlite3_backup_finish() interfaces releases all
5992 ** resources associated with the [sqlite3_backup] object. 6897 ** resources associated with the [sqlite3_backup] object.
5993 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any 6898 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
5994 ** active write-transaction on the destination database is rolled back. 6899 ** active write-transaction on the destination database is rolled back.
5995 ** The [sqlite3_backup] object is invalid 6900 ** The [sqlite3_backup] object is invalid
5996 ** and may not be used following a call to sqlite3_backup_finish(). 6901 ** and may not be used following a call to sqlite3_backup_finish().
5997 ** 6902 **
5998 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no 6903 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
5999 ** sqlite3_backup_step() errors occurred, regardless or whether or not 6904 ** sqlite3_backup_step() errors occurred, regardless or whether or not
6000 ** sqlite3_backup_step() completed. 6905 ** sqlite3_backup_step() completed.
6001 ** ^If an out-of-memory condition or IO error occurred during any prior 6906 ** ^If an out-of-memory condition or IO error occurred during any prior
6002 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then 6907 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
6003 ** sqlite3_backup_finish() returns the corresponding [error code]. 6908 ** sqlite3_backup_finish() returns the corresponding [error code].
6004 ** 6909 **
6005 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() 6910 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
6006 ** is not a permanent error and does not affect the return value of 6911 ** is not a permanent error and does not affect the return value of
6007 ** sqlite3_backup_finish(). 6912 ** sqlite3_backup_finish().
6008 ** 6913 **
6009 ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b> 6914 ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
6915 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
6010 ** 6916 **
6011 ** ^Each call to sqlite3_backup_step() sets two values inside 6917 ** ^Each call to sqlite3_backup_step() sets two values inside
6012 ** the [sqlite3_backup] object: the number of pages still to be backed 6918 ** the [sqlite3_backup] object: the number of pages still to be backed
6013 ** up and the total number of pages in the source database file. 6919 ** up and the total number of pages in the source database file.
6014 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces 6920 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
6015 ** retrieve these two values, respectively. 6921 ** retrieve these two values, respectively.
6016 ** 6922 **
6017 ** ^The values returned by these functions are only updated by 6923 ** ^The values returned by these functions are only updated by
6018 ** sqlite3_backup_step(). ^If the source database is modified during a backup 6924 ** sqlite3_backup_step(). ^If the source database is modified during a backup
6019 ** operation, then the values are not updated to account for any extra 6925 ** operation, then the values are not updated to account for any extra
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
6179 SQLITE_API int sqlite3_unlock_notify( 7085 SQLITE_API int sqlite3_unlock_notify(
6180 sqlite3 *pBlocked, /* Waiting connection */ 7086 sqlite3 *pBlocked, /* Waiting connection */
6181 void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ 7087 void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */
6182 void *pNotifyArg /* Argument to pass to xNotify */ 7088 void *pNotifyArg /* Argument to pass to xNotify */
6183 ); 7089 );
6184 7090
6185 7091
6186 /* 7092 /*
6187 ** CAPI3REF: String Comparison 7093 ** CAPI3REF: String Comparison
6188 ** 7094 **
6189 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to 7095 ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
6190 ** compare the contents of two buffers containing UTF-8 strings in a 7096 ** and extensions to compare the contents of two buffers containing UTF-8
6191 ** case-independent fashion, using the same definition of case independence 7097 ** strings in a case-independent fashion, using the same definition of "case
6192 ** that SQLite uses internally when comparing identifiers. 7098 ** independence" that SQLite uses internally when comparing identifiers.
6193 */ 7099 */
7100 SQLITE_API int sqlite3_stricmp(const char *, const char *);
6194 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); 7101 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
6195 7102
6196 /* 7103 /*
7104 ** CAPI3REF: String Globbing
7105 *
7106 ** ^The [sqlite3_strglob(P,X)] interface returns zero if string X matches
7107 ** the glob pattern P, and it returns non-zero if string X does not match
7108 ** the glob pattern P. ^The definition of glob pattern matching used in
7109 ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
7110 ** SQL dialect used by SQLite. ^The sqlite3_strglob(P,X) function is case
7111 ** sensitive.
7112 **
7113 ** Note that this routine returns zero on a match and non-zero if the strings
7114 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
7115 */
7116 SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
7117
7118 /*
6197 ** CAPI3REF: Error Logging Interface 7119 ** CAPI3REF: Error Logging Interface
6198 ** 7120 **
6199 ** ^The [sqlite3_log()] interface writes a message into the error log 7121 ** ^The [sqlite3_log()] interface writes a message into the [error log]
6200 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 7122 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6201 ** ^If logging is enabled, the zFormat string and subsequent arguments are 7123 ** ^If logging is enabled, the zFormat string and subsequent arguments are
6202 ** used with [sqlite3_snprintf()] to generate the final output string. 7124 ** used with [sqlite3_snprintf()] to generate the final output string.
6203 ** 7125 **
6204 ** The sqlite3_log() interface is intended for use by extensions such as 7126 ** The sqlite3_log() interface is intended for use by extensions such as
6205 ** virtual tables, collating functions, and SQL functions. While there is 7127 ** virtual tables, collating functions, and SQL functions. While there is
6206 ** nothing to prevent an application from calling sqlite3_log(), doing so 7128 ** nothing to prevent an application from calling sqlite3_log(), doing so
6207 ** is considered bad form. 7129 ** is considered bad form.
6208 ** 7130 **
6209 ** The zFormat string must not be NULL. 7131 ** The zFormat string must not be NULL.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
6269 ** checkpoints entirely. 7191 ** checkpoints entirely.
6270 ** 7192 **
6271 ** ^The callback registered by this function replaces any existing callback 7193 ** ^The callback registered by this function replaces any existing callback
6272 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback 7194 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback
6273 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism 7195 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
6274 ** configured by this function. 7196 ** configured by this function.
6275 ** 7197 **
6276 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface 7198 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6277 ** from SQL. 7199 ** from SQL.
6278 ** 7200 **
7201 ** ^Checkpoints initiated by this mechanism are
7202 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
7203 **
6279 ** ^Every new [database connection] defaults to having the auto-checkpoint 7204 ** ^Every new [database connection] defaults to having the auto-checkpoint
6280 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] 7205 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6281 ** pages. The use of this interface 7206 ** pages. The use of this interface
6282 ** is only necessary if the default setting is found to be suboptimal 7207 ** is only necessary if the default setting is found to be suboptimal
6283 ** for a particular application. 7208 ** for a particular application.
6284 */ 7209 */
6285 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); 7210 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6286 7211
6287 /* 7212 /*
6288 ** CAPI3REF: Checkpoint a database 7213 ** CAPI3REF: Checkpoint a database
6289 ** 7214 **
6290 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X 7215 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
6291 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an 7216 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
6292 ** empty string, then a checkpoint is run on all databases of 7217 ** empty string, then a checkpoint is run on all databases of
6293 ** connection D. ^If the database connection D is not in 7218 ** connection D. ^If the database connection D is not in
6294 ** [WAL | write-ahead log mode] then this interface is a harmless no-op. 7219 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7220 ** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7221 ** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7222 ** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7223 ** or RESET checkpoint.
6295 ** 7224 **
6296 ** ^The [wal_checkpoint pragma] can be used to invoke this interface 7225 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
6297 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the 7226 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
6298 ** [wal_autocheckpoint pragma] can be used to cause this interface to be 7227 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
6299 ** run whenever the WAL reaches a certain size threshold. 7228 ** run whenever the WAL reaches a certain size threshold.
6300 ** 7229 **
6301 ** See also: [sqlite3_wal_checkpoint_v2()] 7230 ** See also: [sqlite3_wal_checkpoint_v2()]
6302 */ 7231 */
6303 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); 7232 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
6304 7233
6305 /* 7234 /*
6306 ** CAPI3REF: Checkpoint a database 7235 ** CAPI3REF: Checkpoint a database
6307 ** 7236 **
6308 ** Run a checkpoint operation on WAL database zDb attached to database 7237 ** Run a checkpoint operation on WAL database zDb attached to database
6309 ** handle db. The specific operation is determined by the value of the 7238 ** handle db. The specific operation is determined by the value of the
6310 ** eMode parameter: 7239 ** eMode parameter:
6311 ** 7240 **
6312 ** <dl> 7241 ** <dl>
6313 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> 7242 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
6314 ** Checkpoint as many frames as possible without waiting for any database 7243 ** Checkpoint as many frames as possible without waiting for any database
6315 ** readers or writers to finish. Sync the db file if all frames in the log 7244 ** readers or writers to finish. Sync the db file if all frames in the log
6316 ** are checkpointed. This mode is the same as calling 7245 ** are checkpointed. This mode is the same as calling
6317 ** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked. 7246 ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7247 ** is never invoked.
6318 ** 7248 **
6319 ** <dt>SQLITE_CHECKPOINT_FULL<dd> 7249 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
6320 ** This mode blocks (calls the busy-handler callback) until there is no 7250 ** This mode blocks (it invokes the
7251 ** [sqlite3_busy_handler|busy-handler callback]) until there is no
6321 ** database writer and all readers are reading from the most recent database 7252 ** database writer and all readers are reading from the most recent database
6322 ** snapshot. It then checkpoints all frames in the log file and syncs the 7253 ** snapshot. It then checkpoints all frames in the log file and syncs the
6323 ** database file. This call blocks database writers while it is running, 7254 ** database file. This call blocks database writers while it is running,
6324 ** but not database readers. 7255 ** but not database readers.
6325 ** 7256 **
6326 ** <dt>SQLITE_CHECKPOINT_RESTART<dd> 7257 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
6327 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after 7258 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
6328 ** checkpointing the log file it blocks (calls the busy-handler callback) 7259 ** checkpointing the log file it blocks (calls the
7260 ** [sqlite3_busy_handler|busy-handler callback])
6329 ** until all readers are reading from the database file only. This ensures 7261 ** until all readers are reading from the database file only. This ensures
6330 ** that the next client to write to the database file restarts the log file 7262 ** that the next client to write to the database file restarts the log file
6331 ** from the beginning. This call blocks database writers while it is running, 7263 ** from the beginning. This call blocks database writers while it is running,
6332 ** but not database readers. 7264 ** but not database readers.
6333 ** </dl> 7265 ** </dl>
6334 ** 7266 **
6335 ** If pnLog is not NULL, then *pnLog is set to the total number of frames in 7267 ** If pnLog is not NULL, then *pnLog is set to the total number of frames in
6336 ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to 7268 ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
6337 ** the total number of checkpointed frames (including any that were already 7269 ** the total number of checkpointed frames (including any that were already
6338 ** checkpointed when this function is called). *pnLog and *pnCkpt may be 7270 ** checkpointed when this function is called). *pnLog and *pnCkpt may be
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6385 ** 7317 **
6386 ** These constants can be used as the 3rd parameter to 7318 ** These constants can be used as the 3rd parameter to
6387 ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] 7319 ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()]
6388 ** documentation for additional information about the meaning and use of 7320 ** documentation for additional information about the meaning and use of
6389 ** each of these values. 7321 ** each of these values.
6390 */ 7322 */
6391 #define SQLITE_CHECKPOINT_PASSIVE 0 7323 #define SQLITE_CHECKPOINT_PASSIVE 0
6392 #define SQLITE_CHECKPOINT_FULL 1 7324 #define SQLITE_CHECKPOINT_FULL 1
6393 #define SQLITE_CHECKPOINT_RESTART 2 7325 #define SQLITE_CHECKPOINT_RESTART 2
6394 7326
7327 /*
7328 ** CAPI3REF: Virtual Table Interface Configuration
7329 **
7330 ** This function may be called by either the [xConnect] or [xCreate] method
7331 ** of a [virtual table] implementation to configure
7332 ** various facets of the virtual table interface.
7333 **
7334 ** If this interface is invoked outside the context of an xConnect or
7335 ** xCreate virtual table method then the behavior is undefined.
7336 **
7337 ** At present, there is only one option that may be configured using
7338 ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
7339 ** may be added in the future.
7340 */
7341 SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
7342
7343 /*
7344 ** CAPI3REF: Virtual Table Configuration Options
7345 **
7346 ** These macros define the various options to the
7347 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
7348 ** can use to customize and optimize their behavior.
7349 **
7350 ** <dl>
7351 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
7352 ** <dd>Calls of the form
7353 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
7354 ** where X is an integer. If X is zero, then the [virtual table] whose
7355 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
7356 ** support constraints. In this configuration (which is the default) if
7357 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
7358 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
7359 ** specified as part of the users SQL statement, regardless of the actual
7360 ** ON CONFLICT mode specified.
7361 **
7362 ** If X is non-zero, then the virtual table implementation guarantees
7363 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
7364 ** any modifications to internal or persistent data structures have been made.
7365 ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
7366 ** is able to roll back a statement or database transaction, and abandon
7367 ** or continue processing the current SQL statement as appropriate.
7368 ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
7369 ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
7370 ** had been ABORT.
7371 **
7372 ** Virtual table implementations that are required to handle OR REPLACE
7373 ** must do so within the [xUpdate] method. If a call to the
7374 ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
7375 ** CONFLICT policy is REPLACE, the virtual table implementation should
7376 ** silently replace the appropriate rows within the xUpdate callback and
7377 ** return SQLITE_OK. Or, if this is not possible, it may return
7378 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
7379 ** constraint handling.
7380 ** </dl>
7381 */
7382 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
7383
7384 /*
7385 ** CAPI3REF: Determine The Virtual Table Conflict Policy
7386 **
7387 ** This function may only be called from within a call to the [xUpdate] method
7388 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
7389 ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
7390 ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
7391 ** of the SQL statement that triggered the call to the [xUpdate] method of the
7392 ** [virtual table].
7393 */
7394 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
7395
7396 /*
7397 ** CAPI3REF: Conflict resolution modes
7398 ** KEYWORDS: {conflict resolution mode}
7399 **
7400 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
7401 ** inform a [virtual table] implementation what the [ON CONFLICT] mode
7402 ** is for the SQL statement being evaluated.
7403 **
7404 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
7405 ** return value from the [sqlite3_set_authorizer()] callback and that
7406 ** [SQLITE_ABORT] is also a [result code].
7407 */
7408 #define SQLITE_ROLLBACK 1
7409 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7410 #define SQLITE_FAIL 3
7411 /* #define SQLITE_ABORT 4 // Also an error code */
7412 #define SQLITE_REPLACE 5
7413
7414
6395 7415
6396 /* Begin recover.patch for Chromium */ 7416 /* Begin recover.patch for Chromium */
6397 /* 7417 /*
6398 ** Call to initialize the recover virtual-table modules (see recover.c). 7418 ** Call to initialize the recover virtual-table modules (see recover.c).
6399 ** 7419 **
6400 ** This could be loaded by default in main.c, but that would make the 7420 ** This could be loaded by default in main.c, but that would make the
6401 ** virtual table available to Web SQL. Breaking it out allows only 7421 ** virtual table available to Web SQL. Breaking it out allows only
6402 ** selected users to enable it (currently sql/recovery.cc). 7422 ** selected users to enable it (currently sql/recovery.cc).
6403 */ 7423 */
6404 int recoverVtableInit(sqlite3 *db); 7424 int recoverVtableInit(sqlite3 *db);
6405 /* End recover.patch for Chromium */ 7425 /* End recover.patch for Chromium */
6406 7426
6407 /* 7427 /*
6408 ** Undo the hack that converts floating point types to integer for 7428 ** Undo the hack that converts floating point types to integer for
6409 ** builds on processors without floating point support. 7429 ** builds on processors without floating point support.
6410 */ 7430 */
6411 #ifdef SQLITE_OMIT_FLOATING_POINT 7431 #ifdef SQLITE_OMIT_FLOATING_POINT
6412 # undef double 7432 # undef double
6413 #endif 7433 #endif
6414 7434
6415 #ifdef __cplusplus 7435 #ifdef __cplusplus
6416 } /* End of the 'extern "C"' block */ 7436 } /* End of the 'extern "C"' block */
6417 #endif 7437 #endif
6418 #endif 7438 #endif /* _SQLITE3_H_ */
6419 7439
6420 /* 7440 /*
6421 ** 2010 August 30 7441 ** 2010 August 30
6422 ** 7442 **
6423 ** The author disclaims copyright to this source code. In place of 7443 ** The author disclaims copyright to this source code. In place of
6424 ** a legal notice, here is a blessing: 7444 ** a legal notice, here is a blessing:
6425 ** 7445 **
6426 ** May you do good and not evil. 7446 ** May you do good and not evil.
6427 ** May you find forgiveness for yourself and forgive others. 7447 ** May you find forgiveness for yourself and forgive others.
6428 ** May you share freely, never taking more than you give. 7448 ** May you share freely, never taking more than you give.
6429 ** 7449 **
6430 ************************************************************************* 7450 *************************************************************************
6431 */ 7451 */
6432 7452
6433 #ifndef _SQLITE3RTREE_H_ 7453 #ifndef _SQLITE3RTREE_H_
6434 #define _SQLITE3RTREE_H_ 7454 #define _SQLITE3RTREE_H_
6435 7455
6436 7456
6437 #ifdef __cplusplus 7457 #ifdef __cplusplus
6438 extern "C" { 7458 extern "C" {
6439 #endif 7459 #endif
6440 7460
6441 typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; 7461 typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
7462 typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;
7463
7464 /* The double-precision datatype used by RTree depends on the
7465 ** SQLITE_RTREE_INT_ONLY compile-time option.
7466 */
7467 #ifdef SQLITE_RTREE_INT_ONLY
7468 typedef sqlite3_int64 sqlite3_rtree_dbl;
7469 #else
7470 typedef double sqlite3_rtree_dbl;
7471 #endif
6442 7472
6443 /* 7473 /*
6444 ** Register a geometry callback named zGeom that can be used as part of an 7474 ** Register a geometry callback named zGeom that can be used as part of an
6445 ** R-Tree geometry query as follows: 7475 ** R-Tree geometry query as follows:
6446 ** 7476 **
6447 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 7477 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
6448 */ 7478 */
6449 SQLITE_API int sqlite3_rtree_geometry_callback( 7479 SQLITE_API int sqlite3_rtree_geometry_callback(
6450 sqlite3 *db, 7480 sqlite3 *db,
6451 const char *zGeom, 7481 const char *zGeom,
6452 int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes), 7482 int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
6453 void *pContext 7483 void *pContext
6454 ); 7484 );
6455 7485
6456 7486
6457 /* 7487 /*
6458 ** A pointer to a structure of the following type is passed as the first 7488 ** A pointer to a structure of the following type is passed as the first
6459 ** argument to callbacks registered using rtree_geometry_callback(). 7489 ** argument to callbacks registered using rtree_geometry_callback().
6460 */ 7490 */
6461 struct sqlite3_rtree_geometry { 7491 struct sqlite3_rtree_geometry {
6462 void *pContext; /* Copy of pContext passed to s_r_g_c() */ 7492 void *pContext; /* Copy of pContext passed to s_r_g_c() */
6463 int nParam; /* Size of array aParam[] */ 7493 int nParam; /* Size of array aParam[] */
6464 double *aParam; /* Parameters passed to SQL geom function */ 7494 sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */
6465 void *pUser; /* Callback implementation user data */ 7495 void *pUser; /* Callback implementation user data */
6466 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ 7496 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
6467 }; 7497 };
6468 7498
7499 /*
7500 ** Register a 2nd-generation geometry callback named zScore that can be
7501 ** used as part of an R-Tree geometry query as follows:
7502 **
7503 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
7504 */
7505 SQLITE_API int sqlite3_rtree_query_callback(
7506 sqlite3 *db,
7507 const char *zQueryFunc,
7508 int (*xQueryFunc)(sqlite3_rtree_query_info*),
7509 void *pContext,
7510 void (*xDestructor)(void*)
7511 );
7512
7513
7514 /*
7515 ** A pointer to a structure of the following type is passed as the
7516 ** argument to scored geometry callback registered using
7517 ** sqlite3_rtree_query_callback().
7518 **
7519 ** Note that the first 5 fields of this structure are identical to
7520 ** sqlite3_rtree_geometry. This structure is a subclass of
7521 ** sqlite3_rtree_geometry.
7522 */
7523 struct sqlite3_rtree_query_info {
7524 void *pContext; /* pContext from when function registered */
7525 int nParam; /* Number of function parameters */
7526 sqlite3_rtree_dbl *aParam; /* value of function parameters */
7527 void *pUser; /* callback can use this, if desired */
7528 void (*xDelUser)(void*); /* function to free pUser */
7529 sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */
7530 unsigned int *anQueue; /* Number of pending entries in the queue */
7531 int nCoord; /* Number of coordinates */
7532 int iLevel; /* Level of current node or entry */
7533 int mxLevel; /* The largest iLevel value in the tree */
7534 sqlite3_int64 iRowid; /* Rowid for current entry */
7535 sqlite3_rtree_dbl rParentScore; /* Score of parent node */
7536 int eParentWithin; /* Visibility of parent node */
7537 int eWithin; /* OUT: Visiblity */
7538 sqlite3_rtree_dbl rScore; /* OUT: Write the score here */
7539 };
7540
7541 /*
7542 ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
7543 */
7544 #define NOT_WITHIN 0 /* Object completely outside of query region */
7545 #define PARTLY_WITHIN 1 /* Object partially overlaps query region */
7546 #define FULLY_WITHIN 2 /* Object fully contained within query region */
7547
6469 7548
6470 #ifdef __cplusplus 7549 #ifdef __cplusplus
6471 } /* end of the 'extern "C"' block */ 7550 } /* end of the 'extern "C"' block */
6472 #endif 7551 #endif
6473 7552
6474 #endif /* ifndef _SQLITE3RTREE_H_ */ 7553 #endif /* ifndef _SQLITE3RTREE_H_ */
6475 7554
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698