Fossil SCM

Update the built-in SQLite to the latest SQLite (3.8.12 alpha).

drh 2015-09-11 11:43 UTC trunk
Commit cc0c939202be2a6b6e5946d5353e51b95450e18b
3 files changed +8 -1 +3082 -2180 +37 -4
+8 -1
--- src/shell.c
+++ src/shell.c
@@ -4250,12 +4250,12 @@
42504250
if( nSql ){
42514251
if( !_all_whitespace(zSql) ){
42524252
fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
42534253
errCnt++;
42544254
}
4255
- free(zSql);
42564255
}
4256
+ free(zSql);
42574257
free(zLine);
42584258
return errCnt>0;
42594259
}
42604260
42614261
/*
@@ -4616,10 +4616,17 @@
46164616
fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
46174617
return 1;
46184618
#endif
46194619
}
46204620
data.out = stdout;
4621
+
4622
+#ifdef SQLITE_ENABLE_JSON1
4623
+ {
4624
+ extern int sqlite3_json_init(sqlite3*);
4625
+ sqlite3_auto_extension((void(*)(void))sqlite3_json_init);
4626
+ }
4627
+#endif
46214628
46224629
/* Go ahead and open the database file if it already exists. If the
46234630
** file does not exist, delay opening it. This prevents empty database
46244631
** files from being created if a user mistypes the database name argument
46254632
** to the sqlite command-line tool.
46264633
--- src/shell.c
+++ src/shell.c
@@ -4250,12 +4250,12 @@
4250 if( nSql ){
4251 if( !_all_whitespace(zSql) ){
4252 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
4253 errCnt++;
4254 }
4255 free(zSql);
4256 }
 
4257 free(zLine);
4258 return errCnt>0;
4259 }
4260
4261 /*
@@ -4616,10 +4616,17 @@
4616 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4617 return 1;
4618 #endif
4619 }
4620 data.out = stdout;
 
 
 
 
 
 
 
4621
4622 /* Go ahead and open the database file if it already exists. If the
4623 ** file does not exist, delay opening it. This prevents empty database
4624 ** files from being created if a user mistypes the database name argument
4625 ** to the sqlite command-line tool.
4626
--- src/shell.c
+++ src/shell.c
@@ -4250,12 +4250,12 @@
4250 if( nSql ){
4251 if( !_all_whitespace(zSql) ){
4252 fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
4253 errCnt++;
4254 }
 
4255 }
4256 free(zSql);
4257 free(zLine);
4258 return errCnt>0;
4259 }
4260
4261 /*
@@ -4616,10 +4616,17 @@
4616 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4617 return 1;
4618 #endif
4619 }
4620 data.out = stdout;
4621
4622 #ifdef SQLITE_ENABLE_JSON1
4623 {
4624 extern int sqlite3_json_init(sqlite3*);
4625 sqlite3_auto_extension((void(*)(void))sqlite3_json_init);
4626 }
4627 #endif
4628
4629 /* Go ahead and open the database file if it already exists. If the
4630 ** file does not exist, delay opening it. This prevents empty database
4631 ** files from being created if a user mistypes the database name argument
4632 ** to the sqlite command-line tool.
4633
+3082 -2180
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.8.11.1. By combining all the individual C code files into this
3
+** version 3.8.12. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -323,13 +323,13 @@
323323
**
324324
** See also: [sqlite3_libversion()],
325325
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326326
** [sqlite_version()] and [sqlite_source_id()].
327327
*/
328
-#define SQLITE_VERSION "3.8.11.1"
329
-#define SQLITE_VERSION_NUMBER 3008011
330
-#define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
328
+#define SQLITE_VERSION "3.8.12"
329
+#define SQLITE_VERSION_NUMBER 3008012
330
+#define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a"
331331
332332
/*
333333
** CAPI3REF: Run-Time Library Version Numbers
334334
** KEYWORDS: sqlite3_version, sqlite3_sourceid
335335
**
@@ -689,10 +689,11 @@
689689
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
690690
#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
691691
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
692692
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
693693
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
694
+#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
694695
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
695696
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
696697
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
697698
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
698699
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -3585,11 +3586,12 @@
35853586
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
35863587
** METHOD: sqlite3_stmt
35873588
**
35883589
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
35893590
** [prepared statement] S has been stepped at least once using
3590
-** [sqlite3_step(S)] but has not run to completion and/or has not
3591
+** [sqlite3_step(S)] but has neither run to completion (returned
3592
+** [SQLITE_DONE] from [sqlite3_step(S)]) nor
35913593
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
35923594
** interface returns false if S is a NULL pointer. If S is not a
35933595
** NULL pointer and is not a pointer to a valid [prepared statement]
35943596
** object, then the behavior is undefined and probably undesirable.
35953597
**
@@ -4567,10 +4569,26 @@
45674569
SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
45684570
SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
45694571
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
45704572
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
45714573
4574
+/*
4575
+** CAPI3REF: Obtaining SQL Values
4576
+** METHOD: sqlite3_value
4577
+**
4578
+** The sqlite3_value_subtype(V) function returns the subtype for
4579
+** an [application-defined SQL function] argument V. The subtype
4580
+** information can be used to pass a limited amount of context from
4581
+** one SQL function to another. Use the [sqlite3_result_subtype()]
4582
+** routine to set the subtype for the return value of an SQL function.
4583
+**
4584
+** SQLite makes no use of subtype itself. It merely passes the subtype
4585
+** from the result of one [application-defined SQL function] into the
4586
+** input of another.
4587
+*/
4588
+SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
4589
+
45724590
/*
45734591
** CAPI3REF: Copy And Free SQL Values
45744592
** METHOD: sqlite3_value
45754593
**
45764594
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
@@ -4866,10 +4884,25 @@
48664884
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
48674885
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
48684886
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
48694887
SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
48704888
4889
+
4890
+/*
4891
+** CAPI3REF: Setting The Subtype Of An SQL Function
4892
+** METHOD: sqlite3_context
4893
+**
4894
+** The sqlite3_result_subtype(C,T) function causes the subtype of
4895
+** the result from the [application-defined SQL function] with
4896
+** [sqlite3_context] C to be the value T. Only the lower 8 bits
4897
+** of the subtype T are preserved in current versions of SQLite;
4898
+** higher order bits are discarded.
4899
+** The number of subtype bytes preserved by SQLite might increase
4900
+** in future releases of SQLite.
4901
+*/
4902
+SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
4903
+
48714904
/*
48724905
** CAPI3REF: Define New Collating Sequences
48734906
** METHOD: sqlite3
48744907
**
48754908
** ^These functions add, remove, or modify a [collation] associated
@@ -8361,19 +8394,22 @@
83618394
# define SQLITE_NOINLINE
83628395
#endif
83638396
83648397
/*
83658398
** Make sure that the compiler intrinsics we desire are enabled when
8366
-** compiling with an appropriate version of MSVC.
8399
+** compiling with an appropriate version of MSVC unless prevented by
8400
+** the SQLITE_DISABLE_INTRINSIC define.
83678401
*/
8368
-#if defined(_MSC_VER) && _MSC_VER>=1300
8369
-# if !defined(_WIN32_WCE)
8370
-# include <intrin.h>
8371
-# pragma intrinsic(_byteswap_ushort)
8372
-# pragma intrinsic(_byteswap_ulong)
8373
-# else
8374
-# include <cmnintrin.h>
8402
+#if !defined(SQLITE_DISABLE_INTRINSIC)
8403
+# if defined(_MSC_VER) && _MSC_VER>=1300
8404
+# if !defined(_WIN32_WCE)
8405
+# include <intrin.h>
8406
+# pragma intrinsic(_byteswap_ushort)
8407
+# pragma intrinsic(_byteswap_ulong)
8408
+# else
8409
+# include <cmnintrin.h>
8410
+# endif
83758411
# endif
83768412
#endif
83778413
83788414
/*
83798415
** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
@@ -10050,16 +10086,20 @@
1005010086
*/
1005110087
SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
1005210088
SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
1005310089
SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
1005410090
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
10091
+SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
10092
+SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
10093
+SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
1005510094
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
1005610095
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
1005710096
SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
1005810097
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
1005910098
SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
1006010099
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
10100
+SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
1006110101
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
1006210102
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
1006310103
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
1006410104
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
1006510105
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
@@ -11333,22 +11373,24 @@
1133311373
/*
1133411374
** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
1133511375
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There
1133611376
** are assert() statements in the code to verify this.
1133711377
*/
11338
-#define SQLITE_FUNC_ENCMASK 0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
11339
-#define SQLITE_FUNC_LIKE 0x004 /* Candidate for the LIKE optimization */
11340
-#define SQLITE_FUNC_CASE 0x008 /* Case-sensitive LIKE-type function */
11341
-#define SQLITE_FUNC_EPHEM 0x010 /* Ephemeral. Delete with VDBE */
11342
-#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
11343
-#define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
11344
-#define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
11345
-#define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
11346
-#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
11347
-#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
11348
-#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
11349
-#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
11378
+#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
11379
+#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
11380
+#define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
11381
+#define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
11382
+#define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/
11383
+#define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */
11384
+#define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */
11385
+#define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */
11386
+#define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */
11387
+#define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
11388
+#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
11389
+#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
11390
+#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
11391
+ ** single query - might change over time */
1135011392
1135111393
/*
1135211394
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1135311395
** used to create the initializers for the FuncDef structures.
1135411396
**
@@ -11359,10 +11401,16 @@
1135911401
** as the user-data (sqlite3_user_data()) for the function. If
1136011402
** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
1136111403
**
1136211404
** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
1136311405
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
11406
+**
11407
+** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
11408
+** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
11409
+** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
11410
+** and functions like sqlite_version() that can change, but not during
11411
+** a single query.
1136411412
**
1136511413
** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
1136611414
** Used to create an aggregate function definition implemented by
1136711415
** the C functions xStep and xFinal. The first four parameters
1136811416
** are interpreted in the same way as the first 4 parameters to
@@ -11380,15 +11428,18 @@
1138011428
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1138111429
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1138211430
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
1138311431
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1138411432
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
11433
+#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
11434
+ {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11435
+ SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1138511436
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
1138611437
{nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
1138711438
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1138811439
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
11389
- {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11440
+ {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1139011441
pArg, 0, xFunc, 0, 0, #zName, 0, 0}
1139111442
#define LIKEFUNC(zName, nArg, arg, flags) \
1139211443
{nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1139311444
(void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
1139411445
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
@@ -11428,10 +11479,11 @@
1142811479
struct Module {
1142911480
const sqlite3_module *pModule; /* Callback pointers */
1143011481
const char *zName; /* Name passed to create_module() */
1143111482
void *pAux; /* pAux passed to create_module() */
1143211483
void (*xDestroy)(void *); /* Module destructor function */
11484
+ Table *pEpoTab; /* Eponymous table for this module */
1143311485
};
1143411486
1143511487
/*
1143611488
** information about each column of an SQL table is held in an instance
1143711489
** of this structure.
@@ -11473,10 +11525,11 @@
1147311525
/*
1147411526
** A sort order can be either ASC or DESC.
1147511527
*/
1147611528
#define SQLITE_SO_ASC 0 /* Sort in ascending order */
1147711529
#define SQLITE_SO_DESC 1 /* Sort in ascending order */
11530
+#define SQLITE_SO_UNDEFINED -1 /* No sort order specified */
1147811531
1147911532
/*
1148011533
** Column affinity types.
1148111534
**
1148211535
** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
@@ -11579,13 +11632,12 @@
1157911632
Column *aCol; /* Information about each column */
1158011633
Index *pIndex; /* List of SQL indexes on this table. */
1158111634
Select *pSelect; /* NULL for tables. Points to definition if a view. */
1158211635
FKey *pFKey; /* Linked list of all foreign keys in this table */
1158311636
char *zColAff; /* String defining the affinity of each column */
11584
-#ifndef SQLITE_OMIT_CHECK
1158511637
ExprList *pCheck; /* All CHECK constraints */
11586
-#endif
11638
+ /* ... also used as column name list in a VIEW */
1158711639
int tnum; /* Root BTree page for this table */
1158811640
i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1158911641
i16 nCol; /* Number of columns in this table */
1159011642
u16 nRef; /* Number of pointers to this Table */
1159111643
LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
@@ -11598,11 +11650,11 @@
1159811650
#ifndef SQLITE_OMIT_ALTERTABLE
1159911651
int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
1160011652
#endif
1160111653
#ifndef SQLITE_OMIT_VIRTUALTABLE
1160211654
int nModuleArg; /* Number of arguments to the module */
11603
- char **azModuleArg; /* Text of all module args. [0] is module name */
11655
+ char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */
1160411656
VTable *pVTable; /* List of VTable objects. */
1160511657
#endif
1160611658
Trigger *pTrigger; /* List of triggers stored in pSchema */
1160711659
Schema *pSchema; /* Schema that contains this table */
1160811660
Table *pNextZombie; /* Next on the Parse.pZombieTab list */
@@ -11819,10 +11871,11 @@
1181911871
Index *pNext; /* The next index associated with the same table */
1182011872
Schema *pSchema; /* Schema containing this index */
1182111873
u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
1182211874
char **azColl; /* Array of collation sequence names for index */
1182311875
Expr *pPartIdxWhere; /* WHERE clause for partial indices */
11876
+ ExprList *aColExpr; /* Column expressions */
1182411877
int tnum; /* DB Page containing root of this index */
1182511878
LogEst szIdxRow; /* Estimated average row size in bytes */
1182611879
u16 nKeyCol; /* Number of columns forming the key */
1182711880
u16 nColumn; /* Number of columns stored in the index */
1182811881
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12068,13 +12121,14 @@
1206812121
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
1206912122
#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
1207012123
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
1207112124
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
1207212125
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
12073
-#define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */
12126
+#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
1207412127
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
1207512128
#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
12129
+#define EP_Alias 0x400000 /* Is an alias for a result set column */
1207612130
1207712131
/*
1207812132
** Combinations of two or more EP_* flags
1207912133
*/
1208012134
#define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
@@ -12233,24 +12287,31 @@
1223312287
Table *pTab; /* An SQL table corresponding to zName */
1223412288
Select *pSelect; /* A SELECT statement used in place of a table name */
1223512289
int addrFillSub; /* Address of subroutine to manifest a subquery */
1223612290
int regReturn; /* Register holding return address of addrFillSub */
1223712291
int regResult; /* Registers holding results of a co-routine */
12238
- u8 jointype; /* Type of join between this able and the previous */
12239
- unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
12240
- unsigned isCorrelated :1; /* True if sub-query is correlated */
12241
- unsigned viaCoroutine :1; /* Implemented as a co-routine */
12242
- unsigned isRecursive :1; /* True for recursive reference in WITH */
12292
+ struct {
12293
+ u8 jointype; /* Type of join between this able and the previous */
12294
+ unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
12295
+ unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
12296
+ unsigned isTabFunc :1; /* True if table-valued-function syntax */
12297
+ unsigned isCorrelated :1; /* True if sub-query is correlated */
12298
+ unsigned viaCoroutine :1; /* Implemented as a co-routine */
12299
+ unsigned isRecursive :1; /* True for recursive reference in WITH */
12300
+ } fg;
1224312301
#ifndef SQLITE_OMIT_EXPLAIN
1224412302
u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
1224512303
#endif
1224612304
int iCursor; /* The VDBE cursor number used to access this table */
1224712305
Expr *pOn; /* The ON clause of a join */
1224812306
IdList *pUsing; /* The USING clause of a join */
1224912307
Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
12250
- char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
12251
- Index *pIndex; /* Index structure corresponding to zIndex, if any */
12308
+ union {
12309
+ char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
12310
+ ExprList *pFuncArg; /* Arguments to table-valued-function */
12311
+ } u1;
12312
+ Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */
1225212313
} a[1]; /* One entry for each identifier on the list */
1225312314
};
1225412315
1225512316
/*
1225612317
** Permitted values of the SrcList.a.jointype field
@@ -12332,10 +12393,11 @@
1233212393
#define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
1233312394
#define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
1233412395
#define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
1233512396
#define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
1233612397
#define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
12398
+#define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
1233712399
#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
1233812400
1233912401
/*
1234012402
** An instance of the following structure contains all information
1234112403
** needed to generate code for a single SELECT statement.
@@ -12601,11 +12663,11 @@
1260112663
int nSet; /* Number of sets used so far */
1260212664
int nOnce; /* Number of OP_Once instructions so far */
1260312665
int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
1260412666
int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
1260512667
int ckBase; /* Base register of data during check constraints */
12606
- int iPartIdxTab; /* Table corresponding to a partial index */
12668
+ int iSelfTab; /* Table of an index whose exprs are being coded */
1260712669
int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
1260812670
int iCacheCnt; /* Counter used to generate aColCache[].lru values */
1260912671
int nLabel; /* Number of labels used */
1261012672
int *aLabel; /* Space to hold the labels */
1261112673
struct yColCache {
@@ -12971,11 +13033,11 @@
1297113033
With *pOuter; /* Containing WITH clause, or NULL */
1297213034
struct Cte { /* For each CTE in the WITH clause.... */
1297313035
char *zName; /* Name of this CTE */
1297413036
ExprList *pCols; /* List of explicit column names, or NULL */
1297513037
Select *pSelect; /* The definition of this CTE */
12976
- const char *zErr; /* Error message for circular references */
13038
+ const char *zCteErr; /* Error message for circular references */
1297713039
} a[1];
1297813040
};
1297913041
1298013042
#ifdef SQLITE_DEBUG
1298113043
/*
@@ -13119,10 +13181,15 @@
1311913181
SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3NoopMutex(void);
1312013182
SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int);
1312113183
SQLITE_PRIVATE int sqlite3MutexInit(void);
1312213184
SQLITE_PRIVATE int sqlite3MutexEnd(void);
1312313185
#endif
13186
+#if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP)
13187
+SQLITE_PRIVATE void sqlite3MemoryBarrier(void);
13188
+#else
13189
+# define sqlite3MemoryBarrier();
13190
+#endif
1312413191
1312513192
SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
1312613193
SQLITE_PRIVATE void sqlite3StatusUp(int, int);
1312713194
SQLITE_PRIVATE void sqlite3StatusDown(int, int);
1312813195
SQLITE_PRIVATE void sqlite3StatusSet(int, int);
@@ -13185,10 +13252,11 @@
1318513252
SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
1318613253
SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
1318713254
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
1318813255
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
1318913256
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
13257
+SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
1319013258
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
1319113259
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
1319213260
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
1319313261
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
1319413262
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
@@ -13197,10 +13265,12 @@
1319713265
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
1319813266
SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
1319913267
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
1320013268
SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
1320113269
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
13270
+SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
13271
+SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
1320213272
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
1320313273
SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
1320413274
SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
1320513275
SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
1320613276
SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
@@ -13238,11 +13308,11 @@
1323813308
SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
1323913309
SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64);
1324013310
SQLITE_PRIVATE int sqlite3RowSetTest(RowSet*, int iBatch, i64);
1324113311
SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*);
1324213312
13243
-SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
13313
+SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Select*,int,int);
1324413314
1324513315
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
1324613316
SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
1324713317
#else
1324813318
# define sqlite3ViewGetColumnNames(A,B) 0
@@ -13268,10 +13338,11 @@
1326813338
SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
1326913339
SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
1327013340
SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
1327113341
Token*, Select*, Expr*, IdList*);
1327213342
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
13343
+SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
1327313344
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
1327413345
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
1327513346
SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
1327613347
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
1327713348
SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
@@ -13298,10 +13369,11 @@
1329813369
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
1329913370
SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
1330013371
SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
1330113372
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
1330213373
SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
13374
+SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
1330313375
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
1330413376
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
1330513377
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1330613378
SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
1330713379
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
@@ -13313,13 +13385,14 @@
1331313385
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
1331413386
SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
1331513387
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1331613388
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
1331713389
SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
13318
-SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
13390
+SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
1331913391
#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
1332013392
#define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
13393
+#define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
1332113394
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1332213395
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
1332313396
SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
1332413397
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
1332513398
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
@@ -13487,11 +13560,11 @@
1348713560
sqlite3PutVarint((A),(B)))
1348813561
#define getVarint sqlite3GetVarint
1348913562
#define putVarint sqlite3PutVarint
1349013563
1349113564
13492
-SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
13565
+SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
1349313566
SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
1349413567
SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
1349513568
SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
1349613569
SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
1349713570
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
@@ -13559,10 +13632,11 @@
1355913632
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
1356013633
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
1356113634
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
1356213635
SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
1356313636
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
13637
+SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
1356413638
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
1356513639
SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
1356613640
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
1356713641
SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
1356813642
SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
@@ -13667,10 +13741,12 @@
1366713741
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
1366813742
SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
1366913743
SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
1367013744
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
1367113745
#endif
13746
+SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
13747
+SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
1367213748
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
1367313749
SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
1367413750
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
1367513751
SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*);
1367613752
SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*);
@@ -14770,10 +14846,11 @@
1477014846
RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
1477114847
VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
1477214848
} u;
1477314849
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
1477414850
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
14851
+ u8 eSubtype; /* Subtype for this value */
1477514852
int n; /* Number of characters in string value, excluding '\0' */
1477614853
char *z; /* String or BLOB value */
1477714854
/* ShallowCopy only needs to copy the information above */
1477814855
char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
1477914856
int szMalloc; /* Size of the zMalloc allocation */
@@ -16546,18 +16623,18 @@
1654616623
** external linkage.
1654716624
*/
1654816625
SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
1654916626
static SQLITE_WSD FuncDef aDateTimeFuncs[] = {
1655016627
#ifndef SQLITE_OMIT_DATETIME_FUNCS
16551
- FUNCTION(julianday, -1, 0, 0, juliandayFunc ),
16552
- FUNCTION(date, -1, 0, 0, dateFunc ),
16553
- FUNCTION(time, -1, 0, 0, timeFunc ),
16554
- FUNCTION(datetime, -1, 0, 0, datetimeFunc ),
16555
- FUNCTION(strftime, -1, 0, 0, strftimeFunc ),
16556
- FUNCTION(current_time, 0, 0, 0, ctimeFunc ),
16557
- FUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
16558
- FUNCTION(current_date, 0, 0, 0, cdateFunc ),
16628
+ DFUNCTION(julianday, -1, 0, 0, juliandayFunc ),
16629
+ DFUNCTION(date, -1, 0, 0, dateFunc ),
16630
+ DFUNCTION(time, -1, 0, 0, timeFunc ),
16631
+ DFUNCTION(datetime, -1, 0, 0, datetimeFunc ),
16632
+ DFUNCTION(strftime, -1, 0, 0, strftimeFunc ),
16633
+ DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
16634
+ DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
16635
+ DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
1655916636
#else
1656016637
STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
1656116638
STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc),
1656216639
STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
1656316640
#endif
@@ -19273,10 +19350,11 @@
1927319350
pTo->xMutexEnter = pFrom->xMutexEnter;
1927419351
pTo->xMutexTry = pFrom->xMutexTry;
1927519352
pTo->xMutexLeave = pFrom->xMutexLeave;
1927619353
pTo->xMutexHeld = pFrom->xMutexHeld;
1927719354
pTo->xMutexNotheld = pFrom->xMutexNotheld;
19355
+ sqlite3MemoryBarrier();
1927819356
pTo->xMutexAlloc = pFrom->xMutexAlloc;
1927919357
}
1928019358
rc = sqlite3GlobalConfig.mutex.xMutexInit();
1928119359
1928219360
#ifdef SQLITE_DEBUG
@@ -19679,10 +19757,21 @@
1967919757
}
1968019758
static int pthreadMutexNotheld(sqlite3_mutex *p){
1968119759
return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0;
1968219760
}
1968319761
#endif
19762
+
19763
+/*
19764
+** Try to provide a memory barrier operation, needed for initialization only.
19765
+*/
19766
+SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
19767
+#if defined(SQLITE_MEMORY_BARRIER)
19768
+ SQLITE_MEMORY_BARRIER;
19769
+#elif defined(__GNUC__)
19770
+ __sync_synchronize();
19771
+#endif
19772
+}
1968419773
1968519774
/*
1968619775
** Initialize and deinitialize the mutex subsystem.
1968719776
*/
1968819777
static int pthreadMutexInit(void){ return SQLITE_OK; }
@@ -20341,10 +20430,23 @@
2034120430
static int winMutexNotheld(sqlite3_mutex *p){
2034220431
DWORD tid = GetCurrentThreadId();
2034320432
return winMutexNotheld2(p, tid);
2034420433
}
2034520434
#endif
20435
+
20436
+/*
20437
+** Try to provide a memory barrier operation, needed for initialization only.
20438
+*/
20439
+SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
20440
+#if defined(SQLITE_MEMORY_BARRIER)
20441
+ SQLITE_MEMORY_BARRIER;
20442
+#elif defined(__GNUC__)
20443
+ __sync_synchronize();
20444
+#else
20445
+ MemoryBarrier();
20446
+#endif
20447
+}
2034620448
2034720449
/*
2034820450
** Initialize and deinitialize the mutex subsystem.
2034920451
*/
2035020452
static sqlite3_mutex winMutex_staticMutexes[] = {
@@ -20695,20 +20797,11 @@
2069520797
/*
2069620798
** State information local to the memory allocation subsystem.
2069720799
*/
2069820800
static SQLITE_WSD struct Mem0Global {
2069920801
sqlite3_mutex *mutex; /* Mutex to serialize access */
20700
-
20701
- /*
20702
- ** The alarm callback and its arguments. The mem0.mutex lock will
20703
- ** be held while the callback is running. Recursive calls into
20704
- ** the memory subsystem are allowed, but no new callbacks will be
20705
- ** issued.
20706
- */
20707
- sqlite3_int64 alarmThreshold;
20708
- void (*alarmCallback)(void*, sqlite3_int64,int);
20709
- void *alarmArg;
20802
+ sqlite3_int64 alarmThreshold; /* The soft heap limit */
2071020803
2071120804
/*
2071220805
** Pointers to the end of sqlite3GlobalConfig.pScratch memory
2071320806
** (so that a range test can be used to determine if an allocation
2071420807
** being freed came from pScratch) and a pointer to the list of
@@ -20721,11 +20814,11 @@
2072120814
/*
2072220815
** True if heap is nearly "full" where "full" is defined by the
2072320816
** sqlite3_soft_heap_limit() setting.
2072420817
*/
2072520818
int nearlyFull;
20726
-} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
20819
+} mem0 = { 0, 0, 0, 0, 0, 0 };
2072720820
2072820821
#define mem0 GLOBAL(struct Mem0Global, mem0)
2072920822
2073020823
/*
2073120824
** Return the memory allocator mutex. sqlite3_status() needs it.
@@ -20732,54 +20825,25 @@
2073220825
*/
2073320826
SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void){
2073420827
return mem0.mutex;
2073520828
}
2073620829
20737
-/*
20738
-** This routine runs when the memory allocator sees that the
20739
-** total memory allocation is about to exceed the soft heap
20740
-** limit.
20741
-*/
20742
-static void softHeapLimitEnforcer(
20743
- void *NotUsed,
20744
- sqlite3_int64 NotUsed2,
20745
- int allocSize
20746
-){
20747
- UNUSED_PARAMETER2(NotUsed, NotUsed2);
20748
- sqlite3_release_memory(allocSize);
20749
-}
20750
-
20751
-/*
20752
-** Change the alarm callback
20753
-*/
20754
-static int sqlite3MemoryAlarm(
20755
- void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
20756
- void *pArg,
20757
- sqlite3_int64 iThreshold
20758
-){
20759
- sqlite3_int64 nUsed;
20760
- sqlite3_mutex_enter(mem0.mutex);
20761
- mem0.alarmCallback = xCallback;
20762
- mem0.alarmArg = pArg;
20763
- mem0.alarmThreshold = iThreshold;
20764
- nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20765
- mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
20766
- sqlite3_mutex_leave(mem0.mutex);
20767
- return SQLITE_OK;
20768
-}
20769
-
2077020830
#ifndef SQLITE_OMIT_DEPRECATED
2077120831
/*
20772
-** Deprecated external interface. Internal/core SQLite code
20773
-** should call sqlite3MemoryAlarm.
20832
+** Deprecated external interface. It used to set an alarm callback
20833
+** that was invoked when memory usage grew too large. Now it is a
20834
+** no-op.
2077420835
*/
2077520836
SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
2077620837
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
2077720838
void *pArg,
2077820839
sqlite3_int64 iThreshold
2077920840
){
20780
- return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
20841
+ (void)xCallback;
20842
+ (void)pArg;
20843
+ (void)iThreshold;
20844
+ return SQLITE_OK;
2078120845
}
2078220846
#endif
2078320847
2078420848
/*
2078520849
** Set the soft heap-size limit for the library. Passing a zero or
@@ -20786,23 +20850,25 @@
2078620850
** negative value indicates no limit.
2078720851
*/
2078820852
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
2078920853
sqlite3_int64 priorLimit;
2079020854
sqlite3_int64 excess;
20855
+ sqlite3_int64 nUsed;
2079120856
#ifndef SQLITE_OMIT_AUTOINIT
2079220857
int rc = sqlite3_initialize();
2079320858
if( rc ) return -1;
2079420859
#endif
2079520860
sqlite3_mutex_enter(mem0.mutex);
2079620861
priorLimit = mem0.alarmThreshold;
20862
+ if( n<0 ){
20863
+ sqlite3_mutex_leave(mem0.mutex);
20864
+ return priorLimit;
20865
+ }
20866
+ mem0.alarmThreshold = n;
20867
+ nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20868
+ mem0.nearlyFull = (n>0 && n<=nUsed);
2079720869
sqlite3_mutex_leave(mem0.mutex);
20798
- if( n<0 ) return priorLimit;
20799
- if( n>0 ){
20800
- sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
20801
- }else{
20802
- sqlite3MemoryAlarm(0, 0, 0);
20803
- }
2080420870
excess = sqlite3_memory_used() - n;
2080520871
if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
2080620872
return priorLimit;
2080720873
}
2080820874
SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
@@ -20895,23 +20961,14 @@
2089520961
2089620962
/*
2089720963
** Trigger the alarm
2089820964
*/
2089920965
static void sqlite3MallocAlarm(int nByte){
20900
- void (*xCallback)(void*,sqlite3_int64,int);
20901
- sqlite3_int64 nowUsed;
20902
- void *pArg;
20903
- if( mem0.alarmCallback==0 ) return;
20904
- xCallback = mem0.alarmCallback;
20905
- nowUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20906
- pArg = mem0.alarmArg;
20907
- mem0.alarmCallback = 0;
20966
+ if( mem0.alarmThreshold<=0 ) return;
2090820967
sqlite3_mutex_leave(mem0.mutex);
20909
- xCallback(pArg, nowUsed, nByte);
20968
+ sqlite3_release_memory(nByte);
2091020969
sqlite3_mutex_enter(mem0.mutex);
20911
- mem0.alarmCallback = xCallback;
20912
- mem0.alarmArg = pArg;
2091320970
}
2091420971
2091520972
/*
2091620973
** Do a memory allocation with statistics and alarms. Assume the
2091720974
** lock is already held.
@@ -20920,11 +20977,11 @@
2092020977
int nFull;
2092120978
void *p;
2092220979
assert( sqlite3_mutex_held(mem0.mutex) );
2092320980
nFull = sqlite3GlobalConfig.m.xRoundup(n);
2092420981
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
20925
- if( mem0.alarmCallback!=0 ){
20982
+ if( mem0.alarmThreshold>0 ){
2092620983
sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
2092720984
if( nUsed >= mem0.alarmThreshold - nFull ){
2092820985
mem0.nearlyFull = 1;
2092920986
sqlite3MallocAlarm(nFull);
2093020987
}else{
@@ -20931,11 +20988,11 @@
2093120988
mem0.nearlyFull = 0;
2093220989
}
2093320990
}
2093420991
p = sqlite3GlobalConfig.m.xMalloc(nFull);
2093520992
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
20936
- if( p==0 && mem0.alarmCallback ){
20993
+ if( p==0 && mem0.alarmThreshold>0 ){
2093720994
sqlite3MallocAlarm(nFull);
2093820995
p = sqlite3GlobalConfig.m.xMalloc(nFull);
2093920996
}
2094020997
#endif
2094120998
if( p ){
@@ -21106,23 +21163,24 @@
2110621163
SQLITE_PRIVATE int sqlite3MallocSize(void *p){
2110721164
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2110821165
return sqlite3GlobalConfig.m.xSize(p);
2110921166
}
2111021167
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
21111
- if( db==0 ){
21112
- assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
21113
- assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
21114
- return sqlite3MallocSize(p);
21115
- }else{
21116
- assert( sqlite3_mutex_held(db->mutex) );
21117
- if( isLookaside(db, p) ){
21118
- return db->lookaside.sz;
21168
+ if( db==0 || !isLookaside(db,p) ){
21169
+#if SQLITE_DEBUG
21170
+ if( db==0 ){
21171
+ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
21172
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2111921173
}else{
2112021174
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2112121175
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
21122
- return sqlite3GlobalConfig.m.xSize(p);
2112321176
}
21177
+#endif
21178
+ return sqlite3GlobalConfig.m.xSize(p);
21179
+ }else{
21180
+ assert( sqlite3_mutex_held(db->mutex) );
21181
+ return db->lookaside.sz;
2112421182
}
2112521183
}
2112621184
SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
2112721185
assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2112821186
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
@@ -21219,11 +21277,11 @@
2121921277
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
2122021278
mem0.alarmThreshold-nDiff ){
2122121279
sqlite3MallocAlarm(nDiff);
2122221280
}
2122321281
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21224
- if( pNew==0 && mem0.alarmCallback ){
21282
+ if( pNew==0 && mem0.alarmThreshold>0 ){
2122521283
sqlite3MallocAlarm((int)nBytes);
2122621284
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2122721285
}
2122821286
if( pNew ){
2122921287
nNew = sqlite3MallocSize(pNew);
@@ -21933,25 +21991,20 @@
2193321991
break;
2193421992
}
2193521993
if( realvalue>0.0 ){
2193621994
LONGDOUBLE_TYPE scale = 1.0;
2193721995
while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;}
21938
- while( realvalue>=1e64*scale && exp<=350 ){ scale *= 1e64; exp+=64; }
21939
- while( realvalue>=1e8*scale && exp<=350 ){ scale *= 1e8; exp+=8; }
21996
+ while( realvalue>=1e10*scale && exp<=350 ){ scale *= 1e10; exp+=10; }
2194021997
while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
2194121998
realvalue /= scale;
2194221999
while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
2194322000
while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
2194422001
if( exp>350 ){
21945
- if( prefix=='-' ){
21946
- bufpt = "-Inf";
21947
- }else if( prefix=='+' ){
21948
- bufpt = "+Inf";
21949
- }else{
21950
- bufpt = "Inf";
21951
- }
21952
- length = sqlite3Strlen30(bufpt);
22002
+ bufpt = buf;
22003
+ buf[0] = prefix;
22004
+ memcpy(buf+(prefix!=0),"Inf",4);
22005
+ length = 3+(prefix!=0);
2195322006
break;
2195422007
}
2195522008
}
2195622009
bufpt = buf;
2195722010
/*
@@ -22096,27 +22149,28 @@
2209622149
break;
2209722150
case etSTRING:
2209822151
case etDYNSTRING:
2209922152
if( bArgList ){
2210022153
bufpt = getTextArg(pArgList);
22154
+ xtype = etSTRING;
2210122155
}else{
2210222156
bufpt = va_arg(ap,char*);
2210322157
}
2210422158
if( bufpt==0 ){
2210522159
bufpt = "";
22106
- }else if( xtype==etDYNSTRING && !bArgList ){
22160
+ }else if( xtype==etDYNSTRING ){
2210722161
zExtra = bufpt;
2210822162
}
2210922163
if( precision>=0 ){
2211022164
for(length=0; length<precision && bufpt[length]; length++){}
2211122165
}else{
2211222166
length = sqlite3Strlen30(bufpt);
2211322167
}
2211422168
break;
22115
- case etSQLESCAPE:
22116
- case etSQLESCAPE2:
22117
- case etSQLESCAPE3: {
22169
+ case etSQLESCAPE: /* Escape ' characters */
22170
+ case etSQLESCAPE2: /* Escape ' and enclose in '...' */
22171
+ case etSQLESCAPE3: { /* Escape " characters */
2211822172
int i, j, k, n, isnull;
2211922173
int needQuote;
2212022174
char ch;
2212122175
char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
2212222176
char *escarg;
@@ -22131,11 +22185,11 @@
2213122185
k = precision;
2213222186
for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
2213322187
if( ch==q ) n++;
2213422188
}
2213522189
needQuote = !isnull && xtype==etSQLESCAPE2;
22136
- n += i + 1 + needQuote*2;
22190
+ n += i + 3;
2213722191
if( n>etBUFSIZE ){
2213822192
bufpt = zExtra = sqlite3Malloc( n );
2213922193
if( bufpt==0 ){
2214022194
setStrAccumError(pAccum, STRACCUM_NOMEM);
2214122195
return;
@@ -22527,11 +22581,12 @@
2252722581
}
2252822582
#endif
2252922583
2253022584
2253122585
/*
22532
-** variable-argument wrapper around sqlite3VXPrintf().
22586
+** variable-argument wrapper around sqlite3VXPrintf(). The bFlags argument
22587
+** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
2253322588
*/
2253422589
SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
2253522590
va_list ap;
2253622591
va_start(ap,zFormat);
2253722592
sqlite3VXPrintf(p, bFlags, zFormat, ap);
@@ -22625,94 +22680,104 @@
2262522680
/*
2262622681
** Generate a human-readable description of a the Select object.
2262722682
*/
2262822683
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
2262922684
int n = 0;
22630
- pView = sqlite3TreeViewPush(pView, moreToFollow);
22631
- sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
22632
- ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
22633
- ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
22634
- );
22635
- if( p->pSrc && p->pSrc->nSrc ) n++;
22636
- if( p->pWhere ) n++;
22637
- if( p->pGroupBy ) n++;
22638
- if( p->pHaving ) n++;
22639
- if( p->pOrderBy ) n++;
22640
- if( p->pLimit ) n++;
22641
- if( p->pOffset ) n++;
22642
- if( p->pPrior ) n++;
22643
- sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
22644
- if( p->pSrc && p->pSrc->nSrc ){
22645
- int i;
22646
- pView = sqlite3TreeViewPush(pView, (n--)>0);
22647
- sqlite3TreeViewLine(pView, "FROM");
22648
- for(i=0; i<p->pSrc->nSrc; i++){
22649
- struct SrcList_item *pItem = &p->pSrc->a[i];
22650
- StrAccum x;
22651
- char zLine[100];
22652
- sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
22653
- sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
22654
- if( pItem->zDatabase ){
22655
- sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
22656
- }else if( pItem->zName ){
22657
- sqlite3XPrintf(&x, 0, " %s", pItem->zName);
22658
- }
22659
- if( pItem->pTab ){
22660
- sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
22661
- }
22662
- if( pItem->zAlias ){
22663
- sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
22664
- }
22665
- if( pItem->jointype & JT_LEFT ){
22666
- sqlite3XPrintf(&x, 0, " LEFT-JOIN");
22667
- }
22668
- sqlite3StrAccumFinish(&x);
22669
- sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
22670
- if( pItem->pSelect ){
22671
- sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
22672
- }
22673
- sqlite3TreeViewPop(pView);
22674
- }
22675
- sqlite3TreeViewPop(pView);
22676
- }
22677
- if( p->pWhere ){
22678
- sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
22679
- sqlite3TreeViewExpr(pView, p->pWhere, 0);
22680
- sqlite3TreeViewPop(pView);
22681
- }
22682
- if( p->pGroupBy ){
22683
- sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
22684
- }
22685
- if( p->pHaving ){
22686
- sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
22687
- sqlite3TreeViewExpr(pView, p->pHaving, 0);
22688
- sqlite3TreeViewPop(pView);
22689
- }
22690
- if( p->pOrderBy ){
22691
- sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
22692
- }
22693
- if( p->pLimit ){
22694
- sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
22695
- sqlite3TreeViewExpr(pView, p->pLimit, 0);
22696
- sqlite3TreeViewPop(pView);
22697
- }
22698
- if( p->pOffset ){
22699
- sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
22700
- sqlite3TreeViewExpr(pView, p->pOffset, 0);
22701
- sqlite3TreeViewPop(pView);
22702
- }
22703
- if( p->pPrior ){
22704
- const char *zOp = "UNION";
22705
- switch( p->op ){
22706
- case TK_ALL: zOp = "UNION ALL"; break;
22707
- case TK_INTERSECT: zOp = "INTERSECT"; break;
22708
- case TK_EXCEPT: zOp = "EXCEPT"; break;
22709
- }
22710
- sqlite3TreeViewItem(pView, zOp, (n--)>0);
22711
- sqlite3TreeViewSelect(pView, p->pPrior, 0);
22712
- sqlite3TreeViewPop(pView);
22713
- }
22685
+ int cnt = 0;
22686
+ pView = sqlite3TreeViewPush(pView, moreToFollow);
22687
+ do{
22688
+ sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
22689
+ ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
22690
+ ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
22691
+ );
22692
+ if( cnt++ ) sqlite3TreeViewPop(pView);
22693
+ if( p->pPrior ){
22694
+ n = 1000;
22695
+ }else{
22696
+ n = 0;
22697
+ if( p->pSrc && p->pSrc->nSrc ) n++;
22698
+ if( p->pWhere ) n++;
22699
+ if( p->pGroupBy ) n++;
22700
+ if( p->pHaving ) n++;
22701
+ if( p->pOrderBy ) n++;
22702
+ if( p->pLimit ) n++;
22703
+ if( p->pOffset ) n++;
22704
+ }
22705
+ sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
22706
+ if( p->pSrc && p->pSrc->nSrc ){
22707
+ int i;
22708
+ pView = sqlite3TreeViewPush(pView, (n--)>0);
22709
+ sqlite3TreeViewLine(pView, "FROM");
22710
+ for(i=0; i<p->pSrc->nSrc; i++){
22711
+ struct SrcList_item *pItem = &p->pSrc->a[i];
22712
+ StrAccum x;
22713
+ char zLine[100];
22714
+ sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
22715
+ sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
22716
+ if( pItem->zDatabase ){
22717
+ sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
22718
+ }else if( pItem->zName ){
22719
+ sqlite3XPrintf(&x, 0, " %s", pItem->zName);
22720
+ }
22721
+ if( pItem->pTab ){
22722
+ sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
22723
+ }
22724
+ if( pItem->zAlias ){
22725
+ sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
22726
+ }
22727
+ if( pItem->fg.jointype & JT_LEFT ){
22728
+ sqlite3XPrintf(&x, 0, " LEFT-JOIN");
22729
+ }
22730
+ sqlite3StrAccumFinish(&x);
22731
+ sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
22732
+ if( pItem->pSelect ){
22733
+ sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
22734
+ }
22735
+ if( pItem->fg.isTabFunc ){
22736
+ sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
22737
+ }
22738
+ sqlite3TreeViewPop(pView);
22739
+ }
22740
+ sqlite3TreeViewPop(pView);
22741
+ }
22742
+ if( p->pWhere ){
22743
+ sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
22744
+ sqlite3TreeViewExpr(pView, p->pWhere, 0);
22745
+ sqlite3TreeViewPop(pView);
22746
+ }
22747
+ if( p->pGroupBy ){
22748
+ sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
22749
+ }
22750
+ if( p->pHaving ){
22751
+ sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
22752
+ sqlite3TreeViewExpr(pView, p->pHaving, 0);
22753
+ sqlite3TreeViewPop(pView);
22754
+ }
22755
+ if( p->pOrderBy ){
22756
+ sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
22757
+ }
22758
+ if( p->pLimit ){
22759
+ sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
22760
+ sqlite3TreeViewExpr(pView, p->pLimit, 0);
22761
+ sqlite3TreeViewPop(pView);
22762
+ }
22763
+ if( p->pOffset ){
22764
+ sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
22765
+ sqlite3TreeViewExpr(pView, p->pOffset, 0);
22766
+ sqlite3TreeViewPop(pView);
22767
+ }
22768
+ if( p->pPrior ){
22769
+ const char *zOp = "UNION";
22770
+ switch( p->op ){
22771
+ case TK_ALL: zOp = "UNION ALL"; break;
22772
+ case TK_INTERSECT: zOp = "INTERSECT"; break;
22773
+ case TK_EXCEPT: zOp = "EXCEPT"; break;
22774
+ }
22775
+ sqlite3TreeViewItem(pView, zOp, 1);
22776
+ }
22777
+ p = p->pPrior;
22778
+ }while( p!=0 );
2271422779
sqlite3TreeViewPop(pView);
2271522780
}
2271622781
2271722782
/*
2271822783
** Generate a human-readable explanation of an expression tree.
@@ -22783,15 +22848,10 @@
2278322848
}
2278422849
case TK_REGISTER: {
2278522850
sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
2278622851
break;
2278722852
}
22788
- case TK_AS: {
22789
- sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
22790
- sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
22791
- break;
22792
- }
2279322853
case TK_ID: {
2279422854
sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
2279522855
break;
2279622856
}
2279722857
#ifndef SQLITE_OMIT_CAST
@@ -22962,11 +23022,17 @@
2296223022
if( pList==0 ){
2296323023
sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
2296423024
}else{
2296523025
sqlite3TreeViewLine(pView, "%s", zLabel);
2296623026
for(i=0; i<pList->nExpr; i++){
23027
+ int j = pList->a[i].u.x.iOrderByCol;
23028
+ if( j ){
23029
+ sqlite3TreeViewPush(pView, 0);
23030
+ sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
23031
+ }
2296723032
sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
23033
+ if( j ) sqlite3TreeViewPop(pView);
2296823034
}
2296923035
}
2297023036
sqlite3TreeViewPop(pView);
2297123037
}
2297223038
@@ -24977,15 +25043,12 @@
2497725043
/*
2497825044
** Return the number of bytes that will be needed to store the given
2497925045
** 64-bit integer.
2498025046
*/
2498125047
SQLITE_PRIVATE int sqlite3VarintLen(u64 v){
24982
- int i = 0;
24983
- do{
24984
- i++;
24985
- v >>= 7;
24986
- }while( v!=0 && ALWAYS(i<9) );
25048
+ int i;
25049
+ for(i=1; (v >>= 7)!=0; i++){ assert( i<9 ); }
2498725050
return i;
2498825051
}
2498925052
2499025053
2499125054
/*
@@ -24994,15 +25057,17 @@
2499425057
SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
2499525058
#if SQLITE_BYTEORDER==4321
2499625059
u32 x;
2499725060
memcpy(&x,p,4);
2499825061
return x;
24999
-#elif SQLITE_BYTEORDER==1234 && defined(__GNUC__) && GCC_VERSION>=4003000
25062
+#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
25063
+ && defined(__GNUC__) && GCC_VERSION>=4003000
2500025064
u32 x;
2500125065
memcpy(&x,p,4);
2500225066
return __builtin_bswap32(x);
25003
-#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
25067
+#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
25068
+ && defined(_MSC_VER) && _MSC_VER>=1300
2500425069
u32 x;
2500525070
memcpy(&x,p,4);
2500625071
return _byteswap_ulong(x);
2500725072
#else
2500825073
testcase( p[0]&0x80 );
@@ -29103,11 +29168,10 @@
2910329168
i64 newOffset;
2910429169
#endif
2910529170
TIMER_START;
2910629171
assert( cnt==(cnt&0x1ffff) );
2910729172
assert( id->h>2 );
29108
- cnt &= 0x1ffff;
2910929173
do{
2911029174
#if defined(USE_PREAD)
2911129175
got = osPread(id->h, pBuf, cnt, offset);
2911229176
SimulateIOError( got = -1 );
2911329177
#elif defined(USE_PREAD64)
@@ -29320,20 +29384,20 @@
2932029384
amt -= nCopy;
2932129385
offset += nCopy;
2932229386
}
2932329387
}
2932429388
#endif
29325
-
29326
- while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){
29389
+
29390
+ while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
2932729391
amt -= wrote;
2932829392
offset += wrote;
2932929393
pBuf = &((char*)pBuf)[wrote];
2933029394
}
2933129395
SimulateIOError(( wrote=(-1), amt=1 ));
2933229396
SimulateDiskfullError(( wrote=0, amt=1 ));
2933329397
29334
- if( amt>0 ){
29398
+ if( amt>wrote ){
2933529399
if( wrote<0 && pFile->lastErrno!=ENOSPC ){
2933629400
/* lastErrno set by seekAndWrite */
2933729401
return SQLITE_IOERR_WRITE;
2933829402
}else{
2933929403
storeLastErrno(pFile, 0); /* not a system error */
@@ -39798,11 +39862,11 @@
3979839862
** A complete page cache is an instance of this structure.
3979939863
*/
3980039864
struct PCache {
3980139865
PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
3980239866
PgHdr *pSynced; /* Last synced page in dirty page list */
39803
- int nRef; /* Number of referenced pages */
39867
+ int nRefSum; /* Sum of ref counts over all pages */
3980439868
int szCache; /* Configured cache size */
3980539869
int szPage; /* Size of every page in this cache */
3980639870
int szExtra; /* Size of extra space for each page */
3980739871
u8 bPurgeable; /* True if pages are on backing store */
3980839872
u8 eCreate; /* eCreate value for for xFetch() */
@@ -39963,11 +40027,11 @@
3996340027
/*
3996440028
** Change the page size for PCache object. The caller must ensure that there
3996540029
** are no outstanding page references when this function is called.
3996640030
*/
3996740031
SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
39968
- assert( pCache->nRef==0 && pCache->pDirty==0 );
40032
+ assert( pCache->nRefSum==0 && pCache->pDirty==0 );
3996940033
if( pCache->szPage ){
3997040034
sqlite3_pcache *pNew;
3997140035
pNew = sqlite3GlobalConfig.pcache2.xCreate(
3997240036
szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
3997340037
pCache->bPurgeable
@@ -40130,13 +40194,11 @@
4013040194
pPgHdr = (PgHdr *)pPage->pExtra;
4013140195
4013240196
if( !pPgHdr->pPage ){
4013340197
return pcacheFetchFinishWithInit(pCache, pgno, pPage);
4013440198
}
40135
- if( 0==pPgHdr->nRef ){
40136
- pCache->nRef++;
40137
- }
40199
+ pCache->nRefSum++;
4013840200
pPgHdr->nRef++;
4013940201
return pPgHdr;
4014040202
}
4014140203
4014240204
/*
@@ -40143,13 +40205,12 @@
4014340205
** Decrement the reference count on a page. If the page is clean and the
4014440206
** reference count drops to 0, then it is made eligible for recycling.
4014540207
*/
4014640208
SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
4014740209
assert( p->nRef>0 );
40148
- p->nRef--;
40149
- if( p->nRef==0 ){
40150
- p->pCache->nRef--;
40210
+ p->pCache->nRefSum--;
40211
+ if( (--p->nRef)==0 ){
4015140212
if( p->flags&PGHDR_CLEAN ){
4015240213
pcacheUnpin(p);
4015340214
}else if( p->pDirtyPrev!=0 ){
4015440215
/* Move the page to the head of the dirty list. */
4015540216
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
@@ -40161,10 +40222,11 @@
4016140222
** Increase the reference count of a supplied page by 1.
4016240223
*/
4016340224
SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
4016440225
assert(p->nRef>0);
4016540226
p->nRef++;
40227
+ p->pCache->nRefSum++;
4016640228
}
4016740229
4016840230
/*
4016940231
** Drop a page from the cache. There must be exactly one reference to the
4017040232
** page. This function deletes that reference, so after it returns the
@@ -40173,11 +40235,11 @@
4017340235
SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
4017440236
assert( p->nRef==1 );
4017540237
if( p->flags&PGHDR_DIRTY ){
4017640238
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
4017740239
}
40178
- p->pCache->nRef--;
40240
+ p->pCache->nRefSum--;
4017940241
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
4018040242
}
4018140243
4018240244
/*
4018340245
** Make sure the page is marked as dirty. If it isn't dirty already,
@@ -40269,15 +40331,15 @@
4026940331
if( ALWAYS(p->pgno>pgno) ){
4027040332
assert( p->flags&PGHDR_DIRTY );
4027140333
sqlite3PcacheMakeClean(p);
4027240334
}
4027340335
}
40274
- if( pgno==0 && pCache->nRef ){
40336
+ if( pgno==0 && pCache->nRefSum ){
4027540337
sqlite3_pcache_page *pPage1;
4027640338
pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
4027740339
if( ALWAYS(pPage1) ){ /* Page 1 is always available in cache, because
40278
- ** pCache->nRef>0 */
40340
+ ** pCache->nRefSum>0 */
4027940341
memset(pPage1->pBuf, 0, pCache->szPage);
4028040342
pgno = 1;
4028140343
}
4028240344
}
4028340345
sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
@@ -40379,14 +40441,17 @@
4037940441
}
4038040442
return pcacheSortDirtyList(pCache->pDirty);
4038140443
}
4038240444
4038340445
/*
40384
-** Return the total number of referenced pages held by the cache.
40446
+** Return the total number of references to all pages held by the cache.
40447
+**
40448
+** This is not the total number of pages referenced, but the sum of the
40449
+** reference count for all pages.
4038540450
*/
4038640451
SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
40387
- return pCache->nRef;
40452
+ return pCache->nRefSum;
4038840453
}
4038940454
4039040455
/*
4039140456
** Return the number of references to the page supplied as an argument.
4039240457
*/
@@ -40517,11 +40582,11 @@
4051740582
**
4051840583
** The third case is a chunk of heap memory (defaulting to 100 pages worth)
4051940584
** that is allocated when the page cache is created. The size of the local
4052040585
** bulk allocation can be adjusted using
4052140586
**
40522
-** sqlite3_config(SQLITE_CONFIG_PCACHE, 0, 0, N).
40587
+** sqlite3_config(SQLITE_CONFIG_PAGECACHE, 0, 0, N).
4052340588
**
4052440589
** If N is positive, then N pages worth of memory are allocated using a single
4052540590
** sqlite3Malloc() call and that memory is used for the first N pages allocated.
4052640591
** Or if N is negative, then -1024*N bytes of memory are allocated and used
4052740592
** for as many pages as can be accomodated.
@@ -40538,10 +40603,28 @@
4053840603
4053940604
typedef struct PCache1 PCache1;
4054040605
typedef struct PgHdr1 PgHdr1;
4054140606
typedef struct PgFreeslot PgFreeslot;
4054240607
typedef struct PGroup PGroup;
40608
+
40609
+/*
40610
+** Each cache entry is represented by an instance of the following
40611
+** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
40612
+** PgHdr1.pCache->szPage bytes is allocated directly before this structure
40613
+** in memory.
40614
+*/
40615
+struct PgHdr1 {
40616
+ sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
40617
+ unsigned int iKey; /* Key value (page number) */
40618
+ u8 isPinned; /* Page in use, not on the LRU list */
40619
+ u8 isBulkLocal; /* This page from bulk local storage */
40620
+ u8 isAnchor; /* This is the PGroup.lru element */
40621
+ PgHdr1 *pNext; /* Next in hash table chain */
40622
+ PCache1 *pCache; /* Cache that currently owns this page */
40623
+ PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
40624
+ PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
40625
+};
4054340626
4054440627
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
4054540628
** of one or more PCaches that are able to recycle each other's unpinned
4054640629
** pages when they are under memory pressure. A PGroup is an instance of
4054740630
** the following object.
@@ -40567,11 +40650,11 @@
4056740650
sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */
4056840651
unsigned int nMaxPage; /* Sum of nMax for purgeable caches */
4056940652
unsigned int nMinPage; /* Sum of nMin for purgeable caches */
4057040653
unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */
4057140654
unsigned int nCurrentPage; /* Number of purgeable pages allocated */
40572
- PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
40655
+ PgHdr1 lru; /* The beginning and end of the LRU list */
4057340656
};
4057440657
4057540658
/* Each page cache is an instance of the following object. Every
4057640659
** open database file (including each in-memory database and each
4057740660
** temporary or transient database) has a single page cache which
@@ -40605,27 +40688,10 @@
4060540688
PgHdr1 **apHash; /* Hash table for fast lookup by key */
4060640689
PgHdr1 *pFree; /* List of unused pcache-local pages */
4060740690
void *pBulk; /* Bulk memory used by pcache-local */
4060840691
};
4060940692
40610
-/*
40611
-** Each cache entry is represented by an instance of the following
40612
-** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
40613
-** PgHdr1.pCache->szPage bytes is allocated directly before this structure
40614
-** in memory.
40615
-*/
40616
-struct PgHdr1 {
40617
- sqlite3_pcache_page page;
40618
- unsigned int iKey; /* Key value (page number) */
40619
- u8 isPinned; /* Page in use, not on the LRU list */
40620
- u8 isBulkLocal; /* This page from bulk local storage */
40621
- PgHdr1 *pNext; /* Next in hash table chain */
40622
- PCache1 *pCache; /* Cache that currently owns this page */
40623
- PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
40624
- PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
40625
-};
40626
-
4062740693
/*
4062840694
** Free slots in the allocator used to divide up the global page cache
4062940695
** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
4063040696
*/
4063140697
struct PgFreeslot {
@@ -40681,10 +40747,11 @@
4068140747
# define PCACHE1_MIGHT_USE_GROUP_MUTEX 1
4068240748
#endif
4068340749
4068440750
/******************************************************************************/
4068540751
/******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
40752
+
4068640753
4068740754
/*
4068840755
** This function is called during initialization if a static buffer is
4068940756
** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
4069040757
** verb to sqlite3_config(). Parameter pBuf points to an allocation large
@@ -40741,10 +40808,11 @@
4074140808
for(i=0; i<nBulk; i++){
4074240809
PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
4074340810
pX->page.pBuf = zBulk;
4074440811
pX->page.pExtra = &pX[1];
4074540812
pX->isBulkLocal = 1;
40813
+ pX->isAnchor = 0;
4074640814
pX->pNext = pCache->pFree;
4074740815
pCache->pFree = pX;
4074840816
zBulk += pCache->szAlloc;
4074940817
}
4075040818
}
@@ -40844,11 +40912,11 @@
4084440912
#endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
4084540913
4084640914
/*
4084740915
** Allocate a new page object initially associated with cache pCache.
4084840916
*/
40849
-static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
40917
+static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
4085040918
PgHdr1 *p = 0;
4085140919
void *pPg;
4085240920
4085340921
assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
4085440922
if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
@@ -40862,10 +40930,11 @@
4086240930
** this mutex is not held. */
4086340931
assert( pcache1.separateCache==0 );
4086440932
assert( pCache->pGroup==&pcache1.grp );
4086540933
pcache1LeaveMutex(pCache->pGroup);
4086640934
#endif
40935
+ if( benignMalloc ) sqlite3BeginBenignMalloc();
4086740936
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
4086840937
pPg = pcache1Alloc(pCache->szPage);
4086940938
p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
4087040939
if( !pPg || !p ){
4087140940
pcache1Free(pPg);
@@ -40874,17 +40943,19 @@
4087440943
}
4087540944
#else
4087640945
pPg = pcache1Alloc(pCache->szAlloc);
4087740946
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
4087840947
#endif
40948
+ if( benignMalloc ) sqlite3EndBenignMalloc();
4087940949
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4088040950
pcache1EnterMutex(pCache->pGroup);
4088140951
#endif
4088240952
if( pPg==0 ) return 0;
4088340953
p->page.pBuf = pPg;
4088440954
p->page.pExtra = &p[1];
4088540955
p->isBulkLocal = 0;
40956
+ p->isAnchor = 0;
4088640957
}
4088740958
if( pCache->bPurgeable ){
4088840959
pCache->pGroup->nCurrentPage++;
4088940960
}
4089040961
return p;
@@ -41007,26 +41078,20 @@
4100741078
PCache1 *pCache;
4100841079
4100941080
assert( pPage!=0 );
4101041081
assert( pPage->isPinned==0 );
4101141082
pCache = pPage->pCache;
41012
- assert( pPage->pLruNext || pPage==pCache->pGroup->pLruTail );
41013
- assert( pPage->pLruPrev || pPage==pCache->pGroup->pLruHead );
41083
+ assert( pPage->pLruNext );
41084
+ assert( pPage->pLruPrev );
4101441085
assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
41015
- if( pPage->pLruPrev ){
41016
- pPage->pLruPrev->pLruNext = pPage->pLruNext;
41017
- }else{
41018
- pCache->pGroup->pLruHead = pPage->pLruNext;
41019
- }
41020
- if( pPage->pLruNext ){
41021
- pPage->pLruNext->pLruPrev = pPage->pLruPrev;
41022
- }else{
41023
- pCache->pGroup->pLruTail = pPage->pLruPrev;
41024
- }
41086
+ pPage->pLruPrev->pLruNext = pPage->pLruNext;
41087
+ pPage->pLruNext->pLruPrev = pPage->pLruPrev;
4102541088
pPage->pLruNext = 0;
4102641089
pPage->pLruPrev = 0;
4102741090
pPage->isPinned = 1;
41091
+ assert( pPage->isAnchor==0 );
41092
+ assert( pCache->pGroup->lru.isAnchor==1 );
4102841093
pCache->nRecyclable--;
4102941094
return pPage;
4103041095
}
4103141096
4103241097
@@ -41055,13 +41120,15 @@
4105541120
** If there are currently more than nMaxPage pages allocated, try
4105641121
** to recycle pages to reduce the number allocated to nMaxPage.
4105741122
*/
4105841123
static void pcache1EnforceMaxPage(PCache1 *pCache){
4105941124
PGroup *pGroup = pCache->pGroup;
41125
+ PgHdr1 *p;
4106041126
assert( sqlite3_mutex_held(pGroup->mutex) );
41061
- while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
41062
- PgHdr1 *p = pGroup->pLruTail;
41127
+ while( pGroup->nCurrentPage>pGroup->nMaxPage
41128
+ && (p=pGroup->lru.pLruPrev)->isAnchor==0
41129
+ ){
4106341130
assert( p->pCache->pGroup==pGroup );
4106441131
assert( p->isPinned==0 );
4106541132
pcache1PinPage(p);
4106641133
pcache1RemoveFromHash(p, 1);
4106741134
}
@@ -41191,10 +41258,14 @@
4119141258
pGroup = (PGroup*)&pCache[1];
4119241259
pGroup->mxPinned = 10;
4119341260
}else{
4119441261
pGroup = &pcache1.grp;
4119541262
}
41263
+ if( pGroup->lru.isAnchor==0 ){
41264
+ pGroup->lru.isAnchor = 1;
41265
+ pGroup->lru.pLruPrev = pGroup->lru.pLruNext = &pGroup->lru;
41266
+ }
4119641267
pCache->pGroup = pGroup;
4119741268
pCache->szPage = szPage;
4119841269
pCache->szExtra = szExtra;
4119941270
pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
4120041271
pCache->bPurgeable = (bPurgeable ? 1 : 0);
@@ -41298,15 +41369,15 @@
4129841369
if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
4129941370
assert( pCache->nHash>0 && pCache->apHash );
4130041371
4130141372
/* Step 4. Try to recycle a page. */
4130241373
if( pCache->bPurgeable
41303
- && pGroup->pLruTail
41374
+ && !pGroup->lru.pLruPrev->isAnchor
4130441375
&& ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
4130541376
){
4130641377
PCache1 *pOther;
41307
- pPage = pGroup->pLruTail;
41378
+ pPage = pGroup->lru.pLruPrev;
4130841379
assert( pPage->isPinned==0 );
4130941380
pcache1RemoveFromHash(pPage, 0);
4131041381
pcache1PinPage(pPage);
4131141382
pOther = pPage->pCache;
4131241383
if( pOther->szAlloc != pCache->szAlloc ){
@@ -41319,13 +41390,11 @@
4131941390
4132041391
/* Step 5. If a usable page buffer has still not been found,
4132141392
** attempt to allocate a new one.
4132241393
*/
4132341394
if( !pPage ){
41324
- if( createFlag==1 ){ sqlite3BeginBenignMalloc(); }
41325
- pPage = pcache1AllocPage(pCache);
41326
- if( createFlag==1 ){ sqlite3EndBenignMalloc(); }
41395
+ pPage = pcache1AllocPage(pCache, createFlag==1);
4132741396
}
4132841397
4132941398
if( pPage ){
4133041399
unsigned int h = iKey % pCache->nHash;
4133141400
pCache->nPage++;
@@ -41413,11 +41482,14 @@
4141341482
4141441483
/* Step 1: Search the hash table for an existing entry. */
4141541484
pPage = pCache->apHash[iKey % pCache->nHash];
4141641485
while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }
4141741486
41418
- /* Step 2: Abort if no existing page is found and createFlag is 0 */
41487
+ /* Step 2: If the page was found in the hash table, then return it.
41488
+ ** If the page was not in the hash table and createFlag is 0, abort.
41489
+ ** Otherwise (page not in hash and createFlag!=0) continue with
41490
+ ** subsequent steps to try to create the page. */
4141941491
if( pPage ){
4142041492
if( !pPage->isPinned ){
4142141493
return pcache1PinPage(pPage);
4142241494
}else{
4142341495
return pPage;
@@ -41490,25 +41562,20 @@
4149041562
4149141563
/* It is an error to call this function if the page is already
4149241564
** part of the PGroup LRU list.
4149341565
*/
4149441566
assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
41495
- assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
4149641567
assert( pPage->isPinned==1 );
4149741568
4149841569
if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
4149941570
pcache1RemoveFromHash(pPage, 1);
4150041571
}else{
4150141572
/* Add the page to the PGroup LRU list. */
41502
- if( pGroup->pLruHead ){
41503
- pGroup->pLruHead->pLruPrev = pPage;
41504
- pPage->pLruNext = pGroup->pLruHead;
41505
- pGroup->pLruHead = pPage;
41506
- }else{
41507
- pGroup->pLruTail = pPage;
41508
- pGroup->pLruHead = pPage;
41509
- }
41573
+ PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
41574
+ pPage->pLruPrev = &pGroup->lru;
41575
+ (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
41576
+ *ppFirst = pPage;
4151041577
pCache->nRecyclable++;
4151141578
pPage->isPinned = 0;
4151241579
}
4151341580
4151441581
pcache1LeaveMutex(pCache->pGroup);
@@ -41642,11 +41709,14 @@
4164241709
assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
4164341710
assert( sqlite3_mutex_notheld(pcache1.mutex) );
4164441711
if( sqlite3GlobalConfig.nPage==0 ){
4164541712
PgHdr1 *p;
4164641713
pcache1EnterMutex(&pcache1.grp);
41647
- while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
41714
+ while( (nReq<0 || nFree<nReq)
41715
+ && (p=pcache1.grp.lru.pLruPrev)!=0
41716
+ && p->isAnchor==0
41717
+ ){
4164841718
nFree += pcache1MemSize(p->page.pBuf);
4164941719
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
4165041720
nFree += sqlite3MemSize(p);
4165141721
#endif
4165241722
assert( p->isPinned==0 );
@@ -41670,11 +41740,11 @@
4167041740
int *pnMin, /* OUT: Sum of PCache1.nMin for purgeable caches */
4167141741
int *pnRecyclable /* OUT: Total number of pages available for recycling */
4167241742
){
4167341743
PgHdr1 *p;
4167441744
int nRecyclable = 0;
41675
- for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
41745
+ for(p=pcache1.grp.lru.pLruNext; p && !p->isAnchor; p=p->pLruNext){
4167641746
assert( p->isPinned==0 );
4167741747
nRecyclable++;
4167841748
}
4167941749
*pnCurrent = pcache1.grp.nCurrentPage;
4168041750
*pnMax = (int)pcache1.grp.nMaxPage;
@@ -42984,11 +43054,11 @@
4298443054
u8 changeCountDone; /* Set after incrementing the change-counter */
4298543055
u8 setMaster; /* True if a m-j name has been written to jrnl */
4298643056
u8 doNotSpill; /* Do not spill the cache when non-zero */
4298743057
u8 subjInMemory; /* True to use in-memory sub-journals */
4298843058
u8 bUseFetch; /* True to use xFetch() */
42989
- u8 hasBeenUsed; /* True if any content previously read */
43059
+ u8 hasHeldSharedLock; /* True if a shared lock has ever been held */
4299043060
Pgno dbSize; /* Number of pages in the database */
4299143061
Pgno dbOrigSize; /* dbSize before the current transaction */
4299243062
Pgno dbFileSize; /* Number of pages in the database file */
4299343063
Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
4299443064
int errCode; /* One of several kinds of errors */
@@ -47434,14 +47504,14 @@
4743447504
assert( (pPager->eLock==SHARED_LOCK)
4743547505
|| (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
4743647506
);
4743747507
}
4743847508
47439
- if( !pPager->tempFile && pPager->hasBeenUsed ){
47509
+ if( !pPager->tempFile && pPager->hasHeldSharedLock ){
4744047510
/* The shared-lock has just been acquired then check to
4744147511
** see if the database has been modified. If the database has changed,
47442
- ** flush the cache. The pPager->hasBeenUsed flag prevents this from
47512
+ ** flush the cache. The hasHeldSharedLock flag prevents this from
4744347513
** occurring on the very first access to a file, in order to save a
4744447514
** single unnecessary sqlite3OsRead() call at the start-up.
4744547515
**
4744647516
** Database changes are detected by looking at 15 bytes beginning
4744747517
** at offset 24 into the file. The first 4 of these 16 bytes are
@@ -47507,10 +47577,11 @@
4750747577
assert( !MEMDB );
4750847578
pager_unlock(pPager);
4750947579
assert( pPager->eState==PAGER_OPEN );
4751047580
}else{
4751147581
pPager->eState = PAGER_READER;
47582
+ pPager->hasHeldSharedLock = 1;
4751247583
}
4751347584
return rc;
4751447585
}
4751547586
4751647587
/*
@@ -47590,25 +47661,29 @@
4759047661
4759147662
/* It is acceptable to use a read-only (mmap) page for any page except
4759247663
** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
4759347664
** flag was specified by the caller. And so long as the db is not a
4759447665
** temporary or in-memory database. */
47595
- const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
47666
+ const int bMmapOk = (pgno>1 && USEFETCH(pPager)
4759647667
&& (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
4759747668
#ifdef SQLITE_HAS_CODEC
4759847669
&& pPager->xCodec==0
4759947670
#endif
4760047671
);
4760147672
47673
+ /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
47674
+ ** allows the compiler optimizer to reuse the results of the "pgno>1"
47675
+ ** test in the previous statement, and avoid testing pgno==0 in the
47676
+ ** common case where pgno is large. */
47677
+ if( pgno<=1 && pgno==0 ){
47678
+ return SQLITE_CORRUPT_BKPT;
47679
+ }
4760247680
assert( pPager->eState>=PAGER_READER );
4760347681
assert( assert_pager_state(pPager) );
4760447682
assert( noContent==0 || bMmapOk==0 );
4760547683
47606
- if( pgno==0 ){
47607
- return SQLITE_CORRUPT_BKPT;
47608
- }
47609
- pPager->hasBeenUsed = 1;
47684
+ assert( pPager->hasHeldSharedLock==1 );
4761047685
4761147686
/* If the pager is in the error state, return an error immediately.
4761247687
** Otherwise, request the page from the PCache layer. */
4761347688
if( pPager->errCode!=SQLITE_OK ){
4761447689
rc = pPager->errCode;
@@ -47759,11 +47834,11 @@
4775947834
sqlite3_pcache_page *pPage;
4776047835
assert( pPager!=0 );
4776147836
assert( pgno!=0 );
4776247837
assert( pPager->pPCache!=0 );
4776347838
pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
47764
- assert( pPage==0 || pPager->hasBeenUsed );
47839
+ assert( pPage==0 || pPager->hasHeldSharedLock );
4776547840
if( pPage==0 ) return 0;
4776647841
return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
4776747842
}
4776847843
4776947844
/*
@@ -48726,11 +48801,11 @@
4872648801
return pPager->readOnly;
4872748802
}
4872848803
4872948804
#ifdef SQLITE_DEBUG
4873048805
/*
48731
-** Return the number of references to the pager.
48806
+** Return the sum of the reference counts for all pages held by pPager.
4873248807
*/
4873348808
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
4873448809
return sqlite3PcacheRefCount(pPager->pPCache);
4873548810
}
4873648811
#endif
@@ -50038,10 +50113,11 @@
5003850113
u8 readOnly; /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
5003950114
u8 truncateOnCommit; /* True to truncate WAL file on commit */
5004050115
u8 syncHeader; /* Fsync the WAL header if true */
5004150116
u8 padToSectorBoundary; /* Pad transactions out to the next sector */
5004250117
WalIndexHdr hdr; /* Wal-index header for current transaction */
50118
+ u32 minFrame; /* Ignore wal frames before this one */
5004350119
const char *zWalName; /* Name of WAL file */
5004450120
u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
5004550121
#ifdef SQLITE_DEBUG
5004650122
u8 lockError; /* True if a locking error has occurred */
5004750123
#endif
@@ -51906,16 +51982,31 @@
5190651982
** copied into the database by a checkpointer. If either of these things
5190751983
** happened, then reading the database with the current value of
5190851984
** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
5190951985
** instead.
5191051986
**
51911
- ** This does not guarantee that the copy of the wal-index header is up to
51912
- ** date before proceeding. That would not be possible without somehow
51913
- ** blocking writers. It only guarantees that a dangerous checkpoint or
51914
- ** log-wrap (either of which would require an exclusive lock on
51915
- ** WAL_READ_LOCK(mxI)) has not occurred since the snapshot was valid.
51987
+ ** Before checking that the live wal-index header has not changed
51988
+ ** since it was read, set Wal.minFrame to the first frame in the wal
51989
+ ** file that has not yet been checkpointed. This client will not need
51990
+ ** to read any frames earlier than minFrame from the wal file - they
51991
+ ** can be safely read directly from the database file.
51992
+ **
51993
+ ** Because a ShmBarrier() call is made between taking the copy of
51994
+ ** nBackfill and checking that the wal-header in shared-memory still
51995
+ ** matches the one cached in pWal->hdr, it is guaranteed that the
51996
+ ** checkpointer that set nBackfill was not working with a wal-index
51997
+ ** header newer than that cached in pWal->hdr. If it were, that could
51998
+ ** cause a problem. The checkpointer could omit to checkpoint
51999
+ ** a version of page X that lies before pWal->minFrame (call that version
52000
+ ** A) on the basis that there is a newer version (version B) of the same
52001
+ ** page later in the wal file. But if version B happens to like past
52002
+ ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
52003
+ ** that it can read version A from the database file. However, since
52004
+ ** we can guarantee that the checkpointer that set nBackfill could not
52005
+ ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
5191652006
*/
52007
+ pWal->minFrame = pInfo->nBackfill+1;
5191752008
walShmBarrier(pWal);
5191852009
if( pInfo->aReadMark[mxI]!=mxReadMark
5191952010
|| memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
5192052011
){
5192152012
walUnlockShared(pWal, WAL_READ_LOCK(mxI));
@@ -51982,10 +52073,11 @@
5198252073
u32 *piRead /* OUT: Frame number (or zero) */
5198352074
){
5198452075
u32 iRead = 0; /* If !=0, WAL frame to return data from */
5198552076
u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
5198652077
int iHash; /* Used to loop through N hash tables */
52078
+ int iMinHash;
5198752079
5198852080
/* This routine is only be called from within a read transaction. */
5198952081
assert( pWal->readLock>=0 || pWal->lockError );
5199052082
5199152083
/* If the "last page" field of the wal-index header snapshot is 0, then
@@ -52022,11 +52114,12 @@
5202252114
**
5202352115
** (iFrame<=iLast):
5202452116
** This condition filters out entries that were added to the hash
5202552117
** table after the current read-transaction had started.
5202652118
*/
52027
- for(iHash=walFramePage(iLast); iHash>=0 && iRead==0; iHash--){
52119
+ iMinHash = walFramePage(pWal->minFrame);
52120
+ for(iHash=walFramePage(iLast); iHash>=iMinHash && iRead==0; iHash--){
5202852121
volatile ht_slot *aHash; /* Pointer to hash table */
5202952122
volatile u32 *aPgno; /* Pointer to array of page numbers */
5203052123
u32 iZero; /* Frame number corresponding to aPgno[0] */
5203152124
int iKey; /* Hash slot index */
5203252125
int nCollide; /* Number of hash collisions remaining */
@@ -52037,11 +52130,11 @@
5203752130
return rc;
5203852131
}
5203952132
nCollide = HASHTABLE_NSLOT;
5204052133
for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
5204152134
u32 iFrame = aHash[iKey] + iZero;
52042
- if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
52135
+ if( iFrame<=iLast && iFrame>=pWal->minFrame && aPgno[aHash[iKey]]==pgno ){
5204352136
assert( iFrame>iRead || CORRUPT_DB );
5204452137
iRead = iFrame;
5204552138
}
5204652139
if( (nCollide--)==0 ){
5204752140
return SQLITE_CORRUPT_BKPT;
@@ -52054,11 +52147,12 @@
5205452147
** of the wal-index file content. Make sure the results agree with the
5205552148
** result obtained using the hash indexes above. */
5205652149
{
5205752150
u32 iRead2 = 0;
5205852151
u32 iTest;
52059
- for(iTest=iLast; iTest>0; iTest--){
52152
+ assert( pWal->minFrame>0 );
52153
+ for(iTest=iLast; iTest>=pWal->minFrame; iTest--){
5206052154
if( walFramePgno(pWal, iTest)==pgno ){
5206152155
iRead2 = iTest;
5206252156
break;
5206352157
}
5206452158
}
@@ -53494,13 +53588,15 @@
5349453588
** two-byte aligned address. get2bytea() is only used for accessing the
5349553589
** cell addresses in a btree header.
5349653590
*/
5349753591
#if SQLITE_BYTEORDER==4321
5349853592
# define get2byteAligned(x) (*(u16*)(x))
53499
-#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
53593
+#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
53594
+ && GCC_VERSION>=4008000
5350053595
# define get2byteAligned(x) __builtin_bswap16(*(u16*)(x))
53501
-#elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
53596
+#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
53597
+ && defined(_MSC_VER) && _MSC_VER>=1300
5350253598
# define get2byteAligned(x) _byteswap_ushort(*(u16*)(x))
5350353599
#else
5350453600
# define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
5350553601
#endif
5350653602
@@ -62492,21 +62588,19 @@
6249262588
IntegrityCk *pCheck,
6249362589
const char *zFormat,
6249462590
...
6249562591
){
6249662592
va_list ap;
62497
- char zBuf[200];
6249862593
if( !pCheck->mxErr ) return;
6249962594
pCheck->mxErr--;
6250062595
pCheck->nErr++;
6250162596
va_start(ap, zFormat);
6250262597
if( pCheck->errMsg.nChar ){
6250362598
sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
6250462599
}
6250562600
if( pCheck->zPfx ){
62506
- sqlite3_snprintf(sizeof(zBuf), zBuf, pCheck->zPfx, pCheck->v1, pCheck->v2);
62507
- sqlite3StrAccumAppendAll(&pCheck->errMsg, zBuf);
62601
+ sqlite3XPrintf(&pCheck->errMsg, 0, pCheck->zPfx, pCheck->v1, pCheck->v2);
6250862602
}
6250962603
sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
6251062604
va_end(ap);
6251162605
if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
6251262606
pCheck->mallocFailed = 1;
@@ -65327,11 +65421,11 @@
6532765421
/*
6532865422
** The expression object indicated by the second argument is guaranteed
6532965423
** to be a scalar SQL function. If
6533065424
**
6533165425
** * all function arguments are SQL literals,
65332
-** * the SQLITE_FUNC_CONSTANT function flag is set, and
65426
+** * one of the SQLITE_FUNC_CONSTANT or _SLOCHNG function flags is set, and
6533365427
** * the SQLITE_FUNC_NEEDCOLL function flag is not set,
6533465428
**
6533565429
** then this routine attempts to invoke the SQL function. Assuming no
6533665430
** error occurs, output parameter (*ppVal) is set to point to a value
6533765431
** object containing the result before returning SQLITE_OK.
@@ -65368,11 +65462,11 @@
6536865462
pList = p->x.pList;
6536965463
if( pList ) nVal = pList->nExpr;
6537065464
nName = sqlite3Strlen30(p->u.zToken);
6537165465
pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
6537265466
assert( pFunc );
65373
- if( (pFunc->funcFlags & SQLITE_FUNC_CONSTANT)==0
65467
+ if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
6537465468
|| (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
6537565469
){
6537665470
return SQLITE_OK;
6537765471
}
6537865472
@@ -65962,11 +66056,11 @@
6596266056
/*
6596366057
** Return the SQL associated with a prepared statement
6596466058
*/
6596566059
SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt){
6596666060
Vdbe *p = (Vdbe *)pStmt;
65967
- return (p && p->isPrepareV2) ? p->zSql : 0;
66061
+ return p ? p->zSql : 0;
6596866062
}
6596966063
6597066064
/*
6597166065
** Swap all content between two VDBE structures.
6597266066
*/
@@ -66109,10 +66203,48 @@
6610966203
}
6611066204
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe *p, int op, int p1, int p2){
6611166205
return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
6611266206
}
6611366207
66208
+/* Generate code for an unconditional jump to instruction iDest
66209
+*/
66210
+SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *p, int iDest){
66211
+ return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
66212
+}
66213
+
66214
+/* Generate code to cause the string zStr to be loaded into
66215
+** register iDest
66216
+*/
66217
+SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe *p, int iDest, const char *zStr){
66218
+ return sqlite3VdbeAddOp4(p, OP_String8, 0, iDest, 0, zStr, 0);
66219
+}
66220
+
66221
+/*
66222
+** Generate code that initializes multiple registers to string or integer
66223
+** constants. The registers begin with iDest and increase consecutively.
66224
+** One register is initialized for each characgter in zTypes[]. For each
66225
+** "s" character in zTypes[], the register is a string if the argument is
66226
+** not NULL, or OP_Null if the value is a null pointer. For each "i" character
66227
+** in zTypes[], the register is initialized to an integer.
66228
+*/
66229
+SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe *p, int iDest, const char *zTypes, ...){
66230
+ va_list ap;
66231
+ int i;
66232
+ char c;
66233
+ va_start(ap, zTypes);
66234
+ for(i=0; (c = zTypes[i])!=0; i++){
66235
+ if( c=='s' ){
66236
+ const char *z = va_arg(ap, const char*);
66237
+ int addr = sqlite3VdbeAddOp2(p, z==0 ? OP_Null : OP_String8, 0, iDest++);
66238
+ if( z ) sqlite3VdbeChangeP4(p, addr, z, 0);
66239
+ }else{
66240
+ assert( c=='i' );
66241
+ sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest++);
66242
+ }
66243
+ }
66244
+ va_end(ap);
66245
+}
6611466246
6611566247
/*
6611666248
** Add an opcode that includes the p4 value as a pointer.
6611766249
*/
6611866250
SQLITE_PRIVATE int sqlite3VdbeAddOp4(
@@ -66128,11 +66260,12 @@
6612866260
sqlite3VdbeChangeP4(p, addr, zP4, p4type);
6612966261
return addr;
6613066262
}
6613166263
6613266264
/*
66133
-** Add an opcode that includes the p4 value with a P4_INT64 type.
66265
+** Add an opcode that includes the p4 value with a P4_INT64 or
66266
+** P4_REAL type.
6613466267
*/
6613566268
SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(
6613666269
Vdbe *p, /* Add the opcode to this VM */
6613766270
int op, /* The new opcode */
6613866271
int p1, /* The P1 operand */
@@ -66213,11 +66346,12 @@
6621366346
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
6621466347
Parse *p = v->pParse;
6621566348
int j = -1-x;
6621666349
assert( v->magic==VDBE_MAGIC_INIT );
6621766350
assert( j<p->nLabel );
66218
- if( ALWAYS(j>=0) && p->aLabel ){
66351
+ assert( j>=0 );
66352
+ if( p->aLabel ){
6621966353
p->aLabel[j] = v->nOp;
6622066354
}
6622166355
p->iFixedOp = v->nOp - 1;
6622266356
}
6622366357
@@ -66357,21 +66491,25 @@
6635766491
|| (hasCreateTable && hasInitCoroutine) );
6635866492
}
6635966493
#endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
6636066494
6636166495
/*
66362
-** Loop through the program looking for P2 values that are negative
66363
-** on jump instructions. Each such value is a label. Resolve the
66364
-** label by setting the P2 value to its correct non-zero value.
66365
-**
66366
-** This routine is called once after all opcodes have been inserted.
66367
-**
66368
-** Variable *pMaxFuncArgs is set to the maximum value of any P2 argument
66369
-** to an OP_Function, OP_AggStep or OP_VFilter opcode. This is used by
66370
-** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array.
66371
-**
66372
-** The Op.opflags field is set on all opcodes.
66496
+** This routine is called after all opcodes have been inserted. It loops
66497
+** through all the opcodes and fixes up some details.
66498
+**
66499
+** (1) For each jump instruction with a negative P2 value (a label)
66500
+** resolve the P2 value to an actual address.
66501
+**
66502
+** (2) Compute the maximum number of arguments used by any SQL function
66503
+** and store that value in *pMaxFuncArgs.
66504
+**
66505
+** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
66506
+** indicate what the prepared statement actually does.
66507
+**
66508
+** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
66509
+**
66510
+** (5) Reclaim the memory allocated for storing labels.
6637366511
*/
6637466512
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
6637566513
int i;
6637666514
int nMaxArgs = *pMaxFuncArgs;
6637766515
Op *pOp;
@@ -66480,50 +66618,48 @@
6648066618
/*
6648166619
** Add a whole list of operations to the operation stack. Return the
6648266620
** address of the first operation added.
6648366621
*/
6648466622
SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
66485
- int addr;
66623
+ int addr, i;
66624
+ VdbeOp *pOut;
66625
+ assert( nOp>0 );
6648666626
assert( p->magic==VDBE_MAGIC_INIT );
6648766627
if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
6648866628
return 0;
6648966629
}
6649066630
addr = p->nOp;
66491
- if( ALWAYS(nOp>0) ){
66492
- int i;
66493
- VdbeOpList const *pIn = aOp;
66494
- for(i=0; i<nOp; i++, pIn++){
66495
- int p2 = pIn->p2;
66496
- VdbeOp *pOut = &p->aOp[i+addr];
66497
- pOut->opcode = pIn->opcode;
66498
- pOut->p1 = pIn->p1;
66499
- if( p2<0 ){
66500
- assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
66501
- pOut->p2 = addr + ADDR(p2);
66502
- }else{
66503
- pOut->p2 = p2;
66504
- }
66505
- pOut->p3 = pIn->p3;
66506
- pOut->p4type = P4_NOTUSED;
66507
- pOut->p4.p = 0;
66508
- pOut->p5 = 0;
66631
+ pOut = &p->aOp[addr];
66632
+ for(i=0; i<nOp; i++, aOp++, pOut++){
66633
+ int p2 = aOp->p2;
66634
+ pOut->opcode = aOp->opcode;
66635
+ pOut->p1 = aOp->p1;
66636
+ if( p2<0 ){
66637
+ assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
66638
+ pOut->p2 = addr + ADDR(p2);
66639
+ }else{
66640
+ pOut->p2 = p2;
66641
+ }
66642
+ pOut->p3 = aOp->p3;
66643
+ pOut->p4type = P4_NOTUSED;
66644
+ pOut->p4.p = 0;
66645
+ pOut->p5 = 0;
6650966646
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
66510
- pOut->zComment = 0;
66647
+ pOut->zComment = 0;
6651166648
#endif
6651266649
#ifdef SQLITE_VDBE_COVERAGE
66513
- pOut->iSrcLine = iLineno+i;
66650
+ pOut->iSrcLine = iLineno+i;
6651466651
#else
66515
- (void)iLineno;
66652
+ (void)iLineno;
6651666653
#endif
6651766654
#ifdef SQLITE_DEBUG
66518
- if( p->db->flags & SQLITE_VdbeAddopTrace ){
66519
- sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
66520
- }
66655
+ if( p->db->flags & SQLITE_VdbeAddopTrace ){
66656
+ sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
66657
+ }
6652166658
#endif
66522
- }
66523
- p->nOp += nOp;
6652466659
}
66660
+ p->nOp += nOp;
6652566661
return addr;
6652666662
}
6652766663
6652866664
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
6652966665
/*
@@ -66552,62 +66688,36 @@
6655266688
}
6655366689
#endif
6655466690
6655566691
6655666692
/*
66557
-** Change the value of the P1 operand for a specific instruction.
66558
-** This routine is useful when a large program is loaded from a
66559
-** static array using sqlite3VdbeAddOpList but we want to make a
66560
-** few minor changes to the program.
66693
+** Change the value of the opcode, or P1, P2, P3, or P5 operands
66694
+** for a specific instruction.
6656166695
*/
66696
+SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *p, u32 addr, u8 iNewOpcode){
66697
+ sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
66698
+}
6656266699
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){
66563
- assert( p!=0 );
66564
- if( ((u32)p->nOp)>addr ){
66565
- p->aOp[addr].p1 = val;
66566
- }
66567
-}
66568
-
66569
-/*
66570
-** Change the value of the P2 operand for a specific instruction.
66571
-** This routine is useful for setting a jump destination.
66572
-*/
66700
+ sqlite3VdbeGetOp(p,addr)->p1 = val;
66701
+}
6657366702
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, u32 addr, int val){
66574
- assert( p!=0 );
66575
- if( ((u32)p->nOp)>addr ){
66576
- p->aOp[addr].p2 = val;
66577
- }
66578
-}
66579
-
66580
-/*
66581
-** Change the value of the P3 operand for a specific instruction.
66582
-*/
66703
+ sqlite3VdbeGetOp(p,addr)->p2 = val;
66704
+}
6658366705
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
66584
- assert( p!=0 );
66585
- if( ((u32)p->nOp)>addr ){
66586
- p->aOp[addr].p3 = val;
66587
- }
66588
-}
66589
-
66590
-/*
66591
-** Change the value of the P5 operand for the most recently
66592
-** added operation.
66593
-*/
66594
-SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 val){
66595
- assert( p!=0 );
66596
- if( p->aOp ){
66597
- assert( p->nOp>0 );
66598
- p->aOp[p->nOp-1].p5 = val;
66599
- }
66706
+ sqlite3VdbeGetOp(p,addr)->p3 = val;
66707
+}
66708
+SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){
66709
+ sqlite3VdbeGetOp(p,-1)->p5 = p5;
6660066710
}
6660166711
6660266712
/*
6660366713
** Change the P2 operand of instruction addr so that it points to
6660466714
** the address of the next instruction to be coded.
6660566715
*/
6660666716
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
66607
- sqlite3VdbeChangeP2(p, addr, p->nOp);
6660866717
p->pParse->iFixedOp = p->nOp - 1;
66718
+ sqlite3VdbeChangeP2(p, addr, p->nOp);
6660966719
}
6661066720
6661166721
6661266722
/*
6661366723
** If the input FuncDef structure is ephemeral, then free it. If
@@ -66988,12 +67098,13 @@
6698867098
int n = sqlite3Strlen30(zColl);
6698967099
if( n==6 && memcmp(zColl,"BINARY",6)==0 ){
6699067100
zColl = "B";
6699167101
n = 1;
6699267102
}
66993
- if( i+n>nTemp-6 ){
67103
+ if( i+n>nTemp-7 ){
6699467104
memcpy(&zTemp[i],",...",4);
67105
+ i += 4;
6699567106
break;
6699667107
}
6699767108
zTemp[i++] = ',';
6699867109
if( pKeyInfo->aSortOrder[j] ){
6699967110
zTemp[i++] = '-';
@@ -70329,10 +70440,13 @@
7032970440
SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value *pVal){
7033070441
return (int)sqlite3VdbeIntValue((Mem*)pVal);
7033170442
}
7033270443
SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value *pVal){
7033370444
return sqlite3VdbeIntValue((Mem*)pVal);
70445
+}
70446
+SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value *pVal){
70447
+ return ((Mem*)pVal)->eSubtype;
7033470448
}
7033570449
SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value *pVal){
7033670450
return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
7033770451
}
7033870452
#ifndef SQLITE_OMIT_UTF16
@@ -70507,10 +70621,14 @@
7050770621
sqlite3VdbeMemSetInt64(pCtx->pOut, iVal);
7050870622
}
7050970623
SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context *pCtx){
7051070624
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
7051170625
sqlite3VdbeMemSetNull(pCtx->pOut);
70626
+}
70627
+SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
70628
+ assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
70629
+ pCtx->pOut->eSubtype = eSubtype & 0xff;
7051270630
}
7051370631
SQLITE_API void SQLITE_STDCALL sqlite3_result_text(
7051470632
sqlite3_context *pCtx,
7051570633
const char *z,
7051670634
int n,
@@ -70754,11 +70872,11 @@
7075470872
** be one of the values in the first assert() below. Variable p->rc
7075570873
** contains the value that would be returned if sqlite3_finalize()
7075670874
** were called on statement p.
7075770875
*/
7075870876
assert( rc==SQLITE_ROW || rc==SQLITE_DONE || rc==SQLITE_ERROR
70759
- || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
70877
+ || (rc&0xff)==SQLITE_BUSY || rc==SQLITE_MISUSE
7076070878
);
7076170879
assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp );
7076270880
if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
7076370881
/* If this statement was prepared using sqlite3_prepare_v2(), and an
7076470882
** error has occurred, then return the error code in p->rc to the
@@ -70839,11 +70957,11 @@
7083970957
** parameter) of the sqlite3_create_function() and
7084070958
** sqlite3_create_function16() routines that originally registered the
7084170959
** application defined function.
7084270960
*/
7084370961
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context *p){
70844
- assert( p && p->pFunc );
70962
+ assert( p && p->pOut );
7084570963
return p->pOut->db;
7084670964
}
7084770965
7084870966
/*
7084970967
** Return the current time for a statement. If the current time
@@ -72657,11 +72775,11 @@
7265772775
if( p->rc==SQLITE_NOMEM ){
7265872776
/* This happens if a malloc() inside a call to sqlite3_column_text() or
7265972777
** sqlite3_column_text16() failed. */
7266072778
goto no_mem;
7266172779
}
72662
- assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
72780
+ assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
7266372781
assert( p->bIsReader || p->readOnly!=0 );
7266472782
p->rc = SQLITE_OK;
7266572783
p->iCurrentTime = 0;
7266672784
assert( p->explain==0 );
7266772785
p->pResultSet = 0;
@@ -75094,16 +75212,16 @@
7509475212
db->autoCommit = 1;
7509575213
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
7509675214
goto vdbe_return;
7509775215
}else{
7509875216
db->autoCommit = (u8)desiredAutoCommit;
75099
- if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
75100
- p->pc = (int)(pOp - aOp);
75101
- db->autoCommit = (u8)(1-desiredAutoCommit);
75102
- p->rc = rc = SQLITE_BUSY;
75103
- goto vdbe_return;
75104
- }
75217
+ }
75218
+ if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
75219
+ p->pc = (int)(pOp - aOp);
75220
+ db->autoCommit = (u8)(1-desiredAutoCommit);
75221
+ p->rc = rc = SQLITE_BUSY;
75222
+ goto vdbe_return;
7510575223
}
7510675224
assert( db->nStatement==0 );
7510775225
sqlite3CloseSavepoints(db);
7510875226
if( p->rc==SQLITE_OK ){
7510975227
rc = SQLITE_DONE;
@@ -75171,13 +75289,15 @@
7517175289
}
7517275290
pBt = db->aDb[pOp->p1].pBt;
7517375291
7517475292
if( pBt ){
7517575293
rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
75176
- if( rc==SQLITE_BUSY ){
75294
+ testcase( rc==SQLITE_BUSY_SNAPSHOT );
75295
+ testcase( rc==SQLITE_BUSY_RECOVERY );
75296
+ if( (rc&0xff)==SQLITE_BUSY ){
7517775297
p->pc = (int)(pOp - aOp);
75178
- p->rc = rc = SQLITE_BUSY;
75298
+ p->rc = rc;
7517975299
goto vdbe_return;
7518075300
}
7518175301
if( rc!=SQLITE_OK ){
7518275302
goto abort_due_to_error;
7518375303
}
@@ -79009,11 +79129,12 @@
7900979129
}
7901079130
#endif
7901179131
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
7901279132
int j;
7901379133
for(j=0; j<pIdx->nKeyCol; j++){
79014
- if( pIdx->aiColumn[j]==iCol ){
79134
+ /* FIXME: Be smarter about indexes that use expressions */
79135
+ if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==(-2) ){
7901579136
zFault = "indexed";
7901679137
}
7901779138
}
7901879139
}
7901979140
if( zFault ){
@@ -82590,10 +82711,15 @@
8259082711
if( ALWAYS(pSrc) ){
8259182712
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
8259282713
if( sqlite3WalkSelect(pWalker, pItem->pSelect) ){
8259382714
return WRC_Abort;
8259482715
}
82716
+ if( pItem->fg.isTabFunc
82717
+ && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg)
82718
+ ){
82719
+ return WRC_Abort;
82720
+ }
8259582721
}
8259682722
}
8259782723
return WRC_Continue;
8259882724
}
8259982725
@@ -82687,34 +82813,10 @@
8268782813
8268882814
/*
8268982815
** Turn the pExpr expression into an alias for the iCol-th column of the
8269082816
** result set in pEList.
8269182817
**
82692
-** If the result set column is a simple column reference, then this routine
82693
-** makes an exact copy. But for any other kind of expression, this
82694
-** routine make a copy of the result set column as the argument to the
82695
-** TK_AS operator. The TK_AS operator causes the expression to be
82696
-** evaluated just once and then reused for each alias.
82697
-**
82698
-** The reason for suppressing the TK_AS term when the expression is a simple
82699
-** column reference is so that the column reference will be recognized as
82700
-** usable by indices within the WHERE clause processing logic.
82701
-**
82702
-** The TK_AS operator is inhibited if zType[0]=='G'. This means
82703
-** that in a GROUP BY clause, the expression is evaluated twice. Hence:
82704
-**
82705
-** SELECT random()%5 AS x, count(*) FROM tab GROUP BY x
82706
-**
82707
-** Is equivalent to:
82708
-**
82709
-** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
82710
-**
82711
-** The result of random()%5 in the GROUP BY clause is probably different
82712
-** from the result in the result-set. On the other hand Standard SQL does
82713
-** not allow the GROUP BY clause to contain references to result-set columns.
82714
-** So this should never come up in well-formed queries.
82715
-**
8271682818
** If the reference is followed by a COLLATE operator, then make sure
8271782819
** the COLLATE operator is preserved. For example:
8271882820
**
8271982821
** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
8272082822
**
@@ -82744,23 +82846,15 @@
8274482846
pOrig = pEList->a[iCol].pExpr;
8274582847
assert( pOrig!=0 );
8274682848
db = pParse->db;
8274782849
pDup = sqlite3ExprDup(db, pOrig, 0);
8274882850
if( pDup==0 ) return;
82749
- if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
82750
- incrAggFunctionDepth(pDup, nSubquery);
82751
- pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
82752
- if( pDup==0 ) return;
82753
- ExprSetProperty(pDup, EP_Skip);
82754
- if( pEList->a[iCol].u.x.iAlias==0 ){
82755
- pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
82756
- }
82757
- pDup->iTable = pEList->a[iCol].u.x.iAlias;
82758
- }
82851
+ if( zType[0]!='G' ) incrAggFunctionDepth(pDup, nSubquery);
8275982852
if( pExpr->op==TK_COLLATE ){
8276082853
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
8276182854
}
82855
+ ExprSetProperty(pDup, EP_Alias);
8276282856
8276382857
/* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
8276482858
** prevents ExprDelete() from deleting the Expr structure itself,
8276582859
** allowing it to be repopulated by the memcpy() on the following line.
8276682860
** The pExpr->u.zToken might point into memory that will be freed by the
@@ -82948,11 +83042,11 @@
8294883042
/* If there has been exactly one prior match and this match
8294983043
** is for the right-hand table of a NATURAL JOIN or is in a
8295083044
** USING clause, then skip this match.
8295183045
*/
8295283046
if( cnt==1 ){
82953
- if( pItem->jointype & JT_NATURAL ) continue;
83047
+ if( pItem->fg.jointype & JT_NATURAL ) continue;
8295483048
if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
8295583049
}
8295683050
cnt++;
8295783051
pMatch = pItem;
8295883052
/* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
@@ -82963,12 +83057,12 @@
8296383057
}
8296483058
if( pMatch ){
8296583059
pExpr->iTable = pMatch->iCursor;
8296683060
pExpr->pTab = pMatch->pTab;
8296783061
/* RIGHT JOIN not (yet) supported */
82968
- assert( (pMatch->jointype & JT_RIGHT)==0 );
82969
- if( (pMatch->jointype & JT_LEFT)!=0 ){
83062
+ assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
83063
+ if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
8297083064
ExprSetProperty(pExpr, EP_CanBeNull);
8297183065
}
8297283066
pSchema = pExpr->pTab->pSchema;
8297383067
}
8297483068
} /* if( pSrcList ) */
@@ -83049,13 +83143,13 @@
8304983143
** forms the result set entry ("a+b" in the example) and return immediately.
8305083144
** Note that the expression in the result set should have already been
8305183145
** resolved by the time the WHERE clause is resolved.
8305283146
**
8305383147
** The ability to use an output result-set column in the WHERE, GROUP BY,
83054
- ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
83148
+ ** or HAVING clauses, or as part of a larger expression in the ORDER BY
8305583149
** clause is not standard SQL. This is a (goofy) SQLite extension, that
83056
- ** is supported for backwards compatibility only. TO DO: Issue a warning
83150
+ ** is supported for backwards compatibility only. Hence, we issue a warning
8305783151
** on sqlite3_log() whenever the capability is used.
8305883152
*/
8305983153
if( (pEList = pNC->pEList)!=0
8306083154
&& zTab==0
8306183155
&& cnt==0
@@ -83148,11 +83242,11 @@
8314883242
pExpr->pRight = 0;
8314983243
pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
8315083244
lookupname_end:
8315183245
if( cnt==1 ){
8315283246
assert( pNC!=0 );
83153
- if( pExpr->op!=TK_AS ){
83247
+ if( !ExprHasProperty(pExpr, EP_Alias) ){
8315483248
sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
8315583249
}
8315683250
/* Increment the nRef value on all name contexts from TopNC up to
8315783251
** the point where the name matched. */
8315883252
for(;;){
@@ -83189,40 +83283,29 @@
8318983283
}
8319083284
return p;
8319183285
}
8319283286
8319383287
/*
83194
-** Report an error that an expression is not valid for a partial index WHERE
83195
-** clause.
83196
-*/
83197
-static void notValidPartIdxWhere(
83198
- Parse *pParse, /* Leave error message here */
83199
- NameContext *pNC, /* The name context */
83200
- const char *zMsg /* Type of error */
83201
-){
83202
- if( (pNC->ncFlags & NC_PartIdx)!=0 ){
83203
- sqlite3ErrorMsg(pParse, "%s prohibited in partial index WHERE clauses",
83204
- zMsg);
83205
- }
83206
-}
83207
-
83208
-#ifndef SQLITE_OMIT_CHECK
83209
-/*
83210
-** Report an error that an expression is not valid for a CHECK constraint.
83211
-*/
83212
-static void notValidCheckConstraint(
83213
- Parse *pParse, /* Leave error message here */
83214
- NameContext *pNC, /* The name context */
83215
- const char *zMsg /* Type of error */
83216
-){
83217
- if( (pNC->ncFlags & NC_IsCheck)!=0 ){
83218
- sqlite3ErrorMsg(pParse,"%s prohibited in CHECK constraints", zMsg);
83219
- }
83220
-}
83221
-#else
83222
-# define notValidCheckConstraint(P,N,M)
83223
-#endif
83288
+** Report an error that an expression is not valid for some set of
83289
+** pNC->ncFlags values determined by validMask.
83290
+*/
83291
+static void notValid(
83292
+ Parse *pParse, /* Leave error message here */
83293
+ NameContext *pNC, /* The name context */
83294
+ const char *zMsg, /* Type of error */
83295
+ int validMask /* Set of contexts for which prohibited */
83296
+){
83297
+ assert( (validMask&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr))==0 );
83298
+ if( (pNC->ncFlags & validMask)!=0 ){
83299
+ const char *zIn = "partial index WHERE clauses";
83300
+ if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
83301
+#ifndef SQLITE_OMIT_CHECK
83302
+ else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
83303
+#endif
83304
+ sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
83305
+ }
83306
+}
8322483307
8322583308
/*
8322683309
** Expression p should encode a floating point value between 1.0 and 0.0.
8322783310
** Return 1024 times this value. Or return -1 if p is not a floating point
8322883311
** value between 1.0 and 0.0.
@@ -83303,10 +83386,12 @@
8330383386
const char *zTable;
8330483387
const char *zDb;
8330583388
Expr *pRight;
8330683389
8330783390
/* if( pSrcList==0 ) break; */
83391
+ notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
83392
+ /*notValid(pParse, pNC, "the \".\" operator", NC_PartIdx|NC_IsCheck, 1);*/
8330883393
pRight = pExpr->pRight;
8330983394
if( pRight->op==TK_ID ){
8331083395
zDb = 0;
8331183396
zTable = pExpr->pLeft->u.zToken;
8331283397
zColumn = pRight->u.zToken;
@@ -83332,11 +83417,11 @@
8333283417
const char *zId; /* The function name. */
8333383418
FuncDef *pDef; /* Information about the function */
8333483419
u8 enc = ENC(pParse->db); /* The database encoding */
8333583420
8333683421
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
83337
- notValidPartIdxWhere(pParse, pNC, "functions");
83422
+ notValid(pParse, pNC, "functions", NC_PartIdx);
8333883423
zId = pExpr->u.zToken;
8333983424
nId = sqlite3Strlen30(zId);
8334083425
pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
8334183426
if( pDef==0 ){
8334283427
pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
@@ -83380,13 +83465,22 @@
8338083465
}
8338183466
pExpr->op = TK_NULL;
8338283467
return WRC_Prune;
8338383468
}
8338483469
#endif
83385
- if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){
83470
+ if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
83471
+ /* For the purposes of the EP_ConstFunc flag, date and time
83472
+ ** functions and other functions that change slowly are considered
83473
+ ** constant because they are constant for the duration of one query */
8338683474
ExprSetProperty(pExpr,EP_ConstFunc);
8338783475
}
83476
+ if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
83477
+ /* Date/time functions that use 'now', and other functions like
83478
+ ** sqlite_version() that might change over time cannot be used
83479
+ ** in an index. */
83480
+ notValid(pParse, pNC, "non-deterministic functions", NC_IdxExpr);
83481
+ }
8338883482
}
8338983483
if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
8339083484
sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
8339183485
pNC->nErr++;
8339283486
is_agg = 0;
@@ -83428,23 +83522,21 @@
8342883522
#endif
8342983523
case TK_IN: {
8343083524
testcase( pExpr->op==TK_IN );
8343183525
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
8343283526
int nRef = pNC->nRef;
83433
- notValidCheckConstraint(pParse, pNC, "subqueries");
83434
- notValidPartIdxWhere(pParse, pNC, "subqueries");
83527
+ notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
8343583528
sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
8343683529
assert( pNC->nRef>=nRef );
8343783530
if( nRef!=pNC->nRef ){
8343883531
ExprSetProperty(pExpr, EP_VarSelect);
8343983532
}
8344083533
}
8344183534
break;
8344283535
}
8344383536
case TK_VARIABLE: {
83444
- notValidCheckConstraint(pParse, pNC, "parameters");
83445
- notValidPartIdxWhere(pParse, pNC, "parameters");
83537
+ notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
8344683538
break;
8344783539
}
8344883540
}
8344983541
return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
8345083542
}
@@ -83784,11 +83876,10 @@
8378483876
NameContext *pOuterNC; /* Context that contains this SELECT */
8378583877
NameContext sNC; /* Name context of this SELECT */
8378683878
int isCompound; /* True if p is a compound select */
8378783879
int nCompound; /* Number of compound terms processed so far */
8378883880
Parse *pParse; /* Parsing context */
83789
- ExprList *pEList; /* Result set expression list */
8379083881
int i; /* Loop counter */
8379183882
ExprList *pGroupBy; /* The GROUP BY clause */
8379283883
Select *pLeftmost; /* Left-most of SELECT of a compound */
8379383884
sqlite3 *db; /* Database connection */
8379483885
@@ -83857,21 +83948,21 @@
8385783948
8385883949
/* Count the total number of references to pOuterNC and all of its
8385983950
** parent contexts. After resolving references to expressions in
8386083951
** pItem->pSelect, check if this value has changed. If so, then
8386183952
** SELECT statement pItem->pSelect must be correlated. Set the
83862
- ** pItem->isCorrelated flag if this is the case. */
83953
+ ** pItem->fg.isCorrelated flag if this is the case. */
8386383954
for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef;
8386483955
8386583956
if( pItem->zName ) pParse->zAuthContext = pItem->zName;
8386683957
sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
8386783958
pParse->zAuthContext = zSavedContext;
8386883959
if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
8386983960
8387083961
for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef;
83871
- assert( pItem->isCorrelated==0 && nRef<=0 );
83872
- pItem->isCorrelated = (nRef!=0);
83962
+ assert( pItem->fg.isCorrelated==0 && nRef<=0 );
83963
+ pItem->fg.isCorrelated = (nRef!=0);
8387383964
}
8387483965
}
8387583966
8387683967
/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
8387783968
** resolve the result-set expression list.
@@ -83879,18 +83970,11 @@
8387983970
sNC.ncFlags = NC_AllowAgg;
8388083971
sNC.pSrcList = p->pSrc;
8388183972
sNC.pNext = pOuterNC;
8388283973
8388383974
/* Resolve names in the result set. */
83884
- pEList = p->pEList;
83885
- assert( pEList!=0 );
83886
- for(i=0; i<pEList->nExpr; i++){
83887
- Expr *pX = pEList->a[i].pExpr;
83888
- if( sqlite3ResolveExprNames(&sNC, pX) ){
83889
- return WRC_Abort;
83890
- }
83891
- }
83975
+ if( sqlite3ResolveExprListNames(&sNC, p->pEList) ) return WRC_Abort;
8389283976
8389383977
/* If there are no aggregate functions in the result-set, and no GROUP BY
8389483978
** expression, do not allow aggregates in any of the other expressions.
8389583979
*/
8389683980
assert( (p->selFlags & SF_Aggregate)==0 );
@@ -83918,10 +84002,20 @@
8391884002
** re-evaluated for each reference to it.
8391984003
*/
8392084004
sNC.pEList = p->pEList;
8392184005
if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
8392284006
if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
84007
+
84008
+ /* Resolve names in table-valued-function arguments */
84009
+ for(i=0; i<p->pSrc->nSrc; i++){
84010
+ struct SrcList_item *pItem = &p->pSrc->a[i];
84011
+ if( pItem->fg.isTabFunc
84012
+ && sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg)
84013
+ ){
84014
+ return WRC_Abort;
84015
+ }
84016
+ }
8392384017
8392484018
/* The ORDER BY and GROUP BY clauses may not refer to terms in
8392584019
** outer queries
8392684020
*/
8392784021
sNC.pNext = 0;
@@ -84082,10 +84176,26 @@
8408284176
}
8408384177
pNC->ncFlags |= savedHasAgg;
8408484178
return ExprHasProperty(pExpr, EP_Error);
8408584179
}
8408684180
84181
+/*
84182
+** Resolve all names for all expression in an expression list. This is
84183
+** just like sqlite3ResolveExprNames() except that it works for an expression
84184
+** list rather than a single expression.
84185
+*/
84186
+SQLITE_PRIVATE int sqlite3ResolveExprListNames(
84187
+ NameContext *pNC, /* Namespace to resolve expressions in. */
84188
+ ExprList *pList /* The expression list to be analyzed. */
84189
+){
84190
+ int i;
84191
+ assert( pList!=0 );
84192
+ for(i=0; i<pList->nExpr; i++){
84193
+ if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
84194
+ }
84195
+ return WRC_Continue;
84196
+}
8408784197
8408884198
/*
8408984199
** Resolve all names in all expressions of a SELECT and in all
8409084200
** decendents of the SELECT, including compounds off of p->pPrior,
8409184201
** subqueries in expressions, and subqueries used as FROM clause
@@ -84125,19 +84235,18 @@
8412584235
** Any errors cause an error message to be set in pParse.
8412684236
*/
8412784237
SQLITE_PRIVATE void sqlite3ResolveSelfReference(
8412884238
Parse *pParse, /* Parsing context */
8412984239
Table *pTab, /* The table being referenced */
84130
- int type, /* NC_IsCheck or NC_PartIdx */
84240
+ int type, /* NC_IsCheck or NC_PartIdx or NC_IdxExpr */
8413184241
Expr *pExpr, /* Expression to resolve. May be NULL. */
8413284242
ExprList *pList /* Expression list to resolve. May be NUL. */
8413384243
){
8413484244
SrcList sSrc; /* Fake SrcList for pParse->pNewTable */
8413584245
NameContext sNC; /* Name context for pParse->pNewTable */
84136
- int i; /* Loop counter */
8413784246
84138
- assert( type==NC_IsCheck || type==NC_PartIdx );
84247
+ assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr );
8413984248
memset(&sNC, 0, sizeof(sNC));
8414084249
memset(&sSrc, 0, sizeof(sSrc));
8414184250
sSrc.nSrc = 1;
8414284251
sSrc.a[0].zName = pTab->zName;
8414384252
sSrc.a[0].pTab = pTab;
@@ -84144,17 +84253,11 @@
8414484253
sSrc.a[0].iCursor = -1;
8414584254
sNC.pParse = pParse;
8414684255
sNC.pSrcList = &sSrc;
8414784256
sNC.ncFlags = type;
8414884257
if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
84149
- if( pList ){
84150
- for(i=0; i<pList->nExpr; i++){
84151
- if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
84152
- return;
84153
- }
84154
- }
84155
- }
84258
+ if( pList ) sqlite3ResolveExprListNames(&sNC, pList);
8415684259
}
8415784260
8415884261
/************** End of resolve.c *********************************************/
8415984262
/************** Begin file expr.c ********************************************/
8416084263
/*
@@ -84248,11 +84351,11 @@
8424884351
s.n = sqlite3Strlen30(s.z);
8424984352
return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
8425084353
}
8425184354
8425284355
/*
84253
-** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
84356
+** Skip over any TK_COLLATE operators and any unlikely()
8425484357
** or likelihood() function at the root of an expression.
8425584358
*/
8425684359
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
8425784360
while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
8425884361
if( ExprHasProperty(pExpr, EP_Unlikely) ){
@@ -84259,11 +84362,11 @@
8425984362
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
8426084363
assert( pExpr->x.pList->nExpr>0 );
8426184364
assert( pExpr->op==TK_FUNCTION );
8426284365
pExpr = pExpr->x.pList->a[0].pExpr;
8426384366
}else{
84264
- assert( pExpr->op==TK_COLLATE || pExpr->op==TK_AS );
84367
+ assert( pExpr->op==TK_COLLATE );
8426584368
pExpr = pExpr->pLeft;
8426684369
}
8426784370
}
8426884371
return pExpr;
8426984372
}
@@ -84590,11 +84693,11 @@
8459084693
** for this node and for the pToken argument is a single allocation
8459184694
** obtained from sqlite3DbMalloc(). The calling function
8459284695
** is responsible for making sure the node eventually gets freed.
8459384696
**
8459484697
** If dequote is true, then the token (if it exists) is dequoted.
84595
-** If dequote is false, no dequoting is performance. The deQuote
84698
+** If dequote is false, no dequoting is performed. The deQuote
8459684699
** parameter is ignored if pToken is NULL or if the token does not
8459784700
** appear to be quoted. If the quotes were of the form "..." (double-quotes)
8459884701
** then the EP_DblQuoted flag is set on the expression node.
8459984702
**
8460084703
** Special case: If op==TK_INTEGER and pToken points to a string that
@@ -85191,20 +85294,22 @@
8519185294
Table *pTab;
8519285295
pNewItem->pSchema = pOldItem->pSchema;
8519385296
pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
8519485297
pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
8519585298
pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
85196
- pNewItem->jointype = pOldItem->jointype;
85299
+ pNewItem->fg = pOldItem->fg;
8519785300
pNewItem->iCursor = pOldItem->iCursor;
8519885301
pNewItem->addrFillSub = pOldItem->addrFillSub;
8519985302
pNewItem->regReturn = pOldItem->regReturn;
85200
- pNewItem->isCorrelated = pOldItem->isCorrelated;
85201
- pNewItem->viaCoroutine = pOldItem->viaCoroutine;
85202
- pNewItem->isRecursive = pOldItem->isRecursive;
85203
- pNewItem->zIndexedBy = sqlite3DbStrDup(db, pOldItem->zIndexedBy);
85204
- pNewItem->notIndexed = pOldItem->notIndexed;
85205
- pNewItem->pIndex = pOldItem->pIndex;
85303
+ if( pNewItem->fg.isIndexedBy ){
85304
+ pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
85305
+ }
85306
+ pNewItem->pIBIndex = pOldItem->pIBIndex;
85307
+ if( pNewItem->fg.isTabFunc ){
85308
+ pNewItem->u1.pFuncArg =
85309
+ sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
85310
+ }
8520685311
pTab = pNewItem->pTab = pOldItem->pTab;
8520785312
if( pTab ){
8520885313
pTab->nRef++;
8520985314
}
8521085315
pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
@@ -85314,10 +85419,24 @@
8531485419
/* Avoid leaking memory if malloc has failed. */
8531585420
sqlite3ExprDelete(db, pExpr);
8531685421
sqlite3ExprListDelete(db, pList);
8531785422
return 0;
8531885423
}
85424
+
85425
+/*
85426
+** Set the sort order for the last element on the given ExprList.
85427
+*/
85428
+SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder){
85429
+ if( p==0 ) return;
85430
+ assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC>=0 && SQLITE_SO_DESC>0 );
85431
+ assert( p->nExpr>0 );
85432
+ if( iSortOrder<0 ){
85433
+ assert( p->a[p->nExpr-1].sortOrder==SQLITE_SO_ASC );
85434
+ return;
85435
+ }
85436
+ p->a[p->nExpr-1].sortOrder = (u8)iSortOrder;
85437
+}
8531985438
8532085439
/*
8532185440
** Set the ExprList.a[].zName element of the most recently added item
8532285441
** on the expression list.
8532385442
**
@@ -86286,11 +86405,11 @@
8628686405
}
8628786406
sqlite3ReleaseTempReg(pParse, regToFree);
8628886407
}
8628986408
if( regCkNull ){
8629086409
sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
86291
- sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
86410
+ sqlite3VdbeGoto(v, destIfFalse);
8629286411
}
8629386412
sqlite3VdbeResolveLabel(v, labelOk);
8629486413
sqlite3ReleaseTempReg(pParse, regCkNull);
8629586414
}else{
8629686415
@@ -86304,11 +86423,11 @@
8630486423
sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
8630586424
}else{
8630686425
int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
8630786426
sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
8630886427
VdbeCoverage(v);
86309
- sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
86428
+ sqlite3VdbeGoto(v, destIfNull);
8631086429
sqlite3VdbeJumpHere(v, addr1);
8631186430
}
8631286431
}
8631386432
8631486433
if( eType==IN_INDEX_ROWID ){
@@ -86354,11 +86473,11 @@
8635486473
*/
8635586474
j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
8635686475
VdbeCoverage(v);
8635786476
sqlite3VdbeAddOp2(v, OP_IsNull, rRhsHasNull, destIfNull);
8635886477
VdbeCoverage(v);
86359
- sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
86478
+ sqlite3VdbeGoto(v, destIfFalse);
8636086479
sqlite3VdbeJumpHere(v, j1);
8636186480
}
8636286481
}
8636386482
}
8636486483
sqlite3ReleaseTempReg(pParse, r1);
@@ -86572,10 +86691,32 @@
8657286691
if( p->iReg==iReg ){
8657386692
p->tempReg = 0;
8657486693
}
8657586694
}
8657686695
}
86696
+
86697
+/* Generate code that will load into register regOut a value that is
86698
+** appropriate for the iIdxCol-th column of index pIdx.
86699
+*/
86700
+SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(
86701
+ Parse *pParse, /* The parsing context */
86702
+ Index *pIdx, /* The index whose column is to be loaded */
86703
+ int iTabCur, /* Cursor pointing to a table row */
86704
+ int iIdxCol, /* The column of the index to be loaded */
86705
+ int regOut /* Store the index column value in this register */
86706
+){
86707
+ i16 iTabCol = pIdx->aiColumn[iIdxCol];
86708
+ if( iTabCol>=(-1) ){
86709
+ sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
86710
+ iTabCol, regOut);
86711
+ return;
86712
+ }
86713
+ assert( pIdx->aColExpr );
86714
+ assert( pIdx->aColExpr->nExpr>iIdxCol );
86715
+ pParse->iSelfTab = iTabCur;
86716
+ sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
86717
+}
8657786718
8657886719
/*
8657986720
** Generate code to extract the value of the iCol-th column of a table.
8658086721
*/
8658186722
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
@@ -86758,12 +86899,13 @@
8675886899
if( pParse->ckBase>0 ){
8675986900
/* Generating CHECK constraints or inserting into partial index */
8676086901
inReg = pExpr->iColumn + pParse->ckBase;
8676186902
break;
8676286903
}else{
86763
- /* Deleting from a partial index */
86764
- iTab = pParse->iPartIdxTab;
86904
+ /* Coding an expression that is part of an index where column names
86905
+ ** in the index refer to the table to which the index belongs */
86906
+ iTab = pParse->iSelfTab;
8676586907
}
8676686908
}
8676786909
inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
8676886910
pExpr->iColumn, iTab, target,
8676986911
pExpr->op2);
@@ -86780,11 +86922,11 @@
8678086922
break;
8678186923
}
8678286924
#endif
8678386925
case TK_STRING: {
8678486926
assert( !ExprHasProperty(pExpr, EP_IntValue) );
86785
- sqlite3VdbeAddOp4(v, OP_String8, 0, target, 0, pExpr->u.zToken, 0);
86927
+ sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
8678686928
break;
8678786929
}
8678886930
case TK_NULL: {
8678986931
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
8679086932
break;
@@ -86819,14 +86961,10 @@
8681986961
}
8682086962
case TK_REGISTER: {
8682186963
inReg = pExpr->iTable;
8682286964
break;
8682386965
}
86824
- case TK_AS: {
86825
- inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
86826
- break;
86827
- }
8682886966
#ifndef SQLITE_OMIT_CAST
8682986967
case TK_CAST: {
8683086968
/* Expressions of the form: CAST(pLeft AS token) */
8683186969
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
8683286970
if( inReg!=target ){
@@ -87053,11 +87191,11 @@
8705387191
pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
8705487192
}
8705587193
}
8705687194
8705787195
sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
87058
- sqlite3ExprCodeExprList(pParse, pFarg, r1,
87196
+ sqlite3ExprCodeExprList(pParse, pFarg, r1, 0,
8705987197
SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
8706087198
sqlite3ExprCachePop(pParse); /* Ticket 2ea2425d34be */
8706187199
}else{
8706287200
r1 = 0;
8706387201
}
@@ -87277,11 +87415,11 @@
8727787415
nextCase = sqlite3VdbeMakeLabel(v);
8727887416
testcase( pTest->op==TK_COLUMN );
8727987417
sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
8728087418
testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
8728187419
sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
87282
- sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
87420
+ sqlite3VdbeGoto(v, endLabel);
8728387421
sqlite3ExprCachePop(pParse);
8728487422
sqlite3VdbeResolveLabel(v, nextCase);
8728587423
}
8728687424
if( (nExpr&1)!=0 ){
8728787425
sqlite3ExprCachePush(pParse);
@@ -87469,29 +87607,32 @@
8746987607
*/
8747087608
SQLITE_PRIVATE int sqlite3ExprCodeExprList(
8747187609
Parse *pParse, /* Parsing context */
8747287610
ExprList *pList, /* The expression list to be coded */
8747387611
int target, /* Where to write results */
87612
+ int srcReg, /* Source registers if SQLITE_ECEL_REF */
8747487613
u8 flags /* SQLITE_ECEL_* flags */
8747587614
){
8747687615
struct ExprList_item *pItem;
87477
- int i, n;
87616
+ int i, j, n;
8747887617
u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
87618
+ Vdbe *v = pParse->pVdbe;
8747987619
assert( pList!=0 );
8748087620
assert( target>0 );
8748187621
assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
8748287622
n = pList->nExpr;
8748387623
if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
8748487624
for(pItem=pList->a, i=0; i<n; i++, pItem++){
8748587625
Expr *pExpr = pItem->pExpr;
87486
- if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
87626
+ if( (flags & SQLITE_ECEL_REF)!=0 && (j = pList->a[i].u.x.iOrderByCol)>0 ){
87627
+ sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
87628
+ }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
8748787629
sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
8748887630
}else{
8748987631
int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
8749087632
if( inReg!=target+i ){
8749187633
VdbeOp *pOp;
87492
- Vdbe *v = pParse->pVdbe;
8749387634
if( copyOp==OP_Copy
8749487635
&& (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
8749587636
&& pOp->p1+pOp->p3+1==inReg
8749687637
&& pOp->p2+pOp->p3+1==target+i
8749787638
){
@@ -87664,18 +87805,18 @@
8766487805
#ifndef SQLITE_OMIT_SUBQUERY
8766587806
case TK_IN: {
8766687807
int destIfFalse = sqlite3VdbeMakeLabel(v);
8766787808
int destIfNull = jumpIfNull ? dest : destIfFalse;
8766887809
sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
87669
- sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
87810
+ sqlite3VdbeGoto(v, dest);
8767087811
sqlite3VdbeResolveLabel(v, destIfFalse);
8767187812
break;
8767287813
}
8767387814
#endif
8767487815
default: {
8767587816
if( exprAlwaysTrue(pExpr) ){
87676
- sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
87817
+ sqlite3VdbeGoto(v, dest);
8767787818
}else if( exprAlwaysFalse(pExpr) ){
8767887819
/* No-op */
8767987820
}else{
8768087821
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
8768187822
sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
@@ -87827,11 +87968,11 @@
8782787968
break;
8782887969
}
8782987970
#endif
8783087971
default: {
8783187972
if( exprAlwaysFalse(pExpr) ){
87832
- sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
87973
+ sqlite3VdbeGoto(v, dest);
8783387974
}else if( exprAlwaysTrue(pExpr) ){
8783487975
/* no-op */
8783587976
}else{
8783687977
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
8783787978
sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
@@ -87903,11 +88044,13 @@
8790388044
return 1;
8790488045
}
8790588046
return 2;
8790688047
}
8790788048
if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
87908
- if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
88049
+ if( pA->op==TK_FUNCTION ){
88050
+ if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
88051
+ }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
8790988052
return pA->op==TK_COLLATE ? 1 : 2;
8791088053
}
8791188054
}
8791288055
if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
8791388056
if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
@@ -88811,11 +88954,11 @@
8881188954
** SQLite tables) that are identified by the name of the virtual table.
8881288955
*/
8881388956
#ifndef SQLITE_OMIT_VIRTUALTABLE
8881488957
if( pVTab ){
8881588958
int i = ++pParse->nMem;
88816
- sqlite3VdbeAddOp4(v, OP_String8, 0, i, 0, zName, 0);
88959
+ sqlite3VdbeLoadString(v, i, zName);
8881788960
sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
8881888961
sqlite3MayAbort(pParse);
8881988962
}
8882088963
#endif
8882188964
@@ -90169,11 +90312,11 @@
9016990312
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
9017090313
iTabCur = iTab++;
9017190314
iIdxCur = iTab++;
9017290315
pParse->nTab = MAX(pParse->nTab, iTab);
9017390316
sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
90174
- sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
90317
+ sqlite3VdbeLoadString(v, regTabname, pTab->zName);
9017590318
9017690319
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
9017790320
int nCol; /* Number of columns in pIdx. "N" */
9017890321
int addrRewind; /* Address of "OP_Rewind iIdxCur" */
9017990322
int addrNextRow; /* Address of "next_row:" */
@@ -90191,11 +90334,11 @@
9019190334
zIdxName = pIdx->zName;
9019290335
nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
9019390336
}
9019490337
9019590338
/* Populate the register containing the index name. */
90196
- sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
90339
+ sqlite3VdbeLoadString(v, regIdxname, zIdxName);
9019790340
VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
9019890341
9019990342
/*
9020090343
** Pseudo-code for loop that calls stat_push():
9020190344
**
@@ -90305,11 +90448,11 @@
9030590448
sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
9030690449
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
9030790450
VdbeCoverage(v);
9030890451
}
9030990452
sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
90310
- sqlite3VdbeAddOp2(v, OP_Goto, 0, endDistinctTest);
90453
+ sqlite3VdbeGoto(v, endDistinctTest);
9031190454
9031290455
9031390456
/*
9031490457
** chng_addr_0:
9031590458
** regPrev(0) = idx(0)
@@ -90341,10 +90484,11 @@
9034190484
Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
9034290485
int j, k, regKey;
9034390486
regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
9034490487
for(j=0; j<pPk->nKeyCol; j++){
9034590488
k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
90489
+ assert( k>=0 && k<pTab->nCol );
9034690490
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
9034790491
VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
9034890492
}
9034990493
sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
9035090494
sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
@@ -90390,16 +90534,14 @@
9039090534
/* We know that the regSampleRowid row exists because it was read by
9039190535
** the previous loop. Thus the not-found jump of seekOp will never
9039290536
** be taken */
9039390537
VdbeCoverageNeverTaken(v);
9039490538
#ifdef SQLITE_ENABLE_STAT3
90395
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
90396
- pIdx->aiColumn[0], regSample);
90539
+ sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, 0, regSample);
9039790540
#else
9039890541
for(i=0; i<nCol; i++){
90399
- i16 iCol = pIdx->aiColumn[i];
90400
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
90542
+ sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i);
9040190543
}
9040290544
sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol, regSample);
9040390545
#endif
9040490546
sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
9040590547
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
@@ -92121,11 +92263,11 @@
9212192263
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
9212292264
}
9212392265
}
9212492266
9212592267
/* Finally, jump back to the beginning of the executable code. */
92126
- sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
92268
+ sqlite3VdbeGoto(v, 1);
9212792269
}
9212892270
}
9212992271
9213092272
9213192273
/* Get the VDBE program ready for execution
@@ -92256,10 +92398,21 @@
9225692398
}
9225792399
9225892400
p = sqlite3FindTable(pParse->db, zName, zDbase);
9225992401
if( p==0 ){
9226092402
const char *zMsg = isView ? "no such view" : "no such table";
92403
+#ifndef SQLITE_OMIT_VIRTUALTABLE
92404
+ if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
92405
+ /* If zName is the not the name of a table in the schema created using
92406
+ ** CREATE, then check to see if it is the name of an virtual table that
92407
+ ** can be an eponymous virtual table. */
92408
+ Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
92409
+ if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
92410
+ return pMod->pEpoTab;
92411
+ }
92412
+ }
92413
+#endif
9226192414
if( zDbase ){
9226292415
sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
9226392416
}else{
9226492417
sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
9226592418
}
@@ -92334,10 +92487,11 @@
9233492487
static void freeIndex(sqlite3 *db, Index *p){
9233592488
#ifndef SQLITE_OMIT_ANALYZE
9233692489
sqlite3DeleteIndexSamples(db, p);
9233792490
#endif
9233892491
sqlite3ExprDelete(db, p->pPartIdxWhere);
92492
+ sqlite3ExprListDelete(db, p->aColExpr);
9233992493
sqlite3DbFree(db, p->zColAff);
9234092494
if( p->isResized ) sqlite3DbFree(db, p->azColl);
9234192495
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
9234292496
sqlite3_free(p->aiRowEst);
9234392497
#endif
@@ -92460,11 +92614,11 @@
9246092614
9246192615
/*
9246292616
** Delete memory allocated for the column names of a table or view (the
9246392617
** Table.aCol[] array).
9246492618
*/
92465
-static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
92619
+SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
9246692620
int i;
9246792621
Column *pCol;
9246892622
assert( pTable!=0 );
9246992623
if( (pCol = pTable->aCol)!=0 ){
9247092624
for(i=0; i<pTable->nCol; i++, pCol++){
@@ -92527,17 +92681,15 @@
9252792681
/* Delete any foreign keys attached to this table. */
9252892682
sqlite3FkDelete(db, pTable);
9252992683
9253092684
/* Delete the Table structure itself.
9253192685
*/
92532
- sqliteDeleteColumnNames(db, pTable);
92686
+ sqlite3DeleteColumnNames(db, pTable);
9253392687
sqlite3DbFree(db, pTable->zName);
9253492688
sqlite3DbFree(db, pTable->zColAff);
9253592689
sqlite3SelectDelete(db, pTable->pSelect);
92536
-#ifndef SQLITE_OMIT_CHECK
9253792690
sqlite3ExprListDelete(db, pTable->pCheck);
92538
-#endif
9253992691
#ifndef SQLITE_OMIT_VIRTUALTABLE
9254092692
sqlite3VtabClear(db, pTable);
9254192693
#endif
9254292694
sqlite3DbFree(db, pTable);
9254392695
@@ -92876,10 +93028,12 @@
9287693028
*/
9287793029
if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
9287893030
int j1;
9287993031
int fileFormat;
9288093032
int reg1, reg2, reg3;
93033
+ /* nullRow[] is an OP_Record encoding of a row containing 5 NULLs */
93034
+ static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
9288193035
sqlite3BeginWriteOperation(pParse, 1, iDb);
9288293036
9288393037
#ifndef SQLITE_OMIT_VIRTUALTABLE
9288493038
if( isVirtual ){
9288593039
sqlite3VdbeAddOp0(v, OP_VBegin);
@@ -92920,11 +93074,11 @@
9292093074
{
9292193075
pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
9292293076
}
9292393077
sqlite3OpenMasterTable(pParse, iDb);
9292493078
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
92925
- sqlite3VdbeAddOp2(v, OP_Null, 0, reg3);
93079
+ sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
9292693080
sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
9292793081
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
9292893082
sqlite3VdbeAddOp0(v, OP_Close);
9292993083
}
9293093084
@@ -93201,22 +93355,27 @@
9320193355
zType = pTab->aCol[iCol].zType;
9320293356
nTerm = 1;
9320393357
}else{
9320493358
nTerm = pList->nExpr;
9320593359
for(i=0; i<nTerm; i++){
93206
- for(iCol=0; iCol<pTab->nCol; iCol++){
93207
- if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
93208
- pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
93209
- zType = pTab->aCol[iCol].zType;
93210
- break;
93360
+ Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
93361
+ assert( pCExpr!=0 );
93362
+ if( pCExpr->op==TK_ID ){
93363
+ const char *zCName = pCExpr->u.zToken;
93364
+ for(iCol=0; iCol<pTab->nCol; iCol++){
93365
+ if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
93366
+ pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
93367
+ zType = pTab->aCol[iCol].zType;
93368
+ break;
93369
+ }
9321193370
}
9321293371
}
9321393372
}
9321493373
}
9321593374
if( nTerm==1
9321693375
&& zType && sqlite3StrICmp(zType, "INTEGER")==0
93217
- && sortOrder==SQLITE_SO_ASC
93376
+ && sortOrder!=SQLITE_SO_DESC
9321893377
){
9321993378
pTab->iPKey = iCol;
9322093379
pTab->keyConf = (u8)onError;
9322193380
assert( autoInc==0 || autoInc==1 );
9322293381
pTab->tabFlags |= autoInc*TF_Autoincrement;
@@ -93579,22 +93738,24 @@
9357993738
** root-page for the table into an OP_CreateIndex opcode. The index
9358093739
** created will become the PRIMARY KEY index.
9358193740
*/
9358293741
if( pParse->addrCrTab ){
9358393742
assert( v );
93584
- sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
93743
+ sqlite3VdbeChangeOpcode(v, pParse->addrCrTab, OP_CreateIndex);
9358593744
}
9358693745
9358793746
/* Locate the PRIMARY KEY index. Or, if this table was originally
9358893747
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
9358993748
*/
9359093749
if( pTab->iPKey>=0 ){
9359193750
ExprList *pList;
93592
- pList = sqlite3ExprListAppend(pParse, 0, 0);
93751
+ Token ipkToken;
93752
+ ipkToken.z = pTab->aCol[pTab->iPKey].zName;
93753
+ ipkToken.n = sqlite3Strlen30(ipkToken.z);
93754
+ pList = sqlite3ExprListAppend(pParse, 0,
93755
+ sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
9359393756
if( pList==0 ) return;
93594
- pList->a[0].zName = sqlite3DbStrDup(pParse->db,
93595
- pTab->aCol[pTab->iPKey].zName);
9359693757
pList->a[0].sortOrder = pParse->iPkSortOrder;
9359793758
assert( pParse->pNewTable==pTab );
9359893759
pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
9359993760
if( pPk==0 ) return;
9360093761
pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
@@ -93606,11 +93767,11 @@
9360693767
** table entry. This is only required if currently generating VDBE
9360793768
** code for a CREATE TABLE (not when parsing one as part of reading
9360893769
** a database schema). */
9360993770
if( v ){
9361093771
assert( db->init.busy==0 );
93611
- sqlite3VdbeGetOp(v, pPk->tnum)->opcode = OP_Goto;
93772
+ sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
9361293773
}
9361393774
9361493775
/*
9361593776
** Remove all redundant columns from the PRIMARY KEY. For example, change
9361693777
** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
@@ -93716,13 +93877,14 @@
9371693877
Table *p; /* The new table */
9371793878
sqlite3 *db = pParse->db; /* The database connection */
9371893879
int iDb; /* Database in which the table lives */
9371993880
Index *pIdx; /* An implied index of the table */
9372093881
93721
- if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
93882
+ if( pEnd==0 && pSelect==0 ){
9372293883
return;
9372393884
}
93885
+ assert( !db->mallocFailed );
9372493886
p = pParse->pNewTable;
9372593887
if( p==0 ) return;
9372693888
9372793889
assert( !db->init.busy || !pSelect );
9372893890
@@ -93849,11 +94011,11 @@
9384994011
VdbeCoverage(v);
9385094012
sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
9385194013
sqlite3TableAffinity(v, p, 0);
9385294014
sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
9385394015
sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
93854
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop);
94016
+ sqlite3VdbeGoto(v, addrInsLoop);
9385594017
sqlite3VdbeJumpHere(v, addrInsLoop);
9385694018
sqlite3VdbeAddOp1(v, OP_Close, 1);
9385794019
}
9385894020
9385994021
/* Compute the complete text of the CREATE statement */
@@ -93946,10 +94108,11 @@
9394694108
SQLITE_PRIVATE void sqlite3CreateView(
9394794109
Parse *pParse, /* The parsing context */
9394894110
Token *pBegin, /* The CREATE token that begins the statement */
9394994111
Token *pName1, /* The token that holds the name of the view */
9395094112
Token *pName2, /* The token that holds the name of the view */
94113
+ ExprList *pCNames, /* Optional list of view column names */
9395194114
Select *pSelect, /* A SELECT statement that will become the new view */
9395294115
int isTemp, /* TRUE for a TEMPORARY view */
9395394116
int noErr /* Suppress error messages if VIEW already exists */
9395494117
){
9395594118
Table *p;
@@ -93966,52 +94129,47 @@
9396694129
sqlite3SelectDelete(db, pSelect);
9396794130
return;
9396894131
}
9396994132
sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
9397094133
p = pParse->pNewTable;
93971
- if( p==0 || pParse->nErr ){
93972
- sqlite3SelectDelete(db, pSelect);
93973
- return;
93974
- }
94134
+ if( p==0 || pParse->nErr ) goto create_view_fail;
9397594135
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
9397694136
iDb = sqlite3SchemaToIndex(db, p->pSchema);
9397794137
sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
93978
- if( sqlite3FixSelect(&sFix, pSelect) ){
93979
- sqlite3SelectDelete(db, pSelect);
93980
- return;
93981
- }
94138
+ if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
9398294139
9398394140
/* Make a copy of the entire SELECT statement that defines the view.
9398494141
** This will force all the Expr.token.z values to be dynamically
9398594142
** allocated rather than point to the input string - which means that
9398694143
** they will persist after the current sqlite3_exec() call returns.
9398794144
*/
9398894145
p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
93989
- sqlite3SelectDelete(db, pSelect);
93990
- if( db->mallocFailed ){
93991
- return;
93992
- }
93993
- if( !db->init.busy ){
93994
- sqlite3ViewGetColumnNames(pParse, p);
93995
- }
94146
+ p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
94147
+ if( db->mallocFailed ) goto create_view_fail;
9399694148
9399794149
/* Locate the end of the CREATE VIEW statement. Make sEnd point to
9399894150
** the end.
9399994151
*/
9400094152
sEnd = pParse->sLastToken;
94001
- if( ALWAYS(sEnd.z[0]!=0) && sEnd.z[0]!=';' ){
94153
+ assert( sEnd.z[0]!=0 );
94154
+ if( sEnd.z[0]!=';' ){
9400294155
sEnd.z += sEnd.n;
9400394156
}
9400494157
sEnd.n = 0;
9400594158
n = (int)(sEnd.z - pBegin->z);
94159
+ assert( n>0 );
9400694160
z = pBegin->z;
94007
- while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
94161
+ while( sqlite3Isspace(z[n-1]) ){ n--; }
9400894162
sEnd.z = &z[n-1];
9400994163
sEnd.n = 1;
9401094164
9401194165
/* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
9401294166
sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
94167
+
94168
+create_view_fail:
94169
+ sqlite3SelectDelete(db, pSelect);
94170
+ sqlite3ExprListDelete(db, pCNames);
9401394171
return;
9401494172
}
9401594173
#endif /* SQLITE_OMIT_VIEW */
9401694174
9401794175
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -94025,10 +94183,11 @@
9402594183
Select *pSel; /* Copy of the SELECT that implements the view */
9402694184
int nErr = 0; /* Number of errors encountered */
9402794185
int n; /* Temporarily holds the number of cursors assigned */
9402894186
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
9402994187
sqlite3_xauth xAuth; /* Saved xAuth pointer */
94188
+ u8 bEnabledLA; /* Saved db->lookaside.bEnabled state */
9403094189
9403194190
assert( pTable );
9403294191
9403394192
#ifndef SQLITE_OMIT_VIRTUALTABLE
9403494193
if( sqlite3VtabCallConnect(pParse, pTable) ){
@@ -94070,44 +94229,50 @@
9407094229
** to the elements of the FROM clause. But we do not want these changes
9407194230
** to be permanent. So the computation is done on a copy of the SELECT
9407294231
** statement that defines the view.
9407394232
*/
9407494233
assert( pTable->pSelect );
94075
- pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
94076
- if( pSel ){
94077
- u8 enableLookaside = db->lookaside.bEnabled;
94078
- n = pParse->nTab;
94079
- sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
94080
- pTable->nCol = -1;
94081
- db->lookaside.bEnabled = 0;
94082
-#ifndef SQLITE_OMIT_AUTHORIZATION
94083
- xAuth = db->xAuth;
94084
- db->xAuth = 0;
94085
- pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94086
- db->xAuth = xAuth;
94087
-#else
94088
- pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94089
-#endif
94090
- db->lookaside.bEnabled = enableLookaside;
94091
- pParse->nTab = n;
94092
- if( pSelTab ){
94093
- assert( pTable->aCol==0 );
94094
- pTable->nCol = pSelTab->nCol;
94095
- pTable->aCol = pSelTab->aCol;
94096
- pSelTab->nCol = 0;
94097
- pSelTab->aCol = 0;
94098
- sqlite3DeleteTable(db, pSelTab);
94099
- assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
94100
- pTable->pSchema->schemaFlags |= DB_UnresetViews;
94101
- }else{
94102
- pTable->nCol = 0;
94103
- nErr++;
94104
- }
94105
- sqlite3SelectDelete(db, pSel);
94106
- } else {
94107
- nErr++;
94108
- }
94234
+ bEnabledLA = db->lookaside.bEnabled;
94235
+ if( pTable->pCheck ){
94236
+ db->lookaside.bEnabled = 0;
94237
+ sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
94238
+ &pTable->nCol, &pTable->aCol);
94239
+ }else{
94240
+ pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
94241
+ if( pSel ){
94242
+ n = pParse->nTab;
94243
+ sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
94244
+ pTable->nCol = -1;
94245
+ db->lookaside.bEnabled = 0;
94246
+#ifndef SQLITE_OMIT_AUTHORIZATION
94247
+ xAuth = db->xAuth;
94248
+ db->xAuth = 0;
94249
+ pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94250
+ db->xAuth = xAuth;
94251
+#else
94252
+ pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94253
+#endif
94254
+ pParse->nTab = n;
94255
+ if( pSelTab ){
94256
+ assert( pTable->aCol==0 );
94257
+ pTable->nCol = pSelTab->nCol;
94258
+ pTable->aCol = pSelTab->aCol;
94259
+ pSelTab->nCol = 0;
94260
+ pSelTab->aCol = 0;
94261
+ sqlite3DeleteTable(db, pSelTab);
94262
+ assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
94263
+ }else{
94264
+ pTable->nCol = 0;
94265
+ nErr++;
94266
+ }
94267
+ sqlite3SelectDelete(db, pSel);
94268
+ } else {
94269
+ nErr++;
94270
+ }
94271
+ }
94272
+ db->lookaside.bEnabled = bEnabledLA;
94273
+ pTable->pSchema->schemaFlags |= DB_UnresetViews;
9410994274
#endif /* SQLITE_OMIT_VIEW */
9411094275
return nErr;
9411194276
}
9411294277
#endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
9411394278
@@ -94120,11 +94285,11 @@
9412094285
assert( sqlite3SchemaMutexHeld(db, idx, 0) );
9412194286
if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
9412294287
for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
9412394288
Table *pTab = sqliteHashData(i);
9412494289
if( pTab->pSelect ){
94125
- sqliteDeleteColumnNames(db, pTab);
94290
+ sqlite3DeleteColumnNames(db, pTab);
9412694291
pTab->aCol = 0;
9412794292
pTab->nCol = 0;
9412894293
}
9412994294
}
9413094295
DbClearProperty(db, idx, DB_UnresetViews);
@@ -94675,11 +94840,11 @@
9467594840
9467694841
addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
9467794842
assert( pKey!=0 || db->mallocFailed || pParse->nErr );
9467894843
if( IsUniqueIndex(pIndex) && pKey!=0 ){
9467994844
int j2 = sqlite3VdbeCurrentAddr(v) + 3;
94680
- sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
94845
+ sqlite3VdbeGoto(v, j2);
9468194846
addr2 = sqlite3VdbeCurrentAddr(v);
9468294847
sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
9468394848
pIndex->nKeyCol); VdbeCoverage(v);
9468494849
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
9468594850
}else{
@@ -94730,10 +94895,34 @@
9473094895
p->nKeyCol = nCol - 1;
9473194896
*ppExtra = ((char*)p) + nByte;
9473294897
}
9473394898
return p;
9473494899
}
94900
+
94901
+/*
94902
+** Backwards Compatibility Hack:
94903
+**
94904
+** Historical versions of SQLite accepted strings as column names in
94905
+** indexes and PRIMARY KEY constraints and in UNIQUE constraints. Example:
94906
+**
94907
+** CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
94908
+** CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
94909
+**
94910
+** This is goofy. But to preserve backwards compatibility we continue to
94911
+** accept it. This routine does the necessary conversion. It converts
94912
+** the expression given in its argument from a TK_STRING into a TK_ID
94913
+** if the expression is just a TK_STRING with an optional COLLATE clause.
94914
+** If the epxression is anything other than TK_STRING, the expression is
94915
+** unchanged.
94916
+*/
94917
+static void sqlite3StringToId(Expr *p){
94918
+ if( p->op==TK_STRING ){
94919
+ p->op = TK_ID;
94920
+ }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
94921
+ p->pLeft->op = TK_ID;
94922
+ }
94923
+}
9473594924
9473694925
/*
9473794926
** Create a new index for an SQL table. pName1.pName2 is the name of the index
9473894927
** and pTblList is the name of the table that is to be indexed. Both will
9473994928
** be NULL for a primary key or an index that is created to satisfy a
@@ -94772,11 +94961,10 @@
9477294961
sqlite3 *db = pParse->db;
9477394962
Db *pDb; /* The specific table containing the indexed database */
9477494963
int iDb; /* Index of the database that is being written */
9477594964
Token *pName = 0; /* Unqualified name of the index to create */
9477694965
struct ExprList_item *pListItem; /* For looping over pList */
94777
- const Column *pTabCol; /* A column in the table */
9477894966
int nExtra = 0; /* Space allocated for zExtra[] */
9477994967
int nExtraCol; /* Number of extra columns needed */
9478094968
char *zExtra = 0; /* Extra space after the Index object */
9478194969
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
9478294970
@@ -94927,24 +95115,29 @@
9492795115
/* If pList==0, it means this routine was called to make a primary
9492895116
** key out of the last column added to the table under construction.
9492995117
** So create a fake list to simulate this.
9493095118
*/
9493195119
if( pList==0 ){
94932
- pList = sqlite3ExprListAppend(pParse, 0, 0);
95120
+ Token prevCol;
95121
+ prevCol.z = pTab->aCol[pTab->nCol-1].zName;
95122
+ prevCol.n = sqlite3Strlen30(prevCol.z);
95123
+ pList = sqlite3ExprListAppend(pParse, 0,
95124
+ sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
9493395125
if( pList==0 ) goto exit_create_index;
94934
- pList->a[0].zName = sqlite3DbStrDup(pParse->db,
94935
- pTab->aCol[pTab->nCol-1].zName);
94936
- pList->a[0].sortOrder = (u8)sortOrder;
95126
+ assert( pList->nExpr==1 );
95127
+ sqlite3ExprListSetSortOrder(pList, sortOrder);
95128
+ }else{
95129
+ sqlite3ExprListCheckLength(pParse, pList, "index");
9493795130
}
9493895131
9493995132
/* Figure out how many bytes of space are required to store explicitly
9494095133
** specified collation sequence names.
9494195134
*/
9494295135
for(i=0; i<pList->nExpr; i++){
9494395136
Expr *pExpr = pList->a[i].pExpr;
94944
- if( pExpr ){
94945
- assert( pExpr->op==TK_COLLATE );
95137
+ assert( pExpr!=0 );
95138
+ if( pExpr->op==TK_COLLATE ){
9494695139
nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
9494795140
}
9494895141
}
9494995142
9495095143
/*
@@ -94981,61 +95174,85 @@
9498195174
sortOrderMask = -1; /* Honor DESC */
9498295175
}else{
9498395176
sortOrderMask = 0; /* Ignore DESC */
9498495177
}
9498595178
94986
- /* Scan the names of the columns of the table to be indexed and
94987
- ** load the column indices into the Index structure. Report an error
94988
- ** if any column is not found.
95179
+ /* Analyze the list of expressions that form the terms of the index and
95180
+ ** report any errors. In the common case where the expression is exactly
95181
+ ** a table column, store that column in aiColumn[]. For general expressions,
95182
+ ** populate pIndex->aColExpr and store -2 in aiColumn[].
9498995183
**
94990
- ** TODO: Add a test to make sure that the same column is not named
94991
- ** more than once within the same index. Only the first instance of
94992
- ** the column will ever be used by the optimizer. Note that using the
94993
- ** same column more than once cannot be an error because that would
94994
- ** break backwards compatibility - it needs to be a warning.
95184
+ ** TODO: Issue a warning if two or more columns of the index are identical.
95185
+ ** TODO: Issue a warning if the table primary key is used as part of the
95186
+ ** index key.
9499595187
*/
9499695188
for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){
94997
- const char *zColName = pListItem->zName;
94998
- int requestedSortOrder;
95189
+ Expr *pCExpr; /* The i-th index expression */
95190
+ int requestedSortOrder; /* ASC or DESC on the i-th expression */
9499995191
char *zColl; /* Collation sequence name */
9500095192
95001
- for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){
95002
- if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break;
95003
- }
95004
- if( j>=pTab->nCol ){
95005
- sqlite3ErrorMsg(pParse, "table %s has no column named %s",
95006
- pTab->zName, zColName);
95007
- pParse->checkSchema = 1;
95008
- goto exit_create_index;
95009
- }
95010
- assert( j<=0x7fff );
95011
- pIndex->aiColumn[i] = (i16)j;
95012
- if( pListItem->pExpr ){
95013
- int nColl;
95014
- assert( pListItem->pExpr->op==TK_COLLATE );
95193
+ sqlite3StringToId(pListItem->pExpr);
95194
+ sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
95195
+ if( pParse->nErr ) goto exit_create_index;
95196
+ pCExpr = sqlite3ExprSkipCollate(pListItem->pExpr);
95197
+ if( pCExpr->op!=TK_COLUMN ){
95198
+ if( pTab==pParse->pNewTable ){
95199
+ sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
95200
+ "UNIQUE constraints");
95201
+ goto exit_create_index;
95202
+ }
95203
+ if( pIndex->aColExpr==0 ){
95204
+ ExprList *pCopy = sqlite3ExprListDup(db, pList, 0);
95205
+ pIndex->aColExpr = pCopy;
95206
+ if( !db->mallocFailed ){
95207
+ assert( pCopy!=0 );
95208
+ pListItem = &pCopy->a[i];
95209
+ }
95210
+ }
95211
+ j = -2;
95212
+ pIndex->aiColumn[i] = -2;
95213
+ pIndex->uniqNotNull = 0;
95214
+ }else{
95215
+ j = pCExpr->iColumn;
95216
+ assert( j<=0x7fff );
95217
+ if( j<0 ){
95218
+ j = pTab->iPKey;
95219
+ }else if( pTab->aCol[j].notNull==0 ){
95220
+ pIndex->uniqNotNull = 0;
95221
+ }
95222
+ pIndex->aiColumn[i] = (i16)j;
95223
+ }
95224
+ zColl = 0;
95225
+ if( pListItem->pExpr->op==TK_COLLATE ){
95226
+ int nColl;
9501595227
zColl = pListItem->pExpr->u.zToken;
9501695228
nColl = sqlite3Strlen30(zColl) + 1;
9501795229
assert( nExtra>=nColl );
9501895230
memcpy(zExtra, zColl, nColl);
9501995231
zColl = zExtra;
9502095232
zExtra += nColl;
9502195233
nExtra -= nColl;
95022
- }else{
95234
+ }else if( j>=0 ){
9502395235
zColl = pTab->aCol[j].zColl;
95024
- if( !zColl ) zColl = "BINARY";
9502595236
}
95237
+ if( !zColl ) zColl = "BINARY";
9502695238
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
9502795239
goto exit_create_index;
9502895240
}
9502995241
pIndex->azColl[i] = zColl;
9503095242
requestedSortOrder = pListItem->sortOrder & sortOrderMask;
9503195243
pIndex->aSortOrder[i] = (u8)requestedSortOrder;
95032
- if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
9503395244
}
95245
+
95246
+ /* Append the table key to the end of the index. For WITHOUT ROWID
95247
+ ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
95248
+ ** normal tables (when pPk==0) this will be the rowid.
95249
+ */
9503495250
if( pPk ){
9503595251
for(j=0; j<pPk->nKeyCol; j++){
9503695252
int x = pPk->aiColumn[j];
95253
+ assert( x>=0 );
9503795254
if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
9503895255
pIndex->nColumn--;
9503995256
}else{
9504095257
pIndex->aiColumn[i] = x;
9504195258
pIndex->azColl[i] = pPk->azColl[j];
@@ -95082,10 +95299,11 @@
9508295299
9508395300
if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
9508495301
for(k=0; k<pIdx->nKeyCol; k++){
9508595302
const char *z1;
9508695303
const char *z2;
95304
+ assert( pIdx->aiColumn[k]>=0 );
9508795305
if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
9508895306
z1 = pIdx->azColl[k];
9508995307
z2 = pIndex->azColl[k];
9509095308
if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
9509195309
}
@@ -95113,10 +95331,11 @@
9511395331
}
9511495332
9511595333
/* Link the new Index structure to its table and to the other
9511695334
** in-memory database structures.
9511795335
*/
95336
+ assert( pParse->nErr==0 );
9511895337
if( db->init.busy ){
9511995338
Index *p;
9512095339
assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
9512195340
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
9512295341
pIndex->zName, pIndex);
@@ -95142,11 +95361,11 @@
9514295361
** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
9514395362
** or UNIQUE index in a CREATE TABLE statement. Since the table
9514495363
** has just been created, it contains no data and the index initialization
9514595364
** step can be skipped.
9514695365
*/
95147
- else if( pParse->nErr==0 && (HasRowid(pTab) || pTblName!=0) ){
95366
+ else if( HasRowid(pTab) || pTblName!=0 ){
9514895367
Vdbe *v;
9514995368
char *zStmt;
9515095369
int iMem = ++pParse->nMem;
9515195370
9515295371
v = sqlite3GetVdbe(pParse);
@@ -95602,11 +95821,12 @@
9560295821
if( pList==0 ) return;
9560395822
for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
9560495823
sqlite3DbFree(db, pItem->zDatabase);
9560595824
sqlite3DbFree(db, pItem->zName);
9560695825
sqlite3DbFree(db, pItem->zAlias);
95607
- sqlite3DbFree(db, pItem->zIndexedBy);
95826
+ if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
95827
+ if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
9560895828
sqlite3DeleteTable(db, pItem->pTab);
9560995829
sqlite3SelectDelete(db, pItem->pSelect);
9561095830
sqlite3ExprDelete(db, pItem->pOn);
9561195831
sqlite3IdListDelete(db, pItem->pUsing);
9561295832
}
@@ -95675,20 +95895,40 @@
9567595895
*/
9567695896
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
9567795897
assert( pIndexedBy!=0 );
9567895898
if( p && ALWAYS(p->nSrc>0) ){
9567995899
struct SrcList_item *pItem = &p->a[p->nSrc-1];
95680
- assert( pItem->notIndexed==0 && pItem->zIndexedBy==0 );
95900
+ assert( pItem->fg.notIndexed==0 );
95901
+ assert( pItem->fg.isIndexedBy==0 );
95902
+ assert( pItem->fg.isTabFunc==0 );
9568195903
if( pIndexedBy->n==1 && !pIndexedBy->z ){
9568295904
/* A "NOT INDEXED" clause was supplied. See parse.y
9568395905
** construct "indexed_opt" for details. */
95684
- pItem->notIndexed = 1;
95906
+ pItem->fg.notIndexed = 1;
9568595907
}else{
95686
- pItem->zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
95908
+ pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
95909
+ pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy!=0);
9568795910
}
9568895911
}
9568995912
}
95913
+
95914
+/*
95915
+** Add the list of function arguments to the SrcList entry for a
95916
+** table-valued-function.
95917
+*/
95918
+SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *pList){
95919
+ if( p && pList ){
95920
+ struct SrcList_item *pItem = &p->a[p->nSrc-1];
95921
+ assert( pItem->fg.notIndexed==0 );
95922
+ assert( pItem->fg.isIndexedBy==0 );
95923
+ assert( pItem->fg.isTabFunc==0 );
95924
+ pItem->u1.pFuncArg = pList;
95925
+ pItem->fg.isTabFunc = 1;
95926
+ }else{
95927
+ sqlite3ExprListDelete(pParse->db, pList);
95928
+ }
95929
+}
9569095930
9569195931
/*
9569295932
** When building up a FROM clause in the parser, the join operator
9569395933
** is initially attached to the left operand. But the code generator
9569495934
** expects the join operator to be on the right operand. This routine
@@ -95705,13 +95945,13 @@
9570595945
*/
9570695946
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
9570795947
if( p ){
9570895948
int i;
9570995949
for(i=p->nSrc-1; i>0; i--){
95710
- p->a[i].jointype = p->a[i-1].jointype;
95950
+ p->a[i].fg.jointype = p->a[i-1].fg.jointype;
9571195951
}
95712
- p->a[0].jointype = 0;
95952
+ p->a[0].fg.jointype = 0;
9571395953
}
9571495954
}
9571595955
9571695956
/*
9571795957
** Begin a transaction
@@ -95951,16 +96191,20 @@
9595196191
int j;
9595296192
StrAccum errMsg;
9595396193
Table *pTab = pIdx->pTable;
9595496194
9595596195
sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
95956
- for(j=0; j<pIdx->nKeyCol; j++){
95957
- char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
95958
- if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
95959
- sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
95960
- sqlite3StrAccumAppend(&errMsg, ".", 1);
95961
- sqlite3StrAccumAppendAll(&errMsg, zCol);
96196
+ if( pIdx->aColExpr ){
96197
+ sqlite3XPrintf(&errMsg, 0, "index '%q'", pIdx->zName);
96198
+ }else{
96199
+ for(j=0; j<pIdx->nKeyCol; j++){
96200
+ char *zCol;
96201
+ assert( pIdx->aiColumn[j]>=0 );
96202
+ zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
96203
+ if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
96204
+ sqlite3XPrintf(&errMsg, 0, "%s.%s", pTab->zName, zCol);
96205
+ }
9596296206
}
9596396207
zErr = sqlite3StrAccumFinish(&errMsg);
9596496208
sqlite3HaltConstraint(pParse,
9596596209
IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
9596696210
: SQLITE_CONSTRAINT_UNIQUE,
@@ -96201,11 +96445,11 @@
9620196445
pNew = pWith;
9620296446
}else{
9620396447
pNew->a[pNew->nCte].pSelect = pQuery;
9620496448
pNew->a[pNew->nCte].pCols = pArglist;
9620596449
pNew->a[pNew->nCte].zName = zName;
96206
- pNew->a[pNew->nCte].zErr = 0;
96450
+ pNew->a[pNew->nCte].zCteErr = 0;
9620796451
pNew->nCte++;
9620896452
}
9620996453
9621096454
return pNew;
9621196455
}
@@ -97120,10 +97364,11 @@
9712097364
}
9712197365
9712297366
/* Extract the rowid or primary key for the current row */
9712397367
if( pPk ){
9712497368
for(i=0; i<nPk; i++){
97369
+ assert( pPk->aiColumn[i]>=(-1) );
9712597370
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
9712697371
pPk->aiColumn[i], iPk+i);
9712797372
}
9712897373
iKey = iPk;
9712997374
}else{
@@ -97152,11 +97397,11 @@
9715297397
}else if( pPk ){
9715397398
/* Construct a composite key for the row to be deleted and remember it */
9715497399
iKey = ++pParse->nMem;
9715597400
nKey = 0; /* Zero tells OP_Found to use a composite key */
9715697401
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
97157
- sqlite3IndexAffinityStr(v, pPk), nPk);
97402
+ sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
9715897403
sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
9715997404
}else{
9716097405
/* Get the rowid of the row to be deleted and remember it in the RowSet */
9716197406
nKey = 1; /* OP_Seek always uses a single rowid */
9716297407
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -97165,11 +97410,11 @@
9716597410
/* End of the WHERE loop */
9716697411
sqlite3WhereEnd(pWInfo);
9716797412
if( okOnePass ){
9716897413
/* Bypass the delete logic below if the WHERE loop found zero rows */
9716997414
addrBypass = sqlite3VdbeMakeLabel(v);
97170
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
97415
+ sqlite3VdbeGoto(v, addrBypass);
9717197416
sqlite3VdbeJumpHere(v, addrDelete);
9717297417
}
9717397418
9717497419
/* Unless this is a view, open cursors for the table we are
9717597420
** deleting from and all its indices. If this is a view, then the
@@ -97227,11 +97472,11 @@
9722797472
sqlite3VdbeResolveLabel(v, addrBypass);
9722897473
}else if( pPk ){
9722997474
sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
9723097475
sqlite3VdbeJumpHere(v, addrLoop);
9723197476
}else{
97232
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
97477
+ sqlite3VdbeGoto(v, addrLoop);
9723397478
sqlite3VdbeJumpHere(v, addrLoop);
9723497479
}
9723597480
9723697481
/* Close the cursors open on the table and its indexes. */
9723797482
if( !isView && !IsVirtual(pTab) ){
@@ -97498,18 +97743,17 @@
9749897743
Index *pPrior, /* Previously generated index key */
9749997744
int regPrior /* Register holding previous generated key */
9750097745
){
9750197746
Vdbe *v = pParse->pVdbe;
9750297747
int j;
97503
- Table *pTab = pIdx->pTable;
9750497748
int regBase;
9750597749
int nCol;
9750697750
9750797751
if( piPartIdxLabel ){
9750897752
if( pIdx->pPartIdxWhere ){
9750997753
*piPartIdxLabel = sqlite3VdbeMakeLabel(v);
97510
- pParse->iPartIdxTab = iDataCur;
97754
+ pParse->iSelfTab = iDataCur;
9751197755
sqlite3ExprCachePush(pParse);
9751297756
sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
9751397757
SQLITE_JUMPIFNULL);
9751497758
}else{
9751597759
*piPartIdxLabel = 0;
@@ -97517,13 +97761,18 @@
9751797761
}
9751897762
nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
9751997763
regBase = sqlite3GetTempRange(pParse, nCol);
9752097764
if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
9752197765
for(j=0; j<nCol; j++){
97522
- if( pPrior && pPrior->aiColumn[j]==pIdx->aiColumn[j] ) continue;
97523
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
97524
- regBase+j);
97766
+ if( pPrior
97767
+ && pPrior->aiColumn[j]==pIdx->aiColumn[j]
97768
+ && pPrior->aiColumn[j]>=(-1)
97769
+ ){
97770
+ /* This column was already computed by the previous index */
97771
+ continue;
97772
+ }
97773
+ sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
9752597774
/* If the column affinity is REAL but the number is an integer, then it
9752697775
** might be stored in the table as an integer (using a compact
9752797776
** representation) then converted to REAL by an OP_RealAffinity opcode.
9752897777
** But we are getting ready to store this value back into an index, where
9752997778
** it should be converted by to INTEGER again. So omit the OP_RealAffinity
@@ -99288,19 +99537,19 @@
9928899537
FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
9928999538
FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
9929099539
VFUNCTION(random, 0, 0, 0, randomFunc ),
9929199540
VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
9929299541
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
99293
- FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
99294
- FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
99542
+ DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
99543
+ DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
9929599544
FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
9929699545
#if SQLITE_USER_AUTHENTICATION
9929799546
FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
9929899547
#endif
9929999548
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
99300
- FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
99301
- FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
99549
+ DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
99550
+ DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
9930299551
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
9930399552
FUNCTION(quote, 1, 0, 0, quoteFunc ),
9930499553
VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
9930599554
VFUNCTION(changes, 0, 0, 0, changes ),
9930699555
VFUNCTION(total_changes, 0, 0, 0, total_changes ),
@@ -99308,12 +99557,12 @@
9930899557
FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
9930999558
#ifdef SQLITE_SOUNDEX
9931099559
FUNCTION(soundex, 1, 0, 0, soundexFunc ),
9931199560
#endif
9931299561
#ifndef SQLITE_OMIT_LOAD_EXTENSION
99313
- FUNCTION(load_extension, 1, 0, 0, loadExt ),
99314
- FUNCTION(load_extension, 2, 0, 0, loadExt ),
99562
+ VFUNCTION(load_extension, 1, 0, 0, loadExt ),
99563
+ VFUNCTION(load_extension, 2, 0, 0, loadExt ),
9931599564
#endif
9931699565
AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
9931799566
AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
9931899567
AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
9931999568
AGGREGATE2(count, 0, 0, 0, countStep, countFinalize,
@@ -99724,11 +99973,11 @@
9972499973
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
9972599974
}
9972699975
9972799976
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
9972899977
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
99729
- sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
99978
+ sqlite3VdbeGoto(v, iOk);
9973099979
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
9973199980
sqlite3VdbeJumpHere(v, iMustBeInt);
9973299981
sqlite3ReleaseTempReg(pParse, regTemp);
9973399982
}else{
9973499983
int nCol = pFKey->nCol;
@@ -99762,15 +100011,15 @@
99762100011
iParent = regData;
99763100012
}
99764100013
sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
99765100014
sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
99766100015
}
99767
- sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
100016
+ sqlite3VdbeGoto(v, iOk);
99768100017
}
99769100018
99770100019
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
99771
- sqlite3IndexAffinityStr(v,pIdx), nCol);
100020
+ sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
99772100021
sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
99773100022
99774100023
sqlite3ReleaseTempReg(pParse, regRec);
99775100024
sqlite3ReleaseTempRange(pParse, regTemp, nCol);
99776100025
}
@@ -100823,11 +101072,11 @@
100823101072
**
100824101073
** Memory for the buffer containing the column index affinity string
100825101074
** is managed along with the rest of the Index structure. It will be
100826101075
** released when sqlite3DeleteIndex() is called.
100827101076
*/
100828
-SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
101077
+SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
100829101078
if( !pIdx->zColAff ){
100830101079
/* The first time a column affinity string for a particular index is
100831101080
** required, it is allocated and populated here. It is then stored as
100832101081
** a member of the Index structure for subsequent use.
100833101082
**
@@ -100835,19 +101084,29 @@
100835101084
** sqliteDeleteIndex() when the Index structure itself is cleaned
100836101085
** up.
100837101086
*/
100838101087
int n;
100839101088
Table *pTab = pIdx->pTable;
100840
- sqlite3 *db = sqlite3VdbeDb(v);
100841101089
pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
100842101090
if( !pIdx->zColAff ){
100843101091
db->mallocFailed = 1;
100844101092
return 0;
100845101093
}
100846101094
for(n=0; n<pIdx->nColumn; n++){
100847101095
i16 x = pIdx->aiColumn[n];
100848
- pIdx->zColAff[n] = x<0 ? SQLITE_AFF_INTEGER : pTab->aCol[x].affinity;
101096
+ if( x>=0 ){
101097
+ pIdx->zColAff[n] = pTab->aCol[x].affinity;
101098
+ }else if( x==(-1) ){
101099
+ pIdx->zColAff[n] = SQLITE_AFF_INTEGER;
101100
+ }else{
101101
+ char aff;
101102
+ assert( x==(-2) );
101103
+ assert( pIdx->aColExpr!=0 );
101104
+ aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
101105
+ if( aff==0 ) aff = SQLITE_AFF_BLOB;
101106
+ pIdx->zColAff[n] = aff;
101107
+ }
100849101108
}
100850101109
pIdx->zColAff[n] = 0;
100851101110
}
100852101111
100853101112
return pIdx->zColAff;
@@ -101014,18 +101273,18 @@
101014101273
memId = p->regCtr;
101015101274
assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
101016101275
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
101017101276
sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
101018101277
addr = sqlite3VdbeCurrentAddr(v);
101019
- sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
101278
+ sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
101020101279
sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
101021101280
sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
101022101281
sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
101023101282
sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
101024101283
sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
101025101284
sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
101026
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
101285
+ sqlite3VdbeGoto(v, addr+9);
101027101286
sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
101028101287
sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
101029101288
sqlite3VdbeAddOp0(v, OP_Close);
101030101289
}
101031101290
}
@@ -101445,11 +101704,11 @@
101445101704
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
101446101705
addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
101447101706
sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
101448101707
sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
101449101708
sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
101450
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
101709
+ sqlite3VdbeGoto(v, addrL);
101451101710
sqlite3VdbeJumpHere(v, addrL);
101452101711
sqlite3ReleaseTempReg(pParse, regRec);
101453101712
sqlite3ReleaseTempReg(pParse, regTempRowid);
101454101713
}
101455101714
}else{
@@ -101459,15 +101718,17 @@
101459101718
NameContext sNC;
101460101719
memset(&sNC, 0, sizeof(sNC));
101461101720
sNC.pParse = pParse;
101462101721
srcTab = -1;
101463101722
assert( useTempTable==0 );
101464
- nColumn = pList ? pList->nExpr : 0;
101465
- for(i=0; i<nColumn; i++){
101466
- if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
101723
+ if( pList ){
101724
+ nColumn = pList->nExpr;
101725
+ if( sqlite3ResolveExprListNames(&sNC, pList) ){
101467101726
goto insert_cleanup;
101468101727
}
101728
+ }else{
101729
+ nColumn = 0;
101469101730
}
101470101731
}
101471101732
101472101733
/* If there is no IDLIST term but the table has an integer primary
101473101734
** key, the set the ipkColumn variable to the integer primary key
@@ -101744,11 +102005,11 @@
101744102005
if( useTempTable ){
101745102006
sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
101746102007
sqlite3VdbeJumpHere(v, addrInsTop);
101747102008
sqlite3VdbeAddOp1(v, OP_Close, srcTab);
101748102009
}else if( pSelect ){
101749
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
102010
+ sqlite3VdbeGoto(v, addrCont);
101750102011
sqlite3VdbeJumpHere(v, addrInsTop);
101751102012
}
101752102013
101753102014
if( !IsVirtual(pTab) && !isView ){
101754102015
/* Close all tables opened */
@@ -101991,11 +102252,11 @@
101991102252
onError = overrideError!=OE_Default ? overrideError : OE_Abort;
101992102253
for(i=0; i<pCheck->nExpr; i++){
101993102254
int allOk = sqlite3VdbeMakeLabel(v);
101994102255
sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
101995102256
if( onError==OE_Ignore ){
101996
- sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
102257
+ sqlite3VdbeGoto(v, ignoreDest);
101997102258
}else{
101998102259
char *zName = pCheck->a[i].zName;
101999102260
if( zName==0 ) zName = pTab->zName;
102000102261
if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
102001102262
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
@@ -102099,11 +102360,11 @@
102099102360
seenReplace = 1;
102100102361
break;
102101102362
}
102102102363
case OE_Ignore: {
102103102364
/*assert( seenReplace==0 );*/
102104
- sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
102365
+ sqlite3VdbeGoto(v, ignoreDest);
102105102366
break;
102106102367
}
102107102368
}
102108102369
sqlite3VdbeResolveLabel(v, addrRowidOk);
102109102370
if( ipkTop ){
@@ -102147,19 +102408,26 @@
102147102408
*/
102148102409
regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
102149102410
for(i=0; i<pIdx->nColumn; i++){
102150102411
int iField = pIdx->aiColumn[i];
102151102412
int x;
102152
- if( iField<0 || iField==pTab->iPKey ){
102153
- if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
102154
- x = regNewData;
102155
- regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
102413
+ if( iField==(-2) ){
102414
+ pParse->ckBase = regNewData+1;
102415
+ sqlite3ExprCode(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
102416
+ pParse->ckBase = 0;
102417
+ VdbeComment((v, "%s column %d", pIdx->zName, i));
102156102418
}else{
102157
- x = iField + regNewData + 1;
102419
+ if( iField==(-1) || iField==pTab->iPKey ){
102420
+ if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
102421
+ x = regNewData;
102422
+ regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
102423
+ }else{
102424
+ x = iField + regNewData + 1;
102425
+ }
102426
+ sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
102427
+ VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
102158102428
}
102159
- sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
102160
- VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
102161102429
}
102162102430
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
102163102431
VdbeComment((v, "for %s", pIdx->zName));
102164102432
sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
102165102433
@@ -102252,11 +102520,11 @@
102252102520
case OE_Fail: {
102253102521
sqlite3UniqueConstraint(pParse, onError, pIdx);
102254102522
break;
102255102523
}
102256102524
case OE_Ignore: {
102257
- sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
102525
+ sqlite3VdbeGoto(v, ignoreDest);
102258102526
break;
102259102527
}
102260102528
default: {
102261102529
Trigger *pTrigger = 0;
102262102530
assert( onError==OE_Replace );
@@ -102273,11 +102541,11 @@
102273102541
sqlite3VdbeResolveLabel(v, addrUniqueOk);
102274102542
sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
102275102543
if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
102276102544
}
102277102545
if( ipkTop ){
102278
- sqlite3VdbeAddOp2(v, OP_Goto, 0, ipkTop+1);
102546
+ sqlite3VdbeGoto(v, ipkTop+1);
102279102547
sqlite3VdbeJumpHere(v, ipkBottom);
102280102548
}
102281102549
102282102550
*pbMayReplace = seenReplace;
102283102551
VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
@@ -102475,10 +102743,17 @@
102475102743
return 0; /* Different conflict resolution strategies */
102476102744
}
102477102745
for(i=0; i<pSrc->nKeyCol; i++){
102478102746
if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
102479102747
return 0; /* Different columns indexed */
102748
+ }
102749
+ if( pSrc->aiColumn[i]==(-2) ){
102750
+ assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
102751
+ if( sqlite3ExprCompare(pSrc->aColExpr->a[i].pExpr,
102752
+ pDest->aColExpr->a[i].pExpr, -1)!=0 ){
102753
+ return 0; /* Different expressions in the index */
102754
+ }
102480102755
}
102481102756
if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
102482102757
return 0; /* Different sort orders */
102483102758
}
102484102759
if( !xferCompatibleCollation(pSrc->azColl[i],pDest->azColl[i]) ){
@@ -102719,11 +102994,11 @@
102719102994
** is unable to test uniqueness.)
102720102995
**
102721102996
** (3) onError is something other than OE_Abort and OE_Rollback.
102722102997
*/
102723102998
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
102724
- emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
102999
+ emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
102725103000
sqlite3VdbeJumpHere(v, addr1);
102726103001
}
102727103002
if( HasRowid(pSrc) ){
102728103003
sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
102729103004
emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
@@ -103256,10 +103531,13 @@
103256103531
/* Version 3.8.11 and later */
103257103532
sqlite3_value *(*value_dup)(const sqlite3_value*);
103258103533
void (*value_free)(sqlite3_value*);
103259103534
int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
103260103535
int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
103536
+ /* Version 3.8.12 and later */
103537
+ unsigned int (*value_subtype)(sqlite3_value*);
103538
+ void (*result_subtype)(sqlite3_context*,unsigned int);
103261103539
};
103262103540
103263103541
/*
103264103542
** The following macros redefine the API routines so that they are
103265103543
** redirected through the global sqlite3_api structure.
@@ -103269,11 +103547,11 @@
103269103547
** it can get access to the sqlite3_api_routines structure
103270103548
** definition. But the main library does not want to redefine
103271103549
** the API. So the redefinition macros are only valid if the
103272103550
** SQLITE_CORE macros is undefined.
103273103551
*/
103274
-#ifndef SQLITE_CORE
103552
+#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
103275103553
#define sqlite3_aggregate_context sqlite3_api->aggregate_context
103276103554
#ifndef SQLITE_OMIT_DEPRECATED
103277103555
#define sqlite3_aggregate_count sqlite3_api->aggregate_count
103278103556
#endif
103279103557
#define sqlite3_bind_blob sqlite3_api->bind_blob
@@ -103396,10 +103674,11 @@
103396103674
#define sqlite3_value_text16 sqlite3_api->value_text16
103397103675
#define sqlite3_value_text16be sqlite3_api->value_text16be
103398103676
#define sqlite3_value_text16le sqlite3_api->value_text16le
103399103677
#define sqlite3_value_type sqlite3_api->value_type
103400103678
#define sqlite3_vmprintf sqlite3_api->vmprintf
103679
+#define sqlite3_vsnprintf sqlite3_api->vsnprintf
103401103680
#define sqlite3_overload_function sqlite3_api->overload_function
103402103681
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
103403103682
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
103404103683
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
103405103684
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
@@ -103491,13 +103770,16 @@
103491103770
/* Version 3.8.11 and later */
103492103771
#define sqlite3_value_dup sqlite3_api->value_dup
103493103772
#define sqlite3_value_free sqlite3_api->value_free
103494103773
#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
103495103774
#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
103496
-#endif /* SQLITE_CORE */
103775
+/* Version 3.8.12 and later */
103776
+#define sqlite3_value_subtype sqlite3_api->value_subtype
103777
+#define sqlite3_result_subtype sqlite3_api->result_subtype
103778
+#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
103497103779
103498
-#ifndef SQLITE_CORE
103780
+#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
103499103781
/* This case when the file really is being compiled as a loadable
103500103782
** extension */
103501103783
# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
103502103784
# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
103503103785
# define SQLITE_EXTENSION_INIT3 \
@@ -103902,11 +104184,14 @@
103902104184
sqlite3_strglob,
103903104185
/* Version 3.8.11 and later */
103904104186
(sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
103905104187
sqlite3_value_free,
103906104188
sqlite3_result_zeroblob64,
103907
- sqlite3_bind_zeroblob64
104189
+ sqlite3_bind_zeroblob64,
104190
+ /* Version 3.8.12 and later */
104191
+ sqlite3_value_subtype,
104192
+ sqlite3_result_subtype
103908104193
};
103909104194
103910104195
/*
103911104196
** Attempt to load an SQLite extension library contained in the file
103912104197
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -104898,25 +105183,51 @@
104898105183
}
104899105184
db->temp_store = (u8)ts;
104900105185
return SQLITE_OK;
104901105186
}
104902105187
#endif /* SQLITE_PAGER_PRAGMAS */
105188
+
105189
+/*
105190
+** Set the names of the first N columns to the values in azCol[]
105191
+*/
105192
+static void setAllColumnNames(
105193
+ Vdbe *v, /* The query under construction */
105194
+ int N, /* Number of columns */
105195
+ const char **azCol /* Names of columns */
105196
+){
105197
+ int i;
105198
+ sqlite3VdbeSetNumCols(v, N);
105199
+ for(i=0; i<N; i++){
105200
+ sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC);
105201
+ }
105202
+}
105203
+static void setOneColumnName(Vdbe *v, const char *z){
105204
+ setAllColumnNames(v, 1, &z);
105205
+}
104903105206
104904105207
/*
104905105208
** Generate code to return a single integer value.
104906105209
*/
104907
-static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
104908
- Vdbe *v = sqlite3GetVdbe(pParse);
104909
- int nMem = ++pParse->nMem;
104910
- i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
104911
- if( pI64 ){
104912
- memcpy(pI64, &value, sizeof(value));
104913
- }
104914
- sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
104915
- sqlite3VdbeSetNumCols(v, 1);
104916
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
104917
- sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
105210
+static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){
105211
+ sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
105212
+ setOneColumnName(v, zLabel);
105213
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105214
+}
105215
+
105216
+/*
105217
+** Generate code to return a single text value.
105218
+*/
105219
+static void returnSingleText(
105220
+ Vdbe *v, /* Prepared statement under construction */
105221
+ const char *zLabel, /* Name of the result column */
105222
+ const char *zValue /* Value to be returned */
105223
+){
105224
+ if( zValue ){
105225
+ sqlite3VdbeLoadString(v, 1, (const char*)zValue);
105226
+ setOneColumnName(v, zLabel);
105227
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105228
+ }
104918105229
}
104919105230
104920105231
104921105232
/*
104922105233
** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -105076,18 +105387,12 @@
105076105387
aFcntl[2] = zRight;
105077105388
aFcntl[3] = 0;
105078105389
db->busyHandler.nBusy = 0;
105079105390
rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
105080105391
if( rc==SQLITE_OK ){
105081
- if( aFcntl[0] ){
105082
- int nMem = ++pParse->nMem;
105083
- sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
105084
- sqlite3VdbeSetNumCols(v, 1);
105085
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
105086
- sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
105087
- sqlite3_free(aFcntl[0]);
105088
- }
105392
+ returnSingleText(v, "result", aFcntl[0]);
105393
+ sqlite3_free(aFcntl[0]);
105089105394
goto pragma_out;
105090105395
}
105091105396
if( rc!=SQLITE_NOTFOUND ){
105092105397
if( aFcntl[0] ){
105093105398
sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
@@ -105153,12 +105458,11 @@
105153105458
{ OP_ResultRow, 1, 1, 0},
105154105459
};
105155105460
int addr;
105156105461
sqlite3VdbeUsesBtree(v, iDb);
105157105462
if( !zRight ){
105158
- sqlite3VdbeSetNumCols(v, 1);
105159
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
105463
+ setOneColumnName(v, "cache_size");
105160105464
pParse->nMem += 2;
105161105465
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
105162105466
sqlite3VdbeChangeP1(v, addr, iDb);
105163105467
sqlite3VdbeChangeP1(v, addr+1, iDb);
105164105468
sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
@@ -105188,11 +105492,11 @@
105188105492
case PragTyp_PAGE_SIZE: {
105189105493
Btree *pBt = pDb->pBt;
105190105494
assert( pBt!=0 );
105191105495
if( !zRight ){
105192105496
int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
105193
- returnSingleInt(pParse, "page_size", size);
105497
+ returnSingleInt(v, "page_size", size);
105194105498
}else{
105195105499
/* Malloc may fail when setting the page-size, as there is an internal
105196105500
** buffer that the pager module resizes using sqlite3_realloc().
105197105501
*/
105198105502
db->nextPagesize = sqlite3Atoi(zRight);
@@ -105223,11 +105527,11 @@
105223105527
for(ii=0; ii<db->nDb; ii++){
105224105528
sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
105225105529
}
105226105530
}
105227105531
b = sqlite3BtreeSecureDelete(pBt, b);
105228
- returnSingleInt(pParse, "secure_delete", b);
105532
+ returnSingleInt(v, "secure_delete", b);
105229105533
break;
105230105534
}
105231105535
105232105536
/*
105233105537
** PRAGMA [database.]max_page_count
@@ -105302,14 +105606,11 @@
105302105606
assert( eMode==PAGER_LOCKINGMODE_NORMAL
105303105607
|| eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
105304105608
if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
105305105609
zRet = "exclusive";
105306105610
}
105307
- sqlite3VdbeSetNumCols(v, 1);
105308
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
105309
- sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
105310
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105611
+ returnSingleText(v, "locking_mode", zRet);
105311105612
break;
105312105613
}
105313105614
105314105615
/*
105315105616
** PRAGMA [database.]journal_mode
@@ -105318,13 +105619,11 @@
105318105619
*/
105319105620
case PragTyp_JOURNAL_MODE: {
105320105621
int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
105321105622
int ii; /* Loop counter */
105322105623
105323
- sqlite3VdbeSetNumCols(v, 1);
105324
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
105325
-
105624
+ setOneColumnName(v, "journal_mode");
105326105625
if( zRight==0 ){
105327105626
/* If there is no "=MODE" part of the pragma, do a query for the
105328105627
** current mode */
105329105628
eMode = PAGER_JOURNALMODE_QUERY;
105330105629
}else{
@@ -105366,11 +105665,11 @@
105366105665
if( zRight ){
105367105666
sqlite3DecOrHexToI64(zRight, &iLimit);
105368105667
if( iLimit<-1 ) iLimit = -1;
105369105668
}
105370105669
iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
105371
- returnSingleInt(pParse, "journal_size_limit", iLimit);
105670
+ returnSingleInt(v, "journal_size_limit", iLimit);
105372105671
break;
105373105672
}
105374105673
105375105674
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105376105675
@@ -105384,11 +105683,11 @@
105384105683
#ifndef SQLITE_OMIT_AUTOVACUUM
105385105684
case PragTyp_AUTO_VACUUM: {
105386105685
Btree *pBt = pDb->pBt;
105387105686
assert( pBt!=0 );
105388105687
if( !zRight ){
105389
- returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
105688
+ returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
105390105689
}else{
105391105690
int eAuto = getAutoVacuum(zRight);
105392105691
assert( eAuto>=0 && eAuto<=2 );
105393105692
db->nextAutovac = (u8)eAuto;
105394105693
/* Call SetAutoVacuum() to set initialize the internal auto and
@@ -105462,11 +105761,11 @@
105462105761
*/
105463105762
case PragTyp_CACHE_SIZE: {
105464105763
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
105465105764
if( !zRight ){
105466105765
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105467
- returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
105766
+ returnSingleInt(v, "cache_size", pDb->pSchema->cache_size);
105468105767
}else{
105469105768
int size = sqlite3Atoi(zRight);
105470105769
pDb->pSchema->cache_size = size;
105471105770
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
105472105771
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
@@ -105508,11 +105807,11 @@
105508105807
#else
105509105808
sz = 0;
105510105809
rc = SQLITE_OK;
105511105810
#endif
105512105811
if( rc==SQLITE_OK ){
105513
- returnSingleInt(pParse, "mmap_size", sz);
105812
+ returnSingleInt(v, "mmap_size", sz);
105514105813
}else if( rc!=SQLITE_NOTFOUND ){
105515105814
pParse->nErr++;
105516105815
pParse->rc = rc;
105517105816
}
105518105817
break;
@@ -105529,11 +105828,11 @@
105529105828
** Note that it is possible for the library compile-time options to
105530105829
** override this setting
105531105830
*/
105532105831
case PragTyp_TEMP_STORE: {
105533105832
if( !zRight ){
105534
- returnSingleInt(pParse, "temp_store", db->temp_store);
105833
+ returnSingleInt(v, "temp_store", db->temp_store);
105535105834
}else{
105536105835
changeTempStorage(pParse, zRight);
105537105836
}
105538105837
break;
105539105838
}
@@ -105548,17 +105847,11 @@
105548105847
** If temporary directory is changed, then invalidateTempStorage.
105549105848
**
105550105849
*/
105551105850
case PragTyp_TEMP_STORE_DIRECTORY: {
105552105851
if( !zRight ){
105553
- if( sqlite3_temp_directory ){
105554
- sqlite3VdbeSetNumCols(v, 1);
105555
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
105556
- "temp_store_directory", SQLITE_STATIC);
105557
- sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
105558
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105559
- }
105852
+ returnSingleText(v, "temp_store_directory", sqlite3_temp_directory);
105560105853
}else{
105561105854
#ifndef SQLITE_OMIT_WSD
105562105855
if( zRight[0] ){
105563105856
int res;
105564105857
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -105598,17 +105891,11 @@
105598105891
** by this setting, regardless of its value.
105599105892
**
105600105893
*/
105601105894
case PragTyp_DATA_STORE_DIRECTORY: {
105602105895
if( !zRight ){
105603
- if( sqlite3_data_directory ){
105604
- sqlite3VdbeSetNumCols(v, 1);
105605
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
105606
- "data_store_directory", SQLITE_STATIC);
105607
- sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0);
105608
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105609
- }
105896
+ returnSingleText(v, "data_store_directory", sqlite3_data_directory);
105610105897
}else{
105611105898
#ifndef SQLITE_OMIT_WSD
105612105899
if( zRight[0] ){
105613105900
int res;
105614105901
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -105643,18 +105930,11 @@
105643105930
Pager *pPager = sqlite3BtreePager(pDb->pBt);
105644105931
char *proxy_file_path = NULL;
105645105932
sqlite3_file *pFile = sqlite3PagerFile(pPager);
105646105933
sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
105647105934
&proxy_file_path);
105648
-
105649
- if( proxy_file_path ){
105650
- sqlite3VdbeSetNumCols(v, 1);
105651
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
105652
- "lock_proxy_file", SQLITE_STATIC);
105653
- sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
105654
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105655
- }
105935
+ returnSingleText(v, "lock_proxy_file", proxy_file_path);
105656105936
}else{
105657105937
Pager *pPager = sqlite3BtreePager(pDb->pBt);
105658105938
sqlite3_file *pFile = sqlite3PagerFile(pPager);
105659105939
int res;
105660105940
if( zRight[0] ){
@@ -105682,11 +105962,11 @@
105682105962
** default value will be restored the next time the database is
105683105963
** opened.
105684105964
*/
105685105965
case PragTyp_SYNCHRONOUS: {
105686105966
if( !zRight ){
105687
- returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
105967
+ returnSingleInt(v, "synchronous", pDb->safety_level-1);
105688105968
}else{
105689105969
if( !db->autoCommit ){
105690105970
sqlite3ErrorMsg(pParse,
105691105971
"Safety level may not be changed inside a transaction");
105692105972
}else{
@@ -105701,11 +105981,11 @@
105701105981
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105702105982
105703105983
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
105704105984
case PragTyp_FLAG: {
105705105985
if( zRight==0 ){
105706
- returnSingleInt(pParse, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
105986
+ returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
105707105987
}else{
105708105988
int mask = pPragma->iArg; /* Mask of bits to set or clear. */
105709105989
if( db->autoCommit==0 ){
105710105990
/* Foreign key support may not be enabled or disabled while not
105711105991
** in auto-commit mode. */
@@ -105751,79 +106031,67 @@
105751106031
*/
105752106032
case PragTyp_TABLE_INFO: if( zRight ){
105753106033
Table *pTab;
105754106034
pTab = sqlite3FindTable(db, zRight, zDb);
105755106035
if( pTab ){
106036
+ static const char *azCol[] = {
106037
+ "cid", "name", "type", "notnull", "dflt_value", "pk"
106038
+ };
105756106039
int i, k;
105757106040
int nHidden = 0;
105758106041
Column *pCol;
105759106042
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
105760
- sqlite3VdbeSetNumCols(v, 6);
105761106043
pParse->nMem = 6;
105762106044
sqlite3CodeVerifySchema(pParse, iDb);
105763
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
105764
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105765
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
105766
- sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
105767
- sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
105768
- sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
106045
+ setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
105769106046
sqlite3ViewGetColumnNames(pParse, pTab);
105770106047
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
105771106048
if( IsHiddenColumn(pCol) ){
105772106049
nHidden++;
105773106050
continue;
105774106051
}
105775
- sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
105776
- sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
105777
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
105778
- pCol->zType ? pCol->zType : "", 0);
105779
- sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
105780
- if( pCol->zDflt ){
105781
- sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
105782
- }else{
105783
- sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
105784
- }
105785106052
if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
105786106053
k = 0;
105787106054
}else if( pPk==0 ){
105788106055
k = 1;
105789106056
}else{
105790106057
for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
105791106058
}
105792
- sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
106059
+ sqlite3VdbeMultiLoad(v, 1, "issisi",
106060
+ i-nHidden,
106061
+ pCol->zName,
106062
+ pCol->zType ? pCol->zType : "",
106063
+ pCol->notNull ? 1 : 0,
106064
+ pCol->zDflt,
106065
+ k);
105793106066
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
105794106067
}
105795106068
}
105796106069
}
105797106070
break;
105798106071
105799106072
case PragTyp_STATS: {
106073
+ static const char *azCol[] = { "table", "index", "width", "height" };
105800106074
Index *pIdx;
105801106075
HashElem *i;
105802106076
v = sqlite3GetVdbe(pParse);
105803
- sqlite3VdbeSetNumCols(v, 4);
105804106077
pParse->nMem = 4;
105805106078
sqlite3CodeVerifySchema(pParse, iDb);
105806
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
105807
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC);
105808
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC);
105809
- sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC);
106079
+ setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
105810106080
for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
105811106081
Table *pTab = sqliteHashData(i);
105812
- sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0);
105813
- sqlite3VdbeAddOp2(v, OP_Null, 0, 2);
105814
- sqlite3VdbeAddOp2(v, OP_Integer,
105815
- (int)sqlite3LogEstToInt(pTab->szTabRow), 3);
105816
- sqlite3VdbeAddOp2(v, OP_Integer,
105817
- (int)sqlite3LogEstToInt(pTab->nRowLogEst), 4);
106082
+ sqlite3VdbeMultiLoad(v, 1, "ssii",
106083
+ pTab->zName,
106084
+ 0,
106085
+ (int)sqlite3LogEstToInt(pTab->szTabRow),
106086
+ (int)sqlite3LogEstToInt(pTab->nRowLogEst));
105818106087
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
105819106088
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
105820
- sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
105821
- sqlite3VdbeAddOp2(v, OP_Integer,
105822
- (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3);
105823
- sqlite3VdbeAddOp2(v, OP_Integer,
105824
- (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]), 4);
106089
+ sqlite3VdbeMultiLoad(v, 2, "sii",
106090
+ pIdx->zName,
106091
+ (int)sqlite3LogEstToInt(pIdx->szIdxRow),
106092
+ (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]));
105825106093
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
105826106094
}
105827106095
}
105828106096
}
105829106097
break;
@@ -105831,10 +106099,13 @@
105831106099
case PragTyp_INDEX_INFO: if( zRight ){
105832106100
Index *pIdx;
105833106101
Table *pTab;
105834106102
pIdx = sqlite3FindIndex(db, zRight, zDb);
105835106103
if( pIdx ){
106104
+ static const char *azCol[] = {
106105
+ "seqno", "cid", "name", "desc", "coll", "key"
106106
+ };
105836106107
int i;
105837106108
int mx;
105838106109
if( pPragma->iArg ){
105839106110
/* PRAGMA index_xinfo (newer version with more rows and columns) */
105840106111
mx = pIdx->nColumn;
@@ -105843,33 +106114,22 @@
105843106114
/* PRAGMA index_info (legacy version) */
105844106115
mx = pIdx->nKeyCol;
105845106116
pParse->nMem = 3;
105846106117
}
105847106118
pTab = pIdx->pTable;
105848
- sqlite3VdbeSetNumCols(v, pParse->nMem);
105849106119
sqlite3CodeVerifySchema(pParse, iDb);
105850
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
105851
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
105852
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
105853
- if( pPragma->iArg ){
105854
- sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
105855
- sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
105856
- sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
105857
- }
106120
+ assert( pParse->nMem<=ArraySize(azCol) );
106121
+ setAllColumnNames(v, pParse->nMem, azCol);
105858106122
for(i=0; i<mx; i++){
105859106123
i16 cnum = pIdx->aiColumn[i];
105860
- sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105861
- sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
105862
- if( cnum<0 ){
105863
- sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
105864
- }else{
105865
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
105866
- }
106124
+ sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
106125
+ cnum<0 ? 0 : pTab->aCol[cnum].zName);
105867106126
if( pPragma->iArg ){
105868
- sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
105869
- sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
105870
- sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
106127
+ sqlite3VdbeMultiLoad(v, 4, "isi",
106128
+ pIdx->aSortOrder[i],
106129
+ pIdx->azColl[i],
106130
+ i<pIdx->nKeyCol);
105871106131
}
105872106132
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
105873106133
}
105874106134
}
105875106135
}
@@ -105879,62 +106139,57 @@
105879106139
Index *pIdx;
105880106140
Table *pTab;
105881106141
int i;
105882106142
pTab = sqlite3FindTable(db, zRight, zDb);
105883106143
if( pTab ){
106144
+ static const char *azCol[] = {
106145
+ "seq", "name", "unique", "origin", "partial"
106146
+ };
105884106147
v = sqlite3GetVdbe(pParse);
105885
- sqlite3VdbeSetNumCols(v, 5);
105886106148
pParse->nMem = 5;
105887106149
sqlite3CodeVerifySchema(pParse, iDb);
105888
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105889
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105890
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
105891
- sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "origin", SQLITE_STATIC);
105892
- sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "partial", SQLITE_STATIC);
106150
+ setAllColumnNames(v, 5, azCol); assert( 5==ArraySize(azCol) );
105893106151
for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
105894106152
const char *azOrigin[] = { "c", "u", "pk" };
105895
- sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105896
- sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
105897
- sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
105898
- sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, azOrigin[pIdx->idxType], 0);
105899
- sqlite3VdbeAddOp2(v, OP_Integer, pIdx->pPartIdxWhere!=0, 5);
106153
+ sqlite3VdbeMultiLoad(v, 1, "isisi",
106154
+ i,
106155
+ pIdx->zName,
106156
+ IsUniqueIndex(pIdx),
106157
+ azOrigin[pIdx->idxType],
106158
+ pIdx->pPartIdxWhere!=0);
105900106159
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
105901106160
}
105902106161
}
105903106162
}
105904106163
break;
105905106164
105906106165
case PragTyp_DATABASE_LIST: {
106166
+ static const char *azCol[] = { "seq", "name", "file" };
105907106167
int i;
105908
- sqlite3VdbeSetNumCols(v, 3);
105909106168
pParse->nMem = 3;
105910
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105911
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105912
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
106169
+ setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
105913106170
for(i=0; i<db->nDb; i++){
105914106171
if( db->aDb[i].pBt==0 ) continue;
105915106172
assert( db->aDb[i].zName!=0 );
105916
- sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105917
- sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
105918
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
105919
- sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
106173
+ sqlite3VdbeMultiLoad(v, 1, "iss",
106174
+ i,
106175
+ db->aDb[i].zName,
106176
+ sqlite3BtreeGetFilename(db->aDb[i].pBt));
105920106177
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
105921106178
}
105922106179
}
105923106180
break;
105924106181
105925106182
case PragTyp_COLLATION_LIST: {
106183
+ static const char *azCol[] = { "seq", "name" };
105926106184
int i = 0;
105927106185
HashElem *p;
105928
- sqlite3VdbeSetNumCols(v, 2);
105929106186
pParse->nMem = 2;
105930
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105931
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
106187
+ setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
105932106188
for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
105933106189
CollSeq *pColl = (CollSeq *)sqliteHashData(p);
105934
- sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
105935
- sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
106190
+ sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
105936106191
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
105937106192
}
105938106193
}
105939106194
break;
105940106195
#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
@@ -105946,37 +106201,30 @@
105946106201
pTab = sqlite3FindTable(db, zRight, zDb);
105947106202
if( pTab ){
105948106203
v = sqlite3GetVdbe(pParse);
105949106204
pFK = pTab->pFKey;
105950106205
if( pFK ){
106206
+ static const char *azCol[] = {
106207
+ "id", "seq", "table", "from", "to", "on_update", "on_delete",
106208
+ "match"
106209
+ };
105951106210
int i = 0;
105952
- sqlite3VdbeSetNumCols(v, 8);
105953106211
pParse->nMem = 8;
105954106212
sqlite3CodeVerifySchema(pParse, iDb);
105955
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
105956
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
105957
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
105958
- sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
105959
- sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
105960
- sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
105961
- sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
105962
- sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
106213
+ setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) );
105963106214
while(pFK){
105964106215
int j;
105965106216
for(j=0; j<pFK->nCol; j++){
105966
- char *zCol = pFK->aCol[j].zCol;
105967
- char *zOnDelete = (char *)actionName(pFK->aAction[0]);
105968
- char *zOnUpdate = (char *)actionName(pFK->aAction[1]);
105969
- sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105970
- sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
105971
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
105972
- sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
105973
- pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
105974
- sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
105975
- sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
105976
- sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
105977
- sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
106217
+ sqlite3VdbeMultiLoad(v, 1, "iissssss",
106218
+ i,
106219
+ j,
106220
+ pFK->zTo,
106221
+ pTab->aCol[pFK->aCol[j].iFrom].zName,
106222
+ pFK->aCol[j].zCol,
106223
+ actionName(pFK->aAction[1]), /* ON UPDATE */
106224
+ actionName(pFK->aAction[0]), /* ON DELETE */
106225
+ "NONE");
105978106226
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
105979106227
}
105980106228
++i;
105981106229
pFK = pFK->pNextFrom;
105982106230
}
@@ -106001,21 +106249,18 @@
106001106249
int regKey; /* Register to hold key for checking the FK */
106002106250
int regRow; /* Registers to hold a row from pTab */
106003106251
int addrTop; /* Top of a loop checking foreign keys */
106004106252
int addrOk; /* Jump here if the key is OK */
106005106253
int *aiCols; /* child to parent column mapping */
106254
+ static const char *azCol[] = { "table", "rowid", "parent", "fkid" };
106006106255
106007106256
regResult = pParse->nMem+1;
106008106257
pParse->nMem += 4;
106009106258
regKey = ++pParse->nMem;
106010106259
regRow = ++pParse->nMem;
106011106260
v = sqlite3GetVdbe(pParse);
106012
- sqlite3VdbeSetNumCols(v, 4);
106013
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
106014
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "rowid", SQLITE_STATIC);
106015
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "parent", SQLITE_STATIC);
106016
- sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "fkid", SQLITE_STATIC);
106261
+ setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
106017106262
sqlite3CodeVerifySchema(pParse, iDb);
106018106263
k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
106019106264
while( k ){
106020106265
if( zRight ){
106021106266
pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
@@ -106026,12 +106271,11 @@
106026106271
}
106027106272
if( pTab==0 || pTab->pFKey==0 ) continue;
106028106273
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
106029106274
if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
106030106275
sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
106031
- sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName,
106032
- P4_TRANSIENT);
106276
+ sqlite3VdbeLoadString(v, regResult, pTab->zName);
106033106277
for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
106034106278
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
106035106279
if( pParent==0 ) continue;
106036106280
pIdx = 0;
106037106281
sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -106072,29 +106316,27 @@
106072106316
sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
106073106317
}else{
106074106318
sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
106075106319
}
106076106320
sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
106077
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
106321
+ sqlite3VdbeGoto(v, addrOk);
106078106322
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
106079106323
}else{
106080106324
for(j=0; j<pFK->nCol; j++){
106081106325
sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
106082106326
aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
106083106327
sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
106084106328
}
106085106329
if( pParent ){
106086106330
sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
106087
- sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
106331
+ sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
106088106332
sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
106089106333
VdbeCoverage(v);
106090106334
}
106091106335
}
106092106336
sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
106093
- sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
106094
- pFK->zTo, P4_TRANSIENT);
106095
- sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
106337
+ sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
106096106338
sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
106097106339
sqlite3VdbeResolveLabel(v, addrOk);
106098106340
sqlite3DbFree(db, aiCols);
106099106341
}
106100106342
sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
@@ -106166,12 +106408,11 @@
106166106408
assert( iDb==0 || pId2->z );
106167106409
if( pId2->z==0 ) iDb = -1;
106168106410
106169106411
/* Initialize the VDBE program */
106170106412
pParse->nMem = 6;
106171
- sqlite3VdbeSetNumCols(v, 1);
106172
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
106413
+ setOneColumnName(v, "integrity_check");
106173106414
106174106415
/* Set the maximum error count */
106175106416
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
106176106417
if( zRight ){
106177106418
sqlite3GetInt32(zRight, &mxErr);
@@ -106289,17 +106530,15 @@
106289106530
sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
106290106531
/* Verify that an index entry exists for the current table row */
106291106532
jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
106292106533
pIdx->nColumn); VdbeCoverage(v);
106293106534
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106294
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
106535
+ sqlite3VdbeLoadString(v, 3, "row ");
106295106536
sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
106296
- sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
106297
- " missing from index ", P4_STATIC);
106537
+ sqlite3VdbeLoadString(v, 4, " missing from index ");
106298106538
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106299
- jmp5 = sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
106300
- pIdx->zName, P4_TRANSIENT);
106539
+ jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
106301106540
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106302106541
sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
106303106542
jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
106304106543
sqlite3VdbeAddOp0(v, OP_Halt);
106305106544
sqlite3VdbeJumpHere(v, jmp2);
@@ -106316,38 +106555,36 @@
106316106555
if( pTab->aCol[iCol].notNull ) continue;
106317106556
sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
106318106557
VdbeCoverage(v);
106319106558
}
106320106559
jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
106321
- sqlite3VdbeAddOp2(v, OP_Goto, 0, uniqOk);
106560
+ sqlite3VdbeGoto(v, uniqOk);
106322106561
sqlite3VdbeJumpHere(v, jmp6);
106323106562
sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
106324106563
pIdx->nKeyCol); VdbeCoverage(v);
106325106564
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106326
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
106327
- "non-unique entry in index ", P4_STATIC);
106328
- sqlite3VdbeAddOp2(v, OP_Goto, 0, jmp5);
106565
+ sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
106566
+ sqlite3VdbeGoto(v, jmp5);
106329106567
sqlite3VdbeResolveLabel(v, uniqOk);
106330106568
}
106331106569
sqlite3VdbeJumpHere(v, jmp4);
106332106570
sqlite3ResolvePartIdxLabel(pParse, jmp3);
106333106571
}
106334106572
sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
106335106573
sqlite3VdbeJumpHere(v, loopTop-1);
106336106574
#ifndef SQLITE_OMIT_BTREECOUNT
106337
- sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
106338
- "wrong # of entries in index ", P4_STATIC);
106575
+ sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
106339106576
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
106340106577
if( pPk==pIdx ) continue;
106341106578
addr = sqlite3VdbeCurrentAddr(v);
106342106579
sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
106343106580
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
106344106581
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
106345106582
sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
106346106583
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
106347106584
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
106348
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
106585
+ sqlite3VdbeLoadString(v, 3, pIdx->zName);
106349106586
sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
106350106587
sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
106351106588
}
106352106589
#endif /* SQLITE_OMIT_BTREECOUNT */
106353106590
}
@@ -106399,18 +106636,14 @@
106399106636
{ 0, 0 }
106400106637
};
106401106638
const struct EncName *pEnc;
106402106639
if( !zRight ){ /* "PRAGMA encoding" */
106403106640
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
106404
- sqlite3VdbeSetNumCols(v, 1);
106405
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
106406
- sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
106407106641
assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
106408106642
assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
106409106643
assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
106410
- sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
106411
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
106644
+ returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
106412106645
}else{ /* "PRAGMA encoding = XXX" */
106413106646
/* Only change the value of sqlite.enc if the database handle is not
106414106647
** initialized. If the main database exists, the new sqlite.enc value
106415106648
** will be overwritten when the schema is next loaded. If it does not
106416106649
** already exists, it will be created to use the new encoding value.
@@ -106507,15 +106740,14 @@
106507106740
** one option per row.
106508106741
*/
106509106742
case PragTyp_COMPILE_OPTIONS: {
106510106743
int i = 0;
106511106744
const char *zOpt;
106512
- sqlite3VdbeSetNumCols(v, 1);
106513106745
pParse->nMem = 1;
106514
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
106746
+ setOneColumnName(v, "compile_option");
106515106747
while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
106516
- sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
106748
+ sqlite3VdbeLoadString(v, 1, zOpt);
106517106749
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
106518106750
}
106519106751
}
106520106752
break;
106521106753
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
@@ -106525,10 +106757,11 @@
106525106757
** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
106526106758
**
106527106759
** Checkpoint the database.
106528106760
*/
106529106761
case PragTyp_WAL_CHECKPOINT: {
106762
+ static const char *azCol[] = { "busy", "log", "checkpointed" };
106530106763
int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
106531106764
int eMode = SQLITE_CHECKPOINT_PASSIVE;
106532106765
if( zRight ){
106533106766
if( sqlite3StrICmp(zRight, "full")==0 ){
106534106767
eMode = SQLITE_CHECKPOINT_FULL;
@@ -106536,16 +106769,12 @@
106536106769
eMode = SQLITE_CHECKPOINT_RESTART;
106537106770
}else if( sqlite3StrICmp(zRight, "truncate")==0 ){
106538106771
eMode = SQLITE_CHECKPOINT_TRUNCATE;
106539106772
}
106540106773
}
106541
- sqlite3VdbeSetNumCols(v, 3);
106774
+ setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
106542106775
pParse->nMem = 3;
106543
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
106544
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
106545
- sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
106546
-
106547106776
sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
106548106777
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
106549106778
}
106550106779
break;
106551106780
@@ -106559,11 +106788,11 @@
106559106788
*/
106560106789
case PragTyp_WAL_AUTOCHECKPOINT: {
106561106790
if( zRight ){
106562106791
sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
106563106792
}
106564
- returnSingleInt(pParse, "wal_autocheckpoint",
106793
+ returnSingleInt(v, "wal_autocheckpoint",
106565106794
db->xWalCallback==sqlite3WalDefaultHook ?
106566106795
SQLITE_PTR_TO_INT(db->pWalArg) : 0);
106567106796
}
106568106797
break;
106569106798
#endif
@@ -106592,11 +106821,11 @@
106592106821
/*case PragTyp_BUSY_TIMEOUT*/ default: {
106593106822
assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
106594106823
if( zRight ){
106595106824
sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
106596106825
}
106597
- returnSingleInt(pParse, "timeout", db->busyTimeout);
106826
+ returnSingleInt(v, "timeout", db->busyTimeout);
106598106827
break;
106599106828
}
106600106829
106601106830
/*
106602106831
** PRAGMA soft_heap_limit
@@ -106612,11 +106841,11 @@
106612106841
case PragTyp_SOFT_HEAP_LIMIT: {
106613106842
sqlite3_int64 N;
106614106843
if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
106615106844
sqlite3_soft_heap_limit64(N);
106616106845
}
106617
- returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
106846
+ returnSingleInt(v, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
106618106847
break;
106619106848
}
106620106849
106621106850
/*
106622106851
** PRAGMA threads
@@ -106631,11 +106860,11 @@
106631106860
&& sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
106632106861
&& N>=0
106633106862
){
106634106863
sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
106635106864
}
106636
- returnSingleInt(pParse, "threads",
106865
+ returnSingleInt(v, "threads",
106637106866
sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
106638106867
break;
106639106868
}
106640106869
106641106870
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
@@ -106644,29 +106873,27 @@
106644106873
*/
106645106874
case PragTyp_LOCK_STATUS: {
106646106875
static const char *const azLockName[] = {
106647106876
"unlocked", "shared", "reserved", "pending", "exclusive"
106648106877
};
106878
+ static const char *azCol[] = { "database", "status" };
106649106879
int i;
106650
- sqlite3VdbeSetNumCols(v, 2);
106880
+ setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
106651106881
pParse->nMem = 2;
106652
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
106653
- sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
106654106882
for(i=0; i<db->nDb; i++){
106655106883
Btree *pBt;
106656106884
const char *zState = "unknown";
106657106885
int j;
106658106886
if( db->aDb[i].zName==0 ) continue;
106659
- sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
106660106887
pBt = db->aDb[i].pBt;
106661106888
if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
106662106889
zState = "closed";
106663106890
}else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
106664106891
SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
106665106892
zState = azLockName[j];
106666106893
}
106667
- sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
106894
+ sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
106668106895
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
106669106896
}
106670106897
break;
106671106898
}
106672106899
#endif
@@ -108027,16 +108254,16 @@
108027108254
Table *pLeftTab = pLeft->pTab;
108028108255
Table *pRightTab = pRight->pTab;
108029108256
int isOuter;
108030108257
108031108258
if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
108032
- isOuter = (pRight->jointype & JT_OUTER)!=0;
108259
+ isOuter = (pRight->fg.jointype & JT_OUTER)!=0;
108033108260
108034108261
/* When the NATURAL keyword is present, add WHERE clause terms for
108035108262
** every column that the two tables have in common.
108036108263
*/
108037
- if( pRight->jointype & JT_NATURAL ){
108264
+ if( pRight->fg.jointype & JT_NATURAL ){
108038108265
if( pRight->pOn || pRight->pUsing ){
108039108266
sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
108040108267
"an ON or USING clause", 0);
108041108268
return 1;
108042108269
}
@@ -108117,10 +108344,11 @@
108117108344
static void pushOntoSorter(
108118108345
Parse *pParse, /* Parser context */
108119108346
SortCtx *pSort, /* Information about the ORDER BY clause */
108120108347
Select *pSelect, /* The whole SELECT statement */
108121108348
int regData, /* First register holding data to be sorted */
108349
+ int regOrigData, /* First register holding data before packing */
108122108350
int nData, /* Number of elements in the data array */
108123108351
int nPrefixReg /* No. of reg prior to regData available for use */
108124108352
){
108125108353
Vdbe *v = pParse->pVdbe; /* Stmt under construction */
108126108354
int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
@@ -108130,18 +108358,20 @@
108130108358
int regRecord = ++pParse->nMem; /* Assembled sorter record */
108131108359
int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */
108132108360
int op; /* Opcode to add sorter record to sorter */
108133108361
108134108362
assert( bSeq==0 || bSeq==1 );
108363
+ assert( nData==1 || regData==regOrigData );
108135108364
if( nPrefixReg ){
108136108365
assert( nPrefixReg==nExpr+bSeq );
108137108366
regBase = regData - nExpr - bSeq;
108138108367
}else{
108139108368
regBase = pParse->nMem + 1;
108140108369
pParse->nMem += nBase;
108141108370
}
108142
- sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
108371
+ sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
108372
+ SQLITE_ECEL_DUP|SQLITE_ECEL_REF);
108143108373
if( bSeq ){
108144108374
sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
108145108375
}
108146108376
if( nPrefixReg==0 ){
108147108377
sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
@@ -108215,11 +108445,11 @@
108215108445
int iContinue /* Jump here to skip the current record */
108216108446
){
108217108447
if( iOffset>0 ){
108218108448
int addr;
108219108449
addr = sqlite3VdbeAddOp3(v, OP_IfNeg, iOffset, 0, -1); VdbeCoverage(v);
108220
- sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
108450
+ sqlite3VdbeGoto(v, iContinue);
108221108451
VdbeComment((v, "skip OFFSET records"));
108222108452
sqlite3VdbeJumpHere(v, addr);
108223108453
}
108224108454
}
108225108455
@@ -108347,11 +108577,11 @@
108347108577
if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
108348108578
ecelFlags = SQLITE_ECEL_DUP;
108349108579
}else{
108350108580
ecelFlags = 0;
108351108581
}
108352
- sqlite3ExprCodeExprList(pParse, pEList, regResult, ecelFlags);
108582
+ sqlite3ExprCodeExprList(pParse, pEList, regResult, 0, ecelFlags);
108353108583
}
108354108584
108355108585
/* If the DISTINCT keyword was present on the SELECT statement
108356108586
** and this row has been seen before, then do not make this row
108357108587
** part of the result.
@@ -108463,11 +108693,11 @@
108463108693
sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
108464108694
assert( pSort==0 );
108465108695
}
108466108696
#endif
108467108697
if( pSort ){
108468
- pushOntoSorter(pParse, pSort, p, r1+nPrefixReg, 1, nPrefixReg);
108698
+ pushOntoSorter(pParse, pSort, p, r1+nPrefixReg,regResult,1,nPrefixReg);
108469108699
}else{
108470108700
int r2 = sqlite3GetTempReg(pParse);
108471108701
sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);
108472108702
sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);
108473108703
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -108489,11 +108719,11 @@
108489108719
if( pSort ){
108490108720
/* At first glance you would think we could optimize out the
108491108721
** ORDER BY in this case since the order of entries in the set
108492108722
** does not matter. But there might be a LIMIT clause, in which
108493108723
** case the order does matter */
108494
- pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
108724
+ pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
108495108725
}else{
108496108726
int r1 = sqlite3GetTempReg(pParse);
108497108727
sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult,1,r1, &pDest->affSdst, 1);
108498108728
sqlite3ExprCacheAffinityChange(pParse, regResult, 1);
108499108729
sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
@@ -108515,11 +108745,11 @@
108515108745
** of the scan loop.
108516108746
*/
108517108747
case SRT_Mem: {
108518108748
assert( nResultCol==1 );
108519108749
if( pSort ){
108520
- pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
108750
+ pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
108521108751
}else{
108522108752
assert( regResult==iParm );
108523108753
/* The LIMIT clause will jump out of the loop for us */
108524108754
}
108525108755
break;
@@ -108529,11 +108759,12 @@
108529108759
case SRT_Coroutine: /* Send data to a co-routine */
108530108760
case SRT_Output: { /* Return the results */
108531108761
testcase( eDest==SRT_Coroutine );
108532108762
testcase( eDest==SRT_Output );
108533108763
if( pSort ){
108534
- pushOntoSorter(pParse, pSort, p, regResult, nResultCol, nPrefixReg);
108764
+ pushOntoSorter(pParse, pSort, p, regResult, regResult, nResultCol,
108765
+ nPrefixReg);
108535108766
}else if( eDest==SRT_Coroutine ){
108536108767
sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108537108768
}else{
108538108769
sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
108539108770
sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
@@ -108823,11 +109054,11 @@
108823109054
struct ExprList_item *aOutEx = p->pEList->a;
108824109055
#endif
108825109056
108826109057
if( pSort->labelBkOut ){
108827109058
sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
108828
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBreak);
109059
+ sqlite3VdbeGoto(v, addrBreak);
108829109060
sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
108830109061
}
108831109062
iTab = pSort->iECursor;
108832109063
if( eDest==SRT_Output || eDest==SRT_Coroutine ){
108833109064
regRowid = 0;
@@ -109208,11 +109439,11 @@
109208109439
** and other fields of Column are zeroed.
109209109440
**
109210109441
** Return SQLITE_OK on success. If a memory allocation error occurs,
109211109442
** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
109212109443
*/
109213
-static int selectColumnsFromExprList(
109444
+SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
109214109445
Parse *pParse, /* Parsing context */
109215109446
ExprList *pEList, /* Expr list from which to derive column names */
109216109447
i16 *pnCol, /* Write the number of columns here */
109217109448
Column **paCol /* Write the new column list here */
109218109449
){
@@ -109375,11 +109606,11 @@
109375109606
** is disabled */
109376109607
assert( db->lookaside.bEnabled==0 );
109377109608
pTab->nRef = 1;
109378109609
pTab->zName = 0;
109379109610
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
109380
- selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
109611
+ sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
109381109612
selectAddColumnTypeAndCollation(pParse, pTab, pSelect);
109382109613
pTab->iPKey = -1;
109383109614
if( db->mallocFailed ){
109384109615
sqlite3DeleteTable(db, pTab);
109385109616
return 0;
@@ -109451,11 +109682,11 @@
109451109682
assert( v!=0 );
109452109683
if( sqlite3ExprIsInteger(p->pLimit, &n) ){
109453109684
sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
109454109685
VdbeComment((v, "LIMIT counter"));
109455109686
if( n==0 ){
109456
- sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
109687
+ sqlite3VdbeGoto(v, iBreak);
109457109688
}else if( n>=0 && p->nSelectRow>(u64)n ){
109458109689
p->nSelectRow = n;
109459109690
}
109460109691
}else{
109461109692
sqlite3ExprCode(pParse, p->pLimit, iLimit);
@@ -109554,11 +109785,11 @@
109554109785
** \___________/ \_______________/
109555109786
** p->pPrior p
109556109787
**
109557109788
**
109558109789
** There is exactly one reference to the recursive-table in the FROM clause
109559
-** of recursive-query, marked with the SrcList->a[].isRecursive flag.
109790
+** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
109560109791
**
109561109792
** The setup-query runs once to generate an initial set of rows that go
109562109793
** into a Queue table. Rows are extracted from the Queue table one by
109563109794
** one. Each row extracted from Queue is output to pDest. Then the single
109564109795
** extracted row (now in the iCurrent table) becomes the content of the
@@ -109619,11 +109850,11 @@
109619109850
p->iLimit = p->iOffset = 0;
109620109851
pOrderBy = p->pOrderBy;
109621109852
109622109853
/* Locate the cursor number of the Current table */
109623109854
for(i=0; ALWAYS(i<pSrc->nSrc); i++){
109624
- if( pSrc->a[i].isRecursive ){
109855
+ if( pSrc->a[i].fg.isRecursive ){
109625109856
iCurrent = pSrc->a[i].iCursor;
109626109857
break;
109627109858
}
109628109859
}
109629109860
@@ -109699,11 +109930,11 @@
109699109930
assert( p->pPrior==0 );
109700109931
p->pPrior = pSetup;
109701109932
}
109702109933
109703109934
/* Keep running the loop until the Queue is empty */
109704
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
109935
+ sqlite3VdbeGoto(v, addrTop);
109705109936
sqlite3VdbeResolveLabel(v, addrBreak);
109706109937
109707109938
end_of_recursive_query:
109708109939
sqlite3ExprListDelete(pParse->db, p->pOrderBy);
109709109940
p->pOrderBy = pOrderBy;
@@ -110608,11 +110839,11 @@
110608110839
}else{
110609110840
VdbeNoopComment((v, "eof-A subroutine"));
110610110841
addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110611110842
addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
110612110843
VdbeCoverage(v);
110613
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
110844
+ sqlite3VdbeGoto(v, addrEofA);
110614110845
p->nSelectRow += pPrior->nSelectRow;
110615110846
}
110616110847
110617110848
/* Generate a subroutine to run when the results from select B
110618110849
** are exhausted and only data in select A remains.
@@ -110622,19 +110853,19 @@
110622110853
if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
110623110854
}else{
110624110855
VdbeNoopComment((v, "eof-B subroutine"));
110625110856
addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110626110857
sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
110627
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
110858
+ sqlite3VdbeGoto(v, addrEofB);
110628110859
}
110629110860
110630110861
/* Generate code to handle the case of A<B
110631110862
*/
110632110863
VdbeNoopComment((v, "A-lt-B subroutine"));
110633110864
addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110634110865
sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110635
- sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
110866
+ sqlite3VdbeGoto(v, labelCmpr);
110636110867
110637110868
/* Generate code to handle the case of A==B
110638110869
*/
110639110870
if( op==TK_ALL ){
110640110871
addrAeqB = addrAltB;
@@ -110643,11 +110874,11 @@
110643110874
addrAltB++;
110644110875
}else{
110645110876
VdbeNoopComment((v, "A-eq-B subroutine"));
110646110877
addrAeqB =
110647110878
sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110648
- sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
110879
+ sqlite3VdbeGoto(v, labelCmpr);
110649110880
}
110650110881
110651110882
/* Generate code to handle the case of A>B
110652110883
*/
110653110884
VdbeNoopComment((v, "A-gt-B subroutine"));
@@ -110654,11 +110885,11 @@
110654110885
addrAgtB = sqlite3VdbeCurrentAddr(v);
110655110886
if( op==TK_ALL || op==TK_UNION ){
110656110887
sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110657110888
}
110658110889
sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
110659
- sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
110890
+ sqlite3VdbeGoto(v, labelCmpr);
110660110891
110661110892
/* This code runs once to initialize everything.
110662110893
*/
110663110894
sqlite3VdbeJumpHere(v, j1);
110664110895
sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
@@ -111034,11 +111265,11 @@
111034111265
** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
111035111266
** Ticket #3300 shows that flattening the right term of a LEFT JOIN
111036111267
** is fraught with danger. Best to avoid the whole thing. If the
111037111268
** subquery is the right term of a LEFT JOIN, then do not flatten.
111038111269
*/
111039
- if( (pSubitem->jointype & JT_OUTER)!=0 ){
111270
+ if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
111040111271
return 0;
111041111272
}
111042111273
111043111274
/* Restriction 17: If the sub-query is a compound SELECT, then it must
111044111275
** use only the UNION ALL operator. And none of the simple select queries
@@ -111205,11 +111436,11 @@
111205111436
nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
111206111437
pSrc = pParent->pSrc; /* FROM clause of the outer query */
111207111438
111208111439
if( pSrc ){
111209111440
assert( pParent==p ); /* First time through the loop */
111210
- jointype = pSubitem->jointype;
111441
+ jointype = pSubitem->fg.jointype;
111211111442
}else{
111212111443
assert( pParent!=p ); /* 2nd and subsequent times through the loop */
111213111444
pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
111214111445
if( pSrc==0 ){
111215111446
assert( db->mallocFailed );
@@ -111245,11 +111476,11 @@
111245111476
for(i=0; i<nSubSrc; i++){
111246111477
sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
111247111478
pSrc->a[i+iFrom] = pSubSrc->a[i];
111248111479
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
111249111480
}
111250
- pSrc->a[iFrom].jointype = jointype;
111481
+ pSrc->a[iFrom].fg.jointype = jointype;
111251111482
111252111483
/* Now begin substituting subquery result set expressions for
111253111484
** references to the iParent in the outer query.
111254111485
**
111255111486
** Example:
@@ -111377,10 +111608,13 @@
111377111608
** close would change the meaning of the LIMIT).
111378111609
**
111379111610
** (4) The inner query is the right operand of a LEFT JOIN. (The caller
111380111611
** enforces this restriction since this routine does not have enough
111381111612
** information to know.)
111613
+**
111614
+** (5) The WHERE clause expression originates in the ON or USING clause
111615
+** of a LEFT JOIN.
111382111616
**
111383111617
** Return 0 if no changes are made and non-zero if one or more WHERE clause
111384111618
** terms are duplicated into the subquery.
111385111619
*/
111386111620
static int pushDownWhereTerms(
@@ -111400,10 +111634,11 @@
111400111634
}
111401111635
while( pWhere->op==TK_AND ){
111402111636
nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
111403111637
pWhere = pWhere->pLeft;
111404111638
}
111639
+ if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
111405111640
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
111406111641
nChng++;
111407111642
while( pSubq ){
111408111643
pNew = sqlite3ExprDup(db, pWhere, 0);
111409111644
pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
@@ -111496,13 +111731,13 @@
111496111731
** was such a clause and the named index cannot be found, return
111497111732
** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
111498111733
** pFrom->pIndex and return SQLITE_OK.
111499111734
*/
111500111735
SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){
111501
- if( pFrom->pTab && pFrom->zIndexedBy ){
111736
+ if( pFrom->pTab && pFrom->fg.isIndexedBy ){
111502111737
Table *pTab = pFrom->pTab;
111503
- char *zIndexedBy = pFrom->zIndexedBy;
111738
+ char *zIndexedBy = pFrom->u1.zIndexedBy;
111504111739
Index *pIdx;
111505111740
for(pIdx=pTab->pIndex;
111506111741
pIdx && sqlite3StrICmp(pIdx->zName, zIndexedBy);
111507111742
pIdx=pIdx->pNext
111508111743
);
@@ -111509,11 +111744,11 @@
111509111744
if( !pIdx ){
111510111745
sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
111511111746
pParse->checkSchema = 1;
111512111747
return SQLITE_ERROR;
111513111748
}
111514
- pFrom->pIndex = pIdx;
111749
+ pFrom->pIBIndex = pIdx;
111515111750
}
111516111751
return SQLITE_OK;
111517111752
}
111518111753
/*
111519111754
** Detect compound SELECT statements that use an ORDER BY clause with
@@ -111670,16 +111905,16 @@
111670111905
Select *pSel;
111671111906
Select *pLeft; /* Left-most SELECT statement */
111672111907
int bMayRecursive; /* True if compound joined by UNION [ALL] */
111673111908
With *pSavedWith; /* Initial value of pParse->pWith */
111674111909
111675
- /* If pCte->zErr is non-NULL at this point, then this is an illegal
111910
+ /* If pCte->zCteErr is non-NULL at this point, then this is an illegal
111676111911
** recursive reference to CTE pCte. Leave an error in pParse and return
111677
- ** early. If pCte->zErr is NULL, then this is not a recursive reference.
111912
+ ** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
111678111913
** In this case, proceed. */
111679
- if( pCte->zErr ){
111680
- sqlite3ErrorMsg(pParse, pCte->zErr, pCte->zName);
111914
+ if( pCte->zCteErr ){
111915
+ sqlite3ErrorMsg(pParse, pCte->zCteErr, pCte->zName);
111681111916
return SQLITE_ERROR;
111682111917
}
111683111918
111684111919
assert( pFrom->pTab==0 );
111685111920
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
@@ -111704,11 +111939,11 @@
111704111939
if( pItem->zDatabase==0
111705111940
&& pItem->zName!=0
111706111941
&& 0==sqlite3StrICmp(pItem->zName, pCte->zName)
111707111942
){
111708111943
pItem->pTab = pTab;
111709
- pItem->isRecursive = 1;
111944
+ pItem->fg.isRecursive = 1;
111710111945
pTab->nRef++;
111711111946
pSel->selFlags |= SF_Recursive;
111712111947
}
111713111948
}
111714111949
}
@@ -111720,11 +111955,11 @@
111720111955
);
111721111956
return SQLITE_ERROR;
111722111957
}
111723111958
assert( pTab->nRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nRef==2 ));
111724111959
111725
- pCte->zErr = "circular reference: %s";
111960
+ pCte->zCteErr = "circular reference: %s";
111726111961
pSavedWith = pParse->pWith;
111727111962
pParse->pWith = pWith;
111728111963
sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
111729111964
111730111965
for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
@@ -111738,20 +111973,20 @@
111738111973
return SQLITE_ERROR;
111739111974
}
111740111975
pEList = pCte->pCols;
111741111976
}
111742111977
111743
- selectColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
111978
+ sqlite3ColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
111744111979
if( bMayRecursive ){
111745111980
if( pSel->selFlags & SF_Recursive ){
111746
- pCte->zErr = "multiple recursive references: %s";
111981
+ pCte->zCteErr = "multiple recursive references: %s";
111747111982
}else{
111748
- pCte->zErr = "recursive reference in a subquery: %s";
111983
+ pCte->zCteErr = "recursive reference in a subquery: %s";
111749111984
}
111750111985
sqlite3WalkSelect(pWalker, pSel);
111751111986
}
111752
- pCte->zErr = 0;
111987
+ pCte->zCteErr = 0;
111753111988
pParse->pWith = pSavedWith;
111754111989
}
111755111990
111756111991
return SQLITE_OK;
111757111992
}
@@ -111834,12 +112069,12 @@
111834112069
** an entry of the FROM clause is a subquery instead of a table or view,
111835112070
** then create a transient table structure to describe the subquery.
111836112071
*/
111837112072
for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
111838112073
Table *pTab;
111839
- assert( pFrom->isRecursive==0 || pFrom->pTab );
111840
- if( pFrom->isRecursive ) continue;
112074
+ assert( pFrom->fg.isRecursive==0 || pFrom->pTab );
112075
+ if( pFrom->fg.isRecursive ) continue;
111841112076
if( pFrom->pTab!=0 ){
111842112077
/* This statement has already been prepared. There is no need
111843112078
** to go further. */
111844112079
assert( i==0 );
111845112080
#ifndef SQLITE_OMIT_CTE
@@ -111861,11 +112096,11 @@
111861112096
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
111862112097
if( pTab==0 ) return WRC_Abort;
111863112098
pTab->nRef = 1;
111864112099
pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
111865112100
while( pSel->pPrior ){ pSel = pSel->pPrior; }
111866
- selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
112101
+ sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
111867112102
pTab->iPKey = -1;
111868112103
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
111869112104
pTab->tabFlags |= TF_Ephemeral;
111870112105
#endif
111871112106
}else{
@@ -111998,11 +112233,11 @@
111998112233
continue;
111999112234
}
112000112235
tableSeen = 1;
112001112236
112002112237
if( i>0 && zTName==0 ){
112003
- if( (pFrom->jointype & JT_NATURAL)!=0
112238
+ if( (pFrom->fg.jointype & JT_NATURAL)!=0
112004112239
&& tableAndColumnIndex(pTabList, i, zName, 0, 0)
112005112240
){
112006112241
/* In a NATURAL join, omit the join columns from the
112007112242
** table to the right of the join */
112008112243
continue;
@@ -112284,11 +112519,11 @@
112284112519
ExprList *pList = pF->pExpr->x.pList;
112285112520
assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
112286112521
if( pList ){
112287112522
nArg = pList->nExpr;
112288112523
regAgg = sqlite3GetTempRange(pParse, nArg);
112289
- sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
112524
+ sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
112290112525
}else{
112291112526
nArg = 0;
112292112527
regAgg = 0;
112293112528
}
112294112529
if( pF->iDistinct>=0 ){
@@ -112525,11 +112760,11 @@
112525112760
** for example. In that case, do not regenerate the code to manifest
112526112761
** a view or the co-routine to implement a view. The first instance
112527112762
** is sufficient, though the subroutine to manifest the view does need
112528112763
** to be invoked again. */
112529112764
if( pItem->addrFillSub ){
112530
- if( pItem->viaCoroutine==0 ){
112765
+ if( pItem->fg.viaCoroutine==0 ){
112531112766
sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
112532112767
}
112533112768
continue;
112534112769
}
112535112770
@@ -112543,11 +112778,11 @@
112543112778
pParse->nHeight += sqlite3SelectExprHeight(p);
112544112779
112545112780
/* Make copies of constant WHERE-clause terms in the outer query down
112546112781
** inside the subquery. This can help the subquery to run more efficiently.
112547112782
*/
112548
- if( (pItem->jointype & JT_OUTER)==0
112783
+ if( (pItem->fg.jointype & JT_OUTER)==0
112549112784
&& pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
112550112785
){
112551112786
#if SELECTTRACE_ENABLED
112552112787
if( sqlite3SelectTrace & 0x100 ){
112553112788
SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
@@ -112572,11 +112807,11 @@
112572112807
pItem->addrFillSub = addrTop;
112573112808
sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
112574112809
explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
112575112810
sqlite3Select(pParse, pSub, &dest);
112576112811
pItem->pTab->nRowLogEst = sqlite3LogEst(pSub->nSelectRow);
112577
- pItem->viaCoroutine = 1;
112812
+ pItem->fg.viaCoroutine = 1;
112578112813
pItem->regResult = dest.iSdst;
112579112814
sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
112580112815
sqlite3VdbeJumpHere(v, addrTop-1);
112581112816
sqlite3ClearTempRegCache(pParse);
112582112817
}else{
@@ -112590,11 +112825,11 @@
112590112825
int retAddr;
112591112826
assert( pItem->addrFillSub==0 );
112592112827
pItem->regReturn = ++pParse->nMem;
112593112828
topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
112594112829
pItem->addrFillSub = topAddr+1;
112595
- if( pItem->isCorrelated==0 ){
112830
+ if( pItem->fg.isCorrelated==0 ){
112596112831
/* If the subquery is not correlated and if we are not inside of
112597112832
** a trigger, then we only need to compute the value of the subquery
112598112833
** once. */
112599112834
onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
112600112835
VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
@@ -112688,11 +112923,11 @@
112688112923
*/
112689112924
iEnd = sqlite3VdbeMakeLabel(v);
112690112925
p->nSelectRow = LARGEST_INT64;
112691112926
computeLimitRegisters(pParse, p, iEnd);
112692112927
if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
112693
- sqlite3VdbeGetOp(v, sSort.addrSortIndex)->opcode = OP_SorterOpen;
112928
+ sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
112694112929
sSort.sortFlags |= SORTFLAG_UseSorter;
112695112930
}
112696112931
112697112932
/* Open an ephemeral index to use for the distinct set.
112698112933
*/
@@ -112904,11 +113139,11 @@
112904113139
j++;
112905113140
}
112906113141
}
112907113142
regBase = sqlite3GetTempRange(pParse, nCol);
112908113143
sqlite3ExprCacheClear(pParse);
112909
- sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0);
113144
+ sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
112910113145
j = nGroupBy;
112911113146
for(i=0; i<sAggInfo.nColumn; i++){
112912113147
struct AggInfo_col *pCol = &sAggInfo.aCol[i];
112913113148
if( pCol->iSorterColumn>=j ){
112914113149
int r1 = j + regBase;
@@ -113016,11 +113251,11 @@
113016113251
sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
113017113252
VdbeComment((v, "output final row"));
113018113253
113019113254
/* Jump over the subroutines
113020113255
*/
113021
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEnd);
113256
+ sqlite3VdbeGoto(v, addrEnd);
113022113257
113023113258
/* Generate a subroutine that outputs a single row of the result
113024113259
** set. This subroutine first looks at the iUseFlag. If iUseFlag
113025113260
** is less than or equal to zero, the subroutine is a no-op. If
113026113261
** the processing calls for the query to abort, this subroutine
@@ -113170,11 +113405,11 @@
113170113405
goto select_end;
113171113406
}
113172113407
updateAccumulator(pParse, &sAggInfo);
113173113408
assert( pMinMax==0 || pMinMax->nExpr==1 );
113174113409
if( sqlite3WhereIsOrdered(pWInfo)>0 ){
113175
- sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3WhereBreakLabel(pWInfo));
113410
+ sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
113176113411
VdbeComment((v, "%s() by index",
113177113412
(flag==WHERE_ORDERBY_MIN?"min":"max")));
113178113413
}
113179113414
sqlite3WhereEnd(pWInfo);
113180113415
finalizeAggFunctions(pParse, &sAggInfo);
@@ -114831,20 +115066,23 @@
114831115066
114832115067
hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
114833115068
114834115069
/* There is one entry in the aRegIdx[] array for each index on the table
114835115070
** being updated. Fill in aRegIdx[] with a register number that will hold
114836
- ** the key for accessing each index.
115071
+ ** the key for accessing each index.
115072
+ **
115073
+ ** FIXME: Be smarter about omitting indexes that use expressions.
114837115074
*/
114838115075
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114839115076
int reg;
114840115077
if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
114841115078
reg = ++pParse->nMem;
114842115079
}else{
114843115080
reg = 0;
114844115081
for(i=0; i<pIdx->nKeyCol; i++){
114845
- if( aXRef[pIdx->aiColumn[i]]>=0 ){
115082
+ i16 iIdxCol = pIdx->aiColumn[i];
115083
+ if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
114846115084
reg = ++pParse->nMem;
114847115085
break;
114848115086
}
114849115087
}
114850115088
}
@@ -114940,20 +115178,21 @@
114940115178
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
114941115179
WHERE_ONEPASS_DESIRED, iIdxCur);
114942115180
if( pWInfo==0 ) goto update_cleanup;
114943115181
okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
114944115182
for(i=0; i<nPk; i++){
115183
+ assert( pPk->aiColumn[i]>=(-1) );
114945115184
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
114946115185
iPk+i);
114947115186
}
114948115187
if( okOnePass ){
114949115188
sqlite3VdbeChangeToNoop(v, addrOpen);
114950115189
nKey = nPk;
114951115190
regKey = iPk;
114952115191
}else{
114953115192
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
114954
- sqlite3IndexAffinityStr(v, pPk), nPk);
115193
+ sqlite3IndexAffinityStr(db, pPk), nPk);
114955115194
sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
114956115195
}
114957115196
sqlite3WhereEnd(pWInfo);
114958115197
}
114959115198
@@ -115186,11 +115425,11 @@
115186115425
/* Nothing to do at end-of-loop for a single-pass */
115187115426
}else if( pPk ){
115188115427
sqlite3VdbeResolveLabel(v, labelContinue);
115189115428
sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
115190115429
}else{
115191
- sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
115430
+ sqlite3VdbeGoto(v, labelContinue);
115192115431
}
115193115432
sqlite3VdbeResolveLabel(v, labelBreak);
115194115433
115195115434
/* Close all tables */
115196115435
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
@@ -115768,10 +116007,11 @@
115768116007
memcpy(zCopy, zName, nName+1);
115769116008
pMod->zName = zCopy;
115770116009
pMod->pModule = pModule;
115771116010
pMod->pAux = pAux;
115772116011
pMod->xDestroy = xDestroy;
116012
+ pMod->pEpoTab = 0;
115773116013
pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
115774116014
assert( pDel==0 || pDel==pMod );
115775116015
if( pDel ){
115776116016
db->mallocFailed = 1;
115777116017
sqlite3DbFree(db, pDel);
@@ -115995,27 +116235,21 @@
115995116235
** The string is not copied - the pointer is stored. The
115996116236
** string will be freed automatically when the table is
115997116237
** deleted.
115998116238
*/
115999116239
static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
116000
- int i = pTable->nModuleArg++;
116001
- int nBytes = sizeof(char *)*(1+pTable->nModuleArg);
116240
+ int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
116002116241
char **azModuleArg;
116003116242
azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
116004116243
if( azModuleArg==0 ){
116005
- int j;
116006
- for(j=0; j<i; j++){
116007
- sqlite3DbFree(db, pTable->azModuleArg[j]);
116008
- }
116009116244
sqlite3DbFree(db, zArg);
116010
- sqlite3DbFree(db, pTable->azModuleArg);
116011
- pTable->nModuleArg = 0;
116012116245
}else{
116246
+ int i = pTable->nModuleArg++;
116013116247
azModuleArg[i] = zArg;
116014116248
azModuleArg[i+1] = 0;
116249
+ pTable->azModuleArg = azModuleArg;
116015116250
}
116016
- pTable->azModuleArg = azModuleArg;
116017116251
}
116018116252
116019116253
/*
116020116254
** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
116021116255
** statement. The module name has been parsed, but the optional list
@@ -116138,11 +116372,11 @@
116138116372
sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
116139116373
zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
116140116374
sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
116141116375
116142116376
iReg = ++pParse->nMem;
116143
- sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0);
116377
+ sqlite3VdbeLoadString(v, iReg, pTab->zName);
116144116378
sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
116145116379
}
116146116380
116147116381
/* If we are rereading the sqlite_master table create the in-memory
116148116382
** record of the table. The xConnect() method is not called until
@@ -116414,11 +116648,11 @@
116414116648
116415116649
/* If the module has been registered and includes a Create method,
116416116650
** invoke it now. If the module has not been registered, return an
116417116651
** error. Otherwise, do nothing.
116418116652
*/
116419
- if( !pMod ){
116653
+ if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
116420116654
*pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
116421116655
rc = SQLITE_ERROR;
116422116656
}else{
116423116657
rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
116424116658
}
@@ -116516,18 +116750,21 @@
116516116750
Table *pTab;
116517116751
116518116752
pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
116519116753
if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
116520116754
VTable *p;
116755
+ int (*xDestroy)(sqlite3_vtab *);
116521116756
for(p=pTab->pVTable; p; p=p->pNext){
116522116757
assert( p->pVtab );
116523116758
if( p->pVtab->nRef>0 ){
116524116759
return SQLITE_LOCKED;
116525116760
}
116526116761
}
116527116762
p = vtabDisconnectAll(db, pTab);
116528
- rc = p->pMod->pModule->xDestroy(p->pVtab);
116763
+ xDestroy = p->pMod->pModule->xDestroy;
116764
+ assert( xDestroy!=0 ); /* Checked before the virtual table is created */
116765
+ rc = xDestroy(p->pVtab);
116529116766
/* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
116530116767
if( rc==SQLITE_OK ){
116531116768
assert( pTab->pVTable==p && p->pNext==0 );
116532116769
p->pVtab = 0;
116533116770
pTab->pVTable = 0;
@@ -116801,10 +117038,71 @@
116801117038
pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
116802117039
}else{
116803117040
pToplevel->db->mallocFailed = 1;
116804117041
}
116805117042
}
117043
+
117044
+/*
117045
+** Check to see if virtual tale module pMod can be have an eponymous
117046
+** virtual table instance. If it can, create one if one does not already
117047
+** exist. Return non-zero if the eponymous virtual table instance exists
117048
+** when this routine returns, and return zero if it does not exist.
117049
+**
117050
+** An eponymous virtual table instance is one that is named after its
117051
+** module, and more importantly, does not require a CREATE VIRTUAL TABLE
117052
+** statement in order to come into existance. Eponymous virtual table
117053
+** instances always exist. They cannot be DROP-ed.
117054
+**
117055
+** Any virtual table module for which xConnect and xCreate are the same
117056
+** method can have an eponymous virtual table instance.
117057
+*/
117058
+SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse *pParse, Module *pMod){
117059
+ const sqlite3_module *pModule = pMod->pModule;
117060
+ Table *pTab;
117061
+ char *zErr = 0;
117062
+ int nName;
117063
+ int rc;
117064
+ sqlite3 *db = pParse->db;
117065
+ if( pMod->pEpoTab ) return 1;
117066
+ if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
117067
+ nName = sqlite3Strlen30(pMod->zName) + 1;
117068
+ pTab = sqlite3DbMallocZero(db, sizeof(Table) + nName);
117069
+ if( pTab==0 ) return 0;
117070
+ pMod->pEpoTab = pTab;
117071
+ pTab->zName = (char*)&pTab[1];
117072
+ memcpy(pTab->zName, pMod->zName, nName);
117073
+ pTab->nRef = 1;
117074
+ pTab->pSchema = db->aDb[0].pSchema;
117075
+ pTab->tabFlags |= TF_Virtual;
117076
+ pTab->nModuleArg = 0;
117077
+ pTab->iPKey = -1;
117078
+ addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117079
+ addModuleArgument(db, pTab, 0);
117080
+ addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117081
+ rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
117082
+ if( rc ){
117083
+ sqlite3ErrorMsg(pParse, "%s", zErr);
117084
+ sqlite3DbFree(db, zErr);
117085
+ sqlite3VtabEponymousTableClear(db, pMod);
117086
+ return 0;
117087
+ }
117088
+ return 1;
117089
+}
117090
+
117091
+/*
117092
+** Erase the eponymous virtual table instance associated with
117093
+** virtual table module pMod, if it exists.
117094
+*/
117095
+SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3 *db, Module *pMod){
117096
+ Table *pTab = pMod->pEpoTab;
117097
+ if( (pTab = pMod->pEpoTab)!=0 ){
117098
+ sqlite3DeleteColumnNames(db, pTab);
117099
+ sqlite3VtabClear(db, pTab);
117100
+ sqlite3DbFree(db, pTab);
117101
+ pMod->pEpoTab = 0;
117102
+ }
117103
+}
116806117104
116807117105
/*
116808117106
** Return the ON CONFLICT resolution mode in effect for the virtual
116809117107
** table update operation currently in progress.
116810117108
**
@@ -117172,16 +117470,18 @@
117172117470
*/
117173117471
struct WhereScan {
117174117472
WhereClause *pOrigWC; /* Original, innermost WhereClause */
117175117473
WhereClause *pWC; /* WhereClause currently being scanned */
117176117474
char *zCollName; /* Required collating sequence, if not NULL */
117475
+ Expr *pIdxExpr; /* Search for this index expression */
117177117476
char idxaff; /* Must match this affinity, if zCollName!=NULL */
117178117477
unsigned char nEquiv; /* Number of entries in aEquiv[] */
117179117478
unsigned char iEquiv; /* Next unused slot in aEquiv[] */
117180117479
u32 opMask; /* Acceptable operators */
117181117480
int k; /* Resume scanning at this->pWC->a[this->k] */
117182
- int aEquiv[22]; /* Cursor,Column pairs for equivalence classes */
117481
+ int aiCur[11]; /* Cursors in the equivalence class */
117482
+ i16 aiColumn[11]; /* Corresponding column number in the eq-class */
117183117483
};
117184117484
117185117485
/*
117186117486
** An instance of the following structure holds all information about a
117187117487
** WHERE clause. Mostly this is a container for one or more WhereTerms.
@@ -117361,10 +117661,11 @@
117361117661
SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
117362117662
SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
117363117663
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
117364117664
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
117365117665
SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
117666
+SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, struct SrcList_item*, WhereClause*);
117366117667
117367117668
117368117669
117369117670
117370117671
@@ -117437,10 +117738,20 @@
117437117738
if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117438117739
sqlite3StrAccumAppendAll(pStr, zColumn);
117439117740
sqlite3StrAccumAppend(pStr, zOp, 1);
117440117741
sqlite3StrAccumAppend(pStr, "?", 1);
117441117742
}
117743
+
117744
+/*
117745
+** Return the name of the i-th column of the pIdx index.
117746
+*/
117747
+static const char *explainIndexColumnName(Index *pIdx, int i){
117748
+ i = pIdx->aiColumn[i];
117749
+ if( i==(-2) ) return "<expr>";
117750
+ if( i==(-1) ) return "rowid";
117751
+ return pIdx->pTable->aCol[i].zName;
117752
+}
117442117753
117443117754
/*
117444117755
** Argument pLevel describes a strategy for scanning table pTab. This
117445117756
** function appends text to pStr that describes the subset of table
117446117757
** rows scanned by the strategy in the form of an SQL expression.
@@ -117457,32 +117768,26 @@
117457117768
static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117458117769
Index *pIndex = pLoop->u.btree.pIndex;
117459117770
u16 nEq = pLoop->u.btree.nEq;
117460117771
u16 nSkip = pLoop->nSkip;
117461117772
int i, j;
117462
- Column *aCol = pTab->aCol;
117463
- i16 *aiColumn = pIndex->aiColumn;
117464117773
117465117774
if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
117466117775
sqlite3StrAccumAppend(pStr, " (", 2);
117467117776
for(i=0; i<nEq; i++){
117468
- char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
117469
- if( i>=nSkip ){
117470
- explainAppendTerm(pStr, i, z, "=");
117471
- }else{
117472
- if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117473
- sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
117474
- }
117777
+ const char *z = explainIndexColumnName(pIndex, i);
117778
+ if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117779
+ sqlite3XPrintf(pStr, 0, i>=nSkip ? "%s=?" : "ANY(%s)", z);
117475117780
}
117476117781
117477117782
j = i;
117478117783
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
117479
- char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
117784
+ const char *z = explainIndexColumnName(pIndex, i);
117480117785
explainAppendTerm(pStr, i++, z, ">");
117481117786
}
117482117787
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
117483
- char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
117788
+ const char *z = explainIndexColumnName(pIndex, j);
117484117789
explainAppendTerm(pStr, i, z, "<");
117485117790
}
117486117791
sqlite3StrAccumAppend(pStr, ")", 1);
117487117792
}
117488117793
@@ -117562,23 +117867,22 @@
117562117867
sqlite3StrAccumAppend(&str, " USING ", 7);
117563117868
sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
117564117869
explainIndexRange(&str, pLoop, pItem->pTab);
117565117870
}
117566117871
}else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
117567
- const char *zRange;
117872
+ const char *zRangeOp;
117568117873
if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
117569
- zRange = "(rowid=?)";
117874
+ zRangeOp = "=";
117570117875
}else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
117571
- zRange = "(rowid>? AND rowid<?)";
117876
+ zRangeOp = ">? AND rowid<";
117572117877
}else if( flags&WHERE_BTM_LIMIT ){
117573
- zRange = "(rowid>?)";
117878
+ zRangeOp = ">";
117574117879
}else{
117575117880
assert( flags&WHERE_TOP_LIMIT);
117576
- zRange = "(rowid<?)";
117881
+ zRangeOp = "<";
117577117882
}
117578
- sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
117579
- sqlite3StrAccumAppendAll(&str, zRange);
117883
+ sqlite3XPrintf(&str, 0, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
117580117884
}
117581117885
#ifndef SQLITE_OMIT_VIRTUALTABLE
117582117886
else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
117583117887
sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
117584117888
pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
@@ -117889,11 +118193,11 @@
117889118193
*/
117890118194
regBase = pParse->nMem + 1;
117891118195
nReg = pLoop->u.btree.nEq + nExtraReg;
117892118196
pParse->nMem += nReg;
117893118197
117894
- zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
118198
+ zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
117895118199
if( !zAff ){
117896118200
pParse->db->mallocFailed = 1;
117897118201
}
117898118202
117899118203
if( nSkip ){
@@ -118043,18 +118347,18 @@
118043118347
118044118348
/* If this is the right table of a LEFT OUTER JOIN, allocate and
118045118349
** initialize a memory cell that records if this table matches any
118046118350
** row of the left table of the join.
118047118351
*/
118048
- if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
118352
+ if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
118049118353
pLevel->iLeftJoin = ++pParse->nMem;
118050118354
sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
118051118355
VdbeComment((v, "init LEFT JOIN no-match flag"));
118052118356
}
118053118357
118054118358
/* Special case of a FROM clause subquery implemented as a co-routine */
118055
- if( pTabItem->viaCoroutine ){
118359
+ if( pTabItem->fg.viaCoroutine ){
118056118360
int regYield = pTabItem->regReturn;
118057118361
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
118058118362
pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
118059118363
VdbeCoverage(v);
118060118364
VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
@@ -118777,11 +119081,11 @@
118777119081
if( pAndExpr ){
118778119082
pAndExpr->pLeft = 0;
118779119083
sqlite3ExprDelete(db, pAndExpr);
118780119084
}
118781119085
sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
118782
- sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
119086
+ sqlite3VdbeGoto(v, pLevel->addrBrk);
118783119087
sqlite3VdbeResolveLabel(v, iLoopBody);
118784119088
118785119089
if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
118786119090
if( !untestedTerms ) disableTerm(pLevel, pTerm);
118787119091
}else
@@ -118792,11 +119096,11 @@
118792119096
** scan of the entire table.
118793119097
*/
118794119098
static const u8 aStep[] = { OP_Next, OP_Prev };
118795119099
static const u8 aStart[] = { OP_Rewind, OP_Last };
118796119100
assert( bRev==0 || bRev==1 );
118797
- if( pTabItem->isRecursive ){
119101
+ if( pTabItem->fg.isRecursive ){
118798119102
/* Tables marked isRecursive have only a single row that is stored in
118799119103
** a pseudo-cursor. No need to Rewind or Next such cursors. */
118800119104
pLevel->op = OP_Noop;
118801119105
}else{
118802119106
pLevel->op = aStep[bRev];
@@ -119699,10 +120003,55 @@
119699120003
}
119700120004
pS = pS->pPrior;
119701120005
}
119702120006
return mask;
119703120007
}
120008
+
120009
+/*
120010
+** Expression pExpr is one operand of a comparison operator that might
120011
+** be useful for indexing. This routine checks to see if pExpr appears
120012
+** in any index. Return TRUE (1) if pExpr is an indexed term and return
120013
+** FALSE (0) if not. If TRUE is returned, also set *piCur to the cursor
120014
+** number of the table that is indexed and *piColumn to the column number
120015
+** of the column that is indexed, or -2 if an expression is being indexed.
120016
+**
120017
+** If pExpr is a TK_COLUMN column reference, then this routine always returns
120018
+** true even if that particular column is not indexed, because the column
120019
+** might be added to an automatic index later.
120020
+*/
120021
+static int exprMightBeIndexed(
120022
+ SrcList *pFrom, /* The FROM clause */
120023
+ Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
120024
+ Expr *pExpr, /* An operand of a comparison operator */
120025
+ int *piCur, /* Write the referenced table cursor number here */
120026
+ int *piColumn /* Write the referenced table column number here */
120027
+){
120028
+ Index *pIdx;
120029
+ int i;
120030
+ int iCur;
120031
+ if( pExpr->op==TK_COLUMN ){
120032
+ *piCur = pExpr->iTable;
120033
+ *piColumn = pExpr->iColumn;
120034
+ return 1;
120035
+ }
120036
+ if( mPrereq==0 ) return 0; /* No table references */
120037
+ if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
120038
+ for(i=0; mPrereq>1; i++, mPrereq>>=1){}
120039
+ iCur = pFrom->a[i].iCursor;
120040
+ for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120041
+ if( pIdx->aColExpr==0 ) continue;
120042
+ for(i=0; i<pIdx->nKeyCol; i++){
120043
+ if( pIdx->aiColumn[i]!=(-2) ) continue;
120044
+ if( sqlite3ExprCompare(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
120045
+ *piCur = iCur;
120046
+ *piColumn = -2;
120047
+ return 1;
120048
+ }
120049
+ }
120050
+ }
120051
+ return 0;
120052
+}
119704120053
119705120054
/*
119706120055
** The input to this routine is an WhereTerm structure with only the
119707120056
** "pExpr" field filled in. The job of this routine is to analyze the
119708120057
** subexpression and populate all the other fields of the WhereTerm
@@ -119770,20 +120119,23 @@
119770120119
pTerm->prereqAll = prereqAll;
119771120120
pTerm->leftCursor = -1;
119772120121
pTerm->iParent = -1;
119773120122
pTerm->eOperator = 0;
119774120123
if( allowedOp(op) ){
120124
+ int iCur, iColumn;
119775120125
Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
119776120126
Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
119777120127
u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
119778
- if( pLeft->op==TK_COLUMN ){
119779
- pTerm->leftCursor = pLeft->iTable;
119780
- pTerm->u.leftColumn = pLeft->iColumn;
120128
+ if( exprMightBeIndexed(pSrc, prereqLeft, pLeft, &iCur, &iColumn) ){
120129
+ pTerm->leftCursor = iCur;
120130
+ pTerm->u.leftColumn = iColumn;
119781120131
pTerm->eOperator = operatorMask(op) & opMask;
119782120132
}
119783120133
if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
119784
- if( pRight && pRight->op==TK_COLUMN ){
120134
+ if( pRight
120135
+ && exprMightBeIndexed(pSrc, pTerm->prereqRight, pRight, &iCur, &iColumn)
120136
+ ){
119785120137
WhereTerm *pNew;
119786120138
Expr *pDup;
119787120139
u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
119788120140
if( pTerm->leftCursor>=0 ){
119789120141
int idxNew;
@@ -119808,12 +120160,12 @@
119808120160
pDup = pExpr;
119809120161
pNew = pTerm;
119810120162
}
119811120163
exprCommute(pParse, pDup);
119812120164
pLeft = sqlite3ExprSkipCollate(pDup->pLeft);
119813
- pNew->leftCursor = pLeft->iTable;
119814
- pNew->u.leftColumn = pLeft->iColumn;
120165
+ pNew->leftCursor = iCur;
120166
+ pNew->u.leftColumn = iColumn;
119815120167
testcase( (prereqLeft | extraRight) != prereqLeft );
119816120168
pNew->prereqRight = prereqLeft | extraRight;
119817120169
pNew->prereqAll = prereqAll;
119818120170
pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
119819120171
}
@@ -120152,10 +120504,50 @@
120152120504
int i;
120153120505
for(i=pWC->nTerm-1; i>=0; i--){
120154120506
exprAnalyze(pTabList, pWC, i);
120155120507
}
120156120508
}
120509
+
120510
+/*
120511
+** For table-valued-functions, transform the function arguments into
120512
+** new WHERE clause terms.
120513
+**
120514
+** Each function argument translates into an equality constraint against
120515
+** a HIDDEN column in the table.
120516
+*/
120517
+SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
120518
+ Parse *pParse, /* Parsing context */
120519
+ struct SrcList_item *pItem, /* The FROM clause term to process */
120520
+ WhereClause *pWC /* Xfer function arguments to here */
120521
+){
120522
+ Table *pTab;
120523
+ int j, k;
120524
+ ExprList *pArgs;
120525
+ Expr *pColRef;
120526
+ Expr *pTerm;
120527
+ if( pItem->fg.isTabFunc==0 ) return;
120528
+ pTab = pItem->pTab;
120529
+ assert( pTab!=0 );
120530
+ pArgs = pItem->u1.pFuncArg;
120531
+ assert( pArgs!=0 );
120532
+ for(j=k=0; j<pArgs->nExpr; j++){
120533
+ while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){ k++; }
120534
+ if( k>=pTab->nCol ){
120535
+ sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d",
120536
+ pTab->zName, j);
120537
+ return;
120538
+ }
120539
+ pColRef = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
120540
+ if( pColRef==0 ) return;
120541
+ pColRef->iTable = pItem->iCursor;
120542
+ pColRef->iColumn = k++;
120543
+ pColRef->pTab = pTab;
120544
+ pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
120545
+ sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
120546
+ whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
120547
+ }
120548
+}
120157120549
120158120550
/************** End of whereexpr.c *******************************************/
120159120551
/************** Begin file where.c *******************************************/
120160120552
/*
120161120553
** 2001 September 15
@@ -120328,41 +120720,44 @@
120328120720
** established when the pScan object was initialized by whereScanInit().
120329120721
** Return NULL if there are no more matching WhereTerms.
120330120722
*/
120331120723
static WhereTerm *whereScanNext(WhereScan *pScan){
120332120724
int iCur; /* The cursor on the LHS of the term */
120333
- int iColumn; /* The column on the LHS of the term. -1 for IPK */
120725
+ i16 iColumn; /* The column on the LHS of the term. -1 for IPK */
120334120726
Expr *pX; /* An expression being tested */
120335120727
WhereClause *pWC; /* Shorthand for pScan->pWC */
120336120728
WhereTerm *pTerm; /* The term being tested */
120337120729
int k = pScan->k; /* Where to start scanning */
120338120730
120339120731
while( pScan->iEquiv<=pScan->nEquiv ){
120340
- iCur = pScan->aEquiv[pScan->iEquiv-2];
120341
- iColumn = pScan->aEquiv[pScan->iEquiv-1];
120732
+ iCur = pScan->aiCur[pScan->iEquiv-1];
120733
+ iColumn = pScan->aiColumn[pScan->iEquiv-1];
120734
+ assert( iColumn!=(-2) || pScan->pIdxExpr!=0 );
120342120735
while( (pWC = pScan->pWC)!=0 ){
120343120736
for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
120344120737
if( pTerm->leftCursor==iCur
120345120738
&& pTerm->u.leftColumn==iColumn
120346
- && (pScan->iEquiv<=2 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
120739
+ && (iColumn!=(-2)
120740
+ || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
120741
+ && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
120347120742
){
120348120743
if( (pTerm->eOperator & WO_EQUIV)!=0
120349
- && pScan->nEquiv<ArraySize(pScan->aEquiv)
120744
+ && pScan->nEquiv<ArraySize(pScan->aiCur)
120350120745
){
120351120746
int j;
120352120747
pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
120353120748
assert( pX->op==TK_COLUMN );
120354
- for(j=0; j<pScan->nEquiv; j+=2){
120355
- if( pScan->aEquiv[j]==pX->iTable
120356
- && pScan->aEquiv[j+1]==pX->iColumn ){
120749
+ for(j=0; j<pScan->nEquiv; j++){
120750
+ if( pScan->aiCur[j]==pX->iTable
120751
+ && pScan->aiColumn[j]==pX->iColumn ){
120357120752
break;
120358120753
}
120359120754
}
120360120755
if( j==pScan->nEquiv ){
120361
- pScan->aEquiv[j] = pX->iTable;
120362
- pScan->aEquiv[j+1] = pX->iColumn;
120363
- pScan->nEquiv += 2;
120756
+ pScan->aiCur[j] = pX->iTable;
120757
+ pScan->aiColumn[j] = pX->iColumn;
120758
+ pScan->nEquiv++;
120364120759
}
120365120760
}
120366120761
if( (pTerm->eOperator & pScan->opMask)!=0 ){
120367120762
/* Verify the affinity and collating sequence match */
120368120763
if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
@@ -120380,12 +120775,12 @@
120380120775
continue;
120381120776
}
120382120777
}
120383120778
if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
120384120779
&& (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
120385
- && pX->iTable==pScan->aEquiv[0]
120386
- && pX->iColumn==pScan->aEquiv[1]
120780
+ && pX->iTable==pScan->aiCur[0]
120781
+ && pX->iColumn==pScan->aiColumn[0]
120387120782
){
120388120783
testcase( pTerm->eOperator & WO_IS );
120389120784
continue;
120390120785
}
120391120786
pScan->k = k+1;
@@ -120396,11 +120791,11 @@
120396120791
pScan->pWC = pScan->pWC->pOuter;
120397120792
k = 0;
120398120793
}
120399120794
pScan->pWC = pScan->pOrigWC;
120400120795
k = 0;
120401
- pScan->iEquiv += 2;
120796
+ pScan->iEquiv++;
120402120797
}
120403120798
return 0;
120404120799
}
120405120800
120406120801
/*
@@ -120425,49 +120820,53 @@
120425120820
int iCur, /* Cursor to scan for */
120426120821
int iColumn, /* Column to scan for */
120427120822
u32 opMask, /* Operator(s) to scan for */
120428120823
Index *pIdx /* Must be compatible with this index */
120429120824
){
120430
- int j;
120825
+ int j = 0;
120431120826
120432120827
/* memset(pScan, 0, sizeof(*pScan)); */
120433120828
pScan->pOrigWC = pWC;
120434120829
pScan->pWC = pWC;
120830
+ pScan->pIdxExpr = 0;
120831
+ if( pIdx ){
120832
+ j = iColumn;
120833
+ iColumn = pIdx->aiColumn[j];
120834
+ if( iColumn==(-2) ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
120835
+ }
120435120836
if( pIdx && iColumn>=0 ){
120436120837
pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
120437
- for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
120438
- if( NEVER(j>pIdx->nColumn) ) return 0;
120439
- }
120440120838
pScan->zCollName = pIdx->azColl[j];
120441120839
}else{
120442120840
pScan->idxaff = 0;
120443120841
pScan->zCollName = 0;
120444120842
}
120445120843
pScan->opMask = opMask;
120446120844
pScan->k = 0;
120447
- pScan->aEquiv[0] = iCur;
120448
- pScan->aEquiv[1] = iColumn;
120449
- pScan->nEquiv = 2;
120450
- pScan->iEquiv = 2;
120845
+ pScan->aiCur[0] = iCur;
120846
+ pScan->aiColumn[0] = iColumn;
120847
+ pScan->nEquiv = 1;
120848
+ pScan->iEquiv = 1;
120451120849
return whereScanNext(pScan);
120452120850
}
120453120851
120454120852
/*
120455120853
** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
120456120854
** where X is a reference to the iColumn of table iCur and <op> is one of
120457120855
** the WO_xx operator codes specified by the op parameter.
120458120856
** Return a pointer to the term. Return 0 if not found.
120857
+**
120858
+** If pIdx!=0 then search for terms matching the iColumn-th column of pIdx
120859
+** rather than the iColumn-th column of table iCur.
120459120860
**
120460120861
** The term returned might by Y=<expr> if there is another constraint in
120461120862
** the WHERE clause that specifies that X=Y. Any such constraints will be
120462120863
** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
120463
-** aEquiv[] array holds X and all its equivalents, with each SQL variable
120464
-** taking up two slots in aEquiv[]. The first slot is for the cursor number
120465
-** and the second is for the column number. There are 22 slots in aEquiv[]
120466
-** so that means we can look for X plus up to 10 other equivalent values.
120467
-** Hence a search for X will return <expr> if X=A1 and A1=A2 and A2=A3
120468
-** and ... and A9=A10 and A10=<expr>.
120864
+** aiCur[]/iaColumn[] arrays hold X and all its equivalents. There are 11
120865
+** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10
120866
+** other equivalent values. Hence a search for X will return <expr> if X=A1
120867
+** and A1=A2 and A2=A3 and ... and A9=A10 and A10=<expr>.
120469120868
**
120470120869
** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
120471120870
** then try for the one with no dependencies on <expr> - in other words where
120472120871
** <expr> is a constant expression of some kind. Only return entries of
120473120872
** the form "X <op> Y" where Y is a column in another table if no terms of
@@ -120531,10 +120930,29 @@
120531120930
}
120532120931
}
120533120932
120534120933
return -1;
120535120934
}
120935
+
120936
+/*
120937
+** Return TRUE if the iCol-th column of index pIdx is NOT NULL
120938
+*/
120939
+static int indexColumnNotNull(Index *pIdx, int iCol){
120940
+ int j;
120941
+ assert( pIdx!=0 );
120942
+ assert( iCol>=0 && iCol<pIdx->nColumn );
120943
+ j = pIdx->aiColumn[iCol];
120944
+ if( j>=0 ){
120945
+ return pIdx->pTable->aCol[j].notNull;
120946
+ }else if( j==(-1) ){
120947
+ return 1;
120948
+ }else{
120949
+ assert( j==(-2) );
120950
+ return 0; /* Assume an indexed expression can always yield a NULL */
120951
+
120952
+ }
120953
+}
120536120954
120537120955
/*
120538120956
** Return true if the DISTINCT expression-list passed as the third argument
120539120957
** is redundant.
120540120958
**
@@ -120582,16 +121000,13 @@
120582121000
** contain a "col=X" term are subject to a NOT NULL constraint.
120583121001
*/
120584121002
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120585121003
if( !IsUniqueIndex(pIdx) ) continue;
120586121004
for(i=0; i<pIdx->nKeyCol; i++){
120587
- i16 iCol = pIdx->aiColumn[i];
120588
- if( 0==sqlite3WhereFindTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
120589
- int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i);
120590
- if( iIdxCol<0 || pTab->aCol[iCol].notNull==0 ){
120591
- break;
120592
- }
121005
+ if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
121006
+ if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
121007
+ if( indexColumnNotNull(pIdx, i)==0 ) break;
120593121008
}
120594121009
}
120595121010
if( i==pIdx->nKeyCol ){
120596121011
/* This index implies that the DISTINCT qualifier is redundant. */
120597121012
return 1;
@@ -120866,11 +121281,11 @@
120866121281
VdbeComment((v, "for %s", pTable->zName));
120867121282
120868121283
/* Fill the automatic index with content */
120869121284
sqlite3ExprCachePush(pParse);
120870121285
pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];
120871
- if( pTabItem->viaCoroutine ){
121286
+ if( pTabItem->fg.viaCoroutine ){
120872121287
int regYield = pTabItem->regReturn;
120873121288
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
120874121289
addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
120875121290
VdbeCoverage(v);
120876121291
VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
@@ -120885,14 +121300,14 @@
120885121300
regRecord = sqlite3GetTempReg(pParse);
120886121301
sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
120887121302
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
120888121303
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
120889121304
if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
120890
- if( pTabItem->viaCoroutine ){
121305
+ if( pTabItem->fg.viaCoroutine ){
120891121306
translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult);
120892
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
120893
- pTabItem->viaCoroutine = 0;
121307
+ sqlite3VdbeGoto(v, addrTop);
121308
+ pTabItem->fg.viaCoroutine = 0;
120894121309
}else{
120895121310
sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
120896121311
}
120897121312
sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
120898121313
sqlite3VdbeJumpHere(v, addrTop);
@@ -120939,10 +121354,11 @@
120939121354
testcase( pTerm->eOperator & WO_ISNULL );
120940121355
testcase( pTerm->eOperator & WO_IS );
120941121356
testcase( pTerm->eOperator & WO_ALL );
120942121357
if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
120943121358
if( pTerm->wtFlags & TERM_VNULL ) continue;
121359
+ assert( pTerm->u.leftColumn>=(-1) );
120944121360
nTerm++;
120945121361
}
120946121362
120947121363
/* If the ORDER BY clause contains only columns in the current
120948121364
** virtual table then allocate space for the aOrderBy part of
@@ -120994,10 +121410,11 @@
120994121410
testcase( pTerm->eOperator & WO_IS );
120995121411
testcase( pTerm->eOperator & WO_ISNULL );
120996121412
testcase( pTerm->eOperator & WO_ALL );
120997121413
if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
120998121414
if( pTerm->wtFlags & TERM_VNULL ) continue;
121415
+ assert( pTerm->u.leftColumn>=(-1) );
120999121416
pIdxCons[j].iColumn = pTerm->u.leftColumn;
121000121417
pIdxCons[j].iTermOffset = i;
121001121418
op = (u8)pTerm->eOperator & WO_ALL;
121002121419
if( op==WO_IN ) op = WO_EQ;
121003121420
pIdxCons[j].op = op;
@@ -121283,10 +121700,24 @@
121283121700
nRet -= 20; assert( 20==sqlite3LogEst(4) );
121284121701
}
121285121702
}
121286121703
return nRet;
121287121704
}
121705
+
121706
+
121707
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
121708
+/*
121709
+** Return the affinity for a single column of an index.
121710
+*/
121711
+static char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){
121712
+ if( !pIdx->zColAff ){
121713
+ if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
121714
+ }
121715
+ return pIdx->zColAff[iCol];
121716
+}
121717
+#endif
121718
+
121288121719
121289121720
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
121290121721
/*
121291121722
** This function is called to estimate the number of rows visited by a
121292121723
** range-scan on a skip-scan index. For example:
@@ -121334,11 +121765,11 @@
121334121765
sqlite3 *db = pParse->db;
121335121766
int nLower = -1;
121336121767
int nUpper = p->nSample+1;
121337121768
int rc = SQLITE_OK;
121338121769
int iCol = p->aiColumn[nEq];
121339
- u8 aff = iCol>=0 ? p->pTable->aCol[iCol].affinity : SQLITE_AFF_INTEGER;
121770
+ u8 aff = sqlite3IndexColumnAffinity(db, p, iCol);
121340121771
CollSeq *pColl;
121341121772
121342121773
sqlite3_value *p1 = 0; /* Value extracted from pLower */
121343121774
sqlite3_value *p2 = 0; /* Value extracted from pUpper */
121344121775
sqlite3_value *pVal = 0; /* Value extracted from record */
@@ -121482,15 +121913,12 @@
121482121913
121483121914
if( pRec ){
121484121915
testcase( pRec->nField!=pBuilder->nRecValid );
121485121916
pRec->nField = pBuilder->nRecValid;
121486121917
}
121487
- if( nEq==p->nKeyCol ){
121488
- aff = SQLITE_AFF_INTEGER;
121489
- }else{
121490
- aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
121491
- }
121918
+ aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq);
121919
+ assert( nEq!=p->nKeyCol || aff==SQLITE_AFF_INTEGER );
121492121920
/* Determine iLower and iUpper using ($P) only. */
121493121921
if( nEq==0 ){
121494121922
iLower = 0;
121495121923
iUpper = p->nRowEst0;
121496121924
}else{
@@ -121644,11 +122072,11 @@
121644122072
if( nEq>=p->nColumn ){
121645122073
*pnRow = 1;
121646122074
return SQLITE_OK;
121647122075
}
121648122076
121649
- aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity;
122077
+ aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq-1);
121650122078
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq-1, &bOk);
121651122079
pBuilder->pRec = pRec;
121652122080
if( rc!=SQLITE_OK ) return rc;
121653122081
if( bOk==0 ) return SQLITE_NOTFOUND;
121654122082
pBuilder->nRecValid = nEq;
@@ -122071,22 +122499,24 @@
122071122499
122072122500
/* If pBuilder->pOrSet is defined, then only keep track of the costs
122073122501
** and prereqs.
122074122502
*/
122075122503
if( pBuilder->pOrSet!=0 ){
122504
+ if( pTemplate->nLTerm ){
122076122505
#if WHERETRACE_ENABLED
122077
- u16 n = pBuilder->pOrSet->n;
122078
- int x =
122506
+ u16 n = pBuilder->pOrSet->n;
122507
+ int x =
122079122508
#endif
122080
- whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
122509
+ whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
122081122510
pTemplate->nOut);
122082122511
#if WHERETRACE_ENABLED /* 0x8 */
122083
- if( sqlite3WhereTrace & 0x8 ){
122084
- sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
122085
- whereLoopPrint(pTemplate, pBuilder->pWC);
122512
+ if( sqlite3WhereTrace & 0x8 ){
122513
+ sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
122514
+ whereLoopPrint(pTemplate, pBuilder->pWC);
122515
+ }
122516
+#endif
122086122517
}
122087
-#endif
122088122518
return SQLITE_OK;
122089122519
}
122090122520
122091122521
/* Look for an existing WhereLoop to replace with pTemplate
122092122522
*/
@@ -122272,11 +122702,10 @@
122272122702
u16 saved_nLTerm; /* Original value of pNew->nLTerm */
122273122703
u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
122274122704
u16 saved_nSkip; /* Original value of pNew->nSkip */
122275122705
u32 saved_wsFlags; /* Original value of pNew->wsFlags */
122276122706
LogEst saved_nOut; /* Original value of pNew->nOut */
122277
- int iCol; /* Index of the column in the table */
122278122707
int rc = SQLITE_OK; /* Return code */
122279122708
LogEst rSize; /* Number of rows in the table */
122280122709
LogEst rLogSize; /* Logarithm of table size */
122281122710
WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
122282122711
@@ -122285,28 +122714,27 @@
122285122714
122286122715
assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
122287122716
assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
122288122717
if( pNew->wsFlags & WHERE_BTM_LIMIT ){
122289122718
opMask = WO_LT|WO_LE;
122290
- }else if( /*pProbe->tnum<=0 ||*/ (pSrc->jointype & JT_LEFT)!=0 ){
122719
+ }else if( /*pProbe->tnum<=0 ||*/ (pSrc->fg.jointype & JT_LEFT)!=0 ){
122291122720
opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE;
122292122721
}else{
122293122722
opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
122294122723
}
122295122724
if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
122296122725
122297122726
assert( pNew->u.btree.nEq<pProbe->nColumn );
122298
- iCol = pProbe->aiColumn[pNew->u.btree.nEq];
122299122727
122300
- pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
122301
- opMask, pProbe);
122302122728
saved_nEq = pNew->u.btree.nEq;
122303122729
saved_nSkip = pNew->nSkip;
122304122730
saved_nLTerm = pNew->nLTerm;
122305122731
saved_wsFlags = pNew->wsFlags;
122306122732
saved_prereq = pNew->prereq;
122307122733
saved_nOut = pNew->nOut;
122734
+ pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, saved_nEq,
122735
+ opMask, pProbe);
122308122736
pNew->rSetup = 0;
122309122737
rSize = pProbe->aiRowLogEst[0];
122310122738
rLogSize = estLog(rSize);
122311122739
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
122312122740
u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
@@ -122315,11 +122743,11 @@
122315122743
int nIn = 0;
122316122744
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
122317122745
int nRecValid = pBuilder->nRecValid;
122318122746
#endif
122319122747
if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
122320
- && (iCol<0 || pSrc->pTab->aCol[iCol].notNull)
122748
+ && indexColumnNotNull(pProbe, saved_nEq)
122321122749
){
122322122750
continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
122323122751
}
122324122752
if( pTerm->prereqRight & pNew->maskSelf ) continue;
122325122753
@@ -122352,12 +122780,14 @@
122352122780
}
122353122781
assert( nIn>0 ); /* RHS always has 2 or more terms... The parser
122354122782
** changes "x IN (?)" into "x=?". */
122355122783
122356122784
}else if( eOp & (WO_EQ|WO_IS) ){
122785
+ int iCol = pProbe->aiColumn[saved_nEq];
122357122786
pNew->wsFlags |= WHERE_COLUMN_EQ;
122358
- if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
122787
+ assert( saved_nEq==pNew->u.btree.nEq );
122788
+ if( iCol==(-1) || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) ){
122359122789
if( iCol>=0 && pProbe->uniqNotNull==0 ){
122360122790
pNew->wsFlags |= WHERE_UNQ_WANTED;
122361122791
}else{
122362122792
pNew->wsFlags |= WHERE_ONEROW;
122363122793
}
@@ -122404,11 +122834,11 @@
122404122834
}else{
122405122835
int nEq = ++pNew->u.btree.nEq;
122406122836
assert( eOp & (WO_ISNULL|WO_EQ|WO_IN|WO_IS) );
122407122837
122408122838
assert( pNew->nOut==saved_nOut );
122409
- if( pTerm->truthProb<=0 && iCol>=0 ){
122839
+ if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
122410122840
assert( (eOp & WO_IN) || nIn==0 );
122411122841
testcase( eOp & WO_IN );
122412122842
pNew->nOut += pTerm->truthProb;
122413122843
pNew->nOut -= nIn;
122414122844
}else{
@@ -122580,10 +123010,14 @@
122580123010
** in the current query. Return true if it can be and false if not.
122581123011
*/
122582123012
static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
122583123013
int i;
122584123014
WhereTerm *pTerm;
123015
+ while( pWhere->op==TK_AND ){
123016
+ if( !whereUsablePartialIndex(iTab,pWC,pWhere->pLeft) ) return 0;
123017
+ pWhere = pWhere->pRight;
123018
+ }
122585123019
for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
122586123020
Expr *pExpr = pTerm->pExpr;
122587123021
if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab)
122588123022
&& (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
122589123023
){
@@ -122655,13 +123089,13 @@
122655123089
pSrc = pTabList->a + pNew->iTab;
122656123090
pTab = pSrc->pTab;
122657123091
pWC = pBuilder->pWC;
122658123092
assert( !IsVirtual(pSrc->pTab) );
122659123093
122660
- if( pSrc->pIndex ){
123094
+ if( pSrc->pIBIndex ){
122661123095
/* An INDEXED BY clause specifies a particular index to use */
122662
- pProbe = pSrc->pIndex;
123096
+ pProbe = pSrc->pIBIndex;
122663123097
}else if( !HasRowid(pTab) ){
122664123098
pProbe = pTab->pIndex;
122665123099
}else{
122666123100
/* There is no INDEXED BY clause. Create a fake Index object in local
122667123101
** variable sPk to represent the rowid primary key index. Make this
@@ -122677,11 +123111,11 @@
122677123111
sPk.pTable = pTab;
122678123112
sPk.szIdxRow = pTab->szTabRow;
122679123113
aiRowEstPk[0] = pTab->nRowLogEst;
122680123114
aiRowEstPk[1] = 0;
122681123115
pFirst = pSrc->pTab->pIndex;
122682
- if( pSrc->notIndexed==0 ){
123116
+ if( pSrc->fg.notIndexed==0 ){
122683123117
/* The real indices of the table are only considered if the
122684123118
** NOT INDEXED qualifier is omitted from the FROM clause */
122685123119
sPk.pNext = pFirst;
122686123120
}
122687123121
pProbe = &sPk;
@@ -122689,18 +123123,18 @@
122689123123
rSize = pTab->nRowLogEst;
122690123124
rLogSize = estLog(rSize);
122691123125
122692123126
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
122693123127
/* Automatic indexes */
122694
- if( !pBuilder->pOrSet /* Not part of an OR optimization */
123128
+ if( !pBuilder->pOrSet /* Not part of an OR optimization */
122695123129
&& (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
122696123130
&& (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
122697
- && pSrc->pIndex==0 /* Has no INDEXED BY clause */
122698
- && !pSrc->notIndexed /* Has no NOT INDEXED clause */
122699
- && HasRowid(pTab) /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
122700
- && !pSrc->isCorrelated /* Not a correlated subquery */
122701
- && !pSrc->isRecursive /* Not a recursive common table expression. */
123131
+ && pSrc->pIBIndex==0 /* Has no INDEXED BY clause */
123132
+ && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */
123133
+ && HasRowid(pTab) /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
123134
+ && !pSrc->fg.isCorrelated /* Not a correlated subquery */
123135
+ && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
122702123136
){
122703123137
/* Generate auto-index WhereLoops */
122704123138
WhereTerm *pTerm;
122705123139
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
122706123140
for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
@@ -122817,11 +123251,11 @@
122817123251
pBuilder->pRec = 0;
122818123252
#endif
122819123253
122820123254
/* If there was an INDEXED BY clause, then only that one index is
122821123255
** considered. */
122822
- if( pSrc->pIndex ) break;
123256
+ if( pSrc->pIBIndex ) break;
122823123257
}
122824123258
return rc;
122825123259
}
122826123260
122827123261
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -123163,20 +123597,20 @@
123163123597
whereLoopInit(pNew);
123164123598
for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
123165123599
Bitmask mUnusable = 0;
123166123600
pNew->iTab = iTab;
123167123601
pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
123168
- if( ((pItem->jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
123602
+ if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
123169123603
/* This condition is true when pItem is the FROM clause term on the
123170123604
** right-hand-side of a LEFT or CROSS JOIN. */
123171123605
mExtra = mPrior;
123172123606
}
123173
- priorJointype = pItem->jointype;
123607
+ priorJointype = pItem->fg.jointype;
123174123608
if( IsVirtual(pItem->pTab) ){
123175123609
struct SrcList_item *p;
123176123610
for(p=&pItem[1]; p<pEnd; p++){
123177
- if( mUnusable || (p->jointype & (JT_LEFT|JT_CROSS)) ){
123611
+ if( mUnusable || (p->fg.jointype & (JT_LEFT|JT_CROSS)) ){
123178123612
mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
123179123613
}
123180123614
}
123181123615
rc = whereLoopAddVirtual(pBuilder, mExtra, mUnusable);
123182123616
}else{
@@ -123902,11 +124336,11 @@
123902124336
if( pWInfo->wctrlFlags & WHERE_FORCE_TABLE ) return 0;
123903124337
assert( pWInfo->pTabList->nSrc>=1 );
123904124338
pItem = pWInfo->pTabList->a;
123905124339
pTab = pItem->pTab;
123906124340
if( IsVirtual(pTab) ) return 0;
123907
- if( pItem->zIndexedBy ) return 0;
124341
+ if( pItem->fg.isIndexedBy ) return 0;
123908124342
iCur = pItem->iCursor;
123909124343
pWC = &pWInfo->sWC;
123910124344
pLoop = pBuilder->pNew;
123911124345
pLoop->wsFlags = 0;
123912124346
pLoop->nSkip = 0;
@@ -123927,11 +124361,11 @@
123927124361
|| pIdx->pPartIdxWhere!=0
123928124362
|| pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
123929124363
) continue;
123930124364
opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ;
123931124365
for(j=0; j<pIdx->nKeyCol; j++){
123932
- pTerm = sqlite3WhereFindTerm(pWC, iCur, pIdx->aiColumn[j], 0, opMask, pIdx);
124366
+ pTerm = sqlite3WhereFindTerm(pWC, iCur, j, 0, opMask, pIdx);
123933124367
if( pTerm==0 ) break;
123934124368
testcase( pTerm->eOperator & WO_IS );
123935124369
pLoop->aLTerm[j] = pTerm;
123936124370
}
123937124371
if( j!=pIdx->nKeyCol ) continue;
@@ -124167,35 +124601,30 @@
124167124601
}
124168124602
}
124169124603
124170124604
/* Assign a bit from the bitmask to every term in the FROM clause.
124171124605
**
124172
- ** When assigning bitmask values to FROM clause cursors, it must be
124173
- ** the case that if X is the bitmask for the N-th FROM clause term then
124174
- ** the bitmask for all FROM clause terms to the left of the N-th term
124175
- ** is (X-1). An expression from the ON clause of a LEFT JOIN can use
124176
- ** its Expr.iRightJoinTable value to find the bitmask of the right table
124177
- ** of the join. Subtracting one from the right table bitmask gives a
124178
- ** bitmask for all tables to the left of the join. Knowing the bitmask
124179
- ** for all tables to the left of a left join is important. Ticket #3015.
124606
+ ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
124607
+ **
124608
+ ** The rule of the previous sentence ensures thta if X is the bitmask for
124609
+ ** a table T, then X-1 is the bitmask for all other tables to the left of T.
124610
+ ** Knowing the bitmask for all tables to the left of a left join is
124611
+ ** important. Ticket #3015.
124180124612
**
124181124613
** Note that bitmasks are created for all pTabList->nSrc tables in
124182124614
** pTabList, not just the first nTabList tables. nTabList is normally
124183124615
** equal to pTabList->nSrc but might be shortened to 1 if the
124184124616
** WHERE_ONETABLE_ONLY flag is set.
124185124617
*/
124186124618
for(ii=0; ii<pTabList->nSrc; ii++){
124187124619
createMask(pMaskSet, pTabList->a[ii].iCursor);
124188
- }
124189
-#ifndef NDEBUG
124190
- {
124191
- Bitmask toTheLeft = 0;
124192
- for(ii=0; ii<pTabList->nSrc; ii++){
124193
- Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
124194
- assert( (m-1)==toTheLeft );
124195
- toTheLeft |= m;
124196
- }
124620
+ sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
124621
+ }
124622
+#ifdef SQLITE_DEBUG
124623
+ for(ii=0; ii<pTabList->nSrc; ii++){
124624
+ Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
124625
+ assert( m==MASKBIT(ii) );
124197124626
}
124198124627
#endif
124199124628
124200124629
/* Analyze all of the subexpressions. */
124201124630
sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
@@ -124289,11 +124718,11 @@
124289124718
tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
124290124719
}
124291124720
while( pWInfo->nLevel>=2 ){
124292124721
WhereTerm *pTerm, *pEnd;
124293124722
pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
124294
- if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
124723
+ if( (pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 ) break;
124295124724
if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
124296124725
&& (pLoop->wsFlags & WHERE_ONEROW)==0
124297124726
){
124298124727
break;
124299124728
}
@@ -124527,11 +124956,11 @@
124527124956
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
124528124957
}
124529124958
}
124530124959
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
124531124960
if( pLevel->addrSkip ){
124532
- sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
124961
+ sqlite3VdbeGoto(v, pLevel->addrSkip);
124533124962
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
124534124963
sqlite3VdbeJumpHere(v, pLevel->addrSkip);
124535124964
sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
124536124965
}
124537124966
if( pLevel->addrLikeRep ){
@@ -124555,11 +124984,11 @@
124555124984
sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
124556124985
}
124557124986
if( pLevel->op==OP_Return ){
124558124987
sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst);
124559124988
}else{
124560
- sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
124989
+ sqlite3VdbeGoto(v, pLevel->addrFirst);
124561124990
}
124562124991
sqlite3VdbeJumpHere(v, addr);
124563124992
}
124564124993
VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
124565124994
pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
@@ -124582,11 +125011,11 @@
124582125011
124583125012
/* For a co-routine, change all OP_Column references to the table of
124584125013
** the co-routine into OP_Copy of result contained in a register.
124585125014
** OP_Rowid becomes OP_Null.
124586125015
*/
124587
- if( pTabItem->viaCoroutine && !db->mallocFailed ){
125016
+ if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
124588125017
translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
124589125018
pTabItem->regResult);
124590125019
continue;
124591125020
}
124592125021
@@ -124816,10 +125245,33 @@
124816125245
){
124817125246
pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
124818125247
pOut->zStart = pPreOp->z;
124819125248
pOut->zEnd = pOperand->zEnd;
124820125249
}
125250
+
125251
+ /* Add a single new term to an ExprList that is used to store a
125252
+ ** list of identifiers. Report an error if the ID list contains
125253
+ ** a COLLATE clause or an ASC or DESC keyword, except ignore the
125254
+ ** error while parsing a legacy schema.
125255
+ */
125256
+ static ExprList *parserAddExprIdListTerm(
125257
+ Parse *pParse,
125258
+ ExprList *pPrior,
125259
+ Token *pIdToken,
125260
+ int hasCollate,
125261
+ int sortOrder
125262
+ ){
125263
+ ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
125264
+ if( (hasCollate || sortOrder!=SQLITE_SO_UNDEFINED)
125265
+ && pParse->db->init.busy==0
125266
+ ){
125267
+ sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
125268
+ pIdToken->n, pIdToken->z);
125269
+ }
125270
+ sqlite3ExprListSetName(pParse, p, pIdToken, 1);
125271
+ return p;
125272
+ }
124821125273
/* Next is all token values, in a form suitable for use by makeheaders.
124822125274
** This section will be null unless lemon is run with the -m switch.
124823125275
*/
124824125276
/*
124825125277
** These constants (all generated automatically by the parser generator)
@@ -124860,14 +125312,21 @@
124860125312
** zero the stack is dynamically sized using realloc()
124861125313
** sqlite3ParserARG_SDECL A static variable declaration for the %extra_argument
124862125314
** sqlite3ParserARG_PDECL A parameter declaration for the %extra_argument
124863125315
** sqlite3ParserARG_STORE Code to store %extra_argument into yypParser
124864125316
** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
125317
+** YYERRORSYMBOL is the code number of the error symbol. If not
125318
+** defined, then do no error processing.
124865125319
** YYNSTATE the combined number of states.
124866125320
** YYNRULE the number of rules in the grammar
124867
-** YYERRORSYMBOL is the code number of the error symbol. If not
124868
-** defined, then do no error processing.
125321
+** YY_MAX_SHIFT Maximum value for shift actions
125322
+** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
125323
+** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
125324
+** YY_MIN_REDUCE Maximum value for reduce actions
125325
+** YY_ERROR_ACTION The yy_action[] code for syntax error
125326
+** YY_ACCEPT_ACTION The yy_action[] code for accept
125327
+** YY_NO_ACTION The yy_action[] code for no-op
124869125328
*/
124870125329
#define YYCODETYPE unsigned char
124871125330
#define YYNOCODE 254
124872125331
#define YYACTIONTYPE unsigned short int
124873125332
#define YYWILDCARD 70
@@ -124896,16 +125355,21 @@
124896125355
#endif
124897125356
#define sqlite3ParserARG_SDECL Parse *pParse;
124898125357
#define sqlite3ParserARG_PDECL ,Parse *pParse
124899125358
#define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
124900125359
#define sqlite3ParserARG_STORE yypParser->pParse = pParse
124901
-#define YYNSTATE 642
124902
-#define YYNRULE 327
124903125360
#define YYFALLBACK 1
124904
-#define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
124905
-#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
124906
-#define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
125361
+#define YYNSTATE 436
125362
+#define YYNRULE 328
125363
+#define YY_MAX_SHIFT 435
125364
+#define YY_MIN_SHIFTREDUCE 649
125365
+#define YY_MAX_SHIFTREDUCE 976
125366
+#define YY_MIN_REDUCE 977
125367
+#define YY_MAX_REDUCE 1304
125368
+#define YY_ERROR_ACTION 1305
125369
+#define YY_ACCEPT_ACTION 1306
125370
+#define YY_NO_ACTION 1307
124907125371
124908125372
/* The yyzerominor constant is used to initialize instances of
124909125373
** YYMINORTYPE objects to zero. */
124910125374
static const YYMINORTYPE yyzerominor = { 0 };
124911125375
@@ -124928,20 +125392,24 @@
124928125392
** action integer.
124929125393
**
124930125394
** Suppose the action integer is N. Then the action is determined as
124931125395
** follows
124932125396
**
124933
-** 0 <= N < YYNSTATE Shift N. That is, push the lookahead
125397
+** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
124934125398
** token onto the stack and goto state N.
124935125399
**
124936
-** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE.
125400
+** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
125401
+** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
124937125402
**
124938
-** N == YYNSTATE+YYNRULE A syntax error has occurred.
125403
+** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
125404
+** and YY_MAX_REDUCE
125405
+
125406
+** N == YY_ERROR_ACTION A syntax error has occurred.
124939125407
**
124940
-** N == YYNSTATE+YYNRULE+1 The parser accepts its input.
125408
+** N == YY_ACCEPT_ACTION The parser accepts its input.
124941125409
**
124942
-** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused
125410
+** N == YY_NO_ACTION No such action. Denotes unused
124943125411
** slots in the yy_action[] table.
124944125412
**
124945125413
** The action table is constructed as a single large table named yy_action[].
124946125414
** Given state S and lookahead X, the action is computed as
124947125415
**
@@ -124967,467 +125435,450 @@
124967125435
** shifting terminals.
124968125436
** yy_reduce_ofst[] For each state, the offset into yy_action for
124969125437
** shifting non-terminals after a reduce.
124970125438
** yy_default[] Default action for each state.
124971125439
*/
124972
-#define YY_ACTTAB_COUNT (1497)
125440
+#define YY_ACTTAB_COUNT (1501)
124973125441
static const YYACTIONTYPE yy_action[] = {
124974
- /* 0 */ 306, 212, 432, 955, 639, 191, 955, 295, 559, 88,
124975
- /* 10 */ 88, 88, 88, 81, 86, 86, 86, 86, 85, 85,
124976
- /* 20 */ 84, 84, 84, 83, 330, 185, 184, 183, 635, 635,
124977
- /* 30 */ 292, 606, 606, 88, 88, 88, 88, 683, 86, 86,
124978
- /* 40 */ 86, 86, 85, 85, 84, 84, 84, 83, 330, 16,
124979
- /* 50 */ 436, 597, 89, 90, 80, 600, 599, 601, 601, 87,
124980
- /* 60 */ 87, 88, 88, 88, 88, 684, 86, 86, 86, 86,
124981
- /* 70 */ 85, 85, 84, 84, 84, 83, 330, 306, 559, 84,
124982
- /* 80 */ 84, 84, 83, 330, 65, 86, 86, 86, 86, 85,
124983
- /* 90 */ 85, 84, 84, 84, 83, 330, 635, 635, 634, 633,
124984
- /* 100 */ 182, 682, 550, 379, 376, 375, 17, 322, 606, 606,
124985
- /* 110 */ 371, 198, 479, 91, 374, 82, 79, 165, 85, 85,
124986
- /* 120 */ 84, 84, 84, 83, 330, 598, 635, 635, 107, 89,
124987
- /* 130 */ 90, 80, 600, 599, 601, 601, 87, 87, 88, 88,
124988
- /* 140 */ 88, 88, 186, 86, 86, 86, 86, 85, 85, 84,
124989
- /* 150 */ 84, 84, 83, 330, 306, 594, 594, 142, 328, 327,
124990
- /* 160 */ 484, 249, 344, 238, 635, 635, 634, 633, 585, 448,
124991
- /* 170 */ 526, 525, 229, 388, 1, 394, 450, 584, 449, 635,
124992
- /* 180 */ 635, 635, 635, 319, 395, 606, 606, 199, 157, 273,
124993
- /* 190 */ 382, 268, 381, 187, 635, 635, 634, 633, 311, 555,
124994
- /* 200 */ 266, 593, 593, 266, 347, 588, 89, 90, 80, 600,
124995
- /* 210 */ 599, 601, 601, 87, 87, 88, 88, 88, 88, 478,
124996
- /* 220 */ 86, 86, 86, 86, 85, 85, 84, 84, 84, 83,
124997
- /* 230 */ 330, 306, 272, 536, 634, 633, 146, 610, 197, 310,
124998
- /* 240 */ 575, 182, 482, 271, 379, 376, 375, 506, 21, 634,
124999
- /* 250 */ 633, 634, 633, 635, 635, 374, 611, 574, 548, 440,
125000
- /* 260 */ 111, 563, 606, 606, 634, 633, 324, 479, 608, 608,
125001
- /* 270 */ 608, 300, 435, 573, 119, 407, 210, 162, 562, 883,
125002
- /* 280 */ 592, 592, 306, 89, 90, 80, 600, 599, 601, 601,
125003
- /* 290 */ 87, 87, 88, 88, 88, 88, 506, 86, 86, 86,
125004
- /* 300 */ 86, 85, 85, 84, 84, 84, 83, 330, 620, 111,
125005
- /* 310 */ 635, 635, 361, 606, 606, 358, 249, 349, 248, 433,
125006
- /* 320 */ 243, 479, 586, 634, 633, 195, 611, 93, 119, 221,
125007
- /* 330 */ 575, 497, 534, 534, 89, 90, 80, 600, 599, 601,
125008
- /* 340 */ 601, 87, 87, 88, 88, 88, 88, 574, 86, 86,
125009
- /* 350 */ 86, 86, 85, 85, 84, 84, 84, 83, 330, 306,
125010
- /* 360 */ 77, 429, 638, 573, 589, 530, 240, 230, 242, 105,
125011
- /* 370 */ 249, 349, 248, 515, 588, 208, 460, 529, 564, 173,
125012
- /* 380 */ 634, 633, 970, 144, 430, 2, 424, 228, 380, 557,
125013
- /* 390 */ 606, 606, 190, 153, 159, 158, 514, 51, 632, 631,
125014
- /* 400 */ 630, 71, 536, 432, 954, 196, 610, 954, 614, 45,
125015
- /* 410 */ 18, 89, 90, 80, 600, 599, 601, 601, 87, 87,
125016
- /* 420 */ 88, 88, 88, 88, 261, 86, 86, 86, 86, 85,
125017
- /* 430 */ 85, 84, 84, 84, 83, 330, 306, 608, 608, 608,
125018
- /* 440 */ 542, 424, 402, 385, 241, 506, 451, 320, 211, 543,
125019
- /* 450 */ 164, 436, 386, 293, 451, 587, 108, 496, 111, 334,
125020
- /* 460 */ 391, 591, 424, 614, 27, 452, 453, 606, 606, 72,
125021
- /* 470 */ 257, 70, 259, 452, 339, 342, 564, 582, 68, 415,
125022
- /* 480 */ 469, 328, 327, 62, 614, 45, 110, 393, 89, 90,
125023
- /* 490 */ 80, 600, 599, 601, 601, 87, 87, 88, 88, 88,
125024
- /* 500 */ 88, 152, 86, 86, 86, 86, 85, 85, 84, 84,
125025
- /* 510 */ 84, 83, 330, 306, 110, 499, 520, 538, 402, 389,
125026
- /* 520 */ 424, 110, 566, 500, 593, 593, 454, 82, 79, 165,
125027
- /* 530 */ 424, 591, 384, 564, 340, 615, 188, 162, 424, 350,
125028
- /* 540 */ 616, 424, 614, 44, 606, 606, 445, 582, 300, 434,
125029
- /* 550 */ 151, 19, 614, 9, 568, 580, 348, 615, 469, 567,
125030
- /* 560 */ 614, 26, 616, 614, 45, 89, 90, 80, 600, 599,
125031
- /* 570 */ 601, 601, 87, 87, 88, 88, 88, 88, 411, 86,
125032
- /* 580 */ 86, 86, 86, 85, 85, 84, 84, 84, 83, 330,
125033
- /* 590 */ 306, 579, 110, 578, 521, 282, 433, 398, 400, 255,
125034
- /* 600 */ 486, 82, 79, 165, 487, 164, 82, 79, 165, 488,
125035
- /* 610 */ 488, 364, 387, 424, 544, 544, 509, 350, 362, 155,
125036
- /* 620 */ 191, 606, 606, 559, 642, 640, 333, 82, 79, 165,
125037
- /* 630 */ 305, 564, 507, 312, 357, 614, 45, 329, 596, 595,
125038
- /* 640 */ 194, 337, 89, 90, 80, 600, 599, 601, 601, 87,
125039
- /* 650 */ 87, 88, 88, 88, 88, 424, 86, 86, 86, 86,
125040
- /* 660 */ 85, 85, 84, 84, 84, 83, 330, 306, 20, 323,
125041
- /* 670 */ 150, 263, 211, 543, 421, 596, 595, 614, 22, 424,
125042
- /* 680 */ 193, 424, 284, 424, 391, 424, 509, 424, 577, 424,
125043
- /* 690 */ 186, 335, 424, 559, 424, 313, 120, 546, 606, 606,
125044
- /* 700 */ 67, 614, 47, 614, 50, 614, 48, 614, 100, 614,
125045
- /* 710 */ 99, 614, 101, 576, 614, 102, 614, 109, 326, 89,
125046
- /* 720 */ 90, 80, 600, 599, 601, 601, 87, 87, 88, 88,
125047
- /* 730 */ 88, 88, 424, 86, 86, 86, 86, 85, 85, 84,
125048
- /* 740 */ 84, 84, 83, 330, 306, 424, 311, 424, 585, 54,
125049
- /* 750 */ 424, 516, 517, 590, 614, 112, 424, 584, 424, 572,
125050
- /* 760 */ 424, 195, 424, 571, 424, 67, 424, 614, 94, 614,
125051
- /* 770 */ 98, 424, 614, 97, 264, 606, 606, 195, 614, 46,
125052
- /* 780 */ 614, 96, 614, 30, 614, 49, 614, 115, 614, 114,
125053
- /* 790 */ 418, 229, 388, 614, 113, 306, 89, 90, 80, 600,
125054
- /* 800 */ 599, 601, 601, 87, 87, 88, 88, 88, 88, 424,
125055
- /* 810 */ 86, 86, 86, 86, 85, 85, 84, 84, 84, 83,
125056
- /* 820 */ 330, 119, 424, 590, 110, 372, 606, 606, 195, 53,
125057
- /* 830 */ 250, 614, 29, 195, 472, 438, 729, 190, 302, 498,
125058
- /* 840 */ 14, 523, 641, 2, 614, 43, 306, 89, 90, 80,
125059
- /* 850 */ 600, 599, 601, 601, 87, 87, 88, 88, 88, 88,
125060
- /* 860 */ 424, 86, 86, 86, 86, 85, 85, 84, 84, 84,
125061
- /* 870 */ 83, 330, 424, 613, 964, 964, 354, 606, 606, 420,
125062
- /* 880 */ 312, 64, 614, 42, 391, 355, 283, 437, 301, 255,
125063
- /* 890 */ 414, 410, 495, 492, 614, 28, 471, 306, 89, 90,
125064
- /* 900 */ 80, 600, 599, 601, 601, 87, 87, 88, 88, 88,
125065
- /* 910 */ 88, 424, 86, 86, 86, 86, 85, 85, 84, 84,
125066
- /* 920 */ 84, 83, 330, 424, 110, 110, 110, 110, 606, 606,
125067
- /* 930 */ 110, 254, 13, 614, 41, 532, 531, 283, 481, 531,
125068
- /* 940 */ 457, 284, 119, 561, 356, 614, 40, 284, 306, 89,
125069
- /* 950 */ 78, 80, 600, 599, 601, 601, 87, 87, 88, 88,
125070
- /* 960 */ 88, 88, 424, 86, 86, 86, 86, 85, 85, 84,
125071
- /* 970 */ 84, 84, 83, 330, 110, 424, 341, 220, 555, 606,
125072
- /* 980 */ 606, 351, 555, 318, 614, 95, 413, 255, 83, 330,
125073
- /* 990 */ 284, 284, 255, 640, 333, 356, 255, 614, 39, 306,
125074
- /* 1000 */ 356, 90, 80, 600, 599, 601, 601, 87, 87, 88,
125075
- /* 1010 */ 88, 88, 88, 424, 86, 86, 86, 86, 85, 85,
125076
- /* 1020 */ 84, 84, 84, 83, 330, 424, 317, 316, 141, 465,
125077
- /* 1030 */ 606, 606, 219, 619, 463, 614, 10, 417, 462, 255,
125078
- /* 1040 */ 189, 510, 553, 351, 207, 363, 161, 614, 38, 315,
125079
- /* 1050 */ 218, 255, 255, 80, 600, 599, 601, 601, 87, 87,
125080
- /* 1060 */ 88, 88, 88, 88, 424, 86, 86, 86, 86, 85,
125081
- /* 1070 */ 85, 84, 84, 84, 83, 330, 76, 419, 255, 3,
125082
- /* 1080 */ 878, 461, 424, 247, 331, 331, 614, 37, 217, 76,
125083
- /* 1090 */ 419, 390, 3, 216, 215, 422, 4, 331, 331, 424,
125084
- /* 1100 */ 547, 12, 424, 545, 614, 36, 424, 541, 422, 424,
125085
- /* 1110 */ 540, 424, 214, 424, 408, 424, 539, 403, 605, 605,
125086
- /* 1120 */ 237, 614, 25, 119, 614, 24, 588, 408, 614, 45,
125087
- /* 1130 */ 118, 614, 35, 614, 34, 614, 33, 614, 23, 588,
125088
- /* 1140 */ 60, 223, 603, 602, 513, 378, 73, 74, 140, 139,
125089
- /* 1150 */ 424, 110, 265, 75, 426, 425, 59, 424, 610, 73,
125090
- /* 1160 */ 74, 549, 402, 404, 424, 373, 75, 426, 425, 604,
125091
- /* 1170 */ 138, 610, 614, 11, 392, 76, 419, 181, 3, 614,
125092
- /* 1180 */ 32, 271, 369, 331, 331, 493, 614, 31, 149, 608,
125093
- /* 1190 */ 608, 608, 607, 15, 422, 365, 614, 8, 137, 489,
125094
- /* 1200 */ 136, 190, 608, 608, 608, 607, 15, 485, 176, 135,
125095
- /* 1210 */ 7, 252, 477, 408, 174, 133, 175, 474, 57, 56,
125096
- /* 1220 */ 132, 130, 119, 76, 419, 588, 3, 468, 245, 464,
125097
- /* 1230 */ 171, 331, 331, 125, 123, 456, 447, 122, 446, 104,
125098
- /* 1240 */ 336, 231, 422, 166, 154, 73, 74, 332, 116, 431,
125099
- /* 1250 */ 121, 309, 75, 426, 425, 222, 106, 610, 308, 637,
125100
- /* 1260 */ 204, 408, 629, 627, 628, 6, 200, 428, 427, 290,
125101
- /* 1270 */ 203, 622, 201, 588, 62, 63, 289, 66, 419, 399,
125102
- /* 1280 */ 3, 401, 288, 92, 143, 331, 331, 287, 608, 608,
125103
- /* 1290 */ 608, 607, 15, 73, 74, 227, 422, 325, 69, 416,
125104
- /* 1300 */ 75, 426, 425, 612, 412, 610, 192, 61, 569, 209,
125105
- /* 1310 */ 396, 226, 278, 225, 383, 408, 527, 558, 276, 533,
125106
- /* 1320 */ 552, 528, 321, 523, 370, 508, 180, 588, 494, 179,
125107
- /* 1330 */ 366, 117, 253, 269, 522, 503, 608, 608, 608, 607,
125108
- /* 1340 */ 15, 551, 502, 58, 274, 524, 178, 73, 74, 304,
125109
- /* 1350 */ 501, 368, 303, 206, 75, 426, 425, 491, 360, 610,
125110
- /* 1360 */ 213, 177, 483, 131, 345, 298, 297, 296, 202, 294,
125111
- /* 1370 */ 480, 490, 466, 134, 172, 129, 444, 346, 470, 128,
125112
- /* 1380 */ 314, 459, 103, 127, 126, 148, 124, 167, 443, 235,
125113
- /* 1390 */ 608, 608, 608, 607, 15, 442, 439, 623, 234, 299,
125114
- /* 1400 */ 145, 583, 291, 377, 581, 160, 119, 156, 270, 636,
125115
- /* 1410 */ 971, 169, 279, 626, 520, 625, 473, 624, 170, 621,
125116
- /* 1420 */ 618, 119, 168, 55, 409, 423, 537, 609, 286, 285,
125117
- /* 1430 */ 405, 570, 560, 556, 5, 52, 458, 554, 147, 267,
125118
- /* 1440 */ 519, 504, 518, 406, 262, 239, 260, 512, 343, 511,
125119
- /* 1450 */ 258, 353, 565, 256, 224, 251, 359, 277, 275, 476,
125120
- /* 1460 */ 475, 246, 352, 244, 467, 455, 236, 233, 232, 307,
125121
- /* 1470 */ 441, 281, 205, 163, 397, 280, 535, 505, 330, 617,
125122
- /* 1480 */ 971, 971, 971, 971, 367, 971, 971, 971, 971, 971,
125123
- /* 1490 */ 971, 971, 971, 971, 971, 971, 338,
125442
+ /* 0 */ 311, 1306, 145, 651, 2, 192, 652, 338, 780, 92,
125443
+ /* 10 */ 92, 92, 92, 85, 90, 90, 90, 90, 89, 89,
125444
+ /* 20 */ 88, 88, 88, 87, 335, 88, 88, 88, 87, 335,
125445
+ /* 30 */ 327, 856, 856, 92, 92, 92, 92, 776, 90, 90,
125446
+ /* 40 */ 90, 90, 89, 89, 88, 88, 88, 87, 335, 86,
125447
+ /* 50 */ 83, 166, 93, 94, 84, 868, 871, 860, 860, 91,
125448
+ /* 60 */ 91, 92, 92, 92, 92, 335, 90, 90, 90, 90,
125449
+ /* 70 */ 89, 89, 88, 88, 88, 87, 335, 311, 780, 90,
125450
+ /* 80 */ 90, 90, 90, 89, 89, 88, 88, 88, 87, 335,
125451
+ /* 90 */ 123, 808, 689, 689, 689, 689, 112, 230, 430, 257,
125452
+ /* 100 */ 809, 698, 430, 86, 83, 166, 324, 55, 856, 856,
125453
+ /* 110 */ 201, 158, 276, 387, 271, 386, 188, 689, 689, 828,
125454
+ /* 120 */ 833, 49, 944, 269, 833, 49, 123, 87, 335, 93,
125455
+ /* 130 */ 94, 84, 868, 871, 860, 860, 91, 91, 92, 92,
125456
+ /* 140 */ 92, 92, 342, 90, 90, 90, 90, 89, 89, 88,
125457
+ /* 150 */ 88, 88, 87, 335, 311, 328, 333, 332, 701, 408,
125458
+ /* 160 */ 394, 69, 690, 691, 690, 691, 715, 910, 251, 354,
125459
+ /* 170 */ 250, 698, 704, 430, 908, 430, 909, 89, 89, 88,
125460
+ /* 180 */ 88, 88, 87, 335, 391, 856, 856, 690, 691, 183,
125461
+ /* 190 */ 95, 340, 384, 381, 380, 833, 31, 833, 49, 912,
125462
+ /* 200 */ 912, 333, 332, 379, 123, 311, 93, 94, 84, 868,
125463
+ /* 210 */ 871, 860, 860, 91, 91, 92, 92, 92, 92, 114,
125464
+ /* 220 */ 90, 90, 90, 90, 89, 89, 88, 88, 88, 87,
125465
+ /* 230 */ 335, 430, 408, 399, 435, 657, 856, 856, 346, 57,
125466
+ /* 240 */ 232, 828, 109, 20, 912, 912, 231, 393, 937, 760,
125467
+ /* 250 */ 97, 751, 752, 833, 49, 708, 708, 93, 94, 84,
125468
+ /* 260 */ 868, 871, 860, 860, 91, 91, 92, 92, 92, 92,
125469
+ /* 270 */ 707, 90, 90, 90, 90, 89, 89, 88, 88, 88,
125470
+ /* 280 */ 87, 335, 311, 114, 22, 706, 688, 58, 408, 390,
125471
+ /* 290 */ 251, 349, 240, 749, 752, 689, 689, 847, 685, 115,
125472
+ /* 300 */ 21, 231, 393, 689, 689, 697, 183, 355, 430, 384,
125473
+ /* 310 */ 381, 380, 192, 856, 856, 780, 123, 160, 159, 223,
125474
+ /* 320 */ 379, 738, 25, 315, 362, 841, 143, 689, 689, 835,
125475
+ /* 330 */ 833, 48, 339, 937, 93, 94, 84, 868, 871, 860,
125476
+ /* 340 */ 860, 91, 91, 92, 92, 92, 92, 914, 90, 90,
125477
+ /* 350 */ 90, 90, 89, 89, 88, 88, 88, 87, 335, 311,
125478
+ /* 360 */ 840, 840, 840, 266, 430, 690, 691, 778, 114, 1300,
125479
+ /* 370 */ 1300, 430, 1, 690, 691, 697, 688, 689, 689, 689,
125480
+ /* 380 */ 689, 689, 689, 287, 298, 780, 833, 10, 686, 115,
125481
+ /* 390 */ 856, 856, 355, 833, 10, 828, 366, 690, 691, 363,
125482
+ /* 400 */ 321, 76, 123, 74, 23, 737, 807, 323, 356, 353,
125483
+ /* 410 */ 847, 93, 94, 84, 868, 871, 860, 860, 91, 91,
125484
+ /* 420 */ 92, 92, 92, 92, 940, 90, 90, 90, 90, 89,
125485
+ /* 430 */ 89, 88, 88, 88, 87, 335, 311, 806, 841, 429,
125486
+ /* 440 */ 713, 941, 835, 430, 251, 354, 250, 690, 691, 690,
125487
+ /* 450 */ 691, 690, 691, 86, 83, 166, 24, 942, 151, 753,
125488
+ /* 460 */ 285, 907, 403, 907, 164, 833, 10, 856, 856, 965,
125489
+ /* 470 */ 306, 754, 679, 840, 840, 840, 795, 216, 794, 222,
125490
+ /* 480 */ 906, 344, 906, 904, 86, 83, 166, 286, 93, 94,
125491
+ /* 490 */ 84, 868, 871, 860, 860, 91, 91, 92, 92, 92,
125492
+ /* 500 */ 92, 430, 90, 90, 90, 90, 89, 89, 88, 88,
125493
+ /* 510 */ 88, 87, 335, 311, 430, 724, 352, 705, 427, 699,
125494
+ /* 520 */ 700, 376, 210, 833, 49, 793, 397, 857, 857, 940,
125495
+ /* 530 */ 213, 762, 727, 334, 699, 700, 833, 10, 86, 83,
125496
+ /* 540 */ 166, 345, 396, 902, 856, 856, 941, 385, 833, 9,
125497
+ /* 550 */ 406, 869, 872, 187, 890, 728, 347, 398, 404, 977,
125498
+ /* 560 */ 652, 338, 942, 954, 413, 93, 94, 84, 868, 871,
125499
+ /* 570 */ 860, 860, 91, 91, 92, 92, 92, 92, 861, 90,
125500
+ /* 580 */ 90, 90, 90, 89, 89, 88, 88, 88, 87, 335,
125501
+ /* 590 */ 311, 1219, 114, 430, 834, 430, 5, 165, 192, 688,
125502
+ /* 600 */ 832, 780, 430, 723, 430, 234, 325, 189, 163, 316,
125503
+ /* 610 */ 356, 955, 115, 235, 269, 833, 35, 833, 36, 747,
125504
+ /* 620 */ 720, 856, 856, 793, 833, 12, 833, 27, 745, 174,
125505
+ /* 630 */ 968, 1290, 968, 1291, 1290, 310, 1291, 693, 317, 245,
125506
+ /* 640 */ 264, 311, 93, 94, 84, 868, 871, 860, 860, 91,
125507
+ /* 650 */ 91, 92, 92, 92, 92, 832, 90, 90, 90, 90,
125508
+ /* 660 */ 89, 89, 88, 88, 88, 87, 335, 430, 320, 213,
125509
+ /* 670 */ 762, 780, 856, 856, 920, 920, 369, 257, 966, 220,
125510
+ /* 680 */ 966, 396, 663, 664, 665, 242, 259, 244, 262, 833,
125511
+ /* 690 */ 37, 650, 2, 93, 94, 84, 868, 871, 860, 860,
125512
+ /* 700 */ 91, 91, 92, 92, 92, 92, 430, 90, 90, 90,
125513
+ /* 710 */ 90, 89, 89, 88, 88, 88, 87, 335, 311, 430,
125514
+ /* 720 */ 239, 430, 917, 368, 430, 238, 916, 793, 833, 38,
125515
+ /* 730 */ 430, 825, 430, 66, 430, 392, 430, 766, 766, 430,
125516
+ /* 740 */ 367, 833, 39, 833, 28, 430, 833, 29, 68, 856,
125517
+ /* 750 */ 856, 900, 833, 40, 833, 41, 833, 42, 833, 11,
125518
+ /* 760 */ 72, 833, 43, 243, 305, 970, 114, 833, 99, 961,
125519
+ /* 770 */ 93, 94, 84, 868, 871, 860, 860, 91, 91, 92,
125520
+ /* 780 */ 92, 92, 92, 430, 90, 90, 90, 90, 89, 89,
125521
+ /* 790 */ 88, 88, 88, 87, 335, 311, 430, 361, 430, 165,
125522
+ /* 800 */ 147, 430, 186, 185, 184, 833, 44, 430, 289, 430,
125523
+ /* 810 */ 246, 430, 971, 430, 212, 163, 430, 357, 833, 45,
125524
+ /* 820 */ 833, 32, 932, 833, 46, 793, 856, 856, 718, 833,
125525
+ /* 830 */ 47, 833, 33, 833, 117, 833, 118, 75, 833, 119,
125526
+ /* 840 */ 288, 305, 967, 214, 935, 322, 311, 93, 94, 84,
125527
+ /* 850 */ 868, 871, 860, 860, 91, 91, 92, 92, 92, 92,
125528
+ /* 860 */ 430, 90, 90, 90, 90, 89, 89, 88, 88, 88,
125529
+ /* 870 */ 87, 335, 430, 832, 426, 317, 288, 856, 856, 114,
125530
+ /* 880 */ 763, 257, 833, 53, 930, 219, 364, 257, 257, 971,
125531
+ /* 890 */ 361, 396, 257, 257, 833, 34, 257, 311, 93, 94,
125532
+ /* 900 */ 84, 868, 871, 860, 860, 91, 91, 92, 92, 92,
125533
+ /* 910 */ 92, 430, 90, 90, 90, 90, 89, 89, 88, 88,
125534
+ /* 920 */ 88, 87, 335, 430, 217, 318, 124, 253, 856, 856,
125535
+ /* 930 */ 218, 943, 257, 833, 100, 898, 759, 774, 361, 755,
125536
+ /* 940 */ 423, 329, 758, 1017, 289, 833, 50, 682, 311, 93,
125537
+ /* 950 */ 82, 84, 868, 871, 860, 860, 91, 91, 92, 92,
125538
+ /* 960 */ 92, 92, 430, 90, 90, 90, 90, 89, 89, 88,
125539
+ /* 970 */ 88, 88, 87, 335, 430, 256, 419, 114, 249, 856,
125540
+ /* 980 */ 856, 331, 114, 400, 833, 101, 359, 187, 1064, 726,
125541
+ /* 990 */ 725, 739, 401, 416, 420, 360, 833, 102, 424, 311,
125542
+ /* 1000 */ 258, 94, 84, 868, 871, 860, 860, 91, 91, 92,
125543
+ /* 1010 */ 92, 92, 92, 430, 90, 90, 90, 90, 89, 89,
125544
+ /* 1020 */ 88, 88, 88, 87, 335, 430, 221, 261, 114, 114,
125545
+ /* 1030 */ 856, 856, 808, 114, 156, 833, 98, 772, 733, 734,
125546
+ /* 1040 */ 275, 809, 771, 316, 263, 265, 960, 833, 116, 307,
125547
+ /* 1050 */ 741, 274, 722, 84, 868, 871, 860, 860, 91, 91,
125548
+ /* 1060 */ 92, 92, 92, 92, 430, 90, 90, 90, 90, 89,
125549
+ /* 1070 */ 89, 88, 88, 88, 87, 335, 80, 425, 830, 3,
125550
+ /* 1080 */ 1214, 191, 430, 721, 336, 336, 833, 113, 252, 80,
125551
+ /* 1090 */ 425, 68, 3, 913, 913, 428, 270, 336, 336, 430,
125552
+ /* 1100 */ 377, 784, 430, 197, 833, 106, 430, 716, 428, 430,
125553
+ /* 1110 */ 267, 430, 897, 68, 414, 430, 769, 409, 430, 71,
125554
+ /* 1120 */ 430, 833, 105, 123, 833, 103, 847, 414, 833, 49,
125555
+ /* 1130 */ 843, 833, 104, 833, 52, 800, 123, 833, 54, 847,
125556
+ /* 1140 */ 833, 51, 833, 26, 831, 802, 77, 78, 191, 389,
125557
+ /* 1150 */ 430, 372, 114, 79, 432, 431, 911, 911, 835, 77,
125558
+ /* 1160 */ 78, 779, 893, 408, 410, 197, 79, 432, 431, 791,
125559
+ /* 1170 */ 226, 835, 833, 30, 772, 80, 425, 716, 3, 771,
125560
+ /* 1180 */ 411, 412, 897, 336, 336, 290, 291, 839, 703, 840,
125561
+ /* 1190 */ 840, 840, 842, 19, 428, 695, 684, 672, 111, 671,
125562
+ /* 1200 */ 843, 673, 840, 840, 840, 842, 19, 207, 661, 278,
125563
+ /* 1210 */ 148, 304, 280, 414, 282, 6, 822, 348, 248, 241,
125564
+ /* 1220 */ 358, 934, 720, 80, 425, 847, 3, 161, 382, 273,
125565
+ /* 1230 */ 284, 336, 336, 415, 296, 958, 895, 894, 157, 674,
125566
+ /* 1240 */ 107, 194, 428, 948, 135, 77, 78, 777, 953, 951,
125567
+ /* 1250 */ 56, 319, 79, 432, 431, 121, 66, 835, 59, 128,
125568
+ /* 1260 */ 146, 414, 350, 130, 351, 819, 131, 132, 133, 375,
125569
+ /* 1270 */ 173, 149, 138, 847, 936, 365, 178, 70, 425, 827,
125570
+ /* 1280 */ 3, 889, 62, 371, 915, 336, 336, 792, 840, 840,
125571
+ /* 1290 */ 840, 842, 19, 77, 78, 208, 428, 144, 179, 373,
125572
+ /* 1300 */ 79, 432, 431, 255, 180, 835, 260, 675, 181, 308,
125573
+ /* 1310 */ 388, 744, 326, 743, 742, 414, 731, 718, 712, 402,
125574
+ /* 1320 */ 309, 711, 788, 65, 277, 272, 789, 847, 730, 710,
125575
+ /* 1330 */ 709, 279, 193, 787, 281, 876, 840, 840, 840, 842,
125576
+ /* 1340 */ 19, 786, 283, 73, 418, 330, 422, 77, 78, 227,
125577
+ /* 1350 */ 96, 407, 67, 405, 79, 432, 431, 292, 228, 835,
125578
+ /* 1360 */ 215, 202, 229, 293, 767, 303, 302, 301, 204, 299,
125579
+ /* 1370 */ 294, 295, 676, 7, 681, 433, 669, 206, 110, 224,
125580
+ /* 1380 */ 203, 205, 434, 667, 666, 658, 120, 168, 656, 237,
125581
+ /* 1390 */ 840, 840, 840, 842, 19, 337, 155, 233, 236, 341,
125582
+ /* 1400 */ 167, 905, 108, 313, 903, 826, 314, 125, 126, 127,
125583
+ /* 1410 */ 129, 170, 247, 756, 172, 928, 134, 136, 171, 60,
125584
+ /* 1420 */ 61, 123, 169, 137, 175, 933, 176, 927, 8, 13,
125585
+ /* 1430 */ 177, 254, 191, 918, 139, 370, 924, 140, 678, 150,
125586
+ /* 1440 */ 374, 274, 182, 378, 141, 122, 63, 14, 383, 729,
125587
+ /* 1450 */ 268, 15, 64, 225, 846, 845, 874, 16, 765, 770,
125588
+ /* 1460 */ 4, 162, 209, 395, 211, 142, 878, 796, 801, 312,
125589
+ /* 1470 */ 190, 71, 68, 875, 873, 939, 199, 938, 17, 195,
125590
+ /* 1480 */ 18, 196, 417, 975, 152, 653, 976, 198, 153, 421,
125591
+ /* 1490 */ 877, 154, 200, 844, 696, 81, 343, 297, 1019, 1018,
125592
+ /* 1500 */ 300,
125124125593
};
125125125594
static const YYCODETYPE yy_lookahead[] = {
125126
- /* 0 */ 19, 22, 22, 23, 1, 24, 26, 15, 27, 80,
125595
+ /* 0 */ 19, 144, 145, 146, 147, 24, 1, 2, 27, 80,
125127125596
/* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
125128
- /* 20 */ 91, 92, 93, 94, 95, 108, 109, 110, 27, 28,
125129
- /* 30 */ 23, 50, 51, 80, 81, 82, 83, 122, 85, 86,
125130
- /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 22,
125131
- /* 50 */ 70, 23, 71, 72, 73, 74, 75, 76, 77, 78,
125132
- /* 60 */ 79, 80, 81, 82, 83, 122, 85, 86, 87, 88,
125133
- /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 91,
125134
- /* 80 */ 92, 93, 94, 95, 26, 85, 86, 87, 88, 89,
125135
- /* 90 */ 90, 91, 92, 93, 94, 95, 27, 28, 97, 98,
125136
- /* 100 */ 99, 122, 211, 102, 103, 104, 79, 19, 50, 51,
125137
- /* 110 */ 19, 122, 59, 55, 113, 224, 225, 226, 89, 90,
125138
- /* 120 */ 91, 92, 93, 94, 95, 23, 27, 28, 26, 71,
125597
+ /* 20 */ 91, 92, 93, 94, 95, 91, 92, 93, 94, 95,
125598
+ /* 30 */ 19, 50, 51, 80, 81, 82, 83, 212, 85, 86,
125599
+ /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 224,
125600
+ /* 50 */ 225, 226, 71, 72, 73, 74, 75, 76, 77, 78,
125601
+ /* 60 */ 79, 80, 81, 82, 83, 95, 85, 86, 87, 88,
125602
+ /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 85,
125603
+ /* 80 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
125604
+ /* 90 */ 66, 33, 27, 28, 27, 28, 22, 201, 152, 152,
125605
+ /* 100 */ 42, 27, 152, 224, 225, 226, 95, 211, 50, 51,
125606
+ /* 110 */ 99, 100, 101, 102, 103, 104, 105, 27, 28, 59,
125607
+ /* 120 */ 174, 175, 243, 112, 174, 175, 66, 94, 95, 71,
125139125608
/* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125140
- /* 140 */ 82, 83, 51, 85, 86, 87, 88, 89, 90, 91,
125141
- /* 150 */ 92, 93, 94, 95, 19, 132, 133, 58, 89, 90,
125142
- /* 160 */ 21, 108, 109, 110, 27, 28, 97, 98, 33, 100,
125143
- /* 170 */ 7, 8, 119, 120, 22, 19, 107, 42, 109, 27,
125144
- /* 180 */ 28, 27, 28, 95, 28, 50, 51, 99, 100, 101,
125145
- /* 190 */ 102, 103, 104, 105, 27, 28, 97, 98, 107, 152,
125146
- /* 200 */ 112, 132, 133, 112, 65, 69, 71, 72, 73, 74,
125147
- /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 11,
125609
+ /* 140 */ 82, 83, 195, 85, 86, 87, 88, 89, 90, 91,
125610
+ /* 150 */ 92, 93, 94, 95, 19, 209, 89, 90, 173, 209,
125611
+ /* 160 */ 210, 26, 97, 98, 97, 98, 181, 100, 108, 109,
125612
+ /* 170 */ 110, 97, 174, 152, 107, 152, 109, 89, 90, 91,
125613
+ /* 180 */ 92, 93, 94, 95, 163, 50, 51, 97, 98, 99,
125614
+ /* 190 */ 55, 244, 102, 103, 104, 174, 175, 174, 175, 132,
125615
+ /* 200 */ 133, 89, 90, 113, 66, 19, 71, 72, 73, 74,
125616
+ /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 198,
125148125617
/* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
125149
- /* 230 */ 95, 19, 101, 97, 97, 98, 24, 101, 122, 157,
125150
- /* 240 */ 12, 99, 103, 112, 102, 103, 104, 152, 22, 97,
125151
- /* 250 */ 98, 97, 98, 27, 28, 113, 27, 29, 91, 164,
125152
- /* 260 */ 165, 124, 50, 51, 97, 98, 219, 59, 132, 133,
125153
- /* 270 */ 134, 22, 23, 45, 66, 47, 212, 213, 124, 140,
125154
- /* 280 */ 132, 133, 19, 71, 72, 73, 74, 75, 76, 77,
125155
- /* 290 */ 78, 79, 80, 81, 82, 83, 152, 85, 86, 87,
125156
- /* 300 */ 88, 89, 90, 91, 92, 93, 94, 95, 164, 165,
125157
- /* 310 */ 27, 28, 230, 50, 51, 233, 108, 109, 110, 70,
125158
- /* 320 */ 16, 59, 23, 97, 98, 26, 97, 22, 66, 185,
125159
- /* 330 */ 12, 187, 27, 28, 71, 72, 73, 74, 75, 76,
125160
- /* 340 */ 77, 78, 79, 80, 81, 82, 83, 29, 85, 86,
125618
+ /* 230 */ 95, 152, 209, 210, 148, 149, 50, 51, 100, 53,
125619
+ /* 240 */ 154, 59, 156, 22, 132, 133, 119, 120, 163, 163,
125620
+ /* 250 */ 22, 192, 193, 174, 175, 27, 28, 71, 72, 73,
125621
+ /* 260 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
125622
+ /* 270 */ 174, 85, 86, 87, 88, 89, 90, 91, 92, 93,
125623
+ /* 280 */ 94, 95, 19, 198, 198, 174, 152, 24, 209, 210,
125624
+ /* 290 */ 108, 109, 110, 192, 193, 27, 28, 69, 164, 165,
125625
+ /* 300 */ 79, 119, 120, 27, 28, 27, 99, 222, 152, 102,
125626
+ /* 310 */ 103, 104, 24, 50, 51, 27, 66, 89, 90, 185,
125627
+ /* 320 */ 113, 187, 22, 157, 239, 97, 58, 27, 28, 101,
125628
+ /* 330 */ 174, 175, 246, 163, 71, 72, 73, 74, 75, 76,
125629
+ /* 340 */ 77, 78, 79, 80, 81, 82, 83, 11, 85, 86,
125161125630
/* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19,
125162
- /* 360 */ 22, 148, 149, 45, 23, 47, 62, 154, 64, 156,
125163
- /* 370 */ 108, 109, 110, 37, 69, 23, 163, 59, 26, 26,
125164
- /* 380 */ 97, 98, 144, 145, 146, 147, 152, 200, 52, 23,
125165
- /* 390 */ 50, 51, 26, 22, 89, 90, 60, 210, 7, 8,
125166
- /* 400 */ 9, 138, 97, 22, 23, 26, 101, 26, 174, 175,
125167
- /* 410 */ 197, 71, 72, 73, 74, 75, 76, 77, 78, 79,
125168
- /* 420 */ 80, 81, 82, 83, 16, 85, 86, 87, 88, 89,
125169
- /* 430 */ 90, 91, 92, 93, 94, 95, 19, 132, 133, 134,
125170
- /* 440 */ 23, 152, 208, 209, 140, 152, 152, 111, 195, 196,
125171
- /* 450 */ 98, 70, 163, 160, 152, 23, 22, 164, 165, 246,
125172
- /* 460 */ 207, 27, 152, 174, 175, 171, 172, 50, 51, 137,
125173
- /* 470 */ 62, 139, 64, 171, 172, 222, 124, 27, 138, 24,
125174
- /* 480 */ 163, 89, 90, 130, 174, 175, 197, 163, 71, 72,
125631
+ /* 360 */ 132, 133, 134, 23, 152, 97, 98, 91, 198, 119,
125632
+ /* 370 */ 120, 152, 22, 97, 98, 97, 152, 27, 28, 27,
125633
+ /* 380 */ 28, 27, 28, 227, 160, 97, 174, 175, 164, 165,
125634
+ /* 390 */ 50, 51, 222, 174, 175, 59, 230, 97, 98, 233,
125635
+ /* 400 */ 188, 137, 66, 139, 234, 187, 177, 188, 152, 239,
125636
+ /* 410 */ 69, 71, 72, 73, 74, 75, 76, 77, 78, 79,
125637
+ /* 420 */ 80, 81, 82, 83, 12, 85, 86, 87, 88, 89,
125638
+ /* 430 */ 90, 91, 92, 93, 94, 95, 19, 177, 97, 152,
125639
+ /* 440 */ 23, 29, 101, 152, 108, 109, 110, 97, 98, 97,
125640
+ /* 450 */ 98, 97, 98, 224, 225, 226, 22, 45, 24, 47,
125641
+ /* 460 */ 152, 152, 152, 152, 152, 174, 175, 50, 51, 249,
125642
+ /* 470 */ 250, 59, 21, 132, 133, 134, 124, 221, 124, 188,
125643
+ /* 480 */ 171, 172, 171, 172, 224, 225, 226, 152, 71, 72,
125175125644
/* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
125176
- /* 500 */ 83, 22, 85, 86, 87, 88, 89, 90, 91, 92,
125177
- /* 510 */ 93, 94, 95, 19, 197, 181, 182, 23, 208, 209,
125178
- /* 520 */ 152, 197, 26, 189, 132, 133, 232, 224, 225, 226,
125179
- /* 530 */ 152, 97, 91, 26, 232, 116, 212, 213, 152, 222,
125180
- /* 540 */ 121, 152, 174, 175, 50, 51, 243, 97, 22, 23,
125181
- /* 550 */ 22, 234, 174, 175, 177, 23, 239, 116, 163, 177,
125182
- /* 560 */ 174, 175, 121, 174, 175, 71, 72, 73, 74, 75,
125183
- /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 24, 85,
125645
+ /* 500 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
125646
+ /* 510 */ 93, 94, 95, 19, 152, 183, 65, 23, 170, 171,
125647
+ /* 520 */ 172, 19, 23, 174, 175, 26, 152, 50, 51, 12,
125648
+ /* 530 */ 196, 197, 37, 170, 171, 172, 174, 175, 224, 225,
125649
+ /* 540 */ 226, 232, 208, 232, 50, 51, 29, 52, 174, 175,
125650
+ /* 550 */ 188, 74, 75, 51, 103, 60, 222, 163, 209, 0,
125651
+ /* 560 */ 1, 2, 45, 152, 47, 71, 72, 73, 74, 75,
125652
+ /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 101, 85,
125184125653
/* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
125185
- /* 590 */ 19, 23, 197, 11, 23, 227, 70, 208, 220, 152,
125186
- /* 600 */ 31, 224, 225, 226, 35, 98, 224, 225, 226, 108,
125187
- /* 610 */ 109, 110, 115, 152, 117, 118, 27, 222, 49, 123,
125188
- /* 620 */ 24, 50, 51, 27, 0, 1, 2, 224, 225, 226,
125189
- /* 630 */ 166, 124, 168, 169, 239, 174, 175, 170, 171, 172,
125190
- /* 640 */ 22, 194, 71, 72, 73, 74, 75, 76, 77, 78,
125654
+ /* 590 */ 19, 140, 198, 152, 23, 152, 22, 98, 24, 152,
125655
+ /* 600 */ 152, 27, 152, 183, 152, 152, 111, 213, 214, 107,
125656
+ /* 610 */ 152, 164, 165, 152, 112, 174, 175, 174, 175, 181,
125657
+ /* 620 */ 182, 50, 51, 124, 174, 175, 174, 175, 190, 26,
125658
+ /* 630 */ 22, 23, 22, 23, 26, 166, 26, 168, 169, 16,
125659
+ /* 640 */ 16, 19, 71, 72, 73, 74, 75, 76, 77, 78,
125191125660
/* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88,
125192
- /* 660 */ 89, 90, 91, 92, 93, 94, 95, 19, 22, 208,
125193
- /* 670 */ 24, 23, 195, 196, 170, 171, 172, 174, 175, 152,
125194
- /* 680 */ 26, 152, 152, 152, 207, 152, 97, 152, 23, 152,
125195
- /* 690 */ 51, 244, 152, 97, 152, 247, 248, 23, 50, 51,
125196
- /* 700 */ 26, 174, 175, 174, 175, 174, 175, 174, 175, 174,
125197
- /* 710 */ 175, 174, 175, 23, 174, 175, 174, 175, 188, 71,
125198
- /* 720 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125199
- /* 730 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
125200
- /* 740 */ 92, 93, 94, 95, 19, 152, 107, 152, 33, 24,
125201
- /* 750 */ 152, 100, 101, 27, 174, 175, 152, 42, 152, 23,
125202
- /* 760 */ 152, 26, 152, 23, 152, 26, 152, 174, 175, 174,
125203
- /* 770 */ 175, 152, 174, 175, 23, 50, 51, 26, 174, 175,
125204
- /* 780 */ 174, 175, 174, 175, 174, 175, 174, 175, 174, 175,
125205
- /* 790 */ 163, 119, 120, 174, 175, 19, 71, 72, 73, 74,
125206
- /* 800 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 152,
125207
- /* 810 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
125208
- /* 820 */ 95, 66, 152, 97, 197, 23, 50, 51, 26, 53,
125209
- /* 830 */ 23, 174, 175, 26, 23, 23, 23, 26, 26, 26,
125210
- /* 840 */ 36, 106, 146, 147, 174, 175, 19, 71, 72, 73,
125661
+ /* 660 */ 89, 90, 91, 92, 93, 94, 95, 152, 220, 196,
125662
+ /* 670 */ 197, 97, 50, 51, 108, 109, 110, 152, 70, 221,
125663
+ /* 680 */ 70, 208, 7, 8, 9, 62, 62, 64, 64, 174,
125664
+ /* 690 */ 175, 146, 147, 71, 72, 73, 74, 75, 76, 77,
125665
+ /* 700 */ 78, 79, 80, 81, 82, 83, 152, 85, 86, 87,
125666
+ /* 710 */ 88, 89, 90, 91, 92, 93, 94, 95, 19, 152,
125667
+ /* 720 */ 195, 152, 31, 220, 152, 152, 35, 26, 174, 175,
125668
+ /* 730 */ 152, 163, 152, 130, 152, 115, 152, 117, 118, 152,
125669
+ /* 740 */ 49, 174, 175, 174, 175, 152, 174, 175, 26, 50,
125670
+ /* 750 */ 51, 152, 174, 175, 174, 175, 174, 175, 174, 175,
125671
+ /* 760 */ 138, 174, 175, 140, 22, 23, 198, 174, 175, 152,
125672
+ /* 770 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
125673
+ /* 780 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
125674
+ /* 790 */ 91, 92, 93, 94, 95, 19, 152, 152, 152, 98,
125675
+ /* 800 */ 24, 152, 108, 109, 110, 174, 175, 152, 152, 152,
125676
+ /* 810 */ 152, 152, 70, 152, 213, 214, 152, 152, 174, 175,
125677
+ /* 820 */ 174, 175, 152, 174, 175, 124, 50, 51, 106, 174,
125678
+ /* 830 */ 175, 174, 175, 174, 175, 174, 175, 138, 174, 175,
125679
+ /* 840 */ 152, 22, 23, 22, 163, 189, 19, 71, 72, 73,
125211125680
/* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
125212125681
/* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
125213
- /* 870 */ 94, 95, 152, 196, 119, 120, 19, 50, 51, 168,
125214
- /* 880 */ 169, 26, 174, 175, 207, 28, 152, 249, 250, 152,
125215
- /* 890 */ 163, 163, 163, 163, 174, 175, 163, 19, 71, 72,
125682
+ /* 870 */ 94, 95, 152, 152, 168, 169, 152, 50, 51, 198,
125683
+ /* 880 */ 197, 152, 174, 175, 152, 240, 152, 152, 152, 70,
125684
+ /* 890 */ 152, 208, 152, 152, 174, 175, 152, 19, 71, 72,
125216125685
/* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
125217125686
/* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
125218
- /* 920 */ 93, 94, 95, 152, 197, 197, 197, 197, 50, 51,
125219
- /* 930 */ 197, 194, 36, 174, 175, 191, 192, 152, 191, 192,
125220
- /* 940 */ 163, 152, 66, 124, 152, 174, 175, 152, 19, 71,
125687
+ /* 920 */ 93, 94, 95, 152, 195, 247, 248, 152, 50, 51,
125688
+ /* 930 */ 195, 195, 152, 174, 175, 195, 195, 26, 152, 195,
125689
+ /* 940 */ 252, 220, 163, 122, 152, 174, 175, 163, 19, 71,
125221125690
/* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125222125691
/* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
125223
- /* 970 */ 92, 93, 94, 95, 197, 152, 100, 188, 152, 50,
125224
- /* 980 */ 51, 152, 152, 188, 174, 175, 252, 152, 94, 95,
125225
- /* 990 */ 152, 152, 152, 1, 2, 152, 152, 174, 175, 19,
125692
+ /* 970 */ 92, 93, 94, 95, 152, 195, 252, 198, 240, 50,
125693
+ /* 980 */ 51, 189, 198, 19, 174, 175, 19, 51, 23, 100,
125694
+ /* 990 */ 101, 26, 28, 163, 163, 28, 174, 175, 163, 19,
125226125695
/* 1000 */ 152, 72, 73, 74, 75, 76, 77, 78, 79, 80,
125227125696
/* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
125228
- /* 1020 */ 91, 92, 93, 94, 95, 152, 188, 188, 22, 194,
125229
- /* 1030 */ 50, 51, 240, 173, 194, 174, 175, 252, 194, 152,
125230
- /* 1040 */ 36, 181, 28, 152, 23, 219, 122, 174, 175, 219,
125231
- /* 1050 */ 221, 152, 152, 73, 74, 75, 76, 77, 78, 79,
125697
+ /* 1020 */ 91, 92, 93, 94, 95, 152, 240, 152, 198, 198,
125698
+ /* 1030 */ 50, 51, 33, 198, 123, 174, 175, 116, 7, 8,
125699
+ /* 1040 */ 101, 42, 121, 107, 152, 152, 23, 174, 175, 26,
125700
+ /* 1050 */ 152, 112, 183, 73, 74, 75, 76, 77, 78, 79,
125232125701
/* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89,
125233
- /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 152, 22,
125234
- /* 1080 */ 23, 194, 152, 240, 27, 28, 174, 175, 240, 19,
125235
- /* 1090 */ 20, 26, 22, 194, 194, 38, 22, 27, 28, 152,
125236
- /* 1100 */ 23, 22, 152, 116, 174, 175, 152, 23, 38, 152,
125237
- /* 1110 */ 23, 152, 221, 152, 57, 152, 23, 163, 50, 51,
125238
- /* 1120 */ 194, 174, 175, 66, 174, 175, 69, 57, 174, 175,
125239
- /* 1130 */ 40, 174, 175, 174, 175, 174, 175, 174, 175, 69,
125240
- /* 1140 */ 22, 53, 74, 75, 30, 53, 89, 90, 22, 22,
125241
- /* 1150 */ 152, 197, 23, 96, 97, 98, 22, 152, 101, 89,
125242
- /* 1160 */ 90, 91, 208, 209, 152, 53, 96, 97, 98, 101,
125243
- /* 1170 */ 22, 101, 174, 175, 152, 19, 20, 105, 22, 174,
125244
- /* 1180 */ 175, 112, 19, 27, 28, 20, 174, 175, 24, 132,
125245
- /* 1190 */ 133, 134, 135, 136, 38, 44, 174, 175, 107, 61,
125246
- /* 1200 */ 54, 26, 132, 133, 134, 135, 136, 54, 107, 22,
125247
- /* 1210 */ 5, 140, 1, 57, 36, 111, 122, 28, 79, 79,
125248
- /* 1220 */ 131, 123, 66, 19, 20, 69, 22, 1, 16, 20,
125249
- /* 1230 */ 125, 27, 28, 123, 111, 120, 23, 131, 23, 16,
125250
- /* 1240 */ 68, 142, 38, 15, 22, 89, 90, 3, 167, 4,
125251
- /* 1250 */ 248, 251, 96, 97, 98, 180, 180, 101, 251, 151,
125252
- /* 1260 */ 6, 57, 151, 13, 151, 26, 25, 151, 161, 202,
125253
- /* 1270 */ 153, 162, 153, 69, 130, 128, 203, 19, 20, 127,
125254
- /* 1280 */ 22, 126, 204, 129, 22, 27, 28, 205, 132, 133,
125255
- /* 1290 */ 134, 135, 136, 89, 90, 231, 38, 95, 137, 179,
125256
- /* 1300 */ 96, 97, 98, 206, 179, 101, 122, 107, 159, 159,
125257
- /* 1310 */ 125, 231, 216, 228, 107, 57, 184, 217, 216, 176,
125258
- /* 1320 */ 217, 176, 48, 106, 18, 184, 158, 69, 159, 158,
125259
- /* 1330 */ 46, 71, 237, 176, 176, 176, 132, 133, 134, 135,
125260
- /* 1340 */ 136, 217, 176, 137, 216, 178, 158, 89, 90, 179,
125261
- /* 1350 */ 176, 159, 179, 159, 96, 97, 98, 159, 159, 101,
125262
- /* 1360 */ 5, 158, 202, 22, 18, 10, 11, 12, 13, 14,
125263
- /* 1370 */ 190, 238, 17, 190, 158, 193, 41, 159, 202, 193,
125264
- /* 1380 */ 159, 202, 245, 193, 193, 223, 190, 32, 159, 34,
125265
- /* 1390 */ 132, 133, 134, 135, 136, 159, 39, 155, 43, 150,
125266
- /* 1400 */ 223, 177, 201, 178, 177, 186, 66, 199, 177, 152,
125267
- /* 1410 */ 253, 56, 215, 152, 182, 152, 202, 152, 63, 152,
125268
- /* 1420 */ 152, 66, 67, 242, 229, 152, 174, 152, 152, 152,
125269
- /* 1430 */ 152, 152, 152, 152, 199, 242, 202, 152, 198, 152,
125270
- /* 1440 */ 152, 152, 183, 192, 152, 215, 152, 183, 215, 183,
125271
- /* 1450 */ 152, 241, 214, 152, 211, 152, 152, 211, 211, 152,
125272
- /* 1460 */ 152, 241, 152, 152, 152, 152, 152, 152, 152, 114,
125273
- /* 1470 */ 152, 152, 235, 152, 152, 152, 174, 187, 95, 174,
125274
- /* 1480 */ 253, 253, 253, 253, 236, 253, 253, 253, 253, 253,
125275
- /* 1490 */ 253, 253, 253, 253, 253, 253, 141,
125702
+ /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 23, 22,
125703
+ /* 1080 */ 23, 26, 152, 152, 27, 28, 174, 175, 23, 19,
125704
+ /* 1090 */ 20, 26, 22, 132, 133, 38, 152, 27, 28, 152,
125705
+ /* 1100 */ 23, 215, 152, 26, 174, 175, 152, 27, 38, 152,
125706
+ /* 1110 */ 23, 152, 27, 26, 57, 152, 23, 163, 152, 26,
125707
+ /* 1120 */ 152, 174, 175, 66, 174, 175, 69, 57, 174, 175,
125708
+ /* 1130 */ 27, 174, 175, 174, 175, 152, 66, 174, 175, 69,
125709
+ /* 1140 */ 174, 175, 174, 175, 152, 23, 89, 90, 26, 91,
125710
+ /* 1150 */ 152, 236, 198, 96, 97, 98, 132, 133, 101, 89,
125711
+ /* 1160 */ 90, 152, 23, 209, 210, 26, 96, 97, 98, 152,
125712
+ /* 1170 */ 212, 101, 174, 175, 116, 19, 20, 97, 22, 121,
125713
+ /* 1180 */ 152, 193, 97, 27, 28, 152, 152, 152, 152, 132,
125714
+ /* 1190 */ 133, 134, 135, 136, 38, 23, 152, 152, 26, 152,
125715
+ /* 1200 */ 97, 152, 132, 133, 134, 135, 136, 235, 152, 212,
125716
+ /* 1210 */ 199, 150, 212, 57, 212, 200, 203, 216, 241, 216,
125717
+ /* 1220 */ 241, 203, 182, 19, 20, 69, 22, 186, 178, 177,
125718
+ /* 1230 */ 216, 27, 28, 229, 202, 39, 177, 177, 200, 155,
125719
+ /* 1240 */ 245, 122, 38, 41, 22, 89, 90, 91, 159, 159,
125720
+ /* 1250 */ 242, 159, 96, 97, 98, 71, 130, 101, 242, 191,
125721
+ /* 1260 */ 223, 57, 18, 194, 159, 203, 194, 194, 194, 18,
125722
+ /* 1270 */ 158, 223, 191, 69, 203, 159, 158, 19, 20, 191,
125723
+ /* 1280 */ 22, 203, 137, 46, 238, 27, 28, 159, 132, 133,
125724
+ /* 1290 */ 134, 135, 136, 89, 90, 159, 38, 22, 158, 179,
125725
+ /* 1300 */ 96, 97, 98, 237, 158, 101, 159, 159, 158, 179,
125726
+ /* 1310 */ 107, 176, 48, 176, 176, 57, 184, 106, 176, 125,
125727
+ /* 1320 */ 179, 178, 218, 107, 217, 176, 218, 69, 184, 176,
125728
+ /* 1330 */ 176, 217, 159, 218, 217, 159, 132, 133, 134, 135,
125729
+ /* 1340 */ 136, 218, 217, 137, 179, 95, 179, 89, 90, 228,
125730
+ /* 1350 */ 129, 126, 128, 127, 96, 97, 98, 206, 231, 101,
125731
+ /* 1360 */ 5, 25, 231, 205, 207, 10, 11, 12, 13, 14,
125732
+ /* 1370 */ 204, 203, 17, 26, 162, 161, 13, 6, 180, 180,
125733
+ /* 1380 */ 153, 153, 151, 151, 151, 151, 167, 32, 4, 34,
125734
+ /* 1390 */ 132, 133, 134, 135, 136, 3, 22, 142, 43, 68,
125735
+ /* 1400 */ 15, 23, 16, 251, 23, 120, 251, 248, 131, 111,
125736
+ /* 1410 */ 123, 56, 16, 20, 125, 1, 123, 131, 63, 79,
125737
+ /* 1420 */ 79, 66, 67, 111, 36, 28, 122, 1, 5, 22,
125738
+ /* 1430 */ 107, 140, 26, 54, 54, 44, 61, 107, 20, 24,
125739
+ /* 1440 */ 19, 112, 105, 53, 22, 40, 22, 22, 53, 30,
125740
+ /* 1450 */ 23, 22, 22, 53, 23, 23, 23, 22, 116, 23,
125741
+ /* 1460 */ 22, 122, 23, 26, 23, 22, 11, 124, 28, 114,
125742
+ /* 1470 */ 36, 26, 26, 23, 23, 23, 122, 23, 36, 26,
125743
+ /* 1480 */ 36, 22, 24, 23, 22, 1, 23, 26, 22, 24,
125744
+ /* 1490 */ 23, 22, 122, 23, 23, 22, 141, 23, 122, 122,
125745
+ /* 1500 */ 15,
125276125746
};
125277
-#define YY_SHIFT_USE_DFLT (-86)
125278
-#define YY_SHIFT_COUNT (429)
125279
-#define YY_SHIFT_MIN (-85)
125280
-#define YY_SHIFT_MAX (1383)
125747
+#define YY_SHIFT_USE_DFLT (-72)
125748
+#define YY_SHIFT_COUNT (435)
125749
+#define YY_SHIFT_MIN (-71)
125750
+#define YY_SHIFT_MAX (1485)
125281125751
static const short yy_shift_ofst[] = {
125282
- /* 0 */ 992, 1057, 1355, 1156, 1204, 1204, 1, 262, -19, 135,
125283
- /* 10 */ 135, 776, 1204, 1204, 1204, 1204, 69, 69, 53, 208,
125284
- /* 20 */ 283, 755, 58, 725, 648, 571, 494, 417, 340, 263,
125285
- /* 30 */ 212, 827, 827, 827, 827, 827, 827, 827, 827, 827,
125286
- /* 40 */ 827, 827, 827, 827, 827, 827, 878, 827, 929, 980,
125287
- /* 50 */ 980, 1070, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125752
+ /* 0 */ 5, 1057, 1355, 1070, 1204, 1204, 1204, 90, 60, -19,
125753
+ /* 10 */ 58, 58, 186, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125754
+ /* 20 */ 67, 67, 182, 336, 65, 250, 135, 263, 340, 417,
125755
+ /* 30 */ 494, 571, 622, 699, 776, 827, 827, 827, 827, 827,
125756
+ /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827,
125757
+ /* 50 */ 878, 827, 929, 980, 980, 1156, 1204, 1204, 1204, 1204,
125288125758
/* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125289125759
/* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125290
- /* 80 */ 1258, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125291
- /* 90 */ 1204, 1204, 1204, 1204, -71, -47, -47, -47, -47, -47,
125292
- /* 100 */ 0, 29, -12, 283, 283, 139, 91, 392, 392, 894,
125293
- /* 110 */ 672, 726, 1383, -86, -86, -86, 88, 318, 318, 99,
125294
- /* 120 */ 381, -20, 283, 283, 283, 283, 283, 283, 283, 283,
125295
- /* 130 */ 283, 283, 283, 283, 283, 283, 283, 283, 283, 283,
125296
- /* 140 */ 283, 283, 283, 283, 624, 876, 726, 672, 1340, 1340,
125297
- /* 150 */ 1340, 1340, 1340, 1340, -86, -86, -86, 305, 136, 136,
125298
- /* 160 */ 142, 167, 226, 154, 137, 152, 283, 283, 283, 283,
125299
- /* 170 */ 283, 283, 283, 283, 283, 283, 283, 283, 283, 283,
125300
- /* 180 */ 283, 283, 283, 336, 336, 336, 283, 283, 352, 283,
125301
- /* 190 */ 283, 283, 283, 283, 228, 283, 283, 283, 283, 283,
125302
- /* 200 */ 283, 283, 283, 283, 283, 501, 569, 596, 596, 596,
125303
- /* 210 */ 507, 497, 441, 391, 353, 156, 156, 857, 353, 857,
125304
- /* 220 */ 735, 813, 639, 715, 156, 332, 715, 715, 496, 419,
125305
- /* 230 */ 646, 1357, 1184, 1184, 1335, 1335, 1184, 1341, 1260, 1144,
125306
- /* 240 */ 1346, 1346, 1346, 1346, 1184, 1306, 1144, 1341, 1260, 1260,
125307
- /* 250 */ 1144, 1184, 1306, 1206, 1284, 1184, 1184, 1306, 1184, 1306,
125308
- /* 260 */ 1184, 1306, 1262, 1207, 1207, 1207, 1274, 1262, 1207, 1217,
125309
- /* 270 */ 1207, 1274, 1207, 1207, 1185, 1200, 1185, 1200, 1185, 1200,
125310
- /* 280 */ 1184, 1184, 1161, 1262, 1202, 1202, 1262, 1154, 1155, 1147,
125311
- /* 290 */ 1152, 1144, 1241, 1239, 1250, 1250, 1254, 1254, 1254, 1254,
125312
- /* 300 */ -86, -86, -86, -86, -86, -86, 1068, 304, 526, 249,
125313
- /* 310 */ 408, -83, 434, 812, 27, 811, 807, 802, 751, 589,
125314
- /* 320 */ 651, 163, 131, 674, 366, 450, 299, 148, 23, 102,
125315
- /* 330 */ 229, -21, 1245, 1244, 1222, 1099, 1228, 1172, 1223, 1215,
125316
- /* 340 */ 1213, 1115, 1106, 1123, 1110, 1209, 1105, 1212, 1226, 1098,
125317
- /* 350 */ 1089, 1140, 1139, 1104, 1189, 1178, 1094, 1211, 1205, 1187,
125318
- /* 360 */ 1101, 1071, 1153, 1175, 1146, 1138, 1151, 1091, 1164, 1165,
125319
- /* 370 */ 1163, 1069, 1072, 1148, 1112, 1134, 1127, 1129, 1126, 1092,
125320
- /* 380 */ 1114, 1118, 1088, 1090, 1093, 1087, 1084, 987, 1079, 1077,
125321
- /* 390 */ 1074, 1065, 924, 1021, 1014, 1004, 1006, 819, 739, 896,
125322
- /* 400 */ 855, 804, 739, 740, 736, 690, 654, 665, 618, 582,
125323
- /* 410 */ 568, 528, 554, 379, 532, 479, 455, 379, 432, 371,
125324
- /* 420 */ 341, 28, 338, 116, -11, -57, -85, 7, -8, 3,
125760
+ /* 80 */ 1204, 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204,
125761
+ /* 90 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, -71, -47,
125762
+ /* 100 */ -47, -47, -47, -47, -6, 88, -66, 65, 65, 451,
125763
+ /* 110 */ 502, 112, 112, 33, 127, 278, -30, -72, -72, -72,
125764
+ /* 120 */ 11, 412, 412, 268, 608, 610, 65, 65, 65, 65,
125765
+ /* 130 */ 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
125766
+ /* 140 */ 65, 65, 65, 65, 65, 559, 138, 278, 127, 24,
125767
+ /* 150 */ 24, 24, 24, 24, 24, -72, -72, -72, 228, 341,
125768
+ /* 160 */ 341, 207, 276, 300, 352, 354, 350, 65, 65, 65,
125769
+ /* 170 */ 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
125770
+ /* 180 */ 65, 65, 65, 65, 495, 495, 495, 65, 65, 499,
125771
+ /* 190 */ 65, 65, 65, 574, 65, 65, 517, 65, 65, 65,
125772
+ /* 200 */ 65, 65, 65, 65, 65, 65, 65, 566, 691, 288,
125773
+ /* 210 */ 288, 288, 701, 620, 1058, 675, 603, 964, 964, 967,
125774
+ /* 220 */ 603, 967, 722, 965, 936, 999, 964, 264, 999, 999,
125775
+ /* 230 */ 911, 921, 434, 1196, 1119, 1119, 1202, 1202, 1119, 1222,
125776
+ /* 240 */ 1184, 1126, 1244, 1244, 1244, 1244, 1119, 1251, 1126, 1222,
125777
+ /* 250 */ 1184, 1184, 1126, 1119, 1251, 1145, 1237, 1119, 1119, 1251,
125778
+ /* 260 */ 1275, 1119, 1251, 1119, 1251, 1275, 1203, 1203, 1203, 1264,
125779
+ /* 270 */ 1275, 1203, 1211, 1203, 1264, 1203, 1203, 1194, 1216, 1194,
125780
+ /* 280 */ 1216, 1194, 1216, 1194, 1216, 1119, 1119, 1206, 1275, 1250,
125781
+ /* 290 */ 1250, 1275, 1221, 1225, 1224, 1226, 1126, 1336, 1347, 1363,
125782
+ /* 300 */ 1363, 1371, 1371, 1371, 1371, -72, -72, -72, -72, -72,
125783
+ /* 310 */ -72, 477, 623, 742, 819, 624, 694, 74, 1023, 221,
125784
+ /* 320 */ 1055, 1065, 1077, 1087, 1080, 889, 1031, 939, 1093, 1122,
125785
+ /* 330 */ 1085, 1139, 961, 1024, 1172, 1103, 821, 1384, 1392, 1374,
125786
+ /* 340 */ 1255, 1385, 1331, 1386, 1378, 1381, 1285, 1277, 1298, 1287,
125787
+ /* 350 */ 1393, 1289, 1396, 1414, 1293, 1286, 1340, 1341, 1312, 1397,
125788
+ /* 360 */ 1388, 1304, 1426, 1423, 1407, 1323, 1291, 1379, 1406, 1380,
125789
+ /* 370 */ 1375, 1391, 1330, 1415, 1418, 1421, 1329, 1337, 1422, 1390,
125790
+ /* 380 */ 1424, 1425, 1427, 1429, 1395, 1419, 1430, 1400, 1405, 1431,
125791
+ /* 390 */ 1432, 1433, 1342, 1435, 1436, 1438, 1437, 1339, 1439, 1441,
125792
+ /* 400 */ 1440, 1434, 1443, 1343, 1445, 1442, 1446, 1444, 1445, 1450,
125793
+ /* 410 */ 1451, 1452, 1453, 1454, 1459, 1455, 1460, 1462, 1458, 1461,
125794
+ /* 420 */ 1463, 1466, 1465, 1461, 1467, 1469, 1470, 1471, 1473, 1354,
125795
+ /* 430 */ 1370, 1376, 1377, 1474, 1485, 1484,
125325125796
};
125326
-#define YY_REDUCE_USE_DFLT (-110)
125327
-#define YY_REDUCE_COUNT (305)
125328
-#define YY_REDUCE_MIN (-109)
125329
-#define YY_REDUCE_MAX (1323)
125797
+#define YY_REDUCE_USE_DFLT (-176)
125798
+#define YY_REDUCE_COUNT (310)
125799
+#define YY_REDUCE_MIN (-175)
125800
+#define YY_REDUCE_MAX (1234)
125330125801
static const short yy_reduce_ofst[] = {
125331
- /* 0 */ 238, 954, 213, 289, 310, 234, 144, 317, -109, 382,
125332
- /* 10 */ 377, 303, 461, 389, 378, 368, 302, 294, 253, 395,
125333
- /* 20 */ 293, 324, 403, 403, 403, 403, 403, 403, 403, 403,
125334
- /* 30 */ 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
125335
- /* 40 */ 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
125336
- /* 50 */ 403, 1022, 1012, 1005, 998, 963, 961, 959, 957, 950,
125337
- /* 60 */ 947, 930, 912, 873, 861, 823, 810, 771, 759, 720,
125338
- /* 70 */ 708, 670, 657, 619, 614, 612, 610, 608, 606, 604,
125339
- /* 80 */ 598, 595, 593, 580, 542, 540, 537, 535, 533, 531,
125340
- /* 90 */ 529, 527, 503, 386, 403, 403, 403, 403, 403, 403,
125341
- /* 100 */ 403, 403, 403, 95, 447, 82, 334, 504, 467, 403,
125342
- /* 110 */ 477, 464, 403, 403, 403, 403, 860, 747, 744, 785,
125343
- /* 120 */ 638, 638, 926, 891, 900, 899, 887, 844, 840, 835,
125344
- /* 130 */ 848, 830, 843, 829, 792, 839, 826, 737, 838, 795,
125345
- /* 140 */ 789, 47, 734, 530, 696, 777, 711, 677, 733, 730,
125346
- /* 150 */ 729, 728, 727, 627, 448, 64, 187, 1305, 1302, 1252,
125347
- /* 160 */ 1290, 1273, 1323, 1322, 1321, 1319, 1318, 1316, 1315, 1314,
125348
- /* 170 */ 1313, 1312, 1311, 1310, 1308, 1307, 1304, 1303, 1301, 1298,
125349
- /* 180 */ 1294, 1292, 1289, 1266, 1264, 1259, 1288, 1287, 1238, 1285,
125350
- /* 190 */ 1281, 1280, 1279, 1278, 1251, 1277, 1276, 1275, 1273, 1268,
125351
- /* 200 */ 1267, 1265, 1263, 1261, 1257, 1248, 1237, 1247, 1246, 1243,
125352
- /* 210 */ 1238, 1240, 1235, 1249, 1234, 1233, 1230, 1220, 1214, 1210,
125353
- /* 220 */ 1225, 1219, 1232, 1231, 1197, 1195, 1227, 1224, 1201, 1208,
125354
- /* 230 */ 1242, 1137, 1236, 1229, 1193, 1181, 1221, 1177, 1196, 1179,
125355
- /* 240 */ 1191, 1190, 1186, 1182, 1218, 1216, 1176, 1162, 1183, 1180,
125356
- /* 250 */ 1160, 1199, 1203, 1133, 1095, 1198, 1194, 1188, 1192, 1171,
125357
- /* 260 */ 1169, 1168, 1173, 1174, 1166, 1159, 1141, 1170, 1158, 1167,
125358
- /* 270 */ 1157, 1132, 1145, 1143, 1124, 1128, 1103, 1102, 1100, 1096,
125359
- /* 280 */ 1150, 1149, 1085, 1125, 1080, 1064, 1120, 1097, 1082, 1078,
125360
- /* 290 */ 1073, 1067, 1109, 1107, 1119, 1117, 1116, 1113, 1111, 1108,
125361
- /* 300 */ 1007, 1000, 1002, 1076, 1075, 1081,
125802
+ /* 0 */ -143, 954, 86, 21, -50, 23, 79, 134, 170, -175,
125803
+ /* 10 */ 229, 260, -121, 212, 219, 291, -54, 349, 362, 156,
125804
+ /* 20 */ 309, 311, 334, 85, 224, 394, 314, 314, 314, 314,
125805
+ /* 30 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314,
125806
+ /* 40 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314,
125807
+ /* 50 */ 314, 314, 314, 314, 314, 374, 441, 443, 450, 452,
125808
+ /* 60 */ 515, 554, 567, 569, 572, 578, 580, 582, 584, 587,
125809
+ /* 70 */ 593, 631, 644, 646, 649, 655, 657, 659, 661, 664,
125810
+ /* 80 */ 708, 720, 759, 771, 810, 822, 861, 873, 912, 930,
125811
+ /* 90 */ 947, 950, 957, 959, 963, 966, 968, 998, 314, 314,
125812
+ /* 100 */ 314, 314, 314, 314, 314, 314, 314, 447, -53, 166,
125813
+ /* 110 */ 438, 348, 363, 314, 473, 469, 314, 314, 314, 314,
125814
+ /* 120 */ -15, 59, 101, 688, 220, 220, 525, 256, 729, 735,
125815
+ /* 130 */ 736, 740, 741, 744, 645, 448, 738, 458, 786, 503,
125816
+ /* 140 */ 780, 656, 721, 724, 792, 545, 568, 706, 683, 681,
125817
+ /* 150 */ 779, 784, 830, 831, 835, 678, 601, -104, -2, 96,
125818
+ /* 160 */ 111, 218, 287, 308, 310, 312, 335, 411, 453, 461,
125819
+ /* 170 */ 573, 599, 617, 658, 665, 670, 732, 734, 775, 848,
125820
+ /* 180 */ 875, 892, 893, 898, 332, 420, 869, 931, 944, 886,
125821
+ /* 190 */ 983, 992, 1009, 958, 1017, 1028, 988, 1033, 1034, 1035,
125822
+ /* 200 */ 287, 1036, 1044, 1045, 1047, 1049, 1056, 915, 972, 997,
125823
+ /* 210 */ 1000, 1002, 886, 1011, 1015, 1061, 1013, 1001, 1003, 977,
125824
+ /* 220 */ 1018, 979, 1050, 1041, 1040, 1052, 1014, 1004, 1059, 1060,
125825
+ /* 230 */ 1032, 1038, 1084, 995, 1089, 1090, 1008, 1016, 1092, 1037,
125826
+ /* 240 */ 1068, 1062, 1069, 1072, 1073, 1074, 1105, 1112, 1071, 1048,
125827
+ /* 250 */ 1081, 1088, 1078, 1116, 1118, 1046, 1066, 1128, 1136, 1140,
125828
+ /* 260 */ 1120, 1147, 1146, 1148, 1150, 1130, 1135, 1137, 1138, 1132,
125829
+ /* 270 */ 1141, 1142, 1143, 1149, 1144, 1153, 1154, 1104, 1107, 1108,
125830
+ /* 280 */ 1114, 1115, 1117, 1123, 1125, 1173, 1176, 1121, 1165, 1127,
125831
+ /* 290 */ 1131, 1167, 1157, 1151, 1158, 1166, 1168, 1212, 1214, 1227,
125832
+ /* 300 */ 1228, 1231, 1232, 1233, 1234, 1152, 1155, 1159, 1198, 1199,
125833
+ /* 310 */ 1219,
125362125834
};
125363125835
static const YYACTIONTYPE yy_default[] = {
125364
- /* 0 */ 647, 964, 964, 964, 878, 878, 969, 964, 774, 802,
125365
- /* 10 */ 802, 938, 969, 969, 969, 876, 969, 969, 969, 964,
125366
- /* 20 */ 969, 778, 808, 969, 969, 969, 969, 969, 969, 969,
125367
- /* 30 */ 969, 937, 939, 816, 815, 918, 789, 813, 806, 810,
125368
- /* 40 */ 879, 872, 873, 871, 875, 880, 969, 809, 841, 856,
125369
- /* 50 */ 840, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125370
- /* 60 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125371
- /* 70 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125372
- /* 80 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125373
- /* 90 */ 969, 969, 969, 969, 850, 855, 862, 854, 851, 843,
125374
- /* 100 */ 842, 844, 845, 969, 969, 673, 739, 969, 969, 846,
125375
- /* 110 */ 969, 685, 847, 859, 858, 857, 680, 969, 969, 969,
125376
- /* 120 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125377
- /* 130 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125378
- /* 140 */ 969, 969, 969, 969, 647, 964, 969, 969, 964, 964,
125379
- /* 150 */ 964, 964, 964, 964, 956, 778, 768, 969, 969, 969,
125380
- /* 160 */ 969, 969, 969, 969, 969, 969, 969, 944, 942, 969,
125381
- /* 170 */ 891, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125382
- /* 180 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125383
- /* 190 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125384
- /* 200 */ 969, 969, 969, 969, 653, 969, 911, 774, 774, 774,
125385
- /* 210 */ 776, 754, 766, 655, 812, 791, 791, 923, 812, 923,
125386
- /* 220 */ 710, 733, 707, 802, 791, 874, 802, 802, 775, 766,
125387
- /* 230 */ 969, 949, 782, 782, 941, 941, 782, 821, 743, 812,
125388
- /* 240 */ 750, 750, 750, 750, 782, 670, 812, 821, 743, 743,
125389
- /* 250 */ 812, 782, 670, 917, 915, 782, 782, 670, 782, 670,
125390
- /* 260 */ 782, 670, 884, 741, 741, 741, 725, 884, 741, 710,
125391
- /* 270 */ 741, 725, 741, 741, 795, 790, 795, 790, 795, 790,
125392
- /* 280 */ 782, 782, 969, 884, 888, 888, 884, 807, 796, 805,
125393
- /* 290 */ 803, 812, 676, 728, 663, 663, 652, 652, 652, 652,
125394
- /* 300 */ 961, 961, 956, 712, 712, 695, 969, 969, 969, 969,
125395
- /* 310 */ 969, 969, 687, 969, 893, 969, 969, 969, 969, 969,
125396
- /* 320 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125397
- /* 330 */ 969, 828, 969, 648, 951, 969, 969, 948, 969, 969,
125398
- /* 340 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125399
- /* 350 */ 969, 969, 969, 969, 969, 969, 921, 969, 969, 969,
125400
- /* 360 */ 969, 969, 969, 914, 913, 969, 969, 969, 969, 969,
125401
- /* 370 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125402
- /* 380 */ 969, 969, 969, 969, 969, 969, 969, 757, 969, 969,
125403
- /* 390 */ 969, 761, 969, 969, 969, 969, 969, 969, 804, 969,
125404
- /* 400 */ 797, 969, 877, 969, 969, 969, 969, 969, 969, 969,
125405
- /* 410 */ 969, 969, 969, 966, 969, 969, 969, 965, 969, 969,
125406
- /* 420 */ 969, 969, 969, 830, 969, 829, 833, 969, 661, 969,
125407
- /* 430 */ 644, 649, 960, 963, 962, 959, 958, 957, 952, 950,
125408
- /* 440 */ 947, 946, 945, 943, 940, 936, 897, 895, 902, 901,
125409
- /* 450 */ 900, 899, 898, 896, 894, 892, 818, 817, 814, 811,
125410
- /* 460 */ 753, 935, 890, 752, 749, 748, 669, 953, 920, 929,
125411
- /* 470 */ 928, 927, 822, 926, 925, 924, 922, 919, 906, 820,
125412
- /* 480 */ 819, 744, 882, 881, 672, 910, 909, 908, 912, 916,
125413
- /* 490 */ 907, 784, 751, 671, 668, 675, 679, 731, 732, 740,
125414
- /* 500 */ 738, 737, 736, 735, 734, 730, 681, 686, 724, 709,
125415
- /* 510 */ 708, 717, 716, 722, 721, 720, 719, 718, 715, 714,
125416
- /* 520 */ 713, 706, 705, 711, 704, 727, 726, 723, 703, 747,
125417
- /* 530 */ 746, 745, 742, 702, 701, 700, 833, 699, 698, 838,
125418
- /* 540 */ 837, 866, 826, 755, 759, 758, 762, 763, 771, 770,
125419
- /* 550 */ 769, 780, 781, 793, 792, 824, 823, 794, 779, 773,
125420
- /* 560 */ 772, 788, 787, 786, 785, 777, 767, 799, 798, 868,
125421
- /* 570 */ 783, 867, 865, 934, 933, 932, 931, 930, 870, 967,
125422
- /* 580 */ 968, 887, 889, 886, 801, 800, 885, 869, 839, 836,
125423
- /* 590 */ 690, 691, 905, 904, 903, 693, 692, 689, 688, 863,
125424
- /* 600 */ 860, 852, 864, 861, 853, 849, 848, 834, 832, 831,
125425
- /* 610 */ 827, 835, 760, 756, 825, 765, 764, 697, 696, 694,
125426
- /* 620 */ 678, 677, 674, 667, 665, 664, 666, 662, 660, 659,
125427
- /* 630 */ 658, 657, 656, 684, 683, 682, 654, 651, 650, 646,
125428
- /* 640 */ 645, 643,
125836
+ /* 0 */ 982, 1300, 1300, 1300, 1214, 1214, 1214, 1305, 1300, 1109,
125837
+ /* 10 */ 1138, 1138, 1274, 1305, 1305, 1305, 1305, 1305, 1305, 1212,
125838
+ /* 20 */ 1305, 1305, 1305, 1300, 1305, 1113, 1144, 1305, 1305, 1305,
125839
+ /* 30 */ 1305, 1305, 1305, 1305, 1305, 1273, 1275, 1152, 1151, 1254,
125840
+ /* 40 */ 1125, 1149, 1142, 1146, 1215, 1208, 1209, 1207, 1211, 1216,
125841
+ /* 50 */ 1305, 1145, 1177, 1192, 1176, 1305, 1305, 1305, 1305, 1305,
125842
+ /* 60 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125843
+ /* 70 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125844
+ /* 80 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125845
+ /* 90 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1186, 1191,
125846
+ /* 100 */ 1198, 1190, 1187, 1179, 1178, 1180, 1181, 1305, 1305, 1008,
125847
+ /* 110 */ 1074, 1305, 1305, 1182, 1305, 1020, 1183, 1195, 1194, 1193,
125848
+ /* 120 */ 1015, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125849
+ /* 130 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125850
+ /* 140 */ 1305, 1305, 1305, 1305, 1305, 982, 1300, 1305, 1305, 1300,
125851
+ /* 150 */ 1300, 1300, 1300, 1300, 1300, 1292, 1113, 1103, 1305, 1305,
125852
+ /* 160 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1280, 1278,
125853
+ /* 170 */ 1305, 1227, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125854
+ /* 180 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125855
+ /* 190 */ 1305, 1305, 1305, 1109, 1305, 1305, 1305, 1305, 1305, 1305,
125856
+ /* 200 */ 1305, 1305, 1305, 1305, 1305, 1305, 988, 1305, 1247, 1109,
125857
+ /* 210 */ 1109, 1109, 1111, 1089, 1101, 990, 1148, 1127, 1127, 1259,
125858
+ /* 220 */ 1148, 1259, 1045, 1068, 1042, 1138, 1127, 1210, 1138, 1138,
125859
+ /* 230 */ 1110, 1101, 1305, 1285, 1118, 1118, 1277, 1277, 1118, 1157,
125860
+ /* 240 */ 1078, 1148, 1085, 1085, 1085, 1085, 1118, 1005, 1148, 1157,
125861
+ /* 250 */ 1078, 1078, 1148, 1118, 1005, 1253, 1251, 1118, 1118, 1005,
125862
+ /* 260 */ 1220, 1118, 1005, 1118, 1005, 1220, 1076, 1076, 1076, 1060,
125863
+ /* 270 */ 1220, 1076, 1045, 1076, 1060, 1076, 1076, 1131, 1126, 1131,
125864
+ /* 280 */ 1126, 1131, 1126, 1131, 1126, 1118, 1118, 1305, 1220, 1224,
125865
+ /* 290 */ 1224, 1220, 1143, 1132, 1141, 1139, 1148, 1011, 1063, 998,
125866
+ /* 300 */ 998, 987, 987, 987, 987, 1297, 1297, 1292, 1047, 1047,
125867
+ /* 310 */ 1030, 1305, 1305, 1305, 1305, 1305, 1305, 1022, 1305, 1229,
125868
+ /* 320 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125869
+ /* 330 */ 1305, 1305, 1305, 1305, 1305, 1305, 1164, 1305, 983, 1287,
125870
+ /* 340 */ 1305, 1305, 1284, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125871
+ /* 350 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125872
+ /* 360 */ 1305, 1257, 1305, 1305, 1305, 1305, 1305, 1305, 1250, 1249,
125873
+ /* 370 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125874
+ /* 380 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125875
+ /* 390 */ 1305, 1305, 1092, 1305, 1305, 1305, 1096, 1305, 1305, 1305,
125876
+ /* 400 */ 1305, 1305, 1305, 1305, 1140, 1305, 1133, 1305, 1213, 1305,
125877
+ /* 410 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1302,
125878
+ /* 420 */ 1305, 1305, 1305, 1301, 1305, 1305, 1305, 1305, 1305, 1166,
125879
+ /* 430 */ 1305, 1165, 1169, 1305, 996, 1305,
125429125880
};
125430125881
125431125882
/* The next table maps tokens into fallback tokens. If a construct
125432125883
** like the following:
125433125884
**
@@ -125522,13 +125973,17 @@
125522125973
** (In other words, the "major" token.)
125523125974
**
125524125975
** + The semantic value stored at this level of the stack. This is
125525125976
** the information used by the action routines in the grammar.
125526125977
** It is sometimes called the "minor" token.
125978
+**
125979
+** After the "shift" half of a SHIFTREDUCE action, the stateno field
125980
+** actually contains the reduce action for the second half of the
125981
+** SHIFTREDUCE.
125527125982
*/
125528125983
struct yyStackEntry {
125529
- YYACTIONTYPE stateno; /* The state-number */
125984
+ YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
125530125985
YYCODETYPE major; /* The major token value. This is the code
125531125986
** number for the token at this stack level */
125532125987
YYMINORTYPE minor; /* The user-supplied minor token value. This
125533125988
** is the value of the token */
125534125989
};
@@ -125630,22 +126085,22 @@
125630126085
"createkw", "temp", "ifnotexists", "dbnm",
125631126086
"columnlist", "conslist_opt", "table_options", "select",
125632126087
"column", "columnid", "type", "carglist",
125633126088
"typetoken", "typename", "signed", "plus_num",
125634126089
"minus_num", "ccons", "term", "expr",
125635
- "onconf", "sortorder", "autoinc", "idxlist_opt",
126090
+ "onconf", "sortorder", "autoinc", "eidlist_opt",
125636126091
"refargs", "defer_subclause", "refarg", "refact",
125637126092
"init_deferred_pred_opt", "conslist", "tconscomma", "tcons",
125638
- "idxlist", "defer_subclause_opt", "orconf", "resolvetype",
125639
- "raisetype", "ifexists", "fullname", "selectnowith",
125640
- "oneselect", "with", "multiselect_op", "distinct",
125641
- "selcollist", "from", "where_opt", "groupby_opt",
125642
- "having_opt", "orderby_opt", "limit_opt", "values",
125643
- "nexprlist", "exprlist", "sclp", "as",
125644
- "seltablist", "stl_prefix", "joinop", "indexed_opt",
125645
- "on_opt", "using_opt", "joinop2", "idlist",
125646
- "sortlist", "setlist", "insert_cmd", "inscollist_opt",
126093
+ "sortlist", "eidlist", "defer_subclause_opt", "orconf",
126094
+ "resolvetype", "raisetype", "ifexists", "fullname",
126095
+ "selectnowith", "oneselect", "with", "multiselect_op",
126096
+ "distinct", "selcollist", "from", "where_opt",
126097
+ "groupby_opt", "having_opt", "orderby_opt", "limit_opt",
126098
+ "values", "nexprlist", "exprlist", "sclp",
126099
+ "as", "seltablist", "stl_prefix", "joinop",
126100
+ "indexed_opt", "on_opt", "using_opt", "joinop2",
126101
+ "idlist", "setlist", "insert_cmd", "idlist_opt",
125647126102
"likeop", "between_op", "in_op", "case_operand",
125648126103
"case_exprlist", "case_else", "uniqueflag", "collate",
125649126104
"nmnum", "trigger_decl", "trigger_cmd_list", "trigger_time",
125650126105
"trigger_event", "foreach_clause", "when_clause", "trigger_cmd",
125651126106
"trnm", "tridxby", "database_kw_opt", "key_opt",
@@ -125722,11 +126177,11 @@
125722126177
/* 60 */ "ccons ::= NULL onconf",
125723126178
/* 61 */ "ccons ::= NOT NULL onconf",
125724126179
/* 62 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
125725126180
/* 63 */ "ccons ::= UNIQUE onconf",
125726126181
/* 64 */ "ccons ::= CHECK LP expr RP",
125727
- /* 65 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
126182
+ /* 65 */ "ccons ::= REFERENCES nm eidlist_opt refargs",
125728126183
/* 66 */ "ccons ::= defer_subclause",
125729126184
/* 67 */ "ccons ::= COLLATE ID|STRING",
125730126185
/* 68 */ "autoinc ::=",
125731126186
/* 69 */ "autoinc ::= AUTOINCR",
125732126187
/* 70 */ "refargs ::=",
@@ -125750,14 +126205,14 @@
125750126205
/* 88 */ "conslist ::= conslist tconscomma tcons",
125751126206
/* 89 */ "conslist ::= tcons",
125752126207
/* 90 */ "tconscomma ::= COMMA",
125753126208
/* 91 */ "tconscomma ::=",
125754126209
/* 92 */ "tcons ::= CONSTRAINT nm",
125755
- /* 93 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
125756
- /* 94 */ "tcons ::= UNIQUE LP idxlist RP onconf",
126210
+ /* 93 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf",
126211
+ /* 94 */ "tcons ::= UNIQUE LP sortlist RP onconf",
125757126212
/* 95 */ "tcons ::= CHECK LP expr RP onconf",
125758
- /* 96 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
126213
+ /* 96 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt",
125759126214
/* 97 */ "defer_subclause_opt ::=",
125760126215
/* 98 */ "defer_subclause_opt ::= defer_subclause",
125761126216
/* 99 */ "onconf ::=",
125762126217
/* 100 */ "onconf ::= ON CONFLICT resolvetype",
125763126218
/* 101 */ "orconf ::=",
@@ -125766,11 +126221,11 @@
125766126221
/* 104 */ "resolvetype ::= IGNORE",
125767126222
/* 105 */ "resolvetype ::= REPLACE",
125768126223
/* 106 */ "cmd ::= DROP TABLE ifexists fullname",
125769126224
/* 107 */ "ifexists ::= IF EXISTS",
125770126225
/* 108 */ "ifexists ::=",
125771
- /* 109 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select",
126226
+ /* 109 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select",
125772126227
/* 110 */ "cmd ::= DROP VIEW ifexists fullname",
125773126228
/* 111 */ "cmd ::= select",
125774126229
/* 112 */ "select ::= with selectnowith",
125775126230
/* 113 */ "selectnowith ::= oneselect",
125776126231
/* 114 */ "selectnowith ::= selectnowith multiselect_op oneselect",
@@ -125795,199 +126250,200 @@
125795126250
/* 133 */ "from ::=",
125796126251
/* 134 */ "from ::= FROM seltablist",
125797126252
/* 135 */ "stl_prefix ::= seltablist joinop",
125798126253
/* 136 */ "stl_prefix ::=",
125799126254
/* 137 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
125800
- /* 138 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
125801
- /* 139 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
125802
- /* 140 */ "dbnm ::=",
125803
- /* 141 */ "dbnm ::= DOT nm",
125804
- /* 142 */ "fullname ::= nm dbnm",
125805
- /* 143 */ "joinop ::= COMMA|JOIN",
125806
- /* 144 */ "joinop ::= JOIN_KW JOIN",
125807
- /* 145 */ "joinop ::= JOIN_KW nm JOIN",
125808
- /* 146 */ "joinop ::= JOIN_KW nm nm JOIN",
125809
- /* 147 */ "on_opt ::= ON expr",
125810
- /* 148 */ "on_opt ::=",
125811
- /* 149 */ "indexed_opt ::=",
125812
- /* 150 */ "indexed_opt ::= INDEXED BY nm",
125813
- /* 151 */ "indexed_opt ::= NOT INDEXED",
125814
- /* 152 */ "using_opt ::= USING LP idlist RP",
125815
- /* 153 */ "using_opt ::=",
125816
- /* 154 */ "orderby_opt ::=",
125817
- /* 155 */ "orderby_opt ::= ORDER BY sortlist",
125818
- /* 156 */ "sortlist ::= sortlist COMMA expr sortorder",
125819
- /* 157 */ "sortlist ::= expr sortorder",
125820
- /* 158 */ "sortorder ::= ASC",
125821
- /* 159 */ "sortorder ::= DESC",
125822
- /* 160 */ "sortorder ::=",
125823
- /* 161 */ "groupby_opt ::=",
125824
- /* 162 */ "groupby_opt ::= GROUP BY nexprlist",
125825
- /* 163 */ "having_opt ::=",
125826
- /* 164 */ "having_opt ::= HAVING expr",
125827
- /* 165 */ "limit_opt ::=",
125828
- /* 166 */ "limit_opt ::= LIMIT expr",
125829
- /* 167 */ "limit_opt ::= LIMIT expr OFFSET expr",
125830
- /* 168 */ "limit_opt ::= LIMIT expr COMMA expr",
125831
- /* 169 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
125832
- /* 170 */ "where_opt ::=",
125833
- /* 171 */ "where_opt ::= WHERE expr",
125834
- /* 172 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
125835
- /* 173 */ "setlist ::= setlist COMMA nm EQ expr",
125836
- /* 174 */ "setlist ::= nm EQ expr",
125837
- /* 175 */ "cmd ::= with insert_cmd INTO fullname inscollist_opt select",
125838
- /* 176 */ "cmd ::= with insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
125839
- /* 177 */ "insert_cmd ::= INSERT orconf",
125840
- /* 178 */ "insert_cmd ::= REPLACE",
125841
- /* 179 */ "inscollist_opt ::=",
125842
- /* 180 */ "inscollist_opt ::= LP idlist RP",
125843
- /* 181 */ "idlist ::= idlist COMMA nm",
125844
- /* 182 */ "idlist ::= nm",
125845
- /* 183 */ "expr ::= term",
125846
- /* 184 */ "expr ::= LP expr RP",
125847
- /* 185 */ "term ::= NULL",
125848
- /* 186 */ "expr ::= ID|INDEXED",
125849
- /* 187 */ "expr ::= JOIN_KW",
125850
- /* 188 */ "expr ::= nm DOT nm",
125851
- /* 189 */ "expr ::= nm DOT nm DOT nm",
125852
- /* 190 */ "term ::= INTEGER|FLOAT|BLOB",
125853
- /* 191 */ "term ::= STRING",
125854
- /* 192 */ "expr ::= VARIABLE",
125855
- /* 193 */ "expr ::= expr COLLATE ID|STRING",
125856
- /* 194 */ "expr ::= CAST LP expr AS typetoken RP",
125857
- /* 195 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
125858
- /* 196 */ "expr ::= ID|INDEXED LP STAR RP",
125859
- /* 197 */ "term ::= CTIME_KW",
125860
- /* 198 */ "expr ::= expr AND expr",
125861
- /* 199 */ "expr ::= expr OR expr",
125862
- /* 200 */ "expr ::= expr LT|GT|GE|LE expr",
125863
- /* 201 */ "expr ::= expr EQ|NE expr",
125864
- /* 202 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
125865
- /* 203 */ "expr ::= expr PLUS|MINUS expr",
125866
- /* 204 */ "expr ::= expr STAR|SLASH|REM expr",
125867
- /* 205 */ "expr ::= expr CONCAT expr",
125868
- /* 206 */ "likeop ::= LIKE_KW|MATCH",
125869
- /* 207 */ "likeop ::= NOT LIKE_KW|MATCH",
125870
- /* 208 */ "expr ::= expr likeop expr",
125871
- /* 209 */ "expr ::= expr likeop expr ESCAPE expr",
125872
- /* 210 */ "expr ::= expr ISNULL|NOTNULL",
125873
- /* 211 */ "expr ::= expr NOT NULL",
125874
- /* 212 */ "expr ::= expr IS expr",
125875
- /* 213 */ "expr ::= expr IS NOT expr",
125876
- /* 214 */ "expr ::= NOT expr",
125877
- /* 215 */ "expr ::= BITNOT expr",
125878
- /* 216 */ "expr ::= MINUS expr",
125879
- /* 217 */ "expr ::= PLUS expr",
125880
- /* 218 */ "between_op ::= BETWEEN",
125881
- /* 219 */ "between_op ::= NOT BETWEEN",
125882
- /* 220 */ "expr ::= expr between_op expr AND expr",
125883
- /* 221 */ "in_op ::= IN",
125884
- /* 222 */ "in_op ::= NOT IN",
125885
- /* 223 */ "expr ::= expr in_op LP exprlist RP",
125886
- /* 224 */ "expr ::= LP select RP",
125887
- /* 225 */ "expr ::= expr in_op LP select RP",
125888
- /* 226 */ "expr ::= expr in_op nm dbnm",
125889
- /* 227 */ "expr ::= EXISTS LP select RP",
125890
- /* 228 */ "expr ::= CASE case_operand case_exprlist case_else END",
125891
- /* 229 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
125892
- /* 230 */ "case_exprlist ::= WHEN expr THEN expr",
125893
- /* 231 */ "case_else ::= ELSE expr",
125894
- /* 232 */ "case_else ::=",
125895
- /* 233 */ "case_operand ::= expr",
125896
- /* 234 */ "case_operand ::=",
125897
- /* 235 */ "exprlist ::= nexprlist",
125898
- /* 236 */ "exprlist ::=",
125899
- /* 237 */ "nexprlist ::= nexprlist COMMA expr",
125900
- /* 238 */ "nexprlist ::= expr",
125901
- /* 239 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt",
125902
- /* 240 */ "uniqueflag ::= UNIQUE",
125903
- /* 241 */ "uniqueflag ::=",
125904
- /* 242 */ "idxlist_opt ::=",
125905
- /* 243 */ "idxlist_opt ::= LP idxlist RP",
125906
- /* 244 */ "idxlist ::= idxlist COMMA nm collate sortorder",
125907
- /* 245 */ "idxlist ::= nm collate sortorder",
125908
- /* 246 */ "collate ::=",
125909
- /* 247 */ "collate ::= COLLATE ID|STRING",
125910
- /* 248 */ "cmd ::= DROP INDEX ifexists fullname",
125911
- /* 249 */ "cmd ::= VACUUM",
125912
- /* 250 */ "cmd ::= VACUUM nm",
125913
- /* 251 */ "cmd ::= PRAGMA nm dbnm",
125914
- /* 252 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
125915
- /* 253 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
125916
- /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
125917
- /* 255 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
125918
- /* 256 */ "nmnum ::= plus_num",
125919
- /* 257 */ "nmnum ::= nm",
125920
- /* 258 */ "nmnum ::= ON",
125921
- /* 259 */ "nmnum ::= DELETE",
125922
- /* 260 */ "nmnum ::= DEFAULT",
125923
- /* 261 */ "plus_num ::= PLUS INTEGER|FLOAT",
125924
- /* 262 */ "plus_num ::= INTEGER|FLOAT",
125925
- /* 263 */ "minus_num ::= MINUS INTEGER|FLOAT",
125926
- /* 264 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
125927
- /* 265 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
125928
- /* 266 */ "trigger_time ::= BEFORE",
125929
- /* 267 */ "trigger_time ::= AFTER",
125930
- /* 268 */ "trigger_time ::= INSTEAD OF",
125931
- /* 269 */ "trigger_time ::=",
125932
- /* 270 */ "trigger_event ::= DELETE|INSERT",
125933
- /* 271 */ "trigger_event ::= UPDATE",
125934
- /* 272 */ "trigger_event ::= UPDATE OF idlist",
125935
- /* 273 */ "foreach_clause ::=",
125936
- /* 274 */ "foreach_clause ::= FOR EACH ROW",
125937
- /* 275 */ "when_clause ::=",
125938
- /* 276 */ "when_clause ::= WHEN expr",
125939
- /* 277 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
125940
- /* 278 */ "trigger_cmd_list ::= trigger_cmd SEMI",
125941
- /* 279 */ "trnm ::= nm",
125942
- /* 280 */ "trnm ::= nm DOT nm",
125943
- /* 281 */ "tridxby ::=",
125944
- /* 282 */ "tridxby ::= INDEXED BY nm",
125945
- /* 283 */ "tridxby ::= NOT INDEXED",
125946
- /* 284 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
125947
- /* 285 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
125948
- /* 286 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
125949
- /* 287 */ "trigger_cmd ::= select",
125950
- /* 288 */ "expr ::= RAISE LP IGNORE RP",
125951
- /* 289 */ "expr ::= RAISE LP raisetype COMMA nm RP",
125952
- /* 290 */ "raisetype ::= ROLLBACK",
125953
- /* 291 */ "raisetype ::= ABORT",
125954
- /* 292 */ "raisetype ::= FAIL",
125955
- /* 293 */ "cmd ::= DROP TRIGGER ifexists fullname",
125956
- /* 294 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
125957
- /* 295 */ "cmd ::= DETACH database_kw_opt expr",
125958
- /* 296 */ "key_opt ::=",
125959
- /* 297 */ "key_opt ::= KEY expr",
125960
- /* 298 */ "database_kw_opt ::= DATABASE",
125961
- /* 299 */ "database_kw_opt ::=",
125962
- /* 300 */ "cmd ::= REINDEX",
125963
- /* 301 */ "cmd ::= REINDEX nm dbnm",
125964
- /* 302 */ "cmd ::= ANALYZE",
125965
- /* 303 */ "cmd ::= ANALYZE nm dbnm",
125966
- /* 304 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
125967
- /* 305 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
125968
- /* 306 */ "add_column_fullname ::= fullname",
125969
- /* 307 */ "kwcolumn_opt ::=",
125970
- /* 308 */ "kwcolumn_opt ::= COLUMNKW",
125971
- /* 309 */ "cmd ::= create_vtab",
125972
- /* 310 */ "cmd ::= create_vtab LP vtabarglist RP",
125973
- /* 311 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
125974
- /* 312 */ "vtabarglist ::= vtabarg",
125975
- /* 313 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
125976
- /* 314 */ "vtabarg ::=",
125977
- /* 315 */ "vtabarg ::= vtabarg vtabargtoken",
125978
- /* 316 */ "vtabargtoken ::= ANY",
125979
- /* 317 */ "vtabargtoken ::= lp anylist RP",
125980
- /* 318 */ "lp ::= LP",
125981
- /* 319 */ "anylist ::=",
125982
- /* 320 */ "anylist ::= anylist LP anylist RP",
125983
- /* 321 */ "anylist ::= anylist ANY",
125984
- /* 322 */ "with ::=",
125985
- /* 323 */ "with ::= WITH wqlist",
125986
- /* 324 */ "with ::= WITH RECURSIVE wqlist",
125987
- /* 325 */ "wqlist ::= nm idxlist_opt AS LP select RP",
125988
- /* 326 */ "wqlist ::= wqlist COMMA nm idxlist_opt AS LP select RP",
126255
+ /* 138 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt",
126256
+ /* 139 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
126257
+ /* 140 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
126258
+ /* 141 */ "dbnm ::=",
126259
+ /* 142 */ "dbnm ::= DOT nm",
126260
+ /* 143 */ "fullname ::= nm dbnm",
126261
+ /* 144 */ "joinop ::= COMMA|JOIN",
126262
+ /* 145 */ "joinop ::= JOIN_KW JOIN",
126263
+ /* 146 */ "joinop ::= JOIN_KW nm JOIN",
126264
+ /* 147 */ "joinop ::= JOIN_KW nm nm JOIN",
126265
+ /* 148 */ "on_opt ::= ON expr",
126266
+ /* 149 */ "on_opt ::=",
126267
+ /* 150 */ "indexed_opt ::=",
126268
+ /* 151 */ "indexed_opt ::= INDEXED BY nm",
126269
+ /* 152 */ "indexed_opt ::= NOT INDEXED",
126270
+ /* 153 */ "using_opt ::= USING LP idlist RP",
126271
+ /* 154 */ "using_opt ::=",
126272
+ /* 155 */ "orderby_opt ::=",
126273
+ /* 156 */ "orderby_opt ::= ORDER BY sortlist",
126274
+ /* 157 */ "sortlist ::= sortlist COMMA expr sortorder",
126275
+ /* 158 */ "sortlist ::= expr sortorder",
126276
+ /* 159 */ "sortorder ::= ASC",
126277
+ /* 160 */ "sortorder ::= DESC",
126278
+ /* 161 */ "sortorder ::=",
126279
+ /* 162 */ "groupby_opt ::=",
126280
+ /* 163 */ "groupby_opt ::= GROUP BY nexprlist",
126281
+ /* 164 */ "having_opt ::=",
126282
+ /* 165 */ "having_opt ::= HAVING expr",
126283
+ /* 166 */ "limit_opt ::=",
126284
+ /* 167 */ "limit_opt ::= LIMIT expr",
126285
+ /* 168 */ "limit_opt ::= LIMIT expr OFFSET expr",
126286
+ /* 169 */ "limit_opt ::= LIMIT expr COMMA expr",
126287
+ /* 170 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
126288
+ /* 171 */ "where_opt ::=",
126289
+ /* 172 */ "where_opt ::= WHERE expr",
126290
+ /* 173 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
126291
+ /* 174 */ "setlist ::= setlist COMMA nm EQ expr",
126292
+ /* 175 */ "setlist ::= nm EQ expr",
126293
+ /* 176 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select",
126294
+ /* 177 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES",
126295
+ /* 178 */ "insert_cmd ::= INSERT orconf",
126296
+ /* 179 */ "insert_cmd ::= REPLACE",
126297
+ /* 180 */ "idlist_opt ::=",
126298
+ /* 181 */ "idlist_opt ::= LP idlist RP",
126299
+ /* 182 */ "idlist ::= idlist COMMA nm",
126300
+ /* 183 */ "idlist ::= nm",
126301
+ /* 184 */ "expr ::= term",
126302
+ /* 185 */ "expr ::= LP expr RP",
126303
+ /* 186 */ "term ::= NULL",
126304
+ /* 187 */ "expr ::= ID|INDEXED",
126305
+ /* 188 */ "expr ::= JOIN_KW",
126306
+ /* 189 */ "expr ::= nm DOT nm",
126307
+ /* 190 */ "expr ::= nm DOT nm DOT nm",
126308
+ /* 191 */ "term ::= INTEGER|FLOAT|BLOB",
126309
+ /* 192 */ "term ::= STRING",
126310
+ /* 193 */ "expr ::= VARIABLE",
126311
+ /* 194 */ "expr ::= expr COLLATE ID|STRING",
126312
+ /* 195 */ "expr ::= CAST LP expr AS typetoken RP",
126313
+ /* 196 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
126314
+ /* 197 */ "expr ::= ID|INDEXED LP STAR RP",
126315
+ /* 198 */ "term ::= CTIME_KW",
126316
+ /* 199 */ "expr ::= expr AND expr",
126317
+ /* 200 */ "expr ::= expr OR expr",
126318
+ /* 201 */ "expr ::= expr LT|GT|GE|LE expr",
126319
+ /* 202 */ "expr ::= expr EQ|NE expr",
126320
+ /* 203 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
126321
+ /* 204 */ "expr ::= expr PLUS|MINUS expr",
126322
+ /* 205 */ "expr ::= expr STAR|SLASH|REM expr",
126323
+ /* 206 */ "expr ::= expr CONCAT expr",
126324
+ /* 207 */ "likeop ::= LIKE_KW|MATCH",
126325
+ /* 208 */ "likeop ::= NOT LIKE_KW|MATCH",
126326
+ /* 209 */ "expr ::= expr likeop expr",
126327
+ /* 210 */ "expr ::= expr likeop expr ESCAPE expr",
126328
+ /* 211 */ "expr ::= expr ISNULL|NOTNULL",
126329
+ /* 212 */ "expr ::= expr NOT NULL",
126330
+ /* 213 */ "expr ::= expr IS expr",
126331
+ /* 214 */ "expr ::= expr IS NOT expr",
126332
+ /* 215 */ "expr ::= NOT expr",
126333
+ /* 216 */ "expr ::= BITNOT expr",
126334
+ /* 217 */ "expr ::= MINUS expr",
126335
+ /* 218 */ "expr ::= PLUS expr",
126336
+ /* 219 */ "between_op ::= BETWEEN",
126337
+ /* 220 */ "between_op ::= NOT BETWEEN",
126338
+ /* 221 */ "expr ::= expr between_op expr AND expr",
126339
+ /* 222 */ "in_op ::= IN",
126340
+ /* 223 */ "in_op ::= NOT IN",
126341
+ /* 224 */ "expr ::= expr in_op LP exprlist RP",
126342
+ /* 225 */ "expr ::= LP select RP",
126343
+ /* 226 */ "expr ::= expr in_op LP select RP",
126344
+ /* 227 */ "expr ::= expr in_op nm dbnm",
126345
+ /* 228 */ "expr ::= EXISTS LP select RP",
126346
+ /* 229 */ "expr ::= CASE case_operand case_exprlist case_else END",
126347
+ /* 230 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
126348
+ /* 231 */ "case_exprlist ::= WHEN expr THEN expr",
126349
+ /* 232 */ "case_else ::= ELSE expr",
126350
+ /* 233 */ "case_else ::=",
126351
+ /* 234 */ "case_operand ::= expr",
126352
+ /* 235 */ "case_operand ::=",
126353
+ /* 236 */ "exprlist ::= nexprlist",
126354
+ /* 237 */ "exprlist ::=",
126355
+ /* 238 */ "nexprlist ::= nexprlist COMMA expr",
126356
+ /* 239 */ "nexprlist ::= expr",
126357
+ /* 240 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
126358
+ /* 241 */ "uniqueflag ::= UNIQUE",
126359
+ /* 242 */ "uniqueflag ::=",
126360
+ /* 243 */ "eidlist_opt ::=",
126361
+ /* 244 */ "eidlist_opt ::= LP eidlist RP",
126362
+ /* 245 */ "eidlist ::= eidlist COMMA nm collate sortorder",
126363
+ /* 246 */ "eidlist ::= nm collate sortorder",
126364
+ /* 247 */ "collate ::=",
126365
+ /* 248 */ "collate ::= COLLATE ID|STRING",
126366
+ /* 249 */ "cmd ::= DROP INDEX ifexists fullname",
126367
+ /* 250 */ "cmd ::= VACUUM",
126368
+ /* 251 */ "cmd ::= VACUUM nm",
126369
+ /* 252 */ "cmd ::= PRAGMA nm dbnm",
126370
+ /* 253 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
126371
+ /* 254 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
126372
+ /* 255 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
126373
+ /* 256 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
126374
+ /* 257 */ "nmnum ::= plus_num",
126375
+ /* 258 */ "nmnum ::= nm",
126376
+ /* 259 */ "nmnum ::= ON",
126377
+ /* 260 */ "nmnum ::= DELETE",
126378
+ /* 261 */ "nmnum ::= DEFAULT",
126379
+ /* 262 */ "plus_num ::= PLUS INTEGER|FLOAT",
126380
+ /* 263 */ "plus_num ::= INTEGER|FLOAT",
126381
+ /* 264 */ "minus_num ::= MINUS INTEGER|FLOAT",
126382
+ /* 265 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
126383
+ /* 266 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
126384
+ /* 267 */ "trigger_time ::= BEFORE",
126385
+ /* 268 */ "trigger_time ::= AFTER",
126386
+ /* 269 */ "trigger_time ::= INSTEAD OF",
126387
+ /* 270 */ "trigger_time ::=",
126388
+ /* 271 */ "trigger_event ::= DELETE|INSERT",
126389
+ /* 272 */ "trigger_event ::= UPDATE",
126390
+ /* 273 */ "trigger_event ::= UPDATE OF idlist",
126391
+ /* 274 */ "foreach_clause ::=",
126392
+ /* 275 */ "foreach_clause ::= FOR EACH ROW",
126393
+ /* 276 */ "when_clause ::=",
126394
+ /* 277 */ "when_clause ::= WHEN expr",
126395
+ /* 278 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
126396
+ /* 279 */ "trigger_cmd_list ::= trigger_cmd SEMI",
126397
+ /* 280 */ "trnm ::= nm",
126398
+ /* 281 */ "trnm ::= nm DOT nm",
126399
+ /* 282 */ "tridxby ::=",
126400
+ /* 283 */ "tridxby ::= INDEXED BY nm",
126401
+ /* 284 */ "tridxby ::= NOT INDEXED",
126402
+ /* 285 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
126403
+ /* 286 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
126404
+ /* 287 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
126405
+ /* 288 */ "trigger_cmd ::= select",
126406
+ /* 289 */ "expr ::= RAISE LP IGNORE RP",
126407
+ /* 290 */ "expr ::= RAISE LP raisetype COMMA nm RP",
126408
+ /* 291 */ "raisetype ::= ROLLBACK",
126409
+ /* 292 */ "raisetype ::= ABORT",
126410
+ /* 293 */ "raisetype ::= FAIL",
126411
+ /* 294 */ "cmd ::= DROP TRIGGER ifexists fullname",
126412
+ /* 295 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
126413
+ /* 296 */ "cmd ::= DETACH database_kw_opt expr",
126414
+ /* 297 */ "key_opt ::=",
126415
+ /* 298 */ "key_opt ::= KEY expr",
126416
+ /* 299 */ "database_kw_opt ::= DATABASE",
126417
+ /* 300 */ "database_kw_opt ::=",
126418
+ /* 301 */ "cmd ::= REINDEX",
126419
+ /* 302 */ "cmd ::= REINDEX nm dbnm",
126420
+ /* 303 */ "cmd ::= ANALYZE",
126421
+ /* 304 */ "cmd ::= ANALYZE nm dbnm",
126422
+ /* 305 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
126423
+ /* 306 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
126424
+ /* 307 */ "add_column_fullname ::= fullname",
126425
+ /* 308 */ "kwcolumn_opt ::=",
126426
+ /* 309 */ "kwcolumn_opt ::= COLUMNKW",
126427
+ /* 310 */ "cmd ::= create_vtab",
126428
+ /* 311 */ "cmd ::= create_vtab LP vtabarglist RP",
126429
+ /* 312 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
126430
+ /* 313 */ "vtabarglist ::= vtabarg",
126431
+ /* 314 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
126432
+ /* 315 */ "vtabarg ::=",
126433
+ /* 316 */ "vtabarg ::= vtabarg vtabargtoken",
126434
+ /* 317 */ "vtabargtoken ::= ANY",
126435
+ /* 318 */ "vtabargtoken ::= lp anylist RP",
126436
+ /* 319 */ "lp ::= LP",
126437
+ /* 320 */ "anylist ::=",
126438
+ /* 321 */ "anylist ::= anylist LP anylist RP",
126439
+ /* 322 */ "anylist ::= anylist ANY",
126440
+ /* 323 */ "with ::=",
126441
+ /* 324 */ "with ::= WITH wqlist",
126442
+ /* 325 */ "with ::= WITH RECURSIVE wqlist",
126443
+ /* 326 */ "wqlist ::= nm eidlist_opt AS LP select RP",
126444
+ /* 327 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
125989126445
};
125990126446
#endif /* NDEBUG */
125991126447
125992126448
125993126449
#if YYSTACKDEPTH<=0
@@ -126063,13 +126519,13 @@
126063126519
** Note: during a reduce, the only symbols destroyed are those
126064126520
** which appear on the RHS of the rule, but which are not used
126065126521
** inside the C code.
126066126522
*/
126067126523
case 163: /* select */
126068
- case 195: /* selectnowith */
126069
- case 196: /* oneselect */
126070
- case 207: /* values */
126524
+ case 196: /* selectnowith */
126525
+ case 197: /* oneselect */
126526
+ case 208: /* values */
126071126527
{
126072126528
sqlite3SelectDelete(pParse->db, (yypminor->yy3));
126073126529
}
126074126530
break;
126075126531
case 174: /* term */
@@ -126076,53 +126532,53 @@
126076126532
case 175: /* expr */
126077126533
{
126078126534
sqlite3ExprDelete(pParse->db, (yypminor->yy346).pExpr);
126079126535
}
126080126536
break;
126081
- case 179: /* idxlist_opt */
126082
- case 188: /* idxlist */
126083
- case 200: /* selcollist */
126084
- case 203: /* groupby_opt */
126085
- case 205: /* orderby_opt */
126086
- case 208: /* nexprlist */
126087
- case 209: /* exprlist */
126088
- case 210: /* sclp */
126089
- case 220: /* sortlist */
126537
+ case 179: /* eidlist_opt */
126538
+ case 188: /* sortlist */
126539
+ case 189: /* eidlist */
126540
+ case 201: /* selcollist */
126541
+ case 204: /* groupby_opt */
126542
+ case 206: /* orderby_opt */
126543
+ case 209: /* nexprlist */
126544
+ case 210: /* exprlist */
126545
+ case 211: /* sclp */
126090126546
case 221: /* setlist */
126091126547
case 228: /* case_exprlist */
126092126548
{
126093126549
sqlite3ExprListDelete(pParse->db, (yypminor->yy14));
126094126550
}
126095126551
break;
126096
- case 194: /* fullname */
126097
- case 201: /* from */
126098
- case 212: /* seltablist */
126099
- case 213: /* stl_prefix */
126552
+ case 195: /* fullname */
126553
+ case 202: /* from */
126554
+ case 213: /* seltablist */
126555
+ case 214: /* stl_prefix */
126100126556
{
126101126557
sqlite3SrcListDelete(pParse->db, (yypminor->yy65));
126102126558
}
126103126559
break;
126104
- case 197: /* with */
126560
+ case 198: /* with */
126105126561
case 252: /* wqlist */
126106126562
{
126107126563
sqlite3WithDelete(pParse->db, (yypminor->yy59));
126108126564
}
126109126565
break;
126110
- case 202: /* where_opt */
126111
- case 204: /* having_opt */
126112
- case 216: /* on_opt */
126566
+ case 203: /* where_opt */
126567
+ case 205: /* having_opt */
126568
+ case 217: /* on_opt */
126113126569
case 227: /* case_operand */
126114126570
case 229: /* case_else */
126115126571
case 238: /* when_clause */
126116126572
case 243: /* key_opt */
126117126573
{
126118126574
sqlite3ExprDelete(pParse->db, (yypminor->yy132));
126119126575
}
126120126576
break;
126121
- case 217: /* using_opt */
126122
- case 219: /* idlist */
126123
- case 223: /* inscollist_opt */
126577
+ case 218: /* using_opt */
126578
+ case 220: /* idlist */
126579
+ case 223: /* idlist_opt */
126124126580
{
126125126581
sqlite3IdListDelete(pParse->db, (yypminor->yy408));
126126126582
}
126127126583
break;
126128126584
case 234: /* trigger_cmd_list */
@@ -126218,14 +126674,14 @@
126218126674
YYCODETYPE iLookAhead /* The look-ahead token */
126219126675
){
126220126676
int i;
126221126677
int stateno = pParser->yystack[pParser->yyidx].stateno;
126222126678
126223
- if( stateno>YY_SHIFT_COUNT
126224
- || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
126225
- return yy_default[stateno];
126226
- }
126679
+ if( stateno>=YY_MIN_REDUCE ) return stateno;
126680
+ assert( stateno <= YY_SHIFT_COUNT );
126681
+ i = yy_shift_ofst[stateno];
126682
+ if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
126227126683
assert( iLookAhead!=YYNOCODE );
126228126684
i += iLookAhead;
126229126685
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
126230126686
if( iLookAhead>0 ){
126231126687
#ifdef YYFALLBACK
@@ -126324,11 +126780,33 @@
126324126780
sqlite3ErrorMsg(pParse, "parser stack overflow");
126325126781
sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
126326126782
}
126327126783
126328126784
/*
126329
-** Perform a shift action.
126785
+** Print tracing information for a SHIFT action
126786
+*/
126787
+#ifndef NDEBUG
126788
+static void yyTraceShift(yyParser *yypParser, int yyNewState){
126789
+ if( yyTraceFILE ){
126790
+ int i;
126791
+ if( yyNewState<YYNSTATE ){
126792
+ fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
126793
+ fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
126794
+ for(i=1; i<=yypParser->yyidx; i++)
126795
+ fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
126796
+ fprintf(yyTraceFILE,"\n");
126797
+ }else{
126798
+ fprintf(yyTraceFILE,"%sShift *\n",yyTracePrompt);
126799
+ }
126800
+ }
126801
+}
126802
+#else
126803
+# define yyTraceShift(X,Y)
126804
+#endif
126805
+
126806
+/*
126807
+** Perform a shift action. Return the number of errors.
126330126808
*/
126331126809
static void yy_shift(
126332126810
yyParser *yypParser, /* The parser to be shifted */
126333126811
int yyNewState, /* The new state to shift in */
126334126812
int yyMajor, /* The major token to shift in */
@@ -126357,20 +126835,11 @@
126357126835
#endif
126358126836
yytos = &yypParser->yystack[yypParser->yyidx];
126359126837
yytos->stateno = (YYACTIONTYPE)yyNewState;
126360126838
yytos->major = (YYCODETYPE)yyMajor;
126361126839
yytos->minor = *yypMinor;
126362
-#ifndef NDEBUG
126363
- if( yyTraceFILE && yypParser->yyidx>0 ){
126364
- int i;
126365
- fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
126366
- fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
126367
- for(i=1; i<=yypParser->yyidx; i++)
126368
- fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
126369
- fprintf(yyTraceFILE,"\n");
126370
- }
126371
-#endif
126840
+ yyTraceShift(yypParser, yyNewState);
126372126841
}
126373126842
126374126843
/* The following table contains information about every rule that
126375126844
** is used during the reduce.
126376126845
*/
@@ -126473,96 +126942,97 @@
126473126942
{ 187, 2 },
126474126943
{ 187, 7 },
126475126944
{ 187, 5 },
126476126945
{ 187, 5 },
126477126946
{ 187, 10 },
126478
- { 189, 0 },
126479
- { 189, 1 },
126947
+ { 190, 0 },
126948
+ { 190, 1 },
126480126949
{ 176, 0 },
126481126950
{ 176, 3 },
126482
- { 190, 0 },
126483
- { 190, 2 },
126484
- { 191, 1 },
126485
- { 191, 1 },
126486
- { 191, 1 },
126951
+ { 191, 0 },
126952
+ { 191, 2 },
126953
+ { 192, 1 },
126954
+ { 192, 1 },
126955
+ { 192, 1 },
126487126956
{ 149, 4 },
126488
- { 193, 2 },
126489
- { 193, 0 },
126490
- { 149, 8 },
126957
+ { 194, 2 },
126958
+ { 194, 0 },
126959
+ { 149, 9 },
126491126960
{ 149, 4 },
126492126961
{ 149, 1 },
126493126962
{ 163, 2 },
126494
- { 195, 1 },
126495
- { 195, 3 },
126496
- { 198, 1 },
126497
- { 198, 2 },
126498
- { 198, 1 },
126499
- { 196, 9 },
126500
- { 196, 1 },
126501
- { 207, 4 },
126502
- { 207, 5 },
126503
- { 199, 1 },
126504
- { 199, 1 },
126505
- { 199, 0 },
126506
- { 210, 2 },
126507
- { 210, 0 },
126508
- { 200, 3 },
126509
- { 200, 2 },
126510
- { 200, 4 },
126511
- { 211, 2 },
126512
- { 211, 1 },
126513
- { 211, 0 },
126514
- { 201, 0 },
126515
- { 201, 2 },
126516
- { 213, 2 },
126517
- { 213, 0 },
126518
- { 212, 7 },
126519
- { 212, 7 },
126520
- { 212, 7 },
126963
+ { 196, 1 },
126964
+ { 196, 3 },
126965
+ { 199, 1 },
126966
+ { 199, 2 },
126967
+ { 199, 1 },
126968
+ { 197, 9 },
126969
+ { 197, 1 },
126970
+ { 208, 4 },
126971
+ { 208, 5 },
126972
+ { 200, 1 },
126973
+ { 200, 1 },
126974
+ { 200, 0 },
126975
+ { 211, 2 },
126976
+ { 211, 0 },
126977
+ { 201, 3 },
126978
+ { 201, 2 },
126979
+ { 201, 4 },
126980
+ { 212, 2 },
126981
+ { 212, 1 },
126982
+ { 212, 0 },
126983
+ { 202, 0 },
126984
+ { 202, 2 },
126985
+ { 214, 2 },
126986
+ { 214, 0 },
126987
+ { 213, 7 },
126988
+ { 213, 9 },
126989
+ { 213, 7 },
126990
+ { 213, 7 },
126521126991
{ 159, 0 },
126522126992
{ 159, 2 },
126523
- { 194, 2 },
126524
- { 214, 1 },
126525
- { 214, 2 },
126526
- { 214, 3 },
126527
- { 214, 4 },
126528
- { 216, 2 },
126993
+ { 195, 2 },
126994
+ { 215, 1 },
126995
+ { 215, 2 },
126996
+ { 215, 3 },
126997
+ { 215, 4 },
126998
+ { 217, 2 },
126999
+ { 217, 0 },
126529127000
{ 216, 0 },
126530
- { 215, 0 },
126531
- { 215, 3 },
126532
- { 215, 2 },
126533
- { 217, 4 },
126534
- { 217, 0 },
126535
- { 205, 0 },
126536
- { 205, 3 },
126537
- { 220, 4 },
126538
- { 220, 2 },
127001
+ { 216, 3 },
127002
+ { 216, 2 },
127003
+ { 218, 4 },
127004
+ { 218, 0 },
127005
+ { 206, 0 },
127006
+ { 206, 3 },
127007
+ { 188, 4 },
127008
+ { 188, 2 },
126539127009
{ 177, 1 },
126540127010
{ 177, 1 },
126541127011
{ 177, 0 },
126542
- { 203, 0 },
126543
- { 203, 3 },
126544127012
{ 204, 0 },
126545
- { 204, 2 },
126546
- { 206, 0 },
126547
- { 206, 2 },
126548
- { 206, 4 },
126549
- { 206, 4 },
127013
+ { 204, 3 },
127014
+ { 205, 0 },
127015
+ { 205, 2 },
127016
+ { 207, 0 },
127017
+ { 207, 2 },
127018
+ { 207, 4 },
127019
+ { 207, 4 },
126550127020
{ 149, 6 },
126551
- { 202, 0 },
126552
- { 202, 2 },
127021
+ { 203, 0 },
127022
+ { 203, 2 },
126553127023
{ 149, 8 },
126554127024
{ 221, 5 },
126555127025
{ 221, 3 },
126556127026
{ 149, 6 },
126557127027
{ 149, 7 },
126558127028
{ 222, 2 },
126559127029
{ 222, 1 },
126560127030
{ 223, 0 },
126561127031
{ 223, 3 },
126562
- { 219, 3 },
126563
- { 219, 1 },
127032
+ { 220, 3 },
127033
+ { 220, 1 },
126564127034
{ 175, 1 },
126565127035
{ 175, 3 },
126566127036
{ 174, 1 },
126567127037
{ 175, 1 },
126568127038
{ 175, 1 },
@@ -126611,21 +127081,21 @@
126611127081
{ 228, 4 },
126612127082
{ 229, 2 },
126613127083
{ 229, 0 },
126614127084
{ 227, 1 },
126615127085
{ 227, 0 },
127086
+ { 210, 1 },
127087
+ { 210, 0 },
127088
+ { 209, 3 },
126616127089
{ 209, 1 },
126617
- { 209, 0 },
126618
- { 208, 3 },
126619
- { 208, 1 },
126620127090
{ 149, 12 },
126621127091
{ 230, 1 },
126622127092
{ 230, 0 },
126623127093
{ 179, 0 },
126624127094
{ 179, 3 },
126625
- { 188, 5 },
126626
- { 188, 3 },
127095
+ { 189, 5 },
127096
+ { 189, 3 },
126627127097
{ 231, 0 },
126628127098
{ 231, 2 },
126629127099
{ 149, 4 },
126630127100
{ 149, 1 },
126631127101
{ 149, 2 },
@@ -126666,13 +127136,13 @@
126666127136
{ 239, 5 },
126667127137
{ 239, 5 },
126668127138
{ 239, 1 },
126669127139
{ 175, 4 },
126670127140
{ 175, 6 },
126671
- { 192, 1 },
126672
- { 192, 1 },
126673
- { 192, 1 },
127141
+ { 193, 1 },
127142
+ { 193, 1 },
127143
+ { 193, 1 },
126674127144
{ 149, 4 },
126675127145
{ 149, 6 },
126676127146
{ 149, 3 },
126677127147
{ 243, 0 },
126678127148
{ 243, 2 },
@@ -126698,13 +127168,13 @@
126698127168
{ 249, 3 },
126699127169
{ 250, 1 },
126700127170
{ 251, 0 },
126701127171
{ 251, 4 },
126702127172
{ 251, 2 },
126703
- { 197, 0 },
126704
- { 197, 2 },
126705
- { 197, 3 },
127173
+ { 198, 0 },
127174
+ { 198, 2 },
127175
+ { 198, 3 },
126706127176
{ 252, 6 },
126707127177
{ 252, 8 },
126708127178
};
126709127179
126710127180
static void yy_accept(yyParser*); /* Forward Declaration */
@@ -126725,12 +127195,13 @@
126725127195
sqlite3ParserARG_FETCH;
126726127196
yymsp = &yypParser->yystack[yypParser->yyidx];
126727127197
#ifndef NDEBUG
126728127198
if( yyTraceFILE && yyruleno>=0
126729127199
&& yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
126730
- fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
126731
- yyRuleName[yyruleno]);
127200
+ yysize = yyRuleInfo[yyruleno].nrhs;
127201
+ fprintf(yyTraceFILE, "%sReduce [%s] -> state %d.\n", yyTracePrompt,
127202
+ yyRuleName[yyruleno], yymsp[-yysize].stateno);
126732127203
}
126733127204
#endif /* NDEBUG */
126734127205
126735127206
/* Silence complaints from purify about yygotominor being uninitialized
126736127207
** in some cases when it is copied into the stack after the following
@@ -126823,21 +127294,23 @@
126823127294
case 81: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==81);
126824127295
case 83: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==83);
126825127296
case 85: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==85);
126826127297
case 97: /* defer_subclause_opt ::= */ yytestcase(yyruleno==97);
126827127298
case 108: /* ifexists ::= */ yytestcase(yyruleno==108);
126828
- case 218: /* between_op ::= BETWEEN */ yytestcase(yyruleno==218);
126829
- case 221: /* in_op ::= IN */ yytestcase(yyruleno==221);
127299
+ case 219: /* between_op ::= BETWEEN */ yytestcase(yyruleno==219);
127300
+ case 222: /* in_op ::= IN */ yytestcase(yyruleno==222);
127301
+ case 247: /* collate ::= */ yytestcase(yyruleno==247);
126830127302
{yygotominor.yy328 = 0;}
126831127303
break;
126832127304
case 29: /* ifnotexists ::= IF NOT EXISTS */
126833127305
case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
126834127306
case 69: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==69);
126835127307
case 84: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==84);
126836127308
case 107: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==107);
126837
- case 219: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==219);
126838
- case 222: /* in_op ::= NOT IN */ yytestcase(yyruleno==222);
127309
+ case 220: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==220);
127310
+ case 223: /* in_op ::= NOT IN */ yytestcase(yyruleno==223);
127311
+ case 248: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==248);
126839127312
{yygotominor.yy328 = 1;}
126840127313
break;
126841127314
case 32: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
126842127315
{
126843127316
sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy186,0);
@@ -126880,22 +127353,21 @@
126880127353
case 42: /* nm ::= JOIN_KW */ yytestcase(yyruleno==42);
126881127354
case 45: /* typetoken ::= typename */ yytestcase(yyruleno==45);
126882127355
case 48: /* typename ::= ID|STRING */ yytestcase(yyruleno==48);
126883127356
case 130: /* as ::= AS nm */ yytestcase(yyruleno==130);
126884127357
case 131: /* as ::= ID|STRING */ yytestcase(yyruleno==131);
126885
- case 141: /* dbnm ::= DOT nm */ yytestcase(yyruleno==141);
126886
- case 150: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==150);
126887
- case 247: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==247);
126888
- case 256: /* nmnum ::= plus_num */ yytestcase(yyruleno==256);
126889
- case 257: /* nmnum ::= nm */ yytestcase(yyruleno==257);
126890
- case 258: /* nmnum ::= ON */ yytestcase(yyruleno==258);
126891
- case 259: /* nmnum ::= DELETE */ yytestcase(yyruleno==259);
126892
- case 260: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==260);
126893
- case 261: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==261);
126894
- case 262: /* plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==262);
126895
- case 263: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==263);
126896
- case 279: /* trnm ::= nm */ yytestcase(yyruleno==279);
127358
+ case 142: /* dbnm ::= DOT nm */ yytestcase(yyruleno==142);
127359
+ case 151: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==151);
127360
+ case 257: /* nmnum ::= plus_num */ yytestcase(yyruleno==257);
127361
+ case 258: /* nmnum ::= nm */ yytestcase(yyruleno==258);
127362
+ case 259: /* nmnum ::= ON */ yytestcase(yyruleno==259);
127363
+ case 260: /* nmnum ::= DELETE */ yytestcase(yyruleno==260);
127364
+ case 261: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==261);
127365
+ case 262: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==262);
127366
+ case 263: /* plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==263);
127367
+ case 264: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==264);
127368
+ case 280: /* trnm ::= nm */ yytestcase(yyruleno==280);
126897127369
{yygotominor.yy0 = yymsp[0].minor.yy0;}
126898127370
break;
126899127371
case 44: /* type ::= typetoken */
126900127372
{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
126901127373
break;
@@ -126951,11 +127423,11 @@
126951127423
{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy328,0,0,0,0);}
126952127424
break;
126953127425
case 64: /* ccons ::= CHECK LP expr RP */
126954127426
{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy346.pExpr);}
126955127427
break;
126956
- case 65: /* ccons ::= REFERENCES nm idxlist_opt refargs */
127428
+ case 65: /* ccons ::= REFERENCES nm eidlist_opt refargs */
126957127429
{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy14,yymsp[0].minor.yy328);}
126958127430
break;
126959127431
case 66: /* ccons ::= defer_subclause */
126960127432
{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy328);}
126961127433
break;
@@ -127006,20 +127478,20 @@
127006127478
{yygotominor.yy0 = yymsp[-1].minor.yy0;}
127007127479
break;
127008127480
case 90: /* tconscomma ::= COMMA */
127009127481
{pParse->constraintName.n = 0;}
127010127482
break;
127011
- case 93: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
127483
+ case 93: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
127012127484
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy14,yymsp[0].minor.yy328,yymsp[-2].minor.yy328,0);}
127013127485
break;
127014
- case 94: /* tcons ::= UNIQUE LP idxlist RP onconf */
127486
+ case 94: /* tcons ::= UNIQUE LP sortlist RP onconf */
127015127487
{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy14,yymsp[0].minor.yy328,0,0,0,0);}
127016127488
break;
127017127489
case 95: /* tcons ::= CHECK LP expr RP onconf */
127018127490
{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy346.pExpr);}
127019127491
break;
127020
- case 96: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
127492
+ case 96: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
127021127493
{
127022127494
sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy14, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[-1].minor.yy328);
127023127495
sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy328);
127024127496
}
127025127497
break;
@@ -127041,13 +127513,13 @@
127041127513
case 106: /* cmd ::= DROP TABLE ifexists fullname */
127042127514
{
127043127515
sqlite3DropTable(pParse, yymsp[0].minor.yy65, 0, yymsp[-1].minor.yy328);
127044127516
}
127045127517
break;
127046
- case 109: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
127518
+ case 109: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
127047127519
{
127048
- sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy3, yymsp[-6].minor.yy328, yymsp[-4].minor.yy328);
127520
+ sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[0].minor.yy3, yymsp[-7].minor.yy328, yymsp[-5].minor.yy328);
127049127521
}
127050127522
break;
127051127523
case 110: /* cmd ::= DROP VIEW ifexists fullname */
127052127524
{
127053127525
sqlite3DropTable(pParse, yymsp[0].minor.yy65, 1, yymsp[-1].minor.yy328);
@@ -127160,18 +127632,18 @@
127160127632
break;
127161127633
case 124: /* distinct ::= */
127162127634
{yygotominor.yy381 = 0;}
127163127635
break;
127164127636
case 125: /* sclp ::= selcollist COMMA */
127165
- case 243: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==243);
127637
+ case 244: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==244);
127166127638
{yygotominor.yy14 = yymsp[-1].minor.yy14;}
127167127639
break;
127168127640
case 126: /* sclp ::= */
127169
- case 154: /* orderby_opt ::= */ yytestcase(yyruleno==154);
127170
- case 161: /* groupby_opt ::= */ yytestcase(yyruleno==161);
127171
- case 236: /* exprlist ::= */ yytestcase(yyruleno==236);
127172
- case 242: /* idxlist_opt ::= */ yytestcase(yyruleno==242);
127641
+ case 155: /* orderby_opt ::= */ yytestcase(yyruleno==155);
127642
+ case 162: /* groupby_opt ::= */ yytestcase(yyruleno==162);
127643
+ case 237: /* exprlist ::= */ yytestcase(yyruleno==237);
127644
+ case 243: /* eidlist_opt ::= */ yytestcase(yyruleno==243);
127173127645
{yygotominor.yy14 = 0;}
127174127646
break;
127175127647
case 127: /* selcollist ::= sclp expr as */
127176127648
{
127177127649
yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy14, yymsp[-1].minor.yy346.pExpr);
@@ -127206,11 +127678,11 @@
127206127678
}
127207127679
break;
127208127680
case 135: /* stl_prefix ::= seltablist joinop */
127209127681
{
127210127682
yygotominor.yy65 = yymsp[-1].minor.yy65;
127211
- if( ALWAYS(yygotominor.yy65 && yygotominor.yy65->nSrc>0) ) yygotominor.yy65->a[yygotominor.yy65->nSrc-1].jointype = (u8)yymsp[0].minor.yy328;
127683
+ if( ALWAYS(yygotominor.yy65 && yygotominor.yy65->nSrc>0) ) yygotominor.yy65->a[yygotominor.yy65->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy328;
127212127684
}
127213127685
break;
127214127686
case 136: /* stl_prefix ::= */
127215127687
{yygotominor.yy65 = 0;}
127216127688
break;
@@ -127218,16 +127690,22 @@
127218127690
{
127219127691
yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127220127692
sqlite3SrcListIndexedBy(pParse, yygotominor.yy65, &yymsp[-2].minor.yy0);
127221127693
}
127222127694
break;
127223
- case 138: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
127695
+ case 138: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
127696
+{
127697
+ yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy65,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127698
+ sqlite3SrcListFuncArgs(pParse, yygotominor.yy65, yymsp[-4].minor.yy14);
127699
+}
127700
+ break;
127701
+ case 139: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
127224127702
{
127225127703
yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy3,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127226127704
}
127227127705
break;
127228
- case 139: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
127706
+ case 140: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
127229127707
{
127230127708
if( yymsp[-6].minor.yy65==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy132==0 && yymsp[0].minor.yy408==0 ){
127231127709
yygotominor.yy65 = yymsp[-4].minor.yy65;
127232127710
}else if( yymsp[-4].minor.yy65->nSrc==1 ){
127233127711
yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
@@ -127247,175 +127725,177 @@
127247127725
pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy65,0,0,0,0,SF_NestedFrom,0,0);
127248127726
yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127249127727
}
127250127728
}
127251127729
break;
127252
- case 140: /* dbnm ::= */
127253
- case 149: /* indexed_opt ::= */ yytestcase(yyruleno==149);
127730
+ case 141: /* dbnm ::= */
127731
+ case 150: /* indexed_opt ::= */ yytestcase(yyruleno==150);
127254127732
{yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
127255127733
break;
127256
- case 142: /* fullname ::= nm dbnm */
127734
+ case 143: /* fullname ::= nm dbnm */
127257127735
{yygotominor.yy65 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
127258127736
break;
127259
- case 143: /* joinop ::= COMMA|JOIN */
127737
+ case 144: /* joinop ::= COMMA|JOIN */
127260127738
{ yygotominor.yy328 = JT_INNER; }
127261127739
break;
127262
- case 144: /* joinop ::= JOIN_KW JOIN */
127740
+ case 145: /* joinop ::= JOIN_KW JOIN */
127263127741
{ yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
127264127742
break;
127265
- case 145: /* joinop ::= JOIN_KW nm JOIN */
127743
+ case 146: /* joinop ::= JOIN_KW nm JOIN */
127266127744
{ yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
127267127745
break;
127268
- case 146: /* joinop ::= JOIN_KW nm nm JOIN */
127746
+ case 147: /* joinop ::= JOIN_KW nm nm JOIN */
127269127747
{ yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
127270127748
break;
127271
- case 147: /* on_opt ::= ON expr */
127272
- case 164: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==164);
127273
- case 171: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==171);
127274
- case 231: /* case_else ::= ELSE expr */ yytestcase(yyruleno==231);
127275
- case 233: /* case_operand ::= expr */ yytestcase(yyruleno==233);
127749
+ case 148: /* on_opt ::= ON expr */
127750
+ case 165: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==165);
127751
+ case 172: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==172);
127752
+ case 232: /* case_else ::= ELSE expr */ yytestcase(yyruleno==232);
127753
+ case 234: /* case_operand ::= expr */ yytestcase(yyruleno==234);
127276127754
{yygotominor.yy132 = yymsp[0].minor.yy346.pExpr;}
127277127755
break;
127278
- case 148: /* on_opt ::= */
127279
- case 163: /* having_opt ::= */ yytestcase(yyruleno==163);
127280
- case 170: /* where_opt ::= */ yytestcase(yyruleno==170);
127281
- case 232: /* case_else ::= */ yytestcase(yyruleno==232);
127282
- case 234: /* case_operand ::= */ yytestcase(yyruleno==234);
127756
+ case 149: /* on_opt ::= */
127757
+ case 164: /* having_opt ::= */ yytestcase(yyruleno==164);
127758
+ case 171: /* where_opt ::= */ yytestcase(yyruleno==171);
127759
+ case 233: /* case_else ::= */ yytestcase(yyruleno==233);
127760
+ case 235: /* case_operand ::= */ yytestcase(yyruleno==235);
127283127761
{yygotominor.yy132 = 0;}
127284127762
break;
127285
- case 151: /* indexed_opt ::= NOT INDEXED */
127763
+ case 152: /* indexed_opt ::= NOT INDEXED */
127286127764
{yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
127287127765
break;
127288
- case 152: /* using_opt ::= USING LP idlist RP */
127289
- case 180: /* inscollist_opt ::= LP idlist RP */ yytestcase(yyruleno==180);
127766
+ case 153: /* using_opt ::= USING LP idlist RP */
127767
+ case 181: /* idlist_opt ::= LP idlist RP */ yytestcase(yyruleno==181);
127290127768
{yygotominor.yy408 = yymsp[-1].minor.yy408;}
127291127769
break;
127292
- case 153: /* using_opt ::= */
127293
- case 179: /* inscollist_opt ::= */ yytestcase(yyruleno==179);
127770
+ case 154: /* using_opt ::= */
127771
+ case 180: /* idlist_opt ::= */ yytestcase(yyruleno==180);
127294127772
{yygotominor.yy408 = 0;}
127295127773
break;
127296
- case 155: /* orderby_opt ::= ORDER BY sortlist */
127297
- case 162: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==162);
127298
- case 235: /* exprlist ::= nexprlist */ yytestcase(yyruleno==235);
127774
+ case 156: /* orderby_opt ::= ORDER BY sortlist */
127775
+ case 163: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==163);
127776
+ case 236: /* exprlist ::= nexprlist */ yytestcase(yyruleno==236);
127299127777
{yygotominor.yy14 = yymsp[0].minor.yy14;}
127300127778
break;
127301
- case 156: /* sortlist ::= sortlist COMMA expr sortorder */
127779
+ case 157: /* sortlist ::= sortlist COMMA expr sortorder */
127302127780
{
127303127781
yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy14,yymsp[-1].minor.yy346.pExpr);
127304
- if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
127782
+ sqlite3ExprListSetSortOrder(yygotominor.yy14,yymsp[0].minor.yy328);
127305127783
}
127306127784
break;
127307
- case 157: /* sortlist ::= expr sortorder */
127785
+ case 158: /* sortlist ::= expr sortorder */
127308127786
{
127309127787
yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy346.pExpr);
127310
- if( yygotominor.yy14 && ALWAYS(yygotominor.yy14->a) ) yygotominor.yy14->a[0].sortOrder = (u8)yymsp[0].minor.yy328;
127788
+ sqlite3ExprListSetSortOrder(yygotominor.yy14,yymsp[0].minor.yy328);
127311127789
}
127312127790
break;
127313
- case 158: /* sortorder ::= ASC */
127314
- case 160: /* sortorder ::= */ yytestcase(yyruleno==160);
127791
+ case 159: /* sortorder ::= ASC */
127315127792
{yygotominor.yy328 = SQLITE_SO_ASC;}
127316127793
break;
127317
- case 159: /* sortorder ::= DESC */
127794
+ case 160: /* sortorder ::= DESC */
127318127795
{yygotominor.yy328 = SQLITE_SO_DESC;}
127319127796
break;
127320
- case 165: /* limit_opt ::= */
127797
+ case 161: /* sortorder ::= */
127798
+{yygotominor.yy328 = SQLITE_SO_UNDEFINED;}
127799
+ break;
127800
+ case 166: /* limit_opt ::= */
127321127801
{yygotominor.yy476.pLimit = 0; yygotominor.yy476.pOffset = 0;}
127322127802
break;
127323
- case 166: /* limit_opt ::= LIMIT expr */
127803
+ case 167: /* limit_opt ::= LIMIT expr */
127324127804
{yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr; yygotominor.yy476.pOffset = 0;}
127325127805
break;
127326
- case 167: /* limit_opt ::= LIMIT expr OFFSET expr */
127806
+ case 168: /* limit_opt ::= LIMIT expr OFFSET expr */
127327127807
{yygotominor.yy476.pLimit = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pOffset = yymsp[0].minor.yy346.pExpr;}
127328127808
break;
127329
- case 168: /* limit_opt ::= LIMIT expr COMMA expr */
127809
+ case 169: /* limit_opt ::= LIMIT expr COMMA expr */
127330127810
{yygotominor.yy476.pOffset = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr;}
127331127811
break;
127332
- case 169: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
127812
+ case 170: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
127333127813
{
127334127814
sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
127335127815
sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy65, &yymsp[-1].minor.yy0);
127336127816
sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy65,yymsp[0].minor.yy132);
127337127817
}
127338127818
break;
127339
- case 172: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
127819
+ case 173: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
127340127820
{
127341127821
sqlite3WithPush(pParse, yymsp[-7].minor.yy59, 1);
127342127822
sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy65, &yymsp[-3].minor.yy0);
127343127823
sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy14,"set list");
127344127824
sqlite3Update(pParse,yymsp[-4].minor.yy65,yymsp[-1].minor.yy14,yymsp[0].minor.yy132,yymsp[-5].minor.yy186);
127345127825
}
127346127826
break;
127347
- case 173: /* setlist ::= setlist COMMA nm EQ expr */
127827
+ case 174: /* setlist ::= setlist COMMA nm EQ expr */
127348127828
{
127349127829
yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy14, yymsp[0].minor.yy346.pExpr);
127350127830
sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127351127831
}
127352127832
break;
127353
- case 174: /* setlist ::= nm EQ expr */
127833
+ case 175: /* setlist ::= nm EQ expr */
127354127834
{
127355127835
yygotominor.yy14 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy346.pExpr);
127356127836
sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127357127837
}
127358127838
break;
127359
- case 175: /* cmd ::= with insert_cmd INTO fullname inscollist_opt select */
127839
+ case 176: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */
127360127840
{
127361127841
sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
127362127842
sqlite3Insert(pParse, yymsp[-2].minor.yy65, yymsp[0].minor.yy3, yymsp[-1].minor.yy408, yymsp[-4].minor.yy186);
127363127843
}
127364127844
break;
127365
- case 176: /* cmd ::= with insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
127845
+ case 177: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
127366127846
{
127367127847
sqlite3WithPush(pParse, yymsp[-6].minor.yy59, 1);
127368127848
sqlite3Insert(pParse, yymsp[-3].minor.yy65, 0, yymsp[-2].minor.yy408, yymsp[-5].minor.yy186);
127369127849
}
127370127850
break;
127371
- case 177: /* insert_cmd ::= INSERT orconf */
127851
+ case 178: /* insert_cmd ::= INSERT orconf */
127372127852
{yygotominor.yy186 = yymsp[0].minor.yy186;}
127373127853
break;
127374
- case 178: /* insert_cmd ::= REPLACE */
127854
+ case 179: /* insert_cmd ::= REPLACE */
127375127855
{yygotominor.yy186 = OE_Replace;}
127376127856
break;
127377
- case 181: /* idlist ::= idlist COMMA nm */
127857
+ case 182: /* idlist ::= idlist COMMA nm */
127378127858
{yygotominor.yy408 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy408,&yymsp[0].minor.yy0);}
127379127859
break;
127380
- case 182: /* idlist ::= nm */
127860
+ case 183: /* idlist ::= nm */
127381127861
{yygotominor.yy408 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
127382127862
break;
127383
- case 183: /* expr ::= term */
127863
+ case 184: /* expr ::= term */
127384127864
{yygotominor.yy346 = yymsp[0].minor.yy346;}
127385127865
break;
127386
- case 184: /* expr ::= LP expr RP */
127866
+ case 185: /* expr ::= LP expr RP */
127387127867
{yygotominor.yy346.pExpr = yymsp[-1].minor.yy346.pExpr; spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
127388127868
break;
127389
- case 185: /* term ::= NULL */
127390
- case 190: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==190);
127391
- case 191: /* term ::= STRING */ yytestcase(yyruleno==191);
127869
+ case 186: /* term ::= NULL */
127870
+ case 191: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==191);
127871
+ case 192: /* term ::= STRING */ yytestcase(yyruleno==192);
127392127872
{spanExpr(&yygotominor.yy346, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
127393127873
break;
127394
- case 186: /* expr ::= ID|INDEXED */
127395
- case 187: /* expr ::= JOIN_KW */ yytestcase(yyruleno==187);
127874
+ case 187: /* expr ::= ID|INDEXED */
127875
+ case 188: /* expr ::= JOIN_KW */ yytestcase(yyruleno==188);
127396127876
{spanExpr(&yygotominor.yy346, pParse, TK_ID, &yymsp[0].minor.yy0);}
127397127877
break;
127398
- case 188: /* expr ::= nm DOT nm */
127878
+ case 189: /* expr ::= nm DOT nm */
127399127879
{
127400127880
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
127401127881
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
127402127882
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
127403127883
spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
127404127884
}
127405127885
break;
127406
- case 189: /* expr ::= nm DOT nm DOT nm */
127886
+ case 190: /* expr ::= nm DOT nm DOT nm */
127407127887
{
127408127888
Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
127409127889
Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
127410127890
Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
127411127891
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
127412127892
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
127413127893
spanSet(&yygotominor.yy346,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
127414127894
}
127415127895
break;
127416
- case 192: /* expr ::= VARIABLE */
127896
+ case 193: /* expr ::= VARIABLE */
127417127897
{
127418127898
if( yymsp[0].minor.yy0.n>=2 && yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1]) ){
127419127899
/* When doing a nested parse, one can include terms in an expression
127420127900
** that look like this: #1 #2 ... These terms refer to registers
127421127901
** in the virtual machine. #N is the N-th register. */
@@ -127431,24 +127911,24 @@
127431127911
sqlite3ExprAssignVarNumber(pParse, yygotominor.yy346.pExpr);
127432127912
}
127433127913
spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
127434127914
}
127435127915
break;
127436
- case 193: /* expr ::= expr COLLATE ID|STRING */
127916
+ case 194: /* expr ::= expr COLLATE ID|STRING */
127437127917
{
127438127918
yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0, 1);
127439127919
yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
127440127920
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127441127921
}
127442127922
break;
127443
- case 194: /* expr ::= CAST LP expr AS typetoken RP */
127923
+ case 195: /* expr ::= CAST LP expr AS typetoken RP */
127444127924
{
127445127925
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy346.pExpr, 0, &yymsp[-1].minor.yy0);
127446127926
spanSet(&yygotominor.yy346,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
127447127927
}
127448127928
break;
127449
- case 195: /* expr ::= ID|INDEXED LP distinct exprlist RP */
127929
+ case 196: /* expr ::= ID|INDEXED LP distinct exprlist RP */
127450127930
{
127451127931
if( yymsp[-1].minor.yy14 && yymsp[-1].minor.yy14->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
127452127932
sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
127453127933
}
127454127934
yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy14, &yymsp[-4].minor.yy0);
@@ -127456,39 +127936,39 @@
127456127936
if( yymsp[-2].minor.yy381==SF_Distinct && yygotominor.yy346.pExpr ){
127457127937
yygotominor.yy346.pExpr->flags |= EP_Distinct;
127458127938
}
127459127939
}
127460127940
break;
127461
- case 196: /* expr ::= ID|INDEXED LP STAR RP */
127941
+ case 197: /* expr ::= ID|INDEXED LP STAR RP */
127462127942
{
127463127943
yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
127464127944
spanSet(&yygotominor.yy346,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
127465127945
}
127466127946
break;
127467
- case 197: /* term ::= CTIME_KW */
127947
+ case 198: /* term ::= CTIME_KW */
127468127948
{
127469127949
yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
127470127950
spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
127471127951
}
127472127952
break;
127473
- case 198: /* expr ::= expr AND expr */
127474
- case 199: /* expr ::= expr OR expr */ yytestcase(yyruleno==199);
127475
- case 200: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==200);
127476
- case 201: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==201);
127477
- case 202: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==202);
127478
- case 203: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==203);
127479
- case 204: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==204);
127480
- case 205: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==205);
127953
+ case 199: /* expr ::= expr AND expr */
127954
+ case 200: /* expr ::= expr OR expr */ yytestcase(yyruleno==200);
127955
+ case 201: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==201);
127956
+ case 202: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==202);
127957
+ case 203: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==203);
127958
+ case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204);
127959
+ case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205);
127960
+ case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206);
127481127961
{spanBinaryExpr(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);}
127482127962
break;
127483
- case 206: /* likeop ::= LIKE_KW|MATCH */
127963
+ case 207: /* likeop ::= LIKE_KW|MATCH */
127484127964
{yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 0;}
127485127965
break;
127486
- case 207: /* likeop ::= NOT LIKE_KW|MATCH */
127966
+ case 208: /* likeop ::= NOT LIKE_KW|MATCH */
127487127967
{yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 1;}
127488127968
break;
127489
- case 208: /* expr ::= expr likeop expr */
127969
+ case 209: /* expr ::= expr likeop expr */
127490127970
{
127491127971
ExprList *pList;
127492127972
pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy346.pExpr);
127493127973
pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy346.pExpr);
127494127974
yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy96.eOperator);
@@ -127496,11 +127976,11 @@
127496127976
yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
127497127977
yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127498127978
if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
127499127979
}
127500127980
break;
127501
- case 209: /* expr ::= expr likeop expr ESCAPE expr */
127981
+ case 210: /* expr ::= expr likeop expr ESCAPE expr */
127502127982
{
127503127983
ExprList *pList;
127504127984
pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
127505127985
pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy346.pExpr);
127506127986
pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
@@ -127509,39 +127989,39 @@
127509127989
yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127510127990
yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127511127991
if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
127512127992
}
127513127993
break;
127514
- case 210: /* expr ::= expr ISNULL|NOTNULL */
127994
+ case 211: /* expr ::= expr ISNULL|NOTNULL */
127515127995
{spanUnaryPostfix(&yygotominor.yy346,pParse,yymsp[0].major,&yymsp[-1].minor.yy346,&yymsp[0].minor.yy0);}
127516127996
break;
127517
- case 211: /* expr ::= expr NOT NULL */
127997
+ case 212: /* expr ::= expr NOT NULL */
127518127998
{spanUnaryPostfix(&yygotominor.yy346,pParse,TK_NOTNULL,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy0);}
127519127999
break;
127520
- case 212: /* expr ::= expr IS expr */
128000
+ case 213: /* expr ::= expr IS expr */
127521128001
{
127522128002
spanBinaryExpr(&yygotominor.yy346,pParse,TK_IS,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);
127523128003
binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_ISNULL);
127524128004
}
127525128005
break;
127526
- case 213: /* expr ::= expr IS NOT expr */
128006
+ case 214: /* expr ::= expr IS NOT expr */
127527128007
{
127528128008
spanBinaryExpr(&yygotominor.yy346,pParse,TK_ISNOT,&yymsp[-3].minor.yy346,&yymsp[0].minor.yy346);
127529128009
binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_NOTNULL);
127530128010
}
127531128011
break;
127532
- case 214: /* expr ::= NOT expr */
127533
- case 215: /* expr ::= BITNOT expr */ yytestcase(yyruleno==215);
128012
+ case 215: /* expr ::= NOT expr */
128013
+ case 216: /* expr ::= BITNOT expr */ yytestcase(yyruleno==216);
127534128014
{spanUnaryPrefix(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
127535128015
break;
127536
- case 216: /* expr ::= MINUS expr */
128016
+ case 217: /* expr ::= MINUS expr */
127537128017
{spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UMINUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
127538128018
break;
127539
- case 217: /* expr ::= PLUS expr */
128019
+ case 218: /* expr ::= PLUS expr */
127540128020
{spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UPLUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
127541128021
break;
127542
- case 220: /* expr ::= expr between_op expr AND expr */
128022
+ case 221: /* expr ::= expr between_op expr AND expr */
127543128023
{
127544128024
ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
127545128025
pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
127546128026
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy346.pExpr, 0, 0);
127547128027
if( yygotominor.yy346.pExpr ){
@@ -127552,11 +128032,11 @@
127552128032
if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
127553128033
yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127554128034
yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127555128035
}
127556128036
break;
127557
- case 223: /* expr ::= expr in_op LP exprlist RP */
128037
+ case 224: /* expr ::= expr in_op LP exprlist RP */
127558128038
{
127559128039
if( yymsp[-1].minor.yy14==0 ){
127560128040
/* Expressions of the form
127561128041
**
127562128042
** expr1 IN ()
@@ -127606,11 +128086,11 @@
127606128086
}
127607128087
yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127608128088
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127609128089
}
127610128090
break;
127611
- case 224: /* expr ::= LP select RP */
128091
+ case 225: /* expr ::= LP select RP */
127612128092
{
127613128093
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
127614128094
if( yygotominor.yy346.pExpr ){
127615128095
yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
127616128096
ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
@@ -127620,11 +128100,11 @@
127620128100
}
127621128101
yygotominor.yy346.zStart = yymsp[-2].minor.yy0.z;
127622128102
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127623128103
}
127624128104
break;
127625
- case 225: /* expr ::= expr in_op LP select RP */
128105
+ case 226: /* expr ::= expr in_op LP select RP */
127626128106
{
127627128107
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
127628128108
if( yygotominor.yy346.pExpr ){
127629128109
yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
127630128110
ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
@@ -127635,11 +128115,11 @@
127635128115
if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
127636128116
yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127637128117
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127638128118
}
127639128119
break;
127640
- case 226: /* expr ::= expr in_op nm dbnm */
128120
+ case 227: /* expr ::= expr in_op nm dbnm */
127641128121
{
127642128122
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
127643128123
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy346.pExpr, 0, 0);
127644128124
if( yygotominor.yy346.pExpr ){
127645128125
yygotominor.yy346.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
@@ -127651,11 +128131,11 @@
127651128131
if( yymsp[-2].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
127652128132
yygotominor.yy346.zStart = yymsp[-3].minor.yy346.zStart;
127653128133
yygotominor.yy346.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
127654128134
}
127655128135
break;
127656
- case 227: /* expr ::= EXISTS LP select RP */
128136
+ case 228: /* expr ::= EXISTS LP select RP */
127657128137
{
127658128138
Expr *p = yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
127659128139
if( p ){
127660128140
p->x.pSelect = yymsp[-1].minor.yy3;
127661128141
ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
@@ -127665,11 +128145,11 @@
127665128145
}
127666128146
yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
127667128147
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127668128148
}
127669128149
break;
127670
- case 228: /* expr ::= CASE case_operand case_exprlist case_else END */
128150
+ case 229: /* expr ::= CASE case_operand case_exprlist case_else END */
127671128151
{
127672128152
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy132, 0, 0);
127673128153
if( yygotominor.yy346.pExpr ){
127674128154
yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy132 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[-1].minor.yy132) : yymsp[-2].minor.yy14;
127675128155
sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
@@ -127679,274 +128159,263 @@
127679128159
}
127680128160
yygotominor.yy346.zStart = yymsp[-4].minor.yy0.z;
127681128161
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127682128162
}
127683128163
break;
127684
- case 229: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
128164
+ case 230: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
127685128165
{
127686128166
yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, yymsp[-2].minor.yy346.pExpr);
127687128167
yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
127688128168
}
127689128169
break;
127690
- case 230: /* case_exprlist ::= WHEN expr THEN expr */
128170
+ case 231: /* case_exprlist ::= WHEN expr THEN expr */
127691128171
{
127692128172
yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
127693128173
yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
127694128174
}
127695128175
break;
127696
- case 237: /* nexprlist ::= nexprlist COMMA expr */
128176
+ case 238: /* nexprlist ::= nexprlist COMMA expr */
127697128177
{yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[0].minor.yy346.pExpr);}
127698128178
break;
127699
- case 238: /* nexprlist ::= expr */
128179
+ case 239: /* nexprlist ::= expr */
127700128180
{yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy346.pExpr);}
127701128181
break;
127702
- case 239: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt */
128182
+ case 240: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
127703128183
{
127704128184
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
127705128185
sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy328,
127706128186
&yymsp[-11].minor.yy0, yymsp[0].minor.yy132, SQLITE_SO_ASC, yymsp[-8].minor.yy328);
127707128187
}
127708128188
break;
127709
- case 240: /* uniqueflag ::= UNIQUE */
127710
- case 291: /* raisetype ::= ABORT */ yytestcase(yyruleno==291);
128189
+ case 241: /* uniqueflag ::= UNIQUE */
128190
+ case 292: /* raisetype ::= ABORT */ yytestcase(yyruleno==292);
127711128191
{yygotominor.yy328 = OE_Abort;}
127712128192
break;
127713
- case 241: /* uniqueflag ::= */
128193
+ case 242: /* uniqueflag ::= */
127714128194
{yygotominor.yy328 = OE_None;}
127715128195
break;
127716
- case 244: /* idxlist ::= idxlist COMMA nm collate sortorder */
127717
-{
127718
- Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
127719
- yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, p);
127720
- sqlite3ExprListSetName(pParse,yygotominor.yy14,&yymsp[-2].minor.yy0,1);
127721
- sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
127722
- if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
127723
-}
127724
- break;
127725
- case 245: /* idxlist ::= nm collate sortorder */
127726
-{
127727
- Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
127728
- yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, p);
127729
- sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127730
- sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
127731
- if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
127732
-}
127733
- break;
127734
- case 246: /* collate ::= */
127735
-{yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
127736
- break;
127737
- case 248: /* cmd ::= DROP INDEX ifexists fullname */
128196
+ case 245: /* eidlist ::= eidlist COMMA nm collate sortorder */
128197
+{
128198
+ yygotominor.yy14 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy14, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy328, yymsp[0].minor.yy328);
128199
+}
128200
+ break;
128201
+ case 246: /* eidlist ::= nm collate sortorder */
128202
+{
128203
+ yygotominor.yy14 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy328, yymsp[0].minor.yy328);
128204
+}
128205
+ break;
128206
+ case 249: /* cmd ::= DROP INDEX ifexists fullname */
127738128207
{sqlite3DropIndex(pParse, yymsp[0].minor.yy65, yymsp[-1].minor.yy328);}
127739128208
break;
127740
- case 249: /* cmd ::= VACUUM */
127741
- case 250: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==250);
128209
+ case 250: /* cmd ::= VACUUM */
128210
+ case 251: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==251);
127742128211
{sqlite3Vacuum(pParse);}
127743128212
break;
127744
- case 251: /* cmd ::= PRAGMA nm dbnm */
128213
+ case 252: /* cmd ::= PRAGMA nm dbnm */
127745128214
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
127746128215
break;
127747
- case 252: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
128216
+ case 253: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
127748128217
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
127749128218
break;
127750
- case 253: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
128219
+ case 254: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
127751128220
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
127752128221
break;
127753
- case 254: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
128222
+ case 255: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
127754128223
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
127755128224
break;
127756
- case 255: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
128225
+ case 256: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
127757128226
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
127758128227
break;
127759
- case 264: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
128228
+ case 265: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
127760128229
{
127761128230
Token all;
127762128231
all.z = yymsp[-3].minor.yy0.z;
127763128232
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
127764128233
sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy473, &all);
127765128234
}
127766128235
break;
127767
- case 265: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
128236
+ case 266: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
127768128237
{
127769128238
sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy328, yymsp[-4].minor.yy378.a, yymsp[-4].minor.yy378.b, yymsp[-2].minor.yy65, yymsp[0].minor.yy132, yymsp[-10].minor.yy328, yymsp[-8].minor.yy328);
127770128239
yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
127771128240
}
127772128241
break;
127773
- case 266: /* trigger_time ::= BEFORE */
127774
- case 269: /* trigger_time ::= */ yytestcase(yyruleno==269);
128242
+ case 267: /* trigger_time ::= BEFORE */
128243
+ case 270: /* trigger_time ::= */ yytestcase(yyruleno==270);
127775128244
{ yygotominor.yy328 = TK_BEFORE; }
127776128245
break;
127777
- case 267: /* trigger_time ::= AFTER */
128246
+ case 268: /* trigger_time ::= AFTER */
127778128247
{ yygotominor.yy328 = TK_AFTER; }
127779128248
break;
127780
- case 268: /* trigger_time ::= INSTEAD OF */
128249
+ case 269: /* trigger_time ::= INSTEAD OF */
127781128250
{ yygotominor.yy328 = TK_INSTEAD;}
127782128251
break;
127783
- case 270: /* trigger_event ::= DELETE|INSERT */
127784
- case 271: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==271);
128252
+ case 271: /* trigger_event ::= DELETE|INSERT */
128253
+ case 272: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==272);
127785128254
{yygotominor.yy378.a = yymsp[0].major; yygotominor.yy378.b = 0;}
127786128255
break;
127787
- case 272: /* trigger_event ::= UPDATE OF idlist */
128256
+ case 273: /* trigger_event ::= UPDATE OF idlist */
127788128257
{yygotominor.yy378.a = TK_UPDATE; yygotominor.yy378.b = yymsp[0].minor.yy408;}
127789128258
break;
127790
- case 275: /* when_clause ::= */
127791
- case 296: /* key_opt ::= */ yytestcase(yyruleno==296);
128259
+ case 276: /* when_clause ::= */
128260
+ case 297: /* key_opt ::= */ yytestcase(yyruleno==297);
127792128261
{ yygotominor.yy132 = 0; }
127793128262
break;
127794
- case 276: /* when_clause ::= WHEN expr */
127795
- case 297: /* key_opt ::= KEY expr */ yytestcase(yyruleno==297);
128263
+ case 277: /* when_clause ::= WHEN expr */
128264
+ case 298: /* key_opt ::= KEY expr */ yytestcase(yyruleno==298);
127796128265
{ yygotominor.yy132 = yymsp[0].minor.yy346.pExpr; }
127797128266
break;
127798
- case 277: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
128267
+ case 278: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
127799128268
{
127800128269
assert( yymsp[-2].minor.yy473!=0 );
127801128270
yymsp[-2].minor.yy473->pLast->pNext = yymsp[-1].minor.yy473;
127802128271
yymsp[-2].minor.yy473->pLast = yymsp[-1].minor.yy473;
127803128272
yygotominor.yy473 = yymsp[-2].minor.yy473;
127804128273
}
127805128274
break;
127806
- case 278: /* trigger_cmd_list ::= trigger_cmd SEMI */
128275
+ case 279: /* trigger_cmd_list ::= trigger_cmd SEMI */
127807128276
{
127808128277
assert( yymsp[-1].minor.yy473!=0 );
127809128278
yymsp[-1].minor.yy473->pLast = yymsp[-1].minor.yy473;
127810128279
yygotominor.yy473 = yymsp[-1].minor.yy473;
127811128280
}
127812128281
break;
127813
- case 280: /* trnm ::= nm DOT nm */
128282
+ case 281: /* trnm ::= nm DOT nm */
127814128283
{
127815128284
yygotominor.yy0 = yymsp[0].minor.yy0;
127816128285
sqlite3ErrorMsg(pParse,
127817128286
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
127818128287
"statements within triggers");
127819128288
}
127820128289
break;
127821
- case 282: /* tridxby ::= INDEXED BY nm */
128290
+ case 283: /* tridxby ::= INDEXED BY nm */
127822128291
{
127823128292
sqlite3ErrorMsg(pParse,
127824128293
"the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
127825128294
"within triggers");
127826128295
}
127827128296
break;
127828
- case 283: /* tridxby ::= NOT INDEXED */
128297
+ case 284: /* tridxby ::= NOT INDEXED */
127829128298
{
127830128299
sqlite3ErrorMsg(pParse,
127831128300
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
127832128301
"within triggers");
127833128302
}
127834128303
break;
127835
- case 284: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
128304
+ case 285: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
127836128305
{ yygotominor.yy473 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy14, yymsp[0].minor.yy132, yymsp[-5].minor.yy186); }
127837128306
break;
127838
- case 285: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
128307
+ case 286: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
127839128308
{yygotominor.yy473 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy408, yymsp[0].minor.yy3, yymsp[-4].minor.yy186);}
127840128309
break;
127841
- case 286: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
128310
+ case 287: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
127842128311
{yygotominor.yy473 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy132);}
127843128312
break;
127844
- case 287: /* trigger_cmd ::= select */
128313
+ case 288: /* trigger_cmd ::= select */
127845128314
{yygotominor.yy473 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy3); }
127846128315
break;
127847
- case 288: /* expr ::= RAISE LP IGNORE RP */
128316
+ case 289: /* expr ::= RAISE LP IGNORE RP */
127848128317
{
127849128318
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
127850128319
if( yygotominor.yy346.pExpr ){
127851128320
yygotominor.yy346.pExpr->affinity = OE_Ignore;
127852128321
}
127853128322
yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
127854128323
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127855128324
}
127856128325
break;
127857
- case 289: /* expr ::= RAISE LP raisetype COMMA nm RP */
128326
+ case 290: /* expr ::= RAISE LP raisetype COMMA nm RP */
127858128327
{
127859128328
yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
127860128329
if( yygotominor.yy346.pExpr ) {
127861128330
yygotominor.yy346.pExpr->affinity = (char)yymsp[-3].minor.yy328;
127862128331
}
127863128332
yygotominor.yy346.zStart = yymsp[-5].minor.yy0.z;
127864128333
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127865128334
}
127866128335
break;
127867
- case 290: /* raisetype ::= ROLLBACK */
128336
+ case 291: /* raisetype ::= ROLLBACK */
127868128337
{yygotominor.yy328 = OE_Rollback;}
127869128338
break;
127870
- case 292: /* raisetype ::= FAIL */
128339
+ case 293: /* raisetype ::= FAIL */
127871128340
{yygotominor.yy328 = OE_Fail;}
127872128341
break;
127873
- case 293: /* cmd ::= DROP TRIGGER ifexists fullname */
128342
+ case 294: /* cmd ::= DROP TRIGGER ifexists fullname */
127874128343
{
127875128344
sqlite3DropTrigger(pParse,yymsp[0].minor.yy65,yymsp[-1].minor.yy328);
127876128345
}
127877128346
break;
127878
- case 294: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
128347
+ case 295: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
127879128348
{
127880128349
sqlite3Attach(pParse, yymsp[-3].minor.yy346.pExpr, yymsp[-1].minor.yy346.pExpr, yymsp[0].minor.yy132);
127881128350
}
127882128351
break;
127883
- case 295: /* cmd ::= DETACH database_kw_opt expr */
128352
+ case 296: /* cmd ::= DETACH database_kw_opt expr */
127884128353
{
127885128354
sqlite3Detach(pParse, yymsp[0].minor.yy346.pExpr);
127886128355
}
127887128356
break;
127888
- case 300: /* cmd ::= REINDEX */
128357
+ case 301: /* cmd ::= REINDEX */
127889128358
{sqlite3Reindex(pParse, 0, 0);}
127890128359
break;
127891
- case 301: /* cmd ::= REINDEX nm dbnm */
128360
+ case 302: /* cmd ::= REINDEX nm dbnm */
127892128361
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
127893128362
break;
127894
- case 302: /* cmd ::= ANALYZE */
128363
+ case 303: /* cmd ::= ANALYZE */
127895128364
{sqlite3Analyze(pParse, 0, 0);}
127896128365
break;
127897
- case 303: /* cmd ::= ANALYZE nm dbnm */
128366
+ case 304: /* cmd ::= ANALYZE nm dbnm */
127898128367
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
127899128368
break;
127900
- case 304: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
128369
+ case 305: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
127901128370
{
127902128371
sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy65,&yymsp[0].minor.yy0);
127903128372
}
127904128373
break;
127905
- case 305: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
128374
+ case 306: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
127906128375
{
127907128376
sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
127908128377
}
127909128378
break;
127910
- case 306: /* add_column_fullname ::= fullname */
128379
+ case 307: /* add_column_fullname ::= fullname */
127911128380
{
127912128381
pParse->db->lookaside.bEnabled = 0;
127913128382
sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy65);
127914128383
}
127915128384
break;
127916
- case 309: /* cmd ::= create_vtab */
128385
+ case 310: /* cmd ::= create_vtab */
127917128386
{sqlite3VtabFinishParse(pParse,0);}
127918128387
break;
127919
- case 310: /* cmd ::= create_vtab LP vtabarglist RP */
128388
+ case 311: /* cmd ::= create_vtab LP vtabarglist RP */
127920128389
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
127921128390
break;
127922
- case 311: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
128391
+ case 312: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
127923128392
{
127924128393
sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy328);
127925128394
}
127926128395
break;
127927
- case 314: /* vtabarg ::= */
128396
+ case 315: /* vtabarg ::= */
127928128397
{sqlite3VtabArgInit(pParse);}
127929128398
break;
127930
- case 316: /* vtabargtoken ::= ANY */
127931
- case 317: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==317);
127932
- case 318: /* lp ::= LP */ yytestcase(yyruleno==318);
128399
+ case 317: /* vtabargtoken ::= ANY */
128400
+ case 318: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==318);
128401
+ case 319: /* lp ::= LP */ yytestcase(yyruleno==319);
127933128402
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
127934128403
break;
127935
- case 322: /* with ::= */
128404
+ case 323: /* with ::= */
127936128405
{yygotominor.yy59 = 0;}
127937128406
break;
127938
- case 323: /* with ::= WITH wqlist */
127939
- case 324: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==324);
128407
+ case 324: /* with ::= WITH wqlist */
128408
+ case 325: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==325);
127940128409
{ yygotominor.yy59 = yymsp[0].minor.yy59; }
127941128410
break;
127942
- case 325: /* wqlist ::= nm idxlist_opt AS LP select RP */
128411
+ case 326: /* wqlist ::= nm eidlist_opt AS LP select RP */
127943128412
{
127944128413
yygotominor.yy59 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
127945128414
}
127946128415
break;
127947
- case 326: /* wqlist ::= wqlist COMMA nm idxlist_opt AS LP select RP */
128416
+ case 327: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
127948128417
{
127949128418
yygotominor.yy59 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy59, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
127950128419
}
127951128420
break;
127952128421
default:
@@ -127970,49 +128439,48 @@
127970128439
/* (53) carglist ::= */ yytestcase(yyruleno==53);
127971128440
/* (60) ccons ::= NULL onconf */ yytestcase(yyruleno==60);
127972128441
/* (88) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==88);
127973128442
/* (89) conslist ::= tcons */ yytestcase(yyruleno==89);
127974128443
/* (91) tconscomma ::= */ yytestcase(yyruleno==91);
127975
- /* (273) foreach_clause ::= */ yytestcase(yyruleno==273);
127976
- /* (274) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==274);
127977
- /* (281) tridxby ::= */ yytestcase(yyruleno==281);
127978
- /* (298) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==298);
127979
- /* (299) database_kw_opt ::= */ yytestcase(yyruleno==299);
127980
- /* (307) kwcolumn_opt ::= */ yytestcase(yyruleno==307);
127981
- /* (308) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==308);
127982
- /* (312) vtabarglist ::= vtabarg */ yytestcase(yyruleno==312);
127983
- /* (313) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==313);
127984
- /* (315) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==315);
127985
- /* (319) anylist ::= */ yytestcase(yyruleno==319);
127986
- /* (320) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==320);
127987
- /* (321) anylist ::= anylist ANY */ yytestcase(yyruleno==321);
128444
+ /* (274) foreach_clause ::= */ yytestcase(yyruleno==274);
128445
+ /* (275) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==275);
128446
+ /* (282) tridxby ::= */ yytestcase(yyruleno==282);
128447
+ /* (299) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==299);
128448
+ /* (300) database_kw_opt ::= */ yytestcase(yyruleno==300);
128449
+ /* (308) kwcolumn_opt ::= */ yytestcase(yyruleno==308);
128450
+ /* (309) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==309);
128451
+ /* (313) vtabarglist ::= vtabarg */ yytestcase(yyruleno==313);
128452
+ /* (314) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==314);
128453
+ /* (316) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==316);
128454
+ /* (320) anylist ::= */ yytestcase(yyruleno==320);
128455
+ /* (321) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==321);
128456
+ /* (322) anylist ::= anylist ANY */ yytestcase(yyruleno==322);
127988128457
break;
127989128458
};
127990128459
assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
127991128460
yygoto = yyRuleInfo[yyruleno].lhs;
127992128461
yysize = yyRuleInfo[yyruleno].nrhs;
127993128462
yypParser->yyidx -= yysize;
127994128463
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
127995
- if( yyact < YYNSTATE ){
127996
-#ifdef NDEBUG
127997
- /* If we are not debugging and the reduce action popped at least
128464
+ if( yyact <= YY_MAX_SHIFTREDUCE ){
128465
+ if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
128466
+ /* If the reduce action popped at least
127998128467
** one element off the stack, then we can push the new element back
127999128468
** onto the stack here, and skip the stack overflow test in yy_shift().
128000128469
** That gives a significant speed improvement. */
128001128470
if( yysize ){
128002128471
yypParser->yyidx++;
128003128472
yymsp -= yysize-1;
128004128473
yymsp->stateno = (YYACTIONTYPE)yyact;
128005128474
yymsp->major = (YYCODETYPE)yygoto;
128006128475
yymsp->minor = yygotominor;
128007
- }else
128008
-#endif
128009
- {
128476
+ yyTraceShift(yypParser, yyact);
128477
+ }else{
128010128478
yy_shift(yypParser,yyact,yygoto,&yygotominor);
128011128479
}
128012128480
}else{
128013
- assert( yyact == YYNSTATE + YYNRULE + 1 );
128481
+ assert( yyact == YY_ACCEPT_ACTION );
128014128482
yy_accept(yypParser);
128015128483
}
128016128484
}
128017128485
128018128486
/*
@@ -128133,16 +128601,17 @@
128133128601
}
128134128602
#endif
128135128603
128136128604
do{
128137128605
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
128138
- if( yyact<YYNSTATE ){
128606
+ if( yyact <= YY_MAX_SHIFTREDUCE ){
128607
+ if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
128139128608
yy_shift(yypParser,yyact,yymajor,&yyminorunion);
128140128609
yypParser->yyerrcnt--;
128141128610
yymajor = YYNOCODE;
128142
- }else if( yyact < YYNSTATE + YYNRULE ){
128143
- yy_reduce(yypParser,yyact-YYNSTATE);
128611
+ }else if( yyact <= YY_MAX_REDUCE ){
128612
+ yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
128144128613
}else{
128145128614
assert( yyact == YY_ERROR_ACTION );
128146128615
#ifdef YYERRORSYMBOL
128147128616
int yymx;
128148128617
#endif
@@ -128188,11 +128657,11 @@
128188128657
while(
128189128658
yypParser->yyidx >= 0 &&
128190128659
yymx != YYERRORSYMBOL &&
128191128660
(yyact = yy_find_reduce_action(
128192128661
yypParser->yystack[yypParser->yyidx].stateno,
128193
- YYERRORSYMBOL)) >= YYNSTATE
128662
+ YYERRORSYMBOL)) >= YY_MIN_REDUCE
128194128663
){
128195128664
yy_pop_parser_stack(yypParser);
128196128665
}
128197128666
if( yypParser->yyidx < 0 || yymajor==0 ){
128198128667
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
@@ -128238,10 +128707,15 @@
128238128707
}
128239128708
yymajor = YYNOCODE;
128240128709
#endif
128241128710
}
128242128711
}while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
128712
+#ifndef NDEBUG
128713
+ if( yyTraceFILE ){
128714
+ fprintf(yyTraceFILE,"%sReturn\n",yyTracePrompt);
128715
+ }
128716
+#endif
128243128717
return;
128244128718
}
128245128719
128246128720
/************** End of parse.c ***********************************************/
128247128721
/************** Begin file tokenize.c ****************************************/
@@ -128926,10 +129400,11 @@
128926129400
}
128927129401
pParse->rc = SQLITE_OK;
128928129402
pParse->zTail = zSql;
128929129403
i = 0;
128930129404
assert( pzErrMsg!=0 );
129405
+ /* sqlite3ParserTrace(stdout, "parser: "); */
128931129406
pEngine = sqlite3ParserAlloc(sqlite3Malloc);
128932129407
if( pEngine==0 ){
128933129408
db->mallocFailed = 1;
128934129409
return SQLITE_NOMEM;
128935129410
}
@@ -130370,20 +130845,26 @@
130370130845
** db. This is called when db is being closed.
130371130846
*/
130372130847
static void disconnectAllVtab(sqlite3 *db){
130373130848
#ifndef SQLITE_OMIT_VIRTUALTABLE
130374130849
int i;
130850
+ HashElem *p;
130375130851
sqlite3BtreeEnterAll(db);
130376130852
for(i=0; i<db->nDb; i++){
130377130853
Schema *pSchema = db->aDb[i].pSchema;
130378130854
if( db->aDb[i].pSchema ){
130379
- HashElem *p;
130380130855
for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
130381130856
Table *pTab = (Table *)sqliteHashData(p);
130382130857
if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
130383130858
}
130384130859
}
130860
+ }
130861
+ for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
130862
+ Module *pMod = (Module *)sqliteHashData(p);
130863
+ if( pMod->pEpoTab ){
130864
+ sqlite3VtabDisconnect(db, pMod->pEpoTab);
130865
+ }
130385130866
}
130386130867
sqlite3VtabUnlockList(db);
130387130868
sqlite3BtreeLeaveAll(db);
130388130869
#else
130389130870
UNUSED_PARAMETER(db);
@@ -130558,10 +131039,11 @@
130558131039
for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
130559131040
Module *pMod = (Module *)sqliteHashData(i);
130560131041
if( pMod->xDestroy ){
130561131042
pMod->xDestroy(pMod->pAux);
130562131043
}
131044
+ sqlite3VtabEponymousTableClear(db, pMod);
130563131045
sqlite3DbFree(db, pMod);
130564131046
}
130565131047
sqlite3HashClear(&db->aModule);
130566131048
#endif
130567131049
@@ -156962,14 +157444,10 @@
156962157444
156963157445
/* #include <assert.h> */
156964157446
/* #include <string.h> */
156965157447
/* #include <stdio.h> */
156966157448
156967
-#if !defined(_WIN32)
156968
-/* # include <unistd.h> */
156969
-#endif
156970
-
156971157449
/* #include "sqlite3.h" */
156972157450
156973157451
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
156974157452
/************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
156975157453
/************** Begin file sqlite3rbu.h **************************************/
@@ -157070,10 +157548,22 @@
157070157548
**
157071157549
** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
157072157550
**
157073157551
** The order of the columns in the data_% table does not matter.
157074157552
**
157553
+** Instead of a regular table, the RBU database may also contain virtual
157554
+** tables or view named using the data_<target> naming scheme.
157555
+**
157556
+** Instead of the plain data_<target> naming scheme, RBU database tables
157557
+** may also be named data<integer>_<target>, where <integer> is any sequence
157558
+** of zero or more numeric characters (0-9). This can be significant because
157559
+** tables within the RBU database are always processed in order sorted by
157560
+** name. By judicious selection of the the <integer> portion of the names
157561
+** of the RBU tables the user can therefore control the order in which they
157562
+** are processed. This can be useful, for example, to ensure that "external
157563
+** content" FTS4 tables are updated before their underlying content tables.
157564
+**
157075157565
** If the target database table is a virtual table or a table that has no
157076157566
** PRIMARY KEY declaration, the data_% table must also contain a column
157077157567
** named "rbu_rowid". This column is mapped to the tables implicit primary
157078157568
** key column - "rowid". Virtual tables for which the "rowid" column does
157079157569
** not function like a primary key value cannot be updated using RBU. For
@@ -157149,10 +157639,18 @@
157149157639
** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
157150157640
**
157151157641
** is similar to an UPDATE statement such as:
157152157642
**
157153157643
** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
157644
+**
157645
+** Finally, if an 'f' character appears in place of a 'd' or 's' in an
157646
+** ota_control string, the contents of the data_xxx table column is assumed
157647
+** to be a "fossil delta" - a patch to be applied to a blob value in the
157648
+** format used by the fossil source-code management system. In this case
157649
+** the existing value within the target database table must be of type BLOB.
157650
+** It is replaced by the result of applying the specified fossil delta to
157651
+** itself.
157154157652
**
157155157653
** If the target database table is a virtual table or a table with no PRIMARY
157156157654
** KEY, the rbu_control value should not include a character corresponding
157157157655
** to the rbu_rowid value. For example, this:
157158157656
**
@@ -157307,10 +157805,22 @@
157307157805
** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
157308157806
** that immediately return the same value.
157309157807
*/
157310157808
SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu);
157311157809
157810
+/*
157811
+** Force RBU to save its state to disk.
157812
+**
157813
+** If a power failure or application crash occurs during an update, following
157814
+** system recovery RBU may resume the update from the point at which the state
157815
+** was last saved. In other words, from the most recent successful call to
157816
+** sqlite3rbu_close() or this function.
157817
+**
157818
+** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
157819
+*/
157820
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_savestate(sqlite3rbu *pRbu);
157821
+
157312157822
/*
157313157823
** Close an RBU handle.
157314157824
**
157315157825
** If the RBU update has been completely applied, mark the RBU database
157316157826
** as fully applied. Otherwise, assuming no error has occurred, save the
@@ -157539,10 +158049,11 @@
157539158049
int eType; /* Table type - an RBU_PK_XXX value */
157540158050
157541158051
/* Output variables. zTbl==0 implies EOF. */
157542158052
int bCleanup; /* True in "cleanup" state */
157543158053
const char *zTbl; /* Name of target db table */
158054
+ const char *zDataTbl; /* Name of rbu db table (or null) */
157544158055
const char *zIdx; /* Name of target db index (or null) */
157545158056
int iTnum; /* Root page of current object */
157546158057
int iPkTnum; /* If eType==EXTERNAL, root of PK index */
157547158058
int bUnique; /* Current index is unique */
157548158059
@@ -157549,11 +158060,11 @@
157549158060
/* Statements created by rbuObjIterPrepareAll() */
157550158061
int nCol; /* Number of columns in current object */
157551158062
sqlite3_stmt *pSelect; /* Source data */
157552158063
sqlite3_stmt *pInsert; /* Statement for INSERT operations */
157553158064
sqlite3_stmt *pDelete; /* Statement for DELETE ops */
157554
- sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zTbl */
158065
+ sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zDataTbl */
157555158066
157556158067
/* Last UPDATE used (for PK b-tree updates only), or NULL. */
157557158068
RbuUpdateStmt *pRbuUpdate;
157558158069
};
157559158070
@@ -157659,10 +158170,256 @@
157659158170
const char *zWal; /* Wal filename for this main db file */
157660158171
rbu_file *pWalFd; /* Wal file descriptor for this main db */
157661158172
rbu_file *pMainNext; /* Next MAIN_DB file */
157662158173
};
157663158174
158175
+
158176
+/*************************************************************************
158177
+** The following three functions, found below:
158178
+**
158179
+** rbuDeltaGetInt()
158180
+** rbuDeltaChecksum()
158181
+** rbuDeltaApply()
158182
+**
158183
+** are lifted from the fossil source code (http://fossil-scm.org). They
158184
+** are used to implement the scalar SQL function rbu_fossil_delta().
158185
+*/
158186
+
158187
+/*
158188
+** Read bytes from *pz and convert them into a positive integer. When
158189
+** finished, leave *pz pointing to the first character past the end of
158190
+** the integer. The *pLen parameter holds the length of the string
158191
+** in *pz and is decremented once for each character in the integer.
158192
+*/
158193
+static unsigned int rbuDeltaGetInt(const char **pz, int *pLen){
158194
+ static const signed char zValue[] = {
158195
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158196
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158197
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158198
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
158199
+ -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
158200
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36,
158201
+ -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
158202
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1,
158203
+ };
158204
+ unsigned int v = 0;
158205
+ int c;
158206
+ unsigned char *z = (unsigned char*)*pz;
158207
+ unsigned char *zStart = z;
158208
+ while( (c = zValue[0x7f&*(z++)])>=0 ){
158209
+ v = (v<<6) + c;
158210
+ }
158211
+ z--;
158212
+ *pLen -= z - zStart;
158213
+ *pz = (char*)z;
158214
+ return v;
158215
+}
158216
+
158217
+/*
158218
+** Compute a 32-bit checksum on the N-byte buffer. Return the result.
158219
+*/
158220
+static unsigned int rbuDeltaChecksum(const char *zIn, size_t N){
158221
+ const unsigned char *z = (const unsigned char *)zIn;
158222
+ unsigned sum0 = 0;
158223
+ unsigned sum1 = 0;
158224
+ unsigned sum2 = 0;
158225
+ unsigned sum3 = 0;
158226
+ while(N >= 16){
158227
+ sum0 += ((unsigned)z[0] + z[4] + z[8] + z[12]);
158228
+ sum1 += ((unsigned)z[1] + z[5] + z[9] + z[13]);
158229
+ sum2 += ((unsigned)z[2] + z[6] + z[10]+ z[14]);
158230
+ sum3 += ((unsigned)z[3] + z[7] + z[11]+ z[15]);
158231
+ z += 16;
158232
+ N -= 16;
158233
+ }
158234
+ while(N >= 4){
158235
+ sum0 += z[0];
158236
+ sum1 += z[1];
158237
+ sum2 += z[2];
158238
+ sum3 += z[3];
158239
+ z += 4;
158240
+ N -= 4;
158241
+ }
158242
+ sum3 += (sum2 << 8) + (sum1 << 16) + (sum0 << 24);
158243
+ switch(N){
158244
+ case 3: sum3 += (z[2] << 8);
158245
+ case 2: sum3 += (z[1] << 16);
158246
+ case 1: sum3 += (z[0] << 24);
158247
+ default: ;
158248
+ }
158249
+ return sum3;
158250
+}
158251
+
158252
+/*
158253
+** Apply a delta.
158254
+**
158255
+** The output buffer should be big enough to hold the whole output
158256
+** file and a NUL terminator at the end. The delta_output_size()
158257
+** routine will determine this size for you.
158258
+**
158259
+** The delta string should be null-terminated. But the delta string
158260
+** may contain embedded NUL characters (if the input and output are
158261
+** binary files) so we also have to pass in the length of the delta in
158262
+** the lenDelta parameter.
158263
+**
158264
+** This function returns the size of the output file in bytes (excluding
158265
+** the final NUL terminator character). Except, if the delta string is
158266
+** malformed or intended for use with a source file other than zSrc,
158267
+** then this routine returns -1.
158268
+**
158269
+** Refer to the delta_create() documentation above for a description
158270
+** of the delta file format.
158271
+*/
158272
+static int rbuDeltaApply(
158273
+ const char *zSrc, /* The source or pattern file */
158274
+ int lenSrc, /* Length of the source file */
158275
+ const char *zDelta, /* Delta to apply to the pattern */
158276
+ int lenDelta, /* Length of the delta */
158277
+ char *zOut /* Write the output into this preallocated buffer */
158278
+){
158279
+ unsigned int limit;
158280
+ unsigned int total = 0;
158281
+#ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
158282
+ char *zOrigOut = zOut;
158283
+#endif
158284
+
158285
+ limit = rbuDeltaGetInt(&zDelta, &lenDelta);
158286
+ if( *zDelta!='\n' ){
158287
+ /* ERROR: size integer not terminated by "\n" */
158288
+ return -1;
158289
+ }
158290
+ zDelta++; lenDelta--;
158291
+ while( *zDelta && lenDelta>0 ){
158292
+ unsigned int cnt, ofst;
158293
+ cnt = rbuDeltaGetInt(&zDelta, &lenDelta);
158294
+ switch( zDelta[0] ){
158295
+ case '@': {
158296
+ zDelta++; lenDelta--;
158297
+ ofst = rbuDeltaGetInt(&zDelta, &lenDelta);
158298
+ if( lenDelta>0 && zDelta[0]!=',' ){
158299
+ /* ERROR: copy command not terminated by ',' */
158300
+ return -1;
158301
+ }
158302
+ zDelta++; lenDelta--;
158303
+ total += cnt;
158304
+ if( total>limit ){
158305
+ /* ERROR: copy exceeds output file size */
158306
+ return -1;
158307
+ }
158308
+ if( (int)(ofst+cnt) > lenSrc ){
158309
+ /* ERROR: copy extends past end of input */
158310
+ return -1;
158311
+ }
158312
+ memcpy(zOut, &zSrc[ofst], cnt);
158313
+ zOut += cnt;
158314
+ break;
158315
+ }
158316
+ case ':': {
158317
+ zDelta++; lenDelta--;
158318
+ total += cnt;
158319
+ if( total>limit ){
158320
+ /* ERROR: insert command gives an output larger than predicted */
158321
+ return -1;
158322
+ }
158323
+ if( (int)cnt>lenDelta ){
158324
+ /* ERROR: insert count exceeds size of delta */
158325
+ return -1;
158326
+ }
158327
+ memcpy(zOut, zDelta, cnt);
158328
+ zOut += cnt;
158329
+ zDelta += cnt;
158330
+ lenDelta -= cnt;
158331
+ break;
158332
+ }
158333
+ case ';': {
158334
+ zDelta++; lenDelta--;
158335
+ zOut[0] = 0;
158336
+#ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
158337
+ if( cnt!=rbuDeltaChecksum(zOrigOut, total) ){
158338
+ /* ERROR: bad checksum */
158339
+ return -1;
158340
+ }
158341
+#endif
158342
+ if( total!=limit ){
158343
+ /* ERROR: generated size does not match predicted size */
158344
+ return -1;
158345
+ }
158346
+ return total;
158347
+ }
158348
+ default: {
158349
+ /* ERROR: unknown delta operator */
158350
+ return -1;
158351
+ }
158352
+ }
158353
+ }
158354
+ /* ERROR: unterminated delta */
158355
+ return -1;
158356
+}
158357
+
158358
+static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){
158359
+ int size;
158360
+ size = rbuDeltaGetInt(&zDelta, &lenDelta);
158361
+ if( *zDelta!='\n' ){
158362
+ /* ERROR: size integer not terminated by "\n" */
158363
+ return -1;
158364
+ }
158365
+ return size;
158366
+}
158367
+
158368
+/*
158369
+** End of code taken from fossil.
158370
+*************************************************************************/
158371
+
158372
+/*
158373
+** Implementation of SQL scalar function rbu_fossil_delta().
158374
+**
158375
+** This function applies a fossil delta patch to a blob. Exactly two
158376
+** arguments must be passed to this function. The first is the blob to
158377
+** patch and the second the patch to apply. If no error occurs, this
158378
+** function returns the patched blob.
158379
+*/
158380
+static void rbuFossilDeltaFunc(
158381
+ sqlite3_context *context,
158382
+ int argc,
158383
+ sqlite3_value **argv
158384
+){
158385
+ const char *aDelta;
158386
+ int nDelta;
158387
+ const char *aOrig;
158388
+ int nOrig;
158389
+
158390
+ int nOut;
158391
+ int nOut2;
158392
+ char *aOut;
158393
+
158394
+ assert( argc==2 );
158395
+
158396
+ nOrig = sqlite3_value_bytes(argv[0]);
158397
+ aOrig = (const char*)sqlite3_value_blob(argv[0]);
158398
+ nDelta = sqlite3_value_bytes(argv[1]);
158399
+ aDelta = (const char*)sqlite3_value_blob(argv[1]);
158400
+
158401
+ /* Figure out the size of the output */
158402
+ nOut = rbuDeltaOutputSize(aDelta, nDelta);
158403
+ if( nOut<0 ){
158404
+ sqlite3_result_error(context, "corrupt fossil delta", -1);
158405
+ return;
158406
+ }
158407
+
158408
+ aOut = sqlite3_malloc(nOut+1);
158409
+ if( aOut==0 ){
158410
+ sqlite3_result_error_nomem(context);
158411
+ }else{
158412
+ nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
158413
+ if( nOut2!=nOut ){
158414
+ sqlite3_result_error(context, "corrupt fossil delta", -1);
158415
+ }else{
158416
+ sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
158417
+ }
158418
+ }
158419
+}
158420
+
157664158421
157665158422
/*
157666158423
** Prepare the SQL statement in buffer zSql against database handle db.
157667158424
** If successful, set *ppStmt to point to the new statement and return
157668158425
** SQLITE_OK.
@@ -157826,11 +158583,12 @@
157826158583
if( rc!=SQLITE_ROW ){
157827158584
rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
157828158585
pIter->zTbl = 0;
157829158586
}else{
157830158587
pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
157831
- rc = pIter->zTbl ? SQLITE_OK : SQLITE_NOMEM;
158588
+ pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
158589
+ rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
157832158590
}
157833158591
}else{
157834158592
if( pIter->zIdx==0 ){
157835158593
sqlite3_stmt *pIdx = pIter->pIdxIter;
157836158594
rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
@@ -157857,10 +158615,44 @@
157857158615
p->rc = rc;
157858158616
}
157859158617
return rc;
157860158618
}
157861158619
158620
+
158621
+/*
158622
+** The implementation of the rbu_target_name() SQL function. This function
158623
+** accepts one argument - the name of a table in the RBU database. If the
158624
+** table name matches the pattern:
158625
+**
158626
+** data[0-9]_<name>
158627
+**
158628
+** where <name> is any sequence of 1 or more characters, <name> is returned.
158629
+** Otherwise, if the only argument does not match the above pattern, an SQL
158630
+** NULL is returned.
158631
+**
158632
+** "data_t1" -> "t1"
158633
+** "data0123_t2" -> "t2"
158634
+** "dataAB_t3" -> NULL
158635
+*/
158636
+static void rbuTargetNameFunc(
158637
+ sqlite3_context *context,
158638
+ int argc,
158639
+ sqlite3_value **argv
158640
+){
158641
+ const char *zIn;
158642
+ assert( argc==1 );
158643
+
158644
+ zIn = (const char*)sqlite3_value_text(argv[0]);
158645
+ if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
158646
+ int i;
158647
+ for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
158648
+ if( zIn[i]=='_' && zIn[i+1] ){
158649
+ sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC);
158650
+ }
158651
+ }
158652
+}
158653
+
157862158654
/*
157863158655
** Initialize the iterator structure passed as the second argument.
157864158656
**
157865158657
** If no error occurs, SQLITE_OK is returned and the iterator is left
157866158658
** pointing to the first entry. Otherwise, an error code and message is
@@ -157870,12 +158662,13 @@
157870158662
static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
157871158663
int rc;
157872158664
memset(pIter, 0, sizeof(RbuObjIter));
157873158665
157874158666
rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
157875
- "SELECT substr(name, 6) FROM sqlite_master "
157876
- "WHERE type IN ('table', 'view') AND name LIKE 'data_%'"
158667
+ "SELECT rbu_target_name(name) AS target, name FROM sqlite_master "
158668
+ "WHERE type IN ('table', 'view') AND target IS NOT NULL "
158669
+ "ORDER BY name"
157877158670
);
157878158671
157879158672
if( rc==SQLITE_OK ){
157880158673
rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
157881158674
"SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
@@ -158138,11 +158931,11 @@
158138158931
}
158139158932
*peType = RBU_PK_NONE;
158140158933
}
158141158934
158142158935
rbuTableType_end: {
158143
- int i;
158936
+ unsigned int i;
158144158937
for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
158145158938
rbuFinalize(p, aStmt[i]);
158146158939
}
158147158940
}
158148158941
}
@@ -158217,11 +159010,11 @@
158217159010
158218159011
/* Populate the azTblCol[] and nTblCol variables based on the columns
158219159012
** of the input table. Ignore any input table columns that begin with
158220159013
** "rbu_". */
158221159014
p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
158222
- sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl)
159015
+ sqlite3_mprintf("SELECT * FROM '%q'", pIter->zDataTbl)
158223159016
);
158224159017
if( p->rc==SQLITE_OK ){
158225159018
nCol = sqlite3_column_count(pStmt);
158226159019
rbuAllocateIterArrays(p, pIter, nCol);
158227159020
}
@@ -158242,11 +159035,11 @@
158242159035
if( p->rc==SQLITE_OK
158243159036
&& bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
158244159037
){
158245159038
p->rc = SQLITE_ERROR;
158246159039
p->zErrmsg = sqlite3_mprintf(
158247
- "table data_%q %s rbu_rowid column", pIter->zTbl,
159040
+ "table %q %s rbu_rowid column", pIter->zDataTbl,
158248159041
(bRbuRowid ? "may not have" : "requires")
158249159042
);
158250159043
}
158251159044
158252159045
/* Check that all non-HIDDEN columns in the destination table are also
@@ -158263,12 +159056,12 @@
158263159056
for(i=iOrder; i<pIter->nTblCol; i++){
158264159057
if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
158265159058
}
158266159059
if( i==pIter->nTblCol ){
158267159060
p->rc = SQLITE_ERROR;
158268
- p->zErrmsg = sqlite3_mprintf("column missing from data_%q: %s",
158269
- pIter->zTbl, zName
159061
+ p->zErrmsg = sqlite3_mprintf("column missing from %q: %s",
159062
+ pIter->zDataTbl, zName
158270159063
);
158271159064
}else{
158272159065
int iPk = sqlite3_column_int(pStmt, 5);
158273159066
int bNotNull = sqlite3_column_int(pStmt, 3);
158274159067
const char *zType = (const char*)sqlite3_column_text(pStmt, 2);
@@ -158551,11 +159344,11 @@
158551159344
){
158552159345
char *zList = 0;
158553159346
if( p->rc==SQLITE_OK ){
158554159347
int i;
158555159348
158556
- if( strlen(zMask)!=pIter->nTblCol ){
159349
+ if( (int)strlen(zMask)!=pIter->nTblCol ){
158557159350
rbuBadControlError(p);
158558159351
}else{
158559159352
const char *zSep = "";
158560159353
for(i=0; i<pIter->nTblCol; i++){
158561159354
char c = zMask[pIter->aiSrcOrder[i]];
@@ -158563,15 +159356,21 @@
158563159356
zList = rbuMPrintf(p, "%z%s\"%w\"=?%d",
158564159357
zList, zSep, pIter->azTblCol[i], i+1
158565159358
);
158566159359
zSep = ", ";
158567159360
}
158568
- if( c=='d' ){
159361
+ else if( c=='d' ){
158569159362
zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)",
158570159363
zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
158571159364
);
158572159365
zSep = ", ";
159366
+ }
159367
+ else if( c=='f' ){
159368
+ zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_fossil_delta(\"%w\", ?%d)",
159369
+ zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
159370
+ );
159371
+ zSep = ", ";
158573159372
}
158574159373
}
158575159374
}
158576159375
}
158577159376
return zList;
@@ -158819,11 +159618,11 @@
158819159618
if( zBind ){
158820159619
assert( pIter->pTmpInsert==0 );
158821159620
p->rc = prepareFreeAndCollectError(
158822159621
p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
158823159622
"INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)",
158824
- p->zStateDb, pIter->zTbl, zCollist, zRbuRowid, zBind
159623
+ p->zStateDb, pIter->zDataTbl, zCollist, zRbuRowid, zBind
158825159624
));
158826159625
}
158827159626
}
158828159627
158829159628
static void rbuTmpInsertFunc(
@@ -158915,22 +159714,22 @@
158915159714
if( p->rc==SQLITE_OK ){
158916159715
char *zSql;
158917159716
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158918159717
zSql = sqlite3_mprintf(
158919159718
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
158920
- zCollist, p->zStateDb, pIter->zTbl,
159719
+ zCollist, p->zStateDb, pIter->zDataTbl,
158921159720
zCollist, zLimit
158922159721
);
158923159722
}else{
158924159723
zSql = sqlite3_mprintf(
158925
- "SELECT %s, rbu_control FROM 'data_%q' "
159724
+ "SELECT %s, rbu_control FROM '%q' "
158926159725
"WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
158927159726
"UNION ALL "
158928159727
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
158929159728
"ORDER BY %s%s",
158930
- zCollist, pIter->zTbl,
158931
- zCollist, p->zStateDb, pIter->zTbl,
159729
+ zCollist, pIter->zDataTbl,
159730
+ zCollist, p->zStateDb, pIter->zDataTbl,
158932159731
zCollist, zLimit
158933159732
);
158934159733
}
158935159734
p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
158936159735
}
@@ -158950,20 +159749,10 @@
158950159749
char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
158951159750
158952159751
zCollist = rbuObjIterGetCollist(p, pIter);
158953159752
pIter->nCol = pIter->nTblCol;
158954159753
158955
- /* Create the SELECT statement to read keys from data_xxx */
158956
- if( p->rc==SQLITE_OK ){
158957
- p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
158958
- sqlite3_mprintf(
158959
- "SELECT %s, rbu_control%s FROM 'data_%q'%s",
158960
- zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit
158961
- )
158962
- );
158963
- }
158964
-
158965159754
/* Create the imposter table or tables (if required). */
158966159755
rbuCreateImposterTable(p, pIter);
158967159756
rbuCreateImposterTable2(p, pIter);
158968159757
zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
158969159758
@@ -158993,14 +159782,14 @@
158993159782
}
158994159783
158995159784
/* Create the rbu_tmp_xxx table and the triggers to populate it. */
158996159785
rbuMPrintfExec(p, p->dbRbu,
158997159786
"CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS "
158998
- "SELECT *%s FROM 'data_%q' WHERE 0;"
158999
- , p->zStateDb
159000
- , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
159001
- , zTbl
159787
+ "SELECT *%s FROM '%q' WHERE 0;"
159788
+ , p->zStateDb, pIter->zDataTbl
159789
+ , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
159790
+ , pIter->zDataTbl
159002159791
);
159003159792
159004159793
rbuMPrintfExec(p, p->dbMain,
159005159794
"CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" "
159006159795
"BEGIN "
@@ -159031,10 +159820,21 @@
159031159820
);
159032159821
}
159033159822
159034159823
rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
159035159824
}
159825
+
159826
+ /* Create the SELECT statement to read keys from data_xxx */
159827
+ if( p->rc==SQLITE_OK ){
159828
+ p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
159829
+ sqlite3_mprintf(
159830
+ "SELECT %s, rbu_control%s FROM '%q'%s",
159831
+ zCollist, (bRbuRowid ? ", rbu_rowid" : ""),
159832
+ pIter->zDataTbl, zLimit
159833
+ )
159834
+ );
159835
+ }
159036159836
159037159837
sqlite3_free(zWhere);
159038159838
sqlite3_free(zOldlist);
159039159839
sqlite3_free(zNewlist);
159040159840
sqlite3_free(zBindings);
@@ -159161,10 +159961,22 @@
159161159961
if( p->rc==SQLITE_OK ){
159162159962
p->rc = sqlite3_create_function(p->dbMain,
159163159963
"rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
159164159964
);
159165159965
}
159966
+
159967
+ if( p->rc==SQLITE_OK ){
159968
+ p->rc = sqlite3_create_function(p->dbMain,
159969
+ "rbu_fossil_delta", 2, SQLITE_UTF8, 0, rbuFossilDeltaFunc, 0, 0
159970
+ );
159971
+ }
159972
+
159973
+ if( p->rc==SQLITE_OK ){
159974
+ p->rc = sqlite3_create_function(p->dbRbu,
159975
+ "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
159976
+ );
159977
+ }
159166159978
159167159979
if( p->rc==SQLITE_OK ){
159168159980
p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
159169159981
}
159170159982
rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
@@ -159591,11 +160403,11 @@
159591160403
rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
159592160404
if( pUpdate ){
159593160405
for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
159594160406
char c = zMask[pIter->aiSrcOrder[i]];
159595160407
pVal = sqlite3_column_value(pIter->pSelect, i);
159596
- if( pIter->abTblPk[i] || c=='x' || c=='d' ){
160408
+ if( pIter->abTblPk[i] || c!='.' ){
159597160409
p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
159598160410
}
159599160411
}
159600160412
if( p->rc==SQLITE_OK
159601160413
&& (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
@@ -159703,11 +160515,11 @@
159703160515
/* Clean up the rbu_tmp_xxx table for the previous table. It
159704160516
** cannot be dropped as there are currently active SQL statements.
159705160517
** But the contents can be deleted. */
159706160518
if( pIter->abIndexed ){
159707160519
rbuMPrintfExec(p, p->dbRbu,
159708
- "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zTbl
160520
+ "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
159709160521
);
159710160522
}
159711160523
}else{
159712160524
rbuObjIterPrepareAll(p, pIter, 0);
159713160525
@@ -159926,14 +160738,17 @@
159926160738
** If there is a "*-oal" file in the file-system corresponding to the
159927160739
** target database in the file-system, delete it. If an error occurs,
159928160740
** leave an error code and error message in the rbu handle.
159929160741
*/
159930160742
static void rbuDeleteOalFile(sqlite3rbu *p){
159931
- char *zOal = sqlite3_mprintf("%s-oal", p->zTarget);
159932
- assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159933
- unlink(zOal);
159934
- sqlite3_free(zOal);
160743
+ char *zOal = rbuMPrintf(p, "%s-oal", p->zTarget);
160744
+ if( zOal ){
160745
+ sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
160746
+ assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
160747
+ pVfs->xDelete(pVfs, zOal, 0);
160748
+ sqlite3_free(zOal);
160749
+ }
159935160750
}
159936160751
159937160752
/*
159938160753
** Allocate a private rbu VFS for the rbu handle passed as the only
159939160754
** argument. This VFS will be used unless the call to sqlite3rbu_open()
@@ -160042,18 +160857,29 @@
160042160857
p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
160043160858
}
160044160859
160045160860
if( p->rc==SQLITE_OK ){
160046160861
if( p->eStage==RBU_STAGE_OAL ){
160862
+ sqlite3 *db = p->dbMain;
160047160863
160048160864
/* Open transactions both databases. The *-oal file is opened or
160049160865
** created at this point. */
160050
- p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160866
+ p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160051160867
if( p->rc==SQLITE_OK ){
160052160868
p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160053160869
}
160054
-
160870
+
160871
+ /* Check if the main database is a zipvfs db. If it is, set the upper
160872
+ ** level pager to use "journal_mode=off". This prevents it from
160873
+ ** generating a large journal using a temp file. */
160874
+ if( p->rc==SQLITE_OK ){
160875
+ int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
160876
+ if( frc==SQLITE_OK ){
160877
+ p->rc = sqlite3_exec(db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
160878
+ }
160879
+ }
160880
+
160055160881
/* Point the object iterator at the first object */
160056160882
if( p->rc==SQLITE_OK ){
160057160883
p->rc = rbuObjIterFirst(p, &p->objiter);
160058160884
}
160059160885
@@ -160162,10 +160988,36 @@
160162160988
** current RBU update was started.
160163160989
*/
160164160990
SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){
160165160991
return pRbu->nProgress;
160166160992
}
160993
+
160994
+SQLITE_API int SQLITE_STDCALL sqlite3rbu_savestate(sqlite3rbu *p){
160995
+ int rc = p->rc;
160996
+
160997
+ if( rc==SQLITE_DONE ) return SQLITE_OK;
160998
+
160999
+ assert( p->eStage>=RBU_STAGE_OAL && p->eStage<=RBU_STAGE_DONE );
161000
+ if( p->eStage==RBU_STAGE_OAL ){
161001
+ assert( rc!=SQLITE_DONE );
161002
+ if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
161003
+ }
161004
+
161005
+ p->rc = rc;
161006
+ rbuSaveState(p, p->eStage);
161007
+ rc = p->rc;
161008
+
161009
+ if( p->eStage==RBU_STAGE_OAL ){
161010
+ assert( rc!=SQLITE_DONE );
161011
+ if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
161012
+ if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, 0);
161013
+ if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0,0);
161014
+ }
161015
+
161016
+ p->rc = rc;
161017
+ return rc;
161018
+}
160167161019
160168161020
/**************************************************************************
160169161021
** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
160170161022
** of a standard VFS in the following ways:
160171161023
**
@@ -160642,11 +161494,12 @@
160642161494
rbuVfsSectorSize, /* xSectorSize */
160643161495
rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
160644161496
rbuVfsShmMap, /* xShmMap */
160645161497
rbuVfsShmLock, /* xShmLock */
160646161498
rbuVfsShmBarrier, /* xShmBarrier */
160647
- rbuVfsShmUnmap /* xShmUnmap */
161499
+ rbuVfsShmUnmap, /* xShmUnmap */
161500
+ 0, 0 /* xFetch, xUnfetch */
160648161501
};
160649161502
rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
160650161503
sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
160651161504
rbu_file *pFd = (rbu_file *)pFile;
160652161505
int rc = SQLITE_OK;
@@ -160984,10 +161837,13 @@
160984161837
**
160985161838
** The dbstat virtual table is used to extract low-level formatting
160986161839
** information from an SQLite database in order to implement the
160987161840
** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
160988161841
** for an example implementation.
161842
+**
161843
+** Additional information is available on the "dbstat.html" page of the
161844
+** official SQLite documentation.
160989161845
*/
160990161846
160991161847
/* #include "sqliteInt.h" ** Requires access to internal data structures ** */
160992161848
#if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
160993161849
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -161032,11 +161888,12 @@
161032161888
" ncell INTEGER, /* Cells on page (0 for overflow) */" \
161033161889
" payload INTEGER, /* Bytes of payload on this page */" \
161034161890
" unused INTEGER, /* Bytes of unused space on this page */" \
161035161891
" mx_payload INTEGER, /* Largest payload size of all cells */" \
161036161892
" pgoffset INTEGER, /* Offset of page in file */" \
161037
- " pgsize INTEGER /* Size of the page */" \
161893
+ " pgsize INTEGER, /* Size of the page */" \
161894
+ " schema TEXT HIDDEN /* Database schema being analyzed */" \
161038161895
");"
161039161896
161040161897
161041161898
typedef struct StatTable StatTable;
161042161899
typedef struct StatCursor StatCursor;
@@ -161070,10 +161927,11 @@
161070161927
161071161928
struct StatCursor {
161072161929
sqlite3_vtab_cursor base;
161073161930
sqlite3_stmt *pStmt; /* Iterates through set of root pages */
161074161931
int isEof; /* After pStmt has returned SQLITE_DONE */
161932
+ int iDb; /* Schema used for this query */
161075161933
161076161934
StatPage aPage[32];
161077161935
int iPage; /* Current entry in aPage[] */
161078161936
161079161937
/* Values to return. */
@@ -161147,13 +162005,36 @@
161147162005
return SQLITE_OK;
161148162006
}
161149162007
161150162008
/*
161151162009
** There is no "best-index". This virtual table always does a linear
161152
-** scan of the binary VFS log file.
162010
+** scan. However, a schema=? constraint should cause this table to
162011
+** operate on a different database schema, so check for it.
162012
+**
162013
+** idxNum is normally 0, but will be 1 if a schema=? constraint exists.
161153162014
*/
161154162015
static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
162016
+ int i;
162017
+
162018
+ pIdxInfo->estimatedCost = 1.0e6; /* Initial cost estimate */
162019
+
162020
+ /* Look for a valid schema=? constraint. If found, change the idxNum to
162021
+ ** 1 and request the value of that constraint be sent to xFilter. And
162022
+ ** lower the cost estimate to encourage the constrained version to be
162023
+ ** used.
162024
+ */
162025
+ for(i=0; i<pIdxInfo->nConstraint; i++){
162026
+ if( pIdxInfo->aConstraint[i].usable==0 ) continue;
162027
+ if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
162028
+ if( pIdxInfo->aConstraint[i].iColumn!=10 ) continue;
162029
+ pIdxInfo->idxNum = 1;
162030
+ pIdxInfo->estimatedCost = 1.0;
162031
+ pIdxInfo->aConstraintUsage[i].argvIndex = 1;
162032
+ pIdxInfo->aConstraintUsage[i].omit = 1;
162033
+ break;
162034
+ }
162035
+
161155162036
161156162037
/* Records are always returned in ascending order of (name, path).
161157162038
** If this will satisfy the client, set the orderByConsumed flag so that
161158162039
** SQLite does not do an external sort.
161159162040
*/
@@ -161169,50 +162050,31 @@
161169162050
)
161170162051
){
161171162052
pIdxInfo->orderByConsumed = 1;
161172162053
}
161173162054
161174
- pIdxInfo->estimatedCost = 10.0;
161175162055
return SQLITE_OK;
161176162056
}
161177162057
161178162058
/*
161179162059
** Open a new statvfs cursor.
161180162060
*/
161181162061
static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
161182162062
StatTable *pTab = (StatTable *)pVTab;
161183162063
StatCursor *pCsr;
161184
- int rc;
161185162064
161186162065
pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
161187162066
if( pCsr==0 ){
161188
- rc = SQLITE_NOMEM;
162067
+ return SQLITE_NOMEM;
161189162068
}else{
161190
- char *zSql;
161191162069
memset(pCsr, 0, sizeof(StatCursor));
161192162070
pCsr->base.pVtab = pVTab;
161193
-
161194
- zSql = sqlite3_mprintf(
161195
- "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
161196
- " UNION ALL "
161197
- "SELECT name, rootpage, type"
161198
- " FROM \"%w\".sqlite_master WHERE rootpage!=0"
161199
- " ORDER BY name", pTab->db->aDb[pTab->iDb].zName);
161200
- if( zSql==0 ){
161201
- rc = SQLITE_NOMEM;
161202
- }else{
161203
- rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
161204
- sqlite3_free(zSql);
161205
- }
161206
- if( rc!=SQLITE_OK ){
161207
- sqlite3_free(pCsr);
161208
- pCsr = 0;
161209
- }
162071
+ pCsr->iDb = pTab->iDb;
161210162072
}
161211162073
161212162074
*ppCursor = (sqlite3_vtab_cursor *)pCsr;
161213
- return rc;
162075
+ return SQLITE_OK;
161214162076
}
161215162077
161216162078
static void statClearPage(StatPage *p){
161217162079
int i;
161218162080
if( p->aCell ){
@@ -161233,10 +162095,11 @@
161233162095
statClearPage(&pCsr->aPage[i]);
161234162096
}
161235162097
pCsr->iPage = 0;
161236162098
sqlite3_free(pCsr->zPath);
161237162099
pCsr->zPath = 0;
162100
+ pCsr->isEof = 0;
161238162101
}
161239162102
161240162103
/*
161241162104
** Close a statvfs cursor.
161242162105
*/
@@ -161395,11 +162258,11 @@
161395162258
int rc;
161396162259
int nPayload;
161397162260
char *z;
161398162261
StatCursor *pCsr = (StatCursor *)pCursor;
161399162262
StatTable *pTab = (StatTable *)pCursor->pVtab;
161400
- Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
162263
+ Btree *pBt = pTab->db->aDb[pCsr->iDb].pBt;
161401162264
Pager *pPager = sqlite3BtreePager(pBt);
161402162265
161403162266
sqlite3_free(pCsr->zPath);
161404162267
pCsr->zPath = 0;
161405162268
@@ -161533,13 +162396,47 @@
161533162396
sqlite3_vtab_cursor *pCursor,
161534162397
int idxNum, const char *idxStr,
161535162398
int argc, sqlite3_value **argv
161536162399
){
161537162400
StatCursor *pCsr = (StatCursor *)pCursor;
162401
+ StatTable *pTab = (StatTable*)(pCursor->pVtab);
162402
+ char *zSql;
162403
+ int rc = SQLITE_OK;
162404
+ char *zMaster;
161538162405
162406
+ if( idxNum==1 ){
162407
+ const char *zDbase = (const char*)sqlite3_value_text(argv[0]);
162408
+ pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
162409
+ if( pCsr->iDb<0 ){
162410
+ sqlite3_free(pCursor->pVtab->zErrMsg);
162411
+ pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase);
162412
+ return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM;
162413
+ }
162414
+ }else{
162415
+ pCsr->iDb = pTab->iDb;
162416
+ }
161539162417
statResetCsr(pCsr);
161540
- return statNext(pCursor);
162418
+ sqlite3_finalize(pCsr->pStmt);
162419
+ pCsr->pStmt = 0;
162420
+ zMaster = pCsr->iDb==1 ? "sqlite_temp_master" : "sqlite_master";
162421
+ zSql = sqlite3_mprintf(
162422
+ "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
162423
+ " UNION ALL "
162424
+ "SELECT name, rootpage, type"
162425
+ " FROM \"%w\".%s WHERE rootpage!=0"
162426
+ " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
162427
+ if( zSql==0 ){
162428
+ return SQLITE_NOMEM;
162429
+ }else{
162430
+ rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
162431
+ sqlite3_free(zSql);
162432
+ }
162433
+
162434
+ if( rc==SQLITE_OK ){
162435
+ rc = statNext(pCursor);
162436
+ }
162437
+ return rc;
161541162438
}
161542162439
161543162440
static int statColumn(
161544162441
sqlite3_vtab_cursor *pCursor,
161545162442
sqlite3_context *ctx,
@@ -161572,14 +162469,19 @@
161572162469
sqlite3_result_int(ctx, pCsr->nMxPayload);
161573162470
break;
161574162471
case 8: /* pgoffset */
161575162472
sqlite3_result_int64(ctx, pCsr->iOffset);
161576162473
break;
161577
- default: /* pgsize */
161578
- assert( i==9 );
162474
+ case 9: /* pgsize */
161579162475
sqlite3_result_int(ctx, pCsr->szPage);
161580162476
break;
162477
+ default: { /* schema */
162478
+ sqlite3 *db = sqlite3_context_db_handle(ctx);
162479
+ int iDb = pCsr->iDb;
162480
+ sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
162481
+ break;
162482
+ }
161581162483
}
161582162484
return SQLITE_OK;
161583162485
}
161584162486
161585162487
static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
161586162488
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.11.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -323,13 +323,13 @@
323 **
324 ** See also: [sqlite3_libversion()],
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.11.1"
329 #define SQLITE_VERSION_NUMBER 3008011
330 #define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -689,10 +689,11 @@
689 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
690 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
691 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
692 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
693 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
 
694 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
695 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
696 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
697 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
698 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -3585,11 +3586,12 @@
3585 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3586 ** METHOD: sqlite3_stmt
3587 **
3588 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3589 ** [prepared statement] S has been stepped at least once using
3590 ** [sqlite3_step(S)] but has not run to completion and/or has not
 
3591 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
3592 ** interface returns false if S is a NULL pointer. If S is not a
3593 ** NULL pointer and is not a pointer to a valid [prepared statement]
3594 ** object, then the behavior is undefined and probably undesirable.
3595 **
@@ -4567,10 +4569,26 @@
4567 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
4568 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
4569 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4570 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4572 /*
4573 ** CAPI3REF: Copy And Free SQL Values
4574 ** METHOD: sqlite3_value
4575 **
4576 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
@@ -4866,10 +4884,25 @@
4866 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4867 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4868 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4869 SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
4870
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4871 /*
4872 ** CAPI3REF: Define New Collating Sequences
4873 ** METHOD: sqlite3
4874 **
4875 ** ^These functions add, remove, or modify a [collation] associated
@@ -8361,19 +8394,22 @@
8361 # define SQLITE_NOINLINE
8362 #endif
8363
8364 /*
8365 ** Make sure that the compiler intrinsics we desire are enabled when
8366 ** compiling with an appropriate version of MSVC.
 
8367 */
8368 #if defined(_MSC_VER) && _MSC_VER>=1300
8369 # if !defined(_WIN32_WCE)
8370 # include <intrin.h>
8371 # pragma intrinsic(_byteswap_ushort)
8372 # pragma intrinsic(_byteswap_ulong)
8373 # else
8374 # include <cmnintrin.h>
 
 
8375 # endif
8376 #endif
8377
8378 /*
8379 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
@@ -10050,16 +10086,20 @@
10050 */
10051 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
10052 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
10053 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
10054 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
 
 
 
10055 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
10056 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
10057 SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
10058 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
10059 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
10060 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
 
10061 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
10062 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
10063 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
10064 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
10065 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
@@ -11333,22 +11373,24 @@
11333 /*
11334 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
11335 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There
11336 ** are assert() statements in the code to verify this.
11337 */
11338 #define SQLITE_FUNC_ENCMASK 0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
11339 #define SQLITE_FUNC_LIKE 0x004 /* Candidate for the LIKE optimization */
11340 #define SQLITE_FUNC_CASE 0x008 /* Case-sensitive LIKE-type function */
11341 #define SQLITE_FUNC_EPHEM 0x010 /* Ephemeral. Delete with VDBE */
11342 #define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
11343 #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
11344 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
11345 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
11346 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
11347 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
11348 #define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
11349 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
 
 
11350
11351 /*
11352 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
11353 ** used to create the initializers for the FuncDef structures.
11354 **
@@ -11359,10 +11401,16 @@
11359 ** as the user-data (sqlite3_user_data()) for the function. If
11360 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
11361 **
11362 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
11363 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
 
 
 
 
 
 
11364 **
11365 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
11366 ** Used to create an aggregate function definition implemented by
11367 ** the C functions xStep and xFinal. The first four parameters
11368 ** are interpreted in the same way as the first 4 parameters to
@@ -11380,15 +11428,18 @@
11380 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11381 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
11382 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
11383 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11384 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
 
 
 
11385 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
11386 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
11387 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
11388 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
11389 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11390 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
11391 #define LIKEFUNC(zName, nArg, arg, flags) \
11392 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
11393 (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
11394 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
@@ -11428,10 +11479,11 @@
11428 struct Module {
11429 const sqlite3_module *pModule; /* Callback pointers */
11430 const char *zName; /* Name passed to create_module() */
11431 void *pAux; /* pAux passed to create_module() */
11432 void (*xDestroy)(void *); /* Module destructor function */
 
11433 };
11434
11435 /*
11436 ** information about each column of an SQL table is held in an instance
11437 ** of this structure.
@@ -11473,10 +11525,11 @@
11473 /*
11474 ** A sort order can be either ASC or DESC.
11475 */
11476 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
11477 #define SQLITE_SO_DESC 1 /* Sort in ascending order */
 
11478
11479 /*
11480 ** Column affinity types.
11481 **
11482 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
@@ -11579,13 +11632,12 @@
11579 Column *aCol; /* Information about each column */
11580 Index *pIndex; /* List of SQL indexes on this table. */
11581 Select *pSelect; /* NULL for tables. Points to definition if a view. */
11582 FKey *pFKey; /* Linked list of all foreign keys in this table */
11583 char *zColAff; /* String defining the affinity of each column */
11584 #ifndef SQLITE_OMIT_CHECK
11585 ExprList *pCheck; /* All CHECK constraints */
11586 #endif
11587 int tnum; /* Root BTree page for this table */
11588 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
11589 i16 nCol; /* Number of columns in this table */
11590 u16 nRef; /* Number of pointers to this Table */
11591 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
@@ -11598,11 +11650,11 @@
11598 #ifndef SQLITE_OMIT_ALTERTABLE
11599 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
11600 #endif
11601 #ifndef SQLITE_OMIT_VIRTUALTABLE
11602 int nModuleArg; /* Number of arguments to the module */
11603 char **azModuleArg; /* Text of all module args. [0] is module name */
11604 VTable *pVTable; /* List of VTable objects. */
11605 #endif
11606 Trigger *pTrigger; /* List of triggers stored in pSchema */
11607 Schema *pSchema; /* Schema that contains this table */
11608 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
@@ -11819,10 +11871,11 @@
11819 Index *pNext; /* The next index associated with the same table */
11820 Schema *pSchema; /* Schema containing this index */
11821 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
11822 char **azColl; /* Array of collation sequence names for index */
11823 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
 
11824 int tnum; /* DB Page containing root of this index */
11825 LogEst szIdxRow; /* Estimated average row size in bytes */
11826 u16 nKeyCol; /* Number of columns forming the key */
11827 u16 nColumn; /* Number of columns stored in the index */
11828 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12068,13 +12121,14 @@
12068 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
12069 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
12070 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
12071 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
12072 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
12073 #define EP_ConstFunc 0x080000 /* Node is a SQLITE_FUNC_CONSTANT function */
12074 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
12075 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
 
12076
12077 /*
12078 ** Combinations of two or more EP_* flags
12079 */
12080 #define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
@@ -12233,24 +12287,31 @@
12233 Table *pTab; /* An SQL table corresponding to zName */
12234 Select *pSelect; /* A SELECT statement used in place of a table name */
12235 int addrFillSub; /* Address of subroutine to manifest a subquery */
12236 int regReturn; /* Register holding return address of addrFillSub */
12237 int regResult; /* Registers holding results of a co-routine */
12238 u8 jointype; /* Type of join between this able and the previous */
12239 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
12240 unsigned isCorrelated :1; /* True if sub-query is correlated */
12241 unsigned viaCoroutine :1; /* Implemented as a co-routine */
12242 unsigned isRecursive :1; /* True for recursive reference in WITH */
 
 
 
 
12243 #ifndef SQLITE_OMIT_EXPLAIN
12244 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
12245 #endif
12246 int iCursor; /* The VDBE cursor number used to access this table */
12247 Expr *pOn; /* The ON clause of a join */
12248 IdList *pUsing; /* The USING clause of a join */
12249 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
12250 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
12251 Index *pIndex; /* Index structure corresponding to zIndex, if any */
 
 
 
12252 } a[1]; /* One entry for each identifier on the list */
12253 };
12254
12255 /*
12256 ** Permitted values of the SrcList.a.jointype field
@@ -12332,10 +12393,11 @@
12332 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
12333 #define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
12334 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
12335 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
12336 #define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
 
12337 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
12338
12339 /*
12340 ** An instance of the following structure contains all information
12341 ** needed to generate code for a single SELECT statement.
@@ -12601,11 +12663,11 @@
12601 int nSet; /* Number of sets used so far */
12602 int nOnce; /* Number of OP_Once instructions so far */
12603 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
12604 int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
12605 int ckBase; /* Base register of data during check constraints */
12606 int iPartIdxTab; /* Table corresponding to a partial index */
12607 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
12608 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
12609 int nLabel; /* Number of labels used */
12610 int *aLabel; /* Space to hold the labels */
12611 struct yColCache {
@@ -12971,11 +13033,11 @@
12971 With *pOuter; /* Containing WITH clause, or NULL */
12972 struct Cte { /* For each CTE in the WITH clause.... */
12973 char *zName; /* Name of this CTE */
12974 ExprList *pCols; /* List of explicit column names, or NULL */
12975 Select *pSelect; /* The definition of this CTE */
12976 const char *zErr; /* Error message for circular references */
12977 } a[1];
12978 };
12979
12980 #ifdef SQLITE_DEBUG
12981 /*
@@ -13119,10 +13181,15 @@
13119 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3NoopMutex(void);
13120 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int);
13121 SQLITE_PRIVATE int sqlite3MutexInit(void);
13122 SQLITE_PRIVATE int sqlite3MutexEnd(void);
13123 #endif
 
 
 
 
 
13124
13125 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
13126 SQLITE_PRIVATE void sqlite3StatusUp(int, int);
13127 SQLITE_PRIVATE void sqlite3StatusDown(int, int);
13128 SQLITE_PRIVATE void sqlite3StatusSet(int, int);
@@ -13185,10 +13252,11 @@
13185 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
13186 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
13187 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
13188 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
13189 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
 
13190 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
13191 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
13192 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
13193 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
13194 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
@@ -13197,10 +13265,12 @@
13197 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
13198 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
13199 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
13200 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
13201 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
 
 
13202 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
13203 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
13204 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
13205 SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
13206 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
@@ -13238,11 +13308,11 @@
13238 SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
13239 SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64);
13240 SQLITE_PRIVATE int sqlite3RowSetTest(RowSet*, int iBatch, i64);
13241 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*);
13242
13243 SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int);
13244
13245 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
13246 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
13247 #else
13248 # define sqlite3ViewGetColumnNames(A,B) 0
@@ -13268,10 +13338,11 @@
13268 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
13269 SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
13270 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
13271 Token*, Select*, Expr*, IdList*);
13272 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
 
13273 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
13274 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
13275 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
13276 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
13277 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
@@ -13298,10 +13369,11 @@
13298 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
13299 SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
13300 SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
13301 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
13302 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
 
13303 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
13304 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
13305 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
13306 SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
13307 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
@@ -13313,13 +13385,14 @@
13313 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
13314 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
13315 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
13316 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
13317 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
13318 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
13319 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
13320 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
 
13321 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
13322 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
13323 SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
13324 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
13325 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
@@ -13487,11 +13560,11 @@
13487 sqlite3PutVarint((A),(B)))
13488 #define getVarint sqlite3GetVarint
13489 #define putVarint sqlite3PutVarint
13490
13491
13492 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
13493 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
13494 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
13495 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
13496 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
13497 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
@@ -13559,10 +13632,11 @@
13559 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
13560 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
13561 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
13562 SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
13563 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
 
13564 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
13565 SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
13566 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
13567 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
13568 SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
@@ -13667,10 +13741,12 @@
13667 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
13668 SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
13669 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
13670 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
13671 #endif
 
 
13672 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
13673 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
13674 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
13675 SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*);
13676 SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*);
@@ -14770,10 +14846,11 @@
14770 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
14771 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
14772 } u;
14773 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
14774 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
 
14775 int n; /* Number of characters in string value, excluding '\0' */
14776 char *z; /* String or BLOB value */
14777 /* ShallowCopy only needs to copy the information above */
14778 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14779 int szMalloc; /* Size of the zMalloc allocation */
@@ -16546,18 +16623,18 @@
16546 ** external linkage.
16547 */
16548 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
16549 static SQLITE_WSD FuncDef aDateTimeFuncs[] = {
16550 #ifndef SQLITE_OMIT_DATETIME_FUNCS
16551 FUNCTION(julianday, -1, 0, 0, juliandayFunc ),
16552 FUNCTION(date, -1, 0, 0, dateFunc ),
16553 FUNCTION(time, -1, 0, 0, timeFunc ),
16554 FUNCTION(datetime, -1, 0, 0, datetimeFunc ),
16555 FUNCTION(strftime, -1, 0, 0, strftimeFunc ),
16556 FUNCTION(current_time, 0, 0, 0, ctimeFunc ),
16557 FUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
16558 FUNCTION(current_date, 0, 0, 0, cdateFunc ),
16559 #else
16560 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
16561 STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc),
16562 STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
16563 #endif
@@ -19273,10 +19350,11 @@
19273 pTo->xMutexEnter = pFrom->xMutexEnter;
19274 pTo->xMutexTry = pFrom->xMutexTry;
19275 pTo->xMutexLeave = pFrom->xMutexLeave;
19276 pTo->xMutexHeld = pFrom->xMutexHeld;
19277 pTo->xMutexNotheld = pFrom->xMutexNotheld;
 
19278 pTo->xMutexAlloc = pFrom->xMutexAlloc;
19279 }
19280 rc = sqlite3GlobalConfig.mutex.xMutexInit();
19281
19282 #ifdef SQLITE_DEBUG
@@ -19679,10 +19757,21 @@
19679 }
19680 static int pthreadMutexNotheld(sqlite3_mutex *p){
19681 return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0;
19682 }
19683 #endif
 
 
 
 
 
 
 
 
 
 
 
19684
19685 /*
19686 ** Initialize and deinitialize the mutex subsystem.
19687 */
19688 static int pthreadMutexInit(void){ return SQLITE_OK; }
@@ -20341,10 +20430,23 @@
20341 static int winMutexNotheld(sqlite3_mutex *p){
20342 DWORD tid = GetCurrentThreadId();
20343 return winMutexNotheld2(p, tid);
20344 }
20345 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
20346
20347 /*
20348 ** Initialize and deinitialize the mutex subsystem.
20349 */
20350 static sqlite3_mutex winMutex_staticMutexes[] = {
@@ -20695,20 +20797,11 @@
20695 /*
20696 ** State information local to the memory allocation subsystem.
20697 */
20698 static SQLITE_WSD struct Mem0Global {
20699 sqlite3_mutex *mutex; /* Mutex to serialize access */
20700
20701 /*
20702 ** The alarm callback and its arguments. The mem0.mutex lock will
20703 ** be held while the callback is running. Recursive calls into
20704 ** the memory subsystem are allowed, but no new callbacks will be
20705 ** issued.
20706 */
20707 sqlite3_int64 alarmThreshold;
20708 void (*alarmCallback)(void*, sqlite3_int64,int);
20709 void *alarmArg;
20710
20711 /*
20712 ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
20713 ** (so that a range test can be used to determine if an allocation
20714 ** being freed came from pScratch) and a pointer to the list of
@@ -20721,11 +20814,11 @@
20721 /*
20722 ** True if heap is nearly "full" where "full" is defined by the
20723 ** sqlite3_soft_heap_limit() setting.
20724 */
20725 int nearlyFull;
20726 } mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
20727
20728 #define mem0 GLOBAL(struct Mem0Global, mem0)
20729
20730 /*
20731 ** Return the memory allocator mutex. sqlite3_status() needs it.
@@ -20732,54 +20825,25 @@
20732 */
20733 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void){
20734 return mem0.mutex;
20735 }
20736
20737 /*
20738 ** This routine runs when the memory allocator sees that the
20739 ** total memory allocation is about to exceed the soft heap
20740 ** limit.
20741 */
20742 static void softHeapLimitEnforcer(
20743 void *NotUsed,
20744 sqlite3_int64 NotUsed2,
20745 int allocSize
20746 ){
20747 UNUSED_PARAMETER2(NotUsed, NotUsed2);
20748 sqlite3_release_memory(allocSize);
20749 }
20750
20751 /*
20752 ** Change the alarm callback
20753 */
20754 static int sqlite3MemoryAlarm(
20755 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
20756 void *pArg,
20757 sqlite3_int64 iThreshold
20758 ){
20759 sqlite3_int64 nUsed;
20760 sqlite3_mutex_enter(mem0.mutex);
20761 mem0.alarmCallback = xCallback;
20762 mem0.alarmArg = pArg;
20763 mem0.alarmThreshold = iThreshold;
20764 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20765 mem0.nearlyFull = (iThreshold>0 && iThreshold<=nUsed);
20766 sqlite3_mutex_leave(mem0.mutex);
20767 return SQLITE_OK;
20768 }
20769
20770 #ifndef SQLITE_OMIT_DEPRECATED
20771 /*
20772 ** Deprecated external interface. Internal/core SQLite code
20773 ** should call sqlite3MemoryAlarm.
 
20774 */
20775 SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
20776 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
20777 void *pArg,
20778 sqlite3_int64 iThreshold
20779 ){
20780 return sqlite3MemoryAlarm(xCallback, pArg, iThreshold);
 
 
 
20781 }
20782 #endif
20783
20784 /*
20785 ** Set the soft heap-size limit for the library. Passing a zero or
@@ -20786,23 +20850,25 @@
20786 ** negative value indicates no limit.
20787 */
20788 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
20789 sqlite3_int64 priorLimit;
20790 sqlite3_int64 excess;
 
20791 #ifndef SQLITE_OMIT_AUTOINIT
20792 int rc = sqlite3_initialize();
20793 if( rc ) return -1;
20794 #endif
20795 sqlite3_mutex_enter(mem0.mutex);
20796 priorLimit = mem0.alarmThreshold;
 
 
 
 
 
 
 
20797 sqlite3_mutex_leave(mem0.mutex);
20798 if( n<0 ) return priorLimit;
20799 if( n>0 ){
20800 sqlite3MemoryAlarm(softHeapLimitEnforcer, 0, n);
20801 }else{
20802 sqlite3MemoryAlarm(0, 0, 0);
20803 }
20804 excess = sqlite3_memory_used() - n;
20805 if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
20806 return priorLimit;
20807 }
20808 SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
@@ -20895,23 +20961,14 @@
20895
20896 /*
20897 ** Trigger the alarm
20898 */
20899 static void sqlite3MallocAlarm(int nByte){
20900 void (*xCallback)(void*,sqlite3_int64,int);
20901 sqlite3_int64 nowUsed;
20902 void *pArg;
20903 if( mem0.alarmCallback==0 ) return;
20904 xCallback = mem0.alarmCallback;
20905 nowUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20906 pArg = mem0.alarmArg;
20907 mem0.alarmCallback = 0;
20908 sqlite3_mutex_leave(mem0.mutex);
20909 xCallback(pArg, nowUsed, nByte);
20910 sqlite3_mutex_enter(mem0.mutex);
20911 mem0.alarmCallback = xCallback;
20912 mem0.alarmArg = pArg;
20913 }
20914
20915 /*
20916 ** Do a memory allocation with statistics and alarms. Assume the
20917 ** lock is already held.
@@ -20920,11 +20977,11 @@
20920 int nFull;
20921 void *p;
20922 assert( sqlite3_mutex_held(mem0.mutex) );
20923 nFull = sqlite3GlobalConfig.m.xRoundup(n);
20924 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
20925 if( mem0.alarmCallback!=0 ){
20926 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20927 if( nUsed >= mem0.alarmThreshold - nFull ){
20928 mem0.nearlyFull = 1;
20929 sqlite3MallocAlarm(nFull);
20930 }else{
@@ -20931,11 +20988,11 @@
20931 mem0.nearlyFull = 0;
20932 }
20933 }
20934 p = sqlite3GlobalConfig.m.xMalloc(nFull);
20935 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
20936 if( p==0 && mem0.alarmCallback ){
20937 sqlite3MallocAlarm(nFull);
20938 p = sqlite3GlobalConfig.m.xMalloc(nFull);
20939 }
20940 #endif
20941 if( p ){
@@ -21106,23 +21163,24 @@
21106 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
21107 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
21108 return sqlite3GlobalConfig.m.xSize(p);
21109 }
21110 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
21111 if( db==0 ){
21112 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
21113 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
21114 return sqlite3MallocSize(p);
21115 }else{
21116 assert( sqlite3_mutex_held(db->mutex) );
21117 if( isLookaside(db, p) ){
21118 return db->lookaside.sz;
21119 }else{
21120 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
21121 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
21122 return sqlite3GlobalConfig.m.xSize(p);
21123 }
 
 
 
 
 
21124 }
21125 }
21126 SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
21127 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
21128 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
@@ -21219,11 +21277,11 @@
21219 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
21220 mem0.alarmThreshold-nDiff ){
21221 sqlite3MallocAlarm(nDiff);
21222 }
21223 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21224 if( pNew==0 && mem0.alarmCallback ){
21225 sqlite3MallocAlarm((int)nBytes);
21226 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21227 }
21228 if( pNew ){
21229 nNew = sqlite3MallocSize(pNew);
@@ -21933,25 +21991,20 @@
21933 break;
21934 }
21935 if( realvalue>0.0 ){
21936 LONGDOUBLE_TYPE scale = 1.0;
21937 while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;}
21938 while( realvalue>=1e64*scale && exp<=350 ){ scale *= 1e64; exp+=64; }
21939 while( realvalue>=1e8*scale && exp<=350 ){ scale *= 1e8; exp+=8; }
21940 while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
21941 realvalue /= scale;
21942 while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
21943 while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
21944 if( exp>350 ){
21945 if( prefix=='-' ){
21946 bufpt = "-Inf";
21947 }else if( prefix=='+' ){
21948 bufpt = "+Inf";
21949 }else{
21950 bufpt = "Inf";
21951 }
21952 length = sqlite3Strlen30(bufpt);
21953 break;
21954 }
21955 }
21956 bufpt = buf;
21957 /*
@@ -22096,27 +22149,28 @@
22096 break;
22097 case etSTRING:
22098 case etDYNSTRING:
22099 if( bArgList ){
22100 bufpt = getTextArg(pArgList);
 
22101 }else{
22102 bufpt = va_arg(ap,char*);
22103 }
22104 if( bufpt==0 ){
22105 bufpt = "";
22106 }else if( xtype==etDYNSTRING && !bArgList ){
22107 zExtra = bufpt;
22108 }
22109 if( precision>=0 ){
22110 for(length=0; length<precision && bufpt[length]; length++){}
22111 }else{
22112 length = sqlite3Strlen30(bufpt);
22113 }
22114 break;
22115 case etSQLESCAPE:
22116 case etSQLESCAPE2:
22117 case etSQLESCAPE3: {
22118 int i, j, k, n, isnull;
22119 int needQuote;
22120 char ch;
22121 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
22122 char *escarg;
@@ -22131,11 +22185,11 @@
22131 k = precision;
22132 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
22133 if( ch==q ) n++;
22134 }
22135 needQuote = !isnull && xtype==etSQLESCAPE2;
22136 n += i + 1 + needQuote*2;
22137 if( n>etBUFSIZE ){
22138 bufpt = zExtra = sqlite3Malloc( n );
22139 if( bufpt==0 ){
22140 setStrAccumError(pAccum, STRACCUM_NOMEM);
22141 return;
@@ -22527,11 +22581,12 @@
22527 }
22528 #endif
22529
22530
22531 /*
22532 ** variable-argument wrapper around sqlite3VXPrintf().
 
22533 */
22534 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
22535 va_list ap;
22536 va_start(ap,zFormat);
22537 sqlite3VXPrintf(p, bFlags, zFormat, ap);
@@ -22625,94 +22680,104 @@
22625 /*
22626 ** Generate a human-readable description of a the Select object.
22627 */
22628 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
22629 int n = 0;
22630 pView = sqlite3TreeViewPush(pView, moreToFollow);
22631 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
22632 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
22633 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
22634 );
22635 if( p->pSrc && p->pSrc->nSrc ) n++;
22636 if( p->pWhere ) n++;
22637 if( p->pGroupBy ) n++;
22638 if( p->pHaving ) n++;
22639 if( p->pOrderBy ) n++;
22640 if( p->pLimit ) n++;
22641 if( p->pOffset ) n++;
22642 if( p->pPrior ) n++;
22643 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
22644 if( p->pSrc && p->pSrc->nSrc ){
22645 int i;
22646 pView = sqlite3TreeViewPush(pView, (n--)>0);
22647 sqlite3TreeViewLine(pView, "FROM");
22648 for(i=0; i<p->pSrc->nSrc; i++){
22649 struct SrcList_item *pItem = &p->pSrc->a[i];
22650 StrAccum x;
22651 char zLine[100];
22652 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
22653 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
22654 if( pItem->zDatabase ){
22655 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
22656 }else if( pItem->zName ){
22657 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
22658 }
22659 if( pItem->pTab ){
22660 sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
22661 }
22662 if( pItem->zAlias ){
22663 sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
22664 }
22665 if( pItem->jointype & JT_LEFT ){
22666 sqlite3XPrintf(&x, 0, " LEFT-JOIN");
22667 }
22668 sqlite3StrAccumFinish(&x);
22669 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
22670 if( pItem->pSelect ){
22671 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
22672 }
22673 sqlite3TreeViewPop(pView);
22674 }
22675 sqlite3TreeViewPop(pView);
22676 }
22677 if( p->pWhere ){
22678 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
22679 sqlite3TreeViewExpr(pView, p->pWhere, 0);
22680 sqlite3TreeViewPop(pView);
22681 }
22682 if( p->pGroupBy ){
22683 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
22684 }
22685 if( p->pHaving ){
22686 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
22687 sqlite3TreeViewExpr(pView, p->pHaving, 0);
22688 sqlite3TreeViewPop(pView);
22689 }
22690 if( p->pOrderBy ){
22691 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
22692 }
22693 if( p->pLimit ){
22694 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
22695 sqlite3TreeViewExpr(pView, p->pLimit, 0);
22696 sqlite3TreeViewPop(pView);
22697 }
22698 if( p->pOffset ){
22699 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
22700 sqlite3TreeViewExpr(pView, p->pOffset, 0);
22701 sqlite3TreeViewPop(pView);
22702 }
22703 if( p->pPrior ){
22704 const char *zOp = "UNION";
22705 switch( p->op ){
22706 case TK_ALL: zOp = "UNION ALL"; break;
22707 case TK_INTERSECT: zOp = "INTERSECT"; break;
22708 case TK_EXCEPT: zOp = "EXCEPT"; break;
22709 }
22710 sqlite3TreeViewItem(pView, zOp, (n--)>0);
22711 sqlite3TreeViewSelect(pView, p->pPrior, 0);
22712 sqlite3TreeViewPop(pView);
22713 }
 
 
 
 
 
 
 
 
 
 
22714 sqlite3TreeViewPop(pView);
22715 }
22716
22717 /*
22718 ** Generate a human-readable explanation of an expression tree.
@@ -22783,15 +22848,10 @@
22783 }
22784 case TK_REGISTER: {
22785 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
22786 break;
22787 }
22788 case TK_AS: {
22789 sqlite3TreeViewLine(pView,"AS %Q", pExpr->u.zToken);
22790 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
22791 break;
22792 }
22793 case TK_ID: {
22794 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
22795 break;
22796 }
22797 #ifndef SQLITE_OMIT_CAST
@@ -22962,11 +23022,17 @@
22962 if( pList==0 ){
22963 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
22964 }else{
22965 sqlite3TreeViewLine(pView, "%s", zLabel);
22966 for(i=0; i<pList->nExpr; i++){
 
 
 
 
 
22967 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
 
22968 }
22969 }
22970 sqlite3TreeViewPop(pView);
22971 }
22972
@@ -24977,15 +25043,12 @@
24977 /*
24978 ** Return the number of bytes that will be needed to store the given
24979 ** 64-bit integer.
24980 */
24981 SQLITE_PRIVATE int sqlite3VarintLen(u64 v){
24982 int i = 0;
24983 do{
24984 i++;
24985 v >>= 7;
24986 }while( v!=0 && ALWAYS(i<9) );
24987 return i;
24988 }
24989
24990
24991 /*
@@ -24994,15 +25057,17 @@
24994 SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
24995 #if SQLITE_BYTEORDER==4321
24996 u32 x;
24997 memcpy(&x,p,4);
24998 return x;
24999 #elif SQLITE_BYTEORDER==1234 && defined(__GNUC__) && GCC_VERSION>=4003000
 
25000 u32 x;
25001 memcpy(&x,p,4);
25002 return __builtin_bswap32(x);
25003 #elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
 
25004 u32 x;
25005 memcpy(&x,p,4);
25006 return _byteswap_ulong(x);
25007 #else
25008 testcase( p[0]&0x80 );
@@ -29103,11 +29168,10 @@
29103 i64 newOffset;
29104 #endif
29105 TIMER_START;
29106 assert( cnt==(cnt&0x1ffff) );
29107 assert( id->h>2 );
29108 cnt &= 0x1ffff;
29109 do{
29110 #if defined(USE_PREAD)
29111 got = osPread(id->h, pBuf, cnt, offset);
29112 SimulateIOError( got = -1 );
29113 #elif defined(USE_PREAD64)
@@ -29320,20 +29384,20 @@
29320 amt -= nCopy;
29321 offset += nCopy;
29322 }
29323 }
29324 #endif
29325
29326 while( amt>0 && (wrote = seekAndWrite(pFile, offset, pBuf, amt))>0 ){
29327 amt -= wrote;
29328 offset += wrote;
29329 pBuf = &((char*)pBuf)[wrote];
29330 }
29331 SimulateIOError(( wrote=(-1), amt=1 ));
29332 SimulateDiskfullError(( wrote=0, amt=1 ));
29333
29334 if( amt>0 ){
29335 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
29336 /* lastErrno set by seekAndWrite */
29337 return SQLITE_IOERR_WRITE;
29338 }else{
29339 storeLastErrno(pFile, 0); /* not a system error */
@@ -39798,11 +39862,11 @@
39798 ** A complete page cache is an instance of this structure.
39799 */
39800 struct PCache {
39801 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
39802 PgHdr *pSynced; /* Last synced page in dirty page list */
39803 int nRef; /* Number of referenced pages */
39804 int szCache; /* Configured cache size */
39805 int szPage; /* Size of every page in this cache */
39806 int szExtra; /* Size of extra space for each page */
39807 u8 bPurgeable; /* True if pages are on backing store */
39808 u8 eCreate; /* eCreate value for for xFetch() */
@@ -39963,11 +40027,11 @@
39963 /*
39964 ** Change the page size for PCache object. The caller must ensure that there
39965 ** are no outstanding page references when this function is called.
39966 */
39967 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
39968 assert( pCache->nRef==0 && pCache->pDirty==0 );
39969 if( pCache->szPage ){
39970 sqlite3_pcache *pNew;
39971 pNew = sqlite3GlobalConfig.pcache2.xCreate(
39972 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
39973 pCache->bPurgeable
@@ -40130,13 +40194,11 @@
40130 pPgHdr = (PgHdr *)pPage->pExtra;
40131
40132 if( !pPgHdr->pPage ){
40133 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
40134 }
40135 if( 0==pPgHdr->nRef ){
40136 pCache->nRef++;
40137 }
40138 pPgHdr->nRef++;
40139 return pPgHdr;
40140 }
40141
40142 /*
@@ -40143,13 +40205,12 @@
40143 ** Decrement the reference count on a page. If the page is clean and the
40144 ** reference count drops to 0, then it is made eligible for recycling.
40145 */
40146 SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
40147 assert( p->nRef>0 );
40148 p->nRef--;
40149 if( p->nRef==0 ){
40150 p->pCache->nRef--;
40151 if( p->flags&PGHDR_CLEAN ){
40152 pcacheUnpin(p);
40153 }else if( p->pDirtyPrev!=0 ){
40154 /* Move the page to the head of the dirty list. */
40155 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
@@ -40161,10 +40222,11 @@
40161 ** Increase the reference count of a supplied page by 1.
40162 */
40163 SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
40164 assert(p->nRef>0);
40165 p->nRef++;
 
40166 }
40167
40168 /*
40169 ** Drop a page from the cache. There must be exactly one reference to the
40170 ** page. This function deletes that reference, so after it returns the
@@ -40173,11 +40235,11 @@
40173 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
40174 assert( p->nRef==1 );
40175 if( p->flags&PGHDR_DIRTY ){
40176 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
40177 }
40178 p->pCache->nRef--;
40179 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
40180 }
40181
40182 /*
40183 ** Make sure the page is marked as dirty. If it isn't dirty already,
@@ -40269,15 +40331,15 @@
40269 if( ALWAYS(p->pgno>pgno) ){
40270 assert( p->flags&PGHDR_DIRTY );
40271 sqlite3PcacheMakeClean(p);
40272 }
40273 }
40274 if( pgno==0 && pCache->nRef ){
40275 sqlite3_pcache_page *pPage1;
40276 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
40277 if( ALWAYS(pPage1) ){ /* Page 1 is always available in cache, because
40278 ** pCache->nRef>0 */
40279 memset(pPage1->pBuf, 0, pCache->szPage);
40280 pgno = 1;
40281 }
40282 }
40283 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
@@ -40379,14 +40441,17 @@
40379 }
40380 return pcacheSortDirtyList(pCache->pDirty);
40381 }
40382
40383 /*
40384 ** Return the total number of referenced pages held by the cache.
 
 
 
40385 */
40386 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
40387 return pCache->nRef;
40388 }
40389
40390 /*
40391 ** Return the number of references to the page supplied as an argument.
40392 */
@@ -40517,11 +40582,11 @@
40517 **
40518 ** The third case is a chunk of heap memory (defaulting to 100 pages worth)
40519 ** that is allocated when the page cache is created. The size of the local
40520 ** bulk allocation can be adjusted using
40521 **
40522 ** sqlite3_config(SQLITE_CONFIG_PCACHE, 0, 0, N).
40523 **
40524 ** If N is positive, then N pages worth of memory are allocated using a single
40525 ** sqlite3Malloc() call and that memory is used for the first N pages allocated.
40526 ** Or if N is negative, then -1024*N bytes of memory are allocated and used
40527 ** for as many pages as can be accomodated.
@@ -40538,10 +40603,28 @@
40538
40539 typedef struct PCache1 PCache1;
40540 typedef struct PgHdr1 PgHdr1;
40541 typedef struct PgFreeslot PgFreeslot;
40542 typedef struct PGroup PGroup;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40543
40544 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
40545 ** of one or more PCaches that are able to recycle each other's unpinned
40546 ** pages when they are under memory pressure. A PGroup is an instance of
40547 ** the following object.
@@ -40567,11 +40650,11 @@
40567 sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */
40568 unsigned int nMaxPage; /* Sum of nMax for purgeable caches */
40569 unsigned int nMinPage; /* Sum of nMin for purgeable caches */
40570 unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */
40571 unsigned int nCurrentPage; /* Number of purgeable pages allocated */
40572 PgHdr1 *pLruHead, *pLruTail; /* LRU list of unpinned pages */
40573 };
40574
40575 /* Each page cache is an instance of the following object. Every
40576 ** open database file (including each in-memory database and each
40577 ** temporary or transient database) has a single page cache which
@@ -40605,27 +40688,10 @@
40605 PgHdr1 **apHash; /* Hash table for fast lookup by key */
40606 PgHdr1 *pFree; /* List of unused pcache-local pages */
40607 void *pBulk; /* Bulk memory used by pcache-local */
40608 };
40609
40610 /*
40611 ** Each cache entry is represented by an instance of the following
40612 ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
40613 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
40614 ** in memory.
40615 */
40616 struct PgHdr1 {
40617 sqlite3_pcache_page page;
40618 unsigned int iKey; /* Key value (page number) */
40619 u8 isPinned; /* Page in use, not on the LRU list */
40620 u8 isBulkLocal; /* This page from bulk local storage */
40621 PgHdr1 *pNext; /* Next in hash table chain */
40622 PCache1 *pCache; /* Cache that currently owns this page */
40623 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
40624 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
40625 };
40626
40627 /*
40628 ** Free slots in the allocator used to divide up the global page cache
40629 ** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
40630 */
40631 struct PgFreeslot {
@@ -40681,10 +40747,11 @@
40681 # define PCACHE1_MIGHT_USE_GROUP_MUTEX 1
40682 #endif
40683
40684 /******************************************************************************/
40685 /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
 
40686
40687 /*
40688 ** This function is called during initialization if a static buffer is
40689 ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
40690 ** verb to sqlite3_config(). Parameter pBuf points to an allocation large
@@ -40741,10 +40808,11 @@
40741 for(i=0; i<nBulk; i++){
40742 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
40743 pX->page.pBuf = zBulk;
40744 pX->page.pExtra = &pX[1];
40745 pX->isBulkLocal = 1;
 
40746 pX->pNext = pCache->pFree;
40747 pCache->pFree = pX;
40748 zBulk += pCache->szAlloc;
40749 }
40750 }
@@ -40844,11 +40912,11 @@
40844 #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
40845
40846 /*
40847 ** Allocate a new page object initially associated with cache pCache.
40848 */
40849 static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
40850 PgHdr1 *p = 0;
40851 void *pPg;
40852
40853 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40854 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
@@ -40862,10 +40930,11 @@
40862 ** this mutex is not held. */
40863 assert( pcache1.separateCache==0 );
40864 assert( pCache->pGroup==&pcache1.grp );
40865 pcache1LeaveMutex(pCache->pGroup);
40866 #endif
 
40867 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
40868 pPg = pcache1Alloc(pCache->szPage);
40869 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
40870 if( !pPg || !p ){
40871 pcache1Free(pPg);
@@ -40874,17 +40943,19 @@
40874 }
40875 #else
40876 pPg = pcache1Alloc(pCache->szAlloc);
40877 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
40878 #endif
 
40879 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40880 pcache1EnterMutex(pCache->pGroup);
40881 #endif
40882 if( pPg==0 ) return 0;
40883 p->page.pBuf = pPg;
40884 p->page.pExtra = &p[1];
40885 p->isBulkLocal = 0;
 
40886 }
40887 if( pCache->bPurgeable ){
40888 pCache->pGroup->nCurrentPage++;
40889 }
40890 return p;
@@ -41007,26 +41078,20 @@
41007 PCache1 *pCache;
41008
41009 assert( pPage!=0 );
41010 assert( pPage->isPinned==0 );
41011 pCache = pPage->pCache;
41012 assert( pPage->pLruNext || pPage==pCache->pGroup->pLruTail );
41013 assert( pPage->pLruPrev || pPage==pCache->pGroup->pLruHead );
41014 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
41015 if( pPage->pLruPrev ){
41016 pPage->pLruPrev->pLruNext = pPage->pLruNext;
41017 }else{
41018 pCache->pGroup->pLruHead = pPage->pLruNext;
41019 }
41020 if( pPage->pLruNext ){
41021 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
41022 }else{
41023 pCache->pGroup->pLruTail = pPage->pLruPrev;
41024 }
41025 pPage->pLruNext = 0;
41026 pPage->pLruPrev = 0;
41027 pPage->isPinned = 1;
 
 
41028 pCache->nRecyclable--;
41029 return pPage;
41030 }
41031
41032
@@ -41055,13 +41120,15 @@
41055 ** If there are currently more than nMaxPage pages allocated, try
41056 ** to recycle pages to reduce the number allocated to nMaxPage.
41057 */
41058 static void pcache1EnforceMaxPage(PCache1 *pCache){
41059 PGroup *pGroup = pCache->pGroup;
 
41060 assert( sqlite3_mutex_held(pGroup->mutex) );
41061 while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
41062 PgHdr1 *p = pGroup->pLruTail;
 
41063 assert( p->pCache->pGroup==pGroup );
41064 assert( p->isPinned==0 );
41065 pcache1PinPage(p);
41066 pcache1RemoveFromHash(p, 1);
41067 }
@@ -41191,10 +41258,14 @@
41191 pGroup = (PGroup*)&pCache[1];
41192 pGroup->mxPinned = 10;
41193 }else{
41194 pGroup = &pcache1.grp;
41195 }
 
 
 
 
41196 pCache->pGroup = pGroup;
41197 pCache->szPage = szPage;
41198 pCache->szExtra = szExtra;
41199 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
41200 pCache->bPurgeable = (bPurgeable ? 1 : 0);
@@ -41298,15 +41369,15 @@
41298 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
41299 assert( pCache->nHash>0 && pCache->apHash );
41300
41301 /* Step 4. Try to recycle a page. */
41302 if( pCache->bPurgeable
41303 && pGroup->pLruTail
41304 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
41305 ){
41306 PCache1 *pOther;
41307 pPage = pGroup->pLruTail;
41308 assert( pPage->isPinned==0 );
41309 pcache1RemoveFromHash(pPage, 0);
41310 pcache1PinPage(pPage);
41311 pOther = pPage->pCache;
41312 if( pOther->szAlloc != pCache->szAlloc ){
@@ -41319,13 +41390,11 @@
41319
41320 /* Step 5. If a usable page buffer has still not been found,
41321 ** attempt to allocate a new one.
41322 */
41323 if( !pPage ){
41324 if( createFlag==1 ){ sqlite3BeginBenignMalloc(); }
41325 pPage = pcache1AllocPage(pCache);
41326 if( createFlag==1 ){ sqlite3EndBenignMalloc(); }
41327 }
41328
41329 if( pPage ){
41330 unsigned int h = iKey % pCache->nHash;
41331 pCache->nPage++;
@@ -41413,11 +41482,14 @@
41413
41414 /* Step 1: Search the hash table for an existing entry. */
41415 pPage = pCache->apHash[iKey % pCache->nHash];
41416 while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }
41417
41418 /* Step 2: Abort if no existing page is found and createFlag is 0 */
 
 
 
41419 if( pPage ){
41420 if( !pPage->isPinned ){
41421 return pcache1PinPage(pPage);
41422 }else{
41423 return pPage;
@@ -41490,25 +41562,20 @@
41490
41491 /* It is an error to call this function if the page is already
41492 ** part of the PGroup LRU list.
41493 */
41494 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
41495 assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
41496 assert( pPage->isPinned==1 );
41497
41498 if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
41499 pcache1RemoveFromHash(pPage, 1);
41500 }else{
41501 /* Add the page to the PGroup LRU list. */
41502 if( pGroup->pLruHead ){
41503 pGroup->pLruHead->pLruPrev = pPage;
41504 pPage->pLruNext = pGroup->pLruHead;
41505 pGroup->pLruHead = pPage;
41506 }else{
41507 pGroup->pLruTail = pPage;
41508 pGroup->pLruHead = pPage;
41509 }
41510 pCache->nRecyclable++;
41511 pPage->isPinned = 0;
41512 }
41513
41514 pcache1LeaveMutex(pCache->pGroup);
@@ -41642,11 +41709,14 @@
41642 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
41643 assert( sqlite3_mutex_notheld(pcache1.mutex) );
41644 if( sqlite3GlobalConfig.nPage==0 ){
41645 PgHdr1 *p;
41646 pcache1EnterMutex(&pcache1.grp);
41647 while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
 
 
 
41648 nFree += pcache1MemSize(p->page.pBuf);
41649 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
41650 nFree += sqlite3MemSize(p);
41651 #endif
41652 assert( p->isPinned==0 );
@@ -41670,11 +41740,11 @@
41670 int *pnMin, /* OUT: Sum of PCache1.nMin for purgeable caches */
41671 int *pnRecyclable /* OUT: Total number of pages available for recycling */
41672 ){
41673 PgHdr1 *p;
41674 int nRecyclable = 0;
41675 for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
41676 assert( p->isPinned==0 );
41677 nRecyclable++;
41678 }
41679 *pnCurrent = pcache1.grp.nCurrentPage;
41680 *pnMax = (int)pcache1.grp.nMaxPage;
@@ -42984,11 +43054,11 @@
42984 u8 changeCountDone; /* Set after incrementing the change-counter */
42985 u8 setMaster; /* True if a m-j name has been written to jrnl */
42986 u8 doNotSpill; /* Do not spill the cache when non-zero */
42987 u8 subjInMemory; /* True to use in-memory sub-journals */
42988 u8 bUseFetch; /* True to use xFetch() */
42989 u8 hasBeenUsed; /* True if any content previously read */
42990 Pgno dbSize; /* Number of pages in the database */
42991 Pgno dbOrigSize; /* dbSize before the current transaction */
42992 Pgno dbFileSize; /* Number of pages in the database file */
42993 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
42994 int errCode; /* One of several kinds of errors */
@@ -47434,14 +47504,14 @@
47434 assert( (pPager->eLock==SHARED_LOCK)
47435 || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
47436 );
47437 }
47438
47439 if( !pPager->tempFile && pPager->hasBeenUsed ){
47440 /* The shared-lock has just been acquired then check to
47441 ** see if the database has been modified. If the database has changed,
47442 ** flush the cache. The pPager->hasBeenUsed flag prevents this from
47443 ** occurring on the very first access to a file, in order to save a
47444 ** single unnecessary sqlite3OsRead() call at the start-up.
47445 **
47446 ** Database changes are detected by looking at 15 bytes beginning
47447 ** at offset 24 into the file. The first 4 of these 16 bytes are
@@ -47507,10 +47577,11 @@
47507 assert( !MEMDB );
47508 pager_unlock(pPager);
47509 assert( pPager->eState==PAGER_OPEN );
47510 }else{
47511 pPager->eState = PAGER_READER;
 
47512 }
47513 return rc;
47514 }
47515
47516 /*
@@ -47590,25 +47661,29 @@
47590
47591 /* It is acceptable to use a read-only (mmap) page for any page except
47592 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
47593 ** flag was specified by the caller. And so long as the db is not a
47594 ** temporary or in-memory database. */
47595 const int bMmapOk = (pgno!=1 && USEFETCH(pPager)
47596 && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
47597 #ifdef SQLITE_HAS_CODEC
47598 && pPager->xCodec==0
47599 #endif
47600 );
47601
 
 
 
 
 
 
 
47602 assert( pPager->eState>=PAGER_READER );
47603 assert( assert_pager_state(pPager) );
47604 assert( noContent==0 || bMmapOk==0 );
47605
47606 if( pgno==0 ){
47607 return SQLITE_CORRUPT_BKPT;
47608 }
47609 pPager->hasBeenUsed = 1;
47610
47611 /* If the pager is in the error state, return an error immediately.
47612 ** Otherwise, request the page from the PCache layer. */
47613 if( pPager->errCode!=SQLITE_OK ){
47614 rc = pPager->errCode;
@@ -47759,11 +47834,11 @@
47759 sqlite3_pcache_page *pPage;
47760 assert( pPager!=0 );
47761 assert( pgno!=0 );
47762 assert( pPager->pPCache!=0 );
47763 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
47764 assert( pPage==0 || pPager->hasBeenUsed );
47765 if( pPage==0 ) return 0;
47766 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
47767 }
47768
47769 /*
@@ -48726,11 +48801,11 @@
48726 return pPager->readOnly;
48727 }
48728
48729 #ifdef SQLITE_DEBUG
48730 /*
48731 ** Return the number of references to the pager.
48732 */
48733 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
48734 return sqlite3PcacheRefCount(pPager->pPCache);
48735 }
48736 #endif
@@ -50038,10 +50113,11 @@
50038 u8 readOnly; /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
50039 u8 truncateOnCommit; /* True to truncate WAL file on commit */
50040 u8 syncHeader; /* Fsync the WAL header if true */
50041 u8 padToSectorBoundary; /* Pad transactions out to the next sector */
50042 WalIndexHdr hdr; /* Wal-index header for current transaction */
 
50043 const char *zWalName; /* Name of WAL file */
50044 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
50045 #ifdef SQLITE_DEBUG
50046 u8 lockError; /* True if a locking error has occurred */
50047 #endif
@@ -51906,16 +51982,31 @@
51906 ** copied into the database by a checkpointer. If either of these things
51907 ** happened, then reading the database with the current value of
51908 ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
51909 ** instead.
51910 **
51911 ** This does not guarantee that the copy of the wal-index header is up to
51912 ** date before proceeding. That would not be possible without somehow
51913 ** blocking writers. It only guarantees that a dangerous checkpoint or
51914 ** log-wrap (either of which would require an exclusive lock on
51915 ** WAL_READ_LOCK(mxI)) has not occurred since the snapshot was valid.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51916 */
 
51917 walShmBarrier(pWal);
51918 if( pInfo->aReadMark[mxI]!=mxReadMark
51919 || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
51920 ){
51921 walUnlockShared(pWal, WAL_READ_LOCK(mxI));
@@ -51982,10 +52073,11 @@
51982 u32 *piRead /* OUT: Frame number (or zero) */
51983 ){
51984 u32 iRead = 0; /* If !=0, WAL frame to return data from */
51985 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
51986 int iHash; /* Used to loop through N hash tables */
 
51987
51988 /* This routine is only be called from within a read transaction. */
51989 assert( pWal->readLock>=0 || pWal->lockError );
51990
51991 /* If the "last page" field of the wal-index header snapshot is 0, then
@@ -52022,11 +52114,12 @@
52022 **
52023 ** (iFrame<=iLast):
52024 ** This condition filters out entries that were added to the hash
52025 ** table after the current read-transaction had started.
52026 */
52027 for(iHash=walFramePage(iLast); iHash>=0 && iRead==0; iHash--){
 
52028 volatile ht_slot *aHash; /* Pointer to hash table */
52029 volatile u32 *aPgno; /* Pointer to array of page numbers */
52030 u32 iZero; /* Frame number corresponding to aPgno[0] */
52031 int iKey; /* Hash slot index */
52032 int nCollide; /* Number of hash collisions remaining */
@@ -52037,11 +52130,11 @@
52037 return rc;
52038 }
52039 nCollide = HASHTABLE_NSLOT;
52040 for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
52041 u32 iFrame = aHash[iKey] + iZero;
52042 if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
52043 assert( iFrame>iRead || CORRUPT_DB );
52044 iRead = iFrame;
52045 }
52046 if( (nCollide--)==0 ){
52047 return SQLITE_CORRUPT_BKPT;
@@ -52054,11 +52147,12 @@
52054 ** of the wal-index file content. Make sure the results agree with the
52055 ** result obtained using the hash indexes above. */
52056 {
52057 u32 iRead2 = 0;
52058 u32 iTest;
52059 for(iTest=iLast; iTest>0; iTest--){
 
52060 if( walFramePgno(pWal, iTest)==pgno ){
52061 iRead2 = iTest;
52062 break;
52063 }
52064 }
@@ -53494,13 +53588,15 @@
53494 ** two-byte aligned address. get2bytea() is only used for accessing the
53495 ** cell addresses in a btree header.
53496 */
53497 #if SQLITE_BYTEORDER==4321
53498 # define get2byteAligned(x) (*(u16*)(x))
53499 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
 
53500 # define get2byteAligned(x) __builtin_bswap16(*(u16*)(x))
53501 #elif SQLITE_BYTEORDER==1234 && defined(_MSC_VER) && _MSC_VER>=1300
 
53502 # define get2byteAligned(x) _byteswap_ushort(*(u16*)(x))
53503 #else
53504 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
53505 #endif
53506
@@ -62492,21 +62588,19 @@
62492 IntegrityCk *pCheck,
62493 const char *zFormat,
62494 ...
62495 ){
62496 va_list ap;
62497 char zBuf[200];
62498 if( !pCheck->mxErr ) return;
62499 pCheck->mxErr--;
62500 pCheck->nErr++;
62501 va_start(ap, zFormat);
62502 if( pCheck->errMsg.nChar ){
62503 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
62504 }
62505 if( pCheck->zPfx ){
62506 sqlite3_snprintf(sizeof(zBuf), zBuf, pCheck->zPfx, pCheck->v1, pCheck->v2);
62507 sqlite3StrAccumAppendAll(&pCheck->errMsg, zBuf);
62508 }
62509 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
62510 va_end(ap);
62511 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
62512 pCheck->mallocFailed = 1;
@@ -65327,11 +65421,11 @@
65327 /*
65328 ** The expression object indicated by the second argument is guaranteed
65329 ** to be a scalar SQL function. If
65330 **
65331 ** * all function arguments are SQL literals,
65332 ** * the SQLITE_FUNC_CONSTANT function flag is set, and
65333 ** * the SQLITE_FUNC_NEEDCOLL function flag is not set,
65334 **
65335 ** then this routine attempts to invoke the SQL function. Assuming no
65336 ** error occurs, output parameter (*ppVal) is set to point to a value
65337 ** object containing the result before returning SQLITE_OK.
@@ -65368,11 +65462,11 @@
65368 pList = p->x.pList;
65369 if( pList ) nVal = pList->nExpr;
65370 nName = sqlite3Strlen30(p->u.zToken);
65371 pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
65372 assert( pFunc );
65373 if( (pFunc->funcFlags & SQLITE_FUNC_CONSTANT)==0
65374 || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
65375 ){
65376 return SQLITE_OK;
65377 }
65378
@@ -65962,11 +66056,11 @@
65962 /*
65963 ** Return the SQL associated with a prepared statement
65964 */
65965 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt){
65966 Vdbe *p = (Vdbe *)pStmt;
65967 return (p && p->isPrepareV2) ? p->zSql : 0;
65968 }
65969
65970 /*
65971 ** Swap all content between two VDBE structures.
65972 */
@@ -66109,10 +66203,48 @@
66109 }
66110 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe *p, int op, int p1, int p2){
66111 return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
66112 }
66113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66114
66115 /*
66116 ** Add an opcode that includes the p4 value as a pointer.
66117 */
66118 SQLITE_PRIVATE int sqlite3VdbeAddOp4(
@@ -66128,11 +66260,12 @@
66128 sqlite3VdbeChangeP4(p, addr, zP4, p4type);
66129 return addr;
66130 }
66131
66132 /*
66133 ** Add an opcode that includes the p4 value with a P4_INT64 type.
 
66134 */
66135 SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(
66136 Vdbe *p, /* Add the opcode to this VM */
66137 int op, /* The new opcode */
66138 int p1, /* The P1 operand */
@@ -66213,11 +66346,12 @@
66213 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
66214 Parse *p = v->pParse;
66215 int j = -1-x;
66216 assert( v->magic==VDBE_MAGIC_INIT );
66217 assert( j<p->nLabel );
66218 if( ALWAYS(j>=0) && p->aLabel ){
 
66219 p->aLabel[j] = v->nOp;
66220 }
66221 p->iFixedOp = v->nOp - 1;
66222 }
66223
@@ -66357,21 +66491,25 @@
66357 || (hasCreateTable && hasInitCoroutine) );
66358 }
66359 #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
66360
66361 /*
66362 ** Loop through the program looking for P2 values that are negative
66363 ** on jump instructions. Each such value is a label. Resolve the
66364 ** label by setting the P2 value to its correct non-zero value.
66365 **
66366 ** This routine is called once after all opcodes have been inserted.
66367 **
66368 ** Variable *pMaxFuncArgs is set to the maximum value of any P2 argument
66369 ** to an OP_Function, OP_AggStep or OP_VFilter opcode. This is used by
66370 ** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array.
66371 **
66372 ** The Op.opflags field is set on all opcodes.
 
 
 
 
66373 */
66374 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
66375 int i;
66376 int nMaxArgs = *pMaxFuncArgs;
66377 Op *pOp;
@@ -66480,50 +66618,48 @@
66480 /*
66481 ** Add a whole list of operations to the operation stack. Return the
66482 ** address of the first operation added.
66483 */
66484 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
66485 int addr;
 
 
66486 assert( p->magic==VDBE_MAGIC_INIT );
66487 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
66488 return 0;
66489 }
66490 addr = p->nOp;
66491 if( ALWAYS(nOp>0) ){
66492 int i;
66493 VdbeOpList const *pIn = aOp;
66494 for(i=0; i<nOp; i++, pIn++){
66495 int p2 = pIn->p2;
66496 VdbeOp *pOut = &p->aOp[i+addr];
66497 pOut->opcode = pIn->opcode;
66498 pOut->p1 = pIn->p1;
66499 if( p2<0 ){
66500 assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
66501 pOut->p2 = addr + ADDR(p2);
66502 }else{
66503 pOut->p2 = p2;
66504 }
66505 pOut->p3 = pIn->p3;
66506 pOut->p4type = P4_NOTUSED;
66507 pOut->p4.p = 0;
66508 pOut->p5 = 0;
66509 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
66510 pOut->zComment = 0;
66511 #endif
66512 #ifdef SQLITE_VDBE_COVERAGE
66513 pOut->iSrcLine = iLineno+i;
66514 #else
66515 (void)iLineno;
66516 #endif
66517 #ifdef SQLITE_DEBUG
66518 if( p->db->flags & SQLITE_VdbeAddopTrace ){
66519 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
66520 }
66521 #endif
66522 }
66523 p->nOp += nOp;
66524 }
 
66525 return addr;
66526 }
66527
66528 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
66529 /*
@@ -66552,62 +66688,36 @@
66552 }
66553 #endif
66554
66555
66556 /*
66557 ** Change the value of the P1 operand for a specific instruction.
66558 ** This routine is useful when a large program is loaded from a
66559 ** static array using sqlite3VdbeAddOpList but we want to make a
66560 ** few minor changes to the program.
66561 */
 
 
 
66562 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){
66563 assert( p!=0 );
66564 if( ((u32)p->nOp)>addr ){
66565 p->aOp[addr].p1 = val;
66566 }
66567 }
66568
66569 /*
66570 ** Change the value of the P2 operand for a specific instruction.
66571 ** This routine is useful for setting a jump destination.
66572 */
66573 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, u32 addr, int val){
66574 assert( p!=0 );
66575 if( ((u32)p->nOp)>addr ){
66576 p->aOp[addr].p2 = val;
66577 }
66578 }
66579
66580 /*
66581 ** Change the value of the P3 operand for a specific instruction.
66582 */
66583 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
66584 assert( p!=0 );
66585 if( ((u32)p->nOp)>addr ){
66586 p->aOp[addr].p3 = val;
66587 }
66588 }
66589
66590 /*
66591 ** Change the value of the P5 operand for the most recently
66592 ** added operation.
66593 */
66594 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 val){
66595 assert( p!=0 );
66596 if( p->aOp ){
66597 assert( p->nOp>0 );
66598 p->aOp[p->nOp-1].p5 = val;
66599 }
66600 }
66601
66602 /*
66603 ** Change the P2 operand of instruction addr so that it points to
66604 ** the address of the next instruction to be coded.
66605 */
66606 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
66607 sqlite3VdbeChangeP2(p, addr, p->nOp);
66608 p->pParse->iFixedOp = p->nOp - 1;
 
66609 }
66610
66611
66612 /*
66613 ** If the input FuncDef structure is ephemeral, then free it. If
@@ -66988,12 +67098,13 @@
66988 int n = sqlite3Strlen30(zColl);
66989 if( n==6 && memcmp(zColl,"BINARY",6)==0 ){
66990 zColl = "B";
66991 n = 1;
66992 }
66993 if( i+n>nTemp-6 ){
66994 memcpy(&zTemp[i],",...",4);
 
66995 break;
66996 }
66997 zTemp[i++] = ',';
66998 if( pKeyInfo->aSortOrder[j] ){
66999 zTemp[i++] = '-';
@@ -70329,10 +70440,13 @@
70329 SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value *pVal){
70330 return (int)sqlite3VdbeIntValue((Mem*)pVal);
70331 }
70332 SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value *pVal){
70333 return sqlite3VdbeIntValue((Mem*)pVal);
 
 
 
70334 }
70335 SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value *pVal){
70336 return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
70337 }
70338 #ifndef SQLITE_OMIT_UTF16
@@ -70507,10 +70621,14 @@
70507 sqlite3VdbeMemSetInt64(pCtx->pOut, iVal);
70508 }
70509 SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context *pCtx){
70510 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
70511 sqlite3VdbeMemSetNull(pCtx->pOut);
 
 
 
 
70512 }
70513 SQLITE_API void SQLITE_STDCALL sqlite3_result_text(
70514 sqlite3_context *pCtx,
70515 const char *z,
70516 int n,
@@ -70754,11 +70872,11 @@
70754 ** be one of the values in the first assert() below. Variable p->rc
70755 ** contains the value that would be returned if sqlite3_finalize()
70756 ** were called on statement p.
70757 */
70758 assert( rc==SQLITE_ROW || rc==SQLITE_DONE || rc==SQLITE_ERROR
70759 || rc==SQLITE_BUSY || rc==SQLITE_MISUSE
70760 );
70761 assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp );
70762 if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
70763 /* If this statement was prepared using sqlite3_prepare_v2(), and an
70764 ** error has occurred, then return the error code in p->rc to the
@@ -70839,11 +70957,11 @@
70839 ** parameter) of the sqlite3_create_function() and
70840 ** sqlite3_create_function16() routines that originally registered the
70841 ** application defined function.
70842 */
70843 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context *p){
70844 assert( p && p->pFunc );
70845 return p->pOut->db;
70846 }
70847
70848 /*
70849 ** Return the current time for a statement. If the current time
@@ -72657,11 +72775,11 @@
72657 if( p->rc==SQLITE_NOMEM ){
72658 /* This happens if a malloc() inside a call to sqlite3_column_text() or
72659 ** sqlite3_column_text16() failed. */
72660 goto no_mem;
72661 }
72662 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
72663 assert( p->bIsReader || p->readOnly!=0 );
72664 p->rc = SQLITE_OK;
72665 p->iCurrentTime = 0;
72666 assert( p->explain==0 );
72667 p->pResultSet = 0;
@@ -75094,16 +75212,16 @@
75094 db->autoCommit = 1;
75095 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
75096 goto vdbe_return;
75097 }else{
75098 db->autoCommit = (u8)desiredAutoCommit;
75099 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
75100 p->pc = (int)(pOp - aOp);
75101 db->autoCommit = (u8)(1-desiredAutoCommit);
75102 p->rc = rc = SQLITE_BUSY;
75103 goto vdbe_return;
75104 }
75105 }
75106 assert( db->nStatement==0 );
75107 sqlite3CloseSavepoints(db);
75108 if( p->rc==SQLITE_OK ){
75109 rc = SQLITE_DONE;
@@ -75171,13 +75289,15 @@
75171 }
75172 pBt = db->aDb[pOp->p1].pBt;
75173
75174 if( pBt ){
75175 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
75176 if( rc==SQLITE_BUSY ){
 
 
75177 p->pc = (int)(pOp - aOp);
75178 p->rc = rc = SQLITE_BUSY;
75179 goto vdbe_return;
75180 }
75181 if( rc!=SQLITE_OK ){
75182 goto abort_due_to_error;
75183 }
@@ -79009,11 +79129,12 @@
79009 }
79010 #endif
79011 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
79012 int j;
79013 for(j=0; j<pIdx->nKeyCol; j++){
79014 if( pIdx->aiColumn[j]==iCol ){
 
79015 zFault = "indexed";
79016 }
79017 }
79018 }
79019 if( zFault ){
@@ -82590,10 +82711,15 @@
82590 if( ALWAYS(pSrc) ){
82591 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
82592 if( sqlite3WalkSelect(pWalker, pItem->pSelect) ){
82593 return WRC_Abort;
82594 }
 
 
 
 
 
82595 }
82596 }
82597 return WRC_Continue;
82598 }
82599
@@ -82687,34 +82813,10 @@
82687
82688 /*
82689 ** Turn the pExpr expression into an alias for the iCol-th column of the
82690 ** result set in pEList.
82691 **
82692 ** If the result set column is a simple column reference, then this routine
82693 ** makes an exact copy. But for any other kind of expression, this
82694 ** routine make a copy of the result set column as the argument to the
82695 ** TK_AS operator. The TK_AS operator causes the expression to be
82696 ** evaluated just once and then reused for each alias.
82697 **
82698 ** The reason for suppressing the TK_AS term when the expression is a simple
82699 ** column reference is so that the column reference will be recognized as
82700 ** usable by indices within the WHERE clause processing logic.
82701 **
82702 ** The TK_AS operator is inhibited if zType[0]=='G'. This means
82703 ** that in a GROUP BY clause, the expression is evaluated twice. Hence:
82704 **
82705 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY x
82706 **
82707 ** Is equivalent to:
82708 **
82709 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
82710 **
82711 ** The result of random()%5 in the GROUP BY clause is probably different
82712 ** from the result in the result-set. On the other hand Standard SQL does
82713 ** not allow the GROUP BY clause to contain references to result-set columns.
82714 ** So this should never come up in well-formed queries.
82715 **
82716 ** If the reference is followed by a COLLATE operator, then make sure
82717 ** the COLLATE operator is preserved. For example:
82718 **
82719 ** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
82720 **
@@ -82744,23 +82846,15 @@
82744 pOrig = pEList->a[iCol].pExpr;
82745 assert( pOrig!=0 );
82746 db = pParse->db;
82747 pDup = sqlite3ExprDup(db, pOrig, 0);
82748 if( pDup==0 ) return;
82749 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
82750 incrAggFunctionDepth(pDup, nSubquery);
82751 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
82752 if( pDup==0 ) return;
82753 ExprSetProperty(pDup, EP_Skip);
82754 if( pEList->a[iCol].u.x.iAlias==0 ){
82755 pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
82756 }
82757 pDup->iTable = pEList->a[iCol].u.x.iAlias;
82758 }
82759 if( pExpr->op==TK_COLLATE ){
82760 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
82761 }
 
82762
82763 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
82764 ** prevents ExprDelete() from deleting the Expr structure itself,
82765 ** allowing it to be repopulated by the memcpy() on the following line.
82766 ** The pExpr->u.zToken might point into memory that will be freed by the
@@ -82948,11 +83042,11 @@
82948 /* If there has been exactly one prior match and this match
82949 ** is for the right-hand table of a NATURAL JOIN or is in a
82950 ** USING clause, then skip this match.
82951 */
82952 if( cnt==1 ){
82953 if( pItem->jointype & JT_NATURAL ) continue;
82954 if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
82955 }
82956 cnt++;
82957 pMatch = pItem;
82958 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
@@ -82963,12 +83057,12 @@
82963 }
82964 if( pMatch ){
82965 pExpr->iTable = pMatch->iCursor;
82966 pExpr->pTab = pMatch->pTab;
82967 /* RIGHT JOIN not (yet) supported */
82968 assert( (pMatch->jointype & JT_RIGHT)==0 );
82969 if( (pMatch->jointype & JT_LEFT)!=0 ){
82970 ExprSetProperty(pExpr, EP_CanBeNull);
82971 }
82972 pSchema = pExpr->pTab->pSchema;
82973 }
82974 } /* if( pSrcList ) */
@@ -83049,13 +83143,13 @@
83049 ** forms the result set entry ("a+b" in the example) and return immediately.
83050 ** Note that the expression in the result set should have already been
83051 ** resolved by the time the WHERE clause is resolved.
83052 **
83053 ** The ability to use an output result-set column in the WHERE, GROUP BY,
83054 ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
83055 ** clause is not standard SQL. This is a (goofy) SQLite extension, that
83056 ** is supported for backwards compatibility only. TO DO: Issue a warning
83057 ** on sqlite3_log() whenever the capability is used.
83058 */
83059 if( (pEList = pNC->pEList)!=0
83060 && zTab==0
83061 && cnt==0
@@ -83148,11 +83242,11 @@
83148 pExpr->pRight = 0;
83149 pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
83150 lookupname_end:
83151 if( cnt==1 ){
83152 assert( pNC!=0 );
83153 if( pExpr->op!=TK_AS ){
83154 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
83155 }
83156 /* Increment the nRef value on all name contexts from TopNC up to
83157 ** the point where the name matched. */
83158 for(;;){
@@ -83189,40 +83283,29 @@
83189 }
83190 return p;
83191 }
83192
83193 /*
83194 ** Report an error that an expression is not valid for a partial index WHERE
83195 ** clause.
83196 */
83197 static void notValidPartIdxWhere(
83198 Parse *pParse, /* Leave error message here */
83199 NameContext *pNC, /* The name context */
83200 const char *zMsg /* Type of error */
83201 ){
83202 if( (pNC->ncFlags & NC_PartIdx)!=0 ){
83203 sqlite3ErrorMsg(pParse, "%s prohibited in partial index WHERE clauses",
83204 zMsg);
83205 }
83206 }
83207
83208 #ifndef SQLITE_OMIT_CHECK
83209 /*
83210 ** Report an error that an expression is not valid for a CHECK constraint.
83211 */
83212 static void notValidCheckConstraint(
83213 Parse *pParse, /* Leave error message here */
83214 NameContext *pNC, /* The name context */
83215 const char *zMsg /* Type of error */
83216 ){
83217 if( (pNC->ncFlags & NC_IsCheck)!=0 ){
83218 sqlite3ErrorMsg(pParse,"%s prohibited in CHECK constraints", zMsg);
83219 }
83220 }
83221 #else
83222 # define notValidCheckConstraint(P,N,M)
83223 #endif
83224
83225 /*
83226 ** Expression p should encode a floating point value between 1.0 and 0.0.
83227 ** Return 1024 times this value. Or return -1 if p is not a floating point
83228 ** value between 1.0 and 0.0.
@@ -83303,10 +83386,12 @@
83303 const char *zTable;
83304 const char *zDb;
83305 Expr *pRight;
83306
83307 /* if( pSrcList==0 ) break; */
 
 
83308 pRight = pExpr->pRight;
83309 if( pRight->op==TK_ID ){
83310 zDb = 0;
83311 zTable = pExpr->pLeft->u.zToken;
83312 zColumn = pRight->u.zToken;
@@ -83332,11 +83417,11 @@
83332 const char *zId; /* The function name. */
83333 FuncDef *pDef; /* Information about the function */
83334 u8 enc = ENC(pParse->db); /* The database encoding */
83335
83336 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
83337 notValidPartIdxWhere(pParse, pNC, "functions");
83338 zId = pExpr->u.zToken;
83339 nId = sqlite3Strlen30(zId);
83340 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
83341 if( pDef==0 ){
83342 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
@@ -83380,13 +83465,22 @@
83380 }
83381 pExpr->op = TK_NULL;
83382 return WRC_Prune;
83383 }
83384 #endif
83385 if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ){
 
 
 
83386 ExprSetProperty(pExpr,EP_ConstFunc);
83387 }
 
 
 
 
 
 
83388 }
83389 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
83390 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
83391 pNC->nErr++;
83392 is_agg = 0;
@@ -83428,23 +83522,21 @@
83428 #endif
83429 case TK_IN: {
83430 testcase( pExpr->op==TK_IN );
83431 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
83432 int nRef = pNC->nRef;
83433 notValidCheckConstraint(pParse, pNC, "subqueries");
83434 notValidPartIdxWhere(pParse, pNC, "subqueries");
83435 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
83436 assert( pNC->nRef>=nRef );
83437 if( nRef!=pNC->nRef ){
83438 ExprSetProperty(pExpr, EP_VarSelect);
83439 }
83440 }
83441 break;
83442 }
83443 case TK_VARIABLE: {
83444 notValidCheckConstraint(pParse, pNC, "parameters");
83445 notValidPartIdxWhere(pParse, pNC, "parameters");
83446 break;
83447 }
83448 }
83449 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
83450 }
@@ -83784,11 +83876,10 @@
83784 NameContext *pOuterNC; /* Context that contains this SELECT */
83785 NameContext sNC; /* Name context of this SELECT */
83786 int isCompound; /* True if p is a compound select */
83787 int nCompound; /* Number of compound terms processed so far */
83788 Parse *pParse; /* Parsing context */
83789 ExprList *pEList; /* Result set expression list */
83790 int i; /* Loop counter */
83791 ExprList *pGroupBy; /* The GROUP BY clause */
83792 Select *pLeftmost; /* Left-most of SELECT of a compound */
83793 sqlite3 *db; /* Database connection */
83794
@@ -83857,21 +83948,21 @@
83857
83858 /* Count the total number of references to pOuterNC and all of its
83859 ** parent contexts. After resolving references to expressions in
83860 ** pItem->pSelect, check if this value has changed. If so, then
83861 ** SELECT statement pItem->pSelect must be correlated. Set the
83862 ** pItem->isCorrelated flag if this is the case. */
83863 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef;
83864
83865 if( pItem->zName ) pParse->zAuthContext = pItem->zName;
83866 sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
83867 pParse->zAuthContext = zSavedContext;
83868 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
83869
83870 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef;
83871 assert( pItem->isCorrelated==0 && nRef<=0 );
83872 pItem->isCorrelated = (nRef!=0);
83873 }
83874 }
83875
83876 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
83877 ** resolve the result-set expression list.
@@ -83879,18 +83970,11 @@
83879 sNC.ncFlags = NC_AllowAgg;
83880 sNC.pSrcList = p->pSrc;
83881 sNC.pNext = pOuterNC;
83882
83883 /* Resolve names in the result set. */
83884 pEList = p->pEList;
83885 assert( pEList!=0 );
83886 for(i=0; i<pEList->nExpr; i++){
83887 Expr *pX = pEList->a[i].pExpr;
83888 if( sqlite3ResolveExprNames(&sNC, pX) ){
83889 return WRC_Abort;
83890 }
83891 }
83892
83893 /* If there are no aggregate functions in the result-set, and no GROUP BY
83894 ** expression, do not allow aggregates in any of the other expressions.
83895 */
83896 assert( (p->selFlags & SF_Aggregate)==0 );
@@ -83918,10 +84002,20 @@
83918 ** re-evaluated for each reference to it.
83919 */
83920 sNC.pEList = p->pEList;
83921 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
83922 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
 
 
 
 
 
 
 
 
 
 
83923
83924 /* The ORDER BY and GROUP BY clauses may not refer to terms in
83925 ** outer queries
83926 */
83927 sNC.pNext = 0;
@@ -84082,10 +84176,26 @@
84082 }
84083 pNC->ncFlags |= savedHasAgg;
84084 return ExprHasProperty(pExpr, EP_Error);
84085 }
84086
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84087
84088 /*
84089 ** Resolve all names in all expressions of a SELECT and in all
84090 ** decendents of the SELECT, including compounds off of p->pPrior,
84091 ** subqueries in expressions, and subqueries used as FROM clause
@@ -84125,19 +84235,18 @@
84125 ** Any errors cause an error message to be set in pParse.
84126 */
84127 SQLITE_PRIVATE void sqlite3ResolveSelfReference(
84128 Parse *pParse, /* Parsing context */
84129 Table *pTab, /* The table being referenced */
84130 int type, /* NC_IsCheck or NC_PartIdx */
84131 Expr *pExpr, /* Expression to resolve. May be NULL. */
84132 ExprList *pList /* Expression list to resolve. May be NUL. */
84133 ){
84134 SrcList sSrc; /* Fake SrcList for pParse->pNewTable */
84135 NameContext sNC; /* Name context for pParse->pNewTable */
84136 int i; /* Loop counter */
84137
84138 assert( type==NC_IsCheck || type==NC_PartIdx );
84139 memset(&sNC, 0, sizeof(sNC));
84140 memset(&sSrc, 0, sizeof(sSrc));
84141 sSrc.nSrc = 1;
84142 sSrc.a[0].zName = pTab->zName;
84143 sSrc.a[0].pTab = pTab;
@@ -84144,17 +84253,11 @@
84144 sSrc.a[0].iCursor = -1;
84145 sNC.pParse = pParse;
84146 sNC.pSrcList = &sSrc;
84147 sNC.ncFlags = type;
84148 if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
84149 if( pList ){
84150 for(i=0; i<pList->nExpr; i++){
84151 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
84152 return;
84153 }
84154 }
84155 }
84156 }
84157
84158 /************** End of resolve.c *********************************************/
84159 /************** Begin file expr.c ********************************************/
84160 /*
@@ -84248,11 +84351,11 @@
84248 s.n = sqlite3Strlen30(s.z);
84249 return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
84250 }
84251
84252 /*
84253 ** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
84254 ** or likelihood() function at the root of an expression.
84255 */
84256 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
84257 while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
84258 if( ExprHasProperty(pExpr, EP_Unlikely) ){
@@ -84259,11 +84362,11 @@
84259 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
84260 assert( pExpr->x.pList->nExpr>0 );
84261 assert( pExpr->op==TK_FUNCTION );
84262 pExpr = pExpr->x.pList->a[0].pExpr;
84263 }else{
84264 assert( pExpr->op==TK_COLLATE || pExpr->op==TK_AS );
84265 pExpr = pExpr->pLeft;
84266 }
84267 }
84268 return pExpr;
84269 }
@@ -84590,11 +84693,11 @@
84590 ** for this node and for the pToken argument is a single allocation
84591 ** obtained from sqlite3DbMalloc(). The calling function
84592 ** is responsible for making sure the node eventually gets freed.
84593 **
84594 ** If dequote is true, then the token (if it exists) is dequoted.
84595 ** If dequote is false, no dequoting is performance. The deQuote
84596 ** parameter is ignored if pToken is NULL or if the token does not
84597 ** appear to be quoted. If the quotes were of the form "..." (double-quotes)
84598 ** then the EP_DblQuoted flag is set on the expression node.
84599 **
84600 ** Special case: If op==TK_INTEGER and pToken points to a string that
@@ -85191,20 +85294,22 @@
85191 Table *pTab;
85192 pNewItem->pSchema = pOldItem->pSchema;
85193 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
85194 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
85195 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
85196 pNewItem->jointype = pOldItem->jointype;
85197 pNewItem->iCursor = pOldItem->iCursor;
85198 pNewItem->addrFillSub = pOldItem->addrFillSub;
85199 pNewItem->regReturn = pOldItem->regReturn;
85200 pNewItem->isCorrelated = pOldItem->isCorrelated;
85201 pNewItem->viaCoroutine = pOldItem->viaCoroutine;
85202 pNewItem->isRecursive = pOldItem->isRecursive;
85203 pNewItem->zIndexedBy = sqlite3DbStrDup(db, pOldItem->zIndexedBy);
85204 pNewItem->notIndexed = pOldItem->notIndexed;
85205 pNewItem->pIndex = pOldItem->pIndex;
 
 
85206 pTab = pNewItem->pTab = pOldItem->pTab;
85207 if( pTab ){
85208 pTab->nRef++;
85209 }
85210 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
@@ -85314,10 +85419,24 @@
85314 /* Avoid leaking memory if malloc has failed. */
85315 sqlite3ExprDelete(db, pExpr);
85316 sqlite3ExprListDelete(db, pList);
85317 return 0;
85318 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85319
85320 /*
85321 ** Set the ExprList.a[].zName element of the most recently added item
85322 ** on the expression list.
85323 **
@@ -86286,11 +86405,11 @@
86286 }
86287 sqlite3ReleaseTempReg(pParse, regToFree);
86288 }
86289 if( regCkNull ){
86290 sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
86291 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
86292 }
86293 sqlite3VdbeResolveLabel(v, labelOk);
86294 sqlite3ReleaseTempReg(pParse, regCkNull);
86295 }else{
86296
@@ -86304,11 +86423,11 @@
86304 sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
86305 }else{
86306 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
86307 sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
86308 VdbeCoverage(v);
86309 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
86310 sqlite3VdbeJumpHere(v, addr1);
86311 }
86312 }
86313
86314 if( eType==IN_INDEX_ROWID ){
@@ -86354,11 +86473,11 @@
86354 */
86355 j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
86356 VdbeCoverage(v);
86357 sqlite3VdbeAddOp2(v, OP_IsNull, rRhsHasNull, destIfNull);
86358 VdbeCoverage(v);
86359 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
86360 sqlite3VdbeJumpHere(v, j1);
86361 }
86362 }
86363 }
86364 sqlite3ReleaseTempReg(pParse, r1);
@@ -86572,10 +86691,32 @@
86572 if( p->iReg==iReg ){
86573 p->tempReg = 0;
86574 }
86575 }
86576 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86577
86578 /*
86579 ** Generate code to extract the value of the iCol-th column of a table.
86580 */
86581 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
@@ -86758,12 +86899,13 @@
86758 if( pParse->ckBase>0 ){
86759 /* Generating CHECK constraints or inserting into partial index */
86760 inReg = pExpr->iColumn + pParse->ckBase;
86761 break;
86762 }else{
86763 /* Deleting from a partial index */
86764 iTab = pParse->iPartIdxTab;
 
86765 }
86766 }
86767 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
86768 pExpr->iColumn, iTab, target,
86769 pExpr->op2);
@@ -86780,11 +86922,11 @@
86780 break;
86781 }
86782 #endif
86783 case TK_STRING: {
86784 assert( !ExprHasProperty(pExpr, EP_IntValue) );
86785 sqlite3VdbeAddOp4(v, OP_String8, 0, target, 0, pExpr->u.zToken, 0);
86786 break;
86787 }
86788 case TK_NULL: {
86789 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
86790 break;
@@ -86819,14 +86961,10 @@
86819 }
86820 case TK_REGISTER: {
86821 inReg = pExpr->iTable;
86822 break;
86823 }
86824 case TK_AS: {
86825 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
86826 break;
86827 }
86828 #ifndef SQLITE_OMIT_CAST
86829 case TK_CAST: {
86830 /* Expressions of the form: CAST(pLeft AS token) */
86831 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
86832 if( inReg!=target ){
@@ -87053,11 +87191,11 @@
87053 pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
87054 }
87055 }
87056
87057 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
87058 sqlite3ExprCodeExprList(pParse, pFarg, r1,
87059 SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
87060 sqlite3ExprCachePop(pParse); /* Ticket 2ea2425d34be */
87061 }else{
87062 r1 = 0;
87063 }
@@ -87277,11 +87415,11 @@
87277 nextCase = sqlite3VdbeMakeLabel(v);
87278 testcase( pTest->op==TK_COLUMN );
87279 sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
87280 testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
87281 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
87282 sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
87283 sqlite3ExprCachePop(pParse);
87284 sqlite3VdbeResolveLabel(v, nextCase);
87285 }
87286 if( (nExpr&1)!=0 ){
87287 sqlite3ExprCachePush(pParse);
@@ -87469,29 +87607,32 @@
87469 */
87470 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
87471 Parse *pParse, /* Parsing context */
87472 ExprList *pList, /* The expression list to be coded */
87473 int target, /* Where to write results */
 
87474 u8 flags /* SQLITE_ECEL_* flags */
87475 ){
87476 struct ExprList_item *pItem;
87477 int i, n;
87478 u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
 
87479 assert( pList!=0 );
87480 assert( target>0 );
87481 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
87482 n = pList->nExpr;
87483 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
87484 for(pItem=pList->a, i=0; i<n; i++, pItem++){
87485 Expr *pExpr = pItem->pExpr;
87486 if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
 
 
87487 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
87488 }else{
87489 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
87490 if( inReg!=target+i ){
87491 VdbeOp *pOp;
87492 Vdbe *v = pParse->pVdbe;
87493 if( copyOp==OP_Copy
87494 && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
87495 && pOp->p1+pOp->p3+1==inReg
87496 && pOp->p2+pOp->p3+1==target+i
87497 ){
@@ -87664,18 +87805,18 @@
87664 #ifndef SQLITE_OMIT_SUBQUERY
87665 case TK_IN: {
87666 int destIfFalse = sqlite3VdbeMakeLabel(v);
87667 int destIfNull = jumpIfNull ? dest : destIfFalse;
87668 sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
87669 sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
87670 sqlite3VdbeResolveLabel(v, destIfFalse);
87671 break;
87672 }
87673 #endif
87674 default: {
87675 if( exprAlwaysTrue(pExpr) ){
87676 sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
87677 }else if( exprAlwaysFalse(pExpr) ){
87678 /* No-op */
87679 }else{
87680 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
87681 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
@@ -87827,11 +87968,11 @@
87827 break;
87828 }
87829 #endif
87830 default: {
87831 if( exprAlwaysFalse(pExpr) ){
87832 sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
87833 }else if( exprAlwaysTrue(pExpr) ){
87834 /* no-op */
87835 }else{
87836 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
87837 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
@@ -87903,11 +88044,13 @@
87903 return 1;
87904 }
87905 return 2;
87906 }
87907 if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
87908 if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
 
 
87909 return pA->op==TK_COLLATE ? 1 : 2;
87910 }
87911 }
87912 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
87913 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
@@ -88811,11 +88954,11 @@
88811 ** SQLite tables) that are identified by the name of the virtual table.
88812 */
88813 #ifndef SQLITE_OMIT_VIRTUALTABLE
88814 if( pVTab ){
88815 int i = ++pParse->nMem;
88816 sqlite3VdbeAddOp4(v, OP_String8, 0, i, 0, zName, 0);
88817 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
88818 sqlite3MayAbort(pParse);
88819 }
88820 #endif
88821
@@ -90169,11 +90312,11 @@
90169 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
90170 iTabCur = iTab++;
90171 iIdxCur = iTab++;
90172 pParse->nTab = MAX(pParse->nTab, iTab);
90173 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
90174 sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
90175
90176 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
90177 int nCol; /* Number of columns in pIdx. "N" */
90178 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
90179 int addrNextRow; /* Address of "next_row:" */
@@ -90191,11 +90334,11 @@
90191 zIdxName = pIdx->zName;
90192 nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
90193 }
90194
90195 /* Populate the register containing the index name. */
90196 sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
90197 VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
90198
90199 /*
90200 ** Pseudo-code for loop that calls stat_push():
90201 **
@@ -90305,11 +90448,11 @@
90305 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
90306 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
90307 VdbeCoverage(v);
90308 }
90309 sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
90310 sqlite3VdbeAddOp2(v, OP_Goto, 0, endDistinctTest);
90311
90312
90313 /*
90314 ** chng_addr_0:
90315 ** regPrev(0) = idx(0)
@@ -90341,10 +90484,11 @@
90341 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
90342 int j, k, regKey;
90343 regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
90344 for(j=0; j<pPk->nKeyCol; j++){
90345 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
 
90346 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
90347 VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
90348 }
90349 sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
90350 sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
@@ -90390,16 +90534,14 @@
90390 /* We know that the regSampleRowid row exists because it was read by
90391 ** the previous loop. Thus the not-found jump of seekOp will never
90392 ** be taken */
90393 VdbeCoverageNeverTaken(v);
90394 #ifdef SQLITE_ENABLE_STAT3
90395 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
90396 pIdx->aiColumn[0], regSample);
90397 #else
90398 for(i=0; i<nCol; i++){
90399 i16 iCol = pIdx->aiColumn[i];
90400 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
90401 }
90402 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol, regSample);
90403 #endif
90404 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
90405 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
@@ -92121,11 +92263,11 @@
92121 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
92122 }
92123 }
92124
92125 /* Finally, jump back to the beginning of the executable code. */
92126 sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
92127 }
92128 }
92129
92130
92131 /* Get the VDBE program ready for execution
@@ -92256,10 +92398,21 @@
92256 }
92257
92258 p = sqlite3FindTable(pParse->db, zName, zDbase);
92259 if( p==0 ){
92260 const char *zMsg = isView ? "no such view" : "no such table";
 
 
 
 
 
 
 
 
 
 
 
92261 if( zDbase ){
92262 sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
92263 }else{
92264 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
92265 }
@@ -92334,10 +92487,11 @@
92334 static void freeIndex(sqlite3 *db, Index *p){
92335 #ifndef SQLITE_OMIT_ANALYZE
92336 sqlite3DeleteIndexSamples(db, p);
92337 #endif
92338 sqlite3ExprDelete(db, p->pPartIdxWhere);
 
92339 sqlite3DbFree(db, p->zColAff);
92340 if( p->isResized ) sqlite3DbFree(db, p->azColl);
92341 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
92342 sqlite3_free(p->aiRowEst);
92343 #endif
@@ -92460,11 +92614,11 @@
92460
92461 /*
92462 ** Delete memory allocated for the column names of a table or view (the
92463 ** Table.aCol[] array).
92464 */
92465 static void sqliteDeleteColumnNames(sqlite3 *db, Table *pTable){
92466 int i;
92467 Column *pCol;
92468 assert( pTable!=0 );
92469 if( (pCol = pTable->aCol)!=0 ){
92470 for(i=0; i<pTable->nCol; i++, pCol++){
@@ -92527,17 +92681,15 @@
92527 /* Delete any foreign keys attached to this table. */
92528 sqlite3FkDelete(db, pTable);
92529
92530 /* Delete the Table structure itself.
92531 */
92532 sqliteDeleteColumnNames(db, pTable);
92533 sqlite3DbFree(db, pTable->zName);
92534 sqlite3DbFree(db, pTable->zColAff);
92535 sqlite3SelectDelete(db, pTable->pSelect);
92536 #ifndef SQLITE_OMIT_CHECK
92537 sqlite3ExprListDelete(db, pTable->pCheck);
92538 #endif
92539 #ifndef SQLITE_OMIT_VIRTUALTABLE
92540 sqlite3VtabClear(db, pTable);
92541 #endif
92542 sqlite3DbFree(db, pTable);
92543
@@ -92876,10 +93028,12 @@
92876 */
92877 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
92878 int j1;
92879 int fileFormat;
92880 int reg1, reg2, reg3;
 
 
92881 sqlite3BeginWriteOperation(pParse, 1, iDb);
92882
92883 #ifndef SQLITE_OMIT_VIRTUALTABLE
92884 if( isVirtual ){
92885 sqlite3VdbeAddOp0(v, OP_VBegin);
@@ -92920,11 +93074,11 @@
92920 {
92921 pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
92922 }
92923 sqlite3OpenMasterTable(pParse, iDb);
92924 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
92925 sqlite3VdbeAddOp2(v, OP_Null, 0, reg3);
92926 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
92927 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
92928 sqlite3VdbeAddOp0(v, OP_Close);
92929 }
92930
@@ -93201,22 +93355,27 @@
93201 zType = pTab->aCol[iCol].zType;
93202 nTerm = 1;
93203 }else{
93204 nTerm = pList->nExpr;
93205 for(i=0; i<nTerm; i++){
93206 for(iCol=0; iCol<pTab->nCol; iCol++){
93207 if( sqlite3StrICmp(pList->a[i].zName, pTab->aCol[iCol].zName)==0 ){
93208 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
93209 zType = pTab->aCol[iCol].zType;
93210 break;
 
 
 
 
 
93211 }
93212 }
93213 }
93214 }
93215 if( nTerm==1
93216 && zType && sqlite3StrICmp(zType, "INTEGER")==0
93217 && sortOrder==SQLITE_SO_ASC
93218 ){
93219 pTab->iPKey = iCol;
93220 pTab->keyConf = (u8)onError;
93221 assert( autoInc==0 || autoInc==1 );
93222 pTab->tabFlags |= autoInc*TF_Autoincrement;
@@ -93579,22 +93738,24 @@
93579 ** root-page for the table into an OP_CreateIndex opcode. The index
93580 ** created will become the PRIMARY KEY index.
93581 */
93582 if( pParse->addrCrTab ){
93583 assert( v );
93584 sqlite3VdbeGetOp(v, pParse->addrCrTab)->opcode = OP_CreateIndex;
93585 }
93586
93587 /* Locate the PRIMARY KEY index. Or, if this table was originally
93588 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
93589 */
93590 if( pTab->iPKey>=0 ){
93591 ExprList *pList;
93592 pList = sqlite3ExprListAppend(pParse, 0, 0);
 
 
 
 
93593 if( pList==0 ) return;
93594 pList->a[0].zName = sqlite3DbStrDup(pParse->db,
93595 pTab->aCol[pTab->iPKey].zName);
93596 pList->a[0].sortOrder = pParse->iPkSortOrder;
93597 assert( pParse->pNewTable==pTab );
93598 pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
93599 if( pPk==0 ) return;
93600 pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
@@ -93606,11 +93767,11 @@
93606 ** table entry. This is only required if currently generating VDBE
93607 ** code for a CREATE TABLE (not when parsing one as part of reading
93608 ** a database schema). */
93609 if( v ){
93610 assert( db->init.busy==0 );
93611 sqlite3VdbeGetOp(v, pPk->tnum)->opcode = OP_Goto;
93612 }
93613
93614 /*
93615 ** Remove all redundant columns from the PRIMARY KEY. For example, change
93616 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
@@ -93716,13 +93877,14 @@
93716 Table *p; /* The new table */
93717 sqlite3 *db = pParse->db; /* The database connection */
93718 int iDb; /* Database in which the table lives */
93719 Index *pIdx; /* An implied index of the table */
93720
93721 if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
93722 return;
93723 }
 
93724 p = pParse->pNewTable;
93725 if( p==0 ) return;
93726
93727 assert( !db->init.busy || !pSelect );
93728
@@ -93849,11 +94011,11 @@
93849 VdbeCoverage(v);
93850 sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
93851 sqlite3TableAffinity(v, p, 0);
93852 sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
93853 sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
93854 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop);
93855 sqlite3VdbeJumpHere(v, addrInsLoop);
93856 sqlite3VdbeAddOp1(v, OP_Close, 1);
93857 }
93858
93859 /* Compute the complete text of the CREATE statement */
@@ -93946,10 +94108,11 @@
93946 SQLITE_PRIVATE void sqlite3CreateView(
93947 Parse *pParse, /* The parsing context */
93948 Token *pBegin, /* The CREATE token that begins the statement */
93949 Token *pName1, /* The token that holds the name of the view */
93950 Token *pName2, /* The token that holds the name of the view */
 
93951 Select *pSelect, /* A SELECT statement that will become the new view */
93952 int isTemp, /* TRUE for a TEMPORARY view */
93953 int noErr /* Suppress error messages if VIEW already exists */
93954 ){
93955 Table *p;
@@ -93966,52 +94129,47 @@
93966 sqlite3SelectDelete(db, pSelect);
93967 return;
93968 }
93969 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
93970 p = pParse->pNewTable;
93971 if( p==0 || pParse->nErr ){
93972 sqlite3SelectDelete(db, pSelect);
93973 return;
93974 }
93975 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
93976 iDb = sqlite3SchemaToIndex(db, p->pSchema);
93977 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
93978 if( sqlite3FixSelect(&sFix, pSelect) ){
93979 sqlite3SelectDelete(db, pSelect);
93980 return;
93981 }
93982
93983 /* Make a copy of the entire SELECT statement that defines the view.
93984 ** This will force all the Expr.token.z values to be dynamically
93985 ** allocated rather than point to the input string - which means that
93986 ** they will persist after the current sqlite3_exec() call returns.
93987 */
93988 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
93989 sqlite3SelectDelete(db, pSelect);
93990 if( db->mallocFailed ){
93991 return;
93992 }
93993 if( !db->init.busy ){
93994 sqlite3ViewGetColumnNames(pParse, p);
93995 }
93996
93997 /* Locate the end of the CREATE VIEW statement. Make sEnd point to
93998 ** the end.
93999 */
94000 sEnd = pParse->sLastToken;
94001 if( ALWAYS(sEnd.z[0]!=0) && sEnd.z[0]!=';' ){
 
94002 sEnd.z += sEnd.n;
94003 }
94004 sEnd.n = 0;
94005 n = (int)(sEnd.z - pBegin->z);
 
94006 z = pBegin->z;
94007 while( ALWAYS(n>0) && sqlite3Isspace(z[n-1]) ){ n--; }
94008 sEnd.z = &z[n-1];
94009 sEnd.n = 1;
94010
94011 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
94012 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
 
 
 
 
94013 return;
94014 }
94015 #endif /* SQLITE_OMIT_VIEW */
94016
94017 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -94025,10 +94183,11 @@
94025 Select *pSel; /* Copy of the SELECT that implements the view */
94026 int nErr = 0; /* Number of errors encountered */
94027 int n; /* Temporarily holds the number of cursors assigned */
94028 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
94029 sqlite3_xauth xAuth; /* Saved xAuth pointer */
 
94030
94031 assert( pTable );
94032
94033 #ifndef SQLITE_OMIT_VIRTUALTABLE
94034 if( sqlite3VtabCallConnect(pParse, pTable) ){
@@ -94070,44 +94229,50 @@
94070 ** to the elements of the FROM clause. But we do not want these changes
94071 ** to be permanent. So the computation is done on a copy of the SELECT
94072 ** statement that defines the view.
94073 */
94074 assert( pTable->pSelect );
94075 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
94076 if( pSel ){
94077 u8 enableLookaside = db->lookaside.bEnabled;
94078 n = pParse->nTab;
94079 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
94080 pTable->nCol = -1;
94081 db->lookaside.bEnabled = 0;
94082 #ifndef SQLITE_OMIT_AUTHORIZATION
94083 xAuth = db->xAuth;
94084 db->xAuth = 0;
94085 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94086 db->xAuth = xAuth;
94087 #else
94088 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94089 #endif
94090 db->lookaside.bEnabled = enableLookaside;
94091 pParse->nTab = n;
94092 if( pSelTab ){
94093 assert( pTable->aCol==0 );
94094 pTable->nCol = pSelTab->nCol;
94095 pTable->aCol = pSelTab->aCol;
94096 pSelTab->nCol = 0;
94097 pSelTab->aCol = 0;
94098 sqlite3DeleteTable(db, pSelTab);
94099 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
94100 pTable->pSchema->schemaFlags |= DB_UnresetViews;
94101 }else{
94102 pTable->nCol = 0;
94103 nErr++;
94104 }
94105 sqlite3SelectDelete(db, pSel);
94106 } else {
94107 nErr++;
94108 }
 
 
 
 
 
 
94109 #endif /* SQLITE_OMIT_VIEW */
94110 return nErr;
94111 }
94112 #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
94113
@@ -94120,11 +94285,11 @@
94120 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
94121 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
94122 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
94123 Table *pTab = sqliteHashData(i);
94124 if( pTab->pSelect ){
94125 sqliteDeleteColumnNames(db, pTab);
94126 pTab->aCol = 0;
94127 pTab->nCol = 0;
94128 }
94129 }
94130 DbClearProperty(db, idx, DB_UnresetViews);
@@ -94675,11 +94840,11 @@
94675
94676 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
94677 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
94678 if( IsUniqueIndex(pIndex) && pKey!=0 ){
94679 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
94680 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
94681 addr2 = sqlite3VdbeCurrentAddr(v);
94682 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
94683 pIndex->nKeyCol); VdbeCoverage(v);
94684 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
94685 }else{
@@ -94730,10 +94895,34 @@
94730 p->nKeyCol = nCol - 1;
94731 *ppExtra = ((char*)p) + nByte;
94732 }
94733 return p;
94734 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94735
94736 /*
94737 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
94738 ** and pTblList is the name of the table that is to be indexed. Both will
94739 ** be NULL for a primary key or an index that is created to satisfy a
@@ -94772,11 +94961,10 @@
94772 sqlite3 *db = pParse->db;
94773 Db *pDb; /* The specific table containing the indexed database */
94774 int iDb; /* Index of the database that is being written */
94775 Token *pName = 0; /* Unqualified name of the index to create */
94776 struct ExprList_item *pListItem; /* For looping over pList */
94777 const Column *pTabCol; /* A column in the table */
94778 int nExtra = 0; /* Space allocated for zExtra[] */
94779 int nExtraCol; /* Number of extra columns needed */
94780 char *zExtra = 0; /* Extra space after the Index object */
94781 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
94782
@@ -94927,24 +95115,29 @@
94927 /* If pList==0, it means this routine was called to make a primary
94928 ** key out of the last column added to the table under construction.
94929 ** So create a fake list to simulate this.
94930 */
94931 if( pList==0 ){
94932 pList = sqlite3ExprListAppend(pParse, 0, 0);
 
 
 
 
94933 if( pList==0 ) goto exit_create_index;
94934 pList->a[0].zName = sqlite3DbStrDup(pParse->db,
94935 pTab->aCol[pTab->nCol-1].zName);
94936 pList->a[0].sortOrder = (u8)sortOrder;
 
94937 }
94938
94939 /* Figure out how many bytes of space are required to store explicitly
94940 ** specified collation sequence names.
94941 */
94942 for(i=0; i<pList->nExpr; i++){
94943 Expr *pExpr = pList->a[i].pExpr;
94944 if( pExpr ){
94945 assert( pExpr->op==TK_COLLATE );
94946 nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
94947 }
94948 }
94949
94950 /*
@@ -94981,61 +95174,85 @@
94981 sortOrderMask = -1; /* Honor DESC */
94982 }else{
94983 sortOrderMask = 0; /* Ignore DESC */
94984 }
94985
94986 /* Scan the names of the columns of the table to be indexed and
94987 ** load the column indices into the Index structure. Report an error
94988 ** if any column is not found.
 
94989 **
94990 ** TODO: Add a test to make sure that the same column is not named
94991 ** more than once within the same index. Only the first instance of
94992 ** the column will ever be used by the optimizer. Note that using the
94993 ** same column more than once cannot be an error because that would
94994 ** break backwards compatibility - it needs to be a warning.
94995 */
94996 for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){
94997 const char *zColName = pListItem->zName;
94998 int requestedSortOrder;
94999 char *zColl; /* Collation sequence name */
95000
95001 for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){
95002 if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break;
95003 }
95004 if( j>=pTab->nCol ){
95005 sqlite3ErrorMsg(pParse, "table %s has no column named %s",
95006 pTab->zName, zColName);
95007 pParse->checkSchema = 1;
95008 goto exit_create_index;
95009 }
95010 assert( j<=0x7fff );
95011 pIndex->aiColumn[i] = (i16)j;
95012 if( pListItem->pExpr ){
95013 int nColl;
95014 assert( pListItem->pExpr->op==TK_COLLATE );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95015 zColl = pListItem->pExpr->u.zToken;
95016 nColl = sqlite3Strlen30(zColl) + 1;
95017 assert( nExtra>=nColl );
95018 memcpy(zExtra, zColl, nColl);
95019 zColl = zExtra;
95020 zExtra += nColl;
95021 nExtra -= nColl;
95022 }else{
95023 zColl = pTab->aCol[j].zColl;
95024 if( !zColl ) zColl = "BINARY";
95025 }
 
95026 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
95027 goto exit_create_index;
95028 }
95029 pIndex->azColl[i] = zColl;
95030 requestedSortOrder = pListItem->sortOrder & sortOrderMask;
95031 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
95032 if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
95033 }
 
 
 
 
 
95034 if( pPk ){
95035 for(j=0; j<pPk->nKeyCol; j++){
95036 int x = pPk->aiColumn[j];
 
95037 if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
95038 pIndex->nColumn--;
95039 }else{
95040 pIndex->aiColumn[i] = x;
95041 pIndex->azColl[i] = pPk->azColl[j];
@@ -95082,10 +95299,11 @@
95082
95083 if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
95084 for(k=0; k<pIdx->nKeyCol; k++){
95085 const char *z1;
95086 const char *z2;
 
95087 if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
95088 z1 = pIdx->azColl[k];
95089 z2 = pIndex->azColl[k];
95090 if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
95091 }
@@ -95113,10 +95331,11 @@
95113 }
95114
95115 /* Link the new Index structure to its table and to the other
95116 ** in-memory database structures.
95117 */
 
95118 if( db->init.busy ){
95119 Index *p;
95120 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
95121 p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
95122 pIndex->zName, pIndex);
@@ -95142,11 +95361,11 @@
95142 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
95143 ** or UNIQUE index in a CREATE TABLE statement. Since the table
95144 ** has just been created, it contains no data and the index initialization
95145 ** step can be skipped.
95146 */
95147 else if( pParse->nErr==0 && (HasRowid(pTab) || pTblName!=0) ){
95148 Vdbe *v;
95149 char *zStmt;
95150 int iMem = ++pParse->nMem;
95151
95152 v = sqlite3GetVdbe(pParse);
@@ -95602,11 +95821,12 @@
95602 if( pList==0 ) return;
95603 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
95604 sqlite3DbFree(db, pItem->zDatabase);
95605 sqlite3DbFree(db, pItem->zName);
95606 sqlite3DbFree(db, pItem->zAlias);
95607 sqlite3DbFree(db, pItem->zIndexedBy);
 
95608 sqlite3DeleteTable(db, pItem->pTab);
95609 sqlite3SelectDelete(db, pItem->pSelect);
95610 sqlite3ExprDelete(db, pItem->pOn);
95611 sqlite3IdListDelete(db, pItem->pUsing);
95612 }
@@ -95675,20 +95895,40 @@
95675 */
95676 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
95677 assert( pIndexedBy!=0 );
95678 if( p && ALWAYS(p->nSrc>0) ){
95679 struct SrcList_item *pItem = &p->a[p->nSrc-1];
95680 assert( pItem->notIndexed==0 && pItem->zIndexedBy==0 );
 
 
95681 if( pIndexedBy->n==1 && !pIndexedBy->z ){
95682 /* A "NOT INDEXED" clause was supplied. See parse.y
95683 ** construct "indexed_opt" for details. */
95684 pItem->notIndexed = 1;
95685 }else{
95686 pItem->zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
 
95687 }
95688 }
95689 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95690
95691 /*
95692 ** When building up a FROM clause in the parser, the join operator
95693 ** is initially attached to the left operand. But the code generator
95694 ** expects the join operator to be on the right operand. This routine
@@ -95705,13 +95945,13 @@
95705 */
95706 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
95707 if( p ){
95708 int i;
95709 for(i=p->nSrc-1; i>0; i--){
95710 p->a[i].jointype = p->a[i-1].jointype;
95711 }
95712 p->a[0].jointype = 0;
95713 }
95714 }
95715
95716 /*
95717 ** Begin a transaction
@@ -95951,16 +96191,20 @@
95951 int j;
95952 StrAccum errMsg;
95953 Table *pTab = pIdx->pTable;
95954
95955 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
95956 for(j=0; j<pIdx->nKeyCol; j++){
95957 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
95958 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
95959 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
95960 sqlite3StrAccumAppend(&errMsg, ".", 1);
95961 sqlite3StrAccumAppendAll(&errMsg, zCol);
 
 
 
 
95962 }
95963 zErr = sqlite3StrAccumFinish(&errMsg);
95964 sqlite3HaltConstraint(pParse,
95965 IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
95966 : SQLITE_CONSTRAINT_UNIQUE,
@@ -96201,11 +96445,11 @@
96201 pNew = pWith;
96202 }else{
96203 pNew->a[pNew->nCte].pSelect = pQuery;
96204 pNew->a[pNew->nCte].pCols = pArglist;
96205 pNew->a[pNew->nCte].zName = zName;
96206 pNew->a[pNew->nCte].zErr = 0;
96207 pNew->nCte++;
96208 }
96209
96210 return pNew;
96211 }
@@ -97120,10 +97364,11 @@
97120 }
97121
97122 /* Extract the rowid or primary key for the current row */
97123 if( pPk ){
97124 for(i=0; i<nPk; i++){
 
97125 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
97126 pPk->aiColumn[i], iPk+i);
97127 }
97128 iKey = iPk;
97129 }else{
@@ -97152,11 +97397,11 @@
97152 }else if( pPk ){
97153 /* Construct a composite key for the row to be deleted and remember it */
97154 iKey = ++pParse->nMem;
97155 nKey = 0; /* Zero tells OP_Found to use a composite key */
97156 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
97157 sqlite3IndexAffinityStr(v, pPk), nPk);
97158 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
97159 }else{
97160 /* Get the rowid of the row to be deleted and remember it in the RowSet */
97161 nKey = 1; /* OP_Seek always uses a single rowid */
97162 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -97165,11 +97410,11 @@
97165 /* End of the WHERE loop */
97166 sqlite3WhereEnd(pWInfo);
97167 if( okOnePass ){
97168 /* Bypass the delete logic below if the WHERE loop found zero rows */
97169 addrBypass = sqlite3VdbeMakeLabel(v);
97170 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBypass);
97171 sqlite3VdbeJumpHere(v, addrDelete);
97172 }
97173
97174 /* Unless this is a view, open cursors for the table we are
97175 ** deleting from and all its indices. If this is a view, then the
@@ -97227,11 +97472,11 @@
97227 sqlite3VdbeResolveLabel(v, addrBypass);
97228 }else if( pPk ){
97229 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
97230 sqlite3VdbeJumpHere(v, addrLoop);
97231 }else{
97232 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
97233 sqlite3VdbeJumpHere(v, addrLoop);
97234 }
97235
97236 /* Close the cursors open on the table and its indexes. */
97237 if( !isView && !IsVirtual(pTab) ){
@@ -97498,18 +97743,17 @@
97498 Index *pPrior, /* Previously generated index key */
97499 int regPrior /* Register holding previous generated key */
97500 ){
97501 Vdbe *v = pParse->pVdbe;
97502 int j;
97503 Table *pTab = pIdx->pTable;
97504 int regBase;
97505 int nCol;
97506
97507 if( piPartIdxLabel ){
97508 if( pIdx->pPartIdxWhere ){
97509 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
97510 pParse->iPartIdxTab = iDataCur;
97511 sqlite3ExprCachePush(pParse);
97512 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
97513 SQLITE_JUMPIFNULL);
97514 }else{
97515 *piPartIdxLabel = 0;
@@ -97517,13 +97761,18 @@
97517 }
97518 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
97519 regBase = sqlite3GetTempRange(pParse, nCol);
97520 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
97521 for(j=0; j<nCol; j++){
97522 if( pPrior && pPrior->aiColumn[j]==pIdx->aiColumn[j] ) continue;
97523 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
97524 regBase+j);
 
 
 
 
 
97525 /* If the column affinity is REAL but the number is an integer, then it
97526 ** might be stored in the table as an integer (using a compact
97527 ** representation) then converted to REAL by an OP_RealAffinity opcode.
97528 ** But we are getting ready to store this value back into an index, where
97529 ** it should be converted by to INTEGER again. So omit the OP_RealAffinity
@@ -99288,19 +99537,19 @@
99288 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
99289 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
99290 VFUNCTION(random, 0, 0, 0, randomFunc ),
99291 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
99292 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
99293 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
99294 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
99295 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
99296 #if SQLITE_USER_AUTHENTICATION
99297 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
99298 #endif
99299 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
99300 FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
99301 FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
99302 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
99303 FUNCTION(quote, 1, 0, 0, quoteFunc ),
99304 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
99305 VFUNCTION(changes, 0, 0, 0, changes ),
99306 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
@@ -99308,12 +99557,12 @@
99308 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
99309 #ifdef SQLITE_SOUNDEX
99310 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
99311 #endif
99312 #ifndef SQLITE_OMIT_LOAD_EXTENSION
99313 FUNCTION(load_extension, 1, 0, 0, loadExt ),
99314 FUNCTION(load_extension, 2, 0, 0, loadExt ),
99315 #endif
99316 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
99317 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
99318 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
99319 AGGREGATE2(count, 0, 0, 0, countStep, countFinalize,
@@ -99724,11 +99973,11 @@
99724 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
99725 }
99726
99727 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
99728 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
99729 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
99730 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
99731 sqlite3VdbeJumpHere(v, iMustBeInt);
99732 sqlite3ReleaseTempReg(pParse, regTemp);
99733 }else{
99734 int nCol = pFKey->nCol;
@@ -99762,15 +100011,15 @@
99762 iParent = regData;
99763 }
99764 sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
99765 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
99766 }
99767 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
99768 }
99769
99770 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
99771 sqlite3IndexAffinityStr(v,pIdx), nCol);
99772 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
99773
99774 sqlite3ReleaseTempReg(pParse, regRec);
99775 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
99776 }
@@ -100823,11 +101072,11 @@
100823 **
100824 ** Memory for the buffer containing the column index affinity string
100825 ** is managed along with the rest of the Index structure. It will be
100826 ** released when sqlite3DeleteIndex() is called.
100827 */
100828 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
100829 if( !pIdx->zColAff ){
100830 /* The first time a column affinity string for a particular index is
100831 ** required, it is allocated and populated here. It is then stored as
100832 ** a member of the Index structure for subsequent use.
100833 **
@@ -100835,19 +101084,29 @@
100835 ** sqliteDeleteIndex() when the Index structure itself is cleaned
100836 ** up.
100837 */
100838 int n;
100839 Table *pTab = pIdx->pTable;
100840 sqlite3 *db = sqlite3VdbeDb(v);
100841 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
100842 if( !pIdx->zColAff ){
100843 db->mallocFailed = 1;
100844 return 0;
100845 }
100846 for(n=0; n<pIdx->nColumn; n++){
100847 i16 x = pIdx->aiColumn[n];
100848 pIdx->zColAff[n] = x<0 ? SQLITE_AFF_INTEGER : pTab->aCol[x].affinity;
 
 
 
 
 
 
 
 
 
 
 
100849 }
100850 pIdx->zColAff[n] = 0;
100851 }
100852
100853 return pIdx->zColAff;
@@ -101014,18 +101273,18 @@
101014 memId = p->regCtr;
101015 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
101016 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
101017 sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
101018 addr = sqlite3VdbeCurrentAddr(v);
101019 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
101020 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
101021 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
101022 sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
101023 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
101024 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
101025 sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
101026 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
101027 sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
101028 sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
101029 sqlite3VdbeAddOp0(v, OP_Close);
101030 }
101031 }
@@ -101445,11 +101704,11 @@
101445 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
101446 addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
101447 sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
101448 sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
101449 sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
101450 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
101451 sqlite3VdbeJumpHere(v, addrL);
101452 sqlite3ReleaseTempReg(pParse, regRec);
101453 sqlite3ReleaseTempReg(pParse, regTempRowid);
101454 }
101455 }else{
@@ -101459,15 +101718,17 @@
101459 NameContext sNC;
101460 memset(&sNC, 0, sizeof(sNC));
101461 sNC.pParse = pParse;
101462 srcTab = -1;
101463 assert( useTempTable==0 );
101464 nColumn = pList ? pList->nExpr : 0;
101465 for(i=0; i<nColumn; i++){
101466 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
101467 goto insert_cleanup;
101468 }
 
 
101469 }
101470 }
101471
101472 /* If there is no IDLIST term but the table has an integer primary
101473 ** key, the set the ipkColumn variable to the integer primary key
@@ -101744,11 +102005,11 @@
101744 if( useTempTable ){
101745 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
101746 sqlite3VdbeJumpHere(v, addrInsTop);
101747 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
101748 }else if( pSelect ){
101749 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
101750 sqlite3VdbeJumpHere(v, addrInsTop);
101751 }
101752
101753 if( !IsVirtual(pTab) && !isView ){
101754 /* Close all tables opened */
@@ -101991,11 +102252,11 @@
101991 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
101992 for(i=0; i<pCheck->nExpr; i++){
101993 int allOk = sqlite3VdbeMakeLabel(v);
101994 sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
101995 if( onError==OE_Ignore ){
101996 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
101997 }else{
101998 char *zName = pCheck->a[i].zName;
101999 if( zName==0 ) zName = pTab->zName;
102000 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
102001 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
@@ -102099,11 +102360,11 @@
102099 seenReplace = 1;
102100 break;
102101 }
102102 case OE_Ignore: {
102103 /*assert( seenReplace==0 );*/
102104 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
102105 break;
102106 }
102107 }
102108 sqlite3VdbeResolveLabel(v, addrRowidOk);
102109 if( ipkTop ){
@@ -102147,19 +102408,26 @@
102147 */
102148 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
102149 for(i=0; i<pIdx->nColumn; i++){
102150 int iField = pIdx->aiColumn[i];
102151 int x;
102152 if( iField<0 || iField==pTab->iPKey ){
102153 if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
102154 x = regNewData;
102155 regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
 
102156 }else{
102157 x = iField + regNewData + 1;
 
 
 
 
 
 
 
 
102158 }
102159 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
102160 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
102161 }
102162 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
102163 VdbeComment((v, "for %s", pIdx->zName));
102164 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
102165
@@ -102252,11 +102520,11 @@
102252 case OE_Fail: {
102253 sqlite3UniqueConstraint(pParse, onError, pIdx);
102254 break;
102255 }
102256 case OE_Ignore: {
102257 sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
102258 break;
102259 }
102260 default: {
102261 Trigger *pTrigger = 0;
102262 assert( onError==OE_Replace );
@@ -102273,11 +102541,11 @@
102273 sqlite3VdbeResolveLabel(v, addrUniqueOk);
102274 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
102275 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
102276 }
102277 if( ipkTop ){
102278 sqlite3VdbeAddOp2(v, OP_Goto, 0, ipkTop+1);
102279 sqlite3VdbeJumpHere(v, ipkBottom);
102280 }
102281
102282 *pbMayReplace = seenReplace;
102283 VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
@@ -102475,10 +102743,17 @@
102475 return 0; /* Different conflict resolution strategies */
102476 }
102477 for(i=0; i<pSrc->nKeyCol; i++){
102478 if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
102479 return 0; /* Different columns indexed */
 
 
 
 
 
 
 
102480 }
102481 if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
102482 return 0; /* Different sort orders */
102483 }
102484 if( !xferCompatibleCollation(pSrc->azColl[i],pDest->azColl[i]) ){
@@ -102719,11 +102994,11 @@
102719 ** is unable to test uniqueness.)
102720 **
102721 ** (3) onError is something other than OE_Abort and OE_Rollback.
102722 */
102723 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
102724 emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
102725 sqlite3VdbeJumpHere(v, addr1);
102726 }
102727 if( HasRowid(pSrc) ){
102728 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
102729 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
@@ -103256,10 +103531,13 @@
103256 /* Version 3.8.11 and later */
103257 sqlite3_value *(*value_dup)(const sqlite3_value*);
103258 void (*value_free)(sqlite3_value*);
103259 int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
103260 int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
 
 
 
103261 };
103262
103263 /*
103264 ** The following macros redefine the API routines so that they are
103265 ** redirected through the global sqlite3_api structure.
@@ -103269,11 +103547,11 @@
103269 ** it can get access to the sqlite3_api_routines structure
103270 ** definition. But the main library does not want to redefine
103271 ** the API. So the redefinition macros are only valid if the
103272 ** SQLITE_CORE macros is undefined.
103273 */
103274 #ifndef SQLITE_CORE
103275 #define sqlite3_aggregate_context sqlite3_api->aggregate_context
103276 #ifndef SQLITE_OMIT_DEPRECATED
103277 #define sqlite3_aggregate_count sqlite3_api->aggregate_count
103278 #endif
103279 #define sqlite3_bind_blob sqlite3_api->bind_blob
@@ -103396,10 +103674,11 @@
103396 #define sqlite3_value_text16 sqlite3_api->value_text16
103397 #define sqlite3_value_text16be sqlite3_api->value_text16be
103398 #define sqlite3_value_text16le sqlite3_api->value_text16le
103399 #define sqlite3_value_type sqlite3_api->value_type
103400 #define sqlite3_vmprintf sqlite3_api->vmprintf
 
103401 #define sqlite3_overload_function sqlite3_api->overload_function
103402 #define sqlite3_prepare_v2 sqlite3_api->prepare_v2
103403 #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
103404 #define sqlite3_clear_bindings sqlite3_api->clear_bindings
103405 #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
@@ -103491,13 +103770,16 @@
103491 /* Version 3.8.11 and later */
103492 #define sqlite3_value_dup sqlite3_api->value_dup
103493 #define sqlite3_value_free sqlite3_api->value_free
103494 #define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
103495 #define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
103496 #endif /* SQLITE_CORE */
 
 
 
103497
103498 #ifndef SQLITE_CORE
103499 /* This case when the file really is being compiled as a loadable
103500 ** extension */
103501 # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
103502 # define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
103503 # define SQLITE_EXTENSION_INIT3 \
@@ -103902,11 +104184,14 @@
103902 sqlite3_strglob,
103903 /* Version 3.8.11 and later */
103904 (sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
103905 sqlite3_value_free,
103906 sqlite3_result_zeroblob64,
103907 sqlite3_bind_zeroblob64
 
 
 
103908 };
103909
103910 /*
103911 ** Attempt to load an SQLite extension library contained in the file
103912 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -104898,25 +105183,51 @@
104898 }
104899 db->temp_store = (u8)ts;
104900 return SQLITE_OK;
104901 }
104902 #endif /* SQLITE_PAGER_PRAGMAS */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104903
104904 /*
104905 ** Generate code to return a single integer value.
104906 */
104907 static void returnSingleInt(Parse *pParse, const char *zLabel, i64 value){
104908 Vdbe *v = sqlite3GetVdbe(pParse);
104909 int nMem = ++pParse->nMem;
104910 i64 *pI64 = sqlite3DbMallocRaw(pParse->db, sizeof(value));
104911 if( pI64 ){
104912 memcpy(pI64, &value, sizeof(value));
104913 }
104914 sqlite3VdbeAddOp4(v, OP_Int64, 0, nMem, 0, (char*)pI64, P4_INT64);
104915 sqlite3VdbeSetNumCols(v, 1);
104916 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC);
104917 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
 
 
 
 
 
 
 
 
104918 }
104919
104920
104921 /*
104922 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -105076,18 +105387,12 @@
105076 aFcntl[2] = zRight;
105077 aFcntl[3] = 0;
105078 db->busyHandler.nBusy = 0;
105079 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
105080 if( rc==SQLITE_OK ){
105081 if( aFcntl[0] ){
105082 int nMem = ++pParse->nMem;
105083 sqlite3VdbeAddOp4(v, OP_String8, 0, nMem, 0, aFcntl[0], 0);
105084 sqlite3VdbeSetNumCols(v, 1);
105085 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "result", SQLITE_STATIC);
105086 sqlite3VdbeAddOp2(v, OP_ResultRow, nMem, 1);
105087 sqlite3_free(aFcntl[0]);
105088 }
105089 goto pragma_out;
105090 }
105091 if( rc!=SQLITE_NOTFOUND ){
105092 if( aFcntl[0] ){
105093 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
@@ -105153,12 +105458,11 @@
105153 { OP_ResultRow, 1, 1, 0},
105154 };
105155 int addr;
105156 sqlite3VdbeUsesBtree(v, iDb);
105157 if( !zRight ){
105158 sqlite3VdbeSetNumCols(v, 1);
105159 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
105160 pParse->nMem += 2;
105161 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
105162 sqlite3VdbeChangeP1(v, addr, iDb);
105163 sqlite3VdbeChangeP1(v, addr+1, iDb);
105164 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
@@ -105188,11 +105492,11 @@
105188 case PragTyp_PAGE_SIZE: {
105189 Btree *pBt = pDb->pBt;
105190 assert( pBt!=0 );
105191 if( !zRight ){
105192 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
105193 returnSingleInt(pParse, "page_size", size);
105194 }else{
105195 /* Malloc may fail when setting the page-size, as there is an internal
105196 ** buffer that the pager module resizes using sqlite3_realloc().
105197 */
105198 db->nextPagesize = sqlite3Atoi(zRight);
@@ -105223,11 +105527,11 @@
105223 for(ii=0; ii<db->nDb; ii++){
105224 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
105225 }
105226 }
105227 b = sqlite3BtreeSecureDelete(pBt, b);
105228 returnSingleInt(pParse, "secure_delete", b);
105229 break;
105230 }
105231
105232 /*
105233 ** PRAGMA [database.]max_page_count
@@ -105302,14 +105606,11 @@
105302 assert( eMode==PAGER_LOCKINGMODE_NORMAL
105303 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
105304 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
105305 zRet = "exclusive";
105306 }
105307 sqlite3VdbeSetNumCols(v, 1);
105308 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", SQLITE_STATIC);
105309 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zRet, 0);
105310 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105311 break;
105312 }
105313
105314 /*
105315 ** PRAGMA [database.]journal_mode
@@ -105318,13 +105619,11 @@
105318 */
105319 case PragTyp_JOURNAL_MODE: {
105320 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
105321 int ii; /* Loop counter */
105322
105323 sqlite3VdbeSetNumCols(v, 1);
105324 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);
105325
105326 if( zRight==0 ){
105327 /* If there is no "=MODE" part of the pragma, do a query for the
105328 ** current mode */
105329 eMode = PAGER_JOURNALMODE_QUERY;
105330 }else{
@@ -105366,11 +105665,11 @@
105366 if( zRight ){
105367 sqlite3DecOrHexToI64(zRight, &iLimit);
105368 if( iLimit<-1 ) iLimit = -1;
105369 }
105370 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
105371 returnSingleInt(pParse, "journal_size_limit", iLimit);
105372 break;
105373 }
105374
105375 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105376
@@ -105384,11 +105683,11 @@
105384 #ifndef SQLITE_OMIT_AUTOVACUUM
105385 case PragTyp_AUTO_VACUUM: {
105386 Btree *pBt = pDb->pBt;
105387 assert( pBt!=0 );
105388 if( !zRight ){
105389 returnSingleInt(pParse, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
105390 }else{
105391 int eAuto = getAutoVacuum(zRight);
105392 assert( eAuto>=0 && eAuto<=2 );
105393 db->nextAutovac = (u8)eAuto;
105394 /* Call SetAutoVacuum() to set initialize the internal auto and
@@ -105462,11 +105761,11 @@
105462 */
105463 case PragTyp_CACHE_SIZE: {
105464 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
105465 if( !zRight ){
105466 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105467 returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
105468 }else{
105469 int size = sqlite3Atoi(zRight);
105470 pDb->pSchema->cache_size = size;
105471 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
105472 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
@@ -105508,11 +105807,11 @@
105508 #else
105509 sz = 0;
105510 rc = SQLITE_OK;
105511 #endif
105512 if( rc==SQLITE_OK ){
105513 returnSingleInt(pParse, "mmap_size", sz);
105514 }else if( rc!=SQLITE_NOTFOUND ){
105515 pParse->nErr++;
105516 pParse->rc = rc;
105517 }
105518 break;
@@ -105529,11 +105828,11 @@
105529 ** Note that it is possible for the library compile-time options to
105530 ** override this setting
105531 */
105532 case PragTyp_TEMP_STORE: {
105533 if( !zRight ){
105534 returnSingleInt(pParse, "temp_store", db->temp_store);
105535 }else{
105536 changeTempStorage(pParse, zRight);
105537 }
105538 break;
105539 }
@@ -105548,17 +105847,11 @@
105548 ** If temporary directory is changed, then invalidateTempStorage.
105549 **
105550 */
105551 case PragTyp_TEMP_STORE_DIRECTORY: {
105552 if( !zRight ){
105553 if( sqlite3_temp_directory ){
105554 sqlite3VdbeSetNumCols(v, 1);
105555 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
105556 "temp_store_directory", SQLITE_STATIC);
105557 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_temp_directory, 0);
105558 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105559 }
105560 }else{
105561 #ifndef SQLITE_OMIT_WSD
105562 if( zRight[0] ){
105563 int res;
105564 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -105598,17 +105891,11 @@
105598 ** by this setting, regardless of its value.
105599 **
105600 */
105601 case PragTyp_DATA_STORE_DIRECTORY: {
105602 if( !zRight ){
105603 if( sqlite3_data_directory ){
105604 sqlite3VdbeSetNumCols(v, 1);
105605 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
105606 "data_store_directory", SQLITE_STATIC);
105607 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, sqlite3_data_directory, 0);
105608 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105609 }
105610 }else{
105611 #ifndef SQLITE_OMIT_WSD
105612 if( zRight[0] ){
105613 int res;
105614 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -105643,18 +105930,11 @@
105643 Pager *pPager = sqlite3BtreePager(pDb->pBt);
105644 char *proxy_file_path = NULL;
105645 sqlite3_file *pFile = sqlite3PagerFile(pPager);
105646 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
105647 &proxy_file_path);
105648
105649 if( proxy_file_path ){
105650 sqlite3VdbeSetNumCols(v, 1);
105651 sqlite3VdbeSetColName(v, 0, COLNAME_NAME,
105652 "lock_proxy_file", SQLITE_STATIC);
105653 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, proxy_file_path, 0);
105654 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105655 }
105656 }else{
105657 Pager *pPager = sqlite3BtreePager(pDb->pBt);
105658 sqlite3_file *pFile = sqlite3PagerFile(pPager);
105659 int res;
105660 if( zRight[0] ){
@@ -105682,11 +105962,11 @@
105682 ** default value will be restored the next time the database is
105683 ** opened.
105684 */
105685 case PragTyp_SYNCHRONOUS: {
105686 if( !zRight ){
105687 returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
105688 }else{
105689 if( !db->autoCommit ){
105690 sqlite3ErrorMsg(pParse,
105691 "Safety level may not be changed inside a transaction");
105692 }else{
@@ -105701,11 +105981,11 @@
105701 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105702
105703 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
105704 case PragTyp_FLAG: {
105705 if( zRight==0 ){
105706 returnSingleInt(pParse, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
105707 }else{
105708 int mask = pPragma->iArg; /* Mask of bits to set or clear. */
105709 if( db->autoCommit==0 ){
105710 /* Foreign key support may not be enabled or disabled while not
105711 ** in auto-commit mode. */
@@ -105751,79 +106031,67 @@
105751 */
105752 case PragTyp_TABLE_INFO: if( zRight ){
105753 Table *pTab;
105754 pTab = sqlite3FindTable(db, zRight, zDb);
105755 if( pTab ){
 
 
 
105756 int i, k;
105757 int nHidden = 0;
105758 Column *pCol;
105759 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
105760 sqlite3VdbeSetNumCols(v, 6);
105761 pParse->nMem = 6;
105762 sqlite3CodeVerifySchema(pParse, iDb);
105763 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
105764 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105765 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
105766 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", SQLITE_STATIC);
105767 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", SQLITE_STATIC);
105768 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", SQLITE_STATIC);
105769 sqlite3ViewGetColumnNames(pParse, pTab);
105770 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
105771 if( IsHiddenColumn(pCol) ){
105772 nHidden++;
105773 continue;
105774 }
105775 sqlite3VdbeAddOp2(v, OP_Integer, i-nHidden, 1);
105776 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pCol->zName, 0);
105777 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
105778 pCol->zType ? pCol->zType : "", 0);
105779 sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
105780 if( pCol->zDflt ){
105781 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
105782 }else{
105783 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
105784 }
105785 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
105786 k = 0;
105787 }else if( pPk==0 ){
105788 k = 1;
105789 }else{
105790 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
105791 }
105792 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
 
 
 
 
 
 
105793 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
105794 }
105795 }
105796 }
105797 break;
105798
105799 case PragTyp_STATS: {
 
105800 Index *pIdx;
105801 HashElem *i;
105802 v = sqlite3GetVdbe(pParse);
105803 sqlite3VdbeSetNumCols(v, 4);
105804 pParse->nMem = 4;
105805 sqlite3CodeVerifySchema(pParse, iDb);
105806 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
105807 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "index", SQLITE_STATIC);
105808 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "width", SQLITE_STATIC);
105809 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "height", SQLITE_STATIC);
105810 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
105811 Table *pTab = sqliteHashData(i);
105812 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, pTab->zName, 0);
105813 sqlite3VdbeAddOp2(v, OP_Null, 0, 2);
105814 sqlite3VdbeAddOp2(v, OP_Integer,
105815 (int)sqlite3LogEstToInt(pTab->szTabRow), 3);
105816 sqlite3VdbeAddOp2(v, OP_Integer,
105817 (int)sqlite3LogEstToInt(pTab->nRowLogEst), 4);
105818 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
105819 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
105820 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
105821 sqlite3VdbeAddOp2(v, OP_Integer,
105822 (int)sqlite3LogEstToInt(pIdx->szIdxRow), 3);
105823 sqlite3VdbeAddOp2(v, OP_Integer,
105824 (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]), 4);
105825 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
105826 }
105827 }
105828 }
105829 break;
@@ -105831,10 +106099,13 @@
105831 case PragTyp_INDEX_INFO: if( zRight ){
105832 Index *pIdx;
105833 Table *pTab;
105834 pIdx = sqlite3FindIndex(db, zRight, zDb);
105835 if( pIdx ){
 
 
 
105836 int i;
105837 int mx;
105838 if( pPragma->iArg ){
105839 /* PRAGMA index_xinfo (newer version with more rows and columns) */
105840 mx = pIdx->nColumn;
@@ -105843,33 +106114,22 @@
105843 /* PRAGMA index_info (legacy version) */
105844 mx = pIdx->nKeyCol;
105845 pParse->nMem = 3;
105846 }
105847 pTab = pIdx->pTable;
105848 sqlite3VdbeSetNumCols(v, pParse->nMem);
105849 sqlite3CodeVerifySchema(pParse, iDb);
105850 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
105851 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
105852 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
105853 if( pPragma->iArg ){
105854 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
105855 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
105856 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
105857 }
105858 for(i=0; i<mx; i++){
105859 i16 cnum = pIdx->aiColumn[i];
105860 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105861 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
105862 if( cnum<0 ){
105863 sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
105864 }else{
105865 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
105866 }
105867 if( pPragma->iArg ){
105868 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
105869 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
105870 sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
 
105871 }
105872 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
105873 }
105874 }
105875 }
@@ -105879,62 +106139,57 @@
105879 Index *pIdx;
105880 Table *pTab;
105881 int i;
105882 pTab = sqlite3FindTable(db, zRight, zDb);
105883 if( pTab ){
 
 
 
105884 v = sqlite3GetVdbe(pParse);
105885 sqlite3VdbeSetNumCols(v, 5);
105886 pParse->nMem = 5;
105887 sqlite3CodeVerifySchema(pParse, iDb);
105888 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105889 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105890 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", SQLITE_STATIC);
105891 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "origin", SQLITE_STATIC);
105892 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "partial", SQLITE_STATIC);
105893 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
105894 const char *azOrigin[] = { "c", "u", "pk" };
105895 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105896 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
105897 sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
105898 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, azOrigin[pIdx->idxType], 0);
105899 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->pPartIdxWhere!=0, 5);
 
105900 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
105901 }
105902 }
105903 }
105904 break;
105905
105906 case PragTyp_DATABASE_LIST: {
 
105907 int i;
105908 sqlite3VdbeSetNumCols(v, 3);
105909 pParse->nMem = 3;
105910 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105911 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105912 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", SQLITE_STATIC);
105913 for(i=0; i<db->nDb; i++){
105914 if( db->aDb[i].pBt==0 ) continue;
105915 assert( db->aDb[i].zName!=0 );
105916 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105917 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, db->aDb[i].zName, 0);
105918 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
105919 sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
105920 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
105921 }
105922 }
105923 break;
105924
105925 case PragTyp_COLLATION_LIST: {
 
105926 int i = 0;
105927 HashElem *p;
105928 sqlite3VdbeSetNumCols(v, 2);
105929 pParse->nMem = 2;
105930 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", SQLITE_STATIC);
105931 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
105932 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
105933 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
105934 sqlite3VdbeAddOp2(v, OP_Integer, i++, 1);
105935 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pColl->zName, 0);
105936 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
105937 }
105938 }
105939 break;
105940 #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
@@ -105946,37 +106201,30 @@
105946 pTab = sqlite3FindTable(db, zRight, zDb);
105947 if( pTab ){
105948 v = sqlite3GetVdbe(pParse);
105949 pFK = pTab->pFKey;
105950 if( pFK ){
 
 
 
 
105951 int i = 0;
105952 sqlite3VdbeSetNumCols(v, 8);
105953 pParse->nMem = 8;
105954 sqlite3CodeVerifySchema(pParse, iDb);
105955 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", SQLITE_STATIC);
105956 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", SQLITE_STATIC);
105957 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", SQLITE_STATIC);
105958 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", SQLITE_STATIC);
105959 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", SQLITE_STATIC);
105960 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "on_update", SQLITE_STATIC);
105961 sqlite3VdbeSetColName(v, 6, COLNAME_NAME, "on_delete", SQLITE_STATIC);
105962 sqlite3VdbeSetColName(v, 7, COLNAME_NAME, "match", SQLITE_STATIC);
105963 while(pFK){
105964 int j;
105965 for(j=0; j<pFK->nCol; j++){
105966 char *zCol = pFK->aCol[j].zCol;
105967 char *zOnDelete = (char *)actionName(pFK->aAction[0]);
105968 char *zOnUpdate = (char *)actionName(pFK->aAction[1]);
105969 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
105970 sqlite3VdbeAddOp2(v, OP_Integer, j, 2);
105971 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pFK->zTo, 0);
105972 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
105973 pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
105974 sqlite3VdbeAddOp4(v, zCol ? OP_String8 : OP_Null, 0, 5, 0, zCol, 0);
105975 sqlite3VdbeAddOp4(v, OP_String8, 0, 6, 0, zOnUpdate, 0);
105976 sqlite3VdbeAddOp4(v, OP_String8, 0, 7, 0, zOnDelete, 0);
105977 sqlite3VdbeAddOp4(v, OP_String8, 0, 8, 0, "NONE", 0);
105978 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
105979 }
105980 ++i;
105981 pFK = pFK->pNextFrom;
105982 }
@@ -106001,21 +106249,18 @@
106001 int regKey; /* Register to hold key for checking the FK */
106002 int regRow; /* Registers to hold a row from pTab */
106003 int addrTop; /* Top of a loop checking foreign keys */
106004 int addrOk; /* Jump here if the key is OK */
106005 int *aiCols; /* child to parent column mapping */
 
106006
106007 regResult = pParse->nMem+1;
106008 pParse->nMem += 4;
106009 regKey = ++pParse->nMem;
106010 regRow = ++pParse->nMem;
106011 v = sqlite3GetVdbe(pParse);
106012 sqlite3VdbeSetNumCols(v, 4);
106013 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "table", SQLITE_STATIC);
106014 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "rowid", SQLITE_STATIC);
106015 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "parent", SQLITE_STATIC);
106016 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "fkid", SQLITE_STATIC);
106017 sqlite3CodeVerifySchema(pParse, iDb);
106018 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
106019 while( k ){
106020 if( zRight ){
106021 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
@@ -106026,12 +106271,11 @@
106026 }
106027 if( pTab==0 || pTab->pFKey==0 ) continue;
106028 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
106029 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
106030 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
106031 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult, 0, pTab->zName,
106032 P4_TRANSIENT);
106033 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
106034 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
106035 if( pParent==0 ) continue;
106036 pIdx = 0;
106037 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -106072,29 +106316,27 @@
106072 sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
106073 }else{
106074 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
106075 }
106076 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
106077 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
106078 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
106079 }else{
106080 for(j=0; j<pFK->nCol; j++){
106081 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
106082 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
106083 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
106084 }
106085 if( pParent ){
106086 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
106087 sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
106088 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
106089 VdbeCoverage(v);
106090 }
106091 }
106092 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
106093 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
106094 pFK->zTo, P4_TRANSIENT);
106095 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
106096 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
106097 sqlite3VdbeResolveLabel(v, addrOk);
106098 sqlite3DbFree(db, aiCols);
106099 }
106100 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
@@ -106166,12 +106408,11 @@
106166 assert( iDb==0 || pId2->z );
106167 if( pId2->z==0 ) iDb = -1;
106168
106169 /* Initialize the VDBE program */
106170 pParse->nMem = 6;
106171 sqlite3VdbeSetNumCols(v, 1);
106172 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", SQLITE_STATIC);
106173
106174 /* Set the maximum error count */
106175 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
106176 if( zRight ){
106177 sqlite3GetInt32(zRight, &mxErr);
@@ -106289,17 +106530,15 @@
106289 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
106290 /* Verify that an index entry exists for the current table row */
106291 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
106292 pIdx->nColumn); VdbeCoverage(v);
106293 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106294 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
106295 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
106296 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
106297 " missing from index ", P4_STATIC);
106298 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106299 jmp5 = sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0,
106300 pIdx->zName, P4_TRANSIENT);
106301 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106302 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
106303 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
106304 sqlite3VdbeAddOp0(v, OP_Halt);
106305 sqlite3VdbeJumpHere(v, jmp2);
@@ -106316,38 +106555,36 @@
106316 if( pTab->aCol[iCol].notNull ) continue;
106317 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
106318 VdbeCoverage(v);
106319 }
106320 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
106321 sqlite3VdbeAddOp2(v, OP_Goto, 0, uniqOk);
106322 sqlite3VdbeJumpHere(v, jmp6);
106323 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
106324 pIdx->nKeyCol); VdbeCoverage(v);
106325 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106326 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
106327 "non-unique entry in index ", P4_STATIC);
106328 sqlite3VdbeAddOp2(v, OP_Goto, 0, jmp5);
106329 sqlite3VdbeResolveLabel(v, uniqOk);
106330 }
106331 sqlite3VdbeJumpHere(v, jmp4);
106332 sqlite3ResolvePartIdxLabel(pParse, jmp3);
106333 }
106334 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
106335 sqlite3VdbeJumpHere(v, loopTop-1);
106336 #ifndef SQLITE_OMIT_BTREECOUNT
106337 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
106338 "wrong # of entries in index ", P4_STATIC);
106339 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
106340 if( pPk==pIdx ) continue;
106341 addr = sqlite3VdbeCurrentAddr(v);
106342 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
106343 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
106344 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
106345 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
106346 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
106347 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
106348 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
106349 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
106350 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
106351 }
106352 #endif /* SQLITE_OMIT_BTREECOUNT */
106353 }
@@ -106399,18 +106636,14 @@
106399 { 0, 0 }
106400 };
106401 const struct EncName *pEnc;
106402 if( !zRight ){ /* "PRAGMA encoding" */
106403 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
106404 sqlite3VdbeSetNumCols(v, 1);
106405 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
106406 sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
106407 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
106408 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
106409 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
106410 sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
106411 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
106412 }else{ /* "PRAGMA encoding = XXX" */
106413 /* Only change the value of sqlite.enc if the database handle is not
106414 ** initialized. If the main database exists, the new sqlite.enc value
106415 ** will be overwritten when the schema is next loaded. If it does not
106416 ** already exists, it will be created to use the new encoding value.
@@ -106507,15 +106740,14 @@
106507 ** one option per row.
106508 */
106509 case PragTyp_COMPILE_OPTIONS: {
106510 int i = 0;
106511 const char *zOpt;
106512 sqlite3VdbeSetNumCols(v, 1);
106513 pParse->nMem = 1;
106514 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "compile_option", SQLITE_STATIC);
106515 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
106516 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, zOpt, 0);
106517 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
106518 }
106519 }
106520 break;
106521 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
@@ -106525,10 +106757,11 @@
106525 ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
106526 **
106527 ** Checkpoint the database.
106528 */
106529 case PragTyp_WAL_CHECKPOINT: {
 
106530 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
106531 int eMode = SQLITE_CHECKPOINT_PASSIVE;
106532 if( zRight ){
106533 if( sqlite3StrICmp(zRight, "full")==0 ){
106534 eMode = SQLITE_CHECKPOINT_FULL;
@@ -106536,16 +106769,12 @@
106536 eMode = SQLITE_CHECKPOINT_RESTART;
106537 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
106538 eMode = SQLITE_CHECKPOINT_TRUNCATE;
106539 }
106540 }
106541 sqlite3VdbeSetNumCols(v, 3);
106542 pParse->nMem = 3;
106543 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
106544 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "log", SQLITE_STATIC);
106545 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "checkpointed", SQLITE_STATIC);
106546
106547 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
106548 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
106549 }
106550 break;
106551
@@ -106559,11 +106788,11 @@
106559 */
106560 case PragTyp_WAL_AUTOCHECKPOINT: {
106561 if( zRight ){
106562 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
106563 }
106564 returnSingleInt(pParse, "wal_autocheckpoint",
106565 db->xWalCallback==sqlite3WalDefaultHook ?
106566 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
106567 }
106568 break;
106569 #endif
@@ -106592,11 +106821,11 @@
106592 /*case PragTyp_BUSY_TIMEOUT*/ default: {
106593 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
106594 if( zRight ){
106595 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
106596 }
106597 returnSingleInt(pParse, "timeout", db->busyTimeout);
106598 break;
106599 }
106600
106601 /*
106602 ** PRAGMA soft_heap_limit
@@ -106612,11 +106841,11 @@
106612 case PragTyp_SOFT_HEAP_LIMIT: {
106613 sqlite3_int64 N;
106614 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
106615 sqlite3_soft_heap_limit64(N);
106616 }
106617 returnSingleInt(pParse, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
106618 break;
106619 }
106620
106621 /*
106622 ** PRAGMA threads
@@ -106631,11 +106860,11 @@
106631 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
106632 && N>=0
106633 ){
106634 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
106635 }
106636 returnSingleInt(pParse, "threads",
106637 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
106638 break;
106639 }
106640
106641 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
@@ -106644,29 +106873,27 @@
106644 */
106645 case PragTyp_LOCK_STATUS: {
106646 static const char *const azLockName[] = {
106647 "unlocked", "shared", "reserved", "pending", "exclusive"
106648 };
 
106649 int i;
106650 sqlite3VdbeSetNumCols(v, 2);
106651 pParse->nMem = 2;
106652 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", SQLITE_STATIC);
106653 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", SQLITE_STATIC);
106654 for(i=0; i<db->nDb; i++){
106655 Btree *pBt;
106656 const char *zState = "unknown";
106657 int j;
106658 if( db->aDb[i].zName==0 ) continue;
106659 sqlite3VdbeAddOp4(v, OP_String8, 0, 1, 0, db->aDb[i].zName, P4_STATIC);
106660 pBt = db->aDb[i].pBt;
106661 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
106662 zState = "closed";
106663 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
106664 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
106665 zState = azLockName[j];
106666 }
106667 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, zState, P4_STATIC);
106668 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
106669 }
106670 break;
106671 }
106672 #endif
@@ -108027,16 +108254,16 @@
108027 Table *pLeftTab = pLeft->pTab;
108028 Table *pRightTab = pRight->pTab;
108029 int isOuter;
108030
108031 if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
108032 isOuter = (pRight->jointype & JT_OUTER)!=0;
108033
108034 /* When the NATURAL keyword is present, add WHERE clause terms for
108035 ** every column that the two tables have in common.
108036 */
108037 if( pRight->jointype & JT_NATURAL ){
108038 if( pRight->pOn || pRight->pUsing ){
108039 sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
108040 "an ON or USING clause", 0);
108041 return 1;
108042 }
@@ -108117,10 +108344,11 @@
108117 static void pushOntoSorter(
108118 Parse *pParse, /* Parser context */
108119 SortCtx *pSort, /* Information about the ORDER BY clause */
108120 Select *pSelect, /* The whole SELECT statement */
108121 int regData, /* First register holding data to be sorted */
 
108122 int nData, /* Number of elements in the data array */
108123 int nPrefixReg /* No. of reg prior to regData available for use */
108124 ){
108125 Vdbe *v = pParse->pVdbe; /* Stmt under construction */
108126 int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
@@ -108130,18 +108358,20 @@
108130 int regRecord = ++pParse->nMem; /* Assembled sorter record */
108131 int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */
108132 int op; /* Opcode to add sorter record to sorter */
108133
108134 assert( bSeq==0 || bSeq==1 );
 
108135 if( nPrefixReg ){
108136 assert( nPrefixReg==nExpr+bSeq );
108137 regBase = regData - nExpr - bSeq;
108138 }else{
108139 regBase = pParse->nMem + 1;
108140 pParse->nMem += nBase;
108141 }
108142 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
 
108143 if( bSeq ){
108144 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
108145 }
108146 if( nPrefixReg==0 ){
108147 sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
@@ -108215,11 +108445,11 @@
108215 int iContinue /* Jump here to skip the current record */
108216 ){
108217 if( iOffset>0 ){
108218 int addr;
108219 addr = sqlite3VdbeAddOp3(v, OP_IfNeg, iOffset, 0, -1); VdbeCoverage(v);
108220 sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
108221 VdbeComment((v, "skip OFFSET records"));
108222 sqlite3VdbeJumpHere(v, addr);
108223 }
108224 }
108225
@@ -108347,11 +108577,11 @@
108347 if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
108348 ecelFlags = SQLITE_ECEL_DUP;
108349 }else{
108350 ecelFlags = 0;
108351 }
108352 sqlite3ExprCodeExprList(pParse, pEList, regResult, ecelFlags);
108353 }
108354
108355 /* If the DISTINCT keyword was present on the SELECT statement
108356 ** and this row has been seen before, then do not make this row
108357 ** part of the result.
@@ -108463,11 +108693,11 @@
108463 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
108464 assert( pSort==0 );
108465 }
108466 #endif
108467 if( pSort ){
108468 pushOntoSorter(pParse, pSort, p, r1+nPrefixReg, 1, nPrefixReg);
108469 }else{
108470 int r2 = sqlite3GetTempReg(pParse);
108471 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);
108472 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);
108473 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -108489,11 +108719,11 @@
108489 if( pSort ){
108490 /* At first glance you would think we could optimize out the
108491 ** ORDER BY in this case since the order of entries in the set
108492 ** does not matter. But there might be a LIMIT clause, in which
108493 ** case the order does matter */
108494 pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
108495 }else{
108496 int r1 = sqlite3GetTempReg(pParse);
108497 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult,1,r1, &pDest->affSdst, 1);
108498 sqlite3ExprCacheAffinityChange(pParse, regResult, 1);
108499 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
@@ -108515,11 +108745,11 @@
108515 ** of the scan loop.
108516 */
108517 case SRT_Mem: {
108518 assert( nResultCol==1 );
108519 if( pSort ){
108520 pushOntoSorter(pParse, pSort, p, regResult, 1, nPrefixReg);
108521 }else{
108522 assert( regResult==iParm );
108523 /* The LIMIT clause will jump out of the loop for us */
108524 }
108525 break;
@@ -108529,11 +108759,12 @@
108529 case SRT_Coroutine: /* Send data to a co-routine */
108530 case SRT_Output: { /* Return the results */
108531 testcase( eDest==SRT_Coroutine );
108532 testcase( eDest==SRT_Output );
108533 if( pSort ){
108534 pushOntoSorter(pParse, pSort, p, regResult, nResultCol, nPrefixReg);
 
108535 }else if( eDest==SRT_Coroutine ){
108536 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108537 }else{
108538 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
108539 sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
@@ -108823,11 +109054,11 @@
108823 struct ExprList_item *aOutEx = p->pEList->a;
108824 #endif
108825
108826 if( pSort->labelBkOut ){
108827 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
108828 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBreak);
108829 sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
108830 }
108831 iTab = pSort->iECursor;
108832 if( eDest==SRT_Output || eDest==SRT_Coroutine ){
108833 regRowid = 0;
@@ -109208,11 +109439,11 @@
109208 ** and other fields of Column are zeroed.
109209 **
109210 ** Return SQLITE_OK on success. If a memory allocation error occurs,
109211 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
109212 */
109213 static int selectColumnsFromExprList(
109214 Parse *pParse, /* Parsing context */
109215 ExprList *pEList, /* Expr list from which to derive column names */
109216 i16 *pnCol, /* Write the number of columns here */
109217 Column **paCol /* Write the new column list here */
109218 ){
@@ -109375,11 +109606,11 @@
109375 ** is disabled */
109376 assert( db->lookaside.bEnabled==0 );
109377 pTab->nRef = 1;
109378 pTab->zName = 0;
109379 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
109380 selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
109381 selectAddColumnTypeAndCollation(pParse, pTab, pSelect);
109382 pTab->iPKey = -1;
109383 if( db->mallocFailed ){
109384 sqlite3DeleteTable(db, pTab);
109385 return 0;
@@ -109451,11 +109682,11 @@
109451 assert( v!=0 );
109452 if( sqlite3ExprIsInteger(p->pLimit, &n) ){
109453 sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
109454 VdbeComment((v, "LIMIT counter"));
109455 if( n==0 ){
109456 sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
109457 }else if( n>=0 && p->nSelectRow>(u64)n ){
109458 p->nSelectRow = n;
109459 }
109460 }else{
109461 sqlite3ExprCode(pParse, p->pLimit, iLimit);
@@ -109554,11 +109785,11 @@
109554 ** \___________/ \_______________/
109555 ** p->pPrior p
109556 **
109557 **
109558 ** There is exactly one reference to the recursive-table in the FROM clause
109559 ** of recursive-query, marked with the SrcList->a[].isRecursive flag.
109560 **
109561 ** The setup-query runs once to generate an initial set of rows that go
109562 ** into a Queue table. Rows are extracted from the Queue table one by
109563 ** one. Each row extracted from Queue is output to pDest. Then the single
109564 ** extracted row (now in the iCurrent table) becomes the content of the
@@ -109619,11 +109850,11 @@
109619 p->iLimit = p->iOffset = 0;
109620 pOrderBy = p->pOrderBy;
109621
109622 /* Locate the cursor number of the Current table */
109623 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
109624 if( pSrc->a[i].isRecursive ){
109625 iCurrent = pSrc->a[i].iCursor;
109626 break;
109627 }
109628 }
109629
@@ -109699,11 +109930,11 @@
109699 assert( p->pPrior==0 );
109700 p->pPrior = pSetup;
109701 }
109702
109703 /* Keep running the loop until the Queue is empty */
109704 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
109705 sqlite3VdbeResolveLabel(v, addrBreak);
109706
109707 end_of_recursive_query:
109708 sqlite3ExprListDelete(pParse->db, p->pOrderBy);
109709 p->pOrderBy = pOrderBy;
@@ -110608,11 +110839,11 @@
110608 }else{
110609 VdbeNoopComment((v, "eof-A subroutine"));
110610 addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110611 addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
110612 VdbeCoverage(v);
110613 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
110614 p->nSelectRow += pPrior->nSelectRow;
110615 }
110616
110617 /* Generate a subroutine to run when the results from select B
110618 ** are exhausted and only data in select A remains.
@@ -110622,19 +110853,19 @@
110622 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
110623 }else{
110624 VdbeNoopComment((v, "eof-B subroutine"));
110625 addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110626 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
110627 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
110628 }
110629
110630 /* Generate code to handle the case of A<B
110631 */
110632 VdbeNoopComment((v, "A-lt-B subroutine"));
110633 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110634 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110635 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
110636
110637 /* Generate code to handle the case of A==B
110638 */
110639 if( op==TK_ALL ){
110640 addrAeqB = addrAltB;
@@ -110643,11 +110874,11 @@
110643 addrAltB++;
110644 }else{
110645 VdbeNoopComment((v, "A-eq-B subroutine"));
110646 addrAeqB =
110647 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110648 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
110649 }
110650
110651 /* Generate code to handle the case of A>B
110652 */
110653 VdbeNoopComment((v, "A-gt-B subroutine"));
@@ -110654,11 +110885,11 @@
110654 addrAgtB = sqlite3VdbeCurrentAddr(v);
110655 if( op==TK_ALL || op==TK_UNION ){
110656 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110657 }
110658 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
110659 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
110660
110661 /* This code runs once to initialize everything.
110662 */
110663 sqlite3VdbeJumpHere(v, j1);
110664 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
@@ -111034,11 +111265,11 @@
111034 ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
111035 ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
111036 ** is fraught with danger. Best to avoid the whole thing. If the
111037 ** subquery is the right term of a LEFT JOIN, then do not flatten.
111038 */
111039 if( (pSubitem->jointype & JT_OUTER)!=0 ){
111040 return 0;
111041 }
111042
111043 /* Restriction 17: If the sub-query is a compound SELECT, then it must
111044 ** use only the UNION ALL operator. And none of the simple select queries
@@ -111205,11 +111436,11 @@
111205 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
111206 pSrc = pParent->pSrc; /* FROM clause of the outer query */
111207
111208 if( pSrc ){
111209 assert( pParent==p ); /* First time through the loop */
111210 jointype = pSubitem->jointype;
111211 }else{
111212 assert( pParent!=p ); /* 2nd and subsequent times through the loop */
111213 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
111214 if( pSrc==0 ){
111215 assert( db->mallocFailed );
@@ -111245,11 +111476,11 @@
111245 for(i=0; i<nSubSrc; i++){
111246 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
111247 pSrc->a[i+iFrom] = pSubSrc->a[i];
111248 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
111249 }
111250 pSrc->a[iFrom].jointype = jointype;
111251
111252 /* Now begin substituting subquery result set expressions for
111253 ** references to the iParent in the outer query.
111254 **
111255 ** Example:
@@ -111377,10 +111608,13 @@
111377 ** close would change the meaning of the LIMIT).
111378 **
111379 ** (4) The inner query is the right operand of a LEFT JOIN. (The caller
111380 ** enforces this restriction since this routine does not have enough
111381 ** information to know.)
 
 
 
111382 **
111383 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
111384 ** terms are duplicated into the subquery.
111385 */
111386 static int pushDownWhereTerms(
@@ -111400,10 +111634,11 @@
111400 }
111401 while( pWhere->op==TK_AND ){
111402 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
111403 pWhere = pWhere->pLeft;
111404 }
 
111405 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
111406 nChng++;
111407 while( pSubq ){
111408 pNew = sqlite3ExprDup(db, pWhere, 0);
111409 pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
@@ -111496,13 +111731,13 @@
111496 ** was such a clause and the named index cannot be found, return
111497 ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
111498 ** pFrom->pIndex and return SQLITE_OK.
111499 */
111500 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){
111501 if( pFrom->pTab && pFrom->zIndexedBy ){
111502 Table *pTab = pFrom->pTab;
111503 char *zIndexedBy = pFrom->zIndexedBy;
111504 Index *pIdx;
111505 for(pIdx=pTab->pIndex;
111506 pIdx && sqlite3StrICmp(pIdx->zName, zIndexedBy);
111507 pIdx=pIdx->pNext
111508 );
@@ -111509,11 +111744,11 @@
111509 if( !pIdx ){
111510 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
111511 pParse->checkSchema = 1;
111512 return SQLITE_ERROR;
111513 }
111514 pFrom->pIndex = pIdx;
111515 }
111516 return SQLITE_OK;
111517 }
111518 /*
111519 ** Detect compound SELECT statements that use an ORDER BY clause with
@@ -111670,16 +111905,16 @@
111670 Select *pSel;
111671 Select *pLeft; /* Left-most SELECT statement */
111672 int bMayRecursive; /* True if compound joined by UNION [ALL] */
111673 With *pSavedWith; /* Initial value of pParse->pWith */
111674
111675 /* If pCte->zErr is non-NULL at this point, then this is an illegal
111676 ** recursive reference to CTE pCte. Leave an error in pParse and return
111677 ** early. If pCte->zErr is NULL, then this is not a recursive reference.
111678 ** In this case, proceed. */
111679 if( pCte->zErr ){
111680 sqlite3ErrorMsg(pParse, pCte->zErr, pCte->zName);
111681 return SQLITE_ERROR;
111682 }
111683
111684 assert( pFrom->pTab==0 );
111685 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
@@ -111704,11 +111939,11 @@
111704 if( pItem->zDatabase==0
111705 && pItem->zName!=0
111706 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
111707 ){
111708 pItem->pTab = pTab;
111709 pItem->isRecursive = 1;
111710 pTab->nRef++;
111711 pSel->selFlags |= SF_Recursive;
111712 }
111713 }
111714 }
@@ -111720,11 +111955,11 @@
111720 );
111721 return SQLITE_ERROR;
111722 }
111723 assert( pTab->nRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nRef==2 ));
111724
111725 pCte->zErr = "circular reference: %s";
111726 pSavedWith = pParse->pWith;
111727 pParse->pWith = pWith;
111728 sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
111729
111730 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
@@ -111738,20 +111973,20 @@
111738 return SQLITE_ERROR;
111739 }
111740 pEList = pCte->pCols;
111741 }
111742
111743 selectColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
111744 if( bMayRecursive ){
111745 if( pSel->selFlags & SF_Recursive ){
111746 pCte->zErr = "multiple recursive references: %s";
111747 }else{
111748 pCte->zErr = "recursive reference in a subquery: %s";
111749 }
111750 sqlite3WalkSelect(pWalker, pSel);
111751 }
111752 pCte->zErr = 0;
111753 pParse->pWith = pSavedWith;
111754 }
111755
111756 return SQLITE_OK;
111757 }
@@ -111834,12 +112069,12 @@
111834 ** an entry of the FROM clause is a subquery instead of a table or view,
111835 ** then create a transient table structure to describe the subquery.
111836 */
111837 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
111838 Table *pTab;
111839 assert( pFrom->isRecursive==0 || pFrom->pTab );
111840 if( pFrom->isRecursive ) continue;
111841 if( pFrom->pTab!=0 ){
111842 /* This statement has already been prepared. There is no need
111843 ** to go further. */
111844 assert( i==0 );
111845 #ifndef SQLITE_OMIT_CTE
@@ -111861,11 +112096,11 @@
111861 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
111862 if( pTab==0 ) return WRC_Abort;
111863 pTab->nRef = 1;
111864 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
111865 while( pSel->pPrior ){ pSel = pSel->pPrior; }
111866 selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
111867 pTab->iPKey = -1;
111868 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
111869 pTab->tabFlags |= TF_Ephemeral;
111870 #endif
111871 }else{
@@ -111998,11 +112233,11 @@
111998 continue;
111999 }
112000 tableSeen = 1;
112001
112002 if( i>0 && zTName==0 ){
112003 if( (pFrom->jointype & JT_NATURAL)!=0
112004 && tableAndColumnIndex(pTabList, i, zName, 0, 0)
112005 ){
112006 /* In a NATURAL join, omit the join columns from the
112007 ** table to the right of the join */
112008 continue;
@@ -112284,11 +112519,11 @@
112284 ExprList *pList = pF->pExpr->x.pList;
112285 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
112286 if( pList ){
112287 nArg = pList->nExpr;
112288 regAgg = sqlite3GetTempRange(pParse, nArg);
112289 sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
112290 }else{
112291 nArg = 0;
112292 regAgg = 0;
112293 }
112294 if( pF->iDistinct>=0 ){
@@ -112525,11 +112760,11 @@
112525 ** for example. In that case, do not regenerate the code to manifest
112526 ** a view or the co-routine to implement a view. The first instance
112527 ** is sufficient, though the subroutine to manifest the view does need
112528 ** to be invoked again. */
112529 if( pItem->addrFillSub ){
112530 if( pItem->viaCoroutine==0 ){
112531 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
112532 }
112533 continue;
112534 }
112535
@@ -112543,11 +112778,11 @@
112543 pParse->nHeight += sqlite3SelectExprHeight(p);
112544
112545 /* Make copies of constant WHERE-clause terms in the outer query down
112546 ** inside the subquery. This can help the subquery to run more efficiently.
112547 */
112548 if( (pItem->jointype & JT_OUTER)==0
112549 && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
112550 ){
112551 #if SELECTTRACE_ENABLED
112552 if( sqlite3SelectTrace & 0x100 ){
112553 SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
@@ -112572,11 +112807,11 @@
112572 pItem->addrFillSub = addrTop;
112573 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
112574 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
112575 sqlite3Select(pParse, pSub, &dest);
112576 pItem->pTab->nRowLogEst = sqlite3LogEst(pSub->nSelectRow);
112577 pItem->viaCoroutine = 1;
112578 pItem->regResult = dest.iSdst;
112579 sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
112580 sqlite3VdbeJumpHere(v, addrTop-1);
112581 sqlite3ClearTempRegCache(pParse);
112582 }else{
@@ -112590,11 +112825,11 @@
112590 int retAddr;
112591 assert( pItem->addrFillSub==0 );
112592 pItem->regReturn = ++pParse->nMem;
112593 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
112594 pItem->addrFillSub = topAddr+1;
112595 if( pItem->isCorrelated==0 ){
112596 /* If the subquery is not correlated and if we are not inside of
112597 ** a trigger, then we only need to compute the value of the subquery
112598 ** once. */
112599 onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
112600 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
@@ -112688,11 +112923,11 @@
112688 */
112689 iEnd = sqlite3VdbeMakeLabel(v);
112690 p->nSelectRow = LARGEST_INT64;
112691 computeLimitRegisters(pParse, p, iEnd);
112692 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
112693 sqlite3VdbeGetOp(v, sSort.addrSortIndex)->opcode = OP_SorterOpen;
112694 sSort.sortFlags |= SORTFLAG_UseSorter;
112695 }
112696
112697 /* Open an ephemeral index to use for the distinct set.
112698 */
@@ -112904,11 +113139,11 @@
112904 j++;
112905 }
112906 }
112907 regBase = sqlite3GetTempRange(pParse, nCol);
112908 sqlite3ExprCacheClear(pParse);
112909 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0);
112910 j = nGroupBy;
112911 for(i=0; i<sAggInfo.nColumn; i++){
112912 struct AggInfo_col *pCol = &sAggInfo.aCol[i];
112913 if( pCol->iSorterColumn>=j ){
112914 int r1 = j + regBase;
@@ -113016,11 +113251,11 @@
113016 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
113017 VdbeComment((v, "output final row"));
113018
113019 /* Jump over the subroutines
113020 */
113021 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEnd);
113022
113023 /* Generate a subroutine that outputs a single row of the result
113024 ** set. This subroutine first looks at the iUseFlag. If iUseFlag
113025 ** is less than or equal to zero, the subroutine is a no-op. If
113026 ** the processing calls for the query to abort, this subroutine
@@ -113170,11 +113405,11 @@
113170 goto select_end;
113171 }
113172 updateAccumulator(pParse, &sAggInfo);
113173 assert( pMinMax==0 || pMinMax->nExpr==1 );
113174 if( sqlite3WhereIsOrdered(pWInfo)>0 ){
113175 sqlite3VdbeAddOp2(v, OP_Goto, 0, sqlite3WhereBreakLabel(pWInfo));
113176 VdbeComment((v, "%s() by index",
113177 (flag==WHERE_ORDERBY_MIN?"min":"max")));
113178 }
113179 sqlite3WhereEnd(pWInfo);
113180 finalizeAggFunctions(pParse, &sAggInfo);
@@ -114831,20 +115066,23 @@
114831
114832 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
114833
114834 /* There is one entry in the aRegIdx[] array for each index on the table
114835 ** being updated. Fill in aRegIdx[] with a register number that will hold
114836 ** the key for accessing each index.
 
 
114837 */
114838 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
114839 int reg;
114840 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
114841 reg = ++pParse->nMem;
114842 }else{
114843 reg = 0;
114844 for(i=0; i<pIdx->nKeyCol; i++){
114845 if( aXRef[pIdx->aiColumn[i]]>=0 ){
 
114846 reg = ++pParse->nMem;
114847 break;
114848 }
114849 }
114850 }
@@ -114940,20 +115178,21 @@
114940 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
114941 WHERE_ONEPASS_DESIRED, iIdxCur);
114942 if( pWInfo==0 ) goto update_cleanup;
114943 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
114944 for(i=0; i<nPk; i++){
 
114945 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
114946 iPk+i);
114947 }
114948 if( okOnePass ){
114949 sqlite3VdbeChangeToNoop(v, addrOpen);
114950 nKey = nPk;
114951 regKey = iPk;
114952 }else{
114953 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
114954 sqlite3IndexAffinityStr(v, pPk), nPk);
114955 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
114956 }
114957 sqlite3WhereEnd(pWInfo);
114958 }
114959
@@ -115186,11 +115425,11 @@
115186 /* Nothing to do at end-of-loop for a single-pass */
115187 }else if( pPk ){
115188 sqlite3VdbeResolveLabel(v, labelContinue);
115189 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
115190 }else{
115191 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
115192 }
115193 sqlite3VdbeResolveLabel(v, labelBreak);
115194
115195 /* Close all tables */
115196 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
@@ -115768,10 +116007,11 @@
115768 memcpy(zCopy, zName, nName+1);
115769 pMod->zName = zCopy;
115770 pMod->pModule = pModule;
115771 pMod->pAux = pAux;
115772 pMod->xDestroy = xDestroy;
 
115773 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
115774 assert( pDel==0 || pDel==pMod );
115775 if( pDel ){
115776 db->mallocFailed = 1;
115777 sqlite3DbFree(db, pDel);
@@ -115995,27 +116235,21 @@
115995 ** The string is not copied - the pointer is stored. The
115996 ** string will be freed automatically when the table is
115997 ** deleted.
115998 */
115999 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
116000 int i = pTable->nModuleArg++;
116001 int nBytes = sizeof(char *)*(1+pTable->nModuleArg);
116002 char **azModuleArg;
116003 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
116004 if( azModuleArg==0 ){
116005 int j;
116006 for(j=0; j<i; j++){
116007 sqlite3DbFree(db, pTable->azModuleArg[j]);
116008 }
116009 sqlite3DbFree(db, zArg);
116010 sqlite3DbFree(db, pTable->azModuleArg);
116011 pTable->nModuleArg = 0;
116012 }else{
 
116013 azModuleArg[i] = zArg;
116014 azModuleArg[i+1] = 0;
 
116015 }
116016 pTable->azModuleArg = azModuleArg;
116017 }
116018
116019 /*
116020 ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
116021 ** statement. The module name has been parsed, but the optional list
@@ -116138,11 +116372,11 @@
116138 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
116139 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
116140 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
116141
116142 iReg = ++pParse->nMem;
116143 sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0);
116144 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
116145 }
116146
116147 /* If we are rereading the sqlite_master table create the in-memory
116148 ** record of the table. The xConnect() method is not called until
@@ -116414,11 +116648,11 @@
116414
116415 /* If the module has been registered and includes a Create method,
116416 ** invoke it now. If the module has not been registered, return an
116417 ** error. Otherwise, do nothing.
116418 */
116419 if( !pMod ){
116420 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
116421 rc = SQLITE_ERROR;
116422 }else{
116423 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
116424 }
@@ -116516,18 +116750,21 @@
116516 Table *pTab;
116517
116518 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
116519 if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
116520 VTable *p;
 
116521 for(p=pTab->pVTable; p; p=p->pNext){
116522 assert( p->pVtab );
116523 if( p->pVtab->nRef>0 ){
116524 return SQLITE_LOCKED;
116525 }
116526 }
116527 p = vtabDisconnectAll(db, pTab);
116528 rc = p->pMod->pModule->xDestroy(p->pVtab);
 
 
116529 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
116530 if( rc==SQLITE_OK ){
116531 assert( pTab->pVTable==p && p->pNext==0 );
116532 p->pVtab = 0;
116533 pTab->pVTable = 0;
@@ -116801,10 +117038,71 @@
116801 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
116802 }else{
116803 pToplevel->db->mallocFailed = 1;
116804 }
116805 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116806
116807 /*
116808 ** Return the ON CONFLICT resolution mode in effect for the virtual
116809 ** table update operation currently in progress.
116810 **
@@ -117172,16 +117470,18 @@
117172 */
117173 struct WhereScan {
117174 WhereClause *pOrigWC; /* Original, innermost WhereClause */
117175 WhereClause *pWC; /* WhereClause currently being scanned */
117176 char *zCollName; /* Required collating sequence, if not NULL */
 
117177 char idxaff; /* Must match this affinity, if zCollName!=NULL */
117178 unsigned char nEquiv; /* Number of entries in aEquiv[] */
117179 unsigned char iEquiv; /* Next unused slot in aEquiv[] */
117180 u32 opMask; /* Acceptable operators */
117181 int k; /* Resume scanning at this->pWC->a[this->k] */
117182 int aEquiv[22]; /* Cursor,Column pairs for equivalence classes */
 
117183 };
117184
117185 /*
117186 ** An instance of the following structure holds all information about a
117187 ** WHERE clause. Mostly this is a container for one or more WhereTerms.
@@ -117361,10 +117661,11 @@
117361 SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
117362 SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
117363 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
117364 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
117365 SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
 
117366
117367
117368
117369
117370
@@ -117437,10 +117738,20 @@
117437 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117438 sqlite3StrAccumAppendAll(pStr, zColumn);
117439 sqlite3StrAccumAppend(pStr, zOp, 1);
117440 sqlite3StrAccumAppend(pStr, "?", 1);
117441 }
 
 
 
 
 
 
 
 
 
 
117442
117443 /*
117444 ** Argument pLevel describes a strategy for scanning table pTab. This
117445 ** function appends text to pStr that describes the subset of table
117446 ** rows scanned by the strategy in the form of an SQL expression.
@@ -117457,32 +117768,26 @@
117457 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117458 Index *pIndex = pLoop->u.btree.pIndex;
117459 u16 nEq = pLoop->u.btree.nEq;
117460 u16 nSkip = pLoop->nSkip;
117461 int i, j;
117462 Column *aCol = pTab->aCol;
117463 i16 *aiColumn = pIndex->aiColumn;
117464
117465 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
117466 sqlite3StrAccumAppend(pStr, " (", 2);
117467 for(i=0; i<nEq; i++){
117468 char *z = aiColumn[i] < 0 ? "rowid" : aCol[aiColumn[i]].zName;
117469 if( i>=nSkip ){
117470 explainAppendTerm(pStr, i, z, "=");
117471 }else{
117472 if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117473 sqlite3XPrintf(pStr, 0, "ANY(%s)", z);
117474 }
117475 }
117476
117477 j = i;
117478 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
117479 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
117480 explainAppendTerm(pStr, i++, z, ">");
117481 }
117482 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
117483 char *z = aiColumn[j] < 0 ? "rowid" : aCol[aiColumn[j]].zName;
117484 explainAppendTerm(pStr, i, z, "<");
117485 }
117486 sqlite3StrAccumAppend(pStr, ")", 1);
117487 }
117488
@@ -117562,23 +117867,22 @@
117562 sqlite3StrAccumAppend(&str, " USING ", 7);
117563 sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
117564 explainIndexRange(&str, pLoop, pItem->pTab);
117565 }
117566 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
117567 const char *zRange;
117568 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
117569 zRange = "(rowid=?)";
117570 }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
117571 zRange = "(rowid>? AND rowid<?)";
117572 }else if( flags&WHERE_BTM_LIMIT ){
117573 zRange = "(rowid>?)";
117574 }else{
117575 assert( flags&WHERE_TOP_LIMIT);
117576 zRange = "(rowid<?)";
117577 }
117578 sqlite3StrAccumAppendAll(&str, " USING INTEGER PRIMARY KEY ");
117579 sqlite3StrAccumAppendAll(&str, zRange);
117580 }
117581 #ifndef SQLITE_OMIT_VIRTUALTABLE
117582 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
117583 sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
117584 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
@@ -117889,11 +118193,11 @@
117889 */
117890 regBase = pParse->nMem + 1;
117891 nReg = pLoop->u.btree.nEq + nExtraReg;
117892 pParse->nMem += nReg;
117893
117894 zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
117895 if( !zAff ){
117896 pParse->db->mallocFailed = 1;
117897 }
117898
117899 if( nSkip ){
@@ -118043,18 +118347,18 @@
118043
118044 /* If this is the right table of a LEFT OUTER JOIN, allocate and
118045 ** initialize a memory cell that records if this table matches any
118046 ** row of the left table of the join.
118047 */
118048 if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
118049 pLevel->iLeftJoin = ++pParse->nMem;
118050 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
118051 VdbeComment((v, "init LEFT JOIN no-match flag"));
118052 }
118053
118054 /* Special case of a FROM clause subquery implemented as a co-routine */
118055 if( pTabItem->viaCoroutine ){
118056 int regYield = pTabItem->regReturn;
118057 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
118058 pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
118059 VdbeCoverage(v);
118060 VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
@@ -118777,11 +119081,11 @@
118777 if( pAndExpr ){
118778 pAndExpr->pLeft = 0;
118779 sqlite3ExprDelete(db, pAndExpr);
118780 }
118781 sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
118782 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrBrk);
118783 sqlite3VdbeResolveLabel(v, iLoopBody);
118784
118785 if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
118786 if( !untestedTerms ) disableTerm(pLevel, pTerm);
118787 }else
@@ -118792,11 +119096,11 @@
118792 ** scan of the entire table.
118793 */
118794 static const u8 aStep[] = { OP_Next, OP_Prev };
118795 static const u8 aStart[] = { OP_Rewind, OP_Last };
118796 assert( bRev==0 || bRev==1 );
118797 if( pTabItem->isRecursive ){
118798 /* Tables marked isRecursive have only a single row that is stored in
118799 ** a pseudo-cursor. No need to Rewind or Next such cursors. */
118800 pLevel->op = OP_Noop;
118801 }else{
118802 pLevel->op = aStep[bRev];
@@ -119699,10 +120003,55 @@
119699 }
119700 pS = pS->pPrior;
119701 }
119702 return mask;
119703 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119704
119705 /*
119706 ** The input to this routine is an WhereTerm structure with only the
119707 ** "pExpr" field filled in. The job of this routine is to analyze the
119708 ** subexpression and populate all the other fields of the WhereTerm
@@ -119770,20 +120119,23 @@
119770 pTerm->prereqAll = prereqAll;
119771 pTerm->leftCursor = -1;
119772 pTerm->iParent = -1;
119773 pTerm->eOperator = 0;
119774 if( allowedOp(op) ){
 
119775 Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
119776 Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
119777 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
119778 if( pLeft->op==TK_COLUMN ){
119779 pTerm->leftCursor = pLeft->iTable;
119780 pTerm->u.leftColumn = pLeft->iColumn;
119781 pTerm->eOperator = operatorMask(op) & opMask;
119782 }
119783 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
119784 if( pRight && pRight->op==TK_COLUMN ){
 
 
119785 WhereTerm *pNew;
119786 Expr *pDup;
119787 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
119788 if( pTerm->leftCursor>=0 ){
119789 int idxNew;
@@ -119808,12 +120160,12 @@
119808 pDup = pExpr;
119809 pNew = pTerm;
119810 }
119811 exprCommute(pParse, pDup);
119812 pLeft = sqlite3ExprSkipCollate(pDup->pLeft);
119813 pNew->leftCursor = pLeft->iTable;
119814 pNew->u.leftColumn = pLeft->iColumn;
119815 testcase( (prereqLeft | extraRight) != prereqLeft );
119816 pNew->prereqRight = prereqLeft | extraRight;
119817 pNew->prereqAll = prereqAll;
119818 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
119819 }
@@ -120152,10 +120504,50 @@
120152 int i;
120153 for(i=pWC->nTerm-1; i>=0; i--){
120154 exprAnalyze(pTabList, pWC, i);
120155 }
120156 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120157
120158 /************** End of whereexpr.c *******************************************/
120159 /************** Begin file where.c *******************************************/
120160 /*
120161 ** 2001 September 15
@@ -120328,41 +120720,44 @@
120328 ** established when the pScan object was initialized by whereScanInit().
120329 ** Return NULL if there are no more matching WhereTerms.
120330 */
120331 static WhereTerm *whereScanNext(WhereScan *pScan){
120332 int iCur; /* The cursor on the LHS of the term */
120333 int iColumn; /* The column on the LHS of the term. -1 for IPK */
120334 Expr *pX; /* An expression being tested */
120335 WhereClause *pWC; /* Shorthand for pScan->pWC */
120336 WhereTerm *pTerm; /* The term being tested */
120337 int k = pScan->k; /* Where to start scanning */
120338
120339 while( pScan->iEquiv<=pScan->nEquiv ){
120340 iCur = pScan->aEquiv[pScan->iEquiv-2];
120341 iColumn = pScan->aEquiv[pScan->iEquiv-1];
 
120342 while( (pWC = pScan->pWC)!=0 ){
120343 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
120344 if( pTerm->leftCursor==iCur
120345 && pTerm->u.leftColumn==iColumn
120346 && (pScan->iEquiv<=2 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
 
 
120347 ){
120348 if( (pTerm->eOperator & WO_EQUIV)!=0
120349 && pScan->nEquiv<ArraySize(pScan->aEquiv)
120350 ){
120351 int j;
120352 pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
120353 assert( pX->op==TK_COLUMN );
120354 for(j=0; j<pScan->nEquiv; j+=2){
120355 if( pScan->aEquiv[j]==pX->iTable
120356 && pScan->aEquiv[j+1]==pX->iColumn ){
120357 break;
120358 }
120359 }
120360 if( j==pScan->nEquiv ){
120361 pScan->aEquiv[j] = pX->iTable;
120362 pScan->aEquiv[j+1] = pX->iColumn;
120363 pScan->nEquiv += 2;
120364 }
120365 }
120366 if( (pTerm->eOperator & pScan->opMask)!=0 ){
120367 /* Verify the affinity and collating sequence match */
120368 if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
@@ -120380,12 +120775,12 @@
120380 continue;
120381 }
120382 }
120383 if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
120384 && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
120385 && pX->iTable==pScan->aEquiv[0]
120386 && pX->iColumn==pScan->aEquiv[1]
120387 ){
120388 testcase( pTerm->eOperator & WO_IS );
120389 continue;
120390 }
120391 pScan->k = k+1;
@@ -120396,11 +120791,11 @@
120396 pScan->pWC = pScan->pWC->pOuter;
120397 k = 0;
120398 }
120399 pScan->pWC = pScan->pOrigWC;
120400 k = 0;
120401 pScan->iEquiv += 2;
120402 }
120403 return 0;
120404 }
120405
120406 /*
@@ -120425,49 +120820,53 @@
120425 int iCur, /* Cursor to scan for */
120426 int iColumn, /* Column to scan for */
120427 u32 opMask, /* Operator(s) to scan for */
120428 Index *pIdx /* Must be compatible with this index */
120429 ){
120430 int j;
120431
120432 /* memset(pScan, 0, sizeof(*pScan)); */
120433 pScan->pOrigWC = pWC;
120434 pScan->pWC = pWC;
 
 
 
 
 
 
120435 if( pIdx && iColumn>=0 ){
120436 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
120437 for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
120438 if( NEVER(j>pIdx->nColumn) ) return 0;
120439 }
120440 pScan->zCollName = pIdx->azColl[j];
120441 }else{
120442 pScan->idxaff = 0;
120443 pScan->zCollName = 0;
120444 }
120445 pScan->opMask = opMask;
120446 pScan->k = 0;
120447 pScan->aEquiv[0] = iCur;
120448 pScan->aEquiv[1] = iColumn;
120449 pScan->nEquiv = 2;
120450 pScan->iEquiv = 2;
120451 return whereScanNext(pScan);
120452 }
120453
120454 /*
120455 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
120456 ** where X is a reference to the iColumn of table iCur and <op> is one of
120457 ** the WO_xx operator codes specified by the op parameter.
120458 ** Return a pointer to the term. Return 0 if not found.
 
 
 
120459 **
120460 ** The term returned might by Y=<expr> if there is another constraint in
120461 ** the WHERE clause that specifies that X=Y. Any such constraints will be
120462 ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
120463 ** aEquiv[] array holds X and all its equivalents, with each SQL variable
120464 ** taking up two slots in aEquiv[]. The first slot is for the cursor number
120465 ** and the second is for the column number. There are 22 slots in aEquiv[]
120466 ** so that means we can look for X plus up to 10 other equivalent values.
120467 ** Hence a search for X will return <expr> if X=A1 and A1=A2 and A2=A3
120468 ** and ... and A9=A10 and A10=<expr>.
120469 **
120470 ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
120471 ** then try for the one with no dependencies on <expr> - in other words where
120472 ** <expr> is a constant expression of some kind. Only return entries of
120473 ** the form "X <op> Y" where Y is a column in another table if no terms of
@@ -120531,10 +120930,29 @@
120531 }
120532 }
120533
120534 return -1;
120535 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120536
120537 /*
120538 ** Return true if the DISTINCT expression-list passed as the third argument
120539 ** is redundant.
120540 **
@@ -120582,16 +121000,13 @@
120582 ** contain a "col=X" term are subject to a NOT NULL constraint.
120583 */
120584 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120585 if( !IsUniqueIndex(pIdx) ) continue;
120586 for(i=0; i<pIdx->nKeyCol; i++){
120587 i16 iCol = pIdx->aiColumn[i];
120588 if( 0==sqlite3WhereFindTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
120589 int iIdxCol = findIndexCol(pParse, pDistinct, iBase, pIdx, i);
120590 if( iIdxCol<0 || pTab->aCol[iCol].notNull==0 ){
120591 break;
120592 }
120593 }
120594 }
120595 if( i==pIdx->nKeyCol ){
120596 /* This index implies that the DISTINCT qualifier is redundant. */
120597 return 1;
@@ -120866,11 +121281,11 @@
120866 VdbeComment((v, "for %s", pTable->zName));
120867
120868 /* Fill the automatic index with content */
120869 sqlite3ExprCachePush(pParse);
120870 pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];
120871 if( pTabItem->viaCoroutine ){
120872 int regYield = pTabItem->regReturn;
120873 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
120874 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
120875 VdbeCoverage(v);
120876 VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
@@ -120885,14 +121300,14 @@
120885 regRecord = sqlite3GetTempReg(pParse);
120886 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
120887 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
120888 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
120889 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
120890 if( pTabItem->viaCoroutine ){
120891 translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult);
120892 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
120893 pTabItem->viaCoroutine = 0;
120894 }else{
120895 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
120896 }
120897 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
120898 sqlite3VdbeJumpHere(v, addrTop);
@@ -120939,10 +121354,11 @@
120939 testcase( pTerm->eOperator & WO_ISNULL );
120940 testcase( pTerm->eOperator & WO_IS );
120941 testcase( pTerm->eOperator & WO_ALL );
120942 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
120943 if( pTerm->wtFlags & TERM_VNULL ) continue;
 
120944 nTerm++;
120945 }
120946
120947 /* If the ORDER BY clause contains only columns in the current
120948 ** virtual table then allocate space for the aOrderBy part of
@@ -120994,10 +121410,11 @@
120994 testcase( pTerm->eOperator & WO_IS );
120995 testcase( pTerm->eOperator & WO_ISNULL );
120996 testcase( pTerm->eOperator & WO_ALL );
120997 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
120998 if( pTerm->wtFlags & TERM_VNULL ) continue;
 
120999 pIdxCons[j].iColumn = pTerm->u.leftColumn;
121000 pIdxCons[j].iTermOffset = i;
121001 op = (u8)pTerm->eOperator & WO_ALL;
121002 if( op==WO_IN ) op = WO_EQ;
121003 pIdxCons[j].op = op;
@@ -121283,10 +121700,24 @@
121283 nRet -= 20; assert( 20==sqlite3LogEst(4) );
121284 }
121285 }
121286 return nRet;
121287 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121288
121289 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
121290 /*
121291 ** This function is called to estimate the number of rows visited by a
121292 ** range-scan on a skip-scan index. For example:
@@ -121334,11 +121765,11 @@
121334 sqlite3 *db = pParse->db;
121335 int nLower = -1;
121336 int nUpper = p->nSample+1;
121337 int rc = SQLITE_OK;
121338 int iCol = p->aiColumn[nEq];
121339 u8 aff = iCol>=0 ? p->pTable->aCol[iCol].affinity : SQLITE_AFF_INTEGER;
121340 CollSeq *pColl;
121341
121342 sqlite3_value *p1 = 0; /* Value extracted from pLower */
121343 sqlite3_value *p2 = 0; /* Value extracted from pUpper */
121344 sqlite3_value *pVal = 0; /* Value extracted from record */
@@ -121482,15 +121913,12 @@
121482
121483 if( pRec ){
121484 testcase( pRec->nField!=pBuilder->nRecValid );
121485 pRec->nField = pBuilder->nRecValid;
121486 }
121487 if( nEq==p->nKeyCol ){
121488 aff = SQLITE_AFF_INTEGER;
121489 }else{
121490 aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
121491 }
121492 /* Determine iLower and iUpper using ($P) only. */
121493 if( nEq==0 ){
121494 iLower = 0;
121495 iUpper = p->nRowEst0;
121496 }else{
@@ -121644,11 +122072,11 @@
121644 if( nEq>=p->nColumn ){
121645 *pnRow = 1;
121646 return SQLITE_OK;
121647 }
121648
121649 aff = p->pTable->aCol[p->aiColumn[nEq-1]].affinity;
121650 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq-1, &bOk);
121651 pBuilder->pRec = pRec;
121652 if( rc!=SQLITE_OK ) return rc;
121653 if( bOk==0 ) return SQLITE_NOTFOUND;
121654 pBuilder->nRecValid = nEq;
@@ -122071,22 +122499,24 @@
122071
122072 /* If pBuilder->pOrSet is defined, then only keep track of the costs
122073 ** and prereqs.
122074 */
122075 if( pBuilder->pOrSet!=0 ){
 
122076 #if WHERETRACE_ENABLED
122077 u16 n = pBuilder->pOrSet->n;
122078 int x =
122079 #endif
122080 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
122081 pTemplate->nOut);
122082 #if WHERETRACE_ENABLED /* 0x8 */
122083 if( sqlite3WhereTrace & 0x8 ){
122084 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
122085 whereLoopPrint(pTemplate, pBuilder->pWC);
 
 
122086 }
122087 #endif
122088 return SQLITE_OK;
122089 }
122090
122091 /* Look for an existing WhereLoop to replace with pTemplate
122092 */
@@ -122272,11 +122702,10 @@
122272 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
122273 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
122274 u16 saved_nSkip; /* Original value of pNew->nSkip */
122275 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
122276 LogEst saved_nOut; /* Original value of pNew->nOut */
122277 int iCol; /* Index of the column in the table */
122278 int rc = SQLITE_OK; /* Return code */
122279 LogEst rSize; /* Number of rows in the table */
122280 LogEst rLogSize; /* Logarithm of table size */
122281 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
122282
@@ -122285,28 +122714,27 @@
122285
122286 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
122287 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
122288 if( pNew->wsFlags & WHERE_BTM_LIMIT ){
122289 opMask = WO_LT|WO_LE;
122290 }else if( /*pProbe->tnum<=0 ||*/ (pSrc->jointype & JT_LEFT)!=0 ){
122291 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE;
122292 }else{
122293 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
122294 }
122295 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
122296
122297 assert( pNew->u.btree.nEq<pProbe->nColumn );
122298 iCol = pProbe->aiColumn[pNew->u.btree.nEq];
122299
122300 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
122301 opMask, pProbe);
122302 saved_nEq = pNew->u.btree.nEq;
122303 saved_nSkip = pNew->nSkip;
122304 saved_nLTerm = pNew->nLTerm;
122305 saved_wsFlags = pNew->wsFlags;
122306 saved_prereq = pNew->prereq;
122307 saved_nOut = pNew->nOut;
 
 
122308 pNew->rSetup = 0;
122309 rSize = pProbe->aiRowLogEst[0];
122310 rLogSize = estLog(rSize);
122311 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
122312 u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
@@ -122315,11 +122743,11 @@
122315 int nIn = 0;
122316 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
122317 int nRecValid = pBuilder->nRecValid;
122318 #endif
122319 if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
122320 && (iCol<0 || pSrc->pTab->aCol[iCol].notNull)
122321 ){
122322 continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
122323 }
122324 if( pTerm->prereqRight & pNew->maskSelf ) continue;
122325
@@ -122352,12 +122780,14 @@
122352 }
122353 assert( nIn>0 ); /* RHS always has 2 or more terms... The parser
122354 ** changes "x IN (?)" into "x=?". */
122355
122356 }else if( eOp & (WO_EQ|WO_IS) ){
 
122357 pNew->wsFlags |= WHERE_COLUMN_EQ;
122358 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
 
122359 if( iCol>=0 && pProbe->uniqNotNull==0 ){
122360 pNew->wsFlags |= WHERE_UNQ_WANTED;
122361 }else{
122362 pNew->wsFlags |= WHERE_ONEROW;
122363 }
@@ -122404,11 +122834,11 @@
122404 }else{
122405 int nEq = ++pNew->u.btree.nEq;
122406 assert( eOp & (WO_ISNULL|WO_EQ|WO_IN|WO_IS) );
122407
122408 assert( pNew->nOut==saved_nOut );
122409 if( pTerm->truthProb<=0 && iCol>=0 ){
122410 assert( (eOp & WO_IN) || nIn==0 );
122411 testcase( eOp & WO_IN );
122412 pNew->nOut += pTerm->truthProb;
122413 pNew->nOut -= nIn;
122414 }else{
@@ -122580,10 +123010,14 @@
122580 ** in the current query. Return true if it can be and false if not.
122581 */
122582 static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
122583 int i;
122584 WhereTerm *pTerm;
 
 
 
 
122585 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
122586 Expr *pExpr = pTerm->pExpr;
122587 if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab)
122588 && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
122589 ){
@@ -122655,13 +123089,13 @@
122655 pSrc = pTabList->a + pNew->iTab;
122656 pTab = pSrc->pTab;
122657 pWC = pBuilder->pWC;
122658 assert( !IsVirtual(pSrc->pTab) );
122659
122660 if( pSrc->pIndex ){
122661 /* An INDEXED BY clause specifies a particular index to use */
122662 pProbe = pSrc->pIndex;
122663 }else if( !HasRowid(pTab) ){
122664 pProbe = pTab->pIndex;
122665 }else{
122666 /* There is no INDEXED BY clause. Create a fake Index object in local
122667 ** variable sPk to represent the rowid primary key index. Make this
@@ -122677,11 +123111,11 @@
122677 sPk.pTable = pTab;
122678 sPk.szIdxRow = pTab->szTabRow;
122679 aiRowEstPk[0] = pTab->nRowLogEst;
122680 aiRowEstPk[1] = 0;
122681 pFirst = pSrc->pTab->pIndex;
122682 if( pSrc->notIndexed==0 ){
122683 /* The real indices of the table are only considered if the
122684 ** NOT INDEXED qualifier is omitted from the FROM clause */
122685 sPk.pNext = pFirst;
122686 }
122687 pProbe = &sPk;
@@ -122689,18 +123123,18 @@
122689 rSize = pTab->nRowLogEst;
122690 rLogSize = estLog(rSize);
122691
122692 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
122693 /* Automatic indexes */
122694 if( !pBuilder->pOrSet /* Not part of an OR optimization */
122695 && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
122696 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
122697 && pSrc->pIndex==0 /* Has no INDEXED BY clause */
122698 && !pSrc->notIndexed /* Has no NOT INDEXED clause */
122699 && HasRowid(pTab) /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
122700 && !pSrc->isCorrelated /* Not a correlated subquery */
122701 && !pSrc->isRecursive /* Not a recursive common table expression. */
122702 ){
122703 /* Generate auto-index WhereLoops */
122704 WhereTerm *pTerm;
122705 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
122706 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
@@ -122817,11 +123251,11 @@
122817 pBuilder->pRec = 0;
122818 #endif
122819
122820 /* If there was an INDEXED BY clause, then only that one index is
122821 ** considered. */
122822 if( pSrc->pIndex ) break;
122823 }
122824 return rc;
122825 }
122826
122827 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -123163,20 +123597,20 @@
123163 whereLoopInit(pNew);
123164 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
123165 Bitmask mUnusable = 0;
123166 pNew->iTab = iTab;
123167 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
123168 if( ((pItem->jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
123169 /* This condition is true when pItem is the FROM clause term on the
123170 ** right-hand-side of a LEFT or CROSS JOIN. */
123171 mExtra = mPrior;
123172 }
123173 priorJointype = pItem->jointype;
123174 if( IsVirtual(pItem->pTab) ){
123175 struct SrcList_item *p;
123176 for(p=&pItem[1]; p<pEnd; p++){
123177 if( mUnusable || (p->jointype & (JT_LEFT|JT_CROSS)) ){
123178 mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
123179 }
123180 }
123181 rc = whereLoopAddVirtual(pBuilder, mExtra, mUnusable);
123182 }else{
@@ -123902,11 +124336,11 @@
123902 if( pWInfo->wctrlFlags & WHERE_FORCE_TABLE ) return 0;
123903 assert( pWInfo->pTabList->nSrc>=1 );
123904 pItem = pWInfo->pTabList->a;
123905 pTab = pItem->pTab;
123906 if( IsVirtual(pTab) ) return 0;
123907 if( pItem->zIndexedBy ) return 0;
123908 iCur = pItem->iCursor;
123909 pWC = &pWInfo->sWC;
123910 pLoop = pBuilder->pNew;
123911 pLoop->wsFlags = 0;
123912 pLoop->nSkip = 0;
@@ -123927,11 +124361,11 @@
123927 || pIdx->pPartIdxWhere!=0
123928 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
123929 ) continue;
123930 opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ;
123931 for(j=0; j<pIdx->nKeyCol; j++){
123932 pTerm = sqlite3WhereFindTerm(pWC, iCur, pIdx->aiColumn[j], 0, opMask, pIdx);
123933 if( pTerm==0 ) break;
123934 testcase( pTerm->eOperator & WO_IS );
123935 pLoop->aLTerm[j] = pTerm;
123936 }
123937 if( j!=pIdx->nKeyCol ) continue;
@@ -124167,35 +124601,30 @@
124167 }
124168 }
124169
124170 /* Assign a bit from the bitmask to every term in the FROM clause.
124171 **
124172 ** When assigning bitmask values to FROM clause cursors, it must be
124173 ** the case that if X is the bitmask for the N-th FROM clause term then
124174 ** the bitmask for all FROM clause terms to the left of the N-th term
124175 ** is (X-1). An expression from the ON clause of a LEFT JOIN can use
124176 ** its Expr.iRightJoinTable value to find the bitmask of the right table
124177 ** of the join. Subtracting one from the right table bitmask gives a
124178 ** bitmask for all tables to the left of the join. Knowing the bitmask
124179 ** for all tables to the left of a left join is important. Ticket #3015.
124180 **
124181 ** Note that bitmasks are created for all pTabList->nSrc tables in
124182 ** pTabList, not just the first nTabList tables. nTabList is normally
124183 ** equal to pTabList->nSrc but might be shortened to 1 if the
124184 ** WHERE_ONETABLE_ONLY flag is set.
124185 */
124186 for(ii=0; ii<pTabList->nSrc; ii++){
124187 createMask(pMaskSet, pTabList->a[ii].iCursor);
124188 }
124189 #ifndef NDEBUG
124190 {
124191 Bitmask toTheLeft = 0;
124192 for(ii=0; ii<pTabList->nSrc; ii++){
124193 Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
124194 assert( (m-1)==toTheLeft );
124195 toTheLeft |= m;
124196 }
124197 }
124198 #endif
124199
124200 /* Analyze all of the subexpressions. */
124201 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
@@ -124289,11 +124718,11 @@
124289 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
124290 }
124291 while( pWInfo->nLevel>=2 ){
124292 WhereTerm *pTerm, *pEnd;
124293 pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
124294 if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
124295 if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
124296 && (pLoop->wsFlags & WHERE_ONEROW)==0
124297 ){
124298 break;
124299 }
@@ -124527,11 +124956,11 @@
124527 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
124528 }
124529 }
124530 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
124531 if( pLevel->addrSkip ){
124532 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
124533 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
124534 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
124535 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
124536 }
124537 if( pLevel->addrLikeRep ){
@@ -124555,11 +124984,11 @@
124555 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
124556 }
124557 if( pLevel->op==OP_Return ){
124558 sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst);
124559 }else{
124560 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
124561 }
124562 sqlite3VdbeJumpHere(v, addr);
124563 }
124564 VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
124565 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
@@ -124582,11 +125011,11 @@
124582
124583 /* For a co-routine, change all OP_Column references to the table of
124584 ** the co-routine into OP_Copy of result contained in a register.
124585 ** OP_Rowid becomes OP_Null.
124586 */
124587 if( pTabItem->viaCoroutine && !db->mallocFailed ){
124588 translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
124589 pTabItem->regResult);
124590 continue;
124591 }
124592
@@ -124816,10 +125245,33 @@
124816 ){
124817 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
124818 pOut->zStart = pPreOp->z;
124819 pOut->zEnd = pOperand->zEnd;
124820 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124821 /* Next is all token values, in a form suitable for use by makeheaders.
124822 ** This section will be null unless lemon is run with the -m switch.
124823 */
124824 /*
124825 ** These constants (all generated automatically by the parser generator)
@@ -124860,14 +125312,21 @@
124860 ** zero the stack is dynamically sized using realloc()
124861 ** sqlite3ParserARG_SDECL A static variable declaration for the %extra_argument
124862 ** sqlite3ParserARG_PDECL A parameter declaration for the %extra_argument
124863 ** sqlite3ParserARG_STORE Code to store %extra_argument into yypParser
124864 ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
 
 
124865 ** YYNSTATE the combined number of states.
124866 ** YYNRULE the number of rules in the grammar
124867 ** YYERRORSYMBOL is the code number of the error symbol. If not
124868 ** defined, then do no error processing.
 
 
 
 
 
124869 */
124870 #define YYCODETYPE unsigned char
124871 #define YYNOCODE 254
124872 #define YYACTIONTYPE unsigned short int
124873 #define YYWILDCARD 70
@@ -124896,16 +125355,21 @@
124896 #endif
124897 #define sqlite3ParserARG_SDECL Parse *pParse;
124898 #define sqlite3ParserARG_PDECL ,Parse *pParse
124899 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
124900 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
124901 #define YYNSTATE 642
124902 #define YYNRULE 327
124903 #define YYFALLBACK 1
124904 #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
124905 #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
124906 #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
 
 
 
 
 
 
 
124907
124908 /* The yyzerominor constant is used to initialize instances of
124909 ** YYMINORTYPE objects to zero. */
124910 static const YYMINORTYPE yyzerominor = { 0 };
124911
@@ -124928,20 +125392,24 @@
124928 ** action integer.
124929 **
124930 ** Suppose the action integer is N. Then the action is determined as
124931 ** follows
124932 **
124933 ** 0 <= N < YYNSTATE Shift N. That is, push the lookahead
124934 ** token onto the stack and goto state N.
124935 **
124936 ** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE.
 
124937 **
124938 ** N == YYNSTATE+YYNRULE A syntax error has occurred.
 
 
 
124939 **
124940 ** N == YYNSTATE+YYNRULE+1 The parser accepts its input.
124941 **
124942 ** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused
124943 ** slots in the yy_action[] table.
124944 **
124945 ** The action table is constructed as a single large table named yy_action[].
124946 ** Given state S and lookahead X, the action is computed as
124947 **
@@ -124967,467 +125435,450 @@
124967 ** shifting terminals.
124968 ** yy_reduce_ofst[] For each state, the offset into yy_action for
124969 ** shifting non-terminals after a reduce.
124970 ** yy_default[] Default action for each state.
124971 */
124972 #define YY_ACTTAB_COUNT (1497)
124973 static const YYACTIONTYPE yy_action[] = {
124974 /* 0 */ 306, 212, 432, 955, 639, 191, 955, 295, 559, 88,
124975 /* 10 */ 88, 88, 88, 81, 86, 86, 86, 86, 85, 85,
124976 /* 20 */ 84, 84, 84, 83, 330, 185, 184, 183, 635, 635,
124977 /* 30 */ 292, 606, 606, 88, 88, 88, 88, 683, 86, 86,
124978 /* 40 */ 86, 86, 85, 85, 84, 84, 84, 83, 330, 16,
124979 /* 50 */ 436, 597, 89, 90, 80, 600, 599, 601, 601, 87,
124980 /* 60 */ 87, 88, 88, 88, 88, 684, 86, 86, 86, 86,
124981 /* 70 */ 85, 85, 84, 84, 84, 83, 330, 306, 559, 84,
124982 /* 80 */ 84, 84, 83, 330, 65, 86, 86, 86, 86, 85,
124983 /* 90 */ 85, 84, 84, 84, 83, 330, 635, 635, 634, 633,
124984 /* 100 */ 182, 682, 550, 379, 376, 375, 17, 322, 606, 606,
124985 /* 110 */ 371, 198, 479, 91, 374, 82, 79, 165, 85, 85,
124986 /* 120 */ 84, 84, 84, 83, 330, 598, 635, 635, 107, 89,
124987 /* 130 */ 90, 80, 600, 599, 601, 601, 87, 87, 88, 88,
124988 /* 140 */ 88, 88, 186, 86, 86, 86, 86, 85, 85, 84,
124989 /* 150 */ 84, 84, 83, 330, 306, 594, 594, 142, 328, 327,
124990 /* 160 */ 484, 249, 344, 238, 635, 635, 634, 633, 585, 448,
124991 /* 170 */ 526, 525, 229, 388, 1, 394, 450, 584, 449, 635,
124992 /* 180 */ 635, 635, 635, 319, 395, 606, 606, 199, 157, 273,
124993 /* 190 */ 382, 268, 381, 187, 635, 635, 634, 633, 311, 555,
124994 /* 200 */ 266, 593, 593, 266, 347, 588, 89, 90, 80, 600,
124995 /* 210 */ 599, 601, 601, 87, 87, 88, 88, 88, 88, 478,
124996 /* 220 */ 86, 86, 86, 86, 85, 85, 84, 84, 84, 83,
124997 /* 230 */ 330, 306, 272, 536, 634, 633, 146, 610, 197, 310,
124998 /* 240 */ 575, 182, 482, 271, 379, 376, 375, 506, 21, 634,
124999 /* 250 */ 633, 634, 633, 635, 635, 374, 611, 574, 548, 440,
125000 /* 260 */ 111, 563, 606, 606, 634, 633, 324, 479, 608, 608,
125001 /* 270 */ 608, 300, 435, 573, 119, 407, 210, 162, 562, 883,
125002 /* 280 */ 592, 592, 306, 89, 90, 80, 600, 599, 601, 601,
125003 /* 290 */ 87, 87, 88, 88, 88, 88, 506, 86, 86, 86,
125004 /* 300 */ 86, 85, 85, 84, 84, 84, 83, 330, 620, 111,
125005 /* 310 */ 635, 635, 361, 606, 606, 358, 249, 349, 248, 433,
125006 /* 320 */ 243, 479, 586, 634, 633, 195, 611, 93, 119, 221,
125007 /* 330 */ 575, 497, 534, 534, 89, 90, 80, 600, 599, 601,
125008 /* 340 */ 601, 87, 87, 88, 88, 88, 88, 574, 86, 86,
125009 /* 350 */ 86, 86, 85, 85, 84, 84, 84, 83, 330, 306,
125010 /* 360 */ 77, 429, 638, 573, 589, 530, 240, 230, 242, 105,
125011 /* 370 */ 249, 349, 248, 515, 588, 208, 460, 529, 564, 173,
125012 /* 380 */ 634, 633, 970, 144, 430, 2, 424, 228, 380, 557,
125013 /* 390 */ 606, 606, 190, 153, 159, 158, 514, 51, 632, 631,
125014 /* 400 */ 630, 71, 536, 432, 954, 196, 610, 954, 614, 45,
125015 /* 410 */ 18, 89, 90, 80, 600, 599, 601, 601, 87, 87,
125016 /* 420 */ 88, 88, 88, 88, 261, 86, 86, 86, 86, 85,
125017 /* 430 */ 85, 84, 84, 84, 83, 330, 306, 608, 608, 608,
125018 /* 440 */ 542, 424, 402, 385, 241, 506, 451, 320, 211, 543,
125019 /* 450 */ 164, 436, 386, 293, 451, 587, 108, 496, 111, 334,
125020 /* 460 */ 391, 591, 424, 614, 27, 452, 453, 606, 606, 72,
125021 /* 470 */ 257, 70, 259, 452, 339, 342, 564, 582, 68, 415,
125022 /* 480 */ 469, 328, 327, 62, 614, 45, 110, 393, 89, 90,
125023 /* 490 */ 80, 600, 599, 601, 601, 87, 87, 88, 88, 88,
125024 /* 500 */ 88, 152, 86, 86, 86, 86, 85, 85, 84, 84,
125025 /* 510 */ 84, 83, 330, 306, 110, 499, 520, 538, 402, 389,
125026 /* 520 */ 424, 110, 566, 500, 593, 593, 454, 82, 79, 165,
125027 /* 530 */ 424, 591, 384, 564, 340, 615, 188, 162, 424, 350,
125028 /* 540 */ 616, 424, 614, 44, 606, 606, 445, 582, 300, 434,
125029 /* 550 */ 151, 19, 614, 9, 568, 580, 348, 615, 469, 567,
125030 /* 560 */ 614, 26, 616, 614, 45, 89, 90, 80, 600, 599,
125031 /* 570 */ 601, 601, 87, 87, 88, 88, 88, 88, 411, 86,
125032 /* 580 */ 86, 86, 86, 85, 85, 84, 84, 84, 83, 330,
125033 /* 590 */ 306, 579, 110, 578, 521, 282, 433, 398, 400, 255,
125034 /* 600 */ 486, 82, 79, 165, 487, 164, 82, 79, 165, 488,
125035 /* 610 */ 488, 364, 387, 424, 544, 544, 509, 350, 362, 155,
125036 /* 620 */ 191, 606, 606, 559, 642, 640, 333, 82, 79, 165,
125037 /* 630 */ 305, 564, 507, 312, 357, 614, 45, 329, 596, 595,
125038 /* 640 */ 194, 337, 89, 90, 80, 600, 599, 601, 601, 87,
125039 /* 650 */ 87, 88, 88, 88, 88, 424, 86, 86, 86, 86,
125040 /* 660 */ 85, 85, 84, 84, 84, 83, 330, 306, 20, 323,
125041 /* 670 */ 150, 263, 211, 543, 421, 596, 595, 614, 22, 424,
125042 /* 680 */ 193, 424, 284, 424, 391, 424, 509, 424, 577, 424,
125043 /* 690 */ 186, 335, 424, 559, 424, 313, 120, 546, 606, 606,
125044 /* 700 */ 67, 614, 47, 614, 50, 614, 48, 614, 100, 614,
125045 /* 710 */ 99, 614, 101, 576, 614, 102, 614, 109, 326, 89,
125046 /* 720 */ 90, 80, 600, 599, 601, 601, 87, 87, 88, 88,
125047 /* 730 */ 88, 88, 424, 86, 86, 86, 86, 85, 85, 84,
125048 /* 740 */ 84, 84, 83, 330, 306, 424, 311, 424, 585, 54,
125049 /* 750 */ 424, 516, 517, 590, 614, 112, 424, 584, 424, 572,
125050 /* 760 */ 424, 195, 424, 571, 424, 67, 424, 614, 94, 614,
125051 /* 770 */ 98, 424, 614, 97, 264, 606, 606, 195, 614, 46,
125052 /* 780 */ 614, 96, 614, 30, 614, 49, 614, 115, 614, 114,
125053 /* 790 */ 418, 229, 388, 614, 113, 306, 89, 90, 80, 600,
125054 /* 800 */ 599, 601, 601, 87, 87, 88, 88, 88, 88, 424,
125055 /* 810 */ 86, 86, 86, 86, 85, 85, 84, 84, 84, 83,
125056 /* 820 */ 330, 119, 424, 590, 110, 372, 606, 606, 195, 53,
125057 /* 830 */ 250, 614, 29, 195, 472, 438, 729, 190, 302, 498,
125058 /* 840 */ 14, 523, 641, 2, 614, 43, 306, 89, 90, 80,
125059 /* 850 */ 600, 599, 601, 601, 87, 87, 88, 88, 88, 88,
125060 /* 860 */ 424, 86, 86, 86, 86, 85, 85, 84, 84, 84,
125061 /* 870 */ 83, 330, 424, 613, 964, 964, 354, 606, 606, 420,
125062 /* 880 */ 312, 64, 614, 42, 391, 355, 283, 437, 301, 255,
125063 /* 890 */ 414, 410, 495, 492, 614, 28, 471, 306, 89, 90,
125064 /* 900 */ 80, 600, 599, 601, 601, 87, 87, 88, 88, 88,
125065 /* 910 */ 88, 424, 86, 86, 86, 86, 85, 85, 84, 84,
125066 /* 920 */ 84, 83, 330, 424, 110, 110, 110, 110, 606, 606,
125067 /* 930 */ 110, 254, 13, 614, 41, 532, 531, 283, 481, 531,
125068 /* 940 */ 457, 284, 119, 561, 356, 614, 40, 284, 306, 89,
125069 /* 950 */ 78, 80, 600, 599, 601, 601, 87, 87, 88, 88,
125070 /* 960 */ 88, 88, 424, 86, 86, 86, 86, 85, 85, 84,
125071 /* 970 */ 84, 84, 83, 330, 110, 424, 341, 220, 555, 606,
125072 /* 980 */ 606, 351, 555, 318, 614, 95, 413, 255, 83, 330,
125073 /* 990 */ 284, 284, 255, 640, 333, 356, 255, 614, 39, 306,
125074 /* 1000 */ 356, 90, 80, 600, 599, 601, 601, 87, 87, 88,
125075 /* 1010 */ 88, 88, 88, 424, 86, 86, 86, 86, 85, 85,
125076 /* 1020 */ 84, 84, 84, 83, 330, 424, 317, 316, 141, 465,
125077 /* 1030 */ 606, 606, 219, 619, 463, 614, 10, 417, 462, 255,
125078 /* 1040 */ 189, 510, 553, 351, 207, 363, 161, 614, 38, 315,
125079 /* 1050 */ 218, 255, 255, 80, 600, 599, 601, 601, 87, 87,
125080 /* 1060 */ 88, 88, 88, 88, 424, 86, 86, 86, 86, 85,
125081 /* 1070 */ 85, 84, 84, 84, 83, 330, 76, 419, 255, 3,
125082 /* 1080 */ 878, 461, 424, 247, 331, 331, 614, 37, 217, 76,
125083 /* 1090 */ 419, 390, 3, 216, 215, 422, 4, 331, 331, 424,
125084 /* 1100 */ 547, 12, 424, 545, 614, 36, 424, 541, 422, 424,
125085 /* 1110 */ 540, 424, 214, 424, 408, 424, 539, 403, 605, 605,
125086 /* 1120 */ 237, 614, 25, 119, 614, 24, 588, 408, 614, 45,
125087 /* 1130 */ 118, 614, 35, 614, 34, 614, 33, 614, 23, 588,
125088 /* 1140 */ 60, 223, 603, 602, 513, 378, 73, 74, 140, 139,
125089 /* 1150 */ 424, 110, 265, 75, 426, 425, 59, 424, 610, 73,
125090 /* 1160 */ 74, 549, 402, 404, 424, 373, 75, 426, 425, 604,
125091 /* 1170 */ 138, 610, 614, 11, 392, 76, 419, 181, 3, 614,
125092 /* 1180 */ 32, 271, 369, 331, 331, 493, 614, 31, 149, 608,
125093 /* 1190 */ 608, 608, 607, 15, 422, 365, 614, 8, 137, 489,
125094 /* 1200 */ 136, 190, 608, 608, 608, 607, 15, 485, 176, 135,
125095 /* 1210 */ 7, 252, 477, 408, 174, 133, 175, 474, 57, 56,
125096 /* 1220 */ 132, 130, 119, 76, 419, 588, 3, 468, 245, 464,
125097 /* 1230 */ 171, 331, 331, 125, 123, 456, 447, 122, 446, 104,
125098 /* 1240 */ 336, 231, 422, 166, 154, 73, 74, 332, 116, 431,
125099 /* 1250 */ 121, 309, 75, 426, 425, 222, 106, 610, 308, 637,
125100 /* 1260 */ 204, 408, 629, 627, 628, 6, 200, 428, 427, 290,
125101 /* 1270 */ 203, 622, 201, 588, 62, 63, 289, 66, 419, 399,
125102 /* 1280 */ 3, 401, 288, 92, 143, 331, 331, 287, 608, 608,
125103 /* 1290 */ 608, 607, 15, 73, 74, 227, 422, 325, 69, 416,
125104 /* 1300 */ 75, 426, 425, 612, 412, 610, 192, 61, 569, 209,
125105 /* 1310 */ 396, 226, 278, 225, 383, 408, 527, 558, 276, 533,
125106 /* 1320 */ 552, 528, 321, 523, 370, 508, 180, 588, 494, 179,
125107 /* 1330 */ 366, 117, 253, 269, 522, 503, 608, 608, 608, 607,
125108 /* 1340 */ 15, 551, 502, 58, 274, 524, 178, 73, 74, 304,
125109 /* 1350 */ 501, 368, 303, 206, 75, 426, 425, 491, 360, 610,
125110 /* 1360 */ 213, 177, 483, 131, 345, 298, 297, 296, 202, 294,
125111 /* 1370 */ 480, 490, 466, 134, 172, 129, 444, 346, 470, 128,
125112 /* 1380 */ 314, 459, 103, 127, 126, 148, 124, 167, 443, 235,
125113 /* 1390 */ 608, 608, 608, 607, 15, 442, 439, 623, 234, 299,
125114 /* 1400 */ 145, 583, 291, 377, 581, 160, 119, 156, 270, 636,
125115 /* 1410 */ 971, 169, 279, 626, 520, 625, 473, 624, 170, 621,
125116 /* 1420 */ 618, 119, 168, 55, 409, 423, 537, 609, 286, 285,
125117 /* 1430 */ 405, 570, 560, 556, 5, 52, 458, 554, 147, 267,
125118 /* 1440 */ 519, 504, 518, 406, 262, 239, 260, 512, 343, 511,
125119 /* 1450 */ 258, 353, 565, 256, 224, 251, 359, 277, 275, 476,
125120 /* 1460 */ 475, 246, 352, 244, 467, 455, 236, 233, 232, 307,
125121 /* 1470 */ 441, 281, 205, 163, 397, 280, 535, 505, 330, 617,
125122 /* 1480 */ 971, 971, 971, 971, 367, 971, 971, 971, 971, 971,
125123 /* 1490 */ 971, 971, 971, 971, 971, 971, 338,
 
125124 };
125125 static const YYCODETYPE yy_lookahead[] = {
125126 /* 0 */ 19, 22, 22, 23, 1, 24, 26, 15, 27, 80,
125127 /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
125128 /* 20 */ 91, 92, 93, 94, 95, 108, 109, 110, 27, 28,
125129 /* 30 */ 23, 50, 51, 80, 81, 82, 83, 122, 85, 86,
125130 /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 22,
125131 /* 50 */ 70, 23, 71, 72, 73, 74, 75, 76, 77, 78,
125132 /* 60 */ 79, 80, 81, 82, 83, 122, 85, 86, 87, 88,
125133 /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 91,
125134 /* 80 */ 92, 93, 94, 95, 26, 85, 86, 87, 88, 89,
125135 /* 90 */ 90, 91, 92, 93, 94, 95, 27, 28, 97, 98,
125136 /* 100 */ 99, 122, 211, 102, 103, 104, 79, 19, 50, 51,
125137 /* 110 */ 19, 122, 59, 55, 113, 224, 225, 226, 89, 90,
125138 /* 120 */ 91, 92, 93, 94, 95, 23, 27, 28, 26, 71,
125139 /* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125140 /* 140 */ 82, 83, 51, 85, 86, 87, 88, 89, 90, 91,
125141 /* 150 */ 92, 93, 94, 95, 19, 132, 133, 58, 89, 90,
125142 /* 160 */ 21, 108, 109, 110, 27, 28, 97, 98, 33, 100,
125143 /* 170 */ 7, 8, 119, 120, 22, 19, 107, 42, 109, 27,
125144 /* 180 */ 28, 27, 28, 95, 28, 50, 51, 99, 100, 101,
125145 /* 190 */ 102, 103, 104, 105, 27, 28, 97, 98, 107, 152,
125146 /* 200 */ 112, 132, 133, 112, 65, 69, 71, 72, 73, 74,
125147 /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 11,
125148 /* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
125149 /* 230 */ 95, 19, 101, 97, 97, 98, 24, 101, 122, 157,
125150 /* 240 */ 12, 99, 103, 112, 102, 103, 104, 152, 22, 97,
125151 /* 250 */ 98, 97, 98, 27, 28, 113, 27, 29, 91, 164,
125152 /* 260 */ 165, 124, 50, 51, 97, 98, 219, 59, 132, 133,
125153 /* 270 */ 134, 22, 23, 45, 66, 47, 212, 213, 124, 140,
125154 /* 280 */ 132, 133, 19, 71, 72, 73, 74, 75, 76, 77,
125155 /* 290 */ 78, 79, 80, 81, 82, 83, 152, 85, 86, 87,
125156 /* 300 */ 88, 89, 90, 91, 92, 93, 94, 95, 164, 165,
125157 /* 310 */ 27, 28, 230, 50, 51, 233, 108, 109, 110, 70,
125158 /* 320 */ 16, 59, 23, 97, 98, 26, 97, 22, 66, 185,
125159 /* 330 */ 12, 187, 27, 28, 71, 72, 73, 74, 75, 76,
125160 /* 340 */ 77, 78, 79, 80, 81, 82, 83, 29, 85, 86,
125161 /* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19,
125162 /* 360 */ 22, 148, 149, 45, 23, 47, 62, 154, 64, 156,
125163 /* 370 */ 108, 109, 110, 37, 69, 23, 163, 59, 26, 26,
125164 /* 380 */ 97, 98, 144, 145, 146, 147, 152, 200, 52, 23,
125165 /* 390 */ 50, 51, 26, 22, 89, 90, 60, 210, 7, 8,
125166 /* 400 */ 9, 138, 97, 22, 23, 26, 101, 26, 174, 175,
125167 /* 410 */ 197, 71, 72, 73, 74, 75, 76, 77, 78, 79,
125168 /* 420 */ 80, 81, 82, 83, 16, 85, 86, 87, 88, 89,
125169 /* 430 */ 90, 91, 92, 93, 94, 95, 19, 132, 133, 134,
125170 /* 440 */ 23, 152, 208, 209, 140, 152, 152, 111, 195, 196,
125171 /* 450 */ 98, 70, 163, 160, 152, 23, 22, 164, 165, 246,
125172 /* 460 */ 207, 27, 152, 174, 175, 171, 172, 50, 51, 137,
125173 /* 470 */ 62, 139, 64, 171, 172, 222, 124, 27, 138, 24,
125174 /* 480 */ 163, 89, 90, 130, 174, 175, 197, 163, 71, 72,
125175 /* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
125176 /* 500 */ 83, 22, 85, 86, 87, 88, 89, 90, 91, 92,
125177 /* 510 */ 93, 94, 95, 19, 197, 181, 182, 23, 208, 209,
125178 /* 520 */ 152, 197, 26, 189, 132, 133, 232, 224, 225, 226,
125179 /* 530 */ 152, 97, 91, 26, 232, 116, 212, 213, 152, 222,
125180 /* 540 */ 121, 152, 174, 175, 50, 51, 243, 97, 22, 23,
125181 /* 550 */ 22, 234, 174, 175, 177, 23, 239, 116, 163, 177,
125182 /* 560 */ 174, 175, 121, 174, 175, 71, 72, 73, 74, 75,
125183 /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 24, 85,
125184 /* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
125185 /* 590 */ 19, 23, 197, 11, 23, 227, 70, 208, 220, 152,
125186 /* 600 */ 31, 224, 225, 226, 35, 98, 224, 225, 226, 108,
125187 /* 610 */ 109, 110, 115, 152, 117, 118, 27, 222, 49, 123,
125188 /* 620 */ 24, 50, 51, 27, 0, 1, 2, 224, 225, 226,
125189 /* 630 */ 166, 124, 168, 169, 239, 174, 175, 170, 171, 172,
125190 /* 640 */ 22, 194, 71, 72, 73, 74, 75, 76, 77, 78,
125191 /* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88,
125192 /* 660 */ 89, 90, 91, 92, 93, 94, 95, 19, 22, 208,
125193 /* 670 */ 24, 23, 195, 196, 170, 171, 172, 174, 175, 152,
125194 /* 680 */ 26, 152, 152, 152, 207, 152, 97, 152, 23, 152,
125195 /* 690 */ 51, 244, 152, 97, 152, 247, 248, 23, 50, 51,
125196 /* 700 */ 26, 174, 175, 174, 175, 174, 175, 174, 175, 174,
125197 /* 710 */ 175, 174, 175, 23, 174, 175, 174, 175, 188, 71,
125198 /* 720 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125199 /* 730 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
125200 /* 740 */ 92, 93, 94, 95, 19, 152, 107, 152, 33, 24,
125201 /* 750 */ 152, 100, 101, 27, 174, 175, 152, 42, 152, 23,
125202 /* 760 */ 152, 26, 152, 23, 152, 26, 152, 174, 175, 174,
125203 /* 770 */ 175, 152, 174, 175, 23, 50, 51, 26, 174, 175,
125204 /* 780 */ 174, 175, 174, 175, 174, 175, 174, 175, 174, 175,
125205 /* 790 */ 163, 119, 120, 174, 175, 19, 71, 72, 73, 74,
125206 /* 800 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 152,
125207 /* 810 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
125208 /* 820 */ 95, 66, 152, 97, 197, 23, 50, 51, 26, 53,
125209 /* 830 */ 23, 174, 175, 26, 23, 23, 23, 26, 26, 26,
125210 /* 840 */ 36, 106, 146, 147, 174, 175, 19, 71, 72, 73,
125211 /* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
125212 /* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
125213 /* 870 */ 94, 95, 152, 196, 119, 120, 19, 50, 51, 168,
125214 /* 880 */ 169, 26, 174, 175, 207, 28, 152, 249, 250, 152,
125215 /* 890 */ 163, 163, 163, 163, 174, 175, 163, 19, 71, 72,
125216 /* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
125217 /* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
125218 /* 920 */ 93, 94, 95, 152, 197, 197, 197, 197, 50, 51,
125219 /* 930 */ 197, 194, 36, 174, 175, 191, 192, 152, 191, 192,
125220 /* 940 */ 163, 152, 66, 124, 152, 174, 175, 152, 19, 71,
125221 /* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125222 /* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
125223 /* 970 */ 92, 93, 94, 95, 197, 152, 100, 188, 152, 50,
125224 /* 980 */ 51, 152, 152, 188, 174, 175, 252, 152, 94, 95,
125225 /* 990 */ 152, 152, 152, 1, 2, 152, 152, 174, 175, 19,
125226 /* 1000 */ 152, 72, 73, 74, 75, 76, 77, 78, 79, 80,
125227 /* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
125228 /* 1020 */ 91, 92, 93, 94, 95, 152, 188, 188, 22, 194,
125229 /* 1030 */ 50, 51, 240, 173, 194, 174, 175, 252, 194, 152,
125230 /* 1040 */ 36, 181, 28, 152, 23, 219, 122, 174, 175, 219,
125231 /* 1050 */ 221, 152, 152, 73, 74, 75, 76, 77, 78, 79,
125232 /* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89,
125233 /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 152, 22,
125234 /* 1080 */ 23, 194, 152, 240, 27, 28, 174, 175, 240, 19,
125235 /* 1090 */ 20, 26, 22, 194, 194, 38, 22, 27, 28, 152,
125236 /* 1100 */ 23, 22, 152, 116, 174, 175, 152, 23, 38, 152,
125237 /* 1110 */ 23, 152, 221, 152, 57, 152, 23, 163, 50, 51,
125238 /* 1120 */ 194, 174, 175, 66, 174, 175, 69, 57, 174, 175,
125239 /* 1130 */ 40, 174, 175, 174, 175, 174, 175, 174, 175, 69,
125240 /* 1140 */ 22, 53, 74, 75, 30, 53, 89, 90, 22, 22,
125241 /* 1150 */ 152, 197, 23, 96, 97, 98, 22, 152, 101, 89,
125242 /* 1160 */ 90, 91, 208, 209, 152, 53, 96, 97, 98, 101,
125243 /* 1170 */ 22, 101, 174, 175, 152, 19, 20, 105, 22, 174,
125244 /* 1180 */ 175, 112, 19, 27, 28, 20, 174, 175, 24, 132,
125245 /* 1190 */ 133, 134, 135, 136, 38, 44, 174, 175, 107, 61,
125246 /* 1200 */ 54, 26, 132, 133, 134, 135, 136, 54, 107, 22,
125247 /* 1210 */ 5, 140, 1, 57, 36, 111, 122, 28, 79, 79,
125248 /* 1220 */ 131, 123, 66, 19, 20, 69, 22, 1, 16, 20,
125249 /* 1230 */ 125, 27, 28, 123, 111, 120, 23, 131, 23, 16,
125250 /* 1240 */ 68, 142, 38, 15, 22, 89, 90, 3, 167, 4,
125251 /* 1250 */ 248, 251, 96, 97, 98, 180, 180, 101, 251, 151,
125252 /* 1260 */ 6, 57, 151, 13, 151, 26, 25, 151, 161, 202,
125253 /* 1270 */ 153, 162, 153, 69, 130, 128, 203, 19, 20, 127,
125254 /* 1280 */ 22, 126, 204, 129, 22, 27, 28, 205, 132, 133,
125255 /* 1290 */ 134, 135, 136, 89, 90, 231, 38, 95, 137, 179,
125256 /* 1300 */ 96, 97, 98, 206, 179, 101, 122, 107, 159, 159,
125257 /* 1310 */ 125, 231, 216, 228, 107, 57, 184, 217, 216, 176,
125258 /* 1320 */ 217, 176, 48, 106, 18, 184, 158, 69, 159, 158,
125259 /* 1330 */ 46, 71, 237, 176, 176, 176, 132, 133, 134, 135,
125260 /* 1340 */ 136, 217, 176, 137, 216, 178, 158, 89, 90, 179,
125261 /* 1350 */ 176, 159, 179, 159, 96, 97, 98, 159, 159, 101,
125262 /* 1360 */ 5, 158, 202, 22, 18, 10, 11, 12, 13, 14,
125263 /* 1370 */ 190, 238, 17, 190, 158, 193, 41, 159, 202, 193,
125264 /* 1380 */ 159, 202, 245, 193, 193, 223, 190, 32, 159, 34,
125265 /* 1390 */ 132, 133, 134, 135, 136, 159, 39, 155, 43, 150,
125266 /* 1400 */ 223, 177, 201, 178, 177, 186, 66, 199, 177, 152,
125267 /* 1410 */ 253, 56, 215, 152, 182, 152, 202, 152, 63, 152,
125268 /* 1420 */ 152, 66, 67, 242, 229, 152, 174, 152, 152, 152,
125269 /* 1430 */ 152, 152, 152, 152, 199, 242, 202, 152, 198, 152,
125270 /* 1440 */ 152, 152, 183, 192, 152, 215, 152, 183, 215, 183,
125271 /* 1450 */ 152, 241, 214, 152, 211, 152, 152, 211, 211, 152,
125272 /* 1460 */ 152, 241, 152, 152, 152, 152, 152, 152, 152, 114,
125273 /* 1470 */ 152, 152, 235, 152, 152, 152, 174, 187, 95, 174,
125274 /* 1480 */ 253, 253, 253, 253, 236, 253, 253, 253, 253, 253,
125275 /* 1490 */ 253, 253, 253, 253, 253, 253, 141,
 
125276 };
125277 #define YY_SHIFT_USE_DFLT (-86)
125278 #define YY_SHIFT_COUNT (429)
125279 #define YY_SHIFT_MIN (-85)
125280 #define YY_SHIFT_MAX (1383)
125281 static const short yy_shift_ofst[] = {
125282 /* 0 */ 992, 1057, 1355, 1156, 1204, 1204, 1, 262, -19, 135,
125283 /* 10 */ 135, 776, 1204, 1204, 1204, 1204, 69, 69, 53, 208,
125284 /* 20 */ 283, 755, 58, 725, 648, 571, 494, 417, 340, 263,
125285 /* 30 */ 212, 827, 827, 827, 827, 827, 827, 827, 827, 827,
125286 /* 40 */ 827, 827, 827, 827, 827, 827, 878, 827, 929, 980,
125287 /* 50 */ 980, 1070, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125288 /* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125289 /* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125290 /* 80 */ 1258, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125291 /* 90 */ 1204, 1204, 1204, 1204, -71, -47, -47, -47, -47, -47,
125292 /* 100 */ 0, 29, -12, 283, 283, 139, 91, 392, 392, 894,
125293 /* 110 */ 672, 726, 1383, -86, -86, -86, 88, 318, 318, 99,
125294 /* 120 */ 381, -20, 283, 283, 283, 283, 283, 283, 283, 283,
125295 /* 130 */ 283, 283, 283, 283, 283, 283, 283, 283, 283, 283,
125296 /* 140 */ 283, 283, 283, 283, 624, 876, 726, 672, 1340, 1340,
125297 /* 150 */ 1340, 1340, 1340, 1340, -86, -86, -86, 305, 136, 136,
125298 /* 160 */ 142, 167, 226, 154, 137, 152, 283, 283, 283, 283,
125299 /* 170 */ 283, 283, 283, 283, 283, 283, 283, 283, 283, 283,
125300 /* 180 */ 283, 283, 283, 336, 336, 336, 283, 283, 352, 283,
125301 /* 190 */ 283, 283, 283, 283, 228, 283, 283, 283, 283, 283,
125302 /* 200 */ 283, 283, 283, 283, 283, 501, 569, 596, 596, 596,
125303 /* 210 */ 507, 497, 441, 391, 353, 156, 156, 857, 353, 857,
125304 /* 220 */ 735, 813, 639, 715, 156, 332, 715, 715, 496, 419,
125305 /* 230 */ 646, 1357, 1184, 1184, 1335, 1335, 1184, 1341, 1260, 1144,
125306 /* 240 */ 1346, 1346, 1346, 1346, 1184, 1306, 1144, 1341, 1260, 1260,
125307 /* 250 */ 1144, 1184, 1306, 1206, 1284, 1184, 1184, 1306, 1184, 1306,
125308 /* 260 */ 1184, 1306, 1262, 1207, 1207, 1207, 1274, 1262, 1207, 1217,
125309 /* 270 */ 1207, 1274, 1207, 1207, 1185, 1200, 1185, 1200, 1185, 1200,
125310 /* 280 */ 1184, 1184, 1161, 1262, 1202, 1202, 1262, 1154, 1155, 1147,
125311 /* 290 */ 1152, 1144, 1241, 1239, 1250, 1250, 1254, 1254, 1254, 1254,
125312 /* 300 */ -86, -86, -86, -86, -86, -86, 1068, 304, 526, 249,
125313 /* 310 */ 408, -83, 434, 812, 27, 811, 807, 802, 751, 589,
125314 /* 320 */ 651, 163, 131, 674, 366, 450, 299, 148, 23, 102,
125315 /* 330 */ 229, -21, 1245, 1244, 1222, 1099, 1228, 1172, 1223, 1215,
125316 /* 340 */ 1213, 1115, 1106, 1123, 1110, 1209, 1105, 1212, 1226, 1098,
125317 /* 350 */ 1089, 1140, 1139, 1104, 1189, 1178, 1094, 1211, 1205, 1187,
125318 /* 360 */ 1101, 1071, 1153, 1175, 1146, 1138, 1151, 1091, 1164, 1165,
125319 /* 370 */ 1163, 1069, 1072, 1148, 1112, 1134, 1127, 1129, 1126, 1092,
125320 /* 380 */ 1114, 1118, 1088, 1090, 1093, 1087, 1084, 987, 1079, 1077,
125321 /* 390 */ 1074, 1065, 924, 1021, 1014, 1004, 1006, 819, 739, 896,
125322 /* 400 */ 855, 804, 739, 740, 736, 690, 654, 665, 618, 582,
125323 /* 410 */ 568, 528, 554, 379, 532, 479, 455, 379, 432, 371,
125324 /* 420 */ 341, 28, 338, 116, -11, -57, -85, 7, -8, 3,
 
125325 };
125326 #define YY_REDUCE_USE_DFLT (-110)
125327 #define YY_REDUCE_COUNT (305)
125328 #define YY_REDUCE_MIN (-109)
125329 #define YY_REDUCE_MAX (1323)
125330 static const short yy_reduce_ofst[] = {
125331 /* 0 */ 238, 954, 213, 289, 310, 234, 144, 317, -109, 382,
125332 /* 10 */ 377, 303, 461, 389, 378, 368, 302, 294, 253, 395,
125333 /* 20 */ 293, 324, 403, 403, 403, 403, 403, 403, 403, 403,
125334 /* 30 */ 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
125335 /* 40 */ 403, 403, 403, 403, 403, 403, 403, 403, 403, 403,
125336 /* 50 */ 403, 1022, 1012, 1005, 998, 963, 961, 959, 957, 950,
125337 /* 60 */ 947, 930, 912, 873, 861, 823, 810, 771, 759, 720,
125338 /* 70 */ 708, 670, 657, 619, 614, 612, 610, 608, 606, 604,
125339 /* 80 */ 598, 595, 593, 580, 542, 540, 537, 535, 533, 531,
125340 /* 90 */ 529, 527, 503, 386, 403, 403, 403, 403, 403, 403,
125341 /* 100 */ 403, 403, 403, 95, 447, 82, 334, 504, 467, 403,
125342 /* 110 */ 477, 464, 403, 403, 403, 403, 860, 747, 744, 785,
125343 /* 120 */ 638, 638, 926, 891, 900, 899, 887, 844, 840, 835,
125344 /* 130 */ 848, 830, 843, 829, 792, 839, 826, 737, 838, 795,
125345 /* 140 */ 789, 47, 734, 530, 696, 777, 711, 677, 733, 730,
125346 /* 150 */ 729, 728, 727, 627, 448, 64, 187, 1305, 1302, 1252,
125347 /* 160 */ 1290, 1273, 1323, 1322, 1321, 1319, 1318, 1316, 1315, 1314,
125348 /* 170 */ 1313, 1312, 1311, 1310, 1308, 1307, 1304, 1303, 1301, 1298,
125349 /* 180 */ 1294, 1292, 1289, 1266, 1264, 1259, 1288, 1287, 1238, 1285,
125350 /* 190 */ 1281, 1280, 1279, 1278, 1251, 1277, 1276, 1275, 1273, 1268,
125351 /* 200 */ 1267, 1265, 1263, 1261, 1257, 1248, 1237, 1247, 1246, 1243,
125352 /* 210 */ 1238, 1240, 1235, 1249, 1234, 1233, 1230, 1220, 1214, 1210,
125353 /* 220 */ 1225, 1219, 1232, 1231, 1197, 1195, 1227, 1224, 1201, 1208,
125354 /* 230 */ 1242, 1137, 1236, 1229, 1193, 1181, 1221, 1177, 1196, 1179,
125355 /* 240 */ 1191, 1190, 1186, 1182, 1218, 1216, 1176, 1162, 1183, 1180,
125356 /* 250 */ 1160, 1199, 1203, 1133, 1095, 1198, 1194, 1188, 1192, 1171,
125357 /* 260 */ 1169, 1168, 1173, 1174, 1166, 1159, 1141, 1170, 1158, 1167,
125358 /* 270 */ 1157, 1132, 1145, 1143, 1124, 1128, 1103, 1102, 1100, 1096,
125359 /* 280 */ 1150, 1149, 1085, 1125, 1080, 1064, 1120, 1097, 1082, 1078,
125360 /* 290 */ 1073, 1067, 1109, 1107, 1119, 1117, 1116, 1113, 1111, 1108,
125361 /* 300 */ 1007, 1000, 1002, 1076, 1075, 1081,
 
125362 };
125363 static const YYACTIONTYPE yy_default[] = {
125364 /* 0 */ 647, 964, 964, 964, 878, 878, 969, 964, 774, 802,
125365 /* 10 */ 802, 938, 969, 969, 969, 876, 969, 969, 969, 964,
125366 /* 20 */ 969, 778, 808, 969, 969, 969, 969, 969, 969, 969,
125367 /* 30 */ 969, 937, 939, 816, 815, 918, 789, 813, 806, 810,
125368 /* 40 */ 879, 872, 873, 871, 875, 880, 969, 809, 841, 856,
125369 /* 50 */ 840, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125370 /* 60 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125371 /* 70 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125372 /* 80 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125373 /* 90 */ 969, 969, 969, 969, 850, 855, 862, 854, 851, 843,
125374 /* 100 */ 842, 844, 845, 969, 969, 673, 739, 969, 969, 846,
125375 /* 110 */ 969, 685, 847, 859, 858, 857, 680, 969, 969, 969,
125376 /* 120 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125377 /* 130 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125378 /* 140 */ 969, 969, 969, 969, 647, 964, 969, 969, 964, 964,
125379 /* 150 */ 964, 964, 964, 964, 956, 778, 768, 969, 969, 969,
125380 /* 160 */ 969, 969, 969, 969, 969, 969, 969, 944, 942, 969,
125381 /* 170 */ 891, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125382 /* 180 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125383 /* 190 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125384 /* 200 */ 969, 969, 969, 969, 653, 969, 911, 774, 774, 774,
125385 /* 210 */ 776, 754, 766, 655, 812, 791, 791, 923, 812, 923,
125386 /* 220 */ 710, 733, 707, 802, 791, 874, 802, 802, 775, 766,
125387 /* 230 */ 969, 949, 782, 782, 941, 941, 782, 821, 743, 812,
125388 /* 240 */ 750, 750, 750, 750, 782, 670, 812, 821, 743, 743,
125389 /* 250 */ 812, 782, 670, 917, 915, 782, 782, 670, 782, 670,
125390 /* 260 */ 782, 670, 884, 741, 741, 741, 725, 884, 741, 710,
125391 /* 270 */ 741, 725, 741, 741, 795, 790, 795, 790, 795, 790,
125392 /* 280 */ 782, 782, 969, 884, 888, 888, 884, 807, 796, 805,
125393 /* 290 */ 803, 812, 676, 728, 663, 663, 652, 652, 652, 652,
125394 /* 300 */ 961, 961, 956, 712, 712, 695, 969, 969, 969, 969,
125395 /* 310 */ 969, 969, 687, 969, 893, 969, 969, 969, 969, 969,
125396 /* 320 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125397 /* 330 */ 969, 828, 969, 648, 951, 969, 969, 948, 969, 969,
125398 /* 340 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125399 /* 350 */ 969, 969, 969, 969, 969, 969, 921, 969, 969, 969,
125400 /* 360 */ 969, 969, 969, 914, 913, 969, 969, 969, 969, 969,
125401 /* 370 */ 969, 969, 969, 969, 969, 969, 969, 969, 969, 969,
125402 /* 380 */ 969, 969, 969, 969, 969, 969, 969, 757, 969, 969,
125403 /* 390 */ 969, 761, 969, 969, 969, 969, 969, 969, 804, 969,
125404 /* 400 */ 797, 969, 877, 969, 969, 969, 969, 969, 969, 969,
125405 /* 410 */ 969, 969, 969, 966, 969, 969, 969, 965, 969, 969,
125406 /* 420 */ 969, 969, 969, 830, 969, 829, 833, 969, 661, 969,
125407 /* 430 */ 644, 649, 960, 963, 962, 959, 958, 957, 952, 950,
125408 /* 440 */ 947, 946, 945, 943, 940, 936, 897, 895, 902, 901,
125409 /* 450 */ 900, 899, 898, 896, 894, 892, 818, 817, 814, 811,
125410 /* 460 */ 753, 935, 890, 752, 749, 748, 669, 953, 920, 929,
125411 /* 470 */ 928, 927, 822, 926, 925, 924, 922, 919, 906, 820,
125412 /* 480 */ 819, 744, 882, 881, 672, 910, 909, 908, 912, 916,
125413 /* 490 */ 907, 784, 751, 671, 668, 675, 679, 731, 732, 740,
125414 /* 500 */ 738, 737, 736, 735, 734, 730, 681, 686, 724, 709,
125415 /* 510 */ 708, 717, 716, 722, 721, 720, 719, 718, 715, 714,
125416 /* 520 */ 713, 706, 705, 711, 704, 727, 726, 723, 703, 747,
125417 /* 530 */ 746, 745, 742, 702, 701, 700, 833, 699, 698, 838,
125418 /* 540 */ 837, 866, 826, 755, 759, 758, 762, 763, 771, 770,
125419 /* 550 */ 769, 780, 781, 793, 792, 824, 823, 794, 779, 773,
125420 /* 560 */ 772, 788, 787, 786, 785, 777, 767, 799, 798, 868,
125421 /* 570 */ 783, 867, 865, 934, 933, 932, 931, 930, 870, 967,
125422 /* 580 */ 968, 887, 889, 886, 801, 800, 885, 869, 839, 836,
125423 /* 590 */ 690, 691, 905, 904, 903, 693, 692, 689, 688, 863,
125424 /* 600 */ 860, 852, 864, 861, 853, 849, 848, 834, 832, 831,
125425 /* 610 */ 827, 835, 760, 756, 825, 765, 764, 697, 696, 694,
125426 /* 620 */ 678, 677, 674, 667, 665, 664, 666, 662, 660, 659,
125427 /* 630 */ 658, 657, 656, 684, 683, 682, 654, 651, 650, 646,
125428 /* 640 */ 645, 643,
125429 };
125430
125431 /* The next table maps tokens into fallback tokens. If a construct
125432 ** like the following:
125433 **
@@ -125522,13 +125973,17 @@
125522 ** (In other words, the "major" token.)
125523 **
125524 ** + The semantic value stored at this level of the stack. This is
125525 ** the information used by the action routines in the grammar.
125526 ** It is sometimes called the "minor" token.
 
 
 
 
125527 */
125528 struct yyStackEntry {
125529 YYACTIONTYPE stateno; /* The state-number */
125530 YYCODETYPE major; /* The major token value. This is the code
125531 ** number for the token at this stack level */
125532 YYMINORTYPE minor; /* The user-supplied minor token value. This
125533 ** is the value of the token */
125534 };
@@ -125630,22 +126085,22 @@
125630 "createkw", "temp", "ifnotexists", "dbnm",
125631 "columnlist", "conslist_opt", "table_options", "select",
125632 "column", "columnid", "type", "carglist",
125633 "typetoken", "typename", "signed", "plus_num",
125634 "minus_num", "ccons", "term", "expr",
125635 "onconf", "sortorder", "autoinc", "idxlist_opt",
125636 "refargs", "defer_subclause", "refarg", "refact",
125637 "init_deferred_pred_opt", "conslist", "tconscomma", "tcons",
125638 "idxlist", "defer_subclause_opt", "orconf", "resolvetype",
125639 "raisetype", "ifexists", "fullname", "selectnowith",
125640 "oneselect", "with", "multiselect_op", "distinct",
125641 "selcollist", "from", "where_opt", "groupby_opt",
125642 "having_opt", "orderby_opt", "limit_opt", "values",
125643 "nexprlist", "exprlist", "sclp", "as",
125644 "seltablist", "stl_prefix", "joinop", "indexed_opt",
125645 "on_opt", "using_opt", "joinop2", "idlist",
125646 "sortlist", "setlist", "insert_cmd", "inscollist_opt",
125647 "likeop", "between_op", "in_op", "case_operand",
125648 "case_exprlist", "case_else", "uniqueflag", "collate",
125649 "nmnum", "trigger_decl", "trigger_cmd_list", "trigger_time",
125650 "trigger_event", "foreach_clause", "when_clause", "trigger_cmd",
125651 "trnm", "tridxby", "database_kw_opt", "key_opt",
@@ -125722,11 +126177,11 @@
125722 /* 60 */ "ccons ::= NULL onconf",
125723 /* 61 */ "ccons ::= NOT NULL onconf",
125724 /* 62 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
125725 /* 63 */ "ccons ::= UNIQUE onconf",
125726 /* 64 */ "ccons ::= CHECK LP expr RP",
125727 /* 65 */ "ccons ::= REFERENCES nm idxlist_opt refargs",
125728 /* 66 */ "ccons ::= defer_subclause",
125729 /* 67 */ "ccons ::= COLLATE ID|STRING",
125730 /* 68 */ "autoinc ::=",
125731 /* 69 */ "autoinc ::= AUTOINCR",
125732 /* 70 */ "refargs ::=",
@@ -125750,14 +126205,14 @@
125750 /* 88 */ "conslist ::= conslist tconscomma tcons",
125751 /* 89 */ "conslist ::= tcons",
125752 /* 90 */ "tconscomma ::= COMMA",
125753 /* 91 */ "tconscomma ::=",
125754 /* 92 */ "tcons ::= CONSTRAINT nm",
125755 /* 93 */ "tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf",
125756 /* 94 */ "tcons ::= UNIQUE LP idxlist RP onconf",
125757 /* 95 */ "tcons ::= CHECK LP expr RP onconf",
125758 /* 96 */ "tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt",
125759 /* 97 */ "defer_subclause_opt ::=",
125760 /* 98 */ "defer_subclause_opt ::= defer_subclause",
125761 /* 99 */ "onconf ::=",
125762 /* 100 */ "onconf ::= ON CONFLICT resolvetype",
125763 /* 101 */ "orconf ::=",
@@ -125766,11 +126221,11 @@
125766 /* 104 */ "resolvetype ::= IGNORE",
125767 /* 105 */ "resolvetype ::= REPLACE",
125768 /* 106 */ "cmd ::= DROP TABLE ifexists fullname",
125769 /* 107 */ "ifexists ::= IF EXISTS",
125770 /* 108 */ "ifexists ::=",
125771 /* 109 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select",
125772 /* 110 */ "cmd ::= DROP VIEW ifexists fullname",
125773 /* 111 */ "cmd ::= select",
125774 /* 112 */ "select ::= with selectnowith",
125775 /* 113 */ "selectnowith ::= oneselect",
125776 /* 114 */ "selectnowith ::= selectnowith multiselect_op oneselect",
@@ -125795,199 +126250,200 @@
125795 /* 133 */ "from ::=",
125796 /* 134 */ "from ::= FROM seltablist",
125797 /* 135 */ "stl_prefix ::= seltablist joinop",
125798 /* 136 */ "stl_prefix ::=",
125799 /* 137 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
125800 /* 138 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
125801 /* 139 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
125802 /* 140 */ "dbnm ::=",
125803 /* 141 */ "dbnm ::= DOT nm",
125804 /* 142 */ "fullname ::= nm dbnm",
125805 /* 143 */ "joinop ::= COMMA|JOIN",
125806 /* 144 */ "joinop ::= JOIN_KW JOIN",
125807 /* 145 */ "joinop ::= JOIN_KW nm JOIN",
125808 /* 146 */ "joinop ::= JOIN_KW nm nm JOIN",
125809 /* 147 */ "on_opt ::= ON expr",
125810 /* 148 */ "on_opt ::=",
125811 /* 149 */ "indexed_opt ::=",
125812 /* 150 */ "indexed_opt ::= INDEXED BY nm",
125813 /* 151 */ "indexed_opt ::= NOT INDEXED",
125814 /* 152 */ "using_opt ::= USING LP idlist RP",
125815 /* 153 */ "using_opt ::=",
125816 /* 154 */ "orderby_opt ::=",
125817 /* 155 */ "orderby_opt ::= ORDER BY sortlist",
125818 /* 156 */ "sortlist ::= sortlist COMMA expr sortorder",
125819 /* 157 */ "sortlist ::= expr sortorder",
125820 /* 158 */ "sortorder ::= ASC",
125821 /* 159 */ "sortorder ::= DESC",
125822 /* 160 */ "sortorder ::=",
125823 /* 161 */ "groupby_opt ::=",
125824 /* 162 */ "groupby_opt ::= GROUP BY nexprlist",
125825 /* 163 */ "having_opt ::=",
125826 /* 164 */ "having_opt ::= HAVING expr",
125827 /* 165 */ "limit_opt ::=",
125828 /* 166 */ "limit_opt ::= LIMIT expr",
125829 /* 167 */ "limit_opt ::= LIMIT expr OFFSET expr",
125830 /* 168 */ "limit_opt ::= LIMIT expr COMMA expr",
125831 /* 169 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
125832 /* 170 */ "where_opt ::=",
125833 /* 171 */ "where_opt ::= WHERE expr",
125834 /* 172 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
125835 /* 173 */ "setlist ::= setlist COMMA nm EQ expr",
125836 /* 174 */ "setlist ::= nm EQ expr",
125837 /* 175 */ "cmd ::= with insert_cmd INTO fullname inscollist_opt select",
125838 /* 176 */ "cmd ::= with insert_cmd INTO fullname inscollist_opt DEFAULT VALUES",
125839 /* 177 */ "insert_cmd ::= INSERT orconf",
125840 /* 178 */ "insert_cmd ::= REPLACE",
125841 /* 179 */ "inscollist_opt ::=",
125842 /* 180 */ "inscollist_opt ::= LP idlist RP",
125843 /* 181 */ "idlist ::= idlist COMMA nm",
125844 /* 182 */ "idlist ::= nm",
125845 /* 183 */ "expr ::= term",
125846 /* 184 */ "expr ::= LP expr RP",
125847 /* 185 */ "term ::= NULL",
125848 /* 186 */ "expr ::= ID|INDEXED",
125849 /* 187 */ "expr ::= JOIN_KW",
125850 /* 188 */ "expr ::= nm DOT nm",
125851 /* 189 */ "expr ::= nm DOT nm DOT nm",
125852 /* 190 */ "term ::= INTEGER|FLOAT|BLOB",
125853 /* 191 */ "term ::= STRING",
125854 /* 192 */ "expr ::= VARIABLE",
125855 /* 193 */ "expr ::= expr COLLATE ID|STRING",
125856 /* 194 */ "expr ::= CAST LP expr AS typetoken RP",
125857 /* 195 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
125858 /* 196 */ "expr ::= ID|INDEXED LP STAR RP",
125859 /* 197 */ "term ::= CTIME_KW",
125860 /* 198 */ "expr ::= expr AND expr",
125861 /* 199 */ "expr ::= expr OR expr",
125862 /* 200 */ "expr ::= expr LT|GT|GE|LE expr",
125863 /* 201 */ "expr ::= expr EQ|NE expr",
125864 /* 202 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
125865 /* 203 */ "expr ::= expr PLUS|MINUS expr",
125866 /* 204 */ "expr ::= expr STAR|SLASH|REM expr",
125867 /* 205 */ "expr ::= expr CONCAT expr",
125868 /* 206 */ "likeop ::= LIKE_KW|MATCH",
125869 /* 207 */ "likeop ::= NOT LIKE_KW|MATCH",
125870 /* 208 */ "expr ::= expr likeop expr",
125871 /* 209 */ "expr ::= expr likeop expr ESCAPE expr",
125872 /* 210 */ "expr ::= expr ISNULL|NOTNULL",
125873 /* 211 */ "expr ::= expr NOT NULL",
125874 /* 212 */ "expr ::= expr IS expr",
125875 /* 213 */ "expr ::= expr IS NOT expr",
125876 /* 214 */ "expr ::= NOT expr",
125877 /* 215 */ "expr ::= BITNOT expr",
125878 /* 216 */ "expr ::= MINUS expr",
125879 /* 217 */ "expr ::= PLUS expr",
125880 /* 218 */ "between_op ::= BETWEEN",
125881 /* 219 */ "between_op ::= NOT BETWEEN",
125882 /* 220 */ "expr ::= expr between_op expr AND expr",
125883 /* 221 */ "in_op ::= IN",
125884 /* 222 */ "in_op ::= NOT IN",
125885 /* 223 */ "expr ::= expr in_op LP exprlist RP",
125886 /* 224 */ "expr ::= LP select RP",
125887 /* 225 */ "expr ::= expr in_op LP select RP",
125888 /* 226 */ "expr ::= expr in_op nm dbnm",
125889 /* 227 */ "expr ::= EXISTS LP select RP",
125890 /* 228 */ "expr ::= CASE case_operand case_exprlist case_else END",
125891 /* 229 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
125892 /* 230 */ "case_exprlist ::= WHEN expr THEN expr",
125893 /* 231 */ "case_else ::= ELSE expr",
125894 /* 232 */ "case_else ::=",
125895 /* 233 */ "case_operand ::= expr",
125896 /* 234 */ "case_operand ::=",
125897 /* 235 */ "exprlist ::= nexprlist",
125898 /* 236 */ "exprlist ::=",
125899 /* 237 */ "nexprlist ::= nexprlist COMMA expr",
125900 /* 238 */ "nexprlist ::= expr",
125901 /* 239 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt",
125902 /* 240 */ "uniqueflag ::= UNIQUE",
125903 /* 241 */ "uniqueflag ::=",
125904 /* 242 */ "idxlist_opt ::=",
125905 /* 243 */ "idxlist_opt ::= LP idxlist RP",
125906 /* 244 */ "idxlist ::= idxlist COMMA nm collate sortorder",
125907 /* 245 */ "idxlist ::= nm collate sortorder",
125908 /* 246 */ "collate ::=",
125909 /* 247 */ "collate ::= COLLATE ID|STRING",
125910 /* 248 */ "cmd ::= DROP INDEX ifexists fullname",
125911 /* 249 */ "cmd ::= VACUUM",
125912 /* 250 */ "cmd ::= VACUUM nm",
125913 /* 251 */ "cmd ::= PRAGMA nm dbnm",
125914 /* 252 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
125915 /* 253 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
125916 /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
125917 /* 255 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
125918 /* 256 */ "nmnum ::= plus_num",
125919 /* 257 */ "nmnum ::= nm",
125920 /* 258 */ "nmnum ::= ON",
125921 /* 259 */ "nmnum ::= DELETE",
125922 /* 260 */ "nmnum ::= DEFAULT",
125923 /* 261 */ "plus_num ::= PLUS INTEGER|FLOAT",
125924 /* 262 */ "plus_num ::= INTEGER|FLOAT",
125925 /* 263 */ "minus_num ::= MINUS INTEGER|FLOAT",
125926 /* 264 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
125927 /* 265 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
125928 /* 266 */ "trigger_time ::= BEFORE",
125929 /* 267 */ "trigger_time ::= AFTER",
125930 /* 268 */ "trigger_time ::= INSTEAD OF",
125931 /* 269 */ "trigger_time ::=",
125932 /* 270 */ "trigger_event ::= DELETE|INSERT",
125933 /* 271 */ "trigger_event ::= UPDATE",
125934 /* 272 */ "trigger_event ::= UPDATE OF idlist",
125935 /* 273 */ "foreach_clause ::=",
125936 /* 274 */ "foreach_clause ::= FOR EACH ROW",
125937 /* 275 */ "when_clause ::=",
125938 /* 276 */ "when_clause ::= WHEN expr",
125939 /* 277 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
125940 /* 278 */ "trigger_cmd_list ::= trigger_cmd SEMI",
125941 /* 279 */ "trnm ::= nm",
125942 /* 280 */ "trnm ::= nm DOT nm",
125943 /* 281 */ "tridxby ::=",
125944 /* 282 */ "tridxby ::= INDEXED BY nm",
125945 /* 283 */ "tridxby ::= NOT INDEXED",
125946 /* 284 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
125947 /* 285 */ "trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select",
125948 /* 286 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
125949 /* 287 */ "trigger_cmd ::= select",
125950 /* 288 */ "expr ::= RAISE LP IGNORE RP",
125951 /* 289 */ "expr ::= RAISE LP raisetype COMMA nm RP",
125952 /* 290 */ "raisetype ::= ROLLBACK",
125953 /* 291 */ "raisetype ::= ABORT",
125954 /* 292 */ "raisetype ::= FAIL",
125955 /* 293 */ "cmd ::= DROP TRIGGER ifexists fullname",
125956 /* 294 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
125957 /* 295 */ "cmd ::= DETACH database_kw_opt expr",
125958 /* 296 */ "key_opt ::=",
125959 /* 297 */ "key_opt ::= KEY expr",
125960 /* 298 */ "database_kw_opt ::= DATABASE",
125961 /* 299 */ "database_kw_opt ::=",
125962 /* 300 */ "cmd ::= REINDEX",
125963 /* 301 */ "cmd ::= REINDEX nm dbnm",
125964 /* 302 */ "cmd ::= ANALYZE",
125965 /* 303 */ "cmd ::= ANALYZE nm dbnm",
125966 /* 304 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
125967 /* 305 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
125968 /* 306 */ "add_column_fullname ::= fullname",
125969 /* 307 */ "kwcolumn_opt ::=",
125970 /* 308 */ "kwcolumn_opt ::= COLUMNKW",
125971 /* 309 */ "cmd ::= create_vtab",
125972 /* 310 */ "cmd ::= create_vtab LP vtabarglist RP",
125973 /* 311 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
125974 /* 312 */ "vtabarglist ::= vtabarg",
125975 /* 313 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
125976 /* 314 */ "vtabarg ::=",
125977 /* 315 */ "vtabarg ::= vtabarg vtabargtoken",
125978 /* 316 */ "vtabargtoken ::= ANY",
125979 /* 317 */ "vtabargtoken ::= lp anylist RP",
125980 /* 318 */ "lp ::= LP",
125981 /* 319 */ "anylist ::=",
125982 /* 320 */ "anylist ::= anylist LP anylist RP",
125983 /* 321 */ "anylist ::= anylist ANY",
125984 /* 322 */ "with ::=",
125985 /* 323 */ "with ::= WITH wqlist",
125986 /* 324 */ "with ::= WITH RECURSIVE wqlist",
125987 /* 325 */ "wqlist ::= nm idxlist_opt AS LP select RP",
125988 /* 326 */ "wqlist ::= wqlist COMMA nm idxlist_opt AS LP select RP",
 
125989 };
125990 #endif /* NDEBUG */
125991
125992
125993 #if YYSTACKDEPTH<=0
@@ -126063,13 +126519,13 @@
126063 ** Note: during a reduce, the only symbols destroyed are those
126064 ** which appear on the RHS of the rule, but which are not used
126065 ** inside the C code.
126066 */
126067 case 163: /* select */
126068 case 195: /* selectnowith */
126069 case 196: /* oneselect */
126070 case 207: /* values */
126071 {
126072 sqlite3SelectDelete(pParse->db, (yypminor->yy3));
126073 }
126074 break;
126075 case 174: /* term */
@@ -126076,53 +126532,53 @@
126076 case 175: /* expr */
126077 {
126078 sqlite3ExprDelete(pParse->db, (yypminor->yy346).pExpr);
126079 }
126080 break;
126081 case 179: /* idxlist_opt */
126082 case 188: /* idxlist */
126083 case 200: /* selcollist */
126084 case 203: /* groupby_opt */
126085 case 205: /* orderby_opt */
126086 case 208: /* nexprlist */
126087 case 209: /* exprlist */
126088 case 210: /* sclp */
126089 case 220: /* sortlist */
126090 case 221: /* setlist */
126091 case 228: /* case_exprlist */
126092 {
126093 sqlite3ExprListDelete(pParse->db, (yypminor->yy14));
126094 }
126095 break;
126096 case 194: /* fullname */
126097 case 201: /* from */
126098 case 212: /* seltablist */
126099 case 213: /* stl_prefix */
126100 {
126101 sqlite3SrcListDelete(pParse->db, (yypminor->yy65));
126102 }
126103 break;
126104 case 197: /* with */
126105 case 252: /* wqlist */
126106 {
126107 sqlite3WithDelete(pParse->db, (yypminor->yy59));
126108 }
126109 break;
126110 case 202: /* where_opt */
126111 case 204: /* having_opt */
126112 case 216: /* on_opt */
126113 case 227: /* case_operand */
126114 case 229: /* case_else */
126115 case 238: /* when_clause */
126116 case 243: /* key_opt */
126117 {
126118 sqlite3ExprDelete(pParse->db, (yypminor->yy132));
126119 }
126120 break;
126121 case 217: /* using_opt */
126122 case 219: /* idlist */
126123 case 223: /* inscollist_opt */
126124 {
126125 sqlite3IdListDelete(pParse->db, (yypminor->yy408));
126126 }
126127 break;
126128 case 234: /* trigger_cmd_list */
@@ -126218,14 +126674,14 @@
126218 YYCODETYPE iLookAhead /* The look-ahead token */
126219 ){
126220 int i;
126221 int stateno = pParser->yystack[pParser->yyidx].stateno;
126222
126223 if( stateno>YY_SHIFT_COUNT
126224 || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
126225 return yy_default[stateno];
126226 }
126227 assert( iLookAhead!=YYNOCODE );
126228 i += iLookAhead;
126229 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
126230 if( iLookAhead>0 ){
126231 #ifdef YYFALLBACK
@@ -126324,11 +126780,33 @@
126324 sqlite3ErrorMsg(pParse, "parser stack overflow");
126325 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
126326 }
126327
126328 /*
126329 ** Perform a shift action.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126330 */
126331 static void yy_shift(
126332 yyParser *yypParser, /* The parser to be shifted */
126333 int yyNewState, /* The new state to shift in */
126334 int yyMajor, /* The major token to shift in */
@@ -126357,20 +126835,11 @@
126357 #endif
126358 yytos = &yypParser->yystack[yypParser->yyidx];
126359 yytos->stateno = (YYACTIONTYPE)yyNewState;
126360 yytos->major = (YYCODETYPE)yyMajor;
126361 yytos->minor = *yypMinor;
126362 #ifndef NDEBUG
126363 if( yyTraceFILE && yypParser->yyidx>0 ){
126364 int i;
126365 fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
126366 fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
126367 for(i=1; i<=yypParser->yyidx; i++)
126368 fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
126369 fprintf(yyTraceFILE,"\n");
126370 }
126371 #endif
126372 }
126373
126374 /* The following table contains information about every rule that
126375 ** is used during the reduce.
126376 */
@@ -126473,96 +126942,97 @@
126473 { 187, 2 },
126474 { 187, 7 },
126475 { 187, 5 },
126476 { 187, 5 },
126477 { 187, 10 },
126478 { 189, 0 },
126479 { 189, 1 },
126480 { 176, 0 },
126481 { 176, 3 },
126482 { 190, 0 },
126483 { 190, 2 },
126484 { 191, 1 },
126485 { 191, 1 },
126486 { 191, 1 },
126487 { 149, 4 },
126488 { 193, 2 },
126489 { 193, 0 },
126490 { 149, 8 },
126491 { 149, 4 },
126492 { 149, 1 },
126493 { 163, 2 },
126494 { 195, 1 },
126495 { 195, 3 },
126496 { 198, 1 },
126497 { 198, 2 },
126498 { 198, 1 },
126499 { 196, 9 },
126500 { 196, 1 },
126501 { 207, 4 },
126502 { 207, 5 },
126503 { 199, 1 },
126504 { 199, 1 },
126505 { 199, 0 },
126506 { 210, 2 },
126507 { 210, 0 },
126508 { 200, 3 },
126509 { 200, 2 },
126510 { 200, 4 },
126511 { 211, 2 },
126512 { 211, 1 },
126513 { 211, 0 },
126514 { 201, 0 },
126515 { 201, 2 },
126516 { 213, 2 },
126517 { 213, 0 },
126518 { 212, 7 },
126519 { 212, 7 },
126520 { 212, 7 },
 
126521 { 159, 0 },
126522 { 159, 2 },
126523 { 194, 2 },
126524 { 214, 1 },
126525 { 214, 2 },
126526 { 214, 3 },
126527 { 214, 4 },
126528 { 216, 2 },
 
126529 { 216, 0 },
126530 { 215, 0 },
126531 { 215, 3 },
126532 { 215, 2 },
126533 { 217, 4 },
126534 { 217, 0 },
126535 { 205, 0 },
126536 { 205, 3 },
126537 { 220, 4 },
126538 { 220, 2 },
126539 { 177, 1 },
126540 { 177, 1 },
126541 { 177, 0 },
126542 { 203, 0 },
126543 { 203, 3 },
126544 { 204, 0 },
126545 { 204, 2 },
126546 { 206, 0 },
126547 { 206, 2 },
126548 { 206, 4 },
126549 { 206, 4 },
 
 
126550 { 149, 6 },
126551 { 202, 0 },
126552 { 202, 2 },
126553 { 149, 8 },
126554 { 221, 5 },
126555 { 221, 3 },
126556 { 149, 6 },
126557 { 149, 7 },
126558 { 222, 2 },
126559 { 222, 1 },
126560 { 223, 0 },
126561 { 223, 3 },
126562 { 219, 3 },
126563 { 219, 1 },
126564 { 175, 1 },
126565 { 175, 3 },
126566 { 174, 1 },
126567 { 175, 1 },
126568 { 175, 1 },
@@ -126611,21 +127081,21 @@
126611 { 228, 4 },
126612 { 229, 2 },
126613 { 229, 0 },
126614 { 227, 1 },
126615 { 227, 0 },
 
 
 
126616 { 209, 1 },
126617 { 209, 0 },
126618 { 208, 3 },
126619 { 208, 1 },
126620 { 149, 12 },
126621 { 230, 1 },
126622 { 230, 0 },
126623 { 179, 0 },
126624 { 179, 3 },
126625 { 188, 5 },
126626 { 188, 3 },
126627 { 231, 0 },
126628 { 231, 2 },
126629 { 149, 4 },
126630 { 149, 1 },
126631 { 149, 2 },
@@ -126666,13 +127136,13 @@
126666 { 239, 5 },
126667 { 239, 5 },
126668 { 239, 1 },
126669 { 175, 4 },
126670 { 175, 6 },
126671 { 192, 1 },
126672 { 192, 1 },
126673 { 192, 1 },
126674 { 149, 4 },
126675 { 149, 6 },
126676 { 149, 3 },
126677 { 243, 0 },
126678 { 243, 2 },
@@ -126698,13 +127168,13 @@
126698 { 249, 3 },
126699 { 250, 1 },
126700 { 251, 0 },
126701 { 251, 4 },
126702 { 251, 2 },
126703 { 197, 0 },
126704 { 197, 2 },
126705 { 197, 3 },
126706 { 252, 6 },
126707 { 252, 8 },
126708 };
126709
126710 static void yy_accept(yyParser*); /* Forward Declaration */
@@ -126725,12 +127195,13 @@
126725 sqlite3ParserARG_FETCH;
126726 yymsp = &yypParser->yystack[yypParser->yyidx];
126727 #ifndef NDEBUG
126728 if( yyTraceFILE && yyruleno>=0
126729 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
126730 fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
126731 yyRuleName[yyruleno]);
 
126732 }
126733 #endif /* NDEBUG */
126734
126735 /* Silence complaints from purify about yygotominor being uninitialized
126736 ** in some cases when it is copied into the stack after the following
@@ -126823,21 +127294,23 @@
126823 case 81: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==81);
126824 case 83: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==83);
126825 case 85: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==85);
126826 case 97: /* defer_subclause_opt ::= */ yytestcase(yyruleno==97);
126827 case 108: /* ifexists ::= */ yytestcase(yyruleno==108);
126828 case 218: /* between_op ::= BETWEEN */ yytestcase(yyruleno==218);
126829 case 221: /* in_op ::= IN */ yytestcase(yyruleno==221);
 
126830 {yygotominor.yy328 = 0;}
126831 break;
126832 case 29: /* ifnotexists ::= IF NOT EXISTS */
126833 case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
126834 case 69: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==69);
126835 case 84: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==84);
126836 case 107: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==107);
126837 case 219: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==219);
126838 case 222: /* in_op ::= NOT IN */ yytestcase(yyruleno==222);
 
126839 {yygotominor.yy328 = 1;}
126840 break;
126841 case 32: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
126842 {
126843 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy186,0);
@@ -126880,22 +127353,21 @@
126880 case 42: /* nm ::= JOIN_KW */ yytestcase(yyruleno==42);
126881 case 45: /* typetoken ::= typename */ yytestcase(yyruleno==45);
126882 case 48: /* typename ::= ID|STRING */ yytestcase(yyruleno==48);
126883 case 130: /* as ::= AS nm */ yytestcase(yyruleno==130);
126884 case 131: /* as ::= ID|STRING */ yytestcase(yyruleno==131);
126885 case 141: /* dbnm ::= DOT nm */ yytestcase(yyruleno==141);
126886 case 150: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==150);
126887 case 247: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==247);
126888 case 256: /* nmnum ::= plus_num */ yytestcase(yyruleno==256);
126889 case 257: /* nmnum ::= nm */ yytestcase(yyruleno==257);
126890 case 258: /* nmnum ::= ON */ yytestcase(yyruleno==258);
126891 case 259: /* nmnum ::= DELETE */ yytestcase(yyruleno==259);
126892 case 260: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==260);
126893 case 261: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==261);
126894 case 262: /* plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==262);
126895 case 263: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==263);
126896 case 279: /* trnm ::= nm */ yytestcase(yyruleno==279);
126897 {yygotominor.yy0 = yymsp[0].minor.yy0;}
126898 break;
126899 case 44: /* type ::= typetoken */
126900 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
126901 break;
@@ -126951,11 +127423,11 @@
126951 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy328,0,0,0,0);}
126952 break;
126953 case 64: /* ccons ::= CHECK LP expr RP */
126954 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy346.pExpr);}
126955 break;
126956 case 65: /* ccons ::= REFERENCES nm idxlist_opt refargs */
126957 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy14,yymsp[0].minor.yy328);}
126958 break;
126959 case 66: /* ccons ::= defer_subclause */
126960 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy328);}
126961 break;
@@ -127006,20 +127478,20 @@
127006 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
127007 break;
127008 case 90: /* tconscomma ::= COMMA */
127009 {pParse->constraintName.n = 0;}
127010 break;
127011 case 93: /* tcons ::= PRIMARY KEY LP idxlist autoinc RP onconf */
127012 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy14,yymsp[0].minor.yy328,yymsp[-2].minor.yy328,0);}
127013 break;
127014 case 94: /* tcons ::= UNIQUE LP idxlist RP onconf */
127015 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy14,yymsp[0].minor.yy328,0,0,0,0);}
127016 break;
127017 case 95: /* tcons ::= CHECK LP expr RP onconf */
127018 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy346.pExpr);}
127019 break;
127020 case 96: /* tcons ::= FOREIGN KEY LP idxlist RP REFERENCES nm idxlist_opt refargs defer_subclause_opt */
127021 {
127022 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy14, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[-1].minor.yy328);
127023 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy328);
127024 }
127025 break;
@@ -127041,13 +127513,13 @@
127041 case 106: /* cmd ::= DROP TABLE ifexists fullname */
127042 {
127043 sqlite3DropTable(pParse, yymsp[0].minor.yy65, 0, yymsp[-1].minor.yy328);
127044 }
127045 break;
127046 case 109: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm AS select */
127047 {
127048 sqlite3CreateView(pParse, &yymsp[-7].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, yymsp[0].minor.yy3, yymsp[-6].minor.yy328, yymsp[-4].minor.yy328);
127049 }
127050 break;
127051 case 110: /* cmd ::= DROP VIEW ifexists fullname */
127052 {
127053 sqlite3DropTable(pParse, yymsp[0].minor.yy65, 1, yymsp[-1].minor.yy328);
@@ -127160,18 +127632,18 @@
127160 break;
127161 case 124: /* distinct ::= */
127162 {yygotominor.yy381 = 0;}
127163 break;
127164 case 125: /* sclp ::= selcollist COMMA */
127165 case 243: /* idxlist_opt ::= LP idxlist RP */ yytestcase(yyruleno==243);
127166 {yygotominor.yy14 = yymsp[-1].minor.yy14;}
127167 break;
127168 case 126: /* sclp ::= */
127169 case 154: /* orderby_opt ::= */ yytestcase(yyruleno==154);
127170 case 161: /* groupby_opt ::= */ yytestcase(yyruleno==161);
127171 case 236: /* exprlist ::= */ yytestcase(yyruleno==236);
127172 case 242: /* idxlist_opt ::= */ yytestcase(yyruleno==242);
127173 {yygotominor.yy14 = 0;}
127174 break;
127175 case 127: /* selcollist ::= sclp expr as */
127176 {
127177 yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy14, yymsp[-1].minor.yy346.pExpr);
@@ -127206,11 +127678,11 @@
127206 }
127207 break;
127208 case 135: /* stl_prefix ::= seltablist joinop */
127209 {
127210 yygotominor.yy65 = yymsp[-1].minor.yy65;
127211 if( ALWAYS(yygotominor.yy65 && yygotominor.yy65->nSrc>0) ) yygotominor.yy65->a[yygotominor.yy65->nSrc-1].jointype = (u8)yymsp[0].minor.yy328;
127212 }
127213 break;
127214 case 136: /* stl_prefix ::= */
127215 {yygotominor.yy65 = 0;}
127216 break;
@@ -127218,16 +127690,22 @@
127218 {
127219 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127220 sqlite3SrcListIndexedBy(pParse, yygotominor.yy65, &yymsp[-2].minor.yy0);
127221 }
127222 break;
127223 case 138: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
 
 
 
 
 
 
127224 {
127225 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy3,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127226 }
127227 break;
127228 case 139: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
127229 {
127230 if( yymsp[-6].minor.yy65==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy132==0 && yymsp[0].minor.yy408==0 ){
127231 yygotominor.yy65 = yymsp[-4].minor.yy65;
127232 }else if( yymsp[-4].minor.yy65->nSrc==1 ){
127233 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
@@ -127247,175 +127725,177 @@
127247 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy65,0,0,0,0,SF_NestedFrom,0,0);
127248 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127249 }
127250 }
127251 break;
127252 case 140: /* dbnm ::= */
127253 case 149: /* indexed_opt ::= */ yytestcase(yyruleno==149);
127254 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
127255 break;
127256 case 142: /* fullname ::= nm dbnm */
127257 {yygotominor.yy65 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
127258 break;
127259 case 143: /* joinop ::= COMMA|JOIN */
127260 { yygotominor.yy328 = JT_INNER; }
127261 break;
127262 case 144: /* joinop ::= JOIN_KW JOIN */
127263 { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
127264 break;
127265 case 145: /* joinop ::= JOIN_KW nm JOIN */
127266 { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
127267 break;
127268 case 146: /* joinop ::= JOIN_KW nm nm JOIN */
127269 { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
127270 break;
127271 case 147: /* on_opt ::= ON expr */
127272 case 164: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==164);
127273 case 171: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==171);
127274 case 231: /* case_else ::= ELSE expr */ yytestcase(yyruleno==231);
127275 case 233: /* case_operand ::= expr */ yytestcase(yyruleno==233);
127276 {yygotominor.yy132 = yymsp[0].minor.yy346.pExpr;}
127277 break;
127278 case 148: /* on_opt ::= */
127279 case 163: /* having_opt ::= */ yytestcase(yyruleno==163);
127280 case 170: /* where_opt ::= */ yytestcase(yyruleno==170);
127281 case 232: /* case_else ::= */ yytestcase(yyruleno==232);
127282 case 234: /* case_operand ::= */ yytestcase(yyruleno==234);
127283 {yygotominor.yy132 = 0;}
127284 break;
127285 case 151: /* indexed_opt ::= NOT INDEXED */
127286 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
127287 break;
127288 case 152: /* using_opt ::= USING LP idlist RP */
127289 case 180: /* inscollist_opt ::= LP idlist RP */ yytestcase(yyruleno==180);
127290 {yygotominor.yy408 = yymsp[-1].minor.yy408;}
127291 break;
127292 case 153: /* using_opt ::= */
127293 case 179: /* inscollist_opt ::= */ yytestcase(yyruleno==179);
127294 {yygotominor.yy408 = 0;}
127295 break;
127296 case 155: /* orderby_opt ::= ORDER BY sortlist */
127297 case 162: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==162);
127298 case 235: /* exprlist ::= nexprlist */ yytestcase(yyruleno==235);
127299 {yygotominor.yy14 = yymsp[0].minor.yy14;}
127300 break;
127301 case 156: /* sortlist ::= sortlist COMMA expr sortorder */
127302 {
127303 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy14,yymsp[-1].minor.yy346.pExpr);
127304 if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
127305 }
127306 break;
127307 case 157: /* sortlist ::= expr sortorder */
127308 {
127309 yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy346.pExpr);
127310 if( yygotominor.yy14 && ALWAYS(yygotominor.yy14->a) ) yygotominor.yy14->a[0].sortOrder = (u8)yymsp[0].minor.yy328;
127311 }
127312 break;
127313 case 158: /* sortorder ::= ASC */
127314 case 160: /* sortorder ::= */ yytestcase(yyruleno==160);
127315 {yygotominor.yy328 = SQLITE_SO_ASC;}
127316 break;
127317 case 159: /* sortorder ::= DESC */
127318 {yygotominor.yy328 = SQLITE_SO_DESC;}
127319 break;
127320 case 165: /* limit_opt ::= */
 
 
 
127321 {yygotominor.yy476.pLimit = 0; yygotominor.yy476.pOffset = 0;}
127322 break;
127323 case 166: /* limit_opt ::= LIMIT expr */
127324 {yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr; yygotominor.yy476.pOffset = 0;}
127325 break;
127326 case 167: /* limit_opt ::= LIMIT expr OFFSET expr */
127327 {yygotominor.yy476.pLimit = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pOffset = yymsp[0].minor.yy346.pExpr;}
127328 break;
127329 case 168: /* limit_opt ::= LIMIT expr COMMA expr */
127330 {yygotominor.yy476.pOffset = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr;}
127331 break;
127332 case 169: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
127333 {
127334 sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
127335 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy65, &yymsp[-1].minor.yy0);
127336 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy65,yymsp[0].minor.yy132);
127337 }
127338 break;
127339 case 172: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
127340 {
127341 sqlite3WithPush(pParse, yymsp[-7].minor.yy59, 1);
127342 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy65, &yymsp[-3].minor.yy0);
127343 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy14,"set list");
127344 sqlite3Update(pParse,yymsp[-4].minor.yy65,yymsp[-1].minor.yy14,yymsp[0].minor.yy132,yymsp[-5].minor.yy186);
127345 }
127346 break;
127347 case 173: /* setlist ::= setlist COMMA nm EQ expr */
127348 {
127349 yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy14, yymsp[0].minor.yy346.pExpr);
127350 sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127351 }
127352 break;
127353 case 174: /* setlist ::= nm EQ expr */
127354 {
127355 yygotominor.yy14 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy346.pExpr);
127356 sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127357 }
127358 break;
127359 case 175: /* cmd ::= with insert_cmd INTO fullname inscollist_opt select */
127360 {
127361 sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
127362 sqlite3Insert(pParse, yymsp[-2].minor.yy65, yymsp[0].minor.yy3, yymsp[-1].minor.yy408, yymsp[-4].minor.yy186);
127363 }
127364 break;
127365 case 176: /* cmd ::= with insert_cmd INTO fullname inscollist_opt DEFAULT VALUES */
127366 {
127367 sqlite3WithPush(pParse, yymsp[-6].minor.yy59, 1);
127368 sqlite3Insert(pParse, yymsp[-3].minor.yy65, 0, yymsp[-2].minor.yy408, yymsp[-5].minor.yy186);
127369 }
127370 break;
127371 case 177: /* insert_cmd ::= INSERT orconf */
127372 {yygotominor.yy186 = yymsp[0].minor.yy186;}
127373 break;
127374 case 178: /* insert_cmd ::= REPLACE */
127375 {yygotominor.yy186 = OE_Replace;}
127376 break;
127377 case 181: /* idlist ::= idlist COMMA nm */
127378 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy408,&yymsp[0].minor.yy0);}
127379 break;
127380 case 182: /* idlist ::= nm */
127381 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
127382 break;
127383 case 183: /* expr ::= term */
127384 {yygotominor.yy346 = yymsp[0].minor.yy346;}
127385 break;
127386 case 184: /* expr ::= LP expr RP */
127387 {yygotominor.yy346.pExpr = yymsp[-1].minor.yy346.pExpr; spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
127388 break;
127389 case 185: /* term ::= NULL */
127390 case 190: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==190);
127391 case 191: /* term ::= STRING */ yytestcase(yyruleno==191);
127392 {spanExpr(&yygotominor.yy346, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
127393 break;
127394 case 186: /* expr ::= ID|INDEXED */
127395 case 187: /* expr ::= JOIN_KW */ yytestcase(yyruleno==187);
127396 {spanExpr(&yygotominor.yy346, pParse, TK_ID, &yymsp[0].minor.yy0);}
127397 break;
127398 case 188: /* expr ::= nm DOT nm */
127399 {
127400 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
127401 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
127402 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
127403 spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
127404 }
127405 break;
127406 case 189: /* expr ::= nm DOT nm DOT nm */
127407 {
127408 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
127409 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
127410 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
127411 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
127412 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
127413 spanSet(&yygotominor.yy346,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
127414 }
127415 break;
127416 case 192: /* expr ::= VARIABLE */
127417 {
127418 if( yymsp[0].minor.yy0.n>=2 && yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1]) ){
127419 /* When doing a nested parse, one can include terms in an expression
127420 ** that look like this: #1 #2 ... These terms refer to registers
127421 ** in the virtual machine. #N is the N-th register. */
@@ -127431,24 +127911,24 @@
127431 sqlite3ExprAssignVarNumber(pParse, yygotominor.yy346.pExpr);
127432 }
127433 spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
127434 }
127435 break;
127436 case 193: /* expr ::= expr COLLATE ID|STRING */
127437 {
127438 yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0, 1);
127439 yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
127440 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127441 }
127442 break;
127443 case 194: /* expr ::= CAST LP expr AS typetoken RP */
127444 {
127445 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy346.pExpr, 0, &yymsp[-1].minor.yy0);
127446 spanSet(&yygotominor.yy346,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
127447 }
127448 break;
127449 case 195: /* expr ::= ID|INDEXED LP distinct exprlist RP */
127450 {
127451 if( yymsp[-1].minor.yy14 && yymsp[-1].minor.yy14->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
127452 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
127453 }
127454 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy14, &yymsp[-4].minor.yy0);
@@ -127456,39 +127936,39 @@
127456 if( yymsp[-2].minor.yy381==SF_Distinct && yygotominor.yy346.pExpr ){
127457 yygotominor.yy346.pExpr->flags |= EP_Distinct;
127458 }
127459 }
127460 break;
127461 case 196: /* expr ::= ID|INDEXED LP STAR RP */
127462 {
127463 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
127464 spanSet(&yygotominor.yy346,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
127465 }
127466 break;
127467 case 197: /* term ::= CTIME_KW */
127468 {
127469 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
127470 spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
127471 }
127472 break;
127473 case 198: /* expr ::= expr AND expr */
127474 case 199: /* expr ::= expr OR expr */ yytestcase(yyruleno==199);
127475 case 200: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==200);
127476 case 201: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==201);
127477 case 202: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==202);
127478 case 203: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==203);
127479 case 204: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==204);
127480 case 205: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==205);
127481 {spanBinaryExpr(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);}
127482 break;
127483 case 206: /* likeop ::= LIKE_KW|MATCH */
127484 {yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 0;}
127485 break;
127486 case 207: /* likeop ::= NOT LIKE_KW|MATCH */
127487 {yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 1;}
127488 break;
127489 case 208: /* expr ::= expr likeop expr */
127490 {
127491 ExprList *pList;
127492 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy346.pExpr);
127493 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy346.pExpr);
127494 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy96.eOperator);
@@ -127496,11 +127976,11 @@
127496 yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
127497 yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127498 if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
127499 }
127500 break;
127501 case 209: /* expr ::= expr likeop expr ESCAPE expr */
127502 {
127503 ExprList *pList;
127504 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
127505 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy346.pExpr);
127506 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
@@ -127509,39 +127989,39 @@
127509 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127510 yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127511 if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
127512 }
127513 break;
127514 case 210: /* expr ::= expr ISNULL|NOTNULL */
127515 {spanUnaryPostfix(&yygotominor.yy346,pParse,yymsp[0].major,&yymsp[-1].minor.yy346,&yymsp[0].minor.yy0);}
127516 break;
127517 case 211: /* expr ::= expr NOT NULL */
127518 {spanUnaryPostfix(&yygotominor.yy346,pParse,TK_NOTNULL,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy0);}
127519 break;
127520 case 212: /* expr ::= expr IS expr */
127521 {
127522 spanBinaryExpr(&yygotominor.yy346,pParse,TK_IS,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);
127523 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_ISNULL);
127524 }
127525 break;
127526 case 213: /* expr ::= expr IS NOT expr */
127527 {
127528 spanBinaryExpr(&yygotominor.yy346,pParse,TK_ISNOT,&yymsp[-3].minor.yy346,&yymsp[0].minor.yy346);
127529 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_NOTNULL);
127530 }
127531 break;
127532 case 214: /* expr ::= NOT expr */
127533 case 215: /* expr ::= BITNOT expr */ yytestcase(yyruleno==215);
127534 {spanUnaryPrefix(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
127535 break;
127536 case 216: /* expr ::= MINUS expr */
127537 {spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UMINUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
127538 break;
127539 case 217: /* expr ::= PLUS expr */
127540 {spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UPLUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
127541 break;
127542 case 220: /* expr ::= expr between_op expr AND expr */
127543 {
127544 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
127545 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
127546 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy346.pExpr, 0, 0);
127547 if( yygotominor.yy346.pExpr ){
@@ -127552,11 +128032,11 @@
127552 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
127553 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127554 yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127555 }
127556 break;
127557 case 223: /* expr ::= expr in_op LP exprlist RP */
127558 {
127559 if( yymsp[-1].minor.yy14==0 ){
127560 /* Expressions of the form
127561 **
127562 ** expr1 IN ()
@@ -127606,11 +128086,11 @@
127606 }
127607 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127608 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127609 }
127610 break;
127611 case 224: /* expr ::= LP select RP */
127612 {
127613 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
127614 if( yygotominor.yy346.pExpr ){
127615 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
127616 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
@@ -127620,11 +128100,11 @@
127620 }
127621 yygotominor.yy346.zStart = yymsp[-2].minor.yy0.z;
127622 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127623 }
127624 break;
127625 case 225: /* expr ::= expr in_op LP select RP */
127626 {
127627 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
127628 if( yygotominor.yy346.pExpr ){
127629 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
127630 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
@@ -127635,11 +128115,11 @@
127635 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
127636 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127637 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127638 }
127639 break;
127640 case 226: /* expr ::= expr in_op nm dbnm */
127641 {
127642 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
127643 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy346.pExpr, 0, 0);
127644 if( yygotominor.yy346.pExpr ){
127645 yygotominor.yy346.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
@@ -127651,11 +128131,11 @@
127651 if( yymsp[-2].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
127652 yygotominor.yy346.zStart = yymsp[-3].minor.yy346.zStart;
127653 yygotominor.yy346.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
127654 }
127655 break;
127656 case 227: /* expr ::= EXISTS LP select RP */
127657 {
127658 Expr *p = yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
127659 if( p ){
127660 p->x.pSelect = yymsp[-1].minor.yy3;
127661 ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
@@ -127665,11 +128145,11 @@
127665 }
127666 yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
127667 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127668 }
127669 break;
127670 case 228: /* expr ::= CASE case_operand case_exprlist case_else END */
127671 {
127672 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy132, 0, 0);
127673 if( yygotominor.yy346.pExpr ){
127674 yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy132 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[-1].minor.yy132) : yymsp[-2].minor.yy14;
127675 sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
@@ -127679,274 +128159,263 @@
127679 }
127680 yygotominor.yy346.zStart = yymsp[-4].minor.yy0.z;
127681 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127682 }
127683 break;
127684 case 229: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
127685 {
127686 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, yymsp[-2].minor.yy346.pExpr);
127687 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
127688 }
127689 break;
127690 case 230: /* case_exprlist ::= WHEN expr THEN expr */
127691 {
127692 yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
127693 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
127694 }
127695 break;
127696 case 237: /* nexprlist ::= nexprlist COMMA expr */
127697 {yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[0].minor.yy346.pExpr);}
127698 break;
127699 case 238: /* nexprlist ::= expr */
127700 {yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy346.pExpr);}
127701 break;
127702 case 239: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP where_opt */
127703 {
127704 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
127705 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy328,
127706 &yymsp[-11].minor.yy0, yymsp[0].minor.yy132, SQLITE_SO_ASC, yymsp[-8].minor.yy328);
127707 }
127708 break;
127709 case 240: /* uniqueflag ::= UNIQUE */
127710 case 291: /* raisetype ::= ABORT */ yytestcase(yyruleno==291);
127711 {yygotominor.yy328 = OE_Abort;}
127712 break;
127713 case 241: /* uniqueflag ::= */
127714 {yygotominor.yy328 = OE_None;}
127715 break;
127716 case 244: /* idxlist ::= idxlist COMMA nm collate sortorder */
127717 {
127718 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
127719 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, p);
127720 sqlite3ExprListSetName(pParse,yygotominor.yy14,&yymsp[-2].minor.yy0,1);
127721 sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
127722 if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
127723 }
127724 break;
127725 case 245: /* idxlist ::= nm collate sortorder */
127726 {
127727 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
127728 yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, p);
127729 sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127730 sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
127731 if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
127732 }
127733 break;
127734 case 246: /* collate ::= */
127735 {yygotominor.yy0.z = 0; yygotominor.yy0.n = 0;}
127736 break;
127737 case 248: /* cmd ::= DROP INDEX ifexists fullname */
127738 {sqlite3DropIndex(pParse, yymsp[0].minor.yy65, yymsp[-1].minor.yy328);}
127739 break;
127740 case 249: /* cmd ::= VACUUM */
127741 case 250: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==250);
127742 {sqlite3Vacuum(pParse);}
127743 break;
127744 case 251: /* cmd ::= PRAGMA nm dbnm */
127745 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
127746 break;
127747 case 252: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
127748 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
127749 break;
127750 case 253: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
127751 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
127752 break;
127753 case 254: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
127754 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
127755 break;
127756 case 255: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
127757 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
127758 break;
127759 case 264: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
127760 {
127761 Token all;
127762 all.z = yymsp[-3].minor.yy0.z;
127763 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
127764 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy473, &all);
127765 }
127766 break;
127767 case 265: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
127768 {
127769 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy328, yymsp[-4].minor.yy378.a, yymsp[-4].minor.yy378.b, yymsp[-2].minor.yy65, yymsp[0].minor.yy132, yymsp[-10].minor.yy328, yymsp[-8].minor.yy328);
127770 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
127771 }
127772 break;
127773 case 266: /* trigger_time ::= BEFORE */
127774 case 269: /* trigger_time ::= */ yytestcase(yyruleno==269);
127775 { yygotominor.yy328 = TK_BEFORE; }
127776 break;
127777 case 267: /* trigger_time ::= AFTER */
127778 { yygotominor.yy328 = TK_AFTER; }
127779 break;
127780 case 268: /* trigger_time ::= INSTEAD OF */
127781 { yygotominor.yy328 = TK_INSTEAD;}
127782 break;
127783 case 270: /* trigger_event ::= DELETE|INSERT */
127784 case 271: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==271);
127785 {yygotominor.yy378.a = yymsp[0].major; yygotominor.yy378.b = 0;}
127786 break;
127787 case 272: /* trigger_event ::= UPDATE OF idlist */
127788 {yygotominor.yy378.a = TK_UPDATE; yygotominor.yy378.b = yymsp[0].minor.yy408;}
127789 break;
127790 case 275: /* when_clause ::= */
127791 case 296: /* key_opt ::= */ yytestcase(yyruleno==296);
127792 { yygotominor.yy132 = 0; }
127793 break;
127794 case 276: /* when_clause ::= WHEN expr */
127795 case 297: /* key_opt ::= KEY expr */ yytestcase(yyruleno==297);
127796 { yygotominor.yy132 = yymsp[0].minor.yy346.pExpr; }
127797 break;
127798 case 277: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
127799 {
127800 assert( yymsp[-2].minor.yy473!=0 );
127801 yymsp[-2].minor.yy473->pLast->pNext = yymsp[-1].minor.yy473;
127802 yymsp[-2].minor.yy473->pLast = yymsp[-1].minor.yy473;
127803 yygotominor.yy473 = yymsp[-2].minor.yy473;
127804 }
127805 break;
127806 case 278: /* trigger_cmd_list ::= trigger_cmd SEMI */
127807 {
127808 assert( yymsp[-1].minor.yy473!=0 );
127809 yymsp[-1].minor.yy473->pLast = yymsp[-1].minor.yy473;
127810 yygotominor.yy473 = yymsp[-1].minor.yy473;
127811 }
127812 break;
127813 case 280: /* trnm ::= nm DOT nm */
127814 {
127815 yygotominor.yy0 = yymsp[0].minor.yy0;
127816 sqlite3ErrorMsg(pParse,
127817 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
127818 "statements within triggers");
127819 }
127820 break;
127821 case 282: /* tridxby ::= INDEXED BY nm */
127822 {
127823 sqlite3ErrorMsg(pParse,
127824 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
127825 "within triggers");
127826 }
127827 break;
127828 case 283: /* tridxby ::= NOT INDEXED */
127829 {
127830 sqlite3ErrorMsg(pParse,
127831 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
127832 "within triggers");
127833 }
127834 break;
127835 case 284: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
127836 { yygotominor.yy473 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy14, yymsp[0].minor.yy132, yymsp[-5].minor.yy186); }
127837 break;
127838 case 285: /* trigger_cmd ::= insert_cmd INTO trnm inscollist_opt select */
127839 {yygotominor.yy473 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy408, yymsp[0].minor.yy3, yymsp[-4].minor.yy186);}
127840 break;
127841 case 286: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
127842 {yygotominor.yy473 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy132);}
127843 break;
127844 case 287: /* trigger_cmd ::= select */
127845 {yygotominor.yy473 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy3); }
127846 break;
127847 case 288: /* expr ::= RAISE LP IGNORE RP */
127848 {
127849 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
127850 if( yygotominor.yy346.pExpr ){
127851 yygotominor.yy346.pExpr->affinity = OE_Ignore;
127852 }
127853 yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
127854 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127855 }
127856 break;
127857 case 289: /* expr ::= RAISE LP raisetype COMMA nm RP */
127858 {
127859 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
127860 if( yygotominor.yy346.pExpr ) {
127861 yygotominor.yy346.pExpr->affinity = (char)yymsp[-3].minor.yy328;
127862 }
127863 yygotominor.yy346.zStart = yymsp[-5].minor.yy0.z;
127864 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127865 }
127866 break;
127867 case 290: /* raisetype ::= ROLLBACK */
127868 {yygotominor.yy328 = OE_Rollback;}
127869 break;
127870 case 292: /* raisetype ::= FAIL */
127871 {yygotominor.yy328 = OE_Fail;}
127872 break;
127873 case 293: /* cmd ::= DROP TRIGGER ifexists fullname */
127874 {
127875 sqlite3DropTrigger(pParse,yymsp[0].minor.yy65,yymsp[-1].minor.yy328);
127876 }
127877 break;
127878 case 294: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
127879 {
127880 sqlite3Attach(pParse, yymsp[-3].minor.yy346.pExpr, yymsp[-1].minor.yy346.pExpr, yymsp[0].minor.yy132);
127881 }
127882 break;
127883 case 295: /* cmd ::= DETACH database_kw_opt expr */
127884 {
127885 sqlite3Detach(pParse, yymsp[0].minor.yy346.pExpr);
127886 }
127887 break;
127888 case 300: /* cmd ::= REINDEX */
127889 {sqlite3Reindex(pParse, 0, 0);}
127890 break;
127891 case 301: /* cmd ::= REINDEX nm dbnm */
127892 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
127893 break;
127894 case 302: /* cmd ::= ANALYZE */
127895 {sqlite3Analyze(pParse, 0, 0);}
127896 break;
127897 case 303: /* cmd ::= ANALYZE nm dbnm */
127898 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
127899 break;
127900 case 304: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
127901 {
127902 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy65,&yymsp[0].minor.yy0);
127903 }
127904 break;
127905 case 305: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
127906 {
127907 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
127908 }
127909 break;
127910 case 306: /* add_column_fullname ::= fullname */
127911 {
127912 pParse->db->lookaside.bEnabled = 0;
127913 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy65);
127914 }
127915 break;
127916 case 309: /* cmd ::= create_vtab */
127917 {sqlite3VtabFinishParse(pParse,0);}
127918 break;
127919 case 310: /* cmd ::= create_vtab LP vtabarglist RP */
127920 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
127921 break;
127922 case 311: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
127923 {
127924 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy328);
127925 }
127926 break;
127927 case 314: /* vtabarg ::= */
127928 {sqlite3VtabArgInit(pParse);}
127929 break;
127930 case 316: /* vtabargtoken ::= ANY */
127931 case 317: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==317);
127932 case 318: /* lp ::= LP */ yytestcase(yyruleno==318);
127933 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
127934 break;
127935 case 322: /* with ::= */
127936 {yygotominor.yy59 = 0;}
127937 break;
127938 case 323: /* with ::= WITH wqlist */
127939 case 324: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==324);
127940 { yygotominor.yy59 = yymsp[0].minor.yy59; }
127941 break;
127942 case 325: /* wqlist ::= nm idxlist_opt AS LP select RP */
127943 {
127944 yygotominor.yy59 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
127945 }
127946 break;
127947 case 326: /* wqlist ::= wqlist COMMA nm idxlist_opt AS LP select RP */
127948 {
127949 yygotominor.yy59 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy59, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
127950 }
127951 break;
127952 default:
@@ -127970,49 +128439,48 @@
127970 /* (53) carglist ::= */ yytestcase(yyruleno==53);
127971 /* (60) ccons ::= NULL onconf */ yytestcase(yyruleno==60);
127972 /* (88) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==88);
127973 /* (89) conslist ::= tcons */ yytestcase(yyruleno==89);
127974 /* (91) tconscomma ::= */ yytestcase(yyruleno==91);
127975 /* (273) foreach_clause ::= */ yytestcase(yyruleno==273);
127976 /* (274) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==274);
127977 /* (281) tridxby ::= */ yytestcase(yyruleno==281);
127978 /* (298) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==298);
127979 /* (299) database_kw_opt ::= */ yytestcase(yyruleno==299);
127980 /* (307) kwcolumn_opt ::= */ yytestcase(yyruleno==307);
127981 /* (308) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==308);
127982 /* (312) vtabarglist ::= vtabarg */ yytestcase(yyruleno==312);
127983 /* (313) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==313);
127984 /* (315) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==315);
127985 /* (319) anylist ::= */ yytestcase(yyruleno==319);
127986 /* (320) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==320);
127987 /* (321) anylist ::= anylist ANY */ yytestcase(yyruleno==321);
127988 break;
127989 };
127990 assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
127991 yygoto = yyRuleInfo[yyruleno].lhs;
127992 yysize = yyRuleInfo[yyruleno].nrhs;
127993 yypParser->yyidx -= yysize;
127994 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
127995 if( yyact < YYNSTATE ){
127996 #ifdef NDEBUG
127997 /* If we are not debugging and the reduce action popped at least
127998 ** one element off the stack, then we can push the new element back
127999 ** onto the stack here, and skip the stack overflow test in yy_shift().
128000 ** That gives a significant speed improvement. */
128001 if( yysize ){
128002 yypParser->yyidx++;
128003 yymsp -= yysize-1;
128004 yymsp->stateno = (YYACTIONTYPE)yyact;
128005 yymsp->major = (YYCODETYPE)yygoto;
128006 yymsp->minor = yygotominor;
128007 }else
128008 #endif
128009 {
128010 yy_shift(yypParser,yyact,yygoto,&yygotominor);
128011 }
128012 }else{
128013 assert( yyact == YYNSTATE + YYNRULE + 1 );
128014 yy_accept(yypParser);
128015 }
128016 }
128017
128018 /*
@@ -128133,16 +128601,17 @@
128133 }
128134 #endif
128135
128136 do{
128137 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
128138 if( yyact<YYNSTATE ){
 
128139 yy_shift(yypParser,yyact,yymajor,&yyminorunion);
128140 yypParser->yyerrcnt--;
128141 yymajor = YYNOCODE;
128142 }else if( yyact < YYNSTATE + YYNRULE ){
128143 yy_reduce(yypParser,yyact-YYNSTATE);
128144 }else{
128145 assert( yyact == YY_ERROR_ACTION );
128146 #ifdef YYERRORSYMBOL
128147 int yymx;
128148 #endif
@@ -128188,11 +128657,11 @@
128188 while(
128189 yypParser->yyidx >= 0 &&
128190 yymx != YYERRORSYMBOL &&
128191 (yyact = yy_find_reduce_action(
128192 yypParser->yystack[yypParser->yyidx].stateno,
128193 YYERRORSYMBOL)) >= YYNSTATE
128194 ){
128195 yy_pop_parser_stack(yypParser);
128196 }
128197 if( yypParser->yyidx < 0 || yymajor==0 ){
128198 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
@@ -128238,10 +128707,15 @@
128238 }
128239 yymajor = YYNOCODE;
128240 #endif
128241 }
128242 }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
 
 
 
 
 
128243 return;
128244 }
128245
128246 /************** End of parse.c ***********************************************/
128247 /************** Begin file tokenize.c ****************************************/
@@ -128926,10 +129400,11 @@
128926 }
128927 pParse->rc = SQLITE_OK;
128928 pParse->zTail = zSql;
128929 i = 0;
128930 assert( pzErrMsg!=0 );
 
128931 pEngine = sqlite3ParserAlloc(sqlite3Malloc);
128932 if( pEngine==0 ){
128933 db->mallocFailed = 1;
128934 return SQLITE_NOMEM;
128935 }
@@ -130370,20 +130845,26 @@
130370 ** db. This is called when db is being closed.
130371 */
130372 static void disconnectAllVtab(sqlite3 *db){
130373 #ifndef SQLITE_OMIT_VIRTUALTABLE
130374 int i;
 
130375 sqlite3BtreeEnterAll(db);
130376 for(i=0; i<db->nDb; i++){
130377 Schema *pSchema = db->aDb[i].pSchema;
130378 if( db->aDb[i].pSchema ){
130379 HashElem *p;
130380 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
130381 Table *pTab = (Table *)sqliteHashData(p);
130382 if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
130383 }
130384 }
 
 
 
 
 
 
130385 }
130386 sqlite3VtabUnlockList(db);
130387 sqlite3BtreeLeaveAll(db);
130388 #else
130389 UNUSED_PARAMETER(db);
@@ -130558,10 +131039,11 @@
130558 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
130559 Module *pMod = (Module *)sqliteHashData(i);
130560 if( pMod->xDestroy ){
130561 pMod->xDestroy(pMod->pAux);
130562 }
 
130563 sqlite3DbFree(db, pMod);
130564 }
130565 sqlite3HashClear(&db->aModule);
130566 #endif
130567
@@ -156962,14 +157444,10 @@
156962
156963 /* #include <assert.h> */
156964 /* #include <string.h> */
156965 /* #include <stdio.h> */
156966
156967 #if !defined(_WIN32)
156968 /* # include <unistd.h> */
156969 #endif
156970
156971 /* #include "sqlite3.h" */
156972
156973 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
156974 /************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
156975 /************** Begin file sqlite3rbu.h **************************************/
@@ -157070,10 +157548,22 @@
157070 **
157071 ** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
157072 **
157073 ** The order of the columns in the data_% table does not matter.
157074 **
 
 
 
 
 
 
 
 
 
 
 
 
157075 ** If the target database table is a virtual table or a table that has no
157076 ** PRIMARY KEY declaration, the data_% table must also contain a column
157077 ** named "rbu_rowid". This column is mapped to the tables implicit primary
157078 ** key column - "rowid". Virtual tables for which the "rowid" column does
157079 ** not function like a primary key value cannot be updated using RBU. For
@@ -157149,10 +157639,18 @@
157149 ** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
157150 **
157151 ** is similar to an UPDATE statement such as:
157152 **
157153 ** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
 
 
 
 
 
 
 
 
157154 **
157155 ** If the target database table is a virtual table or a table with no PRIMARY
157156 ** KEY, the rbu_control value should not include a character corresponding
157157 ** to the rbu_rowid value. For example, this:
157158 **
@@ -157307,10 +157805,22 @@
157307 ** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
157308 ** that immediately return the same value.
157309 */
157310 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu);
157311
 
 
 
 
 
 
 
 
 
 
 
 
157312 /*
157313 ** Close an RBU handle.
157314 **
157315 ** If the RBU update has been completely applied, mark the RBU database
157316 ** as fully applied. Otherwise, assuming no error has occurred, save the
@@ -157539,10 +158049,11 @@
157539 int eType; /* Table type - an RBU_PK_XXX value */
157540
157541 /* Output variables. zTbl==0 implies EOF. */
157542 int bCleanup; /* True in "cleanup" state */
157543 const char *zTbl; /* Name of target db table */
 
157544 const char *zIdx; /* Name of target db index (or null) */
157545 int iTnum; /* Root page of current object */
157546 int iPkTnum; /* If eType==EXTERNAL, root of PK index */
157547 int bUnique; /* Current index is unique */
157548
@@ -157549,11 +158060,11 @@
157549 /* Statements created by rbuObjIterPrepareAll() */
157550 int nCol; /* Number of columns in current object */
157551 sqlite3_stmt *pSelect; /* Source data */
157552 sqlite3_stmt *pInsert; /* Statement for INSERT operations */
157553 sqlite3_stmt *pDelete; /* Statement for DELETE ops */
157554 sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zTbl */
157555
157556 /* Last UPDATE used (for PK b-tree updates only), or NULL. */
157557 RbuUpdateStmt *pRbuUpdate;
157558 };
157559
@@ -157659,10 +158170,256 @@
157659 const char *zWal; /* Wal filename for this main db file */
157660 rbu_file *pWalFd; /* Wal file descriptor for this main db */
157661 rbu_file *pMainNext; /* Next MAIN_DB file */
157662 };
157663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157664
157665 /*
157666 ** Prepare the SQL statement in buffer zSql against database handle db.
157667 ** If successful, set *ppStmt to point to the new statement and return
157668 ** SQLITE_OK.
@@ -157826,11 +158583,12 @@
157826 if( rc!=SQLITE_ROW ){
157827 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
157828 pIter->zTbl = 0;
157829 }else{
157830 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
157831 rc = pIter->zTbl ? SQLITE_OK : SQLITE_NOMEM;
 
157832 }
157833 }else{
157834 if( pIter->zIdx==0 ){
157835 sqlite3_stmt *pIdx = pIter->pIdxIter;
157836 rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
@@ -157857,10 +158615,44 @@
157857 p->rc = rc;
157858 }
157859 return rc;
157860 }
157861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157862 /*
157863 ** Initialize the iterator structure passed as the second argument.
157864 **
157865 ** If no error occurs, SQLITE_OK is returned and the iterator is left
157866 ** pointing to the first entry. Otherwise, an error code and message is
@@ -157870,12 +158662,13 @@
157870 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
157871 int rc;
157872 memset(pIter, 0, sizeof(RbuObjIter));
157873
157874 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
157875 "SELECT substr(name, 6) FROM sqlite_master "
157876 "WHERE type IN ('table', 'view') AND name LIKE 'data_%'"
 
157877 );
157878
157879 if( rc==SQLITE_OK ){
157880 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
157881 "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
@@ -158138,11 +158931,11 @@
158138 }
158139 *peType = RBU_PK_NONE;
158140 }
158141
158142 rbuTableType_end: {
158143 int i;
158144 for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
158145 rbuFinalize(p, aStmt[i]);
158146 }
158147 }
158148 }
@@ -158217,11 +159010,11 @@
158217
158218 /* Populate the azTblCol[] and nTblCol variables based on the columns
158219 ** of the input table. Ignore any input table columns that begin with
158220 ** "rbu_". */
158221 p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
158222 sqlite3_mprintf("SELECT * FROM 'data_%q'", pIter->zTbl)
158223 );
158224 if( p->rc==SQLITE_OK ){
158225 nCol = sqlite3_column_count(pStmt);
158226 rbuAllocateIterArrays(p, pIter, nCol);
158227 }
@@ -158242,11 +159035,11 @@
158242 if( p->rc==SQLITE_OK
158243 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
158244 ){
158245 p->rc = SQLITE_ERROR;
158246 p->zErrmsg = sqlite3_mprintf(
158247 "table data_%q %s rbu_rowid column", pIter->zTbl,
158248 (bRbuRowid ? "may not have" : "requires")
158249 );
158250 }
158251
158252 /* Check that all non-HIDDEN columns in the destination table are also
@@ -158263,12 +159056,12 @@
158263 for(i=iOrder; i<pIter->nTblCol; i++){
158264 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
158265 }
158266 if( i==pIter->nTblCol ){
158267 p->rc = SQLITE_ERROR;
158268 p->zErrmsg = sqlite3_mprintf("column missing from data_%q: %s",
158269 pIter->zTbl, zName
158270 );
158271 }else{
158272 int iPk = sqlite3_column_int(pStmt, 5);
158273 int bNotNull = sqlite3_column_int(pStmt, 3);
158274 const char *zType = (const char*)sqlite3_column_text(pStmt, 2);
@@ -158551,11 +159344,11 @@
158551 ){
158552 char *zList = 0;
158553 if( p->rc==SQLITE_OK ){
158554 int i;
158555
158556 if( strlen(zMask)!=pIter->nTblCol ){
158557 rbuBadControlError(p);
158558 }else{
158559 const char *zSep = "";
158560 for(i=0; i<pIter->nTblCol; i++){
158561 char c = zMask[pIter->aiSrcOrder[i]];
@@ -158563,15 +159356,21 @@
158563 zList = rbuMPrintf(p, "%z%s\"%w\"=?%d",
158564 zList, zSep, pIter->azTblCol[i], i+1
158565 );
158566 zSep = ", ";
158567 }
158568 if( c=='d' ){
158569 zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)",
158570 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
158571 );
158572 zSep = ", ";
 
 
 
 
 
 
158573 }
158574 }
158575 }
158576 }
158577 return zList;
@@ -158819,11 +159618,11 @@
158819 if( zBind ){
158820 assert( pIter->pTmpInsert==0 );
158821 p->rc = prepareFreeAndCollectError(
158822 p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
158823 "INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)",
158824 p->zStateDb, pIter->zTbl, zCollist, zRbuRowid, zBind
158825 ));
158826 }
158827 }
158828
158829 static void rbuTmpInsertFunc(
@@ -158915,22 +159714,22 @@
158915 if( p->rc==SQLITE_OK ){
158916 char *zSql;
158917 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
158918 zSql = sqlite3_mprintf(
158919 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
158920 zCollist, p->zStateDb, pIter->zTbl,
158921 zCollist, zLimit
158922 );
158923 }else{
158924 zSql = sqlite3_mprintf(
158925 "SELECT %s, rbu_control FROM 'data_%q' "
158926 "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
158927 "UNION ALL "
158928 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
158929 "ORDER BY %s%s",
158930 zCollist, pIter->zTbl,
158931 zCollist, p->zStateDb, pIter->zTbl,
158932 zCollist, zLimit
158933 );
158934 }
158935 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
158936 }
@@ -158950,20 +159749,10 @@
158950 char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
158951
158952 zCollist = rbuObjIterGetCollist(p, pIter);
158953 pIter->nCol = pIter->nTblCol;
158954
158955 /* Create the SELECT statement to read keys from data_xxx */
158956 if( p->rc==SQLITE_OK ){
158957 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
158958 sqlite3_mprintf(
158959 "SELECT %s, rbu_control%s FROM 'data_%q'%s",
158960 zCollist, (bRbuRowid ? ", rbu_rowid" : ""), zTbl, zLimit
158961 )
158962 );
158963 }
158964
158965 /* Create the imposter table or tables (if required). */
158966 rbuCreateImposterTable(p, pIter);
158967 rbuCreateImposterTable2(p, pIter);
158968 zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
158969
@@ -158993,14 +159782,14 @@
158993 }
158994
158995 /* Create the rbu_tmp_xxx table and the triggers to populate it. */
158996 rbuMPrintfExec(p, p->dbRbu,
158997 "CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS "
158998 "SELECT *%s FROM 'data_%q' WHERE 0;"
158999 , p->zStateDb
159000 , zTbl, (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
159001 , zTbl
159002 );
159003
159004 rbuMPrintfExec(p, p->dbMain,
159005 "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" "
159006 "BEGIN "
@@ -159031,10 +159820,21 @@
159031 );
159032 }
159033
159034 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
159035 }
 
 
 
 
 
 
 
 
 
 
 
159036
159037 sqlite3_free(zWhere);
159038 sqlite3_free(zOldlist);
159039 sqlite3_free(zNewlist);
159040 sqlite3_free(zBindings);
@@ -159161,10 +159961,22 @@
159161 if( p->rc==SQLITE_OK ){
159162 p->rc = sqlite3_create_function(p->dbMain,
159163 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
159164 );
159165 }
 
 
 
 
 
 
 
 
 
 
 
 
159166
159167 if( p->rc==SQLITE_OK ){
159168 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
159169 }
159170 rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
@@ -159591,11 +160403,11 @@
159591 rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
159592 if( pUpdate ){
159593 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
159594 char c = zMask[pIter->aiSrcOrder[i]];
159595 pVal = sqlite3_column_value(pIter->pSelect, i);
159596 if( pIter->abTblPk[i] || c=='x' || c=='d' ){
159597 p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
159598 }
159599 }
159600 if( p->rc==SQLITE_OK
159601 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
@@ -159703,11 +160515,11 @@
159703 /* Clean up the rbu_tmp_xxx table for the previous table. It
159704 ** cannot be dropped as there are currently active SQL statements.
159705 ** But the contents can be deleted. */
159706 if( pIter->abIndexed ){
159707 rbuMPrintfExec(p, p->dbRbu,
159708 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zTbl
159709 );
159710 }
159711 }else{
159712 rbuObjIterPrepareAll(p, pIter, 0);
159713
@@ -159926,14 +160738,17 @@
159926 ** If there is a "*-oal" file in the file-system corresponding to the
159927 ** target database in the file-system, delete it. If an error occurs,
159928 ** leave an error code and error message in the rbu handle.
159929 */
159930 static void rbuDeleteOalFile(sqlite3rbu *p){
159931 char *zOal = sqlite3_mprintf("%s-oal", p->zTarget);
159932 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
159933 unlink(zOal);
159934 sqlite3_free(zOal);
 
 
 
159935 }
159936
159937 /*
159938 ** Allocate a private rbu VFS for the rbu handle passed as the only
159939 ** argument. This VFS will be used unless the call to sqlite3rbu_open()
@@ -160042,18 +160857,29 @@
160042 p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
160043 }
160044
160045 if( p->rc==SQLITE_OK ){
160046 if( p->eStage==RBU_STAGE_OAL ){
 
160047
160048 /* Open transactions both databases. The *-oal file is opened or
160049 ** created at this point. */
160050 p->rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160051 if( p->rc==SQLITE_OK ){
160052 p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160053 }
160054
 
 
 
 
 
 
 
 
 
 
160055 /* Point the object iterator at the first object */
160056 if( p->rc==SQLITE_OK ){
160057 p->rc = rbuObjIterFirst(p, &p->objiter);
160058 }
160059
@@ -160162,10 +160988,36 @@
160162 ** current RBU update was started.
160163 */
160164 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){
160165 return pRbu->nProgress;
160166 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160167
160168 /**************************************************************************
160169 ** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
160170 ** of a standard VFS in the following ways:
160171 **
@@ -160642,11 +161494,12 @@
160642 rbuVfsSectorSize, /* xSectorSize */
160643 rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
160644 rbuVfsShmMap, /* xShmMap */
160645 rbuVfsShmLock, /* xShmLock */
160646 rbuVfsShmBarrier, /* xShmBarrier */
160647 rbuVfsShmUnmap /* xShmUnmap */
 
160648 };
160649 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
160650 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
160651 rbu_file *pFd = (rbu_file *)pFile;
160652 int rc = SQLITE_OK;
@@ -160984,10 +161837,13 @@
160984 **
160985 ** The dbstat virtual table is used to extract low-level formatting
160986 ** information from an SQLite database in order to implement the
160987 ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
160988 ** for an example implementation.
 
 
 
160989 */
160990
160991 /* #include "sqliteInt.h" ** Requires access to internal data structures ** */
160992 #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
160993 && !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -161032,11 +161888,12 @@
161032 " ncell INTEGER, /* Cells on page (0 for overflow) */" \
161033 " payload INTEGER, /* Bytes of payload on this page */" \
161034 " unused INTEGER, /* Bytes of unused space on this page */" \
161035 " mx_payload INTEGER, /* Largest payload size of all cells */" \
161036 " pgoffset INTEGER, /* Offset of page in file */" \
161037 " pgsize INTEGER /* Size of the page */" \
 
161038 ");"
161039
161040
161041 typedef struct StatTable StatTable;
161042 typedef struct StatCursor StatCursor;
@@ -161070,10 +161927,11 @@
161070
161071 struct StatCursor {
161072 sqlite3_vtab_cursor base;
161073 sqlite3_stmt *pStmt; /* Iterates through set of root pages */
161074 int isEof; /* After pStmt has returned SQLITE_DONE */
 
161075
161076 StatPage aPage[32];
161077 int iPage; /* Current entry in aPage[] */
161078
161079 /* Values to return. */
@@ -161147,13 +162005,36 @@
161147 return SQLITE_OK;
161148 }
161149
161150 /*
161151 ** There is no "best-index". This virtual table always does a linear
161152 ** scan of the binary VFS log file.
 
 
 
161153 */
161154 static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161155
161156 /* Records are always returned in ascending order of (name, path).
161157 ** If this will satisfy the client, set the orderByConsumed flag so that
161158 ** SQLite does not do an external sort.
161159 */
@@ -161169,50 +162050,31 @@
161169 )
161170 ){
161171 pIdxInfo->orderByConsumed = 1;
161172 }
161173
161174 pIdxInfo->estimatedCost = 10.0;
161175 return SQLITE_OK;
161176 }
161177
161178 /*
161179 ** Open a new statvfs cursor.
161180 */
161181 static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
161182 StatTable *pTab = (StatTable *)pVTab;
161183 StatCursor *pCsr;
161184 int rc;
161185
161186 pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
161187 if( pCsr==0 ){
161188 rc = SQLITE_NOMEM;
161189 }else{
161190 char *zSql;
161191 memset(pCsr, 0, sizeof(StatCursor));
161192 pCsr->base.pVtab = pVTab;
161193
161194 zSql = sqlite3_mprintf(
161195 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
161196 " UNION ALL "
161197 "SELECT name, rootpage, type"
161198 " FROM \"%w\".sqlite_master WHERE rootpage!=0"
161199 " ORDER BY name", pTab->db->aDb[pTab->iDb].zName);
161200 if( zSql==0 ){
161201 rc = SQLITE_NOMEM;
161202 }else{
161203 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
161204 sqlite3_free(zSql);
161205 }
161206 if( rc!=SQLITE_OK ){
161207 sqlite3_free(pCsr);
161208 pCsr = 0;
161209 }
161210 }
161211
161212 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
161213 return rc;
161214 }
161215
161216 static void statClearPage(StatPage *p){
161217 int i;
161218 if( p->aCell ){
@@ -161233,10 +162095,11 @@
161233 statClearPage(&pCsr->aPage[i]);
161234 }
161235 pCsr->iPage = 0;
161236 sqlite3_free(pCsr->zPath);
161237 pCsr->zPath = 0;
 
161238 }
161239
161240 /*
161241 ** Close a statvfs cursor.
161242 */
@@ -161395,11 +162258,11 @@
161395 int rc;
161396 int nPayload;
161397 char *z;
161398 StatCursor *pCsr = (StatCursor *)pCursor;
161399 StatTable *pTab = (StatTable *)pCursor->pVtab;
161400 Btree *pBt = pTab->db->aDb[pTab->iDb].pBt;
161401 Pager *pPager = sqlite3BtreePager(pBt);
161402
161403 sqlite3_free(pCsr->zPath);
161404 pCsr->zPath = 0;
161405
@@ -161533,13 +162396,47 @@
161533 sqlite3_vtab_cursor *pCursor,
161534 int idxNum, const char *idxStr,
161535 int argc, sqlite3_value **argv
161536 ){
161537 StatCursor *pCsr = (StatCursor *)pCursor;
 
 
 
 
161538
 
 
 
 
 
 
 
 
 
 
 
161539 statResetCsr(pCsr);
161540 return statNext(pCursor);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161541 }
161542
161543 static int statColumn(
161544 sqlite3_vtab_cursor *pCursor,
161545 sqlite3_context *ctx,
@@ -161572,14 +162469,19 @@
161572 sqlite3_result_int(ctx, pCsr->nMxPayload);
161573 break;
161574 case 8: /* pgoffset */
161575 sqlite3_result_int64(ctx, pCsr->iOffset);
161576 break;
161577 default: /* pgsize */
161578 assert( i==9 );
161579 sqlite3_result_int(ctx, pCsr->szPage);
161580 break;
 
 
 
 
 
 
161581 }
161582 return SQLITE_OK;
161583 }
161584
161585 static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
161586
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.12. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -323,13 +323,13 @@
323 **
324 ** See also: [sqlite3_libversion()],
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.12"
329 #define SQLITE_VERSION_NUMBER 3008012
330 #define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -689,10 +689,11 @@
689 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
690 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
691 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
692 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
693 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
694 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
695 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
696 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
697 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
698 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
699 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -3585,11 +3586,12 @@
3586 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3587 ** METHOD: sqlite3_stmt
3588 **
3589 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3590 ** [prepared statement] S has been stepped at least once using
3591 ** [sqlite3_step(S)] but has neither run to completion (returned
3592 ** [SQLITE_DONE] from [sqlite3_step(S)]) nor
3593 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
3594 ** interface returns false if S is a NULL pointer. If S is not a
3595 ** NULL pointer and is not a pointer to a valid [prepared statement]
3596 ** object, then the behavior is undefined and probably undesirable.
3597 **
@@ -4567,10 +4569,26 @@
4569 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
4570 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
4571 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4572 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4573
4574 /*
4575 ** CAPI3REF: Obtaining SQL Values
4576 ** METHOD: sqlite3_value
4577 **
4578 ** The sqlite3_value_subtype(V) function returns the subtype for
4579 ** an [application-defined SQL function] argument V. The subtype
4580 ** information can be used to pass a limited amount of context from
4581 ** one SQL function to another. Use the [sqlite3_result_subtype()]
4582 ** routine to set the subtype for the return value of an SQL function.
4583 **
4584 ** SQLite makes no use of subtype itself. It merely passes the subtype
4585 ** from the result of one [application-defined SQL function] into the
4586 ** input of another.
4587 */
4588 SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
4589
4590 /*
4591 ** CAPI3REF: Copy And Free SQL Values
4592 ** METHOD: sqlite3_value
4593 **
4594 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
@@ -4866,10 +4884,25 @@
4884 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4885 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4886 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4887 SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
4888
4889
4890 /*
4891 ** CAPI3REF: Setting The Subtype Of An SQL Function
4892 ** METHOD: sqlite3_context
4893 **
4894 ** The sqlite3_result_subtype(C,T) function causes the subtype of
4895 ** the result from the [application-defined SQL function] with
4896 ** [sqlite3_context] C to be the value T. Only the lower 8 bits
4897 ** of the subtype T are preserved in current versions of SQLite;
4898 ** higher order bits are discarded.
4899 ** The number of subtype bytes preserved by SQLite might increase
4900 ** in future releases of SQLite.
4901 */
4902 SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
4903
4904 /*
4905 ** CAPI3REF: Define New Collating Sequences
4906 ** METHOD: sqlite3
4907 **
4908 ** ^These functions add, remove, or modify a [collation] associated
@@ -8361,19 +8394,22 @@
8394 # define SQLITE_NOINLINE
8395 #endif
8396
8397 /*
8398 ** Make sure that the compiler intrinsics we desire are enabled when
8399 ** compiling with an appropriate version of MSVC unless prevented by
8400 ** the SQLITE_DISABLE_INTRINSIC define.
8401 */
8402 #if !defined(SQLITE_DISABLE_INTRINSIC)
8403 # if defined(_MSC_VER) && _MSC_VER>=1300
8404 # if !defined(_WIN32_WCE)
8405 # include <intrin.h>
8406 # pragma intrinsic(_byteswap_ushort)
8407 # pragma intrinsic(_byteswap_ulong)
8408 # else
8409 # include <cmnintrin.h>
8410 # endif
8411 # endif
8412 #endif
8413
8414 /*
8415 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
@@ -10050,16 +10086,20 @@
10086 */
10087 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
10088 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
10089 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
10090 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
10091 SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe*,int);
10092 SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe*,int,const char*);
10093 SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
10094 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
10095 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
10096 SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
10097 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
10098 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
10099 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
10100 SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
10101 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
10102 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
10103 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
10104 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
10105 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
@@ -11333,22 +11373,24 @@
11373 /*
11374 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
11375 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There
11376 ** are assert() statements in the code to verify this.
11377 */
11378 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
11379 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
11380 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
11381 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
11382 #define SQLITE_FUNC_NEEDCOLL 0x0020 /* sqlite3GetFuncCollSeq() might be called*/
11383 #define SQLITE_FUNC_LENGTH 0x0040 /* Built-in length() function */
11384 #define SQLITE_FUNC_TYPEOF 0x0080 /* Built-in typeof() function */
11385 #define SQLITE_FUNC_COUNT 0x0100 /* Built-in count(*) aggregate */
11386 #define SQLITE_FUNC_COALESCE 0x0200 /* Built-in coalesce() or ifnull() */
11387 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
11388 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
11389 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
11390 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
11391 ** single query - might change over time */
11392
11393 /*
11394 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
11395 ** used to create the initializers for the FuncDef structures.
11396 **
@@ -11359,10 +11401,16 @@
11401 ** as the user-data (sqlite3_user_data()) for the function. If
11402 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
11403 **
11404 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
11405 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
11406 **
11407 ** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
11408 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
11409 ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions
11410 ** and functions like sqlite_version() that can change, but not during
11411 ** a single query.
11412 **
11413 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
11414 ** Used to create an aggregate function definition implemented by
11415 ** the C functions xStep and xFinal. The first four parameters
11416 ** are interpreted in the same way as the first 4 parameters to
@@ -11380,15 +11428,18 @@
11428 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11429 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
11430 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
11431 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11432 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
11433 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
11434 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11435 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
11436 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
11437 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
11438 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
11439 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
11440 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
11441 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
11442 #define LIKEFUNC(zName, nArg, arg, flags) \
11443 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
11444 (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
11445 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
@@ -11428,10 +11479,11 @@
11479 struct Module {
11480 const sqlite3_module *pModule; /* Callback pointers */
11481 const char *zName; /* Name passed to create_module() */
11482 void *pAux; /* pAux passed to create_module() */
11483 void (*xDestroy)(void *); /* Module destructor function */
11484 Table *pEpoTab; /* Eponymous table for this module */
11485 };
11486
11487 /*
11488 ** information about each column of an SQL table is held in an instance
11489 ** of this structure.
@@ -11473,10 +11525,11 @@
11525 /*
11526 ** A sort order can be either ASC or DESC.
11527 */
11528 #define SQLITE_SO_ASC 0 /* Sort in ascending order */
11529 #define SQLITE_SO_DESC 1 /* Sort in ascending order */
11530 #define SQLITE_SO_UNDEFINED -1 /* No sort order specified */
11531
11532 /*
11533 ** Column affinity types.
11534 **
11535 ** These used to have mnemonic name like 'i' for SQLITE_AFF_INTEGER and
@@ -11579,13 +11632,12 @@
11632 Column *aCol; /* Information about each column */
11633 Index *pIndex; /* List of SQL indexes on this table. */
11634 Select *pSelect; /* NULL for tables. Points to definition if a view. */
11635 FKey *pFKey; /* Linked list of all foreign keys in this table */
11636 char *zColAff; /* String defining the affinity of each column */
 
11637 ExprList *pCheck; /* All CHECK constraints */
11638 /* ... also used as column name list in a VIEW */
11639 int tnum; /* Root BTree page for this table */
11640 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
11641 i16 nCol; /* Number of columns in this table */
11642 u16 nRef; /* Number of pointers to this Table */
11643 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
@@ -11598,11 +11650,11 @@
11650 #ifndef SQLITE_OMIT_ALTERTABLE
11651 int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
11652 #endif
11653 #ifndef SQLITE_OMIT_VIRTUALTABLE
11654 int nModuleArg; /* Number of arguments to the module */
11655 char **azModuleArg; /* 0: module 1: schema 2: vtab name 3...: args */
11656 VTable *pVTable; /* List of VTable objects. */
11657 #endif
11658 Trigger *pTrigger; /* List of triggers stored in pSchema */
11659 Schema *pSchema; /* Schema that contains this table */
11660 Table *pNextZombie; /* Next on the Parse.pZombieTab list */
@@ -11819,10 +11871,11 @@
11871 Index *pNext; /* The next index associated with the same table */
11872 Schema *pSchema; /* Schema containing this index */
11873 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
11874 char **azColl; /* Array of collation sequence names for index */
11875 Expr *pPartIdxWhere; /* WHERE clause for partial indices */
11876 ExprList *aColExpr; /* Column expressions */
11877 int tnum; /* DB Page containing root of this index */
11878 LogEst szIdxRow; /* Estimated average row size in bytes */
11879 u16 nKeyCol; /* Number of columns forming the key */
11880 u16 nColumn; /* Number of columns stored in the index */
11881 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
@@ -12068,13 +12121,14 @@
12121 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
12122 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
12123 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
12124 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
12125 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
12126 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
12127 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
12128 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
12129 #define EP_Alias 0x400000 /* Is an alias for a result set column */
12130
12131 /*
12132 ** Combinations of two or more EP_* flags
12133 */
12134 #define EP_Propagate (EP_Collate|EP_Subquery) /* Propagate these bits up tree */
@@ -12233,24 +12287,31 @@
12287 Table *pTab; /* An SQL table corresponding to zName */
12288 Select *pSelect; /* A SELECT statement used in place of a table name */
12289 int addrFillSub; /* Address of subroutine to manifest a subquery */
12290 int regReturn; /* Register holding return address of addrFillSub */
12291 int regResult; /* Registers holding results of a co-routine */
12292 struct {
12293 u8 jointype; /* Type of join between this able and the previous */
12294 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
12295 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
12296 unsigned isTabFunc :1; /* True if table-valued-function syntax */
12297 unsigned isCorrelated :1; /* True if sub-query is correlated */
12298 unsigned viaCoroutine :1; /* Implemented as a co-routine */
12299 unsigned isRecursive :1; /* True for recursive reference in WITH */
12300 } fg;
12301 #ifndef SQLITE_OMIT_EXPLAIN
12302 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
12303 #endif
12304 int iCursor; /* The VDBE cursor number used to access this table */
12305 Expr *pOn; /* The ON clause of a join */
12306 IdList *pUsing; /* The USING clause of a join */
12307 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
12308 union {
12309 char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
12310 ExprList *pFuncArg; /* Arguments to table-valued-function */
12311 } u1;
12312 Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */
12313 } a[1]; /* One entry for each identifier on the list */
12314 };
12315
12316 /*
12317 ** Permitted values of the SrcList.a.jointype field
@@ -12332,10 +12393,11 @@
12393 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
12394 #define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
12395 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
12396 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
12397 #define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
12398 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
12399 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
12400
12401 /*
12402 ** An instance of the following structure contains all information
12403 ** needed to generate code for a single SELECT statement.
@@ -12601,11 +12663,11 @@
12663 int nSet; /* Number of sets used so far */
12664 int nOnce; /* Number of OP_Once instructions so far */
12665 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
12666 int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
12667 int ckBase; /* Base register of data during check constraints */
12668 int iSelfTab; /* Table of an index whose exprs are being coded */
12669 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
12670 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
12671 int nLabel; /* Number of labels used */
12672 int *aLabel; /* Space to hold the labels */
12673 struct yColCache {
@@ -12971,11 +13033,11 @@
13033 With *pOuter; /* Containing WITH clause, or NULL */
13034 struct Cte { /* For each CTE in the WITH clause.... */
13035 char *zName; /* Name of this CTE */
13036 ExprList *pCols; /* List of explicit column names, or NULL */
13037 Select *pSelect; /* The definition of this CTE */
13038 const char *zCteErr; /* Error message for circular references */
13039 } a[1];
13040 };
13041
13042 #ifdef SQLITE_DEBUG
13043 /*
@@ -13119,10 +13181,15 @@
13181 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3NoopMutex(void);
13182 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int);
13183 SQLITE_PRIVATE int sqlite3MutexInit(void);
13184 SQLITE_PRIVATE int sqlite3MutexEnd(void);
13185 #endif
13186 #if !defined(SQLITE_MUTEX_OMIT) && !defined(SQLITE_MUTEX_NOOP)
13187 SQLITE_PRIVATE void sqlite3MemoryBarrier(void);
13188 #else
13189 # define sqlite3MemoryBarrier();
13190 #endif
13191
13192 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
13193 SQLITE_PRIVATE void sqlite3StatusUp(int, int);
13194 SQLITE_PRIVATE void sqlite3StatusDown(int, int);
13195 SQLITE_PRIVATE void sqlite3StatusSet(int, int);
@@ -13185,10 +13252,11 @@
13252 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
13253 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
13254 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
13255 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
13256 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
13257 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
13258 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
13259 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,ExprSpan*);
13260 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
13261 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
13262 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
@@ -13197,10 +13265,12 @@
13265 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
13266 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
13267 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
13268 SQLITE_PRIVATE void sqlite3BeginParse(Parse*,int);
13269 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
13270 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
13271 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
13272 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*);
13273 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
13274 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
13275 SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index*, i16);
13276 SQLITE_PRIVATE void sqlite3StartTable(Parse*,Token*,Token*,int,int,int,int);
@@ -13238,11 +13308,11 @@
13308 SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*);
13309 SQLITE_PRIVATE void sqlite3RowSetInsert(RowSet*, i64);
13310 SQLITE_PRIVATE int sqlite3RowSetTest(RowSet*, int iBatch, i64);
13311 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet*, i64*);
13312
13313 SQLITE_PRIVATE void sqlite3CreateView(Parse*,Token*,Token*,Token*,ExprList*,Select*,int,int);
13314
13315 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
13316 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse*,Table*);
13317 #else
13318 # define sqlite3ViewGetColumnNames(A,B) 0
@@ -13268,10 +13338,11 @@
13338 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
13339 SQLITE_PRIVATE SrcList *sqlite3SrcListAppend(sqlite3*, SrcList*, Token*, Token*);
13340 SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, Token*,
13341 Token*, Select*, Expr*, IdList*);
13342 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
13343 SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
13344 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
13345 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
13346 SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
13347 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
13348 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3*, SrcList*);
@@ -13298,10 +13369,11 @@
13369 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
13370 SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
13371 SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
13372 SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
13373 SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*);
13374 SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int);
13375 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
13376 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
13377 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
13378 SQLITE_PRIVATE void sqlite3ExprCacheStore(Parse*, int, int, int);
13379 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
@@ -13313,13 +13385,14 @@
13385 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
13386 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
13387 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
13388 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
13389 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
13390 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
13391 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
13392 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
13393 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
13394 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
13395 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
13396 SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
13397 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
13398 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
@@ -13487,11 +13560,11 @@
13560 sqlite3PutVarint((A),(B)))
13561 #define getVarint sqlite3GetVarint
13562 #define putVarint sqlite3PutVarint
13563
13564
13565 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3*, Index*);
13566 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
13567 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
13568 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
13569 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
13570 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
@@ -13559,10 +13632,11 @@
13632 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
13633 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
13634 SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
13635 SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
13636 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
13637 SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*);
13638 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
13639 SQLITE_PRIVATE void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
13640 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
13641 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
13642 SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
@@ -13667,10 +13741,12 @@
13741 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
13742 SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
13743 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
13744 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
13745 #endif
13746 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
13747 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
13748 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
13749 SQLITE_PRIVATE void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
13750 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse*, Token*);
13751 SQLITE_PRIVATE void sqlite3VtabArgInit(Parse*);
13752 SQLITE_PRIVATE void sqlite3VtabArgExtend(Parse*, Token*);
@@ -14770,10 +14846,11 @@
14846 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
14847 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
14848 } u;
14849 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
14850 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
14851 u8 eSubtype; /* Subtype for this value */
14852 int n; /* Number of characters in string value, excluding '\0' */
14853 char *z; /* String or BLOB value */
14854 /* ShallowCopy only needs to copy the information above */
14855 char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
14856 int szMalloc; /* Size of the zMalloc allocation */
@@ -16546,18 +16623,18 @@
16623 ** external linkage.
16624 */
16625 SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void){
16626 static SQLITE_WSD FuncDef aDateTimeFuncs[] = {
16627 #ifndef SQLITE_OMIT_DATETIME_FUNCS
16628 DFUNCTION(julianday, -1, 0, 0, juliandayFunc ),
16629 DFUNCTION(date, -1, 0, 0, dateFunc ),
16630 DFUNCTION(time, -1, 0, 0, timeFunc ),
16631 DFUNCTION(datetime, -1, 0, 0, datetimeFunc ),
16632 DFUNCTION(strftime, -1, 0, 0, strftimeFunc ),
16633 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
16634 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
16635 DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
16636 #else
16637 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
16638 STR_FUNCTION(current_date, 0, "%Y-%m-%d", 0, currentTimeFunc),
16639 STR_FUNCTION(current_timestamp, 0, "%Y-%m-%d %H:%M:%S", 0, currentTimeFunc),
16640 #endif
@@ -19273,10 +19350,11 @@
19350 pTo->xMutexEnter = pFrom->xMutexEnter;
19351 pTo->xMutexTry = pFrom->xMutexTry;
19352 pTo->xMutexLeave = pFrom->xMutexLeave;
19353 pTo->xMutexHeld = pFrom->xMutexHeld;
19354 pTo->xMutexNotheld = pFrom->xMutexNotheld;
19355 sqlite3MemoryBarrier();
19356 pTo->xMutexAlloc = pFrom->xMutexAlloc;
19357 }
19358 rc = sqlite3GlobalConfig.mutex.xMutexInit();
19359
19360 #ifdef SQLITE_DEBUG
@@ -19679,10 +19757,21 @@
19757 }
19758 static int pthreadMutexNotheld(sqlite3_mutex *p){
19759 return p->nRef==0 || pthread_equal(p->owner, pthread_self())==0;
19760 }
19761 #endif
19762
19763 /*
19764 ** Try to provide a memory barrier operation, needed for initialization only.
19765 */
19766 SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
19767 #if defined(SQLITE_MEMORY_BARRIER)
19768 SQLITE_MEMORY_BARRIER;
19769 #elif defined(__GNUC__)
19770 __sync_synchronize();
19771 #endif
19772 }
19773
19774 /*
19775 ** Initialize and deinitialize the mutex subsystem.
19776 */
19777 static int pthreadMutexInit(void){ return SQLITE_OK; }
@@ -20341,10 +20430,23 @@
20430 static int winMutexNotheld(sqlite3_mutex *p){
20431 DWORD tid = GetCurrentThreadId();
20432 return winMutexNotheld2(p, tid);
20433 }
20434 #endif
20435
20436 /*
20437 ** Try to provide a memory barrier operation, needed for initialization only.
20438 */
20439 SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
20440 #if defined(SQLITE_MEMORY_BARRIER)
20441 SQLITE_MEMORY_BARRIER;
20442 #elif defined(__GNUC__)
20443 __sync_synchronize();
20444 #else
20445 MemoryBarrier();
20446 #endif
20447 }
20448
20449 /*
20450 ** Initialize and deinitialize the mutex subsystem.
20451 */
20452 static sqlite3_mutex winMutex_staticMutexes[] = {
@@ -20695,20 +20797,11 @@
20797 /*
20798 ** State information local to the memory allocation subsystem.
20799 */
20800 static SQLITE_WSD struct Mem0Global {
20801 sqlite3_mutex *mutex; /* Mutex to serialize access */
20802 sqlite3_int64 alarmThreshold; /* The soft heap limit */
 
 
 
 
 
 
 
 
 
20803
20804 /*
20805 ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
20806 ** (so that a range test can be used to determine if an allocation
20807 ** being freed came from pScratch) and a pointer to the list of
@@ -20721,11 +20814,11 @@
20814 /*
20815 ** True if heap is nearly "full" where "full" is defined by the
20816 ** sqlite3_soft_heap_limit() setting.
20817 */
20818 int nearlyFull;
20819 } mem0 = { 0, 0, 0, 0, 0, 0 };
20820
20821 #define mem0 GLOBAL(struct Mem0Global, mem0)
20822
20823 /*
20824 ** Return the memory allocator mutex. sqlite3_status() needs it.
@@ -20732,54 +20825,25 @@
20825 */
20826 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void){
20827 return mem0.mutex;
20828 }
20829
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20830 #ifndef SQLITE_OMIT_DEPRECATED
20831 /*
20832 ** Deprecated external interface. It used to set an alarm callback
20833 ** that was invoked when memory usage grew too large. Now it is a
20834 ** no-op.
20835 */
20836 SQLITE_API int SQLITE_STDCALL sqlite3_memory_alarm(
20837 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
20838 void *pArg,
20839 sqlite3_int64 iThreshold
20840 ){
20841 (void)xCallback;
20842 (void)pArg;
20843 (void)iThreshold;
20844 return SQLITE_OK;
20845 }
20846 #endif
20847
20848 /*
20849 ** Set the soft heap-size limit for the library. Passing a zero or
@@ -20786,23 +20850,25 @@
20850 ** negative value indicates no limit.
20851 */
20852 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3_soft_heap_limit64(sqlite3_int64 n){
20853 sqlite3_int64 priorLimit;
20854 sqlite3_int64 excess;
20855 sqlite3_int64 nUsed;
20856 #ifndef SQLITE_OMIT_AUTOINIT
20857 int rc = sqlite3_initialize();
20858 if( rc ) return -1;
20859 #endif
20860 sqlite3_mutex_enter(mem0.mutex);
20861 priorLimit = mem0.alarmThreshold;
20862 if( n<0 ){
20863 sqlite3_mutex_leave(mem0.mutex);
20864 return priorLimit;
20865 }
20866 mem0.alarmThreshold = n;
20867 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20868 mem0.nearlyFull = (n>0 && n<=nUsed);
20869 sqlite3_mutex_leave(mem0.mutex);
 
 
 
 
 
 
20870 excess = sqlite3_memory_used() - n;
20871 if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
20872 return priorLimit;
20873 }
20874 SQLITE_API void SQLITE_STDCALL sqlite3_soft_heap_limit(int n){
@@ -20895,23 +20961,14 @@
20961
20962 /*
20963 ** Trigger the alarm
20964 */
20965 static void sqlite3MallocAlarm(int nByte){
20966 if( mem0.alarmThreshold<=0 ) return;
 
 
 
 
 
 
 
20967 sqlite3_mutex_leave(mem0.mutex);
20968 sqlite3_release_memory(nByte);
20969 sqlite3_mutex_enter(mem0.mutex);
 
 
20970 }
20971
20972 /*
20973 ** Do a memory allocation with statistics and alarms. Assume the
20974 ** lock is already held.
@@ -20920,11 +20977,11 @@
20977 int nFull;
20978 void *p;
20979 assert( sqlite3_mutex_held(mem0.mutex) );
20980 nFull = sqlite3GlobalConfig.m.xRoundup(n);
20981 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
20982 if( mem0.alarmThreshold>0 ){
20983 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20984 if( nUsed >= mem0.alarmThreshold - nFull ){
20985 mem0.nearlyFull = 1;
20986 sqlite3MallocAlarm(nFull);
20987 }else{
@@ -20931,11 +20988,11 @@
20988 mem0.nearlyFull = 0;
20989 }
20990 }
20991 p = sqlite3GlobalConfig.m.xMalloc(nFull);
20992 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
20993 if( p==0 && mem0.alarmThreshold>0 ){
20994 sqlite3MallocAlarm(nFull);
20995 p = sqlite3GlobalConfig.m.xMalloc(nFull);
20996 }
20997 #endif
20998 if( p ){
@@ -21106,23 +21163,24 @@
21163 SQLITE_PRIVATE int sqlite3MallocSize(void *p){
21164 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
21165 return sqlite3GlobalConfig.m.xSize(p);
21166 }
21167 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
21168 if( db==0 || !isLookaside(db,p) ){
21169 #if SQLITE_DEBUG
21170 if( db==0 ){
21171 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
21172 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
 
 
 
21173 }else{
21174 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
21175 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 
21176 }
21177 #endif
21178 return sqlite3GlobalConfig.m.xSize(p);
21179 }else{
21180 assert( sqlite3_mutex_held(db->mutex) );
21181 return db->lookaside.sz;
21182 }
21183 }
21184 SQLITE_API sqlite3_uint64 SQLITE_STDCALL sqlite3_msize(void *p){
21185 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
21186 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
@@ -21219,11 +21277,11 @@
21277 if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
21278 mem0.alarmThreshold-nDiff ){
21279 sqlite3MallocAlarm(nDiff);
21280 }
21281 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21282 if( pNew==0 && mem0.alarmThreshold>0 ){
21283 sqlite3MallocAlarm((int)nBytes);
21284 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21285 }
21286 if( pNew ){
21287 nNew = sqlite3MallocSize(pNew);
@@ -21933,25 +21991,20 @@
21991 break;
21992 }
21993 if( realvalue>0.0 ){
21994 LONGDOUBLE_TYPE scale = 1.0;
21995 while( realvalue>=1e100*scale && exp<=350 ){ scale *= 1e100;exp+=100;}
21996 while( realvalue>=1e10*scale && exp<=350 ){ scale *= 1e10; exp+=10; }
 
21997 while( realvalue>=10.0*scale && exp<=350 ){ scale *= 10.0; exp++; }
21998 realvalue /= scale;
21999 while( realvalue<1e-8 ){ realvalue *= 1e8; exp-=8; }
22000 while( realvalue<1.0 ){ realvalue *= 10.0; exp--; }
22001 if( exp>350 ){
22002 bufpt = buf;
22003 buf[0] = prefix;
22004 memcpy(buf+(prefix!=0),"Inf",4);
22005 length = 3+(prefix!=0);
 
 
 
 
22006 break;
22007 }
22008 }
22009 bufpt = buf;
22010 /*
@@ -22096,27 +22149,28 @@
22149 break;
22150 case etSTRING:
22151 case etDYNSTRING:
22152 if( bArgList ){
22153 bufpt = getTextArg(pArgList);
22154 xtype = etSTRING;
22155 }else{
22156 bufpt = va_arg(ap,char*);
22157 }
22158 if( bufpt==0 ){
22159 bufpt = "";
22160 }else if( xtype==etDYNSTRING ){
22161 zExtra = bufpt;
22162 }
22163 if( precision>=0 ){
22164 for(length=0; length<precision && bufpt[length]; length++){}
22165 }else{
22166 length = sqlite3Strlen30(bufpt);
22167 }
22168 break;
22169 case etSQLESCAPE: /* Escape ' characters */
22170 case etSQLESCAPE2: /* Escape ' and enclose in '...' */
22171 case etSQLESCAPE3: { /* Escape " characters */
22172 int i, j, k, n, isnull;
22173 int needQuote;
22174 char ch;
22175 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
22176 char *escarg;
@@ -22131,11 +22185,11 @@
22185 k = precision;
22186 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
22187 if( ch==q ) n++;
22188 }
22189 needQuote = !isnull && xtype==etSQLESCAPE2;
22190 n += i + 3;
22191 if( n>etBUFSIZE ){
22192 bufpt = zExtra = sqlite3Malloc( n );
22193 if( bufpt==0 ){
22194 setStrAccumError(pAccum, STRACCUM_NOMEM);
22195 return;
@@ -22527,11 +22581,12 @@
22581 }
22582 #endif
22583
22584
22585 /*
22586 ** variable-argument wrapper around sqlite3VXPrintf(). The bFlags argument
22587 ** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
22588 */
22589 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
22590 va_list ap;
22591 va_start(ap,zFormat);
22592 sqlite3VXPrintf(p, bFlags, zFormat, ap);
@@ -22625,94 +22680,104 @@
22680 /*
22681 ** Generate a human-readable description of a the Select object.
22682 */
22683 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){
22684 int n = 0;
22685 int cnt = 0;
22686 pView = sqlite3TreeViewPush(pView, moreToFollow);
22687 do{
22688 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x",
22689 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
22690 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags
22691 );
22692 if( cnt++ ) sqlite3TreeViewPop(pView);
22693 if( p->pPrior ){
22694 n = 1000;
22695 }else{
22696 n = 0;
22697 if( p->pSrc && p->pSrc->nSrc ) n++;
22698 if( p->pWhere ) n++;
22699 if( p->pGroupBy ) n++;
22700 if( p->pHaving ) n++;
22701 if( p->pOrderBy ) n++;
22702 if( p->pLimit ) n++;
22703 if( p->pOffset ) n++;
22704 }
22705 sqlite3TreeViewExprList(pView, p->pEList, (n--)>0, "result-set");
22706 if( p->pSrc && p->pSrc->nSrc ){
22707 int i;
22708 pView = sqlite3TreeViewPush(pView, (n--)>0);
22709 sqlite3TreeViewLine(pView, "FROM");
22710 for(i=0; i<p->pSrc->nSrc; i++){
22711 struct SrcList_item *pItem = &p->pSrc->a[i];
22712 StrAccum x;
22713 char zLine[100];
22714 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
22715 sqlite3XPrintf(&x, 0, "{%d,*}", pItem->iCursor);
22716 if( pItem->zDatabase ){
22717 sqlite3XPrintf(&x, 0, " %s.%s", pItem->zDatabase, pItem->zName);
22718 }else if( pItem->zName ){
22719 sqlite3XPrintf(&x, 0, " %s", pItem->zName);
22720 }
22721 if( pItem->pTab ){
22722 sqlite3XPrintf(&x, 0, " tabname=%Q", pItem->pTab->zName);
22723 }
22724 if( pItem->zAlias ){
22725 sqlite3XPrintf(&x, 0, " (AS %s)", pItem->zAlias);
22726 }
22727 if( pItem->fg.jointype & JT_LEFT ){
22728 sqlite3XPrintf(&x, 0, " LEFT-JOIN");
22729 }
22730 sqlite3StrAccumFinish(&x);
22731 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
22732 if( pItem->pSelect ){
22733 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
22734 }
22735 if( pItem->fg.isTabFunc ){
22736 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
22737 }
22738 sqlite3TreeViewPop(pView);
22739 }
22740 sqlite3TreeViewPop(pView);
22741 }
22742 if( p->pWhere ){
22743 sqlite3TreeViewItem(pView, "WHERE", (n--)>0);
22744 sqlite3TreeViewExpr(pView, p->pWhere, 0);
22745 sqlite3TreeViewPop(pView);
22746 }
22747 if( p->pGroupBy ){
22748 sqlite3TreeViewExprList(pView, p->pGroupBy, (n--)>0, "GROUPBY");
22749 }
22750 if( p->pHaving ){
22751 sqlite3TreeViewItem(pView, "HAVING", (n--)>0);
22752 sqlite3TreeViewExpr(pView, p->pHaving, 0);
22753 sqlite3TreeViewPop(pView);
22754 }
22755 if( p->pOrderBy ){
22756 sqlite3TreeViewExprList(pView, p->pOrderBy, (n--)>0, "ORDERBY");
22757 }
22758 if( p->pLimit ){
22759 sqlite3TreeViewItem(pView, "LIMIT", (n--)>0);
22760 sqlite3TreeViewExpr(pView, p->pLimit, 0);
22761 sqlite3TreeViewPop(pView);
22762 }
22763 if( p->pOffset ){
22764 sqlite3TreeViewItem(pView, "OFFSET", (n--)>0);
22765 sqlite3TreeViewExpr(pView, p->pOffset, 0);
22766 sqlite3TreeViewPop(pView);
22767 }
22768 if( p->pPrior ){
22769 const char *zOp = "UNION";
22770 switch( p->op ){
22771 case TK_ALL: zOp = "UNION ALL"; break;
22772 case TK_INTERSECT: zOp = "INTERSECT"; break;
22773 case TK_EXCEPT: zOp = "EXCEPT"; break;
22774 }
22775 sqlite3TreeViewItem(pView, zOp, 1);
22776 }
22777 p = p->pPrior;
22778 }while( p!=0 );
22779 sqlite3TreeViewPop(pView);
22780 }
22781
22782 /*
22783 ** Generate a human-readable explanation of an expression tree.
@@ -22783,15 +22848,10 @@
22848 }
22849 case TK_REGISTER: {
22850 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
22851 break;
22852 }
 
 
 
 
 
22853 case TK_ID: {
22854 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
22855 break;
22856 }
22857 #ifndef SQLITE_OMIT_CAST
@@ -22962,11 +23022,17 @@
23022 if( pList==0 ){
23023 sqlite3TreeViewLine(pView, "%s (empty)", zLabel);
23024 }else{
23025 sqlite3TreeViewLine(pView, "%s", zLabel);
23026 for(i=0; i<pList->nExpr; i++){
23027 int j = pList->a[i].u.x.iOrderByCol;
23028 if( j ){
23029 sqlite3TreeViewPush(pView, 0);
23030 sqlite3TreeViewLine(pView, "iOrderByCol=%d", j);
23031 }
23032 sqlite3TreeViewExpr(pView, pList->a[i].pExpr, i<pList->nExpr-1);
23033 if( j ) sqlite3TreeViewPop(pView);
23034 }
23035 }
23036 sqlite3TreeViewPop(pView);
23037 }
23038
@@ -24977,15 +25043,12 @@
25043 /*
25044 ** Return the number of bytes that will be needed to store the given
25045 ** 64-bit integer.
25046 */
25047 SQLITE_PRIVATE int sqlite3VarintLen(u64 v){
25048 int i;
25049 for(i=1; (v >>= 7)!=0; i++){ assert( i<9 ); }
 
 
 
25050 return i;
25051 }
25052
25053
25054 /*
@@ -24994,15 +25057,17 @@
25057 SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
25058 #if SQLITE_BYTEORDER==4321
25059 u32 x;
25060 memcpy(&x,p,4);
25061 return x;
25062 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
25063 && defined(__GNUC__) && GCC_VERSION>=4003000
25064 u32 x;
25065 memcpy(&x,p,4);
25066 return __builtin_bswap32(x);
25067 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
25068 && defined(_MSC_VER) && _MSC_VER>=1300
25069 u32 x;
25070 memcpy(&x,p,4);
25071 return _byteswap_ulong(x);
25072 #else
25073 testcase( p[0]&0x80 );
@@ -29103,11 +29168,10 @@
29168 i64 newOffset;
29169 #endif
29170 TIMER_START;
29171 assert( cnt==(cnt&0x1ffff) );
29172 assert( id->h>2 );
 
29173 do{
29174 #if defined(USE_PREAD)
29175 got = osPread(id->h, pBuf, cnt, offset);
29176 SimulateIOError( got = -1 );
29177 #elif defined(USE_PREAD64)
@@ -29320,20 +29384,20 @@
29384 amt -= nCopy;
29385 offset += nCopy;
29386 }
29387 }
29388 #endif
29389
29390 while( (wrote = seekAndWrite(pFile, offset, pBuf, amt))<amt && wrote>0 ){
29391 amt -= wrote;
29392 offset += wrote;
29393 pBuf = &((char*)pBuf)[wrote];
29394 }
29395 SimulateIOError(( wrote=(-1), amt=1 ));
29396 SimulateDiskfullError(( wrote=0, amt=1 ));
29397
29398 if( amt>wrote ){
29399 if( wrote<0 && pFile->lastErrno!=ENOSPC ){
29400 /* lastErrno set by seekAndWrite */
29401 return SQLITE_IOERR_WRITE;
29402 }else{
29403 storeLastErrno(pFile, 0); /* not a system error */
@@ -39798,11 +39862,11 @@
39862 ** A complete page cache is an instance of this structure.
39863 */
39864 struct PCache {
39865 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
39866 PgHdr *pSynced; /* Last synced page in dirty page list */
39867 int nRefSum; /* Sum of ref counts over all pages */
39868 int szCache; /* Configured cache size */
39869 int szPage; /* Size of every page in this cache */
39870 int szExtra; /* Size of extra space for each page */
39871 u8 bPurgeable; /* True if pages are on backing store */
39872 u8 eCreate; /* eCreate value for for xFetch() */
@@ -39963,11 +40027,11 @@
40027 /*
40028 ** Change the page size for PCache object. The caller must ensure that there
40029 ** are no outstanding page references when this function is called.
40030 */
40031 SQLITE_PRIVATE int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
40032 assert( pCache->nRefSum==0 && pCache->pDirty==0 );
40033 if( pCache->szPage ){
40034 sqlite3_pcache *pNew;
40035 pNew = sqlite3GlobalConfig.pcache2.xCreate(
40036 szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
40037 pCache->bPurgeable
@@ -40130,13 +40194,11 @@
40194 pPgHdr = (PgHdr *)pPage->pExtra;
40195
40196 if( !pPgHdr->pPage ){
40197 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
40198 }
40199 pCache->nRefSum++;
 
 
40200 pPgHdr->nRef++;
40201 return pPgHdr;
40202 }
40203
40204 /*
@@ -40143,13 +40205,12 @@
40205 ** Decrement the reference count on a page. If the page is clean and the
40206 ** reference count drops to 0, then it is made eligible for recycling.
40207 */
40208 SQLITE_PRIVATE void SQLITE_NOINLINE sqlite3PcacheRelease(PgHdr *p){
40209 assert( p->nRef>0 );
40210 p->pCache->nRefSum--;
40211 if( (--p->nRef)==0 ){
 
40212 if( p->flags&PGHDR_CLEAN ){
40213 pcacheUnpin(p);
40214 }else if( p->pDirtyPrev!=0 ){
40215 /* Move the page to the head of the dirty list. */
40216 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
@@ -40161,10 +40222,11 @@
40222 ** Increase the reference count of a supplied page by 1.
40223 */
40224 SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
40225 assert(p->nRef>0);
40226 p->nRef++;
40227 p->pCache->nRefSum++;
40228 }
40229
40230 /*
40231 ** Drop a page from the cache. There must be exactly one reference to the
40232 ** page. This function deletes that reference, so after it returns the
@@ -40173,11 +40235,11 @@
40235 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
40236 assert( p->nRef==1 );
40237 if( p->flags&PGHDR_DIRTY ){
40238 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
40239 }
40240 p->pCache->nRefSum--;
40241 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
40242 }
40243
40244 /*
40245 ** Make sure the page is marked as dirty. If it isn't dirty already,
@@ -40269,15 +40331,15 @@
40331 if( ALWAYS(p->pgno>pgno) ){
40332 assert( p->flags&PGHDR_DIRTY );
40333 sqlite3PcacheMakeClean(p);
40334 }
40335 }
40336 if( pgno==0 && pCache->nRefSum ){
40337 sqlite3_pcache_page *pPage1;
40338 pPage1 = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache,1,0);
40339 if( ALWAYS(pPage1) ){ /* Page 1 is always available in cache, because
40340 ** pCache->nRefSum>0 */
40341 memset(pPage1->pBuf, 0, pCache->szPage);
40342 pgno = 1;
40343 }
40344 }
40345 sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
@@ -40379,14 +40441,17 @@
40441 }
40442 return pcacheSortDirtyList(pCache->pDirty);
40443 }
40444
40445 /*
40446 ** Return the total number of references to all pages held by the cache.
40447 **
40448 ** This is not the total number of pages referenced, but the sum of the
40449 ** reference count for all pages.
40450 */
40451 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
40452 return pCache->nRefSum;
40453 }
40454
40455 /*
40456 ** Return the number of references to the page supplied as an argument.
40457 */
@@ -40517,11 +40582,11 @@
40582 **
40583 ** The third case is a chunk of heap memory (defaulting to 100 pages worth)
40584 ** that is allocated when the page cache is created. The size of the local
40585 ** bulk allocation can be adjusted using
40586 **
40587 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, 0, 0, N).
40588 **
40589 ** If N is positive, then N pages worth of memory are allocated using a single
40590 ** sqlite3Malloc() call and that memory is used for the first N pages allocated.
40591 ** Or if N is negative, then -1024*N bytes of memory are allocated and used
40592 ** for as many pages as can be accomodated.
@@ -40538,10 +40603,28 @@
40603
40604 typedef struct PCache1 PCache1;
40605 typedef struct PgHdr1 PgHdr1;
40606 typedef struct PgFreeslot PgFreeslot;
40607 typedef struct PGroup PGroup;
40608
40609 /*
40610 ** Each cache entry is represented by an instance of the following
40611 ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
40612 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
40613 ** in memory.
40614 */
40615 struct PgHdr1 {
40616 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
40617 unsigned int iKey; /* Key value (page number) */
40618 u8 isPinned; /* Page in use, not on the LRU list */
40619 u8 isBulkLocal; /* This page from bulk local storage */
40620 u8 isAnchor; /* This is the PGroup.lru element */
40621 PgHdr1 *pNext; /* Next in hash table chain */
40622 PCache1 *pCache; /* Cache that currently owns this page */
40623 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
40624 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
40625 };
40626
40627 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
40628 ** of one or more PCaches that are able to recycle each other's unpinned
40629 ** pages when they are under memory pressure. A PGroup is an instance of
40630 ** the following object.
@@ -40567,11 +40650,11 @@
40650 sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */
40651 unsigned int nMaxPage; /* Sum of nMax for purgeable caches */
40652 unsigned int nMinPage; /* Sum of nMin for purgeable caches */
40653 unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */
40654 unsigned int nCurrentPage; /* Number of purgeable pages allocated */
40655 PgHdr1 lru; /* The beginning and end of the LRU list */
40656 };
40657
40658 /* Each page cache is an instance of the following object. Every
40659 ** open database file (including each in-memory database and each
40660 ** temporary or transient database) has a single page cache which
@@ -40605,27 +40688,10 @@
40688 PgHdr1 **apHash; /* Hash table for fast lookup by key */
40689 PgHdr1 *pFree; /* List of unused pcache-local pages */
40690 void *pBulk; /* Bulk memory used by pcache-local */
40691 };
40692
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40693 /*
40694 ** Free slots in the allocator used to divide up the global page cache
40695 ** buffer provided using the SQLITE_CONFIG_PAGECACHE mechanism.
40696 */
40697 struct PgFreeslot {
@@ -40681,10 +40747,11 @@
40747 # define PCACHE1_MIGHT_USE_GROUP_MUTEX 1
40748 #endif
40749
40750 /******************************************************************************/
40751 /******** Page Allocation/SQLITE_CONFIG_PCACHE Related Functions **************/
40752
40753
40754 /*
40755 ** This function is called during initialization if a static buffer is
40756 ** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
40757 ** verb to sqlite3_config(). Parameter pBuf points to an allocation large
@@ -40741,10 +40808,11 @@
40808 for(i=0; i<nBulk; i++){
40809 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
40810 pX->page.pBuf = zBulk;
40811 pX->page.pExtra = &pX[1];
40812 pX->isBulkLocal = 1;
40813 pX->isAnchor = 0;
40814 pX->pNext = pCache->pFree;
40815 pCache->pFree = pX;
40816 zBulk += pCache->szAlloc;
40817 }
40818 }
@@ -40844,11 +40912,11 @@
40912 #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
40913
40914 /*
40915 ** Allocate a new page object initially associated with cache pCache.
40916 */
40917 static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
40918 PgHdr1 *p = 0;
40919 void *pPg;
40920
40921 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
40922 if( pCache->pFree || (pCache->nPage==0 && pcache1InitBulk(pCache)) ){
@@ -40862,10 +40930,11 @@
40930 ** this mutex is not held. */
40931 assert( pcache1.separateCache==0 );
40932 assert( pCache->pGroup==&pcache1.grp );
40933 pcache1LeaveMutex(pCache->pGroup);
40934 #endif
40935 if( benignMalloc ) sqlite3BeginBenignMalloc();
40936 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
40937 pPg = pcache1Alloc(pCache->szPage);
40938 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
40939 if( !pPg || !p ){
40940 pcache1Free(pPg);
@@ -40874,17 +40943,19 @@
40943 }
40944 #else
40945 pPg = pcache1Alloc(pCache->szAlloc);
40946 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
40947 #endif
40948 if( benignMalloc ) sqlite3EndBenignMalloc();
40949 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40950 pcache1EnterMutex(pCache->pGroup);
40951 #endif
40952 if( pPg==0 ) return 0;
40953 p->page.pBuf = pPg;
40954 p->page.pExtra = &p[1];
40955 p->isBulkLocal = 0;
40956 p->isAnchor = 0;
40957 }
40958 if( pCache->bPurgeable ){
40959 pCache->pGroup->nCurrentPage++;
40960 }
40961 return p;
@@ -41007,26 +41078,20 @@
41078 PCache1 *pCache;
41079
41080 assert( pPage!=0 );
41081 assert( pPage->isPinned==0 );
41082 pCache = pPage->pCache;
41083 assert( pPage->pLruNext );
41084 assert( pPage->pLruPrev );
41085 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
41086 pPage->pLruPrev->pLruNext = pPage->pLruNext;
41087 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
 
 
 
 
 
 
 
 
41088 pPage->pLruNext = 0;
41089 pPage->pLruPrev = 0;
41090 pPage->isPinned = 1;
41091 assert( pPage->isAnchor==0 );
41092 assert( pCache->pGroup->lru.isAnchor==1 );
41093 pCache->nRecyclable--;
41094 return pPage;
41095 }
41096
41097
@@ -41055,13 +41120,15 @@
41120 ** If there are currently more than nMaxPage pages allocated, try
41121 ** to recycle pages to reduce the number allocated to nMaxPage.
41122 */
41123 static void pcache1EnforceMaxPage(PCache1 *pCache){
41124 PGroup *pGroup = pCache->pGroup;
41125 PgHdr1 *p;
41126 assert( sqlite3_mutex_held(pGroup->mutex) );
41127 while( pGroup->nCurrentPage>pGroup->nMaxPage
41128 && (p=pGroup->lru.pLruPrev)->isAnchor==0
41129 ){
41130 assert( p->pCache->pGroup==pGroup );
41131 assert( p->isPinned==0 );
41132 pcache1PinPage(p);
41133 pcache1RemoveFromHash(p, 1);
41134 }
@@ -41191,10 +41258,14 @@
41258 pGroup = (PGroup*)&pCache[1];
41259 pGroup->mxPinned = 10;
41260 }else{
41261 pGroup = &pcache1.grp;
41262 }
41263 if( pGroup->lru.isAnchor==0 ){
41264 pGroup->lru.isAnchor = 1;
41265 pGroup->lru.pLruPrev = pGroup->lru.pLruNext = &pGroup->lru;
41266 }
41267 pCache->pGroup = pGroup;
41268 pCache->szPage = szPage;
41269 pCache->szExtra = szExtra;
41270 pCache->szAlloc = szPage + szExtra + ROUND8(sizeof(PgHdr1));
41271 pCache->bPurgeable = (bPurgeable ? 1 : 0);
@@ -41298,15 +41369,15 @@
41369 if( pCache->nPage>=pCache->nHash ) pcache1ResizeHash(pCache);
41370 assert( pCache->nHash>0 && pCache->apHash );
41371
41372 /* Step 4. Try to recycle a page. */
41373 if( pCache->bPurgeable
41374 && !pGroup->lru.pLruPrev->isAnchor
41375 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
41376 ){
41377 PCache1 *pOther;
41378 pPage = pGroup->lru.pLruPrev;
41379 assert( pPage->isPinned==0 );
41380 pcache1RemoveFromHash(pPage, 0);
41381 pcache1PinPage(pPage);
41382 pOther = pPage->pCache;
41383 if( pOther->szAlloc != pCache->szAlloc ){
@@ -41319,13 +41390,11 @@
41390
41391 /* Step 5. If a usable page buffer has still not been found,
41392 ** attempt to allocate a new one.
41393 */
41394 if( !pPage ){
41395 pPage = pcache1AllocPage(pCache, createFlag==1);
 
 
41396 }
41397
41398 if( pPage ){
41399 unsigned int h = iKey % pCache->nHash;
41400 pCache->nPage++;
@@ -41413,11 +41482,14 @@
41482
41483 /* Step 1: Search the hash table for an existing entry. */
41484 pPage = pCache->apHash[iKey % pCache->nHash];
41485 while( pPage && pPage->iKey!=iKey ){ pPage = pPage->pNext; }
41486
41487 /* Step 2: If the page was found in the hash table, then return it.
41488 ** If the page was not in the hash table and createFlag is 0, abort.
41489 ** Otherwise (page not in hash and createFlag!=0) continue with
41490 ** subsequent steps to try to create the page. */
41491 if( pPage ){
41492 if( !pPage->isPinned ){
41493 return pcache1PinPage(pPage);
41494 }else{
41495 return pPage;
@@ -41490,25 +41562,20 @@
41562
41563 /* It is an error to call this function if the page is already
41564 ** part of the PGroup LRU list.
41565 */
41566 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
 
41567 assert( pPage->isPinned==1 );
41568
41569 if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
41570 pcache1RemoveFromHash(pPage, 1);
41571 }else{
41572 /* Add the page to the PGroup LRU list. */
41573 PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
41574 pPage->pLruPrev = &pGroup->lru;
41575 (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
41576 *ppFirst = pPage;
 
 
 
 
41577 pCache->nRecyclable++;
41578 pPage->isPinned = 0;
41579 }
41580
41581 pcache1LeaveMutex(pCache->pGroup);
@@ -41642,11 +41709,14 @@
41709 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
41710 assert( sqlite3_mutex_notheld(pcache1.mutex) );
41711 if( sqlite3GlobalConfig.nPage==0 ){
41712 PgHdr1 *p;
41713 pcache1EnterMutex(&pcache1.grp);
41714 while( (nReq<0 || nFree<nReq)
41715 && (p=pcache1.grp.lru.pLruPrev)!=0
41716 && p->isAnchor==0
41717 ){
41718 nFree += pcache1MemSize(p->page.pBuf);
41719 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
41720 nFree += sqlite3MemSize(p);
41721 #endif
41722 assert( p->isPinned==0 );
@@ -41670,11 +41740,11 @@
41740 int *pnMin, /* OUT: Sum of PCache1.nMin for purgeable caches */
41741 int *pnRecyclable /* OUT: Total number of pages available for recycling */
41742 ){
41743 PgHdr1 *p;
41744 int nRecyclable = 0;
41745 for(p=pcache1.grp.lru.pLruNext; p && !p->isAnchor; p=p->pLruNext){
41746 assert( p->isPinned==0 );
41747 nRecyclable++;
41748 }
41749 *pnCurrent = pcache1.grp.nCurrentPage;
41750 *pnMax = (int)pcache1.grp.nMaxPage;
@@ -42984,11 +43054,11 @@
43054 u8 changeCountDone; /* Set after incrementing the change-counter */
43055 u8 setMaster; /* True if a m-j name has been written to jrnl */
43056 u8 doNotSpill; /* Do not spill the cache when non-zero */
43057 u8 subjInMemory; /* True to use in-memory sub-journals */
43058 u8 bUseFetch; /* True to use xFetch() */
43059 u8 hasHeldSharedLock; /* True if a shared lock has ever been held */
43060 Pgno dbSize; /* Number of pages in the database */
43061 Pgno dbOrigSize; /* dbSize before the current transaction */
43062 Pgno dbFileSize; /* Number of pages in the database file */
43063 Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */
43064 int errCode; /* One of several kinds of errors */
@@ -47434,14 +47504,14 @@
47504 assert( (pPager->eLock==SHARED_LOCK)
47505 || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
47506 );
47507 }
47508
47509 if( !pPager->tempFile && pPager->hasHeldSharedLock ){
47510 /* The shared-lock has just been acquired then check to
47511 ** see if the database has been modified. If the database has changed,
47512 ** flush the cache. The hasHeldSharedLock flag prevents this from
47513 ** occurring on the very first access to a file, in order to save a
47514 ** single unnecessary sqlite3OsRead() call at the start-up.
47515 **
47516 ** Database changes are detected by looking at 15 bytes beginning
47517 ** at offset 24 into the file. The first 4 of these 16 bytes are
@@ -47507,10 +47577,11 @@
47577 assert( !MEMDB );
47578 pager_unlock(pPager);
47579 assert( pPager->eState==PAGER_OPEN );
47580 }else{
47581 pPager->eState = PAGER_READER;
47582 pPager->hasHeldSharedLock = 1;
47583 }
47584 return rc;
47585 }
47586
47587 /*
@@ -47590,25 +47661,29 @@
47661
47662 /* It is acceptable to use a read-only (mmap) page for any page except
47663 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
47664 ** flag was specified by the caller. And so long as the db is not a
47665 ** temporary or in-memory database. */
47666 const int bMmapOk = (pgno>1 && USEFETCH(pPager)
47667 && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
47668 #ifdef SQLITE_HAS_CODEC
47669 && pPager->xCodec==0
47670 #endif
47671 );
47672
47673 /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
47674 ** allows the compiler optimizer to reuse the results of the "pgno>1"
47675 ** test in the previous statement, and avoid testing pgno==0 in the
47676 ** common case where pgno is large. */
47677 if( pgno<=1 && pgno==0 ){
47678 return SQLITE_CORRUPT_BKPT;
47679 }
47680 assert( pPager->eState>=PAGER_READER );
47681 assert( assert_pager_state(pPager) );
47682 assert( noContent==0 || bMmapOk==0 );
47683
47684 assert( pPager->hasHeldSharedLock==1 );
 
 
 
47685
47686 /* If the pager is in the error state, return an error immediately.
47687 ** Otherwise, request the page from the PCache layer. */
47688 if( pPager->errCode!=SQLITE_OK ){
47689 rc = pPager->errCode;
@@ -47759,11 +47834,11 @@
47834 sqlite3_pcache_page *pPage;
47835 assert( pPager!=0 );
47836 assert( pgno!=0 );
47837 assert( pPager->pPCache!=0 );
47838 pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
47839 assert( pPage==0 || pPager->hasHeldSharedLock );
47840 if( pPage==0 ) return 0;
47841 return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
47842 }
47843
47844 /*
@@ -48726,11 +48801,11 @@
48801 return pPager->readOnly;
48802 }
48803
48804 #ifdef SQLITE_DEBUG
48805 /*
48806 ** Return the sum of the reference counts for all pages held by pPager.
48807 */
48808 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager *pPager){
48809 return sqlite3PcacheRefCount(pPager->pPCache);
48810 }
48811 #endif
@@ -50038,10 +50113,11 @@
50113 u8 readOnly; /* WAL_RDWR, WAL_RDONLY, or WAL_SHM_RDONLY */
50114 u8 truncateOnCommit; /* True to truncate WAL file on commit */
50115 u8 syncHeader; /* Fsync the WAL header if true */
50116 u8 padToSectorBoundary; /* Pad transactions out to the next sector */
50117 WalIndexHdr hdr; /* Wal-index header for current transaction */
50118 u32 minFrame; /* Ignore wal frames before this one */
50119 const char *zWalName; /* Name of WAL file */
50120 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
50121 #ifdef SQLITE_DEBUG
50122 u8 lockError; /* True if a locking error has occurred */
50123 #endif
@@ -51906,16 +51982,31 @@
51982 ** copied into the database by a checkpointer. If either of these things
51983 ** happened, then reading the database with the current value of
51984 ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
51985 ** instead.
51986 **
51987 ** Before checking that the live wal-index header has not changed
51988 ** since it was read, set Wal.minFrame to the first frame in the wal
51989 ** file that has not yet been checkpointed. This client will not need
51990 ** to read any frames earlier than minFrame from the wal file - they
51991 ** can be safely read directly from the database file.
51992 **
51993 ** Because a ShmBarrier() call is made between taking the copy of
51994 ** nBackfill and checking that the wal-header in shared-memory still
51995 ** matches the one cached in pWal->hdr, it is guaranteed that the
51996 ** checkpointer that set nBackfill was not working with a wal-index
51997 ** header newer than that cached in pWal->hdr. If it were, that could
51998 ** cause a problem. The checkpointer could omit to checkpoint
51999 ** a version of page X that lies before pWal->minFrame (call that version
52000 ** A) on the basis that there is a newer version (version B) of the same
52001 ** page later in the wal file. But if version B happens to like past
52002 ** frame pWal->hdr.mxFrame - then the client would incorrectly assume
52003 ** that it can read version A from the database file. However, since
52004 ** we can guarantee that the checkpointer that set nBackfill could not
52005 ** see any pages past pWal->hdr.mxFrame, this problem does not come up.
52006 */
52007 pWal->minFrame = pInfo->nBackfill+1;
52008 walShmBarrier(pWal);
52009 if( pInfo->aReadMark[mxI]!=mxReadMark
52010 || memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
52011 ){
52012 walUnlockShared(pWal, WAL_READ_LOCK(mxI));
@@ -51982,10 +52073,11 @@
52073 u32 *piRead /* OUT: Frame number (or zero) */
52074 ){
52075 u32 iRead = 0; /* If !=0, WAL frame to return data from */
52076 u32 iLast = pWal->hdr.mxFrame; /* Last page in WAL for this reader */
52077 int iHash; /* Used to loop through N hash tables */
52078 int iMinHash;
52079
52080 /* This routine is only be called from within a read transaction. */
52081 assert( pWal->readLock>=0 || pWal->lockError );
52082
52083 /* If the "last page" field of the wal-index header snapshot is 0, then
@@ -52022,11 +52114,12 @@
52114 **
52115 ** (iFrame<=iLast):
52116 ** This condition filters out entries that were added to the hash
52117 ** table after the current read-transaction had started.
52118 */
52119 iMinHash = walFramePage(pWal->minFrame);
52120 for(iHash=walFramePage(iLast); iHash>=iMinHash && iRead==0; iHash--){
52121 volatile ht_slot *aHash; /* Pointer to hash table */
52122 volatile u32 *aPgno; /* Pointer to array of page numbers */
52123 u32 iZero; /* Frame number corresponding to aPgno[0] */
52124 int iKey; /* Hash slot index */
52125 int nCollide; /* Number of hash collisions remaining */
@@ -52037,11 +52130,11 @@
52130 return rc;
52131 }
52132 nCollide = HASHTABLE_NSLOT;
52133 for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
52134 u32 iFrame = aHash[iKey] + iZero;
52135 if( iFrame<=iLast && iFrame>=pWal->minFrame && aPgno[aHash[iKey]]==pgno ){
52136 assert( iFrame>iRead || CORRUPT_DB );
52137 iRead = iFrame;
52138 }
52139 if( (nCollide--)==0 ){
52140 return SQLITE_CORRUPT_BKPT;
@@ -52054,11 +52147,12 @@
52147 ** of the wal-index file content. Make sure the results agree with the
52148 ** result obtained using the hash indexes above. */
52149 {
52150 u32 iRead2 = 0;
52151 u32 iTest;
52152 assert( pWal->minFrame>0 );
52153 for(iTest=iLast; iTest>=pWal->minFrame; iTest--){
52154 if( walFramePgno(pWal, iTest)==pgno ){
52155 iRead2 = iTest;
52156 break;
52157 }
52158 }
@@ -53494,13 +53588,15 @@
53588 ** two-byte aligned address. get2bytea() is only used for accessing the
53589 ** cell addresses in a btree header.
53590 */
53591 #if SQLITE_BYTEORDER==4321
53592 # define get2byteAligned(x) (*(u16*)(x))
53593 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
53594 && GCC_VERSION>=4008000
53595 # define get2byteAligned(x) __builtin_bswap16(*(u16*)(x))
53596 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
53597 && defined(_MSC_VER) && _MSC_VER>=1300
53598 # define get2byteAligned(x) _byteswap_ushort(*(u16*)(x))
53599 #else
53600 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
53601 #endif
53602
@@ -62492,21 +62588,19 @@
62588 IntegrityCk *pCheck,
62589 const char *zFormat,
62590 ...
62591 ){
62592 va_list ap;
 
62593 if( !pCheck->mxErr ) return;
62594 pCheck->mxErr--;
62595 pCheck->nErr++;
62596 va_start(ap, zFormat);
62597 if( pCheck->errMsg.nChar ){
62598 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
62599 }
62600 if( pCheck->zPfx ){
62601 sqlite3XPrintf(&pCheck->errMsg, 0, pCheck->zPfx, pCheck->v1, pCheck->v2);
 
62602 }
62603 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
62604 va_end(ap);
62605 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
62606 pCheck->mallocFailed = 1;
@@ -65327,11 +65421,11 @@
65421 /*
65422 ** The expression object indicated by the second argument is guaranteed
65423 ** to be a scalar SQL function. If
65424 **
65425 ** * all function arguments are SQL literals,
65426 ** * one of the SQLITE_FUNC_CONSTANT or _SLOCHNG function flags is set, and
65427 ** * the SQLITE_FUNC_NEEDCOLL function flag is not set,
65428 **
65429 ** then this routine attempts to invoke the SQL function. Assuming no
65430 ** error occurs, output parameter (*ppVal) is set to point to a value
65431 ** object containing the result before returning SQLITE_OK.
@@ -65368,11 +65462,11 @@
65462 pList = p->x.pList;
65463 if( pList ) nVal = pList->nExpr;
65464 nName = sqlite3Strlen30(p->u.zToken);
65465 pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
65466 assert( pFunc );
65467 if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
65468 || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
65469 ){
65470 return SQLITE_OK;
65471 }
65472
@@ -65962,11 +66056,11 @@
66056 /*
66057 ** Return the SQL associated with a prepared statement
66058 */
66059 SQLITE_API const char *SQLITE_STDCALL sqlite3_sql(sqlite3_stmt *pStmt){
66060 Vdbe *p = (Vdbe *)pStmt;
66061 return p ? p->zSql : 0;
66062 }
66063
66064 /*
66065 ** Swap all content between two VDBE structures.
66066 */
@@ -66109,10 +66203,48 @@
66203 }
66204 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe *p, int op, int p1, int p2){
66205 return sqlite3VdbeAddOp3(p, op, p1, p2, 0);
66206 }
66207
66208 /* Generate code for an unconditional jump to instruction iDest
66209 */
66210 SQLITE_PRIVATE int sqlite3VdbeGoto(Vdbe *p, int iDest){
66211 return sqlite3VdbeAddOp3(p, OP_Goto, 0, iDest, 0);
66212 }
66213
66214 /* Generate code to cause the string zStr to be loaded into
66215 ** register iDest
66216 */
66217 SQLITE_PRIVATE int sqlite3VdbeLoadString(Vdbe *p, int iDest, const char *zStr){
66218 return sqlite3VdbeAddOp4(p, OP_String8, 0, iDest, 0, zStr, 0);
66219 }
66220
66221 /*
66222 ** Generate code that initializes multiple registers to string or integer
66223 ** constants. The registers begin with iDest and increase consecutively.
66224 ** One register is initialized for each characgter in zTypes[]. For each
66225 ** "s" character in zTypes[], the register is a string if the argument is
66226 ** not NULL, or OP_Null if the value is a null pointer. For each "i" character
66227 ** in zTypes[], the register is initialized to an integer.
66228 */
66229 SQLITE_PRIVATE void sqlite3VdbeMultiLoad(Vdbe *p, int iDest, const char *zTypes, ...){
66230 va_list ap;
66231 int i;
66232 char c;
66233 va_start(ap, zTypes);
66234 for(i=0; (c = zTypes[i])!=0; i++){
66235 if( c=='s' ){
66236 const char *z = va_arg(ap, const char*);
66237 int addr = sqlite3VdbeAddOp2(p, z==0 ? OP_Null : OP_String8, 0, iDest++);
66238 if( z ) sqlite3VdbeChangeP4(p, addr, z, 0);
66239 }else{
66240 assert( c=='i' );
66241 sqlite3VdbeAddOp2(p, OP_Integer, va_arg(ap, int), iDest++);
66242 }
66243 }
66244 va_end(ap);
66245 }
66246
66247 /*
66248 ** Add an opcode that includes the p4 value as a pointer.
66249 */
66250 SQLITE_PRIVATE int sqlite3VdbeAddOp4(
@@ -66128,11 +66260,12 @@
66260 sqlite3VdbeChangeP4(p, addr, zP4, p4type);
66261 return addr;
66262 }
66263
66264 /*
66265 ** Add an opcode that includes the p4 value with a P4_INT64 or
66266 ** P4_REAL type.
66267 */
66268 SQLITE_PRIVATE int sqlite3VdbeAddOp4Dup8(
66269 Vdbe *p, /* Add the opcode to this VM */
66270 int op, /* The new opcode */
66271 int p1, /* The P1 operand */
@@ -66213,11 +66346,12 @@
66346 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
66347 Parse *p = v->pParse;
66348 int j = -1-x;
66349 assert( v->magic==VDBE_MAGIC_INIT );
66350 assert( j<p->nLabel );
66351 assert( j>=0 );
66352 if( p->aLabel ){
66353 p->aLabel[j] = v->nOp;
66354 }
66355 p->iFixedOp = v->nOp - 1;
66356 }
66357
@@ -66357,21 +66491,25 @@
66491 || (hasCreateTable && hasInitCoroutine) );
66492 }
66493 #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
66494
66495 /*
66496 ** This routine is called after all opcodes have been inserted. It loops
66497 ** through all the opcodes and fixes up some details.
66498 **
66499 ** (1) For each jump instruction with a negative P2 value (a label)
66500 ** resolve the P2 value to an actual address.
66501 **
66502 ** (2) Compute the maximum number of arguments used by any SQL function
66503 ** and store that value in *pMaxFuncArgs.
66504 **
66505 ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
66506 ** indicate what the prepared statement actually does.
66507 **
66508 ** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
66509 **
66510 ** (5) Reclaim the memory allocated for storing labels.
66511 */
66512 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
66513 int i;
66514 int nMaxArgs = *pMaxFuncArgs;
66515 Op *pOp;
@@ -66480,50 +66618,48 @@
66618 /*
66619 ** Add a whole list of operations to the operation stack. Return the
66620 ** address of the first operation added.
66621 */
66622 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
66623 int addr, i;
66624 VdbeOp *pOut;
66625 assert( nOp>0 );
66626 assert( p->magic==VDBE_MAGIC_INIT );
66627 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p, nOp) ){
66628 return 0;
66629 }
66630 addr = p->nOp;
66631 pOut = &p->aOp[addr];
66632 for(i=0; i<nOp; i++, aOp++, pOut++){
66633 int p2 = aOp->p2;
66634 pOut->opcode = aOp->opcode;
66635 pOut->p1 = aOp->p1;
66636 if( p2<0 ){
66637 assert( sqlite3OpcodeProperty[pOut->opcode] & OPFLG_JUMP );
66638 pOut->p2 = addr + ADDR(p2);
66639 }else{
66640 pOut->p2 = p2;
66641 }
66642 pOut->p3 = aOp->p3;
66643 pOut->p4type = P4_NOTUSED;
66644 pOut->p4.p = 0;
66645 pOut->p5 = 0;
 
 
 
66646 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
66647 pOut->zComment = 0;
66648 #endif
66649 #ifdef SQLITE_VDBE_COVERAGE
66650 pOut->iSrcLine = iLineno+i;
66651 #else
66652 (void)iLineno;
66653 #endif
66654 #ifdef SQLITE_DEBUG
66655 if( p->db->flags & SQLITE_VdbeAddopTrace ){
66656 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
66657 }
66658 #endif
 
 
66659 }
66660 p->nOp += nOp;
66661 return addr;
66662 }
66663
66664 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
66665 /*
@@ -66552,62 +66688,36 @@
66688 }
66689 #endif
66690
66691
66692 /*
66693 ** Change the value of the opcode, or P1, P2, P3, or P5 operands
66694 ** for a specific instruction.
 
 
66695 */
66696 SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *p, u32 addr, u8 iNewOpcode){
66697 sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
66698 }
66699 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, u32 addr, int val){
66700 sqlite3VdbeGetOp(p,addr)->p1 = val;
66701 }
 
 
 
 
 
 
 
 
66702 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, u32 addr, int val){
66703 sqlite3VdbeGetOp(p,addr)->p2 = val;
66704 }
 
 
 
 
 
 
 
66705 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
66706 sqlite3VdbeGetOp(p,addr)->p3 = val;
66707 }
66708 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){
66709 sqlite3VdbeGetOp(p,-1)->p5 = p5;
 
 
 
 
 
 
 
 
 
 
 
 
66710 }
66711
66712 /*
66713 ** Change the P2 operand of instruction addr so that it points to
66714 ** the address of the next instruction to be coded.
66715 */
66716 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){
 
66717 p->pParse->iFixedOp = p->nOp - 1;
66718 sqlite3VdbeChangeP2(p, addr, p->nOp);
66719 }
66720
66721
66722 /*
66723 ** If the input FuncDef structure is ephemeral, then free it. If
@@ -66988,12 +67098,13 @@
67098 int n = sqlite3Strlen30(zColl);
67099 if( n==6 && memcmp(zColl,"BINARY",6)==0 ){
67100 zColl = "B";
67101 n = 1;
67102 }
67103 if( i+n>nTemp-7 ){
67104 memcpy(&zTemp[i],",...",4);
67105 i += 4;
67106 break;
67107 }
67108 zTemp[i++] = ',';
67109 if( pKeyInfo->aSortOrder[j] ){
67110 zTemp[i++] = '-';
@@ -70329,10 +70440,13 @@
70440 SQLITE_API int SQLITE_STDCALL sqlite3_value_int(sqlite3_value *pVal){
70441 return (int)sqlite3VdbeIntValue((Mem*)pVal);
70442 }
70443 SQLITE_API sqlite_int64 SQLITE_STDCALL sqlite3_value_int64(sqlite3_value *pVal){
70444 return sqlite3VdbeIntValue((Mem*)pVal);
70445 }
70446 SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value *pVal){
70447 return ((Mem*)pVal)->eSubtype;
70448 }
70449 SQLITE_API const unsigned char *SQLITE_STDCALL sqlite3_value_text(sqlite3_value *pVal){
70450 return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
70451 }
70452 #ifndef SQLITE_OMIT_UTF16
@@ -70507,10 +70621,14 @@
70621 sqlite3VdbeMemSetInt64(pCtx->pOut, iVal);
70622 }
70623 SQLITE_API void SQLITE_STDCALL sqlite3_result_null(sqlite3_context *pCtx){
70624 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
70625 sqlite3VdbeMemSetNull(pCtx->pOut);
70626 }
70627 SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context *pCtx, unsigned int eSubtype){
70628 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
70629 pCtx->pOut->eSubtype = eSubtype & 0xff;
70630 }
70631 SQLITE_API void SQLITE_STDCALL sqlite3_result_text(
70632 sqlite3_context *pCtx,
70633 const char *z,
70634 int n,
@@ -70754,11 +70872,11 @@
70872 ** be one of the values in the first assert() below. Variable p->rc
70873 ** contains the value that would be returned if sqlite3_finalize()
70874 ** were called on statement p.
70875 */
70876 assert( rc==SQLITE_ROW || rc==SQLITE_DONE || rc==SQLITE_ERROR
70877 || (rc&0xff)==SQLITE_BUSY || rc==SQLITE_MISUSE
70878 );
70879 assert( (p->rc!=SQLITE_ROW && p->rc!=SQLITE_DONE) || p->rc==p->rcApp );
70880 if( p->isPrepareV2 && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){
70881 /* If this statement was prepared using sqlite3_prepare_v2(), and an
70882 ** error has occurred, then return the error code in p->rc to the
@@ -70839,11 +70957,11 @@
70957 ** parameter) of the sqlite3_create_function() and
70958 ** sqlite3_create_function16() routines that originally registered the
70959 ** application defined function.
70960 */
70961 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3_context_db_handle(sqlite3_context *p){
70962 assert( p && p->pOut );
70963 return p->pOut->db;
70964 }
70965
70966 /*
70967 ** Return the current time for a statement. If the current time
@@ -72657,11 +72775,11 @@
72775 if( p->rc==SQLITE_NOMEM ){
72776 /* This happens if a malloc() inside a call to sqlite3_column_text() or
72777 ** sqlite3_column_text16() failed. */
72778 goto no_mem;
72779 }
72780 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
72781 assert( p->bIsReader || p->readOnly!=0 );
72782 p->rc = SQLITE_OK;
72783 p->iCurrentTime = 0;
72784 assert( p->explain==0 );
72785 p->pResultSet = 0;
@@ -75094,16 +75212,16 @@
75212 db->autoCommit = 1;
75213 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
75214 goto vdbe_return;
75215 }else{
75216 db->autoCommit = (u8)desiredAutoCommit;
75217 }
75218 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
75219 p->pc = (int)(pOp - aOp);
75220 db->autoCommit = (u8)(1-desiredAutoCommit);
75221 p->rc = rc = SQLITE_BUSY;
75222 goto vdbe_return;
75223 }
75224 assert( db->nStatement==0 );
75225 sqlite3CloseSavepoints(db);
75226 if( p->rc==SQLITE_OK ){
75227 rc = SQLITE_DONE;
@@ -75171,13 +75289,15 @@
75289 }
75290 pBt = db->aDb[pOp->p1].pBt;
75291
75292 if( pBt ){
75293 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
75294 testcase( rc==SQLITE_BUSY_SNAPSHOT );
75295 testcase( rc==SQLITE_BUSY_RECOVERY );
75296 if( (rc&0xff)==SQLITE_BUSY ){
75297 p->pc = (int)(pOp - aOp);
75298 p->rc = rc;
75299 goto vdbe_return;
75300 }
75301 if( rc!=SQLITE_OK ){
75302 goto abort_due_to_error;
75303 }
@@ -79009,11 +79129,12 @@
79129 }
79130 #endif
79131 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
79132 int j;
79133 for(j=0; j<pIdx->nKeyCol; j++){
79134 /* FIXME: Be smarter about indexes that use expressions */
79135 if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==(-2) ){
79136 zFault = "indexed";
79137 }
79138 }
79139 }
79140 if( zFault ){
@@ -82590,10 +82711,15 @@
82711 if( ALWAYS(pSrc) ){
82712 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
82713 if( sqlite3WalkSelect(pWalker, pItem->pSelect) ){
82714 return WRC_Abort;
82715 }
82716 if( pItem->fg.isTabFunc
82717 && sqlite3WalkExprList(pWalker, pItem->u1.pFuncArg)
82718 ){
82719 return WRC_Abort;
82720 }
82721 }
82722 }
82723 return WRC_Continue;
82724 }
82725
@@ -82687,34 +82813,10 @@
82813
82814 /*
82815 ** Turn the pExpr expression into an alias for the iCol-th column of the
82816 ** result set in pEList.
82817 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82818 ** If the reference is followed by a COLLATE operator, then make sure
82819 ** the COLLATE operator is preserved. For example:
82820 **
82821 ** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
82822 **
@@ -82744,23 +82846,15 @@
82846 pOrig = pEList->a[iCol].pExpr;
82847 assert( pOrig!=0 );
82848 db = pParse->db;
82849 pDup = sqlite3ExprDup(db, pOrig, 0);
82850 if( pDup==0 ) return;
82851 if( zType[0]!='G' ) incrAggFunctionDepth(pDup, nSubquery);
 
 
 
 
 
 
 
 
 
82852 if( pExpr->op==TK_COLLATE ){
82853 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
82854 }
82855 ExprSetProperty(pDup, EP_Alias);
82856
82857 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
82858 ** prevents ExprDelete() from deleting the Expr structure itself,
82859 ** allowing it to be repopulated by the memcpy() on the following line.
82860 ** The pExpr->u.zToken might point into memory that will be freed by the
@@ -82948,11 +83042,11 @@
83042 /* If there has been exactly one prior match and this match
83043 ** is for the right-hand table of a NATURAL JOIN or is in a
83044 ** USING clause, then skip this match.
83045 */
83046 if( cnt==1 ){
83047 if( pItem->fg.jointype & JT_NATURAL ) continue;
83048 if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
83049 }
83050 cnt++;
83051 pMatch = pItem;
83052 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
@@ -82963,12 +83057,12 @@
83057 }
83058 if( pMatch ){
83059 pExpr->iTable = pMatch->iCursor;
83060 pExpr->pTab = pMatch->pTab;
83061 /* RIGHT JOIN not (yet) supported */
83062 assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
83063 if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
83064 ExprSetProperty(pExpr, EP_CanBeNull);
83065 }
83066 pSchema = pExpr->pTab->pSchema;
83067 }
83068 } /* if( pSrcList ) */
@@ -83049,13 +83143,13 @@
83143 ** forms the result set entry ("a+b" in the example) and return immediately.
83144 ** Note that the expression in the result set should have already been
83145 ** resolved by the time the WHERE clause is resolved.
83146 **
83147 ** The ability to use an output result-set column in the WHERE, GROUP BY,
83148 ** or HAVING clauses, or as part of a larger expression in the ORDER BY
83149 ** clause is not standard SQL. This is a (goofy) SQLite extension, that
83150 ** is supported for backwards compatibility only. Hence, we issue a warning
83151 ** on sqlite3_log() whenever the capability is used.
83152 */
83153 if( (pEList = pNC->pEList)!=0
83154 && zTab==0
83155 && cnt==0
@@ -83148,11 +83242,11 @@
83242 pExpr->pRight = 0;
83243 pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
83244 lookupname_end:
83245 if( cnt==1 ){
83246 assert( pNC!=0 );
83247 if( !ExprHasProperty(pExpr, EP_Alias) ){
83248 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
83249 }
83250 /* Increment the nRef value on all name contexts from TopNC up to
83251 ** the point where the name matched. */
83252 for(;;){
@@ -83189,40 +83283,29 @@
83283 }
83284 return p;
83285 }
83286
83287 /*
83288 ** Report an error that an expression is not valid for some set of
83289 ** pNC->ncFlags values determined by validMask.
83290 */
83291 static void notValid(
83292 Parse *pParse, /* Leave error message here */
83293 NameContext *pNC, /* The name context */
83294 const char *zMsg, /* Type of error */
83295 int validMask /* Set of contexts for which prohibited */
83296 ){
83297 assert( (validMask&~(NC_IsCheck|NC_PartIdx|NC_IdxExpr))==0 );
83298 if( (pNC->ncFlags & validMask)!=0 ){
83299 const char *zIn = "partial index WHERE clauses";
83300 if( pNC->ncFlags & NC_IdxExpr ) zIn = "index expressions";
83301 #ifndef SQLITE_OMIT_CHECK
83302 else if( pNC->ncFlags & NC_IsCheck ) zIn = "CHECK constraints";
83303 #endif
83304 sqlite3ErrorMsg(pParse, "%s prohibited in %s", zMsg, zIn);
83305 }
83306 }
 
 
 
 
 
 
 
 
 
 
 
83307
83308 /*
83309 ** Expression p should encode a floating point value between 1.0 and 0.0.
83310 ** Return 1024 times this value. Or return -1 if p is not a floating point
83311 ** value between 1.0 and 0.0.
@@ -83303,10 +83386,12 @@
83386 const char *zTable;
83387 const char *zDb;
83388 Expr *pRight;
83389
83390 /* if( pSrcList==0 ) break; */
83391 notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr);
83392 /*notValid(pParse, pNC, "the \".\" operator", NC_PartIdx|NC_IsCheck, 1);*/
83393 pRight = pExpr->pRight;
83394 if( pRight->op==TK_ID ){
83395 zDb = 0;
83396 zTable = pExpr->pLeft->u.zToken;
83397 zColumn = pRight->u.zToken;
@@ -83332,11 +83417,11 @@
83417 const char *zId; /* The function name. */
83418 FuncDef *pDef; /* Information about the function */
83419 u8 enc = ENC(pParse->db); /* The database encoding */
83420
83421 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
83422 notValid(pParse, pNC, "functions", NC_PartIdx);
83423 zId = pExpr->u.zToken;
83424 nId = sqlite3Strlen30(zId);
83425 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
83426 if( pDef==0 ){
83427 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
@@ -83380,13 +83465,22 @@
83465 }
83466 pExpr->op = TK_NULL;
83467 return WRC_Prune;
83468 }
83469 #endif
83470 if( pDef->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) ){
83471 /* For the purposes of the EP_ConstFunc flag, date and time
83472 ** functions and other functions that change slowly are considered
83473 ** constant because they are constant for the duration of one query */
83474 ExprSetProperty(pExpr,EP_ConstFunc);
83475 }
83476 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
83477 /* Date/time functions that use 'now', and other functions like
83478 ** sqlite_version() that might change over time cannot be used
83479 ** in an index. */
83480 notValid(pParse, pNC, "non-deterministic functions", NC_IdxExpr);
83481 }
83482 }
83483 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
83484 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
83485 pNC->nErr++;
83486 is_agg = 0;
@@ -83428,23 +83522,21 @@
83522 #endif
83523 case TK_IN: {
83524 testcase( pExpr->op==TK_IN );
83525 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
83526 int nRef = pNC->nRef;
83527 notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
 
83528 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
83529 assert( pNC->nRef>=nRef );
83530 if( nRef!=pNC->nRef ){
83531 ExprSetProperty(pExpr, EP_VarSelect);
83532 }
83533 }
83534 break;
83535 }
83536 case TK_VARIABLE: {
83537 notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
 
83538 break;
83539 }
83540 }
83541 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
83542 }
@@ -83784,11 +83876,10 @@
83876 NameContext *pOuterNC; /* Context that contains this SELECT */
83877 NameContext sNC; /* Name context of this SELECT */
83878 int isCompound; /* True if p is a compound select */
83879 int nCompound; /* Number of compound terms processed so far */
83880 Parse *pParse; /* Parsing context */
 
83881 int i; /* Loop counter */
83882 ExprList *pGroupBy; /* The GROUP BY clause */
83883 Select *pLeftmost; /* Left-most of SELECT of a compound */
83884 sqlite3 *db; /* Database connection */
83885
@@ -83857,21 +83948,21 @@
83948
83949 /* Count the total number of references to pOuterNC and all of its
83950 ** parent contexts. After resolving references to expressions in
83951 ** pItem->pSelect, check if this value has changed. If so, then
83952 ** SELECT statement pItem->pSelect must be correlated. Set the
83953 ** pItem->fg.isCorrelated flag if this is the case. */
83954 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef += pNC->nRef;
83955
83956 if( pItem->zName ) pParse->zAuthContext = pItem->zName;
83957 sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
83958 pParse->zAuthContext = zSavedContext;
83959 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
83960
83961 for(pNC=pOuterNC; pNC; pNC=pNC->pNext) nRef -= pNC->nRef;
83962 assert( pItem->fg.isCorrelated==0 && nRef<=0 );
83963 pItem->fg.isCorrelated = (nRef!=0);
83964 }
83965 }
83966
83967 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
83968 ** resolve the result-set expression list.
@@ -83879,18 +83970,11 @@
83970 sNC.ncFlags = NC_AllowAgg;
83971 sNC.pSrcList = p->pSrc;
83972 sNC.pNext = pOuterNC;
83973
83974 /* Resolve names in the result set. */
83975 if( sqlite3ResolveExprListNames(&sNC, p->pEList) ) return WRC_Abort;
 
 
 
 
 
 
 
83976
83977 /* If there are no aggregate functions in the result-set, and no GROUP BY
83978 ** expression, do not allow aggregates in any of the other expressions.
83979 */
83980 assert( (p->selFlags & SF_Aggregate)==0 );
@@ -83918,10 +84002,20 @@
84002 ** re-evaluated for each reference to it.
84003 */
84004 sNC.pEList = p->pEList;
84005 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
84006 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
84007
84008 /* Resolve names in table-valued-function arguments */
84009 for(i=0; i<p->pSrc->nSrc; i++){
84010 struct SrcList_item *pItem = &p->pSrc->a[i];
84011 if( pItem->fg.isTabFunc
84012 && sqlite3ResolveExprListNames(&sNC, pItem->u1.pFuncArg)
84013 ){
84014 return WRC_Abort;
84015 }
84016 }
84017
84018 /* The ORDER BY and GROUP BY clauses may not refer to terms in
84019 ** outer queries
84020 */
84021 sNC.pNext = 0;
@@ -84082,10 +84176,26 @@
84176 }
84177 pNC->ncFlags |= savedHasAgg;
84178 return ExprHasProperty(pExpr, EP_Error);
84179 }
84180
84181 /*
84182 ** Resolve all names for all expression in an expression list. This is
84183 ** just like sqlite3ResolveExprNames() except that it works for an expression
84184 ** list rather than a single expression.
84185 */
84186 SQLITE_PRIVATE int sqlite3ResolveExprListNames(
84187 NameContext *pNC, /* Namespace to resolve expressions in. */
84188 ExprList *pList /* The expression list to be analyzed. */
84189 ){
84190 int i;
84191 assert( pList!=0 );
84192 for(i=0; i<pList->nExpr; i++){
84193 if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
84194 }
84195 return WRC_Continue;
84196 }
84197
84198 /*
84199 ** Resolve all names in all expressions of a SELECT and in all
84200 ** decendents of the SELECT, including compounds off of p->pPrior,
84201 ** subqueries in expressions, and subqueries used as FROM clause
@@ -84125,19 +84235,18 @@
84235 ** Any errors cause an error message to be set in pParse.
84236 */
84237 SQLITE_PRIVATE void sqlite3ResolveSelfReference(
84238 Parse *pParse, /* Parsing context */
84239 Table *pTab, /* The table being referenced */
84240 int type, /* NC_IsCheck or NC_PartIdx or NC_IdxExpr */
84241 Expr *pExpr, /* Expression to resolve. May be NULL. */
84242 ExprList *pList /* Expression list to resolve. May be NUL. */
84243 ){
84244 SrcList sSrc; /* Fake SrcList for pParse->pNewTable */
84245 NameContext sNC; /* Name context for pParse->pNewTable */
 
84246
84247 assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr );
84248 memset(&sNC, 0, sizeof(sNC));
84249 memset(&sSrc, 0, sizeof(sSrc));
84250 sSrc.nSrc = 1;
84251 sSrc.a[0].zName = pTab->zName;
84252 sSrc.a[0].pTab = pTab;
@@ -84144,17 +84253,11 @@
84253 sSrc.a[0].iCursor = -1;
84254 sNC.pParse = pParse;
84255 sNC.pSrcList = &sSrc;
84256 sNC.ncFlags = type;
84257 if( sqlite3ResolveExprNames(&sNC, pExpr) ) return;
84258 if( pList ) sqlite3ResolveExprListNames(&sNC, pList);
 
 
 
 
 
 
84259 }
84260
84261 /************** End of resolve.c *********************************************/
84262 /************** Begin file expr.c ********************************************/
84263 /*
@@ -84248,11 +84351,11 @@
84351 s.n = sqlite3Strlen30(s.z);
84352 return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
84353 }
84354
84355 /*
84356 ** Skip over any TK_COLLATE operators and any unlikely()
84357 ** or likelihood() function at the root of an expression.
84358 */
84359 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
84360 while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
84361 if( ExprHasProperty(pExpr, EP_Unlikely) ){
@@ -84259,11 +84362,11 @@
84362 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
84363 assert( pExpr->x.pList->nExpr>0 );
84364 assert( pExpr->op==TK_FUNCTION );
84365 pExpr = pExpr->x.pList->a[0].pExpr;
84366 }else{
84367 assert( pExpr->op==TK_COLLATE );
84368 pExpr = pExpr->pLeft;
84369 }
84370 }
84371 return pExpr;
84372 }
@@ -84590,11 +84693,11 @@
84693 ** for this node and for the pToken argument is a single allocation
84694 ** obtained from sqlite3DbMalloc(). The calling function
84695 ** is responsible for making sure the node eventually gets freed.
84696 **
84697 ** If dequote is true, then the token (if it exists) is dequoted.
84698 ** If dequote is false, no dequoting is performed. The deQuote
84699 ** parameter is ignored if pToken is NULL or if the token does not
84700 ** appear to be quoted. If the quotes were of the form "..." (double-quotes)
84701 ** then the EP_DblQuoted flag is set on the expression node.
84702 **
84703 ** Special case: If op==TK_INTEGER and pToken points to a string that
@@ -85191,20 +85294,22 @@
85294 Table *pTab;
85295 pNewItem->pSchema = pOldItem->pSchema;
85296 pNewItem->zDatabase = sqlite3DbStrDup(db, pOldItem->zDatabase);
85297 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
85298 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias);
85299 pNewItem->fg = pOldItem->fg;
85300 pNewItem->iCursor = pOldItem->iCursor;
85301 pNewItem->addrFillSub = pOldItem->addrFillSub;
85302 pNewItem->regReturn = pOldItem->regReturn;
85303 if( pNewItem->fg.isIndexedBy ){
85304 pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
85305 }
85306 pNewItem->pIBIndex = pOldItem->pIBIndex;
85307 if( pNewItem->fg.isTabFunc ){
85308 pNewItem->u1.pFuncArg =
85309 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
85310 }
85311 pTab = pNewItem->pTab = pOldItem->pTab;
85312 if( pTab ){
85313 pTab->nRef++;
85314 }
85315 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
@@ -85314,10 +85419,24 @@
85419 /* Avoid leaking memory if malloc has failed. */
85420 sqlite3ExprDelete(db, pExpr);
85421 sqlite3ExprListDelete(db, pList);
85422 return 0;
85423 }
85424
85425 /*
85426 ** Set the sort order for the last element on the given ExprList.
85427 */
85428 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList *p, int iSortOrder){
85429 if( p==0 ) return;
85430 assert( SQLITE_SO_UNDEFINED<0 && SQLITE_SO_ASC>=0 && SQLITE_SO_DESC>0 );
85431 assert( p->nExpr>0 );
85432 if( iSortOrder<0 ){
85433 assert( p->a[p->nExpr-1].sortOrder==SQLITE_SO_ASC );
85434 return;
85435 }
85436 p->a[p->nExpr-1].sortOrder = (u8)iSortOrder;
85437 }
85438
85439 /*
85440 ** Set the ExprList.a[].zName element of the most recently added item
85441 ** on the expression list.
85442 **
@@ -86286,11 +86405,11 @@
86405 }
86406 sqlite3ReleaseTempReg(pParse, regToFree);
86407 }
86408 if( regCkNull ){
86409 sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v);
86410 sqlite3VdbeGoto(v, destIfFalse);
86411 }
86412 sqlite3VdbeResolveLabel(v, labelOk);
86413 sqlite3ReleaseTempReg(pParse, regCkNull);
86414 }else{
86415
@@ -86304,11 +86423,11 @@
86423 sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
86424 }else{
86425 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
86426 sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
86427 VdbeCoverage(v);
86428 sqlite3VdbeGoto(v, destIfNull);
86429 sqlite3VdbeJumpHere(v, addr1);
86430 }
86431 }
86432
86433 if( eType==IN_INDEX_ROWID ){
@@ -86354,11 +86473,11 @@
86473 */
86474 j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
86475 VdbeCoverage(v);
86476 sqlite3VdbeAddOp2(v, OP_IsNull, rRhsHasNull, destIfNull);
86477 VdbeCoverage(v);
86478 sqlite3VdbeGoto(v, destIfFalse);
86479 sqlite3VdbeJumpHere(v, j1);
86480 }
86481 }
86482 }
86483 sqlite3ReleaseTempReg(pParse, r1);
@@ -86572,10 +86691,32 @@
86691 if( p->iReg==iReg ){
86692 p->tempReg = 0;
86693 }
86694 }
86695 }
86696
86697 /* Generate code that will load into register regOut a value that is
86698 ** appropriate for the iIdxCol-th column of index pIdx.
86699 */
86700 SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(
86701 Parse *pParse, /* The parsing context */
86702 Index *pIdx, /* The index whose column is to be loaded */
86703 int iTabCur, /* Cursor pointing to a table row */
86704 int iIdxCol, /* The column of the index to be loaded */
86705 int regOut /* Store the index column value in this register */
86706 ){
86707 i16 iTabCol = pIdx->aiColumn[iIdxCol];
86708 if( iTabCol>=(-1) ){
86709 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
86710 iTabCol, regOut);
86711 return;
86712 }
86713 assert( pIdx->aColExpr );
86714 assert( pIdx->aColExpr->nExpr>iIdxCol );
86715 pParse->iSelfTab = iTabCur;
86716 sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
86717 }
86718
86719 /*
86720 ** Generate code to extract the value of the iCol-th column of a table.
86721 */
86722 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
@@ -86758,12 +86899,13 @@
86899 if( pParse->ckBase>0 ){
86900 /* Generating CHECK constraints or inserting into partial index */
86901 inReg = pExpr->iColumn + pParse->ckBase;
86902 break;
86903 }else{
86904 /* Coding an expression that is part of an index where column names
86905 ** in the index refer to the table to which the index belongs */
86906 iTab = pParse->iSelfTab;
86907 }
86908 }
86909 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
86910 pExpr->iColumn, iTab, target,
86911 pExpr->op2);
@@ -86780,11 +86922,11 @@
86922 break;
86923 }
86924 #endif
86925 case TK_STRING: {
86926 assert( !ExprHasProperty(pExpr, EP_IntValue) );
86927 sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
86928 break;
86929 }
86930 case TK_NULL: {
86931 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
86932 break;
@@ -86819,14 +86961,10 @@
86961 }
86962 case TK_REGISTER: {
86963 inReg = pExpr->iTable;
86964 break;
86965 }
 
 
 
 
86966 #ifndef SQLITE_OMIT_CAST
86967 case TK_CAST: {
86968 /* Expressions of the form: CAST(pLeft AS token) */
86969 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
86970 if( inReg!=target ){
@@ -87053,11 +87191,11 @@
87191 pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
87192 }
87193 }
87194
87195 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
87196 sqlite3ExprCodeExprList(pParse, pFarg, r1, 0,
87197 SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
87198 sqlite3ExprCachePop(pParse); /* Ticket 2ea2425d34be */
87199 }else{
87200 r1 = 0;
87201 }
@@ -87277,11 +87415,11 @@
87415 nextCase = sqlite3VdbeMakeLabel(v);
87416 testcase( pTest->op==TK_COLUMN );
87417 sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
87418 testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
87419 sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
87420 sqlite3VdbeGoto(v, endLabel);
87421 sqlite3ExprCachePop(pParse);
87422 sqlite3VdbeResolveLabel(v, nextCase);
87423 }
87424 if( (nExpr&1)!=0 ){
87425 sqlite3ExprCachePush(pParse);
@@ -87469,29 +87607,32 @@
87607 */
87608 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
87609 Parse *pParse, /* Parsing context */
87610 ExprList *pList, /* The expression list to be coded */
87611 int target, /* Where to write results */
87612 int srcReg, /* Source registers if SQLITE_ECEL_REF */
87613 u8 flags /* SQLITE_ECEL_* flags */
87614 ){
87615 struct ExprList_item *pItem;
87616 int i, j, n;
87617 u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
87618 Vdbe *v = pParse->pVdbe;
87619 assert( pList!=0 );
87620 assert( target>0 );
87621 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
87622 n = pList->nExpr;
87623 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
87624 for(pItem=pList->a, i=0; i<n; i++, pItem++){
87625 Expr *pExpr = pItem->pExpr;
87626 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pList->a[i].u.x.iOrderByCol)>0 ){
87627 sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
87628 }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
87629 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
87630 }else{
87631 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
87632 if( inReg!=target+i ){
87633 VdbeOp *pOp;
 
87634 if( copyOp==OP_Copy
87635 && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
87636 && pOp->p1+pOp->p3+1==inReg
87637 && pOp->p2+pOp->p3+1==target+i
87638 ){
@@ -87664,18 +87805,18 @@
87805 #ifndef SQLITE_OMIT_SUBQUERY
87806 case TK_IN: {
87807 int destIfFalse = sqlite3VdbeMakeLabel(v);
87808 int destIfNull = jumpIfNull ? dest : destIfFalse;
87809 sqlite3ExprCodeIN(pParse, pExpr, destIfFalse, destIfNull);
87810 sqlite3VdbeGoto(v, dest);
87811 sqlite3VdbeResolveLabel(v, destIfFalse);
87812 break;
87813 }
87814 #endif
87815 default: {
87816 if( exprAlwaysTrue(pExpr) ){
87817 sqlite3VdbeGoto(v, dest);
87818 }else if( exprAlwaysFalse(pExpr) ){
87819 /* No-op */
87820 }else{
87821 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
87822 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
@@ -87827,11 +87968,11 @@
87968 break;
87969 }
87970 #endif
87971 default: {
87972 if( exprAlwaysFalse(pExpr) ){
87973 sqlite3VdbeGoto(v, dest);
87974 }else if( exprAlwaysTrue(pExpr) ){
87975 /* no-op */
87976 }else{
87977 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
87978 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
@@ -87903,11 +88044,13 @@
88044 return 1;
88045 }
88046 return 2;
88047 }
88048 if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
88049 if( pA->op==TK_FUNCTION ){
88050 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
88051 }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
88052 return pA->op==TK_COLLATE ? 1 : 2;
88053 }
88054 }
88055 if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
88056 if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
@@ -88811,11 +88954,11 @@
88954 ** SQLite tables) that are identified by the name of the virtual table.
88955 */
88956 #ifndef SQLITE_OMIT_VIRTUALTABLE
88957 if( pVTab ){
88958 int i = ++pParse->nMem;
88959 sqlite3VdbeLoadString(v, i, zName);
88960 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
88961 sqlite3MayAbort(pParse);
88962 }
88963 #endif
88964
@@ -90169,11 +90312,11 @@
90312 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
90313 iTabCur = iTab++;
90314 iIdxCur = iTab++;
90315 pParse->nTab = MAX(pParse->nTab, iTab);
90316 sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
90317 sqlite3VdbeLoadString(v, regTabname, pTab->zName);
90318
90319 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
90320 int nCol; /* Number of columns in pIdx. "N" */
90321 int addrRewind; /* Address of "OP_Rewind iIdxCur" */
90322 int addrNextRow; /* Address of "next_row:" */
@@ -90191,11 +90334,11 @@
90334 zIdxName = pIdx->zName;
90335 nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
90336 }
90337
90338 /* Populate the register containing the index name. */
90339 sqlite3VdbeLoadString(v, regIdxname, zIdxName);
90340 VdbeComment((v, "Analysis for %s.%s", pTab->zName, zIdxName));
90341
90342 /*
90343 ** Pseudo-code for loop that calls stat_push():
90344 **
@@ -90305,11 +90448,11 @@
90448 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
90449 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
90450 VdbeCoverage(v);
90451 }
90452 sqlite3VdbeAddOp2(v, OP_Integer, nColTest, regChng);
90453 sqlite3VdbeGoto(v, endDistinctTest);
90454
90455
90456 /*
90457 ** chng_addr_0:
90458 ** regPrev(0) = idx(0)
@@ -90341,10 +90484,11 @@
90484 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
90485 int j, k, regKey;
90486 regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol);
90487 for(j=0; j<pPk->nKeyCol; j++){
90488 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
90489 assert( k>=0 && k<pTab->nCol );
90490 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j);
90491 VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName));
90492 }
90493 sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid);
90494 sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol);
@@ -90390,16 +90534,14 @@
90534 /* We know that the regSampleRowid row exists because it was read by
90535 ** the previous loop. Thus the not-found jump of seekOp will never
90536 ** be taken */
90537 VdbeCoverageNeverTaken(v);
90538 #ifdef SQLITE_ENABLE_STAT3
90539 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, 0, regSample);
 
90540 #else
90541 for(i=0; i<nCol; i++){
90542 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i);
 
90543 }
90544 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol, regSample);
90545 #endif
90546 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
90547 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
@@ -92121,11 +92263,11 @@
92263 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
92264 }
92265 }
92266
92267 /* Finally, jump back to the beginning of the executable code. */
92268 sqlite3VdbeGoto(v, 1);
92269 }
92270 }
92271
92272
92273 /* Get the VDBE program ready for execution
@@ -92256,10 +92398,21 @@
92398 }
92399
92400 p = sqlite3FindTable(pParse->db, zName, zDbase);
92401 if( p==0 ){
92402 const char *zMsg = isView ? "no such view" : "no such table";
92403 #ifndef SQLITE_OMIT_VIRTUALTABLE
92404 if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
92405 /* If zName is the not the name of a table in the schema created using
92406 ** CREATE, then check to see if it is the name of an virtual table that
92407 ** can be an eponymous virtual table. */
92408 Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
92409 if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
92410 return pMod->pEpoTab;
92411 }
92412 }
92413 #endif
92414 if( zDbase ){
92415 sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName);
92416 }else{
92417 sqlite3ErrorMsg(pParse, "%s: %s", zMsg, zName);
92418 }
@@ -92334,10 +92487,11 @@
92487 static void freeIndex(sqlite3 *db, Index *p){
92488 #ifndef SQLITE_OMIT_ANALYZE
92489 sqlite3DeleteIndexSamples(db, p);
92490 #endif
92491 sqlite3ExprDelete(db, p->pPartIdxWhere);
92492 sqlite3ExprListDelete(db, p->aColExpr);
92493 sqlite3DbFree(db, p->zColAff);
92494 if( p->isResized ) sqlite3DbFree(db, p->azColl);
92495 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
92496 sqlite3_free(p->aiRowEst);
92497 #endif
@@ -92460,11 +92614,11 @@
92614
92615 /*
92616 ** Delete memory allocated for the column names of a table or view (the
92617 ** Table.aCol[] array).
92618 */
92619 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
92620 int i;
92621 Column *pCol;
92622 assert( pTable!=0 );
92623 if( (pCol = pTable->aCol)!=0 ){
92624 for(i=0; i<pTable->nCol; i++, pCol++){
@@ -92527,17 +92681,15 @@
92681 /* Delete any foreign keys attached to this table. */
92682 sqlite3FkDelete(db, pTable);
92683
92684 /* Delete the Table structure itself.
92685 */
92686 sqlite3DeleteColumnNames(db, pTable);
92687 sqlite3DbFree(db, pTable->zName);
92688 sqlite3DbFree(db, pTable->zColAff);
92689 sqlite3SelectDelete(db, pTable->pSelect);
 
92690 sqlite3ExprListDelete(db, pTable->pCheck);
 
92691 #ifndef SQLITE_OMIT_VIRTUALTABLE
92692 sqlite3VtabClear(db, pTable);
92693 #endif
92694 sqlite3DbFree(db, pTable);
92695
@@ -92876,10 +93028,12 @@
93028 */
93029 if( !db->init.busy && (v = sqlite3GetVdbe(pParse))!=0 ){
93030 int j1;
93031 int fileFormat;
93032 int reg1, reg2, reg3;
93033 /* nullRow[] is an OP_Record encoding of a row containing 5 NULLs */
93034 static const char nullRow[] = { 6, 0, 0, 0, 0, 0 };
93035 sqlite3BeginWriteOperation(pParse, 1, iDb);
93036
93037 #ifndef SQLITE_OMIT_VIRTUALTABLE
93038 if( isVirtual ){
93039 sqlite3VdbeAddOp0(v, OP_VBegin);
@@ -92920,11 +93074,11 @@
93074 {
93075 pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
93076 }
93077 sqlite3OpenMasterTable(pParse, iDb);
93078 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
93079 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
93080 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
93081 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
93082 sqlite3VdbeAddOp0(v, OP_Close);
93083 }
93084
@@ -93201,22 +93355,27 @@
93355 zType = pTab->aCol[iCol].zType;
93356 nTerm = 1;
93357 }else{
93358 nTerm = pList->nExpr;
93359 for(i=0; i<nTerm; i++){
93360 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
93361 assert( pCExpr!=0 );
93362 if( pCExpr->op==TK_ID ){
93363 const char *zCName = pCExpr->u.zToken;
93364 for(iCol=0; iCol<pTab->nCol; iCol++){
93365 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
93366 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
93367 zType = pTab->aCol[iCol].zType;
93368 break;
93369 }
93370 }
93371 }
93372 }
93373 }
93374 if( nTerm==1
93375 && zType && sqlite3StrICmp(zType, "INTEGER")==0
93376 && sortOrder!=SQLITE_SO_DESC
93377 ){
93378 pTab->iPKey = iCol;
93379 pTab->keyConf = (u8)onError;
93380 assert( autoInc==0 || autoInc==1 );
93381 pTab->tabFlags |= autoInc*TF_Autoincrement;
@@ -93579,22 +93738,24 @@
93738 ** root-page for the table into an OP_CreateIndex opcode. The index
93739 ** created will become the PRIMARY KEY index.
93740 */
93741 if( pParse->addrCrTab ){
93742 assert( v );
93743 sqlite3VdbeChangeOpcode(v, pParse->addrCrTab, OP_CreateIndex);
93744 }
93745
93746 /* Locate the PRIMARY KEY index. Or, if this table was originally
93747 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
93748 */
93749 if( pTab->iPKey>=0 ){
93750 ExprList *pList;
93751 Token ipkToken;
93752 ipkToken.z = pTab->aCol[pTab->iPKey].zName;
93753 ipkToken.n = sqlite3Strlen30(ipkToken.z);
93754 pList = sqlite3ExprListAppend(pParse, 0,
93755 sqlite3ExprAlloc(db, TK_ID, &ipkToken, 0));
93756 if( pList==0 ) return;
 
 
93757 pList->a[0].sortOrder = pParse->iPkSortOrder;
93758 assert( pParse->pNewTable==pTab );
93759 pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
93760 if( pPk==0 ) return;
93761 pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
@@ -93606,11 +93767,11 @@
93767 ** table entry. This is only required if currently generating VDBE
93768 ** code for a CREATE TABLE (not when parsing one as part of reading
93769 ** a database schema). */
93770 if( v ){
93771 assert( db->init.busy==0 );
93772 sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
93773 }
93774
93775 /*
93776 ** Remove all redundant columns from the PRIMARY KEY. For example, change
93777 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
@@ -93716,13 +93877,14 @@
93877 Table *p; /* The new table */
93878 sqlite3 *db = pParse->db; /* The database connection */
93879 int iDb; /* Database in which the table lives */
93880 Index *pIdx; /* An implied index of the table */
93881
93882 if( pEnd==0 && pSelect==0 ){
93883 return;
93884 }
93885 assert( !db->mallocFailed );
93886 p = pParse->pNewTable;
93887 if( p==0 ) return;
93888
93889 assert( !db->init.busy || !pSelect );
93890
@@ -93849,11 +94011,11 @@
94011 VdbeCoverage(v);
94012 sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
94013 sqlite3TableAffinity(v, p, 0);
94014 sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
94015 sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
94016 sqlite3VdbeGoto(v, addrInsLoop);
94017 sqlite3VdbeJumpHere(v, addrInsLoop);
94018 sqlite3VdbeAddOp1(v, OP_Close, 1);
94019 }
94020
94021 /* Compute the complete text of the CREATE statement */
@@ -93946,10 +94108,11 @@
94108 SQLITE_PRIVATE void sqlite3CreateView(
94109 Parse *pParse, /* The parsing context */
94110 Token *pBegin, /* The CREATE token that begins the statement */
94111 Token *pName1, /* The token that holds the name of the view */
94112 Token *pName2, /* The token that holds the name of the view */
94113 ExprList *pCNames, /* Optional list of view column names */
94114 Select *pSelect, /* A SELECT statement that will become the new view */
94115 int isTemp, /* TRUE for a TEMPORARY view */
94116 int noErr /* Suppress error messages if VIEW already exists */
94117 ){
94118 Table *p;
@@ -93966,52 +94129,47 @@
94129 sqlite3SelectDelete(db, pSelect);
94130 return;
94131 }
94132 sqlite3StartTable(pParse, pName1, pName2, isTemp, 1, 0, noErr);
94133 p = pParse->pNewTable;
94134 if( p==0 || pParse->nErr ) goto create_view_fail;
 
 
 
94135 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
94136 iDb = sqlite3SchemaToIndex(db, p->pSchema);
94137 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
94138 if( sqlite3FixSelect(&sFix, pSelect) ) goto create_view_fail;
 
 
 
94139
94140 /* Make a copy of the entire SELECT statement that defines the view.
94141 ** This will force all the Expr.token.z values to be dynamically
94142 ** allocated rather than point to the input string - which means that
94143 ** they will persist after the current sqlite3_exec() call returns.
94144 */
94145 p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
94146 p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE);
94147 if( db->mallocFailed ) goto create_view_fail;
 
 
 
 
 
94148
94149 /* Locate the end of the CREATE VIEW statement. Make sEnd point to
94150 ** the end.
94151 */
94152 sEnd = pParse->sLastToken;
94153 assert( sEnd.z[0]!=0 );
94154 if( sEnd.z[0]!=';' ){
94155 sEnd.z += sEnd.n;
94156 }
94157 sEnd.n = 0;
94158 n = (int)(sEnd.z - pBegin->z);
94159 assert( n>0 );
94160 z = pBegin->z;
94161 while( sqlite3Isspace(z[n-1]) ){ n--; }
94162 sEnd.z = &z[n-1];
94163 sEnd.n = 1;
94164
94165 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
94166 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
94167
94168 create_view_fail:
94169 sqlite3SelectDelete(db, pSelect);
94170 sqlite3ExprListDelete(db, pCNames);
94171 return;
94172 }
94173 #endif /* SQLITE_OMIT_VIEW */
94174
94175 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -94025,10 +94183,11 @@
94183 Select *pSel; /* Copy of the SELECT that implements the view */
94184 int nErr = 0; /* Number of errors encountered */
94185 int n; /* Temporarily holds the number of cursors assigned */
94186 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
94187 sqlite3_xauth xAuth; /* Saved xAuth pointer */
94188 u8 bEnabledLA; /* Saved db->lookaside.bEnabled state */
94189
94190 assert( pTable );
94191
94192 #ifndef SQLITE_OMIT_VIRTUALTABLE
94193 if( sqlite3VtabCallConnect(pParse, pTable) ){
@@ -94070,44 +94229,50 @@
94229 ** to the elements of the FROM clause. But we do not want these changes
94230 ** to be permanent. So the computation is done on a copy of the SELECT
94231 ** statement that defines the view.
94232 */
94233 assert( pTable->pSelect );
94234 bEnabledLA = db->lookaside.bEnabled;
94235 if( pTable->pCheck ){
94236 db->lookaside.bEnabled = 0;
94237 sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
94238 &pTable->nCol, &pTable->aCol);
94239 }else{
94240 pSel = sqlite3SelectDup(db, pTable->pSelect, 0);
94241 if( pSel ){
94242 n = pParse->nTab;
94243 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
94244 pTable->nCol = -1;
94245 db->lookaside.bEnabled = 0;
94246 #ifndef SQLITE_OMIT_AUTHORIZATION
94247 xAuth = db->xAuth;
94248 db->xAuth = 0;
94249 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94250 db->xAuth = xAuth;
94251 #else
94252 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel);
94253 #endif
94254 pParse->nTab = n;
94255 if( pSelTab ){
94256 assert( pTable->aCol==0 );
94257 pTable->nCol = pSelTab->nCol;
94258 pTable->aCol = pSelTab->aCol;
94259 pSelTab->nCol = 0;
94260 pSelTab->aCol = 0;
94261 sqlite3DeleteTable(db, pSelTab);
94262 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
94263 }else{
94264 pTable->nCol = 0;
94265 nErr++;
94266 }
94267 sqlite3SelectDelete(db, pSel);
94268 } else {
94269 nErr++;
94270 }
94271 }
94272 db->lookaside.bEnabled = bEnabledLA;
94273 pTable->pSchema->schemaFlags |= DB_UnresetViews;
94274 #endif /* SQLITE_OMIT_VIEW */
94275 return nErr;
94276 }
94277 #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
94278
@@ -94120,11 +94285,11 @@
94285 assert( sqlite3SchemaMutexHeld(db, idx, 0) );
94286 if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
94287 for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
94288 Table *pTab = sqliteHashData(i);
94289 if( pTab->pSelect ){
94290 sqlite3DeleteColumnNames(db, pTab);
94291 pTab->aCol = 0;
94292 pTab->nCol = 0;
94293 }
94294 }
94295 DbClearProperty(db, idx, DB_UnresetViews);
@@ -94675,11 +94840,11 @@
94840
94841 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
94842 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
94843 if( IsUniqueIndex(pIndex) && pKey!=0 ){
94844 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
94845 sqlite3VdbeGoto(v, j2);
94846 addr2 = sqlite3VdbeCurrentAddr(v);
94847 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
94848 pIndex->nKeyCol); VdbeCoverage(v);
94849 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
94850 }else{
@@ -94730,10 +94895,34 @@
94895 p->nKeyCol = nCol - 1;
94896 *ppExtra = ((char*)p) + nByte;
94897 }
94898 return p;
94899 }
94900
94901 /*
94902 ** Backwards Compatibility Hack:
94903 **
94904 ** Historical versions of SQLite accepted strings as column names in
94905 ** indexes and PRIMARY KEY constraints and in UNIQUE constraints. Example:
94906 **
94907 ** CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
94908 ** CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
94909 **
94910 ** This is goofy. But to preserve backwards compatibility we continue to
94911 ** accept it. This routine does the necessary conversion. It converts
94912 ** the expression given in its argument from a TK_STRING into a TK_ID
94913 ** if the expression is just a TK_STRING with an optional COLLATE clause.
94914 ** If the epxression is anything other than TK_STRING, the expression is
94915 ** unchanged.
94916 */
94917 static void sqlite3StringToId(Expr *p){
94918 if( p->op==TK_STRING ){
94919 p->op = TK_ID;
94920 }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
94921 p->pLeft->op = TK_ID;
94922 }
94923 }
94924
94925 /*
94926 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
94927 ** and pTblList is the name of the table that is to be indexed. Both will
94928 ** be NULL for a primary key or an index that is created to satisfy a
@@ -94772,11 +94961,10 @@
94961 sqlite3 *db = pParse->db;
94962 Db *pDb; /* The specific table containing the indexed database */
94963 int iDb; /* Index of the database that is being written */
94964 Token *pName = 0; /* Unqualified name of the index to create */
94965 struct ExprList_item *pListItem; /* For looping over pList */
 
94966 int nExtra = 0; /* Space allocated for zExtra[] */
94967 int nExtraCol; /* Number of extra columns needed */
94968 char *zExtra = 0; /* Extra space after the Index object */
94969 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
94970
@@ -94927,24 +95115,29 @@
95115 /* If pList==0, it means this routine was called to make a primary
95116 ** key out of the last column added to the table under construction.
95117 ** So create a fake list to simulate this.
95118 */
95119 if( pList==0 ){
95120 Token prevCol;
95121 prevCol.z = pTab->aCol[pTab->nCol-1].zName;
95122 prevCol.n = sqlite3Strlen30(prevCol.z);
95123 pList = sqlite3ExprListAppend(pParse, 0,
95124 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
95125 if( pList==0 ) goto exit_create_index;
95126 assert( pList->nExpr==1 );
95127 sqlite3ExprListSetSortOrder(pList, sortOrder);
95128 }else{
95129 sqlite3ExprListCheckLength(pParse, pList, "index");
95130 }
95131
95132 /* Figure out how many bytes of space are required to store explicitly
95133 ** specified collation sequence names.
95134 */
95135 for(i=0; i<pList->nExpr; i++){
95136 Expr *pExpr = pList->a[i].pExpr;
95137 assert( pExpr!=0 );
95138 if( pExpr->op==TK_COLLATE ){
95139 nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
95140 }
95141 }
95142
95143 /*
@@ -94981,61 +95174,85 @@
95174 sortOrderMask = -1; /* Honor DESC */
95175 }else{
95176 sortOrderMask = 0; /* Ignore DESC */
95177 }
95178
95179 /* Analyze the list of expressions that form the terms of the index and
95180 ** report any errors. In the common case where the expression is exactly
95181 ** a table column, store that column in aiColumn[]. For general expressions,
95182 ** populate pIndex->aColExpr and store -2 in aiColumn[].
95183 **
95184 ** TODO: Issue a warning if two or more columns of the index are identical.
95185 ** TODO: Issue a warning if the table primary key is used as part of the
95186 ** index key.
 
 
95187 */
95188 for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){
95189 Expr *pCExpr; /* The i-th index expression */
95190 int requestedSortOrder; /* ASC or DESC on the i-th expression */
95191 char *zColl; /* Collation sequence name */
95192
95193 sqlite3StringToId(pListItem->pExpr);
95194 sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0);
95195 if( pParse->nErr ) goto exit_create_index;
95196 pCExpr = sqlite3ExprSkipCollate(pListItem->pExpr);
95197 if( pCExpr->op!=TK_COLUMN ){
95198 if( pTab==pParse->pNewTable ){
95199 sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
95200 "UNIQUE constraints");
95201 goto exit_create_index;
95202 }
95203 if( pIndex->aColExpr==0 ){
95204 ExprList *pCopy = sqlite3ExprListDup(db, pList, 0);
95205 pIndex->aColExpr = pCopy;
95206 if( !db->mallocFailed ){
95207 assert( pCopy!=0 );
95208 pListItem = &pCopy->a[i];
95209 }
95210 }
95211 j = -2;
95212 pIndex->aiColumn[i] = -2;
95213 pIndex->uniqNotNull = 0;
95214 }else{
95215 j = pCExpr->iColumn;
95216 assert( j<=0x7fff );
95217 if( j<0 ){
95218 j = pTab->iPKey;
95219 }else if( pTab->aCol[j].notNull==0 ){
95220 pIndex->uniqNotNull = 0;
95221 }
95222 pIndex->aiColumn[i] = (i16)j;
95223 }
95224 zColl = 0;
95225 if( pListItem->pExpr->op==TK_COLLATE ){
95226 int nColl;
95227 zColl = pListItem->pExpr->u.zToken;
95228 nColl = sqlite3Strlen30(zColl) + 1;
95229 assert( nExtra>=nColl );
95230 memcpy(zExtra, zColl, nColl);
95231 zColl = zExtra;
95232 zExtra += nColl;
95233 nExtra -= nColl;
95234 }else if( j>=0 ){
95235 zColl = pTab->aCol[j].zColl;
 
95236 }
95237 if( !zColl ) zColl = "BINARY";
95238 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
95239 goto exit_create_index;
95240 }
95241 pIndex->azColl[i] = zColl;
95242 requestedSortOrder = pListItem->sortOrder & sortOrderMask;
95243 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
 
95244 }
95245
95246 /* Append the table key to the end of the index. For WITHOUT ROWID
95247 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
95248 ** normal tables (when pPk==0) this will be the rowid.
95249 */
95250 if( pPk ){
95251 for(j=0; j<pPk->nKeyCol; j++){
95252 int x = pPk->aiColumn[j];
95253 assert( x>=0 );
95254 if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
95255 pIndex->nColumn--;
95256 }else{
95257 pIndex->aiColumn[i] = x;
95258 pIndex->azColl[i] = pPk->azColl[j];
@@ -95082,10 +95299,11 @@
95299
95300 if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
95301 for(k=0; k<pIdx->nKeyCol; k++){
95302 const char *z1;
95303 const char *z2;
95304 assert( pIdx->aiColumn[k]>=0 );
95305 if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
95306 z1 = pIdx->azColl[k];
95307 z2 = pIndex->azColl[k];
95308 if( z1!=z2 && sqlite3StrICmp(z1, z2) ) break;
95309 }
@@ -95113,10 +95331,11 @@
95331 }
95332
95333 /* Link the new Index structure to its table and to the other
95334 ** in-memory database structures.
95335 */
95336 assert( pParse->nErr==0 );
95337 if( db->init.busy ){
95338 Index *p;
95339 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
95340 p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
95341 pIndex->zName, pIndex);
@@ -95142,11 +95361,11 @@
95361 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
95362 ** or UNIQUE index in a CREATE TABLE statement. Since the table
95363 ** has just been created, it contains no data and the index initialization
95364 ** step can be skipped.
95365 */
95366 else if( HasRowid(pTab) || pTblName!=0 ){
95367 Vdbe *v;
95368 char *zStmt;
95369 int iMem = ++pParse->nMem;
95370
95371 v = sqlite3GetVdbe(pParse);
@@ -95602,11 +95821,12 @@
95821 if( pList==0 ) return;
95822 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
95823 sqlite3DbFree(db, pItem->zDatabase);
95824 sqlite3DbFree(db, pItem->zName);
95825 sqlite3DbFree(db, pItem->zAlias);
95826 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
95827 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
95828 sqlite3DeleteTable(db, pItem->pTab);
95829 sqlite3SelectDelete(db, pItem->pSelect);
95830 sqlite3ExprDelete(db, pItem->pOn);
95831 sqlite3IdListDelete(db, pItem->pUsing);
95832 }
@@ -95675,20 +95895,40 @@
95895 */
95896 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
95897 assert( pIndexedBy!=0 );
95898 if( p && ALWAYS(p->nSrc>0) ){
95899 struct SrcList_item *pItem = &p->a[p->nSrc-1];
95900 assert( pItem->fg.notIndexed==0 );
95901 assert( pItem->fg.isIndexedBy==0 );
95902 assert( pItem->fg.isTabFunc==0 );
95903 if( pIndexedBy->n==1 && !pIndexedBy->z ){
95904 /* A "NOT INDEXED" clause was supplied. See parse.y
95905 ** construct "indexed_opt" for details. */
95906 pItem->fg.notIndexed = 1;
95907 }else{
95908 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
95909 pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy!=0);
95910 }
95911 }
95912 }
95913
95914 /*
95915 ** Add the list of function arguments to the SrcList entry for a
95916 ** table-valued-function.
95917 */
95918 SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse *pParse, SrcList *p, ExprList *pList){
95919 if( p && pList ){
95920 struct SrcList_item *pItem = &p->a[p->nSrc-1];
95921 assert( pItem->fg.notIndexed==0 );
95922 assert( pItem->fg.isIndexedBy==0 );
95923 assert( pItem->fg.isTabFunc==0 );
95924 pItem->u1.pFuncArg = pList;
95925 pItem->fg.isTabFunc = 1;
95926 }else{
95927 sqlite3ExprListDelete(pParse->db, pList);
95928 }
95929 }
95930
95931 /*
95932 ** When building up a FROM clause in the parser, the join operator
95933 ** is initially attached to the left operand. But the code generator
95934 ** expects the join operator to be on the right operand. This routine
@@ -95705,13 +95945,13 @@
95945 */
95946 SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList *p){
95947 if( p ){
95948 int i;
95949 for(i=p->nSrc-1; i>0; i--){
95950 p->a[i].fg.jointype = p->a[i-1].fg.jointype;
95951 }
95952 p->a[0].fg.jointype = 0;
95953 }
95954 }
95955
95956 /*
95957 ** Begin a transaction
@@ -95951,16 +96191,20 @@
96191 int j;
96192 StrAccum errMsg;
96193 Table *pTab = pIdx->pTable;
96194
96195 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
96196 if( pIdx->aColExpr ){
96197 sqlite3XPrintf(&errMsg, 0, "index '%q'", pIdx->zName);
96198 }else{
96199 for(j=0; j<pIdx->nKeyCol; j++){
96200 char *zCol;
96201 assert( pIdx->aiColumn[j]>=0 );
96202 zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
96203 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
96204 sqlite3XPrintf(&errMsg, 0, "%s.%s", pTab->zName, zCol);
96205 }
96206 }
96207 zErr = sqlite3StrAccumFinish(&errMsg);
96208 sqlite3HaltConstraint(pParse,
96209 IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
96210 : SQLITE_CONSTRAINT_UNIQUE,
@@ -96201,11 +96445,11 @@
96445 pNew = pWith;
96446 }else{
96447 pNew->a[pNew->nCte].pSelect = pQuery;
96448 pNew->a[pNew->nCte].pCols = pArglist;
96449 pNew->a[pNew->nCte].zName = zName;
96450 pNew->a[pNew->nCte].zCteErr = 0;
96451 pNew->nCte++;
96452 }
96453
96454 return pNew;
96455 }
@@ -97120,10 +97364,11 @@
97364 }
97365
97366 /* Extract the rowid or primary key for the current row */
97367 if( pPk ){
97368 for(i=0; i<nPk; i++){
97369 assert( pPk->aiColumn[i]>=(-1) );
97370 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
97371 pPk->aiColumn[i], iPk+i);
97372 }
97373 iKey = iPk;
97374 }else{
@@ -97152,11 +97397,11 @@
97397 }else if( pPk ){
97398 /* Construct a composite key for the row to be deleted and remember it */
97399 iKey = ++pParse->nMem;
97400 nKey = 0; /* Zero tells OP_Found to use a composite key */
97401 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
97402 sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
97403 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
97404 }else{
97405 /* Get the rowid of the row to be deleted and remember it in the RowSet */
97406 nKey = 1; /* OP_Seek always uses a single rowid */
97407 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -97165,11 +97410,11 @@
97410 /* End of the WHERE loop */
97411 sqlite3WhereEnd(pWInfo);
97412 if( okOnePass ){
97413 /* Bypass the delete logic below if the WHERE loop found zero rows */
97414 addrBypass = sqlite3VdbeMakeLabel(v);
97415 sqlite3VdbeGoto(v, addrBypass);
97416 sqlite3VdbeJumpHere(v, addrDelete);
97417 }
97418
97419 /* Unless this is a view, open cursors for the table we are
97420 ** deleting from and all its indices. If this is a view, then the
@@ -97227,11 +97472,11 @@
97472 sqlite3VdbeResolveLabel(v, addrBypass);
97473 }else if( pPk ){
97474 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
97475 sqlite3VdbeJumpHere(v, addrLoop);
97476 }else{
97477 sqlite3VdbeGoto(v, addrLoop);
97478 sqlite3VdbeJumpHere(v, addrLoop);
97479 }
97480
97481 /* Close the cursors open on the table and its indexes. */
97482 if( !isView && !IsVirtual(pTab) ){
@@ -97498,18 +97743,17 @@
97743 Index *pPrior, /* Previously generated index key */
97744 int regPrior /* Register holding previous generated key */
97745 ){
97746 Vdbe *v = pParse->pVdbe;
97747 int j;
 
97748 int regBase;
97749 int nCol;
97750
97751 if( piPartIdxLabel ){
97752 if( pIdx->pPartIdxWhere ){
97753 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
97754 pParse->iSelfTab = iDataCur;
97755 sqlite3ExprCachePush(pParse);
97756 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
97757 SQLITE_JUMPIFNULL);
97758 }else{
97759 *piPartIdxLabel = 0;
@@ -97517,13 +97761,18 @@
97761 }
97762 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
97763 regBase = sqlite3GetTempRange(pParse, nCol);
97764 if( pPrior && (regBase!=regPrior || pPrior->pPartIdxWhere) ) pPrior = 0;
97765 for(j=0; j<nCol; j++){
97766 if( pPrior
97767 && pPrior->aiColumn[j]==pIdx->aiColumn[j]
97768 && pPrior->aiColumn[j]>=(-1)
97769 ){
97770 /* This column was already computed by the previous index */
97771 continue;
97772 }
97773 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
97774 /* If the column affinity is REAL but the number is an integer, then it
97775 ** might be stored in the table as an integer (using a compact
97776 ** representation) then converted to REAL by an OP_RealAffinity opcode.
97777 ** But we are getting ready to store this value back into an index, where
97778 ** it should be converted by to INTEGER again. So omit the OP_RealAffinity
@@ -99288,19 +99537,19 @@
99537 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
99538 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
99539 VFUNCTION(random, 0, 0, 0, randomFunc ),
99540 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
99541 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
99542 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
99543 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
99544 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
99545 #if SQLITE_USER_AUTHENTICATION
99546 FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ),
99547 #endif
99548 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
99549 DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
99550 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
99551 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
99552 FUNCTION(quote, 1, 0, 0, quoteFunc ),
99553 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
99554 VFUNCTION(changes, 0, 0, 0, changes ),
99555 VFUNCTION(total_changes, 0, 0, 0, total_changes ),
@@ -99308,12 +99557,12 @@
99557 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
99558 #ifdef SQLITE_SOUNDEX
99559 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
99560 #endif
99561 #ifndef SQLITE_OMIT_LOAD_EXTENSION
99562 VFUNCTION(load_extension, 1, 0, 0, loadExt ),
99563 VFUNCTION(load_extension, 2, 0, 0, loadExt ),
99564 #endif
99565 AGGREGATE(sum, 1, 0, 0, sumStep, sumFinalize ),
99566 AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
99567 AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
99568 AGGREGATE2(count, 0, 0, 0, countStep, countFinalize,
@@ -99724,11 +99973,11 @@
99973 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
99974 }
99975
99976 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
99977 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
99978 sqlite3VdbeGoto(v, iOk);
99979 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
99980 sqlite3VdbeJumpHere(v, iMustBeInt);
99981 sqlite3ReleaseTempReg(pParse, regTemp);
99982 }else{
99983 int nCol = pFKey->nCol;
@@ -99762,15 +100011,15 @@
100011 iParent = regData;
100012 }
100013 sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
100014 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
100015 }
100016 sqlite3VdbeGoto(v, iOk);
100017 }
100018
100019 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
100020 sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
100021 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
100022
100023 sqlite3ReleaseTempReg(pParse, regRec);
100024 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
100025 }
@@ -100823,11 +101072,11 @@
101072 **
101073 ** Memory for the buffer containing the column index affinity string
101074 ** is managed along with the rest of the Index structure. It will be
101075 ** released when sqlite3DeleteIndex() is called.
101076 */
101077 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
101078 if( !pIdx->zColAff ){
101079 /* The first time a column affinity string for a particular index is
101080 ** required, it is allocated and populated here. It is then stored as
101081 ** a member of the Index structure for subsequent use.
101082 **
@@ -100835,19 +101084,29 @@
101084 ** sqliteDeleteIndex() when the Index structure itself is cleaned
101085 ** up.
101086 */
101087 int n;
101088 Table *pTab = pIdx->pTable;
 
101089 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
101090 if( !pIdx->zColAff ){
101091 db->mallocFailed = 1;
101092 return 0;
101093 }
101094 for(n=0; n<pIdx->nColumn; n++){
101095 i16 x = pIdx->aiColumn[n];
101096 if( x>=0 ){
101097 pIdx->zColAff[n] = pTab->aCol[x].affinity;
101098 }else if( x==(-1) ){
101099 pIdx->zColAff[n] = SQLITE_AFF_INTEGER;
101100 }else{
101101 char aff;
101102 assert( x==(-2) );
101103 assert( pIdx->aColExpr!=0 );
101104 aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
101105 if( aff==0 ) aff = SQLITE_AFF_BLOB;
101106 pIdx->zColAff[n] = aff;
101107 }
101108 }
101109 pIdx->zColAff[n] = 0;
101110 }
101111
101112 return pIdx->zColAff;
@@ -101014,18 +101273,18 @@
101273 memId = p->regCtr;
101274 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
101275 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
101276 sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
101277 addr = sqlite3VdbeCurrentAddr(v);
101278 sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
101279 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
101280 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
101281 sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
101282 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
101283 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
101284 sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
101285 sqlite3VdbeGoto(v, addr+9);
101286 sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
101287 sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
101288 sqlite3VdbeAddOp0(v, OP_Close);
101289 }
101290 }
@@ -101445,11 +101704,11 @@
101704 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
101705 addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
101706 sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
101707 sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
101708 sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
101709 sqlite3VdbeGoto(v, addrL);
101710 sqlite3VdbeJumpHere(v, addrL);
101711 sqlite3ReleaseTempReg(pParse, regRec);
101712 sqlite3ReleaseTempReg(pParse, regTempRowid);
101713 }
101714 }else{
@@ -101459,15 +101718,17 @@
101718 NameContext sNC;
101719 memset(&sNC, 0, sizeof(sNC));
101720 sNC.pParse = pParse;
101721 srcTab = -1;
101722 assert( useTempTable==0 );
101723 if( pList ){
101724 nColumn = pList->nExpr;
101725 if( sqlite3ResolveExprListNames(&sNC, pList) ){
101726 goto insert_cleanup;
101727 }
101728 }else{
101729 nColumn = 0;
101730 }
101731 }
101732
101733 /* If there is no IDLIST term but the table has an integer primary
101734 ** key, the set the ipkColumn variable to the integer primary key
@@ -101744,11 +102005,11 @@
102005 if( useTempTable ){
102006 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
102007 sqlite3VdbeJumpHere(v, addrInsTop);
102008 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
102009 }else if( pSelect ){
102010 sqlite3VdbeGoto(v, addrCont);
102011 sqlite3VdbeJumpHere(v, addrInsTop);
102012 }
102013
102014 if( !IsVirtual(pTab) && !isView ){
102015 /* Close all tables opened */
@@ -101991,11 +102252,11 @@
102252 onError = overrideError!=OE_Default ? overrideError : OE_Abort;
102253 for(i=0; i<pCheck->nExpr; i++){
102254 int allOk = sqlite3VdbeMakeLabel(v);
102255 sqlite3ExprIfTrue(pParse, pCheck->a[i].pExpr, allOk, SQLITE_JUMPIFNULL);
102256 if( onError==OE_Ignore ){
102257 sqlite3VdbeGoto(v, ignoreDest);
102258 }else{
102259 char *zName = pCheck->a[i].zName;
102260 if( zName==0 ) zName = pTab->zName;
102261 if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-15569-63625 */
102262 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK,
@@ -102099,11 +102360,11 @@
102360 seenReplace = 1;
102361 break;
102362 }
102363 case OE_Ignore: {
102364 /*assert( seenReplace==0 );*/
102365 sqlite3VdbeGoto(v, ignoreDest);
102366 break;
102367 }
102368 }
102369 sqlite3VdbeResolveLabel(v, addrRowidOk);
102370 if( ipkTop ){
@@ -102147,19 +102408,26 @@
102408 */
102409 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
102410 for(i=0; i<pIdx->nColumn; i++){
102411 int iField = pIdx->aiColumn[i];
102412 int x;
102413 if( iField==(-2) ){
102414 pParse->ckBase = regNewData+1;
102415 sqlite3ExprCode(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
102416 pParse->ckBase = 0;
102417 VdbeComment((v, "%s column %d", pIdx->zName, i));
102418 }else{
102419 if( iField==(-1) || iField==pTab->iPKey ){
102420 if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
102421 x = regNewData;
102422 regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
102423 }else{
102424 x = iField + regNewData + 1;
102425 }
102426 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
102427 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
102428 }
 
 
102429 }
102430 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
102431 VdbeComment((v, "for %s", pIdx->zName));
102432 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
102433
@@ -102252,11 +102520,11 @@
102520 case OE_Fail: {
102521 sqlite3UniqueConstraint(pParse, onError, pIdx);
102522 break;
102523 }
102524 case OE_Ignore: {
102525 sqlite3VdbeGoto(v, ignoreDest);
102526 break;
102527 }
102528 default: {
102529 Trigger *pTrigger = 0;
102530 assert( onError==OE_Replace );
@@ -102273,11 +102541,11 @@
102541 sqlite3VdbeResolveLabel(v, addrUniqueOk);
102542 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
102543 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
102544 }
102545 if( ipkTop ){
102546 sqlite3VdbeGoto(v, ipkTop+1);
102547 sqlite3VdbeJumpHere(v, ipkBottom);
102548 }
102549
102550 *pbMayReplace = seenReplace;
102551 VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
@@ -102475,10 +102743,17 @@
102743 return 0; /* Different conflict resolution strategies */
102744 }
102745 for(i=0; i<pSrc->nKeyCol; i++){
102746 if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){
102747 return 0; /* Different columns indexed */
102748 }
102749 if( pSrc->aiColumn[i]==(-2) ){
102750 assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 );
102751 if( sqlite3ExprCompare(pSrc->aColExpr->a[i].pExpr,
102752 pDest->aColExpr->a[i].pExpr, -1)!=0 ){
102753 return 0; /* Different expressions in the index */
102754 }
102755 }
102756 if( pSrc->aSortOrder[i]!=pDest->aSortOrder[i] ){
102757 return 0; /* Different sort orders */
102758 }
102759 if( !xferCompatibleCollation(pSrc->azColl[i],pDest->azColl[i]) ){
@@ -102719,11 +102994,11 @@
102994 ** is unable to test uniqueness.)
102995 **
102996 ** (3) onError is something other than OE_Abort and OE_Rollback.
102997 */
102998 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
102999 emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
103000 sqlite3VdbeJumpHere(v, addr1);
103001 }
103002 if( HasRowid(pSrc) ){
103003 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
103004 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
@@ -103256,10 +103531,13 @@
103531 /* Version 3.8.11 and later */
103532 sqlite3_value *(*value_dup)(const sqlite3_value*);
103533 void (*value_free)(sqlite3_value*);
103534 int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64);
103535 int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64);
103536 /* Version 3.8.12 and later */
103537 unsigned int (*value_subtype)(sqlite3_value*);
103538 void (*result_subtype)(sqlite3_context*,unsigned int);
103539 };
103540
103541 /*
103542 ** The following macros redefine the API routines so that they are
103543 ** redirected through the global sqlite3_api structure.
@@ -103269,11 +103547,11 @@
103547 ** it can get access to the sqlite3_api_routines structure
103548 ** definition. But the main library does not want to redefine
103549 ** the API. So the redefinition macros are only valid if the
103550 ** SQLITE_CORE macros is undefined.
103551 */
103552 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
103553 #define sqlite3_aggregate_context sqlite3_api->aggregate_context
103554 #ifndef SQLITE_OMIT_DEPRECATED
103555 #define sqlite3_aggregate_count sqlite3_api->aggregate_count
103556 #endif
103557 #define sqlite3_bind_blob sqlite3_api->bind_blob
@@ -103396,10 +103674,11 @@
103674 #define sqlite3_value_text16 sqlite3_api->value_text16
103675 #define sqlite3_value_text16be sqlite3_api->value_text16be
103676 #define sqlite3_value_text16le sqlite3_api->value_text16le
103677 #define sqlite3_value_type sqlite3_api->value_type
103678 #define sqlite3_vmprintf sqlite3_api->vmprintf
103679 #define sqlite3_vsnprintf sqlite3_api->vsnprintf
103680 #define sqlite3_overload_function sqlite3_api->overload_function
103681 #define sqlite3_prepare_v2 sqlite3_api->prepare_v2
103682 #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
103683 #define sqlite3_clear_bindings sqlite3_api->clear_bindings
103684 #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
@@ -103491,13 +103770,16 @@
103770 /* Version 3.8.11 and later */
103771 #define sqlite3_value_dup sqlite3_api->value_dup
103772 #define sqlite3_value_free sqlite3_api->value_free
103773 #define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64
103774 #define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64
103775 /* Version 3.8.12 and later */
103776 #define sqlite3_value_subtype sqlite3_api->value_subtype
103777 #define sqlite3_result_subtype sqlite3_api->result_subtype
103778 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
103779
103780 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
103781 /* This case when the file really is being compiled as a loadable
103782 ** extension */
103783 # define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0;
103784 # define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v;
103785 # define SQLITE_EXTENSION_INIT3 \
@@ -103902,11 +104184,14 @@
104184 sqlite3_strglob,
104185 /* Version 3.8.11 and later */
104186 (sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
104187 sqlite3_value_free,
104188 sqlite3_result_zeroblob64,
104189 sqlite3_bind_zeroblob64,
104190 /* Version 3.8.12 and later */
104191 sqlite3_value_subtype,
104192 sqlite3_result_subtype
104193 };
104194
104195 /*
104196 ** Attempt to load an SQLite extension library contained in the file
104197 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -104898,25 +105183,51 @@
105183 }
105184 db->temp_store = (u8)ts;
105185 return SQLITE_OK;
105186 }
105187 #endif /* SQLITE_PAGER_PRAGMAS */
105188
105189 /*
105190 ** Set the names of the first N columns to the values in azCol[]
105191 */
105192 static void setAllColumnNames(
105193 Vdbe *v, /* The query under construction */
105194 int N, /* Number of columns */
105195 const char **azCol /* Names of columns */
105196 ){
105197 int i;
105198 sqlite3VdbeSetNumCols(v, N);
105199 for(i=0; i<N; i++){
105200 sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC);
105201 }
105202 }
105203 static void setOneColumnName(Vdbe *v, const char *z){
105204 setAllColumnNames(v, 1, &z);
105205 }
105206
105207 /*
105208 ** Generate code to return a single integer value.
105209 */
105210 static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){
105211 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
105212 setOneColumnName(v, zLabel);
105213 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105214 }
105215
105216 /*
105217 ** Generate code to return a single text value.
105218 */
105219 static void returnSingleText(
105220 Vdbe *v, /* Prepared statement under construction */
105221 const char *zLabel, /* Name of the result column */
105222 const char *zValue /* Value to be returned */
105223 ){
105224 if( zValue ){
105225 sqlite3VdbeLoadString(v, 1, (const char*)zValue);
105226 setOneColumnName(v, zLabel);
105227 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
105228 }
105229 }
105230
105231
105232 /*
105233 ** Set the safety_level and pager flags for pager iDb. Or if iDb<0
@@ -105076,18 +105387,12 @@
105387 aFcntl[2] = zRight;
105388 aFcntl[3] = 0;
105389 db->busyHandler.nBusy = 0;
105390 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
105391 if( rc==SQLITE_OK ){
105392 returnSingleText(v, "result", aFcntl[0]);
105393 sqlite3_free(aFcntl[0]);
 
 
 
 
 
 
105394 goto pragma_out;
105395 }
105396 if( rc!=SQLITE_NOTFOUND ){
105397 if( aFcntl[0] ){
105398 sqlite3ErrorMsg(pParse, "%s", aFcntl[0]);
@@ -105153,12 +105458,11 @@
105458 { OP_ResultRow, 1, 1, 0},
105459 };
105460 int addr;
105461 sqlite3VdbeUsesBtree(v, iDb);
105462 if( !zRight ){
105463 setOneColumnName(v, "cache_size");
 
105464 pParse->nMem += 2;
105465 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
105466 sqlite3VdbeChangeP1(v, addr, iDb);
105467 sqlite3VdbeChangeP1(v, addr+1, iDb);
105468 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
@@ -105188,11 +105492,11 @@
105492 case PragTyp_PAGE_SIZE: {
105493 Btree *pBt = pDb->pBt;
105494 assert( pBt!=0 );
105495 if( !zRight ){
105496 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
105497 returnSingleInt(v, "page_size", size);
105498 }else{
105499 /* Malloc may fail when setting the page-size, as there is an internal
105500 ** buffer that the pager module resizes using sqlite3_realloc().
105501 */
105502 db->nextPagesize = sqlite3Atoi(zRight);
@@ -105223,11 +105527,11 @@
105527 for(ii=0; ii<db->nDb; ii++){
105528 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
105529 }
105530 }
105531 b = sqlite3BtreeSecureDelete(pBt, b);
105532 returnSingleInt(v, "secure_delete", b);
105533 break;
105534 }
105535
105536 /*
105537 ** PRAGMA [database.]max_page_count
@@ -105302,14 +105606,11 @@
105606 assert( eMode==PAGER_LOCKINGMODE_NORMAL
105607 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
105608 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
105609 zRet = "exclusive";
105610 }
105611 returnSingleText(v, "locking_mode", zRet);
 
 
 
105612 break;
105613 }
105614
105615 /*
105616 ** PRAGMA [database.]journal_mode
@@ -105318,13 +105619,11 @@
105619 */
105620 case PragTyp_JOURNAL_MODE: {
105621 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
105622 int ii; /* Loop counter */
105623
105624 setOneColumnName(v, "journal_mode");
 
 
105625 if( zRight==0 ){
105626 /* If there is no "=MODE" part of the pragma, do a query for the
105627 ** current mode */
105628 eMode = PAGER_JOURNALMODE_QUERY;
105629 }else{
@@ -105366,11 +105665,11 @@
105665 if( zRight ){
105666 sqlite3DecOrHexToI64(zRight, &iLimit);
105667 if( iLimit<-1 ) iLimit = -1;
105668 }
105669 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
105670 returnSingleInt(v, "journal_size_limit", iLimit);
105671 break;
105672 }
105673
105674 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105675
@@ -105384,11 +105683,11 @@
105683 #ifndef SQLITE_OMIT_AUTOVACUUM
105684 case PragTyp_AUTO_VACUUM: {
105685 Btree *pBt = pDb->pBt;
105686 assert( pBt!=0 );
105687 if( !zRight ){
105688 returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
105689 }else{
105690 int eAuto = getAutoVacuum(zRight);
105691 assert( eAuto>=0 && eAuto<=2 );
105692 db->nextAutovac = (u8)eAuto;
105693 /* Call SetAutoVacuum() to set initialize the internal auto and
@@ -105462,11 +105761,11 @@
105761 */
105762 case PragTyp_CACHE_SIZE: {
105763 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
105764 if( !zRight ){
105765 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
105766 returnSingleInt(v, "cache_size", pDb->pSchema->cache_size);
105767 }else{
105768 int size = sqlite3Atoi(zRight);
105769 pDb->pSchema->cache_size = size;
105770 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
105771 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
@@ -105508,11 +105807,11 @@
105807 #else
105808 sz = 0;
105809 rc = SQLITE_OK;
105810 #endif
105811 if( rc==SQLITE_OK ){
105812 returnSingleInt(v, "mmap_size", sz);
105813 }else if( rc!=SQLITE_NOTFOUND ){
105814 pParse->nErr++;
105815 pParse->rc = rc;
105816 }
105817 break;
@@ -105529,11 +105828,11 @@
105828 ** Note that it is possible for the library compile-time options to
105829 ** override this setting
105830 */
105831 case PragTyp_TEMP_STORE: {
105832 if( !zRight ){
105833 returnSingleInt(v, "temp_store", db->temp_store);
105834 }else{
105835 changeTempStorage(pParse, zRight);
105836 }
105837 break;
105838 }
@@ -105548,17 +105847,11 @@
105847 ** If temporary directory is changed, then invalidateTempStorage.
105848 **
105849 */
105850 case PragTyp_TEMP_STORE_DIRECTORY: {
105851 if( !zRight ){
105852 returnSingleText(v, "temp_store_directory", sqlite3_temp_directory);
 
 
 
 
 
 
105853 }else{
105854 #ifndef SQLITE_OMIT_WSD
105855 if( zRight[0] ){
105856 int res;
105857 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -105598,17 +105891,11 @@
105891 ** by this setting, regardless of its value.
105892 **
105893 */
105894 case PragTyp_DATA_STORE_DIRECTORY: {
105895 if( !zRight ){
105896 returnSingleText(v, "data_store_directory", sqlite3_data_directory);
 
 
 
 
 
 
105897 }else{
105898 #ifndef SQLITE_OMIT_WSD
105899 if( zRight[0] ){
105900 int res;
105901 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -105643,18 +105930,11 @@
105930 Pager *pPager = sqlite3BtreePager(pDb->pBt);
105931 char *proxy_file_path = NULL;
105932 sqlite3_file *pFile = sqlite3PagerFile(pPager);
105933 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
105934 &proxy_file_path);
105935 returnSingleText(v, "lock_proxy_file", proxy_file_path);
 
 
 
 
 
 
 
105936 }else{
105937 Pager *pPager = sqlite3BtreePager(pDb->pBt);
105938 sqlite3_file *pFile = sqlite3PagerFile(pPager);
105939 int res;
105940 if( zRight[0] ){
@@ -105682,11 +105962,11 @@
105962 ** default value will be restored the next time the database is
105963 ** opened.
105964 */
105965 case PragTyp_SYNCHRONOUS: {
105966 if( !zRight ){
105967 returnSingleInt(v, "synchronous", pDb->safety_level-1);
105968 }else{
105969 if( !db->autoCommit ){
105970 sqlite3ErrorMsg(pParse,
105971 "Safety level may not be changed inside a transaction");
105972 }else{
@@ -105701,11 +105981,11 @@
105981 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
105982
105983 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
105984 case PragTyp_FLAG: {
105985 if( zRight==0 ){
105986 returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
105987 }else{
105988 int mask = pPragma->iArg; /* Mask of bits to set or clear. */
105989 if( db->autoCommit==0 ){
105990 /* Foreign key support may not be enabled or disabled while not
105991 ** in auto-commit mode. */
@@ -105751,79 +106031,67 @@
106031 */
106032 case PragTyp_TABLE_INFO: if( zRight ){
106033 Table *pTab;
106034 pTab = sqlite3FindTable(db, zRight, zDb);
106035 if( pTab ){
106036 static const char *azCol[] = {
106037 "cid", "name", "type", "notnull", "dflt_value", "pk"
106038 };
106039 int i, k;
106040 int nHidden = 0;
106041 Column *pCol;
106042 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
 
106043 pParse->nMem = 6;
106044 sqlite3CodeVerifySchema(pParse, iDb);
106045 setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
 
 
 
 
 
106046 sqlite3ViewGetColumnNames(pParse, pTab);
106047 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
106048 if( IsHiddenColumn(pCol) ){
106049 nHidden++;
106050 continue;
106051 }
 
 
 
 
 
 
 
 
 
 
106052 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
106053 k = 0;
106054 }else if( pPk==0 ){
106055 k = 1;
106056 }else{
106057 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
106058 }
106059 sqlite3VdbeMultiLoad(v, 1, "issisi",
106060 i-nHidden,
106061 pCol->zName,
106062 pCol->zType ? pCol->zType : "",
106063 pCol->notNull ? 1 : 0,
106064 pCol->zDflt,
106065 k);
106066 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
106067 }
106068 }
106069 }
106070 break;
106071
106072 case PragTyp_STATS: {
106073 static const char *azCol[] = { "table", "index", "width", "height" };
106074 Index *pIdx;
106075 HashElem *i;
106076 v = sqlite3GetVdbe(pParse);
 
106077 pParse->nMem = 4;
106078 sqlite3CodeVerifySchema(pParse, iDb);
106079 setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
 
 
 
106080 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
106081 Table *pTab = sqliteHashData(i);
106082 sqlite3VdbeMultiLoad(v, 1, "ssii",
106083 pTab->zName,
106084 0,
106085 (int)sqlite3LogEstToInt(pTab->szTabRow),
106086 (int)sqlite3LogEstToInt(pTab->nRowLogEst));
 
106087 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
106088 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
106089 sqlite3VdbeMultiLoad(v, 2, "sii",
106090 pIdx->zName,
106091 (int)sqlite3LogEstToInt(pIdx->szIdxRow),
106092 (int)sqlite3LogEstToInt(pIdx->aiRowLogEst[0]));
 
106093 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4);
106094 }
106095 }
106096 }
106097 break;
@@ -105831,10 +106099,13 @@
106099 case PragTyp_INDEX_INFO: if( zRight ){
106100 Index *pIdx;
106101 Table *pTab;
106102 pIdx = sqlite3FindIndex(db, zRight, zDb);
106103 if( pIdx ){
106104 static const char *azCol[] = {
106105 "seqno", "cid", "name", "desc", "coll", "key"
106106 };
106107 int i;
106108 int mx;
106109 if( pPragma->iArg ){
106110 /* PRAGMA index_xinfo (newer version with more rows and columns) */
106111 mx = pIdx->nColumn;
@@ -105843,33 +106114,22 @@
106114 /* PRAGMA index_info (legacy version) */
106115 mx = pIdx->nKeyCol;
106116 pParse->nMem = 3;
106117 }
106118 pTab = pIdx->pTable;
 
106119 sqlite3CodeVerifySchema(pParse, iDb);
106120 assert( pParse->nMem<=ArraySize(azCol) );
106121 setAllColumnNames(v, pParse->nMem, azCol);
 
 
 
 
 
 
106122 for(i=0; i<mx; i++){
106123 i16 cnum = pIdx->aiColumn[i];
106124 sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
106125 cnum<0 ? 0 : pTab->aCol[cnum].zName);
 
 
 
 
 
106126 if( pPragma->iArg ){
106127 sqlite3VdbeMultiLoad(v, 4, "isi",
106128 pIdx->aSortOrder[i],
106129 pIdx->azColl[i],
106130 i<pIdx->nKeyCol);
106131 }
106132 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
106133 }
106134 }
106135 }
@@ -105879,62 +106139,57 @@
106139 Index *pIdx;
106140 Table *pTab;
106141 int i;
106142 pTab = sqlite3FindTable(db, zRight, zDb);
106143 if( pTab ){
106144 static const char *azCol[] = {
106145 "seq", "name", "unique", "origin", "partial"
106146 };
106147 v = sqlite3GetVdbe(pParse);
 
106148 pParse->nMem = 5;
106149 sqlite3CodeVerifySchema(pParse, iDb);
106150 setAllColumnNames(v, 5, azCol); assert( 5==ArraySize(azCol) );
 
 
 
 
106151 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
106152 const char *azOrigin[] = { "c", "u", "pk" };
106153 sqlite3VdbeMultiLoad(v, 1, "isisi",
106154 i,
106155 pIdx->zName,
106156 IsUniqueIndex(pIdx),
106157 azOrigin[pIdx->idxType],
106158 pIdx->pPartIdxWhere!=0);
106159 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5);
106160 }
106161 }
106162 }
106163 break;
106164
106165 case PragTyp_DATABASE_LIST: {
106166 static const char *azCol[] = { "seq", "name", "file" };
106167 int i;
 
106168 pParse->nMem = 3;
106169 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
 
 
106170 for(i=0; i<db->nDb; i++){
106171 if( db->aDb[i].pBt==0 ) continue;
106172 assert( db->aDb[i].zName!=0 );
106173 sqlite3VdbeMultiLoad(v, 1, "iss",
106174 i,
106175 db->aDb[i].zName,
106176 sqlite3BtreeGetFilename(db->aDb[i].pBt));
106177 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
106178 }
106179 }
106180 break;
106181
106182 case PragTyp_COLLATION_LIST: {
106183 static const char *azCol[] = { "seq", "name" };
106184 int i = 0;
106185 HashElem *p;
 
106186 pParse->nMem = 2;
106187 setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
 
106188 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
106189 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
106190 sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
 
106191 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
106192 }
106193 }
106194 break;
106195 #endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
@@ -105946,37 +106201,30 @@
106201 pTab = sqlite3FindTable(db, zRight, zDb);
106202 if( pTab ){
106203 v = sqlite3GetVdbe(pParse);
106204 pFK = pTab->pFKey;
106205 if( pFK ){
106206 static const char *azCol[] = {
106207 "id", "seq", "table", "from", "to", "on_update", "on_delete",
106208 "match"
106209 };
106210 int i = 0;
 
106211 pParse->nMem = 8;
106212 sqlite3CodeVerifySchema(pParse, iDb);
106213 setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) );
 
 
 
 
 
 
 
106214 while(pFK){
106215 int j;
106216 for(j=0; j<pFK->nCol; j++){
106217 sqlite3VdbeMultiLoad(v, 1, "iissssss",
106218 i,
106219 j,
106220 pFK->zTo,
106221 pTab->aCol[pFK->aCol[j].iFrom].zName,
106222 pFK->aCol[j].zCol,
106223 actionName(pFK->aAction[1]), /* ON UPDATE */
106224 actionName(pFK->aAction[0]), /* ON DELETE */
106225 "NONE");
 
 
 
106226 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 8);
106227 }
106228 ++i;
106229 pFK = pFK->pNextFrom;
106230 }
@@ -106001,21 +106249,18 @@
106249 int regKey; /* Register to hold key for checking the FK */
106250 int regRow; /* Registers to hold a row from pTab */
106251 int addrTop; /* Top of a loop checking foreign keys */
106252 int addrOk; /* Jump here if the key is OK */
106253 int *aiCols; /* child to parent column mapping */
106254 static const char *azCol[] = { "table", "rowid", "parent", "fkid" };
106255
106256 regResult = pParse->nMem+1;
106257 pParse->nMem += 4;
106258 regKey = ++pParse->nMem;
106259 regRow = ++pParse->nMem;
106260 v = sqlite3GetVdbe(pParse);
106261 setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
 
 
 
 
106262 sqlite3CodeVerifySchema(pParse, iDb);
106263 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
106264 while( k ){
106265 if( zRight ){
106266 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
@@ -106026,12 +106271,11 @@
106271 }
106272 if( pTab==0 || pTab->pFKey==0 ) continue;
106273 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
106274 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
106275 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
106276 sqlite3VdbeLoadString(v, regResult, pTab->zName);
 
106277 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
106278 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
106279 if( pParent==0 ) continue;
106280 pIdx = 0;
106281 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -106072,29 +106316,27 @@
106316 sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
106317 }else{
106318 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
106319 }
106320 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
106321 sqlite3VdbeGoto(v, addrOk);
106322 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
106323 }else{
106324 for(j=0; j<pFK->nCol; j++){
106325 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
106326 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
106327 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
106328 }
106329 if( pParent ){
106330 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
106331 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
106332 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
106333 VdbeCoverage(v);
106334 }
106335 }
106336 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
106337 sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
 
 
106338 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
106339 sqlite3VdbeResolveLabel(v, addrOk);
106340 sqlite3DbFree(db, aiCols);
106341 }
106342 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
@@ -106166,12 +106408,11 @@
106408 assert( iDb==0 || pId2->z );
106409 if( pId2->z==0 ) iDb = -1;
106410
106411 /* Initialize the VDBE program */
106412 pParse->nMem = 6;
106413 setOneColumnName(v, "integrity_check");
 
106414
106415 /* Set the maximum error count */
106416 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
106417 if( zRight ){
106418 sqlite3GetInt32(zRight, &mxErr);
@@ -106289,17 +106530,15 @@
106530 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
106531 /* Verify that an index entry exists for the current table row */
106532 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
106533 pIdx->nColumn); VdbeCoverage(v);
106534 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106535 sqlite3VdbeLoadString(v, 3, "row ");
106536 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
106537 sqlite3VdbeLoadString(v, 4, " missing from index ");
 
106538 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106539 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
 
106540 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
106541 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
106542 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
106543 sqlite3VdbeAddOp0(v, OP_Halt);
106544 sqlite3VdbeJumpHere(v, jmp2);
@@ -106316,38 +106555,36 @@
106555 if( pTab->aCol[iCol].notNull ) continue;
106556 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
106557 VdbeCoverage(v);
106558 }
106559 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
106560 sqlite3VdbeGoto(v, uniqOk);
106561 sqlite3VdbeJumpHere(v, jmp6);
106562 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
106563 pIdx->nKeyCol); VdbeCoverage(v);
106564 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
106565 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
106566 sqlite3VdbeGoto(v, jmp5);
 
106567 sqlite3VdbeResolveLabel(v, uniqOk);
106568 }
106569 sqlite3VdbeJumpHere(v, jmp4);
106570 sqlite3ResolvePartIdxLabel(pParse, jmp3);
106571 }
106572 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
106573 sqlite3VdbeJumpHere(v, loopTop-1);
106574 #ifndef SQLITE_OMIT_BTREECOUNT
106575 sqlite3VdbeLoadString(v, 2, "wrong # of entries in index ");
 
106576 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
106577 if( pPk==pIdx ) continue;
106578 addr = sqlite3VdbeCurrentAddr(v);
106579 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
106580 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
106581 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
106582 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
106583 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
106584 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
106585 sqlite3VdbeLoadString(v, 3, pIdx->zName);
106586 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
106587 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
106588 }
106589 #endif /* SQLITE_OMIT_BTREECOUNT */
106590 }
@@ -106399,18 +106636,14 @@
106636 { 0, 0 }
106637 };
106638 const struct EncName *pEnc;
106639 if( !zRight ){ /* "PRAGMA encoding" */
106640 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
 
 
 
106641 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
106642 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
106643 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
106644 returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
 
106645 }else{ /* "PRAGMA encoding = XXX" */
106646 /* Only change the value of sqlite.enc if the database handle is not
106647 ** initialized. If the main database exists, the new sqlite.enc value
106648 ** will be overwritten when the schema is next loaded. If it does not
106649 ** already exists, it will be created to use the new encoding value.
@@ -106507,15 +106740,14 @@
106740 ** one option per row.
106741 */
106742 case PragTyp_COMPILE_OPTIONS: {
106743 int i = 0;
106744 const char *zOpt;
 
106745 pParse->nMem = 1;
106746 setOneColumnName(v, "compile_option");
106747 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
106748 sqlite3VdbeLoadString(v, 1, zOpt);
106749 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
106750 }
106751 }
106752 break;
106753 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
@@ -106525,10 +106757,11 @@
106757 ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
106758 **
106759 ** Checkpoint the database.
106760 */
106761 case PragTyp_WAL_CHECKPOINT: {
106762 static const char *azCol[] = { "busy", "log", "checkpointed" };
106763 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
106764 int eMode = SQLITE_CHECKPOINT_PASSIVE;
106765 if( zRight ){
106766 if( sqlite3StrICmp(zRight, "full")==0 ){
106767 eMode = SQLITE_CHECKPOINT_FULL;
@@ -106536,16 +106769,12 @@
106769 eMode = SQLITE_CHECKPOINT_RESTART;
106770 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
106771 eMode = SQLITE_CHECKPOINT_TRUNCATE;
106772 }
106773 }
106774 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
106775 pParse->nMem = 3;
 
 
 
 
106776 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
106777 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
106778 }
106779 break;
106780
@@ -106559,11 +106788,11 @@
106788 */
106789 case PragTyp_WAL_AUTOCHECKPOINT: {
106790 if( zRight ){
106791 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
106792 }
106793 returnSingleInt(v, "wal_autocheckpoint",
106794 db->xWalCallback==sqlite3WalDefaultHook ?
106795 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
106796 }
106797 break;
106798 #endif
@@ -106592,11 +106821,11 @@
106821 /*case PragTyp_BUSY_TIMEOUT*/ default: {
106822 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
106823 if( zRight ){
106824 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
106825 }
106826 returnSingleInt(v, "timeout", db->busyTimeout);
106827 break;
106828 }
106829
106830 /*
106831 ** PRAGMA soft_heap_limit
@@ -106612,11 +106841,11 @@
106841 case PragTyp_SOFT_HEAP_LIMIT: {
106842 sqlite3_int64 N;
106843 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
106844 sqlite3_soft_heap_limit64(N);
106845 }
106846 returnSingleInt(v, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
106847 break;
106848 }
106849
106850 /*
106851 ** PRAGMA threads
@@ -106631,11 +106860,11 @@
106860 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
106861 && N>=0
106862 ){
106863 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
106864 }
106865 returnSingleInt(v, "threads",
106866 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
106867 break;
106868 }
106869
106870 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
@@ -106644,29 +106873,27 @@
106873 */
106874 case PragTyp_LOCK_STATUS: {
106875 static const char *const azLockName[] = {
106876 "unlocked", "shared", "reserved", "pending", "exclusive"
106877 };
106878 static const char *azCol[] = { "database", "status" };
106879 int i;
106880 setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
106881 pParse->nMem = 2;
 
 
106882 for(i=0; i<db->nDb; i++){
106883 Btree *pBt;
106884 const char *zState = "unknown";
106885 int j;
106886 if( db->aDb[i].zName==0 ) continue;
 
106887 pBt = db->aDb[i].pBt;
106888 if( pBt==0 || sqlite3BtreePager(pBt)==0 ){
106889 zState = "closed";
106890 }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0,
106891 SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
106892 zState = azLockName[j];
106893 }
106894 sqlite3VdbeMultiLoad(v, 1, "ss", db->aDb[i].zName, zState);
106895 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
106896 }
106897 break;
106898 }
106899 #endif
@@ -108027,16 +108254,16 @@
108254 Table *pLeftTab = pLeft->pTab;
108255 Table *pRightTab = pRight->pTab;
108256 int isOuter;
108257
108258 if( NEVER(pLeftTab==0 || pRightTab==0) ) continue;
108259 isOuter = (pRight->fg.jointype & JT_OUTER)!=0;
108260
108261 /* When the NATURAL keyword is present, add WHERE clause terms for
108262 ** every column that the two tables have in common.
108263 */
108264 if( pRight->fg.jointype & JT_NATURAL ){
108265 if( pRight->pOn || pRight->pUsing ){
108266 sqlite3ErrorMsg(pParse, "a NATURAL join may not have "
108267 "an ON or USING clause", 0);
108268 return 1;
108269 }
@@ -108117,10 +108344,11 @@
108344 static void pushOntoSorter(
108345 Parse *pParse, /* Parser context */
108346 SortCtx *pSort, /* Information about the ORDER BY clause */
108347 Select *pSelect, /* The whole SELECT statement */
108348 int regData, /* First register holding data to be sorted */
108349 int regOrigData, /* First register holding data before packing */
108350 int nData, /* Number of elements in the data array */
108351 int nPrefixReg /* No. of reg prior to regData available for use */
108352 ){
108353 Vdbe *v = pParse->pVdbe; /* Stmt under construction */
108354 int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
@@ -108130,18 +108358,20 @@
108358 int regRecord = ++pParse->nMem; /* Assembled sorter record */
108359 int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */
108360 int op; /* Opcode to add sorter record to sorter */
108361
108362 assert( bSeq==0 || bSeq==1 );
108363 assert( nData==1 || regData==regOrigData );
108364 if( nPrefixReg ){
108365 assert( nPrefixReg==nExpr+bSeq );
108366 regBase = regData - nExpr - bSeq;
108367 }else{
108368 regBase = pParse->nMem + 1;
108369 pParse->nMem += nBase;
108370 }
108371 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
108372 SQLITE_ECEL_DUP|SQLITE_ECEL_REF);
108373 if( bSeq ){
108374 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
108375 }
108376 if( nPrefixReg==0 ){
108377 sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
@@ -108215,11 +108445,11 @@
108445 int iContinue /* Jump here to skip the current record */
108446 ){
108447 if( iOffset>0 ){
108448 int addr;
108449 addr = sqlite3VdbeAddOp3(v, OP_IfNeg, iOffset, 0, -1); VdbeCoverage(v);
108450 sqlite3VdbeGoto(v, iContinue);
108451 VdbeComment((v, "skip OFFSET records"));
108452 sqlite3VdbeJumpHere(v, addr);
108453 }
108454 }
108455
@@ -108347,11 +108577,11 @@
108577 if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
108578 ecelFlags = SQLITE_ECEL_DUP;
108579 }else{
108580 ecelFlags = 0;
108581 }
108582 sqlite3ExprCodeExprList(pParse, pEList, regResult, 0, ecelFlags);
108583 }
108584
108585 /* If the DISTINCT keyword was present on the SELECT statement
108586 ** and this row has been seen before, then do not make this row
108587 ** part of the result.
@@ -108463,11 +108693,11 @@
108693 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
108694 assert( pSort==0 );
108695 }
108696 #endif
108697 if( pSort ){
108698 pushOntoSorter(pParse, pSort, p, r1+nPrefixReg,regResult,1,nPrefixReg);
108699 }else{
108700 int r2 = sqlite3GetTempReg(pParse);
108701 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);
108702 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);
108703 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -108489,11 +108719,11 @@
108719 if( pSort ){
108720 /* At first glance you would think we could optimize out the
108721 ** ORDER BY in this case since the order of entries in the set
108722 ** does not matter. But there might be a LIMIT clause, in which
108723 ** case the order does matter */
108724 pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
108725 }else{
108726 int r1 = sqlite3GetTempReg(pParse);
108727 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult,1,r1, &pDest->affSdst, 1);
108728 sqlite3ExprCacheAffinityChange(pParse, regResult, 1);
108729 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
@@ -108515,11 +108745,11 @@
108745 ** of the scan loop.
108746 */
108747 case SRT_Mem: {
108748 assert( nResultCol==1 );
108749 if( pSort ){
108750 pushOntoSorter(pParse, pSort, p, regResult, regResult, 1, nPrefixReg);
108751 }else{
108752 assert( regResult==iParm );
108753 /* The LIMIT clause will jump out of the loop for us */
108754 }
108755 break;
@@ -108529,11 +108759,12 @@
108759 case SRT_Coroutine: /* Send data to a co-routine */
108760 case SRT_Output: { /* Return the results */
108761 testcase( eDest==SRT_Coroutine );
108762 testcase( eDest==SRT_Output );
108763 if( pSort ){
108764 pushOntoSorter(pParse, pSort, p, regResult, regResult, nResultCol,
108765 nPrefixReg);
108766 }else if( eDest==SRT_Coroutine ){
108767 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
108768 }else{
108769 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
108770 sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
@@ -108823,11 +109054,11 @@
109054 struct ExprList_item *aOutEx = p->pEList->a;
109055 #endif
109056
109057 if( pSort->labelBkOut ){
109058 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
109059 sqlite3VdbeGoto(v, addrBreak);
109060 sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
109061 }
109062 iTab = pSort->iECursor;
109063 if( eDest==SRT_Output || eDest==SRT_Coroutine ){
109064 regRowid = 0;
@@ -109208,11 +109439,11 @@
109439 ** and other fields of Column are zeroed.
109440 **
109441 ** Return SQLITE_OK on success. If a memory allocation error occurs,
109442 ** store NULL in *paCol and 0 in *pnCol and return SQLITE_NOMEM.
109443 */
109444 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(
109445 Parse *pParse, /* Parsing context */
109446 ExprList *pEList, /* Expr list from which to derive column names */
109447 i16 *pnCol, /* Write the number of columns here */
109448 Column **paCol /* Write the new column list here */
109449 ){
@@ -109375,11 +109606,11 @@
109606 ** is disabled */
109607 assert( db->lookaside.bEnabled==0 );
109608 pTab->nRef = 1;
109609 pTab->zName = 0;
109610 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
109611 sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
109612 selectAddColumnTypeAndCollation(pParse, pTab, pSelect);
109613 pTab->iPKey = -1;
109614 if( db->mallocFailed ){
109615 sqlite3DeleteTable(db, pTab);
109616 return 0;
@@ -109451,11 +109682,11 @@
109682 assert( v!=0 );
109683 if( sqlite3ExprIsInteger(p->pLimit, &n) ){
109684 sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
109685 VdbeComment((v, "LIMIT counter"));
109686 if( n==0 ){
109687 sqlite3VdbeGoto(v, iBreak);
109688 }else if( n>=0 && p->nSelectRow>(u64)n ){
109689 p->nSelectRow = n;
109690 }
109691 }else{
109692 sqlite3ExprCode(pParse, p->pLimit, iLimit);
@@ -109554,11 +109785,11 @@
109785 ** \___________/ \_______________/
109786 ** p->pPrior p
109787 **
109788 **
109789 ** There is exactly one reference to the recursive-table in the FROM clause
109790 ** of recursive-query, marked with the SrcList->a[].fg.isRecursive flag.
109791 **
109792 ** The setup-query runs once to generate an initial set of rows that go
109793 ** into a Queue table. Rows are extracted from the Queue table one by
109794 ** one. Each row extracted from Queue is output to pDest. Then the single
109795 ** extracted row (now in the iCurrent table) becomes the content of the
@@ -109619,11 +109850,11 @@
109850 p->iLimit = p->iOffset = 0;
109851 pOrderBy = p->pOrderBy;
109852
109853 /* Locate the cursor number of the Current table */
109854 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
109855 if( pSrc->a[i].fg.isRecursive ){
109856 iCurrent = pSrc->a[i].iCursor;
109857 break;
109858 }
109859 }
109860
@@ -109699,11 +109930,11 @@
109930 assert( p->pPrior==0 );
109931 p->pPrior = pSetup;
109932 }
109933
109934 /* Keep running the loop until the Queue is empty */
109935 sqlite3VdbeGoto(v, addrTop);
109936 sqlite3VdbeResolveLabel(v, addrBreak);
109937
109938 end_of_recursive_query:
109939 sqlite3ExprListDelete(pParse->db, p->pOrderBy);
109940 p->pOrderBy = pOrderBy;
@@ -110608,11 +110839,11 @@
110839 }else{
110840 VdbeNoopComment((v, "eof-A subroutine"));
110841 addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110842 addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
110843 VdbeCoverage(v);
110844 sqlite3VdbeGoto(v, addrEofA);
110845 p->nSelectRow += pPrior->nSelectRow;
110846 }
110847
110848 /* Generate a subroutine to run when the results from select B
110849 ** are exhausted and only data in select A remains.
@@ -110622,19 +110853,19 @@
110853 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
110854 }else{
110855 VdbeNoopComment((v, "eof-B subroutine"));
110856 addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110857 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
110858 sqlite3VdbeGoto(v, addrEofB);
110859 }
110860
110861 /* Generate code to handle the case of A<B
110862 */
110863 VdbeNoopComment((v, "A-lt-B subroutine"));
110864 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
110865 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110866 sqlite3VdbeGoto(v, labelCmpr);
110867
110868 /* Generate code to handle the case of A==B
110869 */
110870 if( op==TK_ALL ){
110871 addrAeqB = addrAltB;
@@ -110643,11 +110874,11 @@
110874 addrAltB++;
110875 }else{
110876 VdbeNoopComment((v, "A-eq-B subroutine"));
110877 addrAeqB =
110878 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
110879 sqlite3VdbeGoto(v, labelCmpr);
110880 }
110881
110882 /* Generate code to handle the case of A>B
110883 */
110884 VdbeNoopComment((v, "A-gt-B subroutine"));
@@ -110654,11 +110885,11 @@
110885 addrAgtB = sqlite3VdbeCurrentAddr(v);
110886 if( op==TK_ALL || op==TK_UNION ){
110887 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
110888 }
110889 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
110890 sqlite3VdbeGoto(v, labelCmpr);
110891
110892 /* This code runs once to initialize everything.
110893 */
110894 sqlite3VdbeJumpHere(v, j1);
110895 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
@@ -111034,11 +111265,11 @@
111265 ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
111266 ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
111267 ** is fraught with danger. Best to avoid the whole thing. If the
111268 ** subquery is the right term of a LEFT JOIN, then do not flatten.
111269 */
111270 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
111271 return 0;
111272 }
111273
111274 /* Restriction 17: If the sub-query is a compound SELECT, then it must
111275 ** use only the UNION ALL operator. And none of the simple select queries
@@ -111205,11 +111436,11 @@
111436 nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
111437 pSrc = pParent->pSrc; /* FROM clause of the outer query */
111438
111439 if( pSrc ){
111440 assert( pParent==p ); /* First time through the loop */
111441 jointype = pSubitem->fg.jointype;
111442 }else{
111443 assert( pParent!=p ); /* 2nd and subsequent times through the loop */
111444 pSrc = pParent->pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
111445 if( pSrc==0 ){
111446 assert( db->mallocFailed );
@@ -111245,11 +111476,11 @@
111476 for(i=0; i<nSubSrc; i++){
111477 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
111478 pSrc->a[i+iFrom] = pSubSrc->a[i];
111479 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
111480 }
111481 pSrc->a[iFrom].fg.jointype = jointype;
111482
111483 /* Now begin substituting subquery result set expressions for
111484 ** references to the iParent in the outer query.
111485 **
111486 ** Example:
@@ -111377,10 +111608,13 @@
111608 ** close would change the meaning of the LIMIT).
111609 **
111610 ** (4) The inner query is the right operand of a LEFT JOIN. (The caller
111611 ** enforces this restriction since this routine does not have enough
111612 ** information to know.)
111613 **
111614 ** (5) The WHERE clause expression originates in the ON or USING clause
111615 ** of a LEFT JOIN.
111616 **
111617 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
111618 ** terms are duplicated into the subquery.
111619 */
111620 static int pushDownWhereTerms(
@@ -111400,10 +111634,11 @@
111634 }
111635 while( pWhere->op==TK_AND ){
111636 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
111637 pWhere = pWhere->pLeft;
111638 }
111639 if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
111640 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
111641 nChng++;
111642 while( pSubq ){
111643 pNew = sqlite3ExprDup(db, pWhere, 0);
111644 pNew = substExpr(db, pNew, iCursor, pSubq->pEList);
@@ -111496,13 +111731,13 @@
111731 ** was such a clause and the named index cannot be found, return
111732 ** SQLITE_ERROR and leave an error in pParse. Otherwise, populate
111733 ** pFrom->pIndex and return SQLITE_OK.
111734 */
111735 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *pParse, struct SrcList_item *pFrom){
111736 if( pFrom->pTab && pFrom->fg.isIndexedBy ){
111737 Table *pTab = pFrom->pTab;
111738 char *zIndexedBy = pFrom->u1.zIndexedBy;
111739 Index *pIdx;
111740 for(pIdx=pTab->pIndex;
111741 pIdx && sqlite3StrICmp(pIdx->zName, zIndexedBy);
111742 pIdx=pIdx->pNext
111743 );
@@ -111509,11 +111744,11 @@
111744 if( !pIdx ){
111745 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
111746 pParse->checkSchema = 1;
111747 return SQLITE_ERROR;
111748 }
111749 pFrom->pIBIndex = pIdx;
111750 }
111751 return SQLITE_OK;
111752 }
111753 /*
111754 ** Detect compound SELECT statements that use an ORDER BY clause with
@@ -111670,16 +111905,16 @@
111905 Select *pSel;
111906 Select *pLeft; /* Left-most SELECT statement */
111907 int bMayRecursive; /* True if compound joined by UNION [ALL] */
111908 With *pSavedWith; /* Initial value of pParse->pWith */
111909
111910 /* If pCte->zCteErr is non-NULL at this point, then this is an illegal
111911 ** recursive reference to CTE pCte. Leave an error in pParse and return
111912 ** early. If pCte->zCteErr is NULL, then this is not a recursive reference.
111913 ** In this case, proceed. */
111914 if( pCte->zCteErr ){
111915 sqlite3ErrorMsg(pParse, pCte->zCteErr, pCte->zName);
111916 return SQLITE_ERROR;
111917 }
111918
111919 assert( pFrom->pTab==0 );
111920 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
@@ -111704,11 +111939,11 @@
111939 if( pItem->zDatabase==0
111940 && pItem->zName!=0
111941 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
111942 ){
111943 pItem->pTab = pTab;
111944 pItem->fg.isRecursive = 1;
111945 pTab->nRef++;
111946 pSel->selFlags |= SF_Recursive;
111947 }
111948 }
111949 }
@@ -111720,11 +111955,11 @@
111955 );
111956 return SQLITE_ERROR;
111957 }
111958 assert( pTab->nRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nRef==2 ));
111959
111960 pCte->zCteErr = "circular reference: %s";
111961 pSavedWith = pParse->pWith;
111962 pParse->pWith = pWith;
111963 sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
111964
111965 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
@@ -111738,20 +111973,20 @@
111973 return SQLITE_ERROR;
111974 }
111975 pEList = pCte->pCols;
111976 }
111977
111978 sqlite3ColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol);
111979 if( bMayRecursive ){
111980 if( pSel->selFlags & SF_Recursive ){
111981 pCte->zCteErr = "multiple recursive references: %s";
111982 }else{
111983 pCte->zCteErr = "recursive reference in a subquery: %s";
111984 }
111985 sqlite3WalkSelect(pWalker, pSel);
111986 }
111987 pCte->zCteErr = 0;
111988 pParse->pWith = pSavedWith;
111989 }
111990
111991 return SQLITE_OK;
111992 }
@@ -111834,12 +112069,12 @@
112069 ** an entry of the FROM clause is a subquery instead of a table or view,
112070 ** then create a transient table structure to describe the subquery.
112071 */
112072 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
112073 Table *pTab;
112074 assert( pFrom->fg.isRecursive==0 || pFrom->pTab );
112075 if( pFrom->fg.isRecursive ) continue;
112076 if( pFrom->pTab!=0 ){
112077 /* This statement has already been prepared. There is no need
112078 ** to go further. */
112079 assert( i==0 );
112080 #ifndef SQLITE_OMIT_CTE
@@ -111861,11 +112096,11 @@
112096 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
112097 if( pTab==0 ) return WRC_Abort;
112098 pTab->nRef = 1;
112099 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
112100 while( pSel->pPrior ){ pSel = pSel->pPrior; }
112101 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
112102 pTab->iPKey = -1;
112103 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
112104 pTab->tabFlags |= TF_Ephemeral;
112105 #endif
112106 }else{
@@ -111998,11 +112233,11 @@
112233 continue;
112234 }
112235 tableSeen = 1;
112236
112237 if( i>0 && zTName==0 ){
112238 if( (pFrom->fg.jointype & JT_NATURAL)!=0
112239 && tableAndColumnIndex(pTabList, i, zName, 0, 0)
112240 ){
112241 /* In a NATURAL join, omit the join columns from the
112242 ** table to the right of the join */
112243 continue;
@@ -112284,11 +112519,11 @@
112519 ExprList *pList = pF->pExpr->x.pList;
112520 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
112521 if( pList ){
112522 nArg = pList->nExpr;
112523 regAgg = sqlite3GetTempRange(pParse, nArg);
112524 sqlite3ExprCodeExprList(pParse, pList, regAgg, 0, SQLITE_ECEL_DUP);
112525 }else{
112526 nArg = 0;
112527 regAgg = 0;
112528 }
112529 if( pF->iDistinct>=0 ){
@@ -112525,11 +112760,11 @@
112760 ** for example. In that case, do not regenerate the code to manifest
112761 ** a view or the co-routine to implement a view. The first instance
112762 ** is sufficient, though the subroutine to manifest the view does need
112763 ** to be invoked again. */
112764 if( pItem->addrFillSub ){
112765 if( pItem->fg.viaCoroutine==0 ){
112766 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
112767 }
112768 continue;
112769 }
112770
@@ -112543,11 +112778,11 @@
112778 pParse->nHeight += sqlite3SelectExprHeight(p);
112779
112780 /* Make copies of constant WHERE-clause terms in the outer query down
112781 ** inside the subquery. This can help the subquery to run more efficiently.
112782 */
112783 if( (pItem->fg.jointype & JT_OUTER)==0
112784 && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor)
112785 ){
112786 #if SELECTTRACE_ENABLED
112787 if( sqlite3SelectTrace & 0x100 ){
112788 SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
@@ -112572,11 +112807,11 @@
112807 pItem->addrFillSub = addrTop;
112808 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
112809 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
112810 sqlite3Select(pParse, pSub, &dest);
112811 pItem->pTab->nRowLogEst = sqlite3LogEst(pSub->nSelectRow);
112812 pItem->fg.viaCoroutine = 1;
112813 pItem->regResult = dest.iSdst;
112814 sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
112815 sqlite3VdbeJumpHere(v, addrTop-1);
112816 sqlite3ClearTempRegCache(pParse);
112817 }else{
@@ -112590,11 +112825,11 @@
112825 int retAddr;
112826 assert( pItem->addrFillSub==0 );
112827 pItem->regReturn = ++pParse->nMem;
112828 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
112829 pItem->addrFillSub = topAddr+1;
112830 if( pItem->fg.isCorrelated==0 ){
112831 /* If the subquery is not correlated and if we are not inside of
112832 ** a trigger, then we only need to compute the value of the subquery
112833 ** once. */
112834 onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
112835 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
@@ -112688,11 +112923,11 @@
112923 */
112924 iEnd = sqlite3VdbeMakeLabel(v);
112925 p->nSelectRow = LARGEST_INT64;
112926 computeLimitRegisters(pParse, p, iEnd);
112927 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
112928 sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
112929 sSort.sortFlags |= SORTFLAG_UseSorter;
112930 }
112931
112932 /* Open an ephemeral index to use for the distinct set.
112933 */
@@ -112904,11 +113139,11 @@
113139 j++;
113140 }
113141 }
113142 regBase = sqlite3GetTempRange(pParse, nCol);
113143 sqlite3ExprCacheClear(pParse);
113144 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
113145 j = nGroupBy;
113146 for(i=0; i<sAggInfo.nColumn; i++){
113147 struct AggInfo_col *pCol = &sAggInfo.aCol[i];
113148 if( pCol->iSorterColumn>=j ){
113149 int r1 = j + regBase;
@@ -113016,11 +113251,11 @@
113251 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
113252 VdbeComment((v, "output final row"));
113253
113254 /* Jump over the subroutines
113255 */
113256 sqlite3VdbeGoto(v, addrEnd);
113257
113258 /* Generate a subroutine that outputs a single row of the result
113259 ** set. This subroutine first looks at the iUseFlag. If iUseFlag
113260 ** is less than or equal to zero, the subroutine is a no-op. If
113261 ** the processing calls for the query to abort, this subroutine
@@ -113170,11 +113405,11 @@
113405 goto select_end;
113406 }
113407 updateAccumulator(pParse, &sAggInfo);
113408 assert( pMinMax==0 || pMinMax->nExpr==1 );
113409 if( sqlite3WhereIsOrdered(pWInfo)>0 ){
113410 sqlite3VdbeGoto(v, sqlite3WhereBreakLabel(pWInfo));
113411 VdbeComment((v, "%s() by index",
113412 (flag==WHERE_ORDERBY_MIN?"min":"max")));
113413 }
113414 sqlite3WhereEnd(pWInfo);
113415 finalizeAggFunctions(pParse, &sAggInfo);
@@ -114831,20 +115066,23 @@
115066
115067 hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
115068
115069 /* There is one entry in the aRegIdx[] array for each index on the table
115070 ** being updated. Fill in aRegIdx[] with a register number that will hold
115071 ** the key for accessing each index.
115072 **
115073 ** FIXME: Be smarter about omitting indexes that use expressions.
115074 */
115075 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115076 int reg;
115077 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
115078 reg = ++pParse->nMem;
115079 }else{
115080 reg = 0;
115081 for(i=0; i<pIdx->nKeyCol; i++){
115082 i16 iIdxCol = pIdx->aiColumn[i];
115083 if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
115084 reg = ++pParse->nMem;
115085 break;
115086 }
115087 }
115088 }
@@ -114940,20 +115178,21 @@
115178 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
115179 WHERE_ONEPASS_DESIRED, iIdxCur);
115180 if( pWInfo==0 ) goto update_cleanup;
115181 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
115182 for(i=0; i<nPk; i++){
115183 assert( pPk->aiColumn[i]>=(-1) );
115184 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
115185 iPk+i);
115186 }
115187 if( okOnePass ){
115188 sqlite3VdbeChangeToNoop(v, addrOpen);
115189 nKey = nPk;
115190 regKey = iPk;
115191 }else{
115192 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
115193 sqlite3IndexAffinityStr(db, pPk), nPk);
115194 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
115195 }
115196 sqlite3WhereEnd(pWInfo);
115197 }
115198
@@ -115186,11 +115425,11 @@
115425 /* Nothing to do at end-of-loop for a single-pass */
115426 }else if( pPk ){
115427 sqlite3VdbeResolveLabel(v, labelContinue);
115428 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
115429 }else{
115430 sqlite3VdbeGoto(v, labelContinue);
115431 }
115432 sqlite3VdbeResolveLabel(v, labelBreak);
115433
115434 /* Close all tables */
115435 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
@@ -115768,10 +116007,11 @@
116007 memcpy(zCopy, zName, nName+1);
116008 pMod->zName = zCopy;
116009 pMod->pModule = pModule;
116010 pMod->pAux = pAux;
116011 pMod->xDestroy = xDestroy;
116012 pMod->pEpoTab = 0;
116013 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
116014 assert( pDel==0 || pDel==pMod );
116015 if( pDel ){
116016 db->mallocFailed = 1;
116017 sqlite3DbFree(db, pDel);
@@ -115995,27 +116235,21 @@
116235 ** The string is not copied - the pointer is stored. The
116236 ** string will be freed automatically when the table is
116237 ** deleted.
116238 */
116239 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
116240 int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
 
116241 char **azModuleArg;
116242 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
116243 if( azModuleArg==0 ){
 
 
 
 
116244 sqlite3DbFree(db, zArg);
 
 
116245 }else{
116246 int i = pTable->nModuleArg++;
116247 azModuleArg[i] = zArg;
116248 azModuleArg[i+1] = 0;
116249 pTable->azModuleArg = azModuleArg;
116250 }
 
116251 }
116252
116253 /*
116254 ** The parser calls this routine when it first sees a CREATE VIRTUAL TABLE
116255 ** statement. The module name has been parsed, but the optional list
@@ -116138,11 +116372,11 @@
116372 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
116373 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
116374 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
116375
116376 iReg = ++pParse->nMem;
116377 sqlite3VdbeLoadString(v, iReg, pTab->zName);
116378 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
116379 }
116380
116381 /* If we are rereading the sqlite_master table create the in-memory
116382 ** record of the table. The xConnect() method is not called until
@@ -116414,11 +116648,11 @@
116648
116649 /* If the module has been registered and includes a Create method,
116650 ** invoke it now. If the module has not been registered, return an
116651 ** error. Otherwise, do nothing.
116652 */
116653 if( pMod==0 || pMod->pModule->xCreate==0 || pMod->pModule->xDestroy==0 ){
116654 *pzErr = sqlite3MPrintf(db, "no such module: %s", zMod);
116655 rc = SQLITE_ERROR;
116656 }else{
116657 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xCreate, pzErr);
116658 }
@@ -116516,18 +116750,21 @@
116750 Table *pTab;
116751
116752 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
116753 if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
116754 VTable *p;
116755 int (*xDestroy)(sqlite3_vtab *);
116756 for(p=pTab->pVTable; p; p=p->pNext){
116757 assert( p->pVtab );
116758 if( p->pVtab->nRef>0 ){
116759 return SQLITE_LOCKED;
116760 }
116761 }
116762 p = vtabDisconnectAll(db, pTab);
116763 xDestroy = p->pMod->pModule->xDestroy;
116764 assert( xDestroy!=0 ); /* Checked before the virtual table is created */
116765 rc = xDestroy(p->pVtab);
116766 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
116767 if( rc==SQLITE_OK ){
116768 assert( pTab->pVTable==p && p->pNext==0 );
116769 p->pVtab = 0;
116770 pTab->pVTable = 0;
@@ -116801,10 +117038,71 @@
117038 pToplevel->apVtabLock[pToplevel->nVtabLock++] = pTab;
117039 }else{
117040 pToplevel->db->mallocFailed = 1;
117041 }
117042 }
117043
117044 /*
117045 ** Check to see if virtual tale module pMod can be have an eponymous
117046 ** virtual table instance. If it can, create one if one does not already
117047 ** exist. Return non-zero if the eponymous virtual table instance exists
117048 ** when this routine returns, and return zero if it does not exist.
117049 **
117050 ** An eponymous virtual table instance is one that is named after its
117051 ** module, and more importantly, does not require a CREATE VIRTUAL TABLE
117052 ** statement in order to come into existance. Eponymous virtual table
117053 ** instances always exist. They cannot be DROP-ed.
117054 **
117055 ** Any virtual table module for which xConnect and xCreate are the same
117056 ** method can have an eponymous virtual table instance.
117057 */
117058 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse *pParse, Module *pMod){
117059 const sqlite3_module *pModule = pMod->pModule;
117060 Table *pTab;
117061 char *zErr = 0;
117062 int nName;
117063 int rc;
117064 sqlite3 *db = pParse->db;
117065 if( pMod->pEpoTab ) return 1;
117066 if( pModule->xCreate!=0 && pModule->xCreate!=pModule->xConnect ) return 0;
117067 nName = sqlite3Strlen30(pMod->zName) + 1;
117068 pTab = sqlite3DbMallocZero(db, sizeof(Table) + nName);
117069 if( pTab==0 ) return 0;
117070 pMod->pEpoTab = pTab;
117071 pTab->zName = (char*)&pTab[1];
117072 memcpy(pTab->zName, pMod->zName, nName);
117073 pTab->nRef = 1;
117074 pTab->pSchema = db->aDb[0].pSchema;
117075 pTab->tabFlags |= TF_Virtual;
117076 pTab->nModuleArg = 0;
117077 pTab->iPKey = -1;
117078 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117079 addModuleArgument(db, pTab, 0);
117080 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
117081 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
117082 if( rc ){
117083 sqlite3ErrorMsg(pParse, "%s", zErr);
117084 sqlite3DbFree(db, zErr);
117085 sqlite3VtabEponymousTableClear(db, pMod);
117086 return 0;
117087 }
117088 return 1;
117089 }
117090
117091 /*
117092 ** Erase the eponymous virtual table instance associated with
117093 ** virtual table module pMod, if it exists.
117094 */
117095 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3 *db, Module *pMod){
117096 Table *pTab = pMod->pEpoTab;
117097 if( (pTab = pMod->pEpoTab)!=0 ){
117098 sqlite3DeleteColumnNames(db, pTab);
117099 sqlite3VtabClear(db, pTab);
117100 sqlite3DbFree(db, pTab);
117101 pMod->pEpoTab = 0;
117102 }
117103 }
117104
117105 /*
117106 ** Return the ON CONFLICT resolution mode in effect for the virtual
117107 ** table update operation currently in progress.
117108 **
@@ -117172,16 +117470,18 @@
117470 */
117471 struct WhereScan {
117472 WhereClause *pOrigWC; /* Original, innermost WhereClause */
117473 WhereClause *pWC; /* WhereClause currently being scanned */
117474 char *zCollName; /* Required collating sequence, if not NULL */
117475 Expr *pIdxExpr; /* Search for this index expression */
117476 char idxaff; /* Must match this affinity, if zCollName!=NULL */
117477 unsigned char nEquiv; /* Number of entries in aEquiv[] */
117478 unsigned char iEquiv; /* Next unused slot in aEquiv[] */
117479 u32 opMask; /* Acceptable operators */
117480 int k; /* Resume scanning at this->pWC->a[this->k] */
117481 int aiCur[11]; /* Cursors in the equivalence class */
117482 i16 aiColumn[11]; /* Corresponding column number in the eq-class */
117483 };
117484
117485 /*
117486 ** An instance of the following structure holds all information about a
117487 ** WHERE clause. Mostly this is a container for one or more WhereTerms.
@@ -117361,10 +117661,11 @@
117661 SQLITE_PRIVATE void sqlite3WhereClauseClear(WhereClause*);
117662 SQLITE_PRIVATE void sqlite3WhereSplit(WhereClause*,Expr*,u8);
117663 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
117664 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
117665 SQLITE_PRIVATE void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
117666 SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(Parse*, struct SrcList_item*, WhereClause*);
117667
117668
117669
117670
117671
@@ -117437,10 +117738,20 @@
117738 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117739 sqlite3StrAccumAppendAll(pStr, zColumn);
117740 sqlite3StrAccumAppend(pStr, zOp, 1);
117741 sqlite3StrAccumAppend(pStr, "?", 1);
117742 }
117743
117744 /*
117745 ** Return the name of the i-th column of the pIdx index.
117746 */
117747 static const char *explainIndexColumnName(Index *pIdx, int i){
117748 i = pIdx->aiColumn[i];
117749 if( i==(-2) ) return "<expr>";
117750 if( i==(-1) ) return "rowid";
117751 return pIdx->pTable->aCol[i].zName;
117752 }
117753
117754 /*
117755 ** Argument pLevel describes a strategy for scanning table pTab. This
117756 ** function appends text to pStr that describes the subset of table
117757 ** rows scanned by the strategy in the form of an SQL expression.
@@ -117457,32 +117768,26 @@
117768 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117769 Index *pIndex = pLoop->u.btree.pIndex;
117770 u16 nEq = pLoop->u.btree.nEq;
117771 u16 nSkip = pLoop->nSkip;
117772 int i, j;
 
 
117773
117774 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
117775 sqlite3StrAccumAppend(pStr, " (", 2);
117776 for(i=0; i<nEq; i++){
117777 const char *z = explainIndexColumnName(pIndex, i);
117778 if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
117779 sqlite3XPrintf(pStr, 0, i>=nSkip ? "%s=?" : "ANY(%s)", z);
 
 
 
 
117780 }
117781
117782 j = i;
117783 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
117784 const char *z = explainIndexColumnName(pIndex, i);
117785 explainAppendTerm(pStr, i++, z, ">");
117786 }
117787 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
117788 const char *z = explainIndexColumnName(pIndex, j);
117789 explainAppendTerm(pStr, i, z, "<");
117790 }
117791 sqlite3StrAccumAppend(pStr, ")", 1);
117792 }
117793
@@ -117562,23 +117867,22 @@
117867 sqlite3StrAccumAppend(&str, " USING ", 7);
117868 sqlite3XPrintf(&str, 0, zFmt, pIdx->zName);
117869 explainIndexRange(&str, pLoop, pItem->pTab);
117870 }
117871 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
117872 const char *zRangeOp;
117873 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
117874 zRangeOp = "=";
117875 }else if( (flags&WHERE_BOTH_LIMIT)==WHERE_BOTH_LIMIT ){
117876 zRangeOp = ">? AND rowid<";
117877 }else if( flags&WHERE_BTM_LIMIT ){
117878 zRangeOp = ">";
117879 }else{
117880 assert( flags&WHERE_TOP_LIMIT);
117881 zRangeOp = "<";
117882 }
117883 sqlite3XPrintf(&str, 0, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
 
117884 }
117885 #ifndef SQLITE_OMIT_VIRTUALTABLE
117886 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
117887 sqlite3XPrintf(&str, 0, " VIRTUAL TABLE INDEX %d:%s",
117888 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
@@ -117889,11 +118193,11 @@
118193 */
118194 regBase = pParse->nMem + 1;
118195 nReg = pLoop->u.btree.nEq + nExtraReg;
118196 pParse->nMem += nReg;
118197
118198 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
118199 if( !zAff ){
118200 pParse->db->mallocFailed = 1;
118201 }
118202
118203 if( nSkip ){
@@ -118043,18 +118347,18 @@
118347
118348 /* If this is the right table of a LEFT OUTER JOIN, allocate and
118349 ** initialize a memory cell that records if this table matches any
118350 ** row of the left table of the join.
118351 */
118352 if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){
118353 pLevel->iLeftJoin = ++pParse->nMem;
118354 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
118355 VdbeComment((v, "init LEFT JOIN no-match flag"));
118356 }
118357
118358 /* Special case of a FROM clause subquery implemented as a co-routine */
118359 if( pTabItem->fg.viaCoroutine ){
118360 int regYield = pTabItem->regReturn;
118361 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
118362 pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
118363 VdbeCoverage(v);
118364 VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
@@ -118777,11 +119081,11 @@
119081 if( pAndExpr ){
119082 pAndExpr->pLeft = 0;
119083 sqlite3ExprDelete(db, pAndExpr);
119084 }
119085 sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
119086 sqlite3VdbeGoto(v, pLevel->addrBrk);
119087 sqlite3VdbeResolveLabel(v, iLoopBody);
119088
119089 if( pWInfo->nLevel>1 ) sqlite3StackFree(db, pOrTab);
119090 if( !untestedTerms ) disableTerm(pLevel, pTerm);
119091 }else
@@ -118792,11 +119096,11 @@
119096 ** scan of the entire table.
119097 */
119098 static const u8 aStep[] = { OP_Next, OP_Prev };
119099 static const u8 aStart[] = { OP_Rewind, OP_Last };
119100 assert( bRev==0 || bRev==1 );
119101 if( pTabItem->fg.isRecursive ){
119102 /* Tables marked isRecursive have only a single row that is stored in
119103 ** a pseudo-cursor. No need to Rewind or Next such cursors. */
119104 pLevel->op = OP_Noop;
119105 }else{
119106 pLevel->op = aStep[bRev];
@@ -119699,10 +120003,55 @@
120003 }
120004 pS = pS->pPrior;
120005 }
120006 return mask;
120007 }
120008
120009 /*
120010 ** Expression pExpr is one operand of a comparison operator that might
120011 ** be useful for indexing. This routine checks to see if pExpr appears
120012 ** in any index. Return TRUE (1) if pExpr is an indexed term and return
120013 ** FALSE (0) if not. If TRUE is returned, also set *piCur to the cursor
120014 ** number of the table that is indexed and *piColumn to the column number
120015 ** of the column that is indexed, or -2 if an expression is being indexed.
120016 **
120017 ** If pExpr is a TK_COLUMN column reference, then this routine always returns
120018 ** true even if that particular column is not indexed, because the column
120019 ** might be added to an automatic index later.
120020 */
120021 static int exprMightBeIndexed(
120022 SrcList *pFrom, /* The FROM clause */
120023 Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
120024 Expr *pExpr, /* An operand of a comparison operator */
120025 int *piCur, /* Write the referenced table cursor number here */
120026 int *piColumn /* Write the referenced table column number here */
120027 ){
120028 Index *pIdx;
120029 int i;
120030 int iCur;
120031 if( pExpr->op==TK_COLUMN ){
120032 *piCur = pExpr->iTable;
120033 *piColumn = pExpr->iColumn;
120034 return 1;
120035 }
120036 if( mPrereq==0 ) return 0; /* No table references */
120037 if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
120038 for(i=0; mPrereq>1; i++, mPrereq>>=1){}
120039 iCur = pFrom->a[i].iCursor;
120040 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120041 if( pIdx->aColExpr==0 ) continue;
120042 for(i=0; i<pIdx->nKeyCol; i++){
120043 if( pIdx->aiColumn[i]!=(-2) ) continue;
120044 if( sqlite3ExprCompare(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
120045 *piCur = iCur;
120046 *piColumn = -2;
120047 return 1;
120048 }
120049 }
120050 }
120051 return 0;
120052 }
120053
120054 /*
120055 ** The input to this routine is an WhereTerm structure with only the
120056 ** "pExpr" field filled in. The job of this routine is to analyze the
120057 ** subexpression and populate all the other fields of the WhereTerm
@@ -119770,20 +120119,23 @@
120119 pTerm->prereqAll = prereqAll;
120120 pTerm->leftCursor = -1;
120121 pTerm->iParent = -1;
120122 pTerm->eOperator = 0;
120123 if( allowedOp(op) ){
120124 int iCur, iColumn;
120125 Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
120126 Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
120127 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
120128 if( exprMightBeIndexed(pSrc, prereqLeft, pLeft, &iCur, &iColumn) ){
120129 pTerm->leftCursor = iCur;
120130 pTerm->u.leftColumn = iColumn;
120131 pTerm->eOperator = operatorMask(op) & opMask;
120132 }
120133 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
120134 if( pRight
120135 && exprMightBeIndexed(pSrc, pTerm->prereqRight, pRight, &iCur, &iColumn)
120136 ){
120137 WhereTerm *pNew;
120138 Expr *pDup;
120139 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
120140 if( pTerm->leftCursor>=0 ){
120141 int idxNew;
@@ -119808,12 +120160,12 @@
120160 pDup = pExpr;
120161 pNew = pTerm;
120162 }
120163 exprCommute(pParse, pDup);
120164 pLeft = sqlite3ExprSkipCollate(pDup->pLeft);
120165 pNew->leftCursor = iCur;
120166 pNew->u.leftColumn = iColumn;
120167 testcase( (prereqLeft | extraRight) != prereqLeft );
120168 pNew->prereqRight = prereqLeft | extraRight;
120169 pNew->prereqAll = prereqAll;
120170 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
120171 }
@@ -120152,10 +120504,50 @@
120504 int i;
120505 for(i=pWC->nTerm-1; i>=0; i--){
120506 exprAnalyze(pTabList, pWC, i);
120507 }
120508 }
120509
120510 /*
120511 ** For table-valued-functions, transform the function arguments into
120512 ** new WHERE clause terms.
120513 **
120514 ** Each function argument translates into an equality constraint against
120515 ** a HIDDEN column in the table.
120516 */
120517 SQLITE_PRIVATE void sqlite3WhereTabFuncArgs(
120518 Parse *pParse, /* Parsing context */
120519 struct SrcList_item *pItem, /* The FROM clause term to process */
120520 WhereClause *pWC /* Xfer function arguments to here */
120521 ){
120522 Table *pTab;
120523 int j, k;
120524 ExprList *pArgs;
120525 Expr *pColRef;
120526 Expr *pTerm;
120527 if( pItem->fg.isTabFunc==0 ) return;
120528 pTab = pItem->pTab;
120529 assert( pTab!=0 );
120530 pArgs = pItem->u1.pFuncArg;
120531 assert( pArgs!=0 );
120532 for(j=k=0; j<pArgs->nExpr; j++){
120533 while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){ k++; }
120534 if( k>=pTab->nCol ){
120535 sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d",
120536 pTab->zName, j);
120537 return;
120538 }
120539 pColRef = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
120540 if( pColRef==0 ) return;
120541 pColRef->iTable = pItem->iCursor;
120542 pColRef->iColumn = k++;
120543 pColRef->pTab = pTab;
120544 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
120545 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
120546 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
120547 }
120548 }
120549
120550 /************** End of whereexpr.c *******************************************/
120551 /************** Begin file where.c *******************************************/
120552 /*
120553 ** 2001 September 15
@@ -120328,41 +120720,44 @@
120720 ** established when the pScan object was initialized by whereScanInit().
120721 ** Return NULL if there are no more matching WhereTerms.
120722 */
120723 static WhereTerm *whereScanNext(WhereScan *pScan){
120724 int iCur; /* The cursor on the LHS of the term */
120725 i16 iColumn; /* The column on the LHS of the term. -1 for IPK */
120726 Expr *pX; /* An expression being tested */
120727 WhereClause *pWC; /* Shorthand for pScan->pWC */
120728 WhereTerm *pTerm; /* The term being tested */
120729 int k = pScan->k; /* Where to start scanning */
120730
120731 while( pScan->iEquiv<=pScan->nEquiv ){
120732 iCur = pScan->aiCur[pScan->iEquiv-1];
120733 iColumn = pScan->aiColumn[pScan->iEquiv-1];
120734 assert( iColumn!=(-2) || pScan->pIdxExpr!=0 );
120735 while( (pWC = pScan->pWC)!=0 ){
120736 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
120737 if( pTerm->leftCursor==iCur
120738 && pTerm->u.leftColumn==iColumn
120739 && (iColumn!=(-2)
120740 || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0)
120741 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
120742 ){
120743 if( (pTerm->eOperator & WO_EQUIV)!=0
120744 && pScan->nEquiv<ArraySize(pScan->aiCur)
120745 ){
120746 int j;
120747 pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
120748 assert( pX->op==TK_COLUMN );
120749 for(j=0; j<pScan->nEquiv; j++){
120750 if( pScan->aiCur[j]==pX->iTable
120751 && pScan->aiColumn[j]==pX->iColumn ){
120752 break;
120753 }
120754 }
120755 if( j==pScan->nEquiv ){
120756 pScan->aiCur[j] = pX->iTable;
120757 pScan->aiColumn[j] = pX->iColumn;
120758 pScan->nEquiv++;
120759 }
120760 }
120761 if( (pTerm->eOperator & pScan->opMask)!=0 ){
120762 /* Verify the affinity and collating sequence match */
120763 if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
@@ -120380,12 +120775,12 @@
120775 continue;
120776 }
120777 }
120778 if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
120779 && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
120780 && pX->iTable==pScan->aiCur[0]
120781 && pX->iColumn==pScan->aiColumn[0]
120782 ){
120783 testcase( pTerm->eOperator & WO_IS );
120784 continue;
120785 }
120786 pScan->k = k+1;
@@ -120396,11 +120791,11 @@
120791 pScan->pWC = pScan->pWC->pOuter;
120792 k = 0;
120793 }
120794 pScan->pWC = pScan->pOrigWC;
120795 k = 0;
120796 pScan->iEquiv++;
120797 }
120798 return 0;
120799 }
120800
120801 /*
@@ -120425,49 +120820,53 @@
120820 int iCur, /* Cursor to scan for */
120821 int iColumn, /* Column to scan for */
120822 u32 opMask, /* Operator(s) to scan for */
120823 Index *pIdx /* Must be compatible with this index */
120824 ){
120825 int j = 0;
120826
120827 /* memset(pScan, 0, sizeof(*pScan)); */
120828 pScan->pOrigWC = pWC;
120829 pScan->pWC = pWC;
120830 pScan->pIdxExpr = 0;
120831 if( pIdx ){
120832 j = iColumn;
120833 iColumn = pIdx->aiColumn[j];
120834 if( iColumn==(-2) ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
120835 }
120836 if( pIdx && iColumn>=0 ){
120837 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
 
 
 
120838 pScan->zCollName = pIdx->azColl[j];
120839 }else{
120840 pScan->idxaff = 0;
120841 pScan->zCollName = 0;
120842 }
120843 pScan->opMask = opMask;
120844 pScan->k = 0;
120845 pScan->aiCur[0] = iCur;
120846 pScan->aiColumn[0] = iColumn;
120847 pScan->nEquiv = 1;
120848 pScan->iEquiv = 1;
120849 return whereScanNext(pScan);
120850 }
120851
120852 /*
120853 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
120854 ** where X is a reference to the iColumn of table iCur and <op> is one of
120855 ** the WO_xx operator codes specified by the op parameter.
120856 ** Return a pointer to the term. Return 0 if not found.
120857 **
120858 ** If pIdx!=0 then search for terms matching the iColumn-th column of pIdx
120859 ** rather than the iColumn-th column of table iCur.
120860 **
120861 ** The term returned might by Y=<expr> if there is another constraint in
120862 ** the WHERE clause that specifies that X=Y. Any such constraints will be
120863 ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
120864 ** aiCur[]/iaColumn[] arrays hold X and all its equivalents. There are 11
120865 ** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10
120866 ** other equivalent values. Hence a search for X will return <expr> if X=A1
120867 ** and A1=A2 and A2=A3 and ... and A9=A10 and A10=<expr>.
 
 
120868 **
120869 ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
120870 ** then try for the one with no dependencies on <expr> - in other words where
120871 ** <expr> is a constant expression of some kind. Only return entries of
120872 ** the form "X <op> Y" where Y is a column in another table if no terms of
@@ -120531,10 +120930,29 @@
120930 }
120931 }
120932
120933 return -1;
120934 }
120935
120936 /*
120937 ** Return TRUE if the iCol-th column of index pIdx is NOT NULL
120938 */
120939 static int indexColumnNotNull(Index *pIdx, int iCol){
120940 int j;
120941 assert( pIdx!=0 );
120942 assert( iCol>=0 && iCol<pIdx->nColumn );
120943 j = pIdx->aiColumn[iCol];
120944 if( j>=0 ){
120945 return pIdx->pTable->aCol[j].notNull;
120946 }else if( j==(-1) ){
120947 return 1;
120948 }else{
120949 assert( j==(-2) );
120950 return 0; /* Assume an indexed expression can always yield a NULL */
120951
120952 }
120953 }
120954
120955 /*
120956 ** Return true if the DISTINCT expression-list passed as the third argument
120957 ** is redundant.
120958 **
@@ -120582,16 +121000,13 @@
121000 ** contain a "col=X" term are subject to a NOT NULL constraint.
121001 */
121002 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
121003 if( !IsUniqueIndex(pIdx) ) continue;
121004 for(i=0; i<pIdx->nKeyCol; i++){
121005 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
121006 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
121007 if( indexColumnNotNull(pIdx, i)==0 ) break;
 
 
 
121008 }
121009 }
121010 if( i==pIdx->nKeyCol ){
121011 /* This index implies that the DISTINCT qualifier is redundant. */
121012 return 1;
@@ -120866,11 +121281,11 @@
121281 VdbeComment((v, "for %s", pTable->zName));
121282
121283 /* Fill the automatic index with content */
121284 sqlite3ExprCachePush(pParse);
121285 pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];
121286 if( pTabItem->fg.viaCoroutine ){
121287 int regYield = pTabItem->regReturn;
121288 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
121289 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
121290 VdbeCoverage(v);
121291 VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
@@ -120885,14 +121300,14 @@
121300 regRecord = sqlite3GetTempReg(pParse);
121301 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
121302 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
121303 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
121304 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
121305 if( pTabItem->fg.viaCoroutine ){
121306 translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult);
121307 sqlite3VdbeGoto(v, addrTop);
121308 pTabItem->fg.viaCoroutine = 0;
121309 }else{
121310 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
121311 }
121312 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
121313 sqlite3VdbeJumpHere(v, addrTop);
@@ -120939,10 +121354,11 @@
121354 testcase( pTerm->eOperator & WO_ISNULL );
121355 testcase( pTerm->eOperator & WO_IS );
121356 testcase( pTerm->eOperator & WO_ALL );
121357 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
121358 if( pTerm->wtFlags & TERM_VNULL ) continue;
121359 assert( pTerm->u.leftColumn>=(-1) );
121360 nTerm++;
121361 }
121362
121363 /* If the ORDER BY clause contains only columns in the current
121364 ** virtual table then allocate space for the aOrderBy part of
@@ -120994,10 +121410,11 @@
121410 testcase( pTerm->eOperator & WO_IS );
121411 testcase( pTerm->eOperator & WO_ISNULL );
121412 testcase( pTerm->eOperator & WO_ALL );
121413 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
121414 if( pTerm->wtFlags & TERM_VNULL ) continue;
121415 assert( pTerm->u.leftColumn>=(-1) );
121416 pIdxCons[j].iColumn = pTerm->u.leftColumn;
121417 pIdxCons[j].iTermOffset = i;
121418 op = (u8)pTerm->eOperator & WO_ALL;
121419 if( op==WO_IN ) op = WO_EQ;
121420 pIdxCons[j].op = op;
@@ -121283,10 +121700,24 @@
121700 nRet -= 20; assert( 20==sqlite3LogEst(4) );
121701 }
121702 }
121703 return nRet;
121704 }
121705
121706
121707 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
121708 /*
121709 ** Return the affinity for a single column of an index.
121710 */
121711 static char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){
121712 if( !pIdx->zColAff ){
121713 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
121714 }
121715 return pIdx->zColAff[iCol];
121716 }
121717 #endif
121718
121719
121720 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
121721 /*
121722 ** This function is called to estimate the number of rows visited by a
121723 ** range-scan on a skip-scan index. For example:
@@ -121334,11 +121765,11 @@
121765 sqlite3 *db = pParse->db;
121766 int nLower = -1;
121767 int nUpper = p->nSample+1;
121768 int rc = SQLITE_OK;
121769 int iCol = p->aiColumn[nEq];
121770 u8 aff = sqlite3IndexColumnAffinity(db, p, iCol);
121771 CollSeq *pColl;
121772
121773 sqlite3_value *p1 = 0; /* Value extracted from pLower */
121774 sqlite3_value *p2 = 0; /* Value extracted from pUpper */
121775 sqlite3_value *pVal = 0; /* Value extracted from record */
@@ -121482,15 +121913,12 @@
121913
121914 if( pRec ){
121915 testcase( pRec->nField!=pBuilder->nRecValid );
121916 pRec->nField = pBuilder->nRecValid;
121917 }
121918 aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq);
121919 assert( nEq!=p->nKeyCol || aff==SQLITE_AFF_INTEGER );
 
 
 
121920 /* Determine iLower and iUpper using ($P) only. */
121921 if( nEq==0 ){
121922 iLower = 0;
121923 iUpper = p->nRowEst0;
121924 }else{
@@ -121644,11 +122072,11 @@
122072 if( nEq>=p->nColumn ){
122073 *pnRow = 1;
122074 return SQLITE_OK;
122075 }
122076
122077 aff = sqlite3IndexColumnAffinity(pParse->db, p, nEq-1);
122078 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq-1, &bOk);
122079 pBuilder->pRec = pRec;
122080 if( rc!=SQLITE_OK ) return rc;
122081 if( bOk==0 ) return SQLITE_NOTFOUND;
122082 pBuilder->nRecValid = nEq;
@@ -122071,22 +122499,24 @@
122499
122500 /* If pBuilder->pOrSet is defined, then only keep track of the costs
122501 ** and prereqs.
122502 */
122503 if( pBuilder->pOrSet!=0 ){
122504 if( pTemplate->nLTerm ){
122505 #if WHERETRACE_ENABLED
122506 u16 n = pBuilder->pOrSet->n;
122507 int x =
122508 #endif
122509 whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun,
122510 pTemplate->nOut);
122511 #if WHERETRACE_ENABLED /* 0x8 */
122512 if( sqlite3WhereTrace & 0x8 ){
122513 sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n);
122514 whereLoopPrint(pTemplate, pBuilder->pWC);
122515 }
122516 #endif
122517 }
 
122518 return SQLITE_OK;
122519 }
122520
122521 /* Look for an existing WhereLoop to replace with pTemplate
122522 */
@@ -122272,11 +122702,10 @@
122702 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
122703 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
122704 u16 saved_nSkip; /* Original value of pNew->nSkip */
122705 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
122706 LogEst saved_nOut; /* Original value of pNew->nOut */
 
122707 int rc = SQLITE_OK; /* Return code */
122708 LogEst rSize; /* Number of rows in the table */
122709 LogEst rLogSize; /* Logarithm of table size */
122710 WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
122711
@@ -122285,28 +122714,27 @@
122714
122715 assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
122716 assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
122717 if( pNew->wsFlags & WHERE_BTM_LIMIT ){
122718 opMask = WO_LT|WO_LE;
122719 }else if( /*pProbe->tnum<=0 ||*/ (pSrc->fg.jointype & JT_LEFT)!=0 ){
122720 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE;
122721 }else{
122722 opMask = WO_EQ|WO_IN|WO_GT|WO_GE|WO_LT|WO_LE|WO_ISNULL|WO_IS;
122723 }
122724 if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE);
122725
122726 assert( pNew->u.btree.nEq<pProbe->nColumn );
 
122727
 
 
122728 saved_nEq = pNew->u.btree.nEq;
122729 saved_nSkip = pNew->nSkip;
122730 saved_nLTerm = pNew->nLTerm;
122731 saved_wsFlags = pNew->wsFlags;
122732 saved_prereq = pNew->prereq;
122733 saved_nOut = pNew->nOut;
122734 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, saved_nEq,
122735 opMask, pProbe);
122736 pNew->rSetup = 0;
122737 rSize = pProbe->aiRowLogEst[0];
122738 rLogSize = estLog(rSize);
122739 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
122740 u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
@@ -122315,11 +122743,11 @@
122743 int nIn = 0;
122744 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
122745 int nRecValid = pBuilder->nRecValid;
122746 #endif
122747 if( (eOp==WO_ISNULL || (pTerm->wtFlags&TERM_VNULL)!=0)
122748 && indexColumnNotNull(pProbe, saved_nEq)
122749 ){
122750 continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
122751 }
122752 if( pTerm->prereqRight & pNew->maskSelf ) continue;
122753
@@ -122352,12 +122780,14 @@
122780 }
122781 assert( nIn>0 ); /* RHS always has 2 or more terms... The parser
122782 ** changes "x IN (?)" into "x=?". */
122783
122784 }else if( eOp & (WO_EQ|WO_IS) ){
122785 int iCol = pProbe->aiColumn[saved_nEq];
122786 pNew->wsFlags |= WHERE_COLUMN_EQ;
122787 assert( saved_nEq==pNew->u.btree.nEq );
122788 if( iCol==(-1) || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) ){
122789 if( iCol>=0 && pProbe->uniqNotNull==0 ){
122790 pNew->wsFlags |= WHERE_UNQ_WANTED;
122791 }else{
122792 pNew->wsFlags |= WHERE_ONEROW;
122793 }
@@ -122404,11 +122834,11 @@
122834 }else{
122835 int nEq = ++pNew->u.btree.nEq;
122836 assert( eOp & (WO_ISNULL|WO_EQ|WO_IN|WO_IS) );
122837
122838 assert( pNew->nOut==saved_nOut );
122839 if( pTerm->truthProb<=0 && pProbe->aiColumn[saved_nEq]>=0 ){
122840 assert( (eOp & WO_IN) || nIn==0 );
122841 testcase( eOp & WO_IN );
122842 pNew->nOut += pTerm->truthProb;
122843 pNew->nOut -= nIn;
122844 }else{
@@ -122580,10 +123010,14 @@
123010 ** in the current query. Return true if it can be and false if not.
123011 */
123012 static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
123013 int i;
123014 WhereTerm *pTerm;
123015 while( pWhere->op==TK_AND ){
123016 if( !whereUsablePartialIndex(iTab,pWC,pWhere->pLeft) ) return 0;
123017 pWhere = pWhere->pRight;
123018 }
123019 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
123020 Expr *pExpr = pTerm->pExpr;
123021 if( sqlite3ExprImpliesExpr(pExpr, pWhere, iTab)
123022 && (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
123023 ){
@@ -122655,13 +123089,13 @@
123089 pSrc = pTabList->a + pNew->iTab;
123090 pTab = pSrc->pTab;
123091 pWC = pBuilder->pWC;
123092 assert( !IsVirtual(pSrc->pTab) );
123093
123094 if( pSrc->pIBIndex ){
123095 /* An INDEXED BY clause specifies a particular index to use */
123096 pProbe = pSrc->pIBIndex;
123097 }else if( !HasRowid(pTab) ){
123098 pProbe = pTab->pIndex;
123099 }else{
123100 /* There is no INDEXED BY clause. Create a fake Index object in local
123101 ** variable sPk to represent the rowid primary key index. Make this
@@ -122677,11 +123111,11 @@
123111 sPk.pTable = pTab;
123112 sPk.szIdxRow = pTab->szTabRow;
123113 aiRowEstPk[0] = pTab->nRowLogEst;
123114 aiRowEstPk[1] = 0;
123115 pFirst = pSrc->pTab->pIndex;
123116 if( pSrc->fg.notIndexed==0 ){
123117 /* The real indices of the table are only considered if the
123118 ** NOT INDEXED qualifier is omitted from the FROM clause */
123119 sPk.pNext = pFirst;
123120 }
123121 pProbe = &sPk;
@@ -122689,18 +123123,18 @@
123123 rSize = pTab->nRowLogEst;
123124 rLogSize = estLog(rSize);
123125
123126 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
123127 /* Automatic indexes */
123128 if( !pBuilder->pOrSet /* Not part of an OR optimization */
123129 && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
123130 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
123131 && pSrc->pIBIndex==0 /* Has no INDEXED BY clause */
123132 && !pSrc->fg.notIndexed /* Has no NOT INDEXED clause */
123133 && HasRowid(pTab) /* Is not a WITHOUT ROWID table. (FIXME: Why not?) */
123134 && !pSrc->fg.isCorrelated /* Not a correlated subquery */
123135 && !pSrc->fg.isRecursive /* Not a recursive common table expression. */
123136 ){
123137 /* Generate auto-index WhereLoops */
123138 WhereTerm *pTerm;
123139 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
123140 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
@@ -122817,11 +123251,11 @@
123251 pBuilder->pRec = 0;
123252 #endif
123253
123254 /* If there was an INDEXED BY clause, then only that one index is
123255 ** considered. */
123256 if( pSrc->pIBIndex ) break;
123257 }
123258 return rc;
123259 }
123260
123261 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -123163,20 +123597,20 @@
123597 whereLoopInit(pNew);
123598 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
123599 Bitmask mUnusable = 0;
123600 pNew->iTab = iTab;
123601 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
123602 if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
123603 /* This condition is true when pItem is the FROM clause term on the
123604 ** right-hand-side of a LEFT or CROSS JOIN. */
123605 mExtra = mPrior;
123606 }
123607 priorJointype = pItem->fg.jointype;
123608 if( IsVirtual(pItem->pTab) ){
123609 struct SrcList_item *p;
123610 for(p=&pItem[1]; p<pEnd; p++){
123611 if( mUnusable || (p->fg.jointype & (JT_LEFT|JT_CROSS)) ){
123612 mUnusable |= sqlite3WhereGetMask(&pWInfo->sMaskSet, p->iCursor);
123613 }
123614 }
123615 rc = whereLoopAddVirtual(pBuilder, mExtra, mUnusable);
123616 }else{
@@ -123902,11 +124336,11 @@
124336 if( pWInfo->wctrlFlags & WHERE_FORCE_TABLE ) return 0;
124337 assert( pWInfo->pTabList->nSrc>=1 );
124338 pItem = pWInfo->pTabList->a;
124339 pTab = pItem->pTab;
124340 if( IsVirtual(pTab) ) return 0;
124341 if( pItem->fg.isIndexedBy ) return 0;
124342 iCur = pItem->iCursor;
124343 pWC = &pWInfo->sWC;
124344 pLoop = pBuilder->pNew;
124345 pLoop->wsFlags = 0;
124346 pLoop->nSkip = 0;
@@ -123927,11 +124361,11 @@
124361 || pIdx->pPartIdxWhere!=0
124362 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
124363 ) continue;
124364 opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ;
124365 for(j=0; j<pIdx->nKeyCol; j++){
124366 pTerm = sqlite3WhereFindTerm(pWC, iCur, j, 0, opMask, pIdx);
124367 if( pTerm==0 ) break;
124368 testcase( pTerm->eOperator & WO_IS );
124369 pLoop->aLTerm[j] = pTerm;
124370 }
124371 if( j!=pIdx->nKeyCol ) continue;
@@ -124167,35 +124601,30 @@
124601 }
124602 }
124603
124604 /* Assign a bit from the bitmask to every term in the FROM clause.
124605 **
124606 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
124607 **
124608 ** The rule of the previous sentence ensures thta if X is the bitmask for
124609 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
124610 ** Knowing the bitmask for all tables to the left of a left join is
124611 ** important. Ticket #3015.
 
 
124612 **
124613 ** Note that bitmasks are created for all pTabList->nSrc tables in
124614 ** pTabList, not just the first nTabList tables. nTabList is normally
124615 ** equal to pTabList->nSrc but might be shortened to 1 if the
124616 ** WHERE_ONETABLE_ONLY flag is set.
124617 */
124618 for(ii=0; ii<pTabList->nSrc; ii++){
124619 createMask(pMaskSet, pTabList->a[ii].iCursor);
124620 sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
124621 }
124622 #ifdef SQLITE_DEBUG
124623 for(ii=0; ii<pTabList->nSrc; ii++){
124624 Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
124625 assert( m==MASKBIT(ii) );
 
 
 
124626 }
124627 #endif
124628
124629 /* Analyze all of the subexpressions. */
124630 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
@@ -124289,11 +124718,11 @@
124718 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
124719 }
124720 while( pWInfo->nLevel>=2 ){
124721 WhereTerm *pTerm, *pEnd;
124722 pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
124723 if( (pWInfo->pTabList->a[pLoop->iTab].fg.jointype & JT_LEFT)==0 ) break;
124724 if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
124725 && (pLoop->wsFlags & WHERE_ONEROW)==0
124726 ){
124727 break;
124728 }
@@ -124527,11 +124956,11 @@
124956 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
124957 }
124958 }
124959 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
124960 if( pLevel->addrSkip ){
124961 sqlite3VdbeGoto(v, pLevel->addrSkip);
124962 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
124963 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
124964 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
124965 }
124966 if( pLevel->addrLikeRep ){
@@ -124555,11 +124984,11 @@
124984 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
124985 }
124986 if( pLevel->op==OP_Return ){
124987 sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst);
124988 }else{
124989 sqlite3VdbeGoto(v, pLevel->addrFirst);
124990 }
124991 sqlite3VdbeJumpHere(v, addr);
124992 }
124993 VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
124994 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
@@ -124582,11 +125011,11 @@
125011
125012 /* For a co-routine, change all OP_Column references to the table of
125013 ** the co-routine into OP_Copy of result contained in a register.
125014 ** OP_Rowid becomes OP_Null.
125015 */
125016 if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
125017 translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
125018 pTabItem->regResult);
125019 continue;
125020 }
125021
@@ -124816,10 +125245,33 @@
125245 ){
125246 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
125247 pOut->zStart = pPreOp->z;
125248 pOut->zEnd = pOperand->zEnd;
125249 }
125250
125251 /* Add a single new term to an ExprList that is used to store a
125252 ** list of identifiers. Report an error if the ID list contains
125253 ** a COLLATE clause or an ASC or DESC keyword, except ignore the
125254 ** error while parsing a legacy schema.
125255 */
125256 static ExprList *parserAddExprIdListTerm(
125257 Parse *pParse,
125258 ExprList *pPrior,
125259 Token *pIdToken,
125260 int hasCollate,
125261 int sortOrder
125262 ){
125263 ExprList *p = sqlite3ExprListAppend(pParse, pPrior, 0);
125264 if( (hasCollate || sortOrder!=SQLITE_SO_UNDEFINED)
125265 && pParse->db->init.busy==0
125266 ){
125267 sqlite3ErrorMsg(pParse, "syntax error after column name \"%.*s\"",
125268 pIdToken->n, pIdToken->z);
125269 }
125270 sqlite3ExprListSetName(pParse, p, pIdToken, 1);
125271 return p;
125272 }
125273 /* Next is all token values, in a form suitable for use by makeheaders.
125274 ** This section will be null unless lemon is run with the -m switch.
125275 */
125276 /*
125277 ** These constants (all generated automatically by the parser generator)
@@ -124860,14 +125312,21 @@
125312 ** zero the stack is dynamically sized using realloc()
125313 ** sqlite3ParserARG_SDECL A static variable declaration for the %extra_argument
125314 ** sqlite3ParserARG_PDECL A parameter declaration for the %extra_argument
125315 ** sqlite3ParserARG_STORE Code to store %extra_argument into yypParser
125316 ** sqlite3ParserARG_FETCH Code to extract %extra_argument from yypParser
125317 ** YYERRORSYMBOL is the code number of the error symbol. If not
125318 ** defined, then do no error processing.
125319 ** YYNSTATE the combined number of states.
125320 ** YYNRULE the number of rules in the grammar
125321 ** YY_MAX_SHIFT Maximum value for shift actions
125322 ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
125323 ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
125324 ** YY_MIN_REDUCE Maximum value for reduce actions
125325 ** YY_ERROR_ACTION The yy_action[] code for syntax error
125326 ** YY_ACCEPT_ACTION The yy_action[] code for accept
125327 ** YY_NO_ACTION The yy_action[] code for no-op
125328 */
125329 #define YYCODETYPE unsigned char
125330 #define YYNOCODE 254
125331 #define YYACTIONTYPE unsigned short int
125332 #define YYWILDCARD 70
@@ -124896,16 +125355,21 @@
125355 #endif
125356 #define sqlite3ParserARG_SDECL Parse *pParse;
125357 #define sqlite3ParserARG_PDECL ,Parse *pParse
125358 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
125359 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
 
 
125360 #define YYFALLBACK 1
125361 #define YYNSTATE 436
125362 #define YYNRULE 328
125363 #define YY_MAX_SHIFT 435
125364 #define YY_MIN_SHIFTREDUCE 649
125365 #define YY_MAX_SHIFTREDUCE 976
125366 #define YY_MIN_REDUCE 977
125367 #define YY_MAX_REDUCE 1304
125368 #define YY_ERROR_ACTION 1305
125369 #define YY_ACCEPT_ACTION 1306
125370 #define YY_NO_ACTION 1307
125371
125372 /* The yyzerominor constant is used to initialize instances of
125373 ** YYMINORTYPE objects to zero. */
125374 static const YYMINORTYPE yyzerominor = { 0 };
125375
@@ -124928,20 +125392,24 @@
125392 ** action integer.
125393 **
125394 ** Suppose the action integer is N. Then the action is determined as
125395 ** follows
125396 **
125397 ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
125398 ** token onto the stack and goto state N.
125399 **
125400 ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
125401 ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
125402 **
125403 ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
125404 ** and YY_MAX_REDUCE
125405
125406 ** N == YY_ERROR_ACTION A syntax error has occurred.
125407 **
125408 ** N == YY_ACCEPT_ACTION The parser accepts its input.
125409 **
125410 ** N == YY_NO_ACTION No such action. Denotes unused
125411 ** slots in the yy_action[] table.
125412 **
125413 ** The action table is constructed as a single large table named yy_action[].
125414 ** Given state S and lookahead X, the action is computed as
125415 **
@@ -124967,467 +125435,450 @@
125435 ** shifting terminals.
125436 ** yy_reduce_ofst[] For each state, the offset into yy_action for
125437 ** shifting non-terminals after a reduce.
125438 ** yy_default[] Default action for each state.
125439 */
125440 #define YY_ACTTAB_COUNT (1501)
125441 static const YYACTIONTYPE yy_action[] = {
125442 /* 0 */ 311, 1306, 145, 651, 2, 192, 652, 338, 780, 92,
125443 /* 10 */ 92, 92, 92, 85, 90, 90, 90, 90, 89, 89,
125444 /* 20 */ 88, 88, 88, 87, 335, 88, 88, 88, 87, 335,
125445 /* 30 */ 327, 856, 856, 92, 92, 92, 92, 776, 90, 90,
125446 /* 40 */ 90, 90, 89, 89, 88, 88, 88, 87, 335, 86,
125447 /* 50 */ 83, 166, 93, 94, 84, 868, 871, 860, 860, 91,
125448 /* 60 */ 91, 92, 92, 92, 92, 335, 90, 90, 90, 90,
125449 /* 70 */ 89, 89, 88, 88, 88, 87, 335, 311, 780, 90,
125450 /* 80 */ 90, 90, 90, 89, 89, 88, 88, 88, 87, 335,
125451 /* 90 */ 123, 808, 689, 689, 689, 689, 112, 230, 430, 257,
125452 /* 100 */ 809, 698, 430, 86, 83, 166, 324, 55, 856, 856,
125453 /* 110 */ 201, 158, 276, 387, 271, 386, 188, 689, 689, 828,
125454 /* 120 */ 833, 49, 944, 269, 833, 49, 123, 87, 335, 93,
125455 /* 130 */ 94, 84, 868, 871, 860, 860, 91, 91, 92, 92,
125456 /* 140 */ 92, 92, 342, 90, 90, 90, 90, 89, 89, 88,
125457 /* 150 */ 88, 88, 87, 335, 311, 328, 333, 332, 701, 408,
125458 /* 160 */ 394, 69, 690, 691, 690, 691, 715, 910, 251, 354,
125459 /* 170 */ 250, 698, 704, 430, 908, 430, 909, 89, 89, 88,
125460 /* 180 */ 88, 88, 87, 335, 391, 856, 856, 690, 691, 183,
125461 /* 190 */ 95, 340, 384, 381, 380, 833, 31, 833, 49, 912,
125462 /* 200 */ 912, 333, 332, 379, 123, 311, 93, 94, 84, 868,
125463 /* 210 */ 871, 860, 860, 91, 91, 92, 92, 92, 92, 114,
125464 /* 220 */ 90, 90, 90, 90, 89, 89, 88, 88, 88, 87,
125465 /* 230 */ 335, 430, 408, 399, 435, 657, 856, 856, 346, 57,
125466 /* 240 */ 232, 828, 109, 20, 912, 912, 231, 393, 937, 760,
125467 /* 250 */ 97, 751, 752, 833, 49, 708, 708, 93, 94, 84,
125468 /* 260 */ 868, 871, 860, 860, 91, 91, 92, 92, 92, 92,
125469 /* 270 */ 707, 90, 90, 90, 90, 89, 89, 88, 88, 88,
125470 /* 280 */ 87, 335, 311, 114, 22, 706, 688, 58, 408, 390,
125471 /* 290 */ 251, 349, 240, 749, 752, 689, 689, 847, 685, 115,
125472 /* 300 */ 21, 231, 393, 689, 689, 697, 183, 355, 430, 384,
125473 /* 310 */ 381, 380, 192, 856, 856, 780, 123, 160, 159, 223,
125474 /* 320 */ 379, 738, 25, 315, 362, 841, 143, 689, 689, 835,
125475 /* 330 */ 833, 48, 339, 937, 93, 94, 84, 868, 871, 860,
125476 /* 340 */ 860, 91, 91, 92, 92, 92, 92, 914, 90, 90,
125477 /* 350 */ 90, 90, 89, 89, 88, 88, 88, 87, 335, 311,
125478 /* 360 */ 840, 840, 840, 266, 430, 690, 691, 778, 114, 1300,
125479 /* 370 */ 1300, 430, 1, 690, 691, 697, 688, 689, 689, 689,
125480 /* 380 */ 689, 689, 689, 287, 298, 780, 833, 10, 686, 115,
125481 /* 390 */ 856, 856, 355, 833, 10, 828, 366, 690, 691, 363,
125482 /* 400 */ 321, 76, 123, 74, 23, 737, 807, 323, 356, 353,
125483 /* 410 */ 847, 93, 94, 84, 868, 871, 860, 860, 91, 91,
125484 /* 420 */ 92, 92, 92, 92, 940, 90, 90, 90, 90, 89,
125485 /* 430 */ 89, 88, 88, 88, 87, 335, 311, 806, 841, 429,
125486 /* 440 */ 713, 941, 835, 430, 251, 354, 250, 690, 691, 690,
125487 /* 450 */ 691, 690, 691, 86, 83, 166, 24, 942, 151, 753,
125488 /* 460 */ 285, 907, 403, 907, 164, 833, 10, 856, 856, 965,
125489 /* 470 */ 306, 754, 679, 840, 840, 840, 795, 216, 794, 222,
125490 /* 480 */ 906, 344, 906, 904, 86, 83, 166, 286, 93, 94,
125491 /* 490 */ 84, 868, 871, 860, 860, 91, 91, 92, 92, 92,
125492 /* 500 */ 92, 430, 90, 90, 90, 90, 89, 89, 88, 88,
125493 /* 510 */ 88, 87, 335, 311, 430, 724, 352, 705, 427, 699,
125494 /* 520 */ 700, 376, 210, 833, 49, 793, 397, 857, 857, 940,
125495 /* 530 */ 213, 762, 727, 334, 699, 700, 833, 10, 86, 83,
125496 /* 540 */ 166, 345, 396, 902, 856, 856, 941, 385, 833, 9,
125497 /* 550 */ 406, 869, 872, 187, 890, 728, 347, 398, 404, 977,
125498 /* 560 */ 652, 338, 942, 954, 413, 93, 94, 84, 868, 871,
125499 /* 570 */ 860, 860, 91, 91, 92, 92, 92, 92, 861, 90,
125500 /* 580 */ 90, 90, 90, 89, 89, 88, 88, 88, 87, 335,
125501 /* 590 */ 311, 1219, 114, 430, 834, 430, 5, 165, 192, 688,
125502 /* 600 */ 832, 780, 430, 723, 430, 234, 325, 189, 163, 316,
125503 /* 610 */ 356, 955, 115, 235, 269, 833, 35, 833, 36, 747,
125504 /* 620 */ 720, 856, 856, 793, 833, 12, 833, 27, 745, 174,
125505 /* 630 */ 968, 1290, 968, 1291, 1290, 310, 1291, 693, 317, 245,
125506 /* 640 */ 264, 311, 93, 94, 84, 868, 871, 860, 860, 91,
125507 /* 650 */ 91, 92, 92, 92, 92, 832, 90, 90, 90, 90,
125508 /* 660 */ 89, 89, 88, 88, 88, 87, 335, 430, 320, 213,
125509 /* 670 */ 762, 780, 856, 856, 920, 920, 369, 257, 966, 220,
125510 /* 680 */ 966, 396, 663, 664, 665, 242, 259, 244, 262, 833,
125511 /* 690 */ 37, 650, 2, 93, 94, 84, 868, 871, 860, 860,
125512 /* 700 */ 91, 91, 92, 92, 92, 92, 430, 90, 90, 90,
125513 /* 710 */ 90, 89, 89, 88, 88, 88, 87, 335, 311, 430,
125514 /* 720 */ 239, 430, 917, 368, 430, 238, 916, 793, 833, 38,
125515 /* 730 */ 430, 825, 430, 66, 430, 392, 430, 766, 766, 430,
125516 /* 740 */ 367, 833, 39, 833, 28, 430, 833, 29, 68, 856,
125517 /* 750 */ 856, 900, 833, 40, 833, 41, 833, 42, 833, 11,
125518 /* 760 */ 72, 833, 43, 243, 305, 970, 114, 833, 99, 961,
125519 /* 770 */ 93, 94, 84, 868, 871, 860, 860, 91, 91, 92,
125520 /* 780 */ 92, 92, 92, 430, 90, 90, 90, 90, 89, 89,
125521 /* 790 */ 88, 88, 88, 87, 335, 311, 430, 361, 430, 165,
125522 /* 800 */ 147, 430, 186, 185, 184, 833, 44, 430, 289, 430,
125523 /* 810 */ 246, 430, 971, 430, 212, 163, 430, 357, 833, 45,
125524 /* 820 */ 833, 32, 932, 833, 46, 793, 856, 856, 718, 833,
125525 /* 830 */ 47, 833, 33, 833, 117, 833, 118, 75, 833, 119,
125526 /* 840 */ 288, 305, 967, 214, 935, 322, 311, 93, 94, 84,
125527 /* 850 */ 868, 871, 860, 860, 91, 91, 92, 92, 92, 92,
125528 /* 860 */ 430, 90, 90, 90, 90, 89, 89, 88, 88, 88,
125529 /* 870 */ 87, 335, 430, 832, 426, 317, 288, 856, 856, 114,
125530 /* 880 */ 763, 257, 833, 53, 930, 219, 364, 257, 257, 971,
125531 /* 890 */ 361, 396, 257, 257, 833, 34, 257, 311, 93, 94,
125532 /* 900 */ 84, 868, 871, 860, 860, 91, 91, 92, 92, 92,
125533 /* 910 */ 92, 430, 90, 90, 90, 90, 89, 89, 88, 88,
125534 /* 920 */ 88, 87, 335, 430, 217, 318, 124, 253, 856, 856,
125535 /* 930 */ 218, 943, 257, 833, 100, 898, 759, 774, 361, 755,
125536 /* 940 */ 423, 329, 758, 1017, 289, 833, 50, 682, 311, 93,
125537 /* 950 */ 82, 84, 868, 871, 860, 860, 91, 91, 92, 92,
125538 /* 960 */ 92, 92, 430, 90, 90, 90, 90, 89, 89, 88,
125539 /* 970 */ 88, 88, 87, 335, 430, 256, 419, 114, 249, 856,
125540 /* 980 */ 856, 331, 114, 400, 833, 101, 359, 187, 1064, 726,
125541 /* 990 */ 725, 739, 401, 416, 420, 360, 833, 102, 424, 311,
125542 /* 1000 */ 258, 94, 84, 868, 871, 860, 860, 91, 91, 92,
125543 /* 1010 */ 92, 92, 92, 430, 90, 90, 90, 90, 89, 89,
125544 /* 1020 */ 88, 88, 88, 87, 335, 430, 221, 261, 114, 114,
125545 /* 1030 */ 856, 856, 808, 114, 156, 833, 98, 772, 733, 734,
125546 /* 1040 */ 275, 809, 771, 316, 263, 265, 960, 833, 116, 307,
125547 /* 1050 */ 741, 274, 722, 84, 868, 871, 860, 860, 91, 91,
125548 /* 1060 */ 92, 92, 92, 92, 430, 90, 90, 90, 90, 89,
125549 /* 1070 */ 89, 88, 88, 88, 87, 335, 80, 425, 830, 3,
125550 /* 1080 */ 1214, 191, 430, 721, 336, 336, 833, 113, 252, 80,
125551 /* 1090 */ 425, 68, 3, 913, 913, 428, 270, 336, 336, 430,
125552 /* 1100 */ 377, 784, 430, 197, 833, 106, 430, 716, 428, 430,
125553 /* 1110 */ 267, 430, 897, 68, 414, 430, 769, 409, 430, 71,
125554 /* 1120 */ 430, 833, 105, 123, 833, 103, 847, 414, 833, 49,
125555 /* 1130 */ 843, 833, 104, 833, 52, 800, 123, 833, 54, 847,
125556 /* 1140 */ 833, 51, 833, 26, 831, 802, 77, 78, 191, 389,
125557 /* 1150 */ 430, 372, 114, 79, 432, 431, 911, 911, 835, 77,
125558 /* 1160 */ 78, 779, 893, 408, 410, 197, 79, 432, 431, 791,
125559 /* 1170 */ 226, 835, 833, 30, 772, 80, 425, 716, 3, 771,
125560 /* 1180 */ 411, 412, 897, 336, 336, 290, 291, 839, 703, 840,
125561 /* 1190 */ 840, 840, 842, 19, 428, 695, 684, 672, 111, 671,
125562 /* 1200 */ 843, 673, 840, 840, 840, 842, 19, 207, 661, 278,
125563 /* 1210 */ 148, 304, 280, 414, 282, 6, 822, 348, 248, 241,
125564 /* 1220 */ 358, 934, 720, 80, 425, 847, 3, 161, 382, 273,
125565 /* 1230 */ 284, 336, 336, 415, 296, 958, 895, 894, 157, 674,
125566 /* 1240 */ 107, 194, 428, 948, 135, 77, 78, 777, 953, 951,
125567 /* 1250 */ 56, 319, 79, 432, 431, 121, 66, 835, 59, 128,
125568 /* 1260 */ 146, 414, 350, 130, 351, 819, 131, 132, 133, 375,
125569 /* 1270 */ 173, 149, 138, 847, 936, 365, 178, 70, 425, 827,
125570 /* 1280 */ 3, 889, 62, 371, 915, 336, 336, 792, 840, 840,
125571 /* 1290 */ 840, 842, 19, 77, 78, 208, 428, 144, 179, 373,
125572 /* 1300 */ 79, 432, 431, 255, 180, 835, 260, 675, 181, 308,
125573 /* 1310 */ 388, 744, 326, 743, 742, 414, 731, 718, 712, 402,
125574 /* 1320 */ 309, 711, 788, 65, 277, 272, 789, 847, 730, 710,
125575 /* 1330 */ 709, 279, 193, 787, 281, 876, 840, 840, 840, 842,
125576 /* 1340 */ 19, 786, 283, 73, 418, 330, 422, 77, 78, 227,
125577 /* 1350 */ 96, 407, 67, 405, 79, 432, 431, 292, 228, 835,
125578 /* 1360 */ 215, 202, 229, 293, 767, 303, 302, 301, 204, 299,
125579 /* 1370 */ 294, 295, 676, 7, 681, 433, 669, 206, 110, 224,
125580 /* 1380 */ 203, 205, 434, 667, 666, 658, 120, 168, 656, 237,
125581 /* 1390 */ 840, 840, 840, 842, 19, 337, 155, 233, 236, 341,
125582 /* 1400 */ 167, 905, 108, 313, 903, 826, 314, 125, 126, 127,
125583 /* 1410 */ 129, 170, 247, 756, 172, 928, 134, 136, 171, 60,
125584 /* 1420 */ 61, 123, 169, 137, 175, 933, 176, 927, 8, 13,
125585 /* 1430 */ 177, 254, 191, 918, 139, 370, 924, 140, 678, 150,
125586 /* 1440 */ 374, 274, 182, 378, 141, 122, 63, 14, 383, 729,
125587 /* 1450 */ 268, 15, 64, 225, 846, 845, 874, 16, 765, 770,
125588 /* 1460 */ 4, 162, 209, 395, 211, 142, 878, 796, 801, 312,
125589 /* 1470 */ 190, 71, 68, 875, 873, 939, 199, 938, 17, 195,
125590 /* 1480 */ 18, 196, 417, 975, 152, 653, 976, 198, 153, 421,
125591 /* 1490 */ 877, 154, 200, 844, 696, 81, 343, 297, 1019, 1018,
125592 /* 1500 */ 300,
125593 };
125594 static const YYCODETYPE yy_lookahead[] = {
125595 /* 0 */ 19, 144, 145, 146, 147, 24, 1, 2, 27, 80,
125596 /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
125597 /* 20 */ 91, 92, 93, 94, 95, 91, 92, 93, 94, 95,
125598 /* 30 */ 19, 50, 51, 80, 81, 82, 83, 212, 85, 86,
125599 /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 224,
125600 /* 50 */ 225, 226, 71, 72, 73, 74, 75, 76, 77, 78,
125601 /* 60 */ 79, 80, 81, 82, 83, 95, 85, 86, 87, 88,
125602 /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 85,
125603 /* 80 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
125604 /* 90 */ 66, 33, 27, 28, 27, 28, 22, 201, 152, 152,
125605 /* 100 */ 42, 27, 152, 224, 225, 226, 95, 211, 50, 51,
125606 /* 110 */ 99, 100, 101, 102, 103, 104, 105, 27, 28, 59,
125607 /* 120 */ 174, 175, 243, 112, 174, 175, 66, 94, 95, 71,
125608 /* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125609 /* 140 */ 82, 83, 195, 85, 86, 87, 88, 89, 90, 91,
125610 /* 150 */ 92, 93, 94, 95, 19, 209, 89, 90, 173, 209,
125611 /* 160 */ 210, 26, 97, 98, 97, 98, 181, 100, 108, 109,
125612 /* 170 */ 110, 97, 174, 152, 107, 152, 109, 89, 90, 91,
125613 /* 180 */ 92, 93, 94, 95, 163, 50, 51, 97, 98, 99,
125614 /* 190 */ 55, 244, 102, 103, 104, 174, 175, 174, 175, 132,
125615 /* 200 */ 133, 89, 90, 113, 66, 19, 71, 72, 73, 74,
125616 /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 198,
125617 /* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
125618 /* 230 */ 95, 152, 209, 210, 148, 149, 50, 51, 100, 53,
125619 /* 240 */ 154, 59, 156, 22, 132, 133, 119, 120, 163, 163,
125620 /* 250 */ 22, 192, 193, 174, 175, 27, 28, 71, 72, 73,
125621 /* 260 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
125622 /* 270 */ 174, 85, 86, 87, 88, 89, 90, 91, 92, 93,
125623 /* 280 */ 94, 95, 19, 198, 198, 174, 152, 24, 209, 210,
125624 /* 290 */ 108, 109, 110, 192, 193, 27, 28, 69, 164, 165,
125625 /* 300 */ 79, 119, 120, 27, 28, 27, 99, 222, 152, 102,
125626 /* 310 */ 103, 104, 24, 50, 51, 27, 66, 89, 90, 185,
125627 /* 320 */ 113, 187, 22, 157, 239, 97, 58, 27, 28, 101,
125628 /* 330 */ 174, 175, 246, 163, 71, 72, 73, 74, 75, 76,
125629 /* 340 */ 77, 78, 79, 80, 81, 82, 83, 11, 85, 86,
125630 /* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19,
125631 /* 360 */ 132, 133, 134, 23, 152, 97, 98, 91, 198, 119,
125632 /* 370 */ 120, 152, 22, 97, 98, 97, 152, 27, 28, 27,
125633 /* 380 */ 28, 27, 28, 227, 160, 97, 174, 175, 164, 165,
125634 /* 390 */ 50, 51, 222, 174, 175, 59, 230, 97, 98, 233,
125635 /* 400 */ 188, 137, 66, 139, 234, 187, 177, 188, 152, 239,
125636 /* 410 */ 69, 71, 72, 73, 74, 75, 76, 77, 78, 79,
125637 /* 420 */ 80, 81, 82, 83, 12, 85, 86, 87, 88, 89,
125638 /* 430 */ 90, 91, 92, 93, 94, 95, 19, 177, 97, 152,
125639 /* 440 */ 23, 29, 101, 152, 108, 109, 110, 97, 98, 97,
125640 /* 450 */ 98, 97, 98, 224, 225, 226, 22, 45, 24, 47,
125641 /* 460 */ 152, 152, 152, 152, 152, 174, 175, 50, 51, 249,
125642 /* 470 */ 250, 59, 21, 132, 133, 134, 124, 221, 124, 188,
125643 /* 480 */ 171, 172, 171, 172, 224, 225, 226, 152, 71, 72,
125644 /* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
125645 /* 500 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
125646 /* 510 */ 93, 94, 95, 19, 152, 183, 65, 23, 170, 171,
125647 /* 520 */ 172, 19, 23, 174, 175, 26, 152, 50, 51, 12,
125648 /* 530 */ 196, 197, 37, 170, 171, 172, 174, 175, 224, 225,
125649 /* 540 */ 226, 232, 208, 232, 50, 51, 29, 52, 174, 175,
125650 /* 550 */ 188, 74, 75, 51, 103, 60, 222, 163, 209, 0,
125651 /* 560 */ 1, 2, 45, 152, 47, 71, 72, 73, 74, 75,
125652 /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 101, 85,
125653 /* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
125654 /* 590 */ 19, 140, 198, 152, 23, 152, 22, 98, 24, 152,
125655 /* 600 */ 152, 27, 152, 183, 152, 152, 111, 213, 214, 107,
125656 /* 610 */ 152, 164, 165, 152, 112, 174, 175, 174, 175, 181,
125657 /* 620 */ 182, 50, 51, 124, 174, 175, 174, 175, 190, 26,
125658 /* 630 */ 22, 23, 22, 23, 26, 166, 26, 168, 169, 16,
125659 /* 640 */ 16, 19, 71, 72, 73, 74, 75, 76, 77, 78,
125660 /* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88,
125661 /* 660 */ 89, 90, 91, 92, 93, 94, 95, 152, 220, 196,
125662 /* 670 */ 197, 97, 50, 51, 108, 109, 110, 152, 70, 221,
125663 /* 680 */ 70, 208, 7, 8, 9, 62, 62, 64, 64, 174,
125664 /* 690 */ 175, 146, 147, 71, 72, 73, 74, 75, 76, 77,
125665 /* 700 */ 78, 79, 80, 81, 82, 83, 152, 85, 86, 87,
125666 /* 710 */ 88, 89, 90, 91, 92, 93, 94, 95, 19, 152,
125667 /* 720 */ 195, 152, 31, 220, 152, 152, 35, 26, 174, 175,
125668 /* 730 */ 152, 163, 152, 130, 152, 115, 152, 117, 118, 152,
125669 /* 740 */ 49, 174, 175, 174, 175, 152, 174, 175, 26, 50,
125670 /* 750 */ 51, 152, 174, 175, 174, 175, 174, 175, 174, 175,
125671 /* 760 */ 138, 174, 175, 140, 22, 23, 198, 174, 175, 152,
125672 /* 770 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
125673 /* 780 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
125674 /* 790 */ 91, 92, 93, 94, 95, 19, 152, 152, 152, 98,
125675 /* 800 */ 24, 152, 108, 109, 110, 174, 175, 152, 152, 152,
125676 /* 810 */ 152, 152, 70, 152, 213, 214, 152, 152, 174, 175,
125677 /* 820 */ 174, 175, 152, 174, 175, 124, 50, 51, 106, 174,
125678 /* 830 */ 175, 174, 175, 174, 175, 174, 175, 138, 174, 175,
125679 /* 840 */ 152, 22, 23, 22, 163, 189, 19, 71, 72, 73,
125680 /* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
125681 /* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
125682 /* 870 */ 94, 95, 152, 152, 168, 169, 152, 50, 51, 198,
125683 /* 880 */ 197, 152, 174, 175, 152, 240, 152, 152, 152, 70,
125684 /* 890 */ 152, 208, 152, 152, 174, 175, 152, 19, 71, 72,
125685 /* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
125686 /* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
125687 /* 920 */ 93, 94, 95, 152, 195, 247, 248, 152, 50, 51,
125688 /* 930 */ 195, 195, 152, 174, 175, 195, 195, 26, 152, 195,
125689 /* 940 */ 252, 220, 163, 122, 152, 174, 175, 163, 19, 71,
125690 /* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
125691 /* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
125692 /* 970 */ 92, 93, 94, 95, 152, 195, 252, 198, 240, 50,
125693 /* 980 */ 51, 189, 198, 19, 174, 175, 19, 51, 23, 100,
125694 /* 990 */ 101, 26, 28, 163, 163, 28, 174, 175, 163, 19,
125695 /* 1000 */ 152, 72, 73, 74, 75, 76, 77, 78, 79, 80,
125696 /* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
125697 /* 1020 */ 91, 92, 93, 94, 95, 152, 240, 152, 198, 198,
125698 /* 1030 */ 50, 51, 33, 198, 123, 174, 175, 116, 7, 8,
125699 /* 1040 */ 101, 42, 121, 107, 152, 152, 23, 174, 175, 26,
125700 /* 1050 */ 152, 112, 183, 73, 74, 75, 76, 77, 78, 79,
125701 /* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89,
125702 /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 23, 22,
125703 /* 1080 */ 23, 26, 152, 152, 27, 28, 174, 175, 23, 19,
125704 /* 1090 */ 20, 26, 22, 132, 133, 38, 152, 27, 28, 152,
125705 /* 1100 */ 23, 215, 152, 26, 174, 175, 152, 27, 38, 152,
125706 /* 1110 */ 23, 152, 27, 26, 57, 152, 23, 163, 152, 26,
125707 /* 1120 */ 152, 174, 175, 66, 174, 175, 69, 57, 174, 175,
125708 /* 1130 */ 27, 174, 175, 174, 175, 152, 66, 174, 175, 69,
125709 /* 1140 */ 174, 175, 174, 175, 152, 23, 89, 90, 26, 91,
125710 /* 1150 */ 152, 236, 198, 96, 97, 98, 132, 133, 101, 89,
125711 /* 1160 */ 90, 152, 23, 209, 210, 26, 96, 97, 98, 152,
125712 /* 1170 */ 212, 101, 174, 175, 116, 19, 20, 97, 22, 121,
125713 /* 1180 */ 152, 193, 97, 27, 28, 152, 152, 152, 152, 132,
125714 /* 1190 */ 133, 134, 135, 136, 38, 23, 152, 152, 26, 152,
125715 /* 1200 */ 97, 152, 132, 133, 134, 135, 136, 235, 152, 212,
125716 /* 1210 */ 199, 150, 212, 57, 212, 200, 203, 216, 241, 216,
125717 /* 1220 */ 241, 203, 182, 19, 20, 69, 22, 186, 178, 177,
125718 /* 1230 */ 216, 27, 28, 229, 202, 39, 177, 177, 200, 155,
125719 /* 1240 */ 245, 122, 38, 41, 22, 89, 90, 91, 159, 159,
125720 /* 1250 */ 242, 159, 96, 97, 98, 71, 130, 101, 242, 191,
125721 /* 1260 */ 223, 57, 18, 194, 159, 203, 194, 194, 194, 18,
125722 /* 1270 */ 158, 223, 191, 69, 203, 159, 158, 19, 20, 191,
125723 /* 1280 */ 22, 203, 137, 46, 238, 27, 28, 159, 132, 133,
125724 /* 1290 */ 134, 135, 136, 89, 90, 159, 38, 22, 158, 179,
125725 /* 1300 */ 96, 97, 98, 237, 158, 101, 159, 159, 158, 179,
125726 /* 1310 */ 107, 176, 48, 176, 176, 57, 184, 106, 176, 125,
125727 /* 1320 */ 179, 178, 218, 107, 217, 176, 218, 69, 184, 176,
125728 /* 1330 */ 176, 217, 159, 218, 217, 159, 132, 133, 134, 135,
125729 /* 1340 */ 136, 218, 217, 137, 179, 95, 179, 89, 90, 228,
125730 /* 1350 */ 129, 126, 128, 127, 96, 97, 98, 206, 231, 101,
125731 /* 1360 */ 5, 25, 231, 205, 207, 10, 11, 12, 13, 14,
125732 /* 1370 */ 204, 203, 17, 26, 162, 161, 13, 6, 180, 180,
125733 /* 1380 */ 153, 153, 151, 151, 151, 151, 167, 32, 4, 34,
125734 /* 1390 */ 132, 133, 134, 135, 136, 3, 22, 142, 43, 68,
125735 /* 1400 */ 15, 23, 16, 251, 23, 120, 251, 248, 131, 111,
125736 /* 1410 */ 123, 56, 16, 20, 125, 1, 123, 131, 63, 79,
125737 /* 1420 */ 79, 66, 67, 111, 36, 28, 122, 1, 5, 22,
125738 /* 1430 */ 107, 140, 26, 54, 54, 44, 61, 107, 20, 24,
125739 /* 1440 */ 19, 112, 105, 53, 22, 40, 22, 22, 53, 30,
125740 /* 1450 */ 23, 22, 22, 53, 23, 23, 23, 22, 116, 23,
125741 /* 1460 */ 22, 122, 23, 26, 23, 22, 11, 124, 28, 114,
125742 /* 1470 */ 36, 26, 26, 23, 23, 23, 122, 23, 36, 26,
125743 /* 1480 */ 36, 22, 24, 23, 22, 1, 23, 26, 22, 24,
125744 /* 1490 */ 23, 22, 122, 23, 23, 22, 141, 23, 122, 122,
125745 /* 1500 */ 15,
125746 };
125747 #define YY_SHIFT_USE_DFLT (-72)
125748 #define YY_SHIFT_COUNT (435)
125749 #define YY_SHIFT_MIN (-71)
125750 #define YY_SHIFT_MAX (1485)
125751 static const short yy_shift_ofst[] = {
125752 /* 0 */ 5, 1057, 1355, 1070, 1204, 1204, 1204, 90, 60, -19,
125753 /* 10 */ 58, 58, 186, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125754 /* 20 */ 67, 67, 182, 336, 65, 250, 135, 263, 340, 417,
125755 /* 30 */ 494, 571, 622, 699, 776, 827, 827, 827, 827, 827,
125756 /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 827,
125757 /* 50 */ 878, 827, 929, 980, 980, 1156, 1204, 1204, 1204, 1204,
125758 /* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125759 /* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
125760 /* 80 */ 1204, 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204,
125761 /* 90 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, -71, -47,
125762 /* 100 */ -47, -47, -47, -47, -6, 88, -66, 65, 65, 451,
125763 /* 110 */ 502, 112, 112, 33, 127, 278, -30, -72, -72, -72,
125764 /* 120 */ 11, 412, 412, 268, 608, 610, 65, 65, 65, 65,
125765 /* 130 */ 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
125766 /* 140 */ 65, 65, 65, 65, 65, 559, 138, 278, 127, 24,
125767 /* 150 */ 24, 24, 24, 24, 24, -72, -72, -72, 228, 341,
125768 /* 160 */ 341, 207, 276, 300, 352, 354, 350, 65, 65, 65,
125769 /* 170 */ 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
125770 /* 180 */ 65, 65, 65, 65, 495, 495, 495, 65, 65, 499,
125771 /* 190 */ 65, 65, 65, 574, 65, 65, 517, 65, 65, 65,
125772 /* 200 */ 65, 65, 65, 65, 65, 65, 65, 566, 691, 288,
125773 /* 210 */ 288, 288, 701, 620, 1058, 675, 603, 964, 964, 967,
125774 /* 220 */ 603, 967, 722, 965, 936, 999, 964, 264, 999, 999,
125775 /* 230 */ 911, 921, 434, 1196, 1119, 1119, 1202, 1202, 1119, 1222,
125776 /* 240 */ 1184, 1126, 1244, 1244, 1244, 1244, 1119, 1251, 1126, 1222,
125777 /* 250 */ 1184, 1184, 1126, 1119, 1251, 1145, 1237, 1119, 1119, 1251,
125778 /* 260 */ 1275, 1119, 1251, 1119, 1251, 1275, 1203, 1203, 1203, 1264,
125779 /* 270 */ 1275, 1203, 1211, 1203, 1264, 1203, 1203, 1194, 1216, 1194,
125780 /* 280 */ 1216, 1194, 1216, 1194, 1216, 1119, 1119, 1206, 1275, 1250,
125781 /* 290 */ 1250, 1275, 1221, 1225, 1224, 1226, 1126, 1336, 1347, 1363,
125782 /* 300 */ 1363, 1371, 1371, 1371, 1371, -72, -72, -72, -72, -72,
125783 /* 310 */ -72, 477, 623, 742, 819, 624, 694, 74, 1023, 221,
125784 /* 320 */ 1055, 1065, 1077, 1087, 1080, 889, 1031, 939, 1093, 1122,
125785 /* 330 */ 1085, 1139, 961, 1024, 1172, 1103, 821, 1384, 1392, 1374,
125786 /* 340 */ 1255, 1385, 1331, 1386, 1378, 1381, 1285, 1277, 1298, 1287,
125787 /* 350 */ 1393, 1289, 1396, 1414, 1293, 1286, 1340, 1341, 1312, 1397,
125788 /* 360 */ 1388, 1304, 1426, 1423, 1407, 1323, 1291, 1379, 1406, 1380,
125789 /* 370 */ 1375, 1391, 1330, 1415, 1418, 1421, 1329, 1337, 1422, 1390,
125790 /* 380 */ 1424, 1425, 1427, 1429, 1395, 1419, 1430, 1400, 1405, 1431,
125791 /* 390 */ 1432, 1433, 1342, 1435, 1436, 1438, 1437, 1339, 1439, 1441,
125792 /* 400 */ 1440, 1434, 1443, 1343, 1445, 1442, 1446, 1444, 1445, 1450,
125793 /* 410 */ 1451, 1452, 1453, 1454, 1459, 1455, 1460, 1462, 1458, 1461,
125794 /* 420 */ 1463, 1466, 1465, 1461, 1467, 1469, 1470, 1471, 1473, 1354,
125795 /* 430 */ 1370, 1376, 1377, 1474, 1485, 1484,
125796 };
125797 #define YY_REDUCE_USE_DFLT (-176)
125798 #define YY_REDUCE_COUNT (310)
125799 #define YY_REDUCE_MIN (-175)
125800 #define YY_REDUCE_MAX (1234)
125801 static const short yy_reduce_ofst[] = {
125802 /* 0 */ -143, 954, 86, 21, -50, 23, 79, 134, 170, -175,
125803 /* 10 */ 229, 260, -121, 212, 219, 291, -54, 349, 362, 156,
125804 /* 20 */ 309, 311, 334, 85, 224, 394, 314, 314, 314, 314,
125805 /* 30 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314,
125806 /* 40 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314,
125807 /* 50 */ 314, 314, 314, 314, 314, 374, 441, 443, 450, 452,
125808 /* 60 */ 515, 554, 567, 569, 572, 578, 580, 582, 584, 587,
125809 /* 70 */ 593, 631, 644, 646, 649, 655, 657, 659, 661, 664,
125810 /* 80 */ 708, 720, 759, 771, 810, 822, 861, 873, 912, 930,
125811 /* 90 */ 947, 950, 957, 959, 963, 966, 968, 998, 314, 314,
125812 /* 100 */ 314, 314, 314, 314, 314, 314, 314, 447, -53, 166,
125813 /* 110 */ 438, 348, 363, 314, 473, 469, 314, 314, 314, 314,
125814 /* 120 */ -15, 59, 101, 688, 220, 220, 525, 256, 729, 735,
125815 /* 130 */ 736, 740, 741, 744, 645, 448, 738, 458, 786, 503,
125816 /* 140 */ 780, 656, 721, 724, 792, 545, 568, 706, 683, 681,
125817 /* 150 */ 779, 784, 830, 831, 835, 678, 601, -104, -2, 96,
125818 /* 160 */ 111, 218, 287, 308, 310, 312, 335, 411, 453, 461,
125819 /* 170 */ 573, 599, 617, 658, 665, 670, 732, 734, 775, 848,
125820 /* 180 */ 875, 892, 893, 898, 332, 420, 869, 931, 944, 886,
125821 /* 190 */ 983, 992, 1009, 958, 1017, 1028, 988, 1033, 1034, 1035,
125822 /* 200 */ 287, 1036, 1044, 1045, 1047, 1049, 1056, 915, 972, 997,
125823 /* 210 */ 1000, 1002, 886, 1011, 1015, 1061, 1013, 1001, 1003, 977,
125824 /* 220 */ 1018, 979, 1050, 1041, 1040, 1052, 1014, 1004, 1059, 1060,
125825 /* 230 */ 1032, 1038, 1084, 995, 1089, 1090, 1008, 1016, 1092, 1037,
125826 /* 240 */ 1068, 1062, 1069, 1072, 1073, 1074, 1105, 1112, 1071, 1048,
125827 /* 250 */ 1081, 1088, 1078, 1116, 1118, 1046, 1066, 1128, 1136, 1140,
125828 /* 260 */ 1120, 1147, 1146, 1148, 1150, 1130, 1135, 1137, 1138, 1132,
125829 /* 270 */ 1141, 1142, 1143, 1149, 1144, 1153, 1154, 1104, 1107, 1108,
125830 /* 280 */ 1114, 1115, 1117, 1123, 1125, 1173, 1176, 1121, 1165, 1127,
125831 /* 290 */ 1131, 1167, 1157, 1151, 1158, 1166, 1168, 1212, 1214, 1227,
125832 /* 300 */ 1228, 1231, 1232, 1233, 1234, 1152, 1155, 1159, 1198, 1199,
125833 /* 310 */ 1219,
125834 };
125835 static const YYACTIONTYPE yy_default[] = {
125836 /* 0 */ 982, 1300, 1300, 1300, 1214, 1214, 1214, 1305, 1300, 1109,
125837 /* 10 */ 1138, 1138, 1274, 1305, 1305, 1305, 1305, 1305, 1305, 1212,
125838 /* 20 */ 1305, 1305, 1305, 1300, 1305, 1113, 1144, 1305, 1305, 1305,
125839 /* 30 */ 1305, 1305, 1305, 1305, 1305, 1273, 1275, 1152, 1151, 1254,
125840 /* 40 */ 1125, 1149, 1142, 1146, 1215, 1208, 1209, 1207, 1211, 1216,
125841 /* 50 */ 1305, 1145, 1177, 1192, 1176, 1305, 1305, 1305, 1305, 1305,
125842 /* 60 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125843 /* 70 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125844 /* 80 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125845 /* 90 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1186, 1191,
125846 /* 100 */ 1198, 1190, 1187, 1179, 1178, 1180, 1181, 1305, 1305, 1008,
125847 /* 110 */ 1074, 1305, 1305, 1182, 1305, 1020, 1183, 1195, 1194, 1193,
125848 /* 120 */ 1015, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125849 /* 130 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125850 /* 140 */ 1305, 1305, 1305, 1305, 1305, 982, 1300, 1305, 1305, 1300,
125851 /* 150 */ 1300, 1300, 1300, 1300, 1300, 1292, 1113, 1103, 1305, 1305,
125852 /* 160 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1280, 1278,
125853 /* 170 */ 1305, 1227, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125854 /* 180 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125855 /* 190 */ 1305, 1305, 1305, 1109, 1305, 1305, 1305, 1305, 1305, 1305,
125856 /* 200 */ 1305, 1305, 1305, 1305, 1305, 1305, 988, 1305, 1247, 1109,
125857 /* 210 */ 1109, 1109, 1111, 1089, 1101, 990, 1148, 1127, 1127, 1259,
125858 /* 220 */ 1148, 1259, 1045, 1068, 1042, 1138, 1127, 1210, 1138, 1138,
125859 /* 230 */ 1110, 1101, 1305, 1285, 1118, 1118, 1277, 1277, 1118, 1157,
125860 /* 240 */ 1078, 1148, 1085, 1085, 1085, 1085, 1118, 1005, 1148, 1157,
125861 /* 250 */ 1078, 1078, 1148, 1118, 1005, 1253, 1251, 1118, 1118, 1005,
125862 /* 260 */ 1220, 1118, 1005, 1118, 1005, 1220, 1076, 1076, 1076, 1060,
125863 /* 270 */ 1220, 1076, 1045, 1076, 1060, 1076, 1076, 1131, 1126, 1131,
125864 /* 280 */ 1126, 1131, 1126, 1131, 1126, 1118, 1118, 1305, 1220, 1224,
125865 /* 290 */ 1224, 1220, 1143, 1132, 1141, 1139, 1148, 1011, 1063, 998,
125866 /* 300 */ 998, 987, 987, 987, 987, 1297, 1297, 1292, 1047, 1047,
125867 /* 310 */ 1030, 1305, 1305, 1305, 1305, 1305, 1305, 1022, 1305, 1229,
125868 /* 320 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125869 /* 330 */ 1305, 1305, 1305, 1305, 1305, 1305, 1164, 1305, 983, 1287,
125870 /* 340 */ 1305, 1305, 1284, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125871 /* 350 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125872 /* 360 */ 1305, 1257, 1305, 1305, 1305, 1305, 1305, 1305, 1250, 1249,
125873 /* 370 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125874 /* 380 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305,
125875 /* 390 */ 1305, 1305, 1092, 1305, 1305, 1305, 1096, 1305, 1305, 1305,
125876 /* 400 */ 1305, 1305, 1305, 1305, 1140, 1305, 1133, 1305, 1213, 1305,
125877 /* 410 */ 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1305, 1302,
125878 /* 420 */ 1305, 1305, 1305, 1301, 1305, 1305, 1305, 1305, 1305, 1166,
125879 /* 430 */ 1305, 1165, 1169, 1305, 996, 1305,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125880 };
125881
125882 /* The next table maps tokens into fallback tokens. If a construct
125883 ** like the following:
125884 **
@@ -125522,13 +125973,17 @@
125973 ** (In other words, the "major" token.)
125974 **
125975 ** + The semantic value stored at this level of the stack. This is
125976 ** the information used by the action routines in the grammar.
125977 ** It is sometimes called the "minor" token.
125978 **
125979 ** After the "shift" half of a SHIFTREDUCE action, the stateno field
125980 ** actually contains the reduce action for the second half of the
125981 ** SHIFTREDUCE.
125982 */
125983 struct yyStackEntry {
125984 YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
125985 YYCODETYPE major; /* The major token value. This is the code
125986 ** number for the token at this stack level */
125987 YYMINORTYPE minor; /* The user-supplied minor token value. This
125988 ** is the value of the token */
125989 };
@@ -125630,22 +126085,22 @@
126085 "createkw", "temp", "ifnotexists", "dbnm",
126086 "columnlist", "conslist_opt", "table_options", "select",
126087 "column", "columnid", "type", "carglist",
126088 "typetoken", "typename", "signed", "plus_num",
126089 "minus_num", "ccons", "term", "expr",
126090 "onconf", "sortorder", "autoinc", "eidlist_opt",
126091 "refargs", "defer_subclause", "refarg", "refact",
126092 "init_deferred_pred_opt", "conslist", "tconscomma", "tcons",
126093 "sortlist", "eidlist", "defer_subclause_opt", "orconf",
126094 "resolvetype", "raisetype", "ifexists", "fullname",
126095 "selectnowith", "oneselect", "with", "multiselect_op",
126096 "distinct", "selcollist", "from", "where_opt",
126097 "groupby_opt", "having_opt", "orderby_opt", "limit_opt",
126098 "values", "nexprlist", "exprlist", "sclp",
126099 "as", "seltablist", "stl_prefix", "joinop",
126100 "indexed_opt", "on_opt", "using_opt", "joinop2",
126101 "idlist", "setlist", "insert_cmd", "idlist_opt",
126102 "likeop", "between_op", "in_op", "case_operand",
126103 "case_exprlist", "case_else", "uniqueflag", "collate",
126104 "nmnum", "trigger_decl", "trigger_cmd_list", "trigger_time",
126105 "trigger_event", "foreach_clause", "when_clause", "trigger_cmd",
126106 "trnm", "tridxby", "database_kw_opt", "key_opt",
@@ -125722,11 +126177,11 @@
126177 /* 60 */ "ccons ::= NULL onconf",
126178 /* 61 */ "ccons ::= NOT NULL onconf",
126179 /* 62 */ "ccons ::= PRIMARY KEY sortorder onconf autoinc",
126180 /* 63 */ "ccons ::= UNIQUE onconf",
126181 /* 64 */ "ccons ::= CHECK LP expr RP",
126182 /* 65 */ "ccons ::= REFERENCES nm eidlist_opt refargs",
126183 /* 66 */ "ccons ::= defer_subclause",
126184 /* 67 */ "ccons ::= COLLATE ID|STRING",
126185 /* 68 */ "autoinc ::=",
126186 /* 69 */ "autoinc ::= AUTOINCR",
126187 /* 70 */ "refargs ::=",
@@ -125750,14 +126205,14 @@
126205 /* 88 */ "conslist ::= conslist tconscomma tcons",
126206 /* 89 */ "conslist ::= tcons",
126207 /* 90 */ "tconscomma ::= COMMA",
126208 /* 91 */ "tconscomma ::=",
126209 /* 92 */ "tcons ::= CONSTRAINT nm",
126210 /* 93 */ "tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf",
126211 /* 94 */ "tcons ::= UNIQUE LP sortlist RP onconf",
126212 /* 95 */ "tcons ::= CHECK LP expr RP onconf",
126213 /* 96 */ "tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt",
126214 /* 97 */ "defer_subclause_opt ::=",
126215 /* 98 */ "defer_subclause_opt ::= defer_subclause",
126216 /* 99 */ "onconf ::=",
126217 /* 100 */ "onconf ::= ON CONFLICT resolvetype",
126218 /* 101 */ "orconf ::=",
@@ -125766,11 +126221,11 @@
126221 /* 104 */ "resolvetype ::= IGNORE",
126222 /* 105 */ "resolvetype ::= REPLACE",
126223 /* 106 */ "cmd ::= DROP TABLE ifexists fullname",
126224 /* 107 */ "ifexists ::= IF EXISTS",
126225 /* 108 */ "ifexists ::=",
126226 /* 109 */ "cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select",
126227 /* 110 */ "cmd ::= DROP VIEW ifexists fullname",
126228 /* 111 */ "cmd ::= select",
126229 /* 112 */ "select ::= with selectnowith",
126230 /* 113 */ "selectnowith ::= oneselect",
126231 /* 114 */ "selectnowith ::= selectnowith multiselect_op oneselect",
@@ -125795,199 +126250,200 @@
126250 /* 133 */ "from ::=",
126251 /* 134 */ "from ::= FROM seltablist",
126252 /* 135 */ "stl_prefix ::= seltablist joinop",
126253 /* 136 */ "stl_prefix ::=",
126254 /* 137 */ "seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt",
126255 /* 138 */ "seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt",
126256 /* 139 */ "seltablist ::= stl_prefix LP select RP as on_opt using_opt",
126257 /* 140 */ "seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt",
126258 /* 141 */ "dbnm ::=",
126259 /* 142 */ "dbnm ::= DOT nm",
126260 /* 143 */ "fullname ::= nm dbnm",
126261 /* 144 */ "joinop ::= COMMA|JOIN",
126262 /* 145 */ "joinop ::= JOIN_KW JOIN",
126263 /* 146 */ "joinop ::= JOIN_KW nm JOIN",
126264 /* 147 */ "joinop ::= JOIN_KW nm nm JOIN",
126265 /* 148 */ "on_opt ::= ON expr",
126266 /* 149 */ "on_opt ::=",
126267 /* 150 */ "indexed_opt ::=",
126268 /* 151 */ "indexed_opt ::= INDEXED BY nm",
126269 /* 152 */ "indexed_opt ::= NOT INDEXED",
126270 /* 153 */ "using_opt ::= USING LP idlist RP",
126271 /* 154 */ "using_opt ::=",
126272 /* 155 */ "orderby_opt ::=",
126273 /* 156 */ "orderby_opt ::= ORDER BY sortlist",
126274 /* 157 */ "sortlist ::= sortlist COMMA expr sortorder",
126275 /* 158 */ "sortlist ::= expr sortorder",
126276 /* 159 */ "sortorder ::= ASC",
126277 /* 160 */ "sortorder ::= DESC",
126278 /* 161 */ "sortorder ::=",
126279 /* 162 */ "groupby_opt ::=",
126280 /* 163 */ "groupby_opt ::= GROUP BY nexprlist",
126281 /* 164 */ "having_opt ::=",
126282 /* 165 */ "having_opt ::= HAVING expr",
126283 /* 166 */ "limit_opt ::=",
126284 /* 167 */ "limit_opt ::= LIMIT expr",
126285 /* 168 */ "limit_opt ::= LIMIT expr OFFSET expr",
126286 /* 169 */ "limit_opt ::= LIMIT expr COMMA expr",
126287 /* 170 */ "cmd ::= with DELETE FROM fullname indexed_opt where_opt",
126288 /* 171 */ "where_opt ::=",
126289 /* 172 */ "where_opt ::= WHERE expr",
126290 /* 173 */ "cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt",
126291 /* 174 */ "setlist ::= setlist COMMA nm EQ expr",
126292 /* 175 */ "setlist ::= nm EQ expr",
126293 /* 176 */ "cmd ::= with insert_cmd INTO fullname idlist_opt select",
126294 /* 177 */ "cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES",
126295 /* 178 */ "insert_cmd ::= INSERT orconf",
126296 /* 179 */ "insert_cmd ::= REPLACE",
126297 /* 180 */ "idlist_opt ::=",
126298 /* 181 */ "idlist_opt ::= LP idlist RP",
126299 /* 182 */ "idlist ::= idlist COMMA nm",
126300 /* 183 */ "idlist ::= nm",
126301 /* 184 */ "expr ::= term",
126302 /* 185 */ "expr ::= LP expr RP",
126303 /* 186 */ "term ::= NULL",
126304 /* 187 */ "expr ::= ID|INDEXED",
126305 /* 188 */ "expr ::= JOIN_KW",
126306 /* 189 */ "expr ::= nm DOT nm",
126307 /* 190 */ "expr ::= nm DOT nm DOT nm",
126308 /* 191 */ "term ::= INTEGER|FLOAT|BLOB",
126309 /* 192 */ "term ::= STRING",
126310 /* 193 */ "expr ::= VARIABLE",
126311 /* 194 */ "expr ::= expr COLLATE ID|STRING",
126312 /* 195 */ "expr ::= CAST LP expr AS typetoken RP",
126313 /* 196 */ "expr ::= ID|INDEXED LP distinct exprlist RP",
126314 /* 197 */ "expr ::= ID|INDEXED LP STAR RP",
126315 /* 198 */ "term ::= CTIME_KW",
126316 /* 199 */ "expr ::= expr AND expr",
126317 /* 200 */ "expr ::= expr OR expr",
126318 /* 201 */ "expr ::= expr LT|GT|GE|LE expr",
126319 /* 202 */ "expr ::= expr EQ|NE expr",
126320 /* 203 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr",
126321 /* 204 */ "expr ::= expr PLUS|MINUS expr",
126322 /* 205 */ "expr ::= expr STAR|SLASH|REM expr",
126323 /* 206 */ "expr ::= expr CONCAT expr",
126324 /* 207 */ "likeop ::= LIKE_KW|MATCH",
126325 /* 208 */ "likeop ::= NOT LIKE_KW|MATCH",
126326 /* 209 */ "expr ::= expr likeop expr",
126327 /* 210 */ "expr ::= expr likeop expr ESCAPE expr",
126328 /* 211 */ "expr ::= expr ISNULL|NOTNULL",
126329 /* 212 */ "expr ::= expr NOT NULL",
126330 /* 213 */ "expr ::= expr IS expr",
126331 /* 214 */ "expr ::= expr IS NOT expr",
126332 /* 215 */ "expr ::= NOT expr",
126333 /* 216 */ "expr ::= BITNOT expr",
126334 /* 217 */ "expr ::= MINUS expr",
126335 /* 218 */ "expr ::= PLUS expr",
126336 /* 219 */ "between_op ::= BETWEEN",
126337 /* 220 */ "between_op ::= NOT BETWEEN",
126338 /* 221 */ "expr ::= expr between_op expr AND expr",
126339 /* 222 */ "in_op ::= IN",
126340 /* 223 */ "in_op ::= NOT IN",
126341 /* 224 */ "expr ::= expr in_op LP exprlist RP",
126342 /* 225 */ "expr ::= LP select RP",
126343 /* 226 */ "expr ::= expr in_op LP select RP",
126344 /* 227 */ "expr ::= expr in_op nm dbnm",
126345 /* 228 */ "expr ::= EXISTS LP select RP",
126346 /* 229 */ "expr ::= CASE case_operand case_exprlist case_else END",
126347 /* 230 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
126348 /* 231 */ "case_exprlist ::= WHEN expr THEN expr",
126349 /* 232 */ "case_else ::= ELSE expr",
126350 /* 233 */ "case_else ::=",
126351 /* 234 */ "case_operand ::= expr",
126352 /* 235 */ "case_operand ::=",
126353 /* 236 */ "exprlist ::= nexprlist",
126354 /* 237 */ "exprlist ::=",
126355 /* 238 */ "nexprlist ::= nexprlist COMMA expr",
126356 /* 239 */ "nexprlist ::= expr",
126357 /* 240 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
126358 /* 241 */ "uniqueflag ::= UNIQUE",
126359 /* 242 */ "uniqueflag ::=",
126360 /* 243 */ "eidlist_opt ::=",
126361 /* 244 */ "eidlist_opt ::= LP eidlist RP",
126362 /* 245 */ "eidlist ::= eidlist COMMA nm collate sortorder",
126363 /* 246 */ "eidlist ::= nm collate sortorder",
126364 /* 247 */ "collate ::=",
126365 /* 248 */ "collate ::= COLLATE ID|STRING",
126366 /* 249 */ "cmd ::= DROP INDEX ifexists fullname",
126367 /* 250 */ "cmd ::= VACUUM",
126368 /* 251 */ "cmd ::= VACUUM nm",
126369 /* 252 */ "cmd ::= PRAGMA nm dbnm",
126370 /* 253 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
126371 /* 254 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
126372 /* 255 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
126373 /* 256 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
126374 /* 257 */ "nmnum ::= plus_num",
126375 /* 258 */ "nmnum ::= nm",
126376 /* 259 */ "nmnum ::= ON",
126377 /* 260 */ "nmnum ::= DELETE",
126378 /* 261 */ "nmnum ::= DEFAULT",
126379 /* 262 */ "plus_num ::= PLUS INTEGER|FLOAT",
126380 /* 263 */ "plus_num ::= INTEGER|FLOAT",
126381 /* 264 */ "minus_num ::= MINUS INTEGER|FLOAT",
126382 /* 265 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
126383 /* 266 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
126384 /* 267 */ "trigger_time ::= BEFORE",
126385 /* 268 */ "trigger_time ::= AFTER",
126386 /* 269 */ "trigger_time ::= INSTEAD OF",
126387 /* 270 */ "trigger_time ::=",
126388 /* 271 */ "trigger_event ::= DELETE|INSERT",
126389 /* 272 */ "trigger_event ::= UPDATE",
126390 /* 273 */ "trigger_event ::= UPDATE OF idlist",
126391 /* 274 */ "foreach_clause ::=",
126392 /* 275 */ "foreach_clause ::= FOR EACH ROW",
126393 /* 276 */ "when_clause ::=",
126394 /* 277 */ "when_clause ::= WHEN expr",
126395 /* 278 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
126396 /* 279 */ "trigger_cmd_list ::= trigger_cmd SEMI",
126397 /* 280 */ "trnm ::= nm",
126398 /* 281 */ "trnm ::= nm DOT nm",
126399 /* 282 */ "tridxby ::=",
126400 /* 283 */ "tridxby ::= INDEXED BY nm",
126401 /* 284 */ "tridxby ::= NOT INDEXED",
126402 /* 285 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt",
126403 /* 286 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select",
126404 /* 287 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt",
126405 /* 288 */ "trigger_cmd ::= select",
126406 /* 289 */ "expr ::= RAISE LP IGNORE RP",
126407 /* 290 */ "expr ::= RAISE LP raisetype COMMA nm RP",
126408 /* 291 */ "raisetype ::= ROLLBACK",
126409 /* 292 */ "raisetype ::= ABORT",
126410 /* 293 */ "raisetype ::= FAIL",
126411 /* 294 */ "cmd ::= DROP TRIGGER ifexists fullname",
126412 /* 295 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
126413 /* 296 */ "cmd ::= DETACH database_kw_opt expr",
126414 /* 297 */ "key_opt ::=",
126415 /* 298 */ "key_opt ::= KEY expr",
126416 /* 299 */ "database_kw_opt ::= DATABASE",
126417 /* 300 */ "database_kw_opt ::=",
126418 /* 301 */ "cmd ::= REINDEX",
126419 /* 302 */ "cmd ::= REINDEX nm dbnm",
126420 /* 303 */ "cmd ::= ANALYZE",
126421 /* 304 */ "cmd ::= ANALYZE nm dbnm",
126422 /* 305 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
126423 /* 306 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
126424 /* 307 */ "add_column_fullname ::= fullname",
126425 /* 308 */ "kwcolumn_opt ::=",
126426 /* 309 */ "kwcolumn_opt ::= COLUMNKW",
126427 /* 310 */ "cmd ::= create_vtab",
126428 /* 311 */ "cmd ::= create_vtab LP vtabarglist RP",
126429 /* 312 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
126430 /* 313 */ "vtabarglist ::= vtabarg",
126431 /* 314 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
126432 /* 315 */ "vtabarg ::=",
126433 /* 316 */ "vtabarg ::= vtabarg vtabargtoken",
126434 /* 317 */ "vtabargtoken ::= ANY",
126435 /* 318 */ "vtabargtoken ::= lp anylist RP",
126436 /* 319 */ "lp ::= LP",
126437 /* 320 */ "anylist ::=",
126438 /* 321 */ "anylist ::= anylist LP anylist RP",
126439 /* 322 */ "anylist ::= anylist ANY",
126440 /* 323 */ "with ::=",
126441 /* 324 */ "with ::= WITH wqlist",
126442 /* 325 */ "with ::= WITH RECURSIVE wqlist",
126443 /* 326 */ "wqlist ::= nm eidlist_opt AS LP select RP",
126444 /* 327 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
126445 };
126446 #endif /* NDEBUG */
126447
126448
126449 #if YYSTACKDEPTH<=0
@@ -126063,13 +126519,13 @@
126519 ** Note: during a reduce, the only symbols destroyed are those
126520 ** which appear on the RHS of the rule, but which are not used
126521 ** inside the C code.
126522 */
126523 case 163: /* select */
126524 case 196: /* selectnowith */
126525 case 197: /* oneselect */
126526 case 208: /* values */
126527 {
126528 sqlite3SelectDelete(pParse->db, (yypminor->yy3));
126529 }
126530 break;
126531 case 174: /* term */
@@ -126076,53 +126532,53 @@
126532 case 175: /* expr */
126533 {
126534 sqlite3ExprDelete(pParse->db, (yypminor->yy346).pExpr);
126535 }
126536 break;
126537 case 179: /* eidlist_opt */
126538 case 188: /* sortlist */
126539 case 189: /* eidlist */
126540 case 201: /* selcollist */
126541 case 204: /* groupby_opt */
126542 case 206: /* orderby_opt */
126543 case 209: /* nexprlist */
126544 case 210: /* exprlist */
126545 case 211: /* sclp */
126546 case 221: /* setlist */
126547 case 228: /* case_exprlist */
126548 {
126549 sqlite3ExprListDelete(pParse->db, (yypminor->yy14));
126550 }
126551 break;
126552 case 195: /* fullname */
126553 case 202: /* from */
126554 case 213: /* seltablist */
126555 case 214: /* stl_prefix */
126556 {
126557 sqlite3SrcListDelete(pParse->db, (yypminor->yy65));
126558 }
126559 break;
126560 case 198: /* with */
126561 case 252: /* wqlist */
126562 {
126563 sqlite3WithDelete(pParse->db, (yypminor->yy59));
126564 }
126565 break;
126566 case 203: /* where_opt */
126567 case 205: /* having_opt */
126568 case 217: /* on_opt */
126569 case 227: /* case_operand */
126570 case 229: /* case_else */
126571 case 238: /* when_clause */
126572 case 243: /* key_opt */
126573 {
126574 sqlite3ExprDelete(pParse->db, (yypminor->yy132));
126575 }
126576 break;
126577 case 218: /* using_opt */
126578 case 220: /* idlist */
126579 case 223: /* idlist_opt */
126580 {
126581 sqlite3IdListDelete(pParse->db, (yypminor->yy408));
126582 }
126583 break;
126584 case 234: /* trigger_cmd_list */
@@ -126218,14 +126674,14 @@
126674 YYCODETYPE iLookAhead /* The look-ahead token */
126675 ){
126676 int i;
126677 int stateno = pParser->yystack[pParser->yyidx].stateno;
126678
126679 if( stateno>=YY_MIN_REDUCE ) return stateno;
126680 assert( stateno <= YY_SHIFT_COUNT );
126681 i = yy_shift_ofst[stateno];
126682 if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
126683 assert( iLookAhead!=YYNOCODE );
126684 i += iLookAhead;
126685 if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
126686 if( iLookAhead>0 ){
126687 #ifdef YYFALLBACK
@@ -126324,11 +126780,33 @@
126780 sqlite3ErrorMsg(pParse, "parser stack overflow");
126781 sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument var */
126782 }
126783
126784 /*
126785 ** Print tracing information for a SHIFT action
126786 */
126787 #ifndef NDEBUG
126788 static void yyTraceShift(yyParser *yypParser, int yyNewState){
126789 if( yyTraceFILE ){
126790 int i;
126791 if( yyNewState<YYNSTATE ){
126792 fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
126793 fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
126794 for(i=1; i<=yypParser->yyidx; i++)
126795 fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
126796 fprintf(yyTraceFILE,"\n");
126797 }else{
126798 fprintf(yyTraceFILE,"%sShift *\n",yyTracePrompt);
126799 }
126800 }
126801 }
126802 #else
126803 # define yyTraceShift(X,Y)
126804 #endif
126805
126806 /*
126807 ** Perform a shift action. Return the number of errors.
126808 */
126809 static void yy_shift(
126810 yyParser *yypParser, /* The parser to be shifted */
126811 int yyNewState, /* The new state to shift in */
126812 int yyMajor, /* The major token to shift in */
@@ -126357,20 +126835,11 @@
126835 #endif
126836 yytos = &yypParser->yystack[yypParser->yyidx];
126837 yytos->stateno = (YYACTIONTYPE)yyNewState;
126838 yytos->major = (YYCODETYPE)yyMajor;
126839 yytos->minor = *yypMinor;
126840 yyTraceShift(yypParser, yyNewState);
 
 
 
 
 
 
 
 
 
126841 }
126842
126843 /* The following table contains information about every rule that
126844 ** is used during the reduce.
126845 */
@@ -126473,96 +126942,97 @@
126942 { 187, 2 },
126943 { 187, 7 },
126944 { 187, 5 },
126945 { 187, 5 },
126946 { 187, 10 },
126947 { 190, 0 },
126948 { 190, 1 },
126949 { 176, 0 },
126950 { 176, 3 },
126951 { 191, 0 },
126952 { 191, 2 },
126953 { 192, 1 },
126954 { 192, 1 },
126955 { 192, 1 },
126956 { 149, 4 },
126957 { 194, 2 },
126958 { 194, 0 },
126959 { 149, 9 },
126960 { 149, 4 },
126961 { 149, 1 },
126962 { 163, 2 },
126963 { 196, 1 },
126964 { 196, 3 },
126965 { 199, 1 },
126966 { 199, 2 },
126967 { 199, 1 },
126968 { 197, 9 },
126969 { 197, 1 },
126970 { 208, 4 },
126971 { 208, 5 },
126972 { 200, 1 },
126973 { 200, 1 },
126974 { 200, 0 },
126975 { 211, 2 },
126976 { 211, 0 },
126977 { 201, 3 },
126978 { 201, 2 },
126979 { 201, 4 },
126980 { 212, 2 },
126981 { 212, 1 },
126982 { 212, 0 },
126983 { 202, 0 },
126984 { 202, 2 },
126985 { 214, 2 },
126986 { 214, 0 },
126987 { 213, 7 },
126988 { 213, 9 },
126989 { 213, 7 },
126990 { 213, 7 },
126991 { 159, 0 },
126992 { 159, 2 },
126993 { 195, 2 },
126994 { 215, 1 },
126995 { 215, 2 },
126996 { 215, 3 },
126997 { 215, 4 },
126998 { 217, 2 },
126999 { 217, 0 },
127000 { 216, 0 },
127001 { 216, 3 },
127002 { 216, 2 },
127003 { 218, 4 },
127004 { 218, 0 },
127005 { 206, 0 },
127006 { 206, 3 },
127007 { 188, 4 },
127008 { 188, 2 },
 
127009 { 177, 1 },
127010 { 177, 1 },
127011 { 177, 0 },
 
 
127012 { 204, 0 },
127013 { 204, 3 },
127014 { 205, 0 },
127015 { 205, 2 },
127016 { 207, 0 },
127017 { 207, 2 },
127018 { 207, 4 },
127019 { 207, 4 },
127020 { 149, 6 },
127021 { 203, 0 },
127022 { 203, 2 },
127023 { 149, 8 },
127024 { 221, 5 },
127025 { 221, 3 },
127026 { 149, 6 },
127027 { 149, 7 },
127028 { 222, 2 },
127029 { 222, 1 },
127030 { 223, 0 },
127031 { 223, 3 },
127032 { 220, 3 },
127033 { 220, 1 },
127034 { 175, 1 },
127035 { 175, 3 },
127036 { 174, 1 },
127037 { 175, 1 },
127038 { 175, 1 },
@@ -126611,21 +127081,21 @@
127081 { 228, 4 },
127082 { 229, 2 },
127083 { 229, 0 },
127084 { 227, 1 },
127085 { 227, 0 },
127086 { 210, 1 },
127087 { 210, 0 },
127088 { 209, 3 },
127089 { 209, 1 },
 
 
 
127090 { 149, 12 },
127091 { 230, 1 },
127092 { 230, 0 },
127093 { 179, 0 },
127094 { 179, 3 },
127095 { 189, 5 },
127096 { 189, 3 },
127097 { 231, 0 },
127098 { 231, 2 },
127099 { 149, 4 },
127100 { 149, 1 },
127101 { 149, 2 },
@@ -126666,13 +127136,13 @@
127136 { 239, 5 },
127137 { 239, 5 },
127138 { 239, 1 },
127139 { 175, 4 },
127140 { 175, 6 },
127141 { 193, 1 },
127142 { 193, 1 },
127143 { 193, 1 },
127144 { 149, 4 },
127145 { 149, 6 },
127146 { 149, 3 },
127147 { 243, 0 },
127148 { 243, 2 },
@@ -126698,13 +127168,13 @@
127168 { 249, 3 },
127169 { 250, 1 },
127170 { 251, 0 },
127171 { 251, 4 },
127172 { 251, 2 },
127173 { 198, 0 },
127174 { 198, 2 },
127175 { 198, 3 },
127176 { 252, 6 },
127177 { 252, 8 },
127178 };
127179
127180 static void yy_accept(yyParser*); /* Forward Declaration */
@@ -126725,12 +127195,13 @@
127195 sqlite3ParserARG_FETCH;
127196 yymsp = &yypParser->yystack[yypParser->yyidx];
127197 #ifndef NDEBUG
127198 if( yyTraceFILE && yyruleno>=0
127199 && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
127200 yysize = yyRuleInfo[yyruleno].nrhs;
127201 fprintf(yyTraceFILE, "%sReduce [%s] -> state %d.\n", yyTracePrompt,
127202 yyRuleName[yyruleno], yymsp[-yysize].stateno);
127203 }
127204 #endif /* NDEBUG */
127205
127206 /* Silence complaints from purify about yygotominor being uninitialized
127207 ** in some cases when it is copied into the stack after the following
@@ -126823,21 +127294,23 @@
127294 case 81: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */ yytestcase(yyruleno==81);
127295 case 83: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==83);
127296 case 85: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ yytestcase(yyruleno==85);
127297 case 97: /* defer_subclause_opt ::= */ yytestcase(yyruleno==97);
127298 case 108: /* ifexists ::= */ yytestcase(yyruleno==108);
127299 case 219: /* between_op ::= BETWEEN */ yytestcase(yyruleno==219);
127300 case 222: /* in_op ::= IN */ yytestcase(yyruleno==222);
127301 case 247: /* collate ::= */ yytestcase(yyruleno==247);
127302 {yygotominor.yy328 = 0;}
127303 break;
127304 case 29: /* ifnotexists ::= IF NOT EXISTS */
127305 case 30: /* temp ::= TEMP */ yytestcase(yyruleno==30);
127306 case 69: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==69);
127307 case 84: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ yytestcase(yyruleno==84);
127308 case 107: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==107);
127309 case 220: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==220);
127310 case 223: /* in_op ::= NOT IN */ yytestcase(yyruleno==223);
127311 case 248: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==248);
127312 {yygotominor.yy328 = 1;}
127313 break;
127314 case 32: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
127315 {
127316 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy186,0);
@@ -126880,22 +127353,21 @@
127353 case 42: /* nm ::= JOIN_KW */ yytestcase(yyruleno==42);
127354 case 45: /* typetoken ::= typename */ yytestcase(yyruleno==45);
127355 case 48: /* typename ::= ID|STRING */ yytestcase(yyruleno==48);
127356 case 130: /* as ::= AS nm */ yytestcase(yyruleno==130);
127357 case 131: /* as ::= ID|STRING */ yytestcase(yyruleno==131);
127358 case 142: /* dbnm ::= DOT nm */ yytestcase(yyruleno==142);
127359 case 151: /* indexed_opt ::= INDEXED BY nm */ yytestcase(yyruleno==151);
127360 case 257: /* nmnum ::= plus_num */ yytestcase(yyruleno==257);
127361 case 258: /* nmnum ::= nm */ yytestcase(yyruleno==258);
127362 case 259: /* nmnum ::= ON */ yytestcase(yyruleno==259);
127363 case 260: /* nmnum ::= DELETE */ yytestcase(yyruleno==260);
127364 case 261: /* nmnum ::= DEFAULT */ yytestcase(yyruleno==261);
127365 case 262: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==262);
127366 case 263: /* plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==263);
127367 case 264: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==264);
127368 case 280: /* trnm ::= nm */ yytestcase(yyruleno==280);
 
127369 {yygotominor.yy0 = yymsp[0].minor.yy0;}
127370 break;
127371 case 44: /* type ::= typetoken */
127372 {sqlite3AddColumnType(pParse,&yymsp[0].minor.yy0);}
127373 break;
@@ -126951,11 +127423,11 @@
127423 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy328,0,0,0,0);}
127424 break;
127425 case 64: /* ccons ::= CHECK LP expr RP */
127426 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy346.pExpr);}
127427 break;
127428 case 65: /* ccons ::= REFERENCES nm eidlist_opt refargs */
127429 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy14,yymsp[0].minor.yy328);}
127430 break;
127431 case 66: /* ccons ::= defer_subclause */
127432 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy328);}
127433 break;
@@ -127006,20 +127478,20 @@
127478 {yygotominor.yy0 = yymsp[-1].minor.yy0;}
127479 break;
127480 case 90: /* tconscomma ::= COMMA */
127481 {pParse->constraintName.n = 0;}
127482 break;
127483 case 93: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
127484 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy14,yymsp[0].minor.yy328,yymsp[-2].minor.yy328,0);}
127485 break;
127486 case 94: /* tcons ::= UNIQUE LP sortlist RP onconf */
127487 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy14,yymsp[0].minor.yy328,0,0,0,0);}
127488 break;
127489 case 95: /* tcons ::= CHECK LP expr RP onconf */
127490 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy346.pExpr);}
127491 break;
127492 case 96: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
127493 {
127494 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy14, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[-1].minor.yy328);
127495 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy328);
127496 }
127497 break;
@@ -127041,13 +127513,13 @@
127513 case 106: /* cmd ::= DROP TABLE ifexists fullname */
127514 {
127515 sqlite3DropTable(pParse, yymsp[0].minor.yy65, 0, yymsp[-1].minor.yy328);
127516 }
127517 break;
127518 case 109: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
127519 {
127520 sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy14, yymsp[0].minor.yy3, yymsp[-7].minor.yy328, yymsp[-5].minor.yy328);
127521 }
127522 break;
127523 case 110: /* cmd ::= DROP VIEW ifexists fullname */
127524 {
127525 sqlite3DropTable(pParse, yymsp[0].minor.yy65, 1, yymsp[-1].minor.yy328);
@@ -127160,18 +127632,18 @@
127632 break;
127633 case 124: /* distinct ::= */
127634 {yygotominor.yy381 = 0;}
127635 break;
127636 case 125: /* sclp ::= selcollist COMMA */
127637 case 244: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==244);
127638 {yygotominor.yy14 = yymsp[-1].minor.yy14;}
127639 break;
127640 case 126: /* sclp ::= */
127641 case 155: /* orderby_opt ::= */ yytestcase(yyruleno==155);
127642 case 162: /* groupby_opt ::= */ yytestcase(yyruleno==162);
127643 case 237: /* exprlist ::= */ yytestcase(yyruleno==237);
127644 case 243: /* eidlist_opt ::= */ yytestcase(yyruleno==243);
127645 {yygotominor.yy14 = 0;}
127646 break;
127647 case 127: /* selcollist ::= sclp expr as */
127648 {
127649 yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy14, yymsp[-1].minor.yy346.pExpr);
@@ -127206,11 +127678,11 @@
127678 }
127679 break;
127680 case 135: /* stl_prefix ::= seltablist joinop */
127681 {
127682 yygotominor.yy65 = yymsp[-1].minor.yy65;
127683 if( ALWAYS(yygotominor.yy65 && yygotominor.yy65->nSrc>0) ) yygotominor.yy65->a[yygotominor.yy65->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy328;
127684 }
127685 break;
127686 case 136: /* stl_prefix ::= */
127687 {yygotominor.yy65 = 0;}
127688 break;
@@ -127218,16 +127690,22 @@
127690 {
127691 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127692 sqlite3SrcListIndexedBy(pParse, yygotominor.yy65, &yymsp[-2].minor.yy0);
127693 }
127694 break;
127695 case 138: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
127696 {
127697 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy65,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127698 sqlite3SrcListFuncArgs(pParse, yygotominor.yy65, yymsp[-4].minor.yy14);
127699 }
127700 break;
127701 case 139: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
127702 {
127703 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy3,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127704 }
127705 break;
127706 case 140: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
127707 {
127708 if( yymsp[-6].minor.yy65==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy132==0 && yymsp[0].minor.yy408==0 ){
127709 yygotominor.yy65 = yymsp[-4].minor.yy65;
127710 }else if( yymsp[-4].minor.yy65->nSrc==1 ){
127711 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
@@ -127247,175 +127725,177 @@
127725 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy65,0,0,0,0,SF_NestedFrom,0,0);
127726 yygotominor.yy65 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy65,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy132,yymsp[0].minor.yy408);
127727 }
127728 }
127729 break;
127730 case 141: /* dbnm ::= */
127731 case 150: /* indexed_opt ::= */ yytestcase(yyruleno==150);
127732 {yygotominor.yy0.z=0; yygotominor.yy0.n=0;}
127733 break;
127734 case 143: /* fullname ::= nm dbnm */
127735 {yygotominor.yy65 = sqlite3SrcListAppend(pParse->db,0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);}
127736 break;
127737 case 144: /* joinop ::= COMMA|JOIN */
127738 { yygotominor.yy328 = JT_INNER; }
127739 break;
127740 case 145: /* joinop ::= JOIN_KW JOIN */
127741 { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
127742 break;
127743 case 146: /* joinop ::= JOIN_KW nm JOIN */
127744 { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); }
127745 break;
127746 case 147: /* joinop ::= JOIN_KW nm nm JOIN */
127747 { yygotominor.yy328 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); }
127748 break;
127749 case 148: /* on_opt ::= ON expr */
127750 case 165: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==165);
127751 case 172: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==172);
127752 case 232: /* case_else ::= ELSE expr */ yytestcase(yyruleno==232);
127753 case 234: /* case_operand ::= expr */ yytestcase(yyruleno==234);
127754 {yygotominor.yy132 = yymsp[0].minor.yy346.pExpr;}
127755 break;
127756 case 149: /* on_opt ::= */
127757 case 164: /* having_opt ::= */ yytestcase(yyruleno==164);
127758 case 171: /* where_opt ::= */ yytestcase(yyruleno==171);
127759 case 233: /* case_else ::= */ yytestcase(yyruleno==233);
127760 case 235: /* case_operand ::= */ yytestcase(yyruleno==235);
127761 {yygotominor.yy132 = 0;}
127762 break;
127763 case 152: /* indexed_opt ::= NOT INDEXED */
127764 {yygotominor.yy0.z=0; yygotominor.yy0.n=1;}
127765 break;
127766 case 153: /* using_opt ::= USING LP idlist RP */
127767 case 181: /* idlist_opt ::= LP idlist RP */ yytestcase(yyruleno==181);
127768 {yygotominor.yy408 = yymsp[-1].minor.yy408;}
127769 break;
127770 case 154: /* using_opt ::= */
127771 case 180: /* idlist_opt ::= */ yytestcase(yyruleno==180);
127772 {yygotominor.yy408 = 0;}
127773 break;
127774 case 156: /* orderby_opt ::= ORDER BY sortlist */
127775 case 163: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==163);
127776 case 236: /* exprlist ::= nexprlist */ yytestcase(yyruleno==236);
127777 {yygotominor.yy14 = yymsp[0].minor.yy14;}
127778 break;
127779 case 157: /* sortlist ::= sortlist COMMA expr sortorder */
127780 {
127781 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy14,yymsp[-1].minor.yy346.pExpr);
127782 sqlite3ExprListSetSortOrder(yygotominor.yy14,yymsp[0].minor.yy328);
127783 }
127784 break;
127785 case 158: /* sortlist ::= expr sortorder */
127786 {
127787 yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy346.pExpr);
127788 sqlite3ExprListSetSortOrder(yygotominor.yy14,yymsp[0].minor.yy328);
127789 }
127790 break;
127791 case 159: /* sortorder ::= ASC */
 
127792 {yygotominor.yy328 = SQLITE_SO_ASC;}
127793 break;
127794 case 160: /* sortorder ::= DESC */
127795 {yygotominor.yy328 = SQLITE_SO_DESC;}
127796 break;
127797 case 161: /* sortorder ::= */
127798 {yygotominor.yy328 = SQLITE_SO_UNDEFINED;}
127799 break;
127800 case 166: /* limit_opt ::= */
127801 {yygotominor.yy476.pLimit = 0; yygotominor.yy476.pOffset = 0;}
127802 break;
127803 case 167: /* limit_opt ::= LIMIT expr */
127804 {yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr; yygotominor.yy476.pOffset = 0;}
127805 break;
127806 case 168: /* limit_opt ::= LIMIT expr OFFSET expr */
127807 {yygotominor.yy476.pLimit = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pOffset = yymsp[0].minor.yy346.pExpr;}
127808 break;
127809 case 169: /* limit_opt ::= LIMIT expr COMMA expr */
127810 {yygotominor.yy476.pOffset = yymsp[-2].minor.yy346.pExpr; yygotominor.yy476.pLimit = yymsp[0].minor.yy346.pExpr;}
127811 break;
127812 case 170: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */
127813 {
127814 sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
127815 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy65, &yymsp[-1].minor.yy0);
127816 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy65,yymsp[0].minor.yy132);
127817 }
127818 break;
127819 case 173: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */
127820 {
127821 sqlite3WithPush(pParse, yymsp[-7].minor.yy59, 1);
127822 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy65, &yymsp[-3].minor.yy0);
127823 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy14,"set list");
127824 sqlite3Update(pParse,yymsp[-4].minor.yy65,yymsp[-1].minor.yy14,yymsp[0].minor.yy132,yymsp[-5].minor.yy186);
127825 }
127826 break;
127827 case 174: /* setlist ::= setlist COMMA nm EQ expr */
127828 {
127829 yygotominor.yy14 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy14, yymsp[0].minor.yy346.pExpr);
127830 sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127831 }
127832 break;
127833 case 175: /* setlist ::= nm EQ expr */
127834 {
127835 yygotominor.yy14 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy346.pExpr);
127836 sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
127837 }
127838 break;
127839 case 176: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */
127840 {
127841 sqlite3WithPush(pParse, yymsp[-5].minor.yy59, 1);
127842 sqlite3Insert(pParse, yymsp[-2].minor.yy65, yymsp[0].minor.yy3, yymsp[-1].minor.yy408, yymsp[-4].minor.yy186);
127843 }
127844 break;
127845 case 177: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */
127846 {
127847 sqlite3WithPush(pParse, yymsp[-6].minor.yy59, 1);
127848 sqlite3Insert(pParse, yymsp[-3].minor.yy65, 0, yymsp[-2].minor.yy408, yymsp[-5].minor.yy186);
127849 }
127850 break;
127851 case 178: /* insert_cmd ::= INSERT orconf */
127852 {yygotominor.yy186 = yymsp[0].minor.yy186;}
127853 break;
127854 case 179: /* insert_cmd ::= REPLACE */
127855 {yygotominor.yy186 = OE_Replace;}
127856 break;
127857 case 182: /* idlist ::= idlist COMMA nm */
127858 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy408,&yymsp[0].minor.yy0);}
127859 break;
127860 case 183: /* idlist ::= nm */
127861 {yygotominor.yy408 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0);}
127862 break;
127863 case 184: /* expr ::= term */
127864 {yygotominor.yy346 = yymsp[0].minor.yy346;}
127865 break;
127866 case 185: /* expr ::= LP expr RP */
127867 {yygotominor.yy346.pExpr = yymsp[-1].minor.yy346.pExpr; spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);}
127868 break;
127869 case 186: /* term ::= NULL */
127870 case 191: /* term ::= INTEGER|FLOAT|BLOB */ yytestcase(yyruleno==191);
127871 case 192: /* term ::= STRING */ yytestcase(yyruleno==192);
127872 {spanExpr(&yygotominor.yy346, pParse, yymsp[0].major, &yymsp[0].minor.yy0);}
127873 break;
127874 case 187: /* expr ::= ID|INDEXED */
127875 case 188: /* expr ::= JOIN_KW */ yytestcase(yyruleno==188);
127876 {spanExpr(&yygotominor.yy346, pParse, TK_ID, &yymsp[0].minor.yy0);}
127877 break;
127878 case 189: /* expr ::= nm DOT nm */
127879 {
127880 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
127881 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
127882 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
127883 spanSet(&yygotominor.yy346,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
127884 }
127885 break;
127886 case 190: /* expr ::= nm DOT nm DOT nm */
127887 {
127888 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-4].minor.yy0);
127889 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0);
127890 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[0].minor.yy0);
127891 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
127892 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
127893 spanSet(&yygotominor.yy346,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0);
127894 }
127895 break;
127896 case 193: /* expr ::= VARIABLE */
127897 {
127898 if( yymsp[0].minor.yy0.n>=2 && yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1]) ){
127899 /* When doing a nested parse, one can include terms in an expression
127900 ** that look like this: #1 #2 ... These terms refer to registers
127901 ** in the virtual machine. #N is the N-th register. */
@@ -127431,24 +127911,24 @@
127911 sqlite3ExprAssignVarNumber(pParse, yygotominor.yy346.pExpr);
127912 }
127913 spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
127914 }
127915 break;
127916 case 194: /* expr ::= expr COLLATE ID|STRING */
127917 {
127918 yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0, 1);
127919 yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
127920 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
127921 }
127922 break;
127923 case 195: /* expr ::= CAST LP expr AS typetoken RP */
127924 {
127925 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy346.pExpr, 0, &yymsp[-1].minor.yy0);
127926 spanSet(&yygotominor.yy346,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0);
127927 }
127928 break;
127929 case 196: /* expr ::= ID|INDEXED LP distinct exprlist RP */
127930 {
127931 if( yymsp[-1].minor.yy14 && yymsp[-1].minor.yy14->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
127932 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0);
127933 }
127934 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy14, &yymsp[-4].minor.yy0);
@@ -127456,39 +127936,39 @@
127936 if( yymsp[-2].minor.yy381==SF_Distinct && yygotominor.yy346.pExpr ){
127937 yygotominor.yy346.pExpr->flags |= EP_Distinct;
127938 }
127939 }
127940 break;
127941 case 197: /* expr ::= ID|INDEXED LP STAR RP */
127942 {
127943 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0);
127944 spanSet(&yygotominor.yy346,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
127945 }
127946 break;
127947 case 198: /* term ::= CTIME_KW */
127948 {
127949 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
127950 spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
127951 }
127952 break;
127953 case 199: /* expr ::= expr AND expr */
127954 case 200: /* expr ::= expr OR expr */ yytestcase(yyruleno==200);
127955 case 201: /* expr ::= expr LT|GT|GE|LE expr */ yytestcase(yyruleno==201);
127956 case 202: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==202);
127957 case 203: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==203);
127958 case 204: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==204);
127959 case 205: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==205);
127960 case 206: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==206);
127961 {spanBinaryExpr(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);}
127962 break;
127963 case 207: /* likeop ::= LIKE_KW|MATCH */
127964 {yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 0;}
127965 break;
127966 case 208: /* likeop ::= NOT LIKE_KW|MATCH */
127967 {yygotominor.yy96.eOperator = yymsp[0].minor.yy0; yygotominor.yy96.bNot = 1;}
127968 break;
127969 case 209: /* expr ::= expr likeop expr */
127970 {
127971 ExprList *pList;
127972 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy346.pExpr);
127973 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy346.pExpr);
127974 yygotominor.yy346.pExpr = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy96.eOperator);
@@ -127496,11 +127976,11 @@
127976 yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
127977 yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127978 if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
127979 }
127980 break;
127981 case 210: /* expr ::= expr likeop expr ESCAPE expr */
127982 {
127983 ExprList *pList;
127984 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
127985 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy346.pExpr);
127986 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
@@ -127509,39 +127989,39 @@
127989 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
127990 yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
127991 if( yygotominor.yy346.pExpr ) yygotominor.yy346.pExpr->flags |= EP_InfixFunc;
127992 }
127993 break;
127994 case 211: /* expr ::= expr ISNULL|NOTNULL */
127995 {spanUnaryPostfix(&yygotominor.yy346,pParse,yymsp[0].major,&yymsp[-1].minor.yy346,&yymsp[0].minor.yy0);}
127996 break;
127997 case 212: /* expr ::= expr NOT NULL */
127998 {spanUnaryPostfix(&yygotominor.yy346,pParse,TK_NOTNULL,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy0);}
127999 break;
128000 case 213: /* expr ::= expr IS expr */
128001 {
128002 spanBinaryExpr(&yygotominor.yy346,pParse,TK_IS,&yymsp[-2].minor.yy346,&yymsp[0].minor.yy346);
128003 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_ISNULL);
128004 }
128005 break;
128006 case 214: /* expr ::= expr IS NOT expr */
128007 {
128008 spanBinaryExpr(&yygotominor.yy346,pParse,TK_ISNOT,&yymsp[-3].minor.yy346,&yymsp[0].minor.yy346);
128009 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy346.pExpr, yygotominor.yy346.pExpr, TK_NOTNULL);
128010 }
128011 break;
128012 case 215: /* expr ::= NOT expr */
128013 case 216: /* expr ::= BITNOT expr */ yytestcase(yyruleno==216);
128014 {spanUnaryPrefix(&yygotominor.yy346,pParse,yymsp[-1].major,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
128015 break;
128016 case 217: /* expr ::= MINUS expr */
128017 {spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UMINUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
128018 break;
128019 case 218: /* expr ::= PLUS expr */
128020 {spanUnaryPrefix(&yygotominor.yy346,pParse,TK_UPLUS,&yymsp[0].minor.yy346,&yymsp[-1].minor.yy0);}
128021 break;
128022 case 221: /* expr ::= expr between_op expr AND expr */
128023 {
128024 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
128025 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy346.pExpr);
128026 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy346.pExpr, 0, 0);
128027 if( yygotominor.yy346.pExpr ){
@@ -127552,11 +128032,11 @@
128032 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
128033 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
128034 yygotominor.yy346.zEnd = yymsp[0].minor.yy346.zEnd;
128035 }
128036 break;
128037 case 224: /* expr ::= expr in_op LP exprlist RP */
128038 {
128039 if( yymsp[-1].minor.yy14==0 ){
128040 /* Expressions of the form
128041 **
128042 ** expr1 IN ()
@@ -127606,11 +128086,11 @@
128086 }
128087 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
128088 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
128089 }
128090 break;
128091 case 225: /* expr ::= LP select RP */
128092 {
128093 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
128094 if( yygotominor.yy346.pExpr ){
128095 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
128096 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
@@ -127620,11 +128100,11 @@
128100 }
128101 yygotominor.yy346.zStart = yymsp[-2].minor.yy0.z;
128102 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
128103 }
128104 break;
128105 case 226: /* expr ::= expr in_op LP select RP */
128106 {
128107 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy346.pExpr, 0, 0);
128108 if( yygotominor.yy346.pExpr ){
128109 yygotominor.yy346.pExpr->x.pSelect = yymsp[-1].minor.yy3;
128110 ExprSetProperty(yygotominor.yy346.pExpr, EP_xIsSelect|EP_Subquery);
@@ -127635,11 +128115,11 @@
128115 if( yymsp[-3].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
128116 yygotominor.yy346.zStart = yymsp[-4].minor.yy346.zStart;
128117 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
128118 }
128119 break;
128120 case 227: /* expr ::= expr in_op nm dbnm */
128121 {
128122 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
128123 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy346.pExpr, 0, 0);
128124 if( yygotominor.yy346.pExpr ){
128125 yygotominor.yy346.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
@@ -127651,11 +128131,11 @@
128131 if( yymsp[-2].minor.yy328 ) yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_NOT, yygotominor.yy346.pExpr, 0, 0);
128132 yygotominor.yy346.zStart = yymsp[-3].minor.yy346.zStart;
128133 yygotominor.yy346.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
128134 }
128135 break;
128136 case 228: /* expr ::= EXISTS LP select RP */
128137 {
128138 Expr *p = yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
128139 if( p ){
128140 p->x.pSelect = yymsp[-1].minor.yy3;
128141 ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
@@ -127665,11 +128145,11 @@
128145 }
128146 yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
128147 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
128148 }
128149 break;
128150 case 229: /* expr ::= CASE case_operand case_exprlist case_else END */
128151 {
128152 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy132, 0, 0);
128153 if( yygotominor.yy346.pExpr ){
128154 yygotominor.yy346.pExpr->x.pList = yymsp[-1].minor.yy132 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[-1].minor.yy132) : yymsp[-2].minor.yy14;
128155 sqlite3ExprSetHeightAndFlags(pParse, yygotominor.yy346.pExpr);
@@ -127679,274 +128159,263 @@
128159 }
128160 yygotominor.yy346.zStart = yymsp[-4].minor.yy0.z;
128161 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
128162 }
128163 break;
128164 case 230: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
128165 {
128166 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, yymsp[-2].minor.yy346.pExpr);
128167 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
128168 }
128169 break;
128170 case 231: /* case_exprlist ::= WHEN expr THEN expr */
128171 {
128172 yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy346.pExpr);
128173 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yygotominor.yy14, yymsp[0].minor.yy346.pExpr);
128174 }
128175 break;
128176 case 238: /* nexprlist ::= nexprlist COMMA expr */
128177 {yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy14,yymsp[0].minor.yy346.pExpr);}
128178 break;
128179 case 239: /* nexprlist ::= expr */
128180 {yygotominor.yy14 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy346.pExpr);}
128181 break;
128182 case 240: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
128183 {
128184 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
128185 sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy14, yymsp[-10].minor.yy328,
128186 &yymsp[-11].minor.yy0, yymsp[0].minor.yy132, SQLITE_SO_ASC, yymsp[-8].minor.yy328);
128187 }
128188 break;
128189 case 241: /* uniqueflag ::= UNIQUE */
128190 case 292: /* raisetype ::= ABORT */ yytestcase(yyruleno==292);
128191 {yygotominor.yy328 = OE_Abort;}
128192 break;
128193 case 242: /* uniqueflag ::= */
128194 {yygotominor.yy328 = OE_None;}
128195 break;
128196 case 245: /* eidlist ::= eidlist COMMA nm collate sortorder */
128197 {
128198 yygotominor.yy14 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy14, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy328, yymsp[0].minor.yy328);
128199 }
128200 break;
128201 case 246: /* eidlist ::= nm collate sortorder */
128202 {
128203 yygotominor.yy14 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy328, yymsp[0].minor.yy328);
128204 }
128205 break;
128206 case 249: /* cmd ::= DROP INDEX ifexists fullname */
 
 
 
 
 
 
 
 
 
 
 
128207 {sqlite3DropIndex(pParse, yymsp[0].minor.yy65, yymsp[-1].minor.yy328);}
128208 break;
128209 case 250: /* cmd ::= VACUUM */
128210 case 251: /* cmd ::= VACUUM nm */ yytestcase(yyruleno==251);
128211 {sqlite3Vacuum(pParse);}
128212 break;
128213 case 252: /* cmd ::= PRAGMA nm dbnm */
128214 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
128215 break;
128216 case 253: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
128217 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
128218 break;
128219 case 254: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
128220 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
128221 break;
128222 case 255: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
128223 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
128224 break;
128225 case 256: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
128226 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
128227 break;
128228 case 265: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
128229 {
128230 Token all;
128231 all.z = yymsp[-3].minor.yy0.z;
128232 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
128233 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy473, &all);
128234 }
128235 break;
128236 case 266: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
128237 {
128238 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy328, yymsp[-4].minor.yy378.a, yymsp[-4].minor.yy378.b, yymsp[-2].minor.yy65, yymsp[0].minor.yy132, yymsp[-10].minor.yy328, yymsp[-8].minor.yy328);
128239 yygotominor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0);
128240 }
128241 break;
128242 case 267: /* trigger_time ::= BEFORE */
128243 case 270: /* trigger_time ::= */ yytestcase(yyruleno==270);
128244 { yygotominor.yy328 = TK_BEFORE; }
128245 break;
128246 case 268: /* trigger_time ::= AFTER */
128247 { yygotominor.yy328 = TK_AFTER; }
128248 break;
128249 case 269: /* trigger_time ::= INSTEAD OF */
128250 { yygotominor.yy328 = TK_INSTEAD;}
128251 break;
128252 case 271: /* trigger_event ::= DELETE|INSERT */
128253 case 272: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==272);
128254 {yygotominor.yy378.a = yymsp[0].major; yygotominor.yy378.b = 0;}
128255 break;
128256 case 273: /* trigger_event ::= UPDATE OF idlist */
128257 {yygotominor.yy378.a = TK_UPDATE; yygotominor.yy378.b = yymsp[0].minor.yy408;}
128258 break;
128259 case 276: /* when_clause ::= */
128260 case 297: /* key_opt ::= */ yytestcase(yyruleno==297);
128261 { yygotominor.yy132 = 0; }
128262 break;
128263 case 277: /* when_clause ::= WHEN expr */
128264 case 298: /* key_opt ::= KEY expr */ yytestcase(yyruleno==298);
128265 { yygotominor.yy132 = yymsp[0].minor.yy346.pExpr; }
128266 break;
128267 case 278: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
128268 {
128269 assert( yymsp[-2].minor.yy473!=0 );
128270 yymsp[-2].minor.yy473->pLast->pNext = yymsp[-1].minor.yy473;
128271 yymsp[-2].minor.yy473->pLast = yymsp[-1].minor.yy473;
128272 yygotominor.yy473 = yymsp[-2].minor.yy473;
128273 }
128274 break;
128275 case 279: /* trigger_cmd_list ::= trigger_cmd SEMI */
128276 {
128277 assert( yymsp[-1].minor.yy473!=0 );
128278 yymsp[-1].minor.yy473->pLast = yymsp[-1].minor.yy473;
128279 yygotominor.yy473 = yymsp[-1].minor.yy473;
128280 }
128281 break;
128282 case 281: /* trnm ::= nm DOT nm */
128283 {
128284 yygotominor.yy0 = yymsp[0].minor.yy0;
128285 sqlite3ErrorMsg(pParse,
128286 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
128287 "statements within triggers");
128288 }
128289 break;
128290 case 283: /* tridxby ::= INDEXED BY nm */
128291 {
128292 sqlite3ErrorMsg(pParse,
128293 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
128294 "within triggers");
128295 }
128296 break;
128297 case 284: /* tridxby ::= NOT INDEXED */
128298 {
128299 sqlite3ErrorMsg(pParse,
128300 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
128301 "within triggers");
128302 }
128303 break;
128304 case 285: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */
128305 { yygotominor.yy473 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy14, yymsp[0].minor.yy132, yymsp[-5].minor.yy186); }
128306 break;
128307 case 286: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */
128308 {yygotominor.yy473 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy408, yymsp[0].minor.yy3, yymsp[-4].minor.yy186);}
128309 break;
128310 case 287: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */
128311 {yygotominor.yy473 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy132);}
128312 break;
128313 case 288: /* trigger_cmd ::= select */
128314 {yygotominor.yy473 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy3); }
128315 break;
128316 case 289: /* expr ::= RAISE LP IGNORE RP */
128317 {
128318 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
128319 if( yygotominor.yy346.pExpr ){
128320 yygotominor.yy346.pExpr->affinity = OE_Ignore;
128321 }
128322 yygotominor.yy346.zStart = yymsp[-3].minor.yy0.z;
128323 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
128324 }
128325 break;
128326 case 290: /* expr ::= RAISE LP raisetype COMMA nm RP */
128327 {
128328 yygotominor.yy346.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0);
128329 if( yygotominor.yy346.pExpr ) {
128330 yygotominor.yy346.pExpr->affinity = (char)yymsp[-3].minor.yy328;
128331 }
128332 yygotominor.yy346.zStart = yymsp[-5].minor.yy0.z;
128333 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
128334 }
128335 break;
128336 case 291: /* raisetype ::= ROLLBACK */
128337 {yygotominor.yy328 = OE_Rollback;}
128338 break;
128339 case 293: /* raisetype ::= FAIL */
128340 {yygotominor.yy328 = OE_Fail;}
128341 break;
128342 case 294: /* cmd ::= DROP TRIGGER ifexists fullname */
128343 {
128344 sqlite3DropTrigger(pParse,yymsp[0].minor.yy65,yymsp[-1].minor.yy328);
128345 }
128346 break;
128347 case 295: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
128348 {
128349 sqlite3Attach(pParse, yymsp[-3].minor.yy346.pExpr, yymsp[-1].minor.yy346.pExpr, yymsp[0].minor.yy132);
128350 }
128351 break;
128352 case 296: /* cmd ::= DETACH database_kw_opt expr */
128353 {
128354 sqlite3Detach(pParse, yymsp[0].minor.yy346.pExpr);
128355 }
128356 break;
128357 case 301: /* cmd ::= REINDEX */
128358 {sqlite3Reindex(pParse, 0, 0);}
128359 break;
128360 case 302: /* cmd ::= REINDEX nm dbnm */
128361 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
128362 break;
128363 case 303: /* cmd ::= ANALYZE */
128364 {sqlite3Analyze(pParse, 0, 0);}
128365 break;
128366 case 304: /* cmd ::= ANALYZE nm dbnm */
128367 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
128368 break;
128369 case 305: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
128370 {
128371 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy65,&yymsp[0].minor.yy0);
128372 }
128373 break;
128374 case 306: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column */
128375 {
128376 sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy0);
128377 }
128378 break;
128379 case 307: /* add_column_fullname ::= fullname */
128380 {
128381 pParse->db->lookaside.bEnabled = 0;
128382 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy65);
128383 }
128384 break;
128385 case 310: /* cmd ::= create_vtab */
128386 {sqlite3VtabFinishParse(pParse,0);}
128387 break;
128388 case 311: /* cmd ::= create_vtab LP vtabarglist RP */
128389 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
128390 break;
128391 case 312: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
128392 {
128393 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy328);
128394 }
128395 break;
128396 case 315: /* vtabarg ::= */
128397 {sqlite3VtabArgInit(pParse);}
128398 break;
128399 case 317: /* vtabargtoken ::= ANY */
128400 case 318: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==318);
128401 case 319: /* lp ::= LP */ yytestcase(yyruleno==319);
128402 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
128403 break;
128404 case 323: /* with ::= */
128405 {yygotominor.yy59 = 0;}
128406 break;
128407 case 324: /* with ::= WITH wqlist */
128408 case 325: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==325);
128409 { yygotominor.yy59 = yymsp[0].minor.yy59; }
128410 break;
128411 case 326: /* wqlist ::= nm eidlist_opt AS LP select RP */
128412 {
128413 yygotominor.yy59 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
128414 }
128415 break;
128416 case 327: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
128417 {
128418 yygotominor.yy59 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy59, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy14, yymsp[-1].minor.yy3);
128419 }
128420 break;
128421 default:
@@ -127970,49 +128439,48 @@
128439 /* (53) carglist ::= */ yytestcase(yyruleno==53);
128440 /* (60) ccons ::= NULL onconf */ yytestcase(yyruleno==60);
128441 /* (88) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==88);
128442 /* (89) conslist ::= tcons */ yytestcase(yyruleno==89);
128443 /* (91) tconscomma ::= */ yytestcase(yyruleno==91);
128444 /* (274) foreach_clause ::= */ yytestcase(yyruleno==274);
128445 /* (275) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==275);
128446 /* (282) tridxby ::= */ yytestcase(yyruleno==282);
128447 /* (299) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==299);
128448 /* (300) database_kw_opt ::= */ yytestcase(yyruleno==300);
128449 /* (308) kwcolumn_opt ::= */ yytestcase(yyruleno==308);
128450 /* (309) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==309);
128451 /* (313) vtabarglist ::= vtabarg */ yytestcase(yyruleno==313);
128452 /* (314) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==314);
128453 /* (316) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==316);
128454 /* (320) anylist ::= */ yytestcase(yyruleno==320);
128455 /* (321) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==321);
128456 /* (322) anylist ::= anylist ANY */ yytestcase(yyruleno==322);
128457 break;
128458 };
128459 assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
128460 yygoto = yyRuleInfo[yyruleno].lhs;
128461 yysize = yyRuleInfo[yyruleno].nrhs;
128462 yypParser->yyidx -= yysize;
128463 yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
128464 if( yyact <= YY_MAX_SHIFTREDUCE ){
128465 if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
128466 /* If the reduce action popped at least
128467 ** one element off the stack, then we can push the new element back
128468 ** onto the stack here, and skip the stack overflow test in yy_shift().
128469 ** That gives a significant speed improvement. */
128470 if( yysize ){
128471 yypParser->yyidx++;
128472 yymsp -= yysize-1;
128473 yymsp->stateno = (YYACTIONTYPE)yyact;
128474 yymsp->major = (YYCODETYPE)yygoto;
128475 yymsp->minor = yygotominor;
128476 yyTraceShift(yypParser, yyact);
128477 }else{
 
128478 yy_shift(yypParser,yyact,yygoto,&yygotominor);
128479 }
128480 }else{
128481 assert( yyact == YY_ACCEPT_ACTION );
128482 yy_accept(yypParser);
128483 }
128484 }
128485
128486 /*
@@ -128133,16 +128601,17 @@
128601 }
128602 #endif
128603
128604 do{
128605 yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
128606 if( yyact <= YY_MAX_SHIFTREDUCE ){
128607 if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
128608 yy_shift(yypParser,yyact,yymajor,&yyminorunion);
128609 yypParser->yyerrcnt--;
128610 yymajor = YYNOCODE;
128611 }else if( yyact <= YY_MAX_REDUCE ){
128612 yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
128613 }else{
128614 assert( yyact == YY_ERROR_ACTION );
128615 #ifdef YYERRORSYMBOL
128616 int yymx;
128617 #endif
@@ -128188,11 +128657,11 @@
128657 while(
128658 yypParser->yyidx >= 0 &&
128659 yymx != YYERRORSYMBOL &&
128660 (yyact = yy_find_reduce_action(
128661 yypParser->yystack[yypParser->yyidx].stateno,
128662 YYERRORSYMBOL)) >= YY_MIN_REDUCE
128663 ){
128664 yy_pop_parser_stack(yypParser);
128665 }
128666 if( yypParser->yyidx < 0 || yymajor==0 ){
128667 yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
@@ -128238,10 +128707,15 @@
128707 }
128708 yymajor = YYNOCODE;
128709 #endif
128710 }
128711 }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
128712 #ifndef NDEBUG
128713 if( yyTraceFILE ){
128714 fprintf(yyTraceFILE,"%sReturn\n",yyTracePrompt);
128715 }
128716 #endif
128717 return;
128718 }
128719
128720 /************** End of parse.c ***********************************************/
128721 /************** Begin file tokenize.c ****************************************/
@@ -128926,10 +129400,11 @@
129400 }
129401 pParse->rc = SQLITE_OK;
129402 pParse->zTail = zSql;
129403 i = 0;
129404 assert( pzErrMsg!=0 );
129405 /* sqlite3ParserTrace(stdout, "parser: "); */
129406 pEngine = sqlite3ParserAlloc(sqlite3Malloc);
129407 if( pEngine==0 ){
129408 db->mallocFailed = 1;
129409 return SQLITE_NOMEM;
129410 }
@@ -130370,20 +130845,26 @@
130845 ** db. This is called when db is being closed.
130846 */
130847 static void disconnectAllVtab(sqlite3 *db){
130848 #ifndef SQLITE_OMIT_VIRTUALTABLE
130849 int i;
130850 HashElem *p;
130851 sqlite3BtreeEnterAll(db);
130852 for(i=0; i<db->nDb; i++){
130853 Schema *pSchema = db->aDb[i].pSchema;
130854 if( db->aDb[i].pSchema ){
 
130855 for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
130856 Table *pTab = (Table *)sqliteHashData(p);
130857 if( IsVirtual(pTab) ) sqlite3VtabDisconnect(db, pTab);
130858 }
130859 }
130860 }
130861 for(p=sqliteHashFirst(&db->aModule); p; p=sqliteHashNext(p)){
130862 Module *pMod = (Module *)sqliteHashData(p);
130863 if( pMod->pEpoTab ){
130864 sqlite3VtabDisconnect(db, pMod->pEpoTab);
130865 }
130866 }
130867 sqlite3VtabUnlockList(db);
130868 sqlite3BtreeLeaveAll(db);
130869 #else
130870 UNUSED_PARAMETER(db);
@@ -130558,10 +131039,11 @@
131039 for(i=sqliteHashFirst(&db->aModule); i; i=sqliteHashNext(i)){
131040 Module *pMod = (Module *)sqliteHashData(i);
131041 if( pMod->xDestroy ){
131042 pMod->xDestroy(pMod->pAux);
131043 }
131044 sqlite3VtabEponymousTableClear(db, pMod);
131045 sqlite3DbFree(db, pMod);
131046 }
131047 sqlite3HashClear(&db->aModule);
131048 #endif
131049
@@ -156962,14 +157444,10 @@
157444
157445 /* #include <assert.h> */
157446 /* #include <string.h> */
157447 /* #include <stdio.h> */
157448
 
 
 
 
157449 /* #include "sqlite3.h" */
157450
157451 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
157452 /************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
157453 /************** Begin file sqlite3rbu.h **************************************/
@@ -157070,10 +157548,22 @@
157548 **
157549 ** CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
157550 **
157551 ** The order of the columns in the data_% table does not matter.
157552 **
157553 ** Instead of a regular table, the RBU database may also contain virtual
157554 ** tables or view named using the data_<target> naming scheme.
157555 **
157556 ** Instead of the plain data_<target> naming scheme, RBU database tables
157557 ** may also be named data<integer>_<target>, where <integer> is any sequence
157558 ** of zero or more numeric characters (0-9). This can be significant because
157559 ** tables within the RBU database are always processed in order sorted by
157560 ** name. By judicious selection of the the <integer> portion of the names
157561 ** of the RBU tables the user can therefore control the order in which they
157562 ** are processed. This can be useful, for example, to ensure that "external
157563 ** content" FTS4 tables are updated before their underlying content tables.
157564 **
157565 ** If the target database table is a virtual table or a table that has no
157566 ** PRIMARY KEY declaration, the data_% table must also contain a column
157567 ** named "rbu_rowid". This column is mapped to the tables implicit primary
157568 ** key column - "rowid". Virtual tables for which the "rowid" column does
157569 ** not function like a primary key value cannot be updated using RBU. For
@@ -157149,10 +157639,18 @@
157639 ** INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
157640 **
157641 ** is similar to an UPDATE statement such as:
157642 **
157643 ** UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
157644 **
157645 ** Finally, if an 'f' character appears in place of a 'd' or 's' in an
157646 ** ota_control string, the contents of the data_xxx table column is assumed
157647 ** to be a "fossil delta" - a patch to be applied to a blob value in the
157648 ** format used by the fossil source-code management system. In this case
157649 ** the existing value within the target database table must be of type BLOB.
157650 ** It is replaced by the result of applying the specified fossil delta to
157651 ** itself.
157652 **
157653 ** If the target database table is a virtual table or a table with no PRIMARY
157654 ** KEY, the rbu_control value should not include a character corresponding
157655 ** to the rbu_rowid value. For example, this:
157656 **
@@ -157307,10 +157805,22 @@
157805 ** SQLITE_OK, all subsequent calls on the same RBU handle are no-ops
157806 ** that immediately return the same value.
157807 */
157808 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *pRbu);
157809
157810 /*
157811 ** Force RBU to save its state to disk.
157812 **
157813 ** If a power failure or application crash occurs during an update, following
157814 ** system recovery RBU may resume the update from the point at which the state
157815 ** was last saved. In other words, from the most recent successful call to
157816 ** sqlite3rbu_close() or this function.
157817 **
157818 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
157819 */
157820 SQLITE_API int SQLITE_STDCALL sqlite3rbu_savestate(sqlite3rbu *pRbu);
157821
157822 /*
157823 ** Close an RBU handle.
157824 **
157825 ** If the RBU update has been completely applied, mark the RBU database
157826 ** as fully applied. Otherwise, assuming no error has occurred, save the
@@ -157539,10 +158049,11 @@
158049 int eType; /* Table type - an RBU_PK_XXX value */
158050
158051 /* Output variables. zTbl==0 implies EOF. */
158052 int bCleanup; /* True in "cleanup" state */
158053 const char *zTbl; /* Name of target db table */
158054 const char *zDataTbl; /* Name of rbu db table (or null) */
158055 const char *zIdx; /* Name of target db index (or null) */
158056 int iTnum; /* Root page of current object */
158057 int iPkTnum; /* If eType==EXTERNAL, root of PK index */
158058 int bUnique; /* Current index is unique */
158059
@@ -157549,11 +158060,11 @@
158060 /* Statements created by rbuObjIterPrepareAll() */
158061 int nCol; /* Number of columns in current object */
158062 sqlite3_stmt *pSelect; /* Source data */
158063 sqlite3_stmt *pInsert; /* Statement for INSERT operations */
158064 sqlite3_stmt *pDelete; /* Statement for DELETE ops */
158065 sqlite3_stmt *pTmpInsert; /* Insert into rbu_tmp_$zDataTbl */
158066
158067 /* Last UPDATE used (for PK b-tree updates only), or NULL. */
158068 RbuUpdateStmt *pRbuUpdate;
158069 };
158070
@@ -157659,10 +158170,256 @@
158170 const char *zWal; /* Wal filename for this main db file */
158171 rbu_file *pWalFd; /* Wal file descriptor for this main db */
158172 rbu_file *pMainNext; /* Next MAIN_DB file */
158173 };
158174
158175
158176 /*************************************************************************
158177 ** The following three functions, found below:
158178 **
158179 ** rbuDeltaGetInt()
158180 ** rbuDeltaChecksum()
158181 ** rbuDeltaApply()
158182 **
158183 ** are lifted from the fossil source code (http://fossil-scm.org). They
158184 ** are used to implement the scalar SQL function rbu_fossil_delta().
158185 */
158186
158187 /*
158188 ** Read bytes from *pz and convert them into a positive integer. When
158189 ** finished, leave *pz pointing to the first character past the end of
158190 ** the integer. The *pLen parameter holds the length of the string
158191 ** in *pz and is decremented once for each character in the integer.
158192 */
158193 static unsigned int rbuDeltaGetInt(const char **pz, int *pLen){
158194 static const signed char zValue[] = {
158195 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158196 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158197 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158198 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
158199 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
158200 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36,
158201 -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
158202 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1,
158203 };
158204 unsigned int v = 0;
158205 int c;
158206 unsigned char *z = (unsigned char*)*pz;
158207 unsigned char *zStart = z;
158208 while( (c = zValue[0x7f&*(z++)])>=0 ){
158209 v = (v<<6) + c;
158210 }
158211 z--;
158212 *pLen -= z - zStart;
158213 *pz = (char*)z;
158214 return v;
158215 }
158216
158217 /*
158218 ** Compute a 32-bit checksum on the N-byte buffer. Return the result.
158219 */
158220 static unsigned int rbuDeltaChecksum(const char *zIn, size_t N){
158221 const unsigned char *z = (const unsigned char *)zIn;
158222 unsigned sum0 = 0;
158223 unsigned sum1 = 0;
158224 unsigned sum2 = 0;
158225 unsigned sum3 = 0;
158226 while(N >= 16){
158227 sum0 += ((unsigned)z[0] + z[4] + z[8] + z[12]);
158228 sum1 += ((unsigned)z[1] + z[5] + z[9] + z[13]);
158229 sum2 += ((unsigned)z[2] + z[6] + z[10]+ z[14]);
158230 sum3 += ((unsigned)z[3] + z[7] + z[11]+ z[15]);
158231 z += 16;
158232 N -= 16;
158233 }
158234 while(N >= 4){
158235 sum0 += z[0];
158236 sum1 += z[1];
158237 sum2 += z[2];
158238 sum3 += z[3];
158239 z += 4;
158240 N -= 4;
158241 }
158242 sum3 += (sum2 << 8) + (sum1 << 16) + (sum0 << 24);
158243 switch(N){
158244 case 3: sum3 += (z[2] << 8);
158245 case 2: sum3 += (z[1] << 16);
158246 case 1: sum3 += (z[0] << 24);
158247 default: ;
158248 }
158249 return sum3;
158250 }
158251
158252 /*
158253 ** Apply a delta.
158254 **
158255 ** The output buffer should be big enough to hold the whole output
158256 ** file and a NUL terminator at the end. The delta_output_size()
158257 ** routine will determine this size for you.
158258 **
158259 ** The delta string should be null-terminated. But the delta string
158260 ** may contain embedded NUL characters (if the input and output are
158261 ** binary files) so we also have to pass in the length of the delta in
158262 ** the lenDelta parameter.
158263 **
158264 ** This function returns the size of the output file in bytes (excluding
158265 ** the final NUL terminator character). Except, if the delta string is
158266 ** malformed or intended for use with a source file other than zSrc,
158267 ** then this routine returns -1.
158268 **
158269 ** Refer to the delta_create() documentation above for a description
158270 ** of the delta file format.
158271 */
158272 static int rbuDeltaApply(
158273 const char *zSrc, /* The source or pattern file */
158274 int lenSrc, /* Length of the source file */
158275 const char *zDelta, /* Delta to apply to the pattern */
158276 int lenDelta, /* Length of the delta */
158277 char *zOut /* Write the output into this preallocated buffer */
158278 ){
158279 unsigned int limit;
158280 unsigned int total = 0;
158281 #ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
158282 char *zOrigOut = zOut;
158283 #endif
158284
158285 limit = rbuDeltaGetInt(&zDelta, &lenDelta);
158286 if( *zDelta!='\n' ){
158287 /* ERROR: size integer not terminated by "\n" */
158288 return -1;
158289 }
158290 zDelta++; lenDelta--;
158291 while( *zDelta && lenDelta>0 ){
158292 unsigned int cnt, ofst;
158293 cnt = rbuDeltaGetInt(&zDelta, &lenDelta);
158294 switch( zDelta[0] ){
158295 case '@': {
158296 zDelta++; lenDelta--;
158297 ofst = rbuDeltaGetInt(&zDelta, &lenDelta);
158298 if( lenDelta>0 && zDelta[0]!=',' ){
158299 /* ERROR: copy command not terminated by ',' */
158300 return -1;
158301 }
158302 zDelta++; lenDelta--;
158303 total += cnt;
158304 if( total>limit ){
158305 /* ERROR: copy exceeds output file size */
158306 return -1;
158307 }
158308 if( (int)(ofst+cnt) > lenSrc ){
158309 /* ERROR: copy extends past end of input */
158310 return -1;
158311 }
158312 memcpy(zOut, &zSrc[ofst], cnt);
158313 zOut += cnt;
158314 break;
158315 }
158316 case ':': {
158317 zDelta++; lenDelta--;
158318 total += cnt;
158319 if( total>limit ){
158320 /* ERROR: insert command gives an output larger than predicted */
158321 return -1;
158322 }
158323 if( (int)cnt>lenDelta ){
158324 /* ERROR: insert count exceeds size of delta */
158325 return -1;
158326 }
158327 memcpy(zOut, zDelta, cnt);
158328 zOut += cnt;
158329 zDelta += cnt;
158330 lenDelta -= cnt;
158331 break;
158332 }
158333 case ';': {
158334 zDelta++; lenDelta--;
158335 zOut[0] = 0;
158336 #ifndef FOSSIL_OMIT_DELTA_CKSUM_TEST
158337 if( cnt!=rbuDeltaChecksum(zOrigOut, total) ){
158338 /* ERROR: bad checksum */
158339 return -1;
158340 }
158341 #endif
158342 if( total!=limit ){
158343 /* ERROR: generated size does not match predicted size */
158344 return -1;
158345 }
158346 return total;
158347 }
158348 default: {
158349 /* ERROR: unknown delta operator */
158350 return -1;
158351 }
158352 }
158353 }
158354 /* ERROR: unterminated delta */
158355 return -1;
158356 }
158357
158358 static int rbuDeltaOutputSize(const char *zDelta, int lenDelta){
158359 int size;
158360 size = rbuDeltaGetInt(&zDelta, &lenDelta);
158361 if( *zDelta!='\n' ){
158362 /* ERROR: size integer not terminated by "\n" */
158363 return -1;
158364 }
158365 return size;
158366 }
158367
158368 /*
158369 ** End of code taken from fossil.
158370 *************************************************************************/
158371
158372 /*
158373 ** Implementation of SQL scalar function rbu_fossil_delta().
158374 **
158375 ** This function applies a fossil delta patch to a blob. Exactly two
158376 ** arguments must be passed to this function. The first is the blob to
158377 ** patch and the second the patch to apply. If no error occurs, this
158378 ** function returns the patched blob.
158379 */
158380 static void rbuFossilDeltaFunc(
158381 sqlite3_context *context,
158382 int argc,
158383 sqlite3_value **argv
158384 ){
158385 const char *aDelta;
158386 int nDelta;
158387 const char *aOrig;
158388 int nOrig;
158389
158390 int nOut;
158391 int nOut2;
158392 char *aOut;
158393
158394 assert( argc==2 );
158395
158396 nOrig = sqlite3_value_bytes(argv[0]);
158397 aOrig = (const char*)sqlite3_value_blob(argv[0]);
158398 nDelta = sqlite3_value_bytes(argv[1]);
158399 aDelta = (const char*)sqlite3_value_blob(argv[1]);
158400
158401 /* Figure out the size of the output */
158402 nOut = rbuDeltaOutputSize(aDelta, nDelta);
158403 if( nOut<0 ){
158404 sqlite3_result_error(context, "corrupt fossil delta", -1);
158405 return;
158406 }
158407
158408 aOut = sqlite3_malloc(nOut+1);
158409 if( aOut==0 ){
158410 sqlite3_result_error_nomem(context);
158411 }else{
158412 nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
158413 if( nOut2!=nOut ){
158414 sqlite3_result_error(context, "corrupt fossil delta", -1);
158415 }else{
158416 sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
158417 }
158418 }
158419 }
158420
158421
158422 /*
158423 ** Prepare the SQL statement in buffer zSql against database handle db.
158424 ** If successful, set *ppStmt to point to the new statement and return
158425 ** SQLITE_OK.
@@ -157826,11 +158583,12 @@
158583 if( rc!=SQLITE_ROW ){
158584 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
158585 pIter->zTbl = 0;
158586 }else{
158587 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
158588 pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
158589 rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
158590 }
158591 }else{
158592 if( pIter->zIdx==0 ){
158593 sqlite3_stmt *pIdx = pIter->pIdxIter;
158594 rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
@@ -157857,10 +158615,44 @@
158615 p->rc = rc;
158616 }
158617 return rc;
158618 }
158619
158620
158621 /*
158622 ** The implementation of the rbu_target_name() SQL function. This function
158623 ** accepts one argument - the name of a table in the RBU database. If the
158624 ** table name matches the pattern:
158625 **
158626 ** data[0-9]_<name>
158627 **
158628 ** where <name> is any sequence of 1 or more characters, <name> is returned.
158629 ** Otherwise, if the only argument does not match the above pattern, an SQL
158630 ** NULL is returned.
158631 **
158632 ** "data_t1" -> "t1"
158633 ** "data0123_t2" -> "t2"
158634 ** "dataAB_t3" -> NULL
158635 */
158636 static void rbuTargetNameFunc(
158637 sqlite3_context *context,
158638 int argc,
158639 sqlite3_value **argv
158640 ){
158641 const char *zIn;
158642 assert( argc==1 );
158643
158644 zIn = (const char*)sqlite3_value_text(argv[0]);
158645 if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
158646 int i;
158647 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
158648 if( zIn[i]=='_' && zIn[i+1] ){
158649 sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC);
158650 }
158651 }
158652 }
158653
158654 /*
158655 ** Initialize the iterator structure passed as the second argument.
158656 **
158657 ** If no error occurs, SQLITE_OK is returned and the iterator is left
158658 ** pointing to the first entry. Otherwise, an error code and message is
@@ -157870,12 +158662,13 @@
158662 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
158663 int rc;
158664 memset(pIter, 0, sizeof(RbuObjIter));
158665
158666 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
158667 "SELECT rbu_target_name(name) AS target, name FROM sqlite_master "
158668 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
158669 "ORDER BY name"
158670 );
158671
158672 if( rc==SQLITE_OK ){
158673 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
158674 "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
@@ -158138,11 +158931,11 @@
158931 }
158932 *peType = RBU_PK_NONE;
158933 }
158934
158935 rbuTableType_end: {
158936 unsigned int i;
158937 for(i=0; i<sizeof(aStmt)/sizeof(aStmt[0]); i++){
158938 rbuFinalize(p, aStmt[i]);
158939 }
158940 }
158941 }
@@ -158217,11 +159010,11 @@
159010
159011 /* Populate the azTblCol[] and nTblCol variables based on the columns
159012 ** of the input table. Ignore any input table columns that begin with
159013 ** "rbu_". */
159014 p->rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
159015 sqlite3_mprintf("SELECT * FROM '%q'", pIter->zDataTbl)
159016 );
159017 if( p->rc==SQLITE_OK ){
159018 nCol = sqlite3_column_count(pStmt);
159019 rbuAllocateIterArrays(p, pIter, nCol);
159020 }
@@ -158242,11 +159035,11 @@
159035 if( p->rc==SQLITE_OK
159036 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
159037 ){
159038 p->rc = SQLITE_ERROR;
159039 p->zErrmsg = sqlite3_mprintf(
159040 "table %q %s rbu_rowid column", pIter->zDataTbl,
159041 (bRbuRowid ? "may not have" : "requires")
159042 );
159043 }
159044
159045 /* Check that all non-HIDDEN columns in the destination table are also
@@ -158263,12 +159056,12 @@
159056 for(i=iOrder; i<pIter->nTblCol; i++){
159057 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
159058 }
159059 if( i==pIter->nTblCol ){
159060 p->rc = SQLITE_ERROR;
159061 p->zErrmsg = sqlite3_mprintf("column missing from %q: %s",
159062 pIter->zDataTbl, zName
159063 );
159064 }else{
159065 int iPk = sqlite3_column_int(pStmt, 5);
159066 int bNotNull = sqlite3_column_int(pStmt, 3);
159067 const char *zType = (const char*)sqlite3_column_text(pStmt, 2);
@@ -158551,11 +159344,11 @@
159344 ){
159345 char *zList = 0;
159346 if( p->rc==SQLITE_OK ){
159347 int i;
159348
159349 if( (int)strlen(zMask)!=pIter->nTblCol ){
159350 rbuBadControlError(p);
159351 }else{
159352 const char *zSep = "";
159353 for(i=0; i<pIter->nTblCol; i++){
159354 char c = zMask[pIter->aiSrcOrder[i]];
@@ -158563,15 +159356,21 @@
159356 zList = rbuMPrintf(p, "%z%s\"%w\"=?%d",
159357 zList, zSep, pIter->azTblCol[i], i+1
159358 );
159359 zSep = ", ";
159360 }
159361 else if( c=='d' ){
159362 zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_delta(\"%w\", ?%d)",
159363 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
159364 );
159365 zSep = ", ";
159366 }
159367 else if( c=='f' ){
159368 zList = rbuMPrintf(p, "%z%s\"%w\"=rbu_fossil_delta(\"%w\", ?%d)",
159369 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
159370 );
159371 zSep = ", ";
159372 }
159373 }
159374 }
159375 }
159376 return zList;
@@ -158819,11 +159618,11 @@
159618 if( zBind ){
159619 assert( pIter->pTmpInsert==0 );
159620 p->rc = prepareFreeAndCollectError(
159621 p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
159622 "INSERT INTO %s.'rbu_tmp_%q'(rbu_control,%s%s) VALUES(%z)",
159623 p->zStateDb, pIter->zDataTbl, zCollist, zRbuRowid, zBind
159624 ));
159625 }
159626 }
159627
159628 static void rbuTmpInsertFunc(
@@ -158915,22 +159714,22 @@
159714 if( p->rc==SQLITE_OK ){
159715 char *zSql;
159716 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
159717 zSql = sqlite3_mprintf(
159718 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
159719 zCollist, p->zStateDb, pIter->zDataTbl,
159720 zCollist, zLimit
159721 );
159722 }else{
159723 zSql = sqlite3_mprintf(
159724 "SELECT %s, rbu_control FROM '%q' "
159725 "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
159726 "UNION ALL "
159727 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
159728 "ORDER BY %s%s",
159729 zCollist, pIter->zDataTbl,
159730 zCollist, p->zStateDb, pIter->zDataTbl,
159731 zCollist, zLimit
159732 );
159733 }
159734 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
159735 }
@@ -158950,20 +159749,10 @@
159749 char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
159750
159751 zCollist = rbuObjIterGetCollist(p, pIter);
159752 pIter->nCol = pIter->nTblCol;
159753
 
 
 
 
 
 
 
 
 
 
159754 /* Create the imposter table or tables (if required). */
159755 rbuCreateImposterTable(p, pIter);
159756 rbuCreateImposterTable2(p, pIter);
159757 zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
159758
@@ -158993,14 +159782,14 @@
159782 }
159783
159784 /* Create the rbu_tmp_xxx table and the triggers to populate it. */
159785 rbuMPrintfExec(p, p->dbRbu,
159786 "CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS "
159787 "SELECT *%s FROM '%q' WHERE 0;"
159788 , p->zStateDb, pIter->zDataTbl
159789 , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
159790 , pIter->zDataTbl
159791 );
159792
159793 rbuMPrintfExec(p, p->dbMain,
159794 "CREATE TEMP TRIGGER rbu_delete_tr BEFORE DELETE ON \"%s%w\" "
159795 "BEGIN "
@@ -159031,10 +159820,21 @@
159820 );
159821 }
159822
159823 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
159824 }
159825
159826 /* Create the SELECT statement to read keys from data_xxx */
159827 if( p->rc==SQLITE_OK ){
159828 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
159829 sqlite3_mprintf(
159830 "SELECT %s, rbu_control%s FROM '%q'%s",
159831 zCollist, (bRbuRowid ? ", rbu_rowid" : ""),
159832 pIter->zDataTbl, zLimit
159833 )
159834 );
159835 }
159836
159837 sqlite3_free(zWhere);
159838 sqlite3_free(zOldlist);
159839 sqlite3_free(zNewlist);
159840 sqlite3_free(zBindings);
@@ -159161,10 +159961,22 @@
159961 if( p->rc==SQLITE_OK ){
159962 p->rc = sqlite3_create_function(p->dbMain,
159963 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
159964 );
159965 }
159966
159967 if( p->rc==SQLITE_OK ){
159968 p->rc = sqlite3_create_function(p->dbMain,
159969 "rbu_fossil_delta", 2, SQLITE_UTF8, 0, rbuFossilDeltaFunc, 0, 0
159970 );
159971 }
159972
159973 if( p->rc==SQLITE_OK ){
159974 p->rc = sqlite3_create_function(p->dbRbu,
159975 "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
159976 );
159977 }
159978
159979 if( p->rc==SQLITE_OK ){
159980 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
159981 }
159982 rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
@@ -159591,11 +160403,11 @@
160403 rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
160404 if( pUpdate ){
160405 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
160406 char c = zMask[pIter->aiSrcOrder[i]];
160407 pVal = sqlite3_column_value(pIter->pSelect, i);
160408 if( pIter->abTblPk[i] || c!='.' ){
160409 p->rc = sqlite3_bind_value(pUpdate, i+1, pVal);
160410 }
160411 }
160412 if( p->rc==SQLITE_OK
160413 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
@@ -159703,11 +160515,11 @@
160515 /* Clean up the rbu_tmp_xxx table for the previous table. It
160516 ** cannot be dropped as there are currently active SQL statements.
160517 ** But the contents can be deleted. */
160518 if( pIter->abIndexed ){
160519 rbuMPrintfExec(p, p->dbRbu,
160520 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
160521 );
160522 }
160523 }else{
160524 rbuObjIterPrepareAll(p, pIter, 0);
160525
@@ -159926,14 +160738,17 @@
160738 ** If there is a "*-oal" file in the file-system corresponding to the
160739 ** target database in the file-system, delete it. If an error occurs,
160740 ** leave an error code and error message in the rbu handle.
160741 */
160742 static void rbuDeleteOalFile(sqlite3rbu *p){
160743 char *zOal = rbuMPrintf(p, "%s-oal", p->zTarget);
160744 if( zOal ){
160745 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
160746 assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 );
160747 pVfs->xDelete(pVfs, zOal, 0);
160748 sqlite3_free(zOal);
160749 }
160750 }
160751
160752 /*
160753 ** Allocate a private rbu VFS for the rbu handle passed as the only
160754 ** argument. This VFS will be used unless the call to sqlite3rbu_open()
@@ -160042,18 +160857,29 @@
160857 p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
160858 }
160859
160860 if( p->rc==SQLITE_OK ){
160861 if( p->eStage==RBU_STAGE_OAL ){
160862 sqlite3 *db = p->dbMain;
160863
160864 /* Open transactions both databases. The *-oal file is opened or
160865 ** created at this point. */
160866 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160867 if( p->rc==SQLITE_OK ){
160868 p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
160869 }
160870
160871 /* Check if the main database is a zipvfs db. If it is, set the upper
160872 ** level pager to use "journal_mode=off". This prevents it from
160873 ** generating a large journal using a temp file. */
160874 if( p->rc==SQLITE_OK ){
160875 int frc = sqlite3_file_control(db, "main", SQLITE_FCNTL_ZIPVFS, 0);
160876 if( frc==SQLITE_OK ){
160877 p->rc = sqlite3_exec(db, "PRAGMA journal_mode=off",0,0,&p->zErrmsg);
160878 }
160879 }
160880
160881 /* Point the object iterator at the first object */
160882 if( p->rc==SQLITE_OK ){
160883 p->rc = rbuObjIterFirst(p, &p->objiter);
160884 }
160885
@@ -160162,10 +160988,36 @@
160988 ** current RBU update was started.
160989 */
160990 SQLITE_API sqlite3_int64 SQLITE_STDCALL sqlite3rbu_progress(sqlite3rbu *pRbu){
160991 return pRbu->nProgress;
160992 }
160993
160994 SQLITE_API int SQLITE_STDCALL sqlite3rbu_savestate(sqlite3rbu *p){
160995 int rc = p->rc;
160996
160997 if( rc==SQLITE_DONE ) return SQLITE_OK;
160998
160999 assert( p->eStage>=RBU_STAGE_OAL && p->eStage<=RBU_STAGE_DONE );
161000 if( p->eStage==RBU_STAGE_OAL ){
161001 assert( rc!=SQLITE_DONE );
161002 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
161003 }
161004
161005 p->rc = rc;
161006 rbuSaveState(p, p->eStage);
161007 rc = p->rc;
161008
161009 if( p->eStage==RBU_STAGE_OAL ){
161010 assert( rc!=SQLITE_DONE );
161011 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
161012 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, 0);
161013 if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "BEGIN IMMEDIATE", 0, 0,0);
161014 }
161015
161016 p->rc = rc;
161017 return rc;
161018 }
161019
161020 /**************************************************************************
161021 ** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour
161022 ** of a standard VFS in the following ways:
161023 **
@@ -160642,11 +161494,12 @@
161494 rbuVfsSectorSize, /* xSectorSize */
161495 rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */
161496 rbuVfsShmMap, /* xShmMap */
161497 rbuVfsShmLock, /* xShmLock */
161498 rbuVfsShmBarrier, /* xShmBarrier */
161499 rbuVfsShmUnmap, /* xShmUnmap */
161500 0, 0 /* xFetch, xUnfetch */
161501 };
161502 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
161503 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
161504 rbu_file *pFd = (rbu_file *)pFile;
161505 int rc = SQLITE_OK;
@@ -160984,10 +161837,13 @@
161837 **
161838 ** The dbstat virtual table is used to extract low-level formatting
161839 ** information from an SQLite database in order to implement the
161840 ** "sqlite3_analyzer" utility. See the ../tool/spaceanal.tcl script
161841 ** for an example implementation.
161842 **
161843 ** Additional information is available on the "dbstat.html" page of the
161844 ** official SQLite documentation.
161845 */
161846
161847 /* #include "sqliteInt.h" ** Requires access to internal data structures ** */
161848 #if (defined(SQLITE_ENABLE_DBSTAT_VTAB) || defined(SQLITE_TEST)) \
161849 && !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -161032,11 +161888,12 @@
161888 " ncell INTEGER, /* Cells on page (0 for overflow) */" \
161889 " payload INTEGER, /* Bytes of payload on this page */" \
161890 " unused INTEGER, /* Bytes of unused space on this page */" \
161891 " mx_payload INTEGER, /* Largest payload size of all cells */" \
161892 " pgoffset INTEGER, /* Offset of page in file */" \
161893 " pgsize INTEGER, /* Size of the page */" \
161894 " schema TEXT HIDDEN /* Database schema being analyzed */" \
161895 ");"
161896
161897
161898 typedef struct StatTable StatTable;
161899 typedef struct StatCursor StatCursor;
@@ -161070,10 +161927,11 @@
161927
161928 struct StatCursor {
161929 sqlite3_vtab_cursor base;
161930 sqlite3_stmt *pStmt; /* Iterates through set of root pages */
161931 int isEof; /* After pStmt has returned SQLITE_DONE */
161932 int iDb; /* Schema used for this query */
161933
161934 StatPage aPage[32];
161935 int iPage; /* Current entry in aPage[] */
161936
161937 /* Values to return. */
@@ -161147,13 +162005,36 @@
162005 return SQLITE_OK;
162006 }
162007
162008 /*
162009 ** There is no "best-index". This virtual table always does a linear
162010 ** scan. However, a schema=? constraint should cause this table to
162011 ** operate on a different database schema, so check for it.
162012 **
162013 ** idxNum is normally 0, but will be 1 if a schema=? constraint exists.
162014 */
162015 static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
162016 int i;
162017
162018 pIdxInfo->estimatedCost = 1.0e6; /* Initial cost estimate */
162019
162020 /* Look for a valid schema=? constraint. If found, change the idxNum to
162021 ** 1 and request the value of that constraint be sent to xFilter. And
162022 ** lower the cost estimate to encourage the constrained version to be
162023 ** used.
162024 */
162025 for(i=0; i<pIdxInfo->nConstraint; i++){
162026 if( pIdxInfo->aConstraint[i].usable==0 ) continue;
162027 if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
162028 if( pIdxInfo->aConstraint[i].iColumn!=10 ) continue;
162029 pIdxInfo->idxNum = 1;
162030 pIdxInfo->estimatedCost = 1.0;
162031 pIdxInfo->aConstraintUsage[i].argvIndex = 1;
162032 pIdxInfo->aConstraintUsage[i].omit = 1;
162033 break;
162034 }
162035
162036
162037 /* Records are always returned in ascending order of (name, path).
162038 ** If this will satisfy the client, set the orderByConsumed flag so that
162039 ** SQLite does not do an external sort.
162040 */
@@ -161169,50 +162050,31 @@
162050 )
162051 ){
162052 pIdxInfo->orderByConsumed = 1;
162053 }
162054
 
162055 return SQLITE_OK;
162056 }
162057
162058 /*
162059 ** Open a new statvfs cursor.
162060 */
162061 static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
162062 StatTable *pTab = (StatTable *)pVTab;
162063 StatCursor *pCsr;
 
162064
162065 pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor));
162066 if( pCsr==0 ){
162067 return SQLITE_NOMEM;
162068 }else{
 
162069 memset(pCsr, 0, sizeof(StatCursor));
162070 pCsr->base.pVtab = pVTab;
162071 pCsr->iDb = pTab->iDb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162072 }
162073
162074 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
162075 return SQLITE_OK;
162076 }
162077
162078 static void statClearPage(StatPage *p){
162079 int i;
162080 if( p->aCell ){
@@ -161233,10 +162095,11 @@
162095 statClearPage(&pCsr->aPage[i]);
162096 }
162097 pCsr->iPage = 0;
162098 sqlite3_free(pCsr->zPath);
162099 pCsr->zPath = 0;
162100 pCsr->isEof = 0;
162101 }
162102
162103 /*
162104 ** Close a statvfs cursor.
162105 */
@@ -161395,11 +162258,11 @@
162258 int rc;
162259 int nPayload;
162260 char *z;
162261 StatCursor *pCsr = (StatCursor *)pCursor;
162262 StatTable *pTab = (StatTable *)pCursor->pVtab;
162263 Btree *pBt = pTab->db->aDb[pCsr->iDb].pBt;
162264 Pager *pPager = sqlite3BtreePager(pBt);
162265
162266 sqlite3_free(pCsr->zPath);
162267 pCsr->zPath = 0;
162268
@@ -161533,13 +162396,47 @@
162396 sqlite3_vtab_cursor *pCursor,
162397 int idxNum, const char *idxStr,
162398 int argc, sqlite3_value **argv
162399 ){
162400 StatCursor *pCsr = (StatCursor *)pCursor;
162401 StatTable *pTab = (StatTable*)(pCursor->pVtab);
162402 char *zSql;
162403 int rc = SQLITE_OK;
162404 char *zMaster;
162405
162406 if( idxNum==1 ){
162407 const char *zDbase = (const char*)sqlite3_value_text(argv[0]);
162408 pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase);
162409 if( pCsr->iDb<0 ){
162410 sqlite3_free(pCursor->pVtab->zErrMsg);
162411 pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase);
162412 return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM;
162413 }
162414 }else{
162415 pCsr->iDb = pTab->iDb;
162416 }
162417 statResetCsr(pCsr);
162418 sqlite3_finalize(pCsr->pStmt);
162419 pCsr->pStmt = 0;
162420 zMaster = pCsr->iDb==1 ? "sqlite_temp_master" : "sqlite_master";
162421 zSql = sqlite3_mprintf(
162422 "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type"
162423 " UNION ALL "
162424 "SELECT name, rootpage, type"
162425 " FROM \"%w\".%s WHERE rootpage!=0"
162426 " ORDER BY name", pTab->db->aDb[pCsr->iDb].zName, zMaster);
162427 if( zSql==0 ){
162428 return SQLITE_NOMEM;
162429 }else{
162430 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0);
162431 sqlite3_free(zSql);
162432 }
162433
162434 if( rc==SQLITE_OK ){
162435 rc = statNext(pCursor);
162436 }
162437 return rc;
162438 }
162439
162440 static int statColumn(
162441 sqlite3_vtab_cursor *pCursor,
162442 sqlite3_context *ctx,
@@ -161572,14 +162469,19 @@
162469 sqlite3_result_int(ctx, pCsr->nMxPayload);
162470 break;
162471 case 8: /* pgoffset */
162472 sqlite3_result_int64(ctx, pCsr->iOffset);
162473 break;
162474 case 9: /* pgsize */
 
162475 sqlite3_result_int(ctx, pCsr->szPage);
162476 break;
162477 default: { /* schema */
162478 sqlite3 *db = sqlite3_context_db_handle(ctx);
162479 int iDb = pCsr->iDb;
162480 sqlite3_result_text(ctx, db->aDb[iDb].zName, -1, SQLITE_STATIC);
162481 break;
162482 }
162483 }
162484 return SQLITE_OK;
162485 }
162486
162487 static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
162488
+37 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109109
**
110110
** See also: [sqlite3_libversion()],
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114
-#define SQLITE_VERSION "3.8.11.1"
115
-#define SQLITE_VERSION_NUMBER 3008011
116
-#define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
114
+#define SQLITE_VERSION "3.8.12"
115
+#define SQLITE_VERSION_NUMBER 3008012
116
+#define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -475,10 +475,11 @@
475475
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
476476
#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
477477
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
478478
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
479479
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
480
+#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
480481
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
481482
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
482483
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
483484
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
484485
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -3371,11 +3372,12 @@
33713372
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
33723373
** METHOD: sqlite3_stmt
33733374
**
33743375
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
33753376
** [prepared statement] S has been stepped at least once using
3376
-** [sqlite3_step(S)] but has not run to completion and/or has not
3377
+** [sqlite3_step(S)] but has neither run to completion (returned
3378
+** [SQLITE_DONE] from [sqlite3_step(S)]) nor
33773379
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
33783380
** interface returns false if S is a NULL pointer. If S is not a
33793381
** NULL pointer and is not a pointer to a valid [prepared statement]
33803382
** object, then the behavior is undefined and probably undesirable.
33813383
**
@@ -4353,10 +4355,26 @@
43534355
SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
43544356
SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
43554357
SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
43564358
SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
43574359
4360
+/*
4361
+** CAPI3REF: Obtaining SQL Values
4362
+** METHOD: sqlite3_value
4363
+**
4364
+** The sqlite3_value_subtype(V) function returns the subtype for
4365
+** an [application-defined SQL function] argument V. The subtype
4366
+** information can be used to pass a limited amount of context from
4367
+** one SQL function to another. Use the [sqlite3_result_subtype()]
4368
+** routine to set the subtype for the return value of an SQL function.
4369
+**
4370
+** SQLite makes no use of subtype itself. It merely passes the subtype
4371
+** from the result of one [application-defined SQL function] into the
4372
+** input of another.
4373
+*/
4374
+SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
4375
+
43584376
/*
43594377
** CAPI3REF: Copy And Free SQL Values
43604378
** METHOD: sqlite3_value
43614379
**
43624380
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
@@ -4652,10 +4670,25 @@
46524670
SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
46534671
SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
46544672
SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
46554673
SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
46564674
4675
+
4676
+/*
4677
+** CAPI3REF: Setting The Subtype Of An SQL Function
4678
+** METHOD: sqlite3_context
4679
+**
4680
+** The sqlite3_result_subtype(C,T) function causes the subtype of
4681
+** the result from the [application-defined SQL function] with
4682
+** [sqlite3_context] C to be the value T. Only the lower 8 bits
4683
+** of the subtype T are preserved in current versions of SQLite;
4684
+** higher order bits are discarded.
4685
+** The number of subtype bytes preserved by SQLite might increase
4686
+** in future releases of SQLite.
4687
+*/
4688
+SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
4689
+
46574690
/*
46584691
** CAPI3REF: Define New Collating Sequences
46594692
** METHOD: sqlite3
46604693
**
46614694
** ^These functions add, remove, or modify a [collation] associated
46624695
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.11.1"
115 #define SQLITE_VERSION_NUMBER 3008011
116 #define SQLITE_SOURCE_ID "2015-07-29 20:00:57 cf538e2783e468bbc25e7cb2a9ee64d3e0e80b2f"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -475,10 +475,11 @@
475 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
476 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
477 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
478 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
479 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
 
480 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
481 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
482 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
483 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
484 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -3371,11 +3372,12 @@
3371 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3372 ** METHOD: sqlite3_stmt
3373 **
3374 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3375 ** [prepared statement] S has been stepped at least once using
3376 ** [sqlite3_step(S)] but has not run to completion and/or has not
 
3377 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
3378 ** interface returns false if S is a NULL pointer. If S is not a
3379 ** NULL pointer and is not a pointer to a valid [prepared statement]
3380 ** object, then the behavior is undefined and probably undesirable.
3381 **
@@ -4353,10 +4355,26 @@
4353 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
4354 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
4355 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4356 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4358 /*
4359 ** CAPI3REF: Copy And Free SQL Values
4360 ** METHOD: sqlite3_value
4361 **
4362 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
@@ -4652,10 +4670,25 @@
4652 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4653 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4654 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4655 SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
4656
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4657 /*
4658 ** CAPI3REF: Define New Collating Sequences
4659 ** METHOD: sqlite3
4660 **
4661 ** ^These functions add, remove, or modify a [collation] associated
4662
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -109,13 +109,13 @@
109 **
110 ** See also: [sqlite3_libversion()],
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.8.12"
115 #define SQLITE_VERSION_NUMBER 3008012
116 #define SQLITE_SOURCE_ID "2015-09-11 01:22:41 d6cadbe9fefce9a7af6b2d0cb83362f967d7d89a"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -475,10 +475,11 @@
475 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
476 #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
477 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
478 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
479 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
480 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
481 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
482 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
483 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
484 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
485 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -3371,11 +3372,12 @@
3372 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3373 ** METHOD: sqlite3_stmt
3374 **
3375 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3376 ** [prepared statement] S has been stepped at least once using
3377 ** [sqlite3_step(S)] but has neither run to completion (returned
3378 ** [SQLITE_DONE] from [sqlite3_step(S)]) nor
3379 ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
3380 ** interface returns false if S is a NULL pointer. If S is not a
3381 ** NULL pointer and is not a pointer to a valid [prepared statement]
3382 ** object, then the behavior is undefined and probably undesirable.
3383 **
@@ -4353,10 +4355,26 @@
4355 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16le(sqlite3_value*);
4356 SQLITE_API const void *SQLITE_STDCALL sqlite3_value_text16be(sqlite3_value*);
4357 SQLITE_API int SQLITE_STDCALL sqlite3_value_type(sqlite3_value*);
4358 SQLITE_API int SQLITE_STDCALL sqlite3_value_numeric_type(sqlite3_value*);
4359
4360 /*
4361 ** CAPI3REF: Obtaining SQL Values
4362 ** METHOD: sqlite3_value
4363 **
4364 ** The sqlite3_value_subtype(V) function returns the subtype for
4365 ** an [application-defined SQL function] argument V. The subtype
4366 ** information can be used to pass a limited amount of context from
4367 ** one SQL function to another. Use the [sqlite3_result_subtype()]
4368 ** routine to set the subtype for the return value of an SQL function.
4369 **
4370 ** SQLite makes no use of subtype itself. It merely passes the subtype
4371 ** from the result of one [application-defined SQL function] into the
4372 ** input of another.
4373 */
4374 SQLITE_API unsigned int SQLITE_STDCALL sqlite3_value_subtype(sqlite3_value*);
4375
4376 /*
4377 ** CAPI3REF: Copy And Free SQL Values
4378 ** METHOD: sqlite3_value
4379 **
4380 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
@@ -4652,10 +4670,25 @@
4670 SQLITE_API void SQLITE_STDCALL sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
4671 SQLITE_API void SQLITE_STDCALL sqlite3_result_value(sqlite3_context*, sqlite3_value*);
4672 SQLITE_API void SQLITE_STDCALL sqlite3_result_zeroblob(sqlite3_context*, int n);
4673 SQLITE_API int SQLITE_STDCALL sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
4674
4675
4676 /*
4677 ** CAPI3REF: Setting The Subtype Of An SQL Function
4678 ** METHOD: sqlite3_context
4679 **
4680 ** The sqlite3_result_subtype(C,T) function causes the subtype of
4681 ** the result from the [application-defined SQL function] with
4682 ** [sqlite3_context] C to be the value T. Only the lower 8 bits
4683 ** of the subtype T are preserved in current versions of SQLite;
4684 ** higher order bits are discarded.
4685 ** The number of subtype bytes preserved by SQLite might increase
4686 ** in future releases of SQLite.
4687 */
4688 SQLITE_API void SQLITE_STDCALL sqlite3_result_subtype(sqlite3_context*,unsigned int);
4689
4690 /*
4691 ** CAPI3REF: Define New Collating Sequences
4692 ** METHOD: sqlite3
4693 **
4694 ** ^These functions add, remove, or modify a [collation] associated
4695

Keyboard Shortcuts

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