Fossil SCM

merge trunk

jan.nijtmans 2014-10-14 21:43 winsymlink merge
Commit 2932f753cbe14a70bc7ead7d6d94a11cf84689ef
+1
--- auto.def
+++ auto.def
@@ -278,10 +278,11 @@
278278
}
279279
}
280280
cc-check-function-in-lib iconv iconv
281281
cc-check-functions utime
282282
cc-check-functions usleep
283
+cc-check-functions strchrnul
283284
284285
# Check for getloadavg(), and if it doesn't exist, define FOSSIL_OMIT_LOAD_AVERAGE
285286
if {![cc-check-functions getloadavg]} {
286287
define FOSSIL_OMIT_LOAD_AVERAGE 1
287288
msg-result "Load average support unavailable"
288289
--- auto.def
+++ auto.def
@@ -278,10 +278,11 @@
278 }
279 }
280 cc-check-function-in-lib iconv iconv
281 cc-check-functions utime
282 cc-check-functions usleep
 
283
284 # Check for getloadavg(), and if it doesn't exist, define FOSSIL_OMIT_LOAD_AVERAGE
285 if {![cc-check-functions getloadavg]} {
286 define FOSSIL_OMIT_LOAD_AVERAGE 1
287 msg-result "Load average support unavailable"
288
--- auto.def
+++ auto.def
@@ -278,10 +278,11 @@
278 }
279 }
280 cc-check-function-in-lib iconv iconv
281 cc-check-functions utime
282 cc-check-functions usleep
283 cc-check-functions strchrnul
284
285 # Check for getloadavg(), and if it doesn't exist, define FOSSIL_OMIT_LOAD_AVERAGE
286 if {![cc-check-functions getloadavg]} {
287 define FOSSIL_OMIT_LOAD_AVERAGE 1
288 msg-result "Load average support unavailable"
289
--- src/allrepo.c
+++ src/allrepo.c
@@ -98,10 +98,12 @@
9898
** carefully review the local checkouts to be operated upon
9999
** and the --whatif option to carefully review the files to
100100
** be deleted beforehand is highly recommended. The command
101101
** line options supported by the clean command itself, if any
102102
** are present, are passed along verbatim.
103
+**
104
+** dbstat Run the "dbstat" command on all repositories.
103105
**
104106
** extras Shows "extra" files from all local checkouts. The command
105107
** line options supported by the extra command itself, if any
106108
** are present, are passed along verbatim.
107109
**
@@ -190,10 +192,16 @@
190192
collect_argument_value(&extra, "keep");
191193
collect_argument(&extra, "temp",0);
192194
collect_argument(&extra, "verbose","v");
193195
collect_argument(&extra, "whatif",0);
194196
useCheckouts = 1;
197
+ }else if( strncmp(zCmd, "dbstat", n)==0 ){
198
+ zCmd = "dbstat --omit-version-info -R";
199
+ showLabel = 1;
200
+ quiet = 1;
201
+ collect_argument(&extra, "brief", "b");
202
+ collect_argument(&extra, "db-check", 0);
195203
}else if( strncmp(zCmd, "extras", n)==0 ){
196204
if( showFile ){
197205
zCmd = "extras --chdir";
198206
}else{
199207
zCmd = "extras --header --chdir";
200208
--- src/allrepo.c
+++ src/allrepo.c
@@ -98,10 +98,12 @@
98 ** carefully review the local checkouts to be operated upon
99 ** and the --whatif option to carefully review the files to
100 ** be deleted beforehand is highly recommended. The command
101 ** line options supported by the clean command itself, if any
102 ** are present, are passed along verbatim.
 
 
103 **
104 ** extras Shows "extra" files from all local checkouts. The command
105 ** line options supported by the extra command itself, if any
106 ** are present, are passed along verbatim.
107 **
@@ -190,10 +192,16 @@
190 collect_argument_value(&extra, "keep");
191 collect_argument(&extra, "temp",0);
192 collect_argument(&extra, "verbose","v");
193 collect_argument(&extra, "whatif",0);
194 useCheckouts = 1;
 
 
 
 
 
 
195 }else if( strncmp(zCmd, "extras", n)==0 ){
196 if( showFile ){
197 zCmd = "extras --chdir";
198 }else{
199 zCmd = "extras --header --chdir";
200
--- src/allrepo.c
+++ src/allrepo.c
@@ -98,10 +98,12 @@
98 ** carefully review the local checkouts to be operated upon
99 ** and the --whatif option to carefully review the files to
100 ** be deleted beforehand is highly recommended. The command
101 ** line options supported by the clean command itself, if any
102 ** are present, are passed along verbatim.
103 **
104 ** dbstat Run the "dbstat" command on all repositories.
105 **
106 ** extras Shows "extra" files from all local checkouts. The command
107 ** line options supported by the extra command itself, if any
108 ** are present, are passed along verbatim.
109 **
@@ -190,10 +192,16 @@
192 collect_argument_value(&extra, "keep");
193 collect_argument(&extra, "temp",0);
194 collect_argument(&extra, "verbose","v");
195 collect_argument(&extra, "whatif",0);
196 useCheckouts = 1;
197 }else if( strncmp(zCmd, "dbstat", n)==0 ){
198 zCmd = "dbstat --omit-version-info -R";
199 showLabel = 1;
200 quiet = 1;
201 collect_argument(&extra, "brief", "b");
202 collect_argument(&extra, "db-check", 0);
203 }else if( strncmp(zCmd, "extras", n)==0 ){
204 if( showFile ){
205 zCmd = "extras --chdir";
206 }else{
207 zCmd = "extras --header --chdir";
208
+1 -1
--- src/browse.c
+++ src/browse.c
@@ -759,11 +759,11 @@
759759
db_prepare(&ins,
760760
"INSERT INTO temp.fileage(fid, pathname)"
761761
" SELECT rid, :path FROM blob WHERE uuid=:uuid"
762762
);
763763
while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764
- if(zGlob && !strglob(zGlob, pFile->zName)) continue;
764
+ if( zGlob && sqlite3_strglob(zGlob, pFile->zName)!=0 ) continue;
765765
db_bind_text(&ins, ":uuid", pFile->zUuid);
766766
db_bind_text(&ins, ":path", pFile->zName);
767767
db_step(&ins);
768768
db_reset(&ins);
769769
nFile++;
770770
--- src/browse.c
+++ src/browse.c
@@ -759,11 +759,11 @@
759 db_prepare(&ins,
760 "INSERT INTO temp.fileage(fid, pathname)"
761 " SELECT rid, :path FROM blob WHERE uuid=:uuid"
762 );
763 while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764 if(zGlob && !strglob(zGlob, pFile->zName)) continue;
765 db_bind_text(&ins, ":uuid", pFile->zUuid);
766 db_bind_text(&ins, ":path", pFile->zName);
767 db_step(&ins);
768 db_reset(&ins);
769 nFile++;
770
--- src/browse.c
+++ src/browse.c
@@ -759,11 +759,11 @@
759 db_prepare(&ins,
760 "INSERT INTO temp.fileage(fid, pathname)"
761 " SELECT rid, :path FROM blob WHERE uuid=:uuid"
762 );
763 while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764 if( zGlob && sqlite3_strglob(zGlob, pFile->zName)!=0 ) continue;
765 db_bind_text(&ins, ":uuid", pFile->zUuid);
766 db_bind_text(&ins, ":path", pFile->zName);
767 db_step(&ins);
768 db_reset(&ins);
769 nFile++;
770
+2 -2
--- src/cgi.c
+++ src/cgi.c
@@ -277,12 +277,12 @@
277277
** Return true if the response should be sent with Content-Encoding: gzip.
278278
*/
279279
static int is_gzippable(void){
280280
if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
281281
return strncmp(zContentType, "text/", 5)==0
282
- || strglob("application/*xml", zContentType)
283
- || strglob("application/*javascript", zContentType);
282
+ || sqlite3_strglob("application/*xml", zContentType)==0
283
+ || sqlite3_strglob("application/*javascript", zContentType)==0;
284284
}
285285
286286
/*
287287
** Do a normal HTTP reply
288288
*/
289289
--- src/cgi.c
+++ src/cgi.c
@@ -277,12 +277,12 @@
277 ** Return true if the response should be sent with Content-Encoding: gzip.
278 */
279 static int is_gzippable(void){
280 if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
281 return strncmp(zContentType, "text/", 5)==0
282 || strglob("application/*xml", zContentType)
283 || strglob("application/*javascript", zContentType);
284 }
285
286 /*
287 ** Do a normal HTTP reply
288 */
289
--- src/cgi.c
+++ src/cgi.c
@@ -277,12 +277,12 @@
277 ** Return true if the response should be sent with Content-Encoding: gzip.
278 */
279 static int is_gzippable(void){
280 if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
281 return strncmp(zContentType, "text/", 5)==0
282 || sqlite3_strglob("application/*xml", zContentType)==0
283 || sqlite3_strglob("application/*javascript", zContentType)==0;
284 }
285
286 /*
287 ** Do a normal HTTP reply
288 */
289
+3 -3
--- src/db.c
+++ src/db.c
@@ -892,11 +892,11 @@
892892
" WHERE name=='%s' /*scan*/",
893893
db_name("localdb"), zTable);
894894
int rc = 0;
895895
if( zDef ){
896896
char *zPattern = mprintf("* %s *", zColumn);
897
- rc = strglob(zPattern, zDef)==0;
897
+ rc = sqlite3_strglob(zPattern, zDef)!=0;
898898
fossil_free(zPattern);
899899
fossil_free(zDef);
900900
}
901901
return rc;
902902
}
@@ -919,19 +919,19 @@
919919
920920
/* If the "isexe" column is missing from the vfile table, then
921921
** add it now. This code added on 2010-03-06. After all users have
922922
** upgraded, this code can be safely deleted.
923923
*/
924
- if( !strglob("* isexe *", zVFileDef) ){
924
+ if( sqlite3_strglob("* isexe *", zVFileDef)!=0 ){
925925
db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
926926
}
927927
928928
/* If "islink"/"isLink" columns are missing from tables, then
929929
** add them now. This code added on 2011-01-17 and 2011-08-27.
930930
** After all users have upgraded, this code can be safely deleted.
931931
*/
932
- if( !strglob("* islink *", zVFileDef) ){
932
+ if( sqlite3_strglob("* islink *", zVFileDef)!=0 ){
933933
db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
934934
if( db_local_table_exists_but_lacks_column("stashfile", "isLink") ){
935935
db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOL DEFAULT 0");
936936
}
937937
if( db_local_table_exists_but_lacks_column("undo", "isLink") ){
938938
--- src/db.c
+++ src/db.c
@@ -892,11 +892,11 @@
892 " WHERE name=='%s' /*scan*/",
893 db_name("localdb"), zTable);
894 int rc = 0;
895 if( zDef ){
896 char *zPattern = mprintf("* %s *", zColumn);
897 rc = strglob(zPattern, zDef)==0;
898 fossil_free(zPattern);
899 fossil_free(zDef);
900 }
901 return rc;
902 }
@@ -919,19 +919,19 @@
919
920 /* If the "isexe" column is missing from the vfile table, then
921 ** add it now. This code added on 2010-03-06. After all users have
922 ** upgraded, this code can be safely deleted.
923 */
924 if( !strglob("* isexe *", zVFileDef) ){
925 db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
926 }
927
928 /* If "islink"/"isLink" columns are missing from tables, then
929 ** add them now. This code added on 2011-01-17 and 2011-08-27.
930 ** After all users have upgraded, this code can be safely deleted.
931 */
932 if( !strglob("* islink *", zVFileDef) ){
933 db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
934 if( db_local_table_exists_but_lacks_column("stashfile", "isLink") ){
935 db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOL DEFAULT 0");
936 }
937 if( db_local_table_exists_but_lacks_column("undo", "isLink") ){
938
--- src/db.c
+++ src/db.c
@@ -892,11 +892,11 @@
892 " WHERE name=='%s' /*scan*/",
893 db_name("localdb"), zTable);
894 int rc = 0;
895 if( zDef ){
896 char *zPattern = mprintf("* %s *", zColumn);
897 rc = sqlite3_strglob(zPattern, zDef)!=0;
898 fossil_free(zPattern);
899 fossil_free(zDef);
900 }
901 return rc;
902 }
@@ -919,19 +919,19 @@
919
920 /* If the "isexe" column is missing from the vfile table, then
921 ** add it now. This code added on 2010-03-06. After all users have
922 ** upgraded, this code can be safely deleted.
923 */
924 if( sqlite3_strglob("* isexe *", zVFileDef)!=0 ){
925 db_multi_exec("ALTER TABLE vfile ADD COLUMN isexe BOOLEAN DEFAULT 0");
926 }
927
928 /* If "islink"/"isLink" columns are missing from tables, then
929 ** add them now. This code added on 2011-01-17 and 2011-08-27.
930 ** After all users have upgraded, this code can be safely deleted.
931 */
932 if( sqlite3_strglob("* islink *", zVFileDef)!=0 ){
933 db_multi_exec("ALTER TABLE vfile ADD COLUMN islink BOOLEAN DEFAULT 0");
934 if( db_local_table_exists_but_lacks_column("stashfile", "isLink") ){
935 db_multi_exec("ALTER TABLE stashfile ADD COLUMN isLink BOOL DEFAULT 0");
936 }
937 if( db_local_table_exists_but_lacks_column("undo", "isLink") ){
938
+5 -5
--- src/login.c
+++ src/login.c
@@ -395,15 +395,15 @@
395395
/* If a URI appears in the User-Agent, it is probably a bot */
396396
if( strncmp("http", zAgent+i,4)==0 ) return 0;
397397
}
398398
if( strncmp(zAgent, "Mozilla/", 8)==0 ){
399399
if( atoi(&zAgent[8])<4 ) return 0; /* Many bots advertise as Mozilla/3 */
400
- if( strglob("*Firefox/[1-9]*", zAgent) ) return 1;
401
- if( strglob("*Chrome/[1-9]*", zAgent) ) return 1;
402
- if( strglob("*(compatible;?MSIE?[1789]*", zAgent) ) return 1;
403
- if( strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent) ) return 1; /* IE11+ */
404
- if( strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent) ) return 1;
400
+ if( sqlite3_strglob("*Firefox/[1-9]*", zAgent)==0 ) return 1;
401
+ if( sqlite3_strglob("*Chrome/[1-9]*", zAgent)==0 ) return 1;
402
+ if( sqlite3_strglob("*(compatible;?MSIE?[1789]*", zAgent)==0 ) return 1;
403
+ if( sqlite3_strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent)==0 ) return 1; /* IE11+ */
404
+ if( sqlite3_strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent)==0 ) return 1;
405405
return 0;
406406
}
407407
if( strncmp(zAgent, "Opera/", 6)==0 ) return 1;
408408
if( strncmp(zAgent, "Safari/", 7)==0 ) return 1;
409409
if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1;
410410
--- src/login.c
+++ src/login.c
@@ -395,15 +395,15 @@
395 /* If a URI appears in the User-Agent, it is probably a bot */
396 if( strncmp("http", zAgent+i,4)==0 ) return 0;
397 }
398 if( strncmp(zAgent, "Mozilla/", 8)==0 ){
399 if( atoi(&zAgent[8])<4 ) return 0; /* Many bots advertise as Mozilla/3 */
400 if( strglob("*Firefox/[1-9]*", zAgent) ) return 1;
401 if( strglob("*Chrome/[1-9]*", zAgent) ) return 1;
402 if( strglob("*(compatible;?MSIE?[1789]*", zAgent) ) return 1;
403 if( strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent) ) return 1; /* IE11+ */
404 if( strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent) ) return 1;
405 return 0;
406 }
407 if( strncmp(zAgent, "Opera/", 6)==0 ) return 1;
408 if( strncmp(zAgent, "Safari/", 7)==0 ) return 1;
409 if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1;
410
--- src/login.c
+++ src/login.c
@@ -395,15 +395,15 @@
395 /* If a URI appears in the User-Agent, it is probably a bot */
396 if( strncmp("http", zAgent+i,4)==0 ) return 0;
397 }
398 if( strncmp(zAgent, "Mozilla/", 8)==0 ){
399 if( atoi(&zAgent[8])<4 ) return 0; /* Many bots advertise as Mozilla/3 */
400 if( sqlite3_strglob("*Firefox/[1-9]*", zAgent)==0 ) return 1;
401 if( sqlite3_strglob("*Chrome/[1-9]*", zAgent)==0 ) return 1;
402 if( sqlite3_strglob("*(compatible;?MSIE?[1789]*", zAgent)==0 ) return 1;
403 if( sqlite3_strglob("*Trident/[1-9]*;?rv:[1-9]*", zAgent)==0 ) return 1; /* IE11+ */
404 if( sqlite3_strglob("*AppleWebKit/[1-9]*(KHTML*", zAgent)==0 ) return 1;
405 return 0;
406 }
407 if( strncmp(zAgent, "Opera/", 6)==0 ) return 1;
408 if( strncmp(zAgent, "Safari/", 7)==0 ) return 1;
409 if( strncmp(zAgent, "Lynx/", 5)==0 ) return 1;
410
--- src/shell.c
+++ src/shell.c
@@ -3723,10 +3723,11 @@
37233723
}
37243724
}
37253725
if( nSql ){
37263726
if( !_all_whitespace(zSql) ){
37273727
fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
3728
+ errCnt++;
37283729
}
37293730
free(zSql);
37303731
}
37313732
free(zLine);
37323733
return errCnt>0;
37333734
--- src/shell.c
+++ src/shell.c
@@ -3723,10 +3723,11 @@
3723 }
3724 }
3725 if( nSql ){
3726 if( !_all_whitespace(zSql) ){
3727 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
 
3728 }
3729 free(zSql);
3730 }
3731 free(zLine);
3732 return errCnt>0;
3733
--- src/shell.c
+++ src/shell.c
@@ -3723,10 +3723,11 @@
3723 }
3724 }
3725 if( nSql ){
3726 if( !_all_whitespace(zSql) ){
3727 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
3728 errCnt++;
3729 }
3730 free(zSql);
3731 }
3732 free(zLine);
3733 return errCnt>0;
3734
+272 -210
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232232
** [sqlite_version()] and [sqlite_source_id()].
233233
*/
234234
#define SQLITE_VERSION "3.8.7"
235235
#define SQLITE_VERSION_NUMBER 3008007
236
-#define SQLITE_SOURCE_ID "2014-10-04 19:31:53 b8f7f19dc06c59de2e194d83e6c052fb7d28c71d"
236
+#define SQLITE_SOURCE_ID "2014-10-14 20:25:43 eab82330631187dcc3e5d2dddd23dbda5752904b"
237237
238238
/*
239239
** CAPI3REF: Run-Time Library Version Numbers
240240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241241
**
@@ -7944,11 +7944,11 @@
79447944
** A macro to hint to the compiler that a function should not be
79457945
** inlined.
79467946
*/
79477947
#if defined(__GNUC__)
79487948
# define SQLITE_NOINLINE __attribute__((noinline))
7949
-#elif defined(_MSC_VER)
7949
+#elif defined(_MSC_VER) && _MSC_VER>=1310
79507950
# define SQLITE_NOINLINE __declspec(noinline)
79517951
#else
79527952
# define SQLITE_NOINLINE
79537953
#endif
79547954
@@ -11322,10 +11322,11 @@
1132211322
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
1132311323
int nSample; /* Number of elements in aSample[] */
1132411324
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
1132511325
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1132611326
IndexSample *aSample; /* Samples of the left-most key */
11327
+ tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
1132711328
#endif
1132811329
};
1132911330
1133011331
/*
1133111332
** Allowed values for Index.idxType
@@ -12186,11 +12187,10 @@
1218612187
#define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
1218712188
#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
1218812189
#define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
1218912190
#define OPFLAG_APPEND 0x08 /* This is likely to be an append */
1219012191
#define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
12191
-#define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
1219212192
#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
1219312193
#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
1219412194
#define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
1219512195
#define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
1219612196
#define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
@@ -13320,14 +13320,13 @@
1332013320
# define sqlite3MemdebugSetType(X,Y) /* no-op */
1332113321
# define sqlite3MemdebugHasType(X,Y) 1
1332213322
# define sqlite3MemdebugNoType(X,Y) 1
1332313323
#endif
1332413324
#define MEMTYPE_HEAP 0x01 /* General heap allocations */
13325
-#define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
13325
+#define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
1332613326
#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
1332713327
#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
13328
-#define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
1332913328
1333013329
/*
1333113330
** Threading interface
1333213331
*/
1333313332
#if SQLITE_MAX_WORKER_THREADS>0
@@ -14095,21 +14094,19 @@
1409514094
#ifdef SQLITE_DEBUG
1409614095
u8 seekOp; /* Most recent seek operation on this cursor */
1409714096
#endif
1409814097
i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
1409914098
u8 nullRow; /* True if pointing to a row with no data */
14100
- u8 rowidIsValid; /* True if lastRowid is valid */
1410114099
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1410214100
Bool isEphemeral:1; /* True for an ephemeral table */
1410314101
Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
1410414102
Bool isTable:1; /* True if a table requiring integer keys */
1410514103
Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
1410614104
Pgno pgnoRoot; /* Root page of the open btree cursor */
1410714105
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1410814106
i64 seqCount; /* Sequence counter */
1410914107
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
14110
- i64 lastRowid; /* Rowid being deleted by OP_Delete */
1411114108
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
1411214109
1411314110
/* Cached information about the header for the data record that the
1411414111
** cursor is currently pointing to. Only valid if cacheStatus matches
1411514112
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -14122,10 +14119,11 @@
1412214119
u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
1412314120
u32 payloadSize; /* Total number of bytes in the record */
1412414121
u32 szRow; /* Byte available in aRow */
1412514122
u32 iHdrOffset; /* Offset to next unparsed byte of the header */
1412614123
const u8 *aRow; /* Data for the current row, if all on one page */
14124
+ u32 *aOffset; /* Pointer to aType[nField] */
1412714125
u32 aType[1]; /* Type values for all entries in the record */
1412814126
/* 2*nField extra array elements allocated for aType[], beyond the one
1412914127
** static element declared in the structure. nField total array slots for
1413014128
** aType[] and nField+1 array slots for aOffset[] */
1413114129
};
@@ -14198,11 +14196,11 @@
1419814196
int n; /* Number of characters in string value, excluding '\0' */
1419914197
char *z; /* String or BLOB value */
1420014198
/* ShallowCopy only needs to copy the information above */
1420114199
char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
1420214200
int szMalloc; /* Size of the zMalloc allocation */
14203
- int iPadding1; /* Padding for 8-byte alignment */
14201
+ u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
1420414202
sqlite3 *db; /* The associated database connection */
1420514203
void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
1420614204
#ifdef SQLITE_DEBUG
1420714205
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
1420814206
void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
@@ -14406,10 +14404,11 @@
1440614404
** Function prototypes
1440714405
*/
1440814406
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
1440914407
void sqliteVdbePopStack(Vdbe*,int);
1441014408
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
14409
+SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
1441114410
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
1441214411
SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
1441314412
#endif
1441414413
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
1441514414
SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
@@ -17130,11 +17129,11 @@
1713017129
** allocation p. Also return true if p==NULL.
1713117130
**
1713217131
** This routine is designed for use within an assert() statement, to
1713317132
** verify the type of an allocation. For example:
1713417133
**
17135
-** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17134
+** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1713617135
*/
1713717136
SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
1713817137
int rc = 1;
1713917138
if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
1714017139
struct MemBlockHdr *pHdr;
@@ -17152,11 +17151,11 @@
1715217151
** allocation p. Also return true if p==NULL.
1715317152
**
1715417153
** This routine is designed for use within an assert() statement, to
1715517154
** verify the type of an allocation. For example:
1715617155
**
17157
-** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17156
+** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
1715817157
*/
1715917158
SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
1716017159
int rc = 1;
1716117160
if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
1716217161
struct MemBlockHdr *pHdr;
@@ -20364,39 +20363,41 @@
2036420363
** Return the size of a memory allocation previously obtained from
2036520364
** sqlite3Malloc() or sqlite3_malloc().
2036620365
*/
2036720366
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
2036820367
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20369
- assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
2037020368
return sqlite3GlobalConfig.m.xSize(p);
2037120369
}
2037220370
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
2037320371
if( db==0 ){
20372
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20373
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2037420374
return sqlite3MallocSize(p);
2037520375
}else{
2037620376
assert( sqlite3_mutex_held(db->mutex) );
2037720377
if( isLookaside(db, p) ){
2037820378
return db->lookaside.sz;
2037920379
}else{
20380
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20381
- assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20382
- assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20380
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20381
+ assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2038320382
return sqlite3GlobalConfig.m.xSize(p);
2038420383
}
2038520384
}
2038620385
}
2038720386
SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20387
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20388
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2038820389
return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
2038920390
}
2039020391
2039120392
/*
2039220393
** Free memory previously obtained from sqlite3Malloc().
2039320394
*/
2039420395
SQLITE_API void sqlite3_free(void *p){
2039520396
if( p==0 ) return; /* IMP: R-49053-54554 */
20396
- assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
2039720397
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20398
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
2039820399
if( sqlite3GlobalConfig.bMemstat ){
2039920400
sqlite3_mutex_enter(mem0.mutex);
2040020401
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
2040120402
sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
2040220403
sqlite3GlobalConfig.m.xFree(p);
@@ -20436,12 +20437,12 @@
2043620437
db->lookaside.pFree = pBuf;
2043720438
db->lookaside.nOut--;
2043820439
return;
2043920440
}
2044020441
}
20441
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20442
- assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20442
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20443
+ assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2044320444
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2044420445
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2044520446
sqlite3_free(p);
2044620447
}
2044720448
@@ -20449,10 +20450,12 @@
2044920450
** Change the size of an existing memory allocation
2045020451
*/
2045120452
SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
2045220453
int nOld, nNew, nDiff;
2045320454
void *pNew;
20455
+ assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20456
+ assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
2045420457
if( pOld==0 ){
2045520458
return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
2045620459
}
2045720460
if( nBytes==0 ){
2045820461
sqlite3_free(pOld); /* IMP: R-26507-47431 */
@@ -20475,12 +20478,10 @@
2047520478
nDiff = nNew - nOld;
2047620479
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
2047720480
mem0.alarmThreshold-nDiff ){
2047820481
sqlite3MallocAlarm(nDiff);
2047920482
}
20480
- assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20481
- assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
2048220483
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2048320484
if( pNew==0 && mem0.alarmCallback ){
2048420485
sqlite3MallocAlarm((int)nBytes);
2048520486
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2048620487
}
@@ -20589,12 +20590,12 @@
2058920590
#endif
2059020591
p = sqlite3Malloc(n);
2059120592
if( !p && db ){
2059220593
db->mallocFailed = 1;
2059320594
}
20594
- sqlite3MemdebugSetType(p, MEMTYPE_DB |
20595
- ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20595
+ sqlite3MemdebugSetType(p,
20596
+ (db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
2059620597
return p;
2059720598
}
2059820599
2059920600
/*
2060020601
** Resize the block of memory pointed to by p to n bytes. If the
@@ -20616,19 +20617,18 @@
2061620617
if( pNew ){
2061720618
memcpy(pNew, p, db->lookaside.sz);
2061820619
sqlite3DbFree(db, p);
2061920620
}
2062020621
}else{
20621
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20622
- assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20622
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20623
+ assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2062320624
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2062420625
pNew = sqlite3_realloc64(p, n);
2062520626
if( !pNew ){
20626
- sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
2062720627
db->mallocFailed = 1;
2062820628
}
20629
- sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
20629
+ sqlite3MemdebugSetType(pNew,
2063020630
(db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
2063120631
}
2063220632
}
2063320633
return pNew;
2063420634
}
@@ -22098,11 +22098,11 @@
2209822098
#define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
2209922099
#include <process.h>
2210022100
2210122101
/* A running thread */
2210222102
struct SQLiteThread {
22103
- uintptr_t tid; /* The thread handle */
22103
+ void *tid; /* The thread handle */
2210422104
unsigned id; /* The thread identifier */
2210522105
void *(*xTask)(void*); /* The routine to run as a thread */
2210622106
void *pIn; /* Argument to xTask */
2210722107
void *pResult; /* Result of xTask */
2210822108
};
@@ -22146,11 +22146,11 @@
2214622146
if( sqlite3GlobalConfig.bCoreMutex==0 ){
2214722147
memset(p, 0, sizeof(*p));
2214822148
}else{
2214922149
p->xTask = xTask;
2215022150
p->pIn = pIn;
22151
- p->tid = _beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
22151
+ p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
2215222152
if( p->tid==0 ){
2215322153
memset(p, 0, sizeof(*p));
2215422154
}
2215522155
}
2215622156
if( p->xTask==0 ){
@@ -39855,11 +39855,11 @@
3985539855
assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
3985639856
assert( pCache->n90pct == pCache->nMax*9/10 );
3985739857
if( createFlag==1 && (
3985839858
nPinned>=pGroup->mxPinned
3985939859
|| nPinned>=pCache->n90pct
39860
- || pcache1UnderMemoryPressure(pCache)
39860
+ || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
3986139861
)){
3986239862
return 0;
3986339863
}
3986439864
3986539865
if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
@@ -44476,17 +44476,19 @@
4447644476
if( !pNew ) rc = SQLITE_NOMEM;
4447744477
}
4447844478
4447944479
if( rc==SQLITE_OK ){
4448044480
pager_reset(pPager);
44481
- sqlite3PageFree(pPager->pTmpSpace);
44482
- pPager->pTmpSpace = pNew;
4448344481
rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
4448444482
}
4448544483
if( rc==SQLITE_OK ){
44484
+ sqlite3PageFree(pPager->pTmpSpace);
44485
+ pPager->pTmpSpace = pNew;
4448644486
pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
4448744487
pPager->pageSize = pageSize;
44488
+ }else{
44489
+ sqlite3PageFree(pNew);
4448844490
}
4448944491
}
4449044492
4449144493
*pPageSize = pPager->pageSize;
4449244494
if( rc==SQLITE_OK ){
@@ -52947,11 +52949,11 @@
5294752949
**
5294852950
** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
5294952951
** back to where it ought to be if this routine returns true.
5295052952
*/
5295152953
SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
52952
- return pCur && pCur->eState!=CURSOR_VALID;
52954
+ return pCur->eState!=CURSOR_VALID;
5295352955
}
5295452956
5295552957
/*
5295652958
** This routine restores a cursor back to its original position after it
5295752959
** has been moved by some outside activity (such as a btree rebalance or
@@ -58016,15 +58018,10 @@
5801658018
** pTemp is not null. Regardless of pTemp, allocate a new entry
5801758019
** in pPage->apOvfl[] and make it point to the cell content (either
5801858020
** in pTemp or the original pCell) and also record its index.
5801958021
** Allocating a new entry in pPage->aCell[] implies that
5802058022
** pPage->nOverflow is incremented.
58021
-**
58022
-** If nSkip is non-zero, then do not copy the first nSkip bytes of the
58023
-** cell. The caller will overwrite them after this function returns. If
58024
-** nSkip is non-zero, then pCell may not point to an invalid memory location
58025
-** (but pCell+nSkip is always valid).
5802658023
*/
5802758024
static void insertCell(
5802858025
MemPage *pPage, /* Page into which we are copying */
5802958026
int i, /* New cell becomes the i-th cell of the page */
5803058027
u8 *pCell, /* Content of the new cell */
@@ -58037,11 +58034,10 @@
5803758034
int j; /* Loop counter */
5803858035
int end; /* First byte past the last cell pointer in data[] */
5803958036
int ins; /* Index in data[] where new cell pointer is inserted */
5804058037
int cellOffset; /* Address of first cell pointer in data[] */
5804158038
u8 *data; /* The content of the whole page */
58042
- int nSkip = (iChild ? 4 : 0);
5804358039
5804458040
if( *pRC ) return;
5804558041
5804658042
assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
5804758043
assert( MX_CELL(pPage->pBt)<=10921 );
@@ -58055,11 +58051,11 @@
5805558051
** might be less than 8 (leaf-size + pointer) on the interior node. Hence
5805658052
** the term after the || in the following assert(). */
5805758053
assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
5805858054
if( pPage->nOverflow || sz+2>pPage->nFree ){
5805958055
if( pTemp ){
58060
- memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
58056
+ memcpy(pTemp, pCell, sz);
5806158057
pCell = pTemp;
5806258058
}
5806358059
if( iChild ){
5806458060
put4byte(pCell, iChild);
5806558061
}
@@ -58084,11 +58080,11 @@
5808458080
** if it returns success */
5808558081
assert( idx >= end+2 );
5808658082
assert( idx+sz <= (int)pPage->pBt->usableSize );
5808758083
pPage->nCell++;
5808858084
pPage->nFree -= (u16)(2 + sz);
58089
- memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
58085
+ memcpy(&data[idx], pCell, sz);
5809058086
if( iChild ){
5809158087
put4byte(&data[idx], iChild);
5809258088
}
5809358089
memmove(&data[ins+2], &data[ins], end-ins);
5809458090
put2byte(&data[ins], idx);
@@ -61630,11 +61626,14 @@
6163061626
/* If MEM_Dyn is set then Mem.xDel!=0.
6163161627
** Mem.xDel is might not be initialized if MEM_Dyn is clear.
6163261628
*/
6163361629
assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
6163461630
61635
- /* MEM_Dyn may only be set if Mem.szMalloc==0 */
61631
+ /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
61632
+ ** ensure that if Mem.szMalloc>0 then it is safe to do
61633
+ ** Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn.
61634
+ ** That saves a few cycles in inner loops. */
6163661635
assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
6163761636
6163861637
/* Cannot be both MEM_Int and MEM_Real at the same time */
6163961638
assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
6164061639
@@ -61766,11 +61765,12 @@
6176661765
**
6176761766
** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
6176861767
** if unable to complete the resizing.
6176961768
*/
6177061769
SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61771
- assert( szNew>=0 );
61770
+ assert( szNew>0 );
61771
+ assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
6177261772
if( pMem->szMalloc<szNew ){
6177361773
return sqlite3VdbeMemGrow(pMem, szNew, 0);
6177461774
}
6177561775
assert( (pMem->flags & MEM_Dyn)==0 );
6177661776
pMem->z = pMem->zMalloc;
@@ -62490,11 +62490,14 @@
6249062490
nAlloc += (enc==SQLITE_UTF8?1:2);
6249162491
}
6249262492
if( nByte>iLimit ){
6249362493
return SQLITE_TOOBIG;
6249462494
}
62495
- if( sqlite3VdbeMemClearAndResize(pMem, nAlloc) ){
62495
+ testcase( nAlloc==0 );
62496
+ testcase( nAlloc==31 );
62497
+ testcase( nAlloc==32 );
62498
+ if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
6249662499
return SQLITE_NOMEM;
6249762500
}
6249862501
memcpy(pMem->z, z, nAlloc);
6249962502
}else if( xDel==SQLITE_DYNAMIC ){
6250062503
sqlite3VdbeMemRelease(pMem);
@@ -62593,11 +62596,11 @@
6259362596
/*
6259462597
** The pVal argument is known to be a value other than NULL.
6259562598
** Convert it into a string with encoding enc and return a pointer
6259662599
** to a zero-terminated version of that string.
6259762600
*/
62598
-SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
62601
+static SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
6259962602
assert( pVal!=0 );
6260062603
assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
6260162604
assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
6260262605
assert( (pVal->flags & MEM_RowSet)==0 );
6260362606
assert( (pVal->flags & (MEM_Null))==0 );
@@ -64913,11 +64916,11 @@
6491364916
** the call above. */
6491464917
}else if( pCx->pCursor ){
6491564918
sqlite3BtreeCloseCursor(pCx->pCursor);
6491664919
}
6491764920
#ifndef SQLITE_OMIT_VIRTUALTABLE
64918
- if( pCx->pVtabCursor ){
64921
+ else if( pCx->pVtabCursor ){
6491964922
sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
6492064923
const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
6492164924
p->inVtabMethod = 1;
6492264925
pModule->xClose(pVtabCursor);
6492364926
p->inVtabMethod = 0;
@@ -64956,13 +64959,14 @@
6495664959
static void closeAllCursors(Vdbe *p){
6495764960
if( p->pFrame ){
6495864961
VdbeFrame *pFrame;
6495964962
for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
6496064963
sqlite3VdbeFrameRestore(pFrame);
64964
+ p->pFrame = 0;
64965
+ p->nFrame = 0;
6496164966
}
64962
- p->pFrame = 0;
64963
- p->nFrame = 0;
64967
+ assert( p->nFrame==0 );
6496464968
6496564969
if( p->apCsr ){
6496664970
int i;
6496764971
for(i=0; i<p->nCursor; i++){
6496864972
VdbeCursor *pC = p->apCsr[i];
@@ -64980,11 +64984,11 @@
6498064984
p->pDelFrame = pDel->pParent;
6498164985
sqlite3VdbeFrameDelete(pDel);
6498264986
}
6498364987
6498464988
/* Delete any auxdata allocations made by the VM */
64985
- sqlite3VdbeDeleteAuxData(p, -1, 0);
64989
+ if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p, -1, 0);
6498664990
assert( p->pAuxData==0 );
6498764991
}
6498864992
6498964993
/*
6499064994
** Clean up the VM after a single run.
@@ -65886,13 +65890,11 @@
6588665890
#endif
6588765891
assert( p->deferredMoveto );
6588865892
assert( p->isTable );
6588965893
rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
6589065894
if( rc ) return rc;
65891
- p->lastRowid = p->movetoTarget;
6589265895
if( res!=0 ) return SQLITE_CORRUPT_BKPT;
65893
- p->rowidIsValid = 1;
6589465896
#ifdef SQLITE_TEST
6589565897
sqlite3_search_count++;
6589665898
#endif
6589765899
p->deferredMoveto = 0;
6589865900
p->cacheStatus = CACHE_STALE;
@@ -65913,10 +65915,21 @@
6591365915
rc = sqlite3BtreeCursorRestore(p->pCursor, &isDifferentRow);
6591465916
p->cacheStatus = CACHE_STALE;
6591565917
if( isDifferentRow ) p->nullRow = 1;
6591665918
return rc;
6591765919
}
65920
+
65921
+/*
65922
+** Check to ensure that the cursor is valid. Restore the cursor
65923
+** if need be. Return any I/O error from the restore operation.
65924
+*/
65925
+SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){
65926
+ if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65927
+ return handleMovedCursor(p);
65928
+ }
65929
+ return SQLITE_OK;
65930
+}
6591865931
6591965932
/*
6592065933
** Make sure the cursor p is ready to read or write the row to which it
6592165934
** was last positioned. Return an error code if an OOM fault or I/O error
6592265935
** prevents us from positioning the cursor to its correct position.
@@ -65931,11 +65944,11 @@
6593165944
*/
6593265945
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor *p){
6593365946
if( p->deferredMoveto ){
6593465947
return handleDeferredMoveto(p);
6593565948
}
65936
- if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65949
+ if( p->pCursor && sqlite3BtreeCursorHasMoved(p->pCursor) ){
6593765950
return handleMovedCursor(p);
6593865951
}
6593965952
return SQLITE_OK;
6594065953
}
6594165954
@@ -69095,10 +69108,11 @@
6909569108
if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
6909669109
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
6909769110
memset(pCx, 0, sizeof(VdbeCursor));
6909869111
pCx->iDb = iDb;
6909969112
pCx->nField = nField;
69113
+ pCx->aOffset = &pCx->aType[nField];
6910069114
if( isBtreeCursor ){
6910169115
pCx->pCursor = (BtCursor*)
6910269116
&pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
6910369117
sqlite3BtreeCursorZero(pCx->pCursor);
6910469118
}
@@ -70528,11 +70542,11 @@
7052870542
ctx.pFunc = pOp->p4.pFunc;
7052970543
ctx.iOp = pc;
7053070544
ctx.pVdbe = p;
7053170545
MemSetTypeFlag(ctx.pOut, MEM_Null);
7053270546
ctx.fErrorOrAux = 0;
70533
- assert( db->lastRowid==lastRowid );
70547
+ db->lastRowid = lastRowid;
7053470548
(*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
7053570549
lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */
7053670550
7053770551
/* If the function returned an error, throw an exception */
7053870552
if( ctx.fErrorOrAux ){
@@ -71246,11 +71260,11 @@
7124671260
memAboutToChange(p, pDest);
7124771261
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7124871262
pC = p->apCsr[pOp->p1];
7124971263
assert( pC!=0 );
7125071264
assert( p2<pC->nField );
71251
- aOffset = pC->aType + pC->nField;
71265
+ aOffset = pC->aOffset;
7125271266
#ifndef SQLITE_OMIT_VIRTUALTABLE
7125371267
assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
7125471268
#endif
7125571269
pCrsr = pC->pCursor;
7125671270
assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -71257,11 +71271,11 @@
7125771271
assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
7125871272
7125971273
/* If the cursor cache is stale, bring it up-to-date */
7126071274
rc = sqlite3VdbeCursorMoveto(pC);
7126171275
if( rc ) goto abort_due_to_error;
71262
- if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
71276
+ if( pC->cacheStatus!=p->cacheCtr ){
7126371277
if( pC->nullRow ){
7126471278
if( pCrsr==0 ){
7126571279
assert( pC->pseudoTableReg>0 );
7126671280
pReg = &aMem[pC->pseudoTableReg];
7126771281
assert( pReg->flags & MEM_Blob );
@@ -71302,18 +71316,10 @@
7130271316
}
7130371317
pC->cacheStatus = p->cacheCtr;
7130471318
pC->iHdrOffset = getVarint32(pC->aRow, offset);
7130571319
pC->nHdrParsed = 0;
7130671320
aOffset[0] = offset;
71307
- if( avail<offset ){
71308
- /* pC->aRow does not have to hold the entire row, but it does at least
71309
- ** need to cover the header of the record. If pC->aRow does not contain
71310
- ** the complete header, then set it to zero, forcing the header to be
71311
- ** dynamically allocated. */
71312
- pC->aRow = 0;
71313
- pC->szRow = 0;
71314
- }
7131571321
7131671322
/* Make sure a corrupt database has not given us an oversize header.
7131771323
** Do this now to avoid an oversize memory allocation.
7131871324
**
7131971325
** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -71324,19 +71330,36 @@
7132471330
*/
7132571331
if( offset > 98307 || offset > pC->payloadSize ){
7132671332
rc = SQLITE_CORRUPT_BKPT;
7132771333
goto op_column_error;
7132871334
}
71335
+
71336
+ if( avail<offset ){
71337
+ /* pC->aRow does not have to hold the entire row, but it does at least
71338
+ ** need to cover the header of the record. If pC->aRow does not contain
71339
+ ** the complete header, then set it to zero, forcing the header to be
71340
+ ** dynamically allocated. */
71341
+ pC->aRow = 0;
71342
+ pC->szRow = 0;
71343
+ }
71344
+
71345
+ /* The following goto is an optimization. It can be omitted and
71346
+ ** everything will still work. But OP_Column is measurably faster
71347
+ ** by skipping the subsequent conditional, which is always true.
71348
+ */
71349
+ assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
71350
+ goto op_column_read_header;
7132971351
}
7133071352
7133171353
/* Make sure at least the first p2+1 entries of the header have been
7133271354
** parsed and valid information is in aOffset[] and pC->aType[].
7133371355
*/
7133471356
if( pC->nHdrParsed<=p2 ){
7133571357
/* If there is more header available for parsing in the record, try
7133671358
** to extract additional fields up through the p2+1-th field
7133771359
*/
71360
+ op_column_read_header:
7133871361
if( pC->iHdrOffset<aOffset[0] ){
7133971362
/* Make sure zData points to enough of the record to cover the header. */
7134071363
if( pC->aRow==0 ){
7134171364
memset(&sMem, 0, sizeof(sMem));
7134271365
rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
@@ -71377,19 +71400,20 @@
7137771400
if( pC->aRow==0 ){
7137871401
sqlite3VdbeMemRelease(&sMem);
7137971402
sMem.flags = MEM_Null;
7138071403
}
7138171404
71382
- /* If we have read more header data than was contained in the header,
71383
- ** or if the end of the last field appears to be past the end of the
71384
- ** record, or if the end of the last field appears to be before the end
71385
- ** of the record (when all fields present), then we must be dealing
71386
- ** with a corrupt database.
71405
+ /* The record is corrupt if any of the following are true:
71406
+ ** (1) the bytes of the header extend past the declared header size
71407
+ ** (zHdr>zEndHdr)
71408
+ ** (2) the entire header was used but not all data was used
71409
+ ** (zHdr==zEndHdr && offset!=pC->payloadSize)
71410
+ ** (3) the end of the data extends beyond the end of the record.
71411
+ ** (offset > pC->payloadSize)
7138771412
*/
71388
- if( (zHdr > zEndHdr)
71413
+ if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset!=pC->payloadSize))
7138971414
|| (offset > pC->payloadSize)
71390
- || (zHdr==zEndHdr && offset!=pC->payloadSize)
7139171415
){
7139271416
rc = SQLITE_CORRUPT_BKPT;
7139371417
goto op_column_error;
7139471418
}
7139571419
}
@@ -71576,11 +71600,11 @@
7157671600
** out how much space is required for the new record.
7157771601
*/
7157871602
pRec = pLast;
7157971603
do{
7158071604
assert( memIsValid(pRec) );
71581
- serial_type = sqlite3VdbeSerialType(pRec, file_format);
71605
+ pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format);
7158271606
len = sqlite3VdbeSerialTypeLen(serial_type);
7158371607
if( pRec->flags & MEM_Zero ){
7158471608
if( nData ){
7158571609
sqlite3VdbeMemExpandBlob(pRec);
7158671610
}else{
@@ -71625,11 +71649,11 @@
7162571649
i = putVarint32(zNewRecord, nHdr);
7162671650
j = nHdr;
7162771651
assert( pData0<=pLast );
7162871652
pRec = pData0;
7162971653
do{
71630
- serial_type = sqlite3VdbeSerialType(pRec, file_format);
71654
+ serial_type = pRec->uTemp;
7163171655
i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
7163271656
j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
7163371657
}while( (++pRec)<=pLast );
7163471658
assert( i==nHdr );
7163571659
assert( j==nByte );
@@ -72524,11 +72548,10 @@
7252472548
pIn3 = &aMem[pOp->p3];
7252572549
if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
7252672550
applyNumericAffinity(pIn3, 0);
7252772551
}
7252872552
iKey = sqlite3VdbeIntValue(pIn3);
72529
- pC->rowidIsValid = 0;
7253072553
7253172554
/* If the P3 value could not be converted into an integer without
7253272555
** loss of information, then special processing is required... */
7253372556
if( (pIn3->flags & MEM_Int)==0 ){
7253472557
if( (pIn3->flags & MEM_Real)==0 ){
@@ -72560,17 +72583,14 @@
7256072583
assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
7256172584
if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
7256272585
}
7256372586
}
7256472587
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
72588
+ pC->movetoTarget = iKey; /* Used by OP_Delete */
7256572589
if( rc!=SQLITE_OK ){
7256672590
goto abort_due_to_error;
7256772591
}
72568
- if( res==0 ){
72569
- pC->rowidIsValid = 1;
72570
- pC->lastRowid = iKey;
72571
- }
7257272592
}else{
7257372593
nField = pOp->p4.i;
7257472594
assert( pOp->p4type==P4_INT32 );
7257572595
assert( nField>0 );
7257672596
r.pKeyInfo = pC->pKeyInfo;
@@ -72596,11 +72616,10 @@
7259672616
ExpandBlob(r.aMem);
7259772617
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
7259872618
if( rc!=SQLITE_OK ){
7259972619
goto abort_due_to_error;
7260072620
}
72601
- pC->rowidIsValid = 0;
7260272621
}
7260372622
pC->deferredMoveto = 0;
7260472623
pC->cacheStatus = CACHE_STALE;
7260572624
#ifdef SQLITE_TEST
7260672625
sqlite3_search_count++;
@@ -72608,21 +72627,19 @@
7260872627
if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
7260972628
if( res<0 || (res==0 && oc==OP_SeekGT) ){
7261072629
res = 0;
7261172630
rc = sqlite3BtreeNext(pC->pCursor, &res);
7261272631
if( rc!=SQLITE_OK ) goto abort_due_to_error;
72613
- pC->rowidIsValid = 0;
7261472632
}else{
7261572633
res = 0;
7261672634
}
7261772635
}else{
7261872636
assert( oc==OP_SeekLT || oc==OP_SeekLE );
7261972637
if( res>0 || (res==0 && oc==OP_SeekLT) ){
7262072638
res = 0;
7262172639
rc = sqlite3BtreePrevious(pC->pCursor, &res);
7262272640
if( rc!=SQLITE_OK ) goto abort_due_to_error;
72623
- pC->rowidIsValid = 0;
7262472641
}else{
7262572642
/* res might be negative because the table is empty. Check to
7262672643
** see if this is the case.
7262772644
*/
7262872645
res = sqlite3BtreeEof(pC->pCursor);
@@ -72655,11 +72672,10 @@
7265572672
assert( pC->pCursor!=0 );
7265672673
assert( pC->isTable );
7265772674
pC->nullRow = 0;
7265872675
pIn2 = &aMem[pOp->p2];
7265972676
pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
72660
- pC->rowidIsValid = 0;
7266172677
pC->deferredMoveto = 1;
7266272678
break;
7266372679
}
7266472680
7266572681
@@ -72841,19 +72857,17 @@
7284172857
pCrsr = pC->pCursor;
7284272858
assert( pCrsr!=0 );
7284372859
res = 0;
7284472860
iKey = pIn3->u.i;
7284572861
rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
72846
- pC->lastRowid = pIn3->u.i;
72847
- pC->rowidIsValid = res==0 ?1:0;
72862
+ pC->movetoTarget = iKey; /* Used by OP_Delete */
7284872863
pC->nullRow = 0;
7284972864
pC->cacheStatus = CACHE_STALE;
7285072865
pC->deferredMoveto = 0;
7285172866
VdbeBranchTaken(res!=0,2);
7285272867
if( res!=0 ){
7285372868
pc = pOp->p2 - 1;
72854
- assert( pC->rowidIsValid==0 );
7285572869
}
7285672870
pC->seekResult = res;
7285772871
break;
7285872872
}
7285972873
@@ -72997,11 +73011,10 @@
7299773011
rc = SQLITE_FULL; /* IMP: R-38219-53002 */
7299873012
goto abort_due_to_error;
7299973013
}
7300073014
assert( v>0 ); /* EV: R-40812-03570 */
7300173015
}
73002
- pC->rowidIsValid = 0;
7300373016
pC->deferredMoveto = 0;
7300473017
pC->cacheStatus = CACHE_STALE;
7300573018
}
7300673019
pOut->u.i = v;
7300773020
break;
@@ -73102,11 +73115,10 @@
7310273115
}
7310373116
rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
7310473117
pData->z, pData->n, nZero,
7310573118
(pOp->p5 & OPFLAG_APPEND)!=0, seekResult
7310673119
);
73107
- pC->rowidIsValid = 0;
7310873120
pC->deferredMoveto = 0;
7310973121
pC->cacheStatus = CACHE_STALE;
7311073122
7311173123
/* Invoke the update-hook if required. */
7311273124
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
@@ -73139,37 +73151,36 @@
7313973151
** pointing to. The update hook will be invoked, if it exists.
7314073152
** If P4 is not NULL then the P1 cursor must have been positioned
7314173153
** using OP_NotFound prior to invoking this opcode.
7314273154
*/
7314373155
case OP_Delete: {
73144
- i64 iKey;
7314573156
VdbeCursor *pC;
7314673157
7314773158
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7314873159
pC = p->apCsr[pOp->p1];
7314973160
assert( pC!=0 );
7315073161
assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
73151
- iKey = pC->lastRowid; /* Only used for the update hook */
73152
-
73153
- /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
73154
- ** OP_Column on the same table without any intervening operations that
73155
- ** might move or invalidate the cursor. Hence cursor pC is always pointing
73156
- ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
73157
- ** below is always a no-op and cannot fail. We will run it anyhow, though,
73158
- ** to guard against future changes to the code generator.
73159
- **/
7316073162
assert( pC->deferredMoveto==0 );
73161
- rc = sqlite3VdbeCursorMoveto(pC);
73162
- if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7316373163
73164
+#ifdef SQLITE_DEBUG
73165
+ /* The seek operation that positioned the cursor prior to OP_Delete will
73166
+ ** have also set the pC->movetoTarget field to the rowid of the row that
73167
+ ** is being deleted */
73168
+ if( pOp->p4.z && pC->isTable ){
73169
+ i64 iKey = 0;
73170
+ sqlite3BtreeKeySize(pC->pCursor, &iKey);
73171
+ assert( pC->movetoTarget==iKey );
73172
+ }
73173
+#endif
73174
+
7316473175
rc = sqlite3BtreeDelete(pC->pCursor);
7316573176
pC->cacheStatus = CACHE_STALE;
7316673177
7316773178
/* Invoke the update-hook if required. */
7316873179
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
7316973180
db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
73170
- db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
73181
+ db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
7317173182
assert( pC->iDb>=0 );
7317273183
}
7317373184
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
7317473185
break;
7317573186
}
@@ -73218,23 +73229,32 @@
7321873229
pc = pOp->p2-1;
7321973230
}
7322073231
break;
7322173232
};
7322273233
73223
-/* Opcode: SorterData P1 P2 * * *
73234
+/* Opcode: SorterData P1 P2 P3 * *
7322473235
** Synopsis: r[P2]=data
7322573236
**
7322673237
** Write into register P2 the current sorter data for sorter cursor P1.
73238
+** Then clear the column header cache on cursor P3.
73239
+**
73240
+** This opcode is normally use to move a record out of the sorter and into
73241
+** a register that is the source for a pseudo-table cursor created using
73242
+** OpenPseudo. That pseudo-table cursor is the one that is identified by
73243
+** parameter P3. Clearing the P3 column cache as part of this opcode saves
73244
+** us from having to issue a separate NullRow instruction to clear that cache.
7322773245
*/
7322873246
case OP_SorterData: {
7322973247
VdbeCursor *pC;
7323073248
7323173249
pOut = &aMem[pOp->p2];
7323273250
pC = p->apCsr[pOp->p1];
7323373251
assert( isSorter(pC) );
7323473252
rc = sqlite3VdbeSorterRowkey(pC, pOut);
7323573253
assert( rc!=SQLITE_OK || (pOut->flags & MEM_Blob) );
73254
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73255
+ p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
7323673256
break;
7323773257
}
7323873258
7323973259
/* Opcode: RowData P1 P2 * * *
7324073260
** Synopsis: r[P2]=data
@@ -73277,20 +73297,24 @@
7327773297
assert( pC!=0 );
7327873298
assert( pC->nullRow==0 );
7327973299
assert( pC->pseudoTableReg==0 );
7328073300
assert( pC->pCursor!=0 );
7328173301
pCrsr = pC->pCursor;
73282
- assert( sqlite3BtreeCursorIsValid(pCrsr) );
7328373302
7328473303
/* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
7328573304
** OP_Rewind/Op_Next with no intervening instructions that might invalidate
73286
- ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
73287
- ** a no-op and can never fail. But we leave it in place as a safety.
73305
+ ** the cursor. If this where not the case, on of the following assert()s
73306
+ ** would fail. Should this ever change (because of changes in the code
73307
+ ** generator) then the fix would be to insert a call to
73308
+ ** sqlite3VdbeCursorMoveto().
7328873309
*/
7328973310
assert( pC->deferredMoveto==0 );
73311
+ assert( sqlite3BtreeCursorIsValid(pCrsr) );
73312
+#if 0 /* Not required due to the previous to assert() statements */
7329073313
rc = sqlite3VdbeCursorMoveto(pC);
73291
- if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73314
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
73315
+#endif
7329273316
7329373317
if( pC->isTable==0 ){
7329473318
assert( !pC->isTable );
7329573319
VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
7329673320
assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
@@ -73303,11 +73327,12 @@
7330373327
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
7330473328
if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
7330573329
goto too_big;
7330673330
}
7330773331
}
73308
- if( sqlite3VdbeMemClearAndResize(pOut, n) ){
73332
+ testcase( n==0 );
73333
+ if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
7330973334
goto no_mem;
7331073335
}
7331173336
pOut->n = n;
7331273337
MemSetTypeFlag(pOut, MEM_Blob);
7331373338
if( pC->isTable==0 ){
@@ -73354,18 +73379,14 @@
7335473379
rc = pModule->xRowid(pC->pVtabCursor, &v);
7335573380
sqlite3VtabImportErrmsg(p, pVtab);
7335673381
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7335773382
}else{
7335873383
assert( pC->pCursor!=0 );
73359
- rc = sqlite3VdbeCursorMoveto(pC);
73384
+ rc = sqlite3VdbeCursorRestore(pC);
7336073385
if( rc ) goto abort_due_to_error;
73361
- if( pC->rowidIsValid ){
73362
- v = pC->lastRowid;
73363
- }else{
73364
- rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73365
- assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
73366
- }
73386
+ rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73387
+ assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
7336773388
}
7336873389
pOut->u.i = v;
7336973390
break;
7337073391
}
7337173392
@@ -73380,11 +73401,10 @@
7338073401
7338173402
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7338273403
pC = p->apCsr[pOp->p1];
7338373404
assert( pC!=0 );
7338473405
pC->nullRow = 1;
73385
- pC->rowidIsValid = 0;
7338673406
pC->cacheStatus = CACHE_STALE;
7338773407
if( pC->pCursor ){
7338873408
sqlite3BtreeClearCursor(pC->pCursor);
7338973409
}
7339073410
break;
@@ -73414,11 +73434,10 @@
7341473434
res = 0;
7341573435
assert( pCrsr!=0 );
7341673436
rc = sqlite3BtreeLast(pCrsr, &res);
7341773437
pC->nullRow = (u8)res;
7341873438
pC->deferredMoveto = 0;
73419
- pC->rowidIsValid = 0;
7342073439
pC->cacheStatus = CACHE_STALE;
7342173440
#ifdef SQLITE_DEBUG
7342273441
pC->seekOp = OP_Last;
7342373442
#endif
7342473443
if( pOp->p2>0 ){
@@ -73481,11 +73500,10 @@
7348173500
pCrsr = pC->pCursor;
7348273501
assert( pCrsr );
7348373502
rc = sqlite3BtreeFirst(pCrsr, &res);
7348473503
pC->deferredMoveto = 0;
7348573504
pC->cacheStatus = CACHE_STALE;
73486
- pC->rowidIsValid = 0;
7348773505
}
7348873506
pC->nullRow = (u8)res;
7348973507
assert( pOp->p2>0 && pOp->p2<p->nOp );
7349073508
VdbeBranchTaken(res!=0,2);
7349173509
if( res ){
@@ -73607,11 +73625,10 @@
7360773625
sqlite3_search_count++;
7360873626
#endif
7360973627
}else{
7361073628
pC->nullRow = 1;
7361173629
}
73612
- pC->rowidIsValid = 0;
7361373630
goto check_for_interrupt;
7361473631
}
7361573632
7361673633
/* Opcode: IdxInsert P1 P2 P3 * P5
7361773634
** Synopsis: key=r[P2]
@@ -73723,14 +73740,20 @@
7372373740
pC = p->apCsr[pOp->p1];
7372473741
assert( pC!=0 );
7372573742
pCrsr = pC->pCursor;
7372673743
assert( pCrsr!=0 );
7372773744
pOut->flags = MEM_Null;
73728
- rc = sqlite3VdbeCursorMoveto(pC);
73729
- if( NEVER(rc) ) goto abort_due_to_error;
73745
+ assert( pC->isTable==0 );
7373073746
assert( pC->deferredMoveto==0 );
73731
- assert( pC->isTable==0 );
73747
+
73748
+ /* sqlite3VbeCursorRestore() can only fail if the record has been deleted
73749
+ ** out from under the cursor. That will never happend for an IdxRowid
73750
+ ** opcode, hence the NEVER() arround the check of the return value.
73751
+ */
73752
+ rc = sqlite3VdbeCursorRestore(pC);
73753
+ if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73754
+
7373273755
if( !pC->nullRow ){
7373373756
rowid = 0; /* Not needed. Only used to silence a warning. */
7373473757
rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
7373573758
if( rc!=SQLITE_OK ){
7373673759
goto abort_due_to_error;
@@ -87168,29 +87191,27 @@
8716887191
tRowcnt v;
8716987192
8717087193
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
8717187194
if( z==0 ) z = "";
8717287195
#else
87173
- if( NEVER(z==0) ) z = "";
87196
+ assert( z!=0 );
8717487197
#endif
8717587198
for(i=0; *z && i<nOut; i++){
8717687199
v = 0;
8717787200
while( (c=z[0])>='0' && c<='9' ){
8717887201
v = v*10 + c - '0';
8717987202
z++;
8718087203
}
8718187204
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87182
- if( aOut ){
87183
- aOut[i] = v;
87184
- }else
87205
+ if( aOut ) aOut[i] = v;
87206
+ if( aLog ) aLog[i] = sqlite3LogEst(v);
8718587207
#else
8718687208
assert( aOut==0 );
8718787209
UNUSED_PARAMETER(aOut);
87210
+ assert( aLog!=0 );
87211
+ aLog[i] = sqlite3LogEst(v);
8718887212
#endif
87189
- {
87190
- aLog[i] = sqlite3LogEst(v);
87191
- }
8719287213
if( *z==' ' ) z++;
8719387214
}
8719487215
#ifndef SQLITE_ENABLE_STAT3_OR_STAT4
8719587216
assert( pIndex!=0 );
8719687217
#else
@@ -87247,12 +87268,21 @@
8724787268
pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
8724887269
}
8724987270
z = argv[2];
8725087271
8725187272
if( pIndex ){
87273
+ int nCol = pIndex->nKeyCol+1;
87274
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87275
+ tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
87276
+ sizeof(tRowcnt) * nCol
87277
+ );
87278
+ if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
87279
+#else
87280
+ tRowcnt * const aiRowEst = 0;
87281
+#endif
8725287282
pIndex->bUnordered = 0;
87253
- decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
87283
+ decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
8725487284
if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
8725587285
}else{
8725687286
Index fakeIdx;
8725787287
fakeIdx.szIdxRow = pTable->szTabRow;
8725887288
#ifdef SQLITE_ENABLE_COSTMULT
@@ -87307,29 +87337,42 @@
8730787337
** unique. */
8730887338
nCol = pIdx->nSampleCol-1;
8730987339
pIdx->aAvgEq[nCol] = 1;
8731087340
}
8731187341
for(iCol=0; iCol<nCol; iCol++){
87342
+ int nSample = pIdx->nSample;
8731287343
int i; /* Used to iterate through samples */
8731387344
tRowcnt sumEq = 0; /* Sum of the nEq values */
87314
- tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
8731587345
tRowcnt avgEq = 0;
87316
- tRowcnt nDLt = pFinal->anDLt[iCol];
87346
+ tRowcnt nRow; /* Number of rows in index */
87347
+ i64 nSum100 = 0; /* Number of terms contributing to sumEq */
87348
+ i64 nDist100; /* Number of distinct values in index */
87349
+
87350
+ if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
87351
+ nRow = pFinal->anLt[iCol];
87352
+ nDist100 = (i64)100 * pFinal->anDLt[iCol];
87353
+ nSample--;
87354
+ }else{
87355
+ nRow = pIdx->aiRowEst[0];
87356
+ nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
87357
+ }
8731787358
8731887359
/* Set nSum to the number of distinct (iCol+1) field prefixes that
87319
- ** occur in the stat4 table for this index before pFinal. Set
87320
- ** sumEq to the sum of the nEq values for column iCol for the same
87321
- ** set (adding the value only once where there exist duplicate
87322
- ** prefixes). */
87323
- for(i=0; i<(pIdx->nSample-1); i++){
87324
- if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
87360
+ ** occur in the stat4 table for this index. Set sumEq to the sum of
87361
+ ** the nEq values for column iCol for the same set (adding the value
87362
+ ** only once where there exist duplicate prefixes). */
87363
+ for(i=0; i<nSample; i++){
87364
+ if( i==(pIdx->nSample-1)
87365
+ || aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol]
87366
+ ){
8732587367
sumEq += aSample[i].anEq[iCol];
87326
- nSum++;
87368
+ nSum100 += 100;
8732787369
}
8732887370
}
87329
- if( nDLt>nSum ){
87330
- avgEq = (pFinal->anLt[iCol] - sumEq)/(nDLt - nSum);
87371
+
87372
+ if( nDist100>nSum100 ){
87373
+ avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
8733187374
}
8733287375
if( avgEq==0 ) avgEq = 1;
8733387376
pIdx->aAvgEq[iCol] = avgEq;
8733487377
}
8733587378
}
@@ -87576,10 +87619,15 @@
8757687619
if( rc==SQLITE_OK ){
8757787620
int lookasideEnabled = db->lookaside.bEnabled;
8757887621
db->lookaside.bEnabled = 0;
8757987622
rc = loadStat4(db, sInfo.zDatabase);
8758087623
db->lookaside.bEnabled = lookasideEnabled;
87624
+ }
87625
+ for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
87626
+ Index *pIdx = sqliteHashData(i);
87627
+ sqlite3_free(pIdx->aiRowEst);
87628
+ pIdx->aiRowEst = 0;
8758187629
}
8758287630
#endif
8758387631
8758487632
if( rc==SQLITE_NOMEM ){
8758587633
db->mallocFailed = 1;
@@ -88870,10 +88918,13 @@
8887088918
#endif
8887188919
if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
8887288920
sqlite3ExprDelete(db, p->pPartIdxWhere);
8887388921
sqlite3DbFree(db, p->zColAff);
8887488922
if( p->isResized ) sqlite3DbFree(db, p->azColl);
88923
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
88924
+ sqlite3_free(p->aiRowEst);
88925
+#endif
8887588926
sqlite3DbFree(db, p);
8887688927
}
8887788928
8887888929
/*
8887988930
** For the index called zIdxName which is found in the database iDb,
@@ -91179,11 +91230,11 @@
9117991230
pIndex->nKeyCol); VdbeCoverage(v);
9118091231
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
9118191232
}else{
9118291233
addr2 = sqlite3VdbeCurrentAddr(v);
9118391234
}
91184
- sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
91235
+ sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
9118591236
sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
9118691237
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
9118791238
sqlite3ReleaseTempReg(pParse, regRecord);
9118891239
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
9118991240
sqlite3VdbeJumpHere(v, addr1);
@@ -105122,11 +105173,10 @@
105122105173
int regRow;
105123105174
int regRowid;
105124105175
int nKey;
105125105176
int iSortTab; /* Sorter cursor to read from */
105126105177
int nSortData; /* Trailing values to read from sorter */
105127
- u8 p5; /* p5 parameter for 1st OP_Column */
105128105178
int i;
105129105179
int bSeq; /* True if sorter record includes seq. no. */
105130105180
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
105131105181
struct ExprList_item *aOutEx = p->pEList->a;
105132105182
#endif
@@ -105156,23 +105206,20 @@
105156105206
sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
105157105207
if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
105158105208
addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
105159105209
VdbeCoverage(v);
105160105210
codeOffset(v, p->iOffset, addrContinue);
105161
- sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
105162
- p5 = OPFLAG_CLEARCACHE;
105211
+ sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
105163105212
bSeq = 0;
105164105213
}else{
105165105214
addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
105166105215
codeOffset(v, p->iOffset, addrContinue);
105167105216
iSortTab = iTab;
105168
- p5 = 0;
105169105217
bSeq = 1;
105170105218
}
105171105219
for(i=0; i<nSortData; i++){
105172105220
sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
105173
- if( i==0 ) sqlite3VdbeChangeP5(v, p5);
105174105221
VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
105175105222
}
105176105223
switch( eDest ){
105177105224
case SRT_Table:
105178105225
case SRT_EphemTab: {
@@ -109097,16 +109144,15 @@
109097109144
** from the previous row currently stored in a0, a1, a2...
109098109145
*/
109099109146
addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
109100109147
sqlite3ExprCacheClear(pParse);
109101109148
if( groupBySort ){
109102
- sqlite3VdbeAddOp2(v, OP_SorterData, sAggInfo.sortingIdx, sortOut);
109149
+ sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx, sortOut,sortPTab);
109103109150
}
109104109151
for(j=0; j<pGroupBy->nExpr; j++){
109105109152
if( groupBySort ){
109106109153
sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
109107
- if( j==0 ) sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
109108109154
}else{
109109109155
sAggInfo.directMode = 1;
109110109156
sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
109111109157
}
109112109158
}
@@ -112450,10 +112496,11 @@
112450112496
}
112451112497
sqlite3DbFree(db, pVTable);
112452112498
}else if( ALWAYS(pVTable->pVtab) ){
112453112499
/* Justification of ALWAYS(): A correct vtab constructor must allocate
112454112500
** the sqlite3_vtab object if successful. */
112501
+ memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
112455112502
pVTable->pVtab->pModule = pMod->pModule;
112456112503
pVTable->nRef = 1;
112457112504
if( sCtx.pTab ){
112458112505
const char *zFormat = "vtable constructor did not declare schema: %s";
112459112506
*pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
@@ -115700,21 +115747,28 @@
115700115747
** have been requested when testing key $P in whereEqualScanEst(). */
115701115748
whereKeyStats(pParse, p, pRec, 0, a);
115702115749
iLower = a[0];
115703115750
iUpper = a[0] + a[1];
115704115751
}
115752
+
115753
+ assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115754
+ assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115755
+ assert( p->aSortOrder!=0 );
115756
+ if( p->aSortOrder[nEq] ){
115757
+ /* The roles of pLower and pUpper are swapped for a DESC index */
115758
+ SWAP(WhereTerm*, pLower, pUpper);
115759
+ }
115705115760
115706115761
/* If possible, improve on the iLower estimate using ($P:$L). */
115707115762
if( pLower ){
115708115763
int bOk; /* True if value is extracted from pExpr */
115709115764
Expr *pExpr = pLower->pExpr->pRight;
115710
- assert( (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115711115765
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115712115766
if( rc==SQLITE_OK && bOk ){
115713115767
tRowcnt iNew;
115714115768
whereKeyStats(pParse, p, pRec, 0, a);
115715
- iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
115769
+ iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115716115770
if( iNew>iLower ) iLower = iNew;
115717115771
nOut--;
115718115772
pLower = 0;
115719115773
}
115720115774
}
@@ -115721,16 +115775,15 @@
115721115775
115722115776
/* If possible, improve on the iUpper estimate using ($P:$U). */
115723115777
if( pUpper ){
115724115778
int bOk; /* True if value is extracted from pExpr */
115725115779
Expr *pExpr = pUpper->pExpr->pRight;
115726
- assert( (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115727115780
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115728115781
if( rc==SQLITE_OK && bOk ){
115729115782
tRowcnt iNew;
115730115783
whereKeyStats(pParse, p, pRec, 1, a);
115731
- iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
115784
+ iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115732115785
if( iNew<iUpper ) iUpper = iNew;
115733115786
nOut--;
115734115787
pUpper = 0;
115735115788
}
115736115789
}
@@ -116225,65 +116278,52 @@
116225116278
sqlite3StrAccumAppend(pStr, "?", 1);
116226116279
}
116227116280
116228116281
/*
116229116282
** Argument pLevel describes a strategy for scanning table pTab. This
116230
-** function returns a pointer to a string buffer containing a description
116231
-** of the subset of table rows scanned by the strategy in the form of an
116232
-** SQL expression. Or, if all rows are scanned, NULL is returned.
116283
+** function appends text to pStr that describes the subset of table
116284
+** rows scanned by the strategy in the form of an SQL expression.
116233116285
**
116234116286
** For example, if the query:
116235116287
**
116236116288
** SELECT * FROM t1 WHERE a=1 AND b>2;
116237116289
**
116238116290
** is run and there is an index on (a, b), then this function returns a
116239116291
** string similar to:
116240116292
**
116241116293
** "a=? AND b>?"
116242
-**
116243
-** The returned pointer points to memory obtained from sqlite3DbMalloc().
116244
-** It is the responsibility of the caller to free the buffer when it is
116245
-** no longer required.
116246116294
*/
116247
-static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
116295
+static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
116248116296
Index *pIndex = pLoop->u.btree.pIndex;
116249116297
u16 nEq = pLoop->u.btree.nEq;
116250116298
u16 nSkip = pLoop->u.btree.nSkip;
116251116299
int i, j;
116252116300
Column *aCol = pTab->aCol;
116253116301
i16 *aiColumn = pIndex->aiColumn;
116254
- StrAccum txt;
116255
-
116256
- if( nEq==0 && (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ){
116257
- return 0;
116258
- }
116259
- sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
116260
- txt.db = db;
116261
- sqlite3StrAccumAppend(&txt, " (", 2);
116302
+
116303
+ if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
116304
+ sqlite3StrAccumAppend(pStr, " (", 2);
116262116305
for(i=0; i<nEq; i++){
116263116306
char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
116264116307
if( i>=nSkip ){
116265
- explainAppendTerm(&txt, i, z, "=");
116308
+ explainAppendTerm(pStr, i, z, "=");
116266116309
}else{
116267
- if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
116268
- sqlite3StrAccumAppend(&txt, "ANY(", 4);
116269
- sqlite3StrAccumAppendAll(&txt, z);
116270
- sqlite3StrAccumAppend(&txt, ")", 1);
116310
+ if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
116311
+ sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
116271116312
}
116272116313
}
116273116314
116274116315
j = i;
116275116316
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
116276116317
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116277
- explainAppendTerm(&txt, i++, z, ">");
116318
+ explainAppendTerm(pStr, i++, z, ">");
116278116319
}
116279116320
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
116280116321
char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116281
- explainAppendTerm(&txt, i, z, "<");
116322
+ explainAppendTerm(pStr, i, z, "<");
116282116323
}
116283
- sqlite3StrAccumAppend(&txt, ")", 1);
116284
- return sqlite3StrAccumFinish(&txt);
116324
+ sqlite3StrAccumAppend(pStr, ")", 1);
116285116325
}
116286116326
116287116327
/*
116288116328
** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116289116329
** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
@@ -116303,72 +116343,90 @@
116303116343
#endif
116304116344
{
116305116345
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116306116346
Vdbe *v = pParse->pVdbe; /* VM being constructed */
116307116347
sqlite3 *db = pParse->db; /* Database handle */
116308
- char *zMsg; /* Text to add to EQP output */
116309116348
int iId = pParse->iSelectId; /* Select id (left-most output column) */
116310116349
int isSearch; /* True for a SEARCH. False for SCAN. */
116311116350
WhereLoop *pLoop; /* The controlling WhereLoop object */
116312116351
u32 flags; /* Flags that describe this loop */
116352
+ char *zMsg; /* Text to add to EQP output */
116353
+ StrAccum str; /* EQP output string */
116354
+ char zBuf[100]; /* Initial space for EQP output string */
116313116355
116314116356
pLoop = pLevel->pWLoop;
116315116357
flags = pLoop->wsFlags;
116316116358
if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116317116359
116318116360
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116319116361
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116320116362
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116321116363
116322
- zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
116364
+ sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
116365
+ str.db = db;
116366
+ sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
116323116367
if( pItem->pSelect ){
116324
- zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
116368
+ sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
116325116369
}else{
116326
- zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
116370
+ sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
116327116371
}
116328116372
116329116373
if( pItem->zAlias ){
116330
- zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
116331
- }
116332
- if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0
116333
- && ALWAYS(pLoop->u.btree.pIndex!=0)
116334
- ){
116335
- const char *zFmt;
116336
- Index *pIdx = pLoop->u.btree.pIndex;
116337
- char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
116374
+ sqlite3XPrintf(&str, 0, " AS %s", pItem->zAlias);
116375
+ }
116376
+ if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
116377
+ const char *zFmt = 0;
116378
+ Index *pIdx;
116379
+
116380
+ assert( pLoop->u.btree.pIndex!=0 );
116381
+ pIdx = pLoop->u.btree.pIndex;
116338116382
assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116339116383
if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116340
- zFmt = zWhere ? "%s USING PRIMARY KEY%.0s%s" : "%s%.0s%s";
116384
+ if( isSearch ){
116385
+ zFmt = "PRIMARY KEY";
116386
+ }
116341116387
}else if( flags & WHERE_AUTO_INDEX ){
116342
- zFmt = "%s USING AUTOMATIC COVERING INDEX%.0s%s";
116388
+ zFmt = "AUTOMATIC COVERING INDEX";
116343116389
}else if( flags & WHERE_IDX_ONLY ){
116344
- zFmt = "%s USING COVERING INDEX %s%s";
116390
+ zFmt = "COVERING INDEX %s";
116345116391
}else{
116346
- zFmt = "%s USING INDEX %s%s";
116392
+ zFmt = "INDEX %s";
116347116393
}
116348
- zMsg = sqlite3MAppendf(db, zMsg, zFmt, zMsg, pIdx->zName, zWhere);
116349
- sqlite3DbFree(db, zWhere);
116394
+ if( zFmt ){
116395
+ sqlite3StrAccumAppend(&str, " USING ", 7);
116396
+ sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
116397
+ explainIndexRange(&str, pLoop, pItem->pTab);
116398
+ }
116350116399
}else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
116351
- zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
116352
-
116400
+ const char *zRange;
116353116401
if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
116354
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
116402
+ zRange = "(rowid=?)";
116355116403
}else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
116356
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
116404
+ zRange = "(rowid>? AND rowid<?)";
116357116405
}else if( flags&WHERE_BTM_LIMIT ){
116358
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
116359
- }else if( ALWAYS(flags&WHERE_TOP_LIMIT) ){
116360
- zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
116406
+ zRange = "(rowid>?)";
116407
+ }else{
116408
+ assert( flags&WHERE_TOP_LIMIT);
116409
+ zRange = "(rowid<?)";
116361116410
}
116411
+ sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
116412
+ sqlite3StrAccumAppendAll(&str, zRange);
116362116413
}
116363116414
#ifndef SQLITE_OMIT_VIRTUALTABLE
116364116415
else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
116365
- zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
116416
+ sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
116366116417
pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
116367116418
}
116368116419
#endif
116369
- zMsg = sqlite3MAppendf(db, zMsg, "%s", zMsg);
116420
+#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
116421
+ if( pLoop->nOut>=10 ){
116422
+ sqlite3XPrintf(&str, 0, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut));
116423
+ }else{
116424
+ sqlite3StrAccumAppend(&str, " (~1 row)", 9);
116425
+ }
116426
+#endif
116427
+ zMsg = sqlite3StrAccumFinish(&str);
116370116428
sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116371116429
}
116372116430
}
116373116431
#else
116374116432
# define explainOneScan(u,v,w,x,y,z)
@@ -117633,11 +117691,11 @@
117633117691
if( ppPrev==0 ){
117634117692
/* There already exists a WhereLoop on the list that is better
117635117693
** than pTemplate, so just ignore pTemplate */
117636117694
#if WHERETRACE_ENABLED /* 0x8 */
117637117695
if( sqlite3WhereTrace & 0x8 ){
117638
- sqlite3DebugPrintf("ins-noop: ");
117696
+ sqlite3DebugPrintf(" skip: ");
117639117697
whereLoopPrint(pTemplate, pBuilder->pWC);
117640117698
}
117641117699
#endif
117642117700
return SQLITE_OK;
117643117701
}else{
@@ -117649,14 +117707,14 @@
117649117707
** WhereLoop and insert it.
117650117708
*/
117651117709
#if WHERETRACE_ENABLED /* 0x8 */
117652117710
if( sqlite3WhereTrace & 0x8 ){
117653117711
if( p!=0 ){
117654
- sqlite3DebugPrintf("ins-del: ");
117712
+ sqlite3DebugPrintf("replace: ");
117655117713
whereLoopPrint(p, pBuilder->pWC);
117656117714
}
117657
- sqlite3DebugPrintf("ins-new: ");
117715
+ sqlite3DebugPrintf(" add: ");
117658117716
whereLoopPrint(pTemplate, pBuilder->pWC);
117659117717
}
117660117718
#endif
117661117719
if( p==0 ){
117662117720
/* Allocate a new WhereLoop to add to the end of the list */
@@ -117676,11 +117734,11 @@
117676117734
pToDel = *ppTail;
117677117735
if( pToDel==0 ) break;
117678117736
*ppTail = pToDel->pNextLoop;
117679117737
#if WHERETRACE_ENABLED /* 0x8 */
117680117738
if( sqlite3WhereTrace & 0x8 ){
117681
- sqlite3DebugPrintf("ins-del: ");
117739
+ sqlite3DebugPrintf(" delete: ");
117682117740
whereLoopPrint(pToDel, pBuilder->pWC);
117683117741
}
117684117742
#endif
117685117743
whereLoopDelete(db, pToDel);
117686117744
}
@@ -118843,11 +118901,11 @@
118843118901
if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
118844118902
}
118845118903
isMatch = 1;
118846118904
break;
118847118905
}
118848
- if( isMatch && (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
118906
+ if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
118849118907
/* Make sure the sort order is compatible in an ORDER BY clause.
118850118908
** Sort order is irrelevant for a GROUP BY clause. */
118851118909
if( revSet ){
118852118910
if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;
118853118911
}else{
@@ -119308,16 +119366,19 @@
119308119366
pWInfo->revMask = pFrom->revLoop;
119309119367
}
119310119368
if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
119311119369
&& pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
119312119370
){
119313
- Bitmask notUsed = 0;
119371
+ Bitmask revMask = 0;
119314119372
int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
119315
- pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed
119373
+ pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
119316119374
);
119317119375
assert( pWInfo->sorted==0 );
119318
- pWInfo->sorted = (nOrder==pWInfo->pOrderBy->nExpr);
119376
+ if( nOrder==pWInfo->pOrderBy->nExpr ){
119377
+ pWInfo->sorted = 1;
119378
+ pWInfo->revMask = revMask;
119379
+ }
119319119380
}
119320119381
}
119321119382
119322119383
119323119384
pWInfo->nRowOut = pFrom->nRow;
@@ -132620,10 +132681,11 @@
132620132681
assert( iIdx==nVal );
132621132682
132622132683
/* In case the cursor has been used before, clear it now. */
132623132684
sqlite3_finalize(pCsr->pStmt);
132624132685
sqlite3_free(pCsr->aDoclist);
132686
+ sqlite3_free(pCsr->aMatchinfo);
132625132687
sqlite3Fts3ExprFree(pCsr->pExpr);
132626132688
memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
132627132689
132628132690
/* Set the lower and upper bounds on docids to return */
132629132691
pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
@@ -133930,11 +133992,11 @@
133930133992
if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
133931133993
iMax = a[i].iDocid;
133932133994
bMaxSet = 1;
133933133995
}
133934133996
}
133935
- assert( rc!=SQLITE_OK || a[p->nToken-1].bIgnore==0 );
133997
+ assert( rc!=SQLITE_OK || (p->nToken>=1 && a[p->nToken-1].bIgnore==0) );
133936133998
assert( rc!=SQLITE_OK || bMaxSet );
133937133999
133938134000
/* Keep advancing iterators until they all point to the same document */
133939134001
for(i=0; i<p->nToken; i++){
133940134002
while( rc==SQLITE_OK && bEof==0
@@ -136047,11 +136109,11 @@
136047136109
int i = 0;
136048136110
136049136111
/* Set variable i to the maximum number of bytes of input to tokenize. */
136050136112
for(i=0; i<n; i++){
136051136113
if( sqlite3_fts3_enable_parentheses && (z[i]=='(' || z[i]==')') ) break;
136052
- if( z[i]=='*' || z[i]=='"' ) break;
136114
+ if( z[i]=='"' ) break;
136053136115
}
136054136116
136055136117
*pnConsumed = i;
136056136118
rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
136057136119
if( rc==SQLITE_OK ){
136058136120
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.7"
235 #define SQLITE_VERSION_NUMBER 3008007
236 #define SQLITE_SOURCE_ID "2014-10-04 19:31:53 b8f7f19dc06c59de2e194d83e6c052fb7d28c71d"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -7944,11 +7944,11 @@
7944 ** A macro to hint to the compiler that a function should not be
7945 ** inlined.
7946 */
7947 #if defined(__GNUC__)
7948 # define SQLITE_NOINLINE __attribute__((noinline))
7949 #elif defined(_MSC_VER)
7950 # define SQLITE_NOINLINE __declspec(noinline)
7951 #else
7952 # define SQLITE_NOINLINE
7953 #endif
7954
@@ -11322,10 +11322,11 @@
11322 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11323 int nSample; /* Number of elements in aSample[] */
11324 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11325 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11326 IndexSample *aSample; /* Samples of the left-most key */
 
11327 #endif
11328 };
11329
11330 /*
11331 ** Allowed values for Index.idxType
@@ -12186,11 +12187,10 @@
12186 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
12187 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
12188 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
12189 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
12190 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
12191 #define OPFLAG_CLEARCACHE 0x20 /* Clear pseudo-table cache in OP_Column */
12192 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
12193 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
12194 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
12195 #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
12196 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
@@ -13320,14 +13320,13 @@
13320 # define sqlite3MemdebugSetType(X,Y) /* no-op */
13321 # define sqlite3MemdebugHasType(X,Y) 1
13322 # define sqlite3MemdebugNoType(X,Y) 1
13323 #endif
13324 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
13325 #define MEMTYPE_LOOKASIDE 0x02 /* Might have been lookaside memory */
13326 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
13327 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
13328 #define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
13329
13330 /*
13331 ** Threading interface
13332 */
13333 #if SQLITE_MAX_WORKER_THREADS>0
@@ -14095,21 +14094,19 @@
14095 #ifdef SQLITE_DEBUG
14096 u8 seekOp; /* Most recent seek operation on this cursor */
14097 #endif
14098 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
14099 u8 nullRow; /* True if pointing to a row with no data */
14100 u8 rowidIsValid; /* True if lastRowid is valid */
14101 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
14102 Bool isEphemeral:1; /* True for an ephemeral table */
14103 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
14104 Bool isTable:1; /* True if a table requiring integer keys */
14105 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
14106 Pgno pgnoRoot; /* Root page of the open btree cursor */
14107 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
14108 i64 seqCount; /* Sequence counter */
14109 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
14110 i64 lastRowid; /* Rowid being deleted by OP_Delete */
14111 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
14112
14113 /* Cached information about the header for the data record that the
14114 ** cursor is currently pointing to. Only valid if cacheStatus matches
14115 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -14122,10 +14119,11 @@
14122 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
14123 u32 payloadSize; /* Total number of bytes in the record */
14124 u32 szRow; /* Byte available in aRow */
14125 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
14126 const u8 *aRow; /* Data for the current row, if all on one page */
 
14127 u32 aType[1]; /* Type values for all entries in the record */
14128 /* 2*nField extra array elements allocated for aType[], beyond the one
14129 ** static element declared in the structure. nField total array slots for
14130 ** aType[] and nField+1 array slots for aOffset[] */
14131 };
@@ -14198,11 +14196,11 @@
14198 int n; /* Number of characters in string value, excluding '\0' */
14199 char *z; /* String or BLOB value */
14200 /* ShallowCopy only needs to copy the information above */
14201 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14202 int szMalloc; /* Size of the zMalloc allocation */
14203 int iPadding1; /* Padding for 8-byte alignment */
14204 sqlite3 *db; /* The associated database connection */
14205 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
14206 #ifdef SQLITE_DEBUG
14207 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
14208 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
@@ -14406,10 +14404,11 @@
14406 ** Function prototypes
14407 */
14408 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
14409 void sqliteVdbePopStack(Vdbe*,int);
14410 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
 
14411 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
14412 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
14413 #endif
14414 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
14415 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
@@ -17130,11 +17129,11 @@
17130 ** allocation p. Also return true if p==NULL.
17131 **
17132 ** This routine is designed for use within an assert() statement, to
17133 ** verify the type of an allocation. For example:
17134 **
17135 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
17136 */
17137 SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
17138 int rc = 1;
17139 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17140 struct MemBlockHdr *pHdr;
@@ -17152,11 +17151,11 @@
17152 ** allocation p. Also return true if p==NULL.
17153 **
17154 ** This routine is designed for use within an assert() statement, to
17155 ** verify the type of an allocation. For example:
17156 **
17157 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
17158 */
17159 SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
17160 int rc = 1;
17161 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17162 struct MemBlockHdr *pHdr;
@@ -20364,39 +20363,41 @@
20364 ** Return the size of a memory allocation previously obtained from
20365 ** sqlite3Malloc() or sqlite3_malloc().
20366 */
20367 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
20368 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20369 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
20370 return sqlite3GlobalConfig.m.xSize(p);
20371 }
20372 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20373 if( db==0 ){
 
 
20374 return sqlite3MallocSize(p);
20375 }else{
20376 assert( sqlite3_mutex_held(db->mutex) );
20377 if( isLookaside(db, p) ){
20378 return db->lookaside.sz;
20379 }else{
20380 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20381 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20382 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20383 return sqlite3GlobalConfig.m.xSize(p);
20384 }
20385 }
20386 }
20387 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
 
 
20388 return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20389 }
20390
20391 /*
20392 ** Free memory previously obtained from sqlite3Malloc().
20393 */
20394 SQLITE_API void sqlite3_free(void *p){
20395 if( p==0 ) return; /* IMP: R-49053-54554 */
20396 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
20397 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 
20398 if( sqlite3GlobalConfig.bMemstat ){
20399 sqlite3_mutex_enter(mem0.mutex);
20400 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
20401 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20402 sqlite3GlobalConfig.m.xFree(p);
@@ -20436,12 +20437,12 @@
20436 db->lookaside.pFree = pBuf;
20437 db->lookaside.nOut--;
20438 return;
20439 }
20440 }
20441 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20442 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20443 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20444 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20445 sqlite3_free(p);
20446 }
20447
@@ -20449,10 +20450,12 @@
20449 ** Change the size of an existing memory allocation
20450 */
20451 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
20452 int nOld, nNew, nDiff;
20453 void *pNew;
 
 
20454 if( pOld==0 ){
20455 return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
20456 }
20457 if( nBytes==0 ){
20458 sqlite3_free(pOld); /* IMP: R-26507-47431 */
@@ -20475,12 +20478,10 @@
20475 nDiff = nNew - nOld;
20476 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
20477 mem0.alarmThreshold-nDiff ){
20478 sqlite3MallocAlarm(nDiff);
20479 }
20480 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20481 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20482 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20483 if( pNew==0 && mem0.alarmCallback ){
20484 sqlite3MallocAlarm((int)nBytes);
20485 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20486 }
@@ -20589,12 +20590,12 @@
20589 #endif
20590 p = sqlite3Malloc(n);
20591 if( !p && db ){
20592 db->mallocFailed = 1;
20593 }
20594 sqlite3MemdebugSetType(p, MEMTYPE_DB |
20595 ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20596 return p;
20597 }
20598
20599 /*
20600 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -20616,19 +20617,18 @@
20616 if( pNew ){
20617 memcpy(pNew, p, db->lookaside.sz);
20618 sqlite3DbFree(db, p);
20619 }
20620 }else{
20621 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
20622 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
20623 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20624 pNew = sqlite3_realloc64(p, n);
20625 if( !pNew ){
20626 sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
20627 db->mallocFailed = 1;
20628 }
20629 sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
20630 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20631 }
20632 }
20633 return pNew;
20634 }
@@ -22098,11 +22098,11 @@
22098 #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
22099 #include <process.h>
22100
22101 /* A running thread */
22102 struct SQLiteThread {
22103 uintptr_t tid; /* The thread handle */
22104 unsigned id; /* The thread identifier */
22105 void *(*xTask)(void*); /* The routine to run as a thread */
22106 void *pIn; /* Argument to xTask */
22107 void *pResult; /* Result of xTask */
22108 };
@@ -22146,11 +22146,11 @@
22146 if( sqlite3GlobalConfig.bCoreMutex==0 ){
22147 memset(p, 0, sizeof(*p));
22148 }else{
22149 p->xTask = xTask;
22150 p->pIn = pIn;
22151 p->tid = _beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
22152 if( p->tid==0 ){
22153 memset(p, 0, sizeof(*p));
22154 }
22155 }
22156 if( p->xTask==0 ){
@@ -39855,11 +39855,11 @@
39855 assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
39856 assert( pCache->n90pct == pCache->nMax*9/10 );
39857 if( createFlag==1 && (
39858 nPinned>=pGroup->mxPinned
39859 || nPinned>=pCache->n90pct
39860 || pcache1UnderMemoryPressure(pCache)
39861 )){
39862 return 0;
39863 }
39864
39865 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
@@ -44476,17 +44476,19 @@
44476 if( !pNew ) rc = SQLITE_NOMEM;
44477 }
44478
44479 if( rc==SQLITE_OK ){
44480 pager_reset(pPager);
44481 sqlite3PageFree(pPager->pTmpSpace);
44482 pPager->pTmpSpace = pNew;
44483 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
44484 }
44485 if( rc==SQLITE_OK ){
 
 
44486 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44487 pPager->pageSize = pageSize;
 
 
44488 }
44489 }
44490
44491 *pPageSize = pPager->pageSize;
44492 if( rc==SQLITE_OK ){
@@ -52947,11 +52949,11 @@
52947 **
52948 ** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
52949 ** back to where it ought to be if this routine returns true.
52950 */
52951 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
52952 return pCur && pCur->eState!=CURSOR_VALID;
52953 }
52954
52955 /*
52956 ** This routine restores a cursor back to its original position after it
52957 ** has been moved by some outside activity (such as a btree rebalance or
@@ -58016,15 +58018,10 @@
58016 ** pTemp is not null. Regardless of pTemp, allocate a new entry
58017 ** in pPage->apOvfl[] and make it point to the cell content (either
58018 ** in pTemp or the original pCell) and also record its index.
58019 ** Allocating a new entry in pPage->aCell[] implies that
58020 ** pPage->nOverflow is incremented.
58021 **
58022 ** If nSkip is non-zero, then do not copy the first nSkip bytes of the
58023 ** cell. The caller will overwrite them after this function returns. If
58024 ** nSkip is non-zero, then pCell may not point to an invalid memory location
58025 ** (but pCell+nSkip is always valid).
58026 */
58027 static void insertCell(
58028 MemPage *pPage, /* Page into which we are copying */
58029 int i, /* New cell becomes the i-th cell of the page */
58030 u8 *pCell, /* Content of the new cell */
@@ -58037,11 +58034,10 @@
58037 int j; /* Loop counter */
58038 int end; /* First byte past the last cell pointer in data[] */
58039 int ins; /* Index in data[] where new cell pointer is inserted */
58040 int cellOffset; /* Address of first cell pointer in data[] */
58041 u8 *data; /* The content of the whole page */
58042 int nSkip = (iChild ? 4 : 0);
58043
58044 if( *pRC ) return;
58045
58046 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
58047 assert( MX_CELL(pPage->pBt)<=10921 );
@@ -58055,11 +58051,11 @@
58055 ** might be less than 8 (leaf-size + pointer) on the interior node. Hence
58056 ** the term after the || in the following assert(). */
58057 assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
58058 if( pPage->nOverflow || sz+2>pPage->nFree ){
58059 if( pTemp ){
58060 memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
58061 pCell = pTemp;
58062 }
58063 if( iChild ){
58064 put4byte(pCell, iChild);
58065 }
@@ -58084,11 +58080,11 @@
58084 ** if it returns success */
58085 assert( idx >= end+2 );
58086 assert( idx+sz <= (int)pPage->pBt->usableSize );
58087 pPage->nCell++;
58088 pPage->nFree -= (u16)(2 + sz);
58089 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
58090 if( iChild ){
58091 put4byte(&data[idx], iChild);
58092 }
58093 memmove(&data[ins+2], &data[ins], end-ins);
58094 put2byte(&data[ins], idx);
@@ -61630,11 +61626,14 @@
61630 /* If MEM_Dyn is set then Mem.xDel!=0.
61631 ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
61632 */
61633 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
61634
61635 /* MEM_Dyn may only be set if Mem.szMalloc==0 */
 
 
 
61636 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
61637
61638 /* Cannot be both MEM_Int and MEM_Real at the same time */
61639 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
61640
@@ -61766,11 +61765,12 @@
61766 **
61767 ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
61768 ** if unable to complete the resizing.
61769 */
61770 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61771 assert( szNew>=0 );
 
61772 if( pMem->szMalloc<szNew ){
61773 return sqlite3VdbeMemGrow(pMem, szNew, 0);
61774 }
61775 assert( (pMem->flags & MEM_Dyn)==0 );
61776 pMem->z = pMem->zMalloc;
@@ -62490,11 +62490,14 @@
62490 nAlloc += (enc==SQLITE_UTF8?1:2);
62491 }
62492 if( nByte>iLimit ){
62493 return SQLITE_TOOBIG;
62494 }
62495 if( sqlite3VdbeMemClearAndResize(pMem, nAlloc) ){
 
 
 
62496 return SQLITE_NOMEM;
62497 }
62498 memcpy(pMem->z, z, nAlloc);
62499 }else if( xDel==SQLITE_DYNAMIC ){
62500 sqlite3VdbeMemRelease(pMem);
@@ -62593,11 +62596,11 @@
62593 /*
62594 ** The pVal argument is known to be a value other than NULL.
62595 ** Convert it into a string with encoding enc and return a pointer
62596 ** to a zero-terminated version of that string.
62597 */
62598 SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
62599 assert( pVal!=0 );
62600 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
62601 assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
62602 assert( (pVal->flags & MEM_RowSet)==0 );
62603 assert( (pVal->flags & (MEM_Null))==0 );
@@ -64913,11 +64916,11 @@
64913 ** the call above. */
64914 }else if( pCx->pCursor ){
64915 sqlite3BtreeCloseCursor(pCx->pCursor);
64916 }
64917 #ifndef SQLITE_OMIT_VIRTUALTABLE
64918 if( pCx->pVtabCursor ){
64919 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
64920 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
64921 p->inVtabMethod = 1;
64922 pModule->xClose(pVtabCursor);
64923 p->inVtabMethod = 0;
@@ -64956,13 +64959,14 @@
64956 static void closeAllCursors(Vdbe *p){
64957 if( p->pFrame ){
64958 VdbeFrame *pFrame;
64959 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
64960 sqlite3VdbeFrameRestore(pFrame);
 
 
64961 }
64962 p->pFrame = 0;
64963 p->nFrame = 0;
64964
64965 if( p->apCsr ){
64966 int i;
64967 for(i=0; i<p->nCursor; i++){
64968 VdbeCursor *pC = p->apCsr[i];
@@ -64980,11 +64984,11 @@
64980 p->pDelFrame = pDel->pParent;
64981 sqlite3VdbeFrameDelete(pDel);
64982 }
64983
64984 /* Delete any auxdata allocations made by the VM */
64985 sqlite3VdbeDeleteAuxData(p, -1, 0);
64986 assert( p->pAuxData==0 );
64987 }
64988
64989 /*
64990 ** Clean up the VM after a single run.
@@ -65886,13 +65890,11 @@
65886 #endif
65887 assert( p->deferredMoveto );
65888 assert( p->isTable );
65889 rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
65890 if( rc ) return rc;
65891 p->lastRowid = p->movetoTarget;
65892 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
65893 p->rowidIsValid = 1;
65894 #ifdef SQLITE_TEST
65895 sqlite3_search_count++;
65896 #endif
65897 p->deferredMoveto = 0;
65898 p->cacheStatus = CACHE_STALE;
@@ -65913,10 +65915,21 @@
65913 rc = sqlite3BtreeCursorRestore(p->pCursor, &isDifferentRow);
65914 p->cacheStatus = CACHE_STALE;
65915 if( isDifferentRow ) p->nullRow = 1;
65916 return rc;
65917 }
 
 
 
 
 
 
 
 
 
 
 
65918
65919 /*
65920 ** Make sure the cursor p is ready to read or write the row to which it
65921 ** was last positioned. Return an error code if an OOM fault or I/O error
65922 ** prevents us from positioning the cursor to its correct position.
@@ -65931,11 +65944,11 @@
65931 */
65932 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor *p){
65933 if( p->deferredMoveto ){
65934 return handleDeferredMoveto(p);
65935 }
65936 if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65937 return handleMovedCursor(p);
65938 }
65939 return SQLITE_OK;
65940 }
65941
@@ -69095,10 +69108,11 @@
69095 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
69096 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
69097 memset(pCx, 0, sizeof(VdbeCursor));
69098 pCx->iDb = iDb;
69099 pCx->nField = nField;
 
69100 if( isBtreeCursor ){
69101 pCx->pCursor = (BtCursor*)
69102 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
69103 sqlite3BtreeCursorZero(pCx->pCursor);
69104 }
@@ -70528,11 +70542,11 @@
70528 ctx.pFunc = pOp->p4.pFunc;
70529 ctx.iOp = pc;
70530 ctx.pVdbe = p;
70531 MemSetTypeFlag(ctx.pOut, MEM_Null);
70532 ctx.fErrorOrAux = 0;
70533 assert( db->lastRowid==lastRowid );
70534 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
70535 lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */
70536
70537 /* If the function returned an error, throw an exception */
70538 if( ctx.fErrorOrAux ){
@@ -71246,11 +71260,11 @@
71246 memAboutToChange(p, pDest);
71247 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71248 pC = p->apCsr[pOp->p1];
71249 assert( pC!=0 );
71250 assert( p2<pC->nField );
71251 aOffset = pC->aType + pC->nField;
71252 #ifndef SQLITE_OMIT_VIRTUALTABLE
71253 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
71254 #endif
71255 pCrsr = pC->pCursor;
71256 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -71257,11 +71271,11 @@
71257 assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
71258
71259 /* If the cursor cache is stale, bring it up-to-date */
71260 rc = sqlite3VdbeCursorMoveto(pC);
71261 if( rc ) goto abort_due_to_error;
71262 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
71263 if( pC->nullRow ){
71264 if( pCrsr==0 ){
71265 assert( pC->pseudoTableReg>0 );
71266 pReg = &aMem[pC->pseudoTableReg];
71267 assert( pReg->flags & MEM_Blob );
@@ -71302,18 +71316,10 @@
71302 }
71303 pC->cacheStatus = p->cacheCtr;
71304 pC->iHdrOffset = getVarint32(pC->aRow, offset);
71305 pC->nHdrParsed = 0;
71306 aOffset[0] = offset;
71307 if( avail<offset ){
71308 /* pC->aRow does not have to hold the entire row, but it does at least
71309 ** need to cover the header of the record. If pC->aRow does not contain
71310 ** the complete header, then set it to zero, forcing the header to be
71311 ** dynamically allocated. */
71312 pC->aRow = 0;
71313 pC->szRow = 0;
71314 }
71315
71316 /* Make sure a corrupt database has not given us an oversize header.
71317 ** Do this now to avoid an oversize memory allocation.
71318 **
71319 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -71324,19 +71330,36 @@
71324 */
71325 if( offset > 98307 || offset > pC->payloadSize ){
71326 rc = SQLITE_CORRUPT_BKPT;
71327 goto op_column_error;
71328 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71329 }
71330
71331 /* Make sure at least the first p2+1 entries of the header have been
71332 ** parsed and valid information is in aOffset[] and pC->aType[].
71333 */
71334 if( pC->nHdrParsed<=p2 ){
71335 /* If there is more header available for parsing in the record, try
71336 ** to extract additional fields up through the p2+1-th field
71337 */
 
71338 if( pC->iHdrOffset<aOffset[0] ){
71339 /* Make sure zData points to enough of the record to cover the header. */
71340 if( pC->aRow==0 ){
71341 memset(&sMem, 0, sizeof(sMem));
71342 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
@@ -71377,19 +71400,20 @@
71377 if( pC->aRow==0 ){
71378 sqlite3VdbeMemRelease(&sMem);
71379 sMem.flags = MEM_Null;
71380 }
71381
71382 /* If we have read more header data than was contained in the header,
71383 ** or if the end of the last field appears to be past the end of the
71384 ** record, or if the end of the last field appears to be before the end
71385 ** of the record (when all fields present), then we must be dealing
71386 ** with a corrupt database.
 
 
71387 */
71388 if( (zHdr > zEndHdr)
71389 || (offset > pC->payloadSize)
71390 || (zHdr==zEndHdr && offset!=pC->payloadSize)
71391 ){
71392 rc = SQLITE_CORRUPT_BKPT;
71393 goto op_column_error;
71394 }
71395 }
@@ -71576,11 +71600,11 @@
71576 ** out how much space is required for the new record.
71577 */
71578 pRec = pLast;
71579 do{
71580 assert( memIsValid(pRec) );
71581 serial_type = sqlite3VdbeSerialType(pRec, file_format);
71582 len = sqlite3VdbeSerialTypeLen(serial_type);
71583 if( pRec->flags & MEM_Zero ){
71584 if( nData ){
71585 sqlite3VdbeMemExpandBlob(pRec);
71586 }else{
@@ -71625,11 +71649,11 @@
71625 i = putVarint32(zNewRecord, nHdr);
71626 j = nHdr;
71627 assert( pData0<=pLast );
71628 pRec = pData0;
71629 do{
71630 serial_type = sqlite3VdbeSerialType(pRec, file_format);
71631 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
71632 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
71633 }while( (++pRec)<=pLast );
71634 assert( i==nHdr );
71635 assert( j==nByte );
@@ -72524,11 +72548,10 @@
72524 pIn3 = &aMem[pOp->p3];
72525 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
72526 applyNumericAffinity(pIn3, 0);
72527 }
72528 iKey = sqlite3VdbeIntValue(pIn3);
72529 pC->rowidIsValid = 0;
72530
72531 /* If the P3 value could not be converted into an integer without
72532 ** loss of information, then special processing is required... */
72533 if( (pIn3->flags & MEM_Int)==0 ){
72534 if( (pIn3->flags & MEM_Real)==0 ){
@@ -72560,17 +72583,14 @@
72560 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
72561 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
72562 }
72563 }
72564 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
 
72565 if( rc!=SQLITE_OK ){
72566 goto abort_due_to_error;
72567 }
72568 if( res==0 ){
72569 pC->rowidIsValid = 1;
72570 pC->lastRowid = iKey;
72571 }
72572 }else{
72573 nField = pOp->p4.i;
72574 assert( pOp->p4type==P4_INT32 );
72575 assert( nField>0 );
72576 r.pKeyInfo = pC->pKeyInfo;
@@ -72596,11 +72616,10 @@
72596 ExpandBlob(r.aMem);
72597 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
72598 if( rc!=SQLITE_OK ){
72599 goto abort_due_to_error;
72600 }
72601 pC->rowidIsValid = 0;
72602 }
72603 pC->deferredMoveto = 0;
72604 pC->cacheStatus = CACHE_STALE;
72605 #ifdef SQLITE_TEST
72606 sqlite3_search_count++;
@@ -72608,21 +72627,19 @@
72608 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
72609 if( res<0 || (res==0 && oc==OP_SeekGT) ){
72610 res = 0;
72611 rc = sqlite3BtreeNext(pC->pCursor, &res);
72612 if( rc!=SQLITE_OK ) goto abort_due_to_error;
72613 pC->rowidIsValid = 0;
72614 }else{
72615 res = 0;
72616 }
72617 }else{
72618 assert( oc==OP_SeekLT || oc==OP_SeekLE );
72619 if( res>0 || (res==0 && oc==OP_SeekLT) ){
72620 res = 0;
72621 rc = sqlite3BtreePrevious(pC->pCursor, &res);
72622 if( rc!=SQLITE_OK ) goto abort_due_to_error;
72623 pC->rowidIsValid = 0;
72624 }else{
72625 /* res might be negative because the table is empty. Check to
72626 ** see if this is the case.
72627 */
72628 res = sqlite3BtreeEof(pC->pCursor);
@@ -72655,11 +72672,10 @@
72655 assert( pC->pCursor!=0 );
72656 assert( pC->isTable );
72657 pC->nullRow = 0;
72658 pIn2 = &aMem[pOp->p2];
72659 pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
72660 pC->rowidIsValid = 0;
72661 pC->deferredMoveto = 1;
72662 break;
72663 }
72664
72665
@@ -72841,19 +72857,17 @@
72841 pCrsr = pC->pCursor;
72842 assert( pCrsr!=0 );
72843 res = 0;
72844 iKey = pIn3->u.i;
72845 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
72846 pC->lastRowid = pIn3->u.i;
72847 pC->rowidIsValid = res==0 ?1:0;
72848 pC->nullRow = 0;
72849 pC->cacheStatus = CACHE_STALE;
72850 pC->deferredMoveto = 0;
72851 VdbeBranchTaken(res!=0,2);
72852 if( res!=0 ){
72853 pc = pOp->p2 - 1;
72854 assert( pC->rowidIsValid==0 );
72855 }
72856 pC->seekResult = res;
72857 break;
72858 }
72859
@@ -72997,11 +73011,10 @@
72997 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
72998 goto abort_due_to_error;
72999 }
73000 assert( v>0 ); /* EV: R-40812-03570 */
73001 }
73002 pC->rowidIsValid = 0;
73003 pC->deferredMoveto = 0;
73004 pC->cacheStatus = CACHE_STALE;
73005 }
73006 pOut->u.i = v;
73007 break;
@@ -73102,11 +73115,10 @@
73102 }
73103 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
73104 pData->z, pData->n, nZero,
73105 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
73106 );
73107 pC->rowidIsValid = 0;
73108 pC->deferredMoveto = 0;
73109 pC->cacheStatus = CACHE_STALE;
73110
73111 /* Invoke the update-hook if required. */
73112 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
@@ -73139,37 +73151,36 @@
73139 ** pointing to. The update hook will be invoked, if it exists.
73140 ** If P4 is not NULL then the P1 cursor must have been positioned
73141 ** using OP_NotFound prior to invoking this opcode.
73142 */
73143 case OP_Delete: {
73144 i64 iKey;
73145 VdbeCursor *pC;
73146
73147 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73148 pC = p->apCsr[pOp->p1];
73149 assert( pC!=0 );
73150 assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
73151 iKey = pC->lastRowid; /* Only used for the update hook */
73152
73153 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
73154 ** OP_Column on the same table without any intervening operations that
73155 ** might move or invalidate the cursor. Hence cursor pC is always pointing
73156 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
73157 ** below is always a no-op and cannot fail. We will run it anyhow, though,
73158 ** to guard against future changes to the code generator.
73159 **/
73160 assert( pC->deferredMoveto==0 );
73161 rc = sqlite3VdbeCursorMoveto(pC);
73162 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73163
 
 
 
 
 
 
 
 
 
 
 
73164 rc = sqlite3BtreeDelete(pC->pCursor);
73165 pC->cacheStatus = CACHE_STALE;
73166
73167 /* Invoke the update-hook if required. */
73168 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
73169 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
73170 db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
73171 assert( pC->iDb>=0 );
73172 }
73173 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
73174 break;
73175 }
@@ -73218,23 +73229,32 @@
73218 pc = pOp->p2-1;
73219 }
73220 break;
73221 };
73222
73223 /* Opcode: SorterData P1 P2 * * *
73224 ** Synopsis: r[P2]=data
73225 **
73226 ** Write into register P2 the current sorter data for sorter cursor P1.
 
 
 
 
 
 
 
73227 */
73228 case OP_SorterData: {
73229 VdbeCursor *pC;
73230
73231 pOut = &aMem[pOp->p2];
73232 pC = p->apCsr[pOp->p1];
73233 assert( isSorter(pC) );
73234 rc = sqlite3VdbeSorterRowkey(pC, pOut);
73235 assert( rc!=SQLITE_OK || (pOut->flags & MEM_Blob) );
 
 
73236 break;
73237 }
73238
73239 /* Opcode: RowData P1 P2 * * *
73240 ** Synopsis: r[P2]=data
@@ -73277,20 +73297,24 @@
73277 assert( pC!=0 );
73278 assert( pC->nullRow==0 );
73279 assert( pC->pseudoTableReg==0 );
73280 assert( pC->pCursor!=0 );
73281 pCrsr = pC->pCursor;
73282 assert( sqlite3BtreeCursorIsValid(pCrsr) );
73283
73284 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
73285 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
73286 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
73287 ** a no-op and can never fail. But we leave it in place as a safety.
 
 
73288 */
73289 assert( pC->deferredMoveto==0 );
 
 
73290 rc = sqlite3VdbeCursorMoveto(pC);
73291 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
 
73292
73293 if( pC->isTable==0 ){
73294 assert( !pC->isTable );
73295 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
73296 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
@@ -73303,11 +73327,12 @@
73303 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
73304 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
73305 goto too_big;
73306 }
73307 }
73308 if( sqlite3VdbeMemClearAndResize(pOut, n) ){
 
73309 goto no_mem;
73310 }
73311 pOut->n = n;
73312 MemSetTypeFlag(pOut, MEM_Blob);
73313 if( pC->isTable==0 ){
@@ -73354,18 +73379,14 @@
73354 rc = pModule->xRowid(pC->pVtabCursor, &v);
73355 sqlite3VtabImportErrmsg(p, pVtab);
73356 #endif /* SQLITE_OMIT_VIRTUALTABLE */
73357 }else{
73358 assert( pC->pCursor!=0 );
73359 rc = sqlite3VdbeCursorMoveto(pC);
73360 if( rc ) goto abort_due_to_error;
73361 if( pC->rowidIsValid ){
73362 v = pC->lastRowid;
73363 }else{
73364 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73365 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
73366 }
73367 }
73368 pOut->u.i = v;
73369 break;
73370 }
73371
@@ -73380,11 +73401,10 @@
73380
73381 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73382 pC = p->apCsr[pOp->p1];
73383 assert( pC!=0 );
73384 pC->nullRow = 1;
73385 pC->rowidIsValid = 0;
73386 pC->cacheStatus = CACHE_STALE;
73387 if( pC->pCursor ){
73388 sqlite3BtreeClearCursor(pC->pCursor);
73389 }
73390 break;
@@ -73414,11 +73434,10 @@
73414 res = 0;
73415 assert( pCrsr!=0 );
73416 rc = sqlite3BtreeLast(pCrsr, &res);
73417 pC->nullRow = (u8)res;
73418 pC->deferredMoveto = 0;
73419 pC->rowidIsValid = 0;
73420 pC->cacheStatus = CACHE_STALE;
73421 #ifdef SQLITE_DEBUG
73422 pC->seekOp = OP_Last;
73423 #endif
73424 if( pOp->p2>0 ){
@@ -73481,11 +73500,10 @@
73481 pCrsr = pC->pCursor;
73482 assert( pCrsr );
73483 rc = sqlite3BtreeFirst(pCrsr, &res);
73484 pC->deferredMoveto = 0;
73485 pC->cacheStatus = CACHE_STALE;
73486 pC->rowidIsValid = 0;
73487 }
73488 pC->nullRow = (u8)res;
73489 assert( pOp->p2>0 && pOp->p2<p->nOp );
73490 VdbeBranchTaken(res!=0,2);
73491 if( res ){
@@ -73607,11 +73625,10 @@
73607 sqlite3_search_count++;
73608 #endif
73609 }else{
73610 pC->nullRow = 1;
73611 }
73612 pC->rowidIsValid = 0;
73613 goto check_for_interrupt;
73614 }
73615
73616 /* Opcode: IdxInsert P1 P2 P3 * P5
73617 ** Synopsis: key=r[P2]
@@ -73723,14 +73740,20 @@
73723 pC = p->apCsr[pOp->p1];
73724 assert( pC!=0 );
73725 pCrsr = pC->pCursor;
73726 assert( pCrsr!=0 );
73727 pOut->flags = MEM_Null;
73728 rc = sqlite3VdbeCursorMoveto(pC);
73729 if( NEVER(rc) ) goto abort_due_to_error;
73730 assert( pC->deferredMoveto==0 );
73731 assert( pC->isTable==0 );
 
 
 
 
 
 
 
73732 if( !pC->nullRow ){
73733 rowid = 0; /* Not needed. Only used to silence a warning. */
73734 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
73735 if( rc!=SQLITE_OK ){
73736 goto abort_due_to_error;
@@ -87168,29 +87191,27 @@
87168 tRowcnt v;
87169
87170 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87171 if( z==0 ) z = "";
87172 #else
87173 if( NEVER(z==0) ) z = "";
87174 #endif
87175 for(i=0; *z && i<nOut; i++){
87176 v = 0;
87177 while( (c=z[0])>='0' && c<='9' ){
87178 v = v*10 + c - '0';
87179 z++;
87180 }
87181 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87182 if( aOut ){
87183 aOut[i] = v;
87184 }else
87185 #else
87186 assert( aOut==0 );
87187 UNUSED_PARAMETER(aOut);
 
 
87188 #endif
87189 {
87190 aLog[i] = sqlite3LogEst(v);
87191 }
87192 if( *z==' ' ) z++;
87193 }
87194 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
87195 assert( pIndex!=0 );
87196 #else
@@ -87247,12 +87268,21 @@
87247 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
87248 }
87249 z = argv[2];
87250
87251 if( pIndex ){
 
 
 
 
 
 
 
 
 
87252 pIndex->bUnordered = 0;
87253 decodeIntArray((char*)z, pIndex->nKeyCol+1, 0, pIndex->aiRowLogEst, pIndex);
87254 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
87255 }else{
87256 Index fakeIdx;
87257 fakeIdx.szIdxRow = pTable->szTabRow;
87258 #ifdef SQLITE_ENABLE_COSTMULT
@@ -87307,29 +87337,42 @@
87307 ** unique. */
87308 nCol = pIdx->nSampleCol-1;
87309 pIdx->aAvgEq[nCol] = 1;
87310 }
87311 for(iCol=0; iCol<nCol; iCol++){
 
87312 int i; /* Used to iterate through samples */
87313 tRowcnt sumEq = 0; /* Sum of the nEq values */
87314 tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
87315 tRowcnt avgEq = 0;
87316 tRowcnt nDLt = pFinal->anDLt[iCol];
 
 
 
 
 
 
 
 
 
 
 
87317
87318 /* Set nSum to the number of distinct (iCol+1) field prefixes that
87319 ** occur in the stat4 table for this index before pFinal. Set
87320 ** sumEq to the sum of the nEq values for column iCol for the same
87321 ** set (adding the value only once where there exist duplicate
87322 ** prefixes). */
87323 for(i=0; i<(pIdx->nSample-1); i++){
87324 if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
 
87325 sumEq += aSample[i].anEq[iCol];
87326 nSum++;
87327 }
87328 }
87329 if( nDLt>nSum ){
87330 avgEq = (pFinal->anLt[iCol] - sumEq)/(nDLt - nSum);
 
87331 }
87332 if( avgEq==0 ) avgEq = 1;
87333 pIdx->aAvgEq[iCol] = avgEq;
87334 }
87335 }
@@ -87576,10 +87619,15 @@
87576 if( rc==SQLITE_OK ){
87577 int lookasideEnabled = db->lookaside.bEnabled;
87578 db->lookaside.bEnabled = 0;
87579 rc = loadStat4(db, sInfo.zDatabase);
87580 db->lookaside.bEnabled = lookasideEnabled;
 
 
 
 
 
87581 }
87582 #endif
87583
87584 if( rc==SQLITE_NOMEM ){
87585 db->mallocFailed = 1;
@@ -88870,10 +88918,13 @@
88870 #endif
88871 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
88872 sqlite3ExprDelete(db, p->pPartIdxWhere);
88873 sqlite3DbFree(db, p->zColAff);
88874 if( p->isResized ) sqlite3DbFree(db, p->azColl);
 
 
 
88875 sqlite3DbFree(db, p);
88876 }
88877
88878 /*
88879 ** For the index called zIdxName which is found in the database iDb,
@@ -91179,11 +91230,11 @@
91179 pIndex->nKeyCol); VdbeCoverage(v);
91180 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
91181 }else{
91182 addr2 = sqlite3VdbeCurrentAddr(v);
91183 }
91184 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
91185 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
91186 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
91187 sqlite3ReleaseTempReg(pParse, regRecord);
91188 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
91189 sqlite3VdbeJumpHere(v, addr1);
@@ -105122,11 +105173,10 @@
105122 int regRow;
105123 int regRowid;
105124 int nKey;
105125 int iSortTab; /* Sorter cursor to read from */
105126 int nSortData; /* Trailing values to read from sorter */
105127 u8 p5; /* p5 parameter for 1st OP_Column */
105128 int i;
105129 int bSeq; /* True if sorter record includes seq. no. */
105130 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
105131 struct ExprList_item *aOutEx = p->pEList->a;
105132 #endif
@@ -105156,23 +105206,20 @@
105156 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
105157 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
105158 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
105159 VdbeCoverage(v);
105160 codeOffset(v, p->iOffset, addrContinue);
105161 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
105162 p5 = OPFLAG_CLEARCACHE;
105163 bSeq = 0;
105164 }else{
105165 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
105166 codeOffset(v, p->iOffset, addrContinue);
105167 iSortTab = iTab;
105168 p5 = 0;
105169 bSeq = 1;
105170 }
105171 for(i=0; i<nSortData; i++){
105172 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
105173 if( i==0 ) sqlite3VdbeChangeP5(v, p5);
105174 VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
105175 }
105176 switch( eDest ){
105177 case SRT_Table:
105178 case SRT_EphemTab: {
@@ -109097,16 +109144,15 @@
109097 ** from the previous row currently stored in a0, a1, a2...
109098 */
109099 addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
109100 sqlite3ExprCacheClear(pParse);
109101 if( groupBySort ){
109102 sqlite3VdbeAddOp2(v, OP_SorterData, sAggInfo.sortingIdx, sortOut);
109103 }
109104 for(j=0; j<pGroupBy->nExpr; j++){
109105 if( groupBySort ){
109106 sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
109107 if( j==0 ) sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
109108 }else{
109109 sAggInfo.directMode = 1;
109110 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
109111 }
109112 }
@@ -112450,10 +112496,11 @@
112450 }
112451 sqlite3DbFree(db, pVTable);
112452 }else if( ALWAYS(pVTable->pVtab) ){
112453 /* Justification of ALWAYS(): A correct vtab constructor must allocate
112454 ** the sqlite3_vtab object if successful. */
 
112455 pVTable->pVtab->pModule = pMod->pModule;
112456 pVTable->nRef = 1;
112457 if( sCtx.pTab ){
112458 const char *zFormat = "vtable constructor did not declare schema: %s";
112459 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
@@ -115700,21 +115747,28 @@
115700 ** have been requested when testing key $P in whereEqualScanEst(). */
115701 whereKeyStats(pParse, p, pRec, 0, a);
115702 iLower = a[0];
115703 iUpper = a[0] + a[1];
115704 }
 
 
 
 
 
 
 
 
115705
115706 /* If possible, improve on the iLower estimate using ($P:$L). */
115707 if( pLower ){
115708 int bOk; /* True if value is extracted from pExpr */
115709 Expr *pExpr = pLower->pExpr->pRight;
115710 assert( (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115711 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115712 if( rc==SQLITE_OK && bOk ){
115713 tRowcnt iNew;
115714 whereKeyStats(pParse, p, pRec, 0, a);
115715 iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
115716 if( iNew>iLower ) iLower = iNew;
115717 nOut--;
115718 pLower = 0;
115719 }
115720 }
@@ -115721,16 +115775,15 @@
115721
115722 /* If possible, improve on the iUpper estimate using ($P:$U). */
115723 if( pUpper ){
115724 int bOk; /* True if value is extracted from pExpr */
115725 Expr *pExpr = pUpper->pExpr->pRight;
115726 assert( (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115727 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115728 if( rc==SQLITE_OK && bOk ){
115729 tRowcnt iNew;
115730 whereKeyStats(pParse, p, pRec, 1, a);
115731 iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
115732 if( iNew<iUpper ) iUpper = iNew;
115733 nOut--;
115734 pUpper = 0;
115735 }
115736 }
@@ -116225,65 +116278,52 @@
116225 sqlite3StrAccumAppend(pStr, "?", 1);
116226 }
116227
116228 /*
116229 ** Argument pLevel describes a strategy for scanning table pTab. This
116230 ** function returns a pointer to a string buffer containing a description
116231 ** of the subset of table rows scanned by the strategy in the form of an
116232 ** SQL expression. Or, if all rows are scanned, NULL is returned.
116233 **
116234 ** For example, if the query:
116235 **
116236 ** SELECT * FROM t1 WHERE a=1 AND b>2;
116237 **
116238 ** is run and there is an index on (a, b), then this function returns a
116239 ** string similar to:
116240 **
116241 ** "a=? AND b>?"
116242 **
116243 ** The returned pointer points to memory obtained from sqlite3DbMalloc().
116244 ** It is the responsibility of the caller to free the buffer when it is
116245 ** no longer required.
116246 */
116247 static char *explainIndexRange(sqlite3 *db, WhereLoop *pLoop, Table *pTab){
116248 Index *pIndex = pLoop->u.btree.pIndex;
116249 u16 nEq = pLoop->u.btree.nEq;
116250 u16 nSkip = pLoop->u.btree.nSkip;
116251 int i, j;
116252 Column *aCol = pTab->aCol;
116253 i16 *aiColumn = pIndex->aiColumn;
116254 StrAccum txt;
116255
116256 if( nEq==0 && (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ){
116257 return 0;
116258 }
116259 sqlite3StrAccumInit(&txt, 0, 0, SQLITE_MAX_LENGTH);
116260 txt.db = db;
116261 sqlite3StrAccumAppend(&txt, " (", 2);
116262 for(i=0; i<nEq; i++){
116263 char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
116264 if( i>=nSkip ){
116265 explainAppendTerm(&txt, i, z, "=");
116266 }else{
116267 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
116268 sqlite3StrAccumAppend(&txt, "ANY(", 4);
116269 sqlite3StrAccumAppendAll(&txt, z);
116270 sqlite3StrAccumAppend(&txt, ")", 1);
116271 }
116272 }
116273
116274 j = i;
116275 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
116276 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116277 explainAppendTerm(&txt, i++, z, ">");
116278 }
116279 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
116280 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116281 explainAppendTerm(&txt, i, z, "<");
116282 }
116283 sqlite3StrAccumAppend(&txt, ")", 1);
116284 return sqlite3StrAccumFinish(&txt);
116285 }
116286
116287 /*
116288 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116289 ** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
@@ -116303,72 +116343,90 @@
116303 #endif
116304 {
116305 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116306 Vdbe *v = pParse->pVdbe; /* VM being constructed */
116307 sqlite3 *db = pParse->db; /* Database handle */
116308 char *zMsg; /* Text to add to EQP output */
116309 int iId = pParse->iSelectId; /* Select id (left-most output column) */
116310 int isSearch; /* True for a SEARCH. False for SCAN. */
116311 WhereLoop *pLoop; /* The controlling WhereLoop object */
116312 u32 flags; /* Flags that describe this loop */
 
 
 
116313
116314 pLoop = pLevel->pWLoop;
116315 flags = pLoop->wsFlags;
116316 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116317
116318 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116319 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116320 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116321
116322 zMsg = sqlite3MPrintf(db, "%s", isSearch?"SEARCH":"SCAN");
 
 
116323 if( pItem->pSelect ){
116324 zMsg = sqlite3MAppendf(db, zMsg, "%s SUBQUERY %d", zMsg,pItem->iSelectId);
116325 }else{
116326 zMsg = sqlite3MAppendf(db, zMsg, "%s TABLE %s", zMsg, pItem->zName);
116327 }
116328
116329 if( pItem->zAlias ){
116330 zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
116331 }
116332 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0
116333 && ALWAYS(pLoop->u.btree.pIndex!=0)
116334 ){
116335 const char *zFmt;
116336 Index *pIdx = pLoop->u.btree.pIndex;
116337 char *zWhere = explainIndexRange(db, pLoop, pItem->pTab);
116338 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116339 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116340 zFmt = zWhere ? "%s USING PRIMARY KEY%.0s%s" : "%s%.0s%s";
 
 
116341 }else if( flags & WHERE_AUTO_INDEX ){
116342 zFmt = "%s USING AUTOMATIC COVERING INDEX%.0s%s";
116343 }else if( flags & WHERE_IDX_ONLY ){
116344 zFmt = "%s USING COVERING INDEX %s%s";
116345 }else{
116346 zFmt = "%s USING INDEX %s%s";
116347 }
116348 zMsg = sqlite3MAppendf(db, zMsg, zFmt, zMsg, pIdx->zName, zWhere);
116349 sqlite3DbFree(db, zWhere);
 
 
 
116350 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
116351 zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg);
116352
116353 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
116354 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid=?)", zMsg);
116355 }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
116356 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>? AND rowid<?)", zMsg);
116357 }else if( flags&WHERE_BTM_LIMIT ){
116358 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid>?)", zMsg);
116359 }else if( ALWAYS(flags&WHERE_TOP_LIMIT) ){
116360 zMsg = sqlite3MAppendf(db, zMsg, "%s (rowid<?)", zMsg);
 
116361 }
 
 
116362 }
116363 #ifndef SQLITE_OMIT_VIRTUALTABLE
116364 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
116365 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
116366 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
116367 }
116368 #endif
116369 zMsg = sqlite3MAppendf(db, zMsg, "%s", zMsg);
 
 
 
 
 
 
 
116370 sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116371 }
116372 }
116373 #else
116374 # define explainOneScan(u,v,w,x,y,z)
@@ -117633,11 +117691,11 @@
117633 if( ppPrev==0 ){
117634 /* There already exists a WhereLoop on the list that is better
117635 ** than pTemplate, so just ignore pTemplate */
117636 #if WHERETRACE_ENABLED /* 0x8 */
117637 if( sqlite3WhereTrace & 0x8 ){
117638 sqlite3DebugPrintf("ins-noop: ");
117639 whereLoopPrint(pTemplate, pBuilder->pWC);
117640 }
117641 #endif
117642 return SQLITE_OK;
117643 }else{
@@ -117649,14 +117707,14 @@
117649 ** WhereLoop and insert it.
117650 */
117651 #if WHERETRACE_ENABLED /* 0x8 */
117652 if( sqlite3WhereTrace & 0x8 ){
117653 if( p!=0 ){
117654 sqlite3DebugPrintf("ins-del: ");
117655 whereLoopPrint(p, pBuilder->pWC);
117656 }
117657 sqlite3DebugPrintf("ins-new: ");
117658 whereLoopPrint(pTemplate, pBuilder->pWC);
117659 }
117660 #endif
117661 if( p==0 ){
117662 /* Allocate a new WhereLoop to add to the end of the list */
@@ -117676,11 +117734,11 @@
117676 pToDel = *ppTail;
117677 if( pToDel==0 ) break;
117678 *ppTail = pToDel->pNextLoop;
117679 #if WHERETRACE_ENABLED /* 0x8 */
117680 if( sqlite3WhereTrace & 0x8 ){
117681 sqlite3DebugPrintf("ins-del: ");
117682 whereLoopPrint(pToDel, pBuilder->pWC);
117683 }
117684 #endif
117685 whereLoopDelete(db, pToDel);
117686 }
@@ -118843,11 +118901,11 @@
118843 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
118844 }
118845 isMatch = 1;
118846 break;
118847 }
118848 if( isMatch && (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
118849 /* Make sure the sort order is compatible in an ORDER BY clause.
118850 ** Sort order is irrelevant for a GROUP BY clause. */
118851 if( revSet ){
118852 if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;
118853 }else{
@@ -119308,16 +119366,19 @@
119308 pWInfo->revMask = pFrom->revLoop;
119309 }
119310 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
119311 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
119312 ){
119313 Bitmask notUsed = 0;
119314 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
119315 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed
119316 );
119317 assert( pWInfo->sorted==0 );
119318 pWInfo->sorted = (nOrder==pWInfo->pOrderBy->nExpr);
 
 
 
119319 }
119320 }
119321
119322
119323 pWInfo->nRowOut = pFrom->nRow;
@@ -132620,10 +132681,11 @@
132620 assert( iIdx==nVal );
132621
132622 /* In case the cursor has been used before, clear it now. */
132623 sqlite3_finalize(pCsr->pStmt);
132624 sqlite3_free(pCsr->aDoclist);
 
132625 sqlite3Fts3ExprFree(pCsr->pExpr);
132626 memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
132627
132628 /* Set the lower and upper bounds on docids to return */
132629 pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
@@ -133930,11 +133992,11 @@
133930 if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
133931 iMax = a[i].iDocid;
133932 bMaxSet = 1;
133933 }
133934 }
133935 assert( rc!=SQLITE_OK || a[p->nToken-1].bIgnore==0 );
133936 assert( rc!=SQLITE_OK || bMaxSet );
133937
133938 /* Keep advancing iterators until they all point to the same document */
133939 for(i=0; i<p->nToken; i++){
133940 while( rc==SQLITE_OK && bEof==0
@@ -136047,11 +136109,11 @@
136047 int i = 0;
136048
136049 /* Set variable i to the maximum number of bytes of input to tokenize. */
136050 for(i=0; i<n; i++){
136051 if( sqlite3_fts3_enable_parentheses && (z[i]=='(' || z[i]==')') ) break;
136052 if( z[i]=='*' || z[i]=='"' ) break;
136053 }
136054
136055 *pnConsumed = i;
136056 rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
136057 if( rc==SQLITE_OK ){
136058
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -231,11 +231,11 @@
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.7"
235 #define SQLITE_VERSION_NUMBER 3008007
236 #define SQLITE_SOURCE_ID "2014-10-14 20:25:43 eab82330631187dcc3e5d2dddd23dbda5752904b"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -7944,11 +7944,11 @@
7944 ** A macro to hint to the compiler that a function should not be
7945 ** inlined.
7946 */
7947 #if defined(__GNUC__)
7948 # define SQLITE_NOINLINE __attribute__((noinline))
7949 #elif defined(_MSC_VER) && _MSC_VER>=1310
7950 # define SQLITE_NOINLINE __declspec(noinline)
7951 #else
7952 # define SQLITE_NOINLINE
7953 #endif
7954
@@ -11322,10 +11322,11 @@
11322 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11323 int nSample; /* Number of elements in aSample[] */
11324 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11325 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11326 IndexSample *aSample; /* Samples of the left-most key */
11327 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
11328 #endif
11329 };
11330
11331 /*
11332 ** Allowed values for Index.idxType
@@ -12186,11 +12187,10 @@
12187 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
12188 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
12189 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
12190 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
12191 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
 
12192 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
12193 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
12194 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
12195 #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
12196 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
@@ -13320,14 +13320,13 @@
13320 # define sqlite3MemdebugSetType(X,Y) /* no-op */
13321 # define sqlite3MemdebugHasType(X,Y) 1
13322 # define sqlite3MemdebugNoType(X,Y) 1
13323 #endif
13324 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
13325 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
13326 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
13327 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
 
13328
13329 /*
13330 ** Threading interface
13331 */
13332 #if SQLITE_MAX_WORKER_THREADS>0
@@ -14095,21 +14094,19 @@
14094 #ifdef SQLITE_DEBUG
14095 u8 seekOp; /* Most recent seek operation on this cursor */
14096 #endif
14097 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
14098 u8 nullRow; /* True if pointing to a row with no data */
 
14099 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
14100 Bool isEphemeral:1; /* True for an ephemeral table */
14101 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
14102 Bool isTable:1; /* True if a table requiring integer keys */
14103 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
14104 Pgno pgnoRoot; /* Root page of the open btree cursor */
14105 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
14106 i64 seqCount; /* Sequence counter */
14107 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
 
14108 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
14109
14110 /* Cached information about the header for the data record that the
14111 ** cursor is currently pointing to. Only valid if cacheStatus matches
14112 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
@@ -14122,10 +14119,11 @@
14119 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
14120 u32 payloadSize; /* Total number of bytes in the record */
14121 u32 szRow; /* Byte available in aRow */
14122 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
14123 const u8 *aRow; /* Data for the current row, if all on one page */
14124 u32 *aOffset; /* Pointer to aType[nField] */
14125 u32 aType[1]; /* Type values for all entries in the record */
14126 /* 2*nField extra array elements allocated for aType[], beyond the one
14127 ** static element declared in the structure. nField total array slots for
14128 ** aType[] and nField+1 array slots for aOffset[] */
14129 };
@@ -14198,11 +14196,11 @@
14196 int n; /* Number of characters in string value, excluding '\0' */
14197 char *z; /* String or BLOB value */
14198 /* ShallowCopy only needs to copy the information above */
14199 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14200 int szMalloc; /* Size of the zMalloc allocation */
14201 u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
14202 sqlite3 *db; /* The associated database connection */
14203 void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
14204 #ifdef SQLITE_DEBUG
14205 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
14206 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
@@ -14406,10 +14404,11 @@
14404 ** Function prototypes
14405 */
14406 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
14407 void sqliteVdbePopStack(Vdbe*,int);
14408 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor*);
14409 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*);
14410 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
14411 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
14412 #endif
14413 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
14414 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
@@ -17130,11 +17129,11 @@
17129 ** allocation p. Also return true if p==NULL.
17130 **
17131 ** This routine is designed for use within an assert() statement, to
17132 ** verify the type of an allocation. For example:
17133 **
17134 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
17135 */
17136 SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
17137 int rc = 1;
17138 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17139 struct MemBlockHdr *pHdr;
@@ -17152,11 +17151,11 @@
17151 ** allocation p. Also return true if p==NULL.
17152 **
17153 ** This routine is designed for use within an assert() statement, to
17154 ** verify the type of an allocation. For example:
17155 **
17156 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
17157 */
17158 SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
17159 int rc = 1;
17160 if( p && sqlite3GlobalConfig.m.xMalloc==sqlite3MemMalloc ){
17161 struct MemBlockHdr *pHdr;
@@ -20364,39 +20363,41 @@
20363 ** Return the size of a memory allocation previously obtained from
20364 ** sqlite3Malloc() or sqlite3_malloc().
20365 */
20366 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
20367 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 
20368 return sqlite3GlobalConfig.m.xSize(p);
20369 }
20370 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20371 if( db==0 ){
20372 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20373 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20374 return sqlite3MallocSize(p);
20375 }else{
20376 assert( sqlite3_mutex_held(db->mutex) );
20377 if( isLookaside(db, p) ){
20378 return db->lookaside.sz;
20379 }else{
20380 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20381 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 
20382 return sqlite3GlobalConfig.m.xSize(p);
20383 }
20384 }
20385 }
20386 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20387 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20388 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20389 return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20390 }
20391
20392 /*
20393 ** Free memory previously obtained from sqlite3Malloc().
20394 */
20395 SQLITE_API void sqlite3_free(void *p){
20396 if( p==0 ) return; /* IMP: R-49053-54554 */
 
20397 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20398 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20399 if( sqlite3GlobalConfig.bMemstat ){
20400 sqlite3_mutex_enter(mem0.mutex);
20401 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
20402 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20403 sqlite3GlobalConfig.m.xFree(p);
@@ -20436,12 +20437,12 @@
20437 db->lookaside.pFree = pBuf;
20438 db->lookaside.nOut--;
20439 return;
20440 }
20441 }
20442 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20443 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20444 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20445 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20446 sqlite3_free(p);
20447 }
20448
@@ -20449,10 +20450,12 @@
20450 ** Change the size of an existing memory allocation
20451 */
20452 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
20453 int nOld, nNew, nDiff;
20454 void *pNew;
20455 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20456 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20457 if( pOld==0 ){
20458 return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
20459 }
20460 if( nBytes==0 ){
20461 sqlite3_free(pOld); /* IMP: R-26507-47431 */
@@ -20475,12 +20478,10 @@
20478 nDiff = nNew - nOld;
20479 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
20480 mem0.alarmThreshold-nDiff ){
20481 sqlite3MallocAlarm(nDiff);
20482 }
 
 
20483 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20484 if( pNew==0 && mem0.alarmCallback ){
20485 sqlite3MallocAlarm((int)nBytes);
20486 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20487 }
@@ -20589,12 +20590,12 @@
20590 #endif
20591 p = sqlite3Malloc(n);
20592 if( !p && db ){
20593 db->mallocFailed = 1;
20594 }
20595 sqlite3MemdebugSetType(p,
20596 (db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
20597 return p;
20598 }
20599
20600 /*
20601 ** Resize the block of memory pointed to by p to n bytes. If the
@@ -20616,19 +20617,18 @@
20617 if( pNew ){
20618 memcpy(pNew, p, db->lookaside.sz);
20619 sqlite3DbFree(db, p);
20620 }
20621 }else{
20622 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20623 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20624 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20625 pNew = sqlite3_realloc64(p, n);
20626 if( !pNew ){
 
20627 db->mallocFailed = 1;
20628 }
20629 sqlite3MemdebugSetType(pNew,
20630 (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
20631 }
20632 }
20633 return pNew;
20634 }
@@ -22098,11 +22098,11 @@
22098 #define SQLITE_THREADS_IMPLEMENTED 1 /* Prevent the single-thread code below */
22099 #include <process.h>
22100
22101 /* A running thread */
22102 struct SQLiteThread {
22103 void *tid; /* The thread handle */
22104 unsigned id; /* The thread identifier */
22105 void *(*xTask)(void*); /* The routine to run as a thread */
22106 void *pIn; /* Argument to xTask */
22107 void *pResult; /* Result of xTask */
22108 };
@@ -22146,11 +22146,11 @@
22146 if( sqlite3GlobalConfig.bCoreMutex==0 ){
22147 memset(p, 0, sizeof(*p));
22148 }else{
22149 p->xTask = xTask;
22150 p->pIn = pIn;
22151 p->tid = (void*)_beginthreadex(0, 0, sqlite3ThreadProc, p, 0, &p->id);
22152 if( p->tid==0 ){
22153 memset(p, 0, sizeof(*p));
22154 }
22155 }
22156 if( p->xTask==0 ){
@@ -39855,11 +39855,11 @@
39855 assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
39856 assert( pCache->n90pct == pCache->nMax*9/10 );
39857 if( createFlag==1 && (
39858 nPinned>=pGroup->mxPinned
39859 || nPinned>=pCache->n90pct
39860 || (pcache1UnderMemoryPressure(pCache) && pCache->nRecyclable<nPinned)
39861 )){
39862 return 0;
39863 }
39864
39865 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
@@ -44476,17 +44476,19 @@
44476 if( !pNew ) rc = SQLITE_NOMEM;
44477 }
44478
44479 if( rc==SQLITE_OK ){
44480 pager_reset(pPager);
 
 
44481 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
44482 }
44483 if( rc==SQLITE_OK ){
44484 sqlite3PageFree(pPager->pTmpSpace);
44485 pPager->pTmpSpace = pNew;
44486 pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize);
44487 pPager->pageSize = pageSize;
44488 }else{
44489 sqlite3PageFree(pNew);
44490 }
44491 }
44492
44493 *pPageSize = pPager->pageSize;
44494 if( rc==SQLITE_OK ){
@@ -52947,11 +52949,11 @@
52949 **
52950 ** Use the separate sqlite3BtreeCursorRestore() routine to restore a cursor
52951 ** back to where it ought to be if this routine returns true.
52952 */
52953 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
52954 return pCur->eState!=CURSOR_VALID;
52955 }
52956
52957 /*
52958 ** This routine restores a cursor back to its original position after it
52959 ** has been moved by some outside activity (such as a btree rebalance or
@@ -58016,15 +58018,10 @@
58018 ** pTemp is not null. Regardless of pTemp, allocate a new entry
58019 ** in pPage->apOvfl[] and make it point to the cell content (either
58020 ** in pTemp or the original pCell) and also record its index.
58021 ** Allocating a new entry in pPage->aCell[] implies that
58022 ** pPage->nOverflow is incremented.
 
 
 
 
 
58023 */
58024 static void insertCell(
58025 MemPage *pPage, /* Page into which we are copying */
58026 int i, /* New cell becomes the i-th cell of the page */
58027 u8 *pCell, /* Content of the new cell */
@@ -58037,11 +58034,10 @@
58034 int j; /* Loop counter */
58035 int end; /* First byte past the last cell pointer in data[] */
58036 int ins; /* Index in data[] where new cell pointer is inserted */
58037 int cellOffset; /* Address of first cell pointer in data[] */
58038 u8 *data; /* The content of the whole page */
 
58039
58040 if( *pRC ) return;
58041
58042 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
58043 assert( MX_CELL(pPage->pBt)<=10921 );
@@ -58055,11 +58051,11 @@
58051 ** might be less than 8 (leaf-size + pointer) on the interior node. Hence
58052 ** the term after the || in the following assert(). */
58053 assert( sz==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
58054 if( pPage->nOverflow || sz+2>pPage->nFree ){
58055 if( pTemp ){
58056 memcpy(pTemp, pCell, sz);
58057 pCell = pTemp;
58058 }
58059 if( iChild ){
58060 put4byte(pCell, iChild);
58061 }
@@ -58084,11 +58080,11 @@
58080 ** if it returns success */
58081 assert( idx >= end+2 );
58082 assert( idx+sz <= (int)pPage->pBt->usableSize );
58083 pPage->nCell++;
58084 pPage->nFree -= (u16)(2 + sz);
58085 memcpy(&data[idx], pCell, sz);
58086 if( iChild ){
58087 put4byte(&data[idx], iChild);
58088 }
58089 memmove(&data[ins+2], &data[ins], end-ins);
58090 put2byte(&data[ins], idx);
@@ -61630,11 +61626,14 @@
61626 /* If MEM_Dyn is set then Mem.xDel!=0.
61627 ** Mem.xDel is might not be initialized if MEM_Dyn is clear.
61628 */
61629 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
61630
61631 /* MEM_Dyn may only be set if Mem.szMalloc==0. In this way we
61632 ** ensure that if Mem.szMalloc>0 then it is safe to do
61633 ** Mem.z = Mem.zMalloc without having to check Mem.flags&MEM_Dyn.
61634 ** That saves a few cycles in inner loops. */
61635 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
61636
61637 /* Cannot be both MEM_Int and MEM_Real at the same time */
61638 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
61639
@@ -61766,11 +61765,12 @@
61765 **
61766 ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
61767 ** if unable to complete the resizing.
61768 */
61769 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
61770 assert( szNew>0 );
61771 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
61772 if( pMem->szMalloc<szNew ){
61773 return sqlite3VdbeMemGrow(pMem, szNew, 0);
61774 }
61775 assert( (pMem->flags & MEM_Dyn)==0 );
61776 pMem->z = pMem->zMalloc;
@@ -62490,11 +62490,14 @@
62490 nAlloc += (enc==SQLITE_UTF8?1:2);
62491 }
62492 if( nByte>iLimit ){
62493 return SQLITE_TOOBIG;
62494 }
62495 testcase( nAlloc==0 );
62496 testcase( nAlloc==31 );
62497 testcase( nAlloc==32 );
62498 if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
62499 return SQLITE_NOMEM;
62500 }
62501 memcpy(pMem->z, z, nAlloc);
62502 }else if( xDel==SQLITE_DYNAMIC ){
62503 sqlite3VdbeMemRelease(pMem);
@@ -62593,11 +62596,11 @@
62596 /*
62597 ** The pVal argument is known to be a value other than NULL.
62598 ** Convert it into a string with encoding enc and return a pointer
62599 ** to a zero-terminated version of that string.
62600 */
62601 static SQLITE_NOINLINE const void *valueToText(sqlite3_value* pVal, u8 enc){
62602 assert( pVal!=0 );
62603 assert( pVal->db==0 || sqlite3_mutex_held(pVal->db->mutex) );
62604 assert( (enc&3)==(enc&~SQLITE_UTF16_ALIGNED) );
62605 assert( (pVal->flags & MEM_RowSet)==0 );
62606 assert( (pVal->flags & (MEM_Null))==0 );
@@ -64913,11 +64916,11 @@
64916 ** the call above. */
64917 }else if( pCx->pCursor ){
64918 sqlite3BtreeCloseCursor(pCx->pCursor);
64919 }
64920 #ifndef SQLITE_OMIT_VIRTUALTABLE
64921 else if( pCx->pVtabCursor ){
64922 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
64923 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
64924 p->inVtabMethod = 1;
64925 pModule->xClose(pVtabCursor);
64926 p->inVtabMethod = 0;
@@ -64956,13 +64959,14 @@
64959 static void closeAllCursors(Vdbe *p){
64960 if( p->pFrame ){
64961 VdbeFrame *pFrame;
64962 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
64963 sqlite3VdbeFrameRestore(pFrame);
64964 p->pFrame = 0;
64965 p->nFrame = 0;
64966 }
64967 assert( p->nFrame==0 );
 
64968
64969 if( p->apCsr ){
64970 int i;
64971 for(i=0; i<p->nCursor; i++){
64972 VdbeCursor *pC = p->apCsr[i];
@@ -64980,11 +64984,11 @@
64984 p->pDelFrame = pDel->pParent;
64985 sqlite3VdbeFrameDelete(pDel);
64986 }
64987
64988 /* Delete any auxdata allocations made by the VM */
64989 if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p, -1, 0);
64990 assert( p->pAuxData==0 );
64991 }
64992
64993 /*
64994 ** Clean up the VM after a single run.
@@ -65886,13 +65890,11 @@
65890 #endif
65891 assert( p->deferredMoveto );
65892 assert( p->isTable );
65893 rc = sqlite3BtreeMovetoUnpacked(p->pCursor, 0, p->movetoTarget, 0, &res);
65894 if( rc ) return rc;
 
65895 if( res!=0 ) return SQLITE_CORRUPT_BKPT;
 
65896 #ifdef SQLITE_TEST
65897 sqlite3_search_count++;
65898 #endif
65899 p->deferredMoveto = 0;
65900 p->cacheStatus = CACHE_STALE;
@@ -65913,10 +65915,21 @@
65915 rc = sqlite3BtreeCursorRestore(p->pCursor, &isDifferentRow);
65916 p->cacheStatus = CACHE_STALE;
65917 if( isDifferentRow ) p->nullRow = 1;
65918 return rc;
65919 }
65920
65921 /*
65922 ** Check to ensure that the cursor is valid. Restore the cursor
65923 ** if need be. Return any I/O error from the restore operation.
65924 */
65925 SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){
65926 if( sqlite3BtreeCursorHasMoved(p->pCursor) ){
65927 return handleMovedCursor(p);
65928 }
65929 return SQLITE_OK;
65930 }
65931
65932 /*
65933 ** Make sure the cursor p is ready to read or write the row to which it
65934 ** was last positioned. Return an error code if an OOM fault or I/O error
65935 ** prevents us from positioning the cursor to its correct position.
@@ -65931,11 +65944,11 @@
65944 */
65945 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor *p){
65946 if( p->deferredMoveto ){
65947 return handleDeferredMoveto(p);
65948 }
65949 if( p->pCursor && sqlite3BtreeCursorHasMoved(p->pCursor) ){
65950 return handleMovedCursor(p);
65951 }
65952 return SQLITE_OK;
65953 }
65954
@@ -69095,10 +69108,11 @@
69108 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
69109 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
69110 memset(pCx, 0, sizeof(VdbeCursor));
69111 pCx->iDb = iDb;
69112 pCx->nField = nField;
69113 pCx->aOffset = &pCx->aType[nField];
69114 if( isBtreeCursor ){
69115 pCx->pCursor = (BtCursor*)
69116 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
69117 sqlite3BtreeCursorZero(pCx->pCursor);
69118 }
@@ -70528,11 +70542,11 @@
70542 ctx.pFunc = pOp->p4.pFunc;
70543 ctx.iOp = pc;
70544 ctx.pVdbe = p;
70545 MemSetTypeFlag(ctx.pOut, MEM_Null);
70546 ctx.fErrorOrAux = 0;
70547 db->lastRowid = lastRowid;
70548 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
70549 lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */
70550
70551 /* If the function returned an error, throw an exception */
70552 if( ctx.fErrorOrAux ){
@@ -71246,11 +71260,11 @@
71260 memAboutToChange(p, pDest);
71261 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71262 pC = p->apCsr[pOp->p1];
71263 assert( pC!=0 );
71264 assert( p2<pC->nField );
71265 aOffset = pC->aOffset;
71266 #ifndef SQLITE_OMIT_VIRTUALTABLE
71267 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
71268 #endif
71269 pCrsr = pC->pCursor;
71270 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
@@ -71257,11 +71271,11 @@
71271 assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
71272
71273 /* If the cursor cache is stale, bring it up-to-date */
71274 rc = sqlite3VdbeCursorMoveto(pC);
71275 if( rc ) goto abort_due_to_error;
71276 if( pC->cacheStatus!=p->cacheCtr ){
71277 if( pC->nullRow ){
71278 if( pCrsr==0 ){
71279 assert( pC->pseudoTableReg>0 );
71280 pReg = &aMem[pC->pseudoTableReg];
71281 assert( pReg->flags & MEM_Blob );
@@ -71302,18 +71316,10 @@
71316 }
71317 pC->cacheStatus = p->cacheCtr;
71318 pC->iHdrOffset = getVarint32(pC->aRow, offset);
71319 pC->nHdrParsed = 0;
71320 aOffset[0] = offset;
 
 
 
 
 
 
 
 
71321
71322 /* Make sure a corrupt database has not given us an oversize header.
71323 ** Do this now to avoid an oversize memory allocation.
71324 **
71325 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -71324,19 +71330,36 @@
71330 */
71331 if( offset > 98307 || offset > pC->payloadSize ){
71332 rc = SQLITE_CORRUPT_BKPT;
71333 goto op_column_error;
71334 }
71335
71336 if( avail<offset ){
71337 /* pC->aRow does not have to hold the entire row, but it does at least
71338 ** need to cover the header of the record. If pC->aRow does not contain
71339 ** the complete header, then set it to zero, forcing the header to be
71340 ** dynamically allocated. */
71341 pC->aRow = 0;
71342 pC->szRow = 0;
71343 }
71344
71345 /* The following goto is an optimization. It can be omitted and
71346 ** everything will still work. But OP_Column is measurably faster
71347 ** by skipping the subsequent conditional, which is always true.
71348 */
71349 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
71350 goto op_column_read_header;
71351 }
71352
71353 /* Make sure at least the first p2+1 entries of the header have been
71354 ** parsed and valid information is in aOffset[] and pC->aType[].
71355 */
71356 if( pC->nHdrParsed<=p2 ){
71357 /* If there is more header available for parsing in the record, try
71358 ** to extract additional fields up through the p2+1-th field
71359 */
71360 op_column_read_header:
71361 if( pC->iHdrOffset<aOffset[0] ){
71362 /* Make sure zData points to enough of the record to cover the header. */
71363 if( pC->aRow==0 ){
71364 memset(&sMem, 0, sizeof(sMem));
71365 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
@@ -71377,19 +71400,20 @@
71400 if( pC->aRow==0 ){
71401 sqlite3VdbeMemRelease(&sMem);
71402 sMem.flags = MEM_Null;
71403 }
71404
71405 /* The record is corrupt if any of the following are true:
71406 ** (1) the bytes of the header extend past the declared header size
71407 ** (zHdr>zEndHdr)
71408 ** (2) the entire header was used but not all data was used
71409 ** (zHdr==zEndHdr && offset!=pC->payloadSize)
71410 ** (3) the end of the data extends beyond the end of the record.
71411 ** (offset > pC->payloadSize)
71412 */
71413 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset!=pC->payloadSize))
71414 || (offset > pC->payloadSize)
 
71415 ){
71416 rc = SQLITE_CORRUPT_BKPT;
71417 goto op_column_error;
71418 }
71419 }
@@ -71576,11 +71600,11 @@
71600 ** out how much space is required for the new record.
71601 */
71602 pRec = pLast;
71603 do{
71604 assert( memIsValid(pRec) );
71605 pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format);
71606 len = sqlite3VdbeSerialTypeLen(serial_type);
71607 if( pRec->flags & MEM_Zero ){
71608 if( nData ){
71609 sqlite3VdbeMemExpandBlob(pRec);
71610 }else{
@@ -71625,11 +71649,11 @@
71649 i = putVarint32(zNewRecord, nHdr);
71650 j = nHdr;
71651 assert( pData0<=pLast );
71652 pRec = pData0;
71653 do{
71654 serial_type = pRec->uTemp;
71655 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
71656 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
71657 }while( (++pRec)<=pLast );
71658 assert( i==nHdr );
71659 assert( j==nByte );
@@ -72524,11 +72548,10 @@
72548 pIn3 = &aMem[pOp->p3];
72549 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){
72550 applyNumericAffinity(pIn3, 0);
72551 }
72552 iKey = sqlite3VdbeIntValue(pIn3);
 
72553
72554 /* If the P3 value could not be converted into an integer without
72555 ** loss of information, then special processing is required... */
72556 if( (pIn3->flags & MEM_Int)==0 ){
72557 if( (pIn3->flags & MEM_Real)==0 ){
@@ -72560,17 +72583,14 @@
72583 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
72584 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
72585 }
72586 }
72587 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
72588 pC->movetoTarget = iKey; /* Used by OP_Delete */
72589 if( rc!=SQLITE_OK ){
72590 goto abort_due_to_error;
72591 }
 
 
 
 
72592 }else{
72593 nField = pOp->p4.i;
72594 assert( pOp->p4type==P4_INT32 );
72595 assert( nField>0 );
72596 r.pKeyInfo = pC->pKeyInfo;
@@ -72596,11 +72616,10 @@
72616 ExpandBlob(r.aMem);
72617 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
72618 if( rc!=SQLITE_OK ){
72619 goto abort_due_to_error;
72620 }
 
72621 }
72622 pC->deferredMoveto = 0;
72623 pC->cacheStatus = CACHE_STALE;
72624 #ifdef SQLITE_TEST
72625 sqlite3_search_count++;
@@ -72608,21 +72627,19 @@
72627 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
72628 if( res<0 || (res==0 && oc==OP_SeekGT) ){
72629 res = 0;
72630 rc = sqlite3BtreeNext(pC->pCursor, &res);
72631 if( rc!=SQLITE_OK ) goto abort_due_to_error;
 
72632 }else{
72633 res = 0;
72634 }
72635 }else{
72636 assert( oc==OP_SeekLT || oc==OP_SeekLE );
72637 if( res>0 || (res==0 && oc==OP_SeekLT) ){
72638 res = 0;
72639 rc = sqlite3BtreePrevious(pC->pCursor, &res);
72640 if( rc!=SQLITE_OK ) goto abort_due_to_error;
 
72641 }else{
72642 /* res might be negative because the table is empty. Check to
72643 ** see if this is the case.
72644 */
72645 res = sqlite3BtreeEof(pC->pCursor);
@@ -72655,11 +72672,10 @@
72672 assert( pC->pCursor!=0 );
72673 assert( pC->isTable );
72674 pC->nullRow = 0;
72675 pIn2 = &aMem[pOp->p2];
72676 pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
 
72677 pC->deferredMoveto = 1;
72678 break;
72679 }
72680
72681
@@ -72841,19 +72857,17 @@
72857 pCrsr = pC->pCursor;
72858 assert( pCrsr!=0 );
72859 res = 0;
72860 iKey = pIn3->u.i;
72861 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
72862 pC->movetoTarget = iKey; /* Used by OP_Delete */
 
72863 pC->nullRow = 0;
72864 pC->cacheStatus = CACHE_STALE;
72865 pC->deferredMoveto = 0;
72866 VdbeBranchTaken(res!=0,2);
72867 if( res!=0 ){
72868 pc = pOp->p2 - 1;
 
72869 }
72870 pC->seekResult = res;
72871 break;
72872 }
72873
@@ -72997,11 +73011,10 @@
73011 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
73012 goto abort_due_to_error;
73013 }
73014 assert( v>0 ); /* EV: R-40812-03570 */
73015 }
 
73016 pC->deferredMoveto = 0;
73017 pC->cacheStatus = CACHE_STALE;
73018 }
73019 pOut->u.i = v;
73020 break;
@@ -73102,11 +73115,10 @@
73115 }
73116 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
73117 pData->z, pData->n, nZero,
73118 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
73119 );
 
73120 pC->deferredMoveto = 0;
73121 pC->cacheStatus = CACHE_STALE;
73122
73123 /* Invoke the update-hook if required. */
73124 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
@@ -73139,37 +73151,36 @@
73151 ** pointing to. The update hook will be invoked, if it exists.
73152 ** If P4 is not NULL then the P1 cursor must have been positioned
73153 ** using OP_NotFound prior to invoking this opcode.
73154 */
73155 case OP_Delete: {
 
73156 VdbeCursor *pC;
73157
73158 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73159 pC = p->apCsr[pOp->p1];
73160 assert( pC!=0 );
73161 assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
 
 
 
 
 
 
 
 
 
73162 assert( pC->deferredMoveto==0 );
 
 
73163
73164 #ifdef SQLITE_DEBUG
73165 /* The seek operation that positioned the cursor prior to OP_Delete will
73166 ** have also set the pC->movetoTarget field to the rowid of the row that
73167 ** is being deleted */
73168 if( pOp->p4.z && pC->isTable ){
73169 i64 iKey = 0;
73170 sqlite3BtreeKeySize(pC->pCursor, &iKey);
73171 assert( pC->movetoTarget==iKey );
73172 }
73173 #endif
73174
73175 rc = sqlite3BtreeDelete(pC->pCursor);
73176 pC->cacheStatus = CACHE_STALE;
73177
73178 /* Invoke the update-hook if required. */
73179 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
73180 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
73181 db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget);
73182 assert( pC->iDb>=0 );
73183 }
73184 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
73185 break;
73186 }
@@ -73218,23 +73229,32 @@
73229 pc = pOp->p2-1;
73230 }
73231 break;
73232 };
73233
73234 /* Opcode: SorterData P1 P2 P3 * *
73235 ** Synopsis: r[P2]=data
73236 **
73237 ** Write into register P2 the current sorter data for sorter cursor P1.
73238 ** Then clear the column header cache on cursor P3.
73239 **
73240 ** This opcode is normally use to move a record out of the sorter and into
73241 ** a register that is the source for a pseudo-table cursor created using
73242 ** OpenPseudo. That pseudo-table cursor is the one that is identified by
73243 ** parameter P3. Clearing the P3 column cache as part of this opcode saves
73244 ** us from having to issue a separate NullRow instruction to clear that cache.
73245 */
73246 case OP_SorterData: {
73247 VdbeCursor *pC;
73248
73249 pOut = &aMem[pOp->p2];
73250 pC = p->apCsr[pOp->p1];
73251 assert( isSorter(pC) );
73252 rc = sqlite3VdbeSorterRowkey(pC, pOut);
73253 assert( rc!=SQLITE_OK || (pOut->flags & MEM_Blob) );
73254 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73255 p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
73256 break;
73257 }
73258
73259 /* Opcode: RowData P1 P2 * * *
73260 ** Synopsis: r[P2]=data
@@ -73277,20 +73297,24 @@
73297 assert( pC!=0 );
73298 assert( pC->nullRow==0 );
73299 assert( pC->pseudoTableReg==0 );
73300 assert( pC->pCursor!=0 );
73301 pCrsr = pC->pCursor;
 
73302
73303 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
73304 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
73305 ** the cursor. If this where not the case, on of the following assert()s
73306 ** would fail. Should this ever change (because of changes in the code
73307 ** generator) then the fix would be to insert a call to
73308 ** sqlite3VdbeCursorMoveto().
73309 */
73310 assert( pC->deferredMoveto==0 );
73311 assert( sqlite3BtreeCursorIsValid(pCrsr) );
73312 #if 0 /* Not required due to the previous to assert() statements */
73313 rc = sqlite3VdbeCursorMoveto(pC);
73314 if( rc!=SQLITE_OK ) goto abort_due_to_error;
73315 #endif
73316
73317 if( pC->isTable==0 ){
73318 assert( !pC->isTable );
73319 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
73320 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
@@ -73303,11 +73327,12 @@
73327 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
73328 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
73329 goto too_big;
73330 }
73331 }
73332 testcase( n==0 );
73333 if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
73334 goto no_mem;
73335 }
73336 pOut->n = n;
73337 MemSetTypeFlag(pOut, MEM_Blob);
73338 if( pC->isTable==0 ){
@@ -73354,18 +73379,14 @@
73379 rc = pModule->xRowid(pC->pVtabCursor, &v);
73380 sqlite3VtabImportErrmsg(p, pVtab);
73381 #endif /* SQLITE_OMIT_VIRTUALTABLE */
73382 }else{
73383 assert( pC->pCursor!=0 );
73384 rc = sqlite3VdbeCursorRestore(pC);
73385 if( rc ) goto abort_due_to_error;
73386 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73387 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
 
 
 
 
73388 }
73389 pOut->u.i = v;
73390 break;
73391 }
73392
@@ -73380,11 +73401,10 @@
73401
73402 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
73403 pC = p->apCsr[pOp->p1];
73404 assert( pC!=0 );
73405 pC->nullRow = 1;
 
73406 pC->cacheStatus = CACHE_STALE;
73407 if( pC->pCursor ){
73408 sqlite3BtreeClearCursor(pC->pCursor);
73409 }
73410 break;
@@ -73414,11 +73434,10 @@
73434 res = 0;
73435 assert( pCrsr!=0 );
73436 rc = sqlite3BtreeLast(pCrsr, &res);
73437 pC->nullRow = (u8)res;
73438 pC->deferredMoveto = 0;
 
73439 pC->cacheStatus = CACHE_STALE;
73440 #ifdef SQLITE_DEBUG
73441 pC->seekOp = OP_Last;
73442 #endif
73443 if( pOp->p2>0 ){
@@ -73481,11 +73500,10 @@
73500 pCrsr = pC->pCursor;
73501 assert( pCrsr );
73502 rc = sqlite3BtreeFirst(pCrsr, &res);
73503 pC->deferredMoveto = 0;
73504 pC->cacheStatus = CACHE_STALE;
 
73505 }
73506 pC->nullRow = (u8)res;
73507 assert( pOp->p2>0 && pOp->p2<p->nOp );
73508 VdbeBranchTaken(res!=0,2);
73509 if( res ){
@@ -73607,11 +73625,10 @@
73625 sqlite3_search_count++;
73626 #endif
73627 }else{
73628 pC->nullRow = 1;
73629 }
 
73630 goto check_for_interrupt;
73631 }
73632
73633 /* Opcode: IdxInsert P1 P2 P3 * P5
73634 ** Synopsis: key=r[P2]
@@ -73723,14 +73740,20 @@
73740 pC = p->apCsr[pOp->p1];
73741 assert( pC!=0 );
73742 pCrsr = pC->pCursor;
73743 assert( pCrsr!=0 );
73744 pOut->flags = MEM_Null;
73745 assert( pC->isTable==0 );
 
73746 assert( pC->deferredMoveto==0 );
73747
73748 /* sqlite3VbeCursorRestore() can only fail if the record has been deleted
73749 ** out from under the cursor. That will never happend for an IdxRowid
73750 ** opcode, hence the NEVER() arround the check of the return value.
73751 */
73752 rc = sqlite3VdbeCursorRestore(pC);
73753 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
73754
73755 if( !pC->nullRow ){
73756 rowid = 0; /* Not needed. Only used to silence a warning. */
73757 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
73758 if( rc!=SQLITE_OK ){
73759 goto abort_due_to_error;
@@ -87168,29 +87191,27 @@
87191 tRowcnt v;
87192
87193 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87194 if( z==0 ) z = "";
87195 #else
87196 assert( z!=0 );
87197 #endif
87198 for(i=0; *z && i<nOut; i++){
87199 v = 0;
87200 while( (c=z[0])>='0' && c<='9' ){
87201 v = v*10 + c - '0';
87202 z++;
87203 }
87204 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87205 if( aOut ) aOut[i] = v;
87206 if( aLog ) aLog[i] = sqlite3LogEst(v);
 
87207 #else
87208 assert( aOut==0 );
87209 UNUSED_PARAMETER(aOut);
87210 assert( aLog!=0 );
87211 aLog[i] = sqlite3LogEst(v);
87212 #endif
 
 
 
87213 if( *z==' ' ) z++;
87214 }
87215 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
87216 assert( pIndex!=0 );
87217 #else
@@ -87247,12 +87268,21 @@
87268 pIndex = sqlite3FindIndex(pInfo->db, argv[1], pInfo->zDatabase);
87269 }
87270 z = argv[2];
87271
87272 if( pIndex ){
87273 int nCol = pIndex->nKeyCol+1;
87274 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87275 tRowcnt * const aiRowEst = pIndex->aiRowEst = (tRowcnt*)sqlite3MallocZero(
87276 sizeof(tRowcnt) * nCol
87277 );
87278 if( aiRowEst==0 ) pInfo->db->mallocFailed = 1;
87279 #else
87280 tRowcnt * const aiRowEst = 0;
87281 #endif
87282 pIndex->bUnordered = 0;
87283 decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex);
87284 if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0];
87285 }else{
87286 Index fakeIdx;
87287 fakeIdx.szIdxRow = pTable->szTabRow;
87288 #ifdef SQLITE_ENABLE_COSTMULT
@@ -87307,29 +87337,42 @@
87337 ** unique. */
87338 nCol = pIdx->nSampleCol-1;
87339 pIdx->aAvgEq[nCol] = 1;
87340 }
87341 for(iCol=0; iCol<nCol; iCol++){
87342 int nSample = pIdx->nSample;
87343 int i; /* Used to iterate through samples */
87344 tRowcnt sumEq = 0; /* Sum of the nEq values */
 
87345 tRowcnt avgEq = 0;
87346 tRowcnt nRow; /* Number of rows in index */
87347 i64 nSum100 = 0; /* Number of terms contributing to sumEq */
87348 i64 nDist100; /* Number of distinct values in index */
87349
87350 if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
87351 nRow = pFinal->anLt[iCol];
87352 nDist100 = (i64)100 * pFinal->anDLt[iCol];
87353 nSample--;
87354 }else{
87355 nRow = pIdx->aiRowEst[0];
87356 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
87357 }
87358
87359 /* Set nSum to the number of distinct (iCol+1) field prefixes that
87360 ** occur in the stat4 table for this index. Set sumEq to the sum of
87361 ** the nEq values for column iCol for the same set (adding the value
87362 ** only once where there exist duplicate prefixes). */
87363 for(i=0; i<nSample; i++){
87364 if( i==(pIdx->nSample-1)
87365 || aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol]
87366 ){
87367 sumEq += aSample[i].anEq[iCol];
87368 nSum100 += 100;
87369 }
87370 }
87371
87372 if( nDist100>nSum100 ){
87373 avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
87374 }
87375 if( avgEq==0 ) avgEq = 1;
87376 pIdx->aAvgEq[iCol] = avgEq;
87377 }
87378 }
@@ -87576,10 +87619,15 @@
87619 if( rc==SQLITE_OK ){
87620 int lookasideEnabled = db->lookaside.bEnabled;
87621 db->lookaside.bEnabled = 0;
87622 rc = loadStat4(db, sInfo.zDatabase);
87623 db->lookaside.bEnabled = lookasideEnabled;
87624 }
87625 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
87626 Index *pIdx = sqliteHashData(i);
87627 sqlite3_free(pIdx->aiRowEst);
87628 pIdx->aiRowEst = 0;
87629 }
87630 #endif
87631
87632 if( rc==SQLITE_NOMEM ){
87633 db->mallocFailed = 1;
@@ -88870,10 +88918,13 @@
88918 #endif
88919 if( db==0 || db->pnBytesFreed==0 ) sqlite3KeyInfoUnref(p->pKeyInfo);
88920 sqlite3ExprDelete(db, p->pPartIdxWhere);
88921 sqlite3DbFree(db, p->zColAff);
88922 if( p->isResized ) sqlite3DbFree(db, p->azColl);
88923 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
88924 sqlite3_free(p->aiRowEst);
88925 #endif
88926 sqlite3DbFree(db, p);
88927 }
88928
88929 /*
88930 ** For the index called zIdxName which is found in the database iDb,
@@ -91179,11 +91230,11 @@
91230 pIndex->nKeyCol); VdbeCoverage(v);
91231 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
91232 }else{
91233 addr2 = sqlite3VdbeCurrentAddr(v);
91234 }
91235 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
91236 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
91237 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
91238 sqlite3ReleaseTempReg(pParse, regRecord);
91239 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
91240 sqlite3VdbeJumpHere(v, addr1);
@@ -105122,11 +105173,10 @@
105173 int regRow;
105174 int regRowid;
105175 int nKey;
105176 int iSortTab; /* Sorter cursor to read from */
105177 int nSortData; /* Trailing values to read from sorter */
 
105178 int i;
105179 int bSeq; /* True if sorter record includes seq. no. */
105180 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
105181 struct ExprList_item *aOutEx = p->pEList->a;
105182 #endif
@@ -105156,23 +105206,20 @@
105206 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
105207 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
105208 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
105209 VdbeCoverage(v);
105210 codeOffset(v, p->iOffset, addrContinue);
105211 sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
 
105212 bSeq = 0;
105213 }else{
105214 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
105215 codeOffset(v, p->iOffset, addrContinue);
105216 iSortTab = iTab;
 
105217 bSeq = 1;
105218 }
105219 for(i=0; i<nSortData; i++){
105220 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
 
105221 VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
105222 }
105223 switch( eDest ){
105224 case SRT_Table:
105225 case SRT_EphemTab: {
@@ -109097,16 +109144,15 @@
109144 ** from the previous row currently stored in a0, a1, a2...
109145 */
109146 addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
109147 sqlite3ExprCacheClear(pParse);
109148 if( groupBySort ){
109149 sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx, sortOut,sortPTab);
109150 }
109151 for(j=0; j<pGroupBy->nExpr; j++){
109152 if( groupBySort ){
109153 sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
 
109154 }else{
109155 sAggInfo.directMode = 1;
109156 sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
109157 }
109158 }
@@ -112450,10 +112496,11 @@
112496 }
112497 sqlite3DbFree(db, pVTable);
112498 }else if( ALWAYS(pVTable->pVtab) ){
112499 /* Justification of ALWAYS(): A correct vtab constructor must allocate
112500 ** the sqlite3_vtab object if successful. */
112501 memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
112502 pVTable->pVtab->pModule = pMod->pModule;
112503 pVTable->nRef = 1;
112504 if( sCtx.pTab ){
112505 const char *zFormat = "vtable constructor did not declare schema: %s";
112506 *pzErr = sqlite3MPrintf(db, zFormat, pTab->zName);
@@ -115700,21 +115747,28 @@
115747 ** have been requested when testing key $P in whereEqualScanEst(). */
115748 whereKeyStats(pParse, p, pRec, 0, a);
115749 iLower = a[0];
115750 iUpper = a[0] + a[1];
115751 }
115752
115753 assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );
115754 assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
115755 assert( p->aSortOrder!=0 );
115756 if( p->aSortOrder[nEq] ){
115757 /* The roles of pLower and pUpper are swapped for a DESC index */
115758 SWAP(WhereTerm*, pLower, pUpper);
115759 }
115760
115761 /* If possible, improve on the iLower estimate using ($P:$L). */
115762 if( pLower ){
115763 int bOk; /* True if value is extracted from pExpr */
115764 Expr *pExpr = pLower->pExpr->pRight;
 
115765 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115766 if( rc==SQLITE_OK && bOk ){
115767 tRowcnt iNew;
115768 whereKeyStats(pParse, p, pRec, 0, a);
115769 iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115770 if( iNew>iLower ) iLower = iNew;
115771 nOut--;
115772 pLower = 0;
115773 }
115774 }
@@ -115721,16 +115775,15 @@
115775
115776 /* If possible, improve on the iUpper estimate using ($P:$U). */
115777 if( pUpper ){
115778 int bOk; /* True if value is extracted from pExpr */
115779 Expr *pExpr = pUpper->pExpr->pRight;
 
115780 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115781 if( rc==SQLITE_OK && bOk ){
115782 tRowcnt iNew;
115783 whereKeyStats(pParse, p, pRec, 1, a);
115784 iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115785 if( iNew<iUpper ) iUpper = iNew;
115786 nOut--;
115787 pUpper = 0;
115788 }
115789 }
@@ -116225,65 +116278,52 @@
116278 sqlite3StrAccumAppend(pStr, "?", 1);
116279 }
116280
116281 /*
116282 ** Argument pLevel describes a strategy for scanning table pTab. This
116283 ** function appends text to pStr that describes the subset of table
116284 ** rows scanned by the strategy in the form of an SQL expression.
 
116285 **
116286 ** For example, if the query:
116287 **
116288 ** SELECT * FROM t1 WHERE a=1 AND b>2;
116289 **
116290 ** is run and there is an index on (a, b), then this function returns a
116291 ** string similar to:
116292 **
116293 ** "a=? AND b>?"
 
 
 
 
116294 */
116295 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
116296 Index *pIndex = pLoop->u.btree.pIndex;
116297 u16 nEq = pLoop->u.btree.nEq;
116298 u16 nSkip = pLoop->u.btree.nSkip;
116299 int i, j;
116300 Column *aCol = pTab->aCol;
116301 i16 *aiColumn = pIndex->aiColumn;
116302
116303 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
116304 sqlite3StrAccumAppend(pStr, " (", 2);
 
 
 
 
 
116305 for(i=0; i<nEq; i++){
116306 char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
116307 if( i>=nSkip ){
116308 explainAppendTerm(pStr, i, z, "=");
116309 }else{
116310 if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
116311 sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
 
 
116312 }
116313 }
116314
116315 j = i;
116316 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
116317 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116318 explainAppendTerm(pStr, i++, z, ">");
116319 }
116320 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
116321 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
116322 explainAppendTerm(pStr, i, z, "<");
116323 }
116324 sqlite3StrAccumAppend(pStr, ")", 1);
 
116325 }
116326
116327 /*
116328 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116329 ** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
@@ -116303,72 +116343,90 @@
116343 #endif
116344 {
116345 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116346 Vdbe *v = pParse->pVdbe; /* VM being constructed */
116347 sqlite3 *db = pParse->db; /* Database handle */
 
116348 int iId = pParse->iSelectId; /* Select id (left-most output column) */
116349 int isSearch; /* True for a SEARCH. False for SCAN. */
116350 WhereLoop *pLoop; /* The controlling WhereLoop object */
116351 u32 flags; /* Flags that describe this loop */
116352 char *zMsg; /* Text to add to EQP output */
116353 StrAccum str; /* EQP output string */
116354 char zBuf[100]; /* Initial space for EQP output string */
116355
116356 pLoop = pLevel->pWLoop;
116357 flags = pLoop->wsFlags;
116358 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116359
116360 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116361 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116362 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116363
116364 sqlite3StrAccumInit(&str, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
116365 str.db = db;
116366 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
116367 if( pItem->pSelect ){
116368 sqlite3XPrintf(&str, 0, " SUBQUERY %d", pItem->iSelectId);
116369 }else{
116370 sqlite3XPrintf(&str, 0, " TABLE %s", pItem->zName);
116371 }
116372
116373 if( pItem->zAlias ){
116374 sqlite3XPrintf(&str, 0, " AS %s", pItem->zAlias);
116375 }
116376 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
116377 const char *zFmt = 0;
116378 Index *pIdx;
116379
116380 assert( pLoop->u.btree.pIndex!=0 );
116381 pIdx = pLoop->u.btree.pIndex;
116382 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116383 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116384 if( isSearch ){
116385 zFmt = "PRIMARY KEY";
116386 }
116387 }else if( flags & WHERE_AUTO_INDEX ){
116388 zFmt = "AUTOMATIC COVERING INDEX";
116389 }else if( flags & WHERE_IDX_ONLY ){
116390 zFmt = "COVERING INDEX %s";
116391 }else{
116392 zFmt = "INDEX %s";
116393 }
116394 if( zFmt ){
116395 sqlite3StrAccumAppend(&str, " USING ", 7);
116396 sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
116397 explainIndexRange(&str, pLoop, pItem->pTab);
116398 }
116399 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
116400 const char *zRange;
 
116401 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
116402 zRange = "(rowid=?)";
116403 }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
116404 zRange = "(rowid>? AND rowid<?)";
116405 }else if( flags&WHERE_BTM_LIMIT ){
116406 zRange = "(rowid>?)";
116407 }else{
116408 assert( flags&WHERE_TOP_LIMIT);
116409 zRange = "(rowid<?)";
116410 }
116411 sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
116412 sqlite3StrAccumAppendAll(&str, zRange);
116413 }
116414 #ifndef SQLITE_OMIT_VIRTUALTABLE
116415 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
116416 sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
116417 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
116418 }
116419 #endif
116420 #ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
116421 if( pLoop->nOut>=10 ){
116422 sqlite3XPrintf(&str, 0, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut));
116423 }else{
116424 sqlite3StrAccumAppend(&str, " (~1 row)", 9);
116425 }
116426 #endif
116427 zMsg = sqlite3StrAccumFinish(&str);
116428 sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116429 }
116430 }
116431 #else
116432 # define explainOneScan(u,v,w,x,y,z)
@@ -117633,11 +117691,11 @@
117691 if( ppPrev==0 ){
117692 /* There already exists a WhereLoop on the list that is better
117693 ** than pTemplate, so just ignore pTemplate */
117694 #if WHERETRACE_ENABLED /* 0x8 */
117695 if( sqlite3WhereTrace & 0x8 ){
117696 sqlite3DebugPrintf(" skip: ");
117697 whereLoopPrint(pTemplate, pBuilder->pWC);
117698 }
117699 #endif
117700 return SQLITE_OK;
117701 }else{
@@ -117649,14 +117707,14 @@
117707 ** WhereLoop and insert it.
117708 */
117709 #if WHERETRACE_ENABLED /* 0x8 */
117710 if( sqlite3WhereTrace & 0x8 ){
117711 if( p!=0 ){
117712 sqlite3DebugPrintf("replace: ");
117713 whereLoopPrint(p, pBuilder->pWC);
117714 }
117715 sqlite3DebugPrintf(" add: ");
117716 whereLoopPrint(pTemplate, pBuilder->pWC);
117717 }
117718 #endif
117719 if( p==0 ){
117720 /* Allocate a new WhereLoop to add to the end of the list */
@@ -117676,11 +117734,11 @@
117734 pToDel = *ppTail;
117735 if( pToDel==0 ) break;
117736 *ppTail = pToDel->pNextLoop;
117737 #if WHERETRACE_ENABLED /* 0x8 */
117738 if( sqlite3WhereTrace & 0x8 ){
117739 sqlite3DebugPrintf(" delete: ");
117740 whereLoopPrint(pToDel, pBuilder->pWC);
117741 }
117742 #endif
117743 whereLoopDelete(db, pToDel);
117744 }
@@ -118843,11 +118901,11 @@
118901 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
118902 }
118903 isMatch = 1;
118904 break;
118905 }
118906 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
118907 /* Make sure the sort order is compatible in an ORDER BY clause.
118908 ** Sort order is irrelevant for a GROUP BY clause. */
118909 if( revSet ){
118910 if( (rev ^ revIdx)!=pOrderBy->a[i].sortOrder ) isMatch = 0;
118911 }else{
@@ -119308,16 +119366,19 @@
119366 pWInfo->revMask = pFrom->revLoop;
119367 }
119368 if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
119369 && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
119370 ){
119371 Bitmask revMask = 0;
119372 int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
119373 pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
119374 );
119375 assert( pWInfo->sorted==0 );
119376 if( nOrder==pWInfo->pOrderBy->nExpr ){
119377 pWInfo->sorted = 1;
119378 pWInfo->revMask = revMask;
119379 }
119380 }
119381 }
119382
119383
119384 pWInfo->nRowOut = pFrom->nRow;
@@ -132620,10 +132681,11 @@
132681 assert( iIdx==nVal );
132682
132683 /* In case the cursor has been used before, clear it now. */
132684 sqlite3_finalize(pCsr->pStmt);
132685 sqlite3_free(pCsr->aDoclist);
132686 sqlite3_free(pCsr->aMatchinfo);
132687 sqlite3Fts3ExprFree(pCsr->pExpr);
132688 memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
132689
132690 /* Set the lower and upper bounds on docids to return */
132691 pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
@@ -133930,11 +133992,11 @@
133992 if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
133993 iMax = a[i].iDocid;
133994 bMaxSet = 1;
133995 }
133996 }
133997 assert( rc!=SQLITE_OK || (p->nToken>=1 && a[p->nToken-1].bIgnore==0) );
133998 assert( rc!=SQLITE_OK || bMaxSet );
133999
134000 /* Keep advancing iterators until they all point to the same document */
134001 for(i=0; i<p->nToken; i++){
134002 while( rc==SQLITE_OK && bEof==0
@@ -136047,11 +136109,11 @@
136109 int i = 0;
136110
136111 /* Set variable i to the maximum number of bytes of input to tokenize. */
136112 for(i=0; i<n; i++){
136113 if( sqlite3_fts3_enable_parentheses && (z[i]=='(' || z[i]==')') ) break;
136114 if( z[i]=='"' ) break;
136115 }
136116
136117 *pnConsumed = i;
136118 rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
136119 if( rc==SQLITE_OK ){
136120
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.7"
111111
#define SQLITE_VERSION_NUMBER 3008007
112
-#define SQLITE_SOURCE_ID "2014-10-04 19:31:53 b8f7f19dc06c59de2e194d83e6c052fb7d28c71d"
112
+#define SQLITE_SOURCE_ID "2014-10-14 20:25:43 eab82330631187dcc3e5d2dddd23dbda5752904b"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-10-04 19:31:53 b8f7f19dc06c59de2e194d83e6c052fb7d28c71d"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-10-14 20:25:43 eab82330631187dcc3e5d2dddd23dbda5752904b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
+37 -14
--- src/stat.c
+++ src/stat.c
@@ -151,35 +151,45 @@
151151
}
152152
153153
/*
154154
** COMMAND: dbstat*
155155
**
156
-** Usage: %fossil dbstat ?-brief | -b?
156
+** Usage: %fossil dbstat OPTIONS
157157
**
158158
** Shows statistics and global information about the repository.
159159
**
160
-** The (-brief|-b) option removes any "long-running" statistics, namely
161
-** those whose calculations are known to slow down as the repository
162
-** grows.
160
+** Options:
163161
**
162
+** --brief|-b Only show essential elements
163
+** --db-check Run a PRAGMA quick_check on the repository database
164
+** --omit-version-info Omit the SQLite and Fossil version information
164165
*/
165166
void dbstat_cmd(void){
166167
i64 t, fsize;
167168
int n, m;
168169
int szMax, szAvg;
169170
const char *zDb;
170171
int brief;
172
+ int omitVers; /* Omit Fossil and SQLite version information */
173
+ int dbCheck; /* True for the --db-check option */
171174
char zBuf[100];
172175
const int colWidth = -19 /* printf alignment/width for left column */;
173
- const char *p;
176
+ const char *p, *z;
174177
175178
brief = find_option("brief", "b",0)!=0;
179
+ omitVers = find_option("omit-version-info", 0, 0)!=0;
180
+ dbCheck = find_option("db-check",0,0)!=0;
176181
db_find_and_open_repository(0,0);
177182
178183
/* We should be done with options.. */
179184
verify_all_options();
180185
186
+ if( (z = db_get("project-name",0))!=0
187
+ || (z = db_get("short-project-name",0))!=0
188
+ ){
189
+ fossil_print("%*s%s\n", colWidth, "project-name:", z);
190
+ }
181191
fsize = file_size(g.zRepositoryName);
182192
bigSizeName(sizeof(zBuf), zBuf, fsize);
183193
fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf );
184194
if( !brief ){
185195
n = db_int(0, "SELECT count(*) FROM blob");
@@ -225,38 +235,51 @@
225235
fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
226236
n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
227237
fossil_print("%*s%d\n", colWidth, "events:", n);
228238
n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
229239
fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
240
+ z = db_text(0, "SELECT datetime(mtime) ||"
241
+ " printf(' - about %%d days ago ',julianday('now') - mtime)"
242
+ " FROM event "
243
+ " ORDER BY mtime DESC LIMIT 1");
244
+ fossil_print("%*s%s\n", colWidth, "latest-change:", z);
230245
}
231246
n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
232247
" + 0.99");
233248
fossil_print("%*s%d days or approximately %.2f years.\n",
234249
colWidth, "project-age:", n, n/365.2425);
235250
p = db_get("project-code", 0);
236251
if( p ){
237252
fossil_print("%*s%s\n", colWidth, "project-id:", p);
238253
}
254
+#if 0
255
+ /* Server-id is not useful information any more */
239256
fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code", 0));
240
- fossil_print("%*s%s %s [%s] (%s)\n",
241
- colWidth, "fossil-version:",
242
- MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
243
- COMPILER_NAME);
244
- fossil_print("%*s%.19s [%.10s] (%s)\n",
245
- colWidth, "sqlite-version:",
246
- sqlite3_sourceid(), &sqlite3_sourceid()[20],
247
- sqlite3_libversion());
257
+#endif
258
+ if( !omitVers ){
259
+ fossil_print("%*s%s %s [%s] (%s)\n",
260
+ colWidth, "fossil-version:",
261
+ MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
262
+ COMPILER_NAME);
263
+ fossil_print("%*s%.19s [%.10s] (%s)\n",
264
+ colWidth, "sqlite-version:",
265
+ sqlite3_sourceid(), &sqlite3_sourceid()[20],
266
+ sqlite3_libversion());
267
+ }
248268
zDb = db_name("repository");
249269
fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
250270
"%s, %s mode\n",
251271
colWidth, "database-stats:",
252272
db_int(0, "PRAGMA %s.page_count", zDb),
253273
db_int(0, "PRAGMA %s.page_size", zDb),
254274
db_int(0, "PRAGMA %s.freelist_count", zDb),
255275
db_text(0, "PRAGMA %s.encoding", zDb),
256276
db_text(0, "PRAGMA %s.journal_mode", zDb));
257
-
277
+ if( dbCheck ){
278
+ fossil_print("%*s%s\n", colWidth, "database-check:",
279
+ db_text(0, "PRAGMA quick_check(1)"));
280
+ }
258281
}
259282
260283
/*
261284
** WEBPAGE: urllist
262285
**
263286
--- src/stat.c
+++ src/stat.c
@@ -151,35 +151,45 @@
151 }
152
153 /*
154 ** COMMAND: dbstat*
155 **
156 ** Usage: %fossil dbstat ?-brief | -b?
157 **
158 ** Shows statistics and global information about the repository.
159 **
160 ** The (-brief|-b) option removes any "long-running" statistics, namely
161 ** those whose calculations are known to slow down as the repository
162 ** grows.
163 **
 
 
 
164 */
165 void dbstat_cmd(void){
166 i64 t, fsize;
167 int n, m;
168 int szMax, szAvg;
169 const char *zDb;
170 int brief;
 
 
171 char zBuf[100];
172 const int colWidth = -19 /* printf alignment/width for left column */;
173 const char *p;
174
175 brief = find_option("brief", "b",0)!=0;
 
 
176 db_find_and_open_repository(0,0);
177
178 /* We should be done with options.. */
179 verify_all_options();
180
 
 
 
 
 
181 fsize = file_size(g.zRepositoryName);
182 bigSizeName(sizeof(zBuf), zBuf, fsize);
183 fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf );
184 if( !brief ){
185 n = db_int(0, "SELECT count(*) FROM blob");
@@ -225,38 +235,51 @@
225 fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
226 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
227 fossil_print("%*s%d\n", colWidth, "events:", n);
228 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
229 fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
 
 
 
 
 
230 }
231 n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
232 " + 0.99");
233 fossil_print("%*s%d days or approximately %.2f years.\n",
234 colWidth, "project-age:", n, n/365.2425);
235 p = db_get("project-code", 0);
236 if( p ){
237 fossil_print("%*s%s\n", colWidth, "project-id:", p);
238 }
 
 
239 fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code", 0));
240 fossil_print("%*s%s %s [%s] (%s)\n",
241 colWidth, "fossil-version:",
242 MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
243 COMPILER_NAME);
244 fossil_print("%*s%.19s [%.10s] (%s)\n",
245 colWidth, "sqlite-version:",
246 sqlite3_sourceid(), &sqlite3_sourceid()[20],
247 sqlite3_libversion());
 
 
 
248 zDb = db_name("repository");
249 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
250 "%s, %s mode\n",
251 colWidth, "database-stats:",
252 db_int(0, "PRAGMA %s.page_count", zDb),
253 db_int(0, "PRAGMA %s.page_size", zDb),
254 db_int(0, "PRAGMA %s.freelist_count", zDb),
255 db_text(0, "PRAGMA %s.encoding", zDb),
256 db_text(0, "PRAGMA %s.journal_mode", zDb));
257
 
 
 
258 }
259
260 /*
261 ** WEBPAGE: urllist
262 **
263
--- src/stat.c
+++ src/stat.c
@@ -151,35 +151,45 @@
151 }
152
153 /*
154 ** COMMAND: dbstat*
155 **
156 ** Usage: %fossil dbstat OPTIONS
157 **
158 ** Shows statistics and global information about the repository.
159 **
160 ** Options:
 
 
161 **
162 ** --brief|-b Only show essential elements
163 ** --db-check Run a PRAGMA quick_check on the repository database
164 ** --omit-version-info Omit the SQLite and Fossil version information
165 */
166 void dbstat_cmd(void){
167 i64 t, fsize;
168 int n, m;
169 int szMax, szAvg;
170 const char *zDb;
171 int brief;
172 int omitVers; /* Omit Fossil and SQLite version information */
173 int dbCheck; /* True for the --db-check option */
174 char zBuf[100];
175 const int colWidth = -19 /* printf alignment/width for left column */;
176 const char *p, *z;
177
178 brief = find_option("brief", "b",0)!=0;
179 omitVers = find_option("omit-version-info", 0, 0)!=0;
180 dbCheck = find_option("db-check",0,0)!=0;
181 db_find_and_open_repository(0,0);
182
183 /* We should be done with options.. */
184 verify_all_options();
185
186 if( (z = db_get("project-name",0))!=0
187 || (z = db_get("short-project-name",0))!=0
188 ){
189 fossil_print("%*s%s\n", colWidth, "project-name:", z);
190 }
191 fsize = file_size(g.zRepositoryName);
192 bigSizeName(sizeof(zBuf), zBuf, fsize);
193 fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf );
194 if( !brief ){
195 n = db_int(0, "SELECT count(*) FROM blob");
@@ -225,38 +235,51 @@
235 fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
236 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
237 fossil_print("%*s%d\n", colWidth, "events:", n);
238 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
239 fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
240 z = db_text(0, "SELECT datetime(mtime) ||"
241 " printf(' - about %%d days ago ',julianday('now') - mtime)"
242 " FROM event "
243 " ORDER BY mtime DESC LIMIT 1");
244 fossil_print("%*s%s\n", colWidth, "latest-change:", z);
245 }
246 n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)"
247 " + 0.99");
248 fossil_print("%*s%d days or approximately %.2f years.\n",
249 colWidth, "project-age:", n, n/365.2425);
250 p = db_get("project-code", 0);
251 if( p ){
252 fossil_print("%*s%s\n", colWidth, "project-id:", p);
253 }
254 #if 0
255 /* Server-id is not useful information any more */
256 fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code", 0));
257 #endif
258 if( !omitVers ){
259 fossil_print("%*s%s %s [%s] (%s)\n",
260 colWidth, "fossil-version:",
261 MANIFEST_DATE, MANIFEST_VERSION, RELEASE_VERSION,
262 COMPILER_NAME);
263 fossil_print("%*s%.19s [%.10s] (%s)\n",
264 colWidth, "sqlite-version:",
265 sqlite3_sourceid(), &sqlite3_sourceid()[20],
266 sqlite3_libversion());
267 }
268 zDb = db_name("repository");
269 fossil_print("%*s%d pages, %d bytes/pg, %d free pages, "
270 "%s, %s mode\n",
271 colWidth, "database-stats:",
272 db_int(0, "PRAGMA %s.page_count", zDb),
273 db_int(0, "PRAGMA %s.page_size", zDb),
274 db_int(0, "PRAGMA %s.freelist_count", zDb),
275 db_text(0, "PRAGMA %s.encoding", zDb),
276 db_text(0, "PRAGMA %s.journal_mode", zDb));
277 if( dbCheck ){
278 fossil_print("%*s%s\n", colWidth, "database-check:",
279 db_text(0, "PRAGMA quick_check(1)"));
280 }
281 }
282
283 /*
284 ** WEBPAGE: urllist
285 **
286
+1 -1
--- src/style.c
+++ src/style.c
@@ -175,11 +175,11 @@
175175
}
176176
for(i=0; i<nFormAction; i++){
177177
@ gebi("form%d(i+1)").action="%s(aFormAction[i])";
178178
}
179179
@ }
180
- if( strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT")) ){
180
+ if( sqlite3_strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT"))==0 ){
181181
/* Special case for Opera Mini, which executes JS server-side */
182182
@ var isOperaMini = Object.prototype.toString.call(window.operamini)
183183
@ === "[object OperaMini]";
184184
@ if( isOperaMini ){
185185
@ setTimeout("setAllHrefs();",%d(nDelay));
186186
--- src/style.c
+++ src/style.c
@@ -175,11 +175,11 @@
175 }
176 for(i=0; i<nFormAction; i++){
177 @ gebi("form%d(i+1)").action="%s(aFormAction[i])";
178 }
179 @ }
180 if( strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT")) ){
181 /* Special case for Opera Mini, which executes JS server-side */
182 @ var isOperaMini = Object.prototype.toString.call(window.operamini)
183 @ === "[object OperaMini]";
184 @ if( isOperaMini ){
185 @ setTimeout("setAllHrefs();",%d(nDelay));
186
--- src/style.c
+++ src/style.c
@@ -175,11 +175,11 @@
175 }
176 for(i=0; i<nFormAction; i++){
177 @ gebi("form%d(i+1)").action="%s(aFormAction[i])";
178 }
179 @ }
180 if( sqlite3_strglob("*Opera Mini/[1-9]*", P("HTTP_USER_AGENT"))==0 ){
181 /* Special case for Opera Mini, which executes JS server-side */
182 @ var isOperaMini = Object.prototype.toString.call(window.operamini)
183 @ === "[object OperaMini]";
184 @ if( isOperaMini ){
185 @ setTimeout("setAllHrefs();",%d(nDelay));
186
+2 -2
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397397
"original",
398398
"output",
399399
};
400400
int i, j, n;
401401
402
- if( strglob("ci-comment-????????????.txt", zName) ) return 1;
402
+ if( sqlite3_strglob("ci-comment-????????????.txt", zName)==0 ) return 1;
403403
for(; zName[0]!=0; zName++){
404
- if( zName[0]=='/' && strglob("/ci-comment-????????????.txt", zName) ){
404
+ if( zName[0]=='/' && sqlite3_strglob("/ci-comment-????????????.txt", zName)==0 ){
405405
return 1;
406406
}
407407
if( zName[0]!='-' ) continue;
408408
for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409409
n = (int)strlen(azTemp[i]);
410410
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397 "original",
398 "output",
399 };
400 int i, j, n;
401
402 if( strglob("ci-comment-????????????.txt", zName) ) return 1;
403 for(; zName[0]!=0; zName++){
404 if( zName[0]=='/' && strglob("/ci-comment-????????????.txt", zName) ){
405 return 1;
406 }
407 if( zName[0]!='-' ) continue;
408 for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409 n = (int)strlen(azTemp[i]);
410
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397 "original",
398 "output",
399 };
400 int i, j, n;
401
402 if( sqlite3_strglob("ci-comment-????????????.txt", zName)==0 ) return 1;
403 for(; zName[0]!=0; zName++){
404 if( zName[0]=='/' && sqlite3_strglob("/ci-comment-????????????.txt", zName)==0 ){
405 return 1;
406 }
407 if( zName[0]!='-' ) continue;
408 for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409 n = (int)strlen(azTemp[i]);
410
+2 -2
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397397
"original",
398398
"output",
399399
};
400400
int i, j, n;
401401
402
- if( strglob("ci-comment-????????????.txt", zName) ) return 1;
402
+ if( sqlite3_strglob("ci-comment-????????????.txt", zName)==0 ) return 1;
403403
for(; zName[0]!=0; zName++){
404
- if( zName[0]=='/' && strglob("/ci-comment-????????????.txt", zName) ){
404
+ if( zName[0]=='/' && sqlite3_strglob("/ci-comment-????????????.txt", zName)==0 ){
405405
return 1;
406406
}
407407
if( zName[0]!='-' ) continue;
408408
for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409409
n = (int)strlen(azTemp[i]);
410410
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397 "original",
398 "output",
399 };
400 int i, j, n;
401
402 if( strglob("ci-comment-????????????.txt", zName) ) return 1;
403 for(; zName[0]!=0; zName++){
404 if( zName[0]=='/' && strglob("/ci-comment-????????????.txt", zName) ){
405 return 1;
406 }
407 if( zName[0]!='-' ) continue;
408 for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409 n = (int)strlen(azTemp[i]);
410
--- src/vfile.c
+++ src/vfile.c
@@ -397,13 +397,13 @@
397 "original",
398 "output",
399 };
400 int i, j, n;
401
402 if( sqlite3_strglob("ci-comment-????????????.txt", zName)==0 ) return 1;
403 for(; zName[0]!=0; zName++){
404 if( zName[0]=='/' && sqlite3_strglob("/ci-comment-????????????.txt", zName)==0 ){
405 return 1;
406 }
407 if( zName[0]!='-' ) continue;
408 for(i=0; i<sizeof(azTemp)/sizeof(azTemp[0]); i++){
409 n = (int)strlen(azTemp[i]);
410
+1 -1
--- src/xfer.c
+++ src/xfer.c
@@ -1814,11 +1814,11 @@
18141814
** to the next cycle.
18151815
*/
18161816
if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
18171817
char *zMsg = blob_terminate(&xfer.aToken[1]);
18181818
defossilize(zMsg);
1819
- if( (syncFlags & SYNC_PUSH) && zMsg && strglob("pull only *", zMsg) ){
1819
+ if( (syncFlags & SYNC_PUSH) && zMsg && sqlite3_strglob("pull only *", zMsg)==0 ){
18201820
syncFlags &= ~SYNC_PUSH;
18211821
zMsg = 0;
18221822
}
18231823
if( zMsg && zMsg[0] ){
18241824
fossil_force_newline();
18251825
--- src/xfer.c
+++ src/xfer.c
@@ -1814,11 +1814,11 @@
1814 ** to the next cycle.
1815 */
1816 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
1817 char *zMsg = blob_terminate(&xfer.aToken[1]);
1818 defossilize(zMsg);
1819 if( (syncFlags & SYNC_PUSH) && zMsg && strglob("pull only *", zMsg) ){
1820 syncFlags &= ~SYNC_PUSH;
1821 zMsg = 0;
1822 }
1823 if( zMsg && zMsg[0] ){
1824 fossil_force_newline();
1825
--- src/xfer.c
+++ src/xfer.c
@@ -1814,11 +1814,11 @@
1814 ** to the next cycle.
1815 */
1816 if( blob_eq(&xfer.aToken[0],"message") && xfer.nToken==2 ){
1817 char *zMsg = blob_terminate(&xfer.aToken[1]);
1818 defossilize(zMsg);
1819 if( (syncFlags & SYNC_PUSH) && zMsg && sqlite3_strglob("pull only *", zMsg)==0 ){
1820 syncFlags &= ~SYNC_PUSH;
1821 zMsg = 0;
1822 }
1823 if( zMsg && zMsg[0] ){
1824 fossil_force_newline();
1825

Keyboard Shortcuts

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