Fossil SCM

Update SQLite to a version that includes automatic index support. When compiled with FOSSIL_DEBUG, issue warnings if any automatic index is ever used.

drh 2010-04-07 20:02 trunk
Commit b84917dbf84f94be426f03f7898bf83f777b4322
3 files changed +6 -3 +1027 -469 +56 -50
+6 -3
--- src/db.c
+++ src/db.c
@@ -283,18 +283,21 @@
283283
/*
284284
** Print warnings if a query is inefficient.
285285
*/
286286
static void db_stats(Stmt *pStmt){
287287
#ifdef FOSSIL_DEBUG
288
- int c1, c2;
288
+ int c1, c2, c3;
289289
const char *zSql = sqlite3_sql(pStmt->pStmt);
290290
if( zSql==0 ) return;
291291
c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
292
- c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
292
+ c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, 1);
293
+ c3 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
293294
if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
294295
fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
295
- }else if( c2 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
296
+ }else if( c2 ){
297
+ fossil_warning("%d automatic index rows in [%s]", c2, zSql);
298
+ }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
296299
fossil_warning("sort w/o index in [%s]", zSql);
297300
}
298301
pStmt->nStep = 0;
299302
#endif
300303
}
301304
--- src/db.c
+++ src/db.c
@@ -283,18 +283,21 @@
283 /*
284 ** Print warnings if a query is inefficient.
285 */
286 static void db_stats(Stmt *pStmt){
287 #ifdef FOSSIL_DEBUG
288 int c1, c2;
289 const char *zSql = sqlite3_sql(pStmt->pStmt);
290 if( zSql==0 ) return;
291 c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
292 c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
 
293 if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
294 fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
295 }else if( c2 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
 
 
296 fossil_warning("sort w/o index in [%s]", zSql);
297 }
298 pStmt->nStep = 0;
299 #endif
300 }
301
--- src/db.c
+++ src/db.c
@@ -283,18 +283,21 @@
283 /*
284 ** Print warnings if a query is inefficient.
285 */
286 static void db_stats(Stmt *pStmt){
287 #ifdef FOSSIL_DEBUG
288 int c1, c2, c3;
289 const char *zSql = sqlite3_sql(pStmt->pStmt);
290 if( zSql==0 ) return;
291 c1 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, 1);
292 c2 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, 1);
293 c3 = sqlite3_stmt_status(pStmt->pStmt, SQLITE_STMTSTATUS_SORT, 1);
294 if( c1>pStmt->nStep*4 && strstr(zSql,"/*scan*/")==0 ){
295 fossil_warning("%d scan steps for %d rows in [%s]", c1, pStmt->nStep, zSql);
296 }else if( c2 ){
297 fossil_warning("%d automatic index rows in [%s]", c2, zSql);
298 }else if( c3 && strstr(zSql,"/*sort*/")==0 && strstr(zSql,"/*scan*/")==0 ){
299 fossil_warning("sort w/o index in [%s]", zSql);
300 }
301 pStmt->nStep = 0;
302 #endif
303 }
304
+1027 -469
--- 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.6.23.1. By combining all the individual C code files into this
3
+** version 3.6.23. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a one 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% are more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -321,11 +321,11 @@
321321
** to generate appropriate macros for a wide range of compilers.
322322
**
323323
** The correct "ANSI" way to do this is to use the intptr_t type.
324324
** Unfortunately, that typedef is not available on all compilers, or
325325
** if it is available, it requires an #include of specific headers
326
-** that very from one machine to the next.
326
+** that vary from one machine to the next.
327327
**
328328
** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
329329
** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
330330
** So we have to define the macros in different ways depending on the
331331
** compiler.
@@ -626,13 +626,13 @@
626626
**
627627
** See also: [sqlite3_libversion()],
628628
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
629629
** [sqlite_version()] and [sqlite_source_id()].
630630
*/
631
-#define SQLITE_VERSION "3.6.23.1"
631
+#define SQLITE_VERSION "3.6.23"
632632
#define SQLITE_VERSION_NUMBER 3006023
633
-#define SQLITE_SOURCE_ID "2010-03-26 22:28:06 ex-b078b588d617e07886ad156e9f54ade6d823568e"
633
+#define SQLITE_SOURCE_ID "2010-04-07 19:32:00 1f40441204d9a912b1d6b67ff6ff9e17146c7abd"
634634
635635
/*
636636
** CAPI3REF: Run-Time Library Version Numbers
637637
** KEYWORDS: sqlite3_version, sqlite3_sourceid
638638
**
@@ -665,11 +665,10 @@
665665
SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
666666
SQLITE_API const char *sqlite3_libversion(void);
667667
SQLITE_API const char *sqlite3_sourceid(void);
668668
SQLITE_API int sqlite3_libversion_number(void);
669669
670
-#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
671670
/*
672671
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
673672
**
674673
** ^The sqlite3_compileoption_used() function returns 0 or 1
675674
** indicating whether the specified option was defined at
@@ -688,13 +687,14 @@
688687
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
689688
**
690689
** See also: SQL functions [sqlite_compileoption_used()] and
691690
** [sqlite_compileoption_get()] and the [compile_options pragma].
692691
*/
692
+#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
693693
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
694694
SQLITE_API const char *sqlite3_compileoption_get(int N);
695
-#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
695
+#endif
696696
697697
/*
698698
** CAPI3REF: Test To See If The Library Is Threadsafe
699699
**
700700
** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -1492,15 +1492,14 @@
14921492
**
14931493
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
14941494
** ^If the option is unknown or SQLite is unable to set the option
14951495
** then this routine returns a non-zero [error code].
14961496
*/
1497
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
1497
+SQLITE_API int sqlite3_config(int, ...);
14981498
14991499
/*
15001500
** CAPI3REF: Configure database connections
1501
-** EXPERIMENTAL
15021501
**
15031502
** The sqlite3_db_config() interface is used to make configuration
15041503
** changes to a [database connection]. The interface is similar to
15051504
** [sqlite3_config()] except that the changes apply to a single
15061505
** [database connection] (specified in the first argument). The
@@ -1516,15 +1515,14 @@
15161515
** Additional arguments depend on the verb.
15171516
**
15181517
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
15191518
** the call is considered successful.
15201519
*/
1521
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
1520
+SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
15221521
15231522
/*
15241523
** CAPI3REF: Memory Allocation Routines
1525
-** EXPERIMENTAL
15261524
**
15271525
** An instance of this object defines the interface between SQLite
15281526
** and low-level memory allocation routines.
15291527
**
15301528
** This object is used in only one place in the SQLite interface.
@@ -1602,11 +1600,10 @@
16021600
void *pAppData; /* Argument to xInit() and xShutdown() */
16031601
};
16041602
16051603
/*
16061604
** CAPI3REF: Configuration Options
1607
-** EXPERIMENTAL
16081605
**
16091606
** These constants are the available integer configuration options that
16101607
** can be passed as the first argument to the [sqlite3_config()] interface.
16111608
**
16121609
** New configuration options may be added in future releases of SQLite.
@@ -1788,10 +1785,28 @@
17881785
** <dt>SQLITE_CONFIG_GETPCACHE</dt>
17891786
** <dd> ^(This option takes a single argument which is a pointer to an
17901787
** [sqlite3_pcache_methods] object. SQLite copies of the current
17911788
** page cache implementation into that object.)^ </dd>
17921789
**
1790
+** <dt>SQLITE_CONFIG_LOG</dt>
1791
+** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1792
+** function with a call signature of void(*)(void*,int,const char*),
1793
+** and a pointer to void. ^If the function pointer is not NULL, it is
1794
+** invoked by [sqlite3_log()] to process each logging event. ^If the
1795
+** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1796
+** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1797
+** passed through as the first parameter to the application-defined logger
1798
+** function whenever that function is invoked. ^The second parameter to
1799
+** the logger function is a copy of the first parameter to the corresponding
1800
+** [sqlite3_log()] call and is intended to be a [result code] or an
1801
+** [extended result code]. ^The third parameter passed to the logger is
1802
+** log message after formatting via [sqlite3_snprintf()].
1803
+** The SQLite logging interface is not reentrant; the logger function
1804
+** supplied by the application must not invoke any SQLite interface.
1805
+** In a multi-threaded application, the application-defined logger
1806
+** function must be threadsafe. </dd>
1807
+**
17931808
** </dl>
17941809
*/
17951810
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17961811
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
17971812
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1808,12 +1823,11 @@
18081823
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
18091824
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
18101825
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
18111826
18121827
/*
1813
-** CAPI3REF: Configuration Options
1814
-** EXPERIMENTAL
1828
+** CAPI3REF: Database Connection Configuration Options
18151829
**
18161830
** These constants are the available integer configuration options that
18171831
** can be passed as the second argument to the [sqlite3_db_config()] interface.
18181832
**
18191833
** New configuration options may be added in future releases of SQLite.
@@ -2585,11 +2599,10 @@
25852599
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
25862600
#define SQLITE_COPY 0 /* No longer used */
25872601
25882602
/*
25892603
** CAPI3REF: Tracing And Profiling Functions
2590
-** EXPERIMENTAL
25912604
**
25922605
** These routines register callback functions that can be used for
25932606
** tracing and profiling the execution of SQL statements.
25942607
**
25952608
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2603,11 +2616,11 @@
26032616
** ^The callback function registered by sqlite3_profile() is invoked
26042617
** as each SQL statement finishes. ^The profile callback contains
26052618
** the original statement text and an estimate of wall-clock time
26062619
** of how long that statement took to run.
26072620
*/
2608
-SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2621
+SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
26092622
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
26102623
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
26112624
26122625
/*
26132626
** CAPI3REF: Query Progress Callbacks
@@ -4208,11 +4221,11 @@
42084221
sqlite3*,
42094222
void*,
42104223
void(*)(void*,sqlite3*,int eTextRep,const void*)
42114224
);
42124225
4213
-#if SQLITE_HAS_CODEC
4226
+#ifdef SQLITE_HAS_CODEC
42144227
/*
42154228
** Specify the key for an encrypted database. This routine should be
42164229
** called right after sqlite3_open().
42174230
**
42184231
** The code to implement this API is not available in the public release
@@ -4678,12 +4691,10 @@
46784691
** ^This function disables automatic extensions in all threads.
46794692
*/
46804693
SQLITE_API void sqlite3_reset_auto_extension(void);
46814694
46824695
/*
4683
-****** EXPERIMENTAL - subject to change without notice **************
4684
-**
46854696
** The interface to the virtual-table mechanism is currently considered
46864697
** to be experimental. The interface might change in incompatible ways.
46874698
** If this is a problem for you, do not use the interface at this time.
46884699
**
46894700
** When the virtual-table mechanism stabilizes, we will declare the
@@ -4699,11 +4710,10 @@
46994710
typedef struct sqlite3_module sqlite3_module;
47004711
47014712
/*
47024713
** CAPI3REF: Virtual Table Object
47034714
** KEYWORDS: sqlite3_module {virtual table module}
4704
-** EXPERIMENTAL
47054715
**
47064716
** This structure, sometimes called a a "virtual table module",
47074717
** defines the implementation of a [virtual tables].
47084718
** This structure consists mostly of methods for the module.
47094719
**
@@ -4746,11 +4756,10 @@
47464756
};
47474757
47484758
/*
47494759
** CAPI3REF: Virtual Table Indexing Information
47504760
** KEYWORDS: sqlite3_index_info
4751
-** EXPERIMENTAL
47524761
**
47534762
** The sqlite3_index_info structure and its substructures is used to
47544763
** pass information into and receive the reply from the [xBestIndex]
47554764
** method of a [virtual table module]. The fields under **Inputs** are the
47564765
** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4828,11 +4837,10 @@
48284837
#define SQLITE_INDEX_CONSTRAINT_GE 32
48294838
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
48304839
48314840
/*
48324841
** CAPI3REF: Register A Virtual Table Implementation
4833
-** EXPERIMENTAL
48344842
**
48354843
** ^These routines are used to register a new [virtual table module] name.
48364844
** ^Module names must be registered before
48374845
** creating a new [virtual table] using the module and before using a
48384846
** preexisting [virtual table] for the module.
@@ -4850,17 +4858,17 @@
48504858
** invoke the destructor function (if it is not NULL) when SQLite
48514859
** no longer needs the pClientData pointer. ^The sqlite3_create_module()
48524860
** interface is equivalent to sqlite3_create_module_v2() with a NULL
48534861
** destructor.
48544862
*/
4855
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4863
+SQLITE_API int sqlite3_create_module(
48564864
sqlite3 *db, /* SQLite connection to register module with */
48574865
const char *zName, /* Name of the module */
48584866
const sqlite3_module *p, /* Methods for the module */
48594867
void *pClientData /* Client data for xCreate/xConnect */
48604868
);
4861
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4869
+SQLITE_API int sqlite3_create_module_v2(
48624870
sqlite3 *db, /* SQLite connection to register module with */
48634871
const char *zName, /* Name of the module */
48644872
const sqlite3_module *p, /* Methods for the module */
48654873
void *pClientData, /* Client data for xCreate/xConnect */
48664874
void(*xDestroy)(void*) /* Module destructor function */
@@ -4867,11 +4875,10 @@
48674875
);
48684876
48694877
/*
48704878
** CAPI3REF: Virtual Table Instance Object
48714879
** KEYWORDS: sqlite3_vtab
4872
-** EXPERIMENTAL
48734880
**
48744881
** Every [virtual table module] implementation uses a subclass
48754882
** of this object to describe a particular instance
48764883
** of the [virtual table]. Each subclass will
48774884
** be tailored to the specific needs of the module implementation.
@@ -4893,11 +4900,10 @@
48934900
};
48944901
48954902
/*
48964903
** CAPI3REF: Virtual Table Cursor Object
48974904
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4898
-** EXPERIMENTAL
48994905
**
49004906
** Every [virtual table module] implementation uses a subclass of the
49014907
** following structure to describe cursors that point into the
49024908
** [virtual table] and are used
49034909
** to loop through the virtual table. Cursors are created using the
@@ -4915,22 +4921,20 @@
49154921
/* Virtual table implementations will typically add additional fields */
49164922
};
49174923
49184924
/*
49194925
** CAPI3REF: Declare The Schema Of A Virtual Table
4920
-** EXPERIMENTAL
49214926
**
49224927
** ^The [xCreate] and [xConnect] methods of a
49234928
** [virtual table module] call this interface
49244929
** to declare the format (the names and datatypes of the columns) of
49254930
** the virtual tables they implement.
49264931
*/
4927
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4932
+SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
49284933
49294934
/*
49304935
** CAPI3REF: Overload A Function For A Virtual Table
4931
-** EXPERIMENTAL
49324936
**
49334937
** ^(Virtual tables can provide alternative implementations of functions
49344938
** using the [xFindFunction] method of the [virtual table module].
49354939
** But global versions of those functions
49364940
** must exist in order to be overloaded.)^
@@ -4941,22 +4945,20 @@
49414945
** of the new function always causes an exception to be thrown. So
49424946
** the new function is not good for anything by itself. Its only
49434947
** purpose is to be a placeholder function that can be overloaded
49444948
** by a [virtual table].
49454949
*/
4946
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4950
+SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
49474951
49484952
/*
49494953
** The interface to the virtual-table mechanism defined above (back up
49504954
** to a comment remarkably similar to this one) is currently considered
49514955
** to be experimental. The interface might change in incompatible ways.
49524956
** If this is a problem for you, do not use the interface at this time.
49534957
**
49544958
** When the virtual-table mechanism stabilizes, we will declare the
49554959
** interface fixed, support it indefinitely, and remove this comment.
4956
-**
4957
-****** EXPERIMENTAL - subject to change without notice **************
49584960
*/
49594961
49604962
/*
49614963
** CAPI3REF: A Handle To An Open BLOB
49624964
** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -5295,11 +5297,10 @@
52955297
SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
52965298
SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
52975299
52985300
/*
52995301
** CAPI3REF: Mutex Methods Object
5300
-** EXPERIMENTAL
53015302
**
53025303
** An instance of this structure defines the low-level routines
53035304
** used to allocate and use mutexes.
53045305
**
53055306
** Usually, the default mutex implementations provided by SQLite are
@@ -5512,11 +5513,10 @@
55125513
#define SQLITE_TESTCTRL_ISKEYWORD 16
55135514
#define SQLITE_TESTCTRL_LAST 16
55145515
55155516
/*
55165517
** CAPI3REF: SQLite Runtime Status
5517
-** EXPERIMENTAL
55185518
**
55195519
** ^This interface is used to retrieve runtime status information
55205520
** about the preformance of SQLite, and optionally to reset various
55215521
** highwater marks. ^The first argument is an integer code for
55225522
** the specific parameter to measure. ^(Recognized integer codes
@@ -5540,16 +5540,15 @@
55405540
** and it is possible that another thread might change the parameter
55415541
** in between the times when *pCurrent and *pHighwater are written.
55425542
**
55435543
** See also: [sqlite3_db_status()]
55445544
*/
5545
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5545
+SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
55465546
55475547
55485548
/*
55495549
** CAPI3REF: Status Parameters
5550
-** EXPERIMENTAL
55515550
**
55525551
** These integer constants designate various run-time status parameters
55535552
** that can be returned by [sqlite3_status()].
55545553
**
55555554
** <dl>
@@ -5632,31 +5631,31 @@
56325631
#define SQLITE_STATUS_PAGECACHE_SIZE 7
56335632
#define SQLITE_STATUS_SCRATCH_SIZE 8
56345633
56355634
/*
56365635
** CAPI3REF: Database Connection Status
5637
-** EXPERIMENTAL
56385636
**
56395637
** ^This interface is used to retrieve runtime status information
56405638
** about a single [database connection]. ^The first argument is the
56415639
** database connection object to be interrogated. ^The second argument
5642
-** is the parameter to interrogate. ^Currently, the only allowed value
5643
-** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5644
-** Additional options will likely appear in future releases of SQLite.
5640
+** is an integer constant, taken from the set of
5641
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5642
+** determiness the parameter to interrogate. The set of
5643
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5644
+** to grow in future releases of SQLite.
56455645
**
56465646
** ^The current value of the requested parameter is written into *pCur
56475647
** and the highest instantaneous value is written into *pHiwtr. ^If
56485648
** the resetFlg is true, then the highest instantaneous value is
56495649
** reset back down to the current value.
56505650
**
56515651
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
56525652
*/
5653
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5653
+SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
56545654
56555655
/*
56565656
** CAPI3REF: Status Parameters for database connections
5657
-** EXPERIMENTAL
56585657
**
56595658
** These constants are the available integer "verbs" that can be passed as
56605659
** the second argument to the [sqlite3_db_status()] interface.
56615660
**
56625661
** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5667,18 +5666,25 @@
56675666
**
56685667
** <dl>
56695668
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
56705669
** <dd>This parameter returns the number of lookaside memory slots currently
56715670
** checked out.</dd>)^
5671
+**
5672
+** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5673
+** <dd>^This parameter returns the approximate number of of bytes of heap
5674
+** memory used by all pager caches associated with the database connection.
5675
+** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5676
+** checked out.</dd>)^
56725677
** </dl>
56735678
*/
56745679
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5680
+#define SQLITE_DBSTATUS_CACHE_USED 1
5681
+#define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
56755682
56765683
56775684
/*
56785685
** CAPI3REF: Prepared Statement Status
5679
-** EXPERIMENTAL
56805686
**
56815687
** ^(Each prepared statement maintains various
56825688
** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
56835689
** of times it has performed specific operations.)^ These counters can
56845690
** be used to monitor the performance characteristics of the prepared
@@ -5696,15 +5702,14 @@
56965702
** ^If the resetFlg is true, then the counter is reset to zero after this
56975703
** interface call returns.
56985704
**
56995705
** See also: [sqlite3_status()] and [sqlite3_db_status()].
57005706
*/
5701
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5707
+SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
57025708
57035709
/*
57045710
** CAPI3REF: Status Parameters for prepared statements
5705
-** EXPERIMENTAL
57065711
**
57075712
** These preprocessor macros define integer codes that name counter
57085713
** values associated with the [sqlite3_stmt_status()] interface.
57095714
** The meanings of the various counters are as follows:
57105715
**
@@ -5718,18 +5723,25 @@
57185723
** <dt>SQLITE_STMTSTATUS_SORT</dt>
57195724
** <dd>^This is the number of sort operations that have occurred.
57205725
** A non-zero value in this counter may indicate an opportunity to
57215726
** improvement performance through careful use of indices.</dd>
57225727
**
5728
+** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5729
+** <dd>^This is the number of rows inserted into transient indices that
5730
+** were created automatically in order to help joins run faster.
5731
+** A non-zero value in this counter may indicate an opportunity to
5732
+** improvement performance by adding permanent indices that do not
5733
+** need to be reinitialized each time the statement is run.</dd>
5734
+**
57235735
** </dl>
57245736
*/
57255737
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
57265738
#define SQLITE_STMTSTATUS_SORT 2
5739
+#define SQLITE_STMTSTATUS_AUTOINDEX 3
57275740
57285741
/*
57295742
** CAPI3REF: Custom Page Cache Object
5730
-** EXPERIMENTAL
57315743
**
57325744
** The sqlite3_pcache type is opaque. It is implemented by
57335745
** the pluggable module. The SQLite core has no knowledge of
57345746
** its size or internal structure and never deals with the
57355747
** sqlite3_pcache object except by holding and passing pointers
@@ -5740,11 +5752,10 @@
57405752
typedef struct sqlite3_pcache sqlite3_pcache;
57415753
57425754
/*
57435755
** CAPI3REF: Application Defined Page Cache.
57445756
** KEYWORDS: {page cache}
5745
-** EXPERIMENTAL
57465757
**
57475758
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
57485759
** register an alternative page cache implementation by passing in an
57495760
** instance of the sqlite3_pcache_methods structure.)^ The majority of the
57505761
** heap memory used by SQLite is used by the page cache to cache data read
@@ -5882,11 +5893,10 @@
58825893
void (*xDestroy)(sqlite3_pcache*);
58835894
};
58845895
58855896
/*
58865897
** CAPI3REF: Online Backup Object
5887
-** EXPERIMENTAL
58885898
**
58895899
** The sqlite3_backup object records state information about an ongoing
58905900
** online backup operation. ^The sqlite3_backup object is created by
58915901
** a call to [sqlite3_backup_init()] and is destroyed by a call to
58925902
** [sqlite3_backup_finish()].
@@ -5895,11 +5905,10 @@
58955905
*/
58965906
typedef struct sqlite3_backup sqlite3_backup;
58975907
58985908
/*
58995909
** CAPI3REF: Online Backup API.
5900
-** EXPERIMENTAL
59015910
**
59025911
** The backup API copies the content of one database into another.
59035912
** It is useful either for creating backups of databases or
59045913
** for copying in-memory databases to or from persistent files.
59055914
**
@@ -6083,11 +6092,10 @@
60836092
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
60846093
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
60856094
60866095
/*
60876096
** CAPI3REF: Unlock Notification
6088
-** EXPERIMENTAL
60896097
**
60906098
** ^When running in shared-cache mode, a database operation may fail with
60916099
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
60926100
** individual tables within the shared-cache cannot be obtained. See
60936101
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -6205,11 +6213,10 @@
62056213
);
62066214
62076215
62086216
/*
62096217
** CAPI3REF: String Comparison
6210
-** EXPERIMENTAL
62116218
**
62126219
** ^The [sqlite3_strnicmp()] API allows applications and extensions to
62136220
** compare the contents of two buffers containing UTF-8 strings in a
62146221
** case-indendent fashion, using the same definition of case independence
62156222
** that SQLite uses internally when comparing identifiers.
@@ -6216,16 +6223,15 @@
62166223
*/
62176224
SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
62186225
62196226
/*
62206227
** CAPI3REF: Error Logging Interface
6221
-** EXPERIMENTAL
62226228
**
62236229
** ^The [sqlite3_log()] interface writes a message into the error log
62246230
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
62256231
** ^If logging is enabled, the zFormat string and subsequent arguments are
6226
-** passed through to [sqlite3_vmprintf()] to generate the final output string.
6232
+** used with [sqlite3_snprintf()] to generate the final output string.
62276233
**
62286234
** The sqlite3_log() interface is intended for use by extensions such as
62296235
** virtual tables, collating functions, and SQL functions. While there is
62306236
** nothing to prevent an application from calling sqlite3_log(), doing so
62316237
** is considered bad form.
@@ -6529,10 +6535,11 @@
65296535
** If compiling for a processor that lacks floating point support,
65306536
** substitute integer for floating-point
65316537
*/
65326538
#ifdef SQLITE_OMIT_FLOATING_POINT
65336539
# define double sqlite_int64
6540
+# define float sqlite_int64
65346541
# define LONGDOUBLE_TYPE sqlite_int64
65356542
# ifndef SQLITE_BIG_DBL
65366543
# define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
65376544
# endif
65386545
# define SQLITE_OMIT_DATETIME_FUNCS 1
@@ -6940,10 +6947,11 @@
69406947
SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
69416948
SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
69426949
SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
69436950
SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
69446951
SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
6952
+SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
69456953
SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
69466954
SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
69476955
SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
69486956
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
69496957
SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
@@ -7334,85 +7342,85 @@
73347342
#define OP_ReadCookie 35
73357343
#define OP_SetCookie 36
73367344
#define OP_VerifyCookie 37
73377345
#define OP_OpenRead 38
73387346
#define OP_OpenWrite 39
7339
-#define OP_OpenEphemeral 40
7340
-#define OP_OpenPseudo 41
7341
-#define OP_Close 42
7342
-#define OP_SeekLt 43
7343
-#define OP_SeekLe 44
7344
-#define OP_SeekGe 45
7345
-#define OP_SeekGt 46
7346
-#define OP_Seek 47
7347
-#define OP_NotFound 48
7348
-#define OP_Found 49
7349
-#define OP_IsUnique 50
7350
-#define OP_NotExists 51
7351
-#define OP_Sequence 52
7352
-#define OP_NewRowid 53
7353
-#define OP_Insert 54
7354
-#define OP_InsertInt 55
7355
-#define OP_Delete 56
7356
-#define OP_ResetCount 57
7357
-#define OP_RowKey 58
7358
-#define OP_RowData 59
7359
-#define OP_Rowid 60
7360
-#define OP_NullRow 61
7361
-#define OP_Last 62
7362
-#define OP_Sort 63
7363
-#define OP_Rewind 64
7364
-#define OP_Prev 65
7365
-#define OP_Next 66
7366
-#define OP_IdxInsert 67
7367
-#define OP_IdxDelete 70
7368
-#define OP_IdxRowid 71
7369
-#define OP_IdxLT 72
7370
-#define OP_IdxGE 81
7371
-#define OP_Destroy 92
7372
-#define OP_Clear 95
7373
-#define OP_CreateIndex 96
7374
-#define OP_CreateTable 97
7375
-#define OP_ParseSchema 98
7376
-#define OP_LoadAnalysis 99
7377
-#define OP_DropTable 100
7378
-#define OP_DropIndex 101
7379
-#define OP_DropTrigger 102
7380
-#define OP_IntegrityCk 103
7381
-#define OP_RowSetAdd 104
7382
-#define OP_RowSetRead 105
7383
-#define OP_RowSetTest 106
7384
-#define OP_Program 107
7385
-#define OP_Param 108
7386
-#define OP_FkCounter 109
7387
-#define OP_FkIfZero 110
7388
-#define OP_MemMax 111
7389
-#define OP_IfPos 112
7390
-#define OP_IfNeg 113
7391
-#define OP_IfZero 114
7392
-#define OP_AggStep 115
7393
-#define OP_AggFinal 116
7394
-#define OP_Vacuum 117
7395
-#define OP_IncrVacuum 118
7396
-#define OP_Expire 119
7397
-#define OP_TableLock 120
7398
-#define OP_VBegin 121
7399
-#define OP_VCreate 122
7400
-#define OP_VDestroy 123
7401
-#define OP_VOpen 124
7402
-#define OP_VFilter 125
7403
-#define OP_VColumn 126
7404
-#define OP_VNext 127
7405
-#define OP_VRename 128
7406
-#define OP_VUpdate 129
7407
-#define OP_Pagecount 131
7408
-#define OP_Trace 132
7409
-#define OP_Noop 133
7410
-#define OP_Explain 134
7411
-
7412
-/* The following opcode values are never used */
7413
-#define OP_NotUsed_135 135
7347
+#define OP_OpenAutoindex 40
7348
+#define OP_OpenEphemeral 41
7349
+#define OP_OpenPseudo 42
7350
+#define OP_Close 43
7351
+#define OP_SeekLt 44
7352
+#define OP_SeekLe 45
7353
+#define OP_SeekGe 46
7354
+#define OP_SeekGt 47
7355
+#define OP_Seek 48
7356
+#define OP_NotFound 49
7357
+#define OP_Found 50
7358
+#define OP_IsUnique 51
7359
+#define OP_NotExists 52
7360
+#define OP_Sequence 53
7361
+#define OP_NewRowid 54
7362
+#define OP_Insert 55
7363
+#define OP_InsertInt 56
7364
+#define OP_Delete 57
7365
+#define OP_ResetCount 58
7366
+#define OP_RowKey 59
7367
+#define OP_RowData 60
7368
+#define OP_Rowid 61
7369
+#define OP_NullRow 62
7370
+#define OP_Last 63
7371
+#define OP_Sort 64
7372
+#define OP_Rewind 65
7373
+#define OP_Prev 66
7374
+#define OP_Next 67
7375
+#define OP_IdxInsert 70
7376
+#define OP_IdxDelete 71
7377
+#define OP_IdxRowid 72
7378
+#define OP_IdxLT 81
7379
+#define OP_IdxGE 92
7380
+#define OP_Destroy 95
7381
+#define OP_Clear 96
7382
+#define OP_CreateIndex 97
7383
+#define OP_CreateTable 98
7384
+#define OP_ParseSchema 99
7385
+#define OP_LoadAnalysis 100
7386
+#define OP_DropTable 101
7387
+#define OP_DropIndex 102
7388
+#define OP_DropTrigger 103
7389
+#define OP_IntegrityCk 104
7390
+#define OP_RowSetAdd 105
7391
+#define OP_RowSetRead 106
7392
+#define OP_RowSetTest 107
7393
+#define OP_Program 108
7394
+#define OP_Param 109
7395
+#define OP_FkCounter 110
7396
+#define OP_FkIfZero 111
7397
+#define OP_MemMax 112
7398
+#define OP_IfPos 113
7399
+#define OP_IfNeg 114
7400
+#define OP_IfZero 115
7401
+#define OP_AggStep 116
7402
+#define OP_AggFinal 117
7403
+#define OP_Vacuum 118
7404
+#define OP_IncrVacuum 119
7405
+#define OP_Expire 120
7406
+#define OP_TableLock 121
7407
+#define OP_VBegin 122
7408
+#define OP_VCreate 123
7409
+#define OP_VDestroy 124
7410
+#define OP_VOpen 125
7411
+#define OP_VFilter 126
7412
+#define OP_VColumn 127
7413
+#define OP_VNext 128
7414
+#define OP_VRename 129
7415
+#define OP_VUpdate 131
7416
+#define OP_Pagecount 132
7417
+#define OP_Trace 133
7418
+#define OP_Noop 134
7419
+#define OP_Explain 135
7420
+
7421
+/* The following opcode values are never used */
74147422
#define OP_NotUsed_136 136
74157423
#define OP_NotUsed_137 137
74167424
#define OP_NotUsed_138 138
74177425
#define OP_NotUsed_139 139
74187426
#define OP_NotUsed_140 140
@@ -7433,22 +7441,22 @@
74337441
/* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\
74347442
/* 8 */ 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x24,\
74357443
/* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
74367444
/* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
74377445
/* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\
7438
-/* 40 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
7439
-/* 48 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x00,\
7440
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
7441
-/* 64 */ 0x01, 0x01, 0x01, 0x08, 0x4c, 0x4c, 0x00, 0x02,\
7442
-/* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
7446
+/* 40 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\
7447
+/* 48 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00,\
7448
+/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
7449
+/* 64 */ 0x01, 0x01, 0x01, 0x01, 0x4c, 0x4c, 0x08, 0x00,\
7450
+/* 72 */ 0x02, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
74437451
/* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
7444
-/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x02, 0x24, 0x02, 0x00,\
7445
-/* 96 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
7446
-/* 104 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
7447
-/* 112 */ 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00,\
7448
-/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,\
7449
-/* 128 */ 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
7452
+/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x02,\
7453
+/* 96 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
7454
+/* 104 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\
7455
+/* 112 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01,\
7456
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,\
7457
+/* 128 */ 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,\
74507458
/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
74517459
/* 144 */ 0x04, 0x04,}
74527460
74537461
/************** End of opcodes.h *********************************************/
74547462
/************** Continuing where we left off in vdbe.h ***********************/
@@ -7658,10 +7666,11 @@
76587666
SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
76597667
76607668
/* Functions used to query pager state and configuration. */
76617669
SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
76627670
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
7671
+SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
76637672
SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
76647673
SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
76657674
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
76667675
SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
76677676
SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
@@ -8478,10 +8487,11 @@
84788487
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
84798488
#define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
84808489
#define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
84818490
#define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
84828491
#define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
8492
+#define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
84838493
84848494
/*
84858495
** Bits of the sqlite3.flags field that are used by the
84868496
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
84878497
** These must be the low-order bits of the flags field.
@@ -9340,10 +9350,13 @@
93409350
**
93419351
** The jointype starts out showing the join type between the current table
93429352
** and the next table on the list. The parser builds the list this way.
93439353
** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
93449354
** jointype expresses the join between the table and the previous table.
9355
+**
9356
+** In the colUsed field, the high-order bit (bit 63) is set if the table
9357
+** contains more than 63 columns and the 64-th or later column is used.
93459358
*/
93469359
struct SrcList {
93479360
i16 nSrc; /* Number of tables or subqueries in the FROM clause */
93489361
i16 nAlloc; /* Number of entries allocated in a[] below */
93499362
struct SrcList_item {
@@ -9451,11 +9464,11 @@
94519464
#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
94529465
#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
94539466
#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
94549467
#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
94559468
#define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
9456
-#define WHERE_OMIT_OPEN 0x0010 /* Table cursor are already open */
9469
+#define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
94579470
#define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
94589471
#define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
94599472
#define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
94609473
94619474
/*
@@ -9474,10 +9487,11 @@
94749487
int iTop; /* The very beginning of the WHERE loop */
94759488
int iContinue; /* Jump here to continue with next record */
94769489
int iBreak; /* Jump here to break out of the loop */
94779490
int nLevel; /* Number of nested loop */
94789491
struct WhereClause *pWC; /* Decomposition of the WHERE clause */
9492
+ double savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
94799493
WhereLevel a[1]; /* Information about each nest loop in WHERE */
94809494
};
94819495
94829496
/*
94839497
** A NameContext defines a context in which to resolve table and column
@@ -9715,10 +9729,11 @@
97159729
u32 oldmask; /* Mask of old.* columns referenced */
97169730
u32 newmask; /* Mask of new.* columns referenced */
97179731
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
97189732
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
97199733
u8 disableTriggers; /* True to disable triggers */
9734
+ double nQueryLoop; /* Estimated number of iterations of a query */
97209735
97219736
/* Above is constant between recursions. Below is reset before and after
97229737
** each recursion */
97239738
97249739
int nVar; /* Number of '?' variables seen in the SQL so far */
@@ -10656,11 +10671,50 @@
1065610671
#else
1065710672
# define IOTRACE(A)
1065810673
# define sqlite3VdbeIOTraceSql(X)
1065910674
#endif
1066010675
10676
+/*
10677
+** These routines are available for the mem2.c debugging memory allocator
10678
+** only. They are used to verify that different "types" of memory
10679
+** allocations are properly tracked by the system.
10680
+**
10681
+** sqlite3MemdebugSetType() sets the "type" of an allocation to one of
10682
+** the MEMTYPE_* macros defined below. The type must be a bitmask with
10683
+** a single bit set.
10684
+**
10685
+** sqlite3MemdebugHasType() returns true if any of the bits in its second
10686
+** argument match the type set by the previous sqlite3MemdebugSetType().
10687
+** sqlite3MemdebugHasType() is intended for use inside assert() statements.
10688
+** For example:
10689
+**
10690
+** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
10691
+**
10692
+** Perhaps the most important point is the difference between MEMTYPE_HEAP
10693
+** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have
10694
+** been allocated by lookaside, except the allocation was too large or
10695
+** lookaside was already full. It is important to verify that allocations
10696
+** that might have been satisfied by lookaside are not passed back to
10697
+** non-lookaside free() routines. Asserts such as the example above are
10698
+** placed on the non-lookaside free() routines to verify this constraint.
10699
+**
10700
+** All of this is no-op for a production build. It only comes into
10701
+** play when the SQLITE_MEMDEBUG compile-time option is used.
10702
+*/
10703
+#ifdef SQLITE_MEMDEBUG
10704
+SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
10705
+SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
10706
+#else
10707
+# define sqlite3MemdebugSetType(X,Y) /* no-op */
10708
+# define sqlite3MemdebugHasType(X,Y) 1
1066110709
#endif
10710
+#define MEMTYPE_HEAP 0x01 /* General heap allocations */
10711
+#define MEMTYPE_DB 0x02 /* Associated with a database connection */
10712
+#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10713
+#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
10714
+
10715
+#endif /* _SQLITEINT_H_ */
1066210716
1066310717
/************** End of sqliteInt.h *******************************************/
1066410718
/************** Begin file global.c ******************************************/
1066510719
/*
1066610720
** 2008 June 13
@@ -11038,10 +11092,13 @@
1103811092
#ifdef SQLITE_OMIT_AUTOINCREMENT
1103911093
"OMIT_AUTOINCREMENT",
1104011094
#endif
1104111095
#ifdef SQLITE_OMIT_AUTOINIT
1104211096
"OMIT_AUTOINIT",
11097
+#endif
11098
+#ifdef SQLITE_OMIT_AUTOMATIC_INDEX
11099
+ "OMIT_AUTOMATIC_INDEX",
1104311100
#endif
1104411101
#ifdef SQLITE_OMIT_AUTOVACUUM
1104511102
"OMIT_AUTOVACUUM",
1104611103
#endif
1104711104
#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
@@ -11367,10 +11424,30 @@
1136711424
if( resetFlag ){
1136811425
db->lookaside.mxOut = db->lookaside.nOut;
1136911426
}
1137011427
break;
1137111428
}
11429
+
11430
+ /*
11431
+ ** Return an approximation for the amount of memory currently used
11432
+ ** by all pagers associated with the given database connection. The
11433
+ ** highwater mark is meaningless and is returned as zero.
11434
+ */
11435
+ case SQLITE_DBSTATUS_CACHE_USED: {
11436
+ int totalUsed = 0;
11437
+ int i;
11438
+ for(i=0; i<db->nDb; i++){
11439
+ Btree *pBt = db->aDb[i].pBt;
11440
+ if( pBt ){
11441
+ Pager *pPager = sqlite3BtreePager(pBt);
11442
+ totalUsed += sqlite3PagerMemUsed(pPager);
11443
+ }
11444
+ }
11445
+ *pCurrent = totalUsed;
11446
+ *pHighwater = 0;
11447
+ break;
11448
+ }
1137211449
default: {
1137311450
return SQLITE_ERROR;
1137411451
}
1137511452
}
1137611453
return SQLITE_OK;
@@ -13140,11 +13217,12 @@
1314013217
struct MemBlockHdr {
1314113218
i64 iSize; /* Size of this allocation */
1314213219
struct MemBlockHdr *pNext, *pPrev; /* Linked list of all unfreed memory */
1314313220
char nBacktrace; /* Number of backtraces on this alloc */
1314413221
char nBacktraceSlots; /* Available backtrace slots */
13145
- short nTitle; /* Bytes of title; includes '\0' */
13222
+ u8 nTitle; /* Bytes of title; includes '\0' */
13223
+ u8 eType; /* Allocation type code */
1314613224
int iForeGuard; /* Guard word for sanity */
1314713225
};
1314813226
1314913227
/*
1315013228
** Guard words
@@ -13348,10 +13426,11 @@
1334813426
}else{
1334913427
mem.pFirst = pHdr;
1335013428
}
1335113429
mem.pLast = pHdr;
1335213430
pHdr->iForeGuard = FOREGUARD;
13431
+ pHdr->eType = MEMTYPE_HEAP;
1335313432
pHdr->nBacktraceSlots = mem.nBacktrace;
1335413433
pHdr->nTitle = mem.nTitle;
1335513434
if( mem.nBacktrace ){
1335613435
void *aAddr[40];
1335713436
pHdr->nBacktrace = backtrace(aAddr, mem.nBacktrace+1)-1;
@@ -13454,10 +13533,51 @@
1345413533
sqlite3MemShutdown,
1345513534
0
1345613535
};
1345713536
sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
1345813537
}
13538
+
13539
+/*
13540
+** Set the "type" of an allocation.
13541
+*/
13542
+SQLITE_PRIVATE void sqlite3MemdebugSetType(void *p, u8 eType){
13543
+ if( p ){
13544
+ struct MemBlockHdr *pHdr;
13545
+ pHdr = sqlite3MemsysGetHeader(p);
13546
+ assert( pHdr->iForeGuard==FOREGUARD );
13547
+ pHdr->eType = eType;
13548
+ }
13549
+}
13550
+
13551
+/*
13552
+** Return TRUE if the mask of type in eType matches the type of the
13553
+** allocation p. Also return true if p==NULL.
13554
+**
13555
+** This routine is designed for use within an assert() statement, to
13556
+** verify the type of an allocation. For example:
13557
+**
13558
+** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
13559
+*/
13560
+SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
13561
+ int rc = 1;
13562
+ if( p ){
13563
+ struct MemBlockHdr *pHdr;
13564
+ pHdr = sqlite3MemsysGetHeader(p);
13565
+ assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
13566
+ assert( (pHdr->eType & (pHdr->eType-1))==0 ); /* Only one type bit set */
13567
+ if( (pHdr->eType&eType)==0 ){
13568
+ void **pBt;
13569
+ pBt = (void**)pHdr;
13570
+ pBt -= pHdr->nBacktraceSlots;
13571
+ backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(stderr));
13572
+ fprintf(stderr, "\n");
13573
+ rc = 0;
13574
+ }
13575
+ }
13576
+ return rc;
13577
+}
13578
+
1345913579
1346013580
/*
1346113581
** Set the number of backtrace levels kept for each allocation.
1346213582
** A value of zero turns off backtracing. The number is always rounded
1346313583
** up to a multiple of 2.
@@ -16446,10 +16566,11 @@
1644616566
if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
1644716567
sqlite3_mutex_leave(mem0.mutex);
1644816568
}else{
1644916569
p = sqlite3GlobalConfig.m.xMalloc(n);
1645016570
}
16571
+ sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
1645116572
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
1645216573
scratchAllocOut = p!=0;
1645316574
#endif
1645416575
return p;
1645516576
}
@@ -16466,10 +16587,12 @@
1646616587
#endif
1646716588
1646816589
if( sqlite3GlobalConfig.pScratch==0
1646916590
|| p<sqlite3GlobalConfig.pScratch
1647016591
|| p>=(void*)mem0.aScratchFree ){
16592
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
16593
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1647116594
if( sqlite3GlobalConfig.bMemstat ){
1647216595
int iSize = sqlite3MallocSize(p);
1647316596
sqlite3_mutex_enter(mem0.mutex);
1647416597
sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
1647516598
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
@@ -16506,26 +16629,30 @@
1650616629
/*
1650716630
** Return the size of a memory allocation previously obtained from
1650816631
** sqlite3Malloc() or sqlite3_malloc().
1650916632
*/
1651016633
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
16634
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1651116635
return sqlite3GlobalConfig.m.xSize(p);
1651216636
}
1651316637
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
1651416638
assert( db==0 || sqlite3_mutex_held(db->mutex) );
1651516639
if( isLookaside(db, p) ){
1651616640
return db->lookaside.sz;
1651716641
}else{
16642
+ assert( sqlite3MemdebugHasType(p,
16643
+ db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
1651816644
return sqlite3GlobalConfig.m.xSize(p);
1651916645
}
1652016646
}
1652116647
1652216648
/*
1652316649
** Free memory previously obtained from sqlite3Malloc().
1652416650
*/
1652516651
SQLITE_API void sqlite3_free(void *p){
1652616652
if( p==0 ) return;
16653
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1652716654
if( sqlite3GlobalConfig.bMemstat ){
1652816655
sqlite3_mutex_enter(mem0.mutex);
1652916656
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
1653016657
sqlite3GlobalConfig.m.xFree(p);
1653116658
sqlite3_mutex_leave(mem0.mutex);
@@ -16544,10 +16671,12 @@
1654416671
LookasideSlot *pBuf = (LookasideSlot*)p;
1654516672
pBuf->pNext = db->lookaside.pFree;
1654616673
db->lookaside.pFree = pBuf;
1654716674
db->lookaside.nOut--;
1654816675
}else{
16676
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16677
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1654916678
sqlite3_free(p);
1655016679
}
1655116680
}
1655216681
1655316682
/*
@@ -16576,10 +16705,11 @@
1657616705
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
1657716706
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
1657816707
mem0.alarmThreshold ){
1657916708
sqlite3MallocAlarm(nNew-nOld);
1658016709
}
16710
+ assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
1658116711
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1658216712
if( pNew==0 && mem0.alarmCallback ){
1658316713
sqlite3MallocAlarm(nBytes);
1658416714
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
1658516715
}
@@ -16673,10 +16803,12 @@
1667316803
#endif
1667416804
p = sqlite3Malloc(n);
1667516805
if( !p && db ){
1667616806
db->mallocFailed = 1;
1667716807
}
16808
+ sqlite3MemdebugSetType(p,
16809
+ (db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);
1667816810
return p;
1667916811
}
1668016812
1668116813
/*
1668216814
** Resize the block of memory pointed to by p to n bytes. If the
@@ -16698,14 +16830,18 @@
1669816830
if( pNew ){
1669916831
memcpy(pNew, p, db->lookaside.sz);
1670016832
sqlite3DbFree(db, p);
1670116833
}
1670216834
}else{
16835
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16836
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
1670316837
pNew = sqlite3_realloc(p, n);
1670416838
if( !pNew ){
1670516839
db->mallocFailed = 1;
1670616840
}
16841
+ sqlite3MemdebugSetType(pNew,
16842
+ db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
1670716843
}
1670816844
}
1670916845
return pNew;
1671016846
}
1671116847
@@ -18305,11 +18441,11 @@
1830518441
u8 isPrepareV2; /* True if prepared with prepare_v2() */
1830618442
int nChange; /* Number of db changes made since last reset */
1830718443
int btreeMask; /* Bitmask of db->aDb[] entries referenced */
1830818444
i64 startTime; /* Time when query started - used for profiling */
1830918445
BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18310
- int aCounter[2]; /* Counters used by sqlite3_stmt_status() */
18446
+ int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
1831118447
char *zSql; /* Text of the SQL statement that generated this */
1831218448
void *pFree; /* Free this when deleting the vdbe */
1831318449
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1831418450
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
1831518451
int iStatement; /* Statement number (or 0 if has not opened stmt) */
@@ -20345,52 +20481,52 @@
2034520481
/* 35 */ "ReadCookie",
2034620482
/* 36 */ "SetCookie",
2034720483
/* 37 */ "VerifyCookie",
2034820484
/* 38 */ "OpenRead",
2034920485
/* 39 */ "OpenWrite",
20350
- /* 40 */ "OpenEphemeral",
20351
- /* 41 */ "OpenPseudo",
20352
- /* 42 */ "Close",
20353
- /* 43 */ "SeekLt",
20354
- /* 44 */ "SeekLe",
20355
- /* 45 */ "SeekGe",
20356
- /* 46 */ "SeekGt",
20357
- /* 47 */ "Seek",
20358
- /* 48 */ "NotFound",
20359
- /* 49 */ "Found",
20360
- /* 50 */ "IsUnique",
20361
- /* 51 */ "NotExists",
20362
- /* 52 */ "Sequence",
20363
- /* 53 */ "NewRowid",
20364
- /* 54 */ "Insert",
20365
- /* 55 */ "InsertInt",
20366
- /* 56 */ "Delete",
20367
- /* 57 */ "ResetCount",
20368
- /* 58 */ "RowKey",
20369
- /* 59 */ "RowData",
20370
- /* 60 */ "Rowid",
20371
- /* 61 */ "NullRow",
20372
- /* 62 */ "Last",
20373
- /* 63 */ "Sort",
20374
- /* 64 */ "Rewind",
20375
- /* 65 */ "Prev",
20376
- /* 66 */ "Next",
20377
- /* 67 */ "IdxInsert",
20486
+ /* 40 */ "OpenAutoindex",
20487
+ /* 41 */ "OpenEphemeral",
20488
+ /* 42 */ "OpenPseudo",
20489
+ /* 43 */ "Close",
20490
+ /* 44 */ "SeekLt",
20491
+ /* 45 */ "SeekLe",
20492
+ /* 46 */ "SeekGe",
20493
+ /* 47 */ "SeekGt",
20494
+ /* 48 */ "Seek",
20495
+ /* 49 */ "NotFound",
20496
+ /* 50 */ "Found",
20497
+ /* 51 */ "IsUnique",
20498
+ /* 52 */ "NotExists",
20499
+ /* 53 */ "Sequence",
20500
+ /* 54 */ "NewRowid",
20501
+ /* 55 */ "Insert",
20502
+ /* 56 */ "InsertInt",
20503
+ /* 57 */ "Delete",
20504
+ /* 58 */ "ResetCount",
20505
+ /* 59 */ "RowKey",
20506
+ /* 60 */ "RowData",
20507
+ /* 61 */ "Rowid",
20508
+ /* 62 */ "NullRow",
20509
+ /* 63 */ "Last",
20510
+ /* 64 */ "Sort",
20511
+ /* 65 */ "Rewind",
20512
+ /* 66 */ "Prev",
20513
+ /* 67 */ "Next",
2037820514
/* 68 */ "Or",
2037920515
/* 69 */ "And",
20380
- /* 70 */ "IdxDelete",
20381
- /* 71 */ "IdxRowid",
20382
- /* 72 */ "IdxLT",
20516
+ /* 70 */ "IdxInsert",
20517
+ /* 71 */ "IdxDelete",
20518
+ /* 72 */ "IdxRowid",
2038320519
/* 73 */ "IsNull",
2038420520
/* 74 */ "NotNull",
2038520521
/* 75 */ "Ne",
2038620522
/* 76 */ "Eq",
2038720523
/* 77 */ "Gt",
2038820524
/* 78 */ "Le",
2038920525
/* 79 */ "Lt",
2039020526
/* 80 */ "Ge",
20391
- /* 81 */ "IdxGE",
20527
+ /* 81 */ "IdxLT",
2039220528
/* 82 */ "BitAnd",
2039320529
/* 83 */ "BitOr",
2039420530
/* 84 */ "ShiftLeft",
2039520531
/* 85 */ "ShiftRight",
2039620532
/* 86 */ "Add",
@@ -20397,54 +20533,54 @@
2039720533
/* 87 */ "Subtract",
2039820534
/* 88 */ "Multiply",
2039920535
/* 89 */ "Divide",
2040020536
/* 90 */ "Remainder",
2040120537
/* 91 */ "Concat",
20402
- /* 92 */ "Destroy",
20538
+ /* 92 */ "IdxGE",
2040320539
/* 93 */ "BitNot",
2040420540
/* 94 */ "String8",
20405
- /* 95 */ "Clear",
20406
- /* 96 */ "CreateIndex",
20407
- /* 97 */ "CreateTable",
20408
- /* 98 */ "ParseSchema",
20409
- /* 99 */ "LoadAnalysis",
20410
- /* 100 */ "DropTable",
20411
- /* 101 */ "DropIndex",
20412
- /* 102 */ "DropTrigger",
20413
- /* 103 */ "IntegrityCk",
20414
- /* 104 */ "RowSetAdd",
20415
- /* 105 */ "RowSetRead",
20416
- /* 106 */ "RowSetTest",
20417
- /* 107 */ "Program",
20418
- /* 108 */ "Param",
20419
- /* 109 */ "FkCounter",
20420
- /* 110 */ "FkIfZero",
20421
- /* 111 */ "MemMax",
20422
- /* 112 */ "IfPos",
20423
- /* 113 */ "IfNeg",
20424
- /* 114 */ "IfZero",
20425
- /* 115 */ "AggStep",
20426
- /* 116 */ "AggFinal",
20427
- /* 117 */ "Vacuum",
20428
- /* 118 */ "IncrVacuum",
20429
- /* 119 */ "Expire",
20430
- /* 120 */ "TableLock",
20431
- /* 121 */ "VBegin",
20432
- /* 122 */ "VCreate",
20433
- /* 123 */ "VDestroy",
20434
- /* 124 */ "VOpen",
20435
- /* 125 */ "VFilter",
20436
- /* 126 */ "VColumn",
20437
- /* 127 */ "VNext",
20438
- /* 128 */ "VRename",
20439
- /* 129 */ "VUpdate",
20541
+ /* 95 */ "Destroy",
20542
+ /* 96 */ "Clear",
20543
+ /* 97 */ "CreateIndex",
20544
+ /* 98 */ "CreateTable",
20545
+ /* 99 */ "ParseSchema",
20546
+ /* 100 */ "LoadAnalysis",
20547
+ /* 101 */ "DropTable",
20548
+ /* 102 */ "DropIndex",
20549
+ /* 103 */ "DropTrigger",
20550
+ /* 104 */ "IntegrityCk",
20551
+ /* 105 */ "RowSetAdd",
20552
+ /* 106 */ "RowSetRead",
20553
+ /* 107 */ "RowSetTest",
20554
+ /* 108 */ "Program",
20555
+ /* 109 */ "Param",
20556
+ /* 110 */ "FkCounter",
20557
+ /* 111 */ "FkIfZero",
20558
+ /* 112 */ "MemMax",
20559
+ /* 113 */ "IfPos",
20560
+ /* 114 */ "IfNeg",
20561
+ /* 115 */ "IfZero",
20562
+ /* 116 */ "AggStep",
20563
+ /* 117 */ "AggFinal",
20564
+ /* 118 */ "Vacuum",
20565
+ /* 119 */ "IncrVacuum",
20566
+ /* 120 */ "Expire",
20567
+ /* 121 */ "TableLock",
20568
+ /* 122 */ "VBegin",
20569
+ /* 123 */ "VCreate",
20570
+ /* 124 */ "VDestroy",
20571
+ /* 125 */ "VOpen",
20572
+ /* 126 */ "VFilter",
20573
+ /* 127 */ "VColumn",
20574
+ /* 128 */ "VNext",
20575
+ /* 129 */ "VRename",
2044020576
/* 130 */ "Real",
20441
- /* 131 */ "Pagecount",
20442
- /* 132 */ "Trace",
20443
- /* 133 */ "Noop",
20444
- /* 134 */ "Explain",
20445
- /* 135 */ "NotUsed_135",
20577
+ /* 131 */ "VUpdate",
20578
+ /* 132 */ "Pagecount",
20579
+ /* 133 */ "Trace",
20580
+ /* 134 */ "Noop",
20581
+ /* 135 */ "Explain",
2044620582
/* 136 */ "NotUsed_136",
2044720583
/* 137 */ "NotUsed_137",
2044820584
/* 138 */ "NotUsed_138",
2044920585
/* 139 */ "NotUsed_139",
2045020586
/* 140 */ "NotUsed_140",
@@ -26155,13 +26291,11 @@
2615526291
flags |= SQLITE_OPEN_READONLY;
2615626292
openFlags |= O_RDONLY;
2615726293
fd = open(zName, openFlags, openMode);
2615826294
}
2615926295
if( fd<0 ){
26160
- sqlite3_log(SQLITE_CANTOPEN, "cannot open file [%s]: %s", zName,
26161
- strerror(errno));
26162
- rc = SQLITE_CANTOPEN;
26296
+ rc = SQLITE_CANTOPEN_BKPT;
2616326297
goto open_finished;
2616426298
}
2616526299
}
2616626300
assert( fd>=0 );
2616726301
if( pOutFlags ){
@@ -30816,11 +30950,16 @@
3081630950
if( pCache->pCache ){
3081730951
PgHdr *p;
3081830952
PgHdr *pNext;
3081930953
for(p=pCache->pDirty; p; p=pNext){
3082030954
pNext = p->pDirtyNext;
30821
- if( p->pgno>pgno ){
30955
+ /* This routine never gets call with a positive pgno except right
30956
+ ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
30957
+ ** it must be that pgno==0.
30958
+ */
30959
+ assert( p->pgno>0 );
30960
+ if( ALWAYS(p->pgno>pgno) ){
3082230961
assert( p->flags&PGHDR_DIRTY );
3082330962
sqlite3PcacheMakeClean(p);
3082430963
}
3082530964
}
3082630965
if( pgno==0 && pCache->pPage1 ){
@@ -31160,10 +31299,11 @@
3116031299
pcache1EnterMutex();
3116131300
if( p ){
3116231301
int sz = sqlite3MallocSize(p);
3116331302
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
3116431303
}
31304
+ sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
3116531305
}
3116631306
return p;
3116731307
}
3116831308
3116931309
/*
@@ -31177,11 +31317,14 @@
3117731317
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
3117831318
pSlot = (PgFreeslot*)p;
3117931319
pSlot->pNext = pcache1.pFree;
3118031320
pcache1.pFree = pSlot;
3118131321
}else{
31182
- int iSize = sqlite3MallocSize(p);
31322
+ int iSize;
31323
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
31324
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
31325
+ iSize = sqlite3MallocSize(p);
3118331326
sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
3118431327
sqlite3_free(p);
3118531328
}
3118631329
}
3118731330
@@ -33315,12 +33458,13 @@
3331533458
pPager->pInJournal = 0;
3331633459
releaseAllSavepoints(pPager);
3331733460
3331833461
/* If the file is unlocked, somebody else might change it. The
3331933462
** values stored in Pager.dbSize etc. might become invalid if
33320
- ** this happens. TODO: Really, this doesn't need to be cleared
33463
+ ** this happens. One can argue that this doesn't need to be cleared
3332133464
** until the change-counter check fails in PagerSharedLock().
33465
+ ** Clearing the page size cache here is being conservative.
3332233466
*/
3332333467
pPager->dbSizeValid = 0;
3332433468
3332533469
rc = osUnlock(pPager->fd, NO_LOCK);
3332633470
if( rc ){
@@ -33506,16 +33650,15 @@
3350633650
}
3350733651
3350833652
#ifdef SQLITE_CHECK_PAGES
3350933653
sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
3351033654
#endif
33511
-
33512
- sqlite3PcacheCleanAll(pPager->pPCache);
33513
- sqlite3BitvecDestroy(pPager->pInJournal);
33514
- pPager->pInJournal = 0;
33515
- pPager->nRec = 0;
3351633655
}
33656
+ sqlite3BitvecDestroy(pPager->pInJournal);
33657
+ pPager->pInJournal = 0;
33658
+ pPager->nRec = 0;
33659
+ sqlite3PcacheCleanAll(pPager->pPCache);
3351733660
3351833661
if( !pPager->exclusiveMode ){
3351933662
rc2 = osUnlock(pPager->fd, SHARED_LOCK);
3352033663
pPager->state = PAGER_SHARED;
3352133664
pPager->changeCountDone = 0;
@@ -34170,10 +34313,18 @@
3417034313
if( rc!=SQLITE_OK ){
3417134314
if( rc==SQLITE_DONE ){
3417234315
rc = SQLITE_OK;
3417334316
pPager->journalOff = szJ;
3417434317
break;
34318
+ }else if( rc==SQLITE_IOERR_SHORT_READ ){
34319
+ /* If the journal has been truncated, simply stop reading and
34320
+ ** processing the journal. This might happen if the journal was
34321
+ ** not completely written and synced prior to a crash. In that
34322
+ ** case, the database should have never been written in the
34323
+ ** first place so it is OK to simply abandon the rollback. */
34324
+ rc = SQLITE_OK;
34325
+ goto end_playback;
3417534326
}else{
3417634327
/* If we are unable to rollback, quit and return the error
3417734328
** code. This will cause the pager to enter the error state
3417834329
** so that no further harm will be done. Perhaps the next
3417934330
** process to come along will be able to rollback the database.
@@ -34575,14 +34726,16 @@
3457534726
** maximum page count below the current size of the database.
3457634727
**
3457734728
** Regardless of mxPage, return the current maximum page count.
3457834729
*/
3457934730
SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
34731
+ int nPage;
3458034732
if( mxPage>0 ){
3458134733
pPager->mxPgno = mxPage;
3458234734
}
34583
- sqlite3PagerPagecount(pPager, 0);
34735
+ sqlite3PagerPagecount(pPager, &nPage);
34736
+ assert( pPager->mxPgno>=nPage );
3458434737
return pPager->mxPgno;
3458534738
}
3458634739
3458734740
/*
3458834741
** The following set of routines are used to disable the simulated
@@ -34652,15 +34805,10 @@
3465234805
** and *pnPage is set to the number of pages in the database.
3465334806
*/
3465434807
SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
3465534808
Pgno nPage; /* Value to return via *pnPage */
3465634809
34657
- /* If the pager is already in the error state, return the error code. */
34658
- if( pPager->errCode ){
34659
- return pPager->errCode;
34660
- }
34661
-
3466234810
/* Determine the number of pages in the file. Store this in nPage. */
3466334811
if( pPager->dbSizeValid ){
3466434812
nPage = pPager->dbSize;
3466534813
}else{
3466634814
int rc; /* Error returned by OsFileSize() */
@@ -34690,13 +34838,11 @@
3469034838
if( nPage>pPager->mxPgno ){
3469134839
pPager->mxPgno = (Pgno)nPage;
3469234840
}
3469334841
3469434842
/* Set the output variable and return SQLITE_OK */
34695
- if( pnPage ){
34696
- *pnPage = nPage;
34697
- }
34843
+ *pnPage = nPage;
3469834844
return SQLITE_OK;
3469934845
}
3470034846
3470134847
3470234848
/*
@@ -35890,20 +36036,20 @@
3589036036
**
3589136037
** There is a vanishingly small chance that a change will not be
3589236038
** detected. The chance of an undetected change is so small that
3589336039
** it can be neglected.
3589436040
*/
36041
+ int nPage;
3589536042
char dbFileVers[sizeof(pPager->dbFileVers)];
35896
- sqlite3PagerPagecount(pPager, 0);
36043
+ sqlite3PagerPagecount(pPager, &nPage);
3589736044
3589836045
if( pPager->errCode ){
3589936046
rc = pPager->errCode;
3590036047
goto failed;
3590136048
}
3590236049
35903
- assert( pPager->dbSizeValid );
35904
- if( pPager->dbSize>0 ){
36050
+ if( nPage>0 ){
3590536051
IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
3590636052
rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
3590736053
if( rc!=SQLITE_OK ){
3590836054
goto failed;
3590936055
}
@@ -36024,11 +36170,11 @@
3602436170
goto pager_acquire_err;
3602536171
}
3602636172
assert( (*ppPage)->pgno==pgno );
3602736173
assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 );
3602836174
36029
- if( (*ppPage)->pPager ){
36175
+ if( (*ppPage)->pPager && !noContent ){
3603036176
/* In this case the pcache already contains an initialized copy of
3603136177
** the page. Return without further ado. */
3603236178
assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
3603336179
PAGER_INCR(pPager->nHit);
3603436180
return SQLITE_OK;
@@ -36184,10 +36330,11 @@
3618436330
** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
3618536331
** an IO error code if opening or writing the journal file fails.
3618636332
*/
3618736333
static int pager_open_journal(Pager *pPager){
3618836334
int rc = SQLITE_OK; /* Return code */
36335
+ int nPage; /* Size of database file */
3618936336
sqlite3_vfs * const pVfs = pPager->pVfs; /* Local cache of vfs pointer */
3619036337
3619136338
assert( pPager->state>=PAGER_RESERVED );
3619236339
assert( pPager->useJournal );
3619336340
assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF );
@@ -36196,17 +36343,14 @@
3619636343
/* If already in the error state, this function is a no-op. But on
3619736344
** the other hand, this routine is never called if we are already in
3619836345
** an error state. */
3619936346
if( NEVER(pPager->errCode) ) return pPager->errCode;
3620036347
36201
- /* TODO: Is it really possible to get here with dbSizeValid==0? If not,
36202
- ** the call to PagerPagecount() can be removed.
36203
- */
3620436348
testcase( pPager->dbSizeValid==0 );
36205
- sqlite3PagerPagecount(pPager, 0);
36206
-
36207
- pPager->pInJournal = sqlite3BitvecCreate(pPager->dbSize);
36349
+ rc = sqlite3PagerPagecount(pPager, &nPage);
36350
+ if( rc ) return rc;
36351
+ pPager->pInJournal = sqlite3BitvecCreate(nPage);
3620836352
if( pPager->pInJournal==0 ){
3620936353
return SQLITE_NOMEM;
3621036354
}
3621136355
3621236356
/* Open the journal file if it is not already open. */
@@ -36301,16 +36445,15 @@
3630136445
if( exFlag ){
3630236446
rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
3630336447
}
3630436448
}
3630536449
36306
- /* If the required locks were successfully obtained, open the journal
36307
- ** file and write the first journal-header to it.
36450
+ /* No need to open the journal file at this time. It will be
36451
+ ** opened before it is written to. If we defer opening the journal,
36452
+ ** we might save the work of creating a file if the transaction
36453
+ ** ends up being a no-op.
3630836454
*/
36309
- if( rc==SQLITE_OK && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36310
- rc = pager_open_journal(pPager);
36311
- }
3631236455
}else if( isOpen(pPager->jfd) && pPager->journalOff==0 ){
3631336456
/* This happens when the pager was in exclusive-access mode the last
3631436457
** time a (read or write) transaction was successfully concluded
3631536458
** by this connection. Instead of deleting the journal file it was
3631636459
** kept open and either was truncated to 0 bytes or its header was
@@ -36321,11 +36464,10 @@
3632136464
assert( pPager->pInJournal==0 );
3632236465
rc = pager_open_journal(pPager);
3632336466
}
3632436467
3632536468
PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
36326
- assert( !isOpen(pPager->jfd) || pPager->journalOff>0 || rc!=SQLITE_OK );
3632736469
if( rc!=SQLITE_OK ){
3632836470
assert( !pPager->dbModified );
3632936471
/* Ignore any IO error that occurs within pager_end_transaction(). The
3633036472
** purpose of this call is to reset the internal state of the pager
3633136473
** sub-system. It doesn't matter if the journal-file is not properly
@@ -36351,12 +36493,12 @@
3635136493
/* This routine is not called unless a transaction has already been
3635236494
** started.
3635336495
*/
3635436496
assert( pPager->state>=PAGER_RESERVED );
3635536497
36356
- /* If an error has been previously detected, we should not be
36357
- ** calling this routine. Repeat the error for robustness.
36498
+ /* If an error has been previously detected, report the same error
36499
+ ** again.
3635836500
*/
3635936501
if( NEVER(pPager->errCode) ) return pPager->errCode;
3636036502
3636136503
/* Higher-level routines never call this function if database is not
3636236504
** writable. But check anyway, just for robustness. */
@@ -36377,15 +36519,15 @@
3637736519
/* If we get this far, it means that the page needs to be
3637836520
** written to the transaction journal or the ckeckpoint journal
3637936521
** or both.
3638036522
**
3638136523
** Higher level routines should have already started a transaction,
36382
- ** which means they have acquired the necessary locks and opened
36383
- ** a rollback journal. Double-check to makes sure this is the case.
36524
+ ** which means they have acquired the necessary locks but the rollback
36525
+ ** journal might not yet be open.
3638436526
*/
3638536527
rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
36386
- if( NEVER(rc!=SQLITE_OK) ){
36528
+ if( rc!=SQLITE_OK ){
3638736529
return rc;
3638836530
}
3638936531
if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
3639036532
assert( pPager->useJournal );
3639136533
rc = pager_open_journal(pPager);
@@ -36523,11 +36665,12 @@
3652336665
** an integer power of 2. It sets variable pg1 to the identifier
3652436666
** of the first page of the sector pPg is located on.
3652536667
*/
3652636668
pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
3652736669
36528
- sqlite3PagerPagecount(pPager, (int *)&nPageCount);
36670
+ rc = sqlite3PagerPagecount(pPager, (int *)&nPageCount);
36671
+ if( rc ) return rc;
3652936672
if( pPg->pgno>nPageCount ){
3653036673
nPage = (pPg->pgno - pg1)+1;
3653136674
}else if( (pg1+nPagePerSector-1)>nPageCount ){
3653236675
nPage = nPageCount+1-pg1;
3653336676
}else{
@@ -36684,10 +36827,13 @@
3668436827
/* Increment the value just read and write it back to byte 24. */
3668536828
change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
3668636829
change_counter++;
3668736830
put32bits(((char*)pPgHdr->pData)+24, change_counter);
3668836831
36832
+ /* Also store the SQLite version number in bytes 96..99 */
36833
+ put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
36834
+
3668936835
/* If running in direct mode, write the contents of page 1 to the file. */
3669036836
if( DIRECT_MODE ){
3669136837
const void *zBuf = pPgHdr->pData;
3669236838
assert( pPager->dbFileSize>0 );
3669336839
rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
@@ -36757,13 +36903,11 @@
3675736903
int rc = SQLITE_OK; /* Return code */
3675836904
3675936905
/* The dbOrigSize is never set if journal_mode=OFF */
3676036906
assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 );
3676136907
36762
- /* If a prior error occurred, this routine should not be called. ROLLBACK
36763
- ** is the appropriate response to an error, not COMMIT. Guard against
36764
- ** coding errors by repeating the prior error. */
36908
+ /* If a prior error occurred, report that error again. */
3676536909
if( NEVER(pPager->errCode) ) return pPager->errCode;
3676636910
3676736911
PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
3676836912
pPager->zFilename, zMaster, pPager->dbSize));
3676936913
@@ -37048,10 +37192,20 @@
3704837192
** Return the number of references to the pager.
3704937193
*/
3705037194
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
3705137195
return sqlite3PcacheRefCount(pPager->pPCache);
3705237196
}
37197
+
37198
+/*
37199
+** Return the approximate number of bytes of memory currently
37200
+** used by the pager and its associated cache.
37201
+*/
37202
+SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
37203
+ int perPageSize = pPager->pageSize + pPager->nExtra + 20;
37204
+ return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
37205
+ + sqlite3MallocSize(pPager);
37206
+}
3705337207
3705437208
/*
3705537209
** Return the number of references to the specified page.
3705637210
*/
3705737211
SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
@@ -37101,15 +37255,14 @@
3710137255
int nCurrent = pPager->nSavepoint; /* Current number of savepoints */
3710237256
3710337257
if( nSavepoint>nCurrent && pPager->useJournal ){
3710437258
int ii; /* Iterator variable */
3710537259
PagerSavepoint *aNew; /* New Pager.aSavepoint array */
37260
+ int nPage; /* Size of database file */
3710637261
37107
- /* Either there is no active journal or the sub-journal is open or
37108
- ** the journal is always stored in memory */
37109
- assert( pPager->nSavepoint==0 || isOpen(pPager->sjfd) ||
37110
- pPager->journalMode==PAGER_JOURNALMODE_MEMORY );
37262
+ rc = sqlite3PagerPagecount(pPager, &nPage);
37263
+ if( rc ) return rc;
3711137264
3711237265
/* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
3711337266
** if the allocation fails. Otherwise, zero the new portion in case a
3711437267
** malloc failure occurs while populating it in the for(...) loop below.
3711537268
*/
@@ -37123,19 +37276,18 @@
3712337276
pPager->aSavepoint = aNew;
3712437277
pPager->nSavepoint = nSavepoint;
3712537278
3712637279
/* Populate the PagerSavepoint structures just allocated. */
3712737280
for(ii=nCurrent; ii<nSavepoint; ii++){
37128
- assert( pPager->dbSizeValid );
37129
- aNew[ii].nOrig = pPager->dbSize;
37130
- if( isOpen(pPager->jfd) && ALWAYS(pPager->journalOff>0) ){
37281
+ aNew[ii].nOrig = nPage;
37282
+ if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
3713137283
aNew[ii].iOffset = pPager->journalOff;
3713237284
}else{
3713337285
aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
3713437286
}
3713537287
aNew[ii].iSubRec = pPager->nSubRec;
37136
- aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
37288
+ aNew[ii].pInSavepoint = sqlite3BitvecCreate(nPage);
3713737289
if( !aNew[ii].pInSavepoint ){
3713837290
return SQLITE_NOMEM;
3713937291
}
3714037292
}
3714137293
@@ -37518,10 +37670,19 @@
3751837670
&& (!isOpen(pPager->jfd) || 0==pPager->journalOff)
3751937671
){
3752037672
if( isOpen(pPager->jfd) ){
3752137673
sqlite3OsClose(pPager->jfd);
3752237674
}
37675
+ assert( (PAGER_JOURNALMODE_TRUNCATE & 1)==1 );
37676
+ assert( (PAGER_JOURNALMODE_PERSIST & 1)==1 );
37677
+ assert( (PAGER_JOURNALMODE_DELETE & 1)==0 );
37678
+ assert( (PAGER_JOURNALMODE_MEMORY & 1)==0 );
37679
+ assert( (PAGER_JOURNALMODE_OFF & 1)==0 );
37680
+ if( (pPager->journalMode & 1)==1 && (eMode & 1)==0
37681
+ && !pPager->exclusiveMode ){
37682
+ sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
37683
+ }
3752337684
pPager->journalMode = (u8)eMode;
3752437685
}
3752537686
return (int)pPager->journalMode;
3752637687
}
3752737688
@@ -37978,10 +38139,11 @@
3797838139
BtCursor *pCursor; /* A list of all open cursors */
3797938140
MemPage *pPage1; /* First page of the database */
3798038141
u8 readOnly; /* True if the underlying file is readonly */
3798138142
u8 pageSizeFixed; /* True if the page size can no longer be changed */
3798238143
u8 secureDelete; /* True if secure_delete is enabled */
38144
+ u8 initiallyEmpty; /* Database is empty at start of transaction */
3798338145
#ifndef SQLITE_OMIT_AUTOVACUUM
3798438146
u8 autoVacuum; /* True if auto-vacuum is enabled */
3798538147
u8 incrVacuum; /* True if incr-vacuum is enabled */
3798638148
#endif
3798738149
u16 pageSize; /* Total number of bytes on a page */
@@ -37990,10 +38152,11 @@
3799038152
u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
3799138153
u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
3799238154
u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
3799338155
u8 inTransaction; /* Transaction state */
3799438156
int nTransaction; /* Number of open transactions (read + write) */
38157
+ u32 nPage; /* Number of pages in the database */
3799538158
void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
3799638159
void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
3799738160
sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
3799838161
Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */
3799938162
#ifndef SQLITE_OMIT_SHARED_CACHE
@@ -39070,15 +39233,12 @@
3907039233
** at the end of every transaction.
3907139234
*/
3907239235
static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
3907339236
int rc = SQLITE_OK;
3907439237
if( !pBt->pHasContent ){
39075
- int nPage = 100;
39076
- sqlite3PagerPagecount(pBt->pPager, &nPage);
39077
- /* If sqlite3PagerPagecount() fails there is no harm because the
39078
- ** nPage variable is unchanged from its default value of 100 */
39079
- pBt->pHasContent = sqlite3BitvecCreate((u32)nPage);
39238
+ assert( pgno<=pBt->nPage );
39239
+ pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
3908039240
if( !pBt->pHasContent ){
3908139241
rc = SQLITE_NOMEM;
3908239242
}
3908339243
}
3908439244
if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
@@ -40117,17 +40277,17 @@
4011740277
4011840278
/*
4011940279
** Return the size of the database file in pages. If there is any kind of
4012040280
** error, return ((unsigned int)-1).
4012140281
*/
40122
-static Pgno pagerPagecount(BtShared *pBt){
40123
- int nPage = -1;
40124
- int rc;
40125
- assert( pBt->pPage1 );
40126
- rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40127
- assert( rc==SQLITE_OK || nPage==-1 );
40128
- return (Pgno)nPage;
40282
+static Pgno btreePagecount(BtShared *pBt){
40283
+ return pBt->nPage;
40284
+}
40285
+SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
40286
+ assert( sqlite3BtreeHoldsMutex(p) );
40287
+ assert( ((p->pBt->nPage)&0x8000000)==0 );
40288
+ return (int)btreePagecount(p->pBt);
4012940289
}
4013040290
4013140291
/*
4013240292
** Get a page from the pager and initialize it. This routine is just a
4013340293
** convenience wrapper around separate calls to btreeGetPage() and
@@ -40140,29 +40300,22 @@
4014040300
BtShared *pBt, /* The database file */
4014140301
Pgno pgno, /* Number of the page to get */
4014240302
MemPage **ppPage /* Write the page pointer here */
4014340303
){
4014440304
int rc;
40145
- TESTONLY( Pgno iLastPg = pagerPagecount(pBt); )
4014640305
assert( sqlite3_mutex_held(pBt->mutex) );
4014740306
40307
+ if( pgno<=0 || pgno>btreePagecount(pBt) ){
40308
+ return SQLITE_CORRUPT_BKPT;
40309
+ }
4014840310
rc = btreeGetPage(pBt, pgno, ppPage, 0);
4014940311
if( rc==SQLITE_OK ){
4015040312
rc = btreeInitPage(*ppPage);
4015140313
if( rc!=SQLITE_OK ){
4015240314
releasePage(*ppPage);
4015340315
}
4015440316
}
40155
-
40156
- /* If the requested page number was either 0 or greater than the page
40157
- ** number of the last page in the database, this function should return
40158
- ** SQLITE_CORRUPT or some other error (i.e. SQLITE_FULL). Check that this
40159
- ** is the case. */
40160
- assert( (pgno>0 && pgno<=iLastPg) || rc!=SQLITE_OK );
40161
- testcase( pgno==0 );
40162
- testcase( pgno==iLastPg );
40163
-
4016440317
return rc;
4016540318
}
4016640319
4016740320
/*
4016840321
** Release a MemPage. This should be called once for each prior
@@ -40794,13 +40947,15 @@
4079440947
** well-formed database file, then SQLITE_CORRUPT is returned.
4079540948
** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
4079640949
** is returned if we run out of memory.
4079740950
*/
4079840951
static int lockBtree(BtShared *pBt){
40799
- int rc;
40800
- MemPage *pPage1;
40801
- int nPage;
40952
+ int rc; /* Result code from subfunctions */
40953
+ MemPage *pPage1; /* Page 1 of the database file */
40954
+ int nPage; /* Number of pages in the database */
40955
+ int nPageFile = 0; /* Number of pages in the database file */
40956
+ int nPageHeader; /* Number of pages in the database according to hdr */
4080240957
4080340958
assert( sqlite3_mutex_held(pBt->mutex) );
4080440959
assert( pBt->pPage1==0 );
4080540960
rc = sqlite3PagerSharedLock(pBt->pPager);
4080640961
if( rc!=SQLITE_OK ) return rc;
@@ -40808,14 +40963,18 @@
4080840963
if( rc!=SQLITE_OK ) return rc;
4080940964
4081040965
/* Do some checking to help insure the file we opened really is
4081140966
** a valid database file.
4081240967
*/
40813
- rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40814
- if( rc!=SQLITE_OK ){
40968
+ nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
40969
+ if( (rc = sqlite3PagerPagecount(pBt->pPager, &nPageFile))!=SQLITE_OK ){;
4081540970
goto page1_init_failed;
40816
- }else if( nPage>0 ){
40971
+ }
40972
+ if( nPage==0 ){
40973
+ nPage = nPageFile;
40974
+ }
40975
+ if( nPage>0 ){
4081740976
int pageSize;
4081840977
int usableSize;
4081940978
u8 *page1 = pPage1->aData;
4082040979
rc = SQLITE_NOTADB;
4082140980
if( memcmp(page1, zMagicHeader, 16)!=0 ){
@@ -40857,10 +41016,14 @@
4085741016
freeTempSpace(pBt);
4085841017
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
4085941018
pageSize-usableSize);
4086041019
return rc;
4086141020
}
41021
+ if( nPageHeader>nPageFile ){
41022
+ rc = SQLITE_CORRUPT_BKPT;
41023
+ goto page1_init_failed;
41024
+ }
4086241025
if( usableSize<480 ){
4086341026
goto page1_init_failed;
4086441027
}
4086541028
pBt->pageSize = (u16)pageSize;
4086641029
pBt->usableSize = (u16)usableSize;
@@ -40887,10 +41050,11 @@
4088741050
pBt->minLocal = (pBt->usableSize-12)*32/255 - 23;
4088841051
pBt->maxLeaf = pBt->usableSize - 35;
4088941052
pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23;
4089041053
assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
4089141054
pBt->pPage1 = pPage1;
41055
+ pBt->nPage = nPage;
4089241056
return SQLITE_OK;
4089341057
4089441058
page1_init_failed:
4089541059
releasePage(pPage1);
4089641060
pBt->pPage1 = 0;
@@ -40924,16 +41088,14 @@
4092441088
*/
4092541089
static int newDatabase(BtShared *pBt){
4092641090
MemPage *pP1;
4092741091
unsigned char *data;
4092841092
int rc;
40929
- int nPage;
4093041093
4093141094
assert( sqlite3_mutex_held(pBt->mutex) );
40932
- rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40933
- if( rc!=SQLITE_OK || nPage>0 ){
40934
- return rc;
41095
+ if( pBt->nPage>0 ){
41096
+ return SQLITE_OK;
4093541097
}
4093641098
pP1 = pBt->pPage1;
4093741099
assert( pP1!=0 );
4093841100
data = pP1->aData;
4093941101
rc = sqlite3PagerWrite(pP1->pDbPage);
@@ -40955,10 +41117,12 @@
4095541117
assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
4095641118
assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
4095741119
put4byte(&data[36 + 4*4], pBt->autoVacuum);
4095841120
put4byte(&data[36 + 7*4], pBt->incrVacuum);
4095941121
#endif
41122
+ pBt->nPage = 1;
41123
+ data[31] = 1;
4096041124
return SQLITE_OK;
4096141125
}
4096241126
4096341127
/*
4096441128
** Attempt to start a new transaction. A write-transaction
@@ -41044,10 +41208,11 @@
4104441208
** page 1. So if some other shared-cache client already has a write-lock
4104541209
** on page 1, the transaction cannot be opened. */
4104641210
rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
4104741211
if( SQLITE_OK!=rc ) goto trans_begun;
4104841212
41213
+ pBt->initiallyEmpty = pBt->nPage==0;
4104941214
do {
4105041215
/* Call lockBtree() until either pBt->pPage1 is populated or
4105141216
** lockBtree() returns something other than SQLITE_OK. lockBtree()
4105241217
** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
4105341218
** reading page 1 it discovers that the page-size of the database
@@ -41323,16 +41488,16 @@
4132341488
** which may or may not empty the freelist. A full autovacuum
4132441489
** has nFin>0. A "PRAGMA incremental_vacuum" has nFin==0.
4132541490
*/
4132641491
static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
4132741492
Pgno nFreeList; /* Number of pages still on the free-list */
41493
+ int rc;
4132841494
4132941495
assert( sqlite3_mutex_held(pBt->mutex) );
4133041496
assert( iLastPg>nFin );
4133141497
4133241498
if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
41333
- int rc;
4133441499
u8 eType;
4133541500
Pgno iPtrPage;
4133641501
4133741502
nFreeList = get4byte(&pBt->pPage1->aData[36]);
4133841503
if( nFreeList==0 ){
@@ -41404,11 +41569,11 @@
4140441569
if( nFin==0 ){
4140541570
iLastPg--;
4140641571
while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
4140741572
if( PTRMAP_ISPAGE(pBt, iLastPg) ){
4140841573
MemPage *pPg;
41409
- int rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
41574
+ rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
4141041575
if( rc!=SQLITE_OK ){
4141141576
return rc;
4141241577
}
4141341578
rc = sqlite3PagerWrite(pPg->pDbPage);
4141441579
releasePage(pPg);
@@ -41417,10 +41582,11 @@
4141741582
}
4141841583
}
4141941584
iLastPg--;
4142041585
}
4142141586
sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
41587
+ pBt->nPage = iLastPg;
4142241588
}
4142341589
return SQLITE_OK;
4142441590
}
4142541591
4142641592
/*
@@ -41439,11 +41605,15 @@
4143941605
assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
4144041606
if( !pBt->autoVacuum ){
4144141607
rc = SQLITE_DONE;
4144241608
}else{
4144341609
invalidateAllOverflowCache(pBt);
41444
- rc = incrVacuumStep(pBt, 0, pagerPagecount(pBt));
41610
+ rc = incrVacuumStep(pBt, 0, btreePagecount(pBt));
41611
+ if( rc==SQLITE_OK ){
41612
+ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41613
+ put4byte(&pBt->pPage1->aData[28], pBt->nPage);
41614
+ }
4144541615
}
4144641616
sqlite3BtreeLeave(p);
4144741617
return rc;
4144841618
}
4144941619
@@ -41470,11 +41640,11 @@
4147041640
Pgno nPtrmap; /* Number of PtrMap pages to be freed */
4147141641
Pgno iFree; /* The next page to be freed */
4147241642
int nEntry; /* Number of entries on one ptrmap page */
4147341643
Pgno nOrig; /* Database size before freeing */
4147441644
41475
- nOrig = pagerPagecount(pBt);
41645
+ nOrig = btreePagecount(pBt);
4147641646
if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
4147741647
/* It is not possible to create a database for which the final page
4147841648
** is either a pointer-map page or the pending-byte page. If one
4147941649
** is encountered, this indicates corruption.
4148041650
*/
@@ -41495,15 +41665,16 @@
4149541665
4149641666
for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
4149741667
rc = incrVacuumStep(pBt, nFin, iFree);
4149841668
}
4149941669
if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
41500
- rc = SQLITE_OK;
4150141670
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
4150241671
put4byte(&pBt->pPage1->aData[32], 0);
4150341672
put4byte(&pBt->pPage1->aData[36], 0);
41673
+ put4byte(&pBt->pPage1->aData[28], nFin);
4150441674
sqlite3PagerTruncateImage(pBt->pPager, nFin);
41675
+ pBt->nPage = nFin;
4150541676
}
4150641677
if( rc!=SQLITE_OK ){
4150741678
sqlite3PagerRollback(pPager);
4150841679
}
4150941680
}
@@ -41749,10 +41920,15 @@
4174941920
4175041921
/* The rollback may have destroyed the pPage1->aData value. So
4175141922
** call btreeGetPage() on page 1 again to make
4175241923
** sure pPage1->aData is set correctly. */
4175341924
if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
41925
+ int nPage = get4byte(28+(u8*)pPage1->aData);
41926
+ testcase( nPage==0 );
41927
+ if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
41928
+ testcase( pBt->nPage!=nPage );
41929
+ pBt->nPage = nPage;
4175441930
releasePage(pPage1);
4175541931
}
4175641932
assert( countWriteCursors(pBt)==0 );
4175741933
pBt->inTransaction = TRANS_READ;
4175841934
}
@@ -41786,21 +41962,17 @@
4178641962
sqlite3BtreeEnter(p);
4178741963
assert( p->inTrans==TRANS_WRITE );
4178841964
assert( pBt->readOnly==0 );
4178941965
assert( iStatement>0 );
4179041966
assert( iStatement>p->db->nSavepoint );
41791
- if( NEVER(p->inTrans!=TRANS_WRITE || pBt->readOnly) ){
41792
- rc = SQLITE_INTERNAL;
41793
- }else{
41794
- assert( pBt->inTransaction==TRANS_WRITE );
41795
- /* At the pager level, a statement transaction is a savepoint with
41796
- ** an index greater than all savepoints created explicitly using
41797
- ** SQL statements. It is illegal to open, release or rollback any
41798
- ** such savepoints while the statement transaction savepoint is active.
41799
- */
41800
- rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
41801
- }
41967
+ assert( pBt->inTransaction==TRANS_WRITE );
41968
+ /* At the pager level, a statement transaction is a savepoint with
41969
+ ** an index greater than all savepoints created explicitly using
41970
+ ** SQL statements. It is illegal to open, release or rollback any
41971
+ ** such savepoints while the statement transaction savepoint is active.
41972
+ */
41973
+ rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
4180241974
sqlite3BtreeLeave(p);
4180341975
return rc;
4180441976
}
4180541977
4180641978
/*
@@ -41822,11 +41994,13 @@
4182241994
assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
4182341995
assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
4182441996
sqlite3BtreeEnter(p);
4182541997
rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
4182641998
if( rc==SQLITE_OK ){
41999
+ if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
4182742000
rc = newDatabase(pBt);
42001
+ pBt->nPage = get4byte(28 + pBt->pPage1->aData);
4182842002
}
4182942003
sqlite3BtreeLeave(p);
4183042004
}
4183142005
return rc;
4183242006
}
@@ -41888,11 +42062,11 @@
4188842062
assert( pBt->pPage1 && pBt->pPage1->aData );
4188942063
4189042064
if( NEVER(wrFlag && pBt->readOnly) ){
4189142065
return SQLITE_READONLY;
4189242066
}
41893
- if( iTable==1 && pagerPagecount(pBt)==0 ){
42067
+ if( iTable==1 && btreePagecount(pBt)==0 ){
4189442068
return SQLITE_EMPTY;
4189542069
}
4189642070
4189742071
/* Now that no other errors can occur, finish filling in the BtCursor
4189842072
** variables and link the cursor into the BtShared list. */
@@ -42159,11 +42333,11 @@
4215942333
4216042334
while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
4216142335
iGuess++;
4216242336
}
4216342337
42164
- if( iGuess<=pagerPagecount(pBt) ){
42338
+ if( iGuess<=btreePagecount(pBt) ){
4216542339
rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
4216642340
if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
4216742341
next = iGuess;
4216842342
rc = SQLITE_DONE;
4216942343
}
@@ -43191,11 +43365,11 @@
4319143365
MemPage *pPrevTrunk = 0;
4319243366
Pgno mxPage; /* Total size of the database file */
4319343367
4319443368
assert( sqlite3_mutex_held(pBt->mutex) );
4319543369
pPage1 = pBt->pPage1;
43196
- mxPage = pagerPagecount(pBt);
43370
+ mxPage = btreePagecount(pBt);
4319743371
n = get4byte(&pPage1->aData[36]);
4319843372
testcase( n==mxPage-1 );
4319943373
if( n>=mxPage ){
4320043374
return SQLITE_CORRUPT_BKPT;
4320143375
}
@@ -43387,39 +43561,39 @@
4338743561
pPrevTrunk = 0;
4338843562
}while( searchList );
4338943563
}else{
4339043564
/* There are no pages on the freelist, so create a new page at the
4339143565
** end of the file */
43392
- int nPage = pagerPagecount(pBt);
43393
- *pPgno = nPage + 1;
43394
-
43395
- if( *pPgno==PENDING_BYTE_PAGE(pBt) ){
43396
- (*pPgno)++;
43397
- }
43566
+ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
43567
+ if( rc ) return rc;
43568
+ pBt->nPage++;
43569
+ if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
4339843570
4339943571
#ifndef SQLITE_OMIT_AUTOVACUUM
43400
- if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
43572
+ if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, pBt->nPage) ){
4340143573
/* If *pPgno refers to a pointer-map page, allocate two new pages
4340243574
** at the end of the file instead of one. The first allocated page
4340343575
** becomes a new pointer-map page, the second is used by the caller.
4340443576
*/
4340543577
MemPage *pPg = 0;
43406
- TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
43407
- assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43408
- rc = btreeGetPage(pBt, *pPgno, &pPg, 0);
43578
+ TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
43579
+ assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
43580
+ rc = btreeGetPage(pBt, pBt->nPage, &pPg, 1);
4340943581
if( rc==SQLITE_OK ){
4341043582
rc = sqlite3PagerWrite(pPg->pDbPage);
4341143583
releasePage(pPg);
4341243584
}
4341343585
if( rc ) return rc;
43414
- (*pPgno)++;
43415
- if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
43586
+ pBt->nPage++;
43587
+ if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ){ pBt->nPage++; }
4341643588
}
4341743589
#endif
43590
+ put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
43591
+ *pPgno = pBt->nPage;
4341843592
4341943593
assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43420
- rc = btreeGetPage(pBt, *pPgno, ppPage, 0);
43594
+ rc = btreeGetPage(pBt, *pPgno, ppPage, 1);
4342143595
if( rc ) return rc;
4342243596
rc = sqlite3PagerWrite((*ppPage)->pDbPage);
4342343597
if( rc!=SQLITE_OK ){
4342443598
releasePage(*ppPage);
4342543599
}
@@ -43605,11 +43779,11 @@
4360543779
nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
4360643780
assert( ovflPgno==0 || nOvfl>0 );
4360743781
while( nOvfl-- ){
4360843782
Pgno iNext = 0;
4360943783
MemPage *pOvfl = 0;
43610
- if( ovflPgno<2 || ovflPgno>pagerPagecount(pBt) ){
43784
+ if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
4361143785
/* 0 is not a legal page number and page 1 cannot be an
4361243786
** overflow page. Therefore if ovflPgno<2 or past the end of the
4361343787
** file the database must be corrupt. */
4361443788
return SQLITE_CORRUPT_BKPT;
4361543789
}
@@ -45437,12 +45611,18 @@
4543745611
ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
4543845612
if( rc ){
4543945613
releasePage(pRoot);
4544045614
return rc;
4544145615
}
45616
+
45617
+ /* When the new root page was allocated, page 1 was made writable in
45618
+ ** order either to increase the database filesize, or to decrement the
45619
+ ** freelist count. Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
45620
+ */
45621
+ assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
4544245622
rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
45443
- if( rc ){
45623
+ if( NEVER(rc) ){
4544445624
releasePage(pRoot);
4544545625
return rc;
4544645626
}
4544745627
4544845628
}else{
@@ -45478,11 +45658,11 @@
4547845658
int rc;
4547945659
unsigned char *pCell;
4548045660
int i;
4548145661
4548245662
assert( sqlite3_mutex_held(pBt->mutex) );
45483
- if( pgno>pagerPagecount(pBt) ){
45663
+ if( pgno>btreePagecount(pBt) ){
4548445664
return SQLITE_CORRUPT_BKPT;
4548545665
}
4548645666
4548745667
rc = getAndInitPage(pBt, pgno, &pPage);
4548845668
if( rc ) return rc;
@@ -46229,11 +46409,11 @@
4622946409
sqlite3BtreeEnter(p);
4623046410
assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
4623146411
nRef = sqlite3PagerRefcount(pBt->pPager);
4623246412
sCheck.pBt = pBt;
4623346413
sCheck.pPager = pBt->pPager;
46234
- sCheck.nPage = pagerPagecount(sCheck.pBt);
46414
+ sCheck.nPage = btreePagecount(sCheck.pBt);
4623546415
sCheck.mxErr = mxErr;
4623646416
sCheck.nErr = 0;
4623746417
sCheck.mallocFailed = 0;
4623846418
*pnErr = 0;
4623946419
if( sCheck.nPage==0 ){
@@ -46831,13 +47011,12 @@
4683147011
}
4683247012
4683347013
/* Now that there is a read-lock on the source database, query the
4683447014
** source pager for the number of pages in the database.
4683547015
*/
46836
- if( rc==SQLITE_OK ){
46837
- rc = sqlite3PagerPagecount(pSrcPager, &nSrcPage);
46838
- }
47016
+ nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
47017
+ assert( nSrcPage>=0 );
4683947018
for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
4684047019
const Pgno iSrcPg = p->iNext; /* Source page number */
4684147020
if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
4684247021
DbPage *pSrcPg; /* Source page object */
4684347022
rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
@@ -48986,11 +49165,11 @@
4898649165
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
4898749166
pKeyInfo = sqlite3Malloc( nByte );
4898849167
pOp->p4.pKeyInfo = pKeyInfo;
4898949168
if( pKeyInfo ){
4899049169
u8 *aSortOrder;
48991
- memcpy(pKeyInfo, zP4, nByte);
49170
+ memcpy((char*)pKeyInfo, zP4, nByte - nField);
4899249171
aSortOrder = pKeyInfo->aSortOrder;
4899349172
if( aSortOrder ){
4899449173
pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
4899549174
memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
4899649175
}
@@ -53812,18 +53991,13 @@
5381253991
int i;
5381353992
sqlite_int64 rowid;
5381453993
Mem **apArg;
5381553994
Mem *pX;
5381653995
} ck;
53817
- struct OP_Pagecount_stack_vars {
53818
- int p1;
53819
- int nPage;
53820
- Pager *pPager;
53821
- } cl;
5382253996
struct OP_Trace_stack_vars {
5382353997
char *zTrace;
53824
- } cm;
53998
+ } cl;
5382553999
} u;
5382654000
/* End automatically generated code
5382754001
********************************************************************/
5382854002
5382954003
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
@@ -54646,11 +54820,11 @@
5464654820
assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
5464754821
u.ag.pArg = &aMem[pOp->p2];
5464854822
for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
5464954823
u.ag.apVal[u.ag.i] = u.ag.pArg;
5465054824
sqlite3VdbeMemStoreType(u.ag.pArg);
54651
- REGISTER_TRACE(pOp->p2, u.ag.pArg);
54825
+ REGISTER_TRACE(pOp->p2+u.ag.i, u.ag.pArg);
5465254826
}
5465354827
5465454828
assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
5465554829
if( pOp->p4type==P4_FUNCDEF ){
5465654830
u.ag.ctx.pFunc = pOp->p4.pFunc;
@@ -56363,14 +56537,14 @@
5636356537
5636456538
/* Opcode: OpenEphemeral P1 P2 * P4 *
5636556539
**
5636656540
** Open a new cursor P1 to a transient table.
5636756541
** The cursor is always opened read/write even if
56368
-** the main database is read-only. The transient or virtual
56542
+** the main database is read-only. The ephemeral
5636956543
** table is deleted automatically when the cursor is closed.
5637056544
**
56371
-** P2 is the number of columns in the virtual table.
56545
+** P2 is the number of columns in the ephemeral table.
5637256546
** The cursor points to a BTree table if P4==0 and to a BTree index
5637356547
** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
5637456548
** that defines the format of keys in the index.
5637556549
**
5637656550
** This opcode was once called OpenTemp. But that created
@@ -56377,10 +56551,18 @@
5637756551
** confusion because the term "temp table", might refer either
5637856552
** to a TEMP table at the SQL level, or to a table opened by
5637956553
** this opcode. Then this opcode was call OpenVirtual. But
5638056554
** that created confusion with the whole virtual-table idea.
5638156555
*/
56556
+/* Opcode: OpenAutoindex P1 P2 * P4 *
56557
+**
56558
+** This opcode works the same as OP_OpenEphemeral. It has a
56559
+** different name to distinguish its use. Tables created using
56560
+** by this opcode will be used for automatically created transient
56561
+** indices in joins.
56562
+*/
56563
+case OP_OpenAutoindex:
5638256564
case OP_OpenEphemeral: {
5638356565
#if 0 /* local variables moved into u.ax */
5638456566
VdbeCursor *pCx;
5638556567
#endif /* local variables moved into u.ax */
5638656568
static const int openFlags =
@@ -57515,29 +57697,35 @@
5751557697
pc = pOp->p2 - 1;
5751657698
}
5751757699
break;
5751857700
}
5751957701
57520
-/* Opcode: Next P1 P2 * * *
57702
+/* Opcode: Next P1 P2 * * P5
5752157703
**
5752257704
** Advance cursor P1 so that it points to the next key/data pair in its
5752357705
** table or index. If there are no more key/value pairs then fall through
5752457706
** to the following instruction. But if the cursor advance was successful,
5752557707
** jump immediately to P2.
5752657708
**
5752757709
** The P1 cursor must be for a real table, not a pseudo-table.
5752857710
**
57711
+** If P5 is positive and the jump is taken, then event counter
57712
+** number P5-1 in the prepared statement is incremented.
57713
+**
5752957714
** See also: Prev
5753057715
*/
57531
-/* Opcode: Prev P1 P2 * * *
57716
+/* Opcode: Prev P1 P2 * * P5
5753257717
**
5753357718
** Back up cursor P1 so that it points to the previous key/data pair in its
5753457719
** table or index. If there is no previous key/value pairs then fall through
5753557720
** to the following instruction. But if the cursor backup was successful,
5753657721
** jump immediately to P2.
5753757722
**
5753857723
** The P1 cursor must be for a real table, not a pseudo-table.
57724
+**
57725
+** If P5 is positive and the jump is taken, then event counter
57726
+** number P5-1 in the prepared statement is incremented.
5753957727
*/
5754057728
case OP_Prev: /* jump */
5754157729
case OP_Next: { /* jump */
5754257730
#if 0 /* local variables moved into u.bm */
5754357731
VdbeCursor *pC;
@@ -57545,10 +57733,11 @@
5754557733
int res;
5754657734
#endif /* local variables moved into u.bm */
5754757735
5754857736
CHECK_FOR_INTERRUPT;
5754957737
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
57738
+ assert( pOp->p5<=ArraySize(p->aCounter) );
5755057739
u.bm.pC = p->apCsr[pOp->p1];
5755157740
if( u.bm.pC==0 ){
5755257741
break; /* See ticket #2273 */
5755357742
}
5755457743
u.bm.pCrsr = u.bm.pC->pCursor;
@@ -58991,25 +59180,11 @@
5899159180
/* Opcode: Pagecount P1 P2 * * *
5899259181
**
5899359182
** Write the current number of pages in database P1 to memory cell P2.
5899459183
*/
5899559184
case OP_Pagecount: { /* out2-prerelease */
58996
-#if 0 /* local variables moved into u.cl */
58997
- int p1;
58998
- int nPage;
58999
- Pager *pPager;
59000
-#endif /* local variables moved into u.cl */
59001
-
59002
- u.cl.p1 = pOp->p1;
59003
- u.cl.pPager = sqlite3BtreePager(db->aDb[u.cl.p1].pBt);
59004
- rc = sqlite3PagerPagecount(u.cl.pPager, &u.cl.nPage);
59005
- /* OP_Pagecount is always called from within a read transaction. The
59006
- ** page count has already been successfully read and cached. So the
59007
- ** sqlite3PagerPagecount() call above cannot fail. */
59008
- if( ALWAYS(rc==SQLITE_OK) ){
59009
- pOut->u.i = u.cl.nPage;
59010
- }
59185
+ pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
5901159186
break;
5901259187
}
5901359188
#endif
5901459189
5901559190
#ifndef SQLITE_OMIT_TRACE
@@ -59017,24 +59192,24 @@
5901759192
**
5901859193
** If tracing is enabled (by the sqlite3_trace()) interface, then
5901959194
** the UTF-8 string contained in P4 is emitted on the trace callback.
5902059195
*/
5902159196
case OP_Trace: {
59022
-#if 0 /* local variables moved into u.cm */
59197
+#if 0 /* local variables moved into u.cl */
5902359198
char *zTrace;
59024
-#endif /* local variables moved into u.cm */
59199
+#endif /* local variables moved into u.cl */
5902559200
59026
- u.cm.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59027
- if( u.cm.zTrace ){
59201
+ u.cl.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59202
+ if( u.cl.zTrace ){
5902859203
if( db->xTrace ){
59029
- char *z = sqlite3VdbeExpandSql(p, u.cm.zTrace);
59204
+ char *z = sqlite3VdbeExpandSql(p, u.cl.zTrace);
5903059205
db->xTrace(db->pTraceArg, z);
5903159206
sqlite3DbFree(db, z);
5903259207
}
5903359208
#ifdef SQLITE_DEBUG
5903459209
if( (db->flags & SQLITE_SqlTrace)!=0 ){
59035
- sqlite3DebugPrintf("SQL-trace: %s\n", u.cm.zTrace);
59210
+ sqlite3DebugPrintf("SQL-trace: %s\n", u.cl.zTrace);
5903659211
}
5903759212
#endif /* SQLITE_DEBUG */
5903859213
}
5903959214
break;
5904059215
}
@@ -66537,16 +66712,20 @@
6653766712
int n = sqlite3_column_bytes(pStmt, 2);
6653866713
if( n>24 ){
6653966714
n = 24;
6654066715
}
6654166716
pSample->nByte = (u8)n;
66542
- pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66543
- if( pSample->u.z ){
66544
- memcpy(pSample->u.z, z, n);
66717
+ if( n < 1){
66718
+ pSample->u.z = 0;
6654566719
}else{
66546
- db->mallocFailed = 1;
66547
- break;
66720
+ pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66721
+ if( pSample->u.z ){
66722
+ memcpy(pSample->u.z, z, n);
66723
+ }else{
66724
+ db->mallocFailed = 1;
66725
+ break;
66726
+ }
6654866727
}
6654966728
}
6655066729
}
6655166730
}
6655266731
}
@@ -75790,11 +75969,11 @@
7579075969
}else{
7579175970
for(j=0; j<pColumn->nId; j++){
7579275971
if( pColumn->a[j].idx==i ) break;
7579375972
}
7579475973
}
75795
- if( pColumn && j>=pColumn->nId ){
75974
+ if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) ){
7579675975
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
7579775976
}else if( useTempTable ){
7579875977
sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1);
7579975978
}else{
7580075979
assert( pSelect==0 ); /* Otherwise useTempTable is true */
@@ -78086,10 +78265,13 @@
7808678265
{ "count_changes", SQLITE_CountRows },
7808778266
{ "empty_result_callbacks", SQLITE_NullCallback },
7808878267
{ "legacy_file_format", SQLITE_LegacyFileFmt },
7808978268
{ "fullfsync", SQLITE_FullFSync },
7809078269
{ "reverse_unordered_selects", SQLITE_ReverseOrder },
78270
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
78271
+ { "automatic_index", SQLITE_AutoIndex },
78272
+#endif
7809178273
#ifdef SQLITE_DEBUG
7809278274
{ "sql_trace", SQLITE_SqlTrace },
7809378275
{ "vdbe_listing", SQLITE_VdbeListing },
7809478276
{ "vdbe_trace", SQLITE_VdbeTrace },
7809578277
#endif
@@ -79967,10 +80149,11 @@
7996780149
}
7996880150
7996980151
sqlite3VtabUnlockList(db);
7997080152
7997180153
pParse->db = db;
80154
+ pParse->nQueryLoop = (double)1;
7997280155
if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
7997380156
char *zSqlCopy;
7997480157
int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
7997580158
testcase( nBytes==mxLen );
7997680159
testcase( nBytes==mxLen+1 );
@@ -79988,10 +80171,11 @@
7998880171
pParse->zTail = &zSql[nBytes];
7998980172
}
7999080173
}else{
7999180174
sqlite3RunParser(pParse, zSql, &zErrMsg);
7999280175
}
80176
+ assert( 1==(int)pParse->nQueryLoop );
7999380177
7999480178
if( db->mallocFailed ){
7999580179
pParse->rc = SQLITE_NOMEM;
7999680180
}
7999780181
if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
@@ -83744,10 +83928,22 @@
8374483928
if( addrNext ){
8374583929
sqlite3VdbeResolveLabel(v, addrNext);
8374683930
sqlite3ExprCacheClear(pParse);
8374783931
}
8374883932
}
83933
+
83934
+ /* Before populating the accumulator registers, clear the column cache.
83935
+ ** Otherwise, if any of the required column values are already present
83936
+ ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
83937
+ ** to pC->iMem. But by the time the value is used, the original register
83938
+ ** may have been used, invalidating the underlying buffer holding the
83939
+ ** text or blob value. See ticket [883034dcb5].
83940
+ **
83941
+ ** Another solution would be to change the OP_SCopy used to copy cached
83942
+ ** values to an OP_Copy.
83943
+ */
83944
+ sqlite3ExprCacheClear(pParse);
8374983945
for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
8375083946
sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
8375183947
}
8375283948
pAggInfo->directMode = 0;
8375383949
sqlite3ExprCacheClear(pParse);
@@ -85557,10 +85753,11 @@
8555785753
pSubParse->db = db;
8555885754
pSubParse->pTriggerTab = pTab;
8555985755
pSubParse->pToplevel = pTop;
8556085756
pSubParse->zAuthContext = pTrigger->zName;
8556185757
pSubParse->eTriggerOp = pTrigger->op;
85758
+ pSubParse->nQueryLoop = pParse->nQueryLoop;
8556285759
8556385760
v = sqlite3GetVdbe(pSubParse);
8556485761
if( v ){
8556585762
VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
8556685763
pTrigger->zName, onErrorText(orconf),
@@ -87477,10 +87674,11 @@
8747787674
if( pParse==0 ){
8747887675
rc = SQLITE_NOMEM;
8747987676
}else{
8748087677
pParse->declareVtab = 1;
8748187678
pParse->db = db;
87679
+ pParse->nQueryLoop = 1;
8748287680
8748387681
if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
8748487682
&& pParse->pNewTable
8748587683
&& !db->mallocFailed
8748687684
&& !pParse->pNewTable->pSelect
@@ -87997,19 +88195,21 @@
8799788195
#define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
8799888196
#define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
8799988197
#define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
8800088198
#define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
8800188199
#define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
88200
+#define WHERE_NOT_FULLSCAN 0x000f3000 /* Does not do a full table scan */
8800288201
#define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
8800388202
#define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
8800488203
#define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
8800588204
#define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
8800688205
#define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
8800788206
#define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
8800888207
#define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
8800988208
#define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
8801088209
#define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
88210
+#define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
8801188211
8801288212
/*
8801388213
** Initialize a preallocated WhereClause structure.
8801488214
*/
8801588215
static void whereClauseInit(
@@ -89397,10 +89597,238 @@
8939789597
}
8939889598
}
8939989599
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
8940089600
}
8940189601
89602
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89603
+/*
89604
+** Return TRUE if the WHERE clause term pTerm is of a form where it
89605
+** could be used with an index to access pSrc, assuming an appropriate
89606
+** index existed.
89607
+*/
89608
+static int termCanDriveIndex(
89609
+ WhereTerm *pTerm, /* WHERE clause term to check */
89610
+ struct SrcList_item *pSrc, /* Table we are trying to access */
89611
+ Bitmask notReady /* Tables in outer loops of the join */
89612
+){
89613
+ char aff;
89614
+ if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
89615
+ if( pTerm->eOperator!=WO_EQ ) return 0;
89616
+ if( (pTerm->prereqRight & notReady)!=0 ) return 0;
89617
+ aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
89618
+ if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
89619
+ return 1;
89620
+}
89621
+#endif
89622
+
89623
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89624
+/*
89625
+** If the query plan for pSrc specified in pCost is a full table scan
89626
+** and indexing is allows (if there is no NOT INDEXED clause) and it
89627
+** possible to construct a transient index that would perform better
89628
+** than a full table scan even when the cost of constructing the index
89629
+** is taken into account, then alter the query plan to use the
89630
+** transient index.
89631
+*/
89632
+static void bestAutomaticIndex(
89633
+ Parse *pParse, /* The parsing context */
89634
+ WhereClause *pWC, /* The WHERE clause */
89635
+ struct SrcList_item *pSrc, /* The FROM clause term to search */
89636
+ Bitmask notReady, /* Mask of cursors that are not available */
89637
+ WhereCost *pCost /* Lowest cost query plan */
89638
+){
89639
+ double nTableRow; /* Rows in the input table */
89640
+ double logN; /* log(nTableRow) */
89641
+ double costTempIdx; /* per-query cost of the transient index */
89642
+ WhereTerm *pTerm; /* A single term of the WHERE clause */
89643
+ WhereTerm *pWCEnd; /* End of pWC->a[] */
89644
+ Table *pTable; /* Table tht might be indexed */
89645
+
89646
+ if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
89647
+ /* Automatic indices are disabled at run-time */
89648
+ return;
89649
+ }
89650
+ if( (pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)!=0 ){
89651
+ /* We already have some kind of index in use for this query. */
89652
+ return;
89653
+ }
89654
+ if( pSrc->notIndexed ){
89655
+ /* The NOT INDEXED clause appears in the SQL. */
89656
+ return;
89657
+ }
89658
+
89659
+ assert( pParse->nQueryLoop >= (double)1 );
89660
+ nTableRow = pSrc->pIndex ? pSrc->pIndex->aiRowEst[0] : 1000000;
89661
+ logN = estLog(nTableRow);
89662
+ costTempIdx = 2*logN*(nTableRow/pParse->nQueryLoop + 1);
89663
+ if( costTempIdx>=pCost->rCost ){
89664
+ /* The cost of creating the transient table would be greater than
89665
+ ** doing the full table scan */
89666
+ return;
89667
+ }
89668
+
89669
+ /* Search for any equality comparison term */
89670
+ pTable = pSrc->pTab;
89671
+ pWCEnd = &pWC->a[pWC->nTerm];
89672
+ for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89673
+ if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89674
+ WHERETRACE(("auto-index reduces cost from %.2f to %.2f\n",
89675
+ pCost->rCost, costTempIdx));
89676
+ pCost->rCost = costTempIdx;
89677
+ pCost->nRow = logN + 1;
89678
+ pCost->plan.wsFlags = WHERE_TEMP_INDEX;
89679
+ pCost->used = pTerm->prereqRight;
89680
+ break;
89681
+ }
89682
+ }
89683
+}
89684
+#else
89685
+# define bestAutomaticIndex(A,B,C,D,E) /* no-op */
89686
+#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89687
+
89688
+
89689
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89690
+/*
89691
+** Generate code to construct the Index object for an automatic index
89692
+** and to set up the WhereLevel object pLevel so that the code generator
89693
+** makes use of the automatic index.
89694
+*/
89695
+static void constructAutomaticIndex(
89696
+ Parse *pParse, /* The parsing context */
89697
+ WhereClause *pWC, /* The WHERE clause */
89698
+ struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
89699
+ Bitmask notReady, /* Mask of cursors that are not available */
89700
+ WhereLevel *pLevel /* Write new index here */
89701
+){
89702
+ int nColumn; /* Number of columns in the constructed index */
89703
+ WhereTerm *pTerm; /* A single term of the WHERE clause */
89704
+ WhereTerm *pWCEnd; /* End of pWC->a[] */
89705
+ int nByte; /* Byte of memory needed for pIdx */
89706
+ Index *pIdx; /* Object describing the transient index */
89707
+ Vdbe *v; /* Prepared statement under construction */
89708
+ int regIsInit; /* Register set by initialization */
89709
+ int addrInit; /* Address of the initialization bypass jump */
89710
+ Table *pTable; /* The table being indexed */
89711
+ KeyInfo *pKeyinfo; /* Key information for the index */
89712
+ int addrTop; /* Top of the index fill loop */
89713
+ int regRecord; /* Register holding an index record */
89714
+ int n; /* Column counter */
89715
+ int i; /* Loop counter */
89716
+ int mxBitCol; /* Maximum column in pSrc->colUsed */
89717
+ CollSeq *pColl; /* Collating sequence to on a column */
89718
+ Bitmask idxCols; /* Bitmap of columns used for indexing */
89719
+ Bitmask extraCols; /* Bitmap of additional columns */
89720
+
89721
+ /* Generate code to skip over the creation and initialization of the
89722
+ ** transient index on 2nd and subsequent iterations of the loop. */
89723
+ v = pParse->pVdbe;
89724
+ assert( v!=0 );
89725
+ regIsInit = ++pParse->nMem;
89726
+ addrInit = sqlite3VdbeAddOp1(v, OP_If, regIsInit);
89727
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, regIsInit);
89728
+
89729
+ /* Count the number of columns that will be added to the index
89730
+ ** and used to match WHERE clause constraints */
89731
+ nColumn = 0;
89732
+ pTable = pSrc->pTab;
89733
+ pWCEnd = &pWC->a[pWC->nTerm];
89734
+ idxCols = 0;
89735
+ for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89736
+ if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89737
+ int iCol = pTerm->u.leftColumn;
89738
+ if( iCol<BMS && iCol>=0 ) idxCols |= 1<<iCol;
89739
+ nColumn++;
89740
+ }
89741
+ }
89742
+ assert( nColumn>0 );
89743
+ pLevel->plan.nEq = nColumn;
89744
+
89745
+ /* Count the number of additional columns needed to create a
89746
+ ** covering index. A "covering index" is an index that contains all
89747
+ ** columns that are needed by the query. With a covering index, the
89748
+ ** original table never needs to be accessed. Automatic indices must
89749
+ ** be a covering index because the index will not be updated if the
89750
+ ** original table changes and the index and table cannot both be used
89751
+ ** if they go out of sync.
89752
+ */
89753
+ extraCols = pSrc->colUsed & ~idxCols;
89754
+ mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
89755
+ for(i=0; i<mxBitCol; i++){
89756
+ if( extraCols & (1<<i) ) nColumn++;
89757
+ }
89758
+ if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89759
+ nColumn += pTable->nCol - BMS + 1;
89760
+ }
89761
+ pLevel->plan.wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WO_EQ;
89762
+
89763
+ /* Construct the Index object to describe this index */
89764
+ nByte = sizeof(Index);
89765
+ nByte += nColumn*sizeof(int); /* Index.aiColumn */
89766
+ nByte += nColumn*sizeof(char*); /* Index.azColl */
89767
+ nByte += nColumn; /* Index.aSortOrder */
89768
+ pIdx = sqlite3DbMallocZero(pParse->db, nByte);
89769
+ if( pIdx==0 ) return;
89770
+ pLevel->plan.u.pIdx = pIdx;
89771
+ pIdx->azColl = (char**)&pIdx[1];
89772
+ pIdx->aiColumn = (int*)&pIdx->azColl[nColumn];
89773
+ pIdx->aSortOrder = (u8*)&pIdx->aiColumn[nColumn];
89774
+ pIdx->zName = "auto-index";
89775
+ pIdx->nColumn = nColumn;
89776
+ pIdx->pTable = pTable;
89777
+ n = 0;
89778
+ for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89779
+ if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89780
+ Expr *pX = pTerm->pExpr;
89781
+ pIdx->aiColumn[n] = pTerm->u.leftColumn;
89782
+ pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
89783
+ pIdx->azColl[n] = pColl->zName;
89784
+ n++;
89785
+ }
89786
+ }
89787
+ assert( n==pLevel->plan.nEq );
89788
+
89789
+ /* Add additional columns needed to make the automatic index into
89790
+ ** a covering index */
89791
+ for(i=0; i<mxBitCol; i++){
89792
+ if( extraCols & (1<<i) ){
89793
+ pIdx->aiColumn[n] = i;
89794
+ pIdx->azColl[n] = "BINARY";
89795
+ n++;
89796
+ }
89797
+ }
89798
+ if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89799
+ for(i=BMS-1; i<pTable->nCol; i++){
89800
+ pIdx->aiColumn[n] = i;
89801
+ pIdx->azColl[n] = "BINARY";
89802
+ n++;
89803
+ }
89804
+ }
89805
+ assert( n==nColumn );
89806
+
89807
+ /* Create the automatic index */
89808
+ pKeyinfo = sqlite3IndexKeyinfo(pParse, pIdx);
89809
+ assert( pLevel->iIdxCur>=0 );
89810
+ sqlite3VdbeAddOp4(v, OP_OpenAutoindex, pLevel->iIdxCur, nColumn+1, 0,
89811
+ (char*)pKeyinfo, P4_KEYINFO_HANDOFF);
89812
+ VdbeComment((v, "for %s", pTable->zName));
89813
+
89814
+ /* Fill the automatic index with content */
89815
+ addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
89816
+ regRecord = sqlite3GetTempReg(pParse);
89817
+ sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 1);
89818
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
89819
+ sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
89820
+ sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
89821
+ sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
89822
+ sqlite3VdbeJumpHere(v, addrTop);
89823
+ sqlite3ReleaseTempReg(pParse, regRecord);
89824
+
89825
+ /* Jump here when skipping the initialization */
89826
+ sqlite3VdbeJumpHere(v, addrInit);
89827
+}
89828
+#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89829
+
8940289830
#ifndef SQLITE_OMIT_VIRTUALTABLE
8940389831
/*
8940489832
** Allocate and populate an sqlite3_index_info structure. It is the
8940589833
** responsibility of the caller to eventually release the structure
8940689834
** by passing the pointer returned by this function to sqlite3_free().
@@ -89581,10 +90009,11 @@
8958190009
struct sqlite3_index_constraint *pIdxCons;
8958290010
struct sqlite3_index_constraint_usage *pUsage;
8958390011
WhereTerm *pTerm;
8958490012
int i, j;
8958590013
int nOrderBy;
90014
+ double rCost;
8958690015
8958790016
/* Make sure wsFlags is initialized to some sane value. Otherwise, if the
8958890017
** malloc in allocateIndexInfo() fails and this function returns leaving
8958990018
** wsFlags in an uninitialized state, the caller may behave unpredictably.
8959090019
*/
@@ -89666,22 +90095,31 @@
8966690095
for(i=0; i<pIdxInfo->nConstraint; i++){
8966790096
if( pUsage[i].argvIndex>0 ){
8966890097
pCost->used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight;
8966990098
}
8967090099
}
90100
+
90101
+ /* If there is an ORDER BY clause, and the selected virtual table index
90102
+ ** does not satisfy it, increase the cost of the scan accordingly. This
90103
+ ** matches the processing for non-virtual tables in bestBtreeIndex().
90104
+ */
90105
+ rCost = pIdxInfo->estimatedCost;
90106
+ if( pOrderBy && pIdxInfo->orderByConsumed==0 ){
90107
+ rCost += estLog(rCost)*rCost;
90108
+ }
8967190109
8967290110
/* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
8967390111
** inital value of lowestCost in this loop. If it is, then the
8967490112
** (cost<lowestCost) test below will never be true.
8967590113
**
8967690114
** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT
8967790115
** is defined.
8967890116
*/
89679
- if( (SQLITE_BIG_DBL/((double)2))<pIdxInfo->estimatedCost ){
90117
+ if( (SQLITE_BIG_DBL/((double)2))<rCost ){
8968090118
pCost->rCost = (SQLITE_BIG_DBL/((double)2));
8968190119
}else{
89682
- pCost->rCost = pIdxInfo->estimatedCost;
90120
+ pCost->rCost = rCost;
8968390121
}
8968490122
pCost->plan.u.pVtabIdx = pIdxInfo;
8968590123
if( pIdxInfo->orderByConsumed ){
8968690124
pCost->plan.wsFlags |= WHERE_ORDERBY;
8968790125
}
@@ -90175,11 +90613,11 @@
9017590613
}
9017690614
}
9017790615
9017890616
/* If currently calculating the cost of using an index (not the IPK
9017990617
** index), determine if all required column data may be obtained without
90180
- ** seeking to entries in the main table (i.e. if the index is a covering
90618
+ ** using the main table (i.e. if the index is a covering
9018190619
** index for this query). If it is, set the WHERE_IDX_ONLY flag in
9018290620
** wsFlags. Otherwise, set the bLookup variable to true. */
9018390621
if( pIdx && wsFlags ){
9018490622
Bitmask m = pSrc->colUsed;
9018590623
int j;
@@ -90233,14 +90671,14 @@
9023390671
cost /= (double)2;
9023490672
}
9023590673
/**** Cost of using this index has now been computed ****/
9023690674
9023790675
WHERETRACE((
90238
- "tbl=%s idx=%s nEq=%d nInMul=%d nBound=%d bSort=%d bLookup=%d"
90239
- " wsFlags=%d (nRow=%.2f cost=%.2f)\n",
90676
+ "%s(%s): nEq=%d nInMul=%d nBound=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
90677
+ " notReady=0x%llx nRow=%.2f cost=%.2f used=0x%llx\n",
9024090678
pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
90241
- nEq, nInMul, nBound, bSort, bLookup, wsFlags, nRow, cost
90679
+ nEq, nInMul, nBound, bSort, bLookup, wsFlags, notReady, nRow, cost, used
9024290680
));
9024390681
9024490682
/* If this index is the best we have seen so far, then record this
9024590683
** index and its cost in the pCost structure.
9024690684
*/
@@ -90281,10 +90719,11 @@
9028190719
WHERETRACE(("best index is: %s\n",
9028290720
(pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
9028390721
));
9028490722
9028590723
bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
90724
+ bestAutomaticIndex(pParse, pWC, pSrc, notReady, pCost);
9028690725
pCost->plan.wsFlags |= eqTermMask;
9028790726
}
9028890727
9028990728
/*
9029090729
** Find the query plan for accessing table pSrc->pTab. Write the
@@ -90750,11 +91189,15 @@
9075091189
}
9075191190
start = sqlite3VdbeCurrentAddr(v);
9075291191
pLevel->op = bRev ? OP_Prev : OP_Next;
9075391192
pLevel->p1 = iCur;
9075491193
pLevel->p2 = start;
90755
- pLevel->p5 = (pStart==0 && pEnd==0) ?1:0;
91194
+ if( pStart==0 && pEnd==0 ){
91195
+ pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
91196
+ }else{
91197
+ assert( pLevel->p5==0 );
91198
+ }
9075691199
if( testOp!=OP_Noop ){
9075791200
iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
9075891201
sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
9075991202
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
9076091203
sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
@@ -91219,10 +91662,17 @@
9121991662
if( pInfo->needToFreeIdxStr ){
9122091663
sqlite3_free(pInfo->idxStr);
9122191664
}
9122291665
sqlite3DbFree(db, pInfo);
9122391666
}
91667
+ if( pWInfo->a[i].plan.wsFlags & WHERE_TEMP_INDEX ){
91668
+ Index *pIdx = pWInfo->a[i].plan.u.pIdx;
91669
+ if( pIdx ){
91670
+ sqlite3DbFree(db, pIdx->zColAff);
91671
+ sqlite3DbFree(db, pIdx);
91672
+ }
91673
+ }
9122491674
}
9122591675
whereClauseClear(pWInfo->pWC);
9122691676
sqlite3DbFree(db, pWInfo);
9122791677
}
9122891678
}
@@ -91365,18 +91815,21 @@
9136591815
nByteWInfo +
9136691816
sizeof(WhereClause) +
9136791817
sizeof(WhereMaskSet)
9136891818
);
9136991819
if( db->mallocFailed ){
91820
+ sqlite3DbFree(db, pWInfo);
91821
+ pWInfo = 0;
9137091822
goto whereBeginError;
9137191823
}
9137291824
pWInfo->nLevel = nTabList;
9137391825
pWInfo->pParse = pParse;
9137491826
pWInfo->pTabList = pTabList;
9137591827
pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
9137691828
pWInfo->pWC = pWC = (WhereClause *)&((u8 *)pWInfo)[nByteWInfo];
9137791829
pWInfo->wctrlFlags = wctrlFlags;
91830
+ pWInfo->savedNQueryLoop = pParse->nQueryLoop;
9137891831
pMaskSet = (WhereMaskSet*)&pWC[1];
9137991832
9138091833
/* Split the WHERE clause into separate subexpressions where each
9138191834
** subexpression is separated by an AND operator.
9138291835
*/
@@ -91552,17 +92005,20 @@
9155292005
if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
9155392006
*ppOrderBy = 0;
9155492007
}
9155592008
andFlags &= bestPlan.plan.wsFlags;
9155692009
pLevel->plan = bestPlan.plan;
91557
- if( bestPlan.plan.wsFlags & WHERE_INDEXED ){
92010
+ testcase( bestPlan.plan.wsFlags & WHERE_INDEXED );
92011
+ testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX );
92012
+ if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){
9155892013
pLevel->iIdxCur = pParse->nTab++;
9155992014
}else{
9156092015
pLevel->iIdxCur = -1;
9156192016
}
9156292017
notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
9156392018
pLevel->iFrom = (u8)bestJ;
92019
+ if( bestPlan.nRow>=(double)1 ) pParse->nQueryLoop *= bestPlan.nRow;
9156492020
9156592021
/* Check that if the table scanned by this loop iteration had an
9156692022
** INDEXED BY clause attached to it, that the named index is being
9156792023
** used for the scan. If not, then query compilation has failed.
9156892024
** Return an error.
@@ -91605,10 +92061,11 @@
9160592061
9160692062
/* Open all tables in the pTabList and any indices selected for
9160792063
** searching those tables.
9160892064
*/
9160992065
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
92066
+ notReady = ~(Bitmask)0;
9161092067
for(i=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
9161192068
Table *pTab; /* Table to open */
9161292069
int iDb; /* Index of database containing table/index */
9161392070
9161492071
#ifndef SQLITE_OMIT_EXPLAIN
@@ -91617,11 +92074,13 @@
9161792074
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
9161892075
zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
9161992076
if( pItem->zAlias ){
9162092077
zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
9162192078
}
91622
- if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92079
+ if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92080
+ zMsg = sqlite3MAppendf(db, zMsg, "%s WITH AUTOMATIC INDEX", zMsg);
92081
+ }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
9162392082
zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
9162492083
zMsg, pLevel->plan.u.pIdx->zName);
9162592084
}else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
9162692085
zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
9162792086
}else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
@@ -91640,12 +92099,15 @@
9164092099
sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
9164192100
}
9164292101
#endif /* SQLITE_OMIT_EXPLAIN */
9164392102
pTabItem = &pTabList->a[pLevel->iFrom];
9164492103
pTab = pTabItem->pTab;
92104
+ pLevel->iTabCur = pTabItem->iCursor;
9164592105
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
91646
- if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
92106
+ if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
92107
+ /* Do nothing */
92108
+ }else
9164792109
#ifndef SQLITE_OMIT_VIRTUALTABLE
9164892110
if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
9164992111
const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
9165092112
int iCur = pTabItem->iCursor;
9165192113
sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
@@ -91664,11 +92126,15 @@
9166492126
assert( n<=pTab->nCol );
9166592127
}
9166692128
}else{
9166792129
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
9166892130
}
91669
- pLevel->iTabCur = pTabItem->iCursor;
92131
+#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
92132
+ if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92133
+ constructAutomaticIndex(pParse, pWC, pTabItem, notReady, pLevel);
92134
+ }else
92135
+#endif
9167092136
if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
9167192137
Index *pIx = pLevel->plan.u.pIdx;
9167292138
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
9167392139
int iIdxCur = pLevel->iIdxCur;
9167492140
assert( pIx->pSchema==pTab->pSchema );
@@ -91676,12 +92142,14 @@
9167692142
sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
9167792143
(char*)pKey, P4_KEYINFO_HANDOFF);
9167892144
VdbeComment((v, "%s", pIx->zName));
9167992145
}
9168092146
sqlite3CodeVerifySchema(pParse, iDb);
92147
+ notReady &= ~getMask(pWC->pMaskSet, pTabItem->iCursor);
9168192148
}
9168292149
pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
92150
+ if( db->mallocFailed ) goto whereBeginError;
9168392151
9168492152
/* Generate the code to do the search. Each iteration of the for
9168592153
** loop below generates code for a single nested loop of the VM
9168692154
** program.
9168792155
*/
@@ -91745,11 +92213,14 @@
9174592213
*/
9174692214
return pWInfo;
9174792215
9174892216
/* Jump here if malloc fails */
9174992217
whereBeginError:
91750
- whereInfoFree(db, pWInfo);
92218
+ if( pWInfo ){
92219
+ pParse->nQueryLoop = pWInfo->savedNQueryLoop;
92220
+ whereInfoFree(db, pWInfo);
92221
+ }
9175192222
return 0;
9175292223
}
9175392224
9175492225
/*
9175592226
** Generate the end of the WHERE loop. See comments on
@@ -91815,16 +92286,19 @@
9181592286
assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
9181692287
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
9181792288
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
9181892289
Table *pTab = pTabItem->pTab;
9181992290
assert( pTab!=0 );
91820
- if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
91821
- if( (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0 ){
91822
- if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
92291
+ if( (pTab->tabFlags & TF_Ephemeral)==0
92292
+ && pTab->pSelect==0
92293
+ && (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0
92294
+ ){
92295
+ int ws = pLevel->plan.wsFlags;
92296
+ if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
9182392297
sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
9182492298
}
91825
- if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92299
+ if( (ws & (WHERE_INDEXED|WHERE_TEMP_INDEX)) == WHERE_INDEXED ){
9182692300
sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
9182792301
}
9182892302
}
9182992303
9183092304
/* If this scan uses an index, make code substitutions to read data
@@ -91868,11 +92342,14 @@
9186892342
}
9186992343
}
9187092344
9187192345
/* Final cleanup
9187292346
*/
91873
- whereInfoFree(db, pWInfo);
92347
+ if( pWInfo ){
92348
+ pParse->nQueryLoop = pWInfo->savedNQueryLoop;
92349
+ whereInfoFree(db, pWInfo);
92350
+ }
9187492351
return;
9187592352
}
9187692353
9187792354
/************** End of where.c ***********************************************/
9187892355
/************** Begin file parse.c *******************************************/
@@ -98071,11 +98548,11 @@
9807198548
assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
9807298549
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
9807398550
db->autoCommit = 1;
9807498551
db->nextAutovac = -1;
9807598552
db->nextPagesize = 0;
98076
- db->flags |= SQLITE_ShortColNames
98553
+ db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
9807798554
#if SQLITE_DEFAULT_FILE_FORMAT<4
9807898555
| SQLITE_LegacyFileFmt
9807998556
#endif
9808098557
#ifdef SQLITE_ENABLE_LOAD_EXTENSION
9808198558
| SQLITE_LoadExtension
@@ -99199,11 +99676,11 @@
9919999676
** and so on.
9920099677
**
9920199678
** This is similar in concept to how sqlite encodes "varints" but
9920299679
** the encoding is not the same. SQLite varints are big-endian
9920399680
** are are limited to 9 bytes in length whereas FTS3 varints are
99204
-** little-endian and can be upt to 10 bytes in length (in theory).
99681
+** little-endian and can be up to 10 bytes in length (in theory).
9920599682
**
9920699683
** Example encodings:
9920799684
**
9920899685
** 1: 0x01
9920999686
** 127: 0x7f
@@ -99210,30 +99687,30 @@
9921099687
** 128: 0x81 0x00
9921199688
**
9921299689
**
9921399690
**** Document lists ****
9921499691
** A doclist (document list) holds a docid-sorted list of hits for a
99215
-** given term. Doclists hold docids, and can optionally associate
99216
-** token positions and offsets with docids. A position is the index
99217
-** of a word within the document. The first word of the document has
99218
-** a position of 0.
99692
+** given term. Doclists hold docids and associated token positions.
99693
+** A docid is the unique integer identifier for a single document.
99694
+** A position is the index of a word within the document. The first
99695
+** word of the document has a position of 0.
9921999696
**
9922099697
** FTS3 used to optionally store character offsets using a compile-time
9922199698
** option. But that functionality is no longer supported.
9922299699
**
99223
-** A DL_POSITIONS_OFFSETS doclist is stored like this:
99700
+** A doclist is stored like this:
9922499701
**
9922599702
** array {
9922699703
** varint docid;
9922799704
** array { (position list for column 0)
99228
-** varint position; (delta from previous position plus POS_BASE)
99705
+** varint position; (2 more than the delta from previous position)
9922999706
** }
9923099707
** array {
9923199708
** varint POS_COLUMN; (marks start of position list for new column)
9923299709
** varint column; (index of new column)
9923399710
** array {
99234
-** varint position; (delta from previous position plus POS_BASE)
99711
+** varint position; (2 more than the delta from previous position)
9923599712
** }
9923699713
** }
9923799714
** varint POS_END; (marks end of positions for this document.
9923899715
** }
9923999716
**
@@ -99241,11 +99718,11 @@
9924199718
** memory. A "position" is an index of a token in the token stream
9924299719
** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
9924399720
** in the same logical place as the position element, and act as sentinals
9924499721
** ending a position list array. POS_END is 0. POS_COLUMN is 1.
9924599722
** The positions numbers are not stored literally but rather as two more
99246
-** the difference from the prior position, or the just the position plus
99723
+** than the difference from the prior position, or the just the position plus
9924799724
** 2 for the first position. Example:
9924899725
**
9924999726
** label: A B C D E F G H I J K
9925099727
** value: 123 5 9 1 1 14 35 0 234 72 0
9925199728
**
@@ -99255,18 +99732,18 @@
9925599732
** new column is column number 1. There are two positions at 12 and 45
9925699733
** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
9925799734
** 234 at I is the next docid. It has one position 72 (72-2) and then
9925899735
** terminates with the 0 at K.
9925999736
**
99260
-** A DL_POSITIONS doclist omits the startOffset and endOffset
99261
-** information. A DL_DOCIDS doclist omits both the position and
99262
-** offset information, becoming an array of varint-encoded docids.
99263
-**
99264
-** On-disk data is stored as type DL_DEFAULT, so we don't serialize
99265
-** the type. Due to how deletion is implemented in the segmentation
99266
-** system, on-disk doclists MUST store at least positions.
99267
-**
99737
+** A "position-list" is the list of positions for multiple columns for
99738
+** a single docid. A "column-list" is the set of positions for a single
99739
+** column. Hence, a position-list consists of one or more column-lists,
99740
+** a document record consists of a docid followed by a position-list and
99741
+** a doclist consists of one or more document records.
99742
+**
99743
+** A bare doclist omits the position information, becoming an
99744
+** array of varint-encoded docids.
9926899745
**
9926999746
**** Segment leaf nodes ****
9927099747
** Segment leaf nodes store terms and doclists, ordered by term. Leaf
9927199748
** nodes are written using LeafWriter, and read using LeafReader (to
9927299749
** iterate through a single leaf node's data) and LeavesReader (to
@@ -99776,10 +100253,24 @@
99776100253
** Maximum length of a varint encoded integer. The varint format is different
99777100254
** from that used by SQLite, so the maximum length is 10, not 9.
99778100255
*/
99779100256
#define FTS3_VARINT_MAX 10
99780100257
100258
+/*
100259
+** The testcase() macro is only used by the amalgamation. If undefined,
100260
+** make it a no-op.
100261
+*/
100262
+#ifndef testcase
100263
+# define testcase(X)
100264
+#endif
100265
+
100266
+/*
100267
+** Terminator values for position-lists and column-lists.
100268
+*/
100269
+#define POS_COLUMN (1) /* Column-list terminator */
100270
+#define POS_END (0) /* Position-list terminator */
100271
+
99781100272
/*
99782100273
** This section provides definitions to allow the
99783100274
** FTS3 extension to be compiled outside of the
99784100275
** amalgamation.
99785100276
*/
@@ -100087,12 +100578,11 @@
100087100578
*pi = (int) i;
100088100579
return ret;
100089100580
}
100090100581
100091100582
/*
100092
-** Return the number of bytes required to store the value passed as the
100093
-** first argument in varint form.
100583
+** Return the number of bytes required to encode v as a varint
100094100584
*/
100095100585
SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
100096100586
int i = 0;
100097100587
do{
100098100588
i++;
@@ -100139,11 +100629,11 @@
100139100629
}
100140100630
}
100141100631
100142100632
/*
100143100633
** Read a single varint from the doclist at *pp and advance *pp to point
100144
-** to the next element of the varlist. Add the value of the varint
100634
+** to the first byte past the end of the varint. Add the value of the varint
100145100635
** to *pVal.
100146100636
*/
100147100637
static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
100148100638
sqlite3_int64 iVal;
100149100639
*pp += sqlite3Fts3GetVarint(*pp, &iVal);
@@ -100195,11 +100685,11 @@
100195100685
** and then evaluate those statements. The success code is writting
100196100686
** into *pRc.
100197100687
**
100198100688
** If *pRc is initially non-zero then this routine is a no-op.
100199100689
*/
100200
-void fts3DbExec(
100690
+static void fts3DbExec(
100201100691
int *pRc, /* Success code */
100202100692
sqlite3 *db, /* Database in which to run SQL */
100203100693
const char *zFormat, /* Format string for SQL */
100204100694
... /* Arguments to the format string */
100205100695
){
@@ -100275,10 +100765,14 @@
100275100765
100276100766
/*
100277100767
** Create the backing store tables (%_content, %_segments and %_segdir)
100278100768
** required by the FTS3 table passed as the only argument. This is done
100279100769
** as part of the vtab xCreate() method.
100770
+**
100771
+** If the p->bHasDocsize boolean is true (indicating that this is an
100772
+** FTS4 table, not an FTS3 table) then also create the %_docsize and
100773
+** %_stat tables required by FTS4.
100280100774
*/
100281100775
static int fts3CreateTables(Fts3Table *p){
100282100776
int rc = SQLITE_OK; /* Return code */
100283100777
int i; /* Iterator variable */
100284100778
char *zContentCols; /* Columns of %_content table */
@@ -100367,11 +100861,11 @@
100367100861
** This function is the implementation of both the xConnect and xCreate
100368100862
** methods of the FTS3 virtual table.
100369100863
**
100370100864
** The argv[] array contains the following:
100371100865
**
100372
-** argv[0] -> module name
100866
+** argv[0] -> module name ("fts3" or "fts4")
100373100867
** argv[1] -> database name
100374100868
** argv[2] -> table name
100375100869
** argv[...] -> "column name" and other module argument fields.
100376100870
*/
100377100871
static int fts3InitVtab(
@@ -100386,16 +100880,16 @@
100386100880
Fts3Hash *pHash = (Fts3Hash *)pAux;
100387100881
Fts3Table *p; /* Pointer to allocated vtab */
100388100882
int rc; /* Return code */
100389100883
int i; /* Iterator variable */
100390100884
int nByte; /* Size of allocation used for *p */
100391
- int iCol;
100392
- int nString = 0;
100393
- int nCol = 0;
100394
- char *zCsr;
100395
- int nDb;
100396
- int nName;
100885
+ int iCol; /* Column index */
100886
+ int nString = 0; /* Bytes required to hold all column names */
100887
+ int nCol = 0; /* Number of columns in the FTS table */
100888
+ char *zCsr; /* Space for holding column names */
100889
+ int nDb; /* Bytes required to hold database name */
100890
+ int nName; /* Bytes required to hold table name */
100397100891
100398100892
const char *zTokenizer = 0; /* Name of tokenizer to use */
100399100893
sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
100400100894
100401100895
nDb = (int)strlen(argv[1]) + 1;
@@ -100621,10 +101115,15 @@
100621101115
sqlite3_free(pCsr->aMatchinfo);
100622101116
sqlite3_free(pCsr);
100623101117
return SQLITE_OK;
100624101118
}
100625101119
101120
+/*
101121
+** Position the pCsr->pStmt statement so that it is on the row
101122
+** of the %_content table that contains the last match. Return
101123
+** SQLITE_OK on success.
101124
+*/
100626101125
static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
100627101126
if( pCsr->isRequireSeek ){
100628101127
pCsr->isRequireSeek = 0;
100629101128
sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
100630101129
if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
@@ -100647,10 +101146,21 @@
100647101146
}else{
100648101147
return SQLITE_OK;
100649101148
}
100650101149
}
100651101150
101151
+/*
101152
+** Advance the cursor to the next row in the %_content table that
101153
+** matches the search criteria. For a MATCH search, this will be
101154
+** the next row that matches. For a full-table scan, this will be
101155
+** simply the next row in the %_content table. For a docid lookup,
101156
+** this routine simply sets the EOF flag.
101157
+**
101158
+** Return SQLITE_OK if nothing goes wrong. SQLITE_OK is returned
101159
+** even if we reach end-of-file. The fts3EofMethod() will be called
101160
+** subsequently to determine whether or not an EOF was hit.
101161
+*/
100652101162
static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
100653101163
int rc = SQLITE_OK; /* Return code */
100654101164
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
100655101165
100656101166
if( pCsr->aDoclist==0 ){
@@ -100782,10 +101292,15 @@
100782101292
100783101293
/*
100784101294
** When this function is called, *ppPoslist is assumed to point to the
100785101295
** start of a position-list. After it returns, *ppPoslist points to the
100786101296
** first byte after the position-list.
101297
+**
101298
+** A position list is list of positions (delta encoded) and columns for
101299
+** a single document record of a doclist. So, in other words, this
101300
+** routine advances *ppPoslist so that it points to the next docid in
101301
+** the doclist, or to the first byte past the end of the doclist.
100787101302
**
100788101303
** If pp is not NULL, then the contents of the position list are copied
100789101304
** to *pp. *pp is set to point to the first byte past the last byte copied
100790101305
** before this function returns.
100791101306
*/
@@ -100792,21 +101307,24 @@
100792101307
static void fts3PoslistCopy(char **pp, char **ppPoslist){
100793101308
char *pEnd = *ppPoslist;
100794101309
char c = 0;
100795101310
100796101311
/* The end of a position list is marked by a zero encoded as an FTS3
100797
- ** varint. A single 0x00 byte. Except, if the 0x00 byte is preceded by
101312
+ ** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
100798101313
** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
100799101314
** of some other, multi-byte, value.
100800101315
**
100801
- ** The following block moves pEnd to point to the first byte that is not
101316
+ ** The following while-loop moves pEnd to point to the first byte that is not
100802101317
** immediately preceded by a byte with the 0x80 bit set. Then increments
100803101318
** pEnd once more so that it points to the byte immediately following the
100804101319
** last byte in the position-list.
100805101320
*/
100806
- while( *pEnd | c ) c = *pEnd++ & 0x80;
100807
- pEnd++;
101321
+ while( *pEnd | c ){
101322
+ c = *pEnd++ & 0x80;
101323
+ testcase( c!=0 && (*pEnd)==0 );
101324
+ }
101325
+ pEnd++; /* Advance past the POS_END terminator byte */
100808101326
100809101327
if( pp ){
100810101328
int n = (int)(pEnd - *ppPoslist);
100811101329
char *p = *pp;
100812101330
memcpy(p, *ppPoslist, n);
@@ -100814,16 +101332,38 @@
100814101332
*pp = p;
100815101333
}
100816101334
*ppPoslist = pEnd;
100817101335
}
100818101336
101337
+/*
101338
+** When this function is called, *ppPoslist is assumed to point to the
101339
+** start of a column-list. After it returns, *ppPoslist points to the
101340
+** to the terminator (POS_COLUMN or POS_END) byte of the column-list.
101341
+**
101342
+** A column-list is list of delta-encoded positions for a single column
101343
+** within a single document within a doclist.
101344
+**
101345
+** The column-list is terminated either by a POS_COLUMN varint (1) or
101346
+** a POS_END varint (0). This routine leaves *ppPoslist pointing to
101347
+** the POS_COLUMN or POS_END that terminates the column-list.
101348
+**
101349
+** If pp is not NULL, then the contents of the column-list are copied
101350
+** to *pp. *pp is set to point to the first byte past the last byte copied
101351
+** before this function returns. The POS_COLUMN or POS_END terminator
101352
+** is not copied into *pp.
101353
+*/
100819101354
static void fts3ColumnlistCopy(char **pp, char **ppPoslist){
100820101355
char *pEnd = *ppPoslist;
100821101356
char c = 0;
100822101357
100823
- /* A column-list is terminated by either a 0x01 or 0x00. */
100824
- while( 0xFE & (*pEnd | c) ) c = *pEnd++ & 0x80;
101358
+ /* A column-list is terminated by either a 0x01 or 0x00 byte that is
101359
+ ** not part of a multi-byte varint.
101360
+ */
101361
+ while( 0xFE & (*pEnd | c) ){
101362
+ c = *pEnd++ & 0x80;
101363
+ testcase( c!=0 && ((*pEnd)&0xfe)==0 );
101364
+ }
100825101365
if( pp ){
100826101366
int n = (int)(pEnd - *ppPoslist);
100827101367
char *p = *pp;
100828101368
memcpy(p, *ppPoslist, n);
100829101369
p += n;
@@ -100831,41 +101371,49 @@
100831101371
}
100832101372
*ppPoslist = pEnd;
100833101373
}
100834101374
100835101375
/*
100836
-** Value used to signify the end of an offset-list. This is safe because
101376
+** Value used to signify the end of an position-list. This is safe because
100837101377
** it is not possible to have a document with 2^31 terms.
100838101378
*/
100839
-#define OFFSET_LIST_END 0x7fffffff
101379
+#define POSITION_LIST_END 0x7fffffff
100840101380
100841101381
/*
100842
-** This function is used to help parse offset-lists. When this function is
100843
-** called, *pp may point to the start of the next varint in the offset-list
100844
-** being parsed, or it may point to 1 byte past the end of the offset-list
100845
-** (in which case **pp will be 0x00 or 0x01).
101382
+** This function is used to help parse position-lists. When this function is
101383
+** called, *pp may point to the start of the next varint in the position-list
101384
+** being parsed, or it may point to 1 byte past the end of the position-list
101385
+** (in which case **pp will be a terminator bytes POS_END (0) or
101386
+** (1)).
100846101387
**
100847
-** If *pp points past the end of the current offset list, set *pi to
100848
-** OFFSET_LIST_END and return. Otherwise, read the next varint from *pp,
101388
+** If *pp points past the end of the current position-list, set *pi to
101389
+** POSITION_LIST_END and return. Otherwise, read the next varint from *pp,
100849101390
** increment the current value of *pi by the value read, and set *pp to
100850101391
** point to the next value before returning.
101392
+**
101393
+** Before calling this routine *pi must be initialized to the value of
101394
+** the previous position, or zero if we are reading the first position
101395
+** in the position-list. Because positions are delta-encoded, the value
101396
+** of the previous position is needed in order to compute the value of
101397
+** the next position.
100851101398
*/
100852101399
static void fts3ReadNextPos(
100853
- char **pp, /* IN/OUT: Pointer into offset-list buffer */
100854
- sqlite3_int64 *pi /* IN/OUT: Value read from offset-list */
101400
+ char **pp, /* IN/OUT: Pointer into position-list buffer */
101401
+ sqlite3_int64 *pi /* IN/OUT: Value read from position-list */
100855101402
){
100856
- if( **pp&0xFE ){
101403
+ if( (**pp)&0xFE ){
100857101404
fts3GetDeltaVarint(pp, pi);
100858101405
*pi -= 2;
100859101406
}else{
100860
- *pi = OFFSET_LIST_END;
101407
+ *pi = POSITION_LIST_END;
100861101408
}
100862101409
}
100863101410
100864101411
/*
100865
-** If parameter iCol is not 0, write an 0x01 byte followed by the value of
100866
-** iCol encoded as a varint to *pp.
101412
+** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
101413
+** the value of iCol encoded as a varint to *pp. This will start a new
101414
+** column list.
100867101415
**
100868101416
** Set *pp to point to the byte just after the last byte written before
100869101417
** returning (do not modify it if iCol==0). Return the total number of bytes
100870101418
** written (0 if iCol==0).
100871101419
*/
@@ -100879,11 +101427,15 @@
100879101427
}
100880101428
return n;
100881101429
}
100882101430
100883101431
/*
100884
-**
101432
+** Compute the union of two position lists. The output written
101433
+** into *pp contains all positions of both *pp1 and *pp2 in sorted
101434
+** order and with any duplicates removed. All pointers are
101435
+** updated appropriately. The caller is responsible for insuring
101436
+** that there is enough space in *pp to hold the complete output.
100885101437
*/
100886101438
static void fts3PoslistMerge(
100887101439
char **pp, /* Output buffer */
100888101440
char **pp1, /* Left input list */
100889101441
char **pp2 /* Right input list */
@@ -100891,36 +101443,37 @@
100891101443
char *p = *pp;
100892101444
char *p1 = *pp1;
100893101445
char *p2 = *pp2;
100894101446
100895101447
while( *p1 || *p2 ){
100896
- int iCol1;
100897
- int iCol2;
101448
+ int iCol1; /* The current column index in pp1 */
101449
+ int iCol2; /* The current column index in pp2 */
100898101450
100899
- if( *p1==0x01 ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
100900
- else if( *p1==0x00 ) iCol1 = OFFSET_LIST_END;
101451
+ if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
101452
+ else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
100901101453
else iCol1 = 0;
100902101454
100903
- if( *p2==0x01 ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
100904
- else if( *p2==0x00 ) iCol2 = OFFSET_LIST_END;
101455
+ if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
101456
+ else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
100905101457
else iCol2 = 0;
100906101458
100907101459
if( iCol1==iCol2 ){
100908
- sqlite3_int64 i1 = 0;
100909
- sqlite3_int64 i2 = 0;
101460
+ sqlite3_int64 i1 = 0; /* Last position from pp1 */
101461
+ sqlite3_int64 i2 = 0; /* Last position from pp2 */
100910101462
sqlite3_int64 iPrev = 0;
100911101463
int n = fts3PutColNumber(&p, iCol1);
100912101464
p1 += n;
100913101465
p2 += n;
100914101466
100915
- /* At this point, both p1 and p2 point to the start of offset-lists.
100916
- ** An offset-list is a list of non-negative delta-encoded varints, each
100917
- ** incremented by 2 before being stored. Each list is terminated by a 0
100918
- ** or 1 value (0x00 or 0x01). The following block merges the two lists
101467
+ /* At this point, both p1 and p2 point to the start of column-lists
101468
+ ** for the same column (the column with index iCol1 and iCol2).
101469
+ ** A column-list is a list of non-negative delta-encoded varints, each
101470
+ ** incremented by 2 before being stored. Each list is terminated by a
101471
+ ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
100919101472
** and writes the results to buffer p. p is left pointing to the byte
100920
- ** after the list written. No terminator (0x00 or 0x01) is written to
100921
- ** the output.
101473
+ ** after the list written. No terminator (POS_END or POS_COLUMN) is
101474
+ ** written to the output.
100922101475
*/
100923101476
fts3GetDeltaVarint(&p1, &i1);
100924101477
fts3GetDeltaVarint(&p2, &i2);
100925101478
do {
100926101479
fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
@@ -100931,21 +101484,21 @@
100931101484
}else if( i1<i2 ){
100932101485
fts3ReadNextPos(&p1, &i1);
100933101486
}else{
100934101487
fts3ReadNextPos(&p2, &i2);
100935101488
}
100936
- }while( i1!=OFFSET_LIST_END || i2!=OFFSET_LIST_END );
101489
+ }while( i1!=POSITION_LIST_END || i2!=POSITION_LIST_END );
100937101490
}else if( iCol1<iCol2 ){
100938101491
p1 += fts3PutColNumber(&p, iCol1);
100939101492
fts3ColumnlistCopy(&p, &p1);
100940101493
}else{
100941101494
p2 += fts3PutColNumber(&p, iCol2);
100942101495
fts3ColumnlistCopy(&p, &p2);
100943101496
}
100944101497
}
100945101498
100946
- *p++ = '\0';
101499
+ *p++ = POS_END;
100947101500
*pp = p;
100948101501
*pp1 = p1 + 1;
100949101502
*pp2 = p2 + 1;
100950101503
}
100951101504
@@ -100964,15 +101517,15 @@
100964101517
char *p2 = *pp2;
100965101518
100966101519
int iCol1 = 0;
100967101520
int iCol2 = 0;
100968101521
assert( *p1!=0 && *p2!=0 );
100969
- if( *p1==0x01 ){
101522
+ if( *p1==POS_COLUMN ){
100970101523
p1++;
100971101524
p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
100972101525
}
100973
- if( *p2==0x01 ){
101526
+ if( *p2==POS_COLUMN ){
100974101527
p2++;
100975101528
p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
100976101529
}
100977101530
100978101531
while( 1 ){
@@ -100981,15 +101534,16 @@
100981101534
sqlite3_int64 iPrev = 0;
100982101535
sqlite3_int64 iPos1 = 0;
100983101536
sqlite3_int64 iPos2 = 0;
100984101537
100985101538
if( pp && iCol1 ){
100986
- *p++ = 0x01;
101539
+ *p++ = POS_COLUMN;
100987101540
p += sqlite3Fts3PutVarint(p, iCol1);
100988101541
}
100989101542
100990
- assert( *p1!=0x00 && *p2!=0x00 && *p1!=0x01 && *p2!=0x01 );
101543
+ assert( *p1!=POS_END && *p1!=POS_COLUMN );
101544
+ assert( *p2!=POS_END && *p2!=POS_COLUMN );
100991101545
fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
100992101546
fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
100993101547
100994101548
while( 1 ){
100995101549
if( iPos2>iPos1 && iPos2<=iPos1+nToken ){
@@ -101237,10 +101791,11 @@
101237101791
}
101238101792
101239101793
default: assert( mergetype==MERGE_POS_NEAR || mergetype==MERGE_NEAR ); {
101240101794
char *aTmp = 0;
101241101795
char **ppPos = 0;
101796
+
101242101797
if( mergetype==MERGE_POS_NEAR ){
101243101798
ppPos = &p;
101244101799
aTmp = sqlite3_malloc(2*(n1+n2+1));
101245101800
if( !aTmp ){
101246101801
return SQLITE_NOMEM;
@@ -101341,13 +101896,13 @@
101341101896
** This function retreives the doclist for the specified term (or term
101342101897
** prefix) from the database.
101343101898
**
101344101899
** The returned doclist may be in one of two formats, depending on the
101345101900
** value of parameter isReqPos. If isReqPos is zero, then the doclist is
101346
-** a sorted list of delta-compressed docids. If isReqPos is non-zero,
101347
-** then the returned list is in the same format as is stored in the
101348
-** database without the found length specifier at the start of on-disk
101901
+** a sorted list of delta-compressed docids (a bare doclist). If isReqPos
101902
+** is non-zero, then the returned list is in the same format as is stored
101903
+** in the database without the found length specifier at the start of on-disk
101349101904
** doclists.
101350101905
*/
101351101906
static int fts3TermSelect(
101352101907
Fts3Table *p, /* Virtual table handle */
101353101908
int iColumn, /* Column to query (or -ve for all columns) */
@@ -101603,11 +102158,13 @@
101603102158
return rc;
101604102159
}
101605102160
101606102161
/*
101607102162
** Evaluate the full-text expression pExpr against fts3 table pTab. Store
101608
-** the resulting doclist in *paOut and *pnOut.
102163
+** the resulting doclist in *paOut and *pnOut. This routine mallocs for
102164
+** the space needed to store the output. The caller is responsible for
102165
+** freeing the space when it has finished.
101609102166
*/
101610102167
static int evalFts3Expr(
101611102168
Fts3Table *p, /* Virtual table handle */
101612102169
Fts3Expr *pExpr, /* Parsed fts3 expression */
101613102170
char **paOut, /* OUT: Pointer to malloc'd result buffer */
@@ -108163,11 +108720,11 @@
108163108720
** This is done as part of extracting the snippet text, not when selecting
108164108721
** the snippet. Snippet selection is done based on doclists only, so there
108165108722
** is no way for fts3BestSnippet() to know whether or not the document
108166108723
** actually contains terms that follow the final highlighted term.
108167108724
*/
108168
-int fts3SnippetShift(
108725
+static int fts3SnippetShift(
108169108726
Fts3Table *pTab, /* FTS3 table snippet comes from */
108170108727
int nSnippet, /* Number of tokens desired for snippet */
108171108728
const char *zDoc, /* Document text to extract snippet from */
108172108729
int nDoc, /* Size of buffer zDoc in bytes */
108173108730
int *piPos, /* IN/OUT: First token of snippet */
@@ -111280,10 +111837,11 @@
111280111837
rc = SQLITE_CONSTRAINT;
111281111838
goto constraint;
111282111839
}
111283111840
rc = sqlite3_reset(pRtree->pReadRowid);
111284111841
}
111842
+ *pRowid = cell.iRowid;
111285111843
111286111844
if( rc==SQLITE_OK ){
111287111845
rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
111288111846
}
111289111847
if( rc==SQLITE_OK ){
111290111848
--- 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.6.23.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one 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% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -321,11 +321,11 @@
321 ** to generate appropriate macros for a wide range of compilers.
322 **
323 ** The correct "ANSI" way to do this is to use the intptr_t type.
324 ** Unfortunately, that typedef is not available on all compilers, or
325 ** if it is available, it requires an #include of specific headers
326 ** that very from one machine to the next.
327 **
328 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
329 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
330 ** So we have to define the macros in different ways depending on the
331 ** compiler.
@@ -626,13 +626,13 @@
626 **
627 ** See also: [sqlite3_libversion()],
628 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
629 ** [sqlite_version()] and [sqlite_source_id()].
630 */
631 #define SQLITE_VERSION "3.6.23.1"
632 #define SQLITE_VERSION_NUMBER 3006023
633 #define SQLITE_SOURCE_ID "2010-03-26 22:28:06 ex-b078b588d617e07886ad156e9f54ade6d823568e"
634
635 /*
636 ** CAPI3REF: Run-Time Library Version Numbers
637 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
638 **
@@ -665,11 +665,10 @@
665 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
666 SQLITE_API const char *sqlite3_libversion(void);
667 SQLITE_API const char *sqlite3_sourceid(void);
668 SQLITE_API int sqlite3_libversion_number(void);
669
670 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
671 /*
672 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
673 **
674 ** ^The sqlite3_compileoption_used() function returns 0 or 1
675 ** indicating whether the specified option was defined at
@@ -688,13 +687,14 @@
688 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
689 **
690 ** See also: SQL functions [sqlite_compileoption_used()] and
691 ** [sqlite_compileoption_get()] and the [compile_options pragma].
692 */
 
693 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
694 SQLITE_API const char *sqlite3_compileoption_get(int N);
695 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
696
697 /*
698 ** CAPI3REF: Test To See If The Library Is Threadsafe
699 **
700 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -1492,15 +1492,14 @@
1492 **
1493 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1494 ** ^If the option is unknown or SQLite is unable to set the option
1495 ** then this routine returns a non-zero [error code].
1496 */
1497 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
1498
1499 /*
1500 ** CAPI3REF: Configure database connections
1501 ** EXPERIMENTAL
1502 **
1503 ** The sqlite3_db_config() interface is used to make configuration
1504 ** changes to a [database connection]. The interface is similar to
1505 ** [sqlite3_config()] except that the changes apply to a single
1506 ** [database connection] (specified in the first argument). The
@@ -1516,15 +1515,14 @@
1516 ** Additional arguments depend on the verb.
1517 **
1518 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1519 ** the call is considered successful.
1520 */
1521 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
1522
1523 /*
1524 ** CAPI3REF: Memory Allocation Routines
1525 ** EXPERIMENTAL
1526 **
1527 ** An instance of this object defines the interface between SQLite
1528 ** and low-level memory allocation routines.
1529 **
1530 ** This object is used in only one place in the SQLite interface.
@@ -1602,11 +1600,10 @@
1602 void *pAppData; /* Argument to xInit() and xShutdown() */
1603 };
1604
1605 /*
1606 ** CAPI3REF: Configuration Options
1607 ** EXPERIMENTAL
1608 **
1609 ** These constants are the available integer configuration options that
1610 ** can be passed as the first argument to the [sqlite3_config()] interface.
1611 **
1612 ** New configuration options may be added in future releases of SQLite.
@@ -1788,10 +1785,28 @@
1788 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1789 ** <dd> ^(This option takes a single argument which is a pointer to an
1790 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1791 ** page cache implementation into that object.)^ </dd>
1792 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1793 ** </dl>
1794 */
1795 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1796 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1797 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1808,12 +1823,11 @@
1808 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1809 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1810 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1811
1812 /*
1813 ** CAPI3REF: Configuration Options
1814 ** EXPERIMENTAL
1815 **
1816 ** These constants are the available integer configuration options that
1817 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1818 **
1819 ** New configuration options may be added in future releases of SQLite.
@@ -2585,11 +2599,10 @@
2585 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2586 #define SQLITE_COPY 0 /* No longer used */
2587
2588 /*
2589 ** CAPI3REF: Tracing And Profiling Functions
2590 ** EXPERIMENTAL
2591 **
2592 ** These routines register callback functions that can be used for
2593 ** tracing and profiling the execution of SQL statements.
2594 **
2595 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2603,11 +2616,11 @@
2603 ** ^The callback function registered by sqlite3_profile() is invoked
2604 ** as each SQL statement finishes. ^The profile callback contains
2605 ** the original statement text and an estimate of wall-clock time
2606 ** of how long that statement took to run.
2607 */
2608 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2609 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2610 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2611
2612 /*
2613 ** CAPI3REF: Query Progress Callbacks
@@ -4208,11 +4221,11 @@
4208 sqlite3*,
4209 void*,
4210 void(*)(void*,sqlite3*,int eTextRep,const void*)
4211 );
4212
4213 #if SQLITE_HAS_CODEC
4214 /*
4215 ** Specify the key for an encrypted database. This routine should be
4216 ** called right after sqlite3_open().
4217 **
4218 ** The code to implement this API is not available in the public release
@@ -4678,12 +4691,10 @@
4678 ** ^This function disables automatic extensions in all threads.
4679 */
4680 SQLITE_API void sqlite3_reset_auto_extension(void);
4681
4682 /*
4683 ****** EXPERIMENTAL - subject to change without notice **************
4684 **
4685 ** The interface to the virtual-table mechanism is currently considered
4686 ** to be experimental. The interface might change in incompatible ways.
4687 ** If this is a problem for you, do not use the interface at this time.
4688 **
4689 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4699,11 +4710,10 @@
4699 typedef struct sqlite3_module sqlite3_module;
4700
4701 /*
4702 ** CAPI3REF: Virtual Table Object
4703 ** KEYWORDS: sqlite3_module {virtual table module}
4704 ** EXPERIMENTAL
4705 **
4706 ** This structure, sometimes called a a "virtual table module",
4707 ** defines the implementation of a [virtual tables].
4708 ** This structure consists mostly of methods for the module.
4709 **
@@ -4746,11 +4756,10 @@
4746 };
4747
4748 /*
4749 ** CAPI3REF: Virtual Table Indexing Information
4750 ** KEYWORDS: sqlite3_index_info
4751 ** EXPERIMENTAL
4752 **
4753 ** The sqlite3_index_info structure and its substructures is used to
4754 ** pass information into and receive the reply from the [xBestIndex]
4755 ** method of a [virtual table module]. The fields under **Inputs** are the
4756 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4828,11 +4837,10 @@
4828 #define SQLITE_INDEX_CONSTRAINT_GE 32
4829 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4830
4831 /*
4832 ** CAPI3REF: Register A Virtual Table Implementation
4833 ** EXPERIMENTAL
4834 **
4835 ** ^These routines are used to register a new [virtual table module] name.
4836 ** ^Module names must be registered before
4837 ** creating a new [virtual table] using the module and before using a
4838 ** preexisting [virtual table] for the module.
@@ -4850,17 +4858,17 @@
4850 ** invoke the destructor function (if it is not NULL) when SQLite
4851 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4852 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4853 ** destructor.
4854 */
4855 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4856 sqlite3 *db, /* SQLite connection to register module with */
4857 const char *zName, /* Name of the module */
4858 const sqlite3_module *p, /* Methods for the module */
4859 void *pClientData /* Client data for xCreate/xConnect */
4860 );
4861 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4862 sqlite3 *db, /* SQLite connection to register module with */
4863 const char *zName, /* Name of the module */
4864 const sqlite3_module *p, /* Methods for the module */
4865 void *pClientData, /* Client data for xCreate/xConnect */
4866 void(*xDestroy)(void*) /* Module destructor function */
@@ -4867,11 +4875,10 @@
4867 );
4868
4869 /*
4870 ** CAPI3REF: Virtual Table Instance Object
4871 ** KEYWORDS: sqlite3_vtab
4872 ** EXPERIMENTAL
4873 **
4874 ** Every [virtual table module] implementation uses a subclass
4875 ** of this object to describe a particular instance
4876 ** of the [virtual table]. Each subclass will
4877 ** be tailored to the specific needs of the module implementation.
@@ -4893,11 +4900,10 @@
4893 };
4894
4895 /*
4896 ** CAPI3REF: Virtual Table Cursor Object
4897 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4898 ** EXPERIMENTAL
4899 **
4900 ** Every [virtual table module] implementation uses a subclass of the
4901 ** following structure to describe cursors that point into the
4902 ** [virtual table] and are used
4903 ** to loop through the virtual table. Cursors are created using the
@@ -4915,22 +4921,20 @@
4915 /* Virtual table implementations will typically add additional fields */
4916 };
4917
4918 /*
4919 ** CAPI3REF: Declare The Schema Of A Virtual Table
4920 ** EXPERIMENTAL
4921 **
4922 ** ^The [xCreate] and [xConnect] methods of a
4923 ** [virtual table module] call this interface
4924 ** to declare the format (the names and datatypes of the columns) of
4925 ** the virtual tables they implement.
4926 */
4927 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4928
4929 /*
4930 ** CAPI3REF: Overload A Function For A Virtual Table
4931 ** EXPERIMENTAL
4932 **
4933 ** ^(Virtual tables can provide alternative implementations of functions
4934 ** using the [xFindFunction] method of the [virtual table module].
4935 ** But global versions of those functions
4936 ** must exist in order to be overloaded.)^
@@ -4941,22 +4945,20 @@
4941 ** of the new function always causes an exception to be thrown. So
4942 ** the new function is not good for anything by itself. Its only
4943 ** purpose is to be a placeholder function that can be overloaded
4944 ** by a [virtual table].
4945 */
4946 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4947
4948 /*
4949 ** The interface to the virtual-table mechanism defined above (back up
4950 ** to a comment remarkably similar to this one) is currently considered
4951 ** to be experimental. The interface might change in incompatible ways.
4952 ** If this is a problem for you, do not use the interface at this time.
4953 **
4954 ** When the virtual-table mechanism stabilizes, we will declare the
4955 ** interface fixed, support it indefinitely, and remove this comment.
4956 **
4957 ****** EXPERIMENTAL - subject to change without notice **************
4958 */
4959
4960 /*
4961 ** CAPI3REF: A Handle To An Open BLOB
4962 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -5295,11 +5297,10 @@
5295 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
5296 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
5297
5298 /*
5299 ** CAPI3REF: Mutex Methods Object
5300 ** EXPERIMENTAL
5301 **
5302 ** An instance of this structure defines the low-level routines
5303 ** used to allocate and use mutexes.
5304 **
5305 ** Usually, the default mutex implementations provided by SQLite are
@@ -5512,11 +5513,10 @@
5512 #define SQLITE_TESTCTRL_ISKEYWORD 16
5513 #define SQLITE_TESTCTRL_LAST 16
5514
5515 /*
5516 ** CAPI3REF: SQLite Runtime Status
5517 ** EXPERIMENTAL
5518 **
5519 ** ^This interface is used to retrieve runtime status information
5520 ** about the preformance of SQLite, and optionally to reset various
5521 ** highwater marks. ^The first argument is an integer code for
5522 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5540,16 +5540,15 @@
5540 ** and it is possible that another thread might change the parameter
5541 ** in between the times when *pCurrent and *pHighwater are written.
5542 **
5543 ** See also: [sqlite3_db_status()]
5544 */
5545 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5546
5547
5548 /*
5549 ** CAPI3REF: Status Parameters
5550 ** EXPERIMENTAL
5551 **
5552 ** These integer constants designate various run-time status parameters
5553 ** that can be returned by [sqlite3_status()].
5554 **
5555 ** <dl>
@@ -5632,31 +5631,31 @@
5632 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5633 #define SQLITE_STATUS_SCRATCH_SIZE 8
5634
5635 /*
5636 ** CAPI3REF: Database Connection Status
5637 ** EXPERIMENTAL
5638 **
5639 ** ^This interface is used to retrieve runtime status information
5640 ** about a single [database connection]. ^The first argument is the
5641 ** database connection object to be interrogated. ^The second argument
5642 ** is the parameter to interrogate. ^Currently, the only allowed value
5643 ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5644 ** Additional options will likely appear in future releases of SQLite.
 
 
5645 **
5646 ** ^The current value of the requested parameter is written into *pCur
5647 ** and the highest instantaneous value is written into *pHiwtr. ^If
5648 ** the resetFlg is true, then the highest instantaneous value is
5649 ** reset back down to the current value.
5650 **
5651 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5652 */
5653 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5654
5655 /*
5656 ** CAPI3REF: Status Parameters for database connections
5657 ** EXPERIMENTAL
5658 **
5659 ** These constants are the available integer "verbs" that can be passed as
5660 ** the second argument to the [sqlite3_db_status()] interface.
5661 **
5662 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5667,18 +5666,25 @@
5667 **
5668 ** <dl>
5669 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5670 ** <dd>This parameter returns the number of lookaside memory slots currently
5671 ** checked out.</dd>)^
 
 
 
 
 
 
5672 ** </dl>
5673 */
5674 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
 
 
5675
5676
5677 /*
5678 ** CAPI3REF: Prepared Statement Status
5679 ** EXPERIMENTAL
5680 **
5681 ** ^(Each prepared statement maintains various
5682 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5683 ** of times it has performed specific operations.)^ These counters can
5684 ** be used to monitor the performance characteristics of the prepared
@@ -5696,15 +5702,14 @@
5696 ** ^If the resetFlg is true, then the counter is reset to zero after this
5697 ** interface call returns.
5698 **
5699 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5700 */
5701 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5702
5703 /*
5704 ** CAPI3REF: Status Parameters for prepared statements
5705 ** EXPERIMENTAL
5706 **
5707 ** These preprocessor macros define integer codes that name counter
5708 ** values associated with the [sqlite3_stmt_status()] interface.
5709 ** The meanings of the various counters are as follows:
5710 **
@@ -5718,18 +5723,25 @@
5718 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5719 ** <dd>^This is the number of sort operations that have occurred.
5720 ** A non-zero value in this counter may indicate an opportunity to
5721 ** improvement performance through careful use of indices.</dd>
5722 **
 
 
 
 
 
 
 
5723 ** </dl>
5724 */
5725 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5726 #define SQLITE_STMTSTATUS_SORT 2
 
5727
5728 /*
5729 ** CAPI3REF: Custom Page Cache Object
5730 ** EXPERIMENTAL
5731 **
5732 ** The sqlite3_pcache type is opaque. It is implemented by
5733 ** the pluggable module. The SQLite core has no knowledge of
5734 ** its size or internal structure and never deals with the
5735 ** sqlite3_pcache object except by holding and passing pointers
@@ -5740,11 +5752,10 @@
5740 typedef struct sqlite3_pcache sqlite3_pcache;
5741
5742 /*
5743 ** CAPI3REF: Application Defined Page Cache.
5744 ** KEYWORDS: {page cache}
5745 ** EXPERIMENTAL
5746 **
5747 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5748 ** register an alternative page cache implementation by passing in an
5749 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5750 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5882,11 +5893,10 @@
5882 void (*xDestroy)(sqlite3_pcache*);
5883 };
5884
5885 /*
5886 ** CAPI3REF: Online Backup Object
5887 ** EXPERIMENTAL
5888 **
5889 ** The sqlite3_backup object records state information about an ongoing
5890 ** online backup operation. ^The sqlite3_backup object is created by
5891 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5892 ** [sqlite3_backup_finish()].
@@ -5895,11 +5905,10 @@
5895 */
5896 typedef struct sqlite3_backup sqlite3_backup;
5897
5898 /*
5899 ** CAPI3REF: Online Backup API.
5900 ** EXPERIMENTAL
5901 **
5902 ** The backup API copies the content of one database into another.
5903 ** It is useful either for creating backups of databases or
5904 ** for copying in-memory databases to or from persistent files.
5905 **
@@ -6083,11 +6092,10 @@
6083 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
6084 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
6085
6086 /*
6087 ** CAPI3REF: Unlock Notification
6088 ** EXPERIMENTAL
6089 **
6090 ** ^When running in shared-cache mode, a database operation may fail with
6091 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
6092 ** individual tables within the shared-cache cannot be obtained. See
6093 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -6205,11 +6213,10 @@
6205 );
6206
6207
6208 /*
6209 ** CAPI3REF: String Comparison
6210 ** EXPERIMENTAL
6211 **
6212 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
6213 ** compare the contents of two buffers containing UTF-8 strings in a
6214 ** case-indendent fashion, using the same definition of case independence
6215 ** that SQLite uses internally when comparing identifiers.
@@ -6216,16 +6223,15 @@
6216 */
6217 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
6218
6219 /*
6220 ** CAPI3REF: Error Logging Interface
6221 ** EXPERIMENTAL
6222 **
6223 ** ^The [sqlite3_log()] interface writes a message into the error log
6224 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6225 ** ^If logging is enabled, the zFormat string and subsequent arguments are
6226 ** passed through to [sqlite3_vmprintf()] to generate the final output string.
6227 **
6228 ** The sqlite3_log() interface is intended for use by extensions such as
6229 ** virtual tables, collating functions, and SQL functions. While there is
6230 ** nothing to prevent an application from calling sqlite3_log(), doing so
6231 ** is considered bad form.
@@ -6529,10 +6535,11 @@
6529 ** If compiling for a processor that lacks floating point support,
6530 ** substitute integer for floating-point
6531 */
6532 #ifdef SQLITE_OMIT_FLOATING_POINT
6533 # define double sqlite_int64
 
6534 # define LONGDOUBLE_TYPE sqlite_int64
6535 # ifndef SQLITE_BIG_DBL
6536 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
6537 # endif
6538 # define SQLITE_OMIT_DATETIME_FUNCS 1
@@ -6940,10 +6947,11 @@
6940 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
6941 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
6942 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
6943 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
6944 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
 
6945 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
6946 SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
6947 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
6948 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
6949 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
@@ -7334,85 +7342,85 @@
7334 #define OP_ReadCookie 35
7335 #define OP_SetCookie 36
7336 #define OP_VerifyCookie 37
7337 #define OP_OpenRead 38
7338 #define OP_OpenWrite 39
7339 #define OP_OpenEphemeral 40
7340 #define OP_OpenPseudo 41
7341 #define OP_Close 42
7342 #define OP_SeekLt 43
7343 #define OP_SeekLe 44
7344 #define OP_SeekGe 45
7345 #define OP_SeekGt 46
7346 #define OP_Seek 47
7347 #define OP_NotFound 48
7348 #define OP_Found 49
7349 #define OP_IsUnique 50
7350 #define OP_NotExists 51
7351 #define OP_Sequence 52
7352 #define OP_NewRowid 53
7353 #define OP_Insert 54
7354 #define OP_InsertInt 55
7355 #define OP_Delete 56
7356 #define OP_ResetCount 57
7357 #define OP_RowKey 58
7358 #define OP_RowData 59
7359 #define OP_Rowid 60
7360 #define OP_NullRow 61
7361 #define OP_Last 62
7362 #define OP_Sort 63
7363 #define OP_Rewind 64
7364 #define OP_Prev 65
7365 #define OP_Next 66
7366 #define OP_IdxInsert 67
7367 #define OP_IdxDelete 70
7368 #define OP_IdxRowid 71
7369 #define OP_IdxLT 72
7370 #define OP_IdxGE 81
7371 #define OP_Destroy 92
7372 #define OP_Clear 95
7373 #define OP_CreateIndex 96
7374 #define OP_CreateTable 97
7375 #define OP_ParseSchema 98
7376 #define OP_LoadAnalysis 99
7377 #define OP_DropTable 100
7378 #define OP_DropIndex 101
7379 #define OP_DropTrigger 102
7380 #define OP_IntegrityCk 103
7381 #define OP_RowSetAdd 104
7382 #define OP_RowSetRead 105
7383 #define OP_RowSetTest 106
7384 #define OP_Program 107
7385 #define OP_Param 108
7386 #define OP_FkCounter 109
7387 #define OP_FkIfZero 110
7388 #define OP_MemMax 111
7389 #define OP_IfPos 112
7390 #define OP_IfNeg 113
7391 #define OP_IfZero 114
7392 #define OP_AggStep 115
7393 #define OP_AggFinal 116
7394 #define OP_Vacuum 117
7395 #define OP_IncrVacuum 118
7396 #define OP_Expire 119
7397 #define OP_TableLock 120
7398 #define OP_VBegin 121
7399 #define OP_VCreate 122
7400 #define OP_VDestroy 123
7401 #define OP_VOpen 124
7402 #define OP_VFilter 125
7403 #define OP_VColumn 126
7404 #define OP_VNext 127
7405 #define OP_VRename 128
7406 #define OP_VUpdate 129
7407 #define OP_Pagecount 131
7408 #define OP_Trace 132
7409 #define OP_Noop 133
7410 #define OP_Explain 134
7411
7412 /* The following opcode values are never used */
7413 #define OP_NotUsed_135 135
7414 #define OP_NotUsed_136 136
7415 #define OP_NotUsed_137 137
7416 #define OP_NotUsed_138 138
7417 #define OP_NotUsed_139 139
7418 #define OP_NotUsed_140 140
@@ -7433,22 +7441,22 @@
7433 /* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\
7434 /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x24,\
7435 /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
7436 /* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
7437 /* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\
7438 /* 40 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
7439 /* 48 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x00,\
7440 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
7441 /* 64 */ 0x01, 0x01, 0x01, 0x08, 0x4c, 0x4c, 0x00, 0x02,\
7442 /* 72 */ 0x01, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
7443 /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
7444 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x02, 0x24, 0x02, 0x00,\
7445 /* 96 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
7446 /* 104 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
7447 /* 112 */ 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00,\
7448 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,\
7449 /* 128 */ 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
7450 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
7451 /* 144 */ 0x04, 0x04,}
7452
7453 /************** End of opcodes.h *********************************************/
7454 /************** Continuing where we left off in vdbe.h ***********************/
@@ -7658,10 +7666,11 @@
7658 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
7659
7660 /* Functions used to query pager state and configuration. */
7661 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
7662 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
 
7663 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
7664 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
7665 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
7666 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
7667 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
@@ -8478,10 +8487,11 @@
8478 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
8479 #define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
8480 #define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
8481 #define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
8482 #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
 
8483
8484 /*
8485 ** Bits of the sqlite3.flags field that are used by the
8486 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
8487 ** These must be the low-order bits of the flags field.
@@ -9340,10 +9350,13 @@
9340 **
9341 ** The jointype starts out showing the join type between the current table
9342 ** and the next table on the list. The parser builds the list this way.
9343 ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
9344 ** jointype expresses the join between the table and the previous table.
 
 
 
9345 */
9346 struct SrcList {
9347 i16 nSrc; /* Number of tables or subqueries in the FROM clause */
9348 i16 nAlloc; /* Number of entries allocated in a[] below */
9349 struct SrcList_item {
@@ -9451,11 +9464,11 @@
9451 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
9452 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
9453 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
9454 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
9455 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
9456 #define WHERE_OMIT_OPEN 0x0010 /* Table cursor are already open */
9457 #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
9458 #define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
9459 #define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
9460
9461 /*
@@ -9474,10 +9487,11 @@
9474 int iTop; /* The very beginning of the WHERE loop */
9475 int iContinue; /* Jump here to continue with next record */
9476 int iBreak; /* Jump here to break out of the loop */
9477 int nLevel; /* Number of nested loop */
9478 struct WhereClause *pWC; /* Decomposition of the WHERE clause */
 
9479 WhereLevel a[1]; /* Information about each nest loop in WHERE */
9480 };
9481
9482 /*
9483 ** A NameContext defines a context in which to resolve table and column
@@ -9715,10 +9729,11 @@
9715 u32 oldmask; /* Mask of old.* columns referenced */
9716 u32 newmask; /* Mask of new.* columns referenced */
9717 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
9718 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
9719 u8 disableTriggers; /* True to disable triggers */
 
9720
9721 /* Above is constant between recursions. Below is reset before and after
9722 ** each recursion */
9723
9724 int nVar; /* Number of '?' variables seen in the SQL so far */
@@ -10656,11 +10671,50 @@
10656 #else
10657 # define IOTRACE(A)
10658 # define sqlite3VdbeIOTraceSql(X)
10659 #endif
10660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10661 #endif
 
 
 
 
 
 
10662
10663 /************** End of sqliteInt.h *******************************************/
10664 /************** Begin file global.c ******************************************/
10665 /*
10666 ** 2008 June 13
@@ -11038,10 +11092,13 @@
11038 #ifdef SQLITE_OMIT_AUTOINCREMENT
11039 "OMIT_AUTOINCREMENT",
11040 #endif
11041 #ifdef SQLITE_OMIT_AUTOINIT
11042 "OMIT_AUTOINIT",
 
 
 
11043 #endif
11044 #ifdef SQLITE_OMIT_AUTOVACUUM
11045 "OMIT_AUTOVACUUM",
11046 #endif
11047 #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
@@ -11367,10 +11424,30 @@
11367 if( resetFlag ){
11368 db->lookaside.mxOut = db->lookaside.nOut;
11369 }
11370 break;
11371 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11372 default: {
11373 return SQLITE_ERROR;
11374 }
11375 }
11376 return SQLITE_OK;
@@ -13140,11 +13217,12 @@
13140 struct MemBlockHdr {
13141 i64 iSize; /* Size of this allocation */
13142 struct MemBlockHdr *pNext, *pPrev; /* Linked list of all unfreed memory */
13143 char nBacktrace; /* Number of backtraces on this alloc */
13144 char nBacktraceSlots; /* Available backtrace slots */
13145 short nTitle; /* Bytes of title; includes '\0' */
 
13146 int iForeGuard; /* Guard word for sanity */
13147 };
13148
13149 /*
13150 ** Guard words
@@ -13348,10 +13426,11 @@
13348 }else{
13349 mem.pFirst = pHdr;
13350 }
13351 mem.pLast = pHdr;
13352 pHdr->iForeGuard = FOREGUARD;
 
13353 pHdr->nBacktraceSlots = mem.nBacktrace;
13354 pHdr->nTitle = mem.nTitle;
13355 if( mem.nBacktrace ){
13356 void *aAddr[40];
13357 pHdr->nBacktrace = backtrace(aAddr, mem.nBacktrace+1)-1;
@@ -13454,10 +13533,51 @@
13454 sqlite3MemShutdown,
13455 0
13456 };
13457 sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
13458 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13459
13460 /*
13461 ** Set the number of backtrace levels kept for each allocation.
13462 ** A value of zero turns off backtracing. The number is always rounded
13463 ** up to a multiple of 2.
@@ -16446,10 +16566,11 @@
16446 if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
16447 sqlite3_mutex_leave(mem0.mutex);
16448 }else{
16449 p = sqlite3GlobalConfig.m.xMalloc(n);
16450 }
 
16451 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
16452 scratchAllocOut = p!=0;
16453 #endif
16454 return p;
16455 }
@@ -16466,10 +16587,12 @@
16466 #endif
16467
16468 if( sqlite3GlobalConfig.pScratch==0
16469 || p<sqlite3GlobalConfig.pScratch
16470 || p>=(void*)mem0.aScratchFree ){
 
 
16471 if( sqlite3GlobalConfig.bMemstat ){
16472 int iSize = sqlite3MallocSize(p);
16473 sqlite3_mutex_enter(mem0.mutex);
16474 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
16475 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
@@ -16506,26 +16629,30 @@
16506 /*
16507 ** Return the size of a memory allocation previously obtained from
16508 ** sqlite3Malloc() or sqlite3_malloc().
16509 */
16510 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
 
16511 return sqlite3GlobalConfig.m.xSize(p);
16512 }
16513 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
16514 assert( db==0 || sqlite3_mutex_held(db->mutex) );
16515 if( isLookaside(db, p) ){
16516 return db->lookaside.sz;
16517 }else{
 
 
16518 return sqlite3GlobalConfig.m.xSize(p);
16519 }
16520 }
16521
16522 /*
16523 ** Free memory previously obtained from sqlite3Malloc().
16524 */
16525 SQLITE_API void sqlite3_free(void *p){
16526 if( p==0 ) return;
 
16527 if( sqlite3GlobalConfig.bMemstat ){
16528 sqlite3_mutex_enter(mem0.mutex);
16529 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
16530 sqlite3GlobalConfig.m.xFree(p);
16531 sqlite3_mutex_leave(mem0.mutex);
@@ -16544,10 +16671,12 @@
16544 LookasideSlot *pBuf = (LookasideSlot*)p;
16545 pBuf->pNext = db->lookaside.pFree;
16546 db->lookaside.pFree = pBuf;
16547 db->lookaside.nOut--;
16548 }else{
 
 
16549 sqlite3_free(p);
16550 }
16551 }
16552
16553 /*
@@ -16576,10 +16705,11 @@
16576 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
16577 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
16578 mem0.alarmThreshold ){
16579 sqlite3MallocAlarm(nNew-nOld);
16580 }
 
16581 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16582 if( pNew==0 && mem0.alarmCallback ){
16583 sqlite3MallocAlarm(nBytes);
16584 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16585 }
@@ -16673,10 +16803,12 @@
16673 #endif
16674 p = sqlite3Malloc(n);
16675 if( !p && db ){
16676 db->mallocFailed = 1;
16677 }
 
 
16678 return p;
16679 }
16680
16681 /*
16682 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -16698,14 +16830,18 @@
16698 if( pNew ){
16699 memcpy(pNew, p, db->lookaside.sz);
16700 sqlite3DbFree(db, p);
16701 }
16702 }else{
 
 
16703 pNew = sqlite3_realloc(p, n);
16704 if( !pNew ){
16705 db->mallocFailed = 1;
16706 }
 
 
16707 }
16708 }
16709 return pNew;
16710 }
16711
@@ -18305,11 +18441,11 @@
18305 u8 isPrepareV2; /* True if prepared with prepare_v2() */
18306 int nChange; /* Number of db changes made since last reset */
18307 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
18308 i64 startTime; /* Time when query started - used for profiling */
18309 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18310 int aCounter[2]; /* Counters used by sqlite3_stmt_status() */
18311 char *zSql; /* Text of the SQL statement that generated this */
18312 void *pFree; /* Free this when deleting the vdbe */
18313 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
18314 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
18315 int iStatement; /* Statement number (or 0 if has not opened stmt) */
@@ -20345,52 +20481,52 @@
20345 /* 35 */ "ReadCookie",
20346 /* 36 */ "SetCookie",
20347 /* 37 */ "VerifyCookie",
20348 /* 38 */ "OpenRead",
20349 /* 39 */ "OpenWrite",
20350 /* 40 */ "OpenEphemeral",
20351 /* 41 */ "OpenPseudo",
20352 /* 42 */ "Close",
20353 /* 43 */ "SeekLt",
20354 /* 44 */ "SeekLe",
20355 /* 45 */ "SeekGe",
20356 /* 46 */ "SeekGt",
20357 /* 47 */ "Seek",
20358 /* 48 */ "NotFound",
20359 /* 49 */ "Found",
20360 /* 50 */ "IsUnique",
20361 /* 51 */ "NotExists",
20362 /* 52 */ "Sequence",
20363 /* 53 */ "NewRowid",
20364 /* 54 */ "Insert",
20365 /* 55 */ "InsertInt",
20366 /* 56 */ "Delete",
20367 /* 57 */ "ResetCount",
20368 /* 58 */ "RowKey",
20369 /* 59 */ "RowData",
20370 /* 60 */ "Rowid",
20371 /* 61 */ "NullRow",
20372 /* 62 */ "Last",
20373 /* 63 */ "Sort",
20374 /* 64 */ "Rewind",
20375 /* 65 */ "Prev",
20376 /* 66 */ "Next",
20377 /* 67 */ "IdxInsert",
20378 /* 68 */ "Or",
20379 /* 69 */ "And",
20380 /* 70 */ "IdxDelete",
20381 /* 71 */ "IdxRowid",
20382 /* 72 */ "IdxLT",
20383 /* 73 */ "IsNull",
20384 /* 74 */ "NotNull",
20385 /* 75 */ "Ne",
20386 /* 76 */ "Eq",
20387 /* 77 */ "Gt",
20388 /* 78 */ "Le",
20389 /* 79 */ "Lt",
20390 /* 80 */ "Ge",
20391 /* 81 */ "IdxGE",
20392 /* 82 */ "BitAnd",
20393 /* 83 */ "BitOr",
20394 /* 84 */ "ShiftLeft",
20395 /* 85 */ "ShiftRight",
20396 /* 86 */ "Add",
@@ -20397,54 +20533,54 @@
20397 /* 87 */ "Subtract",
20398 /* 88 */ "Multiply",
20399 /* 89 */ "Divide",
20400 /* 90 */ "Remainder",
20401 /* 91 */ "Concat",
20402 /* 92 */ "Destroy",
20403 /* 93 */ "BitNot",
20404 /* 94 */ "String8",
20405 /* 95 */ "Clear",
20406 /* 96 */ "CreateIndex",
20407 /* 97 */ "CreateTable",
20408 /* 98 */ "ParseSchema",
20409 /* 99 */ "LoadAnalysis",
20410 /* 100 */ "DropTable",
20411 /* 101 */ "DropIndex",
20412 /* 102 */ "DropTrigger",
20413 /* 103 */ "IntegrityCk",
20414 /* 104 */ "RowSetAdd",
20415 /* 105 */ "RowSetRead",
20416 /* 106 */ "RowSetTest",
20417 /* 107 */ "Program",
20418 /* 108 */ "Param",
20419 /* 109 */ "FkCounter",
20420 /* 110 */ "FkIfZero",
20421 /* 111 */ "MemMax",
20422 /* 112 */ "IfPos",
20423 /* 113 */ "IfNeg",
20424 /* 114 */ "IfZero",
20425 /* 115 */ "AggStep",
20426 /* 116 */ "AggFinal",
20427 /* 117 */ "Vacuum",
20428 /* 118 */ "IncrVacuum",
20429 /* 119 */ "Expire",
20430 /* 120 */ "TableLock",
20431 /* 121 */ "VBegin",
20432 /* 122 */ "VCreate",
20433 /* 123 */ "VDestroy",
20434 /* 124 */ "VOpen",
20435 /* 125 */ "VFilter",
20436 /* 126 */ "VColumn",
20437 /* 127 */ "VNext",
20438 /* 128 */ "VRename",
20439 /* 129 */ "VUpdate",
20440 /* 130 */ "Real",
20441 /* 131 */ "Pagecount",
20442 /* 132 */ "Trace",
20443 /* 133 */ "Noop",
20444 /* 134 */ "Explain",
20445 /* 135 */ "NotUsed_135",
20446 /* 136 */ "NotUsed_136",
20447 /* 137 */ "NotUsed_137",
20448 /* 138 */ "NotUsed_138",
20449 /* 139 */ "NotUsed_139",
20450 /* 140 */ "NotUsed_140",
@@ -26155,13 +26291,11 @@
26155 flags |= SQLITE_OPEN_READONLY;
26156 openFlags |= O_RDONLY;
26157 fd = open(zName, openFlags, openMode);
26158 }
26159 if( fd<0 ){
26160 sqlite3_log(SQLITE_CANTOPEN, "cannot open file [%s]: %s", zName,
26161 strerror(errno));
26162 rc = SQLITE_CANTOPEN;
26163 goto open_finished;
26164 }
26165 }
26166 assert( fd>=0 );
26167 if( pOutFlags ){
@@ -30816,11 +30950,16 @@
30816 if( pCache->pCache ){
30817 PgHdr *p;
30818 PgHdr *pNext;
30819 for(p=pCache->pDirty; p; p=pNext){
30820 pNext = p->pDirtyNext;
30821 if( p->pgno>pgno ){
 
 
 
 
 
30822 assert( p->flags&PGHDR_DIRTY );
30823 sqlite3PcacheMakeClean(p);
30824 }
30825 }
30826 if( pgno==0 && pCache->pPage1 ){
@@ -31160,10 +31299,11 @@
31160 pcache1EnterMutex();
31161 if( p ){
31162 int sz = sqlite3MallocSize(p);
31163 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
31164 }
 
31165 }
31166 return p;
31167 }
31168
31169 /*
@@ -31177,11 +31317,14 @@
31177 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
31178 pSlot = (PgFreeslot*)p;
31179 pSlot->pNext = pcache1.pFree;
31180 pcache1.pFree = pSlot;
31181 }else{
31182 int iSize = sqlite3MallocSize(p);
 
 
 
31183 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
31184 sqlite3_free(p);
31185 }
31186 }
31187
@@ -33315,12 +33458,13 @@
33315 pPager->pInJournal = 0;
33316 releaseAllSavepoints(pPager);
33317
33318 /* If the file is unlocked, somebody else might change it. The
33319 ** values stored in Pager.dbSize etc. might become invalid if
33320 ** this happens. TODO: Really, this doesn't need to be cleared
33321 ** until the change-counter check fails in PagerSharedLock().
 
33322 */
33323 pPager->dbSizeValid = 0;
33324
33325 rc = osUnlock(pPager->fd, NO_LOCK);
33326 if( rc ){
@@ -33506,16 +33650,15 @@
33506 }
33507
33508 #ifdef SQLITE_CHECK_PAGES
33509 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
33510 #endif
33511
33512 sqlite3PcacheCleanAll(pPager->pPCache);
33513 sqlite3BitvecDestroy(pPager->pInJournal);
33514 pPager->pInJournal = 0;
33515 pPager->nRec = 0;
33516 }
 
 
 
 
33517
33518 if( !pPager->exclusiveMode ){
33519 rc2 = osUnlock(pPager->fd, SHARED_LOCK);
33520 pPager->state = PAGER_SHARED;
33521 pPager->changeCountDone = 0;
@@ -34170,10 +34313,18 @@
34170 if( rc!=SQLITE_OK ){
34171 if( rc==SQLITE_DONE ){
34172 rc = SQLITE_OK;
34173 pPager->journalOff = szJ;
34174 break;
 
 
 
 
 
 
 
 
34175 }else{
34176 /* If we are unable to rollback, quit and return the error
34177 ** code. This will cause the pager to enter the error state
34178 ** so that no further harm will be done. Perhaps the next
34179 ** process to come along will be able to rollback the database.
@@ -34575,14 +34726,16 @@
34575 ** maximum page count below the current size of the database.
34576 **
34577 ** Regardless of mxPage, return the current maximum page count.
34578 */
34579 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
 
34580 if( mxPage>0 ){
34581 pPager->mxPgno = mxPage;
34582 }
34583 sqlite3PagerPagecount(pPager, 0);
 
34584 return pPager->mxPgno;
34585 }
34586
34587 /*
34588 ** The following set of routines are used to disable the simulated
@@ -34652,15 +34805,10 @@
34652 ** and *pnPage is set to the number of pages in the database.
34653 */
34654 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
34655 Pgno nPage; /* Value to return via *pnPage */
34656
34657 /* If the pager is already in the error state, return the error code. */
34658 if( pPager->errCode ){
34659 return pPager->errCode;
34660 }
34661
34662 /* Determine the number of pages in the file. Store this in nPage. */
34663 if( pPager->dbSizeValid ){
34664 nPage = pPager->dbSize;
34665 }else{
34666 int rc; /* Error returned by OsFileSize() */
@@ -34690,13 +34838,11 @@
34690 if( nPage>pPager->mxPgno ){
34691 pPager->mxPgno = (Pgno)nPage;
34692 }
34693
34694 /* Set the output variable and return SQLITE_OK */
34695 if( pnPage ){
34696 *pnPage = nPage;
34697 }
34698 return SQLITE_OK;
34699 }
34700
34701
34702 /*
@@ -35890,20 +36036,20 @@
35890 **
35891 ** There is a vanishingly small chance that a change will not be
35892 ** detected. The chance of an undetected change is so small that
35893 ** it can be neglected.
35894 */
 
35895 char dbFileVers[sizeof(pPager->dbFileVers)];
35896 sqlite3PagerPagecount(pPager, 0);
35897
35898 if( pPager->errCode ){
35899 rc = pPager->errCode;
35900 goto failed;
35901 }
35902
35903 assert( pPager->dbSizeValid );
35904 if( pPager->dbSize>0 ){
35905 IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
35906 rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
35907 if( rc!=SQLITE_OK ){
35908 goto failed;
35909 }
@@ -36024,11 +36170,11 @@
36024 goto pager_acquire_err;
36025 }
36026 assert( (*ppPage)->pgno==pgno );
36027 assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 );
36028
36029 if( (*ppPage)->pPager ){
36030 /* In this case the pcache already contains an initialized copy of
36031 ** the page. Return without further ado. */
36032 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
36033 PAGER_INCR(pPager->nHit);
36034 return SQLITE_OK;
@@ -36184,10 +36330,11 @@
36184 ** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
36185 ** an IO error code if opening or writing the journal file fails.
36186 */
36187 static int pager_open_journal(Pager *pPager){
36188 int rc = SQLITE_OK; /* Return code */
 
36189 sqlite3_vfs * const pVfs = pPager->pVfs; /* Local cache of vfs pointer */
36190
36191 assert( pPager->state>=PAGER_RESERVED );
36192 assert( pPager->useJournal );
36193 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF );
@@ -36196,17 +36343,14 @@
36196 /* If already in the error state, this function is a no-op. But on
36197 ** the other hand, this routine is never called if we are already in
36198 ** an error state. */
36199 if( NEVER(pPager->errCode) ) return pPager->errCode;
36200
36201 /* TODO: Is it really possible to get here with dbSizeValid==0? If not,
36202 ** the call to PagerPagecount() can be removed.
36203 */
36204 testcase( pPager->dbSizeValid==0 );
36205 sqlite3PagerPagecount(pPager, 0);
36206
36207 pPager->pInJournal = sqlite3BitvecCreate(pPager->dbSize);
36208 if( pPager->pInJournal==0 ){
36209 return SQLITE_NOMEM;
36210 }
36211
36212 /* Open the journal file if it is not already open. */
@@ -36301,16 +36445,15 @@
36301 if( exFlag ){
36302 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
36303 }
36304 }
36305
36306 /* If the required locks were successfully obtained, open the journal
36307 ** file and write the first journal-header to it.
 
 
36308 */
36309 if( rc==SQLITE_OK && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36310 rc = pager_open_journal(pPager);
36311 }
36312 }else if( isOpen(pPager->jfd) && pPager->journalOff==0 ){
36313 /* This happens when the pager was in exclusive-access mode the last
36314 ** time a (read or write) transaction was successfully concluded
36315 ** by this connection. Instead of deleting the journal file it was
36316 ** kept open and either was truncated to 0 bytes or its header was
@@ -36321,11 +36464,10 @@
36321 assert( pPager->pInJournal==0 );
36322 rc = pager_open_journal(pPager);
36323 }
36324
36325 PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
36326 assert( !isOpen(pPager->jfd) || pPager->journalOff>0 || rc!=SQLITE_OK );
36327 if( rc!=SQLITE_OK ){
36328 assert( !pPager->dbModified );
36329 /* Ignore any IO error that occurs within pager_end_transaction(). The
36330 ** purpose of this call is to reset the internal state of the pager
36331 ** sub-system. It doesn't matter if the journal-file is not properly
@@ -36351,12 +36493,12 @@
36351 /* This routine is not called unless a transaction has already been
36352 ** started.
36353 */
36354 assert( pPager->state>=PAGER_RESERVED );
36355
36356 /* If an error has been previously detected, we should not be
36357 ** calling this routine. Repeat the error for robustness.
36358 */
36359 if( NEVER(pPager->errCode) ) return pPager->errCode;
36360
36361 /* Higher-level routines never call this function if database is not
36362 ** writable. But check anyway, just for robustness. */
@@ -36377,15 +36519,15 @@
36377 /* If we get this far, it means that the page needs to be
36378 ** written to the transaction journal or the ckeckpoint journal
36379 ** or both.
36380 **
36381 ** Higher level routines should have already started a transaction,
36382 ** which means they have acquired the necessary locks and opened
36383 ** a rollback journal. Double-check to makes sure this is the case.
36384 */
36385 rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
36386 if( NEVER(rc!=SQLITE_OK) ){
36387 return rc;
36388 }
36389 if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36390 assert( pPager->useJournal );
36391 rc = pager_open_journal(pPager);
@@ -36523,11 +36665,12 @@
36523 ** an integer power of 2. It sets variable pg1 to the identifier
36524 ** of the first page of the sector pPg is located on.
36525 */
36526 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
36527
36528 sqlite3PagerPagecount(pPager, (int *)&nPageCount);
 
36529 if( pPg->pgno>nPageCount ){
36530 nPage = (pPg->pgno - pg1)+1;
36531 }else if( (pg1+nPagePerSector-1)>nPageCount ){
36532 nPage = nPageCount+1-pg1;
36533 }else{
@@ -36684,10 +36827,13 @@
36684 /* Increment the value just read and write it back to byte 24. */
36685 change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
36686 change_counter++;
36687 put32bits(((char*)pPgHdr->pData)+24, change_counter);
36688
 
 
 
36689 /* If running in direct mode, write the contents of page 1 to the file. */
36690 if( DIRECT_MODE ){
36691 const void *zBuf = pPgHdr->pData;
36692 assert( pPager->dbFileSize>0 );
36693 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
@@ -36757,13 +36903,11 @@
36757 int rc = SQLITE_OK; /* Return code */
36758
36759 /* The dbOrigSize is never set if journal_mode=OFF */
36760 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 );
36761
36762 /* If a prior error occurred, this routine should not be called. ROLLBACK
36763 ** is the appropriate response to an error, not COMMIT. Guard against
36764 ** coding errors by repeating the prior error. */
36765 if( NEVER(pPager->errCode) ) return pPager->errCode;
36766
36767 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
36768 pPager->zFilename, zMaster, pPager->dbSize));
36769
@@ -37048,10 +37192,20 @@
37048 ** Return the number of references to the pager.
37049 */
37050 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
37051 return sqlite3PcacheRefCount(pPager->pPCache);
37052 }
 
 
 
 
 
 
 
 
 
 
37053
37054 /*
37055 ** Return the number of references to the specified page.
37056 */
37057 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
@@ -37101,15 +37255,14 @@
37101 int nCurrent = pPager->nSavepoint; /* Current number of savepoints */
37102
37103 if( nSavepoint>nCurrent && pPager->useJournal ){
37104 int ii; /* Iterator variable */
37105 PagerSavepoint *aNew; /* New Pager.aSavepoint array */
 
37106
37107 /* Either there is no active journal or the sub-journal is open or
37108 ** the journal is always stored in memory */
37109 assert( pPager->nSavepoint==0 || isOpen(pPager->sjfd) ||
37110 pPager->journalMode==PAGER_JOURNALMODE_MEMORY );
37111
37112 /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
37113 ** if the allocation fails. Otherwise, zero the new portion in case a
37114 ** malloc failure occurs while populating it in the for(...) loop below.
37115 */
@@ -37123,19 +37276,18 @@
37123 pPager->aSavepoint = aNew;
37124 pPager->nSavepoint = nSavepoint;
37125
37126 /* Populate the PagerSavepoint structures just allocated. */
37127 for(ii=nCurrent; ii<nSavepoint; ii++){
37128 assert( pPager->dbSizeValid );
37129 aNew[ii].nOrig = pPager->dbSize;
37130 if( isOpen(pPager->jfd) && ALWAYS(pPager->journalOff>0) ){
37131 aNew[ii].iOffset = pPager->journalOff;
37132 }else{
37133 aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
37134 }
37135 aNew[ii].iSubRec = pPager->nSubRec;
37136 aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
37137 if( !aNew[ii].pInSavepoint ){
37138 return SQLITE_NOMEM;
37139 }
37140 }
37141
@@ -37518,10 +37670,19 @@
37518 && (!isOpen(pPager->jfd) || 0==pPager->journalOff)
37519 ){
37520 if( isOpen(pPager->jfd) ){
37521 sqlite3OsClose(pPager->jfd);
37522 }
 
 
 
 
 
 
 
 
 
37523 pPager->journalMode = (u8)eMode;
37524 }
37525 return (int)pPager->journalMode;
37526 }
37527
@@ -37978,10 +38139,11 @@
37978 BtCursor *pCursor; /* A list of all open cursors */
37979 MemPage *pPage1; /* First page of the database */
37980 u8 readOnly; /* True if the underlying file is readonly */
37981 u8 pageSizeFixed; /* True if the page size can no longer be changed */
37982 u8 secureDelete; /* True if secure_delete is enabled */
 
37983 #ifndef SQLITE_OMIT_AUTOVACUUM
37984 u8 autoVacuum; /* True if auto-vacuum is enabled */
37985 u8 incrVacuum; /* True if incr-vacuum is enabled */
37986 #endif
37987 u16 pageSize; /* Total number of bytes on a page */
@@ -37990,10 +38152,11 @@
37990 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
37991 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
37992 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
37993 u8 inTransaction; /* Transaction state */
37994 int nTransaction; /* Number of open transactions (read + write) */
 
37995 void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
37996 void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
37997 sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
37998 Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */
37999 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -39070,15 +39233,12 @@
39070 ** at the end of every transaction.
39071 */
39072 static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
39073 int rc = SQLITE_OK;
39074 if( !pBt->pHasContent ){
39075 int nPage = 100;
39076 sqlite3PagerPagecount(pBt->pPager, &nPage);
39077 /* If sqlite3PagerPagecount() fails there is no harm because the
39078 ** nPage variable is unchanged from its default value of 100 */
39079 pBt->pHasContent = sqlite3BitvecCreate((u32)nPage);
39080 if( !pBt->pHasContent ){
39081 rc = SQLITE_NOMEM;
39082 }
39083 }
39084 if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
@@ -40117,17 +40277,17 @@
40117
40118 /*
40119 ** Return the size of the database file in pages. If there is any kind of
40120 ** error, return ((unsigned int)-1).
40121 */
40122 static Pgno pagerPagecount(BtShared *pBt){
40123 int nPage = -1;
40124 int rc;
40125 assert( pBt->pPage1 );
40126 rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40127 assert( rc==SQLITE_OK || nPage==-1 );
40128 return (Pgno)nPage;
40129 }
40130
40131 /*
40132 ** Get a page from the pager and initialize it. This routine is just a
40133 ** convenience wrapper around separate calls to btreeGetPage() and
@@ -40140,29 +40300,22 @@
40140 BtShared *pBt, /* The database file */
40141 Pgno pgno, /* Number of the page to get */
40142 MemPage **ppPage /* Write the page pointer here */
40143 ){
40144 int rc;
40145 TESTONLY( Pgno iLastPg = pagerPagecount(pBt); )
40146 assert( sqlite3_mutex_held(pBt->mutex) );
40147
 
 
 
40148 rc = btreeGetPage(pBt, pgno, ppPage, 0);
40149 if( rc==SQLITE_OK ){
40150 rc = btreeInitPage(*ppPage);
40151 if( rc!=SQLITE_OK ){
40152 releasePage(*ppPage);
40153 }
40154 }
40155
40156 /* If the requested page number was either 0 or greater than the page
40157 ** number of the last page in the database, this function should return
40158 ** SQLITE_CORRUPT or some other error (i.e. SQLITE_FULL). Check that this
40159 ** is the case. */
40160 assert( (pgno>0 && pgno<=iLastPg) || rc!=SQLITE_OK );
40161 testcase( pgno==0 );
40162 testcase( pgno==iLastPg );
40163
40164 return rc;
40165 }
40166
40167 /*
40168 ** Release a MemPage. This should be called once for each prior
@@ -40794,13 +40947,15 @@
40794 ** well-formed database file, then SQLITE_CORRUPT is returned.
40795 ** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
40796 ** is returned if we run out of memory.
40797 */
40798 static int lockBtree(BtShared *pBt){
40799 int rc;
40800 MemPage *pPage1;
40801 int nPage;
 
 
40802
40803 assert( sqlite3_mutex_held(pBt->mutex) );
40804 assert( pBt->pPage1==0 );
40805 rc = sqlite3PagerSharedLock(pBt->pPager);
40806 if( rc!=SQLITE_OK ) return rc;
@@ -40808,14 +40963,18 @@
40808 if( rc!=SQLITE_OK ) return rc;
40809
40810 /* Do some checking to help insure the file we opened really is
40811 ** a valid database file.
40812 */
40813 rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40814 if( rc!=SQLITE_OK ){
40815 goto page1_init_failed;
40816 }else if( nPage>0 ){
 
 
 
 
40817 int pageSize;
40818 int usableSize;
40819 u8 *page1 = pPage1->aData;
40820 rc = SQLITE_NOTADB;
40821 if( memcmp(page1, zMagicHeader, 16)!=0 ){
@@ -40857,10 +41016,14 @@
40857 freeTempSpace(pBt);
40858 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
40859 pageSize-usableSize);
40860 return rc;
40861 }
 
 
 
 
40862 if( usableSize<480 ){
40863 goto page1_init_failed;
40864 }
40865 pBt->pageSize = (u16)pageSize;
40866 pBt->usableSize = (u16)usableSize;
@@ -40887,10 +41050,11 @@
40887 pBt->minLocal = (pBt->usableSize-12)*32/255 - 23;
40888 pBt->maxLeaf = pBt->usableSize - 35;
40889 pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23;
40890 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
40891 pBt->pPage1 = pPage1;
 
40892 return SQLITE_OK;
40893
40894 page1_init_failed:
40895 releasePage(pPage1);
40896 pBt->pPage1 = 0;
@@ -40924,16 +41088,14 @@
40924 */
40925 static int newDatabase(BtShared *pBt){
40926 MemPage *pP1;
40927 unsigned char *data;
40928 int rc;
40929 int nPage;
40930
40931 assert( sqlite3_mutex_held(pBt->mutex) );
40932 rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
40933 if( rc!=SQLITE_OK || nPage>0 ){
40934 return rc;
40935 }
40936 pP1 = pBt->pPage1;
40937 assert( pP1!=0 );
40938 data = pP1->aData;
40939 rc = sqlite3PagerWrite(pP1->pDbPage);
@@ -40955,10 +41117,12 @@
40955 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
40956 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
40957 put4byte(&data[36 + 4*4], pBt->autoVacuum);
40958 put4byte(&data[36 + 7*4], pBt->incrVacuum);
40959 #endif
 
 
40960 return SQLITE_OK;
40961 }
40962
40963 /*
40964 ** Attempt to start a new transaction. A write-transaction
@@ -41044,10 +41208,11 @@
41044 ** page 1. So if some other shared-cache client already has a write-lock
41045 ** on page 1, the transaction cannot be opened. */
41046 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
41047 if( SQLITE_OK!=rc ) goto trans_begun;
41048
 
41049 do {
41050 /* Call lockBtree() until either pBt->pPage1 is populated or
41051 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
41052 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
41053 ** reading page 1 it discovers that the page-size of the database
@@ -41323,16 +41488,16 @@
41323 ** which may or may not empty the freelist. A full autovacuum
41324 ** has nFin>0. A "PRAGMA incremental_vacuum" has nFin==0.
41325 */
41326 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
41327 Pgno nFreeList; /* Number of pages still on the free-list */
 
41328
41329 assert( sqlite3_mutex_held(pBt->mutex) );
41330 assert( iLastPg>nFin );
41331
41332 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
41333 int rc;
41334 u8 eType;
41335 Pgno iPtrPage;
41336
41337 nFreeList = get4byte(&pBt->pPage1->aData[36]);
41338 if( nFreeList==0 ){
@@ -41404,11 +41569,11 @@
41404 if( nFin==0 ){
41405 iLastPg--;
41406 while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
41407 if( PTRMAP_ISPAGE(pBt, iLastPg) ){
41408 MemPage *pPg;
41409 int rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
41410 if( rc!=SQLITE_OK ){
41411 return rc;
41412 }
41413 rc = sqlite3PagerWrite(pPg->pDbPage);
41414 releasePage(pPg);
@@ -41417,10 +41582,11 @@
41417 }
41418 }
41419 iLastPg--;
41420 }
41421 sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
 
41422 }
41423 return SQLITE_OK;
41424 }
41425
41426 /*
@@ -41439,11 +41605,15 @@
41439 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
41440 if( !pBt->autoVacuum ){
41441 rc = SQLITE_DONE;
41442 }else{
41443 invalidateAllOverflowCache(pBt);
41444 rc = incrVacuumStep(pBt, 0, pagerPagecount(pBt));
 
 
 
 
41445 }
41446 sqlite3BtreeLeave(p);
41447 return rc;
41448 }
41449
@@ -41470,11 +41640,11 @@
41470 Pgno nPtrmap; /* Number of PtrMap pages to be freed */
41471 Pgno iFree; /* The next page to be freed */
41472 int nEntry; /* Number of entries on one ptrmap page */
41473 Pgno nOrig; /* Database size before freeing */
41474
41475 nOrig = pagerPagecount(pBt);
41476 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
41477 /* It is not possible to create a database for which the final page
41478 ** is either a pointer-map page or the pending-byte page. If one
41479 ** is encountered, this indicates corruption.
41480 */
@@ -41495,15 +41665,16 @@
41495
41496 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
41497 rc = incrVacuumStep(pBt, nFin, iFree);
41498 }
41499 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
41500 rc = SQLITE_OK;
41501 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41502 put4byte(&pBt->pPage1->aData[32], 0);
41503 put4byte(&pBt->pPage1->aData[36], 0);
 
41504 sqlite3PagerTruncateImage(pBt->pPager, nFin);
 
41505 }
41506 if( rc!=SQLITE_OK ){
41507 sqlite3PagerRollback(pPager);
41508 }
41509 }
@@ -41749,10 +41920,15 @@
41749
41750 /* The rollback may have destroyed the pPage1->aData value. So
41751 ** call btreeGetPage() on page 1 again to make
41752 ** sure pPage1->aData is set correctly. */
41753 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
 
 
 
 
 
41754 releasePage(pPage1);
41755 }
41756 assert( countWriteCursors(pBt)==0 );
41757 pBt->inTransaction = TRANS_READ;
41758 }
@@ -41786,21 +41962,17 @@
41786 sqlite3BtreeEnter(p);
41787 assert( p->inTrans==TRANS_WRITE );
41788 assert( pBt->readOnly==0 );
41789 assert( iStatement>0 );
41790 assert( iStatement>p->db->nSavepoint );
41791 if( NEVER(p->inTrans!=TRANS_WRITE || pBt->readOnly) ){
41792 rc = SQLITE_INTERNAL;
41793 }else{
41794 assert( pBt->inTransaction==TRANS_WRITE );
41795 /* At the pager level, a statement transaction is a savepoint with
41796 ** an index greater than all savepoints created explicitly using
41797 ** SQL statements. It is illegal to open, release or rollback any
41798 ** such savepoints while the statement transaction savepoint is active.
41799 */
41800 rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
41801 }
41802 sqlite3BtreeLeave(p);
41803 return rc;
41804 }
41805
41806 /*
@@ -41822,11 +41994,13 @@
41822 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
41823 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
41824 sqlite3BtreeEnter(p);
41825 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
41826 if( rc==SQLITE_OK ){
 
41827 rc = newDatabase(pBt);
 
41828 }
41829 sqlite3BtreeLeave(p);
41830 }
41831 return rc;
41832 }
@@ -41888,11 +42062,11 @@
41888 assert( pBt->pPage1 && pBt->pPage1->aData );
41889
41890 if( NEVER(wrFlag && pBt->readOnly) ){
41891 return SQLITE_READONLY;
41892 }
41893 if( iTable==1 && pagerPagecount(pBt)==0 ){
41894 return SQLITE_EMPTY;
41895 }
41896
41897 /* Now that no other errors can occur, finish filling in the BtCursor
41898 ** variables and link the cursor into the BtShared list. */
@@ -42159,11 +42333,11 @@
42159
42160 while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
42161 iGuess++;
42162 }
42163
42164 if( iGuess<=pagerPagecount(pBt) ){
42165 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
42166 if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
42167 next = iGuess;
42168 rc = SQLITE_DONE;
42169 }
@@ -43191,11 +43365,11 @@
43191 MemPage *pPrevTrunk = 0;
43192 Pgno mxPage; /* Total size of the database file */
43193
43194 assert( sqlite3_mutex_held(pBt->mutex) );
43195 pPage1 = pBt->pPage1;
43196 mxPage = pagerPagecount(pBt);
43197 n = get4byte(&pPage1->aData[36]);
43198 testcase( n==mxPage-1 );
43199 if( n>=mxPage ){
43200 return SQLITE_CORRUPT_BKPT;
43201 }
@@ -43387,39 +43561,39 @@
43387 pPrevTrunk = 0;
43388 }while( searchList );
43389 }else{
43390 /* There are no pages on the freelist, so create a new page at the
43391 ** end of the file */
43392 int nPage = pagerPagecount(pBt);
43393 *pPgno = nPage + 1;
43394
43395 if( *pPgno==PENDING_BYTE_PAGE(pBt) ){
43396 (*pPgno)++;
43397 }
43398
43399 #ifndef SQLITE_OMIT_AUTOVACUUM
43400 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, *pPgno) ){
43401 /* If *pPgno refers to a pointer-map page, allocate two new pages
43402 ** at the end of the file instead of one. The first allocated page
43403 ** becomes a new pointer-map page, the second is used by the caller.
43404 */
43405 MemPage *pPg = 0;
43406 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
43407 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43408 rc = btreeGetPage(pBt, *pPgno, &pPg, 0);
43409 if( rc==SQLITE_OK ){
43410 rc = sqlite3PagerWrite(pPg->pDbPage);
43411 releasePage(pPg);
43412 }
43413 if( rc ) return rc;
43414 (*pPgno)++;
43415 if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
43416 }
43417 #endif
 
 
43418
43419 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43420 rc = btreeGetPage(pBt, *pPgno, ppPage, 0);
43421 if( rc ) return rc;
43422 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
43423 if( rc!=SQLITE_OK ){
43424 releasePage(*ppPage);
43425 }
@@ -43605,11 +43779,11 @@
43605 nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
43606 assert( ovflPgno==0 || nOvfl>0 );
43607 while( nOvfl-- ){
43608 Pgno iNext = 0;
43609 MemPage *pOvfl = 0;
43610 if( ovflPgno<2 || ovflPgno>pagerPagecount(pBt) ){
43611 /* 0 is not a legal page number and page 1 cannot be an
43612 ** overflow page. Therefore if ovflPgno<2 or past the end of the
43613 ** file the database must be corrupt. */
43614 return SQLITE_CORRUPT_BKPT;
43615 }
@@ -45437,12 +45611,18 @@
45437 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
45438 if( rc ){
45439 releasePage(pRoot);
45440 return rc;
45441 }
 
 
 
 
 
 
45442 rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
45443 if( rc ){
45444 releasePage(pRoot);
45445 return rc;
45446 }
45447
45448 }else{
@@ -45478,11 +45658,11 @@
45478 int rc;
45479 unsigned char *pCell;
45480 int i;
45481
45482 assert( sqlite3_mutex_held(pBt->mutex) );
45483 if( pgno>pagerPagecount(pBt) ){
45484 return SQLITE_CORRUPT_BKPT;
45485 }
45486
45487 rc = getAndInitPage(pBt, pgno, &pPage);
45488 if( rc ) return rc;
@@ -46229,11 +46409,11 @@
46229 sqlite3BtreeEnter(p);
46230 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
46231 nRef = sqlite3PagerRefcount(pBt->pPager);
46232 sCheck.pBt = pBt;
46233 sCheck.pPager = pBt->pPager;
46234 sCheck.nPage = pagerPagecount(sCheck.pBt);
46235 sCheck.mxErr = mxErr;
46236 sCheck.nErr = 0;
46237 sCheck.mallocFailed = 0;
46238 *pnErr = 0;
46239 if( sCheck.nPage==0 ){
@@ -46831,13 +47011,12 @@
46831 }
46832
46833 /* Now that there is a read-lock on the source database, query the
46834 ** source pager for the number of pages in the database.
46835 */
46836 if( rc==SQLITE_OK ){
46837 rc = sqlite3PagerPagecount(pSrcPager, &nSrcPage);
46838 }
46839 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
46840 const Pgno iSrcPg = p->iNext; /* Source page number */
46841 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
46842 DbPage *pSrcPg; /* Source page object */
46843 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
@@ -48986,11 +49165,11 @@
48986 nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
48987 pKeyInfo = sqlite3Malloc( nByte );
48988 pOp->p4.pKeyInfo = pKeyInfo;
48989 if( pKeyInfo ){
48990 u8 *aSortOrder;
48991 memcpy(pKeyInfo, zP4, nByte);
48992 aSortOrder = pKeyInfo->aSortOrder;
48993 if( aSortOrder ){
48994 pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
48995 memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
48996 }
@@ -53812,18 +53991,13 @@
53812 int i;
53813 sqlite_int64 rowid;
53814 Mem **apArg;
53815 Mem *pX;
53816 } ck;
53817 struct OP_Pagecount_stack_vars {
53818 int p1;
53819 int nPage;
53820 Pager *pPager;
53821 } cl;
53822 struct OP_Trace_stack_vars {
53823 char *zTrace;
53824 } cm;
53825 } u;
53826 /* End automatically generated code
53827 ********************************************************************/
53828
53829 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
@@ -54646,11 +54820,11 @@
54646 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
54647 u.ag.pArg = &aMem[pOp->p2];
54648 for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
54649 u.ag.apVal[u.ag.i] = u.ag.pArg;
54650 sqlite3VdbeMemStoreType(u.ag.pArg);
54651 REGISTER_TRACE(pOp->p2, u.ag.pArg);
54652 }
54653
54654 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
54655 if( pOp->p4type==P4_FUNCDEF ){
54656 u.ag.ctx.pFunc = pOp->p4.pFunc;
@@ -56363,14 +56537,14 @@
56363
56364 /* Opcode: OpenEphemeral P1 P2 * P4 *
56365 **
56366 ** Open a new cursor P1 to a transient table.
56367 ** The cursor is always opened read/write even if
56368 ** the main database is read-only. The transient or virtual
56369 ** table is deleted automatically when the cursor is closed.
56370 **
56371 ** P2 is the number of columns in the virtual table.
56372 ** The cursor points to a BTree table if P4==0 and to a BTree index
56373 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
56374 ** that defines the format of keys in the index.
56375 **
56376 ** This opcode was once called OpenTemp. But that created
@@ -56377,10 +56551,18 @@
56377 ** confusion because the term "temp table", might refer either
56378 ** to a TEMP table at the SQL level, or to a table opened by
56379 ** this opcode. Then this opcode was call OpenVirtual. But
56380 ** that created confusion with the whole virtual-table idea.
56381 */
 
 
 
 
 
 
 
 
56382 case OP_OpenEphemeral: {
56383 #if 0 /* local variables moved into u.ax */
56384 VdbeCursor *pCx;
56385 #endif /* local variables moved into u.ax */
56386 static const int openFlags =
@@ -57515,29 +57697,35 @@
57515 pc = pOp->p2 - 1;
57516 }
57517 break;
57518 }
57519
57520 /* Opcode: Next P1 P2 * * *
57521 **
57522 ** Advance cursor P1 so that it points to the next key/data pair in its
57523 ** table or index. If there are no more key/value pairs then fall through
57524 ** to the following instruction. But if the cursor advance was successful,
57525 ** jump immediately to P2.
57526 **
57527 ** The P1 cursor must be for a real table, not a pseudo-table.
57528 **
 
 
 
57529 ** See also: Prev
57530 */
57531 /* Opcode: Prev P1 P2 * * *
57532 **
57533 ** Back up cursor P1 so that it points to the previous key/data pair in its
57534 ** table or index. If there is no previous key/value pairs then fall through
57535 ** to the following instruction. But if the cursor backup was successful,
57536 ** jump immediately to P2.
57537 **
57538 ** The P1 cursor must be for a real table, not a pseudo-table.
 
 
 
57539 */
57540 case OP_Prev: /* jump */
57541 case OP_Next: { /* jump */
57542 #if 0 /* local variables moved into u.bm */
57543 VdbeCursor *pC;
@@ -57545,10 +57733,11 @@
57545 int res;
57546 #endif /* local variables moved into u.bm */
57547
57548 CHECK_FOR_INTERRUPT;
57549 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 
57550 u.bm.pC = p->apCsr[pOp->p1];
57551 if( u.bm.pC==0 ){
57552 break; /* See ticket #2273 */
57553 }
57554 u.bm.pCrsr = u.bm.pC->pCursor;
@@ -58991,25 +59180,11 @@
58991 /* Opcode: Pagecount P1 P2 * * *
58992 **
58993 ** Write the current number of pages in database P1 to memory cell P2.
58994 */
58995 case OP_Pagecount: { /* out2-prerelease */
58996 #if 0 /* local variables moved into u.cl */
58997 int p1;
58998 int nPage;
58999 Pager *pPager;
59000 #endif /* local variables moved into u.cl */
59001
59002 u.cl.p1 = pOp->p1;
59003 u.cl.pPager = sqlite3BtreePager(db->aDb[u.cl.p1].pBt);
59004 rc = sqlite3PagerPagecount(u.cl.pPager, &u.cl.nPage);
59005 /* OP_Pagecount is always called from within a read transaction. The
59006 ** page count has already been successfully read and cached. So the
59007 ** sqlite3PagerPagecount() call above cannot fail. */
59008 if( ALWAYS(rc==SQLITE_OK) ){
59009 pOut->u.i = u.cl.nPage;
59010 }
59011 break;
59012 }
59013 #endif
59014
59015 #ifndef SQLITE_OMIT_TRACE
@@ -59017,24 +59192,24 @@
59017 **
59018 ** If tracing is enabled (by the sqlite3_trace()) interface, then
59019 ** the UTF-8 string contained in P4 is emitted on the trace callback.
59020 */
59021 case OP_Trace: {
59022 #if 0 /* local variables moved into u.cm */
59023 char *zTrace;
59024 #endif /* local variables moved into u.cm */
59025
59026 u.cm.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59027 if( u.cm.zTrace ){
59028 if( db->xTrace ){
59029 char *z = sqlite3VdbeExpandSql(p, u.cm.zTrace);
59030 db->xTrace(db->pTraceArg, z);
59031 sqlite3DbFree(db, z);
59032 }
59033 #ifdef SQLITE_DEBUG
59034 if( (db->flags & SQLITE_SqlTrace)!=0 ){
59035 sqlite3DebugPrintf("SQL-trace: %s\n", u.cm.zTrace);
59036 }
59037 #endif /* SQLITE_DEBUG */
59038 }
59039 break;
59040 }
@@ -66537,16 +66712,20 @@
66537 int n = sqlite3_column_bytes(pStmt, 2);
66538 if( n>24 ){
66539 n = 24;
66540 }
66541 pSample->nByte = (u8)n;
66542 pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66543 if( pSample->u.z ){
66544 memcpy(pSample->u.z, z, n);
66545 }else{
66546 db->mallocFailed = 1;
66547 break;
 
 
 
 
 
66548 }
66549 }
66550 }
66551 }
66552 }
@@ -75790,11 +75969,11 @@
75790 }else{
75791 for(j=0; j<pColumn->nId; j++){
75792 if( pColumn->a[j].idx==i ) break;
75793 }
75794 }
75795 if( pColumn && j>=pColumn->nId ){
75796 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
75797 }else if( useTempTable ){
75798 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1);
75799 }else{
75800 assert( pSelect==0 ); /* Otherwise useTempTable is true */
@@ -78086,10 +78265,13 @@
78086 { "count_changes", SQLITE_CountRows },
78087 { "empty_result_callbacks", SQLITE_NullCallback },
78088 { "legacy_file_format", SQLITE_LegacyFileFmt },
78089 { "fullfsync", SQLITE_FullFSync },
78090 { "reverse_unordered_selects", SQLITE_ReverseOrder },
 
 
 
78091 #ifdef SQLITE_DEBUG
78092 { "sql_trace", SQLITE_SqlTrace },
78093 { "vdbe_listing", SQLITE_VdbeListing },
78094 { "vdbe_trace", SQLITE_VdbeTrace },
78095 #endif
@@ -79967,10 +80149,11 @@
79967 }
79968
79969 sqlite3VtabUnlockList(db);
79970
79971 pParse->db = db;
 
79972 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
79973 char *zSqlCopy;
79974 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
79975 testcase( nBytes==mxLen );
79976 testcase( nBytes==mxLen+1 );
@@ -79988,10 +80171,11 @@
79988 pParse->zTail = &zSql[nBytes];
79989 }
79990 }else{
79991 sqlite3RunParser(pParse, zSql, &zErrMsg);
79992 }
 
79993
79994 if( db->mallocFailed ){
79995 pParse->rc = SQLITE_NOMEM;
79996 }
79997 if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
@@ -83744,10 +83928,22 @@
83744 if( addrNext ){
83745 sqlite3VdbeResolveLabel(v, addrNext);
83746 sqlite3ExprCacheClear(pParse);
83747 }
83748 }
 
 
 
 
 
 
 
 
 
 
 
 
83749 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
83750 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
83751 }
83752 pAggInfo->directMode = 0;
83753 sqlite3ExprCacheClear(pParse);
@@ -85557,10 +85753,11 @@
85557 pSubParse->db = db;
85558 pSubParse->pTriggerTab = pTab;
85559 pSubParse->pToplevel = pTop;
85560 pSubParse->zAuthContext = pTrigger->zName;
85561 pSubParse->eTriggerOp = pTrigger->op;
 
85562
85563 v = sqlite3GetVdbe(pSubParse);
85564 if( v ){
85565 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
85566 pTrigger->zName, onErrorText(orconf),
@@ -87477,10 +87674,11 @@
87477 if( pParse==0 ){
87478 rc = SQLITE_NOMEM;
87479 }else{
87480 pParse->declareVtab = 1;
87481 pParse->db = db;
 
87482
87483 if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
87484 && pParse->pNewTable
87485 && !db->mallocFailed
87486 && !pParse->pNewTable->pSelect
@@ -87997,19 +88195,21 @@
87997 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
87998 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
87999 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
88000 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
88001 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
 
88002 #define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
88003 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
88004 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
88005 #define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
88006 #define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
88007 #define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
88008 #define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
88009 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
88010 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
 
88011
88012 /*
88013 ** Initialize a preallocated WhereClause structure.
88014 */
88015 static void whereClauseInit(
@@ -89397,10 +89597,238 @@
89397 }
89398 }
89399 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
89400 }
89401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89402 #ifndef SQLITE_OMIT_VIRTUALTABLE
89403 /*
89404 ** Allocate and populate an sqlite3_index_info structure. It is the
89405 ** responsibility of the caller to eventually release the structure
89406 ** by passing the pointer returned by this function to sqlite3_free().
@@ -89581,10 +90009,11 @@
89581 struct sqlite3_index_constraint *pIdxCons;
89582 struct sqlite3_index_constraint_usage *pUsage;
89583 WhereTerm *pTerm;
89584 int i, j;
89585 int nOrderBy;
 
89586
89587 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
89588 ** malloc in allocateIndexInfo() fails and this function returns leaving
89589 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
89590 */
@@ -89666,22 +90095,31 @@
89666 for(i=0; i<pIdxInfo->nConstraint; i++){
89667 if( pUsage[i].argvIndex>0 ){
89668 pCost->used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight;
89669 }
89670 }
 
 
 
 
 
 
 
 
 
89671
89672 /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
89673 ** inital value of lowestCost in this loop. If it is, then the
89674 ** (cost<lowestCost) test below will never be true.
89675 **
89676 ** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT
89677 ** is defined.
89678 */
89679 if( (SQLITE_BIG_DBL/((double)2))<pIdxInfo->estimatedCost ){
89680 pCost->rCost = (SQLITE_BIG_DBL/((double)2));
89681 }else{
89682 pCost->rCost = pIdxInfo->estimatedCost;
89683 }
89684 pCost->plan.u.pVtabIdx = pIdxInfo;
89685 if( pIdxInfo->orderByConsumed ){
89686 pCost->plan.wsFlags |= WHERE_ORDERBY;
89687 }
@@ -90175,11 +90613,11 @@
90175 }
90176 }
90177
90178 /* If currently calculating the cost of using an index (not the IPK
90179 ** index), determine if all required column data may be obtained without
90180 ** seeking to entries in the main table (i.e. if the index is a covering
90181 ** index for this query). If it is, set the WHERE_IDX_ONLY flag in
90182 ** wsFlags. Otherwise, set the bLookup variable to true. */
90183 if( pIdx && wsFlags ){
90184 Bitmask m = pSrc->colUsed;
90185 int j;
@@ -90233,14 +90671,14 @@
90233 cost /= (double)2;
90234 }
90235 /**** Cost of using this index has now been computed ****/
90236
90237 WHERETRACE((
90238 "tbl=%s idx=%s nEq=%d nInMul=%d nBound=%d bSort=%d bLookup=%d"
90239 " wsFlags=%d (nRow=%.2f cost=%.2f)\n",
90240 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
90241 nEq, nInMul, nBound, bSort, bLookup, wsFlags, nRow, cost
90242 ));
90243
90244 /* If this index is the best we have seen so far, then record this
90245 ** index and its cost in the pCost structure.
90246 */
@@ -90281,10 +90719,11 @@
90281 WHERETRACE(("best index is: %s\n",
90282 (pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
90283 ));
90284
90285 bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
 
90286 pCost->plan.wsFlags |= eqTermMask;
90287 }
90288
90289 /*
90290 ** Find the query plan for accessing table pSrc->pTab. Write the
@@ -90750,11 +91189,15 @@
90750 }
90751 start = sqlite3VdbeCurrentAddr(v);
90752 pLevel->op = bRev ? OP_Prev : OP_Next;
90753 pLevel->p1 = iCur;
90754 pLevel->p2 = start;
90755 pLevel->p5 = (pStart==0 && pEnd==0) ?1:0;
 
 
 
 
90756 if( testOp!=OP_Noop ){
90757 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
90758 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
90759 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
90760 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
@@ -91219,10 +91662,17 @@
91219 if( pInfo->needToFreeIdxStr ){
91220 sqlite3_free(pInfo->idxStr);
91221 }
91222 sqlite3DbFree(db, pInfo);
91223 }
 
 
 
 
 
 
 
91224 }
91225 whereClauseClear(pWInfo->pWC);
91226 sqlite3DbFree(db, pWInfo);
91227 }
91228 }
@@ -91365,18 +91815,21 @@
91365 nByteWInfo +
91366 sizeof(WhereClause) +
91367 sizeof(WhereMaskSet)
91368 );
91369 if( db->mallocFailed ){
 
 
91370 goto whereBeginError;
91371 }
91372 pWInfo->nLevel = nTabList;
91373 pWInfo->pParse = pParse;
91374 pWInfo->pTabList = pTabList;
91375 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
91376 pWInfo->pWC = pWC = (WhereClause *)&((u8 *)pWInfo)[nByteWInfo];
91377 pWInfo->wctrlFlags = wctrlFlags;
 
91378 pMaskSet = (WhereMaskSet*)&pWC[1];
91379
91380 /* Split the WHERE clause into separate subexpressions where each
91381 ** subexpression is separated by an AND operator.
91382 */
@@ -91552,17 +92005,20 @@
91552 if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
91553 *ppOrderBy = 0;
91554 }
91555 andFlags &= bestPlan.plan.wsFlags;
91556 pLevel->plan = bestPlan.plan;
91557 if( bestPlan.plan.wsFlags & WHERE_INDEXED ){
 
 
91558 pLevel->iIdxCur = pParse->nTab++;
91559 }else{
91560 pLevel->iIdxCur = -1;
91561 }
91562 notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
91563 pLevel->iFrom = (u8)bestJ;
 
91564
91565 /* Check that if the table scanned by this loop iteration had an
91566 ** INDEXED BY clause attached to it, that the named index is being
91567 ** used for the scan. If not, then query compilation has failed.
91568 ** Return an error.
@@ -91605,10 +92061,11 @@
91605
91606 /* Open all tables in the pTabList and any indices selected for
91607 ** searching those tables.
91608 */
91609 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
 
91610 for(i=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
91611 Table *pTab; /* Table to open */
91612 int iDb; /* Index of database containing table/index */
91613
91614 #ifndef SQLITE_OMIT_EXPLAIN
@@ -91617,11 +92074,13 @@
91617 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
91618 zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
91619 if( pItem->zAlias ){
91620 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
91621 }
91622 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
 
 
91623 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
91624 zMsg, pLevel->plan.u.pIdx->zName);
91625 }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
91626 zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
91627 }else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
@@ -91640,12 +92099,15 @@
91640 sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
91641 }
91642 #endif /* SQLITE_OMIT_EXPLAIN */
91643 pTabItem = &pTabList->a[pLevel->iFrom];
91644 pTab = pTabItem->pTab;
 
91645 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
91646 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
 
 
91647 #ifndef SQLITE_OMIT_VIRTUALTABLE
91648 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
91649 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
91650 int iCur = pTabItem->iCursor;
91651 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
@@ -91664,11 +92126,15 @@
91664 assert( n<=pTab->nCol );
91665 }
91666 }else{
91667 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
91668 }
91669 pLevel->iTabCur = pTabItem->iCursor;
 
 
 
 
91670 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
91671 Index *pIx = pLevel->plan.u.pIdx;
91672 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
91673 int iIdxCur = pLevel->iIdxCur;
91674 assert( pIx->pSchema==pTab->pSchema );
@@ -91676,12 +92142,14 @@
91676 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
91677 (char*)pKey, P4_KEYINFO_HANDOFF);
91678 VdbeComment((v, "%s", pIx->zName));
91679 }
91680 sqlite3CodeVerifySchema(pParse, iDb);
 
91681 }
91682 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
 
91683
91684 /* Generate the code to do the search. Each iteration of the for
91685 ** loop below generates code for a single nested loop of the VM
91686 ** program.
91687 */
@@ -91745,11 +92213,14 @@
91745 */
91746 return pWInfo;
91747
91748 /* Jump here if malloc fails */
91749 whereBeginError:
91750 whereInfoFree(db, pWInfo);
 
 
 
91751 return 0;
91752 }
91753
91754 /*
91755 ** Generate the end of the WHERE loop. See comments on
@@ -91815,16 +92286,19 @@
91815 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
91816 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
91817 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
91818 Table *pTab = pTabItem->pTab;
91819 assert( pTab!=0 );
91820 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
91821 if( (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0 ){
91822 if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
 
 
 
91823 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
91824 }
91825 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
91826 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
91827 }
91828 }
91829
91830 /* If this scan uses an index, make code substitutions to read data
@@ -91868,11 +92342,14 @@
91868 }
91869 }
91870
91871 /* Final cleanup
91872 */
91873 whereInfoFree(db, pWInfo);
 
 
 
91874 return;
91875 }
91876
91877 /************** End of where.c ***********************************************/
91878 /************** Begin file parse.c *******************************************/
@@ -98071,11 +98548,11 @@
98071 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
98072 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
98073 db->autoCommit = 1;
98074 db->nextAutovac = -1;
98075 db->nextPagesize = 0;
98076 db->flags |= SQLITE_ShortColNames
98077 #if SQLITE_DEFAULT_FILE_FORMAT<4
98078 | SQLITE_LegacyFileFmt
98079 #endif
98080 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
98081 | SQLITE_LoadExtension
@@ -99199,11 +99676,11 @@
99199 ** and so on.
99200 **
99201 ** This is similar in concept to how sqlite encodes "varints" but
99202 ** the encoding is not the same. SQLite varints are big-endian
99203 ** are are limited to 9 bytes in length whereas FTS3 varints are
99204 ** little-endian and can be upt to 10 bytes in length (in theory).
99205 **
99206 ** Example encodings:
99207 **
99208 ** 1: 0x01
99209 ** 127: 0x7f
@@ -99210,30 +99687,30 @@
99210 ** 128: 0x81 0x00
99211 **
99212 **
99213 **** Document lists ****
99214 ** A doclist (document list) holds a docid-sorted list of hits for a
99215 ** given term. Doclists hold docids, and can optionally associate
99216 ** token positions and offsets with docids. A position is the index
99217 ** of a word within the document. The first word of the document has
99218 ** a position of 0.
99219 **
99220 ** FTS3 used to optionally store character offsets using a compile-time
99221 ** option. But that functionality is no longer supported.
99222 **
99223 ** A DL_POSITIONS_OFFSETS doclist is stored like this:
99224 **
99225 ** array {
99226 ** varint docid;
99227 ** array { (position list for column 0)
99228 ** varint position; (delta from previous position plus POS_BASE)
99229 ** }
99230 ** array {
99231 ** varint POS_COLUMN; (marks start of position list for new column)
99232 ** varint column; (index of new column)
99233 ** array {
99234 ** varint position; (delta from previous position plus POS_BASE)
99235 ** }
99236 ** }
99237 ** varint POS_END; (marks end of positions for this document.
99238 ** }
99239 **
@@ -99241,11 +99718,11 @@
99241 ** memory. A "position" is an index of a token in the token stream
99242 ** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
99243 ** in the same logical place as the position element, and act as sentinals
99244 ** ending a position list array. POS_END is 0. POS_COLUMN is 1.
99245 ** The positions numbers are not stored literally but rather as two more
99246 ** the difference from the prior position, or the just the position plus
99247 ** 2 for the first position. Example:
99248 **
99249 ** label: A B C D E F G H I J K
99250 ** value: 123 5 9 1 1 14 35 0 234 72 0
99251 **
@@ -99255,18 +99732,18 @@
99255 ** new column is column number 1. There are two positions at 12 and 45
99256 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
99257 ** 234 at I is the next docid. It has one position 72 (72-2) and then
99258 ** terminates with the 0 at K.
99259 **
99260 ** A DL_POSITIONS doclist omits the startOffset and endOffset
99261 ** information. A DL_DOCIDS doclist omits both the position and
99262 ** offset information, becoming an array of varint-encoded docids.
99263 **
99264 ** On-disk data is stored as type DL_DEFAULT, so we don't serialize
99265 ** the type. Due to how deletion is implemented in the segmentation
99266 ** system, on-disk doclists MUST store at least positions.
99267 **
99268 **
99269 **** Segment leaf nodes ****
99270 ** Segment leaf nodes store terms and doclists, ordered by term. Leaf
99271 ** nodes are written using LeafWriter, and read using LeafReader (to
99272 ** iterate through a single leaf node's data) and LeavesReader (to
@@ -99776,10 +100253,24 @@
99776 ** Maximum length of a varint encoded integer. The varint format is different
99777 ** from that used by SQLite, so the maximum length is 10, not 9.
99778 */
99779 #define FTS3_VARINT_MAX 10
99780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99781 /*
99782 ** This section provides definitions to allow the
99783 ** FTS3 extension to be compiled outside of the
99784 ** amalgamation.
99785 */
@@ -100087,12 +100578,11 @@
100087 *pi = (int) i;
100088 return ret;
100089 }
100090
100091 /*
100092 ** Return the number of bytes required to store the value passed as the
100093 ** first argument in varint form.
100094 */
100095 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
100096 int i = 0;
100097 do{
100098 i++;
@@ -100139,11 +100629,11 @@
100139 }
100140 }
100141
100142 /*
100143 ** Read a single varint from the doclist at *pp and advance *pp to point
100144 ** to the next element of the varlist. Add the value of the varint
100145 ** to *pVal.
100146 */
100147 static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
100148 sqlite3_int64 iVal;
100149 *pp += sqlite3Fts3GetVarint(*pp, &iVal);
@@ -100195,11 +100685,11 @@
100195 ** and then evaluate those statements. The success code is writting
100196 ** into *pRc.
100197 **
100198 ** If *pRc is initially non-zero then this routine is a no-op.
100199 */
100200 void fts3DbExec(
100201 int *pRc, /* Success code */
100202 sqlite3 *db, /* Database in which to run SQL */
100203 const char *zFormat, /* Format string for SQL */
100204 ... /* Arguments to the format string */
100205 ){
@@ -100275,10 +100765,14 @@
100275
100276 /*
100277 ** Create the backing store tables (%_content, %_segments and %_segdir)
100278 ** required by the FTS3 table passed as the only argument. This is done
100279 ** as part of the vtab xCreate() method.
 
 
 
 
100280 */
100281 static int fts3CreateTables(Fts3Table *p){
100282 int rc = SQLITE_OK; /* Return code */
100283 int i; /* Iterator variable */
100284 char *zContentCols; /* Columns of %_content table */
@@ -100367,11 +100861,11 @@
100367 ** This function is the implementation of both the xConnect and xCreate
100368 ** methods of the FTS3 virtual table.
100369 **
100370 ** The argv[] array contains the following:
100371 **
100372 ** argv[0] -> module name
100373 ** argv[1] -> database name
100374 ** argv[2] -> table name
100375 ** argv[...] -> "column name" and other module argument fields.
100376 */
100377 static int fts3InitVtab(
@@ -100386,16 +100880,16 @@
100386 Fts3Hash *pHash = (Fts3Hash *)pAux;
100387 Fts3Table *p; /* Pointer to allocated vtab */
100388 int rc; /* Return code */
100389 int i; /* Iterator variable */
100390 int nByte; /* Size of allocation used for *p */
100391 int iCol;
100392 int nString = 0;
100393 int nCol = 0;
100394 char *zCsr;
100395 int nDb;
100396 int nName;
100397
100398 const char *zTokenizer = 0; /* Name of tokenizer to use */
100399 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
100400
100401 nDb = (int)strlen(argv[1]) + 1;
@@ -100621,10 +101115,15 @@
100621 sqlite3_free(pCsr->aMatchinfo);
100622 sqlite3_free(pCsr);
100623 return SQLITE_OK;
100624 }
100625
 
 
 
 
 
100626 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
100627 if( pCsr->isRequireSeek ){
100628 pCsr->isRequireSeek = 0;
100629 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
100630 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
@@ -100647,10 +101146,21 @@
100647 }else{
100648 return SQLITE_OK;
100649 }
100650 }
100651
 
 
 
 
 
 
 
 
 
 
 
100652 static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
100653 int rc = SQLITE_OK; /* Return code */
100654 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
100655
100656 if( pCsr->aDoclist==0 ){
@@ -100782,10 +101292,15 @@
100782
100783 /*
100784 ** When this function is called, *ppPoslist is assumed to point to the
100785 ** start of a position-list. After it returns, *ppPoslist points to the
100786 ** first byte after the position-list.
 
 
 
 
 
100787 **
100788 ** If pp is not NULL, then the contents of the position list are copied
100789 ** to *pp. *pp is set to point to the first byte past the last byte copied
100790 ** before this function returns.
100791 */
@@ -100792,21 +101307,24 @@
100792 static void fts3PoslistCopy(char **pp, char **ppPoslist){
100793 char *pEnd = *ppPoslist;
100794 char c = 0;
100795
100796 /* The end of a position list is marked by a zero encoded as an FTS3
100797 ** varint. A single 0x00 byte. Except, if the 0x00 byte is preceded by
100798 ** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
100799 ** of some other, multi-byte, value.
100800 **
100801 ** The following block moves pEnd to point to the first byte that is not
100802 ** immediately preceded by a byte with the 0x80 bit set. Then increments
100803 ** pEnd once more so that it points to the byte immediately following the
100804 ** last byte in the position-list.
100805 */
100806 while( *pEnd | c ) c = *pEnd++ & 0x80;
100807 pEnd++;
 
 
 
100808
100809 if( pp ){
100810 int n = (int)(pEnd - *ppPoslist);
100811 char *p = *pp;
100812 memcpy(p, *ppPoslist, n);
@@ -100814,16 +101332,38 @@
100814 *pp = p;
100815 }
100816 *ppPoslist = pEnd;
100817 }
100818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100819 static void fts3ColumnlistCopy(char **pp, char **ppPoslist){
100820 char *pEnd = *ppPoslist;
100821 char c = 0;
100822
100823 /* A column-list is terminated by either a 0x01 or 0x00. */
100824 while( 0xFE & (*pEnd | c) ) c = *pEnd++ & 0x80;
 
 
 
 
 
100825 if( pp ){
100826 int n = (int)(pEnd - *ppPoslist);
100827 char *p = *pp;
100828 memcpy(p, *ppPoslist, n);
100829 p += n;
@@ -100831,41 +101371,49 @@
100831 }
100832 *ppPoslist = pEnd;
100833 }
100834
100835 /*
100836 ** Value used to signify the end of an offset-list. This is safe because
100837 ** it is not possible to have a document with 2^31 terms.
100838 */
100839 #define OFFSET_LIST_END 0x7fffffff
100840
100841 /*
100842 ** This function is used to help parse offset-lists. When this function is
100843 ** called, *pp may point to the start of the next varint in the offset-list
100844 ** being parsed, or it may point to 1 byte past the end of the offset-list
100845 ** (in which case **pp will be 0x00 or 0x01).
 
100846 **
100847 ** If *pp points past the end of the current offset list, set *pi to
100848 ** OFFSET_LIST_END and return. Otherwise, read the next varint from *pp,
100849 ** increment the current value of *pi by the value read, and set *pp to
100850 ** point to the next value before returning.
 
 
 
 
 
 
100851 */
100852 static void fts3ReadNextPos(
100853 char **pp, /* IN/OUT: Pointer into offset-list buffer */
100854 sqlite3_int64 *pi /* IN/OUT: Value read from offset-list */
100855 ){
100856 if( **pp&0xFE ){
100857 fts3GetDeltaVarint(pp, pi);
100858 *pi -= 2;
100859 }else{
100860 *pi = OFFSET_LIST_END;
100861 }
100862 }
100863
100864 /*
100865 ** If parameter iCol is not 0, write an 0x01 byte followed by the value of
100866 ** iCol encoded as a varint to *pp.
 
100867 **
100868 ** Set *pp to point to the byte just after the last byte written before
100869 ** returning (do not modify it if iCol==0). Return the total number of bytes
100870 ** written (0 if iCol==0).
100871 */
@@ -100879,11 +101427,15 @@
100879 }
100880 return n;
100881 }
100882
100883 /*
100884 **
 
 
 
 
100885 */
100886 static void fts3PoslistMerge(
100887 char **pp, /* Output buffer */
100888 char **pp1, /* Left input list */
100889 char **pp2 /* Right input list */
@@ -100891,36 +101443,37 @@
100891 char *p = *pp;
100892 char *p1 = *pp1;
100893 char *p2 = *pp2;
100894
100895 while( *p1 || *p2 ){
100896 int iCol1;
100897 int iCol2;
100898
100899 if( *p1==0x01 ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
100900 else if( *p1==0x00 ) iCol1 = OFFSET_LIST_END;
100901 else iCol1 = 0;
100902
100903 if( *p2==0x01 ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
100904 else if( *p2==0x00 ) iCol2 = OFFSET_LIST_END;
100905 else iCol2 = 0;
100906
100907 if( iCol1==iCol2 ){
100908 sqlite3_int64 i1 = 0;
100909 sqlite3_int64 i2 = 0;
100910 sqlite3_int64 iPrev = 0;
100911 int n = fts3PutColNumber(&p, iCol1);
100912 p1 += n;
100913 p2 += n;
100914
100915 /* At this point, both p1 and p2 point to the start of offset-lists.
100916 ** An offset-list is a list of non-negative delta-encoded varints, each
100917 ** incremented by 2 before being stored. Each list is terminated by a 0
100918 ** or 1 value (0x00 or 0x01). The following block merges the two lists
 
100919 ** and writes the results to buffer p. p is left pointing to the byte
100920 ** after the list written. No terminator (0x00 or 0x01) is written to
100921 ** the output.
100922 */
100923 fts3GetDeltaVarint(&p1, &i1);
100924 fts3GetDeltaVarint(&p2, &i2);
100925 do {
100926 fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
@@ -100931,21 +101484,21 @@
100931 }else if( i1<i2 ){
100932 fts3ReadNextPos(&p1, &i1);
100933 }else{
100934 fts3ReadNextPos(&p2, &i2);
100935 }
100936 }while( i1!=OFFSET_LIST_END || i2!=OFFSET_LIST_END );
100937 }else if( iCol1<iCol2 ){
100938 p1 += fts3PutColNumber(&p, iCol1);
100939 fts3ColumnlistCopy(&p, &p1);
100940 }else{
100941 p2 += fts3PutColNumber(&p, iCol2);
100942 fts3ColumnlistCopy(&p, &p2);
100943 }
100944 }
100945
100946 *p++ = '\0';
100947 *pp = p;
100948 *pp1 = p1 + 1;
100949 *pp2 = p2 + 1;
100950 }
100951
@@ -100964,15 +101517,15 @@
100964 char *p2 = *pp2;
100965
100966 int iCol1 = 0;
100967 int iCol2 = 0;
100968 assert( *p1!=0 && *p2!=0 );
100969 if( *p1==0x01 ){
100970 p1++;
100971 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
100972 }
100973 if( *p2==0x01 ){
100974 p2++;
100975 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
100976 }
100977
100978 while( 1 ){
@@ -100981,15 +101534,16 @@
100981 sqlite3_int64 iPrev = 0;
100982 sqlite3_int64 iPos1 = 0;
100983 sqlite3_int64 iPos2 = 0;
100984
100985 if( pp && iCol1 ){
100986 *p++ = 0x01;
100987 p += sqlite3Fts3PutVarint(p, iCol1);
100988 }
100989
100990 assert( *p1!=0x00 && *p2!=0x00 && *p1!=0x01 && *p2!=0x01 );
 
100991 fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
100992 fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
100993
100994 while( 1 ){
100995 if( iPos2>iPos1 && iPos2<=iPos1+nToken ){
@@ -101237,10 +101791,11 @@
101237 }
101238
101239 default: assert( mergetype==MERGE_POS_NEAR || mergetype==MERGE_NEAR ); {
101240 char *aTmp = 0;
101241 char **ppPos = 0;
 
101242 if( mergetype==MERGE_POS_NEAR ){
101243 ppPos = &p;
101244 aTmp = sqlite3_malloc(2*(n1+n2+1));
101245 if( !aTmp ){
101246 return SQLITE_NOMEM;
@@ -101341,13 +101896,13 @@
101341 ** This function retreives the doclist for the specified term (or term
101342 ** prefix) from the database.
101343 **
101344 ** The returned doclist may be in one of two formats, depending on the
101345 ** value of parameter isReqPos. If isReqPos is zero, then the doclist is
101346 ** a sorted list of delta-compressed docids. If isReqPos is non-zero,
101347 ** then the returned list is in the same format as is stored in the
101348 ** database without the found length specifier at the start of on-disk
101349 ** doclists.
101350 */
101351 static int fts3TermSelect(
101352 Fts3Table *p, /* Virtual table handle */
101353 int iColumn, /* Column to query (or -ve for all columns) */
@@ -101603,11 +102158,13 @@
101603 return rc;
101604 }
101605
101606 /*
101607 ** Evaluate the full-text expression pExpr against fts3 table pTab. Store
101608 ** the resulting doclist in *paOut and *pnOut.
 
 
101609 */
101610 static int evalFts3Expr(
101611 Fts3Table *p, /* Virtual table handle */
101612 Fts3Expr *pExpr, /* Parsed fts3 expression */
101613 char **paOut, /* OUT: Pointer to malloc'd result buffer */
@@ -108163,11 +108720,11 @@
108163 ** This is done as part of extracting the snippet text, not when selecting
108164 ** the snippet. Snippet selection is done based on doclists only, so there
108165 ** is no way for fts3BestSnippet() to know whether or not the document
108166 ** actually contains terms that follow the final highlighted term.
108167 */
108168 int fts3SnippetShift(
108169 Fts3Table *pTab, /* FTS3 table snippet comes from */
108170 int nSnippet, /* Number of tokens desired for snippet */
108171 const char *zDoc, /* Document text to extract snippet from */
108172 int nDoc, /* Size of buffer zDoc in bytes */
108173 int *piPos, /* IN/OUT: First token of snippet */
@@ -111280,10 +111837,11 @@
111280 rc = SQLITE_CONSTRAINT;
111281 goto constraint;
111282 }
111283 rc = sqlite3_reset(pRtree->pReadRowid);
111284 }
 
111285
111286 if( rc==SQLITE_OK ){
111287 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
111288 }
111289 if( rc==SQLITE_OK ){
111290
--- 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.6.23. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one 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% are more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -321,11 +321,11 @@
321 ** to generate appropriate macros for a wide range of compilers.
322 **
323 ** The correct "ANSI" way to do this is to use the intptr_t type.
324 ** Unfortunately, that typedef is not available on all compilers, or
325 ** if it is available, it requires an #include of specific headers
326 ** that vary from one machine to the next.
327 **
328 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on
329 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)).
330 ** So we have to define the macros in different ways depending on the
331 ** compiler.
@@ -626,13 +626,13 @@
626 **
627 ** See also: [sqlite3_libversion()],
628 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
629 ** [sqlite_version()] and [sqlite_source_id()].
630 */
631 #define SQLITE_VERSION "3.6.23"
632 #define SQLITE_VERSION_NUMBER 3006023
633 #define SQLITE_SOURCE_ID "2010-04-07 19:32:00 1f40441204d9a912b1d6b67ff6ff9e17146c7abd"
634
635 /*
636 ** CAPI3REF: Run-Time Library Version Numbers
637 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
638 **
@@ -665,11 +665,10 @@
665 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
666 SQLITE_API const char *sqlite3_libversion(void);
667 SQLITE_API const char *sqlite3_sourceid(void);
668 SQLITE_API int sqlite3_libversion_number(void);
669
 
670 /*
671 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
672 **
673 ** ^The sqlite3_compileoption_used() function returns 0 or 1
674 ** indicating whether the specified option was defined at
@@ -688,13 +687,14 @@
687 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
688 **
689 ** See also: SQL functions [sqlite_compileoption_used()] and
690 ** [sqlite_compileoption_get()] and the [compile_options pragma].
691 */
692 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
693 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
694 SQLITE_API const char *sqlite3_compileoption_get(int N);
695 #endif
696
697 /*
698 ** CAPI3REF: Test To See If The Library Is Threadsafe
699 **
700 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -1492,15 +1492,14 @@
1492 **
1493 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1494 ** ^If the option is unknown or SQLite is unable to set the option
1495 ** then this routine returns a non-zero [error code].
1496 */
1497 SQLITE_API int sqlite3_config(int, ...);
1498
1499 /*
1500 ** CAPI3REF: Configure database connections
 
1501 **
1502 ** The sqlite3_db_config() interface is used to make configuration
1503 ** changes to a [database connection]. The interface is similar to
1504 ** [sqlite3_config()] except that the changes apply to a single
1505 ** [database connection] (specified in the first argument). The
@@ -1516,15 +1515,14 @@
1515 ** Additional arguments depend on the verb.
1516 **
1517 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1518 ** the call is considered successful.
1519 */
1520 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1521
1522 /*
1523 ** CAPI3REF: Memory Allocation Routines
 
1524 **
1525 ** An instance of this object defines the interface between SQLite
1526 ** and low-level memory allocation routines.
1527 **
1528 ** This object is used in only one place in the SQLite interface.
@@ -1602,11 +1600,10 @@
1600 void *pAppData; /* Argument to xInit() and xShutdown() */
1601 };
1602
1603 /*
1604 ** CAPI3REF: Configuration Options
 
1605 **
1606 ** These constants are the available integer configuration options that
1607 ** can be passed as the first argument to the [sqlite3_config()] interface.
1608 **
1609 ** New configuration options may be added in future releases of SQLite.
@@ -1788,10 +1785,28 @@
1785 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1786 ** <dd> ^(This option takes a single argument which is a pointer to an
1787 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1788 ** page cache implementation into that object.)^ </dd>
1789 **
1790 ** <dt>SQLITE_CONFIG_LOG</dt>
1791 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1792 ** function with a call signature of void(*)(void*,int,const char*),
1793 ** and a pointer to void. ^If the function pointer is not NULL, it is
1794 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1795 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1796 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1797 ** passed through as the first parameter to the application-defined logger
1798 ** function whenever that function is invoked. ^The second parameter to
1799 ** the logger function is a copy of the first parameter to the corresponding
1800 ** [sqlite3_log()] call and is intended to be a [result code] or an
1801 ** [extended result code]. ^The third parameter passed to the logger is
1802 ** log message after formatting via [sqlite3_snprintf()].
1803 ** The SQLite logging interface is not reentrant; the logger function
1804 ** supplied by the application must not invoke any SQLite interface.
1805 ** In a multi-threaded application, the application-defined logger
1806 ** function must be threadsafe. </dd>
1807 **
1808 ** </dl>
1809 */
1810 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1811 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1812 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1808,12 +1823,11 @@
1823 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1824 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1825 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1826
1827 /*
1828 ** CAPI3REF: Database Connection Configuration Options
 
1829 **
1830 ** These constants are the available integer configuration options that
1831 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1832 **
1833 ** New configuration options may be added in future releases of SQLite.
@@ -2585,11 +2599,10 @@
2599 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2600 #define SQLITE_COPY 0 /* No longer used */
2601
2602 /*
2603 ** CAPI3REF: Tracing And Profiling Functions
 
2604 **
2605 ** These routines register callback functions that can be used for
2606 ** tracing and profiling the execution of SQL statements.
2607 **
2608 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2603,11 +2616,11 @@
2616 ** ^The callback function registered by sqlite3_profile() is invoked
2617 ** as each SQL statement finishes. ^The profile callback contains
2618 ** the original statement text and an estimate of wall-clock time
2619 ** of how long that statement took to run.
2620 */
2621 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2622 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2623 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2624
2625 /*
2626 ** CAPI3REF: Query Progress Callbacks
@@ -4208,11 +4221,11 @@
4221 sqlite3*,
4222 void*,
4223 void(*)(void*,sqlite3*,int eTextRep,const void*)
4224 );
4225
4226 #ifdef SQLITE_HAS_CODEC
4227 /*
4228 ** Specify the key for an encrypted database. This routine should be
4229 ** called right after sqlite3_open().
4230 **
4231 ** The code to implement this API is not available in the public release
@@ -4678,12 +4691,10 @@
4691 ** ^This function disables automatic extensions in all threads.
4692 */
4693 SQLITE_API void sqlite3_reset_auto_extension(void);
4694
4695 /*
 
 
4696 ** The interface to the virtual-table mechanism is currently considered
4697 ** to be experimental. The interface might change in incompatible ways.
4698 ** If this is a problem for you, do not use the interface at this time.
4699 **
4700 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4699,11 +4710,10 @@
4710 typedef struct sqlite3_module sqlite3_module;
4711
4712 /*
4713 ** CAPI3REF: Virtual Table Object
4714 ** KEYWORDS: sqlite3_module {virtual table module}
 
4715 **
4716 ** This structure, sometimes called a a "virtual table module",
4717 ** defines the implementation of a [virtual tables].
4718 ** This structure consists mostly of methods for the module.
4719 **
@@ -4746,11 +4756,10 @@
4756 };
4757
4758 /*
4759 ** CAPI3REF: Virtual Table Indexing Information
4760 ** KEYWORDS: sqlite3_index_info
 
4761 **
4762 ** The sqlite3_index_info structure and its substructures is used to
4763 ** pass information into and receive the reply from the [xBestIndex]
4764 ** method of a [virtual table module]. The fields under **Inputs** are the
4765 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4828,11 +4837,10 @@
4837 #define SQLITE_INDEX_CONSTRAINT_GE 32
4838 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4839
4840 /*
4841 ** CAPI3REF: Register A Virtual Table Implementation
 
4842 **
4843 ** ^These routines are used to register a new [virtual table module] name.
4844 ** ^Module names must be registered before
4845 ** creating a new [virtual table] using the module and before using a
4846 ** preexisting [virtual table] for the module.
@@ -4850,17 +4858,17 @@
4858 ** invoke the destructor function (if it is not NULL) when SQLite
4859 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4860 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4861 ** destructor.
4862 */
4863 SQLITE_API int sqlite3_create_module(
4864 sqlite3 *db, /* SQLite connection to register module with */
4865 const char *zName, /* Name of the module */
4866 const sqlite3_module *p, /* Methods for the module */
4867 void *pClientData /* Client data for xCreate/xConnect */
4868 );
4869 SQLITE_API int sqlite3_create_module_v2(
4870 sqlite3 *db, /* SQLite connection to register module with */
4871 const char *zName, /* Name of the module */
4872 const sqlite3_module *p, /* Methods for the module */
4873 void *pClientData, /* Client data for xCreate/xConnect */
4874 void(*xDestroy)(void*) /* Module destructor function */
@@ -4867,11 +4875,10 @@
4875 );
4876
4877 /*
4878 ** CAPI3REF: Virtual Table Instance Object
4879 ** KEYWORDS: sqlite3_vtab
 
4880 **
4881 ** Every [virtual table module] implementation uses a subclass
4882 ** of this object to describe a particular instance
4883 ** of the [virtual table]. Each subclass will
4884 ** be tailored to the specific needs of the module implementation.
@@ -4893,11 +4900,10 @@
4900 };
4901
4902 /*
4903 ** CAPI3REF: Virtual Table Cursor Object
4904 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
 
4905 **
4906 ** Every [virtual table module] implementation uses a subclass of the
4907 ** following structure to describe cursors that point into the
4908 ** [virtual table] and are used
4909 ** to loop through the virtual table. Cursors are created using the
@@ -4915,22 +4921,20 @@
4921 /* Virtual table implementations will typically add additional fields */
4922 };
4923
4924 /*
4925 ** CAPI3REF: Declare The Schema Of A Virtual Table
 
4926 **
4927 ** ^The [xCreate] and [xConnect] methods of a
4928 ** [virtual table module] call this interface
4929 ** to declare the format (the names and datatypes of the columns) of
4930 ** the virtual tables they implement.
4931 */
4932 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4933
4934 /*
4935 ** CAPI3REF: Overload A Function For A Virtual Table
 
4936 **
4937 ** ^(Virtual tables can provide alternative implementations of functions
4938 ** using the [xFindFunction] method of the [virtual table module].
4939 ** But global versions of those functions
4940 ** must exist in order to be overloaded.)^
@@ -4941,22 +4945,20 @@
4945 ** of the new function always causes an exception to be thrown. So
4946 ** the new function is not good for anything by itself. Its only
4947 ** purpose is to be a placeholder function that can be overloaded
4948 ** by a [virtual table].
4949 */
4950 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4951
4952 /*
4953 ** The interface to the virtual-table mechanism defined above (back up
4954 ** to a comment remarkably similar to this one) is currently considered
4955 ** to be experimental. The interface might change in incompatible ways.
4956 ** If this is a problem for you, do not use the interface at this time.
4957 **
4958 ** When the virtual-table mechanism stabilizes, we will declare the
4959 ** interface fixed, support it indefinitely, and remove this comment.
 
 
4960 */
4961
4962 /*
4963 ** CAPI3REF: A Handle To An Open BLOB
4964 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -5295,11 +5297,10 @@
5297 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
5298 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
5299
5300 /*
5301 ** CAPI3REF: Mutex Methods Object
 
5302 **
5303 ** An instance of this structure defines the low-level routines
5304 ** used to allocate and use mutexes.
5305 **
5306 ** Usually, the default mutex implementations provided by SQLite are
@@ -5512,11 +5513,10 @@
5513 #define SQLITE_TESTCTRL_ISKEYWORD 16
5514 #define SQLITE_TESTCTRL_LAST 16
5515
5516 /*
5517 ** CAPI3REF: SQLite Runtime Status
 
5518 **
5519 ** ^This interface is used to retrieve runtime status information
5520 ** about the preformance of SQLite, and optionally to reset various
5521 ** highwater marks. ^The first argument is an integer code for
5522 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5540,16 +5540,15 @@
5540 ** and it is possible that another thread might change the parameter
5541 ** in between the times when *pCurrent and *pHighwater are written.
5542 **
5543 ** See also: [sqlite3_db_status()]
5544 */
5545 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5546
5547
5548 /*
5549 ** CAPI3REF: Status Parameters
 
5550 **
5551 ** These integer constants designate various run-time status parameters
5552 ** that can be returned by [sqlite3_status()].
5553 **
5554 ** <dl>
@@ -5632,31 +5631,31 @@
5631 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5632 #define SQLITE_STATUS_SCRATCH_SIZE 8
5633
5634 /*
5635 ** CAPI3REF: Database Connection Status
 
5636 **
5637 ** ^This interface is used to retrieve runtime status information
5638 ** about a single [database connection]. ^The first argument is the
5639 ** database connection object to be interrogated. ^The second argument
5640 ** is an integer constant, taken from the set of
5641 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5642 ** determiness the parameter to interrogate. The set of
5643 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5644 ** to grow in future releases of SQLite.
5645 **
5646 ** ^The current value of the requested parameter is written into *pCur
5647 ** and the highest instantaneous value is written into *pHiwtr. ^If
5648 ** the resetFlg is true, then the highest instantaneous value is
5649 ** reset back down to the current value.
5650 **
5651 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5652 */
5653 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5654
5655 /*
5656 ** CAPI3REF: Status Parameters for database connections
 
5657 **
5658 ** These constants are the available integer "verbs" that can be passed as
5659 ** the second argument to the [sqlite3_db_status()] interface.
5660 **
5661 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5667,18 +5666,25 @@
5666 **
5667 ** <dl>
5668 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5669 ** <dd>This parameter returns the number of lookaside memory slots currently
5670 ** checked out.</dd>)^
5671 **
5672 ** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5673 ** <dd>^This parameter returns the approximate number of of bytes of heap
5674 ** memory used by all pager caches associated with the database connection.
5675 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5676 ** checked out.</dd>)^
5677 ** </dl>
5678 */
5679 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5680 #define SQLITE_DBSTATUS_CACHE_USED 1
5681 #define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
5682
5683
5684 /*
5685 ** CAPI3REF: Prepared Statement Status
 
5686 **
5687 ** ^(Each prepared statement maintains various
5688 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5689 ** of times it has performed specific operations.)^ These counters can
5690 ** be used to monitor the performance characteristics of the prepared
@@ -5696,15 +5702,14 @@
5702 ** ^If the resetFlg is true, then the counter is reset to zero after this
5703 ** interface call returns.
5704 **
5705 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5706 */
5707 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5708
5709 /*
5710 ** CAPI3REF: Status Parameters for prepared statements
 
5711 **
5712 ** These preprocessor macros define integer codes that name counter
5713 ** values associated with the [sqlite3_stmt_status()] interface.
5714 ** The meanings of the various counters are as follows:
5715 **
@@ -5718,18 +5723,25 @@
5723 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5724 ** <dd>^This is the number of sort operations that have occurred.
5725 ** A non-zero value in this counter may indicate an opportunity to
5726 ** improvement performance through careful use of indices.</dd>
5727 **
5728 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5729 ** <dd>^This is the number of rows inserted into transient indices that
5730 ** were created automatically in order to help joins run faster.
5731 ** A non-zero value in this counter may indicate an opportunity to
5732 ** improvement performance by adding permanent indices that do not
5733 ** need to be reinitialized each time the statement is run.</dd>
5734 **
5735 ** </dl>
5736 */
5737 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5738 #define SQLITE_STMTSTATUS_SORT 2
5739 #define SQLITE_STMTSTATUS_AUTOINDEX 3
5740
5741 /*
5742 ** CAPI3REF: Custom Page Cache Object
 
5743 **
5744 ** The sqlite3_pcache type is opaque. It is implemented by
5745 ** the pluggable module. The SQLite core has no knowledge of
5746 ** its size or internal structure and never deals with the
5747 ** sqlite3_pcache object except by holding and passing pointers
@@ -5740,11 +5752,10 @@
5752 typedef struct sqlite3_pcache sqlite3_pcache;
5753
5754 /*
5755 ** CAPI3REF: Application Defined Page Cache.
5756 ** KEYWORDS: {page cache}
 
5757 **
5758 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5759 ** register an alternative page cache implementation by passing in an
5760 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5761 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5882,11 +5893,10 @@
5893 void (*xDestroy)(sqlite3_pcache*);
5894 };
5895
5896 /*
5897 ** CAPI3REF: Online Backup Object
 
5898 **
5899 ** The sqlite3_backup object records state information about an ongoing
5900 ** online backup operation. ^The sqlite3_backup object is created by
5901 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5902 ** [sqlite3_backup_finish()].
@@ -5895,11 +5905,10 @@
5905 */
5906 typedef struct sqlite3_backup sqlite3_backup;
5907
5908 /*
5909 ** CAPI3REF: Online Backup API.
 
5910 **
5911 ** The backup API copies the content of one database into another.
5912 ** It is useful either for creating backups of databases or
5913 ** for copying in-memory databases to or from persistent files.
5914 **
@@ -6083,11 +6092,10 @@
6092 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
6093 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
6094
6095 /*
6096 ** CAPI3REF: Unlock Notification
 
6097 **
6098 ** ^When running in shared-cache mode, a database operation may fail with
6099 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
6100 ** individual tables within the shared-cache cannot be obtained. See
6101 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -6205,11 +6213,10 @@
6213 );
6214
6215
6216 /*
6217 ** CAPI3REF: String Comparison
 
6218 **
6219 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
6220 ** compare the contents of two buffers containing UTF-8 strings in a
6221 ** case-indendent fashion, using the same definition of case independence
6222 ** that SQLite uses internally when comparing identifiers.
@@ -6216,16 +6223,15 @@
6223 */
6224 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
6225
6226 /*
6227 ** CAPI3REF: Error Logging Interface
 
6228 **
6229 ** ^The [sqlite3_log()] interface writes a message into the error log
6230 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6231 ** ^If logging is enabled, the zFormat string and subsequent arguments are
6232 ** used with [sqlite3_snprintf()] to generate the final output string.
6233 **
6234 ** The sqlite3_log() interface is intended for use by extensions such as
6235 ** virtual tables, collating functions, and SQL functions. While there is
6236 ** nothing to prevent an application from calling sqlite3_log(), doing so
6237 ** is considered bad form.
@@ -6529,10 +6535,11 @@
6535 ** If compiling for a processor that lacks floating point support,
6536 ** substitute integer for floating-point
6537 */
6538 #ifdef SQLITE_OMIT_FLOATING_POINT
6539 # define double sqlite_int64
6540 # define float sqlite_int64
6541 # define LONGDOUBLE_TYPE sqlite_int64
6542 # ifndef SQLITE_BIG_DBL
6543 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
6544 # endif
6545 # define SQLITE_OMIT_DATETIME_FUNCS 1
@@ -6940,10 +6947,11 @@
6947 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
6948 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*);
6949 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
6950 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*);
6951 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int);
6952 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*);
6953 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int);
6954 SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*);
6955 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
6956 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
6957 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
@@ -7334,85 +7342,85 @@
7342 #define OP_ReadCookie 35
7343 #define OP_SetCookie 36
7344 #define OP_VerifyCookie 37
7345 #define OP_OpenRead 38
7346 #define OP_OpenWrite 39
7347 #define OP_OpenAutoindex 40
7348 #define OP_OpenEphemeral 41
7349 #define OP_OpenPseudo 42
7350 #define OP_Close 43
7351 #define OP_SeekLt 44
7352 #define OP_SeekLe 45
7353 #define OP_SeekGe 46
7354 #define OP_SeekGt 47
7355 #define OP_Seek 48
7356 #define OP_NotFound 49
7357 #define OP_Found 50
7358 #define OP_IsUnique 51
7359 #define OP_NotExists 52
7360 #define OP_Sequence 53
7361 #define OP_NewRowid 54
7362 #define OP_Insert 55
7363 #define OP_InsertInt 56
7364 #define OP_Delete 57
7365 #define OP_ResetCount 58
7366 #define OP_RowKey 59
7367 #define OP_RowData 60
7368 #define OP_Rowid 61
7369 #define OP_NullRow 62
7370 #define OP_Last 63
7371 #define OP_Sort 64
7372 #define OP_Rewind 65
7373 #define OP_Prev 66
7374 #define OP_Next 67
7375 #define OP_IdxInsert 70
7376 #define OP_IdxDelete 71
7377 #define OP_IdxRowid 72
7378 #define OP_IdxLT 81
7379 #define OP_IdxGE 92
7380 #define OP_Destroy 95
7381 #define OP_Clear 96
7382 #define OP_CreateIndex 97
7383 #define OP_CreateTable 98
7384 #define OP_ParseSchema 99
7385 #define OP_LoadAnalysis 100
7386 #define OP_DropTable 101
7387 #define OP_DropIndex 102
7388 #define OP_DropTrigger 103
7389 #define OP_IntegrityCk 104
7390 #define OP_RowSetAdd 105
7391 #define OP_RowSetRead 106
7392 #define OP_RowSetTest 107
7393 #define OP_Program 108
7394 #define OP_Param 109
7395 #define OP_FkCounter 110
7396 #define OP_FkIfZero 111
7397 #define OP_MemMax 112
7398 #define OP_IfPos 113
7399 #define OP_IfNeg 114
7400 #define OP_IfZero 115
7401 #define OP_AggStep 116
7402 #define OP_AggFinal 117
7403 #define OP_Vacuum 118
7404 #define OP_IncrVacuum 119
7405 #define OP_Expire 120
7406 #define OP_TableLock 121
7407 #define OP_VBegin 122
7408 #define OP_VCreate 123
7409 #define OP_VDestroy 124
7410 #define OP_VOpen 125
7411 #define OP_VFilter 126
7412 #define OP_VColumn 127
7413 #define OP_VNext 128
7414 #define OP_VRename 129
7415 #define OP_VUpdate 131
7416 #define OP_Pagecount 132
7417 #define OP_Trace 133
7418 #define OP_Noop 134
7419 #define OP_Explain 135
7420
7421 /* The following opcode values are never used */
7422 #define OP_NotUsed_136 136
7423 #define OP_NotUsed_137 137
7424 #define OP_NotUsed_138 138
7425 #define OP_NotUsed_139 139
7426 #define OP_NotUsed_140 140
@@ -7433,22 +7441,22 @@
7441 /* 0 */ 0x00, 0x01, 0x05, 0x04, 0x04, 0x10, 0x00, 0x02,\
7442 /* 8 */ 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x24, 0x24,\
7443 /* 16 */ 0x00, 0x00, 0x00, 0x24, 0x04, 0x05, 0x04, 0x00,\
7444 /* 24 */ 0x00, 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02,\
7445 /* 32 */ 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00,\
7446 /* 40 */ 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,\
7447 /* 48 */ 0x08, 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00,\
7448 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01,\
7449 /* 64 */ 0x01, 0x01, 0x01, 0x01, 0x4c, 0x4c, 0x08, 0x00,\
7450 /* 72 */ 0x02, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15, 0x15,\
7451 /* 80 */ 0x15, 0x01, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
7452 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x01, 0x24, 0x02, 0x02,\
7453 /* 96 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
7454 /* 104 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\
7455 /* 112 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x01,\
7456 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,\
7457 /* 128 */ 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00,\
7458 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
7459 /* 144 */ 0x04, 0x04,}
7460
7461 /************** End of opcodes.h *********************************************/
7462 /************** Continuing where we left off in vdbe.h ***********************/
@@ -7658,10 +7666,11 @@
7666 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
7667
7668 /* Functions used to query pager state and configuration. */
7669 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
7670 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
7671 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
7672 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
7673 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
7674 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
7675 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
7676 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
@@ -8478,10 +8487,11 @@
8487 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
8488 #define SQLITE_RecoveryMode 0x00800000 /* Ignore schema errors */
8489 #define SQLITE_ReverseOrder 0x01000000 /* Reverse unordered SELECTs */
8490 #define SQLITE_RecTriggers 0x02000000 /* Enable recursive triggers */
8491 #define SQLITE_ForeignKeys 0x04000000 /* Enforce foreign key constraints */
8492 #define SQLITE_AutoIndex 0x08000000 /* Enable automatic indexes */
8493
8494 /*
8495 ** Bits of the sqlite3.flags field that are used by the
8496 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
8497 ** These must be the low-order bits of the flags field.
@@ -9340,10 +9350,13 @@
9350 **
9351 ** The jointype starts out showing the join type between the current table
9352 ** and the next table on the list. The parser builds the list this way.
9353 ** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
9354 ** jointype expresses the join between the table and the previous table.
9355 **
9356 ** In the colUsed field, the high-order bit (bit 63) is set if the table
9357 ** contains more than 63 columns and the 64-th or later column is used.
9358 */
9359 struct SrcList {
9360 i16 nSrc; /* Number of tables or subqueries in the FROM clause */
9361 i16 nAlloc; /* Number of entries allocated in a[] below */
9362 struct SrcList_item {
@@ -9451,11 +9464,11 @@
9464 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
9465 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
9466 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
9467 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
9468 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
9469 #define WHERE_OMIT_OPEN 0x0010 /* Table cursors are already open */
9470 #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
9471 #define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
9472 #define WHERE_ONETABLE_ONLY 0x0080 /* Only code the 1st table in pTabList */
9473
9474 /*
@@ -9474,10 +9487,11 @@
9487 int iTop; /* The very beginning of the WHERE loop */
9488 int iContinue; /* Jump here to continue with next record */
9489 int iBreak; /* Jump here to break out of the loop */
9490 int nLevel; /* Number of nested loop */
9491 struct WhereClause *pWC; /* Decomposition of the WHERE clause */
9492 double savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
9493 WhereLevel a[1]; /* Information about each nest loop in WHERE */
9494 };
9495
9496 /*
9497 ** A NameContext defines a context in which to resolve table and column
@@ -9715,10 +9729,11 @@
9729 u32 oldmask; /* Mask of old.* columns referenced */
9730 u32 newmask; /* Mask of new.* columns referenced */
9731 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
9732 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
9733 u8 disableTriggers; /* True to disable triggers */
9734 double nQueryLoop; /* Estimated number of iterations of a query */
9735
9736 /* Above is constant between recursions. Below is reset before and after
9737 ** each recursion */
9738
9739 int nVar; /* Number of '?' variables seen in the SQL so far */
@@ -10656,11 +10671,50 @@
10671 #else
10672 # define IOTRACE(A)
10673 # define sqlite3VdbeIOTraceSql(X)
10674 #endif
10675
10676 /*
10677 ** These routines are available for the mem2.c debugging memory allocator
10678 ** only. They are used to verify that different "types" of memory
10679 ** allocations are properly tracked by the system.
10680 **
10681 ** sqlite3MemdebugSetType() sets the "type" of an allocation to one of
10682 ** the MEMTYPE_* macros defined below. The type must be a bitmask with
10683 ** a single bit set.
10684 **
10685 ** sqlite3MemdebugHasType() returns true if any of the bits in its second
10686 ** argument match the type set by the previous sqlite3MemdebugSetType().
10687 ** sqlite3MemdebugHasType() is intended for use inside assert() statements.
10688 ** For example:
10689 **
10690 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
10691 **
10692 ** Perhaps the most important point is the difference between MEMTYPE_HEAP
10693 ** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have
10694 ** been allocated by lookaside, except the allocation was too large or
10695 ** lookaside was already full. It is important to verify that allocations
10696 ** that might have been satisfied by lookaside are not passed back to
10697 ** non-lookaside free() routines. Asserts such as the example above are
10698 ** placed on the non-lookaside free() routines to verify this constraint.
10699 **
10700 ** All of this is no-op for a production build. It only comes into
10701 ** play when the SQLITE_MEMDEBUG compile-time option is used.
10702 */
10703 #ifdef SQLITE_MEMDEBUG
10704 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
10705 SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
10706 #else
10707 # define sqlite3MemdebugSetType(X,Y) /* no-op */
10708 # define sqlite3MemdebugHasType(X,Y) 1
10709 #endif
10710 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
10711 #define MEMTYPE_DB 0x02 /* Associated with a database connection */
10712 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
10713 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
10714
10715 #endif /* _SQLITEINT_H_ */
10716
10717 /************** End of sqliteInt.h *******************************************/
10718 /************** Begin file global.c ******************************************/
10719 /*
10720 ** 2008 June 13
@@ -11038,10 +11092,13 @@
11092 #ifdef SQLITE_OMIT_AUTOINCREMENT
11093 "OMIT_AUTOINCREMENT",
11094 #endif
11095 #ifdef SQLITE_OMIT_AUTOINIT
11096 "OMIT_AUTOINIT",
11097 #endif
11098 #ifdef SQLITE_OMIT_AUTOMATIC_INDEX
11099 "OMIT_AUTOMATIC_INDEX",
11100 #endif
11101 #ifdef SQLITE_OMIT_AUTOVACUUM
11102 "OMIT_AUTOVACUUM",
11103 #endif
11104 #ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
@@ -11367,10 +11424,30 @@
11424 if( resetFlag ){
11425 db->lookaside.mxOut = db->lookaside.nOut;
11426 }
11427 break;
11428 }
11429
11430 /*
11431 ** Return an approximation for the amount of memory currently used
11432 ** by all pagers associated with the given database connection. The
11433 ** highwater mark is meaningless and is returned as zero.
11434 */
11435 case SQLITE_DBSTATUS_CACHE_USED: {
11436 int totalUsed = 0;
11437 int i;
11438 for(i=0; i<db->nDb; i++){
11439 Btree *pBt = db->aDb[i].pBt;
11440 if( pBt ){
11441 Pager *pPager = sqlite3BtreePager(pBt);
11442 totalUsed += sqlite3PagerMemUsed(pPager);
11443 }
11444 }
11445 *pCurrent = totalUsed;
11446 *pHighwater = 0;
11447 break;
11448 }
11449 default: {
11450 return SQLITE_ERROR;
11451 }
11452 }
11453 return SQLITE_OK;
@@ -13140,11 +13217,12 @@
13217 struct MemBlockHdr {
13218 i64 iSize; /* Size of this allocation */
13219 struct MemBlockHdr *pNext, *pPrev; /* Linked list of all unfreed memory */
13220 char nBacktrace; /* Number of backtraces on this alloc */
13221 char nBacktraceSlots; /* Available backtrace slots */
13222 u8 nTitle; /* Bytes of title; includes '\0' */
13223 u8 eType; /* Allocation type code */
13224 int iForeGuard; /* Guard word for sanity */
13225 };
13226
13227 /*
13228 ** Guard words
@@ -13348,10 +13426,11 @@
13426 }else{
13427 mem.pFirst = pHdr;
13428 }
13429 mem.pLast = pHdr;
13430 pHdr->iForeGuard = FOREGUARD;
13431 pHdr->eType = MEMTYPE_HEAP;
13432 pHdr->nBacktraceSlots = mem.nBacktrace;
13433 pHdr->nTitle = mem.nTitle;
13434 if( mem.nBacktrace ){
13435 void *aAddr[40];
13436 pHdr->nBacktrace = backtrace(aAddr, mem.nBacktrace+1)-1;
@@ -13454,10 +13533,51 @@
13533 sqlite3MemShutdown,
13534 0
13535 };
13536 sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
13537 }
13538
13539 /*
13540 ** Set the "type" of an allocation.
13541 */
13542 SQLITE_PRIVATE void sqlite3MemdebugSetType(void *p, u8 eType){
13543 if( p ){
13544 struct MemBlockHdr *pHdr;
13545 pHdr = sqlite3MemsysGetHeader(p);
13546 assert( pHdr->iForeGuard==FOREGUARD );
13547 pHdr->eType = eType;
13548 }
13549 }
13550
13551 /*
13552 ** Return TRUE if the mask of type in eType matches the type of the
13553 ** allocation p. Also return true if p==NULL.
13554 **
13555 ** This routine is designed for use within an assert() statement, to
13556 ** verify the type of an allocation. For example:
13557 **
13558 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
13559 */
13560 SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
13561 int rc = 1;
13562 if( p ){
13563 struct MemBlockHdr *pHdr;
13564 pHdr = sqlite3MemsysGetHeader(p);
13565 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
13566 assert( (pHdr->eType & (pHdr->eType-1))==0 ); /* Only one type bit set */
13567 if( (pHdr->eType&eType)==0 ){
13568 void **pBt;
13569 pBt = (void**)pHdr;
13570 pBt -= pHdr->nBacktraceSlots;
13571 backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(stderr));
13572 fprintf(stderr, "\n");
13573 rc = 0;
13574 }
13575 }
13576 return rc;
13577 }
13578
13579
13580 /*
13581 ** Set the number of backtrace levels kept for each allocation.
13582 ** A value of zero turns off backtracing. The number is always rounded
13583 ** up to a multiple of 2.
@@ -16446,10 +16566,11 @@
16566 if( p ) sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, n);
16567 sqlite3_mutex_leave(mem0.mutex);
16568 }else{
16569 p = sqlite3GlobalConfig.m.xMalloc(n);
16570 }
16571 sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
16572 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
16573 scratchAllocOut = p!=0;
16574 #endif
16575 return p;
16576 }
@@ -16466,10 +16587,12 @@
16587 #endif
16588
16589 if( sqlite3GlobalConfig.pScratch==0
16590 || p<sqlite3GlobalConfig.pScratch
16591 || p>=(void*)mem0.aScratchFree ){
16592 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
16593 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16594 if( sqlite3GlobalConfig.bMemstat ){
16595 int iSize = sqlite3MallocSize(p);
16596 sqlite3_mutex_enter(mem0.mutex);
16597 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
16598 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
@@ -16506,26 +16629,30 @@
16629 /*
16630 ** Return the size of a memory allocation previously obtained from
16631 ** sqlite3Malloc() or sqlite3_malloc().
16632 */
16633 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
16634 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
16635 return sqlite3GlobalConfig.m.xSize(p);
16636 }
16637 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
16638 assert( db==0 || sqlite3_mutex_held(db->mutex) );
16639 if( isLookaside(db, p) ){
16640 return db->lookaside.sz;
16641 }else{
16642 assert( sqlite3MemdebugHasType(p,
16643 db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
16644 return sqlite3GlobalConfig.m.xSize(p);
16645 }
16646 }
16647
16648 /*
16649 ** Free memory previously obtained from sqlite3Malloc().
16650 */
16651 SQLITE_API void sqlite3_free(void *p){
16652 if( p==0 ) return;
16653 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
16654 if( sqlite3GlobalConfig.bMemstat ){
16655 sqlite3_mutex_enter(mem0.mutex);
16656 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
16657 sqlite3GlobalConfig.m.xFree(p);
16658 sqlite3_mutex_leave(mem0.mutex);
@@ -16544,10 +16671,12 @@
16671 LookasideSlot *pBuf = (LookasideSlot*)p;
16672 pBuf->pNext = db->lookaside.pFree;
16673 db->lookaside.pFree = pBuf;
16674 db->lookaside.nOut--;
16675 }else{
16676 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16677 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16678 sqlite3_free(p);
16679 }
16680 }
16681
16682 /*
@@ -16576,10 +16705,11 @@
16705 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
16706 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
16707 mem0.alarmThreshold ){
16708 sqlite3MallocAlarm(nNew-nOld);
16709 }
16710 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
16711 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16712 if( pNew==0 && mem0.alarmCallback ){
16713 sqlite3MallocAlarm(nBytes);
16714 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
16715 }
@@ -16673,10 +16803,12 @@
16803 #endif
16804 p = sqlite3Malloc(n);
16805 if( !p && db ){
16806 db->mallocFailed = 1;
16807 }
16808 sqlite3MemdebugSetType(p,
16809 (db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);
16810 return p;
16811 }
16812
16813 /*
16814 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -16698,14 +16830,18 @@
16830 if( pNew ){
16831 memcpy(pNew, p, db->lookaside.sz);
16832 sqlite3DbFree(db, p);
16833 }
16834 }else{
16835 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
16836 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
16837 pNew = sqlite3_realloc(p, n);
16838 if( !pNew ){
16839 db->mallocFailed = 1;
16840 }
16841 sqlite3MemdebugSetType(pNew,
16842 db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
16843 }
16844 }
16845 return pNew;
16846 }
16847
@@ -18305,11 +18441,11 @@
18441 u8 isPrepareV2; /* True if prepared with prepare_v2() */
18442 int nChange; /* Number of db changes made since last reset */
18443 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
18444 i64 startTime; /* Time when query started - used for profiling */
18445 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
18446 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
18447 char *zSql; /* Text of the SQL statement that generated this */
18448 void *pFree; /* Free this when deleting the vdbe */
18449 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
18450 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
18451 int iStatement; /* Statement number (or 0 if has not opened stmt) */
@@ -20345,52 +20481,52 @@
20481 /* 35 */ "ReadCookie",
20482 /* 36 */ "SetCookie",
20483 /* 37 */ "VerifyCookie",
20484 /* 38 */ "OpenRead",
20485 /* 39 */ "OpenWrite",
20486 /* 40 */ "OpenAutoindex",
20487 /* 41 */ "OpenEphemeral",
20488 /* 42 */ "OpenPseudo",
20489 /* 43 */ "Close",
20490 /* 44 */ "SeekLt",
20491 /* 45 */ "SeekLe",
20492 /* 46 */ "SeekGe",
20493 /* 47 */ "SeekGt",
20494 /* 48 */ "Seek",
20495 /* 49 */ "NotFound",
20496 /* 50 */ "Found",
20497 /* 51 */ "IsUnique",
20498 /* 52 */ "NotExists",
20499 /* 53 */ "Sequence",
20500 /* 54 */ "NewRowid",
20501 /* 55 */ "Insert",
20502 /* 56 */ "InsertInt",
20503 /* 57 */ "Delete",
20504 /* 58 */ "ResetCount",
20505 /* 59 */ "RowKey",
20506 /* 60 */ "RowData",
20507 /* 61 */ "Rowid",
20508 /* 62 */ "NullRow",
20509 /* 63 */ "Last",
20510 /* 64 */ "Sort",
20511 /* 65 */ "Rewind",
20512 /* 66 */ "Prev",
20513 /* 67 */ "Next",
20514 /* 68 */ "Or",
20515 /* 69 */ "And",
20516 /* 70 */ "IdxInsert",
20517 /* 71 */ "IdxDelete",
20518 /* 72 */ "IdxRowid",
20519 /* 73 */ "IsNull",
20520 /* 74 */ "NotNull",
20521 /* 75 */ "Ne",
20522 /* 76 */ "Eq",
20523 /* 77 */ "Gt",
20524 /* 78 */ "Le",
20525 /* 79 */ "Lt",
20526 /* 80 */ "Ge",
20527 /* 81 */ "IdxLT",
20528 /* 82 */ "BitAnd",
20529 /* 83 */ "BitOr",
20530 /* 84 */ "ShiftLeft",
20531 /* 85 */ "ShiftRight",
20532 /* 86 */ "Add",
@@ -20397,54 +20533,54 @@
20533 /* 87 */ "Subtract",
20534 /* 88 */ "Multiply",
20535 /* 89 */ "Divide",
20536 /* 90 */ "Remainder",
20537 /* 91 */ "Concat",
20538 /* 92 */ "IdxGE",
20539 /* 93 */ "BitNot",
20540 /* 94 */ "String8",
20541 /* 95 */ "Destroy",
20542 /* 96 */ "Clear",
20543 /* 97 */ "CreateIndex",
20544 /* 98 */ "CreateTable",
20545 /* 99 */ "ParseSchema",
20546 /* 100 */ "LoadAnalysis",
20547 /* 101 */ "DropTable",
20548 /* 102 */ "DropIndex",
20549 /* 103 */ "DropTrigger",
20550 /* 104 */ "IntegrityCk",
20551 /* 105 */ "RowSetAdd",
20552 /* 106 */ "RowSetRead",
20553 /* 107 */ "RowSetTest",
20554 /* 108 */ "Program",
20555 /* 109 */ "Param",
20556 /* 110 */ "FkCounter",
20557 /* 111 */ "FkIfZero",
20558 /* 112 */ "MemMax",
20559 /* 113 */ "IfPos",
20560 /* 114 */ "IfNeg",
20561 /* 115 */ "IfZero",
20562 /* 116 */ "AggStep",
20563 /* 117 */ "AggFinal",
20564 /* 118 */ "Vacuum",
20565 /* 119 */ "IncrVacuum",
20566 /* 120 */ "Expire",
20567 /* 121 */ "TableLock",
20568 /* 122 */ "VBegin",
20569 /* 123 */ "VCreate",
20570 /* 124 */ "VDestroy",
20571 /* 125 */ "VOpen",
20572 /* 126 */ "VFilter",
20573 /* 127 */ "VColumn",
20574 /* 128 */ "VNext",
20575 /* 129 */ "VRename",
20576 /* 130 */ "Real",
20577 /* 131 */ "VUpdate",
20578 /* 132 */ "Pagecount",
20579 /* 133 */ "Trace",
20580 /* 134 */ "Noop",
20581 /* 135 */ "Explain",
20582 /* 136 */ "NotUsed_136",
20583 /* 137 */ "NotUsed_137",
20584 /* 138 */ "NotUsed_138",
20585 /* 139 */ "NotUsed_139",
20586 /* 140 */ "NotUsed_140",
@@ -26155,13 +26291,11 @@
26291 flags |= SQLITE_OPEN_READONLY;
26292 openFlags |= O_RDONLY;
26293 fd = open(zName, openFlags, openMode);
26294 }
26295 if( fd<0 ){
26296 rc = SQLITE_CANTOPEN_BKPT;
 
 
26297 goto open_finished;
26298 }
26299 }
26300 assert( fd>=0 );
26301 if( pOutFlags ){
@@ -30816,11 +30950,16 @@
30950 if( pCache->pCache ){
30951 PgHdr *p;
30952 PgHdr *pNext;
30953 for(p=pCache->pDirty; p; p=pNext){
30954 pNext = p->pDirtyNext;
30955 /* This routine never gets call with a positive pgno except right
30956 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
30957 ** it must be that pgno==0.
30958 */
30959 assert( p->pgno>0 );
30960 if( ALWAYS(p->pgno>pgno) ){
30961 assert( p->flags&PGHDR_DIRTY );
30962 sqlite3PcacheMakeClean(p);
30963 }
30964 }
30965 if( pgno==0 && pCache->pPage1 ){
@@ -31160,10 +31299,11 @@
31299 pcache1EnterMutex();
31300 if( p ){
31301 int sz = sqlite3MallocSize(p);
31302 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
31303 }
31304 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
31305 }
31306 return p;
31307 }
31308
31309 /*
@@ -31177,11 +31317,14 @@
31317 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
31318 pSlot = (PgFreeslot*)p;
31319 pSlot->pNext = pcache1.pFree;
31320 pcache1.pFree = pSlot;
31321 }else{
31322 int iSize;
31323 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
31324 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
31325 iSize = sqlite3MallocSize(p);
31326 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
31327 sqlite3_free(p);
31328 }
31329 }
31330
@@ -33315,12 +33458,13 @@
33458 pPager->pInJournal = 0;
33459 releaseAllSavepoints(pPager);
33460
33461 /* If the file is unlocked, somebody else might change it. The
33462 ** values stored in Pager.dbSize etc. might become invalid if
33463 ** this happens. One can argue that this doesn't need to be cleared
33464 ** until the change-counter check fails in PagerSharedLock().
33465 ** Clearing the page size cache here is being conservative.
33466 */
33467 pPager->dbSizeValid = 0;
33468
33469 rc = osUnlock(pPager->fd, NO_LOCK);
33470 if( rc ){
@@ -33506,16 +33650,15 @@
33650 }
33651
33652 #ifdef SQLITE_CHECK_PAGES
33653 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
33654 #endif
 
 
 
 
 
33655 }
33656 sqlite3BitvecDestroy(pPager->pInJournal);
33657 pPager->pInJournal = 0;
33658 pPager->nRec = 0;
33659 sqlite3PcacheCleanAll(pPager->pPCache);
33660
33661 if( !pPager->exclusiveMode ){
33662 rc2 = osUnlock(pPager->fd, SHARED_LOCK);
33663 pPager->state = PAGER_SHARED;
33664 pPager->changeCountDone = 0;
@@ -34170,10 +34313,18 @@
34313 if( rc!=SQLITE_OK ){
34314 if( rc==SQLITE_DONE ){
34315 rc = SQLITE_OK;
34316 pPager->journalOff = szJ;
34317 break;
34318 }else if( rc==SQLITE_IOERR_SHORT_READ ){
34319 /* If the journal has been truncated, simply stop reading and
34320 ** processing the journal. This might happen if the journal was
34321 ** not completely written and synced prior to a crash. In that
34322 ** case, the database should have never been written in the
34323 ** first place so it is OK to simply abandon the rollback. */
34324 rc = SQLITE_OK;
34325 goto end_playback;
34326 }else{
34327 /* If we are unable to rollback, quit and return the error
34328 ** code. This will cause the pager to enter the error state
34329 ** so that no further harm will be done. Perhaps the next
34330 ** process to come along will be able to rollback the database.
@@ -34575,14 +34726,16 @@
34726 ** maximum page count below the current size of the database.
34727 **
34728 ** Regardless of mxPage, return the current maximum page count.
34729 */
34730 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
34731 int nPage;
34732 if( mxPage>0 ){
34733 pPager->mxPgno = mxPage;
34734 }
34735 sqlite3PagerPagecount(pPager, &nPage);
34736 assert( pPager->mxPgno>=nPage );
34737 return pPager->mxPgno;
34738 }
34739
34740 /*
34741 ** The following set of routines are used to disable the simulated
@@ -34652,15 +34805,10 @@
34805 ** and *pnPage is set to the number of pages in the database.
34806 */
34807 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
34808 Pgno nPage; /* Value to return via *pnPage */
34809
 
 
 
 
 
34810 /* Determine the number of pages in the file. Store this in nPage. */
34811 if( pPager->dbSizeValid ){
34812 nPage = pPager->dbSize;
34813 }else{
34814 int rc; /* Error returned by OsFileSize() */
@@ -34690,13 +34838,11 @@
34838 if( nPage>pPager->mxPgno ){
34839 pPager->mxPgno = (Pgno)nPage;
34840 }
34841
34842 /* Set the output variable and return SQLITE_OK */
34843 *pnPage = nPage;
 
 
34844 return SQLITE_OK;
34845 }
34846
34847
34848 /*
@@ -35890,20 +36036,20 @@
36036 **
36037 ** There is a vanishingly small chance that a change will not be
36038 ** detected. The chance of an undetected change is so small that
36039 ** it can be neglected.
36040 */
36041 int nPage;
36042 char dbFileVers[sizeof(pPager->dbFileVers)];
36043 sqlite3PagerPagecount(pPager, &nPage);
36044
36045 if( pPager->errCode ){
36046 rc = pPager->errCode;
36047 goto failed;
36048 }
36049
36050 if( nPage>0 ){
 
36051 IOTRACE(("CKVERS %p %d\n", pPager, sizeof(dbFileVers)));
36052 rc = sqlite3OsRead(pPager->fd, &dbFileVers, sizeof(dbFileVers), 24);
36053 if( rc!=SQLITE_OK ){
36054 goto failed;
36055 }
@@ -36024,11 +36170,11 @@
36170 goto pager_acquire_err;
36171 }
36172 assert( (*ppPage)->pgno==pgno );
36173 assert( (*ppPage)->pPager==pPager || (*ppPage)->pPager==0 );
36174
36175 if( (*ppPage)->pPager && !noContent ){
36176 /* In this case the pcache already contains an initialized copy of
36177 ** the page. Return without further ado. */
36178 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
36179 PAGER_INCR(pPager->nHit);
36180 return SQLITE_OK;
@@ -36184,10 +36330,11 @@
36330 ** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or
36331 ** an IO error code if opening or writing the journal file fails.
36332 */
36333 static int pager_open_journal(Pager *pPager){
36334 int rc = SQLITE_OK; /* Return code */
36335 int nPage; /* Size of database file */
36336 sqlite3_vfs * const pVfs = pPager->pVfs; /* Local cache of vfs pointer */
36337
36338 assert( pPager->state>=PAGER_RESERVED );
36339 assert( pPager->useJournal );
36340 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF );
@@ -36196,17 +36343,14 @@
36343 /* If already in the error state, this function is a no-op. But on
36344 ** the other hand, this routine is never called if we are already in
36345 ** an error state. */
36346 if( NEVER(pPager->errCode) ) return pPager->errCode;
36347
 
 
 
36348 testcase( pPager->dbSizeValid==0 );
36349 rc = sqlite3PagerPagecount(pPager, &nPage);
36350 if( rc ) return rc;
36351 pPager->pInJournal = sqlite3BitvecCreate(nPage);
36352 if( pPager->pInJournal==0 ){
36353 return SQLITE_NOMEM;
36354 }
36355
36356 /* Open the journal file if it is not already open. */
@@ -36301,16 +36445,15 @@
36445 if( exFlag ){
36446 rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
36447 }
36448 }
36449
36450 /* No need to open the journal file at this time. It will be
36451 ** opened before it is written to. If we defer opening the journal,
36452 ** we might save the work of creating a file if the transaction
36453 ** ends up being a no-op.
36454 */
 
 
 
36455 }else if( isOpen(pPager->jfd) && pPager->journalOff==0 ){
36456 /* This happens when the pager was in exclusive-access mode the last
36457 ** time a (read or write) transaction was successfully concluded
36458 ** by this connection. Instead of deleting the journal file it was
36459 ** kept open and either was truncated to 0 bytes or its header was
@@ -36321,11 +36464,10 @@
36464 assert( pPager->pInJournal==0 );
36465 rc = pager_open_journal(pPager);
36466 }
36467
36468 PAGERTRACE(("TRANSACTION %d\n", PAGERID(pPager)));
 
36469 if( rc!=SQLITE_OK ){
36470 assert( !pPager->dbModified );
36471 /* Ignore any IO error that occurs within pager_end_transaction(). The
36472 ** purpose of this call is to reset the internal state of the pager
36473 ** sub-system. It doesn't matter if the journal-file is not properly
@@ -36351,12 +36493,12 @@
36493 /* This routine is not called unless a transaction has already been
36494 ** started.
36495 */
36496 assert( pPager->state>=PAGER_RESERVED );
36497
36498 /* If an error has been previously detected, report the same error
36499 ** again.
36500 */
36501 if( NEVER(pPager->errCode) ) return pPager->errCode;
36502
36503 /* Higher-level routines never call this function if database is not
36504 ** writable. But check anyway, just for robustness. */
@@ -36377,15 +36519,15 @@
36519 /* If we get this far, it means that the page needs to be
36520 ** written to the transaction journal or the ckeckpoint journal
36521 ** or both.
36522 **
36523 ** Higher level routines should have already started a transaction,
36524 ** which means they have acquired the necessary locks but the rollback
36525 ** journal might not yet be open.
36526 */
36527 rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
36528 if( rc!=SQLITE_OK ){
36529 return rc;
36530 }
36531 if( !isOpen(pPager->jfd) && pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
36532 assert( pPager->useJournal );
36533 rc = pager_open_journal(pPager);
@@ -36523,11 +36665,12 @@
36665 ** an integer power of 2. It sets variable pg1 to the identifier
36666 ** of the first page of the sector pPg is located on.
36667 */
36668 pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
36669
36670 rc = sqlite3PagerPagecount(pPager, (int *)&nPageCount);
36671 if( rc ) return rc;
36672 if( pPg->pgno>nPageCount ){
36673 nPage = (pPg->pgno - pg1)+1;
36674 }else if( (pg1+nPagePerSector-1)>nPageCount ){
36675 nPage = nPageCount+1-pg1;
36676 }else{
@@ -36684,10 +36827,13 @@
36827 /* Increment the value just read and write it back to byte 24. */
36828 change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
36829 change_counter++;
36830 put32bits(((char*)pPgHdr->pData)+24, change_counter);
36831
36832 /* Also store the SQLite version number in bytes 96..99 */
36833 put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
36834
36835 /* If running in direct mode, write the contents of page 1 to the file. */
36836 if( DIRECT_MODE ){
36837 const void *zBuf = pPgHdr->pData;
36838 assert( pPager->dbFileSize>0 );
36839 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
@@ -36757,13 +36903,11 @@
36903 int rc = SQLITE_OK; /* Return code */
36904
36905 /* The dbOrigSize is never set if journal_mode=OFF */
36906 assert( pPager->journalMode!=PAGER_JOURNALMODE_OFF || pPager->dbOrigSize==0 );
36907
36908 /* If a prior error occurred, report that error again. */
 
 
36909 if( NEVER(pPager->errCode) ) return pPager->errCode;
36910
36911 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
36912 pPager->zFilename, zMaster, pPager->dbSize));
36913
@@ -37048,10 +37192,20 @@
37192 ** Return the number of references to the pager.
37193 */
37194 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
37195 return sqlite3PcacheRefCount(pPager->pPCache);
37196 }
37197
37198 /*
37199 ** Return the approximate number of bytes of memory currently
37200 ** used by the pager and its associated cache.
37201 */
37202 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager *pPager){
37203 int perPageSize = pPager->pageSize + pPager->nExtra + 20;
37204 return perPageSize*sqlite3PcachePagecount(pPager->pPCache)
37205 + sqlite3MallocSize(pPager);
37206 }
37207
37208 /*
37209 ** Return the number of references to the specified page.
37210 */
37211 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage *pPage){
@@ -37101,15 +37255,14 @@
37255 int nCurrent = pPager->nSavepoint; /* Current number of savepoints */
37256
37257 if( nSavepoint>nCurrent && pPager->useJournal ){
37258 int ii; /* Iterator variable */
37259 PagerSavepoint *aNew; /* New Pager.aSavepoint array */
37260 int nPage; /* Size of database file */
37261
37262 rc = sqlite3PagerPagecount(pPager, &nPage);
37263 if( rc ) return rc;
 
 
37264
37265 /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
37266 ** if the allocation fails. Otherwise, zero the new portion in case a
37267 ** malloc failure occurs while populating it in the for(...) loop below.
37268 */
@@ -37123,19 +37276,18 @@
37276 pPager->aSavepoint = aNew;
37277 pPager->nSavepoint = nSavepoint;
37278
37279 /* Populate the PagerSavepoint structures just allocated. */
37280 for(ii=nCurrent; ii<nSavepoint; ii++){
37281 aNew[ii].nOrig = nPage;
37282 if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
 
37283 aNew[ii].iOffset = pPager->journalOff;
37284 }else{
37285 aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
37286 }
37287 aNew[ii].iSubRec = pPager->nSubRec;
37288 aNew[ii].pInSavepoint = sqlite3BitvecCreate(nPage);
37289 if( !aNew[ii].pInSavepoint ){
37290 return SQLITE_NOMEM;
37291 }
37292 }
37293
@@ -37518,10 +37670,19 @@
37670 && (!isOpen(pPager->jfd) || 0==pPager->journalOff)
37671 ){
37672 if( isOpen(pPager->jfd) ){
37673 sqlite3OsClose(pPager->jfd);
37674 }
37675 assert( (PAGER_JOURNALMODE_TRUNCATE & 1)==1 );
37676 assert( (PAGER_JOURNALMODE_PERSIST & 1)==1 );
37677 assert( (PAGER_JOURNALMODE_DELETE & 1)==0 );
37678 assert( (PAGER_JOURNALMODE_MEMORY & 1)==0 );
37679 assert( (PAGER_JOURNALMODE_OFF & 1)==0 );
37680 if( (pPager->journalMode & 1)==1 && (eMode & 1)==0
37681 && !pPager->exclusiveMode ){
37682 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
37683 }
37684 pPager->journalMode = (u8)eMode;
37685 }
37686 return (int)pPager->journalMode;
37687 }
37688
@@ -37978,10 +38139,11 @@
38139 BtCursor *pCursor; /* A list of all open cursors */
38140 MemPage *pPage1; /* First page of the database */
38141 u8 readOnly; /* True if the underlying file is readonly */
38142 u8 pageSizeFixed; /* True if the page size can no longer be changed */
38143 u8 secureDelete; /* True if secure_delete is enabled */
38144 u8 initiallyEmpty; /* Database is empty at start of transaction */
38145 #ifndef SQLITE_OMIT_AUTOVACUUM
38146 u8 autoVacuum; /* True if auto-vacuum is enabled */
38147 u8 incrVacuum; /* True if incr-vacuum is enabled */
38148 #endif
38149 u16 pageSize; /* Total number of bytes on a page */
@@ -37990,10 +38152,11 @@
38152 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
38153 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
38154 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
38155 u8 inTransaction; /* Transaction state */
38156 int nTransaction; /* Number of open transactions (read + write) */
38157 u32 nPage; /* Number of pages in the database */
38158 void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
38159 void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
38160 sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
38161 Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */
38162 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -39070,15 +39233,12 @@
39233 ** at the end of every transaction.
39234 */
39235 static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
39236 int rc = SQLITE_OK;
39237 if( !pBt->pHasContent ){
39238 assert( pgno<=pBt->nPage );
39239 pBt->pHasContent = sqlite3BitvecCreate(pBt->nPage);
 
 
 
39240 if( !pBt->pHasContent ){
39241 rc = SQLITE_NOMEM;
39242 }
39243 }
39244 if( rc==SQLITE_OK && pgno<=sqlite3BitvecSize(pBt->pHasContent) ){
@@ -40117,17 +40277,17 @@
40277
40278 /*
40279 ** Return the size of the database file in pages. If there is any kind of
40280 ** error, return ((unsigned int)-1).
40281 */
40282 static Pgno btreePagecount(BtShared *pBt){
40283 return pBt->nPage;
40284 }
40285 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){
40286 assert( sqlite3BtreeHoldsMutex(p) );
40287 assert( ((p->pBt->nPage)&0x8000000)==0 );
40288 return (int)btreePagecount(p->pBt);
40289 }
40290
40291 /*
40292 ** Get a page from the pager and initialize it. This routine is just a
40293 ** convenience wrapper around separate calls to btreeGetPage() and
@@ -40140,29 +40300,22 @@
40300 BtShared *pBt, /* The database file */
40301 Pgno pgno, /* Number of the page to get */
40302 MemPage **ppPage /* Write the page pointer here */
40303 ){
40304 int rc;
 
40305 assert( sqlite3_mutex_held(pBt->mutex) );
40306
40307 if( pgno<=0 || pgno>btreePagecount(pBt) ){
40308 return SQLITE_CORRUPT_BKPT;
40309 }
40310 rc = btreeGetPage(pBt, pgno, ppPage, 0);
40311 if( rc==SQLITE_OK ){
40312 rc = btreeInitPage(*ppPage);
40313 if( rc!=SQLITE_OK ){
40314 releasePage(*ppPage);
40315 }
40316 }
 
 
 
 
 
 
 
 
 
40317 return rc;
40318 }
40319
40320 /*
40321 ** Release a MemPage. This should be called once for each prior
@@ -40794,13 +40947,15 @@
40947 ** well-formed database file, then SQLITE_CORRUPT is returned.
40948 ** SQLITE_BUSY is returned if the database is locked. SQLITE_NOMEM
40949 ** is returned if we run out of memory.
40950 */
40951 static int lockBtree(BtShared *pBt){
40952 int rc; /* Result code from subfunctions */
40953 MemPage *pPage1; /* Page 1 of the database file */
40954 int nPage; /* Number of pages in the database */
40955 int nPageFile = 0; /* Number of pages in the database file */
40956 int nPageHeader; /* Number of pages in the database according to hdr */
40957
40958 assert( sqlite3_mutex_held(pBt->mutex) );
40959 assert( pBt->pPage1==0 );
40960 rc = sqlite3PagerSharedLock(pBt->pPager);
40961 if( rc!=SQLITE_OK ) return rc;
@@ -40808,14 +40963,18 @@
40963 if( rc!=SQLITE_OK ) return rc;
40964
40965 /* Do some checking to help insure the file we opened really is
40966 ** a valid database file.
40967 */
40968 nPage = nPageHeader = get4byte(28+(u8*)pPage1->aData);
40969 if( (rc = sqlite3PagerPagecount(pBt->pPager, &nPageFile))!=SQLITE_OK ){;
40970 goto page1_init_failed;
40971 }
40972 if( nPage==0 ){
40973 nPage = nPageFile;
40974 }
40975 if( nPage>0 ){
40976 int pageSize;
40977 int usableSize;
40978 u8 *page1 = pPage1->aData;
40979 rc = SQLITE_NOTADB;
40980 if( memcmp(page1, zMagicHeader, 16)!=0 ){
@@ -40857,10 +41016,14 @@
41016 freeTempSpace(pBt);
41017 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
41018 pageSize-usableSize);
41019 return rc;
41020 }
41021 if( nPageHeader>nPageFile ){
41022 rc = SQLITE_CORRUPT_BKPT;
41023 goto page1_init_failed;
41024 }
41025 if( usableSize<480 ){
41026 goto page1_init_failed;
41027 }
41028 pBt->pageSize = (u16)pageSize;
41029 pBt->usableSize = (u16)usableSize;
@@ -40887,10 +41050,11 @@
41050 pBt->minLocal = (pBt->usableSize-12)*32/255 - 23;
41051 pBt->maxLeaf = pBt->usableSize - 35;
41052 pBt->minLeaf = (pBt->usableSize-12)*32/255 - 23;
41053 assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
41054 pBt->pPage1 = pPage1;
41055 pBt->nPage = nPage;
41056 return SQLITE_OK;
41057
41058 page1_init_failed:
41059 releasePage(pPage1);
41060 pBt->pPage1 = 0;
@@ -40924,16 +41088,14 @@
41088 */
41089 static int newDatabase(BtShared *pBt){
41090 MemPage *pP1;
41091 unsigned char *data;
41092 int rc;
 
41093
41094 assert( sqlite3_mutex_held(pBt->mutex) );
41095 if( pBt->nPage>0 ){
41096 return SQLITE_OK;
 
41097 }
41098 pP1 = pBt->pPage1;
41099 assert( pP1!=0 );
41100 data = pP1->aData;
41101 rc = sqlite3PagerWrite(pP1->pDbPage);
@@ -40955,10 +41117,12 @@
41117 assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
41118 assert( pBt->incrVacuum==1 || pBt->incrVacuum==0 );
41119 put4byte(&data[36 + 4*4], pBt->autoVacuum);
41120 put4byte(&data[36 + 7*4], pBt->incrVacuum);
41121 #endif
41122 pBt->nPage = 1;
41123 data[31] = 1;
41124 return SQLITE_OK;
41125 }
41126
41127 /*
41128 ** Attempt to start a new transaction. A write-transaction
@@ -41044,10 +41208,11 @@
41208 ** page 1. So if some other shared-cache client already has a write-lock
41209 ** on page 1, the transaction cannot be opened. */
41210 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
41211 if( SQLITE_OK!=rc ) goto trans_begun;
41212
41213 pBt->initiallyEmpty = pBt->nPage==0;
41214 do {
41215 /* Call lockBtree() until either pBt->pPage1 is populated or
41216 ** lockBtree() returns something other than SQLITE_OK. lockBtree()
41217 ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after
41218 ** reading page 1 it discovers that the page-size of the database
@@ -41323,16 +41488,16 @@
41488 ** which may or may not empty the freelist. A full autovacuum
41489 ** has nFin>0. A "PRAGMA incremental_vacuum" has nFin==0.
41490 */
41491 static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg){
41492 Pgno nFreeList; /* Number of pages still on the free-list */
41493 int rc;
41494
41495 assert( sqlite3_mutex_held(pBt->mutex) );
41496 assert( iLastPg>nFin );
41497
41498 if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
 
41499 u8 eType;
41500 Pgno iPtrPage;
41501
41502 nFreeList = get4byte(&pBt->pPage1->aData[36]);
41503 if( nFreeList==0 ){
@@ -41404,11 +41569,11 @@
41569 if( nFin==0 ){
41570 iLastPg--;
41571 while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
41572 if( PTRMAP_ISPAGE(pBt, iLastPg) ){
41573 MemPage *pPg;
41574 rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
41575 if( rc!=SQLITE_OK ){
41576 return rc;
41577 }
41578 rc = sqlite3PagerWrite(pPg->pDbPage);
41579 releasePage(pPg);
@@ -41417,10 +41582,11 @@
41582 }
41583 }
41584 iLastPg--;
41585 }
41586 sqlite3PagerTruncateImage(pBt->pPager, iLastPg);
41587 pBt->nPage = iLastPg;
41588 }
41589 return SQLITE_OK;
41590 }
41591
41592 /*
@@ -41439,11 +41605,15 @@
41605 assert( pBt->inTransaction==TRANS_WRITE && p->inTrans==TRANS_WRITE );
41606 if( !pBt->autoVacuum ){
41607 rc = SQLITE_DONE;
41608 }else{
41609 invalidateAllOverflowCache(pBt);
41610 rc = incrVacuumStep(pBt, 0, btreePagecount(pBt));
41611 if( rc==SQLITE_OK ){
41612 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41613 put4byte(&pBt->pPage1->aData[28], pBt->nPage);
41614 }
41615 }
41616 sqlite3BtreeLeave(p);
41617 return rc;
41618 }
41619
@@ -41470,11 +41640,11 @@
41640 Pgno nPtrmap; /* Number of PtrMap pages to be freed */
41641 Pgno iFree; /* The next page to be freed */
41642 int nEntry; /* Number of entries on one ptrmap page */
41643 Pgno nOrig; /* Database size before freeing */
41644
41645 nOrig = btreePagecount(pBt);
41646 if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
41647 /* It is not possible to create a database for which the final page
41648 ** is either a pointer-map page or the pending-byte page. If one
41649 ** is encountered, this indicates corruption.
41650 */
@@ -41495,15 +41665,16 @@
41665
41666 for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
41667 rc = incrVacuumStep(pBt, nFin, iFree);
41668 }
41669 if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
 
41670 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
41671 put4byte(&pBt->pPage1->aData[32], 0);
41672 put4byte(&pBt->pPage1->aData[36], 0);
41673 put4byte(&pBt->pPage1->aData[28], nFin);
41674 sqlite3PagerTruncateImage(pBt->pPager, nFin);
41675 pBt->nPage = nFin;
41676 }
41677 if( rc!=SQLITE_OK ){
41678 sqlite3PagerRollback(pPager);
41679 }
41680 }
@@ -41749,10 +41920,15 @@
41920
41921 /* The rollback may have destroyed the pPage1->aData value. So
41922 ** call btreeGetPage() on page 1 again to make
41923 ** sure pPage1->aData is set correctly. */
41924 if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
41925 int nPage = get4byte(28+(u8*)pPage1->aData);
41926 testcase( nPage==0 );
41927 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
41928 testcase( pBt->nPage!=nPage );
41929 pBt->nPage = nPage;
41930 releasePage(pPage1);
41931 }
41932 assert( countWriteCursors(pBt)==0 );
41933 pBt->inTransaction = TRANS_READ;
41934 }
@@ -41786,21 +41962,17 @@
41962 sqlite3BtreeEnter(p);
41963 assert( p->inTrans==TRANS_WRITE );
41964 assert( pBt->readOnly==0 );
41965 assert( iStatement>0 );
41966 assert( iStatement>p->db->nSavepoint );
41967 assert( pBt->inTransaction==TRANS_WRITE );
41968 /* At the pager level, a statement transaction is a savepoint with
41969 ** an index greater than all savepoints created explicitly using
41970 ** SQL statements. It is illegal to open, release or rollback any
41971 ** such savepoints while the statement transaction savepoint is active.
41972 */
41973 rc = sqlite3PagerOpenSavepoint(pBt->pPager, iStatement);
 
 
 
 
41974 sqlite3BtreeLeave(p);
41975 return rc;
41976 }
41977
41978 /*
@@ -41822,11 +41994,13 @@
41994 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
41995 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
41996 sqlite3BtreeEnter(p);
41997 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
41998 if( rc==SQLITE_OK ){
41999 if( iSavepoint<0 && pBt->initiallyEmpty ) pBt->nPage = 0;
42000 rc = newDatabase(pBt);
42001 pBt->nPage = get4byte(28 + pBt->pPage1->aData);
42002 }
42003 sqlite3BtreeLeave(p);
42004 }
42005 return rc;
42006 }
@@ -41888,11 +42062,11 @@
42062 assert( pBt->pPage1 && pBt->pPage1->aData );
42063
42064 if( NEVER(wrFlag && pBt->readOnly) ){
42065 return SQLITE_READONLY;
42066 }
42067 if( iTable==1 && btreePagecount(pBt)==0 ){
42068 return SQLITE_EMPTY;
42069 }
42070
42071 /* Now that no other errors can occur, finish filling in the BtCursor
42072 ** variables and link the cursor into the BtShared list. */
@@ -42159,11 +42333,11 @@
42333
42334 while( PTRMAP_ISPAGE(pBt, iGuess) || iGuess==PENDING_BYTE_PAGE(pBt) ){
42335 iGuess++;
42336 }
42337
42338 if( iGuess<=btreePagecount(pBt) ){
42339 rc = ptrmapGet(pBt, iGuess, &eType, &pgno);
42340 if( rc==SQLITE_OK && eType==PTRMAP_OVERFLOW2 && pgno==ovfl ){
42341 next = iGuess;
42342 rc = SQLITE_DONE;
42343 }
@@ -43191,11 +43365,11 @@
43365 MemPage *pPrevTrunk = 0;
43366 Pgno mxPage; /* Total size of the database file */
43367
43368 assert( sqlite3_mutex_held(pBt->mutex) );
43369 pPage1 = pBt->pPage1;
43370 mxPage = btreePagecount(pBt);
43371 n = get4byte(&pPage1->aData[36]);
43372 testcase( n==mxPage-1 );
43373 if( n>=mxPage ){
43374 return SQLITE_CORRUPT_BKPT;
43375 }
@@ -43387,39 +43561,39 @@
43561 pPrevTrunk = 0;
43562 }while( searchList );
43563 }else{
43564 /* There are no pages on the freelist, so create a new page at the
43565 ** end of the file */
43566 rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
43567 if( rc ) return rc;
43568 pBt->nPage++;
43569 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ) pBt->nPage++;
 
 
43570
43571 #ifndef SQLITE_OMIT_AUTOVACUUM
43572 if( pBt->autoVacuum && PTRMAP_ISPAGE(pBt, pBt->nPage) ){
43573 /* If *pPgno refers to a pointer-map page, allocate two new pages
43574 ** at the end of the file instead of one. The first allocated page
43575 ** becomes a new pointer-map page, the second is used by the caller.
43576 */
43577 MemPage *pPg = 0;
43578 TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", pBt->nPage));
43579 assert( pBt->nPage!=PENDING_BYTE_PAGE(pBt) );
43580 rc = btreeGetPage(pBt, pBt->nPage, &pPg, 1);
43581 if( rc==SQLITE_OK ){
43582 rc = sqlite3PagerWrite(pPg->pDbPage);
43583 releasePage(pPg);
43584 }
43585 if( rc ) return rc;
43586 pBt->nPage++;
43587 if( pBt->nPage==PENDING_BYTE_PAGE(pBt) ){ pBt->nPage++; }
43588 }
43589 #endif
43590 put4byte(28 + (u8*)pBt->pPage1->aData, pBt->nPage);
43591 *pPgno = pBt->nPage;
43592
43593 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
43594 rc = btreeGetPage(pBt, *pPgno, ppPage, 1);
43595 if( rc ) return rc;
43596 rc = sqlite3PagerWrite((*ppPage)->pDbPage);
43597 if( rc!=SQLITE_OK ){
43598 releasePage(*ppPage);
43599 }
@@ -43605,11 +43779,11 @@
43779 nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
43780 assert( ovflPgno==0 || nOvfl>0 );
43781 while( nOvfl-- ){
43782 Pgno iNext = 0;
43783 MemPage *pOvfl = 0;
43784 if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
43785 /* 0 is not a legal page number and page 1 cannot be an
43786 ** overflow page. Therefore if ovflPgno<2 or past the end of the
43787 ** file the database must be corrupt. */
43788 return SQLITE_CORRUPT_BKPT;
43789 }
@@ -45437,12 +45611,18 @@
45611 ptrmapPut(pBt, pgnoRoot, PTRMAP_ROOTPAGE, 0, &rc);
45612 if( rc ){
45613 releasePage(pRoot);
45614 return rc;
45615 }
45616
45617 /* When the new root page was allocated, page 1 was made writable in
45618 ** order either to increase the database filesize, or to decrement the
45619 ** freelist count. Hence, the sqlite3BtreeUpdateMeta() call cannot fail.
45620 */
45621 assert( sqlite3PagerIswriteable(pBt->pPage1->pDbPage) );
45622 rc = sqlite3BtreeUpdateMeta(p, 4, pgnoRoot);
45623 if( NEVER(rc) ){
45624 releasePage(pRoot);
45625 return rc;
45626 }
45627
45628 }else{
@@ -45478,11 +45658,11 @@
45658 int rc;
45659 unsigned char *pCell;
45660 int i;
45661
45662 assert( sqlite3_mutex_held(pBt->mutex) );
45663 if( pgno>btreePagecount(pBt) ){
45664 return SQLITE_CORRUPT_BKPT;
45665 }
45666
45667 rc = getAndInitPage(pBt, pgno, &pPage);
45668 if( rc ) return rc;
@@ -46229,11 +46409,11 @@
46409 sqlite3BtreeEnter(p);
46410 assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
46411 nRef = sqlite3PagerRefcount(pBt->pPager);
46412 sCheck.pBt = pBt;
46413 sCheck.pPager = pBt->pPager;
46414 sCheck.nPage = btreePagecount(sCheck.pBt);
46415 sCheck.mxErr = mxErr;
46416 sCheck.nErr = 0;
46417 sCheck.mallocFailed = 0;
46418 *pnErr = 0;
46419 if( sCheck.nPage==0 ){
@@ -46831,13 +47011,12 @@
47011 }
47012
47013 /* Now that there is a read-lock on the source database, query the
47014 ** source pager for the number of pages in the database.
47015 */
47016 nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
47017 assert( nSrcPage>=0 );
 
47018 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
47019 const Pgno iSrcPg = p->iNext; /* Source page number */
47020 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
47021 DbPage *pSrcPg; /* Source page object */
47022 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
@@ -48986,11 +49165,11 @@
49165 nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
49166 pKeyInfo = sqlite3Malloc( nByte );
49167 pOp->p4.pKeyInfo = pKeyInfo;
49168 if( pKeyInfo ){
49169 u8 *aSortOrder;
49170 memcpy((char*)pKeyInfo, zP4, nByte - nField);
49171 aSortOrder = pKeyInfo->aSortOrder;
49172 if( aSortOrder ){
49173 pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
49174 memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
49175 }
@@ -53812,18 +53991,13 @@
53991 int i;
53992 sqlite_int64 rowid;
53993 Mem **apArg;
53994 Mem *pX;
53995 } ck;
 
 
 
 
 
53996 struct OP_Trace_stack_vars {
53997 char *zTrace;
53998 } cl;
53999 } u;
54000 /* End automatically generated code
54001 ********************************************************************/
54002
54003 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
@@ -54646,11 +54820,11 @@
54820 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.ag.n );
54821 u.ag.pArg = &aMem[pOp->p2];
54822 for(u.ag.i=0; u.ag.i<u.ag.n; u.ag.i++, u.ag.pArg++){
54823 u.ag.apVal[u.ag.i] = u.ag.pArg;
54824 sqlite3VdbeMemStoreType(u.ag.pArg);
54825 REGISTER_TRACE(pOp->p2+u.ag.i, u.ag.pArg);
54826 }
54827
54828 assert( pOp->p4type==P4_FUNCDEF || pOp->p4type==P4_VDBEFUNC );
54829 if( pOp->p4type==P4_FUNCDEF ){
54830 u.ag.ctx.pFunc = pOp->p4.pFunc;
@@ -56363,14 +56537,14 @@
56537
56538 /* Opcode: OpenEphemeral P1 P2 * P4 *
56539 **
56540 ** Open a new cursor P1 to a transient table.
56541 ** The cursor is always opened read/write even if
56542 ** the main database is read-only. The ephemeral
56543 ** table is deleted automatically when the cursor is closed.
56544 **
56545 ** P2 is the number of columns in the ephemeral table.
56546 ** The cursor points to a BTree table if P4==0 and to a BTree index
56547 ** if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
56548 ** that defines the format of keys in the index.
56549 **
56550 ** This opcode was once called OpenTemp. But that created
@@ -56377,10 +56551,18 @@
56551 ** confusion because the term "temp table", might refer either
56552 ** to a TEMP table at the SQL level, or to a table opened by
56553 ** this opcode. Then this opcode was call OpenVirtual. But
56554 ** that created confusion with the whole virtual-table idea.
56555 */
56556 /* Opcode: OpenAutoindex P1 P2 * P4 *
56557 **
56558 ** This opcode works the same as OP_OpenEphemeral. It has a
56559 ** different name to distinguish its use. Tables created using
56560 ** by this opcode will be used for automatically created transient
56561 ** indices in joins.
56562 */
56563 case OP_OpenAutoindex:
56564 case OP_OpenEphemeral: {
56565 #if 0 /* local variables moved into u.ax */
56566 VdbeCursor *pCx;
56567 #endif /* local variables moved into u.ax */
56568 static const int openFlags =
@@ -57515,29 +57697,35 @@
57697 pc = pOp->p2 - 1;
57698 }
57699 break;
57700 }
57701
57702 /* Opcode: Next P1 P2 * * P5
57703 **
57704 ** Advance cursor P1 so that it points to the next key/data pair in its
57705 ** table or index. If there are no more key/value pairs then fall through
57706 ** to the following instruction. But if the cursor advance was successful,
57707 ** jump immediately to P2.
57708 **
57709 ** The P1 cursor must be for a real table, not a pseudo-table.
57710 **
57711 ** If P5 is positive and the jump is taken, then event counter
57712 ** number P5-1 in the prepared statement is incremented.
57713 **
57714 ** See also: Prev
57715 */
57716 /* Opcode: Prev P1 P2 * * P5
57717 **
57718 ** Back up cursor P1 so that it points to the previous key/data pair in its
57719 ** table or index. If there is no previous key/value pairs then fall through
57720 ** to the following instruction. But if the cursor backup was successful,
57721 ** jump immediately to P2.
57722 **
57723 ** The P1 cursor must be for a real table, not a pseudo-table.
57724 **
57725 ** If P5 is positive and the jump is taken, then event counter
57726 ** number P5-1 in the prepared statement is incremented.
57727 */
57728 case OP_Prev: /* jump */
57729 case OP_Next: { /* jump */
57730 #if 0 /* local variables moved into u.bm */
57731 VdbeCursor *pC;
@@ -57545,10 +57733,11 @@
57733 int res;
57734 #endif /* local variables moved into u.bm */
57735
57736 CHECK_FOR_INTERRUPT;
57737 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
57738 assert( pOp->p5<=ArraySize(p->aCounter) );
57739 u.bm.pC = p->apCsr[pOp->p1];
57740 if( u.bm.pC==0 ){
57741 break; /* See ticket #2273 */
57742 }
57743 u.bm.pCrsr = u.bm.pC->pCursor;
@@ -58991,25 +59180,11 @@
59180 /* Opcode: Pagecount P1 P2 * * *
59181 **
59182 ** Write the current number of pages in database P1 to memory cell P2.
59183 */
59184 case OP_Pagecount: { /* out2-prerelease */
59185 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59186 break;
59187 }
59188 #endif
59189
59190 #ifndef SQLITE_OMIT_TRACE
@@ -59017,24 +59192,24 @@
59192 **
59193 ** If tracing is enabled (by the sqlite3_trace()) interface, then
59194 ** the UTF-8 string contained in P4 is emitted on the trace callback.
59195 */
59196 case OP_Trace: {
59197 #if 0 /* local variables moved into u.cl */
59198 char *zTrace;
59199 #endif /* local variables moved into u.cl */
59200
59201 u.cl.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
59202 if( u.cl.zTrace ){
59203 if( db->xTrace ){
59204 char *z = sqlite3VdbeExpandSql(p, u.cl.zTrace);
59205 db->xTrace(db->pTraceArg, z);
59206 sqlite3DbFree(db, z);
59207 }
59208 #ifdef SQLITE_DEBUG
59209 if( (db->flags & SQLITE_SqlTrace)!=0 ){
59210 sqlite3DebugPrintf("SQL-trace: %s\n", u.cl.zTrace);
59211 }
59212 #endif /* SQLITE_DEBUG */
59213 }
59214 break;
59215 }
@@ -66537,16 +66712,20 @@
66712 int n = sqlite3_column_bytes(pStmt, 2);
66713 if( n>24 ){
66714 n = 24;
66715 }
66716 pSample->nByte = (u8)n;
66717 if( n < 1){
66718 pSample->u.z = 0;
 
66719 }else{
66720 pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66721 if( pSample->u.z ){
66722 memcpy(pSample->u.z, z, n);
66723 }else{
66724 db->mallocFailed = 1;
66725 break;
66726 }
66727 }
66728 }
66729 }
66730 }
66731 }
@@ -75790,11 +75969,11 @@
75969 }else{
75970 for(j=0; j<pColumn->nId; j++){
75971 if( pColumn->a[j].idx==i ) break;
75972 }
75973 }
75974 if( (!useTempTable && !pList) || (pColumn && j>=pColumn->nId) ){
75975 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regCols+i+1);
75976 }else if( useTempTable ){
75977 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, regCols+i+1);
75978 }else{
75979 assert( pSelect==0 ); /* Otherwise useTempTable is true */
@@ -78086,10 +78265,13 @@
78265 { "count_changes", SQLITE_CountRows },
78266 { "empty_result_callbacks", SQLITE_NullCallback },
78267 { "legacy_file_format", SQLITE_LegacyFileFmt },
78268 { "fullfsync", SQLITE_FullFSync },
78269 { "reverse_unordered_selects", SQLITE_ReverseOrder },
78270 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
78271 { "automatic_index", SQLITE_AutoIndex },
78272 #endif
78273 #ifdef SQLITE_DEBUG
78274 { "sql_trace", SQLITE_SqlTrace },
78275 { "vdbe_listing", SQLITE_VdbeListing },
78276 { "vdbe_trace", SQLITE_VdbeTrace },
78277 #endif
@@ -79967,10 +80149,11 @@
80149 }
80150
80151 sqlite3VtabUnlockList(db);
80152
80153 pParse->db = db;
80154 pParse->nQueryLoop = (double)1;
80155 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
80156 char *zSqlCopy;
80157 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
80158 testcase( nBytes==mxLen );
80159 testcase( nBytes==mxLen+1 );
@@ -79988,10 +80171,11 @@
80171 pParse->zTail = &zSql[nBytes];
80172 }
80173 }else{
80174 sqlite3RunParser(pParse, zSql, &zErrMsg);
80175 }
80176 assert( 1==(int)pParse->nQueryLoop );
80177
80178 if( db->mallocFailed ){
80179 pParse->rc = SQLITE_NOMEM;
80180 }
80181 if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
@@ -83744,10 +83928,22 @@
83928 if( addrNext ){
83929 sqlite3VdbeResolveLabel(v, addrNext);
83930 sqlite3ExprCacheClear(pParse);
83931 }
83932 }
83933
83934 /* Before populating the accumulator registers, clear the column cache.
83935 ** Otherwise, if any of the required column values are already present
83936 ** in registers, sqlite3ExprCode() may use OP_SCopy to copy the value
83937 ** to pC->iMem. But by the time the value is used, the original register
83938 ** may have been used, invalidating the underlying buffer holding the
83939 ** text or blob value. See ticket [883034dcb5].
83940 **
83941 ** Another solution would be to change the OP_SCopy used to copy cached
83942 ** values to an OP_Copy.
83943 */
83944 sqlite3ExprCacheClear(pParse);
83945 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
83946 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
83947 }
83948 pAggInfo->directMode = 0;
83949 sqlite3ExprCacheClear(pParse);
@@ -85557,10 +85753,11 @@
85753 pSubParse->db = db;
85754 pSubParse->pTriggerTab = pTab;
85755 pSubParse->pToplevel = pTop;
85756 pSubParse->zAuthContext = pTrigger->zName;
85757 pSubParse->eTriggerOp = pTrigger->op;
85758 pSubParse->nQueryLoop = pParse->nQueryLoop;
85759
85760 v = sqlite3GetVdbe(pSubParse);
85761 if( v ){
85762 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
85763 pTrigger->zName, onErrorText(orconf),
@@ -87477,10 +87674,11 @@
87674 if( pParse==0 ){
87675 rc = SQLITE_NOMEM;
87676 }else{
87677 pParse->declareVtab = 1;
87678 pParse->db = db;
87679 pParse->nQueryLoop = 1;
87680
87681 if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
87682 && pParse->pNewTable
87683 && !db->mallocFailed
87684 && !pParse->pNewTable->pSelect
@@ -87997,19 +88195,21 @@
88195 #define WHERE_COLUMN_EQ 0x00010000 /* x=EXPR or x IN (...) or x IS NULL */
88196 #define WHERE_COLUMN_RANGE 0x00020000 /* x<EXPR and/or x>EXPR */
88197 #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */
88198 #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */
88199 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
88200 #define WHERE_NOT_FULLSCAN 0x000f3000 /* Does not do a full table scan */
88201 #define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */
88202 #define WHERE_TOP_LIMIT 0x00100000 /* x<EXPR or x<=EXPR constraint */
88203 #define WHERE_BTM_LIMIT 0x00200000 /* x>EXPR or x>=EXPR constraint */
88204 #define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
88205 #define WHERE_ORDERBY 0x01000000 /* Output will appear in correct order */
88206 #define WHERE_REVERSE 0x02000000 /* Scan in reverse order */
88207 #define WHERE_UNIQUE 0x04000000 /* Selects no more than one row */
88208 #define WHERE_VIRTUALTABLE 0x08000000 /* Use virtual-table processing */
88209 #define WHERE_MULTI_OR 0x10000000 /* OR using multiple indices */
88210 #define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
88211
88212 /*
88213 ** Initialize a preallocated WhereClause structure.
88214 */
88215 static void whereClauseInit(
@@ -89397,10 +89597,238 @@
89597 }
89598 }
89599 #endif /* SQLITE_OMIT_OR_OPTIMIZATION */
89600 }
89601
89602 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89603 /*
89604 ** Return TRUE if the WHERE clause term pTerm is of a form where it
89605 ** could be used with an index to access pSrc, assuming an appropriate
89606 ** index existed.
89607 */
89608 static int termCanDriveIndex(
89609 WhereTerm *pTerm, /* WHERE clause term to check */
89610 struct SrcList_item *pSrc, /* Table we are trying to access */
89611 Bitmask notReady /* Tables in outer loops of the join */
89612 ){
89613 char aff;
89614 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
89615 if( pTerm->eOperator!=WO_EQ ) return 0;
89616 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
89617 aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;
89618 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
89619 return 1;
89620 }
89621 #endif
89622
89623 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89624 /*
89625 ** If the query plan for pSrc specified in pCost is a full table scan
89626 ** and indexing is allows (if there is no NOT INDEXED clause) and it
89627 ** possible to construct a transient index that would perform better
89628 ** than a full table scan even when the cost of constructing the index
89629 ** is taken into account, then alter the query plan to use the
89630 ** transient index.
89631 */
89632 static void bestAutomaticIndex(
89633 Parse *pParse, /* The parsing context */
89634 WhereClause *pWC, /* The WHERE clause */
89635 struct SrcList_item *pSrc, /* The FROM clause term to search */
89636 Bitmask notReady, /* Mask of cursors that are not available */
89637 WhereCost *pCost /* Lowest cost query plan */
89638 ){
89639 double nTableRow; /* Rows in the input table */
89640 double logN; /* log(nTableRow) */
89641 double costTempIdx; /* per-query cost of the transient index */
89642 WhereTerm *pTerm; /* A single term of the WHERE clause */
89643 WhereTerm *pWCEnd; /* End of pWC->a[] */
89644 Table *pTable; /* Table tht might be indexed */
89645
89646 if( (pParse->db->flags & SQLITE_AutoIndex)==0 ){
89647 /* Automatic indices are disabled at run-time */
89648 return;
89649 }
89650 if( (pCost->plan.wsFlags & WHERE_NOT_FULLSCAN)!=0 ){
89651 /* We already have some kind of index in use for this query. */
89652 return;
89653 }
89654 if( pSrc->notIndexed ){
89655 /* The NOT INDEXED clause appears in the SQL. */
89656 return;
89657 }
89658
89659 assert( pParse->nQueryLoop >= (double)1 );
89660 nTableRow = pSrc->pIndex ? pSrc->pIndex->aiRowEst[0] : 1000000;
89661 logN = estLog(nTableRow);
89662 costTempIdx = 2*logN*(nTableRow/pParse->nQueryLoop + 1);
89663 if( costTempIdx>=pCost->rCost ){
89664 /* The cost of creating the transient table would be greater than
89665 ** doing the full table scan */
89666 return;
89667 }
89668
89669 /* Search for any equality comparison term */
89670 pTable = pSrc->pTab;
89671 pWCEnd = &pWC->a[pWC->nTerm];
89672 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89673 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89674 WHERETRACE(("auto-index reduces cost from %.2f to %.2f\n",
89675 pCost->rCost, costTempIdx));
89676 pCost->rCost = costTempIdx;
89677 pCost->nRow = logN + 1;
89678 pCost->plan.wsFlags = WHERE_TEMP_INDEX;
89679 pCost->used = pTerm->prereqRight;
89680 break;
89681 }
89682 }
89683 }
89684 #else
89685 # define bestAutomaticIndex(A,B,C,D,E) /* no-op */
89686 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89687
89688
89689 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
89690 /*
89691 ** Generate code to construct the Index object for an automatic index
89692 ** and to set up the WhereLevel object pLevel so that the code generator
89693 ** makes use of the automatic index.
89694 */
89695 static void constructAutomaticIndex(
89696 Parse *pParse, /* The parsing context */
89697 WhereClause *pWC, /* The WHERE clause */
89698 struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
89699 Bitmask notReady, /* Mask of cursors that are not available */
89700 WhereLevel *pLevel /* Write new index here */
89701 ){
89702 int nColumn; /* Number of columns in the constructed index */
89703 WhereTerm *pTerm; /* A single term of the WHERE clause */
89704 WhereTerm *pWCEnd; /* End of pWC->a[] */
89705 int nByte; /* Byte of memory needed for pIdx */
89706 Index *pIdx; /* Object describing the transient index */
89707 Vdbe *v; /* Prepared statement under construction */
89708 int regIsInit; /* Register set by initialization */
89709 int addrInit; /* Address of the initialization bypass jump */
89710 Table *pTable; /* The table being indexed */
89711 KeyInfo *pKeyinfo; /* Key information for the index */
89712 int addrTop; /* Top of the index fill loop */
89713 int regRecord; /* Register holding an index record */
89714 int n; /* Column counter */
89715 int i; /* Loop counter */
89716 int mxBitCol; /* Maximum column in pSrc->colUsed */
89717 CollSeq *pColl; /* Collating sequence to on a column */
89718 Bitmask idxCols; /* Bitmap of columns used for indexing */
89719 Bitmask extraCols; /* Bitmap of additional columns */
89720
89721 /* Generate code to skip over the creation and initialization of the
89722 ** transient index on 2nd and subsequent iterations of the loop. */
89723 v = pParse->pVdbe;
89724 assert( v!=0 );
89725 regIsInit = ++pParse->nMem;
89726 addrInit = sqlite3VdbeAddOp1(v, OP_If, regIsInit);
89727 sqlite3VdbeAddOp2(v, OP_Integer, 1, regIsInit);
89728
89729 /* Count the number of columns that will be added to the index
89730 ** and used to match WHERE clause constraints */
89731 nColumn = 0;
89732 pTable = pSrc->pTab;
89733 pWCEnd = &pWC->a[pWC->nTerm];
89734 idxCols = 0;
89735 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89736 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89737 int iCol = pTerm->u.leftColumn;
89738 if( iCol<BMS && iCol>=0 ) idxCols |= 1<<iCol;
89739 nColumn++;
89740 }
89741 }
89742 assert( nColumn>0 );
89743 pLevel->plan.nEq = nColumn;
89744
89745 /* Count the number of additional columns needed to create a
89746 ** covering index. A "covering index" is an index that contains all
89747 ** columns that are needed by the query. With a covering index, the
89748 ** original table never needs to be accessed. Automatic indices must
89749 ** be a covering index because the index will not be updated if the
89750 ** original table changes and the index and table cannot both be used
89751 ** if they go out of sync.
89752 */
89753 extraCols = pSrc->colUsed & ~idxCols;
89754 mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
89755 for(i=0; i<mxBitCol; i++){
89756 if( extraCols & (1<<i) ) nColumn++;
89757 }
89758 if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89759 nColumn += pTable->nCol - BMS + 1;
89760 }
89761 pLevel->plan.wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WO_EQ;
89762
89763 /* Construct the Index object to describe this index */
89764 nByte = sizeof(Index);
89765 nByte += nColumn*sizeof(int); /* Index.aiColumn */
89766 nByte += nColumn*sizeof(char*); /* Index.azColl */
89767 nByte += nColumn; /* Index.aSortOrder */
89768 pIdx = sqlite3DbMallocZero(pParse->db, nByte);
89769 if( pIdx==0 ) return;
89770 pLevel->plan.u.pIdx = pIdx;
89771 pIdx->azColl = (char**)&pIdx[1];
89772 pIdx->aiColumn = (int*)&pIdx->azColl[nColumn];
89773 pIdx->aSortOrder = (u8*)&pIdx->aiColumn[nColumn];
89774 pIdx->zName = "auto-index";
89775 pIdx->nColumn = nColumn;
89776 pIdx->pTable = pTable;
89777 n = 0;
89778 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
89779 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
89780 Expr *pX = pTerm->pExpr;
89781 pIdx->aiColumn[n] = pTerm->u.leftColumn;
89782 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
89783 pIdx->azColl[n] = pColl->zName;
89784 n++;
89785 }
89786 }
89787 assert( n==pLevel->plan.nEq );
89788
89789 /* Add additional columns needed to make the automatic index into
89790 ** a covering index */
89791 for(i=0; i<mxBitCol; i++){
89792 if( extraCols & (1<<i) ){
89793 pIdx->aiColumn[n] = i;
89794 pIdx->azColl[n] = "BINARY";
89795 n++;
89796 }
89797 }
89798 if( pSrc->colUsed & (((Bitmask)1)<<(BMS-1)) ){
89799 for(i=BMS-1; i<pTable->nCol; i++){
89800 pIdx->aiColumn[n] = i;
89801 pIdx->azColl[n] = "BINARY";
89802 n++;
89803 }
89804 }
89805 assert( n==nColumn );
89806
89807 /* Create the automatic index */
89808 pKeyinfo = sqlite3IndexKeyinfo(pParse, pIdx);
89809 assert( pLevel->iIdxCur>=0 );
89810 sqlite3VdbeAddOp4(v, OP_OpenAutoindex, pLevel->iIdxCur, nColumn+1, 0,
89811 (char*)pKeyinfo, P4_KEYINFO_HANDOFF);
89812 VdbeComment((v, "for %s", pTable->zName));
89813
89814 /* Fill the automatic index with content */
89815 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
89816 regRecord = sqlite3GetTempReg(pParse);
89817 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 1);
89818 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
89819 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
89820 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
89821 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
89822 sqlite3VdbeJumpHere(v, addrTop);
89823 sqlite3ReleaseTempReg(pParse, regRecord);
89824
89825 /* Jump here when skipping the initialization */
89826 sqlite3VdbeJumpHere(v, addrInit);
89827 }
89828 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
89829
89830 #ifndef SQLITE_OMIT_VIRTUALTABLE
89831 /*
89832 ** Allocate and populate an sqlite3_index_info structure. It is the
89833 ** responsibility of the caller to eventually release the structure
89834 ** by passing the pointer returned by this function to sqlite3_free().
@@ -89581,10 +90009,11 @@
90009 struct sqlite3_index_constraint *pIdxCons;
90010 struct sqlite3_index_constraint_usage *pUsage;
90011 WhereTerm *pTerm;
90012 int i, j;
90013 int nOrderBy;
90014 double rCost;
90015
90016 /* Make sure wsFlags is initialized to some sane value. Otherwise, if the
90017 ** malloc in allocateIndexInfo() fails and this function returns leaving
90018 ** wsFlags in an uninitialized state, the caller may behave unpredictably.
90019 */
@@ -89666,22 +90095,31 @@
90095 for(i=0; i<pIdxInfo->nConstraint; i++){
90096 if( pUsage[i].argvIndex>0 ){
90097 pCost->used |= pWC->a[pIdxCons[i].iTermOffset].prereqRight;
90098 }
90099 }
90100
90101 /* If there is an ORDER BY clause, and the selected virtual table index
90102 ** does not satisfy it, increase the cost of the scan accordingly. This
90103 ** matches the processing for non-virtual tables in bestBtreeIndex().
90104 */
90105 rCost = pIdxInfo->estimatedCost;
90106 if( pOrderBy && pIdxInfo->orderByConsumed==0 ){
90107 rCost += estLog(rCost)*rCost;
90108 }
90109
90110 /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
90111 ** inital value of lowestCost in this loop. If it is, then the
90112 ** (cost<lowestCost) test below will never be true.
90113 **
90114 ** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT
90115 ** is defined.
90116 */
90117 if( (SQLITE_BIG_DBL/((double)2))<rCost ){
90118 pCost->rCost = (SQLITE_BIG_DBL/((double)2));
90119 }else{
90120 pCost->rCost = rCost;
90121 }
90122 pCost->plan.u.pVtabIdx = pIdxInfo;
90123 if( pIdxInfo->orderByConsumed ){
90124 pCost->plan.wsFlags |= WHERE_ORDERBY;
90125 }
@@ -90175,11 +90613,11 @@
90613 }
90614 }
90615
90616 /* If currently calculating the cost of using an index (not the IPK
90617 ** index), determine if all required column data may be obtained without
90618 ** using the main table (i.e. if the index is a covering
90619 ** index for this query). If it is, set the WHERE_IDX_ONLY flag in
90620 ** wsFlags. Otherwise, set the bLookup variable to true. */
90621 if( pIdx && wsFlags ){
90622 Bitmask m = pSrc->colUsed;
90623 int j;
@@ -90233,14 +90671,14 @@
90671 cost /= (double)2;
90672 }
90673 /**** Cost of using this index has now been computed ****/
90674
90675 WHERETRACE((
90676 "%s(%s): nEq=%d nInMul=%d nBound=%d bSort=%d bLookup=%d wsFlags=0x%x\n"
90677 " notReady=0x%llx nRow=%.2f cost=%.2f used=0x%llx\n",
90678 pSrc->pTab->zName, (pIdx ? pIdx->zName : "ipk"),
90679 nEq, nInMul, nBound, bSort, bLookup, wsFlags, notReady, nRow, cost, used
90680 ));
90681
90682 /* If this index is the best we have seen so far, then record this
90683 ** index and its cost in the pCost structure.
90684 */
@@ -90281,10 +90719,11 @@
90719 WHERETRACE(("best index is: %s\n",
90720 (pCost->plan.u.pIdx ? pCost->plan.u.pIdx->zName : "ipk")
90721 ));
90722
90723 bestOrClauseIndex(pParse, pWC, pSrc, notReady, pOrderBy, pCost);
90724 bestAutomaticIndex(pParse, pWC, pSrc, notReady, pCost);
90725 pCost->plan.wsFlags |= eqTermMask;
90726 }
90727
90728 /*
90729 ** Find the query plan for accessing table pSrc->pTab. Write the
@@ -90750,11 +91189,15 @@
91189 }
91190 start = sqlite3VdbeCurrentAddr(v);
91191 pLevel->op = bRev ? OP_Prev : OP_Next;
91192 pLevel->p1 = iCur;
91193 pLevel->p2 = start;
91194 if( pStart==0 && pEnd==0 ){
91195 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
91196 }else{
91197 assert( pLevel->p5==0 );
91198 }
91199 if( testOp!=OP_Noop ){
91200 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
91201 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
91202 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
91203 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
@@ -91219,10 +91662,17 @@
91662 if( pInfo->needToFreeIdxStr ){
91663 sqlite3_free(pInfo->idxStr);
91664 }
91665 sqlite3DbFree(db, pInfo);
91666 }
91667 if( pWInfo->a[i].plan.wsFlags & WHERE_TEMP_INDEX ){
91668 Index *pIdx = pWInfo->a[i].plan.u.pIdx;
91669 if( pIdx ){
91670 sqlite3DbFree(db, pIdx->zColAff);
91671 sqlite3DbFree(db, pIdx);
91672 }
91673 }
91674 }
91675 whereClauseClear(pWInfo->pWC);
91676 sqlite3DbFree(db, pWInfo);
91677 }
91678 }
@@ -91365,18 +91815,21 @@
91815 nByteWInfo +
91816 sizeof(WhereClause) +
91817 sizeof(WhereMaskSet)
91818 );
91819 if( db->mallocFailed ){
91820 sqlite3DbFree(db, pWInfo);
91821 pWInfo = 0;
91822 goto whereBeginError;
91823 }
91824 pWInfo->nLevel = nTabList;
91825 pWInfo->pParse = pParse;
91826 pWInfo->pTabList = pTabList;
91827 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
91828 pWInfo->pWC = pWC = (WhereClause *)&((u8 *)pWInfo)[nByteWInfo];
91829 pWInfo->wctrlFlags = wctrlFlags;
91830 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
91831 pMaskSet = (WhereMaskSet*)&pWC[1];
91832
91833 /* Split the WHERE clause into separate subexpressions where each
91834 ** subexpression is separated by an AND operator.
91835 */
@@ -91552,17 +92005,20 @@
92005 if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
92006 *ppOrderBy = 0;
92007 }
92008 andFlags &= bestPlan.plan.wsFlags;
92009 pLevel->plan = bestPlan.plan;
92010 testcase( bestPlan.plan.wsFlags & WHERE_INDEXED );
92011 testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX );
92012 if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){
92013 pLevel->iIdxCur = pParse->nTab++;
92014 }else{
92015 pLevel->iIdxCur = -1;
92016 }
92017 notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
92018 pLevel->iFrom = (u8)bestJ;
92019 if( bestPlan.nRow>=(double)1 ) pParse->nQueryLoop *= bestPlan.nRow;
92020
92021 /* Check that if the table scanned by this loop iteration had an
92022 ** INDEXED BY clause attached to it, that the named index is being
92023 ** used for the scan. If not, then query compilation has failed.
92024 ** Return an error.
@@ -91605,10 +92061,11 @@
92061
92062 /* Open all tables in the pTabList and any indices selected for
92063 ** searching those tables.
92064 */
92065 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
92066 notReady = ~(Bitmask)0;
92067 for(i=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){
92068 Table *pTab; /* Table to open */
92069 int iDb; /* Index of database containing table/index */
92070
92071 #ifndef SQLITE_OMIT_EXPLAIN
@@ -91617,11 +92074,13 @@
92074 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
92075 zMsg = sqlite3MPrintf(db, "TABLE %s", pItem->zName);
92076 if( pItem->zAlias ){
92077 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
92078 }
92079 if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92080 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH AUTOMATIC INDEX", zMsg);
92081 }else if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92082 zMsg = sqlite3MAppendf(db, zMsg, "%s WITH INDEX %s",
92083 zMsg, pLevel->plan.u.pIdx->zName);
92084 }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
92085 zMsg = sqlite3MAppendf(db, zMsg, "%s VIA MULTI-INDEX UNION", zMsg);
92086 }else if( pLevel->plan.wsFlags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){
@@ -91640,12 +92099,15 @@
92099 sqlite3VdbeAddOp4(v, OP_Explain, i, pLevel->iFrom, 0, zMsg, P4_DYNAMIC);
92100 }
92101 #endif /* SQLITE_OMIT_EXPLAIN */
92102 pTabItem = &pTabList->a[pLevel->iFrom];
92103 pTab = pTabItem->pTab;
92104 pLevel->iTabCur = pTabItem->iCursor;
92105 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
92106 if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ){
92107 /* Do nothing */
92108 }else
92109 #ifndef SQLITE_OMIT_VIRTUALTABLE
92110 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
92111 const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
92112 int iCur = pTabItem->iCursor;
92113 sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB);
@@ -91664,11 +92126,15 @@
92126 assert( n<=pTab->nCol );
92127 }
92128 }else{
92129 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
92130 }
92131 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
92132 if( (pLevel->plan.wsFlags & WHERE_TEMP_INDEX)!=0 ){
92133 constructAutomaticIndex(pParse, pWC, pTabItem, notReady, pLevel);
92134 }else
92135 #endif
92136 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
92137 Index *pIx = pLevel->plan.u.pIdx;
92138 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIx);
92139 int iIdxCur = pLevel->iIdxCur;
92140 assert( pIx->pSchema==pTab->pSchema );
@@ -91676,12 +92142,14 @@
92142 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIx->tnum, iDb,
92143 (char*)pKey, P4_KEYINFO_HANDOFF);
92144 VdbeComment((v, "%s", pIx->zName));
92145 }
92146 sqlite3CodeVerifySchema(pParse, iDb);
92147 notReady &= ~getMask(pWC->pMaskSet, pTabItem->iCursor);
92148 }
92149 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
92150 if( db->mallocFailed ) goto whereBeginError;
92151
92152 /* Generate the code to do the search. Each iteration of the for
92153 ** loop below generates code for a single nested loop of the VM
92154 ** program.
92155 */
@@ -91745,11 +92213,14 @@
92213 */
92214 return pWInfo;
92215
92216 /* Jump here if malloc fails */
92217 whereBeginError:
92218 if( pWInfo ){
92219 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
92220 whereInfoFree(db, pWInfo);
92221 }
92222 return 0;
92223 }
92224
92225 /*
92226 ** Generate the end of the WHERE loop. See comments on
@@ -91815,16 +92286,19 @@
92286 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
92287 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
92288 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
92289 Table *pTab = pTabItem->pTab;
92290 assert( pTab!=0 );
92291 if( (pTab->tabFlags & TF_Ephemeral)==0
92292 && pTab->pSelect==0
92293 && (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0
92294 ){
92295 int ws = pLevel->plan.wsFlags;
92296 if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
92297 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
92298 }
92299 if( (ws & (WHERE_INDEXED|WHERE_TEMP_INDEX)) == WHERE_INDEXED ){
92300 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
92301 }
92302 }
92303
92304 /* If this scan uses an index, make code substitutions to read data
@@ -91868,11 +92342,14 @@
92342 }
92343 }
92344
92345 /* Final cleanup
92346 */
92347 if( pWInfo ){
92348 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
92349 whereInfoFree(db, pWInfo);
92350 }
92351 return;
92352 }
92353
92354 /************** End of where.c ***********************************************/
92355 /************** Begin file parse.c *******************************************/
@@ -98071,11 +98548,11 @@
98548 assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
98549 memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
98550 db->autoCommit = 1;
98551 db->nextAutovac = -1;
98552 db->nextPagesize = 0;
98553 db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
98554 #if SQLITE_DEFAULT_FILE_FORMAT<4
98555 | SQLITE_LegacyFileFmt
98556 #endif
98557 #ifdef SQLITE_ENABLE_LOAD_EXTENSION
98558 | SQLITE_LoadExtension
@@ -99199,11 +99676,11 @@
99676 ** and so on.
99677 **
99678 ** This is similar in concept to how sqlite encodes "varints" but
99679 ** the encoding is not the same. SQLite varints are big-endian
99680 ** are are limited to 9 bytes in length whereas FTS3 varints are
99681 ** little-endian and can be up to 10 bytes in length (in theory).
99682 **
99683 ** Example encodings:
99684 **
99685 ** 1: 0x01
99686 ** 127: 0x7f
@@ -99210,30 +99687,30 @@
99687 ** 128: 0x81 0x00
99688 **
99689 **
99690 **** Document lists ****
99691 ** A doclist (document list) holds a docid-sorted list of hits for a
99692 ** given term. Doclists hold docids and associated token positions.
99693 ** A docid is the unique integer identifier for a single document.
99694 ** A position is the index of a word within the document. The first
99695 ** word of the document has a position of 0.
99696 **
99697 ** FTS3 used to optionally store character offsets using a compile-time
99698 ** option. But that functionality is no longer supported.
99699 **
99700 ** A doclist is stored like this:
99701 **
99702 ** array {
99703 ** varint docid;
99704 ** array { (position list for column 0)
99705 ** varint position; (2 more than the delta from previous position)
99706 ** }
99707 ** array {
99708 ** varint POS_COLUMN; (marks start of position list for new column)
99709 ** varint column; (index of new column)
99710 ** array {
99711 ** varint position; (2 more than the delta from previous position)
99712 ** }
99713 ** }
99714 ** varint POS_END; (marks end of positions for this document.
99715 ** }
99716 **
@@ -99241,11 +99718,11 @@
99718 ** memory. A "position" is an index of a token in the token stream
99719 ** generated by the tokenizer. Note that POS_END and POS_COLUMN occur
99720 ** in the same logical place as the position element, and act as sentinals
99721 ** ending a position list array. POS_END is 0. POS_COLUMN is 1.
99722 ** The positions numbers are not stored literally but rather as two more
99723 ** than the difference from the prior position, or the just the position plus
99724 ** 2 for the first position. Example:
99725 **
99726 ** label: A B C D E F G H I J K
99727 ** value: 123 5 9 1 1 14 35 0 234 72 0
99728 **
@@ -99255,18 +99732,18 @@
99732 ** new column is column number 1. There are two positions at 12 and 45
99733 ** (14-2 and 35-2+12). The 0 at H indicate the end-of-document. The
99734 ** 234 at I is the next docid. It has one position 72 (72-2) and then
99735 ** terminates with the 0 at K.
99736 **
99737 ** A "position-list" is the list of positions for multiple columns for
99738 ** a single docid. A "column-list" is the set of positions for a single
99739 ** column. Hence, a position-list consists of one or more column-lists,
99740 ** a document record consists of a docid followed by a position-list and
99741 ** a doclist consists of one or more document records.
99742 **
99743 ** A bare doclist omits the position information, becoming an
99744 ** array of varint-encoded docids.
99745 **
99746 **** Segment leaf nodes ****
99747 ** Segment leaf nodes store terms and doclists, ordered by term. Leaf
99748 ** nodes are written using LeafWriter, and read using LeafReader (to
99749 ** iterate through a single leaf node's data) and LeavesReader (to
@@ -99776,10 +100253,24 @@
100253 ** Maximum length of a varint encoded integer. The varint format is different
100254 ** from that used by SQLite, so the maximum length is 10, not 9.
100255 */
100256 #define FTS3_VARINT_MAX 10
100257
100258 /*
100259 ** The testcase() macro is only used by the amalgamation. If undefined,
100260 ** make it a no-op.
100261 */
100262 #ifndef testcase
100263 # define testcase(X)
100264 #endif
100265
100266 /*
100267 ** Terminator values for position-lists and column-lists.
100268 */
100269 #define POS_COLUMN (1) /* Column-list terminator */
100270 #define POS_END (0) /* Position-list terminator */
100271
100272 /*
100273 ** This section provides definitions to allow the
100274 ** FTS3 extension to be compiled outside of the
100275 ** amalgamation.
100276 */
@@ -100087,12 +100578,11 @@
100578 *pi = (int) i;
100579 return ret;
100580 }
100581
100582 /*
100583 ** Return the number of bytes required to encode v as a varint
 
100584 */
100585 SQLITE_PRIVATE int sqlite3Fts3VarintLen(sqlite3_uint64 v){
100586 int i = 0;
100587 do{
100588 i++;
@@ -100139,11 +100629,11 @@
100629 }
100630 }
100631
100632 /*
100633 ** Read a single varint from the doclist at *pp and advance *pp to point
100634 ** to the first byte past the end of the varint. Add the value of the varint
100635 ** to *pVal.
100636 */
100637 static void fts3GetDeltaVarint(char **pp, sqlite3_int64 *pVal){
100638 sqlite3_int64 iVal;
100639 *pp += sqlite3Fts3GetVarint(*pp, &iVal);
@@ -100195,11 +100685,11 @@
100685 ** and then evaluate those statements. The success code is writting
100686 ** into *pRc.
100687 **
100688 ** If *pRc is initially non-zero then this routine is a no-op.
100689 */
100690 static void fts3DbExec(
100691 int *pRc, /* Success code */
100692 sqlite3 *db, /* Database in which to run SQL */
100693 const char *zFormat, /* Format string for SQL */
100694 ... /* Arguments to the format string */
100695 ){
@@ -100275,10 +100765,14 @@
100765
100766 /*
100767 ** Create the backing store tables (%_content, %_segments and %_segdir)
100768 ** required by the FTS3 table passed as the only argument. This is done
100769 ** as part of the vtab xCreate() method.
100770 **
100771 ** If the p->bHasDocsize boolean is true (indicating that this is an
100772 ** FTS4 table, not an FTS3 table) then also create the %_docsize and
100773 ** %_stat tables required by FTS4.
100774 */
100775 static int fts3CreateTables(Fts3Table *p){
100776 int rc = SQLITE_OK; /* Return code */
100777 int i; /* Iterator variable */
100778 char *zContentCols; /* Columns of %_content table */
@@ -100367,11 +100861,11 @@
100861 ** This function is the implementation of both the xConnect and xCreate
100862 ** methods of the FTS3 virtual table.
100863 **
100864 ** The argv[] array contains the following:
100865 **
100866 ** argv[0] -> module name ("fts3" or "fts4")
100867 ** argv[1] -> database name
100868 ** argv[2] -> table name
100869 ** argv[...] -> "column name" and other module argument fields.
100870 */
100871 static int fts3InitVtab(
@@ -100386,16 +100880,16 @@
100880 Fts3Hash *pHash = (Fts3Hash *)pAux;
100881 Fts3Table *p; /* Pointer to allocated vtab */
100882 int rc; /* Return code */
100883 int i; /* Iterator variable */
100884 int nByte; /* Size of allocation used for *p */
100885 int iCol; /* Column index */
100886 int nString = 0; /* Bytes required to hold all column names */
100887 int nCol = 0; /* Number of columns in the FTS table */
100888 char *zCsr; /* Space for holding column names */
100889 int nDb; /* Bytes required to hold database name */
100890 int nName; /* Bytes required to hold table name */
100891
100892 const char *zTokenizer = 0; /* Name of tokenizer to use */
100893 sqlite3_tokenizer *pTokenizer = 0; /* Tokenizer for this table */
100894
100895 nDb = (int)strlen(argv[1]) + 1;
@@ -100621,10 +101115,15 @@
101115 sqlite3_free(pCsr->aMatchinfo);
101116 sqlite3_free(pCsr);
101117 return SQLITE_OK;
101118 }
101119
101120 /*
101121 ** Position the pCsr->pStmt statement so that it is on the row
101122 ** of the %_content table that contains the last match. Return
101123 ** SQLITE_OK on success.
101124 */
101125 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
101126 if( pCsr->isRequireSeek ){
101127 pCsr->isRequireSeek = 0;
101128 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
101129 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
@@ -100647,10 +101146,21 @@
101146 }else{
101147 return SQLITE_OK;
101148 }
101149 }
101150
101151 /*
101152 ** Advance the cursor to the next row in the %_content table that
101153 ** matches the search criteria. For a MATCH search, this will be
101154 ** the next row that matches. For a full-table scan, this will be
101155 ** simply the next row in the %_content table. For a docid lookup,
101156 ** this routine simply sets the EOF flag.
101157 **
101158 ** Return SQLITE_OK if nothing goes wrong. SQLITE_OK is returned
101159 ** even if we reach end-of-file. The fts3EofMethod() will be called
101160 ** subsequently to determine whether or not an EOF was hit.
101161 */
101162 static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
101163 int rc = SQLITE_OK; /* Return code */
101164 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
101165
101166 if( pCsr->aDoclist==0 ){
@@ -100782,10 +101292,15 @@
101292
101293 /*
101294 ** When this function is called, *ppPoslist is assumed to point to the
101295 ** start of a position-list. After it returns, *ppPoslist points to the
101296 ** first byte after the position-list.
101297 **
101298 ** A position list is list of positions (delta encoded) and columns for
101299 ** a single document record of a doclist. So, in other words, this
101300 ** routine advances *ppPoslist so that it points to the next docid in
101301 ** the doclist, or to the first byte past the end of the doclist.
101302 **
101303 ** If pp is not NULL, then the contents of the position list are copied
101304 ** to *pp. *pp is set to point to the first byte past the last byte copied
101305 ** before this function returns.
101306 */
@@ -100792,21 +101307,24 @@
101307 static void fts3PoslistCopy(char **pp, char **ppPoslist){
101308 char *pEnd = *ppPoslist;
101309 char c = 0;
101310
101311 /* The end of a position list is marked by a zero encoded as an FTS3
101312 ** varint. A single POS_END (0) byte. Except, if the 0 byte is preceded by
101313 ** a byte with the 0x80 bit set, then it is not a varint 0, but the tail
101314 ** of some other, multi-byte, value.
101315 **
101316 ** The following while-loop moves pEnd to point to the first byte that is not
101317 ** immediately preceded by a byte with the 0x80 bit set. Then increments
101318 ** pEnd once more so that it points to the byte immediately following the
101319 ** last byte in the position-list.
101320 */
101321 while( *pEnd | c ){
101322 c = *pEnd++ & 0x80;
101323 testcase( c!=0 && (*pEnd)==0 );
101324 }
101325 pEnd++; /* Advance past the POS_END terminator byte */
101326
101327 if( pp ){
101328 int n = (int)(pEnd - *ppPoslist);
101329 char *p = *pp;
101330 memcpy(p, *ppPoslist, n);
@@ -100814,16 +101332,38 @@
101332 *pp = p;
101333 }
101334 *ppPoslist = pEnd;
101335 }
101336
101337 /*
101338 ** When this function is called, *ppPoslist is assumed to point to the
101339 ** start of a column-list. After it returns, *ppPoslist points to the
101340 ** to the terminator (POS_COLUMN or POS_END) byte of the column-list.
101341 **
101342 ** A column-list is list of delta-encoded positions for a single column
101343 ** within a single document within a doclist.
101344 **
101345 ** The column-list is terminated either by a POS_COLUMN varint (1) or
101346 ** a POS_END varint (0). This routine leaves *ppPoslist pointing to
101347 ** the POS_COLUMN or POS_END that terminates the column-list.
101348 **
101349 ** If pp is not NULL, then the contents of the column-list are copied
101350 ** to *pp. *pp is set to point to the first byte past the last byte copied
101351 ** before this function returns. The POS_COLUMN or POS_END terminator
101352 ** is not copied into *pp.
101353 */
101354 static void fts3ColumnlistCopy(char **pp, char **ppPoslist){
101355 char *pEnd = *ppPoslist;
101356 char c = 0;
101357
101358 /* A column-list is terminated by either a 0x01 or 0x00 byte that is
101359 ** not part of a multi-byte varint.
101360 */
101361 while( 0xFE & (*pEnd | c) ){
101362 c = *pEnd++ & 0x80;
101363 testcase( c!=0 && ((*pEnd)&0xfe)==0 );
101364 }
101365 if( pp ){
101366 int n = (int)(pEnd - *ppPoslist);
101367 char *p = *pp;
101368 memcpy(p, *ppPoslist, n);
101369 p += n;
@@ -100831,41 +101371,49 @@
101371 }
101372 *ppPoslist = pEnd;
101373 }
101374
101375 /*
101376 ** Value used to signify the end of an position-list. This is safe because
101377 ** it is not possible to have a document with 2^31 terms.
101378 */
101379 #define POSITION_LIST_END 0x7fffffff
101380
101381 /*
101382 ** This function is used to help parse position-lists. When this function is
101383 ** called, *pp may point to the start of the next varint in the position-list
101384 ** being parsed, or it may point to 1 byte past the end of the position-list
101385 ** (in which case **pp will be a terminator bytes POS_END (0) or
101386 ** (1)).
101387 **
101388 ** If *pp points past the end of the current position-list, set *pi to
101389 ** POSITION_LIST_END and return. Otherwise, read the next varint from *pp,
101390 ** increment the current value of *pi by the value read, and set *pp to
101391 ** point to the next value before returning.
101392 **
101393 ** Before calling this routine *pi must be initialized to the value of
101394 ** the previous position, or zero if we are reading the first position
101395 ** in the position-list. Because positions are delta-encoded, the value
101396 ** of the previous position is needed in order to compute the value of
101397 ** the next position.
101398 */
101399 static void fts3ReadNextPos(
101400 char **pp, /* IN/OUT: Pointer into position-list buffer */
101401 sqlite3_int64 *pi /* IN/OUT: Value read from position-list */
101402 ){
101403 if( (**pp)&0xFE ){
101404 fts3GetDeltaVarint(pp, pi);
101405 *pi -= 2;
101406 }else{
101407 *pi = POSITION_LIST_END;
101408 }
101409 }
101410
101411 /*
101412 ** If parameter iCol is not 0, write an POS_COLUMN (1) byte followed by
101413 ** the value of iCol encoded as a varint to *pp. This will start a new
101414 ** column list.
101415 **
101416 ** Set *pp to point to the byte just after the last byte written before
101417 ** returning (do not modify it if iCol==0). Return the total number of bytes
101418 ** written (0 if iCol==0).
101419 */
@@ -100879,11 +101427,15 @@
101427 }
101428 return n;
101429 }
101430
101431 /*
101432 ** Compute the union of two position lists. The output written
101433 ** into *pp contains all positions of both *pp1 and *pp2 in sorted
101434 ** order and with any duplicates removed. All pointers are
101435 ** updated appropriately. The caller is responsible for insuring
101436 ** that there is enough space in *pp to hold the complete output.
101437 */
101438 static void fts3PoslistMerge(
101439 char **pp, /* Output buffer */
101440 char **pp1, /* Left input list */
101441 char **pp2 /* Right input list */
@@ -100891,36 +101443,37 @@
101443 char *p = *pp;
101444 char *p1 = *pp1;
101445 char *p2 = *pp2;
101446
101447 while( *p1 || *p2 ){
101448 int iCol1; /* The current column index in pp1 */
101449 int iCol2; /* The current column index in pp2 */
101450
101451 if( *p1==POS_COLUMN ) sqlite3Fts3GetVarint32(&p1[1], &iCol1);
101452 else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
101453 else iCol1 = 0;
101454
101455 if( *p2==POS_COLUMN ) sqlite3Fts3GetVarint32(&p2[1], &iCol2);
101456 else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
101457 else iCol2 = 0;
101458
101459 if( iCol1==iCol2 ){
101460 sqlite3_int64 i1 = 0; /* Last position from pp1 */
101461 sqlite3_int64 i2 = 0; /* Last position from pp2 */
101462 sqlite3_int64 iPrev = 0;
101463 int n = fts3PutColNumber(&p, iCol1);
101464 p1 += n;
101465 p2 += n;
101466
101467 /* At this point, both p1 and p2 point to the start of column-lists
101468 ** for the same column (the column with index iCol1 and iCol2).
101469 ** A column-list is a list of non-negative delta-encoded varints, each
101470 ** incremented by 2 before being stored. Each list is terminated by a
101471 ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
101472 ** and writes the results to buffer p. p is left pointing to the byte
101473 ** after the list written. No terminator (POS_END or POS_COLUMN) is
101474 ** written to the output.
101475 */
101476 fts3GetDeltaVarint(&p1, &i1);
101477 fts3GetDeltaVarint(&p2, &i2);
101478 do {
101479 fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
@@ -100931,21 +101484,21 @@
101484 }else if( i1<i2 ){
101485 fts3ReadNextPos(&p1, &i1);
101486 }else{
101487 fts3ReadNextPos(&p2, &i2);
101488 }
101489 }while( i1!=POSITION_LIST_END || i2!=POSITION_LIST_END );
101490 }else if( iCol1<iCol2 ){
101491 p1 += fts3PutColNumber(&p, iCol1);
101492 fts3ColumnlistCopy(&p, &p1);
101493 }else{
101494 p2 += fts3PutColNumber(&p, iCol2);
101495 fts3ColumnlistCopy(&p, &p2);
101496 }
101497 }
101498
101499 *p++ = POS_END;
101500 *pp = p;
101501 *pp1 = p1 + 1;
101502 *pp2 = p2 + 1;
101503 }
101504
@@ -100964,15 +101517,15 @@
101517 char *p2 = *pp2;
101518
101519 int iCol1 = 0;
101520 int iCol2 = 0;
101521 assert( *p1!=0 && *p2!=0 );
101522 if( *p1==POS_COLUMN ){
101523 p1++;
101524 p1 += sqlite3Fts3GetVarint32(p1, &iCol1);
101525 }
101526 if( *p2==POS_COLUMN ){
101527 p2++;
101528 p2 += sqlite3Fts3GetVarint32(p2, &iCol2);
101529 }
101530
101531 while( 1 ){
@@ -100981,15 +101534,16 @@
101534 sqlite3_int64 iPrev = 0;
101535 sqlite3_int64 iPos1 = 0;
101536 sqlite3_int64 iPos2 = 0;
101537
101538 if( pp && iCol1 ){
101539 *p++ = POS_COLUMN;
101540 p += sqlite3Fts3PutVarint(p, iCol1);
101541 }
101542
101543 assert( *p1!=POS_END && *p1!=POS_COLUMN );
101544 assert( *p2!=POS_END && *p2!=POS_COLUMN );
101545 fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
101546 fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
101547
101548 while( 1 ){
101549 if( iPos2>iPos1 && iPos2<=iPos1+nToken ){
@@ -101237,10 +101791,11 @@
101791 }
101792
101793 default: assert( mergetype==MERGE_POS_NEAR || mergetype==MERGE_NEAR ); {
101794 char *aTmp = 0;
101795 char **ppPos = 0;
101796
101797 if( mergetype==MERGE_POS_NEAR ){
101798 ppPos = &p;
101799 aTmp = sqlite3_malloc(2*(n1+n2+1));
101800 if( !aTmp ){
101801 return SQLITE_NOMEM;
@@ -101341,13 +101896,13 @@
101896 ** This function retreives the doclist for the specified term (or term
101897 ** prefix) from the database.
101898 **
101899 ** The returned doclist may be in one of two formats, depending on the
101900 ** value of parameter isReqPos. If isReqPos is zero, then the doclist is
101901 ** a sorted list of delta-compressed docids (a bare doclist). If isReqPos
101902 ** is non-zero, then the returned list is in the same format as is stored
101903 ** in the database without the found length specifier at the start of on-disk
101904 ** doclists.
101905 */
101906 static int fts3TermSelect(
101907 Fts3Table *p, /* Virtual table handle */
101908 int iColumn, /* Column to query (or -ve for all columns) */
@@ -101603,11 +102158,13 @@
102158 return rc;
102159 }
102160
102161 /*
102162 ** Evaluate the full-text expression pExpr against fts3 table pTab. Store
102163 ** the resulting doclist in *paOut and *pnOut. This routine mallocs for
102164 ** the space needed to store the output. The caller is responsible for
102165 ** freeing the space when it has finished.
102166 */
102167 static int evalFts3Expr(
102168 Fts3Table *p, /* Virtual table handle */
102169 Fts3Expr *pExpr, /* Parsed fts3 expression */
102170 char **paOut, /* OUT: Pointer to malloc'd result buffer */
@@ -108163,11 +108720,11 @@
108720 ** This is done as part of extracting the snippet text, not when selecting
108721 ** the snippet. Snippet selection is done based on doclists only, so there
108722 ** is no way for fts3BestSnippet() to know whether or not the document
108723 ** actually contains terms that follow the final highlighted term.
108724 */
108725 static int fts3SnippetShift(
108726 Fts3Table *pTab, /* FTS3 table snippet comes from */
108727 int nSnippet, /* Number of tokens desired for snippet */
108728 const char *zDoc, /* Document text to extract snippet from */
108729 int nDoc, /* Size of buffer zDoc in bytes */
108730 int *piPos, /* IN/OUT: First token of snippet */
@@ -111280,10 +111837,11 @@
111837 rc = SQLITE_CONSTRAINT;
111838 goto constraint;
111839 }
111840 rc = sqlite3_reset(pRtree->pReadRowid);
111841 }
111842 *pRowid = cell.iRowid;
111843
111844 if( rc==SQLITE_OK ){
111845 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
111846 }
111847 if( rc==SQLITE_OK ){
111848
+56 -50
--- 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.6.23.1"
110
+#define SQLITE_VERSION "3.6.23"
111111
#define SQLITE_VERSION_NUMBER 3006023
112
-#define SQLITE_SOURCE_ID "2010-03-26 22:28:06 b078b588d617e07886ad156e9f54ade6d823568e"
112
+#define SQLITE_SOURCE_ID "2010-04-07 19:32:00 1f40441204d9a912b1d6b67ff6ff9e17146c7abd"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -144,11 +144,10 @@
144144
SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
145145
SQLITE_API const char *sqlite3_libversion(void);
146146
SQLITE_API const char *sqlite3_sourceid(void);
147147
SQLITE_API int sqlite3_libversion_number(void);
148148
149
-#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
150149
/*
151150
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
152151
**
153152
** ^The sqlite3_compileoption_used() function returns 0 or 1
154153
** indicating whether the specified option was defined at
@@ -167,13 +166,14 @@
167166
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
168167
**
169168
** See also: SQL functions [sqlite_compileoption_used()] and
170169
** [sqlite_compileoption_get()] and the [compile_options pragma].
171170
*/
171
+#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
172172
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
173173
SQLITE_API const char *sqlite3_compileoption_get(int N);
174
-#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
174
+#endif
175175
176176
/*
177177
** CAPI3REF: Test To See If The Library Is Threadsafe
178178
**
179179
** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -971,15 +971,14 @@
971971
**
972972
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
973973
** ^If the option is unknown or SQLite is unable to set the option
974974
** then this routine returns a non-zero [error code].
975975
*/
976
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
976
+SQLITE_API int sqlite3_config(int, ...);
977977
978978
/*
979979
** CAPI3REF: Configure database connections
980
-** EXPERIMENTAL
981980
**
982981
** The sqlite3_db_config() interface is used to make configuration
983982
** changes to a [database connection]. The interface is similar to
984983
** [sqlite3_config()] except that the changes apply to a single
985984
** [database connection] (specified in the first argument). The
@@ -995,15 +994,14 @@
995994
** Additional arguments depend on the verb.
996995
**
997996
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
998997
** the call is considered successful.
999998
*/
1000
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
999
+SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
10011000
10021001
/*
10031002
** CAPI3REF: Memory Allocation Routines
1004
-** EXPERIMENTAL
10051003
**
10061004
** An instance of this object defines the interface between SQLite
10071005
** and low-level memory allocation routines.
10081006
**
10091007
** This object is used in only one place in the SQLite interface.
@@ -1081,11 +1079,10 @@
10811079
void *pAppData; /* Argument to xInit() and xShutdown() */
10821080
};
10831081
10841082
/*
10851083
** CAPI3REF: Configuration Options
1086
-** EXPERIMENTAL
10871084
**
10881085
** These constants are the available integer configuration options that
10891086
** can be passed as the first argument to the [sqlite3_config()] interface.
10901087
**
10911088
** New configuration options may be added in future releases of SQLite.
@@ -1267,10 +1264,28 @@
12671264
** <dt>SQLITE_CONFIG_GETPCACHE</dt>
12681265
** <dd> ^(This option takes a single argument which is a pointer to an
12691266
** [sqlite3_pcache_methods] object. SQLite copies of the current
12701267
** page cache implementation into that object.)^ </dd>
12711268
**
1269
+** <dt>SQLITE_CONFIG_LOG</dt>
1270
+** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1271
+** function with a call signature of void(*)(void*,int,const char*),
1272
+** and a pointer to void. ^If the function pointer is not NULL, it is
1273
+** invoked by [sqlite3_log()] to process each logging event. ^If the
1274
+** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1275
+** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1276
+** passed through as the first parameter to the application-defined logger
1277
+** function whenever that function is invoked. ^The second parameter to
1278
+** the logger function is a copy of the first parameter to the corresponding
1279
+** [sqlite3_log()] call and is intended to be a [result code] or an
1280
+** [extended result code]. ^The third parameter passed to the logger is
1281
+** log message after formatting via [sqlite3_snprintf()].
1282
+** The SQLite logging interface is not reentrant; the logger function
1283
+** supplied by the application must not invoke any SQLite interface.
1284
+** In a multi-threaded application, the application-defined logger
1285
+** function must be threadsafe. </dd>
1286
+**
12721287
** </dl>
12731288
*/
12741289
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
12751290
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
12761291
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1287,12 +1302,11 @@
12871302
#define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
12881303
#define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
12891304
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
12901305
12911306
/*
1292
-** CAPI3REF: Configuration Options
1293
-** EXPERIMENTAL
1307
+** CAPI3REF: Database Connection Configuration Options
12941308
**
12951309
** These constants are the available integer configuration options that
12961310
** can be passed as the second argument to the [sqlite3_db_config()] interface.
12971311
**
12981312
** New configuration options may be added in future releases of SQLite.
@@ -2064,11 +2078,10 @@
20642078
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
20652079
#define SQLITE_COPY 0 /* No longer used */
20662080
20672081
/*
20682082
** CAPI3REF: Tracing And Profiling Functions
2069
-** EXPERIMENTAL
20702083
**
20712084
** These routines register callback functions that can be used for
20722085
** tracing and profiling the execution of SQL statements.
20732086
**
20742087
** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2082,11 +2095,11 @@
20822095
** ^The callback function registered by sqlite3_profile() is invoked
20832096
** as each SQL statement finishes. ^The profile callback contains
20842097
** the original statement text and an estimate of wall-clock time
20852098
** of how long that statement took to run.
20862099
*/
2087
-SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2100
+SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
20882101
SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
20892102
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
20902103
20912104
/*
20922105
** CAPI3REF: Query Progress Callbacks
@@ -3687,11 +3700,11 @@
36873700
sqlite3*,
36883701
void*,
36893702
void(*)(void*,sqlite3*,int eTextRep,const void*)
36903703
);
36913704
3692
-#if SQLITE_HAS_CODEC
3705
+#ifdef SQLITE_HAS_CODEC
36933706
/*
36943707
** Specify the key for an encrypted database. This routine should be
36953708
** called right after sqlite3_open().
36963709
**
36973710
** The code to implement this API is not available in the public release
@@ -4157,12 +4170,10 @@
41574170
** ^This function disables automatic extensions in all threads.
41584171
*/
41594172
SQLITE_API void sqlite3_reset_auto_extension(void);
41604173
41614174
/*
4162
-****** EXPERIMENTAL - subject to change without notice **************
4163
-**
41644175
** The interface to the virtual-table mechanism is currently considered
41654176
** to be experimental. The interface might change in incompatible ways.
41664177
** If this is a problem for you, do not use the interface at this time.
41674178
**
41684179
** When the virtual-table mechanism stabilizes, we will declare the
@@ -4178,11 +4189,10 @@
41784189
typedef struct sqlite3_module sqlite3_module;
41794190
41804191
/*
41814192
** CAPI3REF: Virtual Table Object
41824193
** KEYWORDS: sqlite3_module {virtual table module}
4183
-** EXPERIMENTAL
41844194
**
41854195
** This structure, sometimes called a a "virtual table module",
41864196
** defines the implementation of a [virtual tables].
41874197
** This structure consists mostly of methods for the module.
41884198
**
@@ -4225,11 +4235,10 @@
42254235
};
42264236
42274237
/*
42284238
** CAPI3REF: Virtual Table Indexing Information
42294239
** KEYWORDS: sqlite3_index_info
4230
-** EXPERIMENTAL
42314240
**
42324241
** The sqlite3_index_info structure and its substructures is used to
42334242
** pass information into and receive the reply from the [xBestIndex]
42344243
** method of a [virtual table module]. The fields under **Inputs** are the
42354244
** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4307,11 +4316,10 @@
43074316
#define SQLITE_INDEX_CONSTRAINT_GE 32
43084317
#define SQLITE_INDEX_CONSTRAINT_MATCH 64
43094318
43104319
/*
43114320
** CAPI3REF: Register A Virtual Table Implementation
4312
-** EXPERIMENTAL
43134321
**
43144322
** ^These routines are used to register a new [virtual table module] name.
43154323
** ^Module names must be registered before
43164324
** creating a new [virtual table] using the module and before using a
43174325
** preexisting [virtual table] for the module.
@@ -4329,17 +4337,17 @@
43294337
** invoke the destructor function (if it is not NULL) when SQLite
43304338
** no longer needs the pClientData pointer. ^The sqlite3_create_module()
43314339
** interface is equivalent to sqlite3_create_module_v2() with a NULL
43324340
** destructor.
43334341
*/
4334
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4342
+SQLITE_API int sqlite3_create_module(
43354343
sqlite3 *db, /* SQLite connection to register module with */
43364344
const char *zName, /* Name of the module */
43374345
const sqlite3_module *p, /* Methods for the module */
43384346
void *pClientData /* Client data for xCreate/xConnect */
43394347
);
4340
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4348
+SQLITE_API int sqlite3_create_module_v2(
43414349
sqlite3 *db, /* SQLite connection to register module with */
43424350
const char *zName, /* Name of the module */
43434351
const sqlite3_module *p, /* Methods for the module */
43444352
void *pClientData, /* Client data for xCreate/xConnect */
43454353
void(*xDestroy)(void*) /* Module destructor function */
@@ -4346,11 +4354,10 @@
43464354
);
43474355
43484356
/*
43494357
** CAPI3REF: Virtual Table Instance Object
43504358
** KEYWORDS: sqlite3_vtab
4351
-** EXPERIMENTAL
43524359
**
43534360
** Every [virtual table module] implementation uses a subclass
43544361
** of this object to describe a particular instance
43554362
** of the [virtual table]. Each subclass will
43564363
** be tailored to the specific needs of the module implementation.
@@ -4372,11 +4379,10 @@
43724379
};
43734380
43744381
/*
43754382
** CAPI3REF: Virtual Table Cursor Object
43764383
** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4377
-** EXPERIMENTAL
43784384
**
43794385
** Every [virtual table module] implementation uses a subclass of the
43804386
** following structure to describe cursors that point into the
43814387
** [virtual table] and are used
43824388
** to loop through the virtual table. Cursors are created using the
@@ -4394,22 +4400,20 @@
43944400
/* Virtual table implementations will typically add additional fields */
43954401
};
43964402
43974403
/*
43984404
** CAPI3REF: Declare The Schema Of A Virtual Table
4399
-** EXPERIMENTAL
44004405
**
44014406
** ^The [xCreate] and [xConnect] methods of a
44024407
** [virtual table module] call this interface
44034408
** to declare the format (the names and datatypes of the columns) of
44044409
** the virtual tables they implement.
44054410
*/
4406
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4411
+SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
44074412
44084413
/*
44094414
** CAPI3REF: Overload A Function For A Virtual Table
4410
-** EXPERIMENTAL
44114415
**
44124416
** ^(Virtual tables can provide alternative implementations of functions
44134417
** using the [xFindFunction] method of the [virtual table module].
44144418
** But global versions of those functions
44154419
** must exist in order to be overloaded.)^
@@ -4420,22 +4424,20 @@
44204424
** of the new function always causes an exception to be thrown. So
44214425
** the new function is not good for anything by itself. Its only
44224426
** purpose is to be a placeholder function that can be overloaded
44234427
** by a [virtual table].
44244428
*/
4425
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4429
+SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
44264430
44274431
/*
44284432
** The interface to the virtual-table mechanism defined above (back up
44294433
** to a comment remarkably similar to this one) is currently considered
44304434
** to be experimental. The interface might change in incompatible ways.
44314435
** If this is a problem for you, do not use the interface at this time.
44324436
**
44334437
** When the virtual-table mechanism stabilizes, we will declare the
44344438
** interface fixed, support it indefinitely, and remove this comment.
4435
-**
4436
-****** EXPERIMENTAL - subject to change without notice **************
44374439
*/
44384440
44394441
/*
44404442
** CAPI3REF: A Handle To An Open BLOB
44414443
** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -4774,11 +4776,10 @@
47744776
SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
47754777
SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
47764778
47774779
/*
47784780
** CAPI3REF: Mutex Methods Object
4779
-** EXPERIMENTAL
47804781
**
47814782
** An instance of this structure defines the low-level routines
47824783
** used to allocate and use mutexes.
47834784
**
47844785
** Usually, the default mutex implementations provided by SQLite are
@@ -4991,11 +4992,10 @@
49914992
#define SQLITE_TESTCTRL_ISKEYWORD 16
49924993
#define SQLITE_TESTCTRL_LAST 16
49934994
49944995
/*
49954996
** CAPI3REF: SQLite Runtime Status
4996
-** EXPERIMENTAL
49974997
**
49984998
** ^This interface is used to retrieve runtime status information
49994999
** about the preformance of SQLite, and optionally to reset various
50005000
** highwater marks. ^The first argument is an integer code for
50015001
** the specific parameter to measure. ^(Recognized integer codes
@@ -5019,16 +5019,15 @@
50195019
** and it is possible that another thread might change the parameter
50205020
** in between the times when *pCurrent and *pHighwater are written.
50215021
**
50225022
** See also: [sqlite3_db_status()]
50235023
*/
5024
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5024
+SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
50255025
50265026
50275027
/*
50285028
** CAPI3REF: Status Parameters
5029
-** EXPERIMENTAL
50305029
**
50315030
** These integer constants designate various run-time status parameters
50325031
** that can be returned by [sqlite3_status()].
50335032
**
50345033
** <dl>
@@ -5111,31 +5110,31 @@
51115110
#define SQLITE_STATUS_PAGECACHE_SIZE 7
51125111
#define SQLITE_STATUS_SCRATCH_SIZE 8
51135112
51145113
/*
51155114
** CAPI3REF: Database Connection Status
5116
-** EXPERIMENTAL
51175115
**
51185116
** ^This interface is used to retrieve runtime status information
51195117
** about a single [database connection]. ^The first argument is the
51205118
** database connection object to be interrogated. ^The second argument
5121
-** is the parameter to interrogate. ^Currently, the only allowed value
5122
-** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5123
-** Additional options will likely appear in future releases of SQLite.
5119
+** is an integer constant, taken from the set of
5120
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5121
+** determiness the parameter to interrogate. The set of
5122
+** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5123
+** to grow in future releases of SQLite.
51245124
**
51255125
** ^The current value of the requested parameter is written into *pCur
51265126
** and the highest instantaneous value is written into *pHiwtr. ^If
51275127
** the resetFlg is true, then the highest instantaneous value is
51285128
** reset back down to the current value.
51295129
**
51305130
** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
51315131
*/
5132
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5132
+SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
51335133
51345134
/*
51355135
** CAPI3REF: Status Parameters for database connections
5136
-** EXPERIMENTAL
51375136
**
51385137
** These constants are the available integer "verbs" that can be passed as
51395138
** the second argument to the [sqlite3_db_status()] interface.
51405139
**
51415140
** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5146,18 +5145,25 @@
51465145
**
51475146
** <dl>
51485147
** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
51495148
** <dd>This parameter returns the number of lookaside memory slots currently
51505149
** checked out.</dd>)^
5150
+**
5151
+** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5152
+** <dd>^This parameter returns the approximate number of of bytes of heap
5153
+** memory used by all pager caches associated with the database connection.
5154
+** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5155
+** checked out.</dd>)^
51515156
** </dl>
51525157
*/
51535158
#define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5159
+#define SQLITE_DBSTATUS_CACHE_USED 1
5160
+#define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
51545161
51555162
51565163
/*
51575164
** CAPI3REF: Prepared Statement Status
5158
-** EXPERIMENTAL
51595165
**
51605166
** ^(Each prepared statement maintains various
51615167
** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
51625168
** of times it has performed specific operations.)^ These counters can
51635169
** be used to monitor the performance characteristics of the prepared
@@ -5175,15 +5181,14 @@
51755181
** ^If the resetFlg is true, then the counter is reset to zero after this
51765182
** interface call returns.
51775183
**
51785184
** See also: [sqlite3_status()] and [sqlite3_db_status()].
51795185
*/
5180
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5186
+SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
51815187
51825188
/*
51835189
** CAPI3REF: Status Parameters for prepared statements
5184
-** EXPERIMENTAL
51855190
**
51865191
** These preprocessor macros define integer codes that name counter
51875192
** values associated with the [sqlite3_stmt_status()] interface.
51885193
** The meanings of the various counters are as follows:
51895194
**
@@ -5197,18 +5202,25 @@
51975202
** <dt>SQLITE_STMTSTATUS_SORT</dt>
51985203
** <dd>^This is the number of sort operations that have occurred.
51995204
** A non-zero value in this counter may indicate an opportunity to
52005205
** improvement performance through careful use of indices.</dd>
52015206
**
5207
+** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5208
+** <dd>^This is the number of rows inserted into transient indices that
5209
+** were created automatically in order to help joins run faster.
5210
+** A non-zero value in this counter may indicate an opportunity to
5211
+** improvement performance by adding permanent indices that do not
5212
+** need to be reinitialized each time the statement is run.</dd>
5213
+**
52025214
** </dl>
52035215
*/
52045216
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
52055217
#define SQLITE_STMTSTATUS_SORT 2
5218
+#define SQLITE_STMTSTATUS_AUTOINDEX 3
52065219
52075220
/*
52085221
** CAPI3REF: Custom Page Cache Object
5209
-** EXPERIMENTAL
52105222
**
52115223
** The sqlite3_pcache type is opaque. It is implemented by
52125224
** the pluggable module. The SQLite core has no knowledge of
52135225
** its size or internal structure and never deals with the
52145226
** sqlite3_pcache object except by holding and passing pointers
@@ -5219,11 +5231,10 @@
52195231
typedef struct sqlite3_pcache sqlite3_pcache;
52205232
52215233
/*
52225234
** CAPI3REF: Application Defined Page Cache.
52235235
** KEYWORDS: {page cache}
5224
-** EXPERIMENTAL
52255236
**
52265237
** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
52275238
** register an alternative page cache implementation by passing in an
52285239
** instance of the sqlite3_pcache_methods structure.)^ The majority of the
52295240
** heap memory used by SQLite is used by the page cache to cache data read
@@ -5361,11 +5372,10 @@
53615372
void (*xDestroy)(sqlite3_pcache*);
53625373
};
53635374
53645375
/*
53655376
** CAPI3REF: Online Backup Object
5366
-** EXPERIMENTAL
53675377
**
53685378
** The sqlite3_backup object records state information about an ongoing
53695379
** online backup operation. ^The sqlite3_backup object is created by
53705380
** a call to [sqlite3_backup_init()] and is destroyed by a call to
53715381
** [sqlite3_backup_finish()].
@@ -5374,11 +5384,10 @@
53745384
*/
53755385
typedef struct sqlite3_backup sqlite3_backup;
53765386
53775387
/*
53785388
** CAPI3REF: Online Backup API.
5379
-** EXPERIMENTAL
53805389
**
53815390
** The backup API copies the content of one database into another.
53825391
** It is useful either for creating backups of databases or
53835392
** for copying in-memory databases to or from persistent files.
53845393
**
@@ -5562,11 +5571,10 @@
55625571
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
55635572
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
55645573
55655574
/*
55665575
** CAPI3REF: Unlock Notification
5567
-** EXPERIMENTAL
55685576
**
55695577
** ^When running in shared-cache mode, a database operation may fail with
55705578
** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
55715579
** individual tables within the shared-cache cannot be obtained. See
55725580
** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -5684,11 +5692,10 @@
56845692
);
56855693
56865694
56875695
/*
56885696
** CAPI3REF: String Comparison
5689
-** EXPERIMENTAL
56905697
**
56915698
** ^The [sqlite3_strnicmp()] API allows applications and extensions to
56925699
** compare the contents of two buffers containing UTF-8 strings in a
56935700
** case-indendent fashion, using the same definition of case independence
56945701
** that SQLite uses internally when comparing identifiers.
@@ -5695,16 +5702,15 @@
56955702
*/
56965703
SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
56975704
56985705
/*
56995706
** CAPI3REF: Error Logging Interface
5700
-** EXPERIMENTAL
57015707
**
57025708
** ^The [sqlite3_log()] interface writes a message into the error log
57035709
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
57045710
** ^If logging is enabled, the zFormat string and subsequent arguments are
5705
-** passed through to [sqlite3_vmprintf()] to generate the final output string.
5711
+** used with [sqlite3_snprintf()] to generate the final output string.
57065712
**
57075713
** The sqlite3_log() interface is intended for use by extensions such as
57085714
** virtual tables, collating functions, and SQL functions. While there is
57095715
** nothing to prevent an application from calling sqlite3_log(), doing so
57105716
** is considered bad form.
57115717
--- 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.6.23.1"
111 #define SQLITE_VERSION_NUMBER 3006023
112 #define SQLITE_SOURCE_ID "2010-03-26 22:28:06 b078b588d617e07886ad156e9f54ade6d823568e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -144,11 +144,10 @@
144 SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
145 SQLITE_API const char *sqlite3_libversion(void);
146 SQLITE_API const char *sqlite3_sourceid(void);
147 SQLITE_API int sqlite3_libversion_number(void);
148
149 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
150 /*
151 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
152 **
153 ** ^The sqlite3_compileoption_used() function returns 0 or 1
154 ** indicating whether the specified option was defined at
@@ -167,13 +166,14 @@
167 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
168 **
169 ** See also: SQL functions [sqlite_compileoption_used()] and
170 ** [sqlite_compileoption_get()] and the [compile_options pragma].
171 */
 
172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
173 SQLITE_API const char *sqlite3_compileoption_get(int N);
174 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
175
176 /*
177 ** CAPI3REF: Test To See If The Library Is Threadsafe
178 **
179 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -971,15 +971,14 @@
971 **
972 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
973 ** ^If the option is unknown or SQLite is unable to set the option
974 ** then this routine returns a non-zero [error code].
975 */
976 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...);
977
978 /*
979 ** CAPI3REF: Configure database connections
980 ** EXPERIMENTAL
981 **
982 ** The sqlite3_db_config() interface is used to make configuration
983 ** changes to a [database connection]. The interface is similar to
984 ** [sqlite3_config()] except that the changes apply to a single
985 ** [database connection] (specified in the first argument). The
@@ -995,15 +994,14 @@
995 ** Additional arguments depend on the verb.
996 **
997 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
998 ** the call is considered successful.
999 */
1000 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...);
1001
1002 /*
1003 ** CAPI3REF: Memory Allocation Routines
1004 ** EXPERIMENTAL
1005 **
1006 ** An instance of this object defines the interface between SQLite
1007 ** and low-level memory allocation routines.
1008 **
1009 ** This object is used in only one place in the SQLite interface.
@@ -1081,11 +1079,10 @@
1081 void *pAppData; /* Argument to xInit() and xShutdown() */
1082 };
1083
1084 /*
1085 ** CAPI3REF: Configuration Options
1086 ** EXPERIMENTAL
1087 **
1088 ** These constants are the available integer configuration options that
1089 ** can be passed as the first argument to the [sqlite3_config()] interface.
1090 **
1091 ** New configuration options may be added in future releases of SQLite.
@@ -1267,10 +1264,28 @@
1267 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1268 ** <dd> ^(This option takes a single argument which is a pointer to an
1269 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1270 ** page cache implementation into that object.)^ </dd>
1271 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1272 ** </dl>
1273 */
1274 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1275 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1276 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1287,12 +1302,11 @@
1287 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1288 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1289 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1290
1291 /*
1292 ** CAPI3REF: Configuration Options
1293 ** EXPERIMENTAL
1294 **
1295 ** These constants are the available integer configuration options that
1296 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1297 **
1298 ** New configuration options may be added in future releases of SQLite.
@@ -2064,11 +2078,10 @@
2064 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2065 #define SQLITE_COPY 0 /* No longer used */
2066
2067 /*
2068 ** CAPI3REF: Tracing And Profiling Functions
2069 ** EXPERIMENTAL
2070 **
2071 ** These routines register callback functions that can be used for
2072 ** tracing and profiling the execution of SQL statements.
2073 **
2074 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2082,11 +2095,11 @@
2082 ** ^The callback function registered by sqlite3_profile() is invoked
2083 ** as each SQL statement finishes. ^The profile callback contains
2084 ** the original statement text and an estimate of wall-clock time
2085 ** of how long that statement took to run.
2086 */
2087 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2088 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2089 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2090
2091 /*
2092 ** CAPI3REF: Query Progress Callbacks
@@ -3687,11 +3700,11 @@
3687 sqlite3*,
3688 void*,
3689 void(*)(void*,sqlite3*,int eTextRep,const void*)
3690 );
3691
3692 #if SQLITE_HAS_CODEC
3693 /*
3694 ** Specify the key for an encrypted database. This routine should be
3695 ** called right after sqlite3_open().
3696 **
3697 ** The code to implement this API is not available in the public release
@@ -4157,12 +4170,10 @@
4157 ** ^This function disables automatic extensions in all threads.
4158 */
4159 SQLITE_API void sqlite3_reset_auto_extension(void);
4160
4161 /*
4162 ****** EXPERIMENTAL - subject to change without notice **************
4163 **
4164 ** The interface to the virtual-table mechanism is currently considered
4165 ** to be experimental. The interface might change in incompatible ways.
4166 ** If this is a problem for you, do not use the interface at this time.
4167 **
4168 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4178,11 +4189,10 @@
4178 typedef struct sqlite3_module sqlite3_module;
4179
4180 /*
4181 ** CAPI3REF: Virtual Table Object
4182 ** KEYWORDS: sqlite3_module {virtual table module}
4183 ** EXPERIMENTAL
4184 **
4185 ** This structure, sometimes called a a "virtual table module",
4186 ** defines the implementation of a [virtual tables].
4187 ** This structure consists mostly of methods for the module.
4188 **
@@ -4225,11 +4235,10 @@
4225 };
4226
4227 /*
4228 ** CAPI3REF: Virtual Table Indexing Information
4229 ** KEYWORDS: sqlite3_index_info
4230 ** EXPERIMENTAL
4231 **
4232 ** The sqlite3_index_info structure and its substructures is used to
4233 ** pass information into and receive the reply from the [xBestIndex]
4234 ** method of a [virtual table module]. The fields under **Inputs** are the
4235 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4307,11 +4316,10 @@
4307 #define SQLITE_INDEX_CONSTRAINT_GE 32
4308 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4309
4310 /*
4311 ** CAPI3REF: Register A Virtual Table Implementation
4312 ** EXPERIMENTAL
4313 **
4314 ** ^These routines are used to register a new [virtual table module] name.
4315 ** ^Module names must be registered before
4316 ** creating a new [virtual table] using the module and before using a
4317 ** preexisting [virtual table] for the module.
@@ -4329,17 +4337,17 @@
4329 ** invoke the destructor function (if it is not NULL) when SQLite
4330 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4331 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4332 ** destructor.
4333 */
4334 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module(
4335 sqlite3 *db, /* SQLite connection to register module with */
4336 const char *zName, /* Name of the module */
4337 const sqlite3_module *p, /* Methods for the module */
4338 void *pClientData /* Client data for xCreate/xConnect */
4339 );
4340 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2(
4341 sqlite3 *db, /* SQLite connection to register module with */
4342 const char *zName, /* Name of the module */
4343 const sqlite3_module *p, /* Methods for the module */
4344 void *pClientData, /* Client data for xCreate/xConnect */
4345 void(*xDestroy)(void*) /* Module destructor function */
@@ -4346,11 +4354,10 @@
4346 );
4347
4348 /*
4349 ** CAPI3REF: Virtual Table Instance Object
4350 ** KEYWORDS: sqlite3_vtab
4351 ** EXPERIMENTAL
4352 **
4353 ** Every [virtual table module] implementation uses a subclass
4354 ** of this object to describe a particular instance
4355 ** of the [virtual table]. Each subclass will
4356 ** be tailored to the specific needs of the module implementation.
@@ -4372,11 +4379,10 @@
4372 };
4373
4374 /*
4375 ** CAPI3REF: Virtual Table Cursor Object
4376 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
4377 ** EXPERIMENTAL
4378 **
4379 ** Every [virtual table module] implementation uses a subclass of the
4380 ** following structure to describe cursors that point into the
4381 ** [virtual table] and are used
4382 ** to loop through the virtual table. Cursors are created using the
@@ -4394,22 +4400,20 @@
4394 /* Virtual table implementations will typically add additional fields */
4395 };
4396
4397 /*
4398 ** CAPI3REF: Declare The Schema Of A Virtual Table
4399 ** EXPERIMENTAL
4400 **
4401 ** ^The [xCreate] and [xConnect] methods of a
4402 ** [virtual table module] call this interface
4403 ** to declare the format (the names and datatypes of the columns) of
4404 ** the virtual tables they implement.
4405 */
4406 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4407
4408 /*
4409 ** CAPI3REF: Overload A Function For A Virtual Table
4410 ** EXPERIMENTAL
4411 **
4412 ** ^(Virtual tables can provide alternative implementations of functions
4413 ** using the [xFindFunction] method of the [virtual table module].
4414 ** But global versions of those functions
4415 ** must exist in order to be overloaded.)^
@@ -4420,22 +4424,20 @@
4420 ** of the new function always causes an exception to be thrown. So
4421 ** the new function is not good for anything by itself. Its only
4422 ** purpose is to be a placeholder function that can be overloaded
4423 ** by a [virtual table].
4424 */
4425 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4426
4427 /*
4428 ** The interface to the virtual-table mechanism defined above (back up
4429 ** to a comment remarkably similar to this one) is currently considered
4430 ** to be experimental. The interface might change in incompatible ways.
4431 ** If this is a problem for you, do not use the interface at this time.
4432 **
4433 ** When the virtual-table mechanism stabilizes, we will declare the
4434 ** interface fixed, support it indefinitely, and remove this comment.
4435 **
4436 ****** EXPERIMENTAL - subject to change without notice **************
4437 */
4438
4439 /*
4440 ** CAPI3REF: A Handle To An Open BLOB
4441 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -4774,11 +4776,10 @@
4774 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
4775 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
4776
4777 /*
4778 ** CAPI3REF: Mutex Methods Object
4779 ** EXPERIMENTAL
4780 **
4781 ** An instance of this structure defines the low-level routines
4782 ** used to allocate and use mutexes.
4783 **
4784 ** Usually, the default mutex implementations provided by SQLite are
@@ -4991,11 +4992,10 @@
4991 #define SQLITE_TESTCTRL_ISKEYWORD 16
4992 #define SQLITE_TESTCTRL_LAST 16
4993
4994 /*
4995 ** CAPI3REF: SQLite Runtime Status
4996 ** EXPERIMENTAL
4997 **
4998 ** ^This interface is used to retrieve runtime status information
4999 ** about the preformance of SQLite, and optionally to reset various
5000 ** highwater marks. ^The first argument is an integer code for
5001 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5019,16 +5019,15 @@
5019 ** and it is possible that another thread might change the parameter
5020 ** in between the times when *pCurrent and *pHighwater are written.
5021 **
5022 ** See also: [sqlite3_db_status()]
5023 */
5024 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5025
5026
5027 /*
5028 ** CAPI3REF: Status Parameters
5029 ** EXPERIMENTAL
5030 **
5031 ** These integer constants designate various run-time status parameters
5032 ** that can be returned by [sqlite3_status()].
5033 **
5034 ** <dl>
@@ -5111,31 +5110,31 @@
5111 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5112 #define SQLITE_STATUS_SCRATCH_SIZE 8
5113
5114 /*
5115 ** CAPI3REF: Database Connection Status
5116 ** EXPERIMENTAL
5117 **
5118 ** ^This interface is used to retrieve runtime status information
5119 ** about a single [database connection]. ^The first argument is the
5120 ** database connection object to be interrogated. ^The second argument
5121 ** is the parameter to interrogate. ^Currently, the only allowed value
5122 ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED].
5123 ** Additional options will likely appear in future releases of SQLite.
 
 
5124 **
5125 ** ^The current value of the requested parameter is written into *pCur
5126 ** and the highest instantaneous value is written into *pHiwtr. ^If
5127 ** the resetFlg is true, then the highest instantaneous value is
5128 ** reset back down to the current value.
5129 **
5130 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5131 */
5132 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5133
5134 /*
5135 ** CAPI3REF: Status Parameters for database connections
5136 ** EXPERIMENTAL
5137 **
5138 ** These constants are the available integer "verbs" that can be passed as
5139 ** the second argument to the [sqlite3_db_status()] interface.
5140 **
5141 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5146,18 +5145,25 @@
5146 **
5147 ** <dl>
5148 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5149 ** <dd>This parameter returns the number of lookaside memory slots currently
5150 ** checked out.</dd>)^
 
 
 
 
 
 
5151 ** </dl>
5152 */
5153 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
 
 
5154
5155
5156 /*
5157 ** CAPI3REF: Prepared Statement Status
5158 ** EXPERIMENTAL
5159 **
5160 ** ^(Each prepared statement maintains various
5161 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5162 ** of times it has performed specific operations.)^ These counters can
5163 ** be used to monitor the performance characteristics of the prepared
@@ -5175,15 +5181,14 @@
5175 ** ^If the resetFlg is true, then the counter is reset to zero after this
5176 ** interface call returns.
5177 **
5178 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5179 */
5180 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5181
5182 /*
5183 ** CAPI3REF: Status Parameters for prepared statements
5184 ** EXPERIMENTAL
5185 **
5186 ** These preprocessor macros define integer codes that name counter
5187 ** values associated with the [sqlite3_stmt_status()] interface.
5188 ** The meanings of the various counters are as follows:
5189 **
@@ -5197,18 +5202,25 @@
5197 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5198 ** <dd>^This is the number of sort operations that have occurred.
5199 ** A non-zero value in this counter may indicate an opportunity to
5200 ** improvement performance through careful use of indices.</dd>
5201 **
 
 
 
 
 
 
 
5202 ** </dl>
5203 */
5204 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5205 #define SQLITE_STMTSTATUS_SORT 2
 
5206
5207 /*
5208 ** CAPI3REF: Custom Page Cache Object
5209 ** EXPERIMENTAL
5210 **
5211 ** The sqlite3_pcache type is opaque. It is implemented by
5212 ** the pluggable module. The SQLite core has no knowledge of
5213 ** its size or internal structure and never deals with the
5214 ** sqlite3_pcache object except by holding and passing pointers
@@ -5219,11 +5231,10 @@
5219 typedef struct sqlite3_pcache sqlite3_pcache;
5220
5221 /*
5222 ** CAPI3REF: Application Defined Page Cache.
5223 ** KEYWORDS: {page cache}
5224 ** EXPERIMENTAL
5225 **
5226 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5227 ** register an alternative page cache implementation by passing in an
5228 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5229 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5361,11 +5372,10 @@
5361 void (*xDestroy)(sqlite3_pcache*);
5362 };
5363
5364 /*
5365 ** CAPI3REF: Online Backup Object
5366 ** EXPERIMENTAL
5367 **
5368 ** The sqlite3_backup object records state information about an ongoing
5369 ** online backup operation. ^The sqlite3_backup object is created by
5370 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5371 ** [sqlite3_backup_finish()].
@@ -5374,11 +5384,10 @@
5374 */
5375 typedef struct sqlite3_backup sqlite3_backup;
5376
5377 /*
5378 ** CAPI3REF: Online Backup API.
5379 ** EXPERIMENTAL
5380 **
5381 ** The backup API copies the content of one database into another.
5382 ** It is useful either for creating backups of databases or
5383 ** for copying in-memory databases to or from persistent files.
5384 **
@@ -5562,11 +5571,10 @@
5562 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
5563 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
5564
5565 /*
5566 ** CAPI3REF: Unlock Notification
5567 ** EXPERIMENTAL
5568 **
5569 ** ^When running in shared-cache mode, a database operation may fail with
5570 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
5571 ** individual tables within the shared-cache cannot be obtained. See
5572 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -5684,11 +5692,10 @@
5684 );
5685
5686
5687 /*
5688 ** CAPI3REF: String Comparison
5689 ** EXPERIMENTAL
5690 **
5691 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
5692 ** compare the contents of two buffers containing UTF-8 strings in a
5693 ** case-indendent fashion, using the same definition of case independence
5694 ** that SQLite uses internally when comparing identifiers.
@@ -5695,16 +5702,15 @@
5695 */
5696 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
5697
5698 /*
5699 ** CAPI3REF: Error Logging Interface
5700 ** EXPERIMENTAL
5701 **
5702 ** ^The [sqlite3_log()] interface writes a message into the error log
5703 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
5704 ** ^If logging is enabled, the zFormat string and subsequent arguments are
5705 ** passed through to [sqlite3_vmprintf()] to generate the final output string.
5706 **
5707 ** The sqlite3_log() interface is intended for use by extensions such as
5708 ** virtual tables, collating functions, and SQL functions. While there is
5709 ** nothing to prevent an application from calling sqlite3_log(), doing so
5710 ** is considered bad form.
5711
--- 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.6.23"
111 #define SQLITE_VERSION_NUMBER 3006023
112 #define SQLITE_SOURCE_ID "2010-04-07 19:32:00 1f40441204d9a912b1d6b67ff6ff9e17146c7abd"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -144,11 +144,10 @@
144 SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
145 SQLITE_API const char *sqlite3_libversion(void);
146 SQLITE_API const char *sqlite3_sourceid(void);
147 SQLITE_API int sqlite3_libversion_number(void);
148
 
149 /*
150 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
151 **
152 ** ^The sqlite3_compileoption_used() function returns 0 or 1
153 ** indicating whether the specified option was defined at
@@ -167,13 +166,14 @@
166 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
167 **
168 ** See also: SQL functions [sqlite_compileoption_used()] and
169 ** [sqlite_compileoption_get()] and the [compile_options pragma].
170 */
171 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
173 SQLITE_API const char *sqlite3_compileoption_get(int N);
174 #endif
175
176 /*
177 ** CAPI3REF: Test To See If The Library Is Threadsafe
178 **
179 ** ^The sqlite3_threadsafe() function returns zero if and only if
@@ -971,15 +971,14 @@
971 **
972 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
973 ** ^If the option is unknown or SQLite is unable to set the option
974 ** then this routine returns a non-zero [error code].
975 */
976 SQLITE_API int sqlite3_config(int, ...);
977
978 /*
979 ** CAPI3REF: Configure database connections
 
980 **
981 ** The sqlite3_db_config() interface is used to make configuration
982 ** changes to a [database connection]. The interface is similar to
983 ** [sqlite3_config()] except that the changes apply to a single
984 ** [database connection] (specified in the first argument). The
@@ -995,15 +994,14 @@
994 ** Additional arguments depend on the verb.
995 **
996 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
997 ** the call is considered successful.
998 */
999 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1000
1001 /*
1002 ** CAPI3REF: Memory Allocation Routines
 
1003 **
1004 ** An instance of this object defines the interface between SQLite
1005 ** and low-level memory allocation routines.
1006 **
1007 ** This object is used in only one place in the SQLite interface.
@@ -1081,11 +1079,10 @@
1079 void *pAppData; /* Argument to xInit() and xShutdown() */
1080 };
1081
1082 /*
1083 ** CAPI3REF: Configuration Options
 
1084 **
1085 ** These constants are the available integer configuration options that
1086 ** can be passed as the first argument to the [sqlite3_config()] interface.
1087 **
1088 ** New configuration options may be added in future releases of SQLite.
@@ -1267,10 +1264,28 @@
1264 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
1265 ** <dd> ^(This option takes a single argument which is a pointer to an
1266 ** [sqlite3_pcache_methods] object. SQLite copies of the current
1267 ** page cache implementation into that object.)^ </dd>
1268 **
1269 ** <dt>SQLITE_CONFIG_LOG</dt>
1270 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1271 ** function with a call signature of void(*)(void*,int,const char*),
1272 ** and a pointer to void. ^If the function pointer is not NULL, it is
1273 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1274 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1275 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1276 ** passed through as the first parameter to the application-defined logger
1277 ** function whenever that function is invoked. ^The second parameter to
1278 ** the logger function is a copy of the first parameter to the corresponding
1279 ** [sqlite3_log()] call and is intended to be a [result code] or an
1280 ** [extended result code]. ^The third parameter passed to the logger is
1281 ** log message after formatting via [sqlite3_snprintf()].
1282 ** The SQLite logging interface is not reentrant; the logger function
1283 ** supplied by the application must not invoke any SQLite interface.
1284 ** In a multi-threaded application, the application-defined logger
1285 ** function must be threadsafe. </dd>
1286 **
1287 ** </dl>
1288 */
1289 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1290 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1291 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -1287,12 +1302,11 @@
1302 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */
1303 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */
1304 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
1305
1306 /*
1307 ** CAPI3REF: Database Connection Configuration Options
 
1308 **
1309 ** These constants are the available integer configuration options that
1310 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
1311 **
1312 ** New configuration options may be added in future releases of SQLite.
@@ -2064,11 +2078,10 @@
2078 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
2079 #define SQLITE_COPY 0 /* No longer used */
2080
2081 /*
2082 ** CAPI3REF: Tracing And Profiling Functions
 
2083 **
2084 ** These routines register callback functions that can be used for
2085 ** tracing and profiling the execution of SQL statements.
2086 **
2087 ** ^The callback function registered by sqlite3_trace() is invoked at
@@ -2082,11 +2095,11 @@
2095 ** ^The callback function registered by sqlite3_profile() is invoked
2096 ** as each SQL statement finishes. ^The profile callback contains
2097 ** the original statement text and an estimate of wall-clock time
2098 ** of how long that statement took to run.
2099 */
2100 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
2101 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
2102 void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
2103
2104 /*
2105 ** CAPI3REF: Query Progress Callbacks
@@ -3687,11 +3700,11 @@
3700 sqlite3*,
3701 void*,
3702 void(*)(void*,sqlite3*,int eTextRep,const void*)
3703 );
3704
3705 #ifdef SQLITE_HAS_CODEC
3706 /*
3707 ** Specify the key for an encrypted database. This routine should be
3708 ** called right after sqlite3_open().
3709 **
3710 ** The code to implement this API is not available in the public release
@@ -4157,12 +4170,10 @@
4170 ** ^This function disables automatic extensions in all threads.
4171 */
4172 SQLITE_API void sqlite3_reset_auto_extension(void);
4173
4174 /*
 
 
4175 ** The interface to the virtual-table mechanism is currently considered
4176 ** to be experimental. The interface might change in incompatible ways.
4177 ** If this is a problem for you, do not use the interface at this time.
4178 **
4179 ** When the virtual-table mechanism stabilizes, we will declare the
@@ -4178,11 +4189,10 @@
4189 typedef struct sqlite3_module sqlite3_module;
4190
4191 /*
4192 ** CAPI3REF: Virtual Table Object
4193 ** KEYWORDS: sqlite3_module {virtual table module}
 
4194 **
4195 ** This structure, sometimes called a a "virtual table module",
4196 ** defines the implementation of a [virtual tables].
4197 ** This structure consists mostly of methods for the module.
4198 **
@@ -4225,11 +4235,10 @@
4235 };
4236
4237 /*
4238 ** CAPI3REF: Virtual Table Indexing Information
4239 ** KEYWORDS: sqlite3_index_info
 
4240 **
4241 ** The sqlite3_index_info structure and its substructures is used to
4242 ** pass information into and receive the reply from the [xBestIndex]
4243 ** method of a [virtual table module]. The fields under **Inputs** are the
4244 ** inputs to xBestIndex and are read-only. xBestIndex inserts its
@@ -4307,11 +4316,10 @@
4316 #define SQLITE_INDEX_CONSTRAINT_GE 32
4317 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
4318
4319 /*
4320 ** CAPI3REF: Register A Virtual Table Implementation
 
4321 **
4322 ** ^These routines are used to register a new [virtual table module] name.
4323 ** ^Module names must be registered before
4324 ** creating a new [virtual table] using the module and before using a
4325 ** preexisting [virtual table] for the module.
@@ -4329,17 +4337,17 @@
4337 ** invoke the destructor function (if it is not NULL) when SQLite
4338 ** no longer needs the pClientData pointer. ^The sqlite3_create_module()
4339 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
4340 ** destructor.
4341 */
4342 SQLITE_API int sqlite3_create_module(
4343 sqlite3 *db, /* SQLite connection to register module with */
4344 const char *zName, /* Name of the module */
4345 const sqlite3_module *p, /* Methods for the module */
4346 void *pClientData /* Client data for xCreate/xConnect */
4347 );
4348 SQLITE_API int sqlite3_create_module_v2(
4349 sqlite3 *db, /* SQLite connection to register module with */
4350 const char *zName, /* Name of the module */
4351 const sqlite3_module *p, /* Methods for the module */
4352 void *pClientData, /* Client data for xCreate/xConnect */
4353 void(*xDestroy)(void*) /* Module destructor function */
@@ -4346,11 +4354,10 @@
4354 );
4355
4356 /*
4357 ** CAPI3REF: Virtual Table Instance Object
4358 ** KEYWORDS: sqlite3_vtab
 
4359 **
4360 ** Every [virtual table module] implementation uses a subclass
4361 ** of this object to describe a particular instance
4362 ** of the [virtual table]. Each subclass will
4363 ** be tailored to the specific needs of the module implementation.
@@ -4372,11 +4379,10 @@
4379 };
4380
4381 /*
4382 ** CAPI3REF: Virtual Table Cursor Object
4383 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
 
4384 **
4385 ** Every [virtual table module] implementation uses a subclass of the
4386 ** following structure to describe cursors that point into the
4387 ** [virtual table] and are used
4388 ** to loop through the virtual table. Cursors are created using the
@@ -4394,22 +4400,20 @@
4400 /* Virtual table implementations will typically add additional fields */
4401 };
4402
4403 /*
4404 ** CAPI3REF: Declare The Schema Of A Virtual Table
 
4405 **
4406 ** ^The [xCreate] and [xConnect] methods of a
4407 ** [virtual table module] call this interface
4408 ** to declare the format (the names and datatypes of the columns) of
4409 ** the virtual tables they implement.
4410 */
4411 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
4412
4413 /*
4414 ** CAPI3REF: Overload A Function For A Virtual Table
 
4415 **
4416 ** ^(Virtual tables can provide alternative implementations of functions
4417 ** using the [xFindFunction] method of the [virtual table module].
4418 ** But global versions of those functions
4419 ** must exist in order to be overloaded.)^
@@ -4420,22 +4424,20 @@
4424 ** of the new function always causes an exception to be thrown. So
4425 ** the new function is not good for anything by itself. Its only
4426 ** purpose is to be a placeholder function that can be overloaded
4427 ** by a [virtual table].
4428 */
4429 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
4430
4431 /*
4432 ** The interface to the virtual-table mechanism defined above (back up
4433 ** to a comment remarkably similar to this one) is currently considered
4434 ** to be experimental. The interface might change in incompatible ways.
4435 ** If this is a problem for you, do not use the interface at this time.
4436 **
4437 ** When the virtual-table mechanism stabilizes, we will declare the
4438 ** interface fixed, support it indefinitely, and remove this comment.
 
 
4439 */
4440
4441 /*
4442 ** CAPI3REF: A Handle To An Open BLOB
4443 ** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -4774,11 +4776,10 @@
4776 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
4777 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
4778
4779 /*
4780 ** CAPI3REF: Mutex Methods Object
 
4781 **
4782 ** An instance of this structure defines the low-level routines
4783 ** used to allocate and use mutexes.
4784 **
4785 ** Usually, the default mutex implementations provided by SQLite are
@@ -4991,11 +4992,10 @@
4992 #define SQLITE_TESTCTRL_ISKEYWORD 16
4993 #define SQLITE_TESTCTRL_LAST 16
4994
4995 /*
4996 ** CAPI3REF: SQLite Runtime Status
 
4997 **
4998 ** ^This interface is used to retrieve runtime status information
4999 ** about the preformance of SQLite, and optionally to reset various
5000 ** highwater marks. ^The first argument is an integer code for
5001 ** the specific parameter to measure. ^(Recognized integer codes
@@ -5019,16 +5019,15 @@
5019 ** and it is possible that another thread might change the parameter
5020 ** in between the times when *pCurrent and *pHighwater are written.
5021 **
5022 ** See also: [sqlite3_db_status()]
5023 */
5024 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
5025
5026
5027 /*
5028 ** CAPI3REF: Status Parameters
 
5029 **
5030 ** These integer constants designate various run-time status parameters
5031 ** that can be returned by [sqlite3_status()].
5032 **
5033 ** <dl>
@@ -5111,31 +5110,31 @@
5110 #define SQLITE_STATUS_PAGECACHE_SIZE 7
5111 #define SQLITE_STATUS_SCRATCH_SIZE 8
5112
5113 /*
5114 ** CAPI3REF: Database Connection Status
 
5115 **
5116 ** ^This interface is used to retrieve runtime status information
5117 ** about a single [database connection]. ^The first argument is the
5118 ** database connection object to be interrogated. ^The second argument
5119 ** is an integer constant, taken from the set of
5120 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
5121 ** determiness the parameter to interrogate. The set of
5122 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
5123 ** to grow in future releases of SQLite.
5124 **
5125 ** ^The current value of the requested parameter is written into *pCur
5126 ** and the highest instantaneous value is written into *pHiwtr. ^If
5127 ** the resetFlg is true, then the highest instantaneous value is
5128 ** reset back down to the current value.
5129 **
5130 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
5131 */
5132 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
5133
5134 /*
5135 ** CAPI3REF: Status Parameters for database connections
 
5136 **
5137 ** These constants are the available integer "verbs" that can be passed as
5138 ** the second argument to the [sqlite3_db_status()] interface.
5139 **
5140 ** New verbs may be added in future releases of SQLite. Existing verbs
@@ -5146,18 +5145,25 @@
5145 **
5146 ** <dl>
5147 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
5148 ** <dd>This parameter returns the number of lookaside memory slots currently
5149 ** checked out.</dd>)^
5150 **
5151 ** <dt>SQLITE_DBSTATUS_CACHE_USED</dt>
5152 ** <dd>^This parameter returns the approximate number of of bytes of heap
5153 ** memory used by all pager caches associated with the database connection.
5154 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
5155 ** checked out.</dd>)^
5156 ** </dl>
5157 */
5158 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0
5159 #define SQLITE_DBSTATUS_CACHE_USED 1
5160 #define SQLITE_DBSTATUS_MAX 1 /* Largest defined DBSTATUS */
5161
5162
5163 /*
5164 ** CAPI3REF: Prepared Statement Status
 
5165 **
5166 ** ^(Each prepared statement maintains various
5167 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
5168 ** of times it has performed specific operations.)^ These counters can
5169 ** be used to monitor the performance characteristics of the prepared
@@ -5175,15 +5181,14 @@
5181 ** ^If the resetFlg is true, then the counter is reset to zero after this
5182 ** interface call returns.
5183 **
5184 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
5185 */
5186 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
5187
5188 /*
5189 ** CAPI3REF: Status Parameters for prepared statements
 
5190 **
5191 ** These preprocessor macros define integer codes that name counter
5192 ** values associated with the [sqlite3_stmt_status()] interface.
5193 ** The meanings of the various counters are as follows:
5194 **
@@ -5197,18 +5202,25 @@
5202 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
5203 ** <dd>^This is the number of sort operations that have occurred.
5204 ** A non-zero value in this counter may indicate an opportunity to
5205 ** improvement performance through careful use of indices.</dd>
5206 **
5207 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
5208 ** <dd>^This is the number of rows inserted into transient indices that
5209 ** were created automatically in order to help joins run faster.
5210 ** A non-zero value in this counter may indicate an opportunity to
5211 ** improvement performance by adding permanent indices that do not
5212 ** need to be reinitialized each time the statement is run.</dd>
5213 **
5214 ** </dl>
5215 */
5216 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
5217 #define SQLITE_STMTSTATUS_SORT 2
5218 #define SQLITE_STMTSTATUS_AUTOINDEX 3
5219
5220 /*
5221 ** CAPI3REF: Custom Page Cache Object
 
5222 **
5223 ** The sqlite3_pcache type is opaque. It is implemented by
5224 ** the pluggable module. The SQLite core has no knowledge of
5225 ** its size or internal structure and never deals with the
5226 ** sqlite3_pcache object except by holding and passing pointers
@@ -5219,11 +5231,10 @@
5231 typedef struct sqlite3_pcache sqlite3_pcache;
5232
5233 /*
5234 ** CAPI3REF: Application Defined Page Cache.
5235 ** KEYWORDS: {page cache}
 
5236 **
5237 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
5238 ** register an alternative page cache implementation by passing in an
5239 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the
5240 ** heap memory used by SQLite is used by the page cache to cache data read
@@ -5361,11 +5372,10 @@
5372 void (*xDestroy)(sqlite3_pcache*);
5373 };
5374
5375 /*
5376 ** CAPI3REF: Online Backup Object
 
5377 **
5378 ** The sqlite3_backup object records state information about an ongoing
5379 ** online backup operation. ^The sqlite3_backup object is created by
5380 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
5381 ** [sqlite3_backup_finish()].
@@ -5374,11 +5384,10 @@
5384 */
5385 typedef struct sqlite3_backup sqlite3_backup;
5386
5387 /*
5388 ** CAPI3REF: Online Backup API.
 
5389 **
5390 ** The backup API copies the content of one database into another.
5391 ** It is useful either for creating backups of databases or
5392 ** for copying in-memory databases to or from persistent files.
5393 **
@@ -5562,11 +5571,10 @@
5571 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
5572 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
5573
5574 /*
5575 ** CAPI3REF: Unlock Notification
 
5576 **
5577 ** ^When running in shared-cache mode, a database operation may fail with
5578 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
5579 ** individual tables within the shared-cache cannot be obtained. See
5580 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
@@ -5684,11 +5692,10 @@
5692 );
5693
5694
5695 /*
5696 ** CAPI3REF: String Comparison
 
5697 **
5698 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
5699 ** compare the contents of two buffers containing UTF-8 strings in a
5700 ** case-indendent fashion, using the same definition of case independence
5701 ** that SQLite uses internally when comparing identifiers.
@@ -5695,16 +5702,15 @@
5702 */
5703 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
5704
5705 /*
5706 ** CAPI3REF: Error Logging Interface
 
5707 **
5708 ** ^The [sqlite3_log()] interface writes a message into the error log
5709 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
5710 ** ^If logging is enabled, the zFormat string and subsequent arguments are
5711 ** used with [sqlite3_snprintf()] to generate the final output string.
5712 **
5713 ** The sqlite3_log() interface is intended for use by extensions such as
5714 ** virtual tables, collating functions, and SQL functions. While there is
5715 ** nothing to prevent an application from calling sqlite3_log(), doing so
5716 ** is considered bad form.
5717

Keyboard Shortcuts

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