Fossil SCM

Update to the latest SQLite with its new performance enhancements.

drh 2014-03-03 23:21 UTC trunk
Commit 13c1fa7626d50aea5f6d0018d7b36efda9c33e41
3 files changed +25 +671 -218 +1 -1
+25
--- src/shell.c
+++ src/shell.c
@@ -444,10 +444,11 @@
444444
** state and mode information.
445445
*/
446446
struct callback_data {
447447
sqlite3 *db; /* The database */
448448
int echoOn; /* True to echo input commands */
449
+ int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */
449450
int statsOn; /* True to display memory stats before each finalize */
450451
int cnt; /* Number of records displayed so far */
451452
FILE *out; /* Write results here */
452453
FILE *traceOut; /* Output for sqlite3_trace() */
453454
int nErr; /* Number of errors seen */
@@ -1299,10 +1300,27 @@
12991300
/* echo the sql statement if echo on */
13001301
if( pArg && pArg->echoOn ){
13011302
const char *zStmtSql = sqlite3_sql(pStmt);
13021303
fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
13031304
}
1305
+
1306
+ /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1307
+ if( pArg && pArg->autoEQP ){
1308
+ sqlite3_stmt *pExplain;
1309
+ char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
1310
+ rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1311
+ if( rc==SQLITE_OK ){
1312
+ while( sqlite3_step(pExplain)==SQLITE_ROW ){
1313
+ fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1314
+ fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1315
+ fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
1316
+ fprintf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1317
+ }
1318
+ }
1319
+ sqlite3_finalize(pExplain);
1320
+ sqlite3_free(zEQP);
1321
+ }
13041322
13051323
/* Output TESTCTRL_EXPLAIN text of requested */
13061324
if( pArg && pArg->mode==MODE_Explain ){
13071325
const char *zExplain = 0;
13081326
sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
@@ -2298,10 +2316,14 @@
22982316
}else
22992317
23002318
if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
23012319
p->echoOn = booleanValue(azArg[1]);
23022320
}else
2321
+
2322
+ if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){
2323
+ p->autoEQP = booleanValue(azArg[1]);
2324
+ }else
23032325
23042326
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
23052327
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
23062328
rc = 2;
23072329
}else
@@ -2871,10 +2893,11 @@
28712893
}else
28722894
28732895
if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
28742896
int i;
28752897
fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
2898
+ fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
28762899
fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
28772900
fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
28782901
fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
28792902
fprintf(p->out,"%9.9s: ", "nullvalue");
28802903
output_c_string(p->out, p->nullvalue);
@@ -3708,10 +3731,12 @@
37083731
data.showHeader = 1;
37093732
}else if( strcmp(z,"-noheader")==0 ){
37103733
data.showHeader = 0;
37113734
}else if( strcmp(z,"-echo")==0 ){
37123735
data.echoOn = 1;
3736
+ }else if( strcmp(z,"-eqp")==0 ){
3737
+ data.autoEQP = 1;
37133738
}else if( strcmp(z,"-stats")==0 ){
37143739
data.statsOn = 1;
37153740
}else if( strcmp(z,"-bail")==0 ){
37163741
bail_on_error = 1;
37173742
}else if( strcmp(z,"-version")==0 ){
37183743
--- src/shell.c
+++ src/shell.c
@@ -444,10 +444,11 @@
444 ** state and mode information.
445 */
446 struct callback_data {
447 sqlite3 *db; /* The database */
448 int echoOn; /* True to echo input commands */
 
449 int statsOn; /* True to display memory stats before each finalize */
450 int cnt; /* Number of records displayed so far */
451 FILE *out; /* Write results here */
452 FILE *traceOut; /* Output for sqlite3_trace() */
453 int nErr; /* Number of errors seen */
@@ -1299,10 +1300,27 @@
1299 /* echo the sql statement if echo on */
1300 if( pArg && pArg->echoOn ){
1301 const char *zStmtSql = sqlite3_sql(pStmt);
1302 fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1303 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1304
1305 /* Output TESTCTRL_EXPLAIN text of requested */
1306 if( pArg && pArg->mode==MODE_Explain ){
1307 const char *zExplain = 0;
1308 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
@@ -2298,10 +2316,14 @@
2298 }else
2299
2300 if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
2301 p->echoOn = booleanValue(azArg[1]);
2302 }else
 
 
 
 
2303
2304 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
2305 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2306 rc = 2;
2307 }else
@@ -2871,10 +2893,11 @@
2871 }else
2872
2873 if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
2874 int i;
2875 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
 
2876 fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
2877 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
2878 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
2879 fprintf(p->out,"%9.9s: ", "nullvalue");
2880 output_c_string(p->out, p->nullvalue);
@@ -3708,10 +3731,12 @@
3708 data.showHeader = 1;
3709 }else if( strcmp(z,"-noheader")==0 ){
3710 data.showHeader = 0;
3711 }else if( strcmp(z,"-echo")==0 ){
3712 data.echoOn = 1;
 
 
3713 }else if( strcmp(z,"-stats")==0 ){
3714 data.statsOn = 1;
3715 }else if( strcmp(z,"-bail")==0 ){
3716 bail_on_error = 1;
3717 }else if( strcmp(z,"-version")==0 ){
3718
--- src/shell.c
+++ src/shell.c
@@ -444,10 +444,11 @@
444 ** state and mode information.
445 */
446 struct callback_data {
447 sqlite3 *db; /* The database */
448 int echoOn; /* True to echo input commands */
449 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */
450 int statsOn; /* True to display memory stats before each finalize */
451 int cnt; /* Number of records displayed so far */
452 FILE *out; /* Write results here */
453 FILE *traceOut; /* Output for sqlite3_trace() */
454 int nErr; /* Number of errors seen */
@@ -1299,10 +1300,27 @@
1300 /* echo the sql statement if echo on */
1301 if( pArg && pArg->echoOn ){
1302 const char *zStmtSql = sqlite3_sql(pStmt);
1303 fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1304 }
1305
1306 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1307 if( pArg && pArg->autoEQP ){
1308 sqlite3_stmt *pExplain;
1309 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
1310 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1311 if( rc==SQLITE_OK ){
1312 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1313 fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1314 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
1315 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
1316 fprintf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1317 }
1318 }
1319 sqlite3_finalize(pExplain);
1320 sqlite3_free(zEQP);
1321 }
1322
1323 /* Output TESTCTRL_EXPLAIN text of requested */
1324 if( pArg && pArg->mode==MODE_Explain ){
1325 const char *zExplain = 0;
1326 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
@@ -2298,10 +2316,14 @@
2316 }else
2317
2318 if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
2319 p->echoOn = booleanValue(azArg[1]);
2320 }else
2321
2322 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){
2323 p->autoEQP = booleanValue(azArg[1]);
2324 }else
2325
2326 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
2327 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
2328 rc = 2;
2329 }else
@@ -2871,10 +2893,11 @@
2893 }else
2894
2895 if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
2896 int i;
2897 fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
2898 fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
2899 fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
2900 fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
2901 fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
2902 fprintf(p->out,"%9.9s: ", "nullvalue");
2903 output_c_string(p->out, p->nullvalue);
@@ -3708,10 +3731,12 @@
3731 data.showHeader = 1;
3732 }else if( strcmp(z,"-noheader")==0 ){
3733 data.showHeader = 0;
3734 }else if( strcmp(z,"-echo")==0 ){
3735 data.echoOn = 1;
3736 }else if( strcmp(z,"-eqp")==0 ){
3737 data.autoEQP = 1;
3738 }else if( strcmp(z,"-stats")==0 ){
3739 data.statsOn = 1;
3740 }else if( strcmp(z,"-bail")==0 ){
3741 bail_on_error = 1;
3742 }else if( strcmp(z,"-version")==0 ){
3743
+671 -218
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -189,11 +189,11 @@
189189
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190190
** [sqlite_version()] and [sqlite_source_id()].
191191
*/
192192
#define SQLITE_VERSION "3.8.4"
193193
#define SQLITE_VERSION_NUMBER 3008004
194
-#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
194
+#define SQLITE_SOURCE_ID "2014-03-03 21:59:33 aec5473a750e412eb1e11e17bbafd760db086c86"
195195
196196
/*
197197
** CAPI3REF: Run-Time Library Version Numbers
198198
** KEYWORDS: sqlite3_version, sqlite3_sourceid
199199
**
@@ -9334,12 +9334,15 @@
93349334
#ifndef SQLITE_OMIT_TRACE
93359335
SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
93369336
#endif
93379337
93389338
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9339
-SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
9339
+SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,const UnpackedRecord*,int);
93409340
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9341
+
9342
+typedef int (*RecordCompare)(int,const void*,const UnpackedRecord*,int);
9343
+SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
93419344
93429345
#ifndef SQLITE_OMIT_TRIGGER
93439346
SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
93449347
#endif
93459348
@@ -10950,23 +10953,23 @@
1095010953
** the OP_MakeRecord opcode of the VDBE and is disassembled by the
1095110954
** OP_Column opcode.
1095210955
**
1095310956
** This structure holds a record that has already been disassembled
1095410957
** into its constituent fields.
10958
+**
10959
+** The r1 and r2 member variables are only used by the optimized comparison
10960
+** functions vdbeRecordCompareInt() and vdbeRecordCompareString().
1095510961
*/
1095610962
struct UnpackedRecord {
1095710963
KeyInfo *pKeyInfo; /* Collation and sort-order information */
1095810964
u16 nField; /* Number of entries in apMem[] */
10959
- u8 flags; /* Boolean settings. UNPACKED_... below */
10965
+ char default_rc; /* Comparison result if keys are equal */
1096010966
Mem *aMem; /* Values */
10967
+ int r1; /* Value to return if (lhs > rhs) */
10968
+ int r2; /* Value to return if (rhs < lhs) */
1096110969
};
1096210970
10963
-/*
10964
-** Allowed values of UnpackedRecord.flags
10965
-*/
10966
-#define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
10967
-#define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
1096810971
1096910972
/*
1097010973
** Each SQL index is represented in memory by an
1097110974
** instance of the following structure.
1097210975
**
@@ -13840,11 +13843,11 @@
1384013843
** the following flags must be set to determine the memory management
1384113844
** policy for Mem.z. The MEM_Term flag tells us whether or not the
1384213845
** string is \000 or \u0000 terminated
1384313846
*/
1384413847
#define MEM_Term 0x0200 /* String rep is nul terminated */
13845
-#define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
13848
+#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
1384613849
#define MEM_Static 0x0800 /* Mem.z points to a static string */
1384713850
#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
1384813851
#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
1384913852
#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
1385013853
#ifdef SQLITE_OMIT_INCRBLOB
@@ -14023,11 +14026,11 @@
1402314026
SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
1402414027
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
1402514028
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1402614029
1402714030
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14028
-SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
14031
+SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,const UnpackedRecord*,int*);
1402914032
SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
1403014033
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
1403114034
SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
1403214035
SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
1403314036
SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
@@ -14088,10 +14091,11 @@
1408814091
# define sqlite3VdbeLeave(X)
1408914092
#endif
1409014093
1409114094
#ifdef SQLITE_DEBUG
1409214095
SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
14096
+SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem*);
1409314097
#endif
1409414098
1409514099
#ifndef SQLITE_OMIT_FOREIGN_KEY
1409614100
SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
1409714101
#else
@@ -21471,11 +21475,11 @@
2147121475
assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
2147221476
2147321477
sqlite3VdbeMemRelease(pMem);
2147421478
pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
2147521479
pMem->enc = desiredEnc;
21476
- pMem->flags |= (MEM_Term|MEM_Dyn);
21480
+ pMem->flags |= (MEM_Term);
2147721481
pMem->z = (char*)zOut;
2147821482
pMem->zMalloc = pMem->z;
2147921483
2148021484
translate_out:
2148121485
#if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
@@ -21599,11 +21603,10 @@
2159921603
sqlite3VdbeMemRelease(&m);
2160021604
m.z = 0;
2160121605
}
2160221606
assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
2160321607
assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
21604
- assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
2160521608
assert( m.z || db->mallocFailed );
2160621609
return m.z;
2160721610
}
2160821611
2160921612
/*
@@ -55305,10 +55308,11 @@
5530555308
i64 intKey, /* The table key */
5530655309
int biasRight, /* If true, bias the search to the high end */
5530755310
int *pRes /* Write search results here */
5530855311
){
5530955312
int rc;
55313
+ RecordCompare xRecordCompare;
5531055314
5531155315
assert( cursorHoldsMutex(pCur) );
5531255316
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5531355317
assert( pRes );
5531455318
assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
@@ -55325,10 +55329,20 @@
5532555329
if( pCur->atLast && pCur->info.nKey<intKey ){
5532655330
*pRes = -1;
5532755331
return SQLITE_OK;
5532855332
}
5532955333
}
55334
+
55335
+ if( pIdxKey ){
55336
+ xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
55337
+ assert( pIdxKey->default_rc==1
55338
+ || pIdxKey->default_rc==0
55339
+ || pIdxKey->default_rc==-1
55340
+ );
55341
+ }else{
55342
+ xRecordCompare = 0; /* Not actually used. Avoids a compiler warning. */
55343
+ }
5533055344
5533155345
rc = moveToRoot(pCur);
5533255346
if( rc ){
5533355347
return rc;
5533455348
}
@@ -55410,18 +55424,18 @@
5541055424
if( nCell<=pPage->max1bytePayload ){
5541155425
/* This branch runs if the record-size field of the cell is a
5541255426
** single byte varint and the record fits entirely on the main
5541355427
** b-tree page. */
5541455428
testcase( pCell+nCell+1==pPage->aDataEnd );
55415
- c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55429
+ c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey, 0);
5541655430
}else if( !(pCell[1] & 0x80)
5541755431
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
5541855432
){
5541955433
/* The record-size field is a 2 byte varint and the record
5542055434
** fits entirely on the main b-tree page. */
5542155435
testcase( pCell+nCell+2==pPage->aDataEnd );
55422
- c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
55436
+ c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey, 0);
5542355437
}else{
5542455438
/* The record flows over onto one or more overflow pages. In
5542555439
** this case the whole cell needs to be parsed, a buffer allocated
5542655440
** and accessPayload() used to retrieve the record into the
5542755441
** buffer before VdbeRecordCompare() can be called. */
@@ -55438,11 +55452,11 @@
5543855452
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
5543955453
if( rc ){
5544055454
sqlite3_free(pCellKey);
5544155455
goto moveto_finish;
5544255456
}
55443
- c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
55457
+ c = xRecordCompare(nCell, pCellKey, pIdxKey, 0);
5544455458
sqlite3_free(pCellKey);
5544555459
}
5544655460
if( c<0 ){
5544755461
lwr = idx+1;
5544855462
}else if( c>0 ){
@@ -60001,10 +60015,46 @@
6000160015
** This file contains code use to manipulate "Mem" structure. A "Mem"
6000260016
** stores a single value in the VDBE. Mem is an opaque structure visible
6000360017
** only within the VDBE. Interface routines refer to a Mem using the
6000460018
** name sqlite_value
6000560019
*/
60020
+
60021
+#ifdef SQLITE_DEBUG
60022
+/*
60023
+** Check invariants on a Mem object.
60024
+**
60025
+** This routine is intended for use inside of assert() statements, like
60026
+** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
60027
+*/
60028
+SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
60029
+ /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
60030
+ ** function for Mem.z
60031
+ */
60032
+ assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
60033
+ assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
60034
+
60035
+ /* If p holds a string or blob, the Mem.z must point to exactly
60036
+ ** one of the following:
60037
+ **
60038
+ ** (1) Memory in Mem.zMalloc and managed by the Mem object
60039
+ ** (2) Memory to be freed using Mem.xDel
60040
+ ** (3) An ephermal string or blob
60041
+ ** (4) A static string or blob
60042
+ */
60043
+ if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){
60044
+ assert(
60045
+ ((p->z==p->zMalloc)? 1 : 0) +
60046
+ ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
60047
+ ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
60048
+ ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
60049
+ );
60050
+ }
60051
+
60052
+ return 1;
60053
+}
60054
+#endif
60055
+
6000660056
6000760057
/*
6000860058
** If pMem is an object with a valid string representation, this routine
6000960059
** ensures the internal encoding for the string representation is
6001060060
** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
@@ -60051,16 +60101,11 @@
6005160101
** pMem->z into the new allocation. pMem must be either a string or
6005260102
** blob if bPreserve is true. If bPreserve is false, any prior content
6005360103
** in pMem->z is discarded.
6005460104
*/
6005560105
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
60056
- assert( 1 >=
60057
- ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
60058
- (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
60059
- ((pMem->flags&MEM_Ephem) ? 1 : 0) +
60060
- ((pMem->flags&MEM_Static) ? 1 : 0)
60061
- );
60106
+ assert( sqlite3VdbeCheckMemInvariants(pMem) );
6006260107
assert( (pMem->flags&MEM_RowSet)==0 );
6006360108
6006460109
/* If the bPreserve flag is set to true, then the memory cell must already
6006560110
** contain a valid string or blob value. */
6006660111
assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
@@ -60074,26 +60119,26 @@
6007460119
}else{
6007560120
sqlite3DbFree(pMem->db, pMem->zMalloc);
6007660121
pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
6007760122
}
6007860123
if( pMem->zMalloc==0 ){
60079
- sqlite3VdbeMemRelease(pMem);
60124
+ VdbeMemRelease(pMem);
6008060125
pMem->flags = MEM_Null;
6008160126
return SQLITE_NOMEM;
6008260127
}
6008360128
}
6008460129
6008560130
if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
6008660131
memcpy(pMem->zMalloc, pMem->z, pMem->n);
6008760132
}
60088
- if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
60089
- assert( pMem->xDel!=SQLITE_DYNAMIC );
60133
+ if( (pMem->flags&MEM_Dyn)!=0 ){
60134
+ assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
6009060135
pMem->xDel((void *)(pMem->z));
6009160136
}
6009260137
6009360138
pMem->z = pMem->zMalloc;
60094
- pMem->flags &= ~(MEM_Ephem|MEM_Static);
60139
+ pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
6009560140
pMem->xDel = 0;
6009660141
return SQLITE_OK;
6009760142
}
6009860143
6009960144
/*
@@ -60258,13 +60303,13 @@
6025860303
assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
6025960304
if( p->flags&MEM_Agg ){
6026060305
sqlite3VdbeMemFinalize(p, p->u.pDef);
6026160306
assert( (p->flags & MEM_Agg)==0 );
6026260307
sqlite3VdbeMemRelease(p);
60263
- }else if( p->flags&MEM_Dyn && p->xDel ){
60308
+ }else if( p->flags&MEM_Dyn ){
6026460309
assert( (p->flags&MEM_RowSet)==0 );
60265
- assert( p->xDel!=SQLITE_DYNAMIC );
60310
+ assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
6026660311
p->xDel((void *)p->z);
6026760312
p->xDel = 0;
6026860313
}else if( p->flags&MEM_RowSet ){
6026960314
sqlite3RowSetClear(p->u.pRowSet);
6027060315
}else if( p->flags&MEM_Frame ){
@@ -60276,10 +60321,11 @@
6027660321
** Release any memory held by the Mem. This may leave the Mem in an
6027760322
** inconsistent state, for example with (Mem.z==0) and
6027860323
** (Mem.memType==MEM_Str).
6027960324
*/
6028060325
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60326
+ assert( sqlite3VdbeCheckMemInvariants(p) );
6028160327
VdbeMemRelease(p);
6028260328
if( p->zMalloc ){
6028360329
sqlite3DbFree(p->db, p->zMalloc);
6028460330
p->zMalloc = 0;
6028560331
}
@@ -60613,10 +60659,11 @@
6061360659
6061460660
assert( (pFrom->flags & MEM_RowSet)==0 );
6061560661
VdbeMemRelease(pTo);
6061660662
memcpy(pTo, pFrom, MEMCELLSIZE);
6061760663
pTo->flags &= ~MEM_Dyn;
60664
+ pTo->xDel = 0;
6061860665
6061960666
if( pTo->flags&(MEM_Str|MEM_Blob) ){
6062060667
if( 0==(pFrom->flags&MEM_Static) ){
6062160668
pTo->flags |= MEM_Ephem;
6062260669
rc = sqlite3VdbeMemMakeWriteable(pTo);
@@ -60738,123 +60785,10 @@
6073860785
}
6073960786
6074060787
return SQLITE_OK;
6074160788
}
6074260789
60743
-/*
60744
-** Compare the values contained by the two memory cells, returning
60745
-** negative, zero or positive if pMem1 is less than, equal to, or greater
60746
-** than pMem2. Sorting order is NULL's first, followed by numbers (integers
60747
-** and reals) sorted numerically, followed by text ordered by the collating
60748
-** sequence pColl and finally blob's ordered by memcmp().
60749
-**
60750
-** Two NULL values are considered equal by this function.
60751
-*/
60752
-SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
60753
- int rc;
60754
- int f1, f2;
60755
- int combined_flags;
60756
-
60757
- f1 = pMem1->flags;
60758
- f2 = pMem2->flags;
60759
- combined_flags = f1|f2;
60760
- assert( (combined_flags & MEM_RowSet)==0 );
60761
-
60762
- /* If one value is NULL, it is less than the other. If both values
60763
- ** are NULL, return 0.
60764
- */
60765
- if( combined_flags&MEM_Null ){
60766
- return (f2&MEM_Null) - (f1&MEM_Null);
60767
- }
60768
-
60769
- /* If one value is a number and the other is not, the number is less.
60770
- ** If both are numbers, compare as reals if one is a real, or as integers
60771
- ** if both values are integers.
60772
- */
60773
- if( combined_flags&(MEM_Int|MEM_Real) ){
60774
- double r1, r2;
60775
- if( (f1 & f2 & MEM_Int)!=0 ){
60776
- if( pMem1->u.i < pMem2->u.i ) return -1;
60777
- if( pMem1->u.i > pMem2->u.i ) return 1;
60778
- return 0;
60779
- }
60780
- if( (f1&MEM_Real)!=0 ){
60781
- r1 = pMem1->r;
60782
- }else if( (f1&MEM_Int)!=0 ){
60783
- r1 = (double)pMem1->u.i;
60784
- }else{
60785
- return 1;
60786
- }
60787
- if( (f2&MEM_Real)!=0 ){
60788
- r2 = pMem2->r;
60789
- }else if( (f2&MEM_Int)!=0 ){
60790
- r2 = (double)pMem2->u.i;
60791
- }else{
60792
- return -1;
60793
- }
60794
- if( r1<r2 ) return -1;
60795
- if( r1>r2 ) return 1;
60796
- return 0;
60797
- }
60798
-
60799
- /* If one value is a string and the other is a blob, the string is less.
60800
- ** If both are strings, compare using the collating functions.
60801
- */
60802
- if( combined_flags&MEM_Str ){
60803
- if( (f1 & MEM_Str)==0 ){
60804
- return 1;
60805
- }
60806
- if( (f2 & MEM_Str)==0 ){
60807
- return -1;
60808
- }
60809
-
60810
- assert( pMem1->enc==pMem2->enc );
60811
- assert( pMem1->enc==SQLITE_UTF8 ||
60812
- pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
60813
-
60814
- /* The collation sequence must be defined at this point, even if
60815
- ** the user deletes the collation sequence after the vdbe program is
60816
- ** compiled (this was not always the case).
60817
- */
60818
- assert( !pColl || pColl->xCmp );
60819
-
60820
- if( pColl ){
60821
- if( pMem1->enc==pColl->enc ){
60822
- /* The strings are already in the correct encoding. Call the
60823
- ** comparison function directly */
60824
- return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
60825
- }else{
60826
- const void *v1, *v2;
60827
- int n1, n2;
60828
- Mem c1;
60829
- Mem c2;
60830
- memset(&c1, 0, sizeof(c1));
60831
- memset(&c2, 0, sizeof(c2));
60832
- sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
60833
- sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
60834
- v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
60835
- n1 = v1==0 ? 0 : c1.n;
60836
- v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
60837
- n2 = v2==0 ? 0 : c2.n;
60838
- rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
60839
- sqlite3VdbeMemRelease(&c1);
60840
- sqlite3VdbeMemRelease(&c2);
60841
- return rc;
60842
- }
60843
- }
60844
- /* If a NULL pointer was passed as the collate function, fall through
60845
- ** to the blob case and use memcmp(). */
60846
- }
60847
-
60848
- /* Both values must be blobs. Compare using memcmp(). */
60849
- rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
60850
- if( rc==0 ){
60851
- rc = pMem1->n - pMem2->n;
60852
- }
60853
- return rc;
60854
-}
60855
-
6085660790
/*
6085760791
** Move data out of a btree key or data field and into a Mem structure.
6085860792
** The data or key is taken from the entry that pCur is currently pointing
6085960793
** to. offset and amt determine what portion of the data or key to retrieve.
6086060794
** key is true to get the key or false to get data. The result is written
@@ -60892,11 +60826,11 @@
6089260826
if( offset+amt<=available ){
6089360827
sqlite3VdbeMemRelease(pMem);
6089460828
pMem->z = &zData[offset];
6089560829
pMem->flags = MEM_Blob|MEM_Ephem;
6089660830
}else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60897
- pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60831
+ pMem->flags = MEM_Blob|MEM_Term;
6089860832
pMem->enc = 0;
6089960833
pMem->memType = MEM_Blob;
6090060834
if( key ){
6090160835
rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
6090260836
}else{
@@ -61010,11 +60944,10 @@
6101060944
if( pRec ){
6101160945
pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
6101260946
if( pRec->pKeyInfo ){
6101360947
assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
6101460948
assert( pRec->pKeyInfo->enc==ENC(db) );
61015
- pRec->flags = UNPACKED_PREFIX_MATCH;
6101660949
pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
6101760950
for(i=0; i<nCol; i++){
6101860951
pRec->aMem[i].flags = MEM_Null;
6101960952
pRec->aMem[i].memType = MEM_Null;
6102060953
pRec->aMem[i].db = db;
@@ -62591,10 +62524,11 @@
6259162524
}
6259262525
return;
6259362526
}
6259462527
for(pEnd=&p[N]; p<pEnd; p++){
6259562528
assert( (&p[1])==pEnd || p[0].db==p[1].db );
62529
+ assert( sqlite3VdbeCheckMemInvariants(p) );
6259662530
6259762531
/* This block is really an inlined version of sqlite3VdbeMemRelease()
6259862532
** that takes advantage of the fact that the memory cell value is
6259962533
** being set to NULL after releasing any dynamic resources.
6260062534
**
@@ -62784,11 +62718,11 @@
6278462718
6278562719
if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
6278662720
assert( p->db->mallocFailed );
6278762721
return SQLITE_ERROR;
6278862722
}
62789
- pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62723
+ pMem->flags = MEM_Str|MEM_Term;
6279062724
zP4 = displayP4(pOp, pMem->z, 32);
6279162725
if( zP4!=pMem->z ){
6279262726
sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
6279362727
}else{
6279462728
assert( pMem->z!=0 );
@@ -62801,11 +62735,11 @@
6280162735
if( p->explain==1 ){
6280262736
if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
6280362737
assert( p->db->mallocFailed );
6280462738
return SQLITE_ERROR;
6280562739
}
62806
- pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62740
+ pMem->flags = MEM_Str|MEM_Term;
6280762741
pMem->n = 2;
6280862742
sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
6280962743
pMem->memType = MEM_Str;
6281062744
pMem->enc = SQLITE_UTF8;
6281162745
pMem++;
@@ -62813,11 +62747,11 @@
6281362747
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6281462748
if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
6281562749
assert( p->db->mallocFailed );
6281662750
return SQLITE_ERROR;
6281762751
}
62818
- pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62752
+ pMem->flags = MEM_Str|MEM_Term;
6281962753
pMem->n = displayComment(pOp, zP4, pMem->z, 500);
6282062754
pMem->memType = MEM_Str;
6282162755
pMem->enc = SQLITE_UTF8;
6282262756
#else
6282362757
pMem->flags = MEM_Null; /* Comment */
@@ -64473,11 +64407,11 @@
6447364407
u32 idx; /* Offset in aKey[] to read from */
6447464408
u16 u; /* Unsigned loop counter */
6447564409
u32 szHdr;
6447664410
Mem *pMem = p->aMem;
6447764411
64478
- p->flags = 0;
64412
+ p->default_rc = 0;
6447964413
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
6448064414
idx = getVarint32(aKey, szHdr);
6448164415
d = szHdr;
6448264416
u = 0;
6448364417
while( idx<szHdr && u<p->nField && d<=nKey ){
@@ -64494,30 +64428,22 @@
6449464428
}
6449564429
assert( u<=pKeyInfo->nField + 1 );
6449664430
p->nField = u;
6449764431
}
6449864432
64433
+#if SQLITE_DEBUG
6449964434
/*
64500
-** This function compares the two table rows or index records
64501
-** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64502
-** or positive integer if key1 is less than, equal to or
64503
-** greater than key2. The {nKey1, pKey1} key must be a blob
64504
-** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64505
-** key must be a parsed key such as obtained from
64506
-** sqlite3VdbeParseRecord.
64507
-**
64508
-** Key1 and Key2 do not have to contain the same number of fields.
64509
-** The key with fewer fields is usually compares less than the
64510
-** longer key. However if the UNPACKED_INCRKEY flags in pPKey2 is set
64511
-** and the common prefixes are equal, then key1 is less than key2.
64512
-** Or if the UNPACKED_MATCH_PREFIX flag is set and the prefixes are
64513
-** equal, then the keys are considered to be equal and
64514
-** the parts beyond the common prefix are ignored.
64435
+** This function compares two index or table record keys in the same way
64436
+** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
64437
+** this function deserializes and compares values using the
64438
+** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
64439
+** in assert() statements to ensure that the optimized code in
64440
+** sqlite3VdbeRecordCompare() returns results with these two primitives.
6451564441
*/
64516
-SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64442
+static int vdbeRecordCompareDebug(
6451764443
int nKey1, const void *pKey1, /* Left key */
64518
- UnpackedRecord *pPKey2 /* Right key */
64444
+ const UnpackedRecord *pPKey2 /* Right key */
6451964445
){
6452064446
u32 d1; /* Offset into aKey[] of next data element */
6452164447
u32 idx1; /* Offset into aKey[] of next header element */
6452264448
u32 szHdr1; /* Number of bytes in header */
6452364449
int i = 0;
@@ -64587,28 +64513,552 @@
6458764513
** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
6458864514
*/
6458964515
assert( mem1.zMalloc==0 );
6459064516
6459164517
/* rc==0 here means that one of the keys ran out of fields and
64592
- ** all the fields up to that point were equal. If the UNPACKED_INCRKEY
64593
- ** flag is set, then break the tie by treating key2 as larger.
64594
- ** If the UPACKED_PREFIX_MATCH flag is set, then keys with common prefixes
64595
- ** are considered to be equal. Otherwise, the longer key is the
64596
- ** larger. As it happens, the pPKey2 will always be the longer
64597
- ** if there is a difference.
64598
- */
64599
- assert( rc==0 );
64600
- if( pPKey2->flags & UNPACKED_INCRKEY ){
64601
- rc = -1;
64602
- }else if( pPKey2->flags & UNPACKED_PREFIX_MATCH ){
64603
- /* Leave rc==0 */
64604
- }else if( idx1<szHdr1 ){
64605
- rc = 1;
64606
- }
64607
- return rc;
64608
-}
64609
-
64518
+ ** all the fields up to that point were equal. Return the the default_rc
64519
+ ** value. */
64520
+ return pPKey2->default_rc;
64521
+}
64522
+#endif
64523
+
64524
+/*
64525
+** Both *pMem1 and *pMem2 contain string values. Compare the two values
64526
+** using the collation sequence pColl. As usual, return a negative , zero
64527
+** or positive value if *pMem1 is less than, equal to or greater than
64528
+** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
64529
+*/
64530
+static int vdbeCompareMemString(
64531
+ const Mem *pMem1,
64532
+ const Mem *pMem2,
64533
+ const CollSeq *pColl
64534
+){
64535
+ if( pMem1->enc==pColl->enc ){
64536
+ /* The strings are already in the correct encoding. Call the
64537
+ ** comparison function directly */
64538
+ return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
64539
+ }else{
64540
+ int rc;
64541
+ const void *v1, *v2;
64542
+ int n1, n2;
64543
+ Mem c1;
64544
+ Mem c2;
64545
+ memset(&c1, 0, sizeof(c1));
64546
+ memset(&c2, 0, sizeof(c2));
64547
+ sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
64548
+ sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
64549
+ v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
64550
+ n1 = v1==0 ? 0 : c1.n;
64551
+ v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
64552
+ n2 = v2==0 ? 0 : c2.n;
64553
+ rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
64554
+ sqlite3VdbeMemRelease(&c1);
64555
+ sqlite3VdbeMemRelease(&c2);
64556
+ return rc;
64557
+ }
64558
+}
64559
+
64560
+/*
64561
+** Compare the values contained by the two memory cells, returning
64562
+** negative, zero or positive if pMem1 is less than, equal to, or greater
64563
+** than pMem2. Sorting order is NULL's first, followed by numbers (integers
64564
+** and reals) sorted numerically, followed by text ordered by the collating
64565
+** sequence pColl and finally blob's ordered by memcmp().
64566
+**
64567
+** Two NULL values are considered equal by this function.
64568
+*/
64569
+SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
64570
+ int rc;
64571
+ int f1, f2;
64572
+ int combined_flags;
64573
+
64574
+ f1 = pMem1->flags;
64575
+ f2 = pMem2->flags;
64576
+ combined_flags = f1|f2;
64577
+ assert( (combined_flags & MEM_RowSet)==0 );
64578
+
64579
+ /* If one value is NULL, it is less than the other. If both values
64580
+ ** are NULL, return 0.
64581
+ */
64582
+ if( combined_flags&MEM_Null ){
64583
+ return (f2&MEM_Null) - (f1&MEM_Null);
64584
+ }
64585
+
64586
+ /* If one value is a number and the other is not, the number is less.
64587
+ ** If both are numbers, compare as reals if one is a real, or as integers
64588
+ ** if both values are integers.
64589
+ */
64590
+ if( combined_flags&(MEM_Int|MEM_Real) ){
64591
+ double r1, r2;
64592
+ if( (f1 & f2 & MEM_Int)!=0 ){
64593
+ if( pMem1->u.i < pMem2->u.i ) return -1;
64594
+ if( pMem1->u.i > pMem2->u.i ) return 1;
64595
+ return 0;
64596
+ }
64597
+ if( (f1&MEM_Real)!=0 ){
64598
+ r1 = pMem1->r;
64599
+ }else if( (f1&MEM_Int)!=0 ){
64600
+ r1 = (double)pMem1->u.i;
64601
+ }else{
64602
+ return 1;
64603
+ }
64604
+ if( (f2&MEM_Real)!=0 ){
64605
+ r2 = pMem2->r;
64606
+ }else if( (f2&MEM_Int)!=0 ){
64607
+ r2 = (double)pMem2->u.i;
64608
+ }else{
64609
+ return -1;
64610
+ }
64611
+ if( r1<r2 ) return -1;
64612
+ if( r1>r2 ) return 1;
64613
+ return 0;
64614
+ }
64615
+
64616
+ /* If one value is a string and the other is a blob, the string is less.
64617
+ ** If both are strings, compare using the collating functions.
64618
+ */
64619
+ if( combined_flags&MEM_Str ){
64620
+ if( (f1 & MEM_Str)==0 ){
64621
+ return 1;
64622
+ }
64623
+ if( (f2 & MEM_Str)==0 ){
64624
+ return -1;
64625
+ }
64626
+
64627
+ assert( pMem1->enc==pMem2->enc );
64628
+ assert( pMem1->enc==SQLITE_UTF8 ||
64629
+ pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
64630
+
64631
+ /* The collation sequence must be defined at this point, even if
64632
+ ** the user deletes the collation sequence after the vdbe program is
64633
+ ** compiled (this was not always the case).
64634
+ */
64635
+ assert( !pColl || pColl->xCmp );
64636
+
64637
+ if( pColl ){
64638
+ return vdbeCompareMemString(pMem1, pMem2, pColl);
64639
+ }
64640
+ /* If a NULL pointer was passed as the collate function, fall through
64641
+ ** to the blob case and use memcmp(). */
64642
+ }
64643
+
64644
+ /* Both values must be blobs. Compare using memcmp(). */
64645
+ rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
64646
+ if( rc==0 ){
64647
+ rc = pMem1->n - pMem2->n;
64648
+ }
64649
+ return rc;
64650
+}
64651
+
64652
+
64653
+/*
64654
+** The first argument passed to this function is a serial-type that
64655
+** corresponds to an integer - all values between 1 and 9 inclusive
64656
+** except 7. The second points to a buffer containing an integer value
64657
+** serialized according to serial_type. This function deserializes
64658
+** and returns the value.
64659
+*/
64660
+static i64 vdbeRecordDecodeInt(u32 serial_type, const u8 *aKey){
64661
+ assert( CORRUPT_DB || (serial_type>=1 && serial_type<=9 && serial_type!=7) );
64662
+ switch( serial_type ){
64663
+ case 0:
64664
+ case 1:
64665
+ return (char)aKey[0];
64666
+ case 2:
64667
+ return ((char)aKey[0] << 8) | aKey[1];
64668
+ case 3:
64669
+ return ((char)aKey[0] << 16) | (aKey[1] << 8) | aKey[2];
64670
+ case 4:
64671
+ return ((char)aKey[0]<<24) | (aKey[1]<<16) | (aKey[2]<<8)| aKey[3];
64672
+ case 5: {
64673
+ i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64674
+ u32 lsw = (aKey[4] << 8) | aKey[5];
64675
+ return (i64)( msw << 16 | (u64)lsw );
64676
+ }
64677
+ case 6: {
64678
+ i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64679
+ u32 lsw = ((unsigned)aKey[4]<<24)|(aKey[5]<<16)|(aKey[6]<<8)|aKey[7];
64680
+ return (i64)( msw << 32 | (u64)lsw );
64681
+ }
64682
+ }
64683
+
64684
+ return (serial_type - 8);
64685
+}
64686
+
64687
+/*
64688
+** This function compares the two table rows or index records
64689
+** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64690
+** or positive integer if key1 is less than, equal to or
64691
+** greater than key2. The {nKey1, pKey1} key must be a blob
64692
+** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64693
+** key must be a parsed key such as obtained from
64694
+** sqlite3VdbeParseRecord.
64695
+**
64696
+** If argument bSkip is non-zero, it is assumed that the caller has already
64697
+** determined that the first fields of the keys are equal.
64698
+**
64699
+** Key1 and Key2 do not have to contain the same number of fields. If all
64700
+** fields that appear in both keys are equal, then pPKey2->default_rc is
64701
+** returned.
64702
+*/
64703
+SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64704
+ int nKey1, const void *pKey1, /* Left key */
64705
+ const UnpackedRecord *pPKey2, /* Right key */
64706
+ int bSkip /* If true, skip the first field */
64707
+){
64708
+ u32 d1; /* Offset into aKey[] of next data element */
64709
+ int i; /* Index of next field to compare */
64710
+ int szHdr1; /* Size of record header in bytes */
64711
+ u32 idx1; /* Offset of first type in header */
64712
+ int rc = 0; /* Return value */
64713
+ Mem *pRhs = pPKey2->aMem; /* Next field of pPKey2 to compare */
64714
+ KeyInfo *pKeyInfo = pPKey2->pKeyInfo;
64715
+ const unsigned char *aKey1 = (const unsigned char *)pKey1;
64716
+ Mem mem1;
64717
+
64718
+ /* If bSkip is true, then the caller has already determined that the first
64719
+ ** two elements in the keys are equal. Fix the various stack variables so
64720
+ ** that this routine begins comparing at the second field. */
64721
+ if( bSkip ){
64722
+ u32 s1;
64723
+ idx1 = 1 + getVarint32(&aKey1[1], s1);
64724
+ szHdr1 = aKey1[0];
64725
+ d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
64726
+ i = 1;
64727
+ pRhs++;
64728
+ }else{
64729
+ idx1 = getVarint32(aKey1, szHdr1);
64730
+ d1 = szHdr1;
64731
+ i = 0;
64732
+ }
64733
+
64734
+ VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
64735
+ assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
64736
+ || CORRUPT_DB );
64737
+ assert( pPKey2->pKeyInfo->aSortOrder!=0 );
64738
+ assert( pPKey2->pKeyInfo->nField>0 );
64739
+ assert( idx1<=szHdr1 || CORRUPT_DB );
64740
+ do{
64741
+ u32 serial_type;
64742
+
64743
+ /* RHS is an integer */
64744
+ if( pRhs->flags & MEM_Int ){
64745
+ serial_type = aKey1[idx1];
64746
+ if( serial_type>=12 ){
64747
+ rc = +1;
64748
+ }else if( serial_type==0 ){
64749
+ rc = -1;
64750
+ }else if( serial_type==7 ){
64751
+ double rhs = (double)pRhs->u.i;
64752
+ sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64753
+ if( mem1.r<rhs ){
64754
+ rc = -1;
64755
+ }else if( mem1.r>rhs ){
64756
+ rc = +1;
64757
+ }
64758
+ }else{
64759
+ i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
64760
+ i64 rhs = pRhs->u.i;
64761
+ if( lhs<rhs ){
64762
+ rc = -1;
64763
+ }else if( lhs>rhs ){
64764
+ rc = +1;
64765
+ }
64766
+ }
64767
+ }
64768
+
64769
+ /* RHS is real */
64770
+ else if( pRhs->flags & MEM_Real ){
64771
+ serial_type = aKey1[idx1];
64772
+ if( serial_type>=12 ){
64773
+ rc = +1;
64774
+ }else if( serial_type==0 ){
64775
+ rc = -1;
64776
+ }else{
64777
+ double rhs = pRhs->r;
64778
+ double lhs;
64779
+ sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64780
+ if( serial_type==7 ){
64781
+ lhs = mem1.r;
64782
+ }else{
64783
+ lhs = (double)mem1.u.i;
64784
+ }
64785
+ if( lhs<rhs ){
64786
+ rc = -1;
64787
+ }else if( lhs>rhs ){
64788
+ rc = +1;
64789
+ }
64790
+ }
64791
+ }
64792
+
64793
+ /* RHS is a string */
64794
+ else if( pRhs->flags & MEM_Str ){
64795
+ getVarint32(&aKey1[idx1], serial_type);
64796
+ if( serial_type<12 ){
64797
+ rc = -1;
64798
+ }else if( !(serial_type & 0x01) ){
64799
+ rc = +1;
64800
+ }else{
64801
+ mem1.n = (serial_type - 12) / 2;
64802
+ if( (d1+mem1.n) > (unsigned)nKey1 ){
64803
+ rc = 1; /* Corruption */
64804
+ }else if( pKeyInfo->aColl[i] ){
64805
+ mem1.enc = pKeyInfo->enc;
64806
+ mem1.db = pKeyInfo->db;
64807
+ mem1.flags = MEM_Str;
64808
+ mem1.z = (char*)&aKey1[d1];
64809
+ rc = vdbeCompareMemString(&mem1, pRhs, pKeyInfo->aColl[i]);
64810
+ }else{
64811
+ int nCmp = MIN(mem1.n, pRhs->n);
64812
+ rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64813
+ if( rc==0 ) rc = mem1.n - pRhs->n;
64814
+ }
64815
+ }
64816
+ }
64817
+
64818
+ /* RHS is a blob */
64819
+ else if( pRhs->flags & MEM_Blob ){
64820
+ getVarint32(&aKey1[idx1], serial_type);
64821
+ if( serial_type<12 || (serial_type & 0x01) ){
64822
+ rc = -1;
64823
+ }else{
64824
+ int nStr = (serial_type - 12) / 2;
64825
+ if( (d1+nStr) > (unsigned)nKey1 ){
64826
+ rc = 1; /* Corruption */
64827
+ }else{
64828
+ int nCmp = MIN(nStr, pRhs->n);
64829
+ rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64830
+ if( rc==0 ) rc = nStr - pRhs->n;
64831
+ }
64832
+ }
64833
+ }
64834
+
64835
+ /* RHS is null */
64836
+ else{
64837
+ serial_type = aKey1[idx1];
64838
+ rc = (serial_type!=0);
64839
+ }
64840
+
64841
+ if( rc!=0 ){
64842
+ if( pKeyInfo->aSortOrder[i] ){
64843
+ rc = -rc;
64844
+ }
64845
+ assert( CORRUPT_DB
64846
+ || (rc<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64847
+ || (rc>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64848
+ );
64849
+ assert( mem1.zMalloc==0 ); /* See comment below */
64850
+ return rc;
64851
+ }
64852
+
64853
+ i++;
64854
+ pRhs++;
64855
+ d1 += sqlite3VdbeSerialTypeLen(serial_type);
64856
+ idx1 += sqlite3VarintLen(serial_type);
64857
+ }while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 );
64858
+
64859
+ /* No memory allocation is ever used on mem1. Prove this using
64860
+ ** the following assert(). If the assert() fails, it indicates a
64861
+ ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
64862
+ assert( mem1.zMalloc==0 );
64863
+
64864
+ /* rc==0 here means that one or both of the keys ran out of fields and
64865
+ ** all the fields up to that point were equal. Return the the default_rc
64866
+ ** value. */
64867
+ assert( CORRUPT_DB
64868
+ || pPKey2->default_rc==vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)
64869
+ );
64870
+ return pPKey2->default_rc;
64871
+}
64872
+
64873
+/*
64874
+** This function is an optimized version of sqlite3VdbeRecordCompare()
64875
+** that (a) the first field of pPKey2 is an integer, and (b) the
64876
+** size-of-header varint at the start of (pKey1/nKey1) fits in a single
64877
+** byte (i.e. is less than 128).
64878
+*/
64879
+static int vdbeRecordCompareInt(
64880
+ int nKey1, const void *pKey1, /* Left key */
64881
+ const UnpackedRecord *pPKey2, /* Right key */
64882
+ int bSkip /* Ignored */
64883
+){
64884
+ const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
64885
+ int serial_type = ((const u8*)pKey1)[1];
64886
+ int res;
64887
+ i64 v = pPKey2->aMem[0].u.i;
64888
+ i64 lhs;
64889
+ UNUSED_PARAMETER(bSkip);
64890
+
64891
+ assert( bSkip==0 );
64892
+ switch( serial_type ){
64893
+ case 1:
64894
+ lhs = (char)(aKey[0]);
64895
+ break;
64896
+ case 2:
64897
+ lhs = 256*(signed char)aKey[0] + aKey[1];
64898
+ break;
64899
+ case 3:
64900
+ lhs = 65536*(char)aKey[0] | (aKey[1]<<8) | aKey[2];
64901
+ break;
64902
+ case 4:
64903
+ lhs = (int)(((u32)aKey[0]<<24) | (aKey[1]<<16) | (aKey[2]<<8)| aKey[3]);
64904
+ break;
64905
+ case 5: {
64906
+ i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64907
+ u32 lsw = (aKey[4] << 8) | aKey[5];
64908
+ lhs = (i64)( msw << 16 | (u64)lsw );
64909
+ break;
64910
+ }
64911
+ case 6: {
64912
+ i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64913
+ u32 lsw = ((unsigned)aKey[4]<<24)|(aKey[5]<<16)|(aKey[6]<<8)|aKey[7];
64914
+ lhs = (i64)( msw << 32 | (u64)lsw );
64915
+ break;
64916
+ }
64917
+ case 8:
64918
+ lhs = 0;
64919
+ break;
64920
+ case 9:
64921
+ lhs = 1;
64922
+ break;
64923
+
64924
+ /* This case could be removed without changing the results of running
64925
+ ** this code. Including it causes gcc to generate a faster switch
64926
+ ** statement (since the range of switch targets now starts at zero and
64927
+ ** is contiguous) but does not cause any duplicate code to be generated
64928
+ ** (as gcc is clever enough to combine the two like cases). Other
64929
+ ** compilers might be similar. */
64930
+ case 0: case 7:
64931
+ return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64932
+
64933
+ default:
64934
+ return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64935
+ }
64936
+
64937
+ if( v>lhs ){
64938
+ res = pPKey2->r1;
64939
+ }else if( v<lhs ){
64940
+ res = pPKey2->r2;
64941
+ }else if( pPKey2->nField>1 ){
64942
+ /* The first fields of the two keys are equal. Compare the trailing
64943
+ ** fields. */
64944
+ res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
64945
+ }else{
64946
+ /* The first fields of the two keys are equal and there are no trailing
64947
+ ** fields. Return pPKey2->default_rc in this case. */
64948
+ res = pPKey2->default_rc;
64949
+ }
64950
+
64951
+ assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
64952
+ || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64953
+ || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64954
+ || CORRUPT_DB
64955
+ );
64956
+ return res;
64957
+}
64958
+
64959
+/*
64960
+** This function is an optimized version of sqlite3VdbeRecordCompare()
64961
+** that (a) the first field of pPKey2 is a string, that (b) the first field
64962
+** uses the collation sequence BINARY and (c) that the size-of-header varint
64963
+** at the start of (pKey1/nKey1) fits in a single byte.
64964
+*/
64965
+static int vdbeRecordCompareString(
64966
+ int nKey1, const void *pKey1, /* Left key */
64967
+ const UnpackedRecord *pPKey2, /* Right key */
64968
+ int bSkip
64969
+){
64970
+ const u8 *aKey1 = (const u8*)pKey1;
64971
+ int serial_type;
64972
+ int res;
64973
+ UNUSED_PARAMETER(bSkip);
64974
+
64975
+ assert( bSkip==0 );
64976
+ getVarint32(&aKey1[1], serial_type);
64977
+
64978
+ if( serial_type<12 ){
64979
+ res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
64980
+ }else if( !(serial_type & 0x01) ){
64981
+ res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
64982
+ }else{
64983
+ int nCmp;
64984
+ int nStr;
64985
+ int szHdr = aKey1[0];
64986
+
64987
+ nStr = (serial_type-12) / 2;
64988
+ if( (szHdr + nStr) > nKey1 ) return 0; /* Corruption */
64989
+ nCmp = MIN( pPKey2->aMem[0].n, nStr );
64990
+ res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp);
64991
+
64992
+ if( res==0 ){
64993
+ res = nStr - pPKey2->aMem[0].n;
64994
+ if( res==0 ){
64995
+ if( pPKey2->nField>1 ){
64996
+ res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
64997
+ }else{
64998
+ res = pPKey2->default_rc;
64999
+ }
65000
+ }else if( res>0 ){
65001
+ res = pPKey2->r2;
65002
+ }else{
65003
+ res = pPKey2->r1;
65004
+ }
65005
+ }else if( res>0 ){
65006
+ res = pPKey2->r2;
65007
+ }else{
65008
+ res = pPKey2->r1;
65009
+ }
65010
+ }
65011
+
65012
+ assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
65013
+ || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
65014
+ || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
65015
+ || CORRUPT_DB
65016
+ );
65017
+ return res;
65018
+}
65019
+
65020
+/*
65021
+** Return a pointer to an sqlite3VdbeRecordCompare() compatible function
65022
+** suitable for comparing serialized records to the unpacked record passed
65023
+** as the only argument.
65024
+*/
65025
+SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
65026
+ /* varintRecordCompareInt() and varintRecordCompareString() both assume
65027
+ ** that the size-of-header varint that occurs at the start of each record
65028
+ ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
65029
+ ** also assumes that it is safe to overread a buffer by at least the
65030
+ ** maximum possible legal header size plus 8 bytes. Because there is
65031
+ ** guaranteed to be at least 74 (but not 136) bytes of padding following each
65032
+ ** buffer passed to varintRecordCompareInt() this makes it convenient to
65033
+ ** limit the size of the header to 64 bytes in cases where the first field
65034
+ ** is an integer.
65035
+ **
65036
+ ** The easiest way to enforce this limit is to consider only records with
65037
+ ** 13 fields or less. If the first field is an integer, the maximum legal
65038
+ ** header size is (12*5 + 1 + 1) bytes. */
65039
+ if( (p->pKeyInfo->nField + p->pKeyInfo->nXField)<=13 ){
65040
+ int flags = p->aMem[0].flags;
65041
+ if( p->pKeyInfo->aSortOrder[0] ){
65042
+ p->r1 = 1;
65043
+ p->r2 = -1;
65044
+ }else{
65045
+ p->r1 = -1;
65046
+ p->r2 = 1;
65047
+ }
65048
+ if( (flags & MEM_Int) ){
65049
+ return vdbeRecordCompareInt;
65050
+ }
65051
+ if( (flags & (MEM_Int|MEM_Real|MEM_Null|MEM_Blob))==0
65052
+ && p->pKeyInfo->aColl[0]==0
65053
+ ){
65054
+ return vdbeRecordCompareString;
65055
+ }
65056
+ }
65057
+
65058
+ return sqlite3VdbeRecordCompare;
65059
+}
6461065060
6461165061
/*
6461265062
** pCur points at an index entry created using the OP_MakeRecord opcode.
6461365063
** Read the rowid (the last field in the record) and store it in *rowid.
6461465064
** Return SQLITE_OK if everything works, or an error code otherwise.
@@ -64695,23 +65145,23 @@
6469565145
** omits the rowid at the end. The rowid at the end of the index entry
6469665146
** is ignored as well. Hence, this routine only compares the prefixes
6469765147
** of the keys prior to the final rowid, not the entire key.
6469865148
*/
6469965149
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
64700
- VdbeCursor *pC, /* The cursor to compare against */
64701
- UnpackedRecord *pUnpacked, /* Unpacked version of key to compare against */
64702
- int *res /* Write the comparison result here */
65150
+ VdbeCursor *pC, /* The cursor to compare against */
65151
+ const UnpackedRecord *pUnpacked, /* Unpacked version of key */
65152
+ int *res /* Write the comparison result here */
6470365153
){
6470465154
i64 nCellKey = 0;
6470565155
int rc;
6470665156
BtCursor *pCur = pC->pCursor;
6470765157
Mem m;
6470865158
6470965159
assert( sqlite3BtreeCursorIsValid(pCur) );
6471065160
VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
6471165161
assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64712
- /* nCellKey will always be between 0 and 0xffffffff because of the say
65162
+ /* nCellKey will always be between 0 and 0xffffffff because of the way
6471365163
** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
6471465164
if( nCellKey<=0 || nCellKey>0x7fffffff ){
6471565165
*res = 0;
6471665166
return SQLITE_CORRUPT_BKPT;
6471765167
}
@@ -64718,12 +65168,11 @@
6471865168
memset(&m, 0, sizeof(m));
6471965169
rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
6472065170
if( rc ){
6472165171
return rc;
6472265172
}
64723
- assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64724
- *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
65173
+ *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked, 0);
6472565174
sqlite3VdbeMemRelease(&m);
6472665175
return SQLITE_OK;
6472765176
}
6472865177
6472965178
/*
@@ -66629,11 +67078,11 @@
6662967078
** does not control the string, it might be deleted without the register
6663067079
** knowing it.
6663167080
**
6663267081
** This routine converts an ephemeral string into a dynamically allocated
6663367082
** string that the register itself controls. In other words, it
66634
-** converts an MEM_Ephem string into an MEM_Dyn string.
67083
+** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
6663567084
*/
6663667085
#define Deephemeralize(P) \
6663767086
if( ((P)->flags&MEM_Ephem)!=0 \
6663867087
&& sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
6663967088
@@ -67166,22 +67615,25 @@
6716667615
#ifdef SQLITE_DEBUG
6716767616
if( (pOp->opflags & OPFLG_IN1)!=0 ){
6716867617
assert( pOp->p1>0 );
6716967618
assert( pOp->p1<=(p->nMem-p->nCursor) );
6717067619
assert( memIsValid(&aMem[pOp->p1]) );
67620
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
6717167621
REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
6717267622
}
6717367623
if( (pOp->opflags & OPFLG_IN2)!=0 ){
6717467624
assert( pOp->p2>0 );
6717567625
assert( pOp->p2<=(p->nMem-p->nCursor) );
6717667626
assert( memIsValid(&aMem[pOp->p2]) );
67627
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
6717767628
REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
6717867629
}
6717967630
if( (pOp->opflags & OPFLG_IN3)!=0 ){
6718067631
assert( pOp->p3>0 );
6718167632
assert( pOp->p3<=(p->nMem-p->nCursor) );
6718267633
assert( memIsValid(&aMem[pOp->p3]) );
67634
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
6718367635
REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
6718467636
}
6718567637
if( (pOp->opflags & OPFLG_OUT2)!=0 ){
6718667638
assert( pOp->p2>0 );
6718767639
assert( pOp->p2<=(p->nMem-p->nCursor) );
@@ -67279,11 +67731,11 @@
6727967731
** and then jump to address P2.
6728067732
*/
6728167733
case OP_Gosub: { /* jump */
6728267734
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
6728367735
pIn1 = &aMem[pOp->p1];
67284
- assert( (pIn1->flags & MEM_Dyn)==0 );
67736
+ assert( VdbeMemDynamic(pIn1)==0 );
6728567737
memAboutToChange(p, pIn1);
6728667738
pIn1->flags = MEM_Int;
6728767739
pIn1->u.i = pc;
6728867740
REGISTER_TRACE(pOp->p1, pIn1);
6728967741
pc = pOp->p2 - 1;
@@ -67352,11 +67804,11 @@
6735267804
** OP_EndCoroutine, jump immediately to P2.
6735367805
*/
6735467806
case OP_Yield: { /* in1, jump */
6735567807
int pcDest;
6735667808
pIn1 = &aMem[pOp->p1];
67357
- assert( (pIn1->flags & MEM_Dyn)==0 );
67809
+ assert( VdbeMemDynamic(pIn1)==0 );
6735867810
pIn1->flags = MEM_Int;
6735967811
pcDest = (int)pIn1->u.i;
6736067812
pIn1->u.i = pc;
6736167813
REGISTER_TRACE(pOp->p1, pIn1);
6736267814
pc = pcDest;
@@ -67525,14 +67977,13 @@
6752567977
if( encoding!=SQLITE_UTF8 ){
6752667978
rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
6752767979
if( rc==SQLITE_TOOBIG ) goto too_big;
6752867980
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
6752967981
assert( pOut->zMalloc==pOut->z );
67530
- assert( pOut->flags & MEM_Dyn );
67982
+ assert( VdbeMemDynamic(pOut)==0 );
6753167983
pOut->zMalloc = 0;
6753267984
pOut->flags |= MEM_Static;
67533
- pOut->flags &= ~MEM_Dyn;
6753467985
if( pOp->p4type==P4_DYNAMIC ){
6753567986
sqlite3DbFree(db, pOp->p4.z);
6753667987
}
6753767988
pOp->p4type = P4_DYNAMIC;
6753867989
pOp->p4.z = pOut->z;
@@ -67664,18 +68115,20 @@
6766468115
do{
6766568116
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6766668117
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6766768118
assert( memIsValid(pIn1) );
6766868119
memAboutToChange(p, pOut);
68120
+ VdbeMemRelease(pOut);
6766968121
zMalloc = pOut->zMalloc;
67670
- pOut->zMalloc = 0;
67671
- sqlite3VdbeMemMove(pOut, pIn1);
68122
+ memcpy(pOut, pIn1, sizeof(Mem));
6767268123
#ifdef SQLITE_DEBUG
6767368124
if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
6767468125
pOut->pScopyFrom += p1 - pOp->p2;
6767568126
}
6767668127
#endif
68128
+ pIn1->flags = MEM_Undefined;
68129
+ pIn1->xDel = 0;
6767768130
pIn1->zMalloc = zMalloc;
6767868131
REGISTER_TRACE(p2++, pOut);
6767968132
pIn1++;
6768068133
pOut++;
6768168134
}while( n-- );
@@ -67848,14 +68301,14 @@
6784868301
Stringify(pIn2, encoding);
6784968302
nByte = pIn1->n + pIn2->n;
6785068303
if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6785168304
goto too_big;
6785268305
}
67853
- MemSetTypeFlag(pOut, MEM_Str);
6785468306
if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
6785568307
goto no_mem;
6785668308
}
68309
+ MemSetTypeFlag(pOut, MEM_Str);
6785768310
if( pOut!=pIn2 ){
6785868311
memcpy(pOut->z, pIn2->z, pIn2->n);
6785968312
}
6786068313
memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
6786168314
pOut->z[nByte]=0;
@@ -69026,10 +69479,11 @@
6902669479
** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
6902769480
** all valid.
6902869481
*/
6902969482
assert( p2<pC->nHdrParsed );
6903069483
assert( rc==SQLITE_OK );
69484
+ assert( sqlite3VdbeCheckMemInvariants(pDest) );
6903169485
if( pC->szRow>=aOffset[p2+1] ){
6903269486
/* This is the common case where the desired content fits on the original
6903369487
** page - where the content is not on an overflow page */
6903469488
VdbeMemRelease(pDest);
6903569489
sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
@@ -69063,12 +69517,12 @@
6906369517
** sqlite3VdbeMemFromBtree() call above) then transfer control of that
6906469518
** dynamically allocated space over to the pDest structure.
6906569519
** This prevents a memory copy. */
6906669520
if( sMem.zMalloc ){
6906769521
assert( sMem.z==sMem.zMalloc );
69068
- assert( !(pDest->flags & MEM_Dyn) );
69069
- assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
69522
+ assert( VdbeMemDynamic(pDest)==0 );
69523
+ assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z );
6907069524
pDest->flags &= ~(MEM_Ephem|MEM_Static);
6907169525
pDest->flags |= MEM_Term;
6907269526
pDest->z = sMem.z;
6907369527
pDest->zMalloc = sMem.zMalloc;
6907469528
}
@@ -69247,11 +69701,11 @@
6924769701
assert( i==nHdr );
6924869702
assert( j==nByte );
6924969703
6925069704
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
6925169705
pOut->n = (int)nByte;
69252
- pOut->flags = MEM_Blob | MEM_Dyn;
69706
+ pOut->flags = MEM_Blob;
6925369707
pOut->xDel = 0;
6925469708
if( nZero ){
6925569709
pOut->u.nZero = nZero;
6925669710
pOut->flags |= MEM_Zero;
6925769711
}
@@ -70121,20 +70575,20 @@
7012170575
r.pKeyInfo = pC->pKeyInfo;
7012270576
r.nField = (u16)nField;
7012370577
7012470578
/* The next line of code computes as follows, only faster:
7012570579
** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70126
- ** r.flags = UNPACKED_INCRKEY;
70580
+ ** r.default_rc = -1;
7012770581
** }else{
70128
- ** r.flags = 0;
70582
+ ** r.default_rc = +1;
7012970583
** }
7013070584
*/
70131
- r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132
- assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133
- assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134
- assert( oc!=OP_SeekGE || r.flags==0 );
70135
- assert( oc!=OP_SeekLT || r.flags==0 );
70585
+ r.default_rc = ((1 & (oc - OP_SeekLT)) ? -1 : +1);
70586
+ assert( oc!=OP_SeekGT || r.default_rc==-1 );
70587
+ assert( oc!=OP_SeekLE || r.default_rc==-1 );
70588
+ assert( oc!=OP_SeekGE || r.default_rc==+1 );
70589
+ assert( oc!=OP_SeekLT || r.default_rc==+1 );
7013670590
7013770591
r.aMem = &aMem[pOp->p3];
7013870592
#ifdef SQLITE_DEBUG
7013970593
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7014070594
#endif
@@ -70288,22 +70742,21 @@
7028870742
ExpandBlob(&r.aMem[ii]);
7028970743
#ifdef SQLITE_DEBUG
7029070744
if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
7029170745
#endif
7029270746
}
70293
- r.flags = UNPACKED_PREFIX_MATCH;
7029470747
pIdxKey = &r;
7029570748
}else{
7029670749
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
7029770750
pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
7029870751
);
7029970752
if( pIdxKey==0 ) goto no_mem;
7030070753
assert( pIn3->flags & MEM_Blob );
7030170754
assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
7030270755
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
70303
- pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
7030470756
}
70757
+ pIdxKey->default_rc = 0;
7030570758
if( pOp->opcode==OP_NoConflict ){
7030670759
/* For the OP_NoConflict opcode, take the jump if any of the
7030770760
** input fields are NULL, since any key with a NULL will not
7030870761
** conflict */
7030970762
for(ii=0; ii<r.nField; ii++){
@@ -71188,11 +71641,11 @@
7118871641
pCrsr = pC->pCursor;
7118971642
assert( pCrsr!=0 );
7119071643
assert( pOp->p5==0 );
7119171644
r.pKeyInfo = pC->pKeyInfo;
7119271645
r.nField = (u16)pOp->p3;
71193
- r.flags = UNPACKED_PREFIX_MATCH;
71646
+ r.default_rc = 0;
7119471647
r.aMem = &aMem[pOp->p2];
7119571648
#ifdef SQLITE_DEBUG
7119671649
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7119771650
#endif
7119871651
rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
@@ -71302,14 +71755,14 @@
7130271755
assert( pOp->p4type==P4_INT32 );
7130371756
r.pKeyInfo = pC->pKeyInfo;
7130471757
r.nField = (u16)pOp->p4.i;
7130571758
if( pOp->opcode<OP_IdxLT ){
7130671759
assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71307
- r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71760
+ r.default_rc = -1;
7130871761
}else{
7130971762
assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71310
- r.flags = UNPACKED_PREFIX_MATCH;
71763
+ r.default_rc = 0;
7131171764
}
7131271765
r.aMem = &aMem[pOp->p3];
7131371766
#ifdef SQLITE_DEBUG
7131471767
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7131571768
#endif
@@ -73809,14 +74262,14 @@
7380974262
if( r2->aMem[i].flags & MEM_Null ){
7381074263
*pRes = -1;
7381174264
return;
7381274265
}
7381374266
}
73814
- r2->flags |= UNPACKED_PREFIX_MATCH;
74267
+ assert( r2->default_rc==0 );
7381574268
}
7381674269
73817
- *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
74270
+ *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2, 0);
7381874271
}
7381974272
7382074273
/*
7382174274
** This function is called to compare two iterator keys when merging
7382274275
** multiple b-tree segments. Parameter iOut is the index of the aTree[]
@@ -100117,11 +100570,11 @@
100117100570
}else if( eDest!=SRT_Exists ){
100118100571
/* If the destination is an EXISTS(...) expression, the actual
100119100572
** values returned by the SELECT are not required.
100120100573
*/
100121100574
sqlite3ExprCodeExprList(pParse, pEList, regResult,
100122
- (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100575
+ (eDest==SRT_Output||eDest==SRT_Coroutine)?SQLITE_ECEL_DUP:0);
100123100576
}
100124100577
100125100578
/* If the DISTINCT keyword was present on the SELECT statement
100126100579
** and this row has been seen before, then do not make this row
100127100580
** part of the result.
@@ -110767,11 +111220,11 @@
110767111220
iCol = pRec->nField - 1;
110768111221
assert( pIdx->nSample>0 );
110769111222
assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110770111223
do{
110771111224
iTest = (iMin+i)/2;
110772
- res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
111225
+ res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec, 0);
110773111226
if( res<0 ){
110774111227
iMin = iTest+1;
110775111228
}else{
110776111229
i = iTest;
110777111230
}
@@ -110782,20 +111235,20 @@
110782111235
** above found the right answer. This block serves no purpose other
110783111236
** than to invoke the asserts. */
110784111237
if( res==0 ){
110785111238
/* If (res==0) is true, then sample $i must be equal to pRec */
110786111239
assert( i<pIdx->nSample );
110787
- assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
111240
+ assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)
110788111241
|| pParse->db->mallocFailed );
110789111242
}else{
110790111243
/* Otherwise, pRec must be smaller than sample $i and larger than
110791111244
** sample ($i-1). */
110792111245
assert( i==pIdx->nSample
110793
- || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
111246
+ || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)>0
110794111247
|| pParse->db->mallocFailed );
110795111248
assert( i==0
110796
- || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
111249
+ || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec, 0)<0
110797111250
|| pParse->db->mallocFailed );
110798111251
}
110799111252
#endif /* ifdef SQLITE_DEBUG */
110800111253
110801111254
/* At this point, aSample[i] is the first sample that is greater than
@@ -114724,11 +115177,11 @@
114724115177
114725115178
/* For a co-routine, change all OP_Column references to the table of
114726115179
** the co-routine into OP_SCopy of result contained in a register.
114727115180
** OP_Rowid becomes OP_Null.
114728115181
*/
114729
- if( pTabItem->viaCoroutine ){
115182
+ if( pTabItem->viaCoroutine && !db->mallocFailed ){
114730115183
last = sqlite3VdbeCurrentAddr(v);
114731115184
k = pLevel->addrBody;
114732115185
pOp = sqlite3VdbeGetOp(v, k);
114733115186
for(; k<last; k++, pOp++){
114734115187
if( pOp->p1!=pLevel->iTabCur ) continue;
114735115188
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -189,11 +189,11 @@
189 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190 ** [sqlite_version()] and [sqlite_source_id()].
191 */
192 #define SQLITE_VERSION "3.8.4"
193 #define SQLITE_VERSION_NUMBER 3008004
194 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
195
196 /*
197 ** CAPI3REF: Run-Time Library Version Numbers
198 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
199 **
@@ -9334,12 +9334,15 @@
9334 #ifndef SQLITE_OMIT_TRACE
9335 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
9336 #endif
9337
9338 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9339 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
9340 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
 
 
 
9341
9342 #ifndef SQLITE_OMIT_TRIGGER
9343 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9344 #endif
9345
@@ -10950,23 +10953,23 @@
10950 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
10951 ** OP_Column opcode.
10952 **
10953 ** This structure holds a record that has already been disassembled
10954 ** into its constituent fields.
 
 
 
10955 */
10956 struct UnpackedRecord {
10957 KeyInfo *pKeyInfo; /* Collation and sort-order information */
10958 u16 nField; /* Number of entries in apMem[] */
10959 u8 flags; /* Boolean settings. UNPACKED_... below */
10960 Mem *aMem; /* Values */
 
 
10961 };
10962
10963 /*
10964 ** Allowed values of UnpackedRecord.flags
10965 */
10966 #define UNPACKED_INCRKEY 0x01 /* Make this key an epsilon larger */
10967 #define UNPACKED_PREFIX_MATCH 0x02 /* A prefix match is considered OK */
10968
10969 /*
10970 ** Each SQL index is represented in memory by an
10971 ** instance of the following structure.
10972 **
@@ -13840,11 +13843,11 @@
13840 ** the following flags must be set to determine the memory management
13841 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
13842 ** string is \000 or \u0000 terminated
13843 */
13844 #define MEM_Term 0x0200 /* String rep is nul terminated */
13845 #define MEM_Dyn 0x0400 /* Need to call sqliteFree() on Mem.z */
13846 #define MEM_Static 0x0800 /* Mem.z points to a static string */
13847 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
13848 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
13849 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
13850 #ifdef SQLITE_OMIT_INCRBLOB
@@ -14023,11 +14026,11 @@
14023 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
14024 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
14025 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
14026
14027 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14028 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
14029 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
14030 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
14031 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
14032 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
14033 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
@@ -14088,10 +14091,11 @@
14088 # define sqlite3VdbeLeave(X)
14089 #endif
14090
14091 #ifdef SQLITE_DEBUG
14092 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
 
14093 #endif
14094
14095 #ifndef SQLITE_OMIT_FOREIGN_KEY
14096 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
14097 #else
@@ -21471,11 +21475,11 @@
21471 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
21472
21473 sqlite3VdbeMemRelease(pMem);
21474 pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
21475 pMem->enc = desiredEnc;
21476 pMem->flags |= (MEM_Term|MEM_Dyn);
21477 pMem->z = (char*)zOut;
21478 pMem->zMalloc = pMem->z;
21479
21480 translate_out:
21481 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
@@ -21599,11 +21603,10 @@
21599 sqlite3VdbeMemRelease(&m);
21600 m.z = 0;
21601 }
21602 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
21603 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
21604 assert( (m.flags & MEM_Dyn)!=0 || db->mallocFailed );
21605 assert( m.z || db->mallocFailed );
21606 return m.z;
21607 }
21608
21609 /*
@@ -55305,10 +55308,11 @@
55305 i64 intKey, /* The table key */
55306 int biasRight, /* If true, bias the search to the high end */
55307 int *pRes /* Write search results here */
55308 ){
55309 int rc;
 
55310
55311 assert( cursorHoldsMutex(pCur) );
55312 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
55313 assert( pRes );
55314 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
@@ -55325,10 +55329,20 @@
55325 if( pCur->atLast && pCur->info.nKey<intKey ){
55326 *pRes = -1;
55327 return SQLITE_OK;
55328 }
55329 }
 
 
 
 
 
 
 
 
 
 
55330
55331 rc = moveToRoot(pCur);
55332 if( rc ){
55333 return rc;
55334 }
@@ -55410,18 +55424,18 @@
55410 if( nCell<=pPage->max1bytePayload ){
55411 /* This branch runs if the record-size field of the cell is a
55412 ** single byte varint and the record fits entirely on the main
55413 ** b-tree page. */
55414 testcase( pCell+nCell+1==pPage->aDataEnd );
55415 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55416 }else if( !(pCell[1] & 0x80)
55417 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55418 ){
55419 /* The record-size field is a 2 byte varint and the record
55420 ** fits entirely on the main b-tree page. */
55421 testcase( pCell+nCell+2==pPage->aDataEnd );
55422 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
55423 }else{
55424 /* The record flows over onto one or more overflow pages. In
55425 ** this case the whole cell needs to be parsed, a buffer allocated
55426 ** and accessPayload() used to retrieve the record into the
55427 ** buffer before VdbeRecordCompare() can be called. */
@@ -55438,11 +55452,11 @@
55438 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
55439 if( rc ){
55440 sqlite3_free(pCellKey);
55441 goto moveto_finish;
55442 }
55443 c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
55444 sqlite3_free(pCellKey);
55445 }
55446 if( c<0 ){
55447 lwr = idx+1;
55448 }else if( c>0 ){
@@ -60001,10 +60015,46 @@
60001 ** This file contains code use to manipulate "Mem" structure. A "Mem"
60002 ** stores a single value in the VDBE. Mem is an opaque structure visible
60003 ** only within the VDBE. Interface routines refer to a Mem using the
60004 ** name sqlite_value
60005 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60006
60007 /*
60008 ** If pMem is an object with a valid string representation, this routine
60009 ** ensures the internal encoding for the string representation is
60010 ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
@@ -60051,16 +60101,11 @@
60051 ** pMem->z into the new allocation. pMem must be either a string or
60052 ** blob if bPreserve is true. If bPreserve is false, any prior content
60053 ** in pMem->z is discarded.
60054 */
60055 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
60056 assert( 1 >=
60057 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
60058 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
60059 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
60060 ((pMem->flags&MEM_Static) ? 1 : 0)
60061 );
60062 assert( (pMem->flags&MEM_RowSet)==0 );
60063
60064 /* If the bPreserve flag is set to true, then the memory cell must already
60065 ** contain a valid string or blob value. */
60066 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
@@ -60074,26 +60119,26 @@
60074 }else{
60075 sqlite3DbFree(pMem->db, pMem->zMalloc);
60076 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
60077 }
60078 if( pMem->zMalloc==0 ){
60079 sqlite3VdbeMemRelease(pMem);
60080 pMem->flags = MEM_Null;
60081 return SQLITE_NOMEM;
60082 }
60083 }
60084
60085 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
60086 memcpy(pMem->zMalloc, pMem->z, pMem->n);
60087 }
60088 if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
60089 assert( pMem->xDel!=SQLITE_DYNAMIC );
60090 pMem->xDel((void *)(pMem->z));
60091 }
60092
60093 pMem->z = pMem->zMalloc;
60094 pMem->flags &= ~(MEM_Ephem|MEM_Static);
60095 pMem->xDel = 0;
60096 return SQLITE_OK;
60097 }
60098
60099 /*
@@ -60258,13 +60303,13 @@
60258 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
60259 if( p->flags&MEM_Agg ){
60260 sqlite3VdbeMemFinalize(p, p->u.pDef);
60261 assert( (p->flags & MEM_Agg)==0 );
60262 sqlite3VdbeMemRelease(p);
60263 }else if( p->flags&MEM_Dyn && p->xDel ){
60264 assert( (p->flags&MEM_RowSet)==0 );
60265 assert( p->xDel!=SQLITE_DYNAMIC );
60266 p->xDel((void *)p->z);
60267 p->xDel = 0;
60268 }else if( p->flags&MEM_RowSet ){
60269 sqlite3RowSetClear(p->u.pRowSet);
60270 }else if( p->flags&MEM_Frame ){
@@ -60276,10 +60321,11 @@
60276 ** Release any memory held by the Mem. This may leave the Mem in an
60277 ** inconsistent state, for example with (Mem.z==0) and
60278 ** (Mem.memType==MEM_Str).
60279 */
60280 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
 
60281 VdbeMemRelease(p);
60282 if( p->zMalloc ){
60283 sqlite3DbFree(p->db, p->zMalloc);
60284 p->zMalloc = 0;
60285 }
@@ -60613,10 +60659,11 @@
60613
60614 assert( (pFrom->flags & MEM_RowSet)==0 );
60615 VdbeMemRelease(pTo);
60616 memcpy(pTo, pFrom, MEMCELLSIZE);
60617 pTo->flags &= ~MEM_Dyn;
 
60618
60619 if( pTo->flags&(MEM_Str|MEM_Blob) ){
60620 if( 0==(pFrom->flags&MEM_Static) ){
60621 pTo->flags |= MEM_Ephem;
60622 rc = sqlite3VdbeMemMakeWriteable(pTo);
@@ -60738,123 +60785,10 @@
60738 }
60739
60740 return SQLITE_OK;
60741 }
60742
60743 /*
60744 ** Compare the values contained by the two memory cells, returning
60745 ** negative, zero or positive if pMem1 is less than, equal to, or greater
60746 ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
60747 ** and reals) sorted numerically, followed by text ordered by the collating
60748 ** sequence pColl and finally blob's ordered by memcmp().
60749 **
60750 ** Two NULL values are considered equal by this function.
60751 */
60752 SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
60753 int rc;
60754 int f1, f2;
60755 int combined_flags;
60756
60757 f1 = pMem1->flags;
60758 f2 = pMem2->flags;
60759 combined_flags = f1|f2;
60760 assert( (combined_flags & MEM_RowSet)==0 );
60761
60762 /* If one value is NULL, it is less than the other. If both values
60763 ** are NULL, return 0.
60764 */
60765 if( combined_flags&MEM_Null ){
60766 return (f2&MEM_Null) - (f1&MEM_Null);
60767 }
60768
60769 /* If one value is a number and the other is not, the number is less.
60770 ** If both are numbers, compare as reals if one is a real, or as integers
60771 ** if both values are integers.
60772 */
60773 if( combined_flags&(MEM_Int|MEM_Real) ){
60774 double r1, r2;
60775 if( (f1 & f2 & MEM_Int)!=0 ){
60776 if( pMem1->u.i < pMem2->u.i ) return -1;
60777 if( pMem1->u.i > pMem2->u.i ) return 1;
60778 return 0;
60779 }
60780 if( (f1&MEM_Real)!=0 ){
60781 r1 = pMem1->r;
60782 }else if( (f1&MEM_Int)!=0 ){
60783 r1 = (double)pMem1->u.i;
60784 }else{
60785 return 1;
60786 }
60787 if( (f2&MEM_Real)!=0 ){
60788 r2 = pMem2->r;
60789 }else if( (f2&MEM_Int)!=0 ){
60790 r2 = (double)pMem2->u.i;
60791 }else{
60792 return -1;
60793 }
60794 if( r1<r2 ) return -1;
60795 if( r1>r2 ) return 1;
60796 return 0;
60797 }
60798
60799 /* If one value is a string and the other is a blob, the string is less.
60800 ** If both are strings, compare using the collating functions.
60801 */
60802 if( combined_flags&MEM_Str ){
60803 if( (f1 & MEM_Str)==0 ){
60804 return 1;
60805 }
60806 if( (f2 & MEM_Str)==0 ){
60807 return -1;
60808 }
60809
60810 assert( pMem1->enc==pMem2->enc );
60811 assert( pMem1->enc==SQLITE_UTF8 ||
60812 pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
60813
60814 /* The collation sequence must be defined at this point, even if
60815 ** the user deletes the collation sequence after the vdbe program is
60816 ** compiled (this was not always the case).
60817 */
60818 assert( !pColl || pColl->xCmp );
60819
60820 if( pColl ){
60821 if( pMem1->enc==pColl->enc ){
60822 /* The strings are already in the correct encoding. Call the
60823 ** comparison function directly */
60824 return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
60825 }else{
60826 const void *v1, *v2;
60827 int n1, n2;
60828 Mem c1;
60829 Mem c2;
60830 memset(&c1, 0, sizeof(c1));
60831 memset(&c2, 0, sizeof(c2));
60832 sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
60833 sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
60834 v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
60835 n1 = v1==0 ? 0 : c1.n;
60836 v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
60837 n2 = v2==0 ? 0 : c2.n;
60838 rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
60839 sqlite3VdbeMemRelease(&c1);
60840 sqlite3VdbeMemRelease(&c2);
60841 return rc;
60842 }
60843 }
60844 /* If a NULL pointer was passed as the collate function, fall through
60845 ** to the blob case and use memcmp(). */
60846 }
60847
60848 /* Both values must be blobs. Compare using memcmp(). */
60849 rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
60850 if( rc==0 ){
60851 rc = pMem1->n - pMem2->n;
60852 }
60853 return rc;
60854 }
60855
60856 /*
60857 ** Move data out of a btree key or data field and into a Mem structure.
60858 ** The data or key is taken from the entry that pCur is currently pointing
60859 ** to. offset and amt determine what portion of the data or key to retrieve.
60860 ** key is true to get the key or false to get data. The result is written
@@ -60892,11 +60826,11 @@
60892 if( offset+amt<=available ){
60893 sqlite3VdbeMemRelease(pMem);
60894 pMem->z = &zData[offset];
60895 pMem->flags = MEM_Blob|MEM_Ephem;
60896 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60897 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60898 pMem->enc = 0;
60899 pMem->memType = MEM_Blob;
60900 if( key ){
60901 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60902 }else{
@@ -61010,11 +60944,10 @@
61010 if( pRec ){
61011 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
61012 if( pRec->pKeyInfo ){
61013 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
61014 assert( pRec->pKeyInfo->enc==ENC(db) );
61015 pRec->flags = UNPACKED_PREFIX_MATCH;
61016 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
61017 for(i=0; i<nCol; i++){
61018 pRec->aMem[i].flags = MEM_Null;
61019 pRec->aMem[i].memType = MEM_Null;
61020 pRec->aMem[i].db = db;
@@ -62591,10 +62524,11 @@
62591 }
62592 return;
62593 }
62594 for(pEnd=&p[N]; p<pEnd; p++){
62595 assert( (&p[1])==pEnd || p[0].db==p[1].db );
 
62596
62597 /* This block is really an inlined version of sqlite3VdbeMemRelease()
62598 ** that takes advantage of the fact that the memory cell value is
62599 ** being set to NULL after releasing any dynamic resources.
62600 **
@@ -62784,11 +62718,11 @@
62784
62785 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62786 assert( p->db->mallocFailed );
62787 return SQLITE_ERROR;
62788 }
62789 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62790 zP4 = displayP4(pOp, pMem->z, 32);
62791 if( zP4!=pMem->z ){
62792 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
62793 }else{
62794 assert( pMem->z!=0 );
@@ -62801,11 +62735,11 @@
62801 if( p->explain==1 ){
62802 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62803 assert( p->db->mallocFailed );
62804 return SQLITE_ERROR;
62805 }
62806 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62807 pMem->n = 2;
62808 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62809 pMem->memType = MEM_Str;
62810 pMem->enc = SQLITE_UTF8;
62811 pMem++;
@@ -62813,11 +62747,11 @@
62813 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62814 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
62815 assert( p->db->mallocFailed );
62816 return SQLITE_ERROR;
62817 }
62818 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62819 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62820 pMem->memType = MEM_Str;
62821 pMem->enc = SQLITE_UTF8;
62822 #else
62823 pMem->flags = MEM_Null; /* Comment */
@@ -64473,11 +64407,11 @@
64473 u32 idx; /* Offset in aKey[] to read from */
64474 u16 u; /* Unsigned loop counter */
64475 u32 szHdr;
64476 Mem *pMem = p->aMem;
64477
64478 p->flags = 0;
64479 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
64480 idx = getVarint32(aKey, szHdr);
64481 d = szHdr;
64482 u = 0;
64483 while( idx<szHdr && u<p->nField && d<=nKey ){
@@ -64494,30 +64428,22 @@
64494 }
64495 assert( u<=pKeyInfo->nField + 1 );
64496 p->nField = u;
64497 }
64498
 
64499 /*
64500 ** This function compares the two table rows or index records
64501 ** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64502 ** or positive integer if key1 is less than, equal to or
64503 ** greater than key2. The {nKey1, pKey1} key must be a blob
64504 ** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64505 ** key must be a parsed key such as obtained from
64506 ** sqlite3VdbeParseRecord.
64507 **
64508 ** Key1 and Key2 do not have to contain the same number of fields.
64509 ** The key with fewer fields is usually compares less than the
64510 ** longer key. However if the UNPACKED_INCRKEY flags in pPKey2 is set
64511 ** and the common prefixes are equal, then key1 is less than key2.
64512 ** Or if the UNPACKED_MATCH_PREFIX flag is set and the prefixes are
64513 ** equal, then the keys are considered to be equal and
64514 ** the parts beyond the common prefix are ignored.
64515 */
64516 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64517 int nKey1, const void *pKey1, /* Left key */
64518 UnpackedRecord *pPKey2 /* Right key */
64519 ){
64520 u32 d1; /* Offset into aKey[] of next data element */
64521 u32 idx1; /* Offset into aKey[] of next header element */
64522 u32 szHdr1; /* Number of bytes in header */
64523 int i = 0;
@@ -64587,28 +64513,552 @@
64587 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
64588 */
64589 assert( mem1.zMalloc==0 );
64590
64591 /* rc==0 here means that one of the keys ran out of fields and
64592 ** all the fields up to that point were equal. If the UNPACKED_INCRKEY
64593 ** flag is set, then break the tie by treating key2 as larger.
64594 ** If the UPACKED_PREFIX_MATCH flag is set, then keys with common prefixes
64595 ** are considered to be equal. Otherwise, the longer key is the
64596 ** larger. As it happens, the pPKey2 will always be the longer
64597 ** if there is a difference.
64598 */
64599 assert( rc==0 );
64600 if( pPKey2->flags & UNPACKED_INCRKEY ){
64601 rc = -1;
64602 }else if( pPKey2->flags & UNPACKED_PREFIX_MATCH ){
64603 /* Leave rc==0 */
64604 }else if( idx1<szHdr1 ){
64605 rc = 1;
64606 }
64607 return rc;
64608 }
64609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64610
64611 /*
64612 ** pCur points at an index entry created using the OP_MakeRecord opcode.
64613 ** Read the rowid (the last field in the record) and store it in *rowid.
64614 ** Return SQLITE_OK if everything works, or an error code otherwise.
@@ -64695,23 +65145,23 @@
64695 ** omits the rowid at the end. The rowid at the end of the index entry
64696 ** is ignored as well. Hence, this routine only compares the prefixes
64697 ** of the keys prior to the final rowid, not the entire key.
64698 */
64699 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
64700 VdbeCursor *pC, /* The cursor to compare against */
64701 UnpackedRecord *pUnpacked, /* Unpacked version of key to compare against */
64702 int *res /* Write the comparison result here */
64703 ){
64704 i64 nCellKey = 0;
64705 int rc;
64706 BtCursor *pCur = pC->pCursor;
64707 Mem m;
64708
64709 assert( sqlite3BtreeCursorIsValid(pCur) );
64710 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
64711 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64712 /* nCellKey will always be between 0 and 0xffffffff because of the say
64713 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
64714 if( nCellKey<=0 || nCellKey>0x7fffffff ){
64715 *res = 0;
64716 return SQLITE_CORRUPT_BKPT;
64717 }
@@ -64718,12 +65168,11 @@
64718 memset(&m, 0, sizeof(m));
64719 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
64720 if( rc ){
64721 return rc;
64722 }
64723 assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64724 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
64725 sqlite3VdbeMemRelease(&m);
64726 return SQLITE_OK;
64727 }
64728
64729 /*
@@ -66629,11 +67078,11 @@
66629 ** does not control the string, it might be deleted without the register
66630 ** knowing it.
66631 **
66632 ** This routine converts an ephemeral string into a dynamically allocated
66633 ** string that the register itself controls. In other words, it
66634 ** converts an MEM_Ephem string into an MEM_Dyn string.
66635 */
66636 #define Deephemeralize(P) \
66637 if( ((P)->flags&MEM_Ephem)!=0 \
66638 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
66639
@@ -67166,22 +67615,25 @@
67166 #ifdef SQLITE_DEBUG
67167 if( (pOp->opflags & OPFLG_IN1)!=0 ){
67168 assert( pOp->p1>0 );
67169 assert( pOp->p1<=(p->nMem-p->nCursor) );
67170 assert( memIsValid(&aMem[pOp->p1]) );
 
67171 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
67172 }
67173 if( (pOp->opflags & OPFLG_IN2)!=0 ){
67174 assert( pOp->p2>0 );
67175 assert( pOp->p2<=(p->nMem-p->nCursor) );
67176 assert( memIsValid(&aMem[pOp->p2]) );
 
67177 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
67178 }
67179 if( (pOp->opflags & OPFLG_IN3)!=0 ){
67180 assert( pOp->p3>0 );
67181 assert( pOp->p3<=(p->nMem-p->nCursor) );
67182 assert( memIsValid(&aMem[pOp->p3]) );
 
67183 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
67184 }
67185 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
67186 assert( pOp->p2>0 );
67187 assert( pOp->p2<=(p->nMem-p->nCursor) );
@@ -67279,11 +67731,11 @@
67279 ** and then jump to address P2.
67280 */
67281 case OP_Gosub: { /* jump */
67282 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67283 pIn1 = &aMem[pOp->p1];
67284 assert( (pIn1->flags & MEM_Dyn)==0 );
67285 memAboutToChange(p, pIn1);
67286 pIn1->flags = MEM_Int;
67287 pIn1->u.i = pc;
67288 REGISTER_TRACE(pOp->p1, pIn1);
67289 pc = pOp->p2 - 1;
@@ -67352,11 +67804,11 @@
67352 ** OP_EndCoroutine, jump immediately to P2.
67353 */
67354 case OP_Yield: { /* in1, jump */
67355 int pcDest;
67356 pIn1 = &aMem[pOp->p1];
67357 assert( (pIn1->flags & MEM_Dyn)==0 );
67358 pIn1->flags = MEM_Int;
67359 pcDest = (int)pIn1->u.i;
67360 pIn1->u.i = pc;
67361 REGISTER_TRACE(pOp->p1, pIn1);
67362 pc = pcDest;
@@ -67525,14 +67977,13 @@
67525 if( encoding!=SQLITE_UTF8 ){
67526 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
67527 if( rc==SQLITE_TOOBIG ) goto too_big;
67528 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
67529 assert( pOut->zMalloc==pOut->z );
67530 assert( pOut->flags & MEM_Dyn );
67531 pOut->zMalloc = 0;
67532 pOut->flags |= MEM_Static;
67533 pOut->flags &= ~MEM_Dyn;
67534 if( pOp->p4type==P4_DYNAMIC ){
67535 sqlite3DbFree(db, pOp->p4.z);
67536 }
67537 pOp->p4type = P4_DYNAMIC;
67538 pOp->p4.z = pOut->z;
@@ -67664,18 +68115,20 @@
67664 do{
67665 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67666 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67667 assert( memIsValid(pIn1) );
67668 memAboutToChange(p, pOut);
 
67669 zMalloc = pOut->zMalloc;
67670 pOut->zMalloc = 0;
67671 sqlite3VdbeMemMove(pOut, pIn1);
67672 #ifdef SQLITE_DEBUG
67673 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
67674 pOut->pScopyFrom += p1 - pOp->p2;
67675 }
67676 #endif
 
 
67677 pIn1->zMalloc = zMalloc;
67678 REGISTER_TRACE(p2++, pOut);
67679 pIn1++;
67680 pOut++;
67681 }while( n-- );
@@ -67848,14 +68301,14 @@
67848 Stringify(pIn2, encoding);
67849 nByte = pIn1->n + pIn2->n;
67850 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67851 goto too_big;
67852 }
67853 MemSetTypeFlag(pOut, MEM_Str);
67854 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
67855 goto no_mem;
67856 }
 
67857 if( pOut!=pIn2 ){
67858 memcpy(pOut->z, pIn2->z, pIn2->n);
67859 }
67860 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67861 pOut->z[nByte]=0;
@@ -69026,10 +69479,11 @@
69026 ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
69027 ** all valid.
69028 */
69029 assert( p2<pC->nHdrParsed );
69030 assert( rc==SQLITE_OK );
 
69031 if( pC->szRow>=aOffset[p2+1] ){
69032 /* This is the common case where the desired content fits on the original
69033 ** page - where the content is not on an overflow page */
69034 VdbeMemRelease(pDest);
69035 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
@@ -69063,12 +69517,12 @@
69063 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
69064 ** dynamically allocated space over to the pDest structure.
69065 ** This prevents a memory copy. */
69066 if( sMem.zMalloc ){
69067 assert( sMem.z==sMem.zMalloc );
69068 assert( !(pDest->flags & MEM_Dyn) );
69069 assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
69070 pDest->flags &= ~(MEM_Ephem|MEM_Static);
69071 pDest->flags |= MEM_Term;
69072 pDest->z = sMem.z;
69073 pDest->zMalloc = sMem.zMalloc;
69074 }
@@ -69247,11 +69701,11 @@
69247 assert( i==nHdr );
69248 assert( j==nByte );
69249
69250 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69251 pOut->n = (int)nByte;
69252 pOut->flags = MEM_Blob | MEM_Dyn;
69253 pOut->xDel = 0;
69254 if( nZero ){
69255 pOut->u.nZero = nZero;
69256 pOut->flags |= MEM_Zero;
69257 }
@@ -70121,20 +70575,20 @@
70121 r.pKeyInfo = pC->pKeyInfo;
70122 r.nField = (u16)nField;
70123
70124 /* The next line of code computes as follows, only faster:
70125 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70126 ** r.flags = UNPACKED_INCRKEY;
70127 ** }else{
70128 ** r.flags = 0;
70129 ** }
70130 */
70131 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132 assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133 assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134 assert( oc!=OP_SeekGE || r.flags==0 );
70135 assert( oc!=OP_SeekLT || r.flags==0 );
70136
70137 r.aMem = &aMem[pOp->p3];
70138 #ifdef SQLITE_DEBUG
70139 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70140 #endif
@@ -70288,22 +70742,21 @@
70288 ExpandBlob(&r.aMem[ii]);
70289 #ifdef SQLITE_DEBUG
70290 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70291 #endif
70292 }
70293 r.flags = UNPACKED_PREFIX_MATCH;
70294 pIdxKey = &r;
70295 }else{
70296 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70297 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
70298 );
70299 if( pIdxKey==0 ) goto no_mem;
70300 assert( pIn3->flags & MEM_Blob );
70301 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70302 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
70303 pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70304 }
 
70305 if( pOp->opcode==OP_NoConflict ){
70306 /* For the OP_NoConflict opcode, take the jump if any of the
70307 ** input fields are NULL, since any key with a NULL will not
70308 ** conflict */
70309 for(ii=0; ii<r.nField; ii++){
@@ -71188,11 +71641,11 @@
71188 pCrsr = pC->pCursor;
71189 assert( pCrsr!=0 );
71190 assert( pOp->p5==0 );
71191 r.pKeyInfo = pC->pKeyInfo;
71192 r.nField = (u16)pOp->p3;
71193 r.flags = UNPACKED_PREFIX_MATCH;
71194 r.aMem = &aMem[pOp->p2];
71195 #ifdef SQLITE_DEBUG
71196 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71197 #endif
71198 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
@@ -71302,14 +71755,14 @@
71302 assert( pOp->p4type==P4_INT32 );
71303 r.pKeyInfo = pC->pKeyInfo;
71304 r.nField = (u16)pOp->p4.i;
71305 if( pOp->opcode<OP_IdxLT ){
71306 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71307 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71308 }else{
71309 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71310 r.flags = UNPACKED_PREFIX_MATCH;
71311 }
71312 r.aMem = &aMem[pOp->p3];
71313 #ifdef SQLITE_DEBUG
71314 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71315 #endif
@@ -73809,14 +74262,14 @@
73809 if( r2->aMem[i].flags & MEM_Null ){
73810 *pRes = -1;
73811 return;
73812 }
73813 }
73814 r2->flags |= UNPACKED_PREFIX_MATCH;
73815 }
73816
73817 *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
73818 }
73819
73820 /*
73821 ** This function is called to compare two iterator keys when merging
73822 ** multiple b-tree segments. Parameter iOut is the index of the aTree[]
@@ -100117,11 +100570,11 @@
100117 }else if( eDest!=SRT_Exists ){
100118 /* If the destination is an EXISTS(...) expression, the actual
100119 ** values returned by the SELECT are not required.
100120 */
100121 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100122 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100123 }
100124
100125 /* If the DISTINCT keyword was present on the SELECT statement
100126 ** and this row has been seen before, then do not make this row
100127 ** part of the result.
@@ -110767,11 +111220,11 @@
110767 iCol = pRec->nField - 1;
110768 assert( pIdx->nSample>0 );
110769 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
110770 do{
110771 iTest = (iMin+i)/2;
110772 res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
110773 if( res<0 ){
110774 iMin = iTest+1;
110775 }else{
110776 i = iTest;
110777 }
@@ -110782,20 +111235,20 @@
110782 ** above found the right answer. This block serves no purpose other
110783 ** than to invoke the asserts. */
110784 if( res==0 ){
110785 /* If (res==0) is true, then sample $i must be equal to pRec */
110786 assert( i<pIdx->nSample );
110787 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
110788 || pParse->db->mallocFailed );
110789 }else{
110790 /* Otherwise, pRec must be smaller than sample $i and larger than
110791 ** sample ($i-1). */
110792 assert( i==pIdx->nSample
110793 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
110794 || pParse->db->mallocFailed );
110795 assert( i==0
110796 || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
110797 || pParse->db->mallocFailed );
110798 }
110799 #endif /* ifdef SQLITE_DEBUG */
110800
110801 /* At this point, aSample[i] is the first sample that is greater than
@@ -114724,11 +115177,11 @@
114724
114725 /* For a co-routine, change all OP_Column references to the table of
114726 ** the co-routine into OP_SCopy of result contained in a register.
114727 ** OP_Rowid becomes OP_Null.
114728 */
114729 if( pTabItem->viaCoroutine ){
114730 last = sqlite3VdbeCurrentAddr(v);
114731 k = pLevel->addrBody;
114732 pOp = sqlite3VdbeGetOp(v, k);
114733 for(; k<last; k++, pOp++){
114734 if( pOp->p1!=pLevel->iTabCur ) continue;
114735
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -189,11 +189,11 @@
189 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190 ** [sqlite_version()] and [sqlite_source_id()].
191 */
192 #define SQLITE_VERSION "3.8.4"
193 #define SQLITE_VERSION_NUMBER 3008004
194 #define SQLITE_SOURCE_ID "2014-03-03 21:59:33 aec5473a750e412eb1e11e17bbafd760db086c86"
195
196 /*
197 ** CAPI3REF: Run-Time Library Version Numbers
198 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
199 **
@@ -9334,12 +9334,15 @@
9334 #ifndef SQLITE_OMIT_TRACE
9335 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
9336 #endif
9337
9338 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
9339 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,const UnpackedRecord*,int);
9340 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
9341
9342 typedef int (*RecordCompare)(int,const void*,const UnpackedRecord*,int);
9343 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
9344
9345 #ifndef SQLITE_OMIT_TRIGGER
9346 SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
9347 #endif
9348
@@ -10950,23 +10953,23 @@
10953 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
10954 ** OP_Column opcode.
10955 **
10956 ** This structure holds a record that has already been disassembled
10957 ** into its constituent fields.
10958 **
10959 ** The r1 and r2 member variables are only used by the optimized comparison
10960 ** functions vdbeRecordCompareInt() and vdbeRecordCompareString().
10961 */
10962 struct UnpackedRecord {
10963 KeyInfo *pKeyInfo; /* Collation and sort-order information */
10964 u16 nField; /* Number of entries in apMem[] */
10965 char default_rc; /* Comparison result if keys are equal */
10966 Mem *aMem; /* Values */
10967 int r1; /* Value to return if (lhs > rhs) */
10968 int r2; /* Value to return if (rhs < lhs) */
10969 };
10970
 
 
 
 
 
10971
10972 /*
10973 ** Each SQL index is represented in memory by an
10974 ** instance of the following structure.
10975 **
@@ -13840,11 +13843,11 @@
13843 ** the following flags must be set to determine the memory management
13844 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
13845 ** string is \000 or \u0000 terminated
13846 */
13847 #define MEM_Term 0x0200 /* String rep is nul terminated */
13848 #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
13849 #define MEM_Static 0x0800 /* Mem.z points to a static string */
13850 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
13851 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */
13852 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
13853 #ifdef SQLITE_OMIT_INCRBLOB
@@ -14023,11 +14026,11 @@
14026 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
14027 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
14028 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
14029
14030 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
14031 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,const UnpackedRecord*,int*);
14032 SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor *, i64 *);
14033 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
14034 SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*);
14035 SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*);
14036 SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*);
@@ -14088,10 +14091,11 @@
14091 # define sqlite3VdbeLeave(X)
14092 #endif
14093
14094 #ifdef SQLITE_DEBUG
14095 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
14096 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem*);
14097 #endif
14098
14099 #ifndef SQLITE_OMIT_FOREIGN_KEY
14100 SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int);
14101 #else
@@ -21471,11 +21475,11 @@
21475 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
21476
21477 sqlite3VdbeMemRelease(pMem);
21478 pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem);
21479 pMem->enc = desiredEnc;
21480 pMem->flags |= (MEM_Term);
21481 pMem->z = (char*)zOut;
21482 pMem->zMalloc = pMem->z;
21483
21484 translate_out:
21485 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
@@ -21599,11 +21603,10 @@
21603 sqlite3VdbeMemRelease(&m);
21604 m.z = 0;
21605 }
21606 assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
21607 assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
 
21608 assert( m.z || db->mallocFailed );
21609 return m.z;
21610 }
21611
21612 /*
@@ -55305,10 +55308,11 @@
55308 i64 intKey, /* The table key */
55309 int biasRight, /* If true, bias the search to the high end */
55310 int *pRes /* Write search results here */
55311 ){
55312 int rc;
55313 RecordCompare xRecordCompare;
55314
55315 assert( cursorHoldsMutex(pCur) );
55316 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
55317 assert( pRes );
55318 assert( (pIdxKey==0)==(pCur->pKeyInfo==0) );
@@ -55325,10 +55329,20 @@
55329 if( pCur->atLast && pCur->info.nKey<intKey ){
55330 *pRes = -1;
55331 return SQLITE_OK;
55332 }
55333 }
55334
55335 if( pIdxKey ){
55336 xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
55337 assert( pIdxKey->default_rc==1
55338 || pIdxKey->default_rc==0
55339 || pIdxKey->default_rc==-1
55340 );
55341 }else{
55342 xRecordCompare = 0; /* Not actually used. Avoids a compiler warning. */
55343 }
55344
55345 rc = moveToRoot(pCur);
55346 if( rc ){
55347 return rc;
55348 }
@@ -55410,18 +55424,18 @@
55424 if( nCell<=pPage->max1bytePayload ){
55425 /* This branch runs if the record-size field of the cell is a
55426 ** single byte varint and the record fits entirely on the main
55427 ** b-tree page. */
55428 testcase( pCell+nCell+1==pPage->aDataEnd );
55429 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey, 0);
55430 }else if( !(pCell[1] & 0x80)
55431 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55432 ){
55433 /* The record-size field is a 2 byte varint and the record
55434 ** fits entirely on the main b-tree page. */
55435 testcase( pCell+nCell+2==pPage->aDataEnd );
55436 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey, 0);
55437 }else{
55438 /* The record flows over onto one or more overflow pages. In
55439 ** this case the whole cell needs to be parsed, a buffer allocated
55440 ** and accessPayload() used to retrieve the record into the
55441 ** buffer before VdbeRecordCompare() can be called. */
@@ -55438,11 +55452,11 @@
55452 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
55453 if( rc ){
55454 sqlite3_free(pCellKey);
55455 goto moveto_finish;
55456 }
55457 c = xRecordCompare(nCell, pCellKey, pIdxKey, 0);
55458 sqlite3_free(pCellKey);
55459 }
55460 if( c<0 ){
55461 lwr = idx+1;
55462 }else if( c>0 ){
@@ -60001,10 +60015,46 @@
60015 ** This file contains code use to manipulate "Mem" structure. A "Mem"
60016 ** stores a single value in the VDBE. Mem is an opaque structure visible
60017 ** only within the VDBE. Interface routines refer to a Mem using the
60018 ** name sqlite_value
60019 */
60020
60021 #ifdef SQLITE_DEBUG
60022 /*
60023 ** Check invariants on a Mem object.
60024 **
60025 ** This routine is intended for use inside of assert() statements, like
60026 ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
60027 */
60028 SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
60029 /* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
60030 ** function for Mem.z
60031 */
60032 assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
60033 assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
60034
60035 /* If p holds a string or blob, the Mem.z must point to exactly
60036 ** one of the following:
60037 **
60038 ** (1) Memory in Mem.zMalloc and managed by the Mem object
60039 ** (2) Memory to be freed using Mem.xDel
60040 ** (3) An ephermal string or blob
60041 ** (4) A static string or blob
60042 */
60043 if( (p->flags & (MEM_Str|MEM_Blob)) && p->z!=0 ){
60044 assert(
60045 ((p->z==p->zMalloc)? 1 : 0) +
60046 ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
60047 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
60048 ((p->flags&MEM_Static)!=0 ? 1 : 0) == 1
60049 );
60050 }
60051
60052 return 1;
60053 }
60054 #endif
60055
60056
60057 /*
60058 ** If pMem is an object with a valid string representation, this routine
60059 ** ensures the internal encoding for the string representation is
60060 ** 'desiredEnc', one of SQLITE_UTF8, SQLITE_UTF16LE or SQLITE_UTF16BE.
@@ -60051,16 +60101,11 @@
60101 ** pMem->z into the new allocation. pMem must be either a string or
60102 ** blob if bPreserve is true. If bPreserve is false, any prior content
60103 ** in pMem->z is discarded.
60104 */
60105 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
60106 assert( sqlite3VdbeCheckMemInvariants(pMem) );
 
 
 
 
 
60107 assert( (pMem->flags&MEM_RowSet)==0 );
60108
60109 /* If the bPreserve flag is set to true, then the memory cell must already
60110 ** contain a valid string or blob value. */
60111 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
@@ -60074,26 +60119,26 @@
60119 }else{
60120 sqlite3DbFree(pMem->db, pMem->zMalloc);
60121 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
60122 }
60123 if( pMem->zMalloc==0 ){
60124 VdbeMemRelease(pMem);
60125 pMem->flags = MEM_Null;
60126 return SQLITE_NOMEM;
60127 }
60128 }
60129
60130 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
60131 memcpy(pMem->zMalloc, pMem->z, pMem->n);
60132 }
60133 if( (pMem->flags&MEM_Dyn)!=0 ){
60134 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
60135 pMem->xDel((void *)(pMem->z));
60136 }
60137
60138 pMem->z = pMem->zMalloc;
60139 pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
60140 pMem->xDel = 0;
60141 return SQLITE_OK;
60142 }
60143
60144 /*
@@ -60258,13 +60303,13 @@
60303 assert( p->db==0 || sqlite3_mutex_held(p->db->mutex) );
60304 if( p->flags&MEM_Agg ){
60305 sqlite3VdbeMemFinalize(p, p->u.pDef);
60306 assert( (p->flags & MEM_Agg)==0 );
60307 sqlite3VdbeMemRelease(p);
60308 }else if( p->flags&MEM_Dyn ){
60309 assert( (p->flags&MEM_RowSet)==0 );
60310 assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
60311 p->xDel((void *)p->z);
60312 p->xDel = 0;
60313 }else if( p->flags&MEM_RowSet ){
60314 sqlite3RowSetClear(p->u.pRowSet);
60315 }else if( p->flags&MEM_Frame ){
@@ -60276,10 +60321,11 @@
60321 ** Release any memory held by the Mem. This may leave the Mem in an
60322 ** inconsistent state, for example with (Mem.z==0) and
60323 ** (Mem.memType==MEM_Str).
60324 */
60325 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60326 assert( sqlite3VdbeCheckMemInvariants(p) );
60327 VdbeMemRelease(p);
60328 if( p->zMalloc ){
60329 sqlite3DbFree(p->db, p->zMalloc);
60330 p->zMalloc = 0;
60331 }
@@ -60613,10 +60659,11 @@
60659
60660 assert( (pFrom->flags & MEM_RowSet)==0 );
60661 VdbeMemRelease(pTo);
60662 memcpy(pTo, pFrom, MEMCELLSIZE);
60663 pTo->flags &= ~MEM_Dyn;
60664 pTo->xDel = 0;
60665
60666 if( pTo->flags&(MEM_Str|MEM_Blob) ){
60667 if( 0==(pFrom->flags&MEM_Static) ){
60668 pTo->flags |= MEM_Ephem;
60669 rc = sqlite3VdbeMemMakeWriteable(pTo);
@@ -60738,123 +60785,10 @@
60785 }
60786
60787 return SQLITE_OK;
60788 }
60789
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60790 /*
60791 ** Move data out of a btree key or data field and into a Mem structure.
60792 ** The data or key is taken from the entry that pCur is currently pointing
60793 ** to. offset and amt determine what portion of the data or key to retrieve.
60794 ** key is true to get the key or false to get data. The result is written
@@ -60892,11 +60826,11 @@
60826 if( offset+amt<=available ){
60827 sqlite3VdbeMemRelease(pMem);
60828 pMem->z = &zData[offset];
60829 pMem->flags = MEM_Blob|MEM_Ephem;
60830 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60831 pMem->flags = MEM_Blob|MEM_Term;
60832 pMem->enc = 0;
60833 pMem->memType = MEM_Blob;
60834 if( key ){
60835 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60836 }else{
@@ -61010,11 +60944,10 @@
60944 if( pRec ){
60945 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
60946 if( pRec->pKeyInfo ){
60947 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
60948 assert( pRec->pKeyInfo->enc==ENC(db) );
 
60949 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
60950 for(i=0; i<nCol; i++){
60951 pRec->aMem[i].flags = MEM_Null;
60952 pRec->aMem[i].memType = MEM_Null;
60953 pRec->aMem[i].db = db;
@@ -62591,10 +62524,11 @@
62524 }
62525 return;
62526 }
62527 for(pEnd=&p[N]; p<pEnd; p++){
62528 assert( (&p[1])==pEnd || p[0].db==p[1].db );
62529 assert( sqlite3VdbeCheckMemInvariants(p) );
62530
62531 /* This block is really an inlined version of sqlite3VdbeMemRelease()
62532 ** that takes advantage of the fact that the memory cell value is
62533 ** being set to NULL after releasing any dynamic resources.
62534 **
@@ -62784,11 +62718,11 @@
62718
62719 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62720 assert( p->db->mallocFailed );
62721 return SQLITE_ERROR;
62722 }
62723 pMem->flags = MEM_Str|MEM_Term;
62724 zP4 = displayP4(pOp, pMem->z, 32);
62725 if( zP4!=pMem->z ){
62726 sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0);
62727 }else{
62728 assert( pMem->z!=0 );
@@ -62801,11 +62735,11 @@
62735 if( p->explain==1 ){
62736 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62737 assert( p->db->mallocFailed );
62738 return SQLITE_ERROR;
62739 }
62740 pMem->flags = MEM_Str|MEM_Term;
62741 pMem->n = 2;
62742 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62743 pMem->memType = MEM_Str;
62744 pMem->enc = SQLITE_UTF8;
62745 pMem++;
@@ -62813,11 +62747,11 @@
62747 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62748 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
62749 assert( p->db->mallocFailed );
62750 return SQLITE_ERROR;
62751 }
62752 pMem->flags = MEM_Str|MEM_Term;
62753 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62754 pMem->memType = MEM_Str;
62755 pMem->enc = SQLITE_UTF8;
62756 #else
62757 pMem->flags = MEM_Null; /* Comment */
@@ -64473,11 +64407,11 @@
64407 u32 idx; /* Offset in aKey[] to read from */
64408 u16 u; /* Unsigned loop counter */
64409 u32 szHdr;
64410 Mem *pMem = p->aMem;
64411
64412 p->default_rc = 0;
64413 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
64414 idx = getVarint32(aKey, szHdr);
64415 d = szHdr;
64416 u = 0;
64417 while( idx<szHdr && u<p->nField && d<=nKey ){
@@ -64494,30 +64428,22 @@
64428 }
64429 assert( u<=pKeyInfo->nField + 1 );
64430 p->nField = u;
64431 }
64432
64433 #if SQLITE_DEBUG
64434 /*
64435 ** This function compares two index or table record keys in the same way
64436 ** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
64437 ** this function deserializes and compares values using the
64438 ** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
64439 ** in assert() statements to ensure that the optimized code in
64440 ** sqlite3VdbeRecordCompare() returns results with these two primitives.
 
 
 
 
 
 
 
 
 
64441 */
64442 static int vdbeRecordCompareDebug(
64443 int nKey1, const void *pKey1, /* Left key */
64444 const UnpackedRecord *pPKey2 /* Right key */
64445 ){
64446 u32 d1; /* Offset into aKey[] of next data element */
64447 u32 idx1; /* Offset into aKey[] of next header element */
64448 u32 szHdr1; /* Number of bytes in header */
64449 int i = 0;
@@ -64587,28 +64513,552 @@
64513 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
64514 */
64515 assert( mem1.zMalloc==0 );
64516
64517 /* rc==0 here means that one of the keys ran out of fields and
64518 ** all the fields up to that point were equal. Return the the default_rc
64519 ** value. */
64520 return pPKey2->default_rc;
64521 }
64522 #endif
64523
64524 /*
64525 ** Both *pMem1 and *pMem2 contain string values. Compare the two values
64526 ** using the collation sequence pColl. As usual, return a negative , zero
64527 ** or positive value if *pMem1 is less than, equal to or greater than
64528 ** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
64529 */
64530 static int vdbeCompareMemString(
64531 const Mem *pMem1,
64532 const Mem *pMem2,
64533 const CollSeq *pColl
64534 ){
64535 if( pMem1->enc==pColl->enc ){
64536 /* The strings are already in the correct encoding. Call the
64537 ** comparison function directly */
64538 return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
64539 }else{
64540 int rc;
64541 const void *v1, *v2;
64542 int n1, n2;
64543 Mem c1;
64544 Mem c2;
64545 memset(&c1, 0, sizeof(c1));
64546 memset(&c2, 0, sizeof(c2));
64547 sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
64548 sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
64549 v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
64550 n1 = v1==0 ? 0 : c1.n;
64551 v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
64552 n2 = v2==0 ? 0 : c2.n;
64553 rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
64554 sqlite3VdbeMemRelease(&c1);
64555 sqlite3VdbeMemRelease(&c2);
64556 return rc;
64557 }
64558 }
64559
64560 /*
64561 ** Compare the values contained by the two memory cells, returning
64562 ** negative, zero or positive if pMem1 is less than, equal to, or greater
64563 ** than pMem2. Sorting order is NULL's first, followed by numbers (integers
64564 ** and reals) sorted numerically, followed by text ordered by the collating
64565 ** sequence pColl and finally blob's ordered by memcmp().
64566 **
64567 ** Two NULL values are considered equal by this function.
64568 */
64569 SQLITE_PRIVATE int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
64570 int rc;
64571 int f1, f2;
64572 int combined_flags;
64573
64574 f1 = pMem1->flags;
64575 f2 = pMem2->flags;
64576 combined_flags = f1|f2;
64577 assert( (combined_flags & MEM_RowSet)==0 );
64578
64579 /* If one value is NULL, it is less than the other. If both values
64580 ** are NULL, return 0.
64581 */
64582 if( combined_flags&MEM_Null ){
64583 return (f2&MEM_Null) - (f1&MEM_Null);
64584 }
64585
64586 /* If one value is a number and the other is not, the number is less.
64587 ** If both are numbers, compare as reals if one is a real, or as integers
64588 ** if both values are integers.
64589 */
64590 if( combined_flags&(MEM_Int|MEM_Real) ){
64591 double r1, r2;
64592 if( (f1 & f2 & MEM_Int)!=0 ){
64593 if( pMem1->u.i < pMem2->u.i ) return -1;
64594 if( pMem1->u.i > pMem2->u.i ) return 1;
64595 return 0;
64596 }
64597 if( (f1&MEM_Real)!=0 ){
64598 r1 = pMem1->r;
64599 }else if( (f1&MEM_Int)!=0 ){
64600 r1 = (double)pMem1->u.i;
64601 }else{
64602 return 1;
64603 }
64604 if( (f2&MEM_Real)!=0 ){
64605 r2 = pMem2->r;
64606 }else if( (f2&MEM_Int)!=0 ){
64607 r2 = (double)pMem2->u.i;
64608 }else{
64609 return -1;
64610 }
64611 if( r1<r2 ) return -1;
64612 if( r1>r2 ) return 1;
64613 return 0;
64614 }
64615
64616 /* If one value is a string and the other is a blob, the string is less.
64617 ** If both are strings, compare using the collating functions.
64618 */
64619 if( combined_flags&MEM_Str ){
64620 if( (f1 & MEM_Str)==0 ){
64621 return 1;
64622 }
64623 if( (f2 & MEM_Str)==0 ){
64624 return -1;
64625 }
64626
64627 assert( pMem1->enc==pMem2->enc );
64628 assert( pMem1->enc==SQLITE_UTF8 ||
64629 pMem1->enc==SQLITE_UTF16LE || pMem1->enc==SQLITE_UTF16BE );
64630
64631 /* The collation sequence must be defined at this point, even if
64632 ** the user deletes the collation sequence after the vdbe program is
64633 ** compiled (this was not always the case).
64634 */
64635 assert( !pColl || pColl->xCmp );
64636
64637 if( pColl ){
64638 return vdbeCompareMemString(pMem1, pMem2, pColl);
64639 }
64640 /* If a NULL pointer was passed as the collate function, fall through
64641 ** to the blob case and use memcmp(). */
64642 }
64643
64644 /* Both values must be blobs. Compare using memcmp(). */
64645 rc = memcmp(pMem1->z, pMem2->z, (pMem1->n>pMem2->n)?pMem2->n:pMem1->n);
64646 if( rc==0 ){
64647 rc = pMem1->n - pMem2->n;
64648 }
64649 return rc;
64650 }
64651
64652
64653 /*
64654 ** The first argument passed to this function is a serial-type that
64655 ** corresponds to an integer - all values between 1 and 9 inclusive
64656 ** except 7. The second points to a buffer containing an integer value
64657 ** serialized according to serial_type. This function deserializes
64658 ** and returns the value.
64659 */
64660 static i64 vdbeRecordDecodeInt(u32 serial_type, const u8 *aKey){
64661 assert( CORRUPT_DB || (serial_type>=1 && serial_type<=9 && serial_type!=7) );
64662 switch( serial_type ){
64663 case 0:
64664 case 1:
64665 return (char)aKey[0];
64666 case 2:
64667 return ((char)aKey[0] << 8) | aKey[1];
64668 case 3:
64669 return ((char)aKey[0] << 16) | (aKey[1] << 8) | aKey[2];
64670 case 4:
64671 return ((char)aKey[0]<<24) | (aKey[1]<<16) | (aKey[2]<<8)| aKey[3];
64672 case 5: {
64673 i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64674 u32 lsw = (aKey[4] << 8) | aKey[5];
64675 return (i64)( msw << 16 | (u64)lsw );
64676 }
64677 case 6: {
64678 i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64679 u32 lsw = ((unsigned)aKey[4]<<24)|(aKey[5]<<16)|(aKey[6]<<8)|aKey[7];
64680 return (i64)( msw << 32 | (u64)lsw );
64681 }
64682 }
64683
64684 return (serial_type - 8);
64685 }
64686
64687 /*
64688 ** This function compares the two table rows or index records
64689 ** specified by {nKey1, pKey1} and pPKey2. It returns a negative, zero
64690 ** or positive integer if key1 is less than, equal to or
64691 ** greater than key2. The {nKey1, pKey1} key must be a blob
64692 ** created by th OP_MakeRecord opcode of the VDBE. The pPKey2
64693 ** key must be a parsed key such as obtained from
64694 ** sqlite3VdbeParseRecord.
64695 **
64696 ** If argument bSkip is non-zero, it is assumed that the caller has already
64697 ** determined that the first fields of the keys are equal.
64698 **
64699 ** Key1 and Key2 do not have to contain the same number of fields. If all
64700 ** fields that appear in both keys are equal, then pPKey2->default_rc is
64701 ** returned.
64702 */
64703 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(
64704 int nKey1, const void *pKey1, /* Left key */
64705 const UnpackedRecord *pPKey2, /* Right key */
64706 int bSkip /* If true, skip the first field */
64707 ){
64708 u32 d1; /* Offset into aKey[] of next data element */
64709 int i; /* Index of next field to compare */
64710 int szHdr1; /* Size of record header in bytes */
64711 u32 idx1; /* Offset of first type in header */
64712 int rc = 0; /* Return value */
64713 Mem *pRhs = pPKey2->aMem; /* Next field of pPKey2 to compare */
64714 KeyInfo *pKeyInfo = pPKey2->pKeyInfo;
64715 const unsigned char *aKey1 = (const unsigned char *)pKey1;
64716 Mem mem1;
64717
64718 /* If bSkip is true, then the caller has already determined that the first
64719 ** two elements in the keys are equal. Fix the various stack variables so
64720 ** that this routine begins comparing at the second field. */
64721 if( bSkip ){
64722 u32 s1;
64723 idx1 = 1 + getVarint32(&aKey1[1], s1);
64724 szHdr1 = aKey1[0];
64725 d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
64726 i = 1;
64727 pRhs++;
64728 }else{
64729 idx1 = getVarint32(aKey1, szHdr1);
64730 d1 = szHdr1;
64731 i = 0;
64732 }
64733
64734 VVA_ONLY( mem1.zMalloc = 0; ) /* Only needed by assert() statements */
64735 assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
64736 || CORRUPT_DB );
64737 assert( pPKey2->pKeyInfo->aSortOrder!=0 );
64738 assert( pPKey2->pKeyInfo->nField>0 );
64739 assert( idx1<=szHdr1 || CORRUPT_DB );
64740 do{
64741 u32 serial_type;
64742
64743 /* RHS is an integer */
64744 if( pRhs->flags & MEM_Int ){
64745 serial_type = aKey1[idx1];
64746 if( serial_type>=12 ){
64747 rc = +1;
64748 }else if( serial_type==0 ){
64749 rc = -1;
64750 }else if( serial_type==7 ){
64751 double rhs = (double)pRhs->u.i;
64752 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64753 if( mem1.r<rhs ){
64754 rc = -1;
64755 }else if( mem1.r>rhs ){
64756 rc = +1;
64757 }
64758 }else{
64759 i64 lhs = vdbeRecordDecodeInt(serial_type, &aKey1[d1]);
64760 i64 rhs = pRhs->u.i;
64761 if( lhs<rhs ){
64762 rc = -1;
64763 }else if( lhs>rhs ){
64764 rc = +1;
64765 }
64766 }
64767 }
64768
64769 /* RHS is real */
64770 else if( pRhs->flags & MEM_Real ){
64771 serial_type = aKey1[idx1];
64772 if( serial_type>=12 ){
64773 rc = +1;
64774 }else if( serial_type==0 ){
64775 rc = -1;
64776 }else{
64777 double rhs = pRhs->r;
64778 double lhs;
64779 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
64780 if( serial_type==7 ){
64781 lhs = mem1.r;
64782 }else{
64783 lhs = (double)mem1.u.i;
64784 }
64785 if( lhs<rhs ){
64786 rc = -1;
64787 }else if( lhs>rhs ){
64788 rc = +1;
64789 }
64790 }
64791 }
64792
64793 /* RHS is a string */
64794 else if( pRhs->flags & MEM_Str ){
64795 getVarint32(&aKey1[idx1], serial_type);
64796 if( serial_type<12 ){
64797 rc = -1;
64798 }else if( !(serial_type & 0x01) ){
64799 rc = +1;
64800 }else{
64801 mem1.n = (serial_type - 12) / 2;
64802 if( (d1+mem1.n) > (unsigned)nKey1 ){
64803 rc = 1; /* Corruption */
64804 }else if( pKeyInfo->aColl[i] ){
64805 mem1.enc = pKeyInfo->enc;
64806 mem1.db = pKeyInfo->db;
64807 mem1.flags = MEM_Str;
64808 mem1.z = (char*)&aKey1[d1];
64809 rc = vdbeCompareMemString(&mem1, pRhs, pKeyInfo->aColl[i]);
64810 }else{
64811 int nCmp = MIN(mem1.n, pRhs->n);
64812 rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64813 if( rc==0 ) rc = mem1.n - pRhs->n;
64814 }
64815 }
64816 }
64817
64818 /* RHS is a blob */
64819 else if( pRhs->flags & MEM_Blob ){
64820 getVarint32(&aKey1[idx1], serial_type);
64821 if( serial_type<12 || (serial_type & 0x01) ){
64822 rc = -1;
64823 }else{
64824 int nStr = (serial_type - 12) / 2;
64825 if( (d1+nStr) > (unsigned)nKey1 ){
64826 rc = 1; /* Corruption */
64827 }else{
64828 int nCmp = MIN(nStr, pRhs->n);
64829 rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
64830 if( rc==0 ) rc = nStr - pRhs->n;
64831 }
64832 }
64833 }
64834
64835 /* RHS is null */
64836 else{
64837 serial_type = aKey1[idx1];
64838 rc = (serial_type!=0);
64839 }
64840
64841 if( rc!=0 ){
64842 if( pKeyInfo->aSortOrder[i] ){
64843 rc = -rc;
64844 }
64845 assert( CORRUPT_DB
64846 || (rc<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64847 || (rc>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64848 );
64849 assert( mem1.zMalloc==0 ); /* See comment below */
64850 return rc;
64851 }
64852
64853 i++;
64854 pRhs++;
64855 d1 += sqlite3VdbeSerialTypeLen(serial_type);
64856 idx1 += sqlite3VarintLen(serial_type);
64857 }while( idx1<(unsigned)szHdr1 && i<pPKey2->nField && d1<=(unsigned)nKey1 );
64858
64859 /* No memory allocation is ever used on mem1. Prove this using
64860 ** the following assert(). If the assert() fails, it indicates a
64861 ** memory leak and a need to call sqlite3VdbeMemRelease(&mem1). */
64862 assert( mem1.zMalloc==0 );
64863
64864 /* rc==0 here means that one or both of the keys ran out of fields and
64865 ** all the fields up to that point were equal. Return the the default_rc
64866 ** value. */
64867 assert( CORRUPT_DB
64868 || pPKey2->default_rc==vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)
64869 );
64870 return pPKey2->default_rc;
64871 }
64872
64873 /*
64874 ** This function is an optimized version of sqlite3VdbeRecordCompare()
64875 ** that (a) the first field of pPKey2 is an integer, and (b) the
64876 ** size-of-header varint at the start of (pKey1/nKey1) fits in a single
64877 ** byte (i.e. is less than 128).
64878 */
64879 static int vdbeRecordCompareInt(
64880 int nKey1, const void *pKey1, /* Left key */
64881 const UnpackedRecord *pPKey2, /* Right key */
64882 int bSkip /* Ignored */
64883 ){
64884 const u8 *aKey = &((const u8*)pKey1)[*(const u8*)pKey1 & 0x3F];
64885 int serial_type = ((const u8*)pKey1)[1];
64886 int res;
64887 i64 v = pPKey2->aMem[0].u.i;
64888 i64 lhs;
64889 UNUSED_PARAMETER(bSkip);
64890
64891 assert( bSkip==0 );
64892 switch( serial_type ){
64893 case 1:
64894 lhs = (char)(aKey[0]);
64895 break;
64896 case 2:
64897 lhs = 256*(signed char)aKey[0] + aKey[1];
64898 break;
64899 case 3:
64900 lhs = 65536*(char)aKey[0] | (aKey[1]<<8) | aKey[2];
64901 break;
64902 case 4:
64903 lhs = (int)(((u32)aKey[0]<<24) | (aKey[1]<<16) | (aKey[2]<<8)| aKey[3]);
64904 break;
64905 case 5: {
64906 i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64907 u32 lsw = (aKey[4] << 8) | aKey[5];
64908 lhs = (i64)( msw << 16 | (u64)lsw );
64909 break;
64910 }
64911 case 6: {
64912 i64 msw = ((char)aKey[0]<<24)|(aKey[1]<<16)|(aKey[2]<<8)|aKey[3];
64913 u32 lsw = ((unsigned)aKey[4]<<24)|(aKey[5]<<16)|(aKey[6]<<8)|aKey[7];
64914 lhs = (i64)( msw << 32 | (u64)lsw );
64915 break;
64916 }
64917 case 8:
64918 lhs = 0;
64919 break;
64920 case 9:
64921 lhs = 1;
64922 break;
64923
64924 /* This case could be removed without changing the results of running
64925 ** this code. Including it causes gcc to generate a faster switch
64926 ** statement (since the range of switch targets now starts at zero and
64927 ** is contiguous) but does not cause any duplicate code to be generated
64928 ** (as gcc is clever enough to combine the two like cases). Other
64929 ** compilers might be similar. */
64930 case 0: case 7:
64931 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64932
64933 default:
64934 return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 0);
64935 }
64936
64937 if( v>lhs ){
64938 res = pPKey2->r1;
64939 }else if( v<lhs ){
64940 res = pPKey2->r2;
64941 }else if( pPKey2->nField>1 ){
64942 /* The first fields of the two keys are equal. Compare the trailing
64943 ** fields. */
64944 res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
64945 }else{
64946 /* The first fields of the two keys are equal and there are no trailing
64947 ** fields. Return pPKey2->default_rc in this case. */
64948 res = pPKey2->default_rc;
64949 }
64950
64951 assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
64952 || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
64953 || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
64954 || CORRUPT_DB
64955 );
64956 return res;
64957 }
64958
64959 /*
64960 ** This function is an optimized version of sqlite3VdbeRecordCompare()
64961 ** that (a) the first field of pPKey2 is a string, that (b) the first field
64962 ** uses the collation sequence BINARY and (c) that the size-of-header varint
64963 ** at the start of (pKey1/nKey1) fits in a single byte.
64964 */
64965 static int vdbeRecordCompareString(
64966 int nKey1, const void *pKey1, /* Left key */
64967 const UnpackedRecord *pPKey2, /* Right key */
64968 int bSkip
64969 ){
64970 const u8 *aKey1 = (const u8*)pKey1;
64971 int serial_type;
64972 int res;
64973 UNUSED_PARAMETER(bSkip);
64974
64975 assert( bSkip==0 );
64976 getVarint32(&aKey1[1], serial_type);
64977
64978 if( serial_type<12 ){
64979 res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */
64980 }else if( !(serial_type & 0x01) ){
64981 res = pPKey2->r2; /* (pKey1/nKey1) is a blob */
64982 }else{
64983 int nCmp;
64984 int nStr;
64985 int szHdr = aKey1[0];
64986
64987 nStr = (serial_type-12) / 2;
64988 if( (szHdr + nStr) > nKey1 ) return 0; /* Corruption */
64989 nCmp = MIN( pPKey2->aMem[0].n, nStr );
64990 res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp);
64991
64992 if( res==0 ){
64993 res = nStr - pPKey2->aMem[0].n;
64994 if( res==0 ){
64995 if( pPKey2->nField>1 ){
64996 res = sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2, 1);
64997 }else{
64998 res = pPKey2->default_rc;
64999 }
65000 }else if( res>0 ){
65001 res = pPKey2->r2;
65002 }else{
65003 res = pPKey2->r1;
65004 }
65005 }else if( res>0 ){
65006 res = pPKey2->r2;
65007 }else{
65008 res = pPKey2->r1;
65009 }
65010 }
65011
65012 assert( (res==0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)==0)
65013 || (res<0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)<0)
65014 || (res>0 && vdbeRecordCompareDebug(nKey1, pKey1, pPKey2)>0)
65015 || CORRUPT_DB
65016 );
65017 return res;
65018 }
65019
65020 /*
65021 ** Return a pointer to an sqlite3VdbeRecordCompare() compatible function
65022 ** suitable for comparing serialized records to the unpacked record passed
65023 ** as the only argument.
65024 */
65025 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
65026 /* varintRecordCompareInt() and varintRecordCompareString() both assume
65027 ** that the size-of-header varint that occurs at the start of each record
65028 ** fits in a single byte (i.e. is 127 or less). varintRecordCompareInt()
65029 ** also assumes that it is safe to overread a buffer by at least the
65030 ** maximum possible legal header size plus 8 bytes. Because there is
65031 ** guaranteed to be at least 74 (but not 136) bytes of padding following each
65032 ** buffer passed to varintRecordCompareInt() this makes it convenient to
65033 ** limit the size of the header to 64 bytes in cases where the first field
65034 ** is an integer.
65035 **
65036 ** The easiest way to enforce this limit is to consider only records with
65037 ** 13 fields or less. If the first field is an integer, the maximum legal
65038 ** header size is (12*5 + 1 + 1) bytes. */
65039 if( (p->pKeyInfo->nField + p->pKeyInfo->nXField)<=13 ){
65040 int flags = p->aMem[0].flags;
65041 if( p->pKeyInfo->aSortOrder[0] ){
65042 p->r1 = 1;
65043 p->r2 = -1;
65044 }else{
65045 p->r1 = -1;
65046 p->r2 = 1;
65047 }
65048 if( (flags & MEM_Int) ){
65049 return vdbeRecordCompareInt;
65050 }
65051 if( (flags & (MEM_Int|MEM_Real|MEM_Null|MEM_Blob))==0
65052 && p->pKeyInfo->aColl[0]==0
65053 ){
65054 return vdbeRecordCompareString;
65055 }
65056 }
65057
65058 return sqlite3VdbeRecordCompare;
65059 }
65060
65061 /*
65062 ** pCur points at an index entry created using the OP_MakeRecord opcode.
65063 ** Read the rowid (the last field in the record) and store it in *rowid.
65064 ** Return SQLITE_OK if everything works, or an error code otherwise.
@@ -64695,23 +65145,23 @@
65145 ** omits the rowid at the end. The rowid at the end of the index entry
65146 ** is ignored as well. Hence, this routine only compares the prefixes
65147 ** of the keys prior to the final rowid, not the entire key.
65148 */
65149 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(
65150 VdbeCursor *pC, /* The cursor to compare against */
65151 const UnpackedRecord *pUnpacked, /* Unpacked version of key */
65152 int *res /* Write the comparison result here */
65153 ){
65154 i64 nCellKey = 0;
65155 int rc;
65156 BtCursor *pCur = pC->pCursor;
65157 Mem m;
65158
65159 assert( sqlite3BtreeCursorIsValid(pCur) );
65160 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCur, &nCellKey);
65161 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
65162 /* nCellKey will always be between 0 and 0xffffffff because of the way
65163 ** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
65164 if( nCellKey<=0 || nCellKey>0x7fffffff ){
65165 *res = 0;
65166 return SQLITE_CORRUPT_BKPT;
65167 }
@@ -64718,12 +65168,11 @@
65168 memset(&m, 0, sizeof(m));
65169 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
65170 if( rc ){
65171 return rc;
65172 }
65173 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked, 0);
 
65174 sqlite3VdbeMemRelease(&m);
65175 return SQLITE_OK;
65176 }
65177
65178 /*
@@ -66629,11 +67078,11 @@
67078 ** does not control the string, it might be deleted without the register
67079 ** knowing it.
67080 **
67081 ** This routine converts an ephemeral string into a dynamically allocated
67082 ** string that the register itself controls. In other words, it
67083 ** converts an MEM_Ephem string into a string with P.z==P.zMalloc.
67084 */
67085 #define Deephemeralize(P) \
67086 if( ((P)->flags&MEM_Ephem)!=0 \
67087 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
67088
@@ -67166,22 +67615,25 @@
67615 #ifdef SQLITE_DEBUG
67616 if( (pOp->opflags & OPFLG_IN1)!=0 ){
67617 assert( pOp->p1>0 );
67618 assert( pOp->p1<=(p->nMem-p->nCursor) );
67619 assert( memIsValid(&aMem[pOp->p1]) );
67620 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
67621 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
67622 }
67623 if( (pOp->opflags & OPFLG_IN2)!=0 ){
67624 assert( pOp->p2>0 );
67625 assert( pOp->p2<=(p->nMem-p->nCursor) );
67626 assert( memIsValid(&aMem[pOp->p2]) );
67627 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
67628 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
67629 }
67630 if( (pOp->opflags & OPFLG_IN3)!=0 ){
67631 assert( pOp->p3>0 );
67632 assert( pOp->p3<=(p->nMem-p->nCursor) );
67633 assert( memIsValid(&aMem[pOp->p3]) );
67634 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
67635 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
67636 }
67637 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
67638 assert( pOp->p2>0 );
67639 assert( pOp->p2<=(p->nMem-p->nCursor) );
@@ -67279,11 +67731,11 @@
67731 ** and then jump to address P2.
67732 */
67733 case OP_Gosub: { /* jump */
67734 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67735 pIn1 = &aMem[pOp->p1];
67736 assert( VdbeMemDynamic(pIn1)==0 );
67737 memAboutToChange(p, pIn1);
67738 pIn1->flags = MEM_Int;
67739 pIn1->u.i = pc;
67740 REGISTER_TRACE(pOp->p1, pIn1);
67741 pc = pOp->p2 - 1;
@@ -67352,11 +67804,11 @@
67804 ** OP_EndCoroutine, jump immediately to P2.
67805 */
67806 case OP_Yield: { /* in1, jump */
67807 int pcDest;
67808 pIn1 = &aMem[pOp->p1];
67809 assert( VdbeMemDynamic(pIn1)==0 );
67810 pIn1->flags = MEM_Int;
67811 pcDest = (int)pIn1->u.i;
67812 pIn1->u.i = pc;
67813 REGISTER_TRACE(pOp->p1, pIn1);
67814 pc = pcDest;
@@ -67525,14 +67977,13 @@
67977 if( encoding!=SQLITE_UTF8 ){
67978 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
67979 if( rc==SQLITE_TOOBIG ) goto too_big;
67980 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
67981 assert( pOut->zMalloc==pOut->z );
67982 assert( VdbeMemDynamic(pOut)==0 );
67983 pOut->zMalloc = 0;
67984 pOut->flags |= MEM_Static;
 
67985 if( pOp->p4type==P4_DYNAMIC ){
67986 sqlite3DbFree(db, pOp->p4.z);
67987 }
67988 pOp->p4type = P4_DYNAMIC;
67989 pOp->p4.z = pOut->z;
@@ -67664,18 +68115,20 @@
68115 do{
68116 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
68117 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
68118 assert( memIsValid(pIn1) );
68119 memAboutToChange(p, pOut);
68120 VdbeMemRelease(pOut);
68121 zMalloc = pOut->zMalloc;
68122 memcpy(pOut, pIn1, sizeof(Mem));
 
68123 #ifdef SQLITE_DEBUG
68124 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
68125 pOut->pScopyFrom += p1 - pOp->p2;
68126 }
68127 #endif
68128 pIn1->flags = MEM_Undefined;
68129 pIn1->xDel = 0;
68130 pIn1->zMalloc = zMalloc;
68131 REGISTER_TRACE(p2++, pOut);
68132 pIn1++;
68133 pOut++;
68134 }while( n-- );
@@ -67848,14 +68301,14 @@
68301 Stringify(pIn2, encoding);
68302 nByte = pIn1->n + pIn2->n;
68303 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
68304 goto too_big;
68305 }
 
68306 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
68307 goto no_mem;
68308 }
68309 MemSetTypeFlag(pOut, MEM_Str);
68310 if( pOut!=pIn2 ){
68311 memcpy(pOut->z, pIn2->z, pIn2->n);
68312 }
68313 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
68314 pOut->z[nByte]=0;
@@ -69026,10 +69479,11 @@
69479 ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
69480 ** all valid.
69481 */
69482 assert( p2<pC->nHdrParsed );
69483 assert( rc==SQLITE_OK );
69484 assert( sqlite3VdbeCheckMemInvariants(pDest) );
69485 if( pC->szRow>=aOffset[p2+1] ){
69486 /* This is the common case where the desired content fits on the original
69487 ** page - where the content is not on an overflow page */
69488 VdbeMemRelease(pDest);
69489 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
@@ -69063,12 +69517,12 @@
69517 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
69518 ** dynamically allocated space over to the pDest structure.
69519 ** This prevents a memory copy. */
69520 if( sMem.zMalloc ){
69521 assert( sMem.z==sMem.zMalloc );
69522 assert( VdbeMemDynamic(pDest)==0 );
69523 assert( (pDest->flags & (MEM_Blob|MEM_Str))==0 || pDest->z==sMem.z );
69524 pDest->flags &= ~(MEM_Ephem|MEM_Static);
69525 pDest->flags |= MEM_Term;
69526 pDest->z = sMem.z;
69527 pDest->zMalloc = sMem.zMalloc;
69528 }
@@ -69247,11 +69701,11 @@
69701 assert( i==nHdr );
69702 assert( j==nByte );
69703
69704 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69705 pOut->n = (int)nByte;
69706 pOut->flags = MEM_Blob;
69707 pOut->xDel = 0;
69708 if( nZero ){
69709 pOut->u.nZero = nZero;
69710 pOut->flags |= MEM_Zero;
69711 }
@@ -70121,20 +70575,20 @@
70575 r.pKeyInfo = pC->pKeyInfo;
70576 r.nField = (u16)nField;
70577
70578 /* The next line of code computes as follows, only faster:
70579 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70580 ** r.default_rc = -1;
70581 ** }else{
70582 ** r.default_rc = +1;
70583 ** }
70584 */
70585 r.default_rc = ((1 & (oc - OP_SeekLT)) ? -1 : +1);
70586 assert( oc!=OP_SeekGT || r.default_rc==-1 );
70587 assert( oc!=OP_SeekLE || r.default_rc==-1 );
70588 assert( oc!=OP_SeekGE || r.default_rc==+1 );
70589 assert( oc!=OP_SeekLT || r.default_rc==+1 );
70590
70591 r.aMem = &aMem[pOp->p3];
70592 #ifdef SQLITE_DEBUG
70593 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70594 #endif
@@ -70288,22 +70742,21 @@
70742 ExpandBlob(&r.aMem[ii]);
70743 #ifdef SQLITE_DEBUG
70744 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70745 #endif
70746 }
 
70747 pIdxKey = &r;
70748 }else{
70749 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70750 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
70751 );
70752 if( pIdxKey==0 ) goto no_mem;
70753 assert( pIn3->flags & MEM_Blob );
70754 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70755 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
 
70756 }
70757 pIdxKey->default_rc = 0;
70758 if( pOp->opcode==OP_NoConflict ){
70759 /* For the OP_NoConflict opcode, take the jump if any of the
70760 ** input fields are NULL, since any key with a NULL will not
70761 ** conflict */
70762 for(ii=0; ii<r.nField; ii++){
@@ -71188,11 +71641,11 @@
71641 pCrsr = pC->pCursor;
71642 assert( pCrsr!=0 );
71643 assert( pOp->p5==0 );
71644 r.pKeyInfo = pC->pKeyInfo;
71645 r.nField = (u16)pOp->p3;
71646 r.default_rc = 0;
71647 r.aMem = &aMem[pOp->p2];
71648 #ifdef SQLITE_DEBUG
71649 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71650 #endif
71651 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
@@ -71302,14 +71755,14 @@
71755 assert( pOp->p4type==P4_INT32 );
71756 r.pKeyInfo = pC->pKeyInfo;
71757 r.nField = (u16)pOp->p4.i;
71758 if( pOp->opcode<OP_IdxLT ){
71759 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71760 r.default_rc = -1;
71761 }else{
71762 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71763 r.default_rc = 0;
71764 }
71765 r.aMem = &aMem[pOp->p3];
71766 #ifdef SQLITE_DEBUG
71767 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71768 #endif
@@ -73809,14 +74262,14 @@
74262 if( r2->aMem[i].flags & MEM_Null ){
74263 *pRes = -1;
74264 return;
74265 }
74266 }
74267 assert( r2->default_rc==0 );
74268 }
74269
74270 *pRes = sqlite3VdbeRecordCompare(nKey1, pKey1, r2, 0);
74271 }
74272
74273 /*
74274 ** This function is called to compare two iterator keys when merging
74275 ** multiple b-tree segments. Parameter iOut is the index of the aTree[]
@@ -100117,11 +100570,11 @@
100570 }else if( eDest!=SRT_Exists ){
100571 /* If the destination is an EXISTS(...) expression, the actual
100572 ** values returned by the SELECT are not required.
100573 */
100574 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100575 (eDest==SRT_Output||eDest==SRT_Coroutine)?SQLITE_ECEL_DUP:0);
100576 }
100577
100578 /* If the DISTINCT keyword was present on the SELECT statement
100579 ** and this row has been seen before, then do not make this row
100580 ** part of the result.
@@ -110767,11 +111220,11 @@
111220 iCol = pRec->nField - 1;
111221 assert( pIdx->nSample>0 );
111222 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
111223 do{
111224 iTest = (iMin+i)/2;
111225 res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec, 0);
111226 if( res<0 ){
111227 iMin = iTest+1;
111228 }else{
111229 i = iTest;
111230 }
@@ -110782,20 +111235,20 @@
111235 ** above found the right answer. This block serves no purpose other
111236 ** than to invoke the asserts. */
111237 if( res==0 ){
111238 /* If (res==0) is true, then sample $i must be equal to pRec */
111239 assert( i<pIdx->nSample );
111240 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)
111241 || pParse->db->mallocFailed );
111242 }else{
111243 /* Otherwise, pRec must be smaller than sample $i and larger than
111244 ** sample ($i-1). */
111245 assert( i==pIdx->nSample
111246 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec, 0)>0
111247 || pParse->db->mallocFailed );
111248 assert( i==0
111249 || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec, 0)<0
111250 || pParse->db->mallocFailed );
111251 }
111252 #endif /* ifdef SQLITE_DEBUG */
111253
111254 /* At this point, aSample[i] is the first sample that is greater than
@@ -114724,11 +115177,11 @@
115177
115178 /* For a co-routine, change all OP_Column references to the table of
115179 ** the co-routine into OP_SCopy of result contained in a register.
115180 ** OP_Rowid becomes OP_Null.
115181 */
115182 if( pTabItem->viaCoroutine && !db->mallocFailed ){
115183 last = sqlite3VdbeCurrentAddr(v);
115184 k = pLevel->addrBody;
115185 pOp = sqlite3VdbeGetOp(v, k);
115186 for(; k<last; k++, pOp++){
115187 if( pOp->p1!=pLevel->iTabCur ) continue;
115188
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.4"
111111
#define SQLITE_VERSION_NUMBER 3008004
112
-#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
112
+#define SQLITE_SOURCE_ID "2014-03-03 21:59:33 aec5473a750e412eb1e11e17bbafd760db086c86"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.4"
111 #define SQLITE_VERSION_NUMBER 3008004
112 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.4"
111 #define SQLITE_VERSION_NUMBER 3008004
112 #define SQLITE_SOURCE_ID "2014-03-03 21:59:33 aec5473a750e412eb1e11e17bbafd760db086c86"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

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