Fossil SCM

Merge all the latest trunk changes into the windows-i18n branch.

drh 2011-05-20 11:24 windows-i18n merge
Commit a742d12e8f0d3915c6938fe8b3ca4bd441d9a6c8
+18 -16
--- src/manifest.c
+++ src/manifest.c
@@ -1706,30 +1706,32 @@
17061706
sqlite3_snprintf(sizeof(zLength), zLength, "%d", nWiki);
17071707
tag_insert(zTag, 1, zLength, rid, p->rDate, rid);
17081708
free(zTag);
17091709
prior = db_int(0,
17101710
"SELECT rid FROM tagxref"
1711
- " WHERE tagid=%d AND mtime<%.17g"
1711
+ " WHERE tagid=%d AND mtime<%.17g AND rid!=%d"
17121712
" ORDER BY mtime DESC",
1713
- tagid, p->rDate
1713
+ tagid, p->rDate, rid
1714
+ );
1715
+ subsequent = db_int(0,
1716
+ "SELECT rid FROM tagxref"
1717
+ " WHERE tagid=%d AND mtime>=%.17g AND rid!=%d"
1718
+ " ORDER BY mtime",
1719
+ tagid, p->rDate, rid
17141720
);
17151721
if( prior ){
17161722
content_deltify(prior, rid, 0);
1717
- db_multi_exec(
1718
- "DELETE FROM event"
1719
- " WHERE type='e'"
1720
- " AND tagid=%d"
1721
- " AND objid IN (SELECT rid FROM tagxref WHERE tagid=%d)",
1722
- tagid, tagid
1723
- );
1724
- }
1725
- subsequent = db_int(0,
1726
- "SELECT rid FROM tagxref"
1727
- " WHERE tagid=%d AND mtime>%.17g"
1728
- " ORDER BY mtime",
1729
- tagid, p->rDate
1730
- );
1723
+ if( !subsequent ){
1724
+ db_multi_exec(
1725
+ "DELETE FROM event"
1726
+ " WHERE type='e'"
1727
+ " AND tagid=%d"
1728
+ " AND objid IN (SELECT rid FROM tagxref WHERE tagid=%d)",
1729
+ tagid, tagid
1730
+ );
1731
+ }
1732
+ }
17311733
if( subsequent ){
17321734
content_deltify(rid, subsequent, 0);
17331735
}else{
17341736
db_multi_exec(
17351737
"REPLACE INTO event(type,mtime,objid,tagid,user,comment,bgcolor)"
17361738
--- src/manifest.c
+++ src/manifest.c
@@ -1706,30 +1706,32 @@
1706 sqlite3_snprintf(sizeof(zLength), zLength, "%d", nWiki);
1707 tag_insert(zTag, 1, zLength, rid, p->rDate, rid);
1708 free(zTag);
1709 prior = db_int(0,
1710 "SELECT rid FROM tagxref"
1711 " WHERE tagid=%d AND mtime<%.17g"
1712 " ORDER BY mtime DESC",
1713 tagid, p->rDate
 
 
 
 
 
 
1714 );
1715 if( prior ){
1716 content_deltify(prior, rid, 0);
1717 db_multi_exec(
1718 "DELETE FROM event"
1719 " WHERE type='e'"
1720 " AND tagid=%d"
1721 " AND objid IN (SELECT rid FROM tagxref WHERE tagid=%d)",
1722 tagid, tagid
1723 );
1724 }
1725 subsequent = db_int(0,
1726 "SELECT rid FROM tagxref"
1727 " WHERE tagid=%d AND mtime>%.17g"
1728 " ORDER BY mtime",
1729 tagid, p->rDate
1730 );
1731 if( subsequent ){
1732 content_deltify(rid, subsequent, 0);
1733 }else{
1734 db_multi_exec(
1735 "REPLACE INTO event(type,mtime,objid,tagid,user,comment,bgcolor)"
1736
--- src/manifest.c
+++ src/manifest.c
@@ -1706,30 +1706,32 @@
1706 sqlite3_snprintf(sizeof(zLength), zLength, "%d", nWiki);
1707 tag_insert(zTag, 1, zLength, rid, p->rDate, rid);
1708 free(zTag);
1709 prior = db_int(0,
1710 "SELECT rid FROM tagxref"
1711 " WHERE tagid=%d AND mtime<%.17g AND rid!=%d"
1712 " ORDER BY mtime DESC",
1713 tagid, p->rDate, rid
1714 );
1715 subsequent = db_int(0,
1716 "SELECT rid FROM tagxref"
1717 " WHERE tagid=%d AND mtime>=%.17g AND rid!=%d"
1718 " ORDER BY mtime",
1719 tagid, p->rDate, rid
1720 );
1721 if( prior ){
1722 content_deltify(prior, rid, 0);
1723 if( !subsequent ){
1724 db_multi_exec(
1725 "DELETE FROM event"
1726 " WHERE type='e'"
1727 " AND tagid=%d"
1728 " AND objid IN (SELECT rid FROM tagxref WHERE tagid=%d)",
1729 tagid, tagid
1730 );
1731 }
1732 }
 
 
 
 
1733 if( subsequent ){
1734 content_deltify(rid, subsequent, 0);
1735 }else{
1736 db_multi_exec(
1737 "REPLACE INTO event(type,mtime,objid,tagid,user,comment,bgcolor)"
1738
+59
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,10 +20,11 @@
2020
** is a copy of the "shell.c" code from SQLite. This file contains logic
2121
** to initialize the code in shell.c.
2222
*/
2323
#include "config.h"
2424
#include "sqlcmd.h"
25
+#include <zlib.h>
2526
2627
/*
2728
** Implementation of the "content(X)" SQL function. Return the complete
2829
** content of artifact identified by X as a blob.
2930
*/
@@ -46,10 +47,64 @@
4647
sqlite3_result_blob(context, blob_buffer(&cx), blob_size(&cx),
4748
SQLITE_TRANSIENT);
4849
blob_reset(&cx);
4950
}
5051
}
52
+
53
+/*
54
+** Implementation of the "compress(X)" SQL function. The input X is
55
+** compressed using zLib and the output is returned.
56
+*/
57
+static void sqlcmd_compress(
58
+ sqlite3_context *context,
59
+ int argc,
60
+ sqlite3_value **argv
61
+){
62
+ const unsigned char *pIn;
63
+ unsigned char *pOut;
64
+ unsigned int nIn;
65
+ unsigned long int nOut;
66
+
67
+ pIn = sqlite3_value_blob(argv[0]);
68
+ nIn = sqlite3_value_bytes(argv[0]);
69
+ nOut = 13 + nIn + (nIn+999)/1000;
70
+ pOut = sqlite3_malloc( nOut+4 );
71
+ pOut[0] = nIn>>24 & 0xff;
72
+ pOut[1] = nIn>>16 & 0xff;
73
+ pOut[2] = nIn>>8 & 0xff;
74
+ pOut[3] = nIn & 0xff;
75
+ compress(&pOut[4], &nOut, pIn, nIn);
76
+ sqlite3_result_blob(context, pOut, nOut+4, sqlite3_free);
77
+}
78
+
79
+/*
80
+** Implementation of the "uncontent(X)" SQL function. The argument X
81
+** is a blob which was obtained from compress(Y). The output will be
82
+** the value Y.
83
+*/
84
+static void sqlcmd_decompress(
85
+ sqlite3_context *context,
86
+ int argc,
87
+ sqlite3_value **argv
88
+){
89
+ const unsigned char *pIn;
90
+ unsigned char *pOut;
91
+ unsigned int nIn;
92
+ unsigned long int nOut;
93
+ int rc;
94
+
95
+ pIn = sqlite3_value_blob(argv[0]);
96
+ nIn = sqlite3_value_bytes(argv[0]);
97
+ nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
98
+ pOut = sqlite3_malloc( nOut+1 );
99
+ rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
100
+ if( rc==Z_OK ){
101
+ sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
102
+ }else{
103
+ sqlite3_result_error(context, "input is not zlib compressed", -1);
104
+ }
105
+}
51106
52107
/*
53108
** This is the "automatic extensionn" initializer that runs right after
54109
** the connection to the repository database is opened. Set up the
55110
** database connection to be more useful to the human operator.
@@ -59,10 +114,14 @@
59114
const char **pzErrMsg,
60115
const void *notUsed
61116
){
62117
sqlite3_create_function(db, "content", 1, SQLITE_ANY, 0,
63118
sqlcmd_content, 0, 0);
119
+ sqlite3_create_function(db, "compress", 1, SQLITE_ANY, 0,
120
+ sqlcmd_compress, 0, 0);
121
+ sqlite3_create_function(db, "decompress", 1, SQLITE_ANY, 0,
122
+ sqlcmd_decompress, 0, 0);
64123
return SQLITE_OK;
65124
}
66125
67126
68127
/*
69128
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,10 +20,11 @@
20 ** is a copy of the "shell.c" code from SQLite. This file contains logic
21 ** to initialize the code in shell.c.
22 */
23 #include "config.h"
24 #include "sqlcmd.h"
 
25
26 /*
27 ** Implementation of the "content(X)" SQL function. Return the complete
28 ** content of artifact identified by X as a blob.
29 */
@@ -46,10 +47,64 @@
46 sqlite3_result_blob(context, blob_buffer(&cx), blob_size(&cx),
47 SQLITE_TRANSIENT);
48 blob_reset(&cx);
49 }
50 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
52 /*
53 ** This is the "automatic extensionn" initializer that runs right after
54 ** the connection to the repository database is opened. Set up the
55 ** database connection to be more useful to the human operator.
@@ -59,10 +114,14 @@
59 const char **pzErrMsg,
60 const void *notUsed
61 ){
62 sqlite3_create_function(db, "content", 1, SQLITE_ANY, 0,
63 sqlcmd_content, 0, 0);
 
 
 
 
64 return SQLITE_OK;
65 }
66
67
68 /*
69
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -20,10 +20,11 @@
20 ** is a copy of the "shell.c" code from SQLite. This file contains logic
21 ** to initialize the code in shell.c.
22 */
23 #include "config.h"
24 #include "sqlcmd.h"
25 #include <zlib.h>
26
27 /*
28 ** Implementation of the "content(X)" SQL function. Return the complete
29 ** content of artifact identified by X as a blob.
30 */
@@ -46,10 +47,64 @@
47 sqlite3_result_blob(context, blob_buffer(&cx), blob_size(&cx),
48 SQLITE_TRANSIENT);
49 blob_reset(&cx);
50 }
51 }
52
53 /*
54 ** Implementation of the "compress(X)" SQL function. The input X is
55 ** compressed using zLib and the output is returned.
56 */
57 static void sqlcmd_compress(
58 sqlite3_context *context,
59 int argc,
60 sqlite3_value **argv
61 ){
62 const unsigned char *pIn;
63 unsigned char *pOut;
64 unsigned int nIn;
65 unsigned long int nOut;
66
67 pIn = sqlite3_value_blob(argv[0]);
68 nIn = sqlite3_value_bytes(argv[0]);
69 nOut = 13 + nIn + (nIn+999)/1000;
70 pOut = sqlite3_malloc( nOut+4 );
71 pOut[0] = nIn>>24 & 0xff;
72 pOut[1] = nIn>>16 & 0xff;
73 pOut[2] = nIn>>8 & 0xff;
74 pOut[3] = nIn & 0xff;
75 compress(&pOut[4], &nOut, pIn, nIn);
76 sqlite3_result_blob(context, pOut, nOut+4, sqlite3_free);
77 }
78
79 /*
80 ** Implementation of the "uncontent(X)" SQL function. The argument X
81 ** is a blob which was obtained from compress(Y). The output will be
82 ** the value Y.
83 */
84 static void sqlcmd_decompress(
85 sqlite3_context *context,
86 int argc,
87 sqlite3_value **argv
88 ){
89 const unsigned char *pIn;
90 unsigned char *pOut;
91 unsigned int nIn;
92 unsigned long int nOut;
93 int rc;
94
95 pIn = sqlite3_value_blob(argv[0]);
96 nIn = sqlite3_value_bytes(argv[0]);
97 nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
98 pOut = sqlite3_malloc( nOut+1 );
99 rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
100 if( rc==Z_OK ){
101 sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
102 }else{
103 sqlite3_result_error(context, "input is not zlib compressed", -1);
104 }
105 }
106
107 /*
108 ** This is the "automatic extensionn" initializer that runs right after
109 ** the connection to the repository database is opened. Set up the
110 ** database connection to be more useful to the human operator.
@@ -59,10 +114,14 @@
114 const char **pzErrMsg,
115 const void *notUsed
116 ){
117 sqlite3_create_function(db, "content", 1, SQLITE_ANY, 0,
118 sqlcmd_content, 0, 0);
119 sqlite3_create_function(db, "compress", 1, SQLITE_ANY, 0,
120 sqlcmd_compress, 0, 0);
121 sqlite3_create_function(db, "decompress", 1, SQLITE_ANY, 0,
122 sqlcmd_decompress, 0, 0);
123 return SQLITE_OK;
124 }
125
126
127 /*
128
+1360 -312
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.7.6.1. By combining all the individual C code files into this
3
+** version 3.7.7. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -648,13 +648,13 @@
648648
**
649649
** See also: [sqlite3_libversion()],
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653
-#define SQLITE_VERSION "3.7.6.1"
654
-#define SQLITE_VERSION_NUMBER 3007006
655
-#define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56"
653
+#define SQLITE_VERSION "3.7.7"
654
+#define SQLITE_VERSION_NUMBER 3007007
655
+#define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -916,11 +916,12 @@
916916
** Many SQLite functions return an integer result code from the set shown
917917
** here in order to indicates success or failure.
918918
**
919919
** New error codes may be added in future versions of SQLite.
920920
**
921
-** See also: [SQLITE_IOERR_READ | extended result codes]
921
+** See also: [SQLITE_IOERR_READ | extended result codes],
922
+** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes].
922923
*/
923924
#define SQLITE_OK 0 /* Successful result */
924925
/* beginning-of-error-codes */
925926
#define SQLITE_ERROR 1 /* SQL error or missing database */
926927
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -998,25 +999,26 @@
998999
#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
9991000
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
10001001
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
10011002
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
10021003
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1004
+#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
10031005
10041006
/*
10051007
** CAPI3REF: Flags For File Open Operations
10061008
**
10071009
** These bit values are intended for use in the
10081010
** 3rd parameter to the [sqlite3_open_v2()] interface and
1009
-** in the 4th parameter to the xOpen method of the
1010
-** [sqlite3_vfs] object.
1011
+** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
10111012
*/
10121013
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
10131014
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
10141015
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
10151016
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
10161017
#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
10171018
#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
1019
+#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
10181020
#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
10191021
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
10201022
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
10211023
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
10221024
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -1123,21 +1125,22 @@
11231125
};
11241126
11251127
/*
11261128
** CAPI3REF: OS Interface File Virtual Methods Object
11271129
**
1128
-** Every file opened by the [sqlite3_vfs] xOpen method populates an
1130
+** Every file opened by the [sqlite3_vfs.xOpen] method populates an
11291131
** [sqlite3_file] object (or, more commonly, a subclass of the
11301132
** [sqlite3_file] object) with a pointer to an instance of this object.
11311133
** This object defines the methods used to perform various operations
11321134
** against the open file represented by the [sqlite3_file] object.
11331135
**
1134
-** If the xOpen method sets the sqlite3_file.pMethods element
1136
+** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
11351137
** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
1136
-** may be invoked even if the xOpen reported that it failed. The
1137
-** only way to prevent a call to xClose following a failed xOpen
1138
-** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
1138
+** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
1139
+** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
1140
+** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
1141
+** to NULL.
11391142
**
11401143
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
11411144
** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
11421145
** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
11431146
** flag may be ORed in to indicate that only the data of the file
@@ -1302,10 +1305,11 @@
13021305
*/
13031306
typedef struct sqlite3_mutex sqlite3_mutex;
13041307
13051308
/*
13061309
** CAPI3REF: OS Interface Object
1310
+** KEYWORDS: VFS VFSes
13071311
**
13081312
** An instance of the sqlite3_vfs object defines the interface between
13091313
** the SQLite core and the underlying operating system. The "vfs"
13101314
** in the name of the object stands for "virtual file system".
13111315
**
@@ -1334,10 +1338,11 @@
13341338
** object once the object has been registered.
13351339
**
13361340
** The zName field holds the name of the VFS module. The name must
13371341
** be unique across all VFS modules.
13381342
**
1343
+** [[sqlite3_vfs.xOpen]]
13391344
** ^SQLite guarantees that the zFilename parameter to xOpen
13401345
** is either a NULL pointer or string obtained
13411346
** from xFullPathname() with an optional suffix added.
13421347
** ^If a suffix is added to the zFilename parameter, it will
13431348
** consist of a single "-" character followed by no more than
@@ -1411,10 +1416,11 @@
14111416
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
14121417
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
14131418
** element will be valid after xOpen returns regardless of the success
14141419
** or failure of the xOpen call.
14151420
**
1421
+** [[sqlite3_vfs.xAccess]]
14161422
** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
14171423
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
14181424
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
14191425
** to test whether a file is at least readable. The file can be a
14201426
** directory.
@@ -1657,13 +1663,13 @@
16571663
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
16581664
** Note, however, that ^sqlite3_config() can be called as part of the
16591665
** implementation of an application-defined [sqlite3_os_init()].
16601666
**
16611667
** The first argument to sqlite3_config() is an integer
1662
-** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
1668
+** [configuration option] that determines
16631669
** what property of SQLite is to be configured. Subsequent arguments
1664
-** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
1670
+** vary depending on the [configuration option]
16651671
** in the first argument.
16661672
**
16671673
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
16681674
** ^If the option is unknown or SQLite is unable to set the option
16691675
** then this routine returns a non-zero [error code].
@@ -1769,10 +1775,11 @@
17691775
void *pAppData; /* Argument to xInit() and xShutdown() */
17701776
};
17711777
17721778
/*
17731779
** CAPI3REF: Configuration Options
1780
+** KEYWORDS: {configuration option}
17741781
**
17751782
** These constants are the available integer configuration options that
17761783
** can be passed as the first argument to the [sqlite3_config()] interface.
17771784
**
17781785
** New configuration options may be added in future releases of SQLite.
@@ -1781,11 +1788,11 @@
17811788
** the call worked. The [sqlite3_config()] interface will return a
17821789
** non-zero [error code] if a discontinued or unsupported configuration option
17831790
** is invoked.
17841791
**
17851792
** <dl>
1786
-** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1793
+** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
17871794
** <dd>There are no arguments to this option. ^This option sets the
17881795
** [threading mode] to Single-thread. In other words, it disables
17891796
** all mutexing and puts SQLite into a mode where it can only be used
17901797
** by a single thread. ^If SQLite is compiled with
17911798
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
@@ -1792,11 +1799,11 @@
17921799
** it is not possible to change the [threading mode] from its default
17931800
** value of Single-thread and so [sqlite3_config()] will return
17941801
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
17951802
** configuration option.</dd>
17961803
**
1797
-** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1804
+** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
17981805
** <dd>There are no arguments to this option. ^This option sets the
17991806
** [threading mode] to Multi-thread. In other words, it disables
18001807
** mutexing on [database connection] and [prepared statement] objects.
18011808
** The application is responsible for serializing access to
18021809
** [database connections] and [prepared statements]. But other mutexes
@@ -1806,11 +1813,11 @@
18061813
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
18071814
** it is not possible to set the Multi-thread [threading mode] and
18081815
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
18091816
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
18101817
**
1811
-** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1818
+** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
18121819
** <dd>There are no arguments to this option. ^This option sets the
18131820
** [threading mode] to Serialized. In other words, this option enables
18141821
** all mutexes including the recursive
18151822
** mutexes on [database connection] and [prepared statement] objects.
18161823
** In this mode (which is the default when SQLite is compiled with
@@ -1822,27 +1829,27 @@
18221829
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
18231830
** it is not possible to set the Serialized [threading mode] and
18241831
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
18251832
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
18261833
**
1827
-** <dt>SQLITE_CONFIG_MALLOC</dt>
1834
+** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
18281835
** <dd> ^(This option takes a single argument which is a pointer to an
18291836
** instance of the [sqlite3_mem_methods] structure. The argument specifies
18301837
** alternative low-level memory allocation routines to be used in place of
18311838
** the memory allocation routines built into SQLite.)^ ^SQLite makes
18321839
** its own private copy of the content of the [sqlite3_mem_methods] structure
18331840
** before the [sqlite3_config()] call returns.</dd>
18341841
**
1835
-** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1842
+** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
18361843
** <dd> ^(This option takes a single argument which is a pointer to an
18371844
** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
18381845
** structure is filled with the currently defined memory allocation routines.)^
18391846
** This option can be used to overload the default memory allocation
18401847
** routines with a wrapper that simulations memory allocation failure or
18411848
** tracks memory usage, for example. </dd>
18421849
**
1843
-** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1850
+** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
18441851
** <dd> ^This option takes single argument of type int, interpreted as a
18451852
** boolean, which enables or disables the collection of memory allocation
18461853
** statistics. ^(When memory allocation statistics are disabled, the
18471854
** following SQLite interfaces become non-operational:
18481855
** <ul>
@@ -1854,11 +1861,11 @@
18541861
** ^Memory allocation statistics are enabled by default unless SQLite is
18551862
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
18561863
** allocation statistics are disabled by default.
18571864
** </dd>
18581865
**
1859
-** <dt>SQLITE_CONFIG_SCRATCH</dt>
1866
+** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
18601867
** <dd> ^This option specifies a static memory buffer that SQLite can use for
18611868
** scratch memory. There are three arguments: A pointer an 8-byte
18621869
** aligned memory buffer from which the scratch allocations will be
18631870
** drawn, the size of each scratch allocation (sz),
18641871
** and the maximum number of scratch allocations (N). The sz
@@ -1870,11 +1877,11 @@
18701877
** ^SQLite will never require a scratch buffer that is more than 6
18711878
** times the database page size. ^If SQLite needs needs additional
18721879
** scratch memory beyond what is provided by this configuration option, then
18731880
** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
18741881
**
1875
-** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1882
+** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
18761883
** <dd> ^This option specifies a static memory buffer that SQLite can use for
18771884
** the database page cache with the default page cache implemenation.
18781885
** This configuration should not be used if an application-define page
18791886
** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
18801887
** There are three arguments to this option: A pointer to 8-byte aligned
@@ -1891,11 +1898,11 @@
18911898
** SQLite goes to [sqlite3_malloc()] for the additional storage space.
18921899
** The pointer in the first argument must
18931900
** be aligned to an 8-byte boundary or subsequent behavior of SQLite
18941901
** will be undefined.</dd>
18951902
**
1896
-** <dt>SQLITE_CONFIG_HEAP</dt>
1903
+** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
18971904
** <dd> ^This option specifies a static memory buffer that SQLite will use
18981905
** for all of its dynamic memory allocation needs beyond those provided
18991906
** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
19001907
** There are three arguments: An 8-byte aligned pointer to the memory,
19011908
** the number of bytes in the memory buffer, and the minimum allocation size.
@@ -1908,11 +1915,11 @@
19081915
** The first pointer (the memory pointer) must be aligned to an 8-byte
19091916
** boundary or subsequent behavior of SQLite will be undefined.
19101917
** The minimum allocation size is capped at 2^12. Reasonable values
19111918
** for the minimum allocation size are 2^5 through 2^8.</dd>
19121919
**
1913
-** <dt>SQLITE_CONFIG_MUTEX</dt>
1920
+** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
19141921
** <dd> ^(This option takes a single argument which is a pointer to an
19151922
** instance of the [sqlite3_mutex_methods] structure. The argument specifies
19161923
** alternative low-level mutex routines to be used in place
19171924
** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
19181925
** content of the [sqlite3_mutex_methods] structure before the call to
@@ -1920,11 +1927,11 @@
19201927
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
19211928
** the entire mutexing subsystem is omitted from the build and hence calls to
19221929
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
19231930
** return [SQLITE_ERROR].</dd>
19241931
**
1925
-** <dt>SQLITE_CONFIG_GETMUTEX</dt>
1932
+** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
19261933
** <dd> ^(This option takes a single argument which is a pointer to an
19271934
** instance of the [sqlite3_mutex_methods] structure. The
19281935
** [sqlite3_mutex_methods]
19291936
** structure is filled with the currently defined mutex routines.)^
19301937
** This option can be used to overload the default mutex allocation
@@ -1933,32 +1940,32 @@
19331940
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
19341941
** the entire mutexing subsystem is omitted from the build and hence calls to
19351942
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
19361943
** return [SQLITE_ERROR].</dd>
19371944
**
1938
-** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1945
+** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
19391946
** <dd> ^(This option takes two arguments that determine the default
19401947
** memory allocation for the lookaside memory allocator on each
19411948
** [database connection]. The first argument is the
19421949
** size of each lookaside buffer slot and the second is the number of
19431950
** slots allocated to each database connection.)^ ^(This option sets the
19441951
** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
19451952
** verb to [sqlite3_db_config()] can be used to change the lookaside
19461953
** configuration on individual connections.)^ </dd>
19471954
**
1948
-** <dt>SQLITE_CONFIG_PCACHE</dt>
1955
+** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt>
19491956
** <dd> ^(This option takes a single argument which is a pointer to
19501957
** an [sqlite3_pcache_methods] object. This object specifies the interface
19511958
** to a custom page cache implementation.)^ ^SQLite makes a copy of the
19521959
** object and uses it for page cache memory allocations.</dd>
19531960
**
1954
-** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1961
+** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt>
19551962
** <dd> ^(This option takes a single argument which is a pointer to an
19561963
** [sqlite3_pcache_methods] object. SQLite copies of the current
19571964
** page cache implementation into that object.)^ </dd>
19581965
**
1959
-** <dt>SQLITE_CONFIG_LOG</dt>
1966
+** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
19601967
** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
19611968
** function with a call signature of void(*)(void*,int,const char*),
19621969
** and a pointer to void. ^If the function pointer is not NULL, it is
19631970
** invoked by [sqlite3_log()] to process each logging event. ^If the
19641971
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
@@ -1972,10 +1979,22 @@
19721979
** The SQLite logging interface is not reentrant; the logger function
19731980
** supplied by the application must not invoke any SQLite interface.
19741981
** In a multi-threaded application, the application-defined logger
19751982
** function must be threadsafe. </dd>
19761983
**
1984
+** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1985
+** <dd> This option takes a single argument of type int. If non-zero, then
1986
+** URI handling is globally enabled. If the parameter is zero, then URI handling
1987
+** is globally disabled. If URI handling is globally enabled, all filenames
1988
+** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1989
+** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1990
+** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1991
+** connection is opened. If it is globally disabled, filenames are
1992
+** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1993
+** database connection is opened. By default, URI handling is globally
1994
+** disabled. The default value may be changed by compiling with the
1995
+** [SQLITE_USE_URI] symbol defined.
19771996
** </dl>
19781997
*/
19791998
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
19801999
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
19812000
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1990,10 +2009,11 @@
19902009
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
19912010
#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
19922011
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
19932012
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
19942013
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
2014
+#define SQLITE_CONFIG_URI 17 /* int */
19952015
19962016
/*
19972017
** CAPI3REF: Database Connection Configuration Options
19982018
**
19992019
** These constants are the available integer configuration options that
@@ -2075,17 +2095,21 @@
20752095
** the table has a column of type [INTEGER PRIMARY KEY] then that column
20762096
** is another alias for the rowid.
20772097
**
20782098
** ^This routine returns the [rowid] of the most recent
20792099
** successful [INSERT] into the database from the [database connection]
2080
-** in the first argument. ^If no successful [INSERT]s
2100
+** in the first argument. ^As of SQLite version 3.7.7, this routines
2101
+** records the last insert rowid of both ordinary tables and [virtual tables].
2102
+** ^If no successful [INSERT]s
20812103
** have ever occurred on that database connection, zero is returned.
20822104
**
2083
-** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
2084
-** row is returned by this routine as long as the trigger is running.
2085
-** But once the trigger terminates, the value returned by this routine
2086
-** reverts to the last value inserted before the trigger fired.)^
2105
+** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2106
+** method, then this routine will return the [rowid] of the inserted
2107
+** row as long as the trigger or virtual table method is running.
2108
+** But once the trigger or virtual table method ends, the value returned
2109
+** by this routine reverts to what it was before the trigger or virtual
2110
+** table method began.)^
20872111
**
20882112
** ^An [INSERT] that fails due to a constraint violation is not a
20892113
** successful [INSERT] and does not change the value returned by this
20902114
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
20912115
** and INSERT OR ABORT make no changes to the return value of this
@@ -2744,10 +2768,13 @@
27442768
** The [sqlite3_set_authorizer | authorizer callback function] must
27452769
** return either [SQLITE_OK] or one of these two constants in order
27462770
** to signal SQLite whether or not the action is permitted. See the
27472771
** [sqlite3_set_authorizer | authorizer documentation] for additional
27482772
** information.
2773
+**
2774
+** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code]
2775
+** from the [sqlite3_vtab_on_conflict()] interface.
27492776
*/
27502777
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
27512778
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
27522779
27532780
/*
@@ -2866,11 +2893,11 @@
28662893
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
28672894
28682895
/*
28692896
** CAPI3REF: Opening A New Database Connection
28702897
**
2871
-** ^These routines open an SQLite database file whose name is given by the
2898
+** ^These routines open an SQLite database file as specified by the
28722899
** filename argument. ^The filename argument is interpreted as UTF-8 for
28732900
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
28742901
** order for sqlite3_open16(). ^(A [database connection] handle is usually
28752902
** returned in *ppDb, even if an error occurs. The only exception is that
28762903
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
@@ -2893,11 +2920,11 @@
28932920
** except that it accepts two additional parameters for additional control
28942921
** over the new database connection. ^(The flags parameter to
28952922
** sqlite3_open_v2() can take one of
28962923
** the following three values, optionally combined with the
28972924
** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2898
-** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
2925
+** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
28992926
**
29002927
** <dl>
29012928
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
29022929
** <dd>The database is opened in read-only mode. If the database does not
29032930
** already exist, an error is returned.</dd>)^
@@ -2912,13 +2939,12 @@
29122939
** it does not already exist. This is the behavior that is always used for
29132940
** sqlite3_open() and sqlite3_open16().</dd>)^
29142941
** </dl>
29152942
**
29162943
** If the 3rd parameter to sqlite3_open_v2() is not one of the
2917
-** combinations shown above or one of the combinations shown above combined
2918
-** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2919
-** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2944
+** combinations shown above optionally combined with other
2945
+** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
29202946
** then the behavior is undefined.
29212947
**
29222948
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
29232949
** opens in the multi-thread [threading mode] as long as the single-thread
29242950
** mode has not been set at compile-time or start-time. ^If the
@@ -2928,10 +2954,15 @@
29282954
** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
29292955
** eligible to use [shared cache mode], regardless of whether or not shared
29302956
** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
29312957
** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
29322958
** participate in [shared cache mode] even if it is enabled.
2959
+**
2960
+** ^The fourth parameter to sqlite3_open_v2() is the name of the
2961
+** [sqlite3_vfs] object that defines the operating system interface that
2962
+** the new database connection should use. ^If the fourth parameter is
2963
+** a NULL pointer then the default [sqlite3_vfs] object is used.
29332964
**
29342965
** ^If the filename is ":memory:", then a private, temporary in-memory database
29352966
** is created for the connection. ^This in-memory database will vanish when
29362967
** the database connection is closed. Future versions of SQLite might
29372968
** make use of additional special filenames that begin with the ":" character.
@@ -2941,14 +2972,115 @@
29412972
**
29422973
** ^If the filename is an empty string, then a private, temporary
29432974
** on-disk database will be created. ^This private database will be
29442975
** automatically deleted as soon as the database connection is closed.
29452976
**
2946
-** ^The fourth parameter to sqlite3_open_v2() is the name of the
2947
-** [sqlite3_vfs] object that defines the operating system interface that
2948
-** the new database connection should use. ^If the fourth parameter is
2949
-** a NULL pointer then the default [sqlite3_vfs] object is used.
2977
+** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
2978
+**
2979
+** ^If [URI filename] interpretation is enabled, and the filename argument
2980
+** begins with "file:", then the filename is interpreted as a URI. ^URI
2981
+** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
2982
+** is set in the fourth argument to sqlite3_open_v2(), or if it has
2983
+** been enabled globally using the [SQLITE_CONFIG_URI] option with the
2984
+** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
2985
+** As of SQLite version 3.7.7, URI filename interpretation is turned off
2986
+** by default, but future releases of SQLite might enable URI filename
2987
+** intepretation by default. See "[URI filenames]" for additional
2988
+** information.
2989
+**
2990
+** URI filenames are parsed according to RFC 3986. ^If the URI contains an
2991
+** authority, then it must be either an empty string or the string
2992
+** "localhost". ^If the authority is not an empty string or "localhost", an
2993
+** error is returned to the caller. ^The fragment component of a URI, if
2994
+** present, is ignored.
2995
+**
2996
+** ^SQLite uses the path component of the URI as the name of the disk file
2997
+** which contains the database. ^If the path begins with a '/' character,
2998
+** then it is interpreted as an absolute path. ^If the path does not begin
2999
+** with a '/' (meaning that the authority section is omitted from the URI)
3000
+** then the path is interpreted as a relative path.
3001
+** ^On windows, the first component of an absolute path
3002
+** is a drive specification (e.g. "C:").
3003
+**
3004
+** [[core URI query parameters]]
3005
+** The query component of a URI may contain parameters that are interpreted
3006
+** either by SQLite itself, or by a [VFS | custom VFS implementation].
3007
+** SQLite interprets the following three query parameters:
3008
+**
3009
+** <ul>
3010
+** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3011
+** a VFS object that provides the operating system interface that should
3012
+** be used to access the database file on disk. ^If this option is set to
3013
+** an empty string the default VFS object is used. ^Specifying an unknown
3014
+** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3015
+** present, then the VFS specified by the option takes precedence over
3016
+** the value passed as the fourth parameter to sqlite3_open_v2().
3017
+**
3018
+** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
3019
+** "rwc". Attempting to set it to any other value is an error)^.
3020
+** ^If "ro" is specified, then the database is opened for read-only
3021
+** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3022
+** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
3023
+** "rw", then the database is opened for read-write (but not create)
3024
+** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3025
+** been set. ^Value "rwc" is equivalent to setting both
3026
+** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
3027
+** used, it is an error to specify a value for the mode parameter that is
3028
+** less restrictive than that specified by the flags passed as the third
3029
+** parameter.
3030
+**
3031
+** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3032
+** "private". ^Setting it to "shared" is equivalent to setting the
3033
+** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3034
+** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3035
+** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3036
+** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3037
+** a URI filename, its value overrides any behaviour requested by setting
3038
+** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3039
+** </ul>
3040
+**
3041
+** ^Specifying an unknown parameter in the query component of a URI is not an
3042
+** error. Future versions of SQLite might understand additional query
3043
+** parameters. See "[query parameters with special meaning to SQLite]" for
3044
+** additional information.
3045
+**
3046
+** [[URI filename examples]] <h3>URI filename examples</h3>
3047
+**
3048
+** <table border="1" align=center cellpadding=5>
3049
+** <tr><th> URI filenames <th> Results
3050
+** <tr><td> file:data.db <td>
3051
+** Open the file "data.db" in the current directory.
3052
+** <tr><td> file:/home/fred/data.db<br>
3053
+** file:///home/fred/data.db <br>
3054
+** file://localhost/home/fred/data.db <br> <td>
3055
+** Open the database file "/home/fred/data.db".
3056
+** <tr><td> file://darkstar/home/fred/data.db <td>
3057
+** An error. "darkstar" is not a recognized authority.
3058
+** <tr><td style="white-space:nowrap">
3059
+** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3060
+** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3061
+** C:. Note that the %20 escaping in this example is not strictly
3062
+** necessary - space characters can be used literally
3063
+** in URI filenames.
3064
+** <tr><td> file:data.db?mode=ro&cache=private <td>
3065
+** Open file "data.db" in the current directory for read-only access.
3066
+** Regardless of whether or not shared-cache mode is enabled by
3067
+** default, use a private cache.
3068
+** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
3069
+** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
3070
+** <tr><td> file:data.db?mode=readonly <td>
3071
+** An error. "readonly" is not a valid option for the "mode" parameter.
3072
+** </table>
3073
+**
3074
+** ^URI hexadecimal escape sequences (%HH) are supported within the path and
3075
+** query components of a URI. A hexadecimal escape sequence consists of a
3076
+** percent sign - "%" - followed by exactly two hexadecimal digits
3077
+** specifying an octet value. ^Before the path or query components of a
3078
+** URI filename are interpreted, they are encoded using UTF-8 and all
3079
+** hexadecimal escape sequences replaced by a single byte containing the
3080
+** corresponding octet. If this process generates an invalid UTF-8 encoding,
3081
+** the results are undefined.
29503082
**
29513083
** <b>Note to Windows users:</b> The encoding used for the filename argument
29523084
** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
29533085
** codepage is currently defined. Filenames containing international
29543086
** characters must be converted to UTF-8 prior to passing them into
@@ -2966,10 +3098,30 @@
29663098
const char *filename, /* Database filename (UTF-8) */
29673099
sqlite3 **ppDb, /* OUT: SQLite db handle */
29683100
int flags, /* Flags */
29693101
const char *zVfs /* Name of VFS module to use */
29703102
);
3103
+
3104
+/*
3105
+** CAPI3REF: Obtain Values For URI Parameters
3106
+**
3107
+** This is a utility routine, useful to VFS implementations, that checks
3108
+** to see if a database file was a URI that contained a specific query
3109
+** parameter, and if so obtains the value of the query parameter.
3110
+**
3111
+** The zFilename argument is the filename pointer passed into the xOpen()
3112
+** method of a VFS implementation. The zParam argument is the name of the
3113
+** query parameter we seek. This routine returns the value of the zParam
3114
+** parameter if it exists. If the parameter does not exist, this routine
3115
+** returns a NULL pointer.
3116
+**
3117
+** If the zFilename argument to this function is not a pointer that SQLite
3118
+** passed into the xOpen VFS method, then the behavior of this routine
3119
+** is undefined and probably undesirable.
3120
+*/
3121
+SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3122
+
29713123
29723124
/*
29733125
** CAPI3REF: Error Codes And Messages
29743126
**
29753127
** ^The sqlite3_errcode() interface returns the numeric [result code] or
@@ -3082,47 +3234,49 @@
30823234
** that can be lowered at run-time using [sqlite3_limit()].
30833235
** The synopsis of the meanings of the various limits is shown below.
30843236
** Additional information is available at [limits | Limits in SQLite].
30853237
**
30863238
** <dl>
3087
-** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3239
+** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
30883240
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
30893241
**
3090
-** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3242
+** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
30913243
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
30923244
**
3093
-** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
3245
+** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
30943246
** <dd>The maximum number of columns in a table definition or in the
30953247
** result set of a [SELECT] or the maximum number of columns in an index
30963248
** or in an ORDER BY or GROUP BY clause.</dd>)^
30973249
**
3098
-** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
3250
+** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
30993251
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
31003252
**
3101
-** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3253
+** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
31023254
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
31033255
**
3104
-** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3256
+** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
31053257
** <dd>The maximum number of instructions in a virtual machine program
31063258
** used to implement an SQL statement. This limit is not currently
31073259
** enforced, though that might be added in some future release of
31083260
** SQLite.</dd>)^
31093261
**
3110
-** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3262
+** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
31113263
** <dd>The maximum number of arguments on a function.</dd>)^
31123264
**
3113
-** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
3265
+** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
31143266
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
31153267
**
3268
+** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
31163269
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
31173270
** <dd>The maximum length of the pattern argument to the [LIKE] or
31183271
** [GLOB] operators.</dd>)^
31193272
**
3273
+** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
31203274
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
31213275
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
31223276
**
3123
-** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3277
+** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
31243278
** <dd>The maximum depth of recursion for triggers.</dd>)^
31253279
** </dl>
31263280
*/
31273281
#define SQLITE_LIMIT_LENGTH 0
31283282
#define SQLITE_LIMIT_SQL_LENGTH 1
@@ -5153,10 +5307,15 @@
51535307
int (*xRollback)(sqlite3_vtab *pVTab);
51545308
int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
51555309
void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
51565310
void **ppArg);
51575311
int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
5312
+ /* The methods above are in version 1 of the sqlite_module object. Those
5313
+ ** below are for version 2 and greater. */
5314
+ int (*xSavepoint)(sqlite3_vtab *pVTab, int);
5315
+ int (*xRelease)(sqlite3_vtab *pVTab, int);
5316
+ int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
51585317
};
51595318
51605319
/*
51615320
** CAPI3REF: Virtual Table Indexing Information
51625321
** KEYWORDS: sqlite3_index_info
@@ -5967,11 +6126,11 @@
59676126
**
59686127
** ^This interface is used to retrieve runtime status information
59696128
** about the performance of SQLite, and optionally to reset various
59706129
** highwater marks. ^The first argument is an integer code for
59716130
** the specific parameter to measure. ^(Recognized integer codes
5972
-** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
6131
+** are of the form [status parameters | SQLITE_STATUS_...].)^
59736132
** ^The current value of the parameter is returned into *pCurrent.
59746133
** ^The highest recorded value is returned in *pHighwater. ^If the
59756134
** resetFlag is true, then the highest record value is reset after
59766135
** *pHighwater is written. ^(Some parameters do not record the highest
59776136
** value. For those parameters
@@ -5994,82 +6153,84 @@
59946153
SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
59956154
59966155
59976156
/*
59986157
** CAPI3REF: Status Parameters
6158
+** KEYWORDS: {status parameters}
59996159
**
60006160
** These integer constants designate various run-time status parameters
60016161
** that can be returned by [sqlite3_status()].
60026162
**
60036163
** <dl>
6004
-** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
6164
+** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
60056165
** <dd>This parameter is the current amount of memory checked out
60066166
** using [sqlite3_malloc()], either directly or indirectly. The
60076167
** figure includes calls made to [sqlite3_malloc()] by the application
60086168
** and internal memory usage by the SQLite library. Scratch memory
60096169
** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
60106170
** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
60116171
** this parameter. The amount returned is the sum of the allocation
60126172
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
60136173
**
6014
-** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
6174
+** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
60156175
** <dd>This parameter records the largest memory allocation request
60166176
** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
60176177
** internal equivalents). Only the value returned in the
60186178
** *pHighwater parameter to [sqlite3_status()] is of interest.
60196179
** The value written into the *pCurrent parameter is undefined.</dd>)^
60206180
**
6021
-** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
6181
+** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
60226182
** <dd>This parameter records the number of separate memory allocations
60236183
** currently checked out.</dd>)^
60246184
**
6025
-** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
6185
+** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
60266186
** <dd>This parameter returns the number of pages used out of the
60276187
** [pagecache memory allocator] that was configured using
60286188
** [SQLITE_CONFIG_PAGECACHE]. The
60296189
** value returned is in pages, not in bytes.</dd>)^
60306190
**
6191
+** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
60316192
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
60326193
** <dd>This parameter returns the number of bytes of page cache
60336194
** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
60346195
** buffer and where forced to overflow to [sqlite3_malloc()]. The
60356196
** returned value includes allocations that overflowed because they
60366197
** where too large (they were larger than the "sz" parameter to
60376198
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
60386199
** no space was left in the page cache.</dd>)^
60396200
**
6040
-** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
6201
+** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
60416202
** <dd>This parameter records the largest memory allocation request
60426203
** handed to [pagecache memory allocator]. Only the value returned in the
60436204
** *pHighwater parameter to [sqlite3_status()] is of interest.
60446205
** The value written into the *pCurrent parameter is undefined.</dd>)^
60456206
**
6046
-** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
6207
+** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
60476208
** <dd>This parameter returns the number of allocations used out of the
60486209
** [scratch memory allocator] configured using
60496210
** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
60506211
** in bytes. Since a single thread may only have one scratch allocation
60516212
** outstanding at time, this parameter also reports the number of threads
60526213
** using scratch memory at the same time.</dd>)^
60536214
**
6054
-** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
6215
+** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
60556216
** <dd>This parameter returns the number of bytes of scratch memory
60566217
** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
60576218
** buffer and where forced to overflow to [sqlite3_malloc()]. The values
60586219
** returned include overflows because the requested allocation was too
60596220
** larger (that is, because the requested allocation was larger than the
60606221
** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
60616222
** slots were available.
60626223
** </dd>)^
60636224
**
6064
-** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
6225
+** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
60656226
** <dd>This parameter records the largest memory allocation request
60666227
** handed to [scratch memory allocator]. Only the value returned in the
60676228
** *pHighwater parameter to [sqlite3_status()] is of interest.
60686229
** The value written into the *pCurrent parameter is undefined.</dd>)^
60696230
**
6070
-** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
6231
+** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
60716232
** <dd>This parameter records the deepest parser stack. It is only
60726233
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
60736234
** </dl>
60746235
**
60756236
** New status parameters may be added from time to time.
@@ -6090,13 +6251,13 @@
60906251
**
60916252
** ^This interface is used to retrieve runtime status information
60926253
** about a single [database connection]. ^The first argument is the
60936254
** database connection object to be interrogated. ^The second argument
60946255
** is an integer constant, taken from the set of
6095
-** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
6256
+** [SQLITE_DBSTATUS options], that
60966257
** determines the parameter to interrogate. The set of
6097
-** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
6258
+** [SQLITE_DBSTATUS options] is likely
60986259
** to grow in future releases of SQLite.
60996260
**
61006261
** ^The current value of the requested parameter is written into *pCur
61016262
** and the highest instantaneous value is written into *pHiwtr. ^If
61026263
** the resetFlg is true, then the highest instantaneous value is
@@ -6109,10 +6270,11 @@
61096270
*/
61106271
SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
61116272
61126273
/*
61136274
** CAPI3REF: Status Parameters for database connections
6275
+** KEYWORDS: {SQLITE_DBSTATUS options}
61146276
**
61156277
** These constants are the available integer "verbs" that can be passed as
61166278
** the second argument to the [sqlite3_db_status()] interface.
61176279
**
61186280
** New verbs may be added in future releases of SQLite. Existing verbs
@@ -6120,48 +6282,50 @@
61206282
** [sqlite3_db_status()] to make sure that the call worked.
61216283
** The [sqlite3_db_status()] interface will return a non-zero error code
61226284
** if a discontinued or unsupported verb is invoked.
61236285
**
61246286
** <dl>
6125
-** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6287
+** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
61266288
** <dd>This parameter returns the number of lookaside memory slots currently
61276289
** checked out.</dd>)^
61286290
**
6129
-** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6291
+** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
61306292
** <dd>This parameter returns the number malloc attempts that were
61316293
** satisfied using lookaside memory. Only the high-water value is meaningful;
61326294
** the current value is always zero.)^
61336295
**
6296
+** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
61346297
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
61356298
** <dd>This parameter returns the number malloc attempts that might have
61366299
** been satisfied using lookaside memory but failed due to the amount of
61376300
** memory requested being larger than the lookaside slot size.
61386301
** Only the high-water value is meaningful;
61396302
** the current value is always zero.)^
61406303
**
6304
+** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
61416305
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
61426306
** <dd>This parameter returns the number malloc attempts that might have
61436307
** been satisfied using lookaside memory but failed due to all lookaside
61446308
** memory already being in use.
61456309
** Only the high-water value is meaningful;
61466310
** the current value is always zero.)^
61476311
**
6148
-** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6312
+** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
61496313
** <dd>This parameter returns the approximate number of of bytes of heap
61506314
** memory used by all pager caches associated with the database connection.)^
61516315
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
61526316
**
6153
-** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6317
+** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
61546318
** <dd>This parameter returns the approximate number of of bytes of heap
61556319
** memory used to store the schema for all databases associated
61566320
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
61576321
** ^The full amount of memory used by the schemas is reported, even if the
61586322
** schema memory is shared with other database connections due to
61596323
** [shared cache mode] being enabled.
61606324
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
61616325
**
6162
-** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6326
+** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
61636327
** <dd>This parameter returns the approximate number of of bytes of heap
61646328
** and lookaside memory used by all prepared statements associated with
61656329
** the database connection.)^
61666330
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
61676331
** </dd>
@@ -6179,11 +6343,11 @@
61796343
61806344
/*
61816345
** CAPI3REF: Prepared Statement Status
61826346
**
61836347
** ^(Each prepared statement maintains various
6184
-** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
6348
+** [SQLITE_STMTSTATUS counters] that measure the number
61856349
** of times it has performed specific operations.)^ These counters can
61866350
** be used to monitor the performance characteristics of the prepared
61876351
** statements. For example, if the number of table steps greatly exceeds
61886352
** the number of table searches or result rows, that would tend to indicate
61896353
** that the prepared statement is using a full table scan rather than
@@ -6190,11 +6354,11 @@
61906354
** an index.
61916355
**
61926356
** ^(This interface is used to retrieve and reset counter values from
61936357
** a [prepared statement]. The first argument is the prepared statement
61946358
** object to be interrogated. The second argument
6195
-** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
6359
+** is an integer code for a specific [SQLITE_STMTSTATUS counter]
61966360
** to be interrogated.)^
61976361
** ^The current value of the requested counter is returned.
61986362
** ^If the resetFlg is true, then the counter is reset to zero after this
61996363
** interface call returns.
62006364
**
@@ -6202,28 +6366,29 @@
62026366
*/
62036367
SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
62046368
62056369
/*
62066370
** CAPI3REF: Status Parameters for prepared statements
6371
+** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
62076372
**
62086373
** These preprocessor macros define integer codes that name counter
62096374
** values associated with the [sqlite3_stmt_status()] interface.
62106375
** The meanings of the various counters are as follows:
62116376
**
62126377
** <dl>
6213
-** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
6378
+** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
62146379
** <dd>^This is the number of times that SQLite has stepped forward in
62156380
** a table as part of a full table scan. Large numbers for this counter
62166381
** may indicate opportunities for performance improvement through
62176382
** careful use of indices.</dd>
62186383
**
6219
-** <dt>SQLITE_STMTSTATUS_SORT</dt>
6384
+** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
62206385
** <dd>^This is the number of sort operations that have occurred.
62216386
** A non-zero value in this counter may indicate an opportunity to
62226387
** improvement performance through careful use of indices.</dd>
62236388
**
6224
-** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
6389
+** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
62256390
** <dd>^This is the number of rows inserted into transient indices that
62266391
** were created automatically in order to help joins run faster.
62276392
** A non-zero value in this counter may indicate an opportunity to
62286393
** improvement performance by adding permanent indices that do not
62296394
** need to be reinitialized each time the statement is run.</dd>
@@ -6270,10 +6435,11 @@
62706435
** ^(The contents of the sqlite3_pcache_methods structure are copied to an
62716436
** internal buffer by SQLite within the call to [sqlite3_config]. Hence
62726437
** the application may discard the parameter after the call to
62736438
** [sqlite3_config()] returns.)^
62746439
**
6440
+** [[the xInit() page cache method]]
62756441
** ^(The xInit() method is called once for each effective
62766442
** call to [sqlite3_initialize()])^
62776443
** (usually only once during the lifetime of the process). ^(The xInit()
62786444
** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
62796445
** The intent of the xInit() method is to set up global data structures
@@ -6280,10 +6446,11 @@
62806446
** required by the custom page cache implementation.
62816447
** ^(If the xInit() method is NULL, then the
62826448
** built-in default page cache is used instead of the application defined
62836449
** page cache.)^
62846450
**
6451
+** [[the xShutdown() page cache method]]
62856452
** ^The xShutdown() method is called by [sqlite3_shutdown()].
62866453
** It can be used to clean up
62876454
** any outstanding resources before process shutdown, if required.
62886455
** ^The xShutdown() method may be NULL.
62896456
**
@@ -6294,10 +6461,11 @@
62946461
** in multithreaded applications.
62956462
**
62966463
** ^SQLite will never invoke xInit() more than once without an intervening
62976464
** call to xShutdown().
62986465
**
6466
+** [[the xCreate() page cache methods]]
62996467
** ^SQLite invokes the xCreate() method to construct a new cache instance.
63006468
** SQLite will typically create one cache instance for each open database file,
63016469
** though this is not guaranteed. ^The
63026470
** first parameter, szPage, is the size in bytes of the pages that must
63036471
** be allocated by the cache. ^szPage will not be a power of two. ^szPage
@@ -6318,20 +6486,23 @@
63186486
** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
63196487
** false will always have the "discard" flag set to true.
63206488
** ^Hence, a cache created with bPurgeable false will
63216489
** never contain any unpinned pages.
63226490
**
6491
+** [[the xCachesize() page cache method]]
63236492
** ^(The xCachesize() method may be called at any time by SQLite to set the
63246493
** suggested maximum cache-size (number of pages stored by) the cache
63256494
** instance passed as the first argument. This is the value configured using
63266495
** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
63276496
** parameter, the implementation is not required to do anything with this
63286497
** value; it is advisory only.
63296498
**
6499
+** [[the xPagecount() page cache methods]]
63306500
** The xPagecount() method must return the number of pages currently
63316501
** stored in the cache, both pinned and unpinned.
63326502
**
6503
+** [[the xFetch() page cache methods]]
63336504
** The xFetch() method locates a page in the cache and returns a pointer to
63346505
** the page, or a NULL pointer.
63356506
** A "page", in this context, means a buffer of szPage bytes aligned at an
63366507
** 8-byte boundary. The page to be fetched is determined by the key. ^The
63376508
** mimimum key value is 1. After it has been retrieved using xFetch, the page
@@ -6356,10 +6527,11 @@
63566527
** will only use a createFlag of 2 after a prior call with a createFlag of 1
63576528
** failed.)^ In between the to xFetch() calls, SQLite may
63586529
** attempt to unpin one or more cache pages by spilling the content of
63596530
** pinned pages to disk and synching the operating system disk cache.
63606531
**
6532
+** [[the xUnpin() page cache method]]
63616533
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
63626534
** as its second argument. If the third parameter, discard, is non-zero,
63636535
** then the page must be evicted from the cache.
63646536
** ^If the discard parameter is
63656537
** zero, then the page may be discarded or retained at the discretion of
@@ -6368,10 +6540,11 @@
63686540
**
63696541
** The cache must not perform any reference counting. A single
63706542
** call to xUnpin() unpins the page regardless of the number of prior calls
63716543
** to xFetch().
63726544
**
6545
+** [[the xRekey() page cache methods]]
63736546
** The xRekey() method is used to change the key value associated with the
63746547
** page passed as the second argument. If the cache
63756548
** previously contains an entry associated with newKey, it must be
63766549
** discarded. ^Any prior cache entry associated with newKey is guaranteed not
63776550
** to be pinned.
@@ -6380,10 +6553,11 @@
63806553
** existing cache entries with page numbers (keys) greater than or equal
63816554
** to the value of the iLimit parameter passed to xTruncate(). If any
63826555
** of these pages are pinned, they are implicitly unpinned, meaning that
63836556
** they can be safely discarded.
63846557
**
6558
+** [[the xDestroy() page cache method]]
63856559
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
63866560
** All resources associated with the specified cache should be freed. ^After
63876561
** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
63886562
** handle invalid, and will not use it with any other sqlite3_pcache_methods
63896563
** functions.
@@ -6442,11 +6616,11 @@
64426616
** associated with the backup operation.
64436617
** </ol>)^
64446618
** There should be exactly one call to sqlite3_backup_finish() for each
64456619
** successful call to sqlite3_backup_init().
64466620
**
6447
-** <b>sqlite3_backup_init()</b>
6621
+** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
64486622
**
64496623
** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
64506624
** [database connection] associated with the destination database
64516625
** and the database name, respectively.
64526626
** ^The database name is "main" for the main database, "temp" for the
@@ -6469,11 +6643,11 @@
64696643
** [sqlite3_backup] object.
64706644
** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
64716645
** sqlite3_backup_finish() functions to perform the specified backup
64726646
** operation.
64736647
**
6474
-** <b>sqlite3_backup_step()</b>
6648
+** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
64756649
**
64766650
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
64776651
** the source and destination databases specified by [sqlite3_backup] object B.
64786652
** ^If N is negative, all remaining source pages are copied.
64796653
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
@@ -6526,11 +6700,11 @@
65266700
** restarted by the next call to sqlite3_backup_step(). ^If the source
65276701
** database is modified by the using the same database connection as is used
65286702
** by the backup operation, then the backup database is automatically
65296703
** updated at the same time.
65306704
**
6531
-** <b>sqlite3_backup_finish()</b>
6705
+** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
65326706
**
65336707
** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
65346708
** application wishes to abandon the backup operation, the application
65356709
** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
65366710
** ^The sqlite3_backup_finish() interfaces releases all
@@ -6549,11 +6723,12 @@
65496723
**
65506724
** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
65516725
** is not a permanent error and does not affect the return value of
65526726
** sqlite3_backup_finish().
65536727
**
6554
-** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
6728
+** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
6729
+** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
65556730
**
65566731
** ^Each call to sqlite3_backup_step() sets two values inside
65576732
** the [sqlite3_backup] object: the number of pages still to be backed
65586733
** up and the total number of pages in the source database file.
65596734
** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
@@ -6934,10 +7109,97 @@
69347109
** each of these values.
69357110
*/
69367111
#define SQLITE_CHECKPOINT_PASSIVE 0
69377112
#define SQLITE_CHECKPOINT_FULL 1
69387113
#define SQLITE_CHECKPOINT_RESTART 2
7114
+
7115
+/*
7116
+** CAPI3REF: Virtual Table Interface Configuration
7117
+**
7118
+** This function may be called by either the [xConnect] or [xCreate] method
7119
+** of a [virtual table] implementation to configure
7120
+** various facets of the virtual table interface.
7121
+**
7122
+** If this interface is invoked outside the context of an xConnect or
7123
+** xCreate virtual table method then the behavior is undefined.
7124
+**
7125
+** At present, there is only one option that may be configured using
7126
+** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
7127
+** may be added in the future.
7128
+*/
7129
+SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
7130
+
7131
+/*
7132
+** CAPI3REF: Virtual Table Configuration Options
7133
+**
7134
+** These macros define the various options to the
7135
+** [sqlite3_vtab_config()] interface that [virtual table] implementations
7136
+** can use to customize and optimize their behavior.
7137
+**
7138
+** <dl>
7139
+** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
7140
+** <dd>Calls of the form
7141
+** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
7142
+** where X is an integer. If X is zero, then the [virtual table] whose
7143
+** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
7144
+** support constraints. In this configuration (which is the default) if
7145
+** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
7146
+** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
7147
+** specified as part of the users SQL statement, regardless of the actual
7148
+** ON CONFLICT mode specified.
7149
+**
7150
+** If X is non-zero, then the virtual table implementation guarantees
7151
+** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
7152
+** any modifications to internal or persistent data structures have been made.
7153
+** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
7154
+** is able to roll back a statement or database transaction, and abandon
7155
+** or continue processing the current SQL statement as appropriate.
7156
+** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
7157
+** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
7158
+** had been ABORT.
7159
+**
7160
+** Virtual table implementations that are required to handle OR REPLACE
7161
+** must do so within the [xUpdate] method. If a call to the
7162
+** [sqlite3_vtab_on_conflict()] function indicates that the current ON
7163
+** CONFLICT policy is REPLACE, the virtual table implementation should
7164
+** silently replace the appropriate rows within the xUpdate callback and
7165
+** return SQLITE_OK. Or, if this is not possible, it may return
7166
+** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
7167
+** constraint handling.
7168
+** </dl>
7169
+*/
7170
+#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
7171
+
7172
+/*
7173
+** CAPI3REF: Determine The Virtual Table Conflict Policy
7174
+**
7175
+** This function may only be called from within a call to the [xUpdate] method
7176
+** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
7177
+** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
7178
+** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
7179
+** of the SQL statement that triggered the call to the [xUpdate] method of the
7180
+** [virtual table].
7181
+*/
7182
+SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
7183
+
7184
+/*
7185
+** CAPI3REF: Conflict resolution modes
7186
+**
7187
+** These constants are returned by [sqlite3_vtab_on_conflict()] to
7188
+** inform a [virtual table] implementation what the [ON CONFLICT] mode
7189
+** is for the SQL statement being evaluated.
7190
+**
7191
+** Note that the [SQLITE_IGNORE] constant is also used as a potential
7192
+** return value from the [sqlite3_set_authorizer()] callback and that
7193
+** [SQLITE_ABORT] is also a [result code].
7194
+*/
7195
+#define SQLITE_ROLLBACK 1
7196
+/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7197
+#define SQLITE_FAIL 3
7198
+/* #define SQLITE_ABORT 4 // Also an error code */
7199
+#define SQLITE_REPLACE 5
7200
+
69397201
69407202
69417203
/*
69427204
** Undo the hack that converts floating point types to integer for
69437205
** builds on processors without floating point support.
@@ -7601,10 +7863,11 @@
76017863
typedef struct Trigger Trigger;
76027864
typedef struct TriggerPrg TriggerPrg;
76037865
typedef struct TriggerStep TriggerStep;
76047866
typedef struct UnpackedRecord UnpackedRecord;
76057867
typedef struct VTable VTable;
7868
+typedef struct VtabCtx VtabCtx;
76067869
typedef struct Walker Walker;
76077870
typedef struct WherePlan WherePlan;
76087871
typedef struct WhereInfo WhereInfo;
76097872
typedef struct WhereLevel WhereLevel;
76107873
@@ -7657,10 +7920,11 @@
76577920
typedef struct BtCursor BtCursor;
76587921
typedef struct BtShared BtShared;
76597922
76607923
76617924
SQLITE_PRIVATE int sqlite3BtreeOpen(
7925
+ sqlite3_vfs *pVfs, /* VFS to use with this b-tree */
76627926
const char *zFilename, /* Name of database file to open */
76637927
sqlite3 *db, /* Associated database connection */
76647928
Btree **ppBtree, /* Return open Btree* here */
76657929
int flags, /* Flags */
76667930
int vfsFlags /* Flags passed through to VFS open */
@@ -9136,19 +9400,20 @@
91369400
struct sqlite3 {
91379401
sqlite3_vfs *pVfs; /* OS Interface */
91389402
int nDb; /* Number of backends currently in use */
91399403
Db *aDb; /* All backends */
91409404
int flags; /* Miscellaneous flags. See below */
9141
- int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
9405
+ unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
91429406
int errCode; /* Most recent error code (SQLITE_*) */
91439407
int errMask; /* & result codes with this before returning */
91449408
u8 autoCommit; /* The auto-commit flag. */
91459409
u8 temp_store; /* 1: file 2: memory 0: default */
91469410
u8 mallocFailed; /* True if we have seen a malloc failure */
91479411
u8 dfltLockMode; /* Default locking-mode for attached dbs */
91489412
signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
91499413
u8 suppressErr; /* Do not issue error messages if true */
9414
+ u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
91509415
int nextPagesize; /* Pagesize after VACUUM if >0 */
91519416
int nTable; /* Number of tables in the database */
91529417
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
91539418
i64 lastRowid; /* ROWID of most recent insert (see above) */
91549419
u32 magic; /* Magic number for detect library misuse */
@@ -9203,11 +9468,11 @@
92039468
void *pProgressArg; /* Argument to the progress callback */
92049469
int nProgressOps; /* Number of opcodes for progress callback */
92059470
#endif
92069471
#ifndef SQLITE_OMIT_VIRTUALTABLE
92079472
Hash aModule; /* populated by sqlite3_create_module() */
9208
- Table *pVTab; /* vtab with active Connect/Create method */
9473
+ VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
92099474
VTable **aVTrans; /* Virtual tables with open transactions */
92109475
int nVTrans; /* Allocated size of aVTrans */
92119476
VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
92129477
#endif
92139478
FuncDefHash aFunc; /* Hash table of connection functions */
@@ -9566,10 +9831,11 @@
95669831
struct VTable {
95679832
sqlite3 *db; /* Database connection associated with this table */
95689833
Module *pMod; /* Pointer to module implementation */
95699834
sqlite3_vtab *pVtab; /* Pointer to vtab instance */
95709835
int nRef; /* Number of pointers to this structure */
9836
+ u8 bConstraint; /* True if constraints are supported */
95719837
VTable *pNext; /* Next in linked list (see above) */
95729838
};
95739839
95749840
/*
95759841
** Each SQL table is represented in memory by an instance of the
@@ -10754,10 +11020,11 @@
1075411020
*/
1075511021
struct Sqlite3Config {
1075611022
int bMemstat; /* True to enable memory status */
1075711023
int bCoreMutex; /* True to enable core mutexing */
1075811024
int bFullMutex; /* True to enable full mutexing */
11025
+ int bOpenUri; /* True to interpret filenames as URIs */
1075911026
int mxStrlen; /* Maximum string length */
1076011027
int szLookaside; /* Default lookaside buffer size */
1076111028
int nLookaside; /* Default lookaside buffer count */
1076211029
sqlite3_mem_methods m; /* Low-level memory allocation interface */
1076311030
sqlite3_mutex_methods mutex; /* Low-level mutex interface */
@@ -11003,10 +11270,12 @@
1100311270
SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
1100411271
SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
1100511272
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
1100611273
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
1100711274
SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
11275
+SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
11276
+ sqlite3_vfs**,char**,char **);
1100811277
1100911278
SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32);
1101011279
SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32);
1101111280
SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
1101211281
SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
@@ -11253,10 +11522,11 @@
1125311522
SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
1125411523
SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
1125511524
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
1125611525
SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
1125711526
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
11527
+SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
1125811528
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1125911529
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1126011530
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
1126111531
SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
1126211532
SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
@@ -11268,10 +11538,16 @@
1126811538
SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
1126911539
SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
1127011540
SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
1127111541
SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
1127211542
SQLITE_PRIVATE int sqlite3AbsInt32(int);
11543
+#ifdef SQLITE_ENABLE_8_3_NAMES
11544
+SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*);
11545
+#else
11546
+# define sqlite3FileSuffix3(X,Y)
11547
+#endif
11548
+SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z);
1127311549
1127411550
SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
1127511551
SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
1127611552
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1127711553
void(*)(void*));
@@ -11377,18 +11653,20 @@
1137711653
# define sqlite3VtabCommit(X)
1137811654
# define sqlite3VtabInSync(db) 0
1137911655
# define sqlite3VtabLock(X)
1138011656
# define sqlite3VtabUnlock(X)
1138111657
# define sqlite3VtabUnlockList(X)
11658
+# define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
1138211659
#else
1138311660
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
1138411661
SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
1138511662
SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
1138611663
SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
1138711664
SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
1138811665
SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
1138911666
SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
11667
+SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
1139011668
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
1139111669
#endif
1139211670
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
1139311671
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
1139411672
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
@@ -11691,20 +11969,23 @@
1169111969
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
1169211970
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
1169311971
};
1169411972
#endif
1169511973
11696
-
11974
+#ifndef SQLITE_USE_URI
11975
+# define SQLITE_USE_URI 0
11976
+#endif
1169711977
1169811978
/*
1169911979
** The following singleton contains the global configuration for
1170011980
** the SQLite library.
1170111981
*/
1170211982
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
1170311983
SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
1170411984
1, /* bCoreMutex */
1170511985
SQLITE_THREADSAFE==1, /* bFullMutex */
11986
+ SQLITE_USE_URI, /* bOpenUri */
1170611987
0x7ffffffe, /* mxStrlen */
1170711988
100, /* szLookaside */
1170811989
500, /* nLookaside */
1170911990
{0,0,0,0,0,0,0,0}, /* m */
1171011991
{0,0,0,0,0,0,0,0,0}, /* mutex */
@@ -18217,11 +18498,11 @@
1821718498
sqlite3_mutex_enter(mem0.mutex);
1821818499
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
1821918500
nDiff = nNew - nOld;
1822018501
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
1822118502
mem0.alarmThreshold-nDiff ){
18222
- sqlite3MallocAlarm(nNew-nOld);
18503
+ sqlite3MallocAlarm(nDiff);
1822318504
}
1822418505
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
1822518506
assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
1822618507
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1822718508
if( pNew==0 && mem0.alarmCallback ){
@@ -18228,11 +18509,11 @@
1822818509
sqlite3MallocAlarm(nBytes);
1822918510
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1823018511
}
1823118512
if( pNew ){
1823218513
nNew = sqlite3MallocSize(pNew);
18233
- sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff);
18514
+ sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
1823418515
}
1823518516
sqlite3_mutex_leave(mem0.mutex);
1823618517
}else{
1823718518
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1823818519
}
@@ -21183,27 +21464,25 @@
2118321464
p[3] = (u8)v;
2118421465
}
2118521466
2118621467
2118721468
21188
-#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
2118921469
/*
2119021470
** Translate a single byte of Hex into an integer.
2119121471
** This routine only works if h really is a valid hexadecimal
2119221472
** character: 0..9a..fA..F
2119321473
*/
21194
-static u8 hexToInt(int h){
21474
+SQLITE_PRIVATE u8 sqlite3HexToInt(int h){
2119521475
assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') );
2119621476
#ifdef SQLITE_ASCII
2119721477
h += 9*(1&(h>>6));
2119821478
#endif
2119921479
#ifdef SQLITE_EBCDIC
2120021480
h += 9*(1&~(h>>4));
2120121481
#endif
2120221482
return (u8)(h & 0xf);
2120321483
}
21204
-#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */
2120521484
2120621485
#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
2120721486
/*
2120821487
** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
2120921488
** value. Return a pointer to its binary value. Space to hold the
@@ -21216,11 +21495,11 @@
2121621495
2121721496
zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
2121821497
n--;
2121921498
if( zBlob ){
2122021499
for(i=0; i<n; i+=2){
21221
- zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);
21500
+ zBlob[i/2] = (sqlite3HexToInt(z[i])<<4) | sqlite3HexToInt(z[i+1]);
2122221501
}
2122321502
zBlob[i/2] = 0;
2122421503
}
2122521504
return zBlob;
2122621505
}
@@ -21348,10 +21627,36 @@
2134821627
SQLITE_PRIVATE int sqlite3AbsInt32(int x){
2134921628
if( x>=0 ) return x;
2135021629
if( x==(int)0x80000000 ) return 0x7fffffff;
2135121630
return -x;
2135221631
}
21632
+
21633
+#ifdef SQLITE_ENABLE_8_3_NAMES
21634
+/*
21635
+** If SQLITE_ENABLE_8_3_NAME is set at compile-time and if the database
21636
+** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
21637
+** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
21638
+** three characters, then shorten the suffix on z[] to be the last three
21639
+** characters of the original suffix.
21640
+**
21641
+** Examples:
21642
+**
21643
+** test.db-journal => test.nal
21644
+** test.db-wal => test.wal
21645
+** test.db-shm => test.shm
21646
+*/
21647
+SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
21648
+ const char *zOk;
21649
+ zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names");
21650
+ if( zOk && sqlite3GetBoolean(zOk) ){
21651
+ int i, sz;
21652
+ sz = sqlite3Strlen30(z);
21653
+ for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
21654
+ if( z[i]=='.' && ALWAYS(sz>i+4) ) memcpy(&z[i+1], &z[sz-3], 4);
21655
+ }
21656
+}
21657
+#endif
2135321658
2135421659
/************** End of util.c ************************************************/
2135521660
/************** Begin file hash.c ********************************************/
2135621661
/*
2135721662
** 2001 September 22
@@ -27890,10 +28195,11 @@
2789028195
sqlite3_snprintf(nShmFilename, zShmFilename,
2789128196
SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
2789228197
(u32)sStat.st_ino, (u32)sStat.st_dev);
2789328198
#else
2789428199
sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
28200
+ sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
2789528201
#endif
2789628202
pShmNode->h = -1;
2789728203
pDbFd->pInode->pShmNode = pShmNode;
2789828204
pShmNode->pInode = pDbFd->pInode;
2789928205
pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
@@ -28923,17 +29229,23 @@
2892329229
** Finally, if the file being opened is a WAL or regular journal file, then
2892429230
** this function queries the file-system for the permissions on the
2892529231
** corresponding database file and sets *pMode to this value. Whenever
2892629232
** possible, WAL and journal files are created using the same permissions
2892729233
** as the associated database file.
29234
+**
29235
+** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
29236
+** original filename is unavailable. But 8_3_NAMES is only used for
29237
+** FAT filesystems and permissions do not matter there, so just use
29238
+** the default permissions.
2892829239
*/
2892929240
static int findCreateFileMode(
2893029241
const char *zPath, /* Path of file (possibly) being created */
2893129242
int flags, /* Flags passed as 4th argument to xOpen() */
2893229243
mode_t *pMode /* OUT: Permissions to open file with */
2893329244
){
2893429245
int rc = SQLITE_OK; /* Return Code */
29246
+ *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
2893529247
if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
2893629248
char zDb[MAX_PATHNAME+1]; /* Database file path */
2893729249
int nDb; /* Number of valid bytes in zDb */
2893829250
struct stat sStat; /* Output of stat() on database file */
2893929251
@@ -28941,19 +29253,19 @@
2894129253
** the path to the associated database file from zPath. This block handles
2894229254
** the following naming conventions:
2894329255
**
2894429256
** "<path to db>-journal"
2894529257
** "<path to db>-wal"
28946
- ** "<path to db>-journal-NNNN"
28947
- ** "<path to db>-wal-NNNN"
29258
+ ** "<path to db>-journalNN"
29259
+ ** "<path to db>-walNN"
2894829260
**
28949
- ** where NNNN is a 4 digit decimal number. The NNNN naming schemes are
29261
+ ** where NN is a 4 digit decimal number. The NN naming schemes are
2895029262
** used by the test_multiplex.c module.
2895129263
*/
2895229264
nDb = sqlite3Strlen30(zPath) - 1;
28953
- while( nDb>0 && zPath[nDb]!='l' ) nDb--;
28954
- nDb -= ((flags & SQLITE_OPEN_WAL) ? 3 : 7);
29265
+ while( nDb>0 && zPath[nDb]!='-' ) nDb--;
29266
+ if( nDb==0 ) return SQLITE_OK;
2895529267
memcpy(zDb, zPath, nDb);
2895629268
zDb[nDb] = '\0';
2895729269
2895829270
if( 0==stat(zDb, &sStat) ){
2895929271
*pMode = sStat.st_mode & 0777;
@@ -28960,12 +29272,10 @@
2896029272
}else{
2896129273
rc = SQLITE_IOERR_FSTAT;
2896229274
}
2896329275
}else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
2896429276
*pMode = 0600;
28965
- }else{
28966
- *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
2896729277
}
2896829278
return rc;
2896929279
}
2897029280
2897129281
/*
@@ -32620,10 +32930,11 @@
3262032930
return SQLITE_NOMEM;
3262132931
}
3262232932
memset(pNew, 0, sizeof(*pNew));
3262332933
pNew->zFilename = (char*)&pNew[1];
3262432934
sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
32935
+ sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
3262532936
3262632937
/* Look to see if there is an existing winShmNode that can be used.
3262732938
** If no matching winShmNode currently exists, create a new one.
3262832939
*/
3262932940
winShmEnterMutex();
@@ -33514,10 +33825,17 @@
3351433825
3351533826
#if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
3351633827
int nByte;
3351733828
void *zConverted;
3351833829
char *zOut;
33830
+
33831
+ /* If this path name begins with "/X:", where "X" is any alphabetic
33832
+ ** character, discard the initial "/" from the pathname.
33833
+ */
33834
+ if( zRelative[0]=='/' && sqlite3Isalpha(zRelative[1]) && zRelative[2]==':' ){
33835
+ zRelative++;
33836
+ }
3351933837
3352033838
/* It's odd to simulate an io-error here, but really this is just
3352133839
** using the io-error infrastructure to test that SQLite handles this
3352233840
** function failing. This function could fail if, for example, the
3352333841
** current working directory has been unlinked.
@@ -36326,10 +36644,11 @@
3632636644
#define _WAL_H_
3632736645
3632836646
3632936647
#ifdef SQLITE_OMIT_WAL
3633036648
# define sqlite3WalOpen(x,y,z) 0
36649
+# define sqlite3WalLimit(x,y)
3633136650
# define sqlite3WalClose(w,x,y,z) 0
3633236651
# define sqlite3WalBeginReadTransaction(y,z) 0
3633336652
# define sqlite3WalEndReadTransaction(z)
3633436653
# define sqlite3WalRead(v,w,x,y,z) 0
3633536654
# define sqlite3WalDbsize(y) 0
@@ -36351,13 +36670,16 @@
3635136670
** There is one object of this type for each pager.
3635236671
*/
3635336672
typedef struct Wal Wal;
3635436673
3635536674
/* Open and close a connection to a write-ahead log. */
36356
-SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *zName, int, Wal**);
36675
+SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**);
3635736676
SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *);
3635836677
36678
+/* Set the limiting size of a WAL file. */
36679
+SQLITE_PRIVATE void sqlite3WalLimit(Wal*, i64);
36680
+
3635936681
/* Used by readers to open (lock) and close (unlock) a snapshot. A
3636036682
** snapshot is like a read-transaction. It is the state of the database
3636136683
** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
3636236684
** preserves the current state even if the other threads or processes
3636336685
** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
@@ -40702,10 +41024,12 @@
4070241024
int nPathname = 0; /* Number of bytes in zPathname */
4070341025
int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
4070441026
int noReadlock = (flags & PAGER_NO_READLOCK)!=0; /* True to omit read-lock */
4070541027
int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
4070641028
u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
41029
+ const char *zUri = 0; /* URI args to copy */
41030
+ int nUri = 0; /* Number of bytes of URI args at *zUri */
4070741031
4070841032
/* Figure out how much space is required for each journal file-handle
4070941033
** (there are two of them, the main journal and the sub-journal). This
4071041034
** is the maximum space required for an in-memory journal file handle
4071141035
** and a regular journal file-handle. Note that a "regular journal-handle"
@@ -40732,18 +41056,25 @@
4073241056
/* Compute and store the full pathname in an allocated buffer pointed
4073341057
** to by zPathname, length nPathname. Or, if this is a temporary file,
4073441058
** leave both nPathname and zPathname set to 0.
4073541059
*/
4073641060
if( zFilename && zFilename[0] ){
41061
+ const char *z;
4073741062
nPathname = pVfs->mxPathname+1;
4073841063
zPathname = sqlite3Malloc(nPathname*2);
4073941064
if( zPathname==0 ){
4074041065
return SQLITE_NOMEM;
4074141066
}
4074241067
zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
4074341068
rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
4074441069
nPathname = sqlite3Strlen30(zPathname);
41070
+ z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
41071
+ while( *z ){
41072
+ z += sqlite3Strlen30(z)+1;
41073
+ z += sqlite3Strlen30(z)+1;
41074
+ }
41075
+ nUri = &z[1] - zUri;
4074541076
if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
4074641077
/* This branch is taken when the journal path required by
4074741078
** the database being opened will be more than pVfs->mxPathname
4074841079
** bytes in length. This means the database cannot be opened,
4074941080
** as it will not be possible to open the journal file or even
@@ -40772,11 +41103,11 @@
4077241103
pPtr = (u8 *)sqlite3MallocZero(
4077341104
ROUND8(sizeof(*pPager)) + /* Pager structure */
4077441105
ROUND8(pcacheSize) + /* PCache object */
4077541106
ROUND8(pVfs->szOsFile) + /* The main db file */
4077641107
journalFileSize * 2 + /* The two journal files */
40777
- nPathname + 1 + /* zFilename */
41108
+ nPathname + 1 + nUri + /* zFilename */
4077841109
nPathname + 8 + 1 /* zJournal */
4077941110
#ifndef SQLITE_OMIT_WAL
4078041111
+ nPathname + 4 + 1 /* zWal */
4078141112
#endif
4078241113
);
@@ -40794,18 +41125,21 @@
4079441125
assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
4079541126
4079641127
/* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
4079741128
if( zPathname ){
4079841129
assert( nPathname>0 );
40799
- pPager->zJournal = (char*)(pPtr += nPathname + 1);
41130
+ pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
4080041131
memcpy(pPager->zFilename, zPathname, nPathname);
41132
+ memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
4080141133
memcpy(pPager->zJournal, zPathname, nPathname);
4080241134
memcpy(&pPager->zJournal[nPathname], "-journal", 8);
41135
+ sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
4080341136
#ifndef SQLITE_OMIT_WAL
4080441137
pPager->zWal = &pPager->zJournal[nPathname+8+1];
4080541138
memcpy(pPager->zWal, zPathname, nPathname);
4080641139
memcpy(&pPager->zWal[nPathname], "-wal", 4);
41140
+ sqlite3FileSuffix3(pPager->zFilename, pPager->zWal);
4080741141
#endif
4080841142
sqlite3_free(zPathname);
4080941143
}
4081041144
pPager->pVfs = pVfs;
4081141145
pPager->vfsFlags = vfsFlags;
@@ -43000,10 +43334,11 @@
4300043334
** An attempt to set a limit smaller than -1 is a no-op.
4300143335
*/
4300243336
SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){
4300343337
if( iLimit>=-1 ){
4300443338
pPager->journalSizeLimit = iLimit;
43339
+ sqlite3WalLimit(pPager->pWal, iLimit);
4300543340
}
4300643341
return pPager->journalSizeLimit;
4300743342
}
4300843343
4300943344
/*
@@ -43091,11 +43426,12 @@
4309143426
/* Open the connection to the log file. If this operation fails,
4309243427
** (e.g. due to malloc() failure), return an error code.
4309343428
*/
4309443429
if( rc==SQLITE_OK ){
4309543430
rc = sqlite3WalOpen(pPager->pVfs,
43096
- pPager->fd, pPager->zWal, pPager->exclusiveMode, &pPager->pWal
43431
+ pPager->fd, pPager->zWal, pPager->exclusiveMode,
43432
+ pPager->journalSizeLimit, &pPager->pWal
4309743433
);
4309843434
}
4309943435
4310043436
return rc;
4310143437
}
@@ -43623,10 +43959,11 @@
4362343959
struct Wal {
4362443960
sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */
4362543961
sqlite3_file *pDbFd; /* File handle for the database file */
4362643962
sqlite3_file *pWalFd; /* File handle for WAL file */
4362743963
u32 iCallback; /* Value to pass to log callback (or 0) */
43964
+ i64 mxWalSize; /* Truncate WAL to this size upon reset */
4362843965
int nWiData; /* Size of array apWiData */
4362943966
volatile u32 **apWiData; /* Pointer to wal-index content in memory */
4363043967
u32 szPage; /* Database page size */
4363143968
i16 readLock; /* Which read lock is being held. -1 for none */
4363243969
u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
@@ -44445,10 +44782,11 @@
4444544782
SQLITE_PRIVATE int sqlite3WalOpen(
4444644783
sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
4444744784
sqlite3_file *pDbFd, /* The open database file */
4444844785
const char *zWalName, /* Name of the WAL file */
4444944786
int bNoShm, /* True to run in heap-memory mode */
44787
+ i64 mxWalSize, /* Truncate WAL to this size on reset */
4445044788
Wal **ppWal /* OUT: Allocated Wal handle */
4445144789
){
4445244790
int rc; /* Return Code */
4445344791
Wal *pRet; /* Object to allocate and return */
4445444792
int flags; /* Flags passed to OsOpen() */
@@ -44477,10 +44815,11 @@
4447744815
4447844816
pRet->pVfs = pVfs;
4447944817
pRet->pWalFd = (sqlite3_file *)&pRet[1];
4448044818
pRet->pDbFd = pDbFd;
4448144819
pRet->readLock = -1;
44820
+ pRet->mxWalSize = mxWalSize;
4448244821
pRet->zWalName = zWalName;
4448344822
pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE);
4448444823
4448544824
/* Open file handle on the write-ahead log file. */
4448644825
flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
@@ -44497,10 +44836,17 @@
4449744836
*ppWal = pRet;
4449844837
WALTRACE(("WAL%d: opened\n", pRet));
4449944838
}
4450044839
return rc;
4450144840
}
44841
+
44842
+/*
44843
+** Change the size to which the WAL file is trucated on each reset.
44844
+*/
44845
+SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){
44846
+ if( pWal ) pWal->mxWalSize = iLimit;
44847
+}
4450244848
4450344849
/*
4450444850
** Find the smallest page number out of all pages held in the WAL that
4450544851
** has not been returned by any prior invocation of this method on the
4450644852
** same WalIterator object. Write into *piFrame the frame index where
@@ -45733,10 +46079,26 @@
4573346079
** safe and means there is no special case for sqlite3WalUndo()
4573446080
** to handle if this transaction is rolled back.
4573546081
*/
4573646082
int i; /* Loop counter */
4573746083
u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
46084
+
46085
+ /* Limit the size of WAL file if the journal_size_limit PRAGMA is
46086
+ ** set to a non-negative value. Log errors encountered
46087
+ ** during the truncation attempt. */
46088
+ if( pWal->mxWalSize>=0 ){
46089
+ i64 sz;
46090
+ int rx;
46091
+ rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
46092
+ if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
46093
+ rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
46094
+ }
46095
+ if( rx ){
46096
+ sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
46097
+ }
46098
+ }
46099
+
4573846100
pWal->nCkpt++;
4573946101
pWal->hdr.mxFrame = 0;
4574046102
sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
4574146103
aSalt[1] = salt1;
4574246104
walIndexWriteHdr(pWal);
@@ -47838,10 +48200,11 @@
4783848200
offset = PTRMAP_PTROFFSET(iPtrmap, key);
4783948201
if( offset<0 ){
4784048202
*pRC = SQLITE_CORRUPT_BKPT;
4784148203
goto ptrmap_exit;
4784248204
}
48205
+ assert( offset <= (int)pBt->usableSize-5 );
4784348206
pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
4784448207
4784548208
if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
4784648209
TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
4784748210
*pRC= rc = sqlite3PagerWrite(pDbPage);
@@ -47877,10 +48240,15 @@
4787748240
return rc;
4787848241
}
4787948242
pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
4788048243
4788148244
offset = PTRMAP_PTROFFSET(iPtrmap, key);
48245
+ if( offset<0 ){
48246
+ sqlite3PagerUnref(pDbPage);
48247
+ return SQLITE_CORRUPT_BKPT;
48248
+ }
48249
+ assert( offset <= (int)pBt->usableSize-5 );
4788248250
assert( pEType!=0 );
4788348251
*pEType = pPtrmap[offset];
4788448252
if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);
4788548253
4788648254
sqlite3PagerUnref(pDbPage);
@@ -48738,17 +49106,17 @@
4873849106
** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
4873949107
** objects in the same database connection since doing so will lead
4874049108
** to problems with locking.
4874149109
*/
4874249110
SQLITE_PRIVATE int sqlite3BtreeOpen(
49111
+ sqlite3_vfs *pVfs, /* VFS to use for this b-tree */
4874349112
const char *zFilename, /* Name of the file containing the BTree database */
4874449113
sqlite3 *db, /* Associated database handle */
4874549114
Btree **ppBtree, /* Pointer to new Btree object written here */
4874649115
int flags, /* Options */
4874749116
int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */
4874849117
){
48749
- sqlite3_vfs *pVfs; /* The VFS to use for this btree */
4875049118
BtShared *pBt = 0; /* Shared part of btree structure */
4875149119
Btree *p; /* Handle to return */
4875249120
sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
4875349121
int rc = SQLITE_OK; /* Result code from this function */
4875449122
u8 nReserve; /* Byte of unused space on each page */
@@ -48766,10 +49134,11 @@
4876649134
const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
4876749135
|| (isTempDb && sqlite3TempInMemory(db));
4876849136
#endif
4876949137
4877049138
assert( db!=0 );
49139
+ assert( pVfs!=0 );
4877149140
assert( sqlite3_mutex_held(db->mutex) );
4877249141
assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
4877349142
4877449143
/* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
4877549144
assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
@@ -48784,11 +49153,10 @@
4878449153
flags |= BTREE_MEMORY;
4878549154
}
4878649155
if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
4878749156
vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
4878849157
}
48789
- pVfs = db->pVfs;
4879049158
p = sqlite3MallocZero(sizeof(Btree));
4879149159
if( !p ){
4879249160
return SQLITE_NOMEM;
4879349161
}
4879449162
p->inTrans = TRANS_NONE;
@@ -58855,10 +59223,11 @@
5885559223
sqlite3_randomness(sizeof(iRandom), &iRandom);
5885659224
zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);
5885759225
if( !zMaster ){
5885859226
return SQLITE_NOMEM;
5885959227
}
59228
+ sqlite3FileSuffix3(zMainFile, zMaster);
5886059229
rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
5886159230
}while( rc==SQLITE_OK && res );
5886259231
if( rc==SQLITE_OK ){
5886359232
/* Open the master journal. */
5886459233
rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster,
@@ -59068,10 +59437,19 @@
5906859437
}
5906959438
}
5907059439
}
5907159440
db->nStatement--;
5907259441
p->iStatement = 0;
59442
+
59443
+ if( rc==SQLITE_OK ){
59444
+ if( eOp==SAVEPOINT_ROLLBACK ){
59445
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
59446
+ }
59447
+ if( rc==SQLITE_OK ){
59448
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
59449
+ }
59450
+ }
5907359451
5907459452
/* If the statement transaction is being rolled back, also restore the
5907559453
** database handles deferred constraint counter to the value it had when
5907659454
** the statement transaction was opened. */
5907759455
if( eOp==SAVEPOINT_ROLLBACK ){
@@ -62400,10 +62778,11 @@
6240062778
Mem *pIn2 = 0; /* 2nd input operand */
6240162779
Mem *pIn3 = 0; /* 3rd input operand */
6240262780
Mem *pOut = 0; /* Output operand */
6240362781
int iCompare = 0; /* Result of last OP_Compare operation */
6240462782
int *aPermute = 0; /* Permutation of columns for OP_Compare */
62783
+ i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6240562784
#ifdef VDBE_PROFILE
6240662785
u64 start; /* CPU clock count at start of opcode */
6240762786
int origPc; /* Program counter at start of opcode */
6240862787
#endif
6240962788
/********************************************************************
@@ -63078,10 +63457,11 @@
6307863457
VdbeFrame *pFrame = p->pFrame;
6307963458
p->pFrame = pFrame->pParent;
6308063459
p->nFrame--;
6308163460
sqlite3VdbeSetChanges(db, p->nChange);
6308263461
pc = sqlite3VdbeFrameRestore(pFrame);
63462
+ lastRowid = db->lastRowid;
6308363463
if( pOp->p2==OE_Ignore ){
6308463464
/* Instruction pc is the OP_Program that invoked the sub-program
6308563465
** currently being halted. If the p2 instruction of this OP_Halt
6308663466
** instruction is set to OE_Ignore, then the sub-program is throwing
6308763467
** an IGNORE exception. In this case jump to the address specified
@@ -63650,11 +64030,13 @@
6365064030
assert( pOp>aOp );
6365164031
assert( pOp[-1].p4type==P4_COLLSEQ );
6365264032
assert( pOp[-1].opcode==OP_CollSeq );
6365364033
u.ag.ctx.pColl = pOp[-1].p4.pColl;
6365464034
}
64035
+ db->lastRowid = lastRowid;
6365564036
(*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
64037
+ lastRowid = db->lastRowid;
6365664038
if( db->mallocFailed ){
6365764039
/* Even though a malloc() has failed, the implementation of the
6365864040
** user function may have called an sqlite3_result_XXX() function
6365964041
** to return a value. The following call releases any resources
6366064042
** associated with such a value.
@@ -64857,10 +65239,18 @@
6485765239
"SQL statements in progress");
6485865240
rc = SQLITE_BUSY;
6485965241
}else{
6486065242
u.aq.nName = sqlite3Strlen30(u.aq.zName);
6486165243
65244
+ /* This call is Ok even if this savepoint is actually a transaction
65245
+ ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
65246
+ ** If this is a transaction savepoint being opened, it is guaranteed
65247
+ ** that the db->aVTrans[] array is empty. */
65248
+ assert( db->autoCommit==0 || db->nVTrans==0 );
65249
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
65250
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
65251
+
6486265252
/* Create a new savepoint structure. */
6486365253
u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
6486465254
if( u.aq.pNew ){
6486565255
u.aq.pNew->zName = (char *)&u.aq.pNew[1];
6486665256
memcpy(u.aq.pNew->zName, u.aq.zName, u.aq.nName+1);
@@ -64963,10 +65353,15 @@
6496365353
db->nSavepoint--;
6496465354
}
6496565355
}else{
6496665356
db->nDeferredCons = u.aq.pSavepoint->nDeferredCons;
6496765357
}
65358
+
65359
+ if( !isTransaction ){
65360
+ rc = sqlite3VtabSavepoint(db, u.aq.p1, u.aq.iSavepoint);
65361
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
65362
+ }
6496865363
}
6496965364
}
6497065365
6497165366
break;
6497265367
}
@@ -65102,11 +65497,15 @@
6510265497
if( p->iStatement==0 ){
6510365498
assert( db->nStatement>=0 && db->nSavepoint>=0 );
6510465499
db->nStatement++;
6510565500
p->iStatement = db->nSavepoint + db->nStatement;
6510665501
}
65107
- rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
65502
+
65503
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
65504
+ if( rc==SQLITE_OK ){
65505
+ rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
65506
+ }
6510865507
6510965508
/* Store the current value of the database handles deferred constraint
6511065509
** counter. If the statement transaction needs to be rolled back,
6511165510
** the value of this counter needs to be restored too. */
6511265511
p->nStmtDefCons = db->nDeferredCons;
@@ -65423,11 +65822,11 @@
6542365822
6542465823
assert( pOp->p1>=0 );
6542565824
u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
6542665825
if( u.ax.pCx==0 ) goto no_mem;
6542765826
u.ax.pCx->nullRow = 1;
65428
- rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt,
65827
+ rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ax.pCx->pBt,
6542965828
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
6543065829
if( rc==SQLITE_OK ){
6543165830
rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1);
6543265831
}
6543365832
if( rc==SQLITE_OK ){
@@ -66097,11 +66496,11 @@
6609766496
** engine starts picking positive candidate ROWIDs at random until
6609866497
** it finds one that is not previously used. */
6609966498
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
6610066499
** an AUTOINCREMENT table. */
6610166500
/* on the first attempt, simply do one more than previous */
66102
- u.be.v = db->lastRowid;
66501
+ u.be.v = lastRowid;
6610366502
u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
6610466503
u.be.v++; /* ensure non-zero */
6610566504
u.be.cnt = 0;
6610666505
while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v,
6610766506
0, &u.be.res))==SQLITE_OK)
@@ -66209,11 +66608,11 @@
6620966608
assert( pOp->opcode==OP_InsertInt );
6621066609
u.bf.iKey = pOp->p3;
6621166610
}
6621266611
6621366612
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
66214
- if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = u.bf.iKey;
66613
+ if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bf.iKey;
6621566614
if( u.bf.pData->flags & MEM_Null ){
6621666615
u.bf.pData->z = 0;
6621766616
u.bf.pData->n = 0;
6621866617
}else{
6621966618
assert( u.bf.pData->flags & (MEM_Blob|MEM_Str) );
@@ -67335,11 +67734,11 @@
6733567734
assert( pc==u.by.pFrame->pc );
6733667735
}
6733767736
6733867737
p->nFrame++;
6733967738
u.by.pFrame->pParent = p->pFrame;
67340
- u.by.pFrame->lastRowid = db->lastRowid;
67739
+ u.by.pFrame->lastRowid = lastRowid;
6734167740
u.by.pFrame->nChange = p->nChange;
6734267741
p->nChange = 0;
6734367742
p->pFrame = u.by.pFrame;
6734467743
p->aMem = aMem = &VdbeFrameMem(u.by.pFrame)[-1];
6734567744
p->nMem = u.by.pFrame->nChildMem;
@@ -68146,31 +68545,45 @@
6814668545
sqlite_int64 rowid;
6814768546
Mem **apArg;
6814868547
Mem *pX;
6814968548
#endif /* local variables moved into u.cm */
6815068549
68550
+ assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
68551
+ || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
68552
+ );
6815168553
u.cm.pVtab = pOp->p4.pVtab->pVtab;
6815268554
u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
6815368555
u.cm.nArg = pOp->p2;
6815468556
assert( pOp->p4type==P4_VTAB );
6815568557
if( ALWAYS(u.cm.pModule->xUpdate) ){
68558
+ u8 vtabOnConflict = db->vtabOnConflict;
6815668559
u.cm.apArg = p->apArg;
6815768560
u.cm.pX = &aMem[pOp->p3];
6815868561
for(u.cm.i=0; u.cm.i<u.cm.nArg; u.cm.i++){
6815968562
assert( memIsValid(u.cm.pX) );
6816068563
memAboutToChange(p, u.cm.pX);
6816168564
sqlite3VdbeMemStoreType(u.cm.pX);
6816268565
u.cm.apArg[u.cm.i] = u.cm.pX;
6816368566
u.cm.pX++;
6816468567
}
68568
+ db->vtabOnConflict = pOp->p5;
6816568569
rc = u.cm.pModule->xUpdate(u.cm.pVtab, u.cm.nArg, u.cm.apArg, &u.cm.rowid);
68570
+ db->vtabOnConflict = vtabOnConflict;
6816668571
importVtabErrMsg(p, u.cm.pVtab);
6816768572
if( rc==SQLITE_OK && pOp->p1 ){
6816868573
assert( u.cm.nArg>1 && u.cm.apArg[0] && (u.cm.apArg[0]->flags&MEM_Null) );
68169
- db->lastRowid = u.cm.rowid;
68574
+ db->lastRowid = lastRowid = u.cm.rowid;
6817068575
}
68171
- p->nChange++;
68576
+ if( rc==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
68577
+ if( pOp->p5==OE_Ignore ){
68578
+ rc = SQLITE_OK;
68579
+ }else{
68580
+ p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5);
68581
+ }
68582
+ }else{
68583
+ p->nChange++;
68584
+ }
6817268585
}
6817368586
break;
6817468587
}
6817568588
#endif /* SQLITE_OMIT_VIRTUALTABLE */
6817668589
@@ -68316,10 +68729,11 @@
6831668729
6831768730
/* This is the only way out of this procedure. We have to
6831868731
** release the mutexes on btrees that were acquired at the
6831968732
** top. */
6832068733
vdbe_return:
68734
+ db->lastRowid = lastRowid;
6832168735
sqlite3VdbeLeave(p);
6832268736
return rc;
6832368737
6832468738
/* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
6832568739
** is encountered.
@@ -76044,12 +76458,16 @@
7604476458
int i;
7604576459
int rc = 0;
7604676460
sqlite3 *db = sqlite3_context_db_handle(context);
7604776461
const char *zName;
7604876462
const char *zFile;
76463
+ char *zPath = 0;
76464
+ char *zErr = 0;
76465
+ unsigned int flags;
7604976466
Db *aNew;
7605076467
char *zErrDyn = 0;
76468
+ sqlite3_vfs *pVfs;
7605176469
7605276470
UNUSED_PARAMETER(NotUsed);
7605376471
7605476472
zFile = (const char *)sqlite3_value_text(argv[0]);
7605576473
zName = (const char *)sqlite3_value_text(argv[1]);
@@ -76098,12 +76516,22 @@
7609876516
7609976517
/* Open the database file. If the btree is successfully opened, use
7610076518
** it to obtain the database schema. At this point the schema may
7610176519
** or may not be initialised.
7610276520
*/
76103
- rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,
76104
- db->openFlags | SQLITE_OPEN_MAIN_DB);
76521
+ flags = db->openFlags;
76522
+ rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
76523
+ if( rc!=SQLITE_OK ){
76524
+ if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
76525
+ sqlite3_result_error(context, zErr, -1);
76526
+ sqlite3_free(zErr);
76527
+ return;
76528
+ }
76529
+ assert( pVfs );
76530
+ flags |= SQLITE_OPEN_MAIN_DB;
76531
+ rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
76532
+ sqlite3_free( zPath );
7610576533
db->nDb++;
7610676534
if( rc==SQLITE_CONSTRAINT ){
7610776535
rc = SQLITE_ERROR;
7610876536
zErrDyn = sqlite3MPrintf(db, "database is already attached");
7610976537
}else if( rc==SQLITE_OK ){
@@ -80213,11 +80641,11 @@
8021380641
SQLITE_OPEN_CREATE |
8021480642
SQLITE_OPEN_EXCLUSIVE |
8021580643
SQLITE_OPEN_DELETEONCLOSE |
8021680644
SQLITE_OPEN_TEMP_DB;
8021780645
80218
- rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags);
80646
+ rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
8021980647
if( rc!=SQLITE_OK ){
8022080648
sqlite3ErrorMsg(pParse, "unable to open a temporary database "
8022180649
"file for storing temporary tables");
8022280650
pParse->rc = rc;
8022380651
return 1;
@@ -85399,10 +85827,11 @@
8539985827
#ifndef SQLITE_OMIT_VIRTUALTABLE
8540085828
if( IsVirtual(pTab) ){
8540185829
const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
8540285830
sqlite3VtabMakeWritable(pParse, pTab);
8540385831
sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB);
85832
+ sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
8540485833
sqlite3MayAbort(pParse);
8540585834
}else
8540685835
#endif
8540785836
{
8540885837
int isReplace; /* Set to true if constraints may cause a replace */
@@ -87544,11 +87973,11 @@
8754487973
}
8754587974
8754687975
/*
8754787976
** Interpret the given string as a boolean value.
8754887977
*/
87549
-static u8 getBoolean(const char *z){
87978
+SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){
8755087979
return getSafetyLevel(z)&1;
8755187980
}
8755287981
8755387982
/*
8755487983
** Interpret the given string as a locking mode value.
@@ -87714,11 +88143,11 @@
8771488143
/* Foreign key support may not be enabled or disabled while not
8771588144
** in auto-commit mode. */
8771688145
mask &= ~(SQLITE_ForeignKeys);
8771788146
}
8771888147
87719
- if( getBoolean(zRight) ){
88148
+ if( sqlite3GetBoolean(zRight) ){
8772088149
db->flags |= mask;
8772188150
}else{
8772288151
db->flags &= ~mask;
8772388152
}
8772488153
@@ -87928,11 +88357,11 @@
8792888357
if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
8792988358
Btree *pBt = pDb->pBt;
8793088359
int b = -1;
8793188360
assert( pBt!=0 );
8793288361
if( zRight ){
87933
- b = getBoolean(zRight);
88362
+ b = sqlite3GetBoolean(zRight);
8793488363
}
8793588364
if( pId2->n==0 && b>=0 ){
8793688365
int ii;
8793788366
for(ii=0; ii<db->nDb; ii++){
8793888367
sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
@@ -88528,11 +88957,11 @@
8852888957
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
8852988958
8853088959
#ifndef NDEBUG
8853188960
if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
8853288961
if( zRight ){
88533
- if( getBoolean(zRight) ){
88962
+ if( sqlite3GetBoolean(zRight) ){
8853488963
sqlite3ParserTrace(stderr, "parser: ");
8853588964
}else{
8853688965
sqlite3ParserTrace(0, 0);
8853788966
}
8853888967
}
@@ -88542,11 +88971,11 @@
8854288971
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
8854388972
** used will be case sensitive or not depending on the RHS.
8854488973
*/
8854588974
if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
8854688975
if( zRight ){
88547
- sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
88976
+ sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight));
8854888977
}
8854988978
}else
8855088979
8855188980
#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
8855288981
# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
@@ -95683,11 +96112,12 @@
9568396112
SrcList *pSrc, /* The virtual table to be modified */
9568496113
Table *pTab, /* The virtual table */
9568596114
ExprList *pChanges, /* The columns to change in the UPDATE statement */
9568696115
Expr *pRowidExpr, /* Expression used to recompute the rowid */
9568796116
int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
95688
- Expr *pWhere /* WHERE clause of the UPDATE statement */
96117
+ Expr *pWhere, /* WHERE clause of the UPDATE statement */
96118
+ int onError /* ON CONFLICT strategy */
9568996119
);
9569096120
#endif /* SQLITE_OMIT_VIRTUALTABLE */
9569196121
9569296122
/*
9569396123
** The most recently coded instruction was an OP_Column to retrieve the
@@ -95927,11 +96357,11 @@
9592796357
9592896358
#ifndef SQLITE_OMIT_VIRTUALTABLE
9592996359
/* Virtual tables must be handled separately */
9593096360
if( IsVirtual(pTab) ){
9593196361
updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
95932
- pWhere);
96362
+ pWhere, onError);
9593396363
pWhere = 0;
9593496364
pTabList = 0;
9593596365
goto update_cleanup;
9593696366
}
9593796367
#endif
@@ -96257,11 +96687,12 @@
9625796687
SrcList *pSrc, /* The virtual table to be modified */
9625896688
Table *pTab, /* The virtual table */
9625996689
ExprList *pChanges, /* The columns to change in the UPDATE statement */
9626096690
Expr *pRowid, /* Expression used to recompute the rowid */
9626196691
int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
96262
- Expr *pWhere /* WHERE clause of the UPDATE statement */
96692
+ Expr *pWhere, /* WHERE clause of the UPDATE statement */
96693
+ int onError /* ON CONFLICT strategy */
9626396694
){
9626496695
Vdbe *v = pParse->pVdbe; /* Virtual machine under construction */
9626596696
ExprList *pEList = 0; /* The result set of the SELECT statement */
9626696697
Select *pSelect = 0; /* The SELECT statement */
9626796698
Expr *pExpr; /* Temporary expression */
@@ -96314,10 +96745,11 @@
9631496745
for(i=0; i<pTab->nCol; i++){
9631596746
sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
9631696747
}
9631796748
sqlite3VtabMakeWritable(pParse, pTab);
9631896749
sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
96750
+ sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
9631996751
sqlite3MayAbort(pParse);
9632096752
sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
9632196753
sqlite3VdbeJumpHere(v, addr);
9632296754
sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
9632396755
@@ -96687,10 +97119,22 @@
9668797119
*************************************************************************
9668897120
** This file contains code used to help implement virtual tables.
9668997121
*/
9669097122
#ifndef SQLITE_OMIT_VIRTUALTABLE
9669197123
97124
+/*
97125
+** Before a virtual table xCreate() or xConnect() method is invoked, the
97126
+** sqlite3.pVtabCtx member variable is set to point to an instance of
97127
+** this struct allocated on the stack. It is used by the implementation of
97128
+** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which
97129
+** are invoked only from within xCreate and xConnect methods.
97130
+*/
97131
+struct VtabCtx {
97132
+ Table *pTab;
97133
+ VTable *pVTable;
97134
+};
97135
+
9669297136
/*
9669397137
** The actual function that does the work of creating a new module.
9669497138
** This function implements the sqlite3_create_module() and
9669597139
** sqlite3_create_module_v2() interfaces.
9669697140
*/
@@ -96715,17 +97159,17 @@
9671597159
pMod->pModule = pModule;
9671697160
pMod->pAux = pAux;
9671797161
pMod->xDestroy = xDestroy;
9671897162
pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
9671997163
if( pDel && pDel->xDestroy ){
97164
+ sqlite3ResetInternalSchema(db, -1);
9672097165
pDel->xDestroy(pDel->pAux);
9672197166
}
9672297167
sqlite3DbFree(db, pDel);
9672397168
if( pDel==pMod ){
9672497169
db->mallocFailed = 1;
9672597170
}
96726
- sqlite3ResetInternalSchema(db, -1);
9672797171
}else if( xDestroy ){
9672897172
xDestroy(pAux);
9672997173
}
9673097174
rc = sqlite3ApiExit(db, SQLITE_OK);
9673197175
sqlite3_mutex_leave(db->mutex);
@@ -97107,10 +97551,11 @@
9710797551
Table *pTab,
9710897552
Module *pMod,
9710997553
int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
9711097554
char **pzErr
9711197555
){
97556
+ VtabCtx sCtx;
9711297557
VTable *pVTable;
9711397558
int rc;
9711497559
const char *const*azArg = (const char *const*)pTab->azModuleArg;
9711597560
int nArg = pTab->nModuleArg;
9711697561
char *zErr = 0;
@@ -97126,16 +97571,18 @@
9712697571
return SQLITE_NOMEM;
9712797572
}
9712897573
pVTable->db = db;
9712997574
pVTable->pMod = pMod;
9713097575
97131
- assert( !db->pVTab );
97576
+ /* Invoke the virtual table constructor */
97577
+ assert( &db->pVtabCtx );
9713297578
assert( xConstruct );
97133
- db->pVTab = pTab;
97134
-
97135
- /* Invoke the virtual table constructor */
97579
+ sCtx.pTab = pTab;
97580
+ sCtx.pVTable = pVTable;
97581
+ db->pVtabCtx = &sCtx;
9713697582
rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
97583
+ db->pVtabCtx = 0;
9713797584
if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
9713897585
9713997586
if( SQLITE_OK!=rc ){
9714097587
if( zErr==0 ){
9714197588
*pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
@@ -97147,11 +97594,11 @@
9714797594
}else if( ALWAYS(pVTable->pVtab) ){
9714897595
/* Justification of ALWAYS(): A correct vtab constructor must allocate
9714997596
** the sqlite3_vtab object if successful. */
9715097597
pVTable->pVtab->pModule = pMod->pModule;
9715197598
pVTable->nRef = 1;
97152
- if( db->pVTab ){
97599
+ if( sCtx.pTab ){
9715397600
const char *zFormat = "vtable constructor did not declare schema: %s";
9715497601
*pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
9715597602
sqlite3VtabUnlock(pVTable);
9715697603
rc = SQLITE_ERROR;
9715797604
}else{
@@ -97195,11 +97642,10 @@
9719597642
}
9719697643
}
9719797644
}
9719897645
9719997646
sqlite3DbFree(db, zModuleName);
97200
- db->pVTab = 0;
9720197647
return rc;
9720297648
}
9720397649
9720497650
/*
9720597651
** This function is invoked by the parser to call the xConnect() method
@@ -97315,12 +97761,11 @@
9731597761
int rc = SQLITE_OK;
9731697762
Table *pTab;
9731797763
char *zErr = 0;
9731897764
9731997765
sqlite3_mutex_enter(db->mutex);
97320
- pTab = db->pVTab;
97321
- if( !pTab ){
97766
+ if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
9732297767
sqlite3Error(db, SQLITE_MISUSE, 0);
9732397768
sqlite3_mutex_leave(db->mutex);
9732497769
return SQLITE_MISUSE_BKPT;
9732597770
}
9732697771
assert( (pTab->tabFlags & TF_Virtual)!=0 );
@@ -97343,11 +97788,11 @@
9734397788
pTab->aCol = pParse->pNewTable->aCol;
9734497789
pTab->nCol = pParse->pNewTable->nCol;
9734597790
pParse->pNewTable->nCol = 0;
9734697791
pParse->pNewTable->aCol = 0;
9734797792
}
97348
- db->pVTab = 0;
97793
+ db->pVtabCtx->pTab = 0;
9734997794
}else{
9735097795
sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
9735197796
sqlite3DbFree(db, zErr);
9735297797
rc = SQLITE_ERROR;
9735397798
}
@@ -97495,11 +97940,10 @@
9749597940
pModule = pVTab->pVtab->pModule;
9749697941
9749797942
if( pModule->xBegin ){
9749897943
int i;
9749997944
97500
-
9750197945
/* If pVtab is already in the aVTrans array, return early */
9750297946
for(i=0; i<db->nVTrans; i++){
9750397947
if( db->aVTrans[i]==pVTab ){
9750497948
return SQLITE_OK;
9750597949
}
@@ -97508,10 +97952,53 @@
9750897952
/* Invoke the xBegin method */
9750997953
rc = pModule->xBegin(pVTab->pVtab);
9751097954
if( rc==SQLITE_OK ){
9751197955
rc = addToVTrans(db, pVTab);
9751297956
}
97957
+ }
97958
+ return rc;
97959
+}
97960
+
97961
+/*
97962
+** Invoke either the xSavepoint, xRollbackTo or xRelease method of all
97963
+** virtual tables that currently have an open transaction. Pass iSavepoint
97964
+** as the second argument to the virtual table method invoked.
97965
+**
97966
+** If op is SAVEPOINT_BEGIN, the xSavepoint method is invoked. If it is
97967
+** SAVEPOINT_ROLLBACK, the xRollbackTo method. Otherwise, if op is
97968
+** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with
97969
+** an open transaction is invoked.
97970
+**
97971
+** If any virtual table method returns an error code other than SQLITE_OK,
97972
+** processing is abandoned and the error returned to the caller of this
97973
+** function immediately. If all calls to virtual table methods are successful,
97974
+** SQLITE_OK is returned.
97975
+*/
97976
+SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
97977
+ int rc = SQLITE_OK;
97978
+
97979
+ assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
97980
+ if( db->aVTrans ){
97981
+ int i;
97982
+ for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
97983
+ const sqlite3_module *pMod = db->aVTrans[i]->pMod->pModule;
97984
+ if( pMod->iVersion>=2 ){
97985
+ int (*xMethod)(sqlite3_vtab *, int);
97986
+ switch( op ){
97987
+ case SAVEPOINT_BEGIN:
97988
+ xMethod = pMod->xSavepoint;
97989
+ break;
97990
+ case SAVEPOINT_ROLLBACK:
97991
+ xMethod = pMod->xRollbackTo;
97992
+ break;
97993
+ default:
97994
+ xMethod = pMod->xRelease;
97995
+ break;
97996
+ }
97997
+ if( xMethod ) rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint);
97998
+ }
97999
+ }
9751398000
}
9751498001
return rc;
9751598002
}
9751698003
9751798004
/*
@@ -97609,10 +98096,61 @@
9760998096
pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
9761098097
}else{
9761198098
pToplevel->db->mallocFailed = 1;
9761298099
}
9761398100
}
98101
+
98102
+/*
98103
+** Return the ON CONFLICT resolution mode in effect for the virtual
98104
+** table update operation currently in progress.
98105
+**
98106
+** The results of this routine are undefined unless it is called from
98107
+** within an xUpdate method.
98108
+*/
98109
+SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
98110
+ static const unsigned char aMap[] = {
98111
+ SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
98112
+ };
98113
+ assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
98114
+ assert( OE_Ignore==4 && OE_Replace==5 );
98115
+ assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
98116
+ return (int)aMap[db->vtabOnConflict-1];
98117
+}
98118
+
98119
+/*
98120
+** Call from within the xCreate() or xConnect() methods to provide
98121
+** the SQLite core with additional information about the behavior
98122
+** of the virtual table being implemented.
98123
+*/
98124
+SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
98125
+ va_list ap;
98126
+ int rc = SQLITE_OK;
98127
+
98128
+ sqlite3_mutex_enter(db->mutex);
98129
+
98130
+ va_start(ap, op);
98131
+ switch( op ){
98132
+ case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
98133
+ VtabCtx *p = db->pVtabCtx;
98134
+ if( !p ){
98135
+ rc = SQLITE_MISUSE_BKPT;
98136
+ }else{
98137
+ assert( p->pTab==0 || (p->pTab->tabFlags & TF_Virtual)!=0 );
98138
+ p->pVTable->bConstraint = (u8)va_arg(ap, int);
98139
+ }
98140
+ break;
98141
+ }
98142
+ default:
98143
+ rc = SQLITE_MISUSE_BKPT;
98144
+ break;
98145
+ }
98146
+ va_end(ap);
98147
+
98148
+ if( rc!=SQLITE_OK ) sqlite3Error(db, rc, 0);
98149
+ sqlite3_mutex_leave(db->mutex);
98150
+ return rc;
98151
+}
9761498152
9761598153
#endif /* SQLITE_OMIT_VIRTUALTABLE */
9761698154
9761798155
/************** End of vtab.c ************************************************/
9761898156
/************** Begin file where.c *******************************************/
@@ -107631,10 +108169,15 @@
107631108169
typedef void(*LOGFUNC_t)(void*,int,const char*);
107632108170
sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
107633108171
sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
107634108172
break;
107635108173
}
108174
+
108175
+ case SQLITE_CONFIG_URI: {
108176
+ sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
108177
+ break;
108178
+ }
107636108179
107637108180
default: {
107638108181
rc = SQLITE_ERROR;
107639108182
break;
107640108183
}
@@ -108990,25 +109533,257 @@
108990109533
}
108991109534
db->aLimit[limitId] = newLimit;
108992109535
}
108993109536
return oldLimit; /* IMP: R-53341-35419 */
108994109537
}
109538
+
109539
+/*
109540
+** This function is used to parse both URIs and non-URI filenames passed by the
109541
+** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
109542
+** URIs specified as part of ATTACH statements.
109543
+**
109544
+** The first argument to this function is the name of the VFS to use (or
109545
+** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
109546
+** query parameter. The second argument contains the URI (or non-URI filename)
109547
+** itself. When this function is called the *pFlags variable should contain
109548
+** the default flags to open the database handle with. The value stored in
109549
+** *pFlags may be updated before returning if the URI filename contains
109550
+** "cache=xxx" or "mode=xxx" query parameters.
109551
+**
109552
+** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
109553
+** the VFS that should be used to open the database file. *pzFile is set to
109554
+** point to a buffer containing the name of the file to open. It is the
109555
+** responsibility of the caller to eventually call sqlite3_free() to release
109556
+** this buffer.
109557
+**
109558
+** If an error occurs, then an SQLite error code is returned and *pzErrMsg
109559
+** may be set to point to a buffer containing an English language error
109560
+** message. It is the responsibility of the caller to eventually release
109561
+** this buffer by calling sqlite3_free().
109562
+*/
109563
+SQLITE_PRIVATE int sqlite3ParseUri(
109564
+ const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */
109565
+ const char *zUri, /* Nul-terminated URI to parse */
109566
+ unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
109567
+ sqlite3_vfs **ppVfs, /* OUT: VFS to use */
109568
+ char **pzFile, /* OUT: Filename component of URI */
109569
+ char **pzErrMsg /* OUT: Error message (if rc!=SQLITE_OK) */
109570
+){
109571
+ int rc = SQLITE_OK;
109572
+ unsigned int flags = *pFlags;
109573
+ const char *zVfs = zDefaultVfs;
109574
+ char *zFile;
109575
+ char c;
109576
+ int nUri = sqlite3Strlen30(zUri);
109577
+
109578
+ assert( *pzErrMsg==0 );
109579
+
109580
+ if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
109581
+ && nUri>=5 && memcmp(zUri, "file:", 5)==0
109582
+ ){
109583
+ char *zOpt;
109584
+ int eState; /* Parser state when parsing URI */
109585
+ int iIn; /* Input character index */
109586
+ int iOut = 0; /* Output character index */
109587
+ int nByte = nUri+2; /* Bytes of space to allocate */
109588
+
109589
+ /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
109590
+ ** method that there may be extra parameters following the file-name. */
109591
+ flags |= SQLITE_OPEN_URI;
109592
+
109593
+ for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
109594
+ zFile = sqlite3_malloc(nByte);
109595
+ if( !zFile ) return SQLITE_NOMEM;
109596
+
109597
+ /* Discard the scheme and authority segments of the URI. */
109598
+ if( zUri[5]=='/' && zUri[6]=='/' ){
109599
+ iIn = 7;
109600
+ while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
109601
+
109602
+ if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
109603
+ *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
109604
+ iIn-7, &zUri[7]);
109605
+ rc = SQLITE_ERROR;
109606
+ goto parse_uri_out;
109607
+ }
109608
+ }else{
109609
+ iIn = 5;
109610
+ }
109611
+
109612
+ /* Copy the filename and any query parameters into the zFile buffer.
109613
+ ** Decode %HH escape codes along the way.
109614
+ **
109615
+ ** Within this loop, variable eState may be set to 0, 1 or 2, depending
109616
+ ** on the parsing context. As follows:
109617
+ **
109618
+ ** 0: Parsing file-name.
109619
+ ** 1: Parsing name section of a name=value query parameter.
109620
+ ** 2: Parsing value section of a name=value query parameter.
109621
+ */
109622
+ eState = 0;
109623
+ while( (c = zUri[iIn])!=0 && c!='#' ){
109624
+ iIn++;
109625
+ if( c=='%'
109626
+ && sqlite3Isxdigit(zUri[iIn])
109627
+ && sqlite3Isxdigit(zUri[iIn+1])
109628
+ ){
109629
+ int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
109630
+ octet += sqlite3HexToInt(zUri[iIn++]);
109631
+
109632
+ assert( octet>=0 && octet<256 );
109633
+ if( octet==0 ){
109634
+ /* This branch is taken when "%00" appears within the URI. In this
109635
+ ** case we ignore all text in the remainder of the path, name or
109636
+ ** value currently being parsed. So ignore the current character
109637
+ ** and skip to the next "?", "=" or "&", as appropriate. */
109638
+ while( (c = zUri[iIn])!=0 && c!='#'
109639
+ && (eState!=0 || c!='?')
109640
+ && (eState!=1 || (c!='=' && c!='&'))
109641
+ && (eState!=2 || c!='&')
109642
+ ){
109643
+ iIn++;
109644
+ }
109645
+ continue;
109646
+ }
109647
+ c = octet;
109648
+ }else if( eState==1 && (c=='&' || c=='=') ){
109649
+ if( zFile[iOut-1]==0 ){
109650
+ /* An empty option name. Ignore this option altogether. */
109651
+ while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++;
109652
+ continue;
109653
+ }
109654
+ if( c=='&' ){
109655
+ zFile[iOut++] = '\0';
109656
+ }else{
109657
+ eState = 2;
109658
+ }
109659
+ c = 0;
109660
+ }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
109661
+ c = 0;
109662
+ eState = 1;
109663
+ }
109664
+ zFile[iOut++] = c;
109665
+ }
109666
+ if( eState==1 ) zFile[iOut++] = '\0';
109667
+ zFile[iOut++] = '\0';
109668
+ zFile[iOut++] = '\0';
109669
+
109670
+ /* Check if there were any options specified that should be interpreted
109671
+ ** here. Options that are interpreted here include "vfs" and those that
109672
+ ** correspond to flags that may be passed to the sqlite3_open_v2()
109673
+ ** method. */
109674
+ zOpt = &zFile[sqlite3Strlen30(zFile)+1];
109675
+ while( zOpt[0] ){
109676
+ int nOpt = sqlite3Strlen30(zOpt);
109677
+ char *zVal = &zOpt[nOpt+1];
109678
+ int nVal = sqlite3Strlen30(zVal);
109679
+
109680
+ if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
109681
+ zVfs = zVal;
109682
+ }else{
109683
+ struct OpenMode {
109684
+ const char *z;
109685
+ int mode;
109686
+ } *aMode = 0;
109687
+ char *zModeType;
109688
+ int mask;
109689
+ int limit;
109690
+
109691
+ if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
109692
+ static struct OpenMode aCacheMode[] = {
109693
+ { "shared", SQLITE_OPEN_SHAREDCACHE },
109694
+ { "private", SQLITE_OPEN_PRIVATECACHE },
109695
+ { 0, 0 }
109696
+ };
109697
+
109698
+ mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE;
109699
+ aMode = aCacheMode;
109700
+ limit = mask;
109701
+ zModeType = "cache";
109702
+ }
109703
+ if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
109704
+ static struct OpenMode aOpenMode[] = {
109705
+ { "ro", SQLITE_OPEN_READONLY },
109706
+ { "rw", SQLITE_OPEN_READWRITE },
109707
+ { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
109708
+ { 0, 0 }
109709
+ };
109710
+
109711
+ mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
109712
+ aMode = aOpenMode;
109713
+ limit = mask & flags;
109714
+ zModeType = "access";
109715
+ }
109716
+
109717
+ if( aMode ){
109718
+ int i;
109719
+ int mode = 0;
109720
+ for(i=0; aMode[i].z; i++){
109721
+ const char *z = aMode[i].z;
109722
+ if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
109723
+ mode = aMode[i].mode;
109724
+ break;
109725
+ }
109726
+ }
109727
+ if( mode==0 ){
109728
+ *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
109729
+ rc = SQLITE_ERROR;
109730
+ goto parse_uri_out;
109731
+ }
109732
+ if( mode>limit ){
109733
+ *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
109734
+ zModeType, zVal);
109735
+ rc = SQLITE_PERM;
109736
+ goto parse_uri_out;
109737
+ }
109738
+ flags = (flags & ~mask) | mode;
109739
+ }
109740
+ }
109741
+
109742
+ zOpt = &zVal[nVal+1];
109743
+ }
109744
+
109745
+ }else{
109746
+ zFile = sqlite3_malloc(nUri+2);
109747
+ if( !zFile ) return SQLITE_NOMEM;
109748
+ memcpy(zFile, zUri, nUri);
109749
+ zFile[nUri] = '\0';
109750
+ zFile[nUri+1] = '\0';
109751
+ }
109752
+
109753
+ *ppVfs = sqlite3_vfs_find(zVfs);
109754
+ if( *ppVfs==0 ){
109755
+ *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
109756
+ rc = SQLITE_ERROR;
109757
+ }
109758
+ parse_uri_out:
109759
+ if( rc!=SQLITE_OK ){
109760
+ sqlite3_free(zFile);
109761
+ zFile = 0;
109762
+ }
109763
+ *pFlags = flags;
109764
+ *pzFile = zFile;
109765
+ return rc;
109766
+}
109767
+
108995109768
108996109769
/*
108997109770
** This routine does the work of opening a database on behalf of
108998109771
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
108999109772
** is UTF-8 encoded.
109000109773
*/
109001109774
static int openDatabase(
109002109775
const char *zFilename, /* Database filename UTF-8 encoded */
109003109776
sqlite3 **ppDb, /* OUT: Returned database handle */
109004
- unsigned flags, /* Operational flags */
109777
+ unsigned int flags, /* Operational flags */
109005109778
const char *zVfs /* Name of the VFS to use */
109006109779
){
109007
- sqlite3 *db;
109008
- int rc;
109009
- int isThreadsafe;
109780
+ sqlite3 *db; /* Store allocated handle here */
109781
+ int rc; /* Return code */
109782
+ int isThreadsafe; /* True for threadsafe connections */
109783
+ char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
109784
+ char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
109010109785
109011109786
*ppDb = 0;
109012109787
#ifndef SQLITE_OMIT_AUTOINIT
109013109788
rc = sqlite3_initialize();
109014109789
if( rc ) return rc;
@@ -109028,11 +109803,11 @@
109028109803
assert( SQLITE_OPEN_READWRITE == 0x02 );
109029109804
assert( SQLITE_OPEN_CREATE == 0x04 );
109030109805
testcase( (1<<(flags&7))==0x02 ); /* READONLY */
109031109806
testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
109032109807
testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
109033
- if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE;
109808
+ if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE_BKPT;
109034109809
109035109810
if( sqlite3GlobalConfig.bCoreMutex==0 ){
109036109811
isThreadsafe = 0;
109037109812
}else if( flags & SQLITE_OPEN_NOMUTEX ){
109038109813
isThreadsafe = 0;
@@ -109109,17 +109884,10 @@
109109109884
sqlite3HashInit(&db->aCollSeq);
109110109885
#ifndef SQLITE_OMIT_VIRTUALTABLE
109111109886
sqlite3HashInit(&db->aModule);
109112109887
#endif
109113109888
109114
- db->pVfs = sqlite3_vfs_find(zVfs);
109115
- if( !db->pVfs ){
109116
- rc = SQLITE_ERROR;
109117
- sqlite3Error(db, rc, "no such vfs: %s", zVfs);
109118
- goto opendb_out;
109119
- }
109120
-
109121109889
/* Add the default collation sequence BINARY. BINARY works for both UTF-8
109122109890
** and UTF-16, so add a version for each to avoid any unnecessary
109123109891
** conversions. The only error that can occur here is a malloc() failure.
109124109892
*/
109125109893
createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0,
@@ -109138,13 +109906,22 @@
109138109906
109139109907
/* Also add a UTF-8 case-insensitive collation sequence. */
109140109908
createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
109141109909
nocaseCollatingFunc, 0);
109142109910
109143
- /* Open the backend database driver */
109911
+ /* Parse the filename/URI argument. */
109144109912
db->openFlags = flags;
109145
- rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0,
109913
+ rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
109914
+ if( rc!=SQLITE_OK ){
109915
+ if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
109916
+ sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
109917
+ sqlite3_free(zErrMsg);
109918
+ goto opendb_out;
109919
+ }
109920
+
109921
+ /* Open the backend database driver */
109922
+ rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
109146109923
flags | SQLITE_OPEN_MAIN_DB);
109147109924
if( rc!=SQLITE_OK ){
109148109925
if( rc==SQLITE_IOERR_NOMEM ){
109149109926
rc = SQLITE_NOMEM;
109150109927
}
@@ -109233,10 +110010,11 @@
109233110010
sqlite3GlobalConfig.nLookaside);
109234110011
109235110012
sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
109236110013
109237110014
opendb_out:
110015
+ sqlite3_free(zOpen);
109238110016
if( db ){
109239110017
assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
109240110018
sqlite3_mutex_leave(db->mutex);
109241110019
}
109242110020
rc = sqlite3_errcode(db);
@@ -109264,11 +110042,11 @@
109264110042
const char *filename, /* Database filename (UTF-8) */
109265110043
sqlite3 **ppDb, /* OUT: SQLite db handle */
109266110044
int flags, /* Flags */
109267110045
const char *zVfs /* Name of VFS module to use */
109268110046
){
109269
- return openDatabase(filename, ppDb, flags, zVfs);
110047
+ return openDatabase(filename, ppDb, (unsigned int)flags, zVfs);
109270110048
}
109271110049
109272110050
#ifndef SQLITE_OMIT_UTF16
109273110051
/*
109274110052
** Open a new database handle.
@@ -109874,10 +110652,32 @@
109874110652
}
109875110653
va_end(ap);
109876110654
#endif /* SQLITE_OMIT_BUILTIN_TEST */
109877110655
return rc;
109878110656
}
110657
+
110658
+/*
110659
+** This is a utility routine, useful to VFS implementations, that checks
110660
+** to see if a database file was a URI that contained a specific query
110661
+** parameter, and if so obtains the value of the query parameter.
110662
+**
110663
+** The zFilename argument is the filename pointer passed into the xOpen()
110664
+** method of a VFS implementation. The zParam argument is the name of the
110665
+** query parameter we seek. This routine returns the value of the zParam
110666
+** parameter if it exists. If the parameter does not exist, this routine
110667
+** returns a NULL pointer.
110668
+*/
110669
+SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
110670
+ zFilename += sqlite3Strlen30(zFilename) + 1;
110671
+ while( zFilename[0] ){
110672
+ int x = strcmp(zFilename, zParam);
110673
+ zFilename += sqlite3Strlen30(zFilename) + 1;
110674
+ if( x==0 ) return zFilename;
110675
+ zFilename += sqlite3Strlen30(zFilename) + 1;
110676
+ }
110677
+ return 0;
110678
+}
109879110679
109880110680
/************** End of main.c ************************************************/
109881110681
/************** Begin file notify.c ******************************************/
109882110682
/*
109883110683
** 2009 March 3
@@ -110955,10 +111755,11 @@
110955111755
Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */
110956111756
sqlite3_int64 iPrevId; /* Previous id read from aDoclist */
110957111757
char *pNextId; /* Pointer into the body of aDoclist */
110958111758
char *aDoclist; /* List of docids for full-text queries */
110959111759
int nDoclist; /* Size of buffer at aDoclist */
111760
+ int desc; /* True to sort in descending order */
110960111761
int eEvalmode; /* An FTS3_EVAL_XX constant */
110961111762
int nRowAvg; /* Average size of database rows, in pages */
110962111763
110963111764
int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
110964111765
u32 *aMatchinfo; /* Information about most recent match */
@@ -111137,11 +111938,11 @@
111137111938
SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
111138111939
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
111139111940
SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
111140111941
SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
111141111942
111142
-SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Expr *, sqlite3_int64, int);
111943
+SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Cursor *, Fts3Expr *, sqlite3_int64, int);
111143111944
SQLITE_PRIVATE int sqlite3Fts3ExprLoadDoclist(Fts3Cursor *, Fts3Expr *);
111144111945
SQLITE_PRIVATE int sqlite3Fts3ExprLoadFtDoclist(Fts3Cursor *, Fts3Expr *, char **, int *);
111145111946
SQLITE_PRIVATE int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int);
111146111947
111147111948
/* fts3_tokenizer.c */
@@ -111164,10 +111965,11 @@
111164111965
char **, int, int, const char *, int, Fts3Expr **
111165111966
);
111166111967
SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
111167111968
#ifdef SQLITE_TEST
111168111969
SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
111970
+SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
111169111971
#endif
111170111972
111171111973
/* fts3_aux.c */
111172111974
SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
111173111975
@@ -111284,10 +112086,38 @@
111284112086
static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
111285112087
sqlite3_int64 iVal;
111286112088
*pp += sqlite3Fts3GetVarint(*pp, &iVal);
111287112089
*pVal += iVal;
111288112090
}
112091
+
112092
+/*
112093
+** When this function is called, *pp points to the first byte following a
112094
+** varint that is part of a doclist (or position-list, or any other list
112095
+** of varints). This function moves *pp to point to the start of that varint,
112096
+** and decrements the value stored in *pVal by the varint value.
112097
+**
112098
+** Argument pStart points to the first byte of the doclist that the
112099
+** varint is part of.
112100
+*/
112101
+static void fts3GetReverseDeltaVarint(
112102
+ char **pp,
112103
+ char *pStart,
112104
+ sqlite3_int64 *pVal
112105
+){
112106
+ sqlite3_int64 iVal;
112107
+ char *p = *pp;
112108
+
112109
+ /* Pointer p now points at the first byte past the varint we are
112110
+ ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
112111
+ ** clear on character p[-1]. */
112112
+ for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
112113
+ p++;
112114
+ *pp = p;
112115
+
112116
+ sqlite3Fts3GetVarint(p, &iVal);
112117
+ *pVal -= iVal;
112118
+}
111289112119
111290112120
/*
111291112121
** As long as *pp has not reached its end (pEnd), then do the same
111292112122
** as fts3GetDeltaVarint(): read a single varint and add it to *pVal.
111293112123
** But if we have reached the end of the varint, just set *pp=0 and
@@ -111389,10 +112219,12 @@
111389112219
if( *pRc==SQLITE_OK ){
111390112220
int i; /* Iterator variable */
111391112221
int rc; /* Return code */
111392112222
char *zSql; /* SQL statement passed to declare_vtab() */
111393112223
char *zCols; /* List of user defined columns */
112224
+
112225
+ sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
111394112226
111395112227
/* Create a list of user columns for the virtual table */
111396112228
zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]);
111397112229
for(i=1; zCols && i<p->nColumn; i++){
111398112230
zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]);
@@ -111958,10 +112790,26 @@
111958112790
111959112791
if( iCons>=0 ){
111960112792
pInfo->aConstraintUsage[iCons].argvIndex = 1;
111961112793
pInfo->aConstraintUsage[iCons].omit = 1;
111962112794
}
112795
+
112796
+ /* Regardless of the strategy selected, FTS can deliver rows in rowid (or
112797
+ ** docid) order. Both ascending and descending are possible.
112798
+ */
112799
+ if( pInfo->nOrderBy==1 ){
112800
+ struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0];
112801
+ if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){
112802
+ if( pOrder->desc ){
112803
+ pInfo->idxStr = "DESC";
112804
+ }else{
112805
+ pInfo->idxStr = "ASC";
112806
+ }
112807
+ }
112808
+ pInfo->orderByConsumed = 1;
112809
+ }
112810
+
111963112811
return SQLITE_OK;
111964112812
}
111965112813
111966112814
/*
111967112815
** Implementation of xOpen method.
@@ -112015,11 +112863,11 @@
112015112863
if( rc==SQLITE_OK ){
112016112864
/* If no row was found and no error has occured, then the %_content
112017112865
** table is missing a row that is present in the full-text index.
112018112866
** The data structures are corrupt.
112019112867
*/
112020
- rc = SQLITE_CORRUPT;
112868
+ rc = SQLITE_CORRUPT_VTAB;
112021112869
}
112022112870
pCsr->isEof = 1;
112023112871
if( pContext ){
112024112872
sqlite3_result_error_code(pContext, rc);
112025112873
}
@@ -112075,11 +112923,11 @@
112075112923
** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
112076112924
*/
112077112925
zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
112078112926
zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
112079112927
if( zCsr>zEnd ){
112080
- return SQLITE_CORRUPT;
112928
+ return SQLITE_CORRUPT_VTAB;
112081112929
}
112082112930
112083112931
while( zCsr<zEnd && (piFirst || piLast) ){
112084112932
int cmp; /* memcmp() result */
112085112933
int nSuffix; /* Size of term suffix */
@@ -112093,11 +112941,11 @@
112093112941
}
112094112942
isFirstTerm = 0;
112095112943
zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
112096112944
112097112945
if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
112098
- rc = SQLITE_CORRUPT;
112946
+ rc = SQLITE_CORRUPT_VTAB;
112099112947
goto finish_scan;
112100112948
}
112101112949
if( nPrefix+nSuffix>nAlloc ){
112102112950
char *zNew;
112103112951
nAlloc = (nPrefix+nSuffix) * 2;
@@ -113862,16 +114710,24 @@
113862114710
rc = sqlite3_reset(pCsr->pStmt);
113863114711
break;
113864114712
}
113865114713
pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
113866114714
}else{
113867
- if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){
113868
- pCsr->isEof = 1;
113869
- break;
114715
+ if( pCsr->desc==0 ){
114716
+ if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){
114717
+ pCsr->isEof = 1;
114718
+ break;
114719
+ }
114720
+ fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId);
114721
+ }else{
114722
+ fts3GetReverseDeltaVarint(&pCsr->pNextId,pCsr->aDoclist,&pCsr->iPrevId);
114723
+ if( pCsr->pNextId<=pCsr->aDoclist ){
114724
+ pCsr->isEof = 1;
114725
+ break;
114726
+ }
113870114727
}
113871114728
sqlite3_reset(pCsr->pStmt);
113872
- fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId);
113873114729
pCsr->isRequireSeek = 1;
113874114730
pCsr->isMatchinfoNeeded = 1;
113875114731
}
113876114732
}while( SQLITE_OK==(rc = fts3EvalDeferred(pCsr, &res)) && res==0 );
113877114733
@@ -113900,12 +114756,12 @@
113900114756
const char *idxStr, /* Unused */
113901114757
int nVal, /* Number of elements in apVal */
113902114758
sqlite3_value **apVal /* Arguments for the indexing scheme */
113903114759
){
113904114760
const char *azSql[] = {
113905
- "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */
113906
- "SELECT %s FROM %Q.'%q_content' AS x ", /* full-scan */
114761
+ "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */
114762
+ "SELECT %s FROM %Q.'%q_content' AS x ORDER BY docid %s", /* full-scan */
113907114763
};
113908114764
int rc; /* Return code */
113909114765
char *zSql; /* SQL statement used to access %_content */
113910114766
Fts3Table *p = (Fts3Table *)pCursor->pVtab;
113911114767
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
@@ -113957,11 +114813,13 @@
113957114813
** statement loops through all rows of the %_content table. For a
113958114814
** full-text query or docid lookup, the statement retrieves a single
113959114815
** row by docid.
113960114816
*/
113961114817
zSql = (char *)azSql[idxNum==FTS3_FULLSCAN_SEARCH];
113962
- zSql = sqlite3_mprintf(zSql, p->zReadExprlist, p->zDb, p->zName);
114818
+ zSql = sqlite3_mprintf(
114819
+ zSql, p->zReadExprlist, p->zDb, p->zName, (idxStr ? idxStr : "ASC")
114820
+ );
113963114821
if( !zSql ){
113964114822
rc = SQLITE_NOMEM;
113965114823
}else{
113966114824
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
113967114825
sqlite3_free(zSql);
@@ -113969,11 +114827,26 @@
113969114827
if( rc==SQLITE_OK && idxNum==FTS3_DOCID_SEARCH ){
113970114828
rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]);
113971114829
}
113972114830
pCsr->eSearch = (i16)idxNum;
113973114831
114832
+ assert( pCsr->desc==0 );
113974114833
if( rc!=SQLITE_OK ) return rc;
114834
+ if( rc==SQLITE_OK && pCsr->nDoclist>0 && idxStr && idxStr[0]=='D' ){
114835
+ sqlite3_int64 iDocid = 0;
114836
+ char *csr = pCsr->aDoclist;
114837
+ while( csr<&pCsr->aDoclist[pCsr->nDoclist] ){
114838
+ fts3GetDeltaVarint(&csr, &iDocid);
114839
+ }
114840
+ pCsr->pNextId = csr;
114841
+ pCsr->iPrevId = iDocid;
114842
+ pCsr->desc = 1;
114843
+ pCsr->isRequireSeek = 1;
114844
+ pCsr->isMatchinfoNeeded = 1;
114845
+ pCsr->eEvalmode = FTS3_EVAL_NEXT;
114846
+ return SQLITE_OK;
114847
+ }
113975114848
return fts3NextMethod(pCursor);
113976114849
}
113977114850
113978114851
/*
113979114852
** This is the xEof method of the virtual table. SQLite calls this
@@ -114121,17 +114994,37 @@
114121114994
pCsr->eEvalmode = FTS3_EVAL_MATCHINFO;
114122114995
rc = fts3EvalExpr(pCsr, pExpr, paDoclist, pnDoclist, 1);
114123114996
pCsr->eEvalmode = FTS3_EVAL_NEXT;
114124114997
return rc;
114125114998
}
114999
+
115000
+
115001
+/*
115002
+** When called, *ppPoslist must point to the byte immediately following the
115003
+** end of a position-list. i.e. ( (*ppPoslist)[-1]==POS_END ). This function
115004
+** moves *ppPoslist so that it instead points to the first byte of the
115005
+** same position list.
115006
+*/
115007
+static void fts3ReversePoslist(char *pStart, char **ppPoslist){
115008
+ char *p = &(*ppPoslist)[-3];
115009
+ char c = p[1];
115010
+ while( p>pStart && (*p & 0x80) | c ){
115011
+ c = *p--;
115012
+ }
115013
+ if( p>pStart ){ p = &p[2]; }
115014
+ while( *p++&0x80 );
115015
+ *ppPoslist = p;
115016
+}
115017
+
114126115018
114127115019
/*
114128115020
** After ExprLoadDoclist() (see above) has been called, this function is
114129115021
** used to iterate/search through the position lists that make up the doclist
114130115022
** stored in pExpr->aDoclist.
114131115023
*/
114132115024
SQLITE_PRIVATE char *sqlite3Fts3FindPositions(
115025
+ Fts3Cursor *pCursor, /* Associate FTS3 cursor */
114133115026
Fts3Expr *pExpr, /* Access this expressions doclist */
114134115027
sqlite3_int64 iDocid, /* Docid associated with requested pos-list */
114135115028
int iCol /* Column of requested pos-list */
114136115029
){
114137115030
assert( pExpr->isLoaded );
@@ -114138,23 +115031,39 @@
114138115031
if( pExpr->aDoclist ){
114139115032
char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
114140115033
char *pCsr;
114141115034
114142115035
if( pExpr->pCurrent==0 ){
114143
- pExpr->pCurrent = pExpr->aDoclist;
114144
- pExpr->iCurrent = 0;
114145
- pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent);
115036
+ if( pCursor->desc==0 ){
115037
+ pExpr->pCurrent = pExpr->aDoclist;
115038
+ pExpr->iCurrent = 0;
115039
+ fts3GetDeltaVarint(&pExpr->pCurrent, &pExpr->iCurrent);
115040
+ }else{
115041
+ pCsr = pExpr->aDoclist;
115042
+ while( pCsr<pEnd ){
115043
+ fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
115044
+ fts3PoslistCopy(0, &pCsr);
115045
+ }
115046
+ fts3ReversePoslist(pExpr->aDoclist, &pCsr);
115047
+ pExpr->pCurrent = pCsr;
115048
+ }
114146115049
}
114147115050
pCsr = pExpr->pCurrent;
114148115051
assert( pCsr );
114149115052
114150
- while( pCsr<pEnd ){
114151
- if( pExpr->iCurrent<iDocid ){
115053
+ while( (pCursor->desc==0 && pCsr<pEnd)
115054
+ || (pCursor->desc && pCsr>pExpr->aDoclist)
115055
+ ){
115056
+ if( pCursor->desc==0 && pExpr->iCurrent<iDocid ){
114152115057
fts3PoslistCopy(0, &pCsr);
114153115058
if( pCsr<pEnd ){
114154115059
fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
114155115060
}
115061
+ pExpr->pCurrent = pCsr;
115062
+ }else if( pCursor->desc && pExpr->iCurrent>iDocid ){
115063
+ fts3GetReverseDeltaVarint(&pCsr, pExpr->aDoclist, &pExpr->iCurrent);
115064
+ fts3ReversePoslist(pExpr->aDoclist, &pCsr);
114156115065
pExpr->pCurrent = pCsr;
114157115066
}else{
114158115067
if( pExpr->iCurrent==iDocid ){
114159115068
int iThis = 0;
114160115069
if( iCol<0 ){
@@ -114407,13 +115316,24 @@
114407115316
"ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';",
114408115317
p->zDb, p->zName, zName
114409115318
);
114410115319
return rc;
114411115320
}
115321
+
115322
+static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
115323
+ return sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab);
115324
+}
115325
+static int fts3ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
115326
+ return SQLITE_OK;
115327
+}
115328
+static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
115329
+ sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab);
115330
+ return SQLITE_OK;
115331
+}
114412115332
114413115333
static const sqlite3_module fts3Module = {
114414
- /* iVersion */ 0,
115334
+ /* iVersion */ 2,
114415115335
/* xCreate */ fts3CreateMethod,
114416115336
/* xConnect */ fts3ConnectMethod,
114417115337
/* xBestIndex */ fts3BestIndexMethod,
114418115338
/* xDisconnect */ fts3DisconnectMethod,
114419115339
/* xDestroy */ fts3DestroyMethod,
@@ -114429,10 +115349,13 @@
114429115349
/* xSync */ fts3SyncMethod,
114430115350
/* xCommit */ fts3CommitMethod,
114431115351
/* xRollback */ fts3RollbackMethod,
114432115352
/* xFindFunction */ fts3FindFunctionMethod,
114433115353
/* xRename */ fts3RenameMethod,
115354
+ /* xSavepoint */ fts3SavepointMethod,
115355
+ /* xRelease */ fts3ReleaseMethod,
115356
+ /* xRollbackTo */ fts3RollbackToMethod,
114434115357
};
114435115358
114436115359
/*
114437115360
** This function is registered as the module destructor (called when an
114438115361
** FTS3 enabled database connection is closed). It frees the memory
@@ -114474,10 +115397,15 @@
114474115397
114475115398
#ifdef SQLITE_ENABLE_ICU
114476115399
const sqlite3_tokenizer_module *pIcu = 0;
114477115400
sqlite3Fts3IcuTokenizerModule(&pIcu);
114478115401
#endif
115402
+
115403
+#ifdef SQLITE_TEST
115404
+ rc = sqlite3Fts3InitTerm(db);
115405
+ if( rc!=SQLITE_OK ) return rc;
115406
+#endif
114479115407
114480115408
rc = sqlite3Fts3InitAux(db);
114481115409
if( rc!=SQLITE_OK ) return rc;
114482115410
114483115411
sqlite3Fts3SimpleTokenizerModule(&pSimple);
@@ -117995,11 +118923,11 @@
117995118923
sqlite3_bind_int64(pStmt, 1, iDocid);
117996118924
}
117997118925
rc = sqlite3_step(pStmt);
117998118926
if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
117999118927
rc = sqlite3_reset(pStmt);
118000
- if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT;
118928
+ if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB;
118001118929
pStmt = 0;
118002118930
}else{
118003118931
rc = SQLITE_OK;
118004118932
}
118005118933
}
@@ -118451,18 +119379,18 @@
118451119379
** full-text index.
118452119380
*/
118453119381
static void fts3DeleteTerms(
118454119382
int *pRC, /* Result code */
118455119383
Fts3Table *p, /* The FTS table to delete from */
118456
- sqlite3_value **apVal, /* apVal[] contains the docid to be deleted */
119384
+ sqlite3_value *pRowid, /* The docid to be deleted */
118457119385
u32 *aSz /* Sizes of deleted document written here */
118458119386
){
118459119387
int rc;
118460119388
sqlite3_stmt *pSelect;
118461119389
118462119390
if( *pRC ) return;
118463
- rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, apVal);
119391
+ rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid);
118464119392
if( rc==SQLITE_OK ){
118465119393
if( SQLITE_ROW==sqlite3_step(pSelect) ){
118466119394
int i;
118467119395
for(i=1; i<=p->nColumn; i++){
118468119396
const char *zText = (const char *)sqlite3_column_text(pSelect, i);
@@ -118676,11 +119604,11 @@
118676119604
pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
118677119605
pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
118678119606
if( nPrefix<0 || nSuffix<=0
118679119607
|| &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
118680119608
){
118681
- return SQLITE_CORRUPT;
119609
+ return SQLITE_CORRUPT_VTAB;
118682119610
}
118683119611
118684119612
if( nPrefix+nSuffix>pReader->nTermAlloc ){
118685119613
int nNew = (nPrefix+nSuffix)*2;
118686119614
char *zNew = sqlite3_realloc(pReader->zTerm, nNew);
@@ -118702,11 +119630,11 @@
118702119630
** of these statements is untrue, then the data structure is corrupt.
118703119631
*/
118704119632
if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode]
118705119633
|| pReader->aDoclist[pReader->nDoclist-1]
118706119634
){
118707
- return SQLITE_CORRUPT;
119635
+ return SQLITE_CORRUPT_VTAB;
118708119636
}
118709119637
return SQLITE_OK;
118710119638
}
118711119639
118712119640
/*
@@ -118827,11 +119755,11 @@
118827119755
while( a<pEnd ){
118828119756
a += sqlite3Fts3GetVarint(a, &nByte);
118829119757
}
118830119758
if( nDoc==0 || nByte==0 ){
118831119759
sqlite3_reset(pStmt);
118832
- return SQLITE_CORRUPT;
119760
+ return SQLITE_CORRUPT_VTAB;
118833119761
}
118834119762
118835119763
pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
118836119764
assert( pCsr->nRowAvg>0 );
118837119765
rc = sqlite3_reset(pStmt);
@@ -119598,20 +120526,20 @@
119598120526
119599120527
/*
119600120528
** The first value in the apVal[] array is assumed to contain an integer.
119601120529
** This function tests if there exist any documents with docid values that
119602120530
** are different from that integer. i.e. if deleting the document with docid
119603
-** apVal[0] would mean the FTS3 table were empty.
120531
+** pRowid would mean the FTS3 table were empty.
119604120532
**
119605120533
** If successful, *pisEmpty is set to true if the table is empty except for
119606
-** document apVal[0], or false otherwise, and SQLITE_OK is returned. If an
120534
+** document pRowid, or false otherwise, and SQLITE_OK is returned. If an
119607120535
** error occurs, an SQLite error code is returned.
119608120536
*/
119609
-static int fts3IsEmpty(Fts3Table *p, sqlite3_value **apVal, int *pisEmpty){
120537
+static int fts3IsEmpty(Fts3Table *p, sqlite3_value *pRowid, int *pisEmpty){
119610120538
sqlite3_stmt *pStmt;
119611120539
int rc;
119612
- rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, apVal);
120540
+ rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, &pRowid);
119613120541
if( rc==SQLITE_OK ){
119614120542
if( SQLITE_ROW==sqlite3_step(pStmt) ){
119615120543
*pisEmpty = sqlite3_column_int(pStmt, 0);
119616120544
}
119617120545
rc = sqlite3_reset(pStmt);
@@ -120331,10 +121259,44 @@
120331121259
pToken->pDeferred = pDeferred;
120332121260
120333121261
return SQLITE_OK;
120334121262
}
120335121263
121264
+/*
121265
+** SQLite value pRowid contains the rowid of a row that may or may not be
121266
+** present in the FTS3 table. If it is, delete it and adjust the contents
121267
+** of subsiduary data structures accordingly.
121268
+*/
121269
+static int fts3DeleteByRowid(
121270
+ Fts3Table *p,
121271
+ sqlite3_value *pRowid,
121272
+ int *pnDoc,
121273
+ u32 *aSzDel
121274
+){
121275
+ int isEmpty = 0;
121276
+ int rc = fts3IsEmpty(p, pRowid, &isEmpty);
121277
+ if( rc==SQLITE_OK ){
121278
+ if( isEmpty ){
121279
+ /* Deleting this row means the whole table is empty. In this case
121280
+ ** delete the contents of all three tables and throw away any
121281
+ ** data in the pendingTerms hash table. */
121282
+ rc = fts3DeleteAll(p);
121283
+ *pnDoc = *pnDoc - 1;
121284
+ }else{
121285
+ sqlite3_int64 iRemove = sqlite3_value_int64(pRowid);
121286
+ rc = fts3PendingTermsDocid(p, iRemove);
121287
+ fts3DeleteTerms(&rc, p, pRowid, aSzDel);
121288
+ fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid);
121289
+ if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1;
121290
+ if( p->bHasDocsize ){
121291
+ fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, &pRowid);
121292
+ }
121293
+ }
121294
+ }
121295
+
121296
+ return rc;
121297
+}
120336121298
120337121299
/*
120338121300
** This function does the work for the xUpdate method of FTS3 virtual
120339121301
** tables.
120340121302
*/
@@ -120349,50 +121311,95 @@
120349121311
int isRemove = 0; /* True for an UPDATE or DELETE */
120350121312
sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */
120351121313
u32 *aSzIns; /* Sizes of inserted documents */
120352121314
u32 *aSzDel; /* Sizes of deleted documents */
120353121315
int nChng = 0; /* Net change in number of documents */
121316
+ int bInsertDone = 0;
120354121317
120355121318
assert( p->pSegments==0 );
121319
+
121320
+ /* Check for a "special" INSERT operation. One of the form:
121321
+ **
121322
+ ** INSERT INTO xyz(xyz) VALUES('command');
121323
+ */
121324
+ if( nArg>1
121325
+ && sqlite3_value_type(apVal[0])==SQLITE_NULL
121326
+ && sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL
121327
+ ){
121328
+ return fts3SpecialInsert(p, apVal[p->nColumn+2]);
121329
+ }
120356121330
120357121331
/* Allocate space to hold the change in document sizes */
120358121332
aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 );
120359121333
if( aSzIns==0 ) return SQLITE_NOMEM;
120360121334
aSzDel = &aSzIns[p->nColumn+1];
120361121335
memset(aSzIns, 0, sizeof(aSzIns[0])*(p->nColumn+1)*2);
121336
+
121337
+ /* If this is an INSERT operation, or an UPDATE that modifies the rowid
121338
+ ** value, then this operation requires constraint handling.
121339
+ **
121340
+ ** If the on-conflict mode is REPLACE, this means that the existing row
121341
+ ** should be deleted from the database before inserting the new row. Or,
121342
+ ** if the on-conflict mode is other than REPLACE, then this method must
121343
+ ** detect the conflict and return SQLITE_CONSTRAINT before beginning to
121344
+ ** modify the database file.
121345
+ */
121346
+ if( nArg>1 ){
121347
+ /* Find the value object that holds the new rowid value. */
121348
+ sqlite3_value *pNewRowid = apVal[3+p->nColumn];
121349
+ if( sqlite3_value_type(pNewRowid)==SQLITE_NULL ){
121350
+ pNewRowid = apVal[1];
121351
+ }
121352
+
121353
+ if( sqlite3_value_type(pNewRowid)!=SQLITE_NULL && (
121354
+ sqlite3_value_type(apVal[0])==SQLITE_NULL
121355
+ || sqlite3_value_int64(apVal[0])!=sqlite3_value_int64(pNewRowid)
121356
+ )){
121357
+ /* The new rowid is not NULL (in this case the rowid will be
121358
+ ** automatically assigned and there is no chance of a conflict), and
121359
+ ** the statement is either an INSERT or an UPDATE that modifies the
121360
+ ** rowid column. So if the conflict mode is REPLACE, then delete any
121361
+ ** existing row with rowid=pNewRowid.
121362
+ **
121363
+ ** Or, if the conflict mode is not REPLACE, insert the new record into
121364
+ ** the %_content table. If we hit the duplicate rowid constraint (or any
121365
+ ** other error) while doing so, return immediately.
121366
+ **
121367
+ ** This branch may also run if pNewRowid contains a value that cannot
121368
+ ** be losslessly converted to an integer. In this case, the eventual
121369
+ ** call to fts3InsertData() (either just below or further on in this
121370
+ ** function) will return SQLITE_MISMATCH. If fts3DeleteByRowid is
121371
+ ** invoked, it will delete zero rows (since no row will have
121372
+ ** docid=$pNewRowid if $pNewRowid is not an integer value).
121373
+ */
121374
+ if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){
121375
+ rc = fts3DeleteByRowid(p, pNewRowid, &nChng, aSzDel);
121376
+ }else{
121377
+ rc = fts3InsertData(p, apVal, pRowid);
121378
+ bInsertDone = 1;
121379
+ }
121380
+ }
121381
+ }
121382
+ if( rc!=SQLITE_OK ){
121383
+ sqlite3_free(aSzIns);
121384
+ return rc;
121385
+ }
120362121386
120363121387
/* If this is a DELETE or UPDATE operation, remove the old record. */
120364121388
if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
120365
- int isEmpty = 0;
120366
- rc = fts3IsEmpty(p, apVal, &isEmpty);
120367
- if( rc==SQLITE_OK ){
120368
- if( isEmpty ){
120369
- /* Deleting this row means the whole table is empty. In this case
120370
- ** delete the contents of all three tables and throw away any
120371
- ** data in the pendingTerms hash table.
120372
- */
120373
- rc = fts3DeleteAll(p);
120374
- }else{
120375
- isRemove = 1;
120376
- iRemove = sqlite3_value_int64(apVal[0]);
120377
- rc = fts3PendingTermsDocid(p, iRemove);
120378
- fts3DeleteTerms(&rc, p, apVal, aSzDel);
120379
- fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, apVal);
120380
- if( p->bHasDocsize ){
120381
- fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, apVal);
120382
- }
120383
- nChng--;
120384
- }
120385
- }
120386
- }else if( sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL ){
120387
- sqlite3_free(aSzIns);
120388
- return fts3SpecialInsert(p, apVal[p->nColumn+2]);
121389
+ assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
121390
+ rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
121391
+ isRemove = 1;
121392
+ iRemove = sqlite3_value_int64(apVal[0]);
120389121393
}
120390121394
120391121395
/* If this is an INSERT or UPDATE operation, insert the new record. */
120392121396
if( nArg>1 && rc==SQLITE_OK ){
120393
- rc = fts3InsertData(p, apVal, pRowid);
121397
+ if( bInsertDone==0 ){
121398
+ rc = fts3InsertData(p, apVal, pRowid);
121399
+ if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB;
121400
+ }
120394121401
if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){
120395121402
rc = fts3PendingTermsDocid(p, *pRowid);
120396121403
}
120397121404
if( rc==SQLITE_OK ){
120398121405
rc = fts3InsertTerms(p, apVal, aSzIns);
@@ -120852,11 +121859,11 @@
120852121859
SnippetPhrase *pPhrase = &p->aPhrase[iPhrase];
120853121860
char *pCsr;
120854121861
120855121862
pPhrase->nToken = pExpr->pPhrase->nToken;
120856121863
120857
- pCsr = sqlite3Fts3FindPositions(pExpr, p->pCsr->iPrevId, p->iCol);
121864
+ pCsr = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->pCsr->iPrevId, p->iCol);
120858121865
if( pCsr ){
120859121866
int iFirst = 0;
120860121867
pPhrase->pList = pCsr;
120861121868
fts3GetDeltaPosition(&pCsr, &iFirst);
120862121869
pPhrase->pHead = pCsr;
@@ -121325,11 +122332,11 @@
121325122332
for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0;
121326122333
121327122334
if( pExpr->aDoclist ){
121328122335
char *pCsr;
121329122336
121330
- pCsr = sqlite3Fts3FindPositions(pExpr, p->pCursor->iPrevId, -1);
122337
+ pCsr = sqlite3Fts3FindPositions(p->pCursor, pExpr, p->pCursor->iPrevId, -1);
121331122338
if( pCsr ){
121332122339
fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0);
121333122340
}
121334122341
}
121335122342
@@ -121397,11 +122404,11 @@
121397122404
pStmt = *ppStmt;
121398122405
assert( sqlite3_data_count(pStmt)==1 );
121399122406
121400122407
a = sqlite3_column_blob(pStmt, 0);
121401122408
a += sqlite3Fts3GetVarint(a, &nDoc);
121402
- if( nDoc==0 ) return SQLITE_CORRUPT;
122409
+ if( nDoc==0 ) return SQLITE_CORRUPT_VTAB;
121403122410
*pnDoc = (u32)nDoc;
121404122411
121405122412
if( paLen ) *paLen = a;
121406122413
return SQLITE_OK;
121407122414
}
@@ -121492,11 +122499,11 @@
121492122499
(void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
121493122500
for(i=0; i<pInfo->nPhrase; i++){
121494122501
LcsIterator *pIter = &aIter[i];
121495122502
nToken -= pIter->pExpr->pPhrase->nToken;
121496122503
pIter->iPosOffset = nToken;
121497
- pIter->pRead = sqlite3Fts3FindPositions(pIter->pExpr, pCsr->iPrevId, -1);
122504
+ pIter->pRead = sqlite3Fts3FindPositions(pCsr,pIter->pExpr,pCsr->iPrevId,-1);
121498122505
if( pIter->pRead ){
121499122506
pIter->iPos = pIter->iPosOffset;
121500122507
fts3LcsIteratorAdvance(&aIter[i]);
121501122508
}else{
121502122509
pIter->iCol = LCS_ITERATOR_FINISHED;
@@ -121845,10 +122852,11 @@
121845122852
int iPos; /* Position just read from pList */
121846122853
int iOff; /* Offset of this term from read positions */
121847122854
};
121848122855
121849122856
struct TermOffsetCtx {
122857
+ Fts3Cursor *pCsr;
121850122858
int iCol; /* Column of table to populate aTerm for */
121851122859
int iTerm;
121852122860
sqlite3_int64 iDocid;
121853122861
TermOffset *aTerm;
121854122862
};
@@ -121862,11 +122870,11 @@
121862122870
int iTerm; /* For looping through nTerm phrase terms */
121863122871
char *pList; /* Pointer to position list for phrase */
121864122872
int iPos = 0; /* First position in position-list */
121865122873
121866122874
UNUSED_PARAMETER(iPhrase);
121867
- pList = sqlite3Fts3FindPositions(pExpr, p->iDocid, p->iCol);
122875
+ pList = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->iDocid, p->iCol);
121868122876
nTerm = pExpr->pPhrase->nToken;
121869122877
if( pList ){
121870122878
fts3GetDeltaPosition(&pList, &iPos);
121871122879
assert( iPos>=0 );
121872122880
}
@@ -121915,10 +122923,11 @@
121915122923
if( 0==sCtx.aTerm ){
121916122924
rc = SQLITE_NOMEM;
121917122925
goto offsets_out;
121918122926
}
121919122927
sCtx.iDocid = pCsr->iPrevId;
122928
+ sCtx.pCsr = pCsr;
121920122929
121921122930
/* Loop through the table columns, appending offset information to
121922122931
** string-buffer res for each column.
121923122932
*/
121924122933
for(iCol=0; iCol<pTab->nColumn; iCol++){
@@ -121990,11 +122999,11 @@
121990122999
sqlite3_snprintf(sizeof(aBuffer), aBuffer,
121991123000
"%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
121992123001
);
121993123002
rc = fts3StringAppend(&res, aBuffer, -1);
121994123003
}else if( rc==SQLITE_DONE ){
121995
- rc = SQLITE_CORRUPT;
123004
+ rc = SQLITE_CORRUPT_VTAB;
121996123005
}
121997123006
}
121998123007
}
121999123008
if( rc==SQLITE_DONE ){
122000123009
rc = SQLITE_OK;
@@ -122578,29 +123587,29 @@
122578123587
** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
122579123588
*/
122580123589
if( pNode && iNode==1 ){
122581123590
pRtree->iDepth = readInt16(pNode->zData);
122582123591
if( pRtree->iDepth>RTREE_MAX_DEPTH ){
122583
- rc = SQLITE_CORRUPT;
123592
+ rc = SQLITE_CORRUPT_VTAB;
122584123593
}
122585123594
}
122586123595
122587123596
/* If no error has occurred so far, check if the "number of entries"
122588123597
** field on the node is too large. If so, set the return code to
122589
- ** SQLITE_CORRUPT.
123598
+ ** SQLITE_CORRUPT_VTAB.
122590123599
*/
122591123600
if( pNode && rc==SQLITE_OK ){
122592123601
if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
122593
- rc = SQLITE_CORRUPT;
123602
+ rc = SQLITE_CORRUPT_VTAB;
122594123603
}
122595123604
}
122596123605
122597123606
if( rc==SQLITE_OK ){
122598123607
if( pNode!=0 ){
122599123608
nodeHashInsert(pRtree, pNode);
122600123609
}else{
122601
- rc = SQLITE_CORRUPT;
123610
+ rc = SQLITE_CORRUPT_VTAB;
122602123611
}
122603123612
*ppNode = pNode;
122604123613
}else{
122605123614
sqlite3_free(pNode);
122606123615
*ppNode = 0;
@@ -123123,11 +124132,11 @@
123123124132
if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
123124124133
*piIndex = ii;
123125124134
return SQLITE_OK;
123126124135
}
123127124136
}
123128
- return SQLITE_CORRUPT;
124137
+ return SQLITE_CORRUPT_VTAB;
123129124138
}
123130124139
123131124140
/*
123132124141
** Return the index of the cell containing a pointer to node pNode
123133124142
** in its parent. If pNode is the root node, return -1.
@@ -123718,11 +124727,11 @@
123718124727
RtreeNode *pParent = p->pParent;
123719124728
RtreeCell cell;
123720124729
int iCell;
123721124730
123722124731
if( nodeParentIndex(pRtree, p, &iCell) ){
123723
- return SQLITE_CORRUPT;
124732
+ return SQLITE_CORRUPT_VTAB;
123724124733
}
123725124734
123726124735
nodeGetCell(pRtree, pParent, iCell, &cell);
123727124736
if( !cellContains(pRtree, &cell, pCell) ){
123728124737
cellUnion(pRtree, &cell, pCell);
@@ -124390,11 +125399,11 @@
124390125399
rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
124391125400
}
124392125401
}
124393125402
rc = sqlite3_reset(pRtree->pReadParent);
124394125403
if( rc==SQLITE_OK ) rc = rc2;
124395
- if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT;
125404
+ if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT_VTAB;
124396125405
pChild = pChild->pParent;
124397125406
}
124398125407
return rc;
124399125408
}
124400125409
@@ -124685,10 +125694,94 @@
124685125694
sqlite3_step(pRtree->pWriteRowid);
124686125695
rc = sqlite3_reset(pRtree->pWriteRowid);
124687125696
*piRowid = sqlite3_last_insert_rowid(pRtree->db);
124688125697
return rc;
124689125698
}
125699
+
125700
+/*
125701
+** Remove the entry with rowid=iDelete from the r-tree structure.
125702
+*/
125703
+static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
125704
+ int rc; /* Return code */
125705
+ RtreeNode *pLeaf; /* Leaf node containing record iDelete */
125706
+ int iCell; /* Index of iDelete cell in pLeaf */
125707
+ RtreeNode *pRoot; /* Root node of rtree structure */
125708
+
125709
+
125710
+ /* Obtain a reference to the root node to initialise Rtree.iDepth */
125711
+ rc = nodeAcquire(pRtree, 1, 0, &pRoot);
125712
+
125713
+ /* Obtain a reference to the leaf node that contains the entry
125714
+ ** about to be deleted.
125715
+ */
125716
+ if( rc==SQLITE_OK ){
125717
+ rc = findLeafNode(pRtree, iDelete, &pLeaf);
125718
+ }
125719
+
125720
+ /* Delete the cell in question from the leaf node. */
125721
+ if( rc==SQLITE_OK ){
125722
+ int rc2;
125723
+ rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
125724
+ if( rc==SQLITE_OK ){
125725
+ rc = deleteCell(pRtree, pLeaf, iCell, 0);
125726
+ }
125727
+ rc2 = nodeRelease(pRtree, pLeaf);
125728
+ if( rc==SQLITE_OK ){
125729
+ rc = rc2;
125730
+ }
125731
+ }
125732
+
125733
+ /* Delete the corresponding entry in the <rtree>_rowid table. */
125734
+ if( rc==SQLITE_OK ){
125735
+ sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete);
125736
+ sqlite3_step(pRtree->pDeleteRowid);
125737
+ rc = sqlite3_reset(pRtree->pDeleteRowid);
125738
+ }
125739
+
125740
+ /* Check if the root node now has exactly one child. If so, remove
125741
+ ** it, schedule the contents of the child for reinsertion and
125742
+ ** reduce the tree height by one.
125743
+ **
125744
+ ** This is equivalent to copying the contents of the child into
125745
+ ** the root node (the operation that Gutman's paper says to perform
125746
+ ** in this scenario).
125747
+ */
125748
+ if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
125749
+ int rc2;
125750
+ RtreeNode *pChild;
125751
+ i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
125752
+ rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
125753
+ if( rc==SQLITE_OK ){
125754
+ rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
125755
+ }
125756
+ rc2 = nodeRelease(pRtree, pChild);
125757
+ if( rc==SQLITE_OK ) rc = rc2;
125758
+ if( rc==SQLITE_OK ){
125759
+ pRtree->iDepth--;
125760
+ writeInt16(pRoot->zData, pRtree->iDepth);
125761
+ pRoot->isDirty = 1;
125762
+ }
125763
+ }
125764
+
125765
+ /* Re-insert the contents of any underfull nodes removed from the tree. */
125766
+ for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
125767
+ if( rc==SQLITE_OK ){
125768
+ rc = reinsertNodeContent(pRtree, pLeaf);
125769
+ }
125770
+ pRtree->pDeleted = pLeaf->pNext;
125771
+ sqlite3_free(pLeaf);
125772
+ }
125773
+
125774
+ /* Release the reference to the root node. */
125775
+ if( rc==SQLITE_OK ){
125776
+ rc = nodeRelease(pRtree, pRoot);
125777
+ }else{
125778
+ nodeRelease(pRtree, pRoot);
125779
+ }
125780
+
125781
+ return rc;
125782
+}
124690125783
124691125784
/*
124692125785
** The xUpdate method for rtree module virtual tables.
124693125786
*/
124694125787
static int rtreeUpdate(
@@ -124697,107 +125790,29 @@
124697125790
sqlite3_value **azData,
124698125791
sqlite_int64 *pRowid
124699125792
){
124700125793
Rtree *pRtree = (Rtree *)pVtab;
124701125794
int rc = SQLITE_OK;
125795
+ RtreeCell cell; /* New cell to insert if nData>1 */
125796
+ int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
124702125797
124703125798
rtreeReference(pRtree);
124704
-
124705125799
assert(nData>=1);
124706125800
124707
- /* If azData[0] is not an SQL NULL value, it is the rowid of a
124708
- ** record to delete from the r-tree table. The following block does
124709
- ** just that.
124710
- */
124711
- if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){
124712
- i64 iDelete; /* The rowid to delete */
124713
- RtreeNode *pLeaf; /* Leaf node containing record iDelete */
124714
- int iCell; /* Index of iDelete cell in pLeaf */
124715
- RtreeNode *pRoot;
124716
-
124717
- /* Obtain a reference to the root node to initialise Rtree.iDepth */
124718
- rc = nodeAcquire(pRtree, 1, 0, &pRoot);
124719
-
124720
- /* Obtain a reference to the leaf node that contains the entry
124721
- ** about to be deleted.
124722
- */
124723
- if( rc==SQLITE_OK ){
124724
- iDelete = sqlite3_value_int64(azData[0]);
124725
- rc = findLeafNode(pRtree, iDelete, &pLeaf);
124726
- }
124727
-
124728
- /* Delete the cell in question from the leaf node. */
124729
- if( rc==SQLITE_OK ){
124730
- int rc2;
124731
- rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
124732
- if( rc==SQLITE_OK ){
124733
- rc = deleteCell(pRtree, pLeaf, iCell, 0);
124734
- }
124735
- rc2 = nodeRelease(pRtree, pLeaf);
124736
- if( rc==SQLITE_OK ){
124737
- rc = rc2;
124738
- }
124739
- }
124740
-
124741
- /* Delete the corresponding entry in the <rtree>_rowid table. */
124742
- if( rc==SQLITE_OK ){
124743
- sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete);
124744
- sqlite3_step(pRtree->pDeleteRowid);
124745
- rc = sqlite3_reset(pRtree->pDeleteRowid);
124746
- }
124747
-
124748
- /* Check if the root node now has exactly one child. If so, remove
124749
- ** it, schedule the contents of the child for reinsertion and
124750
- ** reduce the tree height by one.
124751
- **
124752
- ** This is equivalent to copying the contents of the child into
124753
- ** the root node (the operation that Gutman's paper says to perform
124754
- ** in this scenario).
124755
- */
124756
- if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
124757
- int rc2;
124758
- RtreeNode *pChild;
124759
- i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
124760
- rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
124761
- if( rc==SQLITE_OK ){
124762
- rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
124763
- }
124764
- rc2 = nodeRelease(pRtree, pChild);
124765
- if( rc==SQLITE_OK ) rc = rc2;
124766
- if( rc==SQLITE_OK ){
124767
- pRtree->iDepth--;
124768
- writeInt16(pRoot->zData, pRtree->iDepth);
124769
- pRoot->isDirty = 1;
124770
- }
124771
- }
124772
-
124773
- /* Re-insert the contents of any underfull nodes removed from the tree. */
124774
- for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
124775
- if( rc==SQLITE_OK ){
124776
- rc = reinsertNodeContent(pRtree, pLeaf);
124777
- }
124778
- pRtree->pDeleted = pLeaf->pNext;
124779
- sqlite3_free(pLeaf);
124780
- }
124781
-
124782
- /* Release the reference to the root node. */
124783
- if( rc==SQLITE_OK ){
124784
- rc = nodeRelease(pRtree, pRoot);
124785
- }else{
124786
- nodeRelease(pRtree, pRoot);
124787
- }
124788
- }
124789
-
124790
- /* If the azData[] array contains more than one element, elements
124791
- ** (azData[2]..azData[argc-1]) contain a new record to insert into
124792
- ** the r-tree structure.
124793
- */
124794
- if( rc==SQLITE_OK && nData>1 ){
124795
- /* Insert a new record into the r-tree */
124796
- RtreeCell cell;
124797
- int ii;
124798
- RtreeNode *pLeaf;
125801
+ /* Constraint handling. A write operation on an r-tree table may return
125802
+ ** SQLITE_CONSTRAINT for two reasons:
125803
+ **
125804
+ ** 1. A duplicate rowid value, or
125805
+ ** 2. The supplied data violates the "x2>=x1" constraint.
125806
+ **
125807
+ ** In the first case, if the conflict-handling mode is REPLACE, then
125808
+ ** the conflicting row can be removed before proceeding. In the second
125809
+ ** case, SQLITE_CONSTRAINT must be returned regardless of the
125810
+ ** conflict-handling mode specified by the user.
125811
+ */
125812
+ if( nData>1 ){
125813
+ int ii;
124799125814
124800125815
/* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
124801125816
assert( nData==(pRtree->nDim*2 + 3) );
124802125817
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
124803125818
for(ii=0; ii<(pRtree->nDim*2); ii+=2){
@@ -124817,22 +125832,53 @@
124817125832
goto constraint;
124818125833
}
124819125834
}
124820125835
}
124821125836
124822
- /* Figure out the rowid of the new row. */
124823
- if( sqlite3_value_type(azData[2])==SQLITE_NULL ){
124824
- rc = newRowid(pRtree, &cell.iRowid);
124825
- }else{
125837
+ /* If a rowid value was supplied, check if it is already present in
125838
+ ** the table. If so, the constraint has failed. */
125839
+ if( sqlite3_value_type(azData[2])!=SQLITE_NULL ){
124826125840
cell.iRowid = sqlite3_value_int64(azData[2]);
124827
- sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
124828
- if( SQLITE_ROW==sqlite3_step(pRtree->pReadRowid) ){
124829
- sqlite3_reset(pRtree->pReadRowid);
124830
- rc = SQLITE_CONSTRAINT;
124831
- goto constraint;
125841
+ if( sqlite3_value_type(azData[0])==SQLITE_NULL
125842
+ || sqlite3_value_int64(azData[0])!=cell.iRowid
125843
+ ){
125844
+ int steprc;
125845
+ sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
125846
+ steprc = sqlite3_step(pRtree->pReadRowid);
125847
+ rc = sqlite3_reset(pRtree->pReadRowid);
125848
+ if( SQLITE_ROW==steprc ){
125849
+ if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
125850
+ rc = rtreeDeleteRowid(pRtree, cell.iRowid);
125851
+ }else{
125852
+ rc = SQLITE_CONSTRAINT;
125853
+ goto constraint;
125854
+ }
125855
+ }
124832125856
}
124833
- rc = sqlite3_reset(pRtree->pReadRowid);
125857
+ bHaveRowid = 1;
125858
+ }
125859
+ }
125860
+
125861
+ /* If azData[0] is not an SQL NULL value, it is the rowid of a
125862
+ ** record to delete from the r-tree table. The following block does
125863
+ ** just that.
125864
+ */
125865
+ if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){
125866
+ rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(azData[0]));
125867
+ }
125868
+
125869
+ /* If the azData[] array contains more than one element, elements
125870
+ ** (azData[2]..azData[argc-1]) contain a new record to insert into
125871
+ ** the r-tree structure.
125872
+ */
125873
+ if( rc==SQLITE_OK && nData>1 ){
125874
+ /* Insert the new record into the r-tree */
125875
+ RtreeNode *pLeaf;
125876
+
125877
+ /* Figure out the rowid of the new row. */
125878
+ if( bHaveRowid==0 ){
125879
+ rc = newRowid(pRtree, &cell.iRowid);
124834125880
}
124835125881
*pRowid = cell.iRowid;
124836125882
124837125883
if( rc==SQLITE_OK ){
124838125884
rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
@@ -125068,10 +126114,12 @@
125068126114
int iErr = (argc<6) ? 2 : argc>(RTREE_MAX_DIMENSIONS*2+4) ? 3 : argc%2;
125069126115
if( aErrMsg[iErr] ){
125070126116
*pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]);
125071126117
return SQLITE_ERROR;
125072126118
}
126119
+
126120
+ sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
125073126121
125074126122
/* Allocate the sqlite3_vtab structure */
125075126123
nDb = strlen(argv[1]);
125076126124
nName = strlen(argv[2]);
125077126125
pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
125078126126
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.6.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -648,13 +648,13 @@
648 **
649 ** See also: [sqlite3_libversion()],
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.6.1"
654 #define SQLITE_VERSION_NUMBER 3007006
655 #define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -916,11 +916,12 @@
916 ** Many SQLite functions return an integer result code from the set shown
917 ** here in order to indicates success or failure.
918 **
919 ** New error codes may be added in future versions of SQLite.
920 **
921 ** See also: [SQLITE_IOERR_READ | extended result codes]
 
922 */
923 #define SQLITE_OK 0 /* Successful result */
924 /* beginning-of-error-codes */
925 #define SQLITE_ERROR 1 /* SQL error or missing database */
926 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -998,25 +999,26 @@
998 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
999 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1000 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1001 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1002 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
 
1003
1004 /*
1005 ** CAPI3REF: Flags For File Open Operations
1006 **
1007 ** These bit values are intended for use in the
1008 ** 3rd parameter to the [sqlite3_open_v2()] interface and
1009 ** in the 4th parameter to the xOpen method of the
1010 ** [sqlite3_vfs] object.
1011 */
1012 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
1013 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
1014 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
1015 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
1016 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
1017 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
 
1018 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
1019 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
1020 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
1021 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
1022 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -1123,21 +1125,22 @@
1123 };
1124
1125 /*
1126 ** CAPI3REF: OS Interface File Virtual Methods Object
1127 **
1128 ** Every file opened by the [sqlite3_vfs] xOpen method populates an
1129 ** [sqlite3_file] object (or, more commonly, a subclass of the
1130 ** [sqlite3_file] object) with a pointer to an instance of this object.
1131 ** This object defines the methods used to perform various operations
1132 ** against the open file represented by the [sqlite3_file] object.
1133 **
1134 ** If the xOpen method sets the sqlite3_file.pMethods element
1135 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
1136 ** may be invoked even if the xOpen reported that it failed. The
1137 ** only way to prevent a call to xClose following a failed xOpen
1138 ** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
 
1139 **
1140 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
1141 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
1142 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
1143 ** flag may be ORed in to indicate that only the data of the file
@@ -1302,10 +1305,11 @@
1302 */
1303 typedef struct sqlite3_mutex sqlite3_mutex;
1304
1305 /*
1306 ** CAPI3REF: OS Interface Object
 
1307 **
1308 ** An instance of the sqlite3_vfs object defines the interface between
1309 ** the SQLite core and the underlying operating system. The "vfs"
1310 ** in the name of the object stands for "virtual file system".
1311 **
@@ -1334,10 +1338,11 @@
1334 ** object once the object has been registered.
1335 **
1336 ** The zName field holds the name of the VFS module. The name must
1337 ** be unique across all VFS modules.
1338 **
 
1339 ** ^SQLite guarantees that the zFilename parameter to xOpen
1340 ** is either a NULL pointer or string obtained
1341 ** from xFullPathname() with an optional suffix added.
1342 ** ^If a suffix is added to the zFilename parameter, it will
1343 ** consist of a single "-" character followed by no more than
@@ -1411,10 +1416,11 @@
1411 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1412 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
1413 ** element will be valid after xOpen returns regardless of the success
1414 ** or failure of the xOpen call.
1415 **
 
1416 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1417 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1418 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1419 ** to test whether a file is at least readable. The file can be a
1420 ** directory.
@@ -1657,13 +1663,13 @@
1657 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1658 ** Note, however, that ^sqlite3_config() can be called as part of the
1659 ** implementation of an application-defined [sqlite3_os_init()].
1660 **
1661 ** The first argument to sqlite3_config() is an integer
1662 ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
1663 ** what property of SQLite is to be configured. Subsequent arguments
1664 ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
1665 ** in the first argument.
1666 **
1667 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1668 ** ^If the option is unknown or SQLite is unable to set the option
1669 ** then this routine returns a non-zero [error code].
@@ -1769,10 +1775,11 @@
1769 void *pAppData; /* Argument to xInit() and xShutdown() */
1770 };
1771
1772 /*
1773 ** CAPI3REF: Configuration Options
 
1774 **
1775 ** These constants are the available integer configuration options that
1776 ** can be passed as the first argument to the [sqlite3_config()] interface.
1777 **
1778 ** New configuration options may be added in future releases of SQLite.
@@ -1781,11 +1788,11 @@
1781 ** the call worked. The [sqlite3_config()] interface will return a
1782 ** non-zero [error code] if a discontinued or unsupported configuration option
1783 ** is invoked.
1784 **
1785 ** <dl>
1786 ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1787 ** <dd>There are no arguments to this option. ^This option sets the
1788 ** [threading mode] to Single-thread. In other words, it disables
1789 ** all mutexing and puts SQLite into a mode where it can only be used
1790 ** by a single thread. ^If SQLite is compiled with
1791 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
@@ -1792,11 +1799,11 @@
1792 ** it is not possible to change the [threading mode] from its default
1793 ** value of Single-thread and so [sqlite3_config()] will return
1794 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1795 ** configuration option.</dd>
1796 **
1797 ** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1798 ** <dd>There are no arguments to this option. ^This option sets the
1799 ** [threading mode] to Multi-thread. In other words, it disables
1800 ** mutexing on [database connection] and [prepared statement] objects.
1801 ** The application is responsible for serializing access to
1802 ** [database connections] and [prepared statements]. But other mutexes
@@ -1806,11 +1813,11 @@
1806 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1807 ** it is not possible to set the Multi-thread [threading mode] and
1808 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1809 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1810 **
1811 ** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1812 ** <dd>There are no arguments to this option. ^This option sets the
1813 ** [threading mode] to Serialized. In other words, this option enables
1814 ** all mutexes including the recursive
1815 ** mutexes on [database connection] and [prepared statement] objects.
1816 ** In this mode (which is the default when SQLite is compiled with
@@ -1822,27 +1829,27 @@
1822 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1823 ** it is not possible to set the Serialized [threading mode] and
1824 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1825 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1826 **
1827 ** <dt>SQLITE_CONFIG_MALLOC</dt>
1828 ** <dd> ^(This option takes a single argument which is a pointer to an
1829 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
1830 ** alternative low-level memory allocation routines to be used in place of
1831 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1832 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1833 ** before the [sqlite3_config()] call returns.</dd>
1834 **
1835 ** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1836 ** <dd> ^(This option takes a single argument which is a pointer to an
1837 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1838 ** structure is filled with the currently defined memory allocation routines.)^
1839 ** This option can be used to overload the default memory allocation
1840 ** routines with a wrapper that simulations memory allocation failure or
1841 ** tracks memory usage, for example. </dd>
1842 **
1843 ** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1844 ** <dd> ^This option takes single argument of type int, interpreted as a
1845 ** boolean, which enables or disables the collection of memory allocation
1846 ** statistics. ^(When memory allocation statistics are disabled, the
1847 ** following SQLite interfaces become non-operational:
1848 ** <ul>
@@ -1854,11 +1861,11 @@
1854 ** ^Memory allocation statistics are enabled by default unless SQLite is
1855 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1856 ** allocation statistics are disabled by default.
1857 ** </dd>
1858 **
1859 ** <dt>SQLITE_CONFIG_SCRATCH</dt>
1860 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1861 ** scratch memory. There are three arguments: A pointer an 8-byte
1862 ** aligned memory buffer from which the scratch allocations will be
1863 ** drawn, the size of each scratch allocation (sz),
1864 ** and the maximum number of scratch allocations (N). The sz
@@ -1870,11 +1877,11 @@
1870 ** ^SQLite will never require a scratch buffer that is more than 6
1871 ** times the database page size. ^If SQLite needs needs additional
1872 ** scratch memory beyond what is provided by this configuration option, then
1873 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1874 **
1875 ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1876 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1877 ** the database page cache with the default page cache implemenation.
1878 ** This configuration should not be used if an application-define page
1879 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
1880 ** There are three arguments to this option: A pointer to 8-byte aligned
@@ -1891,11 +1898,11 @@
1891 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1892 ** The pointer in the first argument must
1893 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1894 ** will be undefined.</dd>
1895 **
1896 ** <dt>SQLITE_CONFIG_HEAP</dt>
1897 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1898 ** for all of its dynamic memory allocation needs beyond those provided
1899 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1900 ** There are three arguments: An 8-byte aligned pointer to the memory,
1901 ** the number of bytes in the memory buffer, and the minimum allocation size.
@@ -1908,11 +1915,11 @@
1908 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1909 ** boundary or subsequent behavior of SQLite will be undefined.
1910 ** The minimum allocation size is capped at 2^12. Reasonable values
1911 ** for the minimum allocation size are 2^5 through 2^8.</dd>
1912 **
1913 ** <dt>SQLITE_CONFIG_MUTEX</dt>
1914 ** <dd> ^(This option takes a single argument which is a pointer to an
1915 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1916 ** alternative low-level mutex routines to be used in place
1917 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1918 ** content of the [sqlite3_mutex_methods] structure before the call to
@@ -1920,11 +1927,11 @@
1920 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1921 ** the entire mutexing subsystem is omitted from the build and hence calls to
1922 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1923 ** return [SQLITE_ERROR].</dd>
1924 **
1925 ** <dt>SQLITE_CONFIG_GETMUTEX</dt>
1926 ** <dd> ^(This option takes a single argument which is a pointer to an
1927 ** instance of the [sqlite3_mutex_methods] structure. The
1928 ** [sqlite3_mutex_methods]
1929 ** structure is filled with the currently defined mutex routines.)^
1930 ** This option can be used to overload the default mutex allocation
@@ -1933,32 +1940,32 @@
1933 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1934 ** the entire mutexing subsystem is omitted from the build and hence calls to
1935 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1936 ** return [SQLITE_ERROR].</dd>
1937 **
1938 ** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1939 ** <dd> ^(This option takes two arguments that determine the default
1940 ** memory allocation for the lookaside memory allocator on each
1941 ** [database connection]. The first argument is the
1942 ** size of each lookaside buffer slot and the second is the number of
1943 ** slots allocated to each database connection.)^ ^(This option sets the
1944 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1945 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1946 ** configuration on individual connections.)^ </dd>
1947 **
1948 ** <dt>SQLITE_CONFIG_PCACHE</dt>
1949 ** <dd> ^(This option takes a single argument which is a pointer to
1950 ** an [sqlite3_pcache_methods] object. This object specifies the interface
1951 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1952 ** object and uses it for page cache memory allocations.</dd>
1953 **
1954 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1955 ** <dd> ^(This option takes a single argument which is a pointer to an
1956 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1957 ** page cache implementation into that object.)^ </dd>
1958 **
1959 ** <dt>SQLITE_CONFIG_LOG</dt>
1960 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1961 ** function with a call signature of void(*)(void*,int,const char*),
1962 ** and a pointer to void. ^If the function pointer is not NULL, it is
1963 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1964 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
@@ -1972,10 +1979,22 @@
1972 ** The SQLite logging interface is not reentrant; the logger function
1973 ** supplied by the application must not invoke any SQLite interface.
1974 ** In a multi-threaded application, the application-defined logger
1975 ** function must be threadsafe. </dd>
1976 **
 
 
 
 
 
 
 
 
 
 
 
 
1977 ** </dl>
1978 */
1979 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1980 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1981 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1990,10 +2009,11 @@
1990 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
1991 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
1992 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1993 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1994 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
 
1995
1996 /*
1997 ** CAPI3REF: Database Connection Configuration Options
1998 **
1999 ** These constants are the available integer configuration options that
@@ -2075,17 +2095,21 @@
2075 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2076 ** is another alias for the rowid.
2077 **
2078 ** ^This routine returns the [rowid] of the most recent
2079 ** successful [INSERT] into the database from the [database connection]
2080 ** in the first argument. ^If no successful [INSERT]s
 
 
2081 ** have ever occurred on that database connection, zero is returned.
2082 **
2083 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
2084 ** row is returned by this routine as long as the trigger is running.
2085 ** But once the trigger terminates, the value returned by this routine
2086 ** reverts to the last value inserted before the trigger fired.)^
 
 
2087 **
2088 ** ^An [INSERT] that fails due to a constraint violation is not a
2089 ** successful [INSERT] and does not change the value returned by this
2090 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2091 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2744,10 +2768,13 @@
2744 ** The [sqlite3_set_authorizer | authorizer callback function] must
2745 ** return either [SQLITE_OK] or one of these two constants in order
2746 ** to signal SQLite whether or not the action is permitted. See the
2747 ** [sqlite3_set_authorizer | authorizer documentation] for additional
2748 ** information.
 
 
 
2749 */
2750 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2751 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
2752
2753 /*
@@ -2866,11 +2893,11 @@
2866 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2867
2868 /*
2869 ** CAPI3REF: Opening A New Database Connection
2870 **
2871 ** ^These routines open an SQLite database file whose name is given by the
2872 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2873 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2874 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
2875 ** returned in *ppDb, even if an error occurs. The only exception is that
2876 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
@@ -2893,11 +2920,11 @@
2893 ** except that it accepts two additional parameters for additional control
2894 ** over the new database connection. ^(The flags parameter to
2895 ** sqlite3_open_v2() can take one of
2896 ** the following three values, optionally combined with the
2897 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2898 ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
2899 **
2900 ** <dl>
2901 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
2902 ** <dd>The database is opened in read-only mode. If the database does not
2903 ** already exist, an error is returned.</dd>)^
@@ -2912,13 +2939,12 @@
2912 ** it does not already exist. This is the behavior that is always used for
2913 ** sqlite3_open() and sqlite3_open16().</dd>)^
2914 ** </dl>
2915 **
2916 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2917 ** combinations shown above or one of the combinations shown above combined
2918 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2919 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2920 ** then the behavior is undefined.
2921 **
2922 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2923 ** opens in the multi-thread [threading mode] as long as the single-thread
2924 ** mode has not been set at compile-time or start-time. ^If the
@@ -2928,10 +2954,15 @@
2928 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
2929 ** eligible to use [shared cache mode], regardless of whether or not shared
2930 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
2931 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2932 ** participate in [shared cache mode] even if it is enabled.
 
 
 
 
 
2933 **
2934 ** ^If the filename is ":memory:", then a private, temporary in-memory database
2935 ** is created for the connection. ^This in-memory database will vanish when
2936 ** the database connection is closed. Future versions of SQLite might
2937 ** make use of additional special filenames that begin with the ":" character.
@@ -2941,14 +2972,115 @@
2941 **
2942 ** ^If the filename is an empty string, then a private, temporary
2943 ** on-disk database will be created. ^This private database will be
2944 ** automatically deleted as soon as the database connection is closed.
2945 **
2946 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
2947 ** [sqlite3_vfs] object that defines the operating system interface that
2948 ** the new database connection should use. ^If the fourth parameter is
2949 ** a NULL pointer then the default [sqlite3_vfs] object is used.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2950 **
2951 ** <b>Note to Windows users:</b> The encoding used for the filename argument
2952 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
2953 ** codepage is currently defined. Filenames containing international
2954 ** characters must be converted to UTF-8 prior to passing them into
@@ -2966,10 +3098,30 @@
2966 const char *filename, /* Database filename (UTF-8) */
2967 sqlite3 **ppDb, /* OUT: SQLite db handle */
2968 int flags, /* Flags */
2969 const char *zVfs /* Name of VFS module to use */
2970 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2971
2972 /*
2973 ** CAPI3REF: Error Codes And Messages
2974 **
2975 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
@@ -3082,47 +3234,49 @@
3082 ** that can be lowered at run-time using [sqlite3_limit()].
3083 ** The synopsis of the meanings of the various limits is shown below.
3084 ** Additional information is available at [limits | Limits in SQLite].
3085 **
3086 ** <dl>
3087 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3088 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3089 **
3090 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3091 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3092 **
3093 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
3094 ** <dd>The maximum number of columns in a table definition or in the
3095 ** result set of a [SELECT] or the maximum number of columns in an index
3096 ** or in an ORDER BY or GROUP BY clause.</dd>)^
3097 **
3098 ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
3099 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
3100 **
3101 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3102 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3103 **
3104 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3105 ** <dd>The maximum number of instructions in a virtual machine program
3106 ** used to implement an SQL statement. This limit is not currently
3107 ** enforced, though that might be added in some future release of
3108 ** SQLite.</dd>)^
3109 **
3110 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3111 ** <dd>The maximum number of arguments on a function.</dd>)^
3112 **
3113 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
3114 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
3115 **
 
3116 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
3117 ** <dd>The maximum length of the pattern argument to the [LIKE] or
3118 ** [GLOB] operators.</dd>)^
3119 **
 
3120 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3121 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3122 **
3123 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3124 ** <dd>The maximum depth of recursion for triggers.</dd>)^
3125 ** </dl>
3126 */
3127 #define SQLITE_LIMIT_LENGTH 0
3128 #define SQLITE_LIMIT_SQL_LENGTH 1
@@ -5153,10 +5307,15 @@
5153 int (*xRollback)(sqlite3_vtab *pVTab);
5154 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
5155 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
5156 void **ppArg);
5157 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
 
 
 
 
 
5158 };
5159
5160 /*
5161 ** CAPI3REF: Virtual Table Indexing Information
5162 ** KEYWORDS: sqlite3_index_info
@@ -5967,11 +6126,11 @@
5967 **
5968 ** ^This interface is used to retrieve runtime status information
5969 ** about the performance of SQLite, and optionally to reset various
5970 ** highwater marks. ^The first argument is an integer code for
5971 ** the specific parameter to measure. ^(Recognized integer codes
5972 ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
5973 ** ^The current value of the parameter is returned into *pCurrent.
5974 ** ^The highest recorded value is returned in *pHighwater. ^If the
5975 ** resetFlag is true, then the highest record value is reset after
5976 ** *pHighwater is written. ^(Some parameters do not record the highest
5977 ** value. For those parameters
@@ -5994,82 +6153,84 @@
5994 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5995
5996
5997 /*
5998 ** CAPI3REF: Status Parameters
 
5999 **
6000 ** These integer constants designate various run-time status parameters
6001 ** that can be returned by [sqlite3_status()].
6002 **
6003 ** <dl>
6004 ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
6005 ** <dd>This parameter is the current amount of memory checked out
6006 ** using [sqlite3_malloc()], either directly or indirectly. The
6007 ** figure includes calls made to [sqlite3_malloc()] by the application
6008 ** and internal memory usage by the SQLite library. Scratch memory
6009 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
6010 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
6011 ** this parameter. The amount returned is the sum of the allocation
6012 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
6013 **
6014 ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
6015 ** <dd>This parameter records the largest memory allocation request
6016 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
6017 ** internal equivalents). Only the value returned in the
6018 ** *pHighwater parameter to [sqlite3_status()] is of interest.
6019 ** The value written into the *pCurrent parameter is undefined.</dd>)^
6020 **
6021 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
6022 ** <dd>This parameter records the number of separate memory allocations
6023 ** currently checked out.</dd>)^
6024 **
6025 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
6026 ** <dd>This parameter returns the number of pages used out of the
6027 ** [pagecache memory allocator] that was configured using
6028 ** [SQLITE_CONFIG_PAGECACHE]. The
6029 ** value returned is in pages, not in bytes.</dd>)^
6030 **
 
6031 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
6032 ** <dd>This parameter returns the number of bytes of page cache
6033 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
6034 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
6035 ** returned value includes allocations that overflowed because they
6036 ** where too large (they were larger than the "sz" parameter to
6037 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
6038 ** no space was left in the page cache.</dd>)^
6039 **
6040 ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
6041 ** <dd>This parameter records the largest memory allocation request
6042 ** handed to [pagecache memory allocator]. Only the value returned in the
6043 ** *pHighwater parameter to [sqlite3_status()] is of interest.
6044 ** The value written into the *pCurrent parameter is undefined.</dd>)^
6045 **
6046 ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
6047 ** <dd>This parameter returns the number of allocations used out of the
6048 ** [scratch memory allocator] configured using
6049 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
6050 ** in bytes. Since a single thread may only have one scratch allocation
6051 ** outstanding at time, this parameter also reports the number of threads
6052 ** using scratch memory at the same time.</dd>)^
6053 **
6054 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
6055 ** <dd>This parameter returns the number of bytes of scratch memory
6056 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
6057 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
6058 ** returned include overflows because the requested allocation was too
6059 ** larger (that is, because the requested allocation was larger than the
6060 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
6061 ** slots were available.
6062 ** </dd>)^
6063 **
6064 ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
6065 ** <dd>This parameter records the largest memory allocation request
6066 ** handed to [scratch memory allocator]. Only the value returned in the
6067 ** *pHighwater parameter to [sqlite3_status()] is of interest.
6068 ** The value written into the *pCurrent parameter is undefined.</dd>)^
6069 **
6070 ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
6071 ** <dd>This parameter records the deepest parser stack. It is only
6072 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
6073 ** </dl>
6074 **
6075 ** New status parameters may be added from time to time.
@@ -6090,13 +6251,13 @@
6090 **
6091 ** ^This interface is used to retrieve runtime status information
6092 ** about a single [database connection]. ^The first argument is the
6093 ** database connection object to be interrogated. ^The second argument
6094 ** is an integer constant, taken from the set of
6095 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
6096 ** determines the parameter to interrogate. The set of
6097 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
6098 ** to grow in future releases of SQLite.
6099 **
6100 ** ^The current value of the requested parameter is written into *pCur
6101 ** and the highest instantaneous value is written into *pHiwtr. ^If
6102 ** the resetFlg is true, then the highest instantaneous value is
@@ -6109,10 +6270,11 @@
6109 */
6110 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
6111
6112 /*
6113 ** CAPI3REF: Status Parameters for database connections
 
6114 **
6115 ** These constants are the available integer "verbs" that can be passed as
6116 ** the second argument to the [sqlite3_db_status()] interface.
6117 **
6118 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -6120,48 +6282,50 @@
6120 ** [sqlite3_db_status()] to make sure that the call worked.
6121 ** The [sqlite3_db_status()] interface will return a non-zero error code
6122 ** if a discontinued or unsupported verb is invoked.
6123 **
6124 ** <dl>
6125 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6126 ** <dd>This parameter returns the number of lookaside memory slots currently
6127 ** checked out.</dd>)^
6128 **
6129 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6130 ** <dd>This parameter returns the number malloc attempts that were
6131 ** satisfied using lookaside memory. Only the high-water value is meaningful;
6132 ** the current value is always zero.)^
6133 **
 
6134 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
6135 ** <dd>This parameter returns the number malloc attempts that might have
6136 ** been satisfied using lookaside memory but failed due to the amount of
6137 ** memory requested being larger than the lookaside slot size.
6138 ** Only the high-water value is meaningful;
6139 ** the current value is always zero.)^
6140 **
 
6141 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
6142 ** <dd>This parameter returns the number malloc attempts that might have
6143 ** been satisfied using lookaside memory but failed due to all lookaside
6144 ** memory already being in use.
6145 ** Only the high-water value is meaningful;
6146 ** the current value is always zero.)^
6147 **
6148 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6149 ** <dd>This parameter returns the approximate number of of bytes of heap
6150 ** memory used by all pager caches associated with the database connection.)^
6151 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
6152 **
6153 ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6154 ** <dd>This parameter returns the approximate number of of bytes of heap
6155 ** memory used to store the schema for all databases associated
6156 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
6157 ** ^The full amount of memory used by the schemas is reported, even if the
6158 ** schema memory is shared with other database connections due to
6159 ** [shared cache mode] being enabled.
6160 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
6161 **
6162 ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6163 ** <dd>This parameter returns the approximate number of of bytes of heap
6164 ** and lookaside memory used by all prepared statements associated with
6165 ** the database connection.)^
6166 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6167 ** </dd>
@@ -6179,11 +6343,11 @@
6179
6180 /*
6181 ** CAPI3REF: Prepared Statement Status
6182 **
6183 ** ^(Each prepared statement maintains various
6184 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
6185 ** of times it has performed specific operations.)^ These counters can
6186 ** be used to monitor the performance characteristics of the prepared
6187 ** statements. For example, if the number of table steps greatly exceeds
6188 ** the number of table searches or result rows, that would tend to indicate
6189 ** that the prepared statement is using a full table scan rather than
@@ -6190,11 +6354,11 @@
6190 ** an index.
6191 **
6192 ** ^(This interface is used to retrieve and reset counter values from
6193 ** a [prepared statement]. The first argument is the prepared statement
6194 ** object to be interrogated. The second argument
6195 ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
6196 ** to be interrogated.)^
6197 ** ^The current value of the requested counter is returned.
6198 ** ^If the resetFlg is true, then the counter is reset to zero after this
6199 ** interface call returns.
6200 **
@@ -6202,28 +6366,29 @@
6202 */
6203 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
6204
6205 /*
6206 ** CAPI3REF: Status Parameters for prepared statements
 
6207 **
6208 ** These preprocessor macros define integer codes that name counter
6209 ** values associated with the [sqlite3_stmt_status()] interface.
6210 ** The meanings of the various counters are as follows:
6211 **
6212 ** <dl>
6213 ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
6214 ** <dd>^This is the number of times that SQLite has stepped forward in
6215 ** a table as part of a full table scan. Large numbers for this counter
6216 ** may indicate opportunities for performance improvement through
6217 ** careful use of indices.</dd>
6218 **
6219 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
6220 ** <dd>^This is the number of sort operations that have occurred.
6221 ** A non-zero value in this counter may indicate an opportunity to
6222 ** improvement performance through careful use of indices.</dd>
6223 **
6224 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
6225 ** <dd>^This is the number of rows inserted into transient indices that
6226 ** were created automatically in order to help joins run faster.
6227 ** A non-zero value in this counter may indicate an opportunity to
6228 ** improvement performance by adding permanent indices that do not
6229 ** need to be reinitialized each time the statement is run.</dd>
@@ -6270,10 +6435,11 @@
6270 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
6271 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
6272 ** the application may discard the parameter after the call to
6273 ** [sqlite3_config()] returns.)^
6274 **
 
6275 ** ^(The xInit() method is called once for each effective
6276 ** call to [sqlite3_initialize()])^
6277 ** (usually only once during the lifetime of the process). ^(The xInit()
6278 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
6279 ** The intent of the xInit() method is to set up global data structures
@@ -6280,10 +6446,11 @@
6280 ** required by the custom page cache implementation.
6281 ** ^(If the xInit() method is NULL, then the
6282 ** built-in default page cache is used instead of the application defined
6283 ** page cache.)^
6284 **
 
6285 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
6286 ** It can be used to clean up
6287 ** any outstanding resources before process shutdown, if required.
6288 ** ^The xShutdown() method may be NULL.
6289 **
@@ -6294,10 +6461,11 @@
6294 ** in multithreaded applications.
6295 **
6296 ** ^SQLite will never invoke xInit() more than once without an intervening
6297 ** call to xShutdown().
6298 **
 
6299 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
6300 ** SQLite will typically create one cache instance for each open database file,
6301 ** though this is not guaranteed. ^The
6302 ** first parameter, szPage, is the size in bytes of the pages that must
6303 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
@@ -6318,20 +6486,23 @@
6318 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
6319 ** false will always have the "discard" flag set to true.
6320 ** ^Hence, a cache created with bPurgeable false will
6321 ** never contain any unpinned pages.
6322 **
 
6323 ** ^(The xCachesize() method may be called at any time by SQLite to set the
6324 ** suggested maximum cache-size (number of pages stored by) the cache
6325 ** instance passed as the first argument. This is the value configured using
6326 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
6327 ** parameter, the implementation is not required to do anything with this
6328 ** value; it is advisory only.
6329 **
 
6330 ** The xPagecount() method must return the number of pages currently
6331 ** stored in the cache, both pinned and unpinned.
6332 **
 
6333 ** The xFetch() method locates a page in the cache and returns a pointer to
6334 ** the page, or a NULL pointer.
6335 ** A "page", in this context, means a buffer of szPage bytes aligned at an
6336 ** 8-byte boundary. The page to be fetched is determined by the key. ^The
6337 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
@@ -6356,10 +6527,11 @@
6356 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
6357 ** failed.)^ In between the to xFetch() calls, SQLite may
6358 ** attempt to unpin one or more cache pages by spilling the content of
6359 ** pinned pages to disk and synching the operating system disk cache.
6360 **
 
6361 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
6362 ** as its second argument. If the third parameter, discard, is non-zero,
6363 ** then the page must be evicted from the cache.
6364 ** ^If the discard parameter is
6365 ** zero, then the page may be discarded or retained at the discretion of
@@ -6368,10 +6540,11 @@
6368 **
6369 ** The cache must not perform any reference counting. A single
6370 ** call to xUnpin() unpins the page regardless of the number of prior calls
6371 ** to xFetch().
6372 **
 
6373 ** The xRekey() method is used to change the key value associated with the
6374 ** page passed as the second argument. If the cache
6375 ** previously contains an entry associated with newKey, it must be
6376 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
6377 ** to be pinned.
@@ -6380,10 +6553,11 @@
6380 ** existing cache entries with page numbers (keys) greater than or equal
6381 ** to the value of the iLimit parameter passed to xTruncate(). If any
6382 ** of these pages are pinned, they are implicitly unpinned, meaning that
6383 ** they can be safely discarded.
6384 **
 
6385 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
6386 ** All resources associated with the specified cache should be freed. ^After
6387 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
6388 ** handle invalid, and will not use it with any other sqlite3_pcache_methods
6389 ** functions.
@@ -6442,11 +6616,11 @@
6442 ** associated with the backup operation.
6443 ** </ol>)^
6444 ** There should be exactly one call to sqlite3_backup_finish() for each
6445 ** successful call to sqlite3_backup_init().
6446 **
6447 ** <b>sqlite3_backup_init()</b>
6448 **
6449 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
6450 ** [database connection] associated with the destination database
6451 ** and the database name, respectively.
6452 ** ^The database name is "main" for the main database, "temp" for the
@@ -6469,11 +6643,11 @@
6469 ** [sqlite3_backup] object.
6470 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
6471 ** sqlite3_backup_finish() functions to perform the specified backup
6472 ** operation.
6473 **
6474 ** <b>sqlite3_backup_step()</b>
6475 **
6476 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6477 ** the source and destination databases specified by [sqlite3_backup] object B.
6478 ** ^If N is negative, all remaining source pages are copied.
6479 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
@@ -6526,11 +6700,11 @@
6526 ** restarted by the next call to sqlite3_backup_step(). ^If the source
6527 ** database is modified by the using the same database connection as is used
6528 ** by the backup operation, then the backup database is automatically
6529 ** updated at the same time.
6530 **
6531 ** <b>sqlite3_backup_finish()</b>
6532 **
6533 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
6534 ** application wishes to abandon the backup operation, the application
6535 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
6536 ** ^The sqlite3_backup_finish() interfaces releases all
@@ -6549,11 +6723,12 @@
6549 **
6550 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
6551 ** is not a permanent error and does not affect the return value of
6552 ** sqlite3_backup_finish().
6553 **
6554 ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
 
6555 **
6556 ** ^Each call to sqlite3_backup_step() sets two values inside
6557 ** the [sqlite3_backup] object: the number of pages still to be backed
6558 ** up and the total number of pages in the source database file.
6559 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
@@ -6934,10 +7109,97 @@
6934 ** each of these values.
6935 */
6936 #define SQLITE_CHECKPOINT_PASSIVE 0
6937 #define SQLITE_CHECKPOINT_FULL 1
6938 #define SQLITE_CHECKPOINT_RESTART 2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6939
6940
6941 /*
6942 ** Undo the hack that converts floating point types to integer for
6943 ** builds on processors without floating point support.
@@ -7601,10 +7863,11 @@
7601 typedef struct Trigger Trigger;
7602 typedef struct TriggerPrg TriggerPrg;
7603 typedef struct TriggerStep TriggerStep;
7604 typedef struct UnpackedRecord UnpackedRecord;
7605 typedef struct VTable VTable;
 
7606 typedef struct Walker Walker;
7607 typedef struct WherePlan WherePlan;
7608 typedef struct WhereInfo WhereInfo;
7609 typedef struct WhereLevel WhereLevel;
7610
@@ -7657,10 +7920,11 @@
7657 typedef struct BtCursor BtCursor;
7658 typedef struct BtShared BtShared;
7659
7660
7661 SQLITE_PRIVATE int sqlite3BtreeOpen(
 
7662 const char *zFilename, /* Name of database file to open */
7663 sqlite3 *db, /* Associated database connection */
7664 Btree **ppBtree, /* Return open Btree* here */
7665 int flags, /* Flags */
7666 int vfsFlags /* Flags passed through to VFS open */
@@ -9136,19 +9400,20 @@
9136 struct sqlite3 {
9137 sqlite3_vfs *pVfs; /* OS Interface */
9138 int nDb; /* Number of backends currently in use */
9139 Db *aDb; /* All backends */
9140 int flags; /* Miscellaneous flags. See below */
9141 int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
9142 int errCode; /* Most recent error code (SQLITE_*) */
9143 int errMask; /* & result codes with this before returning */
9144 u8 autoCommit; /* The auto-commit flag. */
9145 u8 temp_store; /* 1: file 2: memory 0: default */
9146 u8 mallocFailed; /* True if we have seen a malloc failure */
9147 u8 dfltLockMode; /* Default locking-mode for attached dbs */
9148 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
9149 u8 suppressErr; /* Do not issue error messages if true */
 
9150 int nextPagesize; /* Pagesize after VACUUM if >0 */
9151 int nTable; /* Number of tables in the database */
9152 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
9153 i64 lastRowid; /* ROWID of most recent insert (see above) */
9154 u32 magic; /* Magic number for detect library misuse */
@@ -9203,11 +9468,11 @@
9203 void *pProgressArg; /* Argument to the progress callback */
9204 int nProgressOps; /* Number of opcodes for progress callback */
9205 #endif
9206 #ifndef SQLITE_OMIT_VIRTUALTABLE
9207 Hash aModule; /* populated by sqlite3_create_module() */
9208 Table *pVTab; /* vtab with active Connect/Create method */
9209 VTable **aVTrans; /* Virtual tables with open transactions */
9210 int nVTrans; /* Allocated size of aVTrans */
9211 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
9212 #endif
9213 FuncDefHash aFunc; /* Hash table of connection functions */
@@ -9566,10 +9831,11 @@
9566 struct VTable {
9567 sqlite3 *db; /* Database connection associated with this table */
9568 Module *pMod; /* Pointer to module implementation */
9569 sqlite3_vtab *pVtab; /* Pointer to vtab instance */
9570 int nRef; /* Number of pointers to this structure */
 
9571 VTable *pNext; /* Next in linked list (see above) */
9572 };
9573
9574 /*
9575 ** Each SQL table is represented in memory by an instance of the
@@ -10754,10 +11020,11 @@
10754 */
10755 struct Sqlite3Config {
10756 int bMemstat; /* True to enable memory status */
10757 int bCoreMutex; /* True to enable core mutexing */
10758 int bFullMutex; /* True to enable full mutexing */
 
10759 int mxStrlen; /* Maximum string length */
10760 int szLookaside; /* Default lookaside buffer size */
10761 int nLookaside; /* Default lookaside buffer count */
10762 sqlite3_mem_methods m; /* Low-level memory allocation interface */
10763 sqlite3_mutex_methods mutex; /* Low-level mutex interface */
@@ -11003,10 +11270,12 @@
11003 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
11004 SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
11005 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
11006 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
11007 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
 
 
11008
11009 SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32);
11010 SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32);
11011 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
11012 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
@@ -11253,10 +11522,11 @@
11253 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
11254 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
11255 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
11256 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
11257 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
 
11258 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
11259 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
11260 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
11261 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
11262 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
@@ -11268,10 +11538,16 @@
11268 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
11269 SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
11270 SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
11271 SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
11272 SQLITE_PRIVATE int sqlite3AbsInt32(int);
 
 
 
 
 
 
11273
11274 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
11275 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
11276 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11277 void(*)(void*));
@@ -11377,18 +11653,20 @@
11377 # define sqlite3VtabCommit(X)
11378 # define sqlite3VtabInSync(db) 0
11379 # define sqlite3VtabLock(X)
11380 # define sqlite3VtabUnlock(X)
11381 # define sqlite3VtabUnlockList(X)
 
11382 #else
11383 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
11384 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
11385 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
11386 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
11387 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
11388 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
11389 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
 
11390 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
11391 #endif
11392 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
11393 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
11394 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
@@ -11691,20 +11969,23 @@
11691 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
11692 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
11693 };
11694 #endif
11695
11696
 
 
11697
11698 /*
11699 ** The following singleton contains the global configuration for
11700 ** the SQLite library.
11701 */
11702 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
11703 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
11704 1, /* bCoreMutex */
11705 SQLITE_THREADSAFE==1, /* bFullMutex */
 
11706 0x7ffffffe, /* mxStrlen */
11707 100, /* szLookaside */
11708 500, /* nLookaside */
11709 {0,0,0,0,0,0,0,0}, /* m */
11710 {0,0,0,0,0,0,0,0,0}, /* mutex */
@@ -18217,11 +18498,11 @@
18217 sqlite3_mutex_enter(mem0.mutex);
18218 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
18219 nDiff = nNew - nOld;
18220 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
18221 mem0.alarmThreshold-nDiff ){
18222 sqlite3MallocAlarm(nNew-nOld);
18223 }
18224 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
18225 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
18226 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
18227 if( pNew==0 && mem0.alarmCallback ){
@@ -18228,11 +18509,11 @@
18228 sqlite3MallocAlarm(nBytes);
18229 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
18230 }
18231 if( pNew ){
18232 nNew = sqlite3MallocSize(pNew);
18233 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff);
18234 }
18235 sqlite3_mutex_leave(mem0.mutex);
18236 }else{
18237 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
18238 }
@@ -21183,27 +21464,25 @@
21183 p[3] = (u8)v;
21184 }
21185
21186
21187
21188 #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
21189 /*
21190 ** Translate a single byte of Hex into an integer.
21191 ** This routine only works if h really is a valid hexadecimal
21192 ** character: 0..9a..fA..F
21193 */
21194 static u8 hexToInt(int h){
21195 assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') );
21196 #ifdef SQLITE_ASCII
21197 h += 9*(1&(h>>6));
21198 #endif
21199 #ifdef SQLITE_EBCDIC
21200 h += 9*(1&~(h>>4));
21201 #endif
21202 return (u8)(h & 0xf);
21203 }
21204 #endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */
21205
21206 #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
21207 /*
21208 ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
21209 ** value. Return a pointer to its binary value. Space to hold the
@@ -21216,11 +21495,11 @@
21216
21217 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
21218 n--;
21219 if( zBlob ){
21220 for(i=0; i<n; i+=2){
21221 zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);
21222 }
21223 zBlob[i/2] = 0;
21224 }
21225 return zBlob;
21226 }
@@ -21348,10 +21627,36 @@
21348 SQLITE_PRIVATE int sqlite3AbsInt32(int x){
21349 if( x>=0 ) return x;
21350 if( x==(int)0x80000000 ) return 0x7fffffff;
21351 return -x;
21352 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21353
21354 /************** End of util.c ************************************************/
21355 /************** Begin file hash.c ********************************************/
21356 /*
21357 ** 2001 September 22
@@ -27890,10 +28195,11 @@
27890 sqlite3_snprintf(nShmFilename, zShmFilename,
27891 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
27892 (u32)sStat.st_ino, (u32)sStat.st_dev);
27893 #else
27894 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
 
27895 #endif
27896 pShmNode->h = -1;
27897 pDbFd->pInode->pShmNode = pShmNode;
27898 pShmNode->pInode = pDbFd->pInode;
27899 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
@@ -28923,17 +29229,23 @@
28923 ** Finally, if the file being opened is a WAL or regular journal file, then
28924 ** this function queries the file-system for the permissions on the
28925 ** corresponding database file and sets *pMode to this value. Whenever
28926 ** possible, WAL and journal files are created using the same permissions
28927 ** as the associated database file.
 
 
 
 
 
28928 */
28929 static int findCreateFileMode(
28930 const char *zPath, /* Path of file (possibly) being created */
28931 int flags, /* Flags passed as 4th argument to xOpen() */
28932 mode_t *pMode /* OUT: Permissions to open file with */
28933 ){
28934 int rc = SQLITE_OK; /* Return Code */
 
28935 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
28936 char zDb[MAX_PATHNAME+1]; /* Database file path */
28937 int nDb; /* Number of valid bytes in zDb */
28938 struct stat sStat; /* Output of stat() on database file */
28939
@@ -28941,19 +29253,19 @@
28941 ** the path to the associated database file from zPath. This block handles
28942 ** the following naming conventions:
28943 **
28944 ** "<path to db>-journal"
28945 ** "<path to db>-wal"
28946 ** "<path to db>-journal-NNNN"
28947 ** "<path to db>-wal-NNNN"
28948 **
28949 ** where NNNN is a 4 digit decimal number. The NNNN naming schemes are
28950 ** used by the test_multiplex.c module.
28951 */
28952 nDb = sqlite3Strlen30(zPath) - 1;
28953 while( nDb>0 && zPath[nDb]!='l' ) nDb--;
28954 nDb -= ((flags & SQLITE_OPEN_WAL) ? 3 : 7);
28955 memcpy(zDb, zPath, nDb);
28956 zDb[nDb] = '\0';
28957
28958 if( 0==stat(zDb, &sStat) ){
28959 *pMode = sStat.st_mode & 0777;
@@ -28960,12 +29272,10 @@
28960 }else{
28961 rc = SQLITE_IOERR_FSTAT;
28962 }
28963 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
28964 *pMode = 0600;
28965 }else{
28966 *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
28967 }
28968 return rc;
28969 }
28970
28971 /*
@@ -32620,10 +32930,11 @@
32620 return SQLITE_NOMEM;
32621 }
32622 memset(pNew, 0, sizeof(*pNew));
32623 pNew->zFilename = (char*)&pNew[1];
32624 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
 
32625
32626 /* Look to see if there is an existing winShmNode that can be used.
32627 ** If no matching winShmNode currently exists, create a new one.
32628 */
32629 winShmEnterMutex();
@@ -33514,10 +33825,17 @@
33514
33515 #if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
33516 int nByte;
33517 void *zConverted;
33518 char *zOut;
 
 
 
 
 
 
 
33519
33520 /* It's odd to simulate an io-error here, but really this is just
33521 ** using the io-error infrastructure to test that SQLite handles this
33522 ** function failing. This function could fail if, for example, the
33523 ** current working directory has been unlinked.
@@ -36326,10 +36644,11 @@
36326 #define _WAL_H_
36327
36328
36329 #ifdef SQLITE_OMIT_WAL
36330 # define sqlite3WalOpen(x,y,z) 0
 
36331 # define sqlite3WalClose(w,x,y,z) 0
36332 # define sqlite3WalBeginReadTransaction(y,z) 0
36333 # define sqlite3WalEndReadTransaction(z)
36334 # define sqlite3WalRead(v,w,x,y,z) 0
36335 # define sqlite3WalDbsize(y) 0
@@ -36351,13 +36670,16 @@
36351 ** There is one object of this type for each pager.
36352 */
36353 typedef struct Wal Wal;
36354
36355 /* Open and close a connection to a write-ahead log. */
36356 SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *zName, int, Wal**);
36357 SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *);
36358
 
 
 
36359 /* Used by readers to open (lock) and close (unlock) a snapshot. A
36360 ** snapshot is like a read-transaction. It is the state of the database
36361 ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
36362 ** preserves the current state even if the other threads or processes
36363 ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
@@ -40702,10 +41024,12 @@
40702 int nPathname = 0; /* Number of bytes in zPathname */
40703 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
40704 int noReadlock = (flags & PAGER_NO_READLOCK)!=0; /* True to omit read-lock */
40705 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
40706 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
 
 
40707
40708 /* Figure out how much space is required for each journal file-handle
40709 ** (there are two of them, the main journal and the sub-journal). This
40710 ** is the maximum space required for an in-memory journal file handle
40711 ** and a regular journal file-handle. Note that a "regular journal-handle"
@@ -40732,18 +41056,25 @@
40732 /* Compute and store the full pathname in an allocated buffer pointed
40733 ** to by zPathname, length nPathname. Or, if this is a temporary file,
40734 ** leave both nPathname and zPathname set to 0.
40735 */
40736 if( zFilename && zFilename[0] ){
 
40737 nPathname = pVfs->mxPathname+1;
40738 zPathname = sqlite3Malloc(nPathname*2);
40739 if( zPathname==0 ){
40740 return SQLITE_NOMEM;
40741 }
40742 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
40743 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
40744 nPathname = sqlite3Strlen30(zPathname);
 
 
 
 
 
 
40745 if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
40746 /* This branch is taken when the journal path required by
40747 ** the database being opened will be more than pVfs->mxPathname
40748 ** bytes in length. This means the database cannot be opened,
40749 ** as it will not be possible to open the journal file or even
@@ -40772,11 +41103,11 @@
40772 pPtr = (u8 *)sqlite3MallocZero(
40773 ROUND8(sizeof(*pPager)) + /* Pager structure */
40774 ROUND8(pcacheSize) + /* PCache object */
40775 ROUND8(pVfs->szOsFile) + /* The main db file */
40776 journalFileSize * 2 + /* The two journal files */
40777 nPathname + 1 + /* zFilename */
40778 nPathname + 8 + 1 /* zJournal */
40779 #ifndef SQLITE_OMIT_WAL
40780 + nPathname + 4 + 1 /* zWal */
40781 #endif
40782 );
@@ -40794,18 +41125,21 @@
40794 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
40795
40796 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
40797 if( zPathname ){
40798 assert( nPathname>0 );
40799 pPager->zJournal = (char*)(pPtr += nPathname + 1);
40800 memcpy(pPager->zFilename, zPathname, nPathname);
 
40801 memcpy(pPager->zJournal, zPathname, nPathname);
40802 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
 
40803 #ifndef SQLITE_OMIT_WAL
40804 pPager->zWal = &pPager->zJournal[nPathname+8+1];
40805 memcpy(pPager->zWal, zPathname, nPathname);
40806 memcpy(&pPager->zWal[nPathname], "-wal", 4);
 
40807 #endif
40808 sqlite3_free(zPathname);
40809 }
40810 pPager->pVfs = pVfs;
40811 pPager->vfsFlags = vfsFlags;
@@ -43000,10 +43334,11 @@
43000 ** An attempt to set a limit smaller than -1 is a no-op.
43001 */
43002 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){
43003 if( iLimit>=-1 ){
43004 pPager->journalSizeLimit = iLimit;
 
43005 }
43006 return pPager->journalSizeLimit;
43007 }
43008
43009 /*
@@ -43091,11 +43426,12 @@
43091 /* Open the connection to the log file. If this operation fails,
43092 ** (e.g. due to malloc() failure), return an error code.
43093 */
43094 if( rc==SQLITE_OK ){
43095 rc = sqlite3WalOpen(pPager->pVfs,
43096 pPager->fd, pPager->zWal, pPager->exclusiveMode, &pPager->pWal
 
43097 );
43098 }
43099
43100 return rc;
43101 }
@@ -43623,10 +43959,11 @@
43623 struct Wal {
43624 sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */
43625 sqlite3_file *pDbFd; /* File handle for the database file */
43626 sqlite3_file *pWalFd; /* File handle for WAL file */
43627 u32 iCallback; /* Value to pass to log callback (or 0) */
 
43628 int nWiData; /* Size of array apWiData */
43629 volatile u32 **apWiData; /* Pointer to wal-index content in memory */
43630 u32 szPage; /* Database page size */
43631 i16 readLock; /* Which read lock is being held. -1 for none */
43632 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
@@ -44445,10 +44782,11 @@
44445 SQLITE_PRIVATE int sqlite3WalOpen(
44446 sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
44447 sqlite3_file *pDbFd, /* The open database file */
44448 const char *zWalName, /* Name of the WAL file */
44449 int bNoShm, /* True to run in heap-memory mode */
 
44450 Wal **ppWal /* OUT: Allocated Wal handle */
44451 ){
44452 int rc; /* Return Code */
44453 Wal *pRet; /* Object to allocate and return */
44454 int flags; /* Flags passed to OsOpen() */
@@ -44477,10 +44815,11 @@
44477
44478 pRet->pVfs = pVfs;
44479 pRet->pWalFd = (sqlite3_file *)&pRet[1];
44480 pRet->pDbFd = pDbFd;
44481 pRet->readLock = -1;
 
44482 pRet->zWalName = zWalName;
44483 pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE);
44484
44485 /* Open file handle on the write-ahead log file. */
44486 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
@@ -44497,10 +44836,17 @@
44497 *ppWal = pRet;
44498 WALTRACE(("WAL%d: opened\n", pRet));
44499 }
44500 return rc;
44501 }
 
 
 
 
 
 
 
44502
44503 /*
44504 ** Find the smallest page number out of all pages held in the WAL that
44505 ** has not been returned by any prior invocation of this method on the
44506 ** same WalIterator object. Write into *piFrame the frame index where
@@ -45733,10 +46079,26 @@
45733 ** safe and means there is no special case for sqlite3WalUndo()
45734 ** to handle if this transaction is rolled back.
45735 */
45736 int i; /* Loop counter */
45737 u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45738 pWal->nCkpt++;
45739 pWal->hdr.mxFrame = 0;
45740 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
45741 aSalt[1] = salt1;
45742 walIndexWriteHdr(pWal);
@@ -47838,10 +48200,11 @@
47838 offset = PTRMAP_PTROFFSET(iPtrmap, key);
47839 if( offset<0 ){
47840 *pRC = SQLITE_CORRUPT_BKPT;
47841 goto ptrmap_exit;
47842 }
 
47843 pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
47844
47845 if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
47846 TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
47847 *pRC= rc = sqlite3PagerWrite(pDbPage);
@@ -47877,10 +48240,15 @@
47877 return rc;
47878 }
47879 pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
47880
47881 offset = PTRMAP_PTROFFSET(iPtrmap, key);
 
 
 
 
 
47882 assert( pEType!=0 );
47883 *pEType = pPtrmap[offset];
47884 if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);
47885
47886 sqlite3PagerUnref(pDbPage);
@@ -48738,17 +49106,17 @@
48738 ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
48739 ** objects in the same database connection since doing so will lead
48740 ** to problems with locking.
48741 */
48742 SQLITE_PRIVATE int sqlite3BtreeOpen(
 
48743 const char *zFilename, /* Name of the file containing the BTree database */
48744 sqlite3 *db, /* Associated database handle */
48745 Btree **ppBtree, /* Pointer to new Btree object written here */
48746 int flags, /* Options */
48747 int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */
48748 ){
48749 sqlite3_vfs *pVfs; /* The VFS to use for this btree */
48750 BtShared *pBt = 0; /* Shared part of btree structure */
48751 Btree *p; /* Handle to return */
48752 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
48753 int rc = SQLITE_OK; /* Result code from this function */
48754 u8 nReserve; /* Byte of unused space on each page */
@@ -48766,10 +49134,11 @@
48766 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
48767 || (isTempDb && sqlite3TempInMemory(db));
48768 #endif
48769
48770 assert( db!=0 );
 
48771 assert( sqlite3_mutex_held(db->mutex) );
48772 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
48773
48774 /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
48775 assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
@@ -48784,11 +49153,10 @@
48784 flags |= BTREE_MEMORY;
48785 }
48786 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
48787 vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
48788 }
48789 pVfs = db->pVfs;
48790 p = sqlite3MallocZero(sizeof(Btree));
48791 if( !p ){
48792 return SQLITE_NOMEM;
48793 }
48794 p->inTrans = TRANS_NONE;
@@ -58855,10 +59223,11 @@
58855 sqlite3_randomness(sizeof(iRandom), &iRandom);
58856 zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);
58857 if( !zMaster ){
58858 return SQLITE_NOMEM;
58859 }
 
58860 rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
58861 }while( rc==SQLITE_OK && res );
58862 if( rc==SQLITE_OK ){
58863 /* Open the master journal. */
58864 rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster,
@@ -59068,10 +59437,19 @@
59068 }
59069 }
59070 }
59071 db->nStatement--;
59072 p->iStatement = 0;
 
 
 
 
 
 
 
 
 
59073
59074 /* If the statement transaction is being rolled back, also restore the
59075 ** database handles deferred constraint counter to the value it had when
59076 ** the statement transaction was opened. */
59077 if( eOp==SAVEPOINT_ROLLBACK ){
@@ -62400,10 +62778,11 @@
62400 Mem *pIn2 = 0; /* 2nd input operand */
62401 Mem *pIn3 = 0; /* 3rd input operand */
62402 Mem *pOut = 0; /* Output operand */
62403 int iCompare = 0; /* Result of last OP_Compare operation */
62404 int *aPermute = 0; /* Permutation of columns for OP_Compare */
 
62405 #ifdef VDBE_PROFILE
62406 u64 start; /* CPU clock count at start of opcode */
62407 int origPc; /* Program counter at start of opcode */
62408 #endif
62409 /********************************************************************
@@ -63078,10 +63457,11 @@
63078 VdbeFrame *pFrame = p->pFrame;
63079 p->pFrame = pFrame->pParent;
63080 p->nFrame--;
63081 sqlite3VdbeSetChanges(db, p->nChange);
63082 pc = sqlite3VdbeFrameRestore(pFrame);
 
63083 if( pOp->p2==OE_Ignore ){
63084 /* Instruction pc is the OP_Program that invoked the sub-program
63085 ** currently being halted. If the p2 instruction of this OP_Halt
63086 ** instruction is set to OE_Ignore, then the sub-program is throwing
63087 ** an IGNORE exception. In this case jump to the address specified
@@ -63650,11 +64030,13 @@
63650 assert( pOp>aOp );
63651 assert( pOp[-1].p4type==P4_COLLSEQ );
63652 assert( pOp[-1].opcode==OP_CollSeq );
63653 u.ag.ctx.pColl = pOp[-1].p4.pColl;
63654 }
 
63655 (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
 
63656 if( db->mallocFailed ){
63657 /* Even though a malloc() has failed, the implementation of the
63658 ** user function may have called an sqlite3_result_XXX() function
63659 ** to return a value. The following call releases any resources
63660 ** associated with such a value.
@@ -64857,10 +65239,18 @@
64857 "SQL statements in progress");
64858 rc = SQLITE_BUSY;
64859 }else{
64860 u.aq.nName = sqlite3Strlen30(u.aq.zName);
64861
 
 
 
 
 
 
 
 
64862 /* Create a new savepoint structure. */
64863 u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
64864 if( u.aq.pNew ){
64865 u.aq.pNew->zName = (char *)&u.aq.pNew[1];
64866 memcpy(u.aq.pNew->zName, u.aq.zName, u.aq.nName+1);
@@ -64963,10 +65353,15 @@
64963 db->nSavepoint--;
64964 }
64965 }else{
64966 db->nDeferredCons = u.aq.pSavepoint->nDeferredCons;
64967 }
 
 
 
 
 
64968 }
64969 }
64970
64971 break;
64972 }
@@ -65102,11 +65497,15 @@
65102 if( p->iStatement==0 ){
65103 assert( db->nStatement>=0 && db->nSavepoint>=0 );
65104 db->nStatement++;
65105 p->iStatement = db->nSavepoint + db->nStatement;
65106 }
65107 rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
 
 
 
 
65108
65109 /* Store the current value of the database handles deferred constraint
65110 ** counter. If the statement transaction needs to be rolled back,
65111 ** the value of this counter needs to be restored too. */
65112 p->nStmtDefCons = db->nDeferredCons;
@@ -65423,11 +65822,11 @@
65423
65424 assert( pOp->p1>=0 );
65425 u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
65426 if( u.ax.pCx==0 ) goto no_mem;
65427 u.ax.pCx->nullRow = 1;
65428 rc = sqlite3BtreeOpen(0, db, &u.ax.pCx->pBt,
65429 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
65430 if( rc==SQLITE_OK ){
65431 rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1);
65432 }
65433 if( rc==SQLITE_OK ){
@@ -66097,11 +66496,11 @@
66097 ** engine starts picking positive candidate ROWIDs at random until
66098 ** it finds one that is not previously used. */
66099 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
66100 ** an AUTOINCREMENT table. */
66101 /* on the first attempt, simply do one more than previous */
66102 u.be.v = db->lastRowid;
66103 u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
66104 u.be.v++; /* ensure non-zero */
66105 u.be.cnt = 0;
66106 while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v,
66107 0, &u.be.res))==SQLITE_OK)
@@ -66209,11 +66608,11 @@
66209 assert( pOp->opcode==OP_InsertInt );
66210 u.bf.iKey = pOp->p3;
66211 }
66212
66213 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
66214 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = u.bf.iKey;
66215 if( u.bf.pData->flags & MEM_Null ){
66216 u.bf.pData->z = 0;
66217 u.bf.pData->n = 0;
66218 }else{
66219 assert( u.bf.pData->flags & (MEM_Blob|MEM_Str) );
@@ -67335,11 +67734,11 @@
67335 assert( pc==u.by.pFrame->pc );
67336 }
67337
67338 p->nFrame++;
67339 u.by.pFrame->pParent = p->pFrame;
67340 u.by.pFrame->lastRowid = db->lastRowid;
67341 u.by.pFrame->nChange = p->nChange;
67342 p->nChange = 0;
67343 p->pFrame = u.by.pFrame;
67344 p->aMem = aMem = &VdbeFrameMem(u.by.pFrame)[-1];
67345 p->nMem = u.by.pFrame->nChildMem;
@@ -68146,31 +68545,45 @@
68146 sqlite_int64 rowid;
68147 Mem **apArg;
68148 Mem *pX;
68149 #endif /* local variables moved into u.cm */
68150
 
 
 
68151 u.cm.pVtab = pOp->p4.pVtab->pVtab;
68152 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
68153 u.cm.nArg = pOp->p2;
68154 assert( pOp->p4type==P4_VTAB );
68155 if( ALWAYS(u.cm.pModule->xUpdate) ){
 
68156 u.cm.apArg = p->apArg;
68157 u.cm.pX = &aMem[pOp->p3];
68158 for(u.cm.i=0; u.cm.i<u.cm.nArg; u.cm.i++){
68159 assert( memIsValid(u.cm.pX) );
68160 memAboutToChange(p, u.cm.pX);
68161 sqlite3VdbeMemStoreType(u.cm.pX);
68162 u.cm.apArg[u.cm.i] = u.cm.pX;
68163 u.cm.pX++;
68164 }
 
68165 rc = u.cm.pModule->xUpdate(u.cm.pVtab, u.cm.nArg, u.cm.apArg, &u.cm.rowid);
 
68166 importVtabErrMsg(p, u.cm.pVtab);
68167 if( rc==SQLITE_OK && pOp->p1 ){
68168 assert( u.cm.nArg>1 && u.cm.apArg[0] && (u.cm.apArg[0]->flags&MEM_Null) );
68169 db->lastRowid = u.cm.rowid;
68170 }
68171 p->nChange++;
 
 
 
 
 
 
 
 
68172 }
68173 break;
68174 }
68175 #endif /* SQLITE_OMIT_VIRTUALTABLE */
68176
@@ -68316,10 +68729,11 @@
68316
68317 /* This is the only way out of this procedure. We have to
68318 ** release the mutexes on btrees that were acquired at the
68319 ** top. */
68320 vdbe_return:
 
68321 sqlite3VdbeLeave(p);
68322 return rc;
68323
68324 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
68325 ** is encountered.
@@ -76044,12 +76458,16 @@
76044 int i;
76045 int rc = 0;
76046 sqlite3 *db = sqlite3_context_db_handle(context);
76047 const char *zName;
76048 const char *zFile;
 
 
 
76049 Db *aNew;
76050 char *zErrDyn = 0;
 
76051
76052 UNUSED_PARAMETER(NotUsed);
76053
76054 zFile = (const char *)sqlite3_value_text(argv[0]);
76055 zName = (const char *)sqlite3_value_text(argv[1]);
@@ -76098,12 +76516,22 @@
76098
76099 /* Open the database file. If the btree is successfully opened, use
76100 ** it to obtain the database schema. At this point the schema may
76101 ** or may not be initialised.
76102 */
76103 rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,
76104 db->openFlags | SQLITE_OPEN_MAIN_DB);
 
 
 
 
 
 
 
 
 
 
76105 db->nDb++;
76106 if( rc==SQLITE_CONSTRAINT ){
76107 rc = SQLITE_ERROR;
76108 zErrDyn = sqlite3MPrintf(db, "database is already attached");
76109 }else if( rc==SQLITE_OK ){
@@ -80213,11 +80641,11 @@
80213 SQLITE_OPEN_CREATE |
80214 SQLITE_OPEN_EXCLUSIVE |
80215 SQLITE_OPEN_DELETEONCLOSE |
80216 SQLITE_OPEN_TEMP_DB;
80217
80218 rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags);
80219 if( rc!=SQLITE_OK ){
80220 sqlite3ErrorMsg(pParse, "unable to open a temporary database "
80221 "file for storing temporary tables");
80222 pParse->rc = rc;
80223 return 1;
@@ -85399,10 +85827,11 @@
85399 #ifndef SQLITE_OMIT_VIRTUALTABLE
85400 if( IsVirtual(pTab) ){
85401 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
85402 sqlite3VtabMakeWritable(pParse, pTab);
85403 sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB);
 
85404 sqlite3MayAbort(pParse);
85405 }else
85406 #endif
85407 {
85408 int isReplace; /* Set to true if constraints may cause a replace */
@@ -87544,11 +87973,11 @@
87544 }
87545
87546 /*
87547 ** Interpret the given string as a boolean value.
87548 */
87549 static u8 getBoolean(const char *z){
87550 return getSafetyLevel(z)&1;
87551 }
87552
87553 /*
87554 ** Interpret the given string as a locking mode value.
@@ -87714,11 +88143,11 @@
87714 /* Foreign key support may not be enabled or disabled while not
87715 ** in auto-commit mode. */
87716 mask &= ~(SQLITE_ForeignKeys);
87717 }
87718
87719 if( getBoolean(zRight) ){
87720 db->flags |= mask;
87721 }else{
87722 db->flags &= ~mask;
87723 }
87724
@@ -87928,11 +88357,11 @@
87928 if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
87929 Btree *pBt = pDb->pBt;
87930 int b = -1;
87931 assert( pBt!=0 );
87932 if( zRight ){
87933 b = getBoolean(zRight);
87934 }
87935 if( pId2->n==0 && b>=0 ){
87936 int ii;
87937 for(ii=0; ii<db->nDb; ii++){
87938 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
@@ -88528,11 +88957,11 @@
88528 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
88529
88530 #ifndef NDEBUG
88531 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
88532 if( zRight ){
88533 if( getBoolean(zRight) ){
88534 sqlite3ParserTrace(stderr, "parser: ");
88535 }else{
88536 sqlite3ParserTrace(0, 0);
88537 }
88538 }
@@ -88542,11 +88971,11 @@
88542 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
88543 ** used will be case sensitive or not depending on the RHS.
88544 */
88545 if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
88546 if( zRight ){
88547 sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
88548 }
88549 }else
88550
88551 #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
88552 # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
@@ -95683,11 +96112,12 @@
95683 SrcList *pSrc, /* The virtual table to be modified */
95684 Table *pTab, /* The virtual table */
95685 ExprList *pChanges, /* The columns to change in the UPDATE statement */
95686 Expr *pRowidExpr, /* Expression used to recompute the rowid */
95687 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
95688 Expr *pWhere /* WHERE clause of the UPDATE statement */
 
95689 );
95690 #endif /* SQLITE_OMIT_VIRTUALTABLE */
95691
95692 /*
95693 ** The most recently coded instruction was an OP_Column to retrieve the
@@ -95927,11 +96357,11 @@
95927
95928 #ifndef SQLITE_OMIT_VIRTUALTABLE
95929 /* Virtual tables must be handled separately */
95930 if( IsVirtual(pTab) ){
95931 updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
95932 pWhere);
95933 pWhere = 0;
95934 pTabList = 0;
95935 goto update_cleanup;
95936 }
95937 #endif
@@ -96257,11 +96687,12 @@
96257 SrcList *pSrc, /* The virtual table to be modified */
96258 Table *pTab, /* The virtual table */
96259 ExprList *pChanges, /* The columns to change in the UPDATE statement */
96260 Expr *pRowid, /* Expression used to recompute the rowid */
96261 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
96262 Expr *pWhere /* WHERE clause of the UPDATE statement */
 
96263 ){
96264 Vdbe *v = pParse->pVdbe; /* Virtual machine under construction */
96265 ExprList *pEList = 0; /* The result set of the SELECT statement */
96266 Select *pSelect = 0; /* The SELECT statement */
96267 Expr *pExpr; /* Temporary expression */
@@ -96314,10 +96745,11 @@
96314 for(i=0; i<pTab->nCol; i++){
96315 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
96316 }
96317 sqlite3VtabMakeWritable(pParse, pTab);
96318 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
 
96319 sqlite3MayAbort(pParse);
96320 sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
96321 sqlite3VdbeJumpHere(v, addr);
96322 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
96323
@@ -96687,10 +97119,22 @@
96687 *************************************************************************
96688 ** This file contains code used to help implement virtual tables.
96689 */
96690 #ifndef SQLITE_OMIT_VIRTUALTABLE
96691
 
 
 
 
 
 
 
 
 
 
 
 
96692 /*
96693 ** The actual function that does the work of creating a new module.
96694 ** This function implements the sqlite3_create_module() and
96695 ** sqlite3_create_module_v2() interfaces.
96696 */
@@ -96715,17 +97159,17 @@
96715 pMod->pModule = pModule;
96716 pMod->pAux = pAux;
96717 pMod->xDestroy = xDestroy;
96718 pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
96719 if( pDel && pDel->xDestroy ){
 
96720 pDel->xDestroy(pDel->pAux);
96721 }
96722 sqlite3DbFree(db, pDel);
96723 if( pDel==pMod ){
96724 db->mallocFailed = 1;
96725 }
96726 sqlite3ResetInternalSchema(db, -1);
96727 }else if( xDestroy ){
96728 xDestroy(pAux);
96729 }
96730 rc = sqlite3ApiExit(db, SQLITE_OK);
96731 sqlite3_mutex_leave(db->mutex);
@@ -97107,10 +97551,11 @@
97107 Table *pTab,
97108 Module *pMod,
97109 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
97110 char **pzErr
97111 ){
 
97112 VTable *pVTable;
97113 int rc;
97114 const char *const*azArg = (const char *const*)pTab->azModuleArg;
97115 int nArg = pTab->nModuleArg;
97116 char *zErr = 0;
@@ -97126,16 +97571,18 @@
97126 return SQLITE_NOMEM;
97127 }
97128 pVTable->db = db;
97129 pVTable->pMod = pMod;
97130
97131 assert( !db->pVTab );
 
97132 assert( xConstruct );
97133 db->pVTab = pTab;
97134
97135 /* Invoke the virtual table constructor */
97136 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
 
97137 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
97138
97139 if( SQLITE_OK!=rc ){
97140 if( zErr==0 ){
97141 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
@@ -97147,11 +97594,11 @@
97147 }else if( ALWAYS(pVTable->pVtab) ){
97148 /* Justification of ALWAYS(): A correct vtab constructor must allocate
97149 ** the sqlite3_vtab object if successful. */
97150 pVTable->pVtab->pModule = pMod->pModule;
97151 pVTable->nRef = 1;
97152 if( db->pVTab ){
97153 const char *zFormat = "vtable constructor did not declare schema: %s";
97154 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
97155 sqlite3VtabUnlock(pVTable);
97156 rc = SQLITE_ERROR;
97157 }else{
@@ -97195,11 +97642,10 @@
97195 }
97196 }
97197 }
97198
97199 sqlite3DbFree(db, zModuleName);
97200 db->pVTab = 0;
97201 return rc;
97202 }
97203
97204 /*
97205 ** This function is invoked by the parser to call the xConnect() method
@@ -97315,12 +97761,11 @@
97315 int rc = SQLITE_OK;
97316 Table *pTab;
97317 char *zErr = 0;
97318
97319 sqlite3_mutex_enter(db->mutex);
97320 pTab = db->pVTab;
97321 if( !pTab ){
97322 sqlite3Error(db, SQLITE_MISUSE, 0);
97323 sqlite3_mutex_leave(db->mutex);
97324 return SQLITE_MISUSE_BKPT;
97325 }
97326 assert( (pTab->tabFlags & TF_Virtual)!=0 );
@@ -97343,11 +97788,11 @@
97343 pTab->aCol = pParse->pNewTable->aCol;
97344 pTab->nCol = pParse->pNewTable->nCol;
97345 pParse->pNewTable->nCol = 0;
97346 pParse->pNewTable->aCol = 0;
97347 }
97348 db->pVTab = 0;
97349 }else{
97350 sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
97351 sqlite3DbFree(db, zErr);
97352 rc = SQLITE_ERROR;
97353 }
@@ -97495,11 +97940,10 @@
97495 pModule = pVTab->pVtab->pModule;
97496
97497 if( pModule->xBegin ){
97498 int i;
97499
97500
97501 /* If pVtab is already in the aVTrans array, return early */
97502 for(i=0; i<db->nVTrans; i++){
97503 if( db->aVTrans[i]==pVTab ){
97504 return SQLITE_OK;
97505 }
@@ -97508,10 +97952,53 @@
97508 /* Invoke the xBegin method */
97509 rc = pModule->xBegin(pVTab->pVtab);
97510 if( rc==SQLITE_OK ){
97511 rc = addToVTrans(db, pVTab);
97512 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97513 }
97514 return rc;
97515 }
97516
97517 /*
@@ -97609,10 +98096,61 @@
97609 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
97610 }else{
97611 pToplevel->db->mallocFailed = 1;
97612 }
97613 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97614
97615 #endif /* SQLITE_OMIT_VIRTUALTABLE */
97616
97617 /************** End of vtab.c ************************************************/
97618 /************** Begin file where.c *******************************************/
@@ -107631,10 +108169,15 @@
107631 typedef void(*LOGFUNC_t)(void*,int,const char*);
107632 sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
107633 sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
107634 break;
107635 }
 
 
 
 
 
107636
107637 default: {
107638 rc = SQLITE_ERROR;
107639 break;
107640 }
@@ -108990,25 +109533,257 @@
108990 }
108991 db->aLimit[limitId] = newLimit;
108992 }
108993 return oldLimit; /* IMP: R-53341-35419 */
108994 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108995
108996 /*
108997 ** This routine does the work of opening a database on behalf of
108998 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
108999 ** is UTF-8 encoded.
109000 */
109001 static int openDatabase(
109002 const char *zFilename, /* Database filename UTF-8 encoded */
109003 sqlite3 **ppDb, /* OUT: Returned database handle */
109004 unsigned flags, /* Operational flags */
109005 const char *zVfs /* Name of the VFS to use */
109006 ){
109007 sqlite3 *db;
109008 int rc;
109009 int isThreadsafe;
 
 
109010
109011 *ppDb = 0;
109012 #ifndef SQLITE_OMIT_AUTOINIT
109013 rc = sqlite3_initialize();
109014 if( rc ) return rc;
@@ -109028,11 +109803,11 @@
109028 assert( SQLITE_OPEN_READWRITE == 0x02 );
109029 assert( SQLITE_OPEN_CREATE == 0x04 );
109030 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
109031 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
109032 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
109033 if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE;
109034
109035 if( sqlite3GlobalConfig.bCoreMutex==0 ){
109036 isThreadsafe = 0;
109037 }else if( flags & SQLITE_OPEN_NOMUTEX ){
109038 isThreadsafe = 0;
@@ -109109,17 +109884,10 @@
109109 sqlite3HashInit(&db->aCollSeq);
109110 #ifndef SQLITE_OMIT_VIRTUALTABLE
109111 sqlite3HashInit(&db->aModule);
109112 #endif
109113
109114 db->pVfs = sqlite3_vfs_find(zVfs);
109115 if( !db->pVfs ){
109116 rc = SQLITE_ERROR;
109117 sqlite3Error(db, rc, "no such vfs: %s", zVfs);
109118 goto opendb_out;
109119 }
109120
109121 /* Add the default collation sequence BINARY. BINARY works for both UTF-8
109122 ** and UTF-16, so add a version for each to avoid any unnecessary
109123 ** conversions. The only error that can occur here is a malloc() failure.
109124 */
109125 createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0,
@@ -109138,13 +109906,22 @@
109138
109139 /* Also add a UTF-8 case-insensitive collation sequence. */
109140 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
109141 nocaseCollatingFunc, 0);
109142
109143 /* Open the backend database driver */
109144 db->openFlags = flags;
109145 rc = sqlite3BtreeOpen(zFilename, db, &db->aDb[0].pBt, 0,
 
 
 
 
 
 
 
 
 
109146 flags | SQLITE_OPEN_MAIN_DB);
109147 if( rc!=SQLITE_OK ){
109148 if( rc==SQLITE_IOERR_NOMEM ){
109149 rc = SQLITE_NOMEM;
109150 }
@@ -109233,10 +110010,11 @@
109233 sqlite3GlobalConfig.nLookaside);
109234
109235 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
109236
109237 opendb_out:
 
109238 if( db ){
109239 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
109240 sqlite3_mutex_leave(db->mutex);
109241 }
109242 rc = sqlite3_errcode(db);
@@ -109264,11 +110042,11 @@
109264 const char *filename, /* Database filename (UTF-8) */
109265 sqlite3 **ppDb, /* OUT: SQLite db handle */
109266 int flags, /* Flags */
109267 const char *zVfs /* Name of VFS module to use */
109268 ){
109269 return openDatabase(filename, ppDb, flags, zVfs);
109270 }
109271
109272 #ifndef SQLITE_OMIT_UTF16
109273 /*
109274 ** Open a new database handle.
@@ -109874,10 +110652,32 @@
109874 }
109875 va_end(ap);
109876 #endif /* SQLITE_OMIT_BUILTIN_TEST */
109877 return rc;
109878 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109879
109880 /************** End of main.c ************************************************/
109881 /************** Begin file notify.c ******************************************/
109882 /*
109883 ** 2009 March 3
@@ -110955,10 +111755,11 @@
110955 Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */
110956 sqlite3_int64 iPrevId; /* Previous id read from aDoclist */
110957 char *pNextId; /* Pointer into the body of aDoclist */
110958 char *aDoclist; /* List of docids for full-text queries */
110959 int nDoclist; /* Size of buffer at aDoclist */
 
110960 int eEvalmode; /* An FTS3_EVAL_XX constant */
110961 int nRowAvg; /* Average size of database rows, in pages */
110962
110963 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
110964 u32 *aMatchinfo; /* Information about most recent match */
@@ -111137,11 +111938,11 @@
111137 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
111138 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
111139 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
111140 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
111141
111142 SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Expr *, sqlite3_int64, int);
111143 SQLITE_PRIVATE int sqlite3Fts3ExprLoadDoclist(Fts3Cursor *, Fts3Expr *);
111144 SQLITE_PRIVATE int sqlite3Fts3ExprLoadFtDoclist(Fts3Cursor *, Fts3Expr *, char **, int *);
111145 SQLITE_PRIVATE int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int);
111146
111147 /* fts3_tokenizer.c */
@@ -111164,10 +111965,11 @@
111164 char **, int, int, const char *, int, Fts3Expr **
111165 );
111166 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
111167 #ifdef SQLITE_TEST
111168 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
 
111169 #endif
111170
111171 /* fts3_aux.c */
111172 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
111173
@@ -111284,10 +112086,38 @@
111284 static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
111285 sqlite3_int64 iVal;
111286 *pp += sqlite3Fts3GetVarint(*pp, &iVal);
111287 *pVal += iVal;
111288 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111289
111290 /*
111291 ** As long as *pp has not reached its end (pEnd), then do the same
111292 ** as fts3GetDeltaVarint(): read a single varint and add it to *pVal.
111293 ** But if we have reached the end of the varint, just set *pp=0 and
@@ -111389,10 +112219,12 @@
111389 if( *pRc==SQLITE_OK ){
111390 int i; /* Iterator variable */
111391 int rc; /* Return code */
111392 char *zSql; /* SQL statement passed to declare_vtab() */
111393 char *zCols; /* List of user defined columns */
 
 
111394
111395 /* Create a list of user columns for the virtual table */
111396 zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]);
111397 for(i=1; zCols && i<p->nColumn; i++){
111398 zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]);
@@ -111958,10 +112790,26 @@
111958
111959 if( iCons>=0 ){
111960 pInfo->aConstraintUsage[iCons].argvIndex = 1;
111961 pInfo->aConstraintUsage[iCons].omit = 1;
111962 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111963 return SQLITE_OK;
111964 }
111965
111966 /*
111967 ** Implementation of xOpen method.
@@ -112015,11 +112863,11 @@
112015 if( rc==SQLITE_OK ){
112016 /* If no row was found and no error has occured, then the %_content
112017 ** table is missing a row that is present in the full-text index.
112018 ** The data structures are corrupt.
112019 */
112020 rc = SQLITE_CORRUPT;
112021 }
112022 pCsr->isEof = 1;
112023 if( pContext ){
112024 sqlite3_result_error_code(pContext, rc);
112025 }
@@ -112075,11 +112923,11 @@
112075 ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
112076 */
112077 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
112078 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
112079 if( zCsr>zEnd ){
112080 return SQLITE_CORRUPT;
112081 }
112082
112083 while( zCsr<zEnd && (piFirst || piLast) ){
112084 int cmp; /* memcmp() result */
112085 int nSuffix; /* Size of term suffix */
@@ -112093,11 +112941,11 @@
112093 }
112094 isFirstTerm = 0;
112095 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
112096
112097 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
112098 rc = SQLITE_CORRUPT;
112099 goto finish_scan;
112100 }
112101 if( nPrefix+nSuffix>nAlloc ){
112102 char *zNew;
112103 nAlloc = (nPrefix+nSuffix) * 2;
@@ -113862,16 +114710,24 @@
113862 rc = sqlite3_reset(pCsr->pStmt);
113863 break;
113864 }
113865 pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
113866 }else{
113867 if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){
113868 pCsr->isEof = 1;
113869 break;
 
 
 
 
 
 
 
 
 
113870 }
113871 sqlite3_reset(pCsr->pStmt);
113872 fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId);
113873 pCsr->isRequireSeek = 1;
113874 pCsr->isMatchinfoNeeded = 1;
113875 }
113876 }while( SQLITE_OK==(rc = fts3EvalDeferred(pCsr, &res)) && res==0 );
113877
@@ -113900,12 +114756,12 @@
113900 const char *idxStr, /* Unused */
113901 int nVal, /* Number of elements in apVal */
113902 sqlite3_value **apVal /* Arguments for the indexing scheme */
113903 ){
113904 const char *azSql[] = {
113905 "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */
113906 "SELECT %s FROM %Q.'%q_content' AS x ", /* full-scan */
113907 };
113908 int rc; /* Return code */
113909 char *zSql; /* SQL statement used to access %_content */
113910 Fts3Table *p = (Fts3Table *)pCursor->pVtab;
113911 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
@@ -113957,11 +114813,13 @@
113957 ** statement loops through all rows of the %_content table. For a
113958 ** full-text query or docid lookup, the statement retrieves a single
113959 ** row by docid.
113960 */
113961 zSql = (char *)azSql[idxNum==FTS3_FULLSCAN_SEARCH];
113962 zSql = sqlite3_mprintf(zSql, p->zReadExprlist, p->zDb, p->zName);
 
 
113963 if( !zSql ){
113964 rc = SQLITE_NOMEM;
113965 }else{
113966 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
113967 sqlite3_free(zSql);
@@ -113969,11 +114827,26 @@
113969 if( rc==SQLITE_OK && idxNum==FTS3_DOCID_SEARCH ){
113970 rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]);
113971 }
113972 pCsr->eSearch = (i16)idxNum;
113973
 
113974 if( rc!=SQLITE_OK ) return rc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113975 return fts3NextMethod(pCursor);
113976 }
113977
113978 /*
113979 ** This is the xEof method of the virtual table. SQLite calls this
@@ -114121,17 +114994,37 @@
114121 pCsr->eEvalmode = FTS3_EVAL_MATCHINFO;
114122 rc = fts3EvalExpr(pCsr, pExpr, paDoclist, pnDoclist, 1);
114123 pCsr->eEvalmode = FTS3_EVAL_NEXT;
114124 return rc;
114125 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114126
114127 /*
114128 ** After ExprLoadDoclist() (see above) has been called, this function is
114129 ** used to iterate/search through the position lists that make up the doclist
114130 ** stored in pExpr->aDoclist.
114131 */
114132 SQLITE_PRIVATE char *sqlite3Fts3FindPositions(
 
114133 Fts3Expr *pExpr, /* Access this expressions doclist */
114134 sqlite3_int64 iDocid, /* Docid associated with requested pos-list */
114135 int iCol /* Column of requested pos-list */
114136 ){
114137 assert( pExpr->isLoaded );
@@ -114138,23 +115031,39 @@
114138 if( pExpr->aDoclist ){
114139 char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
114140 char *pCsr;
114141
114142 if( pExpr->pCurrent==0 ){
114143 pExpr->pCurrent = pExpr->aDoclist;
114144 pExpr->iCurrent = 0;
114145 pExpr->pCurrent += sqlite3Fts3GetVarint(pExpr->pCurrent,&pExpr->iCurrent);
 
 
 
 
 
 
 
 
 
 
114146 }
114147 pCsr = pExpr->pCurrent;
114148 assert( pCsr );
114149
114150 while( pCsr<pEnd ){
114151 if( pExpr->iCurrent<iDocid ){
 
 
114152 fts3PoslistCopy(0, &pCsr);
114153 if( pCsr<pEnd ){
114154 fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
114155 }
 
 
 
 
114156 pExpr->pCurrent = pCsr;
114157 }else{
114158 if( pExpr->iCurrent==iDocid ){
114159 int iThis = 0;
114160 if( iCol<0 ){
@@ -114407,13 +115316,24 @@
114407 "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';",
114408 p->zDb, p->zName, zName
114409 );
114410 return rc;
114411 }
 
 
 
 
 
 
 
 
 
 
 
114412
114413 static const sqlite3_module fts3Module = {
114414 /* iVersion */ 0,
114415 /* xCreate */ fts3CreateMethod,
114416 /* xConnect */ fts3ConnectMethod,
114417 /* xBestIndex */ fts3BestIndexMethod,
114418 /* xDisconnect */ fts3DisconnectMethod,
114419 /* xDestroy */ fts3DestroyMethod,
@@ -114429,10 +115349,13 @@
114429 /* xSync */ fts3SyncMethod,
114430 /* xCommit */ fts3CommitMethod,
114431 /* xRollback */ fts3RollbackMethod,
114432 /* xFindFunction */ fts3FindFunctionMethod,
114433 /* xRename */ fts3RenameMethod,
 
 
 
114434 };
114435
114436 /*
114437 ** This function is registered as the module destructor (called when an
114438 ** FTS3 enabled database connection is closed). It frees the memory
@@ -114474,10 +115397,15 @@
114474
114475 #ifdef SQLITE_ENABLE_ICU
114476 const sqlite3_tokenizer_module *pIcu = 0;
114477 sqlite3Fts3IcuTokenizerModule(&pIcu);
114478 #endif
 
 
 
 
 
114479
114480 rc = sqlite3Fts3InitAux(db);
114481 if( rc!=SQLITE_OK ) return rc;
114482
114483 sqlite3Fts3SimpleTokenizerModule(&pSimple);
@@ -117995,11 +118923,11 @@
117995 sqlite3_bind_int64(pStmt, 1, iDocid);
117996 }
117997 rc = sqlite3_step(pStmt);
117998 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
117999 rc = sqlite3_reset(pStmt);
118000 if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT;
118001 pStmt = 0;
118002 }else{
118003 rc = SQLITE_OK;
118004 }
118005 }
@@ -118451,18 +119379,18 @@
118451 ** full-text index.
118452 */
118453 static void fts3DeleteTerms(
118454 int *pRC, /* Result code */
118455 Fts3Table *p, /* The FTS table to delete from */
118456 sqlite3_value **apVal, /* apVal[] contains the docid to be deleted */
118457 u32 *aSz /* Sizes of deleted document written here */
118458 ){
118459 int rc;
118460 sqlite3_stmt *pSelect;
118461
118462 if( *pRC ) return;
118463 rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, apVal);
118464 if( rc==SQLITE_OK ){
118465 if( SQLITE_ROW==sqlite3_step(pSelect) ){
118466 int i;
118467 for(i=1; i<=p->nColumn; i++){
118468 const char *zText = (const char *)sqlite3_column_text(pSelect, i);
@@ -118676,11 +119604,11 @@
118676 pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
118677 pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
118678 if( nPrefix<0 || nSuffix<=0
118679 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
118680 ){
118681 return SQLITE_CORRUPT;
118682 }
118683
118684 if( nPrefix+nSuffix>pReader->nTermAlloc ){
118685 int nNew = (nPrefix+nSuffix)*2;
118686 char *zNew = sqlite3_realloc(pReader->zTerm, nNew);
@@ -118702,11 +119630,11 @@
118702 ** of these statements is untrue, then the data structure is corrupt.
118703 */
118704 if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode]
118705 || pReader->aDoclist[pReader->nDoclist-1]
118706 ){
118707 return SQLITE_CORRUPT;
118708 }
118709 return SQLITE_OK;
118710 }
118711
118712 /*
@@ -118827,11 +119755,11 @@
118827 while( a<pEnd ){
118828 a += sqlite3Fts3GetVarint(a, &nByte);
118829 }
118830 if( nDoc==0 || nByte==0 ){
118831 sqlite3_reset(pStmt);
118832 return SQLITE_CORRUPT;
118833 }
118834
118835 pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
118836 assert( pCsr->nRowAvg>0 );
118837 rc = sqlite3_reset(pStmt);
@@ -119598,20 +120526,20 @@
119598
119599 /*
119600 ** The first value in the apVal[] array is assumed to contain an integer.
119601 ** This function tests if there exist any documents with docid values that
119602 ** are different from that integer. i.e. if deleting the document with docid
119603 ** apVal[0] would mean the FTS3 table were empty.
119604 **
119605 ** If successful, *pisEmpty is set to true if the table is empty except for
119606 ** document apVal[0], or false otherwise, and SQLITE_OK is returned. If an
119607 ** error occurs, an SQLite error code is returned.
119608 */
119609 static int fts3IsEmpty(Fts3Table *p, sqlite3_value **apVal, int *pisEmpty){
119610 sqlite3_stmt *pStmt;
119611 int rc;
119612 rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, apVal);
119613 if( rc==SQLITE_OK ){
119614 if( SQLITE_ROW==sqlite3_step(pStmt) ){
119615 *pisEmpty = sqlite3_column_int(pStmt, 0);
119616 }
119617 rc = sqlite3_reset(pStmt);
@@ -120331,10 +121259,44 @@
120331 pToken->pDeferred = pDeferred;
120332
120333 return SQLITE_OK;
120334 }
120335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120336
120337 /*
120338 ** This function does the work for the xUpdate method of FTS3 virtual
120339 ** tables.
120340 */
@@ -120349,50 +121311,95 @@
120349 int isRemove = 0; /* True for an UPDATE or DELETE */
120350 sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */
120351 u32 *aSzIns; /* Sizes of inserted documents */
120352 u32 *aSzDel; /* Sizes of deleted documents */
120353 int nChng = 0; /* Net change in number of documents */
 
120354
120355 assert( p->pSegments==0 );
 
 
 
 
 
 
 
 
 
 
 
120356
120357 /* Allocate space to hold the change in document sizes */
120358 aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 );
120359 if( aSzIns==0 ) return SQLITE_NOMEM;
120360 aSzDel = &aSzIns[p->nColumn+1];
120361 memset(aSzIns, 0, sizeof(aSzIns[0])*(p->nColumn+1)*2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120362
120363 /* If this is a DELETE or UPDATE operation, remove the old record. */
120364 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
120365 int isEmpty = 0;
120366 rc = fts3IsEmpty(p, apVal, &isEmpty);
120367 if( rc==SQLITE_OK ){
120368 if( isEmpty ){
120369 /* Deleting this row means the whole table is empty. In this case
120370 ** delete the contents of all three tables and throw away any
120371 ** data in the pendingTerms hash table.
120372 */
120373 rc = fts3DeleteAll(p);
120374 }else{
120375 isRemove = 1;
120376 iRemove = sqlite3_value_int64(apVal[0]);
120377 rc = fts3PendingTermsDocid(p, iRemove);
120378 fts3DeleteTerms(&rc, p, apVal, aSzDel);
120379 fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, apVal);
120380 if( p->bHasDocsize ){
120381 fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, apVal);
120382 }
120383 nChng--;
120384 }
120385 }
120386 }else if( sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL ){
120387 sqlite3_free(aSzIns);
120388 return fts3SpecialInsert(p, apVal[p->nColumn+2]);
120389 }
120390
120391 /* If this is an INSERT or UPDATE operation, insert the new record. */
120392 if( nArg>1 && rc==SQLITE_OK ){
120393 rc = fts3InsertData(p, apVal, pRowid);
 
 
 
120394 if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){
120395 rc = fts3PendingTermsDocid(p, *pRowid);
120396 }
120397 if( rc==SQLITE_OK ){
120398 rc = fts3InsertTerms(p, apVal, aSzIns);
@@ -120852,11 +121859,11 @@
120852 SnippetPhrase *pPhrase = &p->aPhrase[iPhrase];
120853 char *pCsr;
120854
120855 pPhrase->nToken = pExpr->pPhrase->nToken;
120856
120857 pCsr = sqlite3Fts3FindPositions(pExpr, p->pCsr->iPrevId, p->iCol);
120858 if( pCsr ){
120859 int iFirst = 0;
120860 pPhrase->pList = pCsr;
120861 fts3GetDeltaPosition(&pCsr, &iFirst);
120862 pPhrase->pHead = pCsr;
@@ -121325,11 +122332,11 @@
121325 for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0;
121326
121327 if( pExpr->aDoclist ){
121328 char *pCsr;
121329
121330 pCsr = sqlite3Fts3FindPositions(pExpr, p->pCursor->iPrevId, -1);
121331 if( pCsr ){
121332 fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0);
121333 }
121334 }
121335
@@ -121397,11 +122404,11 @@
121397 pStmt = *ppStmt;
121398 assert( sqlite3_data_count(pStmt)==1 );
121399
121400 a = sqlite3_column_blob(pStmt, 0);
121401 a += sqlite3Fts3GetVarint(a, &nDoc);
121402 if( nDoc==0 ) return SQLITE_CORRUPT;
121403 *pnDoc = (u32)nDoc;
121404
121405 if( paLen ) *paLen = a;
121406 return SQLITE_OK;
121407 }
@@ -121492,11 +122499,11 @@
121492 (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
121493 for(i=0; i<pInfo->nPhrase; i++){
121494 LcsIterator *pIter = &aIter[i];
121495 nToken -= pIter->pExpr->pPhrase->nToken;
121496 pIter->iPosOffset = nToken;
121497 pIter->pRead = sqlite3Fts3FindPositions(pIter->pExpr, pCsr->iPrevId, -1);
121498 if( pIter->pRead ){
121499 pIter->iPos = pIter->iPosOffset;
121500 fts3LcsIteratorAdvance(&aIter[i]);
121501 }else{
121502 pIter->iCol = LCS_ITERATOR_FINISHED;
@@ -121845,10 +122852,11 @@
121845 int iPos; /* Position just read from pList */
121846 int iOff; /* Offset of this term from read positions */
121847 };
121848
121849 struct TermOffsetCtx {
 
121850 int iCol; /* Column of table to populate aTerm for */
121851 int iTerm;
121852 sqlite3_int64 iDocid;
121853 TermOffset *aTerm;
121854 };
@@ -121862,11 +122870,11 @@
121862 int iTerm; /* For looping through nTerm phrase terms */
121863 char *pList; /* Pointer to position list for phrase */
121864 int iPos = 0; /* First position in position-list */
121865
121866 UNUSED_PARAMETER(iPhrase);
121867 pList = sqlite3Fts3FindPositions(pExpr, p->iDocid, p->iCol);
121868 nTerm = pExpr->pPhrase->nToken;
121869 if( pList ){
121870 fts3GetDeltaPosition(&pList, &iPos);
121871 assert( iPos>=0 );
121872 }
@@ -121915,10 +122923,11 @@
121915 if( 0==sCtx.aTerm ){
121916 rc = SQLITE_NOMEM;
121917 goto offsets_out;
121918 }
121919 sCtx.iDocid = pCsr->iPrevId;
 
121920
121921 /* Loop through the table columns, appending offset information to
121922 ** string-buffer res for each column.
121923 */
121924 for(iCol=0; iCol<pTab->nColumn; iCol++){
@@ -121990,11 +122999,11 @@
121990 sqlite3_snprintf(sizeof(aBuffer), aBuffer,
121991 "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
121992 );
121993 rc = fts3StringAppend(&res, aBuffer, -1);
121994 }else if( rc==SQLITE_DONE ){
121995 rc = SQLITE_CORRUPT;
121996 }
121997 }
121998 }
121999 if( rc==SQLITE_DONE ){
122000 rc = SQLITE_OK;
@@ -122578,29 +123587,29 @@
122578 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
122579 */
122580 if( pNode && iNode==1 ){
122581 pRtree->iDepth = readInt16(pNode->zData);
122582 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
122583 rc = SQLITE_CORRUPT;
122584 }
122585 }
122586
122587 /* If no error has occurred so far, check if the "number of entries"
122588 ** field on the node is too large. If so, set the return code to
122589 ** SQLITE_CORRUPT.
122590 */
122591 if( pNode && rc==SQLITE_OK ){
122592 if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
122593 rc = SQLITE_CORRUPT;
122594 }
122595 }
122596
122597 if( rc==SQLITE_OK ){
122598 if( pNode!=0 ){
122599 nodeHashInsert(pRtree, pNode);
122600 }else{
122601 rc = SQLITE_CORRUPT;
122602 }
122603 *ppNode = pNode;
122604 }else{
122605 sqlite3_free(pNode);
122606 *ppNode = 0;
@@ -123123,11 +124132,11 @@
123123 if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
123124 *piIndex = ii;
123125 return SQLITE_OK;
123126 }
123127 }
123128 return SQLITE_CORRUPT;
123129 }
123130
123131 /*
123132 ** Return the index of the cell containing a pointer to node pNode
123133 ** in its parent. If pNode is the root node, return -1.
@@ -123718,11 +124727,11 @@
123718 RtreeNode *pParent = p->pParent;
123719 RtreeCell cell;
123720 int iCell;
123721
123722 if( nodeParentIndex(pRtree, p, &iCell) ){
123723 return SQLITE_CORRUPT;
123724 }
123725
123726 nodeGetCell(pRtree, pParent, iCell, &cell);
123727 if( !cellContains(pRtree, &cell, pCell) ){
123728 cellUnion(pRtree, &cell, pCell);
@@ -124390,11 +125399,11 @@
124390 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
124391 }
124392 }
124393 rc = sqlite3_reset(pRtree->pReadParent);
124394 if( rc==SQLITE_OK ) rc = rc2;
124395 if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT;
124396 pChild = pChild->pParent;
124397 }
124398 return rc;
124399 }
124400
@@ -124685,10 +125694,94 @@
124685 sqlite3_step(pRtree->pWriteRowid);
124686 rc = sqlite3_reset(pRtree->pWriteRowid);
124687 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
124688 return rc;
124689 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124690
124691 /*
124692 ** The xUpdate method for rtree module virtual tables.
124693 */
124694 static int rtreeUpdate(
@@ -124697,107 +125790,29 @@
124697 sqlite3_value **azData,
124698 sqlite_int64 *pRowid
124699 ){
124700 Rtree *pRtree = (Rtree *)pVtab;
124701 int rc = SQLITE_OK;
 
 
124702
124703 rtreeReference(pRtree);
124704
124705 assert(nData>=1);
124706
124707 /* If azData[0] is not an SQL NULL value, it is the rowid of a
124708 ** record to delete from the r-tree table. The following block does
124709 ** just that.
124710 */
124711 if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){
124712 i64 iDelete; /* The rowid to delete */
124713 RtreeNode *pLeaf; /* Leaf node containing record iDelete */
124714 int iCell; /* Index of iDelete cell in pLeaf */
124715 RtreeNode *pRoot;
124716
124717 /* Obtain a reference to the root node to initialise Rtree.iDepth */
124718 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
124719
124720 /* Obtain a reference to the leaf node that contains the entry
124721 ** about to be deleted.
124722 */
124723 if( rc==SQLITE_OK ){
124724 iDelete = sqlite3_value_int64(azData[0]);
124725 rc = findLeafNode(pRtree, iDelete, &pLeaf);
124726 }
124727
124728 /* Delete the cell in question from the leaf node. */
124729 if( rc==SQLITE_OK ){
124730 int rc2;
124731 rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
124732 if( rc==SQLITE_OK ){
124733 rc = deleteCell(pRtree, pLeaf, iCell, 0);
124734 }
124735 rc2 = nodeRelease(pRtree, pLeaf);
124736 if( rc==SQLITE_OK ){
124737 rc = rc2;
124738 }
124739 }
124740
124741 /* Delete the corresponding entry in the <rtree>_rowid table. */
124742 if( rc==SQLITE_OK ){
124743 sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete);
124744 sqlite3_step(pRtree->pDeleteRowid);
124745 rc = sqlite3_reset(pRtree->pDeleteRowid);
124746 }
124747
124748 /* Check if the root node now has exactly one child. If so, remove
124749 ** it, schedule the contents of the child for reinsertion and
124750 ** reduce the tree height by one.
124751 **
124752 ** This is equivalent to copying the contents of the child into
124753 ** the root node (the operation that Gutman's paper says to perform
124754 ** in this scenario).
124755 */
124756 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
124757 int rc2;
124758 RtreeNode *pChild;
124759 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
124760 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
124761 if( rc==SQLITE_OK ){
124762 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
124763 }
124764 rc2 = nodeRelease(pRtree, pChild);
124765 if( rc==SQLITE_OK ) rc = rc2;
124766 if( rc==SQLITE_OK ){
124767 pRtree->iDepth--;
124768 writeInt16(pRoot->zData, pRtree->iDepth);
124769 pRoot->isDirty = 1;
124770 }
124771 }
124772
124773 /* Re-insert the contents of any underfull nodes removed from the tree. */
124774 for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
124775 if( rc==SQLITE_OK ){
124776 rc = reinsertNodeContent(pRtree, pLeaf);
124777 }
124778 pRtree->pDeleted = pLeaf->pNext;
124779 sqlite3_free(pLeaf);
124780 }
124781
124782 /* Release the reference to the root node. */
124783 if( rc==SQLITE_OK ){
124784 rc = nodeRelease(pRtree, pRoot);
124785 }else{
124786 nodeRelease(pRtree, pRoot);
124787 }
124788 }
124789
124790 /* If the azData[] array contains more than one element, elements
124791 ** (azData[2]..azData[argc-1]) contain a new record to insert into
124792 ** the r-tree structure.
124793 */
124794 if( rc==SQLITE_OK && nData>1 ){
124795 /* Insert a new record into the r-tree */
124796 RtreeCell cell;
124797 int ii;
124798 RtreeNode *pLeaf;
124799
124800 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
124801 assert( nData==(pRtree->nDim*2 + 3) );
124802 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
124803 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
@@ -124817,22 +125832,53 @@
124817 goto constraint;
124818 }
124819 }
124820 }
124821
124822 /* Figure out the rowid of the new row. */
124823 if( sqlite3_value_type(azData[2])==SQLITE_NULL ){
124824 rc = newRowid(pRtree, &cell.iRowid);
124825 }else{
124826 cell.iRowid = sqlite3_value_int64(azData[2]);
124827 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
124828 if( SQLITE_ROW==sqlite3_step(pRtree->pReadRowid) ){
124829 sqlite3_reset(pRtree->pReadRowid);
124830 rc = SQLITE_CONSTRAINT;
124831 goto constraint;
 
 
 
 
 
 
 
 
 
 
124832 }
124833 rc = sqlite3_reset(pRtree->pReadRowid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124834 }
124835 *pRowid = cell.iRowid;
124836
124837 if( rc==SQLITE_OK ){
124838 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
@@ -125068,10 +126114,12 @@
125068 int iErr = (argc<6) ? 2 : argc>(RTREE_MAX_DIMENSIONS*2+4) ? 3 : argc%2;
125069 if( aErrMsg[iErr] ){
125070 *pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]);
125071 return SQLITE_ERROR;
125072 }
 
 
125073
125074 /* Allocate the sqlite3_vtab structure */
125075 nDb = strlen(argv[1]);
125076 nName = strlen(argv[2]);
125077 pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
125078
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.7. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -648,13 +648,13 @@
648 **
649 ** See also: [sqlite3_libversion()],
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.7"
654 #define SQLITE_VERSION_NUMBER 3007007
655 #define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -916,11 +916,12 @@
916 ** Many SQLite functions return an integer result code from the set shown
917 ** here in order to indicates success or failure.
918 **
919 ** New error codes may be added in future versions of SQLite.
920 **
921 ** See also: [SQLITE_IOERR_READ | extended result codes],
922 ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes].
923 */
924 #define SQLITE_OK 0 /* Successful result */
925 /* beginning-of-error-codes */
926 #define SQLITE_ERROR 1 /* SQL error or missing database */
927 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -998,25 +999,26 @@
999 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
1000 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
1001 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1002 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1003 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1004 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
1005
1006 /*
1007 ** CAPI3REF: Flags For File Open Operations
1008 **
1009 ** These bit values are intended for use in the
1010 ** 3rd parameter to the [sqlite3_open_v2()] interface and
1011 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
 
1012 */
1013 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
1014 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
1015 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
1016 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
1017 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
1018 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
1019 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
1020 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
1021 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
1022 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
1023 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
1024 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -1123,21 +1125,22 @@
1125 };
1126
1127 /*
1128 ** CAPI3REF: OS Interface File Virtual Methods Object
1129 **
1130 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
1131 ** [sqlite3_file] object (or, more commonly, a subclass of the
1132 ** [sqlite3_file] object) with a pointer to an instance of this object.
1133 ** This object defines the methods used to perform various operations
1134 ** against the open file represented by the [sqlite3_file] object.
1135 **
1136 ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
1137 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
1138 ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
1139 ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
1140 ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
1141 ** to NULL.
1142 **
1143 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
1144 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
1145 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
1146 ** flag may be ORed in to indicate that only the data of the file
@@ -1302,10 +1305,11 @@
1305 */
1306 typedef struct sqlite3_mutex sqlite3_mutex;
1307
1308 /*
1309 ** CAPI3REF: OS Interface Object
1310 ** KEYWORDS: VFS VFSes
1311 **
1312 ** An instance of the sqlite3_vfs object defines the interface between
1313 ** the SQLite core and the underlying operating system. The "vfs"
1314 ** in the name of the object stands for "virtual file system".
1315 **
@@ -1334,10 +1338,11 @@
1338 ** object once the object has been registered.
1339 **
1340 ** The zName field holds the name of the VFS module. The name must
1341 ** be unique across all VFS modules.
1342 **
1343 ** [[sqlite3_vfs.xOpen]]
1344 ** ^SQLite guarantees that the zFilename parameter to xOpen
1345 ** is either a NULL pointer or string obtained
1346 ** from xFullPathname() with an optional suffix added.
1347 ** ^If a suffix is added to the zFilename parameter, it will
1348 ** consist of a single "-" character followed by no more than
@@ -1411,10 +1416,11 @@
1416 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1417 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
1418 ** element will be valid after xOpen returns regardless of the success
1419 ** or failure of the xOpen call.
1420 **
1421 ** [[sqlite3_vfs.xAccess]]
1422 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1423 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1424 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1425 ** to test whether a file is at least readable. The file can be a
1426 ** directory.
@@ -1657,13 +1663,13 @@
1663 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1664 ** Note, however, that ^sqlite3_config() can be called as part of the
1665 ** implementation of an application-defined [sqlite3_os_init()].
1666 **
1667 ** The first argument to sqlite3_config() is an integer
1668 ** [configuration option] that determines
1669 ** what property of SQLite is to be configured. Subsequent arguments
1670 ** vary depending on the [configuration option]
1671 ** in the first argument.
1672 **
1673 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1674 ** ^If the option is unknown or SQLite is unable to set the option
1675 ** then this routine returns a non-zero [error code].
@@ -1769,10 +1775,11 @@
1775 void *pAppData; /* Argument to xInit() and xShutdown() */
1776 };
1777
1778 /*
1779 ** CAPI3REF: Configuration Options
1780 ** KEYWORDS: {configuration option}
1781 **
1782 ** These constants are the available integer configuration options that
1783 ** can be passed as the first argument to the [sqlite3_config()] interface.
1784 **
1785 ** New configuration options may be added in future releases of SQLite.
@@ -1781,11 +1788,11 @@
1788 ** the call worked. The [sqlite3_config()] interface will return a
1789 ** non-zero [error code] if a discontinued or unsupported configuration option
1790 ** is invoked.
1791 **
1792 ** <dl>
1793 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1794 ** <dd>There are no arguments to this option. ^This option sets the
1795 ** [threading mode] to Single-thread. In other words, it disables
1796 ** all mutexing and puts SQLite into a mode where it can only be used
1797 ** by a single thread. ^If SQLite is compiled with
1798 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
@@ -1792,11 +1799,11 @@
1799 ** it is not possible to change the [threading mode] from its default
1800 ** value of Single-thread and so [sqlite3_config()] will return
1801 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1802 ** configuration option.</dd>
1803 **
1804 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1805 ** <dd>There are no arguments to this option. ^This option sets the
1806 ** [threading mode] to Multi-thread. In other words, it disables
1807 ** mutexing on [database connection] and [prepared statement] objects.
1808 ** The application is responsible for serializing access to
1809 ** [database connections] and [prepared statements]. But other mutexes
@@ -1806,11 +1813,11 @@
1813 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1814 ** it is not possible to set the Multi-thread [threading mode] and
1815 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1816 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1817 **
1818 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1819 ** <dd>There are no arguments to this option. ^This option sets the
1820 ** [threading mode] to Serialized. In other words, this option enables
1821 ** all mutexes including the recursive
1822 ** mutexes on [database connection] and [prepared statement] objects.
1823 ** In this mode (which is the default when SQLite is compiled with
@@ -1822,27 +1829,27 @@
1829 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1830 ** it is not possible to set the Serialized [threading mode] and
1831 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1832 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1833 **
1834 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1835 ** <dd> ^(This option takes a single argument which is a pointer to an
1836 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
1837 ** alternative low-level memory allocation routines to be used in place of
1838 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1839 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1840 ** before the [sqlite3_config()] call returns.</dd>
1841 **
1842 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1843 ** <dd> ^(This option takes a single argument which is a pointer to an
1844 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1845 ** structure is filled with the currently defined memory allocation routines.)^
1846 ** This option can be used to overload the default memory allocation
1847 ** routines with a wrapper that simulations memory allocation failure or
1848 ** tracks memory usage, for example. </dd>
1849 **
1850 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1851 ** <dd> ^This option takes single argument of type int, interpreted as a
1852 ** boolean, which enables or disables the collection of memory allocation
1853 ** statistics. ^(When memory allocation statistics are disabled, the
1854 ** following SQLite interfaces become non-operational:
1855 ** <ul>
@@ -1854,11 +1861,11 @@
1861 ** ^Memory allocation statistics are enabled by default unless SQLite is
1862 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1863 ** allocation statistics are disabled by default.
1864 ** </dd>
1865 **
1866 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1867 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1868 ** scratch memory. There are three arguments: A pointer an 8-byte
1869 ** aligned memory buffer from which the scratch allocations will be
1870 ** drawn, the size of each scratch allocation (sz),
1871 ** and the maximum number of scratch allocations (N). The sz
@@ -1870,11 +1877,11 @@
1877 ** ^SQLite will never require a scratch buffer that is more than 6
1878 ** times the database page size. ^If SQLite needs needs additional
1879 ** scratch memory beyond what is provided by this configuration option, then
1880 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1881 **
1882 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1883 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1884 ** the database page cache with the default page cache implemenation.
1885 ** This configuration should not be used if an application-define page
1886 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
1887 ** There are three arguments to this option: A pointer to 8-byte aligned
@@ -1891,11 +1898,11 @@
1898 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1899 ** The pointer in the first argument must
1900 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1901 ** will be undefined.</dd>
1902 **
1903 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1904 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1905 ** for all of its dynamic memory allocation needs beyond those provided
1906 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1907 ** There are three arguments: An 8-byte aligned pointer to the memory,
1908 ** the number of bytes in the memory buffer, and the minimum allocation size.
@@ -1908,11 +1915,11 @@
1915 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1916 ** boundary or subsequent behavior of SQLite will be undefined.
1917 ** The minimum allocation size is capped at 2^12. Reasonable values
1918 ** for the minimum allocation size are 2^5 through 2^8.</dd>
1919 **
1920 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1921 ** <dd> ^(This option takes a single argument which is a pointer to an
1922 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1923 ** alternative low-level mutex routines to be used in place
1924 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1925 ** content of the [sqlite3_mutex_methods] structure before the call to
@@ -1920,11 +1927,11 @@
1927 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1928 ** the entire mutexing subsystem is omitted from the build and hence calls to
1929 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1930 ** return [SQLITE_ERROR].</dd>
1931 **
1932 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1933 ** <dd> ^(This option takes a single argument which is a pointer to an
1934 ** instance of the [sqlite3_mutex_methods] structure. The
1935 ** [sqlite3_mutex_methods]
1936 ** structure is filled with the currently defined mutex routines.)^
1937 ** This option can be used to overload the default mutex allocation
@@ -1933,32 +1940,32 @@
1940 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1941 ** the entire mutexing subsystem is omitted from the build and hence calls to
1942 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1943 ** return [SQLITE_ERROR].</dd>
1944 **
1945 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1946 ** <dd> ^(This option takes two arguments that determine the default
1947 ** memory allocation for the lookaside memory allocator on each
1948 ** [database connection]. The first argument is the
1949 ** size of each lookaside buffer slot and the second is the number of
1950 ** slots allocated to each database connection.)^ ^(This option sets the
1951 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1952 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1953 ** configuration on individual connections.)^ </dd>
1954 **
1955 ** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt>
1956 ** <dd> ^(This option takes a single argument which is a pointer to
1957 ** an [sqlite3_pcache_methods] object. This object specifies the interface
1958 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1959 ** object and uses it for page cache memory allocations.</dd>
1960 **
1961 ** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt>
1962 ** <dd> ^(This option takes a single argument which is a pointer to an
1963 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1964 ** page cache implementation into that object.)^ </dd>
1965 **
1966 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1967 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1968 ** function with a call signature of void(*)(void*,int,const char*),
1969 ** and a pointer to void. ^If the function pointer is not NULL, it is
1970 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1971 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
@@ -1972,10 +1979,22 @@
1979 ** The SQLite logging interface is not reentrant; the logger function
1980 ** supplied by the application must not invoke any SQLite interface.
1981 ** In a multi-threaded application, the application-defined logger
1982 ** function must be threadsafe. </dd>
1983 **
1984 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1985 ** <dd> This option takes a single argument of type int. If non-zero, then
1986 ** URI handling is globally enabled. If the parameter is zero, then URI handling
1987 ** is globally disabled. If URI handling is globally enabled, all filenames
1988 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1989 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1990 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1991 ** connection is opened. If it is globally disabled, filenames are
1992 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1993 ** database connection is opened. By default, URI handling is globally
1994 ** disabled. The default value may be changed by compiling with the
1995 ** [SQLITE_USE_URI] symbol defined.
1996 ** </dl>
1997 */
1998 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1999 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2000 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1990,10 +2009,11 @@
2009 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
2010 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
2011 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
2012 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
2013 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
2014 #define SQLITE_CONFIG_URI 17 /* int */
2015
2016 /*
2017 ** CAPI3REF: Database Connection Configuration Options
2018 **
2019 ** These constants are the available integer configuration options that
@@ -2075,17 +2095,21 @@
2095 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2096 ** is another alias for the rowid.
2097 **
2098 ** ^This routine returns the [rowid] of the most recent
2099 ** successful [INSERT] into the database from the [database connection]
2100 ** in the first argument. ^As of SQLite version 3.7.7, this routines
2101 ** records the last insert rowid of both ordinary tables and [virtual tables].
2102 ** ^If no successful [INSERT]s
2103 ** have ever occurred on that database connection, zero is returned.
2104 **
2105 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
2106 ** method, then this routine will return the [rowid] of the inserted
2107 ** row as long as the trigger or virtual table method is running.
2108 ** But once the trigger or virtual table method ends, the value returned
2109 ** by this routine reverts to what it was before the trigger or virtual
2110 ** table method began.)^
2111 **
2112 ** ^An [INSERT] that fails due to a constraint violation is not a
2113 ** successful [INSERT] and does not change the value returned by this
2114 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2115 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2744,10 +2768,13 @@
2768 ** The [sqlite3_set_authorizer | authorizer callback function] must
2769 ** return either [SQLITE_OK] or one of these two constants in order
2770 ** to signal SQLite whether or not the action is permitted. See the
2771 ** [sqlite3_set_authorizer | authorizer documentation] for additional
2772 ** information.
2773 **
2774 ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code]
2775 ** from the [sqlite3_vtab_on_conflict()] interface.
2776 */
2777 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2778 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
2779
2780 /*
@@ -2866,11 +2893,11 @@
2893 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2894
2895 /*
2896 ** CAPI3REF: Opening A New Database Connection
2897 **
2898 ** ^These routines open an SQLite database file as specified by the
2899 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2900 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2901 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
2902 ** returned in *ppDb, even if an error occurs. The only exception is that
2903 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
@@ -2893,11 +2920,11 @@
2920 ** except that it accepts two additional parameters for additional control
2921 ** over the new database connection. ^(The flags parameter to
2922 ** sqlite3_open_v2() can take one of
2923 ** the following three values, optionally combined with the
2924 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2925 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
2926 **
2927 ** <dl>
2928 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
2929 ** <dd>The database is opened in read-only mode. If the database does not
2930 ** already exist, an error is returned.</dd>)^
@@ -2912,13 +2939,12 @@
2939 ** it does not already exist. This is the behavior that is always used for
2940 ** sqlite3_open() and sqlite3_open16().</dd>)^
2941 ** </dl>
2942 **
2943 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2944 ** combinations shown above optionally combined with other
2945 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
 
2946 ** then the behavior is undefined.
2947 **
2948 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2949 ** opens in the multi-thread [threading mode] as long as the single-thread
2950 ** mode has not been set at compile-time or start-time. ^If the
@@ -2928,10 +2954,15 @@
2954 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
2955 ** eligible to use [shared cache mode], regardless of whether or not shared
2956 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
2957 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2958 ** participate in [shared cache mode] even if it is enabled.
2959 **
2960 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
2961 ** [sqlite3_vfs] object that defines the operating system interface that
2962 ** the new database connection should use. ^If the fourth parameter is
2963 ** a NULL pointer then the default [sqlite3_vfs] object is used.
2964 **
2965 ** ^If the filename is ":memory:", then a private, temporary in-memory database
2966 ** is created for the connection. ^This in-memory database will vanish when
2967 ** the database connection is closed. Future versions of SQLite might
2968 ** make use of additional special filenames that begin with the ":" character.
@@ -2941,14 +2972,115 @@
2972 **
2973 ** ^If the filename is an empty string, then a private, temporary
2974 ** on-disk database will be created. ^This private database will be
2975 ** automatically deleted as soon as the database connection is closed.
2976 **
2977 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
2978 **
2979 ** ^If [URI filename] interpretation is enabled, and the filename argument
2980 ** begins with "file:", then the filename is interpreted as a URI. ^URI
2981 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
2982 ** is set in the fourth argument to sqlite3_open_v2(), or if it has
2983 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
2984 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
2985 ** As of SQLite version 3.7.7, URI filename interpretation is turned off
2986 ** by default, but future releases of SQLite might enable URI filename
2987 ** intepretation by default. See "[URI filenames]" for additional
2988 ** information.
2989 **
2990 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
2991 ** authority, then it must be either an empty string or the string
2992 ** "localhost". ^If the authority is not an empty string or "localhost", an
2993 ** error is returned to the caller. ^The fragment component of a URI, if
2994 ** present, is ignored.
2995 **
2996 ** ^SQLite uses the path component of the URI as the name of the disk file
2997 ** which contains the database. ^If the path begins with a '/' character,
2998 ** then it is interpreted as an absolute path. ^If the path does not begin
2999 ** with a '/' (meaning that the authority section is omitted from the URI)
3000 ** then the path is interpreted as a relative path.
3001 ** ^On windows, the first component of an absolute path
3002 ** is a drive specification (e.g. "C:").
3003 **
3004 ** [[core URI query parameters]]
3005 ** The query component of a URI may contain parameters that are interpreted
3006 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
3007 ** SQLite interprets the following three query parameters:
3008 **
3009 ** <ul>
3010 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3011 ** a VFS object that provides the operating system interface that should
3012 ** be used to access the database file on disk. ^If this option is set to
3013 ** an empty string the default VFS object is used. ^Specifying an unknown
3014 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3015 ** present, then the VFS specified by the option takes precedence over
3016 ** the value passed as the fourth parameter to sqlite3_open_v2().
3017 **
3018 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
3019 ** "rwc". Attempting to set it to any other value is an error)^.
3020 ** ^If "ro" is specified, then the database is opened for read-only
3021 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3022 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
3023 ** "rw", then the database is opened for read-write (but not create)
3024 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3025 ** been set. ^Value "rwc" is equivalent to setting both
3026 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
3027 ** used, it is an error to specify a value for the mode parameter that is
3028 ** less restrictive than that specified by the flags passed as the third
3029 ** parameter.
3030 **
3031 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3032 ** "private". ^Setting it to "shared" is equivalent to setting the
3033 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3034 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3035 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3036 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3037 ** a URI filename, its value overrides any behaviour requested by setting
3038 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3039 ** </ul>
3040 **
3041 ** ^Specifying an unknown parameter in the query component of a URI is not an
3042 ** error. Future versions of SQLite might understand additional query
3043 ** parameters. See "[query parameters with special meaning to SQLite]" for
3044 ** additional information.
3045 **
3046 ** [[URI filename examples]] <h3>URI filename examples</h3>
3047 **
3048 ** <table border="1" align=center cellpadding=5>
3049 ** <tr><th> URI filenames <th> Results
3050 ** <tr><td> file:data.db <td>
3051 ** Open the file "data.db" in the current directory.
3052 ** <tr><td> file:/home/fred/data.db<br>
3053 ** file:///home/fred/data.db <br>
3054 ** file://localhost/home/fred/data.db <br> <td>
3055 ** Open the database file "/home/fred/data.db".
3056 ** <tr><td> file://darkstar/home/fred/data.db <td>
3057 ** An error. "darkstar" is not a recognized authority.
3058 ** <tr><td style="white-space:nowrap">
3059 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3060 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3061 ** C:. Note that the %20 escaping in this example is not strictly
3062 ** necessary - space characters can be used literally
3063 ** in URI filenames.
3064 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3065 ** Open file "data.db" in the current directory for read-only access.
3066 ** Regardless of whether or not shared-cache mode is enabled by
3067 ** default, use a private cache.
3068 ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
3069 ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
3070 ** <tr><td> file:data.db?mode=readonly <td>
3071 ** An error. "readonly" is not a valid option for the "mode" parameter.
3072 ** </table>
3073 **
3074 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
3075 ** query components of a URI. A hexadecimal escape sequence consists of a
3076 ** percent sign - "%" - followed by exactly two hexadecimal digits
3077 ** specifying an octet value. ^Before the path or query components of a
3078 ** URI filename are interpreted, they are encoded using UTF-8 and all
3079 ** hexadecimal escape sequences replaced by a single byte containing the
3080 ** corresponding octet. If this process generates an invalid UTF-8 encoding,
3081 ** the results are undefined.
3082 **
3083 ** <b>Note to Windows users:</b> The encoding used for the filename argument
3084 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
3085 ** codepage is currently defined. Filenames containing international
3086 ** characters must be converted to UTF-8 prior to passing them into
@@ -2966,10 +3098,30 @@
3098 const char *filename, /* Database filename (UTF-8) */
3099 sqlite3 **ppDb, /* OUT: SQLite db handle */
3100 int flags, /* Flags */
3101 const char *zVfs /* Name of VFS module to use */
3102 );
3103
3104 /*
3105 ** CAPI3REF: Obtain Values For URI Parameters
3106 **
3107 ** This is a utility routine, useful to VFS implementations, that checks
3108 ** to see if a database file was a URI that contained a specific query
3109 ** parameter, and if so obtains the value of the query parameter.
3110 **
3111 ** The zFilename argument is the filename pointer passed into the xOpen()
3112 ** method of a VFS implementation. The zParam argument is the name of the
3113 ** query parameter we seek. This routine returns the value of the zParam
3114 ** parameter if it exists. If the parameter does not exist, this routine
3115 ** returns a NULL pointer.
3116 **
3117 ** If the zFilename argument to this function is not a pointer that SQLite
3118 ** passed into the xOpen VFS method, then the behavior of this routine
3119 ** is undefined and probably undesirable.
3120 */
3121 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3122
3123
3124 /*
3125 ** CAPI3REF: Error Codes And Messages
3126 **
3127 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
@@ -3082,47 +3234,49 @@
3234 ** that can be lowered at run-time using [sqlite3_limit()].
3235 ** The synopsis of the meanings of the various limits is shown below.
3236 ** Additional information is available at [limits | Limits in SQLite].
3237 **
3238 ** <dl>
3239 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3240 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3241 **
3242 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3243 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3244 **
3245 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
3246 ** <dd>The maximum number of columns in a table definition or in the
3247 ** result set of a [SELECT] or the maximum number of columns in an index
3248 ** or in an ORDER BY or GROUP BY clause.</dd>)^
3249 **
3250 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
3251 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
3252 **
3253 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3254 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3255 **
3256 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3257 ** <dd>The maximum number of instructions in a virtual machine program
3258 ** used to implement an SQL statement. This limit is not currently
3259 ** enforced, though that might be added in some future release of
3260 ** SQLite.</dd>)^
3261 **
3262 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3263 ** <dd>The maximum number of arguments on a function.</dd>)^
3264 **
3265 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
3266 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
3267 **
3268 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
3269 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
3270 ** <dd>The maximum length of the pattern argument to the [LIKE] or
3271 ** [GLOB] operators.</dd>)^
3272 **
3273 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
3274 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3275 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3276 **
3277 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3278 ** <dd>The maximum depth of recursion for triggers.</dd>)^
3279 ** </dl>
3280 */
3281 #define SQLITE_LIMIT_LENGTH 0
3282 #define SQLITE_LIMIT_SQL_LENGTH 1
@@ -5153,10 +5307,15 @@
5307 int (*xRollback)(sqlite3_vtab *pVTab);
5308 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
5309 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
5310 void **ppArg);
5311 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
5312 /* The methods above are in version 1 of the sqlite_module object. Those
5313 ** below are for version 2 and greater. */
5314 int (*xSavepoint)(sqlite3_vtab *pVTab, int);
5315 int (*xRelease)(sqlite3_vtab *pVTab, int);
5316 int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
5317 };
5318
5319 /*
5320 ** CAPI3REF: Virtual Table Indexing Information
5321 ** KEYWORDS: sqlite3_index_info
@@ -5967,11 +6126,11 @@
6126 **
6127 ** ^This interface is used to retrieve runtime status information
6128 ** about the performance of SQLite, and optionally to reset various
6129 ** highwater marks. ^The first argument is an integer code for
6130 ** the specific parameter to measure. ^(Recognized integer codes
6131 ** are of the form [status parameters | SQLITE_STATUS_...].)^
6132 ** ^The current value of the parameter is returned into *pCurrent.
6133 ** ^The highest recorded value is returned in *pHighwater. ^If the
6134 ** resetFlag is true, then the highest record value is reset after
6135 ** *pHighwater is written. ^(Some parameters do not record the highest
6136 ** value. For those parameters
@@ -5994,82 +6153,84 @@
6153 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
6154
6155
6156 /*
6157 ** CAPI3REF: Status Parameters
6158 ** KEYWORDS: {status parameters}
6159 **
6160 ** These integer constants designate various run-time status parameters
6161 ** that can be returned by [sqlite3_status()].
6162 **
6163 ** <dl>
6164 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
6165 ** <dd>This parameter is the current amount of memory checked out
6166 ** using [sqlite3_malloc()], either directly or indirectly. The
6167 ** figure includes calls made to [sqlite3_malloc()] by the application
6168 ** and internal memory usage by the SQLite library. Scratch memory
6169 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
6170 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
6171 ** this parameter. The amount returned is the sum of the allocation
6172 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
6173 **
6174 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
6175 ** <dd>This parameter records the largest memory allocation request
6176 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
6177 ** internal equivalents). Only the value returned in the
6178 ** *pHighwater parameter to [sqlite3_status()] is of interest.
6179 ** The value written into the *pCurrent parameter is undefined.</dd>)^
6180 **
6181 ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
6182 ** <dd>This parameter records the number of separate memory allocations
6183 ** currently checked out.</dd>)^
6184 **
6185 ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
6186 ** <dd>This parameter returns the number of pages used out of the
6187 ** [pagecache memory allocator] that was configured using
6188 ** [SQLITE_CONFIG_PAGECACHE]. The
6189 ** value returned is in pages, not in bytes.</dd>)^
6190 **
6191 ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
6192 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
6193 ** <dd>This parameter returns the number of bytes of page cache
6194 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
6195 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
6196 ** returned value includes allocations that overflowed because they
6197 ** where too large (they were larger than the "sz" parameter to
6198 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
6199 ** no space was left in the page cache.</dd>)^
6200 **
6201 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
6202 ** <dd>This parameter records the largest memory allocation request
6203 ** handed to [pagecache memory allocator]. Only the value returned in the
6204 ** *pHighwater parameter to [sqlite3_status()] is of interest.
6205 ** The value written into the *pCurrent parameter is undefined.</dd>)^
6206 **
6207 ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
6208 ** <dd>This parameter returns the number of allocations used out of the
6209 ** [scratch memory allocator] configured using
6210 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
6211 ** in bytes. Since a single thread may only have one scratch allocation
6212 ** outstanding at time, this parameter also reports the number of threads
6213 ** using scratch memory at the same time.</dd>)^
6214 **
6215 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
6216 ** <dd>This parameter returns the number of bytes of scratch memory
6217 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
6218 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
6219 ** returned include overflows because the requested allocation was too
6220 ** larger (that is, because the requested allocation was larger than the
6221 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
6222 ** slots were available.
6223 ** </dd>)^
6224 **
6225 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
6226 ** <dd>This parameter records the largest memory allocation request
6227 ** handed to [scratch memory allocator]. Only the value returned in the
6228 ** *pHighwater parameter to [sqlite3_status()] is of interest.
6229 ** The value written into the *pCurrent parameter is undefined.</dd>)^
6230 **
6231 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
6232 ** <dd>This parameter records the deepest parser stack. It is only
6233 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
6234 ** </dl>
6235 **
6236 ** New status parameters may be added from time to time.
@@ -6090,13 +6251,13 @@
6251 **
6252 ** ^This interface is used to retrieve runtime status information
6253 ** about a single [database connection]. ^The first argument is the
6254 ** database connection object to be interrogated. ^The second argument
6255 ** is an integer constant, taken from the set of
6256 ** [SQLITE_DBSTATUS options], that
6257 ** determines the parameter to interrogate. The set of
6258 ** [SQLITE_DBSTATUS options] is likely
6259 ** to grow in future releases of SQLite.
6260 **
6261 ** ^The current value of the requested parameter is written into *pCur
6262 ** and the highest instantaneous value is written into *pHiwtr. ^If
6263 ** the resetFlg is true, then the highest instantaneous value is
@@ -6109,10 +6270,11 @@
6270 */
6271 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
6272
6273 /*
6274 ** CAPI3REF: Status Parameters for database connections
6275 ** KEYWORDS: {SQLITE_DBSTATUS options}
6276 **
6277 ** These constants are the available integer "verbs" that can be passed as
6278 ** the second argument to the [sqlite3_db_status()] interface.
6279 **
6280 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -6120,48 +6282,50 @@
6282 ** [sqlite3_db_status()] to make sure that the call worked.
6283 ** The [sqlite3_db_status()] interface will return a non-zero error code
6284 ** if a discontinued or unsupported verb is invoked.
6285 **
6286 ** <dl>
6287 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
6288 ** <dd>This parameter returns the number of lookaside memory slots currently
6289 ** checked out.</dd>)^
6290 **
6291 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
6292 ** <dd>This parameter returns the number malloc attempts that were
6293 ** satisfied using lookaside memory. Only the high-water value is meaningful;
6294 ** the current value is always zero.)^
6295 **
6296 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
6297 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
6298 ** <dd>This parameter returns the number malloc attempts that might have
6299 ** been satisfied using lookaside memory but failed due to the amount of
6300 ** memory requested being larger than the lookaside slot size.
6301 ** Only the high-water value is meaningful;
6302 ** the current value is always zero.)^
6303 **
6304 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
6305 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
6306 ** <dd>This parameter returns the number malloc attempts that might have
6307 ** been satisfied using lookaside memory but failed due to all lookaside
6308 ** memory already being in use.
6309 ** Only the high-water value is meaningful;
6310 ** the current value is always zero.)^
6311 **
6312 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
6313 ** <dd>This parameter returns the approximate number of of bytes of heap
6314 ** memory used by all pager caches associated with the database connection.)^
6315 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
6316 **
6317 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
6318 ** <dd>This parameter returns the approximate number of of bytes of heap
6319 ** memory used to store the schema for all databases associated
6320 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
6321 ** ^The full amount of memory used by the schemas is reported, even if the
6322 ** schema memory is shared with other database connections due to
6323 ** [shared cache mode] being enabled.
6324 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
6325 **
6326 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
6327 ** <dd>This parameter returns the approximate number of of bytes of heap
6328 ** and lookaside memory used by all prepared statements associated with
6329 ** the database connection.)^
6330 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
6331 ** </dd>
@@ -6179,11 +6343,11 @@
6343
6344 /*
6345 ** CAPI3REF: Prepared Statement Status
6346 **
6347 ** ^(Each prepared statement maintains various
6348 ** [SQLITE_STMTSTATUS counters] that measure the number
6349 ** of times it has performed specific operations.)^ These counters can
6350 ** be used to monitor the performance characteristics of the prepared
6351 ** statements. For example, if the number of table steps greatly exceeds
6352 ** the number of table searches or result rows, that would tend to indicate
6353 ** that the prepared statement is using a full table scan rather than
@@ -6190,11 +6354,11 @@
6354 ** an index.
6355 **
6356 ** ^(This interface is used to retrieve and reset counter values from
6357 ** a [prepared statement]. The first argument is the prepared statement
6358 ** object to be interrogated. The second argument
6359 ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
6360 ** to be interrogated.)^
6361 ** ^The current value of the requested counter is returned.
6362 ** ^If the resetFlg is true, then the counter is reset to zero after this
6363 ** interface call returns.
6364 **
@@ -6202,28 +6366,29 @@
6366 */
6367 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
6368
6369 /*
6370 ** CAPI3REF: Status Parameters for prepared statements
6371 ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
6372 **
6373 ** These preprocessor macros define integer codes that name counter
6374 ** values associated with the [sqlite3_stmt_status()] interface.
6375 ** The meanings of the various counters are as follows:
6376 **
6377 ** <dl>
6378 ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
6379 ** <dd>^This is the number of times that SQLite has stepped forward in
6380 ** a table as part of a full table scan. Large numbers for this counter
6381 ** may indicate opportunities for performance improvement through
6382 ** careful use of indices.</dd>
6383 **
6384 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
6385 ** <dd>^This is the number of sort operations that have occurred.
6386 ** A non-zero value in this counter may indicate an opportunity to
6387 ** improvement performance through careful use of indices.</dd>
6388 **
6389 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
6390 ** <dd>^This is the number of rows inserted into transient indices that
6391 ** were created automatically in order to help joins run faster.
6392 ** A non-zero value in this counter may indicate an opportunity to
6393 ** improvement performance by adding permanent indices that do not
6394 ** need to be reinitialized each time the statement is run.</dd>
@@ -6270,10 +6435,11 @@
6435 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
6436 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
6437 ** the application may discard the parameter after the call to
6438 ** [sqlite3_config()] returns.)^
6439 **
6440 ** [[the xInit() page cache method]]
6441 ** ^(The xInit() method is called once for each effective
6442 ** call to [sqlite3_initialize()])^
6443 ** (usually only once during the lifetime of the process). ^(The xInit()
6444 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
6445 ** The intent of the xInit() method is to set up global data structures
@@ -6280,10 +6446,11 @@
6446 ** required by the custom page cache implementation.
6447 ** ^(If the xInit() method is NULL, then the
6448 ** built-in default page cache is used instead of the application defined
6449 ** page cache.)^
6450 **
6451 ** [[the xShutdown() page cache method]]
6452 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
6453 ** It can be used to clean up
6454 ** any outstanding resources before process shutdown, if required.
6455 ** ^The xShutdown() method may be NULL.
6456 **
@@ -6294,10 +6461,11 @@
6461 ** in multithreaded applications.
6462 **
6463 ** ^SQLite will never invoke xInit() more than once without an intervening
6464 ** call to xShutdown().
6465 **
6466 ** [[the xCreate() page cache methods]]
6467 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
6468 ** SQLite will typically create one cache instance for each open database file,
6469 ** though this is not guaranteed. ^The
6470 ** first parameter, szPage, is the size in bytes of the pages that must
6471 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
@@ -6318,20 +6486,23 @@
6486 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
6487 ** false will always have the "discard" flag set to true.
6488 ** ^Hence, a cache created with bPurgeable false will
6489 ** never contain any unpinned pages.
6490 **
6491 ** [[the xCachesize() page cache method]]
6492 ** ^(The xCachesize() method may be called at any time by SQLite to set the
6493 ** suggested maximum cache-size (number of pages stored by) the cache
6494 ** instance passed as the first argument. This is the value configured using
6495 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
6496 ** parameter, the implementation is not required to do anything with this
6497 ** value; it is advisory only.
6498 **
6499 ** [[the xPagecount() page cache methods]]
6500 ** The xPagecount() method must return the number of pages currently
6501 ** stored in the cache, both pinned and unpinned.
6502 **
6503 ** [[the xFetch() page cache methods]]
6504 ** The xFetch() method locates a page in the cache and returns a pointer to
6505 ** the page, or a NULL pointer.
6506 ** A "page", in this context, means a buffer of szPage bytes aligned at an
6507 ** 8-byte boundary. The page to be fetched is determined by the key. ^The
6508 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
@@ -6356,10 +6527,11 @@
6527 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
6528 ** failed.)^ In between the to xFetch() calls, SQLite may
6529 ** attempt to unpin one or more cache pages by spilling the content of
6530 ** pinned pages to disk and synching the operating system disk cache.
6531 **
6532 ** [[the xUnpin() page cache method]]
6533 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
6534 ** as its second argument. If the third parameter, discard, is non-zero,
6535 ** then the page must be evicted from the cache.
6536 ** ^If the discard parameter is
6537 ** zero, then the page may be discarded or retained at the discretion of
@@ -6368,10 +6540,11 @@
6540 **
6541 ** The cache must not perform any reference counting. A single
6542 ** call to xUnpin() unpins the page regardless of the number of prior calls
6543 ** to xFetch().
6544 **
6545 ** [[the xRekey() page cache methods]]
6546 ** The xRekey() method is used to change the key value associated with the
6547 ** page passed as the second argument. If the cache
6548 ** previously contains an entry associated with newKey, it must be
6549 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
6550 ** to be pinned.
@@ -6380,10 +6553,11 @@
6553 ** existing cache entries with page numbers (keys) greater than or equal
6554 ** to the value of the iLimit parameter passed to xTruncate(). If any
6555 ** of these pages are pinned, they are implicitly unpinned, meaning that
6556 ** they can be safely discarded.
6557 **
6558 ** [[the xDestroy() page cache method]]
6559 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
6560 ** All resources associated with the specified cache should be freed. ^After
6561 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
6562 ** handle invalid, and will not use it with any other sqlite3_pcache_methods
6563 ** functions.
@@ -6442,11 +6616,11 @@
6616 ** associated with the backup operation.
6617 ** </ol>)^
6618 ** There should be exactly one call to sqlite3_backup_finish() for each
6619 ** successful call to sqlite3_backup_init().
6620 **
6621 ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
6622 **
6623 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
6624 ** [database connection] associated with the destination database
6625 ** and the database name, respectively.
6626 ** ^The database name is "main" for the main database, "temp" for the
@@ -6469,11 +6643,11 @@
6643 ** [sqlite3_backup] object.
6644 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
6645 ** sqlite3_backup_finish() functions to perform the specified backup
6646 ** operation.
6647 **
6648 ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
6649 **
6650 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6651 ** the source and destination databases specified by [sqlite3_backup] object B.
6652 ** ^If N is negative, all remaining source pages are copied.
6653 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
@@ -6526,11 +6700,11 @@
6700 ** restarted by the next call to sqlite3_backup_step(). ^If the source
6701 ** database is modified by the using the same database connection as is used
6702 ** by the backup operation, then the backup database is automatically
6703 ** updated at the same time.
6704 **
6705 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
6706 **
6707 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
6708 ** application wishes to abandon the backup operation, the application
6709 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
6710 ** ^The sqlite3_backup_finish() interfaces releases all
@@ -6549,11 +6723,12 @@
6723 **
6724 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
6725 ** is not a permanent error and does not affect the return value of
6726 ** sqlite3_backup_finish().
6727 **
6728 ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
6729 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
6730 **
6731 ** ^Each call to sqlite3_backup_step() sets two values inside
6732 ** the [sqlite3_backup] object: the number of pages still to be backed
6733 ** up and the total number of pages in the source database file.
6734 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
@@ -6934,10 +7109,97 @@
7109 ** each of these values.
7110 */
7111 #define SQLITE_CHECKPOINT_PASSIVE 0
7112 #define SQLITE_CHECKPOINT_FULL 1
7113 #define SQLITE_CHECKPOINT_RESTART 2
7114
7115 /*
7116 ** CAPI3REF: Virtual Table Interface Configuration
7117 **
7118 ** This function may be called by either the [xConnect] or [xCreate] method
7119 ** of a [virtual table] implementation to configure
7120 ** various facets of the virtual table interface.
7121 **
7122 ** If this interface is invoked outside the context of an xConnect or
7123 ** xCreate virtual table method then the behavior is undefined.
7124 **
7125 ** At present, there is only one option that may be configured using
7126 ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
7127 ** may be added in the future.
7128 */
7129 SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
7130
7131 /*
7132 ** CAPI3REF: Virtual Table Configuration Options
7133 **
7134 ** These macros define the various options to the
7135 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
7136 ** can use to customize and optimize their behavior.
7137 **
7138 ** <dl>
7139 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
7140 ** <dd>Calls of the form
7141 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
7142 ** where X is an integer. If X is zero, then the [virtual table] whose
7143 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
7144 ** support constraints. In this configuration (which is the default) if
7145 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
7146 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
7147 ** specified as part of the users SQL statement, regardless of the actual
7148 ** ON CONFLICT mode specified.
7149 **
7150 ** If X is non-zero, then the virtual table implementation guarantees
7151 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
7152 ** any modifications to internal or persistent data structures have been made.
7153 ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
7154 ** is able to roll back a statement or database transaction, and abandon
7155 ** or continue processing the current SQL statement as appropriate.
7156 ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
7157 ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
7158 ** had been ABORT.
7159 **
7160 ** Virtual table implementations that are required to handle OR REPLACE
7161 ** must do so within the [xUpdate] method. If a call to the
7162 ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
7163 ** CONFLICT policy is REPLACE, the virtual table implementation should
7164 ** silently replace the appropriate rows within the xUpdate callback and
7165 ** return SQLITE_OK. Or, if this is not possible, it may return
7166 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
7167 ** constraint handling.
7168 ** </dl>
7169 */
7170 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
7171
7172 /*
7173 ** CAPI3REF: Determine The Virtual Table Conflict Policy
7174 **
7175 ** This function may only be called from within a call to the [xUpdate] method
7176 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
7177 ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
7178 ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
7179 ** of the SQL statement that triggered the call to the [xUpdate] method of the
7180 ** [virtual table].
7181 */
7182 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
7183
7184 /*
7185 ** CAPI3REF: Conflict resolution modes
7186 **
7187 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
7188 ** inform a [virtual table] implementation what the [ON CONFLICT] mode
7189 ** is for the SQL statement being evaluated.
7190 **
7191 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
7192 ** return value from the [sqlite3_set_authorizer()] callback and that
7193 ** [SQLITE_ABORT] is also a [result code].
7194 */
7195 #define SQLITE_ROLLBACK 1
7196 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7197 #define SQLITE_FAIL 3
7198 /* #define SQLITE_ABORT 4 // Also an error code */
7199 #define SQLITE_REPLACE 5
7200
7201
7202
7203 /*
7204 ** Undo the hack that converts floating point types to integer for
7205 ** builds on processors without floating point support.
@@ -7601,10 +7863,11 @@
7863 typedef struct Trigger Trigger;
7864 typedef struct TriggerPrg TriggerPrg;
7865 typedef struct TriggerStep TriggerStep;
7866 typedef struct UnpackedRecord UnpackedRecord;
7867 typedef struct VTable VTable;
7868 typedef struct VtabCtx VtabCtx;
7869 typedef struct Walker Walker;
7870 typedef struct WherePlan WherePlan;
7871 typedef struct WhereInfo WhereInfo;
7872 typedef struct WhereLevel WhereLevel;
7873
@@ -7657,10 +7920,11 @@
7920 typedef struct BtCursor BtCursor;
7921 typedef struct BtShared BtShared;
7922
7923
7924 SQLITE_PRIVATE int sqlite3BtreeOpen(
7925 sqlite3_vfs *pVfs, /* VFS to use with this b-tree */
7926 const char *zFilename, /* Name of database file to open */
7927 sqlite3 *db, /* Associated database connection */
7928 Btree **ppBtree, /* Return open Btree* here */
7929 int flags, /* Flags */
7930 int vfsFlags /* Flags passed through to VFS open */
@@ -9136,19 +9400,20 @@
9400 struct sqlite3 {
9401 sqlite3_vfs *pVfs; /* OS Interface */
9402 int nDb; /* Number of backends currently in use */
9403 Db *aDb; /* All backends */
9404 int flags; /* Miscellaneous flags. See below */
9405 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
9406 int errCode; /* Most recent error code (SQLITE_*) */
9407 int errMask; /* & result codes with this before returning */
9408 u8 autoCommit; /* The auto-commit flag. */
9409 u8 temp_store; /* 1: file 2: memory 0: default */
9410 u8 mallocFailed; /* True if we have seen a malloc failure */
9411 u8 dfltLockMode; /* Default locking-mode for attached dbs */
9412 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
9413 u8 suppressErr; /* Do not issue error messages if true */
9414 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
9415 int nextPagesize; /* Pagesize after VACUUM if >0 */
9416 int nTable; /* Number of tables in the database */
9417 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
9418 i64 lastRowid; /* ROWID of most recent insert (see above) */
9419 u32 magic; /* Magic number for detect library misuse */
@@ -9203,11 +9468,11 @@
9468 void *pProgressArg; /* Argument to the progress callback */
9469 int nProgressOps; /* Number of opcodes for progress callback */
9470 #endif
9471 #ifndef SQLITE_OMIT_VIRTUALTABLE
9472 Hash aModule; /* populated by sqlite3_create_module() */
9473 VtabCtx *pVtabCtx; /* Context for active vtab connect/create */
9474 VTable **aVTrans; /* Virtual tables with open transactions */
9475 int nVTrans; /* Allocated size of aVTrans */
9476 VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
9477 #endif
9478 FuncDefHash aFunc; /* Hash table of connection functions */
@@ -9566,10 +9831,11 @@
9831 struct VTable {
9832 sqlite3 *db; /* Database connection associated with this table */
9833 Module *pMod; /* Pointer to module implementation */
9834 sqlite3_vtab *pVtab; /* Pointer to vtab instance */
9835 int nRef; /* Number of pointers to this structure */
9836 u8 bConstraint; /* True if constraints are supported */
9837 VTable *pNext; /* Next in linked list (see above) */
9838 };
9839
9840 /*
9841 ** Each SQL table is represented in memory by an instance of the
@@ -10754,10 +11020,11 @@
11020 */
11021 struct Sqlite3Config {
11022 int bMemstat; /* True to enable memory status */
11023 int bCoreMutex; /* True to enable core mutexing */
11024 int bFullMutex; /* True to enable full mutexing */
11025 int bOpenUri; /* True to interpret filenames as URIs */
11026 int mxStrlen; /* Maximum string length */
11027 int szLookaside; /* Default lookaside buffer size */
11028 int nLookaside; /* Default lookaside buffer count */
11029 sqlite3_mem_methods m; /* Low-level memory allocation interface */
11030 sqlite3_mutex_methods mutex; /* Low-level mutex interface */
@@ -11003,10 +11270,12 @@
11270 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
11271 SQLITE_PRIVATE void sqlite3AddColumnType(Parse*,Token*);
11272 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,ExprSpan*);
11273 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
11274 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,Select*);
11275 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
11276 sqlite3_vfs**,char**,char **);
11277
11278 SQLITE_PRIVATE Bitvec *sqlite3BitvecCreate(u32);
11279 SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32);
11280 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
11281 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*);
@@ -11253,10 +11522,11 @@
11522 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
11523 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
11524 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
11525 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
11526 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
11527 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
11528 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
11529 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
11530 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
11531 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
11532 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
@@ -11268,10 +11538,16 @@
11538 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
11539 SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64);
11540 SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64);
11541 SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64);
11542 SQLITE_PRIVATE int sqlite3AbsInt32(int);
11543 #ifdef SQLITE_ENABLE_8_3_NAMES
11544 SQLITE_PRIVATE void sqlite3FileSuffix3(const char*, char*);
11545 #else
11546 # define sqlite3FileSuffix3(X,Y)
11547 #endif
11548 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z);
11549
11550 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
11551 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
11552 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
11553 void(*)(void*));
@@ -11377,18 +11653,20 @@
11653 # define sqlite3VtabCommit(X)
11654 # define sqlite3VtabInSync(db) 0
11655 # define sqlite3VtabLock(X)
11656 # define sqlite3VtabUnlock(X)
11657 # define sqlite3VtabUnlockList(X)
11658 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
11659 #else
11660 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
11661 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
11662 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
11663 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
11664 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
11665 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
11666 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
11667 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
11668 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
11669 #endif
11670 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
11671 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
11672 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
@@ -11691,20 +11969,23 @@
11969 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */
11970 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */
11971 };
11972 #endif
11973
11974 #ifndef SQLITE_USE_URI
11975 # define SQLITE_USE_URI 0
11976 #endif
11977
11978 /*
11979 ** The following singleton contains the global configuration for
11980 ** the SQLite library.
11981 */
11982 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
11983 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
11984 1, /* bCoreMutex */
11985 SQLITE_THREADSAFE==1, /* bFullMutex */
11986 SQLITE_USE_URI, /* bOpenUri */
11987 0x7ffffffe, /* mxStrlen */
11988 100, /* szLookaside */
11989 500, /* nLookaside */
11990 {0,0,0,0,0,0,0,0}, /* m */
11991 {0,0,0,0,0,0,0,0,0}, /* mutex */
@@ -18217,11 +18498,11 @@
18498 sqlite3_mutex_enter(mem0.mutex);
18499 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
18500 nDiff = nNew - nOld;
18501 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
18502 mem0.alarmThreshold-nDiff ){
18503 sqlite3MallocAlarm(nDiff);
18504 }
18505 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
18506 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
18507 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
18508 if( pNew==0 && mem0.alarmCallback ){
@@ -18228,11 +18509,11 @@
18509 sqlite3MallocAlarm(nBytes);
18510 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
18511 }
18512 if( pNew ){
18513 nNew = sqlite3MallocSize(pNew);
18514 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
18515 }
18516 sqlite3_mutex_leave(mem0.mutex);
18517 }else{
18518 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
18519 }
@@ -21183,27 +21464,25 @@
21464 p[3] = (u8)v;
21465 }
21466
21467
21468
 
21469 /*
21470 ** Translate a single byte of Hex into an integer.
21471 ** This routine only works if h really is a valid hexadecimal
21472 ** character: 0..9a..fA..F
21473 */
21474 SQLITE_PRIVATE u8 sqlite3HexToInt(int h){
21475 assert( (h>='0' && h<='9') || (h>='a' && h<='f') || (h>='A' && h<='F') );
21476 #ifdef SQLITE_ASCII
21477 h += 9*(1&(h>>6));
21478 #endif
21479 #ifdef SQLITE_EBCDIC
21480 h += 9*(1&~(h>>4));
21481 #endif
21482 return (u8)(h & 0xf);
21483 }
 
21484
21485 #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
21486 /*
21487 ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary
21488 ** value. Return a pointer to its binary value. Space to hold the
@@ -21216,11 +21495,11 @@
21495
21496 zBlob = (char *)sqlite3DbMallocRaw(db, n/2 + 1);
21497 n--;
21498 if( zBlob ){
21499 for(i=0; i<n; i+=2){
21500 zBlob[i/2] = (sqlite3HexToInt(z[i])<<4) | sqlite3HexToInt(z[i+1]);
21501 }
21502 zBlob[i/2] = 0;
21503 }
21504 return zBlob;
21505 }
@@ -21348,10 +21627,36 @@
21627 SQLITE_PRIVATE int sqlite3AbsInt32(int x){
21628 if( x>=0 ) return x;
21629 if( x==(int)0x80000000 ) return 0x7fffffff;
21630 return -x;
21631 }
21632
21633 #ifdef SQLITE_ENABLE_8_3_NAMES
21634 /*
21635 ** If SQLITE_ENABLE_8_3_NAME is set at compile-time and if the database
21636 ** filename in zBaseFilename is a URI with the "8_3_names=1" parameter and
21637 ** if filename in z[] has a suffix (a.k.a. "extension") that is longer than
21638 ** three characters, then shorten the suffix on z[] to be the last three
21639 ** characters of the original suffix.
21640 **
21641 ** Examples:
21642 **
21643 ** test.db-journal => test.nal
21644 ** test.db-wal => test.wal
21645 ** test.db-shm => test.shm
21646 */
21647 SQLITE_PRIVATE void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
21648 const char *zOk;
21649 zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names");
21650 if( zOk && sqlite3GetBoolean(zOk) ){
21651 int i, sz;
21652 sz = sqlite3Strlen30(z);
21653 for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
21654 if( z[i]=='.' && ALWAYS(sz>i+4) ) memcpy(&z[i+1], &z[sz-3], 4);
21655 }
21656 }
21657 #endif
21658
21659 /************** End of util.c ************************************************/
21660 /************** Begin file hash.c ********************************************/
21661 /*
21662 ** 2001 September 22
@@ -27890,10 +28195,11 @@
28195 sqlite3_snprintf(nShmFilename, zShmFilename,
28196 SQLITE_SHM_DIRECTORY "/sqlite-shm-%x-%x",
28197 (u32)sStat.st_ino, (u32)sStat.st_dev);
28198 #else
28199 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
28200 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
28201 #endif
28202 pShmNode->h = -1;
28203 pDbFd->pInode->pShmNode = pShmNode;
28204 pShmNode->pInode = pDbFd->pInode;
28205 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
@@ -28923,17 +29229,23 @@
29229 ** Finally, if the file being opened is a WAL or regular journal file, then
29230 ** this function queries the file-system for the permissions on the
29231 ** corresponding database file and sets *pMode to this value. Whenever
29232 ** possible, WAL and journal files are created using the same permissions
29233 ** as the associated database file.
29234 **
29235 ** If the SQLITE_ENABLE_8_3_NAMES option is enabled, then the
29236 ** original filename is unavailable. But 8_3_NAMES is only used for
29237 ** FAT filesystems and permissions do not matter there, so just use
29238 ** the default permissions.
29239 */
29240 static int findCreateFileMode(
29241 const char *zPath, /* Path of file (possibly) being created */
29242 int flags, /* Flags passed as 4th argument to xOpen() */
29243 mode_t *pMode /* OUT: Permissions to open file with */
29244 ){
29245 int rc = SQLITE_OK; /* Return Code */
29246 *pMode = SQLITE_DEFAULT_FILE_PERMISSIONS;
29247 if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
29248 char zDb[MAX_PATHNAME+1]; /* Database file path */
29249 int nDb; /* Number of valid bytes in zDb */
29250 struct stat sStat; /* Output of stat() on database file */
29251
@@ -28941,19 +29253,19 @@
29253 ** the path to the associated database file from zPath. This block handles
29254 ** the following naming conventions:
29255 **
29256 ** "<path to db>-journal"
29257 ** "<path to db>-wal"
29258 ** "<path to db>-journalNN"
29259 ** "<path to db>-walNN"
29260 **
29261 ** where NN is a 4 digit decimal number. The NN naming schemes are
29262 ** used by the test_multiplex.c module.
29263 */
29264 nDb = sqlite3Strlen30(zPath) - 1;
29265 while( nDb>0 && zPath[nDb]!='-' ) nDb--;
29266 if( nDb==0 ) return SQLITE_OK;
29267 memcpy(zDb, zPath, nDb);
29268 zDb[nDb] = '\0';
29269
29270 if( 0==stat(zDb, &sStat) ){
29271 *pMode = sStat.st_mode & 0777;
@@ -28960,12 +29272,10 @@
29272 }else{
29273 rc = SQLITE_IOERR_FSTAT;
29274 }
29275 }else if( flags & SQLITE_OPEN_DELETEONCLOSE ){
29276 *pMode = 0600;
 
 
29277 }
29278 return rc;
29279 }
29280
29281 /*
@@ -32620,10 +32930,11 @@
32930 return SQLITE_NOMEM;
32931 }
32932 memset(pNew, 0, sizeof(*pNew));
32933 pNew->zFilename = (char*)&pNew[1];
32934 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
32935 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
32936
32937 /* Look to see if there is an existing winShmNode that can be used.
32938 ** If no matching winShmNode currently exists, create a new one.
32939 */
32940 winShmEnterMutex();
@@ -33514,10 +33825,17 @@
33825
33826 #if !SQLITE_OS_WINCE && !defined(__CYGWIN__)
33827 int nByte;
33828 void *zConverted;
33829 char *zOut;
33830
33831 /* If this path name begins with "/X:", where "X" is any alphabetic
33832 ** character, discard the initial "/" from the pathname.
33833 */
33834 if( zRelative[0]=='/' && sqlite3Isalpha(zRelative[1]) && zRelative[2]==':' ){
33835 zRelative++;
33836 }
33837
33838 /* It's odd to simulate an io-error here, but really this is just
33839 ** using the io-error infrastructure to test that SQLite handles this
33840 ** function failing. This function could fail if, for example, the
33841 ** current working directory has been unlinked.
@@ -36326,10 +36644,11 @@
36644 #define _WAL_H_
36645
36646
36647 #ifdef SQLITE_OMIT_WAL
36648 # define sqlite3WalOpen(x,y,z) 0
36649 # define sqlite3WalLimit(x,y)
36650 # define sqlite3WalClose(w,x,y,z) 0
36651 # define sqlite3WalBeginReadTransaction(y,z) 0
36652 # define sqlite3WalEndReadTransaction(z)
36653 # define sqlite3WalRead(v,w,x,y,z) 0
36654 # define sqlite3WalDbsize(y) 0
@@ -36351,13 +36670,16 @@
36670 ** There is one object of this type for each pager.
36671 */
36672 typedef struct Wal Wal;
36673
36674 /* Open and close a connection to a write-ahead log. */
36675 SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**);
36676 SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *);
36677
36678 /* Set the limiting size of a WAL file. */
36679 SQLITE_PRIVATE void sqlite3WalLimit(Wal*, i64);
36680
36681 /* Used by readers to open (lock) and close (unlock) a snapshot. A
36682 ** snapshot is like a read-transaction. It is the state of the database
36683 ** at an instant in time. sqlite3WalOpenSnapshot gets a read lock and
36684 ** preserves the current state even if the other threads or processes
36685 ** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
@@ -40702,10 +41024,12 @@
41024 int nPathname = 0; /* Number of bytes in zPathname */
41025 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
41026 int noReadlock = (flags & PAGER_NO_READLOCK)!=0; /* True to omit read-lock */
41027 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
41028 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
41029 const char *zUri = 0; /* URI args to copy */
41030 int nUri = 0; /* Number of bytes of URI args at *zUri */
41031
41032 /* Figure out how much space is required for each journal file-handle
41033 ** (there are two of them, the main journal and the sub-journal). This
41034 ** is the maximum space required for an in-memory journal file handle
41035 ** and a regular journal file-handle. Note that a "regular journal-handle"
@@ -40732,18 +41056,25 @@
41056 /* Compute and store the full pathname in an allocated buffer pointed
41057 ** to by zPathname, length nPathname. Or, if this is a temporary file,
41058 ** leave both nPathname and zPathname set to 0.
41059 */
41060 if( zFilename && zFilename[0] ){
41061 const char *z;
41062 nPathname = pVfs->mxPathname+1;
41063 zPathname = sqlite3Malloc(nPathname*2);
41064 if( zPathname==0 ){
41065 return SQLITE_NOMEM;
41066 }
41067 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
41068 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
41069 nPathname = sqlite3Strlen30(zPathname);
41070 z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1];
41071 while( *z ){
41072 z += sqlite3Strlen30(z)+1;
41073 z += sqlite3Strlen30(z)+1;
41074 }
41075 nUri = &z[1] - zUri;
41076 if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){
41077 /* This branch is taken when the journal path required by
41078 ** the database being opened will be more than pVfs->mxPathname
41079 ** bytes in length. This means the database cannot be opened,
41080 ** as it will not be possible to open the journal file or even
@@ -40772,11 +41103,11 @@
41103 pPtr = (u8 *)sqlite3MallocZero(
41104 ROUND8(sizeof(*pPager)) + /* Pager structure */
41105 ROUND8(pcacheSize) + /* PCache object */
41106 ROUND8(pVfs->szOsFile) + /* The main db file */
41107 journalFileSize * 2 + /* The two journal files */
41108 nPathname + 1 + nUri + /* zFilename */
41109 nPathname + 8 + 1 /* zJournal */
41110 #ifndef SQLITE_OMIT_WAL
41111 + nPathname + 4 + 1 /* zWal */
41112 #endif
41113 );
@@ -40794,18 +41125,21 @@
41125 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
41126
41127 /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
41128 if( zPathname ){
41129 assert( nPathname>0 );
41130 pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUri);
41131 memcpy(pPager->zFilename, zPathname, nPathname);
41132 memcpy(&pPager->zFilename[nPathname+1], zUri, nUri);
41133 memcpy(pPager->zJournal, zPathname, nPathname);
41134 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
41135 sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal);
41136 #ifndef SQLITE_OMIT_WAL
41137 pPager->zWal = &pPager->zJournal[nPathname+8+1];
41138 memcpy(pPager->zWal, zPathname, nPathname);
41139 memcpy(&pPager->zWal[nPathname], "-wal", 4);
41140 sqlite3FileSuffix3(pPager->zFilename, pPager->zWal);
41141 #endif
41142 sqlite3_free(zPathname);
41143 }
41144 pPager->pVfs = pVfs;
41145 pPager->vfsFlags = vfsFlags;
@@ -43000,10 +43334,11 @@
43334 ** An attempt to set a limit smaller than -1 is a no-op.
43335 */
43336 SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){
43337 if( iLimit>=-1 ){
43338 pPager->journalSizeLimit = iLimit;
43339 sqlite3WalLimit(pPager->pWal, iLimit);
43340 }
43341 return pPager->journalSizeLimit;
43342 }
43343
43344 /*
@@ -43091,11 +43426,12 @@
43426 /* Open the connection to the log file. If this operation fails,
43427 ** (e.g. due to malloc() failure), return an error code.
43428 */
43429 if( rc==SQLITE_OK ){
43430 rc = sqlite3WalOpen(pPager->pVfs,
43431 pPager->fd, pPager->zWal, pPager->exclusiveMode,
43432 pPager->journalSizeLimit, &pPager->pWal
43433 );
43434 }
43435
43436 return rc;
43437 }
@@ -43623,10 +43959,11 @@
43959 struct Wal {
43960 sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */
43961 sqlite3_file *pDbFd; /* File handle for the database file */
43962 sqlite3_file *pWalFd; /* File handle for WAL file */
43963 u32 iCallback; /* Value to pass to log callback (or 0) */
43964 i64 mxWalSize; /* Truncate WAL to this size upon reset */
43965 int nWiData; /* Size of array apWiData */
43966 volatile u32 **apWiData; /* Pointer to wal-index content in memory */
43967 u32 szPage; /* Database page size */
43968 i16 readLock; /* Which read lock is being held. -1 for none */
43969 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
@@ -44445,10 +44782,11 @@
44782 SQLITE_PRIVATE int sqlite3WalOpen(
44783 sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
44784 sqlite3_file *pDbFd, /* The open database file */
44785 const char *zWalName, /* Name of the WAL file */
44786 int bNoShm, /* True to run in heap-memory mode */
44787 i64 mxWalSize, /* Truncate WAL to this size on reset */
44788 Wal **ppWal /* OUT: Allocated Wal handle */
44789 ){
44790 int rc; /* Return Code */
44791 Wal *pRet; /* Object to allocate and return */
44792 int flags; /* Flags passed to OsOpen() */
@@ -44477,10 +44815,11 @@
44815
44816 pRet->pVfs = pVfs;
44817 pRet->pWalFd = (sqlite3_file *)&pRet[1];
44818 pRet->pDbFd = pDbFd;
44819 pRet->readLock = -1;
44820 pRet->mxWalSize = mxWalSize;
44821 pRet->zWalName = zWalName;
44822 pRet->exclusiveMode = (bNoShm ? WAL_HEAPMEMORY_MODE: WAL_NORMAL_MODE);
44823
44824 /* Open file handle on the write-ahead log file. */
44825 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
@@ -44497,10 +44836,17 @@
44836 *ppWal = pRet;
44837 WALTRACE(("WAL%d: opened\n", pRet));
44838 }
44839 return rc;
44840 }
44841
44842 /*
44843 ** Change the size to which the WAL file is trucated on each reset.
44844 */
44845 SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){
44846 if( pWal ) pWal->mxWalSize = iLimit;
44847 }
44848
44849 /*
44850 ** Find the smallest page number out of all pages held in the WAL that
44851 ** has not been returned by any prior invocation of this method on the
44852 ** same WalIterator object. Write into *piFrame the frame index where
@@ -45733,10 +46079,26 @@
46079 ** safe and means there is no special case for sqlite3WalUndo()
46080 ** to handle if this transaction is rolled back.
46081 */
46082 int i; /* Loop counter */
46083 u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
46084
46085 /* Limit the size of WAL file if the journal_size_limit PRAGMA is
46086 ** set to a non-negative value. Log errors encountered
46087 ** during the truncation attempt. */
46088 if( pWal->mxWalSize>=0 ){
46089 i64 sz;
46090 int rx;
46091 rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
46092 if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
46093 rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
46094 }
46095 if( rx ){
46096 sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
46097 }
46098 }
46099
46100 pWal->nCkpt++;
46101 pWal->hdr.mxFrame = 0;
46102 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
46103 aSalt[1] = salt1;
46104 walIndexWriteHdr(pWal);
@@ -47838,10 +48200,11 @@
48200 offset = PTRMAP_PTROFFSET(iPtrmap, key);
48201 if( offset<0 ){
48202 *pRC = SQLITE_CORRUPT_BKPT;
48203 goto ptrmap_exit;
48204 }
48205 assert( offset <= (int)pBt->usableSize-5 );
48206 pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
48207
48208 if( eType!=pPtrmap[offset] || get4byte(&pPtrmap[offset+1])!=parent ){
48209 TRACE(("PTRMAP_UPDATE: %d->(%d,%d)\n", key, eType, parent));
48210 *pRC= rc = sqlite3PagerWrite(pDbPage);
@@ -47877,10 +48240,15 @@
48240 return rc;
48241 }
48242 pPtrmap = (u8 *)sqlite3PagerGetData(pDbPage);
48243
48244 offset = PTRMAP_PTROFFSET(iPtrmap, key);
48245 if( offset<0 ){
48246 sqlite3PagerUnref(pDbPage);
48247 return SQLITE_CORRUPT_BKPT;
48248 }
48249 assert( offset <= (int)pBt->usableSize-5 );
48250 assert( pEType!=0 );
48251 *pEType = pPtrmap[offset];
48252 if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]);
48253
48254 sqlite3PagerUnref(pDbPage);
@@ -48738,17 +49106,17 @@
49106 ** SQLITE_CONSTRAINT error. We cannot allow two or more BtShared
49107 ** objects in the same database connection since doing so will lead
49108 ** to problems with locking.
49109 */
49110 SQLITE_PRIVATE int sqlite3BtreeOpen(
49111 sqlite3_vfs *pVfs, /* VFS to use for this b-tree */
49112 const char *zFilename, /* Name of the file containing the BTree database */
49113 sqlite3 *db, /* Associated database handle */
49114 Btree **ppBtree, /* Pointer to new Btree object written here */
49115 int flags, /* Options */
49116 int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */
49117 ){
 
49118 BtShared *pBt = 0; /* Shared part of btree structure */
49119 Btree *p; /* Handle to return */
49120 sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
49121 int rc = SQLITE_OK; /* Result code from this function */
49122 u8 nReserve; /* Byte of unused space on each page */
@@ -48766,10 +49134,11 @@
49134 const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
49135 || (isTempDb && sqlite3TempInMemory(db));
49136 #endif
49137
49138 assert( db!=0 );
49139 assert( pVfs!=0 );
49140 assert( sqlite3_mutex_held(db->mutex) );
49141 assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
49142
49143 /* Only a BTREE_SINGLE database can be BTREE_UNORDERED */
49144 assert( (flags & BTREE_UNORDERED)==0 || (flags & BTREE_SINGLE)!=0 );
@@ -48784,11 +49153,10 @@
49153 flags |= BTREE_MEMORY;
49154 }
49155 if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
49156 vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
49157 }
 
49158 p = sqlite3MallocZero(sizeof(Btree));
49159 if( !p ){
49160 return SQLITE_NOMEM;
49161 }
49162 p->inTrans = TRANS_NONE;
@@ -58855,10 +59223,11 @@
59223 sqlite3_randomness(sizeof(iRandom), &iRandom);
59224 zMaster = sqlite3MPrintf(db, "%s-mj%08X", zMainFile, iRandom&0x7fffffff);
59225 if( !zMaster ){
59226 return SQLITE_NOMEM;
59227 }
59228 sqlite3FileSuffix3(zMainFile, zMaster);
59229 rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
59230 }while( rc==SQLITE_OK && res );
59231 if( rc==SQLITE_OK ){
59232 /* Open the master journal. */
59233 rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster,
@@ -59068,10 +59437,19 @@
59437 }
59438 }
59439 }
59440 db->nStatement--;
59441 p->iStatement = 0;
59442
59443 if( rc==SQLITE_OK ){
59444 if( eOp==SAVEPOINT_ROLLBACK ){
59445 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
59446 }
59447 if( rc==SQLITE_OK ){
59448 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
59449 }
59450 }
59451
59452 /* If the statement transaction is being rolled back, also restore the
59453 ** database handles deferred constraint counter to the value it had when
59454 ** the statement transaction was opened. */
59455 if( eOp==SAVEPOINT_ROLLBACK ){
@@ -62400,10 +62778,11 @@
62778 Mem *pIn2 = 0; /* 2nd input operand */
62779 Mem *pIn3 = 0; /* 3rd input operand */
62780 Mem *pOut = 0; /* Output operand */
62781 int iCompare = 0; /* Result of last OP_Compare operation */
62782 int *aPermute = 0; /* Permutation of columns for OP_Compare */
62783 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
62784 #ifdef VDBE_PROFILE
62785 u64 start; /* CPU clock count at start of opcode */
62786 int origPc; /* Program counter at start of opcode */
62787 #endif
62788 /********************************************************************
@@ -63078,10 +63457,11 @@
63457 VdbeFrame *pFrame = p->pFrame;
63458 p->pFrame = pFrame->pParent;
63459 p->nFrame--;
63460 sqlite3VdbeSetChanges(db, p->nChange);
63461 pc = sqlite3VdbeFrameRestore(pFrame);
63462 lastRowid = db->lastRowid;
63463 if( pOp->p2==OE_Ignore ){
63464 /* Instruction pc is the OP_Program that invoked the sub-program
63465 ** currently being halted. If the p2 instruction of this OP_Halt
63466 ** instruction is set to OE_Ignore, then the sub-program is throwing
63467 ** an IGNORE exception. In this case jump to the address specified
@@ -63650,11 +64030,13 @@
64030 assert( pOp>aOp );
64031 assert( pOp[-1].p4type==P4_COLLSEQ );
64032 assert( pOp[-1].opcode==OP_CollSeq );
64033 u.ag.ctx.pColl = pOp[-1].p4.pColl;
64034 }
64035 db->lastRowid = lastRowid;
64036 (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */
64037 lastRowid = db->lastRowid;
64038 if( db->mallocFailed ){
64039 /* Even though a malloc() has failed, the implementation of the
64040 ** user function may have called an sqlite3_result_XXX() function
64041 ** to return a value. The following call releases any resources
64042 ** associated with such a value.
@@ -64857,10 +65239,18 @@
65239 "SQL statements in progress");
65240 rc = SQLITE_BUSY;
65241 }else{
65242 u.aq.nName = sqlite3Strlen30(u.aq.zName);
65243
65244 /* This call is Ok even if this savepoint is actually a transaction
65245 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
65246 ** If this is a transaction savepoint being opened, it is guaranteed
65247 ** that the db->aVTrans[] array is empty. */
65248 assert( db->autoCommit==0 || db->nVTrans==0 );
65249 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
65250 if( rc!=SQLITE_OK ) goto abort_due_to_error;
65251
65252 /* Create a new savepoint structure. */
65253 u.aq.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.aq.nName+1);
65254 if( u.aq.pNew ){
65255 u.aq.pNew->zName = (char *)&u.aq.pNew[1];
65256 memcpy(u.aq.pNew->zName, u.aq.zName, u.aq.nName+1);
@@ -64963,10 +65353,15 @@
65353 db->nSavepoint--;
65354 }
65355 }else{
65356 db->nDeferredCons = u.aq.pSavepoint->nDeferredCons;
65357 }
65358
65359 if( !isTransaction ){
65360 rc = sqlite3VtabSavepoint(db, u.aq.p1, u.aq.iSavepoint);
65361 if( rc!=SQLITE_OK ) goto abort_due_to_error;
65362 }
65363 }
65364 }
65365
65366 break;
65367 }
@@ -65102,11 +65497,15 @@
65497 if( p->iStatement==0 ){
65498 assert( db->nStatement>=0 && db->nSavepoint>=0 );
65499 db->nStatement++;
65500 p->iStatement = db->nSavepoint + db->nStatement;
65501 }
65502
65503 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement);
65504 if( rc==SQLITE_OK ){
65505 rc = sqlite3BtreeBeginStmt(u.as.pBt, p->iStatement);
65506 }
65507
65508 /* Store the current value of the database handles deferred constraint
65509 ** counter. If the statement transaction needs to be rolled back,
65510 ** the value of this counter needs to be restored too. */
65511 p->nStmtDefCons = db->nDeferredCons;
@@ -65423,11 +65822,11 @@
65822
65823 assert( pOp->p1>=0 );
65824 u.ax.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
65825 if( u.ax.pCx==0 ) goto no_mem;
65826 u.ax.pCx->nullRow = 1;
65827 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ax.pCx->pBt,
65828 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
65829 if( rc==SQLITE_OK ){
65830 rc = sqlite3BtreeBeginTrans(u.ax.pCx->pBt, 1);
65831 }
65832 if( rc==SQLITE_OK ){
@@ -66097,11 +66496,11 @@
66496 ** engine starts picking positive candidate ROWIDs at random until
66497 ** it finds one that is not previously used. */
66498 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
66499 ** an AUTOINCREMENT table. */
66500 /* on the first attempt, simply do one more than previous */
66501 u.be.v = lastRowid;
66502 u.be.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
66503 u.be.v++; /* ensure non-zero */
66504 u.be.cnt = 0;
66505 while( ((rc = sqlite3BtreeMovetoUnpacked(u.be.pC->pCursor, 0, (u64)u.be.v,
66506 0, &u.be.res))==SQLITE_OK)
@@ -66209,11 +66608,11 @@
66608 assert( pOp->opcode==OP_InsertInt );
66609 u.bf.iKey = pOp->p3;
66610 }
66611
66612 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
66613 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bf.iKey;
66614 if( u.bf.pData->flags & MEM_Null ){
66615 u.bf.pData->z = 0;
66616 u.bf.pData->n = 0;
66617 }else{
66618 assert( u.bf.pData->flags & (MEM_Blob|MEM_Str) );
@@ -67335,11 +67734,11 @@
67734 assert( pc==u.by.pFrame->pc );
67735 }
67736
67737 p->nFrame++;
67738 u.by.pFrame->pParent = p->pFrame;
67739 u.by.pFrame->lastRowid = lastRowid;
67740 u.by.pFrame->nChange = p->nChange;
67741 p->nChange = 0;
67742 p->pFrame = u.by.pFrame;
67743 p->aMem = aMem = &VdbeFrameMem(u.by.pFrame)[-1];
67744 p->nMem = u.by.pFrame->nChildMem;
@@ -68146,31 +68545,45 @@
68545 sqlite_int64 rowid;
68546 Mem **apArg;
68547 Mem *pX;
68548 #endif /* local variables moved into u.cm */
68549
68550 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
68551 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
68552 );
68553 u.cm.pVtab = pOp->p4.pVtab->pVtab;
68554 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
68555 u.cm.nArg = pOp->p2;
68556 assert( pOp->p4type==P4_VTAB );
68557 if( ALWAYS(u.cm.pModule->xUpdate) ){
68558 u8 vtabOnConflict = db->vtabOnConflict;
68559 u.cm.apArg = p->apArg;
68560 u.cm.pX = &aMem[pOp->p3];
68561 for(u.cm.i=0; u.cm.i<u.cm.nArg; u.cm.i++){
68562 assert( memIsValid(u.cm.pX) );
68563 memAboutToChange(p, u.cm.pX);
68564 sqlite3VdbeMemStoreType(u.cm.pX);
68565 u.cm.apArg[u.cm.i] = u.cm.pX;
68566 u.cm.pX++;
68567 }
68568 db->vtabOnConflict = pOp->p5;
68569 rc = u.cm.pModule->xUpdate(u.cm.pVtab, u.cm.nArg, u.cm.apArg, &u.cm.rowid);
68570 db->vtabOnConflict = vtabOnConflict;
68571 importVtabErrMsg(p, u.cm.pVtab);
68572 if( rc==SQLITE_OK && pOp->p1 ){
68573 assert( u.cm.nArg>1 && u.cm.apArg[0] && (u.cm.apArg[0]->flags&MEM_Null) );
68574 db->lastRowid = lastRowid = u.cm.rowid;
68575 }
68576 if( rc==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
68577 if( pOp->p5==OE_Ignore ){
68578 rc = SQLITE_OK;
68579 }else{
68580 p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5);
68581 }
68582 }else{
68583 p->nChange++;
68584 }
68585 }
68586 break;
68587 }
68588 #endif /* SQLITE_OMIT_VIRTUALTABLE */
68589
@@ -68316,10 +68729,11 @@
68729
68730 /* This is the only way out of this procedure. We have to
68731 ** release the mutexes on btrees that were acquired at the
68732 ** top. */
68733 vdbe_return:
68734 db->lastRowid = lastRowid;
68735 sqlite3VdbeLeave(p);
68736 return rc;
68737
68738 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
68739 ** is encountered.
@@ -76044,12 +76458,16 @@
76458 int i;
76459 int rc = 0;
76460 sqlite3 *db = sqlite3_context_db_handle(context);
76461 const char *zName;
76462 const char *zFile;
76463 char *zPath = 0;
76464 char *zErr = 0;
76465 unsigned int flags;
76466 Db *aNew;
76467 char *zErrDyn = 0;
76468 sqlite3_vfs *pVfs;
76469
76470 UNUSED_PARAMETER(NotUsed);
76471
76472 zFile = (const char *)sqlite3_value_text(argv[0]);
76473 zName = (const char *)sqlite3_value_text(argv[1]);
@@ -76098,12 +76516,22 @@
76516
76517 /* Open the database file. If the btree is successfully opened, use
76518 ** it to obtain the database schema. At this point the schema may
76519 ** or may not be initialised.
76520 */
76521 flags = db->openFlags;
76522 rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
76523 if( rc!=SQLITE_OK ){
76524 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
76525 sqlite3_result_error(context, zErr, -1);
76526 sqlite3_free(zErr);
76527 return;
76528 }
76529 assert( pVfs );
76530 flags |= SQLITE_OPEN_MAIN_DB;
76531 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
76532 sqlite3_free( zPath );
76533 db->nDb++;
76534 if( rc==SQLITE_CONSTRAINT ){
76535 rc = SQLITE_ERROR;
76536 zErrDyn = sqlite3MPrintf(db, "database is already attached");
76537 }else if( rc==SQLITE_OK ){
@@ -80213,11 +80641,11 @@
80641 SQLITE_OPEN_CREATE |
80642 SQLITE_OPEN_EXCLUSIVE |
80643 SQLITE_OPEN_DELETEONCLOSE |
80644 SQLITE_OPEN_TEMP_DB;
80645
80646 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
80647 if( rc!=SQLITE_OK ){
80648 sqlite3ErrorMsg(pParse, "unable to open a temporary database "
80649 "file for storing temporary tables");
80650 pParse->rc = rc;
80651 return 1;
@@ -85399,10 +85827,11 @@
85827 #ifndef SQLITE_OMIT_VIRTUALTABLE
85828 if( IsVirtual(pTab) ){
85829 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
85830 sqlite3VtabMakeWritable(pParse, pTab);
85831 sqlite3VdbeAddOp4(v, OP_VUpdate, 1, pTab->nCol+2, regIns, pVTab, P4_VTAB);
85832 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
85833 sqlite3MayAbort(pParse);
85834 }else
85835 #endif
85836 {
85837 int isReplace; /* Set to true if constraints may cause a replace */
@@ -87544,11 +87973,11 @@
87973 }
87974
87975 /*
87976 ** Interpret the given string as a boolean value.
87977 */
87978 SQLITE_PRIVATE u8 sqlite3GetBoolean(const char *z){
87979 return getSafetyLevel(z)&1;
87980 }
87981
87982 /*
87983 ** Interpret the given string as a locking mode value.
@@ -87714,11 +88143,11 @@
88143 /* Foreign key support may not be enabled or disabled while not
88144 ** in auto-commit mode. */
88145 mask &= ~(SQLITE_ForeignKeys);
88146 }
88147
88148 if( sqlite3GetBoolean(zRight) ){
88149 db->flags |= mask;
88150 }else{
88151 db->flags &= ~mask;
88152 }
88153
@@ -87928,11 +88357,11 @@
88357 if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
88358 Btree *pBt = pDb->pBt;
88359 int b = -1;
88360 assert( pBt!=0 );
88361 if( zRight ){
88362 b = sqlite3GetBoolean(zRight);
88363 }
88364 if( pId2->n==0 && b>=0 ){
88365 int ii;
88366 for(ii=0; ii<db->nDb; ii++){
88367 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
@@ -88528,11 +88957,11 @@
88957 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
88958
88959 #ifndef NDEBUG
88960 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
88961 if( zRight ){
88962 if( sqlite3GetBoolean(zRight) ){
88963 sqlite3ParserTrace(stderr, "parser: ");
88964 }else{
88965 sqlite3ParserTrace(0, 0);
88966 }
88967 }
@@ -88542,11 +88971,11 @@
88971 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
88972 ** used will be case sensitive or not depending on the RHS.
88973 */
88974 if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
88975 if( zRight ){
88976 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight));
88977 }
88978 }else
88979
88980 #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
88981 # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
@@ -95683,11 +96112,12 @@
96112 SrcList *pSrc, /* The virtual table to be modified */
96113 Table *pTab, /* The virtual table */
96114 ExprList *pChanges, /* The columns to change in the UPDATE statement */
96115 Expr *pRowidExpr, /* Expression used to recompute the rowid */
96116 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
96117 Expr *pWhere, /* WHERE clause of the UPDATE statement */
96118 int onError /* ON CONFLICT strategy */
96119 );
96120 #endif /* SQLITE_OMIT_VIRTUALTABLE */
96121
96122 /*
96123 ** The most recently coded instruction was an OP_Column to retrieve the
@@ -95927,11 +96357,11 @@
96357
96358 #ifndef SQLITE_OMIT_VIRTUALTABLE
96359 /* Virtual tables must be handled separately */
96360 if( IsVirtual(pTab) ){
96361 updateVirtualTable(pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
96362 pWhere, onError);
96363 pWhere = 0;
96364 pTabList = 0;
96365 goto update_cleanup;
96366 }
96367 #endif
@@ -96257,11 +96687,12 @@
96687 SrcList *pSrc, /* The virtual table to be modified */
96688 Table *pTab, /* The virtual table */
96689 ExprList *pChanges, /* The columns to change in the UPDATE statement */
96690 Expr *pRowid, /* Expression used to recompute the rowid */
96691 int *aXRef, /* Mapping from columns of pTab to entries in pChanges */
96692 Expr *pWhere, /* WHERE clause of the UPDATE statement */
96693 int onError /* ON CONFLICT strategy */
96694 ){
96695 Vdbe *v = pParse->pVdbe; /* Virtual machine under construction */
96696 ExprList *pEList = 0; /* The result set of the SELECT statement */
96697 Select *pSelect = 0; /* The SELECT statement */
96698 Expr *pExpr; /* Temporary expression */
@@ -96314,10 +96745,11 @@
96745 for(i=0; i<pTab->nCol; i++){
96746 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
96747 }
96748 sqlite3VtabMakeWritable(pParse, pTab);
96749 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
96750 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
96751 sqlite3MayAbort(pParse);
96752 sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
96753 sqlite3VdbeJumpHere(v, addr);
96754 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
96755
@@ -96687,10 +97119,22 @@
97119 *************************************************************************
97120 ** This file contains code used to help implement virtual tables.
97121 */
97122 #ifndef SQLITE_OMIT_VIRTUALTABLE
97123
97124 /*
97125 ** Before a virtual table xCreate() or xConnect() method is invoked, the
97126 ** sqlite3.pVtabCtx member variable is set to point to an instance of
97127 ** this struct allocated on the stack. It is used by the implementation of
97128 ** the sqlite3_declare_vtab() and sqlite3_vtab_config() APIs, both of which
97129 ** are invoked only from within xCreate and xConnect methods.
97130 */
97131 struct VtabCtx {
97132 Table *pTab;
97133 VTable *pVTable;
97134 };
97135
97136 /*
97137 ** The actual function that does the work of creating a new module.
97138 ** This function implements the sqlite3_create_module() and
97139 ** sqlite3_create_module_v2() interfaces.
97140 */
@@ -96715,17 +97159,17 @@
97159 pMod->pModule = pModule;
97160 pMod->pAux = pAux;
97161 pMod->xDestroy = xDestroy;
97162 pDel = (Module *)sqlite3HashInsert(&db->aModule, zCopy, nName, (void*)pMod);
97163 if( pDel && pDel->xDestroy ){
97164 sqlite3ResetInternalSchema(db, -1);
97165 pDel->xDestroy(pDel->pAux);
97166 }
97167 sqlite3DbFree(db, pDel);
97168 if( pDel==pMod ){
97169 db->mallocFailed = 1;
97170 }
 
97171 }else if( xDestroy ){
97172 xDestroy(pAux);
97173 }
97174 rc = sqlite3ApiExit(db, SQLITE_OK);
97175 sqlite3_mutex_leave(db->mutex);
@@ -97107,10 +97551,11 @@
97551 Table *pTab,
97552 Module *pMod,
97553 int (*xConstruct)(sqlite3*,void*,int,const char*const*,sqlite3_vtab**,char**),
97554 char **pzErr
97555 ){
97556 VtabCtx sCtx;
97557 VTable *pVTable;
97558 int rc;
97559 const char *const*azArg = (const char *const*)pTab->azModuleArg;
97560 int nArg = pTab->nModuleArg;
97561 char *zErr = 0;
@@ -97126,16 +97571,18 @@
97571 return SQLITE_NOMEM;
97572 }
97573 pVTable->db = db;
97574 pVTable->pMod = pMod;
97575
97576 /* Invoke the virtual table constructor */
97577 assert( &db->pVtabCtx );
97578 assert( xConstruct );
97579 sCtx.pTab = pTab;
97580 sCtx.pVTable = pVTable;
97581 db->pVtabCtx = &sCtx;
97582 rc = xConstruct(db, pMod->pAux, nArg, azArg, &pVTable->pVtab, &zErr);
97583 db->pVtabCtx = 0;
97584 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
97585
97586 if( SQLITE_OK!=rc ){
97587 if( zErr==0 ){
97588 *pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
@@ -97147,11 +97594,11 @@
97594 }else if( ALWAYS(pVTable->pVtab) ){
97595 /* Justification of ALWAYS(): A correct vtab constructor must allocate
97596 ** the sqlite3_vtab object if successful. */
97597 pVTable->pVtab->pModule = pMod->pModule;
97598 pVTable->nRef = 1;
97599 if( sCtx.pTab ){
97600 const char *zFormat = "vtable constructor did not declare schema: %s";
97601 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
97602 sqlite3VtabUnlock(pVTable);
97603 rc = SQLITE_ERROR;
97604 }else{
@@ -97195,11 +97642,10 @@
97642 }
97643 }
97644 }
97645
97646 sqlite3DbFree(db, zModuleName);
 
97647 return rc;
97648 }
97649
97650 /*
97651 ** This function is invoked by the parser to call the xConnect() method
@@ -97315,12 +97761,11 @@
97761 int rc = SQLITE_OK;
97762 Table *pTab;
97763 char *zErr = 0;
97764
97765 sqlite3_mutex_enter(db->mutex);
97766 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
 
97767 sqlite3Error(db, SQLITE_MISUSE, 0);
97768 sqlite3_mutex_leave(db->mutex);
97769 return SQLITE_MISUSE_BKPT;
97770 }
97771 assert( (pTab->tabFlags & TF_Virtual)!=0 );
@@ -97343,11 +97788,11 @@
97788 pTab->aCol = pParse->pNewTable->aCol;
97789 pTab->nCol = pParse->pNewTable->nCol;
97790 pParse->pNewTable->nCol = 0;
97791 pParse->pNewTable->aCol = 0;
97792 }
97793 db->pVtabCtx->pTab = 0;
97794 }else{
97795 sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
97796 sqlite3DbFree(db, zErr);
97797 rc = SQLITE_ERROR;
97798 }
@@ -97495,11 +97940,10 @@
97940 pModule = pVTab->pVtab->pModule;
97941
97942 if( pModule->xBegin ){
97943 int i;
97944
 
97945 /* If pVtab is already in the aVTrans array, return early */
97946 for(i=0; i<db->nVTrans; i++){
97947 if( db->aVTrans[i]==pVTab ){
97948 return SQLITE_OK;
97949 }
@@ -97508,10 +97952,53 @@
97952 /* Invoke the xBegin method */
97953 rc = pModule->xBegin(pVTab->pVtab);
97954 if( rc==SQLITE_OK ){
97955 rc = addToVTrans(db, pVTab);
97956 }
97957 }
97958 return rc;
97959 }
97960
97961 /*
97962 ** Invoke either the xSavepoint, xRollbackTo or xRelease method of all
97963 ** virtual tables that currently have an open transaction. Pass iSavepoint
97964 ** as the second argument to the virtual table method invoked.
97965 **
97966 ** If op is SAVEPOINT_BEGIN, the xSavepoint method is invoked. If it is
97967 ** SAVEPOINT_ROLLBACK, the xRollbackTo method. Otherwise, if op is
97968 ** SAVEPOINT_RELEASE, then the xRelease method of each virtual table with
97969 ** an open transaction is invoked.
97970 **
97971 ** If any virtual table method returns an error code other than SQLITE_OK,
97972 ** processing is abandoned and the error returned to the caller of this
97973 ** function immediately. If all calls to virtual table methods are successful,
97974 ** SQLITE_OK is returned.
97975 */
97976 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *db, int op, int iSavepoint){
97977 int rc = SQLITE_OK;
97978
97979 assert( op==SAVEPOINT_RELEASE||op==SAVEPOINT_ROLLBACK||op==SAVEPOINT_BEGIN );
97980 if( db->aVTrans ){
97981 int i;
97982 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
97983 const sqlite3_module *pMod = db->aVTrans[i]->pMod->pModule;
97984 if( pMod->iVersion>=2 ){
97985 int (*xMethod)(sqlite3_vtab *, int);
97986 switch( op ){
97987 case SAVEPOINT_BEGIN:
97988 xMethod = pMod->xSavepoint;
97989 break;
97990 case SAVEPOINT_ROLLBACK:
97991 xMethod = pMod->xRollbackTo;
97992 break;
97993 default:
97994 xMethod = pMod->xRelease;
97995 break;
97996 }
97997 if( xMethod ) rc = xMethod(db->aVTrans[i]->pVtab, iSavepoint);
97998 }
97999 }
98000 }
98001 return rc;
98002 }
98003
98004 /*
@@ -97609,10 +98096,61 @@
98096 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
98097 }else{
98098 pToplevel->db->mallocFailed = 1;
98099 }
98100 }
98101
98102 /*
98103 ** Return the ON CONFLICT resolution mode in effect for the virtual
98104 ** table update operation currently in progress.
98105 **
98106 ** The results of this routine are undefined unless it is called from
98107 ** within an xUpdate method.
98108 */
98109 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
98110 static const unsigned char aMap[] = {
98111 SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
98112 };
98113 assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
98114 assert( OE_Ignore==4 && OE_Replace==5 );
98115 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
98116 return (int)aMap[db->vtabOnConflict-1];
98117 }
98118
98119 /*
98120 ** Call from within the xCreate() or xConnect() methods to provide
98121 ** the SQLite core with additional information about the behavior
98122 ** of the virtual table being implemented.
98123 */
98124 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
98125 va_list ap;
98126 int rc = SQLITE_OK;
98127
98128 sqlite3_mutex_enter(db->mutex);
98129
98130 va_start(ap, op);
98131 switch( op ){
98132 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
98133 VtabCtx *p = db->pVtabCtx;
98134 if( !p ){
98135 rc = SQLITE_MISUSE_BKPT;
98136 }else{
98137 assert( p->pTab==0 || (p->pTab->tabFlags & TF_Virtual)!=0 );
98138 p->pVTable->bConstraint = (u8)va_arg(ap, int);
98139 }
98140 break;
98141 }
98142 default:
98143 rc = SQLITE_MISUSE_BKPT;
98144 break;
98145 }
98146 va_end(ap);
98147
98148 if( rc!=SQLITE_OK ) sqlite3Error(db, rc, 0);
98149 sqlite3_mutex_leave(db->mutex);
98150 return rc;
98151 }
98152
98153 #endif /* SQLITE_OMIT_VIRTUALTABLE */
98154
98155 /************** End of vtab.c ************************************************/
98156 /************** Begin file where.c *******************************************/
@@ -107631,10 +108169,15 @@
108169 typedef void(*LOGFUNC_t)(void*,int,const char*);
108170 sqlite3GlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
108171 sqlite3GlobalConfig.pLogArg = va_arg(ap, void*);
108172 break;
108173 }
108174
108175 case SQLITE_CONFIG_URI: {
108176 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
108177 break;
108178 }
108179
108180 default: {
108181 rc = SQLITE_ERROR;
108182 break;
108183 }
@@ -108990,25 +109533,257 @@
109533 }
109534 db->aLimit[limitId] = newLimit;
109535 }
109536 return oldLimit; /* IMP: R-53341-35419 */
109537 }
109538
109539 /*
109540 ** This function is used to parse both URIs and non-URI filenames passed by the
109541 ** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database
109542 ** URIs specified as part of ATTACH statements.
109543 **
109544 ** The first argument to this function is the name of the VFS to use (or
109545 ** a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
109546 ** query parameter. The second argument contains the URI (or non-URI filename)
109547 ** itself. When this function is called the *pFlags variable should contain
109548 ** the default flags to open the database handle with. The value stored in
109549 ** *pFlags may be updated before returning if the URI filename contains
109550 ** "cache=xxx" or "mode=xxx" query parameters.
109551 **
109552 ** If successful, SQLITE_OK is returned. In this case *ppVfs is set to point to
109553 ** the VFS that should be used to open the database file. *pzFile is set to
109554 ** point to a buffer containing the name of the file to open. It is the
109555 ** responsibility of the caller to eventually call sqlite3_free() to release
109556 ** this buffer.
109557 **
109558 ** If an error occurs, then an SQLite error code is returned and *pzErrMsg
109559 ** may be set to point to a buffer containing an English language error
109560 ** message. It is the responsibility of the caller to eventually release
109561 ** this buffer by calling sqlite3_free().
109562 */
109563 SQLITE_PRIVATE int sqlite3ParseUri(
109564 const char *zDefaultVfs, /* VFS to use if no "vfs=xxx" query option */
109565 const char *zUri, /* Nul-terminated URI to parse */
109566 unsigned int *pFlags, /* IN/OUT: SQLITE_OPEN_XXX flags */
109567 sqlite3_vfs **ppVfs, /* OUT: VFS to use */
109568 char **pzFile, /* OUT: Filename component of URI */
109569 char **pzErrMsg /* OUT: Error message (if rc!=SQLITE_OK) */
109570 ){
109571 int rc = SQLITE_OK;
109572 unsigned int flags = *pFlags;
109573 const char *zVfs = zDefaultVfs;
109574 char *zFile;
109575 char c;
109576 int nUri = sqlite3Strlen30(zUri);
109577
109578 assert( *pzErrMsg==0 );
109579
109580 if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
109581 && nUri>=5 && memcmp(zUri, "file:", 5)==0
109582 ){
109583 char *zOpt;
109584 int eState; /* Parser state when parsing URI */
109585 int iIn; /* Input character index */
109586 int iOut = 0; /* Output character index */
109587 int nByte = nUri+2; /* Bytes of space to allocate */
109588
109589 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
109590 ** method that there may be extra parameters following the file-name. */
109591 flags |= SQLITE_OPEN_URI;
109592
109593 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
109594 zFile = sqlite3_malloc(nByte);
109595 if( !zFile ) return SQLITE_NOMEM;
109596
109597 /* Discard the scheme and authority segments of the URI. */
109598 if( zUri[5]=='/' && zUri[6]=='/' ){
109599 iIn = 7;
109600 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
109601
109602 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
109603 *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
109604 iIn-7, &zUri[7]);
109605 rc = SQLITE_ERROR;
109606 goto parse_uri_out;
109607 }
109608 }else{
109609 iIn = 5;
109610 }
109611
109612 /* Copy the filename and any query parameters into the zFile buffer.
109613 ** Decode %HH escape codes along the way.
109614 **
109615 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
109616 ** on the parsing context. As follows:
109617 **
109618 ** 0: Parsing file-name.
109619 ** 1: Parsing name section of a name=value query parameter.
109620 ** 2: Parsing value section of a name=value query parameter.
109621 */
109622 eState = 0;
109623 while( (c = zUri[iIn])!=0 && c!='#' ){
109624 iIn++;
109625 if( c=='%'
109626 && sqlite3Isxdigit(zUri[iIn])
109627 && sqlite3Isxdigit(zUri[iIn+1])
109628 ){
109629 int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
109630 octet += sqlite3HexToInt(zUri[iIn++]);
109631
109632 assert( octet>=0 && octet<256 );
109633 if( octet==0 ){
109634 /* This branch is taken when "%00" appears within the URI. In this
109635 ** case we ignore all text in the remainder of the path, name or
109636 ** value currently being parsed. So ignore the current character
109637 ** and skip to the next "?", "=" or "&", as appropriate. */
109638 while( (c = zUri[iIn])!=0 && c!='#'
109639 && (eState!=0 || c!='?')
109640 && (eState!=1 || (c!='=' && c!='&'))
109641 && (eState!=2 || c!='&')
109642 ){
109643 iIn++;
109644 }
109645 continue;
109646 }
109647 c = octet;
109648 }else if( eState==1 && (c=='&' || c=='=') ){
109649 if( zFile[iOut-1]==0 ){
109650 /* An empty option name. Ignore this option altogether. */
109651 while( zUri[iIn] && zUri[iIn]!='#' && zUri[iIn-1]!='&' ) iIn++;
109652 continue;
109653 }
109654 if( c=='&' ){
109655 zFile[iOut++] = '\0';
109656 }else{
109657 eState = 2;
109658 }
109659 c = 0;
109660 }else if( (eState==0 && c=='?') || (eState==2 && c=='&') ){
109661 c = 0;
109662 eState = 1;
109663 }
109664 zFile[iOut++] = c;
109665 }
109666 if( eState==1 ) zFile[iOut++] = '\0';
109667 zFile[iOut++] = '\0';
109668 zFile[iOut++] = '\0';
109669
109670 /* Check if there were any options specified that should be interpreted
109671 ** here. Options that are interpreted here include "vfs" and those that
109672 ** correspond to flags that may be passed to the sqlite3_open_v2()
109673 ** method. */
109674 zOpt = &zFile[sqlite3Strlen30(zFile)+1];
109675 while( zOpt[0] ){
109676 int nOpt = sqlite3Strlen30(zOpt);
109677 char *zVal = &zOpt[nOpt+1];
109678 int nVal = sqlite3Strlen30(zVal);
109679
109680 if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
109681 zVfs = zVal;
109682 }else{
109683 struct OpenMode {
109684 const char *z;
109685 int mode;
109686 } *aMode = 0;
109687 char *zModeType;
109688 int mask;
109689 int limit;
109690
109691 if( nOpt==5 && memcmp("cache", zOpt, 5)==0 ){
109692 static struct OpenMode aCacheMode[] = {
109693 { "shared", SQLITE_OPEN_SHAREDCACHE },
109694 { "private", SQLITE_OPEN_PRIVATECACHE },
109695 { 0, 0 }
109696 };
109697
109698 mask = SQLITE_OPEN_SHAREDCACHE|SQLITE_OPEN_PRIVATECACHE;
109699 aMode = aCacheMode;
109700 limit = mask;
109701 zModeType = "cache";
109702 }
109703 if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
109704 static struct OpenMode aOpenMode[] = {
109705 { "ro", SQLITE_OPEN_READONLY },
109706 { "rw", SQLITE_OPEN_READWRITE },
109707 { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
109708 { 0, 0 }
109709 };
109710
109711 mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
109712 aMode = aOpenMode;
109713 limit = mask & flags;
109714 zModeType = "access";
109715 }
109716
109717 if( aMode ){
109718 int i;
109719 int mode = 0;
109720 for(i=0; aMode[i].z; i++){
109721 const char *z = aMode[i].z;
109722 if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
109723 mode = aMode[i].mode;
109724 break;
109725 }
109726 }
109727 if( mode==0 ){
109728 *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
109729 rc = SQLITE_ERROR;
109730 goto parse_uri_out;
109731 }
109732 if( mode>limit ){
109733 *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
109734 zModeType, zVal);
109735 rc = SQLITE_PERM;
109736 goto parse_uri_out;
109737 }
109738 flags = (flags & ~mask) | mode;
109739 }
109740 }
109741
109742 zOpt = &zVal[nVal+1];
109743 }
109744
109745 }else{
109746 zFile = sqlite3_malloc(nUri+2);
109747 if( !zFile ) return SQLITE_NOMEM;
109748 memcpy(zFile, zUri, nUri);
109749 zFile[nUri] = '\0';
109750 zFile[nUri+1] = '\0';
109751 }
109752
109753 *ppVfs = sqlite3_vfs_find(zVfs);
109754 if( *ppVfs==0 ){
109755 *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs);
109756 rc = SQLITE_ERROR;
109757 }
109758 parse_uri_out:
109759 if( rc!=SQLITE_OK ){
109760 sqlite3_free(zFile);
109761 zFile = 0;
109762 }
109763 *pFlags = flags;
109764 *pzFile = zFile;
109765 return rc;
109766 }
109767
109768
109769 /*
109770 ** This routine does the work of opening a database on behalf of
109771 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
109772 ** is UTF-8 encoded.
109773 */
109774 static int openDatabase(
109775 const char *zFilename, /* Database filename UTF-8 encoded */
109776 sqlite3 **ppDb, /* OUT: Returned database handle */
109777 unsigned int flags, /* Operational flags */
109778 const char *zVfs /* Name of the VFS to use */
109779 ){
109780 sqlite3 *db; /* Store allocated handle here */
109781 int rc; /* Return code */
109782 int isThreadsafe; /* True for threadsafe connections */
109783 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
109784 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
109785
109786 *ppDb = 0;
109787 #ifndef SQLITE_OMIT_AUTOINIT
109788 rc = sqlite3_initialize();
109789 if( rc ) return rc;
@@ -109028,11 +109803,11 @@
109803 assert( SQLITE_OPEN_READWRITE == 0x02 );
109804 assert( SQLITE_OPEN_CREATE == 0x04 );
109805 testcase( (1<<(flags&7))==0x02 ); /* READONLY */
109806 testcase( (1<<(flags&7))==0x04 ); /* READWRITE */
109807 testcase( (1<<(flags&7))==0x40 ); /* READWRITE | CREATE */
109808 if( ((1<<(flags&7)) & 0x46)==0 ) return SQLITE_MISUSE_BKPT;
109809
109810 if( sqlite3GlobalConfig.bCoreMutex==0 ){
109811 isThreadsafe = 0;
109812 }else if( flags & SQLITE_OPEN_NOMUTEX ){
109813 isThreadsafe = 0;
@@ -109109,17 +109884,10 @@
109884 sqlite3HashInit(&db->aCollSeq);
109885 #ifndef SQLITE_OMIT_VIRTUALTABLE
109886 sqlite3HashInit(&db->aModule);
109887 #endif
109888
 
 
 
 
 
 
 
109889 /* Add the default collation sequence BINARY. BINARY works for both UTF-8
109890 ** and UTF-16, so add a version for each to avoid any unnecessary
109891 ** conversions. The only error that can occur here is a malloc() failure.
109892 */
109893 createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0,
@@ -109138,13 +109906,22 @@
109906
109907 /* Also add a UTF-8 case-insensitive collation sequence. */
109908 createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
109909 nocaseCollatingFunc, 0);
109910
109911 /* Parse the filename/URI argument. */
109912 db->openFlags = flags;
109913 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
109914 if( rc!=SQLITE_OK ){
109915 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
109916 sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
109917 sqlite3_free(zErrMsg);
109918 goto opendb_out;
109919 }
109920
109921 /* Open the backend database driver */
109922 rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0,
109923 flags | SQLITE_OPEN_MAIN_DB);
109924 if( rc!=SQLITE_OK ){
109925 if( rc==SQLITE_IOERR_NOMEM ){
109926 rc = SQLITE_NOMEM;
109927 }
@@ -109233,10 +110010,11 @@
110010 sqlite3GlobalConfig.nLookaside);
110011
110012 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
110013
110014 opendb_out:
110015 sqlite3_free(zOpen);
110016 if( db ){
110017 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
110018 sqlite3_mutex_leave(db->mutex);
110019 }
110020 rc = sqlite3_errcode(db);
@@ -109264,11 +110042,11 @@
110042 const char *filename, /* Database filename (UTF-8) */
110043 sqlite3 **ppDb, /* OUT: SQLite db handle */
110044 int flags, /* Flags */
110045 const char *zVfs /* Name of VFS module to use */
110046 ){
110047 return openDatabase(filename, ppDb, (unsigned int)flags, zVfs);
110048 }
110049
110050 #ifndef SQLITE_OMIT_UTF16
110051 /*
110052 ** Open a new database handle.
@@ -109874,10 +110652,32 @@
110652 }
110653 va_end(ap);
110654 #endif /* SQLITE_OMIT_BUILTIN_TEST */
110655 return rc;
110656 }
110657
110658 /*
110659 ** This is a utility routine, useful to VFS implementations, that checks
110660 ** to see if a database file was a URI that contained a specific query
110661 ** parameter, and if so obtains the value of the query parameter.
110662 **
110663 ** The zFilename argument is the filename pointer passed into the xOpen()
110664 ** method of a VFS implementation. The zParam argument is the name of the
110665 ** query parameter we seek. This routine returns the value of the zParam
110666 ** parameter if it exists. If the parameter does not exist, this routine
110667 ** returns a NULL pointer.
110668 */
110669 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
110670 zFilename += sqlite3Strlen30(zFilename) + 1;
110671 while( zFilename[0] ){
110672 int x = strcmp(zFilename, zParam);
110673 zFilename += sqlite3Strlen30(zFilename) + 1;
110674 if( x==0 ) return zFilename;
110675 zFilename += sqlite3Strlen30(zFilename) + 1;
110676 }
110677 return 0;
110678 }
110679
110680 /************** End of main.c ************************************************/
110681 /************** Begin file notify.c ******************************************/
110682 /*
110683 ** 2009 March 3
@@ -110955,10 +111755,11 @@
111755 Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */
111756 sqlite3_int64 iPrevId; /* Previous id read from aDoclist */
111757 char *pNextId; /* Pointer into the body of aDoclist */
111758 char *aDoclist; /* List of docids for full-text queries */
111759 int nDoclist; /* Size of buffer at aDoclist */
111760 int desc; /* True to sort in descending order */
111761 int eEvalmode; /* An FTS3_EVAL_XX constant */
111762 int nRowAvg; /* Average size of database rows, in pages */
111763
111764 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
111765 u32 *aMatchinfo; /* Information about most recent match */
@@ -111137,11 +111938,11 @@
111938 SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
111939 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *, int *);
111940 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64);
111941 SQLITE_PRIVATE void sqlite3Fts3Dequote(char *);
111942
111943 SQLITE_PRIVATE char *sqlite3Fts3FindPositions(Fts3Cursor *, Fts3Expr *, sqlite3_int64, int);
111944 SQLITE_PRIVATE int sqlite3Fts3ExprLoadDoclist(Fts3Cursor *, Fts3Expr *);
111945 SQLITE_PRIVATE int sqlite3Fts3ExprLoadFtDoclist(Fts3Cursor *, Fts3Expr *, char **, int *);
111946 SQLITE_PRIVATE int sqlite3Fts3ExprNearTrim(Fts3Expr *, Fts3Expr *, int);
111947
111948 /* fts3_tokenizer.c */
@@ -111164,10 +111965,11 @@
111965 char **, int, int, const char *, int, Fts3Expr **
111966 );
111967 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
111968 #ifdef SQLITE_TEST
111969 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
111970 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
111971 #endif
111972
111973 /* fts3_aux.c */
111974 SQLITE_PRIVATE int sqlite3Fts3InitAux(sqlite3 *db);
111975
@@ -111284,10 +112086,38 @@
112086 static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
112087 sqlite3_int64 iVal;
112088 *pp += sqlite3Fts3GetVarint(*pp, &iVal);
112089 *pVal += iVal;
112090 }
112091
112092 /*
112093 ** When this function is called, *pp points to the first byte following a
112094 ** varint that is part of a doclist (or position-list, or any other list
112095 ** of varints). This function moves *pp to point to the start of that varint,
112096 ** and decrements the value stored in *pVal by the varint value.
112097 **
112098 ** Argument pStart points to the first byte of the doclist that the
112099 ** varint is part of.
112100 */
112101 static void fts3GetReverseDeltaVarint(
112102 char **pp,
112103 char *pStart,
112104 sqlite3_int64 *pVal
112105 ){
112106 sqlite3_int64 iVal;
112107 char *p = *pp;
112108
112109 /* Pointer p now points at the first byte past the varint we are
112110 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
112111 ** clear on character p[-1]. */
112112 for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
112113 p++;
112114 *pp = p;
112115
112116 sqlite3Fts3GetVarint(p, &iVal);
112117 *pVal -= iVal;
112118 }
112119
112120 /*
112121 ** As long as *pp has not reached its end (pEnd), then do the same
112122 ** as fts3GetDeltaVarint(): read a single varint and add it to *pVal.
112123 ** But if we have reached the end of the varint, just set *pp=0 and
@@ -111389,10 +112219,12 @@
112219 if( *pRc==SQLITE_OK ){
112220 int i; /* Iterator variable */
112221 int rc; /* Return code */
112222 char *zSql; /* SQL statement passed to declare_vtab() */
112223 char *zCols; /* List of user defined columns */
112224
112225 sqlite3_vtab_config(p->db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
112226
112227 /* Create a list of user columns for the virtual table */
112228 zCols = sqlite3_mprintf("%Q, ", p->azColumn[0]);
112229 for(i=1; zCols && i<p->nColumn; i++){
112230 zCols = sqlite3_mprintf("%z%Q, ", zCols, p->azColumn[i]);
@@ -111958,10 +112790,26 @@
112790
112791 if( iCons>=0 ){
112792 pInfo->aConstraintUsage[iCons].argvIndex = 1;
112793 pInfo->aConstraintUsage[iCons].omit = 1;
112794 }
112795
112796 /* Regardless of the strategy selected, FTS can deliver rows in rowid (or
112797 ** docid) order. Both ascending and descending are possible.
112798 */
112799 if( pInfo->nOrderBy==1 ){
112800 struct sqlite3_index_orderby *pOrder = &pInfo->aOrderBy[0];
112801 if( pOrder->iColumn<0 || pOrder->iColumn==p->nColumn+1 ){
112802 if( pOrder->desc ){
112803 pInfo->idxStr = "DESC";
112804 }else{
112805 pInfo->idxStr = "ASC";
112806 }
112807 }
112808 pInfo->orderByConsumed = 1;
112809 }
112810
112811 return SQLITE_OK;
112812 }
112813
112814 /*
112815 ** Implementation of xOpen method.
@@ -112015,11 +112863,11 @@
112863 if( rc==SQLITE_OK ){
112864 /* If no row was found and no error has occured, then the %_content
112865 ** table is missing a row that is present in the full-text index.
112866 ** The data structures are corrupt.
112867 */
112868 rc = SQLITE_CORRUPT_VTAB;
112869 }
112870 pCsr->isEof = 1;
112871 if( pContext ){
112872 sqlite3_result_error_code(pContext, rc);
112873 }
@@ -112075,11 +112923,11 @@
112923 ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
112924 */
112925 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
112926 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
112927 if( zCsr>zEnd ){
112928 return SQLITE_CORRUPT_VTAB;
112929 }
112930
112931 while( zCsr<zEnd && (piFirst || piLast) ){
112932 int cmp; /* memcmp() result */
112933 int nSuffix; /* Size of term suffix */
@@ -112093,11 +112941,11 @@
112941 }
112942 isFirstTerm = 0;
112943 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
112944
112945 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
112946 rc = SQLITE_CORRUPT_VTAB;
112947 goto finish_scan;
112948 }
112949 if( nPrefix+nSuffix>nAlloc ){
112950 char *zNew;
112951 nAlloc = (nPrefix+nSuffix) * 2;
@@ -113862,16 +114710,24 @@
114710 rc = sqlite3_reset(pCsr->pStmt);
114711 break;
114712 }
114713 pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
114714 }else{
114715 if( pCsr->desc==0 ){
114716 if( pCsr->pNextId>=&pCsr->aDoclist[pCsr->nDoclist] ){
114717 pCsr->isEof = 1;
114718 break;
114719 }
114720 fts3GetDeltaVarint(&pCsr->pNextId, &pCsr->iPrevId);
114721 }else{
114722 fts3GetReverseDeltaVarint(&pCsr->pNextId,pCsr->aDoclist,&pCsr->iPrevId);
114723 if( pCsr->pNextId<=pCsr->aDoclist ){
114724 pCsr->isEof = 1;
114725 break;
114726 }
114727 }
114728 sqlite3_reset(pCsr->pStmt);
 
114729 pCsr->isRequireSeek = 1;
114730 pCsr->isMatchinfoNeeded = 1;
114731 }
114732 }while( SQLITE_OK==(rc = fts3EvalDeferred(pCsr, &res)) && res==0 );
114733
@@ -113900,12 +114756,12 @@
114756 const char *idxStr, /* Unused */
114757 int nVal, /* Number of elements in apVal */
114758 sqlite3_value **apVal /* Arguments for the indexing scheme */
114759 ){
114760 const char *azSql[] = {
114761 "SELECT %s FROM %Q.'%q_content' AS x WHERE docid = ?", /* non-full-scan */
114762 "SELECT %s FROM %Q.'%q_content' AS x ORDER BY docid %s", /* full-scan */
114763 };
114764 int rc; /* Return code */
114765 char *zSql; /* SQL statement used to access %_content */
114766 Fts3Table *p = (Fts3Table *)pCursor->pVtab;
114767 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
@@ -113957,11 +114813,13 @@
114813 ** statement loops through all rows of the %_content table. For a
114814 ** full-text query or docid lookup, the statement retrieves a single
114815 ** row by docid.
114816 */
114817 zSql = (char *)azSql[idxNum==FTS3_FULLSCAN_SEARCH];
114818 zSql = sqlite3_mprintf(
114819 zSql, p->zReadExprlist, p->zDb, p->zName, (idxStr ? idxStr : "ASC")
114820 );
114821 if( !zSql ){
114822 rc = SQLITE_NOMEM;
114823 }else{
114824 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
114825 sqlite3_free(zSql);
@@ -113969,11 +114827,26 @@
114827 if( rc==SQLITE_OK && idxNum==FTS3_DOCID_SEARCH ){
114828 rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]);
114829 }
114830 pCsr->eSearch = (i16)idxNum;
114831
114832 assert( pCsr->desc==0 );
114833 if( rc!=SQLITE_OK ) return rc;
114834 if( rc==SQLITE_OK && pCsr->nDoclist>0 && idxStr && idxStr[0]=='D' ){
114835 sqlite3_int64 iDocid = 0;
114836 char *csr = pCsr->aDoclist;
114837 while( csr<&pCsr->aDoclist[pCsr->nDoclist] ){
114838 fts3GetDeltaVarint(&csr, &iDocid);
114839 }
114840 pCsr->pNextId = csr;
114841 pCsr->iPrevId = iDocid;
114842 pCsr->desc = 1;
114843 pCsr->isRequireSeek = 1;
114844 pCsr->isMatchinfoNeeded = 1;
114845 pCsr->eEvalmode = FTS3_EVAL_NEXT;
114846 return SQLITE_OK;
114847 }
114848 return fts3NextMethod(pCursor);
114849 }
114850
114851 /*
114852 ** This is the xEof method of the virtual table. SQLite calls this
@@ -114121,17 +114994,37 @@
114994 pCsr->eEvalmode = FTS3_EVAL_MATCHINFO;
114995 rc = fts3EvalExpr(pCsr, pExpr, paDoclist, pnDoclist, 1);
114996 pCsr->eEvalmode = FTS3_EVAL_NEXT;
114997 return rc;
114998 }
114999
115000
115001 /*
115002 ** When called, *ppPoslist must point to the byte immediately following the
115003 ** end of a position-list. i.e. ( (*ppPoslist)[-1]==POS_END ). This function
115004 ** moves *ppPoslist so that it instead points to the first byte of the
115005 ** same position list.
115006 */
115007 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
115008 char *p = &(*ppPoslist)[-3];
115009 char c = p[1];
115010 while( p>pStart && (*p & 0x80) | c ){
115011 c = *p--;
115012 }
115013 if( p>pStart ){ p = &p[2]; }
115014 while( *p++&0x80 );
115015 *ppPoslist = p;
115016 }
115017
115018
115019 /*
115020 ** After ExprLoadDoclist() (see above) has been called, this function is
115021 ** used to iterate/search through the position lists that make up the doclist
115022 ** stored in pExpr->aDoclist.
115023 */
115024 SQLITE_PRIVATE char *sqlite3Fts3FindPositions(
115025 Fts3Cursor *pCursor, /* Associate FTS3 cursor */
115026 Fts3Expr *pExpr, /* Access this expressions doclist */
115027 sqlite3_int64 iDocid, /* Docid associated with requested pos-list */
115028 int iCol /* Column of requested pos-list */
115029 ){
115030 assert( pExpr->isLoaded );
@@ -114138,23 +115031,39 @@
115031 if( pExpr->aDoclist ){
115032 char *pEnd = &pExpr->aDoclist[pExpr->nDoclist];
115033 char *pCsr;
115034
115035 if( pExpr->pCurrent==0 ){
115036 if( pCursor->desc==0 ){
115037 pExpr->pCurrent = pExpr->aDoclist;
115038 pExpr->iCurrent = 0;
115039 fts3GetDeltaVarint(&pExpr->pCurrent, &pExpr->iCurrent);
115040 }else{
115041 pCsr = pExpr->aDoclist;
115042 while( pCsr<pEnd ){
115043 fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
115044 fts3PoslistCopy(0, &pCsr);
115045 }
115046 fts3ReversePoslist(pExpr->aDoclist, &pCsr);
115047 pExpr->pCurrent = pCsr;
115048 }
115049 }
115050 pCsr = pExpr->pCurrent;
115051 assert( pCsr );
115052
115053 while( (pCursor->desc==0 && pCsr<pEnd)
115054 || (pCursor->desc && pCsr>pExpr->aDoclist)
115055 ){
115056 if( pCursor->desc==0 && pExpr->iCurrent<iDocid ){
115057 fts3PoslistCopy(0, &pCsr);
115058 if( pCsr<pEnd ){
115059 fts3GetDeltaVarint(&pCsr, &pExpr->iCurrent);
115060 }
115061 pExpr->pCurrent = pCsr;
115062 }else if( pCursor->desc && pExpr->iCurrent>iDocid ){
115063 fts3GetReverseDeltaVarint(&pCsr, pExpr->aDoclist, &pExpr->iCurrent);
115064 fts3ReversePoslist(pExpr->aDoclist, &pCsr);
115065 pExpr->pCurrent = pCsr;
115066 }else{
115067 if( pExpr->iCurrent==iDocid ){
115068 int iThis = 0;
115069 if( iCol<0 ){
@@ -114407,13 +115316,24 @@
115316 "ALTER TABLE %Q.'%q_segdir' RENAME TO '%q_segdir';",
115317 p->zDb, p->zName, zName
115318 );
115319 return rc;
115320 }
115321
115322 static int fts3SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
115323 return sqlite3Fts3PendingTermsFlush((Fts3Table *)pVtab);
115324 }
115325 static int fts3ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
115326 return SQLITE_OK;
115327 }
115328 static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
115329 sqlite3Fts3PendingTermsClear((Fts3Table *)pVtab);
115330 return SQLITE_OK;
115331 }
115332
115333 static const sqlite3_module fts3Module = {
115334 /* iVersion */ 2,
115335 /* xCreate */ fts3CreateMethod,
115336 /* xConnect */ fts3ConnectMethod,
115337 /* xBestIndex */ fts3BestIndexMethod,
115338 /* xDisconnect */ fts3DisconnectMethod,
115339 /* xDestroy */ fts3DestroyMethod,
@@ -114429,10 +115349,13 @@
115349 /* xSync */ fts3SyncMethod,
115350 /* xCommit */ fts3CommitMethod,
115351 /* xRollback */ fts3RollbackMethod,
115352 /* xFindFunction */ fts3FindFunctionMethod,
115353 /* xRename */ fts3RenameMethod,
115354 /* xSavepoint */ fts3SavepointMethod,
115355 /* xRelease */ fts3ReleaseMethod,
115356 /* xRollbackTo */ fts3RollbackToMethod,
115357 };
115358
115359 /*
115360 ** This function is registered as the module destructor (called when an
115361 ** FTS3 enabled database connection is closed). It frees the memory
@@ -114474,10 +115397,15 @@
115397
115398 #ifdef SQLITE_ENABLE_ICU
115399 const sqlite3_tokenizer_module *pIcu = 0;
115400 sqlite3Fts3IcuTokenizerModule(&pIcu);
115401 #endif
115402
115403 #ifdef SQLITE_TEST
115404 rc = sqlite3Fts3InitTerm(db);
115405 if( rc!=SQLITE_OK ) return rc;
115406 #endif
115407
115408 rc = sqlite3Fts3InitAux(db);
115409 if( rc!=SQLITE_OK ) return rc;
115410
115411 sqlite3Fts3SimpleTokenizerModule(&pSimple);
@@ -117995,11 +118923,11 @@
118923 sqlite3_bind_int64(pStmt, 1, iDocid);
118924 }
118925 rc = sqlite3_step(pStmt);
118926 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
118927 rc = sqlite3_reset(pStmt);
118928 if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB;
118929 pStmt = 0;
118930 }else{
118931 rc = SQLITE_OK;
118932 }
118933 }
@@ -118451,18 +119379,18 @@
119379 ** full-text index.
119380 */
119381 static void fts3DeleteTerms(
119382 int *pRC, /* Result code */
119383 Fts3Table *p, /* The FTS table to delete from */
119384 sqlite3_value *pRowid, /* The docid to be deleted */
119385 u32 *aSz /* Sizes of deleted document written here */
119386 ){
119387 int rc;
119388 sqlite3_stmt *pSelect;
119389
119390 if( *pRC ) return;
119391 rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid);
119392 if( rc==SQLITE_OK ){
119393 if( SQLITE_ROW==sqlite3_step(pSelect) ){
119394 int i;
119395 for(i=1; i<=p->nColumn; i++){
119396 const char *zText = (const char *)sqlite3_column_text(pSelect, i);
@@ -118676,11 +119604,11 @@
119604 pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
119605 pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
119606 if( nPrefix<0 || nSuffix<=0
119607 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
119608 ){
119609 return SQLITE_CORRUPT_VTAB;
119610 }
119611
119612 if( nPrefix+nSuffix>pReader->nTermAlloc ){
119613 int nNew = (nPrefix+nSuffix)*2;
119614 char *zNew = sqlite3_realloc(pReader->zTerm, nNew);
@@ -118702,11 +119630,11 @@
119630 ** of these statements is untrue, then the data structure is corrupt.
119631 */
119632 if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode]
119633 || pReader->aDoclist[pReader->nDoclist-1]
119634 ){
119635 return SQLITE_CORRUPT_VTAB;
119636 }
119637 return SQLITE_OK;
119638 }
119639
119640 /*
@@ -118827,11 +119755,11 @@
119755 while( a<pEnd ){
119756 a += sqlite3Fts3GetVarint(a, &nByte);
119757 }
119758 if( nDoc==0 || nByte==0 ){
119759 sqlite3_reset(pStmt);
119760 return SQLITE_CORRUPT_VTAB;
119761 }
119762
119763 pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
119764 assert( pCsr->nRowAvg>0 );
119765 rc = sqlite3_reset(pStmt);
@@ -119598,20 +120526,20 @@
120526
120527 /*
120528 ** The first value in the apVal[] array is assumed to contain an integer.
120529 ** This function tests if there exist any documents with docid values that
120530 ** are different from that integer. i.e. if deleting the document with docid
120531 ** pRowid would mean the FTS3 table were empty.
120532 **
120533 ** If successful, *pisEmpty is set to true if the table is empty except for
120534 ** document pRowid, or false otherwise, and SQLITE_OK is returned. If an
120535 ** error occurs, an SQLite error code is returned.
120536 */
120537 static int fts3IsEmpty(Fts3Table *p, sqlite3_value *pRowid, int *pisEmpty){
120538 sqlite3_stmt *pStmt;
120539 int rc;
120540 rc = fts3SqlStmt(p, SQL_IS_EMPTY, &pStmt, &pRowid);
120541 if( rc==SQLITE_OK ){
120542 if( SQLITE_ROW==sqlite3_step(pStmt) ){
120543 *pisEmpty = sqlite3_column_int(pStmt, 0);
120544 }
120545 rc = sqlite3_reset(pStmt);
@@ -120331,10 +121259,44 @@
121259 pToken->pDeferred = pDeferred;
121260
121261 return SQLITE_OK;
121262 }
121263
121264 /*
121265 ** SQLite value pRowid contains the rowid of a row that may or may not be
121266 ** present in the FTS3 table. If it is, delete it and adjust the contents
121267 ** of subsiduary data structures accordingly.
121268 */
121269 static int fts3DeleteByRowid(
121270 Fts3Table *p,
121271 sqlite3_value *pRowid,
121272 int *pnDoc,
121273 u32 *aSzDel
121274 ){
121275 int isEmpty = 0;
121276 int rc = fts3IsEmpty(p, pRowid, &isEmpty);
121277 if( rc==SQLITE_OK ){
121278 if( isEmpty ){
121279 /* Deleting this row means the whole table is empty. In this case
121280 ** delete the contents of all three tables and throw away any
121281 ** data in the pendingTerms hash table. */
121282 rc = fts3DeleteAll(p);
121283 *pnDoc = *pnDoc - 1;
121284 }else{
121285 sqlite3_int64 iRemove = sqlite3_value_int64(pRowid);
121286 rc = fts3PendingTermsDocid(p, iRemove);
121287 fts3DeleteTerms(&rc, p, pRowid, aSzDel);
121288 fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid);
121289 if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1;
121290 if( p->bHasDocsize ){
121291 fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, &pRowid);
121292 }
121293 }
121294 }
121295
121296 return rc;
121297 }
121298
121299 /*
121300 ** This function does the work for the xUpdate method of FTS3 virtual
121301 ** tables.
121302 */
@@ -120349,50 +121311,95 @@
121311 int isRemove = 0; /* True for an UPDATE or DELETE */
121312 sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */
121313 u32 *aSzIns; /* Sizes of inserted documents */
121314 u32 *aSzDel; /* Sizes of deleted documents */
121315 int nChng = 0; /* Net change in number of documents */
121316 int bInsertDone = 0;
121317
121318 assert( p->pSegments==0 );
121319
121320 /* Check for a "special" INSERT operation. One of the form:
121321 **
121322 ** INSERT INTO xyz(xyz) VALUES('command');
121323 */
121324 if( nArg>1
121325 && sqlite3_value_type(apVal[0])==SQLITE_NULL
121326 && sqlite3_value_type(apVal[p->nColumn+2])!=SQLITE_NULL
121327 ){
121328 return fts3SpecialInsert(p, apVal[p->nColumn+2]);
121329 }
121330
121331 /* Allocate space to hold the change in document sizes */
121332 aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 );
121333 if( aSzIns==0 ) return SQLITE_NOMEM;
121334 aSzDel = &aSzIns[p->nColumn+1];
121335 memset(aSzIns, 0, sizeof(aSzIns[0])*(p->nColumn+1)*2);
121336
121337 /* If this is an INSERT operation, or an UPDATE that modifies the rowid
121338 ** value, then this operation requires constraint handling.
121339 **
121340 ** If the on-conflict mode is REPLACE, this means that the existing row
121341 ** should be deleted from the database before inserting the new row. Or,
121342 ** if the on-conflict mode is other than REPLACE, then this method must
121343 ** detect the conflict and return SQLITE_CONSTRAINT before beginning to
121344 ** modify the database file.
121345 */
121346 if( nArg>1 ){
121347 /* Find the value object that holds the new rowid value. */
121348 sqlite3_value *pNewRowid = apVal[3+p->nColumn];
121349 if( sqlite3_value_type(pNewRowid)==SQLITE_NULL ){
121350 pNewRowid = apVal[1];
121351 }
121352
121353 if( sqlite3_value_type(pNewRowid)!=SQLITE_NULL && (
121354 sqlite3_value_type(apVal[0])==SQLITE_NULL
121355 || sqlite3_value_int64(apVal[0])!=sqlite3_value_int64(pNewRowid)
121356 )){
121357 /* The new rowid is not NULL (in this case the rowid will be
121358 ** automatically assigned and there is no chance of a conflict), and
121359 ** the statement is either an INSERT or an UPDATE that modifies the
121360 ** rowid column. So if the conflict mode is REPLACE, then delete any
121361 ** existing row with rowid=pNewRowid.
121362 **
121363 ** Or, if the conflict mode is not REPLACE, insert the new record into
121364 ** the %_content table. If we hit the duplicate rowid constraint (or any
121365 ** other error) while doing so, return immediately.
121366 **
121367 ** This branch may also run if pNewRowid contains a value that cannot
121368 ** be losslessly converted to an integer. In this case, the eventual
121369 ** call to fts3InsertData() (either just below or further on in this
121370 ** function) will return SQLITE_MISMATCH. If fts3DeleteByRowid is
121371 ** invoked, it will delete zero rows (since no row will have
121372 ** docid=$pNewRowid if $pNewRowid is not an integer value).
121373 */
121374 if( sqlite3_vtab_on_conflict(p->db)==SQLITE_REPLACE ){
121375 rc = fts3DeleteByRowid(p, pNewRowid, &nChng, aSzDel);
121376 }else{
121377 rc = fts3InsertData(p, apVal, pRowid);
121378 bInsertDone = 1;
121379 }
121380 }
121381 }
121382 if( rc!=SQLITE_OK ){
121383 sqlite3_free(aSzIns);
121384 return rc;
121385 }
121386
121387 /* If this is a DELETE or UPDATE operation, remove the old record. */
121388 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
121389 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
121390 rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
121391 isRemove = 1;
121392 iRemove = sqlite3_value_int64(apVal[0]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121393 }
121394
121395 /* If this is an INSERT or UPDATE operation, insert the new record. */
121396 if( nArg>1 && rc==SQLITE_OK ){
121397 if( bInsertDone==0 ){
121398 rc = fts3InsertData(p, apVal, pRowid);
121399 if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB;
121400 }
121401 if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){
121402 rc = fts3PendingTermsDocid(p, *pRowid);
121403 }
121404 if( rc==SQLITE_OK ){
121405 rc = fts3InsertTerms(p, apVal, aSzIns);
@@ -120852,11 +121859,11 @@
121859 SnippetPhrase *pPhrase = &p->aPhrase[iPhrase];
121860 char *pCsr;
121861
121862 pPhrase->nToken = pExpr->pPhrase->nToken;
121863
121864 pCsr = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->pCsr->iPrevId, p->iCol);
121865 if( pCsr ){
121866 int iFirst = 0;
121867 pPhrase->pList = pCsr;
121868 fts3GetDeltaPosition(&pCsr, &iFirst);
121869 pPhrase->pHead = pCsr;
@@ -121325,11 +122332,11 @@
122332 for(i=0; i<p->nCol; i++) p->aMatchinfo[iStart+i*3] = 0;
122333
122334 if( pExpr->aDoclist ){
122335 char *pCsr;
122336
122337 pCsr = sqlite3Fts3FindPositions(p->pCursor, pExpr, p->pCursor->iPrevId, -1);
122338 if( pCsr ){
122339 fts3LoadColumnlistCounts(&pCsr, &p->aMatchinfo[iStart], 0);
122340 }
122341 }
122342
@@ -121397,11 +122404,11 @@
122404 pStmt = *ppStmt;
122405 assert( sqlite3_data_count(pStmt)==1 );
122406
122407 a = sqlite3_column_blob(pStmt, 0);
122408 a += sqlite3Fts3GetVarint(a, &nDoc);
122409 if( nDoc==0 ) return SQLITE_CORRUPT_VTAB;
122410 *pnDoc = (u32)nDoc;
122411
122412 if( paLen ) *paLen = a;
122413 return SQLITE_OK;
122414 }
@@ -121492,11 +122499,11 @@
122499 (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
122500 for(i=0; i<pInfo->nPhrase; i++){
122501 LcsIterator *pIter = &aIter[i];
122502 nToken -= pIter->pExpr->pPhrase->nToken;
122503 pIter->iPosOffset = nToken;
122504 pIter->pRead = sqlite3Fts3FindPositions(pCsr,pIter->pExpr,pCsr->iPrevId,-1);
122505 if( pIter->pRead ){
122506 pIter->iPos = pIter->iPosOffset;
122507 fts3LcsIteratorAdvance(&aIter[i]);
122508 }else{
122509 pIter->iCol = LCS_ITERATOR_FINISHED;
@@ -121845,10 +122852,11 @@
122852 int iPos; /* Position just read from pList */
122853 int iOff; /* Offset of this term from read positions */
122854 };
122855
122856 struct TermOffsetCtx {
122857 Fts3Cursor *pCsr;
122858 int iCol; /* Column of table to populate aTerm for */
122859 int iTerm;
122860 sqlite3_int64 iDocid;
122861 TermOffset *aTerm;
122862 };
@@ -121862,11 +122870,11 @@
122870 int iTerm; /* For looping through nTerm phrase terms */
122871 char *pList; /* Pointer to position list for phrase */
122872 int iPos = 0; /* First position in position-list */
122873
122874 UNUSED_PARAMETER(iPhrase);
122875 pList = sqlite3Fts3FindPositions(p->pCsr, pExpr, p->iDocid, p->iCol);
122876 nTerm = pExpr->pPhrase->nToken;
122877 if( pList ){
122878 fts3GetDeltaPosition(&pList, &iPos);
122879 assert( iPos>=0 );
122880 }
@@ -121915,10 +122923,11 @@
122923 if( 0==sCtx.aTerm ){
122924 rc = SQLITE_NOMEM;
122925 goto offsets_out;
122926 }
122927 sCtx.iDocid = pCsr->iPrevId;
122928 sCtx.pCsr = pCsr;
122929
122930 /* Loop through the table columns, appending offset information to
122931 ** string-buffer res for each column.
122932 */
122933 for(iCol=0; iCol<pTab->nColumn; iCol++){
@@ -121990,11 +122999,11 @@
122999 sqlite3_snprintf(sizeof(aBuffer), aBuffer,
123000 "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
123001 );
123002 rc = fts3StringAppend(&res, aBuffer, -1);
123003 }else if( rc==SQLITE_DONE ){
123004 rc = SQLITE_CORRUPT_VTAB;
123005 }
123006 }
123007 }
123008 if( rc==SQLITE_DONE ){
123009 rc = SQLITE_OK;
@@ -122578,29 +123587,29 @@
123587 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
123588 */
123589 if( pNode && iNode==1 ){
123590 pRtree->iDepth = readInt16(pNode->zData);
123591 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
123592 rc = SQLITE_CORRUPT_VTAB;
123593 }
123594 }
123595
123596 /* If no error has occurred so far, check if the "number of entries"
123597 ** field on the node is too large. If so, set the return code to
123598 ** SQLITE_CORRUPT_VTAB.
123599 */
123600 if( pNode && rc==SQLITE_OK ){
123601 if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
123602 rc = SQLITE_CORRUPT_VTAB;
123603 }
123604 }
123605
123606 if( rc==SQLITE_OK ){
123607 if( pNode!=0 ){
123608 nodeHashInsert(pRtree, pNode);
123609 }else{
123610 rc = SQLITE_CORRUPT_VTAB;
123611 }
123612 *ppNode = pNode;
123613 }else{
123614 sqlite3_free(pNode);
123615 *ppNode = 0;
@@ -123123,11 +124132,11 @@
124132 if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
124133 *piIndex = ii;
124134 return SQLITE_OK;
124135 }
124136 }
124137 return SQLITE_CORRUPT_VTAB;
124138 }
124139
124140 /*
124141 ** Return the index of the cell containing a pointer to node pNode
124142 ** in its parent. If pNode is the root node, return -1.
@@ -123718,11 +124727,11 @@
124727 RtreeNode *pParent = p->pParent;
124728 RtreeCell cell;
124729 int iCell;
124730
124731 if( nodeParentIndex(pRtree, p, &iCell) ){
124732 return SQLITE_CORRUPT_VTAB;
124733 }
124734
124735 nodeGetCell(pRtree, pParent, iCell, &cell);
124736 if( !cellContains(pRtree, &cell, pCell) ){
124737 cellUnion(pRtree, &cell, pCell);
@@ -124390,11 +125399,11 @@
125399 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
125400 }
125401 }
125402 rc = sqlite3_reset(pRtree->pReadParent);
125403 if( rc==SQLITE_OK ) rc = rc2;
125404 if( rc==SQLITE_OK && !pChild->pParent ) rc = SQLITE_CORRUPT_VTAB;
125405 pChild = pChild->pParent;
125406 }
125407 return rc;
125408 }
125409
@@ -124685,10 +125694,94 @@
125694 sqlite3_step(pRtree->pWriteRowid);
125695 rc = sqlite3_reset(pRtree->pWriteRowid);
125696 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
125697 return rc;
125698 }
125699
125700 /*
125701 ** Remove the entry with rowid=iDelete from the r-tree structure.
125702 */
125703 static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
125704 int rc; /* Return code */
125705 RtreeNode *pLeaf; /* Leaf node containing record iDelete */
125706 int iCell; /* Index of iDelete cell in pLeaf */
125707 RtreeNode *pRoot; /* Root node of rtree structure */
125708
125709
125710 /* Obtain a reference to the root node to initialise Rtree.iDepth */
125711 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
125712
125713 /* Obtain a reference to the leaf node that contains the entry
125714 ** about to be deleted.
125715 */
125716 if( rc==SQLITE_OK ){
125717 rc = findLeafNode(pRtree, iDelete, &pLeaf);
125718 }
125719
125720 /* Delete the cell in question from the leaf node. */
125721 if( rc==SQLITE_OK ){
125722 int rc2;
125723 rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
125724 if( rc==SQLITE_OK ){
125725 rc = deleteCell(pRtree, pLeaf, iCell, 0);
125726 }
125727 rc2 = nodeRelease(pRtree, pLeaf);
125728 if( rc==SQLITE_OK ){
125729 rc = rc2;
125730 }
125731 }
125732
125733 /* Delete the corresponding entry in the <rtree>_rowid table. */
125734 if( rc==SQLITE_OK ){
125735 sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete);
125736 sqlite3_step(pRtree->pDeleteRowid);
125737 rc = sqlite3_reset(pRtree->pDeleteRowid);
125738 }
125739
125740 /* Check if the root node now has exactly one child. If so, remove
125741 ** it, schedule the contents of the child for reinsertion and
125742 ** reduce the tree height by one.
125743 **
125744 ** This is equivalent to copying the contents of the child into
125745 ** the root node (the operation that Gutman's paper says to perform
125746 ** in this scenario).
125747 */
125748 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
125749 int rc2;
125750 RtreeNode *pChild;
125751 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
125752 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
125753 if( rc==SQLITE_OK ){
125754 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
125755 }
125756 rc2 = nodeRelease(pRtree, pChild);
125757 if( rc==SQLITE_OK ) rc = rc2;
125758 if( rc==SQLITE_OK ){
125759 pRtree->iDepth--;
125760 writeInt16(pRoot->zData, pRtree->iDepth);
125761 pRoot->isDirty = 1;
125762 }
125763 }
125764
125765 /* Re-insert the contents of any underfull nodes removed from the tree. */
125766 for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
125767 if( rc==SQLITE_OK ){
125768 rc = reinsertNodeContent(pRtree, pLeaf);
125769 }
125770 pRtree->pDeleted = pLeaf->pNext;
125771 sqlite3_free(pLeaf);
125772 }
125773
125774 /* Release the reference to the root node. */
125775 if( rc==SQLITE_OK ){
125776 rc = nodeRelease(pRtree, pRoot);
125777 }else{
125778 nodeRelease(pRtree, pRoot);
125779 }
125780
125781 return rc;
125782 }
125783
125784 /*
125785 ** The xUpdate method for rtree module virtual tables.
125786 */
125787 static int rtreeUpdate(
@@ -124697,107 +125790,29 @@
125790 sqlite3_value **azData,
125791 sqlite_int64 *pRowid
125792 ){
125793 Rtree *pRtree = (Rtree *)pVtab;
125794 int rc = SQLITE_OK;
125795 RtreeCell cell; /* New cell to insert if nData>1 */
125796 int bHaveRowid = 0; /* Set to 1 after new rowid is determined */
125797
125798 rtreeReference(pRtree);
 
125799 assert(nData>=1);
125800
125801 /* Constraint handling. A write operation on an r-tree table may return
125802 ** SQLITE_CONSTRAINT for two reasons:
125803 **
125804 ** 1. A duplicate rowid value, or
125805 ** 2. The supplied data violates the "x2>=x1" constraint.
125806 **
125807 ** In the first case, if the conflict-handling mode is REPLACE, then
125808 ** the conflicting row can be removed before proceeding. In the second
125809 ** case, SQLITE_CONSTRAINT must be returned regardless of the
125810 ** conflict-handling mode specified by the user.
125811 */
125812 if( nData>1 ){
125813 int ii;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125814
125815 /* Populate the cell.aCoord[] array. The first coordinate is azData[3]. */
125816 assert( nData==(pRtree->nDim*2 + 3) );
125817 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
125818 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
@@ -124817,22 +125832,53 @@
125832 goto constraint;
125833 }
125834 }
125835 }
125836
125837 /* If a rowid value was supplied, check if it is already present in
125838 ** the table. If so, the constraint has failed. */
125839 if( sqlite3_value_type(azData[2])!=SQLITE_NULL ){
 
125840 cell.iRowid = sqlite3_value_int64(azData[2]);
125841 if( sqlite3_value_type(azData[0])==SQLITE_NULL
125842 || sqlite3_value_int64(azData[0])!=cell.iRowid
125843 ){
125844 int steprc;
125845 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
125846 steprc = sqlite3_step(pRtree->pReadRowid);
125847 rc = sqlite3_reset(pRtree->pReadRowid);
125848 if( SQLITE_ROW==steprc ){
125849 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
125850 rc = rtreeDeleteRowid(pRtree, cell.iRowid);
125851 }else{
125852 rc = SQLITE_CONSTRAINT;
125853 goto constraint;
125854 }
125855 }
125856 }
125857 bHaveRowid = 1;
125858 }
125859 }
125860
125861 /* If azData[0] is not an SQL NULL value, it is the rowid of a
125862 ** record to delete from the r-tree table. The following block does
125863 ** just that.
125864 */
125865 if( sqlite3_value_type(azData[0])!=SQLITE_NULL ){
125866 rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(azData[0]));
125867 }
125868
125869 /* If the azData[] array contains more than one element, elements
125870 ** (azData[2]..azData[argc-1]) contain a new record to insert into
125871 ** the r-tree structure.
125872 */
125873 if( rc==SQLITE_OK && nData>1 ){
125874 /* Insert the new record into the r-tree */
125875 RtreeNode *pLeaf;
125876
125877 /* Figure out the rowid of the new row. */
125878 if( bHaveRowid==0 ){
125879 rc = newRowid(pRtree, &cell.iRowid);
125880 }
125881 *pRowid = cell.iRowid;
125882
125883 if( rc==SQLITE_OK ){
125884 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
@@ -125068,10 +126114,12 @@
126114 int iErr = (argc<6) ? 2 : argc>(RTREE_MAX_DIMENSIONS*2+4) ? 3 : argc%2;
126115 if( aErrMsg[iErr] ){
126116 *pzErr = sqlite3_mprintf("%s", aErrMsg[iErr]);
126117 return SQLITE_ERROR;
126118 }
126119
126120 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
126121
126122 /* Allocate the sqlite3_vtab structure */
126123 nDb = strlen(argv[1]);
126124 nName = strlen(argv[2]);
126125 pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
126126
+339 -77
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.6.1"
111
-#define SQLITE_VERSION_NUMBER 3007006
112
-#define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56"
110
+#define SQLITE_VERSION "3.7.7"
111
+#define SQLITE_VERSION_NUMBER 3007007
112
+#define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -373,11 +373,12 @@
373373
** Many SQLite functions return an integer result code from the set shown
374374
** here in order to indicates success or failure.
375375
**
376376
** New error codes may be added in future versions of SQLite.
377377
**
378
-** See also: [SQLITE_IOERR_READ | extended result codes]
378
+** See also: [SQLITE_IOERR_READ | extended result codes],
379
+** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes].
379380
*/
380381
#define SQLITE_OK 0 /* Successful result */
381382
/* beginning-of-error-codes */
382383
#define SQLITE_ERROR 1 /* SQL error or missing database */
383384
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -455,25 +456,26 @@
455456
#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
456457
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
457458
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
458459
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
459460
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
461
+#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
460462
461463
/*
462464
** CAPI3REF: Flags For File Open Operations
463465
**
464466
** These bit values are intended for use in the
465467
** 3rd parameter to the [sqlite3_open_v2()] interface and
466
-** in the 4th parameter to the xOpen method of the
467
-** [sqlite3_vfs] object.
468
+** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
468469
*/
469470
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
470471
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
471472
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
472473
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
473474
#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
474475
#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
476
+#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
475477
#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
476478
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
477479
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
478480
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
479481
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -580,21 +582,22 @@
580582
};
581583
582584
/*
583585
** CAPI3REF: OS Interface File Virtual Methods Object
584586
**
585
-** Every file opened by the [sqlite3_vfs] xOpen method populates an
587
+** Every file opened by the [sqlite3_vfs.xOpen] method populates an
586588
** [sqlite3_file] object (or, more commonly, a subclass of the
587589
** [sqlite3_file] object) with a pointer to an instance of this object.
588590
** This object defines the methods used to perform various operations
589591
** against the open file represented by the [sqlite3_file] object.
590592
**
591
-** If the xOpen method sets the sqlite3_file.pMethods element
593
+** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
592594
** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
593
-** may be invoked even if the xOpen reported that it failed. The
594
-** only way to prevent a call to xClose following a failed xOpen
595
-** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
595
+** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
596
+** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
597
+** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
598
+** to NULL.
596599
**
597600
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
598601
** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
599602
** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
600603
** flag may be ORed in to indicate that only the data of the file
@@ -759,10 +762,11 @@
759762
*/
760763
typedef struct sqlite3_mutex sqlite3_mutex;
761764
762765
/*
763766
** CAPI3REF: OS Interface Object
767
+** KEYWORDS: VFS VFSes
764768
**
765769
** An instance of the sqlite3_vfs object defines the interface between
766770
** the SQLite core and the underlying operating system. The "vfs"
767771
** in the name of the object stands for "virtual file system".
768772
**
@@ -791,10 +795,11 @@
791795
** object once the object has been registered.
792796
**
793797
** The zName field holds the name of the VFS module. The name must
794798
** be unique across all VFS modules.
795799
**
800
+** [[sqlite3_vfs.xOpen]]
796801
** ^SQLite guarantees that the zFilename parameter to xOpen
797802
** is either a NULL pointer or string obtained
798803
** from xFullPathname() with an optional suffix added.
799804
** ^If a suffix is added to the zFilename parameter, it will
800805
** consist of a single "-" character followed by no more than
@@ -868,10 +873,11 @@
868873
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
869874
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
870875
** element will be valid after xOpen returns regardless of the success
871876
** or failure of the xOpen call.
872877
**
878
+** [[sqlite3_vfs.xAccess]]
873879
** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
874880
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
875881
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
876882
** to test whether a file is at least readable. The file can be a
877883
** directory.
@@ -1114,13 +1120,13 @@
11141120
** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
11151121
** Note, however, that ^sqlite3_config() can be called as part of the
11161122
** implementation of an application-defined [sqlite3_os_init()].
11171123
**
11181124
** The first argument to sqlite3_config() is an integer
1119
-** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
1125
+** [configuration option] that determines
11201126
** what property of SQLite is to be configured. Subsequent arguments
1121
-** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
1127
+** vary depending on the [configuration option]
11221128
** in the first argument.
11231129
**
11241130
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
11251131
** ^If the option is unknown or SQLite is unable to set the option
11261132
** then this routine returns a non-zero [error code].
@@ -1226,10 +1232,11 @@
12261232
void *pAppData; /* Argument to xInit() and xShutdown() */
12271233
};
12281234
12291235
/*
12301236
** CAPI3REF: Configuration Options
1237
+** KEYWORDS: {configuration option}
12311238
**
12321239
** These constants are the available integer configuration options that
12331240
** can be passed as the first argument to the [sqlite3_config()] interface.
12341241
**
12351242
** New configuration options may be added in future releases of SQLite.
@@ -1238,11 +1245,11 @@
12381245
** the call worked. The [sqlite3_config()] interface will return a
12391246
** non-zero [error code] if a discontinued or unsupported configuration option
12401247
** is invoked.
12411248
**
12421249
** <dl>
1243
-** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1250
+** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
12441251
** <dd>There are no arguments to this option. ^This option sets the
12451252
** [threading mode] to Single-thread. In other words, it disables
12461253
** all mutexing and puts SQLite into a mode where it can only be used
12471254
** by a single thread. ^If SQLite is compiled with
12481255
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
@@ -1249,11 +1256,11 @@
12491256
** it is not possible to change the [threading mode] from its default
12501257
** value of Single-thread and so [sqlite3_config()] will return
12511258
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
12521259
** configuration option.</dd>
12531260
**
1254
-** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1261
+** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
12551262
** <dd>There are no arguments to this option. ^This option sets the
12561263
** [threading mode] to Multi-thread. In other words, it disables
12571264
** mutexing on [database connection] and [prepared statement] objects.
12581265
** The application is responsible for serializing access to
12591266
** [database connections] and [prepared statements]. But other mutexes
@@ -1263,11 +1270,11 @@
12631270
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
12641271
** it is not possible to set the Multi-thread [threading mode] and
12651272
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
12661273
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
12671274
**
1268
-** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1275
+** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
12691276
** <dd>There are no arguments to this option. ^This option sets the
12701277
** [threading mode] to Serialized. In other words, this option enables
12711278
** all mutexes including the recursive
12721279
** mutexes on [database connection] and [prepared statement] objects.
12731280
** In this mode (which is the default when SQLite is compiled with
@@ -1279,27 +1286,27 @@
12791286
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
12801287
** it is not possible to set the Serialized [threading mode] and
12811288
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
12821289
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
12831290
**
1284
-** <dt>SQLITE_CONFIG_MALLOC</dt>
1291
+** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
12851292
** <dd> ^(This option takes a single argument which is a pointer to an
12861293
** instance of the [sqlite3_mem_methods] structure. The argument specifies
12871294
** alternative low-level memory allocation routines to be used in place of
12881295
** the memory allocation routines built into SQLite.)^ ^SQLite makes
12891296
** its own private copy of the content of the [sqlite3_mem_methods] structure
12901297
** before the [sqlite3_config()] call returns.</dd>
12911298
**
1292
-** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1299
+** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
12931300
** <dd> ^(This option takes a single argument which is a pointer to an
12941301
** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
12951302
** structure is filled with the currently defined memory allocation routines.)^
12961303
** This option can be used to overload the default memory allocation
12971304
** routines with a wrapper that simulations memory allocation failure or
12981305
** tracks memory usage, for example. </dd>
12991306
**
1300
-** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1307
+** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
13011308
** <dd> ^This option takes single argument of type int, interpreted as a
13021309
** boolean, which enables or disables the collection of memory allocation
13031310
** statistics. ^(When memory allocation statistics are disabled, the
13041311
** following SQLite interfaces become non-operational:
13051312
** <ul>
@@ -1311,11 +1318,11 @@
13111318
** ^Memory allocation statistics are enabled by default unless SQLite is
13121319
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
13131320
** allocation statistics are disabled by default.
13141321
** </dd>
13151322
**
1316
-** <dt>SQLITE_CONFIG_SCRATCH</dt>
1323
+** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
13171324
** <dd> ^This option specifies a static memory buffer that SQLite can use for
13181325
** scratch memory. There are three arguments: A pointer an 8-byte
13191326
** aligned memory buffer from which the scratch allocations will be
13201327
** drawn, the size of each scratch allocation (sz),
13211328
** and the maximum number of scratch allocations (N). The sz
@@ -1327,11 +1334,11 @@
13271334
** ^SQLite will never require a scratch buffer that is more than 6
13281335
** times the database page size. ^If SQLite needs needs additional
13291336
** scratch memory beyond what is provided by this configuration option, then
13301337
** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
13311338
**
1332
-** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1339
+** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
13331340
** <dd> ^This option specifies a static memory buffer that SQLite can use for
13341341
** the database page cache with the default page cache implemenation.
13351342
** This configuration should not be used if an application-define page
13361343
** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
13371344
** There are three arguments to this option: A pointer to 8-byte aligned
@@ -1348,11 +1355,11 @@
13481355
** SQLite goes to [sqlite3_malloc()] for the additional storage space.
13491356
** The pointer in the first argument must
13501357
** be aligned to an 8-byte boundary or subsequent behavior of SQLite
13511358
** will be undefined.</dd>
13521359
**
1353
-** <dt>SQLITE_CONFIG_HEAP</dt>
1360
+** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
13541361
** <dd> ^This option specifies a static memory buffer that SQLite will use
13551362
** for all of its dynamic memory allocation needs beyond those provided
13561363
** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
13571364
** There are three arguments: An 8-byte aligned pointer to the memory,
13581365
** the number of bytes in the memory buffer, and the minimum allocation size.
@@ -1365,11 +1372,11 @@
13651372
** The first pointer (the memory pointer) must be aligned to an 8-byte
13661373
** boundary or subsequent behavior of SQLite will be undefined.
13671374
** The minimum allocation size is capped at 2^12. Reasonable values
13681375
** for the minimum allocation size are 2^5 through 2^8.</dd>
13691376
**
1370
-** <dt>SQLITE_CONFIG_MUTEX</dt>
1377
+** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
13711378
** <dd> ^(This option takes a single argument which is a pointer to an
13721379
** instance of the [sqlite3_mutex_methods] structure. The argument specifies
13731380
** alternative low-level mutex routines to be used in place
13741381
** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
13751382
** content of the [sqlite3_mutex_methods] structure before the call to
@@ -1377,11 +1384,11 @@
13771384
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
13781385
** the entire mutexing subsystem is omitted from the build and hence calls to
13791386
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
13801387
** return [SQLITE_ERROR].</dd>
13811388
**
1382
-** <dt>SQLITE_CONFIG_GETMUTEX</dt>
1389
+** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
13831390
** <dd> ^(This option takes a single argument which is a pointer to an
13841391
** instance of the [sqlite3_mutex_methods] structure. The
13851392
** [sqlite3_mutex_methods]
13861393
** structure is filled with the currently defined mutex routines.)^
13871394
** This option can be used to overload the default mutex allocation
@@ -1390,32 +1397,32 @@
13901397
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
13911398
** the entire mutexing subsystem is omitted from the build and hence calls to
13921399
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
13931400
** return [SQLITE_ERROR].</dd>
13941401
**
1395
-** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1402
+** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
13961403
** <dd> ^(This option takes two arguments that determine the default
13971404
** memory allocation for the lookaside memory allocator on each
13981405
** [database connection]. The first argument is the
13991406
** size of each lookaside buffer slot and the second is the number of
14001407
** slots allocated to each database connection.)^ ^(This option sets the
14011408
** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
14021409
** verb to [sqlite3_db_config()] can be used to change the lookaside
14031410
** configuration on individual connections.)^ </dd>
14041411
**
1405
-** <dt>SQLITE_CONFIG_PCACHE</dt>
1412
+** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt>
14061413
** <dd> ^(This option takes a single argument which is a pointer to
14071414
** an [sqlite3_pcache_methods] object. This object specifies the interface
14081415
** to a custom page cache implementation.)^ ^SQLite makes a copy of the
14091416
** object and uses it for page cache memory allocations.</dd>
14101417
**
1411
-** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1418
+** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt>
14121419
** <dd> ^(This option takes a single argument which is a pointer to an
14131420
** [sqlite3_pcache_methods] object. SQLite copies of the current
14141421
** page cache implementation into that object.)^ </dd>
14151422
**
1416
-** <dt>SQLITE_CONFIG_LOG</dt>
1423
+** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
14171424
** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
14181425
** function with a call signature of void(*)(void*,int,const char*),
14191426
** and a pointer to void. ^If the function pointer is not NULL, it is
14201427
** invoked by [sqlite3_log()] to process each logging event. ^If the
14211428
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
@@ -1429,10 +1436,22 @@
14291436
** The SQLite logging interface is not reentrant; the logger function
14301437
** supplied by the application must not invoke any SQLite interface.
14311438
** In a multi-threaded application, the application-defined logger
14321439
** function must be threadsafe. </dd>
14331440
**
1441
+** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1442
+** <dd> This option takes a single argument of type int. If non-zero, then
1443
+** URI handling is globally enabled. If the parameter is zero, then URI handling
1444
+** is globally disabled. If URI handling is globally enabled, all filenames
1445
+** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1446
+** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1447
+** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1448
+** connection is opened. If it is globally disabled, filenames are
1449
+** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1450
+** database connection is opened. By default, URI handling is globally
1451
+** disabled. The default value may be changed by compiling with the
1452
+** [SQLITE_USE_URI] symbol defined.
14341453
** </dl>
14351454
*/
14361455
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
14371456
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
14381457
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1447,10 +1466,11 @@
14471466
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
14481467
#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
14491468
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
14501469
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
14511470
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1471
+#define SQLITE_CONFIG_URI 17 /* int */
14521472
14531473
/*
14541474
** CAPI3REF: Database Connection Configuration Options
14551475
**
14561476
** These constants are the available integer configuration options that
@@ -1532,17 +1552,21 @@
15321552
** the table has a column of type [INTEGER PRIMARY KEY] then that column
15331553
** is another alias for the rowid.
15341554
**
15351555
** ^This routine returns the [rowid] of the most recent
15361556
** successful [INSERT] into the database from the [database connection]
1537
-** in the first argument. ^If no successful [INSERT]s
1557
+** in the first argument. ^As of SQLite version 3.7.7, this routines
1558
+** records the last insert rowid of both ordinary tables and [virtual tables].
1559
+** ^If no successful [INSERT]s
15381560
** have ever occurred on that database connection, zero is returned.
15391561
**
1540
-** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
1541
-** row is returned by this routine as long as the trigger is running.
1542
-** But once the trigger terminates, the value returned by this routine
1543
-** reverts to the last value inserted before the trigger fired.)^
1562
+** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1563
+** method, then this routine will return the [rowid] of the inserted
1564
+** row as long as the trigger or virtual table method is running.
1565
+** But once the trigger or virtual table method ends, the value returned
1566
+** by this routine reverts to what it was before the trigger or virtual
1567
+** table method began.)^
15441568
**
15451569
** ^An [INSERT] that fails due to a constraint violation is not a
15461570
** successful [INSERT] and does not change the value returned by this
15471571
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
15481572
** and INSERT OR ABORT make no changes to the return value of this
@@ -2201,10 +2225,13 @@
22012225
** The [sqlite3_set_authorizer | authorizer callback function] must
22022226
** return either [SQLITE_OK] or one of these two constants in order
22032227
** to signal SQLite whether or not the action is permitted. See the
22042228
** [sqlite3_set_authorizer | authorizer documentation] for additional
22052229
** information.
2230
+**
2231
+** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code]
2232
+** from the [sqlite3_vtab_on_conflict()] interface.
22062233
*/
22072234
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
22082235
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
22092236
22102237
/*
@@ -2323,11 +2350,11 @@
23232350
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
23242351
23252352
/*
23262353
** CAPI3REF: Opening A New Database Connection
23272354
**
2328
-** ^These routines open an SQLite database file whose name is given by the
2355
+** ^These routines open an SQLite database file as specified by the
23292356
** filename argument. ^The filename argument is interpreted as UTF-8 for
23302357
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
23312358
** order for sqlite3_open16(). ^(A [database connection] handle is usually
23322359
** returned in *ppDb, even if an error occurs. The only exception is that
23332360
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
@@ -2350,11 +2377,11 @@
23502377
** except that it accepts two additional parameters for additional control
23512378
** over the new database connection. ^(The flags parameter to
23522379
** sqlite3_open_v2() can take one of
23532380
** the following three values, optionally combined with the
23542381
** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2355
-** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
2382
+** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
23562383
**
23572384
** <dl>
23582385
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
23592386
** <dd>The database is opened in read-only mode. If the database does not
23602387
** already exist, an error is returned.</dd>)^
@@ -2369,13 +2396,12 @@
23692396
** it does not already exist. This is the behavior that is always used for
23702397
** sqlite3_open() and sqlite3_open16().</dd>)^
23712398
** </dl>
23722399
**
23732400
** If the 3rd parameter to sqlite3_open_v2() is not one of the
2374
-** combinations shown above or one of the combinations shown above combined
2375
-** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2376
-** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2401
+** combinations shown above optionally combined with other
2402
+** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
23772403
** then the behavior is undefined.
23782404
**
23792405
** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
23802406
** opens in the multi-thread [threading mode] as long as the single-thread
23812407
** mode has not been set at compile-time or start-time. ^If the
@@ -2385,10 +2411,15 @@
23852411
** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
23862412
** eligible to use [shared cache mode], regardless of whether or not shared
23872413
** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
23882414
** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
23892415
** participate in [shared cache mode] even if it is enabled.
2416
+**
2417
+** ^The fourth parameter to sqlite3_open_v2() is the name of the
2418
+** [sqlite3_vfs] object that defines the operating system interface that
2419
+** the new database connection should use. ^If the fourth parameter is
2420
+** a NULL pointer then the default [sqlite3_vfs] object is used.
23902421
**
23912422
** ^If the filename is ":memory:", then a private, temporary in-memory database
23922423
** is created for the connection. ^This in-memory database will vanish when
23932424
** the database connection is closed. Future versions of SQLite might
23942425
** make use of additional special filenames that begin with the ":" character.
@@ -2398,14 +2429,115 @@
23982429
**
23992430
** ^If the filename is an empty string, then a private, temporary
24002431
** on-disk database will be created. ^This private database will be
24012432
** automatically deleted as soon as the database connection is closed.
24022433
**
2403
-** ^The fourth parameter to sqlite3_open_v2() is the name of the
2404
-** [sqlite3_vfs] object that defines the operating system interface that
2405
-** the new database connection should use. ^If the fourth parameter is
2406
-** a NULL pointer then the default [sqlite3_vfs] object is used.
2434
+** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
2435
+**
2436
+** ^If [URI filename] interpretation is enabled, and the filename argument
2437
+** begins with "file:", then the filename is interpreted as a URI. ^URI
2438
+** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
2439
+** is set in the fourth argument to sqlite3_open_v2(), or if it has
2440
+** been enabled globally using the [SQLITE_CONFIG_URI] option with the
2441
+** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
2442
+** As of SQLite version 3.7.7, URI filename interpretation is turned off
2443
+** by default, but future releases of SQLite might enable URI filename
2444
+** intepretation by default. See "[URI filenames]" for additional
2445
+** information.
2446
+**
2447
+** URI filenames are parsed according to RFC 3986. ^If the URI contains an
2448
+** authority, then it must be either an empty string or the string
2449
+** "localhost". ^If the authority is not an empty string or "localhost", an
2450
+** error is returned to the caller. ^The fragment component of a URI, if
2451
+** present, is ignored.
2452
+**
2453
+** ^SQLite uses the path component of the URI as the name of the disk file
2454
+** which contains the database. ^If the path begins with a '/' character,
2455
+** then it is interpreted as an absolute path. ^If the path does not begin
2456
+** with a '/' (meaning that the authority section is omitted from the URI)
2457
+** then the path is interpreted as a relative path.
2458
+** ^On windows, the first component of an absolute path
2459
+** is a drive specification (e.g. "C:").
2460
+**
2461
+** [[core URI query parameters]]
2462
+** The query component of a URI may contain parameters that are interpreted
2463
+** either by SQLite itself, or by a [VFS | custom VFS implementation].
2464
+** SQLite interprets the following three query parameters:
2465
+**
2466
+** <ul>
2467
+** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
2468
+** a VFS object that provides the operating system interface that should
2469
+** be used to access the database file on disk. ^If this option is set to
2470
+** an empty string the default VFS object is used. ^Specifying an unknown
2471
+** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
2472
+** present, then the VFS specified by the option takes precedence over
2473
+** the value passed as the fourth parameter to sqlite3_open_v2().
2474
+**
2475
+** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
2476
+** "rwc". Attempting to set it to any other value is an error)^.
2477
+** ^If "ro" is specified, then the database is opened for read-only
2478
+** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2479
+** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
2480
+** "rw", then the database is opened for read-write (but not create)
2481
+** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
2482
+** been set. ^Value "rwc" is equivalent to setting both
2483
+** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
2484
+** used, it is an error to specify a value for the mode parameter that is
2485
+** less restrictive than that specified by the flags passed as the third
2486
+** parameter.
2487
+**
2488
+** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
2489
+** "private". ^Setting it to "shared" is equivalent to setting the
2490
+** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2491
+** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
2492
+** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2493
+** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2494
+** a URI filename, its value overrides any behaviour requested by setting
2495
+** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2496
+** </ul>
2497
+**
2498
+** ^Specifying an unknown parameter in the query component of a URI is not an
2499
+** error. Future versions of SQLite might understand additional query
2500
+** parameters. See "[query parameters with special meaning to SQLite]" for
2501
+** additional information.
2502
+**
2503
+** [[URI filename examples]] <h3>URI filename examples</h3>
2504
+**
2505
+** <table border="1" align=center cellpadding=5>
2506
+** <tr><th> URI filenames <th> Results
2507
+** <tr><td> file:data.db <td>
2508
+** Open the file "data.db" in the current directory.
2509
+** <tr><td> file:/home/fred/data.db<br>
2510
+** file:///home/fred/data.db <br>
2511
+** file://localhost/home/fred/data.db <br> <td>
2512
+** Open the database file "/home/fred/data.db".
2513
+** <tr><td> file://darkstar/home/fred/data.db <td>
2514
+** An error. "darkstar" is not a recognized authority.
2515
+** <tr><td style="white-space:nowrap">
2516
+** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
2517
+** <td> Windows only: Open the file "data.db" on fred's desktop on drive
2518
+** C:. Note that the %20 escaping in this example is not strictly
2519
+** necessary - space characters can be used literally
2520
+** in URI filenames.
2521
+** <tr><td> file:data.db?mode=ro&cache=private <td>
2522
+** Open file "data.db" in the current directory for read-only access.
2523
+** Regardless of whether or not shared-cache mode is enabled by
2524
+** default, use a private cache.
2525
+** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
2526
+** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
2527
+** <tr><td> file:data.db?mode=readonly <td>
2528
+** An error. "readonly" is not a valid option for the "mode" parameter.
2529
+** </table>
2530
+**
2531
+** ^URI hexadecimal escape sequences (%HH) are supported within the path and
2532
+** query components of a URI. A hexadecimal escape sequence consists of a
2533
+** percent sign - "%" - followed by exactly two hexadecimal digits
2534
+** specifying an octet value. ^Before the path or query components of a
2535
+** URI filename are interpreted, they are encoded using UTF-8 and all
2536
+** hexadecimal escape sequences replaced by a single byte containing the
2537
+** corresponding octet. If this process generates an invalid UTF-8 encoding,
2538
+** the results are undefined.
24072539
**
24082540
** <b>Note to Windows users:</b> The encoding used for the filename argument
24092541
** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
24102542
** codepage is currently defined. Filenames containing international
24112543
** characters must be converted to UTF-8 prior to passing them into
@@ -2423,10 +2555,30 @@
24232555
const char *filename, /* Database filename (UTF-8) */
24242556
sqlite3 **ppDb, /* OUT: SQLite db handle */
24252557
int flags, /* Flags */
24262558
const char *zVfs /* Name of VFS module to use */
24272559
);
2560
+
2561
+/*
2562
+** CAPI3REF: Obtain Values For URI Parameters
2563
+**
2564
+** This is a utility routine, useful to VFS implementations, that checks
2565
+** to see if a database file was a URI that contained a specific query
2566
+** parameter, and if so obtains the value of the query parameter.
2567
+**
2568
+** The zFilename argument is the filename pointer passed into the xOpen()
2569
+** method of a VFS implementation. The zParam argument is the name of the
2570
+** query parameter we seek. This routine returns the value of the zParam
2571
+** parameter if it exists. If the parameter does not exist, this routine
2572
+** returns a NULL pointer.
2573
+**
2574
+** If the zFilename argument to this function is not a pointer that SQLite
2575
+** passed into the xOpen VFS method, then the behavior of this routine
2576
+** is undefined and probably undesirable.
2577
+*/
2578
+SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
2579
+
24282580
24292581
/*
24302582
** CAPI3REF: Error Codes And Messages
24312583
**
24322584
** ^The sqlite3_errcode() interface returns the numeric [result code] or
@@ -2539,47 +2691,49 @@
25392691
** that can be lowered at run-time using [sqlite3_limit()].
25402692
** The synopsis of the meanings of the various limits is shown below.
25412693
** Additional information is available at [limits | Limits in SQLite].
25422694
**
25432695
** <dl>
2544
-** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2696
+** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
25452697
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
25462698
**
2547
-** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2699
+** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
25482700
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
25492701
**
2550
-** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
2702
+** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
25512703
** <dd>The maximum number of columns in a table definition or in the
25522704
** result set of a [SELECT] or the maximum number of columns in an index
25532705
** or in an ORDER BY or GROUP BY clause.</dd>)^
25542706
**
2555
-** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
2707
+** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
25562708
** <dd>The maximum depth of the parse tree on any expression.</dd>)^
25572709
**
2558
-** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2710
+** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
25592711
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
25602712
**
2561
-** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2713
+** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
25622714
** <dd>The maximum number of instructions in a virtual machine program
25632715
** used to implement an SQL statement. This limit is not currently
25642716
** enforced, though that might be added in some future release of
25652717
** SQLite.</dd>)^
25662718
**
2567
-** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2719
+** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
25682720
** <dd>The maximum number of arguments on a function.</dd>)^
25692721
**
2570
-** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
2722
+** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
25712723
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
25722724
**
2725
+** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
25732726
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
25742727
** <dd>The maximum length of the pattern argument to the [LIKE] or
25752728
** [GLOB] operators.</dd>)^
25762729
**
2730
+** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
25772731
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
25782732
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
25792733
**
2580
-** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2734
+** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
25812735
** <dd>The maximum depth of recursion for triggers.</dd>)^
25822736
** </dl>
25832737
*/
25842738
#define SQLITE_LIMIT_LENGTH 0
25852739
#define SQLITE_LIMIT_SQL_LENGTH 1
@@ -4610,10 +4764,15 @@
46104764
int (*xRollback)(sqlite3_vtab *pVTab);
46114765
int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
46124766
void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
46134767
void **ppArg);
46144768
int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
4769
+ /* The methods above are in version 1 of the sqlite_module object. Those
4770
+ ** below are for version 2 and greater. */
4771
+ int (*xSavepoint)(sqlite3_vtab *pVTab, int);
4772
+ int (*xRelease)(sqlite3_vtab *pVTab, int);
4773
+ int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
46154774
};
46164775
46174776
/*
46184777
** CAPI3REF: Virtual Table Indexing Information
46194778
** KEYWORDS: sqlite3_index_info
@@ -5424,11 +5583,11 @@
54245583
**
54255584
** ^This interface is used to retrieve runtime status information
54265585
** about the performance of SQLite, and optionally to reset various
54275586
** highwater marks. ^The first argument is an integer code for
54285587
** the specific parameter to measure. ^(Recognized integer codes
5429
-** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
5588
+** are of the form [status parameters | SQLITE_STATUS_...].)^
54305589
** ^The current value of the parameter is returned into *pCurrent.
54315590
** ^The highest recorded value is returned in *pHighwater. ^If the
54325591
** resetFlag is true, then the highest record value is reset after
54335592
** *pHighwater is written. ^(Some parameters do not record the highest
54345593
** value. For those parameters
@@ -5451,82 +5610,84 @@
54515610
SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
54525611
54535612
54545613
/*
54555614
** CAPI3REF: Status Parameters
5615
+** KEYWORDS: {status parameters}
54565616
**
54575617
** These integer constants designate various run-time status parameters
54585618
** that can be returned by [sqlite3_status()].
54595619
**
54605620
** <dl>
5461
-** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
5621
+** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
54625622
** <dd>This parameter is the current amount of memory checked out
54635623
** using [sqlite3_malloc()], either directly or indirectly. The
54645624
** figure includes calls made to [sqlite3_malloc()] by the application
54655625
** and internal memory usage by the SQLite library. Scratch memory
54665626
** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
54675627
** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
54685628
** this parameter. The amount returned is the sum of the allocation
54695629
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
54705630
**
5471
-** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
5631
+** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
54725632
** <dd>This parameter records the largest memory allocation request
54735633
** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
54745634
** internal equivalents). Only the value returned in the
54755635
** *pHighwater parameter to [sqlite3_status()] is of interest.
54765636
** The value written into the *pCurrent parameter is undefined.</dd>)^
54775637
**
5478
-** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5638
+** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
54795639
** <dd>This parameter records the number of separate memory allocations
54805640
** currently checked out.</dd>)^
54815641
**
5482
-** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5642
+** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
54835643
** <dd>This parameter returns the number of pages used out of the
54845644
** [pagecache memory allocator] that was configured using
54855645
** [SQLITE_CONFIG_PAGECACHE]. The
54865646
** value returned is in pages, not in bytes.</dd>)^
54875647
**
5648
+** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
54885649
** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
54895650
** <dd>This parameter returns the number of bytes of page cache
54905651
** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
54915652
** buffer and where forced to overflow to [sqlite3_malloc()]. The
54925653
** returned value includes allocations that overflowed because they
54935654
** where too large (they were larger than the "sz" parameter to
54945655
** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
54955656
** no space was left in the page cache.</dd>)^
54965657
**
5497
-** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
5658
+** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
54985659
** <dd>This parameter records the largest memory allocation request
54995660
** handed to [pagecache memory allocator]. Only the value returned in the
55005661
** *pHighwater parameter to [sqlite3_status()] is of interest.
55015662
** The value written into the *pCurrent parameter is undefined.</dd>)^
55025663
**
5503
-** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
5664
+** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
55045665
** <dd>This parameter returns the number of allocations used out of the
55055666
** [scratch memory allocator] configured using
55065667
** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
55075668
** in bytes. Since a single thread may only have one scratch allocation
55085669
** outstanding at time, this parameter also reports the number of threads
55095670
** using scratch memory at the same time.</dd>)^
55105671
**
5511
-** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5672
+** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
55125673
** <dd>This parameter returns the number of bytes of scratch memory
55135674
** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
55145675
** buffer and where forced to overflow to [sqlite3_malloc()]. The values
55155676
** returned include overflows because the requested allocation was too
55165677
** larger (that is, because the requested allocation was larger than the
55175678
** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
55185679
** slots were available.
55195680
** </dd>)^
55205681
**
5521
-** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
5682
+** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
55225683
** <dd>This parameter records the largest memory allocation request
55235684
** handed to [scratch memory allocator]. Only the value returned in the
55245685
** *pHighwater parameter to [sqlite3_status()] is of interest.
55255686
** The value written into the *pCurrent parameter is undefined.</dd>)^
55265687
**
5527
-** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
5688
+** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
55285689
** <dd>This parameter records the deepest parser stack. It is only
55295690
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
55305691
** </dl>
55315692
**
55325693
** New status parameters may be added from time to time.
@@ -5547,13 +5708,13 @@
55475708
**
55485709
** ^This interface is used to retrieve runtime status information
55495710
** about a single [database connection]. ^The first argument is the
55505711
** database connection object to be interrogated. ^The second argument
55515712
** is an integer constant, taken from the set of
5552
-** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5713
+** [SQLITE_DBSTATUS options], that
55535714
** determines the parameter to interrogate. The set of
5554
-** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5715
+** [SQLITE_DBSTATUS options] is likely
55555716
** to grow in future releases of SQLite.
55565717
**
55575718
** ^The current value of the requested parameter is written into *pCur
55585719
** and the highest instantaneous value is written into *pHiwtr. ^If
55595720
** the resetFlg is true, then the highest instantaneous value is
@@ -5566,10 +5727,11 @@
55665727
*/
55675728
SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
55685729
55695730
/*
55705731
** CAPI3REF: Status Parameters for database connections
5732
+** KEYWORDS: {SQLITE_DBSTATUS options}
55715733
**
55725734
** These constants are the available integer "verbs" that can be passed as
55735735
** the second argument to the [sqlite3_db_status()] interface.
55745736
**
55755737
** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5577,48 +5739,50 @@
55775739
** [sqlite3_db_status()] to make sure that the call worked.
55785740
** The [sqlite3_db_status()] interface will return a non-zero error code
55795741
** if a discontinued or unsupported verb is invoked.
55805742
**
55815743
** <dl>
5582
-** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5744
+** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
55835745
** <dd>This parameter returns the number of lookaside memory slots currently
55845746
** checked out.</dd>)^
55855747
**
5586
-** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5748
+** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
55875749
** <dd>This parameter returns the number malloc attempts that were
55885750
** satisfied using lookaside memory. Only the high-water value is meaningful;
55895751
** the current value is always zero.)^
55905752
**
5753
+** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
55915754
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
55925755
** <dd>This parameter returns the number malloc attempts that might have
55935756
** been satisfied using lookaside memory but failed due to the amount of
55945757
** memory requested being larger than the lookaside slot size.
55955758
** Only the high-water value is meaningful;
55965759
** the current value is always zero.)^
55975760
**
5761
+** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
55985762
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
55995763
** <dd>This parameter returns the number malloc attempts that might have
56005764
** been satisfied using lookaside memory but failed due to all lookaside
56015765
** memory already being in use.
56025766
** Only the high-water value is meaningful;
56035767
** the current value is always zero.)^
56045768
**
5605
-** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5769
+** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
56065770
** <dd>This parameter returns the approximate number of of bytes of heap
56075771
** memory used by all pager caches associated with the database connection.)^
56085772
** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
56095773
**
5610
-** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5774
+** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
56115775
** <dd>This parameter returns the approximate number of of bytes of heap
56125776
** memory used to store the schema for all databases associated
56135777
** with the connection - main, temp, and any [ATTACH]-ed databases.)^
56145778
** ^The full amount of memory used by the schemas is reported, even if the
56155779
** schema memory is shared with other database connections due to
56165780
** [shared cache mode] being enabled.
56175781
** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
56185782
**
5619
-** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5783
+** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
56205784
** <dd>This parameter returns the approximate number of of bytes of heap
56215785
** and lookaside memory used by all prepared statements associated with
56225786
** the database connection.)^
56235787
** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
56245788
** </dd>
@@ -5636,11 +5800,11 @@
56365800
56375801
/*
56385802
** CAPI3REF: Prepared Statement Status
56395803
**
56405804
** ^(Each prepared statement maintains various
5641
-** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5805
+** [SQLITE_STMTSTATUS counters] that measure the number
56425806
** of times it has performed specific operations.)^ These counters can
56435807
** be used to monitor the performance characteristics of the prepared
56445808
** statements. For example, if the number of table steps greatly exceeds
56455809
** the number of table searches or result rows, that would tend to indicate
56465810
** that the prepared statement is using a full table scan rather than
@@ -5647,11 +5811,11 @@
56475811
** an index.
56485812
**
56495813
** ^(This interface is used to retrieve and reset counter values from
56505814
** a [prepared statement]. The first argument is the prepared statement
56515815
** object to be interrogated. The second argument
5652
-** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
5816
+** is an integer code for a specific [SQLITE_STMTSTATUS counter]
56535817
** to be interrogated.)^
56545818
** ^The current value of the requested counter is returned.
56555819
** ^If the resetFlg is true, then the counter is reset to zero after this
56565820
** interface call returns.
56575821
**
@@ -5659,28 +5823,29 @@
56595823
*/
56605824
SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
56615825
56625826
/*
56635827
** CAPI3REF: Status Parameters for prepared statements
5828
+** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
56645829
**
56655830
** These preprocessor macros define integer codes that name counter
56665831
** values associated with the [sqlite3_stmt_status()] interface.
56675832
** The meanings of the various counters are as follows:
56685833
**
56695834
** <dl>
5670
-** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
5835
+** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
56715836
** <dd>^This is the number of times that SQLite has stepped forward in
56725837
** a table as part of a full table scan. Large numbers for this counter
56735838
** may indicate opportunities for performance improvement through
56745839
** careful use of indices.</dd>
56755840
**
5676
-** <dt>SQLITE_STMTSTATUS_SORT</dt>
5841
+** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
56775842
** <dd>^This is the number of sort operations that have occurred.
56785843
** A non-zero value in this counter may indicate an opportunity to
56795844
** improvement performance through careful use of indices.</dd>
56805845
**
5681
-** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5846
+** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
56825847
** <dd>^This is the number of rows inserted into transient indices that
56835848
** were created automatically in order to help joins run faster.
56845849
** A non-zero value in this counter may indicate an opportunity to
56855850
** improvement performance by adding permanent indices that do not
56865851
** need to be reinitialized each time the statement is run.</dd>
@@ -5727,10 +5892,11 @@
57275892
** ^(The contents of the sqlite3_pcache_methods structure are copied to an
57285893
** internal buffer by SQLite within the call to [sqlite3_config]. Hence
57295894
** the application may discard the parameter after the call to
57305895
** [sqlite3_config()] returns.)^
57315896
**
5897
+** [[the xInit() page cache method]]
57325898
** ^(The xInit() method is called once for each effective
57335899
** call to [sqlite3_initialize()])^
57345900
** (usually only once during the lifetime of the process). ^(The xInit()
57355901
** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
57365902
** The intent of the xInit() method is to set up global data structures
@@ -5737,10 +5903,11 @@
57375903
** required by the custom page cache implementation.
57385904
** ^(If the xInit() method is NULL, then the
57395905
** built-in default page cache is used instead of the application defined
57405906
** page cache.)^
57415907
**
5908
+** [[the xShutdown() page cache method]]
57425909
** ^The xShutdown() method is called by [sqlite3_shutdown()].
57435910
** It can be used to clean up
57445911
** any outstanding resources before process shutdown, if required.
57455912
** ^The xShutdown() method may be NULL.
57465913
**
@@ -5751,10 +5918,11 @@
57515918
** in multithreaded applications.
57525919
**
57535920
** ^SQLite will never invoke xInit() more than once without an intervening
57545921
** call to xShutdown().
57555922
**
5923
+** [[the xCreate() page cache methods]]
57565924
** ^SQLite invokes the xCreate() method to construct a new cache instance.
57575925
** SQLite will typically create one cache instance for each open database file,
57585926
** though this is not guaranteed. ^The
57595927
** first parameter, szPage, is the size in bytes of the pages that must
57605928
** be allocated by the cache. ^szPage will not be a power of two. ^szPage
@@ -5775,20 +5943,23 @@
57755943
** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
57765944
** false will always have the "discard" flag set to true.
57775945
** ^Hence, a cache created with bPurgeable false will
57785946
** never contain any unpinned pages.
57795947
**
5948
+** [[the xCachesize() page cache method]]
57805949
** ^(The xCachesize() method may be called at any time by SQLite to set the
57815950
** suggested maximum cache-size (number of pages stored by) the cache
57825951
** instance passed as the first argument. This is the value configured using
57835952
** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
57845953
** parameter, the implementation is not required to do anything with this
57855954
** value; it is advisory only.
57865955
**
5956
+** [[the xPagecount() page cache methods]]
57875957
** The xPagecount() method must return the number of pages currently
57885958
** stored in the cache, both pinned and unpinned.
57895959
**
5960
+** [[the xFetch() page cache methods]]
57905961
** The xFetch() method locates a page in the cache and returns a pointer to
57915962
** the page, or a NULL pointer.
57925963
** A "page", in this context, means a buffer of szPage bytes aligned at an
57935964
** 8-byte boundary. The page to be fetched is determined by the key. ^The
57945965
** mimimum key value is 1. After it has been retrieved using xFetch, the page
@@ -5813,10 +5984,11 @@
58135984
** will only use a createFlag of 2 after a prior call with a createFlag of 1
58145985
** failed.)^ In between the to xFetch() calls, SQLite may
58155986
** attempt to unpin one or more cache pages by spilling the content of
58165987
** pinned pages to disk and synching the operating system disk cache.
58175988
**
5989
+** [[the xUnpin() page cache method]]
58185990
** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
58195991
** as its second argument. If the third parameter, discard, is non-zero,
58205992
** then the page must be evicted from the cache.
58215993
** ^If the discard parameter is
58225994
** zero, then the page may be discarded or retained at the discretion of
@@ -5825,10 +5997,11 @@
58255997
**
58265998
** The cache must not perform any reference counting. A single
58275999
** call to xUnpin() unpins the page regardless of the number of prior calls
58286000
** to xFetch().
58296001
**
6002
+** [[the xRekey() page cache methods]]
58306003
** The xRekey() method is used to change the key value associated with the
58316004
** page passed as the second argument. If the cache
58326005
** previously contains an entry associated with newKey, it must be
58336006
** discarded. ^Any prior cache entry associated with newKey is guaranteed not
58346007
** to be pinned.
@@ -5837,10 +6010,11 @@
58376010
** existing cache entries with page numbers (keys) greater than or equal
58386011
** to the value of the iLimit parameter passed to xTruncate(). If any
58396012
** of these pages are pinned, they are implicitly unpinned, meaning that
58406013
** they can be safely discarded.
58416014
**
6015
+** [[the xDestroy() page cache method]]
58426016
** ^The xDestroy() method is used to delete a cache allocated by xCreate().
58436017
** All resources associated with the specified cache should be freed. ^After
58446018
** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
58456019
** handle invalid, and will not use it with any other sqlite3_pcache_methods
58466020
** functions.
@@ -5899,11 +6073,11 @@
58996073
** associated with the backup operation.
59006074
** </ol>)^
59016075
** There should be exactly one call to sqlite3_backup_finish() for each
59026076
** successful call to sqlite3_backup_init().
59036077
**
5904
-** <b>sqlite3_backup_init()</b>
6078
+** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
59056079
**
59066080
** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
59076081
** [database connection] associated with the destination database
59086082
** and the database name, respectively.
59096083
** ^The database name is "main" for the main database, "temp" for the
@@ -5926,11 +6100,11 @@
59266100
** [sqlite3_backup] object.
59276101
** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
59286102
** sqlite3_backup_finish() functions to perform the specified backup
59296103
** operation.
59306104
**
5931
-** <b>sqlite3_backup_step()</b>
6105
+** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
59326106
**
59336107
** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
59346108
** the source and destination databases specified by [sqlite3_backup] object B.
59356109
** ^If N is negative, all remaining source pages are copied.
59366110
** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
@@ -5983,11 +6157,11 @@
59836157
** restarted by the next call to sqlite3_backup_step(). ^If the source
59846158
** database is modified by the using the same database connection as is used
59856159
** by the backup operation, then the backup database is automatically
59866160
** updated at the same time.
59876161
**
5988
-** <b>sqlite3_backup_finish()</b>
6162
+** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
59896163
**
59906164
** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
59916165
** application wishes to abandon the backup operation, the application
59926166
** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
59936167
** ^The sqlite3_backup_finish() interfaces releases all
@@ -6006,11 +6180,12 @@
60066180
**
60076181
** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
60086182
** is not a permanent error and does not affect the return value of
60096183
** sqlite3_backup_finish().
60106184
**
6011
-** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
6185
+** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
6186
+** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
60126187
**
60136188
** ^Each call to sqlite3_backup_step() sets two values inside
60146189
** the [sqlite3_backup] object: the number of pages still to be backed
60156190
** up and the total number of pages in the source database file.
60166191
** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
@@ -6391,10 +6566,97 @@
63916566
** each of these values.
63926567
*/
63936568
#define SQLITE_CHECKPOINT_PASSIVE 0
63946569
#define SQLITE_CHECKPOINT_FULL 1
63956570
#define SQLITE_CHECKPOINT_RESTART 2
6571
+
6572
+/*
6573
+** CAPI3REF: Virtual Table Interface Configuration
6574
+**
6575
+** This function may be called by either the [xConnect] or [xCreate] method
6576
+** of a [virtual table] implementation to configure
6577
+** various facets of the virtual table interface.
6578
+**
6579
+** If this interface is invoked outside the context of an xConnect or
6580
+** xCreate virtual table method then the behavior is undefined.
6581
+**
6582
+** At present, there is only one option that may be configured using
6583
+** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
6584
+** may be added in the future.
6585
+*/
6586
+SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
6587
+
6588
+/*
6589
+** CAPI3REF: Virtual Table Configuration Options
6590
+**
6591
+** These macros define the various options to the
6592
+** [sqlite3_vtab_config()] interface that [virtual table] implementations
6593
+** can use to customize and optimize their behavior.
6594
+**
6595
+** <dl>
6596
+** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
6597
+** <dd>Calls of the form
6598
+** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
6599
+** where X is an integer. If X is zero, then the [virtual table] whose
6600
+** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
6601
+** support constraints. In this configuration (which is the default) if
6602
+** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
6603
+** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
6604
+** specified as part of the users SQL statement, regardless of the actual
6605
+** ON CONFLICT mode specified.
6606
+**
6607
+** If X is non-zero, then the virtual table implementation guarantees
6608
+** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
6609
+** any modifications to internal or persistent data structures have been made.
6610
+** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
6611
+** is able to roll back a statement or database transaction, and abandon
6612
+** or continue processing the current SQL statement as appropriate.
6613
+** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
6614
+** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
6615
+** had been ABORT.
6616
+**
6617
+** Virtual table implementations that are required to handle OR REPLACE
6618
+** must do so within the [xUpdate] method. If a call to the
6619
+** [sqlite3_vtab_on_conflict()] function indicates that the current ON
6620
+** CONFLICT policy is REPLACE, the virtual table implementation should
6621
+** silently replace the appropriate rows within the xUpdate callback and
6622
+** return SQLITE_OK. Or, if this is not possible, it may return
6623
+** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
6624
+** constraint handling.
6625
+** </dl>
6626
+*/
6627
+#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
6628
+
6629
+/*
6630
+** CAPI3REF: Determine The Virtual Table Conflict Policy
6631
+**
6632
+** This function may only be called from within a call to the [xUpdate] method
6633
+** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
6634
+** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
6635
+** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
6636
+** of the SQL statement that triggered the call to the [xUpdate] method of the
6637
+** [virtual table].
6638
+*/
6639
+SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
6640
+
6641
+/*
6642
+** CAPI3REF: Conflict resolution modes
6643
+**
6644
+** These constants are returned by [sqlite3_vtab_on_conflict()] to
6645
+** inform a [virtual table] implementation what the [ON CONFLICT] mode
6646
+** is for the SQL statement being evaluated.
6647
+**
6648
+** Note that the [SQLITE_IGNORE] constant is also used as a potential
6649
+** return value from the [sqlite3_set_authorizer()] callback and that
6650
+** [SQLITE_ABORT] is also a [result code].
6651
+*/
6652
+#define SQLITE_ROLLBACK 1
6653
+/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
6654
+#define SQLITE_FAIL 3
6655
+/* #define SQLITE_ABORT 4 // Also an error code */
6656
+#define SQLITE_REPLACE 5
6657
+
63966658
63976659
63986660
/*
63996661
** Undo the hack that converts floating point types to integer for
64006662
** builds on processors without floating point support.
64016663
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.6.1"
111 #define SQLITE_VERSION_NUMBER 3007006
112 #define SQLITE_SOURCE_ID "2011-04-27 19:54:44 f55156c5194e85c47728b8a97fde3e5f0a5c9b56"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -373,11 +373,12 @@
373 ** Many SQLite functions return an integer result code from the set shown
374 ** here in order to indicates success or failure.
375 **
376 ** New error codes may be added in future versions of SQLite.
377 **
378 ** See also: [SQLITE_IOERR_READ | extended result codes]
 
379 */
380 #define SQLITE_OK 0 /* Successful result */
381 /* beginning-of-error-codes */
382 #define SQLITE_ERROR 1 /* SQL error or missing database */
383 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -455,25 +456,26 @@
455 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
456 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
457 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
458 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
459 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
 
460
461 /*
462 ** CAPI3REF: Flags For File Open Operations
463 **
464 ** These bit values are intended for use in the
465 ** 3rd parameter to the [sqlite3_open_v2()] interface and
466 ** in the 4th parameter to the xOpen method of the
467 ** [sqlite3_vfs] object.
468 */
469 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
470 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
471 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
472 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
473 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
474 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
 
475 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
476 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
477 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
478 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
479 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -580,21 +582,22 @@
580 };
581
582 /*
583 ** CAPI3REF: OS Interface File Virtual Methods Object
584 **
585 ** Every file opened by the [sqlite3_vfs] xOpen method populates an
586 ** [sqlite3_file] object (or, more commonly, a subclass of the
587 ** [sqlite3_file] object) with a pointer to an instance of this object.
588 ** This object defines the methods used to perform various operations
589 ** against the open file represented by the [sqlite3_file] object.
590 **
591 ** If the xOpen method sets the sqlite3_file.pMethods element
592 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
593 ** may be invoked even if the xOpen reported that it failed. The
594 ** only way to prevent a call to xClose following a failed xOpen
595 ** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
 
596 **
597 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
598 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
599 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
600 ** flag may be ORed in to indicate that only the data of the file
@@ -759,10 +762,11 @@
759 */
760 typedef struct sqlite3_mutex sqlite3_mutex;
761
762 /*
763 ** CAPI3REF: OS Interface Object
 
764 **
765 ** An instance of the sqlite3_vfs object defines the interface between
766 ** the SQLite core and the underlying operating system. The "vfs"
767 ** in the name of the object stands for "virtual file system".
768 **
@@ -791,10 +795,11 @@
791 ** object once the object has been registered.
792 **
793 ** The zName field holds the name of the VFS module. The name must
794 ** be unique across all VFS modules.
795 **
 
796 ** ^SQLite guarantees that the zFilename parameter to xOpen
797 ** is either a NULL pointer or string obtained
798 ** from xFullPathname() with an optional suffix added.
799 ** ^If a suffix is added to the zFilename parameter, it will
800 ** consist of a single "-" character followed by no more than
@@ -868,10 +873,11 @@
868 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
869 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
870 ** element will be valid after xOpen returns regardless of the success
871 ** or failure of the xOpen call.
872 **
 
873 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
874 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
875 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
876 ** to test whether a file is at least readable. The file can be a
877 ** directory.
@@ -1114,13 +1120,13 @@
1114 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1115 ** Note, however, that ^sqlite3_config() can be called as part of the
1116 ** implementation of an application-defined [sqlite3_os_init()].
1117 **
1118 ** The first argument to sqlite3_config() is an integer
1119 ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
1120 ** what property of SQLite is to be configured. Subsequent arguments
1121 ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
1122 ** in the first argument.
1123 **
1124 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1125 ** ^If the option is unknown or SQLite is unable to set the option
1126 ** then this routine returns a non-zero [error code].
@@ -1226,10 +1232,11 @@
1226 void *pAppData; /* Argument to xInit() and xShutdown() */
1227 };
1228
1229 /*
1230 ** CAPI3REF: Configuration Options
 
1231 **
1232 ** These constants are the available integer configuration options that
1233 ** can be passed as the first argument to the [sqlite3_config()] interface.
1234 **
1235 ** New configuration options may be added in future releases of SQLite.
@@ -1238,11 +1245,11 @@
1238 ** the call worked. The [sqlite3_config()] interface will return a
1239 ** non-zero [error code] if a discontinued or unsupported configuration option
1240 ** is invoked.
1241 **
1242 ** <dl>
1243 ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1244 ** <dd>There are no arguments to this option. ^This option sets the
1245 ** [threading mode] to Single-thread. In other words, it disables
1246 ** all mutexing and puts SQLite into a mode where it can only be used
1247 ** by a single thread. ^If SQLite is compiled with
1248 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
@@ -1249,11 +1256,11 @@
1249 ** it is not possible to change the [threading mode] from its default
1250 ** value of Single-thread and so [sqlite3_config()] will return
1251 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1252 ** configuration option.</dd>
1253 **
1254 ** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1255 ** <dd>There are no arguments to this option. ^This option sets the
1256 ** [threading mode] to Multi-thread. In other words, it disables
1257 ** mutexing on [database connection] and [prepared statement] objects.
1258 ** The application is responsible for serializing access to
1259 ** [database connections] and [prepared statements]. But other mutexes
@@ -1263,11 +1270,11 @@
1263 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1264 ** it is not possible to set the Multi-thread [threading mode] and
1265 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1266 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1267 **
1268 ** <dt>SQLITE_CONFIG_SERIALIZED</dt>
1269 ** <dd>There are no arguments to this option. ^This option sets the
1270 ** [threading mode] to Serialized. In other words, this option enables
1271 ** all mutexes including the recursive
1272 ** mutexes on [database connection] and [prepared statement] objects.
1273 ** In this mode (which is the default when SQLite is compiled with
@@ -1279,27 +1286,27 @@
1279 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1280 ** it is not possible to set the Serialized [threading mode] and
1281 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1282 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1283 **
1284 ** <dt>SQLITE_CONFIG_MALLOC</dt>
1285 ** <dd> ^(This option takes a single argument which is a pointer to an
1286 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
1287 ** alternative low-level memory allocation routines to be used in place of
1288 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1289 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1290 ** before the [sqlite3_config()] call returns.</dd>
1291 **
1292 ** <dt>SQLITE_CONFIG_GETMALLOC</dt>
1293 ** <dd> ^(This option takes a single argument which is a pointer to an
1294 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1295 ** structure is filled with the currently defined memory allocation routines.)^
1296 ** This option can be used to overload the default memory allocation
1297 ** routines with a wrapper that simulations memory allocation failure or
1298 ** tracks memory usage, for example. </dd>
1299 **
1300 ** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1301 ** <dd> ^This option takes single argument of type int, interpreted as a
1302 ** boolean, which enables or disables the collection of memory allocation
1303 ** statistics. ^(When memory allocation statistics are disabled, the
1304 ** following SQLite interfaces become non-operational:
1305 ** <ul>
@@ -1311,11 +1318,11 @@
1311 ** ^Memory allocation statistics are enabled by default unless SQLite is
1312 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1313 ** allocation statistics are disabled by default.
1314 ** </dd>
1315 **
1316 ** <dt>SQLITE_CONFIG_SCRATCH</dt>
1317 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1318 ** scratch memory. There are three arguments: A pointer an 8-byte
1319 ** aligned memory buffer from which the scratch allocations will be
1320 ** drawn, the size of each scratch allocation (sz),
1321 ** and the maximum number of scratch allocations (N). The sz
@@ -1327,11 +1334,11 @@
1327 ** ^SQLite will never require a scratch buffer that is more than 6
1328 ** times the database page size. ^If SQLite needs needs additional
1329 ** scratch memory beyond what is provided by this configuration option, then
1330 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1331 **
1332 ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
1333 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1334 ** the database page cache with the default page cache implemenation.
1335 ** This configuration should not be used if an application-define page
1336 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
1337 ** There are three arguments to this option: A pointer to 8-byte aligned
@@ -1348,11 +1355,11 @@
1348 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1349 ** The pointer in the first argument must
1350 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1351 ** will be undefined.</dd>
1352 **
1353 ** <dt>SQLITE_CONFIG_HEAP</dt>
1354 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1355 ** for all of its dynamic memory allocation needs beyond those provided
1356 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1357 ** There are three arguments: An 8-byte aligned pointer to the memory,
1358 ** the number of bytes in the memory buffer, and the minimum allocation size.
@@ -1365,11 +1372,11 @@
1365 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1366 ** boundary or subsequent behavior of SQLite will be undefined.
1367 ** The minimum allocation size is capped at 2^12. Reasonable values
1368 ** for the minimum allocation size are 2^5 through 2^8.</dd>
1369 **
1370 ** <dt>SQLITE_CONFIG_MUTEX</dt>
1371 ** <dd> ^(This option takes a single argument which is a pointer to an
1372 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1373 ** alternative low-level mutex routines to be used in place
1374 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1375 ** content of the [sqlite3_mutex_methods] structure before the call to
@@ -1377,11 +1384,11 @@
1377 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1378 ** the entire mutexing subsystem is omitted from the build and hence calls to
1379 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1380 ** return [SQLITE_ERROR].</dd>
1381 **
1382 ** <dt>SQLITE_CONFIG_GETMUTEX</dt>
1383 ** <dd> ^(This option takes a single argument which is a pointer to an
1384 ** instance of the [sqlite3_mutex_methods] structure. The
1385 ** [sqlite3_mutex_methods]
1386 ** structure is filled with the currently defined mutex routines.)^
1387 ** This option can be used to overload the default mutex allocation
@@ -1390,32 +1397,32 @@
1390 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1391 ** the entire mutexing subsystem is omitted from the build and hence calls to
1392 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1393 ** return [SQLITE_ERROR].</dd>
1394 **
1395 ** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1396 ** <dd> ^(This option takes two arguments that determine the default
1397 ** memory allocation for the lookaside memory allocator on each
1398 ** [database connection]. The first argument is the
1399 ** size of each lookaside buffer slot and the second is the number of
1400 ** slots allocated to each database connection.)^ ^(This option sets the
1401 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1402 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1403 ** configuration on individual connections.)^ </dd>
1404 **
1405 ** <dt>SQLITE_CONFIG_PCACHE</dt>
1406 ** <dd> ^(This option takes a single argument which is a pointer to
1407 ** an [sqlite3_pcache_methods] object. This object specifies the interface
1408 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1409 ** object and uses it for page cache memory allocations.</dd>
1410 **
1411 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1412 ** <dd> ^(This option takes a single argument which is a pointer to an
1413 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1414 ** page cache implementation into that object.)^ </dd>
1415 **
1416 ** <dt>SQLITE_CONFIG_LOG</dt>
1417 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1418 ** function with a call signature of void(*)(void*,int,const char*),
1419 ** and a pointer to void. ^If the function pointer is not NULL, it is
1420 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1421 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
@@ -1429,10 +1436,22 @@
1429 ** The SQLite logging interface is not reentrant; the logger function
1430 ** supplied by the application must not invoke any SQLite interface.
1431 ** In a multi-threaded application, the application-defined logger
1432 ** function must be threadsafe. </dd>
1433 **
 
 
 
 
 
 
 
 
 
 
 
 
1434 ** </dl>
1435 */
1436 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1437 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1438 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1447,10 +1466,11 @@
1447 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
1448 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
1449 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1450 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1451 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
 
1452
1453 /*
1454 ** CAPI3REF: Database Connection Configuration Options
1455 **
1456 ** These constants are the available integer configuration options that
@@ -1532,17 +1552,21 @@
1532 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1533 ** is another alias for the rowid.
1534 **
1535 ** ^This routine returns the [rowid] of the most recent
1536 ** successful [INSERT] into the database from the [database connection]
1537 ** in the first argument. ^If no successful [INSERT]s
 
 
1538 ** have ever occurred on that database connection, zero is returned.
1539 **
1540 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
1541 ** row is returned by this routine as long as the trigger is running.
1542 ** But once the trigger terminates, the value returned by this routine
1543 ** reverts to the last value inserted before the trigger fired.)^
 
 
1544 **
1545 ** ^An [INSERT] that fails due to a constraint violation is not a
1546 ** successful [INSERT] and does not change the value returned by this
1547 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
1548 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2201,10 +2225,13 @@
2201 ** The [sqlite3_set_authorizer | authorizer callback function] must
2202 ** return either [SQLITE_OK] or one of these two constants in order
2203 ** to signal SQLite whether or not the action is permitted. See the
2204 ** [sqlite3_set_authorizer | authorizer documentation] for additional
2205 ** information.
 
 
 
2206 */
2207 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2208 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
2209
2210 /*
@@ -2323,11 +2350,11 @@
2323 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2324
2325 /*
2326 ** CAPI3REF: Opening A New Database Connection
2327 **
2328 ** ^These routines open an SQLite database file whose name is given by the
2329 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2330 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2331 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
2332 ** returned in *ppDb, even if an error occurs. The only exception is that
2333 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
@@ -2350,11 +2377,11 @@
2350 ** except that it accepts two additional parameters for additional control
2351 ** over the new database connection. ^(The flags parameter to
2352 ** sqlite3_open_v2() can take one of
2353 ** the following three values, optionally combined with the
2354 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2355 ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
2356 **
2357 ** <dl>
2358 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
2359 ** <dd>The database is opened in read-only mode. If the database does not
2360 ** already exist, an error is returned.</dd>)^
@@ -2369,13 +2396,12 @@
2369 ** it does not already exist. This is the behavior that is always used for
2370 ** sqlite3_open() and sqlite3_open16().</dd>)^
2371 ** </dl>
2372 **
2373 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2374 ** combinations shown above or one of the combinations shown above combined
2375 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
2376 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_PRIVATECACHE] flags,
2377 ** then the behavior is undefined.
2378 **
2379 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2380 ** opens in the multi-thread [threading mode] as long as the single-thread
2381 ** mode has not been set at compile-time or start-time. ^If the
@@ -2385,10 +2411,15 @@
2385 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
2386 ** eligible to use [shared cache mode], regardless of whether or not shared
2387 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
2388 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2389 ** participate in [shared cache mode] even if it is enabled.
 
 
 
 
 
2390 **
2391 ** ^If the filename is ":memory:", then a private, temporary in-memory database
2392 ** is created for the connection. ^This in-memory database will vanish when
2393 ** the database connection is closed. Future versions of SQLite might
2394 ** make use of additional special filenames that begin with the ":" character.
@@ -2398,14 +2429,115 @@
2398 **
2399 ** ^If the filename is an empty string, then a private, temporary
2400 ** on-disk database will be created. ^This private database will be
2401 ** automatically deleted as soon as the database connection is closed.
2402 **
2403 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
2404 ** [sqlite3_vfs] object that defines the operating system interface that
2405 ** the new database connection should use. ^If the fourth parameter is
2406 ** a NULL pointer then the default [sqlite3_vfs] object is used.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2407 **
2408 ** <b>Note to Windows users:</b> The encoding used for the filename argument
2409 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
2410 ** codepage is currently defined. Filenames containing international
2411 ** characters must be converted to UTF-8 prior to passing them into
@@ -2423,10 +2555,30 @@
2423 const char *filename, /* Database filename (UTF-8) */
2424 sqlite3 **ppDb, /* OUT: SQLite db handle */
2425 int flags, /* Flags */
2426 const char *zVfs /* Name of VFS module to use */
2427 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2428
2429 /*
2430 ** CAPI3REF: Error Codes And Messages
2431 **
2432 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
@@ -2539,47 +2691,49 @@
2539 ** that can be lowered at run-time using [sqlite3_limit()].
2540 ** The synopsis of the meanings of the various limits is shown below.
2541 ** Additional information is available at [limits | Limits in SQLite].
2542 **
2543 ** <dl>
2544 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2545 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
2546 **
2547 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2548 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
2549 **
2550 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
2551 ** <dd>The maximum number of columns in a table definition or in the
2552 ** result set of a [SELECT] or the maximum number of columns in an index
2553 ** or in an ORDER BY or GROUP BY clause.</dd>)^
2554 **
2555 ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
2556 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
2557 **
2558 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2559 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
2560 **
2561 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2562 ** <dd>The maximum number of instructions in a virtual machine program
2563 ** used to implement an SQL statement. This limit is not currently
2564 ** enforced, though that might be added in some future release of
2565 ** SQLite.</dd>)^
2566 **
2567 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2568 ** <dd>The maximum number of arguments on a function.</dd>)^
2569 **
2570 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
2571 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
2572 **
 
2573 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2574 ** <dd>The maximum length of the pattern argument to the [LIKE] or
2575 ** [GLOB] operators.</dd>)^
2576 **
 
2577 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2578 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
2579 **
2580 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2581 ** <dd>The maximum depth of recursion for triggers.</dd>)^
2582 ** </dl>
2583 */
2584 #define SQLITE_LIMIT_LENGTH 0
2585 #define SQLITE_LIMIT_SQL_LENGTH 1
@@ -4610,10 +4764,15 @@
4610 int (*xRollback)(sqlite3_vtab *pVTab);
4611 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
4612 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
4613 void **ppArg);
4614 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
 
 
 
 
 
4615 };
4616
4617 /*
4618 ** CAPI3REF: Virtual Table Indexing Information
4619 ** KEYWORDS: sqlite3_index_info
@@ -5424,11 +5583,11 @@
5424 **
5425 ** ^This interface is used to retrieve runtime status information
5426 ** about the performance of SQLite, and optionally to reset various
5427 ** highwater marks. ^The first argument is an integer code for
5428 ** the specific parameter to measure. ^(Recognized integer codes
5429 ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
5430 ** ^The current value of the parameter is returned into *pCurrent.
5431 ** ^The highest recorded value is returned in *pHighwater. ^If the
5432 ** resetFlag is true, then the highest record value is reset after
5433 ** *pHighwater is written. ^(Some parameters do not record the highest
5434 ** value. For those parameters
@@ -5451,82 +5610,84 @@
5451 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5452
5453
5454 /*
5455 ** CAPI3REF: Status Parameters
 
5456 **
5457 ** These integer constants designate various run-time status parameters
5458 ** that can be returned by [sqlite3_status()].
5459 **
5460 ** <dl>
5461 ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
5462 ** <dd>This parameter is the current amount of memory checked out
5463 ** using [sqlite3_malloc()], either directly or indirectly. The
5464 ** figure includes calls made to [sqlite3_malloc()] by the application
5465 ** and internal memory usage by the SQLite library. Scratch memory
5466 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
5467 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
5468 ** this parameter. The amount returned is the sum of the allocation
5469 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
5470 **
5471 ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
5472 ** <dd>This parameter records the largest memory allocation request
5473 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5474 ** internal equivalents). Only the value returned in the
5475 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5476 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5477 **
5478 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5479 ** <dd>This parameter records the number of separate memory allocations
5480 ** currently checked out.</dd>)^
5481 **
5482 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5483 ** <dd>This parameter returns the number of pages used out of the
5484 ** [pagecache memory allocator] that was configured using
5485 ** [SQLITE_CONFIG_PAGECACHE]. The
5486 ** value returned is in pages, not in bytes.</dd>)^
5487 **
 
5488 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5489 ** <dd>This parameter returns the number of bytes of page cache
5490 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
5491 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
5492 ** returned value includes allocations that overflowed because they
5493 ** where too large (they were larger than the "sz" parameter to
5494 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5495 ** no space was left in the page cache.</dd>)^
5496 **
5497 ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
5498 ** <dd>This parameter records the largest memory allocation request
5499 ** handed to [pagecache memory allocator]. Only the value returned in the
5500 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5501 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5502 **
5503 ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
5504 ** <dd>This parameter returns the number of allocations used out of the
5505 ** [scratch memory allocator] configured using
5506 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
5507 ** in bytes. Since a single thread may only have one scratch allocation
5508 ** outstanding at time, this parameter also reports the number of threads
5509 ** using scratch memory at the same time.</dd>)^
5510 **
5511 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5512 ** <dd>This parameter returns the number of bytes of scratch memory
5513 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
5514 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
5515 ** returned include overflows because the requested allocation was too
5516 ** larger (that is, because the requested allocation was larger than the
5517 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5518 ** slots were available.
5519 ** </dd>)^
5520 **
5521 ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
5522 ** <dd>This parameter records the largest memory allocation request
5523 ** handed to [scratch memory allocator]. Only the value returned in the
5524 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5525 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5526 **
5527 ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
5528 ** <dd>This parameter records the deepest parser stack. It is only
5529 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
5530 ** </dl>
5531 **
5532 ** New status parameters may be added from time to time.
@@ -5547,13 +5708,13 @@
5547 **
5548 ** ^This interface is used to retrieve runtime status information
5549 ** about a single [database connection]. ^The first argument is the
5550 ** database connection object to be interrogated. ^The second argument
5551 ** is an integer constant, taken from the set of
5552 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5553 ** determines the parameter to interrogate. The set of
5554 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5555 ** to grow in future releases of SQLite.
5556 **
5557 ** ^The current value of the requested parameter is written into *pCur
5558 ** and the highest instantaneous value is written into *pHiwtr. ^If
5559 ** the resetFlg is true, then the highest instantaneous value is
@@ -5566,10 +5727,11 @@
5566 */
5567 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5568
5569 /*
5570 ** CAPI3REF: Status Parameters for database connections
 
5571 **
5572 ** These constants are the available integer "verbs" that can be passed as
5573 ** the second argument to the [sqlite3_db_status()] interface.
5574 **
5575 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5577,48 +5739,50 @@
5577 ** [sqlite3_db_status()] to make sure that the call worked.
5578 ** The [sqlite3_db_status()] interface will return a non-zero error code
5579 ** if a discontinued or unsupported verb is invoked.
5580 **
5581 ** <dl>
5582 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5583 ** <dd>This parameter returns the number of lookaside memory slots currently
5584 ** checked out.</dd>)^
5585 **
5586 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5587 ** <dd>This parameter returns the number malloc attempts that were
5588 ** satisfied using lookaside memory. Only the high-water value is meaningful;
5589 ** the current value is always zero.)^
5590 **
 
5591 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5592 ** <dd>This parameter returns the number malloc attempts that might have
5593 ** been satisfied using lookaside memory but failed due to the amount of
5594 ** memory requested being larger than the lookaside slot size.
5595 ** Only the high-water value is meaningful;
5596 ** the current value is always zero.)^
5597 **
 
5598 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5599 ** <dd>This parameter returns the number malloc attempts that might have
5600 ** been satisfied using lookaside memory but failed due to all lookaside
5601 ** memory already being in use.
5602 ** Only the high-water value is meaningful;
5603 ** the current value is always zero.)^
5604 **
5605 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5606 ** <dd>This parameter returns the approximate number of of bytes of heap
5607 ** memory used by all pager caches associated with the database connection.)^
5608 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5609 **
5610 ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5611 ** <dd>This parameter returns the approximate number of of bytes of heap
5612 ** memory used to store the schema for all databases associated
5613 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5614 ** ^The full amount of memory used by the schemas is reported, even if the
5615 ** schema memory is shared with other database connections due to
5616 ** [shared cache mode] being enabled.
5617 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5618 **
5619 ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5620 ** <dd>This parameter returns the approximate number of of bytes of heap
5621 ** and lookaside memory used by all prepared statements associated with
5622 ** the database connection.)^
5623 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5624 ** </dd>
@@ -5636,11 +5800,11 @@
5636
5637 /*
5638 ** CAPI3REF: Prepared Statement Status
5639 **
5640 ** ^(Each prepared statement maintains various
5641 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5642 ** of times it has performed specific operations.)^ These counters can
5643 ** be used to monitor the performance characteristics of the prepared
5644 ** statements. For example, if the number of table steps greatly exceeds
5645 ** the number of table searches or result rows, that would tend to indicate
5646 ** that the prepared statement is using a full table scan rather than
@@ -5647,11 +5811,11 @@
5647 ** an index.
5648 **
5649 ** ^(This interface is used to retrieve and reset counter values from
5650 ** a [prepared statement]. The first argument is the prepared statement
5651 ** object to be interrogated. The second argument
5652 ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
5653 ** to be interrogated.)^
5654 ** ^The current value of the requested counter is returned.
5655 ** ^If the resetFlg is true, then the counter is reset to zero after this
5656 ** interface call returns.
5657 **
@@ -5659,28 +5823,29 @@
5659 */
5660 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5661
5662 /*
5663 ** CAPI3REF: Status Parameters for prepared statements
 
5664 **
5665 ** These preprocessor macros define integer codes that name counter
5666 ** values associated with the [sqlite3_stmt_status()] interface.
5667 ** The meanings of the various counters are as follows:
5668 **
5669 ** <dl>
5670 ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
5671 ** <dd>^This is the number of times that SQLite has stepped forward in
5672 ** a table as part of a full table scan. Large numbers for this counter
5673 ** may indicate opportunities for performance improvement through
5674 ** careful use of indices.</dd>
5675 **
5676 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5677 ** <dd>^This is the number of sort operations that have occurred.
5678 ** A non-zero value in this counter may indicate an opportunity to
5679 ** improvement performance through careful use of indices.</dd>
5680 **
5681 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5682 ** <dd>^This is the number of rows inserted into transient indices that
5683 ** were created automatically in order to help joins run faster.
5684 ** A non-zero value in this counter may indicate an opportunity to
5685 ** improvement performance by adding permanent indices that do not
5686 ** need to be reinitialized each time the statement is run.</dd>
@@ -5727,10 +5892,11 @@
5727 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
5728 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
5729 ** the application may discard the parameter after the call to
5730 ** [sqlite3_config()] returns.)^
5731 **
 
5732 ** ^(The xInit() method is called once for each effective
5733 ** call to [sqlite3_initialize()])^
5734 ** (usually only once during the lifetime of the process). ^(The xInit()
5735 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
5736 ** The intent of the xInit() method is to set up global data structures
@@ -5737,10 +5903,11 @@
5737 ** required by the custom page cache implementation.
5738 ** ^(If the xInit() method is NULL, then the
5739 ** built-in default page cache is used instead of the application defined
5740 ** page cache.)^
5741 **
 
5742 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
5743 ** It can be used to clean up
5744 ** any outstanding resources before process shutdown, if required.
5745 ** ^The xShutdown() method may be NULL.
5746 **
@@ -5751,10 +5918,11 @@
5751 ** in multithreaded applications.
5752 **
5753 ** ^SQLite will never invoke xInit() more than once without an intervening
5754 ** call to xShutdown().
5755 **
 
5756 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
5757 ** SQLite will typically create one cache instance for each open database file,
5758 ** though this is not guaranteed. ^The
5759 ** first parameter, szPage, is the size in bytes of the pages that must
5760 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
@@ -5775,20 +5943,23 @@
5775 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
5776 ** false will always have the "discard" flag set to true.
5777 ** ^Hence, a cache created with bPurgeable false will
5778 ** never contain any unpinned pages.
5779 **
 
5780 ** ^(The xCachesize() method may be called at any time by SQLite to set the
5781 ** suggested maximum cache-size (number of pages stored by) the cache
5782 ** instance passed as the first argument. This is the value configured using
5783 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
5784 ** parameter, the implementation is not required to do anything with this
5785 ** value; it is advisory only.
5786 **
 
5787 ** The xPagecount() method must return the number of pages currently
5788 ** stored in the cache, both pinned and unpinned.
5789 **
 
5790 ** The xFetch() method locates a page in the cache and returns a pointer to
5791 ** the page, or a NULL pointer.
5792 ** A "page", in this context, means a buffer of szPage bytes aligned at an
5793 ** 8-byte boundary. The page to be fetched is determined by the key. ^The
5794 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
@@ -5813,10 +5984,11 @@
5813 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
5814 ** failed.)^ In between the to xFetch() calls, SQLite may
5815 ** attempt to unpin one or more cache pages by spilling the content of
5816 ** pinned pages to disk and synching the operating system disk cache.
5817 **
 
5818 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
5819 ** as its second argument. If the third parameter, discard, is non-zero,
5820 ** then the page must be evicted from the cache.
5821 ** ^If the discard parameter is
5822 ** zero, then the page may be discarded or retained at the discretion of
@@ -5825,10 +5997,11 @@
5825 **
5826 ** The cache must not perform any reference counting. A single
5827 ** call to xUnpin() unpins the page regardless of the number of prior calls
5828 ** to xFetch().
5829 **
 
5830 ** The xRekey() method is used to change the key value associated with the
5831 ** page passed as the second argument. If the cache
5832 ** previously contains an entry associated with newKey, it must be
5833 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
5834 ** to be pinned.
@@ -5837,10 +6010,11 @@
5837 ** existing cache entries with page numbers (keys) greater than or equal
5838 ** to the value of the iLimit parameter passed to xTruncate(). If any
5839 ** of these pages are pinned, they are implicitly unpinned, meaning that
5840 ** they can be safely discarded.
5841 **
 
5842 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
5843 ** All resources associated with the specified cache should be freed. ^After
5844 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
5845 ** handle invalid, and will not use it with any other sqlite3_pcache_methods
5846 ** functions.
@@ -5899,11 +6073,11 @@
5899 ** associated with the backup operation.
5900 ** </ol>)^
5901 ** There should be exactly one call to sqlite3_backup_finish() for each
5902 ** successful call to sqlite3_backup_init().
5903 **
5904 ** <b>sqlite3_backup_init()</b>
5905 **
5906 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
5907 ** [database connection] associated with the destination database
5908 ** and the database name, respectively.
5909 ** ^The database name is "main" for the main database, "temp" for the
@@ -5926,11 +6100,11 @@
5926 ** [sqlite3_backup] object.
5927 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
5928 ** sqlite3_backup_finish() functions to perform the specified backup
5929 ** operation.
5930 **
5931 ** <b>sqlite3_backup_step()</b>
5932 **
5933 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
5934 ** the source and destination databases specified by [sqlite3_backup] object B.
5935 ** ^If N is negative, all remaining source pages are copied.
5936 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
@@ -5983,11 +6157,11 @@
5983 ** restarted by the next call to sqlite3_backup_step(). ^If the source
5984 ** database is modified by the using the same database connection as is used
5985 ** by the backup operation, then the backup database is automatically
5986 ** updated at the same time.
5987 **
5988 ** <b>sqlite3_backup_finish()</b>
5989 **
5990 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
5991 ** application wishes to abandon the backup operation, the application
5992 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
5993 ** ^The sqlite3_backup_finish() interfaces releases all
@@ -6006,11 +6180,12 @@
6006 **
6007 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
6008 ** is not a permanent error and does not affect the return value of
6009 ** sqlite3_backup_finish().
6010 **
6011 ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
 
6012 **
6013 ** ^Each call to sqlite3_backup_step() sets two values inside
6014 ** the [sqlite3_backup] object: the number of pages still to be backed
6015 ** up and the total number of pages in the source database file.
6016 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
@@ -6391,10 +6566,97 @@
6391 ** each of these values.
6392 */
6393 #define SQLITE_CHECKPOINT_PASSIVE 0
6394 #define SQLITE_CHECKPOINT_FULL 1
6395 #define SQLITE_CHECKPOINT_RESTART 2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6396
6397
6398 /*
6399 ** Undo the hack that converts floating point types to integer for
6400 ** builds on processors without floating point support.
6401
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.7"
111 #define SQLITE_VERSION_NUMBER 3007007
112 #define SQLITE_SOURCE_ID "2011-05-18 03:02:10 186d7ff1d9804d508e472e4939608bf2be67bdc2"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -373,11 +373,12 @@
373 ** Many SQLite functions return an integer result code from the set shown
374 ** here in order to indicates success or failure.
375 **
376 ** New error codes may be added in future versions of SQLite.
377 **
378 ** See also: [SQLITE_IOERR_READ | extended result codes],
379 ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes].
380 */
381 #define SQLITE_OK 0 /* Successful result */
382 /* beginning-of-error-codes */
383 #define SQLITE_ERROR 1 /* SQL error or missing database */
384 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -455,25 +456,26 @@
456 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
457 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
458 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
459 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
460 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
461 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
462
463 /*
464 ** CAPI3REF: Flags For File Open Operations
465 **
466 ** These bit values are intended for use in the
467 ** 3rd parameter to the [sqlite3_open_v2()] interface and
468 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
 
469 */
470 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
471 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
472 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
473 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
474 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
475 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
476 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
477 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
478 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
479 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
480 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
481 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
@@ -580,21 +582,22 @@
582 };
583
584 /*
585 ** CAPI3REF: OS Interface File Virtual Methods Object
586 **
587 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
588 ** [sqlite3_file] object (or, more commonly, a subclass of the
589 ** [sqlite3_file] object) with a pointer to an instance of this object.
590 ** This object defines the methods used to perform various operations
591 ** against the open file represented by the [sqlite3_file] object.
592 **
593 ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
594 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
595 ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
596 ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
597 ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
598 ** to NULL.
599 **
600 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
601 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
602 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
603 ** flag may be ORed in to indicate that only the data of the file
@@ -759,10 +762,11 @@
762 */
763 typedef struct sqlite3_mutex sqlite3_mutex;
764
765 /*
766 ** CAPI3REF: OS Interface Object
767 ** KEYWORDS: VFS VFSes
768 **
769 ** An instance of the sqlite3_vfs object defines the interface between
770 ** the SQLite core and the underlying operating system. The "vfs"
771 ** in the name of the object stands for "virtual file system".
772 **
@@ -791,10 +795,11 @@
795 ** object once the object has been registered.
796 **
797 ** The zName field holds the name of the VFS module. The name must
798 ** be unique across all VFS modules.
799 **
800 ** [[sqlite3_vfs.xOpen]]
801 ** ^SQLite guarantees that the zFilename parameter to xOpen
802 ** is either a NULL pointer or string obtained
803 ** from xFullPathname() with an optional suffix added.
804 ** ^If a suffix is added to the zFilename parameter, it will
805 ** consist of a single "-" character followed by no more than
@@ -868,10 +873,11 @@
873 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
874 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
875 ** element will be valid after xOpen returns regardless of the success
876 ** or failure of the xOpen call.
877 **
878 ** [[sqlite3_vfs.xAccess]]
879 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
880 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
881 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
882 ** to test whether a file is at least readable. The file can be a
883 ** directory.
@@ -1114,13 +1120,13 @@
1120 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1121 ** Note, however, that ^sqlite3_config() can be called as part of the
1122 ** implementation of an application-defined [sqlite3_os_init()].
1123 **
1124 ** The first argument to sqlite3_config() is an integer
1125 ** [configuration option] that determines
1126 ** what property of SQLite is to be configured. Subsequent arguments
1127 ** vary depending on the [configuration option]
1128 ** in the first argument.
1129 **
1130 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1131 ** ^If the option is unknown or SQLite is unable to set the option
1132 ** then this routine returns a non-zero [error code].
@@ -1226,10 +1232,11 @@
1232 void *pAppData; /* Argument to xInit() and xShutdown() */
1233 };
1234
1235 /*
1236 ** CAPI3REF: Configuration Options
1237 ** KEYWORDS: {configuration option}
1238 **
1239 ** These constants are the available integer configuration options that
1240 ** can be passed as the first argument to the [sqlite3_config()] interface.
1241 **
1242 ** New configuration options may be added in future releases of SQLite.
@@ -1238,11 +1245,11 @@
1245 ** the call worked. The [sqlite3_config()] interface will return a
1246 ** non-zero [error code] if a discontinued or unsupported configuration option
1247 ** is invoked.
1248 **
1249 ** <dl>
1250 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1251 ** <dd>There are no arguments to this option. ^This option sets the
1252 ** [threading mode] to Single-thread. In other words, it disables
1253 ** all mutexing and puts SQLite into a mode where it can only be used
1254 ** by a single thread. ^If SQLite is compiled with
1255 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
@@ -1249,11 +1256,11 @@
1256 ** it is not possible to change the [threading mode] from its default
1257 ** value of Single-thread and so [sqlite3_config()] will return
1258 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1259 ** configuration option.</dd>
1260 **
1261 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1262 ** <dd>There are no arguments to this option. ^This option sets the
1263 ** [threading mode] to Multi-thread. In other words, it disables
1264 ** mutexing on [database connection] and [prepared statement] objects.
1265 ** The application is responsible for serializing access to
1266 ** [database connections] and [prepared statements]. But other mutexes
@@ -1263,11 +1270,11 @@
1270 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1271 ** it is not possible to set the Multi-thread [threading mode] and
1272 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1273 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1274 **
1275 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1276 ** <dd>There are no arguments to this option. ^This option sets the
1277 ** [threading mode] to Serialized. In other words, this option enables
1278 ** all mutexes including the recursive
1279 ** mutexes on [database connection] and [prepared statement] objects.
1280 ** In this mode (which is the default when SQLite is compiled with
@@ -1279,27 +1286,27 @@
1286 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1287 ** it is not possible to set the Serialized [threading mode] and
1288 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1289 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1290 **
1291 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1292 ** <dd> ^(This option takes a single argument which is a pointer to an
1293 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
1294 ** alternative low-level memory allocation routines to be used in place of
1295 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1296 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1297 ** before the [sqlite3_config()] call returns.</dd>
1298 **
1299 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1300 ** <dd> ^(This option takes a single argument which is a pointer to an
1301 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1302 ** structure is filled with the currently defined memory allocation routines.)^
1303 ** This option can be used to overload the default memory allocation
1304 ** routines with a wrapper that simulations memory allocation failure or
1305 ** tracks memory usage, for example. </dd>
1306 **
1307 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1308 ** <dd> ^This option takes single argument of type int, interpreted as a
1309 ** boolean, which enables or disables the collection of memory allocation
1310 ** statistics. ^(When memory allocation statistics are disabled, the
1311 ** following SQLite interfaces become non-operational:
1312 ** <ul>
@@ -1311,11 +1318,11 @@
1318 ** ^Memory allocation statistics are enabled by default unless SQLite is
1319 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1320 ** allocation statistics are disabled by default.
1321 ** </dd>
1322 **
1323 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1324 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1325 ** scratch memory. There are three arguments: A pointer an 8-byte
1326 ** aligned memory buffer from which the scratch allocations will be
1327 ** drawn, the size of each scratch allocation (sz),
1328 ** and the maximum number of scratch allocations (N). The sz
@@ -1327,11 +1334,11 @@
1334 ** ^SQLite will never require a scratch buffer that is more than 6
1335 ** times the database page size. ^If SQLite needs needs additional
1336 ** scratch memory beyond what is provided by this configuration option, then
1337 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1338 **
1339 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1340 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1341 ** the database page cache with the default page cache implemenation.
1342 ** This configuration should not be used if an application-define page
1343 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
1344 ** There are three arguments to this option: A pointer to 8-byte aligned
@@ -1348,11 +1355,11 @@
1355 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1356 ** The pointer in the first argument must
1357 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1358 ** will be undefined.</dd>
1359 **
1360 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1361 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1362 ** for all of its dynamic memory allocation needs beyond those provided
1363 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1364 ** There are three arguments: An 8-byte aligned pointer to the memory,
1365 ** the number of bytes in the memory buffer, and the minimum allocation size.
@@ -1365,11 +1372,11 @@
1372 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1373 ** boundary or subsequent behavior of SQLite will be undefined.
1374 ** The minimum allocation size is capped at 2^12. Reasonable values
1375 ** for the minimum allocation size are 2^5 through 2^8.</dd>
1376 **
1377 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1378 ** <dd> ^(This option takes a single argument which is a pointer to an
1379 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1380 ** alternative low-level mutex routines to be used in place
1381 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1382 ** content of the [sqlite3_mutex_methods] structure before the call to
@@ -1377,11 +1384,11 @@
1384 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1385 ** the entire mutexing subsystem is omitted from the build and hence calls to
1386 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1387 ** return [SQLITE_ERROR].</dd>
1388 **
1389 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1390 ** <dd> ^(This option takes a single argument which is a pointer to an
1391 ** instance of the [sqlite3_mutex_methods] structure. The
1392 ** [sqlite3_mutex_methods]
1393 ** structure is filled with the currently defined mutex routines.)^
1394 ** This option can be used to overload the default mutex allocation
@@ -1390,32 +1397,32 @@
1397 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1398 ** the entire mutexing subsystem is omitted from the build and hence calls to
1399 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1400 ** return [SQLITE_ERROR].</dd>
1401 **
1402 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1403 ** <dd> ^(This option takes two arguments that determine the default
1404 ** memory allocation for the lookaside memory allocator on each
1405 ** [database connection]. The first argument is the
1406 ** size of each lookaside buffer slot and the second is the number of
1407 ** slots allocated to each database connection.)^ ^(This option sets the
1408 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1409 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1410 ** configuration on individual connections.)^ </dd>
1411 **
1412 ** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt>
1413 ** <dd> ^(This option takes a single argument which is a pointer to
1414 ** an [sqlite3_pcache_methods] object. This object specifies the interface
1415 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1416 ** object and uses it for page cache memory allocations.</dd>
1417 **
1418 ** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt>
1419 ** <dd> ^(This option takes a single argument which is a pointer to an
1420 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1421 ** page cache implementation into that object.)^ </dd>
1422 **
1423 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1424 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1425 ** function with a call signature of void(*)(void*,int,const char*),
1426 ** and a pointer to void. ^If the function pointer is not NULL, it is
1427 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1428 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
@@ -1429,10 +1436,22 @@
1436 ** The SQLite logging interface is not reentrant; the logger function
1437 ** supplied by the application must not invoke any SQLite interface.
1438 ** In a multi-threaded application, the application-defined logger
1439 ** function must be threadsafe. </dd>
1440 **
1441 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1442 ** <dd> This option takes a single argument of type int. If non-zero, then
1443 ** URI handling is globally enabled. If the parameter is zero, then URI handling
1444 ** is globally disabled. If URI handling is globally enabled, all filenames
1445 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1446 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1447 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1448 ** connection is opened. If it is globally disabled, filenames are
1449 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1450 ** database connection is opened. By default, URI handling is globally
1451 ** disabled. The default value may be changed by compiling with the
1452 ** [SQLITE_USE_URI] symbol defined.
1453 ** </dl>
1454 */
1455 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1456 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1457 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1447,10 +1466,11 @@
1466 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
1467 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
1468 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1469 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1470 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1471 #define SQLITE_CONFIG_URI 17 /* int */
1472
1473 /*
1474 ** CAPI3REF: Database Connection Configuration Options
1475 **
1476 ** These constants are the available integer configuration options that
@@ -1532,17 +1552,21 @@
1552 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1553 ** is another alias for the rowid.
1554 **
1555 ** ^This routine returns the [rowid] of the most recent
1556 ** successful [INSERT] into the database from the [database connection]
1557 ** in the first argument. ^As of SQLite version 3.7.7, this routines
1558 ** records the last insert rowid of both ordinary tables and [virtual tables].
1559 ** ^If no successful [INSERT]s
1560 ** have ever occurred on that database connection, zero is returned.
1561 **
1562 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table]
1563 ** method, then this routine will return the [rowid] of the inserted
1564 ** row as long as the trigger or virtual table method is running.
1565 ** But once the trigger or virtual table method ends, the value returned
1566 ** by this routine reverts to what it was before the trigger or virtual
1567 ** table method began.)^
1568 **
1569 ** ^An [INSERT] that fails due to a constraint violation is not a
1570 ** successful [INSERT] and does not change the value returned by this
1571 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
1572 ** and INSERT OR ABORT make no changes to the return value of this
@@ -2201,10 +2225,13 @@
2225 ** The [sqlite3_set_authorizer | authorizer callback function] must
2226 ** return either [SQLITE_OK] or one of these two constants in order
2227 ** to signal SQLite whether or not the action is permitted. See the
2228 ** [sqlite3_set_authorizer | authorizer documentation] for additional
2229 ** information.
2230 **
2231 ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code]
2232 ** from the [sqlite3_vtab_on_conflict()] interface.
2233 */
2234 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */
2235 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
2236
2237 /*
@@ -2323,11 +2350,11 @@
2350 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
2351
2352 /*
2353 ** CAPI3REF: Opening A New Database Connection
2354 **
2355 ** ^These routines open an SQLite database file as specified by the
2356 ** filename argument. ^The filename argument is interpreted as UTF-8 for
2357 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
2358 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
2359 ** returned in *ppDb, even if an error occurs. The only exception is that
2360 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
@@ -2350,11 +2377,11 @@
2377 ** except that it accepts two additional parameters for additional control
2378 ** over the new database connection. ^(The flags parameter to
2379 ** sqlite3_open_v2() can take one of
2380 ** the following three values, optionally combined with the
2381 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
2382 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
2383 **
2384 ** <dl>
2385 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
2386 ** <dd>The database is opened in read-only mode. If the database does not
2387 ** already exist, an error is returned.</dd>)^
@@ -2369,13 +2396,12 @@
2396 ** it does not already exist. This is the behavior that is always used for
2397 ** sqlite3_open() and sqlite3_open16().</dd>)^
2398 ** </dl>
2399 **
2400 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
2401 ** combinations shown above optionally combined with other
2402 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
 
2403 ** then the behavior is undefined.
2404 **
2405 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
2406 ** opens in the multi-thread [threading mode] as long as the single-thread
2407 ** mode has not been set at compile-time or start-time. ^If the
@@ -2385,10 +2411,15 @@
2411 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
2412 ** eligible to use [shared cache mode], regardless of whether or not shared
2413 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
2414 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
2415 ** participate in [shared cache mode] even if it is enabled.
2416 **
2417 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
2418 ** [sqlite3_vfs] object that defines the operating system interface that
2419 ** the new database connection should use. ^If the fourth parameter is
2420 ** a NULL pointer then the default [sqlite3_vfs] object is used.
2421 **
2422 ** ^If the filename is ":memory:", then a private, temporary in-memory database
2423 ** is created for the connection. ^This in-memory database will vanish when
2424 ** the database connection is closed. Future versions of SQLite might
2425 ** make use of additional special filenames that begin with the ":" character.
@@ -2398,14 +2429,115 @@
2429 **
2430 ** ^If the filename is an empty string, then a private, temporary
2431 ** on-disk database will be created. ^This private database will be
2432 ** automatically deleted as soon as the database connection is closed.
2433 **
2434 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
2435 **
2436 ** ^If [URI filename] interpretation is enabled, and the filename argument
2437 ** begins with "file:", then the filename is interpreted as a URI. ^URI
2438 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
2439 ** is set in the fourth argument to sqlite3_open_v2(), or if it has
2440 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
2441 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
2442 ** As of SQLite version 3.7.7, URI filename interpretation is turned off
2443 ** by default, but future releases of SQLite might enable URI filename
2444 ** intepretation by default. See "[URI filenames]" for additional
2445 ** information.
2446 **
2447 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
2448 ** authority, then it must be either an empty string or the string
2449 ** "localhost". ^If the authority is not an empty string or "localhost", an
2450 ** error is returned to the caller. ^The fragment component of a URI, if
2451 ** present, is ignored.
2452 **
2453 ** ^SQLite uses the path component of the URI as the name of the disk file
2454 ** which contains the database. ^If the path begins with a '/' character,
2455 ** then it is interpreted as an absolute path. ^If the path does not begin
2456 ** with a '/' (meaning that the authority section is omitted from the URI)
2457 ** then the path is interpreted as a relative path.
2458 ** ^On windows, the first component of an absolute path
2459 ** is a drive specification (e.g. "C:").
2460 **
2461 ** [[core URI query parameters]]
2462 ** The query component of a URI may contain parameters that are interpreted
2463 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
2464 ** SQLite interprets the following three query parameters:
2465 **
2466 ** <ul>
2467 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
2468 ** a VFS object that provides the operating system interface that should
2469 ** be used to access the database file on disk. ^If this option is set to
2470 ** an empty string the default VFS object is used. ^Specifying an unknown
2471 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
2472 ** present, then the VFS specified by the option takes precedence over
2473 ** the value passed as the fourth parameter to sqlite3_open_v2().
2474 **
2475 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or
2476 ** "rwc". Attempting to set it to any other value is an error)^.
2477 ** ^If "ro" is specified, then the database is opened for read-only
2478 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
2479 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to
2480 ** "rw", then the database is opened for read-write (but not create)
2481 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
2482 ** been set. ^Value "rwc" is equivalent to setting both
2483 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is
2484 ** used, it is an error to specify a value for the mode parameter that is
2485 ** less restrictive than that specified by the flags passed as the third
2486 ** parameter.
2487 **
2488 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
2489 ** "private". ^Setting it to "shared" is equivalent to setting the
2490 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
2491 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
2492 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
2493 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
2494 ** a URI filename, its value overrides any behaviour requested by setting
2495 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
2496 ** </ul>
2497 **
2498 ** ^Specifying an unknown parameter in the query component of a URI is not an
2499 ** error. Future versions of SQLite might understand additional query
2500 ** parameters. See "[query parameters with special meaning to SQLite]" for
2501 ** additional information.
2502 **
2503 ** [[URI filename examples]] <h3>URI filename examples</h3>
2504 **
2505 ** <table border="1" align=center cellpadding=5>
2506 ** <tr><th> URI filenames <th> Results
2507 ** <tr><td> file:data.db <td>
2508 ** Open the file "data.db" in the current directory.
2509 ** <tr><td> file:/home/fred/data.db<br>
2510 ** file:///home/fred/data.db <br>
2511 ** file://localhost/home/fred/data.db <br> <td>
2512 ** Open the database file "/home/fred/data.db".
2513 ** <tr><td> file://darkstar/home/fred/data.db <td>
2514 ** An error. "darkstar" is not a recognized authority.
2515 ** <tr><td style="white-space:nowrap">
2516 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
2517 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive
2518 ** C:. Note that the %20 escaping in this example is not strictly
2519 ** necessary - space characters can be used literally
2520 ** in URI filenames.
2521 ** <tr><td> file:data.db?mode=ro&cache=private <td>
2522 ** Open file "data.db" in the current directory for read-only access.
2523 ** Regardless of whether or not shared-cache mode is enabled by
2524 ** default, use a private cache.
2525 ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td>
2526 ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock".
2527 ** <tr><td> file:data.db?mode=readonly <td>
2528 ** An error. "readonly" is not a valid option for the "mode" parameter.
2529 ** </table>
2530 **
2531 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
2532 ** query components of a URI. A hexadecimal escape sequence consists of a
2533 ** percent sign - "%" - followed by exactly two hexadecimal digits
2534 ** specifying an octet value. ^Before the path or query components of a
2535 ** URI filename are interpreted, they are encoded using UTF-8 and all
2536 ** hexadecimal escape sequences replaced by a single byte containing the
2537 ** corresponding octet. If this process generates an invalid UTF-8 encoding,
2538 ** the results are undefined.
2539 **
2540 ** <b>Note to Windows users:</b> The encoding used for the filename argument
2541 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
2542 ** codepage is currently defined. Filenames containing international
2543 ** characters must be converted to UTF-8 prior to passing them into
@@ -2423,10 +2555,30 @@
2555 const char *filename, /* Database filename (UTF-8) */
2556 sqlite3 **ppDb, /* OUT: SQLite db handle */
2557 int flags, /* Flags */
2558 const char *zVfs /* Name of VFS module to use */
2559 );
2560
2561 /*
2562 ** CAPI3REF: Obtain Values For URI Parameters
2563 **
2564 ** This is a utility routine, useful to VFS implementations, that checks
2565 ** to see if a database file was a URI that contained a specific query
2566 ** parameter, and if so obtains the value of the query parameter.
2567 **
2568 ** The zFilename argument is the filename pointer passed into the xOpen()
2569 ** method of a VFS implementation. The zParam argument is the name of the
2570 ** query parameter we seek. This routine returns the value of the zParam
2571 ** parameter if it exists. If the parameter does not exist, this routine
2572 ** returns a NULL pointer.
2573 **
2574 ** If the zFilename argument to this function is not a pointer that SQLite
2575 ** passed into the xOpen VFS method, then the behavior of this routine
2576 ** is undefined and probably undesirable.
2577 */
2578 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
2579
2580
2581 /*
2582 ** CAPI3REF: Error Codes And Messages
2583 **
2584 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
@@ -2539,47 +2691,49 @@
2691 ** that can be lowered at run-time using [sqlite3_limit()].
2692 ** The synopsis of the meanings of the various limits is shown below.
2693 ** Additional information is available at [limits | Limits in SQLite].
2694 **
2695 ** <dl>
2696 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
2697 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
2698 **
2699 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
2700 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
2701 **
2702 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
2703 ** <dd>The maximum number of columns in a table definition or in the
2704 ** result set of a [SELECT] or the maximum number of columns in an index
2705 ** or in an ORDER BY or GROUP BY clause.</dd>)^
2706 **
2707 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
2708 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
2709 **
2710 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
2711 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
2712 **
2713 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
2714 ** <dd>The maximum number of instructions in a virtual machine program
2715 ** used to implement an SQL statement. This limit is not currently
2716 ** enforced, though that might be added in some future release of
2717 ** SQLite.</dd>)^
2718 **
2719 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
2720 ** <dd>The maximum number of arguments on a function.</dd>)^
2721 **
2722 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
2723 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
2724 **
2725 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
2726 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
2727 ** <dd>The maximum length of the pattern argument to the [LIKE] or
2728 ** [GLOB] operators.</dd>)^
2729 **
2730 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
2731 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
2732 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
2733 **
2734 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
2735 ** <dd>The maximum depth of recursion for triggers.</dd>)^
2736 ** </dl>
2737 */
2738 #define SQLITE_LIMIT_LENGTH 0
2739 #define SQLITE_LIMIT_SQL_LENGTH 1
@@ -4610,10 +4764,15 @@
4764 int (*xRollback)(sqlite3_vtab *pVTab);
4765 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
4766 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
4767 void **ppArg);
4768 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
4769 /* The methods above are in version 1 of the sqlite_module object. Those
4770 ** below are for version 2 and greater. */
4771 int (*xSavepoint)(sqlite3_vtab *pVTab, int);
4772 int (*xRelease)(sqlite3_vtab *pVTab, int);
4773 int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
4774 };
4775
4776 /*
4777 ** CAPI3REF: Virtual Table Indexing Information
4778 ** KEYWORDS: sqlite3_index_info
@@ -5424,11 +5583,11 @@
5583 **
5584 ** ^This interface is used to retrieve runtime status information
5585 ** about the performance of SQLite, and optionally to reset various
5586 ** highwater marks. ^The first argument is an integer code for
5587 ** the specific parameter to measure. ^(Recognized integer codes
5588 ** are of the form [status parameters | SQLITE_STATUS_...].)^
5589 ** ^The current value of the parameter is returned into *pCurrent.
5590 ** ^The highest recorded value is returned in *pHighwater. ^If the
5591 ** resetFlag is true, then the highest record value is reset after
5592 ** *pHighwater is written. ^(Some parameters do not record the highest
5593 ** value. For those parameters
@@ -5451,82 +5610,84 @@
5610 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5611
5612
5613 /*
5614 ** CAPI3REF: Status Parameters
5615 ** KEYWORDS: {status parameters}
5616 **
5617 ** These integer constants designate various run-time status parameters
5618 ** that can be returned by [sqlite3_status()].
5619 **
5620 ** <dl>
5621 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
5622 ** <dd>This parameter is the current amount of memory checked out
5623 ** using [sqlite3_malloc()], either directly or indirectly. The
5624 ** figure includes calls made to [sqlite3_malloc()] by the application
5625 ** and internal memory usage by the SQLite library. Scratch memory
5626 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
5627 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
5628 ** this parameter. The amount returned is the sum of the allocation
5629 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
5630 **
5631 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
5632 ** <dd>This parameter records the largest memory allocation request
5633 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
5634 ** internal equivalents). Only the value returned in the
5635 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5636 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5637 **
5638 ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
5639 ** <dd>This parameter records the number of separate memory allocations
5640 ** currently checked out.</dd>)^
5641 **
5642 ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
5643 ** <dd>This parameter returns the number of pages used out of the
5644 ** [pagecache memory allocator] that was configured using
5645 ** [SQLITE_CONFIG_PAGECACHE]. The
5646 ** value returned is in pages, not in bytes.</dd>)^
5647 **
5648 ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
5649 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
5650 ** <dd>This parameter returns the number of bytes of page cache
5651 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
5652 ** buffer and where forced to overflow to [sqlite3_malloc()]. The
5653 ** returned value includes allocations that overflowed because they
5654 ** where too large (they were larger than the "sz" parameter to
5655 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
5656 ** no space was left in the page cache.</dd>)^
5657 **
5658 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
5659 ** <dd>This parameter records the largest memory allocation request
5660 ** handed to [pagecache memory allocator]. Only the value returned in the
5661 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5662 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5663 **
5664 ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
5665 ** <dd>This parameter returns the number of allocations used out of the
5666 ** [scratch memory allocator] configured using
5667 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
5668 ** in bytes. Since a single thread may only have one scratch allocation
5669 ** outstanding at time, this parameter also reports the number of threads
5670 ** using scratch memory at the same time.</dd>)^
5671 **
5672 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
5673 ** <dd>This parameter returns the number of bytes of scratch memory
5674 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
5675 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
5676 ** returned include overflows because the requested allocation was too
5677 ** larger (that is, because the requested allocation was larger than the
5678 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
5679 ** slots were available.
5680 ** </dd>)^
5681 **
5682 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
5683 ** <dd>This parameter records the largest memory allocation request
5684 ** handed to [scratch memory allocator]. Only the value returned in the
5685 ** *pHighwater parameter to [sqlite3_status()] is of interest.
5686 ** The value written into the *pCurrent parameter is undefined.</dd>)^
5687 **
5688 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
5689 ** <dd>This parameter records the deepest parser stack. It is only
5690 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
5691 ** </dl>
5692 **
5693 ** New status parameters may be added from time to time.
@@ -5547,13 +5708,13 @@
5708 **
5709 ** ^This interface is used to retrieve runtime status information
5710 ** about a single [database connection]. ^The first argument is the
5711 ** database connection object to be interrogated. ^The second argument
5712 ** is an integer constant, taken from the set of
5713 ** [SQLITE_DBSTATUS options], that
5714 ** determines the parameter to interrogate. The set of
5715 ** [SQLITE_DBSTATUS options] is likely
5716 ** to grow in future releases of SQLite.
5717 **
5718 ** ^The current value of the requested parameter is written into *pCur
5719 ** and the highest instantaneous value is written into *pHiwtr. ^If
5720 ** the resetFlg is true, then the highest instantaneous value is
@@ -5566,10 +5727,11 @@
5727 */
5728 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5729
5730 /*
5731 ** CAPI3REF: Status Parameters for database connections
5732 ** KEYWORDS: {SQLITE_DBSTATUS options}
5733 **
5734 ** These constants are the available integer "verbs" that can be passed as
5735 ** the second argument to the [sqlite3_db_status()] interface.
5736 **
5737 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5577,48 +5739,50 @@
5739 ** [sqlite3_db_status()] to make sure that the call worked.
5740 ** The [sqlite3_db_status()] interface will return a non-zero error code
5741 ** if a discontinued or unsupported verb is invoked.
5742 **
5743 ** <dl>
5744 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5745 ** <dd>This parameter returns the number of lookaside memory slots currently
5746 ** checked out.</dd>)^
5747 **
5748 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
5749 ** <dd>This parameter returns the number malloc attempts that were
5750 ** satisfied using lookaside memory. Only the high-water value is meaningful;
5751 ** the current value is always zero.)^
5752 **
5753 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
5754 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
5755 ** <dd>This parameter returns the number malloc attempts that might have
5756 ** been satisfied using lookaside memory but failed due to the amount of
5757 ** memory requested being larger than the lookaside slot size.
5758 ** Only the high-water value is meaningful;
5759 ** the current value is always zero.)^
5760 **
5761 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
5762 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
5763 ** <dd>This parameter returns the number malloc attempts that might have
5764 ** been satisfied using lookaside memory but failed due to all lookaside
5765 ** memory already being in use.
5766 ** Only the high-water value is meaningful;
5767 ** the current value is always zero.)^
5768 **
5769 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5770 ** <dd>This parameter returns the approximate number of of bytes of heap
5771 ** memory used by all pager caches associated with the database connection.)^
5772 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5773 **
5774 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
5775 ** <dd>This parameter returns the approximate number of of bytes of heap
5776 ** memory used to store the schema for all databases associated
5777 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
5778 ** ^The full amount of memory used by the schemas is reported, even if the
5779 ** schema memory is shared with other database connections due to
5780 ** [shared cache mode] being enabled.
5781 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
5782 **
5783 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
5784 ** <dd>This parameter returns the approximate number of of bytes of heap
5785 ** and lookaside memory used by all prepared statements associated with
5786 ** the database connection.)^
5787 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
5788 ** </dd>
@@ -5636,11 +5800,11 @@
5800
5801 /*
5802 ** CAPI3REF: Prepared Statement Status
5803 **
5804 ** ^(Each prepared statement maintains various
5805 ** [SQLITE_STMTSTATUS counters] that measure the number
5806 ** of times it has performed specific operations.)^ These counters can
5807 ** be used to monitor the performance characteristics of the prepared
5808 ** statements. For example, if the number of table steps greatly exceeds
5809 ** the number of table searches or result rows, that would tend to indicate
5810 ** that the prepared statement is using a full table scan rather than
@@ -5647,11 +5811,11 @@
5811 ** an index.
5812 **
5813 ** ^(This interface is used to retrieve and reset counter values from
5814 ** a [prepared statement]. The first argument is the prepared statement
5815 ** object to be interrogated. The second argument
5816 ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
5817 ** to be interrogated.)^
5818 ** ^The current value of the requested counter is returned.
5819 ** ^If the resetFlg is true, then the counter is reset to zero after this
5820 ** interface call returns.
5821 **
@@ -5659,28 +5823,29 @@
5823 */
5824 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5825
5826 /*
5827 ** CAPI3REF: Status Parameters for prepared statements
5828 ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
5829 **
5830 ** These preprocessor macros define integer codes that name counter
5831 ** values associated with the [sqlite3_stmt_status()] interface.
5832 ** The meanings of the various counters are as follows:
5833 **
5834 ** <dl>
5835 ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
5836 ** <dd>^This is the number of times that SQLite has stepped forward in
5837 ** a table as part of a full table scan. Large numbers for this counter
5838 ** may indicate opportunities for performance improvement through
5839 ** careful use of indices.</dd>
5840 **
5841 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
5842 ** <dd>^This is the number of sort operations that have occurred.
5843 ** A non-zero value in this counter may indicate an opportunity to
5844 ** improvement performance through careful use of indices.</dd>
5845 **
5846 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5847 ** <dd>^This is the number of rows inserted into transient indices that
5848 ** were created automatically in order to help joins run faster.
5849 ** A non-zero value in this counter may indicate an opportunity to
5850 ** improvement performance by adding permanent indices that do not
5851 ** need to be reinitialized each time the statement is run.</dd>
@@ -5727,10 +5892,11 @@
5892 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
5893 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence
5894 ** the application may discard the parameter after the call to
5895 ** [sqlite3_config()] returns.)^
5896 **
5897 ** [[the xInit() page cache method]]
5898 ** ^(The xInit() method is called once for each effective
5899 ** call to [sqlite3_initialize()])^
5900 ** (usually only once during the lifetime of the process). ^(The xInit()
5901 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
5902 ** The intent of the xInit() method is to set up global data structures
@@ -5737,10 +5903,11 @@
5903 ** required by the custom page cache implementation.
5904 ** ^(If the xInit() method is NULL, then the
5905 ** built-in default page cache is used instead of the application defined
5906 ** page cache.)^
5907 **
5908 ** [[the xShutdown() page cache method]]
5909 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
5910 ** It can be used to clean up
5911 ** any outstanding resources before process shutdown, if required.
5912 ** ^The xShutdown() method may be NULL.
5913 **
@@ -5751,10 +5918,11 @@
5918 ** in multithreaded applications.
5919 **
5920 ** ^SQLite will never invoke xInit() more than once without an intervening
5921 ** call to xShutdown().
5922 **
5923 ** [[the xCreate() page cache methods]]
5924 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
5925 ** SQLite will typically create one cache instance for each open database file,
5926 ** though this is not guaranteed. ^The
5927 ** first parameter, szPage, is the size in bytes of the pages that must
5928 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
@@ -5775,20 +5943,23 @@
5943 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
5944 ** false will always have the "discard" flag set to true.
5945 ** ^Hence, a cache created with bPurgeable false will
5946 ** never contain any unpinned pages.
5947 **
5948 ** [[the xCachesize() page cache method]]
5949 ** ^(The xCachesize() method may be called at any time by SQLite to set the
5950 ** suggested maximum cache-size (number of pages stored by) the cache
5951 ** instance passed as the first argument. This is the value configured using
5952 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable
5953 ** parameter, the implementation is not required to do anything with this
5954 ** value; it is advisory only.
5955 **
5956 ** [[the xPagecount() page cache methods]]
5957 ** The xPagecount() method must return the number of pages currently
5958 ** stored in the cache, both pinned and unpinned.
5959 **
5960 ** [[the xFetch() page cache methods]]
5961 ** The xFetch() method locates a page in the cache and returns a pointer to
5962 ** the page, or a NULL pointer.
5963 ** A "page", in this context, means a buffer of szPage bytes aligned at an
5964 ** 8-byte boundary. The page to be fetched is determined by the key. ^The
5965 ** mimimum key value is 1. After it has been retrieved using xFetch, the page
@@ -5813,10 +5984,11 @@
5984 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
5985 ** failed.)^ In between the to xFetch() calls, SQLite may
5986 ** attempt to unpin one or more cache pages by spilling the content of
5987 ** pinned pages to disk and synching the operating system disk cache.
5988 **
5989 ** [[the xUnpin() page cache method]]
5990 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
5991 ** as its second argument. If the third parameter, discard, is non-zero,
5992 ** then the page must be evicted from the cache.
5993 ** ^If the discard parameter is
5994 ** zero, then the page may be discarded or retained at the discretion of
@@ -5825,10 +5997,11 @@
5997 **
5998 ** The cache must not perform any reference counting. A single
5999 ** call to xUnpin() unpins the page regardless of the number of prior calls
6000 ** to xFetch().
6001 **
6002 ** [[the xRekey() page cache methods]]
6003 ** The xRekey() method is used to change the key value associated with the
6004 ** page passed as the second argument. If the cache
6005 ** previously contains an entry associated with newKey, it must be
6006 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
6007 ** to be pinned.
@@ -5837,10 +6010,11 @@
6010 ** existing cache entries with page numbers (keys) greater than or equal
6011 ** to the value of the iLimit parameter passed to xTruncate(). If any
6012 ** of these pages are pinned, they are implicitly unpinned, meaning that
6013 ** they can be safely discarded.
6014 **
6015 ** [[the xDestroy() page cache method]]
6016 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
6017 ** All resources associated with the specified cache should be freed. ^After
6018 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
6019 ** handle invalid, and will not use it with any other sqlite3_pcache_methods
6020 ** functions.
@@ -5899,11 +6073,11 @@
6073 ** associated with the backup operation.
6074 ** </ol>)^
6075 ** There should be exactly one call to sqlite3_backup_finish() for each
6076 ** successful call to sqlite3_backup_init().
6077 **
6078 ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
6079 **
6080 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
6081 ** [database connection] associated with the destination database
6082 ** and the database name, respectively.
6083 ** ^The database name is "main" for the main database, "temp" for the
@@ -5926,11 +6100,11 @@
6100 ** [sqlite3_backup] object.
6101 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
6102 ** sqlite3_backup_finish() functions to perform the specified backup
6103 ** operation.
6104 **
6105 ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
6106 **
6107 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
6108 ** the source and destination databases specified by [sqlite3_backup] object B.
6109 ** ^If N is negative, all remaining source pages are copied.
6110 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
@@ -5983,11 +6157,11 @@
6157 ** restarted by the next call to sqlite3_backup_step(). ^If the source
6158 ** database is modified by the using the same database connection as is used
6159 ** by the backup operation, then the backup database is automatically
6160 ** updated at the same time.
6161 **
6162 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
6163 **
6164 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
6165 ** application wishes to abandon the backup operation, the application
6166 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
6167 ** ^The sqlite3_backup_finish() interfaces releases all
@@ -6006,11 +6180,12 @@
6180 **
6181 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
6182 ** is not a permanent error and does not affect the return value of
6183 ** sqlite3_backup_finish().
6184 **
6185 ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
6186 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
6187 **
6188 ** ^Each call to sqlite3_backup_step() sets two values inside
6189 ** the [sqlite3_backup] object: the number of pages still to be backed
6190 ** up and the total number of pages in the source database file.
6191 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
@@ -6391,10 +6566,97 @@
6566 ** each of these values.
6567 */
6568 #define SQLITE_CHECKPOINT_PASSIVE 0
6569 #define SQLITE_CHECKPOINT_FULL 1
6570 #define SQLITE_CHECKPOINT_RESTART 2
6571
6572 /*
6573 ** CAPI3REF: Virtual Table Interface Configuration
6574 **
6575 ** This function may be called by either the [xConnect] or [xCreate] method
6576 ** of a [virtual table] implementation to configure
6577 ** various facets of the virtual table interface.
6578 **
6579 ** If this interface is invoked outside the context of an xConnect or
6580 ** xCreate virtual table method then the behavior is undefined.
6581 **
6582 ** At present, there is only one option that may be configured using
6583 ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options
6584 ** may be added in the future.
6585 */
6586 SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
6587
6588 /*
6589 ** CAPI3REF: Virtual Table Configuration Options
6590 **
6591 ** These macros define the various options to the
6592 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
6593 ** can use to customize and optimize their behavior.
6594 **
6595 ** <dl>
6596 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
6597 ** <dd>Calls of the form
6598 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
6599 ** where X is an integer. If X is zero, then the [virtual table] whose
6600 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
6601 ** support constraints. In this configuration (which is the default) if
6602 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
6603 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
6604 ** specified as part of the users SQL statement, regardless of the actual
6605 ** ON CONFLICT mode specified.
6606 **
6607 ** If X is non-zero, then the virtual table implementation guarantees
6608 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
6609 ** any modifications to internal or persistent data structures have been made.
6610 ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
6611 ** is able to roll back a statement or database transaction, and abandon
6612 ** or continue processing the current SQL statement as appropriate.
6613 ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
6614 ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
6615 ** had been ABORT.
6616 **
6617 ** Virtual table implementations that are required to handle OR REPLACE
6618 ** must do so within the [xUpdate] method. If a call to the
6619 ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
6620 ** CONFLICT policy is REPLACE, the virtual table implementation should
6621 ** silently replace the appropriate rows within the xUpdate callback and
6622 ** return SQLITE_OK. Or, if this is not possible, it may return
6623 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
6624 ** constraint handling.
6625 ** </dl>
6626 */
6627 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
6628
6629 /*
6630 ** CAPI3REF: Determine The Virtual Table Conflict Policy
6631 **
6632 ** This function may only be called from within a call to the [xUpdate] method
6633 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
6634 ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
6635 ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
6636 ** of the SQL statement that triggered the call to the [xUpdate] method of the
6637 ** [virtual table].
6638 */
6639 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
6640
6641 /*
6642 ** CAPI3REF: Conflict resolution modes
6643 **
6644 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
6645 ** inform a [virtual table] implementation what the [ON CONFLICT] mode
6646 ** is for the SQL statement being evaluated.
6647 **
6648 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
6649 ** return value from the [sqlite3_set_authorizer()] callback and that
6650 ** [SQLITE_ABORT] is also a [result code].
6651 */
6652 #define SQLITE_ROLLBACK 1
6653 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
6654 #define SQLITE_FAIL 3
6655 /* #define SQLITE_ABORT 4 // Also an error code */
6656 #define SQLITE_REPLACE 5
6657
6658
6659
6660 /*
6661 ** Undo the hack that converts floating point types to integer for
6662 ** builds on processors without floating point support.
6663
+3 -3
--- src/timeline.c
+++ src/timeline.c
@@ -726,23 +726,23 @@
726726
** the event identified by rid.
727727
*/
728728
static void timeline_add_dividers(const char *zDate, int rid){
729729
char *zToDel = 0;
730730
if( zDate==0 ){
731
- zToDel = db_text(0,"SELECT datetime(mtime,'localtime') FROM event"
731
+ zToDel = db_text(0,"SELECT julianday(mtime,'localtime') FROM event"
732732
" WHERE objid=%d", rid);
733733
zDate = zToDel;
734734
if( zDate==0 ) zDate = "1";
735735
}
736736
db_multi_exec(
737737
"INSERT INTO timeline(rid,sortby,etype)"
738
- "VALUES(-1,julianday(%Q,'utc')-5.0e-6,'div')",
738
+ "VALUES(-1,julianday(%Q,'utc')-1.0e-5,'div')",
739739
zDate
740740
);
741741
db_multi_exec(
742742
"INSERT INTO timeline(rid,sortby,etype)"
743
- "VALUES(-2,julianday(%Q,'utc')+5.0e-6,'div')",
743
+ "VALUES(-2,julianday(%Q,'utc')+1.0e-5,'div')",
744744
zDate
745745
);
746746
fossil_free(zToDel);
747747
}
748748
749749
--- src/timeline.c
+++ src/timeline.c
@@ -726,23 +726,23 @@
726 ** the event identified by rid.
727 */
728 static void timeline_add_dividers(const char *zDate, int rid){
729 char *zToDel = 0;
730 if( zDate==0 ){
731 zToDel = db_text(0,"SELECT datetime(mtime,'localtime') FROM event"
732 " WHERE objid=%d", rid);
733 zDate = zToDel;
734 if( zDate==0 ) zDate = "1";
735 }
736 db_multi_exec(
737 "INSERT INTO timeline(rid,sortby,etype)"
738 "VALUES(-1,julianday(%Q,'utc')-5.0e-6,'div')",
739 zDate
740 );
741 db_multi_exec(
742 "INSERT INTO timeline(rid,sortby,etype)"
743 "VALUES(-2,julianday(%Q,'utc')+5.0e-6,'div')",
744 zDate
745 );
746 fossil_free(zToDel);
747 }
748
749
--- src/timeline.c
+++ src/timeline.c
@@ -726,23 +726,23 @@
726 ** the event identified by rid.
727 */
728 static void timeline_add_dividers(const char *zDate, int rid){
729 char *zToDel = 0;
730 if( zDate==0 ){
731 zToDel = db_text(0,"SELECT julianday(mtime,'localtime') FROM event"
732 " WHERE objid=%d", rid);
733 zDate = zToDel;
734 if( zDate==0 ) zDate = "1";
735 }
736 db_multi_exec(
737 "INSERT INTO timeline(rid,sortby,etype)"
738 "VALUES(-1,julianday(%Q,'utc')-1.0e-5,'div')",
739 zDate
740 );
741 db_multi_exec(
742 "INSERT INTO timeline(rid,sortby,etype)"
743 "VALUES(-2,julianday(%Q,'utc')+1.0e-5,'div')",
744 zDate
745 );
746 fossil_free(zToDel);
747 }
748
749
+3 -3
--- src/timeline.c
+++ src/timeline.c
@@ -726,23 +726,23 @@
726726
** the event identified by rid.
727727
*/
728728
static void timeline_add_dividers(const char *zDate, int rid){
729729
char *zToDel = 0;
730730
if( zDate==0 ){
731
- zToDel = db_text(0,"SELECT datetime(mtime,'localtime') FROM event"
731
+ zToDel = db_text(0,"SELECT julianday(mtime,'localtime') FROM event"
732732
" WHERE objid=%d", rid);
733733
zDate = zToDel;
734734
if( zDate==0 ) zDate = "1";
735735
}
736736
db_multi_exec(
737737
"INSERT INTO timeline(rid,sortby,etype)"
738
- "VALUES(-1,julianday(%Q,'utc')-5.0e-6,'div')",
738
+ "VALUES(-1,julianday(%Q,'utc')-1.0e-5,'div')",
739739
zDate
740740
);
741741
db_multi_exec(
742742
"INSERT INTO timeline(rid,sortby,etype)"
743
- "VALUES(-2,julianday(%Q,'utc')+5.0e-6,'div')",
743
+ "VALUES(-2,julianday(%Q,'utc')+1.0e-5,'div')",
744744
zDate
745745
);
746746
fossil_free(zToDel);
747747
}
748748
749749
--- src/timeline.c
+++ src/timeline.c
@@ -726,23 +726,23 @@
726 ** the event identified by rid.
727 */
728 static void timeline_add_dividers(const char *zDate, int rid){
729 char *zToDel = 0;
730 if( zDate==0 ){
731 zToDel = db_text(0,"SELECT datetime(mtime,'localtime') FROM event"
732 " WHERE objid=%d", rid);
733 zDate = zToDel;
734 if( zDate==0 ) zDate = "1";
735 }
736 db_multi_exec(
737 "INSERT INTO timeline(rid,sortby,etype)"
738 "VALUES(-1,julianday(%Q,'utc')-5.0e-6,'div')",
739 zDate
740 );
741 db_multi_exec(
742 "INSERT INTO timeline(rid,sortby,etype)"
743 "VALUES(-2,julianday(%Q,'utc')+5.0e-6,'div')",
744 zDate
745 );
746 fossil_free(zToDel);
747 }
748
749
--- src/timeline.c
+++ src/timeline.c
@@ -726,23 +726,23 @@
726 ** the event identified by rid.
727 */
728 static void timeline_add_dividers(const char *zDate, int rid){
729 char *zToDel = 0;
730 if( zDate==0 ){
731 zToDel = db_text(0,"SELECT julianday(mtime,'localtime') FROM event"
732 " WHERE objid=%d", rid);
733 zDate = zToDel;
734 if( zDate==0 ) zDate = "1";
735 }
736 db_multi_exec(
737 "INSERT INTO timeline(rid,sortby,etype)"
738 "VALUES(-1,julianday(%Q,'utc')-1.0e-5,'div')",
739 zDate
740 );
741 db_multi_exec(
742 "INSERT INTO timeline(rid,sortby,etype)"
743 "VALUES(-2,julianday(%Q,'utc')+1.0e-5,'div')",
744 zDate
745 );
746 fossil_free(zToDel);
747 }
748
749
--- www/fossil_logo_small.gif
+++ www/fossil_logo_small.gif
cannot compute difference between binary files
11
--- www/fossil_logo_small.gif
+++ www/fossil_logo_small.gif
0 annot compute difference between binary files
1
--- www/fossil_logo_small.gif
+++ www/fossil_logo_small.gif
0 annot compute difference between binary files
1
--- www/selfhost.wiki
+++ www/selfhost.wiki
@@ -58,8 +58,8 @@
5858
<blockquote><pre>
5959
/home/hwaci/bin/fossil sync -R /home/hwaci/fossil/fossil.fossil
6060
</pre></blockquote>
6161
6262
Server (2) is a
63
-<a href="http://www.linode.com/">Linode 512</a> located in Atlanta, GA
63
+<a href="http://www.linode.com/">Linode 512</a> located in Newark, NJ
6464
and set up just like the canonical server (1) with the addition of a
6565
cron job for synchronization as in server (3).
6666
--- www/selfhost.wiki
+++ www/selfhost.wiki
@@ -58,8 +58,8 @@
58 <blockquote><pre>
59 /home/hwaci/bin/fossil sync -R /home/hwaci/fossil/fossil.fossil
60 </pre></blockquote>
61
62 Server (2) is a
63 <a href="http://www.linode.com/">Linode 512</a> located in Atlanta, GA
64 and set up just like the canonical server (1) with the addition of a
65 cron job for synchronization as in server (3).
66
--- www/selfhost.wiki
+++ www/selfhost.wiki
@@ -58,8 +58,8 @@
58 <blockquote><pre>
59 /home/hwaci/bin/fossil sync -R /home/hwaci/fossil/fossil.fossil
60 </pre></blockquote>
61
62 Server (2) is a
63 <a href="http://www.linode.com/">Linode 512</a> located in Newark, NJ
64 and set up just like the canonical server (1) with the addition of a
65 cron job for synchronization as in server (3).
66

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button