Fossil SCM

Update the built-in SQLite and the SQL command-line shell to the latest code from the SQLite trunk: version 3.7.9 alpha. This fixes some warnings that started appearing after upgrading to gcc 4.6.1.

drh 2011-10-15 10:40 trunk
Commit 3dd0c1558303f2ba711c90637f1efdae478f51e9
3 files changed +8 -10 +240 -230 +16 -3
+8 -10
--- src/shell.c
+++ src/shell.c
@@ -336,22 +336,20 @@
336336
*/
337337
static char *local_getline(char *zPrompt, FILE *in){
338338
char *zLine;
339339
int nLine;
340340
int n;
341
- int eol;
342341
343342
if( zPrompt && *zPrompt ){
344343
printf("%s",zPrompt);
345344
fflush(stdout);
346345
}
347346
nLine = 100;
348347
zLine = malloc( nLine );
349348
if( zLine==0 ) return 0;
350349
n = 0;
351
- eol = 0;
352
- while( !eol ){
350
+ while( 1 ){
353351
if( n+100>nLine ){
354352
nLine = nLine*2 + 100;
355353
zLine = realloc(zLine, nLine);
356354
if( zLine==0 ) return 0;
357355
}
@@ -359,19 +357,18 @@
359357
if( n==0 ){
360358
free(zLine);
361359
return 0;
362360
}
363361
zLine[n] = 0;
364
- eol = 1;
365362
break;
366363
}
367364
while( zLine[n] ){ n++; }
368365
if( n>0 && zLine[n-1]=='\n' ){
369366
n--;
370367
if( n>0 && zLine[n-1]=='\r' ) n--;
371368
zLine[n] = 0;
372
- eol = 1;
369
+ break;
373370
}
374371
}
375372
zLine = realloc( zLine, n+1 );
376373
return zLine;
377374
}
@@ -1095,10 +1092,11 @@
10951092
struct callback_data *pArg, /* Pointer to struct callback_data */
10961093
char **pzErrMsg /* Error msg written here */
10971094
){
10981095
sqlite3_stmt *pStmt = NULL; /* Statement to execute. */
10991096
int rc = SQLITE_OK; /* Return Code */
1097
+ int rc2;
11001098
const char *zLeftover; /* Tail of unprocessed SQL */
11011099
11021100
if( pzErrMsg ){
11031101
*pzErrMsg = NULL;
11041102
}
@@ -1188,11 +1186,12 @@
11881186
}
11891187
11901188
/* Finalize the statement just executed. If this fails, save a
11911189
** copy of the error message. Otherwise, set zSql to point to the
11921190
** next statement to execute. */
1193
- rc = sqlite3_finalize(pStmt);
1191
+ rc2 = sqlite3_finalize(pStmt);
1192
+ if( rc!=SQLITE_NOMEM ) rc = rc2;
11941193
if( rc==SQLITE_OK ){
11951194
zSql = zLeftover;
11961195
while( IsSpace(zSql[0]) ) zSql++;
11971196
}else if( pzErrMsg ){
11981197
*pzErrMsg = save_err_msg(db);
@@ -1760,11 +1759,10 @@
17601759
}
17611760
sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
17621761
zCommit = "COMMIT";
17631762
while( (zLine = local_getline(0, in))!=0 ){
17641763
char *z;
1765
- i = 0;
17661764
lineno++;
17671765
azCol[0] = zLine;
17681766
for(i=0, z=zLine; *z && *z!='\n' && *z!='\r'; z++){
17691767
if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
17701768
*z = 0;
@@ -2235,11 +2233,11 @@
22352233
for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
22362234
if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
22372235
if( testctrl<0 ){
22382236
testctrl = aCtrl[i].ctrlCode;
22392237
}else{
2240
- fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[i]);
2238
+ fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
22412239
testctrl = -1;
22422240
break;
22432241
}
22442242
}
22452243
}
@@ -2743,10 +2741,11 @@
27432741
** we do the actual processing of arguments later in a second pass.
27442742
*/
27452743
}else if( strcmp(argv[i],"-batch")==0 ){
27462744
stdin_is_interactive = 0;
27472745
}else if( strcmp(argv[i],"-heap")==0 ){
2746
+#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
27482747
int j, c;
27492748
const char *zSize;
27502749
sqlite3_int64 szHeap;
27512750
27522751
zSize = argv[++i];
@@ -2755,11 +2754,10 @@
27552754
if( c=='M' ){ szHeap *= 1000000; break; }
27562755
if( c=='K' ){ szHeap *= 1000; break; }
27572756
if( c=='G' ){ szHeap *= 1000000000; break; }
27582757
}
27592758
if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
2760
-#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
27612759
sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
27622760
#endif
27632761
#ifdef SQLITE_ENABLE_VFSTRACE
27642762
}else if( strcmp(argv[i],"-vfstrace")==0 ){
27652763
extern int vfstrace_register(
@@ -2796,11 +2794,11 @@
27962794
#ifndef SQLITE_OMIT_MEMORYDB
27972795
data.zDbFilename = ":memory:";
27982796
#else
27992797
data.zDbFilename = 0;
28002798
#endif
2801
- /***** Begin Fossil Patch *****/
2799
+ /***** Begin Fossil Patch *****/
28022800
{
28032801
extern void fossil_open(const char **);
28042802
fossil_open(&data.zDbFilename);
28052803
}
28062804
/***** End Fossil Patch *****/
28072805
--- src/shell.c
+++ src/shell.c
@@ -336,22 +336,20 @@
336 */
337 static char *local_getline(char *zPrompt, FILE *in){
338 char *zLine;
339 int nLine;
340 int n;
341 int eol;
342
343 if( zPrompt && *zPrompt ){
344 printf("%s",zPrompt);
345 fflush(stdout);
346 }
347 nLine = 100;
348 zLine = malloc( nLine );
349 if( zLine==0 ) return 0;
350 n = 0;
351 eol = 0;
352 while( !eol ){
353 if( n+100>nLine ){
354 nLine = nLine*2 + 100;
355 zLine = realloc(zLine, nLine);
356 if( zLine==0 ) return 0;
357 }
@@ -359,19 +357,18 @@
359 if( n==0 ){
360 free(zLine);
361 return 0;
362 }
363 zLine[n] = 0;
364 eol = 1;
365 break;
366 }
367 while( zLine[n] ){ n++; }
368 if( n>0 && zLine[n-1]=='\n' ){
369 n--;
370 if( n>0 && zLine[n-1]=='\r' ) n--;
371 zLine[n] = 0;
372 eol = 1;
373 }
374 }
375 zLine = realloc( zLine, n+1 );
376 return zLine;
377 }
@@ -1095,10 +1092,11 @@
1095 struct callback_data *pArg, /* Pointer to struct callback_data */
1096 char **pzErrMsg /* Error msg written here */
1097 ){
1098 sqlite3_stmt *pStmt = NULL; /* Statement to execute. */
1099 int rc = SQLITE_OK; /* Return Code */
 
1100 const char *zLeftover; /* Tail of unprocessed SQL */
1101
1102 if( pzErrMsg ){
1103 *pzErrMsg = NULL;
1104 }
@@ -1188,11 +1186,12 @@
1188 }
1189
1190 /* Finalize the statement just executed. If this fails, save a
1191 ** copy of the error message. Otherwise, set zSql to point to the
1192 ** next statement to execute. */
1193 rc = sqlite3_finalize(pStmt);
 
1194 if( rc==SQLITE_OK ){
1195 zSql = zLeftover;
1196 while( IsSpace(zSql[0]) ) zSql++;
1197 }else if( pzErrMsg ){
1198 *pzErrMsg = save_err_msg(db);
@@ -1760,11 +1759,10 @@
1760 }
1761 sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
1762 zCommit = "COMMIT";
1763 while( (zLine = local_getline(0, in))!=0 ){
1764 char *z;
1765 i = 0;
1766 lineno++;
1767 azCol[0] = zLine;
1768 for(i=0, z=zLine; *z && *z!='\n' && *z!='\r'; z++){
1769 if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
1770 *z = 0;
@@ -2235,11 +2233,11 @@
2235 for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
2236 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
2237 if( testctrl<0 ){
2238 testctrl = aCtrl[i].ctrlCode;
2239 }else{
2240 fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[i]);
2241 testctrl = -1;
2242 break;
2243 }
2244 }
2245 }
@@ -2743,10 +2741,11 @@
2743 ** we do the actual processing of arguments later in a second pass.
2744 */
2745 }else if( strcmp(argv[i],"-batch")==0 ){
2746 stdin_is_interactive = 0;
2747 }else if( strcmp(argv[i],"-heap")==0 ){
 
2748 int j, c;
2749 const char *zSize;
2750 sqlite3_int64 szHeap;
2751
2752 zSize = argv[++i];
@@ -2755,11 +2754,10 @@
2755 if( c=='M' ){ szHeap *= 1000000; break; }
2756 if( c=='K' ){ szHeap *= 1000; break; }
2757 if( c=='G' ){ szHeap *= 1000000000; break; }
2758 }
2759 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
2760 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
2761 sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
2762 #endif
2763 #ifdef SQLITE_ENABLE_VFSTRACE
2764 }else if( strcmp(argv[i],"-vfstrace")==0 ){
2765 extern int vfstrace_register(
@@ -2796,11 +2794,11 @@
2796 #ifndef SQLITE_OMIT_MEMORYDB
2797 data.zDbFilename = ":memory:";
2798 #else
2799 data.zDbFilename = 0;
2800 #endif
2801 /***** Begin Fossil Patch *****/
2802 {
2803 extern void fossil_open(const char **);
2804 fossil_open(&data.zDbFilename);
2805 }
2806 /***** End Fossil Patch *****/
2807
--- src/shell.c
+++ src/shell.c
@@ -336,22 +336,20 @@
336 */
337 static char *local_getline(char *zPrompt, FILE *in){
338 char *zLine;
339 int nLine;
340 int n;
 
341
342 if( zPrompt && *zPrompt ){
343 printf("%s",zPrompt);
344 fflush(stdout);
345 }
346 nLine = 100;
347 zLine = malloc( nLine );
348 if( zLine==0 ) return 0;
349 n = 0;
350 while( 1 ){
 
351 if( n+100>nLine ){
352 nLine = nLine*2 + 100;
353 zLine = realloc(zLine, nLine);
354 if( zLine==0 ) return 0;
355 }
@@ -359,19 +357,18 @@
357 if( n==0 ){
358 free(zLine);
359 return 0;
360 }
361 zLine[n] = 0;
 
362 break;
363 }
364 while( zLine[n] ){ n++; }
365 if( n>0 && zLine[n-1]=='\n' ){
366 n--;
367 if( n>0 && zLine[n-1]=='\r' ) n--;
368 zLine[n] = 0;
369 break;
370 }
371 }
372 zLine = realloc( zLine, n+1 );
373 return zLine;
374 }
@@ -1095,10 +1092,11 @@
1092 struct callback_data *pArg, /* Pointer to struct callback_data */
1093 char **pzErrMsg /* Error msg written here */
1094 ){
1095 sqlite3_stmt *pStmt = NULL; /* Statement to execute. */
1096 int rc = SQLITE_OK; /* Return Code */
1097 int rc2;
1098 const char *zLeftover; /* Tail of unprocessed SQL */
1099
1100 if( pzErrMsg ){
1101 *pzErrMsg = NULL;
1102 }
@@ -1188,11 +1186,12 @@
1186 }
1187
1188 /* Finalize the statement just executed. If this fails, save a
1189 ** copy of the error message. Otherwise, set zSql to point to the
1190 ** next statement to execute. */
1191 rc2 = sqlite3_finalize(pStmt);
1192 if( rc!=SQLITE_NOMEM ) rc = rc2;
1193 if( rc==SQLITE_OK ){
1194 zSql = zLeftover;
1195 while( IsSpace(zSql[0]) ) zSql++;
1196 }else if( pzErrMsg ){
1197 *pzErrMsg = save_err_msg(db);
@@ -1760,11 +1759,10 @@
1759 }
1760 sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
1761 zCommit = "COMMIT";
1762 while( (zLine = local_getline(0, in))!=0 ){
1763 char *z;
 
1764 lineno++;
1765 azCol[0] = zLine;
1766 for(i=0, z=zLine; *z && *z!='\n' && *z!='\r'; z++){
1767 if( *z==p->separator[0] && strncmp(z, p->separator, nSep)==0 ){
1768 *z = 0;
@@ -2235,11 +2233,11 @@
2233 for(i=0; i<(int)(sizeof(aCtrl)/sizeof(aCtrl[0])); i++){
2234 if( strncmp(azArg[1], aCtrl[i].zCtrlName, n)==0 ){
2235 if( testctrl<0 ){
2236 testctrl = aCtrl[i].ctrlCode;
2237 }else{
2238 fprintf(stderr, "ambiguous option name: \"%s\"\n", azArg[1]);
2239 testctrl = -1;
2240 break;
2241 }
2242 }
2243 }
@@ -2743,10 +2741,11 @@
2741 ** we do the actual processing of arguments later in a second pass.
2742 */
2743 }else if( strcmp(argv[i],"-batch")==0 ){
2744 stdin_is_interactive = 0;
2745 }else if( strcmp(argv[i],"-heap")==0 ){
2746 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
2747 int j, c;
2748 const char *zSize;
2749 sqlite3_int64 szHeap;
2750
2751 zSize = argv[++i];
@@ -2755,11 +2754,10 @@
2754 if( c=='M' ){ szHeap *= 1000000; break; }
2755 if( c=='K' ){ szHeap *= 1000; break; }
2756 if( c=='G' ){ szHeap *= 1000000000; break; }
2757 }
2758 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
 
2759 sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
2760 #endif
2761 #ifdef SQLITE_ENABLE_VFSTRACE
2762 }else if( strcmp(argv[i],"-vfstrace")==0 ){
2763 extern int vfstrace_register(
@@ -2796,11 +2794,11 @@
2794 #ifndef SQLITE_OMIT_MEMORYDB
2795 data.zDbFilename = ":memory:";
2796 #else
2797 data.zDbFilename = 0;
2798 #endif
2799 /***** Begin Fossil Patch *****/
2800 {
2801 extern void fossil_open(const char **);
2802 fossil_open(&data.zDbFilename);
2803 }
2804 /***** End Fossil Patch *****/
2805
+240 -230
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656656
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657657
** [sqlite_version()] and [sqlite_source_id()].
658658
*/
659659
#define SQLITE_VERSION "3.7.9"
660660
#define SQLITE_VERSION_NUMBER 3007009
661
-#define SQLITE_SOURCE_ID "2011-10-11 20:41:54 b94a80a832777f0e639f6a81fcfe169bf970a8c0"
661
+#define SQLITE_SOURCE_ID "2011-10-15 00:16:30 39408702a989f907261c298bf0947f3e68bd10fe"
662662
663663
/*
664664
** CAPI3REF: Run-Time Library Version Numbers
665665
** KEYWORDS: sqlite3_version, sqlite3_sourceid
666666
**
@@ -3351,11 +3351,12 @@
33513351
** zSql string ends at either the first '\000' or '\u0000' character or
33523352
** the nByte-th byte, whichever comes first. If the caller knows
33533353
** that the supplied string is nul-terminated, then there is a small
33543354
** performance advantage to be gained by passing an nByte parameter that
33553355
** is equal to the number of bytes in the input string <i>including</i>
3356
-** the nul-terminator bytes.
3356
+** the nul-terminator bytes as this saves SQLite from having to
3357
+** make a copy of the input string.
33573358
**
33583359
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
33593360
** past the end of the first SQL statement in zSql. These routines only
33603361
** compile the first statement in zSql, so *pzTail is left pointing to
33613362
** what remains uncompiled.
@@ -3572,10 +3573,17 @@
35723573
** ^(In those routines that have a fourth argument, its value is the
35733574
** number of bytes in the parameter. To be clear: the value is the
35743575
** number of <u>bytes</u> in the value, not the number of characters.)^
35753576
** ^If the fourth parameter is negative, the length of the string is
35763577
** the number of bytes up to the first zero terminator.
3578
+** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3579
+** or sqlite3_bind_text16() then that parameter must be the byte offset
3580
+** where the NUL terminator would occur assuming the string were NUL
3581
+** terminated. If any NUL characters occur at byte offsets less than
3582
+** the value of the fourth parameter then the resulting string value will
3583
+** contain embedded NULs. The result of expressions involving strings
3584
+** with embedded NULs is undefined.
35773585
**
35783586
** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
35793587
** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
35803588
** string after SQLite has finished with it. ^The destructor is called
35813589
** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
@@ -4590,11 +4598,16 @@
45904598
** is negative, then SQLite takes result text from the 2nd parameter
45914599
** through the first zero character.
45924600
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
45934601
** is non-negative, then as many bytes (not characters) of the text
45944602
** pointed to by the 2nd parameter are taken as the application-defined
4595
-** function result.
4603
+** function result. If the 3rd parameter is non-negative, then it
4604
+** must be the byte offset into the string where the NUL terminator would
4605
+** appear if the string where NUL terminated. If any NUL characters occur
4606
+** in the string at a byte offset that is less than the value of the 3rd
4607
+** parameter, then the resulting string will contain embedded NULs and the
4608
+** result of expressions operating on strings with embedded NULs is undefined.
45964609
** ^If the 4th parameter to the sqlite3_result_text* interfaces
45974610
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
45984611
** function as the destructor on the text or BLOB result when it has
45994612
** finished using that result.
46004613
** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
@@ -9315,18 +9328,21 @@
93159328
/*
93169329
** If this is a no-op implementation, implement everything as macros.
93179330
*/
93189331
#define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
93199332
#define sqlite3_mutex_free(X)
9320
-#define sqlite3_mutex_enter(X)
9333
+#define sqlite3_mutex_enter(X)
93219334
#define sqlite3_mutex_try(X) SQLITE_OK
9322
-#define sqlite3_mutex_leave(X)
9335
+#define sqlite3_mutex_leave(X)
93239336
#define sqlite3_mutex_held(X) ((void)(X),1)
93249337
#define sqlite3_mutex_notheld(X) ((void)(X),1)
93259338
#define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
93269339
#define sqlite3MutexInit() SQLITE_OK
93279340
#define sqlite3MutexEnd()
9341
+#define MUTEX_LOGIC(X)
9342
+#else
9343
+#define MUTEX_LOGIC(X) X
93289344
#endif /* defined(SQLITE_MUTEX_OMIT) */
93299345
93309346
/************** End of mutex.h ***********************************************/
93319347
/************** Continuing where we left off in sqliteInt.h ******************/
93329348
@@ -11754,19 +11770,21 @@
1175411770
# define sqlite3VtabInSync(db) 0
1175511771
# define sqlite3VtabLock(X)
1175611772
# define sqlite3VtabUnlock(X)
1175711773
# define sqlite3VtabUnlockList(X)
1175811774
# define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
11775
+# define sqlite3GetVTable(X,Y) ((VTable*)0)
1175911776
#else
1176011777
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
1176111778
SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
1176211779
SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
1176311780
SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
1176411781
SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
1176511782
SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
1176611783
SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
1176711784
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
11785
+SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
1176811786
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
1176911787
#endif
1177011788
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
1177111789
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
1177211790
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
@@ -11782,11 +11800,10 @@
1178211800
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
1178311801
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
1178411802
SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
1178511803
SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
1178611804
SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
11787
-SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
1178811805
SQLITE_PRIVATE const char *sqlite3JournalModename(int);
1178911806
SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*);
1179011807
SQLITE_PRIVATE int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
1179111808
1179211809
/* Declarations for functions in fkey.c. All of these are replaced by
@@ -13558,16 +13575,22 @@
1355813575
}
1355913576
return 0;
1356013577
}
1356113578
1356213579
/*
13563
-** Set the time to the current time reported by the VFS
13580
+** Set the time to the current time reported by the VFS.
13581
+**
13582
+** Return the number of errors.
1356413583
*/
13565
-static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
13584
+static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
1356613585
sqlite3 *db = sqlite3_context_db_handle(context);
13567
- sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
13568
- p->validJD = 1;
13586
+ if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
13587
+ p->validJD = 1;
13588
+ return 0;
13589
+ }else{
13590
+ return 1;
13591
+ }
1356913592
}
1357013593
1357113594
/*
1357213595
** Attempt to parse the given string into a Julian Day Number. Return
1357313596
** the number of errors.
@@ -13593,12 +13616,11 @@
1359313616
if( parseYyyyMmDd(zDate,p)==0 ){
1359413617
return 0;
1359513618
}else if( parseHhMmSs(zDate, p)==0 ){
1359613619
return 0;
1359713620
}else if( sqlite3StrICmp(zDate,"now")==0){
13598
- setDateTimeToCurrent(context, p);
13599
- return 0;
13621
+ return setDateTimeToCurrent(context, p);
1360013622
}else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
1360113623
p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
1360213624
p->validJD = 1;
1360313625
return 0;
1360413626
}
@@ -14021,12 +14043,13 @@
1402114043
int i;
1402214044
const unsigned char *z;
1402314045
int eType;
1402414046
memset(p, 0, sizeof(*p));
1402514047
if( argc==0 ){
14026
- setDateTimeToCurrent(context, p);
14027
- }else if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
14048
+ return setDateTimeToCurrent(context, p);
14049
+ }
14050
+ if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
1402814051
|| eType==SQLITE_INTEGER ){
1402914052
p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
1403014053
p->validJD = 1;
1403114054
}else{
1403214055
z = sqlite3_value_text(argv[0]);
@@ -14334,35 +14357,32 @@
1433414357
){
1433514358
time_t t;
1433614359
char *zFormat = (char *)sqlite3_user_data(context);
1433714360
sqlite3 *db;
1433814361
sqlite3_int64 iT;
14362
+ struct tm *pTm;
14363
+ struct tm sNow;
1433914364
char zBuf[20];
1434014365
1434114366
UNUSED_PARAMETER(argc);
1434214367
UNUSED_PARAMETER(argv);
1434314368
1434414369
db = sqlite3_context_db_handle(context);
14345
- sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
14370
+ if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
1434614371
t = iT/1000 - 10000*(sqlite3_int64)21086676;
1434714372
#ifdef HAVE_GMTIME_R
14348
- {
14349
- struct tm sNow;
14350
- gmtime_r(&t, &sNow);
14373
+ pTm = gmtime_r(&t, &sNow);
14374
+#else
14375
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14376
+ pTm = gmtime(&t);
14377
+ if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
14378
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14379
+#endif
14380
+ if( pTm ){
1435114381
strftime(zBuf, 20, zFormat, &sNow);
14352
- }
14353
-#else
14354
- {
14355
- struct tm *pTm;
14356
- sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14357
- pTm = gmtime(&t);
14358
- strftime(zBuf, 20, zFormat, pTm);
14359
- sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14360
- }
14361
-#endif
14362
-
14363
- sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
14382
+ sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
14383
+ }
1436414384
}
1436514385
#endif
1436614386
1436714387
/*
1436814388
** This function registered all of the above C functions as SQL
@@ -14693,16 +14713,16 @@
1469314713
** Register a VFS with the system. It is harmless to register the same
1469414714
** VFS multiple times. The new VFS becomes the default if makeDflt is
1469514715
** true.
1469614716
*/
1469714717
SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
14698
- sqlite3_mutex *mutex = 0;
14718
+ MUTEX_LOGIC(sqlite3_mutex *mutex;)
1469914719
#ifndef SQLITE_OMIT_AUTOINIT
1470014720
int rc = sqlite3_initialize();
1470114721
if( rc ) return rc;
1470214722
#endif
14703
- mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
14723
+ MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
1470414724
sqlite3_mutex_enter(mutex);
1470514725
vfsUnlink(pVfs);
1470614726
if( makeDflt || vfsList==0 ){
1470714727
pVfs->pNext = vfsList;
1470814728
vfsList = pVfs;
@@ -18946,52 +18966,14 @@
1894618966
** an historical reference. Most of the "enhancements" have been backed
1894718967
** out so that the functionality is now the same as standard printf().
1894818968
**
1894918969
**************************************************************************
1895018970
**
18951
-** The following modules is an enhanced replacement for the "printf" subroutines
18952
-** found in the standard C library. The following enhancements are
18953
-** supported:
18954
-**
18955
-** + Additional functions. The standard set of "printf" functions
18956
-** includes printf, fprintf, sprintf, vprintf, vfprintf, and
18957
-** vsprintf. This module adds the following:
18958
-**
18959
-** * snprintf -- Works like sprintf, but has an extra argument
18960
-** which is the size of the buffer written to.
18961
-**
18962
-** * mprintf -- Similar to sprintf. Writes output to memory
18963
-** obtained from malloc.
18964
-**
18965
-** * xprintf -- Calls a function to dispose of output.
18966
-**
18967
-** * nprintf -- No output, but returns the number of characters
18968
-** that would have been output by printf.
18969
-**
18970
-** * A v- version (ex: vsnprintf) of every function is also
18971
-** supplied.
18972
-**
18973
-** + A few extensions to the formatting notation are supported:
18974
-**
18975
-** * The "=" flag (similar to "-") causes the output to be
18976
-** be centered in the appropriately sized field.
18977
-**
18978
-** * The %b field outputs an integer in binary notation.
18979
-**
18980
-** * The %c field now accepts a precision. The character output
18981
-** is repeated by the number of times the precision specifies.
18982
-**
18983
-** * The %' field works like %c, but takes as its character the
18984
-** next character of the format string, instead of the next
18985
-** argument. For example, printf("%.78'-") prints 78 minus
18986
-** signs, the same as printf("%.78c",'-').
18987
-**
18988
-** + When compiled using GCC on a SPARC, this version of printf is
18989
-** faster than the library printf for SUN OS 4.1.
18990
-**
18991
-** + All functions are fully reentrant.
18992
-**
18971
+** This file contains code for a set of "printf"-like routines. These
18972
+** routines format strings much like the printf() from the standard C
18973
+** library, though the implementation here has enhancements to support
18974
+** SQLlite.
1899318975
*/
1899418976
1899518977
/*
1899618978
** Conversion types fall into various categories as defined by the
1899718979
** following enumeration.
@@ -19125,43 +19107,19 @@
1912519107
}
1912619108
}
1912719109
1912819110
/*
1912919111
** On machines with a small stack size, you can redefine the
19130
-** SQLITE_PRINT_BUF_SIZE to be less than 350.
19112
+** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
1913119113
*/
1913219114
#ifndef SQLITE_PRINT_BUF_SIZE
1913319115
# define SQLITE_PRINT_BUF_SIZE 70
1913419116
#endif
1913519117
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
1913619118
1913719119
/*
19138
-** The root program. All variations call this core.
19139
-**
19140
-** INPUTS:
19141
-** func This is a pointer to a function taking three arguments
19142
-** 1. A pointer to anything. Same as the "arg" parameter.
19143
-** 2. A pointer to the list of characters to be output
19144
-** (Note, this list is NOT null terminated.)
19145
-** 3. An integer number of characters to be output.
19146
-** (Note: This number might be zero.)
19147
-**
19148
-** arg This is the pointer to anything which will be passed as the
19149
-** first argument to "func". Use it for whatever you like.
19150
-**
19151
-** fmt This is the format string, as in the usual print.
19152
-**
19153
-** ap This is a pointer to a list of arguments. Same as in
19154
-** vfprint.
19155
-**
19156
-** OUTPUTS:
19157
-** The return value is the total number of characters sent to
19158
-** the function "func". Returns -1 on a error.
19159
-**
19160
-** Note that the order in which automatic variables are declared below
19161
-** seems to make a big difference in determining how fast this beast
19162
-** will run.
19120
+** Render a string given by "fmt" into the StrAccum object.
1916319121
*/
1916419122
SQLITE_PRIVATE void sqlite3VXPrintf(
1916519123
StrAccum *pAccum, /* Accumulate results here */
1916619124
int useExtended, /* Allow extended %-conversions */
1916719125
const char *fmt, /* Format string */
@@ -19180,28 +19138,27 @@
1918019138
etByte flag_altform2; /* True if "!" flag is present */
1918119139
etByte flag_zeropad; /* True if field width constant starts with zero */
1918219140
etByte flag_long; /* True if "l" flag is present */
1918319141
etByte flag_longlong; /* True if the "ll" flag is present */
1918419142
etByte done; /* Loop termination flag */
19143
+ etByte xtype = 0; /* Conversion paradigm */
19144
+ char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
1918519145
sqlite_uint64 longvalue; /* Value for integer types */
1918619146
LONGDOUBLE_TYPE realvalue; /* Value for real types */
1918719147
const et_info *infop; /* Pointer to the appropriate info structure */
19188
- char buf[etBUFSIZE]; /* Conversion buffer */
1918919148
char *zOut; /* Rendering buffer */
1919019149
int nOut; /* Size of the rendering buffer */
19191
- char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
19192
- etByte xtype = 0; /* Conversion paradigm */
19193
- char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
19150
+ char *zExtra; /* Malloced memory used by some conversion */
1919419151
#ifndef SQLITE_OMIT_FLOATING_POINT
1919519152
int exp, e2; /* exponent of real numbers */
19153
+ int nsd; /* Number of significant digits returned */
1919619154
double rounder; /* Used for rounding floating point values */
1919719155
etByte flag_dp; /* True if decimal point should be shown */
1919819156
etByte flag_rtz; /* True if trailing zeros should be removed */
19199
- int nsd; /* Number of significant digits returned */
1920019157
#endif
19158
+ char buf[etBUFSIZE]; /* Conversion buffer */
1920119159
19202
- length = 0;
1920319160
bufpt = 0;
1920419161
for(; (c=(*fmt))!=0; ++fmt){
1920519162
if( c!='%' ){
1920619163
int amt;
1920719164
bufpt = (char *)fmt;
@@ -19692,10 +19649,11 @@
1969219649
if( p->tooBig | p->mallocFailed ){
1969319650
testcase(p->tooBig);
1969419651
testcase(p->mallocFailed);
1969519652
return;
1969619653
}
19654
+ assert( p->zText!=0 || p->nChar==0 );
1969719655
if( N<0 ){
1969819656
N = sqlite3Strlen30(z);
1969919657
}
1970019658
if( N==0 || NEVER(z==0) ){
1970119659
return;
@@ -19723,19 +19681,20 @@
1972319681
zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
1972419682
}else{
1972519683
zNew = sqlite3_realloc(zOld, p->nAlloc);
1972619684
}
1972719685
if( zNew ){
19728
- if( zOld==0 ) memcpy(zNew, p->zText, p->nChar);
19686
+ if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
1972919687
p->zText = zNew;
1973019688
}else{
1973119689
p->mallocFailed = 1;
1973219690
sqlite3StrAccumReset(p);
1973319691
return;
1973419692
}
1973519693
}
1973619694
}
19695
+ assert( p->zText );
1973719696
memcpy(&p->zText[p->nChar], z, N);
1973819697
p->nChar += N;
1973919698
}
1974019699
1974119700
/*
@@ -25172,11 +25131,11 @@
2517225131
return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
2517325132
}
2517425133
#endif
2517525134
2517625135
25177
-#ifdef SQLITE_DEBUG
25136
+#if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
2517825137
/*
2517925138
** Helper function for printing out trace information from debugging
2518025139
** binaries. This returns the string represetation of the supplied
2518125140
** integer lock-type.
2518225141
*/
@@ -26007,18 +25966,18 @@
2600725966
** locking a random byte from a range, concurrent SHARED locks may exist
2600825967
** even if the locking primitive used is always a write-lock.
2600925968
*/
2601025969
int rc = SQLITE_OK;
2601125970
unixFile *pFile = (unixFile*)id;
26012
- unixInodeInfo *pInode = pFile->pInode;
25971
+ unixInodeInfo *pInode;
2601325972
struct flock lock;
2601425973
int tErrno = 0;
2601525974
2601625975
assert( pFile );
2601725976
OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
2601825977
azFileLock(eFileLock), azFileLock(pFile->eFileLock),
26019
- azFileLock(pInode->eFileLock), pInode->nShared , getpid()));
25978
+ azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared , getpid()));
2602025979
2602125980
/* If there is already a lock of this type or more restrictive on the
2602225981
** unixFile, do nothing. Don't use the end_lock: exit path, as
2602325982
** unixEnterMutex() hasn't been called yet.
2602425983
*/
@@ -26218,11 +26177,10 @@
2621826177
static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
2621926178
unixFile *pFile = (unixFile*)id;
2622026179
unixInodeInfo *pInode;
2622126180
struct flock lock;
2622226181
int rc = SQLITE_OK;
26223
- int h;
2622426182
2622526183
assert( pFile );
2622626184
OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
2622726185
pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
2622826186
getpid()));
@@ -26230,18 +26188,14 @@
2623026188
assert( eFileLock<=SHARED_LOCK );
2623126189
if( pFile->eFileLock<=eFileLock ){
2623226190
return SQLITE_OK;
2623326191
}
2623426192
unixEnterMutex();
26235
- h = pFile->h;
2623626193
pInode = pFile->pInode;
2623726194
assert( pInode->nShared!=0 );
2623826195
if( pFile->eFileLock>SHARED_LOCK ){
2623926196
assert( pInode->eFileLock==pFile->eFileLock );
26240
- SimulateIOErrorBenign(1);
26241
- SimulateIOError( h=(-1) )
26242
- SimulateIOErrorBenign(0);
2624326197
2624426198
#ifndef NDEBUG
2624526199
/* When reducing a lock such that other processes can start
2624626200
** reading the database file again, make sure that the
2624726201
** transaction counter was updated if any part of the database
@@ -26248,15 +26202,10 @@
2624826202
** file changed. If the transaction counter is not updated,
2624926203
** other connections to the same file might not realize that
2625026204
** the file has changed and hence might not know to flush their
2625126205
** cache. The use of a stale cache can lead to database corruption.
2625226206
*/
26253
-#if 0
26254
- assert( pFile->inNormalWrite==0
26255
- || pFile->dbUpdate==0
26256
- || pFile->transCntrChng==1 );
26257
-#endif
2625826207
pFile->inNormalWrite = 0;
2625926208
#endif
2626026209
2626126210
/* downgrading to a shared lock on NFS involves clearing the write lock
2626226211
** before establishing the readlock - to avoid a race condition we downgrade
@@ -26354,13 +26303,10 @@
2635426303
pInode->nShared--;
2635526304
if( pInode->nShared==0 ){
2635626305
lock.l_type = F_UNLCK;
2635726306
lock.l_whence = SEEK_SET;
2635826307
lock.l_start = lock.l_len = 0L;
26359
- SimulateIOErrorBenign(1);
26360
- SimulateIOError( h=(-1) )
26361
- SimulateIOErrorBenign(0);
2636226308
if( unixFileLock(pFile, &lock)==0 ){
2636326309
pInode->eFileLock = NO_LOCK;
2636426310
}else{
2636526311
rc = SQLITE_IOERR_UNLOCK;
2636626312
pFile->lastErrno = errno;
@@ -29191,10 +29137,13 @@
2919129137
assert( zFilename==0 || zFilename[0]=='/'
2919229138
|| pVfs->pAppData==(void*)&autolockIoFinder );
2919329139
#else
2919429140
assert( zFilename==0 || zFilename[0]=='/' );
2919529141
#endif
29142
+
29143
+ /* No locking occurs in temporary files */
29144
+ assert( zFilename!=0 || noLock );
2919629145
2919729146
OSTRACE(("OPEN %-3d %s\n", h, zFilename));
2919829147
pNew->h = h;
2919929148
pNew->zPath = zFilename;
2920029149
if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
@@ -29293,10 +29242,11 @@
2929329242
/* Dotfile locking uses the file path so it needs to be included in
2929429243
** the dotlockLockingContext
2929529244
*/
2929629245
char *zLockFile;
2929729246
int nFilename;
29247
+ assert( zFilename!=0 );
2929829248
nFilename = (int)strlen(zFilename) + 6;
2929929249
zLockFile = (char *)sqlite3_malloc(nFilename);
2930029250
if( zLockFile==0 ){
2930129251
rc = SQLITE_NOMEM;
2930229252
}else{
@@ -30072,14 +30022,16 @@
3007230022
** the current time and date as a Julian Day number times 86_400_000. In
3007330023
** other words, write into *piNow the number of milliseconds since the Julian
3007430024
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
3007530025
** proleptic Gregorian calendar.
3007630026
**
30077
-** On success, return 0. Return 1 if the time and date cannot be found.
30027
+** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
30028
+** cannot be found.
3007830029
*/
3007930030
static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
3008030031
static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
30032
+ int rc = SQLITE_OK;
3008130033
#if defined(NO_GETTOD)
3008230034
time_t t;
3008330035
time(&t);
3008430036
*piNow = ((sqlite3_int64)t)*1000 + unixEpoch;
3008530037
#elif OS_VXWORKS
@@ -30086,34 +30038,38 @@
3008630038
struct timespec sNow;
3008730039
clock_gettime(CLOCK_REALTIME, &sNow);
3008830040
*piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
3008930041
#else
3009030042
struct timeval sNow;
30091
- gettimeofday(&sNow, 0);
30092
- *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
30043
+ if( gettimeofday(&sNow, 0)==0 ){
30044
+ *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
30045
+ }else{
30046
+ rc = SQLITE_ERROR;
30047
+ }
3009330048
#endif
3009430049
3009530050
#ifdef SQLITE_TEST
3009630051
if( sqlite3_current_time ){
3009730052
*piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
3009830053
}
3009930054
#endif
3010030055
UNUSED_PARAMETER(NotUsed);
30101
- return 0;
30056
+ return rc;
3010230057
}
3010330058
3010430059
/*
3010530060
** Find the current time (in Universal Coordinated Time). Write the
3010630061
** current time and date as a Julian Day number into *prNow and
3010730062
** return 0. Return 1 if the time and date cannot be found.
3010830063
*/
3010930064
static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
30110
- sqlite3_int64 i;
30065
+ sqlite3_int64 i = 0;
30066
+ int rc;
3011130067
UNUSED_PARAMETER(NotUsed);
30112
- unixCurrentTimeInt64(0, &i);
30068
+ rc = unixCurrentTimeInt64(0, &i);
3011330069
*prNow = i/86400000.0;
30114
- return 0;
30070
+ return rc;
3011530071
}
3011630072
3011730073
/*
3011830074
** We added the xGetLastError() method with the intention of providing
3011930075
** better low-level error messages when operating-system problems come up
@@ -34612,11 +34568,11 @@
3461234568
}
3461334569
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
3461434570
UNUSED_PARAMETER(pVfs);
3461534571
getLastErrorMsg(nBuf, zBufOut);
3461634572
}
34617
-void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
34573
+static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
3461834574
UNUSED_PARAMETER(pVfs);
3461934575
#if SQLITE_OS_WINCE
3462034576
/* The GetProcAddressA() routine is only available on wince. */
3462134577
return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol);
3462234578
#else
@@ -34623,11 +34579,11 @@
3462334579
/* All other windows platforms expect GetProcAddress() to take
3462434580
** an Ansi string regardless of the _UNICODE setting */
3462534581
return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol);
3462634582
#endif
3462734583
}
34628
-void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
34584
+static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
3462934585
UNUSED_PARAMETER(pVfs);
3463034586
FreeLibrary((HANDLE)pHandle);
3463134587
}
3463234588
#else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
3463334589
#define winDlOpen 0
@@ -34697,11 +34653,12 @@
3469734653
** the current time and date as a Julian Day number times 86_400_000. In
3469834654
** other words, write into *piNow the number of milliseconds since the Julian
3469934655
** epoch of noon in Greenwich on November 24, 4714 B.C according to the
3470034656
** proleptic Gregorian calendar.
3470134657
**
34702
-** On success, return 0. Return 1 if the time and date cannot be found.
34658
+** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
34659
+** cannot be found.
3470334660
*/
3470434661
static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
3470534662
/* FILETIME structure is a 64-bit value representing the number of
3470634663
100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
3470734664
*/
@@ -34717,11 +34674,11 @@
3471734674
#if SQLITE_OS_WINCE
3471834675
SYSTEMTIME time;
3471934676
GetSystemTime(&time);
3472034677
/* if SystemTimeToFileTime() fails, it returns zero. */
3472134678
if (!SystemTimeToFileTime(&time,&ft)){
34722
- return 1;
34679
+ return SQLITE_ERROR;
3472334680
}
3472434681
#else
3472534682
GetSystemTimeAsFileTime( &ft );
3472634683
#endif
3472734684
@@ -34733,19 +34690,19 @@
3473334690
if( sqlite3_current_time ){
3473434691
*piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
3473534692
}
3473634693
#endif
3473734694
UNUSED_PARAMETER(pVfs);
34738
- return 0;
34695
+ return SQLITE_OK;
3473934696
}
3474034697
3474134698
/*
3474234699
** Find the current time (in Universal Coordinated Time). Write the
3474334700
** current time and date as a Julian Day number into *prNow and
3474434701
** return 0. Return 1 if the time and date cannot be found.
3474534702
*/
34746
-int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
34703
+static int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
3474734704
int rc;
3474834705
sqlite3_int64 i;
3474934706
rc = winCurrentTimeInt64(pVfs, &i);
3475034707
if( !rc ){
3475134708
*prNow = i/86400000.0;
@@ -40068,11 +40025,10 @@
4006840025
needPagerReset = 0;
4006940026
}
4007040027
rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
4007140028
if( rc!=SQLITE_OK ){
4007240029
if( rc==SQLITE_DONE ){
40073
- rc = SQLITE_OK;
4007440030
pPager->journalOff = szJ;
4007540031
break;
4007640032
}else if( rc==SQLITE_IOERR_SHORT_READ ){
4007740033
/* If the journal has been truncated, simply stop reading and
4007840034
** processing the journal. This might happen if the journal was
@@ -40330,10 +40286,11 @@
4033040286
#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
4033140287
PgHdr *p; /* For looping over pages */
4033240288
#endif
4033340289
4033440290
assert( pPager->pWal );
40291
+ assert( pList );
4033540292
#ifdef SQLITE_DEBUG
4033640293
/* Verify that the page list is in accending order */
4033740294
for(p=pList; p && p->pDirty; p=p->pDirty){
4033840295
assert( p->pgno < p->pDirty->pgno );
4033940296
}
@@ -46566,11 +46523,11 @@
4656646523
*/
4656746524
if( iRead ){
4656846525
int sz;
4656946526
i64 iOffset;
4657046527
sz = pWal->hdr.szPage;
46571
- sz = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
46528
+ sz = (sz&0xfe00) + ((sz&0x0001)<<16);
4657246529
testcase( sz<=32768 );
4657346530
testcase( sz>=65536 );
4657446531
iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
4657546532
*pInWal = 1;
4657646533
/* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
@@ -49879,21 +49836,23 @@
4987949836
*/
4988049837
if( isMemdb==0 && isTempDb==0 ){
4988149838
if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
4988249839
int nFullPathname = pVfs->mxPathname+1;
4988349840
char *zFullPathname = sqlite3Malloc(nFullPathname);
49884
- sqlite3_mutex *mutexShared;
49841
+ MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
4988549842
p->sharable = 1;
4988649843
if( !zFullPathname ){
4988749844
sqlite3_free(p);
4988849845
return SQLITE_NOMEM;
4988949846
}
4989049847
sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
49848
+#if SQLITE_THREADSAFE
4989149849
mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
4989249850
sqlite3_mutex_enter(mutexOpen);
4989349851
mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
4989449852
sqlite3_mutex_enter(mutexShared);
49853
+#endif
4989549854
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
4989649855
assert( pBt->nRef>0 );
4989749856
if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
4989849857
&& sqlite3PagerVfs(pBt->pPager)==pVfs ){
4989949858
int iDb;
@@ -49995,13 +49954,13 @@
4999549954
4999649955
#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
4999749956
/* Add the new BtShared object to the linked list sharable BtShareds.
4999849957
*/
4999949958
if( p->sharable ){
50000
- sqlite3_mutex *mutexShared;
49959
+ MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
5000149960
pBt->nRef = 1;
50002
- mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
49961
+ MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);)
5000349962
if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
5000449963
pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
5000549964
if( pBt->mutex==0 ){
5000649965
rc = SQLITE_NOMEM;
5000749966
db->mallocFailed = 0;
@@ -50079,16 +50038,16 @@
5007950038
** true if the BtShared.nRef counter reaches zero and return
5008050039
** false if it is still positive.
5008150040
*/
5008250041
static int removeFromSharingList(BtShared *pBt){
5008350042
#ifndef SQLITE_OMIT_SHARED_CACHE
50084
- sqlite3_mutex *pMaster;
50043
+ MUTEX_LOGIC( sqlite3_mutex *pMaster; )
5008550044
BtShared *pList;
5008650045
int removed = 0;
5008750046
5008850047
assert( sqlite3_mutex_notheld(pBt->mutex) );
50089
- pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
50048
+ MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
5009050049
sqlite3_mutex_enter(pMaster);
5009150050
pBt->nRef--;
5009250051
if( pBt->nRef<=0 ){
5009350052
if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
5009450053
GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
@@ -52698,11 +52657,10 @@
5269852657
}
5269952658
}
5270052659
if( c==0 ){
5270152660
if( pPage->intKey && !pPage->leaf ){
5270252661
lwr = idx;
52703
- upr = lwr - 1;
5270452662
break;
5270552663
}else{
5270652664
*pRes = 0;
5270752665
rc = SQLITE_OK;
5270852666
goto moveto_finish;
@@ -52716,11 +52674,11 @@
5271652674
if( lwr>upr ){
5271752675
break;
5271852676
}
5271952677
pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
5272052678
}
52721
- assert( lwr==upr+1 );
52679
+ assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
5272252680
assert( pPage->isInit );
5272352681
if( pPage->leaf ){
5272452682
chldPg = 0;
5272552683
}else if( lwr>=pPage->nCell ){
5272652684
chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
@@ -52981,10 +52939,12 @@
5298152939
}
5298252940
if( rc ){
5298352941
pTrunk = 0;
5298452942
goto end_allocate_page;
5298552943
}
52944
+ assert( pTrunk!=0 );
52945
+ assert( pTrunk->aData!=0 );
5298652946
5298752947
k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
5298852948
if( k==0 && !searchList ){
5298952949
/* The trunk has no leaves and the list is not being searched.
5299052950
** So extract the trunk page itself and use it as the newly
@@ -54108,17 +54068,19 @@
5410854068
** This is safe because dropping a cell only overwrites the first
5410954069
** four bytes of it, and this function does not need the first
5411054070
** four bytes of the divider cell. So the pointer is safe to use
5411154071
** later on.
5411254072
**
54113
- ** Unless SQLite is compiled in secure-delete mode. In this case,
54073
+ ** But not if we are in secure-delete mode. In secure-delete mode,
5411454074
** the dropCell() routine will overwrite the entire cell with zeroes.
5411554075
** In this case, temporarily copy the cell into the aOvflSpace[]
5411654076
** buffer. It will be copied out again as soon as the aSpace[] buffer
5411754077
** is allocated. */
5411854078
if( pBt->secureDelete ){
54119
- int iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
54079
+ int iOff;
54080
+
54081
+ iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
5412054082
if( (iOff+szNew[i])>(int)pBt->usableSize ){
5412154083
rc = SQLITE_CORRUPT_BKPT;
5412254084
memset(apOld, 0, (i+1)*sizeof(MemPage*));
5412354085
goto balance_cleanup;
5412454086
}else{
@@ -54534,10 +54496,11 @@
5453454496
int isDivider = 0;
5453554497
while( i==iNextOld ){
5453654498
/* Cell i is the cell immediately following the last cell on old
5453754499
** sibling page j. If the siblings are not leaf pages of an
5453854500
** intkey b-tree, then cell i was a divider cell. */
54501
+ assert( j+1 < ArraySize(apCopy) );
5453954502
pOld = apCopy[++j];
5454054503
iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
5454154504
if( pOld->nOverflow ){
5454254505
nOverflow = pOld->nOverflow;
5454354506
iOverflow = i + !leafData + pOld->aOvfl[0].idx;
@@ -56876,18 +56839,18 @@
5687656839
/*
5687756840
** Release all resources associated with an sqlite3_backup* handle.
5687856841
*/
5687956842
SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p){
5688056843
sqlite3_backup **pp; /* Ptr to head of pagers backup list */
56881
- sqlite3_mutex *mutex; /* Mutex to protect source database */
56844
+ MUTEX_LOGIC( sqlite3_mutex *mutex; ) /* Mutex to protect source database */
5688256845
int rc; /* Value to return */
5688356846
5688456847
/* Enter the mutexes */
5688556848
if( p==0 ) return SQLITE_OK;
5688656849
sqlite3_mutex_enter(p->pSrcDb->mutex);
5688756850
sqlite3BtreeEnter(p->pSrc);
56888
- mutex = p->pSrcDb->mutex;
56851
+ MUTEX_LOGIC( mutex = p->pSrcDb->mutex; )
5688956852
if( p->pDestDb ){
5689056853
sqlite3_mutex_enter(p->pDestDb->mutex);
5689156854
}
5689256855
5689356856
/* Detach this backup from the source pager. */
@@ -58983,34 +58946,33 @@
5898358946
** Change the comment on the the most recently coded instruction. Or
5898458947
** insert a No-op and add the comment to that new instruction. This
5898558948
** makes the code easier to read during debugging. None of this happens
5898658949
** in a production build.
5898758950
*/
58988
-SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
58989
- va_list ap;
58990
- if( !p ) return;
58951
+static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
5899158952
assert( p->nOp>0 || p->aOp==0 );
5899258953
assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
5899358954
if( p->nOp ){
58994
- char **pz = &p->aOp[p->nOp-1].zComment;
58955
+ assert( p->aOp );
58956
+ sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
58957
+ p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
58958
+ }
58959
+}
58960
+SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
58961
+ va_list ap;
58962
+ if( p ){
5899558963
va_start(ap, zFormat);
58996
- sqlite3DbFree(p->db, *pz);
58997
- *pz = sqlite3VMPrintf(p->db, zFormat, ap);
58964
+ vdbeVComment(p, zFormat, ap);
5899858965
va_end(ap);
5899958966
}
5900058967
}
5900158968
SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe *p, const char *zFormat, ...){
5900258969
va_list ap;
59003
- if( !p ) return;
59004
- sqlite3VdbeAddOp0(p, OP_Noop);
59005
- assert( p->nOp>0 || p->aOp==0 );
59006
- assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
59007
- if( p->nOp ){
59008
- char **pz = &p->aOp[p->nOp-1].zComment;
58970
+ if( p ){
58971
+ sqlite3VdbeAddOp0(p, OP_Noop);
5900958972
va_start(ap, zFormat);
59010
- sqlite3DbFree(p->db, *pz);
59011
- *pz = sqlite3VMPrintf(p->db, zFormat, ap);
58973
+ vdbeVComment(p, zFormat, ap);
5901258974
va_end(ap);
5901358975
}
5901458976
}
5901558977
#endif /* NDEBUG */
5901658978
@@ -61266,11 +61228,11 @@
6126661228
** than 2GiB are support - anything large must be database corruption.
6126761229
** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
6126861230
** this code can safely assume that nCellKey is 32-bits
6126961231
*/
6127061232
assert( sqlite3BtreeCursorIsValid(pCur) );
61271
- rc = sqlite3BtreeKeySize(pCur, &nCellKey);
61233
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
6127261234
assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
6127361235
assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
6127461236
6127561237
/* Read in the complete content of the index entry */
6127661238
memset(&m, 0, sizeof(m));
@@ -61341,11 +61303,11 @@
6134161303
int rc;
6134261304
BtCursor *pCur = pC->pCursor;
6134361305
Mem m;
6134461306
6134561307
assert( sqlite3BtreeCursorIsValid(pCur) );
61346
- rc = sqlite3BtreeKeySize(pCur, &nCellKey);
61308
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
6134761309
assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
6134861310
/* nCellKey will always be between 0 and 0xffffffff because of the say
6134961311
** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
6135061312
if( nCellKey<=0 || nCellKey>0x7fffffff ){
6135161313
*res = 0;
@@ -65617,20 +65579,20 @@
6561765579
}else if( u.am.pC->cacheStatus==p->cacheCtr ){
6561865580
u.am.payloadSize = u.am.pC->payloadSize;
6561965581
u.am.zRec = (char*)u.am.pC->aRow;
6562065582
}else if( u.am.pC->isIndex ){
6562165583
assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) );
65622
- rc = sqlite3BtreeKeySize(u.am.pCrsr, &u.am.payloadSize64);
65584
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(u.am.pCrsr, &u.am.payloadSize64);
6562365585
assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
6562465586
/* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
6562565587
** payload size, so it is impossible for u.am.payloadSize64 to be
6562665588
** larger than 32 bits. */
6562765589
assert( (u.am.payloadSize64 & SQLITE_MAX_U32)==(u64)u.am.payloadSize64 );
6562865590
u.am.payloadSize = (u32)u.am.payloadSize64;
6562965591
}else{
6563065592
assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) );
65631
- rc = sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize);
65593
+ VVA_ONLY(rc =) sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize);
6563265594
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
6563365595
}
6563465596
}else if( ALWAYS(u.am.pC->pseudoTableReg>0) ){
6563565597
u.am.pReg = &aMem[u.am.pC->pseudoTableReg];
6563665598
assert( u.am.pReg->flags & MEM_Blob );
@@ -67678,18 +67640,18 @@
6767867640
rc = sqlite3VdbeCursorMoveto(u.bk.pC);
6767967641
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
6768067642
6768167643
if( u.bk.pC->isIndex ){
6768267644
assert( !u.bk.pC->isTable );
67683
- rc = sqlite3BtreeKeySize(u.bk.pCrsr, &u.bk.n64);
67645
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bk.pCrsr, &u.bk.n64);
6768467646
assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
6768567647
if( u.bk.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6768667648
goto too_big;
6768767649
}
6768867650
u.bk.n = (u32)u.bk.n64;
6768967651
}else{
67690
- rc = sqlite3BtreeDataSize(u.bk.pCrsr, &u.bk.n);
67652
+ VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bk.pCrsr, &u.bk.n);
6769167653
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
6769267654
if( u.bk.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
6769367655
goto too_big;
6769467656
}
6769567657
}
@@ -73322,11 +73284,12 @@
7332273284
pNew->flags |= EP_IntValue;
7332373285
pNew->u.iValue = iValue;
7332473286
}else{
7332573287
int c;
7332673288
pNew->u.zToken = (char*)&pNew[1];
73327
- memcpy(pNew->u.zToken, pToken->z, pToken->n);
73289
+ assert( pToken->z!=0 || pToken->n==0 );
73290
+ if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
7332873291
pNew->u.zToken[pToken->n] = 0;
7332973292
if( dequote && nExtra>=3
7333073293
&& ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
7333173294
sqlite3Dequote(pNew->u.zToken);
7333273295
if( c=='"' ) pNew->flags |= EP_DblQuoted;
@@ -74361,15 +74324,23 @@
7436174324
** ephemeral table.
7436274325
*/
7436374326
p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
7436474327
if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
7436574328
sqlite3 *db = pParse->db; /* Database connection */
74366
- Expr *pExpr = p->pEList->a[0].pExpr; /* Expression <column> */
74367
- int iCol = pExpr->iColumn; /* Index of column <column> */
7436874329
Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
74369
- Table *pTab = p->pSrc->a[0].pTab; /* Table <table>. */
74330
+ Table *pTab; /* Table <table>. */
74331
+ Expr *pExpr; /* Expression <column> */
74332
+ int iCol; /* Index of column <column> */
7437074333
int iDb; /* Database idx for pTab */
74334
+
74335
+ assert( p ); /* Because of isCandidateForInOpt(p) */
74336
+ assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
74337
+ assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
74338
+ assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
74339
+ pTab = p->pSrc->a[0].pTab;
74340
+ pExpr = p->pEList->a[0].pExpr;
74341
+ iCol = pExpr->iColumn;
7437174342
7437274343
/* Code an OP_VerifyCookie and OP_TableLock for <table>. */
7437374344
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7437474345
sqlite3CodeVerifySchema(pParse, iDb);
7437574346
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
@@ -76372,11 +76343,11 @@
7637276343
if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
7637376344
return 2;
7637476345
}
7637576346
}else if( pA->op!=TK_COLUMN && pA->u.zToken ){
7637676347
if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
76377
- if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ){
76348
+ if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
7637876349
return 2;
7637976350
}
7638076351
}
7638176352
if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1;
7638276353
if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2;
@@ -81778,17 +81749,19 @@
8177881749
*/
8177981750
static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
8178081751
Table *pTab = pIndex->pTable; /* The table that is indexed */
8178181752
int iTab = pParse->nTab++; /* Btree cursor used for pTab */
8178281753
int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */
81783
- int iSorter = iTab; /* Cursor opened by OpenSorter (if in use) */
81754
+ int iSorter; /* Cursor opened by OpenSorter (if in use) */
8178481755
int addr1; /* Address of top of loop */
8178581756
int addr2; /* Address to jump to for next iteration */
8178681757
int tnum; /* Root page of index */
8178781758
Vdbe *v; /* Generate code into this virtual machine */
8178881759
KeyInfo *pKey; /* KeyInfo for index */
81760
+#ifdef SQLITE_OMIT_MERGE_SORT
8178981761
int regIdxKey; /* Registers containing the index key */
81762
+#endif
8179081763
int regRecord; /* Register holding assemblied index record */
8179181764
sqlite3 *db = pParse->db; /* The database connection */
8179281765
int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
8179381766
8179481767
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -81818,21 +81791,22 @@
8181881791
8181981792
#ifndef SQLITE_OMIT_MERGE_SORT
8182081793
/* Open the sorter cursor if we are to use one. */
8182181794
iSorter = pParse->nTab++;
8182281795
sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
81796
+#else
81797
+ iSorter = iTab;
8182381798
#endif
8182481799
8182581800
/* Open the table. Loop through all rows of the table, inserting index
8182681801
** records into the sorter. */
8182781802
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
8182881803
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
81829
- addr2 = addr1 + 1;
8183081804
regRecord = sqlite3GetTempReg(pParse);
81831
- regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
8183281805
8183381806
#ifndef SQLITE_OMIT_MERGE_SORT
81807
+ sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
8183481808
sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
8183581809
sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
8183681810
sqlite3VdbeJumpHere(v, addr1);
8183781811
addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
8183881812
if( pIndex->onError!=OE_None ){
@@ -81848,10 +81822,12 @@
8184881822
}
8184981823
sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
8185081824
sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
8185181825
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
8185281826
#else
81827
+ regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
81828
+ addr2 = addr1 + 1;
8185381829
if( pIndex->onError!=OE_None ){
8185481830
const int regRowid = regIdxKey + pIndex->nColumn;
8185581831
const int j2 = sqlite3VdbeCurrentAddr(v) + 2;
8185681832
void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey);
8185781833
@@ -81945,10 +81921,11 @@
8194581921
** before looking up the table.
8194681922
*/
8194781923
assert( pName1 && pName2 );
8194881924
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
8194981925
if( iDb<0 ) goto exit_create_index;
81926
+ assert( pName && pName->z );
8195081927
8195181928
#ifndef SQLITE_OMIT_TEMPDB
8195281929
/* If the index name was unqualified, check if the the table
8195381930
** is a temp table. If so, set the database to 1. Do not do this
8195481931
** if initialising a database schema.
@@ -81972,10 +81949,11 @@
8197281949
pTblName->a[0].zDatabase);
8197381950
if( !pTab || db->mallocFailed ) goto exit_create_index;
8197481951
assert( db->aDb[iDb].pSchema==pTab->pSchema );
8197581952
}else{
8197681953
assert( pName==0 );
81954
+ assert( pStart==0 );
8197781955
pTab = pParse->pNewTable;
8197881956
if( !pTab ) goto exit_create_index;
8197981957
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
8198081958
}
8198181959
pDb = &db->aDb[iDb];
@@ -82014,10 +81992,11 @@
8201481992
** own name.
8201581993
*/
8201681994
if( pName ){
8201781995
zName = sqlite3NameFromToken(db, pName);
8201881996
if( zName==0 ) goto exit_create_index;
81997
+ assert( pName->z!=0 );
8201981998
if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
8202081999
goto exit_create_index;
8202182000
}
8202282001
if( !db->init.busy ){
8202382002
if( sqlite3FindTable(db, zName, 0)!=0 ){
@@ -82869,17 +82848,14 @@
8286982848
8287082849
/*
8287182850
** Commit a transaction
8287282851
*/
8287382852
SQLITE_PRIVATE void sqlite3CommitTransaction(Parse *pParse){
82874
- sqlite3 *db;
8287582853
Vdbe *v;
8287682854
8287782855
assert( pParse!=0 );
82878
- db = pParse->db;
82879
- assert( db!=0 );
82880
-/* if( db->aDb[0].pBt==0 ) return; */
82856
+ assert( pParse->db!=0 );
8288182857
if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ){
8288282858
return;
8288382859
}
8288482860
v = sqlite3GetVdbe(pParse);
8288582861
if( v ){
@@ -82889,17 +82865,14 @@
8288982865
8289082866
/*
8289182867
** Rollback a transaction
8289282868
*/
8289382869
SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse *pParse){
82894
- sqlite3 *db;
8289582870
Vdbe *v;
8289682871
8289782872
assert( pParse!=0 );
82898
- db = pParse->db;
82899
- assert( db!=0 );
82900
-/* if( db->aDb[0].pBt==0 ) return; */
82873
+ assert( pParse->db!=0 );
8290182874
if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ){
8290282875
return;
8290382876
}
8290482877
v = sqlite3GetVdbe(pParse);
8290582878
if( v ){
@@ -84701,20 +84674,19 @@
8470184674
/* Verify that the call to _bytes() does not invalidate the _text() pointer */
8470284675
assert( z2==(char*)sqlite3_value_text(argv[0]) );
8470384676
if( z2 ){
8470484677
z1 = contextMalloc(context, ((i64)n)+1);
8470584678
if( z1 ){
84706
- memcpy(z1, z2, n+1);
84707
- for(i=0; z1[i]; i++){
84708
- z1[i] = (char)sqlite3Toupper(z1[i]);
84679
+ for(i=0; i<n; i++){
84680
+ z1[i] = (char)sqlite3Toupper(z2[i]);
8470984681
}
84710
- sqlite3_result_text(context, z1, -1, sqlite3_free);
84682
+ sqlite3_result_text(context, z1, n, sqlite3_free);
8471184683
}
8471284684
}
8471384685
}
8471484686
static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
84715
- u8 *z1;
84687
+ char *z1;
8471684688
const char *z2;
8471784689
int i, n;
8471884690
UNUSED_PARAMETER(argc);
8471984691
z2 = (char*)sqlite3_value_text(argv[0]);
8472084692
n = sqlite3_value_bytes(argv[0]);
@@ -84721,15 +84693,14 @@
8472184693
/* Verify that the call to _bytes() does not invalidate the _text() pointer */
8472284694
assert( z2==(char*)sqlite3_value_text(argv[0]) );
8472384695
if( z2 ){
8472484696
z1 = contextMalloc(context, ((i64)n)+1);
8472584697
if( z1 ){
84726
- memcpy(z1, z2, n+1);
84727
- for(i=0; z1[i]; i++){
84728
- z1[i] = sqlite3Tolower(z1[i]);
84698
+ for(i=0; i<n; i++){
84699
+ z1[i] = sqlite3Tolower(z2[i]);
8472984700
}
84730
- sqlite3_result_text(context, (char *)z1, -1, sqlite3_free);
84701
+ sqlite3_result_text(context, z1, n, sqlite3_free);
8473184702
}
8473284703
}
8473384704
}
8473484705
8473584706
@@ -87102,10 +87073,11 @@
8710287073
sqlite3SelectDelete(db, pSelect);
8710387074
if( db->mallocFailed==1 ){
8710487075
fkTriggerDelete(db, pTrigger);
8710587076
return 0;
8710687077
}
87078
+ assert( pStep!=0 );
8710787079
8710887080
switch( action ){
8710987081
case OE_Restrict:
8711087082
pStep->op = TK_SELECT;
8711187083
break;
@@ -90025,11 +89997,11 @@
9002589997
sqlite3_vfs *pVfs = db->pVfs;
9002689998
void *handle;
9002789999
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
9002890000
char *zErrmsg = 0;
9002990001
void **aHandle;
90030
- const int nMsg = 300;
90002
+ int nMsg = 300 + sqlite3Strlen30(zFile);
9003190003
9003290004
if( pzErrMsg ) *pzErrMsg = 0;
9003390005
9003490006
/* Ticket #1863. To avoid a creating security problems for older
9003590007
** applications that relink against newer versions of SQLite, the
@@ -90062,10 +90034,11 @@
9006290034
}
9006390035
xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
9006490036
sqlite3OsDlSym(pVfs, handle, zProc);
9006590037
if( xInit==0 ){
9006690038
if( pzErrMsg ){
90039
+ nMsg += sqlite3Strlen30(zProc);
9006790040
*pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
9006890041
if( zErrmsg ){
9006990042
sqlite3_snprintf(nMsg, zErrmsg,
9007090043
"no entry point [%s] in shared library [%s]", zProc,zFile);
9007190044
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
@@ -90747,11 +90720,11 @@
9074790720
){
9074890721
int iReg;
9074990722
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9075090723
sqlite3CodeVerifySchema(pParse, iDb);
9075190724
iReg = ++pParse->nMem;
90752
- if( zLeft[0]=='p' ){
90725
+ if( sqlite3Tolower(zLeft[0])=='p' ){
9075390726
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
9075490727
}else{
9075590728
sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, sqlite3Atoi(zRight));
9075690729
}
9075790730
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
@@ -91360,11 +91333,11 @@
9136091333
{ OP_IfNeg, 1, 0, 0}, /* 1 */
9136191334
{ OP_String8, 0, 3, 0}, /* 2 */
9136291335
{ OP_ResultRow, 3, 1, 0},
9136391336
};
9136491337
91365
- int isQuick = (zLeft[0]=='q');
91338
+ int isQuick = (sqlite3Tolower(zLeft[0])=='q');
9136691339
9136791340
/* Initialize the VDBE program */
9136891341
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9136991342
pParse->nMem = 6;
9137091343
sqlite3VdbeSetNumCols(v, 1);
@@ -93942,11 +93915,14 @@
9394293915
/* If the column contains an "AS <name>" phrase, use <name> as the name */
9394393916
zName = sqlite3DbStrDup(db, zName);
9394493917
}else{
9394593918
Expr *pColExpr = p; /* The expression that is the result column name */
9394693919
Table *pTab; /* Table associated with this expression */
93947
- while( pColExpr->op==TK_DOT ) pColExpr = pColExpr->pRight;
93920
+ while( pColExpr->op==TK_DOT ){
93921
+ pColExpr = pColExpr->pRight;
93922
+ assert( pColExpr!=0 );
93923
+ }
9394893924
if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
9394993925
/* For columns use the column name name */
9395093926
int iCol = pColExpr->iColumn;
9395193927
pTab = pColExpr->pTab;
9395293928
if( iCol<0 ) iCol = pTab->iPKey;
@@ -98940,10 +98916,11 @@
9894098916
break;
9894198917
}
9894298918
}
9894398919
}
9894498920
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
98921
+ assert( aRegIdx );
9894598922
if( openAll || aRegIdx[i]>0 ){
9894698923
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
9894798924
sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,
9894898925
(char*)pKey, P4_KEYINFO_HANDOFF);
9894998926
assert( pParse->nTab>iCur+i+1 );
@@ -99113,10 +99090,11 @@
9911399090
sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
9911499091
sqlite3VdbeJumpHere(v, addr);
9911599092
9911699093
/* Close all tables */
9911799094
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
99095
+ assert( aRegIdx );
9911899096
if( openAll || aRegIdx[i]>0 ){
9911999097
sqlite3VdbeAddOp2(v, OP_Close, iCur+i+1, 0);
9912099098
}
9912199099
}
9912299100
sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
@@ -103144,11 +103122,10 @@
103144103122
assert( roundUp==0 || roundUp==1 );
103145103123
assert( pIdx->nSample>0 );
103146103124
if( pVal==0 ) return SQLITE_ERROR;
103147103125
n = pIdx->aiRowEst[0];
103148103126
aSample = pIdx->aSample;
103149
- i = 0;
103150103127
eType = sqlite3_value_type(pVal);
103151103128
103152103129
if( eType==SQLITE_INTEGER ){
103153103130
v = sqlite3_value_int64(pVal);
103154103131
r = (i64)v;
@@ -105564,11 +105541,12 @@
105564105541
assert( bestJ>=0 );
105565105542
assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
105566105543
WHERETRACE(("*** Optimizer selects table %d for loop %d"
105567105544
" with cost=%g and nRow=%g\n",
105568105545
bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.plan.nRow));
105569
- if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
105546
+ /* The ALWAYS() that follows was added to hush up clang scan-build */
105547
+ if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 && ALWAYS(ppOrderBy) ){
105570105548
*ppOrderBy = 0;
105571105549
}
105572105550
if( (bestPlan.plan.wsFlags & WHERE_DISTINCT)!=0 ){
105573105551
assert( pWInfo->eDistinct==0 );
105574105552
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
@@ -109180,11 +109158,13 @@
109180109158
sqlite3ParserTOKENTYPE yyminor /* The value for the token */
109181109159
sqlite3ParserARG_PDECL /* Optional %extra_argument parameter */
109182109160
){
109183109161
YYMINORTYPE yyminorunion;
109184109162
int yyact; /* The parser action. */
109163
+#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
109185109164
int yyendofinput; /* True if we are at the end of input */
109165
+#endif
109186109166
#ifdef YYERRORSYMBOL
109187109167
int yyerrorhit = 0; /* True if yymajor has invoked an error */
109188109168
#endif
109189109169
yyParser *yypParser; /* The parser */
109190109170
@@ -109203,11 +109183,13 @@
109203109183
yypParser->yyerrcnt = -1;
109204109184
yypParser->yystack[0].stateno = 0;
109205109185
yypParser->yystack[0].major = 0;
109206109186
}
109207109187
yyminorunion.yy0 = yyminor;
109188
+#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
109208109189
yyendofinput = (yymajor==0);
109190
+#endif
109209109191
sqlite3ParserARG_STORE;
109210109192
109211109193
#ifndef NDEBUG
109212109194
if( yyTraceFILE ){
109213109195
fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
@@ -109215,11 +109197,10 @@
109215109197
#endif
109216109198
109217109199
do{
109218109200
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
109219109201
if( yyact<YYNSTATE ){
109220
- assert( !yyendofinput ); /* Impossible to shift the $ token */
109221109202
yy_shift(yypParser,yyact,yymajor,&yyminorunion);
109222109203
yypParser->yyerrcnt--;
109223109204
yymajor = YYNOCODE;
109224109205
}else if( yyact < YYNSTATE + YYNRULE ){
109225109206
yy_reduce(yypParser,yyact-YYNSTATE);
@@ -110607,11 +110588,11 @@
110607110588
**
110608110589
** * Recursive calls to this routine from thread X return immediately
110609110590
** without blocking.
110610110591
*/
110611110592
SQLITE_API int sqlite3_initialize(void){
110612
- sqlite3_mutex *pMaster; /* The main static mutex */
110593
+ MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
110613110594
int rc; /* Result code */
110614110595
110615110596
#ifdef SQLITE_OMIT_WSD
110616110597
rc = sqlite3_wsd_init(4096, 24);
110617110598
if( rc!=SQLITE_OK ){
@@ -110641,11 +110622,11 @@
110641110622
** This operation is protected by the STATIC_MASTER mutex. Note that
110642110623
** MutexAlloc() is called for a static mutex prior to initializing the
110643110624
** malloc subsystem - this implies that the allocation of a static
110644110625
** mutex must not require support from the malloc subsystem.
110645110626
*/
110646
- pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
110627
+ MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
110647110628
sqlite3_mutex_enter(pMaster);
110648110629
sqlite3GlobalConfig.isMutexInit = 1;
110649110630
if( !sqlite3GlobalConfig.isMallocInit ){
110650110631
rc = sqlite3MallocInit();
110651110632
}
@@ -111715,17 +111696,17 @@
111715111696
sqlite3 *db,
111716111697
const char *zName,
111717111698
int nArg
111718111699
){
111719111700
int nName = sqlite3Strlen30(zName);
111720
- int rc;
111701
+ int rc = SQLITE_OK;
111721111702
sqlite3_mutex_enter(db->mutex);
111722111703
if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
111723
- sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
111724
- 0, sqlite3InvalidFunction, 0, 0, 0);
111704
+ rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
111705
+ 0, sqlite3InvalidFunction, 0, 0, 0);
111725111706
}
111726
- rc = sqlite3ApiExit(db, SQLITE_OK);
111707
+ rc = sqlite3ApiExit(db, rc);
111727111708
sqlite3_mutex_leave(db->mutex);
111728111709
return rc;
111729111710
}
111730111711
111731111712
#ifndef SQLITE_OMIT_TRACE
@@ -112783,10 +112764,11 @@
112783112764
if( db ){
112784112765
assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
112785112766
sqlite3_mutex_leave(db->mutex);
112786112767
}
112787112768
rc = sqlite3_errcode(db);
112769
+ assert( db!=0 || rc==SQLITE_NOMEM );
112788112770
if( rc==SQLITE_NOMEM ){
112789112771
sqlite3_close(db);
112790112772
db = 0;
112791112773
}else if( rc!=SQLITE_OK ){
112792112774
db->magic = SQLITE_MAGIC_SICK;
@@ -114511,10 +114493,17 @@
114511114493
#else
114512114494
# define TESTONLY(X)
114513114495
#endif
114514114496
114515114497
#endif /* SQLITE_AMALGAMATION */
114498
+
114499
+#ifdef SQLITE_DEBUG
114500
+SQLITE_PRIVATE int sqlite3Fts3Corrupt(void);
114501
+# define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt()
114502
+#else
114503
+# define FTS_CORRUPT_VTAB SQLITE_CORRUPT_VTAB
114504
+#endif
114516114505
114517114506
typedef struct Fts3Table Fts3Table;
114518114507
typedef struct Fts3Cursor Fts3Cursor;
114519114508
typedef struct Fts3Expr Fts3Expr;
114520114509
typedef struct Fts3Phrase Fts3Phrase;
@@ -115012,11 +115001,11 @@
115012115001
char **pp,
115013115002
char *pStart,
115014115003
sqlite3_int64 *pVal
115015115004
){
115016115005
sqlite3_int64 iVal;
115017
- char *p = *pp;
115006
+ char *p;
115018115007
115019115008
/* Pointer p now points at the first byte past the varint we are
115020115009
** interested in. So, unless the doclist is corrupt, the 0x80 bit is
115021115010
** clear on character p[-1]. */
115022115011
for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
@@ -115413,11 +115402,11 @@
115413115402
** the output value undefined. Otherwise SQLITE_OK is returned.
115414115403
**
115415115404
** This function is used when parsing the "prefix=" FTS4 parameter.
115416115405
*/
115417115406
static int fts3GobbleInt(const char **pp, int *pnOut){
115418
- const char *p = *pp; /* Iterator pointer */
115407
+ const char *p; /* Iterator pointer */
115419115408
int nInt = 0; /* Output value */
115420115409
115421115410
for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
115422115411
nInt = nInt * 10 + (p[0] - '0');
115423115412
}
@@ -115912,11 +115901,11 @@
115912115901
if( rc==SQLITE_OK ){
115913115902
/* If no row was found and no error has occured, then the %_content
115914115903
** table is missing a row that is present in the full-text index.
115915115904
** The data structures are corrupt.
115916115905
*/
115917
- rc = SQLITE_CORRUPT_VTAB;
115906
+ rc = FTS_CORRUPT_VTAB;
115918115907
}
115919115908
pCsr->isEof = 1;
115920115909
if( pContext ){
115921115910
sqlite3_result_error_code(pContext, rc);
115922115911
}
@@ -115972,11 +115961,11 @@
115972115961
** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
115973115962
*/
115974115963
zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
115975115964
zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
115976115965
if( zCsr>zEnd ){
115977
- return SQLITE_CORRUPT_VTAB;
115966
+ return FTS_CORRUPT_VTAB;
115978115967
}
115979115968
115980115969
while( zCsr<zEnd && (piFirst || piLast) ){
115981115970
int cmp; /* memcmp() result */
115982115971
int nSuffix; /* Size of term suffix */
@@ -115990,11 +115979,11 @@
115990115979
}
115991115980
isFirstTerm = 0;
115992115981
zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
115993115982
115994115983
if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
115995
- rc = SQLITE_CORRUPT_VTAB;
115984
+ rc = FTS_CORRUPT_VTAB;
115996115985
goto finish_scan;
115997115986
}
115998115987
if( nPrefix+nSuffix>nAlloc ){
115999115988
char *zNew;
116000115989
nAlloc = (nPrefix+nSuffix) * 2;
@@ -116003,10 +115992,11 @@
116003115992
rc = SQLITE_NOMEM;
116004115993
goto finish_scan;
116005115994
}
116006115995
zBuffer = zNew;
116007115996
}
115997
+ assert( zBuffer );
116008115998
memcpy(&zBuffer[nPrefix], zCsr, nSuffix);
116009115999
nBuffer = nPrefix + nSuffix;
116010116000
zCsr += nSuffix;
116011116001
116012116002
/* Compare the term we are searching for with the term just loaded from
@@ -117439,11 +117429,11 @@
117439117429
** moves *ppPoslist so that it instead points to the first byte of the
117440117430
** same position list.
117441117431
*/
117442117432
static void fts3ReversePoslist(char *pStart, char **ppPoslist){
117443117433
char *p = &(*ppPoslist)[-2];
117444
- char c;
117434
+ char c = 0;
117445117435
117446117436
while( p>pStart && (c=*p--)==0 );
117447117437
while( p>pStart && (*p & 0x80) | c ){
117448117438
c = *p--;
117449117439
}
@@ -118433,11 +118423,11 @@
118433118423
while( a<pEnd ){
118434118424
a += sqlite3Fts3GetVarint(a, &nByte);
118435118425
}
118436118426
if( nDoc==0 || nByte==0 ){
118437118427
sqlite3_reset(pStmt);
118438
- return SQLITE_CORRUPT_VTAB;
118428
+ return FTS_CORRUPT_VTAB;
118439118429
}
118440118430
118441118431
pCsr->nDoc = nDoc;
118442118432
pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
118443118433
assert( pCsr->nRowAvg>0 );
@@ -118909,12 +118899,15 @@
118909118899
}
118910118900
118911118901
aPoslist = pExpr->pRight->pPhrase->doclist.pList;
118912118902
nToken = pExpr->pRight->pPhrase->nToken;
118913118903
for(p=pExpr->pLeft; p && res; p=p->pLeft){
118914
- int nNear = p->pParent->nNear;
118915
- Fts3Phrase *pPhrase = (
118904
+ int nNear;
118905
+ Fts3Phrase *pPhrase;
118906
+ assert( p->pParent && p->pParent->pLeft==p );
118907
+ nNear = p->pParent->nNear;
118908
+ pPhrase = (
118916118909
p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
118917118910
);
118918118911
res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
118919118912
}
118920118913
}
@@ -119400,10 +119393,19 @@
119400119393
pPhrase->aToken[i].pSegcsr = 0;
119401119394
}
119402119395
}
119403119396
}
119404119397
119398
+/*
119399
+** Return SQLITE_CORRUPT_VTAB.
119400
+*/
119401
+#ifdef SQLITE_DEBUG
119402
+SQLITE_PRIVATE int sqlite3Fts3Corrupt(){
119403
+ return SQLITE_CORRUPT_VTAB;
119404
+}
119405
+#endif
119406
+
119405119407
#if !SQLITE_CORE
119406119408
/*
119407119409
** Initialize API pointer table, if required.
119408119410
*/
119409119411
SQLITE_API int sqlite3_extension_init(
@@ -120197,12 +120199,16 @@
120197120199
p->pPhrase = (Fts3Phrase *)&p[1];
120198120200
p->pPhrase->iColumn = pParse->iDefaultCol;
120199120201
p->pPhrase->nToken = nToken;
120200120202
120201120203
zBuf = (char *)&p->pPhrase->aToken[nToken];
120202
- memcpy(zBuf, zTemp, nTemp);
120203
- sqlite3_free(zTemp);
120204
+ if( zTemp ){
120205
+ memcpy(zBuf, zTemp, nTemp);
120206
+ sqlite3_free(zTemp);
120207
+ }else{
120208
+ assert( nTemp==0 );
120209
+ }
120204120210
120205120211
for(jj=0; jj<p->pPhrase->nToken; jj++){
120206120212
p->pPhrase->aToken[jj].z = zBuf;
120207120213
zBuf += p->pPhrase->aToken[jj].n;
120208120214
}
@@ -122957,11 +122963,11 @@
122957122963
sqlite3_bind_int64(pStmt, 1, iDocid);
122958122964
}
122959122965
rc = sqlite3_step(pStmt);
122960122966
if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
122961122967
rc = sqlite3_reset(pStmt);
122962
- if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB;
122968
+ if( rc==SQLITE_OK ) rc = FTS_CORRUPT_VTAB;
122963122969
pStmt = 0;
122964122970
}else{
122965122971
rc = SQLITE_OK;
122966122972
}
122967122973
}
@@ -123761,11 +123767,11 @@
123761123767
pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
123762123768
pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
123763123769
if( nPrefix<0 || nSuffix<=0
123764123770
|| &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
123765123771
){
123766
- return SQLITE_CORRUPT_VTAB;
123772
+ return FTS_CORRUPT_VTAB;
123767123773
}
123768123774
123769123775
if( nPrefix+nSuffix>pReader->nTermAlloc ){
123770123776
int nNew = (nPrefix+nSuffix)*2;
123771123777
char *zNew = sqlite3_realloc(pReader->zTerm, nNew);
@@ -123791,11 +123797,11 @@
123791123797
** of these statements is untrue, then the data structure is corrupt.
123792123798
*/
123793123799
if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode]
123794123800
|| (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
123795123801
){
123796
- return SQLITE_CORRUPT_VTAB;
123802
+ return FTS_CORRUPT_VTAB;
123797123803
}
123798123804
return SQLITE_OK;
123799123805
}
123800123806
123801123807
/*
@@ -125745,11 +125751,10 @@
125745125751
sqlite_int64 *pRowid /* OUT: The affected (or effected) rowid */
125746125752
){
125747125753
Fts3Table *p = (Fts3Table *)pVtab;
125748125754
int rc = SQLITE_OK; /* Return Code */
125749125755
int isRemove = 0; /* True for an UPDATE or DELETE */
125750
- sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */
125751125756
u32 *aSzIns = 0; /* Sizes of inserted documents */
125752125757
u32 *aSzDel; /* Sizes of deleted documents */
125753125758
int nChng = 0; /* Net change in number of documents */
125754125759
int bInsertDone = 0;
125755125760
@@ -125828,23 +125833,23 @@
125828125833
/* If this is a DELETE or UPDATE operation, remove the old record. */
125829125834
if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
125830125835
assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
125831125836
rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
125832125837
isRemove = 1;
125833
- iRemove = sqlite3_value_int64(apVal[0]);
125834125838
}
125835125839
125836125840
/* If this is an INSERT or UPDATE operation, insert the new record. */
125837125841
if( nArg>1 && rc==SQLITE_OK ){
125838125842
if( bInsertDone==0 ){
125839125843
rc = fts3InsertData(p, apVal, pRowid);
125840
- if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB;
125844
+ if( rc==SQLITE_CONSTRAINT ) rc = FTS_CORRUPT_VTAB;
125841125845
}
125842
- if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){
125846
+ if( rc==SQLITE_OK && (!isRemove || *pRowid!=p->iPrevDocid ) ){
125843125847
rc = fts3PendingTermsDocid(p, *pRowid);
125844125848
}
125845125849
if( rc==SQLITE_OK ){
125850
+ assert( p->iPrevDocid==*pRowid );
125846125851
rc = fts3InsertTerms(p, apVal, aSzIns);
125847125852
}
125848125853
if( p->bHasDocsize ){
125849125854
fts3InsertDocsize(&rc, p, aSzIns);
125850125855
}
@@ -126734,11 +126739,11 @@
126734126739
pStmt = *ppStmt;
126735126740
assert( sqlite3_data_count(pStmt)==1 );
126736126741
126737126742
a = sqlite3_column_blob(pStmt, 0);
126738126743
a += sqlite3Fts3GetVarint(a, &nDoc);
126739
- if( nDoc==0 ) return SQLITE_CORRUPT_VTAB;
126744
+ if( nDoc==0 ) return FTS_CORRUPT_VTAB;
126740126745
*pnDoc = (u32)nDoc;
126741126746
126742126747
if( paLen ) *paLen = a;
126743126748
return SQLITE_OK;
126744126749
}
@@ -127313,11 +127318,11 @@
127313127318
sqlite3_snprintf(sizeof(aBuffer), aBuffer,
127314127319
"%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
127315127320
);
127316127321
rc = fts3StringAppend(&res, aBuffer, -1);
127317127322
}else if( rc==SQLITE_DONE ){
127318
- rc = SQLITE_CORRUPT_VTAB;
127323
+ rc = FTS_CORRUPT_VTAB;
127319127324
}
127320127325
}
127321127326
}
127322127327
if( rc==SQLITE_DONE ){
127323127328
rc = SQLITE_OK;
@@ -128654,11 +128659,12 @@
128654128659
pCsr->nConstraint = argc;
128655128660
if( !pCsr->aConstraint ){
128656128661
rc = SQLITE_NOMEM;
128657128662
}else{
128658128663
memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
128659
- assert( (idxStr==0 && argc==0) || (int)strlen(idxStr)==argc*2 );
128664
+ assert( (idxStr==0 && argc==0)
128665
+ || (idxStr && (int)strlen(idxStr)==argc*2) );
128660128666
for(ii=0; ii<argc; ii++){
128661128667
RtreeConstraint *p = &pCsr->aConstraint[ii];
128662128668
p->op = idxStr[ii*2];
128663128669
p->iCoord = idxStr[ii*2+1]-'a';
128664128670
if( p->op==RTREE_MATCH ){
@@ -128955,11 +128961,14 @@
128955128961
int iCell;
128956128962
sqlite3_int64 iBest = 0;
128957128963
128958128964
float fMinGrowth = 0.0;
128959128965
float fMinArea = 0.0;
128966
+#if VARIANT_RSTARTREE_CHOOSESUBTREE
128960128967
float fMinOverlap = 0.0;
128968
+ float overlap;
128969
+#endif
128961128970
128962128971
int nCell = NCELL(pNode);
128963128972
RtreeCell cell;
128964128973
RtreeNode *pChild;
128965128974
@@ -128987,33 +128996,34 @@
128987128996
*/
128988128997
for(iCell=0; iCell<nCell; iCell++){
128989128998
int bBest = 0;
128990128999
float growth;
128991129000
float area;
128992
- float overlap = 0.0;
128993129001
nodeGetCell(pRtree, pNode, iCell, &cell);
128994129002
growth = cellGrowth(pRtree, &cell, pCell);
128995129003
area = cellArea(pRtree, &cell);
128996129004
128997129005
#if VARIANT_RSTARTREE_CHOOSESUBTREE
128998129006
if( ii==(pRtree->iDepth-1) ){
128999129007
overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell);
129008
+ }else{
129009
+ overlap = 0.0;
129000129010
}
129001129011
if( (iCell==0)
129002129012
|| (overlap<fMinOverlap)
129003129013
|| (overlap==fMinOverlap && growth<fMinGrowth)
129004129014
|| (overlap==fMinOverlap && growth==fMinGrowth && area<fMinArea)
129005129015
){
129006129016
bBest = 1;
129017
+ fMinOverlap = overlap;
129007129018
}
129008129019
#else
129009129020
if( iCell==0||growth<fMinGrowth||(growth==fMinGrowth && area<fMinArea) ){
129010129021
bBest = 1;
129011129022
}
129012129023
#endif
129013129024
if( bBest ){
129014
- fMinOverlap = overlap;
129015129025
fMinGrowth = growth;
129016129026
fMinArea = area;
129017129027
iBest = cell.iRowid;
129018129028
}
129019129029
}
129020129030
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.7.9"
660 #define SQLITE_VERSION_NUMBER 3007009
661 #define SQLITE_SOURCE_ID "2011-10-11 20:41:54 b94a80a832777f0e639f6a81fcfe169bf970a8c0"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -3351,11 +3351,12 @@
3351 ** zSql string ends at either the first '\000' or '\u0000' character or
3352 ** the nByte-th byte, whichever comes first. If the caller knows
3353 ** that the supplied string is nul-terminated, then there is a small
3354 ** performance advantage to be gained by passing an nByte parameter that
3355 ** is equal to the number of bytes in the input string <i>including</i>
3356 ** the nul-terminator bytes.
 
3357 **
3358 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3359 ** past the end of the first SQL statement in zSql. These routines only
3360 ** compile the first statement in zSql, so *pzTail is left pointing to
3361 ** what remains uncompiled.
@@ -3572,10 +3573,17 @@
3572 ** ^(In those routines that have a fourth argument, its value is the
3573 ** number of bytes in the parameter. To be clear: the value is the
3574 ** number of <u>bytes</u> in the value, not the number of characters.)^
3575 ** ^If the fourth parameter is negative, the length of the string is
3576 ** the number of bytes up to the first zero terminator.
 
 
 
 
 
 
 
3577 **
3578 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3579 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3580 ** string after SQLite has finished with it. ^The destructor is called
3581 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
@@ -4590,11 +4598,16 @@
4590 ** is negative, then SQLite takes result text from the 2nd parameter
4591 ** through the first zero character.
4592 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4593 ** is non-negative, then as many bytes (not characters) of the text
4594 ** pointed to by the 2nd parameter are taken as the application-defined
4595 ** function result.
 
 
 
 
 
4596 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
4597 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
4598 ** function as the destructor on the text or BLOB result when it has
4599 ** finished using that result.
4600 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
@@ -9315,18 +9328,21 @@
9315 /*
9316 ** If this is a no-op implementation, implement everything as macros.
9317 */
9318 #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
9319 #define sqlite3_mutex_free(X)
9320 #define sqlite3_mutex_enter(X)
9321 #define sqlite3_mutex_try(X) SQLITE_OK
9322 #define sqlite3_mutex_leave(X)
9323 #define sqlite3_mutex_held(X) ((void)(X),1)
9324 #define sqlite3_mutex_notheld(X) ((void)(X),1)
9325 #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
9326 #define sqlite3MutexInit() SQLITE_OK
9327 #define sqlite3MutexEnd()
 
 
 
9328 #endif /* defined(SQLITE_MUTEX_OMIT) */
9329
9330 /************** End of mutex.h ***********************************************/
9331 /************** Continuing where we left off in sqliteInt.h ******************/
9332
@@ -11754,19 +11770,21 @@
11754 # define sqlite3VtabInSync(db) 0
11755 # define sqlite3VtabLock(X)
11756 # define sqlite3VtabUnlock(X)
11757 # define sqlite3VtabUnlockList(X)
11758 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
 
11759 #else
11760 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
11761 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
11762 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
11763 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
11764 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
11765 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
11766 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
11767 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
 
11768 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
11769 #endif
11770 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
11771 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
11772 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
@@ -11782,11 +11800,10 @@
11782 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
11783 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
11784 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
11785 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
11786 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
11787 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
11788 SQLITE_PRIVATE const char *sqlite3JournalModename(int);
11789 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*);
11790 SQLITE_PRIVATE int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
11791
11792 /* Declarations for functions in fkey.c. All of these are replaced by
@@ -13558,16 +13575,22 @@
13558 }
13559 return 0;
13560 }
13561
13562 /*
13563 ** Set the time to the current time reported by the VFS
 
 
13564 */
13565 static void setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
13566 sqlite3 *db = sqlite3_context_db_handle(context);
13567 sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD);
13568 p->validJD = 1;
 
 
 
 
13569 }
13570
13571 /*
13572 ** Attempt to parse the given string into a Julian Day Number. Return
13573 ** the number of errors.
@@ -13593,12 +13616,11 @@
13593 if( parseYyyyMmDd(zDate,p)==0 ){
13594 return 0;
13595 }else if( parseHhMmSs(zDate, p)==0 ){
13596 return 0;
13597 }else if( sqlite3StrICmp(zDate,"now")==0){
13598 setDateTimeToCurrent(context, p);
13599 return 0;
13600 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
13601 p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
13602 p->validJD = 1;
13603 return 0;
13604 }
@@ -14021,12 +14043,13 @@
14021 int i;
14022 const unsigned char *z;
14023 int eType;
14024 memset(p, 0, sizeof(*p));
14025 if( argc==0 ){
14026 setDateTimeToCurrent(context, p);
14027 }else if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
 
14028 || eType==SQLITE_INTEGER ){
14029 p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
14030 p->validJD = 1;
14031 }else{
14032 z = sqlite3_value_text(argv[0]);
@@ -14334,35 +14357,32 @@
14334 ){
14335 time_t t;
14336 char *zFormat = (char *)sqlite3_user_data(context);
14337 sqlite3 *db;
14338 sqlite3_int64 iT;
 
 
14339 char zBuf[20];
14340
14341 UNUSED_PARAMETER(argc);
14342 UNUSED_PARAMETER(argv);
14343
14344 db = sqlite3_context_db_handle(context);
14345 sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
14346 t = iT/1000 - 10000*(sqlite3_int64)21086676;
14347 #ifdef HAVE_GMTIME_R
14348 {
14349 struct tm sNow;
14350 gmtime_r(&t, &sNow);
 
 
 
 
 
14351 strftime(zBuf, 20, zFormat, &sNow);
14352 }
14353 #else
14354 {
14355 struct tm *pTm;
14356 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14357 pTm = gmtime(&t);
14358 strftime(zBuf, 20, zFormat, pTm);
14359 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14360 }
14361 #endif
14362
14363 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
14364 }
14365 #endif
14366
14367 /*
14368 ** This function registered all of the above C functions as SQL
@@ -14693,16 +14713,16 @@
14693 ** Register a VFS with the system. It is harmless to register the same
14694 ** VFS multiple times. The new VFS becomes the default if makeDflt is
14695 ** true.
14696 */
14697 SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
14698 sqlite3_mutex *mutex = 0;
14699 #ifndef SQLITE_OMIT_AUTOINIT
14700 int rc = sqlite3_initialize();
14701 if( rc ) return rc;
14702 #endif
14703 mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
14704 sqlite3_mutex_enter(mutex);
14705 vfsUnlink(pVfs);
14706 if( makeDflt || vfsList==0 ){
14707 pVfs->pNext = vfsList;
14708 vfsList = pVfs;
@@ -18946,52 +18966,14 @@
18946 ** an historical reference. Most of the "enhancements" have been backed
18947 ** out so that the functionality is now the same as standard printf().
18948 **
18949 **************************************************************************
18950 **
18951 ** The following modules is an enhanced replacement for the "printf" subroutines
18952 ** found in the standard C library. The following enhancements are
18953 ** supported:
18954 **
18955 ** + Additional functions. The standard set of "printf" functions
18956 ** includes printf, fprintf, sprintf, vprintf, vfprintf, and
18957 ** vsprintf. This module adds the following:
18958 **
18959 ** * snprintf -- Works like sprintf, but has an extra argument
18960 ** which is the size of the buffer written to.
18961 **
18962 ** * mprintf -- Similar to sprintf. Writes output to memory
18963 ** obtained from malloc.
18964 **
18965 ** * xprintf -- Calls a function to dispose of output.
18966 **
18967 ** * nprintf -- No output, but returns the number of characters
18968 ** that would have been output by printf.
18969 **
18970 ** * A v- version (ex: vsnprintf) of every function is also
18971 ** supplied.
18972 **
18973 ** + A few extensions to the formatting notation are supported:
18974 **
18975 ** * The "=" flag (similar to "-") causes the output to be
18976 ** be centered in the appropriately sized field.
18977 **
18978 ** * The %b field outputs an integer in binary notation.
18979 **
18980 ** * The %c field now accepts a precision. The character output
18981 ** is repeated by the number of times the precision specifies.
18982 **
18983 ** * The %' field works like %c, but takes as its character the
18984 ** next character of the format string, instead of the next
18985 ** argument. For example, printf("%.78'-") prints 78 minus
18986 ** signs, the same as printf("%.78c",'-').
18987 **
18988 ** + When compiled using GCC on a SPARC, this version of printf is
18989 ** faster than the library printf for SUN OS 4.1.
18990 **
18991 ** + All functions are fully reentrant.
18992 **
18993 */
18994
18995 /*
18996 ** Conversion types fall into various categories as defined by the
18997 ** following enumeration.
@@ -19125,43 +19107,19 @@
19125 }
19126 }
19127
19128 /*
19129 ** On machines with a small stack size, you can redefine the
19130 ** SQLITE_PRINT_BUF_SIZE to be less than 350.
19131 */
19132 #ifndef SQLITE_PRINT_BUF_SIZE
19133 # define SQLITE_PRINT_BUF_SIZE 70
19134 #endif
19135 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
19136
19137 /*
19138 ** The root program. All variations call this core.
19139 **
19140 ** INPUTS:
19141 ** func This is a pointer to a function taking three arguments
19142 ** 1. A pointer to anything. Same as the "arg" parameter.
19143 ** 2. A pointer to the list of characters to be output
19144 ** (Note, this list is NOT null terminated.)
19145 ** 3. An integer number of characters to be output.
19146 ** (Note: This number might be zero.)
19147 **
19148 ** arg This is the pointer to anything which will be passed as the
19149 ** first argument to "func". Use it for whatever you like.
19150 **
19151 ** fmt This is the format string, as in the usual print.
19152 **
19153 ** ap This is a pointer to a list of arguments. Same as in
19154 ** vfprint.
19155 **
19156 ** OUTPUTS:
19157 ** The return value is the total number of characters sent to
19158 ** the function "func". Returns -1 on a error.
19159 **
19160 ** Note that the order in which automatic variables are declared below
19161 ** seems to make a big difference in determining how fast this beast
19162 ** will run.
19163 */
19164 SQLITE_PRIVATE void sqlite3VXPrintf(
19165 StrAccum *pAccum, /* Accumulate results here */
19166 int useExtended, /* Allow extended %-conversions */
19167 const char *fmt, /* Format string */
@@ -19180,28 +19138,27 @@
19180 etByte flag_altform2; /* True if "!" flag is present */
19181 etByte flag_zeropad; /* True if field width constant starts with zero */
19182 etByte flag_long; /* True if "l" flag is present */
19183 etByte flag_longlong; /* True if the "ll" flag is present */
19184 etByte done; /* Loop termination flag */
 
 
19185 sqlite_uint64 longvalue; /* Value for integer types */
19186 LONGDOUBLE_TYPE realvalue; /* Value for real types */
19187 const et_info *infop; /* Pointer to the appropriate info structure */
19188 char buf[etBUFSIZE]; /* Conversion buffer */
19189 char *zOut; /* Rendering buffer */
19190 int nOut; /* Size of the rendering buffer */
19191 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
19192 etByte xtype = 0; /* Conversion paradigm */
19193 char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
19194 #ifndef SQLITE_OMIT_FLOATING_POINT
19195 int exp, e2; /* exponent of real numbers */
 
19196 double rounder; /* Used for rounding floating point values */
19197 etByte flag_dp; /* True if decimal point should be shown */
19198 etByte flag_rtz; /* True if trailing zeros should be removed */
19199 int nsd; /* Number of significant digits returned */
19200 #endif
 
19201
19202 length = 0;
19203 bufpt = 0;
19204 for(; (c=(*fmt))!=0; ++fmt){
19205 if( c!='%' ){
19206 int amt;
19207 bufpt = (char *)fmt;
@@ -19692,10 +19649,11 @@
19692 if( p->tooBig | p->mallocFailed ){
19693 testcase(p->tooBig);
19694 testcase(p->mallocFailed);
19695 return;
19696 }
 
19697 if( N<0 ){
19698 N = sqlite3Strlen30(z);
19699 }
19700 if( N==0 || NEVER(z==0) ){
19701 return;
@@ -19723,19 +19681,20 @@
19723 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
19724 }else{
19725 zNew = sqlite3_realloc(zOld, p->nAlloc);
19726 }
19727 if( zNew ){
19728 if( zOld==0 ) memcpy(zNew, p->zText, p->nChar);
19729 p->zText = zNew;
19730 }else{
19731 p->mallocFailed = 1;
19732 sqlite3StrAccumReset(p);
19733 return;
19734 }
19735 }
19736 }
 
19737 memcpy(&p->zText[p->nChar], z, N);
19738 p->nChar += N;
19739 }
19740
19741 /*
@@ -25172,11 +25131,11 @@
25172 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
25173 }
25174 #endif
25175
25176
25177 #ifdef SQLITE_DEBUG
25178 /*
25179 ** Helper function for printing out trace information from debugging
25180 ** binaries. This returns the string represetation of the supplied
25181 ** integer lock-type.
25182 */
@@ -26007,18 +25966,18 @@
26007 ** locking a random byte from a range, concurrent SHARED locks may exist
26008 ** even if the locking primitive used is always a write-lock.
26009 */
26010 int rc = SQLITE_OK;
26011 unixFile *pFile = (unixFile*)id;
26012 unixInodeInfo *pInode = pFile->pInode;
26013 struct flock lock;
26014 int tErrno = 0;
26015
26016 assert( pFile );
26017 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
26018 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
26019 azFileLock(pInode->eFileLock), pInode->nShared , getpid()));
26020
26021 /* If there is already a lock of this type or more restrictive on the
26022 ** unixFile, do nothing. Don't use the end_lock: exit path, as
26023 ** unixEnterMutex() hasn't been called yet.
26024 */
@@ -26218,11 +26177,10 @@
26218 static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
26219 unixFile *pFile = (unixFile*)id;
26220 unixInodeInfo *pInode;
26221 struct flock lock;
26222 int rc = SQLITE_OK;
26223 int h;
26224
26225 assert( pFile );
26226 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
26227 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
26228 getpid()));
@@ -26230,18 +26188,14 @@
26230 assert( eFileLock<=SHARED_LOCK );
26231 if( pFile->eFileLock<=eFileLock ){
26232 return SQLITE_OK;
26233 }
26234 unixEnterMutex();
26235 h = pFile->h;
26236 pInode = pFile->pInode;
26237 assert( pInode->nShared!=0 );
26238 if( pFile->eFileLock>SHARED_LOCK ){
26239 assert( pInode->eFileLock==pFile->eFileLock );
26240 SimulateIOErrorBenign(1);
26241 SimulateIOError( h=(-1) )
26242 SimulateIOErrorBenign(0);
26243
26244 #ifndef NDEBUG
26245 /* When reducing a lock such that other processes can start
26246 ** reading the database file again, make sure that the
26247 ** transaction counter was updated if any part of the database
@@ -26248,15 +26202,10 @@
26248 ** file changed. If the transaction counter is not updated,
26249 ** other connections to the same file might not realize that
26250 ** the file has changed and hence might not know to flush their
26251 ** cache. The use of a stale cache can lead to database corruption.
26252 */
26253 #if 0
26254 assert( pFile->inNormalWrite==0
26255 || pFile->dbUpdate==0
26256 || pFile->transCntrChng==1 );
26257 #endif
26258 pFile->inNormalWrite = 0;
26259 #endif
26260
26261 /* downgrading to a shared lock on NFS involves clearing the write lock
26262 ** before establishing the readlock - to avoid a race condition we downgrade
@@ -26354,13 +26303,10 @@
26354 pInode->nShared--;
26355 if( pInode->nShared==0 ){
26356 lock.l_type = F_UNLCK;
26357 lock.l_whence = SEEK_SET;
26358 lock.l_start = lock.l_len = 0L;
26359 SimulateIOErrorBenign(1);
26360 SimulateIOError( h=(-1) )
26361 SimulateIOErrorBenign(0);
26362 if( unixFileLock(pFile, &lock)==0 ){
26363 pInode->eFileLock = NO_LOCK;
26364 }else{
26365 rc = SQLITE_IOERR_UNLOCK;
26366 pFile->lastErrno = errno;
@@ -29191,10 +29137,13 @@
29191 assert( zFilename==0 || zFilename[0]=='/'
29192 || pVfs->pAppData==(void*)&autolockIoFinder );
29193 #else
29194 assert( zFilename==0 || zFilename[0]=='/' );
29195 #endif
 
 
 
29196
29197 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
29198 pNew->h = h;
29199 pNew->zPath = zFilename;
29200 if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
@@ -29293,10 +29242,11 @@
29293 /* Dotfile locking uses the file path so it needs to be included in
29294 ** the dotlockLockingContext
29295 */
29296 char *zLockFile;
29297 int nFilename;
 
29298 nFilename = (int)strlen(zFilename) + 6;
29299 zLockFile = (char *)sqlite3_malloc(nFilename);
29300 if( zLockFile==0 ){
29301 rc = SQLITE_NOMEM;
29302 }else{
@@ -30072,14 +30022,16 @@
30072 ** the current time and date as a Julian Day number times 86_400_000. In
30073 ** other words, write into *piNow the number of milliseconds since the Julian
30074 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
30075 ** proleptic Gregorian calendar.
30076 **
30077 ** On success, return 0. Return 1 if the time and date cannot be found.
 
30078 */
30079 static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
30080 static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
 
30081 #if defined(NO_GETTOD)
30082 time_t t;
30083 time(&t);
30084 *piNow = ((sqlite3_int64)t)*1000 + unixEpoch;
30085 #elif OS_VXWORKS
@@ -30086,34 +30038,38 @@
30086 struct timespec sNow;
30087 clock_gettime(CLOCK_REALTIME, &sNow);
30088 *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
30089 #else
30090 struct timeval sNow;
30091 gettimeofday(&sNow, 0);
30092 *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
 
 
 
30093 #endif
30094
30095 #ifdef SQLITE_TEST
30096 if( sqlite3_current_time ){
30097 *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
30098 }
30099 #endif
30100 UNUSED_PARAMETER(NotUsed);
30101 return 0;
30102 }
30103
30104 /*
30105 ** Find the current time (in Universal Coordinated Time). Write the
30106 ** current time and date as a Julian Day number into *prNow and
30107 ** return 0. Return 1 if the time and date cannot be found.
30108 */
30109 static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
30110 sqlite3_int64 i;
 
30111 UNUSED_PARAMETER(NotUsed);
30112 unixCurrentTimeInt64(0, &i);
30113 *prNow = i/86400000.0;
30114 return 0;
30115 }
30116
30117 /*
30118 ** We added the xGetLastError() method with the intention of providing
30119 ** better low-level error messages when operating-system problems come up
@@ -34612,11 +34568,11 @@
34612 }
34613 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
34614 UNUSED_PARAMETER(pVfs);
34615 getLastErrorMsg(nBuf, zBufOut);
34616 }
34617 void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
34618 UNUSED_PARAMETER(pVfs);
34619 #if SQLITE_OS_WINCE
34620 /* The GetProcAddressA() routine is only available on wince. */
34621 return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol);
34622 #else
@@ -34623,11 +34579,11 @@
34623 /* All other windows platforms expect GetProcAddress() to take
34624 ** an Ansi string regardless of the _UNICODE setting */
34625 return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol);
34626 #endif
34627 }
34628 void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
34629 UNUSED_PARAMETER(pVfs);
34630 FreeLibrary((HANDLE)pHandle);
34631 }
34632 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
34633 #define winDlOpen 0
@@ -34697,11 +34653,12 @@
34697 ** the current time and date as a Julian Day number times 86_400_000. In
34698 ** other words, write into *piNow the number of milliseconds since the Julian
34699 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
34700 ** proleptic Gregorian calendar.
34701 **
34702 ** On success, return 0. Return 1 if the time and date cannot be found.
 
34703 */
34704 static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
34705 /* FILETIME structure is a 64-bit value representing the number of
34706 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
34707 */
@@ -34717,11 +34674,11 @@
34717 #if SQLITE_OS_WINCE
34718 SYSTEMTIME time;
34719 GetSystemTime(&time);
34720 /* if SystemTimeToFileTime() fails, it returns zero. */
34721 if (!SystemTimeToFileTime(&time,&ft)){
34722 return 1;
34723 }
34724 #else
34725 GetSystemTimeAsFileTime( &ft );
34726 #endif
34727
@@ -34733,19 +34690,19 @@
34733 if( sqlite3_current_time ){
34734 *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
34735 }
34736 #endif
34737 UNUSED_PARAMETER(pVfs);
34738 return 0;
34739 }
34740
34741 /*
34742 ** Find the current time (in Universal Coordinated Time). Write the
34743 ** current time and date as a Julian Day number into *prNow and
34744 ** return 0. Return 1 if the time and date cannot be found.
34745 */
34746 int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
34747 int rc;
34748 sqlite3_int64 i;
34749 rc = winCurrentTimeInt64(pVfs, &i);
34750 if( !rc ){
34751 *prNow = i/86400000.0;
@@ -40068,11 +40025,10 @@
40068 needPagerReset = 0;
40069 }
40070 rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
40071 if( rc!=SQLITE_OK ){
40072 if( rc==SQLITE_DONE ){
40073 rc = SQLITE_OK;
40074 pPager->journalOff = szJ;
40075 break;
40076 }else if( rc==SQLITE_IOERR_SHORT_READ ){
40077 /* If the journal has been truncated, simply stop reading and
40078 ** processing the journal. This might happen if the journal was
@@ -40330,10 +40286,11 @@
40330 #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
40331 PgHdr *p; /* For looping over pages */
40332 #endif
40333
40334 assert( pPager->pWal );
 
40335 #ifdef SQLITE_DEBUG
40336 /* Verify that the page list is in accending order */
40337 for(p=pList; p && p->pDirty; p=p->pDirty){
40338 assert( p->pgno < p->pDirty->pgno );
40339 }
@@ -46566,11 +46523,11 @@
46566 */
46567 if( iRead ){
46568 int sz;
46569 i64 iOffset;
46570 sz = pWal->hdr.szPage;
46571 sz = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
46572 testcase( sz<=32768 );
46573 testcase( sz>=65536 );
46574 iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
46575 *pInWal = 1;
46576 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
@@ -49879,21 +49836,23 @@
49879 */
49880 if( isMemdb==0 && isTempDb==0 ){
49881 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
49882 int nFullPathname = pVfs->mxPathname+1;
49883 char *zFullPathname = sqlite3Malloc(nFullPathname);
49884 sqlite3_mutex *mutexShared;
49885 p->sharable = 1;
49886 if( !zFullPathname ){
49887 sqlite3_free(p);
49888 return SQLITE_NOMEM;
49889 }
49890 sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
 
49891 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
49892 sqlite3_mutex_enter(mutexOpen);
49893 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
49894 sqlite3_mutex_enter(mutexShared);
 
49895 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
49896 assert( pBt->nRef>0 );
49897 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
49898 && sqlite3PagerVfs(pBt->pPager)==pVfs ){
49899 int iDb;
@@ -49995,13 +49954,13 @@
49995
49996 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
49997 /* Add the new BtShared object to the linked list sharable BtShareds.
49998 */
49999 if( p->sharable ){
50000 sqlite3_mutex *mutexShared;
50001 pBt->nRef = 1;
50002 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
50003 if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
50004 pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
50005 if( pBt->mutex==0 ){
50006 rc = SQLITE_NOMEM;
50007 db->mallocFailed = 0;
@@ -50079,16 +50038,16 @@
50079 ** true if the BtShared.nRef counter reaches zero and return
50080 ** false if it is still positive.
50081 */
50082 static int removeFromSharingList(BtShared *pBt){
50083 #ifndef SQLITE_OMIT_SHARED_CACHE
50084 sqlite3_mutex *pMaster;
50085 BtShared *pList;
50086 int removed = 0;
50087
50088 assert( sqlite3_mutex_notheld(pBt->mutex) );
50089 pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
50090 sqlite3_mutex_enter(pMaster);
50091 pBt->nRef--;
50092 if( pBt->nRef<=0 ){
50093 if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
50094 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
@@ -52698,11 +52657,10 @@
52698 }
52699 }
52700 if( c==0 ){
52701 if( pPage->intKey && !pPage->leaf ){
52702 lwr = idx;
52703 upr = lwr - 1;
52704 break;
52705 }else{
52706 *pRes = 0;
52707 rc = SQLITE_OK;
52708 goto moveto_finish;
@@ -52716,11 +52674,11 @@
52716 if( lwr>upr ){
52717 break;
52718 }
52719 pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
52720 }
52721 assert( lwr==upr+1 );
52722 assert( pPage->isInit );
52723 if( pPage->leaf ){
52724 chldPg = 0;
52725 }else if( lwr>=pPage->nCell ){
52726 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
@@ -52981,10 +52939,12 @@
52981 }
52982 if( rc ){
52983 pTrunk = 0;
52984 goto end_allocate_page;
52985 }
 
 
52986
52987 k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
52988 if( k==0 && !searchList ){
52989 /* The trunk has no leaves and the list is not being searched.
52990 ** So extract the trunk page itself and use it as the newly
@@ -54108,17 +54068,19 @@
54108 ** This is safe because dropping a cell only overwrites the first
54109 ** four bytes of it, and this function does not need the first
54110 ** four bytes of the divider cell. So the pointer is safe to use
54111 ** later on.
54112 **
54113 ** Unless SQLite is compiled in secure-delete mode. In this case,
54114 ** the dropCell() routine will overwrite the entire cell with zeroes.
54115 ** In this case, temporarily copy the cell into the aOvflSpace[]
54116 ** buffer. It will be copied out again as soon as the aSpace[] buffer
54117 ** is allocated. */
54118 if( pBt->secureDelete ){
54119 int iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
 
 
54120 if( (iOff+szNew[i])>(int)pBt->usableSize ){
54121 rc = SQLITE_CORRUPT_BKPT;
54122 memset(apOld, 0, (i+1)*sizeof(MemPage*));
54123 goto balance_cleanup;
54124 }else{
@@ -54534,10 +54496,11 @@
54534 int isDivider = 0;
54535 while( i==iNextOld ){
54536 /* Cell i is the cell immediately following the last cell on old
54537 ** sibling page j. If the siblings are not leaf pages of an
54538 ** intkey b-tree, then cell i was a divider cell. */
 
54539 pOld = apCopy[++j];
54540 iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
54541 if( pOld->nOverflow ){
54542 nOverflow = pOld->nOverflow;
54543 iOverflow = i + !leafData + pOld->aOvfl[0].idx;
@@ -56876,18 +56839,18 @@
56876 /*
56877 ** Release all resources associated with an sqlite3_backup* handle.
56878 */
56879 SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p){
56880 sqlite3_backup **pp; /* Ptr to head of pagers backup list */
56881 sqlite3_mutex *mutex; /* Mutex to protect source database */
56882 int rc; /* Value to return */
56883
56884 /* Enter the mutexes */
56885 if( p==0 ) return SQLITE_OK;
56886 sqlite3_mutex_enter(p->pSrcDb->mutex);
56887 sqlite3BtreeEnter(p->pSrc);
56888 mutex = p->pSrcDb->mutex;
56889 if( p->pDestDb ){
56890 sqlite3_mutex_enter(p->pDestDb->mutex);
56891 }
56892
56893 /* Detach this backup from the source pager. */
@@ -58983,34 +58946,33 @@
58983 ** Change the comment on the the most recently coded instruction. Or
58984 ** insert a No-op and add the comment to that new instruction. This
58985 ** makes the code easier to read during debugging. None of this happens
58986 ** in a production build.
58987 */
58988 SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
58989 va_list ap;
58990 if( !p ) return;
58991 assert( p->nOp>0 || p->aOp==0 );
58992 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
58993 if( p->nOp ){
58994 char **pz = &p->aOp[p->nOp-1].zComment;
 
 
 
 
 
 
 
58995 va_start(ap, zFormat);
58996 sqlite3DbFree(p->db, *pz);
58997 *pz = sqlite3VMPrintf(p->db, zFormat, ap);
58998 va_end(ap);
58999 }
59000 }
59001 SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe *p, const char *zFormat, ...){
59002 va_list ap;
59003 if( !p ) return;
59004 sqlite3VdbeAddOp0(p, OP_Noop);
59005 assert( p->nOp>0 || p->aOp==0 );
59006 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
59007 if( p->nOp ){
59008 char **pz = &p->aOp[p->nOp-1].zComment;
59009 va_start(ap, zFormat);
59010 sqlite3DbFree(p->db, *pz);
59011 *pz = sqlite3VMPrintf(p->db, zFormat, ap);
59012 va_end(ap);
59013 }
59014 }
59015 #endif /* NDEBUG */
59016
@@ -61266,11 +61228,11 @@
61266 ** than 2GiB are support - anything large must be database corruption.
61267 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
61268 ** this code can safely assume that nCellKey is 32-bits
61269 */
61270 assert( sqlite3BtreeCursorIsValid(pCur) );
61271 rc = sqlite3BtreeKeySize(pCur, &nCellKey);
61272 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
61273 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
61274
61275 /* Read in the complete content of the index entry */
61276 memset(&m, 0, sizeof(m));
@@ -61341,11 +61303,11 @@
61341 int rc;
61342 BtCursor *pCur = pC->pCursor;
61343 Mem m;
61344
61345 assert( sqlite3BtreeCursorIsValid(pCur) );
61346 rc = sqlite3BtreeKeySize(pCur, &nCellKey);
61347 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
61348 /* nCellKey will always be between 0 and 0xffffffff because of the say
61349 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
61350 if( nCellKey<=0 || nCellKey>0x7fffffff ){
61351 *res = 0;
@@ -65617,20 +65579,20 @@
65617 }else if( u.am.pC->cacheStatus==p->cacheCtr ){
65618 u.am.payloadSize = u.am.pC->payloadSize;
65619 u.am.zRec = (char*)u.am.pC->aRow;
65620 }else if( u.am.pC->isIndex ){
65621 assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) );
65622 rc = sqlite3BtreeKeySize(u.am.pCrsr, &u.am.payloadSize64);
65623 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
65624 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
65625 ** payload size, so it is impossible for u.am.payloadSize64 to be
65626 ** larger than 32 bits. */
65627 assert( (u.am.payloadSize64 & SQLITE_MAX_U32)==(u64)u.am.payloadSize64 );
65628 u.am.payloadSize = (u32)u.am.payloadSize64;
65629 }else{
65630 assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) );
65631 rc = sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize);
65632 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
65633 }
65634 }else if( ALWAYS(u.am.pC->pseudoTableReg>0) ){
65635 u.am.pReg = &aMem[u.am.pC->pseudoTableReg];
65636 assert( u.am.pReg->flags & MEM_Blob );
@@ -67678,18 +67640,18 @@
67678 rc = sqlite3VdbeCursorMoveto(u.bk.pC);
67679 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
67680
67681 if( u.bk.pC->isIndex ){
67682 assert( !u.bk.pC->isTable );
67683 rc = sqlite3BtreeKeySize(u.bk.pCrsr, &u.bk.n64);
67684 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
67685 if( u.bk.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67686 goto too_big;
67687 }
67688 u.bk.n = (u32)u.bk.n64;
67689 }else{
67690 rc = sqlite3BtreeDataSize(u.bk.pCrsr, &u.bk.n);
67691 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
67692 if( u.bk.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
67693 goto too_big;
67694 }
67695 }
@@ -73322,11 +73284,12 @@
73322 pNew->flags |= EP_IntValue;
73323 pNew->u.iValue = iValue;
73324 }else{
73325 int c;
73326 pNew->u.zToken = (char*)&pNew[1];
73327 memcpy(pNew->u.zToken, pToken->z, pToken->n);
 
73328 pNew->u.zToken[pToken->n] = 0;
73329 if( dequote && nExtra>=3
73330 && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
73331 sqlite3Dequote(pNew->u.zToken);
73332 if( c=='"' ) pNew->flags |= EP_DblQuoted;
@@ -74361,15 +74324,23 @@
74361 ** ephemeral table.
74362 */
74363 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
74364 if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
74365 sqlite3 *db = pParse->db; /* Database connection */
74366 Expr *pExpr = p->pEList->a[0].pExpr; /* Expression <column> */
74367 int iCol = pExpr->iColumn; /* Index of column <column> */
74368 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
74369 Table *pTab = p->pSrc->a[0].pTab; /* Table <table>. */
 
 
74370 int iDb; /* Database idx for pTab */
 
 
 
 
 
 
 
 
74371
74372 /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
74373 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
74374 sqlite3CodeVerifySchema(pParse, iDb);
74375 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
@@ -76372,11 +76343,11 @@
76372 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
76373 return 2;
76374 }
76375 }else if( pA->op!=TK_COLUMN && pA->u.zToken ){
76376 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
76377 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ){
76378 return 2;
76379 }
76380 }
76381 if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1;
76382 if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2;
@@ -81778,17 +81749,19 @@
81778 */
81779 static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
81780 Table *pTab = pIndex->pTable; /* The table that is indexed */
81781 int iTab = pParse->nTab++; /* Btree cursor used for pTab */
81782 int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */
81783 int iSorter = iTab; /* Cursor opened by OpenSorter (if in use) */
81784 int addr1; /* Address of top of loop */
81785 int addr2; /* Address to jump to for next iteration */
81786 int tnum; /* Root page of index */
81787 Vdbe *v; /* Generate code into this virtual machine */
81788 KeyInfo *pKey; /* KeyInfo for index */
 
81789 int regIdxKey; /* Registers containing the index key */
 
81790 int regRecord; /* Register holding assemblied index record */
81791 sqlite3 *db = pParse->db; /* The database connection */
81792 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
81793
81794 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -81818,21 +81791,22 @@
81818
81819 #ifndef SQLITE_OMIT_MERGE_SORT
81820 /* Open the sorter cursor if we are to use one. */
81821 iSorter = pParse->nTab++;
81822 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
 
 
81823 #endif
81824
81825 /* Open the table. Loop through all rows of the table, inserting index
81826 ** records into the sorter. */
81827 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
81828 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
81829 addr2 = addr1 + 1;
81830 regRecord = sqlite3GetTempReg(pParse);
81831 regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
81832
81833 #ifndef SQLITE_OMIT_MERGE_SORT
 
81834 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
81835 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
81836 sqlite3VdbeJumpHere(v, addr1);
81837 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
81838 if( pIndex->onError!=OE_None ){
@@ -81848,10 +81822,12 @@
81848 }
81849 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
81850 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
81851 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
81852 #else
 
 
81853 if( pIndex->onError!=OE_None ){
81854 const int regRowid = regIdxKey + pIndex->nColumn;
81855 const int j2 = sqlite3VdbeCurrentAddr(v) + 2;
81856 void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey);
81857
@@ -81945,10 +81921,11 @@
81945 ** before looking up the table.
81946 */
81947 assert( pName1 && pName2 );
81948 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
81949 if( iDb<0 ) goto exit_create_index;
 
81950
81951 #ifndef SQLITE_OMIT_TEMPDB
81952 /* If the index name was unqualified, check if the the table
81953 ** is a temp table. If so, set the database to 1. Do not do this
81954 ** if initialising a database schema.
@@ -81972,10 +81949,11 @@
81972 pTblName->a[0].zDatabase);
81973 if( !pTab || db->mallocFailed ) goto exit_create_index;
81974 assert( db->aDb[iDb].pSchema==pTab->pSchema );
81975 }else{
81976 assert( pName==0 );
 
81977 pTab = pParse->pNewTable;
81978 if( !pTab ) goto exit_create_index;
81979 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
81980 }
81981 pDb = &db->aDb[iDb];
@@ -82014,10 +81992,11 @@
82014 ** own name.
82015 */
82016 if( pName ){
82017 zName = sqlite3NameFromToken(db, pName);
82018 if( zName==0 ) goto exit_create_index;
 
82019 if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
82020 goto exit_create_index;
82021 }
82022 if( !db->init.busy ){
82023 if( sqlite3FindTable(db, zName, 0)!=0 ){
@@ -82869,17 +82848,14 @@
82869
82870 /*
82871 ** Commit a transaction
82872 */
82873 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse *pParse){
82874 sqlite3 *db;
82875 Vdbe *v;
82876
82877 assert( pParse!=0 );
82878 db = pParse->db;
82879 assert( db!=0 );
82880 /* if( db->aDb[0].pBt==0 ) return; */
82881 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ){
82882 return;
82883 }
82884 v = sqlite3GetVdbe(pParse);
82885 if( v ){
@@ -82889,17 +82865,14 @@
82889
82890 /*
82891 ** Rollback a transaction
82892 */
82893 SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse *pParse){
82894 sqlite3 *db;
82895 Vdbe *v;
82896
82897 assert( pParse!=0 );
82898 db = pParse->db;
82899 assert( db!=0 );
82900 /* if( db->aDb[0].pBt==0 ) return; */
82901 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ){
82902 return;
82903 }
82904 v = sqlite3GetVdbe(pParse);
82905 if( v ){
@@ -84701,20 +84674,19 @@
84701 /* Verify that the call to _bytes() does not invalidate the _text() pointer */
84702 assert( z2==(char*)sqlite3_value_text(argv[0]) );
84703 if( z2 ){
84704 z1 = contextMalloc(context, ((i64)n)+1);
84705 if( z1 ){
84706 memcpy(z1, z2, n+1);
84707 for(i=0; z1[i]; i++){
84708 z1[i] = (char)sqlite3Toupper(z1[i]);
84709 }
84710 sqlite3_result_text(context, z1, -1, sqlite3_free);
84711 }
84712 }
84713 }
84714 static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
84715 u8 *z1;
84716 const char *z2;
84717 int i, n;
84718 UNUSED_PARAMETER(argc);
84719 z2 = (char*)sqlite3_value_text(argv[0]);
84720 n = sqlite3_value_bytes(argv[0]);
@@ -84721,15 +84693,14 @@
84721 /* Verify that the call to _bytes() does not invalidate the _text() pointer */
84722 assert( z2==(char*)sqlite3_value_text(argv[0]) );
84723 if( z2 ){
84724 z1 = contextMalloc(context, ((i64)n)+1);
84725 if( z1 ){
84726 memcpy(z1, z2, n+1);
84727 for(i=0; z1[i]; i++){
84728 z1[i] = sqlite3Tolower(z1[i]);
84729 }
84730 sqlite3_result_text(context, (char *)z1, -1, sqlite3_free);
84731 }
84732 }
84733 }
84734
84735
@@ -87102,10 +87073,11 @@
87102 sqlite3SelectDelete(db, pSelect);
87103 if( db->mallocFailed==1 ){
87104 fkTriggerDelete(db, pTrigger);
87105 return 0;
87106 }
 
87107
87108 switch( action ){
87109 case OE_Restrict:
87110 pStep->op = TK_SELECT;
87111 break;
@@ -90025,11 +89997,11 @@
90025 sqlite3_vfs *pVfs = db->pVfs;
90026 void *handle;
90027 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
90028 char *zErrmsg = 0;
90029 void **aHandle;
90030 const int nMsg = 300;
90031
90032 if( pzErrMsg ) *pzErrMsg = 0;
90033
90034 /* Ticket #1863. To avoid a creating security problems for older
90035 ** applications that relink against newer versions of SQLite, the
@@ -90062,10 +90034,11 @@
90062 }
90063 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
90064 sqlite3OsDlSym(pVfs, handle, zProc);
90065 if( xInit==0 ){
90066 if( pzErrMsg ){
 
90067 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
90068 if( zErrmsg ){
90069 sqlite3_snprintf(nMsg, zErrmsg,
90070 "no entry point [%s] in shared library [%s]", zProc,zFile);
90071 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
@@ -90747,11 +90720,11 @@
90747 ){
90748 int iReg;
90749 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
90750 sqlite3CodeVerifySchema(pParse, iDb);
90751 iReg = ++pParse->nMem;
90752 if( zLeft[0]=='p' ){
90753 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
90754 }else{
90755 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, sqlite3Atoi(zRight));
90756 }
90757 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
@@ -91360,11 +91333,11 @@
91360 { OP_IfNeg, 1, 0, 0}, /* 1 */
91361 { OP_String8, 0, 3, 0}, /* 2 */
91362 { OP_ResultRow, 3, 1, 0},
91363 };
91364
91365 int isQuick = (zLeft[0]=='q');
91366
91367 /* Initialize the VDBE program */
91368 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
91369 pParse->nMem = 6;
91370 sqlite3VdbeSetNumCols(v, 1);
@@ -93942,11 +93915,14 @@
93942 /* If the column contains an "AS <name>" phrase, use <name> as the name */
93943 zName = sqlite3DbStrDup(db, zName);
93944 }else{
93945 Expr *pColExpr = p; /* The expression that is the result column name */
93946 Table *pTab; /* Table associated with this expression */
93947 while( pColExpr->op==TK_DOT ) pColExpr = pColExpr->pRight;
 
 
 
93948 if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
93949 /* For columns use the column name name */
93950 int iCol = pColExpr->iColumn;
93951 pTab = pColExpr->pTab;
93952 if( iCol<0 ) iCol = pTab->iPKey;
@@ -98940,10 +98916,11 @@
98940 break;
98941 }
98942 }
98943 }
98944 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
 
98945 if( openAll || aRegIdx[i]>0 ){
98946 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
98947 sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,
98948 (char*)pKey, P4_KEYINFO_HANDOFF);
98949 assert( pParse->nTab>iCur+i+1 );
@@ -99113,10 +99090,11 @@
99113 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
99114 sqlite3VdbeJumpHere(v, addr);
99115
99116 /* Close all tables */
99117 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
 
99118 if( openAll || aRegIdx[i]>0 ){
99119 sqlite3VdbeAddOp2(v, OP_Close, iCur+i+1, 0);
99120 }
99121 }
99122 sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
@@ -103144,11 +103122,10 @@
103144 assert( roundUp==0 || roundUp==1 );
103145 assert( pIdx->nSample>0 );
103146 if( pVal==0 ) return SQLITE_ERROR;
103147 n = pIdx->aiRowEst[0];
103148 aSample = pIdx->aSample;
103149 i = 0;
103150 eType = sqlite3_value_type(pVal);
103151
103152 if( eType==SQLITE_INTEGER ){
103153 v = sqlite3_value_int64(pVal);
103154 r = (i64)v;
@@ -105564,11 +105541,12 @@
105564 assert( bestJ>=0 );
105565 assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
105566 WHERETRACE(("*** Optimizer selects table %d for loop %d"
105567 " with cost=%g and nRow=%g\n",
105568 bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.plan.nRow));
105569 if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){
 
105570 *ppOrderBy = 0;
105571 }
105572 if( (bestPlan.plan.wsFlags & WHERE_DISTINCT)!=0 ){
105573 assert( pWInfo->eDistinct==0 );
105574 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
@@ -109180,11 +109158,13 @@
109180 sqlite3ParserTOKENTYPE yyminor /* The value for the token */
109181 sqlite3ParserARG_PDECL /* Optional %extra_argument parameter */
109182 ){
109183 YYMINORTYPE yyminorunion;
109184 int yyact; /* The parser action. */
 
109185 int yyendofinput; /* True if we are at the end of input */
 
109186 #ifdef YYERRORSYMBOL
109187 int yyerrorhit = 0; /* True if yymajor has invoked an error */
109188 #endif
109189 yyParser *yypParser; /* The parser */
109190
@@ -109203,11 +109183,13 @@
109203 yypParser->yyerrcnt = -1;
109204 yypParser->yystack[0].stateno = 0;
109205 yypParser->yystack[0].major = 0;
109206 }
109207 yyminorunion.yy0 = yyminor;
 
109208 yyendofinput = (yymajor==0);
 
109209 sqlite3ParserARG_STORE;
109210
109211 #ifndef NDEBUG
109212 if( yyTraceFILE ){
109213 fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
@@ -109215,11 +109197,10 @@
109215 #endif
109216
109217 do{
109218 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
109219 if( yyact<YYNSTATE ){
109220 assert( !yyendofinput ); /* Impossible to shift the $ token */
109221 yy_shift(yypParser,yyact,yymajor,&yyminorunion);
109222 yypParser->yyerrcnt--;
109223 yymajor = YYNOCODE;
109224 }else if( yyact < YYNSTATE + YYNRULE ){
109225 yy_reduce(yypParser,yyact-YYNSTATE);
@@ -110607,11 +110588,11 @@
110607 **
110608 ** * Recursive calls to this routine from thread X return immediately
110609 ** without blocking.
110610 */
110611 SQLITE_API int sqlite3_initialize(void){
110612 sqlite3_mutex *pMaster; /* The main static mutex */
110613 int rc; /* Result code */
110614
110615 #ifdef SQLITE_OMIT_WSD
110616 rc = sqlite3_wsd_init(4096, 24);
110617 if( rc!=SQLITE_OK ){
@@ -110641,11 +110622,11 @@
110641 ** This operation is protected by the STATIC_MASTER mutex. Note that
110642 ** MutexAlloc() is called for a static mutex prior to initializing the
110643 ** malloc subsystem - this implies that the allocation of a static
110644 ** mutex must not require support from the malloc subsystem.
110645 */
110646 pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
110647 sqlite3_mutex_enter(pMaster);
110648 sqlite3GlobalConfig.isMutexInit = 1;
110649 if( !sqlite3GlobalConfig.isMallocInit ){
110650 rc = sqlite3MallocInit();
110651 }
@@ -111715,17 +111696,17 @@
111715 sqlite3 *db,
111716 const char *zName,
111717 int nArg
111718 ){
111719 int nName = sqlite3Strlen30(zName);
111720 int rc;
111721 sqlite3_mutex_enter(db->mutex);
111722 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
111723 sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
111724 0, sqlite3InvalidFunction, 0, 0, 0);
111725 }
111726 rc = sqlite3ApiExit(db, SQLITE_OK);
111727 sqlite3_mutex_leave(db->mutex);
111728 return rc;
111729 }
111730
111731 #ifndef SQLITE_OMIT_TRACE
@@ -112783,10 +112764,11 @@
112783 if( db ){
112784 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
112785 sqlite3_mutex_leave(db->mutex);
112786 }
112787 rc = sqlite3_errcode(db);
 
112788 if( rc==SQLITE_NOMEM ){
112789 sqlite3_close(db);
112790 db = 0;
112791 }else if( rc!=SQLITE_OK ){
112792 db->magic = SQLITE_MAGIC_SICK;
@@ -114511,10 +114493,17 @@
114511 #else
114512 # define TESTONLY(X)
114513 #endif
114514
114515 #endif /* SQLITE_AMALGAMATION */
 
 
 
 
 
 
 
114516
114517 typedef struct Fts3Table Fts3Table;
114518 typedef struct Fts3Cursor Fts3Cursor;
114519 typedef struct Fts3Expr Fts3Expr;
114520 typedef struct Fts3Phrase Fts3Phrase;
@@ -115012,11 +115001,11 @@
115012 char **pp,
115013 char *pStart,
115014 sqlite3_int64 *pVal
115015 ){
115016 sqlite3_int64 iVal;
115017 char *p = *pp;
115018
115019 /* Pointer p now points at the first byte past the varint we are
115020 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
115021 ** clear on character p[-1]. */
115022 for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
@@ -115413,11 +115402,11 @@
115413 ** the output value undefined. Otherwise SQLITE_OK is returned.
115414 **
115415 ** This function is used when parsing the "prefix=" FTS4 parameter.
115416 */
115417 static int fts3GobbleInt(const char **pp, int *pnOut){
115418 const char *p = *pp; /* Iterator pointer */
115419 int nInt = 0; /* Output value */
115420
115421 for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
115422 nInt = nInt * 10 + (p[0] - '0');
115423 }
@@ -115912,11 +115901,11 @@
115912 if( rc==SQLITE_OK ){
115913 /* If no row was found and no error has occured, then the %_content
115914 ** table is missing a row that is present in the full-text index.
115915 ** The data structures are corrupt.
115916 */
115917 rc = SQLITE_CORRUPT_VTAB;
115918 }
115919 pCsr->isEof = 1;
115920 if( pContext ){
115921 sqlite3_result_error_code(pContext, rc);
115922 }
@@ -115972,11 +115961,11 @@
115972 ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
115973 */
115974 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
115975 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
115976 if( zCsr>zEnd ){
115977 return SQLITE_CORRUPT_VTAB;
115978 }
115979
115980 while( zCsr<zEnd && (piFirst || piLast) ){
115981 int cmp; /* memcmp() result */
115982 int nSuffix; /* Size of term suffix */
@@ -115990,11 +115979,11 @@
115990 }
115991 isFirstTerm = 0;
115992 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
115993
115994 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
115995 rc = SQLITE_CORRUPT_VTAB;
115996 goto finish_scan;
115997 }
115998 if( nPrefix+nSuffix>nAlloc ){
115999 char *zNew;
116000 nAlloc = (nPrefix+nSuffix) * 2;
@@ -116003,10 +115992,11 @@
116003 rc = SQLITE_NOMEM;
116004 goto finish_scan;
116005 }
116006 zBuffer = zNew;
116007 }
 
116008 memcpy(&zBuffer[nPrefix], zCsr, nSuffix);
116009 nBuffer = nPrefix + nSuffix;
116010 zCsr += nSuffix;
116011
116012 /* Compare the term we are searching for with the term just loaded from
@@ -117439,11 +117429,11 @@
117439 ** moves *ppPoslist so that it instead points to the first byte of the
117440 ** same position list.
117441 */
117442 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
117443 char *p = &(*ppPoslist)[-2];
117444 char c;
117445
117446 while( p>pStart && (c=*p--)==0 );
117447 while( p>pStart && (*p & 0x80) | c ){
117448 c = *p--;
117449 }
@@ -118433,11 +118423,11 @@
118433 while( a<pEnd ){
118434 a += sqlite3Fts3GetVarint(a, &nByte);
118435 }
118436 if( nDoc==0 || nByte==0 ){
118437 sqlite3_reset(pStmt);
118438 return SQLITE_CORRUPT_VTAB;
118439 }
118440
118441 pCsr->nDoc = nDoc;
118442 pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
118443 assert( pCsr->nRowAvg>0 );
@@ -118909,12 +118899,15 @@
118909 }
118910
118911 aPoslist = pExpr->pRight->pPhrase->doclist.pList;
118912 nToken = pExpr->pRight->pPhrase->nToken;
118913 for(p=pExpr->pLeft; p && res; p=p->pLeft){
118914 int nNear = p->pParent->nNear;
118915 Fts3Phrase *pPhrase = (
 
 
 
118916 p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
118917 );
118918 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
118919 }
118920 }
@@ -119400,10 +119393,19 @@
119400 pPhrase->aToken[i].pSegcsr = 0;
119401 }
119402 }
119403 }
119404
 
 
 
 
 
 
 
 
 
119405 #if !SQLITE_CORE
119406 /*
119407 ** Initialize API pointer table, if required.
119408 */
119409 SQLITE_API int sqlite3_extension_init(
@@ -120197,12 +120199,16 @@
120197 p->pPhrase = (Fts3Phrase *)&p[1];
120198 p->pPhrase->iColumn = pParse->iDefaultCol;
120199 p->pPhrase->nToken = nToken;
120200
120201 zBuf = (char *)&p->pPhrase->aToken[nToken];
120202 memcpy(zBuf, zTemp, nTemp);
120203 sqlite3_free(zTemp);
 
 
 
 
120204
120205 for(jj=0; jj<p->pPhrase->nToken; jj++){
120206 p->pPhrase->aToken[jj].z = zBuf;
120207 zBuf += p->pPhrase->aToken[jj].n;
120208 }
@@ -122957,11 +122963,11 @@
122957 sqlite3_bind_int64(pStmt, 1, iDocid);
122958 }
122959 rc = sqlite3_step(pStmt);
122960 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
122961 rc = sqlite3_reset(pStmt);
122962 if( rc==SQLITE_OK ) rc = SQLITE_CORRUPT_VTAB;
122963 pStmt = 0;
122964 }else{
122965 rc = SQLITE_OK;
122966 }
122967 }
@@ -123761,11 +123767,11 @@
123761 pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
123762 pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
123763 if( nPrefix<0 || nSuffix<=0
123764 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
123765 ){
123766 return SQLITE_CORRUPT_VTAB;
123767 }
123768
123769 if( nPrefix+nSuffix>pReader->nTermAlloc ){
123770 int nNew = (nPrefix+nSuffix)*2;
123771 char *zNew = sqlite3_realloc(pReader->zTerm, nNew);
@@ -123791,11 +123797,11 @@
123791 ** of these statements is untrue, then the data structure is corrupt.
123792 */
123793 if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode]
123794 || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
123795 ){
123796 return SQLITE_CORRUPT_VTAB;
123797 }
123798 return SQLITE_OK;
123799 }
123800
123801 /*
@@ -125745,11 +125751,10 @@
125745 sqlite_int64 *pRowid /* OUT: The affected (or effected) rowid */
125746 ){
125747 Fts3Table *p = (Fts3Table *)pVtab;
125748 int rc = SQLITE_OK; /* Return Code */
125749 int isRemove = 0; /* True for an UPDATE or DELETE */
125750 sqlite3_int64 iRemove = 0; /* Rowid removed by UPDATE or DELETE */
125751 u32 *aSzIns = 0; /* Sizes of inserted documents */
125752 u32 *aSzDel; /* Sizes of deleted documents */
125753 int nChng = 0; /* Net change in number of documents */
125754 int bInsertDone = 0;
125755
@@ -125828,23 +125833,23 @@
125828 /* If this is a DELETE or UPDATE operation, remove the old record. */
125829 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
125830 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
125831 rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
125832 isRemove = 1;
125833 iRemove = sqlite3_value_int64(apVal[0]);
125834 }
125835
125836 /* If this is an INSERT or UPDATE operation, insert the new record. */
125837 if( nArg>1 && rc==SQLITE_OK ){
125838 if( bInsertDone==0 ){
125839 rc = fts3InsertData(p, apVal, pRowid);
125840 if( rc==SQLITE_CONSTRAINT ) rc = SQLITE_CORRUPT_VTAB;
125841 }
125842 if( rc==SQLITE_OK && (!isRemove || *pRowid!=iRemove) ){
125843 rc = fts3PendingTermsDocid(p, *pRowid);
125844 }
125845 if( rc==SQLITE_OK ){
 
125846 rc = fts3InsertTerms(p, apVal, aSzIns);
125847 }
125848 if( p->bHasDocsize ){
125849 fts3InsertDocsize(&rc, p, aSzIns);
125850 }
@@ -126734,11 +126739,11 @@
126734 pStmt = *ppStmt;
126735 assert( sqlite3_data_count(pStmt)==1 );
126736
126737 a = sqlite3_column_blob(pStmt, 0);
126738 a += sqlite3Fts3GetVarint(a, &nDoc);
126739 if( nDoc==0 ) return SQLITE_CORRUPT_VTAB;
126740 *pnDoc = (u32)nDoc;
126741
126742 if( paLen ) *paLen = a;
126743 return SQLITE_OK;
126744 }
@@ -127313,11 +127318,11 @@
127313 sqlite3_snprintf(sizeof(aBuffer), aBuffer,
127314 "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
127315 );
127316 rc = fts3StringAppend(&res, aBuffer, -1);
127317 }else if( rc==SQLITE_DONE ){
127318 rc = SQLITE_CORRUPT_VTAB;
127319 }
127320 }
127321 }
127322 if( rc==SQLITE_DONE ){
127323 rc = SQLITE_OK;
@@ -128654,11 +128659,12 @@
128654 pCsr->nConstraint = argc;
128655 if( !pCsr->aConstraint ){
128656 rc = SQLITE_NOMEM;
128657 }else{
128658 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
128659 assert( (idxStr==0 && argc==0) || (int)strlen(idxStr)==argc*2 );
 
128660 for(ii=0; ii<argc; ii++){
128661 RtreeConstraint *p = &pCsr->aConstraint[ii];
128662 p->op = idxStr[ii*2];
128663 p->iCoord = idxStr[ii*2+1]-'a';
128664 if( p->op==RTREE_MATCH ){
@@ -128955,11 +128961,14 @@
128955 int iCell;
128956 sqlite3_int64 iBest = 0;
128957
128958 float fMinGrowth = 0.0;
128959 float fMinArea = 0.0;
 
128960 float fMinOverlap = 0.0;
 
 
128961
128962 int nCell = NCELL(pNode);
128963 RtreeCell cell;
128964 RtreeNode *pChild;
128965
@@ -128987,33 +128996,34 @@
128987 */
128988 for(iCell=0; iCell<nCell; iCell++){
128989 int bBest = 0;
128990 float growth;
128991 float area;
128992 float overlap = 0.0;
128993 nodeGetCell(pRtree, pNode, iCell, &cell);
128994 growth = cellGrowth(pRtree, &cell, pCell);
128995 area = cellArea(pRtree, &cell);
128996
128997 #if VARIANT_RSTARTREE_CHOOSESUBTREE
128998 if( ii==(pRtree->iDepth-1) ){
128999 overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell);
 
 
129000 }
129001 if( (iCell==0)
129002 || (overlap<fMinOverlap)
129003 || (overlap==fMinOverlap && growth<fMinGrowth)
129004 || (overlap==fMinOverlap && growth==fMinGrowth && area<fMinArea)
129005 ){
129006 bBest = 1;
 
129007 }
129008 #else
129009 if( iCell==0||growth<fMinGrowth||(growth==fMinGrowth && area<fMinArea) ){
129010 bBest = 1;
129011 }
129012 #endif
129013 if( bBest ){
129014 fMinOverlap = overlap;
129015 fMinGrowth = growth;
129016 fMinArea = area;
129017 iBest = cell.iRowid;
129018 }
129019 }
129020
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.7.9"
660 #define SQLITE_VERSION_NUMBER 3007009
661 #define SQLITE_SOURCE_ID "2011-10-15 00:16:30 39408702a989f907261c298bf0947f3e68bd10fe"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -3351,11 +3351,12 @@
3351 ** zSql string ends at either the first '\000' or '\u0000' character or
3352 ** the nByte-th byte, whichever comes first. If the caller knows
3353 ** that the supplied string is nul-terminated, then there is a small
3354 ** performance advantage to be gained by passing an nByte parameter that
3355 ** is equal to the number of bytes in the input string <i>including</i>
3356 ** the nul-terminator bytes as this saves SQLite from having to
3357 ** make a copy of the input string.
3358 **
3359 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3360 ** past the end of the first SQL statement in zSql. These routines only
3361 ** compile the first statement in zSql, so *pzTail is left pointing to
3362 ** what remains uncompiled.
@@ -3572,10 +3573,17 @@
3573 ** ^(In those routines that have a fourth argument, its value is the
3574 ** number of bytes in the parameter. To be clear: the value is the
3575 ** number of <u>bytes</u> in the value, not the number of characters.)^
3576 ** ^If the fourth parameter is negative, the length of the string is
3577 ** the number of bytes up to the first zero terminator.
3578 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3579 ** or sqlite3_bind_text16() then that parameter must be the byte offset
3580 ** where the NUL terminator would occur assuming the string were NUL
3581 ** terminated. If any NUL characters occur at byte offsets less than
3582 ** the value of the fourth parameter then the resulting string value will
3583 ** contain embedded NULs. The result of expressions involving strings
3584 ** with embedded NULs is undefined.
3585 **
3586 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3587 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3588 ** string after SQLite has finished with it. ^The destructor is called
3589 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
@@ -4590,11 +4598,16 @@
4598 ** is negative, then SQLite takes result text from the 2nd parameter
4599 ** through the first zero character.
4600 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4601 ** is non-negative, then as many bytes (not characters) of the text
4602 ** pointed to by the 2nd parameter are taken as the application-defined
4603 ** function result. If the 3rd parameter is non-negative, then it
4604 ** must be the byte offset into the string where the NUL terminator would
4605 ** appear if the string where NUL terminated. If any NUL characters occur
4606 ** in the string at a byte offset that is less than the value of the 3rd
4607 ** parameter, then the resulting string will contain embedded NULs and the
4608 ** result of expressions operating on strings with embedded NULs is undefined.
4609 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
4610 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
4611 ** function as the destructor on the text or BLOB result when it has
4612 ** finished using that result.
4613 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
@@ -9315,18 +9328,21 @@
9328 /*
9329 ** If this is a no-op implementation, implement everything as macros.
9330 */
9331 #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
9332 #define sqlite3_mutex_free(X)
9333 #define sqlite3_mutex_enter(X)
9334 #define sqlite3_mutex_try(X) SQLITE_OK
9335 #define sqlite3_mutex_leave(X)
9336 #define sqlite3_mutex_held(X) ((void)(X),1)
9337 #define sqlite3_mutex_notheld(X) ((void)(X),1)
9338 #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
9339 #define sqlite3MutexInit() SQLITE_OK
9340 #define sqlite3MutexEnd()
9341 #define MUTEX_LOGIC(X)
9342 #else
9343 #define MUTEX_LOGIC(X) X
9344 #endif /* defined(SQLITE_MUTEX_OMIT) */
9345
9346 /************** End of mutex.h ***********************************************/
9347 /************** Continuing where we left off in sqliteInt.h ******************/
9348
@@ -11754,19 +11770,21 @@
11770 # define sqlite3VtabInSync(db) 0
11771 # define sqlite3VtabLock(X)
11772 # define sqlite3VtabUnlock(X)
11773 # define sqlite3VtabUnlockList(X)
11774 # define sqlite3VtabSavepoint(X, Y, Z) SQLITE_OK
11775 # define sqlite3GetVTable(X,Y) ((VTable*)0)
11776 #else
11777 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table*);
11778 SQLITE_PRIVATE int sqlite3VtabSync(sqlite3 *db, char **);
11779 SQLITE_PRIVATE int sqlite3VtabRollback(sqlite3 *db);
11780 SQLITE_PRIVATE int sqlite3VtabCommit(sqlite3 *db);
11781 SQLITE_PRIVATE void sqlite3VtabLock(VTable *);
11782 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
11783 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
11784 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
11785 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
11786 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
11787 #endif
11788 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
11789 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
11790 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
@@ -11782,11 +11800,10 @@
11800 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
11801 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
11802 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
11803 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
11804 SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*);
 
11805 SQLITE_PRIVATE const char *sqlite3JournalModename(int);
11806 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*);
11807 SQLITE_PRIVATE int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
11808
11809 /* Declarations for functions in fkey.c. All of these are replaced by
@@ -13558,16 +13575,22 @@
13575 }
13576 return 0;
13577 }
13578
13579 /*
13580 ** Set the time to the current time reported by the VFS.
13581 **
13582 ** Return the number of errors.
13583 */
13584 static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
13585 sqlite3 *db = sqlite3_context_db_handle(context);
13586 if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
13587 p->validJD = 1;
13588 return 0;
13589 }else{
13590 return 1;
13591 }
13592 }
13593
13594 /*
13595 ** Attempt to parse the given string into a Julian Day Number. Return
13596 ** the number of errors.
@@ -13593,12 +13616,11 @@
13616 if( parseYyyyMmDd(zDate,p)==0 ){
13617 return 0;
13618 }else if( parseHhMmSs(zDate, p)==0 ){
13619 return 0;
13620 }else if( sqlite3StrICmp(zDate,"now")==0){
13621 return setDateTimeToCurrent(context, p);
 
13622 }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){
13623 p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5);
13624 p->validJD = 1;
13625 return 0;
13626 }
@@ -14021,12 +14043,13 @@
14043 int i;
14044 const unsigned char *z;
14045 int eType;
14046 memset(p, 0, sizeof(*p));
14047 if( argc==0 ){
14048 return setDateTimeToCurrent(context, p);
14049 }
14050 if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
14051 || eType==SQLITE_INTEGER ){
14052 p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5);
14053 p->validJD = 1;
14054 }else{
14055 z = sqlite3_value_text(argv[0]);
@@ -14334,35 +14357,32 @@
14357 ){
14358 time_t t;
14359 char *zFormat = (char *)sqlite3_user_data(context);
14360 sqlite3 *db;
14361 sqlite3_int64 iT;
14362 struct tm *pTm;
14363 struct tm sNow;
14364 char zBuf[20];
14365
14366 UNUSED_PARAMETER(argc);
14367 UNUSED_PARAMETER(argv);
14368
14369 db = sqlite3_context_db_handle(context);
14370 if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
14371 t = iT/1000 - 10000*(sqlite3_int64)21086676;
14372 #ifdef HAVE_GMTIME_R
14373 pTm = gmtime_r(&t, &sNow);
14374 #else
14375 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14376 pTm = gmtime(&t);
14377 if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
14378 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
14379 #endif
14380 if( pTm ){
14381 strftime(zBuf, 20, zFormat, &sNow);
14382 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
14383 }
 
 
 
 
 
 
 
 
 
 
14384 }
14385 #endif
14386
14387 /*
14388 ** This function registered all of the above C functions as SQL
@@ -14693,16 +14713,16 @@
14713 ** Register a VFS with the system. It is harmless to register the same
14714 ** VFS multiple times. The new VFS becomes the default if makeDflt is
14715 ** true.
14716 */
14717 SQLITE_API int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
14718 MUTEX_LOGIC(sqlite3_mutex *mutex;)
14719 #ifndef SQLITE_OMIT_AUTOINIT
14720 int rc = sqlite3_initialize();
14721 if( rc ) return rc;
14722 #endif
14723 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
14724 sqlite3_mutex_enter(mutex);
14725 vfsUnlink(pVfs);
14726 if( makeDflt || vfsList==0 ){
14727 pVfs->pNext = vfsList;
14728 vfsList = pVfs;
@@ -18946,52 +18966,14 @@
18966 ** an historical reference. Most of the "enhancements" have been backed
18967 ** out so that the functionality is now the same as standard printf().
18968 **
18969 **************************************************************************
18970 **
18971 ** This file contains code for a set of "printf"-like routines. These
18972 ** routines format strings much like the printf() from the standard C
18973 ** library, though the implementation here has enhancements to support
18974 ** SQLlite.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18975 */
18976
18977 /*
18978 ** Conversion types fall into various categories as defined by the
18979 ** following enumeration.
@@ -19125,43 +19107,19 @@
19107 }
19108 }
19109
19110 /*
19111 ** On machines with a small stack size, you can redefine the
19112 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19113 */
19114 #ifndef SQLITE_PRINT_BUF_SIZE
19115 # define SQLITE_PRINT_BUF_SIZE 70
19116 #endif
19117 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
19118
19119 /*
19120 ** Render a string given by "fmt" into the StrAccum object.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19121 */
19122 SQLITE_PRIVATE void sqlite3VXPrintf(
19123 StrAccum *pAccum, /* Accumulate results here */
19124 int useExtended, /* Allow extended %-conversions */
19125 const char *fmt, /* Format string */
@@ -19180,28 +19138,27 @@
19138 etByte flag_altform2; /* True if "!" flag is present */
19139 etByte flag_zeropad; /* True if field width constant starts with zero */
19140 etByte flag_long; /* True if "l" flag is present */
19141 etByte flag_longlong; /* True if the "ll" flag is present */
19142 etByte done; /* Loop termination flag */
19143 etByte xtype = 0; /* Conversion paradigm */
19144 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
19145 sqlite_uint64 longvalue; /* Value for integer types */
19146 LONGDOUBLE_TYPE realvalue; /* Value for real types */
19147 const et_info *infop; /* Pointer to the appropriate info structure */
 
19148 char *zOut; /* Rendering buffer */
19149 int nOut; /* Size of the rendering buffer */
19150 char *zExtra; /* Malloced memory used by some conversion */
 
 
19151 #ifndef SQLITE_OMIT_FLOATING_POINT
19152 int exp, e2; /* exponent of real numbers */
19153 int nsd; /* Number of significant digits returned */
19154 double rounder; /* Used for rounding floating point values */
19155 etByte flag_dp; /* True if decimal point should be shown */
19156 etByte flag_rtz; /* True if trailing zeros should be removed */
 
19157 #endif
19158 char buf[etBUFSIZE]; /* Conversion buffer */
19159
 
19160 bufpt = 0;
19161 for(; (c=(*fmt))!=0; ++fmt){
19162 if( c!='%' ){
19163 int amt;
19164 bufpt = (char *)fmt;
@@ -19692,10 +19649,11 @@
19649 if( p->tooBig | p->mallocFailed ){
19650 testcase(p->tooBig);
19651 testcase(p->mallocFailed);
19652 return;
19653 }
19654 assert( p->zText!=0 || p->nChar==0 );
19655 if( N<0 ){
19656 N = sqlite3Strlen30(z);
19657 }
19658 if( N==0 || NEVER(z==0) ){
19659 return;
@@ -19723,19 +19681,20 @@
19681 zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
19682 }else{
19683 zNew = sqlite3_realloc(zOld, p->nAlloc);
19684 }
19685 if( zNew ){
19686 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
19687 p->zText = zNew;
19688 }else{
19689 p->mallocFailed = 1;
19690 sqlite3StrAccumReset(p);
19691 return;
19692 }
19693 }
19694 }
19695 assert( p->zText );
19696 memcpy(&p->zText[p->nChar], z, N);
19697 p->nChar += N;
19698 }
19699
19700 /*
@@ -25172,11 +25131,11 @@
25131 return sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
25132 }
25133 #endif
25134
25135
25136 #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
25137 /*
25138 ** Helper function for printing out trace information from debugging
25139 ** binaries. This returns the string represetation of the supplied
25140 ** integer lock-type.
25141 */
@@ -26007,18 +25966,18 @@
25966 ** locking a random byte from a range, concurrent SHARED locks may exist
25967 ** even if the locking primitive used is always a write-lock.
25968 */
25969 int rc = SQLITE_OK;
25970 unixFile *pFile = (unixFile*)id;
25971 unixInodeInfo *pInode;
25972 struct flock lock;
25973 int tErrno = 0;
25974
25975 assert( pFile );
25976 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
25977 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
25978 azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared , getpid()));
25979
25980 /* If there is already a lock of this type or more restrictive on the
25981 ** unixFile, do nothing. Don't use the end_lock: exit path, as
25982 ** unixEnterMutex() hasn't been called yet.
25983 */
@@ -26218,11 +26177,10 @@
26177 static int posixUnlock(sqlite3_file *id, int eFileLock, int handleNFSUnlock){
26178 unixFile *pFile = (unixFile*)id;
26179 unixInodeInfo *pInode;
26180 struct flock lock;
26181 int rc = SQLITE_OK;
 
26182
26183 assert( pFile );
26184 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
26185 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
26186 getpid()));
@@ -26230,18 +26188,14 @@
26188 assert( eFileLock<=SHARED_LOCK );
26189 if( pFile->eFileLock<=eFileLock ){
26190 return SQLITE_OK;
26191 }
26192 unixEnterMutex();
 
26193 pInode = pFile->pInode;
26194 assert( pInode->nShared!=0 );
26195 if( pFile->eFileLock>SHARED_LOCK ){
26196 assert( pInode->eFileLock==pFile->eFileLock );
 
 
 
26197
26198 #ifndef NDEBUG
26199 /* When reducing a lock such that other processes can start
26200 ** reading the database file again, make sure that the
26201 ** transaction counter was updated if any part of the database
@@ -26248,15 +26202,10 @@
26202 ** file changed. If the transaction counter is not updated,
26203 ** other connections to the same file might not realize that
26204 ** the file has changed and hence might not know to flush their
26205 ** cache. The use of a stale cache can lead to database corruption.
26206 */
 
 
 
 
 
26207 pFile->inNormalWrite = 0;
26208 #endif
26209
26210 /* downgrading to a shared lock on NFS involves clearing the write lock
26211 ** before establishing the readlock - to avoid a race condition we downgrade
@@ -26354,13 +26303,10 @@
26303 pInode->nShared--;
26304 if( pInode->nShared==0 ){
26305 lock.l_type = F_UNLCK;
26306 lock.l_whence = SEEK_SET;
26307 lock.l_start = lock.l_len = 0L;
 
 
 
26308 if( unixFileLock(pFile, &lock)==0 ){
26309 pInode->eFileLock = NO_LOCK;
26310 }else{
26311 rc = SQLITE_IOERR_UNLOCK;
26312 pFile->lastErrno = errno;
@@ -29191,10 +29137,13 @@
29137 assert( zFilename==0 || zFilename[0]=='/'
29138 || pVfs->pAppData==(void*)&autolockIoFinder );
29139 #else
29140 assert( zFilename==0 || zFilename[0]=='/' );
29141 #endif
29142
29143 /* No locking occurs in temporary files */
29144 assert( zFilename!=0 || noLock );
29145
29146 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
29147 pNew->h = h;
29148 pNew->zPath = zFilename;
29149 if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
@@ -29293,10 +29242,11 @@
29242 /* Dotfile locking uses the file path so it needs to be included in
29243 ** the dotlockLockingContext
29244 */
29245 char *zLockFile;
29246 int nFilename;
29247 assert( zFilename!=0 );
29248 nFilename = (int)strlen(zFilename) + 6;
29249 zLockFile = (char *)sqlite3_malloc(nFilename);
29250 if( zLockFile==0 ){
29251 rc = SQLITE_NOMEM;
29252 }else{
@@ -30072,14 +30022,16 @@
30022 ** the current time and date as a Julian Day number times 86_400_000. In
30023 ** other words, write into *piNow the number of milliseconds since the Julian
30024 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
30025 ** proleptic Gregorian calendar.
30026 **
30027 ** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
30028 ** cannot be found.
30029 */
30030 static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow){
30031 static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000;
30032 int rc = SQLITE_OK;
30033 #if defined(NO_GETTOD)
30034 time_t t;
30035 time(&t);
30036 *piNow = ((sqlite3_int64)t)*1000 + unixEpoch;
30037 #elif OS_VXWORKS
@@ -30086,34 +30038,38 @@
30038 struct timespec sNow;
30039 clock_gettime(CLOCK_REALTIME, &sNow);
30040 *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_nsec/1000000;
30041 #else
30042 struct timeval sNow;
30043 if( gettimeofday(&sNow, 0)==0 ){
30044 *piNow = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000;
30045 }else{
30046 rc = SQLITE_ERROR;
30047 }
30048 #endif
30049
30050 #ifdef SQLITE_TEST
30051 if( sqlite3_current_time ){
30052 *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
30053 }
30054 #endif
30055 UNUSED_PARAMETER(NotUsed);
30056 return rc;
30057 }
30058
30059 /*
30060 ** Find the current time (in Universal Coordinated Time). Write the
30061 ** current time and date as a Julian Day number into *prNow and
30062 ** return 0. Return 1 if the time and date cannot be found.
30063 */
30064 static int unixCurrentTime(sqlite3_vfs *NotUsed, double *prNow){
30065 sqlite3_int64 i = 0;
30066 int rc;
30067 UNUSED_PARAMETER(NotUsed);
30068 rc = unixCurrentTimeInt64(0, &i);
30069 *prNow = i/86400000.0;
30070 return rc;
30071 }
30072
30073 /*
30074 ** We added the xGetLastError() method with the intention of providing
30075 ** better low-level error messages when operating-system problems come up
@@ -34612,11 +34568,11 @@
34568 }
34569 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
34570 UNUSED_PARAMETER(pVfs);
34571 getLastErrorMsg(nBuf, zBufOut);
34572 }
34573 static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
34574 UNUSED_PARAMETER(pVfs);
34575 #if SQLITE_OS_WINCE
34576 /* The GetProcAddressA() routine is only available on wince. */
34577 return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol);
34578 #else
@@ -34623,11 +34579,11 @@
34579 /* All other windows platforms expect GetProcAddress() to take
34580 ** an Ansi string regardless of the _UNICODE setting */
34581 return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol);
34582 #endif
34583 }
34584 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
34585 UNUSED_PARAMETER(pVfs);
34586 FreeLibrary((HANDLE)pHandle);
34587 }
34588 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
34589 #define winDlOpen 0
@@ -34697,11 +34653,12 @@
34653 ** the current time and date as a Julian Day number times 86_400_000. In
34654 ** other words, write into *piNow the number of milliseconds since the Julian
34655 ** epoch of noon in Greenwich on November 24, 4714 B.C according to the
34656 ** proleptic Gregorian calendar.
34657 **
34658 ** On success, return SQLITE_OK. Return SQLITE_ERROR if the time and date
34659 ** cannot be found.
34660 */
34661 static int winCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *piNow){
34662 /* FILETIME structure is a 64-bit value representing the number of
34663 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5).
34664 */
@@ -34717,11 +34674,11 @@
34674 #if SQLITE_OS_WINCE
34675 SYSTEMTIME time;
34676 GetSystemTime(&time);
34677 /* if SystemTimeToFileTime() fails, it returns zero. */
34678 if (!SystemTimeToFileTime(&time,&ft)){
34679 return SQLITE_ERROR;
34680 }
34681 #else
34682 GetSystemTimeAsFileTime( &ft );
34683 #endif
34684
@@ -34733,19 +34690,19 @@
34690 if( sqlite3_current_time ){
34691 *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
34692 }
34693 #endif
34694 UNUSED_PARAMETER(pVfs);
34695 return SQLITE_OK;
34696 }
34697
34698 /*
34699 ** Find the current time (in Universal Coordinated Time). Write the
34700 ** current time and date as a Julian Day number into *prNow and
34701 ** return 0. Return 1 if the time and date cannot be found.
34702 */
34703 static int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
34704 int rc;
34705 sqlite3_int64 i;
34706 rc = winCurrentTimeInt64(pVfs, &i);
34707 if( !rc ){
34708 *prNow = i/86400000.0;
@@ -40068,11 +40025,10 @@
40025 needPagerReset = 0;
40026 }
40027 rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
40028 if( rc!=SQLITE_OK ){
40029 if( rc==SQLITE_DONE ){
 
40030 pPager->journalOff = szJ;
40031 break;
40032 }else if( rc==SQLITE_IOERR_SHORT_READ ){
40033 /* If the journal has been truncated, simply stop reading and
40034 ** processing the journal. This might happen if the journal was
@@ -40330,10 +40286,11 @@
40286 #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
40287 PgHdr *p; /* For looping over pages */
40288 #endif
40289
40290 assert( pPager->pWal );
40291 assert( pList );
40292 #ifdef SQLITE_DEBUG
40293 /* Verify that the page list is in accending order */
40294 for(p=pList; p && p->pDirty; p=p->pDirty){
40295 assert( p->pgno < p->pDirty->pgno );
40296 }
@@ -46566,11 +46523,11 @@
46523 */
46524 if( iRead ){
46525 int sz;
46526 i64 iOffset;
46527 sz = pWal->hdr.szPage;
46528 sz = (sz&0xfe00) + ((sz&0x0001)<<16);
46529 testcase( sz<=32768 );
46530 testcase( sz>=65536 );
46531 iOffset = walFrameOffset(iRead, sz) + WAL_FRAME_HDRSIZE;
46532 *pInWal = 1;
46533 /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL */
@@ -49879,21 +49836,23 @@
49836 */
49837 if( isMemdb==0 && isTempDb==0 ){
49838 if( vfsFlags & SQLITE_OPEN_SHAREDCACHE ){
49839 int nFullPathname = pVfs->mxPathname+1;
49840 char *zFullPathname = sqlite3Malloc(nFullPathname);
49841 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
49842 p->sharable = 1;
49843 if( !zFullPathname ){
49844 sqlite3_free(p);
49845 return SQLITE_NOMEM;
49846 }
49847 sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
49848 #if SQLITE_THREADSAFE
49849 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
49850 sqlite3_mutex_enter(mutexOpen);
49851 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
49852 sqlite3_mutex_enter(mutexShared);
49853 #endif
49854 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
49855 assert( pBt->nRef>0 );
49856 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager))
49857 && sqlite3PagerVfs(pBt->pPager)==pVfs ){
49858 int iDb;
@@ -49995,13 +49954,13 @@
49954
49955 #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
49956 /* Add the new BtShared object to the linked list sharable BtShareds.
49957 */
49958 if( p->sharable ){
49959 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
49960 pBt->nRef = 1;
49961 MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);)
49962 if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
49963 pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
49964 if( pBt->mutex==0 ){
49965 rc = SQLITE_NOMEM;
49966 db->mallocFailed = 0;
@@ -50079,16 +50038,16 @@
50038 ** true if the BtShared.nRef counter reaches zero and return
50039 ** false if it is still positive.
50040 */
50041 static int removeFromSharingList(BtShared *pBt){
50042 #ifndef SQLITE_OMIT_SHARED_CACHE
50043 MUTEX_LOGIC( sqlite3_mutex *pMaster; )
50044 BtShared *pList;
50045 int removed = 0;
50046
50047 assert( sqlite3_mutex_notheld(pBt->mutex) );
50048 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
50049 sqlite3_mutex_enter(pMaster);
50050 pBt->nRef--;
50051 if( pBt->nRef<=0 ){
50052 if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
50053 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
@@ -52698,11 +52657,10 @@
52657 }
52658 }
52659 if( c==0 ){
52660 if( pPage->intKey && !pPage->leaf ){
52661 lwr = idx;
 
52662 break;
52663 }else{
52664 *pRes = 0;
52665 rc = SQLITE_OK;
52666 goto moveto_finish;
@@ -52716,11 +52674,11 @@
52674 if( lwr>upr ){
52675 break;
52676 }
52677 pCur->aiIdx[pCur->iPage] = (u16)(idx = (lwr+upr)/2);
52678 }
52679 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
52680 assert( pPage->isInit );
52681 if( pPage->leaf ){
52682 chldPg = 0;
52683 }else if( lwr>=pPage->nCell ){
52684 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
@@ -52981,10 +52939,12 @@
52939 }
52940 if( rc ){
52941 pTrunk = 0;
52942 goto end_allocate_page;
52943 }
52944 assert( pTrunk!=0 );
52945 assert( pTrunk->aData!=0 );
52946
52947 k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
52948 if( k==0 && !searchList ){
52949 /* The trunk has no leaves and the list is not being searched.
52950 ** So extract the trunk page itself and use it as the newly
@@ -54108,17 +54068,19 @@
54068 ** This is safe because dropping a cell only overwrites the first
54069 ** four bytes of it, and this function does not need the first
54070 ** four bytes of the divider cell. So the pointer is safe to use
54071 ** later on.
54072 **
54073 ** But not if we are in secure-delete mode. In secure-delete mode,
54074 ** the dropCell() routine will overwrite the entire cell with zeroes.
54075 ** In this case, temporarily copy the cell into the aOvflSpace[]
54076 ** buffer. It will be copied out again as soon as the aSpace[] buffer
54077 ** is allocated. */
54078 if( pBt->secureDelete ){
54079 int iOff;
54080
54081 iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
54082 if( (iOff+szNew[i])>(int)pBt->usableSize ){
54083 rc = SQLITE_CORRUPT_BKPT;
54084 memset(apOld, 0, (i+1)*sizeof(MemPage*));
54085 goto balance_cleanup;
54086 }else{
@@ -54534,10 +54496,11 @@
54496 int isDivider = 0;
54497 while( i==iNextOld ){
54498 /* Cell i is the cell immediately following the last cell on old
54499 ** sibling page j. If the siblings are not leaf pages of an
54500 ** intkey b-tree, then cell i was a divider cell. */
54501 assert( j+1 < ArraySize(apCopy) );
54502 pOld = apCopy[++j];
54503 iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
54504 if( pOld->nOverflow ){
54505 nOverflow = pOld->nOverflow;
54506 iOverflow = i + !leafData + pOld->aOvfl[0].idx;
@@ -56876,18 +56839,18 @@
56839 /*
56840 ** Release all resources associated with an sqlite3_backup* handle.
56841 */
56842 SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p){
56843 sqlite3_backup **pp; /* Ptr to head of pagers backup list */
56844 MUTEX_LOGIC( sqlite3_mutex *mutex; ) /* Mutex to protect source database */
56845 int rc; /* Value to return */
56846
56847 /* Enter the mutexes */
56848 if( p==0 ) return SQLITE_OK;
56849 sqlite3_mutex_enter(p->pSrcDb->mutex);
56850 sqlite3BtreeEnter(p->pSrc);
56851 MUTEX_LOGIC( mutex = p->pSrcDb->mutex; )
56852 if( p->pDestDb ){
56853 sqlite3_mutex_enter(p->pDestDb->mutex);
56854 }
56855
56856 /* Detach this backup from the source pager. */
@@ -58983,34 +58946,33 @@
58946 ** Change the comment on the the most recently coded instruction. Or
58947 ** insert a No-op and add the comment to that new instruction. This
58948 ** makes the code easier to read during debugging. None of this happens
58949 ** in a production build.
58950 */
58951 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
 
 
58952 assert( p->nOp>0 || p->aOp==0 );
58953 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed );
58954 if( p->nOp ){
58955 assert( p->aOp );
58956 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
58957 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
58958 }
58959 }
58960 SQLITE_PRIVATE void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
58961 va_list ap;
58962 if( p ){
58963 va_start(ap, zFormat);
58964 vdbeVComment(p, zFormat, ap);
 
58965 va_end(ap);
58966 }
58967 }
58968 SQLITE_PRIVATE void sqlite3VdbeNoopComment(Vdbe *p, const char *zFormat, ...){
58969 va_list ap;
58970 if( p ){
58971 sqlite3VdbeAddOp0(p, OP_Noop);
 
 
 
 
58972 va_start(ap, zFormat);
58973 vdbeVComment(p, zFormat, ap);
 
58974 va_end(ap);
58975 }
58976 }
58977 #endif /* NDEBUG */
58978
@@ -61266,11 +61228,11 @@
61228 ** than 2GiB are support - anything large must be database corruption.
61229 ** Any corruption is detected in sqlite3BtreeParseCellPtr(), though, so
61230 ** this code can safely assume that nCellKey is 32-bits
61231 */
61232 assert( sqlite3BtreeCursorIsValid(pCur) );
61233 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
61234 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
61235 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
61236
61237 /* Read in the complete content of the index entry */
61238 memset(&m, 0, sizeof(m));
@@ -61341,11 +61303,11 @@
61303 int rc;
61304 BtCursor *pCur = pC->pCursor;
61305 Mem m;
61306
61307 assert( sqlite3BtreeCursorIsValid(pCur) );
61308 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
61309 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
61310 /* nCellKey will always be between 0 and 0xffffffff because of the say
61311 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
61312 if( nCellKey<=0 || nCellKey>0x7fffffff ){
61313 *res = 0;
@@ -65617,20 +65579,20 @@
65579 }else if( u.am.pC->cacheStatus==p->cacheCtr ){
65580 u.am.payloadSize = u.am.pC->payloadSize;
65581 u.am.zRec = (char*)u.am.pC->aRow;
65582 }else if( u.am.pC->isIndex ){
65583 assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) );
65584 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.am.pCrsr, &u.am.payloadSize64);
65585 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
65586 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
65587 ** payload size, so it is impossible for u.am.payloadSize64 to be
65588 ** larger than 32 bits. */
65589 assert( (u.am.payloadSize64 & SQLITE_MAX_U32)==(u64)u.am.payloadSize64 );
65590 u.am.payloadSize = (u32)u.am.payloadSize64;
65591 }else{
65592 assert( sqlite3BtreeCursorIsValid(u.am.pCrsr) );
65593 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.am.pCrsr, &u.am.payloadSize);
65594 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
65595 }
65596 }else if( ALWAYS(u.am.pC->pseudoTableReg>0) ){
65597 u.am.pReg = &aMem[u.am.pC->pseudoTableReg];
65598 assert( u.am.pReg->flags & MEM_Blob );
@@ -67678,18 +67640,18 @@
67640 rc = sqlite3VdbeCursorMoveto(u.bk.pC);
67641 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
67642
67643 if( u.bk.pC->isIndex ){
67644 assert( !u.bk.pC->isTable );
67645 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bk.pCrsr, &u.bk.n64);
67646 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
67647 if( u.bk.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67648 goto too_big;
67649 }
67650 u.bk.n = (u32)u.bk.n64;
67651 }else{
67652 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bk.pCrsr, &u.bk.n);
67653 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
67654 if( u.bk.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
67655 goto too_big;
67656 }
67657 }
@@ -73322,11 +73284,12 @@
73284 pNew->flags |= EP_IntValue;
73285 pNew->u.iValue = iValue;
73286 }else{
73287 int c;
73288 pNew->u.zToken = (char*)&pNew[1];
73289 assert( pToken->z!=0 || pToken->n==0 );
73290 if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
73291 pNew->u.zToken[pToken->n] = 0;
73292 if( dequote && nExtra>=3
73293 && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
73294 sqlite3Dequote(pNew->u.zToken);
73295 if( c=='"' ) pNew->flags |= EP_DblQuoted;
@@ -74361,15 +74324,23 @@
74324 ** ephemeral table.
74325 */
74326 p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
74327 if( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
74328 sqlite3 *db = pParse->db; /* Database connection */
 
 
74329 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
74330 Table *pTab; /* Table <table>. */
74331 Expr *pExpr; /* Expression <column> */
74332 int iCol; /* Index of column <column> */
74333 int iDb; /* Database idx for pTab */
74334
74335 assert( p ); /* Because of isCandidateForInOpt(p) */
74336 assert( p->pEList!=0 ); /* Because of isCandidateForInOpt(p) */
74337 assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
74338 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
74339 pTab = p->pSrc->a[0].pTab;
74340 pExpr = p->pEList->a[0].pExpr;
74341 iCol = pExpr->iColumn;
74342
74343 /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
74344 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
74345 sqlite3CodeVerifySchema(pParse, iDb);
74346 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
@@ -76372,11 +76343,11 @@
76343 if( !ExprHasProperty(pB, EP_IntValue) || pA->u.iValue!=pB->u.iValue ){
76344 return 2;
76345 }
76346 }else if( pA->op!=TK_COLUMN && pA->u.zToken ){
76347 if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
76348 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
76349 return 2;
76350 }
76351 }
76352 if( (pA->flags & EP_ExpCollate)!=(pB->flags & EP_ExpCollate) ) return 1;
76353 if( (pA->flags & EP_ExpCollate)!=0 && pA->pColl!=pB->pColl ) return 2;
@@ -81778,17 +81749,19 @@
81749 */
81750 static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
81751 Table *pTab = pIndex->pTable; /* The table that is indexed */
81752 int iTab = pParse->nTab++; /* Btree cursor used for pTab */
81753 int iIdx = pParse->nTab++; /* Btree cursor used for pIndex */
81754 int iSorter; /* Cursor opened by OpenSorter (if in use) */
81755 int addr1; /* Address of top of loop */
81756 int addr2; /* Address to jump to for next iteration */
81757 int tnum; /* Root page of index */
81758 Vdbe *v; /* Generate code into this virtual machine */
81759 KeyInfo *pKey; /* KeyInfo for index */
81760 #ifdef SQLITE_OMIT_MERGE_SORT
81761 int regIdxKey; /* Registers containing the index key */
81762 #endif
81763 int regRecord; /* Register holding assemblied index record */
81764 sqlite3 *db = pParse->db; /* The database connection */
81765 int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);
81766
81767 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -81818,21 +81791,22 @@
81791
81792 #ifndef SQLITE_OMIT_MERGE_SORT
81793 /* Open the sorter cursor if we are to use one. */
81794 iSorter = pParse->nTab++;
81795 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)pKey, P4_KEYINFO);
81796 #else
81797 iSorter = iTab;
81798 #endif
81799
81800 /* Open the table. Loop through all rows of the table, inserting index
81801 ** records into the sorter. */
81802 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
81803 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
 
81804 regRecord = sqlite3GetTempReg(pParse);
 
81805
81806 #ifndef SQLITE_OMIT_MERGE_SORT
81807 sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
81808 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
81809 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
81810 sqlite3VdbeJumpHere(v, addr1);
81811 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
81812 if( pIndex->onError!=OE_None ){
@@ -81848,10 +81822,12 @@
81822 }
81823 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
81824 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
81825 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
81826 #else
81827 regIdxKey = sqlite3GenerateIndexKey(pParse, pIndex, iTab, regRecord, 1);
81828 addr2 = addr1 + 1;
81829 if( pIndex->onError!=OE_None ){
81830 const int regRowid = regIdxKey + pIndex->nColumn;
81831 const int j2 = sqlite3VdbeCurrentAddr(v) + 2;
81832 void * const pRegKey = SQLITE_INT_TO_PTR(regIdxKey);
81833
@@ -81945,10 +81921,11 @@
81921 ** before looking up the table.
81922 */
81923 assert( pName1 && pName2 );
81924 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
81925 if( iDb<0 ) goto exit_create_index;
81926 assert( pName && pName->z );
81927
81928 #ifndef SQLITE_OMIT_TEMPDB
81929 /* If the index name was unqualified, check if the the table
81930 ** is a temp table. If so, set the database to 1. Do not do this
81931 ** if initialising a database schema.
@@ -81972,10 +81949,11 @@
81949 pTblName->a[0].zDatabase);
81950 if( !pTab || db->mallocFailed ) goto exit_create_index;
81951 assert( db->aDb[iDb].pSchema==pTab->pSchema );
81952 }else{
81953 assert( pName==0 );
81954 assert( pStart==0 );
81955 pTab = pParse->pNewTable;
81956 if( !pTab ) goto exit_create_index;
81957 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
81958 }
81959 pDb = &db->aDb[iDb];
@@ -82014,10 +81992,11 @@
81992 ** own name.
81993 */
81994 if( pName ){
81995 zName = sqlite3NameFromToken(db, pName);
81996 if( zName==0 ) goto exit_create_index;
81997 assert( pName->z!=0 );
81998 if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
81999 goto exit_create_index;
82000 }
82001 if( !db->init.busy ){
82002 if( sqlite3FindTable(db, zName, 0)!=0 ){
@@ -82869,17 +82848,14 @@
82848
82849 /*
82850 ** Commit a transaction
82851 */
82852 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse *pParse){
 
82853 Vdbe *v;
82854
82855 assert( pParse!=0 );
82856 assert( pParse->db!=0 );
 
 
82857 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "COMMIT", 0, 0) ){
82858 return;
82859 }
82860 v = sqlite3GetVdbe(pParse);
82861 if( v ){
@@ -82889,17 +82865,14 @@
82865
82866 /*
82867 ** Rollback a transaction
82868 */
82869 SQLITE_PRIVATE void sqlite3RollbackTransaction(Parse *pParse){
 
82870 Vdbe *v;
82871
82872 assert( pParse!=0 );
82873 assert( pParse->db!=0 );
 
 
82874 if( sqlite3AuthCheck(pParse, SQLITE_TRANSACTION, "ROLLBACK", 0, 0) ){
82875 return;
82876 }
82877 v = sqlite3GetVdbe(pParse);
82878 if( v ){
@@ -84701,20 +84674,19 @@
84674 /* Verify that the call to _bytes() does not invalidate the _text() pointer */
84675 assert( z2==(char*)sqlite3_value_text(argv[0]) );
84676 if( z2 ){
84677 z1 = contextMalloc(context, ((i64)n)+1);
84678 if( z1 ){
84679 for(i=0; i<n; i++){
84680 z1[i] = (char)sqlite3Toupper(z2[i]);
 
84681 }
84682 sqlite3_result_text(context, z1, n, sqlite3_free);
84683 }
84684 }
84685 }
84686 static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
84687 char *z1;
84688 const char *z2;
84689 int i, n;
84690 UNUSED_PARAMETER(argc);
84691 z2 = (char*)sqlite3_value_text(argv[0]);
84692 n = sqlite3_value_bytes(argv[0]);
@@ -84721,15 +84693,14 @@
84693 /* Verify that the call to _bytes() does not invalidate the _text() pointer */
84694 assert( z2==(char*)sqlite3_value_text(argv[0]) );
84695 if( z2 ){
84696 z1 = contextMalloc(context, ((i64)n)+1);
84697 if( z1 ){
84698 for(i=0; i<n; i++){
84699 z1[i] = sqlite3Tolower(z2[i]);
 
84700 }
84701 sqlite3_result_text(context, z1, n, sqlite3_free);
84702 }
84703 }
84704 }
84705
84706
@@ -87102,10 +87073,11 @@
87073 sqlite3SelectDelete(db, pSelect);
87074 if( db->mallocFailed==1 ){
87075 fkTriggerDelete(db, pTrigger);
87076 return 0;
87077 }
87078 assert( pStep!=0 );
87079
87080 switch( action ){
87081 case OE_Restrict:
87082 pStep->op = TK_SELECT;
87083 break;
@@ -90025,11 +89997,11 @@
89997 sqlite3_vfs *pVfs = db->pVfs;
89998 void *handle;
89999 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
90000 char *zErrmsg = 0;
90001 void **aHandle;
90002 int nMsg = 300 + sqlite3Strlen30(zFile);
90003
90004 if( pzErrMsg ) *pzErrMsg = 0;
90005
90006 /* Ticket #1863. To avoid a creating security problems for older
90007 ** applications that relink against newer versions of SQLite, the
@@ -90062,10 +90034,11 @@
90034 }
90035 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
90036 sqlite3OsDlSym(pVfs, handle, zProc);
90037 if( xInit==0 ){
90038 if( pzErrMsg ){
90039 nMsg += sqlite3Strlen30(zProc);
90040 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
90041 if( zErrmsg ){
90042 sqlite3_snprintf(nMsg, zErrmsg,
90043 "no entry point [%s] in shared library [%s]", zProc,zFile);
90044 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
@@ -90747,11 +90720,11 @@
90720 ){
90721 int iReg;
90722 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
90723 sqlite3CodeVerifySchema(pParse, iDb);
90724 iReg = ++pParse->nMem;
90725 if( sqlite3Tolower(zLeft[0])=='p' ){
90726 sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
90727 }else{
90728 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, sqlite3Atoi(zRight));
90729 }
90730 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
@@ -91360,11 +91333,11 @@
91333 { OP_IfNeg, 1, 0, 0}, /* 1 */
91334 { OP_String8, 0, 3, 0}, /* 2 */
91335 { OP_ResultRow, 3, 1, 0},
91336 };
91337
91338 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
91339
91340 /* Initialize the VDBE program */
91341 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
91342 pParse->nMem = 6;
91343 sqlite3VdbeSetNumCols(v, 1);
@@ -93942,11 +93915,14 @@
93915 /* If the column contains an "AS <name>" phrase, use <name> as the name */
93916 zName = sqlite3DbStrDup(db, zName);
93917 }else{
93918 Expr *pColExpr = p; /* The expression that is the result column name */
93919 Table *pTab; /* Table associated with this expression */
93920 while( pColExpr->op==TK_DOT ){
93921 pColExpr = pColExpr->pRight;
93922 assert( pColExpr!=0 );
93923 }
93924 if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
93925 /* For columns use the column name name */
93926 int iCol = pColExpr->iColumn;
93927 pTab = pColExpr->pTab;
93928 if( iCol<0 ) iCol = pTab->iPKey;
@@ -98940,10 +98916,11 @@
98916 break;
98917 }
98918 }
98919 }
98920 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
98921 assert( aRegIdx );
98922 if( openAll || aRegIdx[i]>0 ){
98923 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
98924 sqlite3VdbeAddOp4(v, OP_OpenWrite, iCur+i+1, pIdx->tnum, iDb,
98925 (char*)pKey, P4_KEYINFO_HANDOFF);
98926 assert( pParse->nTab>iCur+i+1 );
@@ -99113,10 +99090,11 @@
99090 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
99091 sqlite3VdbeJumpHere(v, addr);
99092
99093 /* Close all tables */
99094 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
99095 assert( aRegIdx );
99096 if( openAll || aRegIdx[i]>0 ){
99097 sqlite3VdbeAddOp2(v, OP_Close, iCur+i+1, 0);
99098 }
99099 }
99100 sqlite3VdbeAddOp2(v, OP_Close, iCur, 0);
@@ -103144,11 +103122,10 @@
103122 assert( roundUp==0 || roundUp==1 );
103123 assert( pIdx->nSample>0 );
103124 if( pVal==0 ) return SQLITE_ERROR;
103125 n = pIdx->aiRowEst[0];
103126 aSample = pIdx->aSample;
 
103127 eType = sqlite3_value_type(pVal);
103128
103129 if( eType==SQLITE_INTEGER ){
103130 v = sqlite3_value_int64(pVal);
103131 r = (i64)v;
@@ -105564,11 +105541,12 @@
105541 assert( bestJ>=0 );
105542 assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) );
105543 WHERETRACE(("*** Optimizer selects table %d for loop %d"
105544 " with cost=%g and nRow=%g\n",
105545 bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.plan.nRow));
105546 /* The ALWAYS() that follows was added to hush up clang scan-build */
105547 if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 && ALWAYS(ppOrderBy) ){
105548 *ppOrderBy = 0;
105549 }
105550 if( (bestPlan.plan.wsFlags & WHERE_DISTINCT)!=0 ){
105551 assert( pWInfo->eDistinct==0 );
105552 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
@@ -109180,11 +109158,13 @@
109158 sqlite3ParserTOKENTYPE yyminor /* The value for the token */
109159 sqlite3ParserARG_PDECL /* Optional %extra_argument parameter */
109160 ){
109161 YYMINORTYPE yyminorunion;
109162 int yyact; /* The parser action. */
109163 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
109164 int yyendofinput; /* True if we are at the end of input */
109165 #endif
109166 #ifdef YYERRORSYMBOL
109167 int yyerrorhit = 0; /* True if yymajor has invoked an error */
109168 #endif
109169 yyParser *yypParser; /* The parser */
109170
@@ -109203,11 +109183,13 @@
109183 yypParser->yyerrcnt = -1;
109184 yypParser->yystack[0].stateno = 0;
109185 yypParser->yystack[0].major = 0;
109186 }
109187 yyminorunion.yy0 = yyminor;
109188 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
109189 yyendofinput = (yymajor==0);
109190 #endif
109191 sqlite3ParserARG_STORE;
109192
109193 #ifndef NDEBUG
109194 if( yyTraceFILE ){
109195 fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
@@ -109215,11 +109197,10 @@
109197 #endif
109198
109199 do{
109200 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
109201 if( yyact<YYNSTATE ){
 
109202 yy_shift(yypParser,yyact,yymajor,&yyminorunion);
109203 yypParser->yyerrcnt--;
109204 yymajor = YYNOCODE;
109205 }else if( yyact < YYNSTATE + YYNRULE ){
109206 yy_reduce(yypParser,yyact-YYNSTATE);
@@ -110607,11 +110588,11 @@
110588 **
110589 ** * Recursive calls to this routine from thread X return immediately
110590 ** without blocking.
110591 */
110592 SQLITE_API int sqlite3_initialize(void){
110593 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
110594 int rc; /* Result code */
110595
110596 #ifdef SQLITE_OMIT_WSD
110597 rc = sqlite3_wsd_init(4096, 24);
110598 if( rc!=SQLITE_OK ){
@@ -110641,11 +110622,11 @@
110622 ** This operation is protected by the STATIC_MASTER mutex. Note that
110623 ** MutexAlloc() is called for a static mutex prior to initializing the
110624 ** malloc subsystem - this implies that the allocation of a static
110625 ** mutex must not require support from the malloc subsystem.
110626 */
110627 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
110628 sqlite3_mutex_enter(pMaster);
110629 sqlite3GlobalConfig.isMutexInit = 1;
110630 if( !sqlite3GlobalConfig.isMallocInit ){
110631 rc = sqlite3MallocInit();
110632 }
@@ -111715,17 +111696,17 @@
111696 sqlite3 *db,
111697 const char *zName,
111698 int nArg
111699 ){
111700 int nName = sqlite3Strlen30(zName);
111701 int rc = SQLITE_OK;
111702 sqlite3_mutex_enter(db->mutex);
111703 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
111704 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
111705 0, sqlite3InvalidFunction, 0, 0, 0);
111706 }
111707 rc = sqlite3ApiExit(db, rc);
111708 sqlite3_mutex_leave(db->mutex);
111709 return rc;
111710 }
111711
111712 #ifndef SQLITE_OMIT_TRACE
@@ -112783,10 +112764,11 @@
112764 if( db ){
112765 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
112766 sqlite3_mutex_leave(db->mutex);
112767 }
112768 rc = sqlite3_errcode(db);
112769 assert( db!=0 || rc==SQLITE_NOMEM );
112770 if( rc==SQLITE_NOMEM ){
112771 sqlite3_close(db);
112772 db = 0;
112773 }else if( rc!=SQLITE_OK ){
112774 db->magic = SQLITE_MAGIC_SICK;
@@ -114511,10 +114493,17 @@
114493 #else
114494 # define TESTONLY(X)
114495 #endif
114496
114497 #endif /* SQLITE_AMALGAMATION */
114498
114499 #ifdef SQLITE_DEBUG
114500 SQLITE_PRIVATE int sqlite3Fts3Corrupt(void);
114501 # define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt()
114502 #else
114503 # define FTS_CORRUPT_VTAB SQLITE_CORRUPT_VTAB
114504 #endif
114505
114506 typedef struct Fts3Table Fts3Table;
114507 typedef struct Fts3Cursor Fts3Cursor;
114508 typedef struct Fts3Expr Fts3Expr;
114509 typedef struct Fts3Phrase Fts3Phrase;
@@ -115012,11 +115001,11 @@
115001 char **pp,
115002 char *pStart,
115003 sqlite3_int64 *pVal
115004 ){
115005 sqlite3_int64 iVal;
115006 char *p;
115007
115008 /* Pointer p now points at the first byte past the varint we are
115009 ** interested in. So, unless the doclist is corrupt, the 0x80 bit is
115010 ** clear on character p[-1]. */
115011 for(p = (*pp)-2; p>=pStart && *p&0x80; p--);
@@ -115413,11 +115402,11 @@
115402 ** the output value undefined. Otherwise SQLITE_OK is returned.
115403 **
115404 ** This function is used when parsing the "prefix=" FTS4 parameter.
115405 */
115406 static int fts3GobbleInt(const char **pp, int *pnOut){
115407 const char *p; /* Iterator pointer */
115408 int nInt = 0; /* Output value */
115409
115410 for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
115411 nInt = nInt * 10 + (p[0] - '0');
115412 }
@@ -115912,11 +115901,11 @@
115901 if( rc==SQLITE_OK ){
115902 /* If no row was found and no error has occured, then the %_content
115903 ** table is missing a row that is present in the full-text index.
115904 ** The data structures are corrupt.
115905 */
115906 rc = FTS_CORRUPT_VTAB;
115907 }
115908 pCsr->isEof = 1;
115909 if( pContext ){
115910 sqlite3_result_error_code(pContext, rc);
115911 }
@@ -115972,11 +115961,11 @@
115961 ** nNode bytes of content (see sqlite3Fts3ReadBlock() for details).
115962 */
115963 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
115964 zCsr += sqlite3Fts3GetVarint(zCsr, &iChild);
115965 if( zCsr>zEnd ){
115966 return FTS_CORRUPT_VTAB;
115967 }
115968
115969 while( zCsr<zEnd && (piFirst || piLast) ){
115970 int cmp; /* memcmp() result */
115971 int nSuffix; /* Size of term suffix */
@@ -115990,11 +115979,11 @@
115979 }
115980 isFirstTerm = 0;
115981 zCsr += sqlite3Fts3GetVarint32(zCsr, &nSuffix);
115982
115983 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
115984 rc = FTS_CORRUPT_VTAB;
115985 goto finish_scan;
115986 }
115987 if( nPrefix+nSuffix>nAlloc ){
115988 char *zNew;
115989 nAlloc = (nPrefix+nSuffix) * 2;
@@ -116003,10 +115992,11 @@
115992 rc = SQLITE_NOMEM;
115993 goto finish_scan;
115994 }
115995 zBuffer = zNew;
115996 }
115997 assert( zBuffer );
115998 memcpy(&zBuffer[nPrefix], zCsr, nSuffix);
115999 nBuffer = nPrefix + nSuffix;
116000 zCsr += nSuffix;
116001
116002 /* Compare the term we are searching for with the term just loaded from
@@ -117439,11 +117429,11 @@
117429 ** moves *ppPoslist so that it instead points to the first byte of the
117430 ** same position list.
117431 */
117432 static void fts3ReversePoslist(char *pStart, char **ppPoslist){
117433 char *p = &(*ppPoslist)[-2];
117434 char c = 0;
117435
117436 while( p>pStart && (c=*p--)==0 );
117437 while( p>pStart && (*p & 0x80) | c ){
117438 c = *p--;
117439 }
@@ -118433,11 +118423,11 @@
118423 while( a<pEnd ){
118424 a += sqlite3Fts3GetVarint(a, &nByte);
118425 }
118426 if( nDoc==0 || nByte==0 ){
118427 sqlite3_reset(pStmt);
118428 return FTS_CORRUPT_VTAB;
118429 }
118430
118431 pCsr->nDoc = nDoc;
118432 pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
118433 assert( pCsr->nRowAvg>0 );
@@ -118909,12 +118899,15 @@
118899 }
118900
118901 aPoslist = pExpr->pRight->pPhrase->doclist.pList;
118902 nToken = pExpr->pRight->pPhrase->nToken;
118903 for(p=pExpr->pLeft; p && res; p=p->pLeft){
118904 int nNear;
118905 Fts3Phrase *pPhrase;
118906 assert( p->pParent && p->pParent->pLeft==p );
118907 nNear = p->pParent->nNear;
118908 pPhrase = (
118909 p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
118910 );
118911 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
118912 }
118913 }
@@ -119400,10 +119393,19 @@
119393 pPhrase->aToken[i].pSegcsr = 0;
119394 }
119395 }
119396 }
119397
119398 /*
119399 ** Return SQLITE_CORRUPT_VTAB.
119400 */
119401 #ifdef SQLITE_DEBUG
119402 SQLITE_PRIVATE int sqlite3Fts3Corrupt(){
119403 return SQLITE_CORRUPT_VTAB;
119404 }
119405 #endif
119406
119407 #if !SQLITE_CORE
119408 /*
119409 ** Initialize API pointer table, if required.
119410 */
119411 SQLITE_API int sqlite3_extension_init(
@@ -120197,12 +120199,16 @@
120199 p->pPhrase = (Fts3Phrase *)&p[1];
120200 p->pPhrase->iColumn = pParse->iDefaultCol;
120201 p->pPhrase->nToken = nToken;
120202
120203 zBuf = (char *)&p->pPhrase->aToken[nToken];
120204 if( zTemp ){
120205 memcpy(zBuf, zTemp, nTemp);
120206 sqlite3_free(zTemp);
120207 }else{
120208 assert( nTemp==0 );
120209 }
120210
120211 for(jj=0; jj<p->pPhrase->nToken; jj++){
120212 p->pPhrase->aToken[jj].z = zBuf;
120213 zBuf += p->pPhrase->aToken[jj].n;
120214 }
@@ -122957,11 +122963,11 @@
122963 sqlite3_bind_int64(pStmt, 1, iDocid);
122964 }
122965 rc = sqlite3_step(pStmt);
122966 if( rc!=SQLITE_ROW || sqlite3_column_type(pStmt, 0)!=SQLITE_BLOB ){
122967 rc = sqlite3_reset(pStmt);
122968 if( rc==SQLITE_OK ) rc = FTS_CORRUPT_VTAB;
122969 pStmt = 0;
122970 }else{
122971 rc = SQLITE_OK;
122972 }
122973 }
@@ -123761,11 +123767,11 @@
123767 pNext += sqlite3Fts3GetVarint32(pNext, &nPrefix);
123768 pNext += sqlite3Fts3GetVarint32(pNext, &nSuffix);
123769 if( nPrefix<0 || nSuffix<=0
123770 || &pNext[nSuffix]>&pReader->aNode[pReader->nNode]
123771 ){
123772 return FTS_CORRUPT_VTAB;
123773 }
123774
123775 if( nPrefix+nSuffix>pReader->nTermAlloc ){
123776 int nNew = (nPrefix+nSuffix)*2;
123777 char *zNew = sqlite3_realloc(pReader->zTerm, nNew);
@@ -123791,11 +123797,11 @@
123797 ** of these statements is untrue, then the data structure is corrupt.
123798 */
123799 if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode]
123800 || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
123801 ){
123802 return FTS_CORRUPT_VTAB;
123803 }
123804 return SQLITE_OK;
123805 }
123806
123807 /*
@@ -125745,11 +125751,10 @@
125751 sqlite_int64 *pRowid /* OUT: The affected (or effected) rowid */
125752 ){
125753 Fts3Table *p = (Fts3Table *)pVtab;
125754 int rc = SQLITE_OK; /* Return Code */
125755 int isRemove = 0; /* True for an UPDATE or DELETE */
 
125756 u32 *aSzIns = 0; /* Sizes of inserted documents */
125757 u32 *aSzDel; /* Sizes of deleted documents */
125758 int nChng = 0; /* Net change in number of documents */
125759 int bInsertDone = 0;
125760
@@ -125828,23 +125833,23 @@
125833 /* If this is a DELETE or UPDATE operation, remove the old record. */
125834 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
125835 assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER );
125836 rc = fts3DeleteByRowid(p, apVal[0], &nChng, aSzDel);
125837 isRemove = 1;
 
125838 }
125839
125840 /* If this is an INSERT or UPDATE operation, insert the new record. */
125841 if( nArg>1 && rc==SQLITE_OK ){
125842 if( bInsertDone==0 ){
125843 rc = fts3InsertData(p, apVal, pRowid);
125844 if( rc==SQLITE_CONSTRAINT ) rc = FTS_CORRUPT_VTAB;
125845 }
125846 if( rc==SQLITE_OK && (!isRemove || *pRowid!=p->iPrevDocid ) ){
125847 rc = fts3PendingTermsDocid(p, *pRowid);
125848 }
125849 if( rc==SQLITE_OK ){
125850 assert( p->iPrevDocid==*pRowid );
125851 rc = fts3InsertTerms(p, apVal, aSzIns);
125852 }
125853 if( p->bHasDocsize ){
125854 fts3InsertDocsize(&rc, p, aSzIns);
125855 }
@@ -126734,11 +126739,11 @@
126739 pStmt = *ppStmt;
126740 assert( sqlite3_data_count(pStmt)==1 );
126741
126742 a = sqlite3_column_blob(pStmt, 0);
126743 a += sqlite3Fts3GetVarint(a, &nDoc);
126744 if( nDoc==0 ) return FTS_CORRUPT_VTAB;
126745 *pnDoc = (u32)nDoc;
126746
126747 if( paLen ) *paLen = a;
126748 return SQLITE_OK;
126749 }
@@ -127313,11 +127318,11 @@
127318 sqlite3_snprintf(sizeof(aBuffer), aBuffer,
127319 "%d %d %d %d ", iCol, pTerm-sCtx.aTerm, iStart, iEnd-iStart
127320 );
127321 rc = fts3StringAppend(&res, aBuffer, -1);
127322 }else if( rc==SQLITE_DONE ){
127323 rc = FTS_CORRUPT_VTAB;
127324 }
127325 }
127326 }
127327 if( rc==SQLITE_DONE ){
127328 rc = SQLITE_OK;
@@ -128654,11 +128659,12 @@
128659 pCsr->nConstraint = argc;
128660 if( !pCsr->aConstraint ){
128661 rc = SQLITE_NOMEM;
128662 }else{
128663 memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc);
128664 assert( (idxStr==0 && argc==0)
128665 || (idxStr && (int)strlen(idxStr)==argc*2) );
128666 for(ii=0; ii<argc; ii++){
128667 RtreeConstraint *p = &pCsr->aConstraint[ii];
128668 p->op = idxStr[ii*2];
128669 p->iCoord = idxStr[ii*2+1]-'a';
128670 if( p->op==RTREE_MATCH ){
@@ -128955,11 +128961,14 @@
128961 int iCell;
128962 sqlite3_int64 iBest = 0;
128963
128964 float fMinGrowth = 0.0;
128965 float fMinArea = 0.0;
128966 #if VARIANT_RSTARTREE_CHOOSESUBTREE
128967 float fMinOverlap = 0.0;
128968 float overlap;
128969 #endif
128970
128971 int nCell = NCELL(pNode);
128972 RtreeCell cell;
128973 RtreeNode *pChild;
128974
@@ -128987,33 +128996,34 @@
128996 */
128997 for(iCell=0; iCell<nCell; iCell++){
128998 int bBest = 0;
128999 float growth;
129000 float area;
 
129001 nodeGetCell(pRtree, pNode, iCell, &cell);
129002 growth = cellGrowth(pRtree, &cell, pCell);
129003 area = cellArea(pRtree, &cell);
129004
129005 #if VARIANT_RSTARTREE_CHOOSESUBTREE
129006 if( ii==(pRtree->iDepth-1) ){
129007 overlap = cellOverlapEnlargement(pRtree,&cell,pCell,aCell,nCell,iCell);
129008 }else{
129009 overlap = 0.0;
129010 }
129011 if( (iCell==0)
129012 || (overlap<fMinOverlap)
129013 || (overlap==fMinOverlap && growth<fMinGrowth)
129014 || (overlap==fMinOverlap && growth==fMinGrowth && area<fMinArea)
129015 ){
129016 bBest = 1;
129017 fMinOverlap = overlap;
129018 }
129019 #else
129020 if( iCell==0||growth<fMinGrowth||(growth==fMinGrowth && area<fMinArea) ){
129021 bBest = 1;
129022 }
129023 #endif
129024 if( bBest ){
 
129025 fMinGrowth = growth;
129026 fMinArea = area;
129027 iBest = cell.iRowid;
129028 }
129029 }
129030
+16 -3
--- 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.7.9"
111111
#define SQLITE_VERSION_NUMBER 3007009
112
-#define SQLITE_SOURCE_ID "2011-10-11 20:41:54 b94a80a832777f0e639f6a81fcfe169bf970a8c0"
112
+#define SQLITE_SOURCE_ID "2011-10-15 00:16:30 39408702a989f907261c298bf0947f3e68bd10fe"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2802,11 +2802,12 @@
28022802
** zSql string ends at either the first '\000' or '\u0000' character or
28032803
** the nByte-th byte, whichever comes first. If the caller knows
28042804
** that the supplied string is nul-terminated, then there is a small
28052805
** performance advantage to be gained by passing an nByte parameter that
28062806
** is equal to the number of bytes in the input string <i>including</i>
2807
-** the nul-terminator bytes.
2807
+** the nul-terminator bytes as this saves SQLite from having to
2808
+** make a copy of the input string.
28082809
**
28092810
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
28102811
** past the end of the first SQL statement in zSql. These routines only
28112812
** compile the first statement in zSql, so *pzTail is left pointing to
28122813
** what remains uncompiled.
@@ -3023,10 +3024,17 @@
30233024
** ^(In those routines that have a fourth argument, its value is the
30243025
** number of bytes in the parameter. To be clear: the value is the
30253026
** number of <u>bytes</u> in the value, not the number of characters.)^
30263027
** ^If the fourth parameter is negative, the length of the string is
30273028
** the number of bytes up to the first zero terminator.
3029
+** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3030
+** or sqlite3_bind_text16() then that parameter must be the byte offset
3031
+** where the NUL terminator would occur assuming the string were NUL
3032
+** terminated. If any NUL characters occur at byte offsets less than
3033
+** the value of the fourth parameter then the resulting string value will
3034
+** contain embedded NULs. The result of expressions involving strings
3035
+** with embedded NULs is undefined.
30283036
**
30293037
** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
30303038
** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
30313039
** string after SQLite has finished with it. ^The destructor is called
30323040
** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
@@ -4041,11 +4049,16 @@
40414049
** is negative, then SQLite takes result text from the 2nd parameter
40424050
** through the first zero character.
40434051
** ^If the 3rd parameter to the sqlite3_result_text* interfaces
40444052
** is non-negative, then as many bytes (not characters) of the text
40454053
** pointed to by the 2nd parameter are taken as the application-defined
4046
-** function result.
4054
+** function result. If the 3rd parameter is non-negative, then it
4055
+** must be the byte offset into the string where the NUL terminator would
4056
+** appear if the string where NUL terminated. If any NUL characters occur
4057
+** in the string at a byte offset that is less than the value of the 3rd
4058
+** parameter, then the resulting string will contain embedded NULs and the
4059
+** result of expressions operating on strings with embedded NULs is undefined.
40474060
** ^If the 4th parameter to the sqlite3_result_text* interfaces
40484061
** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
40494062
** function as the destructor on the text or BLOB result when it has
40504063
** finished using that result.
40514064
** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
40524065
--- 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.7.9"
111 #define SQLITE_VERSION_NUMBER 3007009
112 #define SQLITE_SOURCE_ID "2011-10-11 20:41:54 b94a80a832777f0e639f6a81fcfe169bf970a8c0"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2802,11 +2802,12 @@
2802 ** zSql string ends at either the first '\000' or '\u0000' character or
2803 ** the nByte-th byte, whichever comes first. If the caller knows
2804 ** that the supplied string is nul-terminated, then there is a small
2805 ** performance advantage to be gained by passing an nByte parameter that
2806 ** is equal to the number of bytes in the input string <i>including</i>
2807 ** the nul-terminator bytes.
 
2808 **
2809 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
2810 ** past the end of the first SQL statement in zSql. These routines only
2811 ** compile the first statement in zSql, so *pzTail is left pointing to
2812 ** what remains uncompiled.
@@ -3023,10 +3024,17 @@
3023 ** ^(In those routines that have a fourth argument, its value is the
3024 ** number of bytes in the parameter. To be clear: the value is the
3025 ** number of <u>bytes</u> in the value, not the number of characters.)^
3026 ** ^If the fourth parameter is negative, the length of the string is
3027 ** the number of bytes up to the first zero terminator.
 
 
 
 
 
 
 
3028 **
3029 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3030 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3031 ** string after SQLite has finished with it. ^The destructor is called
3032 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
@@ -4041,11 +4049,16 @@
4041 ** is negative, then SQLite takes result text from the 2nd parameter
4042 ** through the first zero character.
4043 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4044 ** is non-negative, then as many bytes (not characters) of the text
4045 ** pointed to by the 2nd parameter are taken as the application-defined
4046 ** function result.
 
 
 
 
 
4047 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
4048 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
4049 ** function as the destructor on the text or BLOB result when it has
4050 ** finished using that result.
4051 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
4052
--- 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.7.9"
111 #define SQLITE_VERSION_NUMBER 3007009
112 #define SQLITE_SOURCE_ID "2011-10-15 00:16:30 39408702a989f907261c298bf0947f3e68bd10fe"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2802,11 +2802,12 @@
2802 ** zSql string ends at either the first '\000' or '\u0000' character or
2803 ** the nByte-th byte, whichever comes first. If the caller knows
2804 ** that the supplied string is nul-terminated, then there is a small
2805 ** performance advantage to be gained by passing an nByte parameter that
2806 ** is equal to the number of bytes in the input string <i>including</i>
2807 ** the nul-terminator bytes as this saves SQLite from having to
2808 ** make a copy of the input string.
2809 **
2810 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
2811 ** past the end of the first SQL statement in zSql. These routines only
2812 ** compile the first statement in zSql, so *pzTail is left pointing to
2813 ** what remains uncompiled.
@@ -3023,10 +3024,17 @@
3024 ** ^(In those routines that have a fourth argument, its value is the
3025 ** number of bytes in the parameter. To be clear: the value is the
3026 ** number of <u>bytes</u> in the value, not the number of characters.)^
3027 ** ^If the fourth parameter is negative, the length of the string is
3028 ** the number of bytes up to the first zero terminator.
3029 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3030 ** or sqlite3_bind_text16() then that parameter must be the byte offset
3031 ** where the NUL terminator would occur assuming the string were NUL
3032 ** terminated. If any NUL characters occur at byte offsets less than
3033 ** the value of the fourth parameter then the resulting string value will
3034 ** contain embedded NULs. The result of expressions involving strings
3035 ** with embedded NULs is undefined.
3036 **
3037 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
3038 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
3039 ** string after SQLite has finished with it. ^The destructor is called
3040 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(),
@@ -4041,11 +4049,16 @@
4049 ** is negative, then SQLite takes result text from the 2nd parameter
4050 ** through the first zero character.
4051 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
4052 ** is non-negative, then as many bytes (not characters) of the text
4053 ** pointed to by the 2nd parameter are taken as the application-defined
4054 ** function result. If the 3rd parameter is non-negative, then it
4055 ** must be the byte offset into the string where the NUL terminator would
4056 ** appear if the string where NUL terminated. If any NUL characters occur
4057 ** in the string at a byte offset that is less than the value of the 3rd
4058 ** parameter, then the resulting string will contain embedded NULs and the
4059 ** result of expressions operating on strings with embedded NULs is undefined.
4060 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
4061 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
4062 ** function as the destructor on the text or BLOB result when it has
4063 ** finished using that result.
4064 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
4065

Keyboard Shortcuts

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