Fossil SCM

Update the build-in SQLite to the 3.8.1 alpha from upstream, for the purpose of testing SQLite.

drh 2013-09-17 13:31 trunk
Commit 02d3f53305aa1c6589b9e61e738778b57b4d37f0
3 files changed +7 -3 +970 -523 +1 -1
+7 -3
--- src/shell.c
+++ src/shell.c
@@ -1192,21 +1192,25 @@
11921192
rc = SQLITE_NOMEM;
11931193
}else{
11941194
char **azCols = (char **)pData; /* Names of result columns */
11951195
char **azVals = &azCols[nCol]; /* Results */
11961196
int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1197
- int i;
1197
+ int i, x;
11981198
assert(sizeof(int) <= sizeof(char *));
11991199
/* save off ptrs to column names */
12001200
for(i=0; i<nCol; i++){
12011201
azCols[i] = (char *)sqlite3_column_name(pStmt, i);
12021202
}
12031203
do{
12041204
/* extract the data and data types */
12051205
for(i=0; i<nCol; i++){
1206
- azVals[i] = (char *)sqlite3_column_text(pStmt, i);
1207
- aiTypes[i] = sqlite3_column_type(pStmt, i);
1206
+ aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1207
+ if( x==SQLITE_BLOB && pArg->mode==MODE_Insert ){
1208
+ azVals[i] = "";
1209
+ }else{
1210
+ azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1211
+ }
12081212
if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
12091213
rc = SQLITE_NOMEM;
12101214
break; /* from for */
12111215
}
12121216
} /* end for */
12131217
--- src/shell.c
+++ src/shell.c
@@ -1192,21 +1192,25 @@
1192 rc = SQLITE_NOMEM;
1193 }else{
1194 char **azCols = (char **)pData; /* Names of result columns */
1195 char **azVals = &azCols[nCol]; /* Results */
1196 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1197 int i;
1198 assert(sizeof(int) <= sizeof(char *));
1199 /* save off ptrs to column names */
1200 for(i=0; i<nCol; i++){
1201 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1202 }
1203 do{
1204 /* extract the data and data types */
1205 for(i=0; i<nCol; i++){
1206 azVals[i] = (char *)sqlite3_column_text(pStmt, i);
1207 aiTypes[i] = sqlite3_column_type(pStmt, i);
 
 
 
 
1208 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1209 rc = SQLITE_NOMEM;
1210 break; /* from for */
1211 }
1212 } /* end for */
1213
--- src/shell.c
+++ src/shell.c
@@ -1192,21 +1192,25 @@
1192 rc = SQLITE_NOMEM;
1193 }else{
1194 char **azCols = (char **)pData; /* Names of result columns */
1195 char **azVals = &azCols[nCol]; /* Results */
1196 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1197 int i, x;
1198 assert(sizeof(int) <= sizeof(char *));
1199 /* save off ptrs to column names */
1200 for(i=0; i<nCol; i++){
1201 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1202 }
1203 do{
1204 /* extract the data and data types */
1205 for(i=0; i<nCol; i++){
1206 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1207 if( x==SQLITE_BLOB && pArg->mode==MODE_Insert ){
1208 azVals[i] = "";
1209 }else{
1210 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1211 }
1212 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1213 rc = SQLITE_NOMEM;
1214 break; /* from for */
1215 }
1216 } /* end for */
1217
+970 -523
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656656
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657657
** [sqlite_version()] and [sqlite_source_id()].
658658
*/
659659
#define SQLITE_VERSION "3.8.1"
660660
#define SQLITE_VERSION_NUMBER 3008001
661
-#define SQLITE_SOURCE_ID "2013-09-04 04:04:08 8df95bb0b3f72222cf262174247a467c234f9939"
661
+#define SQLITE_SOURCE_ID "2013-09-16 12:57:19 daf6ba413cb3cb6065774ba07495eab4a28b49b0"
662662
663663
/*
664664
** CAPI3REF: Run-Time Library Version Numbers
665665
** KEYWORDS: sqlite3_version, sqlite3_sourceid
666666
**
@@ -10143,12 +10143,10 @@
1014310143
#endif
1014410144
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
1014510145
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
1014610146
void *pCollNeededArg;
1014710147
sqlite3_value *pErr; /* Most recent error message */
10148
- char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
10149
- char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
1015010148
union {
1015110149
volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
1015210150
double notUsed1; /* Spacer */
1015310151
} u1;
1015410152
Lookaside lookaside; /* Lookaside malloc configuration */
@@ -10254,10 +10252,11 @@
1025410252
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1025510253
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1025610254
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
1025710255
#define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
1025810256
#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10257
+#define SQLITE_AdjustOutEst 0x1000 /* Adjust output estimates using WHERE */
1025910258
#define SQLITE_AllOpts 0xffff /* All optimizations */
1026010259
1026110260
/*
1026210261
** Macros for testing whether or not optimizations are enabled or disabled.
1026310262
*/
@@ -10287,12 +10286,11 @@
1028710286
** hash table. When multiple functions have the same name, the hash table
1028810287
** points to a linked list of these structures.
1028910288
*/
1029010289
struct FuncDef {
1029110290
i16 nArg; /* Number of arguments. -1 means unlimited */
10292
- u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
10293
- u8 flags; /* Some combination of SQLITE_FUNC_* */
10291
+ u16 funcFlags; /* Some combination of SQLITE_FUNC_* */
1029410292
void *pUserData; /* User data parameter */
1029510293
FuncDef *pNext; /* Next function with same name */
1029610294
void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
1029710295
void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
1029810296
void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
@@ -10324,18 +10322,20 @@
1032410322
/*
1032510323
** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
1032610324
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There
1032710325
** are assert() statements in the code to verify this.
1032810326
*/
10329
-#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
10330
-#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
10331
-#define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */
10332
-#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
10333
-#define SQLITE_FUNC_COUNT 0x10 /* Built-in count(*) aggregate */
10334
-#define SQLITE_FUNC_COALESCE 0x20 /* Built-in coalesce() or ifnull() function */
10335
-#define SQLITE_FUNC_LENGTH 0x40 /* Built-in length() function */
10336
-#define SQLITE_FUNC_TYPEOF 0x80 /* Built-in typeof() function */
10327
+#define SQLITE_FUNC_ENCMASK 0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
10328
+#define SQLITE_FUNC_LIKE 0x004 /* Candidate for the LIKE optimization */
10329
+#define SQLITE_FUNC_CASE 0x008 /* Case-sensitive LIKE-type function */
10330
+#define SQLITE_FUNC_EPHEM 0x010 /* Ephemeral. Delete with VDBE */
10331
+#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
10332
+#define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
10333
+#define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10334
+#define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10335
+#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10336
+#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
1033710337
1033810338
/*
1033910339
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1034010340
** used to create the initializers for the FuncDef structures.
1034110341
**
@@ -10359,22 +10359,22 @@
1035910359
** available as the function user-data (sqlite3_user_data()). The
1036010360
** FuncDef.flags variable is set to the value passed as the flags
1036110361
** parameter.
1036210362
*/
1036310363
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
10364
- {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL), \
10364
+ {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1036510365
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1036610366
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10367
- {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
10367
+ {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
1036810368
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1036910369
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10370
- {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
10370
+ {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1037110371
pArg, 0, xFunc, 0, 0, #zName, 0, 0}
1037210372
#define LIKEFUNC(zName, nArg, arg, flags) \
10373
- {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10373
+ {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
1037410374
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10375
- {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
10375
+ {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
1037610376
SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
1037710377
1037810378
/*
1037910379
** All current savepoints are stored in a linked list starting at
1038010380
** sqlite3.pSavepoint. The first element in the list is the most recently
@@ -10945,11 +10945,11 @@
1094510945
** allocated, regardless of whether or not EP_Reduced is set.
1094610946
*/
1094710947
struct Expr {
1094810948
u8 op; /* Operation performed by this node */
1094910949
char affinity; /* The affinity of the column or 0 if not a column */
10950
- u16 flags; /* Various flags. EP_* See below */
10950
+ u32 flags; /* Various flags. EP_* See below */
1095110951
union {
1095210952
char *zToken; /* Token value. Zero terminated and dequoted */
1095310953
int iValue; /* Non-negative integer value if EP_IntValue */
1095410954
} u;
1095510955
@@ -10959,12 +10959,12 @@
1095910959
*********************************************************************/
1096010960
1096110961
Expr *pLeft; /* Left subnode */
1096210962
Expr *pRight; /* Right subnode */
1096310963
union {
10964
- ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */
10965
- Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */
10964
+ ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */
10965
+ Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */
1096610966
} x;
1096710967
1096810968
/* If the EP_Reduced flag is set in the Expr.flags mask, then no
1096910969
** space is allocated for the fields below this point. An attempt to
1097010970
** access them will result in a segfault or malfunction.
@@ -10973,16 +10973,16 @@
1097310973
#if SQLITE_MAX_EXPR_DEPTH>0
1097410974
int nHeight; /* Height of the tree headed by this node */
1097510975
#endif
1097610976
int iTable; /* TK_COLUMN: cursor number of table holding column
1097710977
** TK_REGISTER: register number
10978
- ** TK_TRIGGER: 1 -> new, 0 -> old */
10978
+ ** TK_TRIGGER: 1 -> new, 0 -> old
10979
+ ** EP_Unlikely: 1000 times likelihood */
1097910980
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1098010981
** TK_VARIABLE: variable number (always >= 1). */
1098110982
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
1098210983
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
10983
- u8 flags2; /* Second set of flags. EP2_... */
1098410984
u8 op2; /* TK_REGISTER: original value of Expr.op
1098510985
** TK_COLUMN: the value of p5 for OP_Column
1098610986
** TK_AGG_FUNCTION: nesting depth */
1098710987
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
1098810988
Table *pTab; /* Table for TK_COLUMN expressions. */
@@ -10989,53 +10989,48 @@
1098910989
};
1099010990
1099110991
/*
1099210992
** The following are the meanings of bits in the Expr.flags field.
1099310993
*/
10994
-#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
10995
-#define EP_Agg 0x0002 /* Contains one or more aggregate functions */
10996
-#define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
10997
-#define EP_Error 0x0008 /* Expression contains one or more errors */
10998
-#define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */
10999
-#define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
11000
-#define EP_DblQuoted 0x0040 /* token.z was originally in "..." */
11001
-#define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */
11002
-#define EP_Collate 0x0100 /* Tree contains a TK_COLLATE opeartor */
11003
-#define EP_FixedDest 0x0200 /* Result needed in a specific register */
11004
-#define EP_IntValue 0x0400 /* Integer value contained in u.iValue */
11005
-#define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */
11006
-#define EP_Hint 0x1000 /* Not used */
11007
-#define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */
11008
-#define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */
11009
-#define EP_Static 0x8000 /* Held in memory not obtained from malloc() */
11010
-
11011
-/*
11012
-** The following are the meanings of bits in the Expr.flags2 field.
11013
-*/
11014
-#define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */
11015
-#define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */
11016
-
11017
-/*
11018
-** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible
11019
-** flag on an expression structure. This flag is used for VV&A only. The
11020
-** routine is implemented as a macro that only works when in debugging mode,
11021
-** so as not to burden production code.
11022
-*/
11023
-#ifdef SQLITE_DEBUG
11024
-# define ExprSetIrreducible(X) (X)->flags2 |= EP2_Irreducible
11025
-#else
11026
-# define ExprSetIrreducible(X)
11027
-#endif
10994
+#define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */
10995
+#define EP_Agg 0x000002 /* Contains one or more aggregate functions */
10996
+#define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */
10997
+#define EP_Error 0x000008 /* Expression contains one or more errors */
10998
+#define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
10999
+#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
11000
+#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
11001
+#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
11002
+#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11003
+#define EP_FixedDest 0x000200 /* Result needed in a specific register */
11004
+#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
11005
+#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
11006
+#define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
11007
+#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
11008
+#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11009
+#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11010
+#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11011
+#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11012
+#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
1102811013
1102911014
/*
1103011015
** These macros can be used to test, set, or clear bits in the
1103111016
** Expr.flags field.
1103211017
*/
11033
-#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
11034
-#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
11018
+#define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
11019
+#define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
1103511020
#define ExprSetProperty(E,P) (E)->flags|=(P)
1103611021
#define ExprClearProperty(E,P) (E)->flags&=~(P)
11022
+
11023
+/* The ExprSetVVAProperty() macro is used for Verification, Validation,
11024
+** and Accreditation only. It works like ExprSetProperty() during VVA
11025
+** processes but is a no-op for delivery.
11026
+*/
11027
+#ifdef SQLITE_DEBUG
11028
+# define ExprSetVVAProperty(E,P) (E)->flags|=(P)
11029
+#else
11030
+# define ExprSetVVAProperty(E,P)
11031
+#endif
1103711032
1103811033
/*
1103911034
** Macros to determine the number of bytes required by a normal Expr
1104011035
** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
1104111036
** and an Expr struct with the EP_TokenOnly flag set.
@@ -12411,10 +12406,11 @@
1241112406
SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
1241212407
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
1241312408
SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
1241412409
SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
1241512410
SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
12411
+SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
1241612412
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
1241712413
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
1241812414
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
1241912415
SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
1242012416
SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
@@ -12431,22 +12427,22 @@
1243112427
** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
1243212428
** this case foreign keys are parsed, but no other functionality is
1243312429
** provided (enforcement of FK constraints requires the triggers sub-system).
1243412430
*/
1243512431
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
12436
-SQLITE_PRIVATE void sqlite3FkCheck(Parse*, Table*, int, int);
12432
+SQLITE_PRIVATE void sqlite3FkCheck(Parse*, Table*, int, int, int*, int);
1243712433
SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
12438
-SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int);
12434
+SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
1243912435
SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
1244012436
SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
1244112437
SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
1244212438
#else
12443
- #define sqlite3FkActions(a,b,c,d)
12439
+ #define sqlite3FkActions(a,b,c,d,e,f)
1244412440
#define sqlite3FkCheck(a,b,c,d)
1244512441
#define sqlite3FkDropTable(a,b,c)
12446
- #define sqlite3FkOldmask(a,b) 0
12447
- #define sqlite3FkRequired(a,b,c,d) 0
12442
+ #define sqlite3FkOldmask(a,b) 0
12443
+ #define sqlite3FkRequired(a,b,c,d,e,f) 0
1244812444
#endif
1244912445
#ifndef SQLITE_OMIT_FOREIGN_KEY
1245012446
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
1245112447
SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
1245212448
#else
@@ -13589,10 +13585,11 @@
1358913585
int iStatement; /* Statement number (or 0 if has not opened stmt) */
1359013586
u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */
1359113587
#ifndef SQLITE_OMIT_TRACE
1359213588
i64 startTime; /* Time when query started - used for profiling */
1359313589
#endif
13590
+ i64 iCurrentTime; /* Value of julianday('now') for this statement */
1359413591
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1359513592
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
1359613593
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
1359713594
char *zSql; /* Text of the SQL statement that generated this */
1359813595
void *pFree; /* Free this when deleting the vdbe */
@@ -14268,12 +14265,12 @@
1426814265
** Set the time to the current time reported by the VFS.
1426914266
**
1427014267
** Return the number of errors.
1427114268
*/
1427214269
static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
14273
- sqlite3 *db = sqlite3_context_db_handle(context);
14274
- if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
14270
+ p->iJD = sqlite3StmtCurrentTime(context);
14271
+ if( p->iJD>0 ){
1427514272
p->validJD = 1;
1427614273
return 0;
1427714274
}else{
1427814275
return 1;
1427914276
}
@@ -15052,12 +15049,12 @@
1505215049
char zBuf[20];
1505315050
1505415051
UNUSED_PARAMETER(argc);
1505515052
UNUSED_PARAMETER(argv);
1505615053
15057
- db = sqlite3_context_db_handle(context);
15058
- if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
15054
+ iT = sqlite3StmtCurrentTime(context);
15055
+ if( iT<=0 ) return;
1505915056
t = iT/1000 - 10000*(sqlite3_int64)21086676;
1506015057
#ifdef HAVE_GMTIME_R
1506115058
pTm = gmtime_r(&t, &sNow);
1506215059
#else
1506315060
sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
@@ -19259,10 +19256,11 @@
1925919256
** Free memory that might be associated with a particular database
1926019257
** connection.
1926119258
*/
1926219259
SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
1926319260
assert( db==0 || sqlite3_mutex_held(db->mutex) );
19261
+ if( p==0 ) return;
1926419262
if( db ){
1926519263
if( db->pnBytesFreed ){
1926619264
*db->pnBytesFreed += sqlite3DbMallocSize(db, p);
1926719265
return;
1926819266
}
@@ -21374,11 +21372,12 @@
2137421372
case '"': break;
2137521373
case '`': break; /* For MySQL compatibility */
2137621374
case '[': quote = ']'; break; /* For MS SqlServer compatibility */
2137721375
default: return -1;
2137821376
}
21379
- for(i=1, j=0; ALWAYS(z[i]); i++){
21377
+ for(i=1, j=0;; i++){
21378
+ assert( z[i] );
2138021379
if( z[i]==quote ){
2138121380
if( z[i+1]==quote ){
2138221381
z[j++] = quote;
2138321382
i++;
2138421383
}else{
@@ -30809,10 +30808,18 @@
3080930808
*/
3081030809
#ifndef winIsDirSep
3081130810
# define winIsDirSep(a) (((a) == '/') || ((a) == '\\'))
3081230811
#endif
3081330812
30813
+/*
30814
+** This macro is used when a local variable is set to a value that is
30815
+** [sometimes] not used by the code (e.g. via conditional compilation).
30816
+*/
30817
+#ifndef UNUSED_VARIABLE_VALUE
30818
+# define UNUSED_VARIABLE_VALUE(x) (void)(x)
30819
+#endif
30820
+
3081430821
/*
3081530822
** Returns the string that should be used as the directory separator.
3081630823
*/
3081730824
#ifndef winGetDirDep
3081830825
# ifdef __CYGWIN__
@@ -31059,11 +31066,12 @@
3105931066
** In order to facilitate testing on a WinNT system, the test fixture
3106031067
** can manually set this value to 1 to emulate Win98 behavior.
3106131068
*/
3106231069
#ifdef SQLITE_TEST
3106331070
SQLITE_API int sqlite3_os_type = 0;
31064
-#else
31071
+#elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
31072
+ defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
3106531073
static int sqlite3_os_type = 0;
3106631074
#endif
3106731075
3106831076
#ifndef SYSCALL
3106931077
# define SYSCALL sqlite3_syscall_ptr
@@ -31374,89 +31382,98 @@
3137431382
#endif
3137531383
3137631384
#define osGetVersionExA ((BOOL(WINAPI*)( \
3137731385
LPOSVERSIONINFOA))aSyscall[34].pCurrent)
3137831386
31387
+#if defined(SQLITE_WIN32_HAS_WIDE)
31388
+ { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
31389
+#else
31390
+ { "GetVersionExW", (SYSCALL)0, 0 },
31391
+#endif
31392
+
31393
+#define osGetVersionExW ((BOOL(WINAPI*)( \
31394
+ LPOSVERSIONINFOW))aSyscall[35].pCurrent)
31395
+
3137931396
{ "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
3138031397
3138131398
#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
31382
- SIZE_T))aSyscall[35].pCurrent)
31399
+ SIZE_T))aSyscall[36].pCurrent)
3138331400
3138431401
#if !SQLITE_OS_WINRT
3138531402
{ "HeapCreate", (SYSCALL)HeapCreate, 0 },
3138631403
#else
3138731404
{ "HeapCreate", (SYSCALL)0, 0 },
3138831405
#endif
3138931406
3139031407
#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
31391
- SIZE_T))aSyscall[36].pCurrent)
31408
+ SIZE_T))aSyscall[37].pCurrent)
3139231409
3139331410
#if !SQLITE_OS_WINRT
3139431411
{ "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
3139531412
#else
3139631413
{ "HeapDestroy", (SYSCALL)0, 0 },
3139731414
#endif
3139831415
31399
-#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
31416
+#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[38].pCurrent)
3140031417
3140131418
{ "HeapFree", (SYSCALL)HeapFree, 0 },
3140231419
31403
-#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
31420
+#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[39].pCurrent)
3140431421
3140531422
{ "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
3140631423
3140731424
#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
31408
- SIZE_T))aSyscall[39].pCurrent)
31425
+ SIZE_T))aSyscall[40].pCurrent)
3140931426
3141031427
{ "HeapSize", (SYSCALL)HeapSize, 0 },
3141131428
3141231429
#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
31413
- LPCVOID))aSyscall[40].pCurrent)
31430
+ LPCVOID))aSyscall[41].pCurrent)
3141431431
3141531432
#if !SQLITE_OS_WINRT
3141631433
{ "HeapValidate", (SYSCALL)HeapValidate, 0 },
3141731434
#else
3141831435
{ "HeapValidate", (SYSCALL)0, 0 },
3141931436
#endif
3142031437
3142131438
#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
31422
- LPCVOID))aSyscall[41].pCurrent)
31439
+ LPCVOID))aSyscall[42].pCurrent)
3142331440
3142431441
#if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
3142531442
{ "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
3142631443
#else
3142731444
{ "LoadLibraryA", (SYSCALL)0, 0 },
3142831445
#endif
3142931446
31430
-#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
31447
+#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[43].pCurrent)
3143131448
3143231449
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
3143331450
!defined(SQLITE_OMIT_LOAD_EXTENSION)
3143431451
{ "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
3143531452
#else
3143631453
{ "LoadLibraryW", (SYSCALL)0, 0 },
3143731454
#endif
3143831455
31439
-#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
31456
+#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[44].pCurrent)
3144031457
3144131458
#if !SQLITE_OS_WINRT
3144231459
{ "LocalFree", (SYSCALL)LocalFree, 0 },
3144331460
#else
3144431461
{ "LocalFree", (SYSCALL)0, 0 },
3144531462
#endif
3144631463
31447
-#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
31464
+#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[45].pCurrent)
3144831465
3144931466
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3145031467
{ "LockFile", (SYSCALL)LockFile, 0 },
3145131468
#else
3145231469
{ "LockFile", (SYSCALL)0, 0 },
3145331470
#endif
3145431471
3145531472
#ifndef osLockFile
3145631473
#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31457
- DWORD))aSyscall[45].pCurrent)
31474
+ DWORD))aSyscall[46].pCurrent)
3145831475
#endif
3145931476
3146031477
#if !SQLITE_OS_WINCE
3146131478
{ "LockFileEx", (SYSCALL)LockFileEx, 0 },
3146231479
#else
@@ -31463,218 +31480,218 @@
3146331480
{ "LockFileEx", (SYSCALL)0, 0 },
3146431481
#endif
3146531482
3146631483
#ifndef osLockFileEx
3146731484
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
31468
- LPOVERLAPPED))aSyscall[46].pCurrent)
31485
+ LPOVERLAPPED))aSyscall[47].pCurrent)
3146931486
#endif
3147031487
3147131488
#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
3147231489
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
3147331490
#else
3147431491
{ "MapViewOfFile", (SYSCALL)0, 0 },
3147531492
#endif
3147631493
3147731494
#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31478
- SIZE_T))aSyscall[47].pCurrent)
31495
+ SIZE_T))aSyscall[48].pCurrent)
3147931496
3148031497
{ "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
3148131498
3148231499
#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
31483
- int))aSyscall[48].pCurrent)
31500
+ int))aSyscall[49].pCurrent)
3148431501
3148531502
{ "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
3148631503
3148731504
#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
31488
- LARGE_INTEGER*))aSyscall[49].pCurrent)
31505
+ LARGE_INTEGER*))aSyscall[50].pCurrent)
3148931506
3149031507
{ "ReadFile", (SYSCALL)ReadFile, 0 },
3149131508
3149231509
#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
31493
- LPOVERLAPPED))aSyscall[50].pCurrent)
31510
+ LPOVERLAPPED))aSyscall[51].pCurrent)
3149431511
3149531512
{ "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
3149631513
31497
-#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
31514
+#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent)
3149831515
3149931516
#if !SQLITE_OS_WINRT
3150031517
{ "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
3150131518
#else
3150231519
{ "SetFilePointer", (SYSCALL)0, 0 },
3150331520
#endif
3150431521
3150531522
#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
31506
- DWORD))aSyscall[52].pCurrent)
31523
+ DWORD))aSyscall[53].pCurrent)
3150731524
3150831525
#if !SQLITE_OS_WINRT
3150931526
{ "Sleep", (SYSCALL)Sleep, 0 },
3151031527
#else
3151131528
{ "Sleep", (SYSCALL)0, 0 },
3151231529
#endif
3151331530
31514
-#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
31531
+#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[54].pCurrent)
3151531532
3151631533
{ "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
3151731534
3151831535
#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
31519
- LPFILETIME))aSyscall[54].pCurrent)
31536
+ LPFILETIME))aSyscall[55].pCurrent)
3152031537
3152131538
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
3152231539
{ "UnlockFile", (SYSCALL)UnlockFile, 0 },
3152331540
#else
3152431541
{ "UnlockFile", (SYSCALL)0, 0 },
3152531542
#endif
3152631543
3152731544
#ifndef osUnlockFile
3152831545
#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31529
- DWORD))aSyscall[55].pCurrent)
31546
+ DWORD))aSyscall[56].pCurrent)
3153031547
#endif
3153131548
3153231549
#if !SQLITE_OS_WINCE
3153331550
{ "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
3153431551
#else
3153531552
{ "UnlockFileEx", (SYSCALL)0, 0 },
3153631553
#endif
3153731554
3153831555
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31539
- LPOVERLAPPED))aSyscall[56].pCurrent)
31556
+ LPOVERLAPPED))aSyscall[57].pCurrent)
3154031557
3154131558
#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
3154231559
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
3154331560
#else
3154431561
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
3154531562
#endif
3154631563
31547
-#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
31564
+#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[58].pCurrent)
3154831565
3154931566
{ "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
3155031567
3155131568
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
31552
- LPCSTR,LPBOOL))aSyscall[58].pCurrent)
31569
+ LPCSTR,LPBOOL))aSyscall[59].pCurrent)
3155331570
3155431571
{ "WriteFile", (SYSCALL)WriteFile, 0 },
3155531572
3155631573
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
31557
- LPOVERLAPPED))aSyscall[59].pCurrent)
31574
+ LPOVERLAPPED))aSyscall[60].pCurrent)
3155831575
3155931576
#if SQLITE_OS_WINRT
3156031577
{ "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
3156131578
#else
3156231579
{ "CreateEventExW", (SYSCALL)0, 0 },
3156331580
#endif
3156431581
3156531582
#define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
31566
- DWORD,DWORD))aSyscall[60].pCurrent)
31583
+ DWORD,DWORD))aSyscall[61].pCurrent)
3156731584
3156831585
#if !SQLITE_OS_WINRT
3156931586
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
3157031587
#else
3157131588
{ "WaitForSingleObject", (SYSCALL)0, 0 },
3157231589
#endif
3157331590
3157431591
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
31575
- DWORD))aSyscall[61].pCurrent)
31592
+ DWORD))aSyscall[62].pCurrent)
3157631593
3157731594
#if SQLITE_OS_WINRT
3157831595
{ "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
3157931596
#else
3158031597
{ "WaitForSingleObjectEx", (SYSCALL)0, 0 },
3158131598
#endif
3158231599
3158331600
#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
31584
- BOOL))aSyscall[62].pCurrent)
31601
+ BOOL))aSyscall[63].pCurrent)
3158531602
3158631603
#if SQLITE_OS_WINRT
3158731604
{ "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
3158831605
#else
3158931606
{ "SetFilePointerEx", (SYSCALL)0, 0 },
3159031607
#endif
3159131608
3159231609
#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
31593
- PLARGE_INTEGER,DWORD))aSyscall[63].pCurrent)
31610
+ PLARGE_INTEGER,DWORD))aSyscall[64].pCurrent)
3159431611
3159531612
#if SQLITE_OS_WINRT
3159631613
{ "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
3159731614
#else
3159831615
{ "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
3159931616
#endif
3160031617
3160131618
#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
31602
- FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[64].pCurrent)
31619
+ FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[65].pCurrent)
3160331620
3160431621
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3160531622
{ "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
3160631623
#else
3160731624
{ "MapViewOfFileFromApp", (SYSCALL)0, 0 },
3160831625
#endif
3160931626
3161031627
#define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
31611
- SIZE_T))aSyscall[65].pCurrent)
31628
+ SIZE_T))aSyscall[66].pCurrent)
3161231629
3161331630
#if SQLITE_OS_WINRT
3161431631
{ "CreateFile2", (SYSCALL)CreateFile2, 0 },
3161531632
#else
3161631633
{ "CreateFile2", (SYSCALL)0, 0 },
3161731634
#endif
3161831635
3161931636
#define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
31620
- LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[66].pCurrent)
31637
+ LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[67].pCurrent)
3162131638
3162231639
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_LOAD_EXTENSION)
3162331640
{ "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
3162431641
#else
3162531642
{ "LoadPackagedLibrary", (SYSCALL)0, 0 },
3162631643
#endif
3162731644
3162831645
#define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
31629
- DWORD))aSyscall[67].pCurrent)
31646
+ DWORD))aSyscall[68].pCurrent)
3163031647
3163131648
#if SQLITE_OS_WINRT
3163231649
{ "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
3163331650
#else
3163431651
{ "GetTickCount64", (SYSCALL)0, 0 },
3163531652
#endif
3163631653
31637
-#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[68].pCurrent)
31654
+#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[69].pCurrent)
3163831655
3163931656
#if SQLITE_OS_WINRT
3164031657
{ "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
3164131658
#else
3164231659
{ "GetNativeSystemInfo", (SYSCALL)0, 0 },
3164331660
#endif
3164431661
3164531662
#define osGetNativeSystemInfo ((VOID(WINAPI*)( \
31646
- LPSYSTEM_INFO))aSyscall[69].pCurrent)
31663
+ LPSYSTEM_INFO))aSyscall[70].pCurrent)
3164731664
3164831665
#if defined(SQLITE_WIN32_HAS_ANSI)
3164931666
{ "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
3165031667
#else
3165131668
{ "OutputDebugStringA", (SYSCALL)0, 0 },
3165231669
#endif
3165331670
31654
-#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[70].pCurrent)
31671
+#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[71].pCurrent)
3165531672
3165631673
#if defined(SQLITE_WIN32_HAS_WIDE)
3165731674
{ "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
3165831675
#else
3165931676
{ "OutputDebugStringW", (SYSCALL)0, 0 },
3166031677
#endif
3166131678
31662
-#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[71].pCurrent)
31679
+#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[72].pCurrent)
3166331680
3166431681
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
3166531682
31666
-#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[72].pCurrent)
31683
+#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[73].pCurrent)
3166731684
3166831685
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
3166931686
{ "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
3167031687
#else
3167131688
{ "CreateFileMappingFromApp", (SYSCALL)0, 0 },
3167231689
#endif
3167331690
3167431691
#define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
31675
- LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[73].pCurrent)
31692
+ LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[74].pCurrent)
3167631693
3167731694
}; /* End of the overrideable system calls */
3167831695
3167931696
/*
3168031697
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -31826,20 +31843,30 @@
3182631843
** API as long as we don't call it when running Win95/98/ME. A call to
3182731844
** this routine is used to determine if the host is Win95/98/ME or
3182831845
** WinNT/2K/XP so that we will know whether or not we can safely call
3182931846
** the LockFileEx() API.
3183031847
*/
31848
+#ifndef NTDDI_WIN8
31849
+# define NTDDI_WIN8 0x06020000
31850
+#endif
31851
+
3183131852
#if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
3183231853
# define osIsNT() (1)
3183331854
#elif !defined(SQLITE_WIN32_HAS_WIDE)
3183431855
# define osIsNT() (0)
3183531856
#else
3183631857
static int osIsNT(void){
3183731858
if( sqlite3_os_type==0 ){
31859
+#if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
31860
+ OSVERSIONINFOW sInfo;
31861
+ sInfo.dwOSVersionInfoSize = sizeof(sInfo);
31862
+ osGetVersionExW(&sInfo);
31863
+#else
3183831864
OSVERSIONINFOA sInfo;
3183931865
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
3184031866
osGetVersionExA(&sInfo);
31867
+#endif
3184131868
sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
3184231869
}
3184331870
return sqlite3_os_type==2;
3184431871
}
3184531872
#endif
@@ -31860,11 +31887,11 @@
3186031887
assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3186131888
#endif
3186231889
assert( nBytes>=0 );
3186331890
p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
3186431891
if( !p ){
31865
- sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
31892
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%lu), heap=%p",
3186631893
nBytes, osGetLastError(), (void*)hHeap);
3186731894
}
3186831895
return p;
3186931896
}
3187031897
@@ -31881,11 +31908,11 @@
3188131908
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3188231909
assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
3188331910
#endif
3188431911
if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
3188531912
if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
31886
- sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
31913
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%lu), heap=%p",
3188731914
pPrior, osGetLastError(), (void*)hHeap);
3188831915
}
3188931916
}
3189031917
3189131918
/*
@@ -31907,11 +31934,11 @@
3190731934
p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
3190831935
}else{
3190931936
p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
3191031937
}
3191131938
if( !p ){
31912
- sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
31939
+ sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%lu), heap=%p",
3191331940
pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(),
3191431941
(void*)hHeap);
3191531942
}
3191631943
return p;
3191731944
}
@@ -31931,11 +31958,11 @@
3193131958
assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3193231959
#endif
3193331960
if( !p ) return 0;
3193431961
n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
3193531962
if( n==(SIZE_T)-1 ){
31936
- sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
31963
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%lu), heap=%p",
3193731964
p, osGetLastError(), (void*)hHeap);
3193831965
return 0;
3193931966
}
3194031967
return (int)n;
3194131968
}
@@ -31961,11 +31988,11 @@
3196131988
pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
3196231989
SQLITE_WIN32_HEAP_INIT_SIZE,
3196331990
SQLITE_WIN32_HEAP_MAX_SIZE);
3196431991
if( !pWinMemData->hHeap ){
3196531992
sqlite3_log(SQLITE_NOMEM,
31966
- "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u",
31993
+ "failed to HeapCreate (%lu), flags=%u, initSize=%u, maxSize=%u",
3196731994
osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
3196831995
SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
3196931996
return SQLITE_NOMEM;
3197031997
}
3197131998
pWinMemData->bOwned = TRUE;
@@ -31973,11 +32000,11 @@
3197332000
}
3197432001
#else
3197532002
pWinMemData->hHeap = osGetProcessHeap();
3197632003
if( !pWinMemData->hHeap ){
3197732004
sqlite3_log(SQLITE_NOMEM,
31978
- "failed to GetProcessHeap (%d)", osGetLastError());
32005
+ "failed to GetProcessHeap (%lu)", osGetLastError());
3197932006
return SQLITE_NOMEM;
3198032007
}
3198132008
pWinMemData->bOwned = FALSE;
3198232009
assert( !pWinMemData->bOwned );
3198332010
#endif
@@ -32001,11 +32028,11 @@
3200132028
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
3200232029
assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
3200332030
#endif
3200432031
if( pWinMemData->bOwned ){
3200532032
if( !osHeapDestroy(pWinMemData->hHeap) ){
32006
- sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
32033
+ sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%lu), heap=%p",
3200732034
osGetLastError(), (void*)pWinMemData->hHeap);
3200832035
}
3200932036
pWinMemData->bOwned = FALSE;
3201032037
}
3201132038
pWinMemData->hHeap = NULL;
@@ -33886,26 +33913,27 @@
3388633913
** by VFS shared-memory methods.
3388733914
*/
3388833915
static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
3388933916
winShmNode **pp;
3389033917
winShmNode *p;
33891
- BOOL bRc;
3389233918
assert( winShmMutexHeld() );
3389333919
OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
3389433920
osGetCurrentProcessId(), deleteFlag));
3389533921
pp = &winShmNodeList;
3389633922
while( (p = *pp)!=0 ){
3389733923
if( p->nRef==0 ){
3389833924
int i;
3389933925
if( p->mutex ) sqlite3_mutex_free(p->mutex);
3390033926
for(i=0; i<p->nRegion; i++){
33901
- bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
33927
+ BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
3390233928
OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
3390333929
osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
33930
+ UNUSED_VARIABLE_VALUE(bRc);
3390433931
bRc = osCloseHandle(p->aRegion[i].hMap);
3390533932
OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
3390633933
osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
33934
+ UNUSED_VARIABLE_VALUE(bRc);
3390733935
}
3390833936
if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
3390933937
SimulateIOErrorBenign(1);
3391033938
winClose((sqlite3_file *)&p->hFile);
3391133939
SimulateIOErrorBenign(0);
@@ -34620,10 +34648,11 @@
3462034648
**
3462134649
** This division contains the implementation of methods on the
3462234650
** sqlite3_vfs object.
3462334651
*/
3462434652
34653
+#if 0
3462534654
/*
3462634655
** Convert a filename from whatever the underlying operating system
3462734656
** supports for filenames into UTF-8. Space to hold the result is
3462834657
** obtained from malloc and must be freed by the calling function.
3462934658
*/
@@ -34638,10 +34667,11 @@
3463834667
}
3463934668
#endif
3464034669
/* caller will handle out of memory */
3464134670
return zConverted;
3464234671
}
34672
+#endif
3464334673
3464434674
/*
3464534675
** Convert a UTF-8 filename into whatever form the underlying
3464634676
** operating system wants filenames in. Space to hold the result
3464734677
** is obtained from malloc and must be freed by the calling
@@ -35855,11 +35885,11 @@
3585535885
};
3585635886
#endif
3585735887
3585835888
/* Double-check that the aSyscall[] array has been constructed
3585935889
** correctly. See ticket [bb3a86e890c8e96ab] */
35860
- assert( ArraySize(aSyscall)==74 );
35890
+ assert( ArraySize(aSyscall)==75 );
3586135891
3586235892
/* get memory map allocation granularity */
3586335893
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
3586435894
#if SQLITE_OS_WINRT
3586535895
osGetNativeSystemInfo(&winSysInfo);
@@ -60404,10 +60434,12 @@
6040460434
int iVal, /* Array element to populate */
6040560435
int *pbOk /* OUT: True if value was extracted */
6040660436
){
6040760437
int rc = SQLITE_OK;
6040860438
sqlite3_value *pVal = 0;
60439
+ sqlite3 *db = pParse->db;
60440
+
6040960441
6041060442
struct ValueNewStat4Ctx alloc;
6041160443
alloc.pParse = pParse;
6041260444
alloc.pIdx = pIdx;
6041360445
alloc.ppRec = ppRec;
@@ -60415,11 +60447,11 @@
6041560447
6041660448
/* Skip over any TK_COLLATE nodes */
6041760449
pExpr = sqlite3ExprSkipCollate(pExpr);
6041860450
6041960451
if( !pExpr ){
60420
- pVal = valueNew(pParse->db, &alloc);
60452
+ pVal = valueNew(db, &alloc);
6042160453
if( pVal ){
6042260454
sqlite3VdbeMemSetNull((Mem*)pVal);
6042360455
*pbOk = 1;
6042460456
}
6042560457
}else if( pExpr->op==TK_VARIABLE
@@ -60427,30 +60459,29 @@
6042760459
){
6042860460
Vdbe *v;
6042960461
int iBindVar = pExpr->iColumn;
6043060462
sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
6043160463
if( (v = pParse->pReprepare)!=0 ){
60432
- pVal = valueNew(pParse->db, &alloc);
60464
+ pVal = valueNew(db, &alloc);
6043360465
if( pVal ){
6043460466
rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
6043560467
if( rc==SQLITE_OK ){
60436
- sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
60468
+ sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
6043760469
}
6043860470
pVal->db = pParse->db;
6043960471
*pbOk = 1;
6044060472
sqlite3VdbeMemStoreType((Mem*)pVal);
6044160473
}
6044260474
}else{
6044360475
*pbOk = 0;
6044460476
}
6044560477
}else{
60446
- sqlite3 *db = pParse->db;
6044760478
rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
6044860479
*pbOk = (pVal!=0);
6044960480
}
6045060481
60451
- assert( pVal==0 || pVal->db==pParse->db );
60482
+ assert( pVal==0 || pVal->db==db );
6045260483
return rc;
6045360484
}
6045460485
6045560486
/*
6045660487
** Unless it is NULL, the argument must be an UnpackedRecord object returned
@@ -61114,11 +61145,11 @@
6111461145
/*
6111561146
** If the input FuncDef structure is ephemeral, then free it. If
6111661147
** the FuncDef is not ephermal, then do nothing.
6111761148
*/
6111861149
static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
61119
- if( ALWAYS(pDef) && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
61150
+ if( ALWAYS(pDef) && (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
6112061151
sqlite3DbFree(db, pDef);
6112161152
}
6112261153
}
6112361154
6112461155
static void vdbeFreeOpArray(sqlite3 *, Op *, int);
@@ -64341,10 +64372,11 @@
6434164372
}
6434264373
rc = sqlite3ApiExit(db, rc);
6434364374
sqlite3_mutex_leave(db->mutex);
6434464375
return rc;
6434564376
}
64377
+
6434664378
6434764379
/*
6434864380
** Extract the user data from a sqlite3_context structure and return a
6434964381
** pointer to it.
6435064382
*/
@@ -64365,10 +64397,23 @@
6436564397
*/
6436664398
SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
6436764399
assert( p && p->pFunc );
6436864400
return p->s.db;
6436964401
}
64402
+
64403
+/*
64404
+** Return the current time for a statement
64405
+*/
64406
+SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
64407
+ Vdbe *v = p->pVdbe;
64408
+ int rc;
64409
+ if( v->iCurrentTime==0 ){
64410
+ rc = sqlite3OsCurrentTimeInt64(p->s.db->pVfs, &v->iCurrentTime);
64411
+ if( rc ) v->iCurrentTime = 0;
64412
+ }
64413
+ return v->iCurrentTime;
64414
+}
6437064415
6437164416
/*
6437264417
** The following is the implementation of an SQL function that always
6437364418
** fails with an error message stating that the function is used in the
6437464419
** wrong context. The sqlite3_overload_function() API might construct
@@ -66518,10 +66563,11 @@
6651866563
goto no_mem;
6651966564
}
6652066565
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
6652166566
assert( p->bIsReader || p->readOnly!=0 );
6652266567
p->rc = SQLITE_OK;
66568
+ p->iCurrentTime = 0;
6652366569
assert( p->explain==0 );
6652466570
p->pResultSet = 0;
6652566571
db->busyHandler.nBusy = 0;
6652666572
CHECK_FOR_INTERRUPT;
6652766573
sqlite3VdbeIOTraceSql(p);
@@ -67406,11 +67452,11 @@
6740667452
*/
6740767453
sqlite3VdbeMemMove(&u.ai.ctx.s, pOut);
6740867454
MemSetTypeFlag(&u.ai.ctx.s, MEM_Null);
6740967455
6741067456
u.ai.ctx.fErrorOrAux = 0;
67411
- if( u.ai.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
67457
+ if( u.ai.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
6741267458
assert( pOp>aOp );
6741367459
assert( pOp[-1].p4type==P4_COLLSEQ );
6741467460
assert( pOp[-1].opcode==OP_CollSeq );
6741567461
u.ai.ctx.pColl = pOp[-1].p4.pColl;
6741667462
}
@@ -71506,11 +71552,11 @@
7150671552
u.cg.ctx.s.xDel = 0;
7150771553
u.cg.ctx.s.db = db;
7150871554
u.cg.ctx.isError = 0;
7150971555
u.cg.ctx.pColl = 0;
7151071556
u.cg.ctx.skipFlag = 0;
71511
- if( u.cg.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
71557
+ if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
7151271558
assert( pOp>p->aOp );
7151371559
assert( pOp[-1].p4type==P4_COLLSEQ );
7151471560
assert( pOp[-1].opcode==OP_CollSeq );
7151571561
u.cg.ctx.pColl = pOp[-1].p4.pColl;
7151671562
}
@@ -74434,11 +74480,11 @@
7443474480
if( pExpr==0 ) return WRC_Continue;
7443574481
testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
7443674482
testcase( ExprHasProperty(pExpr, EP_Reduced) );
7443774483
rc = pWalker->xExprCallback(pWalker, pExpr);
7443874484
if( rc==WRC_Continue
74439
- && !ExprHasAnyProperty(pExpr,EP_TokenOnly) ){
74485
+ && !ExprHasProperty(pExpr,EP_TokenOnly) ){
7444074486
if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
7444174487
if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
7444274488
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
7444374489
if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
7444474490
}else{
@@ -74653,10 +74699,11 @@
7465374699
if( pDup==0 ) return;
7465474700
if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
7465574701
incrAggFunctionDepth(pDup, nSubquery);
7465674702
pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
7465774703
if( pDup==0 ) return;
74704
+ ExprSetProperty(pDup, EP_Skip);
7465874705
if( pEList->a[iCol].iAlias==0 ){
7465974706
pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
7466074707
}
7466174708
pDup->iTable = pEList->a[iCol].iAlias;
7466274709
}
@@ -74675,11 +74722,11 @@
7467574722
sqlite3ExprDelete(db, pExpr);
7467674723
memcpy(pExpr, pDup, sizeof(*pExpr));
7467774724
if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
7467874725
assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
7467974726
pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
74680
- pExpr->flags2 |= EP2_MallocedToken;
74727
+ pExpr->flags |= EP_MemToken;
7468174728
}
7468274729
sqlite3DbFree(db, pDup);
7468374730
}
7468474731
7468574732
@@ -74775,16 +74822,16 @@
7477574822
Schema *pSchema = 0; /* Schema of the expression */
7477674823
int isTrigger = 0;
7477774824
7477874825
assert( pNC ); /* the name context cannot be NULL. */
7477974826
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
74780
- assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
74827
+ assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
7478174828
7478274829
/* Initialize the node to no-match */
7478374830
pExpr->iTable = -1;
7478474831
pExpr->pTab = 0;
74785
- ExprSetIrreducible(pExpr);
74832
+ ExprSetVVAProperty(pExpr, EP_NoReduce);
7478674833
7478774834
/* Translate the schema name in zDb into a pointer to the corresponding
7478874835
** schema. If not found, pSchema will remain NULL and nothing will match
7478974836
** resulting in an appropriate error message toward the end of this routine
7479074837
*/
@@ -75116,10 +75163,23 @@
7511675163
}
7511775164
#else
7511875165
# define notValidCheckConstraint(P,N,M)
7511975166
#endif
7512075167
75168
+/*
75169
+** Expression p should encode a floating point value between 1.0 and 0.0.
75170
+** Return 1024 times this value. Or return -1 if p is not a floating point
75171
+** value between 1.0 and 0.0.
75172
+*/
75173
+static int exprProbability(Expr *p){
75174
+ double r = -1.0;
75175
+ if( p->op!=TK_FLOAT ) return -1;
75176
+ sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
75177
+ assert( r>=0.0 );
75178
+ if( r>1.0 ) return -1;
75179
+ return (int)(r*1000.0);
75180
+}
7512175181
7512275182
/*
7512375183
** This routine is callback for sqlite3WalkExpr().
7512475184
**
7512575185
** Resolve symbolic names into TK_COLUMN operators for the current
@@ -75137,11 +75197,11 @@
7513775197
pNC = pWalker->u.pNC;
7513875198
assert( pNC!=0 );
7513975199
pParse = pNC->pParse;
7514075200
assert( pParse==pWalker->pParse );
7514175201
75142
- if( ExprHasAnyProperty(pExpr, EP_Resolved) ) return WRC_Prune;
75202
+ if( ExprHasProperty(pExpr, EP_Resolved) ) return WRC_Prune;
7514375203
ExprSetProperty(pExpr, EP_Resolved);
7514475204
#ifndef NDEBUG
7514575205
if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
7514675206
SrcList *pSrcList = pNC->pSrcList;
7514775207
int i;
@@ -75229,10 +75289,23 @@
7522975289
}else{
7523075290
wrong_num_args = 1;
7523175291
}
7523275292
}else{
7523375293
is_agg = pDef->xFunc==0;
75294
+ if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
75295
+ ExprSetProperty(pExpr, EP_Unlikely|EP_Skip);
75296
+ if( n==2 ){
75297
+ pExpr->iTable = exprProbability(pList->a[1].pExpr);
75298
+ if( pExpr->iTable<0 ){
75299
+ sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a "
75300
+ "constant between 0.0 and 1.0");
75301
+ pNC->nErr++;
75302
+ }
75303
+ }else{
75304
+ pExpr->iTable = 62; /* TUNING: Default 2nd arg to unlikely() is 0.0625 */
75305
+ }
75306
+ }
7523475307
}
7523575308
#ifndef SQLITE_OMIT_AUTHORIZATION
7523675309
if( pDef ){
7523775310
auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
7523875311
if( auth!=SQLITE_OK ){
@@ -76038,11 +76111,11 @@
7603876111
SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr *pExpr, Token *pCollName){
7603976112
if( pCollName->n>0 ){
7604076113
Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1);
7604176114
if( pNew ){
7604276115
pNew->pLeft = pExpr;
76043
- pNew->flags |= EP_Collate;
76116
+ pNew->flags |= EP_Collate|EP_Skip;
7604476117
pExpr = pNew;
7604576118
}
7604676119
}
7604776120
return pExpr;
7604876121
}
@@ -76053,17 +76126,25 @@
7605376126
s.n = sqlite3Strlen30(s.z);
7605476127
return sqlite3ExprAddCollateToken(pParse, pExpr, &s);
7605576128
}
7605676129
7605776130
/*
76058
-** Skip over any TK_COLLATE and/or TK_AS operators at the root of
76059
-** an expression.
76131
+** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
76132
+** or likelihood() function at the root of an expression.
7606076133
*/
7606176134
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
76062
- while( pExpr && (pExpr->op==TK_COLLATE || pExpr->op==TK_AS) ){
76063
- pExpr = pExpr->pLeft;
76064
- }
76135
+ while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
76136
+ if( ExprHasProperty(pExpr, EP_Unlikely) ){
76137
+ assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
76138
+ assert( pExpr->x.pList->nExpr>0 );
76139
+ assert( pExpr->op==TK_FUNCTION );
76140
+ pExpr = pExpr->x.pList->a[0].pExpr;
76141
+ }else{
76142
+ assert( pExpr->op==TK_COLLATE || pExpr->op==TK_AS );
76143
+ pExpr = pExpr->pLeft;
76144
+ }
76145
+ }
7606576146
return pExpr;
7606676147
}
7606776148
7606876149
/*
7606976150
** Return the collation sequence for the expression pExpr. If
@@ -76564,11 +76645,11 @@
7656476645
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
7656576646
sqlite3 *db = pParse->db;
7656676647
const char *z;
7656776648
7656876649
if( pExpr==0 ) return;
76569
- assert( !ExprHasAnyProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
76650
+ assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
7657076651
z = pExpr->u.zToken;
7657176652
assert( z!=0 );
7657276653
assert( z[0]!=0 );
7657376654
if( z[1]==0 ){
7657476655
/* Wildcard of the form "?". Assign the next variable number */
@@ -76634,16 +76715,16 @@
7663476715
*/
7663576716
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
7663676717
if( p==0 ) return;
7663776718
/* Sanity check: Assert that the IntValue is non-negative if it exists */
7663876719
assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
76639
- if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
76720
+ if( !ExprHasProperty(p, EP_TokenOnly) ){
76721
+ /* The Expr.x union is never used at the same time as Expr.pRight */
76722
+ assert( p->x.pList==0 || p->pRight==0 );
7664076723
sqlite3ExprDelete(db, p->pLeft);
7664176724
sqlite3ExprDelete(db, p->pRight);
76642
- if( !ExprHasProperty(p, EP_Reduced) && (p->flags2 & EP2_MallocedToken)!=0 ){
76643
- sqlite3DbFree(db, p->u.zToken);
76644
- }
76725
+ if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
7664576726
if( ExprHasProperty(p, EP_xIsSelect) ){
7664676727
sqlite3SelectDelete(db, p->x.pSelect);
7664776728
}else{
7664876729
sqlite3ExprListDelete(db, p->x.pList);
7664976730
}
@@ -76699,20 +76780,23 @@
7669976780
** to enforce this constraint.
7670076781
*/
7670176782
static int dupedExprStructSize(Expr *p, int flags){
7670276783
int nSize;
7670376784
assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
76785
+ assert( EXPR_FULLSIZE<=0xfff );
76786
+ assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
7670476787
if( 0==(flags&EXPRDUP_REDUCE) ){
7670576788
nSize = EXPR_FULLSIZE;
7670676789
}else{
76707
- assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) );
76790
+ assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
7670876791
assert( !ExprHasProperty(p, EP_FromJoin) );
76709
- assert( (p->flags2 & EP2_MallocedToken)==0 );
76710
- assert( (p->flags2 & EP2_Irreducible)==0 );
76711
- if( p->pLeft || p->pRight || p->x.pList ){
76792
+ assert( !ExprHasProperty(p, EP_MemToken) );
76793
+ assert( !ExprHasProperty(p, EP_NoReduce) );
76794
+ if( p->pLeft || p->x.pList ){
7671276795
nSize = EXPR_REDUCEDSIZE | EP_Reduced;
7671376796
}else{
76797
+ assert( p->pRight==0 );
7671476798
nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly;
7671576799
}
7671676800
}
7671776801
return nSize;
7671876802
}
@@ -76802,11 +76886,11 @@
7680276886
memcpy(zAlloc, p, nSize);
7680376887
memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
7680476888
}
7680576889
7680676890
/* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
76807
- pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static);
76891
+ pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
7680876892
pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
7680976893
pNew->flags |= staticFlag;
7681076894
7681176895
/* Copy the p->u.zToken string, if any. */
7681276896
if( nToken ){
@@ -76822,22 +76906,21 @@
7682276906
pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
7682376907
}
7682476908
}
7682576909
7682676910
/* Fill in pNew->pLeft and pNew->pRight. */
76827
- if( ExprHasAnyProperty(pNew, EP_Reduced|EP_TokenOnly) ){
76911
+ if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
7682876912
zAlloc += dupedExprNodeSize(p, flags);
7682976913
if( ExprHasProperty(pNew, EP_Reduced) ){
7683076914
pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
7683176915
pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
7683276916
}
7683376917
if( pzBuffer ){
7683476918
*pzBuffer = zAlloc;
7683576919
}
7683676920
}else{
76837
- pNew->flags2 = 0;
76838
- if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
76921
+ if( !ExprHasProperty(p, EP_TokenOnly) ){
7683976922
pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
7684076923
pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
7684176924
}
7684276925
}
7684376926
@@ -77143,11 +77226,11 @@
7714377226
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
7714477227
7714577228
/* If pWalker->u.i is 3 then any term of the expression that comes from
7714677229
** the ON or USING clauses of a join disqualifies the expression
7714777230
** from being considered constant. */
77148
- if( pWalker->u.i==3 && ExprHasAnyProperty(pExpr, EP_FromJoin) ){
77231
+ if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
7714977232
pWalker->u.i = 0;
7715077233
return WRC_Abort;
7715177234
}
7715277235
7715377236
switch( pExpr->op ){
@@ -77574,11 +77657,11 @@
7757477657
*prNotFound = rMayHaveNull = ++pParse->nMem;
7757577658
sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
7757677659
}else{
7757777660
testcase( pParse->nQueryLoop>0 );
7757877661
pParse->nQueryLoop = 0;
77579
- if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
77662
+ if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
7758077663
eType = IN_INDEX_ROWID;
7758177664
}
7758277665
}
7758377666
sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
7758477667
pParse->nQueryLoop = savedNQueryLoop;
@@ -77643,11 +77726,11 @@
7764377726
** * We are inside a trigger
7764477727
**
7764577728
** If all of the above are false, then we can run this code just once
7764677729
** save the results, and reuse the same result on subsequent invocations.
7764777730
*/
77648
- if( !ExprHasAnyProperty(pExpr, EP_VarSelect) ){
77731
+ if( !ExprHasProperty(pExpr, EP_VarSelect) ){
7764977732
testAddr = sqlite3CodeOnce(pParse);
7765077733
}
7765177734
7765277735
#ifndef SQLITE_OMIT_EXPLAIN
7765377736
if( pParse->explain==2 ){
@@ -77812,11 +77895,11 @@
7781277895
pSel->iLimit = 0;
7781377896
if( sqlite3Select(pParse, pSel, &dest) ){
7781477897
return 0;
7781577898
}
7781677899
rReg = dest.iSDParm;
77817
- ExprSetIrreducible(pExpr);
77900
+ ExprSetVVAProperty(pExpr, EP_NoReduce);
7781877901
break;
7781977902
}
7782077903
}
7782177904
7782277905
if( testAddr>=0 ){
@@ -78283,10 +78366,20 @@
7828378366
if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
7828478367
}
7828578368
return 0;
7828678369
}
7828778370
#endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
78371
+
78372
+/*
78373
+** Convert an expression node to a TK_REGISTER
78374
+*/
78375
+static void exprToRegister(Expr *p, int iReg){
78376
+ p->op2 = p->op;
78377
+ p->op = TK_REGISTER;
78378
+ p->iTable = iReg;
78379
+ ExprClearProperty(p, EP_Skip);
78380
+}
7828878381
7828978382
/*
7829078383
** Generate code into the current Vdbe to evaluate the given
7829178384
** expression. Attempt to store the results in register "target".
7829278385
** Return the register where results are stored.
@@ -78583,11 +78676,11 @@
7858378676
CollSeq *pColl = 0; /* A collating sequence */
7858478677
7858578678
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
7858678679
testcase( op==TK_CONST_FUNC );
7858778680
testcase( op==TK_FUNCTION );
78588
- if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
78681
+ if( ExprHasProperty(pExpr, EP_TokenOnly) ){
7858978682
pFarg = 0;
7859078683
}else{
7859178684
pFarg = pExpr->x.pList;
7859278685
}
7859378686
nFarg = pFarg ? pFarg->nExpr : 0;
@@ -78602,11 +78695,11 @@
7860278695
7860378696
/* Attempt a direct implementation of the built-in COALESCE() and
7860478697
** IFNULL() functions. This avoids unnecessary evalation of
7860578698
** arguments past the first non-NULL argument.
7860678699
*/
78607
- if( pDef->flags & SQLITE_FUNC_COALESCE ){
78700
+ if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
7860878701
int endCoalesce = sqlite3VdbeMakeLabel(v);
7860978702
assert( nFarg>=2 );
7861078703
sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
7861178704
for(i=1; i<nFarg; i++){
7861278705
sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
@@ -78617,29 +78710,38 @@
7861778710
}
7861878711
sqlite3VdbeResolveLabel(v, endCoalesce);
7861978712
break;
7862078713
}
7862178714
78715
+ /* The UNLIKELY() function is a no-op. The result is the value
78716
+ ** of the first argument.
78717
+ */
78718
+ if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
78719
+ assert( nFarg>=1 );
78720
+ sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
78721
+ break;
78722
+ }
7862278723
7862378724
if( pFarg ){
7862478725
r1 = sqlite3GetTempRange(pParse, nFarg);
7862578726
7862678727
/* For length() and typeof() functions with a column argument,
7862778728
** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
7862878729
** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
7862978730
** loading.
7863078731
*/
78631
- if( (pDef->flags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
78732
+ if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
7863278733
u8 exprOp;
7863378734
assert( nFarg==1 );
7863478735
assert( pFarg->a[0].pExpr!=0 );
7863578736
exprOp = pFarg->a[0].pExpr->op;
7863678737
if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
7863778738
assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
7863878739
assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
78639
- testcase( pDef->flags==SQLITE_FUNC_LENGTH );
78640
- pFarg->a[0].pExpr->op2 = pDef->flags;
78740
+ testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK)
78741
+ ==SQLITE_FUNC_LENGTH );
78742
+ pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK;
7864178743
}
7864278744
}
7864378745
7864478746
sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
7864578747
sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
@@ -78668,15 +78770,15 @@
7866878770
#endif
7866978771
for(i=0; i<nFarg; i++){
7867078772
if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
7867178773
constMask |= (1<<i);
7867278774
}
78673
- if( (pDef->flags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
78775
+ if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
7867478776
pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
7867578777
}
7867678778
}
78677
- if( pDef->flags & SQLITE_FUNC_NEEDCOLL ){
78779
+ if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
7867878780
if( !pColl ) pColl = db->pDfltColl;
7867978781
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
7868078782
}
7868178783
sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
7868278784
(char*)pDef, P4_FUNCDEF);
@@ -78813,13 +78915,13 @@
7881378915
** Form A is can be transformed into the equivalent form B as follows:
7881478916
** CASE WHEN x=e1 THEN r1 WHEN x=e2 THEN r2 ...
7881578917
** WHEN x=eN THEN rN ELSE y END
7881678918
**
7881778919
** X (if it exists) is in pExpr->pLeft.
78818
- ** Y is in pExpr->pRight. The Y is also optional. If there is no
78819
- ** ELSE clause and no other term matches, then the result of the
78820
- ** exprssion is NULL.
78920
+ ** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
78921
+ ** odd. The Y is also optional. If the number of elements in x.pList
78922
+ ** is even, then Y is omitted and the "otherwise" result is NULL.
7882178923
** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
7882278924
**
7882378925
** The result of the expression is the Ri for the first matching Ei,
7882478926
** or if there is no matching Ei, the ELSE term Y, or if there is
7882578927
** no ELSE term, NULL.
@@ -78836,33 +78938,31 @@
7883678938
Expr *pX; /* The X expression */
7883778939
Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
7883878940
VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
7883978941
7884078942
assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
78841
- assert((pExpr->x.pList->nExpr % 2) == 0);
7884278943
assert(pExpr->x.pList->nExpr > 0);
7884378944
pEList = pExpr->x.pList;
7884478945
aListelem = pEList->a;
7884578946
nExpr = pEList->nExpr;
7884678947
endLabel = sqlite3VdbeMakeLabel(v);
7884778948
if( (pX = pExpr->pLeft)!=0 ){
7884878949
cacheX = *pX;
7884978950
testcase( pX->op==TK_COLUMN );
7885078951
testcase( pX->op==TK_REGISTER );
78851
- cacheX.iTable = sqlite3ExprCodeTemp(pParse, pX, &regFree1);
78952
+ exprToRegister(&cacheX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
7885278953
testcase( regFree1==0 );
78853
- cacheX.op = TK_REGISTER;
7885478954
opCompare.op = TK_EQ;
7885578955
opCompare.pLeft = &cacheX;
7885678956
pTest = &opCompare;
7885778957
/* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
7885878958
** The value in regFree1 might get SCopy-ed into the file result.
7885978959
** So make sure that the regFree1 register is not reused for other
7886078960
** purposes and possibly overwritten. */
7886178961
regFree1 = 0;
7886278962
}
78863
- for(i=0; i<nExpr; i=i+2){
78963
+ for(i=0; i<nExpr-1; i=i+2){
7886478964
sqlite3ExprCachePush(pParse);
7886578965
if( pX ){
7886678966
assert( pTest!=0 );
7886778967
opCompare.pRight = aListelem[i].pExpr;
7886878968
}else{
@@ -78876,13 +78976,13 @@
7887678976
sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
7887778977
sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
7887878978
sqlite3ExprCachePop(pParse, 1);
7887978979
sqlite3VdbeResolveLabel(v, nextCase);
7888078980
}
78881
- if( pExpr->pRight ){
78981
+ if( (nExpr&1)!=0 ){
7888278982
sqlite3ExprCachePush(pParse);
78883
- sqlite3ExprCode(pParse, pExpr->pRight, target);
78983
+ sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target);
7888478984
sqlite3ExprCachePop(pParse, 1);
7888578985
}else{
7888678986
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
7888778987
}
7888878988
assert( db->mallocFailed || pParse->nErr>0
@@ -78990,13 +79090,11 @@
7899079090
** modifications or enhancements. */
7899179091
if( ALWAYS(pExpr->op!=TK_REGISTER) ){
7899279092
int iMem;
7899379093
iMem = ++pParse->nMem;
7899479094
sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
78995
- pExpr->iTable = iMem;
78996
- pExpr->op2 = pExpr->op;
78997
- pExpr->op = TK_REGISTER;
79095
+ exprToRegister(pExpr, iMem);
7899879096
}
7899979097
return inReg;
7900079098
}
7900179099
7900279100
#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -79122,11 +79220,11 @@
7912279220
7912379221
case TK_AGG_FUNCTION:
7912479222
case TK_CONST_FUNC:
7912579223
case TK_FUNCTION: {
7912679224
ExprList *pFarg; /* List of function arguments */
79127
- if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
79225
+ if( ExprHasProperty(pExpr, EP_TokenOnly) ){
7912879226
pFarg = 0;
7912979227
}else{
7913079228
pFarg = pExpr->x.pList;
7913179229
}
7913279230
if( op==TK_AGG_FUNCTION ){
@@ -79371,13 +79469,11 @@
7937179469
int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
7937279470
/* If r2!=r1, it means that register r1 is never used. That is harmless
7937379471
** but suboptimal, so we want to know about the situation to fix it.
7937479472
** Hence the following assert: */
7937579473
assert( r2==r1 );
79376
- pExpr->op2 = pExpr->op;
79377
- pExpr->op = TK_REGISTER;
79378
- pExpr->iTable = r2;
79474
+ exprToRegister(pExpr, r2);
7937979475
return WRC_Prune;
7938079476
}
7938179477
return WRC_Continue;
7938279478
}
7938379479
@@ -79471,13 +79567,11 @@
7947179567
compLeft.pLeft = &exprX;
7947279568
compLeft.pRight = pExpr->x.pList->a[0].pExpr;
7947379569
compRight.op = TK_LE;
7947479570
compRight.pLeft = &exprX;
7947579571
compRight.pRight = pExpr->x.pList->a[1].pExpr;
79476
- exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, &regFree1);
79477
- exprX.op2 = exprX.op;
79478
- exprX.op = TK_REGISTER;
79572
+ exprToRegister(&exprX, sqlite3ExprCodeTemp(pParse, &exprX, &regFree1));
7947979573
if( jumpIfTrue ){
7948079574
sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull);
7948179575
}else{
7948279576
sqlite3ExprIfFalse(pParse, &exprAnd, dest, jumpIfNull);
7948379577
}
@@ -79788,12 +79882,12 @@
7978879882
*/
7978979883
SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
7979079884
if( pA==0||pB==0 ){
7979179885
return pB==pA ? 0 : 2;
7979279886
}
79793
- assert( !ExprHasAnyProperty(pA, EP_TokenOnly|EP_Reduced) );
79794
- assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) );
79887
+ assert( !ExprHasProperty(pA, EP_TokenOnly|EP_Reduced) );
79888
+ assert( !ExprHasProperty(pB, EP_TokenOnly|EP_Reduced) );
7979579889
if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
7979679890
return 2;
7979779891
}
7979879892
if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
7979979893
if( pA->op!=pB->op && (pA->op!=TK_REGISTER || pA->op2!=pB->op) ){
@@ -80003,11 +80097,11 @@
8000380097
** clause of the aggregate query */
8000480098
if( ALWAYS(pSrcList!=0) ){
8000580099
struct SrcList_item *pItem = pSrcList->a;
8000680100
for(i=0; i<pSrcList->nSrc; i++, pItem++){
8000780101
struct AggInfo_col *pCol;
80008
- assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
80102
+ assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
8000980103
if( pExpr->iTable==pItem->iCursor ){
8001080104
/* If we reach this point, it means that pExpr refers to a table
8001180105
** that is in the FROM clause of the aggregate query.
8001280106
**
8001380107
** Make an entry for the column in pAggInfo->aCol[] if there
@@ -80052,11 +80146,11 @@
8005280146
/* There is now an entry for pExpr in pAggInfo->aCol[] (either
8005380147
** because it was there before or because we just created it).
8005480148
** Convert the pExpr to be a TK_AGG_COLUMN referring to that
8005580149
** pAggInfo->aCol[] entry.
8005680150
*/
80057
- ExprSetIrreducible(pExpr);
80151
+ ExprSetVVAProperty(pExpr, EP_NoReduce);
8005880152
pExpr->pAggInfo = pAggInfo;
8005980153
pExpr->op = TK_AGG_COLUMN;
8006080154
pExpr->iAgg = (i16)k;
8006180155
break;
8006280156
} /* endif pExpr->iTable==pItem->iCursor */
@@ -80098,12 +80192,12 @@
8009880192
}
8009980193
}
8010080194
}
8010180195
/* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
8010280196
*/
80103
- assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
80104
- ExprSetIrreducible(pExpr);
80197
+ assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
80198
+ ExprSetVVAProperty(pExpr, EP_NoReduce);
8010580199
pExpr->iAgg = (i16)i;
8010680200
pExpr->pAggInfo = pAggInfo;
8010780201
return WRC_Prune;
8010880202
}else{
8010980203
return WRC_Continue;
@@ -81394,11 +81488,11 @@
8139481488
8139581489
p->iGet = -1;
8139681490
p->mxSample = mxSample;
8139781491
p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[1])/(mxSample/3+1) + 1);
8139881492
p->current.anLt = &p->current.anEq[nColUp];
81399
- sqlite3_randomness(sizeof(p->iPrn), &p->iPrn);
81493
+ p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[1])*0xd0944565;
8140081494
8140181495
/* Set up the Stat4Accum.a[] and aBest[] arrays */
8140281496
p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
8140381497
p->aBest = &p->a[mxSample];
8140481498
pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -81418,12 +81512,11 @@
8141881512
/* Return a pointer to the allocated object to the caller */
8141981513
sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
8142081514
}
8142181515
static const FuncDef statInitFuncdef = {
8142281516
1+IsStat34, /* nArg */
81423
- SQLITE_UTF8, /* iPrefEnc */
81424
- 0, /* flags */
81517
+ SQLITE_UTF8, /* funcFlags */
8142581518
0, /* pUserData */
8142681519
0, /* pNext */
8142781520
statInit, /* xFunc */
8142881521
0, /* xStep */
8142981522
0, /* xFinalize */
@@ -81715,12 +81808,11 @@
8171581808
}
8171681809
#endif
8171781810
}
8171881811
static const FuncDef statPushFuncdef = {
8171981812
2+IsStat34, /* nArg */
81720
- SQLITE_UTF8, /* iPrefEnc */
81721
- 0, /* flags */
81813
+ SQLITE_UTF8, /* funcFlags */
8172281814
0, /* pUserData */
8172381815
0, /* pNext */
8172481816
statPush, /* xFunc */
8172581817
0, /* xStep */
8172681818
0, /* xFinalize */
@@ -81851,12 +81943,11 @@
8185181943
}
8185281944
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
8185381945
}
8185481946
static const FuncDef statGetFuncdef = {
8185581947
1+IsStat34, /* nArg */
81856
- SQLITE_UTF8, /* iPrefEnc */
81857
- 0, /* flags */
81948
+ SQLITE_UTF8, /* funcFlags */
8185881949
0, /* pUserData */
8185981950
0, /* pNext */
8186081951
statGet, /* xFunc */
8186181952
0, /* xStep */
8186281953
0, /* xFinalize */
@@ -83056,12 +83147,11 @@
8305683147
** DETACH pDbname
8305783148
*/
8305883149
SQLITE_PRIVATE void sqlite3Detach(Parse *pParse, Expr *pDbname){
8305983150
static const FuncDef detach_func = {
8306083151
1, /* nArg */
83061
- SQLITE_UTF8, /* iPrefEnc */
83062
- 0, /* flags */
83152
+ SQLITE_UTF8, /* funcFlags */
8306383153
0, /* pUserData */
8306483154
0, /* pNext */
8306583155
detachFunc, /* xFunc */
8306683156
0, /* xStep */
8306783157
0, /* xFinalize */
@@ -83078,12 +83168,11 @@
8307883168
** ATTACH p AS pDbname KEY pKey
8307983169
*/
8308083170
SQLITE_PRIVATE void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
8308183171
static const FuncDef attach_func = {
8308283172
3, /* nArg */
83083
- SQLITE_UTF8, /* iPrefEnc */
83084
- 0, /* flags */
83173
+ SQLITE_UTF8, /* funcFlags */
8308583174
0, /* pUserData */
8308683175
0, /* pNext */
8308783176
attachFunc, /* xFunc */
8308883177
0, /* xStep */
8308983178
0, /* xFinalize */
@@ -83188,11 +83277,11 @@
8318883277
SQLITE_PRIVATE int sqlite3FixExpr(
8318983278
DbFixer *pFix, /* Context of the fixation */
8319083279
Expr *pExpr /* The expression to be fixed to one database */
8319183280
){
8319283281
while( pExpr ){
83193
- if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ) break;
83282
+ if( ExprHasProperty(pExpr, EP_TokenOnly) ) break;
8319483283
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
8319583284
if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1;
8319683285
}else{
8319783286
if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1;
8319883287
}
@@ -87589,13 +87678,13 @@
8758987678
}else{
8759087679
match = 1;
8759187680
}
8759287681
8759387682
/* Bonus points if the text encoding matches */
87594
- if( enc==p->iPrefEnc ){
87683
+ if( enc==(p->funcFlags & SQLITE_FUNC_ENCMASK) ){
8759587684
match += 2; /* Exact encoding match */
87596
- }else if( (enc & p->iPrefEnc & 2)!=0 ){
87685
+ }else if( (enc & p->funcFlags & 2)!=0 ){
8759787686
match += 1; /* Both are UTF16, but with different byte orders */
8759887687
}
8759987688
8760087689
return match;
8760187690
}
@@ -87725,11 +87814,11 @@
8772587814
*/
8772687815
if( createFlag && bestScore<FUNC_PERFECT_MATCH &&
8772787816
(pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
8772887817
pBest->zName = (char *)&pBest[1];
8772987818
pBest->nArg = (u16)nArg;
87730
- pBest->iPrefEnc = enc;
87819
+ pBest->funcFlags = enc;
8773187820
memcpy(pBest->zName, zName, nName);
8773287821
pBest->zName[nName] = 0;
8773387822
sqlite3FuncDefInsert(&db->aFunc, pBest);
8773487823
}
8773587824
@@ -88335,11 +88424,11 @@
8833588424
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
8833688425
8833788426
/* Do FK processing. This call checks that any FK constraints that
8833888427
** refer to this table (i.e. constraints attached to other tables)
8833988428
** are not violated by deleting this row. */
88340
- sqlite3FkCheck(pParse, pTab, iOld, 0);
88429
+ sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
8834188430
}
8834288431
8834388432
/* Delete the index and table entries. Skip this step if pTab is really
8834488433
** a view (in which case the only effect of the DELETE statement is to
8834588434
** fire the INSTEAD OF triggers). */
@@ -88352,11 +88441,11 @@
8835288441
}
8835388442
8835488443
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
8835588444
** handle rows (possibly in other tables) that refer via a foreign key
8835688445
** to the row just deleted. */
88357
- sqlite3FkActions(pParse, pTab, 0, iOld);
88446
+ sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
8835888447
8835988448
/* Invoke AFTER DELETE trigger programs. */
8836088449
sqlite3CodeRowTrigger(pParse, pTrigger,
8836188450
TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
8836288451
);
@@ -88891,18 +88980,18 @@
8889188980
}
8889288981
}
8889388982
}
8889488983
8889588984
/*
88896
-** The COALESCE() and IFNULL() functions are implemented as VDBE code so
88897
-** that unused argument values do not have to be computed. However, we
88898
-** still need some kind of function implementation for this routines in
88899
-** the function table. That function implementation will never be called
88900
-** so it doesn't matter what the implementation is. We might as well use
88901
-** the "version()" function as a substitute.
88985
+** Some functions like COALESCE() and IFNULL() and UNLIKELY() are implemented
88986
+** as VDBE code so that unused argument values do not have to be computed.
88987
+** However, we still need some kind of function implementation for this
88988
+** routines in the function table. The noopFunc macro provides this.
88989
+** noopFunc will never be called so it doesn't matter what the implementation
88990
+** is. We might as well use the "version()" function as a substitute.
8890288991
*/
88903
-#define ifnullFunc versionFunc /* Substitute function - never called */
88992
+#define noopFunc versionFunc /* Substitute function - never called */
8890488993
8890588994
/*
8890688995
** Implementation of random(). Return a random integer.
8890788996
*/
8890888997
static void randomFunc(
@@ -89017,13 +89106,13 @@
8901789106
** able to participate in upper-case-to-lower-case mappings in EBCDIC
8901889107
** whereas only characters less than 0x80 do in ASCII.
8901989108
*/
8902089109
#if defined(SQLITE_EBCDIC)
8902189110
# define sqlite3Utf8Read(A) (*((*A)++))
89022
-# define GlogUpperToLower(A) A = sqlite3UpperToLower[A]
89111
+# define GlobUpperToLower(A) A = sqlite3UpperToLower[A]
8902389112
#else
89024
-# define GlogUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
89113
+# define GlobUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
8902589114
#endif
8902689115
8902789116
static const struct compareInfo globInfo = { '*', '?', '[', 0 };
8902889117
/* The correct SQL-92 behavior is for the LIKE operator to ignore
8902989118
** case. Thus 'a' LIKE 'A' would be true. */
@@ -89098,15 +89187,15 @@
8909889187
}
8909989188
return *zString!=0;
8910089189
}
8910189190
while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
8910289191
if( noCase ){
89103
- GlogUpperToLower(c2);
89104
- GlogUpperToLower(c);
89192
+ GlobUpperToLower(c2);
89193
+ GlobUpperToLower(c);
8910589194
while( c2 != 0 && c2 != c ){
8910689195
c2 = sqlite3Utf8Read(&zString);
89107
- GlogUpperToLower(c2);
89196
+ GlobUpperToLower(c2);
8910889197
}
8910989198
}else{
8911089199
while( c2 != 0 && c2 != c ){
8911189200
c2 = sqlite3Utf8Read(&zString);
8911289201
}
@@ -89154,12 +89243,12 @@
8915489243
}else if( esc==c && !prevEscape ){
8915589244
prevEscape = 1;
8915689245
}else{
8915789246
c2 = sqlite3Utf8Read(&zString);
8915889247
if( noCase ){
89159
- GlogUpperToLower(c);
89160
- GlogUpperToLower(c2);
89248
+ GlobUpperToLower(c);
89249
+ GlobUpperToLower(c2);
8916189250
}
8916289251
if( c!=c2 ){
8916389252
return 0;
8916489253
}
8916589254
prevEscape = 0;
@@ -90027,11 +90116,11 @@
9002790116
static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
9002890117
FuncDef *pDef;
9002990118
pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
9003090119
2, SQLITE_UTF8, 0);
9003190120
if( ALWAYS(pDef) ){
90032
- pDef->flags = flagVal;
90121
+ pDef->funcFlags |= flagVal;
9003390122
}
9003490123
}
9003590124
9003690125
/*
9003790126
** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -90071,11 +90160,11 @@
9007190160
}
9007290161
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
9007390162
pDef = sqlite3FindFunction(db, pExpr->u.zToken,
9007490163
sqlite3Strlen30(pExpr->u.zToken),
9007590164
2, SQLITE_UTF8, 0);
90076
- if( NEVER(pDef==0) || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
90165
+ if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
9007790166
return 0;
9007890167
}
9007990168
9008090169
/* The memcpy() statement assumes that the wildcard characters are
9008190170
** the first three statements in the compareInfo structure. The
@@ -90083,11 +90172,11 @@
9008390172
*/
9008490173
memcpy(aWc, pDef->pUserData, 3);
9008590174
assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
9008690175
assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
9008790176
assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
90088
- *pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
90177
+ *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
9008990178
return 1;
9009090179
}
9009190180
9009290181
/*
9009390182
** All all of the FuncDef structures in the aBuiltinFunc[] array above
@@ -90132,13 +90221,15 @@
9013290221
#endif
9013390222
FUNCTION(upper, 1, 0, 0, upperFunc ),
9013490223
FUNCTION(lower, 1, 0, 0, lowerFunc ),
9013590224
FUNCTION(coalesce, 1, 0, 0, 0 ),
9013690225
FUNCTION(coalesce, 0, 0, 0, 0 ),
90137
- FUNCTION2(coalesce, -1, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE),
90226
+ FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
9013890227
FUNCTION(hex, 1, 0, 0, hexFunc ),
90139
- FUNCTION2(ifnull, 2, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE),
90228
+ FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
90229
+ FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
90230
+ FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
9014090231
FUNCTION(random, 0, 0, 0, randomFunc ),
9014190232
FUNCTION(randomblob, 1, 0, 0, randomBlob ),
9014290233
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
9014390234
FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
9014490235
FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -90162,11 +90253,11 @@
9016290253
#endif
9016390254
AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
9016490255
AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
9016590256
AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
9016690257
/* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
90167
- {0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
90258
+ {0,SQLITE_UTF8|SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
9016890259
AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
9016990260
AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
9017090261
AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
9017190262
9017290263
LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -90878,10 +90969,74 @@
9087890969
sqlite3VdbeResolveLabel(v, iSkip);
9087990970
}
9088090971
}
9088190972
}
9088290973
90974
+
90975
+/*
90976
+** The second argument points to an FKey object representing a foreign key
90977
+** for which pTab is the child table. An UPDATE statement against pTab
90978
+** is currently being processed. For each column of the table that is
90979
+** actually updated, the corresponding element in the aChange[] array
90980
+** is zero or greater (if a column is unmodified the corresponding element
90981
+** is set to -1). If the rowid column is modified by the UPDATE statement
90982
+** the bChngRowid argument is non-zero.
90983
+**
90984
+** This function returns true if any of the columns that are part of the
90985
+** child key for FK constraint *p are modified.
90986
+*/
90987
+static int fkChildIsModified(
90988
+ Table *pTab, /* Table being updated */
90989
+ FKey *p, /* Foreign key for which pTab is the child */
90990
+ int *aChange, /* Array indicating modified columns */
90991
+ int bChngRowid /* True if rowid is modified by this update */
90992
+){
90993
+ int i;
90994
+ for(i=0; i<p->nCol; i++){
90995
+ int iChildKey = p->aCol[i].iFrom;
90996
+ if( aChange[iChildKey]>=0 ) return 1;
90997
+ if( iChildKey==pTab->iPKey && bChngRowid ) return 1;
90998
+ }
90999
+ return 0;
91000
+}
91001
+
91002
+/*
91003
+** The second argument points to an FKey object representing a foreign key
91004
+** for which pTab is the parent table. An UPDATE statement against pTab
91005
+** is currently being processed. For each column of the table that is
91006
+** actually updated, the corresponding element in the aChange[] array
91007
+** is zero or greater (if a column is unmodified the corresponding element
91008
+** is set to -1). If the rowid column is modified by the UPDATE statement
91009
+** the bChngRowid argument is non-zero.
91010
+**
91011
+** This function returns true if any of the columns that are part of the
91012
+** parent key for FK constraint *p are modified.
91013
+*/
91014
+static int fkParentIsModified(
91015
+ Table *pTab,
91016
+ FKey *p,
91017
+ int *aChange,
91018
+ int bChngRowid
91019
+){
91020
+ int i;
91021
+ for(i=0; i<p->nCol; i++){
91022
+ char *zKey = p->aCol[i].zCol;
91023
+ int iKey;
91024
+ for(iKey=0; iKey<pTab->nCol; iKey++){
91025
+ if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
91026
+ Column *pCol = &pTab->aCol[iKey];
91027
+ if( zKey ){
91028
+ if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
91029
+ }else if( pCol->colFlags & COLFLAG_PRIMKEY ){
91030
+ return 1;
91031
+ }
91032
+ }
91033
+ }
91034
+ }
91035
+ return 0;
91036
+}
91037
+
9088391038
/*
9088491039
** This function is called when inserting, deleting or updating a row of
9088591040
** table pTab to generate VDBE code to perform foreign key constraint
9088691041
** processing for the operation.
9088791042
**
@@ -90902,11 +91057,13 @@
9090291057
*/
9090391058
SQLITE_PRIVATE void sqlite3FkCheck(
9090491059
Parse *pParse, /* Parse context */
9090591060
Table *pTab, /* Row is being deleted from this table */
9090691061
int regOld, /* Previous row data is stored here */
90907
- int regNew /* New row data is stored here */
91062
+ int regNew, /* New row data is stored here */
91063
+ int *aChange, /* Array indicating UPDATEd columns (or 0) */
91064
+ int bChngRowid /* True if rowid is UPDATEd */
9090891065
){
9090991066
sqlite3 *db = pParse->db; /* Database handle */
9091091067
FKey *pFKey; /* Used to iterate through FKs */
9091191068
int iDb; /* Index of database containing pTab */
9091291069
const char *zDb; /* Name of database containing pTab */
@@ -90929,10 +91086,17 @@
9092991086
int *aiFree = 0;
9093091087
int *aiCol;
9093191088
int iCol;
9093291089
int i;
9093391090
int isIgnore = 0;
91091
+
91092
+ if( aChange
91093
+ && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
91094
+ && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
91095
+ ){
91096
+ continue;
91097
+ }
9093491098
9093591099
/* Find the parent table of this foreign key. Also find a unique index
9093691100
** on the parent key columns in the parent table. If either of these
9093791101
** schema items cannot be located, set an error in pParse and return
9093891102
** early. */
@@ -91011,10 +91175,14 @@
9101191175
/* Loop through all the foreign key constraints that refer to this table */
9101291176
for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
9101391177
Index *pIdx = 0; /* Foreign key index for pFKey */
9101491178
SrcList *pSrc;
9101591179
int *aiCol = 0;
91180
+
91181
+ if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
91182
+ continue;
91183
+ }
9101691184
9101791185
if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
9101891186
&& !pParse->pToplevel && !pParse->isMultiWrite
9101991187
){
9102091188
assert( regOld==0 && regNew!=0 );
@@ -91084,10 +91252,11 @@
9108491252
}
9108591253
}
9108691254
}
9108791255
return mask;
9108891256
}
91257
+
9108991258
9109091259
/*
9109191260
** This function is called before generating code to update or delete a
9109291261
** row contained in table pTab. If the operation is a DELETE, then
9109391262
** parameter aChange is passed a NULL value. For an UPDATE, aChange points
@@ -91114,36 +91283,20 @@
9111491283
** foreign key constraint. */
9111591284
return (sqlite3FkReferences(pTab) || pTab->pFKey);
9111691285
}else{
9111791286
/* This is an UPDATE. Foreign key processing is only required if the
9111891287
** operation modifies one or more child or parent key columns. */
91119
- int i;
9112091288
FKey *p;
9112191289
9112291290
/* Check if any child key columns are being modified. */
9112391291
for(p=pTab->pFKey; p; p=p->pNextFrom){
91124
- for(i=0; i<p->nCol; i++){
91125
- int iChildKey = p->aCol[i].iFrom;
91126
- if( aChange[iChildKey]>=0 ) return 1;
91127
- if( iChildKey==pTab->iPKey && chngRowid ) return 1;
91128
- }
91292
+ if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
9112991293
}
9113091294
9113191295
/* Check if any parent key columns are being modified. */
9113291296
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
91133
- for(i=0; i<p->nCol; i++){
91134
- char *zKey = p->aCol[i].zCol;
91135
- int iKey;
91136
- for(iKey=0; iKey<pTab->nCol; iKey++){
91137
- Column *pCol = &pTab->aCol[iKey];
91138
- if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey)
91139
- : (pCol->colFlags & COLFLAG_PRIMKEY)!=0) ){
91140
- if( aChange[iKey]>=0 ) return 1;
91141
- if( iKey==pTab->iPKey && chngRowid ) return 1;
91142
- }
91143
- }
91144
- }
91297
+ if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
9114591298
}
9114691299
}
9114791300
}
9114891301
return 0;
9114991302
}
@@ -91365,22 +91518,26 @@
9136591518
*/
9136691519
SQLITE_PRIVATE void sqlite3FkActions(
9136791520
Parse *pParse, /* Parse context */
9136891521
Table *pTab, /* Table being updated or deleted from */
9136991522
ExprList *pChanges, /* Change-list for UPDATE, NULL for DELETE */
91370
- int regOld /* Address of array containing old row */
91523
+ int regOld, /* Address of array containing old row */
91524
+ int *aChange, /* Array indicating UPDATEd columns (or 0) */
91525
+ int bChngRowid /* True if rowid is UPDATEd */
9137191526
){
9137291527
/* If foreign-key support is enabled, iterate through all FKs that
9137391528
** refer to table pTab. If there is an action associated with the FK
9137491529
** for this operation (either update or delete), invoke the associated
9137591530
** trigger sub-program. */
9137691531
if( pParse->db->flags&SQLITE_ForeignKeys ){
9137791532
FKey *pFKey; /* Iterator variable */
9137891533
for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
91379
- Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
91380
- if( pAction ){
91381
- sqlite3CodeRowTriggerDirect(pParse, pAction, pTab, regOld, OE_Abort, 0);
91534
+ if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
91535
+ Trigger *pAct = fkActionTrigger(pParse, pTab, pFKey, pChanges);
91536
+ if( pAct ){
91537
+ sqlite3CodeRowTriggerDirect(pParse, pAct, pTab, regOld, OE_Abort, 0);
91538
+ }
9138291539
}
9138391540
}
9138491541
}
9138591542
}
9138691543
@@ -92461,11 +92618,11 @@
9246192618
{
9246292619
int isReplace; /* Set to true if constraints may cause a replace */
9246392620
sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
9246492621
keyColumn>=0, 0, onError, endOfLoop, &isReplace
9246592622
);
92466
- sqlite3FkCheck(pParse, pTab, 0, regIns);
92623
+ sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
9246792624
sqlite3CompleteInsertion(
9246892625
pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
9246992626
);
9247092627
}
9247192628
}
@@ -94762,10 +94919,239 @@
9476294919
**
9476394920
*************************************************************************
9476494921
** This file contains code used to implement the PRAGMA command.
9476594922
*/
9476694923
94924
+#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
94925
+# if defined(__APPLE__)
94926
+# define SQLITE_ENABLE_LOCKING_STYLE 1
94927
+# else
94928
+# define SQLITE_ENABLE_LOCKING_STYLE 0
94929
+# endif
94930
+#endif
94931
+
94932
+/***************************************************************************
94933
+** The next block of code, including the PragTyp_XXXX macro definitions and
94934
+** the aPragmaName[] object is composed of generated code. DO NOT EDIT.
94935
+**
94936
+** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
94937
+** that script. Then copy/paste the output in place of the following:
94938
+*/
94939
+#define PragTyp_HEADER_VALUE 0
94940
+#define PragTyp_AUTO_VACUUM 1
94941
+#define PragTyp_FLAG 2
94942
+#define PragTyp_BUSY_TIMEOUT 3
94943
+#define PragTyp_CACHE_SIZE 4
94944
+#define PragTyp_CASE_SENSITIVE_LIKE 5
94945
+#define PragTyp_COLLATION_LIST 6
94946
+#define PragTyp_COMPILE_OPTIONS 7
94947
+#define PragTyp_DATA_STORE_DIRECTORY 8
94948
+#define PragTyp_DATABASE_LIST 9
94949
+#define PragTyp_DEFAULT_CACHE_SIZE 10
94950
+#define PragTyp_ENCODING 11
94951
+#define PragTyp_FOREIGN_KEY_CHECK 12
94952
+#define PragTyp_FOREIGN_KEY_LIST 13
94953
+#define PragTyp_INCREMENTAL_VACUUM 14
94954
+#define PragTyp_INDEX_INFO 15
94955
+#define PragTyp_INDEX_LIST 16
94956
+#define PragTyp_INTEGRITY_CHECK 17
94957
+#define PragTyp_JOURNAL_MODE 18
94958
+#define PragTyp_JOURNAL_SIZE_LIMIT 19
94959
+#define PragTyp_LOCK_PROXY_FILE 20
94960
+#define PragTyp_LOCKING_MODE 21
94961
+#define PragTyp_PAGE_COUNT 22
94962
+#define PragTyp_MMAP_SIZE 23
94963
+#define PragTyp_PAGE_SIZE 24
94964
+#define PragTyp_SECURE_DELETE 25
94965
+#define PragTyp_SHRINK_MEMORY 26
94966
+#define PragTyp_SOFT_HEAP_LIMIT 27
94967
+#define PragTyp_SYNCHRONOUS 28
94968
+#define PragTyp_TABLE_INFO 29
94969
+#define PragTyp_TEMP_STORE 30
94970
+#define PragTyp_TEMP_STORE_DIRECTORY 31
94971
+#define PragTyp_WAL_AUTOCHECKPOINT 32
94972
+#define PragTyp_WAL_CHECKPOINT 33
94973
+#define PragTyp_ACTIVATE_EXTENSIONS 34
94974
+#define PragTyp_HEXKEY 35
94975
+#define PragTyp_KEY 36
94976
+#define PragTyp_REKEY 37
94977
+#define PragTyp_LOCK_STATUS 38
94978
+#define PragTyp_PARSER_TRACE 39
94979
+static const struct sPragmaNames {
94980
+ const char *const zName; /* Name of pragma */
94981
+ u8 ePragTyp; /* PragTyp_XXX value */
94982
+ u32 iArg; /* Extra argument */
94983
+} aPragmaNames[] = {
94984
+#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
94985
+ { "activate_extensions", PragTyp_ACTIVATE_EXTENSIONS, 0 },
94986
+#endif
94987
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
94988
+ { "application_id", PragTyp_HEADER_VALUE, 0 },
94989
+#endif
94990
+#if !defined(SQLITE_OMIT_AUTOVACUUM)
94991
+ { "auto_vacuum", PragTyp_AUTO_VACUUM, 0 },
94992
+#endif
94993
+#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
94994
+ { "automatic_index", PragTyp_FLAG,
94995
+ SQLITE_AutoIndex },
94996
+#endif
94997
+ { "busy_timeout", PragTyp_BUSY_TIMEOUT, 0 },
94998
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
94999
+ { "cache_size", PragTyp_CACHE_SIZE, 0 },
95000
+#endif
95001
+ { "cache_spill", PragTyp_FLAG,
95002
+ SQLITE_CacheSpill },
95003
+ { "case_sensitive_like", PragTyp_CASE_SENSITIVE_LIKE, 0 },
95004
+ { "checkpoint_fullfsync", PragTyp_FLAG,
95005
+ SQLITE_CkptFullFSync },
95006
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95007
+ { "collation_list", PragTyp_COLLATION_LIST, 0 },
95008
+#endif
95009
+#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
95010
+ { "compile_options", PragTyp_COMPILE_OPTIONS, 0 },
95011
+#endif
95012
+ { "count_changes", PragTyp_FLAG,
95013
+ SQLITE_CountRows },
95014
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
95015
+ { "data_store_directory", PragTyp_DATA_STORE_DIRECTORY, 0 },
95016
+#endif
95017
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95018
+ { "database_list", PragTyp_DATABASE_LIST, 0 },
95019
+#endif
95020
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
95021
+ { "default_cache_size", PragTyp_DEFAULT_CACHE_SIZE, 0 },
95022
+#endif
95023
+#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95024
+ { "defer_foreign_keys", PragTyp_FLAG,
95025
+ SQLITE_DeferFKs },
95026
+#endif
95027
+ { "empty_result_callbacks", PragTyp_FLAG,
95028
+ SQLITE_NullCallback },
95029
+#if !defined(SQLITE_OMIT_UTF16)
95030
+ { "encoding", PragTyp_ENCODING, 0 },
95031
+#endif
95032
+#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95033
+ { "foreign_key_check", PragTyp_FOREIGN_KEY_CHECK, 0 },
95034
+#endif
95035
+#if !defined(SQLITE_OMIT_FOREIGN_KEY)
95036
+ { "foreign_key_list", PragTyp_FOREIGN_KEY_LIST, 0 },
95037
+#endif
95038
+#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95039
+ { "foreign_keys", PragTyp_FLAG,
95040
+ SQLITE_ForeignKeys },
95041
+#endif
95042
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95043
+ { "freelist_count", PragTyp_HEADER_VALUE, 0 },
95044
+#endif
95045
+ { "full_column_names", PragTyp_FLAG,
95046
+ SQLITE_FullColNames },
95047
+ { "fullfsync", PragTyp_FLAG,
95048
+ SQLITE_FullFSync },
95049
+#if defined(SQLITE_HAS_CODEC)
95050
+ { "hexkey", PragTyp_HEXKEY, 0 },
95051
+#endif
95052
+#if !defined(SQLITE_OMIT_CHECK)
95053
+ { "ignore_check_constraints", PragTyp_FLAG,
95054
+ SQLITE_IgnoreChecks },
95055
+#endif
95056
+#if !defined(SQLITE_OMIT_AUTOVACUUM)
95057
+ { "incremental_vacuum", PragTyp_INCREMENTAL_VACUUM, 0 },
95058
+#endif
95059
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95060
+ { "index_info", PragTyp_INDEX_INFO, 0 },
95061
+ { "index_list", PragTyp_INDEX_LIST, 0 },
95062
+#endif
95063
+#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
95064
+ { "integrity_check", PragTyp_INTEGRITY_CHECK, 0 },
95065
+#endif
95066
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95067
+ { "journal_mode", PragTyp_JOURNAL_MODE, 0 },
95068
+ { "journal_size_limit", PragTyp_JOURNAL_SIZE_LIMIT, 0 },
95069
+#endif
95070
+#if defined(SQLITE_HAS_CODEC)
95071
+ { "key", PragTyp_KEY, 0 },
95072
+#endif
95073
+ { "legacy_file_format", PragTyp_FLAG,
95074
+ SQLITE_LegacyFileFmt },
95075
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
95076
+ { "lock_proxy_file", PragTyp_LOCK_PROXY_FILE, 0 },
95077
+#endif
95078
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
95079
+ { "lock_status", PragTyp_LOCK_STATUS, 0 },
95080
+#endif
95081
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95082
+ { "locking_mode", PragTyp_LOCKING_MODE, 0 },
95083
+ { "max_page_count", PragTyp_PAGE_COUNT, 0 },
95084
+ { "mmap_size", PragTyp_MMAP_SIZE, 0 },
95085
+ { "page_count", PragTyp_PAGE_COUNT, 0 },
95086
+ { "page_size", PragTyp_PAGE_SIZE, 0 },
95087
+#endif
95088
+#if defined(SQLITE_DEBUG)
95089
+ { "parser_trace", PragTyp_PARSER_TRACE, 0 },
95090
+#endif
95091
+ { "query_only", PragTyp_FLAG,
95092
+ SQLITE_QueryOnly },
95093
+#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
95094
+ { "quick_check", PragTyp_INTEGRITY_CHECK, 0 },
95095
+#endif
95096
+ { "read_uncommitted", PragTyp_FLAG,
95097
+ SQLITE_ReadUncommitted },
95098
+ { "recursive_triggers", PragTyp_FLAG,
95099
+ SQLITE_RecTriggers },
95100
+#if defined(SQLITE_HAS_CODEC)
95101
+ { "rekey", PragTyp_REKEY, 0 },
95102
+#endif
95103
+ { "reverse_unordered_selects", PragTyp_FLAG,
95104
+ SQLITE_ReverseOrder },
95105
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95106
+ { "schema_version", PragTyp_HEADER_VALUE, 0 },
95107
+#endif
95108
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95109
+ { "secure_delete", PragTyp_SECURE_DELETE, 0 },
95110
+#endif
95111
+ { "short_column_names", PragTyp_FLAG,
95112
+ SQLITE_ShortColNames },
95113
+ { "shrink_memory", PragTyp_SHRINK_MEMORY, 0 },
95114
+ { "soft_heap_limit", PragTyp_SOFT_HEAP_LIMIT, 0 },
95115
+#if defined(SQLITE_DEBUG)
95116
+ { "sql_trace", PragTyp_FLAG,
95117
+ SQLITE_SqlTrace },
95118
+#endif
95119
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95120
+ { "synchronous", PragTyp_SYNCHRONOUS, 0 },
95121
+#endif
95122
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95123
+ { "table_info", PragTyp_TABLE_INFO, 0 },
95124
+#endif
95125
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95126
+ { "temp_store", PragTyp_TEMP_STORE, 0 },
95127
+ { "temp_store_directory", PragTyp_TEMP_STORE_DIRECTORY, 0 },
95128
+#endif
95129
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95130
+ { "user_version", PragTyp_HEADER_VALUE, 0 },
95131
+#endif
95132
+#if defined(SQLITE_DEBUG)
95133
+ { "vdbe_addoptrace", PragTyp_FLAG,
95134
+ SQLITE_VdbeAddopTrace },
95135
+ { "vdbe_debug", PragTyp_FLAG,
95136
+ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
95137
+ { "vdbe_listing", PragTyp_FLAG,
95138
+ SQLITE_VdbeListing },
95139
+ { "vdbe_trace", PragTyp_FLAG,
95140
+ SQLITE_VdbeTrace },
95141
+#endif
95142
+#if !defined(SQLITE_OMIT_WAL)
95143
+ { "wal_autocheckpoint", PragTyp_WAL_AUTOCHECKPOINT, 0 },
95144
+ { "wal_checkpoint", PragTyp_WAL_CHECKPOINT, 0 },
95145
+#endif
95146
+ { "writable_schema", PragTyp_FLAG,
95147
+ SQLITE_WriteSchema|SQLITE_RecoveryMode },
95148
+};
95149
+/* Number of pragmas: 55 on by default, 66 total. */
95150
+/* End of the automatically generated pragma table.
95151
+***************************************************************************/
95152
+
9476795153
/*
9476895154
** Interpret the given string as a safety level. Return 0 for OFF,
9476995155
** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
9477095156
** unrecognized string argument. The FULL option is disallowed
9477195157
** if the omitFull parameter it 1.
@@ -94937,101 +95323,10 @@
9493795323
#else
9493895324
# define setAllPagerFlags(X) /* no-op */
9493995325
#endif
9494095326
9494195327
94942
-#ifndef SQLITE_OMIT_FLAG_PRAGMAS
94943
-/*
94944
-** Check to see if zRight and zLeft refer to a pragma that queries
94945
-** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
94946
-** Also, implement the pragma.
94947
-*/
94948
-static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
94949
- static const struct sPragmaType {
94950
- const char *zName; /* Name of the pragma */
94951
- int mask; /* Mask for the db->flags value */
94952
- } aPragma[] = {
94953
- { "full_column_names", SQLITE_FullColNames },
94954
- { "short_column_names", SQLITE_ShortColNames },
94955
- { "count_changes", SQLITE_CountRows },
94956
- { "empty_result_callbacks", SQLITE_NullCallback },
94957
- { "legacy_file_format", SQLITE_LegacyFileFmt },
94958
- { "fullfsync", SQLITE_FullFSync },
94959
- { "checkpoint_fullfsync", SQLITE_CkptFullFSync },
94960
- { "cache_spill", SQLITE_CacheSpill },
94961
- { "reverse_unordered_selects", SQLITE_ReverseOrder },
94962
- { "query_only", SQLITE_QueryOnly },
94963
-#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
94964
- { "automatic_index", SQLITE_AutoIndex },
94965
-#endif
94966
-#ifdef SQLITE_DEBUG
94967
- { "sql_trace", SQLITE_SqlTrace },
94968
- { "vdbe_listing", SQLITE_VdbeListing },
94969
- { "vdbe_trace", SQLITE_VdbeTrace },
94970
- { "vdbe_addoptrace", SQLITE_VdbeAddopTrace},
94971
- { "vdbe_debug", SQLITE_SqlTrace | SQLITE_VdbeListing
94972
- | SQLITE_VdbeTrace },
94973
-#endif
94974
-#ifndef SQLITE_OMIT_CHECK
94975
- { "ignore_check_constraints", SQLITE_IgnoreChecks },
94976
-#endif
94977
- /* The following is VERY experimental */
94978
- { "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode },
94979
-
94980
- /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
94981
- ** flag if there are any active statements. */
94982
- { "read_uncommitted", SQLITE_ReadUncommitted },
94983
- { "recursive_triggers", SQLITE_RecTriggers },
94984
-
94985
- /* This flag may only be set if both foreign-key and trigger support
94986
- ** are present in the build. */
94987
-#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
94988
- { "foreign_keys", SQLITE_ForeignKeys },
94989
- { "defer_foreign_keys", SQLITE_DeferFKs },
94990
-#endif
94991
- };
94992
- int i;
94993
- const struct sPragmaType *p;
94994
- for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
94995
- if( sqlite3StrICmp(zLeft, p->zName)==0 ){
94996
- sqlite3 *db = pParse->db;
94997
- Vdbe *v;
94998
- v = sqlite3GetVdbe(pParse);
94999
- assert( v!=0 ); /* Already allocated by sqlite3Pragma() */
95000
- if( ALWAYS(v) ){
95001
- if( zRight==0 ){
95002
- returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
95003
- }else{
95004
- int mask = p->mask; /* Mask of bits to set or clear. */
95005
- if( db->autoCommit==0 ){
95006
- /* Foreign key support may not be enabled or disabled while not
95007
- ** in auto-commit mode. */
95008
- mask &= ~(SQLITE_ForeignKeys);
95009
- }
95010
-
95011
- if( sqlite3GetBoolean(zRight, 0) ){
95012
- db->flags |= mask;
95013
- }else{
95014
- db->flags &= ~mask;
95015
- if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
95016
- }
95017
-
95018
- /* Many of the flag-pragmas modify the code generated by the SQL
95019
- ** compiler (eg. count_changes). So add an opcode to expire all
95020
- ** compiled SQL statements after modifying a pragma value.
95021
- */
95022
- sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
95023
- }
95024
- }
95025
-
95026
- return 1;
95027
- }
95028
- }
95029
- return 0;
95030
-}
95031
-#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
95032
-
9503395328
/*
9503495329
** Return a human-readable name for a constraint resolution action.
9503595330
*/
9503695331
#ifndef SQLITE_OMIT_FOREIGN_KEY
9503795332
static const char *actionName(u8 action){
@@ -95097,12 +95392,13 @@
9509795392
){
9509895393
char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
9509995394
char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
9510095395
const char *zDb = 0; /* The database name */
9510195396
Token *pId; /* Pointer to <id> token */
95102
- int iDb; /* Database index for <database> */
9510395397
char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
95398
+ int iDb; /* Database index for <database> */
95399
+ int lwr, upr, mid; /* Binary search bounds */
9510495400
int rc; /* return value form SQLITE_FCNTL_PRAGMA */
9510595401
sqlite3 *db = pParse->db; /* The database connection */
9510695402
Db *pDb; /* The specific database being pragmaed */
9510795403
Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
9510895404
@@ -95154,20 +95450,40 @@
9515495450
sqlite3VdbeSetNumCols(v, 1);
9515595451
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
9515695452
sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
9515795453
sqlite3_free(aFcntl[0]);
9515895454
}
95159
- }else if( rc!=SQLITE_NOTFOUND ){
95455
+ goto pragma_out;
95456
+ }
95457
+ if( rc!=SQLITE_NOTFOUND ){
9516095458
if( aFcntl[0] ){
9516195459
sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
9516295460
sqlite3_free(aFcntl[0]);
9516395461
}
9516495462
pParse->nErr++;
9516595463
pParse->rc = rc;
95166
- }else
95167
-
95168
-
95464
+ goto pragma_out;
95465
+ }
95466
+
95467
+ /* Locate the pragma in the lookup table */
95468
+ lwr = 0;
95469
+ upr = ArraySize(aPragmaNames)-1;
95470
+ while( lwr<=upr ){
95471
+ mid = (lwr+upr)/2;
95472
+ rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName);
95473
+ if( rc==0 ) break;
95474
+ if( rc<0 ){
95475
+ upr = mid - 1;
95476
+ }else{
95477
+ lwr = mid + 1;
95478
+ }
95479
+ }
95480
+ if( lwr>upr ) goto pragma_out;
95481
+
95482
+ /* Jump to the appropriate pragma handler */
95483
+ switch( aPragmaNames[mid].ePragTyp ){
95484
+
9516995485
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
9517095486
/*
9517195487
** PRAGMA [database.]default_cache_size
9517295488
** PRAGMA [database.]default_cache_size=N
9517395489
**
@@ -95181,11 +95497,11 @@
9518195497
** negative number to indicate synchronous=OFF. These days, synchronous
9518295498
** is always on by default regardless of the sign of the default cache
9518395499
** size. But continue to take the absolute value of the default cache
9518495500
** size of historical compatibility.
9518595501
*/
95186
- if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
95502
+ case PragTyp_DEFAULT_CACHE_SIZE: {
9518795503
static const VdbeOpList getCacheSize[] = {
9518895504
{ OP_Transaction, 0, 0, 0}, /* 0 */
9518995505
{ OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
9519095506
{ OP_IfPos, 1, 8, 0},
9519195507
{ OP_Integer, 0, 2, 0},
@@ -95213,11 +95529,12 @@
9521395529
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
9521495530
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9521595531
pDb->pSchema->cache_size = size;
9521695532
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
9521795533
}
95218
- }else
95534
+ break;
95535
+ }
9521995536
#endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
9522095537
9522195538
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
9522295539
/*
9522395540
** PRAGMA [database.]page_size
@@ -95226,11 +95543,11 @@
9522695543
** The first form reports the current setting for the
9522795544
** database page size in bytes. The second form sets the
9522895545
** database page size value. The value can only be set if
9522995546
** the database has not yet been created.
9523095547
*/
95231
- if( sqlite3StrICmp(zLeft,"page_size")==0 ){
95548
+ case PragTyp_PAGE_SIZE: {
9523295549
Btree *pBt = pDb->pBt;
9523395550
assert( pBt!=0 );
9523495551
if( !zRight ){
9523595552
int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
9523695553
returnSingleInt(pParse, "page_size", size);
@@ -95241,21 +95558,22 @@
9524195558
db->nextPagesize = sqlite3Atoi(zRight);
9524295559
if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
9524395560
db->mallocFailed = 1;
9524495561
}
9524595562
}
95246
- }else
95563
+ break;
95564
+ }
9524795565
9524895566
/*
9524995567
** PRAGMA [database.]secure_delete
9525095568
** PRAGMA [database.]secure_delete=ON/OFF
9525195569
**
9525295570
** The first form reports the current setting for the
9525395571
** secure_delete flag. The second form changes the secure_delete
9525495572
** flag setting and reports thenew value.
9525595573
*/
95256
- if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
95574
+ case PragTyp_SECURE_DELETE: {
9525795575
Btree *pBt = pDb->pBt;
9525895576
int b = -1;
9525995577
assert( pBt!=0 );
9526095578
if( zRight ){
9526195579
b = sqlite3GetBoolean(zRight, 0);
@@ -95266,11 +95584,12 @@
9526695584
sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
9526795585
}
9526895586
}
9526995587
b = sqlite3BtreeSecureDelete(pBt, b);
9527095588
returnSingleInt(pParse, "secure_delete", b);
95271
- }else
95589
+ break;
95590
+ }
9527295591
9527395592
/*
9527495593
** PRAGMA [database.]max_page_count
9527595594
** PRAGMA [database.]max_page_count=N
9527695595
**
@@ -95285,13 +95604,11 @@
9528595604
**
9528695605
** PRAGMA [database.]page_count
9528795606
**
9528895607
** Return the number of pages in the specified database.
9528995608
*/
95290
- if( sqlite3StrICmp(zLeft,"page_count")==0
95291
- || sqlite3StrICmp(zLeft,"max_page_count")==0
95292
- ){
95609
+ case PragTyp_PAGE_COUNT: {
9529395610
int iReg;
9529495611
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9529595612
sqlite3CodeVerifySchema(pParse, iDb);
9529695613
iReg = ++pParse->nMem;
9529795614
if( sqlite3Tolower(zLeft[0])=='p' ){
@@ -95301,17 +95618,18 @@
9530195618
sqlite3AbsInt32(sqlite3Atoi(zRight)));
9530295619
}
9530395620
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
9530495621
sqlite3VdbeSetNumCols(v, 1);
9530595622
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
95306
- }else
95623
+ break;
95624
+ }
9530795625
9530895626
/*
9530995627
** PRAGMA [database.]locking_mode
9531095628
** PRAGMA [database.]locking_mode = (normal|exclusive)
9531195629
*/
95312
- if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
95630
+ case PragTyp_LOCKING_MODE: {
9531395631
const char *zRet = "normal";
9531495632
int eMode = getLockingMode(zRight);
9531595633
9531695634
if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
9531795635
/* Simple "PRAGMA locking_mode;" statement. This is a query for
@@ -95340,26 +95658,28 @@
9534095658
}
9534195659
pPager = sqlite3BtreePager(pDb->pBt);
9534295660
eMode = sqlite3PagerLockingMode(pPager, eMode);
9534395661
}
9534495662
95345
- assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
95663
+ assert( eMode==PAGER_LOCKINGMODE_NORMAL
95664
+ || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
9534695665
if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
9534795666
zRet = "exclusive";
9534895667
}
9534995668
sqlite3VdbeSetNumCols(v, 1);
9535095669
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
9535195670
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
9535295671
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
95353
- }else
95672
+ break;
95673
+ }
9535495674
9535595675
/*
9535695676
** PRAGMA [database.]journal_mode
9535795677
** PRAGMA [database.]journal_mode =
9535895678
** (delete|persist|off|truncate|memory|wal|off)
9535995679
*/
95360
- if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
95680
+ case PragTyp_JOURNAL_MODE: {
9536195681
int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
9536295682
int ii; /* Loop counter */
9536395683
9536495684
/* Force the schema to be loaded on all databases. This causes all
9536595685
** database files to be opened and the journal_modes set. This is
@@ -95398,28 +95718,30 @@
9539895718
sqlite3VdbeUsesBtree(v, ii);
9539995719
sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
9540095720
}
9540195721
}
9540295722
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
95403
- }else
95723
+ break;
95724
+ }
9540495725
9540595726
/*
9540695727
** PRAGMA [database.]journal_size_limit
9540795728
** PRAGMA [database.]journal_size_limit=N
9540895729
**
9540995730
** Get or set the size limit on rollback journal files.
9541095731
*/
95411
- if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
95732
+ case PragTyp_JOURNAL_SIZE_LIMIT: {
9541295733
Pager *pPager = sqlite3BtreePager(pDb->pBt);
9541395734
i64 iLimit = -2;
9541495735
if( zRight ){
9541595736
sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8);
9541695737
if( iLimit<-1 ) iLimit = -1;
9541795738
}
9541895739
iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
9541995740
returnSingleInt(pParse, "journal_size_limit", iLimit);
95420
- }else
95741
+ break;
95742
+ }
9542195743
9542295744
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
9542395745
9542495746
/*
9542595747
** PRAGMA [database.]auto_vacuum
@@ -95427,11 +95749,11 @@
9542795749
**
9542895750
** Get or set the value of the database 'auto-vacuum' parameter.
9542995751
** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
9543095752
*/
9543195753
#ifndef SQLITE_OMIT_AUTOVACUUM
95432
- if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
95754
+ case PragTyp_AUTO_VACUUM: {
9543395755
Btree *pBt = pDb->pBt;
9543495756
assert( pBt!=0 );
9543595757
if( sqlite3ReadSchema(pParse) ){
9543695758
goto pragma_out;
9543795759
}
@@ -95477,20 +95799,21 @@
9547795799
sqlite3VdbeChangeP1(v, iAddr+5, iDb);
9547895800
sqlite3VdbeUsesBtree(v, iDb);
9547995801
}
9548095802
}
9548195803
}
95482
- }else
95804
+ break;
95805
+ }
9548395806
#endif
9548495807
9548595808
/*
9548695809
** PRAGMA [database.]incremental_vacuum(N)
9548795810
**
9548895811
** Do N steps of incremental vacuuming on a database.
9548995812
*/
9549095813
#ifndef SQLITE_OMIT_AUTOVACUUM
95491
- if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
95814
+ case PragTyp_INCREMENTAL_VACUUM: {
9549295815
int iLimit, addr;
9549395816
if( sqlite3ReadSchema(pParse) ){
9549495817
goto pragma_out;
9549595818
}
9549695819
if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
@@ -95501,11 +95824,12 @@
9550195824
addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
9550295825
sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
9550395826
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
9550495827
sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
9550595828
sqlite3VdbeJumpHere(v, addr);
95506
- }else
95829
+ break;
95830
+ }
9550795831
#endif
9550895832
9550995833
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
9551095834
/*
9551195835
** PRAGMA [database.]cache_size
@@ -95516,21 +95840,22 @@
9551695840
** page cache size value. If N is positive then that is the
9551795841
** number of pages in the cache. If N is negative, then the
9551895842
** number of pages is adjusted so that the cache uses -N kibibytes
9551995843
** of memory.
9552095844
*/
95521
- if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
95845
+ case PragTyp_CACHE_SIZE: {
9552295846
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9552395847
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9552495848
if( !zRight ){
9552595849
returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
9552695850
}else{
9552795851
int size = sqlite3Atoi(zRight);
9552895852
pDb->pSchema->cache_size = size;
9552995853
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
9553095854
}
95531
- }else
95855
+ break;
95856
+ }
9553295857
9553395858
/*
9553495859
** PRAGMA [database.]mmap_size(N)
9553595860
**
9553695861
** Used to set mapping size limit. The mapping size limit is
@@ -95542,11 +95867,11 @@
9554295867
**
9554395868
** This value is advisory. The underlying VFS is free to memory map
9554495869
** as little or as much as it wants. Except, if N is set to 0 then the
9554595870
** upper layers will never invoke the xFetch interfaces to the VFS.
9554695871
*/
95547
- if( sqlite3StrICmp(zLeft,"mmap_size")==0 ){
95872
+ case PragTyp_MMAP_SIZE: {
9554895873
sqlite3_int64 sz;
9554995874
#if SQLITE_MAX_MMAP_SIZE>0
9555095875
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
9555195876
if( zRight ){
9555295877
int ii;
@@ -95569,11 +95894,12 @@
9556995894
returnSingleInt(pParse, "mmap_size", sz);
9557095895
}else if( rc!=SQLITE_NOTFOUND ){
9557195896
pParse->nErr++;
9557295897
pParse->rc = rc;
9557395898
}
95574
- }else
95899
+ break;
95900
+ }
9557595901
9557695902
/*
9557795903
** PRAGMA temp_store
9557895904
** PRAGMA temp_store = "default"|"memory"|"file"
9557995905
**
@@ -95582,17 +95908,18 @@
9558295908
** value will be restored the next time the database is opened.
9558395909
**
9558495910
** Note that it is possible for the library compile-time options to
9558595911
** override this setting
9558695912
*/
95587
- if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
95913
+ case PragTyp_TEMP_STORE: {
9558895914
if( !zRight ){
9558995915
returnSingleInt(pParse, "temp_store", db->temp_store);
9559095916
}else{
9559195917
changeTempStorage(pParse, zRight);
9559295918
}
95593
- }else
95919
+ break;
95920
+ }
9559495921
9559595922
/*
9559695923
** PRAGMA temp_store_directory
9559795924
** PRAGMA temp_store_directory = ""|"directory_name"
9559895925
**
@@ -95600,11 +95927,11 @@
9560095927
** the value sets a specific directory to be used for temporary files.
9560195928
** Setting to a null string reverts to the default temporary directory search.
9560295929
** If temporary directory is changed, then invalidateTempStorage.
9560395930
**
9560495931
*/
95605
- if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
95932
+ case PragTyp_TEMP_STORE_DIRECTORY: {
9560695933
if( !zRight ){
9560795934
if( sqlite3_temp_directory ){
9560895935
sqlite3VdbeSetNumCols(v, 1);
9560995936
sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
9561095937
"temp_store_directory", SQLITE_STATIC);
@@ -95633,11 +95960,12 @@
9563395960
}else{
9563495961
sqlite3_temp_directory = 0;
9563595962
}
9563695963
#endif /* SQLITE_OMIT_WSD */
9563795964
}
95638
- }else
95965
+ break;
95966
+ }
9563995967
9564095968
#if SQLITE_OS_WIN
9564195969
/*
9564295970
** PRAGMA data_store_directory
9564395971
** PRAGMA data_store_directory = ""|"directory_name"
@@ -95649,11 +95977,11 @@
9564995977
** a relative path will probably be based on the current directory for the
9565095978
** process. Database file specified with an absolute path are not impacted
9565195979
** by this setting, regardless of its value.
9565295980
**
9565395981
*/
95654
- if( sqlite3StrICmp(zLeft, "data_store_directory")==0 ){
95982
+ case PragTyp_DATA_STORE_DIRECTORY: {
9565595983
if( !zRight ){
9565695984
if( sqlite3_data_directory ){
9565795985
sqlite3VdbeSetNumCols(v, 1);
9565895986
sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
9565995987
"data_store_directory", SQLITE_STATIC);
@@ -95676,30 +96004,24 @@
9567696004
}else{
9567796005
sqlite3_data_directory = 0;
9567896006
}
9567996007
#endif /* SQLITE_OMIT_WSD */
9568096008
}
95681
- }else
96009
+ break;
96010
+ }
9568296011
#endif
9568396012
95684
-#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
95685
-# if defined(__APPLE__)
95686
-# define SQLITE_ENABLE_LOCKING_STYLE 1
95687
-# else
95688
-# define SQLITE_ENABLE_LOCKING_STYLE 0
95689
-# endif
95690
-#endif
9569196013
#if SQLITE_ENABLE_LOCKING_STYLE
9569296014
/*
95693
- ** PRAGMA [database.]lock_proxy_file
95694
- ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
95695
- **
95696
- ** Return or set the value of the lock_proxy_file flag. Changing
95697
- ** the value sets a specific file to be used for database access locks.
95698
- **
95699
- */
95700
- if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
96015
+ ** PRAGMA [database.]lock_proxy_file
96016
+ ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
96017
+ **
96018
+ ** Return or set the value of the lock_proxy_file flag. Changing
96019
+ ** the value sets a specific file to be used for database access locks.
96020
+ **
96021
+ */
96022
+ case PragTyp_LOCK_PROXY_FILE: {
9570196023
if( !zRight ){
9570296024
Pager *pPager = sqlite3BtreePager(pDb->pBt);
9570396025
char *proxy_file_path = NULL;
9570496026
sqlite3_file *pFile = sqlite3PagerFile(pPager);
9570596027
sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
@@ -95726,11 +96048,12 @@
9572696048
if( res!=SQLITE_OK ){
9572796049
sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
9572896050
goto pragma_out;
9572996051
}
9573096052
}
95731
- }else
96053
+ break;
96054
+ }
9573296055
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
9573396056
9573496057
/*
9573596058
** PRAGMA [database.]synchronous
9573696059
** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
@@ -95738,11 +96061,11 @@
9573896061
** Return or set the local value of the synchronous flag. Changing
9573996062
** the local value does not make changes to the disk file and the
9574096063
** default value will be restored the next time the database is
9574196064
** opened.
9574296065
*/
95743
- if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
96066
+ case PragTyp_SYNCHRONOUS: {
9574496067
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9574596068
if( !zRight ){
9574696069
returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
9574796070
}else{
9574896071
if( !db->autoCommit ){
@@ -95751,17 +96074,43 @@
9575196074
}else{
9575296075
pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
9575396076
setAllPagerFlags(db);
9575496077
}
9575596078
}
95756
- }else
96079
+ break;
96080
+ }
9575796081
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
9575896082
9575996083
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
95760
- if( flagPragma(pParse, zLeft, zRight) ){
95761
- setAllPagerFlags(db);
95762
- }else
96084
+ case PragTyp_FLAG: {
96085
+ if( zRight==0 ){
96086
+ returnSingleInt(pParse, aPragmaNames[mid].zName,
96087
+ (db->flags & aPragmaNames[mid].iArg)!=0 );
96088
+ }else{
96089
+ int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */
96090
+ if( db->autoCommit==0 ){
96091
+ /* Foreign key support may not be enabled or disabled while not
96092
+ ** in auto-commit mode. */
96093
+ mask &= ~(SQLITE_ForeignKeys);
96094
+ }
96095
+
96096
+ if( sqlite3GetBoolean(zRight, 0) ){
96097
+ db->flags |= mask;
96098
+ }else{
96099
+ db->flags &= ~mask;
96100
+ if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
96101
+ }
96102
+
96103
+ /* Many of the flag-pragmas modify the code generated by the SQL
96104
+ ** compiler (eg. count_changes). So add an opcode to expire all
96105
+ ** compiled SQL statements after modifying a pragma value.
96106
+ */
96107
+ sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
96108
+ setAllPagerFlags(db);
96109
+ }
96110
+ break;
96111
+ }
9576396112
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
9576496113
9576596114
#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
9576696115
/*
9576796116
** PRAGMA table_info(<table>)
@@ -95773,11 +96122,11 @@
9577396122
** name: Column name
9577496123
** type: Column declaration type.
9577596124
** notnull: True if 'NOT NULL' is part of column declaration
9577696125
** dflt_value: The default value for the column, if any.
9577796126
*/
95778
- if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
96127
+ case PragTyp_TABLE_INFO: if( zRight ){
9577996128
Table *pTab;
9578096129
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9578196130
pTab = sqlite3FindTable(db, zRight, zDb);
9578296131
if( pTab ){
9578396132
int i, k;
@@ -95819,13 +96168,14 @@
9581996168
}
9582096169
sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
9582196170
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
9582296171
}
9582396172
}
95824
- }else
96173
+ }
96174
+ break;
9582596175
95826
- if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
96176
+ case PragTyp_INDEX_INFO: if( zRight ){
9582796177
Index *pIdx;
9582896178
Table *pTab;
9582996179
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9583096180
pIdx = sqlite3FindIndex(db, zRight, zDb);
9583196181
if( pIdx ){
@@ -95844,13 +96194,14 @@
9584496194
assert( pTab->nCol>cnum );
9584596195
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
9584696196
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
9584796197
}
9584896198
}
95849
- }else
96199
+ }
96200
+ break;
9585096201
95851
- if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
96202
+ case PragTyp_INDEX_LIST: if( zRight ){
9585296203
Index *pIdx;
9585396204
Table *pTab;
9585496205
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9585596206
pTab = sqlite3FindTable(db, zRight, zDb);
9585696207
if( pTab ){
@@ -95872,13 +96223,14 @@
9587296223
++i;
9587396224
pIdx = pIdx->pNext;
9587496225
}
9587596226
}
9587696227
}
95877
- }else
96228
+ }
96229
+ break;
9587896230
95879
- if( sqlite3StrICmp(zLeft, "database_list")==0 ){
96231
+ case PragTyp_DATABASE_LIST: {
9588096232
int i;
9588196233
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9588296234
sqlite3VdbeSetNumCols(v, 3);
9588396235
pParse->nMem = 3;
9588496236
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
@@ -95891,13 +96243,14 @@
9589196243
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
9589296244
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
9589396245
sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
9589496246
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
9589596247
}
95896
- }else
96248
+ }
96249
+ break;
9589796250
95898
- if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
96251
+ case PragTyp_COLLATION_LIST: {
9589996252
int i = 0;
9590096253
HashElem *p;
9590196254
sqlite3VdbeSetNumCols(v, 2);
9590296255
pParse->nMem = 2;
9590396256
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
@@ -95906,15 +96259,16 @@
9590696259
CollSeq *pColl = (CollSeq *)sqliteHashData(p);
9590796260
sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
9590896261
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
9590996262
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
9591096263
}
95911
- }else
96264
+ }
96265
+ break;
9591296266
#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
9591396267
9591496268
#ifndef SQLITE_OMIT_FOREIGN_KEY
95915
- if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
96269
+ case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
9591696270
FKey *pFK;
9591796271
Table *pTab;
9591896272
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9591996273
pTab = sqlite3FindTable(db, zRight, zDb);
9592096274
if( pTab ){
@@ -95953,16 +96307,17 @@
9595396307
++i;
9595496308
pFK = pFK->pNextFrom;
9595596309
}
9595696310
}
9595796311
}
95958
- }else
96312
+ }
96313
+ break;
9595996314
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
9596096315
9596196316
#ifndef SQLITE_OMIT_FOREIGN_KEY
9596296317
#ifndef SQLITE_OMIT_TRIGGER
95963
- if( sqlite3StrICmp(zLeft, "foreign_key_check")==0 ){
96318
+ case PragTyp_FOREIGN_KEY_CHECK: {
9596496319
FKey *pFK; /* A foreign key constraint */
9596596320
Table *pTab; /* Child table contain "REFERENCES" keyword */
9596696321
Table *pParent; /* Parent table that child points to */
9596796322
Index *pIdx; /* Index in the parent table */
9596896323
int i; /* Loop counter: Foreign key number for pTab */
@@ -96068,34 +96423,37 @@
9606896423
sqlite3DbFree(db, aiCols);
9606996424
}
9607096425
sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
9607196426
sqlite3VdbeJumpHere(v, addrTop);
9607296427
}
96073
- }else
96428
+ }
96429
+ break;
9607496430
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
9607596431
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
9607696432
9607796433
#ifndef NDEBUG
96078
- if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
96434
+ case PragTyp_PARSER_TRACE: {
9607996435
if( zRight ){
9608096436
if( sqlite3GetBoolean(zRight, 0) ){
9608196437
sqlite3ParserTrace(stderr, "parser: ");
9608296438
}else{
9608396439
sqlite3ParserTrace(0, 0);
9608496440
}
9608596441
}
96086
- }else
96442
+ }
96443
+ break;
9608796444
#endif
9608896445
9608996446
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
9609096447
** used will be case sensitive or not depending on the RHS.
9609196448
*/
96092
- if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
96449
+ case PragTyp_CASE_SENSITIVE_LIKE: {
9609396450
if( zRight ){
9609496451
sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
9609596452
}
96096
- }else
96453
+ }
96454
+ break;
9609796455
9609896456
#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
9609996457
# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
9610096458
#endif
9610196459
@@ -96102,13 +96460,11 @@
9610296460
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
9610396461
/* Pragma "quick_check" is reduced version of
9610496462
** integrity_check designed to detect most database corruption
9610596463
** without most of the overhead of a full integrity-check.
9610696464
*/
96107
- if( sqlite3StrICmp(zLeft, "integrity_check")==0
96108
- || sqlite3StrICmp(zLeft, "quick_check")==0
96109
- ){
96465
+ case PragTyp_INTEGRITY_CHECK: {
9611096466
int i, j, addr, mxErr;
9611196467
9611296468
/* Code that appears at the end of the integrity check. If no error
9611396469
** messages have been generated, output OK. Otherwise output the
9611496470
** error message
@@ -96264,11 +96620,12 @@
9626496620
}
9626596621
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
9626696622
sqlite3VdbeChangeP2(v, addr, -mxErr);
9626796623
sqlite3VdbeJumpHere(v, addr+1);
9626896624
sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
96269
- }else
96625
+ }
96626
+ break;
9627096627
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
9627196628
9627296629
#ifndef SQLITE_OMIT_UTF16
9627396630
/*
9627496631
** PRAGMA encoding
@@ -96290,11 +96647,11 @@
9629096647
**
9629196648
** In the second form this pragma sets the text encoding to be used in
9629296649
** new database files created using this database handle. It is only
9629396650
** useful if invoked immediately after the main database i
9629496651
*/
96295
- if( sqlite3StrICmp(zLeft, "encoding")==0 ){
96652
+ case PragTyp_ENCODING: {
9629696653
static const struct EncName {
9629796654
char *zName;
9629896655
u8 enc;
9629996656
} encnames[] = {
9630096657
{ "UTF8", SQLITE_UTF8 },
@@ -96337,11 +96694,12 @@
9633796694
if( !pEnc->zName ){
9633896695
sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
9633996696
}
9634096697
}
9634196698
}
96342
- }else
96699
+ }
96700
+ break;
9634396701
#endif /* SQLITE_OMIT_UTF16 */
9634496702
9634596703
#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
9634696704
/*
9634796705
** PRAGMA [database.]schema_version
@@ -96371,15 +96729,11 @@
9637196729
** crashes or database corruption. Use with caution!
9637296730
**
9637396731
** The user-version is not used internally by SQLite. It may be used by
9637496732
** applications for any purpose.
9637596733
*/
96376
- if( sqlite3StrICmp(zLeft, "schema_version")==0
96377
- || sqlite3StrICmp(zLeft, "user_version")==0
96378
- || sqlite3StrICmp(zLeft, "freelist_count")==0
96379
- || sqlite3StrICmp(zLeft, "application_id")==0
96380
- ){
96734
+ case PragTyp_HEADER_VALUE: {
9638196735
int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
9638296736
sqlite3VdbeUsesBtree(v, iDb);
9638396737
switch( zLeft[0] ){
9638496738
case 'a': case 'A':
9638596739
iCookie = BTREE_APPLICATION_ID;
@@ -96419,40 +96773,42 @@
9641996773
sqlite3VdbeChangeP1(v, addr+1, iDb);
9642096774
sqlite3VdbeChangeP3(v, addr+1, iCookie);
9642196775
sqlite3VdbeSetNumCols(v, 1);
9642296776
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
9642396777
}
96424
- }else
96778
+ }
96779
+ break;
9642596780
#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
9642696781
9642796782
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
9642896783
/*
9642996784
** PRAGMA compile_options
9643096785
**
9643196786
** Return the names of all compile-time options used in this build,
9643296787
** one option per row.
9643396788
*/
96434
- if( sqlite3StrICmp(zLeft, "compile_options")==0 ){
96789
+ case PragTyp_COMPILE_OPTIONS: {
9643596790
int i = 0;
9643696791
const char *zOpt;
9643796792
sqlite3VdbeSetNumCols(v, 1);
9643896793
pParse->nMem = 1;
9643996794
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
9644096795
while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
9644196796
sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
9644296797
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
9644396798
}
96444
- }else
96799
+ }
96800
+ break;
9644596801
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
9644696802
9644796803
#ifndef SQLITE_OMIT_WAL
9644896804
/*
9644996805
** PRAGMA [database.]wal_checkpoint = passive|full|restart
9645096806
**
9645196807
** Checkpoint the database.
9645296808
*/
96453
- if( sqlite3StrICmp(zLeft, "wal_checkpoint")==0 ){
96809
+ case PragTyp_WAL_CHECKPOINT: {
9645496810
int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
9645596811
int eMode = SQLITE_CHECKPOINT_PASSIVE;
9645696812
if( zRight ){
9645796813
if( sqlite3StrICmp(zRight, "full")==0 ){
9645896814
eMode = SQLITE_CHECKPOINT_FULL;
@@ -96467,39 +96823,42 @@
9646796823
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
9646896824
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
9646996825
9647096826
sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
9647196827
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
96472
- }else
96828
+ }
96829
+ break;
9647396830
9647496831
/*
9647596832
** PRAGMA wal_autocheckpoint
9647696833
** PRAGMA wal_autocheckpoint = N
9647796834
**
9647896835
** Configure a database connection to automatically checkpoint a database
9647996836
** after accumulating N frames in the log. Or query for the current value
9648096837
** of N.
9648196838
*/
96482
- if( sqlite3StrICmp(zLeft, "wal_autocheckpoint")==0 ){
96839
+ case PragTyp_WAL_AUTOCHECKPOINT: {
9648396840
if( zRight ){
9648496841
sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
9648596842
}
9648696843
returnSingleInt(pParse, "wal_autocheckpoint",
9648796844
db->xWalCallback==sqlite3WalDefaultHook ?
9648896845
SQLITE_PTR_TO_INT(db->pWalArg) : 0);
96489
- }else
96846
+ }
96847
+ break;
9649096848
#endif
9649196849
9649296850
/*
9649396851
** PRAGMA shrink_memory
9649496852
**
9649596853
** This pragma attempts to free as much memory as possible from the
9649696854
** current database connection.
9649796855
*/
96498
- if( sqlite3StrICmp(zLeft, "shrink_memory")==0 ){
96856
+ case PragTyp_SHRINK_MEMORY: {
9649996857
sqlite3_db_release_memory(db);
96500
- }else
96858
+ break;
96859
+ }
9650196860
9650296861
/*
9650396862
** PRAGMA busy_timeout
9650496863
** PRAGMA busy_timeout = N
9650596864
**
@@ -96506,22 +96865,40 @@
9650696865
** Call sqlite3_busy_timeout(db, N). Return the current timeout value
9650796866
** if one is set. If no busy handler or a different busy handler is set
9650896867
** then 0 is returned. Setting the busy_timeout to 0 or negative
9650996868
** disables the timeout.
9651096869
*/
96511
- if( sqlite3StrICmp(zLeft, "busy_timeout")==0 ){
96870
+ /*case PragTyp_BUSY_TIMEOUT*/ default: {
96871
+ assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT );
9651296872
if( zRight ){
9651396873
sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
9651496874
}
9651596875
returnSingleInt(pParse, "timeout", db->busyTimeout);
96516
- }else
96876
+ break;
96877
+ }
96878
+
96879
+ /*
96880
+ ** PRAGMA soft_heap_limit
96881
+ ** PRAGMA soft_heap_limit = N
96882
+ **
96883
+ ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
96884
+ ** use -1.
96885
+ */
96886
+ case PragTyp_SOFT_HEAP_LIMIT: {
96887
+ sqlite3_int64 N;
96888
+ if( zRight && sqlite3Atoi64(zRight, &N, 1000000, SQLITE_UTF8)==SQLITE_OK ){
96889
+ sqlite3_soft_heap_limit64(N);
96890
+ }
96891
+ returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
96892
+ break;
96893
+ }
9651796894
9651896895
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
9651996896
/*
9652096897
** Report the current state of file logs for all databases
9652196898
*/
96522
- if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
96899
+ case PragTyp_LOCK_STATUS: {
9652396900
static const char *const azLockName[] = {
9652496901
"unlocked", "shared", "reserved", "pending", "exclusive"
9652596902
};
9652696903
int i;
9652796904
sqlite3VdbeSetNumCols(v, 2);
@@ -96542,39 +96919,43 @@
9654296919
zState = azLockName[j];
9654396920
}
9654496921
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
9654596922
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
9654696923
}
96547
-
96548
- }else
96924
+ break;
96925
+ }
9654996926
#endif
9655096927
9655196928
#ifdef SQLITE_HAS_CODEC
96552
- if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
96553
- sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96554
- }else
96555
- if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
96556
- sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96557
- }else
96558
- if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
96559
- sqlite3StrICmp(zLeft, "hexrekey")==0) ){
96560
- int i, h1, h2;
96561
- char zKey[40];
96562
- for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
96563
- h1 += 9*(1&(h1>>6));
96564
- h2 += 9*(1&(h2>>6));
96565
- zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
96566
- }
96567
- if( (zLeft[3] & 0xf)==0xb ){
96568
- sqlite3_key_v2(db, zDb, zKey, i/2);
96569
- }else{
96570
- sqlite3_rekey_v2(db, zDb, zKey, i/2);
96571
- }
96572
- }else
96929
+ case PragTyp_KEY: {
96930
+ if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96931
+ break;
96932
+ }
96933
+ case PragTyp_REKEY: {
96934
+ if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96935
+ break;
96936
+ }
96937
+ case PragTyp_HEXKEY: {
96938
+ if( zRight ){
96939
+ int i, h1, h2;
96940
+ char zKey[40];
96941
+ for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
96942
+ h1 += 9*(1&(h1>>6));
96943
+ h2 += 9*(1&(h2>>6));
96944
+ zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
96945
+ }
96946
+ if( (zLeft[3] & 0xf)==0xb ){
96947
+ sqlite3_key_v2(db, zDb, zKey, i/2);
96948
+ }else{
96949
+ sqlite3_rekey_v2(db, zDb, zKey, i/2);
96950
+ }
96951
+ }
96952
+ break;
96953
+ }
9657396954
#endif
9657496955
#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
96575
- if( sqlite3StrICmp(zLeft, "activate_extensions")==0 && zRight ){
96956
+ case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){
9657696957
#ifdef SQLITE_HAS_CODEC
9657796958
if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
9657896959
sqlite3_activate_see(&zRight[4]);
9657996960
}
9658096961
#endif
@@ -96581,15 +96962,15 @@
9658196962
#ifdef SQLITE_ENABLE_CEROD
9658296963
if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
9658396964
sqlite3_activate_cerod(&zRight[6]);
9658496965
}
9658596966
#endif
96586
- }else
96967
+ }
96968
+ break;
9658796969
#endif
9658896970
96589
-
96590
- {/* Empty ELSE clause */}
96971
+ } /* End of the PRAGMA switch */
9659196972
9659296973
pragma_out:
9659396974
sqlite3DbFree(db, zLeft);
9659496975
sqlite3DbFree(db, zRight);
9659596976
}
@@ -97736,12 +98117,12 @@
9773698117
pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
9773798118
9773898119
pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
9773998120
if( pEq && isOuterJoin ){
9774098121
ExprSetProperty(pEq, EP_FromJoin);
97741
- assert( !ExprHasAnyProperty(pEq, EP_TokenOnly|EP_Reduced) );
97742
- ExprSetIrreducible(pEq);
98122
+ assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
98123
+ ExprSetVVAProperty(pEq, EP_NoReduce);
9774398124
pEq->iRightJoinTable = (i16)pE2->iTable;
9774498125
}
9774598126
*ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
9774698127
}
9774798128
@@ -97772,12 +98153,12 @@
9777298153
** the output, which is incorrect.
9777398154
*/
9777498155
static void setJoinExpr(Expr *p, int iTable){
9777598156
while( p ){
9777698157
ExprSetProperty(p, EP_FromJoin);
97777
- assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) );
97778
- ExprSetIrreducible(p);
98158
+ assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
98159
+ ExprSetVVAProperty(p, EP_NoReduce);
9777998160
p->iRightJoinTable = (i16)iTable;
9778098161
setJoinExpr(p->pLeft, iTable);
9778198162
p = p->pRight;
9778298163
}
9778398164
}
@@ -100700,11 +101081,11 @@
100700101081
assert( pTab && !pTab->pSelect && pExpr );
100701101082
100702101083
if( IsVirtual(pTab) ) return 0;
100703101084
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
100704101085
if( NEVER(pAggInfo->nFunc==0) ) return 0;
100705
- if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
101086
+ if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
100706101087
if( pExpr->flags&EP_Distinct ) return 0;
100707101088
100708101089
return pTab;
100709101090
}
100710101091
@@ -101297,11 +101678,11 @@
101297101678
if( pF->iDistinct>=0 ){
101298101679
addrNext = sqlite3VdbeMakeLabel(v);
101299101680
assert( nArg==1 );
101300101681
codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
101301101682
}
101302
- if( pF->pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
101683
+ if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
101303101684
CollSeq *pColl = 0;
101304101685
struct ExprList_item *pItem;
101305101686
int j;
101306101687
assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
101307101688
for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
@@ -104140,11 +104521,11 @@
104140104521
sqlite3GenerateConstraintChecks(pParse, pTab, iCur, regNewRowid,
104141104522
aRegIdx, (chngRowid?regOldRowid:0), 1, onError, addr, 0);
104142104523
104143104524
/* Do FK constraint checks. */
104144104525
if( hasFK ){
104145
- sqlite3FkCheck(pParse, pTab, regOldRowid, 0);
104526
+ sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngRowid);
104146104527
}
104147104528
104148104529
/* Delete the index entries associated with the current record. */
104149104530
j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regOldRowid);
104150104531
sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
@@ -104154,21 +104535,21 @@
104154104535
sqlite3VdbeAddOp2(v, OP_Delete, iCur, 0);
104155104536
}
104156104537
sqlite3VdbeJumpHere(v, j1);
104157104538
104158104539
if( hasFK ){
104159
- sqlite3FkCheck(pParse, pTab, 0, regNewRowid);
104540
+ sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngRowid);
104160104541
}
104161104542
104162104543
/* Insert the new index entries and the new record. */
104163104544
sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
104164104545
104165104546
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
104166104547
** handle rows (possibly in other tables) that refer via a foreign key
104167104548
** to the row just updated. */
104168104549
if( hasFK ){
104169
- sqlite3FkActions(pParse, pTab, pChanges, regOldRowid);
104550
+ sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngRowid);
104170104551
}
104171104552
}
104172104553
104173104554
/* Increment the row counter
104174104555
*/
@@ -105692,11 +106073,11 @@
105692106073
*pNew = *pDef;
105693106074
pNew->zName = (char *)&pNew[1];
105694106075
memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1);
105695106076
pNew->xFunc = xFunc;
105696106077
pNew->pUserData = pArg;
105697
- pNew->flags |= SQLITE_FUNC_EPHEM;
106078
+ pNew->funcFlags |= SQLITE_FUNC_EPHEM;
105698106079
return pNew;
105699106080
}
105700106081
105701106082
/*
105702106083
** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
@@ -105829,24 +106210,25 @@
105829106210
105830106211
/*
105831106212
** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The
105832106213
** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
105833106214
** (Virtual tables can return a larger cost, but let's assume they do not.)
105834
-** So all costs can be stored in a 16-bit unsigned integer without risk
106215
+** So all costs can be stored in a 16-bit integer without risk
105835106216
** of overflow.
105836106217
**
105837106218
** Costs are estimates, so no effort is made to compute 10*log2(X) exactly.
105838
-** Instead, a close estimate is used. Any value of X<=1 is stored as 0.
105839
-** X=2 is 10. X=3 is 16. X=1000 is 99. etc.
106219
+** Instead, a close estimate is used. Any value of X=1 is stored as 0.
106220
+** X=2 is 10. X=3 is 16. X=1000 is 99. etc. Negative values are allowed.
106221
+** A WhereCost of -10 means 0.5. WhereCost of -20 means 0.25. And so forth.
105840106222
**
105841106223
** The tool/wherecosttest.c source file implements a command-line program
105842106224
** that will convert WhereCosts to integers, convert integers to WhereCosts
105843106225
** and do addition and multiplication on WhereCost values. The wherecosttest
105844106226
** command-line program is a useful utility to have around when working with
105845106227
** this module.
105846106228
*/
105847
-typedef unsigned short int WhereCost;
106229
+typedef short int WhereCost;
105848106230
105849106231
/*
105850106232
** This object contains information needed to implement a single nested
105851106233
** loop in WHERE clause.
105852106234
**
@@ -105883,10 +106265,11 @@
105883106265
} *aInLoop; /* Information about each nested IN operator */
105884106266
} in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
105885106267
Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
105886106268
} u;
105887106269
struct WhereLoop *pWLoop; /* The selected WhereLoop object */
106270
+ Bitmask notReady; /* FROM entries not usable at this level */
105888106271
};
105889106272
105890106273
/*
105891106274
** Each instance of this object represents an algorithm for evaluating one
105892106275
** term of a join. Every term of the FROM clause will have at least
@@ -106045,10 +106428,11 @@
106045106428
union {
106046106429
int leftColumn; /* Column number of X in "X <op> <expr>" */
106047106430
WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
106048106431
WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
106049106432
} u;
106433
+ WhereCost truthProb; /* Probability of truth for this expression */
106050106434
u16 eOperator; /* A WO_xx value describing <op> */
106051106435
u8 wtFlags; /* TERM_xxx bit flags. See below */
106052106436
u8 nChild; /* Number of children that must disable us */
106053106437
WhereClause *pWC; /* The clause this term is part of */
106054106438
Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
@@ -106419,10 +106803,13 @@
106419106803
if( pWC->a!=pWC->aStatic ){
106420106804
sqlite3DbFree(db, pWC->a);
106421106805
}
106422106806
}
106423106807
106808
+/* Forward declaration */
106809
+static WhereCost whereCost(tRowcnt x);
106810
+
106424106811
/*
106425106812
** Add a single new WhereTerm entry to the WhereClause object pWC.
106426106813
** The new WhereTerm object is constructed from Expr p and with wtFlags.
106427106814
** The index in pWC->a[] of the new WhereTerm is returned on success.
106428106815
** 0 is returned if the new WhereTerm could not be added due to a memory
@@ -106460,10 +106847,15 @@
106460106847
sqlite3DbFree(db, pOld);
106461106848
}
106462106849
pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
106463106850
}
106464106851
pTerm = &pWC->a[idx = pWC->nTerm++];
106852
+ if( p && ExprHasProperty(p, EP_Unlikely) ){
106853
+ pTerm->truthProb = whereCost(p->iTable) - 99;
106854
+ }else{
106855
+ pTerm->truthProb = -1;
106856
+ }
106465106857
pTerm->pExpr = sqlite3ExprSkipCollate(p);
106466106858
pTerm->wtFlags = wtFlags;
106467106859
pTerm->pWC = pWC;
106468106860
pTerm->iParent = -1;
106469106861
return idx;
@@ -108321,18 +108713,19 @@
108321108713
WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */
108322108714
WhereCost *pnOut /* IN/OUT: Number of rows visited */
108323108715
){
108324108716
int rc = SQLITE_OK;
108325108717
int nOut = (int)*pnOut;
108718
+ WhereCost nNew;
108326108719
108327108720
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
108328108721
Index *p = pBuilder->pNew->u.btree.pIndex;
108329108722
int nEq = pBuilder->pNew->u.btree.nEq;
108330108723
108331
- if( nEq==pBuilder->nRecValid
108724
+ if( p->nSample>0
108725
+ && nEq==pBuilder->nRecValid
108332108726
&& nEq<p->nSampleCol
108333
- && p->nSample
108334108727
&& OptimizationEnabled(pParse->db, SQLITE_Stat3)
108335108728
){
108336108729
UnpackedRecord *pRec = pBuilder->pRec;
108337108730
tRowcnt a[2];
108338108731
u8 aff;
@@ -108383,10 +108776,11 @@
108383108776
if( rc==SQLITE_OK && bOk ){
108384108777
tRowcnt iNew;
108385108778
whereKeyStats(pParse, p, pRec, 0, a);
108386108779
iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
108387108780
if( iNew>iLower ) iLower = iNew;
108781
+ nOut--;
108388108782
}
108389108783
}
108390108784
108391108785
/* If possible, improve on the iUpper estimate using ($P:$U). */
108392108786
if( pUpper ){
@@ -108397,16 +108791,16 @@
108397108791
if( rc==SQLITE_OK && bOk ){
108398108792
tRowcnt iNew;
108399108793
whereKeyStats(pParse, p, pRec, 1, a);
108400108794
iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
108401108795
if( iNew<iUpper ) iUpper = iNew;
108796
+ nOut--;
108402108797
}
108403108798
}
108404108799
108405108800
pBuilder->pRec = pRec;
108406108801
if( rc==SQLITE_OK ){
108407
- WhereCost nNew;
108408108802
if( iUpper>iLower ){
108409108803
nNew = whereCost(iUpper - iLower);
108410108804
}else{
108411108805
nNew = 10; assert( 10==whereCost(2) );
108412108806
}
@@ -108424,17 +108818,21 @@
108424108818
UNUSED_PARAMETER(pBuilder);
108425108819
#endif
108426108820
assert( pLower || pUpper );
108427108821
/* TUNING: Each inequality constraint reduces the search space 4-fold.
108428108822
** A BETWEEN operator, therefore, reduces the search space 16-fold */
108823
+ nNew = nOut;
108429108824
if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ){
108430
- nOut -= 20; assert( 20==whereCost(4) );
108825
+ nNew -= 20; assert( 20==whereCost(4) );
108826
+ nOut--;
108431108827
}
108432108828
if( pUpper ){
108433
- nOut -= 20; assert( 20==whereCost(4) );
108829
+ nNew -= 20; assert( 20==whereCost(4) );
108830
+ nOut--;
108434108831
}
108435
- if( nOut<10 ) nOut = 10;
108832
+ if( nNew<10 ) nNew = 10;
108833
+ if( nNew<nOut ) nOut = nNew;
108436108834
*pnOut = (WhereCost)nOut;
108437108835
return rc;
108438108836
}
108439108837
108440108838
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -108576,10 +108974,11 @@
108576108974
*/
108577108975
static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
108578108976
if( pTerm
108579108977
&& (pTerm->wtFlags & TERM_CODED)==0
108580108978
&& (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
108979
+ && (pLevel->notReady & pTerm->prereqAll)==0
108581108980
){
108582108981
pTerm->wtFlags |= TERM_CODED;
108583108982
if( pTerm->iParent>=0 ){
108584108983
WhereTerm *pOther = &pTerm->pWC->a[pTerm->iParent];
108585108984
if( (--pOther->nChild)==0 ){
@@ -109001,20 +109400,20 @@
109001109400
struct SrcList_item *pTabItem; /* FROM clause term being coded */
109002109401
int addrBrk; /* Jump here to break out of the loop */
109003109402
int addrCont; /* Jump here to continue with next cycle */
109004109403
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
109005109404
int iReleaseReg = 0; /* Temp register to free before returning */
109006
- Bitmask newNotReady; /* Return value */
109007109405
109008109406
pParse = pWInfo->pParse;
109009109407
v = pParse->pVdbe;
109010109408
pWC = &pWInfo->sWC;
109011109409
db = pParse->db;
109012109410
pLevel = &pWInfo->a[iLevel];
109013109411
pLoop = pLevel->pWLoop;
109014109412
pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
109015109413
iCur = pTabItem->iCursor;
109414
+ pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109016109415
bRev = (pWInfo->revMask>>iLevel)&1;
109017109416
omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
109018109417
&& (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
109019109418
VdbeNoopComment((v, "Begin Join Loop %d", iLevel));
109020109419
@@ -109663,21 +110062,20 @@
109663110062
pLevel->op = aStep[bRev];
109664110063
pLevel->p1 = iCur;
109665110064
pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
109666110065
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
109667110066
}
109668
- newNotReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109669110067
109670110068
/* Insert code to test every subexpression that can be completely
109671110069
** computed using the current set of tables.
109672110070
*/
109673110071
for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
109674110072
Expr *pE;
109675110073
testcase( pTerm->wtFlags & TERM_VIRTUAL );
109676110074
testcase( pTerm->wtFlags & TERM_CODED );
109677110075
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
109678
- if( (pTerm->prereqAll & newNotReady)!=0 ){
110076
+ if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
109679110077
testcase( pWInfo->untestedTerms==0
109680110078
&& (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
109681110079
pWInfo->untestedTerms = 1;
109682110080
continue;
109683110081
}
@@ -109705,11 +110103,11 @@
109705110103
if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
109706110104
if( pTerm->leftCursor!=iCur ) continue;
109707110105
if( pLevel->iLeftJoin ) continue;
109708110106
pE = pTerm->pExpr;
109709110107
assert( !ExprHasProperty(pE, EP_FromJoin) );
109710
- assert( (pTerm->prereqRight & newNotReady)!=0 );
110108
+ assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
109711110109
pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
109712110110
if( pAlt==0 ) continue;
109713110111
if( pAlt->wtFlags & (TERM_CODED) ) continue;
109714110112
testcase( pAlt->eOperator & WO_EQ );
109715110113
testcase( pAlt->eOperator & WO_IN );
@@ -109733,11 +110131,11 @@
109733110131
sqlite3ExprCacheClear(pParse);
109734110132
for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
109735110133
testcase( pTerm->wtFlags & TERM_VIRTUAL );
109736110134
testcase( pTerm->wtFlags & TERM_CODED );
109737110135
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
109738
- if( (pTerm->prereqAll & newNotReady)!=0 ){
110136
+ if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
109739110137
assert( pWInfo->untestedTerms );
109740110138
continue;
109741110139
}
109742110140
assert( pTerm->pExpr );
109743110141
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
@@ -109744,11 +110142,11 @@
109744110142
pTerm->wtFlags |= TERM_CODED;
109745110143
}
109746110144
}
109747110145
sqlite3ReleaseTempReg(pParse, iReleaseReg);
109748110146
109749
- return newNotReady;
110147
+ return pLevel->notReady;
109750110148
}
109751110149
109752110150
#ifdef WHERETRACE_ENABLED
109753110151
/*
109754110152
** Print a WhereLoop object for debugging purposes
@@ -109845,12 +110243,15 @@
109845110243
109846110244
/*
109847110245
** Transfer content from the second pLoop into the first.
109848110246
*/
109849110247
static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
109850
- if( whereLoopResize(db, pTo, pFrom->nLTerm) ) return SQLITE_NOMEM;
109851110248
whereLoopClearUnion(db, pTo);
110249
+ if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
110250
+ memset(&pTo->u, 0, sizeof(pTo->u));
110251
+ return SQLITE_NOMEM;
110252
+ }
109852110253
memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
109853110254
memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
109854110255
if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
109855110256
pFrom->u.vtab.needFree = 0;
109856110257
}else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
@@ -109962,13 +110363,13 @@
109962110363
** all of (1) dependencies (2) setup-cost, (3) run-cost, and
109963110364
** (4) number of output rows. */
109964110365
assert( p->rSetup==pTemplate->rSetup );
109965110366
if( p->prereq==pTemplate->prereq
109966110367
&& p->nLTerm<pTemplate->nLTerm
109967
- && (p->wsFlags & WHERE_INDEXED)!=0
109968
- && (pTemplate->wsFlags & WHERE_INDEXED)!=0
109969
- && p->u.btree.pIndex==pTemplate->u.btree.pIndex
110368
+ && (p->wsFlags & pTemplate->wsFlags & WHERE_INDEXED)!=0
110369
+ && (p->u.btree.pIndex==pTemplate->u.btree.pIndex
110370
+ || pTemplate->rRun+p->nLTerm<=p->rRun+pTemplate->nLTerm)
109970110371
){
109971110372
/* Overwrite an existing WhereLoop with an similar one that uses
109972110373
** more terms of the index */
109973110374
pNext = p->pNextLoop;
109974110375
break;
@@ -109979,16 +110380,16 @@
109979110380
}
109980110381
}
109981110382
if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
109982110383
&& p->rRun>=pTemplate->rRun
109983110384
&& p->nOut>=pTemplate->nOut
109984
- && ALWAYS(p->rSetup>=pTemplate->rSetup) /* See SETUP-INVARIANT above */
109985110385
){
109986110386
/* Overwrite an existing WhereLoop with a better one: one that is
109987110387
** better at one of (1) dependencies, (2) setup-cost, (3) run-cost
109988110388
** or (4) number of output rows, and is no worse in any of those
109989110389
** categories. */
110390
+ assert( p->rSetup>=pTemplate->rSetup ); /* SETUP-INVARIANT above */
109990110391
pNext = p->pNextLoop;
109991110392
break;
109992110393
}
109993110394
}
109994110395
@@ -110030,10 +110431,40 @@
110030110431
whereLoopPrint(pTemplate, pWInfo->pTabList);
110031110432
}
110032110433
#endif
110033110434
return SQLITE_OK;
110034110435
}
110436
+
110437
+/*
110438
+** Adjust the WhereLoop.nOut value downward to account for terms of the
110439
+** WHERE clause that reference the loop but which are not used by an
110440
+** index.
110441
+**
110442
+** In the current implementation, the first extra WHERE clause term reduces
110443
+** the number of output rows by a factor of 10 and each additional term
110444
+** reduces the number of output rows by sqrt(2).
110445
+*/
110446
+static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop, int iCur){
110447
+ WhereTerm *pTerm, *pX;
110448
+ Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
110449
+ int i, j;
110450
+
110451
+ if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){
110452
+ return;
110453
+ }
110454
+ for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
110455
+ if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
110456
+ if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
110457
+ if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
110458
+ for(j=pLoop->nLTerm-1; j>=0; j--){
110459
+ pX = pLoop->aLTerm[j];
110460
+ if( pX==pTerm ) break;
110461
+ if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
110462
+ }
110463
+ if( j<0 ) pLoop->nOut += pTerm->truthProb;
110464
+ }
110465
+}
110035110466
110036110467
/*
110037110468
** We have so far matched pBuilder->pNew->u.btree.nEq terms of the index pIndex.
110038110469
** Try to match one more.
110039110470
**
@@ -110197,11 +110628,11 @@
110197110628
** the main table */
110198110629
pNew->rRun = whereCostAdd(pNew->rRun, rLogSize>27 ? rLogSize-17 : 10);
110199110630
}
110200110631
/* Step cost for each output row */
110201110632
pNew->rRun = whereCostAdd(pNew->rRun, pNew->nOut);
110202
- /* TBD: Adjust nOut for additional constraints */
110633
+ whereLoopOutputAdjust(pBuilder->pWC, pNew, pSrc->iCursor);
110203110634
rc = whereLoopInsert(pBuilder, pNew);
110204110635
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
110205110636
&& pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0))
110206110637
){
110207110638
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -110401,11 +110832,13 @@
110401110832
** + The extra 3 factor is to encourage the use of indexed lookups
110402110833
** over full scans. A smaller constant 2 is used for covering
110403110834
** index scans so that a covering index scan will be favored over
110404110835
** a table scan. */
110405110836
pNew->rRun = whereCostAdd(rSize,rLogSize) + 16;
110837
+ whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor);
110406110838
rc = whereLoopInsert(pBuilder, pNew);
110839
+ pNew->nOut = rSize;
110407110840
if( rc ) break;
110408110841
}else{
110409110842
Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe);
110410110843
pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
110411110844
@@ -110433,11 +110866,13 @@
110433110866
assert( b!=0 );
110434110867
/* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N)
110435110868
** which we will simplify to just N*log2(N) */
110436110869
pNew->rRun = rSize + rLogSize;
110437110870
}
110871
+ whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor);
110438110872
rc = whereLoopInsert(pBuilder, pNew);
110873
+ pNew->nOut = rSize;
110439110874
if( rc ) break;
110440110875
}
110441110876
}
110442110877
110443110878
rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
@@ -111040,13 +111475,16 @@
111040111475
int nLoop; /* Number of terms in the join */
111041111476
Parse *pParse; /* Parsing context */
111042111477
sqlite3 *db; /* The database connection */
111043111478
int iLoop; /* Loop counter over the terms of the join */
111044111479
int ii, jj; /* Loop counters */
111045
- WhereCost rCost; /* Cost of a path */
111046
- WhereCost mxCost = 0; /* Maximum cost of a set of paths */
111047
- WhereCost rSortCost; /* Cost to do a sort */
111480
+ int mxI = 0; /* Index of next entry to replace */
111481
+ WhereCost rCost; /* Cost of a path */
111482
+ WhereCost nOut; /* Number of outputs */
111483
+ WhereCost mxCost = 0; /* Maximum cost of a set of paths */
111484
+ WhereCost mxOut = 0; /* Maximum nOut value on the set of paths */
111485
+ WhereCost rSortCost; /* Cost to do a sort */
111048111486
int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
111049111487
WherePath *aFrom; /* All nFrom paths at the previous level */
111050111488
WherePath *aTo; /* The nTo best paths at the current level */
111051111489
WherePath *pFrom; /* An element of aFrom[] that we are working on */
111052111490
WherePath *pTo; /* An element of aTo[] that we are working on */
@@ -111111,10 +111549,11 @@
111111111549
if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
111112111550
/* At this point, pWLoop is a candidate to be the next loop.
111113111551
** Compute its cost */
111114111552
rCost = whereCostAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
111115111553
rCost = whereCostAdd(rCost, pFrom->rCost);
111554
+ nOut = pFrom->nRow + pWLoop->nOut;
111116111555
maskNew = pFrom->maskLoop | pWLoop->maskSelf;
111117111556
if( !isOrderedValid ){
111118111557
switch( wherePathSatisfiesOrderBy(pWInfo,
111119111558
pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
111120111559
iLoop, pWLoop, &revMask) ){
@@ -111133,21 +111572,25 @@
111133111572
}else{
111134111573
revMask = pFrom->revLoop;
111135111574
}
111136111575
/* Check to see if pWLoop should be added to the mxChoice best so far */
111137111576
for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
111138
- if( pTo->maskLoop==maskNew && pTo->isOrderedValid==isOrderedValid ){
111577
+ if( pTo->maskLoop==maskNew
111578
+ && pTo->isOrderedValid==isOrderedValid
111579
+ && ((pTo->rCost<=rCost && pTo->nRow<=nOut) ||
111580
+ (pTo->rCost>=rCost && pTo->nRow>=nOut))
111581
+ ){
111139111582
testcase( jj==nTo-1 );
111140111583
break;
111141111584
}
111142111585
}
111143111586
if( jj>=nTo ){
111144111587
if( nTo>=mxChoice && rCost>=mxCost ){
111145111588
#ifdef WHERETRACE_ENABLED
111146111589
if( sqlite3WhereTrace&0x4 ){
111147
- sqlite3DebugPrintf("Skip %s cost=%3d order=%c\n",
111148
- wherePathName(pFrom, iLoop, pWLoop), rCost,
111590
+ sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
111591
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111149111592
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111150111593
}
111151111594
#endif
111152111595
continue;
111153111596
}
@@ -111155,30 +111598,30 @@
111155111598
if( nTo<mxChoice ){
111156111599
/* Increase the size of the aTo set by one */
111157111600
jj = nTo++;
111158111601
}else{
111159111602
/* New path replaces the prior worst to keep count below mxChoice */
111160
- for(jj=nTo-1; aTo[jj].rCost<mxCost; jj--){ assert(jj>0); }
111603
+ jj = mxI;
111161111604
}
111162111605
pTo = &aTo[jj];
111163111606
#ifdef WHERETRACE_ENABLED
111164111607
if( sqlite3WhereTrace&0x4 ){
111165
- sqlite3DebugPrintf("New %s cost=%-3d order=%c\n",
111166
- wherePathName(pFrom, iLoop, pWLoop), rCost,
111608
+ sqlite3DebugPrintf("New %s cost=%-3d,%3d order=%c\n",
111609
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111167111610
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111168111611
}
111169111612
#endif
111170111613
}else{
111171
- if( pTo->rCost<=rCost ){
111614
+ if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
111172111615
#ifdef WHERETRACE_ENABLED
111173111616
if( sqlite3WhereTrace&0x4 ){
111174111617
sqlite3DebugPrintf(
111175
- "Skip %s cost=%-3d order=%c",
111176
- wherePathName(pFrom, iLoop, pWLoop), rCost,
111618
+ "Skip %s cost=%-3d,%3d order=%c",
111619
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111177111620
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111178
- sqlite3DebugPrintf(" vs %s cost=%-3d order=%c\n",
111179
- wherePathName(pTo, iLoop+1, 0), pTo->rCost,
111621
+ sqlite3DebugPrintf(" vs %s cost=%-3d,%d order=%c\n",
111622
+ wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
111180111623
pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
111181111624
}
111182111625
#endif
111183111626
testcase( pTo->rCost==rCost );
111184111627
continue;
@@ -111186,32 +111629,38 @@
111186111629
testcase( pTo->rCost==rCost+1 );
111187111630
/* A new and better score for a previously created equivalent path */
111188111631
#ifdef WHERETRACE_ENABLED
111189111632
if( sqlite3WhereTrace&0x4 ){
111190111633
sqlite3DebugPrintf(
111191
- "Update %s cost=%-3d order=%c",
111192
- wherePathName(pFrom, iLoop, pWLoop), rCost,
111634
+ "Update %s cost=%-3d,%3d order=%c",
111635
+ wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111193111636
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111194
- sqlite3DebugPrintf(" was %s cost=%-3d order=%c\n",
111195
- wherePathName(pTo, iLoop+1, 0), pTo->rCost,
111637
+ sqlite3DebugPrintf(" was %s cost=%-3d,%3d order=%c\n",
111638
+ wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
111196111639
pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
111197111640
}
111198111641
#endif
111199111642
}
111200111643
/* pWLoop is a winner. Add it to the set of best so far */
111201111644
pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
111202111645
pTo->revLoop = revMask;
111203
- pTo->nRow = pFrom->nRow + pWLoop->nOut;
111646
+ pTo->nRow = nOut;
111204111647
pTo->rCost = rCost;
111205111648
pTo->isOrderedValid = isOrderedValid;
111206111649
pTo->isOrdered = isOrdered;
111207111650
memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
111208111651
pTo->aLoop[iLoop] = pWLoop;
111209111652
if( nTo>=mxChoice ){
111653
+ mxI = 0;
111210111654
mxCost = aTo[0].rCost;
111655
+ mxOut = aTo[0].nRow;
111211111656
for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
111212
- if( pTo->rCost>mxCost ) mxCost = pTo->rCost;
111657
+ if( pTo->rCost>mxCost || (pTo->rCost==mxCost && pTo->nRow>mxOut) ){
111658
+ mxCost = pTo->rCost;
111659
+ mxOut = pTo->nRow;
111660
+ mxI = jj;
111661
+ }
111213111662
}
111214111663
}
111215111664
}
111216111665
}
111217111666
@@ -111244,16 +111693,13 @@
111244111693
return SQLITE_ERROR;
111245111694
}
111246111695
111247111696
/* Find the lowest cost path. pFrom will be left pointing to that path */
111248111697
pFrom = aFrom;
111249
- assert( nFrom==1 );
111250
-#if 0 /* The following is needed if nFrom is ever more than 1 */
111251111698
for(ii=1; ii<nFrom; ii++){
111252111699
if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
111253111700
}
111254
-#endif
111255111701
assert( pWInfo->nLevel==nLoop );
111256111702
/* Load the lowest cost path into pWInfo */
111257111703
for(iLoop=0; iLoop<nLoop; iLoop++){
111258111704
WhereLevel *pLevel = pWInfo->a + iLoop;
111259111705
pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -114879,16 +115325,17 @@
114879115325
yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
114880115326
}
114881115327
break;
114882115328
case 231: /* expr ::= CASE case_operand case_exprlist case_else END */
114883115329
{
114884
- yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, 0);
115330
+ yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, 0, 0);
114885115331
if( yygotominor.yy342.pExpr ){
114886
- yygotominor.yy342.pExpr->x.pList = yymsp[-2].minor.yy442;
115332
+ yygotominor.yy342.pExpr->x.pList = yymsp[-1].minor.yy122 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[-1].minor.yy122) : yymsp[-2].minor.yy442;
114887115333
sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
114888115334
}else{
114889115335
sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
115336
+ sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy122);
114890115337
}
114891115338
yygotominor.yy342.zStart = yymsp[-4].minor.yy0.z;
114892115339
yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
114893115340
}
114894115341
break;
@@ -118020,11 +118467,11 @@
118020118467
** and there are active VMs, then return SQLITE_BUSY. If a function
118021118468
** is being overridden/deleted but there are no active VMs, allow the
118022118469
** operation to continue but invalidate all precompiled statements.
118023118470
*/
118024118471
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
118025
- if( p && p->iPrefEnc==enc && p->nArg==nArg ){
118472
+ if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){
118026118473
if( db->nVdbeActive ){
118027118474
sqlite3Error(db, SQLITE_BUSY,
118028118475
"unable to delete/modify user-function due to active statements");
118029118476
assert( !db->mallocFailed );
118030118477
return SQLITE_BUSY;
@@ -118045,11 +118492,11 @@
118045118492
118046118493
if( pDestructor ){
118047118494
pDestructor->nRef++;
118048118495
}
118049118496
p->pDestructor = pDestructor;
118050
- p->flags = 0;
118497
+ p->funcFlags &= SQLITE_FUNC_ENCMASK;
118051118498
p->xFunc = xFunc;
118052118499
p->xStep = xStep;
118053118500
p->xFinalize = xFinal;
118054118501
p->pUserData = pUserData;
118055118502
p->nArg = (u16)nArg;
118056118503
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.1"
660 #define SQLITE_VERSION_NUMBER 3008001
661 #define SQLITE_SOURCE_ID "2013-09-04 04:04:08 8df95bb0b3f72222cf262174247a467c234f9939"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -10143,12 +10143,10 @@
10143 #endif
10144 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
10145 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
10146 void *pCollNeededArg;
10147 sqlite3_value *pErr; /* Most recent error message */
10148 char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
10149 char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
10150 union {
10151 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
10152 double notUsed1; /* Spacer */
10153 } u1;
10154 Lookaside lookaside; /* Lookaside malloc configuration */
@@ -10254,10 +10252,11 @@
10254 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10255 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10256 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10257 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10258 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
 
10259 #define SQLITE_AllOpts 0xffff /* All optimizations */
10260
10261 /*
10262 ** Macros for testing whether or not optimizations are enabled or disabled.
10263 */
@@ -10287,12 +10286,11 @@
10287 ** hash table. When multiple functions have the same name, the hash table
10288 ** points to a linked list of these structures.
10289 */
10290 struct FuncDef {
10291 i16 nArg; /* Number of arguments. -1 means unlimited */
10292 u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
10293 u8 flags; /* Some combination of SQLITE_FUNC_* */
10294 void *pUserData; /* User data parameter */
10295 FuncDef *pNext; /* Next function with same name */
10296 void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
10297 void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
10298 void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
@@ -10324,18 +10322,20 @@
10324 /*
10325 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
10326 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There
10327 ** are assert() statements in the code to verify this.
10328 */
10329 #define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
10330 #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
10331 #define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */
10332 #define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
10333 #define SQLITE_FUNC_COUNT 0x10 /* Built-in count(*) aggregate */
10334 #define SQLITE_FUNC_COALESCE 0x20 /* Built-in coalesce() or ifnull() function */
10335 #define SQLITE_FUNC_LENGTH 0x40 /* Built-in length() function */
10336 #define SQLITE_FUNC_TYPEOF 0x80 /* Built-in typeof() function */
 
 
10337
10338 /*
10339 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10340 ** used to create the initializers for the FuncDef structures.
10341 **
@@ -10359,22 +10359,22 @@
10359 ** available as the function user-data (sqlite3_user_data()). The
10360 ** FuncDef.flags variable is set to the value passed as the flags
10361 ** parameter.
10362 */
10363 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
10364 {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL), \
10365 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10366 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10367 {nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
10368 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10369 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10370 {nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
10371 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
10372 #define LIKEFUNC(zName, nArg, arg, flags) \
10373 {nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10374 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10375 {nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
10376 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10377
10378 /*
10379 ** All current savepoints are stored in a linked list starting at
10380 ** sqlite3.pSavepoint. The first element in the list is the most recently
@@ -10945,11 +10945,11 @@
10945 ** allocated, regardless of whether or not EP_Reduced is set.
10946 */
10947 struct Expr {
10948 u8 op; /* Operation performed by this node */
10949 char affinity; /* The affinity of the column or 0 if not a column */
10950 u16 flags; /* Various flags. EP_* See below */
10951 union {
10952 char *zToken; /* Token value. Zero terminated and dequoted */
10953 int iValue; /* Non-negative integer value if EP_IntValue */
10954 } u;
10955
@@ -10959,12 +10959,12 @@
10959 *********************************************************************/
10960
10961 Expr *pLeft; /* Left subnode */
10962 Expr *pRight; /* Right subnode */
10963 union {
10964 ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */
10965 Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */
10966 } x;
10967
10968 /* If the EP_Reduced flag is set in the Expr.flags mask, then no
10969 ** space is allocated for the fields below this point. An attempt to
10970 ** access them will result in a segfault or malfunction.
@@ -10973,16 +10973,16 @@
10973 #if SQLITE_MAX_EXPR_DEPTH>0
10974 int nHeight; /* Height of the tree headed by this node */
10975 #endif
10976 int iTable; /* TK_COLUMN: cursor number of table holding column
10977 ** TK_REGISTER: register number
10978 ** TK_TRIGGER: 1 -> new, 0 -> old */
 
10979 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
10980 ** TK_VARIABLE: variable number (always >= 1). */
10981 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
10982 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
10983 u8 flags2; /* Second set of flags. EP2_... */
10984 u8 op2; /* TK_REGISTER: original value of Expr.op
10985 ** TK_COLUMN: the value of p5 for OP_Column
10986 ** TK_AGG_FUNCTION: nesting depth */
10987 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
10988 Table *pTab; /* Table for TK_COLUMN expressions. */
@@ -10989,53 +10989,48 @@
10989 };
10990
10991 /*
10992 ** The following are the meanings of bits in the Expr.flags field.
10993 */
10994 #define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
10995 #define EP_Agg 0x0002 /* Contains one or more aggregate functions */
10996 #define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
10997 #define EP_Error 0x0008 /* Expression contains one or more errors */
10998 #define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */
10999 #define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
11000 #define EP_DblQuoted 0x0040 /* token.z was originally in "..." */
11001 #define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */
11002 #define EP_Collate 0x0100 /* Tree contains a TK_COLLATE opeartor */
11003 #define EP_FixedDest 0x0200 /* Result needed in a specific register */
11004 #define EP_IntValue 0x0400 /* Integer value contained in u.iValue */
11005 #define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */
11006 #define EP_Hint 0x1000 /* Not used */
11007 #define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */
11008 #define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */
11009 #define EP_Static 0x8000 /* Held in memory not obtained from malloc() */
11010
11011 /*
11012 ** The following are the meanings of bits in the Expr.flags2 field.
11013 */
11014 #define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */
11015 #define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */
11016
11017 /*
11018 ** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible
11019 ** flag on an expression structure. This flag is used for VV&A only. The
11020 ** routine is implemented as a macro that only works when in debugging mode,
11021 ** so as not to burden production code.
11022 */
11023 #ifdef SQLITE_DEBUG
11024 # define ExprSetIrreducible(X) (X)->flags2 |= EP2_Irreducible
11025 #else
11026 # define ExprSetIrreducible(X)
11027 #endif
11028
11029 /*
11030 ** These macros can be used to test, set, or clear bits in the
11031 ** Expr.flags field.
11032 */
11033 #define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
11034 #define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
11035 #define ExprSetProperty(E,P) (E)->flags|=(P)
11036 #define ExprClearProperty(E,P) (E)->flags&=~(P)
 
 
 
 
 
 
 
 
 
 
11037
11038 /*
11039 ** Macros to determine the number of bytes required by a normal Expr
11040 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
11041 ** and an Expr struct with the EP_TokenOnly flag set.
@@ -12411,10 +12406,11 @@
12411 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
12412 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
12413 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
12414 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
12415 SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
 
12416 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
12417 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
12418 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
12419 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
12420 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
@@ -12431,22 +12427,22 @@
12431 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
12432 ** this case foreign keys are parsed, but no other functionality is
12433 ** provided (enforcement of FK constraints requires the triggers sub-system).
12434 */
12435 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
12436 SQLITE_PRIVATE void sqlite3FkCheck(Parse*, Table*, int, int);
12437 SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
12438 SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int);
12439 SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
12440 SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
12441 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
12442 #else
12443 #define sqlite3FkActions(a,b,c,d)
12444 #define sqlite3FkCheck(a,b,c,d)
12445 #define sqlite3FkDropTable(a,b,c)
12446 #define sqlite3FkOldmask(a,b) 0
12447 #define sqlite3FkRequired(a,b,c,d) 0
12448 #endif
12449 #ifndef SQLITE_OMIT_FOREIGN_KEY
12450 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
12451 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
12452 #else
@@ -13589,10 +13585,11 @@
13589 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13590 u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */
13591 #ifndef SQLITE_OMIT_TRACE
13592 i64 startTime; /* Time when query started - used for profiling */
13593 #endif
 
13594 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13595 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13596 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
13597 char *zSql; /* Text of the SQL statement that generated this */
13598 void *pFree; /* Free this when deleting the vdbe */
@@ -14268,12 +14265,12 @@
14268 ** Set the time to the current time reported by the VFS.
14269 **
14270 ** Return the number of errors.
14271 */
14272 static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
14273 sqlite3 *db = sqlite3_context_db_handle(context);
14274 if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
14275 p->validJD = 1;
14276 return 0;
14277 }else{
14278 return 1;
14279 }
@@ -15052,12 +15049,12 @@
15052 char zBuf[20];
15053
15054 UNUSED_PARAMETER(argc);
15055 UNUSED_PARAMETER(argv);
15056
15057 db = sqlite3_context_db_handle(context);
15058 if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
15059 t = iT/1000 - 10000*(sqlite3_int64)21086676;
15060 #ifdef HAVE_GMTIME_R
15061 pTm = gmtime_r(&t, &sNow);
15062 #else
15063 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
@@ -19259,10 +19256,11 @@
19259 ** Free memory that might be associated with a particular database
19260 ** connection.
19261 */
19262 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
19263 assert( db==0 || sqlite3_mutex_held(db->mutex) );
 
19264 if( db ){
19265 if( db->pnBytesFreed ){
19266 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
19267 return;
19268 }
@@ -21374,11 +21372,12 @@
21374 case '"': break;
21375 case '`': break; /* For MySQL compatibility */
21376 case '[': quote = ']'; break; /* For MS SqlServer compatibility */
21377 default: return -1;
21378 }
21379 for(i=1, j=0; ALWAYS(z[i]); i++){
 
21380 if( z[i]==quote ){
21381 if( z[i+1]==quote ){
21382 z[j++] = quote;
21383 i++;
21384 }else{
@@ -30809,10 +30808,18 @@
30809 */
30810 #ifndef winIsDirSep
30811 # define winIsDirSep(a) (((a) == '/') || ((a) == '\\'))
30812 #endif
30813
 
 
 
 
 
 
 
 
30814 /*
30815 ** Returns the string that should be used as the directory separator.
30816 */
30817 #ifndef winGetDirDep
30818 # ifdef __CYGWIN__
@@ -31059,11 +31066,12 @@
31059 ** In order to facilitate testing on a WinNT system, the test fixture
31060 ** can manually set this value to 1 to emulate Win98 behavior.
31061 */
31062 #ifdef SQLITE_TEST
31063 SQLITE_API int sqlite3_os_type = 0;
31064 #else
 
31065 static int sqlite3_os_type = 0;
31066 #endif
31067
31068 #ifndef SYSCALL
31069 # define SYSCALL sqlite3_syscall_ptr
@@ -31374,89 +31382,98 @@
31374 #endif
31375
31376 #define osGetVersionExA ((BOOL(WINAPI*)( \
31377 LPOSVERSIONINFOA))aSyscall[34].pCurrent)
31378
 
 
 
 
 
 
 
 
 
31379 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
31380
31381 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
31382 SIZE_T))aSyscall[35].pCurrent)
31383
31384 #if !SQLITE_OS_WINRT
31385 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
31386 #else
31387 { "HeapCreate", (SYSCALL)0, 0 },
31388 #endif
31389
31390 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
31391 SIZE_T))aSyscall[36].pCurrent)
31392
31393 #if !SQLITE_OS_WINRT
31394 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
31395 #else
31396 { "HeapDestroy", (SYSCALL)0, 0 },
31397 #endif
31398
31399 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
31400
31401 { "HeapFree", (SYSCALL)HeapFree, 0 },
31402
31403 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
31404
31405 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
31406
31407 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
31408 SIZE_T))aSyscall[39].pCurrent)
31409
31410 { "HeapSize", (SYSCALL)HeapSize, 0 },
31411
31412 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
31413 LPCVOID))aSyscall[40].pCurrent)
31414
31415 #if !SQLITE_OS_WINRT
31416 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
31417 #else
31418 { "HeapValidate", (SYSCALL)0, 0 },
31419 #endif
31420
31421 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
31422 LPCVOID))aSyscall[41].pCurrent)
31423
31424 #if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31425 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
31426 #else
31427 { "LoadLibraryA", (SYSCALL)0, 0 },
31428 #endif
31429
31430 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
31431
31432 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
31433 !defined(SQLITE_OMIT_LOAD_EXTENSION)
31434 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
31435 #else
31436 { "LoadLibraryW", (SYSCALL)0, 0 },
31437 #endif
31438
31439 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
31440
31441 #if !SQLITE_OS_WINRT
31442 { "LocalFree", (SYSCALL)LocalFree, 0 },
31443 #else
31444 { "LocalFree", (SYSCALL)0, 0 },
31445 #endif
31446
31447 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
31448
31449 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31450 { "LockFile", (SYSCALL)LockFile, 0 },
31451 #else
31452 { "LockFile", (SYSCALL)0, 0 },
31453 #endif
31454
31455 #ifndef osLockFile
31456 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31457 DWORD))aSyscall[45].pCurrent)
31458 #endif
31459
31460 #if !SQLITE_OS_WINCE
31461 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
31462 #else
@@ -31463,218 +31480,218 @@
31463 { "LockFileEx", (SYSCALL)0, 0 },
31464 #endif
31465
31466 #ifndef osLockFileEx
31467 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
31468 LPOVERLAPPED))aSyscall[46].pCurrent)
31469 #endif
31470
31471 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
31472 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
31473 #else
31474 { "MapViewOfFile", (SYSCALL)0, 0 },
31475 #endif
31476
31477 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31478 SIZE_T))aSyscall[47].pCurrent)
31479
31480 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
31481
31482 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
31483 int))aSyscall[48].pCurrent)
31484
31485 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
31486
31487 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
31488 LARGE_INTEGER*))aSyscall[49].pCurrent)
31489
31490 { "ReadFile", (SYSCALL)ReadFile, 0 },
31491
31492 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
31493 LPOVERLAPPED))aSyscall[50].pCurrent)
31494
31495 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
31496
31497 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
31498
31499 #if !SQLITE_OS_WINRT
31500 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
31501 #else
31502 { "SetFilePointer", (SYSCALL)0, 0 },
31503 #endif
31504
31505 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
31506 DWORD))aSyscall[52].pCurrent)
31507
31508 #if !SQLITE_OS_WINRT
31509 { "Sleep", (SYSCALL)Sleep, 0 },
31510 #else
31511 { "Sleep", (SYSCALL)0, 0 },
31512 #endif
31513
31514 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
31515
31516 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
31517
31518 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
31519 LPFILETIME))aSyscall[54].pCurrent)
31520
31521 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31522 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
31523 #else
31524 { "UnlockFile", (SYSCALL)0, 0 },
31525 #endif
31526
31527 #ifndef osUnlockFile
31528 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31529 DWORD))aSyscall[55].pCurrent)
31530 #endif
31531
31532 #if !SQLITE_OS_WINCE
31533 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
31534 #else
31535 { "UnlockFileEx", (SYSCALL)0, 0 },
31536 #endif
31537
31538 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31539 LPOVERLAPPED))aSyscall[56].pCurrent)
31540
31541 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
31542 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
31543 #else
31544 { "UnmapViewOfFile", (SYSCALL)0, 0 },
31545 #endif
31546
31547 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
31548
31549 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
31550
31551 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
31552 LPCSTR,LPBOOL))aSyscall[58].pCurrent)
31553
31554 { "WriteFile", (SYSCALL)WriteFile, 0 },
31555
31556 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
31557 LPOVERLAPPED))aSyscall[59].pCurrent)
31558
31559 #if SQLITE_OS_WINRT
31560 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
31561 #else
31562 { "CreateEventExW", (SYSCALL)0, 0 },
31563 #endif
31564
31565 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
31566 DWORD,DWORD))aSyscall[60].pCurrent)
31567
31568 #if !SQLITE_OS_WINRT
31569 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
31570 #else
31571 { "WaitForSingleObject", (SYSCALL)0, 0 },
31572 #endif
31573
31574 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
31575 DWORD))aSyscall[61].pCurrent)
31576
31577 #if SQLITE_OS_WINRT
31578 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
31579 #else
31580 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
31581 #endif
31582
31583 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
31584 BOOL))aSyscall[62].pCurrent)
31585
31586 #if SQLITE_OS_WINRT
31587 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
31588 #else
31589 { "SetFilePointerEx", (SYSCALL)0, 0 },
31590 #endif
31591
31592 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
31593 PLARGE_INTEGER,DWORD))aSyscall[63].pCurrent)
31594
31595 #if SQLITE_OS_WINRT
31596 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
31597 #else
31598 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
31599 #endif
31600
31601 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
31602 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[64].pCurrent)
31603
31604 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31605 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
31606 #else
31607 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
31608 #endif
31609
31610 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
31611 SIZE_T))aSyscall[65].pCurrent)
31612
31613 #if SQLITE_OS_WINRT
31614 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
31615 #else
31616 { "CreateFile2", (SYSCALL)0, 0 },
31617 #endif
31618
31619 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
31620 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[66].pCurrent)
31621
31622 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31623 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
31624 #else
31625 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
31626 #endif
31627
31628 #define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
31629 DWORD))aSyscall[67].pCurrent)
31630
31631 #if SQLITE_OS_WINRT
31632 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
31633 #else
31634 { "GetTickCount64", (SYSCALL)0, 0 },
31635 #endif
31636
31637 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[68].pCurrent)
31638
31639 #if SQLITE_OS_WINRT
31640 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
31641 #else
31642 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
31643 #endif
31644
31645 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
31646 LPSYSTEM_INFO))aSyscall[69].pCurrent)
31647
31648 #if defined(SQLITE_WIN32_HAS_ANSI)
31649 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
31650 #else
31651 { "OutputDebugStringA", (SYSCALL)0, 0 },
31652 #endif
31653
31654 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[70].pCurrent)
31655
31656 #if defined(SQLITE_WIN32_HAS_WIDE)
31657 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
31658 #else
31659 { "OutputDebugStringW", (SYSCALL)0, 0 },
31660 #endif
31661
31662 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[71].pCurrent)
31663
31664 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
31665
31666 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[72].pCurrent)
31667
31668 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31669 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
31670 #else
31671 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
31672 #endif
31673
31674 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
31675 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[73].pCurrent)
31676
31677 }; /* End of the overrideable system calls */
31678
31679 /*
31680 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -31826,20 +31843,30 @@
31826 ** API as long as we don't call it when running Win95/98/ME. A call to
31827 ** this routine is used to determine if the host is Win95/98/ME or
31828 ** WinNT/2K/XP so that we will know whether or not we can safely call
31829 ** the LockFileEx() API.
31830 */
 
 
 
 
31831 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
31832 # define osIsNT() (1)
31833 #elif !defined(SQLITE_WIN32_HAS_WIDE)
31834 # define osIsNT() (0)
31835 #else
31836 static int osIsNT(void){
31837 if( sqlite3_os_type==0 ){
 
 
 
 
 
31838 OSVERSIONINFOA sInfo;
31839 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
31840 osGetVersionExA(&sInfo);
 
31841 sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
31842 }
31843 return sqlite3_os_type==2;
31844 }
31845 #endif
@@ -31860,11 +31887,11 @@
31860 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31861 #endif
31862 assert( nBytes>=0 );
31863 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
31864 if( !p ){
31865 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
31866 nBytes, osGetLastError(), (void*)hHeap);
31867 }
31868 return p;
31869 }
31870
@@ -31881,11 +31908,11 @@
31881 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
31882 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
31883 #endif
31884 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
31885 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
31886 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
31887 pPrior, osGetLastError(), (void*)hHeap);
31888 }
31889 }
31890
31891 /*
@@ -31907,11 +31934,11 @@
31907 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
31908 }else{
31909 p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
31910 }
31911 if( !p ){
31912 sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
31913 pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(),
31914 (void*)hHeap);
31915 }
31916 return p;
31917 }
@@ -31931,11 +31958,11 @@
31931 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31932 #endif
31933 if( !p ) return 0;
31934 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
31935 if( n==(SIZE_T)-1 ){
31936 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
31937 p, osGetLastError(), (void*)hHeap);
31938 return 0;
31939 }
31940 return (int)n;
31941 }
@@ -31961,11 +31988,11 @@
31961 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
31962 SQLITE_WIN32_HEAP_INIT_SIZE,
31963 SQLITE_WIN32_HEAP_MAX_SIZE);
31964 if( !pWinMemData->hHeap ){
31965 sqlite3_log(SQLITE_NOMEM,
31966 "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u",
31967 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
31968 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
31969 return SQLITE_NOMEM;
31970 }
31971 pWinMemData->bOwned = TRUE;
@@ -31973,11 +32000,11 @@
31973 }
31974 #else
31975 pWinMemData->hHeap = osGetProcessHeap();
31976 if( !pWinMemData->hHeap ){
31977 sqlite3_log(SQLITE_NOMEM,
31978 "failed to GetProcessHeap (%d)", osGetLastError());
31979 return SQLITE_NOMEM;
31980 }
31981 pWinMemData->bOwned = FALSE;
31982 assert( !pWinMemData->bOwned );
31983 #endif
@@ -32001,11 +32028,11 @@
32001 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32002 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32003 #endif
32004 if( pWinMemData->bOwned ){
32005 if( !osHeapDestroy(pWinMemData->hHeap) ){
32006 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
32007 osGetLastError(), (void*)pWinMemData->hHeap);
32008 }
32009 pWinMemData->bOwned = FALSE;
32010 }
32011 pWinMemData->hHeap = NULL;
@@ -33886,26 +33913,27 @@
33886 ** by VFS shared-memory methods.
33887 */
33888 static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
33889 winShmNode **pp;
33890 winShmNode *p;
33891 BOOL bRc;
33892 assert( winShmMutexHeld() );
33893 OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
33894 osGetCurrentProcessId(), deleteFlag));
33895 pp = &winShmNodeList;
33896 while( (p = *pp)!=0 ){
33897 if( p->nRef==0 ){
33898 int i;
33899 if( p->mutex ) sqlite3_mutex_free(p->mutex);
33900 for(i=0; i<p->nRegion; i++){
33901 bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
33902 OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
33903 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
 
33904 bRc = osCloseHandle(p->aRegion[i].hMap);
33905 OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
33906 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
 
33907 }
33908 if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
33909 SimulateIOErrorBenign(1);
33910 winClose((sqlite3_file *)&p->hFile);
33911 SimulateIOErrorBenign(0);
@@ -34620,10 +34648,11 @@
34620 **
34621 ** This division contains the implementation of methods on the
34622 ** sqlite3_vfs object.
34623 */
34624
 
34625 /*
34626 ** Convert a filename from whatever the underlying operating system
34627 ** supports for filenames into UTF-8. Space to hold the result is
34628 ** obtained from malloc and must be freed by the calling function.
34629 */
@@ -34638,10 +34667,11 @@
34638 }
34639 #endif
34640 /* caller will handle out of memory */
34641 return zConverted;
34642 }
 
34643
34644 /*
34645 ** Convert a UTF-8 filename into whatever form the underlying
34646 ** operating system wants filenames in. Space to hold the result
34647 ** is obtained from malloc and must be freed by the calling
@@ -35855,11 +35885,11 @@
35855 };
35856 #endif
35857
35858 /* Double-check that the aSyscall[] array has been constructed
35859 ** correctly. See ticket [bb3a86e890c8e96ab] */
35860 assert( ArraySize(aSyscall)==74 );
35861
35862 /* get memory map allocation granularity */
35863 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
35864 #if SQLITE_OS_WINRT
35865 osGetNativeSystemInfo(&winSysInfo);
@@ -60404,10 +60434,12 @@
60404 int iVal, /* Array element to populate */
60405 int *pbOk /* OUT: True if value was extracted */
60406 ){
60407 int rc = SQLITE_OK;
60408 sqlite3_value *pVal = 0;
 
 
60409
60410 struct ValueNewStat4Ctx alloc;
60411 alloc.pParse = pParse;
60412 alloc.pIdx = pIdx;
60413 alloc.ppRec = ppRec;
@@ -60415,11 +60447,11 @@
60415
60416 /* Skip over any TK_COLLATE nodes */
60417 pExpr = sqlite3ExprSkipCollate(pExpr);
60418
60419 if( !pExpr ){
60420 pVal = valueNew(pParse->db, &alloc);
60421 if( pVal ){
60422 sqlite3VdbeMemSetNull((Mem*)pVal);
60423 *pbOk = 1;
60424 }
60425 }else if( pExpr->op==TK_VARIABLE
@@ -60427,30 +60459,29 @@
60427 ){
60428 Vdbe *v;
60429 int iBindVar = pExpr->iColumn;
60430 sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
60431 if( (v = pParse->pReprepare)!=0 ){
60432 pVal = valueNew(pParse->db, &alloc);
60433 if( pVal ){
60434 rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
60435 if( rc==SQLITE_OK ){
60436 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
60437 }
60438 pVal->db = pParse->db;
60439 *pbOk = 1;
60440 sqlite3VdbeMemStoreType((Mem*)pVal);
60441 }
60442 }else{
60443 *pbOk = 0;
60444 }
60445 }else{
60446 sqlite3 *db = pParse->db;
60447 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
60448 *pbOk = (pVal!=0);
60449 }
60450
60451 assert( pVal==0 || pVal->db==pParse->db );
60452 return rc;
60453 }
60454
60455 /*
60456 ** Unless it is NULL, the argument must be an UnpackedRecord object returned
@@ -61114,11 +61145,11 @@
61114 /*
61115 ** If the input FuncDef structure is ephemeral, then free it. If
61116 ** the FuncDef is not ephermal, then do nothing.
61117 */
61118 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
61119 if( ALWAYS(pDef) && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
61120 sqlite3DbFree(db, pDef);
61121 }
61122 }
61123
61124 static void vdbeFreeOpArray(sqlite3 *, Op *, int);
@@ -64341,10 +64372,11 @@
64341 }
64342 rc = sqlite3ApiExit(db, rc);
64343 sqlite3_mutex_leave(db->mutex);
64344 return rc;
64345 }
 
64346
64347 /*
64348 ** Extract the user data from a sqlite3_context structure and return a
64349 ** pointer to it.
64350 */
@@ -64365,10 +64397,23 @@
64365 */
64366 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
64367 assert( p && p->pFunc );
64368 return p->s.db;
64369 }
 
 
 
 
 
 
 
 
 
 
 
 
 
64370
64371 /*
64372 ** The following is the implementation of an SQL function that always
64373 ** fails with an error message stating that the function is used in the
64374 ** wrong context. The sqlite3_overload_function() API might construct
@@ -66518,10 +66563,11 @@
66518 goto no_mem;
66519 }
66520 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
66521 assert( p->bIsReader || p->readOnly!=0 );
66522 p->rc = SQLITE_OK;
 
66523 assert( p->explain==0 );
66524 p->pResultSet = 0;
66525 db->busyHandler.nBusy = 0;
66526 CHECK_FOR_INTERRUPT;
66527 sqlite3VdbeIOTraceSql(p);
@@ -67406,11 +67452,11 @@
67406 */
67407 sqlite3VdbeMemMove(&u.ai.ctx.s, pOut);
67408 MemSetTypeFlag(&u.ai.ctx.s, MEM_Null);
67409
67410 u.ai.ctx.fErrorOrAux = 0;
67411 if( u.ai.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
67412 assert( pOp>aOp );
67413 assert( pOp[-1].p4type==P4_COLLSEQ );
67414 assert( pOp[-1].opcode==OP_CollSeq );
67415 u.ai.ctx.pColl = pOp[-1].p4.pColl;
67416 }
@@ -71506,11 +71552,11 @@
71506 u.cg.ctx.s.xDel = 0;
71507 u.cg.ctx.s.db = db;
71508 u.cg.ctx.isError = 0;
71509 u.cg.ctx.pColl = 0;
71510 u.cg.ctx.skipFlag = 0;
71511 if( u.cg.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
71512 assert( pOp>p->aOp );
71513 assert( pOp[-1].p4type==P4_COLLSEQ );
71514 assert( pOp[-1].opcode==OP_CollSeq );
71515 u.cg.ctx.pColl = pOp[-1].p4.pColl;
71516 }
@@ -74434,11 +74480,11 @@
74434 if( pExpr==0 ) return WRC_Continue;
74435 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
74436 testcase( ExprHasProperty(pExpr, EP_Reduced) );
74437 rc = pWalker->xExprCallback(pWalker, pExpr);
74438 if( rc==WRC_Continue
74439 && !ExprHasAnyProperty(pExpr,EP_TokenOnly) ){
74440 if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
74441 if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
74442 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
74443 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
74444 }else{
@@ -74653,10 +74699,11 @@
74653 if( pDup==0 ) return;
74654 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
74655 incrAggFunctionDepth(pDup, nSubquery);
74656 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
74657 if( pDup==0 ) return;
 
74658 if( pEList->a[iCol].iAlias==0 ){
74659 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
74660 }
74661 pDup->iTable = pEList->a[iCol].iAlias;
74662 }
@@ -74675,11 +74722,11 @@
74675 sqlite3ExprDelete(db, pExpr);
74676 memcpy(pExpr, pDup, sizeof(*pExpr));
74677 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
74678 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
74679 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
74680 pExpr->flags2 |= EP2_MallocedToken;
74681 }
74682 sqlite3DbFree(db, pDup);
74683 }
74684
74685
@@ -74775,16 +74822,16 @@
74775 Schema *pSchema = 0; /* Schema of the expression */
74776 int isTrigger = 0;
74777
74778 assert( pNC ); /* the name context cannot be NULL. */
74779 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
74780 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
74781
74782 /* Initialize the node to no-match */
74783 pExpr->iTable = -1;
74784 pExpr->pTab = 0;
74785 ExprSetIrreducible(pExpr);
74786
74787 /* Translate the schema name in zDb into a pointer to the corresponding
74788 ** schema. If not found, pSchema will remain NULL and nothing will match
74789 ** resulting in an appropriate error message toward the end of this routine
74790 */
@@ -75116,10 +75163,23 @@
75116 }
75117 #else
75118 # define notValidCheckConstraint(P,N,M)
75119 #endif
75120
 
 
 
 
 
 
 
 
 
 
 
 
 
75121
75122 /*
75123 ** This routine is callback for sqlite3WalkExpr().
75124 **
75125 ** Resolve symbolic names into TK_COLUMN operators for the current
@@ -75137,11 +75197,11 @@
75137 pNC = pWalker->u.pNC;
75138 assert( pNC!=0 );
75139 pParse = pNC->pParse;
75140 assert( pParse==pWalker->pParse );
75141
75142 if( ExprHasAnyProperty(pExpr, EP_Resolved) ) return WRC_Prune;
75143 ExprSetProperty(pExpr, EP_Resolved);
75144 #ifndef NDEBUG
75145 if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
75146 SrcList *pSrcList = pNC->pSrcList;
75147 int i;
@@ -75229,10 +75289,23 @@
75229 }else{
75230 wrong_num_args = 1;
75231 }
75232 }else{
75233 is_agg = pDef->xFunc==0;
 
 
 
 
 
 
 
 
 
 
 
 
 
75234 }
75235 #ifndef SQLITE_OMIT_AUTHORIZATION
75236 if( pDef ){
75237 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
75238 if( auth!=SQLITE_OK ){
@@ -76038,11 +76111,11 @@
76038 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr *pExpr, Token *pCollName){
76039 if( pCollName->n>0 ){
76040 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1);
76041 if( pNew ){
76042 pNew->pLeft = pExpr;
76043 pNew->flags |= EP_Collate;
76044 pExpr = pNew;
76045 }
76046 }
76047 return pExpr;
76048 }
@@ -76053,17 +76126,25 @@
76053 s.n = sqlite3Strlen30(s.z);
76054 return sqlite3ExprAddCollateToken(pParse, pExpr, &s);
76055 }
76056
76057 /*
76058 ** Skip over any TK_COLLATE and/or TK_AS operators at the root of
76059 ** an expression.
76060 */
76061 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
76062 while( pExpr && (pExpr->op==TK_COLLATE || pExpr->op==TK_AS) ){
76063 pExpr = pExpr->pLeft;
76064 }
 
 
 
 
 
 
 
 
76065 return pExpr;
76066 }
76067
76068 /*
76069 ** Return the collation sequence for the expression pExpr. If
@@ -76564,11 +76645,11 @@
76564 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
76565 sqlite3 *db = pParse->db;
76566 const char *z;
76567
76568 if( pExpr==0 ) return;
76569 assert( !ExprHasAnyProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
76570 z = pExpr->u.zToken;
76571 assert( z!=0 );
76572 assert( z[0]!=0 );
76573 if( z[1]==0 ){
76574 /* Wildcard of the form "?". Assign the next variable number */
@@ -76634,16 +76715,16 @@
76634 */
76635 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
76636 if( p==0 ) return;
76637 /* Sanity check: Assert that the IntValue is non-negative if it exists */
76638 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
76639 if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
 
 
76640 sqlite3ExprDelete(db, p->pLeft);
76641 sqlite3ExprDelete(db, p->pRight);
76642 if( !ExprHasProperty(p, EP_Reduced) && (p->flags2 & EP2_MallocedToken)!=0 ){
76643 sqlite3DbFree(db, p->u.zToken);
76644 }
76645 if( ExprHasProperty(p, EP_xIsSelect) ){
76646 sqlite3SelectDelete(db, p->x.pSelect);
76647 }else{
76648 sqlite3ExprListDelete(db, p->x.pList);
76649 }
@@ -76699,20 +76780,23 @@
76699 ** to enforce this constraint.
76700 */
76701 static int dupedExprStructSize(Expr *p, int flags){
76702 int nSize;
76703 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
 
 
76704 if( 0==(flags&EXPRDUP_REDUCE) ){
76705 nSize = EXPR_FULLSIZE;
76706 }else{
76707 assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) );
76708 assert( !ExprHasProperty(p, EP_FromJoin) );
76709 assert( (p->flags2 & EP2_MallocedToken)==0 );
76710 assert( (p->flags2 & EP2_Irreducible)==0 );
76711 if( p->pLeft || p->pRight || p->x.pList ){
76712 nSize = EXPR_REDUCEDSIZE | EP_Reduced;
76713 }else{
 
76714 nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly;
76715 }
76716 }
76717 return nSize;
76718 }
@@ -76802,11 +76886,11 @@
76802 memcpy(zAlloc, p, nSize);
76803 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
76804 }
76805
76806 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
76807 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static);
76808 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
76809 pNew->flags |= staticFlag;
76810
76811 /* Copy the p->u.zToken string, if any. */
76812 if( nToken ){
@@ -76822,22 +76906,21 @@
76822 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
76823 }
76824 }
76825
76826 /* Fill in pNew->pLeft and pNew->pRight. */
76827 if( ExprHasAnyProperty(pNew, EP_Reduced|EP_TokenOnly) ){
76828 zAlloc += dupedExprNodeSize(p, flags);
76829 if( ExprHasProperty(pNew, EP_Reduced) ){
76830 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
76831 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
76832 }
76833 if( pzBuffer ){
76834 *pzBuffer = zAlloc;
76835 }
76836 }else{
76837 pNew->flags2 = 0;
76838 if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
76839 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
76840 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
76841 }
76842 }
76843
@@ -77143,11 +77226,11 @@
77143 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
77144
77145 /* If pWalker->u.i is 3 then any term of the expression that comes from
77146 ** the ON or USING clauses of a join disqualifies the expression
77147 ** from being considered constant. */
77148 if( pWalker->u.i==3 && ExprHasAnyProperty(pExpr, EP_FromJoin) ){
77149 pWalker->u.i = 0;
77150 return WRC_Abort;
77151 }
77152
77153 switch( pExpr->op ){
@@ -77574,11 +77657,11 @@
77574 *prNotFound = rMayHaveNull = ++pParse->nMem;
77575 sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
77576 }else{
77577 testcase( pParse->nQueryLoop>0 );
77578 pParse->nQueryLoop = 0;
77579 if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
77580 eType = IN_INDEX_ROWID;
77581 }
77582 }
77583 sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
77584 pParse->nQueryLoop = savedNQueryLoop;
@@ -77643,11 +77726,11 @@
77643 ** * We are inside a trigger
77644 **
77645 ** If all of the above are false, then we can run this code just once
77646 ** save the results, and reuse the same result on subsequent invocations.
77647 */
77648 if( !ExprHasAnyProperty(pExpr, EP_VarSelect) ){
77649 testAddr = sqlite3CodeOnce(pParse);
77650 }
77651
77652 #ifndef SQLITE_OMIT_EXPLAIN
77653 if( pParse->explain==2 ){
@@ -77812,11 +77895,11 @@
77812 pSel->iLimit = 0;
77813 if( sqlite3Select(pParse, pSel, &dest) ){
77814 return 0;
77815 }
77816 rReg = dest.iSDParm;
77817 ExprSetIrreducible(pExpr);
77818 break;
77819 }
77820 }
77821
77822 if( testAddr>=0 ){
@@ -78283,10 +78366,20 @@
78283 if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
78284 }
78285 return 0;
78286 }
78287 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
 
 
 
 
 
 
 
 
 
 
78288
78289 /*
78290 ** Generate code into the current Vdbe to evaluate the given
78291 ** expression. Attempt to store the results in register "target".
78292 ** Return the register where results are stored.
@@ -78583,11 +78676,11 @@
78583 CollSeq *pColl = 0; /* A collating sequence */
78584
78585 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
78586 testcase( op==TK_CONST_FUNC );
78587 testcase( op==TK_FUNCTION );
78588 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
78589 pFarg = 0;
78590 }else{
78591 pFarg = pExpr->x.pList;
78592 }
78593 nFarg = pFarg ? pFarg->nExpr : 0;
@@ -78602,11 +78695,11 @@
78602
78603 /* Attempt a direct implementation of the built-in COALESCE() and
78604 ** IFNULL() functions. This avoids unnecessary evalation of
78605 ** arguments past the first non-NULL argument.
78606 */
78607 if( pDef->flags & SQLITE_FUNC_COALESCE ){
78608 int endCoalesce = sqlite3VdbeMakeLabel(v);
78609 assert( nFarg>=2 );
78610 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
78611 for(i=1; i<nFarg; i++){
78612 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
@@ -78617,29 +78710,38 @@
78617 }
78618 sqlite3VdbeResolveLabel(v, endCoalesce);
78619 break;
78620 }
78621
 
 
 
 
 
 
 
 
78622
78623 if( pFarg ){
78624 r1 = sqlite3GetTempRange(pParse, nFarg);
78625
78626 /* For length() and typeof() functions with a column argument,
78627 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
78628 ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
78629 ** loading.
78630 */
78631 if( (pDef->flags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
78632 u8 exprOp;
78633 assert( nFarg==1 );
78634 assert( pFarg->a[0].pExpr!=0 );
78635 exprOp = pFarg->a[0].pExpr->op;
78636 if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
78637 assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
78638 assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
78639 testcase( pDef->flags==SQLITE_FUNC_LENGTH );
78640 pFarg->a[0].pExpr->op2 = pDef->flags;
 
78641 }
78642 }
78643
78644 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
78645 sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
@@ -78668,15 +78770,15 @@
78668 #endif
78669 for(i=0; i<nFarg; i++){
78670 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
78671 constMask |= (1<<i);
78672 }
78673 if( (pDef->flags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
78674 pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
78675 }
78676 }
78677 if( pDef->flags & SQLITE_FUNC_NEEDCOLL ){
78678 if( !pColl ) pColl = db->pDfltColl;
78679 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
78680 }
78681 sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
78682 (char*)pDef, P4_FUNCDEF);
@@ -78813,13 +78915,13 @@
78813 ** Form A is can be transformed into the equivalent form B as follows:
78814 ** CASE WHEN x=e1 THEN r1 WHEN x=e2 THEN r2 ...
78815 ** WHEN x=eN THEN rN ELSE y END
78816 **
78817 ** X (if it exists) is in pExpr->pLeft.
78818 ** Y is in pExpr->pRight. The Y is also optional. If there is no
78819 ** ELSE clause and no other term matches, then the result of the
78820 ** exprssion is NULL.
78821 ** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
78822 **
78823 ** The result of the expression is the Ri for the first matching Ei,
78824 ** or if there is no matching Ei, the ELSE term Y, or if there is
78825 ** no ELSE term, NULL.
@@ -78836,33 +78938,31 @@
78836 Expr *pX; /* The X expression */
78837 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
78838 VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
78839
78840 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
78841 assert((pExpr->x.pList->nExpr % 2) == 0);
78842 assert(pExpr->x.pList->nExpr > 0);
78843 pEList = pExpr->x.pList;
78844 aListelem = pEList->a;
78845 nExpr = pEList->nExpr;
78846 endLabel = sqlite3VdbeMakeLabel(v);
78847 if( (pX = pExpr->pLeft)!=0 ){
78848 cacheX = *pX;
78849 testcase( pX->op==TK_COLUMN );
78850 testcase( pX->op==TK_REGISTER );
78851 cacheX.iTable = sqlite3ExprCodeTemp(pParse, pX, &regFree1);
78852 testcase( regFree1==0 );
78853 cacheX.op = TK_REGISTER;
78854 opCompare.op = TK_EQ;
78855 opCompare.pLeft = &cacheX;
78856 pTest = &opCompare;
78857 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
78858 ** The value in regFree1 might get SCopy-ed into the file result.
78859 ** So make sure that the regFree1 register is not reused for other
78860 ** purposes and possibly overwritten. */
78861 regFree1 = 0;
78862 }
78863 for(i=0; i<nExpr; i=i+2){
78864 sqlite3ExprCachePush(pParse);
78865 if( pX ){
78866 assert( pTest!=0 );
78867 opCompare.pRight = aListelem[i].pExpr;
78868 }else{
@@ -78876,13 +78976,13 @@
78876 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
78877 sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
78878 sqlite3ExprCachePop(pParse, 1);
78879 sqlite3VdbeResolveLabel(v, nextCase);
78880 }
78881 if( pExpr->pRight ){
78882 sqlite3ExprCachePush(pParse);
78883 sqlite3ExprCode(pParse, pExpr->pRight, target);
78884 sqlite3ExprCachePop(pParse, 1);
78885 }else{
78886 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
78887 }
78888 assert( db->mallocFailed || pParse->nErr>0
@@ -78990,13 +79090,11 @@
78990 ** modifications or enhancements. */
78991 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
78992 int iMem;
78993 iMem = ++pParse->nMem;
78994 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
78995 pExpr->iTable = iMem;
78996 pExpr->op2 = pExpr->op;
78997 pExpr->op = TK_REGISTER;
78998 }
78999 return inReg;
79000 }
79001
79002 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -79122,11 +79220,11 @@
79122
79123 case TK_AGG_FUNCTION:
79124 case TK_CONST_FUNC:
79125 case TK_FUNCTION: {
79126 ExprList *pFarg; /* List of function arguments */
79127 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
79128 pFarg = 0;
79129 }else{
79130 pFarg = pExpr->x.pList;
79131 }
79132 if( op==TK_AGG_FUNCTION ){
@@ -79371,13 +79469,11 @@
79371 int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79372 /* If r2!=r1, it means that register r1 is never used. That is harmless
79373 ** but suboptimal, so we want to know about the situation to fix it.
79374 ** Hence the following assert: */
79375 assert( r2==r1 );
79376 pExpr->op2 = pExpr->op;
79377 pExpr->op = TK_REGISTER;
79378 pExpr->iTable = r2;
79379 return WRC_Prune;
79380 }
79381 return WRC_Continue;
79382 }
79383
@@ -79471,13 +79567,11 @@
79471 compLeft.pLeft = &exprX;
79472 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
79473 compRight.op = TK_LE;
79474 compRight.pLeft = &exprX;
79475 compRight.pRight = pExpr->x.pList->a[1].pExpr;
79476 exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, &regFree1);
79477 exprX.op2 = exprX.op;
79478 exprX.op = TK_REGISTER;
79479 if( jumpIfTrue ){
79480 sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull);
79481 }else{
79482 sqlite3ExprIfFalse(pParse, &exprAnd, dest, jumpIfNull);
79483 }
@@ -79788,12 +79882,12 @@
79788 */
79789 SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
79790 if( pA==0||pB==0 ){
79791 return pB==pA ? 0 : 2;
79792 }
79793 assert( !ExprHasAnyProperty(pA, EP_TokenOnly|EP_Reduced) );
79794 assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) );
79795 if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
79796 return 2;
79797 }
79798 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
79799 if( pA->op!=pB->op && (pA->op!=TK_REGISTER || pA->op2!=pB->op) ){
@@ -80003,11 +80097,11 @@
80003 ** clause of the aggregate query */
80004 if( ALWAYS(pSrcList!=0) ){
80005 struct SrcList_item *pItem = pSrcList->a;
80006 for(i=0; i<pSrcList->nSrc; i++, pItem++){
80007 struct AggInfo_col *pCol;
80008 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
80009 if( pExpr->iTable==pItem->iCursor ){
80010 /* If we reach this point, it means that pExpr refers to a table
80011 ** that is in the FROM clause of the aggregate query.
80012 **
80013 ** Make an entry for the column in pAggInfo->aCol[] if there
@@ -80052,11 +80146,11 @@
80052 /* There is now an entry for pExpr in pAggInfo->aCol[] (either
80053 ** because it was there before or because we just created it).
80054 ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
80055 ** pAggInfo->aCol[] entry.
80056 */
80057 ExprSetIrreducible(pExpr);
80058 pExpr->pAggInfo = pAggInfo;
80059 pExpr->op = TK_AGG_COLUMN;
80060 pExpr->iAgg = (i16)k;
80061 break;
80062 } /* endif pExpr->iTable==pItem->iCursor */
@@ -80098,12 +80192,12 @@
80098 }
80099 }
80100 }
80101 /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
80102 */
80103 assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
80104 ExprSetIrreducible(pExpr);
80105 pExpr->iAgg = (i16)i;
80106 pExpr->pAggInfo = pAggInfo;
80107 return WRC_Prune;
80108 }else{
80109 return WRC_Continue;
@@ -81394,11 +81488,11 @@
81394
81395 p->iGet = -1;
81396 p->mxSample = mxSample;
81397 p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[1])/(mxSample/3+1) + 1);
81398 p->current.anLt = &p->current.anEq[nColUp];
81399 sqlite3_randomness(sizeof(p->iPrn), &p->iPrn);
81400
81401 /* Set up the Stat4Accum.a[] and aBest[] arrays */
81402 p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
81403 p->aBest = &p->a[mxSample];
81404 pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -81418,12 +81512,11 @@
81418 /* Return a pointer to the allocated object to the caller */
81419 sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
81420 }
81421 static const FuncDef statInitFuncdef = {
81422 1+IsStat34, /* nArg */
81423 SQLITE_UTF8, /* iPrefEnc */
81424 0, /* flags */
81425 0, /* pUserData */
81426 0, /* pNext */
81427 statInit, /* xFunc */
81428 0, /* xStep */
81429 0, /* xFinalize */
@@ -81715,12 +81808,11 @@
81715 }
81716 #endif
81717 }
81718 static const FuncDef statPushFuncdef = {
81719 2+IsStat34, /* nArg */
81720 SQLITE_UTF8, /* iPrefEnc */
81721 0, /* flags */
81722 0, /* pUserData */
81723 0, /* pNext */
81724 statPush, /* xFunc */
81725 0, /* xStep */
81726 0, /* xFinalize */
@@ -81851,12 +81943,11 @@
81851 }
81852 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
81853 }
81854 static const FuncDef statGetFuncdef = {
81855 1+IsStat34, /* nArg */
81856 SQLITE_UTF8, /* iPrefEnc */
81857 0, /* flags */
81858 0, /* pUserData */
81859 0, /* pNext */
81860 statGet, /* xFunc */
81861 0, /* xStep */
81862 0, /* xFinalize */
@@ -83056,12 +83147,11 @@
83056 ** DETACH pDbname
83057 */
83058 SQLITE_PRIVATE void sqlite3Detach(Parse *pParse, Expr *pDbname){
83059 static const FuncDef detach_func = {
83060 1, /* nArg */
83061 SQLITE_UTF8, /* iPrefEnc */
83062 0, /* flags */
83063 0, /* pUserData */
83064 0, /* pNext */
83065 detachFunc, /* xFunc */
83066 0, /* xStep */
83067 0, /* xFinalize */
@@ -83078,12 +83168,11 @@
83078 ** ATTACH p AS pDbname KEY pKey
83079 */
83080 SQLITE_PRIVATE void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
83081 static const FuncDef attach_func = {
83082 3, /* nArg */
83083 SQLITE_UTF8, /* iPrefEnc */
83084 0, /* flags */
83085 0, /* pUserData */
83086 0, /* pNext */
83087 attachFunc, /* xFunc */
83088 0, /* xStep */
83089 0, /* xFinalize */
@@ -83188,11 +83277,11 @@
83188 SQLITE_PRIVATE int sqlite3FixExpr(
83189 DbFixer *pFix, /* Context of the fixation */
83190 Expr *pExpr /* The expression to be fixed to one database */
83191 ){
83192 while( pExpr ){
83193 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ) break;
83194 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
83195 if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1;
83196 }else{
83197 if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1;
83198 }
@@ -87589,13 +87678,13 @@
87589 }else{
87590 match = 1;
87591 }
87592
87593 /* Bonus points if the text encoding matches */
87594 if( enc==p->iPrefEnc ){
87595 match += 2; /* Exact encoding match */
87596 }else if( (enc & p->iPrefEnc & 2)!=0 ){
87597 match += 1; /* Both are UTF16, but with different byte orders */
87598 }
87599
87600 return match;
87601 }
@@ -87725,11 +87814,11 @@
87725 */
87726 if( createFlag && bestScore<FUNC_PERFECT_MATCH &&
87727 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
87728 pBest->zName = (char *)&pBest[1];
87729 pBest->nArg = (u16)nArg;
87730 pBest->iPrefEnc = enc;
87731 memcpy(pBest->zName, zName, nName);
87732 pBest->zName[nName] = 0;
87733 sqlite3FuncDefInsert(&db->aFunc, pBest);
87734 }
87735
@@ -88335,11 +88424,11 @@
88335 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
88336
88337 /* Do FK processing. This call checks that any FK constraints that
88338 ** refer to this table (i.e. constraints attached to other tables)
88339 ** are not violated by deleting this row. */
88340 sqlite3FkCheck(pParse, pTab, iOld, 0);
88341 }
88342
88343 /* Delete the index and table entries. Skip this step if pTab is really
88344 ** a view (in which case the only effect of the DELETE statement is to
88345 ** fire the INSTEAD OF triggers). */
@@ -88352,11 +88441,11 @@
88352 }
88353
88354 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
88355 ** handle rows (possibly in other tables) that refer via a foreign key
88356 ** to the row just deleted. */
88357 sqlite3FkActions(pParse, pTab, 0, iOld);
88358
88359 /* Invoke AFTER DELETE trigger programs. */
88360 sqlite3CodeRowTrigger(pParse, pTrigger,
88361 TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
88362 );
@@ -88891,18 +88980,18 @@
88891 }
88892 }
88893 }
88894
88895 /*
88896 ** The COALESCE() and IFNULL() functions are implemented as VDBE code so
88897 ** that unused argument values do not have to be computed. However, we
88898 ** still need some kind of function implementation for this routines in
88899 ** the function table. That function implementation will never be called
88900 ** so it doesn't matter what the implementation is. We might as well use
88901 ** the "version()" function as a substitute.
88902 */
88903 #define ifnullFunc versionFunc /* Substitute function - never called */
88904
88905 /*
88906 ** Implementation of random(). Return a random integer.
88907 */
88908 static void randomFunc(
@@ -89017,13 +89106,13 @@
89017 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
89018 ** whereas only characters less than 0x80 do in ASCII.
89019 */
89020 #if defined(SQLITE_EBCDIC)
89021 # define sqlite3Utf8Read(A) (*((*A)++))
89022 # define GlogUpperToLower(A) A = sqlite3UpperToLower[A]
89023 #else
89024 # define GlogUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
89025 #endif
89026
89027 static const struct compareInfo globInfo = { '*', '?', '[', 0 };
89028 /* The correct SQL-92 behavior is for the LIKE operator to ignore
89029 ** case. Thus 'a' LIKE 'A' would be true. */
@@ -89098,15 +89187,15 @@
89098 }
89099 return *zString!=0;
89100 }
89101 while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
89102 if( noCase ){
89103 GlogUpperToLower(c2);
89104 GlogUpperToLower(c);
89105 while( c2 != 0 && c2 != c ){
89106 c2 = sqlite3Utf8Read(&zString);
89107 GlogUpperToLower(c2);
89108 }
89109 }else{
89110 while( c2 != 0 && c2 != c ){
89111 c2 = sqlite3Utf8Read(&zString);
89112 }
@@ -89154,12 +89243,12 @@
89154 }else if( esc==c && !prevEscape ){
89155 prevEscape = 1;
89156 }else{
89157 c2 = sqlite3Utf8Read(&zString);
89158 if( noCase ){
89159 GlogUpperToLower(c);
89160 GlogUpperToLower(c2);
89161 }
89162 if( c!=c2 ){
89163 return 0;
89164 }
89165 prevEscape = 0;
@@ -90027,11 +90116,11 @@
90027 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
90028 FuncDef *pDef;
90029 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
90030 2, SQLITE_UTF8, 0);
90031 if( ALWAYS(pDef) ){
90032 pDef->flags = flagVal;
90033 }
90034 }
90035
90036 /*
90037 ** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -90071,11 +90160,11 @@
90071 }
90072 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
90073 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
90074 sqlite3Strlen30(pExpr->u.zToken),
90075 2, SQLITE_UTF8, 0);
90076 if( NEVER(pDef==0) || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
90077 return 0;
90078 }
90079
90080 /* The memcpy() statement assumes that the wildcard characters are
90081 ** the first three statements in the compareInfo structure. The
@@ -90083,11 +90172,11 @@
90083 */
90084 memcpy(aWc, pDef->pUserData, 3);
90085 assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
90086 assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
90087 assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
90088 *pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
90089 return 1;
90090 }
90091
90092 /*
90093 ** All all of the FuncDef structures in the aBuiltinFunc[] array above
@@ -90132,13 +90221,15 @@
90132 #endif
90133 FUNCTION(upper, 1, 0, 0, upperFunc ),
90134 FUNCTION(lower, 1, 0, 0, lowerFunc ),
90135 FUNCTION(coalesce, 1, 0, 0, 0 ),
90136 FUNCTION(coalesce, 0, 0, 0, 0 ),
90137 FUNCTION2(coalesce, -1, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE),
90138 FUNCTION(hex, 1, 0, 0, hexFunc ),
90139 FUNCTION2(ifnull, 2, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE),
 
 
90140 FUNCTION(random, 0, 0, 0, randomFunc ),
90141 FUNCTION(randomblob, 1, 0, 0, randomBlob ),
90142 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
90143 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
90144 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -90162,11 +90253,11 @@
90162 #endif
90163 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
90164 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
90165 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
90166 /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
90167 {0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
90168 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
90169 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
90170 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
90171
90172 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -90878,10 +90969,74 @@
90878 sqlite3VdbeResolveLabel(v, iSkip);
90879 }
90880 }
90881 }
90882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90883 /*
90884 ** This function is called when inserting, deleting or updating a row of
90885 ** table pTab to generate VDBE code to perform foreign key constraint
90886 ** processing for the operation.
90887 **
@@ -90902,11 +91057,13 @@
90902 */
90903 SQLITE_PRIVATE void sqlite3FkCheck(
90904 Parse *pParse, /* Parse context */
90905 Table *pTab, /* Row is being deleted from this table */
90906 int regOld, /* Previous row data is stored here */
90907 int regNew /* New row data is stored here */
 
 
90908 ){
90909 sqlite3 *db = pParse->db; /* Database handle */
90910 FKey *pFKey; /* Used to iterate through FKs */
90911 int iDb; /* Index of database containing pTab */
90912 const char *zDb; /* Name of database containing pTab */
@@ -90929,10 +91086,17 @@
90929 int *aiFree = 0;
90930 int *aiCol;
90931 int iCol;
90932 int i;
90933 int isIgnore = 0;
 
 
 
 
 
 
 
90934
90935 /* Find the parent table of this foreign key. Also find a unique index
90936 ** on the parent key columns in the parent table. If either of these
90937 ** schema items cannot be located, set an error in pParse and return
90938 ** early. */
@@ -91011,10 +91175,14 @@
91011 /* Loop through all the foreign key constraints that refer to this table */
91012 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
91013 Index *pIdx = 0; /* Foreign key index for pFKey */
91014 SrcList *pSrc;
91015 int *aiCol = 0;
 
 
 
 
91016
91017 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
91018 && !pParse->pToplevel && !pParse->isMultiWrite
91019 ){
91020 assert( regOld==0 && regNew!=0 );
@@ -91084,10 +91252,11 @@
91084 }
91085 }
91086 }
91087 return mask;
91088 }
 
91089
91090 /*
91091 ** This function is called before generating code to update or delete a
91092 ** row contained in table pTab. If the operation is a DELETE, then
91093 ** parameter aChange is passed a NULL value. For an UPDATE, aChange points
@@ -91114,36 +91283,20 @@
91114 ** foreign key constraint. */
91115 return (sqlite3FkReferences(pTab) || pTab->pFKey);
91116 }else{
91117 /* This is an UPDATE. Foreign key processing is only required if the
91118 ** operation modifies one or more child or parent key columns. */
91119 int i;
91120 FKey *p;
91121
91122 /* Check if any child key columns are being modified. */
91123 for(p=pTab->pFKey; p; p=p->pNextFrom){
91124 for(i=0; i<p->nCol; i++){
91125 int iChildKey = p->aCol[i].iFrom;
91126 if( aChange[iChildKey]>=0 ) return 1;
91127 if( iChildKey==pTab->iPKey && chngRowid ) return 1;
91128 }
91129 }
91130
91131 /* Check if any parent key columns are being modified. */
91132 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
91133 for(i=0; i<p->nCol; i++){
91134 char *zKey = p->aCol[i].zCol;
91135 int iKey;
91136 for(iKey=0; iKey<pTab->nCol; iKey++){
91137 Column *pCol = &pTab->aCol[iKey];
91138 if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey)
91139 : (pCol->colFlags & COLFLAG_PRIMKEY)!=0) ){
91140 if( aChange[iKey]>=0 ) return 1;
91141 if( iKey==pTab->iPKey && chngRowid ) return 1;
91142 }
91143 }
91144 }
91145 }
91146 }
91147 }
91148 return 0;
91149 }
@@ -91365,22 +91518,26 @@
91365 */
91366 SQLITE_PRIVATE void sqlite3FkActions(
91367 Parse *pParse, /* Parse context */
91368 Table *pTab, /* Table being updated or deleted from */
91369 ExprList *pChanges, /* Change-list for UPDATE, NULL for DELETE */
91370 int regOld /* Address of array containing old row */
 
 
91371 ){
91372 /* If foreign-key support is enabled, iterate through all FKs that
91373 ** refer to table pTab. If there is an action associated with the FK
91374 ** for this operation (either update or delete), invoke the associated
91375 ** trigger sub-program. */
91376 if( pParse->db->flags&SQLITE_ForeignKeys ){
91377 FKey *pFKey; /* Iterator variable */
91378 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
91379 Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
91380 if( pAction ){
91381 sqlite3CodeRowTriggerDirect(pParse, pAction, pTab, regOld, OE_Abort, 0);
 
 
91382 }
91383 }
91384 }
91385 }
91386
@@ -92461,11 +92618,11 @@
92461 {
92462 int isReplace; /* Set to true if constraints may cause a replace */
92463 sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
92464 keyColumn>=0, 0, onError, endOfLoop, &isReplace
92465 );
92466 sqlite3FkCheck(pParse, pTab, 0, regIns);
92467 sqlite3CompleteInsertion(
92468 pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
92469 );
92470 }
92471 }
@@ -94762,10 +94919,239 @@
94762 **
94763 *************************************************************************
94764 ** This file contains code used to implement the PRAGMA command.
94765 */
94766
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94767 /*
94768 ** Interpret the given string as a safety level. Return 0 for OFF,
94769 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
94770 ** unrecognized string argument. The FULL option is disallowed
94771 ** if the omitFull parameter it 1.
@@ -94937,101 +95323,10 @@
94937 #else
94938 # define setAllPagerFlags(X) /* no-op */
94939 #endif
94940
94941
94942 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
94943 /*
94944 ** Check to see if zRight and zLeft refer to a pragma that queries
94945 ** or changes one of the flags in db->flags. Return 1 if so and 0 if not.
94946 ** Also, implement the pragma.
94947 */
94948 static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
94949 static const struct sPragmaType {
94950 const char *zName; /* Name of the pragma */
94951 int mask; /* Mask for the db->flags value */
94952 } aPragma[] = {
94953 { "full_column_names", SQLITE_FullColNames },
94954 { "short_column_names", SQLITE_ShortColNames },
94955 { "count_changes", SQLITE_CountRows },
94956 { "empty_result_callbacks", SQLITE_NullCallback },
94957 { "legacy_file_format", SQLITE_LegacyFileFmt },
94958 { "fullfsync", SQLITE_FullFSync },
94959 { "checkpoint_fullfsync", SQLITE_CkptFullFSync },
94960 { "cache_spill", SQLITE_CacheSpill },
94961 { "reverse_unordered_selects", SQLITE_ReverseOrder },
94962 { "query_only", SQLITE_QueryOnly },
94963 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
94964 { "automatic_index", SQLITE_AutoIndex },
94965 #endif
94966 #ifdef SQLITE_DEBUG
94967 { "sql_trace", SQLITE_SqlTrace },
94968 { "vdbe_listing", SQLITE_VdbeListing },
94969 { "vdbe_trace", SQLITE_VdbeTrace },
94970 { "vdbe_addoptrace", SQLITE_VdbeAddopTrace},
94971 { "vdbe_debug", SQLITE_SqlTrace | SQLITE_VdbeListing
94972 | SQLITE_VdbeTrace },
94973 #endif
94974 #ifndef SQLITE_OMIT_CHECK
94975 { "ignore_check_constraints", SQLITE_IgnoreChecks },
94976 #endif
94977 /* The following is VERY experimental */
94978 { "writable_schema", SQLITE_WriteSchema|SQLITE_RecoveryMode },
94979
94980 /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
94981 ** flag if there are any active statements. */
94982 { "read_uncommitted", SQLITE_ReadUncommitted },
94983 { "recursive_triggers", SQLITE_RecTriggers },
94984
94985 /* This flag may only be set if both foreign-key and trigger support
94986 ** are present in the build. */
94987 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
94988 { "foreign_keys", SQLITE_ForeignKeys },
94989 { "defer_foreign_keys", SQLITE_DeferFKs },
94990 #endif
94991 };
94992 int i;
94993 const struct sPragmaType *p;
94994 for(i=0, p=aPragma; i<ArraySize(aPragma); i++, p++){
94995 if( sqlite3StrICmp(zLeft, p->zName)==0 ){
94996 sqlite3 *db = pParse->db;
94997 Vdbe *v;
94998 v = sqlite3GetVdbe(pParse);
94999 assert( v!=0 ); /* Already allocated by sqlite3Pragma() */
95000 if( ALWAYS(v) ){
95001 if( zRight==0 ){
95002 returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
95003 }else{
95004 int mask = p->mask; /* Mask of bits to set or clear. */
95005 if( db->autoCommit==0 ){
95006 /* Foreign key support may not be enabled or disabled while not
95007 ** in auto-commit mode. */
95008 mask &= ~(SQLITE_ForeignKeys);
95009 }
95010
95011 if( sqlite3GetBoolean(zRight, 0) ){
95012 db->flags |= mask;
95013 }else{
95014 db->flags &= ~mask;
95015 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
95016 }
95017
95018 /* Many of the flag-pragmas modify the code generated by the SQL
95019 ** compiler (eg. count_changes). So add an opcode to expire all
95020 ** compiled SQL statements after modifying a pragma value.
95021 */
95022 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
95023 }
95024 }
95025
95026 return 1;
95027 }
95028 }
95029 return 0;
95030 }
95031 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
95032
95033 /*
95034 ** Return a human-readable name for a constraint resolution action.
95035 */
95036 #ifndef SQLITE_OMIT_FOREIGN_KEY
95037 static const char *actionName(u8 action){
@@ -95097,12 +95392,13 @@
95097 ){
95098 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
95099 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
95100 const char *zDb = 0; /* The database name */
95101 Token *pId; /* Pointer to <id> token */
95102 int iDb; /* Database index for <database> */
95103 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
 
 
95104 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
95105 sqlite3 *db = pParse->db; /* The database connection */
95106 Db *pDb; /* The specific database being pragmaed */
95107 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
95108
@@ -95154,20 +95450,40 @@
95154 sqlite3VdbeSetNumCols(v, 1);
95155 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
95156 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
95157 sqlite3_free(aFcntl[0]);
95158 }
95159 }else if( rc!=SQLITE_NOTFOUND ){
 
 
95160 if( aFcntl[0] ){
95161 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
95162 sqlite3_free(aFcntl[0]);
95163 }
95164 pParse->nErr++;
95165 pParse->rc = rc;
95166 }else
95167
95168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95169 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
95170 /*
95171 ** PRAGMA [database.]default_cache_size
95172 ** PRAGMA [database.]default_cache_size=N
95173 **
@@ -95181,11 +95497,11 @@
95181 ** negative number to indicate synchronous=OFF. These days, synchronous
95182 ** is always on by default regardless of the sign of the default cache
95183 ** size. But continue to take the absolute value of the default cache
95184 ** size of historical compatibility.
95185 */
95186 if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
95187 static const VdbeOpList getCacheSize[] = {
95188 { OP_Transaction, 0, 0, 0}, /* 0 */
95189 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
95190 { OP_IfPos, 1, 8, 0},
95191 { OP_Integer, 0, 2, 0},
@@ -95213,11 +95529,12 @@
95213 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
95214 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95215 pDb->pSchema->cache_size = size;
95216 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
95217 }
95218 }else
 
95219 #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
95220
95221 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95222 /*
95223 ** PRAGMA [database.]page_size
@@ -95226,11 +95543,11 @@
95226 ** The first form reports the current setting for the
95227 ** database page size in bytes. The second form sets the
95228 ** database page size value. The value can only be set if
95229 ** the database has not yet been created.
95230 */
95231 if( sqlite3StrICmp(zLeft,"page_size")==0 ){
95232 Btree *pBt = pDb->pBt;
95233 assert( pBt!=0 );
95234 if( !zRight ){
95235 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
95236 returnSingleInt(pParse, "page_size", size);
@@ -95241,21 +95558,22 @@
95241 db->nextPagesize = sqlite3Atoi(zRight);
95242 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
95243 db->mallocFailed = 1;
95244 }
95245 }
95246 }else
 
95247
95248 /*
95249 ** PRAGMA [database.]secure_delete
95250 ** PRAGMA [database.]secure_delete=ON/OFF
95251 **
95252 ** The first form reports the current setting for the
95253 ** secure_delete flag. The second form changes the secure_delete
95254 ** flag setting and reports thenew value.
95255 */
95256 if( sqlite3StrICmp(zLeft,"secure_delete")==0 ){
95257 Btree *pBt = pDb->pBt;
95258 int b = -1;
95259 assert( pBt!=0 );
95260 if( zRight ){
95261 b = sqlite3GetBoolean(zRight, 0);
@@ -95266,11 +95584,12 @@
95266 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
95267 }
95268 }
95269 b = sqlite3BtreeSecureDelete(pBt, b);
95270 returnSingleInt(pParse, "secure_delete", b);
95271 }else
 
95272
95273 /*
95274 ** PRAGMA [database.]max_page_count
95275 ** PRAGMA [database.]max_page_count=N
95276 **
@@ -95285,13 +95604,11 @@
95285 **
95286 ** PRAGMA [database.]page_count
95287 **
95288 ** Return the number of pages in the specified database.
95289 */
95290 if( sqlite3StrICmp(zLeft,"page_count")==0
95291 || sqlite3StrICmp(zLeft,"max_page_count")==0
95292 ){
95293 int iReg;
95294 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95295 sqlite3CodeVerifySchema(pParse, iDb);
95296 iReg = ++pParse->nMem;
95297 if( sqlite3Tolower(zLeft[0])=='p' ){
@@ -95301,17 +95618,18 @@
95301 sqlite3AbsInt32(sqlite3Atoi(zRight)));
95302 }
95303 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
95304 sqlite3VdbeSetNumCols(v, 1);
95305 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
95306 }else
 
95307
95308 /*
95309 ** PRAGMA [database.]locking_mode
95310 ** PRAGMA [database.]locking_mode = (normal|exclusive)
95311 */
95312 if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
95313 const char *zRet = "normal";
95314 int eMode = getLockingMode(zRight);
95315
95316 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
95317 /* Simple "PRAGMA locking_mode;" statement. This is a query for
@@ -95340,26 +95658,28 @@
95340 }
95341 pPager = sqlite3BtreePager(pDb->pBt);
95342 eMode = sqlite3PagerLockingMode(pPager, eMode);
95343 }
95344
95345 assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
 
95346 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
95347 zRet = "exclusive";
95348 }
95349 sqlite3VdbeSetNumCols(v, 1);
95350 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
95351 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
95352 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
95353 }else
 
95354
95355 /*
95356 ** PRAGMA [database.]journal_mode
95357 ** PRAGMA [database.]journal_mode =
95358 ** (delete|persist|off|truncate|memory|wal|off)
95359 */
95360 if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
95361 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
95362 int ii; /* Loop counter */
95363
95364 /* Force the schema to be loaded on all databases. This causes all
95365 ** database files to be opened and the journal_modes set. This is
@@ -95398,28 +95718,30 @@
95398 sqlite3VdbeUsesBtree(v, ii);
95399 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
95400 }
95401 }
95402 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
95403 }else
 
95404
95405 /*
95406 ** PRAGMA [database.]journal_size_limit
95407 ** PRAGMA [database.]journal_size_limit=N
95408 **
95409 ** Get or set the size limit on rollback journal files.
95410 */
95411 if( sqlite3StrICmp(zLeft,"journal_size_limit")==0 ){
95412 Pager *pPager = sqlite3BtreePager(pDb->pBt);
95413 i64 iLimit = -2;
95414 if( zRight ){
95415 sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8);
95416 if( iLimit<-1 ) iLimit = -1;
95417 }
95418 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
95419 returnSingleInt(pParse, "journal_size_limit", iLimit);
95420 }else
 
95421
95422 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
95423
95424 /*
95425 ** PRAGMA [database.]auto_vacuum
@@ -95427,11 +95749,11 @@
95427 **
95428 ** Get or set the value of the database 'auto-vacuum' parameter.
95429 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
95430 */
95431 #ifndef SQLITE_OMIT_AUTOVACUUM
95432 if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
95433 Btree *pBt = pDb->pBt;
95434 assert( pBt!=0 );
95435 if( sqlite3ReadSchema(pParse) ){
95436 goto pragma_out;
95437 }
@@ -95477,20 +95799,21 @@
95477 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
95478 sqlite3VdbeUsesBtree(v, iDb);
95479 }
95480 }
95481 }
95482 }else
 
95483 #endif
95484
95485 /*
95486 ** PRAGMA [database.]incremental_vacuum(N)
95487 **
95488 ** Do N steps of incremental vacuuming on a database.
95489 */
95490 #ifndef SQLITE_OMIT_AUTOVACUUM
95491 if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
95492 int iLimit, addr;
95493 if( sqlite3ReadSchema(pParse) ){
95494 goto pragma_out;
95495 }
95496 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
@@ -95501,11 +95824,12 @@
95501 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
95502 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
95503 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
95504 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
95505 sqlite3VdbeJumpHere(v, addr);
95506 }else
 
95507 #endif
95508
95509 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
95510 /*
95511 ** PRAGMA [database.]cache_size
@@ -95516,21 +95840,22 @@
95516 ** page cache size value. If N is positive then that is the
95517 ** number of pages in the cache. If N is negative, then the
95518 ** number of pages is adjusted so that the cache uses -N kibibytes
95519 ** of memory.
95520 */
95521 if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
95522 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95523 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95524 if( !zRight ){
95525 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
95526 }else{
95527 int size = sqlite3Atoi(zRight);
95528 pDb->pSchema->cache_size = size;
95529 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
95530 }
95531 }else
 
95532
95533 /*
95534 ** PRAGMA [database.]mmap_size(N)
95535 **
95536 ** Used to set mapping size limit. The mapping size limit is
@@ -95542,11 +95867,11 @@
95542 **
95543 ** This value is advisory. The underlying VFS is free to memory map
95544 ** as little or as much as it wants. Except, if N is set to 0 then the
95545 ** upper layers will never invoke the xFetch interfaces to the VFS.
95546 */
95547 if( sqlite3StrICmp(zLeft,"mmap_size")==0 ){
95548 sqlite3_int64 sz;
95549 #if SQLITE_MAX_MMAP_SIZE>0
95550 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95551 if( zRight ){
95552 int ii;
@@ -95569,11 +95894,12 @@
95569 returnSingleInt(pParse, "mmap_size", sz);
95570 }else if( rc!=SQLITE_NOTFOUND ){
95571 pParse->nErr++;
95572 pParse->rc = rc;
95573 }
95574 }else
 
95575
95576 /*
95577 ** PRAGMA temp_store
95578 ** PRAGMA temp_store = "default"|"memory"|"file"
95579 **
@@ -95582,17 +95908,18 @@
95582 ** value will be restored the next time the database is opened.
95583 **
95584 ** Note that it is possible for the library compile-time options to
95585 ** override this setting
95586 */
95587 if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
95588 if( !zRight ){
95589 returnSingleInt(pParse, "temp_store", db->temp_store);
95590 }else{
95591 changeTempStorage(pParse, zRight);
95592 }
95593 }else
 
95594
95595 /*
95596 ** PRAGMA temp_store_directory
95597 ** PRAGMA temp_store_directory = ""|"directory_name"
95598 **
@@ -95600,11 +95927,11 @@
95600 ** the value sets a specific directory to be used for temporary files.
95601 ** Setting to a null string reverts to the default temporary directory search.
95602 ** If temporary directory is changed, then invalidateTempStorage.
95603 **
95604 */
95605 if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
95606 if( !zRight ){
95607 if( sqlite3_temp_directory ){
95608 sqlite3VdbeSetNumCols(v, 1);
95609 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
95610 "temp_store_directory", SQLITE_STATIC);
@@ -95633,11 +95960,12 @@
95633 }else{
95634 sqlite3_temp_directory = 0;
95635 }
95636 #endif /* SQLITE_OMIT_WSD */
95637 }
95638 }else
 
95639
95640 #if SQLITE_OS_WIN
95641 /*
95642 ** PRAGMA data_store_directory
95643 ** PRAGMA data_store_directory = ""|"directory_name"
@@ -95649,11 +95977,11 @@
95649 ** a relative path will probably be based on the current directory for the
95650 ** process. Database file specified with an absolute path are not impacted
95651 ** by this setting, regardless of its value.
95652 **
95653 */
95654 if( sqlite3StrICmp(zLeft, "data_store_directory")==0 ){
95655 if( !zRight ){
95656 if( sqlite3_data_directory ){
95657 sqlite3VdbeSetNumCols(v, 1);
95658 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
95659 "data_store_directory", SQLITE_STATIC);
@@ -95676,30 +96004,24 @@
95676 }else{
95677 sqlite3_data_directory = 0;
95678 }
95679 #endif /* SQLITE_OMIT_WSD */
95680 }
95681 }else
 
95682 #endif
95683
95684 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
95685 # if defined(__APPLE__)
95686 # define SQLITE_ENABLE_LOCKING_STYLE 1
95687 # else
95688 # define SQLITE_ENABLE_LOCKING_STYLE 0
95689 # endif
95690 #endif
95691 #if SQLITE_ENABLE_LOCKING_STYLE
95692 /*
95693 ** PRAGMA [database.]lock_proxy_file
95694 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
95695 **
95696 ** Return or set the value of the lock_proxy_file flag. Changing
95697 ** the value sets a specific file to be used for database access locks.
95698 **
95699 */
95700 if( sqlite3StrICmp(zLeft, "lock_proxy_file")==0 ){
95701 if( !zRight ){
95702 Pager *pPager = sqlite3BtreePager(pDb->pBt);
95703 char *proxy_file_path = NULL;
95704 sqlite3_file *pFile = sqlite3PagerFile(pPager);
95705 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
@@ -95726,11 +96048,12 @@
95726 if( res!=SQLITE_OK ){
95727 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
95728 goto pragma_out;
95729 }
95730 }
95731 }else
 
95732 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
95733
95734 /*
95735 ** PRAGMA [database.]synchronous
95736 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
@@ -95738,11 +96061,11 @@
95738 ** Return or set the local value of the synchronous flag. Changing
95739 ** the local value does not make changes to the disk file and the
95740 ** default value will be restored the next time the database is
95741 ** opened.
95742 */
95743 if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
95744 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95745 if( !zRight ){
95746 returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
95747 }else{
95748 if( !db->autoCommit ){
@@ -95751,17 +96074,43 @@
95751 }else{
95752 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
95753 setAllPagerFlags(db);
95754 }
95755 }
95756 }else
 
95757 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
95758
95759 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
95760 if( flagPragma(pParse, zLeft, zRight) ){
95761 setAllPagerFlags(db);
95762 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95763 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
95764
95765 #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
95766 /*
95767 ** PRAGMA table_info(<table>)
@@ -95773,11 +96122,11 @@
95773 ** name: Column name
95774 ** type: Column declaration type.
95775 ** notnull: True if 'NOT NULL' is part of column declaration
95776 ** dflt_value: The default value for the column, if any.
95777 */
95778 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
95779 Table *pTab;
95780 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95781 pTab = sqlite3FindTable(db, zRight, zDb);
95782 if( pTab ){
95783 int i, k;
@@ -95819,13 +96168,14 @@
95819 }
95820 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
95821 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
95822 }
95823 }
95824 }else
 
95825
95826 if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
95827 Index *pIdx;
95828 Table *pTab;
95829 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95830 pIdx = sqlite3FindIndex(db, zRight, zDb);
95831 if( pIdx ){
@@ -95844,13 +96194,14 @@
95844 assert( pTab->nCol>cnum );
95845 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
95846 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
95847 }
95848 }
95849 }else
 
95850
95851 if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
95852 Index *pIdx;
95853 Table *pTab;
95854 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95855 pTab = sqlite3FindTable(db, zRight, zDb);
95856 if( pTab ){
@@ -95872,13 +96223,14 @@
95872 ++i;
95873 pIdx = pIdx->pNext;
95874 }
95875 }
95876 }
95877 }else
 
95878
95879 if( sqlite3StrICmp(zLeft, "database_list")==0 ){
95880 int i;
95881 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95882 sqlite3VdbeSetNumCols(v, 3);
95883 pParse->nMem = 3;
95884 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
@@ -95891,13 +96243,14 @@
95891 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
95892 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
95893 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
95894 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
95895 }
95896 }else
 
95897
95898 if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
95899 int i = 0;
95900 HashElem *p;
95901 sqlite3VdbeSetNumCols(v, 2);
95902 pParse->nMem = 2;
95903 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
@@ -95906,15 +96259,16 @@
95906 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
95907 sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
95908 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
95909 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
95910 }
95911 }else
 
95912 #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
95913
95914 #ifndef SQLITE_OMIT_FOREIGN_KEY
95915 if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
95916 FKey *pFK;
95917 Table *pTab;
95918 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95919 pTab = sqlite3FindTable(db, zRight, zDb);
95920 if( pTab ){
@@ -95953,16 +96307,17 @@
95953 ++i;
95954 pFK = pFK->pNextFrom;
95955 }
95956 }
95957 }
95958 }else
 
95959 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
95960
95961 #ifndef SQLITE_OMIT_FOREIGN_KEY
95962 #ifndef SQLITE_OMIT_TRIGGER
95963 if( sqlite3StrICmp(zLeft, "foreign_key_check")==0 ){
95964 FKey *pFK; /* A foreign key constraint */
95965 Table *pTab; /* Child table contain "REFERENCES" keyword */
95966 Table *pParent; /* Parent table that child points to */
95967 Index *pIdx; /* Index in the parent table */
95968 int i; /* Loop counter: Foreign key number for pTab */
@@ -96068,34 +96423,37 @@
96068 sqlite3DbFree(db, aiCols);
96069 }
96070 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
96071 sqlite3VdbeJumpHere(v, addrTop);
96072 }
96073 }else
 
96074 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
96075 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
96076
96077 #ifndef NDEBUG
96078 if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
96079 if( zRight ){
96080 if( sqlite3GetBoolean(zRight, 0) ){
96081 sqlite3ParserTrace(stderr, "parser: ");
96082 }else{
96083 sqlite3ParserTrace(0, 0);
96084 }
96085 }
96086 }else
 
96087 #endif
96088
96089 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
96090 ** used will be case sensitive or not depending on the RHS.
96091 */
96092 if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
96093 if( zRight ){
96094 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
96095 }
96096 }else
 
96097
96098 #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
96099 # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
96100 #endif
96101
@@ -96102,13 +96460,11 @@
96102 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
96103 /* Pragma "quick_check" is reduced version of
96104 ** integrity_check designed to detect most database corruption
96105 ** without most of the overhead of a full integrity-check.
96106 */
96107 if( sqlite3StrICmp(zLeft, "integrity_check")==0
96108 || sqlite3StrICmp(zLeft, "quick_check")==0
96109 ){
96110 int i, j, addr, mxErr;
96111
96112 /* Code that appears at the end of the integrity check. If no error
96113 ** messages have been generated, output OK. Otherwise output the
96114 ** error message
@@ -96264,11 +96620,12 @@
96264 }
96265 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
96266 sqlite3VdbeChangeP2(v, addr, -mxErr);
96267 sqlite3VdbeJumpHere(v, addr+1);
96268 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
96269 }else
 
96270 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
96271
96272 #ifndef SQLITE_OMIT_UTF16
96273 /*
96274 ** PRAGMA encoding
@@ -96290,11 +96647,11 @@
96290 **
96291 ** In the second form this pragma sets the text encoding to be used in
96292 ** new database files created using this database handle. It is only
96293 ** useful if invoked immediately after the main database i
96294 */
96295 if( sqlite3StrICmp(zLeft, "encoding")==0 ){
96296 static const struct EncName {
96297 char *zName;
96298 u8 enc;
96299 } encnames[] = {
96300 { "UTF8", SQLITE_UTF8 },
@@ -96337,11 +96694,12 @@
96337 if( !pEnc->zName ){
96338 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
96339 }
96340 }
96341 }
96342 }else
 
96343 #endif /* SQLITE_OMIT_UTF16 */
96344
96345 #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
96346 /*
96347 ** PRAGMA [database.]schema_version
@@ -96371,15 +96729,11 @@
96371 ** crashes or database corruption. Use with caution!
96372 **
96373 ** The user-version is not used internally by SQLite. It may be used by
96374 ** applications for any purpose.
96375 */
96376 if( sqlite3StrICmp(zLeft, "schema_version")==0
96377 || sqlite3StrICmp(zLeft, "user_version")==0
96378 || sqlite3StrICmp(zLeft, "freelist_count")==0
96379 || sqlite3StrICmp(zLeft, "application_id")==0
96380 ){
96381 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
96382 sqlite3VdbeUsesBtree(v, iDb);
96383 switch( zLeft[0] ){
96384 case 'a': case 'A':
96385 iCookie = BTREE_APPLICATION_ID;
@@ -96419,40 +96773,42 @@
96419 sqlite3VdbeChangeP1(v, addr+1, iDb);
96420 sqlite3VdbeChangeP3(v, addr+1, iCookie);
96421 sqlite3VdbeSetNumCols(v, 1);
96422 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
96423 }
96424 }else
 
96425 #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
96426
96427 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
96428 /*
96429 ** PRAGMA compile_options
96430 **
96431 ** Return the names of all compile-time options used in this build,
96432 ** one option per row.
96433 */
96434 if( sqlite3StrICmp(zLeft, "compile_options")==0 ){
96435 int i = 0;
96436 const char *zOpt;
96437 sqlite3VdbeSetNumCols(v, 1);
96438 pParse->nMem = 1;
96439 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
96440 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
96441 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
96442 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
96443 }
96444 }else
 
96445 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
96446
96447 #ifndef SQLITE_OMIT_WAL
96448 /*
96449 ** PRAGMA [database.]wal_checkpoint = passive|full|restart
96450 **
96451 ** Checkpoint the database.
96452 */
96453 if( sqlite3StrICmp(zLeft, "wal_checkpoint")==0 ){
96454 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
96455 int eMode = SQLITE_CHECKPOINT_PASSIVE;
96456 if( zRight ){
96457 if( sqlite3StrICmp(zRight, "full")==0 ){
96458 eMode = SQLITE_CHECKPOINT_FULL;
@@ -96467,39 +96823,42 @@
96467 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
96468 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
96469
96470 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
96471 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
96472 }else
 
96473
96474 /*
96475 ** PRAGMA wal_autocheckpoint
96476 ** PRAGMA wal_autocheckpoint = N
96477 **
96478 ** Configure a database connection to automatically checkpoint a database
96479 ** after accumulating N frames in the log. Or query for the current value
96480 ** of N.
96481 */
96482 if( sqlite3StrICmp(zLeft, "wal_autocheckpoint")==0 ){
96483 if( zRight ){
96484 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
96485 }
96486 returnSingleInt(pParse, "wal_autocheckpoint",
96487 db->xWalCallback==sqlite3WalDefaultHook ?
96488 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
96489 }else
 
96490 #endif
96491
96492 /*
96493 ** PRAGMA shrink_memory
96494 **
96495 ** This pragma attempts to free as much memory as possible from the
96496 ** current database connection.
96497 */
96498 if( sqlite3StrICmp(zLeft, "shrink_memory")==0 ){
96499 sqlite3_db_release_memory(db);
96500 }else
 
96501
96502 /*
96503 ** PRAGMA busy_timeout
96504 ** PRAGMA busy_timeout = N
96505 **
@@ -96506,22 +96865,40 @@
96506 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value
96507 ** if one is set. If no busy handler or a different busy handler is set
96508 ** then 0 is returned. Setting the busy_timeout to 0 or negative
96509 ** disables the timeout.
96510 */
96511 if( sqlite3StrICmp(zLeft, "busy_timeout")==0 ){
 
96512 if( zRight ){
96513 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
96514 }
96515 returnSingleInt(pParse, "timeout", db->busyTimeout);
96516 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96517
96518 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
96519 /*
96520 ** Report the current state of file logs for all databases
96521 */
96522 if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
96523 static const char *const azLockName[] = {
96524 "unlocked", "shared", "reserved", "pending", "exclusive"
96525 };
96526 int i;
96527 sqlite3VdbeSetNumCols(v, 2);
@@ -96542,39 +96919,43 @@
96542 zState = azLockName[j];
96543 }
96544 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
96545 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
96546 }
96547
96548 }else
96549 #endif
96550
96551 #ifdef SQLITE_HAS_CODEC
96552 if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
96553 sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96554 }else
96555 if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
96556 sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96557 }else
96558 if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
96559 sqlite3StrICmp(zLeft, "hexrekey")==0) ){
96560 int i, h1, h2;
96561 char zKey[40];
96562 for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
96563 h1 += 9*(1&(h1>>6));
96564 h2 += 9*(1&(h2>>6));
96565 zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
96566 }
96567 if( (zLeft[3] & 0xf)==0xb ){
96568 sqlite3_key_v2(db, zDb, zKey, i/2);
96569 }else{
96570 sqlite3_rekey_v2(db, zDb, zKey, i/2);
96571 }
96572 }else
 
 
 
 
96573 #endif
96574 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
96575 if( sqlite3StrICmp(zLeft, "activate_extensions")==0 && zRight ){
96576 #ifdef SQLITE_HAS_CODEC
96577 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
96578 sqlite3_activate_see(&zRight[4]);
96579 }
96580 #endif
@@ -96581,15 +96962,15 @@
96581 #ifdef SQLITE_ENABLE_CEROD
96582 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
96583 sqlite3_activate_cerod(&zRight[6]);
96584 }
96585 #endif
96586 }else
 
96587 #endif
96588
96589
96590 {/* Empty ELSE clause */}
96591
96592 pragma_out:
96593 sqlite3DbFree(db, zLeft);
96594 sqlite3DbFree(db, zRight);
96595 }
@@ -97736,12 +98117,12 @@
97736 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
97737
97738 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
97739 if( pEq && isOuterJoin ){
97740 ExprSetProperty(pEq, EP_FromJoin);
97741 assert( !ExprHasAnyProperty(pEq, EP_TokenOnly|EP_Reduced) );
97742 ExprSetIrreducible(pEq);
97743 pEq->iRightJoinTable = (i16)pE2->iTable;
97744 }
97745 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
97746 }
97747
@@ -97772,12 +98153,12 @@
97772 ** the output, which is incorrect.
97773 */
97774 static void setJoinExpr(Expr *p, int iTable){
97775 while( p ){
97776 ExprSetProperty(p, EP_FromJoin);
97777 assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) );
97778 ExprSetIrreducible(p);
97779 p->iRightJoinTable = (i16)iTable;
97780 setJoinExpr(p->pLeft, iTable);
97781 p = p->pRight;
97782 }
97783 }
@@ -100700,11 +101081,11 @@
100700 assert( pTab && !pTab->pSelect && pExpr );
100701
100702 if( IsVirtual(pTab) ) return 0;
100703 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
100704 if( NEVER(pAggInfo->nFunc==0) ) return 0;
100705 if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
100706 if( pExpr->flags&EP_Distinct ) return 0;
100707
100708 return pTab;
100709 }
100710
@@ -101297,11 +101678,11 @@
101297 if( pF->iDistinct>=0 ){
101298 addrNext = sqlite3VdbeMakeLabel(v);
101299 assert( nArg==1 );
101300 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
101301 }
101302 if( pF->pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
101303 CollSeq *pColl = 0;
101304 struct ExprList_item *pItem;
101305 int j;
101306 assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
101307 for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
@@ -104140,11 +104521,11 @@
104140 sqlite3GenerateConstraintChecks(pParse, pTab, iCur, regNewRowid,
104141 aRegIdx, (chngRowid?regOldRowid:0), 1, onError, addr, 0);
104142
104143 /* Do FK constraint checks. */
104144 if( hasFK ){
104145 sqlite3FkCheck(pParse, pTab, regOldRowid, 0);
104146 }
104147
104148 /* Delete the index entries associated with the current record. */
104149 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regOldRowid);
104150 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
@@ -104154,21 +104535,21 @@
104154 sqlite3VdbeAddOp2(v, OP_Delete, iCur, 0);
104155 }
104156 sqlite3VdbeJumpHere(v, j1);
104157
104158 if( hasFK ){
104159 sqlite3FkCheck(pParse, pTab, 0, regNewRowid);
104160 }
104161
104162 /* Insert the new index entries and the new record. */
104163 sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
104164
104165 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
104166 ** handle rows (possibly in other tables) that refer via a foreign key
104167 ** to the row just updated. */
104168 if( hasFK ){
104169 sqlite3FkActions(pParse, pTab, pChanges, regOldRowid);
104170 }
104171 }
104172
104173 /* Increment the row counter
104174 */
@@ -105692,11 +106073,11 @@
105692 *pNew = *pDef;
105693 pNew->zName = (char *)&pNew[1];
105694 memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1);
105695 pNew->xFunc = xFunc;
105696 pNew->pUserData = pArg;
105697 pNew->flags |= SQLITE_FUNC_EPHEM;
105698 return pNew;
105699 }
105700
105701 /*
105702 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
@@ -105829,24 +106210,25 @@
105829
105830 /*
105831 ** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The
105832 ** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
105833 ** (Virtual tables can return a larger cost, but let's assume they do not.)
105834 ** So all costs can be stored in a 16-bit unsigned integer without risk
105835 ** of overflow.
105836 **
105837 ** Costs are estimates, so no effort is made to compute 10*log2(X) exactly.
105838 ** Instead, a close estimate is used. Any value of X<=1 is stored as 0.
105839 ** X=2 is 10. X=3 is 16. X=1000 is 99. etc.
 
105840 **
105841 ** The tool/wherecosttest.c source file implements a command-line program
105842 ** that will convert WhereCosts to integers, convert integers to WhereCosts
105843 ** and do addition and multiplication on WhereCost values. The wherecosttest
105844 ** command-line program is a useful utility to have around when working with
105845 ** this module.
105846 */
105847 typedef unsigned short int WhereCost;
105848
105849 /*
105850 ** This object contains information needed to implement a single nested
105851 ** loop in WHERE clause.
105852 **
@@ -105883,10 +106265,11 @@
105883 } *aInLoop; /* Information about each nested IN operator */
105884 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
105885 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
105886 } u;
105887 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
 
105888 };
105889
105890 /*
105891 ** Each instance of this object represents an algorithm for evaluating one
105892 ** term of a join. Every term of the FROM clause will have at least
@@ -106045,10 +106428,11 @@
106045 union {
106046 int leftColumn; /* Column number of X in "X <op> <expr>" */
106047 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
106048 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
106049 } u;
 
106050 u16 eOperator; /* A WO_xx value describing <op> */
106051 u8 wtFlags; /* TERM_xxx bit flags. See below */
106052 u8 nChild; /* Number of children that must disable us */
106053 WhereClause *pWC; /* The clause this term is part of */
106054 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
@@ -106419,10 +106803,13 @@
106419 if( pWC->a!=pWC->aStatic ){
106420 sqlite3DbFree(db, pWC->a);
106421 }
106422 }
106423
 
 
 
106424 /*
106425 ** Add a single new WhereTerm entry to the WhereClause object pWC.
106426 ** The new WhereTerm object is constructed from Expr p and with wtFlags.
106427 ** The index in pWC->a[] of the new WhereTerm is returned on success.
106428 ** 0 is returned if the new WhereTerm could not be added due to a memory
@@ -106460,10 +106847,15 @@
106460 sqlite3DbFree(db, pOld);
106461 }
106462 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
106463 }
106464 pTerm = &pWC->a[idx = pWC->nTerm++];
 
 
 
 
 
106465 pTerm->pExpr = sqlite3ExprSkipCollate(p);
106466 pTerm->wtFlags = wtFlags;
106467 pTerm->pWC = pWC;
106468 pTerm->iParent = -1;
106469 return idx;
@@ -108321,18 +108713,19 @@
108321 WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */
108322 WhereCost *pnOut /* IN/OUT: Number of rows visited */
108323 ){
108324 int rc = SQLITE_OK;
108325 int nOut = (int)*pnOut;
 
108326
108327 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
108328 Index *p = pBuilder->pNew->u.btree.pIndex;
108329 int nEq = pBuilder->pNew->u.btree.nEq;
108330
108331 if( nEq==pBuilder->nRecValid
 
108332 && nEq<p->nSampleCol
108333 && p->nSample
108334 && OptimizationEnabled(pParse->db, SQLITE_Stat3)
108335 ){
108336 UnpackedRecord *pRec = pBuilder->pRec;
108337 tRowcnt a[2];
108338 u8 aff;
@@ -108383,10 +108776,11 @@
108383 if( rc==SQLITE_OK && bOk ){
108384 tRowcnt iNew;
108385 whereKeyStats(pParse, p, pRec, 0, a);
108386 iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
108387 if( iNew>iLower ) iLower = iNew;
 
108388 }
108389 }
108390
108391 /* If possible, improve on the iUpper estimate using ($P:$U). */
108392 if( pUpper ){
@@ -108397,16 +108791,16 @@
108397 if( rc==SQLITE_OK && bOk ){
108398 tRowcnt iNew;
108399 whereKeyStats(pParse, p, pRec, 1, a);
108400 iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
108401 if( iNew<iUpper ) iUpper = iNew;
 
108402 }
108403 }
108404
108405 pBuilder->pRec = pRec;
108406 if( rc==SQLITE_OK ){
108407 WhereCost nNew;
108408 if( iUpper>iLower ){
108409 nNew = whereCost(iUpper - iLower);
108410 }else{
108411 nNew = 10; assert( 10==whereCost(2) );
108412 }
@@ -108424,17 +108818,21 @@
108424 UNUSED_PARAMETER(pBuilder);
108425 #endif
108426 assert( pLower || pUpper );
108427 /* TUNING: Each inequality constraint reduces the search space 4-fold.
108428 ** A BETWEEN operator, therefore, reduces the search space 16-fold */
 
108429 if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ){
108430 nOut -= 20; assert( 20==whereCost(4) );
 
108431 }
108432 if( pUpper ){
108433 nOut -= 20; assert( 20==whereCost(4) );
 
108434 }
108435 if( nOut<10 ) nOut = 10;
 
108436 *pnOut = (WhereCost)nOut;
108437 return rc;
108438 }
108439
108440 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -108576,10 +108974,11 @@
108576 */
108577 static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
108578 if( pTerm
108579 && (pTerm->wtFlags & TERM_CODED)==0
108580 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
 
108581 ){
108582 pTerm->wtFlags |= TERM_CODED;
108583 if( pTerm->iParent>=0 ){
108584 WhereTerm *pOther = &pTerm->pWC->a[pTerm->iParent];
108585 if( (--pOther->nChild)==0 ){
@@ -109001,20 +109400,20 @@
109001 struct SrcList_item *pTabItem; /* FROM clause term being coded */
109002 int addrBrk; /* Jump here to break out of the loop */
109003 int addrCont; /* Jump here to continue with next cycle */
109004 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
109005 int iReleaseReg = 0; /* Temp register to free before returning */
109006 Bitmask newNotReady; /* Return value */
109007
109008 pParse = pWInfo->pParse;
109009 v = pParse->pVdbe;
109010 pWC = &pWInfo->sWC;
109011 db = pParse->db;
109012 pLevel = &pWInfo->a[iLevel];
109013 pLoop = pLevel->pWLoop;
109014 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
109015 iCur = pTabItem->iCursor;
 
109016 bRev = (pWInfo->revMask>>iLevel)&1;
109017 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
109018 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
109019 VdbeNoopComment((v, "Begin Join Loop %d", iLevel));
109020
@@ -109663,21 +110062,20 @@
109663 pLevel->op = aStep[bRev];
109664 pLevel->p1 = iCur;
109665 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
109666 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
109667 }
109668 newNotReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109669
109670 /* Insert code to test every subexpression that can be completely
109671 ** computed using the current set of tables.
109672 */
109673 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
109674 Expr *pE;
109675 testcase( pTerm->wtFlags & TERM_VIRTUAL );
109676 testcase( pTerm->wtFlags & TERM_CODED );
109677 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
109678 if( (pTerm->prereqAll & newNotReady)!=0 ){
109679 testcase( pWInfo->untestedTerms==0
109680 && (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
109681 pWInfo->untestedTerms = 1;
109682 continue;
109683 }
@@ -109705,11 +110103,11 @@
109705 if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
109706 if( pTerm->leftCursor!=iCur ) continue;
109707 if( pLevel->iLeftJoin ) continue;
109708 pE = pTerm->pExpr;
109709 assert( !ExprHasProperty(pE, EP_FromJoin) );
109710 assert( (pTerm->prereqRight & newNotReady)!=0 );
109711 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
109712 if( pAlt==0 ) continue;
109713 if( pAlt->wtFlags & (TERM_CODED) ) continue;
109714 testcase( pAlt->eOperator & WO_EQ );
109715 testcase( pAlt->eOperator & WO_IN );
@@ -109733,11 +110131,11 @@
109733 sqlite3ExprCacheClear(pParse);
109734 for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
109735 testcase( pTerm->wtFlags & TERM_VIRTUAL );
109736 testcase( pTerm->wtFlags & TERM_CODED );
109737 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
109738 if( (pTerm->prereqAll & newNotReady)!=0 ){
109739 assert( pWInfo->untestedTerms );
109740 continue;
109741 }
109742 assert( pTerm->pExpr );
109743 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
@@ -109744,11 +110142,11 @@
109744 pTerm->wtFlags |= TERM_CODED;
109745 }
109746 }
109747 sqlite3ReleaseTempReg(pParse, iReleaseReg);
109748
109749 return newNotReady;
109750 }
109751
109752 #ifdef WHERETRACE_ENABLED
109753 /*
109754 ** Print a WhereLoop object for debugging purposes
@@ -109845,12 +110243,15 @@
109845
109846 /*
109847 ** Transfer content from the second pLoop into the first.
109848 */
109849 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
109850 if( whereLoopResize(db, pTo, pFrom->nLTerm) ) return SQLITE_NOMEM;
109851 whereLoopClearUnion(db, pTo);
 
 
 
 
109852 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
109853 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
109854 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
109855 pFrom->u.vtab.needFree = 0;
109856 }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
@@ -109962,13 +110363,13 @@
109962 ** all of (1) dependencies (2) setup-cost, (3) run-cost, and
109963 ** (4) number of output rows. */
109964 assert( p->rSetup==pTemplate->rSetup );
109965 if( p->prereq==pTemplate->prereq
109966 && p->nLTerm<pTemplate->nLTerm
109967 && (p->wsFlags & WHERE_INDEXED)!=0
109968 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
109969 && p->u.btree.pIndex==pTemplate->u.btree.pIndex
109970 ){
109971 /* Overwrite an existing WhereLoop with an similar one that uses
109972 ** more terms of the index */
109973 pNext = p->pNextLoop;
109974 break;
@@ -109979,16 +110380,16 @@
109979 }
109980 }
109981 if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
109982 && p->rRun>=pTemplate->rRun
109983 && p->nOut>=pTemplate->nOut
109984 && ALWAYS(p->rSetup>=pTemplate->rSetup) /* See SETUP-INVARIANT above */
109985 ){
109986 /* Overwrite an existing WhereLoop with a better one: one that is
109987 ** better at one of (1) dependencies, (2) setup-cost, (3) run-cost
109988 ** or (4) number of output rows, and is no worse in any of those
109989 ** categories. */
 
109990 pNext = p->pNextLoop;
109991 break;
109992 }
109993 }
109994
@@ -110030,10 +110431,40 @@
110030 whereLoopPrint(pTemplate, pWInfo->pTabList);
110031 }
110032 #endif
110033 return SQLITE_OK;
110034 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110035
110036 /*
110037 ** We have so far matched pBuilder->pNew->u.btree.nEq terms of the index pIndex.
110038 ** Try to match one more.
110039 **
@@ -110197,11 +110628,11 @@
110197 ** the main table */
110198 pNew->rRun = whereCostAdd(pNew->rRun, rLogSize>27 ? rLogSize-17 : 10);
110199 }
110200 /* Step cost for each output row */
110201 pNew->rRun = whereCostAdd(pNew->rRun, pNew->nOut);
110202 /* TBD: Adjust nOut for additional constraints */
110203 rc = whereLoopInsert(pBuilder, pNew);
110204 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
110205 && pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0))
110206 ){
110207 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -110401,11 +110832,13 @@
110401 ** + The extra 3 factor is to encourage the use of indexed lookups
110402 ** over full scans. A smaller constant 2 is used for covering
110403 ** index scans so that a covering index scan will be favored over
110404 ** a table scan. */
110405 pNew->rRun = whereCostAdd(rSize,rLogSize) + 16;
 
110406 rc = whereLoopInsert(pBuilder, pNew);
 
110407 if( rc ) break;
110408 }else{
110409 Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe);
110410 pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
110411
@@ -110433,11 +110866,13 @@
110433 assert( b!=0 );
110434 /* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N)
110435 ** which we will simplify to just N*log2(N) */
110436 pNew->rRun = rSize + rLogSize;
110437 }
 
110438 rc = whereLoopInsert(pBuilder, pNew);
 
110439 if( rc ) break;
110440 }
110441 }
110442
110443 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
@@ -111040,13 +111475,16 @@
111040 int nLoop; /* Number of terms in the join */
111041 Parse *pParse; /* Parsing context */
111042 sqlite3 *db; /* The database connection */
111043 int iLoop; /* Loop counter over the terms of the join */
111044 int ii, jj; /* Loop counters */
111045 WhereCost rCost; /* Cost of a path */
111046 WhereCost mxCost = 0; /* Maximum cost of a set of paths */
111047 WhereCost rSortCost; /* Cost to do a sort */
 
 
 
111048 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
111049 WherePath *aFrom; /* All nFrom paths at the previous level */
111050 WherePath *aTo; /* The nTo best paths at the current level */
111051 WherePath *pFrom; /* An element of aFrom[] that we are working on */
111052 WherePath *pTo; /* An element of aTo[] that we are working on */
@@ -111111,10 +111549,11 @@
111111 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
111112 /* At this point, pWLoop is a candidate to be the next loop.
111113 ** Compute its cost */
111114 rCost = whereCostAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
111115 rCost = whereCostAdd(rCost, pFrom->rCost);
 
111116 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
111117 if( !isOrderedValid ){
111118 switch( wherePathSatisfiesOrderBy(pWInfo,
111119 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
111120 iLoop, pWLoop, &revMask) ){
@@ -111133,21 +111572,25 @@
111133 }else{
111134 revMask = pFrom->revLoop;
111135 }
111136 /* Check to see if pWLoop should be added to the mxChoice best so far */
111137 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
111138 if( pTo->maskLoop==maskNew && pTo->isOrderedValid==isOrderedValid ){
 
 
 
 
111139 testcase( jj==nTo-1 );
111140 break;
111141 }
111142 }
111143 if( jj>=nTo ){
111144 if( nTo>=mxChoice && rCost>=mxCost ){
111145 #ifdef WHERETRACE_ENABLED
111146 if( sqlite3WhereTrace&0x4 ){
111147 sqlite3DebugPrintf("Skip %s cost=%3d order=%c\n",
111148 wherePathName(pFrom, iLoop, pWLoop), rCost,
111149 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111150 }
111151 #endif
111152 continue;
111153 }
@@ -111155,30 +111598,30 @@
111155 if( nTo<mxChoice ){
111156 /* Increase the size of the aTo set by one */
111157 jj = nTo++;
111158 }else{
111159 /* New path replaces the prior worst to keep count below mxChoice */
111160 for(jj=nTo-1; aTo[jj].rCost<mxCost; jj--){ assert(jj>0); }
111161 }
111162 pTo = &aTo[jj];
111163 #ifdef WHERETRACE_ENABLED
111164 if( sqlite3WhereTrace&0x4 ){
111165 sqlite3DebugPrintf("New %s cost=%-3d order=%c\n",
111166 wherePathName(pFrom, iLoop, pWLoop), rCost,
111167 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111168 }
111169 #endif
111170 }else{
111171 if( pTo->rCost<=rCost ){
111172 #ifdef WHERETRACE_ENABLED
111173 if( sqlite3WhereTrace&0x4 ){
111174 sqlite3DebugPrintf(
111175 "Skip %s cost=%-3d order=%c",
111176 wherePathName(pFrom, iLoop, pWLoop), rCost,
111177 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111178 sqlite3DebugPrintf(" vs %s cost=%-3d order=%c\n",
111179 wherePathName(pTo, iLoop+1, 0), pTo->rCost,
111180 pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
111181 }
111182 #endif
111183 testcase( pTo->rCost==rCost );
111184 continue;
@@ -111186,32 +111629,38 @@
111186 testcase( pTo->rCost==rCost+1 );
111187 /* A new and better score for a previously created equivalent path */
111188 #ifdef WHERETRACE_ENABLED
111189 if( sqlite3WhereTrace&0x4 ){
111190 sqlite3DebugPrintf(
111191 "Update %s cost=%-3d order=%c",
111192 wherePathName(pFrom, iLoop, pWLoop), rCost,
111193 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111194 sqlite3DebugPrintf(" was %s cost=%-3d order=%c\n",
111195 wherePathName(pTo, iLoop+1, 0), pTo->rCost,
111196 pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
111197 }
111198 #endif
111199 }
111200 /* pWLoop is a winner. Add it to the set of best so far */
111201 pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
111202 pTo->revLoop = revMask;
111203 pTo->nRow = pFrom->nRow + pWLoop->nOut;
111204 pTo->rCost = rCost;
111205 pTo->isOrderedValid = isOrderedValid;
111206 pTo->isOrdered = isOrdered;
111207 memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
111208 pTo->aLoop[iLoop] = pWLoop;
111209 if( nTo>=mxChoice ){
 
111210 mxCost = aTo[0].rCost;
 
111211 for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
111212 if( pTo->rCost>mxCost ) mxCost = pTo->rCost;
 
 
 
 
111213 }
111214 }
111215 }
111216 }
111217
@@ -111244,16 +111693,13 @@
111244 return SQLITE_ERROR;
111245 }
111246
111247 /* Find the lowest cost path. pFrom will be left pointing to that path */
111248 pFrom = aFrom;
111249 assert( nFrom==1 );
111250 #if 0 /* The following is needed if nFrom is ever more than 1 */
111251 for(ii=1; ii<nFrom; ii++){
111252 if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
111253 }
111254 #endif
111255 assert( pWInfo->nLevel==nLoop );
111256 /* Load the lowest cost path into pWInfo */
111257 for(iLoop=0; iLoop<nLoop; iLoop++){
111258 WhereLevel *pLevel = pWInfo->a + iLoop;
111259 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -114879,16 +115325,17 @@
114879 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
114880 }
114881 break;
114882 case 231: /* expr ::= CASE case_operand case_exprlist case_else END */
114883 {
114884 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, yymsp[-1].minor.yy122, 0);
114885 if( yygotominor.yy342.pExpr ){
114886 yygotominor.yy342.pExpr->x.pList = yymsp[-2].minor.yy442;
114887 sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
114888 }else{
114889 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
 
114890 }
114891 yygotominor.yy342.zStart = yymsp[-4].minor.yy0.z;
114892 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
114893 }
114894 break;
@@ -118020,11 +118467,11 @@
118020 ** and there are active VMs, then return SQLITE_BUSY. If a function
118021 ** is being overridden/deleted but there are no active VMs, allow the
118022 ** operation to continue but invalidate all precompiled statements.
118023 */
118024 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
118025 if( p && p->iPrefEnc==enc && p->nArg==nArg ){
118026 if( db->nVdbeActive ){
118027 sqlite3Error(db, SQLITE_BUSY,
118028 "unable to delete/modify user-function due to active statements");
118029 assert( !db->mallocFailed );
118030 return SQLITE_BUSY;
@@ -118045,11 +118492,11 @@
118045
118046 if( pDestructor ){
118047 pDestructor->nRef++;
118048 }
118049 p->pDestructor = pDestructor;
118050 p->flags = 0;
118051 p->xFunc = xFunc;
118052 p->xStep = xStep;
118053 p->xFinalize = xFinal;
118054 p->pUserData = pUserData;
118055 p->nArg = (u16)nArg;
118056
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.1"
660 #define SQLITE_VERSION_NUMBER 3008001
661 #define SQLITE_SOURCE_ID "2013-09-16 12:57:19 daf6ba413cb3cb6065774ba07495eab4a28b49b0"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -10143,12 +10143,10 @@
10143 #endif
10144 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
10145 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
10146 void *pCollNeededArg;
10147 sqlite3_value *pErr; /* Most recent error message */
 
 
10148 union {
10149 volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
10150 double notUsed1; /* Spacer */
10151 } u1;
10152 Lookaside lookaside; /* Lookaside malloc configuration */
@@ -10254,10 +10252,11 @@
10252 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10253 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10254 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10255 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10256 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10257 #define SQLITE_AdjustOutEst 0x1000 /* Adjust output estimates using WHERE */
10258 #define SQLITE_AllOpts 0xffff /* All optimizations */
10259
10260 /*
10261 ** Macros for testing whether or not optimizations are enabled or disabled.
10262 */
@@ -10287,12 +10286,11 @@
10286 ** hash table. When multiple functions have the same name, the hash table
10287 ** points to a linked list of these structures.
10288 */
10289 struct FuncDef {
10290 i16 nArg; /* Number of arguments. -1 means unlimited */
10291 u16 funcFlags; /* Some combination of SQLITE_FUNC_* */
 
10292 void *pUserData; /* User data parameter */
10293 FuncDef *pNext; /* Next function with same name */
10294 void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
10295 void (*xStep)(sqlite3_context*,int,sqlite3_value**); /* Aggregate step */
10296 void (*xFinalize)(sqlite3_context*); /* Aggregate finalizer */
@@ -10324,18 +10322,20 @@
10322 /*
10323 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
10324 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There
10325 ** are assert() statements in the code to verify this.
10326 */
10327 #define SQLITE_FUNC_ENCMASK 0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
10328 #define SQLITE_FUNC_LIKE 0x004 /* Candidate for the LIKE optimization */
10329 #define SQLITE_FUNC_CASE 0x008 /* Case-sensitive LIKE-type function */
10330 #define SQLITE_FUNC_EPHEM 0x010 /* Ephemeral. Delete with VDBE */
10331 #define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
10332 #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
10333 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10334 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10335 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10336 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10337
10338 /*
10339 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10340 ** used to create the initializers for the FuncDef structures.
10341 **
@@ -10359,22 +10359,22 @@
10359 ** available as the function user-data (sqlite3_user_data()). The
10360 ** FuncDef.flags variable is set to the value passed as the flags
10361 ** parameter.
10362 */
10363 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
10364 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10365 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10366 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10367 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
10368 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10369 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10370 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10371 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
10372 #define LIKEFUNC(zName, nArg, arg, flags) \
10373 {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10374 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10375 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
10376 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10377
10378 /*
10379 ** All current savepoints are stored in a linked list starting at
10380 ** sqlite3.pSavepoint. The first element in the list is the most recently
@@ -10945,11 +10945,11 @@
10945 ** allocated, regardless of whether or not EP_Reduced is set.
10946 */
10947 struct Expr {
10948 u8 op; /* Operation performed by this node */
10949 char affinity; /* The affinity of the column or 0 if not a column */
10950 u32 flags; /* Various flags. EP_* See below */
10951 union {
10952 char *zToken; /* Token value. Zero terminated and dequoted */
10953 int iValue; /* Non-negative integer value if EP_IntValue */
10954 } u;
10955
@@ -10959,12 +10959,12 @@
10959 *********************************************************************/
10960
10961 Expr *pLeft; /* Left subnode */
10962 Expr *pRight; /* Right subnode */
10963 union {
10964 ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */
10965 Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */
10966 } x;
10967
10968 /* If the EP_Reduced flag is set in the Expr.flags mask, then no
10969 ** space is allocated for the fields below this point. An attempt to
10970 ** access them will result in a segfault or malfunction.
@@ -10973,16 +10973,16 @@
10973 #if SQLITE_MAX_EXPR_DEPTH>0
10974 int nHeight; /* Height of the tree headed by this node */
10975 #endif
10976 int iTable; /* TK_COLUMN: cursor number of table holding column
10977 ** TK_REGISTER: register number
10978 ** TK_TRIGGER: 1 -> new, 0 -> old
10979 ** EP_Unlikely: 1000 times likelihood */
10980 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
10981 ** TK_VARIABLE: variable number (always >= 1). */
10982 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
10983 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
 
10984 u8 op2; /* TK_REGISTER: original value of Expr.op
10985 ** TK_COLUMN: the value of p5 for OP_Column
10986 ** TK_AGG_FUNCTION: nesting depth */
10987 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
10988 Table *pTab; /* Table for TK_COLUMN expressions. */
@@ -10989,53 +10989,48 @@
10989 };
10990
10991 /*
10992 ** The following are the meanings of bits in the Expr.flags field.
10993 */
10994 #define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */
10995 #define EP_Agg 0x000002 /* Contains one or more aggregate functions */
10996 #define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */
10997 #define EP_Error 0x000008 /* Expression contains one or more errors */
10998 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
10999 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
11000 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
11001 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
11002 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
11003 #define EP_FixedDest 0x000200 /* Result needed in a specific register */
11004 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
11005 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
11006 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
11007 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
11008 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11009 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11010 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11011 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11012 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11013
11014 /*
11015 ** These macros can be used to test, set, or clear bits in the
11016 ** Expr.flags field.
11017 */
11018 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
11019 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
11020 #define ExprSetProperty(E,P) (E)->flags|=(P)
11021 #define ExprClearProperty(E,P) (E)->flags&=~(P)
11022
11023 /* The ExprSetVVAProperty() macro is used for Verification, Validation,
11024 ** and Accreditation only. It works like ExprSetProperty() during VVA
11025 ** processes but is a no-op for delivery.
11026 */
11027 #ifdef SQLITE_DEBUG
11028 # define ExprSetVVAProperty(E,P) (E)->flags|=(P)
11029 #else
11030 # define ExprSetVVAProperty(E,P)
11031 #endif
11032
11033 /*
11034 ** Macros to determine the number of bytes required by a normal Expr
11035 ** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
11036 ** and an Expr struct with the EP_TokenOnly flag set.
@@ -12411,10 +12406,11 @@
12406 SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*);
12407 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
12408 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
12409 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
12410 SQLITE_PRIVATE void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
12411 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
12412 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
12413 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
12414 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
12415 SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
12416 SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
@@ -12431,22 +12427,22 @@
12427 ** OMIT_FOREIGN_KEY is not, only some of the functions are no-oped. In
12428 ** this case foreign keys are parsed, but no other functionality is
12429 ** provided (enforcement of FK constraints requires the triggers sub-system).
12430 */
12431 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
12432 SQLITE_PRIVATE void sqlite3FkCheck(Parse*, Table*, int, int, int*, int);
12433 SQLITE_PRIVATE void sqlite3FkDropTable(Parse*, SrcList *, Table*);
12434 SQLITE_PRIVATE void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
12435 SQLITE_PRIVATE int sqlite3FkRequired(Parse*, Table*, int*, int);
12436 SQLITE_PRIVATE u32 sqlite3FkOldmask(Parse*, Table*);
12437 SQLITE_PRIVATE FKey *sqlite3FkReferences(Table *);
12438 #else
12439 #define sqlite3FkActions(a,b,c,d,e,f)
12440 #define sqlite3FkCheck(a,b,c,d)
12441 #define sqlite3FkDropTable(a,b,c)
12442 #define sqlite3FkOldmask(a,b) 0
12443 #define sqlite3FkRequired(a,b,c,d,e,f) 0
12444 #endif
12445 #ifndef SQLITE_OMIT_FOREIGN_KEY
12446 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
12447 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
12448 #else
@@ -13589,10 +13585,11 @@
13585 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13586 u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */
13587 #ifndef SQLITE_OMIT_TRACE
13588 i64 startTime; /* Time when query started - used for profiling */
13589 #endif
13590 i64 iCurrentTime; /* Value of julianday('now') for this statement */
13591 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13592 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
13593 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
13594 char *zSql; /* Text of the SQL statement that generated this */
13595 void *pFree; /* Free this when deleting the vdbe */
@@ -14268,12 +14265,12 @@
14265 ** Set the time to the current time reported by the VFS.
14266 **
14267 ** Return the number of errors.
14268 */
14269 static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
14270 p->iJD = sqlite3StmtCurrentTime(context);
14271 if( p->iJD>0 ){
14272 p->validJD = 1;
14273 return 0;
14274 }else{
14275 return 1;
14276 }
@@ -15052,12 +15049,12 @@
15049 char zBuf[20];
15050
15051 UNUSED_PARAMETER(argc);
15052 UNUSED_PARAMETER(argv);
15053
15054 iT = sqlite3StmtCurrentTime(context);
15055 if( iT<=0 ) return;
15056 t = iT/1000 - 10000*(sqlite3_int64)21086676;
15057 #ifdef HAVE_GMTIME_R
15058 pTm = gmtime_r(&t, &sNow);
15059 #else
15060 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
@@ -19259,10 +19256,11 @@
19256 ** Free memory that might be associated with a particular database
19257 ** connection.
19258 */
19259 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
19260 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19261 if( p==0 ) return;
19262 if( db ){
19263 if( db->pnBytesFreed ){
19264 *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
19265 return;
19266 }
@@ -21374,11 +21372,12 @@
21372 case '"': break;
21373 case '`': break; /* For MySQL compatibility */
21374 case '[': quote = ']'; break; /* For MS SqlServer compatibility */
21375 default: return -1;
21376 }
21377 for(i=1, j=0;; i++){
21378 assert( z[i] );
21379 if( z[i]==quote ){
21380 if( z[i+1]==quote ){
21381 z[j++] = quote;
21382 i++;
21383 }else{
@@ -30809,10 +30808,18 @@
30808 */
30809 #ifndef winIsDirSep
30810 # define winIsDirSep(a) (((a) == '/') || ((a) == '\\'))
30811 #endif
30812
30813 /*
30814 ** This macro is used when a local variable is set to a value that is
30815 ** [sometimes] not used by the code (e.g. via conditional compilation).
30816 */
30817 #ifndef UNUSED_VARIABLE_VALUE
30818 # define UNUSED_VARIABLE_VALUE(x) (void)(x)
30819 #endif
30820
30821 /*
30822 ** Returns the string that should be used as the directory separator.
30823 */
30824 #ifndef winGetDirDep
30825 # ifdef __CYGWIN__
@@ -31059,11 +31066,12 @@
31066 ** In order to facilitate testing on a WinNT system, the test fixture
31067 ** can manually set this value to 1 to emulate Win98 behavior.
31068 */
31069 #ifdef SQLITE_TEST
31070 SQLITE_API int sqlite3_os_type = 0;
31071 #elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
31072 defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
31073 static int sqlite3_os_type = 0;
31074 #endif
31075
31076 #ifndef SYSCALL
31077 # define SYSCALL sqlite3_syscall_ptr
@@ -31374,89 +31382,98 @@
31382 #endif
31383
31384 #define osGetVersionExA ((BOOL(WINAPI*)( \
31385 LPOSVERSIONINFOA))aSyscall[34].pCurrent)
31386
31387 #if defined(SQLITE_WIN32_HAS_WIDE)
31388 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
31389 #else
31390 { "GetVersionExW", (SYSCALL)0, 0 },
31391 #endif
31392
31393 #define osGetVersionExW ((BOOL(WINAPI*)( \
31394 LPOSVERSIONINFOW))aSyscall[35].pCurrent)
31395
31396 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
31397
31398 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
31399 SIZE_T))aSyscall[36].pCurrent)
31400
31401 #if !SQLITE_OS_WINRT
31402 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
31403 #else
31404 { "HeapCreate", (SYSCALL)0, 0 },
31405 #endif
31406
31407 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
31408 SIZE_T))aSyscall[37].pCurrent)
31409
31410 #if !SQLITE_OS_WINRT
31411 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
31412 #else
31413 { "HeapDestroy", (SYSCALL)0, 0 },
31414 #endif
31415
31416 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[38].pCurrent)
31417
31418 { "HeapFree", (SYSCALL)HeapFree, 0 },
31419
31420 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[39].pCurrent)
31421
31422 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
31423
31424 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
31425 SIZE_T))aSyscall[40].pCurrent)
31426
31427 { "HeapSize", (SYSCALL)HeapSize, 0 },
31428
31429 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
31430 LPCVOID))aSyscall[41].pCurrent)
31431
31432 #if !SQLITE_OS_WINRT
31433 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
31434 #else
31435 { "HeapValidate", (SYSCALL)0, 0 },
31436 #endif
31437
31438 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
31439 LPCVOID))aSyscall[42].pCurrent)
31440
31441 #if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31442 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
31443 #else
31444 { "LoadLibraryA", (SYSCALL)0, 0 },
31445 #endif
31446
31447 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[43].pCurrent)
31448
31449 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
31450 !defined(SQLITE_OMIT_LOAD_EXTENSION)
31451 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
31452 #else
31453 { "LoadLibraryW", (SYSCALL)0, 0 },
31454 #endif
31455
31456 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[44].pCurrent)
31457
31458 #if !SQLITE_OS_WINRT
31459 { "LocalFree", (SYSCALL)LocalFree, 0 },
31460 #else
31461 { "LocalFree", (SYSCALL)0, 0 },
31462 #endif
31463
31464 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[45].pCurrent)
31465
31466 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31467 { "LockFile", (SYSCALL)LockFile, 0 },
31468 #else
31469 { "LockFile", (SYSCALL)0, 0 },
31470 #endif
31471
31472 #ifndef osLockFile
31473 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31474 DWORD))aSyscall[46].pCurrent)
31475 #endif
31476
31477 #if !SQLITE_OS_WINCE
31478 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
31479 #else
@@ -31463,218 +31480,218 @@
31480 { "LockFileEx", (SYSCALL)0, 0 },
31481 #endif
31482
31483 #ifndef osLockFileEx
31484 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
31485 LPOVERLAPPED))aSyscall[47].pCurrent)
31486 #endif
31487
31488 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
31489 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
31490 #else
31491 { "MapViewOfFile", (SYSCALL)0, 0 },
31492 #endif
31493
31494 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31495 SIZE_T))aSyscall[48].pCurrent)
31496
31497 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
31498
31499 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
31500 int))aSyscall[49].pCurrent)
31501
31502 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
31503
31504 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
31505 LARGE_INTEGER*))aSyscall[50].pCurrent)
31506
31507 { "ReadFile", (SYSCALL)ReadFile, 0 },
31508
31509 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
31510 LPOVERLAPPED))aSyscall[51].pCurrent)
31511
31512 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
31513
31514 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent)
31515
31516 #if !SQLITE_OS_WINRT
31517 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
31518 #else
31519 { "SetFilePointer", (SYSCALL)0, 0 },
31520 #endif
31521
31522 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
31523 DWORD))aSyscall[53].pCurrent)
31524
31525 #if !SQLITE_OS_WINRT
31526 { "Sleep", (SYSCALL)Sleep, 0 },
31527 #else
31528 { "Sleep", (SYSCALL)0, 0 },
31529 #endif
31530
31531 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[54].pCurrent)
31532
31533 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
31534
31535 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
31536 LPFILETIME))aSyscall[55].pCurrent)
31537
31538 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
31539 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
31540 #else
31541 { "UnlockFile", (SYSCALL)0, 0 },
31542 #endif
31543
31544 #ifndef osUnlockFile
31545 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31546 DWORD))aSyscall[56].pCurrent)
31547 #endif
31548
31549 #if !SQLITE_OS_WINCE
31550 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
31551 #else
31552 { "UnlockFileEx", (SYSCALL)0, 0 },
31553 #endif
31554
31555 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
31556 LPOVERLAPPED))aSyscall[57].pCurrent)
31557
31558 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
31559 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
31560 #else
31561 { "UnmapViewOfFile", (SYSCALL)0, 0 },
31562 #endif
31563
31564 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[58].pCurrent)
31565
31566 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
31567
31568 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
31569 LPCSTR,LPBOOL))aSyscall[59].pCurrent)
31570
31571 { "WriteFile", (SYSCALL)WriteFile, 0 },
31572
31573 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
31574 LPOVERLAPPED))aSyscall[60].pCurrent)
31575
31576 #if SQLITE_OS_WINRT
31577 { "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
31578 #else
31579 { "CreateEventExW", (SYSCALL)0, 0 },
31580 #endif
31581
31582 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
31583 DWORD,DWORD))aSyscall[61].pCurrent)
31584
31585 #if !SQLITE_OS_WINRT
31586 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
31587 #else
31588 { "WaitForSingleObject", (SYSCALL)0, 0 },
31589 #endif
31590
31591 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
31592 DWORD))aSyscall[62].pCurrent)
31593
31594 #if SQLITE_OS_WINRT
31595 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
31596 #else
31597 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
31598 #endif
31599
31600 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
31601 BOOL))aSyscall[63].pCurrent)
31602
31603 #if SQLITE_OS_WINRT
31604 { "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
31605 #else
31606 { "SetFilePointerEx", (SYSCALL)0, 0 },
31607 #endif
31608
31609 #define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
31610 PLARGE_INTEGER,DWORD))aSyscall[64].pCurrent)
31611
31612 #if SQLITE_OS_WINRT
31613 { "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
31614 #else
31615 { "GetFileInformationByHandleEx", (SYSCALL)0, 0 },
31616 #endif
31617
31618 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
31619 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[65].pCurrent)
31620
31621 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31622 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
31623 #else
31624 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
31625 #endif
31626
31627 #define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
31628 SIZE_T))aSyscall[66].pCurrent)
31629
31630 #if SQLITE_OS_WINRT
31631 { "CreateFile2", (SYSCALL)CreateFile2, 0 },
31632 #else
31633 { "CreateFile2", (SYSCALL)0, 0 },
31634 #endif
31635
31636 #define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
31637 LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[67].pCurrent)
31638
31639 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_LOAD_EXTENSION)
31640 { "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
31641 #else
31642 { "LoadPackagedLibrary", (SYSCALL)0, 0 },
31643 #endif
31644
31645 #define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
31646 DWORD))aSyscall[68].pCurrent)
31647
31648 #if SQLITE_OS_WINRT
31649 { "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
31650 #else
31651 { "GetTickCount64", (SYSCALL)0, 0 },
31652 #endif
31653
31654 #define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[69].pCurrent)
31655
31656 #if SQLITE_OS_WINRT
31657 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
31658 #else
31659 { "GetNativeSystemInfo", (SYSCALL)0, 0 },
31660 #endif
31661
31662 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
31663 LPSYSTEM_INFO))aSyscall[70].pCurrent)
31664
31665 #if defined(SQLITE_WIN32_HAS_ANSI)
31666 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
31667 #else
31668 { "OutputDebugStringA", (SYSCALL)0, 0 },
31669 #endif
31670
31671 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[71].pCurrent)
31672
31673 #if defined(SQLITE_WIN32_HAS_WIDE)
31674 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
31675 #else
31676 { "OutputDebugStringW", (SYSCALL)0, 0 },
31677 #endif
31678
31679 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[72].pCurrent)
31680
31681 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
31682
31683 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[73].pCurrent)
31684
31685 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
31686 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
31687 #else
31688 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
31689 #endif
31690
31691 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
31692 LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[74].pCurrent)
31693
31694 }; /* End of the overrideable system calls */
31695
31696 /*
31697 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -31826,20 +31843,30 @@
31843 ** API as long as we don't call it when running Win95/98/ME. A call to
31844 ** this routine is used to determine if the host is Win95/98/ME or
31845 ** WinNT/2K/XP so that we will know whether or not we can safely call
31846 ** the LockFileEx() API.
31847 */
31848 #ifndef NTDDI_WIN8
31849 # define NTDDI_WIN8 0x06020000
31850 #endif
31851
31852 #if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
31853 # define osIsNT() (1)
31854 #elif !defined(SQLITE_WIN32_HAS_WIDE)
31855 # define osIsNT() (0)
31856 #else
31857 static int osIsNT(void){
31858 if( sqlite3_os_type==0 ){
31859 #if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
31860 OSVERSIONINFOW sInfo;
31861 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
31862 osGetVersionExW(&sInfo);
31863 #else
31864 OSVERSIONINFOA sInfo;
31865 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
31866 osGetVersionExA(&sInfo);
31867 #endif
31868 sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
31869 }
31870 return sqlite3_os_type==2;
31871 }
31872 #endif
@@ -31860,11 +31887,11 @@
31887 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31888 #endif
31889 assert( nBytes>=0 );
31890 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
31891 if( !p ){
31892 sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%lu), heap=%p",
31893 nBytes, osGetLastError(), (void*)hHeap);
31894 }
31895 return p;
31896 }
31897
@@ -31881,11 +31908,11 @@
31908 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
31909 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
31910 #endif
31911 if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
31912 if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
31913 sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%lu), heap=%p",
31914 pPrior, osGetLastError(), (void*)hHeap);
31915 }
31916 }
31917
31918 /*
@@ -31907,11 +31934,11 @@
31934 p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
31935 }else{
31936 p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
31937 }
31938 if( !p ){
31939 sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%lu), heap=%p",
31940 pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(),
31941 (void*)hHeap);
31942 }
31943 return p;
31944 }
@@ -31931,11 +31958,11 @@
31958 assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
31959 #endif
31960 if( !p ) return 0;
31961 n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
31962 if( n==(SIZE_T)-1 ){
31963 sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%lu), heap=%p",
31964 p, osGetLastError(), (void*)hHeap);
31965 return 0;
31966 }
31967 return (int)n;
31968 }
@@ -31961,11 +31988,11 @@
31988 pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
31989 SQLITE_WIN32_HEAP_INIT_SIZE,
31990 SQLITE_WIN32_HEAP_MAX_SIZE);
31991 if( !pWinMemData->hHeap ){
31992 sqlite3_log(SQLITE_NOMEM,
31993 "failed to HeapCreate (%lu), flags=%u, initSize=%u, maxSize=%u",
31994 osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
31995 SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
31996 return SQLITE_NOMEM;
31997 }
31998 pWinMemData->bOwned = TRUE;
@@ -31973,11 +32000,11 @@
32000 }
32001 #else
32002 pWinMemData->hHeap = osGetProcessHeap();
32003 if( !pWinMemData->hHeap ){
32004 sqlite3_log(SQLITE_NOMEM,
32005 "failed to GetProcessHeap (%lu)", osGetLastError());
32006 return SQLITE_NOMEM;
32007 }
32008 pWinMemData->bOwned = FALSE;
32009 assert( !pWinMemData->bOwned );
32010 #endif
@@ -32001,11 +32028,11 @@
32028 #if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_MALLOC_VALIDATE)
32029 assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
32030 #endif
32031 if( pWinMemData->bOwned ){
32032 if( !osHeapDestroy(pWinMemData->hHeap) ){
32033 sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%lu), heap=%p",
32034 osGetLastError(), (void*)pWinMemData->hHeap);
32035 }
32036 pWinMemData->bOwned = FALSE;
32037 }
32038 pWinMemData->hHeap = NULL;
@@ -33886,26 +33913,27 @@
33913 ** by VFS shared-memory methods.
33914 */
33915 static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
33916 winShmNode **pp;
33917 winShmNode *p;
 
33918 assert( winShmMutexHeld() );
33919 OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
33920 osGetCurrentProcessId(), deleteFlag));
33921 pp = &winShmNodeList;
33922 while( (p = *pp)!=0 ){
33923 if( p->nRef==0 ){
33924 int i;
33925 if( p->mutex ) sqlite3_mutex_free(p->mutex);
33926 for(i=0; i<p->nRegion; i++){
33927 BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
33928 OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
33929 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
33930 UNUSED_VARIABLE_VALUE(bRc);
33931 bRc = osCloseHandle(p->aRegion[i].hMap);
33932 OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
33933 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
33934 UNUSED_VARIABLE_VALUE(bRc);
33935 }
33936 if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
33937 SimulateIOErrorBenign(1);
33938 winClose((sqlite3_file *)&p->hFile);
33939 SimulateIOErrorBenign(0);
@@ -34620,10 +34648,11 @@
34648 **
34649 ** This division contains the implementation of methods on the
34650 ** sqlite3_vfs object.
34651 */
34652
34653 #if 0
34654 /*
34655 ** Convert a filename from whatever the underlying operating system
34656 ** supports for filenames into UTF-8. Space to hold the result is
34657 ** obtained from malloc and must be freed by the calling function.
34658 */
@@ -34638,10 +34667,11 @@
34667 }
34668 #endif
34669 /* caller will handle out of memory */
34670 return zConverted;
34671 }
34672 #endif
34673
34674 /*
34675 ** Convert a UTF-8 filename into whatever form the underlying
34676 ** operating system wants filenames in. Space to hold the result
34677 ** is obtained from malloc and must be freed by the calling
@@ -35855,11 +35885,11 @@
35885 };
35886 #endif
35887
35888 /* Double-check that the aSyscall[] array has been constructed
35889 ** correctly. See ticket [bb3a86e890c8e96ab] */
35890 assert( ArraySize(aSyscall)==75 );
35891
35892 /* get memory map allocation granularity */
35893 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
35894 #if SQLITE_OS_WINRT
35895 osGetNativeSystemInfo(&winSysInfo);
@@ -60404,10 +60434,12 @@
60434 int iVal, /* Array element to populate */
60435 int *pbOk /* OUT: True if value was extracted */
60436 ){
60437 int rc = SQLITE_OK;
60438 sqlite3_value *pVal = 0;
60439 sqlite3 *db = pParse->db;
60440
60441
60442 struct ValueNewStat4Ctx alloc;
60443 alloc.pParse = pParse;
60444 alloc.pIdx = pIdx;
60445 alloc.ppRec = ppRec;
@@ -60415,11 +60447,11 @@
60447
60448 /* Skip over any TK_COLLATE nodes */
60449 pExpr = sqlite3ExprSkipCollate(pExpr);
60450
60451 if( !pExpr ){
60452 pVal = valueNew(db, &alloc);
60453 if( pVal ){
60454 sqlite3VdbeMemSetNull((Mem*)pVal);
60455 *pbOk = 1;
60456 }
60457 }else if( pExpr->op==TK_VARIABLE
@@ -60427,30 +60459,29 @@
60459 ){
60460 Vdbe *v;
60461 int iBindVar = pExpr->iColumn;
60462 sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
60463 if( (v = pParse->pReprepare)!=0 ){
60464 pVal = valueNew(db, &alloc);
60465 if( pVal ){
60466 rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
60467 if( rc==SQLITE_OK ){
60468 sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
60469 }
60470 pVal->db = pParse->db;
60471 *pbOk = 1;
60472 sqlite3VdbeMemStoreType((Mem*)pVal);
60473 }
60474 }else{
60475 *pbOk = 0;
60476 }
60477 }else{
 
60478 rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
60479 *pbOk = (pVal!=0);
60480 }
60481
60482 assert( pVal==0 || pVal->db==db );
60483 return rc;
60484 }
60485
60486 /*
60487 ** Unless it is NULL, the argument must be an UnpackedRecord object returned
@@ -61114,11 +61145,11 @@
61145 /*
61146 ** If the input FuncDef structure is ephemeral, then free it. If
61147 ** the FuncDef is not ephermal, then do nothing.
61148 */
61149 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
61150 if( ALWAYS(pDef) && (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
61151 sqlite3DbFree(db, pDef);
61152 }
61153 }
61154
61155 static void vdbeFreeOpArray(sqlite3 *, Op *, int);
@@ -64341,10 +64372,11 @@
64372 }
64373 rc = sqlite3ApiExit(db, rc);
64374 sqlite3_mutex_leave(db->mutex);
64375 return rc;
64376 }
64377
64378
64379 /*
64380 ** Extract the user data from a sqlite3_context structure and return a
64381 ** pointer to it.
64382 */
@@ -64365,10 +64397,23 @@
64397 */
64398 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
64399 assert( p && p->pFunc );
64400 return p->s.db;
64401 }
64402
64403 /*
64404 ** Return the current time for a statement
64405 */
64406 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
64407 Vdbe *v = p->pVdbe;
64408 int rc;
64409 if( v->iCurrentTime==0 ){
64410 rc = sqlite3OsCurrentTimeInt64(p->s.db->pVfs, &v->iCurrentTime);
64411 if( rc ) v->iCurrentTime = 0;
64412 }
64413 return v->iCurrentTime;
64414 }
64415
64416 /*
64417 ** The following is the implementation of an SQL function that always
64418 ** fails with an error message stating that the function is used in the
64419 ** wrong context. The sqlite3_overload_function() API might construct
@@ -66518,10 +66563,11 @@
66563 goto no_mem;
66564 }
66565 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
66566 assert( p->bIsReader || p->readOnly!=0 );
66567 p->rc = SQLITE_OK;
66568 p->iCurrentTime = 0;
66569 assert( p->explain==0 );
66570 p->pResultSet = 0;
66571 db->busyHandler.nBusy = 0;
66572 CHECK_FOR_INTERRUPT;
66573 sqlite3VdbeIOTraceSql(p);
@@ -67406,11 +67452,11 @@
67452 */
67453 sqlite3VdbeMemMove(&u.ai.ctx.s, pOut);
67454 MemSetTypeFlag(&u.ai.ctx.s, MEM_Null);
67455
67456 u.ai.ctx.fErrorOrAux = 0;
67457 if( u.ai.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67458 assert( pOp>aOp );
67459 assert( pOp[-1].p4type==P4_COLLSEQ );
67460 assert( pOp[-1].opcode==OP_CollSeq );
67461 u.ai.ctx.pColl = pOp[-1].p4.pColl;
67462 }
@@ -71506,11 +71552,11 @@
71552 u.cg.ctx.s.xDel = 0;
71553 u.cg.ctx.s.db = db;
71554 u.cg.ctx.isError = 0;
71555 u.cg.ctx.pColl = 0;
71556 u.cg.ctx.skipFlag = 0;
71557 if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
71558 assert( pOp>p->aOp );
71559 assert( pOp[-1].p4type==P4_COLLSEQ );
71560 assert( pOp[-1].opcode==OP_CollSeq );
71561 u.cg.ctx.pColl = pOp[-1].p4.pColl;
71562 }
@@ -74434,11 +74480,11 @@
74480 if( pExpr==0 ) return WRC_Continue;
74481 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
74482 testcase( ExprHasProperty(pExpr, EP_Reduced) );
74483 rc = pWalker->xExprCallback(pWalker, pExpr);
74484 if( rc==WRC_Continue
74485 && !ExprHasProperty(pExpr,EP_TokenOnly) ){
74486 if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
74487 if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
74488 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
74489 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
74490 }else{
@@ -74653,10 +74699,11 @@
74699 if( pDup==0 ) return;
74700 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
74701 incrAggFunctionDepth(pDup, nSubquery);
74702 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
74703 if( pDup==0 ) return;
74704 ExprSetProperty(pDup, EP_Skip);
74705 if( pEList->a[iCol].iAlias==0 ){
74706 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
74707 }
74708 pDup->iTable = pEList->a[iCol].iAlias;
74709 }
@@ -74675,11 +74722,11 @@
74722 sqlite3ExprDelete(db, pExpr);
74723 memcpy(pExpr, pDup, sizeof(*pExpr));
74724 if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
74725 assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
74726 pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
74727 pExpr->flags |= EP_MemToken;
74728 }
74729 sqlite3DbFree(db, pDup);
74730 }
74731
74732
@@ -74775,16 +74822,16 @@
74822 Schema *pSchema = 0; /* Schema of the expression */
74823 int isTrigger = 0;
74824
74825 assert( pNC ); /* the name context cannot be NULL. */
74826 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
74827 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
74828
74829 /* Initialize the node to no-match */
74830 pExpr->iTable = -1;
74831 pExpr->pTab = 0;
74832 ExprSetVVAProperty(pExpr, EP_NoReduce);
74833
74834 /* Translate the schema name in zDb into a pointer to the corresponding
74835 ** schema. If not found, pSchema will remain NULL and nothing will match
74836 ** resulting in an appropriate error message toward the end of this routine
74837 */
@@ -75116,10 +75163,23 @@
75163 }
75164 #else
75165 # define notValidCheckConstraint(P,N,M)
75166 #endif
75167
75168 /*
75169 ** Expression p should encode a floating point value between 1.0 and 0.0.
75170 ** Return 1024 times this value. Or return -1 if p is not a floating point
75171 ** value between 1.0 and 0.0.
75172 */
75173 static int exprProbability(Expr *p){
75174 double r = -1.0;
75175 if( p->op!=TK_FLOAT ) return -1;
75176 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
75177 assert( r>=0.0 );
75178 if( r>1.0 ) return -1;
75179 return (int)(r*1000.0);
75180 }
75181
75182 /*
75183 ** This routine is callback for sqlite3WalkExpr().
75184 **
75185 ** Resolve symbolic names into TK_COLUMN operators for the current
@@ -75137,11 +75197,11 @@
75197 pNC = pWalker->u.pNC;
75198 assert( pNC!=0 );
75199 pParse = pNC->pParse;
75200 assert( pParse==pWalker->pParse );
75201
75202 if( ExprHasProperty(pExpr, EP_Resolved) ) return WRC_Prune;
75203 ExprSetProperty(pExpr, EP_Resolved);
75204 #ifndef NDEBUG
75205 if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
75206 SrcList *pSrcList = pNC->pSrcList;
75207 int i;
@@ -75229,10 +75289,23 @@
75289 }else{
75290 wrong_num_args = 1;
75291 }
75292 }else{
75293 is_agg = pDef->xFunc==0;
75294 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
75295 ExprSetProperty(pExpr, EP_Unlikely|EP_Skip);
75296 if( n==2 ){
75297 pExpr->iTable = exprProbability(pList->a[1].pExpr);
75298 if( pExpr->iTable<0 ){
75299 sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a "
75300 "constant between 0.0 and 1.0");
75301 pNC->nErr++;
75302 }
75303 }else{
75304 pExpr->iTable = 62; /* TUNING: Default 2nd arg to unlikely() is 0.0625 */
75305 }
75306 }
75307 }
75308 #ifndef SQLITE_OMIT_AUTHORIZATION
75309 if( pDef ){
75310 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
75311 if( auth!=SQLITE_OK ){
@@ -76038,11 +76111,11 @@
76111 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr *pExpr, Token *pCollName){
76112 if( pCollName->n>0 ){
76113 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1);
76114 if( pNew ){
76115 pNew->pLeft = pExpr;
76116 pNew->flags |= EP_Collate|EP_Skip;
76117 pExpr = pNew;
76118 }
76119 }
76120 return pExpr;
76121 }
@@ -76053,17 +76126,25 @@
76126 s.n = sqlite3Strlen30(s.z);
76127 return sqlite3ExprAddCollateToken(pParse, pExpr, &s);
76128 }
76129
76130 /*
76131 ** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
76132 ** or likelihood() function at the root of an expression.
76133 */
76134 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
76135 while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
76136 if( ExprHasProperty(pExpr, EP_Unlikely) ){
76137 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
76138 assert( pExpr->x.pList->nExpr>0 );
76139 assert( pExpr->op==TK_FUNCTION );
76140 pExpr = pExpr->x.pList->a[0].pExpr;
76141 }else{
76142 assert( pExpr->op==TK_COLLATE || pExpr->op==TK_AS );
76143 pExpr = pExpr->pLeft;
76144 }
76145 }
76146 return pExpr;
76147 }
76148
76149 /*
76150 ** Return the collation sequence for the expression pExpr. If
@@ -76564,11 +76645,11 @@
76645 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
76646 sqlite3 *db = pParse->db;
76647 const char *z;
76648
76649 if( pExpr==0 ) return;
76650 assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
76651 z = pExpr->u.zToken;
76652 assert( z!=0 );
76653 assert( z[0]!=0 );
76654 if( z[1]==0 ){
76655 /* Wildcard of the form "?". Assign the next variable number */
@@ -76634,16 +76715,16 @@
76715 */
76716 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
76717 if( p==0 ) return;
76718 /* Sanity check: Assert that the IntValue is non-negative if it exists */
76719 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
76720 if( !ExprHasProperty(p, EP_TokenOnly) ){
76721 /* The Expr.x union is never used at the same time as Expr.pRight */
76722 assert( p->x.pList==0 || p->pRight==0 );
76723 sqlite3ExprDelete(db, p->pLeft);
76724 sqlite3ExprDelete(db, p->pRight);
76725 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
 
 
76726 if( ExprHasProperty(p, EP_xIsSelect) ){
76727 sqlite3SelectDelete(db, p->x.pSelect);
76728 }else{
76729 sqlite3ExprListDelete(db, p->x.pList);
76730 }
@@ -76699,20 +76780,23 @@
76780 ** to enforce this constraint.
76781 */
76782 static int dupedExprStructSize(Expr *p, int flags){
76783 int nSize;
76784 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
76785 assert( EXPR_FULLSIZE<=0xfff );
76786 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
76787 if( 0==(flags&EXPRDUP_REDUCE) ){
76788 nSize = EXPR_FULLSIZE;
76789 }else{
76790 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
76791 assert( !ExprHasProperty(p, EP_FromJoin) );
76792 assert( !ExprHasProperty(p, EP_MemToken) );
76793 assert( !ExprHasProperty(p, EP_NoReduce) );
76794 if( p->pLeft || p->x.pList ){
76795 nSize = EXPR_REDUCEDSIZE | EP_Reduced;
76796 }else{
76797 assert( p->pRight==0 );
76798 nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly;
76799 }
76800 }
76801 return nSize;
76802 }
@@ -76802,11 +76886,11 @@
76886 memcpy(zAlloc, p, nSize);
76887 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
76888 }
76889
76890 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
76891 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
76892 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
76893 pNew->flags |= staticFlag;
76894
76895 /* Copy the p->u.zToken string, if any. */
76896 if( nToken ){
@@ -76822,22 +76906,21 @@
76906 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
76907 }
76908 }
76909
76910 /* Fill in pNew->pLeft and pNew->pRight. */
76911 if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
76912 zAlloc += dupedExprNodeSize(p, flags);
76913 if( ExprHasProperty(pNew, EP_Reduced) ){
76914 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
76915 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
76916 }
76917 if( pzBuffer ){
76918 *pzBuffer = zAlloc;
76919 }
76920 }else{
76921 if( !ExprHasProperty(p, EP_TokenOnly) ){
 
76922 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
76923 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
76924 }
76925 }
76926
@@ -77143,11 +77226,11 @@
77226 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
77227
77228 /* If pWalker->u.i is 3 then any term of the expression that comes from
77229 ** the ON or USING clauses of a join disqualifies the expression
77230 ** from being considered constant. */
77231 if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
77232 pWalker->u.i = 0;
77233 return WRC_Abort;
77234 }
77235
77236 switch( pExpr->op ){
@@ -77574,11 +77657,11 @@
77657 *prNotFound = rMayHaveNull = ++pParse->nMem;
77658 sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
77659 }else{
77660 testcase( pParse->nQueryLoop>0 );
77661 pParse->nQueryLoop = 0;
77662 if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
77663 eType = IN_INDEX_ROWID;
77664 }
77665 }
77666 sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
77667 pParse->nQueryLoop = savedNQueryLoop;
@@ -77643,11 +77726,11 @@
77726 ** * We are inside a trigger
77727 **
77728 ** If all of the above are false, then we can run this code just once
77729 ** save the results, and reuse the same result on subsequent invocations.
77730 */
77731 if( !ExprHasProperty(pExpr, EP_VarSelect) ){
77732 testAddr = sqlite3CodeOnce(pParse);
77733 }
77734
77735 #ifndef SQLITE_OMIT_EXPLAIN
77736 if( pParse->explain==2 ){
@@ -77812,11 +77895,11 @@
77895 pSel->iLimit = 0;
77896 if( sqlite3Select(pParse, pSel, &dest) ){
77897 return 0;
77898 }
77899 rReg = dest.iSDParm;
77900 ExprSetVVAProperty(pExpr, EP_NoReduce);
77901 break;
77902 }
77903 }
77904
77905 if( testAddr>=0 ){
@@ -78283,10 +78366,20 @@
78366 if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
78367 }
78368 return 0;
78369 }
78370 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
78371
78372 /*
78373 ** Convert an expression node to a TK_REGISTER
78374 */
78375 static void exprToRegister(Expr *p, int iReg){
78376 p->op2 = p->op;
78377 p->op = TK_REGISTER;
78378 p->iTable = iReg;
78379 ExprClearProperty(p, EP_Skip);
78380 }
78381
78382 /*
78383 ** Generate code into the current Vdbe to evaluate the given
78384 ** expression. Attempt to store the results in register "target".
78385 ** Return the register where results are stored.
@@ -78583,11 +78676,11 @@
78676 CollSeq *pColl = 0; /* A collating sequence */
78677
78678 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
78679 testcase( op==TK_CONST_FUNC );
78680 testcase( op==TK_FUNCTION );
78681 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
78682 pFarg = 0;
78683 }else{
78684 pFarg = pExpr->x.pList;
78685 }
78686 nFarg = pFarg ? pFarg->nExpr : 0;
@@ -78602,11 +78695,11 @@
78695
78696 /* Attempt a direct implementation of the built-in COALESCE() and
78697 ** IFNULL() functions. This avoids unnecessary evalation of
78698 ** arguments past the first non-NULL argument.
78699 */
78700 if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
78701 int endCoalesce = sqlite3VdbeMakeLabel(v);
78702 assert( nFarg>=2 );
78703 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
78704 for(i=1; i<nFarg; i++){
78705 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
@@ -78617,29 +78710,38 @@
78710 }
78711 sqlite3VdbeResolveLabel(v, endCoalesce);
78712 break;
78713 }
78714
78715 /* The UNLIKELY() function is a no-op. The result is the value
78716 ** of the first argument.
78717 */
78718 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
78719 assert( nFarg>=1 );
78720 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
78721 break;
78722 }
78723
78724 if( pFarg ){
78725 r1 = sqlite3GetTempRange(pParse, nFarg);
78726
78727 /* For length() and typeof() functions with a column argument,
78728 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
78729 ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
78730 ** loading.
78731 */
78732 if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
78733 u8 exprOp;
78734 assert( nFarg==1 );
78735 assert( pFarg->a[0].pExpr!=0 );
78736 exprOp = pFarg->a[0].pExpr->op;
78737 if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
78738 assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
78739 assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
78740 testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK)
78741 ==SQLITE_FUNC_LENGTH );
78742 pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK;
78743 }
78744 }
78745
78746 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
78747 sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
@@ -78668,15 +78770,15 @@
78770 #endif
78771 for(i=0; i<nFarg; i++){
78772 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
78773 constMask |= (1<<i);
78774 }
78775 if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
78776 pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
78777 }
78778 }
78779 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
78780 if( !pColl ) pColl = db->pDfltColl;
78781 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
78782 }
78783 sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
78784 (char*)pDef, P4_FUNCDEF);
@@ -78813,13 +78915,13 @@
78915 ** Form A is can be transformed into the equivalent form B as follows:
78916 ** CASE WHEN x=e1 THEN r1 WHEN x=e2 THEN r2 ...
78917 ** WHEN x=eN THEN rN ELSE y END
78918 **
78919 ** X (if it exists) is in pExpr->pLeft.
78920 ** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
78921 ** odd. The Y is also optional. If the number of elements in x.pList
78922 ** is even, then Y is omitted and the "otherwise" result is NULL.
78923 ** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
78924 **
78925 ** The result of the expression is the Ri for the first matching Ei,
78926 ** or if there is no matching Ei, the ELSE term Y, or if there is
78927 ** no ELSE term, NULL.
@@ -78836,33 +78938,31 @@
78938 Expr *pX; /* The X expression */
78939 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
78940 VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
78941
78942 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
 
78943 assert(pExpr->x.pList->nExpr > 0);
78944 pEList = pExpr->x.pList;
78945 aListelem = pEList->a;
78946 nExpr = pEList->nExpr;
78947 endLabel = sqlite3VdbeMakeLabel(v);
78948 if( (pX = pExpr->pLeft)!=0 ){
78949 cacheX = *pX;
78950 testcase( pX->op==TK_COLUMN );
78951 testcase( pX->op==TK_REGISTER );
78952 exprToRegister(&cacheX, sqlite3ExprCodeTemp(pParse, pX, &regFree1));
78953 testcase( regFree1==0 );
 
78954 opCompare.op = TK_EQ;
78955 opCompare.pLeft = &cacheX;
78956 pTest = &opCompare;
78957 /* Ticket b351d95f9cd5ef17e9d9dbae18f5ca8611190001:
78958 ** The value in regFree1 might get SCopy-ed into the file result.
78959 ** So make sure that the regFree1 register is not reused for other
78960 ** purposes and possibly overwritten. */
78961 regFree1 = 0;
78962 }
78963 for(i=0; i<nExpr-1; i=i+2){
78964 sqlite3ExprCachePush(pParse);
78965 if( pX ){
78966 assert( pTest!=0 );
78967 opCompare.pRight = aListelem[i].pExpr;
78968 }else{
@@ -78876,13 +78976,13 @@
78976 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
78977 sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
78978 sqlite3ExprCachePop(pParse, 1);
78979 sqlite3VdbeResolveLabel(v, nextCase);
78980 }
78981 if( (nExpr&1)!=0 ){
78982 sqlite3ExprCachePush(pParse);
78983 sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target);
78984 sqlite3ExprCachePop(pParse, 1);
78985 }else{
78986 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
78987 }
78988 assert( db->mallocFailed || pParse->nErr>0
@@ -78990,13 +79090,11 @@
79090 ** modifications or enhancements. */
79091 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79092 int iMem;
79093 iMem = ++pParse->nMem;
79094 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79095 exprToRegister(pExpr, iMem);
 
 
79096 }
79097 return inReg;
79098 }
79099
79100 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -79122,11 +79220,11 @@
79220
79221 case TK_AGG_FUNCTION:
79222 case TK_CONST_FUNC:
79223 case TK_FUNCTION: {
79224 ExprList *pFarg; /* List of function arguments */
79225 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79226 pFarg = 0;
79227 }else{
79228 pFarg = pExpr->x.pList;
79229 }
79230 if( op==TK_AGG_FUNCTION ){
@@ -79371,13 +79469,11 @@
79469 int r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79470 /* If r2!=r1, it means that register r1 is never used. That is harmless
79471 ** but suboptimal, so we want to know about the situation to fix it.
79472 ** Hence the following assert: */
79473 assert( r2==r1 );
79474 exprToRegister(pExpr, r2);
 
 
79475 return WRC_Prune;
79476 }
79477 return WRC_Continue;
79478 }
79479
@@ -79471,13 +79567,11 @@
79567 compLeft.pLeft = &exprX;
79568 compLeft.pRight = pExpr->x.pList->a[0].pExpr;
79569 compRight.op = TK_LE;
79570 compRight.pLeft = &exprX;
79571 compRight.pRight = pExpr->x.pList->a[1].pExpr;
79572 exprToRegister(&exprX, sqlite3ExprCodeTemp(pParse, &exprX, &regFree1));
 
 
79573 if( jumpIfTrue ){
79574 sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull);
79575 }else{
79576 sqlite3ExprIfFalse(pParse, &exprAnd, dest, jumpIfNull);
79577 }
@@ -79788,12 +79882,12 @@
79882 */
79883 SQLITE_PRIVATE int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
79884 if( pA==0||pB==0 ){
79885 return pB==pA ? 0 : 2;
79886 }
79887 assert( !ExprHasProperty(pA, EP_TokenOnly|EP_Reduced) );
79888 assert( !ExprHasProperty(pB, EP_TokenOnly|EP_Reduced) );
79889 if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
79890 return 2;
79891 }
79892 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
79893 if( pA->op!=pB->op && (pA->op!=TK_REGISTER || pA->op2!=pB->op) ){
@@ -80003,11 +80097,11 @@
80097 ** clause of the aggregate query */
80098 if( ALWAYS(pSrcList!=0) ){
80099 struct SrcList_item *pItem = pSrcList->a;
80100 for(i=0; i<pSrcList->nSrc; i++, pItem++){
80101 struct AggInfo_col *pCol;
80102 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
80103 if( pExpr->iTable==pItem->iCursor ){
80104 /* If we reach this point, it means that pExpr refers to a table
80105 ** that is in the FROM clause of the aggregate query.
80106 **
80107 ** Make an entry for the column in pAggInfo->aCol[] if there
@@ -80052,11 +80146,11 @@
80146 /* There is now an entry for pExpr in pAggInfo->aCol[] (either
80147 ** because it was there before or because we just created it).
80148 ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
80149 ** pAggInfo->aCol[] entry.
80150 */
80151 ExprSetVVAProperty(pExpr, EP_NoReduce);
80152 pExpr->pAggInfo = pAggInfo;
80153 pExpr->op = TK_AGG_COLUMN;
80154 pExpr->iAgg = (i16)k;
80155 break;
80156 } /* endif pExpr->iTable==pItem->iCursor */
@@ -80098,12 +80192,12 @@
80192 }
80193 }
80194 }
80195 /* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
80196 */
80197 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
80198 ExprSetVVAProperty(pExpr, EP_NoReduce);
80199 pExpr->iAgg = (i16)i;
80200 pExpr->pAggInfo = pAggInfo;
80201 return WRC_Prune;
80202 }else{
80203 return WRC_Continue;
@@ -81394,11 +81488,11 @@
81488
81489 p->iGet = -1;
81490 p->mxSample = mxSample;
81491 p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[1])/(mxSample/3+1) + 1);
81492 p->current.anLt = &p->current.anEq[nColUp];
81493 p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[1])*0xd0944565;
81494
81495 /* Set up the Stat4Accum.a[] and aBest[] arrays */
81496 p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
81497 p->aBest = &p->a[mxSample];
81498 pSpace = (u8*)(&p->a[mxSample+nCol]);
@@ -81418,12 +81512,11 @@
81512 /* Return a pointer to the allocated object to the caller */
81513 sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
81514 }
81515 static const FuncDef statInitFuncdef = {
81516 1+IsStat34, /* nArg */
81517 SQLITE_UTF8, /* funcFlags */
 
81518 0, /* pUserData */
81519 0, /* pNext */
81520 statInit, /* xFunc */
81521 0, /* xStep */
81522 0, /* xFinalize */
@@ -81715,12 +81808,11 @@
81808 }
81809 #endif
81810 }
81811 static const FuncDef statPushFuncdef = {
81812 2+IsStat34, /* nArg */
81813 SQLITE_UTF8, /* funcFlags */
 
81814 0, /* pUserData */
81815 0, /* pNext */
81816 statPush, /* xFunc */
81817 0, /* xStep */
81818 0, /* xFinalize */
@@ -81851,12 +81943,11 @@
81943 }
81944 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
81945 }
81946 static const FuncDef statGetFuncdef = {
81947 1+IsStat34, /* nArg */
81948 SQLITE_UTF8, /* funcFlags */
 
81949 0, /* pUserData */
81950 0, /* pNext */
81951 statGet, /* xFunc */
81952 0, /* xStep */
81953 0, /* xFinalize */
@@ -83056,12 +83147,11 @@
83147 ** DETACH pDbname
83148 */
83149 SQLITE_PRIVATE void sqlite3Detach(Parse *pParse, Expr *pDbname){
83150 static const FuncDef detach_func = {
83151 1, /* nArg */
83152 SQLITE_UTF8, /* funcFlags */
 
83153 0, /* pUserData */
83154 0, /* pNext */
83155 detachFunc, /* xFunc */
83156 0, /* xStep */
83157 0, /* xFinalize */
@@ -83078,12 +83168,11 @@
83168 ** ATTACH p AS pDbname KEY pKey
83169 */
83170 SQLITE_PRIVATE void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
83171 static const FuncDef attach_func = {
83172 3, /* nArg */
83173 SQLITE_UTF8, /* funcFlags */
 
83174 0, /* pUserData */
83175 0, /* pNext */
83176 attachFunc, /* xFunc */
83177 0, /* xStep */
83178 0, /* xFinalize */
@@ -83188,11 +83277,11 @@
83277 SQLITE_PRIVATE int sqlite3FixExpr(
83278 DbFixer *pFix, /* Context of the fixation */
83279 Expr *pExpr /* The expression to be fixed to one database */
83280 ){
83281 while( pExpr ){
83282 if( ExprHasProperty(pExpr, EP_TokenOnly) ) break;
83283 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
83284 if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1;
83285 }else{
83286 if( sqlite3FixExprList(pFix, pExpr->x.pList) ) return 1;
83287 }
@@ -87589,13 +87678,13 @@
87678 }else{
87679 match = 1;
87680 }
87681
87682 /* Bonus points if the text encoding matches */
87683 if( enc==(p->funcFlags & SQLITE_FUNC_ENCMASK) ){
87684 match += 2; /* Exact encoding match */
87685 }else if( (enc & p->funcFlags & 2)!=0 ){
87686 match += 1; /* Both are UTF16, but with different byte orders */
87687 }
87688
87689 return match;
87690 }
@@ -87725,11 +87814,11 @@
87814 */
87815 if( createFlag && bestScore<FUNC_PERFECT_MATCH &&
87816 (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
87817 pBest->zName = (char *)&pBest[1];
87818 pBest->nArg = (u16)nArg;
87819 pBest->funcFlags = enc;
87820 memcpy(pBest->zName, zName, nName);
87821 pBest->zName[nName] = 0;
87822 sqlite3FuncDefInsert(&db->aFunc, pBest);
87823 }
87824
@@ -88335,11 +88424,11 @@
88424 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
88425
88426 /* Do FK processing. This call checks that any FK constraints that
88427 ** refer to this table (i.e. constraints attached to other tables)
88428 ** are not violated by deleting this row. */
88429 sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
88430 }
88431
88432 /* Delete the index and table entries. Skip this step if pTab is really
88433 ** a view (in which case the only effect of the DELETE statement is to
88434 ** fire the INSTEAD OF triggers). */
@@ -88352,11 +88441,11 @@
88441 }
88442
88443 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
88444 ** handle rows (possibly in other tables) that refer via a foreign key
88445 ** to the row just deleted. */
88446 sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
88447
88448 /* Invoke AFTER DELETE trigger programs. */
88449 sqlite3CodeRowTrigger(pParse, pTrigger,
88450 TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
88451 );
@@ -88891,18 +88980,18 @@
88980 }
88981 }
88982 }
88983
88984 /*
88985 ** Some functions like COALESCE() and IFNULL() and UNLIKELY() are implemented
88986 ** as VDBE code so that unused argument values do not have to be computed.
88987 ** However, we still need some kind of function implementation for this
88988 ** routines in the function table. The noopFunc macro provides this.
88989 ** noopFunc will never be called so it doesn't matter what the implementation
88990 ** is. We might as well use the "version()" function as a substitute.
88991 */
88992 #define noopFunc versionFunc /* Substitute function - never called */
88993
88994 /*
88995 ** Implementation of random(). Return a random integer.
88996 */
88997 static void randomFunc(
@@ -89017,13 +89106,13 @@
89106 ** able to participate in upper-case-to-lower-case mappings in EBCDIC
89107 ** whereas only characters less than 0x80 do in ASCII.
89108 */
89109 #if defined(SQLITE_EBCDIC)
89110 # define sqlite3Utf8Read(A) (*((*A)++))
89111 # define GlobUpperToLower(A) A = sqlite3UpperToLower[A]
89112 #else
89113 # define GlobUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
89114 #endif
89115
89116 static const struct compareInfo globInfo = { '*', '?', '[', 0 };
89117 /* The correct SQL-92 behavior is for the LIKE operator to ignore
89118 ** case. Thus 'a' LIKE 'A' would be true. */
@@ -89098,15 +89187,15 @@
89187 }
89188 return *zString!=0;
89189 }
89190 while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
89191 if( noCase ){
89192 GlobUpperToLower(c2);
89193 GlobUpperToLower(c);
89194 while( c2 != 0 && c2 != c ){
89195 c2 = sqlite3Utf8Read(&zString);
89196 GlobUpperToLower(c2);
89197 }
89198 }else{
89199 while( c2 != 0 && c2 != c ){
89200 c2 = sqlite3Utf8Read(&zString);
89201 }
@@ -89154,12 +89243,12 @@
89243 }else if( esc==c && !prevEscape ){
89244 prevEscape = 1;
89245 }else{
89246 c2 = sqlite3Utf8Read(&zString);
89247 if( noCase ){
89248 GlobUpperToLower(c);
89249 GlobUpperToLower(c2);
89250 }
89251 if( c!=c2 ){
89252 return 0;
89253 }
89254 prevEscape = 0;
@@ -90027,11 +90116,11 @@
90116 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
90117 FuncDef *pDef;
90118 pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
90119 2, SQLITE_UTF8, 0);
90120 if( ALWAYS(pDef) ){
90121 pDef->funcFlags |= flagVal;
90122 }
90123 }
90124
90125 /*
90126 ** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -90071,11 +90160,11 @@
90160 }
90161 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
90162 pDef = sqlite3FindFunction(db, pExpr->u.zToken,
90163 sqlite3Strlen30(pExpr->u.zToken),
90164 2, SQLITE_UTF8, 0);
90165 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
90166 return 0;
90167 }
90168
90169 /* The memcpy() statement assumes that the wildcard characters are
90170 ** the first three statements in the compareInfo structure. The
@@ -90083,11 +90172,11 @@
90172 */
90173 memcpy(aWc, pDef->pUserData, 3);
90174 assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
90175 assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
90176 assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
90177 *pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
90178 return 1;
90179 }
90180
90181 /*
90182 ** All all of the FuncDef structures in the aBuiltinFunc[] array above
@@ -90132,13 +90221,15 @@
90221 #endif
90222 FUNCTION(upper, 1, 0, 0, upperFunc ),
90223 FUNCTION(lower, 1, 0, 0, lowerFunc ),
90224 FUNCTION(coalesce, 1, 0, 0, 0 ),
90225 FUNCTION(coalesce, 0, 0, 0, 0 ),
90226 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
90227 FUNCTION(hex, 1, 0, 0, hexFunc ),
90228 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
90229 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
90230 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
90231 FUNCTION(random, 0, 0, 0, randomFunc ),
90232 FUNCTION(randomblob, 1, 0, 0, randomBlob ),
90233 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
90234 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
90235 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
@@ -90162,11 +90253,11 @@
90253 #endif
90254 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
90255 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
90256 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
90257 /* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
90258 {0,SQLITE_UTF8|SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
90259 AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
90260 AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
90261 AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
90262
90263 LIKEFUNC(glob, 2, &globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
@@ -90878,10 +90969,74 @@
90969 sqlite3VdbeResolveLabel(v, iSkip);
90970 }
90971 }
90972 }
90973
90974
90975 /*
90976 ** The second argument points to an FKey object representing a foreign key
90977 ** for which pTab is the child table. An UPDATE statement against pTab
90978 ** is currently being processed. For each column of the table that is
90979 ** actually updated, the corresponding element in the aChange[] array
90980 ** is zero or greater (if a column is unmodified the corresponding element
90981 ** is set to -1). If the rowid column is modified by the UPDATE statement
90982 ** the bChngRowid argument is non-zero.
90983 **
90984 ** This function returns true if any of the columns that are part of the
90985 ** child key for FK constraint *p are modified.
90986 */
90987 static int fkChildIsModified(
90988 Table *pTab, /* Table being updated */
90989 FKey *p, /* Foreign key for which pTab is the child */
90990 int *aChange, /* Array indicating modified columns */
90991 int bChngRowid /* True if rowid is modified by this update */
90992 ){
90993 int i;
90994 for(i=0; i<p->nCol; i++){
90995 int iChildKey = p->aCol[i].iFrom;
90996 if( aChange[iChildKey]>=0 ) return 1;
90997 if( iChildKey==pTab->iPKey && bChngRowid ) return 1;
90998 }
90999 return 0;
91000 }
91001
91002 /*
91003 ** The second argument points to an FKey object representing a foreign key
91004 ** for which pTab is the parent table. An UPDATE statement against pTab
91005 ** is currently being processed. For each column of the table that is
91006 ** actually updated, the corresponding element in the aChange[] array
91007 ** is zero or greater (if a column is unmodified the corresponding element
91008 ** is set to -1). If the rowid column is modified by the UPDATE statement
91009 ** the bChngRowid argument is non-zero.
91010 **
91011 ** This function returns true if any of the columns that are part of the
91012 ** parent key for FK constraint *p are modified.
91013 */
91014 static int fkParentIsModified(
91015 Table *pTab,
91016 FKey *p,
91017 int *aChange,
91018 int bChngRowid
91019 ){
91020 int i;
91021 for(i=0; i<p->nCol; i++){
91022 char *zKey = p->aCol[i].zCol;
91023 int iKey;
91024 for(iKey=0; iKey<pTab->nCol; iKey++){
91025 if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
91026 Column *pCol = &pTab->aCol[iKey];
91027 if( zKey ){
91028 if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
91029 }else if( pCol->colFlags & COLFLAG_PRIMKEY ){
91030 return 1;
91031 }
91032 }
91033 }
91034 }
91035 return 0;
91036 }
91037
91038 /*
91039 ** This function is called when inserting, deleting or updating a row of
91040 ** table pTab to generate VDBE code to perform foreign key constraint
91041 ** processing for the operation.
91042 **
@@ -90902,11 +91057,13 @@
91057 */
91058 SQLITE_PRIVATE void sqlite3FkCheck(
91059 Parse *pParse, /* Parse context */
91060 Table *pTab, /* Row is being deleted from this table */
91061 int regOld, /* Previous row data is stored here */
91062 int regNew, /* New row data is stored here */
91063 int *aChange, /* Array indicating UPDATEd columns (or 0) */
91064 int bChngRowid /* True if rowid is UPDATEd */
91065 ){
91066 sqlite3 *db = pParse->db; /* Database handle */
91067 FKey *pFKey; /* Used to iterate through FKs */
91068 int iDb; /* Index of database containing pTab */
91069 const char *zDb; /* Name of database containing pTab */
@@ -90929,10 +91086,17 @@
91086 int *aiFree = 0;
91087 int *aiCol;
91088 int iCol;
91089 int i;
91090 int isIgnore = 0;
91091
91092 if( aChange
91093 && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
91094 && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
91095 ){
91096 continue;
91097 }
91098
91099 /* Find the parent table of this foreign key. Also find a unique index
91100 ** on the parent key columns in the parent table. If either of these
91101 ** schema items cannot be located, set an error in pParse and return
91102 ** early. */
@@ -91011,10 +91175,14 @@
91175 /* Loop through all the foreign key constraints that refer to this table */
91176 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
91177 Index *pIdx = 0; /* Foreign key index for pFKey */
91178 SrcList *pSrc;
91179 int *aiCol = 0;
91180
91181 if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
91182 continue;
91183 }
91184
91185 if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
91186 && !pParse->pToplevel && !pParse->isMultiWrite
91187 ){
91188 assert( regOld==0 && regNew!=0 );
@@ -91084,10 +91252,11 @@
91252 }
91253 }
91254 }
91255 return mask;
91256 }
91257
91258
91259 /*
91260 ** This function is called before generating code to update or delete a
91261 ** row contained in table pTab. If the operation is a DELETE, then
91262 ** parameter aChange is passed a NULL value. For an UPDATE, aChange points
@@ -91114,36 +91283,20 @@
91283 ** foreign key constraint. */
91284 return (sqlite3FkReferences(pTab) || pTab->pFKey);
91285 }else{
91286 /* This is an UPDATE. Foreign key processing is only required if the
91287 ** operation modifies one or more child or parent key columns. */
 
91288 FKey *p;
91289
91290 /* Check if any child key columns are being modified. */
91291 for(p=pTab->pFKey; p; p=p->pNextFrom){
91292 if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
 
 
 
 
91293 }
91294
91295 /* Check if any parent key columns are being modified. */
91296 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
91297 if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
 
 
 
 
 
 
 
 
 
 
 
91298 }
91299 }
91300 }
91301 return 0;
91302 }
@@ -91365,22 +91518,26 @@
91518 */
91519 SQLITE_PRIVATE void sqlite3FkActions(
91520 Parse *pParse, /* Parse context */
91521 Table *pTab, /* Table being updated or deleted from */
91522 ExprList *pChanges, /* Change-list for UPDATE, NULL for DELETE */
91523 int regOld, /* Address of array containing old row */
91524 int *aChange, /* Array indicating UPDATEd columns (or 0) */
91525 int bChngRowid /* True if rowid is UPDATEd */
91526 ){
91527 /* If foreign-key support is enabled, iterate through all FKs that
91528 ** refer to table pTab. If there is an action associated with the FK
91529 ** for this operation (either update or delete), invoke the associated
91530 ** trigger sub-program. */
91531 if( pParse->db->flags&SQLITE_ForeignKeys ){
91532 FKey *pFKey; /* Iterator variable */
91533 for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
91534 if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
91535 Trigger *pAct = fkActionTrigger(pParse, pTab, pFKey, pChanges);
91536 if( pAct ){
91537 sqlite3CodeRowTriggerDirect(pParse, pAct, pTab, regOld, OE_Abort, 0);
91538 }
91539 }
91540 }
91541 }
91542 }
91543
@@ -92461,11 +92618,11 @@
92618 {
92619 int isReplace; /* Set to true if constraints may cause a replace */
92620 sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
92621 keyColumn>=0, 0, onError, endOfLoop, &isReplace
92622 );
92623 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
92624 sqlite3CompleteInsertion(
92625 pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
92626 );
92627 }
92628 }
@@ -94762,10 +94919,239 @@
94919 **
94920 *************************************************************************
94921 ** This file contains code used to implement the PRAGMA command.
94922 */
94923
94924 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
94925 # if defined(__APPLE__)
94926 # define SQLITE_ENABLE_LOCKING_STYLE 1
94927 # else
94928 # define SQLITE_ENABLE_LOCKING_STYLE 0
94929 # endif
94930 #endif
94931
94932 /***************************************************************************
94933 ** The next block of code, including the PragTyp_XXXX macro definitions and
94934 ** the aPragmaName[] object is composed of generated code. DO NOT EDIT.
94935 **
94936 ** To add new pragmas, edit the code in ../tool/mkpragmatab.tcl and rerun
94937 ** that script. Then copy/paste the output in place of the following:
94938 */
94939 #define PragTyp_HEADER_VALUE 0
94940 #define PragTyp_AUTO_VACUUM 1
94941 #define PragTyp_FLAG 2
94942 #define PragTyp_BUSY_TIMEOUT 3
94943 #define PragTyp_CACHE_SIZE 4
94944 #define PragTyp_CASE_SENSITIVE_LIKE 5
94945 #define PragTyp_COLLATION_LIST 6
94946 #define PragTyp_COMPILE_OPTIONS 7
94947 #define PragTyp_DATA_STORE_DIRECTORY 8
94948 #define PragTyp_DATABASE_LIST 9
94949 #define PragTyp_DEFAULT_CACHE_SIZE 10
94950 #define PragTyp_ENCODING 11
94951 #define PragTyp_FOREIGN_KEY_CHECK 12
94952 #define PragTyp_FOREIGN_KEY_LIST 13
94953 #define PragTyp_INCREMENTAL_VACUUM 14
94954 #define PragTyp_INDEX_INFO 15
94955 #define PragTyp_INDEX_LIST 16
94956 #define PragTyp_INTEGRITY_CHECK 17
94957 #define PragTyp_JOURNAL_MODE 18
94958 #define PragTyp_JOURNAL_SIZE_LIMIT 19
94959 #define PragTyp_LOCK_PROXY_FILE 20
94960 #define PragTyp_LOCKING_MODE 21
94961 #define PragTyp_PAGE_COUNT 22
94962 #define PragTyp_MMAP_SIZE 23
94963 #define PragTyp_PAGE_SIZE 24
94964 #define PragTyp_SECURE_DELETE 25
94965 #define PragTyp_SHRINK_MEMORY 26
94966 #define PragTyp_SOFT_HEAP_LIMIT 27
94967 #define PragTyp_SYNCHRONOUS 28
94968 #define PragTyp_TABLE_INFO 29
94969 #define PragTyp_TEMP_STORE 30
94970 #define PragTyp_TEMP_STORE_DIRECTORY 31
94971 #define PragTyp_WAL_AUTOCHECKPOINT 32
94972 #define PragTyp_WAL_CHECKPOINT 33
94973 #define PragTyp_ACTIVATE_EXTENSIONS 34
94974 #define PragTyp_HEXKEY 35
94975 #define PragTyp_KEY 36
94976 #define PragTyp_REKEY 37
94977 #define PragTyp_LOCK_STATUS 38
94978 #define PragTyp_PARSER_TRACE 39
94979 static const struct sPragmaNames {
94980 const char *const zName; /* Name of pragma */
94981 u8 ePragTyp; /* PragTyp_XXX value */
94982 u32 iArg; /* Extra argument */
94983 } aPragmaNames[] = {
94984 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
94985 { "activate_extensions", PragTyp_ACTIVATE_EXTENSIONS, 0 },
94986 #endif
94987 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
94988 { "application_id", PragTyp_HEADER_VALUE, 0 },
94989 #endif
94990 #if !defined(SQLITE_OMIT_AUTOVACUUM)
94991 { "auto_vacuum", PragTyp_AUTO_VACUUM, 0 },
94992 #endif
94993 #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
94994 { "automatic_index", PragTyp_FLAG,
94995 SQLITE_AutoIndex },
94996 #endif
94997 { "busy_timeout", PragTyp_BUSY_TIMEOUT, 0 },
94998 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
94999 { "cache_size", PragTyp_CACHE_SIZE, 0 },
95000 #endif
95001 { "cache_spill", PragTyp_FLAG,
95002 SQLITE_CacheSpill },
95003 { "case_sensitive_like", PragTyp_CASE_SENSITIVE_LIKE, 0 },
95004 { "checkpoint_fullfsync", PragTyp_FLAG,
95005 SQLITE_CkptFullFSync },
95006 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95007 { "collation_list", PragTyp_COLLATION_LIST, 0 },
95008 #endif
95009 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
95010 { "compile_options", PragTyp_COMPILE_OPTIONS, 0 },
95011 #endif
95012 { "count_changes", PragTyp_FLAG,
95013 SQLITE_CountRows },
95014 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
95015 { "data_store_directory", PragTyp_DATA_STORE_DIRECTORY, 0 },
95016 #endif
95017 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95018 { "database_list", PragTyp_DATABASE_LIST, 0 },
95019 #endif
95020 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
95021 { "default_cache_size", PragTyp_DEFAULT_CACHE_SIZE, 0 },
95022 #endif
95023 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95024 { "defer_foreign_keys", PragTyp_FLAG,
95025 SQLITE_DeferFKs },
95026 #endif
95027 { "empty_result_callbacks", PragTyp_FLAG,
95028 SQLITE_NullCallback },
95029 #if !defined(SQLITE_OMIT_UTF16)
95030 { "encoding", PragTyp_ENCODING, 0 },
95031 #endif
95032 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95033 { "foreign_key_check", PragTyp_FOREIGN_KEY_CHECK, 0 },
95034 #endif
95035 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
95036 { "foreign_key_list", PragTyp_FOREIGN_KEY_LIST, 0 },
95037 #endif
95038 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
95039 { "foreign_keys", PragTyp_FLAG,
95040 SQLITE_ForeignKeys },
95041 #endif
95042 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95043 { "freelist_count", PragTyp_HEADER_VALUE, 0 },
95044 #endif
95045 { "full_column_names", PragTyp_FLAG,
95046 SQLITE_FullColNames },
95047 { "fullfsync", PragTyp_FLAG,
95048 SQLITE_FullFSync },
95049 #if defined(SQLITE_HAS_CODEC)
95050 { "hexkey", PragTyp_HEXKEY, 0 },
95051 #endif
95052 #if !defined(SQLITE_OMIT_CHECK)
95053 { "ignore_check_constraints", PragTyp_FLAG,
95054 SQLITE_IgnoreChecks },
95055 #endif
95056 #if !defined(SQLITE_OMIT_AUTOVACUUM)
95057 { "incremental_vacuum", PragTyp_INCREMENTAL_VACUUM, 0 },
95058 #endif
95059 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95060 { "index_info", PragTyp_INDEX_INFO, 0 },
95061 { "index_list", PragTyp_INDEX_LIST, 0 },
95062 #endif
95063 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
95064 { "integrity_check", PragTyp_INTEGRITY_CHECK, 0 },
95065 #endif
95066 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95067 { "journal_mode", PragTyp_JOURNAL_MODE, 0 },
95068 { "journal_size_limit", PragTyp_JOURNAL_SIZE_LIMIT, 0 },
95069 #endif
95070 #if defined(SQLITE_HAS_CODEC)
95071 { "key", PragTyp_KEY, 0 },
95072 #endif
95073 { "legacy_file_format", PragTyp_FLAG,
95074 SQLITE_LegacyFileFmt },
95075 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
95076 { "lock_proxy_file", PragTyp_LOCK_PROXY_FILE, 0 },
95077 #endif
95078 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
95079 { "lock_status", PragTyp_LOCK_STATUS, 0 },
95080 #endif
95081 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95082 { "locking_mode", PragTyp_LOCKING_MODE, 0 },
95083 { "max_page_count", PragTyp_PAGE_COUNT, 0 },
95084 { "mmap_size", PragTyp_MMAP_SIZE, 0 },
95085 { "page_count", PragTyp_PAGE_COUNT, 0 },
95086 { "page_size", PragTyp_PAGE_SIZE, 0 },
95087 #endif
95088 #if defined(SQLITE_DEBUG)
95089 { "parser_trace", PragTyp_PARSER_TRACE, 0 },
95090 #endif
95091 { "query_only", PragTyp_FLAG,
95092 SQLITE_QueryOnly },
95093 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
95094 { "quick_check", PragTyp_INTEGRITY_CHECK, 0 },
95095 #endif
95096 { "read_uncommitted", PragTyp_FLAG,
95097 SQLITE_ReadUncommitted },
95098 { "recursive_triggers", PragTyp_FLAG,
95099 SQLITE_RecTriggers },
95100 #if defined(SQLITE_HAS_CODEC)
95101 { "rekey", PragTyp_REKEY, 0 },
95102 #endif
95103 { "reverse_unordered_selects", PragTyp_FLAG,
95104 SQLITE_ReverseOrder },
95105 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95106 { "schema_version", PragTyp_HEADER_VALUE, 0 },
95107 #endif
95108 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95109 { "secure_delete", PragTyp_SECURE_DELETE, 0 },
95110 #endif
95111 { "short_column_names", PragTyp_FLAG,
95112 SQLITE_ShortColNames },
95113 { "shrink_memory", PragTyp_SHRINK_MEMORY, 0 },
95114 { "soft_heap_limit", PragTyp_SOFT_HEAP_LIMIT, 0 },
95115 #if defined(SQLITE_DEBUG)
95116 { "sql_trace", PragTyp_FLAG,
95117 SQLITE_SqlTrace },
95118 #endif
95119 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95120 { "synchronous", PragTyp_SYNCHRONOUS, 0 },
95121 #endif
95122 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
95123 { "table_info", PragTyp_TABLE_INFO, 0 },
95124 #endif
95125 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95126 { "temp_store", PragTyp_TEMP_STORE, 0 },
95127 { "temp_store_directory", PragTyp_TEMP_STORE_DIRECTORY, 0 },
95128 #endif
95129 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
95130 { "user_version", PragTyp_HEADER_VALUE, 0 },
95131 #endif
95132 #if defined(SQLITE_DEBUG)
95133 { "vdbe_addoptrace", PragTyp_FLAG,
95134 SQLITE_VdbeAddopTrace },
95135 { "vdbe_debug", PragTyp_FLAG,
95136 SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
95137 { "vdbe_listing", PragTyp_FLAG,
95138 SQLITE_VdbeListing },
95139 { "vdbe_trace", PragTyp_FLAG,
95140 SQLITE_VdbeTrace },
95141 #endif
95142 #if !defined(SQLITE_OMIT_WAL)
95143 { "wal_autocheckpoint", PragTyp_WAL_AUTOCHECKPOINT, 0 },
95144 { "wal_checkpoint", PragTyp_WAL_CHECKPOINT, 0 },
95145 #endif
95146 { "writable_schema", PragTyp_FLAG,
95147 SQLITE_WriteSchema|SQLITE_RecoveryMode },
95148 };
95149 /* Number of pragmas: 55 on by default, 66 total. */
95150 /* End of the automatically generated pragma table.
95151 ***************************************************************************/
95152
95153 /*
95154 ** Interpret the given string as a safety level. Return 0 for OFF,
95155 ** 1 for ON or NORMAL and 2 for FULL. Return 1 for an empty or
95156 ** unrecognized string argument. The FULL option is disallowed
95157 ** if the omitFull parameter it 1.
@@ -94937,101 +95323,10 @@
95323 #else
95324 # define setAllPagerFlags(X) /* no-op */
95325 #endif
95326
95327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95328 /*
95329 ** Return a human-readable name for a constraint resolution action.
95330 */
95331 #ifndef SQLITE_OMIT_FOREIGN_KEY
95332 static const char *actionName(u8 action){
@@ -95097,12 +95392,13 @@
95392 ){
95393 char *zLeft = 0; /* Nul-terminated UTF-8 string <id> */
95394 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
95395 const char *zDb = 0; /* The database name */
95396 Token *pId; /* Pointer to <id> token */
 
95397 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
95398 int iDb; /* Database index for <database> */
95399 int lwr, upr, mid; /* Binary search bounds */
95400 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
95401 sqlite3 *db = pParse->db; /* The database connection */
95402 Db *pDb; /* The specific database being pragmaed */
95403 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
95404
@@ -95154,20 +95450,40 @@
95450 sqlite3VdbeSetNumCols(v, 1);
95451 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
95452 sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1);
95453 sqlite3_free(aFcntl[0]);
95454 }
95455 goto pragma_out;
95456 }
95457 if( rc!=SQLITE_NOTFOUND ){
95458 if( aFcntl[0] ){
95459 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
95460 sqlite3_free(aFcntl[0]);
95461 }
95462 pParse->nErr++;
95463 pParse->rc = rc;
95464 goto pragma_out;
95465 }
95466
95467 /* Locate the pragma in the lookup table */
95468 lwr = 0;
95469 upr = ArraySize(aPragmaNames)-1;
95470 while( lwr<=upr ){
95471 mid = (lwr+upr)/2;
95472 rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName);
95473 if( rc==0 ) break;
95474 if( rc<0 ){
95475 upr = mid - 1;
95476 }else{
95477 lwr = mid + 1;
95478 }
95479 }
95480 if( lwr>upr ) goto pragma_out;
95481
95482 /* Jump to the appropriate pragma handler */
95483 switch( aPragmaNames[mid].ePragTyp ){
95484
95485 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
95486 /*
95487 ** PRAGMA [database.]default_cache_size
95488 ** PRAGMA [database.]default_cache_size=N
95489 **
@@ -95181,11 +95497,11 @@
95497 ** negative number to indicate synchronous=OFF. These days, synchronous
95498 ** is always on by default regardless of the sign of the default cache
95499 ** size. But continue to take the absolute value of the default cache
95500 ** size of historical compatibility.
95501 */
95502 case PragTyp_DEFAULT_CACHE_SIZE: {
95503 static const VdbeOpList getCacheSize[] = {
95504 { OP_Transaction, 0, 0, 0}, /* 0 */
95505 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
95506 { OP_IfPos, 1, 8, 0},
95507 { OP_Integer, 0, 2, 0},
@@ -95213,11 +95529,12 @@
95529 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
95530 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95531 pDb->pSchema->cache_size = size;
95532 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
95533 }
95534 break;
95535 }
95536 #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
95537
95538 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
95539 /*
95540 ** PRAGMA [database.]page_size
@@ -95226,11 +95543,11 @@
95543 ** The first form reports the current setting for the
95544 ** database page size in bytes. The second form sets the
95545 ** database page size value. The value can only be set if
95546 ** the database has not yet been created.
95547 */
95548 case PragTyp_PAGE_SIZE: {
95549 Btree *pBt = pDb->pBt;
95550 assert( pBt!=0 );
95551 if( !zRight ){
95552 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
95553 returnSingleInt(pParse, "page_size", size);
@@ -95241,21 +95558,22 @@
95558 db->nextPagesize = sqlite3Atoi(zRight);
95559 if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
95560 db->mallocFailed = 1;
95561 }
95562 }
95563 break;
95564 }
95565
95566 /*
95567 ** PRAGMA [database.]secure_delete
95568 ** PRAGMA [database.]secure_delete=ON/OFF
95569 **
95570 ** The first form reports the current setting for the
95571 ** secure_delete flag. The second form changes the secure_delete
95572 ** flag setting and reports thenew value.
95573 */
95574 case PragTyp_SECURE_DELETE: {
95575 Btree *pBt = pDb->pBt;
95576 int b = -1;
95577 assert( pBt!=0 );
95578 if( zRight ){
95579 b = sqlite3GetBoolean(zRight, 0);
@@ -95266,11 +95584,12 @@
95584 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
95585 }
95586 }
95587 b = sqlite3BtreeSecureDelete(pBt, b);
95588 returnSingleInt(pParse, "secure_delete", b);
95589 break;
95590 }
95591
95592 /*
95593 ** PRAGMA [database.]max_page_count
95594 ** PRAGMA [database.]max_page_count=N
95595 **
@@ -95285,13 +95604,11 @@
95604 **
95605 ** PRAGMA [database.]page_count
95606 **
95607 ** Return the number of pages in the specified database.
95608 */
95609 case PragTyp_PAGE_COUNT: {
 
 
95610 int iReg;
95611 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95612 sqlite3CodeVerifySchema(pParse, iDb);
95613 iReg = ++pParse->nMem;
95614 if( sqlite3Tolower(zLeft[0])=='p' ){
@@ -95301,17 +95618,18 @@
95618 sqlite3AbsInt32(sqlite3Atoi(zRight)));
95619 }
95620 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
95621 sqlite3VdbeSetNumCols(v, 1);
95622 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
95623 break;
95624 }
95625
95626 /*
95627 ** PRAGMA [database.]locking_mode
95628 ** PRAGMA [database.]locking_mode = (normal|exclusive)
95629 */
95630 case PragTyp_LOCKING_MODE: {
95631 const char *zRet = "normal";
95632 int eMode = getLockingMode(zRight);
95633
95634 if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
95635 /* Simple "PRAGMA locking_mode;" statement. This is a query for
@@ -95340,26 +95658,28 @@
95658 }
95659 pPager = sqlite3BtreePager(pDb->pBt);
95660 eMode = sqlite3PagerLockingMode(pPager, eMode);
95661 }
95662
95663 assert( eMode==PAGER_LOCKINGMODE_NORMAL
95664 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
95665 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
95666 zRet = "exclusive";
95667 }
95668 sqlite3VdbeSetNumCols(v, 1);
95669 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
95670 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
95671 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
95672 break;
95673 }
95674
95675 /*
95676 ** PRAGMA [database.]journal_mode
95677 ** PRAGMA [database.]journal_mode =
95678 ** (delete|persist|off|truncate|memory|wal|off)
95679 */
95680 case PragTyp_JOURNAL_MODE: {
95681 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
95682 int ii; /* Loop counter */
95683
95684 /* Force the schema to be loaded on all databases. This causes all
95685 ** database files to be opened and the journal_modes set. This is
@@ -95398,28 +95718,30 @@
95718 sqlite3VdbeUsesBtree(v, ii);
95719 sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
95720 }
95721 }
95722 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
95723 break;
95724 }
95725
95726 /*
95727 ** PRAGMA [database.]journal_size_limit
95728 ** PRAGMA [database.]journal_size_limit=N
95729 **
95730 ** Get or set the size limit on rollback journal files.
95731 */
95732 case PragTyp_JOURNAL_SIZE_LIMIT: {
95733 Pager *pPager = sqlite3BtreePager(pDb->pBt);
95734 i64 iLimit = -2;
95735 if( zRight ){
95736 sqlite3Atoi64(zRight, &iLimit, sqlite3Strlen30(zRight), SQLITE_UTF8);
95737 if( iLimit<-1 ) iLimit = -1;
95738 }
95739 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
95740 returnSingleInt(pParse, "journal_size_limit", iLimit);
95741 break;
95742 }
95743
95744 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
95745
95746 /*
95747 ** PRAGMA [database.]auto_vacuum
@@ -95427,11 +95749,11 @@
95749 **
95750 ** Get or set the value of the database 'auto-vacuum' parameter.
95751 ** The value is one of: 0 NONE 1 FULL 2 INCREMENTAL
95752 */
95753 #ifndef SQLITE_OMIT_AUTOVACUUM
95754 case PragTyp_AUTO_VACUUM: {
95755 Btree *pBt = pDb->pBt;
95756 assert( pBt!=0 );
95757 if( sqlite3ReadSchema(pParse) ){
95758 goto pragma_out;
95759 }
@@ -95477,20 +95799,21 @@
95799 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
95800 sqlite3VdbeUsesBtree(v, iDb);
95801 }
95802 }
95803 }
95804 break;
95805 }
95806 #endif
95807
95808 /*
95809 ** PRAGMA [database.]incremental_vacuum(N)
95810 **
95811 ** Do N steps of incremental vacuuming on a database.
95812 */
95813 #ifndef SQLITE_OMIT_AUTOVACUUM
95814 case PragTyp_INCREMENTAL_VACUUM: {
95815 int iLimit, addr;
95816 if( sqlite3ReadSchema(pParse) ){
95817 goto pragma_out;
95818 }
95819 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
@@ -95501,11 +95824,12 @@
95824 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
95825 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
95826 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
95827 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
95828 sqlite3VdbeJumpHere(v, addr);
95829 break;
95830 }
95831 #endif
95832
95833 #ifndef SQLITE_OMIT_PAGER_PRAGMAS
95834 /*
95835 ** PRAGMA [database.]cache_size
@@ -95516,21 +95840,22 @@
95840 ** page cache size value. If N is positive then that is the
95841 ** number of pages in the cache. If N is negative, then the
95842 ** number of pages is adjusted so that the cache uses -N kibibytes
95843 ** of memory.
95844 */
95845 case PragTyp_CACHE_SIZE: {
95846 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
95847 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95848 if( !zRight ){
95849 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
95850 }else{
95851 int size = sqlite3Atoi(zRight);
95852 pDb->pSchema->cache_size = size;
95853 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
95854 }
95855 break;
95856 }
95857
95858 /*
95859 ** PRAGMA [database.]mmap_size(N)
95860 **
95861 ** Used to set mapping size limit. The mapping size limit is
@@ -95542,11 +95867,11 @@
95867 **
95868 ** This value is advisory. The underlying VFS is free to memory map
95869 ** as little or as much as it wants. Except, if N is set to 0 then the
95870 ** upper layers will never invoke the xFetch interfaces to the VFS.
95871 */
95872 case PragTyp_MMAP_SIZE: {
95873 sqlite3_int64 sz;
95874 #if SQLITE_MAX_MMAP_SIZE>0
95875 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
95876 if( zRight ){
95877 int ii;
@@ -95569,11 +95894,12 @@
95894 returnSingleInt(pParse, "mmap_size", sz);
95895 }else if( rc!=SQLITE_NOTFOUND ){
95896 pParse->nErr++;
95897 pParse->rc = rc;
95898 }
95899 break;
95900 }
95901
95902 /*
95903 ** PRAGMA temp_store
95904 ** PRAGMA temp_store = "default"|"memory"|"file"
95905 **
@@ -95582,17 +95908,18 @@
95908 ** value will be restored the next time the database is opened.
95909 **
95910 ** Note that it is possible for the library compile-time options to
95911 ** override this setting
95912 */
95913 case PragTyp_TEMP_STORE: {
95914 if( !zRight ){
95915 returnSingleInt(pParse, "temp_store", db->temp_store);
95916 }else{
95917 changeTempStorage(pParse, zRight);
95918 }
95919 break;
95920 }
95921
95922 /*
95923 ** PRAGMA temp_store_directory
95924 ** PRAGMA temp_store_directory = ""|"directory_name"
95925 **
@@ -95600,11 +95927,11 @@
95927 ** the value sets a specific directory to be used for temporary files.
95928 ** Setting to a null string reverts to the default temporary directory search.
95929 ** If temporary directory is changed, then invalidateTempStorage.
95930 **
95931 */
95932 case PragTyp_TEMP_STORE_DIRECTORY: {
95933 if( !zRight ){
95934 if( sqlite3_temp_directory ){
95935 sqlite3VdbeSetNumCols(v, 1);
95936 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
95937 "temp_store_directory", SQLITE_STATIC);
@@ -95633,11 +95960,12 @@
95960 }else{
95961 sqlite3_temp_directory = 0;
95962 }
95963 #endif /* SQLITE_OMIT_WSD */
95964 }
95965 break;
95966 }
95967
95968 #if SQLITE_OS_WIN
95969 /*
95970 ** PRAGMA data_store_directory
95971 ** PRAGMA data_store_directory = ""|"directory_name"
@@ -95649,11 +95977,11 @@
95977 ** a relative path will probably be based on the current directory for the
95978 ** process. Database file specified with an absolute path are not impacted
95979 ** by this setting, regardless of its value.
95980 **
95981 */
95982 case PragTyp_DATA_STORE_DIRECTORY: {
95983 if( !zRight ){
95984 if( sqlite3_data_directory ){
95985 sqlite3VdbeSetNumCols(v, 1);
95986 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
95987 "data_store_directory", SQLITE_STATIC);
@@ -95676,30 +96004,24 @@
96004 }else{
96005 sqlite3_data_directory = 0;
96006 }
96007 #endif /* SQLITE_OMIT_WSD */
96008 }
96009 break;
96010 }
96011 #endif
96012
 
 
 
 
 
 
 
96013 #if SQLITE_ENABLE_LOCKING_STYLE
96014 /*
96015 ** PRAGMA [database.]lock_proxy_file
96016 ** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
96017 **
96018 ** Return or set the value of the lock_proxy_file flag. Changing
96019 ** the value sets a specific file to be used for database access locks.
96020 **
96021 */
96022 case PragTyp_LOCK_PROXY_FILE: {
96023 if( !zRight ){
96024 Pager *pPager = sqlite3BtreePager(pDb->pBt);
96025 char *proxy_file_path = NULL;
96026 sqlite3_file *pFile = sqlite3PagerFile(pPager);
96027 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
@@ -95726,11 +96048,12 @@
96048 if( res!=SQLITE_OK ){
96049 sqlite3ErrorMsg(pParse, "failed to set lock proxy file");
96050 goto pragma_out;
96051 }
96052 }
96053 break;
96054 }
96055 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
96056
96057 /*
96058 ** PRAGMA [database.]synchronous
96059 ** PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
@@ -95738,11 +96061,11 @@
96061 ** Return or set the local value of the synchronous flag. Changing
96062 ** the local value does not make changes to the disk file and the
96063 ** default value will be restored the next time the database is
96064 ** opened.
96065 */
96066 case PragTyp_SYNCHRONOUS: {
96067 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
96068 if( !zRight ){
96069 returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
96070 }else{
96071 if( !db->autoCommit ){
@@ -95751,17 +96074,43 @@
96074 }else{
96075 pDb->safety_level = getSafetyLevel(zRight,0,1)+1;
96076 setAllPagerFlags(db);
96077 }
96078 }
96079 break;
96080 }
96081 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
96082
96083 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
96084 case PragTyp_FLAG: {
96085 if( zRight==0 ){
96086 returnSingleInt(pParse, aPragmaNames[mid].zName,
96087 (db->flags & aPragmaNames[mid].iArg)!=0 );
96088 }else{
96089 int mask = aPragmaNames[mid].iArg; /* Mask of bits to set or clear. */
96090 if( db->autoCommit==0 ){
96091 /* Foreign key support may not be enabled or disabled while not
96092 ** in auto-commit mode. */
96093 mask &= ~(SQLITE_ForeignKeys);
96094 }
96095
96096 if( sqlite3GetBoolean(zRight, 0) ){
96097 db->flags |= mask;
96098 }else{
96099 db->flags &= ~mask;
96100 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
96101 }
96102
96103 /* Many of the flag-pragmas modify the code generated by the SQL
96104 ** compiler (eg. count_changes). So add an opcode to expire all
96105 ** compiled SQL statements after modifying a pragma value.
96106 */
96107 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
96108 setAllPagerFlags(db);
96109 }
96110 break;
96111 }
96112 #endif /* SQLITE_OMIT_FLAG_PRAGMAS */
96113
96114 #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
96115 /*
96116 ** PRAGMA table_info(<table>)
@@ -95773,11 +96122,11 @@
96122 ** name: Column name
96123 ** type: Column declaration type.
96124 ** notnull: True if 'NOT NULL' is part of column declaration
96125 ** dflt_value: The default value for the column, if any.
96126 */
96127 case PragTyp_TABLE_INFO: if( zRight ){
96128 Table *pTab;
96129 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
96130 pTab = sqlite3FindTable(db, zRight, zDb);
96131 if( pTab ){
96132 int i, k;
@@ -95819,13 +96168,14 @@
96168 }
96169 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
96170 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
96171 }
96172 }
96173 }
96174 break;
96175
96176 case PragTyp_INDEX_INFO: if( zRight ){
96177 Index *pIdx;
96178 Table *pTab;
96179 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
96180 pIdx = sqlite3FindIndex(db, zRight, zDb);
96181 if( pIdx ){
@@ -95844,13 +96194,14 @@
96194 assert( pTab->nCol>cnum );
96195 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
96196 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
96197 }
96198 }
96199 }
96200 break;
96201
96202 case PragTyp_INDEX_LIST: if( zRight ){
96203 Index *pIdx;
96204 Table *pTab;
96205 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
96206 pTab = sqlite3FindTable(db, zRight, zDb);
96207 if( pTab ){
@@ -95872,13 +96223,14 @@
96223 ++i;
96224 pIdx = pIdx->pNext;
96225 }
96226 }
96227 }
96228 }
96229 break;
96230
96231 case PragTyp_DATABASE_LIST: {
96232 int i;
96233 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
96234 sqlite3VdbeSetNumCols(v, 3);
96235 pParse->nMem = 3;
96236 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
@@ -95891,13 +96243,14 @@
96243 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
96244 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
96245 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
96246 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
96247 }
96248 }
96249 break;
96250
96251 case PragTyp_COLLATION_LIST: {
96252 int i = 0;
96253 HashElem *p;
96254 sqlite3VdbeSetNumCols(v, 2);
96255 pParse->nMem = 2;
96256 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
@@ -95906,15 +96259,16 @@
96259 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
96260 sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
96261 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
96262 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
96263 }
96264 }
96265 break;
96266 #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
96267
96268 #ifndef SQLITE_OMIT_FOREIGN_KEY
96269 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
96270 FKey *pFK;
96271 Table *pTab;
96272 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
96273 pTab = sqlite3FindTable(db, zRight, zDb);
96274 if( pTab ){
@@ -95953,16 +96307,17 @@
96307 ++i;
96308 pFK = pFK->pNextFrom;
96309 }
96310 }
96311 }
96312 }
96313 break;
96314 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
96315
96316 #ifndef SQLITE_OMIT_FOREIGN_KEY
96317 #ifndef SQLITE_OMIT_TRIGGER
96318 case PragTyp_FOREIGN_KEY_CHECK: {
96319 FKey *pFK; /* A foreign key constraint */
96320 Table *pTab; /* Child table contain "REFERENCES" keyword */
96321 Table *pParent; /* Parent table that child points to */
96322 Index *pIdx; /* Index in the parent table */
96323 int i; /* Loop counter: Foreign key number for pTab */
@@ -96068,34 +96423,37 @@
96423 sqlite3DbFree(db, aiCols);
96424 }
96425 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
96426 sqlite3VdbeJumpHere(v, addrTop);
96427 }
96428 }
96429 break;
96430 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
96431 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
96432
96433 #ifndef NDEBUG
96434 case PragTyp_PARSER_TRACE: {
96435 if( zRight ){
96436 if( sqlite3GetBoolean(zRight, 0) ){
96437 sqlite3ParserTrace(stderr, "parser: ");
96438 }else{
96439 sqlite3ParserTrace(0, 0);
96440 }
96441 }
96442 }
96443 break;
96444 #endif
96445
96446 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
96447 ** used will be case sensitive or not depending on the RHS.
96448 */
96449 case PragTyp_CASE_SENSITIVE_LIKE: {
96450 if( zRight ){
96451 sqlite3RegisterLikeFunctions(db, sqlite3GetBoolean(zRight, 0));
96452 }
96453 }
96454 break;
96455
96456 #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
96457 # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
96458 #endif
96459
@@ -96102,13 +96460,11 @@
96460 #ifndef SQLITE_OMIT_INTEGRITY_CHECK
96461 /* Pragma "quick_check" is reduced version of
96462 ** integrity_check designed to detect most database corruption
96463 ** without most of the overhead of a full integrity-check.
96464 */
96465 case PragTyp_INTEGRITY_CHECK: {
 
 
96466 int i, j, addr, mxErr;
96467
96468 /* Code that appears at the end of the integrity check. If no error
96469 ** messages have been generated, output OK. Otherwise output the
96470 ** error message
@@ -96264,11 +96620,12 @@
96620 }
96621 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
96622 sqlite3VdbeChangeP2(v, addr, -mxErr);
96623 sqlite3VdbeJumpHere(v, addr+1);
96624 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
96625 }
96626 break;
96627 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
96628
96629 #ifndef SQLITE_OMIT_UTF16
96630 /*
96631 ** PRAGMA encoding
@@ -96290,11 +96647,11 @@
96647 **
96648 ** In the second form this pragma sets the text encoding to be used in
96649 ** new database files created using this database handle. It is only
96650 ** useful if invoked immediately after the main database i
96651 */
96652 case PragTyp_ENCODING: {
96653 static const struct EncName {
96654 char *zName;
96655 u8 enc;
96656 } encnames[] = {
96657 { "UTF8", SQLITE_UTF8 },
@@ -96337,11 +96694,12 @@
96694 if( !pEnc->zName ){
96695 sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
96696 }
96697 }
96698 }
96699 }
96700 break;
96701 #endif /* SQLITE_OMIT_UTF16 */
96702
96703 #ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
96704 /*
96705 ** PRAGMA [database.]schema_version
@@ -96371,15 +96729,11 @@
96729 ** crashes or database corruption. Use with caution!
96730 **
96731 ** The user-version is not used internally by SQLite. It may be used by
96732 ** applications for any purpose.
96733 */
96734 case PragTyp_HEADER_VALUE: {
 
 
 
 
96735 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
96736 sqlite3VdbeUsesBtree(v, iDb);
96737 switch( zLeft[0] ){
96738 case 'a': case 'A':
96739 iCookie = BTREE_APPLICATION_ID;
@@ -96419,40 +96773,42 @@
96773 sqlite3VdbeChangeP1(v, addr+1, iDb);
96774 sqlite3VdbeChangeP3(v, addr+1, iCookie);
96775 sqlite3VdbeSetNumCols(v, 1);
96776 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
96777 }
96778 }
96779 break;
96780 #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
96781
96782 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
96783 /*
96784 ** PRAGMA compile_options
96785 **
96786 ** Return the names of all compile-time options used in this build,
96787 ** one option per row.
96788 */
96789 case PragTyp_COMPILE_OPTIONS: {
96790 int i = 0;
96791 const char *zOpt;
96792 sqlite3VdbeSetNumCols(v, 1);
96793 pParse->nMem = 1;
96794 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
96795 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
96796 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
96797 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
96798 }
96799 }
96800 break;
96801 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
96802
96803 #ifndef SQLITE_OMIT_WAL
96804 /*
96805 ** PRAGMA [database.]wal_checkpoint = passive|full|restart
96806 **
96807 ** Checkpoint the database.
96808 */
96809 case PragTyp_WAL_CHECKPOINT: {
96810 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
96811 int eMode = SQLITE_CHECKPOINT_PASSIVE;
96812 if( zRight ){
96813 if( sqlite3StrICmp(zRight, "full")==0 ){
96814 eMode = SQLITE_CHECKPOINT_FULL;
@@ -96467,39 +96823,42 @@
96823 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
96824 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
96825
96826 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
96827 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
96828 }
96829 break;
96830
96831 /*
96832 ** PRAGMA wal_autocheckpoint
96833 ** PRAGMA wal_autocheckpoint = N
96834 **
96835 ** Configure a database connection to automatically checkpoint a database
96836 ** after accumulating N frames in the log. Or query for the current value
96837 ** of N.
96838 */
96839 case PragTyp_WAL_AUTOCHECKPOINT: {
96840 if( zRight ){
96841 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
96842 }
96843 returnSingleInt(pParse, "wal_autocheckpoint",
96844 db->xWalCallback==sqlite3WalDefaultHook ?
96845 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
96846 }
96847 break;
96848 #endif
96849
96850 /*
96851 ** PRAGMA shrink_memory
96852 **
96853 ** This pragma attempts to free as much memory as possible from the
96854 ** current database connection.
96855 */
96856 case PragTyp_SHRINK_MEMORY: {
96857 sqlite3_db_release_memory(db);
96858 break;
96859 }
96860
96861 /*
96862 ** PRAGMA busy_timeout
96863 ** PRAGMA busy_timeout = N
96864 **
@@ -96506,22 +96865,40 @@
96865 ** Call sqlite3_busy_timeout(db, N). Return the current timeout value
96866 ** if one is set. If no busy handler or a different busy handler is set
96867 ** then 0 is returned. Setting the busy_timeout to 0 or negative
96868 ** disables the timeout.
96869 */
96870 /*case PragTyp_BUSY_TIMEOUT*/ default: {
96871 assert( aPragmaNames[mid].ePragTyp==PragTyp_BUSY_TIMEOUT );
96872 if( zRight ){
96873 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
96874 }
96875 returnSingleInt(pParse, "timeout", db->busyTimeout);
96876 break;
96877 }
96878
96879 /*
96880 ** PRAGMA soft_heap_limit
96881 ** PRAGMA soft_heap_limit = N
96882 **
96883 ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
96884 ** use -1.
96885 */
96886 case PragTyp_SOFT_HEAP_LIMIT: {
96887 sqlite3_int64 N;
96888 if( zRight && sqlite3Atoi64(zRight, &N, 1000000, SQLITE_UTF8)==SQLITE_OK ){
96889 sqlite3_soft_heap_limit64(N);
96890 }
96891 returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
96892 break;
96893 }
96894
96895 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
96896 /*
96897 ** Report the current state of file logs for all databases
96898 */
96899 case PragTyp_LOCK_STATUS: {
96900 static const char *const azLockName[] = {
96901 "unlocked", "shared", "reserved", "pending", "exclusive"
96902 };
96903 int i;
96904 sqlite3VdbeSetNumCols(v, 2);
@@ -96542,39 +96919,43 @@
96919 zState = azLockName[j];
96920 }
96921 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
96922 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
96923 }
96924 break;
96925 }
96926 #endif
96927
96928 #ifdef SQLITE_HAS_CODEC
96929 case PragTyp_KEY: {
96930 if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96931 break;
96932 }
96933 case PragTyp_REKEY: {
96934 if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight));
96935 break;
96936 }
96937 case PragTyp_HEXKEY: {
96938 if( zRight ){
96939 int i, h1, h2;
96940 char zKey[40];
96941 for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
96942 h1 += 9*(1&(h1>>6));
96943 h2 += 9*(1&(h2>>6));
96944 zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
96945 }
96946 if( (zLeft[3] & 0xf)==0xb ){
96947 sqlite3_key_v2(db, zDb, zKey, i/2);
96948 }else{
96949 sqlite3_rekey_v2(db, zDb, zKey, i/2);
96950 }
96951 }
96952 break;
96953 }
96954 #endif
96955 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
96956 case PragTyp_ACTIVATE_EXTENSIONS: if( zRight ){
96957 #ifdef SQLITE_HAS_CODEC
96958 if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
96959 sqlite3_activate_see(&zRight[4]);
96960 }
96961 #endif
@@ -96581,15 +96962,15 @@
96962 #ifdef SQLITE_ENABLE_CEROD
96963 if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
96964 sqlite3_activate_cerod(&zRight[6]);
96965 }
96966 #endif
96967 }
96968 break;
96969 #endif
96970
96971 } /* End of the PRAGMA switch */
 
96972
96973 pragma_out:
96974 sqlite3DbFree(db, zLeft);
96975 sqlite3DbFree(db, zRight);
96976 }
@@ -97736,12 +98117,12 @@
98117 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
98118
98119 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
98120 if( pEq && isOuterJoin ){
98121 ExprSetProperty(pEq, EP_FromJoin);
98122 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
98123 ExprSetVVAProperty(pEq, EP_NoReduce);
98124 pEq->iRightJoinTable = (i16)pE2->iTable;
98125 }
98126 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
98127 }
98128
@@ -97772,12 +98153,12 @@
98153 ** the output, which is incorrect.
98154 */
98155 static void setJoinExpr(Expr *p, int iTable){
98156 while( p ){
98157 ExprSetProperty(p, EP_FromJoin);
98158 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
98159 ExprSetVVAProperty(p, EP_NoReduce);
98160 p->iRightJoinTable = (i16)iTable;
98161 setJoinExpr(p->pLeft, iTable);
98162 p = p->pRight;
98163 }
98164 }
@@ -100700,11 +101081,11 @@
101081 assert( pTab && !pTab->pSelect && pExpr );
101082
101083 if( IsVirtual(pTab) ) return 0;
101084 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
101085 if( NEVER(pAggInfo->nFunc==0) ) return 0;
101086 if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
101087 if( pExpr->flags&EP_Distinct ) return 0;
101088
101089 return pTab;
101090 }
101091
@@ -101297,11 +101678,11 @@
101678 if( pF->iDistinct>=0 ){
101679 addrNext = sqlite3VdbeMakeLabel(v);
101680 assert( nArg==1 );
101681 codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
101682 }
101683 if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
101684 CollSeq *pColl = 0;
101685 struct ExprList_item *pItem;
101686 int j;
101687 assert( pList!=0 ); /* pList!=0 if pF->pFunc has NEEDCOLL */
101688 for(j=0, pItem=pList->a; !pColl && j<nArg; j++, pItem++){
@@ -104140,11 +104521,11 @@
104521 sqlite3GenerateConstraintChecks(pParse, pTab, iCur, regNewRowid,
104522 aRegIdx, (chngRowid?regOldRowid:0), 1, onError, addr, 0);
104523
104524 /* Do FK constraint checks. */
104525 if( hasFK ){
104526 sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngRowid);
104527 }
104528
104529 /* Delete the index entries associated with the current record. */
104530 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regOldRowid);
104531 sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, aRegIdx);
@@ -104154,21 +104535,21 @@
104535 sqlite3VdbeAddOp2(v, OP_Delete, iCur, 0);
104536 }
104537 sqlite3VdbeJumpHere(v, j1);
104538
104539 if( hasFK ){
104540 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngRowid);
104541 }
104542
104543 /* Insert the new index entries and the new record. */
104544 sqlite3CompleteInsertion(pParse, pTab, iCur, regNewRowid, aRegIdx, 1, 0, 0);
104545
104546 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
104547 ** handle rows (possibly in other tables) that refer via a foreign key
104548 ** to the row just updated. */
104549 if( hasFK ){
104550 sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngRowid);
104551 }
104552 }
104553
104554 /* Increment the row counter
104555 */
@@ -105692,11 +106073,11 @@
106073 *pNew = *pDef;
106074 pNew->zName = (char *)&pNew[1];
106075 memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1);
106076 pNew->xFunc = xFunc;
106077 pNew->pUserData = pArg;
106078 pNew->funcFlags |= SQLITE_FUNC_EPHEM;
106079 return pNew;
106080 }
106081
106082 /*
106083 ** Make sure virtual table pTab is contained in the pParse->apVirtualLock[]
@@ -105829,24 +106210,25 @@
106210
106211 /*
106212 ** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The
106213 ** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
106214 ** (Virtual tables can return a larger cost, but let's assume they do not.)
106215 ** So all costs can be stored in a 16-bit integer without risk
106216 ** of overflow.
106217 **
106218 ** Costs are estimates, so no effort is made to compute 10*log2(X) exactly.
106219 ** Instead, a close estimate is used. Any value of X=1 is stored as 0.
106220 ** X=2 is 10. X=3 is 16. X=1000 is 99. etc. Negative values are allowed.
106221 ** A WhereCost of -10 means 0.5. WhereCost of -20 means 0.25. And so forth.
106222 **
106223 ** The tool/wherecosttest.c source file implements a command-line program
106224 ** that will convert WhereCosts to integers, convert integers to WhereCosts
106225 ** and do addition and multiplication on WhereCost values. The wherecosttest
106226 ** command-line program is a useful utility to have around when working with
106227 ** this module.
106228 */
106229 typedef short int WhereCost;
106230
106231 /*
106232 ** This object contains information needed to implement a single nested
106233 ** loop in WHERE clause.
106234 **
@@ -105883,10 +106265,11 @@
106265 } *aInLoop; /* Information about each nested IN operator */
106266 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
106267 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
106268 } u;
106269 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
106270 Bitmask notReady; /* FROM entries not usable at this level */
106271 };
106272
106273 /*
106274 ** Each instance of this object represents an algorithm for evaluating one
106275 ** term of a join. Every term of the FROM clause will have at least
@@ -106045,10 +106428,11 @@
106428 union {
106429 int leftColumn; /* Column number of X in "X <op> <expr>" */
106430 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
106431 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
106432 } u;
106433 WhereCost truthProb; /* Probability of truth for this expression */
106434 u16 eOperator; /* A WO_xx value describing <op> */
106435 u8 wtFlags; /* TERM_xxx bit flags. See below */
106436 u8 nChild; /* Number of children that must disable us */
106437 WhereClause *pWC; /* The clause this term is part of */
106438 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
@@ -106419,10 +106803,13 @@
106803 if( pWC->a!=pWC->aStatic ){
106804 sqlite3DbFree(db, pWC->a);
106805 }
106806 }
106807
106808 /* Forward declaration */
106809 static WhereCost whereCost(tRowcnt x);
106810
106811 /*
106812 ** Add a single new WhereTerm entry to the WhereClause object pWC.
106813 ** The new WhereTerm object is constructed from Expr p and with wtFlags.
106814 ** The index in pWC->a[] of the new WhereTerm is returned on success.
106815 ** 0 is returned if the new WhereTerm could not be added due to a memory
@@ -106460,10 +106847,15 @@
106847 sqlite3DbFree(db, pOld);
106848 }
106849 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
106850 }
106851 pTerm = &pWC->a[idx = pWC->nTerm++];
106852 if( p && ExprHasProperty(p, EP_Unlikely) ){
106853 pTerm->truthProb = whereCost(p->iTable) - 99;
106854 }else{
106855 pTerm->truthProb = -1;
106856 }
106857 pTerm->pExpr = sqlite3ExprSkipCollate(p);
106858 pTerm->wtFlags = wtFlags;
106859 pTerm->pWC = pWC;
106860 pTerm->iParent = -1;
106861 return idx;
@@ -108321,18 +108713,19 @@
108713 WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */
108714 WhereCost *pnOut /* IN/OUT: Number of rows visited */
108715 ){
108716 int rc = SQLITE_OK;
108717 int nOut = (int)*pnOut;
108718 WhereCost nNew;
108719
108720 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
108721 Index *p = pBuilder->pNew->u.btree.pIndex;
108722 int nEq = pBuilder->pNew->u.btree.nEq;
108723
108724 if( p->nSample>0
108725 && nEq==pBuilder->nRecValid
108726 && nEq<p->nSampleCol
 
108727 && OptimizationEnabled(pParse->db, SQLITE_Stat3)
108728 ){
108729 UnpackedRecord *pRec = pBuilder->pRec;
108730 tRowcnt a[2];
108731 u8 aff;
@@ -108383,10 +108776,11 @@
108776 if( rc==SQLITE_OK && bOk ){
108777 tRowcnt iNew;
108778 whereKeyStats(pParse, p, pRec, 0, a);
108779 iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
108780 if( iNew>iLower ) iLower = iNew;
108781 nOut--;
108782 }
108783 }
108784
108785 /* If possible, improve on the iUpper estimate using ($P:$U). */
108786 if( pUpper ){
@@ -108397,16 +108791,16 @@
108791 if( rc==SQLITE_OK && bOk ){
108792 tRowcnt iNew;
108793 whereKeyStats(pParse, p, pRec, 1, a);
108794 iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
108795 if( iNew<iUpper ) iUpper = iNew;
108796 nOut--;
108797 }
108798 }
108799
108800 pBuilder->pRec = pRec;
108801 if( rc==SQLITE_OK ){
 
108802 if( iUpper>iLower ){
108803 nNew = whereCost(iUpper - iLower);
108804 }else{
108805 nNew = 10; assert( 10==whereCost(2) );
108806 }
@@ -108424,17 +108818,21 @@
108818 UNUSED_PARAMETER(pBuilder);
108819 #endif
108820 assert( pLower || pUpper );
108821 /* TUNING: Each inequality constraint reduces the search space 4-fold.
108822 ** A BETWEEN operator, therefore, reduces the search space 16-fold */
108823 nNew = nOut;
108824 if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ){
108825 nNew -= 20; assert( 20==whereCost(4) );
108826 nOut--;
108827 }
108828 if( pUpper ){
108829 nNew -= 20; assert( 20==whereCost(4) );
108830 nOut--;
108831 }
108832 if( nNew<10 ) nNew = 10;
108833 if( nNew<nOut ) nOut = nNew;
108834 *pnOut = (WhereCost)nOut;
108835 return rc;
108836 }
108837
108838 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
@@ -108576,10 +108974,11 @@
108974 */
108975 static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
108976 if( pTerm
108977 && (pTerm->wtFlags & TERM_CODED)==0
108978 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
108979 && (pLevel->notReady & pTerm->prereqAll)==0
108980 ){
108981 pTerm->wtFlags |= TERM_CODED;
108982 if( pTerm->iParent>=0 ){
108983 WhereTerm *pOther = &pTerm->pWC->a[pTerm->iParent];
108984 if( (--pOther->nChild)==0 ){
@@ -109001,20 +109400,20 @@
109400 struct SrcList_item *pTabItem; /* FROM clause term being coded */
109401 int addrBrk; /* Jump here to break out of the loop */
109402 int addrCont; /* Jump here to continue with next cycle */
109403 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
109404 int iReleaseReg = 0; /* Temp register to free before returning */
 
109405
109406 pParse = pWInfo->pParse;
109407 v = pParse->pVdbe;
109408 pWC = &pWInfo->sWC;
109409 db = pParse->db;
109410 pLevel = &pWInfo->a[iLevel];
109411 pLoop = pLevel->pWLoop;
109412 pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
109413 iCur = pTabItem->iCursor;
109414 pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
109415 bRev = (pWInfo->revMask>>iLevel)&1;
109416 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
109417 && (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
109418 VdbeNoopComment((v, "Begin Join Loop %d", iLevel));
109419
@@ -109663,21 +110062,20 @@
110062 pLevel->op = aStep[bRev];
110063 pLevel->p1 = iCur;
110064 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
110065 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
110066 }
 
110067
110068 /* Insert code to test every subexpression that can be completely
110069 ** computed using the current set of tables.
110070 */
110071 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
110072 Expr *pE;
110073 testcase( pTerm->wtFlags & TERM_VIRTUAL );
110074 testcase( pTerm->wtFlags & TERM_CODED );
110075 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
110076 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
110077 testcase( pWInfo->untestedTerms==0
110078 && (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
110079 pWInfo->untestedTerms = 1;
110080 continue;
110081 }
@@ -109705,11 +110103,11 @@
110103 if( pTerm->eOperator!=(WO_EQUIV|WO_EQ) ) continue;
110104 if( pTerm->leftCursor!=iCur ) continue;
110105 if( pLevel->iLeftJoin ) continue;
110106 pE = pTerm->pExpr;
110107 assert( !ExprHasProperty(pE, EP_FromJoin) );
110108 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
110109 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
110110 if( pAlt==0 ) continue;
110111 if( pAlt->wtFlags & (TERM_CODED) ) continue;
110112 testcase( pAlt->eOperator & WO_EQ );
110113 testcase( pAlt->eOperator & WO_IN );
@@ -109733,11 +110131,11 @@
110131 sqlite3ExprCacheClear(pParse);
110132 for(pTerm=pWC->a, j=0; j<pWC->nTerm; j++, pTerm++){
110133 testcase( pTerm->wtFlags & TERM_VIRTUAL );
110134 testcase( pTerm->wtFlags & TERM_CODED );
110135 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
110136 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
110137 assert( pWInfo->untestedTerms );
110138 continue;
110139 }
110140 assert( pTerm->pExpr );
110141 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
@@ -109744,11 +110142,11 @@
110142 pTerm->wtFlags |= TERM_CODED;
110143 }
110144 }
110145 sqlite3ReleaseTempReg(pParse, iReleaseReg);
110146
110147 return pLevel->notReady;
110148 }
110149
110150 #ifdef WHERETRACE_ENABLED
110151 /*
110152 ** Print a WhereLoop object for debugging purposes
@@ -109845,12 +110243,15 @@
110243
110244 /*
110245 ** Transfer content from the second pLoop into the first.
110246 */
110247 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
 
110248 whereLoopClearUnion(db, pTo);
110249 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
110250 memset(&pTo->u, 0, sizeof(pTo->u));
110251 return SQLITE_NOMEM;
110252 }
110253 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
110254 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
110255 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
110256 pFrom->u.vtab.needFree = 0;
110257 }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
@@ -109962,13 +110363,13 @@
110363 ** all of (1) dependencies (2) setup-cost, (3) run-cost, and
110364 ** (4) number of output rows. */
110365 assert( p->rSetup==pTemplate->rSetup );
110366 if( p->prereq==pTemplate->prereq
110367 && p->nLTerm<pTemplate->nLTerm
110368 && (p->wsFlags & pTemplate->wsFlags & WHERE_INDEXED)!=0
110369 && (p->u.btree.pIndex==pTemplate->u.btree.pIndex
110370 || pTemplate->rRun+p->nLTerm<=p->rRun+pTemplate->nLTerm)
110371 ){
110372 /* Overwrite an existing WhereLoop with an similar one that uses
110373 ** more terms of the index */
110374 pNext = p->pNextLoop;
110375 break;
@@ -109979,16 +110380,16 @@
110380 }
110381 }
110382 if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
110383 && p->rRun>=pTemplate->rRun
110384 && p->nOut>=pTemplate->nOut
 
110385 ){
110386 /* Overwrite an existing WhereLoop with a better one: one that is
110387 ** better at one of (1) dependencies, (2) setup-cost, (3) run-cost
110388 ** or (4) number of output rows, and is no worse in any of those
110389 ** categories. */
110390 assert( p->rSetup>=pTemplate->rSetup ); /* SETUP-INVARIANT above */
110391 pNext = p->pNextLoop;
110392 break;
110393 }
110394 }
110395
@@ -110030,10 +110431,40 @@
110431 whereLoopPrint(pTemplate, pWInfo->pTabList);
110432 }
110433 #endif
110434 return SQLITE_OK;
110435 }
110436
110437 /*
110438 ** Adjust the WhereLoop.nOut value downward to account for terms of the
110439 ** WHERE clause that reference the loop but which are not used by an
110440 ** index.
110441 **
110442 ** In the current implementation, the first extra WHERE clause term reduces
110443 ** the number of output rows by a factor of 10 and each additional term
110444 ** reduces the number of output rows by sqrt(2).
110445 */
110446 static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop, int iCur){
110447 WhereTerm *pTerm, *pX;
110448 Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
110449 int i, j;
110450
110451 if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){
110452 return;
110453 }
110454 for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
110455 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
110456 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
110457 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
110458 for(j=pLoop->nLTerm-1; j>=0; j--){
110459 pX = pLoop->aLTerm[j];
110460 if( pX==pTerm ) break;
110461 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
110462 }
110463 if( j<0 ) pLoop->nOut += pTerm->truthProb;
110464 }
110465 }
110466
110467 /*
110468 ** We have so far matched pBuilder->pNew->u.btree.nEq terms of the index pIndex.
110469 ** Try to match one more.
110470 **
@@ -110197,11 +110628,11 @@
110628 ** the main table */
110629 pNew->rRun = whereCostAdd(pNew->rRun, rLogSize>27 ? rLogSize-17 : 10);
110630 }
110631 /* Step cost for each output row */
110632 pNew->rRun = whereCostAdd(pNew->rRun, pNew->nOut);
110633 whereLoopOutputAdjust(pBuilder->pWC, pNew, pSrc->iCursor);
110634 rc = whereLoopInsert(pBuilder, pNew);
110635 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
110636 && pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0))
110637 ){
110638 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -110401,11 +110832,13 @@
110832 ** + The extra 3 factor is to encourage the use of indexed lookups
110833 ** over full scans. A smaller constant 2 is used for covering
110834 ** index scans so that a covering index scan will be favored over
110835 ** a table scan. */
110836 pNew->rRun = whereCostAdd(rSize,rLogSize) + 16;
110837 whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor);
110838 rc = whereLoopInsert(pBuilder, pNew);
110839 pNew->nOut = rSize;
110840 if( rc ) break;
110841 }else{
110842 Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe);
110843 pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
110844
@@ -110433,11 +110866,13 @@
110866 assert( b!=0 );
110867 /* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N)
110868 ** which we will simplify to just N*log2(N) */
110869 pNew->rRun = rSize + rLogSize;
110870 }
110871 whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor);
110872 rc = whereLoopInsert(pBuilder, pNew);
110873 pNew->nOut = rSize;
110874 if( rc ) break;
110875 }
110876 }
110877
110878 rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0);
@@ -111040,13 +111475,16 @@
111475 int nLoop; /* Number of terms in the join */
111476 Parse *pParse; /* Parsing context */
111477 sqlite3 *db; /* The database connection */
111478 int iLoop; /* Loop counter over the terms of the join */
111479 int ii, jj; /* Loop counters */
111480 int mxI = 0; /* Index of next entry to replace */
111481 WhereCost rCost; /* Cost of a path */
111482 WhereCost nOut; /* Number of outputs */
111483 WhereCost mxCost = 0; /* Maximum cost of a set of paths */
111484 WhereCost mxOut = 0; /* Maximum nOut value on the set of paths */
111485 WhereCost rSortCost; /* Cost to do a sort */
111486 int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
111487 WherePath *aFrom; /* All nFrom paths at the previous level */
111488 WherePath *aTo; /* The nTo best paths at the current level */
111489 WherePath *pFrom; /* An element of aFrom[] that we are working on */
111490 WherePath *pTo; /* An element of aTo[] that we are working on */
@@ -111111,10 +111549,11 @@
111549 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
111550 /* At this point, pWLoop is a candidate to be the next loop.
111551 ** Compute its cost */
111552 rCost = whereCostAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
111553 rCost = whereCostAdd(rCost, pFrom->rCost);
111554 nOut = pFrom->nRow + pWLoop->nOut;
111555 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
111556 if( !isOrderedValid ){
111557 switch( wherePathSatisfiesOrderBy(pWInfo,
111558 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
111559 iLoop, pWLoop, &revMask) ){
@@ -111133,21 +111572,25 @@
111572 }else{
111573 revMask = pFrom->revLoop;
111574 }
111575 /* Check to see if pWLoop should be added to the mxChoice best so far */
111576 for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
111577 if( pTo->maskLoop==maskNew
111578 && pTo->isOrderedValid==isOrderedValid
111579 && ((pTo->rCost<=rCost && pTo->nRow<=nOut) ||
111580 (pTo->rCost>=rCost && pTo->nRow>=nOut))
111581 ){
111582 testcase( jj==nTo-1 );
111583 break;
111584 }
111585 }
111586 if( jj>=nTo ){
111587 if( nTo>=mxChoice && rCost>=mxCost ){
111588 #ifdef WHERETRACE_ENABLED
111589 if( sqlite3WhereTrace&0x4 ){
111590 sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
111591 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111592 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111593 }
111594 #endif
111595 continue;
111596 }
@@ -111155,30 +111598,30 @@
111598 if( nTo<mxChoice ){
111599 /* Increase the size of the aTo set by one */
111600 jj = nTo++;
111601 }else{
111602 /* New path replaces the prior worst to keep count below mxChoice */
111603 jj = mxI;
111604 }
111605 pTo = &aTo[jj];
111606 #ifdef WHERETRACE_ENABLED
111607 if( sqlite3WhereTrace&0x4 ){
111608 sqlite3DebugPrintf("New %s cost=%-3d,%3d order=%c\n",
111609 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111610 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111611 }
111612 #endif
111613 }else{
111614 if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
111615 #ifdef WHERETRACE_ENABLED
111616 if( sqlite3WhereTrace&0x4 ){
111617 sqlite3DebugPrintf(
111618 "Skip %s cost=%-3d,%3d order=%c",
111619 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111620 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111621 sqlite3DebugPrintf(" vs %s cost=%-3d,%d order=%c\n",
111622 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
111623 pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
111624 }
111625 #endif
111626 testcase( pTo->rCost==rCost );
111627 continue;
@@ -111186,32 +111629,38 @@
111629 testcase( pTo->rCost==rCost+1 );
111630 /* A new and better score for a previously created equivalent path */
111631 #ifdef WHERETRACE_ENABLED
111632 if( sqlite3WhereTrace&0x4 ){
111633 sqlite3DebugPrintf(
111634 "Update %s cost=%-3d,%3d order=%c",
111635 wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
111636 isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
111637 sqlite3DebugPrintf(" was %s cost=%-3d,%3d order=%c\n",
111638 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
111639 pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
111640 }
111641 #endif
111642 }
111643 /* pWLoop is a winner. Add it to the set of best so far */
111644 pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
111645 pTo->revLoop = revMask;
111646 pTo->nRow = nOut;
111647 pTo->rCost = rCost;
111648 pTo->isOrderedValid = isOrderedValid;
111649 pTo->isOrdered = isOrdered;
111650 memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
111651 pTo->aLoop[iLoop] = pWLoop;
111652 if( nTo>=mxChoice ){
111653 mxI = 0;
111654 mxCost = aTo[0].rCost;
111655 mxOut = aTo[0].nRow;
111656 for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
111657 if( pTo->rCost>mxCost || (pTo->rCost==mxCost && pTo->nRow>mxOut) ){
111658 mxCost = pTo->rCost;
111659 mxOut = pTo->nRow;
111660 mxI = jj;
111661 }
111662 }
111663 }
111664 }
111665 }
111666
@@ -111244,16 +111693,13 @@
111693 return SQLITE_ERROR;
111694 }
111695
111696 /* Find the lowest cost path. pFrom will be left pointing to that path */
111697 pFrom = aFrom;
 
 
111698 for(ii=1; ii<nFrom; ii++){
111699 if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
111700 }
 
111701 assert( pWInfo->nLevel==nLoop );
111702 /* Load the lowest cost path into pWInfo */
111703 for(iLoop=0; iLoop<nLoop; iLoop++){
111704 WhereLevel *pLevel = pWInfo->a + iLoop;
111705 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
@@ -114879,16 +115325,17 @@
115325 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115326 }
115327 break;
115328 case 231: /* expr ::= CASE case_operand case_exprlist case_else END */
115329 {
115330 yygotominor.yy342.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy122, 0, 0);
115331 if( yygotominor.yy342.pExpr ){
115332 yygotominor.yy342.pExpr->x.pList = yymsp[-1].minor.yy122 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy442,yymsp[-1].minor.yy122) : yymsp[-2].minor.yy442;
115333 sqlite3ExprSetHeight(pParse, yygotominor.yy342.pExpr);
115334 }else{
115335 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy442);
115336 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy122);
115337 }
115338 yygotominor.yy342.zStart = yymsp[-4].minor.yy0.z;
115339 yygotominor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
115340 }
115341 break;
@@ -118020,11 +118467,11 @@
118467 ** and there are active VMs, then return SQLITE_BUSY. If a function
118468 ** is being overridden/deleted but there are no active VMs, allow the
118469 ** operation to continue but invalidate all precompiled statements.
118470 */
118471 p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
118472 if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){
118473 if( db->nVdbeActive ){
118474 sqlite3Error(db, SQLITE_BUSY,
118475 "unable to delete/modify user-function due to active statements");
118476 assert( !db->mallocFailed );
118477 return SQLITE_BUSY;
@@ -118045,11 +118492,11 @@
118492
118493 if( pDestructor ){
118494 pDestructor->nRef++;
118495 }
118496 p->pDestructor = pDestructor;
118497 p->funcFlags &= SQLITE_FUNC_ENCMASK;
118498 p->xFunc = xFunc;
118499 p->xStep = xStep;
118500 p->xFinalize = xFinal;
118501 p->pUserData = pUserData;
118502 p->nArg = (u16)nArg;
118503
+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.1"
111111
#define SQLITE_VERSION_NUMBER 3008001
112
-#define SQLITE_SOURCE_ID "2013-09-04 04:04:08 8df95bb0b3f72222cf262174247a467c234f9939"
112
+#define SQLITE_SOURCE_ID "2013-09-16 12:57:19 daf6ba413cb3cb6065774ba07495eab4a28b49b0"
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.1"
111 #define SQLITE_VERSION_NUMBER 3008001
112 #define SQLITE_SOURCE_ID "2013-09-04 04:04:08 8df95bb0b3f72222cf262174247a467c234f9939"
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.1"
111 #define SQLITE_VERSION_NUMBER 3008001
112 #define SQLITE_SOURCE_ID "2013-09-16 12:57:19 daf6ba413cb3cb6065774ba07495eab4a28b49b0"
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