Fossil SCM

Use the latest SQLite 3.8.3 alpha from upstream.

drh 2014-01-04 16:17 trunk
Commit da90bbe591a535533c9ce82a0609756e66f279d1
2 files changed +167 -73 +7 -5
+167 -73
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138138
#define SQLITE_VERSION "3.8.3"
139139
#define SQLITE_VERSION_NUMBER 3008003
140
-#define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d"
140
+#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -2426,15 +2426,17 @@
24262426
** already uses the largest possible [ROWID]. The PRNG is also used for
24272427
** the build-in random() and randomblob() SQL functions. This interface allows
24282428
** applications to access the same PRNG for other purposes.
24292429
**
24302430
** ^A call to this routine stores N bytes of randomness into buffer P.
2431
+** ^If N is less than one, then P can be a NULL pointer.
24312432
**
2432
-** ^The first time this routine is invoked (either internally or by
2433
-** the application) the PRNG is seeded using randomness obtained
2434
-** from the xRandomness method of the default [sqlite3_vfs] object.
2435
-** ^On all subsequent invocations, the pseudo-randomness is generated
2433
+** ^If this routine has not been previously called or if the previous
2434
+** call had N less than one, then the PRNG is seeded using randomness
2435
+** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2436
+** ^If the previous call to this routine had an N of 1 or more then
2437
+** the pseudo-randomness is generated
24362438
** internally and without recourse to the [sqlite3_vfs] xRandomness
24372439
** method.
24382440
*/
24392441
SQLITE_API void sqlite3_randomness(int N, void *P);
24402442
@@ -9278,10 +9280,11 @@
92789280
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
92799281
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
92809282
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
92819283
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
92829284
SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
9285
+SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*);
92839286
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
92849287
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
92859288
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
92869289
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
92879290
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
@@ -10371,11 +10374,11 @@
1037110374
*/
1037210375
#define SQLITE_QueryFlattener 0x0001 /* Query flattening */
1037310376
#define SQLITE_ColumnCache 0x0002 /* Column cache */
1037410377
#define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
1037510378
#define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10376
-#define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
10379
+/* not used 0x0010 // Was: SQLITE_IdxRealAsInt */
1037710380
#define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
1037810381
#define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1037910382
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1038010383
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1038110384
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
@@ -11605,10 +11608,13 @@
1160511608
int nErr; /* Number of errors seen */
1160611609
int nTab; /* Number of previously allocated VDBE cursors */
1160711610
int nMem; /* Number of memory cells used so far */
1160811611
int nSet; /* Number of sets used so far */
1160911612
int nOnce; /* Number of OP_Once instructions so far */
11613
+ int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11614
+ int nLabel; /* Number of labels used */
11615
+ int *aLabel; /* Space to hold the labels */
1161011616
int ckBase; /* Base register of data during check constraints */
1161111617
int iPartIdxTab; /* Table corresponding to a partial index */
1161211618
int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
1161311619
int iCacheCnt; /* Counter used to generate aColCache[].lru values */
1161411620
struct yColCache {
@@ -12284,11 +12290,10 @@
1228412290
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
1228512291
SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
1228612292
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
1228712293
SQLITE_PRIVATE void sqlite3PrngSaveState(void);
1228812294
SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
12289
-SQLITE_PRIVATE void sqlite3PrngResetState(void);
1229012295
SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
1229112296
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
1229212297
SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
1229312298
SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
1229412299
SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
@@ -13776,19 +13781,13 @@
1377613781
Op *aOp; /* Space to hold the virtual machine's program */
1377713782
Mem *aMem; /* The memory locations */
1377813783
Mem **apArg; /* Arguments to currently executing user function */
1377913784
Mem *aColName; /* Column names to return */
1378013785
Mem *pResultSet; /* Pointer to an array of results */
13781
-#ifdef SQLITE_DEBUG
1378213786
Parse *pParse; /* Parsing context used to create this Vdbe */
13783
-#endif
1378413787
int nMem; /* Number of memory locations currently allocated */
1378513788
int nOp; /* Number of instructions in the program */
13786
- int nOpAlloc; /* Number of slots allocated for aOp[] */
13787
- int nLabel; /* Number of labels used */
13788
- int *aLabel; /* Space to hold the labels */
13789
- u16 nResColumn; /* Number of columns in one row of the result set */
1379013789
int nCursor; /* Number of slots in apCsr[] */
1379113790
u32 magic; /* Magic number for sanity checking */
1379213791
char *zErrMsg; /* Error message written here */
1379313792
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
1379413793
VdbeCursor **apCsr; /* One element of this array for each open cursor */
@@ -13797,10 +13796,11 @@
1379713796
ynVar nVar; /* Number of entries in aVar[] */
1379813797
ynVar nzVar; /* Number of entries in azVar[] */
1379913798
u32 cacheCtr; /* VdbeCursor row cache generation counter */
1380013799
int pc; /* The program counter */
1380113800
int rc; /* Value to return */
13801
+ u16 nResColumn; /* Number of columns in one row of the result set */
1380213802
u8 errorAction; /* Recovery action to do in case of an error */
1380313803
u8 minWriteFileFormat; /* Minimum file format for writable database files */
1380413804
bft explain:2; /* True if EXPLAIN present on SQL command */
1380513805
bft inVtabMethod:2; /* See comments above */
1380613806
bft changeCntOn:1; /* True to update the change-counter */
@@ -20901,10 +20901,16 @@
2090120901
2090220902
#if SQLITE_THREADSAFE
2090320903
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
2090420904
sqlite3_mutex_enter(mutex);
2090520905
#endif
20906
+
20907
+ if( N<=0 ){
20908
+ wsdPrng.isInit = 0;
20909
+ sqlite3_mutex_leave(mutex);
20910
+ return;
20911
+ }
2090620912
2090720913
/* Initialize the state of the random number generator once,
2090820914
** the first time this routine is called. The seed value does
2090920915
** not need to contain a lot of randomness since we are not
2091020916
** trying to do secure encryption or anything like that...
@@ -20929,19 +20935,20 @@
2092920935
wsdPrng.s[i] = t;
2093020936
}
2093120937
wsdPrng.isInit = 1;
2093220938
}
2093320939
20934
- while( N-- ){
20940
+ assert( N>0 );
20941
+ do{
2093520942
wsdPrng.i++;
2093620943
t = wsdPrng.s[wsdPrng.i];
2093720944
wsdPrng.j += t;
2093820945
wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
2093920946
wsdPrng.s[wsdPrng.j] = t;
2094020947
t += wsdPrng.s[wsdPrng.i];
2094120948
*(zBuf++) = wsdPrng.s[t];
20942
- }
20949
+ }while( --N );
2094320950
sqlite3_mutex_leave(mutex);
2094420951
}
2094520952
2094620953
#ifndef SQLITE_OMIT_BUILTIN_TEST
2094720954
/*
@@ -20966,13 +20973,10 @@
2096620973
&GLOBAL(struct sqlite3PrngType, sqlite3Prng),
2096720974
&GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
2096820975
sizeof(sqlite3Prng)
2096920976
);
2097020977
}
20971
-SQLITE_PRIVATE void sqlite3PrngResetState(void){
20972
- GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0;
20973
-}
2097420978
#endif /* SQLITE_OMIT_BUILTIN_TEST */
2097520979
2097620980
/************** End of random.c **********************************************/
2097720981
/************** Begin file utf.c *********************************************/
2097820982
/*
@@ -23505,10 +23509,16 @@
2350523509
** it is larger than the struct CrashFile defined in test6.c.
2350623510
*/
2350723511
char aPadding[32];
2350823512
#endif
2350923513
};
23514
+
23515
+/* This variable holds the process id (pid) from when the xRandomness()
23516
+** method was called. If xOpen() is called from a different process id,
23517
+** indicating that a fork() has occurred, the PRNG will be reset.
23518
+*/
23519
+static int randomnessPid = 0;
2351023520
2351123521
/*
2351223522
** Allowed values for the unixFile.ctrlFlags bitmask:
2351323523
*/
2351423524
#define UNIXFILE_EXCL 0x01 /* Connections from one process only */
@@ -29104,10 +29114,20 @@
2910429114
assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
2910529115
|| eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
2910629116
|| eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
2910729117
|| eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
2910829118
);
29119
+
29120
+ /* Detect a pid change and reset the PRNG. There is a race condition
29121
+ ** here such that two or more threads all trying to open databases at
29122
+ ** the same instant might all reset the PRNG. But multiple resets
29123
+ ** are harmless.
29124
+ */
29125
+ if( randomnessPid!=getpid() ){
29126
+ randomnessPid = getpid();
29127
+ sqlite3_randomness(0,0);
29128
+ }
2910929129
2911029130
memset(p, 0, sizeof(unixFile));
2911129131
2911229132
if( eType==SQLITE_OPEN_MAIN_DB ){
2911329133
UnixUnusedFd *pUnused;
@@ -29492,22 +29512,22 @@
2949229512
** When testing, initializing zBuf[] to zero is all we do. That means
2949329513
** that we always use the same random number sequence. This makes the
2949429514
** tests repeatable.
2949529515
*/
2949629516
memset(zBuf, 0, nBuf);
29517
+ randomnessPid = getpid();
2949729518
#if !defined(SQLITE_TEST)
2949829519
{
29499
- int pid, fd, got;
29520
+ int fd, got;
2950029521
fd = robust_open("/dev/urandom", O_RDONLY, 0);
2950129522
if( fd<0 ){
2950229523
time_t t;
2950329524
time(&t);
2950429525
memcpy(zBuf, &t, sizeof(t));
29505
- pid = getpid();
29506
- memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
29507
- assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
29508
- nBuf = sizeof(t) + sizeof(pid);
29526
+ memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid));
29527
+ assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf );
29528
+ nBuf = sizeof(t) + sizeof(randomnessPid);
2950929529
}else{
2951029530
do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
2951129531
robust_close(0, fd, __LINE__);
2951229532
}
2951329533
}
@@ -61200,13 +61220,14 @@
6120061220
}
6120161221
p->pNext = db->pVdbe;
6120261222
p->pPrev = 0;
6120361223
db->pVdbe = p;
6120461224
p->magic = VDBE_MAGIC_INIT;
61205
-#if SQLITE_DEBUG
6120661225
p->pParse = pParse;
61207
-#endif
61226
+ assert( pParse->aLabel==0 );
61227
+ assert( pParse->nLabel==0 );
61228
+ assert( pParse->nOpAlloc==0 );
6120861229
return p;
6120961230
}
6121061231
6121161232
/*
6121261233
** Remember the SQL string for a prepared statement.
@@ -61258,17 +61279,18 @@
6125861279
** If an out-of-memory error occurs while resizing the array, return
6125961280
** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
6126061281
** unchanged (this is so that any opcodes already allocated can be
6126161282
** correctly deallocated along with the rest of the Vdbe).
6126261283
*/
61263
-static int growOpArray(Vdbe *p){
61284
+static int growOpArray(Vdbe *v){
6126461285
VdbeOp *pNew;
61286
+ Parse *p = v->pParse;
6126561287
int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
61266
- pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
61288
+ pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
6126761289
if( pNew ){
6126861290
p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
61269
- p->aOp = pNew;
61291
+ v->aOp = pNew;
6127061292
}
6127161293
return (pNew ? SQLITE_OK : SQLITE_NOMEM);
6127261294
}
6127361295
6127461296
#ifdef SQLITE_DEBUG
@@ -61303,11 +61325,11 @@
6130361325
VdbeOp *pOp;
6130461326
6130561327
i = p->nOp;
6130661328
assert( p->magic==VDBE_MAGIC_INIT );
6130761329
assert( op>0 && op<0xff );
61308
- if( p->nOpAlloc<=i ){
61330
+ if( p->pParse->nOpAlloc<=i ){
6130961331
if( growOpArray(p) ){
6131061332
return 1;
6131161333
}
6131261334
}
6131361335
p->nOp++;
@@ -61414,13 +61436,14 @@
6141461436
** always negative and P2 values are suppose to be non-negative.
6141561437
** Hence, a negative P2 value is a label that has yet to be resolved.
6141661438
**
6141761439
** Zero is returned if a malloc() fails.
6141861440
*/
61419
-SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){
61441
+SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){
61442
+ Parse *p = v->pParse;
6142061443
int i = p->nLabel++;
61421
- assert( p->magic==VDBE_MAGIC_INIT );
61444
+ assert( v->magic==VDBE_MAGIC_INIT );
6142261445
if( (i & (i-1))==0 ){
6142361446
p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
6142461447
(i*2+1)*sizeof(p->aLabel[0]));
6142561448
}
6142661449
if( p->aLabel ){
@@ -61432,16 +61455,17 @@
6143261455
/*
6143361456
** Resolve label "x" to be the address of the next instruction to
6143461457
** be inserted. The parameter "x" must have been obtained from
6143561458
** a prior call to sqlite3VdbeMakeLabel().
6143661459
*/
61437
-SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){
61460
+SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
61461
+ Parse *p = v->pParse;
6143861462
int j = -1-x;
61439
- assert( p->magic==VDBE_MAGIC_INIT );
61463
+ assert( v->magic==VDBE_MAGIC_INIT );
6144061464
assert( j<p->nLabel );
6144161465
if( j>=0 && p->aLabel ){
61442
- p->aLabel[j] = p->nOp;
61466
+ p->aLabel[j] = v->nOp;
6144361467
}
6144461468
}
6144561469
6144661470
/*
6144761471
** Mark the VDBE as one that can only be run one time.
@@ -61586,11 +61610,12 @@
6158661610
*/
6158761611
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
6158861612
int i;
6158961613
int nMaxArgs = *pMaxFuncArgs;
6159061614
Op *pOp;
61591
- int *aLabel = p->aLabel;
61615
+ Parse *pParse = p->pParse;
61616
+ int *aLabel = pParse->aLabel;
6159261617
p->readOnly = 1;
6159361618
p->bIsReader = 0;
6159461619
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
6159561620
u8 opcode = pOp->opcode;
6159661621
@@ -61649,16 +61674,17 @@
6164961674
}
6165061675
}
6165161676
6165261677
pOp->opflags = sqlite3OpcodeProperty[opcode];
6165361678
if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
61654
- assert( -1-pOp->p2<p->nLabel );
61679
+ assert( -1-pOp->p2<pParse->nLabel );
6165561680
pOp->p2 = aLabel[-1-pOp->p2];
6165661681
}
6165761682
}
61658
- sqlite3DbFree(p->db, p->aLabel);
61659
- p->aLabel = 0;
61683
+ sqlite3DbFree(p->db, pParse->aLabel);
61684
+ pParse->aLabel = 0;
61685
+ pParse->nLabel = 0;
6166061686
*pMaxFuncArgs = nMaxArgs;
6166161687
assert( p->bIsReader!=0 || p->btreeMask==0 );
6166261688
}
6166361689
6166461690
/*
@@ -61698,11 +61724,11 @@
6169861724
** address of the first operation added.
6169961725
*/
6170061726
SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
6170161727
int addr;
6170261728
assert( p->magic==VDBE_MAGIC_INIT );
61703
- if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){
61729
+ if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
6170461730
return 0;
6170561731
}
6170661732
addr = p->nOp;
6170761733
if( ALWAYS(nOp>0) ){
6170861734
int i;
@@ -61886,10 +61912,17 @@
6188661912
memset(pOp, 0, sizeof(pOp[0]));
6188761913
pOp->opcode = OP_Noop;
6188861914
if( addr==p->nOp-1 ) p->nOp--;
6188961915
}
6189061916
}
61917
+
61918
+/*
61919
+** Remove the last opcode inserted
61920
+*/
61921
+SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){
61922
+ p->nOp--;
61923
+}
6189161924
6189261925
/*
6189361926
** Change the value of the P4 operand for a specific instruction.
6189461927
** This routine is useful when a large program is loaded from a
6189561928
** static array using sqlite3VdbeAddOpList but we want to make a
@@ -62768,10 +62801,11 @@
6276862801
6276962802
assert( p!=0 );
6277062803
assert( p->nOp>0 );
6277162804
assert( pParse!=0 );
6277262805
assert( p->magic==VDBE_MAGIC_INIT );
62806
+ assert( pParse==p->pParse );
6277362807
db = p->db;
6277462808
assert( db->mallocFailed==0 );
6277562809
nVar = pParse->nVar;
6277662810
nMem = pParse->nMem;
6277762811
nCursor = pParse->nTab;
@@ -62791,12 +62825,12 @@
6279162825
nMem += nCursor;
6279262826
6279362827
/* Allocate space for memory registers, SQL variables, VDBE cursors and
6279462828
** an array to marshal SQL function arguments in.
6279562829
*/
62796
- zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62797
- zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */
62830
+ zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62831
+ zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */
6279862832
6279962833
resolveP2Values(p, &nArg);
6280062834
p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
6280162835
if( pParse->explain && nMem<10 ){
6280262836
nMem = 10;
@@ -63795,11 +63829,10 @@
6379563829
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
6379663830
sqlite3DbFree(db, pSub);
6379763831
}
6379863832
for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
6379963833
vdbeFreeOpArray(db, p->aOp, p->nOp);
63800
- sqlite3DbFree(db, p->aLabel);
6380163834
sqlite3DbFree(db, p->aColName);
6380263835
sqlite3DbFree(db, p->zSql);
6380363836
sqlite3DbFree(db, p->pFree);
6380463837
#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
6380563838
sqlite3DbFree(db, p->zExplain);
@@ -76765,20 +76798,29 @@
7676576798
}
7676676799
return p;
7676776800
}
7676876801
7676976802
/*
76770
-** Return 1 if an expression must be FALSE in all cases and 0 if the
76771
-** expression might be true. This is an optimization. If is OK to
76772
-** return 0 here even if the expression really is always false (a
76773
-** false negative). But it is a bug to return 1 if the expression
76774
-** might be true in some rare circumstances (a false positive.)
76803
+** If the expression is always either TRUE or FALSE (respectively),
76804
+** then return 1. If one cannot determine the truth value of the
76805
+** expression at compile-time return 0.
76806
+**
76807
+** This is an optimization. If is OK to return 0 here even if
76808
+** the expression really is always false or false (a false negative).
76809
+** But it is a bug to return 1 if the expression might have different
76810
+** boolean values in different circumstances (a false positive.)
7677576811
**
7677676812
** Note that if the expression is part of conditional for a
7677776813
** LEFT JOIN, then we cannot determine at compile-time whether or not
7677876814
** is it true or false, so always return 0.
7677976815
*/
76816
+static int exprAlwaysTrue(Expr *p){
76817
+ int v = 0;
76818
+ if( ExprHasProperty(p, EP_FromJoin) ) return 0;
76819
+ if( !sqlite3ExprIsInteger(p, &v) ) return 0;
76820
+ return v!=0;
76821
+}
7678076822
static int exprAlwaysFalse(Expr *p){
7678176823
int v = 0;
7678276824
if( ExprHasProperty(p, EP_FromJoin) ) return 0;
7678376825
if( !sqlite3ExprIsInteger(p, &v) ) return 0;
7678476826
return v==0;
@@ -79621,11 +79663,11 @@
7962179663
sqlite3ExplainPush(pOut);
7962279664
for(i=0; i<pList->nExpr; i++){
7962379665
sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
7962479666
sqlite3ExplainPush(pOut);
7962579667
sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
79626
- sqlite3ExplainPop(pOut);
79668
+ sqlite3ExplainPop(pOut, 1);
7962779669
if( pList->a[i].zName ){
7962879670
sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
7962979671
}
7963079672
if( pList->a[i].bSpanIsTab ){
7963179673
sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
@@ -79771,21 +79813,23 @@
7977179813
op = pExpr->op;
7977279814
switch( op ){
7977379815
case TK_AND: {
7977479816
int d2 = sqlite3VdbeMakeLabel(v);
7977579817
testcase( jumpIfNull==0 );
79776
- sqlite3ExprCachePush(pParse);
7977779818
sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
79819
+ sqlite3ExprCachePush(pParse);
7977879820
sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
7977979821
sqlite3VdbeResolveLabel(v, d2);
7978079822
sqlite3ExprCachePop(pParse, 1);
7978179823
break;
7978279824
}
7978379825
case TK_OR: {
7978479826
testcase( jumpIfNull==0 );
7978579827
sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
79828
+ sqlite3ExprCachePush(pParse);
7978679829
sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
79830
+ sqlite3ExprCachePop(pParse, 1);
7978779831
break;
7978879832
}
7978979833
case TK_NOT: {
7979079834
testcase( jumpIfNull==0 );
7979179835
sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
@@ -79856,14 +79900,20 @@
7985679900
sqlite3VdbeResolveLabel(v, destIfFalse);
7985779901
break;
7985879902
}
7985979903
#endif
7986079904
default: {
79861
- r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
79862
- sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
79863
- testcase( regFree1==0 );
79864
- testcase( jumpIfNull==0 );
79905
+ if( exprAlwaysTrue(pExpr) ){
79906
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
79907
+ }else if( exprAlwaysFalse(pExpr) ){
79908
+ /* No-op */
79909
+ }else{
79910
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
79911
+ sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
79912
+ testcase( regFree1==0 );
79913
+ testcase( jumpIfNull==0 );
79914
+ }
7986579915
break;
7986679916
}
7986779917
}
7986879918
sqlite3ReleaseTempReg(pParse, regFree1);
7986979919
sqlite3ReleaseTempReg(pParse, regFree2);
@@ -79922,18 +79972,20 @@
7992279972
7992379973
switch( pExpr->op ){
7992479974
case TK_AND: {
7992579975
testcase( jumpIfNull==0 );
7992679976
sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
79977
+ sqlite3ExprCachePush(pParse);
7992779978
sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
79979
+ sqlite3ExprCachePop(pParse, 1);
7992879980
break;
7992979981
}
7993079982
case TK_OR: {
7993179983
int d2 = sqlite3VdbeMakeLabel(v);
7993279984
testcase( jumpIfNull==0 );
79933
- sqlite3ExprCachePush(pParse);
7993479985
sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
79986
+ sqlite3ExprCachePush(pParse);
7993579987
sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
7993679988
sqlite3VdbeResolveLabel(v, d2);
7993779989
sqlite3ExprCachePop(pParse, 1);
7993879990
break;
7993979991
}
@@ -80001,14 +80053,20 @@
8000180053
}
8000280054
break;
8000380055
}
8000480056
#endif
8000580057
default: {
80006
- r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80007
- sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80008
- testcase( regFree1==0 );
80009
- testcase( jumpIfNull==0 );
80058
+ if( exprAlwaysFalse(pExpr) ){
80059
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
80060
+ }else if( exprAlwaysTrue(pExpr) ){
80061
+ /* no-op */
80062
+ }else{
80063
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80064
+ sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80065
+ testcase( regFree1==0 );
80066
+ testcase( jumpIfNull==0 );
80067
+ }
8001080068
break;
8001180069
}
8001280070
}
8001380071
sqlite3ReleaseTempReg(pParse, regFree1);
8001480072
sqlite3ReleaseTempReg(pParse, regFree2);
@@ -89357,22 +89415,22 @@
8935789415
nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
8935889416
regBase = sqlite3GetTempRange(pParse, nCol);
8935989417
for(j=0; j<nCol; j++){
8936089418
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
8936189419
regBase+j);
89420
+ /* If the column affinity is REAL but the number is an integer, then it
89421
+ ** might be stored in the table as an integer (using a compact
89422
+ ** representation) then converted to REAL by an OP_RealAffinity opcode.
89423
+ ** But we are getting ready to store this value back into an index, where
89424
+ ** it should be converted by to INTEGER again. So omit the OP_RealAffinity
89425
+ ** opcode if it is present */
89426
+ if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){
89427
+ sqlite3VdbeDeleteLastOpcode(v);
89428
+ }
8936289429
}
8936389430
if( regOut ){
89364
- const char *zAff;
89365
- if( pTab->pSelect
89366
- || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
89367
- ){
89368
- zAff = 0;
89369
- }else{
89370
- zAff = sqlite3IndexAffinityStr(v, pIdx);
89371
- }
8937289431
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
89373
- sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
8937489432
}
8937589433
sqlite3ReleaseTempRange(pParse, regBase, nCol);
8937689434
return regBase;
8937789435
}
8937889436
@@ -93721,10 +93779,11 @@
9372193779
int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
9372293780
int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
9372393781
int ipkTop = 0; /* Top of the rowid change constraint check */
9372493782
int ipkBottom = 0; /* Bottom of the rowid change constraint check */
9372593783
u8 isUpdate; /* True if this is an UPDATE operation */
93784
+ int regRowid = -1; /* Register holding ROWID value */
9372693785
9372793786
isUpdate = regOldData!=0;
9372893787
db = pParse->db;
9372993788
v = sqlite3GetVdbe(pParse);
9373093789
assert( v!=0 );
@@ -93951,11 +94010,13 @@
9395194010
regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
9395294011
for(i=0; i<pIdx->nColumn; i++){
9395394012
int iField = pIdx->aiColumn[i];
9395494013
int x;
9395594014
if( iField<0 || iField==pTab->iPKey ){
94015
+ if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
9395694016
x = regNewData;
94017
+ regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
9395794018
}else{
9395894019
x = iField + regNewData + 1;
9395994020
}
9396094021
sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
9396194022
VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
@@ -98780,11 +98841,15 @@
9878098841
9878198842
/*
9878298843
** Free all memory allocations in the pParse object
9878398844
*/
9878498845
SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
98785
- if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
98846
+ if( pParse ){
98847
+ sqlite3 *db = pParse->db;
98848
+ sqlite3DbFree(db, pParse->aLabel);
98849
+ sqlite3ExprListDelete(db, pParse->pConstExpr);
98850
+ }
9878698851
}
9878798852
9878898853
/*
9878998854
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
9879098855
*/
@@ -113528,13 +113593,16 @@
113528113593
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113529113594
113530113595
/* Special case: a WHERE clause that is constant. Evaluate the
113531113596
** expression and either jump over all of the code or fall thru.
113532113597
*/
113533
- if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
113534
- sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);
113535
- pWhere = 0;
113598
+ for(ii=0; ii<sWLB.pWC->nTerm; ii++){
113599
+ if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){
113600
+ sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak,
113601
+ SQLITE_JUMPIFNULL);
113602
+ sWLB.pWC->a[ii].wtFlags |= TERM_CODED;
113603
+ }
113536113604
}
113537113605
113538113606
/* Special case: No FROM clause
113539113607
*/
113540113608
if( nTabList==0 ){
@@ -121784,11 +121852,11 @@
121784121852
** Reset the PRNG back to its uninitialized state. The next call
121785121853
** to sqlite3_randomness() will reseed the PRNG using a single call
121786121854
** to the xRandomness method of the default VFS.
121787121855
*/
121788121856
case SQLITE_TESTCTRL_PRNG_RESET: {
121789
- sqlite3PrngResetState();
121857
+ sqlite3_randomness(0,0);
121790121858
break;
121791121859
}
121792121860
121793121861
/*
121794121862
** sqlite3_test_control(BITVEC_TEST, size, program)
@@ -124767,10 +124835,23 @@
124767124835
sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
124768124836
char **pzErr /* OUT: sqlite3_malloc'd error message */
124769124837
){
124770124838
return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
124771124839
}
124840
+
124841
+/*
124842
+** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
124843
+** extension is currently being used by a version of SQLite too old to
124844
+** support estimatedRows. In that case this function is a no-op.
124845
+*/
124846
+static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
124847
+#if SQLITE_VERSION_NUMBER>=3008002
124848
+ if( sqlite3_libversion_number()>=3008002 ){
124849
+ pIdxInfo->estimatedRows = nRow;
124850
+ }
124851
+#endif
124852
+}
124772124853
124773124854
/*
124774124855
** Implementation of the xBestIndex method for FTS3 tables. There
124775124856
** are three possible strategies, in order of preference:
124776124857
**
@@ -124795,11 +124876,24 @@
124795124876
pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124796124877
pInfo->estimatedCost = 5000000;
124797124878
for(i=0; i<pInfo->nConstraint; i++){
124798124879
int bDocid; /* True if this constraint is on docid */
124799124880
struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
124800
- if( pCons->usable==0 ) continue;
124881
+ if( pCons->usable==0 ){
124882
+ if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){
124883
+ /* There exists an unusable MATCH constraint. This means that if
124884
+ ** the planner does elect to use the results of this call as part
124885
+ ** of the overall query plan the user will see an "unable to use
124886
+ ** function MATCH in the requested context" error. To discourage
124887
+ ** this, return a very high cost here. */
124888
+ pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124889
+ pInfo->estimatedCost = 1e50;
124890
+ setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50);
124891
+ return SQLITE_OK;
124892
+ }
124893
+ continue;
124894
+ }
124801124895
124802124896
bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
124803124897
124804124898
/* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
124805124899
if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
124806124900
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -2426,15 +2426,17 @@
2426 ** already uses the largest possible [ROWID]. The PRNG is also used for
2427 ** the build-in random() and randomblob() SQL functions. This interface allows
2428 ** applications to access the same PRNG for other purposes.
2429 **
2430 ** ^A call to this routine stores N bytes of randomness into buffer P.
 
2431 **
2432 ** ^The first time this routine is invoked (either internally or by
2433 ** the application) the PRNG is seeded using randomness obtained
2434 ** from the xRandomness method of the default [sqlite3_vfs] object.
2435 ** ^On all subsequent invocations, the pseudo-randomness is generated
 
2436 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2437 ** method.
2438 */
2439 SQLITE_API void sqlite3_randomness(int N, void *P);
2440
@@ -9278,10 +9280,11 @@
9278 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9279 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9280 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
9281 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
9282 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
 
9283 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
9284 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
9285 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
9286 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
9287 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
@@ -10371,11 +10374,11 @@
10371 */
10372 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
10373 #define SQLITE_ColumnCache 0x0002 /* Column cache */
10374 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
10375 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10376 #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
10377 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10378 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10379 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10380 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10381 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
@@ -11605,10 +11608,13 @@
11605 int nErr; /* Number of errors seen */
11606 int nTab; /* Number of previously allocated VDBE cursors */
11607 int nMem; /* Number of memory cells used so far */
11608 int nSet; /* Number of sets used so far */
11609 int nOnce; /* Number of OP_Once instructions so far */
 
 
 
11610 int ckBase; /* Base register of data during check constraints */
11611 int iPartIdxTab; /* Table corresponding to a partial index */
11612 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11613 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11614 struct yColCache {
@@ -12284,11 +12290,10 @@
12284 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
12285 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
12286 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
12287 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
12288 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
12289 SQLITE_PRIVATE void sqlite3PrngResetState(void);
12290 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
12291 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
12292 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
12293 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
12294 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
@@ -13776,19 +13781,13 @@
13776 Op *aOp; /* Space to hold the virtual machine's program */
13777 Mem *aMem; /* The memory locations */
13778 Mem **apArg; /* Arguments to currently executing user function */
13779 Mem *aColName; /* Column names to return */
13780 Mem *pResultSet; /* Pointer to an array of results */
13781 #ifdef SQLITE_DEBUG
13782 Parse *pParse; /* Parsing context used to create this Vdbe */
13783 #endif
13784 int nMem; /* Number of memory locations currently allocated */
13785 int nOp; /* Number of instructions in the program */
13786 int nOpAlloc; /* Number of slots allocated for aOp[] */
13787 int nLabel; /* Number of labels used */
13788 int *aLabel; /* Space to hold the labels */
13789 u16 nResColumn; /* Number of columns in one row of the result set */
13790 int nCursor; /* Number of slots in apCsr[] */
13791 u32 magic; /* Magic number for sanity checking */
13792 char *zErrMsg; /* Error message written here */
13793 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
13794 VdbeCursor **apCsr; /* One element of this array for each open cursor */
@@ -13797,10 +13796,11 @@
13797 ynVar nVar; /* Number of entries in aVar[] */
13798 ynVar nzVar; /* Number of entries in azVar[] */
13799 u32 cacheCtr; /* VdbeCursor row cache generation counter */
13800 int pc; /* The program counter */
13801 int rc; /* Value to return */
 
13802 u8 errorAction; /* Recovery action to do in case of an error */
13803 u8 minWriteFileFormat; /* Minimum file format for writable database files */
13804 bft explain:2; /* True if EXPLAIN present on SQL command */
13805 bft inVtabMethod:2; /* See comments above */
13806 bft changeCntOn:1; /* True to update the change-counter */
@@ -20901,10 +20901,16 @@
20901
20902 #if SQLITE_THREADSAFE
20903 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20904 sqlite3_mutex_enter(mutex);
20905 #endif
 
 
 
 
 
 
20906
20907 /* Initialize the state of the random number generator once,
20908 ** the first time this routine is called. The seed value does
20909 ** not need to contain a lot of randomness since we are not
20910 ** trying to do secure encryption or anything like that...
@@ -20929,19 +20935,20 @@
20929 wsdPrng.s[i] = t;
20930 }
20931 wsdPrng.isInit = 1;
20932 }
20933
20934 while( N-- ){
 
20935 wsdPrng.i++;
20936 t = wsdPrng.s[wsdPrng.i];
20937 wsdPrng.j += t;
20938 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20939 wsdPrng.s[wsdPrng.j] = t;
20940 t += wsdPrng.s[wsdPrng.i];
20941 *(zBuf++) = wsdPrng.s[t];
20942 }
20943 sqlite3_mutex_leave(mutex);
20944 }
20945
20946 #ifndef SQLITE_OMIT_BUILTIN_TEST
20947 /*
@@ -20966,13 +20973,10 @@
20966 &GLOBAL(struct sqlite3PrngType, sqlite3Prng),
20967 &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
20968 sizeof(sqlite3Prng)
20969 );
20970 }
20971 SQLITE_PRIVATE void sqlite3PrngResetState(void){
20972 GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0;
20973 }
20974 #endif /* SQLITE_OMIT_BUILTIN_TEST */
20975
20976 /************** End of random.c **********************************************/
20977 /************** Begin file utf.c *********************************************/
20978 /*
@@ -23505,10 +23509,16 @@
23505 ** it is larger than the struct CrashFile defined in test6.c.
23506 */
23507 char aPadding[32];
23508 #endif
23509 };
 
 
 
 
 
 
23510
23511 /*
23512 ** Allowed values for the unixFile.ctrlFlags bitmask:
23513 */
23514 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
@@ -29104,10 +29114,20 @@
29104 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
29105 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
29106 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
29107 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
29108 );
 
 
 
 
 
 
 
 
 
 
29109
29110 memset(p, 0, sizeof(unixFile));
29111
29112 if( eType==SQLITE_OPEN_MAIN_DB ){
29113 UnixUnusedFd *pUnused;
@@ -29492,22 +29512,22 @@
29492 ** When testing, initializing zBuf[] to zero is all we do. That means
29493 ** that we always use the same random number sequence. This makes the
29494 ** tests repeatable.
29495 */
29496 memset(zBuf, 0, nBuf);
 
29497 #if !defined(SQLITE_TEST)
29498 {
29499 int pid, fd, got;
29500 fd = robust_open("/dev/urandom", O_RDONLY, 0);
29501 if( fd<0 ){
29502 time_t t;
29503 time(&t);
29504 memcpy(zBuf, &t, sizeof(t));
29505 pid = getpid();
29506 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
29507 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
29508 nBuf = sizeof(t) + sizeof(pid);
29509 }else{
29510 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
29511 robust_close(0, fd, __LINE__);
29512 }
29513 }
@@ -61200,13 +61220,14 @@
61200 }
61201 p->pNext = db->pVdbe;
61202 p->pPrev = 0;
61203 db->pVdbe = p;
61204 p->magic = VDBE_MAGIC_INIT;
61205 #if SQLITE_DEBUG
61206 p->pParse = pParse;
61207 #endif
 
 
61208 return p;
61209 }
61210
61211 /*
61212 ** Remember the SQL string for a prepared statement.
@@ -61258,17 +61279,18 @@
61258 ** If an out-of-memory error occurs while resizing the array, return
61259 ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
61260 ** unchanged (this is so that any opcodes already allocated can be
61261 ** correctly deallocated along with the rest of the Vdbe).
61262 */
61263 static int growOpArray(Vdbe *p){
61264 VdbeOp *pNew;
 
61265 int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
61266 pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
61267 if( pNew ){
61268 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
61269 p->aOp = pNew;
61270 }
61271 return (pNew ? SQLITE_OK : SQLITE_NOMEM);
61272 }
61273
61274 #ifdef SQLITE_DEBUG
@@ -61303,11 +61325,11 @@
61303 VdbeOp *pOp;
61304
61305 i = p->nOp;
61306 assert( p->magic==VDBE_MAGIC_INIT );
61307 assert( op>0 && op<0xff );
61308 if( p->nOpAlloc<=i ){
61309 if( growOpArray(p) ){
61310 return 1;
61311 }
61312 }
61313 p->nOp++;
@@ -61414,13 +61436,14 @@
61414 ** always negative and P2 values are suppose to be non-negative.
61415 ** Hence, a negative P2 value is a label that has yet to be resolved.
61416 **
61417 ** Zero is returned if a malloc() fails.
61418 */
61419 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){
 
61420 int i = p->nLabel++;
61421 assert( p->magic==VDBE_MAGIC_INIT );
61422 if( (i & (i-1))==0 ){
61423 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
61424 (i*2+1)*sizeof(p->aLabel[0]));
61425 }
61426 if( p->aLabel ){
@@ -61432,16 +61455,17 @@
61432 /*
61433 ** Resolve label "x" to be the address of the next instruction to
61434 ** be inserted. The parameter "x" must have been obtained from
61435 ** a prior call to sqlite3VdbeMakeLabel().
61436 */
61437 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){
 
61438 int j = -1-x;
61439 assert( p->magic==VDBE_MAGIC_INIT );
61440 assert( j<p->nLabel );
61441 if( j>=0 && p->aLabel ){
61442 p->aLabel[j] = p->nOp;
61443 }
61444 }
61445
61446 /*
61447 ** Mark the VDBE as one that can only be run one time.
@@ -61586,11 +61610,12 @@
61586 */
61587 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
61588 int i;
61589 int nMaxArgs = *pMaxFuncArgs;
61590 Op *pOp;
61591 int *aLabel = p->aLabel;
 
61592 p->readOnly = 1;
61593 p->bIsReader = 0;
61594 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
61595 u8 opcode = pOp->opcode;
61596
@@ -61649,16 +61674,17 @@
61649 }
61650 }
61651
61652 pOp->opflags = sqlite3OpcodeProperty[opcode];
61653 if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
61654 assert( -1-pOp->p2<p->nLabel );
61655 pOp->p2 = aLabel[-1-pOp->p2];
61656 }
61657 }
61658 sqlite3DbFree(p->db, p->aLabel);
61659 p->aLabel = 0;
 
61660 *pMaxFuncArgs = nMaxArgs;
61661 assert( p->bIsReader!=0 || p->btreeMask==0 );
61662 }
61663
61664 /*
@@ -61698,11 +61724,11 @@
61698 ** address of the first operation added.
61699 */
61700 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61701 int addr;
61702 assert( p->magic==VDBE_MAGIC_INIT );
61703 if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){
61704 return 0;
61705 }
61706 addr = p->nOp;
61707 if( ALWAYS(nOp>0) ){
61708 int i;
@@ -61886,10 +61912,17 @@
61886 memset(pOp, 0, sizeof(pOp[0]));
61887 pOp->opcode = OP_Noop;
61888 if( addr==p->nOp-1 ) p->nOp--;
61889 }
61890 }
 
 
 
 
 
 
 
61891
61892 /*
61893 ** Change the value of the P4 operand for a specific instruction.
61894 ** This routine is useful when a large program is loaded from a
61895 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -62768,10 +62801,11 @@
62768
62769 assert( p!=0 );
62770 assert( p->nOp>0 );
62771 assert( pParse!=0 );
62772 assert( p->magic==VDBE_MAGIC_INIT );
 
62773 db = p->db;
62774 assert( db->mallocFailed==0 );
62775 nVar = pParse->nVar;
62776 nMem = pParse->nMem;
62777 nCursor = pParse->nTab;
@@ -62791,12 +62825,12 @@
62791 nMem += nCursor;
62792
62793 /* Allocate space for memory registers, SQL variables, VDBE cursors and
62794 ** an array to marshal SQL function arguments in.
62795 */
62796 zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62797 zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */
62798
62799 resolveP2Values(p, &nArg);
62800 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
62801 if( pParse->explain && nMem<10 ){
62802 nMem = 10;
@@ -63795,11 +63829,10 @@
63795 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
63796 sqlite3DbFree(db, pSub);
63797 }
63798 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
63799 vdbeFreeOpArray(db, p->aOp, p->nOp);
63800 sqlite3DbFree(db, p->aLabel);
63801 sqlite3DbFree(db, p->aColName);
63802 sqlite3DbFree(db, p->zSql);
63803 sqlite3DbFree(db, p->pFree);
63804 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
63805 sqlite3DbFree(db, p->zExplain);
@@ -76765,20 +76798,29 @@
76765 }
76766 return p;
76767 }
76768
76769 /*
76770 ** Return 1 if an expression must be FALSE in all cases and 0 if the
76771 ** expression might be true. This is an optimization. If is OK to
76772 ** return 0 here even if the expression really is always false (a
76773 ** false negative). But it is a bug to return 1 if the expression
76774 ** might be true in some rare circumstances (a false positive.)
 
 
 
76775 **
76776 ** Note that if the expression is part of conditional for a
76777 ** LEFT JOIN, then we cannot determine at compile-time whether or not
76778 ** is it true or false, so always return 0.
76779 */
 
 
 
 
 
 
76780 static int exprAlwaysFalse(Expr *p){
76781 int v = 0;
76782 if( ExprHasProperty(p, EP_FromJoin) ) return 0;
76783 if( !sqlite3ExprIsInteger(p, &v) ) return 0;
76784 return v==0;
@@ -79621,11 +79663,11 @@
79621 sqlite3ExplainPush(pOut);
79622 for(i=0; i<pList->nExpr; i++){
79623 sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
79624 sqlite3ExplainPush(pOut);
79625 sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
79626 sqlite3ExplainPop(pOut);
79627 if( pList->a[i].zName ){
79628 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
79629 }
79630 if( pList->a[i].bSpanIsTab ){
79631 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
@@ -79771,21 +79813,23 @@
79771 op = pExpr->op;
79772 switch( op ){
79773 case TK_AND: {
79774 int d2 = sqlite3VdbeMakeLabel(v);
79775 testcase( jumpIfNull==0 );
79776 sqlite3ExprCachePush(pParse);
79777 sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
 
79778 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
79779 sqlite3VdbeResolveLabel(v, d2);
79780 sqlite3ExprCachePop(pParse, 1);
79781 break;
79782 }
79783 case TK_OR: {
79784 testcase( jumpIfNull==0 );
79785 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
 
79786 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
 
79787 break;
79788 }
79789 case TK_NOT: {
79790 testcase( jumpIfNull==0 );
79791 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
@@ -79856,14 +79900,20 @@
79856 sqlite3VdbeResolveLabel(v, destIfFalse);
79857 break;
79858 }
79859 #endif
79860 default: {
79861 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
79862 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
79863 testcase( regFree1==0 );
79864 testcase( jumpIfNull==0 );
 
 
 
 
 
 
79865 break;
79866 }
79867 }
79868 sqlite3ReleaseTempReg(pParse, regFree1);
79869 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -79922,18 +79972,20 @@
79922
79923 switch( pExpr->op ){
79924 case TK_AND: {
79925 testcase( jumpIfNull==0 );
79926 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
 
79927 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
 
79928 break;
79929 }
79930 case TK_OR: {
79931 int d2 = sqlite3VdbeMakeLabel(v);
79932 testcase( jumpIfNull==0 );
79933 sqlite3ExprCachePush(pParse);
79934 sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
 
79935 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
79936 sqlite3VdbeResolveLabel(v, d2);
79937 sqlite3ExprCachePop(pParse, 1);
79938 break;
79939 }
@@ -80001,14 +80053,20 @@
80001 }
80002 break;
80003 }
80004 #endif
80005 default: {
80006 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80007 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80008 testcase( regFree1==0 );
80009 testcase( jumpIfNull==0 );
 
 
 
 
 
 
80010 break;
80011 }
80012 }
80013 sqlite3ReleaseTempReg(pParse, regFree1);
80014 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -89357,22 +89415,22 @@
89357 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
89358 regBase = sqlite3GetTempRange(pParse, nCol);
89359 for(j=0; j<nCol; j++){
89360 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
89361 regBase+j);
 
 
 
 
 
 
 
 
 
89362 }
89363 if( regOut ){
89364 const char *zAff;
89365 if( pTab->pSelect
89366 || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
89367 ){
89368 zAff = 0;
89369 }else{
89370 zAff = sqlite3IndexAffinityStr(v, pIdx);
89371 }
89372 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
89373 sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
89374 }
89375 sqlite3ReleaseTempRange(pParse, regBase, nCol);
89376 return regBase;
89377 }
89378
@@ -93721,10 +93779,11 @@
93721 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
93722 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
93723 int ipkTop = 0; /* Top of the rowid change constraint check */
93724 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
93725 u8 isUpdate; /* True if this is an UPDATE operation */
 
93726
93727 isUpdate = regOldData!=0;
93728 db = pParse->db;
93729 v = sqlite3GetVdbe(pParse);
93730 assert( v!=0 );
@@ -93951,11 +94010,13 @@
93951 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
93952 for(i=0; i<pIdx->nColumn; i++){
93953 int iField = pIdx->aiColumn[i];
93954 int x;
93955 if( iField<0 || iField==pTab->iPKey ){
 
93956 x = regNewData;
 
93957 }else{
93958 x = iField + regNewData + 1;
93959 }
93960 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
93961 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
@@ -98780,11 +98841,15 @@
98780
98781 /*
98782 ** Free all memory allocations in the pParse object
98783 */
98784 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
98785 if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
 
 
 
 
98786 }
98787
98788 /*
98789 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
98790 */
@@ -113528,13 +113593,16 @@
113528 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113529
113530 /* Special case: a WHERE clause that is constant. Evaluate the
113531 ** expression and either jump over all of the code or fall thru.
113532 */
113533 if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
113534 sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);
113535 pWhere = 0;
 
 
 
113536 }
113537
113538 /* Special case: No FROM clause
113539 */
113540 if( nTabList==0 ){
@@ -121784,11 +121852,11 @@
121784 ** Reset the PRNG back to its uninitialized state. The next call
121785 ** to sqlite3_randomness() will reseed the PRNG using a single call
121786 ** to the xRandomness method of the default VFS.
121787 */
121788 case SQLITE_TESTCTRL_PRNG_RESET: {
121789 sqlite3PrngResetState();
121790 break;
121791 }
121792
121793 /*
121794 ** sqlite3_test_control(BITVEC_TEST, size, program)
@@ -124767,10 +124835,23 @@
124767 sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
124768 char **pzErr /* OUT: sqlite3_malloc'd error message */
124769 ){
124770 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
124771 }
 
 
 
 
 
 
 
 
 
 
 
 
 
124772
124773 /*
124774 ** Implementation of the xBestIndex method for FTS3 tables. There
124775 ** are three possible strategies, in order of preference:
124776 **
@@ -124795,11 +124876,24 @@
124795 pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124796 pInfo->estimatedCost = 5000000;
124797 for(i=0; i<pInfo->nConstraint; i++){
124798 int bDocid; /* True if this constraint is on docid */
124799 struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
124800 if( pCons->usable==0 ) continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
124801
124802 bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
124803
124804 /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
124805 if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
124806
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -2426,15 +2426,17 @@
2426 ** already uses the largest possible [ROWID]. The PRNG is also used for
2427 ** the build-in random() and randomblob() SQL functions. This interface allows
2428 ** applications to access the same PRNG for other purposes.
2429 **
2430 ** ^A call to this routine stores N bytes of randomness into buffer P.
2431 ** ^If N is less than one, then P can be a NULL pointer.
2432 **
2433 ** ^If this routine has not been previously called or if the previous
2434 ** call had N less than one, then the PRNG is seeded using randomness
2435 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2436 ** ^If the previous call to this routine had an N of 1 or more then
2437 ** the pseudo-randomness is generated
2438 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2439 ** method.
2440 */
2441 SQLITE_API void sqlite3_randomness(int N, void *P);
2442
@@ -9278,10 +9280,11 @@
9280 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9281 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9282 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
9283 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
9284 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
9285 SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*);
9286 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
9287 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
9288 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
9289 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
9290 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
@@ -10371,11 +10374,11 @@
10374 */
10375 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
10376 #define SQLITE_ColumnCache 0x0002 /* Column cache */
10377 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
10378 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10379 /* not used 0x0010 // Was: SQLITE_IdxRealAsInt */
10380 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10381 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10382 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10383 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10384 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
@@ -11605,10 +11608,13 @@
11608 int nErr; /* Number of errors seen */
11609 int nTab; /* Number of previously allocated VDBE cursors */
11610 int nMem; /* Number of memory cells used so far */
11611 int nSet; /* Number of sets used so far */
11612 int nOnce; /* Number of OP_Once instructions so far */
11613 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11614 int nLabel; /* Number of labels used */
11615 int *aLabel; /* Space to hold the labels */
11616 int ckBase; /* Base register of data during check constraints */
11617 int iPartIdxTab; /* Table corresponding to a partial index */
11618 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11619 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11620 struct yColCache {
@@ -12284,11 +12290,10 @@
12290 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
12291 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
12292 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
12293 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
12294 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
 
12295 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
12296 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
12297 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
12298 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
12299 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
@@ -13776,19 +13781,13 @@
13781 Op *aOp; /* Space to hold the virtual machine's program */
13782 Mem *aMem; /* The memory locations */
13783 Mem **apArg; /* Arguments to currently executing user function */
13784 Mem *aColName; /* Column names to return */
13785 Mem *pResultSet; /* Pointer to an array of results */
 
13786 Parse *pParse; /* Parsing context used to create this Vdbe */
 
13787 int nMem; /* Number of memory locations currently allocated */
13788 int nOp; /* Number of instructions in the program */
 
 
 
 
13789 int nCursor; /* Number of slots in apCsr[] */
13790 u32 magic; /* Magic number for sanity checking */
13791 char *zErrMsg; /* Error message written here */
13792 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
13793 VdbeCursor **apCsr; /* One element of this array for each open cursor */
@@ -13797,10 +13796,11 @@
13796 ynVar nVar; /* Number of entries in aVar[] */
13797 ynVar nzVar; /* Number of entries in azVar[] */
13798 u32 cacheCtr; /* VdbeCursor row cache generation counter */
13799 int pc; /* The program counter */
13800 int rc; /* Value to return */
13801 u16 nResColumn; /* Number of columns in one row of the result set */
13802 u8 errorAction; /* Recovery action to do in case of an error */
13803 u8 minWriteFileFormat; /* Minimum file format for writable database files */
13804 bft explain:2; /* True if EXPLAIN present on SQL command */
13805 bft inVtabMethod:2; /* See comments above */
13806 bft changeCntOn:1; /* True to update the change-counter */
@@ -20901,10 +20901,16 @@
20901
20902 #if SQLITE_THREADSAFE
20903 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20904 sqlite3_mutex_enter(mutex);
20905 #endif
20906
20907 if( N<=0 ){
20908 wsdPrng.isInit = 0;
20909 sqlite3_mutex_leave(mutex);
20910 return;
20911 }
20912
20913 /* Initialize the state of the random number generator once,
20914 ** the first time this routine is called. The seed value does
20915 ** not need to contain a lot of randomness since we are not
20916 ** trying to do secure encryption or anything like that...
@@ -20929,19 +20935,20 @@
20935 wsdPrng.s[i] = t;
20936 }
20937 wsdPrng.isInit = 1;
20938 }
20939
20940 assert( N>0 );
20941 do{
20942 wsdPrng.i++;
20943 t = wsdPrng.s[wsdPrng.i];
20944 wsdPrng.j += t;
20945 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20946 wsdPrng.s[wsdPrng.j] = t;
20947 t += wsdPrng.s[wsdPrng.i];
20948 *(zBuf++) = wsdPrng.s[t];
20949 }while( --N );
20950 sqlite3_mutex_leave(mutex);
20951 }
20952
20953 #ifndef SQLITE_OMIT_BUILTIN_TEST
20954 /*
@@ -20966,13 +20973,10 @@
20973 &GLOBAL(struct sqlite3PrngType, sqlite3Prng),
20974 &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
20975 sizeof(sqlite3Prng)
20976 );
20977 }
 
 
 
20978 #endif /* SQLITE_OMIT_BUILTIN_TEST */
20979
20980 /************** End of random.c **********************************************/
20981 /************** Begin file utf.c *********************************************/
20982 /*
@@ -23505,10 +23509,16 @@
23509 ** it is larger than the struct CrashFile defined in test6.c.
23510 */
23511 char aPadding[32];
23512 #endif
23513 };
23514
23515 /* This variable holds the process id (pid) from when the xRandomness()
23516 ** method was called. If xOpen() is called from a different process id,
23517 ** indicating that a fork() has occurred, the PRNG will be reset.
23518 */
23519 static int randomnessPid = 0;
23520
23521 /*
23522 ** Allowed values for the unixFile.ctrlFlags bitmask:
23523 */
23524 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
@@ -29104,10 +29114,20 @@
29114 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
29115 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
29116 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
29117 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
29118 );
29119
29120 /* Detect a pid change and reset the PRNG. There is a race condition
29121 ** here such that two or more threads all trying to open databases at
29122 ** the same instant might all reset the PRNG. But multiple resets
29123 ** are harmless.
29124 */
29125 if( randomnessPid!=getpid() ){
29126 randomnessPid = getpid();
29127 sqlite3_randomness(0,0);
29128 }
29129
29130 memset(p, 0, sizeof(unixFile));
29131
29132 if( eType==SQLITE_OPEN_MAIN_DB ){
29133 UnixUnusedFd *pUnused;
@@ -29492,22 +29512,22 @@
29512 ** When testing, initializing zBuf[] to zero is all we do. That means
29513 ** that we always use the same random number sequence. This makes the
29514 ** tests repeatable.
29515 */
29516 memset(zBuf, 0, nBuf);
29517 randomnessPid = getpid();
29518 #if !defined(SQLITE_TEST)
29519 {
29520 int fd, got;
29521 fd = robust_open("/dev/urandom", O_RDONLY, 0);
29522 if( fd<0 ){
29523 time_t t;
29524 time(&t);
29525 memcpy(zBuf, &t, sizeof(t));
29526 memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid));
29527 assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf );
29528 nBuf = sizeof(t) + sizeof(randomnessPid);
 
29529 }else{
29530 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
29531 robust_close(0, fd, __LINE__);
29532 }
29533 }
@@ -61200,13 +61220,14 @@
61220 }
61221 p->pNext = db->pVdbe;
61222 p->pPrev = 0;
61223 db->pVdbe = p;
61224 p->magic = VDBE_MAGIC_INIT;
 
61225 p->pParse = pParse;
61226 assert( pParse->aLabel==0 );
61227 assert( pParse->nLabel==0 );
61228 assert( pParse->nOpAlloc==0 );
61229 return p;
61230 }
61231
61232 /*
61233 ** Remember the SQL string for a prepared statement.
@@ -61258,17 +61279,18 @@
61279 ** If an out-of-memory error occurs while resizing the array, return
61280 ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
61281 ** unchanged (this is so that any opcodes already allocated can be
61282 ** correctly deallocated along with the rest of the Vdbe).
61283 */
61284 static int growOpArray(Vdbe *v){
61285 VdbeOp *pNew;
61286 Parse *p = v->pParse;
61287 int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
61288 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
61289 if( pNew ){
61290 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
61291 v->aOp = pNew;
61292 }
61293 return (pNew ? SQLITE_OK : SQLITE_NOMEM);
61294 }
61295
61296 #ifdef SQLITE_DEBUG
@@ -61303,11 +61325,11 @@
61325 VdbeOp *pOp;
61326
61327 i = p->nOp;
61328 assert( p->magic==VDBE_MAGIC_INIT );
61329 assert( op>0 && op<0xff );
61330 if( p->pParse->nOpAlloc<=i ){
61331 if( growOpArray(p) ){
61332 return 1;
61333 }
61334 }
61335 p->nOp++;
@@ -61414,13 +61436,14 @@
61436 ** always negative and P2 values are suppose to be non-negative.
61437 ** Hence, a negative P2 value is a label that has yet to be resolved.
61438 **
61439 ** Zero is returned if a malloc() fails.
61440 */
61441 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){
61442 Parse *p = v->pParse;
61443 int i = p->nLabel++;
61444 assert( v->magic==VDBE_MAGIC_INIT );
61445 if( (i & (i-1))==0 ){
61446 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
61447 (i*2+1)*sizeof(p->aLabel[0]));
61448 }
61449 if( p->aLabel ){
@@ -61432,16 +61455,17 @@
61455 /*
61456 ** Resolve label "x" to be the address of the next instruction to
61457 ** be inserted. The parameter "x" must have been obtained from
61458 ** a prior call to sqlite3VdbeMakeLabel().
61459 */
61460 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
61461 Parse *p = v->pParse;
61462 int j = -1-x;
61463 assert( v->magic==VDBE_MAGIC_INIT );
61464 assert( j<p->nLabel );
61465 if( j>=0 && p->aLabel ){
61466 p->aLabel[j] = v->nOp;
61467 }
61468 }
61469
61470 /*
61471 ** Mark the VDBE as one that can only be run one time.
@@ -61586,11 +61610,12 @@
61610 */
61611 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
61612 int i;
61613 int nMaxArgs = *pMaxFuncArgs;
61614 Op *pOp;
61615 Parse *pParse = p->pParse;
61616 int *aLabel = pParse->aLabel;
61617 p->readOnly = 1;
61618 p->bIsReader = 0;
61619 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
61620 u8 opcode = pOp->opcode;
61621
@@ -61649,16 +61674,17 @@
61674 }
61675 }
61676
61677 pOp->opflags = sqlite3OpcodeProperty[opcode];
61678 if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
61679 assert( -1-pOp->p2<pParse->nLabel );
61680 pOp->p2 = aLabel[-1-pOp->p2];
61681 }
61682 }
61683 sqlite3DbFree(p->db, pParse->aLabel);
61684 pParse->aLabel = 0;
61685 pParse->nLabel = 0;
61686 *pMaxFuncArgs = nMaxArgs;
61687 assert( p->bIsReader!=0 || p->btreeMask==0 );
61688 }
61689
61690 /*
@@ -61698,11 +61724,11 @@
61724 ** address of the first operation added.
61725 */
61726 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61727 int addr;
61728 assert( p->magic==VDBE_MAGIC_INIT );
61729 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
61730 return 0;
61731 }
61732 addr = p->nOp;
61733 if( ALWAYS(nOp>0) ){
61734 int i;
@@ -61886,10 +61912,17 @@
61912 memset(pOp, 0, sizeof(pOp[0]));
61913 pOp->opcode = OP_Noop;
61914 if( addr==p->nOp-1 ) p->nOp--;
61915 }
61916 }
61917
61918 /*
61919 ** Remove the last opcode inserted
61920 */
61921 SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){
61922 p->nOp--;
61923 }
61924
61925 /*
61926 ** Change the value of the P4 operand for a specific instruction.
61927 ** This routine is useful when a large program is loaded from a
61928 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -62768,10 +62801,11 @@
62801
62802 assert( p!=0 );
62803 assert( p->nOp>0 );
62804 assert( pParse!=0 );
62805 assert( p->magic==VDBE_MAGIC_INIT );
62806 assert( pParse==p->pParse );
62807 db = p->db;
62808 assert( db->mallocFailed==0 );
62809 nVar = pParse->nVar;
62810 nMem = pParse->nMem;
62811 nCursor = pParse->nTab;
@@ -62791,12 +62825,12 @@
62825 nMem += nCursor;
62826
62827 /* Allocate space for memory registers, SQL variables, VDBE cursors and
62828 ** an array to marshal SQL function arguments in.
62829 */
62830 zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62831 zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */
62832
62833 resolveP2Values(p, &nArg);
62834 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
62835 if( pParse->explain && nMem<10 ){
62836 nMem = 10;
@@ -63795,11 +63829,10 @@
63829 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
63830 sqlite3DbFree(db, pSub);
63831 }
63832 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
63833 vdbeFreeOpArray(db, p->aOp, p->nOp);
 
63834 sqlite3DbFree(db, p->aColName);
63835 sqlite3DbFree(db, p->zSql);
63836 sqlite3DbFree(db, p->pFree);
63837 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
63838 sqlite3DbFree(db, p->zExplain);
@@ -76765,20 +76798,29 @@
76798 }
76799 return p;
76800 }
76801
76802 /*
76803 ** If the expression is always either TRUE or FALSE (respectively),
76804 ** then return 1. If one cannot determine the truth value of the
76805 ** expression at compile-time return 0.
76806 **
76807 ** This is an optimization. If is OK to return 0 here even if
76808 ** the expression really is always false or false (a false negative).
76809 ** But it is a bug to return 1 if the expression might have different
76810 ** boolean values in different circumstances (a false positive.)
76811 **
76812 ** Note that if the expression is part of conditional for a
76813 ** LEFT JOIN, then we cannot determine at compile-time whether or not
76814 ** is it true or false, so always return 0.
76815 */
76816 static int exprAlwaysTrue(Expr *p){
76817 int v = 0;
76818 if( ExprHasProperty(p, EP_FromJoin) ) return 0;
76819 if( !sqlite3ExprIsInteger(p, &v) ) return 0;
76820 return v!=0;
76821 }
76822 static int exprAlwaysFalse(Expr *p){
76823 int v = 0;
76824 if( ExprHasProperty(p, EP_FromJoin) ) return 0;
76825 if( !sqlite3ExprIsInteger(p, &v) ) return 0;
76826 return v==0;
@@ -79621,11 +79663,11 @@
79663 sqlite3ExplainPush(pOut);
79664 for(i=0; i<pList->nExpr; i++){
79665 sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
79666 sqlite3ExplainPush(pOut);
79667 sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
79668 sqlite3ExplainPop(pOut, 1);
79669 if( pList->a[i].zName ){
79670 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
79671 }
79672 if( pList->a[i].bSpanIsTab ){
79673 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
@@ -79771,21 +79813,23 @@
79813 op = pExpr->op;
79814 switch( op ){
79815 case TK_AND: {
79816 int d2 = sqlite3VdbeMakeLabel(v);
79817 testcase( jumpIfNull==0 );
 
79818 sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
79819 sqlite3ExprCachePush(pParse);
79820 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
79821 sqlite3VdbeResolveLabel(v, d2);
79822 sqlite3ExprCachePop(pParse, 1);
79823 break;
79824 }
79825 case TK_OR: {
79826 testcase( jumpIfNull==0 );
79827 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
79828 sqlite3ExprCachePush(pParse);
79829 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
79830 sqlite3ExprCachePop(pParse, 1);
79831 break;
79832 }
79833 case TK_NOT: {
79834 testcase( jumpIfNull==0 );
79835 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
@@ -79856,14 +79900,20 @@
79900 sqlite3VdbeResolveLabel(v, destIfFalse);
79901 break;
79902 }
79903 #endif
79904 default: {
79905 if( exprAlwaysTrue(pExpr) ){
79906 sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
79907 }else if( exprAlwaysFalse(pExpr) ){
79908 /* No-op */
79909 }else{
79910 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
79911 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
79912 testcase( regFree1==0 );
79913 testcase( jumpIfNull==0 );
79914 }
79915 break;
79916 }
79917 }
79918 sqlite3ReleaseTempReg(pParse, regFree1);
79919 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -79922,18 +79972,20 @@
79972
79973 switch( pExpr->op ){
79974 case TK_AND: {
79975 testcase( jumpIfNull==0 );
79976 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
79977 sqlite3ExprCachePush(pParse);
79978 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
79979 sqlite3ExprCachePop(pParse, 1);
79980 break;
79981 }
79982 case TK_OR: {
79983 int d2 = sqlite3VdbeMakeLabel(v);
79984 testcase( jumpIfNull==0 );
 
79985 sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
79986 sqlite3ExprCachePush(pParse);
79987 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
79988 sqlite3VdbeResolveLabel(v, d2);
79989 sqlite3ExprCachePop(pParse, 1);
79990 break;
79991 }
@@ -80001,14 +80053,20 @@
80053 }
80054 break;
80055 }
80056 #endif
80057 default: {
80058 if( exprAlwaysFalse(pExpr) ){
80059 sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
80060 }else if( exprAlwaysTrue(pExpr) ){
80061 /* no-op */
80062 }else{
80063 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80064 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80065 testcase( regFree1==0 );
80066 testcase( jumpIfNull==0 );
80067 }
80068 break;
80069 }
80070 }
80071 sqlite3ReleaseTempReg(pParse, regFree1);
80072 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -89357,22 +89415,22 @@
89415 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
89416 regBase = sqlite3GetTempRange(pParse, nCol);
89417 for(j=0; j<nCol; j++){
89418 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
89419 regBase+j);
89420 /* If the column affinity is REAL but the number is an integer, then it
89421 ** might be stored in the table as an integer (using a compact
89422 ** representation) then converted to REAL by an OP_RealAffinity opcode.
89423 ** But we are getting ready to store this value back into an index, where
89424 ** it should be converted by to INTEGER again. So omit the OP_RealAffinity
89425 ** opcode if it is present */
89426 if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){
89427 sqlite3VdbeDeleteLastOpcode(v);
89428 }
89429 }
89430 if( regOut ){
 
 
 
 
 
 
 
 
89431 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
 
89432 }
89433 sqlite3ReleaseTempRange(pParse, regBase, nCol);
89434 return regBase;
89435 }
89436
@@ -93721,10 +93779,11 @@
93779 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
93780 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
93781 int ipkTop = 0; /* Top of the rowid change constraint check */
93782 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
93783 u8 isUpdate; /* True if this is an UPDATE operation */
93784 int regRowid = -1; /* Register holding ROWID value */
93785
93786 isUpdate = regOldData!=0;
93787 db = pParse->db;
93788 v = sqlite3GetVdbe(pParse);
93789 assert( v!=0 );
@@ -93951,11 +94010,13 @@
94010 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
94011 for(i=0; i<pIdx->nColumn; i++){
94012 int iField = pIdx->aiColumn[i];
94013 int x;
94014 if( iField<0 || iField==pTab->iPKey ){
94015 if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
94016 x = regNewData;
94017 regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
94018 }else{
94019 x = iField + regNewData + 1;
94020 }
94021 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94022 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
@@ -98780,11 +98841,15 @@
98841
98842 /*
98843 ** Free all memory allocations in the pParse object
98844 */
98845 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
98846 if( pParse ){
98847 sqlite3 *db = pParse->db;
98848 sqlite3DbFree(db, pParse->aLabel);
98849 sqlite3ExprListDelete(db, pParse->pConstExpr);
98850 }
98851 }
98852
98853 /*
98854 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
98855 */
@@ -113528,13 +113593,16 @@
113593 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113594
113595 /* Special case: a WHERE clause that is constant. Evaluate the
113596 ** expression and either jump over all of the code or fall thru.
113597 */
113598 for(ii=0; ii<sWLB.pWC->nTerm; ii++){
113599 if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){
113600 sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak,
113601 SQLITE_JUMPIFNULL);
113602 sWLB.pWC->a[ii].wtFlags |= TERM_CODED;
113603 }
113604 }
113605
113606 /* Special case: No FROM clause
113607 */
113608 if( nTabList==0 ){
@@ -121784,11 +121852,11 @@
121852 ** Reset the PRNG back to its uninitialized state. The next call
121853 ** to sqlite3_randomness() will reseed the PRNG using a single call
121854 ** to the xRandomness method of the default VFS.
121855 */
121856 case SQLITE_TESTCTRL_PRNG_RESET: {
121857 sqlite3_randomness(0,0);
121858 break;
121859 }
121860
121861 /*
121862 ** sqlite3_test_control(BITVEC_TEST, size, program)
@@ -124767,10 +124835,23 @@
124835 sqlite3_vtab **ppVtab, /* OUT: New sqlite3_vtab object */
124836 char **pzErr /* OUT: sqlite3_malloc'd error message */
124837 ){
124838 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
124839 }
124840
124841 /*
124842 ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
124843 ** extension is currently being used by a version of SQLite too old to
124844 ** support estimatedRows. In that case this function is a no-op.
124845 */
124846 static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
124847 #if SQLITE_VERSION_NUMBER>=3008002
124848 if( sqlite3_libversion_number()>=3008002 ){
124849 pIdxInfo->estimatedRows = nRow;
124850 }
124851 #endif
124852 }
124853
124854 /*
124855 ** Implementation of the xBestIndex method for FTS3 tables. There
124856 ** are three possible strategies, in order of preference:
124857 **
@@ -124795,11 +124876,24 @@
124876 pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124877 pInfo->estimatedCost = 5000000;
124878 for(i=0; i<pInfo->nConstraint; i++){
124879 int bDocid; /* True if this constraint is on docid */
124880 struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
124881 if( pCons->usable==0 ){
124882 if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){
124883 /* There exists an unusable MATCH constraint. This means that if
124884 ** the planner does elect to use the results of this call as part
124885 ** of the overall query plan the user will see an "unable to use
124886 ** function MATCH in the requested context" error. To discourage
124887 ** this, return a very high cost here. */
124888 pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124889 pInfo->estimatedCost = 1e50;
124890 setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50);
124891 return SQLITE_OK;
124892 }
124893 continue;
124894 }
124895
124896 bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
124897
124898 /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
124899 if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
124900
+7 -5
--- 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.3"
111111
#define SQLITE_VERSION_NUMBER 3008003
112
-#define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d"
112
+#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -2398,15 +2398,17 @@
23982398
** already uses the largest possible [ROWID]. The PRNG is also used for
23992399
** the build-in random() and randomblob() SQL functions. This interface allows
24002400
** applications to access the same PRNG for other purposes.
24012401
**
24022402
** ^A call to this routine stores N bytes of randomness into buffer P.
2403
+** ^If N is less than one, then P can be a NULL pointer.
24032404
**
2404
-** ^The first time this routine is invoked (either internally or by
2405
-** the application) the PRNG is seeded using randomness obtained
2406
-** from the xRandomness method of the default [sqlite3_vfs] object.
2407
-** ^On all subsequent invocations, the pseudo-randomness is generated
2405
+** ^If this routine has not been previously called or if the previous
2406
+** call had N less than one, then the PRNG is seeded using randomness
2407
+** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2408
+** ^If the previous call to this routine had an N of 1 or more then
2409
+** the pseudo-randomness is generated
24082410
** internally and without recourse to the [sqlite3_vfs] xRandomness
24092411
** method.
24102412
*/
24112413
SQLITE_API void sqlite3_randomness(int N, void *P);
24122414
24132415
--- 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.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2013-12-23 11:33:32 25b8a1c9ba77df3b7c78cbce922cb593d661696d"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2398,15 +2398,17 @@
2398 ** already uses the largest possible [ROWID]. The PRNG is also used for
2399 ** the build-in random() and randomblob() SQL functions. This interface allows
2400 ** applications to access the same PRNG for other purposes.
2401 **
2402 ** ^A call to this routine stores N bytes of randomness into buffer P.
 
2403 **
2404 ** ^The first time this routine is invoked (either internally or by
2405 ** the application) the PRNG is seeded using randomness obtained
2406 ** from the xRandomness method of the default [sqlite3_vfs] object.
2407 ** ^On all subsequent invocations, the pseudo-randomness is generated
 
2408 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2409 ** method.
2410 */
2411 SQLITE_API void sqlite3_randomness(int N, void *P);
2412
2413
--- 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.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -2398,15 +2398,17 @@
2398 ** already uses the largest possible [ROWID]. The PRNG is also used for
2399 ** the build-in random() and randomblob() SQL functions. This interface allows
2400 ** applications to access the same PRNG for other purposes.
2401 **
2402 ** ^A call to this routine stores N bytes of randomness into buffer P.
2403 ** ^If N is less than one, then P can be a NULL pointer.
2404 **
2405 ** ^If this routine has not been previously called or if the previous
2406 ** call had N less than one, then the PRNG is seeded using randomness
2407 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2408 ** ^If the previous call to this routine had an N of 1 or more then
2409 ** the pseudo-randomness is generated
2410 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2411 ** method.
2412 */
2413 SQLITE_API void sqlite3_randomness(int N, void *P);
2414
2415

Keyboard Shortcuts

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