amalgalite 1.1.2-x86-mingw32 → 1.4.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CONTRIBUTING.md +49 -0
  2. data/{HISTORY.rdoc → HISTORY.md} +102 -73
  3. data/LICENSE +2 -2
  4. data/Manifest.txt +104 -0
  5. data/README.md +73 -0
  6. data/Rakefile +25 -0
  7. data/TODO.md +49 -0
  8. data/ext/amalgalite/{amalgalite3.c → c/amalgalite.c} +12 -12
  9. data/ext/amalgalite/{amalgalite3.h → c/amalgalite.h} +5 -5
  10. data/ext/amalgalite/{amalgalite3_blob.c → c/amalgalite_blob.c} +2 -2
  11. data/ext/amalgalite/{amalgalite3_constants.c → c/amalgalite_constants.c} +2 -2
  12. data/ext/amalgalite/{amalgalite3_database.c → c/amalgalite_database.c} +49 -21
  13. data/ext/amalgalite/{amalgalite3_requires_bootstrap.c → c/amalgalite_requires_bootstrap.c} +131 -58
  14. data/ext/amalgalite/{amalgalite3_statement.c → c/amalgalite_statement.c} +2 -2
  15. data/ext/amalgalite/{extconf.rb → c/extconf.rb} +6 -5
  16. data/ext/amalgalite/{gen_constants.rb → c/gen_constants.rb} +3 -3
  17. data/ext/amalgalite/c/notes.txt +134 -0
  18. data/ext/amalgalite/{sqlite3.c → c/sqlite3.c} +111793 -83396
  19. data/ext/amalgalite/{sqlite3.h → c/sqlite3.h} +1597 -383
  20. data/ext/amalgalite/{sqlite3_options.h → c/sqlite3_options.h} +0 -0
  21. data/ext/amalgalite/{sqlite3ext.h → c/sqlite3ext.h} +114 -17
  22. data/lib/amalgalite.rb +13 -6
  23. data/lib/amalgalite/1.9/amalgalite.so +0 -0
  24. data/lib/amalgalite/2.0/amalgalite.so +0 -0
  25. data/lib/amalgalite/2.1/amalgalite.so +0 -0
  26. data/lib/amalgalite/column.rb +7 -5
  27. data/lib/amalgalite/database.rb +18 -10
  28. data/lib/amalgalite/packer.rb +5 -2
  29. data/lib/amalgalite/requires.rb +47 -16
  30. data/lib/amalgalite/schema.rb +63 -36
  31. data/lib/amalgalite/sqlite3/version.rb +0 -1
  32. data/lib/amalgalite/statement.rb +7 -5
  33. data/lib/amalgalite/table.rb +9 -8
  34. data/lib/amalgalite/type_maps/default_map.rb +0 -1
  35. data/lib/amalgalite/type_maps/storage_map.rb +0 -2
  36. data/lib/amalgalite/type_maps/text_map.rb +0 -1
  37. data/lib/amalgalite/version.rb +3 -32
  38. data/spec/aggregate_spec.rb +1 -1
  39. data/spec/amalgalite_spec.rb +1 -1
  40. data/spec/blob_spec.rb +1 -1
  41. data/spec/boolean_spec.rb +2 -1
  42. data/spec/busy_handler.rb +1 -1
  43. data/spec/database_spec.rb +18 -13
  44. data/spec/default_map_spec.rb +1 -1
  45. data/spec/function_spec.rb +1 -1
  46. data/spec/integeration_spec.rb +2 -1
  47. data/spec/packer_spec.rb +4 -4
  48. data/spec/paths_spec.rb +1 -1
  49. data/spec/progress_handler_spec.rb +4 -5
  50. data/spec/requires_spec.rb +36 -2
  51. data/spec/rtree_spec.rb +6 -5
  52. data/spec/schema_spec.rb +28 -20
  53. data/spec/spec_helper.rb +7 -7
  54. data/spec/sqlite3/constants_spec.rb +1 -1
  55. data/spec/sqlite3/database_status_spec.rb +4 -4
  56. data/spec/sqlite3/status_spec.rb +5 -5
  57. data/spec/sqlite3/version_spec.rb +12 -12
  58. data/spec/sqlite3_spec.rb +3 -3
  59. data/spec/statement_spec.rb +3 -4
  60. data/spec/storage_map_spec.rb +1 -1
  61. data/spec/tap_spec.rb +4 -4
  62. data/spec/text_map_spec.rb +1 -1
  63. data/spec/type_map_spec.rb +1 -1
  64. data/spec/version_spec.rb +3 -10
  65. data/tasks/custom.rake +102 -0
  66. data/tasks/default.rake +247 -0
  67. data/tasks/extension.rake +28 -202
  68. data/tasks/this.rb +206 -0
  69. metadata +194 -236
  70. data/README.rdoc +0 -54
  71. data/gemspec.rb +0 -63
  72. data/lib/amalgalite/1.8/amalgalite3.so +0 -0
  73. data/lib/amalgalite/1.9/amalgalite3.so +0 -0
  74. data/tasks/announce.rake +0 -44
  75. data/tasks/config.rb +0 -107
  76. data/tasks/distribution.rake +0 -77
  77. data/tasks/documentation.rake +0 -36
  78. data/tasks/rspec.rake +0 -30
  79. data/tasks/utils.rb +0 -80
@@ -107,9 +107,9 @@ extern "C" {
107
107
  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108
108
  ** [sqlite_version()] and [sqlite_source_id()].
109
109
  */
110
- #define SQLITE_VERSION "3.7.5"
111
- #define SQLITE_VERSION_NUMBER 3007005
112
- #define SQLITE_SOURCE_ID "2011-01-28 17:03:50 ed759d5a9edb3bba5f48f243df47be29e3fe8cd7"
110
+ #define SQLITE_VERSION "3.8.7.4"
111
+ #define SQLITE_VERSION_NUMBER 3008007
112
+ #define SQLITE_SOURCE_ID "2014-12-09 01:34:36 f66f7a17b78ba617acde90fc810107f34f1a1f2e"
113
113
 
114
114
  /*
115
115
  ** CAPI3REF: Run-Time Library Version Numbers
@@ -177,7 +177,7 @@ SQLITE_API const char *sqlite3_compileoption_get(int N);
177
177
  ** CAPI3REF: Test To See If The Library Is Threadsafe
178
178
  **
179
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
181
  ** [SQLITE_THREADSAFE] compile-time option being set to 0.
182
182
  **
183
183
  ** SQLite can be compiled with or without mutexes. When
@@ -219,7 +219,8 @@ SQLITE_API int sqlite3_threadsafe(void);
219
219
  ** the opaque structure named "sqlite3". It is useful to think of an sqlite3
220
220
  ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
221
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
224
  ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
224
225
  ** [sqlite3_busy_timeout()] to name but three) that are methods on an
225
226
  ** sqlite3 object.
@@ -266,28 +267,46 @@ typedef sqlite_uint64 sqlite3_uint64;
266
267
  /*
267
268
  ** CAPI3REF: Closing A Database Connection
268
269
  **
269
- ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object.
270
- ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is
271
- ** successfully destroyed and all associated resources are deallocated.
272
- **
273
- ** Applications must [sqlite3_finalize | finalize] all [prepared statements]
274
- ** and [sqlite3_blob_close | close] all [BLOB handles] associated with
275
- ** the [sqlite3] object prior to attempting to close the object. ^If
276
- ** sqlite3_close() is called on a [database connection] that still has
277
- ** outstanding [prepared statements] or [BLOB handles], then it returns
278
- ** SQLITE_BUSY.
279
- **
280
- ** ^If [sqlite3_close()] is invoked while a transaction is open,
270
+ ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
271
+ ** for the [sqlite3] object.
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.
275
+ **
276
+ ** ^If the database connection is associated with unfinalized prepared
277
+ ** statements or unfinished sqlite3_backup objects then sqlite3_close()
278
+ ** will leave the database connection open and return [SQLITE_BUSY].
279
+ ** ^If sqlite3_close_v2() is called with unfinalized prepared statements
280
+ ** and/or unfinished sqlite3_backups, then the database connection becomes
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.
286
+ **
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
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
302
  ** pointer or an [sqlite3] object pointer obtained
285
303
  ** from [sqlite3_open()], [sqlite3_open16()], or
286
304
  ** [sqlite3_open_v2()], and not previously closed.
287
- ** ^Calling sqlite3_close() with a NULL pointer argument is a
288
- ** harmless no-op.
305
+ ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
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
312
  ** The type for a callback function.
@@ -310,7 +329,7 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**);
310
329
  ** argument. ^If the callback function of the 3rd argument to
311
330
  ** sqlite3_exec() is not NULL, then it is invoked for each result row
312
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
333
  ** callback invocation. ^If the callback pointer to sqlite3_exec()
315
334
  ** is NULL, then no callback is ever invoked and result rows are
316
335
  ** ignored.
@@ -351,7 +370,7 @@ typedef int (*sqlite3_callback)(void*,int,char**, char**);
351
370
  ** <ul>
352
371
  ** <li> The application must insure that the 1st parameter to sqlite3_exec()
353
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
374
  ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
356
375
  ** <li> The application must not modify the SQL statement text passed into
357
376
  ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
@@ -367,15 +386,14 @@ SQLITE_API int sqlite3_exec(
367
386
 
368
387
  /*
369
388
  ** CAPI3REF: Result Codes
370
- ** KEYWORDS: SQLITE_OK {error code} {error codes}
371
- ** KEYWORDS: {result code} {result codes}
389
+ ** KEYWORDS: {result code definitions}
372
390
  **
373
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
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
398
  #define SQLITE_OK 0 /* Successful result */
381
399
  /* beginning-of-error-codes */
@@ -405,32 +423,27 @@ SQLITE_API int sqlite3_exec(
405
423
  #define SQLITE_FORMAT 24 /* Auxiliary database format error */
406
424
  #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
407
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
428
  #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
409
429
  #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
410
430
  /* end-of-error-codes */
411
431
 
412
432
  /*
413
433
  ** CAPI3REF: Extended Result Codes
414
- ** KEYWORDS: {extended error code} {extended error codes}
415
- ** KEYWORDS: {extended result code} {extended result codes}
434
+ ** KEYWORDS: {extended result code definitions}
416
435
  **
417
- ** In its default configuration, SQLite API routines return one of 26 integer
418
- ** [SQLITE_OK | result codes]. However, experience has shown that many of
436
+ ** In its default configuration, SQLite API routines return one of 30 integer
437
+ ** [result codes]. However, experience has shown that many of
419
438
  ** these result codes are too coarse-grained. They do not provide as
420
439
  ** much information about problems as programmers might like. In an effort to
421
440
  ** address this, newer versions of SQLite (version 3.3.8 and later) include
422
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
443
  ** on a per database connection basis using the
425
- ** [sqlite3_extended_result_codes()] API.
426
- **
427
- ** Some of the available extended result codes are listed here.
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.
444
+ ** [sqlite3_extended_result_codes()] API. Or, the extended code for
445
+ ** the most recent error can be obtained using
446
+ ** [sqlite3_extended_errcode()].
434
447
  */
435
448
  #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
436
449
  #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
@@ -452,17 +465,46 @@ SQLITE_API int sqlite3_exec(
452
465
  #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
453
466
  #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
454
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
474
  #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
456
475
  #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
476
+ #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
457
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
503
  ** CAPI3REF: Flags For File Open Operations
461
504
  **
462
505
  ** These bit values are intended for use in the
463
506
  ** 3rd parameter to the [sqlite3_open_v2()] interface and
464
- ** in the 4th parameter to the xOpen method of the
465
- ** [sqlite3_vfs] object.
507
+ ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
466
508
  */
467
509
  #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
468
510
  #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
@@ -470,6 +512,8 @@ SQLITE_API int sqlite3_exec(
470
512
  #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
471
513
  #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
472
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
517
  #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
474
518
  #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
475
519
  #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
@@ -483,11 +527,13 @@ SQLITE_API int sqlite3_exec(
483
527
  #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
484
528
  #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
485
529
 
530
+ /* Reserved: 0x00F00000 */
531
+
486
532
  /*
487
533
  ** CAPI3REF: Device Characteristics
488
534
  **
489
535
  ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
490
- ** object returns an integer which is a vector of the these
536
+ ** object returns an integer which is a vector of these
491
537
  ** bit values expressing I/O characteristics of the mass storage
492
538
  ** device that holds the file that the [sqlite3_io_methods]
493
539
  ** refers to.
@@ -501,7 +547,15 @@ SQLITE_API int sqlite3_exec(
501
547
  ** first then the size of the file is extended, never the other
502
548
  ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
503
549
  ** information is written to disk in the same order as calls
504
- ** 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.
505
559
  */
506
560
  #define SQLITE_IOCAP_ATOMIC 0x00000001
507
561
  #define SQLITE_IOCAP_ATOMIC512 0x00000002
@@ -515,6 +569,8 @@ SQLITE_API int sqlite3_exec(
515
569
  #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
516
570
  #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
517
571
  #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
572
+ #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
573
+ #define SQLITE_IOCAP_IMMUTABLE 0x00002000
518
574
 
519
575
  /*
520
576
  ** CAPI3REF: File Locking Levels
@@ -578,17 +634,18 @@ struct sqlite3_file {
578
634
  /*
579
635
  ** CAPI3REF: OS Interface File Virtual Methods Object
580
636
  **
581
- ** Every file opened by the [sqlite3_vfs] xOpen method populates an
637
+ ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
582
638
  ** [sqlite3_file] object (or, more commonly, a subclass of the
583
639
  ** [sqlite3_file] object) with a pointer to an instance of this object.
584
640
  ** This object defines the methods used to perform various operations
585
641
  ** against the open file represented by the [sqlite3_file] object.
586
642
  **
587
- ** If the xOpen method sets the sqlite3_file.pMethods element
643
+ ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
588
644
  ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
589
- ** may be invoked even if the xOpen reported that it failed. The
590
- ** only way to prevent a call to xClose following a failed xOpen
591
- ** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
645
+ ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
646
+ ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
647
+ ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
648
+ ** to NULL.
592
649
  **
593
650
  ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
594
651
  ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
@@ -620,7 +677,7 @@ struct sqlite3_file {
620
677
  ** locking strategy (for example to use dot-file locks), to inquire
621
678
  ** about the status of a lock, or to break stale locks. The SQLite
622
679
  ** core reserves all opcodes less than 100 for its own use.
623
- ** 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.
624
681
  ** Applications that define a custom xFileControl method should use opcodes
625
682
  ** greater than 100 to avoid conflicts. VFS implementations should
626
683
  ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
@@ -685,11 +742,15 @@ struct sqlite3_io_methods {
685
742
  void (*xShmBarrier)(sqlite3_file*);
686
743
  int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
687
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 */
688
748
  /* Additional methods may be added in future releases */
689
749
  };
690
750
 
691
751
  /*
692
752
  ** CAPI3REF: Standard File Control Opcodes
753
+ ** KEYWORDS: {file control opcodes} {file control opcode}
693
754
  **
694
755
  ** These integer constants are opcodes for the xFileControl method
695
756
  ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
@@ -702,7 +763,8 @@ struct sqlite3_io_methods {
702
763
  ** into an integer that the pArg argument points to. This capability
703
764
  ** is used during testing and only needs to be supported when SQLITE_TEST
704
765
  ** is defined.
705
- **
766
+ ** <ul>
767
+ ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
706
768
  ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
707
769
  ** layer a hint of how large the database file will grow to be during the
708
770
  ** current transaction. This hint is not guaranteed to be accurate but it
@@ -710,6 +772,7 @@ struct sqlite3_io_methods {
710
772
  ** file space based on this hint in order to help writes to the database
711
773
  ** file run faster.
712
774
  **
775
+ ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
713
776
  ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
714
777
  ** extends and truncates the database file in chunks of a size specified
715
778
  ** by the user. The fourth argument to [sqlite3_file_control()] should
@@ -718,30 +781,195 @@ struct sqlite3_io_methods {
718
781
  ** chunks (say 1MB at a time), may reduce file-system fragmentation and
719
782
  ** improve performance on some systems.
720
783
  **
784
+ ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
721
785
  ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
722
786
  ** to the [sqlite3_file] object associated with a particular database
723
787
  ** connection. See the [sqlite3_file_control()] documentation for
724
788
  ** additional information.
725
789
  **
726
- ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
727
- ** SQLite and sent to all VFSes in place of a call to the xSync method
728
- ** when the database connection has [PRAGMA synchronous] set to OFF.)^
729
- ** Some specialized VFSes need this signal in order to operate correctly
730
- ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
731
- ** VFSes do not need this signal and should silently ignore this opcode.
732
- ** Applications should not call [sqlite3_file_control()] with this
733
- ** opcode as doing so may disrupt the operation of the specilized VFSes
734
- ** that do require it.
790
+ ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
791
+ ** No longer in use.
792
+ **
793
+ ** <li>[[SQLITE_FCNTL_SYNC]]
794
+ ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
795
+ ** sent to the VFS immediately before the xSync method is invoked on a
796
+ ** database file descriptor. Or, if the xSync method is not invoked
797
+ ** because the user has configured SQLite with
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>
735
950
  */
736
- #define SQLITE_FCNTL_LOCKSTATE 1
737
- #define SQLITE_GET_LOCKPROXYFILE 2
738
- #define SQLITE_SET_LOCKPROXYFILE 3
739
- #define SQLITE_LAST_ERRNO 4
740
- #define SQLITE_FCNTL_SIZE_HINT 5
741
- #define SQLITE_FCNTL_CHUNK_SIZE 6
742
- #define SQLITE_FCNTL_FILE_POINTER 7
743
- #define SQLITE_FCNTL_SYNC_OMITTED 8
744
-
951
+ #define SQLITE_FCNTL_LOCKSTATE 1
952
+ #define SQLITE_GET_LOCKPROXYFILE 2
953
+ #define SQLITE_SET_LOCKPROXYFILE 3
954
+ #define SQLITE_LAST_ERRNO 4
955
+ #define SQLITE_FCNTL_SIZE_HINT 5
956
+ #define SQLITE_FCNTL_CHUNK_SIZE 6
957
+ #define SQLITE_FCNTL_FILE_POINTER 7
958
+ #define SQLITE_FCNTL_SYNC_OMITTED 8
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
745
973
 
746
974
  /*
747
975
  ** CAPI3REF: Mutex Handle
@@ -760,7 +988,8 @@ typedef struct sqlite3_mutex sqlite3_mutex;
760
988
  **
761
989
  ** An instance of the sqlite3_vfs object defines the interface between
762
990
  ** the SQLite core and the underlying operating system. The "vfs"
763
- ** 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.
764
993
  **
765
994
  ** The value of the iVersion field is initially 1 but may be larger in
766
995
  ** future versions of SQLite. Additional fields may be appended to this
@@ -789,12 +1018,13 @@ typedef struct sqlite3_mutex sqlite3_mutex;
789
1018
  ** The zName field holds the name of the VFS module. The name must
790
1019
  ** be unique across all VFS modules.
791
1020
  **
1021
+ ** [[sqlite3_vfs.xOpen]]
792
1022
  ** ^SQLite guarantees that the zFilename parameter to xOpen
793
1023
  ** is either a NULL pointer or string obtained
794
1024
  ** from xFullPathname() with an optional suffix added.
795
1025
  ** ^If a suffix is added to the zFilename parameter, it will
796
1026
  ** consist of a single "-" character followed by no more than
797
- ** 10 alphanumeric and/or "-" characters.
1027
+ ** 11 alphanumeric and/or "-" characters.
798
1028
  ** ^SQLite further guarantees that
799
1029
  ** the string will be valid and unchanged until xClose() is
800
1030
  ** called. Because of the previous sentence,
@@ -866,6 +1096,7 @@ typedef struct sqlite3_mutex sqlite3_mutex;
866
1096
  ** element will be valid after xOpen returns regardless of the success
867
1097
  ** or failure of the xOpen call.
868
1098
  **
1099
+ ** [[sqlite3_vfs.xAccess]]
869
1100
  ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
870
1101
  ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
871
1102
  ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
@@ -890,16 +1121,29 @@ typedef struct sqlite3_mutex sqlite3_mutex;
890
1121
  ** method returns a Julian Day Number for the current date and time as
891
1122
  ** a floating point value.
892
1123
  ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
893
- ** Day Number multipled by 86400000 (the number of milliseconds in
1124
+ ** Day Number multiplied by 86400000 (the number of milliseconds in
894
1125
  ** a 24-hour day).
895
1126
  ** ^SQLite will use the xCurrentTimeInt64() method to get the current
896
1127
  ** date and time if that method is available (if iVersion is 2 or
897
1128
  ** greater and the function pointer is not NULL) and will fall back
898
1129
  ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1130
+ **
1131
+ ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1132
+ ** are not used by the SQLite core. These optional interfaces are provided
1133
+ ** by some VFSes to facilitate testing of the VFS code. By overriding
1134
+ ** system calls with functions under its control, a test program can
1135
+ ** simulate faults and error conditions that would otherwise be difficult
1136
+ ** or impossible to induce. The set of system calls that can be overridden
1137
+ ** varies from one VFS to another, and from one version of the same VFS to the
1138
+ ** next. Applications that use these interfaces must be prepared for any
1139
+ ** or all of these interfaces to be NULL or for their behavior to change
1140
+ ** from one release to the next. Applications must not attempt to access
1141
+ ** any of these methods if the iVersion of the VFS is less than 3.
899
1142
  */
900
1143
  typedef struct sqlite3_vfs sqlite3_vfs;
1144
+ typedef void (*sqlite3_syscall_ptr)(void);
901
1145
  struct sqlite3_vfs {
902
- int iVersion; /* Structure version number (currently 2) */
1146
+ int iVersion; /* Structure version number (currently 3) */
903
1147
  int szOsFile; /* Size of subclassed sqlite3_file */
904
1148
  int mxPathname; /* Maximum file pathname length */
905
1149
  sqlite3_vfs *pNext; /* Next registered VFS */
@@ -925,6 +1169,13 @@ struct sqlite3_vfs {
925
1169
  int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
926
1170
  /*
927
1171
  ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1172
+ ** Those below are for version 3 and greater.
1173
+ */
1174
+ int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1175
+ sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1176
+ const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1177
+ /*
1178
+ ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
928
1179
  ** New fields may be appended in figure versions. The iVersion
929
1180
  ** value will increment whenever this happens.
930
1181
  */
@@ -1092,9 +1343,9 @@ SQLITE_API int sqlite3_os_end(void);
1092
1343
  ** implementation of an application-defined [sqlite3_os_init()].
1093
1344
  **
1094
1345
  ** The first argument to sqlite3_config() is an integer
1095
- ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
1346
+ ** [configuration option] that determines
1096
1347
  ** what property of SQLite is to be configured. Subsequent arguments
1097
- ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
1348
+ ** vary depending on the [configuration option]
1098
1349
  ** in the first argument.
1099
1350
  **
1100
1351
  ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
@@ -1109,17 +1360,12 @@ SQLITE_API int sqlite3_config(int, ...);
1109
1360
  ** The sqlite3_db_config() interface is used to make configuration
1110
1361
  ** changes to a [database connection]. The interface is similar to
1111
1362
  ** [sqlite3_config()] except that the changes apply to a single
1112
- ** [database connection] (specified in the first argument). The
1113
- ** sqlite3_db_config() interface should only be used immediately after
1114
- ** the database connection is created using [sqlite3_open()],
1115
- ** [sqlite3_open16()], or [sqlite3_open_v2()].
1363
+ ** [database connection] (specified in the first argument).
1116
1364
  **
1117
1365
  ** The second argument to sqlite3_db_config(D,V,...) is the
1118
- ** configuration verb - an integer code that indicates what
1119
- ** aspect of the [database connection] is being configured.
1120
- ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
1121
- ** New verbs are likely to be added in future releases of SQLite.
1122
- ** Additional arguments depend on the verb.
1366
+ ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1367
+ ** that indicates what aspect of the [database connection] is being configured.
1368
+ ** Subsequent arguments vary depending on the configuration verb.
1123
1369
  **
1124
1370
  ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1125
1371
  ** the call is considered successful.
@@ -1151,16 +1397,10 @@ SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1151
1397
  ** order to verify that SQLite recovers gracefully from such
1152
1398
  ** conditions.
1153
1399
  **
1154
- ** The xMalloc and xFree methods must work like the
1155
- ** malloc() and free() functions from the standard C library.
1156
- ** The xRealloc method must work like realloc() from the standard C library
1157
- ** with the exception that if the second argument to xRealloc is zero,
1158
- ** xRealloc must be a no-op - it must not perform any allocation or
1159
- ** deallocation. ^SQLite guarantees that the second argument to
1400
+ ** The xMalloc, xRealloc, and xFree methods must work like the
1401
+ ** malloc(), realloc() and free() functions from the standard C library.
1402
+ ** ^SQLite guarantees that the second argument to
1160
1403
  ** xRealloc is always a value returned by a prior call to xRoundup.
1161
- ** And so in cases where xRoundup always returns a positive number,
1162
- ** xRealloc can perform exactly as the standard library realloc() and
1163
- ** still be in compliance with this specification.
1164
1404
  **
1165
1405
  ** xSize should return the allocated size of a memory allocation
1166
1406
  ** previously obtained from xMalloc or xRealloc. The allocated size
@@ -1174,7 +1414,7 @@ SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1174
1414
  ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1175
1415
  ** that causes the corresponding memory allocation to fail.
1176
1416
  **
1177
- ** The xInit method initializes the memory allocator. (For example,
1417
+ ** The xInit method initializes the memory allocator. For example,
1178
1418
  ** it might allocate any require mutexes or initialize internal data
1179
1419
  ** structures. The xShutdown method is invoked (indirectly) by
1180
1420
  ** [sqlite3_shutdown()] and should deallocate any resources acquired
@@ -1209,6 +1449,7 @@ struct sqlite3_mem_methods {
1209
1449
 
1210
1450
  /*
1211
1451
  ** CAPI3REF: Configuration Options
1452
+ ** KEYWORDS: {configuration option}
1212
1453
  **
1213
1454
  ** These constants are the available integer configuration options that
1214
1455
  ** can be passed as the first argument to the [sqlite3_config()] interface.
@@ -1221,7 +1462,7 @@ struct sqlite3_mem_methods {
1221
1462
  ** is invoked.
1222
1463
  **
1223
1464
  ** <dl>
1224
- ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1465
+ ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1225
1466
  ** <dd>There are no arguments to this option. ^This option sets the
1226
1467
  ** [threading mode] to Single-thread. In other words, it disables
1227
1468
  ** all mutexing and puts SQLite into a mode where it can only be used
@@ -1232,7 +1473,7 @@ struct sqlite3_mem_methods {
1232
1473
  ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1233
1474
  ** configuration option.</dd>
1234
1475
  **
1235
- ** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1476
+ ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1236
1477
  ** <dd>There are no arguments to this option. ^This option sets the
1237
1478
  ** [threading mode] to Multi-thread. In other words, it disables
1238
1479
  ** mutexing on [database connection] and [prepared statement] objects.
@@ -1246,7 +1487,7 @@ struct sqlite3_mem_methods {
1246
1487
  ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1247
1488
  ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1248
1489
  **
1249
- ** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1490
+ ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1250
1491
  ** <dd>There are no arguments to this option. ^This option sets the
1251
1492
  ** [threading mode] to Serialized. In other words, this option enables
1252
1493
  ** all mutexes including the recursive
@@ -1262,7 +1503,7 @@ struct sqlite3_mem_methods {
1262
1503
  ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1263
1504
  ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1264
1505
  **
1265
- ** <dt>SQLITE_CONFIG_MALLOC</dt>
1506
+ ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1266
1507
  ** <dd> ^(This option takes a single argument which is a pointer to an
1267
1508
  ** instance of the [sqlite3_mem_methods] structure. The argument specifies
1268
1509
  ** alternative low-level memory allocation routines to be used in place of
@@ -1270,7 +1511,7 @@ struct sqlite3_mem_methods {
1270
1511
  ** its own private copy of the content of the [sqlite3_mem_methods] structure
1271
1512
  ** before the [sqlite3_config()] call returns.</dd>
1272
1513
  **
1273
- ** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1514
+ ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1274
1515
  ** <dd> ^(This option takes a single argument which is a pointer to an
1275
1516
  ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1276
1517
  ** structure is filled with the currently defined memory allocation routines.)^
@@ -1278,7 +1519,7 @@ struct sqlite3_mem_methods {
1278
1519
  ** routines with a wrapper that simulations memory allocation failure or
1279
1520
  ** tracks memory usage, for example. </dd>
1280
1521
  **
1281
- ** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1522
+ ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1282
1523
  ** <dd> ^This option takes single argument of type int, interpreted as a
1283
1524
  ** boolean, which enables or disables the collection of memory allocation
1284
1525
  ** statistics. ^(When memory allocation statistics are disabled, the
@@ -1294,10 +1535,10 @@ struct sqlite3_mem_methods {
1294
1535
  ** allocation statistics are disabled by default.
1295
1536
  ** </dd>
1296
1537
  **
1297
- ** <dt>SQLITE_CONFIG_SCRATCH</dt>
1538
+ ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1298
1539
  ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1299
1540
  ** scratch memory. There are three arguments: A pointer an 8-byte
1300
- ** aligned memory buffer from which the scrach allocations will be
1541
+ ** aligned memory buffer from which the scratch allocations will be
1301
1542
  ** drawn, the size of each scratch allocation (sz),
1302
1543
  ** and the maximum number of scratch allocations (N). The sz
1303
1544
  ** argument must be a multiple of 16.
@@ -1310,11 +1551,11 @@ struct sqlite3_mem_methods {
1310
1551
  ** scratch memory beyond what is provided by this configuration option, then
1311
1552
  ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1312
1553
  **
1313
- ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1554
+ ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1314
1555
  ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1315
- ** the database page cache with the default page cache implemenation.
1556
+ ** the database page cache with the default page cache implementation.
1316
1557
  ** This configuration should not be used if an application-define page
1317
- ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
1558
+ ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1318
1559
  ** There are three arguments to this option: A pointer to 8-byte aligned
1319
1560
  ** memory, the size of each page buffer (sz), and the number of pages (N).
1320
1561
  ** The sz argument should be the size of the largest database page
@@ -1331,7 +1572,7 @@ struct sqlite3_mem_methods {
1331
1572
  ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1332
1573
  ** will be undefined.</dd>
1333
1574
  **
1334
- ** <dt>SQLITE_CONFIG_HEAP</dt>
1575
+ ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1335
1576
  ** <dd> ^This option specifies a static memory buffer that SQLite will use
1336
1577
  ** for all of its dynamic memory allocation needs beyond those provided
1337
1578
  ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
@@ -1344,9 +1585,11 @@ struct sqlite3_mem_methods {
1344
1585
  ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1345
1586
  ** allocator is engaged to handle all of SQLites memory allocation needs.
1346
1587
  ** The first pointer (the memory pointer) must be aligned to an 8-byte
1347
- ** boundary or subsequent behavior of SQLite will be undefined.</dd>
1588
+ ** boundary or subsequent behavior of SQLite will be undefined.
1589
+ ** The minimum allocation size is capped at 2**12. Reasonable values
1590
+ ** for the minimum allocation size are 2**5 through 2**8.</dd>
1348
1591
  **
1349
- ** <dt>SQLITE_CONFIG_MUTEX</dt>
1592
+ ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1350
1593
  ** <dd> ^(This option takes a single argument which is a pointer to an
1351
1594
  ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1352
1595
  ** alternative low-level mutex routines to be used in place
@@ -1358,7 +1601,7 @@ struct sqlite3_mem_methods {
1358
1601
  ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1359
1602
  ** return [SQLITE_ERROR].</dd>
1360
1603
  **
1361
- ** <dt>SQLITE_CONFIG_GETMUTEX</dt>
1604
+ ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1362
1605
  ** <dd> ^(This option takes a single argument which is a pointer to an
1363
1606
  ** instance of the [sqlite3_mutex_methods] structure. The
1364
1607
  ** [sqlite3_mutex_methods]
@@ -1371,7 +1614,7 @@ struct sqlite3_mem_methods {
1371
1614
  ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1372
1615
  ** return [SQLITE_ERROR].</dd>
1373
1616
  **
1374
- ** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1617
+ ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1375
1618
  ** <dd> ^(This option takes two arguments that determine the default
1376
1619
  ** memory allocation for the lookaside memory allocator on each
1377
1620
  ** [database connection]. The first argument is the
@@ -1381,19 +1624,21 @@ struct sqlite3_mem_methods {
1381
1624
  ** verb to [sqlite3_db_config()] can be used to change the lookaside
1382
1625
  ** configuration on individual connections.)^ </dd>
1383
1626
  **
1384
- ** <dt>SQLITE_CONFIG_PCACHE</dt>
1627
+ ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1385
1628
  ** <dd> ^(This option takes a single argument which is a pointer to
1386
- ** an [sqlite3_pcache_methods] object. This object specifies the interface
1629
+ ** an [sqlite3_pcache_methods2] object. This object specifies the interface
1387
1630
  ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1388
1631
  ** object and uses it for page cache memory allocations.</dd>
1389
1632
  **
1390
- ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1633
+ ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1391
1634
  ** <dd> ^(This option takes a single argument which is a pointer to an
1392
- ** [sqlite3_pcache_methods] object. SQLite copies of the current
1635
+ ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1393
1636
  ** page cache implementation into that object.)^ </dd>
1394
1637
  **
1395
- ** <dt>SQLITE_CONFIG_LOG</dt>
1396
- ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1638
+ ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
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
1397
1642
  ** function with a call signature of void(*)(void*,int,const char*),
1398
1643
  ** and a pointer to void. ^If the function pointer is not NULL, it is
1399
1644
  ** invoked by [sqlite3_log()] to process each logging event. ^If the
@@ -1410,6 +1655,74 @@ struct sqlite3_mem_methods {
1410
1655
  ** In a multi-threaded application, the application-defined logger
1411
1656
  ** function must be threadsafe. </dd>
1412
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.
1413
1726
  ** </dl>
1414
1727
  */
1415
1728
  #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
@@ -1425,9 +1738,16 @@ struct sqlite3_mem_methods {
1425
1738
  #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
1426
1739
  /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
1427
1740
  #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
1428
- #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1429
- #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1741
+ #define SQLITE_CONFIG_PCACHE 14 /* no-op */
1742
+ #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
1430
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 */
1431
1751
 
1432
1752
  /*
1433
1753
  ** CAPI3REF: Database Connection Configuration Options
@@ -1447,7 +1767,7 @@ struct sqlite3_mem_methods {
1447
1767
  ** <dd> ^This option takes three additional arguments that determine the
1448
1768
  ** [lookaside memory allocator] configuration for the [database connection].
1449
1769
  ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
1450
- ** pointer to an memory buffer to use for lookaside memory.
1770
+ ** pointer to a memory buffer to use for lookaside memory.
1451
1771
  ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
1452
1772
  ** may be NULL in which case SQLite will allocate the
1453
1773
  ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
@@ -1465,9 +1785,31 @@ struct sqlite3_mem_methods {
1465
1785
  ** memory is in use leaves the configuration unchanged and returns
1466
1786
  ** [SQLITE_BUSY].)^</dd>
1467
1787
  **
1788
+ ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
1789
+ ** <dd> ^This option is used to enable or disable the enforcement of
1790
+ ** [foreign key constraints]. There should be two additional arguments.
1791
+ ** The first argument is an integer which is 0 to disable FK enforcement,
1792
+ ** positive to enable FK enforcement or negative to leave FK enforcement
1793
+ ** unchanged. The second parameter is a pointer to an integer into which
1794
+ ** is written 0 or 1 to indicate whether FK enforcement is off or on
1795
+ ** following this call. The second parameter may be a NULL pointer, in
1796
+ ** which case the FK enforcement setting is not reported back. </dd>
1797
+ **
1798
+ ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
1799
+ ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
1800
+ ** There should be two additional arguments.
1801
+ ** The first argument is an integer which is 0 to disable triggers,
1802
+ ** positive to enable triggers or negative to leave the setting unchanged.
1803
+ ** The second parameter is a pointer to an integer into which
1804
+ ** is written 0 or 1 to indicate whether triggers are disabled or enabled
1805
+ ** following this call. The second parameter may be a NULL pointer, in
1806
+ ** which case the trigger setting is not reported back. </dd>
1807
+ **
1468
1808
  ** </dl>
1469
1809
  */
1470
- #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1810
+ #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1811
+ #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1812
+ #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1471
1813
 
1472
1814
 
1473
1815
  /*
@@ -1482,22 +1824,28 @@ SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
1482
1824
  /*
1483
1825
  ** CAPI3REF: Last Insert Rowid
1484
1826
  **
1485
- ** ^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
1486
1829
  ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
1487
1830
  ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1488
1831
  ** names are not also used by explicitly declared columns. ^If
1489
1832
  ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1490
1833
  ** is another alias for the rowid.
1491
1834
  **
1492
- ** ^This routine returns the [rowid] of the most recent
1493
- ** successful [INSERT] into the database from the [database connection]
1494
- ** in the first argument. ^If no successful [INSERT]s
1495
- ** have ever occurred on that database connection, zero is returned.
1496
- **
1497
- ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
1498
- ** row is returned by this routine as long as the trigger is running.
1499
- ** But once the trigger terminates, the value returned by this routine
1500
- ** reverts to the last value inserted before the trigger fired.)^
1835
+ ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the
1836
+ ** most recent successful [INSERT] into a rowid table or [virtual table]
1837
+ ** on database connection D.
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.
1842
+ **
1843
+ ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1844
+ ** method, then this routine will return the [rowid] of the inserted
1845
+ ** row as long as the trigger or virtual table method is running.
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.)^
1501
1849
  **
1502
1850
  ** ^An [INSERT] that fails due to a constraint violation is not a
1503
1851
  ** successful [INSERT] and does not change the value returned by this
@@ -1682,27 +2030,33 @@ SQLITE_API int sqlite3_complete16(const void *sql);
1682
2030
  /*
1683
2031
  ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
1684
2032
  **
1685
- ** ^This routine sets a callback function that might be invoked whenever
1686
- ** an attempt is made to open a database table that another thread
1687
- ** or process has locked.
2033
+ ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2034
+ ** that might be invoked with argument P whenever
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].
1688
2040
  **
1689
- ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2041
+ ** ^If the busy callback is NULL, then [SQLITE_BUSY]
1690
2042
  ** is returned immediately upon encountering the lock. ^If the busy callback
1691
2043
  ** is not NULL, then the callback might be invoked with two arguments.
1692
2044
  **
1693
2045
  ** ^The first argument to the busy handler is a copy of the void* pointer which
1694
2046
  ** is the third argument to sqlite3_busy_handler(). ^The second argument to
1695
2047
  ** the busy handler callback is the number of times that the busy handler has
1696
- ** been invoked for this locking event. ^If the
2048
+ ** been invoked for the same locking event. ^If the
1697
2049
  ** busy callback returns 0, then no additional attempts are made to
1698
- ** 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.
1699
2052
  ** ^If the callback returns non-zero, then another attempt
1700
- ** is made to open the database for reading and the cycle repeats.
2053
+ ** is made to access the database and the cycle repeats.
1701
2054
  **
1702
2055
  ** The presence of a busy handler does not guarantee that it will be invoked
1703
2056
  ** when there is lock contention. ^If SQLite determines that invoking the busy
1704
2057
  ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
1705
- ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
2058
+ ** to the application instead of invoking the
2059
+ ** busy handler.
1706
2060
  ** Consider a scenario where one process is holding a read lock that
1707
2061
  ** it is trying to promote to a reserved lock and
1708
2062
  ** a second process is holding a reserved lock that it is trying
@@ -1716,28 +2070,15 @@ SQLITE_API int sqlite3_complete16(const void *sql);
1716
2070
  **
1717
2071
  ** ^The default busy callback is NULL.
1718
2072
  **
1719
- ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
1720
- ** when SQLite is in the middle of a large transaction where all the
1721
- ** changes will not fit into the in-memory cache. SQLite will
1722
- ** already hold a RESERVED lock on the database file, but it needs
1723
- ** to promote this lock to EXCLUSIVE so that it can spill cache
1724
- ** pages into the database file without harm to concurrent
1725
- ** readers. ^If it is unable to promote the lock, then the in-memory
1726
- ** cache will be left in an inconsistent state and so the error
1727
- ** code is promoted from the relatively benign [SQLITE_BUSY] to
1728
- ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion
1729
- ** forces an automatic rollback of the changes. See the
1730
- ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
1731
- ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
1732
- ** this is important.
1733
- **
1734
2073
  ** ^(There can only be a single busy handler defined for each
1735
2074
  ** [database connection]. Setting a new busy handler clears any
1736
2075
  ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
1737
- ** 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.
1738
2078
  **
1739
2079
  ** The busy callback should not take any actions which modify the
1740
- ** 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
1741
2082
  ** result in undefined behavior.
1742
2083
  **
1743
2084
  ** A busy handler must not close the database connection
@@ -1753,15 +2094,17 @@ SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
1753
2094
  ** will sleep multiple times until at least "ms" milliseconds of sleeping
1754
2095
  ** have accumulated. ^After at least "ms" milliseconds of sleeping,
1755
2096
  ** the handler returns 0 which causes [sqlite3_step()] to return
1756
- ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
2097
+ ** [SQLITE_BUSY].
1757
2098
  **
1758
2099
  ** ^Calling this routine with an argument less than or equal to zero
1759
2100
  ** turns off all busy handlers.
1760
2101
  **
1761
2102
  ** ^(There can only be a single busy handler for a particular
1762
- ** [database connection] any any given moment. If another busy handler
2103
+ ** [database connection] at any given moment. If another busy handler
1763
2104
  ** was defined (using [sqlite3_busy_handler()]) prior to calling
1764
2105
  ** this routine, that other busy handler is cleared.)^
2106
+ **
2107
+ ** See also: [PRAGMA busy_timeout]
1765
2108
  */
1766
2109
  SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
1767
2110
 
@@ -1886,7 +2229,7 @@ SQLITE_API void sqlite3_free_table(char **result);
1886
2229
  ** All of the usual printf() formatting options apply. In addition, there
1887
2230
  ** is are "%q", "%Q", and "%z" options.
1888
2231
  **
1889
- ** ^(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
1890
2233
  ** string from the argument list. But %q also doubles every '\'' character.
1891
2234
  ** %q is designed for use inside a string literal.)^ By doubling each '\''
1892
2235
  ** character it escapes that character and allows it to be inserted into
@@ -1961,6 +2304,10 @@ SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
1961
2304
  ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
1962
2305
  ** a NULL pointer.
1963
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
+ **
1964
2311
  ** ^Calling sqlite3_free() with a pointer previously returned
1965
2312
  ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
1966
2313
  ** that it might be reused. ^The sqlite3_free() routine is
@@ -1972,24 +2319,38 @@ SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
1972
2319
  ** might result if sqlite3_free() is called with a non-NULL pointer that
1973
2320
  ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
1974
2321
  **
1975
- ** ^(The sqlite3_realloc() interface attempts to resize a
1976
- ** prior memory allocation to be at least N bytes, where N is the
1977
- ** second parameter. The memory allocation to be resized is the first
1978
- ** parameter.)^ ^ If the first parameter to sqlite3_realloc()
2322
+ ** ^The sqlite3_realloc(X,N) interface attempts to resize a
2323
+ ** prior memory allocation X to be at least N bytes.
2324
+ ** ^If the X parameter to sqlite3_realloc(X,N)
1979
2325
  ** is a NULL pointer then its behavior is identical to calling
1980
- ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
1981
- ** ^If the second parameter to sqlite3_realloc() is zero or
2326
+ ** sqlite3_malloc(N).
2327
+ ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
1982
2328
  ** negative then the behavior is exactly the same as calling
1983
- ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
1984
- ** ^sqlite3_realloc() returns a pointer to a memory allocation
1985
- ** of at least N bytes in size or NULL if sufficient memory is unavailable.
2329
+ ** sqlite3_free(X).
2330
+ ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2331
+ ** of at least N bytes in size or NULL if insufficient memory is available.
1986
2332
  ** ^If M is the size of the prior allocation, then min(N,M) bytes
1987
2333
  ** of the prior allocation are copied into the beginning of buffer returned
1988
- ** by sqlite3_realloc() and the prior allocation is freed.
1989
- ** ^If sqlite3_realloc() returns NULL, then the prior allocation
1990
- ** is not freed.
1991
- **
1992
- ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
2334
+ ** by sqlite3_realloc(X,N) and the prior allocation is freed.
2335
+ ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2336
+ ** prior allocation is not freed.
2337
+ **
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()
1993
2354
  ** is always aligned to at least an 8 byte boundary, or to a
1994
2355
  ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
1995
2356
  ** option is used.
@@ -1999,12 +2360,12 @@ SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
1999
2360
  ** implementation of these routines to be omitted. That capability
2000
2361
  ** is no longer provided. Only built-in memory allocators can be used.
2001
2362
  **
2002
- ** The Windows OS interface layer calls
2363
+ ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2003
2364
  ** the system malloc() and free() directly when converting
2004
2365
  ** filenames between the UTF-8 encoding used by SQLite
2005
2366
  ** and whatever filename encoding is used by the particular Windows
2006
- ** installation. Memory allocation errors are detected, but
2007
- ** they are reported back as [SQLITE_CANTOPEN] or
2367
+ ** installation. Memory allocation errors were detected, but
2368
+ ** they were reported back as [SQLITE_CANTOPEN] or
2008
2369
  ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2009
2370
  **
2010
2371
  ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
@@ -2017,8 +2378,11 @@ SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
2017
2378
  ** [sqlite3_free()] or [sqlite3_realloc()].
2018
2379
  */
2019
2380
  SQLITE_API void *sqlite3_malloc(int);
2381
+ SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
2020
2382
  SQLITE_API void *sqlite3_realloc(void*, int);
2383
+ SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
2021
2384
  SQLITE_API void sqlite3_free(void*);
2385
+ SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
2022
2386
 
2023
2387
  /*
2024
2388
  ** CAPI3REF: Memory Allocator Statistics
@@ -2056,11 +2420,13 @@ SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
2056
2420
  ** applications to access the same PRNG for other purposes.
2057
2421
  **
2058
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.
2059
2424
  **
2060
- ** ^The first time this routine is invoked (either internally or by
2061
- ** the application) the PRNG is seeded using randomness obtained
2062
- ** from the xRandomness method of the default [sqlite3_vfs] object.
2063
- ** ^On all subsequent invocations, the pseudo-randomness is generated
2425
+ ** ^If this routine has not been previously called or if the previous
2426
+ ** call had N less than one, then the PRNG is seeded using randomness
2427
+ ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2428
+ ** ^If the previous call to this routine had an N of 1 or more then
2429
+ ** the pseudo-randomness is generated
2064
2430
  ** internally and without recourse to the [sqlite3_vfs] xRandomness
2065
2431
  ** method.
2066
2432
  */
@@ -2069,7 +2435,7 @@ SQLITE_API void sqlite3_randomness(int N, void *P);
2069
2435
  /*
2070
2436
  ** CAPI3REF: Compile-Time Authorization Callbacks
2071
2437
  **
2072
- ** ^This routine registers a authorizer callback with a particular
2438
+ ** ^This routine registers an authorizer callback with a particular
2073
2439
  ** [database connection], supplied in the first argument.
2074
2440
  ** ^The authorizer callback is invoked as SQL statements are being compiled
2075
2441
  ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2160,6 +2526,9 @@ SQLITE_API int sqlite3_set_authorizer(
2160
2526
  ** to signal SQLite whether or not the action is permitted. See the
2161
2527
  ** [sqlite3_set_authorizer | authorizer documentation] for additional
2162
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.
2163
2532
  */
2164
2533
  #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2165
2534
  #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
@@ -2217,6 +2586,7 @@ SQLITE_API int sqlite3_set_authorizer(
2217
2586
  #define SQLITE_FUNCTION 31 /* NULL Function Name */
2218
2587
  #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2219
2588
  #define SQLITE_COPY 0 /* No longer used */
2589
+ #define SQLITE_RECURSIVE 33 /* NULL NULL */
2220
2590
 
2221
2591
  /*
2222
2592
  ** CAPI3REF: Tracing And Profiling Functions
@@ -2232,6 +2602,9 @@ SQLITE_API int sqlite3_set_authorizer(
2232
2602
  ** as each triggered subprogram is entered. The callbacks for triggers
2233
2603
  ** contain a UTF-8 SQL comment that identifies the trigger.)^
2234
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
+ **
2235
2608
  ** ^The callback function registered by sqlite3_profile() is invoked
2236
2609
  ** as each SQL statement finishes. ^The profile callback contains
2237
2610
  ** the original statement text and an estimate of wall-clock time
@@ -2257,9 +2630,10 @@ SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2257
2630
  ** interface is to keep a GUI updated during a large query.
2258
2631
  **
2259
2632
  ** ^The parameter P is passed through as the only parameter to the
2260
- ** callback function X. ^The parameter N is the number of
2633
+ ** callback function X. ^The parameter N is the approximate number of
2261
2634
  ** [virtual machine instructions] that are evaluated between successive
2262
- ** invocations of the callback X.
2635
+ ** invocations of the callback X. ^If N is less than one then the progress
2636
+ ** handler is disabled.
2263
2637
  **
2264
2638
  ** ^Only a single progress handler may be defined at one time per
2265
2639
  ** [database connection]; setting a new progress handler cancels the
@@ -2282,7 +2656,7 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2282
2656
  /*
2283
2657
  ** CAPI3REF: Opening A New Database Connection
2284
2658
  **
2285
- ** ^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
2286
2660
  ** filename argument. ^The filename argument is interpreted as UTF-8 for
2287
2661
  ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2288
2662
  ** order for sqlite3_open16(). ^(A [database connection] handle is usually
@@ -2295,9 +2669,9 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2295
2669
  ** an English language description of the error following a failure of any
2296
2670
  ** of the sqlite3_open() routines.
2297
2671
  **
2298
- ** ^The default encoding for the database will be UTF-8 if
2299
- ** sqlite3_open() or sqlite3_open_v2() is called and
2300
- ** UTF-16 in the native byte order if sqlite3_open16() is used.
2672
+ ** ^The default encoding will be UTF-8 for databases created using
2673
+ ** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
2674
+ ** created using sqlite3_open16() will be UTF-16 in the native byte order.
2301
2675
  **
2302
2676
  ** Whether or not an error occurs when it is opened, resources
2303
2677
  ** associated with the [database connection] handle should be released by
@@ -2309,7 +2683,7 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2309
2683
  ** sqlite3_open_v2() can take one of
2310
2684
  ** the following three values, optionally combined with the
2311
2685
  ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2312
- ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
2686
+ ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
2313
2687
  **
2314
2688
  ** <dl>
2315
2689
  ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
@@ -2328,9 +2702,8 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2328
2702
  ** </dl>
2329
2703
  **
2330
2704
  ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2331
- ** combinations shown above or one of the combinations shown above combined
2332
- ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2333
- ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2705
+ ** combinations shown above optionally combined with other
2706
+ ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
2334
2707
  ** then the behavior is undefined.
2335
2708
  **
2336
2709
  ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
@@ -2345,6 +2718,11 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2345
2718
  ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2346
2719
  ** participate in [shared cache mode] even if it is enabled.
2347
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
+ **
2348
2726
  ** ^If the filename is ":memory:", then a private, temporary in-memory database
2349
2727
  ** is created for the connection. ^This in-memory database will vanish when
2350
2728
  ** the database connection is closed. Future versions of SQLite might
@@ -2357,16 +2735,149 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2357
2735
  ** on-disk database will be created. ^This private database will be
2358
2736
  ** automatically deleted as soon as the database connection is closed.
2359
2737
  **
2360
- ** ^The fourth parameter to sqlite3_open_v2() is the name of the
2361
- ** [sqlite3_vfs] object that defines the operating system interface that
2362
- ** the new database connection should use. ^If the fourth parameter is
2363
- ** a NULL pointer then the default [sqlite3_vfs] object is used.
2738
+ ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
2739
+ **
2740
+ ** ^If [URI filename] interpretation is enabled, and the filename argument
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.
2364
2869
  **
2365
2870
  ** <b>Note to Windows users:</b> The encoding used for the filename argument
2366
2871
  ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
2367
2872
  ** codepage is currently defined. Filenames containing international
2368
2873
  ** characters must be converted to UTF-8 prior to passing them into
2369
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]
2370
2881
  */
2371
2882
  SQLITE_API int sqlite3_open(
2372
2883
  const char *filename, /* Database filename (UTF-8) */
@@ -2383,6 +2894,50 @@ SQLITE_API int sqlite3_open_v2(
2383
2894
  const char *zVfs /* Name of VFS module to use */
2384
2895
  );
2385
2896
 
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 bDefault);
2938
+ SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
2939
+
2940
+
2386
2941
  /*
2387
2942
  ** CAPI3REF: Error Codes And Messages
2388
2943
  **
@@ -2402,6 +2957,11 @@ SQLITE_API int sqlite3_open_v2(
2402
2957
  ** However, the error string might be overwritten or deallocated by
2403
2958
  ** subsequent calls to other SQLite interface functions.)^
2404
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
+ **
2405
2965
  ** When the serialized [threading mode] is in use, it might be the
2406
2966
  ** case that a second error occurs on a separate thread in between
2407
2967
  ** the time of the first error and the call to these interfaces.
@@ -2420,6 +2980,7 @@ SQLITE_API int sqlite3_errcode(sqlite3 *db);
2420
2980
  SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
2421
2981
  SQLITE_API const char *sqlite3_errmsg(sqlite3*);
2422
2982
  SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
2983
+ SQLITE_API const char *sqlite3_errstr(int);
2423
2984
 
2424
2985
  /*
2425
2986
  ** CAPI3REF: SQL Statement Object
@@ -2498,44 +3059,50 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
2498
3059
  ** Additional information is available at [limits | Limits in SQLite].
2499
3060
  **
2500
3061
  ** <dl>
2501
- ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3062
+ ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2502
3063
  ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
2503
3064
  **
2504
- ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3065
+ ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2505
3066
  ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
2506
3067
  **
2507
- ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
3068
+ ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
2508
3069
  ** <dd>The maximum number of columns in a table definition or in the
2509
3070
  ** result set of a [SELECT] or the maximum number of columns in an index
2510
3071
  ** or in an ORDER BY or GROUP BY clause.</dd>)^
2511
3072
  **
2512
- ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
3073
+ ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
2513
3074
  ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
2514
3075
  **
2515
- ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3076
+ ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2516
3077
  ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
2517
3078
  **
2518
- ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3079
+ ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2519
3080
  ** <dd>The maximum number of instructions in a virtual machine program
2520
3081
  ** used to implement an SQL statement. This limit is not currently
2521
3082
  ** enforced, though that might be added in some future release of
2522
3083
  ** SQLite.</dd>)^
2523
3084
  **
2524
- ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3085
+ ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2525
3086
  ** <dd>The maximum number of arguments on a function.</dd>)^
2526
3087
  **
2527
- ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
3088
+ ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
2528
3089
  ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
2529
3090
  **
3091
+ ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
2530
3092
  ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2531
3093
  ** <dd>The maximum length of the pattern argument to the [LIKE] or
2532
3094
  ** [GLOB] operators.</dd>)^
2533
3095
  **
3096
+ ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
2534
3097
  ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2535
3098
  ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
2536
3099
  **
2537
- ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3100
+ ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2538
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>)^
2539
3106
  ** </dl>
2540
3107
  */
2541
3108
  #define SQLITE_LIMIT_LENGTH 0
@@ -2549,6 +3116,7 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
2549
3116
  #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
2550
3117
  #define SQLITE_LIMIT_VARIABLE_NUMBER 9
2551
3118
  #define SQLITE_LIMIT_TRIGGER_DEPTH 10
3119
+ #define SQLITE_LIMIT_WORKER_THREADS 11
2552
3120
 
2553
3121
  /*
2554
3122
  ** CAPI3REF: Compiling An SQL Statement
@@ -2574,7 +3142,8 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
2574
3142
  ** that the supplied string is nul-terminated, then there is a small
2575
3143
  ** performance advantage to be gained by passing an nByte parameter that
2576
3144
  ** is equal to the number of bytes in the input string <i>including</i>
2577
- ** the nul-terminator bytes.
3145
+ ** the nul-terminator bytes as this saves SQLite from having to
3146
+ ** make a copy of the input string.
2578
3147
  **
2579
3148
  ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
2580
3149
  ** past the end of the first SQL statement in zSql. These routines only
@@ -2604,7 +3173,8 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
2604
3173
  ** <li>
2605
3174
  ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
2606
3175
  ** always used to do, [sqlite3_step()] will automatically recompile the SQL
2607
- ** 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.
2608
3178
  ** </li>
2609
3179
  **
2610
3180
  ** <li>
@@ -2625,8 +3195,7 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
2625
3195
  ** ^The specific value of WHERE-clause [parameter] might influence the
2626
3196
  ** choice of query plan if the parameter is the left-hand side of a [LIKE]
2627
3197
  ** or [GLOB] operator or if the parameter is compared to an indexed column
2628
- ** and the [SQLITE_ENABLE_STAT2] compile-time option is enabled.
2629
- ** the
3198
+ ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
2630
3199
  ** </li>
2631
3200
  ** </ol>
2632
3201
  */
@@ -2671,7 +3240,7 @@ SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
2671
3240
  /*
2672
3241
  ** CAPI3REF: Determine If An SQL Statement Writes The Database
2673
3242
  **
2674
- ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3243
+ ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
2675
3244
  ** and only if the [prepared statement] X makes no direct changes to
2676
3245
  ** the content of the database file.
2677
3246
  **
@@ -2699,6 +3268,25 @@ SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
2699
3268
  */
2700
3269
  SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
2701
3270
 
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
+
2702
3290
  /*
2703
3291
  ** CAPI3REF: Dynamically Typed Value Object
2704
3292
  ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
@@ -2715,7 +3303,7 @@ SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
2715
3303
  ** whether or not it requires a protected sqlite3_value.
2716
3304
  **
2717
3305
  ** The terms "protected" and "unprotected" refer to whether or not
2718
- ** a mutex is held. A internal mutex is held for a protected
3306
+ ** a mutex is held. An internal mutex is held for a protected
2719
3307
  ** sqlite3_value object but no mutex is held for an unprotected
2720
3308
  ** sqlite3_value object. If SQLite is compiled to be single-threaded
2721
3309
  ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
@@ -2789,18 +3377,31 @@ typedef struct sqlite3_context sqlite3_context;
2789
3377
  ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
2790
3378
  **
2791
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().
2792
3383
  **
2793
3384
  ** ^(In those routines that have a fourth argument, its value is the
2794
3385
  ** number of bytes in the parameter. To be clear: the value is the
2795
3386
  ** number of <u>bytes</u> in the value, not the number of characters.)^
2796
- ** ^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
2797
3389
  ** the number of bytes up to the first zero terminator.
2798
- **
2799
- ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
2800
- ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
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.
3400
+ **
3401
+ ** ^The fifth argument to the BLOB and string binding interfaces
3402
+ ** is a destructor used to dispose of the BLOB or
2801
3403
  ** string after SQLite has finished with it. ^The destructor is called
2802
- ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
2803
- ** sqlite3_bind_text(), or sqlite3_bind_text16() fails.
3404
+ ** to dispose of the BLOB or string even if the call to bind API fails.
2804
3405
  ** ^If the fifth argument is
2805
3406
  ** the special value [SQLITE_STATIC], then SQLite assumes that the
2806
3407
  ** information is in static, unmanaged space and does not need to be freed.
@@ -2808,6 +3409,14 @@ typedef struct sqlite3_context sqlite3_context;
2808
3409
  ** SQLite makes its own private copy of the data immediately, before
2809
3410
  ** the sqlite3_bind_*() routine returns.
2810
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
+ **
2811
3420
  ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
2812
3421
  ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
2813
3422
  ** (just an integer to hold its size) while it is being processed.
@@ -2828,6 +3437,9 @@ typedef struct sqlite3_context sqlite3_context;
2828
3437
  **
2829
3438
  ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
2830
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].
2831
3443
  ** ^[SQLITE_RANGE] is returned if the parameter
2832
3444
  ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
2833
3445
  **
@@ -2835,12 +3447,16 @@ typedef struct sqlite3_context sqlite3_context;
2835
3447
  ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
2836
3448
  */
2837
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_uint64,
3451
+ void(*)(void*));
2838
3452
  SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
2839
3453
  SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
2840
3454
  SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
2841
3455
  SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
2842
- 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*));
2843
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_uint64,
3459
+ void(*)(void*), unsigned char encoding);
2844
3460
  SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
2845
3461
  SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
2846
3462
 
@@ -2939,7 +3555,9 @@ SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
2939
3555
  ** column number. ^The leftmost column is number 0.
2940
3556
  **
2941
3557
  ** ^The returned string pointer is valid until either the [prepared statement]
2942
- ** is destroyed by [sqlite3_finalize()] or until the next call to
3558
+ ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
3559
+ ** reprepared by the first call to [sqlite3_step()] for a particular run
3560
+ ** or until the next call to
2943
3561
  ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
2944
3562
  **
2945
3563
  ** ^If sqlite3_malloc() fails during the processing of either routine
@@ -2965,7 +3583,9 @@ SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
2965
3583
  ** the database name, the _table_ routines return the table name, and
2966
3584
  ** the origin_ routines return the column name.
2967
3585
  ** ^The returned string is valid until the [prepared statement] is destroyed
2968
- ** using [sqlite3_finalize()] or until the same information is requested
3586
+ ** using [sqlite3_finalize()] or until the statement is automatically
3587
+ ** reprepared by the first call to [sqlite3_step()] for a particular run
3588
+ ** or until the same information is requested
2969
3589
  ** again in a different encoding.
2970
3590
  **
2971
3591
  ** ^The names returned are the original un-aliased names of the
@@ -3059,7 +3679,7 @@ SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
3059
3679
  ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
3060
3680
  ** database locks it needs to do its job. ^If the statement is a [COMMIT]
3061
3681
  ** or occurs outside of an explicit transaction, then you can retry the
3062
- ** 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
3063
3683
  ** explicit transaction then you should rollback the transaction before
3064
3684
  ** continuing.
3065
3685
  **
@@ -3124,6 +3744,12 @@ SQLITE_API int sqlite3_step(sqlite3_stmt*);
3124
3744
  ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
3125
3745
  ** interfaces) then sqlite3_data_count(P) returns 0.
3126
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.
3127
3753
  **
3128
3754
  ** See also: [sqlite3_column_count()]
3129
3755
  */
@@ -3223,7 +3849,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3223
3849
  ** bytes in the string, not the number of characters.
3224
3850
  **
3225
3851
  ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
3226
- ** even empty strings, are always zero terminated. ^The return
3852
+ ** even empty strings, are always zero-terminated. ^The return
3227
3853
  ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
3228
3854
  **
3229
3855
  ** ^The object returned by [sqlite3_column_value()] is an
@@ -3246,19 +3872,19 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3246
3872
  **
3247
3873
  ** <tr><td> NULL <td> INTEGER <td> Result is 0
3248
3874
  ** <tr><td> NULL <td> FLOAT <td> Result is 0.0
3249
- ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer
3250
- ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer
3875
+ ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
3876
+ ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
3251
3877
  ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
3252
3878
  ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
3253
3879
  ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
3254
- ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer
3880
+ ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
3255
3881
  ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
3256
- ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT
3257
- ** <tr><td> TEXT <td> INTEGER <td> Use atoi()
3258
- ** <tr><td> TEXT <td> FLOAT <td> Use atof()
3882
+ ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
3883
+ ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
3884
+ ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
3259
3885
  ** <tr><td> TEXT <td> BLOB <td> No change
3260
- ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi()
3261
- ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof()
3886
+ ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
3887
+ ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
3262
3888
  ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed
3263
3889
  ** </table>
3264
3890
  ** </blockquote>)^
@@ -3314,7 +3940,7 @@ SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
3314
3940
  ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
3315
3941
  ** [sqlite3_finalize()] is called. ^The memory space used to hold strings
3316
3942
  ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned
3317
- ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3943
+ ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
3318
3944
  ** [sqlite3_free()].
3319
3945
  **
3320
3946
  ** ^(If a memory allocation error occurs during the evaluation of any
@@ -3338,7 +3964,7 @@ SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
3338
3964
  ** CAPI3REF: Destroy A Prepared Statement Object
3339
3965
  **
3340
3966
  ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
3341
- ** ^If the most recent evaluation of the statement encountered no errors or
3967
+ ** ^If the most recent evaluation of the statement encountered no errors
3342
3968
  ** or if the statement is never been evaluated, then sqlite3_finalize() returns
3343
3969
  ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
3344
3970
  ** sqlite3_finalize(S) returns the appropriate [error code] or
@@ -3397,7 +4023,7 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
3397
4023
  ** are used to add SQL functions or aggregates or to redefine the behavior
3398
4024
  ** of existing SQL functions or aggregates. The only differences between
3399
4025
  ** these routines are the text encoding expected for
3400
- ** the the second parameter (the name of the function being created)
4026
+ ** the second parameter (the name of the function being created)
3401
4027
  ** and the presence or absence of a destructor callback for
3402
4028
  ** the application data pointer.
3403
4029
  **
@@ -3423,15 +4049,24 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
3423
4049
  **
3424
4050
  ** ^The fourth parameter, eTextRep, specifies what
3425
4051
  ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3426
- ** its parameters. Every SQL function implementation must be able to work
3427
- ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3428
- ** more efficient with one encoding than another. ^An application may
3429
- ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3430
- ** times with the same function but with different values of eTextRep.
4052
+ ** its parameters. The application should set this parameter to
4053
+ ** [SQLITE_UTF16LE] if the function implementation invokes
4054
+ ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
4055
+ ** implementation invokes [sqlite3_value_text16be()] on an input, or
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.
3431
4060
  ** ^When multiple implementations of the same function are available, SQLite
3432
4061
  ** will pick the one that involves the least amount of data conversion.
3433
- ** If there is only a single implementation which does not care what text
3434
- ** encoding is used, then the fourth argument should be [SQLITE_ANY].
4062
+ **
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.
3435
4070
  **
3436
4071
  ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3437
4072
  ** function can gain access to this pointer using [sqlite3_user_data()].)^
@@ -3442,7 +4077,7 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
3442
4077
  ** callback only; NULL pointers must be passed as the xStep and xFinal
3443
4078
  ** parameters. ^An aggregate SQL function requires an implementation of xStep
3444
4079
  ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3445
- ** SQL function or aggregate, pass NULL poiners for all three function
4080
+ ** SQL function or aggregate, pass NULL pointers for all three function
3446
4081
  ** callbacks.
3447
4082
  **
3448
4083
  ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
@@ -3517,9 +4152,19 @@ SQLITE_API int sqlite3_create_function_v2(
3517
4152
  #define SQLITE_UTF16LE 2
3518
4153
  #define SQLITE_UTF16BE 3
3519
4154
  #define SQLITE_UTF16 4 /* Use native byte order */
3520
- #define SQLITE_ANY 5 /* sqlite3_create_function only */
4155
+ #define SQLITE_ANY 5 /* Deprecated */
3521
4156
  #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
3522
4157
 
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
+
3523
4168
  /*
3524
4169
  ** CAPI3REF: Deprecated Functions
3525
4170
  ** DEPRECATED
@@ -3536,7 +4181,8 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
3536
4181
  SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
3537
4182
  SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
3538
4183
  SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
3539
- SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
4184
+ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
4185
+ void*,sqlite3_int64);
3540
4186
  #endif
3541
4187
 
3542
4188
  /*
@@ -3559,7 +4205,7 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6
3559
4205
  ** object results in undefined behavior.
3560
4206
  **
3561
4207
  ** ^These routines work just like the corresponding [column access functions]
3562
- ** except that these routines take a single [protected sqlite3_value] object
4208
+ ** except that these routines take a single [protected sqlite3_value] object
3563
4209
  ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
3564
4210
  **
3565
4211
  ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
@@ -3616,14 +4262,17 @@ SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
3616
4262
  ** In those cases, sqlite3_aggregate_context() might be called for the
3617
4263
  ** first time from within xFinal().)^
3618
4264
  **
3619
- ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
3620
- ** less than or equal to zero or if a memory allocate error occurs.
4265
+ ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
4266
+ ** when first called if N is less than or equal to zero or if a memory
4267
+ ** allocate error occurs.
3621
4268
  **
3622
4269
  ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
3623
4270
  ** determined by the N parameter on first successful call. Changing the
3624
4271
  ** value of N in subsequent call to sqlite3_aggregate_context() within
3625
4272
  ** the same aggregate function instance will not resize the memory
3626
- ** 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.
3627
4276
  **
3628
4277
  ** ^SQLite automatically frees the memory allocated by
3629
4278
  ** sqlite3_aggregate_context() when the aggregate query concludes.
@@ -3666,41 +4315,49 @@ SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
3666
4315
  /*
3667
4316
  ** CAPI3REF: Function Auxiliary Data
3668
4317
  **
3669
- ** The following two functions may be used by scalar SQL functions to
4318
+ ** These functions may be used by (non-aggregate) SQL functions to
3670
4319
  ** associate metadata with argument values. If the same value is passed to
3671
4320
  ** multiple invocations of the same SQL function during query execution, under
3672
- ** some circumstances the associated metadata may be preserved. This may
3673
- ** be used, for example, to add a regular-expression matching scalar
3674
- ** function. The compiled version of the regular expression is stored as
3675
- ** metadata associated with the SQL value passed as the regular expression
3676
- ** pattern. The compiled regular expression can be reused on multiple
3677
- ** invocations of the same function so that the original pattern string
3678
- ** does not need to be recompiled on each invocation.
4321
+ ** some circumstances the associated metadata may be preserved. An example
4322
+ ** of where this might be useful is in a regular-expression matching
4323
+ ** function. The compiled version of the regular expression can be stored as
4324
+ ** metadata associated with the pattern string.
4325
+ ** Then as long as the pattern string remains the same,
4326
+ ** the compiled regular expression can be reused on multiple
4327
+ ** invocations of the same function.
3679
4328
  **
3680
4329
  ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
3681
4330
  ** associated by the sqlite3_set_auxdata() function with the Nth argument
3682
- ** value to the application-defined function. ^If no metadata has been ever
3683
- ** been set for the Nth argument of the function, or if the corresponding
3684
- ** function parameter has changed since the meta-data was set,
3685
- ** then sqlite3_get_auxdata() returns a NULL pointer.
3686
- **
3687
- ** ^The sqlite3_set_auxdata() interface saves the metadata
3688
- ** pointed to by its 3rd parameter as the metadata for the N-th
3689
- ** argument of the application-defined function. Subsequent
3690
- ** calls to sqlite3_get_auxdata() might return this data, if it has
3691
- ** not been destroyed.
3692
- ** ^If it is not NULL, SQLite will invoke the destructor
3693
- ** function given by the 4th parameter to sqlite3_set_auxdata() on
3694
- ** the metadata when the corresponding function parameter changes
3695
- ** or when the SQL statement completes, whichever comes first.
3696
- **
3697
- ** SQLite is free to call the destructor and drop metadata on any
3698
- ** parameter of any function at any time. ^The only guarantee is that
3699
- ** the destructor will be called before the metadata is dropped.
4331
+ ** value to the application-defined function. ^If there is no metadata
4332
+ ** associated with the function argument, this sqlite3_get_auxdata() interface
4333
+ ** returns a NULL pointer.
4334
+ **
4335
+ ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4336
+ ** argument of the application-defined function. ^Subsequent
4337
+ ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
4338
+ ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
4339
+ ** NULL if the metadata has been discarded.
4340
+ ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
4341
+ ** SQLite will invoke the destructor function X with parameter P exactly
4342
+ ** once, when the metadata is discarded.
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>)^
4350
+ **
4351
+ ** Note the last bullet in particular. The destructor X in
4352
+ ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
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.
3700
4357
  **
3701
4358
  ** ^(In practice, metadata is preserved between function calls for
3702
- ** expressions that are constant at compile time. This includes literal
3703
- ** values and [parameters].)^
4359
+ ** function parameters that are compile-time constants, including literal
4360
+ ** values and [parameters] and expressions composed from the same.)^
3704
4361
  **
3705
4362
  ** These routines must be called from the same thread in which
3706
4363
  ** the SQL function is running.
@@ -3721,7 +4378,7 @@ SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(voi
3721
4378
  ** the content before returning.
3722
4379
  **
3723
4380
  ** The typedef is necessary to work around problems in certain
3724
- ** C++ compilers. See ticket #2191.
4381
+ ** C++ compilers.
3725
4382
  */
3726
4383
  typedef void (*sqlite3_destructor_type)(void*);
3727
4384
  #define SQLITE_STATIC ((sqlite3_destructor_type)0)
@@ -3774,11 +4431,11 @@ typedef void (*sqlite3_destructor_type)(void*);
3774
4431
  ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()
3775
4432
  ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
3776
4433
  **
3777
- ** ^The sqlite3_result_toobig() interface causes SQLite to throw an error
3778
- ** indicating that a string or BLOB is too long to represent.
4434
+ ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
4435
+ ** error indicating that a string or BLOB is too long to represent.
3779
4436
  **
3780
- ** ^The sqlite3_result_nomem() interface causes SQLite to throw an error
3781
- ** indicating that a memory allocation failed.
4437
+ ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
4438
+ ** error indicating that a memory allocation failed.
3782
4439
  **
3783
4440
  ** ^The sqlite3_result_int() interface sets the return value
3784
4441
  ** of the application-defined function to be the 32-bit signed integer
@@ -3795,6 +4452,10 @@ typedef void (*sqlite3_destructor_type)(void*);
3795
4452
  ** set the return value of the application-defined function to be
3796
4453
  ** a text string which is represented as UTF-8, UTF-16 native byte order,
3797
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].
3798
4459
  ** ^SQLite takes the text result from the application from
3799
4460
  ** the 2nd parameter of the sqlite3_result_text* interfaces.
3800
4461
  ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
@@ -3803,7 +4464,12 @@ typedef void (*sqlite3_destructor_type)(void*);
3803
4464
  ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
3804
4465
  ** is non-negative, then as many bytes (not characters) of the text
3805
4466
  ** pointed to by the 2nd parameter are taken as the application-defined
3806
- ** 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.
3807
4473
  ** ^If the 4th parameter to the sqlite3_result_text* interfaces
3808
4474
  ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
3809
4475
  ** function as the destructor on the text or BLOB result when it has
@@ -3833,6 +4499,7 @@ typedef void (*sqlite3_destructor_type)(void*);
3833
4499
  ** the [sqlite3_context] pointer, the results are undefined.
3834
4500
  */
3835
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_uint64,void(*)(void*));
3836
4503
  SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
3837
4504
  SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
3838
4505
  SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
@@ -3843,6 +4510,8 @@ SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
3843
4510
  SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
3844
4511
  SQLITE_API void sqlite3_result_null(sqlite3_context*);
3845
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_uint64,
4514
+ void(*)(void*), unsigned char encoding);
3846
4515
  SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
3847
4516
  SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
3848
4517
  SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
@@ -3876,7 +4545,7 @@ SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
3876
4545
  ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
3877
4546
  ** on an even byte address.
3878
4547
  **
3879
- ** ^The fourth argument, pArg, is a application data pointer that is passed
4548
+ ** ^The fourth argument, pArg, is an application data pointer that is passed
3880
4549
  ** through as the first argument to the collating function callback.
3881
4550
  **
3882
4551
  ** ^The fifth argument, xCallback, is a pointer to the collating function.
@@ -3892,7 +4561,7 @@ SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
3892
4561
  ** by the eTextRep argument. The collating function must return an
3893
4562
  ** integer that is negative, zero, or positive
3894
4563
  ** if the first string is less than, equal to, or greater than the second,
3895
- ** respectively. A collating function must alway return the same answer
4564
+ ** respectively. A collating function must always return the same answer
3896
4565
  ** given the same inputs. If two or more collating functions are registered
3897
4566
  ** to the same collation name (using different eTextRep values) then all
3898
4567
  ** must give an equivalent answer when invoked with equivalent strings.
@@ -4000,6 +4669,11 @@ SQLITE_API int sqlite3_key(
4000
4669
  sqlite3 *db, /* Database to be rekeyed */
4001
4670
  const void *pKey, int nKey /* The key */
4002
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
+ );
4003
4677
 
4004
4678
  /*
4005
4679
  ** Change the key on an open database. If the current database is not
@@ -4013,6 +4687,11 @@ SQLITE_API int sqlite3_rekey(
4013
4687
  sqlite3 *db, /* Database to be rekeyed */
4014
4688
  const void *pKey, int nKey /* The new key */
4015
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
+ );
4016
4695
 
4017
4696
  /*
4018
4697
  ** Specify the activation key for a SEE database. Unless
@@ -4062,6 +4741,13 @@ SQLITE_API int sqlite3_sleep(int);
4062
4741
  ** is a NULL pointer, then SQLite performs a search for an appropriate
4063
4742
  ** temporary file directory.
4064
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
+ **
4065
4751
  ** It is not safe to read or modify this variable in more than one
4066
4752
  ** thread at a time. It is not safe to read or modify this variable
4067
4753
  ** if a [database connection] is being used at the same time in a separate
@@ -4080,9 +4766,66 @@ SQLITE_API int sqlite3_sleep(int);
4080
4766
  ** Hence, if this variable is modified directly, either it should be
4081
4767
  ** made NULL or made to point to memory obtained from [sqlite3_malloc]
4082
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>
4083
4789
  */
4084
4790
  SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
4085
4791
 
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
+
4086
4829
  /*
4087
4830
  ** CAPI3REF: Test For Auto-Commit Mode
4088
4831
  ** KEYWORDS: {autocommit mode}
@@ -4118,6 +4861,31 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3*);
4118
4861
  */
4119
4862
  SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
4120
4863
 
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
+
4121
4889
  /*
4122
4890
  ** CAPI3REF: Find the next prepared statement
4123
4891
  **
@@ -4153,13 +4921,15 @@ SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
4153
4921
  ** on the same [database connection] D, or NULL for
4154
4922
  ** the first call for each function on D.
4155
4923
  **
4924
+ ** The commit and rollback hook callbacks are not reentrant.
4156
4925
  ** The callback implementation must not do anything that will modify
4157
4926
  ** the database connection that invoked the callback. Any actions
4158
4927
  ** to modify the database connection must be deferred until after the
4159
4928
  ** completion of the [sqlite3_step()] call that triggered the commit
4160
4929
  ** or rollback hook in the first place.
4161
- ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
4162
- ** database connections for the meaning of "modify" in this paragraph.
4930
+ ** Note that running any other SQL statements, including SELECT statements,
4931
+ ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
4932
+ ** the database connections for the meaning of "modify" in this paragraph.
4163
4933
  **
4164
4934
  ** ^Registering a NULL function disables the callback.
4165
4935
  **
@@ -4185,12 +4955,13 @@ SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
4185
4955
  **
4186
4956
  ** ^The sqlite3_update_hook() interface registers a callback function
4187
4957
  ** with the [database connection] identified by the first argument
4188
- ** 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.
4189
4960
  ** ^Any callback set by a previous call to this function
4190
4961
  ** for the same database connection is overridden.
4191
4962
  **
4192
4963
  ** ^The second argument is a pointer to the function to invoke when a
4193
- ** row is updated, inserted or deleted.
4964
+ ** row is updated, inserted or deleted in a rowid table.
4194
4965
  ** ^The first argument to the callback is a copy of the third argument
4195
4966
  ** to sqlite3_update_hook().
4196
4967
  ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
@@ -4203,6 +4974,7 @@ SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
4203
4974
  **
4204
4975
  ** ^(The update hook is not invoked when internal system tables are
4205
4976
  ** modified (i.e. sqlite_master and sqlite_sequence).)^
4977
+ ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
4206
4978
  **
4207
4979
  ** ^In the current implementation, the update hook
4208
4980
  ** is not invoked when duplication rows are deleted because of an
@@ -4234,7 +5006,6 @@ SQLITE_API void *sqlite3_update_hook(
4234
5006
 
4235
5007
  /*
4236
5008
  ** CAPI3REF: Enable Or Disable Shared Pager Cache
4237
- ** KEYWORDS: {shared cache}
4238
5009
  **
4239
5010
  ** ^(This routine enables or disables the sharing of the database cache
4240
5011
  ** and schema data structures between [database connection | connections]
@@ -4257,6 +5028,9 @@ SQLITE_API void *sqlite3_update_hook(
4257
5028
  ** future releases of SQLite. Applications that care about shared
4258
5029
  ** cache setting should set it explicitly.
4259
5030
  **
5031
+ ** This interface is threadsafe on processors where writing a
5032
+ ** 32-bit integer is atomic.
5033
+ **
4260
5034
  ** See Also: [SQLite Shared-Cache Mode]
4261
5035
  */
4262
5036
  SQLITE_API int sqlite3_enable_shared_cache(int);
@@ -4272,9 +5046,24 @@ SQLITE_API int sqlite3_enable_shared_cache(int);
4272
5046
  ** which might be more or less than the amount requested.
4273
5047
  ** ^The sqlite3_release_memory() routine is a no-op returning zero
4274
5048
  ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
5049
+ **
5050
+ ** See also: [sqlite3_db_release_memory()]
4275
5051
  */
4276
5052
  SQLITE_API int sqlite3_release_memory(int);
4277
5053
 
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
+
4278
5067
  /*
4279
5068
  ** CAPI3REF: Impose A Limit On Heap Size
4280
5069
  **
@@ -4289,7 +5078,8 @@ SQLITE_API int sqlite3_release_memory(int);
4289
5078
  ** is advisory only.
4290
5079
  **
4291
5080
  ** ^The return value from sqlite3_soft_heap_limit64() is the size of
4292
- ** 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
4293
5083
  ** then no change is made to the soft heap limit. Hence, the current
4294
5084
  ** size of the soft heap limit can be determined by invoking
4295
5085
  ** sqlite3_soft_heap_limit64() with a negative argument.
@@ -4304,8 +5094,8 @@ SQLITE_API int sqlite3_release_memory(int);
4304
5094
  ** <li> Memory accounting is disabled using a combination of the
4305
5095
  ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
4306
5096
  ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
4307
- ** <li> An alternative page cache implementation is specifed using
4308
- ** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
5097
+ ** <li> An alternative page cache implementation is specified using
5098
+ ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
4309
5099
  ** <li> The page cache allocates from its own memory pool supplied
4310
5100
  ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
4311
5101
  ** from the heap.
@@ -4418,11 +5208,20 @@ SQLITE_API int sqlite3_table_column_metadata(
4418
5208
  ** ^This interface loads an SQLite extension library from the named file.
4419
5209
  **
4420
5210
  ** ^The sqlite3_load_extension() interface attempts to load an
4421
- ** 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.
4422
5217
  **
4423
5218
  ** ^The entry point is zProc.
4424
- ** ^zProc may be 0, in which case the name of the entry point
4425
- ** defaults to "sqlite3_extension_init".
5219
+ ** ^(zProc may be 0, in which case SQLite will try to come up with an
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".)^
4426
5225
  ** ^The sqlite3_load_extension() interface returns
4427
5226
  ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
4428
5227
  ** ^If an error occurs and pzErrMsg is not 0, then the
@@ -4448,11 +5247,11 @@ SQLITE_API int sqlite3_load_extension(
4448
5247
  ** CAPI3REF: Enable Or Disable Extension Loading
4449
5248
  **
4450
5249
  ** ^So as not to open security holes in older applications that are
4451
- ** unprepared to deal with extension loading, and as a means of disabling
4452
- ** extension loading while evaluating user-entered SQL, the following API
5250
+ ** unprepared to deal with [extension loading], and as a means of disabling
5251
+ ** [extension loading] while evaluating user-entered SQL, the following API
4453
5252
  ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
4454
5253
  **
4455
- ** ^Extension loading is off by default. See ticket #1863.
5254
+ ** ^Extension loading is off by default.
4456
5255
  ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
4457
5256
  ** to turn extension loading on and call it with onoff==0 to turn
4458
5257
  ** it back off again.
@@ -4464,7 +5263,7 @@ SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4464
5263
  **
4465
5264
  ** ^This interface causes the xEntryPoint() function to be invoked for
4466
5265
  ** each new [database connection] that is created. The idea here is that
4467
- ** xEntryPoint() is the entry point for a statically linked SQLite extension
5266
+ ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
4468
5267
  ** that is to be automatically loaded into all new database connections.
4469
5268
  **
4470
5269
  ** ^(Even though the function prototype shows that xEntryPoint() takes
@@ -4492,10 +5291,23 @@ SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
4492
5291
  ** on the list of automatic extensions is a harmless no-op. ^No entry point
4493
5292
  ** will be called more than once for each database connection that is opened.
4494
5293
  **
4495
- ** See also: [sqlite3_reset_auto_extension()].
5294
+ ** See also: [sqlite3_reset_auto_extension()]
5295
+ ** and [sqlite3_cancel_auto_extension()]
4496
5296
  */
4497
5297
  SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
4498
5298
 
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
+
4499
5311
  /*
4500
5312
  ** CAPI3REF: Reset Automatic Extension Loading
4501
5313
  **
@@ -4525,7 +5337,7 @@ typedef struct sqlite3_module sqlite3_module;
4525
5337
  ** CAPI3REF: Virtual Table Object
4526
5338
  ** KEYWORDS: sqlite3_module {virtual table module}
4527
5339
  **
4528
- ** This structure, sometimes called a a "virtual table module",
5340
+ ** This structure, sometimes called a "virtual table module",
4529
5341
  ** defines the implementation of a [virtual tables].
4530
5342
  ** This structure consists mostly of methods for the module.
4531
5343
  **
@@ -4565,6 +5377,11 @@ struct sqlite3_module {
4565
5377
  void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
4566
5378
  void **ppArg);
4567
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);
4568
5385
  };
4569
5386
 
4570
5387
  /*
@@ -4615,10 +5432,22 @@ struct sqlite3_module {
4615
5432
  ** the correct order to satisfy the ORDER BY clause so that no separate
4616
5433
  ** sorting step is required.
4617
5434
  **
4618
- ** ^The estimatedCost value is an estimate of the cost of doing the
4619
- ** particular lookup. A full scan of a table with N entries should have
4620
- ** a cost of N. A binary search of a table of N entries should have a
4621
- ** cost of approximately log(N).
5435
+ ** ^The estimatedCost value is an estimate of the cost of a particular
5436
+ ** strategy. A cost of N indicates that the cost of the strategy is similar
5437
+ ** to a linear scan of an SQLite table with N rows. A cost of 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.
4622
5451
  */
4623
5452
  struct sqlite3_index_info {
4624
5453
  /* Inputs */
@@ -4643,7 +5472,9 @@ struct sqlite3_index_info {
4643
5472
  char *idxStr; /* String, possibly obtained from sqlite3_malloc */
4644
5473
  int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
4645
5474
  int orderByConsumed; /* True if output is already ordered */
4646
- 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 */
4647
5478
  };
4648
5479
 
4649
5480
  /*
@@ -4837,7 +5668,7 @@ typedef struct sqlite3_blob sqlite3_blob;
4837
5668
  ** This is true if any column of the row is changed, even a column
4838
5669
  ** other than the one the BLOB handle is open on.)^
4839
5670
  ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
4840
- ** a expired BLOB handle fail with an return code of [SQLITE_ABORT].
5671
+ ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
4841
5672
  ** ^(Changes written into a BLOB prior to the BLOB expiring are not
4842
5673
  ** rolled back by the expiration of the BLOB. Such changes will eventually
4843
5674
  ** commit if the transaction continues to completion.)^
@@ -4847,6 +5678,9 @@ typedef struct sqlite3_blob sqlite3_blob;
4847
5678
  ** interface. Use the [UPDATE] SQL command to change the size of a
4848
5679
  ** blob.
4849
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
+ **
4850
5684
  ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
4851
5685
  ** and the built-in [zeroblob] SQL function can be used, if desired,
4852
5686
  ** to create an empty, zero-filled blob in which to read or write using
@@ -5041,17 +5875,16 @@ SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
5041
5875
  ** implementations are available in the SQLite core:
5042
5876
  **
5043
5877
  ** <ul>
5044
- ** <li> SQLITE_MUTEX_OS2
5045
- ** <li> SQLITE_MUTEX_PTHREAD
5878
+ ** <li> SQLITE_MUTEX_PTHREADS
5046
5879
  ** <li> SQLITE_MUTEX_W32
5047
5880
  ** <li> SQLITE_MUTEX_NOOP
5048
5881
  ** </ul>)^
5049
5882
  **
5050
5883
  ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
5051
5884
  ** that does no real locking and is appropriate for use in
5052
- ** a single-threaded application. ^The SQLITE_MUTEX_OS2,
5053
- ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
5054
- ** are appropriate for use on OS/2, Unix, and Windows.
5885
+ ** a single-threaded application. ^The SQLITE_MUTEX_PTHREADS and
5886
+ ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
5887
+ ** and Windows.
5055
5888
  **
5056
5889
  ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
5057
5890
  ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
@@ -5072,10 +5905,12 @@ SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
5072
5905
  ** <li> SQLITE_MUTEX_RECURSIVE
5073
5906
  ** <li> SQLITE_MUTEX_STATIC_MASTER
5074
5907
  ** <li> SQLITE_MUTEX_STATIC_MEM
5075
- ** <li> SQLITE_MUTEX_STATIC_MEM2
5908
+ ** <li> SQLITE_MUTEX_STATIC_OPEN
5076
5909
  ** <li> SQLITE_MUTEX_STATIC_PRNG
5077
5910
  ** <li> SQLITE_MUTEX_STATIC_LRU
5078
- ** <li> SQLITE_MUTEX_STATIC_LRU2
5911
+ ** <li> SQLITE_MUTEX_STATIC_PMEM
5912
+ ** <li> SQLITE_MUTEX_STATIC_APP1
5913
+ ** <li> SQLITE_MUTEX_STATIC_APP2
5079
5914
  ** </ul>)^
5080
5915
  **
5081
5916
  ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
@@ -5240,14 +6075,14 @@ struct sqlite3_mutex_methods {
5240
6075
  ** ^These routines should return true if the mutex in their argument
5241
6076
  ** is held or not held, respectively, by the calling thread.
5242
6077
  **
5243
- ** ^The implementation is not required to provided versions of these
6078
+ ** ^The implementation is not required to provide versions of these
5244
6079
  ** routines that actually work. If the implementation does not provide working
5245
6080
  ** versions of these routines, it should at least provide stubs that always
5246
6081
  ** return true so that one does not get spurious assertion failures.
5247
6082
  **
5248
6083
  ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
5249
6084
  ** the routine should return 1. This seems counter-intuitive since
5250
- ** 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
5251
6086
  ** the reason the mutex does not exist is because the build is not
5252
6087
  ** using mutexes. And we do not want the assert() containing the
5253
6088
  ** call to sqlite3_mutex_held() to fail, so a non-zero return is
@@ -5279,6 +6114,9 @@ SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
5279
6114
  #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
5280
6115
  #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */
5281
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 */
5282
6120
 
5283
6121
  /*
5284
6122
  ** CAPI3REF: Retrieve the mutex for a database connection
@@ -5368,9 +6206,15 @@ SQLITE_API int sqlite3_test_control(int op, ...);
5368
6206
  #define SQLITE_TESTCTRL_RESERVE 14
5369
6207
  #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
5370
6208
  #define SQLITE_TESTCTRL_ISKEYWORD 16
5371
- #define SQLITE_TESTCTRL_PGHDRSZ 17
5372
- #define SQLITE_TESTCTRL_SCRATCHMALLOC 18
5373
- #define SQLITE_TESTCTRL_LAST 18
6209
+ #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6210
+ #define SQLITE_TESTCTRL_LOCALTIME_FAULT 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
5374
6218
 
5375
6219
  /*
5376
6220
  ** CAPI3REF: SQLite Runtime Status
@@ -5379,7 +6223,7 @@ SQLITE_API int sqlite3_test_control(int op, ...);
5379
6223
  ** about the performance of SQLite, and optionally to reset various
5380
6224
  ** highwater marks. ^The first argument is an integer code for
5381
6225
  ** the specific parameter to measure. ^(Recognized integer codes
5382
- ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
6226
+ ** are of the form [status parameters | SQLITE_STATUS_...].)^
5383
6227
  ** ^The current value of the parameter is returned into *pCurrent.
5384
6228
  ** ^The highest recorded value is returned in *pHighwater. ^If the
5385
6229
  ** resetFlag is true, then the highest record value is reset after
@@ -5406,12 +6250,13 @@ SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
5406
6250
 
5407
6251
  /*
5408
6252
  ** CAPI3REF: Status Parameters
6253
+ ** KEYWORDS: {status parameters}
5409
6254
  **
5410
6255
  ** These integer constants designate various run-time status parameters
5411
6256
  ** that can be returned by [sqlite3_status()].
5412
6257
  **
5413
6258
  ** <dl>
5414
- ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
6259
+ ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
5415
6260
  ** <dd>This parameter is the current amount of memory checked out
5416
6261
  ** using [sqlite3_malloc()], either directly or indirectly. The
5417
6262
  ** figure includes calls made to [sqlite3_malloc()] by the application
@@ -5421,23 +6266,24 @@ SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
5421
6266
  ** this parameter. The amount returned is the sum of the allocation
5422
6267
  ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
5423
6268
  **
5424
- ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
6269
+ ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
5425
6270
  ** <dd>This parameter records the largest memory allocation request
5426
6271
  ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5427
6272
  ** internal equivalents). Only the value returned in the
5428
6273
  ** *pHighwater parameter to [sqlite3_status()] is of interest.
5429
6274
  ** The value written into the *pCurrent parameter is undefined.</dd>)^
5430
6275
  **
5431
- ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
6276
+ ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5432
6277
  ** <dd>This parameter records the number of separate memory allocations
5433
6278
  ** currently checked out.</dd>)^
5434
6279
  **
5435
- ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
6280
+ ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5436
6281
  ** <dd>This parameter returns the number of pages used out of the
5437
6282
  ** [pagecache memory allocator] that was configured using
5438
6283
  ** [SQLITE_CONFIG_PAGECACHE]. The
5439
6284
  ** value returned is in pages, not in bytes.</dd>)^
5440
6285
  **
6286
+ ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
5441
6287
  ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5442
6288
  ** <dd>This parameter returns the number of bytes of page cache
5443
6289
  ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
@@ -5447,13 +6293,13 @@ SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
5447
6293
  ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5448
6294
  ** no space was left in the page cache.</dd>)^
5449
6295
  **
5450
- ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
6296
+ ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
5451
6297
  ** <dd>This parameter records the largest memory allocation request
5452
6298
  ** handed to [pagecache memory allocator]. Only the value returned in the
5453
6299
  ** *pHighwater parameter to [sqlite3_status()] is of interest.
5454
6300
  ** The value written into the *pCurrent parameter is undefined.</dd>)^
5455
6301
  **
5456
- ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
6302
+ ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
5457
6303
  ** <dd>This parameter returns the number of allocations used out of the
5458
6304
  ** [scratch memory allocator] configured using
5459
6305
  ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
@@ -5461,7 +6307,7 @@ SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
5461
6307
  ** outstanding at time, this parameter also reports the number of threads
5462
6308
  ** using scratch memory at the same time.</dd>)^
5463
6309
  **
5464
- ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
6310
+ ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5465
6311
  ** <dd>This parameter returns the number of bytes of scratch memory
5466
6312
  ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
5467
6313
  ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
@@ -5471,13 +6317,13 @@ SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
5471
6317
  ** slots were available.
5472
6318
  ** </dd>)^
5473
6319
  **
5474
- ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
6320
+ ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
5475
6321
  ** <dd>This parameter records the largest memory allocation request
5476
6322
  ** handed to [scratch memory allocator]. Only the value returned in the
5477
6323
  ** *pHighwater parameter to [sqlite3_status()] is of interest.
5478
6324
  ** The value written into the *pCurrent parameter is undefined.</dd>)^
5479
6325
  **
5480
- ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
6326
+ ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
5481
6327
  ** <dd>This parameter records the deepest parser stack. It is only
5482
6328
  ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
5483
6329
  ** </dl>
@@ -5502,9 +6348,9 @@ SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetF
5502
6348
  ** about a single [database connection]. ^The first argument is the
5503
6349
  ** database connection object to be interrogated. ^The second argument
5504
6350
  ** is an integer constant, taken from the set of
5505
- ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
6351
+ ** [SQLITE_DBSTATUS options], that
5506
6352
  ** determines the parameter to interrogate. The set of
5507
- ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
6353
+ ** [SQLITE_DBSTATUS options] is likely
5508
6354
  ** to grow in future releases of SQLite.
5509
6355
  **
5510
6356
  ** ^The current value of the requested parameter is written into *pCur
@@ -5521,6 +6367,7 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
5521
6367
 
5522
6368
  /*
5523
6369
  ** CAPI3REF: Status Parameters for database connections
6370
+ ** KEYWORDS: {SQLITE_DBSTATUS options}
5524
6371
  **
5525
6372
  ** These constants are the available integer "verbs" that can be passed as
5526
6373
  ** the second argument to the [sqlite3_db_status()] interface.
@@ -5532,39 +6379,38 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
5532
6379
  ** if a discontinued or unsupported verb is invoked.
5533
6380
  **
5534
6381
  ** <dl>
5535
- ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6382
+ ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5536
6383
  ** <dd>This parameter returns the number of lookaside memory slots currently
5537
6384
  ** checked out.</dd>)^
5538
6385
  **
5539
- ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6386
+ ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5540
6387
  ** <dd>This parameter returns the number malloc attempts that were
5541
6388
  ** satisfied using lookaside memory. Only the high-water value is meaningful;
5542
- ** the current value is always zero.
5543
- ** checked out.</dd>)^
6389
+ ** the current value is always zero.)^
5544
6390
  **
6391
+ ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
5545
6392
  ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5546
6393
  ** <dd>This parameter returns the number malloc attempts that might have
5547
6394
  ** been satisfied using lookaside memory but failed due to the amount of
5548
6395
  ** memory requested being larger than the lookaside slot size.
5549
6396
  ** Only the high-water value is meaningful;
5550
- ** the current value is always zero.
5551
- ** checked out.</dd>)^
6397
+ ** the current value is always zero.)^
5552
6398
  **
6399
+ ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
5553
6400
  ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5554
6401
  ** <dd>This parameter returns the number malloc attempts that might have
5555
6402
  ** been satisfied using lookaside memory but failed due to all lookaside
5556
6403
  ** memory already being in use.
5557
6404
  ** Only the high-water value is meaningful;
5558
- ** the current value is always zero.
5559
- ** checked out.</dd>)^
6405
+ ** the current value is always zero.)^
5560
6406
  **
5561
- ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5562
- ** <dd>This parameter returns the approximate number of of bytes of heap
6407
+ ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6408
+ ** <dd>This parameter returns the approximate number of bytes of heap
5563
6409
  ** memory used by all pager caches associated with the database connection.)^
5564
6410
  ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5565
6411
  **
5566
- ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5567
- ** <dd>This parameter returns the approximate number of of bytes of heap
6412
+ ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6413
+ ** <dd>This parameter returns the approximate number of bytes of heap
5568
6414
  ** memory used to store the schema for all databases associated
5569
6415
  ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5570
6416
  ** ^The full amount of memory used by the schemas is reported, even if the
@@ -5572,12 +6418,41 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
5572
6418
  ** [shared cache mode] being enabled.
5573
6419
  ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5574
6420
  **
5575
- ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5576
- ** <dd>This parameter returns the approximate number of of bytes of heap
6421
+ ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6422
+ ** <dd>This parameter returns the approximate number of bytes of heap
5577
6423
  ** and lookaside memory used by all prepared statements associated with
5578
6424
  ** the database connection.)^
5579
6425
  ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5580
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>
5581
6456
  ** </dl>
5582
6457
  */
5583
6458
  #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
@@ -5587,14 +6462,18 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
5587
6462
  #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4
5588
6463
  #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5
5589
6464
  #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6
5590
- #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 */
5591
6470
 
5592
6471
 
5593
6472
  /*
5594
6473
  ** CAPI3REF: Prepared Statement Status
5595
6474
  **
5596
6475
  ** ^(Each prepared statement maintains various
5597
- ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
6476
+ ** [SQLITE_STMTSTATUS counters] that measure the number
5598
6477
  ** of times it has performed specific operations.)^ These counters can
5599
6478
  ** be used to monitor the performance characteristics of the prepared
5600
6479
  ** statements. For example, if the number of table steps greatly exceeds
@@ -5605,7 +6484,7 @@ SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int r
5605
6484
  ** ^(This interface is used to retrieve and reset counter values from
5606
6485
  ** a [prepared statement]. The first argument is the prepared statement
5607
6486
  ** object to be interrogated. The second argument
5608
- ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
6487
+ ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
5609
6488
  ** to be interrogated.)^
5610
6489
  ** ^The current value of the requested counter is returned.
5611
6490
  ** ^If the resetFlg is true, then the counter is reset to zero after this
@@ -5617,35 +6496,45 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5617
6496
 
5618
6497
  /*
5619
6498
  ** CAPI3REF: Status Parameters for prepared statements
6499
+ ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
5620
6500
  **
5621
6501
  ** These preprocessor macros define integer codes that name counter
5622
6502
  ** values associated with the [sqlite3_stmt_status()] interface.
5623
6503
  ** The meanings of the various counters are as follows:
5624
6504
  **
5625
6505
  ** <dl>
5626
- ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
6506
+ ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
5627
6507
  ** <dd>^This is the number of times that SQLite has stepped forward in
5628
6508
  ** a table as part of a full table scan. Large numbers for this counter
5629
6509
  ** may indicate opportunities for performance improvement through
5630
6510
  ** careful use of indices.</dd>
5631
6511
  **
5632
- ** <dt>SQLITE_STMTSTATUS_SORT</dt>
6512
+ ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
5633
6513
  ** <dd>^This is the number of sort operations that have occurred.
5634
6514
  ** A non-zero value in this counter may indicate an opportunity to
5635
6515
  ** improvement performance through careful use of indices.</dd>
5636
6516
  **
5637
- ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
6517
+ ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5638
6518
  ** <dd>^This is the number of rows inserted into transient indices that
5639
6519
  ** were created automatically in order to help joins run faster.
5640
6520
  ** A non-zero value in this counter may indicate an opportunity to
5641
6521
  ** improvement performance by adding permanent indices that do not
5642
6522
  ** need to be reinitialized each time the statement is run.</dd>
5643
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>
5644
6532
  ** </dl>
5645
6533
  */
5646
6534
  #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5647
6535
  #define SQLITE_STMTSTATUS_SORT 2
5648
6536
  #define SQLITE_STMTSTATUS_AUTOINDEX 3
6537
+ #define SQLITE_STMTSTATUS_VM_STEP 4
5649
6538
 
5650
6539
  /*
5651
6540
  ** CAPI3REF: Custom Page Cache Object
@@ -5656,17 +6545,33 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5656
6545
  ** sqlite3_pcache object except by holding and passing pointers
5657
6546
  ** to the object.
5658
6547
  **
5659
- ** See [sqlite3_pcache_methods] for additional information.
6548
+ ** See [sqlite3_pcache_methods2] for additional information.
5660
6549
  */
5661
6550
  typedef struct sqlite3_pcache sqlite3_pcache;
5662
6551
 
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
+
5663
6568
  /*
5664
6569
  ** CAPI3REF: Application Defined Page Cache.
5665
6570
  ** KEYWORDS: {page cache}
5666
6571
  **
5667
- ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
6572
+ ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
5668
6573
  ** register an alternative page cache implementation by passing in an
5669
- ** instance of the sqlite3_pcache_methods structure.)^
6574
+ ** instance of the sqlite3_pcache_methods2 structure.)^
5670
6575
  ** In many applications, most of the heap memory allocated by
5671
6576
  ** SQLite is used for the page cache.
5672
6577
  ** By implementing a
@@ -5680,21 +6585,23 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5680
6585
  ** extreme measure that is only needed by the most demanding applications.
5681
6586
  ** The built-in page cache is recommended for most uses.
5682
6587
  **
5683
- ** ^(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
5684
6589
  ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
5685
6590
  ** the application may discard the parameter after the call to
5686
6591
  ** [sqlite3_config()] returns.)^
5687
6592
  **
6593
+ ** [[the xInit() page cache method]]
5688
6594
  ** ^(The xInit() method is called once for each effective
5689
6595
  ** call to [sqlite3_initialize()])^
5690
6596
  ** (usually only once during the lifetime of the process). ^(The xInit()
5691
- ** 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.)^
5692
6598
  ** The intent of the xInit() method is to set up global data structures
5693
6599
  ** required by the custom page cache implementation.
5694
6600
  ** ^(If the xInit() method is NULL, then the
5695
6601
  ** built-in default page cache is used instead of the application defined
5696
6602
  ** page cache.)^
5697
6603
  **
6604
+ ** [[the xShutdown() page cache method]]
5698
6605
  ** ^The xShutdown() method is called by [sqlite3_shutdown()].
5699
6606
  ** It can be used to clean up
5700
6607
  ** any outstanding resources before process shutdown, if required.
@@ -5709,21 +6616,20 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5709
6616
  ** ^SQLite will never invoke xInit() more than once without an intervening
5710
6617
  ** call to xShutdown().
5711
6618
  **
6619
+ ** [[the xCreate() page cache methods]]
5712
6620
  ** ^SQLite invokes the xCreate() method to construct a new cache instance.
5713
6621
  ** SQLite will typically create one cache instance for each open database file,
5714
6622
  ** though this is not guaranteed. ^The
5715
6623
  ** first parameter, szPage, is the size in bytes of the pages that must
5716
- ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
5717
- ** will the page size of the database file that is to be cached plus an
5718
- ** increment (here called "R") of less than 250. SQLite will use the
5719
- ** extra R bytes on each page to store metadata about the underlying
5720
- ** database page on disk. The value of R depends
6624
+ ** be allocated by the cache. ^szPage will always a power of two. ^The
6625
+ ** second parameter szExtra is a number of bytes of extra storage
6626
+ ** associated with each page cache entry. ^The szExtra parameter will
6627
+ ** a number less than 250. SQLite will use the
6628
+ ** extra szExtra bytes on each page to store metadata about the underlying
6629
+ ** database page on disk. The value passed into szExtra depends
5721
6630
  ** on the SQLite version, the target platform, and how SQLite was compiled.
5722
- ** ^(R is constant for a particular build of SQLite. Except, there are two
5723
- ** distinct values of R when SQLite is compiled with the proprietary
5724
- ** ZIPVFS extension.)^ ^The second argument to
5725
- ** xCreate(), bPurgeable, is true if the cache being created will
5726
- ** be used to cache database pages of a file stored on disk, or
6631
+ ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
6632
+ ** created will be used to cache database pages of a file stored on disk, or
5727
6633
  ** false if it is used for an in-memory database. The cache implementation
5728
6634
  ** does not have to do anything special based with the value of bPurgeable;
5729
6635
  ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
@@ -5733,6 +6639,7 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5733
6639
  ** ^Hence, a cache created with bPurgeable false will
5734
6640
  ** never contain any unpinned pages.
5735
6641
  **
6642
+ ** [[the xCachesize() page cache method]]
5736
6643
  ** ^(The xCachesize() method may be called at any time by SQLite to set the
5737
6644
  ** suggested maximum cache-size (number of pages stored by) the cache
5738
6645
  ** instance passed as the first argument. This is the value configured using
@@ -5740,15 +6647,22 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5740
6647
  ** parameter, the implementation is not required to do anything with this
5741
6648
  ** value; it is advisory only.
5742
6649
  **
6650
+ ** [[the xPagecount() page cache methods]]
5743
6651
  ** The xPagecount() method must return the number of pages currently
5744
6652
  ** stored in the cache, both pinned and unpinned.
5745
6653
  **
6654
+ ** [[the xFetch() page cache methods]]
5746
6655
  ** The xFetch() method locates a page in the cache and returns a pointer to
5747
- ** the page, or a NULL pointer.
5748
- ** A "page", in this context, means a buffer of szPage bytes aligned at an
5749
- ** 8-byte boundary. The page to be fetched is determined by the key. ^The
5750
- ** mimimum key value is 1. After it has been retrieved using xFetch, the page
5751
- ** is considered to be "pinned".
6656
+ ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
6657
+ ** The pBuf element of the returned sqlite3_pcache_page object will be a
6658
+ ** pointer to a buffer of szPage bytes used to store the content of a
6659
+ ** single database page. The pExtra element of sqlite3_pcache_page will be
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".
5752
6666
  **
5753
6667
  ** If the requested page is already in the page cache, then the page cache
5754
6668
  ** implementation must return a pointer to the page buffer with its content
@@ -5757,7 +6671,7 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5757
6671
  ** parameter to help it determined what action to take:
5758
6672
  **
5759
6673
  ** <table border=1 width=85% align=center>
5760
- ** <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
5761
6675
  ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
5762
6676
  ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
5763
6677
  ** Otherwise return NULL.
@@ -5771,6 +6685,7 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5771
6685
  ** attempt to unpin one or more cache pages by spilling the content of
5772
6686
  ** pinned pages to disk and synching the operating system disk cache.
5773
6687
  **
6688
+ ** [[the xUnpin() page cache method]]
5774
6689
  ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
5775
6690
  ** as its second argument. If the third parameter, discard, is non-zero,
5776
6691
  ** then the page must be evicted from the cache.
@@ -5783,6 +6698,7 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5783
6698
  ** call to xUnpin() unpins the page regardless of the number of prior calls
5784
6699
  ** to xFetch().
5785
6700
  **
6701
+ ** [[the xRekey() page cache methods]]
5786
6702
  ** The xRekey() method is used to change the key value associated with the
5787
6703
  ** page passed as the second argument. If the cache
5788
6704
  ** previously contains an entry associated with newKey, it must be
@@ -5795,11 +6711,41 @@ typedef struct sqlite3_pcache sqlite3_pcache;
5795
6711
  ** of these pages are pinned, they are implicitly unpinned, meaning that
5796
6712
  ** they can be safely discarded.
5797
6713
  **
6714
+ ** [[the xDestroy() page cache method]]
5798
6715
  ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
5799
6716
  ** All resources associated with the specified cache should be freed. ^After
5800
6717
  ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
5801
- ** 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
5802
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.
5803
6749
  */
5804
6750
  typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
5805
6751
  struct sqlite3_pcache_methods {
@@ -5816,6 +6762,7 @@ struct sqlite3_pcache_methods {
5816
6762
  void (*xDestroy)(sqlite3_pcache*);
5817
6763
  };
5818
6764
 
6765
+
5819
6766
  /*
5820
6767
  ** CAPI3REF: Online Backup Object
5821
6768
  **
@@ -5857,7 +6804,7 @@ typedef struct sqlite3_backup sqlite3_backup;
5857
6804
  ** There should be exactly one call to sqlite3_backup_finish() for each
5858
6805
  ** successful call to sqlite3_backup_init().
5859
6806
  **
5860
- ** <b>sqlite3_backup_init()</b>
6807
+ ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
5861
6808
  **
5862
6809
  ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
5863
6810
  ** [database connection] associated with the destination database
@@ -5884,7 +6831,7 @@ typedef struct sqlite3_backup sqlite3_backup;
5884
6831
  ** sqlite3_backup_finish() functions to perform the specified backup
5885
6832
  ** operation.
5886
6833
  **
5887
- ** <b>sqlite3_backup_step()</b>
6834
+ ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
5888
6835
  **
5889
6836
  ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
5890
6837
  ** the source and destination databases specified by [sqlite3_backup] object B.
@@ -5941,7 +6888,7 @@ typedef struct sqlite3_backup sqlite3_backup;
5941
6888
  ** by the backup operation, then the backup database is automatically
5942
6889
  ** updated at the same time.
5943
6890
  **
5944
- ** <b>sqlite3_backup_finish()</b>
6891
+ ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
5945
6892
  **
5946
6893
  ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
5947
6894
  ** application wishes to abandon the backup operation, the application
@@ -5964,7 +6911,8 @@ typedef struct sqlite3_backup sqlite3_backup;
5964
6911
  ** is not a permanent error and does not affect the return value of
5965
6912
  ** sqlite3_backup_finish().
5966
6913
  **
5967
- ** <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>
5968
6916
  **
5969
6917
  ** ^Each call to sqlite3_backup_step() sets two values inside
5970
6918
  ** the [sqlite3_backup] object: the number of pages still to be backed
@@ -6144,17 +7092,33 @@ SQLITE_API int sqlite3_unlock_notify(
6144
7092
  /*
6145
7093
  ** CAPI3REF: String Comparison
6146
7094
  **
6147
- ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
6148
- ** compare the contents of two buffers containing UTF-8 strings in a
6149
- ** case-independent fashion, using the same definition of case independence
6150
- ** that SQLite uses internally when comparing identifiers.
7095
+ ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
7096
+ ** and extensions to compare the contents of two buffers containing UTF-8
7097
+ ** strings in a case-independent fashion, using the same definition of "case
7098
+ ** independence" that SQLite uses internally when comparing identifiers.
6151
7099
  */
7100
+ SQLITE_API int sqlite3_stricmp(const char *, const char *);
6152
7101
  SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
6153
7102
 
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
+
6154
7118
  /*
6155
7119
  ** CAPI3REF: Error Logging Interface
6156
7120
  **
6157
- ** ^The [sqlite3_log()] interface writes a message into the error log
7121
+ ** ^The [sqlite3_log()] interface writes a message into the [error log]
6158
7122
  ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6159
7123
  ** ^If logging is enabled, the zFormat string and subsequent arguments are
6160
7124
  ** used with [sqlite3_snprintf()] to generate the final output string.
@@ -6234,6 +7198,9 @@ SQLITE_API void *sqlite3_wal_hook(
6234
7198
  ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
6235
7199
  ** from SQL.
6236
7200
  **
7201
+ ** ^Checkpoints initiated by this mechanism are
7202
+ ** [sqlite3_wal_checkpoint_v2|PASSIVE].
7203
+ **
6237
7204
  ** ^Every new [database connection] defaults to having the auto-checkpoint
6238
7205
  ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
6239
7206
  ** pages. The use of this interface
@@ -6250,14 +7217,202 @@ SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
6250
7217
  ** empty string, then a checkpoint is run on all databases of
6251
7218
  ** connection D. ^If the database connection D is not in
6252
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.
6253
7224
  **
6254
7225
  ** ^The [wal_checkpoint pragma] can be used to invoke this interface
6255
7226
  ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
6256
7227
  ** [wal_autocheckpoint pragma] can be used to cause this interface to be
6257
7228
  ** run whenever the WAL reaches a certain size threshold.
7229
+ **
7230
+ ** See also: [sqlite3_wal_checkpoint_v2()]
6258
7231
  */
6259
7232
  SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
6260
7233
 
7234
+ /*
7235
+ ** CAPI3REF: Checkpoint a database
7236
+ **
7237
+ ** Run a checkpoint operation on WAL database zDb attached to database
7238
+ ** handle db. The specific operation is determined by the value of the
7239
+ ** eMode parameter:
7240
+ **
7241
+ ** <dl>
7242
+ ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7243
+ ** Checkpoint as many frames as possible without waiting for any database
7244
+ ** readers or writers to finish. Sync the db file if all frames in the log
7245
+ ** are checkpointed. This mode is the same as calling
7246
+ ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7247
+ ** is never invoked.
7248
+ **
7249
+ ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7250
+ ** This mode blocks (it invokes the
7251
+ ** [sqlite3_busy_handler|busy-handler callback]) until there is no
7252
+ ** database writer and all readers are reading from the most recent database
7253
+ ** snapshot. It then checkpoints all frames in the log file and syncs the
7254
+ ** database file. This call blocks database writers while it is running,
7255
+ ** but not database readers.
7256
+ **
7257
+ ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7258
+ ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7259
+ ** checkpointing the log file it blocks (calls the
7260
+ ** [sqlite3_busy_handler|busy-handler callback])
7261
+ ** until all readers are reading from the database file only. This ensures
7262
+ ** that the next client to write to the database file restarts the log file
7263
+ ** from the beginning. This call blocks database writers while it is running,
7264
+ ** but not database readers.
7265
+ ** </dl>
7266
+ **
7267
+ ** If pnLog is not NULL, then *pnLog is set to the total number of frames in
7268
+ ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
7269
+ ** the total number of checkpointed frames (including any that were already
7270
+ ** checkpointed when this function is called). *pnLog and *pnCkpt may be
7271
+ ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
7272
+ ** If no values are available because of an error, they are both set to -1
7273
+ ** before returning to communicate this to the caller.
7274
+ **
7275
+ ** All calls obtain an exclusive "checkpoint" lock on the database file. If
7276
+ ** any other process is running a checkpoint operation at the same time, the
7277
+ ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a
7278
+ ** busy-handler configured, it will not be invoked in this case.
7279
+ **
7280
+ ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive
7281
+ ** "writer" lock on the database file. If the writer lock cannot be obtained
7282
+ ** immediately, and a busy-handler is configured, it is invoked and the writer
7283
+ ** lock retried until either the busy-handler returns 0 or the lock is
7284
+ ** successfully obtained. The busy-handler is also invoked while waiting for
7285
+ ** database readers as described above. If the busy-handler returns 0 before
7286
+ ** the writer lock is obtained or while waiting for database readers, the
7287
+ ** checkpoint operation proceeds from that point in the same way as
7288
+ ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
7289
+ ** without blocking any further. SQLITE_BUSY is returned in this case.
7290
+ **
7291
+ ** If parameter zDb is NULL or points to a zero length string, then the
7292
+ ** specified operation is attempted on all WAL databases. In this case the
7293
+ ** values written to output parameters *pnLog and *pnCkpt are undefined. If
7294
+ ** an SQLITE_BUSY error is encountered when processing one or more of the
7295
+ ** attached WAL databases, the operation is still attempted on any remaining
7296
+ ** attached databases and SQLITE_BUSY is returned to the caller. If any other
7297
+ ** error occurs while processing an attached database, processing is abandoned
7298
+ ** and the error code returned to the caller immediately. If no error
7299
+ ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
7300
+ ** databases, SQLITE_OK is returned.
7301
+ **
7302
+ ** If database zDb is the name of an attached database that is not in WAL
7303
+ ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
7304
+ ** zDb is not NULL (or a zero length string) and is not the name of any
7305
+ ** attached database, SQLITE_ERROR is returned to the caller.
7306
+ */
7307
+ SQLITE_API int sqlite3_wal_checkpoint_v2(
7308
+ sqlite3 *db, /* Database handle */
7309
+ const char *zDb, /* Name of attached database (or NULL) */
7310
+ int eMode, /* SQLITE_CHECKPOINT_* value */
7311
+ int *pnLog, /* OUT: Size of WAL log in frames */
7312
+ int *pnCkpt /* OUT: Total number of frames checkpointed */
7313
+ );
7314
+
7315
+ /*
7316
+ ** CAPI3REF: Checkpoint operation parameters
7317
+ **
7318
+ ** These constants can be used as the 3rd parameter to
7319
+ ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()]
7320
+ ** documentation for additional information about the meaning and use of
7321
+ ** each of these values.
7322
+ */
7323
+ #define SQLITE_CHECKPOINT_PASSIVE 0
7324
+ #define SQLITE_CHECKPOINT_FULL 1
7325
+ #define SQLITE_CHECKPOINT_RESTART 2
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
+
7415
+
6261
7416
  /*
6262
7417
  ** Undo the hack that converts floating point types to integer for
6263
7418
  ** builds on processors without floating point support.
@@ -6269,7 +7424,7 @@ SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
6269
7424
  #ifdef __cplusplus
6270
7425
  } /* End of the 'extern "C"' block */
6271
7426
  #endif
6272
- #endif
7427
+ #endif /* _SQLITE3_H_ */
6273
7428
 
6274
7429
  /*
6275
7430
  ** 2010 August 30
@@ -6293,6 +7448,16 @@ extern "C" {
6293
7448
  #endif
6294
7449
 
6295
7450
  typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
7451
+ typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;
7452
+
7453
+ /* The double-precision datatype used by RTree depends on the
7454
+ ** SQLITE_RTREE_INT_ONLY compile-time option.
7455
+ */
7456
+ #ifdef SQLITE_RTREE_INT_ONLY
7457
+ typedef sqlite3_int64 sqlite3_rtree_dbl;
7458
+ #else
7459
+ typedef double sqlite3_rtree_dbl;
7460
+ #endif
6296
7461
 
6297
7462
  /*
6298
7463
  ** Register a geometry callback named zGeom that can be used as part of an
@@ -6303,7 +7468,7 @@ typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
6303
7468
  SQLITE_API int sqlite3_rtree_geometry_callback(
6304
7469
  sqlite3 *db,
6305
7470
  const char *zGeom,
6306
- int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes),
7471
+ int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
6307
7472
  void *pContext
6308
7473
  );
6309
7474
 
@@ -6315,11 +7480,60 @@ SQLITE_API int sqlite3_rtree_geometry_callback(
6315
7480
  struct sqlite3_rtree_geometry {
6316
7481
  void *pContext; /* Copy of pContext passed to s_r_g_c() */
6317
7482
  int nParam; /* Size of array aParam[] */
6318
- double *aParam; /* Parameters passed to SQL geom function */
7483
+ sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */
6319
7484
  void *pUser; /* Callback implementation user data */
6320
7485
  void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */
6321
7486
  };
6322
7487
 
7488
+ /*
7489
+ ** Register a 2nd-generation geometry callback named zScore that can be
7490
+ ** used as part of an R-Tree geometry query as follows:
7491
+ **
7492
+ ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
7493
+ */
7494
+ SQLITE_API int sqlite3_rtree_query_callback(
7495
+ sqlite3 *db,
7496
+ const char *zQueryFunc,
7497
+ int (*xQueryFunc)(sqlite3_rtree_query_info*),
7498
+ void *pContext,
7499
+ void (*xDestructor)(void*)
7500
+ );
7501
+
7502
+
7503
+ /*
7504
+ ** A pointer to a structure of the following type is passed as the
7505
+ ** argument to scored geometry callback registered using
7506
+ ** sqlite3_rtree_query_callback().
7507
+ **
7508
+ ** Note that the first 5 fields of this structure are identical to
7509
+ ** sqlite3_rtree_geometry. This structure is a subclass of
7510
+ ** sqlite3_rtree_geometry.
7511
+ */
7512
+ struct sqlite3_rtree_query_info {
7513
+ void *pContext; /* pContext from when function registered */
7514
+ int nParam; /* Number of function parameters */
7515
+ sqlite3_rtree_dbl *aParam; /* value of function parameters */
7516
+ void *pUser; /* callback can use this, if desired */
7517
+ void (*xDelUser)(void*); /* function to free pUser */
7518
+ sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */
7519
+ unsigned int *anQueue; /* Number of pending entries in the queue */
7520
+ int nCoord; /* Number of coordinates */
7521
+ int iLevel; /* Level of current node or entry */
7522
+ int mxLevel; /* The largest iLevel value in the tree */
7523
+ sqlite3_int64 iRowid; /* Rowid for current entry */
7524
+ sqlite3_rtree_dbl rParentScore; /* Score of parent node */
7525
+ int eParentWithin; /* Visibility of parent node */
7526
+ int eWithin; /* OUT: Visiblity */
7527
+ sqlite3_rtree_dbl rScore; /* OUT: Write the score here */
7528
+ };
7529
+
7530
+ /*
7531
+ ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
7532
+ */
7533
+ #define NOT_WITHIN 0 /* Object completely outside of query region */
7534
+ #define PARTLY_WITHIN 1 /* Object partially overlaps query region */
7535
+ #define FULLY_WITHIN 2 /* Object fully contained within query region */
7536
+
6323
7537
 
6324
7538
  #ifdef __cplusplus
6325
7539
  } /* end of the 'extern "C"' block */