Fossil SCM

Replace embedded SQLite version to version 3.8.2 stable.

jan.nijtmans 2014-01-09 16:11 trunk
Commit 1e4b84864acfc1f1089758f2d4d6e8ab8523aa55
2 files changed +2429 -2229 +25 -71
+2429 -2229
--- 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.3. By combining all the individual C code files into this
3
+** version 3.8.2. 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.
@@ -133,13 +133,13 @@
133133
**
134134
** See also: [sqlite3_libversion()],
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138
-#define SQLITE_VERSION "3.8.3"
139
-#define SQLITE_VERSION_NUMBER 3008003
140
-#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
138
+#define SQLITE_VERSION "3.8.2"
139
+#define SQLITE_VERSION_NUMBER 3008002
140
+#define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -517,11 +517,10 @@
517517
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518518
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519519
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520520
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521521
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
522
-#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
523522
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
524523
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
525524
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
526525
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
527526
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -585,12 +584,11 @@
585584
** information is written to disk in the same order as calls
586585
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
587586
** after reboot following a crash or power loss, the only bytes in a
588587
** file that were written at the application level might have changed
589588
** and that adjacent bytes, even bytes within the same sector are
590
-** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
591
-** flag indicate that a file cannot be deleted when open.
589
+** guaranteed to be unchanged.
592590
*/
593591
#define SQLITE_IOCAP_ATOMIC 0x00000001
594592
#define SQLITE_IOCAP_ATOMIC512 0x00000002
595593
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
596594
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -817,33 +815,19 @@
817815
** to the [sqlite3_file] object associated with a particular database
818816
** connection. See the [sqlite3_file_control()] documentation for
819817
** additional information.
820818
**
821819
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
822
-** No longer in use.
823
-**
824
-** <li>[[SQLITE_FCNTL_SYNC]]
825
-** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
826
-** sent to the VFS immediately before the xSync method is invoked on a
827
-** database file descriptor. Or, if the xSync method is not invoked
828
-** because the user has configured SQLite with
829
-** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
830
-** of the xSync method. In most cases, the pointer argument passed with
831
-** this file-control is NULL. However, if the database file is being synced
832
-** as part of a multi-database commit, the argument points to a nul-terminated
833
-** string containing the transactions master-journal file name. VFSes that
834
-** do not need this signal should silently ignore this opcode. Applications
835
-** should not call [sqlite3_file_control()] with this opcode as doing so may
836
-** disrupt the operation of the specialized VFSes that do require it.
837
-**
838
-** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
839
-** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
840
-** and sent to the VFS after a transaction has been committed immediately
841
-** but before the database is unlocked. VFSes that do not need this signal
842
-** should silently ignore this opcode. Applications should not call
843
-** [sqlite3_file_control()] with this opcode as doing so may disrupt the
844
-** operation of the specialized VFSes that do require it.
820
+** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
821
+** SQLite and sent to all VFSes in place of a call to the xSync method
822
+** when the database connection has [PRAGMA synchronous] set to OFF.)^
823
+** Some specialized VFSes need this signal in order to operate correctly
824
+** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
825
+** VFSes do not need this signal and should silently ignore this opcode.
826
+** Applications should not call [sqlite3_file_control()] with this
827
+** opcode as doing so may disrupt the operation of the specialized VFSes
828
+** that do require it.
845829
**
846830
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
847831
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
848832
** retry counts and intervals for certain disk I/O operations for the
849833
** windows [VFS] in order to provide robustness in the presence of
@@ -963,16 +947,10 @@
963947
** This file control is used by some VFS activity tracing [shims].
964948
** The argument is a zero-terminated string. Higher layers in the
965949
** SQLite stack may generate instances of this file control if
966950
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
967951
**
968
-** <li>[[SQLITE_FCNTL_HAS_MOVED]]
969
-** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
970
-** pointer to an integer and it writes a boolean into that integer depending
971
-** on whether or not the file has been renamed, moved, or deleted since it
972
-** was first opened.
973
-**
974952
** </ul>
975953
*/
976954
#define SQLITE_FCNTL_LOCKSTATE 1
977955
#define SQLITE_GET_LOCKPROXYFILE 2
978956
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -989,13 +967,10 @@
989967
#define SQLITE_FCNTL_PRAGMA 14
990968
#define SQLITE_FCNTL_BUSYHANDLER 15
991969
#define SQLITE_FCNTL_TEMPFILENAME 16
992970
#define SQLITE_FCNTL_MMAP_SIZE 18
993971
#define SQLITE_FCNTL_TRACE 19
994
-#define SQLITE_FCNTL_HAS_MOVED 20
995
-#define SQLITE_FCNTL_SYNC 21
996
-#define SQLITE_FCNTL_COMMIT_PHASETWO 22
997972
998973
/*
999974
** CAPI3REF: Mutex Handle
1000975
**
1001976
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2426,17 +2401,15 @@
24262401
** already uses the largest possible [ROWID]. The PRNG is also used for
24272402
** the build-in random() and randomblob() SQL functions. This interface allows
24282403
** applications to access the same PRNG for other purposes.
24292404
**
24302405
** ^A call to this routine stores N bytes of randomness into buffer P.
2431
-** ^If N is less than one, then P can be a NULL pointer.
24322406
**
2433
-** ^If this routine has not been previously called or if the previous
2434
-** call had N less than one, then the PRNG is seeded using randomness
2435
-** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2436
-** ^If the previous call to this routine had an N of 1 or more then
2437
-** the pseudo-randomness is generated
2407
+** ^The first time this routine is invoked (either internally or by
2408
+** the application) the PRNG is seeded using randomness obtained
2409
+** from the xRandomness method of the default [sqlite3_vfs] object.
2410
+** ^On all subsequent invocations, the pseudo-randomness is generated
24382411
** internally and without recourse to the [sqlite3_vfs] xRandomness
24392412
** method.
24402413
*/
24412414
SQLITE_API void sqlite3_randomness(int N, void *P);
24422415
@@ -4010,28 +3983,19 @@
40103983
** parameter is less than -1 or greater than 127 then the behavior is
40113984
** undefined.
40123985
**
40133986
** ^The fourth parameter, eTextRep, specifies what
40143987
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
4015
-** its parameters. The application should set this parameter to
4016
-** [SQLITE_UTF16LE] if the function implementation invokes
4017
-** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
4018
-** implementation invokes [sqlite3_value_text16be()] on an input, or
4019
-** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
4020
-** otherwise. ^The same SQL function may be registered multiple times using
4021
-** different preferred text encodings, with different implementations for
4022
-** each encoding.
3988
+** its parameters. Every SQL function implementation must be able to work
3989
+** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3990
+** more efficient with one encoding than another. ^An application may
3991
+** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3992
+** times with the same function but with different values of eTextRep.
40233993
** ^When multiple implementations of the same function are available, SQLite
40243994
** will pick the one that involves the least amount of data conversion.
4025
-**
4026
-** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
4027
-** to signal that the function will always return the same result given
4028
-** the same inputs within a single SQL statement. Most SQL functions are
4029
-** deterministic. The built-in [random()] SQL function is an example of a
4030
-** function that is not deterministic. The SQLite query planner is able to
4031
-** perform additional optimizations on deterministic functions, so use
4032
-** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
3995
+** If there is only a single implementation which does not care what text
3996
+** encoding is used, then the fourth argument should be [SQLITE_ANY].
40333997
**
40343998
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
40353999
** function can gain access to this pointer using [sqlite3_user_data()].)^
40364000
**
40374001
** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4113,23 +4077,13 @@
41134077
*/
41144078
#define SQLITE_UTF8 1
41154079
#define SQLITE_UTF16LE 2
41164080
#define SQLITE_UTF16BE 3
41174081
#define SQLITE_UTF16 4 /* Use native byte order */
4118
-#define SQLITE_ANY 5 /* Deprecated */
4082
+#define SQLITE_ANY 5 /* sqlite3_create_function only */
41194083
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
41204084
4121
-/*
4122
-** CAPI3REF: Function Flags
4123
-**
4124
-** These constants may be ORed together with the
4125
-** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4126
-** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4127
-** [sqlite3_create_function_v2()].
4128
-*/
4129
-#define SQLITE_DETERMINISTIC 0x800
4130
-
41314085
/*
41324086
** CAPI3REF: Deprecated Functions
41334087
** DEPRECATED
41344088
**
41354089
** These functions are [deprecated]. In order to maintain
@@ -8627,11 +8581,10 @@
86278581
typedef struct Lookaside Lookaside;
86288582
typedef struct LookasideSlot LookasideSlot;
86298583
typedef struct Module Module;
86308584
typedef struct NameContext NameContext;
86318585
typedef struct Parse Parse;
8632
-typedef struct PrintfArguments PrintfArguments;
86338586
typedef struct RowSet RowSet;
86348587
typedef struct Savepoint Savepoint;
86358588
typedef struct Select Select;
86368589
typedef struct SelectDest SelectDest;
86378590
typedef struct SrcList SrcList;
@@ -9100,11 +9053,11 @@
91009053
#define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
91019054
#define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
91029055
#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
91039056
#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
91049057
#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9105
-#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9058
+#define OP_Copy 30 /* synopsis: r[P2@P3]=r[P1@P3] */
91069059
#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
91079060
#define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
91089061
#define OP_CollSeq 33
91099062
#define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
91109063
#define OP_MustBeInt 35
@@ -9265,11 +9218,11 @@
92659218
92669219
/*
92679220
** Prototypes for the VDBE interface. See comments on the implementation
92689221
** for a description of what each of these routines does.
92699222
*/
9270
-SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
9223
+SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3*);
92719224
SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
92729225
SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
92739226
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
92749227
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
92759228
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
@@ -9280,11 +9233,10 @@
92809233
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
92819234
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
92829235
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
92839236
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
92849237
SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
9285
-SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*);
92869238
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
92879239
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
92889240
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
92899241
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
92909242
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
@@ -9487,11 +9439,10 @@
94879439
SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
94889440
#define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
94899441
SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
94909442
SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
94919443
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
9492
-SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
94939444
94949445
/* Operations on page references. */
94959446
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
94969447
SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
94979448
SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -9502,11 +9453,11 @@
95029453
/* Functions used to manage pager transactions and savepoints. */
95039454
SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
95049455
SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
95059456
SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
95069457
SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
9507
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster);
9458
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
95089459
SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
95099460
SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
95109461
SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
95119462
SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
95129463
SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -10374,11 +10325,11 @@
1037410325
*/
1037510326
#define SQLITE_QueryFlattener 0x0001 /* Query flattening */
1037610327
#define SQLITE_ColumnCache 0x0002 /* Column cache */
1037710328
#define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
1037810329
#define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10379
-/* not used 0x0010 // Was: SQLITE_IdxRealAsInt */
10330
+#define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
1038010331
#define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
1038110332
#define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1038210333
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1038310334
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1038410335
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
@@ -11006,11 +10957,10 @@
1100610957
u8 useSortingIdx; /* In direct mode, reference the sorting index rather
1100710958
** than the source table */
1100810959
int sortingIdx; /* Cursor number of the sorting index */
1100910960
int sortingIdxPTab; /* Cursor number of pseudo-table */
1101010961
int nSortingColumn; /* Number of columns in the sorting index */
11011
- int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
1101210962
ExprList *pGroupBy; /* The group by clause */
1101310963
struct AggInfo_col { /* For each column used in source tables */
1101410964
Table *pTab; /* Source table */
1101510965
int iTable; /* Cursor number of the source table */
1101610966
int iColumn; /* Column number within the source table */
@@ -11608,13 +11558,10 @@
1160811558
int nErr; /* Number of errors seen */
1160911559
int nTab; /* Number of previously allocated VDBE cursors */
1161011560
int nMem; /* Number of memory cells used so far */
1161111561
int nSet; /* Number of sets used so far */
1161211562
int nOnce; /* Number of OP_Once instructions so far */
11613
- int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11614
- int nLabel; /* Number of labels used */
11615
- int *aLabel; /* Space to hold the labels */
1161611563
int ckBase; /* Base register of data during check constraints */
1161711564
int iPartIdxTab; /* Table corresponding to a partial index */
1161811565
int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
1161911566
int iCacheCnt; /* Counter used to generate aColCache[].lru values */
1162011567
struct yColCache {
@@ -12087,24 +12034,14 @@
1208712034
SQLITE_PRIVATE int sqlite3IsNaN(double);
1208812035
#else
1208912036
# define sqlite3IsNaN(X) 0
1209012037
#endif
1209112038
12092
-/*
12093
-** An instance of the following structure holds information about SQL
12094
-** functions arguments that are the parameters to the printf() function.
12095
-*/
12096
-struct PrintfArguments {
12097
- int nArg; /* Total number of arguments */
12098
- int nUsed; /* Number of arguments used so far */
12099
- sqlite3_value **apArg; /* The argument values */
12100
-};
12101
-
12102
-#define SQLITE_PRINTF_INTERNAL 0x01
12103
-#define SQLITE_PRINTF_SQLFUNC 0x02
12104
-SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
12105
-SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
12039
+SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
12040
+#ifndef SQLITE_OMIT_TRACE
12041
+SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...);
12042
+#endif
1210612043
SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
1210712044
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
1210812045
SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
1210912046
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
1211012047
SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
@@ -12290,10 +12227,11 @@
1229012227
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
1229112228
SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
1229212229
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
1229312230
SQLITE_PRIVATE void sqlite3PrngSaveState(void);
1229412231
SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
12232
+SQLITE_PRIVATE void sqlite3PrngResetState(void);
1229512233
SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
1229612234
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
1229712235
SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
1229812236
SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
1229912237
SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
@@ -12458,11 +12396,12 @@
1245812396
SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
1245912397
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
1246012398
SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
1246112399
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
1246212400
12463
-#if defined(SQLITE_TEST)
12401
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
12402
+ defined(SQLITE_DEBUG_OS_TRACE)
1246412403
SQLITE_PRIVATE const char *sqlite3ErrName(int);
1246512404
#endif
1246612405
1246712406
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1246812407
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -12488,11 +12427,10 @@
1248812427
1248912428
SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
1249012429
SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
1249112430
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1249212431
void(*)(void*));
12493
-SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*);
1249412432
SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
1249512433
SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
1249612434
SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
1249712435
SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
1249812436
SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
@@ -12554,11 +12492,10 @@
1255412492
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1255512493
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1255612494
1255712495
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
1255812496
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
12559
-SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
1256012497
SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
1256112498
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
1256212499
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
1256312500
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
1256412501
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -13781,13 +13718,16 @@
1378113718
Op *aOp; /* Space to hold the virtual machine's program */
1378213719
Mem *aMem; /* The memory locations */
1378313720
Mem **apArg; /* Arguments to currently executing user function */
1378413721
Mem *aColName; /* Column names to return */
1378513722
Mem *pResultSet; /* Pointer to an array of results */
13786
- Parse *pParse; /* Parsing context used to create this Vdbe */
1378713723
int nMem; /* Number of memory locations currently allocated */
1378813724
int nOp; /* Number of instructions in the program */
13725
+ int nOpAlloc; /* Number of slots allocated for aOp[] */
13726
+ int nLabel; /* Number of labels used */
13727
+ int *aLabel; /* Space to hold the labels */
13728
+ u16 nResColumn; /* Number of columns in one row of the result set */
1378913729
int nCursor; /* Number of slots in apCsr[] */
1379013730
u32 magic; /* Magic number for sanity checking */
1379113731
char *zErrMsg; /* Error message written here */
1379213732
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
1379313733
VdbeCursor **apCsr; /* One element of this array for each open cursor */
@@ -13796,11 +13736,10 @@
1379613736
ynVar nVar; /* Number of entries in aVar[] */
1379713737
ynVar nzVar; /* Number of entries in azVar[] */
1379813738
u32 cacheCtr; /* VdbeCursor row cache generation counter */
1379913739
int pc; /* The program counter */
1380013740
int rc; /* Value to return */
13801
- u16 nResColumn; /* Number of columns in one row of the result set */
1380213741
u8 errorAction; /* Recovery action to do in case of an error */
1380313742
u8 minWriteFileFormat; /* Minimum file format for writable database files */
1380413743
bft explain:2; /* True if EXPLAIN present on SQL command */
1380513744
bft inVtabMethod:2; /* See comments above */
1380613745
bft changeCntOn:1; /* True to update the change-counter */
@@ -13856,11 +13795,11 @@
1385613795
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
1385713796
SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
1385813797
#endif
1385913798
SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
1386013799
SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13861
-SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
13800
+SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
1386213801
SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
1386313802
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
1386413803
1386513804
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
1386613805
SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -15446,25 +15385,11 @@
1544615385
** really care if the VFS receives and understands the information since it
1544715386
** is only a hint and can be safely ignored. The sqlite3OsFileControlHint()
1544815387
** routine has no return value since the return value would be meaningless.
1544915388
*/
1545015389
SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
15451
-#ifdef SQLITE_TEST
15452
- if( op!=SQLITE_FCNTL_COMMIT_PHASETWO ){
15453
- /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
15454
- ** is using a regular VFS, it is called after the corresponding
15455
- ** transaction has been committed. Injecting a fault at this point
15456
- ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM
15457
- ** but the transaction is committed anyway.
15458
- **
15459
- ** The core must call OsFileControl() though, not OsFileControlHint(),
15460
- ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
15461
- ** means the commit really has failed and an error should be returned
15462
- ** to the user. */
15463
- DO_OS_MALLOC_TEST(id);
15464
- }
15465
-#endif
15390
+ DO_OS_MALLOC_TEST(id);
1546615391
return id->pMethods->xFileControl(id, op, pArg);
1546715392
}
1546815393
SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
1546915394
(void)id->pMethods->xFileControl(id, op, pArg);
1547015395
}
@@ -19455,11 +19380,11 @@
1945519380
/*
1945619381
** TRUE if p is a lookaside memory allocation from db
1945719382
*/
1945819383
#ifndef SQLITE_OMIT_LOOKASIDE
1945919384
static int isLookaside(sqlite3 *db, void *p){
19460
- return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19385
+ return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
1946119386
}
1946219387
#else
1946319388
#define isLookaside(A,B) 0
1946419389
#endif
1946519390
@@ -19471,13 +19396,12 @@
1947119396
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
1947219397
assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
1947319398
return sqlite3GlobalConfig.m.xSize(p);
1947419399
}
1947519400
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19476
- assert( db!=0 );
19477
- assert( sqlite3_mutex_held(db->mutex) );
19478
- if( isLookaside(db, p) ){
19401
+ assert( db==0 || sqlite3_mutex_held(db->mutex) );
19402
+ if( db && isLookaside(db, p) ){
1947919403
return db->lookaside.sz;
1948019404
}else{
1948119405
assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
1948219406
assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
1948319407
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19955,35 +19879,10 @@
1995519879
}
1995619880
if( N>0 ){
1995719881
sqlite3StrAccumAppend(pAccum, zSpaces, N);
1995819882
}
1995919883
}
19960
-
19961
-/*
19962
-** Set the StrAccum object to an error mode.
19963
-*/
19964
-static void setStrAccumError(StrAccum *p, u8 eError){
19965
- p->accError = eError;
19966
- p->nAlloc = 0;
19967
-}
19968
-
19969
-/*
19970
-** Extra argument values from a PrintfArguments object
19971
-*/
19972
-static sqlite3_int64 getIntArg(PrintfArguments *p){
19973
- if( p->nArg<=p->nUsed ) return 0;
19974
- return sqlite3_value_int64(p->apArg[p->nUsed++]);
19975
-}
19976
-static double getDoubleArg(PrintfArguments *p){
19977
- if( p->nArg<=p->nUsed ) return 0.0;
19978
- return sqlite3_value_double(p->apArg[p->nUsed++]);
19979
-}
19980
-static char *getTextArg(PrintfArguments *p){
19981
- if( p->nArg<=p->nUsed ) return 0;
19982
- return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
19983
-}
19984
-
1998519884
1998619885
/*
1998719886
** On machines with a small stack size, you can redefine the
1998819887
** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
1998919888
*/
@@ -19994,14 +19893,14 @@
1999419893
1999519894
/*
1999619895
** Render a string given by "fmt" into the StrAccum object.
1999719896
*/
1999819897
SQLITE_PRIVATE void sqlite3VXPrintf(
19999
- StrAccum *pAccum, /* Accumulate results here */
20000
- u32 bFlags, /* SQLITE_PRINTF_* flags */
20001
- const char *fmt, /* Format string */
20002
- va_list ap /* arguments */
19898
+ StrAccum *pAccum, /* Accumulate results here */
19899
+ int useExtended, /* Allow extended %-conversions */
19900
+ const char *fmt, /* Format string */
19901
+ va_list ap /* arguments */
2000319902
){
2000419903
int c; /* Next character in the format string */
2000519904
char *bufpt; /* Pointer to the conversion buffer */
2000619905
int precision; /* Precision of the current field */
2000719906
int length; /* Length of the field */
@@ -20015,12 +19914,10 @@
2001519914
etByte flag_zeropad; /* True if field width constant starts with zero */
2001619915
etByte flag_long; /* True if "l" flag is present */
2001719916
etByte flag_longlong; /* True if the "ll" flag is present */
2001819917
etByte done; /* Loop termination flag */
2001919918
etByte xtype = 0; /* Conversion paradigm */
20020
- u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
20021
- u8 useIntern; /* Ok to use internal conversions (ex: %T) */
2002219919
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
2002319920
sqlite_uint64 longvalue; /* Value for integer types */
2002419921
LONGDOUBLE_TYPE realvalue; /* Value for real types */
2002519922
const et_info *infop; /* Pointer to the appropriate info structure */
2002619923
char *zOut; /* Rendering buffer */
@@ -20031,22 +19928,13 @@
2003119928
int nsd; /* Number of significant digits returned */
2003219929
double rounder; /* Used for rounding floating point values */
2003319930
etByte flag_dp; /* True if decimal point should be shown */
2003419931
etByte flag_rtz; /* True if trailing zeros should be removed */
2003519932
#endif
20036
- PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
2003719933
char buf[etBUFSIZE]; /* Conversion buffer */
2003819934
2003919935
bufpt = 0;
20040
- if( bFlags ){
20041
- if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
20042
- pArgList = va_arg(ap, PrintfArguments*);
20043
- }
20044
- useIntern = bFlags & SQLITE_PRINTF_INTERNAL;
20045
- }else{
20046
- bArgList = useIntern = 0;
20047
- }
2004819936
for(; (c=(*fmt))!=0; ++fmt){
2004919937
if( c!='%' ){
2005019938
int amt;
2005119939
bufpt = (char *)fmt;
2005219940
amt = 1;
@@ -20074,15 +19962,11 @@
2007419962
}
2007519963
}while( !done && (c=(*++fmt))!=0 );
2007619964
/* Get the field width */
2007719965
width = 0;
2007819966
if( c=='*' ){
20079
- if( bArgList ){
20080
- width = (int)getIntArg(pArgList);
20081
- }else{
20082
- width = va_arg(ap,int);
20083
- }
19967
+ width = va_arg(ap,int);
2008419968
if( width<0 ){
2008519969
flag_leftjustify = 1;
2008619970
width = -width;
2008719971
}
2008819972
c = *++fmt;
@@ -20095,15 +19979,11 @@
2009519979
/* Get the precision */
2009619980
if( c=='.' ){
2009719981
precision = 0;
2009819982
c = *++fmt;
2009919983
if( c=='*' ){
20100
- if( bArgList ){
20101
- precision = (int)getIntArg(pArgList);
20102
- }else{
20103
- precision = va_arg(ap,int);
20104
- }
19984
+ precision = va_arg(ap,int);
2010519985
if( precision<0 ) precision = -precision;
2010619986
c = *++fmt;
2010719987
}else{
2010819988
while( c>='0' && c<='9' ){
2010919989
precision = precision*10 + c - '0';
@@ -20130,11 +20010,11 @@
2013020010
infop = &fmtinfo[0];
2013120011
xtype = etINVALID;
2013220012
for(idx=0; idx<ArraySize(fmtinfo); idx++){
2013320013
if( c==fmtinfo[idx].fmttype ){
2013420014
infop = &fmtinfo[idx];
20135
- if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
20015
+ if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
2013620016
xtype = infop->type;
2013720017
}else{
2013820018
return;
2013920019
}
2014020020
break;
@@ -20170,13 +20050,11 @@
2017020050
/* Fall through into the next case */
2017120051
case etORDINAL:
2017220052
case etRADIX:
2017320053
if( infop->flags & FLAG_SIGNED ){
2017420054
i64 v;
20175
- if( bArgList ){
20176
- v = getIntArg(pArgList);
20177
- }else if( flag_longlong ){
20055
+ if( flag_longlong ){
2017820056
v = va_arg(ap,i64);
2017920057
}else if( flag_long ){
2018020058
v = va_arg(ap,long int);
2018120059
}else{
2018220060
v = va_arg(ap,int);
@@ -20193,13 +20071,11 @@
2019320071
if( flag_plussign ) prefix = '+';
2019420072
else if( flag_blanksign ) prefix = ' ';
2019520073
else prefix = 0;
2019620074
}
2019720075
}else{
20198
- if( bArgList ){
20199
- longvalue = (u64)getIntArg(pArgList);
20200
- }else if( flag_longlong ){
20076
+ if( flag_longlong ){
2020120077
longvalue = va_arg(ap,u64);
2020220078
}else if( flag_long ){
2020320079
longvalue = va_arg(ap,unsigned long int);
2020420080
}else{
2020520081
longvalue = va_arg(ap,unsigned int);
@@ -20215,11 +20091,11 @@
2021520091
zOut = buf;
2021620092
}else{
2021720093
nOut = precision + 10;
2021820094
zOut = zExtra = sqlite3Malloc( nOut );
2021920095
if( zOut==0 ){
20220
- setStrAccumError(pAccum, STRACCUM_NOMEM);
20096
+ pAccum->accError = STRACCUM_NOMEM;
2022120097
return;
2022220098
}
2022320099
}
2022420100
bufpt = &zOut[nOut-1];
2022520101
if( xtype==etORDINAL ){
@@ -20255,15 +20131,11 @@
2025520131
length = (int)(&zOut[nOut-1]-bufpt);
2025620132
break;
2025720133
case etFLOAT:
2025820134
case etEXP:
2025920135
case etGENERIC:
20260
- if( bArgList ){
20261
- realvalue = getDoubleArg(pArgList);
20262
- }else{
20263
- realvalue = va_arg(ap,double);
20264
- }
20136
+ realvalue = va_arg(ap,double);
2026520137
#ifdef SQLITE_OMIT_FLOATING_POINT
2026620138
length = 0;
2026720139
#else
2026820140
if( precision<0 ) precision = 6; /* Set default precision */
2026920141
if( realvalue<0.0 ){
@@ -20331,11 +20203,11 @@
2033120203
e2 = exp;
2033220204
}
2033320205
if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
2033420206
bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
2033520207
if( bufpt==0 ){
20336
- setStrAccumError(pAccum, STRACCUM_NOMEM);
20208
+ pAccum->accError = STRACCUM_NOMEM;
2033720209
return;
2033820210
}
2033920211
}
2034020212
zOut = bufpt;
2034120213
nsd = 16 + flag_altform2*10;
@@ -20414,27 +20286,20 @@
2041420286
length = width;
2041520287
}
2041620288
#endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
2041720289
break;
2041820290
case etSIZE:
20419
- if( !bArgList ){
20420
- *(va_arg(ap,int*)) = pAccum->nChar;
20421
- }
20291
+ *(va_arg(ap,int*)) = pAccum->nChar;
2042220292
length = width = 0;
2042320293
break;
2042420294
case etPERCENT:
2042520295
buf[0] = '%';
2042620296
bufpt = buf;
2042720297
length = 1;
2042820298
break;
2042920299
case etCHARX:
20430
- if( bArgList ){
20431
- bufpt = getTextArg(pArgList);
20432
- c = bufpt ? bufpt[0] : 0;
20433
- }else{
20434
- c = va_arg(ap,int);
20435
- }
20300
+ c = va_arg(ap,int);
2043620301
buf[0] = (char)c;
2043720302
if( precision>=0 ){
2043820303
for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
2043920304
length = precision;
2044020305
}else{
@@ -20442,18 +20307,14 @@
2044220307
}
2044320308
bufpt = buf;
2044420309
break;
2044520310
case etSTRING:
2044620311
case etDYNSTRING:
20447
- if( bArgList ){
20448
- bufpt = getTextArg(pArgList);
20449
- }else{
20450
- bufpt = va_arg(ap,char*);
20451
- }
20312
+ bufpt = va_arg(ap,char*);
2045220313
if( bufpt==0 ){
2045320314
bufpt = "";
20454
- }else if( xtype==etDYNSTRING && !bArgList ){
20315
+ }else if( xtype==etDYNSTRING ){
2045520316
zExtra = bufpt;
2045620317
}
2045720318
if( precision>=0 ){
2045820319
for(length=0; length<precision && bufpt[length]; length++){}
2045920320
}else{
@@ -20465,17 +20326,11 @@
2046520326
case etSQLESCAPE3: {
2046620327
int i, j, k, n, isnull;
2046720328
int needQuote;
2046820329
char ch;
2046920330
char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
20470
- char *escarg;
20471
-
20472
- if( bArgList ){
20473
- escarg = getTextArg(pArgList);
20474
- }else{
20475
- escarg = va_arg(ap,char*);
20476
- }
20331
+ char *escarg = va_arg(ap,char*);
2047720332
isnull = escarg==0;
2047820333
if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
2047920334
k = precision;
2048020335
for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
2048120336
if( ch==q ) n++;
@@ -20483,11 +20338,11 @@
2048320338
needQuote = !isnull && xtype==etSQLESCAPE2;
2048420339
n += i + 1 + needQuote*2;
2048520340
if( n>etBUFSIZE ){
2048620341
bufpt = zExtra = sqlite3Malloc( n );
2048720342
if( bufpt==0 ){
20488
- setStrAccumError(pAccum, STRACCUM_NOMEM);
20343
+ pAccum->accError = STRACCUM_NOMEM;
2048920344
return;
2049020345
}
2049120346
}else{
2049220347
bufpt = buf;
2049320348
}
@@ -20506,28 +20361,26 @@
2050620361
** if( precision>=0 && precision<length ) length = precision; */
2050720362
break;
2050820363
}
2050920364
case etTOKEN: {
2051020365
Token *pToken = va_arg(ap, Token*);
20511
- assert( bArgList==0 );
20512
- if( pToken && pToken->n ){
20366
+ if( pToken ){
2051320367
sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
2051420368
}
2051520369
length = width = 0;
2051620370
break;
2051720371
}
2051820372
case etSRCLIST: {
2051920373
SrcList *pSrc = va_arg(ap, SrcList*);
2052020374
int k = va_arg(ap, int);
2052120375
struct SrcList_item *pItem = &pSrc->a[k];
20522
- assert( bArgList==0 );
2052320376
assert( k>=0 && k<pSrc->nSrc );
2052420377
if( pItem->zDatabase ){
20525
- sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
20378
+ sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
2052620379
sqlite3StrAccumAppend(pAccum, ".", 1);
2052720380
}
20528
- sqlite3StrAccumAppendAll(pAccum, pItem->zName);
20381
+ sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
2052920382
length = width = 0;
2053020383
break;
2053120384
}
2053220385
default: {
2053320386
assert( xtype==etINVALID );
@@ -20554,42 +20407,44 @@
2055420407
nspace = width-length;
2055520408
if( nspace>0 ){
2055620409
sqlite3AppendSpace(pAccum, nspace);
2055720410
}
2055820411
}
20559
- if( zExtra ) sqlite3_free(zExtra);
20412
+ sqlite3_free(zExtra);
2056020413
}/* End for loop over the format string */
2056120414
} /* End of function */
2056220415
2056320416
/*
2056420417
** Append N bytes of text from z to the StrAccum object.
2056520418
*/
2056620419
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20567
- assert( z!=0 );
20568
- assert( p->zText!=0 || p->nChar==0 || p->accError );
20569
- assert( N>=0 );
20570
- assert( p->accError==0 || p->nAlloc==0 );
20420
+ assert( z!=0 || N==0 );
20421
+ if( p->accError ){
20422
+ testcase(p->accError==STRACCUM_TOOBIG);
20423
+ testcase(p->accError==STRACCUM_NOMEM);
20424
+ return;
20425
+ }
20426
+ assert( p->zText!=0 || p->nChar==0 );
20427
+ if( N<=0 ){
20428
+ if( N==0 || z[0]==0 ) return;
20429
+ N = sqlite3Strlen30(z);
20430
+ }
2057120431
if( p->nChar+N >= p->nAlloc ){
2057220432
char *zNew;
20573
- if( p->accError ){
20574
- testcase(p->accError==STRACCUM_TOOBIG);
20575
- testcase(p->accError==STRACCUM_NOMEM);
20576
- return;
20577
- }
2057820433
if( !p->useMalloc ){
20434
+ p->accError = STRACCUM_TOOBIG;
2057920435
N = p->nAlloc - p->nChar - 1;
20580
- setStrAccumError(p, STRACCUM_TOOBIG);
2058120436
if( N<=0 ){
2058220437
return;
2058320438
}
2058420439
}else{
2058520440
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
2058620441
i64 szNew = p->nChar;
2058720442
szNew += N + 1;
2058820443
if( szNew > p->mxAlloc ){
2058920444
sqlite3StrAccumReset(p);
20590
- setStrAccumError(p, STRACCUM_TOOBIG);
20445
+ p->accError = STRACCUM_TOOBIG;
2059120446
return;
2059220447
}else{
2059320448
p->nAlloc = (int)szNew;
2059420449
}
2059520450
if( p->useMalloc==1 ){
@@ -20599,28 +20454,20 @@
2059920454
}
2060020455
if( zNew ){
2060120456
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2060220457
p->zText = zNew;
2060320458
}else{
20459
+ p->accError = STRACCUM_NOMEM;
2060420460
sqlite3StrAccumReset(p);
20605
- setStrAccumError(p, STRACCUM_NOMEM);
2060620461
return;
2060720462
}
2060820463
}
2060920464
}
2061020465
assert( p->zText );
2061120466
memcpy(&p->zText[p->nChar], z, N);
2061220467
p->nChar += N;
2061320468
}
20614
-
20615
-/*
20616
-** Append the complete text of zero-terminated string z[] to the p string.
20617
-*/
20618
-SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){
20619
- sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z));
20620
-}
20621
-
2062220469
2062320470
/*
2062420471
** Finish off a string by making sure it is zero-terminated.
2062520472
** Return a pointer to the resulting string. Return a NULL
2062620473
** pointer if any kind of error was encountered.
@@ -20635,11 +20482,11 @@
2063520482
p->zText = sqlite3_malloc(p->nChar+1);
2063620483
}
2063720484
if( p->zText ){
2063820485
memcpy(p->zText, p->zBase, p->nChar+1);
2063920486
}else{
20640
- setStrAccumError(p, STRACCUM_NOMEM);
20487
+ p->accError = STRACCUM_NOMEM;
2064120488
}
2064220489
}
2064320490
}
2064420491
return p->zText;
2064520492
}
@@ -20681,11 +20528,11 @@
2068120528
StrAccum acc;
2068220529
assert( db!=0 );
2068320530
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
2068420531
db->aLimit[SQLITE_LIMIT_LENGTH]);
2068520532
acc.db = db;
20686
- sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
20533
+ sqlite3VXPrintf(&acc, 1, zFormat, ap);
2068720534
z = sqlite3StrAccumFinish(&acc);
2068820535
if( acc.accError==STRACCUM_NOMEM ){
2068920536
db->mallocFailed = 1;
2069020537
}
2069120538
return z;
@@ -20837,19 +20684,21 @@
2083720684
fprintf(stdout,"%s", zBuf);
2083820685
fflush(stdout);
2083920686
}
2084020687
#endif
2084120688
20689
+#ifndef SQLITE_OMIT_TRACE
2084220690
/*
2084320691
** variable-argument wrapper around sqlite3VXPrintf().
2084420692
*/
20845
-SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
20693
+SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){
2084620694
va_list ap;
2084720695
va_start(ap,zFormat);
20848
- sqlite3VXPrintf(p, bFlags, zFormat, ap);
20696
+ sqlite3VXPrintf(p, 1, zFormat, ap);
2084920697
va_end(ap);
2085020698
}
20699
+#endif
2085120700
2085220701
/************** End of printf.c **********************************************/
2085320702
/************** Begin file random.c ******************************************/
2085420703
/*
2085520704
** 2001 September 15
@@ -20902,16 +20751,10 @@
2090220751
#if SQLITE_THREADSAFE
2090320752
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
2090420753
sqlite3_mutex_enter(mutex);
2090520754
#endif
2090620755
20907
- if( N<=0 ){
20908
- wsdPrng.isInit = 0;
20909
- sqlite3_mutex_leave(mutex);
20910
- return;
20911
- }
20912
-
2091320756
/* Initialize the state of the random number generator once,
2091420757
** the first time this routine is called. The seed value does
2091520758
** not need to contain a lot of randomness since we are not
2091620759
** trying to do secure encryption or anything like that...
2091720760
**
@@ -20935,20 +20778,19 @@
2093520778
wsdPrng.s[i] = t;
2093620779
}
2093720780
wsdPrng.isInit = 1;
2093820781
}
2093920782
20940
- assert( N>0 );
20941
- do{
20783
+ while( N-- ){
2094220784
wsdPrng.i++;
2094320785
t = wsdPrng.s[wsdPrng.i];
2094420786
wsdPrng.j += t;
2094520787
wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
2094620788
wsdPrng.s[wsdPrng.j] = t;
2094720789
t += wsdPrng.s[wsdPrng.i];
2094820790
*(zBuf++) = wsdPrng.s[t];
20949
- }while( --N );
20791
+ }
2095020792
sqlite3_mutex_leave(mutex);
2095120793
}
2095220794
2095320795
#ifndef SQLITE_OMIT_BUILTIN_TEST
2095420796
/*
@@ -20973,10 +20815,13 @@
2097320815
&GLOBAL(struct sqlite3PrngType, sqlite3Prng),
2097420816
&GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
2097520817
sizeof(sqlite3Prng)
2097620818
);
2097720819
}
20820
+SQLITE_PRIVATE void sqlite3PrngResetState(void){
20821
+ GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0;
20822
+}
2097820823
#endif /* SQLITE_OMIT_BUILTIN_TEST */
2097920824
2098020825
/************** End of random.c **********************************************/
2098120826
/************** Begin file utf.c *********************************************/
2098220827
/*
@@ -21624,21 +21469,22 @@
2162421469
** To clear the most recent error for sqlite handle "db", sqlite3Error
2162521470
** should be called with err_code set to SQLITE_OK and zFormat set
2162621471
** to NULL.
2162721472
*/
2162821473
SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21629
- assert( db!=0 );
21630
- db->errCode = err_code;
21631
- if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21632
- char *z;
21633
- va_list ap;
21634
- va_start(ap, zFormat);
21635
- z = sqlite3VMPrintf(db, zFormat, ap);
21636
- va_end(ap);
21637
- sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21638
- }else if( db->pErr ){
21639
- sqlite3ValueSetNull(db->pErr);
21474
+ if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21475
+ db->errCode = err_code;
21476
+ if( zFormat ){
21477
+ char *z;
21478
+ va_list ap;
21479
+ va_start(ap, zFormat);
21480
+ z = sqlite3VMPrintf(db, zFormat, ap);
21481
+ va_end(ap);
21482
+ sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21483
+ }else{
21484
+ sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
21485
+ }
2164021486
}
2164121487
}
2164221488
2164321489
/*
2164421490
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
@@ -23119,11 +22965,11 @@
2311922965
/* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
2312022966
/* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
2312122967
/* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
2312222968
/* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
2312322969
/* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23124
- /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
22970
+ /* 30 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
2312522971
/* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
2312622972
/* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
2312722973
/* 33 */ "CollSeq" OpHelp(""),
2312822974
/* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
2312922975
/* 35 */ "MustBeInt" OpHelp(""),
@@ -23510,16 +23356,10 @@
2351023356
*/
2351123357
char aPadding[32];
2351223358
#endif
2351323359
};
2351423360
23515
-/* This variable holds the process id (pid) from when the xRandomness()
23516
-** method was called. If xOpen() is called from a different process id,
23517
-** indicating that a fork() has occurred, the PRNG will be reset.
23518
-*/
23519
-static int randomnessPid = 0;
23520
-
2352123361
/*
2352223362
** Allowed values for the unixFile.ctrlFlags bitmask:
2352323363
*/
2352423364
#define UNIXFILE_EXCL 0x01 /* Connections from one process only */
2352523365
#define UNIXFILE_RDONLY 0x02 /* Connection is read only */
@@ -24779,19 +24619,10 @@
2477924619
}
2478024620
*ppInode = pInode;
2478124621
return SQLITE_OK;
2478224622
}
2478324623
24784
-/*
24785
-** Return TRUE if pFile has been renamed or unlinked since it was first opened.
24786
-*/
24787
-static int fileHasMoved(unixFile *pFile){
24788
- struct stat buf;
24789
- return pFile->pInode!=0 &&
24790
- (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
24791
-}
24792
-
2479324624
2479424625
/*
2479524626
** Check a unixFile that is a database. Verify the following:
2479624627
**
2479724628
** (1) There is exactly one hard link on the file
@@ -24822,11 +24653,14 @@
2482224653
if( buf.st_nlink>1 ){
2482324654
sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
2482424655
pFile->ctrlFlags |= UNIXFILE_WARNED;
2482524656
return;
2482624657
}
24827
- if( fileHasMoved(pFile) ){
24658
+ if( pFile->pInode!=0
24659
+ && ((rc = osStat(pFile->zPath, &buf))!=0
24660
+ || buf.st_ino!=pFile->pInode->fileId.ino)
24661
+ ){
2482824662
sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
2482924663
pFile->ctrlFlags |= UNIXFILE_WARNED;
2483024664
return;
2483124665
}
2483224666
}
@@ -27271,14 +27105,10 @@
2727127105
unixGetTempname(pFile->pVfs->mxPathname, zTFile);
2727227106
*(char**)pArg = zTFile;
2727327107
}
2727427108
return SQLITE_OK;
2727527109
}
27276
- case SQLITE_FCNTL_HAS_MOVED: {
27277
- *(int*)pArg = fileHasMoved(pFile);
27278
- return SQLITE_OK;
27279
- }
2728027110
#if SQLITE_MAX_MMAP_SIZE>0
2728127111
case SQLITE_FCNTL_MMAP_SIZE: {
2728227112
i64 newLimit = *(i64*)pArg;
2728327113
int rc = SQLITE_OK;
2728427114
if( newLimit>sqlite3GlobalConfig.mxMmap ){
@@ -29115,20 +28945,10 @@
2911528945
|| eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
2911628946
|| eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
2911728947
|| eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
2911828948
);
2911928949
29120
- /* Detect a pid change and reset the PRNG. There is a race condition
29121
- ** here such that two or more threads all trying to open databases at
29122
- ** the same instant might all reset the PRNG. But multiple resets
29123
- ** are harmless.
29124
- */
29125
- if( randomnessPid!=getpid() ){
29126
- randomnessPid = getpid();
29127
- sqlite3_randomness(0,0);
29128
- }
29129
-
2913028950
memset(p, 0, sizeof(unixFile));
2913128951
2913228952
if( eType==SQLITE_OPEN_MAIN_DB ){
2913328953
UnixUnusedFd *pUnused;
2913428954
pUnused = findReusableFd(zName, flags);
@@ -29512,22 +29332,22 @@
2951229332
** When testing, initializing zBuf[] to zero is all we do. That means
2951329333
** that we always use the same random number sequence. This makes the
2951429334
** tests repeatable.
2951529335
*/
2951629336
memset(zBuf, 0, nBuf);
29517
- randomnessPid = getpid();
2951829337
#if !defined(SQLITE_TEST)
2951929338
{
29520
- int fd, got;
29339
+ int pid, fd, got;
2952129340
fd = robust_open("/dev/urandom", O_RDONLY, 0);
2952229341
if( fd<0 ){
2952329342
time_t t;
2952429343
time(&t);
2952529344
memcpy(zBuf, &t, sizeof(t));
29526
- memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid));
29527
- assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf );
29528
- nBuf = sizeof(t) + sizeof(randomnessPid);
29345
+ pid = getpid();
29346
+ memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
29347
+ assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
29348
+ nBuf = sizeof(t) + sizeof(pid);
2952929349
}else{
2953029350
do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
2953129351
robust_close(0, fd, __LINE__);
2953229352
}
2953329353
}
@@ -34261,11 +34081,11 @@
3426134081
winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
3426234082
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
3426334083
return SQLITE_OK;
3426434084
}
3426534085
case SQLITE_FCNTL_VFSNAME: {
34266
- *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
34086
+ *(char**)pArg = sqlite3_mprintf("win32");
3426734087
OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
3426834088
return SQLITE_OK;
3426934089
}
3427034090
case SQLITE_FCNTL_WIN32_AV_RETRY: {
3427134091
int *a = (int*)pArg;
@@ -37703,11 +37523,10 @@
3770337523
** in memory.
3770437524
*/
3770537525
struct PgHdr1 {
3770637526
sqlite3_pcache_page page;
3770737527
unsigned int iKey; /* Key value (page number) */
37708
- u8 isPinned; /* Page in use, not on the LRU list */
3770937528
PgHdr1 *pNext; /* Next in hash table chain */
3771037529
PCache1 *pCache; /* Cache that currently owns this page */
3771137530
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
3771237531
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
3771337532
};
@@ -38032,36 +37851,38 @@
3803237851
** This function is used internally to remove the page pPage from the
3803337852
** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
3803437853
** LRU list, then this function is a no-op.
3803537854
**
3803637855
** The PGroup mutex must be held when this function is called.
37856
+**
37857
+** If pPage is NULL then this routine is a no-op.
3803737858
*/
3803837859
static void pcache1PinPage(PgHdr1 *pPage){
3803937860
PCache1 *pCache;
3804037861
PGroup *pGroup;
3804137862
38042
- assert( pPage!=0 );
38043
- assert( pPage->isPinned==0 );
37863
+ if( pPage==0 ) return;
3804437864
pCache = pPage->pCache;
3804537865
pGroup = pCache->pGroup;
38046
- assert( pPage->pLruNext || pPage==pGroup->pLruTail );
38047
- assert( pPage->pLruPrev || pPage==pGroup->pLruHead );
3804837866
assert( sqlite3_mutex_held(pGroup->mutex) );
38049
- if( pPage->pLruPrev ){
38050
- pPage->pLruPrev->pLruNext = pPage->pLruNext;
38051
- }else{
38052
- pGroup->pLruHead = pPage->pLruNext;
38053
- }
38054
- if( pPage->pLruNext ){
38055
- pPage->pLruNext->pLruPrev = pPage->pLruPrev;
38056
- }else{
38057
- pGroup->pLruTail = pPage->pLruPrev;
38058
- }
38059
- pPage->pLruNext = 0;
38060
- pPage->pLruPrev = 0;
38061
- pPage->isPinned = 1;
38062
- pCache->nRecyclable--;
37867
+ if( pPage->pLruNext || pPage==pGroup->pLruTail ){
37868
+ if( pPage->pLruPrev ){
37869
+ pPage->pLruPrev->pLruNext = pPage->pLruNext;
37870
+ }
37871
+ if( pPage->pLruNext ){
37872
+ pPage->pLruNext->pLruPrev = pPage->pLruPrev;
37873
+ }
37874
+ if( pGroup->pLruHead==pPage ){
37875
+ pGroup->pLruHead = pPage->pLruNext;
37876
+ }
37877
+ if( pGroup->pLruTail==pPage ){
37878
+ pGroup->pLruTail = pPage->pLruPrev;
37879
+ }
37880
+ pPage->pLruNext = 0;
37881
+ pPage->pLruPrev = 0;
37882
+ pPage->pCache->nRecyclable--;
37883
+ }
3806337884
}
3806437885
3806537886
3806637887
/*
3806737888
** Remove the page supplied as an argument from the hash table
@@ -38089,11 +37910,10 @@
3808937910
static void pcache1EnforceMaxPage(PGroup *pGroup){
3809037911
assert( sqlite3_mutex_held(pGroup->mutex) );
3809137912
while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
3809237913
PgHdr1 *p = pGroup->pLruTail;
3809337914
assert( p->pCache->pGroup==pGroup );
38094
- assert( p->isPinned==0 );
3809537915
pcache1PinPage(p);
3809637916
pcache1RemoveFromHash(p);
3809737917
pcache1FreePage(p);
3809837918
}
3809937919
}
@@ -38117,11 +37937,11 @@
3811737937
PgHdr1 *pPage;
3811837938
while( (pPage = *pp)!=0 ){
3811937939
if( pPage->iKey>=iLimit ){
3812037940
pCache->nPage--;
3812137941
*pp = pPage->pNext;
38122
- if( !pPage->isPinned ) pcache1PinPage(pPage);
37942
+ pcache1PinPage(pPage);
3812337943
pcache1FreePage(pPage);
3812437944
}else{
3812537945
pp = &pPage->pNext;
3812637946
TESTONLY( nPage++; )
3812737947
}
@@ -38340,15 +38160,12 @@
3834038160
unsigned int h = iKey % pCache->nHash;
3834138161
for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
3834238162
}
3834338163
3834438164
/* Step 2: Abort if no existing page is found and createFlag is 0 */
38345
- if( pPage ){
38346
- if( !pPage->isPinned ) pcache1PinPage(pPage);
38347
- goto fetch_out;
38348
- }
38349
- if( createFlag==0 ){
38165
+ if( pPage || createFlag==0 ){
38166
+ pcache1PinPage(pPage);
3835038167
goto fetch_out;
3835138168
}
3835238169
3835338170
/* The pGroup local variable will normally be initialized by the
3835438171
** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined,
@@ -38385,11 +38202,10 @@
3838538202
|| pGroup->nCurrentPage>=pGroup->nMaxPage
3838638203
|| pcache1UnderMemoryPressure(pCache)
3838738204
)){
3838838205
PCache1 *pOther;
3838938206
pPage = pGroup->pLruTail;
38390
- assert( pPage->isPinned==0 );
3839138207
pcache1RemoveFromHash(pPage);
3839238208
pcache1PinPage(pPage);
3839338209
pOther = pPage->pCache;
3839438210
3839538211
/* We want to verify that szPage and szExtra are the same for pOther
@@ -38422,11 +38238,10 @@
3842238238
pPage->iKey = iKey;
3842338239
pPage->pNext = pCache->apHash[h];
3842438240
pPage->pCache = pCache;
3842538241
pPage->pLruPrev = 0;
3842638242
pPage->pLruNext = 0;
38427
- pPage->isPinned = 1;
3842838243
*(void **)pPage->page.pExtra = 0;
3842938244
pCache->apHash[h] = pPage;
3843038245
}
3843138246
3843238247
fetch_out:
@@ -38458,11 +38273,10 @@
3845838273
/* It is an error to call this function if the page is already
3845938274
** part of the PGroup LRU list.
3846038275
*/
3846138276
assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
3846238277
assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
38463
- assert( pPage->isPinned==1 );
3846438278
3846538279
if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
3846638280
pcache1RemoveFromHash(pPage);
3846738281
pcache1FreePage(pPage);
3846838282
}else{
@@ -38474,11 +38288,10 @@
3847438288
}else{
3847538289
pGroup->pLruTail = pPage;
3847638290
pGroup->pLruHead = pPage;
3847738291
}
3847838292
pCache->nRecyclable++;
38479
- pPage->isPinned = 0;
3848038293
}
3848138294
3848238295
pcache1LeaveMutex(pCache->pGroup);
3848338296
}
3848438297
@@ -38601,11 +38414,10 @@
3860138414
while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
3860238415
nFree += pcache1MemSize(p->page.pBuf);
3860338416
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
3860438417
nFree += sqlite3MemSize(p);
3860538418
#endif
38606
- assert( p->isPinned==0 );
3860738419
pcache1PinPage(p);
3860838420
pcache1RemoveFromHash(p);
3860938421
pcache1FreePage(p);
3861038422
}
3861138423
pcache1LeaveMutex(&pcache1.grp);
@@ -38626,11 +38438,10 @@
3862638438
int *pnRecyclable /* OUT: Total number of pages available for recycling */
3862738439
){
3862838440
PgHdr1 *p;
3862938441
int nRecyclable = 0;
3863038442
for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
38631
- assert( p->isPinned==0 );
3863238443
nRecyclable++;
3863338444
}
3863438445
*pnCurrent = pcache1.grp.nCurrentPage;
3863538446
*pnMax = (int)pcache1.grp.nMaxPage;
3863638447
*pnMin = (int)pcache1.grp.nMinPage;
@@ -40313,26 +40124,29 @@
4031340124
** PagerSavepoint.pInSavepoint.
4031440125
*/
4031540126
static int subjRequiresPage(PgHdr *pPg){
4031640127
Pager *pPager = pPg->pPager;
4031740128
PagerSavepoint *p;
40318
- Pgno pgno = pPg->pgno;
40129
+ Pgno pgno;
4031940130
int i;
40320
- for(i=0; i<pPager->nSavepoint; i++){
40321
- p = &pPager->aSavepoint[i];
40322
- if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40323
- return 1;
40131
+ if( pPager->nSavepoint ){
40132
+ pgno = pPg->pgno;
40133
+ for(i=0; i<pPager->nSavepoint; i++){
40134
+ p = &pPager->aSavepoint[i];
40135
+ if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40136
+ return 1;
40137
+ }
4032440138
}
4032540139
}
4032640140
return 0;
4032740141
}
4032840142
4032940143
/*
4033040144
** Return true if the page is already in the journal file.
4033140145
*/
40332
-static int pageInJournal(Pager *pPager, PgHdr *pPg){
40333
- return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno);
40146
+static int pageInJournal(PgHdr *pPg){
40147
+ return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
4033440148
}
4033540149
4033640150
/*
4033740151
** Read a 32-bit integer from the given file descriptor. Store the integer
4033840152
** that is read in *pRes. Return SQLITE_OK if everything worked, or an
@@ -40535,11 +40349,10 @@
4053540349
4053640350
if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
4053740351
|| szJ<16
4053840352
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
4053940353
|| len>=nMaster
40540
- || len==0
4054140354
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
4054240355
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
4054340356
|| memcmp(aMagic, aJournalMagic, 8)
4054440357
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
4054540358
){
@@ -41276,11 +41089,11 @@
4127641089
sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
4127741090
if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
4127841091
PgHdr *p = pager_lookup(pPager, 1);
4127941092
if( p ){
4128041093
p->pageHash = 0;
41281
- sqlite3PagerUnrefNotNull(p);
41094
+ sqlite3PagerUnref(p);
4128241095
}
4128341096
}
4128441097
#endif
4128541098
4128641099
sqlite3BitvecDestroy(pPager->pInJournal);
@@ -41305,15 +41118,10 @@
4130541118
** required size. */
4130641119
assert( pPager->eLock==EXCLUSIVE_LOCK );
4130741120
rc = pager_truncate(pPager, pPager->dbSize);
4130841121
}
4130941122
41310
- if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){
41311
- rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
41312
- if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
41313
- }
41314
-
4131541123
if( !pPager->exclusiveMode
4131641124
&& (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
4131741125
){
4131841126
rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
4131941127
pPager->changeCountDone = 0;
@@ -42123,11 +41931,11 @@
4212341931
testcase( rc!=SQLITE_OK );
4212441932
}
4212541933
if( rc==SQLITE_OK
4212641934
&& (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
4212741935
){
42128
- rc = sqlite3PagerSync(pPager, 0);
41936
+ rc = sqlite3PagerSync(pPager);
4212941937
}
4213041938
if( rc==SQLITE_OK ){
4213141939
rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
4213241940
testcase( rc!=SQLITE_OK );
4213341941
}
@@ -42269,11 +42077,11 @@
4226942077
rc = readDbPage(pPg, iFrame);
4227042078
}
4227142079
if( rc==SQLITE_OK ){
4227242080
pPager->xReiniter(pPg);
4227342081
}
42274
- sqlite3PagerUnrefNotNull(pPg);
42082
+ sqlite3PagerUnref(pPg);
4227542083
}
4227642084
}
4227742085
4227842086
/* Normally, if a transaction is rolled back, any backup processes are
4227942087
** updated as data is copied out of the rollback journal and into the
@@ -43624,11 +43432,11 @@
4362443432
/* Open the sub-journal, if it has not already been opened */
4362543433
assert( pPager->useJournal );
4362643434
assert( isOpen(pPager->jfd) || pagerUseWal(pPager) );
4362743435
assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
4362843436
assert( pagerUseWal(pPager)
43629
- || pageInJournal(pPager, pPg)
43437
+ || pageInJournal(pPg)
4363043438
|| pPg->pgno>pPager->dbOrigSize
4363143439
);
4363243440
rc = openSubJournal(pPager);
4363343441
4363443442
/* If the sub-journal was opened successfully (or was already open),
@@ -44089,34 +43897,10 @@
4408943897
*ppPager = pPager;
4409043898
return SQLITE_OK;
4409143899
}
4409243900
4409343901
44094
-/* Verify that the database file has not be deleted or renamed out from
44095
-** under the pager. Return SQLITE_OK if the database is still were it ought
44096
-** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error
44097
-** code from sqlite3OsAccess()) if the database has gone missing.
44098
-*/
44099
-static int databaseIsUnmoved(Pager *pPager){
44100
- int bHasMoved = 0;
44101
- int rc;
44102
-
44103
- if( pPager->tempFile ) return SQLITE_OK;
44104
- if( pPager->dbSize==0 ) return SQLITE_OK;
44105
- assert( pPager->zFilename && pPager->zFilename[0] );
44106
- rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved);
44107
- if( rc==SQLITE_NOTFOUND ){
44108
- /* If the HAS_MOVED file-control is unimplemented, assume that the file
44109
- ** has not been moved. That is the historical behavior of SQLite: prior to
44110
- ** version 3.8.3, it never checked */
44111
- rc = SQLITE_OK;
44112
- }else if( rc==SQLITE_OK && bHasMoved ){
44113
- rc = SQLITE_READONLY_DBMOVED;
44114
- }
44115
- return rc;
44116
-}
44117
-
4411843902
4411943903
/*
4412043904
** This function is called after transitioning from PAGER_UNLOCK to
4412143905
** PAGER_SHARED state. It tests if there is a hot journal present in
4412243906
** the file-system for the given pager. A hot journal is one that
@@ -44584,11 +44368,11 @@
4458444368
if( bMmapOk && pagerUseWal(pPager) ){
4458544369
rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
4458644370
if( rc!=SQLITE_OK ) goto pager_acquire_err;
4458744371
}
4458844372
44589
- if( bMmapOk && iFrame==0 ){
44373
+ if( iFrame==0 && bMmapOk ){
4459044374
void *pData = 0;
4459144375
4459244376
rc = sqlite3OsFetch(pPager->fd,
4459344377
(i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
4459444378
);
@@ -44725,23 +44509,20 @@
4472544509
** If the number of references to the page drop to zero, then the
4472644510
** page is added to the LRU list. When all references to all pages
4472744511
** are released, a rollback occurs and the lock on the database is
4472844512
** removed.
4472944513
*/
44730
-SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
44731
- Pager *pPager;
44732
- assert( pPg!=0 );
44733
- pPager = pPg->pPager;
44734
- if( pPg->flags & PGHDR_MMAP ){
44735
- pagerReleaseMapPage(pPg);
44736
- }else{
44737
- sqlite3PcacheRelease(pPg);
44738
- }
44739
- pagerUnlockIfUnused(pPager);
44740
-}
4474144514
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
44742
- if( pPg ) sqlite3PagerUnrefNotNull(pPg);
44515
+ if( pPg ){
44516
+ Pager *pPager = pPg->pPager;
44517
+ if( pPg->flags & PGHDR_MMAP ){
44518
+ pagerReleaseMapPage(pPg);
44519
+ }else{
44520
+ sqlite3PcacheRelease(pPg);
44521
+ }
44522
+ pagerUnlockIfUnused(pPager);
44523
+ }
4474344524
}
4474444525
4474544526
/*
4474644527
** This function is called at the start of every write transaction.
4474744528
** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -44792,23 +44573,17 @@
4479244573
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
4479344574
(pPager->tempFile ?
4479444575
(SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
4479544576
(SQLITE_OPEN_MAIN_JOURNAL)
4479644577
);
44797
-
44798
- /* Verify that the database still has the same name as it did when
44799
- ** it was originally opened. */
44800
- rc = databaseIsUnmoved(pPager);
44801
- if( rc==SQLITE_OK ){
44802
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
44803
- rc = sqlite3JournalOpen(
44804
- pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44805
- );
44806
-#else
44807
- rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44808
-#endif
44809
- }
44578
+ #ifdef SQLITE_ENABLE_ATOMIC_WRITE
44579
+ rc = sqlite3JournalOpen(
44580
+ pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44581
+ );
44582
+ #else
44583
+ rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44584
+ #endif
4481044585
}
4481144586
assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
4481244587
}
4481344588
4481444589
@@ -44925,13 +44700,13 @@
4492544700
** one of the journals, the corresponding bit is set in the
4492644701
** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
4492744702
** of any open savepoints as appropriate.
4492844703
*/
4492944704
static int pager_write(PgHdr *pPg){
44705
+ void *pData = pPg->pData;
4493044706
Pager *pPager = pPg->pPager;
4493144707
int rc = SQLITE_OK;
44932
- int inJournal;
4493344708
4493444709
/* This routine is not called unless a write-transaction has already
4493544710
** been started. The journal file may or may not be open at this point.
4493644711
** It is never called in the ERROR state.
4493744712
*/
@@ -44938,12 +44713,18 @@
4493844713
assert( pPager->eState==PAGER_WRITER_LOCKED
4493944714
|| pPager->eState==PAGER_WRITER_CACHEMOD
4494044715
|| pPager->eState==PAGER_WRITER_DBMOD
4494144716
);
4494244717
assert( assert_pager_state(pPager) );
44943
- assert( pPager->errCode==0 );
44944
- assert( pPager->readOnly==0 );
44718
+
44719
+ /* If an error has been previously detected, report the same error
44720
+ ** again. This should not happen, but the check provides robustness. */
44721
+ if( NEVER(pPager->errCode) ) return pPager->errCode;
44722
+
44723
+ /* Higher-level routines never call this function if database is not
44724
+ ** writable. But check anyway, just for robustness. */
44725
+ if( NEVER(pPager->readOnly) ) return SQLITE_PERM;
4494544726
4494644727
CHECK_PAGE(pPg);
4494744728
4494844729
/* The journal file needs to be opened. Higher level routines have already
4494944730
** obtained the necessary locks to begin the write-transaction, but the
@@ -44963,20 +44744,19 @@
4496344744
4496444745
/* Mark the page as dirty. If the page has already been written
4496544746
** to the journal then we can return right away.
4496644747
*/
4496744748
sqlite3PcacheMakeDirty(pPg);
44968
- inJournal = pageInJournal(pPager, pPg);
44969
- if( inJournal && (pPager->nSavepoint==0 || !subjRequiresPage(pPg)) ){
44749
+ if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){
4497044750
assert( !pagerUseWal(pPager) );
4497144751
}else{
4497244752
4497344753
/* The transaction journal now exists and we have a RESERVED or an
4497444754
** EXCLUSIVE lock on the main database file. Write the current page to
4497544755
** the transaction journal if it is not there already.
4497644756
*/
44977
- if( !inJournal && !pagerUseWal(pPager) ){
44757
+ if( !pageInJournal(pPg) && !pagerUseWal(pPager) ){
4497844758
assert( pagerUseWal(pPager)==0 );
4497944759
if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){
4498044760
u32 cksum;
4498144761
char *pData2;
4498244762
i64 iOff = pPager->journalOff;
@@ -44985,11 +44765,11 @@
4498544765
** contains the database locks. The following assert verifies
4498644766
** that we do not. */
4498744767
assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
4498844768
4498944769
assert( pPager->journalHdr<=pPager->journalOff );
44990
- CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
44770
+ CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
4499144771
cksum = pager_cksum(pPager, (u8*)pData2);
4499244772
4499344773
/* Even if an IO or diskfull error occurs while journalling the
4499444774
** page in the block above, set the need-sync flag for the page.
4499544775
** Otherwise, when the transaction is rolled back, the logic in
@@ -45037,11 +44817,11 @@
4503744817
/* If the statement journal is open and the page is not in it,
4503844818
** then write the current page to the statement journal. Note that
4503944819
** the statement journal format differs from the standard journal format
4504044820
** in that it omits the checksums and the header.
4504144821
*/
45042
- if( pPager->nSavepoint>0 && subjRequiresPage(pPg) ){
44822
+ if( subjRequiresPage(pPg) ){
4504344823
rc = subjournalPage(pPg);
4504444824
}
4504544825
}
4504644826
4504744827
/* Update the database size and return.
@@ -45069,23 +44849,23 @@
4506944849
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
4507044850
int rc = SQLITE_OK;
4507144851
4507244852
PgHdr *pPg = pDbPage;
4507344853
Pager *pPager = pPg->pPager;
44854
+ Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
4507444855
4507544856
assert( (pPg->flags & PGHDR_MMAP)==0 );
4507644857
assert( pPager->eState>=PAGER_WRITER_LOCKED );
4507744858
assert( pPager->eState!=PAGER_ERROR );
4507844859
assert( assert_pager_state(pPager) );
4507944860
45080
- if( pPager->sectorSize > (u32)pPager->pageSize ){
44861
+ if( nPagePerSector>1 ){
4508144862
Pgno nPageCount; /* Total number of pages in database file */
4508244863
Pgno pg1; /* First page of the sector pPg is located on. */
4508344864
int nPage = 0; /* Number of pages starting at pg1 to journal */
4508444865
int ii; /* Loop counter */
4508544866
int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
45086
- Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
4508744867
4508844868
/* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
4508944869
** a journal header to be written between the pages journaled by
4509044870
** this function.
4509144871
*/
@@ -45120,18 +44900,18 @@
4512044900
if( rc==SQLITE_OK ){
4512144901
rc = pager_write(pPage);
4512244902
if( pPage->flags&PGHDR_NEED_SYNC ){
4512344903
needSync = 1;
4512444904
}
45125
- sqlite3PagerUnrefNotNull(pPage);
44905
+ sqlite3PagerUnref(pPage);
4512644906
}
4512744907
}
4512844908
}else if( (pPage = pager_lookup(pPager, pg))!=0 ){
4512944909
if( pPage->flags&PGHDR_NEED_SYNC ){
4513044910
needSync = 1;
4513144911
}
45132
- sqlite3PagerUnrefNotNull(pPage);
44912
+ sqlite3PagerUnref(pPage);
4513344913
}
4513444914
}
4513544915
4513644916
/* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
4513744917
** starting at pg1, then it needs to be set for all of them. Because
@@ -45143,11 +44923,11 @@
4514344923
assert( !MEMDB );
4514444924
for(ii=0; ii<nPage; ii++){
4514544925
PgHdr *pPage = pager_lookup(pPager, pg1+ii);
4514644926
if( pPage ){
4514744927
pPage->flags |= PGHDR_NEED_SYNC;
45148
- sqlite3PagerUnrefNotNull(pPage);
44928
+ sqlite3PagerUnref(pPage);
4514944929
}
4515044930
}
4515144931
}
4515244932
4515344933
assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
@@ -45296,21 +45076,21 @@
4529645076
** or pages with the Pager.noSync flag set.
4529745077
**
4529845078
** If successful, or if called on a pager for which it is a no-op, this
4529945079
** function returns SQLITE_OK. Otherwise, an IO error code is returned.
4530045080
*/
45301
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){
45081
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
4530245082
int rc = SQLITE_OK;
45303
-
45304
- if( isOpen(pPager->fd) ){
45305
- void *pArg = (void*)zMaster;
45306
- rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
45307
- if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
45308
- }
45309
- if( rc==SQLITE_OK && !pPager->noSync ){
45083
+ if( !pPager->noSync ){
4531045084
assert( !MEMDB );
4531145085
rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
45086
+ }else if( isOpen(pPager->fd) ){
45087
+ assert( !MEMDB );
45088
+ rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0);
45089
+ if( rc==SQLITE_NOTFOUND ){
45090
+ rc = SQLITE_OK;
45091
+ }
4531245092
}
4531345093
return rc;
4531445094
}
4531545095
4531645096
/*
@@ -45505,11 +45285,11 @@
4550545285
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
4550645286
}
4550745287
4550845288
/* Finally, sync the database file. */
4550945289
if( !noSync ){
45510
- rc = sqlite3PagerSync(pPager, zMaster);
45290
+ rc = sqlite3PagerSync(pPager);
4551145291
}
4551245292
IOTRACE(("DBSYNC %p\n", pPager))
4551345293
}
4551445294
}
4551545295
@@ -45634,13 +45414,11 @@
4563445414
rc = pager_playback(pPager, 0);
4563545415
}
4563645416
4563745417
assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
4563845418
assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT
45639
- || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
45640
- || rc==SQLITE_CANTOPEN
45641
- );
45419
+ || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR );
4564245420
4564345421
/* If an error occurs during a ROLLBACK, we can no longer trust the pager
4564445422
** cache. So call pager_error() on the way out to make any error persistent.
4564545423
*/
4564645424
return pager_error(pPager, rc);
@@ -46039,11 +45817,11 @@
4603945817
** can be written to. The caller has already promised not to write to it.
4604045818
*/
4604145819
if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
4604245820
needSyncPgno = pPg->pgno;
4604345821
assert( pPager->journalMode==PAGER_JOURNALMODE_OFF ||
46044
- pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
45822
+ pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
4604545823
assert( pPg->flags&PGHDR_DIRTY );
4604645824
}
4604745825
4604845826
/* If the cache contains a page with page-number pgno, remove it
4604945827
** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
@@ -46073,11 +45851,11 @@
4607345851
** as the original page since it has already been allocated.
4607445852
*/
4607545853
if( MEMDB ){
4607645854
assert( pPgOld );
4607745855
sqlite3PcacheMove(pPgOld, origPgno);
46078
- sqlite3PagerUnrefNotNull(pPgOld);
45856
+ sqlite3PagerUnref(pPgOld);
4607945857
}
4608045858
4608145859
if( needSyncPgno ){
4608245860
/* If needSyncPgno is non-zero, then the journal file needs to be
4608345861
** sync()ed before any data is written to database file page needSyncPgno.
@@ -46102,11 +45880,11 @@
4610245880
}
4610345881
return rc;
4610445882
}
4610545883
pPgHdr->flags |= PGHDR_NEED_SYNC;
4610645884
sqlite3PcacheMakeDirty(pPgHdr);
46107
- sqlite3PagerUnrefNotNull(pPgHdr);
45885
+ sqlite3PagerUnref(pPgHdr);
4610845886
}
4610945887
4611045888
return SQLITE_OK;
4611145889
}
4611245890
#endif
@@ -52221,11 +51999,11 @@
5222151999
5222252000
if( pgno>btreePagecount(pBt) ){
5222352001
rc = SQLITE_CORRUPT_BKPT;
5222452002
}else{
5222552003
rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
52226
- if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
52004
+ if( rc==SQLITE_OK ){
5222752005
rc = btreeInitPage(*ppPage);
5222852006
if( rc!=SQLITE_OK ){
5222952007
releasePage(*ppPage);
5223052008
}
5223152009
}
@@ -52242,15 +52020,14 @@
5224252020
*/
5224352021
static void releasePage(MemPage *pPage){
5224452022
if( pPage ){
5224552023
assert( pPage->aData );
5224652024
assert( pPage->pBt );
52247
- assert( pPage->pDbPage!=0 );
5224852025
assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
5224952026
assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
5225052027
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52251
- sqlite3PagerUnrefNotNull(pPage->pDbPage);
52028
+ sqlite3PagerUnref(pPage->pDbPage);
5225252029
}
5225352030
}
5225452031
5225552032
/*
5225652033
** During a rollback, when the pager reloads information into the cache
@@ -54762,14 +54539,14 @@
5476254539
}
5476354540
5476454541
/*
5476554542
** Return a pointer to payload information from the entry that the
5476654543
** pCur cursor is pointing to. The pointer is to the beginning of
54767
-** the key if index btrees (pPage->intKey==0) and is the data for
54768
-** table btrees (pPage->intKey==1). The number of bytes of available
54769
-** key/data is written into *pAmt. If *pAmt==0, then the value
54770
-** returned will not be a valid pointer.
54544
+** the key if skipKey==0 and it points to the beginning of data if
54545
+** skipKey==1. The number of bytes of available key/data is written
54546
+** into *pAmt. If *pAmt==0, then the value returned will not be
54547
+** a valid pointer.
5477154548
**
5477254549
** This routine is an optimization. It is common for the entire key
5477354550
** and data to fit on the local page and for there to be no overflow
5477454551
** pages. When that is so, this routine can be used to access the
5477554552
** key and data without making a copy. If the key and/or data spills
@@ -54778,25 +54555,45 @@
5477854555
**
5477954556
** The pointer returned by this routine looks directly into the cached
5478054557
** page of the database. The data might change or move the next time
5478154558
** any btree routine is called.
5478254559
*/
54783
-static const void *fetchPayload(
54560
+static const unsigned char *fetchPayload(
5478454561
BtCursor *pCur, /* Cursor pointing to entry to read from */
54785
- u32 *pAmt /* Write the number of available bytes here */
54562
+ u32 *pAmt, /* Write the number of available bytes here */
54563
+ int skipKey /* read beginning at data if this is true */
5478654564
){
54565
+ unsigned char *aPayload;
54566
+ MemPage *pPage;
54567
+ u32 nKey;
54568
+ u32 nLocal;
54569
+
5478754570
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
5478854571
assert( pCur->eState==CURSOR_VALID );
54789
- assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5479054572
assert( cursorHoldsMutex(pCur) );
54791
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
54573
+ pPage = pCur->apPage[pCur->iPage];
54574
+ assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
5479254575
if( pCur->info.nSize==0 ){
5479354576
btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
5479454577
&pCur->info);
5479554578
}
54796
- *pAmt = pCur->info.nLocal;
54797
- return (void*)(pCur->info.pCell + pCur->info.nHeader);
54579
+ aPayload = pCur->info.pCell;
54580
+ aPayload += pCur->info.nHeader;
54581
+ if( pPage->intKey ){
54582
+ nKey = 0;
54583
+ }else{
54584
+ nKey = (int)pCur->info.nKey;
54585
+ }
54586
+ if( skipKey ){
54587
+ aPayload += nKey;
54588
+ nLocal = pCur->info.nLocal - nKey;
54589
+ }else{
54590
+ nLocal = pCur->info.nLocal;
54591
+ assert( nLocal<=nKey );
54592
+ }
54593
+ *pAmt = nLocal;
54594
+ return aPayload;
5479854595
}
5479954596
5480054597
5480154598
/*
5480254599
** For the entry that cursor pCur is point to, return as
@@ -54811,14 +54608,26 @@
5481154608
**
5481254609
** These routines is used to get quick access to key and data
5481354610
** in the common case where no overflow pages are used.
5481454611
*/
5481554612
SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
54816
- return fetchPayload(pCur, pAmt);
54613
+ const void *p = 0;
54614
+ assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54615
+ assert( cursorHoldsMutex(pCur) );
54616
+ if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54617
+ p = (const void*)fetchPayload(pCur, pAmt, 0);
54618
+ }
54619
+ return p;
5481754620
}
5481854621
SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
54819
- return fetchPayload(pCur, pAmt);
54622
+ const void *p = 0;
54623
+ assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54624
+ assert( cursorHoldsMutex(pCur) );
54625
+ if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54626
+ p = (const void*)fetchPayload(pCur, pAmt, 1);
54627
+ }
54628
+ return p;
5482054629
}
5482154630
5482254631
5482354632
/*
5482454633
** Move the cursor down to a new child page. The newPgno argument is the
@@ -54933,10 +54742,12 @@
5493354742
** b-tree).
5493454743
*/
5493554744
static int moveToRoot(BtCursor *pCur){
5493654745
MemPage *pRoot;
5493754746
int rc = SQLITE_OK;
54747
+ Btree *p = pCur->pBtree;
54748
+ BtShared *pBt = p->pBt;
5493854749
5493954750
assert( cursorHoldsMutex(pCur) );
5494054751
assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
5494154752
assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
5494254753
assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54947,16 +54758,20 @@
5494754758
}
5494854759
sqlite3BtreeClearCursor(pCur);
5494954760
}
5495054761
5495154762
if( pCur->iPage>=0 ){
54952
- while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]);
54763
+ int i;
54764
+ for(i=1; i<=pCur->iPage; i++){
54765
+ releasePage(pCur->apPage[i]);
54766
+ }
54767
+ pCur->iPage = 0;
5495354768
}else if( pCur->pgnoRoot==0 ){
5495454769
pCur->eState = CURSOR_INVALID;
5495554770
return SQLITE_OK;
5495654771
}else{
54957
- rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
54772
+ rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
5495854773
pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
5495954774
if( rc!=SQLITE_OK ){
5496054775
pCur->eState = CURSOR_INVALID;
5496154776
return rc;
5496254777
}
@@ -54985,20 +54800,18 @@
5498554800
pCur->aiIdx[0] = 0;
5498654801
pCur->info.nSize = 0;
5498754802
pCur->atLast = 0;
5498854803
pCur->validNKey = 0;
5498954804
54990
- if( pRoot->nCell>0 ){
54991
- pCur->eState = CURSOR_VALID;
54992
- }else if( !pRoot->leaf ){
54805
+ if( pRoot->nCell==0 && !pRoot->leaf ){
5499354806
Pgno subpage;
5499454807
if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
5499554808
subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
5499654809
pCur->eState = CURSOR_VALID;
5499754810
rc = moveToChild(pCur, subpage);
5499854811
}else{
54999
- pCur->eState = CURSOR_INVALID;
54812
+ pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
5500054813
}
5500154814
return rc;
5500254815
}
5500354816
5500454817
/*
@@ -55250,18 +55063,21 @@
5525055063
** the entire cell by checking for the cases where the record is
5525155064
** stored entirely within the b-tree page by inspecting the first
5525255065
** 2 bytes of the cell.
5525355066
*/
5525455067
nCell = pCell[0];
55255
- if( nCell<=pPage->max1bytePayload ){
55068
+ if( nCell<=pPage->max1bytePayload
55069
+ /* && (pCell+nCell)<pPage->aDataEnd */
55070
+ ){
5525655071
/* This branch runs if the record-size field of the cell is a
5525755072
** single byte varint and the record fits entirely on the main
5525855073
** b-tree page. */
5525955074
testcase( pCell+nCell+1==pPage->aDataEnd );
5526055075
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
5526155076
}else if( !(pCell[1] & 0x80)
5526255077
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55078
+ /* && (pCell+nCell+2)<=pPage->aDataEnd */
5526355079
){
5526455080
/* The record-size field is a 2 byte varint and the record
5526555081
** fits entirely on the main b-tree page. */
5526655082
testcase( pCell+nCell+2==pPage->aDataEnd );
5526755083
c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -56081,11 +55897,11 @@
5608155897
nHeader = 0;
5608255898
if( !pPage->leaf ){
5608355899
nHeader += 4;
5608455900
}
5608555901
if( pPage->hasData ){
56086
- nHeader += putVarint32(&pCell[nHeader], nData+nZero);
55902
+ nHeader += putVarint(&pCell[nHeader], nData+nZero);
5608755903
}else{
5608855904
nData = nZero = 0;
5608955905
}
5609055906
nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
5609155907
btreeParseCellPtr(pPage, pCell, &info);
@@ -56209,10 +56025,11 @@
5620956025
*/
5621056026
static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
5621156027
u32 pc; /* Offset to cell content of cell being deleted */
5621256028
u8 *data; /* pPage->aData */
5621356029
u8 *ptr; /* Used to move bytes around within data[] */
56030
+ u8 *endPtr; /* End of loop */
5621456031
int rc; /* The return code */
5621556032
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
5621656033
5621756034
if( *pRC ) return;
5621856035
@@ -56232,13 +56049,18 @@
5623256049
}
5623356050
rc = freeSpace(pPage, pc, sz);
5623456051
if( rc ){
5623556052
*pRC = rc;
5623656053
return;
56054
+ }
56055
+ endPtr = &pPage->aCellIdx[2*pPage->nCell - 2];
56056
+ assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
56057
+ while( ptr<endPtr ){
56058
+ *(u16*)ptr = *(u16*)&ptr[2];
56059
+ ptr += 2;
5623756060
}
5623856061
pPage->nCell--;
56239
- memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
5624056062
put2byte(&data[hdr+3], pPage->nCell);
5624156063
pPage->nFree += 2;
5624256064
}
5624356065
5624456066
/*
@@ -56271,10 +56093,13 @@
5627156093
int j; /* Loop counter */
5627256094
int end; /* First byte past the last cell pointer in data[] */
5627356095
int ins; /* Index in data[] where new cell pointer is inserted */
5627456096
int cellOffset; /* Address of first cell pointer in data[] */
5627556097
u8 *data; /* The content of the whole page */
56098
+ u8 *ptr; /* Used for moving information around in data[] */
56099
+ u8 *endPtr; /* End of the loop */
56100
+
5627656101
int nSkip = (iChild ? 4 : 0);
5627756102
5627856103
if( *pRC ) return;
5627956104
5628056105
assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56321,11 +56146,17 @@
5632156146
pPage->nFree -= (u16)(2 + sz);
5632256147
memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
5632356148
if( iChild ){
5632456149
put4byte(&data[idx], iChild);
5632556150
}
56326
- memmove(&data[ins+2], &data[ins], end-ins);
56151
+ ptr = &data[end];
56152
+ endPtr = &data[ins];
56153
+ assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
56154
+ while( ptr>endPtr ){
56155
+ *(u16*)ptr = *(u16*)&ptr[-2];
56156
+ ptr -= 2;
56157
+ }
5632756158
put2byte(&data[ins], idx);
5632856159
put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
5632956160
#ifndef SQLITE_OMIT_AUTOVACUUM
5633056161
if( pPage->pBt->autoVacuum ){
5633156162
/* The cell may contain a pointer to an overflow page. If so, write
@@ -58283,11 +58114,11 @@
5828358114
va_start(ap, zFormat);
5828458115
if( pCheck->errMsg.nChar ){
5828558116
sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
5828658117
}
5828758118
if( zMsg1 ){
58288
- sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
58119
+ sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
5828958120
}
5829058121
sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
5829158122
va_end(ap);
5829258123
if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
5829358124
pCheck->mallocFailed = 1;
@@ -59577,11 +59408,11 @@
5957759408
rc = backupTruncateFile(pFile, iSize);
5957859409
}
5957959410
5958059411
/* Sync the database file to disk. */
5958159412
if( rc==SQLITE_OK ){
59582
- rc = sqlite3PagerSync(pDestPager, 0);
59413
+ rc = sqlite3PagerSync(pDestPager);
5958359414
}
5958459415
}else{
5958559416
sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
5958659417
rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
5958759418
}
@@ -59652,14 +59483,14 @@
5965259483
/* If a transaction is still open on the Btree, roll it back. */
5965359484
sqlite3BtreeRollback(p->pDest, SQLITE_OK);
5965459485
5965559486
/* Set the error code of the destination database handle. */
5965659487
rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
59488
+ sqlite3Error(p->pDestDb, rc, 0);
59489
+
59490
+ /* Exit the mutexes and free the backup context structure. */
5965759491
if( p->pDestDb ){
59658
- sqlite3Error(p->pDestDb, rc, 0);
59659
-
59660
- /* Exit the mutexes and free the backup context structure. */
5966159492
sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
5966259493
}
5966359494
sqlite3BtreeLeave(p->pSrc);
5966459495
if( p->pDestDb ){
5966559496
/* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
@@ -59859,59 +59690,61 @@
5985959690
#endif
5986059691
}
5986159692
5986259693
/*
5986359694
** Make sure pMem->z points to a writable allocation of at least
59864
-** min(n,32) bytes.
59695
+** n bytes.
5986559696
**
59866
-** If the bPreserve argument is true, then copy of the content of
59867
-** pMem->z into the new allocation. pMem must be either a string or
59868
-** blob if bPreserve is true. If bPreserve is false, any prior content
59869
-** in pMem->z is discarded.
59697
+** If the third argument passed to this function is true, then memory
59698
+** cell pMem must contain a string or blob. In this case the content is
59699
+** preserved. Otherwise, if the third parameter to this function is false,
59700
+** any current string or blob value may be discarded.
59701
+**
59702
+** This function sets the MEM_Dyn flag and clears any xDel callback.
59703
+** It also clears MEM_Ephem and MEM_Static. If the preserve flag is
59704
+** not set, Mem.n is zeroed.
5987059705
*/
59871
-SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
59706
+SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
5987259707
assert( 1 >=
5987359708
((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
5987459709
(((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
5987559710
((pMem->flags&MEM_Ephem) ? 1 : 0) +
5987659711
((pMem->flags&MEM_Static) ? 1 : 0)
5987759712
);
5987859713
assert( (pMem->flags&MEM_RowSet)==0 );
5987959714
59880
- /* If the bPreserve flag is set to true, then the memory cell must already
59715
+ /* If the preserve flag is set to true, then the memory cell must already
5988159716
** contain a valid string or blob value. */
59882
- assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
59883
- testcase( bPreserve && pMem->z==0 );
59717
+ assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
5988459718
59885
- if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59886
- if( n<32 ) n = 32;
59887
- if( bPreserve && pMem->z==pMem->zMalloc ){
59719
+ if( n<32 ) n = 32;
59720
+ if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59721
+ if( preserve && pMem->z==pMem->zMalloc ){
5988859722
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59889
- bPreserve = 0;
59723
+ preserve = 0;
5989059724
}else{
5989159725
sqlite3DbFree(pMem->db, pMem->zMalloc);
5989259726
pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
5989359727
}
59894
- if( pMem->zMalloc==0 ){
59895
- sqlite3VdbeMemRelease(pMem);
59896
- pMem->flags = MEM_Null;
59897
- return SQLITE_NOMEM;
59898
- }
5989959728
}
5990059729
59901
- if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
59730
+ if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
5990259731
memcpy(pMem->zMalloc, pMem->z, pMem->n);
5990359732
}
59904
- if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
59733
+ if( pMem->flags&MEM_Dyn && pMem->xDel ){
5990559734
assert( pMem->xDel!=SQLITE_DYNAMIC );
5990659735
pMem->xDel((void *)(pMem->z));
5990759736
}
5990859737
5990959738
pMem->z = pMem->zMalloc;
59910
- pMem->flags &= ~(MEM_Ephem|MEM_Static);
59739
+ if( pMem->z==0 ){
59740
+ pMem->flags = MEM_Null;
59741
+ }else{
59742
+ pMem->flags &= ~(MEM_Ephem|MEM_Static);
59743
+ }
5991159744
pMem->xDel = 0;
59912
- return SQLITE_OK;
59745
+ return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
5991359746
}
5991459747
5991559748
/*
5991659749
** Make the given Mem object MEM_Dyn. In other words, make it so
5991759750
** that any TEXT or BLOB content is stored in memory obtained from
@@ -60093,16 +59926,14 @@
6009359926
** inconsistent state, for example with (Mem.z==0) and
6009459927
** (Mem.type==SQLITE_TEXT).
6009559928
*/
6009659929
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
6009759930
VdbeMemRelease(p);
60098
- if( p->zMalloc ){
60099
- sqlite3DbFree(p->db, p->zMalloc);
60100
- p->zMalloc = 0;
60101
- }
59931
+ sqlite3DbFree(p->db, p->zMalloc);
6010259932
p->z = 0;
60103
- assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */
59933
+ p->zMalloc = 0;
59934
+ p->xDel = 0;
6010459935
}
6010559936
6010659937
/*
6010759938
** Convert a 64-bit IEEE double into a 64-bit signed integer.
6010859939
** If the double is out of range of a 64-bit signed integer then
@@ -60282,13 +60113,10 @@
6028260113
sqlite3RowSetClear(pMem->u.pRowSet);
6028360114
}
6028460115
MemSetTypeFlag(pMem, MEM_Null);
6028560116
pMem->type = SQLITE_NULL;
6028660117
}
60287
-SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60288
- sqlite3VdbeMemSetNull((Mem*)p);
60289
-}
6029060118
6029160119
/*
6029260120
** Delete any previous value and set the value to be a BLOB of length
6029360121
** n containing all zeros.
6029460122
*/
@@ -61022,11 +60850,11 @@
6102260850
if( aRet==0 ){
6102360851
sqlite3_result_error_nomem(context);
6102460852
}else{
6102560853
aRet[0] = nSerial+1;
6102660854
sqlite3PutVarint(&aRet[1], iSerial);
61027
- sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
60855
+ sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
6102860856
sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
6102960857
sqlite3DbFree(db, aRet);
6103060858
}
6103160859
}
6103260860
@@ -61207,12 +61035,11 @@
6120761035
*/
6120861036
6120961037
/*
6121061038
** Create a new virtual database engine.
6121161039
*/
61212
-SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){
61213
- sqlite3 *db = pParse->db;
61040
+SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
6121461041
Vdbe *p;
6121561042
p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
6121661043
if( p==0 ) return 0;
6121761044
p->db = db;
6121861045
if( db->pVdbe ){
@@ -61220,14 +61047,10 @@
6122061047
}
6122161048
p->pNext = db->pVdbe;
6122261049
p->pPrev = 0;
6122361050
db->pVdbe = p;
6122461051
p->magic = VDBE_MAGIC_INIT;
61225
- p->pParse = pParse;
61226
- assert( pParse->aLabel==0 );
61227
- assert( pParse->nLabel==0 );
61228
- assert( pParse->nOpAlloc==0 );
6122961052
return p;
6123061053
}
6123161054
6123261055
/*
6123361056
** Remember the SQL string for a prepared statement.
@@ -61279,18 +61102,17 @@
6127961102
** If an out-of-memory error occurs while resizing the array, return
6128061103
** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
6128161104
** unchanged (this is so that any opcodes already allocated can be
6128261105
** correctly deallocated along with the rest of the Vdbe).
6128361106
*/
61284
-static int growOpArray(Vdbe *v){
61107
+static int growOpArray(Vdbe *p){
6128561108
VdbeOp *pNew;
61286
- Parse *p = v->pParse;
6128761109
int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
61288
- pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
61110
+ pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
6128961111
if( pNew ){
6129061112
p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
61291
- v->aOp = pNew;
61113
+ p->aOp = pNew;
6129261114
}
6129361115
return (pNew ? SQLITE_OK : SQLITE_NOMEM);
6129461116
}
6129561117
6129661118
#ifdef SQLITE_DEBUG
@@ -61325,11 +61147,11 @@
6132561147
VdbeOp *pOp;
6132661148
6132761149
i = p->nOp;
6132861150
assert( p->magic==VDBE_MAGIC_INIT );
6132961151
assert( op>0 && op<0xff );
61330
- if( p->pParse->nOpAlloc<=i ){
61152
+ if( p->nOpAlloc<=i ){
6133161153
if( growOpArray(p) ){
6133261154
return 1;
6133361155
}
6133461156
}
6133561157
p->nOp++;
@@ -61344,19 +61166,10 @@
6134461166
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6134561167
pOp->zComment = 0;
6134661168
#endif
6134761169
#ifdef SQLITE_DEBUG
6134861170
if( p->db->flags & SQLITE_VdbeAddopTrace ){
61349
- int jj, kk;
61350
- Parse *pParse = p->pParse;
61351
- for(jj=kk=0; jj<SQLITE_N_COLCACHE; jj++){
61352
- struct yColCache *x = pParse->aColCache + jj;
61353
- if( x->iLevel>pParse->iCacheLevel || x->iReg==0 ) continue;
61354
- printf(" r[%d]={%d:%d}", x->iReg, x->iTable, x->iColumn);
61355
- kk++;
61356
- }
61357
- if( kk ) printf("\n");
6135861171
sqlite3VdbePrintOp(0, i, &p->aOp[i]);
6135961172
test_addop_breakpoint();
6136061173
}
6136161174
#endif
6136261175
#ifdef VDBE_PROFILE
@@ -61436,14 +61249,13 @@
6143661249
** always negative and P2 values are suppose to be non-negative.
6143761250
** Hence, a negative P2 value is a label that has yet to be resolved.
6143861251
**
6143961252
** Zero is returned if a malloc() fails.
6144061253
*/
61441
-SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){
61442
- Parse *p = v->pParse;
61254
+SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){
6144361255
int i = p->nLabel++;
61444
- assert( v->magic==VDBE_MAGIC_INIT );
61256
+ assert( p->magic==VDBE_MAGIC_INIT );
6144561257
if( (i & (i-1))==0 ){
6144661258
p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
6144761259
(i*2+1)*sizeof(p->aLabel[0]));
6144861260
}
6144961261
if( p->aLabel ){
@@ -61455,17 +61267,16 @@
6145561267
/*
6145661268
** Resolve label "x" to be the address of the next instruction to
6145761269
** be inserted. The parameter "x" must have been obtained from
6145861270
** a prior call to sqlite3VdbeMakeLabel().
6145961271
*/
61460
-SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
61461
- Parse *p = v->pParse;
61272
+SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){
6146261273
int j = -1-x;
61463
- assert( v->magic==VDBE_MAGIC_INIT );
61274
+ assert( p->magic==VDBE_MAGIC_INIT );
6146461275
assert( j<p->nLabel );
6146561276
if( j>=0 && p->aLabel ){
61466
- p->aLabel[j] = v->nOp;
61277
+ p->aLabel[j] = p->nOp;
6146761278
}
6146861279
}
6146961280
6147061281
/*
6147161282
** Mark the VDBE as one that can only be run one time.
@@ -61610,12 +61421,11 @@
6161061421
*/
6161161422
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
6161261423
int i;
6161361424
int nMaxArgs = *pMaxFuncArgs;
6161461425
Op *pOp;
61615
- Parse *pParse = p->pParse;
61616
- int *aLabel = pParse->aLabel;
61426
+ int *aLabel = p->aLabel;
6161761427
p->readOnly = 1;
6161861428
p->bIsReader = 0;
6161961429
for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
6162061430
u8 opcode = pOp->opcode;
6162161431
@@ -61674,17 +61484,16 @@
6167461484
}
6167561485
}
6167661486
6167761487
pOp->opflags = sqlite3OpcodeProperty[opcode];
6167861488
if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
61679
- assert( -1-pOp->p2<pParse->nLabel );
61489
+ assert( -1-pOp->p2<p->nLabel );
6168061490
pOp->p2 = aLabel[-1-pOp->p2];
6168161491
}
6168261492
}
61683
- sqlite3DbFree(p->db, pParse->aLabel);
61684
- pParse->aLabel = 0;
61685
- pParse->nLabel = 0;
61493
+ sqlite3DbFree(p->db, p->aLabel);
61494
+ p->aLabel = 0;
6168661495
*pMaxFuncArgs = nMaxArgs;
6168761496
assert( p->bIsReader!=0 || p->btreeMask==0 );
6168861497
}
6168961498
6169061499
/*
@@ -61724,11 +61533,11 @@
6172461533
** address of the first operation added.
6172561534
*/
6172661535
SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
6172761536
int addr;
6172861537
assert( p->magic==VDBE_MAGIC_INIT );
61729
- if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
61538
+ if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){
6173061539
return 0;
6173161540
}
6173261541
addr = p->nOp;
6173361542
if( ALWAYS(nOp>0) ){
6173461543
int i;
@@ -61913,17 +61722,10 @@
6191361722
pOp->opcode = OP_Noop;
6191461723
if( addr==p->nOp-1 ) p->nOp--;
6191561724
}
6191661725
}
6191761726
61918
-/*
61919
-** Remove the last opcode inserted
61920
-*/
61921
-SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){
61922
- p->nOp--;
61923
-}
61924
-
6192561727
/*
6192661728
** Change the value of the P4 operand for a specific instruction.
6192761729
** This routine is useful when a large program is loaded from a
6192861730
** static array using sqlite3VdbeAddOpList but we want to make a
6192961731
** few minor changes to the program.
@@ -62085,21 +61887,11 @@
6208561887
if( c=='4' ) return pOp->p4.i;
6208661888
return pOp->p5;
6208761889
}
6208861890
6208961891
/*
62090
-** Compute a string for the "comment" field of a VDBE opcode listing.
62091
-**
62092
-** The Synopsis: field in comments in the vdbe.c source file gets converted
62093
-** to an extra string that is appended to the sqlite3OpcodeName(). In the
62094
-** absence of other comments, this synopsis becomes the comment on the opcode.
62095
-** Some translation occurs:
62096
-**
62097
-** "PX" -> "r[X]"
62098
-** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
62099
-** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
62100
-** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x
61892
+** Compute a string for the "comment" field of a VDBE opcode listing
6210161893
*/
6210261894
static int displayComment(
6210361895
const Op *pOp, /* The opcode to be commented */
6210461896
const char *zP4, /* Previously obtained value for P4 */
6210561897
char *zTemp, /* Write result here */
@@ -62129,17 +61921,11 @@
6212961921
sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
6213061922
if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
6213161923
ii += 3;
6213261924
jj += sqlite3Strlen30(zTemp+jj);
6213361925
v2 = translateP(zSynopsis[ii], pOp);
62134
- if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){
62135
- ii += 2;
62136
- v2++;
62137
- }
62138
- if( v2>1 ){
62139
- sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
62140
- }
61926
+ if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
6214161927
}else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
6214261928
ii += 4;
6214361929
}
6214461930
}
6214561931
jj += sqlite3Strlen30(zTemp+jj);
@@ -62367,13 +62153,10 @@
6236762153
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6236862154
displayComment(pOp, zP4, zCom, sizeof(zCom));
6236962155
#else
6237062156
zCom[0] = 0
6237162157
#endif
62372
- /* NB: The sqlite3OpcodeName() function is implemented by code created
62373
- ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
62374
- ** information from the vdbe.c source text */
6237562158
fprintf(pOut, zFormat1, pc,
6237662159
sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
6237762160
zCom
6237862161
);
6237962162
fflush(pOut);
@@ -62801,11 +62584,10 @@
6280162584
6280262585
assert( p!=0 );
6280362586
assert( p->nOp>0 );
6280462587
assert( pParse!=0 );
6280562588
assert( p->magic==VDBE_MAGIC_INIT );
62806
- assert( pParse==p->pParse );
6280762589
db = p->db;
6280862590
assert( db->mallocFailed==0 );
6280962591
nVar = pParse->nVar;
6281062592
nMem = pParse->nMem;
6281162593
nCursor = pParse->nTab;
@@ -62825,12 +62607,12 @@
6282562607
nMem += nCursor;
6282662608
6282762609
/* Allocate space for memory registers, SQL variables, VDBE cursors and
6282862610
** an array to marshal SQL function arguments in.
6282962611
*/
62830
- zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62831
- zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */
62612
+ zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62613
+ zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */
6283262614
6283362615
resolveP2Values(p, &nArg);
6283462616
p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
6283562617
if( pParse->explain && nMem<10 ){
6283662618
nMem = 10;
@@ -63653,11 +63435,10 @@
6365363435
sqlite3 *db = p->db;
6365463436
int rc = p->rc;
6365563437
if( p->zErrMsg ){
6365663438
u8 mallocFailed = db->mallocFailed;
6365763439
sqlite3BeginBenignMalloc();
63658
- if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
6365963440
sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
6366063441
sqlite3EndBenignMalloc();
6366163442
db->mallocFailed = mallocFailed;
6366263443
db->errCode = rc;
6366363444
}else{
@@ -63722,11 +63503,12 @@
6372263503
}else if( p->rc && p->expired ){
6372363504
/* The expired flag was set on the VDBE before the first call
6372463505
** to sqlite3_step(). For consistency (since sqlite3_step() was
6372563506
** called), set the database error in this case as well.
6372663507
*/
63727
- sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
63508
+ sqlite3Error(db, p->rc, 0);
63509
+ sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
6372863510
sqlite3DbFree(db, p->zErrMsg);
6372963511
p->zErrMsg = 0;
6373063512
}
6373163513
6373263514
/* Reclaim all memory used by the VDBE
@@ -63829,10 +63611,11 @@
6382963611
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
6383063612
sqlite3DbFree(db, pSub);
6383163613
}
6383263614
for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
6383363615
vdbeFreeOpArray(db, p->aOp, p->nOp);
63616
+ sqlite3DbFree(db, p->aLabel);
6383463617
sqlite3DbFree(db, p->aColName);
6383563618
sqlite3DbFree(db, p->zSql);
6383663619
sqlite3DbFree(db, p->pFree);
6383763620
#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
6383863621
sqlite3DbFree(db, p->zExplain);
@@ -64059,19 +63842,25 @@
6405963842
/*
6406063843
** Write the serialized data blob for the value stored in pMem into
6406163844
** buf. It is assumed that the caller has allocated sufficient space.
6406263845
** Return the number of bytes written.
6406363846
**
64064
-** nBuf is the amount of space left in buf[]. The caller is responsible
64065
-** for allocating enough space to buf[] to hold the entire field, exclusive
64066
-** of the pMem->u.nZero bytes for a MEM_Zero value.
63847
+** nBuf is the amount of space left in buf[]. nBuf must always be
63848
+** large enough to hold the entire field. Except, if the field is
63849
+** a blob with a zero-filled tail, then buf[] might be just the right
63850
+** size to hold everything except for the zero-filled tail. If buf[]
63851
+** is only big enough to hold the non-zero prefix, then only write that
63852
+** prefix into buf[]. But if buf[] is large enough to hold both the
63853
+** prefix and the tail then write the prefix and set the tail to all
63854
+** zeros.
6406763855
**
6406863856
** Return the number of bytes actually written into buf[]. The number
6406963857
** of bytes in the zero-filled tail is included in the return value only
6407063858
** if those bytes were zeroed in buf[].
6407163859
*/
64072
-SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
63860
+SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
63861
+ u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
6407363862
u32 len;
6407463863
6407563864
/* Integer and Real */
6407663865
if( serial_type<=7 && serial_type>0 ){
6407763866
u64 v;
@@ -64082,10 +63871,11 @@
6408263871
swapMixedEndianFloat(v);
6408363872
}else{
6408463873
v = pMem->u.i;
6408563874
}
6408663875
len = i = sqlite3VdbeSerialTypeLen(serial_type);
63876
+ assert( len<=(u32)nBuf );
6408763877
while( i-- ){
6408863878
buf[i] = (u8)(v&0xFF);
6408963879
v >>= 8;
6409063880
}
6409163881
return len;
@@ -64093,12 +63883,21 @@
6409363883
6409463884
/* String or blob */
6409563885
if( serial_type>=12 ){
6409663886
assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
6409763887
== (int)sqlite3VdbeSerialTypeLen(serial_type) );
63888
+ assert( pMem->n<=nBuf );
6409863889
len = pMem->n;
6409963890
memcpy(buf, pMem->z, len);
63891
+ if( pMem->flags & MEM_Zero ){
63892
+ len += pMem->u.nZero;
63893
+ assert( nBuf>=0 );
63894
+ if( len > (u32)nBuf ){
63895
+ len = (u32)nBuf;
63896
+ }
63897
+ memset(&buf[pMem->n], 0, len-pMem->n);
63898
+ }
6410063899
return len;
6410163900
}
6410263901
6410363902
/* NULL or constants 0 or 1 */
6410463903
return 0;
@@ -65095,21 +64894,20 @@
6509564894
&& (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
6509664895
sqlite3_reset(pStmt);
6509764896
v->doingRerun = 1;
6509864897
assert( v->expired==0 );
6509964898
}
65100
- if( rc2!=SQLITE_OK ){
64899
+ if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
6510164900
/* This case occurs after failing to recompile an sql statement.
6510264901
** The error message from the SQL compiler has already been loaded
6510364902
** into the database handle. This block copies the error message
6510464903
** from the database handle into the statement and sets the statement
6510564904
** program counter to 0 to ensure that when the statement is
6510664905
** finalized or reset the parser error message is available via
6510764906
** sqlite3_errmsg() and sqlite3_errcode().
6510864907
*/
6510964908
const char *zErr = (const char *)sqlite3_value_text(db->pErr);
65110
- assert( zErr!=0 || db->mallocFailed );
6511164909
sqlite3DbFree(db, v->zErrMsg);
6511264910
if( !db->mallocFailed ){
6511364911
v->zErrMsg = sqlite3DbStrDup(db, zErr);
6511464912
v->rc = rc2;
6511564913
} else {
@@ -66021,11 +65819,10 @@
6602165819
if( db->nVdbeExec>1 ){
6602265820
while( *zRawSql ){
6602365821
const char *zStart = zRawSql;
6602465822
while( *(zRawSql++)!='\n' && *zRawSql );
6602565823
sqlite3StrAccumAppend(&out, "-- ", 3);
66026
- assert( (zRawSql - zStart) > 0 );
6602765824
sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
6602865825
}
6602965826
}else{
6603065827
while( zRawSql[0] ){
6603165828
n = findNextHostParameter(zRawSql, &nToken);
@@ -66054,13 +65851,13 @@
6605465851
assert( idx>0 && idx<=p->nVar );
6605565852
pVar = &p->aVar[idx-1];
6605665853
if( pVar->flags & MEM_Null ){
6605765854
sqlite3StrAccumAppend(&out, "NULL", 4);
6605865855
}else if( pVar->flags & MEM_Int ){
66059
- sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
65856
+ sqlite3XPrintf(&out, "%lld", pVar->u.i);
6606065857
}else if( pVar->flags & MEM_Real ){
66061
- sqlite3XPrintf(&out, 0, "%!.15g", pVar->r);
65858
+ sqlite3XPrintf(&out, "%!.15g", pVar->r);
6606265859
}else if( pVar->flags & MEM_Str ){
6606365860
int nOut; /* Number of bytes of the string text to include in output */
6606465861
#ifndef SQLITE_OMIT_UTF16
6606565862
u8 enc = ENC(db);
6606665863
Mem utf8;
@@ -66077,37 +65874,33 @@
6607765874
if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
6607865875
nOut = SQLITE_TRACE_SIZE_LIMIT;
6607965876
while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
6608065877
}
6608165878
#endif
66082
- sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z);
65879
+ sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z);
6608365880
#ifdef SQLITE_TRACE_SIZE_LIMIT
66084
- if( nOut<pVar->n ){
66085
- sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66086
- }
65881
+ if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
6608765882
#endif
6608865883
#ifndef SQLITE_OMIT_UTF16
6608965884
if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
6609065885
#endif
6609165886
}else if( pVar->flags & MEM_Zero ){
66092
- sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero);
65887
+ sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
6609365888
}else{
6609465889
int nOut; /* Number of bytes of the blob to include in output */
6609565890
assert( pVar->flags & MEM_Blob );
6609665891
sqlite3StrAccumAppend(&out, "x'", 2);
6609765892
nOut = pVar->n;
6609865893
#ifdef SQLITE_TRACE_SIZE_LIMIT
6609965894
if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
6610065895
#endif
6610165896
for(i=0; i<nOut; i++){
66102
- sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff);
65897
+ sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
6610365898
}
6610465899
sqlite3StrAccumAppend(&out, "'", 1);
6610565900
#ifdef SQLITE_TRACE_SIZE_LIMIT
66106
- if( nOut<pVar->n ){
66107
- sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66108
- }
65901
+ if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
6610965902
#endif
6611065903
}
6611165904
}
6611265905
}
6611365906
return sqlite3StrAccumFinish(&out);
@@ -66162,11 +65955,11 @@
6616265955
int n = p->nIndent;
6616365956
if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
6616465957
sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
6616565958
}
6616665959
va_start(ap, zFormat);
66167
- sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap);
65960
+ sqlite3VXPrintf(&p->str, 1, zFormat, ap);
6616865961
va_end(ap);
6616965962
}
6617065963
}
6617165964
6617265965
/*
@@ -66869,11 +66662,433 @@
6686966662
i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6687066663
#ifdef VDBE_PROFILE
6687166664
u64 start; /* CPU clock count at start of opcode */
6687266665
int origPc; /* Program counter at start of opcode */
6687366666
#endif
66874
- /*** INSERT STACK UNION HERE ***/
66667
+ /********************************************************************
66668
+ ** Automatically generated code
66669
+ **
66670
+ ** The following union is automatically generated by the
66671
+ ** vdbe-compress.tcl script. The purpose of this union is to
66672
+ ** reduce the amount of stack space required by this function.
66673
+ ** See comments in the vdbe-compress.tcl script for details.
66674
+ */
66675
+ union vdbeExecUnion {
66676
+ struct OP_Yield_stack_vars {
66677
+ int pcDest;
66678
+ } aa;
66679
+ struct OP_Halt_stack_vars {
66680
+ const char *zType;
66681
+ const char *zLogFmt;
66682
+ } ab;
66683
+ struct OP_Null_stack_vars {
66684
+ int cnt;
66685
+ u16 nullFlag;
66686
+ } ac;
66687
+ struct OP_Variable_stack_vars {
66688
+ Mem *pVar; /* Value being transferred */
66689
+ } ad;
66690
+ struct OP_Move_stack_vars {
66691
+ char *zMalloc; /* Holding variable for allocated memory */
66692
+ int n; /* Number of registers left to copy */
66693
+ int p1; /* Register to copy from */
66694
+ int p2; /* Register to copy to */
66695
+ } ae;
66696
+ struct OP_Copy_stack_vars {
66697
+ int n;
66698
+ } af;
66699
+ struct OP_ResultRow_stack_vars {
66700
+ Mem *pMem;
66701
+ int i;
66702
+ } ag;
66703
+ struct OP_Concat_stack_vars {
66704
+ i64 nByte;
66705
+ } ah;
66706
+ struct OP_Remainder_stack_vars {
66707
+ char bIntint; /* Started out as two integer operands */
66708
+ int flags; /* Combined MEM_* flags from both inputs */
66709
+ i64 iA; /* Integer value of left operand */
66710
+ i64 iB; /* Integer value of right operand */
66711
+ double rA; /* Real value of left operand */
66712
+ double rB; /* Real value of right operand */
66713
+ } ai;
66714
+ struct OP_Function_stack_vars {
66715
+ int i;
66716
+ Mem *pArg;
66717
+ sqlite3_context ctx;
66718
+ sqlite3_value **apVal;
66719
+ int n;
66720
+ } aj;
66721
+ struct OP_ShiftRight_stack_vars {
66722
+ i64 iA;
66723
+ u64 uA;
66724
+ i64 iB;
66725
+ u8 op;
66726
+ } ak;
66727
+ struct OP_Ge_stack_vars {
66728
+ int res; /* Result of the comparison of pIn1 against pIn3 */
66729
+ char affinity; /* Affinity to use for comparison */
66730
+ u16 flags1; /* Copy of initial value of pIn1->flags */
66731
+ u16 flags3; /* Copy of initial value of pIn3->flags */
66732
+ } al;
66733
+ struct OP_Compare_stack_vars {
66734
+ int n;
66735
+ int i;
66736
+ int p1;
66737
+ int p2;
66738
+ const KeyInfo *pKeyInfo;
66739
+ int idx;
66740
+ CollSeq *pColl; /* Collating sequence to use on this term */
66741
+ int bRev; /* True for DESCENDING sort order */
66742
+ } am;
66743
+ struct OP_Or_stack_vars {
66744
+ int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66745
+ int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66746
+ } an;
66747
+ struct OP_IfNot_stack_vars {
66748
+ int c;
66749
+ } ao;
66750
+ struct OP_Column_stack_vars {
66751
+ i64 payloadSize64; /* Number of bytes in the record */
66752
+ int p2; /* column number to retrieve */
66753
+ VdbeCursor *pC; /* The VDBE cursor */
66754
+ BtCursor *pCrsr; /* The BTree cursor */
66755
+ u32 *aType; /* aType[i] holds the numeric type of the i-th column */
66756
+ u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
66757
+ int len; /* The length of the serialized data for the column */
66758
+ int i; /* Loop counter */
66759
+ Mem *pDest; /* Where to write the extracted value */
66760
+ Mem sMem; /* For storing the record being decoded */
66761
+ const u8 *zData; /* Part of the record being decoded */
66762
+ const u8 *zHdr; /* Next unparsed byte of the header */
66763
+ const u8 *zEndHdr; /* Pointer to first byte after the header */
66764
+ u32 offset; /* Offset into the data */
66765
+ u32 szField; /* Number of bytes in the content of a field */
66766
+ u32 avail; /* Number of bytes of available data */
66767
+ u32 t; /* A type code from the record header */
66768
+ Mem *pReg; /* PseudoTable input register */
66769
+ } ap;
66770
+ struct OP_Affinity_stack_vars {
66771
+ const char *zAffinity; /* The affinity to be applied */
66772
+ char cAff; /* A single character of affinity */
66773
+ } aq;
66774
+ struct OP_MakeRecord_stack_vars {
66775
+ u8 *zNewRecord; /* A buffer to hold the data for the new record */
66776
+ Mem *pRec; /* The new record */
66777
+ u64 nData; /* Number of bytes of data space */
66778
+ int nHdr; /* Number of bytes of header space */
66779
+ i64 nByte; /* Data space required for this record */
66780
+ int nZero; /* Number of zero bytes at the end of the record */
66781
+ int nVarint; /* Number of bytes in a varint */
66782
+ u32 serial_type; /* Type field */
66783
+ Mem *pData0; /* First field to be combined into the record */
66784
+ Mem *pLast; /* Last field of the record */
66785
+ int nField; /* Number of fields in the record */
66786
+ char *zAffinity; /* The affinity string for the record */
66787
+ int file_format; /* File format to use for encoding */
66788
+ int i; /* Space used in zNewRecord[] */
66789
+ int len; /* Length of a field */
66790
+ } ar;
66791
+ struct OP_Count_stack_vars {
66792
+ i64 nEntry;
66793
+ BtCursor *pCrsr;
66794
+ } as;
66795
+ struct OP_Savepoint_stack_vars {
66796
+ int p1; /* Value of P1 operand */
66797
+ char *zName; /* Name of savepoint */
66798
+ int nName;
66799
+ Savepoint *pNew;
66800
+ Savepoint *pSavepoint;
66801
+ Savepoint *pTmp;
66802
+ int iSavepoint;
66803
+ int ii;
66804
+ } at;
66805
+ struct OP_AutoCommit_stack_vars {
66806
+ int desiredAutoCommit;
66807
+ int iRollback;
66808
+ int turnOnAC;
66809
+ } au;
66810
+ struct OP_Transaction_stack_vars {
66811
+ Btree *pBt;
66812
+ } av;
66813
+ struct OP_ReadCookie_stack_vars {
66814
+ int iMeta;
66815
+ int iDb;
66816
+ int iCookie;
66817
+ } aw;
66818
+ struct OP_SetCookie_stack_vars {
66819
+ Db *pDb;
66820
+ } ax;
66821
+ struct OP_VerifyCookie_stack_vars {
66822
+ int iMeta;
66823
+ int iGen;
66824
+ Btree *pBt;
66825
+ } ay;
66826
+ struct OP_OpenWrite_stack_vars {
66827
+ int nField;
66828
+ KeyInfo *pKeyInfo;
66829
+ int p2;
66830
+ int iDb;
66831
+ int wrFlag;
66832
+ Btree *pX;
66833
+ VdbeCursor *pCur;
66834
+ Db *pDb;
66835
+ } az;
66836
+ struct OP_OpenEphemeral_stack_vars {
66837
+ VdbeCursor *pCx;
66838
+ KeyInfo *pKeyInfo;
66839
+ } ba;
66840
+ struct OP_SorterOpen_stack_vars {
66841
+ VdbeCursor *pCx;
66842
+ } bb;
66843
+ struct OP_OpenPseudo_stack_vars {
66844
+ VdbeCursor *pCx;
66845
+ } bc;
66846
+ struct OP_SeekGt_stack_vars {
66847
+ int res;
66848
+ int oc;
66849
+ VdbeCursor *pC;
66850
+ UnpackedRecord r;
66851
+ int nField;
66852
+ i64 iKey; /* The rowid we are to seek to */
66853
+ } bd;
66854
+ struct OP_Seek_stack_vars {
66855
+ VdbeCursor *pC;
66856
+ } be;
66857
+ struct OP_Found_stack_vars {
66858
+ int alreadyExists;
66859
+ int ii;
66860
+ VdbeCursor *pC;
66861
+ int res;
66862
+ char *pFree;
66863
+ UnpackedRecord *pIdxKey;
66864
+ UnpackedRecord r;
66865
+ char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
66866
+ } bf;
66867
+ struct OP_NotExists_stack_vars {
66868
+ VdbeCursor *pC;
66869
+ BtCursor *pCrsr;
66870
+ int res;
66871
+ u64 iKey;
66872
+ } bg;
66873
+ struct OP_NewRowid_stack_vars {
66874
+ i64 v; /* The new rowid */
66875
+ VdbeCursor *pC; /* Cursor of table to get the new rowid */
66876
+ int res; /* Result of an sqlite3BtreeLast() */
66877
+ int cnt; /* Counter to limit the number of searches */
66878
+ Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
66879
+ VdbeFrame *pFrame; /* Root frame of VDBE */
66880
+ } bh;
66881
+ struct OP_InsertInt_stack_vars {
66882
+ Mem *pData; /* MEM cell holding data for the record to be inserted */
66883
+ Mem *pKey; /* MEM cell holding key for the record */
66884
+ i64 iKey; /* The integer ROWID or key for the record to be inserted */
66885
+ VdbeCursor *pC; /* Cursor to table into which insert is written */
66886
+ int nZero; /* Number of zero-bytes to append */
66887
+ int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
66888
+ const char *zDb; /* database name - used by the update hook */
66889
+ const char *zTbl; /* Table name - used by the opdate hook */
66890
+ int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
66891
+ } bi;
66892
+ struct OP_Delete_stack_vars {
66893
+ i64 iKey;
66894
+ VdbeCursor *pC;
66895
+ } bj;
66896
+ struct OP_SorterCompare_stack_vars {
66897
+ VdbeCursor *pC;
66898
+ int res;
66899
+ int nIgnore;
66900
+ } bk;
66901
+ struct OP_SorterData_stack_vars {
66902
+ VdbeCursor *pC;
66903
+ } bl;
66904
+ struct OP_RowData_stack_vars {
66905
+ VdbeCursor *pC;
66906
+ BtCursor *pCrsr;
66907
+ u32 n;
66908
+ i64 n64;
66909
+ } bm;
66910
+ struct OP_Rowid_stack_vars {
66911
+ VdbeCursor *pC;
66912
+ i64 v;
66913
+ sqlite3_vtab *pVtab;
66914
+ const sqlite3_module *pModule;
66915
+ } bn;
66916
+ struct OP_NullRow_stack_vars {
66917
+ VdbeCursor *pC;
66918
+ } bo;
66919
+ struct OP_Last_stack_vars {
66920
+ VdbeCursor *pC;
66921
+ BtCursor *pCrsr;
66922
+ int res;
66923
+ } bp;
66924
+ struct OP_Rewind_stack_vars {
66925
+ VdbeCursor *pC;
66926
+ BtCursor *pCrsr;
66927
+ int res;
66928
+ } bq;
66929
+ struct OP_SorterNext_stack_vars {
66930
+ VdbeCursor *pC;
66931
+ int res;
66932
+ } br;
66933
+ struct OP_IdxInsert_stack_vars {
66934
+ VdbeCursor *pC;
66935
+ BtCursor *pCrsr;
66936
+ int nKey;
66937
+ const char *zKey;
66938
+ } bs;
66939
+ struct OP_IdxDelete_stack_vars {
66940
+ VdbeCursor *pC;
66941
+ BtCursor *pCrsr;
66942
+ int res;
66943
+ UnpackedRecord r;
66944
+ } bt;
66945
+ struct OP_IdxRowid_stack_vars {
66946
+ BtCursor *pCrsr;
66947
+ VdbeCursor *pC;
66948
+ i64 rowid;
66949
+ } bu;
66950
+ struct OP_IdxGE_stack_vars {
66951
+ VdbeCursor *pC;
66952
+ int res;
66953
+ UnpackedRecord r;
66954
+ } bv;
66955
+ struct OP_Destroy_stack_vars {
66956
+ int iMoved;
66957
+ int iCnt;
66958
+ Vdbe *pVdbe;
66959
+ int iDb;
66960
+ } bw;
66961
+ struct OP_Clear_stack_vars {
66962
+ int nChange;
66963
+ } bx;
66964
+ struct OP_CreateTable_stack_vars {
66965
+ int pgno;
66966
+ int flags;
66967
+ Db *pDb;
66968
+ } by;
66969
+ struct OP_ParseSchema_stack_vars {
66970
+ int iDb;
66971
+ const char *zMaster;
66972
+ char *zSql;
66973
+ InitData initData;
66974
+ } bz;
66975
+ struct OP_IntegrityCk_stack_vars {
66976
+ int nRoot; /* Number of tables to check. (Number of root pages.) */
66977
+ int *aRoot; /* Array of rootpage numbers for tables to be checked */
66978
+ int j; /* Loop counter */
66979
+ int nErr; /* Number of errors reported */
66980
+ char *z; /* Text of the error report */
66981
+ Mem *pnErr; /* Register keeping track of errors remaining */
66982
+ } ca;
66983
+ struct OP_RowSetRead_stack_vars {
66984
+ i64 val;
66985
+ } cb;
66986
+ struct OP_RowSetTest_stack_vars {
66987
+ int iSet;
66988
+ int exists;
66989
+ } cc;
66990
+ struct OP_Program_stack_vars {
66991
+ int nMem; /* Number of memory registers for sub-program */
66992
+ int nByte; /* Bytes of runtime space required for sub-program */
66993
+ Mem *pRt; /* Register to allocate runtime space */
66994
+ Mem *pMem; /* Used to iterate through memory cells */
66995
+ Mem *pEnd; /* Last memory cell in new array */
66996
+ VdbeFrame *pFrame; /* New vdbe frame to execute in */
66997
+ SubProgram *pProgram; /* Sub-program to execute */
66998
+ void *t; /* Token identifying trigger */
66999
+ } cd;
67000
+ struct OP_Param_stack_vars {
67001
+ VdbeFrame *pFrame;
67002
+ Mem *pIn;
67003
+ } ce;
67004
+ struct OP_MemMax_stack_vars {
67005
+ Mem *pIn1;
67006
+ VdbeFrame *pFrame;
67007
+ } cf;
67008
+ struct OP_AggStep_stack_vars {
67009
+ int n;
67010
+ int i;
67011
+ Mem *pMem;
67012
+ Mem *pRec;
67013
+ sqlite3_context ctx;
67014
+ sqlite3_value **apVal;
67015
+ } cg;
67016
+ struct OP_AggFinal_stack_vars {
67017
+ Mem *pMem;
67018
+ } ch;
67019
+ struct OP_Checkpoint_stack_vars {
67020
+ int i; /* Loop counter */
67021
+ int aRes[3]; /* Results */
67022
+ Mem *pMem; /* Write results here */
67023
+ } ci;
67024
+ struct OP_JournalMode_stack_vars {
67025
+ Btree *pBt; /* Btree to change journal mode of */
67026
+ Pager *pPager; /* Pager associated with pBt */
67027
+ int eNew; /* New journal mode */
67028
+ int eOld; /* The old journal mode */
67029
+#ifndef SQLITE_OMIT_WAL
67030
+ const char *zFilename; /* Name of database file for pPager */
67031
+#endif
67032
+ } cj;
67033
+ struct OP_IncrVacuum_stack_vars {
67034
+ Btree *pBt;
67035
+ } ck;
67036
+ struct OP_VBegin_stack_vars {
67037
+ VTable *pVTab;
67038
+ } cl;
67039
+ struct OP_VOpen_stack_vars {
67040
+ VdbeCursor *pCur;
67041
+ sqlite3_vtab_cursor *pVtabCursor;
67042
+ sqlite3_vtab *pVtab;
67043
+ sqlite3_module *pModule;
67044
+ } cm;
67045
+ struct OP_VFilter_stack_vars {
67046
+ int nArg;
67047
+ int iQuery;
67048
+ const sqlite3_module *pModule;
67049
+ Mem *pQuery;
67050
+ Mem *pArgc;
67051
+ sqlite3_vtab_cursor *pVtabCursor;
67052
+ sqlite3_vtab *pVtab;
67053
+ VdbeCursor *pCur;
67054
+ int res;
67055
+ int i;
67056
+ Mem **apArg;
67057
+ } cn;
67058
+ struct OP_VColumn_stack_vars {
67059
+ sqlite3_vtab *pVtab;
67060
+ const sqlite3_module *pModule;
67061
+ Mem *pDest;
67062
+ sqlite3_context sContext;
67063
+ } co;
67064
+ struct OP_VNext_stack_vars {
67065
+ sqlite3_vtab *pVtab;
67066
+ const sqlite3_module *pModule;
67067
+ int res;
67068
+ VdbeCursor *pCur;
67069
+ } cp;
67070
+ struct OP_VRename_stack_vars {
67071
+ sqlite3_vtab *pVtab;
67072
+ Mem *pName;
67073
+ } cq;
67074
+ struct OP_VUpdate_stack_vars {
67075
+ sqlite3_vtab *pVtab;
67076
+ sqlite3_module *pModule;
67077
+ int nArg;
67078
+ int i;
67079
+ sqlite_int64 rowid;
67080
+ Mem **apArg;
67081
+ Mem *pX;
67082
+ } cr;
67083
+ struct OP_Trace_stack_vars {
67084
+ char *zTrace;
67085
+ char *z;
67086
+ } cs;
67087
+ } u;
67088
+ /* End automatically generated code
67089
+ ********************************************************************/
6687567090
6687667091
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
6687767092
sqlite3VdbeEnter(p);
6687867093
if( p->rc==SQLITE_NOMEM ){
6687967094
/* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67115,18 +67330,20 @@
6711567330
/* Opcode: Yield P1 * * * *
6711667331
**
6711767332
** Swap the program counter with the value in register P1.
6711867333
*/
6711967334
case OP_Yield: { /* in1 */
67335
+#if 0 /* local variables moved into u.aa */
6712067336
int pcDest;
67337
+#endif /* local variables moved into u.aa */
6712167338
pIn1 = &aMem[pOp->p1];
6712267339
assert( (pIn1->flags & MEM_Dyn)==0 );
6712367340
pIn1->flags = MEM_Int;
67124
- pcDest = (int)pIn1->u.i;
67341
+ u.aa.pcDest = (int)pIn1->u.i;
6712567342
pIn1->u.i = pc;
6712667343
REGISTER_TRACE(pOp->p1, pIn1);
67127
- pc = pcDest;
67344
+ pc = u.aa.pcDest;
6712867345
break;
6712967346
}
6713067347
6713167348
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
6713267349
** Synopsis: if r[P3] null then halt
@@ -67171,12 +67388,14 @@
6717167388
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
6717267389
** every program. So a jump past the last instruction of the program
6717367390
** is the same as executing Halt.
6717467391
*/
6717567392
case OP_Halt: {
67393
+#if 0 /* local variables moved into u.ab */
6717667394
const char *zType;
6717767395
const char *zLogFmt;
67396
+#endif /* local variables moved into u.ab */
6717867397
6717967398
if( pOp->p1==SQLITE_OK && p->pFrame ){
6718067399
/* Halt the sub-program. Return control to the parent frame. */
6718167400
VdbeFrame *pFrame = p->pFrame;
6718267401
p->pFrame = pFrame->pParent;
@@ -67183,11 +67402,11 @@
6718367402
p->nFrame--;
6718467403
sqlite3VdbeSetChanges(db, p->nChange);
6718567404
pc = sqlite3VdbeFrameRestore(pFrame);
6718667405
lastRowid = db->lastRowid;
6718767406
if( pOp->p2==OE_Ignore ){
67188
- /* Instruction pc is the OP_Program that invoked the sub-program
67407
+ /* Instruction pc is the OP_Program that invoked the sub-program
6718967408
** currently being halted. If the p2 instruction of this OP_Halt
6719067409
** instruction is set to OE_Ignore, then the sub-program is throwing
6719167410
** an IGNORE exception. In this case jump to the address specified
6719267411
** as the p2 of the calling OP_Program. */
6719367412
pc = p->aOp[pc].p2-1;
@@ -67206,25 +67425,25 @@
6720667425
assert( pOp->p5>=1 && pOp->p5<=4 );
6720767426
testcase( pOp->p5==1 );
6720867427
testcase( pOp->p5==2 );
6720967428
testcase( pOp->p5==3 );
6721067429
testcase( pOp->p5==4 );
67211
- zType = azType[pOp->p5-1];
67430
+ u.ab.zType = azType[pOp->p5-1];
6721267431
}else{
67213
- zType = 0;
67432
+ u.ab.zType = 0;
6721467433
}
67215
- assert( zType!=0 || pOp->p4.z!=0 );
67216
- zLogFmt = "abort at %d in [%s]: %s";
67217
- if( zType && pOp->p4.z ){
67218
- sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67219
- zType, pOp->p4.z);
67434
+ assert( u.ab.zType!=0 || pOp->p4.z!=0 );
67435
+ u.ab.zLogFmt = "abort at %d in [%s]: %s";
67436
+ if( u.ab.zType && pOp->p4.z ){
67437
+ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67438
+ u.ab.zType, pOp->p4.z);
6722067439
}else if( pOp->p4.z ){
6722167440
sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
6722267441
}else{
67223
- sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
67442
+ sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
6722467443
}
67225
- sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
67444
+ sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
6722667445
}
6722767446
rc = sqlite3VdbeHalt(p);
6722867447
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
6722967448
if( rc==SQLITE_BUSY ){
6723067449
p->rc = rc = SQLITE_BUSY;
@@ -67334,21 +67553,23 @@
6733467553
** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
6733567554
** NULL values will not compare equal even if SQLITE_NULLEQ is set on
6733667555
** OP_Ne or OP_Eq.
6733767556
*/
6733867557
case OP_Null: { /* out2-prerelease */
67558
+#if 0 /* local variables moved into u.ac */
6733967559
int cnt;
6734067560
u16 nullFlag;
67341
- cnt = pOp->p3-pOp->p2;
67561
+#endif /* local variables moved into u.ac */
67562
+ u.ac.cnt = pOp->p3-pOp->p2;
6734267563
assert( pOp->p3<=(p->nMem-p->nCursor) );
67343
- pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67344
- while( cnt>0 ){
67564
+ pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67565
+ while( u.ac.cnt>0 ){
6734567566
pOut++;
6734667567
memAboutToChange(p, pOut);
6734767568
VdbeMemRelease(pOut);
67348
- pOut->flags = nullFlag;
67349
- cnt--;
67569
+ pOut->flags = u.ac.nullFlag;
67570
+ u.ac.cnt--;
6735067571
}
6735167572
break;
6735267573
}
6735367574
6735467575
@@ -67373,19 +67594,21 @@
6737367594
**
6737467595
** If the parameter is named, then its name appears in P4 and P3==1.
6737567596
** The P4 value is used by sqlite3_bind_parameter_name().
6737667597
*/
6737767598
case OP_Variable: { /* out2-prerelease */
67599
+#if 0 /* local variables moved into u.ad */
6737867600
Mem *pVar; /* Value being transferred */
67601
+#endif /* local variables moved into u.ad */
6737967602
6738067603
assert( pOp->p1>0 && pOp->p1<=p->nVar );
6738167604
assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67382
- pVar = &p->aVar[pOp->p1 - 1];
67383
- if( sqlite3VdbeMemTooBig(pVar) ){
67605
+ u.ad.pVar = &p->aVar[pOp->p1 - 1];
67606
+ if( sqlite3VdbeMemTooBig(u.ad.pVar) ){
6738467607
goto too_big;
6738567608
}
67386
- sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
67609
+ sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
6738767610
UPDATE_MAX_BLOBSIZE(pOut);
6738867611
break;
6738967612
}
6739067613
6739167614
/* Opcode: Move P1 P2 P3 * *
@@ -67395,67 +67618,71 @@
6739567618
** registers P2..P2+P3. Registers P1..P1+P3 are
6739667619
** left holding a NULL. It is an error for register ranges
6739767620
** P1..P1+P3 and P2..P2+P3 to overlap.
6739867621
*/
6739967622
case OP_Move: {
67623
+#if 0 /* local variables moved into u.ae */
6740067624
char *zMalloc; /* Holding variable for allocated memory */
6740167625
int n; /* Number of registers left to copy */
6740267626
int p1; /* Register to copy from */
6740367627
int p2; /* Register to copy to */
67404
-
67405
- n = pOp->p3;
67406
- p1 = pOp->p1;
67407
- p2 = pOp->p2;
67408
- assert( n>=0 && p1>0 && p2>0 );
67409
- assert( p1+n<=p2 || p2+n<=p1 );
67410
-
67411
- pIn1 = &aMem[p1];
67412
- pOut = &aMem[p2];
67628
+#endif /* local variables moved into u.ae */
67629
+
67630
+ u.ae.n = pOp->p3;
67631
+ u.ae.p1 = pOp->p1;
67632
+ u.ae.p2 = pOp->p2;
67633
+ assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 );
67634
+ assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67635
+
67636
+ pIn1 = &aMem[u.ae.p1];
67637
+ pOut = &aMem[u.ae.p2];
6741367638
do{
6741467639
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6741567640
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6741667641
assert( memIsValid(pIn1) );
6741767642
memAboutToChange(p, pOut);
67418
- zMalloc = pOut->zMalloc;
67643
+ u.ae.zMalloc = pOut->zMalloc;
6741967644
pOut->zMalloc = 0;
6742067645
sqlite3VdbeMemMove(pOut, pIn1);
6742167646
#ifdef SQLITE_DEBUG
67422
- if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
67423
- pOut->pScopyFrom += p1 - pOp->p2;
67647
+ if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){
67648
+ pOut->pScopyFrom += u.ae.p1 - pOp->p2;
6742467649
}
6742567650
#endif
67426
- pIn1->zMalloc = zMalloc;
67427
- REGISTER_TRACE(p2++, pOut);
67651
+ pIn1->zMalloc = u.ae.zMalloc;
67652
+ REGISTER_TRACE(u.ae.p2++, pOut);
6742867653
pIn1++;
6742967654
pOut++;
67430
- }while( n-- );
67655
+ }while( u.ae.n-- );
6743167656
break;
6743267657
}
6743367658
6743467659
/* Opcode: Copy P1 P2 P3 * *
67435
-** Synopsis: r[P2@P3+1]=r[P1@P3+1]
67660
+** Synopsis: r[P2@P3]=r[P1@P3]
6743667661
**
6743767662
** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
6743867663
**
6743967664
** This instruction makes a deep copy of the value. A duplicate
6744067665
** is made of any string or blob constant. See also OP_SCopy.
6744167666
*/
6744267667
case OP_Copy: {
67668
+#if 0 /* local variables moved into u.af */
6744367669
int n;
67670
+#endif /* local variables moved into u.af */
6744467671
67445
- n = pOp->p3;
67672
+ u.af.n = pOp->p3;
6744667673
pIn1 = &aMem[pOp->p1];
6744767674
pOut = &aMem[pOp->p2];
6744867675
assert( pOut!=pIn1 );
6744967676
while( 1 ){
6745067677
sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
6745167678
Deephemeralize(pOut);
6745267679
#ifdef SQLITE_DEBUG
6745367680
pOut->pScopyFrom = 0;
6745467681
#endif
67455
- REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
67456
- if( (n--)==0 ) break;
67682
+ REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut);
67683
+ if( (u.af.n--)==0 ) break;
6745767684
pOut++;
6745867685
pIn1++;
6745967686
}
6746067687
break;
6746167688
}
@@ -67492,12 +67719,14 @@
6749267719
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
6749367720
** structure to provide access to the top P1 values as the result
6749467721
** row.
6749567722
*/
6749667723
case OP_ResultRow: {
67724
+#if 0 /* local variables moved into u.ag */
6749767725
Mem *pMem;
6749867726
int i;
67727
+#endif /* local variables moved into u.ag */
6749967728
assert( p->nResColumn==pOp->p2 );
6750067729
assert( pOp->p1>0 );
6750167730
assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
6750267731
6750367732
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -67519,12 +67748,12 @@
6751967748
assert( db->flags&SQLITE_CountRows );
6752067749
assert( p->usesStmtJournal );
6752167750
break;
6752267751
}
6752367752
67524
- /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67525
- ** DML statements invoke this opcode to return the number of rows
67753
+ /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67754
+ ** DML statements invoke this opcode to return the number of rows
6752667755
** modified to the user. This is the only way that a VM that
6752767756
** opens a statement transaction may invoke this opcode.
6752867757
**
6752967758
** In case this is such a statement, close any statement transaction
6753067759
** opened by this VM before returning control to the user. This is to
@@ -67547,19 +67776,19 @@
6754767776
6754867777
/* Make sure the results of the current row are \000 terminated
6754967778
** and have an assigned type. The results are de-ephemeralized as
6755067779
** a side effect.
6755167780
*/
67552
- pMem = p->pResultSet = &aMem[pOp->p1];
67553
- for(i=0; i<pOp->p2; i++){
67554
- assert( memIsValid(&pMem[i]) );
67555
- Deephemeralize(&pMem[i]);
67556
- assert( (pMem[i].flags & MEM_Ephem)==0
67557
- || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
67558
- sqlite3VdbeMemNulTerminate(&pMem[i]);
67559
- sqlite3VdbeMemStoreType(&pMem[i]);
67560
- REGISTER_TRACE(pOp->p1+i, &pMem[i]);
67781
+ u.ag.pMem = p->pResultSet = &aMem[pOp->p1];
67782
+ for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){
67783
+ assert( memIsValid(&u.ag.pMem[u.ag.i]) );
67784
+ Deephemeralize(&u.ag.pMem[u.ag.i]);
67785
+ assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0
67786
+ || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 );
67787
+ sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]);
67788
+ sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]);
67789
+ REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]);
6756167790
}
6756267791
if( db->mallocFailed ) goto no_mem;
6756367792
6756467793
/* Return SQLITE_ROW
6756567794
*/
@@ -67580,11 +67809,13 @@
6758067809
** It is illegal for P1 and P3 to be the same register. Sometimes,
6758167810
** if P3 is the same register as P2, the implementation is able
6758267811
** to avoid a memcpy().
6758367812
*/
6758467813
case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67814
+#if 0 /* local variables moved into u.ah */
6758567815
i64 nByte;
67816
+#endif /* local variables moved into u.ah */
6758667817
6758767818
pIn1 = &aMem[pOp->p1];
6758867819
pIn2 = &aMem[pOp->p2];
6758967820
pOut = &aMem[pOp->p3];
6759067821
assert( pIn1!=pOut );
@@ -67593,26 +67824,26 @@
6759367824
break;
6759467825
}
6759567826
if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
6759667827
Stringify(pIn1, encoding);
6759767828
Stringify(pIn2, encoding);
67598
- nByte = pIn1->n + pIn2->n;
67599
- if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67829
+ u.ah.nByte = pIn1->n + pIn2->n;
67830
+ if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6760067831
goto too_big;
6760167832
}
6760267833
MemSetTypeFlag(pOut, MEM_Str);
67603
- if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
67834
+ if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
6760467835
goto no_mem;
6760567836
}
6760667837
if( pOut!=pIn2 ){
6760767838
memcpy(pOut->z, pIn2->z, pIn2->n);
6760867839
}
6760967840
memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67610
- pOut->z[nByte]=0;
67611
- pOut->z[nByte+1] = 0;
67841
+ pOut->z[u.ah.nByte]=0;
67842
+ pOut->z[u.ah.nByte+1] = 0;
6761267843
pOut->flags |= MEM_Term;
67613
- pOut->n = (int)nByte;
67844
+ pOut->n = (int)u.ah.nByte;
6761467845
pOut->enc = encoding;
6761567846
UPDATE_MAX_BLOBSIZE(pOut);
6761667847
break;
6761767848
}
6761867849
@@ -67657,81 +67888,83 @@
6765767888
case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
6765867889
case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
6765967890
case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
6766067891
case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
6766167892
case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67893
+#if 0 /* local variables moved into u.ai */
6766267894
char bIntint; /* Started out as two integer operands */
6766367895
int flags; /* Combined MEM_* flags from both inputs */
6766467896
i64 iA; /* Integer value of left operand */
6766567897
i64 iB; /* Integer value of right operand */
6766667898
double rA; /* Real value of left operand */
6766767899
double rB; /* Real value of right operand */
67900
+#endif /* local variables moved into u.ai */
6766867901
6766967902
pIn1 = &aMem[pOp->p1];
6767067903
applyNumericAffinity(pIn1);
6767167904
pIn2 = &aMem[pOp->p2];
6767267905
applyNumericAffinity(pIn2);
6767367906
pOut = &aMem[pOp->p3];
67674
- flags = pIn1->flags | pIn2->flags;
67675
- if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67907
+ u.ai.flags = pIn1->flags | pIn2->flags;
67908
+ if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
6767667909
if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67677
- iA = pIn1->u.i;
67678
- iB = pIn2->u.i;
67679
- bIntint = 1;
67910
+ u.ai.iA = pIn1->u.i;
67911
+ u.ai.iB = pIn2->u.i;
67912
+ u.ai.bIntint = 1;
6768067913
switch( pOp->opcode ){
67681
- case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
67682
- case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
67683
- case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break;
67914
+ case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67915
+ case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67916
+ case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
6768467917
case OP_Divide: {
67685
- if( iA==0 ) goto arithmetic_result_is_null;
67686
- if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math;
67687
- iB /= iA;
67918
+ if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67919
+ if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math;
67920
+ u.ai.iB /= u.ai.iA;
6768867921
break;
6768967922
}
6769067923
default: {
67691
- if( iA==0 ) goto arithmetic_result_is_null;
67692
- if( iA==-1 ) iA = 1;
67693
- iB %= iA;
67924
+ if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67925
+ if( u.ai.iA==-1 ) u.ai.iA = 1;
67926
+ u.ai.iB %= u.ai.iA;
6769467927
break;
6769567928
}
6769667929
}
67697
- pOut->u.i = iB;
67930
+ pOut->u.i = u.ai.iB;
6769867931
MemSetTypeFlag(pOut, MEM_Int);
6769967932
}else{
67700
- bIntint = 0;
67933
+ u.ai.bIntint = 0;
6770167934
fp_math:
67702
- rA = sqlite3VdbeRealValue(pIn1);
67703
- rB = sqlite3VdbeRealValue(pIn2);
67935
+ u.ai.rA = sqlite3VdbeRealValue(pIn1);
67936
+ u.ai.rB = sqlite3VdbeRealValue(pIn2);
6770467937
switch( pOp->opcode ){
67705
- case OP_Add: rB += rA; break;
67706
- case OP_Subtract: rB -= rA; break;
67707
- case OP_Multiply: rB *= rA; break;
67938
+ case OP_Add: u.ai.rB += u.ai.rA; break;
67939
+ case OP_Subtract: u.ai.rB -= u.ai.rA; break;
67940
+ case OP_Multiply: u.ai.rB *= u.ai.rA; break;
6770867941
case OP_Divide: {
6770967942
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67710
- if( rA==(double)0 ) goto arithmetic_result_is_null;
67711
- rB /= rA;
67943
+ if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null;
67944
+ u.ai.rB /= u.ai.rA;
6771267945
break;
6771367946
}
6771467947
default: {
67715
- iA = (i64)rA;
67716
- iB = (i64)rB;
67717
- if( iA==0 ) goto arithmetic_result_is_null;
67718
- if( iA==-1 ) iA = 1;
67719
- rB = (double)(iB % iA);
67948
+ u.ai.iA = (i64)u.ai.rA;
67949
+ u.ai.iB = (i64)u.ai.rB;
67950
+ if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67951
+ if( u.ai.iA==-1 ) u.ai.iA = 1;
67952
+ u.ai.rB = (double)(u.ai.iB % u.ai.iA);
6772067953
break;
6772167954
}
6772267955
}
6772367956
#ifdef SQLITE_OMIT_FLOATING_POINT
67724
- pOut->u.i = rB;
67957
+ pOut->u.i = u.ai.rB;
6772567958
MemSetTypeFlag(pOut, MEM_Int);
6772667959
#else
67727
- if( sqlite3IsNaN(rB) ){
67960
+ if( sqlite3IsNaN(u.ai.rB) ){
6772867961
goto arithmetic_result_is_null;
6772967962
}
67730
- pOut->r = rB;
67963
+ pOut->r = u.ai.rB;
6773167964
MemSetTypeFlag(pOut, MEM_Real);
67732
- if( (flags & MEM_Real)==0 && !bIntint ){
67965
+ if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
6773367966
sqlite3VdbeIntegerAffinity(pOut);
6773467967
}
6773567968
#endif
6773667969
}
6773767970
break;
@@ -67780,83 +68013,85 @@
6778068013
** invocation of this opcode.
6778168014
**
6778268015
** See also: AggStep and AggFinal
6778368016
*/
6778468017
case OP_Function: {
68018
+#if 0 /* local variables moved into u.aj */
6778568019
int i;
6778668020
Mem *pArg;
6778768021
sqlite3_context ctx;
6778868022
sqlite3_value **apVal;
6778968023
int n;
68024
+#endif /* local variables moved into u.aj */
6779068025
67791
- n = pOp->p5;
67792
- apVal = p->apArg;
67793
- assert( apVal || n==0 );
68026
+ u.aj.n = pOp->p5;
68027
+ u.aj.apVal = p->apArg;
68028
+ assert( u.aj.apVal || u.aj.n==0 );
6779468029
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
6779568030
pOut = &aMem[pOp->p3];
6779668031
memAboutToChange(p, pOut);
6779768032
67798
- assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) );
67799
- assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
67800
- pArg = &aMem[pOp->p2];
67801
- for(i=0; i<n; i++, pArg++){
67802
- assert( memIsValid(pArg) );
67803
- apVal[i] = pArg;
67804
- Deephemeralize(pArg);
67805
- sqlite3VdbeMemStoreType(pArg);
67806
- REGISTER_TRACE(pOp->p2+i, pArg);
68033
+ assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) );
68034
+ assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n );
68035
+ u.aj.pArg = &aMem[pOp->p2];
68036
+ for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){
68037
+ assert( memIsValid(u.aj.pArg) );
68038
+ u.aj.apVal[u.aj.i] = u.aj.pArg;
68039
+ Deephemeralize(u.aj.pArg);
68040
+ sqlite3VdbeMemStoreType(u.aj.pArg);
68041
+ REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
6780768042
}
6780868043
6780968044
assert( pOp->p4type==P4_FUNCDEF );
67810
- ctx.pFunc = pOp->p4.pFunc;
67811
- ctx.iOp = pc;
67812
- ctx.pVdbe = p;
68045
+ u.aj.ctx.pFunc = pOp->p4.pFunc;
68046
+ u.aj.ctx.iOp = pc;
68047
+ u.aj.ctx.pVdbe = p;
6781368048
6781468049
/* The output cell may already have a buffer allocated. Move
67815
- ** the pointer to ctx.s so in case the user-function can use
68050
+ ** the pointer to u.aj.ctx.s so in case the user-function can use
6781668051
** the already allocated buffer instead of allocating a new one.
6781768052
*/
67818
- memcpy(&ctx.s, pOut, sizeof(Mem));
68053
+ memcpy(&u.aj.ctx.s, pOut, sizeof(Mem));
6781968054
pOut->flags = MEM_Null;
6782068055
pOut->xDel = 0;
6782168056
pOut->zMalloc = 0;
67822
- MemSetTypeFlag(&ctx.s, MEM_Null);
68057
+ MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
6782368058
67824
- ctx.fErrorOrAux = 0;
67825
- if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
68059
+ u.aj.ctx.fErrorOrAux = 0;
68060
+ if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
6782668061
assert( pOp>aOp );
6782768062
assert( pOp[-1].p4type==P4_COLLSEQ );
6782868063
assert( pOp[-1].opcode==OP_CollSeq );
67829
- ctx.pColl = pOp[-1].p4.pColl;
68064
+ u.aj.ctx.pColl = pOp[-1].p4.pColl;
6783068065
}
6783168066
db->lastRowid = lastRowid;
67832
- (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
68067
+ (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */
6783368068
lastRowid = db->lastRowid;
6783468069
6783568070
if( db->mallocFailed ){
6783668071
/* Even though a malloc() has failed, the implementation of the
6783768072
** user function may have called an sqlite3_result_XXX() function
6783868073
** to return a value. The following call releases any resources
6783968074
** associated with such a value.
6784068075
*/
67841
- sqlite3VdbeMemRelease(&ctx.s);
68076
+ sqlite3VdbeMemRelease(&u.aj.ctx.s);
6784268077
goto no_mem;
6784368078
}
6784468079
6784568080
/* If the function returned an error, throw an exception */
67846
- if( ctx.fErrorOrAux ){
67847
- if( ctx.isError ){
67848
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
67849
- rc = ctx.isError;
68081
+ if( u.aj.ctx.fErrorOrAux ){
68082
+ if( u.aj.ctx.isError ){
68083
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s));
68084
+ rc = u.aj.ctx.isError;
6785068085
}
6785168086
sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
6785268087
}
6785368088
6785468089
/* Copy the result of the function into register P3 */
67855
- sqlite3VdbeChangeEncoding(&ctx.s, encoding);
68090
+ sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
6785668091
assert( pOut->flags==MEM_Null );
67857
- memcpy(pOut, &ctx.s, sizeof(Mem));
68092
+ memcpy(pOut, &u.aj.ctx.s, sizeof(Mem));
6785868093
if( sqlite3VdbeMemTooBig(pOut) ){
6785968094
goto too_big;
6786068095
}
6786168096
6786268097
#if 0
@@ -67904,54 +68139,56 @@
6790468139
*/
6790568140
case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
6790668141
case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
6790768142
case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
6790868143
case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
68144
+#if 0 /* local variables moved into u.ak */
6790968145
i64 iA;
6791068146
u64 uA;
6791168147
i64 iB;
6791268148
u8 op;
68149
+#endif /* local variables moved into u.ak */
6791368150
6791468151
pIn1 = &aMem[pOp->p1];
6791568152
pIn2 = &aMem[pOp->p2];
6791668153
pOut = &aMem[pOp->p3];
6791768154
if( (pIn1->flags | pIn2->flags) & MEM_Null ){
6791868155
sqlite3VdbeMemSetNull(pOut);
6791968156
break;
6792068157
}
67921
- iA = sqlite3VdbeIntValue(pIn2);
67922
- iB = sqlite3VdbeIntValue(pIn1);
67923
- op = pOp->opcode;
67924
- if( op==OP_BitAnd ){
67925
- iA &= iB;
67926
- }else if( op==OP_BitOr ){
67927
- iA |= iB;
67928
- }else if( iB!=0 ){
67929
- assert( op==OP_ShiftRight || op==OP_ShiftLeft );
68158
+ u.ak.iA = sqlite3VdbeIntValue(pIn2);
68159
+ u.ak.iB = sqlite3VdbeIntValue(pIn1);
68160
+ u.ak.op = pOp->opcode;
68161
+ if( u.ak.op==OP_BitAnd ){
68162
+ u.ak.iA &= u.ak.iB;
68163
+ }else if( u.ak.op==OP_BitOr ){
68164
+ u.ak.iA |= u.ak.iB;
68165
+ }else if( u.ak.iB!=0 ){
68166
+ assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft );
6793068167
6793168168
/* If shifting by a negative amount, shift in the other direction */
67932
- if( iB<0 ){
68169
+ if( u.ak.iB<0 ){
6793368170
assert( OP_ShiftRight==OP_ShiftLeft+1 );
67934
- op = 2*OP_ShiftLeft + 1 - op;
67935
- iB = iB>(-64) ? -iB : 64;
68171
+ u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op;
68172
+ u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64;
6793668173
}
6793768174
67938
- if( iB>=64 ){
67939
- iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
67940
- }else{
67941
- memcpy(&uA, &iA, sizeof(uA));
67942
- if( op==OP_ShiftLeft ){
67943
- uA <<= iB;
67944
- }else{
67945
- uA >>= iB;
68175
+ if( u.ak.iB>=64 ){
68176
+ u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1;
68177
+ }else{
68178
+ memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA));
68179
+ if( u.ak.op==OP_ShiftLeft ){
68180
+ u.ak.uA <<= u.ak.iB;
68181
+ }else{
68182
+ u.ak.uA >>= u.ak.iB;
6794668183
/* Sign-extend on a right shift of a negative number */
67947
- if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
68184
+ if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB);
6794868185
}
67949
- memcpy(&iA, &uA, sizeof(iA));
68186
+ memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
6795068187
}
6795168188
}
67952
- pOut->u.i = iA;
68189
+ pOut->u.i = u.ak.iA;
6795368190
MemSetTypeFlag(pOut, MEM_Int);
6795468191
break;
6795568192
}
6795668193
6795768194
/* Opcode: AddImm P1 P2 * * *
@@ -68201,35 +68438,37 @@
6820168438
case OP_Ne: /* same as TK_NE, jump, in1, in3 */
6820268439
case OP_Lt: /* same as TK_LT, jump, in1, in3 */
6820368440
case OP_Le: /* same as TK_LE, jump, in1, in3 */
6820468441
case OP_Gt: /* same as TK_GT, jump, in1, in3 */
6820568442
case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
68443
+#if 0 /* local variables moved into u.al */
6820668444
int res; /* Result of the comparison of pIn1 against pIn3 */
6820768445
char affinity; /* Affinity to use for comparison */
6820868446
u16 flags1; /* Copy of initial value of pIn1->flags */
6820968447
u16 flags3; /* Copy of initial value of pIn3->flags */
68448
+#endif /* local variables moved into u.al */
6821068449
6821168450
pIn1 = &aMem[pOp->p1];
6821268451
pIn3 = &aMem[pOp->p3];
68213
- flags1 = pIn1->flags;
68214
- flags3 = pIn3->flags;
68215
- if( (flags1 | flags3)&MEM_Null ){
68452
+ u.al.flags1 = pIn1->flags;
68453
+ u.al.flags3 = pIn3->flags;
68454
+ if( (u.al.flags1 | u.al.flags3)&MEM_Null ){
6821668455
/* One or both operands are NULL */
6821768456
if( pOp->p5 & SQLITE_NULLEQ ){
6821868457
/* If SQLITE_NULLEQ is set (which will only happen if the operator is
6821968458
** OP_Eq or OP_Ne) then take the jump or not depending on whether
6822068459
** or not both operands are null.
6822168460
*/
6822268461
assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68223
- assert( (flags1 & MEM_Cleared)==0 );
68224
- if( (flags1&MEM_Null)!=0
68225
- && (flags3&MEM_Null)!=0
68226
- && (flags3&MEM_Cleared)==0
68462
+ assert( (u.al.flags1 & MEM_Cleared)==0 );
68463
+ if( (u.al.flags1&MEM_Null)!=0
68464
+ && (u.al.flags3&MEM_Null)!=0
68465
+ && (u.al.flags3&MEM_Cleared)==0
6822768466
){
68228
- res = 0; /* Results are equal */
68467
+ u.al.res = 0; /* Results are equal */
6822968468
}else{
68230
- res = 1; /* Results are not equal */
68469
+ u.al.res = 1; /* Results are not equal */
6823168470
}
6823268471
}else{
6823368472
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
6823468473
** then the result is always NULL.
6823568474
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68243,44 +68482,44 @@
6824368482
}
6824468483
break;
6824568484
}
6824668485
}else{
6824768486
/* Neither operand is NULL. Do a comparison. */
68248
- affinity = pOp->p5 & SQLITE_AFF_MASK;
68249
- if( affinity ){
68250
- applyAffinity(pIn1, affinity, encoding);
68251
- applyAffinity(pIn3, affinity, encoding);
68487
+ u.al.affinity = pOp->p5 & SQLITE_AFF_MASK;
68488
+ if( u.al.affinity ){
68489
+ applyAffinity(pIn1, u.al.affinity, encoding);
68490
+ applyAffinity(pIn3, u.al.affinity, encoding);
6825268491
if( db->mallocFailed ) goto no_mem;
6825368492
}
6825468493
6825568494
assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
6825668495
ExpandBlob(pIn1);
6825768496
ExpandBlob(pIn3);
68258
- res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68497
+ u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
6825968498
}
6826068499
switch( pOp->opcode ){
68261
- case OP_Eq: res = res==0; break;
68262
- case OP_Ne: res = res!=0; break;
68263
- case OP_Lt: res = res<0; break;
68264
- case OP_Le: res = res<=0; break;
68265
- case OP_Gt: res = res>0; break;
68266
- default: res = res>=0; break;
68500
+ case OP_Eq: u.al.res = u.al.res==0; break;
68501
+ case OP_Ne: u.al.res = u.al.res!=0; break;
68502
+ case OP_Lt: u.al.res = u.al.res<0; break;
68503
+ case OP_Le: u.al.res = u.al.res<=0; break;
68504
+ case OP_Gt: u.al.res = u.al.res>0; break;
68505
+ default: u.al.res = u.al.res>=0; break;
6826768506
}
6826868507
6826968508
if( pOp->p5 & SQLITE_STOREP2 ){
6827068509
pOut = &aMem[pOp->p2];
6827168510
memAboutToChange(p, pOut);
6827268511
MemSetTypeFlag(pOut, MEM_Int);
68273
- pOut->u.i = res;
68512
+ pOut->u.i = u.al.res;
6827468513
REGISTER_TRACE(pOp->p2, pOut);
68275
- }else if( res ){
68514
+ }else if( u.al.res ){
6827668515
pc = pOp->p2-1;
6827768516
}
6827868517
6827968518
/* Undo any changes made by applyAffinity() to the input registers. */
68280
- pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68281
- pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68519
+ pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask);
68520
+ pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask);
6828268521
break;
6828368522
}
6828468523
6828568524
/* Opcode: Permutation * * * P4 *
6828668525
**
@@ -68316,49 +68555,51 @@
6831668555
** The comparison is a sort comparison, so NULLs compare equal,
6831768556
** NULLs are less than numbers, numbers are less than strings,
6831868557
** and strings are less than blobs.
6831968558
*/
6832068559
case OP_Compare: {
68560
+#if 0 /* local variables moved into u.am */
6832168561
int n;
6832268562
int i;
6832368563
int p1;
6832468564
int p2;
6832568565
const KeyInfo *pKeyInfo;
6832668566
int idx;
6832768567
CollSeq *pColl; /* Collating sequence to use on this term */
6832868568
int bRev; /* True for DESCENDING sort order */
68569
+#endif /* local variables moved into u.am */
6832968570
6833068571
if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68331
- n = pOp->p3;
68332
- pKeyInfo = pOp->p4.pKeyInfo;
68333
- assert( n>0 );
68334
- assert( pKeyInfo!=0 );
68335
- p1 = pOp->p1;
68336
- p2 = pOp->p2;
68572
+ u.am.n = pOp->p3;
68573
+ u.am.pKeyInfo = pOp->p4.pKeyInfo;
68574
+ assert( u.am.n>0 );
68575
+ assert( u.am.pKeyInfo!=0 );
68576
+ u.am.p1 = pOp->p1;
68577
+ u.am.p2 = pOp->p2;
6833768578
#if SQLITE_DEBUG
6833868579
if( aPermute ){
6833968580
int k, mx = 0;
68340
- for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68341
- assert( p1>0 && p1+mx<=(p->nMem-p->nCursor)+1 );
68342
- assert( p2>0 && p2+mx<=(p->nMem-p->nCursor)+1 );
68581
+ for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68582
+ assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 );
68583
+ assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 );
6834368584
}else{
68344
- assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 );
68345
- assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 );
68585
+ assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 );
68586
+ assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 );
6834668587
}
6834768588
#endif /* SQLITE_DEBUG */
68348
- for(i=0; i<n; i++){
68349
- idx = aPermute ? aPermute[i] : i;
68350
- assert( memIsValid(&aMem[p1+idx]) );
68351
- assert( memIsValid(&aMem[p2+idx]) );
68352
- REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
68353
- REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
68354
- assert( i<pKeyInfo->nField );
68355
- pColl = pKeyInfo->aColl[i];
68356
- bRev = pKeyInfo->aSortOrder[i];
68357
- iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
68589
+ for(u.am.i=0; u.am.i<u.am.n; u.am.i++){
68590
+ u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i;
68591
+ assert( memIsValid(&aMem[u.am.p1+u.am.idx]) );
68592
+ assert( memIsValid(&aMem[u.am.p2+u.am.idx]) );
68593
+ REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]);
68594
+ REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]);
68595
+ assert( u.am.i<u.am.pKeyInfo->nField );
68596
+ u.am.pColl = u.am.pKeyInfo->aColl[u.am.i];
68597
+ u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i];
68598
+ iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl);
6835868599
if( iCompare ){
68359
- if( bRev ) iCompare = -iCompare;
68600
+ if( u.am.bRev ) iCompare = -iCompare;
6836068601
break;
6836168602
}
6836268603
}
6836368604
aPermute = 0;
6836468605
break;
@@ -68401,37 +68642,39 @@
6840168642
** even if the other input is NULL. A NULL and false or two NULLs
6840268643
** give a NULL output.
6840368644
*/
6840468645
case OP_And: /* same as TK_AND, in1, in2, out3 */
6840568646
case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68647
+#if 0 /* local variables moved into u.an */
6840668648
int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
6840768649
int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68650
+#endif /* local variables moved into u.an */
6840868651
6840968652
pIn1 = &aMem[pOp->p1];
6841068653
if( pIn1->flags & MEM_Null ){
68411
- v1 = 2;
68654
+ u.an.v1 = 2;
6841268655
}else{
68413
- v1 = sqlite3VdbeIntValue(pIn1)!=0;
68656
+ u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
6841468657
}
6841568658
pIn2 = &aMem[pOp->p2];
6841668659
if( pIn2->flags & MEM_Null ){
68417
- v2 = 2;
68660
+ u.an.v2 = 2;
6841868661
}else{
68419
- v2 = sqlite3VdbeIntValue(pIn2)!=0;
68662
+ u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
6842068663
}
6842168664
if( pOp->opcode==OP_And ){
6842268665
static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68423
- v1 = and_logic[v1*3+v2];
68666
+ u.an.v1 = and_logic[u.an.v1*3+u.an.v2];
6842468667
}else{
6842568668
static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68426
- v1 = or_logic[v1*3+v2];
68669
+ u.an.v1 = or_logic[u.an.v1*3+u.an.v2];
6842768670
}
6842868671
pOut = &aMem[pOp->p3];
68429
- if( v1==2 ){
68672
+ if( u.an.v1==2 ){
6843068673
MemSetTypeFlag(pOut, MEM_Null);
6843168674
}else{
68432
- pOut->u.i = v1;
68675
+ pOut->u.i = u.an.v1;
6843368676
MemSetTypeFlag(pOut, MEM_Int);
6843468677
}
6843568678
break;
6843668679
}
6843768680
@@ -68498,23 +68741,25 @@
6849868741
** is considered false if it has a numeric value of zero. If the value
6849968742
** in P1 is NULL then take the jump if P3 is zero.
6850068743
*/
6850168744
case OP_If: /* jump, in1 */
6850268745
case OP_IfNot: { /* jump, in1 */
68746
+#if 0 /* local variables moved into u.ao */
6850368747
int c;
68748
+#endif /* local variables moved into u.ao */
6850468749
pIn1 = &aMem[pOp->p1];
6850568750
if( pIn1->flags & MEM_Null ){
68506
- c = pOp->p3;
68751
+ u.ao.c = pOp->p3;
6850768752
}else{
6850868753
#ifdef SQLITE_OMIT_FLOATING_POINT
68509
- c = sqlite3VdbeIntValue(pIn1)!=0;
68754
+ u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
6851068755
#else
68511
- c = sqlite3VdbeRealValue(pIn1)!=0.0;
68756
+ u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
6851268757
#endif
68513
- if( pOp->opcode==OP_IfNot ) c = !c;
68758
+ if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
6851468759
}
68515
- if( c ){
68760
+ if( u.ao.c ){
6851668761
pc = pOp->p2-1;
6851768762
}
6851868763
break;
6851968764
}
6852068765
@@ -68568,10 +68813,11 @@
6856868813
** the result is guaranteed to only be used as the argument of a length()
6856968814
** or typeof() function, respectively. The loading of large blobs can be
6857068815
** skipped for length() and all content loading can be skipped for typeof().
6857168816
*/
6857268817
case OP_Column: {
68818
+#if 0 /* local variables moved into u.ap */
6857368819
i64 payloadSize64; /* Number of bytes in the record */
6857468820
int p2; /* column number to retrieve */
6857568821
VdbeCursor *pC; /* The VDBE cursor */
6857668822
BtCursor *pCrsr; /* The BTree cursor */
6857768823
u32 *aType; /* aType[i] holds the numeric type of the i-th column */
@@ -68586,88 +68832,89 @@
6858668832
u32 offset; /* Offset into the data */
6858768833
u32 szField; /* Number of bytes in the content of a field */
6858868834
u32 avail; /* Number of bytes of available data */
6858968835
u32 t; /* A type code from the record header */
6859068836
Mem *pReg; /* PseudoTable input register */
68591
-
68592
- p2 = pOp->p2;
68593
- assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68594
- pDest = &aMem[pOp->p3];
68595
- memAboutToChange(p, pDest);
68596
- assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68597
- pC = p->apCsr[pOp->p1];
68598
- assert( pC!=0 );
68599
- assert( p2<pC->nField );
68600
- aType = pC->aType;
68601
- aOffset = aType + pC->nField;
68602
-#ifndef SQLITE_OMIT_VIRTUALTABLE
68603
- assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
68604
-#endif
68605
- pCrsr = pC->pCursor;
68606
- assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
68607
- assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
68608
-
68609
- /* If the cursor cache is stale, bring it up-to-date */
68610
- rc = sqlite3VdbeCursorMoveto(pC);
68611
- if( rc ) goto abort_due_to_error;
68612
- if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68613
- if( pC->nullRow ){
68614
- if( pCrsr==0 ){
68615
- assert( pC->pseudoTableReg>0 );
68616
- pReg = &aMem[pC->pseudoTableReg];
68617
- if( pC->multiPseudo ){
68618
- sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68619
- Deephemeralize(pDest);
68620
- goto op_column_out;
68621
- }
68622
- assert( pReg->flags & MEM_Blob );
68623
- assert( memIsValid(pReg) );
68624
- pC->payloadSize = pC->szRow = avail = pReg->n;
68625
- pC->aRow = (u8*)pReg->z;
68626
- }else{
68627
- MemSetTypeFlag(pDest, MEM_Null);
68628
- goto op_column_out;
68629
- }
68630
- }else{
68631
- assert( pCrsr );
68632
- if( pC->isTable==0 ){
68633
- assert( sqlite3BtreeCursorIsValid(pCrsr) );
68634
- VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64);
68635
- assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68636
- /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68637
- ** payload size, so it is impossible for payloadSize64 to be
68638
- ** larger than 32 bits. */
68639
- assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
68640
- pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail);
68641
- pC->payloadSize = (u32)payloadSize64;
68642
- }else{
68643
- assert( sqlite3BtreeCursorIsValid(pCrsr) );
68644
- VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize);
68645
- assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68646
- pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail);
68647
- }
68648
- assert( avail<=65536 ); /* Maximum page size is 64KiB */
68649
- if( pC->payloadSize <= (u32)avail ){
68650
- pC->szRow = pC->payloadSize;
68651
- }else{
68652
- pC->szRow = avail;
68653
- }
68654
- if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68655
- goto too_big;
68656
- }
68657
- }
68658
- pC->cacheStatus = p->cacheCtr;
68659
- pC->iHdrOffset = getVarint32(pC->aRow, offset);
68660
- pC->nHdrParsed = 0;
68661
- aOffset[0] = offset;
68662
- if( avail<offset ){
68663
- /* pC->aRow does not have to hold the entire row, but it does at least
68664
- ** need to cover the header of the record. If pC->aRow does not contain
68665
- ** the complete header, then set it to zero, forcing the header to be
68666
- ** dynamically allocated. */
68667
- pC->aRow = 0;
68668
- pC->szRow = 0;
68837
+#endif /* local variables moved into u.ap */
68838
+
68839
+ u.ap.p2 = pOp->p2;
68840
+ assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68841
+ u.ap.pDest = &aMem[pOp->p3];
68842
+ memAboutToChange(p, u.ap.pDest);
68843
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68844
+ u.ap.pC = p->apCsr[pOp->p1];
68845
+ assert( u.ap.pC!=0 );
68846
+ assert( u.ap.p2<u.ap.pC->nField );
68847
+ u.ap.aType = u.ap.pC->aType;
68848
+ u.ap.aOffset = u.ap.aType + u.ap.pC->nField;
68849
+#ifndef SQLITE_OMIT_VIRTUALTABLE
68850
+ assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
68851
+#endif
68852
+ u.ap.pCrsr = u.ap.pC->pCursor;
68853
+ assert( u.ap.pCrsr!=0 || u.ap.pC->pseudoTableReg>0 ); /* u.ap.pCrsr NULL on PseudoTables */
68854
+ assert( u.ap.pCrsr!=0 || u.ap.pC->nullRow ); /* u.ap.pC->nullRow on PseudoTables */
68855
+
68856
+ /* If the cursor cache is stale, bring it up-to-date */
68857
+ rc = sqlite3VdbeCursorMoveto(u.ap.pC);
68858
+ if( rc ) goto abort_due_to_error;
68859
+ if( u.ap.pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68860
+ if( u.ap.pC->nullRow ){
68861
+ if( u.ap.pCrsr==0 ){
68862
+ assert( u.ap.pC->pseudoTableReg>0 );
68863
+ u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
68864
+ if( u.ap.pC->multiPseudo ){
68865
+ sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
68866
+ Deephemeralize(u.ap.pDest);
68867
+ goto op_column_out;
68868
+ }
68869
+ assert( u.ap.pReg->flags & MEM_Blob );
68870
+ assert( memIsValid(u.ap.pReg) );
68871
+ u.ap.pC->payloadSize = u.ap.pC->szRow = u.ap.avail = u.ap.pReg->n;
68872
+ u.ap.pC->aRow = (u8*)u.ap.pReg->z;
68873
+ }else{
68874
+ MemSetTypeFlag(u.ap.pDest, MEM_Null);
68875
+ goto op_column_out;
68876
+ }
68877
+ }else{
68878
+ assert( u.ap.pCrsr );
68879
+ if( u.ap.pC->isTable==0 ){
68880
+ assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68881
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
68882
+ assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68883
+ /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68884
+ ** payload size, so it is impossible for u.ap.payloadSize64 to be
68885
+ ** larger than 32 bits. */
68886
+ assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
68887
+ u.ap.pC->aRow = sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
68888
+ u.ap.pC->payloadSize = (u32)u.ap.payloadSize64;
68889
+ }else{
68890
+ assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68891
+ VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.pC->payloadSize);
68892
+ assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68893
+ u.ap.pC->aRow = sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
68894
+ }
68895
+ assert( u.ap.avail<=65536 ); /* Maximum page size is 64KiB */
68896
+ if( u.ap.pC->payloadSize <= (u32)u.ap.avail ){
68897
+ u.ap.pC->szRow = u.ap.pC->payloadSize;
68898
+ }else{
68899
+ u.ap.pC->szRow = u.ap.avail;
68900
+ }
68901
+ if( u.ap.pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68902
+ goto too_big;
68903
+ }
68904
+ }
68905
+ u.ap.pC->cacheStatus = p->cacheCtr;
68906
+ u.ap.pC->iHdrOffset = getVarint32(u.ap.pC->aRow, u.ap.offset);
68907
+ u.ap.pC->nHdrParsed = 0;
68908
+ u.ap.aOffset[0] = u.ap.offset;
68909
+ if( u.ap.avail<u.ap.offset ){
68910
+ /* u.ap.pC->aRow does not have to hold the entire row, but it does at least
68911
+ ** need to cover the header of the record. If u.ap.pC->aRow does not contain
68912
+ ** the complete header, then set it to zero, forcing the header to be
68913
+ ** dynamically allocated. */
68914
+ u.ap.pC->aRow = 0;
68915
+ u.ap.pC->szRow = 0;
6866968916
}
6867068917
6867168918
/* Make sure a corrupt database has not given us an oversize header.
6867268919
** Do this now to avoid an oversize memory allocation.
6867368920
**
@@ -68675,154 +68922,154 @@
6867568922
** types use so much data space that there can only be 4096 and 32 of
6867668923
** them, respectively. So the maximum header length results from a
6867768924
** 3-byte type for each of the maximum of 32768 columns plus three
6867868925
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
6867968926
*/
68680
- if( offset > 98307 || offset > pC->payloadSize ){
68927
+ if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){
6868168928
rc = SQLITE_CORRUPT_BKPT;
6868268929
goto op_column_error;
6868368930
}
6868468931
}
6868568932
68686
- /* Make sure at least the first p2+1 entries of the header have been
68687
- ** parsed and valid information is in aOffset[] and aType[].
68933
+ /* Make sure at least the first u.ap.p2+1 entries of the header have been
68934
+ ** parsed and valid information is in u.ap.aOffset[] and u.ap.aType[].
6868868935
*/
68689
- if( pC->nHdrParsed<=p2 ){
68936
+ if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
6869068937
/* If there is more header available for parsing in the record, try
68691
- ** to extract additional fields up through the p2+1-th field
68938
+ ** to extract additional fields up through the u.ap.p2+1-th field
6869268939
*/
68693
- if( pC->iHdrOffset<aOffset[0] ){
68694
- /* Make sure zData points to enough of the record to cover the header. */
68695
- if( pC->aRow==0 ){
68696
- memset(&sMem, 0, sizeof(sMem));
68697
- rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
68698
- !pC->isTable, &sMem);
68940
+ if( u.ap.pC->iHdrOffset<u.ap.aOffset[0] ){
68941
+ /* Make sure u.ap.zData points to enough of the record to cover the header. */
68942
+ if( u.ap.pC->aRow==0 ){
68943
+ memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
68944
+ rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.aOffset[0],
68945
+ !u.ap.pC->isTable, &u.ap.sMem);
6869968946
if( rc!=SQLITE_OK ){
6870068947
goto op_column_error;
6870168948
}
68702
- zData = (u8*)sMem.z;
68949
+ u.ap.zData = (u8*)u.ap.sMem.z;
6870368950
}else{
68704
- zData = pC->aRow;
68705
- }
68706
-
68707
- /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
68708
- i = pC->nHdrParsed;
68709
- offset = aOffset[i];
68710
- zHdr = zData + pC->iHdrOffset;
68711
- zEndHdr = zData + aOffset[0];
68712
- assert( i<=p2 && zHdr<zEndHdr );
68951
+ u.ap.zData = u.ap.pC->aRow;
68952
+ }
68953
+
68954
+ /* Fill in u.ap.aType[u.ap.i] and u.ap.aOffset[u.ap.i] values through the u.ap.p2-th field. */
68955
+ u.ap.i = u.ap.pC->nHdrParsed;
68956
+ u.ap.offset = u.ap.aOffset[u.ap.i];
68957
+ u.ap.zHdr = u.ap.zData + u.ap.pC->iHdrOffset;
68958
+ u.ap.zEndHdr = u.ap.zData + u.ap.aOffset[0];
68959
+ assert( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr );
6871368960
do{
68714
- if( zHdr[0]<0x80 ){
68715
- t = zHdr[0];
68716
- zHdr++;
68961
+ if( u.ap.zHdr[0]<0x80 ){
68962
+ u.ap.t = u.ap.zHdr[0];
68963
+ u.ap.zHdr++;
6871768964
}else{
68718
- zHdr += sqlite3GetVarint32(zHdr, &t);
68965
+ u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t);
6871968966
}
68720
- aType[i] = t;
68721
- szField = sqlite3VdbeSerialTypeLen(t);
68722
- offset += szField;
68723
- if( offset<szField ){ /* True if offset overflows */
68724
- zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68967
+ u.ap.aType[u.ap.i] = u.ap.t;
68968
+ u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68969
+ u.ap.offset += u.ap.szField;
68970
+ if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */
68971
+ u.ap.zHdr = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
6872568972
break;
6872668973
}
68727
- i++;
68728
- aOffset[i] = offset;
68729
- }while( i<=p2 && zHdr<zEndHdr );
68730
- pC->nHdrParsed = i;
68731
- pC->iHdrOffset = (u32)(zHdr - zData);
68732
- if( pC->aRow==0 ){
68733
- sqlite3VdbeMemRelease(&sMem);
68734
- sMem.flags = MEM_Null;
68735
- }
68736
-
68974
+ u.ap.i++;
68975
+ u.ap.aOffset[u.ap.i] = u.ap.offset;
68976
+ }while( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr );
68977
+ u.ap.pC->nHdrParsed = u.ap.i;
68978
+ u.ap.pC->iHdrOffset = (u32)(u.ap.zHdr - u.ap.zData);
68979
+ if( u.ap.pC->aRow==0 ){
68980
+ sqlite3VdbeMemRelease(&u.ap.sMem);
68981
+ u.ap.sMem.flags = MEM_Null;
68982
+ }
68983
+
6873768984
/* If we have read more header data than was contained in the header,
6873868985
** or if the end of the last field appears to be past the end of the
6873968986
** record, or if the end of the last field appears to be before the end
68740
- ** of the record (when all fields present), then we must be dealing
68987
+ ** of the record (when all fields present), then we must be dealing
6874168988
** with a corrupt database.
6874268989
*/
68743
- if( (zHdr > zEndHdr)
68744
- || (offset > pC->payloadSize)
68745
- || (zHdr==zEndHdr && offset!=pC->payloadSize)
68990
+ if( (u.ap.zHdr > u.ap.zEndHdr)
68991
+ || (u.ap.offset > u.ap.pC->payloadSize)
68992
+ || (u.ap.zHdr==u.ap.zEndHdr && u.ap.offset!=u.ap.pC->payloadSize)
6874668993
){
6874768994
rc = SQLITE_CORRUPT_BKPT;
6874868995
goto op_column_error;
6874968996
}
6875068997
}
6875168998
6875268999
/* If after trying to extra new entries from the header, nHdrParsed is
68753
- ** still not up to p2, that means that the record has fewer than p2
69000
+ ** still not up to u.ap.p2, that means that the record has fewer than u.ap.p2
6875469001
** columns. So the result will be either the default value or a NULL.
6875569002
*/
68756
- if( pC->nHdrParsed<=p2 ){
69003
+ if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
6875769004
if( pOp->p4type==P4_MEM ){
68758
- sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
69005
+ sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
6875969006
}else{
68760
- MemSetTypeFlag(pDest, MEM_Null);
69007
+ MemSetTypeFlag(u.ap.pDest, MEM_Null);
6876169008
}
6876269009
goto op_column_out;
6876369010
}
6876469011
}
6876569012
68766
- /* Extract the content for the p2+1-th column. Control can only
68767
- ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
69013
+ /* Extract the content for the u.ap.p2+1-th column. Control can only
69014
+ ** reach this point if u.ap.aOffset[u.ap.p2], u.ap.aOffset[u.ap.p2+1], and u.ap.aType[u.ap.p2] are
6876869015
** all valid.
6876969016
*/
68770
- assert( p2<pC->nHdrParsed );
69017
+ assert( u.ap.p2<u.ap.pC->nHdrParsed );
6877169018
assert( rc==SQLITE_OK );
68772
- if( pC->szRow>=aOffset[p2+1] ){
69019
+ if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){
6877369020
/* This is the common case where the desired content fits on the original
6877469021
** page - where the content is not on an overflow page */
68775
- VdbeMemRelease(pDest);
68776
- sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
69022
+ VdbeMemRelease(u.ap.pDest);
69023
+ sqlite3VdbeSerialGet(u.ap.pC->aRow+u.ap.aOffset[u.ap.p2], u.ap.aType[u.ap.p2], u.ap.pDest);
6877769024
}else{
6877869025
/* This branch happens only when content is on overflow pages */
68779
- t = aType[p2];
69026
+ u.ap.t = u.ap.aType[u.ap.p2];
6878069027
if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68781
- && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
68782
- || (len = sqlite3VdbeSerialTypeLen(t))==0
69028
+ && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
69029
+ || (u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t))==0
6878369030
){
6878469031
/* Content is irrelevant for the typeof() function and for
6878569032
** the length(X) function if X is a blob. So we might as well use
6878669033
** bogus content rather than reading content from disk. NULL works
68787
- ** for text and blob and whatever is in the payloadSize64 variable
69034
+ ** for text and blob and whatever is in the u.ap.payloadSize64 variable
6878869035
** will work for everything else. Content is also irrelevant if
6878969036
** the content length is 0. */
68790
- zData = t<=13 ? (u8*)&payloadSize64 : 0;
68791
- sMem.zMalloc = 0;
69037
+ u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0;
69038
+ u.ap.sMem.zMalloc = 0;
6879269039
}else{
68793
- memset(&sMem, 0, sizeof(sMem));
68794
- sqlite3VdbeMemMove(&sMem, pDest);
68795
- rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
68796
- &sMem);
69040
+ memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
69041
+ sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
69042
+ rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, !u.ap.pC->isTable,
69043
+ &u.ap.sMem);
6879769044
if( rc!=SQLITE_OK ){
6879869045
goto op_column_error;
6879969046
}
68800
- zData = (u8*)sMem.z;
69047
+ u.ap.zData = (u8*)u.ap.sMem.z;
6880169048
}
68802
- sqlite3VdbeSerialGet(zData, t, pDest);
69049
+ sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest);
6880369050
/* If we dynamically allocated space to hold the data (in the
6880469051
** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68805
- ** dynamically allocated space over to the pDest structure.
69052
+ ** dynamically allocated space over to the u.ap.pDest structure.
6880669053
** This prevents a memory copy. */
68807
- if( sMem.zMalloc ){
68808
- assert( sMem.z==sMem.zMalloc );
68809
- assert( !(pDest->flags & MEM_Dyn) );
68810
- assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
68811
- pDest->flags &= ~(MEM_Ephem|MEM_Static);
68812
- pDest->flags |= MEM_Term;
68813
- pDest->z = sMem.z;
68814
- pDest->zMalloc = sMem.zMalloc;
69054
+ if( u.ap.sMem.zMalloc ){
69055
+ assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
69056
+ assert( !(u.ap.pDest->flags & MEM_Dyn) );
69057
+ assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
69058
+ u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
69059
+ u.ap.pDest->flags |= MEM_Term;
69060
+ u.ap.pDest->z = u.ap.sMem.z;
69061
+ u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
6881569062
}
6881669063
}
68817
- pDest->enc = encoding;
69064
+ u.ap.pDest->enc = encoding;
6881869065
6881969066
op_column_out:
68820
- Deephemeralize(pDest);
69067
+ rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
6882169068
op_column_error:
68822
- UPDATE_MAX_BLOBSIZE(pDest);
68823
- REGISTER_TRACE(pOp->p3, pDest);
69069
+ UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69070
+ REGISTER_TRACE(pOp->p3, u.ap.pDest);
6882469071
break;
6882569072
}
6882669073
6882769074
/* Opcode: Affinity P1 P2 * P4 *
6882869075
** Synopsis: affinity(r[P1@P2])
@@ -68832,22 +69079,24 @@
6883269079
** P4 is a string that is P2 characters long. The nth character of the
6883369080
** string indicates the column affinity that should be used for the nth
6883469081
** memory cell in the range.
6883569082
*/
6883669083
case OP_Affinity: {
69084
+#if 0 /* local variables moved into u.aq */
6883769085
const char *zAffinity; /* The affinity to be applied */
6883869086
char cAff; /* A single character of affinity */
69087
+#endif /* local variables moved into u.aq */
6883969088
68840
- zAffinity = pOp->p4.z;
68841
- assert( zAffinity!=0 );
68842
- assert( zAffinity[pOp->p2]==0 );
69089
+ u.aq.zAffinity = pOp->p4.z;
69090
+ assert( u.aq.zAffinity!=0 );
69091
+ assert( u.aq.zAffinity[pOp->p2]==0 );
6884369092
pIn1 = &aMem[pOp->p1];
68844
- while( (cAff = *(zAffinity++))!=0 ){
69093
+ while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
6884569094
assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
6884669095
assert( memIsValid(pIn1) );
6884769096
ExpandBlob(pIn1);
68848
- applyAffinity(pIn1, cAff, encoding);
69097
+ applyAffinity(pIn1, u.aq.cAff, encoding);
6884969098
pIn1++;
6885069099
}
6885169100
break;
6885269101
}
6885369102
@@ -68866,10 +69115,11 @@
6886669115
** macros defined in sqliteInt.h.
6886769116
**
6886869117
** If P4 is NULL then all index fields have the affinity NONE.
6886969118
*/
6887069119
case OP_MakeRecord: {
69120
+#if 0 /* local variables moved into u.ar */
6887169121
u8 *zNewRecord; /* A buffer to hold the data for the new record */
6887269122
Mem *pRec; /* The new record */
6887369123
u64 nData; /* Number of bytes of data space */
6887469124
int nHdr; /* Number of bytes of header space */
6887569125
i64 nByte; /* Data space required for this record */
@@ -68879,123 +69129,106 @@
6887969129
Mem *pData0; /* First field to be combined into the record */
6888069130
Mem *pLast; /* Last field of the record */
6888169131
int nField; /* Number of fields in the record */
6888269132
char *zAffinity; /* The affinity string for the record */
6888369133
int file_format; /* File format to use for encoding */
68884
- int i; /* Space used in zNewRecord[] header */
68885
- int j; /* Space used in zNewRecord[] content */
69134
+ int i; /* Space used in zNewRecord[] */
6888669135
int len; /* Length of a field */
69136
+#endif /* local variables moved into u.ar */
6888769137
6888869138
/* Assuming the record contains N fields, the record format looks
6888969139
** like this:
6889069140
**
6889169141
** ------------------------------------------------------------------------
68892
- ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
69142
+ ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
6889369143
** ------------------------------------------------------------------------
6889469144
**
6889569145
** Data(0) is taken from register P1. Data(1) comes from register P1+1
6889669146
** and so froth.
6889769147
**
68898
- ** Each type field is a varint representing the serial type of the
69148
+ ** Each type field is a varint representing the serial type of the
6889969149
** corresponding data element (see sqlite3VdbeSerialType()). The
6890069150
** hdr-size field is also a varint which is the offset from the beginning
6890169151
** of the record to data0.
6890269152
*/
68903
- nData = 0; /* Number of bytes of data space */
68904
- nHdr = 0; /* Number of bytes of header space */
68905
- nZero = 0; /* Number of zero bytes at the end of the record */
68906
- nField = pOp->p1;
68907
- zAffinity = pOp->p4.z;
68908
- assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem-p->nCursor)+1 );
68909
- pData0 = &aMem[nField];
68910
- nField = pOp->p2;
68911
- pLast = &pData0[nField-1];
68912
- file_format = p->minWriteFileFormat;
69153
+ u.ar.nData = 0; /* Number of bytes of data space */
69154
+ u.ar.nHdr = 0; /* Number of bytes of header space */
69155
+ u.ar.nZero = 0; /* Number of zero bytes at the end of the record */
69156
+ u.ar.nField = pOp->p1;
69157
+ u.ar.zAffinity = pOp->p4.z;
69158
+ assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 );
69159
+ u.ar.pData0 = &aMem[u.ar.nField];
69160
+ u.ar.nField = pOp->p2;
69161
+ u.ar.pLast = &u.ar.pData0[u.ar.nField-1];
69162
+ u.ar.file_format = p->minWriteFileFormat;
6891369163
6891469164
/* Identify the output register */
6891569165
assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
6891669166
pOut = &aMem[pOp->p3];
6891769167
memAboutToChange(p, pOut);
6891869168
68919
- /* Apply the requested affinity to all inputs
68920
- */
68921
- assert( pData0<=pLast );
68922
- if( zAffinity ){
68923
- pRec = pData0;
68924
- do{
68925
- applyAffinity(pRec, *(zAffinity++), encoding);
68926
- }while( (++pRec)<=pLast );
68927
- }
68928
-
6892969169
/* Loop through the elements that will make up the record to figure
6893069170
** out how much space is required for the new record.
6893169171
*/
68932
- pRec = pLast;
68933
- do{
68934
- assert( memIsValid(pRec) );
68935
- serial_type = sqlite3VdbeSerialType(pRec, file_format);
68936
- len = sqlite3VdbeSerialTypeLen(serial_type);
68937
- if( pRec->flags & MEM_Zero ){
68938
- if( nData ){
68939
- sqlite3VdbeMemExpandBlob(pRec);
68940
- }else{
68941
- nZero += pRec->u.nZero;
68942
- len -= pRec->u.nZero;
68943
- }
68944
- }
68945
- nData += len;
68946
- testcase( serial_type==127 );
68947
- testcase( serial_type==128 );
68948
- nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
68949
- }while( (--pRec)>=pData0 );
69172
+ for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69173
+ assert( memIsValid(u.ar.pRec) );
69174
+ if( u.ar.zAffinity ){
69175
+ applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding);
69176
+ }
69177
+ if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){
69178
+ sqlite3VdbeMemExpandBlob(u.ar.pRec);
69179
+ }
69180
+ u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69181
+ u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type);
69182
+ u.ar.nData += u.ar.len;
69183
+ u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type);
69184
+ if( u.ar.pRec->flags & MEM_Zero ){
69185
+ /* Only pure zero-filled BLOBs can be input to this Opcode.
69186
+ ** We do not allow blobs with a prefix and a zero-filled tail. */
69187
+ u.ar.nZero += u.ar.pRec->u.nZero;
69188
+ }else if( u.ar.len ){
69189
+ u.ar.nZero = 0;
69190
+ }
69191
+ }
6895069192
6895169193
/* Add the initial header varint and total the size */
68952
- testcase( nHdr==126 );
68953
- testcase( nHdr==127 );
68954
- if( nHdr<=126 ){
68955
- /* The common case */
68956
- nHdr += 1;
68957
- }else{
68958
- /* Rare case of a really large header */
68959
- nVarint = sqlite3VarintLen(nHdr);
68960
- nHdr += nVarint;
68961
- if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
68962
- }
68963
- nByte = nHdr+nData;
68964
- if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
69194
+ u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr);
69195
+ if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){
69196
+ u.ar.nHdr++;
69197
+ }
69198
+ u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero;
69199
+ if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
6896569200
goto too_big;
6896669201
}
6896769202
68968
- /* Make sure the output register has a buffer large enough to store
69203
+ /* Make sure the output register has a buffer large enough to store
6896969204
** the new record. The output register (pOp->p3) is not allowed to
6897069205
** be one of the input registers (because the following call to
6897169206
** sqlite3VdbeMemGrow() could clobber the value before it is used).
6897269207
*/
68973
- if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
69208
+ if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
6897469209
goto no_mem;
6897569210
}
68976
- zNewRecord = (u8 *)pOut->z;
69211
+ u.ar.zNewRecord = (u8 *)pOut->z;
6897769212
6897869213
/* Write the record */
68979
- i = putVarint32(zNewRecord, nHdr);
68980
- j = nHdr;
68981
- assert( pData0<=pLast );
68982
- pRec = pData0;
68983
- do{
68984
- serial_type = sqlite3VdbeSerialType(pRec, file_format);
68985
- i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
68986
- j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
68987
- }while( (++pRec)<=pLast );
68988
- assert( i==nHdr );
68989
- assert( j==nByte );
69214
+ u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr);
69215
+ for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69216
+ u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69217
+ u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */
69218
+ }
69219
+ for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */
69220
+ u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format);
69221
+ }
69222
+ assert( u.ar.i==u.ar.nByte );
6899069223
6899169224
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68992
- pOut->n = (int)nByte;
69225
+ pOut->n = (int)u.ar.nByte;
6899369226
pOut->flags = MEM_Blob | MEM_Dyn;
6899469227
pOut->xDel = 0;
68995
- if( nZero ){
68996
- pOut->u.nZero = nZero;
69228
+ if( u.ar.nZero ){
69229
+ pOut->u.nZero = u.ar.nZero;
6899769230
pOut->flags |= MEM_Zero;
6899869231
}
6899969232
pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
6900069233
REGISTER_TRACE(pOp->p3, pOut);
6900169234
UPDATE_MAX_BLOBSIZE(pOut);
@@ -69008,18 +69241,19 @@
6900869241
** Store the number of entries (an integer value) in the table or index
6900969242
** opened by cursor P1 in register P2
6901069243
*/
6901169244
#ifndef SQLITE_OMIT_BTREECOUNT
6901269245
case OP_Count: { /* out2-prerelease */
69246
+#if 0 /* local variables moved into u.as */
6901369247
i64 nEntry;
6901469248
BtCursor *pCrsr;
69249
+#endif /* local variables moved into u.as */
6901569250
69016
- pCrsr = p->apCsr[pOp->p1]->pCursor;
69017
- assert( pCrsr );
69018
- nEntry = 0; /* Not needed. Only used to silence a warning. */
69019
- rc = sqlite3BtreeCount(pCrsr, &nEntry);
69020
- pOut->u.i = nEntry;
69251
+ u.as.pCrsr = p->apCsr[pOp->p1]->pCursor;
69252
+ assert( u.as.pCrsr );
69253
+ rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry);
69254
+ pOut->u.i = u.as.nEntry;
6902169255
break;
6902269256
}
6902369257
#endif
6902469258
6902569259
/* Opcode: Savepoint P1 * * P4 *
@@ -69027,41 +69261,43 @@
6902769261
** Open, release or rollback the savepoint named by parameter P4, depending
6902869262
** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
6902969263
** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
6903069264
*/
6903169265
case OP_Savepoint: {
69266
+#if 0 /* local variables moved into u.at */
6903269267
int p1; /* Value of P1 operand */
6903369268
char *zName; /* Name of savepoint */
6903469269
int nName;
6903569270
Savepoint *pNew;
6903669271
Savepoint *pSavepoint;
6903769272
Savepoint *pTmp;
6903869273
int iSavepoint;
6903969274
int ii;
69275
+#endif /* local variables moved into u.at */
6904069276
69041
- p1 = pOp->p1;
69042
- zName = pOp->p4.z;
69277
+ u.at.p1 = pOp->p1;
69278
+ u.at.zName = pOp->p4.z;
6904369279
69044
- /* Assert that the p1 parameter is valid. Also that if there is no open
69045
- ** transaction, then there cannot be any savepoints.
69280
+ /* Assert that the u.at.p1 parameter is valid. Also that if there is no open
69281
+ ** transaction, then there cannot be any savepoints.
6904669282
*/
6904769283
assert( db->pSavepoint==0 || db->autoCommit==0 );
69048
- assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK );
69284
+ assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK );
6904969285
assert( db->pSavepoint || db->isTransactionSavepoint==0 );
6905069286
assert( checkSavepointCount(db) );
6905169287
assert( p->bIsReader );
6905269288
69053
- if( p1==SAVEPOINT_BEGIN ){
69289
+ if( u.at.p1==SAVEPOINT_BEGIN ){
6905469290
if( db->nVdbeWrite>0 ){
69055
- /* A new savepoint cannot be created if there are active write
69291
+ /* A new savepoint cannot be created if there are active write
6905669292
** statements (i.e. open read/write incremental blob handles).
6905769293
*/
6905869294
sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
6905969295
"SQL statements in progress");
6906069296
rc = SQLITE_BUSY;
6906169297
}else{
69062
- nName = sqlite3Strlen30(zName);
69298
+ u.at.nName = sqlite3Strlen30(u.at.zName);
6906369299
6906469300
#ifndef SQLITE_OMIT_VIRTUALTABLE
6906569301
/* This call is Ok even if this savepoint is actually a transaction
6906669302
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
6906769303
** If this is a transaction savepoint being opened, it is guaranteed
@@ -69071,62 +69307,62 @@
6907169307
db->nStatement+db->nSavepoint);
6907269308
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6907369309
#endif
6907469310
6907569311
/* Create a new savepoint structure. */
69076
- pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
69077
- if( pNew ){
69078
- pNew->zName = (char *)&pNew[1];
69079
- memcpy(pNew->zName, zName, nName+1);
69080
-
69312
+ u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1);
69313
+ if( u.at.pNew ){
69314
+ u.at.pNew->zName = (char *)&u.at.pNew[1];
69315
+ memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1);
69316
+
6908169317
/* If there is no open transaction, then mark this as a special
6908269318
** "transaction savepoint". */
6908369319
if( db->autoCommit ){
6908469320
db->autoCommit = 0;
6908569321
db->isTransactionSavepoint = 1;
6908669322
}else{
6908769323
db->nSavepoint++;
6908869324
}
69089
-
69325
+
6909069326
/* Link the new savepoint into the database handle's list. */
69091
- pNew->pNext = db->pSavepoint;
69092
- db->pSavepoint = pNew;
69093
- pNew->nDeferredCons = db->nDeferredCons;
69094
- pNew->nDeferredImmCons = db->nDeferredImmCons;
69327
+ u.at.pNew->pNext = db->pSavepoint;
69328
+ db->pSavepoint = u.at.pNew;
69329
+ u.at.pNew->nDeferredCons = db->nDeferredCons;
69330
+ u.at.pNew->nDeferredImmCons = db->nDeferredImmCons;
6909569331
}
6909669332
}
6909769333
}else{
69098
- iSavepoint = 0;
69334
+ u.at.iSavepoint = 0;
6909969335
6910069336
/* Find the named savepoint. If there is no such savepoint, then an
6910169337
** an error is returned to the user. */
6910269338
for(
69103
- pSavepoint = db->pSavepoint;
69104
- pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
69105
- pSavepoint = pSavepoint->pNext
69339
+ u.at.pSavepoint = db->pSavepoint;
69340
+ u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName);
69341
+ u.at.pSavepoint = u.at.pSavepoint->pNext
6910669342
){
69107
- iSavepoint++;
69343
+ u.at.iSavepoint++;
6910869344
}
69109
- if( !pSavepoint ){
69110
- sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
69345
+ if( !u.at.pSavepoint ){
69346
+ sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName);
6911169347
rc = SQLITE_ERROR;
69112
- }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
69113
- /* It is not possible to release (commit) a savepoint if there are
69348
+ }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){
69349
+ /* It is not possible to release (commit) a savepoint if there are
6911469350
** active write statements.
6911569351
*/
69116
- sqlite3SetString(&p->zErrMsg, db,
69352
+ sqlite3SetString(&p->zErrMsg, db,
6911769353
"cannot release savepoint - SQL statements in progress"
6911869354
);
6911969355
rc = SQLITE_BUSY;
6912069356
}else{
6912169357
6912269358
/* Determine whether or not this is a transaction savepoint. If so,
69123
- ** and this is a RELEASE command, then the current transaction
69124
- ** is committed.
69359
+ ** and this is a RELEASE command, then the current transaction
69360
+ ** is committed.
6912569361
*/
69126
- int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
69127
- if( isTransaction && p1==SAVEPOINT_RELEASE ){
69362
+ int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint;
69363
+ if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){
6912869364
if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6912969365
goto vdbe_return;
6913069366
}
6913169367
db->autoCommit = 1;
6913269368
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69136,56 +69372,56 @@
6913669372
goto vdbe_return;
6913769373
}
6913869374
db->isTransactionSavepoint = 0;
6913969375
rc = p->rc;
6914069376
}else{
69141
- iSavepoint = db->nSavepoint - iSavepoint - 1;
69142
- if( p1==SAVEPOINT_ROLLBACK ){
69143
- for(ii=0; ii<db->nDb; ii++){
69144
- sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
69377
+ u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1;
69378
+ if( u.at.p1==SAVEPOINT_ROLLBACK ){
69379
+ for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69380
+ sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT);
6914569381
}
6914669382
}
69147
- for(ii=0; ii<db->nDb; ii++){
69148
- rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
69383
+ for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69384
+ rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint);
6914969385
if( rc!=SQLITE_OK ){
6915069386
goto abort_due_to_error;
6915169387
}
6915269388
}
69153
- if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
69389
+ if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
6915469390
sqlite3ExpirePreparedStatements(db);
6915569391
sqlite3ResetAllSchemasOfConnection(db);
6915669392
db->flags = (db->flags | SQLITE_InternChanges);
6915769393
}
6915869394
}
69159
-
69160
- /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
69395
+
69396
+ /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
6916169397
** savepoints nested inside of the savepoint being operated on. */
69162
- while( db->pSavepoint!=pSavepoint ){
69163
- pTmp = db->pSavepoint;
69164
- db->pSavepoint = pTmp->pNext;
69165
- sqlite3DbFree(db, pTmp);
69398
+ while( db->pSavepoint!=u.at.pSavepoint ){
69399
+ u.at.pTmp = db->pSavepoint;
69400
+ db->pSavepoint = u.at.pTmp->pNext;
69401
+ sqlite3DbFree(db, u.at.pTmp);
6916669402
db->nSavepoint--;
6916769403
}
6916869404
69169
- /* If it is a RELEASE, then destroy the savepoint being operated on
69170
- ** too. If it is a ROLLBACK TO, then set the number of deferred
69405
+ /* If it is a RELEASE, then destroy the savepoint being operated on
69406
+ ** too. If it is a ROLLBACK TO, then set the number of deferred
6917169407
** constraint violations present in the database to the value stored
6917269408
** when the savepoint was created. */
69173
- if( p1==SAVEPOINT_RELEASE ){
69174
- assert( pSavepoint==db->pSavepoint );
69175
- db->pSavepoint = pSavepoint->pNext;
69176
- sqlite3DbFree(db, pSavepoint);
69409
+ if( u.at.p1==SAVEPOINT_RELEASE ){
69410
+ assert( u.at.pSavepoint==db->pSavepoint );
69411
+ db->pSavepoint = u.at.pSavepoint->pNext;
69412
+ sqlite3DbFree(db, u.at.pSavepoint);
6917769413
if( !isTransaction ){
6917869414
db->nSavepoint--;
6917969415
}
6918069416
}else{
69181
- db->nDeferredCons = pSavepoint->nDeferredCons;
69182
- db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
69417
+ db->nDeferredCons = u.at.pSavepoint->nDeferredCons;
69418
+ db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons;
6918369419
}
6918469420
6918569421
if( !isTransaction ){
69186
- rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
69422
+ rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
6918769423
if( rc!=SQLITE_OK ) goto abort_due_to_error;
6918869424
}
6918969425
}
6919069426
}
6919169427
@@ -69200,52 +69436,54 @@
6920069436
** there are active writing VMs or active VMs that use shared cache.
6920169437
**
6920269438
** This instruction causes the VM to halt.
6920369439
*/
6920469440
case OP_AutoCommit: {
69441
+#if 0 /* local variables moved into u.au */
6920569442
int desiredAutoCommit;
6920669443
int iRollback;
6920769444
int turnOnAC;
69445
+#endif /* local variables moved into u.au */
6920869446
69209
- desiredAutoCommit = pOp->p1;
69210
- iRollback = pOp->p2;
69211
- turnOnAC = desiredAutoCommit && !db->autoCommit;
69212
- assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
69213
- assert( desiredAutoCommit==1 || iRollback==0 );
69447
+ u.au.desiredAutoCommit = pOp->p1;
69448
+ u.au.iRollback = pOp->p2;
69449
+ u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit;
69450
+ assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 );
69451
+ assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 );
6921469452
assert( db->nVdbeActive>0 ); /* At least this one VM is active */
6921569453
assert( p->bIsReader );
6921669454
6921769455
#if 0
69218
- if( turnOnAC && iRollback && db->nVdbeActive>1 ){
69456
+ if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
6921969457
/* If this instruction implements a ROLLBACK and other VMs are
6922069458
** still running, and a transaction is active, return an error indicating
69221
- ** that the other VMs must complete first.
69459
+ ** that the other VMs must complete first.
6922269460
*/
6922369461
sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
6922469462
"SQL statements in progress");
6922569463
rc = SQLITE_BUSY;
6922669464
}else
6922769465
#endif
69228
- if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
69466
+ if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
6922969467
/* If this instruction implements a COMMIT and other VMs are writing
69230
- ** return an error indicating that the other VMs must complete first.
69468
+ ** return an error indicating that the other VMs must complete first.
6923169469
*/
6923269470
sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
6923369471
"SQL statements in progress");
6923469472
rc = SQLITE_BUSY;
69235
- }else if( desiredAutoCommit!=db->autoCommit ){
69236
- if( iRollback ){
69237
- assert( desiredAutoCommit==1 );
69473
+ }else if( u.au.desiredAutoCommit!=db->autoCommit ){
69474
+ if( u.au.iRollback ){
69475
+ assert( u.au.desiredAutoCommit==1 );
6923869476
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6923969477
db->autoCommit = 1;
6924069478
}else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
6924169479
goto vdbe_return;
6924269480
}else{
69243
- db->autoCommit = (u8)desiredAutoCommit;
69481
+ db->autoCommit = (u8)u.au.desiredAutoCommit;
6924469482
if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
6924569483
p->pc = pc;
69246
- db->autoCommit = (u8)(1-desiredAutoCommit);
69484
+ db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
6924769485
p->rc = rc = SQLITE_BUSY;
6924869486
goto vdbe_return;
6924969487
}
6925069488
}
6925169489
assert( db->nStatement==0 );
@@ -69256,14 +69494,14 @@
6925669494
rc = SQLITE_ERROR;
6925769495
}
6925869496
goto vdbe_return;
6925969497
}else{
6926069498
sqlite3SetString(&p->zErrMsg, db,
69261
- (!desiredAutoCommit)?"cannot start a transaction within a transaction":(
69262
- (iRollback)?"cannot rollback - no transaction is active":
69499
+ (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69500
+ (u.au.iRollback)?"cannot rollback - no transaction is active":
6926369501
"cannot commit - no transaction is active"));
69264
-
69502
+
6926569503
rc = SQLITE_ERROR;
6926669504
}
6926769505
break;
6926869506
}
6926969507
@@ -69297,46 +69535,48 @@
6929769535
** will automatically commit when the VDBE halts.
6929869536
**
6929969537
** If P2 is zero, then a read-lock is obtained on the database file.
6930069538
*/
6930169539
case OP_Transaction: {
69540
+#if 0 /* local variables moved into u.av */
6930269541
Btree *pBt;
69542
+#endif /* local variables moved into u.av */
6930369543
6930469544
assert( p->bIsReader );
6930569545
assert( p->readOnly==0 || pOp->p2==0 );
6930669546
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6930769547
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6930869548
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
6930969549
rc = SQLITE_READONLY;
6931069550
goto abort_due_to_error;
6931169551
}
69312
- pBt = db->aDb[pOp->p1].pBt;
69552
+ u.av.pBt = db->aDb[pOp->p1].pBt;
6931369553
69314
- if( pBt ){
69315
- rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
69554
+ if( u.av.pBt ){
69555
+ rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
6931669556
if( rc==SQLITE_BUSY ){
6931769557
p->pc = pc;
6931869558
p->rc = rc = SQLITE_BUSY;
6931969559
goto vdbe_return;
6932069560
}
6932169561
if( rc!=SQLITE_OK ){
6932269562
goto abort_due_to_error;
6932369563
}
6932469564
69325
- if( pOp->p2 && p->usesStmtJournal
69326
- && (db->autoCommit==0 || db->nVdbeRead>1)
69565
+ if( pOp->p2 && p->usesStmtJournal
69566
+ && (db->autoCommit==0 || db->nVdbeRead>1)
6932769567
){
69328
- assert( sqlite3BtreeIsInTrans(pBt) );
69568
+ assert( sqlite3BtreeIsInTrans(u.av.pBt) );
6932969569
if( p->iStatement==0 ){
6933069570
assert( db->nStatement>=0 && db->nSavepoint>=0 );
69331
- db->nStatement++;
69571
+ db->nStatement++;
6933269572
p->iStatement = db->nSavepoint + db->nStatement;
6933369573
}
6933469574
6933569575
rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
6933669576
if( rc==SQLITE_OK ){
69337
- rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
69577
+ rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
6933869578
}
6933969579
6934069580
/* Store the current value of the database handles deferred constraint
6934169581
** counter. If the statement transaction needs to be rolled back,
6934269582
** the value of this counter needs to be restored too. */
@@ -69358,24 +69598,26 @@
6935869598
** There must be a read-lock on the database (either a transaction
6935969599
** must be started or there must be an open cursor) before
6936069600
** executing this instruction.
6936169601
*/
6936269602
case OP_ReadCookie: { /* out2-prerelease */
69603
+#if 0 /* local variables moved into u.aw */
6936369604
int iMeta;
6936469605
int iDb;
6936569606
int iCookie;
69607
+#endif /* local variables moved into u.aw */
6936669608
6936769609
assert( p->bIsReader );
69368
- iDb = pOp->p1;
69369
- iCookie = pOp->p3;
69610
+ u.aw.iDb = pOp->p1;
69611
+ u.aw.iCookie = pOp->p3;
6937069612
assert( pOp->p3<SQLITE_N_BTREE_META );
69371
- assert( iDb>=0 && iDb<db->nDb );
69372
- assert( db->aDb[iDb].pBt!=0 );
69373
- assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69613
+ assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
69614
+ assert( db->aDb[u.aw.iDb].pBt!=0 );
69615
+ assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 );
6937469616
69375
- sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
69376
- pOut->u.i = iMeta;
69617
+ sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta);
69618
+ pOut->u.i = u.aw.iMeta;
6937769619
break;
6937869620
}
6937969621
6938069622
/* Opcode: SetCookie P1 P2 P3 * *
6938169623
**
@@ -69386,29 +69628,31 @@
6938669628
** database file used to store temporary tables.
6938769629
**
6938869630
** A transaction must be started before executing this opcode.
6938969631
*/
6939069632
case OP_SetCookie: { /* in3 */
69633
+#if 0 /* local variables moved into u.ax */
6939169634
Db *pDb;
69635
+#endif /* local variables moved into u.ax */
6939269636
assert( pOp->p2<SQLITE_N_BTREE_META );
6939369637
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6939469638
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6939569639
assert( p->readOnly==0 );
69396
- pDb = &db->aDb[pOp->p1];
69397
- assert( pDb->pBt!=0 );
69640
+ u.ax.pDb = &db->aDb[pOp->p1];
69641
+ assert( u.ax.pDb->pBt!=0 );
6939869642
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6939969643
pIn3 = &aMem[pOp->p3];
6940069644
sqlite3VdbeMemIntegerify(pIn3);
6940169645
/* See note about index shifting on OP_ReadCookie */
69402
- rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
69646
+ rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i);
6940369647
if( pOp->p2==BTREE_SCHEMA_VERSION ){
6940469648
/* When the schema cookie changes, record the new cookie internally */
69405
- pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69649
+ u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
6940669650
db->flags |= SQLITE_InternChanges;
6940769651
}else if( pOp->p2==BTREE_FILE_FORMAT ){
6940869652
/* Record changes in the file format */
69409
- pDb->pSchema->file_format = (u8)pIn3->u.i;
69653
+ u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i;
6941069654
}
6941169655
if( pOp->p1==1 ){
6941269656
/* Invalidate all prepared statements whenever the TEMP database
6941369657
** schema is changed. Ticket #1644 */
6941469658
sqlite3ExpirePreparedStatements(db);
@@ -69434,42 +69678,44 @@
6943469678
** Either a transaction needs to have been started or an OP_Open needs
6943569679
** to be executed (to establish a read lock) before this opcode is
6943669680
** invoked.
6943769681
*/
6943869682
case OP_VerifyCookie: {
69683
+#if 0 /* local variables moved into u.ay */
6943969684
int iMeta;
6944069685
int iGen;
6944169686
Btree *pBt;
69687
+#endif /* local variables moved into u.ay */
6944269688
6944369689
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6944469690
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
6944569691
assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
6944669692
assert( p->bIsReader );
69447
- pBt = db->aDb[pOp->p1].pBt;
69448
- if( pBt ){
69449
- sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69450
- iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69693
+ u.ay.pBt = db->aDb[pOp->p1].pBt;
69694
+ if( u.ay.pBt ){
69695
+ sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta);
69696
+ u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
6945169697
}else{
69452
- iGen = iMeta = 0;
69698
+ u.ay.iGen = u.ay.iMeta = 0;
6945369699
}
69454
- if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69700
+ if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
6945569701
sqlite3DbFree(db, p->zErrMsg);
6945669702
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69457
- /* If the schema-cookie from the database file matches the cookie
69703
+ /* If the schema-cookie from the database file matches the cookie
6945869704
** stored with the in-memory representation of the schema, do
6945969705
** not reload the schema from the database file.
6946069706
**
6946169707
** If virtual-tables are in use, this is not just an optimization.
6946269708
** Often, v-tables store their data in other SQLite tables, which
6946369709
** are queried from within xNext() and other v-table methods using
6946469710
** prepared queries. If such a query is out-of-date, we do not want to
6946569711
** discard the database schema, as the user code implementing the
6946669712
** v-table would have to be ready for the sqlite3_vtab structure itself
69467
- ** to be invalidated whenever sqlite3_step() is called from within
69713
+ ** to be invalidated whenever sqlite3_step() is called from within
6946869714
** a v-table method.
6946969715
*/
69470
- if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69716
+ if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
6947169717
sqlite3ResetOneSchema(db, pOp->p1);
6947269718
}
6947369719
6947469720
p->expired = 1;
6947569721
rc = SQLITE_SCHEMA;
@@ -69528,18 +69774,20 @@
6952869774
**
6952969775
** See also OpenRead.
6953069776
*/
6953169777
case OP_OpenRead:
6953269778
case OP_OpenWrite: {
69779
+#if 0 /* local variables moved into u.az */
6953369780
int nField;
6953469781
KeyInfo *pKeyInfo;
6953569782
int p2;
6953669783
int iDb;
6953769784
int wrFlag;
6953869785
Btree *pX;
6953969786
VdbeCursor *pCur;
6954069787
Db *pDb;
69788
+#endif /* local variables moved into u.az */
6954169789
6954269790
assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
6954369791
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
6954469792
assert( p->bIsReader );
6954569793
assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69547,74 +69795,74 @@
6954769795
if( p->expired ){
6954869796
rc = SQLITE_ABORT;
6954969797
break;
6955069798
}
6955169799
69552
- nField = 0;
69553
- pKeyInfo = 0;
69554
- p2 = pOp->p2;
69555
- iDb = pOp->p3;
69556
- assert( iDb>=0 && iDb<db->nDb );
69557
- assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69558
- pDb = &db->aDb[iDb];
69559
- pX = pDb->pBt;
69560
- assert( pX!=0 );
69800
+ u.az.nField = 0;
69801
+ u.az.pKeyInfo = 0;
69802
+ u.az.p2 = pOp->p2;
69803
+ u.az.iDb = pOp->p3;
69804
+ assert( u.az.iDb>=0 && u.az.iDb<db->nDb );
69805
+ assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 );
69806
+ u.az.pDb = &db->aDb[u.az.iDb];
69807
+ u.az.pX = u.az.pDb->pBt;
69808
+ assert( u.az.pX!=0 );
6956169809
if( pOp->opcode==OP_OpenWrite ){
69562
- wrFlag = 1;
69563
- assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
69564
- if( pDb->pSchema->file_format < p->minWriteFileFormat ){
69565
- p->minWriteFileFormat = pDb->pSchema->file_format;
69810
+ u.az.wrFlag = 1;
69811
+ assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) );
69812
+ if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){
69813
+ p->minWriteFileFormat = u.az.pDb->pSchema->file_format;
6956669814
}
6956769815
}else{
69568
- wrFlag = 0;
69816
+ u.az.wrFlag = 0;
6956969817
}
6957069818
if( pOp->p5 & OPFLAG_P2ISREG ){
69571
- assert( p2>0 );
69572
- assert( p2<=(p->nMem-p->nCursor) );
69573
- pIn2 = &aMem[p2];
69819
+ assert( u.az.p2>0 );
69820
+ assert( u.az.p2<=(p->nMem-p->nCursor) );
69821
+ pIn2 = &aMem[u.az.p2];
6957469822
assert( memIsValid(pIn2) );
6957569823
assert( (pIn2->flags & MEM_Int)!=0 );
6957669824
sqlite3VdbeMemIntegerify(pIn2);
69577
- p2 = (int)pIn2->u.i;
69578
- /* The p2 value always comes from a prior OP_CreateTable opcode and
69579
- ** that opcode will always set the p2 value to 2 or more or else fail.
69825
+ u.az.p2 = (int)pIn2->u.i;
69826
+ /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and
69827
+ ** that opcode will always set the u.az.p2 value to 2 or more or else fail.
6958069828
** If there were a failure, the prepared statement would have halted
6958169829
** before reaching this instruction. */
69582
- if( NEVER(p2<2) ) {
69830
+ if( NEVER(u.az.p2<2) ) {
6958369831
rc = SQLITE_CORRUPT_BKPT;
6958469832
goto abort_due_to_error;
6958569833
}
6958669834
}
6958769835
if( pOp->p4type==P4_KEYINFO ){
69588
- pKeyInfo = pOp->p4.pKeyInfo;
69589
- assert( pKeyInfo->enc==ENC(db) );
69590
- assert( pKeyInfo->db==db );
69591
- nField = pKeyInfo->nField+pKeyInfo->nXField;
69836
+ u.az.pKeyInfo = pOp->p4.pKeyInfo;
69837
+ assert( u.az.pKeyInfo->enc==ENC(db) );
69838
+ assert( u.az.pKeyInfo->db==db );
69839
+ u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
6959269840
}else if( pOp->p4type==P4_INT32 ){
69593
- nField = pOp->p4.i;
69841
+ u.az.nField = pOp->p4.i;
6959469842
}
6959569843
assert( pOp->p1>=0 );
69596
- assert( nField>=0 );
69597
- testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
69598
- pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
69599
- if( pCur==0 ) goto no_mem;
69600
- pCur->nullRow = 1;
69601
- pCur->isOrdered = 1;
69602
- rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
69603
- pCur->pKeyInfo = pKeyInfo;
69844
+ assert( u.az.nField>=0 );
69845
+ testcase( u.az.nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
69846
+ u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69847
+ if( u.az.pCur==0 ) goto no_mem;
69848
+ u.az.pCur->nullRow = 1;
69849
+ u.az.pCur->isOrdered = 1;
69850
+ rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
69851
+ u.az.pCur->pKeyInfo = u.az.pKeyInfo;
6960469852
assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69605
- sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69853
+ sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
6960669854
6960769855
/* Since it performs no memory allocation or IO, the only value that
6960869856
** sqlite3BtreeCursor() may return is SQLITE_OK. */
6960969857
assert( rc==SQLITE_OK );
6961069858
6961169859
/* Set the VdbeCursor.isTable variable. Previous versions of
6961269860
** SQLite used to check if the root-page flags were sane at this point
6961369861
** and report database corruption if they were not, but this check has
69614
- ** since moved into the btree layer. */
69615
- pCur->isTable = pOp->p4type!=P4_KEYINFO;
69862
+ ** since moved into the btree layer. */
69863
+ u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
6961669864
break;
6961769865
}
6961869866
6961969867
/* Opcode: OpenEphemeral P1 P2 * P4 P5
6962069868
** Synopsis: nColumn=P2
@@ -69642,53 +69890,55 @@
6964269890
** by this opcode will be used for automatically created transient
6964369891
** indices in joins.
6964469892
*/
6964569893
case OP_OpenAutoindex:
6964669894
case OP_OpenEphemeral: {
69895
+#if 0 /* local variables moved into u.ba */
6964769896
VdbeCursor *pCx;
6964869897
KeyInfo *pKeyInfo;
69898
+#endif /* local variables moved into u.ba */
6964969899
69650
- static const int vfsFlags =
69900
+ static const int vfsFlags =
6965169901
SQLITE_OPEN_READWRITE |
6965269902
SQLITE_OPEN_CREATE |
6965369903
SQLITE_OPEN_EXCLUSIVE |
6965469904
SQLITE_OPEN_DELETEONCLOSE |
6965569905
SQLITE_OPEN_TRANSIENT_DB;
6965669906
assert( pOp->p1>=0 );
6965769907
assert( pOp->p2>=0 );
69658
- pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69659
- if( pCx==0 ) goto no_mem;
69660
- pCx->nullRow = 1;
69661
- rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
69908
+ u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69909
+ if( u.ba.pCx==0 ) goto no_mem;
69910
+ u.ba.pCx->nullRow = 1;
69911
+ rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
6966269912
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
6966369913
if( rc==SQLITE_OK ){
69664
- rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
69914
+ rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
6966569915
}
6966669916
if( rc==SQLITE_OK ){
6966769917
/* If a transient index is required, create it by calling
6966869918
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
6966969919
** opening it. If a transient table is required, just use the
6967069920
** automatically created table with root-page 1 (an BLOB_INTKEY table).
6967169921
*/
69672
- if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69922
+ if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
6967369923
int pgno;
6967469924
assert( pOp->p4type==P4_KEYINFO );
69675
- rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69925
+ rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
6967669926
if( rc==SQLITE_OK ){
6967769927
assert( pgno==MASTER_ROOT+1 );
69678
- assert( pKeyInfo->db==db );
69679
- assert( pKeyInfo->enc==ENC(db) );
69680
- pCx->pKeyInfo = pKeyInfo;
69681
- rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor);
69682
- }
69683
- pCx->isTable = 0;
69684
- }else{
69685
- rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor);
69686
- pCx->isTable = 1;
69928
+ assert( u.ba.pKeyInfo->db==db );
69929
+ assert( u.ba.pKeyInfo->enc==ENC(db) );
69930
+ u.ba.pCx->pKeyInfo = u.ba.pKeyInfo;
69931
+ rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor);
69932
+ }
69933
+ u.ba.pCx->isTable = 0;
69934
+ }else{
69935
+ rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69936
+ u.ba.pCx->isTable = 1;
6968769937
}
6968869938
}
69689
- pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69939
+ u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
6969069940
break;
6969169941
}
6969269942
6969369943
/* Opcode: SorterOpen P1 * * P4 *
6969469944
**
@@ -69695,20 +69945,22 @@
6969569945
** This opcode works like OP_OpenEphemeral except that it opens
6969669946
** a transient index that is specifically designed to sort large
6969769947
** tables using an external merge-sort algorithm.
6969869948
*/
6969969949
case OP_SorterOpen: {
69950
+#if 0 /* local variables moved into u.bb */
6970069951
VdbeCursor *pCx;
69952
+#endif /* local variables moved into u.bb */
6970169953
6970269954
assert( pOp->p1>=0 );
6970369955
assert( pOp->p2>=0 );
69704
- pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69705
- if( pCx==0 ) goto no_mem;
69706
- pCx->pKeyInfo = pOp->p4.pKeyInfo;
69707
- assert( pCx->pKeyInfo->db==db );
69708
- assert( pCx->pKeyInfo->enc==ENC(db) );
69709
- rc = sqlite3VdbeSorterInit(db, pCx);
69956
+ u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69957
+ if( u.bb.pCx==0 ) goto no_mem;
69958
+ u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69959
+ assert( u.bb.pCx->pKeyInfo->db==db );
69960
+ assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69961
+ rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
6971069962
break;
6971169963
}
6971269964
6971369965
/* Opcode: OpenPseudo P1 P2 P3 * P5
6971469966
** Synopsis: content in r[P2@P3]
@@ -69726,20 +69978,22 @@
6972669978
**
6972769979
** P3 is the number of fields in the records that will be stored by
6972869980
** the pseudo-table.
6972969981
*/
6973069982
case OP_OpenPseudo: {
69983
+#if 0 /* local variables moved into u.bc */
6973169984
VdbeCursor *pCx;
69985
+#endif /* local variables moved into u.bc */
6973269986
6973369987
assert( pOp->p1>=0 );
6973469988
assert( pOp->p3>=0 );
69735
- pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69736
- if( pCx==0 ) goto no_mem;
69737
- pCx->nullRow = 1;
69738
- pCx->pseudoTableReg = pOp->p2;
69739
- pCx->isTable = 1;
69740
- pCx->multiPseudo = pOp->p5;
69989
+ u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69990
+ if( u.bc.pCx==0 ) goto no_mem;
69991
+ u.bc.pCx->nullRow = 1;
69992
+ u.bc.pCx->pseudoTableReg = pOp->p2;
69993
+ u.bc.pCx->isTable = 1;
69994
+ u.bc.pCx->multiPseudo = pOp->p5;
6974169995
break;
6974269996
}
6974369997
6974469998
/* Opcode: Close P1 * * * *
6974569999
**
@@ -69811,37 +70065,39 @@
6981170065
*/
6981270066
case OP_SeekLt: /* jump, in3 */
6981370067
case OP_SeekLe: /* jump, in3 */
6981470068
case OP_SeekGe: /* jump, in3 */
6981570069
case OP_SeekGt: { /* jump, in3 */
70070
+#if 0 /* local variables moved into u.bd */
6981670071
int res;
6981770072
int oc;
6981870073
VdbeCursor *pC;
6981970074
UnpackedRecord r;
6982070075
int nField;
6982170076
i64 iKey; /* The rowid we are to seek to */
70077
+#endif /* local variables moved into u.bd */
6982270078
6982370079
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6982470080
assert( pOp->p2!=0 );
69825
- pC = p->apCsr[pOp->p1];
69826
- assert( pC!=0 );
69827
- assert( pC->pseudoTableReg==0 );
70081
+ u.bd.pC = p->apCsr[pOp->p1];
70082
+ assert( u.bd.pC!=0 );
70083
+ assert( u.bd.pC->pseudoTableReg==0 );
6982870084
assert( OP_SeekLe == OP_SeekLt+1 );
6982970085
assert( OP_SeekGe == OP_SeekLt+2 );
6983070086
assert( OP_SeekGt == OP_SeekLt+3 );
69831
- assert( pC->isOrdered );
69832
- assert( pC->pCursor!=0 );
69833
- oc = pOp->opcode;
69834
- pC->nullRow = 0;
69835
- if( pC->isTable ){
70087
+ assert( u.bd.pC->isOrdered );
70088
+ assert( u.bd.pC->pCursor!=0 );
70089
+ u.bd.oc = pOp->opcode;
70090
+ u.bd.pC->nullRow = 0;
70091
+ if( u.bd.pC->isTable ){
6983670092
/* The input value in P3 might be of any type: integer, real, string,
6983770093
** blob, or NULL. But it needs to be an integer before we can do
6983870094
** the seek, so covert it. */
6983970095
pIn3 = &aMem[pOp->p3];
6984070096
applyNumericAffinity(pIn3);
69841
- iKey = sqlite3VdbeIntValue(pIn3);
69842
- pC->rowidIsValid = 0;
70097
+ u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70098
+ u.bd.pC->rowidIsValid = 0;
6984370099
6984470100
/* If the P3 value could not be converted into an integer without
6984570101
** loss of information, then special processing is required... */
6984670102
if( (pIn3->flags & MEM_Int)==0 ){
6984770103
if( (pIn3->flags & MEM_Real)==0 ){
@@ -69849,100 +70105,100 @@
6984970105
** then the seek is not possible, so jump to P2 */
6985070106
pc = pOp->p2 - 1;
6985170107
break;
6985270108
}
6985370109
69854
- /* If the approximation iKey is larger than the actual real search
70110
+ /* If the approximation u.bd.iKey is larger than the actual real search
6985570111
** term, substitute >= for > and < for <=. e.g. if the search term
6985670112
** is 4.9 and the integer approximation 5:
6985770113
**
6985870114
** (x > 4.9) -> (x >= 5)
6985970115
** (x <= 4.9) -> (x < 5)
6986070116
*/
69861
- if( pIn3->r<(double)iKey ){
69862
- assert( OP_SeekGe==(OP_SeekGt-1) );
69863
- assert( OP_SeekLt==(OP_SeekLe-1) );
69864
- assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69865
- if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
69866
- }
69867
-
69868
- /* If the approximation iKey is smaller than the actual real search
69869
- ** term, substitute <= for < and > for >=. */
69870
- else if( pIn3->r>(double)iKey ){
69871
- assert( OP_SeekLe==(OP_SeekLt+1) );
69872
- assert( OP_SeekGt==(OP_SeekGe+1) );
69873
- assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69874
- if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
69875
- }
69876
- }
69877
- rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
69878
- if( rc!=SQLITE_OK ){
69879
- goto abort_due_to_error;
69880
- }
69881
- if( res==0 ){
69882
- pC->rowidIsValid = 1;
69883
- pC->lastRowid = iKey;
69884
- }
69885
- }else{
69886
- nField = pOp->p4.i;
69887
- assert( pOp->p4type==P4_INT32 );
69888
- assert( nField>0 );
69889
- r.pKeyInfo = pC->pKeyInfo;
69890
- r.nField = (u16)nField;
69891
-
69892
- /* The next line of code computes as follows, only faster:
69893
- ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
69894
- ** r.flags = UNPACKED_INCRKEY;
69895
- ** }else{
69896
- ** r.flags = 0;
69897
- ** }
69898
- */
69899
- r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
69900
- assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
69901
- assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
69902
- assert( oc!=OP_SeekGe || r.flags==0 );
69903
- assert( oc!=OP_SeekLt || r.flags==0 );
69904
-
69905
- r.aMem = &aMem[pOp->p3];
69906
-#ifdef SQLITE_DEBUG
69907
- { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
69908
-#endif
69909
- ExpandBlob(r.aMem);
69910
- rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
69911
- if( rc!=SQLITE_OK ){
69912
- goto abort_due_to_error;
69913
- }
69914
- pC->rowidIsValid = 0;
69915
- }
69916
- pC->deferredMoveto = 0;
69917
- pC->cacheStatus = CACHE_STALE;
69918
-#ifdef SQLITE_TEST
69919
- sqlite3_search_count++;
69920
-#endif
69921
- if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
69922
- if( res<0 || (res==0 && oc==OP_SeekGt) ){
69923
- rc = sqlite3BtreeNext(pC->pCursor, &res);
69924
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
69925
- pC->rowidIsValid = 0;
69926
- }else{
69927
- res = 0;
69928
- }
69929
- }else{
69930
- assert( oc==OP_SeekLt || oc==OP_SeekLe );
69931
- if( res>0 || (res==0 && oc==OP_SeekLt) ){
69932
- rc = sqlite3BtreePrevious(pC->pCursor, &res);
69933
- if( rc!=SQLITE_OK ) goto abort_due_to_error;
69934
- pC->rowidIsValid = 0;
69935
- }else{
69936
- /* res might be negative because the table is empty. Check to
69937
- ** see if this is the case.
69938
- */
69939
- res = sqlite3BtreeEof(pC->pCursor);
69940
- }
69941
- }
69942
- assert( pOp->p2>0 );
69943
- if( res ){
70117
+ if( pIn3->r<(double)u.bd.iKey ){
70118
+ assert( OP_SeekGe==(OP_SeekGt-1) );
70119
+ assert( OP_SeekLt==(OP_SeekLe-1) );
70120
+ assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
70121
+ if( (u.bd.oc & 0x0001)==(OP_SeekGt & 0x0001) ) u.bd.oc--;
70122
+ }
70123
+
70124
+ /* If the approximation u.bd.iKey is smaller than the actual real search
70125
+ ** term, substitute <= for < and > for >=. */
70126
+ else if( pIn3->r>(double)u.bd.iKey ){
70127
+ assert( OP_SeekLe==(OP_SeekLt+1) );
70128
+ assert( OP_SeekGt==(OP_SeekGe+1) );
70129
+ assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
70130
+ if( (u.bd.oc & 0x0001)==(OP_SeekLt & 0x0001) ) u.bd.oc++;
70131
+ }
70132
+ }
70133
+ rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res);
70134
+ if( rc!=SQLITE_OK ){
70135
+ goto abort_due_to_error;
70136
+ }
70137
+ if( u.bd.res==0 ){
70138
+ u.bd.pC->rowidIsValid = 1;
70139
+ u.bd.pC->lastRowid = u.bd.iKey;
70140
+ }
70141
+ }else{
70142
+ u.bd.nField = pOp->p4.i;
70143
+ assert( pOp->p4type==P4_INT32 );
70144
+ assert( u.bd.nField>0 );
70145
+ u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo;
70146
+ u.bd.r.nField = (u16)u.bd.nField;
70147
+
70148
+ /* The next line of code computes as follows, only faster:
70149
+ ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){
70150
+ ** u.bd.r.flags = UNPACKED_INCRKEY;
70151
+ ** }else{
70152
+ ** u.bd.r.flags = 0;
70153
+ ** }
70154
+ */
70155
+ u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt)));
70156
+ assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY );
70157
+ assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY );
70158
+ assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 );
70159
+ assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 );
70160
+
70161
+ u.bd.r.aMem = &aMem[pOp->p3];
70162
+#ifdef SQLITE_DEBUG
70163
+ { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); }
70164
+#endif
70165
+ ExpandBlob(u.bd.r.aMem);
70166
+ rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res);
70167
+ if( rc!=SQLITE_OK ){
70168
+ goto abort_due_to_error;
70169
+ }
70170
+ u.bd.pC->rowidIsValid = 0;
70171
+ }
70172
+ u.bd.pC->deferredMoveto = 0;
70173
+ u.bd.pC->cacheStatus = CACHE_STALE;
70174
+#ifdef SQLITE_TEST
70175
+ sqlite3_search_count++;
70176
+#endif
70177
+ if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70178
+ if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){
70179
+ rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res);
70180
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
70181
+ u.bd.pC->rowidIsValid = 0;
70182
+ }else{
70183
+ u.bd.res = 0;
70184
+ }
70185
+ }else{
70186
+ assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70187
+ if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){
70188
+ rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res);
70189
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
70190
+ u.bd.pC->rowidIsValid = 0;
70191
+ }else{
70192
+ /* u.bd.res might be negative because the table is empty. Check to
70193
+ ** see if this is the case.
70194
+ */
70195
+ u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor);
70196
+ }
70197
+ }
70198
+ assert( pOp->p2>0 );
70199
+ if( u.bd.res ){
6994470200
pc = pOp->p2 - 1;
6994570201
}
6994670202
break;
6994770203
}
6994870204
@@ -69955,22 +70211,24 @@
6995570211
** This is actually a deferred seek. Nothing actually happens until
6995670212
** the cursor is used to read a record. That way, if no reads
6995770213
** occur, no unnecessary I/O happens.
6995870214
*/
6995970215
case OP_Seek: { /* in2 */
70216
+#if 0 /* local variables moved into u.be */
6996070217
VdbeCursor *pC;
70218
+#endif /* local variables moved into u.be */
6996170219
6996270220
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69963
- pC = p->apCsr[pOp->p1];
69964
- assert( pC!=0 );
69965
- assert( pC->pCursor!=0 );
69966
- assert( pC->isTable );
69967
- pC->nullRow = 0;
70221
+ u.be.pC = p->apCsr[pOp->p1];
70222
+ assert( u.be.pC!=0 );
70223
+ assert( u.be.pC->pCursor!=0 );
70224
+ assert( u.be.pC->isTable );
70225
+ u.be.pC->nullRow = 0;
6996870226
pIn2 = &aMem[pOp->p2];
69969
- pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
69970
- pC->rowidIsValid = 0;
69971
- pC->deferredMoveto = 1;
70227
+ u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
70228
+ u.be.pC->rowidIsValid = 0;
70229
+ u.be.pC->deferredMoveto = 1;
6997270230
break;
6997370231
}
6997470232
6997570233
6997670234
/* Opcode: Found P1 P2 P3 P4 *
@@ -70021,83 +70279,85 @@
7002170279
** See also: NotFound, Found, NotExists
7002270280
*/
7002370281
case OP_NoConflict: /* jump, in3 */
7002470282
case OP_NotFound: /* jump, in3 */
7002570283
case OP_Found: { /* jump, in3 */
70284
+#if 0 /* local variables moved into u.bf */
7002670285
int alreadyExists;
7002770286
int ii;
7002870287
VdbeCursor *pC;
7002970288
int res;
7003070289
char *pFree;
7003170290
UnpackedRecord *pIdxKey;
7003270291
UnpackedRecord r;
7003370292
char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70293
+#endif /* local variables moved into u.bf */
7003470294
7003570295
#ifdef SQLITE_TEST
7003670296
if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
7003770297
#endif
7003870298
70299
+ u.bf.alreadyExists = 0;
7003970300
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7004070301
assert( pOp->p4type==P4_INT32 );
70041
- pC = p->apCsr[pOp->p1];
70042
- assert( pC!=0 );
70302
+ u.bf.pC = p->apCsr[pOp->p1];
70303
+ assert( u.bf.pC!=0 );
7004370304
pIn3 = &aMem[pOp->p3];
70044
- assert( pC->pCursor!=0 );
70045
- assert( pC->isTable==0 );
70046
- pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
70305
+ assert( u.bf.pC->pCursor!=0 );
70306
+ assert( u.bf.pC->isTable==0 );
7004770307
if( pOp->p4.i>0 ){
70048
- r.pKeyInfo = pC->pKeyInfo;
70049
- r.nField = (u16)pOp->p4.i;
70050
- r.aMem = pIn3;
70308
+ u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo;
70309
+ u.bf.r.nField = (u16)pOp->p4.i;
70310
+ u.bf.r.aMem = pIn3;
7005170311
#ifdef SQLITE_DEBUG
7005270312
{
7005370313
int i;
70054
- for(i=0; i<r.nField; i++){
70055
- assert( memIsValid(&r.aMem[i]) );
70056
- if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
70314
+ for(i=0; i<u.bf.r.nField; i++){
70315
+ assert( memIsValid(&u.bf.r.aMem[i]) );
70316
+ if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]);
7005770317
}
7005870318
}
7005970319
#endif
70060
- r.flags = UNPACKED_PREFIX_MATCH;
70061
- pIdxKey = &r;
70320
+ u.bf.r.flags = UNPACKED_PREFIX_MATCH;
70321
+ u.bf.pIdxKey = &u.bf.r;
7006270322
}else{
70063
- pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70064
- pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
70065
- );
70066
- if( pIdxKey==0 ) goto no_mem;
70323
+ u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70324
+ u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree
70325
+ );
70326
+ if( u.bf.pIdxKey==0 ) goto no_mem;
7006770327
assert( pIn3->flags & MEM_Blob );
7006870328
assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70069
- sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
70070
- pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70329
+ sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey);
70330
+ u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
7007170331
}
7007270332
if( pOp->opcode==OP_NoConflict ){
7007370333
/* For the OP_NoConflict opcode, take the jump if any of the
7007470334
** input fields are NULL, since any key with a NULL will not
7007570335
** conflict */
70076
- for(ii=0; ii<r.nField; ii++){
70077
- if( r.aMem[ii].flags & MEM_Null ){
70336
+ for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){
70337
+ if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){
7007870338
pc = pOp->p2 - 1;
7007970339
break;
7008070340
}
7008170341
}
7008270342
}
70083
- rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
70343
+ rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
7008470344
if( pOp->p4.i==0 ){
70085
- sqlite3DbFree(db, pFree);
70345
+ sqlite3DbFree(db, u.bf.pFree);
7008670346
}
7008770347
if( rc!=SQLITE_OK ){
7008870348
break;
7008970349
}
70090
- pC->seekResult = res;
70091
- alreadyExists = (res==0);
70092
- pC->nullRow = 1-alreadyExists;
70093
- pC->deferredMoveto = 0;
70094
- pC->cacheStatus = CACHE_STALE;
70350
+ u.bf.pC->seekResult = u.bf.res;
70351
+ u.bf.alreadyExists = (u.bf.res==0);
70352
+ u.bf.pC->nullRow = 1-u.bf.alreadyExists;
70353
+ u.bf.pC->deferredMoveto = 0;
70354
+ u.bf.pC->cacheStatus = CACHE_STALE;
7009570355
if( pOp->opcode==OP_Found ){
70096
- if( alreadyExists ) pc = pOp->p2 - 1;
70356
+ if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
7009770357
}else{
70098
- if( !alreadyExists ) pc = pOp->p2 - 1;
70358
+ if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
7009970359
}
7010070360
break;
7010170361
}
7010270362
7010370363
/* Opcode: NotExists P1 P2 P3 * *
@@ -70113,37 +70373,39 @@
7011370373
** (with arbitrary multi-value keys).
7011470374
**
7011570375
** See also: Found, NotFound, NoConflict
7011670376
*/
7011770377
case OP_NotExists: { /* jump, in3 */
70378
+#if 0 /* local variables moved into u.bg */
7011870379
VdbeCursor *pC;
7011970380
BtCursor *pCrsr;
7012070381
int res;
7012170382
u64 iKey;
70383
+#endif /* local variables moved into u.bg */
7012270384
7012370385
pIn3 = &aMem[pOp->p3];
7012470386
assert( pIn3->flags & MEM_Int );
7012570387
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70126
- pC = p->apCsr[pOp->p1];
70127
- assert( pC!=0 );
70128
- assert( pC->isTable );
70129
- assert( pC->pseudoTableReg==0 );
70130
- pCrsr = pC->pCursor;
70131
- assert( pCrsr!=0 );
70132
- res = 0;
70133
- iKey = pIn3->u.i;
70134
- rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
70135
- pC->lastRowid = pIn3->u.i;
70136
- pC->rowidIsValid = res==0 ?1:0;
70137
- pC->nullRow = 0;
70138
- pC->cacheStatus = CACHE_STALE;
70139
- pC->deferredMoveto = 0;
70140
- if( res!=0 ){
70388
+ u.bg.pC = p->apCsr[pOp->p1];
70389
+ assert( u.bg.pC!=0 );
70390
+ assert( u.bg.pC->isTable );
70391
+ assert( u.bg.pC->pseudoTableReg==0 );
70392
+ u.bg.pCrsr = u.bg.pC->pCursor;
70393
+ assert( u.bg.pCrsr!=0 );
70394
+ u.bg.res = 0;
70395
+ u.bg.iKey = pIn3->u.i;
70396
+ rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70397
+ u.bg.pC->lastRowid = pIn3->u.i;
70398
+ u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70399
+ u.bg.pC->nullRow = 0;
70400
+ u.bg.pC->cacheStatus = CACHE_STALE;
70401
+ u.bg.pC->deferredMoveto = 0;
70402
+ if( u.bg.res!=0 ){
7014170403
pc = pOp->p2 - 1;
70142
- assert( pC->rowidIsValid==0 );
70404
+ assert( u.bg.pC->rowidIsValid==0 );
7014370405
}
70144
- pC->seekResult = res;
70406
+ u.bg.pC->seekResult = u.bg.res;
7014570407
break;
7014670408
}
7014770409
7014870410
/* Opcode: Sequence P1 P2 * * *
7014970411
** Synopsis: r[P2]=rowid
@@ -70175,23 +70437,25 @@
7017570437
** an SQLITE_FULL error is generated. The P3 register is updated with the '
7017670438
** generated record number. This P3 mechanism is used to help implement the
7017770439
** AUTOINCREMENT feature.
7017870440
*/
7017970441
case OP_NewRowid: { /* out2-prerelease */
70442
+#if 0 /* local variables moved into u.bh */
7018070443
i64 v; /* The new rowid */
7018170444
VdbeCursor *pC; /* Cursor of table to get the new rowid */
7018270445
int res; /* Result of an sqlite3BtreeLast() */
7018370446
int cnt; /* Counter to limit the number of searches */
7018470447
Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
7018570448
VdbeFrame *pFrame; /* Root frame of VDBE */
70449
+#endif /* local variables moved into u.bh */
7018670450
70187
- v = 0;
70188
- res = 0;
70451
+ u.bh.v = 0;
70452
+ u.bh.res = 0;
7018970453
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70190
- pC = p->apCsr[pOp->p1];
70191
- assert( pC!=0 );
70192
- if( NEVER(pC->pCursor==0) ){
70454
+ u.bh.pC = p->apCsr[pOp->p1];
70455
+ assert( u.bh.pC!=0 );
70456
+ if( NEVER(u.bh.pC->pCursor==0) ){
7019370457
/* The zero initialization above is all that is needed */
7019470458
}else{
7019570459
/* The next rowid or record number (different terms for the same
7019670460
** thing) is obtained in a two-step algorithm.
7019770461
**
@@ -70203,11 +70467,11 @@
7020370467
** The second algorithm is to select a rowid at random and see if
7020470468
** it already exists in the table. If it does not exist, we have
7020570469
** succeeded. If the random rowid does exist, we select a new one
7020670470
** and try again, up to 100 times.
7020770471
*/
70208
- assert( pC->isTable );
70472
+ assert( u.bh.pC->isTable );
7020970473
7021070474
#ifdef SQLITE_32BIT_ROWID
7021170475
# define MAX_ROWID 0x7fffffff
7021270476
#else
7021370477
/* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70215,101 +70479,101 @@
7021570479
** to provide the constant while making all compilers happy.
7021670480
*/
7021770481
# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
7021870482
#endif
7021970483
70220
- if( !pC->useRandomRowid ){
70221
- v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70222
- if( v==0 ){
70223
- rc = sqlite3BtreeLast(pC->pCursor, &res);
70484
+ if( !u.bh.pC->useRandomRowid ){
70485
+ u.bh.v = sqlite3BtreeGetCachedRowid(u.bh.pC->pCursor);
70486
+ if( u.bh.v==0 ){
70487
+ rc = sqlite3BtreeLast(u.bh.pC->pCursor, &u.bh.res);
7022470488
if( rc!=SQLITE_OK ){
7022570489
goto abort_due_to_error;
7022670490
}
70227
- if( res ){
70228
- v = 1; /* IMP: R-61914-48074 */
70491
+ if( u.bh.res ){
70492
+ u.bh.v = 1; /* IMP: R-61914-48074 */
7022970493
}else{
70230
- assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70231
- rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70494
+ assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) );
70495
+ rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v);
7023270496
assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70233
- if( v>=MAX_ROWID ){
70234
- pC->useRandomRowid = 1;
70497
+ if( u.bh.v>=MAX_ROWID ){
70498
+ u.bh.pC->useRandomRowid = 1;
7023570499
}else{
70236
- v++; /* IMP: R-29538-34987 */
70500
+ u.bh.v++; /* IMP: R-29538-34987 */
7023770501
}
7023870502
}
7023970503
}
7024070504
7024170505
#ifndef SQLITE_OMIT_AUTOINCREMENT
7024270506
if( pOp->p3 ){
7024370507
/* Assert that P3 is a valid memory cell. */
7024470508
assert( pOp->p3>0 );
7024570509
if( p->pFrame ){
70246
- for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70510
+ for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent);
7024770511
/* Assert that P3 is a valid memory cell. */
70248
- assert( pOp->p3<=pFrame->nMem );
70249
- pMem = &pFrame->aMem[pOp->p3];
70512
+ assert( pOp->p3<=u.bh.pFrame->nMem );
70513
+ u.bh.pMem = &u.bh.pFrame->aMem[pOp->p3];
7025070514
}else{
7025170515
/* Assert that P3 is a valid memory cell. */
7025270516
assert( pOp->p3<=(p->nMem-p->nCursor) );
70253
- pMem = &aMem[pOp->p3];
70254
- memAboutToChange(p, pMem);
70255
- }
70256
- assert( memIsValid(pMem) );
70257
-
70258
- REGISTER_TRACE(pOp->p3, pMem);
70259
- sqlite3VdbeMemIntegerify(pMem);
70260
- assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70261
- if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70517
+ u.bh.pMem = &aMem[pOp->p3];
70518
+ memAboutToChange(p, u.bh.pMem);
70519
+ }
70520
+ assert( memIsValid(u.bh.pMem) );
70521
+
70522
+ REGISTER_TRACE(pOp->p3, u.bh.pMem);
70523
+ sqlite3VdbeMemIntegerify(u.bh.pMem);
70524
+ assert( (u.bh.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70525
+ if( u.bh.pMem->u.i==MAX_ROWID || u.bh.pC->useRandomRowid ){
7026270526
rc = SQLITE_FULL; /* IMP: R-12275-61338 */
7026370527
goto abort_due_to_error;
7026470528
}
70265
- if( v<pMem->u.i+1 ){
70266
- v = pMem->u.i + 1;
70529
+ if( u.bh.v<u.bh.pMem->u.i+1 ){
70530
+ u.bh.v = u.bh.pMem->u.i + 1;
7026770531
}
70268
- pMem->u.i = v;
70532
+ u.bh.pMem->u.i = u.bh.v;
7026970533
}
7027070534
#endif
7027170535
70272
- sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70536
+ sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0);
7027370537
}
70274
- if( pC->useRandomRowid ){
70538
+ if( u.bh.pC->useRandomRowid ){
7027570539
/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
7027670540
** largest possible integer (9223372036854775807) then the database
7027770541
** engine starts picking positive candidate ROWIDs at random until
7027870542
** it finds one that is not previously used. */
7027970543
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
7028070544
** an AUTOINCREMENT table. */
7028170545
/* on the first attempt, simply do one more than previous */
70282
- v = lastRowid;
70283
- v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70284
- v++; /* ensure non-zero */
70285
- cnt = 0;
70286
- while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
70287
- 0, &res))==SQLITE_OK)
70288
- && (res==0)
70289
- && (++cnt<100)){
70546
+ u.bh.v = lastRowid;
70547
+ u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70548
+ u.bh.v++; /* ensure non-zero */
70549
+ u.bh.cnt = 0;
70550
+ while( ((rc = sqlite3BtreeMovetoUnpacked(u.bh.pC->pCursor, 0, (u64)u.bh.v,
70551
+ 0, &u.bh.res))==SQLITE_OK)
70552
+ && (u.bh.res==0)
70553
+ && (++u.bh.cnt<100)){
7029070554
/* collision - try another random rowid */
70291
- sqlite3_randomness(sizeof(v), &v);
70292
- if( cnt<5 ){
70555
+ sqlite3_randomness(sizeof(u.bh.v), &u.bh.v);
70556
+ if( u.bh.cnt<5 ){
7029370557
/* try "small" random rowids for the initial attempts */
70294
- v &= 0xffffff;
70558
+ u.bh.v &= 0xffffff;
7029570559
}else{
70296
- v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70560
+ u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
7029770561
}
70298
- v++; /* ensure non-zero */
70562
+ u.bh.v++; /* ensure non-zero */
7029970563
}
70300
- if( rc==SQLITE_OK && res==0 ){
70564
+ if( rc==SQLITE_OK && u.bh.res==0 ){
7030170565
rc = SQLITE_FULL; /* IMP: R-38219-53002 */
7030270566
goto abort_due_to_error;
7030370567
}
70304
- assert( v>0 ); /* EV: R-40812-03570 */
70568
+ assert( u.bh.v>0 ); /* EV: R-40812-03570 */
7030570569
}
70306
- pC->rowidIsValid = 0;
70307
- pC->deferredMoveto = 0;
70308
- pC->cacheStatus = CACHE_STALE;
70570
+ u.bh.pC->rowidIsValid = 0;
70571
+ u.bh.pC->deferredMoveto = 0;
70572
+ u.bh.pC->cacheStatus = CACHE_STALE;
7030970573
}
70310
- pOut->u.i = v;
70574
+ pOut->u.i = u.bh.v;
7031170575
break;
7031270576
}
7031370577
7031470578
/* Opcode: Insert P1 P2 P3 P4 P5
7031570579
** Synopsis: intkey=r[P3] data=r[P2]
@@ -70357,72 +70621,74 @@
7035770621
** This works exactly like OP_Insert except that the key is the
7035870622
** integer value P3, not the value of the integer stored in register P3.
7035970623
*/
7036070624
case OP_Insert:
7036170625
case OP_InsertInt: {
70626
+#if 0 /* local variables moved into u.bi */
7036270627
Mem *pData; /* MEM cell holding data for the record to be inserted */
7036370628
Mem *pKey; /* MEM cell holding key for the record */
7036470629
i64 iKey; /* The integer ROWID or key for the record to be inserted */
7036570630
VdbeCursor *pC; /* Cursor to table into which insert is written */
7036670631
int nZero; /* Number of zero-bytes to append */
7036770632
int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
7036870633
const char *zDb; /* database name - used by the update hook */
7036970634
const char *zTbl; /* Table name - used by the opdate hook */
7037070635
int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
70636
+#endif /* local variables moved into u.bi */
7037170637
70372
- pData = &aMem[pOp->p2];
70638
+ u.bi.pData = &aMem[pOp->p2];
7037370639
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70374
- assert( memIsValid(pData) );
70375
- pC = p->apCsr[pOp->p1];
70376
- assert( pC!=0 );
70377
- assert( pC->pCursor!=0 );
70378
- assert( pC->pseudoTableReg==0 );
70379
- assert( pC->isTable );
70380
- REGISTER_TRACE(pOp->p2, pData);
70640
+ assert( memIsValid(u.bi.pData) );
70641
+ u.bi.pC = p->apCsr[pOp->p1];
70642
+ assert( u.bi.pC!=0 );
70643
+ assert( u.bi.pC->pCursor!=0 );
70644
+ assert( u.bi.pC->pseudoTableReg==0 );
70645
+ assert( u.bi.pC->isTable );
70646
+ REGISTER_TRACE(pOp->p2, u.bi.pData);
7038170647
7038270648
if( pOp->opcode==OP_Insert ){
70383
- pKey = &aMem[pOp->p3];
70384
- assert( pKey->flags & MEM_Int );
70385
- assert( memIsValid(pKey) );
70386
- REGISTER_TRACE(pOp->p3, pKey);
70387
- iKey = pKey->u.i;
70649
+ u.bi.pKey = &aMem[pOp->p3];
70650
+ assert( u.bi.pKey->flags & MEM_Int );
70651
+ assert( memIsValid(u.bi.pKey) );
70652
+ REGISTER_TRACE(pOp->p3, u.bi.pKey);
70653
+ u.bi.iKey = u.bi.pKey->u.i;
7038870654
}else{
7038970655
assert( pOp->opcode==OP_InsertInt );
70390
- iKey = pOp->p3;
70656
+ u.bi.iKey = pOp->p3;
7039170657
}
7039270658
7039370659
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70394
- if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
70395
- if( pData->flags & MEM_Null ){
70396
- pData->z = 0;
70397
- pData->n = 0;
70398
- }else{
70399
- assert( pData->flags & (MEM_Blob|MEM_Str) );
70400
- }
70401
- seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
70402
- if( pData->flags & MEM_Zero ){
70403
- nZero = pData->u.nZero;
70404
- }else{
70405
- nZero = 0;
70406
- }
70407
- sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70408
- rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70409
- pData->z, pData->n, nZero,
70410
- (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
70660
+ if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bi.iKey;
70661
+ if( u.bi.pData->flags & MEM_Null ){
70662
+ u.bi.pData->z = 0;
70663
+ u.bi.pData->n = 0;
70664
+ }else{
70665
+ assert( u.bi.pData->flags & (MEM_Blob|MEM_Str) );
70666
+ }
70667
+ u.bi.seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bi.pC->seekResult : 0);
70668
+ if( u.bi.pData->flags & MEM_Zero ){
70669
+ u.bi.nZero = u.bi.pData->u.nZero;
70670
+ }else{
70671
+ u.bi.nZero = 0;
70672
+ }
70673
+ sqlite3BtreeSetCachedRowid(u.bi.pC->pCursor, 0);
70674
+ rc = sqlite3BtreeInsert(u.bi.pC->pCursor, 0, u.bi.iKey,
70675
+ u.bi.pData->z, u.bi.pData->n, u.bi.nZero,
70676
+ (pOp->p5 & OPFLAG_APPEND)!=0, u.bi.seekResult
7041170677
);
70412
- pC->rowidIsValid = 0;
70413
- pC->deferredMoveto = 0;
70414
- pC->cacheStatus = CACHE_STALE;
70678
+ u.bi.pC->rowidIsValid = 0;
70679
+ u.bi.pC->deferredMoveto = 0;
70680
+ u.bi.pC->cacheStatus = CACHE_STALE;
7041570681
7041670682
/* Invoke the update-hook if required. */
7041770683
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70418
- zDb = db->aDb[pC->iDb].zName;
70419
- zTbl = pOp->p4.z;
70420
- op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70421
- assert( pC->isTable );
70422
- db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
70423
- assert( pC->iDb>=0 );
70684
+ u.bi.zDb = db->aDb[u.bi.pC->iDb].zName;
70685
+ u.bi.zTbl = pOp->p4.z;
70686
+ u.bi.op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70687
+ assert( u.bi.pC->isTable );
70688
+ db->xUpdateCallback(db->pUpdateArg, u.bi.op, u.bi.zDb, u.bi.zTbl, u.bi.iKey);
70689
+ assert( u.bi.pC->iDb>=0 );
7042470690
}
7042570691
break;
7042670692
}
7042770693
7042870694
/* Opcode: Delete P1 P2 * P4 *
@@ -70444,39 +70710,41 @@
7044470710
** pointing to. The update hook will be invoked, if it exists.
7044570711
** If P4 is not NULL then the P1 cursor must have been positioned
7044670712
** using OP_NotFound prior to invoking this opcode.
7044770713
*/
7044870714
case OP_Delete: {
70715
+#if 0 /* local variables moved into u.bj */
7044970716
i64 iKey;
7045070717
VdbeCursor *pC;
70718
+#endif /* local variables moved into u.bj */
7045170719
7045270720
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70453
- pC = p->apCsr[pOp->p1];
70454
- assert( pC!=0 );
70455
- assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70456
- iKey = pC->lastRowid; /* Only used for the update hook */
70721
+ u.bj.pC = p->apCsr[pOp->p1];
70722
+ assert( u.bj.pC!=0 );
70723
+ assert( u.bj.pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70724
+ u.bj.iKey = u.bj.pC->lastRowid; /* Only used for the update hook */
7045770725
7045870726
/* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
7045970727
** OP_Column on the same table without any intervening operations that
70460
- ** might move or invalidate the cursor. Hence cursor pC is always pointing
70728
+ ** might move or invalidate the cursor. Hence cursor u.bj.pC is always pointing
7046170729
** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
7046270730
** below is always a no-op and cannot fail. We will run it anyhow, though,
7046370731
** to guard against future changes to the code generator.
7046470732
**/
70465
- assert( pC->deferredMoveto==0 );
70466
- rc = sqlite3VdbeCursorMoveto(pC);
70733
+ assert( u.bj.pC->deferredMoveto==0 );
70734
+ rc = sqlite3VdbeCursorMoveto(u.bj.pC);
7046770735
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7046870736
70469
- sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70470
- rc = sqlite3BtreeDelete(pC->pCursor);
70471
- pC->cacheStatus = CACHE_STALE;
70737
+ sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0);
70738
+ rc = sqlite3BtreeDelete(u.bj.pC->pCursor);
70739
+ u.bj.pC->cacheStatus = CACHE_STALE;
7047270740
7047370741
/* Invoke the update-hook if required. */
70474
- if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
70742
+ if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && u.bj.pC->isTable ){
7047570743
db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
70476
- db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
70477
- assert( pC->iDb>=0 );
70744
+ db->aDb[u.bj.pC->iDb].zName, pOp->p4.z, u.bj.iKey);
70745
+ assert( u.bj.pC->iDb>=0 );
7047870746
}
7047970747
if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
7048070748
break;
7048170749
}
7048270750
/* Opcode: ResetCount * * * * *
@@ -70506,21 +70774,23 @@
7050670774
**
7050770775
** Fall through to next instruction if the two records compare equal to
7050870776
** each other. Jump to P2 if they are different.
7050970777
*/
7051070778
case OP_SorterCompare: {
70779
+#if 0 /* local variables moved into u.bk */
7051170780
VdbeCursor *pC;
7051270781
int res;
7051370782
int nIgnore;
70783
+#endif /* local variables moved into u.bk */
7051470784
70515
- pC = p->apCsr[pOp->p1];
70516
- assert( isSorter(pC) );
70785
+ u.bk.pC = p->apCsr[pOp->p1];
70786
+ assert( isSorter(u.bk.pC) );
7051770787
assert( pOp->p4type==P4_INT32 );
7051870788
pIn3 = &aMem[pOp->p3];
70519
- nIgnore = pOp->p4.i;
70520
- rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70521
- if( res ){
70789
+ u.bk.nIgnore = pOp->p4.i;
70790
+ rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res);
70791
+ if( u.bk.res ){
7052270792
pc = pOp->p2-1;
7052370793
}
7052470794
break;
7052570795
};
7052670796
@@ -70528,16 +70798,18 @@
7052870798
** Synopsis: r[P2]=data
7052970799
**
7053070800
** Write into register P2 the current sorter data for sorter cursor P1.
7053170801
*/
7053270802
case OP_SorterData: {
70803
+#if 0 /* local variables moved into u.bl */
7053370804
VdbeCursor *pC;
70805
+#endif /* local variables moved into u.bl */
7053470806
7053570807
pOut = &aMem[pOp->p2];
70536
- pC = p->apCsr[pOp->p1];
70537
- assert( isSorter(pC) );
70538
- rc = sqlite3VdbeSorterRowkey(pC, pOut);
70808
+ u.bl.pC = p->apCsr[pOp->p1];
70809
+ assert( isSorter(u.bl.pC) );
70810
+ rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
7053970811
break;
7054070812
}
7054170813
7054270814
/* Opcode: RowData P1 P2 * * *
7054370815
** Synopsis: r[P2]=data
@@ -70561,64 +70833,66 @@
7056170833
** If the P1 cursor must be pointing to a valid row (not a NULL row)
7056270834
** of a real table, not a pseudo-table.
7056370835
*/
7056470836
case OP_RowKey:
7056570837
case OP_RowData: {
70838
+#if 0 /* local variables moved into u.bm */
7056670839
VdbeCursor *pC;
7056770840
BtCursor *pCrsr;
7056870841
u32 n;
7056970842
i64 n64;
70843
+#endif /* local variables moved into u.bm */
7057070844
7057170845
pOut = &aMem[pOp->p2];
7057270846
memAboutToChange(p, pOut);
7057370847
7057470848
/* Note that RowKey and RowData are really exactly the same instruction */
7057570849
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70576
- pC = p->apCsr[pOp->p1];
70577
- assert( isSorter(pC)==0 );
70578
- assert( pC->isTable || pOp->opcode!=OP_RowData );
70579
- assert( pC->isTable==0 || pOp->opcode==OP_RowData );
70580
- assert( pC!=0 );
70581
- assert( pC->nullRow==0 );
70582
- assert( pC->pseudoTableReg==0 );
70583
- assert( pC->pCursor!=0 );
70584
- pCrsr = pC->pCursor;
70585
- assert( sqlite3BtreeCursorIsValid(pCrsr) );
70850
+ u.bm.pC = p->apCsr[pOp->p1];
70851
+ assert( isSorter(u.bm.pC)==0 );
70852
+ assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
70853
+ assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData );
70854
+ assert( u.bm.pC!=0 );
70855
+ assert( u.bm.pC->nullRow==0 );
70856
+ assert( u.bm.pC->pseudoTableReg==0 );
70857
+ assert( u.bm.pC->pCursor!=0 );
70858
+ u.bm.pCrsr = u.bm.pC->pCursor;
70859
+ assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) );
7058670860
7058770861
/* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
7058870862
** OP_Rewind/Op_Next with no intervening instructions that might invalidate
7058970863
** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
7059070864
** a no-op and can never fail. But we leave it in place as a safety.
7059170865
*/
70592
- assert( pC->deferredMoveto==0 );
70593
- rc = sqlite3VdbeCursorMoveto(pC);
70594
- if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70595
-
70596
- if( pC->isTable==0 ){
70597
- assert( !pC->isTable );
70598
- VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
70599
- assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70600
- if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70601
- goto too_big;
70602
- }
70603
- n = (u32)n64;
70604
- }else{
70605
- VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n);
70606
- assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70607
- if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70608
- goto too_big;
70609
- }
70610
- }
70611
- if( sqlite3VdbeMemGrow(pOut, n, 0) ){
70612
- goto no_mem;
70613
- }
70614
- pOut->n = n;
70615
- MemSetTypeFlag(pOut, MEM_Blob);
70616
- if( pC->isTable==0 ){
70617
- rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z);
70618
- }else{
70619
- rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z);
70866
+ assert( u.bm.pC->deferredMoveto==0 );
70867
+ rc = sqlite3VdbeCursorMoveto(u.bm.pC);
70868
+ if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70869
+
70870
+ if( u.bm.pC->isTable==0 ){
70871
+ assert( !u.bm.pC->isTable );
70872
+ VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
70873
+ assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70874
+ if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70875
+ goto too_big;
70876
+ }
70877
+ u.bm.n = (u32)u.bm.n64;
70878
+ }else{
70879
+ VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bm.pCrsr, &u.bm.n);
70880
+ assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70881
+ if( u.bm.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70882
+ goto too_big;
70883
+ }
70884
+ }
70885
+ if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
70886
+ goto no_mem;
70887
+ }
70888
+ pOut->n = u.bm.n;
70889
+ MemSetTypeFlag(pOut, MEM_Blob);
70890
+ if( u.bm.pC->isTable==0 ){
70891
+ rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70892
+ }else{
70893
+ rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
7062070894
}
7062170895
pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
7062270896
UPDATE_MAX_BLOBSIZE(pOut);
7062370897
REGISTER_TRACE(pOp->p2, pOut);
7062470898
break;
@@ -70633,44 +70907,46 @@
7063370907
** P1 can be either an ordinary table or a virtual table. There used to
7063470908
** be a separate OP_VRowid opcode for use with virtual tables, but this
7063570909
** one opcode now works for both table types.
7063670910
*/
7063770911
case OP_Rowid: { /* out2-prerelease */
70912
+#if 0 /* local variables moved into u.bn */
7063870913
VdbeCursor *pC;
7063970914
i64 v;
7064070915
sqlite3_vtab *pVtab;
7064170916
const sqlite3_module *pModule;
70917
+#endif /* local variables moved into u.bn */
7064270918
7064370919
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70644
- pC = p->apCsr[pOp->p1];
70645
- assert( pC!=0 );
70646
- assert( pC->pseudoTableReg==0 || pC->nullRow );
70647
- if( pC->nullRow ){
70920
+ u.bn.pC = p->apCsr[pOp->p1];
70921
+ assert( u.bn.pC!=0 );
70922
+ assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow );
70923
+ if( u.bn.pC->nullRow ){
7064870924
pOut->flags = MEM_Null;
7064970925
break;
70650
- }else if( pC->deferredMoveto ){
70651
- v = pC->movetoTarget;
70926
+ }else if( u.bn.pC->deferredMoveto ){
70927
+ u.bn.v = u.bn.pC->movetoTarget;
7065270928
#ifndef SQLITE_OMIT_VIRTUALTABLE
70653
- }else if( pC->pVtabCursor ){
70654
- pVtab = pC->pVtabCursor->pVtab;
70655
- pModule = pVtab->pModule;
70656
- assert( pModule->xRowid );
70657
- rc = pModule->xRowid(pC->pVtabCursor, &v);
70658
- sqlite3VtabImportErrmsg(p, pVtab);
70929
+ }else if( u.bn.pC->pVtabCursor ){
70930
+ u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab;
70931
+ u.bn.pModule = u.bn.pVtab->pModule;
70932
+ assert( u.bn.pModule->xRowid );
70933
+ rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v);
70934
+ sqlite3VtabImportErrmsg(p, u.bn.pVtab);
7065970935
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7066070936
}else{
70661
- assert( pC->pCursor!=0 );
70662
- rc = sqlite3VdbeCursorMoveto(pC);
70937
+ assert( u.bn.pC->pCursor!=0 );
70938
+ rc = sqlite3VdbeCursorMoveto(u.bn.pC);
7066370939
if( rc ) goto abort_due_to_error;
70664
- if( pC->rowidIsValid ){
70665
- v = pC->lastRowid;
70940
+ if( u.bn.pC->rowidIsValid ){
70941
+ u.bn.v = u.bn.pC->lastRowid;
7066670942
}else{
70667
- rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70943
+ rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v);
7066870944
assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
7066970945
}
7067070946
}
70671
- pOut->u.i = v;
70947
+ pOut->u.i = u.bn.v;
7067270948
break;
7067370949
}
7067470950
7067570951
/* Opcode: NullRow P1 * * * *
7067670952
**
@@ -70677,21 +70953,23 @@
7067770953
** Move the cursor P1 to a null row. Any OP_Column operations
7067870954
** that occur while the cursor is on the null row will always
7067970955
** write a NULL.
7068070956
*/
7068170957
case OP_NullRow: {
70958
+#if 0 /* local variables moved into u.bo */
7068270959
VdbeCursor *pC;
70960
+#endif /* local variables moved into u.bo */
7068370961
7068470962
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70685
- pC = p->apCsr[pOp->p1];
70686
- assert( pC!=0 );
70687
- pC->nullRow = 1;
70688
- pC->rowidIsValid = 0;
70689
- pC->cacheStatus = CACHE_STALE;
70690
- assert( pC->pCursor || pC->pVtabCursor );
70691
- if( pC->pCursor ){
70692
- sqlite3BtreeClearCursor(pC->pCursor);
70963
+ u.bo.pC = p->apCsr[pOp->p1];
70964
+ assert( u.bo.pC!=0 );
70965
+ u.bo.pC->nullRow = 1;
70966
+ u.bo.pC->rowidIsValid = 0;
70967
+ u.bo.pC->cacheStatus = CACHE_STALE;
70968
+ assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
70969
+ if( u.bo.pC->pCursor ){
70970
+ sqlite3BtreeClearCursor(u.bo.pC->pCursor);
7069370971
}
7069470972
break;
7069570973
}
7069670974
7069770975
/* Opcode: Last P1 P2 * * *
@@ -70701,26 +70979,28 @@
7070170979
** If the table or index is empty and P2>0, then jump immediately to P2.
7070270980
** If P2 is 0 or if the table or index is not empty, fall through
7070370981
** to the following instruction.
7070470982
*/
7070570983
case OP_Last: { /* jump */
70984
+#if 0 /* local variables moved into u.bp */
7070670985
VdbeCursor *pC;
7070770986
BtCursor *pCrsr;
7070870987
int res;
70988
+#endif /* local variables moved into u.bp */
7070970989
7071070990
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70711
- pC = p->apCsr[pOp->p1];
70712
- assert( pC!=0 );
70713
- pCrsr = pC->pCursor;
70714
- res = 0;
70715
- assert( pCrsr!=0 );
70716
- rc = sqlite3BtreeLast(pCrsr, &res);
70717
- pC->nullRow = (u8)res;
70718
- pC->deferredMoveto = 0;
70719
- pC->rowidIsValid = 0;
70720
- pC->cacheStatus = CACHE_STALE;
70721
- if( pOp->p2>0 && res ){
70991
+ u.bp.pC = p->apCsr[pOp->p1];
70992
+ assert( u.bp.pC!=0 );
70993
+ u.bp.pCrsr = u.bp.pC->pCursor;
70994
+ u.bp.res = 0;
70995
+ assert( u.bp.pCrsr!=0 );
70996
+ rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
70997
+ u.bp.pC->nullRow = (u8)u.bp.res;
70998
+ u.bp.pC->deferredMoveto = 0;
70999
+ u.bp.pC->rowidIsValid = 0;
71000
+ u.bp.pC->cacheStatus = CACHE_STALE;
71001
+ if( pOp->p2>0 && u.bp.res ){
7072271002
pc = pOp->p2 - 1;
7072371003
}
7072471004
break;
7072571005
}
7072671006
@@ -70753,32 +71033,34 @@
7075371033
** If the table or index is empty and P2>0, then jump immediately to P2.
7075471034
** If P2 is 0 or if the table or index is not empty, fall through
7075571035
** to the following instruction.
7075671036
*/
7075771037
case OP_Rewind: { /* jump */
71038
+#if 0 /* local variables moved into u.bq */
7075871039
VdbeCursor *pC;
7075971040
BtCursor *pCrsr;
7076071041
int res;
71042
+#endif /* local variables moved into u.bq */
7076171043
7076271044
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70763
- pC = p->apCsr[pOp->p1];
70764
- assert( pC!=0 );
70765
- assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
70766
- res = 1;
70767
- if( isSorter(pC) ){
70768
- rc = sqlite3VdbeSorterRewind(db, pC, &res);
71045
+ u.bq.pC = p->apCsr[pOp->p1];
71046
+ assert( u.bq.pC!=0 );
71047
+ assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) );
71048
+ u.bq.res = 1;
71049
+ if( isSorter(u.bq.pC) ){
71050
+ rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
7076971051
}else{
70770
- pCrsr = pC->pCursor;
70771
- assert( pCrsr );
70772
- rc = sqlite3BtreeFirst(pCrsr, &res);
70773
- pC->deferredMoveto = 0;
70774
- pC->cacheStatus = CACHE_STALE;
70775
- pC->rowidIsValid = 0;
70776
- }
70777
- pC->nullRow = (u8)res;
71052
+ u.bq.pCrsr = u.bq.pC->pCursor;
71053
+ assert( u.bq.pCrsr );
71054
+ rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
71055
+ u.bq.pC->deferredMoveto = 0;
71056
+ u.bq.pC->cacheStatus = CACHE_STALE;
71057
+ u.bq.pC->rowidIsValid = 0;
71058
+ }
71059
+ u.bq.pC->nullRow = (u8)u.bq.res;
7077871060
assert( pOp->p2>0 && pOp->p2<p->nOp );
70779
- if( res ){
71061
+ if( u.bq.res ){
7078071062
pc = pOp->p2 - 1;
7078171063
}
7078271064
break;
7078371065
}
7078471066
@@ -70825,47 +71107,49 @@
7082571107
**
7082671108
** This opcode works just like OP_Prev except that if cursor P1 is not
7082771109
** open it behaves a no-op.
7082871110
*/
7082971111
case OP_SorterNext: { /* jump */
71112
+#if 0 /* local variables moved into u.br */
7083071113
VdbeCursor *pC;
7083171114
int res;
71115
+#endif /* local variables moved into u.br */
7083271116
70833
- pC = p->apCsr[pOp->p1];
70834
- assert( isSorter(pC) );
70835
- rc = sqlite3VdbeSorterNext(db, pC, &res);
71117
+ u.br.pC = p->apCsr[pOp->p1];
71118
+ assert( isSorter(u.br.pC) );
71119
+ rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res);
7083671120
goto next_tail;
7083771121
case OP_PrevIfOpen: /* jump */
7083871122
case OP_NextIfOpen: /* jump */
7083971123
if( p->apCsr[pOp->p1]==0 ) break;
7084071124
/* Fall through */
7084171125
case OP_Prev: /* jump */
7084271126
case OP_Next: /* jump */
7084371127
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7084471128
assert( pOp->p5<ArraySize(p->aCounter) );
70845
- pC = p->apCsr[pOp->p1];
70846
- assert( pC!=0 );
70847
- assert( pC->deferredMoveto==0 );
70848
- assert( pC->pCursor );
71129
+ u.br.pC = p->apCsr[pOp->p1];
71130
+ assert( u.br.pC!=0 );
71131
+ assert( u.br.pC->deferredMoveto==0 );
71132
+ assert( u.br.pC->pCursor );
7084971133
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
7085071134
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
7085171135
assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
7085271136
assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
70853
- rc = pOp->p4.xAdvance(pC->pCursor, &res);
71137
+ rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res);
7085471138
next_tail:
70855
- pC->cacheStatus = CACHE_STALE;
70856
- if( res==0 ){
70857
- pC->nullRow = 0;
71139
+ u.br.pC->cacheStatus = CACHE_STALE;
71140
+ if( u.br.res==0 ){
71141
+ u.br.pC->nullRow = 0;
7085871142
pc = pOp->p2 - 1;
7085971143
p->aCounter[pOp->p5]++;
7086071144
#ifdef SQLITE_TEST
7086171145
sqlite3_search_count++;
7086271146
#endif
7086371147
}else{
70864
- pC->nullRow = 1;
71148
+ u.br.pC->nullRow = 1;
7086571149
}
70866
- pC->rowidIsValid = 0;
71150
+ u.br.pC->rowidIsValid = 0;
7086771151
goto check_for_interrupt;
7086871152
}
7086971153
7087071154
/* Opcode: IdxInsert P1 P2 P3 * P5
7087171155
** Synopsis: key=r[P2]
@@ -70880,37 +71164,39 @@
7088071164
** This instruction only works for indices. The equivalent instruction
7088171165
** for tables is OP_Insert.
7088271166
*/
7088371167
case OP_SorterInsert: /* in2 */
7088471168
case OP_IdxInsert: { /* in2 */
71169
+#if 0 /* local variables moved into u.bs */
7088571170
VdbeCursor *pC;
7088671171
BtCursor *pCrsr;
7088771172
int nKey;
7088871173
const char *zKey;
71174
+#endif /* local variables moved into u.bs */
7088971175
7089071176
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70891
- pC = p->apCsr[pOp->p1];
70892
- assert( pC!=0 );
70893
- assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) );
71177
+ u.bs.pC = p->apCsr[pOp->p1];
71178
+ assert( u.bs.pC!=0 );
71179
+ assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) );
7089471180
pIn2 = &aMem[pOp->p2];
7089571181
assert( pIn2->flags & MEM_Blob );
70896
- pCrsr = pC->pCursor;
71182
+ u.bs.pCrsr = u.bs.pC->pCursor;
7089771183
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70898
- assert( pCrsr!=0 );
70899
- assert( pC->isTable==0 );
71184
+ assert( u.bs.pCrsr!=0 );
71185
+ assert( u.bs.pC->isTable==0 );
7090071186
rc = ExpandBlob(pIn2);
7090171187
if( rc==SQLITE_OK ){
70902
- if( isSorter(pC) ){
70903
- rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
71188
+ if( isSorter(u.bs.pC) ){
71189
+ rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
7090471190
}else{
70905
- nKey = pIn2->n;
70906
- zKey = pIn2->z;
70907
- rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3,
70908
- ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
71191
+ u.bs.nKey = pIn2->n;
71192
+ u.bs.zKey = pIn2->z;
71193
+ rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
71194
+ ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
7090971195
);
70910
- assert( pC->deferredMoveto==0 );
70911
- pC->cacheStatus = CACHE_STALE;
71196
+ assert( u.bs.pC->deferredMoveto==0 );
71197
+ u.bs.pC->cacheStatus = CACHE_STALE;
7091271198
}
7091371199
}
7091471200
break;
7091571201
}
7091671202
@@ -70920,36 +71206,38 @@
7092071206
** The content of P3 registers starting at register P2 form
7092171207
** an unpacked index key. This opcode removes that entry from the
7092271208
** index opened by cursor P1.
7092371209
*/
7092471210
case OP_IdxDelete: {
71211
+#if 0 /* local variables moved into u.bt */
7092571212
VdbeCursor *pC;
7092671213
BtCursor *pCrsr;
7092771214
int res;
7092871215
UnpackedRecord r;
71216
+#endif /* local variables moved into u.bt */
7092971217
7093071218
assert( pOp->p3>0 );
7093171219
assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
7093271220
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70933
- pC = p->apCsr[pOp->p1];
70934
- assert( pC!=0 );
70935
- pCrsr = pC->pCursor;
70936
- assert( pCrsr!=0 );
71221
+ u.bt.pC = p->apCsr[pOp->p1];
71222
+ assert( u.bt.pC!=0 );
71223
+ u.bt.pCrsr = u.bt.pC->pCursor;
71224
+ assert( u.bt.pCrsr!=0 );
7093771225
assert( pOp->p5==0 );
70938
- r.pKeyInfo = pC->pKeyInfo;
70939
- r.nField = (u16)pOp->p3;
70940
- r.flags = UNPACKED_PREFIX_MATCH;
70941
- r.aMem = &aMem[pOp->p2];
71226
+ u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
71227
+ u.bt.r.nField = (u16)pOp->p3;
71228
+ u.bt.r.flags = UNPACKED_PREFIX_MATCH;
71229
+ u.bt.r.aMem = &aMem[pOp->p2];
7094271230
#ifdef SQLITE_DEBUG
70943
- { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71231
+ { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
7094471232
#endif
70945
- rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
70946
- if( rc==SQLITE_OK && res==0 ){
70947
- rc = sqlite3BtreeDelete(pCrsr);
71233
+ rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
71234
+ if( rc==SQLITE_OK && u.bt.res==0 ){
71235
+ rc = sqlite3BtreeDelete(u.bt.pCrsr);
7094871236
}
70949
- assert( pC->deferredMoveto==0 );
70950
- pC->cacheStatus = CACHE_STALE;
71237
+ assert( u.bt.pC->deferredMoveto==0 );
71238
+ u.bt.pC->cacheStatus = CACHE_STALE;
7095171239
break;
7095271240
}
7095371241
7095471242
/* Opcode: IdxRowid P1 P2 * * *
7095571243
** Synopsis: r[P2]=rowid
@@ -70959,31 +71247,32 @@
7095971247
** the rowid of the table entry to which this index entry points.
7096071248
**
7096171249
** See also: Rowid, MakeRecord.
7096271250
*/
7096371251
case OP_IdxRowid: { /* out2-prerelease */
71252
+#if 0 /* local variables moved into u.bu */
7096471253
BtCursor *pCrsr;
7096571254
VdbeCursor *pC;
7096671255
i64 rowid;
71256
+#endif /* local variables moved into u.bu */
7096771257
7096871258
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70969
- pC = p->apCsr[pOp->p1];
70970
- assert( pC!=0 );
70971
- pCrsr = pC->pCursor;
70972
- assert( pCrsr!=0 );
71259
+ u.bu.pC = p->apCsr[pOp->p1];
71260
+ assert( u.bu.pC!=0 );
71261
+ u.bu.pCrsr = u.bu.pC->pCursor;
71262
+ assert( u.bu.pCrsr!=0 );
7097371263
pOut->flags = MEM_Null;
70974
- rc = sqlite3VdbeCursorMoveto(pC);
71264
+ rc = sqlite3VdbeCursorMoveto(u.bu.pC);
7097571265
if( NEVER(rc) ) goto abort_due_to_error;
70976
- assert( pC->deferredMoveto==0 );
70977
- assert( pC->isTable==0 );
70978
- if( !pC->nullRow ){
70979
- rowid = 0; /* Not needed. Only used to silence a warning. */
70980
- rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
71266
+ assert( u.bu.pC->deferredMoveto==0 );
71267
+ assert( u.bu.pC->isTable==0 );
71268
+ if( !u.bu.pC->nullRow ){
71269
+ rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
7098171270
if( rc!=SQLITE_OK ){
7098271271
goto abort_due_to_error;
7098371272
}
70984
- pOut->u.i = rowid;
71273
+ pOut->u.i = u.bu.rowid;
7098571274
pOut->flags = MEM_Int;
7098671275
}
7098771276
break;
7098871277
}
7098971278
@@ -71015,42 +71304,43 @@
7101571304
** If P5 is non-zero then the key value is increased by an epsilon prior
7101671305
** to the comparison. This makes the opcode work like IdxLE.
7101771306
*/
7101871307
case OP_IdxLT: /* jump */
7101971308
case OP_IdxGE: { /* jump */
71309
+#if 0 /* local variables moved into u.bv */
7102071310
VdbeCursor *pC;
7102171311
int res;
7102271312
UnpackedRecord r;
71313
+#endif /* local variables moved into u.bv */
7102371314
7102471315
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71025
- pC = p->apCsr[pOp->p1];
71026
- assert( pC!=0 );
71027
- assert( pC->isOrdered );
71028
- assert( pC->pCursor!=0);
71029
- assert( pC->deferredMoveto==0 );
71316
+ u.bv.pC = p->apCsr[pOp->p1];
71317
+ assert( u.bv.pC!=0 );
71318
+ assert( u.bv.pC->isOrdered );
71319
+ assert( u.bv.pC->pCursor!=0);
71320
+ assert( u.bv.pC->deferredMoveto==0 );
7103071321
assert( pOp->p5==0 || pOp->p5==1 );
7103171322
assert( pOp->p4type==P4_INT32 );
71032
- r.pKeyInfo = pC->pKeyInfo;
71033
- r.nField = (u16)pOp->p4.i;
71323
+ u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
71324
+ u.bv.r.nField = (u16)pOp->p4.i;
7103471325
if( pOp->p5 ){
71035
- r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71326
+ u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
7103671327
}else{
71037
- r.flags = UNPACKED_PREFIX_MATCH;
71328
+ u.bv.r.flags = UNPACKED_PREFIX_MATCH;
7103871329
}
71039
- r.aMem = &aMem[pOp->p3];
71330
+ u.bv.r.aMem = &aMem[pOp->p3];
7104071331
#ifdef SQLITE_DEBUG
71041
- { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71332
+ { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
7104271333
#endif
71043
- res = 0; /* Not needed. Only used to silence a warning. */
71044
- rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71334
+ rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
7104571335
if( pOp->opcode==OP_IdxLT ){
71046
- res = -res;
71336
+ u.bv.res = -u.bv.res;
7104771337
}else{
7104871338
assert( pOp->opcode==OP_IdxGE );
71049
- res++;
71339
+ u.bv.res++;
7105071340
}
71051
- if( res>0 ){
71341
+ if( u.bv.res>0 ){
7105271342
pc = pOp->p2 - 1 ;
7105371343
}
7105471344
break;
7105571345
}
7105671346
@@ -71073,46 +71363,47 @@
7107371363
** If AUTOVACUUM is disabled then a zero is stored in register P2.
7107471364
**
7107571365
** See also: Clear
7107671366
*/
7107771367
case OP_Destroy: { /* out2-prerelease */
71368
+#if 0 /* local variables moved into u.bw */
7107871369
int iMoved;
7107971370
int iCnt;
7108071371
Vdbe *pVdbe;
7108171372
int iDb;
71373
+#endif /* local variables moved into u.bw */
7108271374
7108371375
assert( p->readOnly==0 );
7108471376
#ifndef SQLITE_OMIT_VIRTUALTABLE
71085
- iCnt = 0;
71086
- for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){
71087
- if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader
71088
- && pVdbe->inVtabMethod<2 && pVdbe->pc>=0
71377
+ u.bw.iCnt = 0;
71378
+ for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){
71379
+ if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader
71380
+ && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0
7108971381
){
71090
- iCnt++;
71382
+ u.bw.iCnt++;
7109171383
}
7109271384
}
7109371385
#else
71094
- iCnt = db->nVdbeRead;
71386
+ u.bw.iCnt = db->nVdbeRead;
7109571387
#endif
7109671388
pOut->flags = MEM_Null;
71097
- if( iCnt>1 ){
71389
+ if( u.bw.iCnt>1 ){
7109871390
rc = SQLITE_LOCKED;
7109971391
p->errorAction = OE_Abort;
7110071392
}else{
71101
- iDb = pOp->p3;
71102
- assert( iCnt==1 );
71103
- assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
71104
- iMoved = 0; /* Not needed. Only to silence a warning. */
71105
- rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
71393
+ u.bw.iDb = pOp->p3;
71394
+ assert( u.bw.iCnt==1 );
71395
+ assert( (p->btreeMask & (((yDbMask)1)<<u.bw.iDb))!=0 );
71396
+ rc = sqlite3BtreeDropTable(db->aDb[u.bw.iDb].pBt, pOp->p1, &u.bw.iMoved);
7110671397
pOut->flags = MEM_Int;
71107
- pOut->u.i = iMoved;
71398
+ pOut->u.i = u.bw.iMoved;
7110871399
#ifndef SQLITE_OMIT_AUTOVACUUM
71109
- if( rc==SQLITE_OK && iMoved!=0 ){
71110
- sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
71400
+ if( rc==SQLITE_OK && u.bw.iMoved!=0 ){
71401
+ sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1);
7111171402
/* All OP_Destroy operations occur on the same btree */
71112
- assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
71113
- resetSchemaOnFault = iDb+1;
71403
+ assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 );
71404
+ resetSchemaOnFault = u.bw.iDb+1;
7111471405
}
7111571406
#endif
7111671407
}
7111771408
break;
7111871409
}
@@ -71134,25 +71425,27 @@
7113471425
** also incremented by the number of rows in the table being cleared.
7113571426
**
7113671427
** See also: Destroy
7113771428
*/
7113871429
case OP_Clear: {
71430
+#if 0 /* local variables moved into u.bx */
7113971431
int nChange;
71140
-
71141
- nChange = 0;
71432
+#endif /* local variables moved into u.bx */
71433
+
71434
+ u.bx.nChange = 0;
7114271435
assert( p->readOnly==0 );
7114371436
assert( pOp->p1!=1 );
7114471437
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
7114571438
rc = sqlite3BtreeClearTable(
71146
- db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
71439
+ db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
7114771440
);
7114871441
if( pOp->p3 ){
71149
- p->nChange += nChange;
71442
+ p->nChange += u.bx.nChange;
7115071443
if( pOp->p3>0 ){
7115171444
assert( memIsValid(&aMem[pOp->p3]) );
7115271445
memAboutToChange(p, &aMem[pOp->p3]);
71153
- aMem[pOp->p3].u.i += nChange;
71446
+ aMem[pOp->p3].u.i += u.bx.nChange;
7115471447
}
7115571448
}
7115671449
break;
7115771450
}
7115871451
@@ -71180,28 +71473,30 @@
7118071473
**
7118171474
** See documentation on OP_CreateTable for additional information.
7118271475
*/
7118371476
case OP_CreateIndex: /* out2-prerelease */
7118471477
case OP_CreateTable: { /* out2-prerelease */
71478
+#if 0 /* local variables moved into u.by */
7118571479
int pgno;
7118671480
int flags;
7118771481
Db *pDb;
71482
+#endif /* local variables moved into u.by */
7118871483
71189
- pgno = 0;
71484
+ u.by.pgno = 0;
7119071485
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7119171486
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7119271487
assert( p->readOnly==0 );
71193
- pDb = &db->aDb[pOp->p1];
71194
- assert( pDb->pBt!=0 );
71488
+ u.by.pDb = &db->aDb[pOp->p1];
71489
+ assert( u.by.pDb->pBt!=0 );
7119571490
if( pOp->opcode==OP_CreateTable ){
71196
- /* flags = BTREE_INTKEY; */
71197
- flags = BTREE_INTKEY;
71491
+ /* u.by.flags = BTREE_INTKEY; */
71492
+ u.by.flags = BTREE_INTKEY;
7119871493
}else{
71199
- flags = BTREE_BLOBKEY;
71494
+ u.by.flags = BTREE_BLOBKEY;
7120071495
}
71201
- rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
71202
- pOut->u.i = pgno;
71496
+ rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags);
71497
+ pOut->u.i = u.by.pgno;
7120371498
break;
7120471499
}
7120571500
7120671501
/* Opcode: ParseSchema P1 * * P4 *
7120771502
**
@@ -71210,54 +71505,56 @@
7121071505
**
7121171506
** This opcode invokes the parser to create a new virtual machine,
7121271507
** then runs the new virtual machine. It is thus a re-entrant opcode.
7121371508
*/
7121471509
case OP_ParseSchema: {
71510
+#if 0 /* local variables moved into u.bz */
7121571511
int iDb;
7121671512
const char *zMaster;
7121771513
char *zSql;
7121871514
InitData initData;
71515
+#endif /* local variables moved into u.bz */
7121971516
7122071517
/* Any prepared statement that invokes this opcode will hold mutexes
71221
- ** on every btree. This is a prerequisite for invoking
71518
+ ** on every btree. This is a prerequisite for invoking
7122271519
** sqlite3InitCallback().
7122371520
*/
7122471521
#ifdef SQLITE_DEBUG
71225
- for(iDb=0; iDb<db->nDb; iDb++){
71226
- assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
71522
+ for(u.bz.iDb=0; u.bz.iDb<db->nDb; u.bz.iDb++){
71523
+ assert( u.bz.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bz.iDb].pBt) );
7122771524
}
7122871525
#endif
7122971526
71230
- iDb = pOp->p1;
71231
- assert( iDb>=0 && iDb<db->nDb );
71232
- assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
71527
+ u.bz.iDb = pOp->p1;
71528
+ assert( u.bz.iDb>=0 && u.bz.iDb<db->nDb );
71529
+ assert( DbHasProperty(db, u.bz.iDb, DB_SchemaLoaded) );
7123371530
/* Used to be a conditional */ {
71234
- zMaster = SCHEMA_TABLE(iDb);
71235
- initData.db = db;
71236
- initData.iDb = pOp->p1;
71237
- initData.pzErrMsg = &p->zErrMsg;
71238
- zSql = sqlite3MPrintf(db,
71531
+ u.bz.zMaster = SCHEMA_TABLE(u.bz.iDb);
71532
+ u.bz.initData.db = db;
71533
+ u.bz.initData.iDb = pOp->p1;
71534
+ u.bz.initData.pzErrMsg = &p->zErrMsg;
71535
+ u.bz.zSql = sqlite3MPrintf(db,
7123971536
"SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
71240
- db->aDb[iDb].zName, zMaster, pOp->p4.z);
71241
- if( zSql==0 ){
71537
+ db->aDb[u.bz.iDb].zName, u.bz.zMaster, pOp->p4.z);
71538
+ if( u.bz.zSql==0 ){
7124271539
rc = SQLITE_NOMEM;
7124371540
}else{
7124471541
assert( db->init.busy==0 );
7124571542
db->init.busy = 1;
71246
- initData.rc = SQLITE_OK;
71543
+ u.bz.initData.rc = SQLITE_OK;
7124771544
assert( !db->mallocFailed );
71248
- rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
71249
- if( rc==SQLITE_OK ) rc = initData.rc;
71250
- sqlite3DbFree(db, zSql);
71545
+ rc = sqlite3_exec(db, u.bz.zSql, sqlite3InitCallback, &u.bz.initData, 0);
71546
+ if( rc==SQLITE_OK ) rc = u.bz.initData.rc;
71547
+ sqlite3DbFree(db, u.bz.zSql);
7125171548
db->init.busy = 0;
7125271549
}
7125371550
}
7125471551
if( rc ) sqlite3ResetAllSchemasOfConnection(db);
7125571552
if( rc==SQLITE_NOMEM ){
7125671553
goto no_mem;
7125771554
}
71258
- break;
71555
+ break;
7125971556
}
7126071557
7126171558
#if !defined(SQLITE_OMIT_ANALYZE)
7126271559
/* Opcode: LoadAnalysis P1 * * * *
7126371560
**
@@ -71329,44 +71626,46 @@
7132971626
** file, not the main database file.
7133071627
**
7133171628
** This opcode is used to implement the integrity_check pragma.
7133271629
*/
7133371630
case OP_IntegrityCk: {
71631
+#if 0 /* local variables moved into u.ca */
7133471632
int nRoot; /* Number of tables to check. (Number of root pages.) */
7133571633
int *aRoot; /* Array of rootpage numbers for tables to be checked */
7133671634
int j; /* Loop counter */
7133771635
int nErr; /* Number of errors reported */
7133871636
char *z; /* Text of the error report */
7133971637
Mem *pnErr; /* Register keeping track of errors remaining */
71638
+#endif /* local variables moved into u.ca */
7134071639
7134171640
assert( p->bIsReader );
71342
- nRoot = pOp->p2;
71343
- assert( nRoot>0 );
71344
- aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
71345
- if( aRoot==0 ) goto no_mem;
71641
+ u.ca.nRoot = pOp->p2;
71642
+ assert( u.ca.nRoot>0 );
71643
+ u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) );
71644
+ if( u.ca.aRoot==0 ) goto no_mem;
7134671645
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71347
- pnErr = &aMem[pOp->p3];
71348
- assert( (pnErr->flags & MEM_Int)!=0 );
71349
- assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
71646
+ u.ca.pnErr = &aMem[pOp->p3];
71647
+ assert( (u.ca.pnErr->flags & MEM_Int)!=0 );
71648
+ assert( (u.ca.pnErr->flags & (MEM_Str|MEM_Blob))==0 );
7135071649
pIn1 = &aMem[pOp->p1];
71351
- for(j=0; j<nRoot; j++){
71352
- aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
71650
+ for(u.ca.j=0; u.ca.j<u.ca.nRoot; u.ca.j++){
71651
+ u.ca.aRoot[u.ca.j] = (int)sqlite3VdbeIntValue(&pIn1[u.ca.j]);
7135371652
}
71354
- aRoot[j] = 0;
71653
+ u.ca.aRoot[u.ca.j] = 0;
7135571654
assert( pOp->p5<db->nDb );
7135671655
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
71357
- z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
71358
- (int)pnErr->u.i, &nErr);
71359
- sqlite3DbFree(db, aRoot);
71360
- pnErr->u.i -= nErr;
71656
+ u.ca.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.ca.aRoot, u.ca.nRoot,
71657
+ (int)u.ca.pnErr->u.i, &u.ca.nErr);
71658
+ sqlite3DbFree(db, u.ca.aRoot);
71659
+ u.ca.pnErr->u.i -= u.ca.nErr;
7136171660
sqlite3VdbeMemSetNull(pIn1);
71362
- if( nErr==0 ){
71363
- assert( z==0 );
71364
- }else if( z==0 ){
71661
+ if( u.ca.nErr==0 ){
71662
+ assert( u.ca.z==0 );
71663
+ }else if( u.ca.z==0 ){
7136571664
goto no_mem;
7136671665
}else{
71367
- sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
71666
+ sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free);
7136871667
}
7136971668
UPDATE_MAX_BLOBSIZE(pIn1);
7137071669
sqlite3VdbeChangeEncoding(pIn1, encoding);
7137171670
break;
7137271671
}
@@ -71398,22 +71697,24 @@
7139871697
** Extract the smallest value from boolean index P1 and put that value into
7139971698
** register P3. Or, if boolean index P1 is initially empty, leave P3
7140071699
** unchanged and jump to instruction P2.
7140171700
*/
7140271701
case OP_RowSetRead: { /* jump, in1, out3 */
71702
+#if 0 /* local variables moved into u.cb */
7140371703
i64 val;
71704
+#endif /* local variables moved into u.cb */
7140471705
7140571706
pIn1 = &aMem[pOp->p1];
71406
- if( (pIn1->flags & MEM_RowSet)==0
71407
- || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71707
+ if( (pIn1->flags & MEM_RowSet)==0
71708
+ || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
7140871709
){
7140971710
/* The boolean index is empty */
7141071711
sqlite3VdbeMemSetNull(pIn1);
7141171712
pc = pOp->p2 - 1;
7141271713
}else{
7141371714
/* A value was pulled from the index */
71414
- sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71715
+ sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
7141571716
}
7141671717
goto check_for_interrupt;
7141771718
}
7141871719
7141971720
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -71439,16 +71740,18 @@
7143971740
** inserted, there is no need to search to see if the same value was
7144071741
** previously inserted as part of set X (only if it was previously
7144171742
** inserted as part of some other set).
7144271743
*/
7144371744
case OP_RowSetTest: { /* jump, in1, in3 */
71745
+#if 0 /* local variables moved into u.cc */
7144471746
int iSet;
7144571747
int exists;
71748
+#endif /* local variables moved into u.cc */
7144671749
7144771750
pIn1 = &aMem[pOp->p1];
7144871751
pIn3 = &aMem[pOp->p3];
71449
- iSet = pOp->p4.i;
71752
+ u.cc.iSet = pOp->p4.i;
7145071753
assert( pIn3->flags&MEM_Int );
7145171754
7145271755
/* If there is anything other than a rowset object in memory cell P1,
7145371756
** delete it now and initialize P1 with an empty rowset
7145471757
*/
@@ -71456,21 +71759,21 @@
7145671759
sqlite3VdbeMemSetRowSet(pIn1);
7145771760
if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
7145871761
}
7145971762
7146071763
assert( pOp->p4type==P4_INT32 );
71461
- assert( iSet==-1 || iSet>=0 );
71462
- if( iSet ){
71463
- exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71464
- (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71764
+ assert( u.cc.iSet==-1 || u.cc.iSet>=0 );
71765
+ if( u.cc.iSet ){
71766
+ u.cc.exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71767
+ (u8)(u.cc.iSet>=0 ? u.cc.iSet & 0xf : 0xff),
7146571768
pIn3->u.i);
71466
- if( exists ){
71769
+ if( u.cc.exists ){
7146771770
pc = pOp->p2 - 1;
7146871771
break;
7146971772
}
7147071773
}
71471
- if( iSet>=0 ){
71774
+ if( u.cc.iSet>=0 ){
7147271775
sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
7147371776
}
7147471777
break;
7147571778
}
7147671779
@@ -71489,109 +71792,111 @@
7148971792
** memory required by the sub-vdbe at runtime.
7149071793
**
7149171794
** P4 is a pointer to the VM containing the trigger program.
7149271795
*/
7149371796
case OP_Program: { /* jump */
71797
+#if 0 /* local variables moved into u.cd */
7149471798
int nMem; /* Number of memory registers for sub-program */
7149571799
int nByte; /* Bytes of runtime space required for sub-program */
7149671800
Mem *pRt; /* Register to allocate runtime space */
7149771801
Mem *pMem; /* Used to iterate through memory cells */
7149871802
Mem *pEnd; /* Last memory cell in new array */
7149971803
VdbeFrame *pFrame; /* New vdbe frame to execute in */
7150071804
SubProgram *pProgram; /* Sub-program to execute */
7150171805
void *t; /* Token identifying trigger */
71806
+#endif /* local variables moved into u.cd */
7150271807
71503
- pProgram = pOp->p4.pProgram;
71504
- pRt = &aMem[pOp->p3];
71505
- assert( pProgram->nOp>0 );
71506
-
71507
- /* If the p5 flag is clear, then recursive invocation of triggers is
71808
+ u.cd.pProgram = pOp->p4.pProgram;
71809
+ u.cd.pRt = &aMem[pOp->p3];
71810
+ assert( u.cd.pProgram->nOp>0 );
71811
+
71812
+ /* If the p5 flag is clear, then recursive invocation of triggers is
7150871813
** disabled for backwards compatibility (p5 is set if this sub-program
7150971814
** is really a trigger, not a foreign key action, and the flag set
7151071815
** and cleared by the "PRAGMA recursive_triggers" command is clear).
71511
- **
71512
- ** It is recursive invocation of triggers, at the SQL level, that is
71513
- ** disabled. In some cases a single trigger may generate more than one
71514
- ** SubProgram (if the trigger may be executed with more than one different
71816
+ **
71817
+ ** It is recursive invocation of triggers, at the SQL level, that is
71818
+ ** disabled. In some cases a single trigger may generate more than one
71819
+ ** SubProgram (if the trigger may be executed with more than one different
7151571820
** ON CONFLICT algorithm). SubProgram structures associated with a
71516
- ** single trigger all have the same value for the SubProgram.token
71821
+ ** single trigger all have the same value for the SubProgram.token
7151771822
** variable. */
7151871823
if( pOp->p5 ){
71519
- t = pProgram->token;
71520
- for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent);
71521
- if( pFrame ) break;
71824
+ u.cd.t = u.cd.pProgram->token;
71825
+ for(u.cd.pFrame=p->pFrame; u.cd.pFrame && u.cd.pFrame->token!=u.cd.t; u.cd.pFrame=u.cd.pFrame->pParent);
71826
+ if( u.cd.pFrame ) break;
7152271827
}
7152371828
7152471829
if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
7152571830
rc = SQLITE_ERROR;
7152671831
sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
7152771832
break;
7152871833
}
7152971834
71530
- /* Register pRt is used to store the memory required to save the state
71835
+ /* Register u.cd.pRt is used to store the memory required to save the state
7153171836
** of the current program, and the memory required at runtime to execute
71532
- ** the trigger program. If this trigger has been fired before, then pRt
71837
+ ** the trigger program. If this trigger has been fired before, then u.cd.pRt
7153371838
** is already allocated. Otherwise, it must be initialized. */
71534
- if( (pRt->flags&MEM_Frame)==0 ){
71535
- /* SubProgram.nMem is set to the number of memory cells used by the
71839
+ if( (u.cd.pRt->flags&MEM_Frame)==0 ){
71840
+ /* SubProgram.nMem is set to the number of memory cells used by the
7153671841
** program stored in SubProgram.aOp. As well as these, one memory
7153771842
** cell is required for each cursor used by the program. Set local
71538
- ** variable nMem (and later, VdbeFrame.nChildMem) to this value.
71843
+ ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value.
7153971844
*/
71540
- nMem = pProgram->nMem + pProgram->nCsr;
71541
- nByte = ROUND8(sizeof(VdbeFrame))
71542
- + nMem * sizeof(Mem)
71543
- + pProgram->nCsr * sizeof(VdbeCursor *)
71544
- + pProgram->nOnce * sizeof(u8);
71545
- pFrame = sqlite3DbMallocZero(db, nByte);
71546
- if( !pFrame ){
71845
+ u.cd.nMem = u.cd.pProgram->nMem + u.cd.pProgram->nCsr;
71846
+ u.cd.nByte = ROUND8(sizeof(VdbeFrame))
71847
+ + u.cd.nMem * sizeof(Mem)
71848
+ + u.cd.pProgram->nCsr * sizeof(VdbeCursor *)
71849
+ + u.cd.pProgram->nOnce * sizeof(u8);
71850
+ u.cd.pFrame = sqlite3DbMallocZero(db, u.cd.nByte);
71851
+ if( !u.cd.pFrame ){
7154771852
goto no_mem;
7154871853
}
71549
- sqlite3VdbeMemRelease(pRt);
71550
- pRt->flags = MEM_Frame;
71551
- pRt->u.pFrame = pFrame;
71552
-
71553
- pFrame->v = p;
71554
- pFrame->nChildMem = nMem;
71555
- pFrame->nChildCsr = pProgram->nCsr;
71556
- pFrame->pc = pc;
71557
- pFrame->aMem = p->aMem;
71558
- pFrame->nMem = p->nMem;
71559
- pFrame->apCsr = p->apCsr;
71560
- pFrame->nCursor = p->nCursor;
71561
- pFrame->aOp = p->aOp;
71562
- pFrame->nOp = p->nOp;
71563
- pFrame->token = pProgram->token;
71564
- pFrame->aOnceFlag = p->aOnceFlag;
71565
- pFrame->nOnceFlag = p->nOnceFlag;
71566
-
71567
- pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71568
- for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71569
- pMem->flags = MEM_Invalid;
71570
- pMem->db = db;
71854
+ sqlite3VdbeMemRelease(u.cd.pRt);
71855
+ u.cd.pRt->flags = MEM_Frame;
71856
+ u.cd.pRt->u.pFrame = u.cd.pFrame;
71857
+
71858
+ u.cd.pFrame->v = p;
71859
+ u.cd.pFrame->nChildMem = u.cd.nMem;
71860
+ u.cd.pFrame->nChildCsr = u.cd.pProgram->nCsr;
71861
+ u.cd.pFrame->pc = pc;
71862
+ u.cd.pFrame->aMem = p->aMem;
71863
+ u.cd.pFrame->nMem = p->nMem;
71864
+ u.cd.pFrame->apCsr = p->apCsr;
71865
+ u.cd.pFrame->nCursor = p->nCursor;
71866
+ u.cd.pFrame->aOp = p->aOp;
71867
+ u.cd.pFrame->nOp = p->nOp;
71868
+ u.cd.pFrame->token = u.cd.pProgram->token;
71869
+ u.cd.pFrame->aOnceFlag = p->aOnceFlag;
71870
+ u.cd.pFrame->nOnceFlag = p->nOnceFlag;
71871
+
71872
+ u.cd.pEnd = &VdbeFrameMem(u.cd.pFrame)[u.cd.pFrame->nChildMem];
71873
+ for(u.cd.pMem=VdbeFrameMem(u.cd.pFrame); u.cd.pMem!=u.cd.pEnd; u.cd.pMem++){
71874
+ u.cd.pMem->flags = MEM_Invalid;
71875
+ u.cd.pMem->db = db;
7157171876
}
7157271877
}else{
71573
- pFrame = pRt->u.pFrame;
71574
- assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
71575
- assert( pProgram->nCsr==pFrame->nChildCsr );
71576
- assert( pc==pFrame->pc );
71878
+ u.cd.pFrame = u.cd.pRt->u.pFrame;
71879
+ assert( u.cd.pProgram->nMem+u.cd.pProgram->nCsr==u.cd.pFrame->nChildMem );
71880
+ assert( u.cd.pProgram->nCsr==u.cd.pFrame->nChildCsr );
71881
+ assert( pc==u.cd.pFrame->pc );
7157771882
}
7157871883
7157971884
p->nFrame++;
71580
- pFrame->pParent = p->pFrame;
71581
- pFrame->lastRowid = lastRowid;
71582
- pFrame->nChange = p->nChange;
71885
+ u.cd.pFrame->pParent = p->pFrame;
71886
+ u.cd.pFrame->lastRowid = lastRowid;
71887
+ u.cd.pFrame->nChange = p->nChange;
7158371888
p->nChange = 0;
71584
- p->pFrame = pFrame;
71585
- p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
71586
- p->nMem = pFrame->nChildMem;
71587
- p->nCursor = (u16)pFrame->nChildCsr;
71889
+ p->pFrame = u.cd.pFrame;
71890
+ p->aMem = aMem = &VdbeFrameMem(u.cd.pFrame)[-1];
71891
+ p->nMem = u.cd.pFrame->nChildMem;
71892
+ p->nCursor = (u16)u.cd.pFrame->nChildCsr;
7158871893
p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71589
- p->aOp = aOp = pProgram->aOp;
71590
- p->nOp = pProgram->nOp;
71894
+ p->aOp = aOp = u.cd.pProgram->aOp;
71895
+ p->nOp = u.cd.pProgram->nOp;
7159171896
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71592
- p->nOnceFlag = pProgram->nOnce;
71897
+ p->nOnceFlag = u.cd.pProgram->nOnce;
7159371898
pc = -1;
7159471899
memset(p->aOnceFlag, 0, p->nOnceFlag);
7159571900
7159671901
break;
7159771902
}
@@ -71607,15 +71912,17 @@
7160771912
** The address of the cell in the parent frame is determined by adding
7160871913
** the value of the P1 argument to the value of the P1 argument to the
7160971914
** calling OP_Program instruction.
7161071915
*/
7161171916
case OP_Param: { /* out2-prerelease */
71917
+#if 0 /* local variables moved into u.ce */
7161271918
VdbeFrame *pFrame;
7161371919
Mem *pIn;
71614
- pFrame = p->pFrame;
71615
- pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
71616
- sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
71920
+#endif /* local variables moved into u.ce */
71921
+ u.ce.pFrame = p->pFrame;
71922
+ u.ce.pIn = &u.ce.pFrame->aMem[pOp->p1 + u.ce.pFrame->aOp[u.ce.pFrame->pc].p1];
71923
+ sqlite3VdbeMemShallowCopy(pOut, u.ce.pIn, MEM_Ephem);
7161771924
break;
7161871925
}
7161971926
7162071927
#endif /* #ifndef SQLITE_OMIT_TRIGGER */
7162171928
@@ -71672,23 +71979,26 @@
7167271979
**
7167371980
** This instruction throws an error if the memory cell is not initially
7167471981
** an integer.
7167571982
*/
7167671983
case OP_MemMax: { /* in2 */
71984
+#if 0 /* local variables moved into u.cf */
71985
+ Mem *pIn1;
7167771986
VdbeFrame *pFrame;
71987
+#endif /* local variables moved into u.cf */
7167871988
if( p->pFrame ){
71679
- for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
71680
- pIn1 = &pFrame->aMem[pOp->p1];
71989
+ for(u.cf.pFrame=p->pFrame; u.cf.pFrame->pParent; u.cf.pFrame=u.cf.pFrame->pParent);
71990
+ u.cf.pIn1 = &u.cf.pFrame->aMem[pOp->p1];
7168171991
}else{
71682
- pIn1 = &aMem[pOp->p1];
71992
+ u.cf.pIn1 = &aMem[pOp->p1];
7168371993
}
71684
- assert( memIsValid(pIn1) );
71685
- sqlite3VdbeMemIntegerify(pIn1);
71994
+ assert( memIsValid(u.cf.pIn1) );
71995
+ sqlite3VdbeMemIntegerify(u.cf.pIn1);
7168671996
pIn2 = &aMem[pOp->p2];
7168771997
sqlite3VdbeMemIntegerify(pIn2);
71688
- if( pIn1->u.i<pIn2->u.i){
71689
- pIn1->u.i = pIn2->u.i;
71998
+ if( u.cf.pIn1->u.i<pIn2->u.i){
71999
+ u.cf.pIn1->u.i = pIn2->u.i;
7169072000
}
7169172001
break;
7169272002
}
7169372003
#endif /* SQLITE_OMIT_AUTOINCREMENT */
7169472004
@@ -71755,58 +72065,60 @@
7175572065
**
7175672066
** The P5 arguments are taken from register P2 and its
7175772067
** successors.
7175872068
*/
7175972069
case OP_AggStep: {
72070
+#if 0 /* local variables moved into u.cg */
7176072071
int n;
7176172072
int i;
7176272073
Mem *pMem;
7176372074
Mem *pRec;
7176472075
sqlite3_context ctx;
7176572076
sqlite3_value **apVal;
71766
-
71767
- n = pOp->p5;
71768
- assert( n>=0 );
71769
- pRec = &aMem[pOp->p2];
71770
- apVal = p->apArg;
71771
- assert( apVal || n==0 );
71772
- for(i=0; i<n; i++, pRec++){
71773
- assert( memIsValid(pRec) );
71774
- apVal[i] = pRec;
71775
- memAboutToChange(p, pRec);
71776
- sqlite3VdbeMemStoreType(pRec);
71777
- }
71778
- ctx.pFunc = pOp->p4.pFunc;
72077
+#endif /* local variables moved into u.cg */
72078
+
72079
+ u.cg.n = pOp->p5;
72080
+ assert( u.cg.n>=0 );
72081
+ u.cg.pRec = &aMem[pOp->p2];
72082
+ u.cg.apVal = p->apArg;
72083
+ assert( u.cg.apVal || u.cg.n==0 );
72084
+ for(u.cg.i=0; u.cg.i<u.cg.n; u.cg.i++, u.cg.pRec++){
72085
+ assert( memIsValid(u.cg.pRec) );
72086
+ u.cg.apVal[u.cg.i] = u.cg.pRec;
72087
+ memAboutToChange(p, u.cg.pRec);
72088
+ sqlite3VdbeMemStoreType(u.cg.pRec);
72089
+ }
72090
+ u.cg.ctx.pFunc = pOp->p4.pFunc;
7177972091
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71780
- ctx.pMem = pMem = &aMem[pOp->p3];
71781
- pMem->n++;
71782
- ctx.s.flags = MEM_Null;
71783
- ctx.s.z = 0;
71784
- ctx.s.zMalloc = 0;
71785
- ctx.s.xDel = 0;
71786
- ctx.s.db = db;
71787
- ctx.isError = 0;
71788
- ctx.pColl = 0;
71789
- ctx.skipFlag = 0;
71790
- if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
72092
+ u.cg.ctx.pMem = u.cg.pMem = &aMem[pOp->p3];
72093
+ u.cg.pMem->n++;
72094
+ u.cg.ctx.s.flags = MEM_Null;
72095
+ u.cg.ctx.s.z = 0;
72096
+ u.cg.ctx.s.zMalloc = 0;
72097
+ u.cg.ctx.s.xDel = 0;
72098
+ u.cg.ctx.s.db = db;
72099
+ u.cg.ctx.isError = 0;
72100
+ u.cg.ctx.pColl = 0;
72101
+ u.cg.ctx.skipFlag = 0;
72102
+ if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
7179172103
assert( pOp>p->aOp );
7179272104
assert( pOp[-1].p4type==P4_COLLSEQ );
7179372105
assert( pOp[-1].opcode==OP_CollSeq );
71794
- ctx.pColl = pOp[-1].p4.pColl;
71795
- }
71796
- (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
71797
- if( ctx.isError ){
71798
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
71799
- rc = ctx.isError;
71800
- }
71801
- if( ctx.skipFlag ){
72106
+ u.cg.ctx.pColl = pOp[-1].p4.pColl;
72107
+ }
72108
+ (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */
72109
+ if( u.cg.ctx.isError ){
72110
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cg.ctx.s));
72111
+ rc = u.cg.ctx.isError;
72112
+ }
72113
+ if( u.cg.ctx.skipFlag ){
7180272114
assert( pOp[-1].opcode==OP_CollSeq );
71803
- i = pOp[-1].p1;
71804
- if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1);
72115
+ u.cg.i = pOp[-1].p1;
72116
+ if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1);
7180572117
}
7180672118
71807
- sqlite3VdbeMemRelease(&ctx.s);
72119
+ sqlite3VdbeMemRelease(&u.cg.ctx.s);
7180872120
7180972121
break;
7181072122
}
7181172123
7181272124
/* Opcode: AggFinal P1 P2 * P4 *
@@ -71821,21 +72133,23 @@
7182172133
** functions that can take varying numbers of arguments. The
7182272134
** P4 argument is only needed for the degenerate case where
7182372135
** the step function was not previously called.
7182472136
*/
7182572137
case OP_AggFinal: {
72138
+#if 0 /* local variables moved into u.ch */
7182672139
Mem *pMem;
72140
+#endif /* local variables moved into u.ch */
7182772141
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71828
- pMem = &aMem[pOp->p1];
71829
- assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
71830
- rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
72142
+ u.ch.pMem = &aMem[pOp->p1];
72143
+ assert( (u.ch.pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
72144
+ rc = sqlite3VdbeMemFinalize(u.ch.pMem, pOp->p4.pFunc);
7183172145
if( rc ){
71832
- sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
72146
+ sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem));
7183372147
}
71834
- sqlite3VdbeChangeEncoding(pMem, encoding);
71835
- UPDATE_MAX_BLOBSIZE(pMem);
71836
- if( sqlite3VdbeMemTooBig(pMem) ){
72148
+ sqlite3VdbeChangeEncoding(u.ch.pMem, encoding);
72149
+ UPDATE_MAX_BLOBSIZE(u.ch.pMem);
72150
+ if( sqlite3VdbeMemTooBig(u.ch.pMem) ){
7183772151
goto too_big;
7183872152
}
7183972153
break;
7184072154
}
7184172155
@@ -71850,29 +72164,31 @@
7185072164
** in the WAL that have been checkpointed after the checkpoint
7185172165
** completes into mem[P3+2]. However on an error, mem[P3+1] and
7185272166
** mem[P3+2] are initialized to -1.
7185372167
*/
7185472168
case OP_Checkpoint: {
72169
+#if 0 /* local variables moved into u.ci */
7185572170
int i; /* Loop counter */
7185672171
int aRes[3]; /* Results */
7185772172
Mem *pMem; /* Write results here */
72173
+#endif /* local variables moved into u.ci */
7185872174
7185972175
assert( p->readOnly==0 );
71860
- aRes[0] = 0;
71861
- aRes[1] = aRes[2] = -1;
72176
+ u.ci.aRes[0] = 0;
72177
+ u.ci.aRes[1] = u.ci.aRes[2] = -1;
7186272178
assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
7186372179
|| pOp->p2==SQLITE_CHECKPOINT_FULL
7186472180
|| pOp->p2==SQLITE_CHECKPOINT_RESTART
7186572181
);
71866
- rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
72182
+ rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]);
7186772183
if( rc==SQLITE_BUSY ){
7186872184
rc = SQLITE_OK;
71869
- aRes[0] = 1;
72185
+ u.ci.aRes[0] = 1;
7187072186
}
71871
- for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
71872
- sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]);
71873
- }
72187
+ for(u.ci.i=0, u.ci.pMem = &aMem[pOp->p3]; u.ci.i<3; u.ci.i++, u.ci.pMem++){
72188
+ sqlite3VdbeMemSetInt64(u.ci.pMem, (i64)u.ci.aRes[u.ci.i]);
72189
+ }
7187472190
break;
7187572191
};
7187672192
#endif
7187772193
7187872194
#ifndef SQLITE_OMIT_PRAGMA
@@ -71886,96 +72202,98 @@
7188672202
** If changing into or out of WAL mode the procedure is more complicated.
7188772203
**
7188872204
** Write a string containing the final journal-mode to register P2.
7188972205
*/
7189072206
case OP_JournalMode: { /* out2-prerelease */
72207
+#if 0 /* local variables moved into u.cj */
7189172208
Btree *pBt; /* Btree to change journal mode of */
7189272209
Pager *pPager; /* Pager associated with pBt */
7189372210
int eNew; /* New journal mode */
7189472211
int eOld; /* The old journal mode */
7189572212
#ifndef SQLITE_OMIT_WAL
7189672213
const char *zFilename; /* Name of database file for pPager */
7189772214
#endif
71898
-
71899
- eNew = pOp->p3;
71900
- assert( eNew==PAGER_JOURNALMODE_DELETE
71901
- || eNew==PAGER_JOURNALMODE_TRUNCATE
71902
- || eNew==PAGER_JOURNALMODE_PERSIST
71903
- || eNew==PAGER_JOURNALMODE_OFF
71904
- || eNew==PAGER_JOURNALMODE_MEMORY
71905
- || eNew==PAGER_JOURNALMODE_WAL
71906
- || eNew==PAGER_JOURNALMODE_QUERY
72215
+#endif /* local variables moved into u.cj */
72216
+
72217
+ u.cj.eNew = pOp->p3;
72218
+ assert( u.cj.eNew==PAGER_JOURNALMODE_DELETE
72219
+ || u.cj.eNew==PAGER_JOURNALMODE_TRUNCATE
72220
+ || u.cj.eNew==PAGER_JOURNALMODE_PERSIST
72221
+ || u.cj.eNew==PAGER_JOURNALMODE_OFF
72222
+ || u.cj.eNew==PAGER_JOURNALMODE_MEMORY
72223
+ || u.cj.eNew==PAGER_JOURNALMODE_WAL
72224
+ || u.cj.eNew==PAGER_JOURNALMODE_QUERY
7190772225
);
7190872226
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7190972227
assert( p->readOnly==0 );
7191072228
71911
- pBt = db->aDb[pOp->p1].pBt;
71912
- pPager = sqlite3BtreePager(pBt);
71913
- eOld = sqlite3PagerGetJournalMode(pPager);
71914
- if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld;
71915
- if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld;
72229
+ u.cj.pBt = db->aDb[pOp->p1].pBt;
72230
+ u.cj.pPager = sqlite3BtreePager(u.cj.pBt);
72231
+ u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager);
72232
+ if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld;
72233
+ if( !sqlite3PagerOkToChangeJournalMode(u.cj.pPager) ) u.cj.eNew = u.cj.eOld;
7191672234
7191772235
#ifndef SQLITE_OMIT_WAL
71918
- zFilename = sqlite3PagerFilename(pPager, 1);
72236
+ u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1);
7191972237
7192072238
/* Do not allow a transition to journal_mode=WAL for a database
71921
- ** in temporary storage or if the VFS does not support shared memory
72239
+ ** in temporary storage or if the VFS does not support shared memory
7192272240
*/
71923
- if( eNew==PAGER_JOURNALMODE_WAL
71924
- && (sqlite3Strlen30(zFilename)==0 /* Temp file */
71925
- || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */
72241
+ if( u.cj.eNew==PAGER_JOURNALMODE_WAL
72242
+ && (sqlite3Strlen30(u.cj.zFilename)==0 /* Temp file */
72243
+ || !sqlite3PagerWalSupported(u.cj.pPager)) /* No shared-memory support */
7192672244
){
71927
- eNew = eOld;
72245
+ u.cj.eNew = u.cj.eOld;
7192872246
}
7192972247
71930
- if( (eNew!=eOld)
71931
- && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL)
72248
+ if( (u.cj.eNew!=u.cj.eOld)
72249
+ && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
7193272250
){
7193372251
if( !db->autoCommit || db->nVdbeRead>1 ){
7193472252
rc = SQLITE_ERROR;
71935
- sqlite3SetString(&p->zErrMsg, db,
72253
+ sqlite3SetString(&p->zErrMsg, db,
7193672254
"cannot change %s wal mode from within a transaction",
71937
- (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
72255
+ (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
7193872256
);
7193972257
break;
7194072258
}else{
71941
-
71942
- if( eOld==PAGER_JOURNALMODE_WAL ){
72259
+
72260
+ if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){
7194372261
/* If leaving WAL mode, close the log file. If successful, the call
71944
- ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
71945
- ** file. An EXCLUSIVE lock may still be held on the database file
71946
- ** after a successful return.
72262
+ ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
72263
+ ** file. An EXCLUSIVE lock may still be held on the database file
72264
+ ** after a successful return.
7194772265
*/
71948
- rc = sqlite3PagerCloseWal(pPager);
72266
+ rc = sqlite3PagerCloseWal(u.cj.pPager);
7194972267
if( rc==SQLITE_OK ){
71950
- sqlite3PagerSetJournalMode(pPager, eNew);
72268
+ sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
7195172269
}
71952
- }else if( eOld==PAGER_JOURNALMODE_MEMORY ){
72270
+ }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){
7195372271
/* Cannot transition directly from MEMORY to WAL. Use mode OFF
7195472272
** as an intermediate */
71955
- sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF);
72273
+ sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF);
7195672274
}
71957
-
72275
+
7195872276
/* Open a transaction on the database file. Regardless of the journal
7195972277
** mode, this transaction always uses a rollback journal.
7196072278
*/
71961
- assert( sqlite3BtreeIsInTrans(pBt)==0 );
72279
+ assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 );
7196272280
if( rc==SQLITE_OK ){
71963
- rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
72281
+ rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
7196472282
}
7196572283
}
7196672284
}
7196772285
#endif /* ifndef SQLITE_OMIT_WAL */
7196872286
7196972287
if( rc ){
71970
- eNew = eOld;
72288
+ u.cj.eNew = u.cj.eOld;
7197172289
}
71972
- eNew = sqlite3PagerSetJournalMode(pPager, eNew);
72290
+ u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
7197372291
7197472292
pOut = &aMem[pOp->p2];
7197572293
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71976
- pOut->z = (char *)sqlite3JournalModename(eNew);
72294
+ pOut->z = (char *)sqlite3JournalModename(u.cj.eNew);
7197772295
pOut->n = sqlite3Strlen30(pOut->z);
7197872296
pOut->enc = SQLITE_UTF8;
7197972297
sqlite3VdbeChangeEncoding(pOut, encoding);
7198072298
break;
7198172299
};
@@ -72001,17 +72319,19 @@
7200172319
** Perform a single step of the incremental vacuum procedure on
7200272320
** the P1 database. If the vacuum has finished, jump to instruction
7200372321
** P2. Otherwise, fall through to the next instruction.
7200472322
*/
7200572323
case OP_IncrVacuum: { /* jump */
72324
+#if 0 /* local variables moved into u.ck */
7200672325
Btree *pBt;
72326
+#endif /* local variables moved into u.ck */
7200772327
7200872328
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7200972329
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7201072330
assert( p->readOnly==0 );
72011
- pBt = db->aDb[pOp->p1].pBt;
72012
- rc = sqlite3BtreeIncrVacuum(pBt);
72331
+ u.ck.pBt = db->aDb[pOp->p1].pBt;
72332
+ rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
7201372333
if( rc==SQLITE_DONE ){
7201472334
pc = pOp->p2 - 1;
7201572335
rc = SQLITE_OK;
7201672336
}
7201772337
break;
@@ -72078,14 +72398,16 @@
7207872398
** Also, whether or not P4 is set, check that this is not being called from
7207972399
** within a callback to a virtual table xSync() method. If it is, the error
7208072400
** code will be set to SQLITE_LOCKED.
7208172401
*/
7208272402
case OP_VBegin: {
72403
+#if 0 /* local variables moved into u.cl */
7208372404
VTable *pVTab;
72084
- pVTab = pOp->p4.pVtab;
72085
- rc = sqlite3VtabBegin(db, pVTab);
72086
- if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab);
72405
+#endif /* local variables moved into u.cl */
72406
+ u.cl.pVTab = pOp->p4.pVtab;
72407
+ rc = sqlite3VtabBegin(db, u.cl.pVTab);
72408
+ if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab);
7208772409
break;
7208872410
}
7208972411
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7209072412
7209172413
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72120,34 +72442,36 @@
7212072442
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7212172443
** P1 is a cursor number. This opcode opens a cursor to the virtual
7212272444
** table and stores that cursor in P1.
7212372445
*/
7212472446
case OP_VOpen: {
72447
+#if 0 /* local variables moved into u.cm */
7212572448
VdbeCursor *pCur;
7212672449
sqlite3_vtab_cursor *pVtabCursor;
7212772450
sqlite3_vtab *pVtab;
7212872451
sqlite3_module *pModule;
72452
+#endif /* local variables moved into u.cm */
7212972453
7213072454
assert( p->bIsReader );
72131
- pCur = 0;
72132
- pVtabCursor = 0;
72133
- pVtab = pOp->p4.pVtab->pVtab;
72134
- pModule = (sqlite3_module *)pVtab->pModule;
72135
- assert(pVtab && pModule);
72136
- rc = pModule->xOpen(pVtab, &pVtabCursor);
72137
- sqlite3VtabImportErrmsg(p, pVtab);
72455
+ u.cm.pCur = 0;
72456
+ u.cm.pVtabCursor = 0;
72457
+ u.cm.pVtab = pOp->p4.pVtab->pVtab;
72458
+ u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
72459
+ assert(u.cm.pVtab && u.cm.pModule);
72460
+ rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor);
72461
+ sqlite3VtabImportErrmsg(p, u.cm.pVtab);
7213872462
if( SQLITE_OK==rc ){
7213972463
/* Initialize sqlite3_vtab_cursor base class */
72140
- pVtabCursor->pVtab = pVtab;
72464
+ u.cm.pVtabCursor->pVtab = u.cm.pVtab;
7214172465
7214272466
/* Initialize vdbe cursor object */
72143
- pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72144
- if( pCur ){
72145
- pCur->pVtabCursor = pVtabCursor;
72467
+ u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72468
+ if( u.cm.pCur ){
72469
+ u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
7214672470
}else{
7214772471
db->mallocFailed = 1;
72148
- pModule->xClose(pVtabCursor);
72472
+ u.cm.pModule->xClose(u.cm.pVtabCursor);
7214972473
}
7215072474
}
7215172475
break;
7215272476
}
7215372477
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72171,10 +72495,11 @@
7217172495
** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
7217272496
**
7217372497
** A jump is made to P2 if the result set after filtering would be empty.
7217472498
*/
7217572499
case OP_VFilter: { /* jump */
72500
+#if 0 /* local variables moved into u.cn */
7217672501
int nArg;
7217772502
int iQuery;
7217872503
const sqlite3_module *pModule;
7217972504
Mem *pQuery;
7218072505
Mem *pArgc;
@@ -72182,48 +72507,49 @@
7218272507
sqlite3_vtab *pVtab;
7218372508
VdbeCursor *pCur;
7218472509
int res;
7218572510
int i;
7218672511
Mem **apArg;
72187
-
72188
- pQuery = &aMem[pOp->p3];
72189
- pArgc = &pQuery[1];
72190
- pCur = p->apCsr[pOp->p1];
72191
- assert( memIsValid(pQuery) );
72192
- REGISTER_TRACE(pOp->p3, pQuery);
72193
- assert( pCur->pVtabCursor );
72194
- pVtabCursor = pCur->pVtabCursor;
72195
- pVtab = pVtabCursor->pVtab;
72196
- pModule = pVtab->pModule;
72512
+#endif /* local variables moved into u.cn */
72513
+
72514
+ u.cn.pQuery = &aMem[pOp->p3];
72515
+ u.cn.pArgc = &u.cn.pQuery[1];
72516
+ u.cn.pCur = p->apCsr[pOp->p1];
72517
+ assert( memIsValid(u.cn.pQuery) );
72518
+ REGISTER_TRACE(pOp->p3, u.cn.pQuery);
72519
+ assert( u.cn.pCur->pVtabCursor );
72520
+ u.cn.pVtabCursor = u.cn.pCur->pVtabCursor;
72521
+ u.cn.pVtab = u.cn.pVtabCursor->pVtab;
72522
+ u.cn.pModule = u.cn.pVtab->pModule;
7219772523
7219872524
/* Grab the index number and argc parameters */
72199
- assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
72200
- nArg = (int)pArgc->u.i;
72201
- iQuery = (int)pQuery->u.i;
72525
+ assert( (u.cn.pQuery->flags&MEM_Int)!=0 && u.cn.pArgc->flags==MEM_Int );
72526
+ u.cn.nArg = (int)u.cn.pArgc->u.i;
72527
+ u.cn.iQuery = (int)u.cn.pQuery->u.i;
7220272528
7220372529
/* Invoke the xFilter method */
7220472530
{
72205
- res = 0;
72206
- apArg = p->apArg;
72207
- for(i = 0; i<nArg; i++){
72208
- apArg[i] = &pArgc[i+1];
72209
- sqlite3VdbeMemStoreType(apArg[i]);
72531
+ u.cn.res = 0;
72532
+ u.cn.apArg = p->apArg;
72533
+ for(u.cn.i = 0; u.cn.i<u.cn.nArg; u.cn.i++){
72534
+ u.cn.apArg[u.cn.i] = &u.cn.pArgc[u.cn.i+1];
72535
+ sqlite3VdbeMemStoreType(u.cn.apArg[u.cn.i]);
7221072536
}
7221172537
7221272538
p->inVtabMethod = 1;
72213
- rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
72539
+ rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
7221472540
p->inVtabMethod = 0;
72215
- sqlite3VtabImportErrmsg(p, pVtab);
72541
+ sqlite3VtabImportErrmsg(p, u.cn.pVtab);
7221672542
if( rc==SQLITE_OK ){
72217
- res = pModule->xEof(pVtabCursor);
72543
+ u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
7221872544
}
7221972545
72220
- if( res ){
72546
+ if( u.cn.res ){
7222172547
pc = pOp->p2 - 1;
7222272548
}
7222372549
}
72224
- pCur->nullRow = 0;
72550
+ u.cn.pCur->nullRow = 0;
7222572551
7222672552
break;
7222772553
}
7222872554
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7222972555
@@ -72234,53 +72560,55 @@
7223472560
** Store the value of the P2-th column of
7223572561
** the row of the virtual-table that the
7223672562
** P1 cursor is pointing to into register P3.
7223772563
*/
7223872564
case OP_VColumn: {
72565
+#if 0 /* local variables moved into u.co */
7223972566
sqlite3_vtab *pVtab;
7224072567
const sqlite3_module *pModule;
7224172568
Mem *pDest;
7224272569
sqlite3_context sContext;
72570
+#endif /* local variables moved into u.co */
7224372571
7224472572
VdbeCursor *pCur = p->apCsr[pOp->p1];
7224572573
assert( pCur->pVtabCursor );
7224672574
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72247
- pDest = &aMem[pOp->p3];
72248
- memAboutToChange(p, pDest);
72575
+ u.co.pDest = &aMem[pOp->p3];
72576
+ memAboutToChange(p, u.co.pDest);
7224972577
if( pCur->nullRow ){
72250
- sqlite3VdbeMemSetNull(pDest);
72578
+ sqlite3VdbeMemSetNull(u.co.pDest);
7225172579
break;
7225272580
}
72253
- pVtab = pCur->pVtabCursor->pVtab;
72254
- pModule = pVtab->pModule;
72255
- assert( pModule->xColumn );
72256
- memset(&sContext, 0, sizeof(sContext));
72581
+ u.co.pVtab = pCur->pVtabCursor->pVtab;
72582
+ u.co.pModule = u.co.pVtab->pModule;
72583
+ assert( u.co.pModule->xColumn );
72584
+ memset(&u.co.sContext, 0, sizeof(u.co.sContext));
7225772585
7225872586
/* The output cell may already have a buffer allocated. Move
72259
- ** the current contents to sContext.s so in case the user-function
72260
- ** can use the already allocated buffer instead of allocating a
72587
+ ** the current contents to u.co.sContext.s so in case the user-function
72588
+ ** can use the already allocated buffer instead of allocating a
7226172589
** new one.
7226272590
*/
72263
- sqlite3VdbeMemMove(&sContext.s, pDest);
72264
- MemSetTypeFlag(&sContext.s, MEM_Null);
72591
+ sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
72592
+ MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
7226572593
72266
- rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
72267
- sqlite3VtabImportErrmsg(p, pVtab);
72268
- if( sContext.isError ){
72269
- rc = sContext.isError;
72594
+ rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2);
72595
+ sqlite3VtabImportErrmsg(p, u.co.pVtab);
72596
+ if( u.co.sContext.isError ){
72597
+ rc = u.co.sContext.isError;
7227072598
}
7227172599
7227272600
/* Copy the result of the function to the P3 register. We
7227372601
** do this regardless of whether or not an error occurred to ensure any
72274
- ** dynamic allocation in sContext.s (a Mem struct) is released.
72602
+ ** dynamic allocation in u.co.sContext.s (a Mem struct) is released.
7227572603
*/
72276
- sqlite3VdbeChangeEncoding(&sContext.s, encoding);
72277
- sqlite3VdbeMemMove(pDest, &sContext.s);
72278
- REGISTER_TRACE(pOp->p3, pDest);
72279
- UPDATE_MAX_BLOBSIZE(pDest);
72604
+ sqlite3VdbeChangeEncoding(&u.co.sContext.s, encoding);
72605
+ sqlite3VdbeMemMove(u.co.pDest, &u.co.sContext.s);
72606
+ REGISTER_TRACE(pOp->p3, u.co.pDest);
72607
+ UPDATE_MAX_BLOBSIZE(u.co.pDest);
7228072608
72281
- if( sqlite3VdbeMemTooBig(pDest) ){
72609
+ if( sqlite3VdbeMemTooBig(u.co.pDest) ){
7228272610
goto too_big;
7228372611
}
7228472612
break;
7228572613
}
7228672614
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72291,40 +72619,42 @@
7229172619
** Advance virtual table P1 to the next row in its result set and
7229272620
** jump to instruction P2. Or, if the virtual table has reached
7229372621
** the end of its result set, then fall through to the next instruction.
7229472622
*/
7229572623
case OP_VNext: { /* jump */
72624
+#if 0 /* local variables moved into u.cp */
7229672625
sqlite3_vtab *pVtab;
7229772626
const sqlite3_module *pModule;
7229872627
int res;
7229972628
VdbeCursor *pCur;
72629
+#endif /* local variables moved into u.cp */
7230072630
72301
- res = 0;
72302
- pCur = p->apCsr[pOp->p1];
72303
- assert( pCur->pVtabCursor );
72304
- if( pCur->nullRow ){
72631
+ u.cp.res = 0;
72632
+ u.cp.pCur = p->apCsr[pOp->p1];
72633
+ assert( u.cp.pCur->pVtabCursor );
72634
+ if( u.cp.pCur->nullRow ){
7230572635
break;
7230672636
}
72307
- pVtab = pCur->pVtabCursor->pVtab;
72308
- pModule = pVtab->pModule;
72309
- assert( pModule->xNext );
72637
+ u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab;
72638
+ u.cp.pModule = u.cp.pVtab->pModule;
72639
+ assert( u.cp.pModule->xNext );
7231072640
7231172641
/* Invoke the xNext() method of the module. There is no way for the
7231272642
** underlying implementation to return an error if one occurs during
72313
- ** xNext(). Instead, if an error occurs, true is returned (indicating that
72643
+ ** xNext(). Instead, if an error occurs, true is returned (indicating that
7231472644
** data is available) and the error code returned when xColumn or
7231572645
** some other method is next invoked on the save virtual table cursor.
7231672646
*/
7231772647
p->inVtabMethod = 1;
72318
- rc = pModule->xNext(pCur->pVtabCursor);
72648
+ rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
7231972649
p->inVtabMethod = 0;
72320
- sqlite3VtabImportErrmsg(p, pVtab);
72650
+ sqlite3VtabImportErrmsg(p, u.cp.pVtab);
7232172651
if( rc==SQLITE_OK ){
72322
- res = pModule->xEof(pCur->pVtabCursor);
72652
+ u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
7232372653
}
7232472654
72325
- if( !res ){
72655
+ if( !u.cp.res ){
7232672656
/* If there is data, jump to P2 */
7232772657
pc = pOp->p2 - 1;
7232872658
}
7232972659
goto check_for_interrupt;
7233072660
}
@@ -72336,27 +72666,29 @@
7233672666
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7233772667
** This opcode invokes the corresponding xRename method. The value
7233872668
** in register P1 is passed as the zName argument to the xRename method.
7233972669
*/
7234072670
case OP_VRename: {
72671
+#if 0 /* local variables moved into u.cq */
7234172672
sqlite3_vtab *pVtab;
7234272673
Mem *pName;
72674
+#endif /* local variables moved into u.cq */
7234372675
72344
- pVtab = pOp->p4.pVtab->pVtab;
72345
- pName = &aMem[pOp->p1];
72346
- assert( pVtab->pModule->xRename );
72347
- assert( memIsValid(pName) );
72676
+ u.cq.pVtab = pOp->p4.pVtab->pVtab;
72677
+ u.cq.pName = &aMem[pOp->p1];
72678
+ assert( u.cq.pVtab->pModule->xRename );
72679
+ assert( memIsValid(u.cq.pName) );
7234872680
assert( p->readOnly==0 );
72349
- REGISTER_TRACE(pOp->p1, pName);
72350
- assert( pName->flags & MEM_Str );
72351
- testcase( pName->enc==SQLITE_UTF8 );
72352
- testcase( pName->enc==SQLITE_UTF16BE );
72353
- testcase( pName->enc==SQLITE_UTF16LE );
72354
- rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8);
72681
+ REGISTER_TRACE(pOp->p1, u.cq.pName);
72682
+ assert( u.cq.pName->flags & MEM_Str );
72683
+ testcase( u.cq.pName->enc==SQLITE_UTF8 );
72684
+ testcase( u.cq.pName->enc==SQLITE_UTF16BE );
72685
+ testcase( u.cq.pName->enc==SQLITE_UTF16LE );
72686
+ rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8);
7235572687
if( rc==SQLITE_OK ){
72356
- rc = pVtab->pModule->xRename(pVtab, pName->z);
72357
- sqlite3VtabImportErrmsg(p, pVtab);
72688
+ rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
72689
+ sqlite3VtabImportErrmsg(p, u.cq.pVtab);
7235872690
p->expired = 0;
7235972691
}
7236072692
break;
7236172693
}
7236272694
#endif
@@ -72385,44 +72717,46 @@
7238572717
** P1 is a boolean flag. If it is set to true and the xUpdate call
7238672718
** is successful, then the value returned by sqlite3_last_insert_rowid()
7238772719
** is set to the value of the rowid for the row just inserted.
7238872720
*/
7238972721
case OP_VUpdate: {
72722
+#if 0 /* local variables moved into u.cr */
7239072723
sqlite3_vtab *pVtab;
7239172724
sqlite3_module *pModule;
7239272725
int nArg;
7239372726
int i;
7239472727
sqlite_int64 rowid;
7239572728
Mem **apArg;
7239672729
Mem *pX;
72730
+#endif /* local variables moved into u.cr */
7239772731
72398
- assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72732
+ assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
7239972733
|| pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
7240072734
);
7240172735
assert( p->readOnly==0 );
72402
- pVtab = pOp->p4.pVtab->pVtab;
72403
- pModule = (sqlite3_module *)pVtab->pModule;
72404
- nArg = pOp->p2;
72736
+ u.cr.pVtab = pOp->p4.pVtab->pVtab;
72737
+ u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule;
72738
+ u.cr.nArg = pOp->p2;
7240572739
assert( pOp->p4type==P4_VTAB );
72406
- if( ALWAYS(pModule->xUpdate) ){
72740
+ if( ALWAYS(u.cr.pModule->xUpdate) ){
7240772741
u8 vtabOnConflict = db->vtabOnConflict;
72408
- apArg = p->apArg;
72409
- pX = &aMem[pOp->p3];
72410
- for(i=0; i<nArg; i++){
72411
- assert( memIsValid(pX) );
72412
- memAboutToChange(p, pX);
72413
- sqlite3VdbeMemStoreType(pX);
72414
- apArg[i] = pX;
72415
- pX++;
72742
+ u.cr.apArg = p->apArg;
72743
+ u.cr.pX = &aMem[pOp->p3];
72744
+ for(u.cr.i=0; u.cr.i<u.cr.nArg; u.cr.i++){
72745
+ assert( memIsValid(u.cr.pX) );
72746
+ memAboutToChange(p, u.cr.pX);
72747
+ sqlite3VdbeMemStoreType(u.cr.pX);
72748
+ u.cr.apArg[u.cr.i] = u.cr.pX;
72749
+ u.cr.pX++;
7241672750
}
7241772751
db->vtabOnConflict = pOp->p5;
72418
- rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
72752
+ rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
7241972753
db->vtabOnConflict = vtabOnConflict;
72420
- sqlite3VtabImportErrmsg(p, pVtab);
72754
+ sqlite3VtabImportErrmsg(p, u.cr.pVtab);
7242172755
if( rc==SQLITE_OK && pOp->p1 ){
72422
- assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
72423
- db->lastRowid = lastRowid = rowid;
72756
+ assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) );
72757
+ db->lastRowid = lastRowid = u.cr.rowid;
7242472758
}
7242572759
if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
7242672760
if( pOp->p5==OE_Ignore ){
7242772761
rc = SQLITE_OK;
7242872762
}else{
@@ -72478,36 +72812,38 @@
7247872812
**
7247972813
** If tracing is enabled (by the sqlite3_trace()) interface, then
7248072814
** the UTF-8 string contained in P4 is emitted on the trace callback.
7248172815
*/
7248272816
case OP_Trace: {
72817
+#if 0 /* local variables moved into u.cs */
7248372818
char *zTrace;
7248472819
char *z;
72820
+#endif /* local variables moved into u.cs */
7248572821
7248672822
if( db->xTrace
7248772823
&& !p->doingRerun
72488
- && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72824
+ && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7248972825
){
72490
- z = sqlite3VdbeExpandSql(p, zTrace);
72491
- db->xTrace(db->pTraceArg, z);
72492
- sqlite3DbFree(db, z);
72826
+ u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
72827
+ db->xTrace(db->pTraceArg, u.cs.z);
72828
+ sqlite3DbFree(db, u.cs.z);
7249372829
}
7249472830
#ifdef SQLITE_USE_FCNTL_TRACE
72495
- zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72496
- if( zTrace ){
72831
+ u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72832
+ if( u.cs.zTrace ){
7249772833
int i;
7249872834
for(i=0; i<db->nDb; i++){
7249972835
if( ((1<<i) & p->btreeMask)==0 ) continue;
72500
- sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
72836
+ sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace);
7250172837
}
7250272838
}
7250372839
#endif /* SQLITE_USE_FCNTL_TRACE */
7250472840
#ifdef SQLITE_DEBUG
7250572841
if( (db->flags & SQLITE_SqlTrace)!=0
72506
- && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72842
+ && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7250772843
){
72508
- sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72844
+ sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
7250972845
}
7251072846
#endif /* SQLITE_DEBUG */
7251172847
break;
7251272848
}
7251372849
#endif
@@ -72632,11 +72968,10 @@
7263272968
rc = SQLITE_INTERRUPT;
7263372969
p->rc = rc;
7263472970
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
7263572971
goto vdbe_error_halt;
7263672972
}
72637
-
7263872973
7263972974
/************** End of vdbe.c ************************************************/
7264072975
/************** Begin file vdbeblob.c ****************************************/
7264172976
/*
7264272977
** 2007 May 1
@@ -72891,11 +73226,11 @@
7289173226
sqlite3BtreeLeaveAll(db);
7289273227
goto blob_open_out;
7289373228
}
7289473229
}
7289573230
72896
- pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse);
73231
+ pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db);
7289773232
assert( pBlob->pStmt || db->mallocFailed );
7289873233
if( pBlob->pStmt ){
7289973234
Vdbe *v = (Vdbe *)pBlob->pStmt;
7290073235
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7290173236
@@ -76798,29 +77133,20 @@
7679877133
}
7679977134
return p;
7680077135
}
7680177136
7680277137
/*
76803
-** If the expression is always either TRUE or FALSE (respectively),
76804
-** then return 1. If one cannot determine the truth value of the
76805
-** expression at compile-time return 0.
76806
-**
76807
-** This is an optimization. If is OK to return 0 here even if
76808
-** the expression really is always false or false (a false negative).
76809
-** But it is a bug to return 1 if the expression might have different
76810
-** boolean values in different circumstances (a false positive.)
77138
+** Return 1 if an expression must be FALSE in all cases and 0 if the
77139
+** expression might be true. This is an optimization. If is OK to
77140
+** return 0 here even if the expression really is always false (a
77141
+** false negative). But it is a bug to return 1 if the expression
77142
+** might be true in some rare circumstances (a false positive.)
7681177143
**
7681277144
** Note that if the expression is part of conditional for a
7681377145
** LEFT JOIN, then we cannot determine at compile-time whether or not
7681477146
** is it true or false, so always return 0.
7681577147
*/
76816
-static int exprAlwaysTrue(Expr *p){
76817
- int v = 0;
76818
- if( ExprHasProperty(p, EP_FromJoin) ) return 0;
76819
- if( !sqlite3ExprIsInteger(p, &v) ) return 0;
76820
- return v!=0;
76821
-}
7682277148
static int exprAlwaysFalse(Expr *p){
7682377149
int v = 0;
7682477150
if( ExprHasProperty(p, EP_FromJoin) ) return 0;
7682577151
if( !sqlite3ExprIsInteger(p, &v) ) return 0;
7682677152
return v==0;
@@ -78454,15 +78780,10 @@
7845478780
** added to the column cache after this call are removed when the
7845578781
** corresponding pop occurs.
7845678782
*/
7845778783
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse *pParse){
7845878784
pParse->iCacheLevel++;
78459
-#ifdef SQLITE_DEBUG
78460
- if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
78461
- printf("PUSH to %d\n", pParse->iCacheLevel);
78462
- }
78463
-#endif
7846478785
}
7846578786
7846678787
/*
7846778788
** Remove from the column cache any entries that were added since the
7846878789
** the previous N Push operations. In other words, restore the cache
@@ -78472,15 +78793,10 @@
7847278793
int i;
7847378794
struct yColCache *p;
7847478795
assert( N>0 );
7847578796
assert( pParse->iCacheLevel>=N );
7847678797
pParse->iCacheLevel -= N;
78477
-#ifdef SQLITE_DEBUG
78478
- if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
78479
- printf("POP to %d\n", pParse->iCacheLevel);
78480
- }
78481
-#endif
7848278798
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
7848378799
if( p->iReg && p->iLevel>pParse->iCacheLevel ){
7848478800
cacheEntryClear(pParse, p);
7848578801
p->iReg = 0;
7848678802
}
@@ -78571,15 +78887,10 @@
7857178887
*/
7857278888
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){
7857378889
int i;
7857478890
struct yColCache *p;
7857578891
78576
-#if SQLITE_DEBUG
78577
- if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
78578
- printf("CLEAR\n");
78579
- }
78580
-#endif
7858178892
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
7858278893
if( p->iReg ){
7858378894
cacheEntryClear(pParse, p);
7858478895
p->iReg = 0;
7858578896
}
@@ -79663,11 +79974,11 @@
7966379974
sqlite3ExplainPush(pOut);
7966479975
for(i=0; i<pList->nExpr; i++){
7966579976
sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
7966679977
sqlite3ExplainPush(pOut);
7966779978
sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
79668
- sqlite3ExplainPop(pOut, 1);
79979
+ sqlite3ExplainPop(pOut);
7966979980
if( pList->a[i].zName ){
7967079981
sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
7967179982
}
7967279983
if( pList->a[i].bSpanIsTab ){
7967379984
sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
@@ -79712,21 +80023,11 @@
7971280023
if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
7971380024
sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
7971480025
}else{
7971580026
int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
7971680027
if( inReg!=target+i ){
79717
- VdbeOp *pOp;
79718
- Vdbe *v = pParse->pVdbe;
79719
- if( copyOp==OP_Copy
79720
- && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
79721
- && pOp->p1+pOp->p3+1==inReg
79722
- && pOp->p2+pOp->p3+1==target+i
79723
- ){
79724
- pOp->p3++;
79725
- }else{
79726
- sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
79727
- }
80028
+ sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i);
7972880029
}
7972980030
}
7973080031
}
7973180032
return n;
7973280033
}
@@ -79813,23 +80114,21 @@
7981380114
op = pExpr->op;
7981480115
switch( op ){
7981580116
case TK_AND: {
7981680117
int d2 = sqlite3VdbeMakeLabel(v);
7981780118
testcase( jumpIfNull==0 );
79818
- sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
7981980119
sqlite3ExprCachePush(pParse);
80120
+ sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
7982080121
sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
7982180122
sqlite3VdbeResolveLabel(v, d2);
7982280123
sqlite3ExprCachePop(pParse, 1);
7982380124
break;
7982480125
}
7982580126
case TK_OR: {
7982680127
testcase( jumpIfNull==0 );
7982780128
sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
79828
- sqlite3ExprCachePush(pParse);
7982980129
sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
79830
- sqlite3ExprCachePop(pParse, 1);
7983180130
break;
7983280131
}
7983380132
case TK_NOT: {
7983480133
testcase( jumpIfNull==0 );
7983580134
sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
@@ -79900,20 +80199,14 @@
7990080199
sqlite3VdbeResolveLabel(v, destIfFalse);
7990180200
break;
7990280201
}
7990380202
#endif
7990480203
default: {
79905
- if( exprAlwaysTrue(pExpr) ){
79906
- sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
79907
- }else if( exprAlwaysFalse(pExpr) ){
79908
- /* No-op */
79909
- }else{
79910
- r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
79911
- sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
79912
- testcase( regFree1==0 );
79913
- testcase( jumpIfNull==0 );
79914
- }
80204
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80205
+ sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
80206
+ testcase( regFree1==0 );
80207
+ testcase( jumpIfNull==0 );
7991580208
break;
7991680209
}
7991780210
}
7991880211
sqlite3ReleaseTempReg(pParse, regFree1);
7991980212
sqlite3ReleaseTempReg(pParse, regFree2);
@@ -79972,20 +80265,18 @@
7997280265
7997380266
switch( pExpr->op ){
7997480267
case TK_AND: {
7997580268
testcase( jumpIfNull==0 );
7997680269
sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
79977
- sqlite3ExprCachePush(pParse);
7997880270
sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
79979
- sqlite3ExprCachePop(pParse, 1);
7998080271
break;
7998180272
}
7998280273
case TK_OR: {
7998380274
int d2 = sqlite3VdbeMakeLabel(v);
7998480275
testcase( jumpIfNull==0 );
79985
- sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
7998680276
sqlite3ExprCachePush(pParse);
80277
+ sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
7998780278
sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
7998880279
sqlite3VdbeResolveLabel(v, d2);
7998980280
sqlite3ExprCachePop(pParse, 1);
7999080281
break;
7999180282
}
@@ -80053,20 +80344,14 @@
8005380344
}
8005480345
break;
8005580346
}
8005680347
#endif
8005780348
default: {
80058
- if( exprAlwaysFalse(pExpr) ){
80059
- sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
80060
- }else if( exprAlwaysTrue(pExpr) ){
80061
- /* no-op */
80062
- }else{
80063
- r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80064
- sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80065
- testcase( regFree1==0 );
80066
- testcase( jumpIfNull==0 );
80067
- }
80349
+ r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80350
+ sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80351
+ testcase( regFree1==0 );
80352
+ testcase( jumpIfNull==0 );
8006880353
break;
8006980354
}
8007080355
}
8007180356
sqlite3ReleaseTempReg(pParse, regFree1);
8007280357
sqlite3ReleaseTempReg(pParse, regFree2);
@@ -83162,10 +83447,14 @@
8316283447
{
8316383448
int rc = SQLITE_OK;
8316483449
if( pExpr ){
8316583450
if( pExpr->op!=TK_ID ){
8316683451
rc = sqlite3ResolveExprNames(pName, pExpr);
83452
+ if( rc==SQLITE_OK && !sqlite3ExprIsConstant(pExpr) ){
83453
+ sqlite3ErrorMsg(pName->pParse, "invalid name: \"%s\"", pExpr->u.zToken);
83454
+ return SQLITE_ERROR;
83455
+ }
8316783456
}else{
8316883457
pExpr->op = TK_STRING;
8316983458
}
8317083459
}
8317183460
return rc;
@@ -87940,13 +88229,13 @@
8794088229
sqlite3StrAccumInit(&errMsg, 0, 0, 200);
8794188230
errMsg.db = pParse->db;
8794288231
for(j=0; j<pIdx->nKeyCol; j++){
8794388232
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
8794488233
if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
87945
- sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
88234
+ sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
8794688235
sqlite3StrAccumAppend(&errMsg, ".", 1);
87947
- sqlite3StrAccumAppendAll(&errMsg, zCol);
88236
+ sqlite3StrAccumAppend(&errMsg, zCol, -1);
8794888237
}
8794988238
zErr = sqlite3StrAccumFinish(&errMsg);
8795088239
sqlite3HaltConstraint(pParse,
8795188240
(pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
8795288241
onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88134,13 +88423,12 @@
8813488423
}
8813588424
if( pKey ){
8813688425
assert( sqlite3KeyInfoIsWriteable(pKey) );
8813788426
for(i=0; i<nCol; i++){
8813888427
char *zColl = pIdx->azColl[i];
88139
- assert( zColl!=0 );
88140
- pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
88141
- sqlite3LocateCollSeq(pParse, zColl);
88428
+ if( NEVER(zColl==0) ) zColl = "BINARY";
88429
+ pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
8814288430
pKey->aSortOrder[i] = pIdx->aSortOrder[i];
8814388431
}
8814488432
if( pParse->nErr ){
8814588433
sqlite3KeyInfoUnref(pKey);
8814688434
}else{
@@ -88509,10 +88797,11 @@
8850988797
int bestScore = 0; /* Score of best match */
8851088798
int h; /* Hash value */
8851188799
8851288800
assert( nArg>=(-2) );
8851388801
assert( nArg>=(-1) || createFlag==0 );
88802
+ assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
8851488803
h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
8851588804
8851688805
/* First search for a match amongst the application-defined functions.
8851788806
*/
8851888807
p = functionSearch(&db->aFunc, h, zName, nName);
@@ -89399,10 +89688,11 @@
8939989688
Vdbe *v = pParse->pVdbe;
8940089689
int j;
8940189690
Table *pTab = pIdx->pTable;
8940289691
int regBase;
8940389692
int nCol;
89693
+ Index *pPk;
8940489694
8940589695
if( piPartIdxLabel ){
8940689696
if( pIdx->pPartIdxWhere ){
8940789697
*piPartIdxLabel = sqlite3VdbeMakeLabel(v);
8940889698
pParse->iPartIdxTab = iDataCur;
@@ -89412,25 +89702,32 @@
8941289702
*piPartIdxLabel = 0;
8941389703
}
8941489704
}
8941589705
nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
8941689706
regBase = sqlite3GetTempRange(pParse, nCol);
89707
+ pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
8941789708
for(j=0; j<nCol; j++){
89418
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
89419
- regBase+j);
89420
- /* If the column affinity is REAL but the number is an integer, then it
89421
- ** might be stored in the table as an integer (using a compact
89422
- ** representation) then converted to REAL by an OP_RealAffinity opcode.
89423
- ** But we are getting ready to store this value back into an index, where
89424
- ** it should be converted by to INTEGER again. So omit the OP_RealAffinity
89425
- ** opcode if it is present */
89426
- if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){
89427
- sqlite3VdbeDeleteLastOpcode(v);
89709
+ i16 idx = pIdx->aiColumn[j];
89710
+ if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx);
89711
+ if( idx<0 || idx==pTab->iPKey ){
89712
+ sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j);
89713
+ }else{
89714
+ sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j);
89715
+ sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1);
8942889716
}
8942989717
}
8943089718
if( regOut ){
89719
+ const char *zAff;
89720
+ if( pTab->pSelect
89721
+ || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
89722
+ ){
89723
+ zAff = 0;
89724
+ }else{
89725
+ zAff = sqlite3IndexAffinityStr(v, pIdx);
89726
+ }
8943189727
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
89728
+ sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
8943289729
}
8943389730
sqlite3ReleaseTempRange(pParse, regBase, nCol);
8943489731
return regBase;
8943589732
}
8943689733
@@ -89652,36 +89949,10 @@
8965289949
}
8965389950
if( nNeedle>nHaystack ) N = 0;
8965489951
sqlite3_result_int(context, N);
8965589952
}
8965689953
89657
-/*
89658
-** Implementation of the printf() function.
89659
-*/
89660
-static void printfFunc(
89661
- sqlite3_context *context,
89662
- int argc,
89663
- sqlite3_value **argv
89664
-){
89665
- PrintfArguments x;
89666
- StrAccum str;
89667
- const char *zFormat;
89668
- int n;
89669
-
89670
- if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
89671
- x.nArg = argc-1;
89672
- x.nUsed = 0;
89673
- x.apArg = argv+1;
89674
- sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
89675
- str.db = sqlite3_context_db_handle(context);
89676
- sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
89677
- n = str.nChar;
89678
- sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
89679
- SQLITE_DYNAMIC);
89680
- }
89681
-}
89682
-
8968389954
/*
8968489955
** Implementation of the substr() function.
8968589956
**
8968689957
** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
8968789958
** p1 is 1-indexed. So substr(x,1,1) returns the first character
@@ -90971,15 +91242,15 @@
9097191242
nSep = sqlite3_value_bytes(argv[1]);
9097291243
}else{
9097391244
zSep = ",";
9097491245
nSep = 1;
9097591246
}
90976
- if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
91247
+ sqlite3StrAccumAppend(pAccum, zSep, nSep);
9097791248
}
9097891249
zVal = (char*)sqlite3_value_text(argv[0]);
9097991250
nVal = sqlite3_value_bytes(argv[0]);
90980
- if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
91251
+ sqlite3StrAccumAppend(pAccum, zVal, nVal);
9098191252
}
9098291253
}
9098391254
static void groupConcatFinalize(sqlite3_context *context){
9098491255
StrAccum *pAccum;
9098591256
pAccum = sqlite3_aggregate_context(context, 0);
@@ -91108,11 +91379,10 @@
9110891379
FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
9110991380
FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
9111091381
FUNCTION(instr, 2, 0, 0, instrFunc ),
9111191382
FUNCTION(substr, 2, 0, 0, substrFunc ),
9111291383
FUNCTION(substr, 3, 0, 0, substrFunc ),
91113
- FUNCTION(printf, -1, 0, 0, printfFunc ),
9111491384
FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
9111591385
FUNCTION(char, -1, 0, 0, charFunc ),
9111691386
FUNCTION(abs, 1, 0, 0, absFunc ),
9111791387
#ifndef SQLITE_OMIT_FLOATING_POINT
9111891388
FUNCTION(round, 1, 0, 0, roundFunc ),
@@ -93779,11 +94049,10 @@
9377994049
int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
9378094050
int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
9378194051
int ipkTop = 0; /* Top of the rowid change constraint check */
9378294052
int ipkBottom = 0; /* Bottom of the rowid change constraint check */
9378394053
u8 isUpdate; /* True if this is an UPDATE operation */
93784
- int regRowid = -1; /* Register holding ROWID value */
9378594054
9378694055
isUpdate = regOldData!=0;
9378794056
db = pParse->db;
9378894057
v = sqlite3GetVdbe(pParse);
9378994058
assert( v!=0 );
@@ -94010,13 +94279,11 @@
9401094279
regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
9401194280
for(i=0; i<pIdx->nColumn; i++){
9401294281
int iField = pIdx->aiColumn[i];
9401394282
int x;
9401494283
if( iField<0 || iField==pTab->iPKey ){
94015
- if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
9401694284
x = regNewData;
94017
- regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
9401894285
}else{
9401994286
x = iField + regNewData + 1;
9402094287
}
9402194288
sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
9402294289
VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
@@ -94052,53 +94319,51 @@
9405294319
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
9405394320
regIdx, pIdx->nKeyCol);
9405494321
9405594322
/* Generate code to handle collisions */
9405694323
regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94057
- if( isUpdate || onError==OE_Replace ){
94058
- if( HasRowid(pTab) ){
94059
- sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94060
- /* Conflict only if the rowid of the existing index entry
94061
- ** is different from old-rowid */
94062
- if( isUpdate ){
94063
- sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94064
- }
94065
- }else{
94066
- int x;
94067
- /* Extract the PRIMARY KEY from the end of the index entry and
94068
- ** store it in registers regR..regR+nPk-1 */
94069
- if( pIdx!=pPk ){
94070
- for(i=0; i<pPk->nKeyCol; i++){
94071
- x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
94072
- sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
94073
- VdbeComment((v, "%s.%s", pTab->zName,
94074
- pTab->aCol[pPk->aiColumn[i]].zName));
94075
- }
94076
- }
94077
- if( isUpdate ){
94078
- /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
94079
- ** table, only conflict if the new PRIMARY KEY values are actually
94080
- ** different from the old.
94081
- **
94082
- ** For a UNIQUE index, only conflict if the PRIMARY KEY values
94083
- ** of the matched index row are different from the original PRIMARY
94084
- ** KEY values of this row before the update. */
94085
- int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
94086
- int op = OP_Ne;
94087
- int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
94088
-
94089
- for(i=0; i<pPk->nKeyCol; i++){
94090
- char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
94091
- x = pPk->aiColumn[i];
94092
- if( i==(pPk->nKeyCol-1) ){
94093
- addrJump = addrUniqueOk;
94094
- op = OP_Eq;
94095
- }
94096
- sqlite3VdbeAddOp4(v, op,
94097
- regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94098
- );
94099
- }
94324
+ if( HasRowid(pTab) ){
94325
+ sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94326
+ /* Conflict only if the rowid of the existing index entry
94327
+ ** is different from old-rowid */
94328
+ if( isUpdate ){
94329
+ sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94330
+ }
94331
+ }else{
94332
+ int x;
94333
+ /* Extract the PRIMARY KEY from the end of the index entry and
94334
+ ** store it in registers regR..regR+nPk-1 */
94335
+ if( (isUpdate || onError==OE_Replace) && pIdx!=pPk ){
94336
+ for(i=0; i<pPk->nKeyCol; i++){
94337
+ x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
94338
+ sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
94339
+ VdbeComment((v, "%s.%s", pTab->zName,
94340
+ pTab->aCol[pPk->aiColumn[i]].zName));
94341
+ }
94342
+ }
94343
+ if( isUpdate ){
94344
+ /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
94345
+ ** table, only conflict if the new PRIMARY KEY values are actually
94346
+ ** different from the old.
94347
+ **
94348
+ ** For a UNIQUE index, only conflict if the PRIMARY KEY values
94349
+ ** of the matched index row are different from the original PRIMARY
94350
+ ** KEY values of this row before the update. */
94351
+ int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
94352
+ int op = OP_Ne;
94353
+ int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
94354
+
94355
+ for(i=0; i<pPk->nKeyCol; i++){
94356
+ char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
94357
+ x = pPk->aiColumn[i];
94358
+ if( i==(pPk->nKeyCol-1) ){
94359
+ addrJump = addrUniqueOk;
94360
+ op = OP_Eq;
94361
+ }
94362
+ sqlite3VdbeAddOp4(v, op,
94363
+ regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94364
+ );
9410094365
}
9410194366
}
9410294367
}
9410394368
9410494369
/* Generate code that executes if the new index entry is not unique */
@@ -98841,15 +99106,11 @@
9884199106
9884299107
/*
9884399108
** Free all memory allocations in the pParse object
9884499109
*/
9884599110
SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
98846
- if( pParse ){
98847
- sqlite3 *db = pParse->db;
98848
- sqlite3DbFree(db, pParse->aLabel);
98849
- sqlite3ExprListDelete(db, pParse->pConstExpr);
98850
- }
99111
+ if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
9885199112
}
9885299113
9885399114
/*
9885499115
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
9885599116
*/
@@ -99798,10 +100059,11 @@
99798100059
}
99799100060
}else if( eDest!=SRT_Exists ){
99800100061
/* If the destination is an EXISTS(...) expression, the actual
99801100062
** values returned by the SELECT are not required.
99802100063
*/
100064
+ sqlite3ExprCacheClear(pParse);
99803100065
sqlite3ExprCodeExprList(pParse, pEList, regResult,
99804100066
(eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
99805100067
}
99806100068
nColumn = nResultCol;
99807100069
@@ -100764,11 +101026,11 @@
100764101026
** If an error occurs, return NULL and leave a message in pParse.
100765101027
*/
100766101028
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
100767101029
Vdbe *v = pParse->pVdbe;
100768101030
if( v==0 ){
100769
- v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
101031
+ v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db);
100770101032
#ifndef SQLITE_OMIT_TRACE
100771101033
if( v ){
100772101034
sqlite3VdbeAddOp0(v, OP_Trace);
100773101035
}
100774101036
#endif
@@ -103022,27 +103284,18 @@
103022103284
*/
103023103285
static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
103024103286
Vdbe *v = pParse->pVdbe;
103025103287
int i;
103026103288
struct AggInfo_func *pFunc;
103027
- int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
103028
- if( nReg==0 ) return;
103029
-#ifdef SQLITE_DEBUG
103030
- /* Verify that all AggInfo registers are within the range specified by
103031
- ** AggInfo.mnReg..AggInfo.mxReg */
103032
- assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
103289
+ if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){
103290
+ return;
103291
+ }
103033103292
for(i=0; i<pAggInfo->nColumn; i++){
103034
- assert( pAggInfo->aCol[i].iMem>=pAggInfo->mnReg
103035
- && pAggInfo->aCol[i].iMem<=pAggInfo->mxReg );
103036
- }
103037
- for(i=0; i<pAggInfo->nFunc; i++){
103038
- assert( pAggInfo->aFunc[i].iMem>=pAggInfo->mnReg
103039
- && pAggInfo->aFunc[i].iMem<=pAggInfo->mxReg );
103040
- }
103041
-#endif
103042
- sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
103293
+ sqlite3VdbeAddOp2(v, OP_Null, 0, pAggInfo->aCol[i].iMem);
103294
+ }
103043103295
for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
103296
+ sqlite3VdbeAddOp2(v, OP_Null, 0, pFunc->iMem);
103044103297
if( pFunc->iDistinct>=0 ){
103045103298
Expr *pE = pFunc->pExpr;
103046103299
assert( !ExprHasProperty(pE, EP_xIsSelect) );
103047103300
if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
103048103301
sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
@@ -103084,10 +103337,11 @@
103084103337
int addrHitTest = 0;
103085103338
struct AggInfo_func *pF;
103086103339
struct AggInfo_col *pC;
103087103340
103088103341
pAggInfo->directMode = 1;
103342
+ sqlite3ExprCacheClear(pParse);
103089103343
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
103090103344
int nArg;
103091103345
int addrNext = 0;
103092103346
int regAgg;
103093103347
ExprList *pList = pF->pExpr->x.pList;
@@ -103616,11 +103870,10 @@
103616103870
*/
103617103871
memset(&sNC, 0, sizeof(sNC));
103618103872
sNC.pParse = pParse;
103619103873
sNC.pSrcList = pTabList;
103620103874
sNC.pAggInfo = &sAggInfo;
103621
- sAggInfo.mnReg = pParse->nMem+1;
103622103875
sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0;
103623103876
sAggInfo.pGroupBy = pGroupBy;
103624103877
sqlite3ExprAnalyzeAggList(&sNC, pEList);
103625103878
sqlite3ExprAnalyzeAggList(&sNC, pOrderBy);
103626103879
if( pHaving ){
@@ -103631,11 +103884,10 @@
103631103884
assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
103632103885
sNC.ncFlags |= NC_InAggFunc;
103633103886
sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
103634103887
sNC.ncFlags &= ~NC_InAggFunc;
103635103888
}
103636
- sAggInfo.mxReg = pParse->nMem;
103637103889
if( db->mallocFailed ) goto select_end;
103638103890
103639103891
/* Processing for aggregates with GROUP BY is very different and
103640103892
** much more complex than aggregates without a GROUP BY.
103641103893
*/
@@ -105536,11 +105788,11 @@
105536105788
pCol->affinity, &pValue);
105537105789
if( pValue ){
105538105790
sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM);
105539105791
}
105540105792
#ifndef SQLITE_OMIT_FLOATING_POINT
105541
- if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
105793
+ if( iReg>=0 && pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
105542105794
sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
105543105795
}
105544105796
#endif
105545105797
}
105546105798
}
@@ -105960,14 +106212,14 @@
105960106212
** be used eliminates some redundant opcodes.
105961106213
*/
105962106214
newmask = sqlite3TriggerColmask(
105963106215
pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError
105964106216
);
105965
- /*sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);*/
106217
+ sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);
105966106218
for(i=0; i<pTab->nCol; i++){
105967106219
if( i==pTab->iPKey ){
105968
- sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
106220
+ /*sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);*/
105969106221
}else{
105970106222
j = aXRef[i];
105971106223
if( j>=0 ){
105972106224
sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i);
105973106225
}else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask&(1<<i)) ){
@@ -105977,12 +106229,10 @@
105977106229
** a new.* reference in a trigger program.
105978106230
*/
105979106231
testcase( i==31 );
105980106232
testcase( i==32 );
105981106233
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
105982
- }else{
105983
- sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
105984106234
}
105985106235
}
105986106236
}
105987106237
105988106238
/* Fire any BEFORE UPDATE triggers. This happens before constraints are
@@ -110731,11 +110981,11 @@
110731110981
int iTerm, /* Index of this term. First is zero */
110732110982
const char *zColumn, /* Name of the column */
110733110983
const char *zOp /* Name of the operator */
110734110984
){
110735110985
if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110736
- sqlite3StrAccumAppendAll(pStr, zColumn);
110986
+ sqlite3StrAccumAppend(pStr, zColumn, -1);
110737110987
sqlite3StrAccumAppend(pStr, zOp, 1);
110738110988
sqlite3StrAccumAppend(pStr, "?", 1);
110739110989
}
110740110990
110741110991
/*
@@ -110777,11 +111027,11 @@
110777111027
if( i>=nSkip ){
110778111028
explainAppendTerm(&txt, i, z, "=");
110779111029
}else{
110780111030
if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
110781111031
sqlite3StrAccumAppend(&txt, "ANY(", 4);
110782
- sqlite3StrAccumAppendAll(&txt, z);
111032
+ sqlite3StrAccumAppend(&txt, z, -1);
110783111033
sqlite3StrAccumAppend(&txt, ")", 1);
110784111034
}
110785111035
}
110786111036
110787111037
j = i;
@@ -113593,16 +113843,13 @@
113593113843
sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113594113844
113595113845
/* Special case: a WHERE clause that is constant. Evaluate the
113596113846
** expression and either jump over all of the code or fall thru.
113597113847
*/
113598
- for(ii=0; ii<sWLB.pWC->nTerm; ii++){
113599
- if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){
113600
- sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak,
113601
- SQLITE_JUMPIFNULL);
113602
- sWLB.pWC->a[ii].wtFlags |= TERM_CODED;
113603
- }
113848
+ if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
113849
+ sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);
113850
+ pWhere = 0;
113604113851
}
113605113852
113606113853
/* Special case: No FROM clause
113607113854
*/
113608113855
if( nTabList==0 ){
@@ -119339,12 +119586,11 @@
119339119586
}
119340119587
db->lookaside.pEnd = p;
119341119588
db->lookaside.bEnabled = 1;
119342119589
db->lookaside.bMalloced = pBuf==0 ?1:0;
119343119590
}else{
119344
- db->lookaside.pStart = db;
119345
- db->lookaside.pEnd = db;
119591
+ db->lookaside.pEnd = 0;
119346119592
db->lookaside.bEnabled = 0;
119347119593
db->lookaside.bMalloced = 0;
119348119594
}
119349119595
return SQLITE_OK;
119350119596
}
@@ -119738,11 +119984,13 @@
119738119984
}
119739119985
sqlite3HashClear(&db->aModule);
119740119986
#endif
119741119987
119742119988
sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
119743
- sqlite3ValueFree(db->pErr);
119989
+ if( db->pErr ){
119990
+ sqlite3ValueFree(db->pErr);
119991
+ }
119744119992
sqlite3CloseExtensions(db);
119745119993
119746119994
db->magic = SQLITE_MAGIC_ERROR;
119747119995
119748119996
/* The temp-database schema is allocated differently from the other schema
@@ -119813,11 +120061,12 @@
119813120061
119814120062
/*
119815120063
** Return a static string containing the name corresponding to the error code
119816120064
** specified in the argument.
119817120065
*/
119818
-#if defined(SQLITE_TEST)
120066
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
120067
+ defined(SQLITE_DEBUG_OS_TRACE)
119819120068
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
119820120069
const char *zName = 0;
119821120070
int i, origRc = rc;
119822120071
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
119823120072
switch( rc ){
@@ -119835,11 +120084,10 @@
119835120084
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
119836120085
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
119837120086
case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
119838120087
case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
119839120088
case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
119840
- case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
119841120089
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
119842120090
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
119843120091
case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
119844120092
case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
119845120093
case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -120120,11 +120368,10 @@
120120120368
void (*xFinal)(sqlite3_context*),
120121120369
FuncDestructor *pDestructor
120122120370
){
120123120371
FuncDef *p;
120124120372
int nName;
120125
- int extraFlags;
120126120373
120127120374
assert( sqlite3_mutex_held(db->mutex) );
120128120375
if( zFunctionName==0 ||
120129120376
(xFunc && (xFinal || xStep)) ||
120130120377
(!xFunc && (xFinal && !xStep)) ||
@@ -120131,14 +120378,10 @@
120131120378
(!xFunc && (!xFinal && xStep)) ||
120132120379
(nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
120133120380
(255<(nName = sqlite3Strlen30( zFunctionName))) ){
120134120381
return SQLITE_MISUSE_BKPT;
120135120382
}
120136
-
120137
- assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
120138
- extraFlags = enc & SQLITE_DETERMINISTIC;
120139
- enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
120140120383
120141120384
#ifndef SQLITE_OMIT_UTF16
120142120385
/* If SQLITE_UTF16 is specified as the encoding type, transform this
120143120386
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
120144120387
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -120148,14 +120391,14 @@
120148120391
*/
120149120392
if( enc==SQLITE_UTF16 ){
120150120393
enc = SQLITE_UTF16NATIVE;
120151120394
}else if( enc==SQLITE_ANY ){
120152120395
int rc;
120153
- rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
120396
+ rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
120154120397
pUserData, xFunc, xStep, xFinal, pDestructor);
120155120398
if( rc==SQLITE_OK ){
120156
- rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
120399
+ rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
120157120400
pUserData, xFunc, xStep, xFinal, pDestructor);
120158120401
}
120159120402
if( rc!=SQLITE_OK ){
120160120403
return rc;
120161120404
}
@@ -120194,12 +120437,11 @@
120194120437
120195120438
if( pDestructor ){
120196120439
pDestructor->nRef++;
120197120440
}
120198120441
p->pDestructor = pDestructor;
120199
- p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
120200
- testcase( p->funcFlags & SQLITE_DETERMINISTIC );
120442
+ p->funcFlags &= SQLITE_FUNC_ENCMASK;
120201120443
p->xFunc = xFunc;
120202120444
p->xStep = xStep;
120203120445
p->xFinalize = xFinal;
120204120446
p->pUserData = pUserData;
120205120447
p->nArg = (u16)nArg;
@@ -120625,11 +120867,10 @@
120625120867
}
120626120868
sqlite3_mutex_enter(db->mutex);
120627120869
if( db->mallocFailed ){
120628120870
z = sqlite3ErrStr(SQLITE_NOMEM);
120629120871
}else{
120630
- testcase( db->pErr==0 );
120631120872
z = (char*)sqlite3_value_text(db->pErr);
120632120873
assert( !db->mallocFailed );
120633120874
if( z==0 ){
120634120875
z = sqlite3ErrStr(db->errCode);
120635120876
}
@@ -120667,11 +120908,12 @@
120667120908
if( db->mallocFailed ){
120668120909
z = (void *)outOfMem;
120669120910
}else{
120670120911
z = sqlite3_value_text16(db->pErr);
120671120912
if( z==0 ){
120672
- sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode));
120913
+ sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
120914
+ SQLITE_UTF8, SQLITE_STATIC);
120673120915
z = sqlite3_value_text16(db->pErr);
120674120916
}
120675120917
/* A malloc() may have failed within the call to sqlite3_value_text16()
120676120918
** above. If this is the case, then the db->mallocFailed flag needs to
120677120919
** be cleared before returning. Do this directly, instead of via
@@ -121380,10 +121622,12 @@
121380121622
#ifdef SQLITE_ENABLE_RTREE
121381121623
if( !db->mallocFailed && rc==SQLITE_OK){
121382121624
rc = sqlite3RtreeInit(db);
121383121625
}
121384121626
#endif
121627
+
121628
+ sqlite3Error(db, rc, 0);
121385121629
121386121630
/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
121387121631
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
121388121632
** mode. Doing nothing at all also makes NORMAL the default.
121389121633
*/
@@ -121391,12 +121635,10 @@
121391121635
db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
121392121636
sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
121393121637
SQLITE_DEFAULT_LOCKING_MODE);
121394121638
#endif
121395121639
121396
- if( rc ) sqlite3Error(db, rc, 0);
121397
-
121398121640
/* Enable the lookaside-malloc subsystem */
121399121641
setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
121400121642
sqlite3GlobalConfig.nLookaside);
121401121643
121402121644
sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
@@ -121852,11 +122094,11 @@
121852122094
** Reset the PRNG back to its uninitialized state. The next call
121853122095
** to sqlite3_randomness() will reseed the PRNG using a single call
121854122096
** to the xRandomness method of the default VFS.
121855122097
*/
121856122098
case SQLITE_TESTCTRL_PRNG_RESET: {
121857
- sqlite3_randomness(0,0);
122099
+ sqlite3PrngResetState();
121858122100
break;
121859122101
}
121860122102
121861122103
/*
121862122104
** sqlite3_test_control(BITVEC_TEST, size, program)
@@ -124836,23 +125078,10 @@
124836125078
char **pzErr /* OUT: sqlite3_malloc'd error message */
124837125079
){
124838125080
return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
124839125081
}
124840125082
124841
-/*
124842
-** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
124843
-** extension is currently being used by a version of SQLite too old to
124844
-** support estimatedRows. In that case this function is a no-op.
124845
-*/
124846
-static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
124847
-#if SQLITE_VERSION_NUMBER>=3008002
124848
- if( sqlite3_libversion_number()>=3008002 ){
124849
- pIdxInfo->estimatedRows = nRow;
124850
- }
124851
-#endif
124852
-}
124853
-
124854125083
/*
124855125084
** Implementation of the xBestIndex method for FTS3 tables. There
124856125085
** are three possible strategies, in order of preference:
124857125086
**
124858125087
** 1. Direct lookup by rowid or docid.
@@ -124876,24 +125105,11 @@
124876125105
pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124877125106
pInfo->estimatedCost = 5000000;
124878125107
for(i=0; i<pInfo->nConstraint; i++){
124879125108
int bDocid; /* True if this constraint is on docid */
124880125109
struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
124881
- if( pCons->usable==0 ){
124882
- if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){
124883
- /* There exists an unusable MATCH constraint. This means that if
124884
- ** the planner does elect to use the results of this call as part
124885
- ** of the overall query plan the user will see an "unable to use
124886
- ** function MATCH in the requested context" error. To discourage
124887
- ** this, return a very high cost here. */
124888
- pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124889
- pInfo->estimatedCost = 1e50;
124890
- setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50);
124891
- return SQLITE_OK;
124892
- }
124893
- continue;
124894
- }
125110
+ if( pCons->usable==0 ) continue;
124895125111
124896125112
bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
124897125113
124898125114
/* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
124899125115
if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
@@ -131750,74 +131966,61 @@
131750131966
}
131751131967
131752131968
/* Step 2 */
131753131969
switch( z[1] ){
131754131970
case 'a':
131755
- if( !stem(&z, "lanoita", "ate", m_gt_0) ){
131756
- stem(&z, "lanoit", "tion", m_gt_0);
131757
- }
131971
+ stem(&z, "lanoita", "ate", m_gt_0) ||
131972
+ stem(&z, "lanoit", "tion", m_gt_0);
131758131973
break;
131759131974
case 'c':
131760
- if( !stem(&z, "icne", "ence", m_gt_0) ){
131761
- stem(&z, "icna", "ance", m_gt_0);
131762
- }
131975
+ stem(&z, "icne", "ence", m_gt_0) ||
131976
+ stem(&z, "icna", "ance", m_gt_0);
131763131977
break;
131764131978
case 'e':
131765131979
stem(&z, "rezi", "ize", m_gt_0);
131766131980
break;
131767131981
case 'g':
131768131982
stem(&z, "igol", "log", m_gt_0);
131769131983
break;
131770131984
case 'l':
131771
- if( !stem(&z, "ilb", "ble", m_gt_0)
131772
- && !stem(&z, "illa", "al", m_gt_0)
131773
- && !stem(&z, "iltne", "ent", m_gt_0)
131774
- && !stem(&z, "ile", "e", m_gt_0)
131775
- ){
131776
- stem(&z, "ilsuo", "ous", m_gt_0);
131777
- }
131985
+ stem(&z, "ilb", "ble", m_gt_0) ||
131986
+ stem(&z, "illa", "al", m_gt_0) ||
131987
+ stem(&z, "iltne", "ent", m_gt_0) ||
131988
+ stem(&z, "ile", "e", m_gt_0) ||
131989
+ stem(&z, "ilsuo", "ous", m_gt_0);
131778131990
break;
131779131991
case 'o':
131780
- if( !stem(&z, "noitazi", "ize", m_gt_0)
131781
- && !stem(&z, "noita", "ate", m_gt_0)
131782
- ){
131783
- stem(&z, "rota", "ate", m_gt_0);
131784
- }
131992
+ stem(&z, "noitazi", "ize", m_gt_0) ||
131993
+ stem(&z, "noita", "ate", m_gt_0) ||
131994
+ stem(&z, "rota", "ate", m_gt_0);
131785131995
break;
131786131996
case 's':
131787
- if( !stem(&z, "msila", "al", m_gt_0)
131788
- && !stem(&z, "ssenevi", "ive", m_gt_0)
131789
- && !stem(&z, "ssenluf", "ful", m_gt_0)
131790
- ){
131791
- stem(&z, "ssensuo", "ous", m_gt_0);
131792
- }
131997
+ stem(&z, "msila", "al", m_gt_0) ||
131998
+ stem(&z, "ssenevi", "ive", m_gt_0) ||
131999
+ stem(&z, "ssenluf", "ful", m_gt_0) ||
132000
+ stem(&z, "ssensuo", "ous", m_gt_0);
131793132001
break;
131794132002
case 't':
131795
- if( !stem(&z, "itila", "al", m_gt_0)
131796
- && !stem(&z, "itivi", "ive", m_gt_0)
131797
- ){
131798
- stem(&z, "itilib", "ble", m_gt_0);
131799
- }
132003
+ stem(&z, "itila", "al", m_gt_0) ||
132004
+ stem(&z, "itivi", "ive", m_gt_0) ||
132005
+ stem(&z, "itilib", "ble", m_gt_0);
131800132006
break;
131801132007
}
131802132008
131803132009
/* Step 3 */
131804132010
switch( z[0] ){
131805132011
case 'e':
131806
- if( !stem(&z, "etaci", "ic", m_gt_0)
131807
- && !stem(&z, "evita", "", m_gt_0)
131808
- ){
131809
- stem(&z, "ezila", "al", m_gt_0);
131810
- }
132012
+ stem(&z, "etaci", "ic", m_gt_0) ||
132013
+ stem(&z, "evita", "", m_gt_0) ||
132014
+ stem(&z, "ezila", "al", m_gt_0);
131811132015
break;
131812132016
case 'i':
131813132017
stem(&z, "itici", "ic", m_gt_0);
131814132018
break;
131815132019
case 'l':
131816
- if( !stem(&z, "laci", "ic", m_gt_0) ){
131817
- stem(&z, "luf", "", m_gt_0);
131818
- }
132020
+ stem(&z, "laci", "ic", m_gt_0) ||
132021
+ stem(&z, "luf", "", m_gt_0);
131819132022
break;
131820132023
case 's':
131821132024
stem(&z, "ssen", "", m_gt_0);
131822132025
break;
131823132026
}
@@ -131854,15 +132057,13 @@
131854132057
if( z[2]=='a' ){
131855132058
if( m_gt_1(z+3) ){
131856132059
z += 3;
131857132060
}
131858132061
}else if( z[2]=='e' ){
131859
- if( !stem(&z, "tneme", "", m_gt_1)
131860
- && !stem(&z, "tnem", "", m_gt_1)
131861
- ){
131862
- stem(&z, "tne", "", m_gt_1);
131863
- }
132062
+ stem(&z, "tneme", "", m_gt_1) ||
132063
+ stem(&z, "tnem", "", m_gt_1) ||
132064
+ stem(&z, "tne", "", m_gt_1);
131864132065
}
131865132066
}
131866132067
break;
131867132068
case 'o':
131868132069
if( z[0]=='u' ){
@@ -131877,13 +132078,12 @@
131877132078
if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
131878132079
z += 3;
131879132080
}
131880132081
break;
131881132082
case 't':
131882
- if( !stem(&z, "eta", "", m_gt_1) ){
131883
- stem(&z, "iti", "", m_gt_1);
131884
- }
132083
+ stem(&z, "eta", "", m_gt_1) ||
132084
+ stem(&z, "iti", "", m_gt_1);
131885132085
break;
131886132086
case 'u':
131887132087
if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
131888132088
z += 3;
131889132089
}
131890132090
--- 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.3. 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.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -517,11 +517,10 @@
517 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
522 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
523 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
524 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
525 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
526 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
527 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -585,12 +584,11 @@
585 ** information is written to disk in the same order as calls
586 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
587 ** after reboot following a crash or power loss, the only bytes in a
588 ** file that were written at the application level might have changed
589 ** and that adjacent bytes, even bytes within the same sector are
590 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
591 ** flag indicate that a file cannot be deleted when open.
592 */
593 #define SQLITE_IOCAP_ATOMIC 0x00000001
594 #define SQLITE_IOCAP_ATOMIC512 0x00000002
595 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
596 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -817,33 +815,19 @@
817 ** to the [sqlite3_file] object associated with a particular database
818 ** connection. See the [sqlite3_file_control()] documentation for
819 ** additional information.
820 **
821 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
822 ** No longer in use.
823 **
824 ** <li>[[SQLITE_FCNTL_SYNC]]
825 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
826 ** sent to the VFS immediately before the xSync method is invoked on a
827 ** database file descriptor. Or, if the xSync method is not invoked
828 ** because the user has configured SQLite with
829 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
830 ** of the xSync method. In most cases, the pointer argument passed with
831 ** this file-control is NULL. However, if the database file is being synced
832 ** as part of a multi-database commit, the argument points to a nul-terminated
833 ** string containing the transactions master-journal file name. VFSes that
834 ** do not need this signal should silently ignore this opcode. Applications
835 ** should not call [sqlite3_file_control()] with this opcode as doing so may
836 ** disrupt the operation of the specialized VFSes that do require it.
837 **
838 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
839 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
840 ** and sent to the VFS after a transaction has been committed immediately
841 ** but before the database is unlocked. VFSes that do not need this signal
842 ** should silently ignore this opcode. Applications should not call
843 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
844 ** operation of the specialized VFSes that do require it.
845 **
846 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
847 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
848 ** retry counts and intervals for certain disk I/O operations for the
849 ** windows [VFS] in order to provide robustness in the presence of
@@ -963,16 +947,10 @@
963 ** This file control is used by some VFS activity tracing [shims].
964 ** The argument is a zero-terminated string. Higher layers in the
965 ** SQLite stack may generate instances of this file control if
966 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
967 **
968 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
969 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
970 ** pointer to an integer and it writes a boolean into that integer depending
971 ** on whether or not the file has been renamed, moved, or deleted since it
972 ** was first opened.
973 **
974 ** </ul>
975 */
976 #define SQLITE_FCNTL_LOCKSTATE 1
977 #define SQLITE_GET_LOCKPROXYFILE 2
978 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -989,13 +967,10 @@
989 #define SQLITE_FCNTL_PRAGMA 14
990 #define SQLITE_FCNTL_BUSYHANDLER 15
991 #define SQLITE_FCNTL_TEMPFILENAME 16
992 #define SQLITE_FCNTL_MMAP_SIZE 18
993 #define SQLITE_FCNTL_TRACE 19
994 #define SQLITE_FCNTL_HAS_MOVED 20
995 #define SQLITE_FCNTL_SYNC 21
996 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
997
998 /*
999 ** CAPI3REF: Mutex Handle
1000 **
1001 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2426,17 +2401,15 @@
2426 ** already uses the largest possible [ROWID]. The PRNG is also used for
2427 ** the build-in random() and randomblob() SQL functions. This interface allows
2428 ** applications to access the same PRNG for other purposes.
2429 **
2430 ** ^A call to this routine stores N bytes of randomness into buffer P.
2431 ** ^If N is less than one, then P can be a NULL pointer.
2432 **
2433 ** ^If this routine has not been previously called or if the previous
2434 ** call had N less than one, then the PRNG is seeded using randomness
2435 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2436 ** ^If the previous call to this routine had an N of 1 or more then
2437 ** the pseudo-randomness is generated
2438 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2439 ** method.
2440 */
2441 SQLITE_API void sqlite3_randomness(int N, void *P);
2442
@@ -4010,28 +3983,19 @@
4010 ** parameter is less than -1 or greater than 127 then the behavior is
4011 ** undefined.
4012 **
4013 ** ^The fourth parameter, eTextRep, specifies what
4014 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
4015 ** its parameters. The application should set this parameter to
4016 ** [SQLITE_UTF16LE] if the function implementation invokes
4017 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
4018 ** implementation invokes [sqlite3_value_text16be()] on an input, or
4019 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
4020 ** otherwise. ^The same SQL function may be registered multiple times using
4021 ** different preferred text encodings, with different implementations for
4022 ** each encoding.
4023 ** ^When multiple implementations of the same function are available, SQLite
4024 ** will pick the one that involves the least amount of data conversion.
4025 **
4026 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
4027 ** to signal that the function will always return the same result given
4028 ** the same inputs within a single SQL statement. Most SQL functions are
4029 ** deterministic. The built-in [random()] SQL function is an example of a
4030 ** function that is not deterministic. The SQLite query planner is able to
4031 ** perform additional optimizations on deterministic functions, so use
4032 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4033 **
4034 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4035 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4036 **
4037 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4113,23 +4077,13 @@
4113 */
4114 #define SQLITE_UTF8 1
4115 #define SQLITE_UTF16LE 2
4116 #define SQLITE_UTF16BE 3
4117 #define SQLITE_UTF16 4 /* Use native byte order */
4118 #define SQLITE_ANY 5 /* Deprecated */
4119 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4120
4121 /*
4122 ** CAPI3REF: Function Flags
4123 **
4124 ** These constants may be ORed together with the
4125 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4126 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4127 ** [sqlite3_create_function_v2()].
4128 */
4129 #define SQLITE_DETERMINISTIC 0x800
4130
4131 /*
4132 ** CAPI3REF: Deprecated Functions
4133 ** DEPRECATED
4134 **
4135 ** These functions are [deprecated]. In order to maintain
@@ -8627,11 +8581,10 @@
8627 typedef struct Lookaside Lookaside;
8628 typedef struct LookasideSlot LookasideSlot;
8629 typedef struct Module Module;
8630 typedef struct NameContext NameContext;
8631 typedef struct Parse Parse;
8632 typedef struct PrintfArguments PrintfArguments;
8633 typedef struct RowSet RowSet;
8634 typedef struct Savepoint Savepoint;
8635 typedef struct Select Select;
8636 typedef struct SelectDest SelectDest;
8637 typedef struct SrcList SrcList;
@@ -9100,11 +9053,11 @@
9100 #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9101 #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9102 #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9103 #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9104 #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9105 #define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9106 #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9107 #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9108 #define OP_CollSeq 33
9109 #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9110 #define OP_MustBeInt 35
@@ -9265,11 +9218,11 @@
9265
9266 /*
9267 ** Prototypes for the VDBE interface. See comments on the implementation
9268 ** for a description of what each of these routines does.
9269 */
9270 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*);
9271 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
9272 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
9273 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
9274 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
9275 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
@@ -9280,11 +9233,10 @@
9280 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9281 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9282 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
9283 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
9284 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
9285 SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*);
9286 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
9287 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
9288 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
9289 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
9290 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
@@ -9487,11 +9439,10 @@
9487 SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
9488 #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
9489 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
9490 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
9491 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
9492 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
9493
9494 /* Operations on page references. */
9495 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
9496 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
9497 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -9502,11 +9453,11 @@
9502 /* Functions used to manage pager transactions and savepoints. */
9503 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
9504 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
9505 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
9506 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
9507 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster);
9508 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
9509 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
9510 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
9511 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
9512 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -10374,11 +10325,11 @@
10374 */
10375 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
10376 #define SQLITE_ColumnCache 0x0002 /* Column cache */
10377 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
10378 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10379 /* not used 0x0010 // Was: SQLITE_IdxRealAsInt */
10380 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10381 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10382 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10383 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10384 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
@@ -11006,11 +10957,10 @@
11006 u8 useSortingIdx; /* In direct mode, reference the sorting index rather
11007 ** than the source table */
11008 int sortingIdx; /* Cursor number of the sorting index */
11009 int sortingIdxPTab; /* Cursor number of pseudo-table */
11010 int nSortingColumn; /* Number of columns in the sorting index */
11011 int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
11012 ExprList *pGroupBy; /* The group by clause */
11013 struct AggInfo_col { /* For each column used in source tables */
11014 Table *pTab; /* Source table */
11015 int iTable; /* Cursor number of the source table */
11016 int iColumn; /* Column number within the source table */
@@ -11608,13 +11558,10 @@
11608 int nErr; /* Number of errors seen */
11609 int nTab; /* Number of previously allocated VDBE cursors */
11610 int nMem; /* Number of memory cells used so far */
11611 int nSet; /* Number of sets used so far */
11612 int nOnce; /* Number of OP_Once instructions so far */
11613 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11614 int nLabel; /* Number of labels used */
11615 int *aLabel; /* Space to hold the labels */
11616 int ckBase; /* Base register of data during check constraints */
11617 int iPartIdxTab; /* Table corresponding to a partial index */
11618 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11619 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11620 struct yColCache {
@@ -12087,24 +12034,14 @@
12087 SQLITE_PRIVATE int sqlite3IsNaN(double);
12088 #else
12089 # define sqlite3IsNaN(X) 0
12090 #endif
12091
12092 /*
12093 ** An instance of the following structure holds information about SQL
12094 ** functions arguments that are the parameters to the printf() function.
12095 */
12096 struct PrintfArguments {
12097 int nArg; /* Total number of arguments */
12098 int nUsed; /* Number of arguments used so far */
12099 sqlite3_value **apArg; /* The argument values */
12100 };
12101
12102 #define SQLITE_PRINTF_INTERNAL 0x01
12103 #define SQLITE_PRINTF_SQLFUNC 0x02
12104 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
12105 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
12106 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
12107 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
12108 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12109 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
12110 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
@@ -12290,10 +12227,11 @@
12290 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
12291 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
12292 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
12293 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
12294 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
 
12295 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
12296 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
12297 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
12298 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
12299 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
@@ -12458,11 +12396,12 @@
12458 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
12459 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
12460 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
12461 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
12462
12463 #if defined(SQLITE_TEST)
 
12464 SQLITE_PRIVATE const char *sqlite3ErrName(int);
12465 #endif
12466
12467 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
12468 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -12488,11 +12427,10 @@
12488
12489 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
12490 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
12491 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
12492 void(*)(void*));
12493 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*);
12494 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
12495 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
12496 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
12497 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
12498 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
@@ -12554,11 +12492,10 @@
12554 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
12555 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
12556
12557 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
12558 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
12559 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
12560 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
12561 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
12562 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
12563 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
12564 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -13781,13 +13718,16 @@
13781 Op *aOp; /* Space to hold the virtual machine's program */
13782 Mem *aMem; /* The memory locations */
13783 Mem **apArg; /* Arguments to currently executing user function */
13784 Mem *aColName; /* Column names to return */
13785 Mem *pResultSet; /* Pointer to an array of results */
13786 Parse *pParse; /* Parsing context used to create this Vdbe */
13787 int nMem; /* Number of memory locations currently allocated */
13788 int nOp; /* Number of instructions in the program */
 
 
 
 
13789 int nCursor; /* Number of slots in apCsr[] */
13790 u32 magic; /* Magic number for sanity checking */
13791 char *zErrMsg; /* Error message written here */
13792 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
13793 VdbeCursor **apCsr; /* One element of this array for each open cursor */
@@ -13796,11 +13736,10 @@
13796 ynVar nVar; /* Number of entries in aVar[] */
13797 ynVar nzVar; /* Number of entries in azVar[] */
13798 u32 cacheCtr; /* VdbeCursor row cache generation counter */
13799 int pc; /* The program counter */
13800 int rc; /* Value to return */
13801 u16 nResColumn; /* Number of columns in one row of the result set */
13802 u8 errorAction; /* Recovery action to do in case of an error */
13803 u8 minWriteFileFormat; /* Minimum file format for writable database files */
13804 bft explain:2; /* True if EXPLAIN present on SQL command */
13805 bft inVtabMethod:2; /* See comments above */
13806 bft changeCntOn:1; /* True to update the change-counter */
@@ -13856,11 +13795,11 @@
13856 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
13857 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
13858 #endif
13859 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13860 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13861 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
13862 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13863 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13864
13865 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13866 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -15446,25 +15385,11 @@
15446 ** really care if the VFS receives and understands the information since it
15447 ** is only a hint and can be safely ignored. The sqlite3OsFileControlHint()
15448 ** routine has no return value since the return value would be meaningless.
15449 */
15450 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
15451 #ifdef SQLITE_TEST
15452 if( op!=SQLITE_FCNTL_COMMIT_PHASETWO ){
15453 /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
15454 ** is using a regular VFS, it is called after the corresponding
15455 ** transaction has been committed. Injecting a fault at this point
15456 ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM
15457 ** but the transaction is committed anyway.
15458 **
15459 ** The core must call OsFileControl() though, not OsFileControlHint(),
15460 ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
15461 ** means the commit really has failed and an error should be returned
15462 ** to the user. */
15463 DO_OS_MALLOC_TEST(id);
15464 }
15465 #endif
15466 return id->pMethods->xFileControl(id, op, pArg);
15467 }
15468 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
15469 (void)id->pMethods->xFileControl(id, op, pArg);
15470 }
@@ -19455,11 +19380,11 @@
19455 /*
19456 ** TRUE if p is a lookaside memory allocation from db
19457 */
19458 #ifndef SQLITE_OMIT_LOOKASIDE
19459 static int isLookaside(sqlite3 *db, void *p){
19460 return p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19461 }
19462 #else
19463 #define isLookaside(A,B) 0
19464 #endif
19465
@@ -19471,13 +19396,12 @@
19471 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
19472 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
19473 return sqlite3GlobalConfig.m.xSize(p);
19474 }
19475 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19476 assert( db!=0 );
19477 assert( sqlite3_mutex_held(db->mutex) );
19478 if( isLookaside(db, p) ){
19479 return db->lookaside.sz;
19480 }else{
19481 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
19482 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
19483 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19955,35 +19879,10 @@
19955 }
19956 if( N>0 ){
19957 sqlite3StrAccumAppend(pAccum, zSpaces, N);
19958 }
19959 }
19960
19961 /*
19962 ** Set the StrAccum object to an error mode.
19963 */
19964 static void setStrAccumError(StrAccum *p, u8 eError){
19965 p->accError = eError;
19966 p->nAlloc = 0;
19967 }
19968
19969 /*
19970 ** Extra argument values from a PrintfArguments object
19971 */
19972 static sqlite3_int64 getIntArg(PrintfArguments *p){
19973 if( p->nArg<=p->nUsed ) return 0;
19974 return sqlite3_value_int64(p->apArg[p->nUsed++]);
19975 }
19976 static double getDoubleArg(PrintfArguments *p){
19977 if( p->nArg<=p->nUsed ) return 0.0;
19978 return sqlite3_value_double(p->apArg[p->nUsed++]);
19979 }
19980 static char *getTextArg(PrintfArguments *p){
19981 if( p->nArg<=p->nUsed ) return 0;
19982 return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
19983 }
19984
19985
19986 /*
19987 ** On machines with a small stack size, you can redefine the
19988 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19989 */
@@ -19994,14 +19893,14 @@
19994
19995 /*
19996 ** Render a string given by "fmt" into the StrAccum object.
19997 */
19998 SQLITE_PRIVATE void sqlite3VXPrintf(
19999 StrAccum *pAccum, /* Accumulate results here */
20000 u32 bFlags, /* SQLITE_PRINTF_* flags */
20001 const char *fmt, /* Format string */
20002 va_list ap /* arguments */
20003 ){
20004 int c; /* Next character in the format string */
20005 char *bufpt; /* Pointer to the conversion buffer */
20006 int precision; /* Precision of the current field */
20007 int length; /* Length of the field */
@@ -20015,12 +19914,10 @@
20015 etByte flag_zeropad; /* True if field width constant starts with zero */
20016 etByte flag_long; /* True if "l" flag is present */
20017 etByte flag_longlong; /* True if the "ll" flag is present */
20018 etByte done; /* Loop termination flag */
20019 etByte xtype = 0; /* Conversion paradigm */
20020 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
20021 u8 useIntern; /* Ok to use internal conversions (ex: %T) */
20022 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
20023 sqlite_uint64 longvalue; /* Value for integer types */
20024 LONGDOUBLE_TYPE realvalue; /* Value for real types */
20025 const et_info *infop; /* Pointer to the appropriate info structure */
20026 char *zOut; /* Rendering buffer */
@@ -20031,22 +19928,13 @@
20031 int nsd; /* Number of significant digits returned */
20032 double rounder; /* Used for rounding floating point values */
20033 etByte flag_dp; /* True if decimal point should be shown */
20034 etByte flag_rtz; /* True if trailing zeros should be removed */
20035 #endif
20036 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
20037 char buf[etBUFSIZE]; /* Conversion buffer */
20038
20039 bufpt = 0;
20040 if( bFlags ){
20041 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
20042 pArgList = va_arg(ap, PrintfArguments*);
20043 }
20044 useIntern = bFlags & SQLITE_PRINTF_INTERNAL;
20045 }else{
20046 bArgList = useIntern = 0;
20047 }
20048 for(; (c=(*fmt))!=0; ++fmt){
20049 if( c!='%' ){
20050 int amt;
20051 bufpt = (char *)fmt;
20052 amt = 1;
@@ -20074,15 +19962,11 @@
20074 }
20075 }while( !done && (c=(*++fmt))!=0 );
20076 /* Get the field width */
20077 width = 0;
20078 if( c=='*' ){
20079 if( bArgList ){
20080 width = (int)getIntArg(pArgList);
20081 }else{
20082 width = va_arg(ap,int);
20083 }
20084 if( width<0 ){
20085 flag_leftjustify = 1;
20086 width = -width;
20087 }
20088 c = *++fmt;
@@ -20095,15 +19979,11 @@
20095 /* Get the precision */
20096 if( c=='.' ){
20097 precision = 0;
20098 c = *++fmt;
20099 if( c=='*' ){
20100 if( bArgList ){
20101 precision = (int)getIntArg(pArgList);
20102 }else{
20103 precision = va_arg(ap,int);
20104 }
20105 if( precision<0 ) precision = -precision;
20106 c = *++fmt;
20107 }else{
20108 while( c>='0' && c<='9' ){
20109 precision = precision*10 + c - '0';
@@ -20130,11 +20010,11 @@
20130 infop = &fmtinfo[0];
20131 xtype = etINVALID;
20132 for(idx=0; idx<ArraySize(fmtinfo); idx++){
20133 if( c==fmtinfo[idx].fmttype ){
20134 infop = &fmtinfo[idx];
20135 if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
20136 xtype = infop->type;
20137 }else{
20138 return;
20139 }
20140 break;
@@ -20170,13 +20050,11 @@
20170 /* Fall through into the next case */
20171 case etORDINAL:
20172 case etRADIX:
20173 if( infop->flags & FLAG_SIGNED ){
20174 i64 v;
20175 if( bArgList ){
20176 v = getIntArg(pArgList);
20177 }else if( flag_longlong ){
20178 v = va_arg(ap,i64);
20179 }else if( flag_long ){
20180 v = va_arg(ap,long int);
20181 }else{
20182 v = va_arg(ap,int);
@@ -20193,13 +20071,11 @@
20193 if( flag_plussign ) prefix = '+';
20194 else if( flag_blanksign ) prefix = ' ';
20195 else prefix = 0;
20196 }
20197 }else{
20198 if( bArgList ){
20199 longvalue = (u64)getIntArg(pArgList);
20200 }else if( flag_longlong ){
20201 longvalue = va_arg(ap,u64);
20202 }else if( flag_long ){
20203 longvalue = va_arg(ap,unsigned long int);
20204 }else{
20205 longvalue = va_arg(ap,unsigned int);
@@ -20215,11 +20091,11 @@
20215 zOut = buf;
20216 }else{
20217 nOut = precision + 10;
20218 zOut = zExtra = sqlite3Malloc( nOut );
20219 if( zOut==0 ){
20220 setStrAccumError(pAccum, STRACCUM_NOMEM);
20221 return;
20222 }
20223 }
20224 bufpt = &zOut[nOut-1];
20225 if( xtype==etORDINAL ){
@@ -20255,15 +20131,11 @@
20255 length = (int)(&zOut[nOut-1]-bufpt);
20256 break;
20257 case etFLOAT:
20258 case etEXP:
20259 case etGENERIC:
20260 if( bArgList ){
20261 realvalue = getDoubleArg(pArgList);
20262 }else{
20263 realvalue = va_arg(ap,double);
20264 }
20265 #ifdef SQLITE_OMIT_FLOATING_POINT
20266 length = 0;
20267 #else
20268 if( precision<0 ) precision = 6; /* Set default precision */
20269 if( realvalue<0.0 ){
@@ -20331,11 +20203,11 @@
20331 e2 = exp;
20332 }
20333 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20334 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20335 if( bufpt==0 ){
20336 setStrAccumError(pAccum, STRACCUM_NOMEM);
20337 return;
20338 }
20339 }
20340 zOut = bufpt;
20341 nsd = 16 + flag_altform2*10;
@@ -20414,27 +20286,20 @@
20414 length = width;
20415 }
20416 #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
20417 break;
20418 case etSIZE:
20419 if( !bArgList ){
20420 *(va_arg(ap,int*)) = pAccum->nChar;
20421 }
20422 length = width = 0;
20423 break;
20424 case etPERCENT:
20425 buf[0] = '%';
20426 bufpt = buf;
20427 length = 1;
20428 break;
20429 case etCHARX:
20430 if( bArgList ){
20431 bufpt = getTextArg(pArgList);
20432 c = bufpt ? bufpt[0] : 0;
20433 }else{
20434 c = va_arg(ap,int);
20435 }
20436 buf[0] = (char)c;
20437 if( precision>=0 ){
20438 for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
20439 length = precision;
20440 }else{
@@ -20442,18 +20307,14 @@
20442 }
20443 bufpt = buf;
20444 break;
20445 case etSTRING:
20446 case etDYNSTRING:
20447 if( bArgList ){
20448 bufpt = getTextArg(pArgList);
20449 }else{
20450 bufpt = va_arg(ap,char*);
20451 }
20452 if( bufpt==0 ){
20453 bufpt = "";
20454 }else if( xtype==etDYNSTRING && !bArgList ){
20455 zExtra = bufpt;
20456 }
20457 if( precision>=0 ){
20458 for(length=0; length<precision && bufpt[length]; length++){}
20459 }else{
@@ -20465,17 +20326,11 @@
20465 case etSQLESCAPE3: {
20466 int i, j, k, n, isnull;
20467 int needQuote;
20468 char ch;
20469 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
20470 char *escarg;
20471
20472 if( bArgList ){
20473 escarg = getTextArg(pArgList);
20474 }else{
20475 escarg = va_arg(ap,char*);
20476 }
20477 isnull = escarg==0;
20478 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
20479 k = precision;
20480 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
20481 if( ch==q ) n++;
@@ -20483,11 +20338,11 @@
20483 needQuote = !isnull && xtype==etSQLESCAPE2;
20484 n += i + 1 + needQuote*2;
20485 if( n>etBUFSIZE ){
20486 bufpt = zExtra = sqlite3Malloc( n );
20487 if( bufpt==0 ){
20488 setStrAccumError(pAccum, STRACCUM_NOMEM);
20489 return;
20490 }
20491 }else{
20492 bufpt = buf;
20493 }
@@ -20506,28 +20361,26 @@
20506 ** if( precision>=0 && precision<length ) length = precision; */
20507 break;
20508 }
20509 case etTOKEN: {
20510 Token *pToken = va_arg(ap, Token*);
20511 assert( bArgList==0 );
20512 if( pToken && pToken->n ){
20513 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20514 }
20515 length = width = 0;
20516 break;
20517 }
20518 case etSRCLIST: {
20519 SrcList *pSrc = va_arg(ap, SrcList*);
20520 int k = va_arg(ap, int);
20521 struct SrcList_item *pItem = &pSrc->a[k];
20522 assert( bArgList==0 );
20523 assert( k>=0 && k<pSrc->nSrc );
20524 if( pItem->zDatabase ){
20525 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
20526 sqlite3StrAccumAppend(pAccum, ".", 1);
20527 }
20528 sqlite3StrAccumAppendAll(pAccum, pItem->zName);
20529 length = width = 0;
20530 break;
20531 }
20532 default: {
20533 assert( xtype==etINVALID );
@@ -20554,42 +20407,44 @@
20554 nspace = width-length;
20555 if( nspace>0 ){
20556 sqlite3AppendSpace(pAccum, nspace);
20557 }
20558 }
20559 if( zExtra ) sqlite3_free(zExtra);
20560 }/* End for loop over the format string */
20561 } /* End of function */
20562
20563 /*
20564 ** Append N bytes of text from z to the StrAccum object.
20565 */
20566 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20567 assert( z!=0 );
20568 assert( p->zText!=0 || p->nChar==0 || p->accError );
20569 assert( N>=0 );
20570 assert( p->accError==0 || p->nAlloc==0 );
 
 
 
 
 
 
 
20571 if( p->nChar+N >= p->nAlloc ){
20572 char *zNew;
20573 if( p->accError ){
20574 testcase(p->accError==STRACCUM_TOOBIG);
20575 testcase(p->accError==STRACCUM_NOMEM);
20576 return;
20577 }
20578 if( !p->useMalloc ){
 
20579 N = p->nAlloc - p->nChar - 1;
20580 setStrAccumError(p, STRACCUM_TOOBIG);
20581 if( N<=0 ){
20582 return;
20583 }
20584 }else{
20585 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20586 i64 szNew = p->nChar;
20587 szNew += N + 1;
20588 if( szNew > p->mxAlloc ){
20589 sqlite3StrAccumReset(p);
20590 setStrAccumError(p, STRACCUM_TOOBIG);
20591 return;
20592 }else{
20593 p->nAlloc = (int)szNew;
20594 }
20595 if( p->useMalloc==1 ){
@@ -20599,28 +20454,20 @@
20599 }
20600 if( zNew ){
20601 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20602 p->zText = zNew;
20603 }else{
 
20604 sqlite3StrAccumReset(p);
20605 setStrAccumError(p, STRACCUM_NOMEM);
20606 return;
20607 }
20608 }
20609 }
20610 assert( p->zText );
20611 memcpy(&p->zText[p->nChar], z, N);
20612 p->nChar += N;
20613 }
20614
20615 /*
20616 ** Append the complete text of zero-terminated string z[] to the p string.
20617 */
20618 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){
20619 sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z));
20620 }
20621
20622
20623 /*
20624 ** Finish off a string by making sure it is zero-terminated.
20625 ** Return a pointer to the resulting string. Return a NULL
20626 ** pointer if any kind of error was encountered.
@@ -20635,11 +20482,11 @@
20635 p->zText = sqlite3_malloc(p->nChar+1);
20636 }
20637 if( p->zText ){
20638 memcpy(p->zText, p->zBase, p->nChar+1);
20639 }else{
20640 setStrAccumError(p, STRACCUM_NOMEM);
20641 }
20642 }
20643 }
20644 return p->zText;
20645 }
@@ -20681,11 +20528,11 @@
20681 StrAccum acc;
20682 assert( db!=0 );
20683 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
20684 db->aLimit[SQLITE_LIMIT_LENGTH]);
20685 acc.db = db;
20686 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
20687 z = sqlite3StrAccumFinish(&acc);
20688 if( acc.accError==STRACCUM_NOMEM ){
20689 db->mallocFailed = 1;
20690 }
20691 return z;
@@ -20837,19 +20684,21 @@
20837 fprintf(stdout,"%s", zBuf);
20838 fflush(stdout);
20839 }
20840 #endif
20841
 
20842 /*
20843 ** variable-argument wrapper around sqlite3VXPrintf().
20844 */
20845 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
20846 va_list ap;
20847 va_start(ap,zFormat);
20848 sqlite3VXPrintf(p, bFlags, zFormat, ap);
20849 va_end(ap);
20850 }
 
20851
20852 /************** End of printf.c **********************************************/
20853 /************** Begin file random.c ******************************************/
20854 /*
20855 ** 2001 September 15
@@ -20902,16 +20751,10 @@
20902 #if SQLITE_THREADSAFE
20903 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20904 sqlite3_mutex_enter(mutex);
20905 #endif
20906
20907 if( N<=0 ){
20908 wsdPrng.isInit = 0;
20909 sqlite3_mutex_leave(mutex);
20910 return;
20911 }
20912
20913 /* Initialize the state of the random number generator once,
20914 ** the first time this routine is called. The seed value does
20915 ** not need to contain a lot of randomness since we are not
20916 ** trying to do secure encryption or anything like that...
20917 **
@@ -20935,20 +20778,19 @@
20935 wsdPrng.s[i] = t;
20936 }
20937 wsdPrng.isInit = 1;
20938 }
20939
20940 assert( N>0 );
20941 do{
20942 wsdPrng.i++;
20943 t = wsdPrng.s[wsdPrng.i];
20944 wsdPrng.j += t;
20945 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20946 wsdPrng.s[wsdPrng.j] = t;
20947 t += wsdPrng.s[wsdPrng.i];
20948 *(zBuf++) = wsdPrng.s[t];
20949 }while( --N );
20950 sqlite3_mutex_leave(mutex);
20951 }
20952
20953 #ifndef SQLITE_OMIT_BUILTIN_TEST
20954 /*
@@ -20973,10 +20815,13 @@
20973 &GLOBAL(struct sqlite3PrngType, sqlite3Prng),
20974 &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
20975 sizeof(sqlite3Prng)
20976 );
20977 }
 
 
 
20978 #endif /* SQLITE_OMIT_BUILTIN_TEST */
20979
20980 /************** End of random.c **********************************************/
20981 /************** Begin file utf.c *********************************************/
20982 /*
@@ -21624,21 +21469,22 @@
21624 ** To clear the most recent error for sqlite handle "db", sqlite3Error
21625 ** should be called with err_code set to SQLITE_OK and zFormat set
21626 ** to NULL.
21627 */
21628 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21629 assert( db!=0 );
21630 db->errCode = err_code;
21631 if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21632 char *z;
21633 va_list ap;
21634 va_start(ap, zFormat);
21635 z = sqlite3VMPrintf(db, zFormat, ap);
21636 va_end(ap);
21637 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21638 }else if( db->pErr ){
21639 sqlite3ValueSetNull(db->pErr);
 
21640 }
21641 }
21642
21643 /*
21644 ** Add an error message to pParse->zErrMsg and increment pParse->nErr.
@@ -23119,11 +22965,11 @@
23119 /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23120 /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
23121 /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23122 /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23123 /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23124 /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23125 /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23126 /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23127 /* 33 */ "CollSeq" OpHelp(""),
23128 /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23129 /* 35 */ "MustBeInt" OpHelp(""),
@@ -23510,16 +23356,10 @@
23510 */
23511 char aPadding[32];
23512 #endif
23513 };
23514
23515 /* This variable holds the process id (pid) from when the xRandomness()
23516 ** method was called. If xOpen() is called from a different process id,
23517 ** indicating that a fork() has occurred, the PRNG will be reset.
23518 */
23519 static int randomnessPid = 0;
23520
23521 /*
23522 ** Allowed values for the unixFile.ctrlFlags bitmask:
23523 */
23524 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
23525 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */
@@ -24779,19 +24619,10 @@
24779 }
24780 *ppInode = pInode;
24781 return SQLITE_OK;
24782 }
24783
24784 /*
24785 ** Return TRUE if pFile has been renamed or unlinked since it was first opened.
24786 */
24787 static int fileHasMoved(unixFile *pFile){
24788 struct stat buf;
24789 return pFile->pInode!=0 &&
24790 (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
24791 }
24792
24793
24794 /*
24795 ** Check a unixFile that is a database. Verify the following:
24796 **
24797 ** (1) There is exactly one hard link on the file
@@ -24822,11 +24653,14 @@
24822 if( buf.st_nlink>1 ){
24823 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
24824 pFile->ctrlFlags |= UNIXFILE_WARNED;
24825 return;
24826 }
24827 if( fileHasMoved(pFile) ){
 
 
 
24828 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
24829 pFile->ctrlFlags |= UNIXFILE_WARNED;
24830 return;
24831 }
24832 }
@@ -27271,14 +27105,10 @@
27271 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
27272 *(char**)pArg = zTFile;
27273 }
27274 return SQLITE_OK;
27275 }
27276 case SQLITE_FCNTL_HAS_MOVED: {
27277 *(int*)pArg = fileHasMoved(pFile);
27278 return SQLITE_OK;
27279 }
27280 #if SQLITE_MAX_MMAP_SIZE>0
27281 case SQLITE_FCNTL_MMAP_SIZE: {
27282 i64 newLimit = *(i64*)pArg;
27283 int rc = SQLITE_OK;
27284 if( newLimit>sqlite3GlobalConfig.mxMmap ){
@@ -29115,20 +28945,10 @@
29115 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
29116 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
29117 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
29118 );
29119
29120 /* Detect a pid change and reset the PRNG. There is a race condition
29121 ** here such that two or more threads all trying to open databases at
29122 ** the same instant might all reset the PRNG. But multiple resets
29123 ** are harmless.
29124 */
29125 if( randomnessPid!=getpid() ){
29126 randomnessPid = getpid();
29127 sqlite3_randomness(0,0);
29128 }
29129
29130 memset(p, 0, sizeof(unixFile));
29131
29132 if( eType==SQLITE_OPEN_MAIN_DB ){
29133 UnixUnusedFd *pUnused;
29134 pUnused = findReusableFd(zName, flags);
@@ -29512,22 +29332,22 @@
29512 ** When testing, initializing zBuf[] to zero is all we do. That means
29513 ** that we always use the same random number sequence. This makes the
29514 ** tests repeatable.
29515 */
29516 memset(zBuf, 0, nBuf);
29517 randomnessPid = getpid();
29518 #if !defined(SQLITE_TEST)
29519 {
29520 int fd, got;
29521 fd = robust_open("/dev/urandom", O_RDONLY, 0);
29522 if( fd<0 ){
29523 time_t t;
29524 time(&t);
29525 memcpy(zBuf, &t, sizeof(t));
29526 memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid));
29527 assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf );
29528 nBuf = sizeof(t) + sizeof(randomnessPid);
 
29529 }else{
29530 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
29531 robust_close(0, fd, __LINE__);
29532 }
29533 }
@@ -34261,11 +34081,11 @@
34261 winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
34262 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34263 return SQLITE_OK;
34264 }
34265 case SQLITE_FCNTL_VFSNAME: {
34266 *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
34267 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34268 return SQLITE_OK;
34269 }
34270 case SQLITE_FCNTL_WIN32_AV_RETRY: {
34271 int *a = (int*)pArg;
@@ -37703,11 +37523,10 @@
37703 ** in memory.
37704 */
37705 struct PgHdr1 {
37706 sqlite3_pcache_page page;
37707 unsigned int iKey; /* Key value (page number) */
37708 u8 isPinned; /* Page in use, not on the LRU list */
37709 PgHdr1 *pNext; /* Next in hash table chain */
37710 PCache1 *pCache; /* Cache that currently owns this page */
37711 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
37712 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
37713 };
@@ -38032,36 +37851,38 @@
38032 ** This function is used internally to remove the page pPage from the
38033 ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
38034 ** LRU list, then this function is a no-op.
38035 **
38036 ** The PGroup mutex must be held when this function is called.
 
 
38037 */
38038 static void pcache1PinPage(PgHdr1 *pPage){
38039 PCache1 *pCache;
38040 PGroup *pGroup;
38041
38042 assert( pPage!=0 );
38043 assert( pPage->isPinned==0 );
38044 pCache = pPage->pCache;
38045 pGroup = pCache->pGroup;
38046 assert( pPage->pLruNext || pPage==pGroup->pLruTail );
38047 assert( pPage->pLruPrev || pPage==pGroup->pLruHead );
38048 assert( sqlite3_mutex_held(pGroup->mutex) );
38049 if( pPage->pLruPrev ){
38050 pPage->pLruPrev->pLruNext = pPage->pLruNext;
38051 }else{
38052 pGroup->pLruHead = pPage->pLruNext;
38053 }
38054 if( pPage->pLruNext ){
38055 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
38056 }else{
38057 pGroup->pLruTail = pPage->pLruPrev;
38058 }
38059 pPage->pLruNext = 0;
38060 pPage->pLruPrev = 0;
38061 pPage->isPinned = 1;
38062 pCache->nRecyclable--;
 
 
 
38063 }
38064
38065
38066 /*
38067 ** Remove the page supplied as an argument from the hash table
@@ -38089,11 +37910,10 @@
38089 static void pcache1EnforceMaxPage(PGroup *pGroup){
38090 assert( sqlite3_mutex_held(pGroup->mutex) );
38091 while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
38092 PgHdr1 *p = pGroup->pLruTail;
38093 assert( p->pCache->pGroup==pGroup );
38094 assert( p->isPinned==0 );
38095 pcache1PinPage(p);
38096 pcache1RemoveFromHash(p);
38097 pcache1FreePage(p);
38098 }
38099 }
@@ -38117,11 +37937,11 @@
38117 PgHdr1 *pPage;
38118 while( (pPage = *pp)!=0 ){
38119 if( pPage->iKey>=iLimit ){
38120 pCache->nPage--;
38121 *pp = pPage->pNext;
38122 if( !pPage->isPinned ) pcache1PinPage(pPage);
38123 pcache1FreePage(pPage);
38124 }else{
38125 pp = &pPage->pNext;
38126 TESTONLY( nPage++; )
38127 }
@@ -38340,15 +38160,12 @@
38340 unsigned int h = iKey % pCache->nHash;
38341 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
38342 }
38343
38344 /* Step 2: Abort if no existing page is found and createFlag is 0 */
38345 if( pPage ){
38346 if( !pPage->isPinned ) pcache1PinPage(pPage);
38347 goto fetch_out;
38348 }
38349 if( createFlag==0 ){
38350 goto fetch_out;
38351 }
38352
38353 /* The pGroup local variable will normally be initialized by the
38354 ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined,
@@ -38385,11 +38202,10 @@
38385 || pGroup->nCurrentPage>=pGroup->nMaxPage
38386 || pcache1UnderMemoryPressure(pCache)
38387 )){
38388 PCache1 *pOther;
38389 pPage = pGroup->pLruTail;
38390 assert( pPage->isPinned==0 );
38391 pcache1RemoveFromHash(pPage);
38392 pcache1PinPage(pPage);
38393 pOther = pPage->pCache;
38394
38395 /* We want to verify that szPage and szExtra are the same for pOther
@@ -38422,11 +38238,10 @@
38422 pPage->iKey = iKey;
38423 pPage->pNext = pCache->apHash[h];
38424 pPage->pCache = pCache;
38425 pPage->pLruPrev = 0;
38426 pPage->pLruNext = 0;
38427 pPage->isPinned = 1;
38428 *(void **)pPage->page.pExtra = 0;
38429 pCache->apHash[h] = pPage;
38430 }
38431
38432 fetch_out:
@@ -38458,11 +38273,10 @@
38458 /* It is an error to call this function if the page is already
38459 ** part of the PGroup LRU list.
38460 */
38461 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
38462 assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
38463 assert( pPage->isPinned==1 );
38464
38465 if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
38466 pcache1RemoveFromHash(pPage);
38467 pcache1FreePage(pPage);
38468 }else{
@@ -38474,11 +38288,10 @@
38474 }else{
38475 pGroup->pLruTail = pPage;
38476 pGroup->pLruHead = pPage;
38477 }
38478 pCache->nRecyclable++;
38479 pPage->isPinned = 0;
38480 }
38481
38482 pcache1LeaveMutex(pCache->pGroup);
38483 }
38484
@@ -38601,11 +38414,10 @@
38601 while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
38602 nFree += pcache1MemSize(p->page.pBuf);
38603 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
38604 nFree += sqlite3MemSize(p);
38605 #endif
38606 assert( p->isPinned==0 );
38607 pcache1PinPage(p);
38608 pcache1RemoveFromHash(p);
38609 pcache1FreePage(p);
38610 }
38611 pcache1LeaveMutex(&pcache1.grp);
@@ -38626,11 +38438,10 @@
38626 int *pnRecyclable /* OUT: Total number of pages available for recycling */
38627 ){
38628 PgHdr1 *p;
38629 int nRecyclable = 0;
38630 for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
38631 assert( p->isPinned==0 );
38632 nRecyclable++;
38633 }
38634 *pnCurrent = pcache1.grp.nCurrentPage;
38635 *pnMax = (int)pcache1.grp.nMaxPage;
38636 *pnMin = (int)pcache1.grp.nMinPage;
@@ -40313,26 +40124,29 @@
40313 ** PagerSavepoint.pInSavepoint.
40314 */
40315 static int subjRequiresPage(PgHdr *pPg){
40316 Pager *pPager = pPg->pPager;
40317 PagerSavepoint *p;
40318 Pgno pgno = pPg->pgno;
40319 int i;
40320 for(i=0; i<pPager->nSavepoint; i++){
40321 p = &pPager->aSavepoint[i];
40322 if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40323 return 1;
 
 
 
40324 }
40325 }
40326 return 0;
40327 }
40328
40329 /*
40330 ** Return true if the page is already in the journal file.
40331 */
40332 static int pageInJournal(Pager *pPager, PgHdr *pPg){
40333 return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno);
40334 }
40335
40336 /*
40337 ** Read a 32-bit integer from the given file descriptor. Store the integer
40338 ** that is read in *pRes. Return SQLITE_OK if everything worked, or an
@@ -40535,11 +40349,10 @@
40535
40536 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
40537 || szJ<16
40538 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
40539 || len>=nMaster
40540 || len==0
40541 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
40542 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
40543 || memcmp(aMagic, aJournalMagic, 8)
40544 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
40545 ){
@@ -41276,11 +41089,11 @@
41276 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
41277 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
41278 PgHdr *p = pager_lookup(pPager, 1);
41279 if( p ){
41280 p->pageHash = 0;
41281 sqlite3PagerUnrefNotNull(p);
41282 }
41283 }
41284 #endif
41285
41286 sqlite3BitvecDestroy(pPager->pInJournal);
@@ -41305,15 +41118,10 @@
41305 ** required size. */
41306 assert( pPager->eLock==EXCLUSIVE_LOCK );
41307 rc = pager_truncate(pPager, pPager->dbSize);
41308 }
41309
41310 if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){
41311 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
41312 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
41313 }
41314
41315 if( !pPager->exclusiveMode
41316 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
41317 ){
41318 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
41319 pPager->changeCountDone = 0;
@@ -42123,11 +41931,11 @@
42123 testcase( rc!=SQLITE_OK );
42124 }
42125 if( rc==SQLITE_OK
42126 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
42127 ){
42128 rc = sqlite3PagerSync(pPager, 0);
42129 }
42130 if( rc==SQLITE_OK ){
42131 rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
42132 testcase( rc!=SQLITE_OK );
42133 }
@@ -42269,11 +42077,11 @@
42269 rc = readDbPage(pPg, iFrame);
42270 }
42271 if( rc==SQLITE_OK ){
42272 pPager->xReiniter(pPg);
42273 }
42274 sqlite3PagerUnrefNotNull(pPg);
42275 }
42276 }
42277
42278 /* Normally, if a transaction is rolled back, any backup processes are
42279 ** updated as data is copied out of the rollback journal and into the
@@ -43624,11 +43432,11 @@
43624 /* Open the sub-journal, if it has not already been opened */
43625 assert( pPager->useJournal );
43626 assert( isOpen(pPager->jfd) || pagerUseWal(pPager) );
43627 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
43628 assert( pagerUseWal(pPager)
43629 || pageInJournal(pPager, pPg)
43630 || pPg->pgno>pPager->dbOrigSize
43631 );
43632 rc = openSubJournal(pPager);
43633
43634 /* If the sub-journal was opened successfully (or was already open),
@@ -44089,34 +43897,10 @@
44089 *ppPager = pPager;
44090 return SQLITE_OK;
44091 }
44092
44093
44094 /* Verify that the database file has not be deleted or renamed out from
44095 ** under the pager. Return SQLITE_OK if the database is still were it ought
44096 ** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error
44097 ** code from sqlite3OsAccess()) if the database has gone missing.
44098 */
44099 static int databaseIsUnmoved(Pager *pPager){
44100 int bHasMoved = 0;
44101 int rc;
44102
44103 if( pPager->tempFile ) return SQLITE_OK;
44104 if( pPager->dbSize==0 ) return SQLITE_OK;
44105 assert( pPager->zFilename && pPager->zFilename[0] );
44106 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved);
44107 if( rc==SQLITE_NOTFOUND ){
44108 /* If the HAS_MOVED file-control is unimplemented, assume that the file
44109 ** has not been moved. That is the historical behavior of SQLite: prior to
44110 ** version 3.8.3, it never checked */
44111 rc = SQLITE_OK;
44112 }else if( rc==SQLITE_OK && bHasMoved ){
44113 rc = SQLITE_READONLY_DBMOVED;
44114 }
44115 return rc;
44116 }
44117
44118
44119 /*
44120 ** This function is called after transitioning from PAGER_UNLOCK to
44121 ** PAGER_SHARED state. It tests if there is a hot journal present in
44122 ** the file-system for the given pager. A hot journal is one that
@@ -44584,11 +44368,11 @@
44584 if( bMmapOk && pagerUseWal(pPager) ){
44585 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
44586 if( rc!=SQLITE_OK ) goto pager_acquire_err;
44587 }
44588
44589 if( bMmapOk && iFrame==0 ){
44590 void *pData = 0;
44591
44592 rc = sqlite3OsFetch(pPager->fd,
44593 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
44594 );
@@ -44725,23 +44509,20 @@
44725 ** If the number of references to the page drop to zero, then the
44726 ** page is added to the LRU list. When all references to all pages
44727 ** are released, a rollback occurs and the lock on the database is
44728 ** removed.
44729 */
44730 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
44731 Pager *pPager;
44732 assert( pPg!=0 );
44733 pPager = pPg->pPager;
44734 if( pPg->flags & PGHDR_MMAP ){
44735 pagerReleaseMapPage(pPg);
44736 }else{
44737 sqlite3PcacheRelease(pPg);
44738 }
44739 pagerUnlockIfUnused(pPager);
44740 }
44741 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
44742 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
 
 
 
 
 
 
 
 
44743 }
44744
44745 /*
44746 ** This function is called at the start of every write transaction.
44747 ** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -44792,23 +44573,17 @@
44792 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
44793 (pPager->tempFile ?
44794 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
44795 (SQLITE_OPEN_MAIN_JOURNAL)
44796 );
44797
44798 /* Verify that the database still has the same name as it did when
44799 ** it was originally opened. */
44800 rc = databaseIsUnmoved(pPager);
44801 if( rc==SQLITE_OK ){
44802 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
44803 rc = sqlite3JournalOpen(
44804 pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44805 );
44806 #else
44807 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44808 #endif
44809 }
44810 }
44811 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
44812 }
44813
44814
@@ -44925,13 +44700,13 @@
44925 ** one of the journals, the corresponding bit is set in the
44926 ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
44927 ** of any open savepoints as appropriate.
44928 */
44929 static int pager_write(PgHdr *pPg){
 
44930 Pager *pPager = pPg->pPager;
44931 int rc = SQLITE_OK;
44932 int inJournal;
44933
44934 /* This routine is not called unless a write-transaction has already
44935 ** been started. The journal file may or may not be open at this point.
44936 ** It is never called in the ERROR state.
44937 */
@@ -44938,12 +44713,18 @@
44938 assert( pPager->eState==PAGER_WRITER_LOCKED
44939 || pPager->eState==PAGER_WRITER_CACHEMOD
44940 || pPager->eState==PAGER_WRITER_DBMOD
44941 );
44942 assert( assert_pager_state(pPager) );
44943 assert( pPager->errCode==0 );
44944 assert( pPager->readOnly==0 );
 
 
 
 
 
 
44945
44946 CHECK_PAGE(pPg);
44947
44948 /* The journal file needs to be opened. Higher level routines have already
44949 ** obtained the necessary locks to begin the write-transaction, but the
@@ -44963,20 +44744,19 @@
44963
44964 /* Mark the page as dirty. If the page has already been written
44965 ** to the journal then we can return right away.
44966 */
44967 sqlite3PcacheMakeDirty(pPg);
44968 inJournal = pageInJournal(pPager, pPg);
44969 if( inJournal && (pPager->nSavepoint==0 || !subjRequiresPage(pPg)) ){
44970 assert( !pagerUseWal(pPager) );
44971 }else{
44972
44973 /* The transaction journal now exists and we have a RESERVED or an
44974 ** EXCLUSIVE lock on the main database file. Write the current page to
44975 ** the transaction journal if it is not there already.
44976 */
44977 if( !inJournal && !pagerUseWal(pPager) ){
44978 assert( pagerUseWal(pPager)==0 );
44979 if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){
44980 u32 cksum;
44981 char *pData2;
44982 i64 iOff = pPager->journalOff;
@@ -44985,11 +44765,11 @@
44985 ** contains the database locks. The following assert verifies
44986 ** that we do not. */
44987 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
44988
44989 assert( pPager->journalHdr<=pPager->journalOff );
44990 CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
44991 cksum = pager_cksum(pPager, (u8*)pData2);
44992
44993 /* Even if an IO or diskfull error occurs while journalling the
44994 ** page in the block above, set the need-sync flag for the page.
44995 ** Otherwise, when the transaction is rolled back, the logic in
@@ -45037,11 +44817,11 @@
45037 /* If the statement journal is open and the page is not in it,
45038 ** then write the current page to the statement journal. Note that
45039 ** the statement journal format differs from the standard journal format
45040 ** in that it omits the checksums and the header.
45041 */
45042 if( pPager->nSavepoint>0 && subjRequiresPage(pPg) ){
45043 rc = subjournalPage(pPg);
45044 }
45045 }
45046
45047 /* Update the database size and return.
@@ -45069,23 +44849,23 @@
45069 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
45070 int rc = SQLITE_OK;
45071
45072 PgHdr *pPg = pDbPage;
45073 Pager *pPager = pPg->pPager;
 
45074
45075 assert( (pPg->flags & PGHDR_MMAP)==0 );
45076 assert( pPager->eState>=PAGER_WRITER_LOCKED );
45077 assert( pPager->eState!=PAGER_ERROR );
45078 assert( assert_pager_state(pPager) );
45079
45080 if( pPager->sectorSize > (u32)pPager->pageSize ){
45081 Pgno nPageCount; /* Total number of pages in database file */
45082 Pgno pg1; /* First page of the sector pPg is located on. */
45083 int nPage = 0; /* Number of pages starting at pg1 to journal */
45084 int ii; /* Loop counter */
45085 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
45086 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
45087
45088 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
45089 ** a journal header to be written between the pages journaled by
45090 ** this function.
45091 */
@@ -45120,18 +44900,18 @@
45120 if( rc==SQLITE_OK ){
45121 rc = pager_write(pPage);
45122 if( pPage->flags&PGHDR_NEED_SYNC ){
45123 needSync = 1;
45124 }
45125 sqlite3PagerUnrefNotNull(pPage);
45126 }
45127 }
45128 }else if( (pPage = pager_lookup(pPager, pg))!=0 ){
45129 if( pPage->flags&PGHDR_NEED_SYNC ){
45130 needSync = 1;
45131 }
45132 sqlite3PagerUnrefNotNull(pPage);
45133 }
45134 }
45135
45136 /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
45137 ** starting at pg1, then it needs to be set for all of them. Because
@@ -45143,11 +44923,11 @@
45143 assert( !MEMDB );
45144 for(ii=0; ii<nPage; ii++){
45145 PgHdr *pPage = pager_lookup(pPager, pg1+ii);
45146 if( pPage ){
45147 pPage->flags |= PGHDR_NEED_SYNC;
45148 sqlite3PagerUnrefNotNull(pPage);
45149 }
45150 }
45151 }
45152
45153 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
@@ -45296,21 +45076,21 @@
45296 ** or pages with the Pager.noSync flag set.
45297 **
45298 ** If successful, or if called on a pager for which it is a no-op, this
45299 ** function returns SQLITE_OK. Otherwise, an IO error code is returned.
45300 */
45301 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){
45302 int rc = SQLITE_OK;
45303
45304 if( isOpen(pPager->fd) ){
45305 void *pArg = (void*)zMaster;
45306 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
45307 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
45308 }
45309 if( rc==SQLITE_OK && !pPager->noSync ){
45310 assert( !MEMDB );
45311 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
 
 
 
 
 
 
45312 }
45313 return rc;
45314 }
45315
45316 /*
@@ -45505,11 +45285,11 @@
45505 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
45506 }
45507
45508 /* Finally, sync the database file. */
45509 if( !noSync ){
45510 rc = sqlite3PagerSync(pPager, zMaster);
45511 }
45512 IOTRACE(("DBSYNC %p\n", pPager))
45513 }
45514 }
45515
@@ -45634,13 +45414,11 @@
45634 rc = pager_playback(pPager, 0);
45635 }
45636
45637 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
45638 assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT
45639 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
45640 || rc==SQLITE_CANTOPEN
45641 );
45642
45643 /* If an error occurs during a ROLLBACK, we can no longer trust the pager
45644 ** cache. So call pager_error() on the way out to make any error persistent.
45645 */
45646 return pager_error(pPager, rc);
@@ -46039,11 +45817,11 @@
46039 ** can be written to. The caller has already promised not to write to it.
46040 */
46041 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
46042 needSyncPgno = pPg->pgno;
46043 assert( pPager->journalMode==PAGER_JOURNALMODE_OFF ||
46044 pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
46045 assert( pPg->flags&PGHDR_DIRTY );
46046 }
46047
46048 /* If the cache contains a page with page-number pgno, remove it
46049 ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
@@ -46073,11 +45851,11 @@
46073 ** as the original page since it has already been allocated.
46074 */
46075 if( MEMDB ){
46076 assert( pPgOld );
46077 sqlite3PcacheMove(pPgOld, origPgno);
46078 sqlite3PagerUnrefNotNull(pPgOld);
46079 }
46080
46081 if( needSyncPgno ){
46082 /* If needSyncPgno is non-zero, then the journal file needs to be
46083 ** sync()ed before any data is written to database file page needSyncPgno.
@@ -46102,11 +45880,11 @@
46102 }
46103 return rc;
46104 }
46105 pPgHdr->flags |= PGHDR_NEED_SYNC;
46106 sqlite3PcacheMakeDirty(pPgHdr);
46107 sqlite3PagerUnrefNotNull(pPgHdr);
46108 }
46109
46110 return SQLITE_OK;
46111 }
46112 #endif
@@ -52221,11 +51999,11 @@
52221
52222 if( pgno>btreePagecount(pBt) ){
52223 rc = SQLITE_CORRUPT_BKPT;
52224 }else{
52225 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
52226 if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){
52227 rc = btreeInitPage(*ppPage);
52228 if( rc!=SQLITE_OK ){
52229 releasePage(*ppPage);
52230 }
52231 }
@@ -52242,15 +52020,14 @@
52242 */
52243 static void releasePage(MemPage *pPage){
52244 if( pPage ){
52245 assert( pPage->aData );
52246 assert( pPage->pBt );
52247 assert( pPage->pDbPage!=0 );
52248 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
52249 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
52250 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52251 sqlite3PagerUnrefNotNull(pPage->pDbPage);
52252 }
52253 }
52254
52255 /*
52256 ** During a rollback, when the pager reloads information into the cache
@@ -54762,14 +54539,14 @@
54762 }
54763
54764 /*
54765 ** Return a pointer to payload information from the entry that the
54766 ** pCur cursor is pointing to. The pointer is to the beginning of
54767 ** the key if index btrees (pPage->intKey==0) and is the data for
54768 ** table btrees (pPage->intKey==1). The number of bytes of available
54769 ** key/data is written into *pAmt. If *pAmt==0, then the value
54770 ** returned will not be a valid pointer.
54771 **
54772 ** This routine is an optimization. It is common for the entire key
54773 ** and data to fit on the local page and for there to be no overflow
54774 ** pages. When that is so, this routine can be used to access the
54775 ** key and data without making a copy. If the key and/or data spills
@@ -54778,25 +54555,45 @@
54778 **
54779 ** The pointer returned by this routine looks directly into the cached
54780 ** page of the database. The data might change or move the next time
54781 ** any btree routine is called.
54782 */
54783 static const void *fetchPayload(
54784 BtCursor *pCur, /* Cursor pointing to entry to read from */
54785 u32 *pAmt /* Write the number of available bytes here */
 
54786 ){
 
 
 
 
 
54787 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
54788 assert( pCur->eState==CURSOR_VALID );
54789 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54790 assert( cursorHoldsMutex(pCur) );
54791 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
 
54792 if( pCur->info.nSize==0 ){
54793 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
54794 &pCur->info);
54795 }
54796 *pAmt = pCur->info.nLocal;
54797 return (void*)(pCur->info.pCell + pCur->info.nHeader);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54798 }
54799
54800
54801 /*
54802 ** For the entry that cursor pCur is point to, return as
@@ -54811,14 +54608,26 @@
54811 **
54812 ** These routines is used to get quick access to key and data
54813 ** in the common case where no overflow pages are used.
54814 */
54815 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
54816 return fetchPayload(pCur, pAmt);
 
 
 
 
 
 
54817 }
54818 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
54819 return fetchPayload(pCur, pAmt);
 
 
 
 
 
 
54820 }
54821
54822
54823 /*
54824 ** Move the cursor down to a new child page. The newPgno argument is the
@@ -54933,10 +54742,12 @@
54933 ** b-tree).
54934 */
54935 static int moveToRoot(BtCursor *pCur){
54936 MemPage *pRoot;
54937 int rc = SQLITE_OK;
 
 
54938
54939 assert( cursorHoldsMutex(pCur) );
54940 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
54941 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
54942 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54947,16 +54758,20 @@
54947 }
54948 sqlite3BtreeClearCursor(pCur);
54949 }
54950
54951 if( pCur->iPage>=0 ){
54952 while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]);
 
 
 
 
54953 }else if( pCur->pgnoRoot==0 ){
54954 pCur->eState = CURSOR_INVALID;
54955 return SQLITE_OK;
54956 }else{
54957 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
54958 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
54959 if( rc!=SQLITE_OK ){
54960 pCur->eState = CURSOR_INVALID;
54961 return rc;
54962 }
@@ -54985,20 +54800,18 @@
54985 pCur->aiIdx[0] = 0;
54986 pCur->info.nSize = 0;
54987 pCur->atLast = 0;
54988 pCur->validNKey = 0;
54989
54990 if( pRoot->nCell>0 ){
54991 pCur->eState = CURSOR_VALID;
54992 }else if( !pRoot->leaf ){
54993 Pgno subpage;
54994 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
54995 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
54996 pCur->eState = CURSOR_VALID;
54997 rc = moveToChild(pCur, subpage);
54998 }else{
54999 pCur->eState = CURSOR_INVALID;
55000 }
55001 return rc;
55002 }
55003
55004 /*
@@ -55250,18 +55063,21 @@
55250 ** the entire cell by checking for the cases where the record is
55251 ** stored entirely within the b-tree page by inspecting the first
55252 ** 2 bytes of the cell.
55253 */
55254 nCell = pCell[0];
55255 if( nCell<=pPage->max1bytePayload ){
 
 
55256 /* This branch runs if the record-size field of the cell is a
55257 ** single byte varint and the record fits entirely on the main
55258 ** b-tree page. */
55259 testcase( pCell+nCell+1==pPage->aDataEnd );
55260 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55261 }else if( !(pCell[1] & 0x80)
55262 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
 
55263 ){
55264 /* The record-size field is a 2 byte varint and the record
55265 ** fits entirely on the main b-tree page. */
55266 testcase( pCell+nCell+2==pPage->aDataEnd );
55267 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -56081,11 +55897,11 @@
56081 nHeader = 0;
56082 if( !pPage->leaf ){
56083 nHeader += 4;
56084 }
56085 if( pPage->hasData ){
56086 nHeader += putVarint32(&pCell[nHeader], nData+nZero);
56087 }else{
56088 nData = nZero = 0;
56089 }
56090 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
56091 btreeParseCellPtr(pPage, pCell, &info);
@@ -56209,10 +56025,11 @@
56209 */
56210 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
56211 u32 pc; /* Offset to cell content of cell being deleted */
56212 u8 *data; /* pPage->aData */
56213 u8 *ptr; /* Used to move bytes around within data[] */
 
56214 int rc; /* The return code */
56215 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
56216
56217 if( *pRC ) return;
56218
@@ -56232,13 +56049,18 @@
56232 }
56233 rc = freeSpace(pPage, pc, sz);
56234 if( rc ){
56235 *pRC = rc;
56236 return;
 
 
 
 
 
 
56237 }
56238 pPage->nCell--;
56239 memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
56240 put2byte(&data[hdr+3], pPage->nCell);
56241 pPage->nFree += 2;
56242 }
56243
56244 /*
@@ -56271,10 +56093,13 @@
56271 int j; /* Loop counter */
56272 int end; /* First byte past the last cell pointer in data[] */
56273 int ins; /* Index in data[] where new cell pointer is inserted */
56274 int cellOffset; /* Address of first cell pointer in data[] */
56275 u8 *data; /* The content of the whole page */
 
 
 
56276 int nSkip = (iChild ? 4 : 0);
56277
56278 if( *pRC ) return;
56279
56280 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56321,11 +56146,17 @@
56321 pPage->nFree -= (u16)(2 + sz);
56322 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
56323 if( iChild ){
56324 put4byte(&data[idx], iChild);
56325 }
56326 memmove(&data[ins+2], &data[ins], end-ins);
 
 
 
 
 
 
56327 put2byte(&data[ins], idx);
56328 put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
56329 #ifndef SQLITE_OMIT_AUTOVACUUM
56330 if( pPage->pBt->autoVacuum ){
56331 /* The cell may contain a pointer to an overflow page. If so, write
@@ -58283,11 +58114,11 @@
58283 va_start(ap, zFormat);
58284 if( pCheck->errMsg.nChar ){
58285 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
58286 }
58287 if( zMsg1 ){
58288 sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1);
58289 }
58290 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
58291 va_end(ap);
58292 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
58293 pCheck->mallocFailed = 1;
@@ -59577,11 +59408,11 @@
59577 rc = backupTruncateFile(pFile, iSize);
59578 }
59579
59580 /* Sync the database file to disk. */
59581 if( rc==SQLITE_OK ){
59582 rc = sqlite3PagerSync(pDestPager, 0);
59583 }
59584 }else{
59585 sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
59586 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
59587 }
@@ -59652,14 +59483,14 @@
59652 /* If a transaction is still open on the Btree, roll it back. */
59653 sqlite3BtreeRollback(p->pDest, SQLITE_OK);
59654
59655 /* Set the error code of the destination database handle. */
59656 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
 
 
 
59657 if( p->pDestDb ){
59658 sqlite3Error(p->pDestDb, rc, 0);
59659
59660 /* Exit the mutexes and free the backup context structure. */
59661 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
59662 }
59663 sqlite3BtreeLeave(p->pSrc);
59664 if( p->pDestDb ){
59665 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
@@ -59859,59 +59690,61 @@
59859 #endif
59860 }
59861
59862 /*
59863 ** Make sure pMem->z points to a writable allocation of at least
59864 ** min(n,32) bytes.
59865 **
59866 ** If the bPreserve argument is true, then copy of the content of
59867 ** pMem->z into the new allocation. pMem must be either a string or
59868 ** blob if bPreserve is true. If bPreserve is false, any prior content
59869 ** in pMem->z is discarded.
 
 
 
 
59870 */
59871 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
59872 assert( 1 >=
59873 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
59874 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
59875 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
59876 ((pMem->flags&MEM_Static) ? 1 : 0)
59877 );
59878 assert( (pMem->flags&MEM_RowSet)==0 );
59879
59880 /* If the bPreserve flag is set to true, then the memory cell must already
59881 ** contain a valid string or blob value. */
59882 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
59883 testcase( bPreserve && pMem->z==0 );
59884
59885 if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59886 if( n<32 ) n = 32;
59887 if( bPreserve && pMem->z==pMem->zMalloc ){
59888 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59889 bPreserve = 0;
59890 }else{
59891 sqlite3DbFree(pMem->db, pMem->zMalloc);
59892 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
59893 }
59894 if( pMem->zMalloc==0 ){
59895 sqlite3VdbeMemRelease(pMem);
59896 pMem->flags = MEM_Null;
59897 return SQLITE_NOMEM;
59898 }
59899 }
59900
59901 if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
59902 memcpy(pMem->zMalloc, pMem->z, pMem->n);
59903 }
59904 if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){
59905 assert( pMem->xDel!=SQLITE_DYNAMIC );
59906 pMem->xDel((void *)(pMem->z));
59907 }
59908
59909 pMem->z = pMem->zMalloc;
59910 pMem->flags &= ~(MEM_Ephem|MEM_Static);
 
 
 
 
59911 pMem->xDel = 0;
59912 return SQLITE_OK;
59913 }
59914
59915 /*
59916 ** Make the given Mem object MEM_Dyn. In other words, make it so
59917 ** that any TEXT or BLOB content is stored in memory obtained from
@@ -60093,16 +59926,14 @@
60093 ** inconsistent state, for example with (Mem.z==0) and
60094 ** (Mem.type==SQLITE_TEXT).
60095 */
60096 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60097 VdbeMemRelease(p);
60098 if( p->zMalloc ){
60099 sqlite3DbFree(p->db, p->zMalloc);
60100 p->zMalloc = 0;
60101 }
60102 p->z = 0;
60103 assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */
 
60104 }
60105
60106 /*
60107 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
60108 ** If the double is out of range of a 64-bit signed integer then
@@ -60282,13 +60113,10 @@
60282 sqlite3RowSetClear(pMem->u.pRowSet);
60283 }
60284 MemSetTypeFlag(pMem, MEM_Null);
60285 pMem->type = SQLITE_NULL;
60286 }
60287 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60288 sqlite3VdbeMemSetNull((Mem*)p);
60289 }
60290
60291 /*
60292 ** Delete any previous value and set the value to be a BLOB of length
60293 ** n containing all zeros.
60294 */
@@ -61022,11 +60850,11 @@
61022 if( aRet==0 ){
61023 sqlite3_result_error_nomem(context);
61024 }else{
61025 aRet[0] = nSerial+1;
61026 sqlite3PutVarint(&aRet[1], iSerial);
61027 sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
61028 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
61029 sqlite3DbFree(db, aRet);
61030 }
61031 }
61032
@@ -61207,12 +61035,11 @@
61207 */
61208
61209 /*
61210 ** Create a new virtual database engine.
61211 */
61212 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){
61213 sqlite3 *db = pParse->db;
61214 Vdbe *p;
61215 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
61216 if( p==0 ) return 0;
61217 p->db = db;
61218 if( db->pVdbe ){
@@ -61220,14 +61047,10 @@
61220 }
61221 p->pNext = db->pVdbe;
61222 p->pPrev = 0;
61223 db->pVdbe = p;
61224 p->magic = VDBE_MAGIC_INIT;
61225 p->pParse = pParse;
61226 assert( pParse->aLabel==0 );
61227 assert( pParse->nLabel==0 );
61228 assert( pParse->nOpAlloc==0 );
61229 return p;
61230 }
61231
61232 /*
61233 ** Remember the SQL string for a prepared statement.
@@ -61279,18 +61102,17 @@
61279 ** If an out-of-memory error occurs while resizing the array, return
61280 ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
61281 ** unchanged (this is so that any opcodes already allocated can be
61282 ** correctly deallocated along with the rest of the Vdbe).
61283 */
61284 static int growOpArray(Vdbe *v){
61285 VdbeOp *pNew;
61286 Parse *p = v->pParse;
61287 int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
61288 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
61289 if( pNew ){
61290 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
61291 v->aOp = pNew;
61292 }
61293 return (pNew ? SQLITE_OK : SQLITE_NOMEM);
61294 }
61295
61296 #ifdef SQLITE_DEBUG
@@ -61325,11 +61147,11 @@
61325 VdbeOp *pOp;
61326
61327 i = p->nOp;
61328 assert( p->magic==VDBE_MAGIC_INIT );
61329 assert( op>0 && op<0xff );
61330 if( p->pParse->nOpAlloc<=i ){
61331 if( growOpArray(p) ){
61332 return 1;
61333 }
61334 }
61335 p->nOp++;
@@ -61344,19 +61166,10 @@
61344 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61345 pOp->zComment = 0;
61346 #endif
61347 #ifdef SQLITE_DEBUG
61348 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61349 int jj, kk;
61350 Parse *pParse = p->pParse;
61351 for(jj=kk=0; jj<SQLITE_N_COLCACHE; jj++){
61352 struct yColCache *x = pParse->aColCache + jj;
61353 if( x->iLevel>pParse->iCacheLevel || x->iReg==0 ) continue;
61354 printf(" r[%d]={%d:%d}", x->iReg, x->iTable, x->iColumn);
61355 kk++;
61356 }
61357 if( kk ) printf("\n");
61358 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
61359 test_addop_breakpoint();
61360 }
61361 #endif
61362 #ifdef VDBE_PROFILE
@@ -61436,14 +61249,13 @@
61436 ** always negative and P2 values are suppose to be non-negative.
61437 ** Hence, a negative P2 value is a label that has yet to be resolved.
61438 **
61439 ** Zero is returned if a malloc() fails.
61440 */
61441 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){
61442 Parse *p = v->pParse;
61443 int i = p->nLabel++;
61444 assert( v->magic==VDBE_MAGIC_INIT );
61445 if( (i & (i-1))==0 ){
61446 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
61447 (i*2+1)*sizeof(p->aLabel[0]));
61448 }
61449 if( p->aLabel ){
@@ -61455,17 +61267,16 @@
61455 /*
61456 ** Resolve label "x" to be the address of the next instruction to
61457 ** be inserted. The parameter "x" must have been obtained from
61458 ** a prior call to sqlite3VdbeMakeLabel().
61459 */
61460 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
61461 Parse *p = v->pParse;
61462 int j = -1-x;
61463 assert( v->magic==VDBE_MAGIC_INIT );
61464 assert( j<p->nLabel );
61465 if( j>=0 && p->aLabel ){
61466 p->aLabel[j] = v->nOp;
61467 }
61468 }
61469
61470 /*
61471 ** Mark the VDBE as one that can only be run one time.
@@ -61610,12 +61421,11 @@
61610 */
61611 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
61612 int i;
61613 int nMaxArgs = *pMaxFuncArgs;
61614 Op *pOp;
61615 Parse *pParse = p->pParse;
61616 int *aLabel = pParse->aLabel;
61617 p->readOnly = 1;
61618 p->bIsReader = 0;
61619 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
61620 u8 opcode = pOp->opcode;
61621
@@ -61674,17 +61484,16 @@
61674 }
61675 }
61676
61677 pOp->opflags = sqlite3OpcodeProperty[opcode];
61678 if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
61679 assert( -1-pOp->p2<pParse->nLabel );
61680 pOp->p2 = aLabel[-1-pOp->p2];
61681 }
61682 }
61683 sqlite3DbFree(p->db, pParse->aLabel);
61684 pParse->aLabel = 0;
61685 pParse->nLabel = 0;
61686 *pMaxFuncArgs = nMaxArgs;
61687 assert( p->bIsReader!=0 || p->btreeMask==0 );
61688 }
61689
61690 /*
@@ -61724,11 +61533,11 @@
61724 ** address of the first operation added.
61725 */
61726 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61727 int addr;
61728 assert( p->magic==VDBE_MAGIC_INIT );
61729 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
61730 return 0;
61731 }
61732 addr = p->nOp;
61733 if( ALWAYS(nOp>0) ){
61734 int i;
@@ -61913,17 +61722,10 @@
61913 pOp->opcode = OP_Noop;
61914 if( addr==p->nOp-1 ) p->nOp--;
61915 }
61916 }
61917
61918 /*
61919 ** Remove the last opcode inserted
61920 */
61921 SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){
61922 p->nOp--;
61923 }
61924
61925 /*
61926 ** Change the value of the P4 operand for a specific instruction.
61927 ** This routine is useful when a large program is loaded from a
61928 ** static array using sqlite3VdbeAddOpList but we want to make a
61929 ** few minor changes to the program.
@@ -62085,21 +61887,11 @@
62085 if( c=='4' ) return pOp->p4.i;
62086 return pOp->p5;
62087 }
62088
62089 /*
62090 ** Compute a string for the "comment" field of a VDBE opcode listing.
62091 **
62092 ** The Synopsis: field in comments in the vdbe.c source file gets converted
62093 ** to an extra string that is appended to the sqlite3OpcodeName(). In the
62094 ** absence of other comments, this synopsis becomes the comment on the opcode.
62095 ** Some translation occurs:
62096 **
62097 ** "PX" -> "r[X]"
62098 ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1
62099 ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0
62100 ** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x
62101 */
62102 static int displayComment(
62103 const Op *pOp, /* The opcode to be commented */
62104 const char *zP4, /* Previously obtained value for P4 */
62105 char *zTemp, /* Write result here */
@@ -62129,17 +61921,11 @@
62129 sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
62130 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
62131 ii += 3;
62132 jj += sqlite3Strlen30(zTemp+jj);
62133 v2 = translateP(zSynopsis[ii], pOp);
62134 if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){
62135 ii += 2;
62136 v2++;
62137 }
62138 if( v2>1 ){
62139 sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
62140 }
62141 }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
62142 ii += 4;
62143 }
62144 }
62145 jj += sqlite3Strlen30(zTemp+jj);
@@ -62367,13 +62153,10 @@
62367 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62368 displayComment(pOp, zP4, zCom, sizeof(zCom));
62369 #else
62370 zCom[0] = 0
62371 #endif
62372 /* NB: The sqlite3OpcodeName() function is implemented by code created
62373 ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
62374 ** information from the vdbe.c source text */
62375 fprintf(pOut, zFormat1, pc,
62376 sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
62377 zCom
62378 );
62379 fflush(pOut);
@@ -62801,11 +62584,10 @@
62801
62802 assert( p!=0 );
62803 assert( p->nOp>0 );
62804 assert( pParse!=0 );
62805 assert( p->magic==VDBE_MAGIC_INIT );
62806 assert( pParse==p->pParse );
62807 db = p->db;
62808 assert( db->mallocFailed==0 );
62809 nVar = pParse->nVar;
62810 nMem = pParse->nMem;
62811 nCursor = pParse->nTab;
@@ -62825,12 +62607,12 @@
62825 nMem += nCursor;
62826
62827 /* Allocate space for memory registers, SQL variables, VDBE cursors and
62828 ** an array to marshal SQL function arguments in.
62829 */
62830 zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62831 zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */
62832
62833 resolveP2Values(p, &nArg);
62834 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
62835 if( pParse->explain && nMem<10 ){
62836 nMem = 10;
@@ -63653,11 +63435,10 @@
63653 sqlite3 *db = p->db;
63654 int rc = p->rc;
63655 if( p->zErrMsg ){
63656 u8 mallocFailed = db->mallocFailed;
63657 sqlite3BeginBenignMalloc();
63658 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
63659 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
63660 sqlite3EndBenignMalloc();
63661 db->mallocFailed = mallocFailed;
63662 db->errCode = rc;
63663 }else{
@@ -63722,11 +63503,12 @@
63722 }else if( p->rc && p->expired ){
63723 /* The expired flag was set on the VDBE before the first call
63724 ** to sqlite3_step(). For consistency (since sqlite3_step() was
63725 ** called), set the database error in this case as well.
63726 */
63727 sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
 
63728 sqlite3DbFree(db, p->zErrMsg);
63729 p->zErrMsg = 0;
63730 }
63731
63732 /* Reclaim all memory used by the VDBE
@@ -63829,10 +63611,11 @@
63829 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
63830 sqlite3DbFree(db, pSub);
63831 }
63832 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
63833 vdbeFreeOpArray(db, p->aOp, p->nOp);
 
63834 sqlite3DbFree(db, p->aColName);
63835 sqlite3DbFree(db, p->zSql);
63836 sqlite3DbFree(db, p->pFree);
63837 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
63838 sqlite3DbFree(db, p->zExplain);
@@ -64059,19 +63842,25 @@
64059 /*
64060 ** Write the serialized data blob for the value stored in pMem into
64061 ** buf. It is assumed that the caller has allocated sufficient space.
64062 ** Return the number of bytes written.
64063 **
64064 ** nBuf is the amount of space left in buf[]. The caller is responsible
64065 ** for allocating enough space to buf[] to hold the entire field, exclusive
64066 ** of the pMem->u.nZero bytes for a MEM_Zero value.
 
 
 
 
 
64067 **
64068 ** Return the number of bytes actually written into buf[]. The number
64069 ** of bytes in the zero-filled tail is included in the return value only
64070 ** if those bytes were zeroed in buf[].
64071 */
64072 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){
 
64073 u32 len;
64074
64075 /* Integer and Real */
64076 if( serial_type<=7 && serial_type>0 ){
64077 u64 v;
@@ -64082,10 +63871,11 @@
64082 swapMixedEndianFloat(v);
64083 }else{
64084 v = pMem->u.i;
64085 }
64086 len = i = sqlite3VdbeSerialTypeLen(serial_type);
 
64087 while( i-- ){
64088 buf[i] = (u8)(v&0xFF);
64089 v >>= 8;
64090 }
64091 return len;
@@ -64093,12 +63883,21 @@
64093
64094 /* String or blob */
64095 if( serial_type>=12 ){
64096 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
64097 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
 
64098 len = pMem->n;
64099 memcpy(buf, pMem->z, len);
 
 
 
 
 
 
 
 
64100 return len;
64101 }
64102
64103 /* NULL or constants 0 or 1 */
64104 return 0;
@@ -65095,21 +64894,20 @@
65095 && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
65096 sqlite3_reset(pStmt);
65097 v->doingRerun = 1;
65098 assert( v->expired==0 );
65099 }
65100 if( rc2!=SQLITE_OK ){
65101 /* This case occurs after failing to recompile an sql statement.
65102 ** The error message from the SQL compiler has already been loaded
65103 ** into the database handle. This block copies the error message
65104 ** from the database handle into the statement and sets the statement
65105 ** program counter to 0 to ensure that when the statement is
65106 ** finalized or reset the parser error message is available via
65107 ** sqlite3_errmsg() and sqlite3_errcode().
65108 */
65109 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
65110 assert( zErr!=0 || db->mallocFailed );
65111 sqlite3DbFree(db, v->zErrMsg);
65112 if( !db->mallocFailed ){
65113 v->zErrMsg = sqlite3DbStrDup(db, zErr);
65114 v->rc = rc2;
65115 } else {
@@ -66021,11 +65819,10 @@
66021 if( db->nVdbeExec>1 ){
66022 while( *zRawSql ){
66023 const char *zStart = zRawSql;
66024 while( *(zRawSql++)!='\n' && *zRawSql );
66025 sqlite3StrAccumAppend(&out, "-- ", 3);
66026 assert( (zRawSql - zStart) > 0 );
66027 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
66028 }
66029 }else{
66030 while( zRawSql[0] ){
66031 n = findNextHostParameter(zRawSql, &nToken);
@@ -66054,13 +65851,13 @@
66054 assert( idx>0 && idx<=p->nVar );
66055 pVar = &p->aVar[idx-1];
66056 if( pVar->flags & MEM_Null ){
66057 sqlite3StrAccumAppend(&out, "NULL", 4);
66058 }else if( pVar->flags & MEM_Int ){
66059 sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
66060 }else if( pVar->flags & MEM_Real ){
66061 sqlite3XPrintf(&out, 0, "%!.15g", pVar->r);
66062 }else if( pVar->flags & MEM_Str ){
66063 int nOut; /* Number of bytes of the string text to include in output */
66064 #ifndef SQLITE_OMIT_UTF16
66065 u8 enc = ENC(db);
66066 Mem utf8;
@@ -66077,37 +65874,33 @@
66077 if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
66078 nOut = SQLITE_TRACE_SIZE_LIMIT;
66079 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
66080 }
66081 #endif
66082 sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z);
66083 #ifdef SQLITE_TRACE_SIZE_LIMIT
66084 if( nOut<pVar->n ){
66085 sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66086 }
66087 #endif
66088 #ifndef SQLITE_OMIT_UTF16
66089 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
66090 #endif
66091 }else if( pVar->flags & MEM_Zero ){
66092 sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero);
66093 }else{
66094 int nOut; /* Number of bytes of the blob to include in output */
66095 assert( pVar->flags & MEM_Blob );
66096 sqlite3StrAccumAppend(&out, "x'", 2);
66097 nOut = pVar->n;
66098 #ifdef SQLITE_TRACE_SIZE_LIMIT
66099 if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
66100 #endif
66101 for(i=0; i<nOut; i++){
66102 sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff);
66103 }
66104 sqlite3StrAccumAppend(&out, "'", 1);
66105 #ifdef SQLITE_TRACE_SIZE_LIMIT
66106 if( nOut<pVar->n ){
66107 sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66108 }
66109 #endif
66110 }
66111 }
66112 }
66113 return sqlite3StrAccumFinish(&out);
@@ -66162,11 +65955,11 @@
66162 int n = p->nIndent;
66163 if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
66164 sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
66165 }
66166 va_start(ap, zFormat);
66167 sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap);
66168 va_end(ap);
66169 }
66170 }
66171
66172 /*
@@ -66869,11 +66662,433 @@
66869 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66870 #ifdef VDBE_PROFILE
66871 u64 start; /* CPU clock count at start of opcode */
66872 int origPc; /* Program counter at start of opcode */
66873 #endif
66874 /*** INSERT STACK UNION HERE ***/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66875
66876 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
66877 sqlite3VdbeEnter(p);
66878 if( p->rc==SQLITE_NOMEM ){
66879 /* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67115,18 +67330,20 @@
67115 /* Opcode: Yield P1 * * * *
67116 **
67117 ** Swap the program counter with the value in register P1.
67118 */
67119 case OP_Yield: { /* in1 */
 
67120 int pcDest;
 
67121 pIn1 = &aMem[pOp->p1];
67122 assert( (pIn1->flags & MEM_Dyn)==0 );
67123 pIn1->flags = MEM_Int;
67124 pcDest = (int)pIn1->u.i;
67125 pIn1->u.i = pc;
67126 REGISTER_TRACE(pOp->p1, pIn1);
67127 pc = pcDest;
67128 break;
67129 }
67130
67131 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67132 ** Synopsis: if r[P3] null then halt
@@ -67171,12 +67388,14 @@
67171 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
67172 ** every program. So a jump past the last instruction of the program
67173 ** is the same as executing Halt.
67174 */
67175 case OP_Halt: {
 
67176 const char *zType;
67177 const char *zLogFmt;
 
67178
67179 if( pOp->p1==SQLITE_OK && p->pFrame ){
67180 /* Halt the sub-program. Return control to the parent frame. */
67181 VdbeFrame *pFrame = p->pFrame;
67182 p->pFrame = pFrame->pParent;
@@ -67183,11 +67402,11 @@
67183 p->nFrame--;
67184 sqlite3VdbeSetChanges(db, p->nChange);
67185 pc = sqlite3VdbeFrameRestore(pFrame);
67186 lastRowid = db->lastRowid;
67187 if( pOp->p2==OE_Ignore ){
67188 /* Instruction pc is the OP_Program that invoked the sub-program
67189 ** currently being halted. If the p2 instruction of this OP_Halt
67190 ** instruction is set to OE_Ignore, then the sub-program is throwing
67191 ** an IGNORE exception. In this case jump to the address specified
67192 ** as the p2 of the calling OP_Program. */
67193 pc = p->aOp[pc].p2-1;
@@ -67206,25 +67425,25 @@
67206 assert( pOp->p5>=1 && pOp->p5<=4 );
67207 testcase( pOp->p5==1 );
67208 testcase( pOp->p5==2 );
67209 testcase( pOp->p5==3 );
67210 testcase( pOp->p5==4 );
67211 zType = azType[pOp->p5-1];
67212 }else{
67213 zType = 0;
67214 }
67215 assert( zType!=0 || pOp->p4.z!=0 );
67216 zLogFmt = "abort at %d in [%s]: %s";
67217 if( zType && pOp->p4.z ){
67218 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67219 zType, pOp->p4.z);
67220 }else if( pOp->p4.z ){
67221 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67222 }else{
67223 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType);
67224 }
67225 sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg);
67226 }
67227 rc = sqlite3VdbeHalt(p);
67228 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67229 if( rc==SQLITE_BUSY ){
67230 p->rc = rc = SQLITE_BUSY;
@@ -67334,21 +67553,23 @@
67334 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67335 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67336 ** OP_Ne or OP_Eq.
67337 */
67338 case OP_Null: { /* out2-prerelease */
 
67339 int cnt;
67340 u16 nullFlag;
67341 cnt = pOp->p3-pOp->p2;
 
67342 assert( pOp->p3<=(p->nMem-p->nCursor) );
67343 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67344 while( cnt>0 ){
67345 pOut++;
67346 memAboutToChange(p, pOut);
67347 VdbeMemRelease(pOut);
67348 pOut->flags = nullFlag;
67349 cnt--;
67350 }
67351 break;
67352 }
67353
67354
@@ -67373,19 +67594,21 @@
67373 **
67374 ** If the parameter is named, then its name appears in P4 and P3==1.
67375 ** The P4 value is used by sqlite3_bind_parameter_name().
67376 */
67377 case OP_Variable: { /* out2-prerelease */
 
67378 Mem *pVar; /* Value being transferred */
 
67379
67380 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67381 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67382 pVar = &p->aVar[pOp->p1 - 1];
67383 if( sqlite3VdbeMemTooBig(pVar) ){
67384 goto too_big;
67385 }
67386 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
67387 UPDATE_MAX_BLOBSIZE(pOut);
67388 break;
67389 }
67390
67391 /* Opcode: Move P1 P2 P3 * *
@@ -67395,67 +67618,71 @@
67395 ** registers P2..P2+P3. Registers P1..P1+P3 are
67396 ** left holding a NULL. It is an error for register ranges
67397 ** P1..P1+P3 and P2..P2+P3 to overlap.
67398 */
67399 case OP_Move: {
 
67400 char *zMalloc; /* Holding variable for allocated memory */
67401 int n; /* Number of registers left to copy */
67402 int p1; /* Register to copy from */
67403 int p2; /* Register to copy to */
67404
67405 n = pOp->p3;
67406 p1 = pOp->p1;
67407 p2 = pOp->p2;
67408 assert( n>=0 && p1>0 && p2>0 );
67409 assert( p1+n<=p2 || p2+n<=p1 );
67410
67411 pIn1 = &aMem[p1];
67412 pOut = &aMem[p2];
 
67413 do{
67414 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67415 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67416 assert( memIsValid(pIn1) );
67417 memAboutToChange(p, pOut);
67418 zMalloc = pOut->zMalloc;
67419 pOut->zMalloc = 0;
67420 sqlite3VdbeMemMove(pOut, pIn1);
67421 #ifdef SQLITE_DEBUG
67422 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){
67423 pOut->pScopyFrom += p1 - pOp->p2;
67424 }
67425 #endif
67426 pIn1->zMalloc = zMalloc;
67427 REGISTER_TRACE(p2++, pOut);
67428 pIn1++;
67429 pOut++;
67430 }while( n-- );
67431 break;
67432 }
67433
67434 /* Opcode: Copy P1 P2 P3 * *
67435 ** Synopsis: r[P2@P3+1]=r[P1@P3+1]
67436 **
67437 ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
67438 **
67439 ** This instruction makes a deep copy of the value. A duplicate
67440 ** is made of any string or blob constant. See also OP_SCopy.
67441 */
67442 case OP_Copy: {
 
67443 int n;
 
67444
67445 n = pOp->p3;
67446 pIn1 = &aMem[pOp->p1];
67447 pOut = &aMem[pOp->p2];
67448 assert( pOut!=pIn1 );
67449 while( 1 ){
67450 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67451 Deephemeralize(pOut);
67452 #ifdef SQLITE_DEBUG
67453 pOut->pScopyFrom = 0;
67454 #endif
67455 REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut);
67456 if( (n--)==0 ) break;
67457 pOut++;
67458 pIn1++;
67459 }
67460 break;
67461 }
@@ -67492,12 +67719,14 @@
67492 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67493 ** structure to provide access to the top P1 values as the result
67494 ** row.
67495 */
67496 case OP_ResultRow: {
 
67497 Mem *pMem;
67498 int i;
 
67499 assert( p->nResColumn==pOp->p2 );
67500 assert( pOp->p1>0 );
67501 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67502
67503 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -67519,12 +67748,12 @@
67519 assert( db->flags&SQLITE_CountRows );
67520 assert( p->usesStmtJournal );
67521 break;
67522 }
67523
67524 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67525 ** DML statements invoke this opcode to return the number of rows
67526 ** modified to the user. This is the only way that a VM that
67527 ** opens a statement transaction may invoke this opcode.
67528 **
67529 ** In case this is such a statement, close any statement transaction
67530 ** opened by this VM before returning control to the user. This is to
@@ -67547,19 +67776,19 @@
67547
67548 /* Make sure the results of the current row are \000 terminated
67549 ** and have an assigned type. The results are de-ephemeralized as
67550 ** a side effect.
67551 */
67552 pMem = p->pResultSet = &aMem[pOp->p1];
67553 for(i=0; i<pOp->p2; i++){
67554 assert( memIsValid(&pMem[i]) );
67555 Deephemeralize(&pMem[i]);
67556 assert( (pMem[i].flags & MEM_Ephem)==0
67557 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 );
67558 sqlite3VdbeMemNulTerminate(&pMem[i]);
67559 sqlite3VdbeMemStoreType(&pMem[i]);
67560 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
67561 }
67562 if( db->mallocFailed ) goto no_mem;
67563
67564 /* Return SQLITE_ROW
67565 */
@@ -67580,11 +67809,13 @@
67580 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67581 ** if P3 is the same register as P2, the implementation is able
67582 ** to avoid a memcpy().
67583 */
67584 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
 
67585 i64 nByte;
 
67586
67587 pIn1 = &aMem[pOp->p1];
67588 pIn2 = &aMem[pOp->p2];
67589 pOut = &aMem[pOp->p3];
67590 assert( pIn1!=pOut );
@@ -67593,26 +67824,26 @@
67593 break;
67594 }
67595 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67596 Stringify(pIn1, encoding);
67597 Stringify(pIn2, encoding);
67598 nByte = pIn1->n + pIn2->n;
67599 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67600 goto too_big;
67601 }
67602 MemSetTypeFlag(pOut, MEM_Str);
67603 if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){
67604 goto no_mem;
67605 }
67606 if( pOut!=pIn2 ){
67607 memcpy(pOut->z, pIn2->z, pIn2->n);
67608 }
67609 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67610 pOut->z[nByte]=0;
67611 pOut->z[nByte+1] = 0;
67612 pOut->flags |= MEM_Term;
67613 pOut->n = (int)nByte;
67614 pOut->enc = encoding;
67615 UPDATE_MAX_BLOBSIZE(pOut);
67616 break;
67617 }
67618
@@ -67657,81 +67888,83 @@
67657 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67658 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67659 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67660 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67661 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
 
67662 char bIntint; /* Started out as two integer operands */
67663 int flags; /* Combined MEM_* flags from both inputs */
67664 i64 iA; /* Integer value of left operand */
67665 i64 iB; /* Integer value of right operand */
67666 double rA; /* Real value of left operand */
67667 double rB; /* Real value of right operand */
 
67668
67669 pIn1 = &aMem[pOp->p1];
67670 applyNumericAffinity(pIn1);
67671 pIn2 = &aMem[pOp->p2];
67672 applyNumericAffinity(pIn2);
67673 pOut = &aMem[pOp->p3];
67674 flags = pIn1->flags | pIn2->flags;
67675 if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67676 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67677 iA = pIn1->u.i;
67678 iB = pIn2->u.i;
67679 bIntint = 1;
67680 switch( pOp->opcode ){
67681 case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
67682 case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
67683 case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break;
67684 case OP_Divide: {
67685 if( iA==0 ) goto arithmetic_result_is_null;
67686 if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math;
67687 iB /= iA;
67688 break;
67689 }
67690 default: {
67691 if( iA==0 ) goto arithmetic_result_is_null;
67692 if( iA==-1 ) iA = 1;
67693 iB %= iA;
67694 break;
67695 }
67696 }
67697 pOut->u.i = iB;
67698 MemSetTypeFlag(pOut, MEM_Int);
67699 }else{
67700 bIntint = 0;
67701 fp_math:
67702 rA = sqlite3VdbeRealValue(pIn1);
67703 rB = sqlite3VdbeRealValue(pIn2);
67704 switch( pOp->opcode ){
67705 case OP_Add: rB += rA; break;
67706 case OP_Subtract: rB -= rA; break;
67707 case OP_Multiply: rB *= rA; break;
67708 case OP_Divide: {
67709 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67710 if( rA==(double)0 ) goto arithmetic_result_is_null;
67711 rB /= rA;
67712 break;
67713 }
67714 default: {
67715 iA = (i64)rA;
67716 iB = (i64)rB;
67717 if( iA==0 ) goto arithmetic_result_is_null;
67718 if( iA==-1 ) iA = 1;
67719 rB = (double)(iB % iA);
67720 break;
67721 }
67722 }
67723 #ifdef SQLITE_OMIT_FLOATING_POINT
67724 pOut->u.i = rB;
67725 MemSetTypeFlag(pOut, MEM_Int);
67726 #else
67727 if( sqlite3IsNaN(rB) ){
67728 goto arithmetic_result_is_null;
67729 }
67730 pOut->r = rB;
67731 MemSetTypeFlag(pOut, MEM_Real);
67732 if( (flags & MEM_Real)==0 && !bIntint ){
67733 sqlite3VdbeIntegerAffinity(pOut);
67734 }
67735 #endif
67736 }
67737 break;
@@ -67780,83 +68013,85 @@
67780 ** invocation of this opcode.
67781 **
67782 ** See also: AggStep and AggFinal
67783 */
67784 case OP_Function: {
 
67785 int i;
67786 Mem *pArg;
67787 sqlite3_context ctx;
67788 sqlite3_value **apVal;
67789 int n;
 
67790
67791 n = pOp->p5;
67792 apVal = p->apArg;
67793 assert( apVal || n==0 );
67794 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
67795 pOut = &aMem[pOp->p3];
67796 memAboutToChange(p, pOut);
67797
67798 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) );
67799 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n );
67800 pArg = &aMem[pOp->p2];
67801 for(i=0; i<n; i++, pArg++){
67802 assert( memIsValid(pArg) );
67803 apVal[i] = pArg;
67804 Deephemeralize(pArg);
67805 sqlite3VdbeMemStoreType(pArg);
67806 REGISTER_TRACE(pOp->p2+i, pArg);
67807 }
67808
67809 assert( pOp->p4type==P4_FUNCDEF );
67810 ctx.pFunc = pOp->p4.pFunc;
67811 ctx.iOp = pc;
67812 ctx.pVdbe = p;
67813
67814 /* The output cell may already have a buffer allocated. Move
67815 ** the pointer to ctx.s so in case the user-function can use
67816 ** the already allocated buffer instead of allocating a new one.
67817 */
67818 memcpy(&ctx.s, pOut, sizeof(Mem));
67819 pOut->flags = MEM_Null;
67820 pOut->xDel = 0;
67821 pOut->zMalloc = 0;
67822 MemSetTypeFlag(&ctx.s, MEM_Null);
67823
67824 ctx.fErrorOrAux = 0;
67825 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67826 assert( pOp>aOp );
67827 assert( pOp[-1].p4type==P4_COLLSEQ );
67828 assert( pOp[-1].opcode==OP_CollSeq );
67829 ctx.pColl = pOp[-1].p4.pColl;
67830 }
67831 db->lastRowid = lastRowid;
67832 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
67833 lastRowid = db->lastRowid;
67834
67835 if( db->mallocFailed ){
67836 /* Even though a malloc() has failed, the implementation of the
67837 ** user function may have called an sqlite3_result_XXX() function
67838 ** to return a value. The following call releases any resources
67839 ** associated with such a value.
67840 */
67841 sqlite3VdbeMemRelease(&ctx.s);
67842 goto no_mem;
67843 }
67844
67845 /* If the function returned an error, throw an exception */
67846 if( ctx.fErrorOrAux ){
67847 if( ctx.isError ){
67848 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
67849 rc = ctx.isError;
67850 }
67851 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
67852 }
67853
67854 /* Copy the result of the function into register P3 */
67855 sqlite3VdbeChangeEncoding(&ctx.s, encoding);
67856 assert( pOut->flags==MEM_Null );
67857 memcpy(pOut, &ctx.s, sizeof(Mem));
67858 if( sqlite3VdbeMemTooBig(pOut) ){
67859 goto too_big;
67860 }
67861
67862 #if 0
@@ -67904,54 +68139,56 @@
67904 */
67905 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
67906 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
67907 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
67908 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
 
67909 i64 iA;
67910 u64 uA;
67911 i64 iB;
67912 u8 op;
 
67913
67914 pIn1 = &aMem[pOp->p1];
67915 pIn2 = &aMem[pOp->p2];
67916 pOut = &aMem[pOp->p3];
67917 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
67918 sqlite3VdbeMemSetNull(pOut);
67919 break;
67920 }
67921 iA = sqlite3VdbeIntValue(pIn2);
67922 iB = sqlite3VdbeIntValue(pIn1);
67923 op = pOp->opcode;
67924 if( op==OP_BitAnd ){
67925 iA &= iB;
67926 }else if( op==OP_BitOr ){
67927 iA |= iB;
67928 }else if( iB!=0 ){
67929 assert( op==OP_ShiftRight || op==OP_ShiftLeft );
67930
67931 /* If shifting by a negative amount, shift in the other direction */
67932 if( iB<0 ){
67933 assert( OP_ShiftRight==OP_ShiftLeft+1 );
67934 op = 2*OP_ShiftLeft + 1 - op;
67935 iB = iB>(-64) ? -iB : 64;
67936 }
67937
67938 if( iB>=64 ){
67939 iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1;
67940 }else{
67941 memcpy(&uA, &iA, sizeof(uA));
67942 if( op==OP_ShiftLeft ){
67943 uA <<= iB;
67944 }else{
67945 uA >>= iB;
67946 /* Sign-extend on a right shift of a negative number */
67947 if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB);
67948 }
67949 memcpy(&iA, &uA, sizeof(iA));
67950 }
67951 }
67952 pOut->u.i = iA;
67953 MemSetTypeFlag(pOut, MEM_Int);
67954 break;
67955 }
67956
67957 /* Opcode: AddImm P1 P2 * * *
@@ -68201,35 +68438,37 @@
68201 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
68202 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
68203 case OP_Le: /* same as TK_LE, jump, in1, in3 */
68204 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
68205 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
 
68206 int res; /* Result of the comparison of pIn1 against pIn3 */
68207 char affinity; /* Affinity to use for comparison */
68208 u16 flags1; /* Copy of initial value of pIn1->flags */
68209 u16 flags3; /* Copy of initial value of pIn3->flags */
 
68210
68211 pIn1 = &aMem[pOp->p1];
68212 pIn3 = &aMem[pOp->p3];
68213 flags1 = pIn1->flags;
68214 flags3 = pIn3->flags;
68215 if( (flags1 | flags3)&MEM_Null ){
68216 /* One or both operands are NULL */
68217 if( pOp->p5 & SQLITE_NULLEQ ){
68218 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
68219 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68220 ** or not both operands are null.
68221 */
68222 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68223 assert( (flags1 & MEM_Cleared)==0 );
68224 if( (flags1&MEM_Null)!=0
68225 && (flags3&MEM_Null)!=0
68226 && (flags3&MEM_Cleared)==0
68227 ){
68228 res = 0; /* Results are equal */
68229 }else{
68230 res = 1; /* Results are not equal */
68231 }
68232 }else{
68233 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68234 ** then the result is always NULL.
68235 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68243,44 +68482,44 @@
68243 }
68244 break;
68245 }
68246 }else{
68247 /* Neither operand is NULL. Do a comparison. */
68248 affinity = pOp->p5 & SQLITE_AFF_MASK;
68249 if( affinity ){
68250 applyAffinity(pIn1, affinity, encoding);
68251 applyAffinity(pIn3, affinity, encoding);
68252 if( db->mallocFailed ) goto no_mem;
68253 }
68254
68255 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68256 ExpandBlob(pIn1);
68257 ExpandBlob(pIn3);
68258 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68259 }
68260 switch( pOp->opcode ){
68261 case OP_Eq: res = res==0; break;
68262 case OP_Ne: res = res!=0; break;
68263 case OP_Lt: res = res<0; break;
68264 case OP_Le: res = res<=0; break;
68265 case OP_Gt: res = res>0; break;
68266 default: res = res>=0; break;
68267 }
68268
68269 if( pOp->p5 & SQLITE_STOREP2 ){
68270 pOut = &aMem[pOp->p2];
68271 memAboutToChange(p, pOut);
68272 MemSetTypeFlag(pOut, MEM_Int);
68273 pOut->u.i = res;
68274 REGISTER_TRACE(pOp->p2, pOut);
68275 }else if( res ){
68276 pc = pOp->p2-1;
68277 }
68278
68279 /* Undo any changes made by applyAffinity() to the input registers. */
68280 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68281 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68282 break;
68283 }
68284
68285 /* Opcode: Permutation * * * P4 *
68286 **
@@ -68316,49 +68555,51 @@
68316 ** The comparison is a sort comparison, so NULLs compare equal,
68317 ** NULLs are less than numbers, numbers are less than strings,
68318 ** and strings are less than blobs.
68319 */
68320 case OP_Compare: {
 
68321 int n;
68322 int i;
68323 int p1;
68324 int p2;
68325 const KeyInfo *pKeyInfo;
68326 int idx;
68327 CollSeq *pColl; /* Collating sequence to use on this term */
68328 int bRev; /* True for DESCENDING sort order */
 
68329
68330 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68331 n = pOp->p3;
68332 pKeyInfo = pOp->p4.pKeyInfo;
68333 assert( n>0 );
68334 assert( pKeyInfo!=0 );
68335 p1 = pOp->p1;
68336 p2 = pOp->p2;
68337 #if SQLITE_DEBUG
68338 if( aPermute ){
68339 int k, mx = 0;
68340 for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68341 assert( p1>0 && p1+mx<=(p->nMem-p->nCursor)+1 );
68342 assert( p2>0 && p2+mx<=(p->nMem-p->nCursor)+1 );
68343 }else{
68344 assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 );
68345 assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 );
68346 }
68347 #endif /* SQLITE_DEBUG */
68348 for(i=0; i<n; i++){
68349 idx = aPermute ? aPermute[i] : i;
68350 assert( memIsValid(&aMem[p1+idx]) );
68351 assert( memIsValid(&aMem[p2+idx]) );
68352 REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
68353 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
68354 assert( i<pKeyInfo->nField );
68355 pColl = pKeyInfo->aColl[i];
68356 bRev = pKeyInfo->aSortOrder[i];
68357 iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
68358 if( iCompare ){
68359 if( bRev ) iCompare = -iCompare;
68360 break;
68361 }
68362 }
68363 aPermute = 0;
68364 break;
@@ -68401,37 +68642,39 @@
68401 ** even if the other input is NULL. A NULL and false or two NULLs
68402 ** give a NULL output.
68403 */
68404 case OP_And: /* same as TK_AND, in1, in2, out3 */
68405 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
 
68406 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68407 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
 
68408
68409 pIn1 = &aMem[pOp->p1];
68410 if( pIn1->flags & MEM_Null ){
68411 v1 = 2;
68412 }else{
68413 v1 = sqlite3VdbeIntValue(pIn1)!=0;
68414 }
68415 pIn2 = &aMem[pOp->p2];
68416 if( pIn2->flags & MEM_Null ){
68417 v2 = 2;
68418 }else{
68419 v2 = sqlite3VdbeIntValue(pIn2)!=0;
68420 }
68421 if( pOp->opcode==OP_And ){
68422 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68423 v1 = and_logic[v1*3+v2];
68424 }else{
68425 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68426 v1 = or_logic[v1*3+v2];
68427 }
68428 pOut = &aMem[pOp->p3];
68429 if( v1==2 ){
68430 MemSetTypeFlag(pOut, MEM_Null);
68431 }else{
68432 pOut->u.i = v1;
68433 MemSetTypeFlag(pOut, MEM_Int);
68434 }
68435 break;
68436 }
68437
@@ -68498,23 +68741,25 @@
68498 ** is considered false if it has a numeric value of zero. If the value
68499 ** in P1 is NULL then take the jump if P3 is zero.
68500 */
68501 case OP_If: /* jump, in1 */
68502 case OP_IfNot: { /* jump, in1 */
 
68503 int c;
 
68504 pIn1 = &aMem[pOp->p1];
68505 if( pIn1->flags & MEM_Null ){
68506 c = pOp->p3;
68507 }else{
68508 #ifdef SQLITE_OMIT_FLOATING_POINT
68509 c = sqlite3VdbeIntValue(pIn1)!=0;
68510 #else
68511 c = sqlite3VdbeRealValue(pIn1)!=0.0;
68512 #endif
68513 if( pOp->opcode==OP_IfNot ) c = !c;
68514 }
68515 if( c ){
68516 pc = pOp->p2-1;
68517 }
68518 break;
68519 }
68520
@@ -68568,10 +68813,11 @@
68568 ** the result is guaranteed to only be used as the argument of a length()
68569 ** or typeof() function, respectively. The loading of large blobs can be
68570 ** skipped for length() and all content loading can be skipped for typeof().
68571 */
68572 case OP_Column: {
 
68573 i64 payloadSize64; /* Number of bytes in the record */
68574 int p2; /* column number to retrieve */
68575 VdbeCursor *pC; /* The VDBE cursor */
68576 BtCursor *pCrsr; /* The BTree cursor */
68577 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
@@ -68586,88 +68832,89 @@
68586 u32 offset; /* Offset into the data */
68587 u32 szField; /* Number of bytes in the content of a field */
68588 u32 avail; /* Number of bytes of available data */
68589 u32 t; /* A type code from the record header */
68590 Mem *pReg; /* PseudoTable input register */
68591
68592 p2 = pOp->p2;
68593 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68594 pDest = &aMem[pOp->p3];
68595 memAboutToChange(p, pDest);
68596 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68597 pC = p->apCsr[pOp->p1];
68598 assert( pC!=0 );
68599 assert( p2<pC->nField );
68600 aType = pC->aType;
68601 aOffset = aType + pC->nField;
68602 #ifndef SQLITE_OMIT_VIRTUALTABLE
68603 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
68604 #endif
68605 pCrsr = pC->pCursor;
68606 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
68607 assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
68608
68609 /* If the cursor cache is stale, bring it up-to-date */
68610 rc = sqlite3VdbeCursorMoveto(pC);
68611 if( rc ) goto abort_due_to_error;
68612 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68613 if( pC->nullRow ){
68614 if( pCrsr==0 ){
68615 assert( pC->pseudoTableReg>0 );
68616 pReg = &aMem[pC->pseudoTableReg];
68617 if( pC->multiPseudo ){
68618 sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68619 Deephemeralize(pDest);
68620 goto op_column_out;
68621 }
68622 assert( pReg->flags & MEM_Blob );
68623 assert( memIsValid(pReg) );
68624 pC->payloadSize = pC->szRow = avail = pReg->n;
68625 pC->aRow = (u8*)pReg->z;
68626 }else{
68627 MemSetTypeFlag(pDest, MEM_Null);
68628 goto op_column_out;
68629 }
68630 }else{
68631 assert( pCrsr );
68632 if( pC->isTable==0 ){
68633 assert( sqlite3BtreeCursorIsValid(pCrsr) );
68634 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64);
68635 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68636 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68637 ** payload size, so it is impossible for payloadSize64 to be
68638 ** larger than 32 bits. */
68639 assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 );
68640 pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail);
68641 pC->payloadSize = (u32)payloadSize64;
68642 }else{
68643 assert( sqlite3BtreeCursorIsValid(pCrsr) );
68644 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize);
68645 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68646 pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail);
68647 }
68648 assert( avail<=65536 ); /* Maximum page size is 64KiB */
68649 if( pC->payloadSize <= (u32)avail ){
68650 pC->szRow = pC->payloadSize;
68651 }else{
68652 pC->szRow = avail;
68653 }
68654 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68655 goto too_big;
68656 }
68657 }
68658 pC->cacheStatus = p->cacheCtr;
68659 pC->iHdrOffset = getVarint32(pC->aRow, offset);
68660 pC->nHdrParsed = 0;
68661 aOffset[0] = offset;
68662 if( avail<offset ){
68663 /* pC->aRow does not have to hold the entire row, but it does at least
68664 ** need to cover the header of the record. If pC->aRow does not contain
68665 ** the complete header, then set it to zero, forcing the header to be
68666 ** dynamically allocated. */
68667 pC->aRow = 0;
68668 pC->szRow = 0;
 
68669 }
68670
68671 /* Make sure a corrupt database has not given us an oversize header.
68672 ** Do this now to avoid an oversize memory allocation.
68673 **
@@ -68675,154 +68922,154 @@
68675 ** types use so much data space that there can only be 4096 and 32 of
68676 ** them, respectively. So the maximum header length results from a
68677 ** 3-byte type for each of the maximum of 32768 columns plus three
68678 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68679 */
68680 if( offset > 98307 || offset > pC->payloadSize ){
68681 rc = SQLITE_CORRUPT_BKPT;
68682 goto op_column_error;
68683 }
68684 }
68685
68686 /* Make sure at least the first p2+1 entries of the header have been
68687 ** parsed and valid information is in aOffset[] and aType[].
68688 */
68689 if( pC->nHdrParsed<=p2 ){
68690 /* If there is more header available for parsing in the record, try
68691 ** to extract additional fields up through the p2+1-th field
68692 */
68693 if( pC->iHdrOffset<aOffset[0] ){
68694 /* Make sure zData points to enough of the record to cover the header. */
68695 if( pC->aRow==0 ){
68696 memset(&sMem, 0, sizeof(sMem));
68697 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0],
68698 !pC->isTable, &sMem);
68699 if( rc!=SQLITE_OK ){
68700 goto op_column_error;
68701 }
68702 zData = (u8*)sMem.z;
68703 }else{
68704 zData = pC->aRow;
68705 }
68706
68707 /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
68708 i = pC->nHdrParsed;
68709 offset = aOffset[i];
68710 zHdr = zData + pC->iHdrOffset;
68711 zEndHdr = zData + aOffset[0];
68712 assert( i<=p2 && zHdr<zEndHdr );
68713 do{
68714 if( zHdr[0]<0x80 ){
68715 t = zHdr[0];
68716 zHdr++;
68717 }else{
68718 zHdr += sqlite3GetVarint32(zHdr, &t);
68719 }
68720 aType[i] = t;
68721 szField = sqlite3VdbeSerialTypeLen(t);
68722 offset += szField;
68723 if( offset<szField ){ /* True if offset overflows */
68724 zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68725 break;
68726 }
68727 i++;
68728 aOffset[i] = offset;
68729 }while( i<=p2 && zHdr<zEndHdr );
68730 pC->nHdrParsed = i;
68731 pC->iHdrOffset = (u32)(zHdr - zData);
68732 if( pC->aRow==0 ){
68733 sqlite3VdbeMemRelease(&sMem);
68734 sMem.flags = MEM_Null;
68735 }
68736
68737 /* If we have read more header data than was contained in the header,
68738 ** or if the end of the last field appears to be past the end of the
68739 ** record, or if the end of the last field appears to be before the end
68740 ** of the record (when all fields present), then we must be dealing
68741 ** with a corrupt database.
68742 */
68743 if( (zHdr > zEndHdr)
68744 || (offset > pC->payloadSize)
68745 || (zHdr==zEndHdr && offset!=pC->payloadSize)
68746 ){
68747 rc = SQLITE_CORRUPT_BKPT;
68748 goto op_column_error;
68749 }
68750 }
68751
68752 /* If after trying to extra new entries from the header, nHdrParsed is
68753 ** still not up to p2, that means that the record has fewer than p2
68754 ** columns. So the result will be either the default value or a NULL.
68755 */
68756 if( pC->nHdrParsed<=p2 ){
68757 if( pOp->p4type==P4_MEM ){
68758 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
68759 }else{
68760 MemSetTypeFlag(pDest, MEM_Null);
68761 }
68762 goto op_column_out;
68763 }
68764 }
68765
68766 /* Extract the content for the p2+1-th column. Control can only
68767 ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
68768 ** all valid.
68769 */
68770 assert( p2<pC->nHdrParsed );
68771 assert( rc==SQLITE_OK );
68772 if( pC->szRow>=aOffset[p2+1] ){
68773 /* This is the common case where the desired content fits on the original
68774 ** page - where the content is not on an overflow page */
68775 VdbeMemRelease(pDest);
68776 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
68777 }else{
68778 /* This branch happens only when content is on overflow pages */
68779 t = aType[p2];
68780 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
68781 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
68782 || (len = sqlite3VdbeSerialTypeLen(t))==0
68783 ){
68784 /* Content is irrelevant for the typeof() function and for
68785 ** the length(X) function if X is a blob. So we might as well use
68786 ** bogus content rather than reading content from disk. NULL works
68787 ** for text and blob and whatever is in the payloadSize64 variable
68788 ** will work for everything else. Content is also irrelevant if
68789 ** the content length is 0. */
68790 zData = t<=13 ? (u8*)&payloadSize64 : 0;
68791 sMem.zMalloc = 0;
68792 }else{
68793 memset(&sMem, 0, sizeof(sMem));
68794 sqlite3VdbeMemMove(&sMem, pDest);
68795 rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
68796 &sMem);
68797 if( rc!=SQLITE_OK ){
68798 goto op_column_error;
68799 }
68800 zData = (u8*)sMem.z;
68801 }
68802 sqlite3VdbeSerialGet(zData, t, pDest);
68803 /* If we dynamically allocated space to hold the data (in the
68804 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
68805 ** dynamically allocated space over to the pDest structure.
68806 ** This prevents a memory copy. */
68807 if( sMem.zMalloc ){
68808 assert( sMem.z==sMem.zMalloc );
68809 assert( !(pDest->flags & MEM_Dyn) );
68810 assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z );
68811 pDest->flags &= ~(MEM_Ephem|MEM_Static);
68812 pDest->flags |= MEM_Term;
68813 pDest->z = sMem.z;
68814 pDest->zMalloc = sMem.zMalloc;
68815 }
68816 }
68817 pDest->enc = encoding;
68818
68819 op_column_out:
68820 Deephemeralize(pDest);
68821 op_column_error:
68822 UPDATE_MAX_BLOBSIZE(pDest);
68823 REGISTER_TRACE(pOp->p3, pDest);
68824 break;
68825 }
68826
68827 /* Opcode: Affinity P1 P2 * P4 *
68828 ** Synopsis: affinity(r[P1@P2])
@@ -68832,22 +69079,24 @@
68832 ** P4 is a string that is P2 characters long. The nth character of the
68833 ** string indicates the column affinity that should be used for the nth
68834 ** memory cell in the range.
68835 */
68836 case OP_Affinity: {
 
68837 const char *zAffinity; /* The affinity to be applied */
68838 char cAff; /* A single character of affinity */
 
68839
68840 zAffinity = pOp->p4.z;
68841 assert( zAffinity!=0 );
68842 assert( zAffinity[pOp->p2]==0 );
68843 pIn1 = &aMem[pOp->p1];
68844 while( (cAff = *(zAffinity++))!=0 ){
68845 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
68846 assert( memIsValid(pIn1) );
68847 ExpandBlob(pIn1);
68848 applyAffinity(pIn1, cAff, encoding);
68849 pIn1++;
68850 }
68851 break;
68852 }
68853
@@ -68866,10 +69115,11 @@
68866 ** macros defined in sqliteInt.h.
68867 **
68868 ** If P4 is NULL then all index fields have the affinity NONE.
68869 */
68870 case OP_MakeRecord: {
 
68871 u8 *zNewRecord; /* A buffer to hold the data for the new record */
68872 Mem *pRec; /* The new record */
68873 u64 nData; /* Number of bytes of data space */
68874 int nHdr; /* Number of bytes of header space */
68875 i64 nByte; /* Data space required for this record */
@@ -68879,123 +69129,106 @@
68879 Mem *pData0; /* First field to be combined into the record */
68880 Mem *pLast; /* Last field of the record */
68881 int nField; /* Number of fields in the record */
68882 char *zAffinity; /* The affinity string for the record */
68883 int file_format; /* File format to use for encoding */
68884 int i; /* Space used in zNewRecord[] header */
68885 int j; /* Space used in zNewRecord[] content */
68886 int len; /* Length of a field */
 
68887
68888 /* Assuming the record contains N fields, the record format looks
68889 ** like this:
68890 **
68891 ** ------------------------------------------------------------------------
68892 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
68893 ** ------------------------------------------------------------------------
68894 **
68895 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
68896 ** and so froth.
68897 **
68898 ** Each type field is a varint representing the serial type of the
68899 ** corresponding data element (see sqlite3VdbeSerialType()). The
68900 ** hdr-size field is also a varint which is the offset from the beginning
68901 ** of the record to data0.
68902 */
68903 nData = 0; /* Number of bytes of data space */
68904 nHdr = 0; /* Number of bytes of header space */
68905 nZero = 0; /* Number of zero bytes at the end of the record */
68906 nField = pOp->p1;
68907 zAffinity = pOp->p4.z;
68908 assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem-p->nCursor)+1 );
68909 pData0 = &aMem[nField];
68910 nField = pOp->p2;
68911 pLast = &pData0[nField-1];
68912 file_format = p->minWriteFileFormat;
68913
68914 /* Identify the output register */
68915 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
68916 pOut = &aMem[pOp->p3];
68917 memAboutToChange(p, pOut);
68918
68919 /* Apply the requested affinity to all inputs
68920 */
68921 assert( pData0<=pLast );
68922 if( zAffinity ){
68923 pRec = pData0;
68924 do{
68925 applyAffinity(pRec, *(zAffinity++), encoding);
68926 }while( (++pRec)<=pLast );
68927 }
68928
68929 /* Loop through the elements that will make up the record to figure
68930 ** out how much space is required for the new record.
68931 */
68932 pRec = pLast;
68933 do{
68934 assert( memIsValid(pRec) );
68935 serial_type = sqlite3VdbeSerialType(pRec, file_format);
68936 len = sqlite3VdbeSerialTypeLen(serial_type);
68937 if( pRec->flags & MEM_Zero ){
68938 if( nData ){
68939 sqlite3VdbeMemExpandBlob(pRec);
68940 }else{
68941 nZero += pRec->u.nZero;
68942 len -= pRec->u.nZero;
68943 }
68944 }
68945 nData += len;
68946 testcase( serial_type==127 );
68947 testcase( serial_type==128 );
68948 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
68949 }while( (--pRec)>=pData0 );
 
 
68950
68951 /* Add the initial header varint and total the size */
68952 testcase( nHdr==126 );
68953 testcase( nHdr==127 );
68954 if( nHdr<=126 ){
68955 /* The common case */
68956 nHdr += 1;
68957 }else{
68958 /* Rare case of a really large header */
68959 nVarint = sqlite3VarintLen(nHdr);
68960 nHdr += nVarint;
68961 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++;
68962 }
68963 nByte = nHdr+nData;
68964 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
68965 goto too_big;
68966 }
68967
68968 /* Make sure the output register has a buffer large enough to store
68969 ** the new record. The output register (pOp->p3) is not allowed to
68970 ** be one of the input registers (because the following call to
68971 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
68972 */
68973 if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){
68974 goto no_mem;
68975 }
68976 zNewRecord = (u8 *)pOut->z;
68977
68978 /* Write the record */
68979 i = putVarint32(zNewRecord, nHdr);
68980 j = nHdr;
68981 assert( pData0<=pLast );
68982 pRec = pData0;
68983 do{
68984 serial_type = sqlite3VdbeSerialType(pRec, file_format);
68985 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
68986 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
68987 }while( (++pRec)<=pLast );
68988 assert( i==nHdr );
68989 assert( j==nByte );
68990
68991 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68992 pOut->n = (int)nByte;
68993 pOut->flags = MEM_Blob | MEM_Dyn;
68994 pOut->xDel = 0;
68995 if( nZero ){
68996 pOut->u.nZero = nZero;
68997 pOut->flags |= MEM_Zero;
68998 }
68999 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
69000 REGISTER_TRACE(pOp->p3, pOut);
69001 UPDATE_MAX_BLOBSIZE(pOut);
@@ -69008,18 +69241,19 @@
69008 ** Store the number of entries (an integer value) in the table or index
69009 ** opened by cursor P1 in register P2
69010 */
69011 #ifndef SQLITE_OMIT_BTREECOUNT
69012 case OP_Count: { /* out2-prerelease */
 
69013 i64 nEntry;
69014 BtCursor *pCrsr;
 
69015
69016 pCrsr = p->apCsr[pOp->p1]->pCursor;
69017 assert( pCrsr );
69018 nEntry = 0; /* Not needed. Only used to silence a warning. */
69019 rc = sqlite3BtreeCount(pCrsr, &nEntry);
69020 pOut->u.i = nEntry;
69021 break;
69022 }
69023 #endif
69024
69025 /* Opcode: Savepoint P1 * * P4 *
@@ -69027,41 +69261,43 @@
69027 ** Open, release or rollback the savepoint named by parameter P4, depending
69028 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
69029 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
69030 */
69031 case OP_Savepoint: {
 
69032 int p1; /* Value of P1 operand */
69033 char *zName; /* Name of savepoint */
69034 int nName;
69035 Savepoint *pNew;
69036 Savepoint *pSavepoint;
69037 Savepoint *pTmp;
69038 int iSavepoint;
69039 int ii;
 
69040
69041 p1 = pOp->p1;
69042 zName = pOp->p4.z;
69043
69044 /* Assert that the p1 parameter is valid. Also that if there is no open
69045 ** transaction, then there cannot be any savepoints.
69046 */
69047 assert( db->pSavepoint==0 || db->autoCommit==0 );
69048 assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK );
69049 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
69050 assert( checkSavepointCount(db) );
69051 assert( p->bIsReader );
69052
69053 if( p1==SAVEPOINT_BEGIN ){
69054 if( db->nVdbeWrite>0 ){
69055 /* A new savepoint cannot be created if there are active write
69056 ** statements (i.e. open read/write incremental blob handles).
69057 */
69058 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
69059 "SQL statements in progress");
69060 rc = SQLITE_BUSY;
69061 }else{
69062 nName = sqlite3Strlen30(zName);
69063
69064 #ifndef SQLITE_OMIT_VIRTUALTABLE
69065 /* This call is Ok even if this savepoint is actually a transaction
69066 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
69067 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -69071,62 +69307,62 @@
69071 db->nStatement+db->nSavepoint);
69072 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69073 #endif
69074
69075 /* Create a new savepoint structure. */
69076 pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1);
69077 if( pNew ){
69078 pNew->zName = (char *)&pNew[1];
69079 memcpy(pNew->zName, zName, nName+1);
69080
69081 /* If there is no open transaction, then mark this as a special
69082 ** "transaction savepoint". */
69083 if( db->autoCommit ){
69084 db->autoCommit = 0;
69085 db->isTransactionSavepoint = 1;
69086 }else{
69087 db->nSavepoint++;
69088 }
69089
69090 /* Link the new savepoint into the database handle's list. */
69091 pNew->pNext = db->pSavepoint;
69092 db->pSavepoint = pNew;
69093 pNew->nDeferredCons = db->nDeferredCons;
69094 pNew->nDeferredImmCons = db->nDeferredImmCons;
69095 }
69096 }
69097 }else{
69098 iSavepoint = 0;
69099
69100 /* Find the named savepoint. If there is no such savepoint, then an
69101 ** an error is returned to the user. */
69102 for(
69103 pSavepoint = db->pSavepoint;
69104 pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName);
69105 pSavepoint = pSavepoint->pNext
69106 ){
69107 iSavepoint++;
69108 }
69109 if( !pSavepoint ){
69110 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName);
69111 rc = SQLITE_ERROR;
69112 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){
69113 /* It is not possible to release (commit) a savepoint if there are
69114 ** active write statements.
69115 */
69116 sqlite3SetString(&p->zErrMsg, db,
69117 "cannot release savepoint - SQL statements in progress"
69118 );
69119 rc = SQLITE_BUSY;
69120 }else{
69121
69122 /* Determine whether or not this is a transaction savepoint. If so,
69123 ** and this is a RELEASE command, then the current transaction
69124 ** is committed.
69125 */
69126 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint;
69127 if( isTransaction && p1==SAVEPOINT_RELEASE ){
69128 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69129 goto vdbe_return;
69130 }
69131 db->autoCommit = 1;
69132 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69136,56 +69372,56 @@
69136 goto vdbe_return;
69137 }
69138 db->isTransactionSavepoint = 0;
69139 rc = p->rc;
69140 }else{
69141 iSavepoint = db->nSavepoint - iSavepoint - 1;
69142 if( p1==SAVEPOINT_ROLLBACK ){
69143 for(ii=0; ii<db->nDb; ii++){
69144 sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
69145 }
69146 }
69147 for(ii=0; ii<db->nDb; ii++){
69148 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
69149 if( rc!=SQLITE_OK ){
69150 goto abort_due_to_error;
69151 }
69152 }
69153 if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
69154 sqlite3ExpirePreparedStatements(db);
69155 sqlite3ResetAllSchemasOfConnection(db);
69156 db->flags = (db->flags | SQLITE_InternChanges);
69157 }
69158 }
69159
69160 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
69161 ** savepoints nested inside of the savepoint being operated on. */
69162 while( db->pSavepoint!=pSavepoint ){
69163 pTmp = db->pSavepoint;
69164 db->pSavepoint = pTmp->pNext;
69165 sqlite3DbFree(db, pTmp);
69166 db->nSavepoint--;
69167 }
69168
69169 /* If it is a RELEASE, then destroy the savepoint being operated on
69170 ** too. If it is a ROLLBACK TO, then set the number of deferred
69171 ** constraint violations present in the database to the value stored
69172 ** when the savepoint was created. */
69173 if( p1==SAVEPOINT_RELEASE ){
69174 assert( pSavepoint==db->pSavepoint );
69175 db->pSavepoint = pSavepoint->pNext;
69176 sqlite3DbFree(db, pSavepoint);
69177 if( !isTransaction ){
69178 db->nSavepoint--;
69179 }
69180 }else{
69181 db->nDeferredCons = pSavepoint->nDeferredCons;
69182 db->nDeferredImmCons = pSavepoint->nDeferredImmCons;
69183 }
69184
69185 if( !isTransaction ){
69186 rc = sqlite3VtabSavepoint(db, p1, iSavepoint);
69187 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69188 }
69189 }
69190 }
69191
@@ -69200,52 +69436,54 @@
69200 ** there are active writing VMs or active VMs that use shared cache.
69201 **
69202 ** This instruction causes the VM to halt.
69203 */
69204 case OP_AutoCommit: {
 
69205 int desiredAutoCommit;
69206 int iRollback;
69207 int turnOnAC;
 
69208
69209 desiredAutoCommit = pOp->p1;
69210 iRollback = pOp->p2;
69211 turnOnAC = desiredAutoCommit && !db->autoCommit;
69212 assert( desiredAutoCommit==1 || desiredAutoCommit==0 );
69213 assert( desiredAutoCommit==1 || iRollback==0 );
69214 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
69215 assert( p->bIsReader );
69216
69217 #if 0
69218 if( turnOnAC && iRollback && db->nVdbeActive>1 ){
69219 /* If this instruction implements a ROLLBACK and other VMs are
69220 ** still running, and a transaction is active, return an error indicating
69221 ** that the other VMs must complete first.
69222 */
69223 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69224 "SQL statements in progress");
69225 rc = SQLITE_BUSY;
69226 }else
69227 #endif
69228 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){
69229 /* If this instruction implements a COMMIT and other VMs are writing
69230 ** return an error indicating that the other VMs must complete first.
69231 */
69232 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69233 "SQL statements in progress");
69234 rc = SQLITE_BUSY;
69235 }else if( desiredAutoCommit!=db->autoCommit ){
69236 if( iRollback ){
69237 assert( desiredAutoCommit==1 );
69238 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69239 db->autoCommit = 1;
69240 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69241 goto vdbe_return;
69242 }else{
69243 db->autoCommit = (u8)desiredAutoCommit;
69244 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69245 p->pc = pc;
69246 db->autoCommit = (u8)(1-desiredAutoCommit);
69247 p->rc = rc = SQLITE_BUSY;
69248 goto vdbe_return;
69249 }
69250 }
69251 assert( db->nStatement==0 );
@@ -69256,14 +69494,14 @@
69256 rc = SQLITE_ERROR;
69257 }
69258 goto vdbe_return;
69259 }else{
69260 sqlite3SetString(&p->zErrMsg, db,
69261 (!desiredAutoCommit)?"cannot start a transaction within a transaction":(
69262 (iRollback)?"cannot rollback - no transaction is active":
69263 "cannot commit - no transaction is active"));
69264
69265 rc = SQLITE_ERROR;
69266 }
69267 break;
69268 }
69269
@@ -69297,46 +69535,48 @@
69297 ** will automatically commit when the VDBE halts.
69298 **
69299 ** If P2 is zero, then a read-lock is obtained on the database file.
69300 */
69301 case OP_Transaction: {
 
69302 Btree *pBt;
 
69303
69304 assert( p->bIsReader );
69305 assert( p->readOnly==0 || pOp->p2==0 );
69306 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69307 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69308 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69309 rc = SQLITE_READONLY;
69310 goto abort_due_to_error;
69311 }
69312 pBt = db->aDb[pOp->p1].pBt;
69313
69314 if( pBt ){
69315 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2);
69316 if( rc==SQLITE_BUSY ){
69317 p->pc = pc;
69318 p->rc = rc = SQLITE_BUSY;
69319 goto vdbe_return;
69320 }
69321 if( rc!=SQLITE_OK ){
69322 goto abort_due_to_error;
69323 }
69324
69325 if( pOp->p2 && p->usesStmtJournal
69326 && (db->autoCommit==0 || db->nVdbeRead>1)
69327 ){
69328 assert( sqlite3BtreeIsInTrans(pBt) );
69329 if( p->iStatement==0 ){
69330 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69331 db->nStatement++;
69332 p->iStatement = db->nSavepoint + db->nStatement;
69333 }
69334
69335 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69336 if( rc==SQLITE_OK ){
69337 rc = sqlite3BtreeBeginStmt(pBt, p->iStatement);
69338 }
69339
69340 /* Store the current value of the database handles deferred constraint
69341 ** counter. If the statement transaction needs to be rolled back,
69342 ** the value of this counter needs to be restored too. */
@@ -69358,24 +69598,26 @@
69358 ** There must be a read-lock on the database (either a transaction
69359 ** must be started or there must be an open cursor) before
69360 ** executing this instruction.
69361 */
69362 case OP_ReadCookie: { /* out2-prerelease */
 
69363 int iMeta;
69364 int iDb;
69365 int iCookie;
 
69366
69367 assert( p->bIsReader );
69368 iDb = pOp->p1;
69369 iCookie = pOp->p3;
69370 assert( pOp->p3<SQLITE_N_BTREE_META );
69371 assert( iDb>=0 && iDb<db->nDb );
69372 assert( db->aDb[iDb].pBt!=0 );
69373 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69374
69375 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
69376 pOut->u.i = iMeta;
69377 break;
69378 }
69379
69380 /* Opcode: SetCookie P1 P2 P3 * *
69381 **
@@ -69386,29 +69628,31 @@
69386 ** database file used to store temporary tables.
69387 **
69388 ** A transaction must be started before executing this opcode.
69389 */
69390 case OP_SetCookie: { /* in3 */
 
69391 Db *pDb;
 
69392 assert( pOp->p2<SQLITE_N_BTREE_META );
69393 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69394 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69395 assert( p->readOnly==0 );
69396 pDb = &db->aDb[pOp->p1];
69397 assert( pDb->pBt!=0 );
69398 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69399 pIn3 = &aMem[pOp->p3];
69400 sqlite3VdbeMemIntegerify(pIn3);
69401 /* See note about index shifting on OP_ReadCookie */
69402 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
69403 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69404 /* When the schema cookie changes, record the new cookie internally */
69405 pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69406 db->flags |= SQLITE_InternChanges;
69407 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69408 /* Record changes in the file format */
69409 pDb->pSchema->file_format = (u8)pIn3->u.i;
69410 }
69411 if( pOp->p1==1 ){
69412 /* Invalidate all prepared statements whenever the TEMP database
69413 ** schema is changed. Ticket #1644 */
69414 sqlite3ExpirePreparedStatements(db);
@@ -69434,42 +69678,44 @@
69434 ** Either a transaction needs to have been started or an OP_Open needs
69435 ** to be executed (to establish a read lock) before this opcode is
69436 ** invoked.
69437 */
69438 case OP_VerifyCookie: {
 
69439 int iMeta;
69440 int iGen;
69441 Btree *pBt;
 
69442
69443 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69444 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69445 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69446 assert( p->bIsReader );
69447 pBt = db->aDb[pOp->p1].pBt;
69448 if( pBt ){
69449 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69450 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69451 }else{
69452 iGen = iMeta = 0;
69453 }
69454 if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69455 sqlite3DbFree(db, p->zErrMsg);
69456 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69457 /* If the schema-cookie from the database file matches the cookie
69458 ** stored with the in-memory representation of the schema, do
69459 ** not reload the schema from the database file.
69460 **
69461 ** If virtual-tables are in use, this is not just an optimization.
69462 ** Often, v-tables store their data in other SQLite tables, which
69463 ** are queried from within xNext() and other v-table methods using
69464 ** prepared queries. If such a query is out-of-date, we do not want to
69465 ** discard the database schema, as the user code implementing the
69466 ** v-table would have to be ready for the sqlite3_vtab structure itself
69467 ** to be invalidated whenever sqlite3_step() is called from within
69468 ** a v-table method.
69469 */
69470 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69471 sqlite3ResetOneSchema(db, pOp->p1);
69472 }
69473
69474 p->expired = 1;
69475 rc = SQLITE_SCHEMA;
@@ -69528,18 +69774,20 @@
69528 **
69529 ** See also OpenRead.
69530 */
69531 case OP_OpenRead:
69532 case OP_OpenWrite: {
 
69533 int nField;
69534 KeyInfo *pKeyInfo;
69535 int p2;
69536 int iDb;
69537 int wrFlag;
69538 Btree *pX;
69539 VdbeCursor *pCur;
69540 Db *pDb;
 
69541
69542 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69543 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69544 assert( p->bIsReader );
69545 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69547,74 +69795,74 @@
69547 if( p->expired ){
69548 rc = SQLITE_ABORT;
69549 break;
69550 }
69551
69552 nField = 0;
69553 pKeyInfo = 0;
69554 p2 = pOp->p2;
69555 iDb = pOp->p3;
69556 assert( iDb>=0 && iDb<db->nDb );
69557 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
69558 pDb = &db->aDb[iDb];
69559 pX = pDb->pBt;
69560 assert( pX!=0 );
69561 if( pOp->opcode==OP_OpenWrite ){
69562 wrFlag = 1;
69563 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
69564 if( pDb->pSchema->file_format < p->minWriteFileFormat ){
69565 p->minWriteFileFormat = pDb->pSchema->file_format;
69566 }
69567 }else{
69568 wrFlag = 0;
69569 }
69570 if( pOp->p5 & OPFLAG_P2ISREG ){
69571 assert( p2>0 );
69572 assert( p2<=(p->nMem-p->nCursor) );
69573 pIn2 = &aMem[p2];
69574 assert( memIsValid(pIn2) );
69575 assert( (pIn2->flags & MEM_Int)!=0 );
69576 sqlite3VdbeMemIntegerify(pIn2);
69577 p2 = (int)pIn2->u.i;
69578 /* The p2 value always comes from a prior OP_CreateTable opcode and
69579 ** that opcode will always set the p2 value to 2 or more or else fail.
69580 ** If there were a failure, the prepared statement would have halted
69581 ** before reaching this instruction. */
69582 if( NEVER(p2<2) ) {
69583 rc = SQLITE_CORRUPT_BKPT;
69584 goto abort_due_to_error;
69585 }
69586 }
69587 if( pOp->p4type==P4_KEYINFO ){
69588 pKeyInfo = pOp->p4.pKeyInfo;
69589 assert( pKeyInfo->enc==ENC(db) );
69590 assert( pKeyInfo->db==db );
69591 nField = pKeyInfo->nField+pKeyInfo->nXField;
69592 }else if( pOp->p4type==P4_INT32 ){
69593 nField = pOp->p4.i;
69594 }
69595 assert( pOp->p1>=0 );
69596 assert( nField>=0 );
69597 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
69598 pCur = allocateCursor(p, pOp->p1, nField, iDb, 1);
69599 if( pCur==0 ) goto no_mem;
69600 pCur->nullRow = 1;
69601 pCur->isOrdered = 1;
69602 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
69603 pCur->pKeyInfo = pKeyInfo;
69604 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69605 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69606
69607 /* Since it performs no memory allocation or IO, the only value that
69608 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69609 assert( rc==SQLITE_OK );
69610
69611 /* Set the VdbeCursor.isTable variable. Previous versions of
69612 ** SQLite used to check if the root-page flags were sane at this point
69613 ** and report database corruption if they were not, but this check has
69614 ** since moved into the btree layer. */
69615 pCur->isTable = pOp->p4type!=P4_KEYINFO;
69616 break;
69617 }
69618
69619 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69620 ** Synopsis: nColumn=P2
@@ -69642,53 +69890,55 @@
69642 ** by this opcode will be used for automatically created transient
69643 ** indices in joins.
69644 */
69645 case OP_OpenAutoindex:
69646 case OP_OpenEphemeral: {
 
69647 VdbeCursor *pCx;
69648 KeyInfo *pKeyInfo;
 
69649
69650 static const int vfsFlags =
69651 SQLITE_OPEN_READWRITE |
69652 SQLITE_OPEN_CREATE |
69653 SQLITE_OPEN_EXCLUSIVE |
69654 SQLITE_OPEN_DELETEONCLOSE |
69655 SQLITE_OPEN_TRANSIENT_DB;
69656 assert( pOp->p1>=0 );
69657 assert( pOp->p2>=0 );
69658 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69659 if( pCx==0 ) goto no_mem;
69660 pCx->nullRow = 1;
69661 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
69662 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69663 if( rc==SQLITE_OK ){
69664 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
69665 }
69666 if( rc==SQLITE_OK ){
69667 /* If a transient index is required, create it by calling
69668 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69669 ** opening it. If a transient table is required, just use the
69670 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69671 */
69672 if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69673 int pgno;
69674 assert( pOp->p4type==P4_KEYINFO );
69675 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69676 if( rc==SQLITE_OK ){
69677 assert( pgno==MASTER_ROOT+1 );
69678 assert( pKeyInfo->db==db );
69679 assert( pKeyInfo->enc==ENC(db) );
69680 pCx->pKeyInfo = pKeyInfo;
69681 rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor);
69682 }
69683 pCx->isTable = 0;
69684 }else{
69685 rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor);
69686 pCx->isTable = 1;
69687 }
69688 }
69689 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69690 break;
69691 }
69692
69693 /* Opcode: SorterOpen P1 * * P4 *
69694 **
@@ -69695,20 +69945,22 @@
69695 ** This opcode works like OP_OpenEphemeral except that it opens
69696 ** a transient index that is specifically designed to sort large
69697 ** tables using an external merge-sort algorithm.
69698 */
69699 case OP_SorterOpen: {
 
69700 VdbeCursor *pCx;
 
69701
69702 assert( pOp->p1>=0 );
69703 assert( pOp->p2>=0 );
69704 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69705 if( pCx==0 ) goto no_mem;
69706 pCx->pKeyInfo = pOp->p4.pKeyInfo;
69707 assert( pCx->pKeyInfo->db==db );
69708 assert( pCx->pKeyInfo->enc==ENC(db) );
69709 rc = sqlite3VdbeSorterInit(db, pCx);
69710 break;
69711 }
69712
69713 /* Opcode: OpenPseudo P1 P2 P3 * P5
69714 ** Synopsis: content in r[P2@P3]
@@ -69726,20 +69978,22 @@
69726 **
69727 ** P3 is the number of fields in the records that will be stored by
69728 ** the pseudo-table.
69729 */
69730 case OP_OpenPseudo: {
 
69731 VdbeCursor *pCx;
 
69732
69733 assert( pOp->p1>=0 );
69734 assert( pOp->p3>=0 );
69735 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69736 if( pCx==0 ) goto no_mem;
69737 pCx->nullRow = 1;
69738 pCx->pseudoTableReg = pOp->p2;
69739 pCx->isTable = 1;
69740 pCx->multiPseudo = pOp->p5;
69741 break;
69742 }
69743
69744 /* Opcode: Close P1 * * * *
69745 **
@@ -69811,37 +70065,39 @@
69811 */
69812 case OP_SeekLt: /* jump, in3 */
69813 case OP_SeekLe: /* jump, in3 */
69814 case OP_SeekGe: /* jump, in3 */
69815 case OP_SeekGt: { /* jump, in3 */
 
69816 int res;
69817 int oc;
69818 VdbeCursor *pC;
69819 UnpackedRecord r;
69820 int nField;
69821 i64 iKey; /* The rowid we are to seek to */
 
69822
69823 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69824 assert( pOp->p2!=0 );
69825 pC = p->apCsr[pOp->p1];
69826 assert( pC!=0 );
69827 assert( pC->pseudoTableReg==0 );
69828 assert( OP_SeekLe == OP_SeekLt+1 );
69829 assert( OP_SeekGe == OP_SeekLt+2 );
69830 assert( OP_SeekGt == OP_SeekLt+3 );
69831 assert( pC->isOrdered );
69832 assert( pC->pCursor!=0 );
69833 oc = pOp->opcode;
69834 pC->nullRow = 0;
69835 if( pC->isTable ){
69836 /* The input value in P3 might be of any type: integer, real, string,
69837 ** blob, or NULL. But it needs to be an integer before we can do
69838 ** the seek, so covert it. */
69839 pIn3 = &aMem[pOp->p3];
69840 applyNumericAffinity(pIn3);
69841 iKey = sqlite3VdbeIntValue(pIn3);
69842 pC->rowidIsValid = 0;
69843
69844 /* If the P3 value could not be converted into an integer without
69845 ** loss of information, then special processing is required... */
69846 if( (pIn3->flags & MEM_Int)==0 ){
69847 if( (pIn3->flags & MEM_Real)==0 ){
@@ -69849,100 +70105,100 @@
69849 ** then the seek is not possible, so jump to P2 */
69850 pc = pOp->p2 - 1;
69851 break;
69852 }
69853
69854 /* If the approximation iKey is larger than the actual real search
69855 ** term, substitute >= for > and < for <=. e.g. if the search term
69856 ** is 4.9 and the integer approximation 5:
69857 **
69858 ** (x > 4.9) -> (x >= 5)
69859 ** (x <= 4.9) -> (x < 5)
69860 */
69861 if( pIn3->r<(double)iKey ){
69862 assert( OP_SeekGe==(OP_SeekGt-1) );
69863 assert( OP_SeekLt==(OP_SeekLe-1) );
69864 assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69865 if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
69866 }
69867
69868 /* If the approximation iKey is smaller than the actual real search
69869 ** term, substitute <= for < and > for >=. */
69870 else if( pIn3->r>(double)iKey ){
69871 assert( OP_SeekLe==(OP_SeekLt+1) );
69872 assert( OP_SeekGt==(OP_SeekGe+1) );
69873 assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69874 if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
69875 }
69876 }
69877 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
69878 if( rc!=SQLITE_OK ){
69879 goto abort_due_to_error;
69880 }
69881 if( res==0 ){
69882 pC->rowidIsValid = 1;
69883 pC->lastRowid = iKey;
69884 }
69885 }else{
69886 nField = pOp->p4.i;
69887 assert( pOp->p4type==P4_INT32 );
69888 assert( nField>0 );
69889 r.pKeyInfo = pC->pKeyInfo;
69890 r.nField = (u16)nField;
69891
69892 /* The next line of code computes as follows, only faster:
69893 ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
69894 ** r.flags = UNPACKED_INCRKEY;
69895 ** }else{
69896 ** r.flags = 0;
69897 ** }
69898 */
69899 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
69900 assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
69901 assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
69902 assert( oc!=OP_SeekGe || r.flags==0 );
69903 assert( oc!=OP_SeekLt || r.flags==0 );
69904
69905 r.aMem = &aMem[pOp->p3];
69906 #ifdef SQLITE_DEBUG
69907 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
69908 #endif
69909 ExpandBlob(r.aMem);
69910 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res);
69911 if( rc!=SQLITE_OK ){
69912 goto abort_due_to_error;
69913 }
69914 pC->rowidIsValid = 0;
69915 }
69916 pC->deferredMoveto = 0;
69917 pC->cacheStatus = CACHE_STALE;
69918 #ifdef SQLITE_TEST
69919 sqlite3_search_count++;
69920 #endif
69921 if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
69922 if( res<0 || (res==0 && oc==OP_SeekGt) ){
69923 rc = sqlite3BtreeNext(pC->pCursor, &res);
69924 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69925 pC->rowidIsValid = 0;
69926 }else{
69927 res = 0;
69928 }
69929 }else{
69930 assert( oc==OP_SeekLt || oc==OP_SeekLe );
69931 if( res>0 || (res==0 && oc==OP_SeekLt) ){
69932 rc = sqlite3BtreePrevious(pC->pCursor, &res);
69933 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69934 pC->rowidIsValid = 0;
69935 }else{
69936 /* res might be negative because the table is empty. Check to
69937 ** see if this is the case.
69938 */
69939 res = sqlite3BtreeEof(pC->pCursor);
69940 }
69941 }
69942 assert( pOp->p2>0 );
69943 if( res ){
69944 pc = pOp->p2 - 1;
69945 }
69946 break;
69947 }
69948
@@ -69955,22 +70211,24 @@
69955 ** This is actually a deferred seek. Nothing actually happens until
69956 ** the cursor is used to read a record. That way, if no reads
69957 ** occur, no unnecessary I/O happens.
69958 */
69959 case OP_Seek: { /* in2 */
 
69960 VdbeCursor *pC;
 
69961
69962 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69963 pC = p->apCsr[pOp->p1];
69964 assert( pC!=0 );
69965 assert( pC->pCursor!=0 );
69966 assert( pC->isTable );
69967 pC->nullRow = 0;
69968 pIn2 = &aMem[pOp->p2];
69969 pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
69970 pC->rowidIsValid = 0;
69971 pC->deferredMoveto = 1;
69972 break;
69973 }
69974
69975
69976 /* Opcode: Found P1 P2 P3 P4 *
@@ -70021,83 +70279,85 @@
70021 ** See also: NotFound, Found, NotExists
70022 */
70023 case OP_NoConflict: /* jump, in3 */
70024 case OP_NotFound: /* jump, in3 */
70025 case OP_Found: { /* jump, in3 */
 
70026 int alreadyExists;
70027 int ii;
70028 VdbeCursor *pC;
70029 int res;
70030 char *pFree;
70031 UnpackedRecord *pIdxKey;
70032 UnpackedRecord r;
70033 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
 
70034
70035 #ifdef SQLITE_TEST
70036 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
70037 #endif
70038
 
70039 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70040 assert( pOp->p4type==P4_INT32 );
70041 pC = p->apCsr[pOp->p1];
70042 assert( pC!=0 );
70043 pIn3 = &aMem[pOp->p3];
70044 assert( pC->pCursor!=0 );
70045 assert( pC->isTable==0 );
70046 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
70047 if( pOp->p4.i>0 ){
70048 r.pKeyInfo = pC->pKeyInfo;
70049 r.nField = (u16)pOp->p4.i;
70050 r.aMem = pIn3;
70051 #ifdef SQLITE_DEBUG
70052 {
70053 int i;
70054 for(i=0; i<r.nField; i++){
70055 assert( memIsValid(&r.aMem[i]) );
70056 if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
70057 }
70058 }
70059 #endif
70060 r.flags = UNPACKED_PREFIX_MATCH;
70061 pIdxKey = &r;
70062 }else{
70063 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70064 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
70065 );
70066 if( pIdxKey==0 ) goto no_mem;
70067 assert( pIn3->flags & MEM_Blob );
70068 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70069 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
70070 pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70071 }
70072 if( pOp->opcode==OP_NoConflict ){
70073 /* For the OP_NoConflict opcode, take the jump if any of the
70074 ** input fields are NULL, since any key with a NULL will not
70075 ** conflict */
70076 for(ii=0; ii<r.nField; ii++){
70077 if( r.aMem[ii].flags & MEM_Null ){
70078 pc = pOp->p2 - 1;
70079 break;
70080 }
70081 }
70082 }
70083 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
70084 if( pOp->p4.i==0 ){
70085 sqlite3DbFree(db, pFree);
70086 }
70087 if( rc!=SQLITE_OK ){
70088 break;
70089 }
70090 pC->seekResult = res;
70091 alreadyExists = (res==0);
70092 pC->nullRow = 1-alreadyExists;
70093 pC->deferredMoveto = 0;
70094 pC->cacheStatus = CACHE_STALE;
70095 if( pOp->opcode==OP_Found ){
70096 if( alreadyExists ) pc = pOp->p2 - 1;
70097 }else{
70098 if( !alreadyExists ) pc = pOp->p2 - 1;
70099 }
70100 break;
70101 }
70102
70103 /* Opcode: NotExists P1 P2 P3 * *
@@ -70113,37 +70373,39 @@
70113 ** (with arbitrary multi-value keys).
70114 **
70115 ** See also: Found, NotFound, NoConflict
70116 */
70117 case OP_NotExists: { /* jump, in3 */
 
70118 VdbeCursor *pC;
70119 BtCursor *pCrsr;
70120 int res;
70121 u64 iKey;
 
70122
70123 pIn3 = &aMem[pOp->p3];
70124 assert( pIn3->flags & MEM_Int );
70125 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70126 pC = p->apCsr[pOp->p1];
70127 assert( pC!=0 );
70128 assert( pC->isTable );
70129 assert( pC->pseudoTableReg==0 );
70130 pCrsr = pC->pCursor;
70131 assert( pCrsr!=0 );
70132 res = 0;
70133 iKey = pIn3->u.i;
70134 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
70135 pC->lastRowid = pIn3->u.i;
70136 pC->rowidIsValid = res==0 ?1:0;
70137 pC->nullRow = 0;
70138 pC->cacheStatus = CACHE_STALE;
70139 pC->deferredMoveto = 0;
70140 if( res!=0 ){
70141 pc = pOp->p2 - 1;
70142 assert( pC->rowidIsValid==0 );
70143 }
70144 pC->seekResult = res;
70145 break;
70146 }
70147
70148 /* Opcode: Sequence P1 P2 * * *
70149 ** Synopsis: r[P2]=rowid
@@ -70175,23 +70437,25 @@
70175 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
70176 ** generated record number. This P3 mechanism is used to help implement the
70177 ** AUTOINCREMENT feature.
70178 */
70179 case OP_NewRowid: { /* out2-prerelease */
 
70180 i64 v; /* The new rowid */
70181 VdbeCursor *pC; /* Cursor of table to get the new rowid */
70182 int res; /* Result of an sqlite3BtreeLast() */
70183 int cnt; /* Counter to limit the number of searches */
70184 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
70185 VdbeFrame *pFrame; /* Root frame of VDBE */
 
70186
70187 v = 0;
70188 res = 0;
70189 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70190 pC = p->apCsr[pOp->p1];
70191 assert( pC!=0 );
70192 if( NEVER(pC->pCursor==0) ){
70193 /* The zero initialization above is all that is needed */
70194 }else{
70195 /* The next rowid or record number (different terms for the same
70196 ** thing) is obtained in a two-step algorithm.
70197 **
@@ -70203,11 +70467,11 @@
70203 ** The second algorithm is to select a rowid at random and see if
70204 ** it already exists in the table. If it does not exist, we have
70205 ** succeeded. If the random rowid does exist, we select a new one
70206 ** and try again, up to 100 times.
70207 */
70208 assert( pC->isTable );
70209
70210 #ifdef SQLITE_32BIT_ROWID
70211 # define MAX_ROWID 0x7fffffff
70212 #else
70213 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70215,101 +70479,101 @@
70215 ** to provide the constant while making all compilers happy.
70216 */
70217 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70218 #endif
70219
70220 if( !pC->useRandomRowid ){
70221 v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70222 if( v==0 ){
70223 rc = sqlite3BtreeLast(pC->pCursor, &res);
70224 if( rc!=SQLITE_OK ){
70225 goto abort_due_to_error;
70226 }
70227 if( res ){
70228 v = 1; /* IMP: R-61914-48074 */
70229 }else{
70230 assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70231 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70232 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70233 if( v>=MAX_ROWID ){
70234 pC->useRandomRowid = 1;
70235 }else{
70236 v++; /* IMP: R-29538-34987 */
70237 }
70238 }
70239 }
70240
70241 #ifndef SQLITE_OMIT_AUTOINCREMENT
70242 if( pOp->p3 ){
70243 /* Assert that P3 is a valid memory cell. */
70244 assert( pOp->p3>0 );
70245 if( p->pFrame ){
70246 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70247 /* Assert that P3 is a valid memory cell. */
70248 assert( pOp->p3<=pFrame->nMem );
70249 pMem = &pFrame->aMem[pOp->p3];
70250 }else{
70251 /* Assert that P3 is a valid memory cell. */
70252 assert( pOp->p3<=(p->nMem-p->nCursor) );
70253 pMem = &aMem[pOp->p3];
70254 memAboutToChange(p, pMem);
70255 }
70256 assert( memIsValid(pMem) );
70257
70258 REGISTER_TRACE(pOp->p3, pMem);
70259 sqlite3VdbeMemIntegerify(pMem);
70260 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70261 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70262 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70263 goto abort_due_to_error;
70264 }
70265 if( v<pMem->u.i+1 ){
70266 v = pMem->u.i + 1;
70267 }
70268 pMem->u.i = v;
70269 }
70270 #endif
70271
70272 sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70273 }
70274 if( pC->useRandomRowid ){
70275 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70276 ** largest possible integer (9223372036854775807) then the database
70277 ** engine starts picking positive candidate ROWIDs at random until
70278 ** it finds one that is not previously used. */
70279 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
70280 ** an AUTOINCREMENT table. */
70281 /* on the first attempt, simply do one more than previous */
70282 v = lastRowid;
70283 v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70284 v++; /* ensure non-zero */
70285 cnt = 0;
70286 while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v,
70287 0, &res))==SQLITE_OK)
70288 && (res==0)
70289 && (++cnt<100)){
70290 /* collision - try another random rowid */
70291 sqlite3_randomness(sizeof(v), &v);
70292 if( cnt<5 ){
70293 /* try "small" random rowids for the initial attempts */
70294 v &= 0xffffff;
70295 }else{
70296 v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70297 }
70298 v++; /* ensure non-zero */
70299 }
70300 if( rc==SQLITE_OK && res==0 ){
70301 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
70302 goto abort_due_to_error;
70303 }
70304 assert( v>0 ); /* EV: R-40812-03570 */
70305 }
70306 pC->rowidIsValid = 0;
70307 pC->deferredMoveto = 0;
70308 pC->cacheStatus = CACHE_STALE;
70309 }
70310 pOut->u.i = v;
70311 break;
70312 }
70313
70314 /* Opcode: Insert P1 P2 P3 P4 P5
70315 ** Synopsis: intkey=r[P3] data=r[P2]
@@ -70357,72 +70621,74 @@
70357 ** This works exactly like OP_Insert except that the key is the
70358 ** integer value P3, not the value of the integer stored in register P3.
70359 */
70360 case OP_Insert:
70361 case OP_InsertInt: {
 
70362 Mem *pData; /* MEM cell holding data for the record to be inserted */
70363 Mem *pKey; /* MEM cell holding key for the record */
70364 i64 iKey; /* The integer ROWID or key for the record to be inserted */
70365 VdbeCursor *pC; /* Cursor to table into which insert is written */
70366 int nZero; /* Number of zero-bytes to append */
70367 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
70368 const char *zDb; /* database name - used by the update hook */
70369 const char *zTbl; /* Table name - used by the opdate hook */
70370 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
 
70371
70372 pData = &aMem[pOp->p2];
70373 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70374 assert( memIsValid(pData) );
70375 pC = p->apCsr[pOp->p1];
70376 assert( pC!=0 );
70377 assert( pC->pCursor!=0 );
70378 assert( pC->pseudoTableReg==0 );
70379 assert( pC->isTable );
70380 REGISTER_TRACE(pOp->p2, pData);
70381
70382 if( pOp->opcode==OP_Insert ){
70383 pKey = &aMem[pOp->p3];
70384 assert( pKey->flags & MEM_Int );
70385 assert( memIsValid(pKey) );
70386 REGISTER_TRACE(pOp->p3, pKey);
70387 iKey = pKey->u.i;
70388 }else{
70389 assert( pOp->opcode==OP_InsertInt );
70390 iKey = pOp->p3;
70391 }
70392
70393 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70394 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey;
70395 if( pData->flags & MEM_Null ){
70396 pData->z = 0;
70397 pData->n = 0;
70398 }else{
70399 assert( pData->flags & (MEM_Blob|MEM_Str) );
70400 }
70401 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0);
70402 if( pData->flags & MEM_Zero ){
70403 nZero = pData->u.nZero;
70404 }else{
70405 nZero = 0;
70406 }
70407 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70408 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70409 pData->z, pData->n, nZero,
70410 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
70411 );
70412 pC->rowidIsValid = 0;
70413 pC->deferredMoveto = 0;
70414 pC->cacheStatus = CACHE_STALE;
70415
70416 /* Invoke the update-hook if required. */
70417 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70418 zDb = db->aDb[pC->iDb].zName;
70419 zTbl = pOp->p4.z;
70420 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70421 assert( pC->isTable );
70422 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey);
70423 assert( pC->iDb>=0 );
70424 }
70425 break;
70426 }
70427
70428 /* Opcode: Delete P1 P2 * P4 *
@@ -70444,39 +70710,41 @@
70444 ** pointing to. The update hook will be invoked, if it exists.
70445 ** If P4 is not NULL then the P1 cursor must have been positioned
70446 ** using OP_NotFound prior to invoking this opcode.
70447 */
70448 case OP_Delete: {
 
70449 i64 iKey;
70450 VdbeCursor *pC;
 
70451
70452 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70453 pC = p->apCsr[pOp->p1];
70454 assert( pC!=0 );
70455 assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70456 iKey = pC->lastRowid; /* Only used for the update hook */
70457
70458 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
70459 ** OP_Column on the same table without any intervening operations that
70460 ** might move or invalidate the cursor. Hence cursor pC is always pointing
70461 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
70462 ** below is always a no-op and cannot fail. We will run it anyhow, though,
70463 ** to guard against future changes to the code generator.
70464 **/
70465 assert( pC->deferredMoveto==0 );
70466 rc = sqlite3VdbeCursorMoveto(pC);
70467 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70468
70469 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70470 rc = sqlite3BtreeDelete(pC->pCursor);
70471 pC->cacheStatus = CACHE_STALE;
70472
70473 /* Invoke the update-hook if required. */
70474 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
70475 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
70476 db->aDb[pC->iDb].zName, pOp->p4.z, iKey);
70477 assert( pC->iDb>=0 );
70478 }
70479 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
70480 break;
70481 }
70482 /* Opcode: ResetCount * * * * *
@@ -70506,21 +70774,23 @@
70506 **
70507 ** Fall through to next instruction if the two records compare equal to
70508 ** each other. Jump to P2 if they are different.
70509 */
70510 case OP_SorterCompare: {
 
70511 VdbeCursor *pC;
70512 int res;
70513 int nIgnore;
 
70514
70515 pC = p->apCsr[pOp->p1];
70516 assert( isSorter(pC) );
70517 assert( pOp->p4type==P4_INT32 );
70518 pIn3 = &aMem[pOp->p3];
70519 nIgnore = pOp->p4.i;
70520 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70521 if( res ){
70522 pc = pOp->p2-1;
70523 }
70524 break;
70525 };
70526
@@ -70528,16 +70798,18 @@
70528 ** Synopsis: r[P2]=data
70529 **
70530 ** Write into register P2 the current sorter data for sorter cursor P1.
70531 */
70532 case OP_SorterData: {
 
70533 VdbeCursor *pC;
 
70534
70535 pOut = &aMem[pOp->p2];
70536 pC = p->apCsr[pOp->p1];
70537 assert( isSorter(pC) );
70538 rc = sqlite3VdbeSorterRowkey(pC, pOut);
70539 break;
70540 }
70541
70542 /* Opcode: RowData P1 P2 * * *
70543 ** Synopsis: r[P2]=data
@@ -70561,64 +70833,66 @@
70561 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70562 ** of a real table, not a pseudo-table.
70563 */
70564 case OP_RowKey:
70565 case OP_RowData: {
 
70566 VdbeCursor *pC;
70567 BtCursor *pCrsr;
70568 u32 n;
70569 i64 n64;
 
70570
70571 pOut = &aMem[pOp->p2];
70572 memAboutToChange(p, pOut);
70573
70574 /* Note that RowKey and RowData are really exactly the same instruction */
70575 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70576 pC = p->apCsr[pOp->p1];
70577 assert( isSorter(pC)==0 );
70578 assert( pC->isTable || pOp->opcode!=OP_RowData );
70579 assert( pC->isTable==0 || pOp->opcode==OP_RowData );
70580 assert( pC!=0 );
70581 assert( pC->nullRow==0 );
70582 assert( pC->pseudoTableReg==0 );
70583 assert( pC->pCursor!=0 );
70584 pCrsr = pC->pCursor;
70585 assert( sqlite3BtreeCursorIsValid(pCrsr) );
70586
70587 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
70588 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
70589 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
70590 ** a no-op and can never fail. But we leave it in place as a safety.
70591 */
70592 assert( pC->deferredMoveto==0 );
70593 rc = sqlite3VdbeCursorMoveto(pC);
70594 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70595
70596 if( pC->isTable==0 ){
70597 assert( !pC->isTable );
70598 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64);
70599 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70600 if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70601 goto too_big;
70602 }
70603 n = (u32)n64;
70604 }else{
70605 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n);
70606 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70607 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70608 goto too_big;
70609 }
70610 }
70611 if( sqlite3VdbeMemGrow(pOut, n, 0) ){
70612 goto no_mem;
70613 }
70614 pOut->n = n;
70615 MemSetTypeFlag(pOut, MEM_Blob);
70616 if( pC->isTable==0 ){
70617 rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z);
70618 }else{
70619 rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z);
70620 }
70621 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70622 UPDATE_MAX_BLOBSIZE(pOut);
70623 REGISTER_TRACE(pOp->p2, pOut);
70624 break;
@@ -70633,44 +70907,46 @@
70633 ** P1 can be either an ordinary table or a virtual table. There used to
70634 ** be a separate OP_VRowid opcode for use with virtual tables, but this
70635 ** one opcode now works for both table types.
70636 */
70637 case OP_Rowid: { /* out2-prerelease */
 
70638 VdbeCursor *pC;
70639 i64 v;
70640 sqlite3_vtab *pVtab;
70641 const sqlite3_module *pModule;
 
70642
70643 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70644 pC = p->apCsr[pOp->p1];
70645 assert( pC!=0 );
70646 assert( pC->pseudoTableReg==0 || pC->nullRow );
70647 if( pC->nullRow ){
70648 pOut->flags = MEM_Null;
70649 break;
70650 }else if( pC->deferredMoveto ){
70651 v = pC->movetoTarget;
70652 #ifndef SQLITE_OMIT_VIRTUALTABLE
70653 }else if( pC->pVtabCursor ){
70654 pVtab = pC->pVtabCursor->pVtab;
70655 pModule = pVtab->pModule;
70656 assert( pModule->xRowid );
70657 rc = pModule->xRowid(pC->pVtabCursor, &v);
70658 sqlite3VtabImportErrmsg(p, pVtab);
70659 #endif /* SQLITE_OMIT_VIRTUALTABLE */
70660 }else{
70661 assert( pC->pCursor!=0 );
70662 rc = sqlite3VdbeCursorMoveto(pC);
70663 if( rc ) goto abort_due_to_error;
70664 if( pC->rowidIsValid ){
70665 v = pC->lastRowid;
70666 }else{
70667 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70668 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
70669 }
70670 }
70671 pOut->u.i = v;
70672 break;
70673 }
70674
70675 /* Opcode: NullRow P1 * * * *
70676 **
@@ -70677,21 +70953,23 @@
70677 ** Move the cursor P1 to a null row. Any OP_Column operations
70678 ** that occur while the cursor is on the null row will always
70679 ** write a NULL.
70680 */
70681 case OP_NullRow: {
 
70682 VdbeCursor *pC;
 
70683
70684 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70685 pC = p->apCsr[pOp->p1];
70686 assert( pC!=0 );
70687 pC->nullRow = 1;
70688 pC->rowidIsValid = 0;
70689 pC->cacheStatus = CACHE_STALE;
70690 assert( pC->pCursor || pC->pVtabCursor );
70691 if( pC->pCursor ){
70692 sqlite3BtreeClearCursor(pC->pCursor);
70693 }
70694 break;
70695 }
70696
70697 /* Opcode: Last P1 P2 * * *
@@ -70701,26 +70979,28 @@
70701 ** If the table or index is empty and P2>0, then jump immediately to P2.
70702 ** If P2 is 0 or if the table or index is not empty, fall through
70703 ** to the following instruction.
70704 */
70705 case OP_Last: { /* jump */
 
70706 VdbeCursor *pC;
70707 BtCursor *pCrsr;
70708 int res;
 
70709
70710 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70711 pC = p->apCsr[pOp->p1];
70712 assert( pC!=0 );
70713 pCrsr = pC->pCursor;
70714 res = 0;
70715 assert( pCrsr!=0 );
70716 rc = sqlite3BtreeLast(pCrsr, &res);
70717 pC->nullRow = (u8)res;
70718 pC->deferredMoveto = 0;
70719 pC->rowidIsValid = 0;
70720 pC->cacheStatus = CACHE_STALE;
70721 if( pOp->p2>0 && res ){
70722 pc = pOp->p2 - 1;
70723 }
70724 break;
70725 }
70726
@@ -70753,32 +71033,34 @@
70753 ** If the table or index is empty and P2>0, then jump immediately to P2.
70754 ** If P2 is 0 or if the table or index is not empty, fall through
70755 ** to the following instruction.
70756 */
70757 case OP_Rewind: { /* jump */
 
70758 VdbeCursor *pC;
70759 BtCursor *pCrsr;
70760 int res;
 
70761
70762 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70763 pC = p->apCsr[pOp->p1];
70764 assert( pC!=0 );
70765 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
70766 res = 1;
70767 if( isSorter(pC) ){
70768 rc = sqlite3VdbeSorterRewind(db, pC, &res);
70769 }else{
70770 pCrsr = pC->pCursor;
70771 assert( pCrsr );
70772 rc = sqlite3BtreeFirst(pCrsr, &res);
70773 pC->deferredMoveto = 0;
70774 pC->cacheStatus = CACHE_STALE;
70775 pC->rowidIsValid = 0;
70776 }
70777 pC->nullRow = (u8)res;
70778 assert( pOp->p2>0 && pOp->p2<p->nOp );
70779 if( res ){
70780 pc = pOp->p2 - 1;
70781 }
70782 break;
70783 }
70784
@@ -70825,47 +71107,49 @@
70825 **
70826 ** This opcode works just like OP_Prev except that if cursor P1 is not
70827 ** open it behaves a no-op.
70828 */
70829 case OP_SorterNext: { /* jump */
 
70830 VdbeCursor *pC;
70831 int res;
 
70832
70833 pC = p->apCsr[pOp->p1];
70834 assert( isSorter(pC) );
70835 rc = sqlite3VdbeSorterNext(db, pC, &res);
70836 goto next_tail;
70837 case OP_PrevIfOpen: /* jump */
70838 case OP_NextIfOpen: /* jump */
70839 if( p->apCsr[pOp->p1]==0 ) break;
70840 /* Fall through */
70841 case OP_Prev: /* jump */
70842 case OP_Next: /* jump */
70843 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70844 assert( pOp->p5<ArraySize(p->aCounter) );
70845 pC = p->apCsr[pOp->p1];
70846 assert( pC!=0 );
70847 assert( pC->deferredMoveto==0 );
70848 assert( pC->pCursor );
70849 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
70850 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
70851 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
70852 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
70853 rc = pOp->p4.xAdvance(pC->pCursor, &res);
70854 next_tail:
70855 pC->cacheStatus = CACHE_STALE;
70856 if( res==0 ){
70857 pC->nullRow = 0;
70858 pc = pOp->p2 - 1;
70859 p->aCounter[pOp->p5]++;
70860 #ifdef SQLITE_TEST
70861 sqlite3_search_count++;
70862 #endif
70863 }else{
70864 pC->nullRow = 1;
70865 }
70866 pC->rowidIsValid = 0;
70867 goto check_for_interrupt;
70868 }
70869
70870 /* Opcode: IdxInsert P1 P2 P3 * P5
70871 ** Synopsis: key=r[P2]
@@ -70880,37 +71164,39 @@
70880 ** This instruction only works for indices. The equivalent instruction
70881 ** for tables is OP_Insert.
70882 */
70883 case OP_SorterInsert: /* in2 */
70884 case OP_IdxInsert: { /* in2 */
 
70885 VdbeCursor *pC;
70886 BtCursor *pCrsr;
70887 int nKey;
70888 const char *zKey;
 
70889
70890 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70891 pC = p->apCsr[pOp->p1];
70892 assert( pC!=0 );
70893 assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) );
70894 pIn2 = &aMem[pOp->p2];
70895 assert( pIn2->flags & MEM_Blob );
70896 pCrsr = pC->pCursor;
70897 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70898 assert( pCrsr!=0 );
70899 assert( pC->isTable==0 );
70900 rc = ExpandBlob(pIn2);
70901 if( rc==SQLITE_OK ){
70902 if( isSorter(pC) ){
70903 rc = sqlite3VdbeSorterWrite(db, pC, pIn2);
70904 }else{
70905 nKey = pIn2->n;
70906 zKey = pIn2->z;
70907 rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3,
70908 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
70909 );
70910 assert( pC->deferredMoveto==0 );
70911 pC->cacheStatus = CACHE_STALE;
70912 }
70913 }
70914 break;
70915 }
70916
@@ -70920,36 +71206,38 @@
70920 ** The content of P3 registers starting at register P2 form
70921 ** an unpacked index key. This opcode removes that entry from the
70922 ** index opened by cursor P1.
70923 */
70924 case OP_IdxDelete: {
 
70925 VdbeCursor *pC;
70926 BtCursor *pCrsr;
70927 int res;
70928 UnpackedRecord r;
 
70929
70930 assert( pOp->p3>0 );
70931 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
70932 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70933 pC = p->apCsr[pOp->p1];
70934 assert( pC!=0 );
70935 pCrsr = pC->pCursor;
70936 assert( pCrsr!=0 );
70937 assert( pOp->p5==0 );
70938 r.pKeyInfo = pC->pKeyInfo;
70939 r.nField = (u16)pOp->p3;
70940 r.flags = UNPACKED_PREFIX_MATCH;
70941 r.aMem = &aMem[pOp->p2];
70942 #ifdef SQLITE_DEBUG
70943 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70944 #endif
70945 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res);
70946 if( rc==SQLITE_OK && res==0 ){
70947 rc = sqlite3BtreeDelete(pCrsr);
70948 }
70949 assert( pC->deferredMoveto==0 );
70950 pC->cacheStatus = CACHE_STALE;
70951 break;
70952 }
70953
70954 /* Opcode: IdxRowid P1 P2 * * *
70955 ** Synopsis: r[P2]=rowid
@@ -70959,31 +71247,32 @@
70959 ** the rowid of the table entry to which this index entry points.
70960 **
70961 ** See also: Rowid, MakeRecord.
70962 */
70963 case OP_IdxRowid: { /* out2-prerelease */
 
70964 BtCursor *pCrsr;
70965 VdbeCursor *pC;
70966 i64 rowid;
 
70967
70968 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70969 pC = p->apCsr[pOp->p1];
70970 assert( pC!=0 );
70971 pCrsr = pC->pCursor;
70972 assert( pCrsr!=0 );
70973 pOut->flags = MEM_Null;
70974 rc = sqlite3VdbeCursorMoveto(pC);
70975 if( NEVER(rc) ) goto abort_due_to_error;
70976 assert( pC->deferredMoveto==0 );
70977 assert( pC->isTable==0 );
70978 if( !pC->nullRow ){
70979 rowid = 0; /* Not needed. Only used to silence a warning. */
70980 rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
70981 if( rc!=SQLITE_OK ){
70982 goto abort_due_to_error;
70983 }
70984 pOut->u.i = rowid;
70985 pOut->flags = MEM_Int;
70986 }
70987 break;
70988 }
70989
@@ -71015,42 +71304,43 @@
71015 ** If P5 is non-zero then the key value is increased by an epsilon prior
71016 ** to the comparison. This makes the opcode work like IdxLE.
71017 */
71018 case OP_IdxLT: /* jump */
71019 case OP_IdxGE: { /* jump */
 
71020 VdbeCursor *pC;
71021 int res;
71022 UnpackedRecord r;
 
71023
71024 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71025 pC = p->apCsr[pOp->p1];
71026 assert( pC!=0 );
71027 assert( pC->isOrdered );
71028 assert( pC->pCursor!=0);
71029 assert( pC->deferredMoveto==0 );
71030 assert( pOp->p5==0 || pOp->p5==1 );
71031 assert( pOp->p4type==P4_INT32 );
71032 r.pKeyInfo = pC->pKeyInfo;
71033 r.nField = (u16)pOp->p4.i;
71034 if( pOp->p5 ){
71035 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71036 }else{
71037 r.flags = UNPACKED_PREFIX_MATCH;
71038 }
71039 r.aMem = &aMem[pOp->p3];
71040 #ifdef SQLITE_DEBUG
71041 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71042 #endif
71043 res = 0; /* Not needed. Only used to silence a warning. */
71044 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71045 if( pOp->opcode==OP_IdxLT ){
71046 res = -res;
71047 }else{
71048 assert( pOp->opcode==OP_IdxGE );
71049 res++;
71050 }
71051 if( res>0 ){
71052 pc = pOp->p2 - 1 ;
71053 }
71054 break;
71055 }
71056
@@ -71073,46 +71363,47 @@
71073 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
71074 **
71075 ** See also: Clear
71076 */
71077 case OP_Destroy: { /* out2-prerelease */
 
71078 int iMoved;
71079 int iCnt;
71080 Vdbe *pVdbe;
71081 int iDb;
 
71082
71083 assert( p->readOnly==0 );
71084 #ifndef SQLITE_OMIT_VIRTUALTABLE
71085 iCnt = 0;
71086 for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){
71087 if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader
71088 && pVdbe->inVtabMethod<2 && pVdbe->pc>=0
71089 ){
71090 iCnt++;
71091 }
71092 }
71093 #else
71094 iCnt = db->nVdbeRead;
71095 #endif
71096 pOut->flags = MEM_Null;
71097 if( iCnt>1 ){
71098 rc = SQLITE_LOCKED;
71099 p->errorAction = OE_Abort;
71100 }else{
71101 iDb = pOp->p3;
71102 assert( iCnt==1 );
71103 assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 );
71104 iMoved = 0; /* Not needed. Only to silence a warning. */
71105 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
71106 pOut->flags = MEM_Int;
71107 pOut->u.i = iMoved;
71108 #ifndef SQLITE_OMIT_AUTOVACUUM
71109 if( rc==SQLITE_OK && iMoved!=0 ){
71110 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1);
71111 /* All OP_Destroy operations occur on the same btree */
71112 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 );
71113 resetSchemaOnFault = iDb+1;
71114 }
71115 #endif
71116 }
71117 break;
71118 }
@@ -71134,25 +71425,27 @@
71134 ** also incremented by the number of rows in the table being cleared.
71135 **
71136 ** See also: Destroy
71137 */
71138 case OP_Clear: {
 
71139 int nChange;
71140
71141 nChange = 0;
 
71142 assert( p->readOnly==0 );
71143 assert( pOp->p1!=1 );
71144 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71145 rc = sqlite3BtreeClearTable(
71146 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
71147 );
71148 if( pOp->p3 ){
71149 p->nChange += nChange;
71150 if( pOp->p3>0 ){
71151 assert( memIsValid(&aMem[pOp->p3]) );
71152 memAboutToChange(p, &aMem[pOp->p3]);
71153 aMem[pOp->p3].u.i += nChange;
71154 }
71155 }
71156 break;
71157 }
71158
@@ -71180,28 +71473,30 @@
71180 **
71181 ** See documentation on OP_CreateTable for additional information.
71182 */
71183 case OP_CreateIndex: /* out2-prerelease */
71184 case OP_CreateTable: { /* out2-prerelease */
 
71185 int pgno;
71186 int flags;
71187 Db *pDb;
 
71188
71189 pgno = 0;
71190 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71191 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71192 assert( p->readOnly==0 );
71193 pDb = &db->aDb[pOp->p1];
71194 assert( pDb->pBt!=0 );
71195 if( pOp->opcode==OP_CreateTable ){
71196 /* flags = BTREE_INTKEY; */
71197 flags = BTREE_INTKEY;
71198 }else{
71199 flags = BTREE_BLOBKEY;
71200 }
71201 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
71202 pOut->u.i = pgno;
71203 break;
71204 }
71205
71206 /* Opcode: ParseSchema P1 * * P4 *
71207 **
@@ -71210,54 +71505,56 @@
71210 **
71211 ** This opcode invokes the parser to create a new virtual machine,
71212 ** then runs the new virtual machine. It is thus a re-entrant opcode.
71213 */
71214 case OP_ParseSchema: {
 
71215 int iDb;
71216 const char *zMaster;
71217 char *zSql;
71218 InitData initData;
 
71219
71220 /* Any prepared statement that invokes this opcode will hold mutexes
71221 ** on every btree. This is a prerequisite for invoking
71222 ** sqlite3InitCallback().
71223 */
71224 #ifdef SQLITE_DEBUG
71225 for(iDb=0; iDb<db->nDb; iDb++){
71226 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
71227 }
71228 #endif
71229
71230 iDb = pOp->p1;
71231 assert( iDb>=0 && iDb<db->nDb );
71232 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
71233 /* Used to be a conditional */ {
71234 zMaster = SCHEMA_TABLE(iDb);
71235 initData.db = db;
71236 initData.iDb = pOp->p1;
71237 initData.pzErrMsg = &p->zErrMsg;
71238 zSql = sqlite3MPrintf(db,
71239 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
71240 db->aDb[iDb].zName, zMaster, pOp->p4.z);
71241 if( zSql==0 ){
71242 rc = SQLITE_NOMEM;
71243 }else{
71244 assert( db->init.busy==0 );
71245 db->init.busy = 1;
71246 initData.rc = SQLITE_OK;
71247 assert( !db->mallocFailed );
71248 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
71249 if( rc==SQLITE_OK ) rc = initData.rc;
71250 sqlite3DbFree(db, zSql);
71251 db->init.busy = 0;
71252 }
71253 }
71254 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
71255 if( rc==SQLITE_NOMEM ){
71256 goto no_mem;
71257 }
71258 break;
71259 }
71260
71261 #if !defined(SQLITE_OMIT_ANALYZE)
71262 /* Opcode: LoadAnalysis P1 * * * *
71263 **
@@ -71329,44 +71626,46 @@
71329 ** file, not the main database file.
71330 **
71331 ** This opcode is used to implement the integrity_check pragma.
71332 */
71333 case OP_IntegrityCk: {
 
71334 int nRoot; /* Number of tables to check. (Number of root pages.) */
71335 int *aRoot; /* Array of rootpage numbers for tables to be checked */
71336 int j; /* Loop counter */
71337 int nErr; /* Number of errors reported */
71338 char *z; /* Text of the error report */
71339 Mem *pnErr; /* Register keeping track of errors remaining */
 
71340
71341 assert( p->bIsReader );
71342 nRoot = pOp->p2;
71343 assert( nRoot>0 );
71344 aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) );
71345 if( aRoot==0 ) goto no_mem;
71346 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71347 pnErr = &aMem[pOp->p3];
71348 assert( (pnErr->flags & MEM_Int)!=0 );
71349 assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
71350 pIn1 = &aMem[pOp->p1];
71351 for(j=0; j<nRoot; j++){
71352 aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
71353 }
71354 aRoot[j] = 0;
71355 assert( pOp->p5<db->nDb );
71356 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
71357 z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
71358 (int)pnErr->u.i, &nErr);
71359 sqlite3DbFree(db, aRoot);
71360 pnErr->u.i -= nErr;
71361 sqlite3VdbeMemSetNull(pIn1);
71362 if( nErr==0 ){
71363 assert( z==0 );
71364 }else if( z==0 ){
71365 goto no_mem;
71366 }else{
71367 sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
71368 }
71369 UPDATE_MAX_BLOBSIZE(pIn1);
71370 sqlite3VdbeChangeEncoding(pIn1, encoding);
71371 break;
71372 }
@@ -71398,22 +71697,24 @@
71398 ** Extract the smallest value from boolean index P1 and put that value into
71399 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71400 ** unchanged and jump to instruction P2.
71401 */
71402 case OP_RowSetRead: { /* jump, in1, out3 */
 
71403 i64 val;
 
71404
71405 pIn1 = &aMem[pOp->p1];
71406 if( (pIn1->flags & MEM_RowSet)==0
71407 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71408 ){
71409 /* The boolean index is empty */
71410 sqlite3VdbeMemSetNull(pIn1);
71411 pc = pOp->p2 - 1;
71412 }else{
71413 /* A value was pulled from the index */
71414 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71415 }
71416 goto check_for_interrupt;
71417 }
71418
71419 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71439,16 +71740,18 @@
71439 ** inserted, there is no need to search to see if the same value was
71440 ** previously inserted as part of set X (only if it was previously
71441 ** inserted as part of some other set).
71442 */
71443 case OP_RowSetTest: { /* jump, in1, in3 */
 
71444 int iSet;
71445 int exists;
 
71446
71447 pIn1 = &aMem[pOp->p1];
71448 pIn3 = &aMem[pOp->p3];
71449 iSet = pOp->p4.i;
71450 assert( pIn3->flags&MEM_Int );
71451
71452 /* If there is anything other than a rowset object in memory cell P1,
71453 ** delete it now and initialize P1 with an empty rowset
71454 */
@@ -71456,21 +71759,21 @@
71456 sqlite3VdbeMemSetRowSet(pIn1);
71457 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
71458 }
71459
71460 assert( pOp->p4type==P4_INT32 );
71461 assert( iSet==-1 || iSet>=0 );
71462 if( iSet ){
71463 exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71464 (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71465 pIn3->u.i);
71466 if( exists ){
71467 pc = pOp->p2 - 1;
71468 break;
71469 }
71470 }
71471 if( iSet>=0 ){
71472 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
71473 }
71474 break;
71475 }
71476
@@ -71489,109 +71792,111 @@
71489 ** memory required by the sub-vdbe at runtime.
71490 **
71491 ** P4 is a pointer to the VM containing the trigger program.
71492 */
71493 case OP_Program: { /* jump */
 
71494 int nMem; /* Number of memory registers for sub-program */
71495 int nByte; /* Bytes of runtime space required for sub-program */
71496 Mem *pRt; /* Register to allocate runtime space */
71497 Mem *pMem; /* Used to iterate through memory cells */
71498 Mem *pEnd; /* Last memory cell in new array */
71499 VdbeFrame *pFrame; /* New vdbe frame to execute in */
71500 SubProgram *pProgram; /* Sub-program to execute */
71501 void *t; /* Token identifying trigger */
 
71502
71503 pProgram = pOp->p4.pProgram;
71504 pRt = &aMem[pOp->p3];
71505 assert( pProgram->nOp>0 );
71506
71507 /* If the p5 flag is clear, then recursive invocation of triggers is
71508 ** disabled for backwards compatibility (p5 is set if this sub-program
71509 ** is really a trigger, not a foreign key action, and the flag set
71510 ** and cleared by the "PRAGMA recursive_triggers" command is clear).
71511 **
71512 ** It is recursive invocation of triggers, at the SQL level, that is
71513 ** disabled. In some cases a single trigger may generate more than one
71514 ** SubProgram (if the trigger may be executed with more than one different
71515 ** ON CONFLICT algorithm). SubProgram structures associated with a
71516 ** single trigger all have the same value for the SubProgram.token
71517 ** variable. */
71518 if( pOp->p5 ){
71519 t = pProgram->token;
71520 for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent);
71521 if( pFrame ) break;
71522 }
71523
71524 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
71525 rc = SQLITE_ERROR;
71526 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
71527 break;
71528 }
71529
71530 /* Register pRt is used to store the memory required to save the state
71531 ** of the current program, and the memory required at runtime to execute
71532 ** the trigger program. If this trigger has been fired before, then pRt
71533 ** is already allocated. Otherwise, it must be initialized. */
71534 if( (pRt->flags&MEM_Frame)==0 ){
71535 /* SubProgram.nMem is set to the number of memory cells used by the
71536 ** program stored in SubProgram.aOp. As well as these, one memory
71537 ** cell is required for each cursor used by the program. Set local
71538 ** variable nMem (and later, VdbeFrame.nChildMem) to this value.
71539 */
71540 nMem = pProgram->nMem + pProgram->nCsr;
71541 nByte = ROUND8(sizeof(VdbeFrame))
71542 + nMem * sizeof(Mem)
71543 + pProgram->nCsr * sizeof(VdbeCursor *)
71544 + pProgram->nOnce * sizeof(u8);
71545 pFrame = sqlite3DbMallocZero(db, nByte);
71546 if( !pFrame ){
71547 goto no_mem;
71548 }
71549 sqlite3VdbeMemRelease(pRt);
71550 pRt->flags = MEM_Frame;
71551 pRt->u.pFrame = pFrame;
71552
71553 pFrame->v = p;
71554 pFrame->nChildMem = nMem;
71555 pFrame->nChildCsr = pProgram->nCsr;
71556 pFrame->pc = pc;
71557 pFrame->aMem = p->aMem;
71558 pFrame->nMem = p->nMem;
71559 pFrame->apCsr = p->apCsr;
71560 pFrame->nCursor = p->nCursor;
71561 pFrame->aOp = p->aOp;
71562 pFrame->nOp = p->nOp;
71563 pFrame->token = pProgram->token;
71564 pFrame->aOnceFlag = p->aOnceFlag;
71565 pFrame->nOnceFlag = p->nOnceFlag;
71566
71567 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71568 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71569 pMem->flags = MEM_Invalid;
71570 pMem->db = db;
71571 }
71572 }else{
71573 pFrame = pRt->u.pFrame;
71574 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
71575 assert( pProgram->nCsr==pFrame->nChildCsr );
71576 assert( pc==pFrame->pc );
71577 }
71578
71579 p->nFrame++;
71580 pFrame->pParent = p->pFrame;
71581 pFrame->lastRowid = lastRowid;
71582 pFrame->nChange = p->nChange;
71583 p->nChange = 0;
71584 p->pFrame = pFrame;
71585 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
71586 p->nMem = pFrame->nChildMem;
71587 p->nCursor = (u16)pFrame->nChildCsr;
71588 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71589 p->aOp = aOp = pProgram->aOp;
71590 p->nOp = pProgram->nOp;
71591 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71592 p->nOnceFlag = pProgram->nOnce;
71593 pc = -1;
71594 memset(p->aOnceFlag, 0, p->nOnceFlag);
71595
71596 break;
71597 }
@@ -71607,15 +71912,17 @@
71607 ** The address of the cell in the parent frame is determined by adding
71608 ** the value of the P1 argument to the value of the P1 argument to the
71609 ** calling OP_Program instruction.
71610 */
71611 case OP_Param: { /* out2-prerelease */
 
71612 VdbeFrame *pFrame;
71613 Mem *pIn;
71614 pFrame = p->pFrame;
71615 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1];
71616 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem);
 
71617 break;
71618 }
71619
71620 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71621
@@ -71672,23 +71979,26 @@
71672 **
71673 ** This instruction throws an error if the memory cell is not initially
71674 ** an integer.
71675 */
71676 case OP_MemMax: { /* in2 */
 
 
71677 VdbeFrame *pFrame;
 
71678 if( p->pFrame ){
71679 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
71680 pIn1 = &pFrame->aMem[pOp->p1];
71681 }else{
71682 pIn1 = &aMem[pOp->p1];
71683 }
71684 assert( memIsValid(pIn1) );
71685 sqlite3VdbeMemIntegerify(pIn1);
71686 pIn2 = &aMem[pOp->p2];
71687 sqlite3VdbeMemIntegerify(pIn2);
71688 if( pIn1->u.i<pIn2->u.i){
71689 pIn1->u.i = pIn2->u.i;
71690 }
71691 break;
71692 }
71693 #endif /* SQLITE_OMIT_AUTOINCREMENT */
71694
@@ -71755,58 +72065,60 @@
71755 **
71756 ** The P5 arguments are taken from register P2 and its
71757 ** successors.
71758 */
71759 case OP_AggStep: {
 
71760 int n;
71761 int i;
71762 Mem *pMem;
71763 Mem *pRec;
71764 sqlite3_context ctx;
71765 sqlite3_value **apVal;
71766
71767 n = pOp->p5;
71768 assert( n>=0 );
71769 pRec = &aMem[pOp->p2];
71770 apVal = p->apArg;
71771 assert( apVal || n==0 );
71772 for(i=0; i<n; i++, pRec++){
71773 assert( memIsValid(pRec) );
71774 apVal[i] = pRec;
71775 memAboutToChange(p, pRec);
71776 sqlite3VdbeMemStoreType(pRec);
71777 }
71778 ctx.pFunc = pOp->p4.pFunc;
 
71779 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71780 ctx.pMem = pMem = &aMem[pOp->p3];
71781 pMem->n++;
71782 ctx.s.flags = MEM_Null;
71783 ctx.s.z = 0;
71784 ctx.s.zMalloc = 0;
71785 ctx.s.xDel = 0;
71786 ctx.s.db = db;
71787 ctx.isError = 0;
71788 ctx.pColl = 0;
71789 ctx.skipFlag = 0;
71790 if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
71791 assert( pOp>p->aOp );
71792 assert( pOp[-1].p4type==P4_COLLSEQ );
71793 assert( pOp[-1].opcode==OP_CollSeq );
71794 ctx.pColl = pOp[-1].p4.pColl;
71795 }
71796 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
71797 if( ctx.isError ){
71798 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
71799 rc = ctx.isError;
71800 }
71801 if( ctx.skipFlag ){
71802 assert( pOp[-1].opcode==OP_CollSeq );
71803 i = pOp[-1].p1;
71804 if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1);
71805 }
71806
71807 sqlite3VdbeMemRelease(&ctx.s);
71808
71809 break;
71810 }
71811
71812 /* Opcode: AggFinal P1 P2 * P4 *
@@ -71821,21 +72133,23 @@
71821 ** functions that can take varying numbers of arguments. The
71822 ** P4 argument is only needed for the degenerate case where
71823 ** the step function was not previously called.
71824 */
71825 case OP_AggFinal: {
 
71826 Mem *pMem;
 
71827 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
71828 pMem = &aMem[pOp->p1];
71829 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
71830 rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
71831 if( rc ){
71832 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
71833 }
71834 sqlite3VdbeChangeEncoding(pMem, encoding);
71835 UPDATE_MAX_BLOBSIZE(pMem);
71836 if( sqlite3VdbeMemTooBig(pMem) ){
71837 goto too_big;
71838 }
71839 break;
71840 }
71841
@@ -71850,29 +72164,31 @@
71850 ** in the WAL that have been checkpointed after the checkpoint
71851 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
71852 ** mem[P3+2] are initialized to -1.
71853 */
71854 case OP_Checkpoint: {
 
71855 int i; /* Loop counter */
71856 int aRes[3]; /* Results */
71857 Mem *pMem; /* Write results here */
 
71858
71859 assert( p->readOnly==0 );
71860 aRes[0] = 0;
71861 aRes[1] = aRes[2] = -1;
71862 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
71863 || pOp->p2==SQLITE_CHECKPOINT_FULL
71864 || pOp->p2==SQLITE_CHECKPOINT_RESTART
71865 );
71866 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
71867 if( rc==SQLITE_BUSY ){
71868 rc = SQLITE_OK;
71869 aRes[0] = 1;
71870 }
71871 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
71872 sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]);
71873 }
71874 break;
71875 };
71876 #endif
71877
71878 #ifndef SQLITE_OMIT_PRAGMA
@@ -71886,96 +72202,98 @@
71886 ** If changing into or out of WAL mode the procedure is more complicated.
71887 **
71888 ** Write a string containing the final journal-mode to register P2.
71889 */
71890 case OP_JournalMode: { /* out2-prerelease */
 
71891 Btree *pBt; /* Btree to change journal mode of */
71892 Pager *pPager; /* Pager associated with pBt */
71893 int eNew; /* New journal mode */
71894 int eOld; /* The old journal mode */
71895 #ifndef SQLITE_OMIT_WAL
71896 const char *zFilename; /* Name of database file for pPager */
71897 #endif
71898
71899 eNew = pOp->p3;
71900 assert( eNew==PAGER_JOURNALMODE_DELETE
71901 || eNew==PAGER_JOURNALMODE_TRUNCATE
71902 || eNew==PAGER_JOURNALMODE_PERSIST
71903 || eNew==PAGER_JOURNALMODE_OFF
71904 || eNew==PAGER_JOURNALMODE_MEMORY
71905 || eNew==PAGER_JOURNALMODE_WAL
71906 || eNew==PAGER_JOURNALMODE_QUERY
 
71907 );
71908 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71909 assert( p->readOnly==0 );
71910
71911 pBt = db->aDb[pOp->p1].pBt;
71912 pPager = sqlite3BtreePager(pBt);
71913 eOld = sqlite3PagerGetJournalMode(pPager);
71914 if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld;
71915 if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld;
71916
71917 #ifndef SQLITE_OMIT_WAL
71918 zFilename = sqlite3PagerFilename(pPager, 1);
71919
71920 /* Do not allow a transition to journal_mode=WAL for a database
71921 ** in temporary storage or if the VFS does not support shared memory
71922 */
71923 if( eNew==PAGER_JOURNALMODE_WAL
71924 && (sqlite3Strlen30(zFilename)==0 /* Temp file */
71925 || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */
71926 ){
71927 eNew = eOld;
71928 }
71929
71930 if( (eNew!=eOld)
71931 && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL)
71932 ){
71933 if( !db->autoCommit || db->nVdbeRead>1 ){
71934 rc = SQLITE_ERROR;
71935 sqlite3SetString(&p->zErrMsg, db,
71936 "cannot change %s wal mode from within a transaction",
71937 (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
71938 );
71939 break;
71940 }else{
71941
71942 if( eOld==PAGER_JOURNALMODE_WAL ){
71943 /* If leaving WAL mode, close the log file. If successful, the call
71944 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
71945 ** file. An EXCLUSIVE lock may still be held on the database file
71946 ** after a successful return.
71947 */
71948 rc = sqlite3PagerCloseWal(pPager);
71949 if( rc==SQLITE_OK ){
71950 sqlite3PagerSetJournalMode(pPager, eNew);
71951 }
71952 }else if( eOld==PAGER_JOURNALMODE_MEMORY ){
71953 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
71954 ** as an intermediate */
71955 sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF);
71956 }
71957
71958 /* Open a transaction on the database file. Regardless of the journal
71959 ** mode, this transaction always uses a rollback journal.
71960 */
71961 assert( sqlite3BtreeIsInTrans(pBt)==0 );
71962 if( rc==SQLITE_OK ){
71963 rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
71964 }
71965 }
71966 }
71967 #endif /* ifndef SQLITE_OMIT_WAL */
71968
71969 if( rc ){
71970 eNew = eOld;
71971 }
71972 eNew = sqlite3PagerSetJournalMode(pPager, eNew);
71973
71974 pOut = &aMem[pOp->p2];
71975 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71976 pOut->z = (char *)sqlite3JournalModename(eNew);
71977 pOut->n = sqlite3Strlen30(pOut->z);
71978 pOut->enc = SQLITE_UTF8;
71979 sqlite3VdbeChangeEncoding(pOut, encoding);
71980 break;
71981 };
@@ -72001,17 +72319,19 @@
72001 ** Perform a single step of the incremental vacuum procedure on
72002 ** the P1 database. If the vacuum has finished, jump to instruction
72003 ** P2. Otherwise, fall through to the next instruction.
72004 */
72005 case OP_IncrVacuum: { /* jump */
 
72006 Btree *pBt;
 
72007
72008 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72009 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72010 assert( p->readOnly==0 );
72011 pBt = db->aDb[pOp->p1].pBt;
72012 rc = sqlite3BtreeIncrVacuum(pBt);
72013 if( rc==SQLITE_DONE ){
72014 pc = pOp->p2 - 1;
72015 rc = SQLITE_OK;
72016 }
72017 break;
@@ -72078,14 +72398,16 @@
72078 ** Also, whether or not P4 is set, check that this is not being called from
72079 ** within a callback to a virtual table xSync() method. If it is, the error
72080 ** code will be set to SQLITE_LOCKED.
72081 */
72082 case OP_VBegin: {
 
72083 VTable *pVTab;
72084 pVTab = pOp->p4.pVtab;
72085 rc = sqlite3VtabBegin(db, pVTab);
72086 if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab);
 
72087 break;
72088 }
72089 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72090
72091 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72120,34 +72442,36 @@
72120 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72121 ** P1 is a cursor number. This opcode opens a cursor to the virtual
72122 ** table and stores that cursor in P1.
72123 */
72124 case OP_VOpen: {
 
72125 VdbeCursor *pCur;
72126 sqlite3_vtab_cursor *pVtabCursor;
72127 sqlite3_vtab *pVtab;
72128 sqlite3_module *pModule;
 
72129
72130 assert( p->bIsReader );
72131 pCur = 0;
72132 pVtabCursor = 0;
72133 pVtab = pOp->p4.pVtab->pVtab;
72134 pModule = (sqlite3_module *)pVtab->pModule;
72135 assert(pVtab && pModule);
72136 rc = pModule->xOpen(pVtab, &pVtabCursor);
72137 sqlite3VtabImportErrmsg(p, pVtab);
72138 if( SQLITE_OK==rc ){
72139 /* Initialize sqlite3_vtab_cursor base class */
72140 pVtabCursor->pVtab = pVtab;
72141
72142 /* Initialize vdbe cursor object */
72143 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72144 if( pCur ){
72145 pCur->pVtabCursor = pVtabCursor;
72146 }else{
72147 db->mallocFailed = 1;
72148 pModule->xClose(pVtabCursor);
72149 }
72150 }
72151 break;
72152 }
72153 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72171,10 +72495,11 @@
72171 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
72172 **
72173 ** A jump is made to P2 if the result set after filtering would be empty.
72174 */
72175 case OP_VFilter: { /* jump */
 
72176 int nArg;
72177 int iQuery;
72178 const sqlite3_module *pModule;
72179 Mem *pQuery;
72180 Mem *pArgc;
@@ -72182,48 +72507,49 @@
72182 sqlite3_vtab *pVtab;
72183 VdbeCursor *pCur;
72184 int res;
72185 int i;
72186 Mem **apArg;
72187
72188 pQuery = &aMem[pOp->p3];
72189 pArgc = &pQuery[1];
72190 pCur = p->apCsr[pOp->p1];
72191 assert( memIsValid(pQuery) );
72192 REGISTER_TRACE(pOp->p3, pQuery);
72193 assert( pCur->pVtabCursor );
72194 pVtabCursor = pCur->pVtabCursor;
72195 pVtab = pVtabCursor->pVtab;
72196 pModule = pVtab->pModule;
 
72197
72198 /* Grab the index number and argc parameters */
72199 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
72200 nArg = (int)pArgc->u.i;
72201 iQuery = (int)pQuery->u.i;
72202
72203 /* Invoke the xFilter method */
72204 {
72205 res = 0;
72206 apArg = p->apArg;
72207 for(i = 0; i<nArg; i++){
72208 apArg[i] = &pArgc[i+1];
72209 sqlite3VdbeMemStoreType(apArg[i]);
72210 }
72211
72212 p->inVtabMethod = 1;
72213 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
72214 p->inVtabMethod = 0;
72215 sqlite3VtabImportErrmsg(p, pVtab);
72216 if( rc==SQLITE_OK ){
72217 res = pModule->xEof(pVtabCursor);
72218 }
72219
72220 if( res ){
72221 pc = pOp->p2 - 1;
72222 }
72223 }
72224 pCur->nullRow = 0;
72225
72226 break;
72227 }
72228 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72229
@@ -72234,53 +72560,55 @@
72234 ** Store the value of the P2-th column of
72235 ** the row of the virtual-table that the
72236 ** P1 cursor is pointing to into register P3.
72237 */
72238 case OP_VColumn: {
 
72239 sqlite3_vtab *pVtab;
72240 const sqlite3_module *pModule;
72241 Mem *pDest;
72242 sqlite3_context sContext;
 
72243
72244 VdbeCursor *pCur = p->apCsr[pOp->p1];
72245 assert( pCur->pVtabCursor );
72246 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72247 pDest = &aMem[pOp->p3];
72248 memAboutToChange(p, pDest);
72249 if( pCur->nullRow ){
72250 sqlite3VdbeMemSetNull(pDest);
72251 break;
72252 }
72253 pVtab = pCur->pVtabCursor->pVtab;
72254 pModule = pVtab->pModule;
72255 assert( pModule->xColumn );
72256 memset(&sContext, 0, sizeof(sContext));
72257
72258 /* The output cell may already have a buffer allocated. Move
72259 ** the current contents to sContext.s so in case the user-function
72260 ** can use the already allocated buffer instead of allocating a
72261 ** new one.
72262 */
72263 sqlite3VdbeMemMove(&sContext.s, pDest);
72264 MemSetTypeFlag(&sContext.s, MEM_Null);
72265
72266 rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
72267 sqlite3VtabImportErrmsg(p, pVtab);
72268 if( sContext.isError ){
72269 rc = sContext.isError;
72270 }
72271
72272 /* Copy the result of the function to the P3 register. We
72273 ** do this regardless of whether or not an error occurred to ensure any
72274 ** dynamic allocation in sContext.s (a Mem struct) is released.
72275 */
72276 sqlite3VdbeChangeEncoding(&sContext.s, encoding);
72277 sqlite3VdbeMemMove(pDest, &sContext.s);
72278 REGISTER_TRACE(pOp->p3, pDest);
72279 UPDATE_MAX_BLOBSIZE(pDest);
72280
72281 if( sqlite3VdbeMemTooBig(pDest) ){
72282 goto too_big;
72283 }
72284 break;
72285 }
72286 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72291,40 +72619,42 @@
72291 ** Advance virtual table P1 to the next row in its result set and
72292 ** jump to instruction P2. Or, if the virtual table has reached
72293 ** the end of its result set, then fall through to the next instruction.
72294 */
72295 case OP_VNext: { /* jump */
 
72296 sqlite3_vtab *pVtab;
72297 const sqlite3_module *pModule;
72298 int res;
72299 VdbeCursor *pCur;
 
72300
72301 res = 0;
72302 pCur = p->apCsr[pOp->p1];
72303 assert( pCur->pVtabCursor );
72304 if( pCur->nullRow ){
72305 break;
72306 }
72307 pVtab = pCur->pVtabCursor->pVtab;
72308 pModule = pVtab->pModule;
72309 assert( pModule->xNext );
72310
72311 /* Invoke the xNext() method of the module. There is no way for the
72312 ** underlying implementation to return an error if one occurs during
72313 ** xNext(). Instead, if an error occurs, true is returned (indicating that
72314 ** data is available) and the error code returned when xColumn or
72315 ** some other method is next invoked on the save virtual table cursor.
72316 */
72317 p->inVtabMethod = 1;
72318 rc = pModule->xNext(pCur->pVtabCursor);
72319 p->inVtabMethod = 0;
72320 sqlite3VtabImportErrmsg(p, pVtab);
72321 if( rc==SQLITE_OK ){
72322 res = pModule->xEof(pCur->pVtabCursor);
72323 }
72324
72325 if( !res ){
72326 /* If there is data, jump to P2 */
72327 pc = pOp->p2 - 1;
72328 }
72329 goto check_for_interrupt;
72330 }
@@ -72336,27 +72666,29 @@
72336 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72337 ** This opcode invokes the corresponding xRename method. The value
72338 ** in register P1 is passed as the zName argument to the xRename method.
72339 */
72340 case OP_VRename: {
 
72341 sqlite3_vtab *pVtab;
72342 Mem *pName;
 
72343
72344 pVtab = pOp->p4.pVtab->pVtab;
72345 pName = &aMem[pOp->p1];
72346 assert( pVtab->pModule->xRename );
72347 assert( memIsValid(pName) );
72348 assert( p->readOnly==0 );
72349 REGISTER_TRACE(pOp->p1, pName);
72350 assert( pName->flags & MEM_Str );
72351 testcase( pName->enc==SQLITE_UTF8 );
72352 testcase( pName->enc==SQLITE_UTF16BE );
72353 testcase( pName->enc==SQLITE_UTF16LE );
72354 rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8);
72355 if( rc==SQLITE_OK ){
72356 rc = pVtab->pModule->xRename(pVtab, pName->z);
72357 sqlite3VtabImportErrmsg(p, pVtab);
72358 p->expired = 0;
72359 }
72360 break;
72361 }
72362 #endif
@@ -72385,44 +72717,46 @@
72385 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72386 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72387 ** is set to the value of the rowid for the row just inserted.
72388 */
72389 case OP_VUpdate: {
 
72390 sqlite3_vtab *pVtab;
72391 sqlite3_module *pModule;
72392 int nArg;
72393 int i;
72394 sqlite_int64 rowid;
72395 Mem **apArg;
72396 Mem *pX;
 
72397
72398 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72399 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
72400 );
72401 assert( p->readOnly==0 );
72402 pVtab = pOp->p4.pVtab->pVtab;
72403 pModule = (sqlite3_module *)pVtab->pModule;
72404 nArg = pOp->p2;
72405 assert( pOp->p4type==P4_VTAB );
72406 if( ALWAYS(pModule->xUpdate) ){
72407 u8 vtabOnConflict = db->vtabOnConflict;
72408 apArg = p->apArg;
72409 pX = &aMem[pOp->p3];
72410 for(i=0; i<nArg; i++){
72411 assert( memIsValid(pX) );
72412 memAboutToChange(p, pX);
72413 sqlite3VdbeMemStoreType(pX);
72414 apArg[i] = pX;
72415 pX++;
72416 }
72417 db->vtabOnConflict = pOp->p5;
72418 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
72419 db->vtabOnConflict = vtabOnConflict;
72420 sqlite3VtabImportErrmsg(p, pVtab);
72421 if( rc==SQLITE_OK && pOp->p1 ){
72422 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
72423 db->lastRowid = lastRowid = rowid;
72424 }
72425 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
72426 if( pOp->p5==OE_Ignore ){
72427 rc = SQLITE_OK;
72428 }else{
@@ -72478,36 +72812,38 @@
72478 **
72479 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72480 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72481 */
72482 case OP_Trace: {
 
72483 char *zTrace;
72484 char *z;
 
72485
72486 if( db->xTrace
72487 && !p->doingRerun
72488 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72489 ){
72490 z = sqlite3VdbeExpandSql(p, zTrace);
72491 db->xTrace(db->pTraceArg, z);
72492 sqlite3DbFree(db, z);
72493 }
72494 #ifdef SQLITE_USE_FCNTL_TRACE
72495 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72496 if( zTrace ){
72497 int i;
72498 for(i=0; i<db->nDb; i++){
72499 if( ((1<<i) & p->btreeMask)==0 ) continue;
72500 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace);
72501 }
72502 }
72503 #endif /* SQLITE_USE_FCNTL_TRACE */
72504 #ifdef SQLITE_DEBUG
72505 if( (db->flags & SQLITE_SqlTrace)!=0
72506 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72507 ){
72508 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72509 }
72510 #endif /* SQLITE_DEBUG */
72511 break;
72512 }
72513 #endif
@@ -72632,11 +72968,10 @@
72632 rc = SQLITE_INTERRUPT;
72633 p->rc = rc;
72634 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
72635 goto vdbe_error_halt;
72636 }
72637
72638
72639 /************** End of vdbe.c ************************************************/
72640 /************** Begin file vdbeblob.c ****************************************/
72641 /*
72642 ** 2007 May 1
@@ -72891,11 +73226,11 @@
72891 sqlite3BtreeLeaveAll(db);
72892 goto blob_open_out;
72893 }
72894 }
72895
72896 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse);
72897 assert( pBlob->pStmt || db->mallocFailed );
72898 if( pBlob->pStmt ){
72899 Vdbe *v = (Vdbe *)pBlob->pStmt;
72900 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
72901
@@ -76798,29 +77133,20 @@
76798 }
76799 return p;
76800 }
76801
76802 /*
76803 ** If the expression is always either TRUE or FALSE (respectively),
76804 ** then return 1. If one cannot determine the truth value of the
76805 ** expression at compile-time return 0.
76806 **
76807 ** This is an optimization. If is OK to return 0 here even if
76808 ** the expression really is always false or false (a false negative).
76809 ** But it is a bug to return 1 if the expression might have different
76810 ** boolean values in different circumstances (a false positive.)
76811 **
76812 ** Note that if the expression is part of conditional for a
76813 ** LEFT JOIN, then we cannot determine at compile-time whether or not
76814 ** is it true or false, so always return 0.
76815 */
76816 static int exprAlwaysTrue(Expr *p){
76817 int v = 0;
76818 if( ExprHasProperty(p, EP_FromJoin) ) return 0;
76819 if( !sqlite3ExprIsInteger(p, &v) ) return 0;
76820 return v!=0;
76821 }
76822 static int exprAlwaysFalse(Expr *p){
76823 int v = 0;
76824 if( ExprHasProperty(p, EP_FromJoin) ) return 0;
76825 if( !sqlite3ExprIsInteger(p, &v) ) return 0;
76826 return v==0;
@@ -78454,15 +78780,10 @@
78454 ** added to the column cache after this call are removed when the
78455 ** corresponding pop occurs.
78456 */
78457 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse *pParse){
78458 pParse->iCacheLevel++;
78459 #ifdef SQLITE_DEBUG
78460 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
78461 printf("PUSH to %d\n", pParse->iCacheLevel);
78462 }
78463 #endif
78464 }
78465
78466 /*
78467 ** Remove from the column cache any entries that were added since the
78468 ** the previous N Push operations. In other words, restore the cache
@@ -78472,15 +78793,10 @@
78472 int i;
78473 struct yColCache *p;
78474 assert( N>0 );
78475 assert( pParse->iCacheLevel>=N );
78476 pParse->iCacheLevel -= N;
78477 #ifdef SQLITE_DEBUG
78478 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
78479 printf("POP to %d\n", pParse->iCacheLevel);
78480 }
78481 #endif
78482 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
78483 if( p->iReg && p->iLevel>pParse->iCacheLevel ){
78484 cacheEntryClear(pParse, p);
78485 p->iReg = 0;
78486 }
@@ -78571,15 +78887,10 @@
78571 */
78572 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){
78573 int i;
78574 struct yColCache *p;
78575
78576 #if SQLITE_DEBUG
78577 if( pParse->db->flags & SQLITE_VdbeAddopTrace ){
78578 printf("CLEAR\n");
78579 }
78580 #endif
78581 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
78582 if( p->iReg ){
78583 cacheEntryClear(pParse, p);
78584 p->iReg = 0;
78585 }
@@ -79663,11 +79974,11 @@
79663 sqlite3ExplainPush(pOut);
79664 for(i=0; i<pList->nExpr; i++){
79665 sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
79666 sqlite3ExplainPush(pOut);
79667 sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
79668 sqlite3ExplainPop(pOut, 1);
79669 if( pList->a[i].zName ){
79670 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
79671 }
79672 if( pList->a[i].bSpanIsTab ){
79673 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
@@ -79712,21 +80023,11 @@
79712 if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
79713 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
79714 }else{
79715 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
79716 if( inReg!=target+i ){
79717 VdbeOp *pOp;
79718 Vdbe *v = pParse->pVdbe;
79719 if( copyOp==OP_Copy
79720 && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
79721 && pOp->p1+pOp->p3+1==inReg
79722 && pOp->p2+pOp->p3+1==target+i
79723 ){
79724 pOp->p3++;
79725 }else{
79726 sqlite3VdbeAddOp2(v, copyOp, inReg, target+i);
79727 }
79728 }
79729 }
79730 }
79731 return n;
79732 }
@@ -79813,23 +80114,21 @@
79813 op = pExpr->op;
79814 switch( op ){
79815 case TK_AND: {
79816 int d2 = sqlite3VdbeMakeLabel(v);
79817 testcase( jumpIfNull==0 );
79818 sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
79819 sqlite3ExprCachePush(pParse);
 
79820 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
79821 sqlite3VdbeResolveLabel(v, d2);
79822 sqlite3ExprCachePop(pParse, 1);
79823 break;
79824 }
79825 case TK_OR: {
79826 testcase( jumpIfNull==0 );
79827 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
79828 sqlite3ExprCachePush(pParse);
79829 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
79830 sqlite3ExprCachePop(pParse, 1);
79831 break;
79832 }
79833 case TK_NOT: {
79834 testcase( jumpIfNull==0 );
79835 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
@@ -79900,20 +80199,14 @@
79900 sqlite3VdbeResolveLabel(v, destIfFalse);
79901 break;
79902 }
79903 #endif
79904 default: {
79905 if( exprAlwaysTrue(pExpr) ){
79906 sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
79907 }else if( exprAlwaysFalse(pExpr) ){
79908 /* No-op */
79909 }else{
79910 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
79911 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
79912 testcase( regFree1==0 );
79913 testcase( jumpIfNull==0 );
79914 }
79915 break;
79916 }
79917 }
79918 sqlite3ReleaseTempReg(pParse, regFree1);
79919 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -79972,20 +80265,18 @@
79972
79973 switch( pExpr->op ){
79974 case TK_AND: {
79975 testcase( jumpIfNull==0 );
79976 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
79977 sqlite3ExprCachePush(pParse);
79978 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
79979 sqlite3ExprCachePop(pParse, 1);
79980 break;
79981 }
79982 case TK_OR: {
79983 int d2 = sqlite3VdbeMakeLabel(v);
79984 testcase( jumpIfNull==0 );
79985 sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
79986 sqlite3ExprCachePush(pParse);
 
79987 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
79988 sqlite3VdbeResolveLabel(v, d2);
79989 sqlite3ExprCachePop(pParse, 1);
79990 break;
79991 }
@@ -80053,20 +80344,14 @@
80053 }
80054 break;
80055 }
80056 #endif
80057 default: {
80058 if( exprAlwaysFalse(pExpr) ){
80059 sqlite3VdbeAddOp2(v, OP_Goto, 0, dest);
80060 }else if( exprAlwaysTrue(pExpr) ){
80061 /* no-op */
80062 }else{
80063 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80064 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80065 testcase( regFree1==0 );
80066 testcase( jumpIfNull==0 );
80067 }
80068 break;
80069 }
80070 }
80071 sqlite3ReleaseTempReg(pParse, regFree1);
80072 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -83162,10 +83447,14 @@
83162 {
83163 int rc = SQLITE_OK;
83164 if( pExpr ){
83165 if( pExpr->op!=TK_ID ){
83166 rc = sqlite3ResolveExprNames(pName, pExpr);
 
 
 
 
83167 }else{
83168 pExpr->op = TK_STRING;
83169 }
83170 }
83171 return rc;
@@ -87940,13 +88229,13 @@
87940 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
87941 errMsg.db = pParse->db;
87942 for(j=0; j<pIdx->nKeyCol; j++){
87943 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
87944 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
87945 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
87946 sqlite3StrAccumAppend(&errMsg, ".", 1);
87947 sqlite3StrAccumAppendAll(&errMsg, zCol);
87948 }
87949 zErr = sqlite3StrAccumFinish(&errMsg);
87950 sqlite3HaltConstraint(pParse,
87951 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
87952 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88134,13 +88423,12 @@
88134 }
88135 if( pKey ){
88136 assert( sqlite3KeyInfoIsWriteable(pKey) );
88137 for(i=0; i<nCol; i++){
88138 char *zColl = pIdx->azColl[i];
88139 assert( zColl!=0 );
88140 pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 :
88141 sqlite3LocateCollSeq(pParse, zColl);
88142 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
88143 }
88144 if( pParse->nErr ){
88145 sqlite3KeyInfoUnref(pKey);
88146 }else{
@@ -88509,10 +88797,11 @@
88509 int bestScore = 0; /* Score of best match */
88510 int h; /* Hash value */
88511
88512 assert( nArg>=(-2) );
88513 assert( nArg>=(-1) || createFlag==0 );
 
88514 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
88515
88516 /* First search for a match amongst the application-defined functions.
88517 */
88518 p = functionSearch(&db->aFunc, h, zName, nName);
@@ -89399,10 +89688,11 @@
89399 Vdbe *v = pParse->pVdbe;
89400 int j;
89401 Table *pTab = pIdx->pTable;
89402 int regBase;
89403 int nCol;
 
89404
89405 if( piPartIdxLabel ){
89406 if( pIdx->pPartIdxWhere ){
89407 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
89408 pParse->iPartIdxTab = iDataCur;
@@ -89412,25 +89702,32 @@
89412 *piPartIdxLabel = 0;
89413 }
89414 }
89415 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
89416 regBase = sqlite3GetTempRange(pParse, nCol);
 
89417 for(j=0; j<nCol; j++){
89418 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j],
89419 regBase+j);
89420 /* If the column affinity is REAL but the number is an integer, then it
89421 ** might be stored in the table as an integer (using a compact
89422 ** representation) then converted to REAL by an OP_RealAffinity opcode.
89423 ** But we are getting ready to store this value back into an index, where
89424 ** it should be converted by to INTEGER again. So omit the OP_RealAffinity
89425 ** opcode if it is present */
89426 if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){
89427 sqlite3VdbeDeleteLastOpcode(v);
89428 }
89429 }
89430 if( regOut ){
 
 
 
 
 
 
 
 
89431 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
 
89432 }
89433 sqlite3ReleaseTempRange(pParse, regBase, nCol);
89434 return regBase;
89435 }
89436
@@ -89652,36 +89949,10 @@
89652 }
89653 if( nNeedle>nHaystack ) N = 0;
89654 sqlite3_result_int(context, N);
89655 }
89656
89657 /*
89658 ** Implementation of the printf() function.
89659 */
89660 static void printfFunc(
89661 sqlite3_context *context,
89662 int argc,
89663 sqlite3_value **argv
89664 ){
89665 PrintfArguments x;
89666 StrAccum str;
89667 const char *zFormat;
89668 int n;
89669
89670 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
89671 x.nArg = argc-1;
89672 x.nUsed = 0;
89673 x.apArg = argv+1;
89674 sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
89675 str.db = sqlite3_context_db_handle(context);
89676 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
89677 n = str.nChar;
89678 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
89679 SQLITE_DYNAMIC);
89680 }
89681 }
89682
89683 /*
89684 ** Implementation of the substr() function.
89685 **
89686 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
89687 ** p1 is 1-indexed. So substr(x,1,1) returns the first character
@@ -90971,15 +91242,15 @@
90971 nSep = sqlite3_value_bytes(argv[1]);
90972 }else{
90973 zSep = ",";
90974 nSep = 1;
90975 }
90976 if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
90977 }
90978 zVal = (char*)sqlite3_value_text(argv[0]);
90979 nVal = sqlite3_value_bytes(argv[0]);
90980 if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
90981 }
90982 }
90983 static void groupConcatFinalize(sqlite3_context *context){
90984 StrAccum *pAccum;
90985 pAccum = sqlite3_aggregate_context(context, 0);
@@ -91108,11 +91379,10 @@
91108 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
91109 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
91110 FUNCTION(instr, 2, 0, 0, instrFunc ),
91111 FUNCTION(substr, 2, 0, 0, substrFunc ),
91112 FUNCTION(substr, 3, 0, 0, substrFunc ),
91113 FUNCTION(printf, -1, 0, 0, printfFunc ),
91114 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
91115 FUNCTION(char, -1, 0, 0, charFunc ),
91116 FUNCTION(abs, 1, 0, 0, absFunc ),
91117 #ifndef SQLITE_OMIT_FLOATING_POINT
91118 FUNCTION(round, 1, 0, 0, roundFunc ),
@@ -93779,11 +94049,10 @@
93779 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
93780 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
93781 int ipkTop = 0; /* Top of the rowid change constraint check */
93782 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
93783 u8 isUpdate; /* True if this is an UPDATE operation */
93784 int regRowid = -1; /* Register holding ROWID value */
93785
93786 isUpdate = regOldData!=0;
93787 db = pParse->db;
93788 v = sqlite3GetVdbe(pParse);
93789 assert( v!=0 );
@@ -94010,13 +94279,11 @@
94010 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
94011 for(i=0; i<pIdx->nColumn; i++){
94012 int iField = pIdx->aiColumn[i];
94013 int x;
94014 if( iField<0 || iField==pTab->iPKey ){
94015 if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
94016 x = regNewData;
94017 regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
94018 }else{
94019 x = iField + regNewData + 1;
94020 }
94021 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94022 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
@@ -94052,53 +94319,51 @@
94052 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94053 regIdx, pIdx->nKeyCol);
94054
94055 /* Generate code to handle collisions */
94056 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94057 if( isUpdate || onError==OE_Replace ){
94058 if( HasRowid(pTab) ){
94059 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94060 /* Conflict only if the rowid of the existing index entry
94061 ** is different from old-rowid */
94062 if( isUpdate ){
94063 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94064 }
94065 }else{
94066 int x;
94067 /* Extract the PRIMARY KEY from the end of the index entry and
94068 ** store it in registers regR..regR+nPk-1 */
94069 if( pIdx!=pPk ){
94070 for(i=0; i<pPk->nKeyCol; i++){
94071 x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
94072 sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
94073 VdbeComment((v, "%s.%s", pTab->zName,
94074 pTab->aCol[pPk->aiColumn[i]].zName));
94075 }
94076 }
94077 if( isUpdate ){
94078 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
94079 ** table, only conflict if the new PRIMARY KEY values are actually
94080 ** different from the old.
94081 **
94082 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
94083 ** of the matched index row are different from the original PRIMARY
94084 ** KEY values of this row before the update. */
94085 int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
94086 int op = OP_Ne;
94087 int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
94088
94089 for(i=0; i<pPk->nKeyCol; i++){
94090 char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
94091 x = pPk->aiColumn[i];
94092 if( i==(pPk->nKeyCol-1) ){
94093 addrJump = addrUniqueOk;
94094 op = OP_Eq;
94095 }
94096 sqlite3VdbeAddOp4(v, op,
94097 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94098 );
94099 }
94100 }
94101 }
94102 }
94103
94104 /* Generate code that executes if the new index entry is not unique */
@@ -98841,15 +99106,11 @@
98841
98842 /*
98843 ** Free all memory allocations in the pParse object
98844 */
98845 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
98846 if( pParse ){
98847 sqlite3 *db = pParse->db;
98848 sqlite3DbFree(db, pParse->aLabel);
98849 sqlite3ExprListDelete(db, pParse->pConstExpr);
98850 }
98851 }
98852
98853 /*
98854 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
98855 */
@@ -99798,10 +100059,11 @@
99798 }
99799 }else if( eDest!=SRT_Exists ){
99800 /* If the destination is an EXISTS(...) expression, the actual
99801 ** values returned by the SELECT are not required.
99802 */
 
99803 sqlite3ExprCodeExprList(pParse, pEList, regResult,
99804 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
99805 }
99806 nColumn = nResultCol;
99807
@@ -100764,11 +101026,11 @@
100764 ** If an error occurs, return NULL and leave a message in pParse.
100765 */
100766 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
100767 Vdbe *v = pParse->pVdbe;
100768 if( v==0 ){
100769 v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
100770 #ifndef SQLITE_OMIT_TRACE
100771 if( v ){
100772 sqlite3VdbeAddOp0(v, OP_Trace);
100773 }
100774 #endif
@@ -103022,27 +103284,18 @@
103022 */
103023 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
103024 Vdbe *v = pParse->pVdbe;
103025 int i;
103026 struct AggInfo_func *pFunc;
103027 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
103028 if( nReg==0 ) return;
103029 #ifdef SQLITE_DEBUG
103030 /* Verify that all AggInfo registers are within the range specified by
103031 ** AggInfo.mnReg..AggInfo.mxReg */
103032 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
103033 for(i=0; i<pAggInfo->nColumn; i++){
103034 assert( pAggInfo->aCol[i].iMem>=pAggInfo->mnReg
103035 && pAggInfo->aCol[i].iMem<=pAggInfo->mxReg );
103036 }
103037 for(i=0; i<pAggInfo->nFunc; i++){
103038 assert( pAggInfo->aFunc[i].iMem>=pAggInfo->mnReg
103039 && pAggInfo->aFunc[i].iMem<=pAggInfo->mxReg );
103040 }
103041 #endif
103042 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
103043 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
 
103044 if( pFunc->iDistinct>=0 ){
103045 Expr *pE = pFunc->pExpr;
103046 assert( !ExprHasProperty(pE, EP_xIsSelect) );
103047 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
103048 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
@@ -103084,10 +103337,11 @@
103084 int addrHitTest = 0;
103085 struct AggInfo_func *pF;
103086 struct AggInfo_col *pC;
103087
103088 pAggInfo->directMode = 1;
 
103089 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
103090 int nArg;
103091 int addrNext = 0;
103092 int regAgg;
103093 ExprList *pList = pF->pExpr->x.pList;
@@ -103616,11 +103870,10 @@
103616 */
103617 memset(&sNC, 0, sizeof(sNC));
103618 sNC.pParse = pParse;
103619 sNC.pSrcList = pTabList;
103620 sNC.pAggInfo = &sAggInfo;
103621 sAggInfo.mnReg = pParse->nMem+1;
103622 sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0;
103623 sAggInfo.pGroupBy = pGroupBy;
103624 sqlite3ExprAnalyzeAggList(&sNC, pEList);
103625 sqlite3ExprAnalyzeAggList(&sNC, pOrderBy);
103626 if( pHaving ){
@@ -103631,11 +103884,10 @@
103631 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
103632 sNC.ncFlags |= NC_InAggFunc;
103633 sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
103634 sNC.ncFlags &= ~NC_InAggFunc;
103635 }
103636 sAggInfo.mxReg = pParse->nMem;
103637 if( db->mallocFailed ) goto select_end;
103638
103639 /* Processing for aggregates with GROUP BY is very different and
103640 ** much more complex than aggregates without a GROUP BY.
103641 */
@@ -105536,11 +105788,11 @@
105536 pCol->affinity, &pValue);
105537 if( pValue ){
105538 sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM);
105539 }
105540 #ifndef SQLITE_OMIT_FLOATING_POINT
105541 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
105542 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
105543 }
105544 #endif
105545 }
105546 }
@@ -105960,14 +106212,14 @@
105960 ** be used eliminates some redundant opcodes.
105961 */
105962 newmask = sqlite3TriggerColmask(
105963 pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError
105964 );
105965 /*sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);*/
105966 for(i=0; i<pTab->nCol; i++){
105967 if( i==pTab->iPKey ){
105968 sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
105969 }else{
105970 j = aXRef[i];
105971 if( j>=0 ){
105972 sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i);
105973 }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask&(1<<i)) ){
@@ -105977,12 +106229,10 @@
105977 ** a new.* reference in a trigger program.
105978 */
105979 testcase( i==31 );
105980 testcase( i==32 );
105981 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
105982 }else{
105983 sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
105984 }
105985 }
105986 }
105987
105988 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
@@ -110731,11 +110981,11 @@
110731 int iTerm, /* Index of this term. First is zero */
110732 const char *zColumn, /* Name of the column */
110733 const char *zOp /* Name of the operator */
110734 ){
110735 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110736 sqlite3StrAccumAppendAll(pStr, zColumn);
110737 sqlite3StrAccumAppend(pStr, zOp, 1);
110738 sqlite3StrAccumAppend(pStr, "?", 1);
110739 }
110740
110741 /*
@@ -110777,11 +111027,11 @@
110777 if( i>=nSkip ){
110778 explainAppendTerm(&txt, i, z, "=");
110779 }else{
110780 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
110781 sqlite3StrAccumAppend(&txt, "ANY(", 4);
110782 sqlite3StrAccumAppendAll(&txt, z);
110783 sqlite3StrAccumAppend(&txt, ")", 1);
110784 }
110785 }
110786
110787 j = i;
@@ -113593,16 +113843,13 @@
113593 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113594
113595 /* Special case: a WHERE clause that is constant. Evaluate the
113596 ** expression and either jump over all of the code or fall thru.
113597 */
113598 for(ii=0; ii<sWLB.pWC->nTerm; ii++){
113599 if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){
113600 sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak,
113601 SQLITE_JUMPIFNULL);
113602 sWLB.pWC->a[ii].wtFlags |= TERM_CODED;
113603 }
113604 }
113605
113606 /* Special case: No FROM clause
113607 */
113608 if( nTabList==0 ){
@@ -119339,12 +119586,11 @@
119339 }
119340 db->lookaside.pEnd = p;
119341 db->lookaside.bEnabled = 1;
119342 db->lookaside.bMalloced = pBuf==0 ?1:0;
119343 }else{
119344 db->lookaside.pStart = db;
119345 db->lookaside.pEnd = db;
119346 db->lookaside.bEnabled = 0;
119347 db->lookaside.bMalloced = 0;
119348 }
119349 return SQLITE_OK;
119350 }
@@ -119738,11 +119984,13 @@
119738 }
119739 sqlite3HashClear(&db->aModule);
119740 #endif
119741
119742 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
119743 sqlite3ValueFree(db->pErr);
 
 
119744 sqlite3CloseExtensions(db);
119745
119746 db->magic = SQLITE_MAGIC_ERROR;
119747
119748 /* The temp-database schema is allocated differently from the other schema
@@ -119813,11 +120061,12 @@
119813
119814 /*
119815 ** Return a static string containing the name corresponding to the error code
119816 ** specified in the argument.
119817 */
119818 #if defined(SQLITE_TEST)
 
119819 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
119820 const char *zName = 0;
119821 int i, origRc = rc;
119822 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
119823 switch( rc ){
@@ -119835,11 +120084,10 @@
119835 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
119836 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
119837 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
119838 case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
119839 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
119840 case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break;
119841 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
119842 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
119843 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
119844 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
119845 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -120120,11 +120368,10 @@
120120 void (*xFinal)(sqlite3_context*),
120121 FuncDestructor *pDestructor
120122 ){
120123 FuncDef *p;
120124 int nName;
120125 int extraFlags;
120126
120127 assert( sqlite3_mutex_held(db->mutex) );
120128 if( zFunctionName==0 ||
120129 (xFunc && (xFinal || xStep)) ||
120130 (!xFunc && (xFinal && !xStep)) ||
@@ -120131,14 +120378,10 @@
120131 (!xFunc && (!xFinal && xStep)) ||
120132 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
120133 (255<(nName = sqlite3Strlen30( zFunctionName))) ){
120134 return SQLITE_MISUSE_BKPT;
120135 }
120136
120137 assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
120138 extraFlags = enc & SQLITE_DETERMINISTIC;
120139 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
120140
120141 #ifndef SQLITE_OMIT_UTF16
120142 /* If SQLITE_UTF16 is specified as the encoding type, transform this
120143 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
120144 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -120148,14 +120391,14 @@
120148 */
120149 if( enc==SQLITE_UTF16 ){
120150 enc = SQLITE_UTF16NATIVE;
120151 }else if( enc==SQLITE_ANY ){
120152 int rc;
120153 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
120154 pUserData, xFunc, xStep, xFinal, pDestructor);
120155 if( rc==SQLITE_OK ){
120156 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
120157 pUserData, xFunc, xStep, xFinal, pDestructor);
120158 }
120159 if( rc!=SQLITE_OK ){
120160 return rc;
120161 }
@@ -120194,12 +120437,11 @@
120194
120195 if( pDestructor ){
120196 pDestructor->nRef++;
120197 }
120198 p->pDestructor = pDestructor;
120199 p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
120200 testcase( p->funcFlags & SQLITE_DETERMINISTIC );
120201 p->xFunc = xFunc;
120202 p->xStep = xStep;
120203 p->xFinalize = xFinal;
120204 p->pUserData = pUserData;
120205 p->nArg = (u16)nArg;
@@ -120625,11 +120867,10 @@
120625 }
120626 sqlite3_mutex_enter(db->mutex);
120627 if( db->mallocFailed ){
120628 z = sqlite3ErrStr(SQLITE_NOMEM);
120629 }else{
120630 testcase( db->pErr==0 );
120631 z = (char*)sqlite3_value_text(db->pErr);
120632 assert( !db->mallocFailed );
120633 if( z==0 ){
120634 z = sqlite3ErrStr(db->errCode);
120635 }
@@ -120667,11 +120908,12 @@
120667 if( db->mallocFailed ){
120668 z = (void *)outOfMem;
120669 }else{
120670 z = sqlite3_value_text16(db->pErr);
120671 if( z==0 ){
120672 sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode));
 
120673 z = sqlite3_value_text16(db->pErr);
120674 }
120675 /* A malloc() may have failed within the call to sqlite3_value_text16()
120676 ** above. If this is the case, then the db->mallocFailed flag needs to
120677 ** be cleared before returning. Do this directly, instead of via
@@ -121380,10 +121622,12 @@
121380 #ifdef SQLITE_ENABLE_RTREE
121381 if( !db->mallocFailed && rc==SQLITE_OK){
121382 rc = sqlite3RtreeInit(db);
121383 }
121384 #endif
 
 
121385
121386 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
121387 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
121388 ** mode. Doing nothing at all also makes NORMAL the default.
121389 */
@@ -121391,12 +121635,10 @@
121391 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
121392 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
121393 SQLITE_DEFAULT_LOCKING_MODE);
121394 #endif
121395
121396 if( rc ) sqlite3Error(db, rc, 0);
121397
121398 /* Enable the lookaside-malloc subsystem */
121399 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
121400 sqlite3GlobalConfig.nLookaside);
121401
121402 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
@@ -121852,11 +122094,11 @@
121852 ** Reset the PRNG back to its uninitialized state. The next call
121853 ** to sqlite3_randomness() will reseed the PRNG using a single call
121854 ** to the xRandomness method of the default VFS.
121855 */
121856 case SQLITE_TESTCTRL_PRNG_RESET: {
121857 sqlite3_randomness(0,0);
121858 break;
121859 }
121860
121861 /*
121862 ** sqlite3_test_control(BITVEC_TEST, size, program)
@@ -124836,23 +125078,10 @@
124836 char **pzErr /* OUT: sqlite3_malloc'd error message */
124837 ){
124838 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
124839 }
124840
124841 /*
124842 ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
124843 ** extension is currently being used by a version of SQLite too old to
124844 ** support estimatedRows. In that case this function is a no-op.
124845 */
124846 static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
124847 #if SQLITE_VERSION_NUMBER>=3008002
124848 if( sqlite3_libversion_number()>=3008002 ){
124849 pIdxInfo->estimatedRows = nRow;
124850 }
124851 #endif
124852 }
124853
124854 /*
124855 ** Implementation of the xBestIndex method for FTS3 tables. There
124856 ** are three possible strategies, in order of preference:
124857 **
124858 ** 1. Direct lookup by rowid or docid.
@@ -124876,24 +125105,11 @@
124876 pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124877 pInfo->estimatedCost = 5000000;
124878 for(i=0; i<pInfo->nConstraint; i++){
124879 int bDocid; /* True if this constraint is on docid */
124880 struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
124881 if( pCons->usable==0 ){
124882 if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){
124883 /* There exists an unusable MATCH constraint. This means that if
124884 ** the planner does elect to use the results of this call as part
124885 ** of the overall query plan the user will see an "unable to use
124886 ** function MATCH in the requested context" error. To discourage
124887 ** this, return a very high cost here. */
124888 pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
124889 pInfo->estimatedCost = 1e50;
124890 setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50);
124891 return SQLITE_OK;
124892 }
124893 continue;
124894 }
124895
124896 bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
124897
124898 /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
124899 if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
@@ -131750,74 +131966,61 @@
131750 }
131751
131752 /* Step 2 */
131753 switch( z[1] ){
131754 case 'a':
131755 if( !stem(&z, "lanoita", "ate", m_gt_0) ){
131756 stem(&z, "lanoit", "tion", m_gt_0);
131757 }
131758 break;
131759 case 'c':
131760 if( !stem(&z, "icne", "ence", m_gt_0) ){
131761 stem(&z, "icna", "ance", m_gt_0);
131762 }
131763 break;
131764 case 'e':
131765 stem(&z, "rezi", "ize", m_gt_0);
131766 break;
131767 case 'g':
131768 stem(&z, "igol", "log", m_gt_0);
131769 break;
131770 case 'l':
131771 if( !stem(&z, "ilb", "ble", m_gt_0)
131772 && !stem(&z, "illa", "al", m_gt_0)
131773 && !stem(&z, "iltne", "ent", m_gt_0)
131774 && !stem(&z, "ile", "e", m_gt_0)
131775 ){
131776 stem(&z, "ilsuo", "ous", m_gt_0);
131777 }
131778 break;
131779 case 'o':
131780 if( !stem(&z, "noitazi", "ize", m_gt_0)
131781 && !stem(&z, "noita", "ate", m_gt_0)
131782 ){
131783 stem(&z, "rota", "ate", m_gt_0);
131784 }
131785 break;
131786 case 's':
131787 if( !stem(&z, "msila", "al", m_gt_0)
131788 && !stem(&z, "ssenevi", "ive", m_gt_0)
131789 && !stem(&z, "ssenluf", "ful", m_gt_0)
131790 ){
131791 stem(&z, "ssensuo", "ous", m_gt_0);
131792 }
131793 break;
131794 case 't':
131795 if( !stem(&z, "itila", "al", m_gt_0)
131796 && !stem(&z, "itivi", "ive", m_gt_0)
131797 ){
131798 stem(&z, "itilib", "ble", m_gt_0);
131799 }
131800 break;
131801 }
131802
131803 /* Step 3 */
131804 switch( z[0] ){
131805 case 'e':
131806 if( !stem(&z, "etaci", "ic", m_gt_0)
131807 && !stem(&z, "evita", "", m_gt_0)
131808 ){
131809 stem(&z, "ezila", "al", m_gt_0);
131810 }
131811 break;
131812 case 'i':
131813 stem(&z, "itici", "ic", m_gt_0);
131814 break;
131815 case 'l':
131816 if( !stem(&z, "laci", "ic", m_gt_0) ){
131817 stem(&z, "luf", "", m_gt_0);
131818 }
131819 break;
131820 case 's':
131821 stem(&z, "ssen", "", m_gt_0);
131822 break;
131823 }
@@ -131854,15 +132057,13 @@
131854 if( z[2]=='a' ){
131855 if( m_gt_1(z+3) ){
131856 z += 3;
131857 }
131858 }else if( z[2]=='e' ){
131859 if( !stem(&z, "tneme", "", m_gt_1)
131860 && !stem(&z, "tnem", "", m_gt_1)
131861 ){
131862 stem(&z, "tne", "", m_gt_1);
131863 }
131864 }
131865 }
131866 break;
131867 case 'o':
131868 if( z[0]=='u' ){
@@ -131877,13 +132078,12 @@
131877 if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
131878 z += 3;
131879 }
131880 break;
131881 case 't':
131882 if( !stem(&z, "eta", "", m_gt_1) ){
131883 stem(&z, "iti", "", m_gt_1);
131884 }
131885 break;
131886 case 'u':
131887 if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
131888 z += 3;
131889 }
131890
--- 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.2. 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.
@@ -133,13 +133,13 @@
133 **
134 ** See also: [sqlite3_libversion()],
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -517,11 +517,10 @@
517 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
518 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
519 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
520 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
521 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
 
522 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
523 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
524 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
525 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
526 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -585,12 +584,11 @@
584 ** information is written to disk in the same order as calls
585 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
586 ** after reboot following a crash or power loss, the only bytes in a
587 ** file that were written at the application level might have changed
588 ** and that adjacent bytes, even bytes within the same sector are
589 ** guaranteed to be unchanged.
 
590 */
591 #define SQLITE_IOCAP_ATOMIC 0x00000001
592 #define SQLITE_IOCAP_ATOMIC512 0x00000002
593 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
594 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -817,33 +815,19 @@
815 ** to the [sqlite3_file] object associated with a particular database
816 ** connection. See the [sqlite3_file_control()] documentation for
817 ** additional information.
818 **
819 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
820 ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
821 ** SQLite and sent to all VFSes in place of a call to the xSync method
822 ** when the database connection has [PRAGMA synchronous] set to OFF.)^
823 ** Some specialized VFSes need this signal in order to operate correctly
824 ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
825 ** VFSes do not need this signal and should silently ignore this opcode.
826 ** Applications should not call [sqlite3_file_control()] with this
827 ** opcode as doing so may disrupt the operation of the specialized VFSes
828 ** that do require it.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829 **
830 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
831 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
832 ** retry counts and intervals for certain disk I/O operations for the
833 ** windows [VFS] in order to provide robustness in the presence of
@@ -963,16 +947,10 @@
947 ** This file control is used by some VFS activity tracing [shims].
948 ** The argument is a zero-terminated string. Higher layers in the
949 ** SQLite stack may generate instances of this file control if
950 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
951 **
 
 
 
 
 
 
952 ** </ul>
953 */
954 #define SQLITE_FCNTL_LOCKSTATE 1
955 #define SQLITE_GET_LOCKPROXYFILE 2
956 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -989,13 +967,10 @@
967 #define SQLITE_FCNTL_PRAGMA 14
968 #define SQLITE_FCNTL_BUSYHANDLER 15
969 #define SQLITE_FCNTL_TEMPFILENAME 16
970 #define SQLITE_FCNTL_MMAP_SIZE 18
971 #define SQLITE_FCNTL_TRACE 19
 
 
 
972
973 /*
974 ** CAPI3REF: Mutex Handle
975 **
976 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2426,17 +2401,15 @@
2401 ** already uses the largest possible [ROWID]. The PRNG is also used for
2402 ** the build-in random() and randomblob() SQL functions. This interface allows
2403 ** applications to access the same PRNG for other purposes.
2404 **
2405 ** ^A call to this routine stores N bytes of randomness into buffer P.
 
2406 **
2407 ** ^The first time this routine is invoked (either internally or by
2408 ** the application) the PRNG is seeded using randomness obtained
2409 ** from the xRandomness method of the default [sqlite3_vfs] object.
2410 ** ^On all subsequent invocations, the pseudo-randomness is generated
 
2411 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2412 ** method.
2413 */
2414 SQLITE_API void sqlite3_randomness(int N, void *P);
2415
@@ -4010,28 +3983,19 @@
3983 ** parameter is less than -1 or greater than 127 then the behavior is
3984 ** undefined.
3985 **
3986 ** ^The fourth parameter, eTextRep, specifies what
3987 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3988 ** its parameters. Every SQL function implementation must be able to work
3989 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3990 ** more efficient with one encoding than another. ^An application may
3991 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3992 ** times with the same function but with different values of eTextRep.
 
 
 
3993 ** ^When multiple implementations of the same function are available, SQLite
3994 ** will pick the one that involves the least amount of data conversion.
3995 ** If there is only a single implementation which does not care what text
3996 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
 
 
 
 
 
 
3997 **
3998 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3999 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4000 **
4001 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4113,23 +4077,13 @@
4077 */
4078 #define SQLITE_UTF8 1
4079 #define SQLITE_UTF16LE 2
4080 #define SQLITE_UTF16BE 3
4081 #define SQLITE_UTF16 4 /* Use native byte order */
4082 #define SQLITE_ANY 5 /* sqlite3_create_function only */
4083 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4084
 
 
 
 
 
 
 
 
 
 
4085 /*
4086 ** CAPI3REF: Deprecated Functions
4087 ** DEPRECATED
4088 **
4089 ** These functions are [deprecated]. In order to maintain
@@ -8627,11 +8581,10 @@
8581 typedef struct Lookaside Lookaside;
8582 typedef struct LookasideSlot LookasideSlot;
8583 typedef struct Module Module;
8584 typedef struct NameContext NameContext;
8585 typedef struct Parse Parse;
 
8586 typedef struct RowSet RowSet;
8587 typedef struct Savepoint Savepoint;
8588 typedef struct Select Select;
8589 typedef struct SelectDest SelectDest;
8590 typedef struct SrcList SrcList;
@@ -9100,11 +9053,11 @@
9053 #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9054 #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9055 #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9056 #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9057 #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9058 #define OP_Copy 30 /* synopsis: r[P2@P3]=r[P1@P3] */
9059 #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9060 #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9061 #define OP_CollSeq 33
9062 #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9063 #define OP_MustBeInt 35
@@ -9265,11 +9218,11 @@
9218
9219 /*
9220 ** Prototypes for the VDBE interface. See comments on the implementation
9221 ** for a description of what each of these routines does.
9222 */
9223 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3*);
9224 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int);
9225 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
9226 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
9227 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
9228 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
@@ -9280,11 +9233,10 @@
9233 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9234 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9235 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
9236 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
9237 SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr);
 
9238 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
9239 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
9240 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
9241 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
9242 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*);
@@ -9487,11 +9439,10 @@
9439 SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
9440 #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
9441 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
9442 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
9443 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
 
9444
9445 /* Operations on page references. */
9446 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
9447 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
9448 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -9502,11 +9453,11 @@
9453 /* Functions used to manage pager transactions and savepoints. */
9454 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
9455 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
9456 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
9457 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
9458 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
9459 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
9460 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
9461 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
9462 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
9463 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -10374,11 +10325,11 @@
10325 */
10326 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
10327 #define SQLITE_ColumnCache 0x0002 /* Column cache */
10328 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
10329 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10330 #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
10331 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10332 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10333 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10334 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10335 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
@@ -11006,11 +10957,10 @@
10957 u8 useSortingIdx; /* In direct mode, reference the sorting index rather
10958 ** than the source table */
10959 int sortingIdx; /* Cursor number of the sorting index */
10960 int sortingIdxPTab; /* Cursor number of pseudo-table */
10961 int nSortingColumn; /* Number of columns in the sorting index */
 
10962 ExprList *pGroupBy; /* The group by clause */
10963 struct AggInfo_col { /* For each column used in source tables */
10964 Table *pTab; /* Source table */
10965 int iTable; /* Cursor number of the source table */
10966 int iColumn; /* Column number within the source table */
@@ -11608,13 +11558,10 @@
11558 int nErr; /* Number of errors seen */
11559 int nTab; /* Number of previously allocated VDBE cursors */
11560 int nMem; /* Number of memory cells used so far */
11561 int nSet; /* Number of sets used so far */
11562 int nOnce; /* Number of OP_Once instructions so far */
 
 
 
11563 int ckBase; /* Base register of data during check constraints */
11564 int iPartIdxTab; /* Table corresponding to a partial index */
11565 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11566 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11567 struct yColCache {
@@ -12087,24 +12034,14 @@
12034 SQLITE_PRIVATE int sqlite3IsNaN(double);
12035 #else
12036 # define sqlite3IsNaN(X) 0
12037 #endif
12038
12039 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
12040 #ifndef SQLITE_OMIT_TRACE
12041 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...);
12042 #endif
 
 
 
 
 
 
 
 
 
 
12043 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
12044 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
12045 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12046 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
12047 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
@@ -12290,10 +12227,11 @@
12227 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
12228 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
12229 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
12230 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
12231 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
12232 SQLITE_PRIVATE void sqlite3PrngResetState(void);
12233 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
12234 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int);
12235 SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb);
12236 SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int);
12237 SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*);
@@ -12458,11 +12396,12 @@
12396 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
12397 SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
12398 SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
12399 SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
12400
12401 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
12402 defined(SQLITE_DEBUG_OS_TRACE)
12403 SQLITE_PRIVATE const char *sqlite3ErrName(int);
12404 #endif
12405
12406 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
12407 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
@@ -12488,11 +12427,10 @@
12427
12428 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
12429 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
12430 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
12431 void(*)(void*));
 
12432 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
12433 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
12434 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
12435 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
12436 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
@@ -12554,11 +12492,10 @@
12492 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
12493 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
12494
12495 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
12496 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
 
12497 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
12498 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
12499 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
12500 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
12501 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
@@ -13781,13 +13718,16 @@
13718 Op *aOp; /* Space to hold the virtual machine's program */
13719 Mem *aMem; /* The memory locations */
13720 Mem **apArg; /* Arguments to currently executing user function */
13721 Mem *aColName; /* Column names to return */
13722 Mem *pResultSet; /* Pointer to an array of results */
 
13723 int nMem; /* Number of memory locations currently allocated */
13724 int nOp; /* Number of instructions in the program */
13725 int nOpAlloc; /* Number of slots allocated for aOp[] */
13726 int nLabel; /* Number of labels used */
13727 int *aLabel; /* Space to hold the labels */
13728 u16 nResColumn; /* Number of columns in one row of the result set */
13729 int nCursor; /* Number of slots in apCsr[] */
13730 u32 magic; /* Magic number for sanity checking */
13731 char *zErrMsg; /* Error message written here */
13732 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
13733 VdbeCursor **apCsr; /* One element of this array for each open cursor */
@@ -13796,11 +13736,10 @@
13736 ynVar nVar; /* Number of entries in aVar[] */
13737 ynVar nzVar; /* Number of entries in azVar[] */
13738 u32 cacheCtr; /* VdbeCursor row cache generation counter */
13739 int pc; /* The program counter */
13740 int rc; /* Value to return */
 
13741 u8 errorAction; /* Recovery action to do in case of an error */
13742 u8 minWriteFileFormat; /* Minimum file format for writable database files */
13743 bft explain:2; /* True if EXPLAIN present on SQL command */
13744 bft inVtabMethod:2; /* See comments above */
13745 bft changeCntOn:1; /* True to update the change-counter */
@@ -13856,11 +13795,11 @@
13795 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
13796 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*);
13797 #endif
13798 SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32);
13799 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int);
13800 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int);
13801 SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
13802 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
13803
13804 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
13805 SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
@@ -15446,25 +15385,11 @@
15385 ** really care if the VFS receives and understands the information since it
15386 ** is only a hint and can be safely ignored. The sqlite3OsFileControlHint()
15387 ** routine has no return value since the return value would be meaningless.
15388 */
15389 SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
15390 DO_OS_MALLOC_TEST(id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15391 return id->pMethods->xFileControl(id, op, pArg);
15392 }
15393 SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
15394 (void)id->pMethods->xFileControl(id, op, pArg);
15395 }
@@ -19455,11 +19380,11 @@
19380 /*
19381 ** TRUE if p is a lookaside memory allocation from db
19382 */
19383 #ifndef SQLITE_OMIT_LOOKASIDE
19384 static int isLookaside(sqlite3 *db, void *p){
19385 return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
19386 }
19387 #else
19388 #define isLookaside(A,B) 0
19389 #endif
19390
@@ -19471,13 +19396,12 @@
19396 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
19397 assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
19398 return sqlite3GlobalConfig.m.xSize(p);
19399 }
19400 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
19401 assert( db==0 || sqlite3_mutex_held(db->mutex) );
19402 if( db && isLookaside(db, p) ){
 
19403 return db->lookaside.sz;
19404 }else{
19405 assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
19406 assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
19407 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
@@ -19955,35 +19879,10 @@
19879 }
19880 if( N>0 ){
19881 sqlite3StrAccumAppend(pAccum, zSpaces, N);
19882 }
19883 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19884
19885 /*
19886 ** On machines with a small stack size, you can redefine the
19887 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19888 */
@@ -19994,14 +19893,14 @@
19893
19894 /*
19895 ** Render a string given by "fmt" into the StrAccum object.
19896 */
19897 SQLITE_PRIVATE void sqlite3VXPrintf(
19898 StrAccum *pAccum, /* Accumulate results here */
19899 int useExtended, /* Allow extended %-conversions */
19900 const char *fmt, /* Format string */
19901 va_list ap /* arguments */
19902 ){
19903 int c; /* Next character in the format string */
19904 char *bufpt; /* Pointer to the conversion buffer */
19905 int precision; /* Precision of the current field */
19906 int length; /* Length of the field */
@@ -20015,12 +19914,10 @@
19914 etByte flag_zeropad; /* True if field width constant starts with zero */
19915 etByte flag_long; /* True if "l" flag is present */
19916 etByte flag_longlong; /* True if the "ll" flag is present */
19917 etByte done; /* Loop termination flag */
19918 etByte xtype = 0; /* Conversion paradigm */
 
 
19919 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
19920 sqlite_uint64 longvalue; /* Value for integer types */
19921 LONGDOUBLE_TYPE realvalue; /* Value for real types */
19922 const et_info *infop; /* Pointer to the appropriate info structure */
19923 char *zOut; /* Rendering buffer */
@@ -20031,22 +19928,13 @@
19928 int nsd; /* Number of significant digits returned */
19929 double rounder; /* Used for rounding floating point values */
19930 etByte flag_dp; /* True if decimal point should be shown */
19931 etByte flag_rtz; /* True if trailing zeros should be removed */
19932 #endif
 
19933 char buf[etBUFSIZE]; /* Conversion buffer */
19934
19935 bufpt = 0;
 
 
 
 
 
 
 
 
19936 for(; (c=(*fmt))!=0; ++fmt){
19937 if( c!='%' ){
19938 int amt;
19939 bufpt = (char *)fmt;
19940 amt = 1;
@@ -20074,15 +19962,11 @@
19962 }
19963 }while( !done && (c=(*++fmt))!=0 );
19964 /* Get the field width */
19965 width = 0;
19966 if( c=='*' ){
19967 width = va_arg(ap,int);
 
 
 
 
19968 if( width<0 ){
19969 flag_leftjustify = 1;
19970 width = -width;
19971 }
19972 c = *++fmt;
@@ -20095,15 +19979,11 @@
19979 /* Get the precision */
19980 if( c=='.' ){
19981 precision = 0;
19982 c = *++fmt;
19983 if( c=='*' ){
19984 precision = va_arg(ap,int);
 
 
 
 
19985 if( precision<0 ) precision = -precision;
19986 c = *++fmt;
19987 }else{
19988 while( c>='0' && c<='9' ){
19989 precision = precision*10 + c - '0';
@@ -20130,11 +20010,11 @@
20010 infop = &fmtinfo[0];
20011 xtype = etINVALID;
20012 for(idx=0; idx<ArraySize(fmtinfo); idx++){
20013 if( c==fmtinfo[idx].fmttype ){
20014 infop = &fmtinfo[idx];
20015 if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
20016 xtype = infop->type;
20017 }else{
20018 return;
20019 }
20020 break;
@@ -20170,13 +20050,11 @@
20050 /* Fall through into the next case */
20051 case etORDINAL:
20052 case etRADIX:
20053 if( infop->flags & FLAG_SIGNED ){
20054 i64 v;
20055 if( flag_longlong ){
 
 
20056 v = va_arg(ap,i64);
20057 }else if( flag_long ){
20058 v = va_arg(ap,long int);
20059 }else{
20060 v = va_arg(ap,int);
@@ -20193,13 +20071,11 @@
20071 if( flag_plussign ) prefix = '+';
20072 else if( flag_blanksign ) prefix = ' ';
20073 else prefix = 0;
20074 }
20075 }else{
20076 if( flag_longlong ){
 
 
20077 longvalue = va_arg(ap,u64);
20078 }else if( flag_long ){
20079 longvalue = va_arg(ap,unsigned long int);
20080 }else{
20081 longvalue = va_arg(ap,unsigned int);
@@ -20215,11 +20091,11 @@
20091 zOut = buf;
20092 }else{
20093 nOut = precision + 10;
20094 zOut = zExtra = sqlite3Malloc( nOut );
20095 if( zOut==0 ){
20096 pAccum->accError = STRACCUM_NOMEM;
20097 return;
20098 }
20099 }
20100 bufpt = &zOut[nOut-1];
20101 if( xtype==etORDINAL ){
@@ -20255,15 +20131,11 @@
20131 length = (int)(&zOut[nOut-1]-bufpt);
20132 break;
20133 case etFLOAT:
20134 case etEXP:
20135 case etGENERIC:
20136 realvalue = va_arg(ap,double);
 
 
 
 
20137 #ifdef SQLITE_OMIT_FLOATING_POINT
20138 length = 0;
20139 #else
20140 if( precision<0 ) precision = 6; /* Set default precision */
20141 if( realvalue<0.0 ){
@@ -20331,11 +20203,11 @@
20203 e2 = exp;
20204 }
20205 if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){
20206 bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 );
20207 if( bufpt==0 ){
20208 pAccum->accError = STRACCUM_NOMEM;
20209 return;
20210 }
20211 }
20212 zOut = bufpt;
20213 nsd = 16 + flag_altform2*10;
@@ -20414,27 +20286,20 @@
20286 length = width;
20287 }
20288 #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
20289 break;
20290 case etSIZE:
20291 *(va_arg(ap,int*)) = pAccum->nChar;
 
 
20292 length = width = 0;
20293 break;
20294 case etPERCENT:
20295 buf[0] = '%';
20296 bufpt = buf;
20297 length = 1;
20298 break;
20299 case etCHARX:
20300 c = va_arg(ap,int);
 
 
 
 
 
20301 buf[0] = (char)c;
20302 if( precision>=0 ){
20303 for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
20304 length = precision;
20305 }else{
@@ -20442,18 +20307,14 @@
20307 }
20308 bufpt = buf;
20309 break;
20310 case etSTRING:
20311 case etDYNSTRING:
20312 bufpt = va_arg(ap,char*);
 
 
 
 
20313 if( bufpt==0 ){
20314 bufpt = "";
20315 }else if( xtype==etDYNSTRING ){
20316 zExtra = bufpt;
20317 }
20318 if( precision>=0 ){
20319 for(length=0; length<precision && bufpt[length]; length++){}
20320 }else{
@@ -20465,17 +20326,11 @@
20326 case etSQLESCAPE3: {
20327 int i, j, k, n, isnull;
20328 int needQuote;
20329 char ch;
20330 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
20331 char *escarg = va_arg(ap,char*);
 
 
 
 
 
 
20332 isnull = escarg==0;
20333 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
20334 k = precision;
20335 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
20336 if( ch==q ) n++;
@@ -20483,11 +20338,11 @@
20338 needQuote = !isnull && xtype==etSQLESCAPE2;
20339 n += i + 1 + needQuote*2;
20340 if( n>etBUFSIZE ){
20341 bufpt = zExtra = sqlite3Malloc( n );
20342 if( bufpt==0 ){
20343 pAccum->accError = STRACCUM_NOMEM;
20344 return;
20345 }
20346 }else{
20347 bufpt = buf;
20348 }
@@ -20506,28 +20361,26 @@
20361 ** if( precision>=0 && precision<length ) length = precision; */
20362 break;
20363 }
20364 case etTOKEN: {
20365 Token *pToken = va_arg(ap, Token*);
20366 if( pToken ){
 
20367 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20368 }
20369 length = width = 0;
20370 break;
20371 }
20372 case etSRCLIST: {
20373 SrcList *pSrc = va_arg(ap, SrcList*);
20374 int k = va_arg(ap, int);
20375 struct SrcList_item *pItem = &pSrc->a[k];
 
20376 assert( k>=0 && k<pSrc->nSrc );
20377 if( pItem->zDatabase ){
20378 sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
20379 sqlite3StrAccumAppend(pAccum, ".", 1);
20380 }
20381 sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
20382 length = width = 0;
20383 break;
20384 }
20385 default: {
20386 assert( xtype==etINVALID );
@@ -20554,42 +20407,44 @@
20407 nspace = width-length;
20408 if( nspace>0 ){
20409 sqlite3AppendSpace(pAccum, nspace);
20410 }
20411 }
20412 sqlite3_free(zExtra);
20413 }/* End for loop over the format string */
20414 } /* End of function */
20415
20416 /*
20417 ** Append N bytes of text from z to the StrAccum object.
20418 */
20419 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
20420 assert( z!=0 || N==0 );
20421 if( p->accError ){
20422 testcase(p->accError==STRACCUM_TOOBIG);
20423 testcase(p->accError==STRACCUM_NOMEM);
20424 return;
20425 }
20426 assert( p->zText!=0 || p->nChar==0 );
20427 if( N<=0 ){
20428 if( N==0 || z[0]==0 ) return;
20429 N = sqlite3Strlen30(z);
20430 }
20431 if( p->nChar+N >= p->nAlloc ){
20432 char *zNew;
 
 
 
 
 
20433 if( !p->useMalloc ){
20434 p->accError = STRACCUM_TOOBIG;
20435 N = p->nAlloc - p->nChar - 1;
 
20436 if( N<=0 ){
20437 return;
20438 }
20439 }else{
20440 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
20441 i64 szNew = p->nChar;
20442 szNew += N + 1;
20443 if( szNew > p->mxAlloc ){
20444 sqlite3StrAccumReset(p);
20445 p->accError = STRACCUM_TOOBIG;
20446 return;
20447 }else{
20448 p->nAlloc = (int)szNew;
20449 }
20450 if( p->useMalloc==1 ){
@@ -20599,28 +20454,20 @@
20454 }
20455 if( zNew ){
20456 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
20457 p->zText = zNew;
20458 }else{
20459 p->accError = STRACCUM_NOMEM;
20460 sqlite3StrAccumReset(p);
 
20461 return;
20462 }
20463 }
20464 }
20465 assert( p->zText );
20466 memcpy(&p->zText[p->nChar], z, N);
20467 p->nChar += N;
20468 }
 
 
 
 
 
 
 
 
20469
20470 /*
20471 ** Finish off a string by making sure it is zero-terminated.
20472 ** Return a pointer to the resulting string. Return a NULL
20473 ** pointer if any kind of error was encountered.
@@ -20635,11 +20482,11 @@
20482 p->zText = sqlite3_malloc(p->nChar+1);
20483 }
20484 if( p->zText ){
20485 memcpy(p->zText, p->zBase, p->nChar+1);
20486 }else{
20487 p->accError = STRACCUM_NOMEM;
20488 }
20489 }
20490 }
20491 return p->zText;
20492 }
@@ -20681,11 +20528,11 @@
20528 StrAccum acc;
20529 assert( db!=0 );
20530 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
20531 db->aLimit[SQLITE_LIMIT_LENGTH]);
20532 acc.db = db;
20533 sqlite3VXPrintf(&acc, 1, zFormat, ap);
20534 z = sqlite3StrAccumFinish(&acc);
20535 if( acc.accError==STRACCUM_NOMEM ){
20536 db->mallocFailed = 1;
20537 }
20538 return z;
@@ -20837,19 +20684,21 @@
20684 fprintf(stdout,"%s", zBuf);
20685 fflush(stdout);
20686 }
20687 #endif
20688
20689 #ifndef SQLITE_OMIT_TRACE
20690 /*
20691 ** variable-argument wrapper around sqlite3VXPrintf().
20692 */
20693 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){
20694 va_list ap;
20695 va_start(ap,zFormat);
20696 sqlite3VXPrintf(p, 1, zFormat, ap);
20697 va_end(ap);
20698 }
20699 #endif
20700
20701 /************** End of printf.c **********************************************/
20702 /************** Begin file random.c ******************************************/
20703 /*
20704 ** 2001 September 15
@@ -20902,16 +20751,10 @@
20751 #if SQLITE_THREADSAFE
20752 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
20753 sqlite3_mutex_enter(mutex);
20754 #endif
20755
 
 
 
 
 
 
20756 /* Initialize the state of the random number generator once,
20757 ** the first time this routine is called. The seed value does
20758 ** not need to contain a lot of randomness since we are not
20759 ** trying to do secure encryption or anything like that...
20760 **
@@ -20935,20 +20778,19 @@
20778 wsdPrng.s[i] = t;
20779 }
20780 wsdPrng.isInit = 1;
20781 }
20782
20783 while( N-- ){
 
20784 wsdPrng.i++;
20785 t = wsdPrng.s[wsdPrng.i];
20786 wsdPrng.j += t;
20787 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
20788 wsdPrng.s[wsdPrng.j] = t;
20789 t += wsdPrng.s[wsdPrng.i];
20790 *(zBuf++) = wsdPrng.s[t];
20791 }
20792 sqlite3_mutex_leave(mutex);
20793 }
20794
20795 #ifndef SQLITE_OMIT_BUILTIN_TEST
20796 /*
@@ -20973,10 +20815,13 @@
20815 &GLOBAL(struct sqlite3PrngType, sqlite3Prng),
20816 &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng),
20817 sizeof(sqlite3Prng)
20818 );
20819 }
20820 SQLITE_PRIVATE void sqlite3PrngResetState(void){
20821 GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0;
20822 }
20823 #endif /* SQLITE_OMIT_BUILTIN_TEST */
20824
20825 /************** End of random.c **********************************************/
20826 /************** Begin file utf.c *********************************************/
20827 /*
@@ -21624,21 +21469,22 @@
21469 ** To clear the most recent error for sqlite handle "db", sqlite3Error
21470 ** should be called with err_code set to SQLITE_OK and zFormat set
21471 ** to NULL.
21472 */
21473 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21474 if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21475 db->errCode = err_code;
21476 if( zFormat ){
21477 char *z;
21478 va_list ap;
21479 va_start(ap, zFormat);
21480 z = sqlite3VMPrintf(db, zFormat, ap);
21481 va_end(ap);
21482 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21483 }else{
21484 sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
21485 }
21486 }
21487 }
21488
21489 /*
21490 ** Add an error message to pParse->zErrMsg and increment pParse->nErr.
@@ -23119,11 +22965,11 @@
22965 /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
22966 /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
22967 /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
22968 /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
22969 /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
22970 /* 30 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"),
22971 /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
22972 /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
22973 /* 33 */ "CollSeq" OpHelp(""),
22974 /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
22975 /* 35 */ "MustBeInt" OpHelp(""),
@@ -23510,16 +23356,10 @@
23356 */
23357 char aPadding[32];
23358 #endif
23359 };
23360
 
 
 
 
 
 
23361 /*
23362 ** Allowed values for the unixFile.ctrlFlags bitmask:
23363 */
23364 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
23365 #define UNIXFILE_RDONLY 0x02 /* Connection is read only */
@@ -24779,19 +24619,10 @@
24619 }
24620 *ppInode = pInode;
24621 return SQLITE_OK;
24622 }
24623
 
 
 
 
 
 
 
 
 
24624
24625 /*
24626 ** Check a unixFile that is a database. Verify the following:
24627 **
24628 ** (1) There is exactly one hard link on the file
@@ -24822,11 +24653,14 @@
24653 if( buf.st_nlink>1 ){
24654 sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
24655 pFile->ctrlFlags |= UNIXFILE_WARNED;
24656 return;
24657 }
24658 if( pFile->pInode!=0
24659 && ((rc = osStat(pFile->zPath, &buf))!=0
24660 || buf.st_ino!=pFile->pInode->fileId.ino)
24661 ){
24662 sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
24663 pFile->ctrlFlags |= UNIXFILE_WARNED;
24664 return;
24665 }
24666 }
@@ -27271,14 +27105,10 @@
27105 unixGetTempname(pFile->pVfs->mxPathname, zTFile);
27106 *(char**)pArg = zTFile;
27107 }
27108 return SQLITE_OK;
27109 }
 
 
 
 
27110 #if SQLITE_MAX_MMAP_SIZE>0
27111 case SQLITE_FCNTL_MMAP_SIZE: {
27112 i64 newLimit = *(i64*)pArg;
27113 int rc = SQLITE_OK;
27114 if( newLimit>sqlite3GlobalConfig.mxMmap ){
@@ -29115,20 +28945,10 @@
28945 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
28946 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
28947 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
28948 );
28949
 
 
 
 
 
 
 
 
 
 
28950 memset(p, 0, sizeof(unixFile));
28951
28952 if( eType==SQLITE_OPEN_MAIN_DB ){
28953 UnixUnusedFd *pUnused;
28954 pUnused = findReusableFd(zName, flags);
@@ -29512,22 +29332,22 @@
29332 ** When testing, initializing zBuf[] to zero is all we do. That means
29333 ** that we always use the same random number sequence. This makes the
29334 ** tests repeatable.
29335 */
29336 memset(zBuf, 0, nBuf);
 
29337 #if !defined(SQLITE_TEST)
29338 {
29339 int pid, fd, got;
29340 fd = robust_open("/dev/urandom", O_RDONLY, 0);
29341 if( fd<0 ){
29342 time_t t;
29343 time(&t);
29344 memcpy(zBuf, &t, sizeof(t));
29345 pid = getpid();
29346 memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
29347 assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
29348 nBuf = sizeof(t) + sizeof(pid);
29349 }else{
29350 do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR );
29351 robust_close(0, fd, __LINE__);
29352 }
29353 }
@@ -34261,11 +34081,11 @@
34081 winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
34082 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34083 return SQLITE_OK;
34084 }
34085 case SQLITE_FCNTL_VFSNAME: {
34086 *(char**)pArg = sqlite3_mprintf("win32");
34087 OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
34088 return SQLITE_OK;
34089 }
34090 case SQLITE_FCNTL_WIN32_AV_RETRY: {
34091 int *a = (int*)pArg;
@@ -37703,11 +37523,10 @@
37523 ** in memory.
37524 */
37525 struct PgHdr1 {
37526 sqlite3_pcache_page page;
37527 unsigned int iKey; /* Key value (page number) */
 
37528 PgHdr1 *pNext; /* Next in hash table chain */
37529 PCache1 *pCache; /* Cache that currently owns this page */
37530 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
37531 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
37532 };
@@ -38032,36 +37851,38 @@
37851 ** This function is used internally to remove the page pPage from the
37852 ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
37853 ** LRU list, then this function is a no-op.
37854 **
37855 ** The PGroup mutex must be held when this function is called.
37856 **
37857 ** If pPage is NULL then this routine is a no-op.
37858 */
37859 static void pcache1PinPage(PgHdr1 *pPage){
37860 PCache1 *pCache;
37861 PGroup *pGroup;
37862
37863 if( pPage==0 ) return;
 
37864 pCache = pPage->pCache;
37865 pGroup = pCache->pGroup;
 
 
37866 assert( sqlite3_mutex_held(pGroup->mutex) );
37867 if( pPage->pLruNext || pPage==pGroup->pLruTail ){
37868 if( pPage->pLruPrev ){
37869 pPage->pLruPrev->pLruNext = pPage->pLruNext;
37870 }
37871 if( pPage->pLruNext ){
37872 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
37873 }
37874 if( pGroup->pLruHead==pPage ){
37875 pGroup->pLruHead = pPage->pLruNext;
37876 }
37877 if( pGroup->pLruTail==pPage ){
37878 pGroup->pLruTail = pPage->pLruPrev;
37879 }
37880 pPage->pLruNext = 0;
37881 pPage->pLruPrev = 0;
37882 pPage->pCache->nRecyclable--;
37883 }
37884 }
37885
37886
37887 /*
37888 ** Remove the page supplied as an argument from the hash table
@@ -38089,11 +37910,10 @@
37910 static void pcache1EnforceMaxPage(PGroup *pGroup){
37911 assert( sqlite3_mutex_held(pGroup->mutex) );
37912 while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
37913 PgHdr1 *p = pGroup->pLruTail;
37914 assert( p->pCache->pGroup==pGroup );
 
37915 pcache1PinPage(p);
37916 pcache1RemoveFromHash(p);
37917 pcache1FreePage(p);
37918 }
37919 }
@@ -38117,11 +37937,11 @@
37937 PgHdr1 *pPage;
37938 while( (pPage = *pp)!=0 ){
37939 if( pPage->iKey>=iLimit ){
37940 pCache->nPage--;
37941 *pp = pPage->pNext;
37942 pcache1PinPage(pPage);
37943 pcache1FreePage(pPage);
37944 }else{
37945 pp = &pPage->pNext;
37946 TESTONLY( nPage++; )
37947 }
@@ -38340,15 +38160,12 @@
38160 unsigned int h = iKey % pCache->nHash;
38161 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
38162 }
38163
38164 /* Step 2: Abort if no existing page is found and createFlag is 0 */
38165 if( pPage || createFlag==0 ){
38166 pcache1PinPage(pPage);
 
 
 
38167 goto fetch_out;
38168 }
38169
38170 /* The pGroup local variable will normally be initialized by the
38171 ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined,
@@ -38385,11 +38202,10 @@
38202 || pGroup->nCurrentPage>=pGroup->nMaxPage
38203 || pcache1UnderMemoryPressure(pCache)
38204 )){
38205 PCache1 *pOther;
38206 pPage = pGroup->pLruTail;
 
38207 pcache1RemoveFromHash(pPage);
38208 pcache1PinPage(pPage);
38209 pOther = pPage->pCache;
38210
38211 /* We want to verify that szPage and szExtra are the same for pOther
@@ -38422,11 +38238,10 @@
38238 pPage->iKey = iKey;
38239 pPage->pNext = pCache->apHash[h];
38240 pPage->pCache = pCache;
38241 pPage->pLruPrev = 0;
38242 pPage->pLruNext = 0;
 
38243 *(void **)pPage->page.pExtra = 0;
38244 pCache->apHash[h] = pPage;
38245 }
38246
38247 fetch_out:
@@ -38458,11 +38273,10 @@
38273 /* It is an error to call this function if the page is already
38274 ** part of the PGroup LRU list.
38275 */
38276 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
38277 assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
 
38278
38279 if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
38280 pcache1RemoveFromHash(pPage);
38281 pcache1FreePage(pPage);
38282 }else{
@@ -38474,11 +38288,10 @@
38288 }else{
38289 pGroup->pLruTail = pPage;
38290 pGroup->pLruHead = pPage;
38291 }
38292 pCache->nRecyclable++;
 
38293 }
38294
38295 pcache1LeaveMutex(pCache->pGroup);
38296 }
38297
@@ -38601,11 +38414,10 @@
38414 while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
38415 nFree += pcache1MemSize(p->page.pBuf);
38416 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
38417 nFree += sqlite3MemSize(p);
38418 #endif
 
38419 pcache1PinPage(p);
38420 pcache1RemoveFromHash(p);
38421 pcache1FreePage(p);
38422 }
38423 pcache1LeaveMutex(&pcache1.grp);
@@ -38626,11 +38438,10 @@
38438 int *pnRecyclable /* OUT: Total number of pages available for recycling */
38439 ){
38440 PgHdr1 *p;
38441 int nRecyclable = 0;
38442 for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
 
38443 nRecyclable++;
38444 }
38445 *pnCurrent = pcache1.grp.nCurrentPage;
38446 *pnMax = (int)pcache1.grp.nMaxPage;
38447 *pnMin = (int)pcache1.grp.nMinPage;
@@ -40313,26 +40124,29 @@
40124 ** PagerSavepoint.pInSavepoint.
40125 */
40126 static int subjRequiresPage(PgHdr *pPg){
40127 Pager *pPager = pPg->pPager;
40128 PagerSavepoint *p;
40129 Pgno pgno;
40130 int i;
40131 if( pPager->nSavepoint ){
40132 pgno = pPg->pgno;
40133 for(i=0; i<pPager->nSavepoint; i++){
40134 p = &pPager->aSavepoint[i];
40135 if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40136 return 1;
40137 }
40138 }
40139 }
40140 return 0;
40141 }
40142
40143 /*
40144 ** Return true if the page is already in the journal file.
40145 */
40146 static int pageInJournal(PgHdr *pPg){
40147 return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
40148 }
40149
40150 /*
40151 ** Read a 32-bit integer from the given file descriptor. Store the integer
40152 ** that is read in *pRes. Return SQLITE_OK if everything worked, or an
@@ -40535,11 +40349,10 @@
40349
40350 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
40351 || szJ<16
40352 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
40353 || len>=nMaster
 
40354 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
40355 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
40356 || memcmp(aMagic, aJournalMagic, 8)
40357 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
40358 ){
@@ -41276,11 +41089,11 @@
41089 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
41090 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
41091 PgHdr *p = pager_lookup(pPager, 1);
41092 if( p ){
41093 p->pageHash = 0;
41094 sqlite3PagerUnref(p);
41095 }
41096 }
41097 #endif
41098
41099 sqlite3BitvecDestroy(pPager->pInJournal);
@@ -41305,15 +41118,10 @@
41118 ** required size. */
41119 assert( pPager->eLock==EXCLUSIVE_LOCK );
41120 rc = pager_truncate(pPager, pPager->dbSize);
41121 }
41122
 
 
 
 
 
41123 if( !pPager->exclusiveMode
41124 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
41125 ){
41126 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
41127 pPager->changeCountDone = 0;
@@ -42123,11 +41931,11 @@
41931 testcase( rc!=SQLITE_OK );
41932 }
41933 if( rc==SQLITE_OK
41934 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
41935 ){
41936 rc = sqlite3PagerSync(pPager);
41937 }
41938 if( rc==SQLITE_OK ){
41939 rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
41940 testcase( rc!=SQLITE_OK );
41941 }
@@ -42269,11 +42077,11 @@
42077 rc = readDbPage(pPg, iFrame);
42078 }
42079 if( rc==SQLITE_OK ){
42080 pPager->xReiniter(pPg);
42081 }
42082 sqlite3PagerUnref(pPg);
42083 }
42084 }
42085
42086 /* Normally, if a transaction is rolled back, any backup processes are
42087 ** updated as data is copied out of the rollback journal and into the
@@ -43624,11 +43432,11 @@
43432 /* Open the sub-journal, if it has not already been opened */
43433 assert( pPager->useJournal );
43434 assert( isOpen(pPager->jfd) || pagerUseWal(pPager) );
43435 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
43436 assert( pagerUseWal(pPager)
43437 || pageInJournal(pPg)
43438 || pPg->pgno>pPager->dbOrigSize
43439 );
43440 rc = openSubJournal(pPager);
43441
43442 /* If the sub-journal was opened successfully (or was already open),
@@ -44089,34 +43897,10 @@
43897 *ppPager = pPager;
43898 return SQLITE_OK;
43899 }
43900
43901
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43902
43903 /*
43904 ** This function is called after transitioning from PAGER_UNLOCK to
43905 ** PAGER_SHARED state. It tests if there is a hot journal present in
43906 ** the file-system for the given pager. A hot journal is one that
@@ -44584,11 +44368,11 @@
44368 if( bMmapOk && pagerUseWal(pPager) ){
44369 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
44370 if( rc!=SQLITE_OK ) goto pager_acquire_err;
44371 }
44372
44373 if( iFrame==0 && bMmapOk ){
44374 void *pData = 0;
44375
44376 rc = sqlite3OsFetch(pPager->fd,
44377 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
44378 );
@@ -44725,23 +44509,20 @@
44509 ** If the number of references to the page drop to zero, then the
44510 ** page is added to the LRU list. When all references to all pages
44511 ** are released, a rollback occurs and the lock on the database is
44512 ** removed.
44513 */
 
 
 
 
 
 
 
 
 
 
 
44514 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
44515 if( pPg ){
44516 Pager *pPager = pPg->pPager;
44517 if( pPg->flags & PGHDR_MMAP ){
44518 pagerReleaseMapPage(pPg);
44519 }else{
44520 sqlite3PcacheRelease(pPg);
44521 }
44522 pagerUnlockIfUnused(pPager);
44523 }
44524 }
44525
44526 /*
44527 ** This function is called at the start of every write transaction.
44528 ** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -44792,23 +44573,17 @@
44573 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
44574 (pPager->tempFile ?
44575 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
44576 (SQLITE_OPEN_MAIN_JOURNAL)
44577 );
44578 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
44579 rc = sqlite3JournalOpen(
44580 pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
44581 );
44582 #else
44583 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
44584 #endif
 
 
 
 
 
 
44585 }
44586 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
44587 }
44588
44589
@@ -44925,13 +44700,13 @@
44700 ** one of the journals, the corresponding bit is set in the
44701 ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
44702 ** of any open savepoints as appropriate.
44703 */
44704 static int pager_write(PgHdr *pPg){
44705 void *pData = pPg->pData;
44706 Pager *pPager = pPg->pPager;
44707 int rc = SQLITE_OK;
 
44708
44709 /* This routine is not called unless a write-transaction has already
44710 ** been started. The journal file may or may not be open at this point.
44711 ** It is never called in the ERROR state.
44712 */
@@ -44938,12 +44713,18 @@
44713 assert( pPager->eState==PAGER_WRITER_LOCKED
44714 || pPager->eState==PAGER_WRITER_CACHEMOD
44715 || pPager->eState==PAGER_WRITER_DBMOD
44716 );
44717 assert( assert_pager_state(pPager) );
44718
44719 /* If an error has been previously detected, report the same error
44720 ** again. This should not happen, but the check provides robustness. */
44721 if( NEVER(pPager->errCode) ) return pPager->errCode;
44722
44723 /* Higher-level routines never call this function if database is not
44724 ** writable. But check anyway, just for robustness. */
44725 if( NEVER(pPager->readOnly) ) return SQLITE_PERM;
44726
44727 CHECK_PAGE(pPg);
44728
44729 /* The journal file needs to be opened. Higher level routines have already
44730 ** obtained the necessary locks to begin the write-transaction, but the
@@ -44963,20 +44744,19 @@
44744
44745 /* Mark the page as dirty. If the page has already been written
44746 ** to the journal then we can return right away.
44747 */
44748 sqlite3PcacheMakeDirty(pPg);
44749 if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){
 
44750 assert( !pagerUseWal(pPager) );
44751 }else{
44752
44753 /* The transaction journal now exists and we have a RESERVED or an
44754 ** EXCLUSIVE lock on the main database file. Write the current page to
44755 ** the transaction journal if it is not there already.
44756 */
44757 if( !pageInJournal(pPg) && !pagerUseWal(pPager) ){
44758 assert( pagerUseWal(pPager)==0 );
44759 if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){
44760 u32 cksum;
44761 char *pData2;
44762 i64 iOff = pPager->journalOff;
@@ -44985,11 +44765,11 @@
44765 ** contains the database locks. The following assert verifies
44766 ** that we do not. */
44767 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
44768
44769 assert( pPager->journalHdr<=pPager->journalOff );
44770 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
44771 cksum = pager_cksum(pPager, (u8*)pData2);
44772
44773 /* Even if an IO or diskfull error occurs while journalling the
44774 ** page in the block above, set the need-sync flag for the page.
44775 ** Otherwise, when the transaction is rolled back, the logic in
@@ -45037,11 +44817,11 @@
44817 /* If the statement journal is open and the page is not in it,
44818 ** then write the current page to the statement journal. Note that
44819 ** the statement journal format differs from the standard journal format
44820 ** in that it omits the checksums and the header.
44821 */
44822 if( subjRequiresPage(pPg) ){
44823 rc = subjournalPage(pPg);
44824 }
44825 }
44826
44827 /* Update the database size and return.
@@ -45069,23 +44849,23 @@
44849 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
44850 int rc = SQLITE_OK;
44851
44852 PgHdr *pPg = pDbPage;
44853 Pager *pPager = pPg->pPager;
44854 Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
44855
44856 assert( (pPg->flags & PGHDR_MMAP)==0 );
44857 assert( pPager->eState>=PAGER_WRITER_LOCKED );
44858 assert( pPager->eState!=PAGER_ERROR );
44859 assert( assert_pager_state(pPager) );
44860
44861 if( nPagePerSector>1 ){
44862 Pgno nPageCount; /* Total number of pages in database file */
44863 Pgno pg1; /* First page of the sector pPg is located on. */
44864 int nPage = 0; /* Number of pages starting at pg1 to journal */
44865 int ii; /* Loop counter */
44866 int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */
 
44867
44868 /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow
44869 ** a journal header to be written between the pages journaled by
44870 ** this function.
44871 */
@@ -45120,18 +44900,18 @@
44900 if( rc==SQLITE_OK ){
44901 rc = pager_write(pPage);
44902 if( pPage->flags&PGHDR_NEED_SYNC ){
44903 needSync = 1;
44904 }
44905 sqlite3PagerUnref(pPage);
44906 }
44907 }
44908 }else if( (pPage = pager_lookup(pPager, pg))!=0 ){
44909 if( pPage->flags&PGHDR_NEED_SYNC ){
44910 needSync = 1;
44911 }
44912 sqlite3PagerUnref(pPage);
44913 }
44914 }
44915
44916 /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
44917 ** starting at pg1, then it needs to be set for all of them. Because
@@ -45143,11 +44923,11 @@
44923 assert( !MEMDB );
44924 for(ii=0; ii<nPage; ii++){
44925 PgHdr *pPage = pager_lookup(pPager, pg1+ii);
44926 if( pPage ){
44927 pPage->flags |= PGHDR_NEED_SYNC;
44928 sqlite3PagerUnref(pPage);
44929 }
44930 }
44931 }
44932
44933 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
@@ -45296,21 +45076,21 @@
45076 ** or pages with the Pager.noSync flag set.
45077 **
45078 ** If successful, or if called on a pager for which it is a no-op, this
45079 ** function returns SQLITE_OK. Otherwise, an IO error code is returned.
45080 */
45081 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
45082 int rc = SQLITE_OK;
45083 if( !pPager->noSync ){
 
 
 
 
 
 
45084 assert( !MEMDB );
45085 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
45086 }else if( isOpen(pPager->fd) ){
45087 assert( !MEMDB );
45088 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0);
45089 if( rc==SQLITE_NOTFOUND ){
45090 rc = SQLITE_OK;
45091 }
45092 }
45093 return rc;
45094 }
45095
45096 /*
@@ -45505,11 +45285,11 @@
45285 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
45286 }
45287
45288 /* Finally, sync the database file. */
45289 if( !noSync ){
45290 rc = sqlite3PagerSync(pPager);
45291 }
45292 IOTRACE(("DBSYNC %p\n", pPager))
45293 }
45294 }
45295
@@ -45634,13 +45414,11 @@
45414 rc = pager_playback(pPager, 0);
45415 }
45416
45417 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
45418 assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT
45419 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR );
 
 
45420
45421 /* If an error occurs during a ROLLBACK, we can no longer trust the pager
45422 ** cache. So call pager_error() on the way out to make any error persistent.
45423 */
45424 return pager_error(pPager, rc);
@@ -46039,11 +45817,11 @@
45817 ** can be written to. The caller has already promised not to write to it.
45818 */
45819 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
45820 needSyncPgno = pPg->pgno;
45821 assert( pPager->journalMode==PAGER_JOURNALMODE_OFF ||
45822 pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
45823 assert( pPg->flags&PGHDR_DIRTY );
45824 }
45825
45826 /* If the cache contains a page with page-number pgno, remove it
45827 ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
@@ -46073,11 +45851,11 @@
45851 ** as the original page since it has already been allocated.
45852 */
45853 if( MEMDB ){
45854 assert( pPgOld );
45855 sqlite3PcacheMove(pPgOld, origPgno);
45856 sqlite3PagerUnref(pPgOld);
45857 }
45858
45859 if( needSyncPgno ){
45860 /* If needSyncPgno is non-zero, then the journal file needs to be
45861 ** sync()ed before any data is written to database file page needSyncPgno.
@@ -46102,11 +45880,11 @@
45880 }
45881 return rc;
45882 }
45883 pPgHdr->flags |= PGHDR_NEED_SYNC;
45884 sqlite3PcacheMakeDirty(pPgHdr);
45885 sqlite3PagerUnref(pPgHdr);
45886 }
45887
45888 return SQLITE_OK;
45889 }
45890 #endif
@@ -52221,11 +51999,11 @@
51999
52000 if( pgno>btreePagecount(pBt) ){
52001 rc = SQLITE_CORRUPT_BKPT;
52002 }else{
52003 rc = btreeGetPage(pBt, pgno, ppPage, bReadonly);
52004 if( rc==SQLITE_OK ){
52005 rc = btreeInitPage(*ppPage);
52006 if( rc!=SQLITE_OK ){
52007 releasePage(*ppPage);
52008 }
52009 }
@@ -52242,15 +52020,14 @@
52020 */
52021 static void releasePage(MemPage *pPage){
52022 if( pPage ){
52023 assert( pPage->aData );
52024 assert( pPage->pBt );
 
52025 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
52026 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
52027 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52028 sqlite3PagerUnref(pPage->pDbPage);
52029 }
52030 }
52031
52032 /*
52033 ** During a rollback, when the pager reloads information into the cache
@@ -54762,14 +54539,14 @@
54539 }
54540
54541 /*
54542 ** Return a pointer to payload information from the entry that the
54543 ** pCur cursor is pointing to. The pointer is to the beginning of
54544 ** the key if skipKey==0 and it points to the beginning of data if
54545 ** skipKey==1. The number of bytes of available key/data is written
54546 ** into *pAmt. If *pAmt==0, then the value returned will not be
54547 ** a valid pointer.
54548 **
54549 ** This routine is an optimization. It is common for the entire key
54550 ** and data to fit on the local page and for there to be no overflow
54551 ** pages. When that is so, this routine can be used to access the
54552 ** key and data without making a copy. If the key and/or data spills
@@ -54778,25 +54555,45 @@
54555 **
54556 ** The pointer returned by this routine looks directly into the cached
54557 ** page of the database. The data might change or move the next time
54558 ** any btree routine is called.
54559 */
54560 static const unsigned char *fetchPayload(
54561 BtCursor *pCur, /* Cursor pointing to entry to read from */
54562 u32 *pAmt, /* Write the number of available bytes here */
54563 int skipKey /* read beginning at data if this is true */
54564 ){
54565 unsigned char *aPayload;
54566 MemPage *pPage;
54567 u32 nKey;
54568 u32 nLocal;
54569
54570 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
54571 assert( pCur->eState==CURSOR_VALID );
 
54572 assert( cursorHoldsMutex(pCur) );
54573 pPage = pCur->apPage[pCur->iPage];
54574 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
54575 if( pCur->info.nSize==0 ){
54576 btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage],
54577 &pCur->info);
54578 }
54579 aPayload = pCur->info.pCell;
54580 aPayload += pCur->info.nHeader;
54581 if( pPage->intKey ){
54582 nKey = 0;
54583 }else{
54584 nKey = (int)pCur->info.nKey;
54585 }
54586 if( skipKey ){
54587 aPayload += nKey;
54588 nLocal = pCur->info.nLocal - nKey;
54589 }else{
54590 nLocal = pCur->info.nLocal;
54591 assert( nLocal<=nKey );
54592 }
54593 *pAmt = nLocal;
54594 return aPayload;
54595 }
54596
54597
54598 /*
54599 ** For the entry that cursor pCur is point to, return as
@@ -54811,14 +54608,26 @@
54608 **
54609 ** These routines is used to get quick access to key and data
54610 ** in the common case where no overflow pages are used.
54611 */
54612 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
54613 const void *p = 0;
54614 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54615 assert( cursorHoldsMutex(pCur) );
54616 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54617 p = (const void*)fetchPayload(pCur, pAmt, 0);
54618 }
54619 return p;
54620 }
54621 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
54622 const void *p = 0;
54623 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54624 assert( cursorHoldsMutex(pCur) );
54625 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54626 p = (const void*)fetchPayload(pCur, pAmt, 1);
54627 }
54628 return p;
54629 }
54630
54631
54632 /*
54633 ** Move the cursor down to a new child page. The newPgno argument is the
@@ -54933,10 +54742,12 @@
54742 ** b-tree).
54743 */
54744 static int moveToRoot(BtCursor *pCur){
54745 MemPage *pRoot;
54746 int rc = SQLITE_OK;
54747 Btree *p = pCur->pBtree;
54748 BtShared *pBt = p->pBt;
54749
54750 assert( cursorHoldsMutex(pCur) );
54751 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
54752 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
54753 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
@@ -54947,16 +54758,20 @@
54758 }
54759 sqlite3BtreeClearCursor(pCur);
54760 }
54761
54762 if( pCur->iPage>=0 ){
54763 int i;
54764 for(i=1; i<=pCur->iPage; i++){
54765 releasePage(pCur->apPage[i]);
54766 }
54767 pCur->iPage = 0;
54768 }else if( pCur->pgnoRoot==0 ){
54769 pCur->eState = CURSOR_INVALID;
54770 return SQLITE_OK;
54771 }else{
54772 rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0],
54773 pCur->wrFlag==0 ? PAGER_GET_READONLY : 0);
54774 if( rc!=SQLITE_OK ){
54775 pCur->eState = CURSOR_INVALID;
54776 return rc;
54777 }
@@ -54985,20 +54800,18 @@
54800 pCur->aiIdx[0] = 0;
54801 pCur->info.nSize = 0;
54802 pCur->atLast = 0;
54803 pCur->validNKey = 0;
54804
54805 if( pRoot->nCell==0 && !pRoot->leaf ){
 
 
54806 Pgno subpage;
54807 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
54808 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
54809 pCur->eState = CURSOR_VALID;
54810 rc = moveToChild(pCur, subpage);
54811 }else{
54812 pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID);
54813 }
54814 return rc;
54815 }
54816
54817 /*
@@ -55250,18 +55063,21 @@
55063 ** the entire cell by checking for the cases where the record is
55064 ** stored entirely within the b-tree page by inspecting the first
55065 ** 2 bytes of the cell.
55066 */
55067 nCell = pCell[0];
55068 if( nCell<=pPage->max1bytePayload
55069 /* && (pCell+nCell)<pPage->aDataEnd */
55070 ){
55071 /* This branch runs if the record-size field of the cell is a
55072 ** single byte varint and the record fits entirely on the main
55073 ** b-tree page. */
55074 testcase( pCell+nCell+1==pPage->aDataEnd );
55075 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
55076 }else if( !(pCell[1] & 0x80)
55077 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
55078 /* && (pCell+nCell+2)<=pPage->aDataEnd */
55079 ){
55080 /* The record-size field is a 2 byte varint and the record
55081 ** fits entirely on the main b-tree page. */
55082 testcase( pCell+nCell+2==pPage->aDataEnd );
55083 c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
@@ -56081,11 +55897,11 @@
55897 nHeader = 0;
55898 if( !pPage->leaf ){
55899 nHeader += 4;
55900 }
55901 if( pPage->hasData ){
55902 nHeader += putVarint(&pCell[nHeader], nData+nZero);
55903 }else{
55904 nData = nZero = 0;
55905 }
55906 nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
55907 btreeParseCellPtr(pPage, pCell, &info);
@@ -56209,10 +56025,11 @@
56025 */
56026 static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
56027 u32 pc; /* Offset to cell content of cell being deleted */
56028 u8 *data; /* pPage->aData */
56029 u8 *ptr; /* Used to move bytes around within data[] */
56030 u8 *endPtr; /* End of loop */
56031 int rc; /* The return code */
56032 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
56033
56034 if( *pRC ) return;
56035
@@ -56232,13 +56049,18 @@
56049 }
56050 rc = freeSpace(pPage, pc, sz);
56051 if( rc ){
56052 *pRC = rc;
56053 return;
56054 }
56055 endPtr = &pPage->aCellIdx[2*pPage->nCell - 2];
56056 assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
56057 while( ptr<endPtr ){
56058 *(u16*)ptr = *(u16*)&ptr[2];
56059 ptr += 2;
56060 }
56061 pPage->nCell--;
 
56062 put2byte(&data[hdr+3], pPage->nCell);
56063 pPage->nFree += 2;
56064 }
56065
56066 /*
@@ -56271,10 +56093,13 @@
56093 int j; /* Loop counter */
56094 int end; /* First byte past the last cell pointer in data[] */
56095 int ins; /* Index in data[] where new cell pointer is inserted */
56096 int cellOffset; /* Address of first cell pointer in data[] */
56097 u8 *data; /* The content of the whole page */
56098 u8 *ptr; /* Used for moving information around in data[] */
56099 u8 *endPtr; /* End of the loop */
56100
56101 int nSkip = (iChild ? 4 : 0);
56102
56103 if( *pRC ) return;
56104
56105 assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
@@ -56321,11 +56146,17 @@
56146 pPage->nFree -= (u16)(2 + sz);
56147 memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
56148 if( iChild ){
56149 put4byte(&data[idx], iChild);
56150 }
56151 ptr = &data[end];
56152 endPtr = &data[ins];
56153 assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */
56154 while( ptr>endPtr ){
56155 *(u16*)ptr = *(u16*)&ptr[-2];
56156 ptr -= 2;
56157 }
56158 put2byte(&data[ins], idx);
56159 put2byte(&data[pPage->hdrOffset+3], pPage->nCell);
56160 #ifndef SQLITE_OMIT_AUTOVACUUM
56161 if( pPage->pBt->autoVacuum ){
56162 /* The cell may contain a pointer to an overflow page. If so, write
@@ -58283,11 +58114,11 @@
58114 va_start(ap, zFormat);
58115 if( pCheck->errMsg.nChar ){
58116 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
58117 }
58118 if( zMsg1 ){
58119 sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1);
58120 }
58121 sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap);
58122 va_end(ap);
58123 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
58124 pCheck->mallocFailed = 1;
@@ -59577,11 +59408,11 @@
59408 rc = backupTruncateFile(pFile, iSize);
59409 }
59410
59411 /* Sync the database file to disk. */
59412 if( rc==SQLITE_OK ){
59413 rc = sqlite3PagerSync(pDestPager);
59414 }
59415 }else{
59416 sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
59417 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
59418 }
@@ -59652,14 +59483,14 @@
59483 /* If a transaction is still open on the Btree, roll it back. */
59484 sqlite3BtreeRollback(p->pDest, SQLITE_OK);
59485
59486 /* Set the error code of the destination database handle. */
59487 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
59488 sqlite3Error(p->pDestDb, rc, 0);
59489
59490 /* Exit the mutexes and free the backup context structure. */
59491 if( p->pDestDb ){
 
 
 
59492 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
59493 }
59494 sqlite3BtreeLeave(p->pSrc);
59495 if( p->pDestDb ){
59496 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
@@ -59859,59 +59690,61 @@
59690 #endif
59691 }
59692
59693 /*
59694 ** Make sure pMem->z points to a writable allocation of at least
59695 ** n bytes.
59696 **
59697 ** If the third argument passed to this function is true, then memory
59698 ** cell pMem must contain a string or blob. In this case the content is
59699 ** preserved. Otherwise, if the third parameter to this function is false,
59700 ** any current string or blob value may be discarded.
59701 **
59702 ** This function sets the MEM_Dyn flag and clears any xDel callback.
59703 ** It also clears MEM_Ephem and MEM_Static. If the preserve flag is
59704 ** not set, Mem.n is zeroed.
59705 */
59706 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
59707 assert( 1 >=
59708 ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) +
59709 (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) +
59710 ((pMem->flags&MEM_Ephem) ? 1 : 0) +
59711 ((pMem->flags&MEM_Static) ? 1 : 0)
59712 );
59713 assert( (pMem->flags&MEM_RowSet)==0 );
59714
59715 /* If the preserve flag is set to true, then the memory cell must already
59716 ** contain a valid string or blob value. */
59717 assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
 
59718
59719 if( n<32 ) n = 32;
59720 if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){
59721 if( preserve && pMem->z==pMem->zMalloc ){
59722 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
59723 preserve = 0;
59724 }else{
59725 sqlite3DbFree(pMem->db, pMem->zMalloc);
59726 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
59727 }
 
 
 
 
 
59728 }
59729
59730 if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
59731 memcpy(pMem->zMalloc, pMem->z, pMem->n);
59732 }
59733 if( pMem->flags&MEM_Dyn && pMem->xDel ){
59734 assert( pMem->xDel!=SQLITE_DYNAMIC );
59735 pMem->xDel((void *)(pMem->z));
59736 }
59737
59738 pMem->z = pMem->zMalloc;
59739 if( pMem->z==0 ){
59740 pMem->flags = MEM_Null;
59741 }else{
59742 pMem->flags &= ~(MEM_Ephem|MEM_Static);
59743 }
59744 pMem->xDel = 0;
59745 return (pMem->z ? SQLITE_OK : SQLITE_NOMEM);
59746 }
59747
59748 /*
59749 ** Make the given Mem object MEM_Dyn. In other words, make it so
59750 ** that any TEXT or BLOB content is stored in memory obtained from
@@ -60093,16 +59926,14 @@
59926 ** inconsistent state, for example with (Mem.z==0) and
59927 ** (Mem.type==SQLITE_TEXT).
59928 */
59929 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
59930 VdbeMemRelease(p);
59931 sqlite3DbFree(p->db, p->zMalloc);
 
 
 
59932 p->z = 0;
59933 p->zMalloc = 0;
59934 p->xDel = 0;
59935 }
59936
59937 /*
59938 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
59939 ** If the double is out of range of a 64-bit signed integer then
@@ -60282,13 +60113,10 @@
60113 sqlite3RowSetClear(pMem->u.pRowSet);
60114 }
60115 MemSetTypeFlag(pMem, MEM_Null);
60116 pMem->type = SQLITE_NULL;
60117 }
 
 
 
60118
60119 /*
60120 ** Delete any previous value and set the value to be a BLOB of length
60121 ** n containing all zeros.
60122 */
@@ -61022,11 +60850,11 @@
60850 if( aRet==0 ){
60851 sqlite3_result_error_nomem(context);
60852 }else{
60853 aRet[0] = nSerial+1;
60854 sqlite3PutVarint(&aRet[1], iSerial);
60855 sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format);
60856 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
60857 sqlite3DbFree(db, aRet);
60858 }
60859 }
60860
@@ -61207,12 +61035,11 @@
61035 */
61036
61037 /*
61038 ** Create a new virtual database engine.
61039 */
61040 SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){
 
61041 Vdbe *p;
61042 p = sqlite3DbMallocZero(db, sizeof(Vdbe) );
61043 if( p==0 ) return 0;
61044 p->db = db;
61045 if( db->pVdbe ){
@@ -61220,14 +61047,10 @@
61047 }
61048 p->pNext = db->pVdbe;
61049 p->pPrev = 0;
61050 db->pVdbe = p;
61051 p->magic = VDBE_MAGIC_INIT;
 
 
 
 
61052 return p;
61053 }
61054
61055 /*
61056 ** Remember the SQL string for a prepared statement.
@@ -61279,18 +61102,17 @@
61102 ** If an out-of-memory error occurs while resizing the array, return
61103 ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain
61104 ** unchanged (this is so that any opcodes already allocated can be
61105 ** correctly deallocated along with the rest of the Vdbe).
61106 */
61107 static int growOpArray(Vdbe *p){
61108 VdbeOp *pNew;
 
61109 int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op)));
61110 pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op));
61111 if( pNew ){
61112 p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
61113 p->aOp = pNew;
61114 }
61115 return (pNew ? SQLITE_OK : SQLITE_NOMEM);
61116 }
61117
61118 #ifdef SQLITE_DEBUG
@@ -61325,11 +61147,11 @@
61147 VdbeOp *pOp;
61148
61149 i = p->nOp;
61150 assert( p->magic==VDBE_MAGIC_INIT );
61151 assert( op>0 && op<0xff );
61152 if( p->nOpAlloc<=i ){
61153 if( growOpArray(p) ){
61154 return 1;
61155 }
61156 }
61157 p->nOp++;
@@ -61344,19 +61166,10 @@
61166 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61167 pOp->zComment = 0;
61168 #endif
61169 #ifdef SQLITE_DEBUG
61170 if( p->db->flags & SQLITE_VdbeAddopTrace ){
 
 
 
 
 
 
 
 
 
61171 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
61172 test_addop_breakpoint();
61173 }
61174 #endif
61175 #ifdef VDBE_PROFILE
@@ -61436,14 +61249,13 @@
61249 ** always negative and P2 values are suppose to be non-negative.
61250 ** Hence, a negative P2 value is a label that has yet to be resolved.
61251 **
61252 ** Zero is returned if a malloc() fails.
61253 */
61254 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){
 
61255 int i = p->nLabel++;
61256 assert( p->magic==VDBE_MAGIC_INIT );
61257 if( (i & (i-1))==0 ){
61258 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
61259 (i*2+1)*sizeof(p->aLabel[0]));
61260 }
61261 if( p->aLabel ){
@@ -61455,17 +61267,16 @@
61267 /*
61268 ** Resolve label "x" to be the address of the next instruction to
61269 ** be inserted. The parameter "x" must have been obtained from
61270 ** a prior call to sqlite3VdbeMakeLabel().
61271 */
61272 SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){
 
61273 int j = -1-x;
61274 assert( p->magic==VDBE_MAGIC_INIT );
61275 assert( j<p->nLabel );
61276 if( j>=0 && p->aLabel ){
61277 p->aLabel[j] = p->nOp;
61278 }
61279 }
61280
61281 /*
61282 ** Mark the VDBE as one that can only be run one time.
@@ -61610,12 +61421,11 @@
61421 */
61422 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
61423 int i;
61424 int nMaxArgs = *pMaxFuncArgs;
61425 Op *pOp;
61426 int *aLabel = p->aLabel;
 
61427 p->readOnly = 1;
61428 p->bIsReader = 0;
61429 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
61430 u8 opcode = pOp->opcode;
61431
@@ -61674,17 +61484,16 @@
61484 }
61485 }
61486
61487 pOp->opflags = sqlite3OpcodeProperty[opcode];
61488 if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
61489 assert( -1-pOp->p2<p->nLabel );
61490 pOp->p2 = aLabel[-1-pOp->p2];
61491 }
61492 }
61493 sqlite3DbFree(p->db, p->aLabel);
61494 p->aLabel = 0;
 
61495 *pMaxFuncArgs = nMaxArgs;
61496 assert( p->bIsReader!=0 || p->btreeMask==0 );
61497 }
61498
61499 /*
@@ -61724,11 +61533,11 @@
61533 ** address of the first operation added.
61534 */
61535 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61536 int addr;
61537 assert( p->magic==VDBE_MAGIC_INIT );
61538 if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){
61539 return 0;
61540 }
61541 addr = p->nOp;
61542 if( ALWAYS(nOp>0) ){
61543 int i;
@@ -61913,17 +61722,10 @@
61722 pOp->opcode = OP_Noop;
61723 if( addr==p->nOp-1 ) p->nOp--;
61724 }
61725 }
61726
 
 
 
 
 
 
 
61727 /*
61728 ** Change the value of the P4 operand for a specific instruction.
61729 ** This routine is useful when a large program is loaded from a
61730 ** static array using sqlite3VdbeAddOpList but we want to make a
61731 ** few minor changes to the program.
@@ -62085,21 +61887,11 @@
61887 if( c=='4' ) return pOp->p4.i;
61888 return pOp->p5;
61889 }
61890
61891 /*
61892 ** Compute a string for the "comment" field of a VDBE opcode listing
 
 
 
 
 
 
 
 
 
 
61893 */
61894 static int displayComment(
61895 const Op *pOp, /* The opcode to be commented */
61896 const char *zP4, /* Previously obtained value for P4 */
61897 char *zTemp, /* Write result here */
@@ -62129,17 +61921,11 @@
61921 sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
61922 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
61923 ii += 3;
61924 jj += sqlite3Strlen30(zTemp+jj);
61925 v2 = translateP(zSynopsis[ii], pOp);
61926 if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
 
 
 
 
 
 
61927 }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
61928 ii += 4;
61929 }
61930 }
61931 jj += sqlite3Strlen30(zTemp+jj);
@@ -62367,13 +62153,10 @@
62153 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62154 displayComment(pOp, zP4, zCom, sizeof(zCom));
62155 #else
62156 zCom[0] = 0
62157 #endif
 
 
 
62158 fprintf(pOut, zFormat1, pc,
62159 sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5,
62160 zCom
62161 );
62162 fflush(pOut);
@@ -62801,11 +62584,10 @@
62584
62585 assert( p!=0 );
62586 assert( p->nOp>0 );
62587 assert( pParse!=0 );
62588 assert( p->magic==VDBE_MAGIC_INIT );
 
62589 db = p->db;
62590 assert( db->mallocFailed==0 );
62591 nVar = pParse->nVar;
62592 nMem = pParse->nMem;
62593 nCursor = pParse->nTab;
@@ -62825,12 +62607,12 @@
62607 nMem += nCursor;
62608
62609 /* Allocate space for memory registers, SQL variables, VDBE cursors and
62610 ** an array to marshal SQL function arguments in.
62611 */
62612 zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */
62613 zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */
62614
62615 resolveP2Values(p, &nArg);
62616 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
62617 if( pParse->explain && nMem<10 ){
62618 nMem = 10;
@@ -63653,11 +63435,10 @@
63435 sqlite3 *db = p->db;
63436 int rc = p->rc;
63437 if( p->zErrMsg ){
63438 u8 mallocFailed = db->mallocFailed;
63439 sqlite3BeginBenignMalloc();
 
63440 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
63441 sqlite3EndBenignMalloc();
63442 db->mallocFailed = mallocFailed;
63443 db->errCode = rc;
63444 }else{
@@ -63722,11 +63503,12 @@
63503 }else if( p->rc && p->expired ){
63504 /* The expired flag was set on the VDBE before the first call
63505 ** to sqlite3_step(). For consistency (since sqlite3_step() was
63506 ** called), set the database error in this case as well.
63507 */
63508 sqlite3Error(db, p->rc, 0);
63509 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
63510 sqlite3DbFree(db, p->zErrMsg);
63511 p->zErrMsg = 0;
63512 }
63513
63514 /* Reclaim all memory used by the VDBE
@@ -63829,10 +63611,11 @@
63611 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
63612 sqlite3DbFree(db, pSub);
63613 }
63614 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
63615 vdbeFreeOpArray(db, p->aOp, p->nOp);
63616 sqlite3DbFree(db, p->aLabel);
63617 sqlite3DbFree(db, p->aColName);
63618 sqlite3DbFree(db, p->zSql);
63619 sqlite3DbFree(db, p->pFree);
63620 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
63621 sqlite3DbFree(db, p->zExplain);
@@ -64059,19 +63842,25 @@
63842 /*
63843 ** Write the serialized data blob for the value stored in pMem into
63844 ** buf. It is assumed that the caller has allocated sufficient space.
63845 ** Return the number of bytes written.
63846 **
63847 ** nBuf is the amount of space left in buf[]. nBuf must always be
63848 ** large enough to hold the entire field. Except, if the field is
63849 ** a blob with a zero-filled tail, then buf[] might be just the right
63850 ** size to hold everything except for the zero-filled tail. If buf[]
63851 ** is only big enough to hold the non-zero prefix, then only write that
63852 ** prefix into buf[]. But if buf[] is large enough to hold both the
63853 ** prefix and the tail then write the prefix and set the tail to all
63854 ** zeros.
63855 **
63856 ** Return the number of bytes actually written into buf[]. The number
63857 ** of bytes in the zero-filled tail is included in the return value only
63858 ** if those bytes were zeroed in buf[].
63859 */
63860 SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){
63861 u32 serial_type = sqlite3VdbeSerialType(pMem, file_format);
63862 u32 len;
63863
63864 /* Integer and Real */
63865 if( serial_type<=7 && serial_type>0 ){
63866 u64 v;
@@ -64082,10 +63871,11 @@
63871 swapMixedEndianFloat(v);
63872 }else{
63873 v = pMem->u.i;
63874 }
63875 len = i = sqlite3VdbeSerialTypeLen(serial_type);
63876 assert( len<=(u32)nBuf );
63877 while( i-- ){
63878 buf[i] = (u8)(v&0xFF);
63879 v >>= 8;
63880 }
63881 return len;
@@ -64093,12 +63883,21 @@
63883
63884 /* String or blob */
63885 if( serial_type>=12 ){
63886 assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0)
63887 == (int)sqlite3VdbeSerialTypeLen(serial_type) );
63888 assert( pMem->n<=nBuf );
63889 len = pMem->n;
63890 memcpy(buf, pMem->z, len);
63891 if( pMem->flags & MEM_Zero ){
63892 len += pMem->u.nZero;
63893 assert( nBuf>=0 );
63894 if( len > (u32)nBuf ){
63895 len = (u32)nBuf;
63896 }
63897 memset(&buf[pMem->n], 0, len-pMem->n);
63898 }
63899 return len;
63900 }
63901
63902 /* NULL or constants 0 or 1 */
63903 return 0;
@@ -65095,21 +64894,20 @@
64894 && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
64895 sqlite3_reset(pStmt);
64896 v->doingRerun = 1;
64897 assert( v->expired==0 );
64898 }
64899 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
64900 /* This case occurs after failing to recompile an sql statement.
64901 ** The error message from the SQL compiler has already been loaded
64902 ** into the database handle. This block copies the error message
64903 ** from the database handle into the statement and sets the statement
64904 ** program counter to 0 to ensure that when the statement is
64905 ** finalized or reset the parser error message is available via
64906 ** sqlite3_errmsg() and sqlite3_errcode().
64907 */
64908 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
 
64909 sqlite3DbFree(db, v->zErrMsg);
64910 if( !db->mallocFailed ){
64911 v->zErrMsg = sqlite3DbStrDup(db, zErr);
64912 v->rc = rc2;
64913 } else {
@@ -66021,11 +65819,10 @@
65819 if( db->nVdbeExec>1 ){
65820 while( *zRawSql ){
65821 const char *zStart = zRawSql;
65822 while( *(zRawSql++)!='\n' && *zRawSql );
65823 sqlite3StrAccumAppend(&out, "-- ", 3);
 
65824 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
65825 }
65826 }else{
65827 while( zRawSql[0] ){
65828 n = findNextHostParameter(zRawSql, &nToken);
@@ -66054,13 +65851,13 @@
65851 assert( idx>0 && idx<=p->nVar );
65852 pVar = &p->aVar[idx-1];
65853 if( pVar->flags & MEM_Null ){
65854 sqlite3StrAccumAppend(&out, "NULL", 4);
65855 }else if( pVar->flags & MEM_Int ){
65856 sqlite3XPrintf(&out, "%lld", pVar->u.i);
65857 }else if( pVar->flags & MEM_Real ){
65858 sqlite3XPrintf(&out, "%!.15g", pVar->r);
65859 }else if( pVar->flags & MEM_Str ){
65860 int nOut; /* Number of bytes of the string text to include in output */
65861 #ifndef SQLITE_OMIT_UTF16
65862 u8 enc = ENC(db);
65863 Mem utf8;
@@ -66077,37 +65874,33 @@
65874 if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
65875 nOut = SQLITE_TRACE_SIZE_LIMIT;
65876 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
65877 }
65878 #endif
65879 sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z);
65880 #ifdef SQLITE_TRACE_SIZE_LIMIT
65881 if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
 
 
65882 #endif
65883 #ifndef SQLITE_OMIT_UTF16
65884 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
65885 #endif
65886 }else if( pVar->flags & MEM_Zero ){
65887 sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
65888 }else{
65889 int nOut; /* Number of bytes of the blob to include in output */
65890 assert( pVar->flags & MEM_Blob );
65891 sqlite3StrAccumAppend(&out, "x'", 2);
65892 nOut = pVar->n;
65893 #ifdef SQLITE_TRACE_SIZE_LIMIT
65894 if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
65895 #endif
65896 for(i=0; i<nOut; i++){
65897 sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
65898 }
65899 sqlite3StrAccumAppend(&out, "'", 1);
65900 #ifdef SQLITE_TRACE_SIZE_LIMIT
65901 if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
 
 
65902 #endif
65903 }
65904 }
65905 }
65906 return sqlite3StrAccumFinish(&out);
@@ -66162,11 +65955,11 @@
65955 int n = p->nIndent;
65956 if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
65957 sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
65958 }
65959 va_start(ap, zFormat);
65960 sqlite3VXPrintf(&p->str, 1, zFormat, ap);
65961 va_end(ap);
65962 }
65963 }
65964
65965 /*
@@ -66869,11 +66662,433 @@
66662 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66663 #ifdef VDBE_PROFILE
66664 u64 start; /* CPU clock count at start of opcode */
66665 int origPc; /* Program counter at start of opcode */
66666 #endif
66667 /********************************************************************
66668 ** Automatically generated code
66669 **
66670 ** The following union is automatically generated by the
66671 ** vdbe-compress.tcl script. The purpose of this union is to
66672 ** reduce the amount of stack space required by this function.
66673 ** See comments in the vdbe-compress.tcl script for details.
66674 */
66675 union vdbeExecUnion {
66676 struct OP_Yield_stack_vars {
66677 int pcDest;
66678 } aa;
66679 struct OP_Halt_stack_vars {
66680 const char *zType;
66681 const char *zLogFmt;
66682 } ab;
66683 struct OP_Null_stack_vars {
66684 int cnt;
66685 u16 nullFlag;
66686 } ac;
66687 struct OP_Variable_stack_vars {
66688 Mem *pVar; /* Value being transferred */
66689 } ad;
66690 struct OP_Move_stack_vars {
66691 char *zMalloc; /* Holding variable for allocated memory */
66692 int n; /* Number of registers left to copy */
66693 int p1; /* Register to copy from */
66694 int p2; /* Register to copy to */
66695 } ae;
66696 struct OP_Copy_stack_vars {
66697 int n;
66698 } af;
66699 struct OP_ResultRow_stack_vars {
66700 Mem *pMem;
66701 int i;
66702 } ag;
66703 struct OP_Concat_stack_vars {
66704 i64 nByte;
66705 } ah;
66706 struct OP_Remainder_stack_vars {
66707 char bIntint; /* Started out as two integer operands */
66708 int flags; /* Combined MEM_* flags from both inputs */
66709 i64 iA; /* Integer value of left operand */
66710 i64 iB; /* Integer value of right operand */
66711 double rA; /* Real value of left operand */
66712 double rB; /* Real value of right operand */
66713 } ai;
66714 struct OP_Function_stack_vars {
66715 int i;
66716 Mem *pArg;
66717 sqlite3_context ctx;
66718 sqlite3_value **apVal;
66719 int n;
66720 } aj;
66721 struct OP_ShiftRight_stack_vars {
66722 i64 iA;
66723 u64 uA;
66724 i64 iB;
66725 u8 op;
66726 } ak;
66727 struct OP_Ge_stack_vars {
66728 int res; /* Result of the comparison of pIn1 against pIn3 */
66729 char affinity; /* Affinity to use for comparison */
66730 u16 flags1; /* Copy of initial value of pIn1->flags */
66731 u16 flags3; /* Copy of initial value of pIn3->flags */
66732 } al;
66733 struct OP_Compare_stack_vars {
66734 int n;
66735 int i;
66736 int p1;
66737 int p2;
66738 const KeyInfo *pKeyInfo;
66739 int idx;
66740 CollSeq *pColl; /* Collating sequence to use on this term */
66741 int bRev; /* True for DESCENDING sort order */
66742 } am;
66743 struct OP_Or_stack_vars {
66744 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66745 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
66746 } an;
66747 struct OP_IfNot_stack_vars {
66748 int c;
66749 } ao;
66750 struct OP_Column_stack_vars {
66751 i64 payloadSize64; /* Number of bytes in the record */
66752 int p2; /* column number to retrieve */
66753 VdbeCursor *pC; /* The VDBE cursor */
66754 BtCursor *pCrsr; /* The BTree cursor */
66755 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
66756 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
66757 int len; /* The length of the serialized data for the column */
66758 int i; /* Loop counter */
66759 Mem *pDest; /* Where to write the extracted value */
66760 Mem sMem; /* For storing the record being decoded */
66761 const u8 *zData; /* Part of the record being decoded */
66762 const u8 *zHdr; /* Next unparsed byte of the header */
66763 const u8 *zEndHdr; /* Pointer to first byte after the header */
66764 u32 offset; /* Offset into the data */
66765 u32 szField; /* Number of bytes in the content of a field */
66766 u32 avail; /* Number of bytes of available data */
66767 u32 t; /* A type code from the record header */
66768 Mem *pReg; /* PseudoTable input register */
66769 } ap;
66770 struct OP_Affinity_stack_vars {
66771 const char *zAffinity; /* The affinity to be applied */
66772 char cAff; /* A single character of affinity */
66773 } aq;
66774 struct OP_MakeRecord_stack_vars {
66775 u8 *zNewRecord; /* A buffer to hold the data for the new record */
66776 Mem *pRec; /* The new record */
66777 u64 nData; /* Number of bytes of data space */
66778 int nHdr; /* Number of bytes of header space */
66779 i64 nByte; /* Data space required for this record */
66780 int nZero; /* Number of zero bytes at the end of the record */
66781 int nVarint; /* Number of bytes in a varint */
66782 u32 serial_type; /* Type field */
66783 Mem *pData0; /* First field to be combined into the record */
66784 Mem *pLast; /* Last field of the record */
66785 int nField; /* Number of fields in the record */
66786 char *zAffinity; /* The affinity string for the record */
66787 int file_format; /* File format to use for encoding */
66788 int i; /* Space used in zNewRecord[] */
66789 int len; /* Length of a field */
66790 } ar;
66791 struct OP_Count_stack_vars {
66792 i64 nEntry;
66793 BtCursor *pCrsr;
66794 } as;
66795 struct OP_Savepoint_stack_vars {
66796 int p1; /* Value of P1 operand */
66797 char *zName; /* Name of savepoint */
66798 int nName;
66799 Savepoint *pNew;
66800 Savepoint *pSavepoint;
66801 Savepoint *pTmp;
66802 int iSavepoint;
66803 int ii;
66804 } at;
66805 struct OP_AutoCommit_stack_vars {
66806 int desiredAutoCommit;
66807 int iRollback;
66808 int turnOnAC;
66809 } au;
66810 struct OP_Transaction_stack_vars {
66811 Btree *pBt;
66812 } av;
66813 struct OP_ReadCookie_stack_vars {
66814 int iMeta;
66815 int iDb;
66816 int iCookie;
66817 } aw;
66818 struct OP_SetCookie_stack_vars {
66819 Db *pDb;
66820 } ax;
66821 struct OP_VerifyCookie_stack_vars {
66822 int iMeta;
66823 int iGen;
66824 Btree *pBt;
66825 } ay;
66826 struct OP_OpenWrite_stack_vars {
66827 int nField;
66828 KeyInfo *pKeyInfo;
66829 int p2;
66830 int iDb;
66831 int wrFlag;
66832 Btree *pX;
66833 VdbeCursor *pCur;
66834 Db *pDb;
66835 } az;
66836 struct OP_OpenEphemeral_stack_vars {
66837 VdbeCursor *pCx;
66838 KeyInfo *pKeyInfo;
66839 } ba;
66840 struct OP_SorterOpen_stack_vars {
66841 VdbeCursor *pCx;
66842 } bb;
66843 struct OP_OpenPseudo_stack_vars {
66844 VdbeCursor *pCx;
66845 } bc;
66846 struct OP_SeekGt_stack_vars {
66847 int res;
66848 int oc;
66849 VdbeCursor *pC;
66850 UnpackedRecord r;
66851 int nField;
66852 i64 iKey; /* The rowid we are to seek to */
66853 } bd;
66854 struct OP_Seek_stack_vars {
66855 VdbeCursor *pC;
66856 } be;
66857 struct OP_Found_stack_vars {
66858 int alreadyExists;
66859 int ii;
66860 VdbeCursor *pC;
66861 int res;
66862 char *pFree;
66863 UnpackedRecord *pIdxKey;
66864 UnpackedRecord r;
66865 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
66866 } bf;
66867 struct OP_NotExists_stack_vars {
66868 VdbeCursor *pC;
66869 BtCursor *pCrsr;
66870 int res;
66871 u64 iKey;
66872 } bg;
66873 struct OP_NewRowid_stack_vars {
66874 i64 v; /* The new rowid */
66875 VdbeCursor *pC; /* Cursor of table to get the new rowid */
66876 int res; /* Result of an sqlite3BtreeLast() */
66877 int cnt; /* Counter to limit the number of searches */
66878 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
66879 VdbeFrame *pFrame; /* Root frame of VDBE */
66880 } bh;
66881 struct OP_InsertInt_stack_vars {
66882 Mem *pData; /* MEM cell holding data for the record to be inserted */
66883 Mem *pKey; /* MEM cell holding key for the record */
66884 i64 iKey; /* The integer ROWID or key for the record to be inserted */
66885 VdbeCursor *pC; /* Cursor to table into which insert is written */
66886 int nZero; /* Number of zero-bytes to append */
66887 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
66888 const char *zDb; /* database name - used by the update hook */
66889 const char *zTbl; /* Table name - used by the opdate hook */
66890 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
66891 } bi;
66892 struct OP_Delete_stack_vars {
66893 i64 iKey;
66894 VdbeCursor *pC;
66895 } bj;
66896 struct OP_SorterCompare_stack_vars {
66897 VdbeCursor *pC;
66898 int res;
66899 int nIgnore;
66900 } bk;
66901 struct OP_SorterData_stack_vars {
66902 VdbeCursor *pC;
66903 } bl;
66904 struct OP_RowData_stack_vars {
66905 VdbeCursor *pC;
66906 BtCursor *pCrsr;
66907 u32 n;
66908 i64 n64;
66909 } bm;
66910 struct OP_Rowid_stack_vars {
66911 VdbeCursor *pC;
66912 i64 v;
66913 sqlite3_vtab *pVtab;
66914 const sqlite3_module *pModule;
66915 } bn;
66916 struct OP_NullRow_stack_vars {
66917 VdbeCursor *pC;
66918 } bo;
66919 struct OP_Last_stack_vars {
66920 VdbeCursor *pC;
66921 BtCursor *pCrsr;
66922 int res;
66923 } bp;
66924 struct OP_Rewind_stack_vars {
66925 VdbeCursor *pC;
66926 BtCursor *pCrsr;
66927 int res;
66928 } bq;
66929 struct OP_SorterNext_stack_vars {
66930 VdbeCursor *pC;
66931 int res;
66932 } br;
66933 struct OP_IdxInsert_stack_vars {
66934 VdbeCursor *pC;
66935 BtCursor *pCrsr;
66936 int nKey;
66937 const char *zKey;
66938 } bs;
66939 struct OP_IdxDelete_stack_vars {
66940 VdbeCursor *pC;
66941 BtCursor *pCrsr;
66942 int res;
66943 UnpackedRecord r;
66944 } bt;
66945 struct OP_IdxRowid_stack_vars {
66946 BtCursor *pCrsr;
66947 VdbeCursor *pC;
66948 i64 rowid;
66949 } bu;
66950 struct OP_IdxGE_stack_vars {
66951 VdbeCursor *pC;
66952 int res;
66953 UnpackedRecord r;
66954 } bv;
66955 struct OP_Destroy_stack_vars {
66956 int iMoved;
66957 int iCnt;
66958 Vdbe *pVdbe;
66959 int iDb;
66960 } bw;
66961 struct OP_Clear_stack_vars {
66962 int nChange;
66963 } bx;
66964 struct OP_CreateTable_stack_vars {
66965 int pgno;
66966 int flags;
66967 Db *pDb;
66968 } by;
66969 struct OP_ParseSchema_stack_vars {
66970 int iDb;
66971 const char *zMaster;
66972 char *zSql;
66973 InitData initData;
66974 } bz;
66975 struct OP_IntegrityCk_stack_vars {
66976 int nRoot; /* Number of tables to check. (Number of root pages.) */
66977 int *aRoot; /* Array of rootpage numbers for tables to be checked */
66978 int j; /* Loop counter */
66979 int nErr; /* Number of errors reported */
66980 char *z; /* Text of the error report */
66981 Mem *pnErr; /* Register keeping track of errors remaining */
66982 } ca;
66983 struct OP_RowSetRead_stack_vars {
66984 i64 val;
66985 } cb;
66986 struct OP_RowSetTest_stack_vars {
66987 int iSet;
66988 int exists;
66989 } cc;
66990 struct OP_Program_stack_vars {
66991 int nMem; /* Number of memory registers for sub-program */
66992 int nByte; /* Bytes of runtime space required for sub-program */
66993 Mem *pRt; /* Register to allocate runtime space */
66994 Mem *pMem; /* Used to iterate through memory cells */
66995 Mem *pEnd; /* Last memory cell in new array */
66996 VdbeFrame *pFrame; /* New vdbe frame to execute in */
66997 SubProgram *pProgram; /* Sub-program to execute */
66998 void *t; /* Token identifying trigger */
66999 } cd;
67000 struct OP_Param_stack_vars {
67001 VdbeFrame *pFrame;
67002 Mem *pIn;
67003 } ce;
67004 struct OP_MemMax_stack_vars {
67005 Mem *pIn1;
67006 VdbeFrame *pFrame;
67007 } cf;
67008 struct OP_AggStep_stack_vars {
67009 int n;
67010 int i;
67011 Mem *pMem;
67012 Mem *pRec;
67013 sqlite3_context ctx;
67014 sqlite3_value **apVal;
67015 } cg;
67016 struct OP_AggFinal_stack_vars {
67017 Mem *pMem;
67018 } ch;
67019 struct OP_Checkpoint_stack_vars {
67020 int i; /* Loop counter */
67021 int aRes[3]; /* Results */
67022 Mem *pMem; /* Write results here */
67023 } ci;
67024 struct OP_JournalMode_stack_vars {
67025 Btree *pBt; /* Btree to change journal mode of */
67026 Pager *pPager; /* Pager associated with pBt */
67027 int eNew; /* New journal mode */
67028 int eOld; /* The old journal mode */
67029 #ifndef SQLITE_OMIT_WAL
67030 const char *zFilename; /* Name of database file for pPager */
67031 #endif
67032 } cj;
67033 struct OP_IncrVacuum_stack_vars {
67034 Btree *pBt;
67035 } ck;
67036 struct OP_VBegin_stack_vars {
67037 VTable *pVTab;
67038 } cl;
67039 struct OP_VOpen_stack_vars {
67040 VdbeCursor *pCur;
67041 sqlite3_vtab_cursor *pVtabCursor;
67042 sqlite3_vtab *pVtab;
67043 sqlite3_module *pModule;
67044 } cm;
67045 struct OP_VFilter_stack_vars {
67046 int nArg;
67047 int iQuery;
67048 const sqlite3_module *pModule;
67049 Mem *pQuery;
67050 Mem *pArgc;
67051 sqlite3_vtab_cursor *pVtabCursor;
67052 sqlite3_vtab *pVtab;
67053 VdbeCursor *pCur;
67054 int res;
67055 int i;
67056 Mem **apArg;
67057 } cn;
67058 struct OP_VColumn_stack_vars {
67059 sqlite3_vtab *pVtab;
67060 const sqlite3_module *pModule;
67061 Mem *pDest;
67062 sqlite3_context sContext;
67063 } co;
67064 struct OP_VNext_stack_vars {
67065 sqlite3_vtab *pVtab;
67066 const sqlite3_module *pModule;
67067 int res;
67068 VdbeCursor *pCur;
67069 } cp;
67070 struct OP_VRename_stack_vars {
67071 sqlite3_vtab *pVtab;
67072 Mem *pName;
67073 } cq;
67074 struct OP_VUpdate_stack_vars {
67075 sqlite3_vtab *pVtab;
67076 sqlite3_module *pModule;
67077 int nArg;
67078 int i;
67079 sqlite_int64 rowid;
67080 Mem **apArg;
67081 Mem *pX;
67082 } cr;
67083 struct OP_Trace_stack_vars {
67084 char *zTrace;
67085 char *z;
67086 } cs;
67087 } u;
67088 /* End automatically generated code
67089 ********************************************************************/
67090
67091 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
67092 sqlite3VdbeEnter(p);
67093 if( p->rc==SQLITE_NOMEM ){
67094 /* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -67115,18 +67330,20 @@
67330 /* Opcode: Yield P1 * * * *
67331 **
67332 ** Swap the program counter with the value in register P1.
67333 */
67334 case OP_Yield: { /* in1 */
67335 #if 0 /* local variables moved into u.aa */
67336 int pcDest;
67337 #endif /* local variables moved into u.aa */
67338 pIn1 = &aMem[pOp->p1];
67339 assert( (pIn1->flags & MEM_Dyn)==0 );
67340 pIn1->flags = MEM_Int;
67341 u.aa.pcDest = (int)pIn1->u.i;
67342 pIn1->u.i = pc;
67343 REGISTER_TRACE(pOp->p1, pIn1);
67344 pc = u.aa.pcDest;
67345 break;
67346 }
67347
67348 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67349 ** Synopsis: if r[P3] null then halt
@@ -67171,12 +67388,14 @@
67388 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
67389 ** every program. So a jump past the last instruction of the program
67390 ** is the same as executing Halt.
67391 */
67392 case OP_Halt: {
67393 #if 0 /* local variables moved into u.ab */
67394 const char *zType;
67395 const char *zLogFmt;
67396 #endif /* local variables moved into u.ab */
67397
67398 if( pOp->p1==SQLITE_OK && p->pFrame ){
67399 /* Halt the sub-program. Return control to the parent frame. */
67400 VdbeFrame *pFrame = p->pFrame;
67401 p->pFrame = pFrame->pParent;
@@ -67183,11 +67402,11 @@
67402 p->nFrame--;
67403 sqlite3VdbeSetChanges(db, p->nChange);
67404 pc = sqlite3VdbeFrameRestore(pFrame);
67405 lastRowid = db->lastRowid;
67406 if( pOp->p2==OE_Ignore ){
67407 /* Instruction pc is the OP_Program that invoked the sub-program
67408 ** currently being halted. If the p2 instruction of this OP_Halt
67409 ** instruction is set to OE_Ignore, then the sub-program is throwing
67410 ** an IGNORE exception. In this case jump to the address specified
67411 ** as the p2 of the calling OP_Program. */
67412 pc = p->aOp[pc].p2-1;
@@ -67206,25 +67425,25 @@
67425 assert( pOp->p5>=1 && pOp->p5<=4 );
67426 testcase( pOp->p5==1 );
67427 testcase( pOp->p5==2 );
67428 testcase( pOp->p5==3 );
67429 testcase( pOp->p5==4 );
67430 u.ab.zType = azType[pOp->p5-1];
67431 }else{
67432 u.ab.zType = 0;
67433 }
67434 assert( u.ab.zType!=0 || pOp->p4.z!=0 );
67435 u.ab.zLogFmt = "abort at %d in [%s]: %s";
67436 if( u.ab.zType && pOp->p4.z ){
67437 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s",
67438 u.ab.zType, pOp->p4.z);
67439 }else if( pOp->p4.z ){
67440 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z);
67441 }else{
67442 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType);
67443 }
67444 sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg);
67445 }
67446 rc = sqlite3VdbeHalt(p);
67447 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
67448 if( rc==SQLITE_BUSY ){
67449 p->rc = rc = SQLITE_BUSY;
@@ -67334,21 +67553,23 @@
67553 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that
67554 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on
67555 ** OP_Ne or OP_Eq.
67556 */
67557 case OP_Null: { /* out2-prerelease */
67558 #if 0 /* local variables moved into u.ac */
67559 int cnt;
67560 u16 nullFlag;
67561 #endif /* local variables moved into u.ac */
67562 u.ac.cnt = pOp->p3-pOp->p2;
67563 assert( pOp->p3<=(p->nMem-p->nCursor) );
67564 pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null;
67565 while( u.ac.cnt>0 ){
67566 pOut++;
67567 memAboutToChange(p, pOut);
67568 VdbeMemRelease(pOut);
67569 pOut->flags = u.ac.nullFlag;
67570 u.ac.cnt--;
67571 }
67572 break;
67573 }
67574
67575
@@ -67373,19 +67594,21 @@
67594 **
67595 ** If the parameter is named, then its name appears in P4 and P3==1.
67596 ** The P4 value is used by sqlite3_bind_parameter_name().
67597 */
67598 case OP_Variable: { /* out2-prerelease */
67599 #if 0 /* local variables moved into u.ad */
67600 Mem *pVar; /* Value being transferred */
67601 #endif /* local variables moved into u.ad */
67602
67603 assert( pOp->p1>0 && pOp->p1<=p->nVar );
67604 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
67605 u.ad.pVar = &p->aVar[pOp->p1 - 1];
67606 if( sqlite3VdbeMemTooBig(u.ad.pVar) ){
67607 goto too_big;
67608 }
67609 sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static);
67610 UPDATE_MAX_BLOBSIZE(pOut);
67611 break;
67612 }
67613
67614 /* Opcode: Move P1 P2 P3 * *
@@ -67395,67 +67618,71 @@
67618 ** registers P2..P2+P3. Registers P1..P1+P3 are
67619 ** left holding a NULL. It is an error for register ranges
67620 ** P1..P1+P3 and P2..P2+P3 to overlap.
67621 */
67622 case OP_Move: {
67623 #if 0 /* local variables moved into u.ae */
67624 char *zMalloc; /* Holding variable for allocated memory */
67625 int n; /* Number of registers left to copy */
67626 int p1; /* Register to copy from */
67627 int p2; /* Register to copy to */
67628 #endif /* local variables moved into u.ae */
67629
67630 u.ae.n = pOp->p3;
67631 u.ae.p1 = pOp->p1;
67632 u.ae.p2 = pOp->p2;
67633 assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 );
67634 assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67635
67636 pIn1 = &aMem[u.ae.p1];
67637 pOut = &aMem[u.ae.p2];
67638 do{
67639 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67640 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67641 assert( memIsValid(pIn1) );
67642 memAboutToChange(p, pOut);
67643 u.ae.zMalloc = pOut->zMalloc;
67644 pOut->zMalloc = 0;
67645 sqlite3VdbeMemMove(pOut, pIn1);
67646 #ifdef SQLITE_DEBUG
67647 if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){
67648 pOut->pScopyFrom += u.ae.p1 - pOp->p2;
67649 }
67650 #endif
67651 pIn1->zMalloc = u.ae.zMalloc;
67652 REGISTER_TRACE(u.ae.p2++, pOut);
67653 pIn1++;
67654 pOut++;
67655 }while( u.ae.n-- );
67656 break;
67657 }
67658
67659 /* Opcode: Copy P1 P2 P3 * *
67660 ** Synopsis: r[P2@P3]=r[P1@P3]
67661 **
67662 ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3.
67663 **
67664 ** This instruction makes a deep copy of the value. A duplicate
67665 ** is made of any string or blob constant. See also OP_SCopy.
67666 */
67667 case OP_Copy: {
67668 #if 0 /* local variables moved into u.af */
67669 int n;
67670 #endif /* local variables moved into u.af */
67671
67672 u.af.n = pOp->p3;
67673 pIn1 = &aMem[pOp->p1];
67674 pOut = &aMem[pOp->p2];
67675 assert( pOut!=pIn1 );
67676 while( 1 ){
67677 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem);
67678 Deephemeralize(pOut);
67679 #ifdef SQLITE_DEBUG
67680 pOut->pScopyFrom = 0;
67681 #endif
67682 REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut);
67683 if( (u.af.n--)==0 ) break;
67684 pOut++;
67685 pIn1++;
67686 }
67687 break;
67688 }
@@ -67492,12 +67719,14 @@
67719 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67720 ** structure to provide access to the top P1 values as the result
67721 ** row.
67722 */
67723 case OP_ResultRow: {
67724 #if 0 /* local variables moved into u.ag */
67725 Mem *pMem;
67726 int i;
67727 #endif /* local variables moved into u.ag */
67728 assert( p->nResColumn==pOp->p2 );
67729 assert( pOp->p1>0 );
67730 assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 );
67731
67732 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -67519,12 +67748,12 @@
67748 assert( db->flags&SQLITE_CountRows );
67749 assert( p->usesStmtJournal );
67750 break;
67751 }
67752
67753 /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then
67754 ** DML statements invoke this opcode to return the number of rows
67755 ** modified to the user. This is the only way that a VM that
67756 ** opens a statement transaction may invoke this opcode.
67757 **
67758 ** In case this is such a statement, close any statement transaction
67759 ** opened by this VM before returning control to the user. This is to
@@ -67547,19 +67776,19 @@
67776
67777 /* Make sure the results of the current row are \000 terminated
67778 ** and have an assigned type. The results are de-ephemeralized as
67779 ** a side effect.
67780 */
67781 u.ag.pMem = p->pResultSet = &aMem[pOp->p1];
67782 for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){
67783 assert( memIsValid(&u.ag.pMem[u.ag.i]) );
67784 Deephemeralize(&u.ag.pMem[u.ag.i]);
67785 assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0
67786 || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 );
67787 sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]);
67788 sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]);
67789 REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]);
67790 }
67791 if( db->mallocFailed ) goto no_mem;
67792
67793 /* Return SQLITE_ROW
67794 */
@@ -67580,11 +67809,13 @@
67809 ** It is illegal for P1 and P3 to be the same register. Sometimes,
67810 ** if P3 is the same register as P2, the implementation is able
67811 ** to avoid a memcpy().
67812 */
67813 case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
67814 #if 0 /* local variables moved into u.ah */
67815 i64 nByte;
67816 #endif /* local variables moved into u.ah */
67817
67818 pIn1 = &aMem[pOp->p1];
67819 pIn2 = &aMem[pOp->p2];
67820 pOut = &aMem[pOp->p3];
67821 assert( pIn1!=pOut );
@@ -67593,26 +67824,26 @@
67824 break;
67825 }
67826 if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem;
67827 Stringify(pIn1, encoding);
67828 Stringify(pIn2, encoding);
67829 u.ah.nByte = pIn1->n + pIn2->n;
67830 if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
67831 goto too_big;
67832 }
67833 MemSetTypeFlag(pOut, MEM_Str);
67834 if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){
67835 goto no_mem;
67836 }
67837 if( pOut!=pIn2 ){
67838 memcpy(pOut->z, pIn2->z, pIn2->n);
67839 }
67840 memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n);
67841 pOut->z[u.ah.nByte]=0;
67842 pOut->z[u.ah.nByte+1] = 0;
67843 pOut->flags |= MEM_Term;
67844 pOut->n = (int)u.ah.nByte;
67845 pOut->enc = encoding;
67846 UPDATE_MAX_BLOBSIZE(pOut);
67847 break;
67848 }
67849
@@ -67657,81 +67888,83 @@
67888 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
67889 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
67890 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
67891 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
67892 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
67893 #if 0 /* local variables moved into u.ai */
67894 char bIntint; /* Started out as two integer operands */
67895 int flags; /* Combined MEM_* flags from both inputs */
67896 i64 iA; /* Integer value of left operand */
67897 i64 iB; /* Integer value of right operand */
67898 double rA; /* Real value of left operand */
67899 double rB; /* Real value of right operand */
67900 #endif /* local variables moved into u.ai */
67901
67902 pIn1 = &aMem[pOp->p1];
67903 applyNumericAffinity(pIn1);
67904 pIn2 = &aMem[pOp->p2];
67905 applyNumericAffinity(pIn2);
67906 pOut = &aMem[pOp->p3];
67907 u.ai.flags = pIn1->flags | pIn2->flags;
67908 if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
67909 if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){
67910 u.ai.iA = pIn1->u.i;
67911 u.ai.iB = pIn2->u.i;
67912 u.ai.bIntint = 1;
67913 switch( pOp->opcode ){
67914 case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67915 case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67916 case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break;
67917 case OP_Divide: {
67918 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67919 if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math;
67920 u.ai.iB /= u.ai.iA;
67921 break;
67922 }
67923 default: {
67924 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67925 if( u.ai.iA==-1 ) u.ai.iA = 1;
67926 u.ai.iB %= u.ai.iA;
67927 break;
67928 }
67929 }
67930 pOut->u.i = u.ai.iB;
67931 MemSetTypeFlag(pOut, MEM_Int);
67932 }else{
67933 u.ai.bIntint = 0;
67934 fp_math:
67935 u.ai.rA = sqlite3VdbeRealValue(pIn1);
67936 u.ai.rB = sqlite3VdbeRealValue(pIn2);
67937 switch( pOp->opcode ){
67938 case OP_Add: u.ai.rB += u.ai.rA; break;
67939 case OP_Subtract: u.ai.rB -= u.ai.rA; break;
67940 case OP_Multiply: u.ai.rB *= u.ai.rA; break;
67941 case OP_Divide: {
67942 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
67943 if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null;
67944 u.ai.rB /= u.ai.rA;
67945 break;
67946 }
67947 default: {
67948 u.ai.iA = (i64)u.ai.rA;
67949 u.ai.iB = (i64)u.ai.rB;
67950 if( u.ai.iA==0 ) goto arithmetic_result_is_null;
67951 if( u.ai.iA==-1 ) u.ai.iA = 1;
67952 u.ai.rB = (double)(u.ai.iB % u.ai.iA);
67953 break;
67954 }
67955 }
67956 #ifdef SQLITE_OMIT_FLOATING_POINT
67957 pOut->u.i = u.ai.rB;
67958 MemSetTypeFlag(pOut, MEM_Int);
67959 #else
67960 if( sqlite3IsNaN(u.ai.rB) ){
67961 goto arithmetic_result_is_null;
67962 }
67963 pOut->r = u.ai.rB;
67964 MemSetTypeFlag(pOut, MEM_Real);
67965 if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){
67966 sqlite3VdbeIntegerAffinity(pOut);
67967 }
67968 #endif
67969 }
67970 break;
@@ -67780,83 +68013,85 @@
68013 ** invocation of this opcode.
68014 **
68015 ** See also: AggStep and AggFinal
68016 */
68017 case OP_Function: {
68018 #if 0 /* local variables moved into u.aj */
68019 int i;
68020 Mem *pArg;
68021 sqlite3_context ctx;
68022 sqlite3_value **apVal;
68023 int n;
68024 #endif /* local variables moved into u.aj */
68025
68026 u.aj.n = pOp->p5;
68027 u.aj.apVal = p->apArg;
68028 assert( u.aj.apVal || u.aj.n==0 );
68029 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68030 pOut = &aMem[pOp->p3];
68031 memAboutToChange(p, pOut);
68032
68033 assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) );
68034 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n );
68035 u.aj.pArg = &aMem[pOp->p2];
68036 for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){
68037 assert( memIsValid(u.aj.pArg) );
68038 u.aj.apVal[u.aj.i] = u.aj.pArg;
68039 Deephemeralize(u.aj.pArg);
68040 sqlite3VdbeMemStoreType(u.aj.pArg);
68041 REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
68042 }
68043
68044 assert( pOp->p4type==P4_FUNCDEF );
68045 u.aj.ctx.pFunc = pOp->p4.pFunc;
68046 u.aj.ctx.iOp = pc;
68047 u.aj.ctx.pVdbe = p;
68048
68049 /* The output cell may already have a buffer allocated. Move
68050 ** the pointer to u.aj.ctx.s so in case the user-function can use
68051 ** the already allocated buffer instead of allocating a new one.
68052 */
68053 memcpy(&u.aj.ctx.s, pOut, sizeof(Mem));
68054 pOut->flags = MEM_Null;
68055 pOut->xDel = 0;
68056 pOut->zMalloc = 0;
68057 MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
68058
68059 u.aj.ctx.fErrorOrAux = 0;
68060 if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
68061 assert( pOp>aOp );
68062 assert( pOp[-1].p4type==P4_COLLSEQ );
68063 assert( pOp[-1].opcode==OP_CollSeq );
68064 u.aj.ctx.pColl = pOp[-1].p4.pColl;
68065 }
68066 db->lastRowid = lastRowid;
68067 (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */
68068 lastRowid = db->lastRowid;
68069
68070 if( db->mallocFailed ){
68071 /* Even though a malloc() has failed, the implementation of the
68072 ** user function may have called an sqlite3_result_XXX() function
68073 ** to return a value. The following call releases any resources
68074 ** associated with such a value.
68075 */
68076 sqlite3VdbeMemRelease(&u.aj.ctx.s);
68077 goto no_mem;
68078 }
68079
68080 /* If the function returned an error, throw an exception */
68081 if( u.aj.ctx.fErrorOrAux ){
68082 if( u.aj.ctx.isError ){
68083 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s));
68084 rc = u.aj.ctx.isError;
68085 }
68086 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
68087 }
68088
68089 /* Copy the result of the function into register P3 */
68090 sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
68091 assert( pOut->flags==MEM_Null );
68092 memcpy(pOut, &u.aj.ctx.s, sizeof(Mem));
68093 if( sqlite3VdbeMemTooBig(pOut) ){
68094 goto too_big;
68095 }
68096
68097 #if 0
@@ -67904,54 +68139,56 @@
68139 */
68140 case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */
68141 case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */
68142 case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */
68143 case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */
68144 #if 0 /* local variables moved into u.ak */
68145 i64 iA;
68146 u64 uA;
68147 i64 iB;
68148 u8 op;
68149 #endif /* local variables moved into u.ak */
68150
68151 pIn1 = &aMem[pOp->p1];
68152 pIn2 = &aMem[pOp->p2];
68153 pOut = &aMem[pOp->p3];
68154 if( (pIn1->flags | pIn2->flags) & MEM_Null ){
68155 sqlite3VdbeMemSetNull(pOut);
68156 break;
68157 }
68158 u.ak.iA = sqlite3VdbeIntValue(pIn2);
68159 u.ak.iB = sqlite3VdbeIntValue(pIn1);
68160 u.ak.op = pOp->opcode;
68161 if( u.ak.op==OP_BitAnd ){
68162 u.ak.iA &= u.ak.iB;
68163 }else if( u.ak.op==OP_BitOr ){
68164 u.ak.iA |= u.ak.iB;
68165 }else if( u.ak.iB!=0 ){
68166 assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft );
68167
68168 /* If shifting by a negative amount, shift in the other direction */
68169 if( u.ak.iB<0 ){
68170 assert( OP_ShiftRight==OP_ShiftLeft+1 );
68171 u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op;
68172 u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64;
68173 }
68174
68175 if( u.ak.iB>=64 ){
68176 u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1;
68177 }else{
68178 memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA));
68179 if( u.ak.op==OP_ShiftLeft ){
68180 u.ak.uA <<= u.ak.iB;
68181 }else{
68182 u.ak.uA >>= u.ak.iB;
68183 /* Sign-extend on a right shift of a negative number */
68184 if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB);
68185 }
68186 memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA));
68187 }
68188 }
68189 pOut->u.i = u.ak.iA;
68190 MemSetTypeFlag(pOut, MEM_Int);
68191 break;
68192 }
68193
68194 /* Opcode: AddImm P1 P2 * * *
@@ -68201,35 +68438,37 @@
68438 case OP_Ne: /* same as TK_NE, jump, in1, in3 */
68439 case OP_Lt: /* same as TK_LT, jump, in1, in3 */
68440 case OP_Le: /* same as TK_LE, jump, in1, in3 */
68441 case OP_Gt: /* same as TK_GT, jump, in1, in3 */
68442 case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
68443 #if 0 /* local variables moved into u.al */
68444 int res; /* Result of the comparison of pIn1 against pIn3 */
68445 char affinity; /* Affinity to use for comparison */
68446 u16 flags1; /* Copy of initial value of pIn1->flags */
68447 u16 flags3; /* Copy of initial value of pIn3->flags */
68448 #endif /* local variables moved into u.al */
68449
68450 pIn1 = &aMem[pOp->p1];
68451 pIn3 = &aMem[pOp->p3];
68452 u.al.flags1 = pIn1->flags;
68453 u.al.flags3 = pIn3->flags;
68454 if( (u.al.flags1 | u.al.flags3)&MEM_Null ){
68455 /* One or both operands are NULL */
68456 if( pOp->p5 & SQLITE_NULLEQ ){
68457 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
68458 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68459 ** or not both operands are null.
68460 */
68461 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68462 assert( (u.al.flags1 & MEM_Cleared)==0 );
68463 if( (u.al.flags1&MEM_Null)!=0
68464 && (u.al.flags3&MEM_Null)!=0
68465 && (u.al.flags3&MEM_Cleared)==0
68466 ){
68467 u.al.res = 0; /* Results are equal */
68468 }else{
68469 u.al.res = 1; /* Results are not equal */
68470 }
68471 }else{
68472 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68473 ** then the result is always NULL.
68474 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -68243,44 +68482,44 @@
68482 }
68483 break;
68484 }
68485 }else{
68486 /* Neither operand is NULL. Do a comparison. */
68487 u.al.affinity = pOp->p5 & SQLITE_AFF_MASK;
68488 if( u.al.affinity ){
68489 applyAffinity(pIn1, u.al.affinity, encoding);
68490 applyAffinity(pIn3, u.al.affinity, encoding);
68491 if( db->mallocFailed ) goto no_mem;
68492 }
68493
68494 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
68495 ExpandBlob(pIn1);
68496 ExpandBlob(pIn3);
68497 u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
68498 }
68499 switch( pOp->opcode ){
68500 case OP_Eq: u.al.res = u.al.res==0; break;
68501 case OP_Ne: u.al.res = u.al.res!=0; break;
68502 case OP_Lt: u.al.res = u.al.res<0; break;
68503 case OP_Le: u.al.res = u.al.res<=0; break;
68504 case OP_Gt: u.al.res = u.al.res>0; break;
68505 default: u.al.res = u.al.res>=0; break;
68506 }
68507
68508 if( pOp->p5 & SQLITE_STOREP2 ){
68509 pOut = &aMem[pOp->p2];
68510 memAboutToChange(p, pOut);
68511 MemSetTypeFlag(pOut, MEM_Int);
68512 pOut->u.i = u.al.res;
68513 REGISTER_TRACE(pOp->p2, pOut);
68514 }else if( u.al.res ){
68515 pc = pOp->p2-1;
68516 }
68517
68518 /* Undo any changes made by applyAffinity() to the input registers. */
68519 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask);
68520 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask);
68521 break;
68522 }
68523
68524 /* Opcode: Permutation * * * P4 *
68525 **
@@ -68316,49 +68555,51 @@
68555 ** The comparison is a sort comparison, so NULLs compare equal,
68556 ** NULLs are less than numbers, numbers are less than strings,
68557 ** and strings are less than blobs.
68558 */
68559 case OP_Compare: {
68560 #if 0 /* local variables moved into u.am */
68561 int n;
68562 int i;
68563 int p1;
68564 int p2;
68565 const KeyInfo *pKeyInfo;
68566 int idx;
68567 CollSeq *pColl; /* Collating sequence to use on this term */
68568 int bRev; /* True for DESCENDING sort order */
68569 #endif /* local variables moved into u.am */
68570
68571 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
68572 u.am.n = pOp->p3;
68573 u.am.pKeyInfo = pOp->p4.pKeyInfo;
68574 assert( u.am.n>0 );
68575 assert( u.am.pKeyInfo!=0 );
68576 u.am.p1 = pOp->p1;
68577 u.am.p2 = pOp->p2;
68578 #if SQLITE_DEBUG
68579 if( aPermute ){
68580 int k, mx = 0;
68581 for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k];
68582 assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 );
68583 assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 );
68584 }else{
68585 assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 );
68586 assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 );
68587 }
68588 #endif /* SQLITE_DEBUG */
68589 for(u.am.i=0; u.am.i<u.am.n; u.am.i++){
68590 u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i;
68591 assert( memIsValid(&aMem[u.am.p1+u.am.idx]) );
68592 assert( memIsValid(&aMem[u.am.p2+u.am.idx]) );
68593 REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]);
68594 REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]);
68595 assert( u.am.i<u.am.pKeyInfo->nField );
68596 u.am.pColl = u.am.pKeyInfo->aColl[u.am.i];
68597 u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i];
68598 iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl);
68599 if( iCompare ){
68600 if( u.am.bRev ) iCompare = -iCompare;
68601 break;
68602 }
68603 }
68604 aPermute = 0;
68605 break;
@@ -68401,37 +68642,39 @@
68642 ** even if the other input is NULL. A NULL and false or two NULLs
68643 ** give a NULL output.
68644 */
68645 case OP_And: /* same as TK_AND, in1, in2, out3 */
68646 case OP_Or: { /* same as TK_OR, in1, in2, out3 */
68647 #if 0 /* local variables moved into u.an */
68648 int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68649 int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */
68650 #endif /* local variables moved into u.an */
68651
68652 pIn1 = &aMem[pOp->p1];
68653 if( pIn1->flags & MEM_Null ){
68654 u.an.v1 = 2;
68655 }else{
68656 u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0;
68657 }
68658 pIn2 = &aMem[pOp->p2];
68659 if( pIn2->flags & MEM_Null ){
68660 u.an.v2 = 2;
68661 }else{
68662 u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0;
68663 }
68664 if( pOp->opcode==OP_And ){
68665 static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 };
68666 u.an.v1 = and_logic[u.an.v1*3+u.an.v2];
68667 }else{
68668 static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 };
68669 u.an.v1 = or_logic[u.an.v1*3+u.an.v2];
68670 }
68671 pOut = &aMem[pOp->p3];
68672 if( u.an.v1==2 ){
68673 MemSetTypeFlag(pOut, MEM_Null);
68674 }else{
68675 pOut->u.i = u.an.v1;
68676 MemSetTypeFlag(pOut, MEM_Int);
68677 }
68678 break;
68679 }
68680
@@ -68498,23 +68741,25 @@
68741 ** is considered false if it has a numeric value of zero. If the value
68742 ** in P1 is NULL then take the jump if P3 is zero.
68743 */
68744 case OP_If: /* jump, in1 */
68745 case OP_IfNot: { /* jump, in1 */
68746 #if 0 /* local variables moved into u.ao */
68747 int c;
68748 #endif /* local variables moved into u.ao */
68749 pIn1 = &aMem[pOp->p1];
68750 if( pIn1->flags & MEM_Null ){
68751 u.ao.c = pOp->p3;
68752 }else{
68753 #ifdef SQLITE_OMIT_FLOATING_POINT
68754 u.ao.c = sqlite3VdbeIntValue(pIn1)!=0;
68755 #else
68756 u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0;
68757 #endif
68758 if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c;
68759 }
68760 if( u.ao.c ){
68761 pc = pOp->p2-1;
68762 }
68763 break;
68764 }
68765
@@ -68568,10 +68813,11 @@
68813 ** the result is guaranteed to only be used as the argument of a length()
68814 ** or typeof() function, respectively. The loading of large blobs can be
68815 ** skipped for length() and all content loading can be skipped for typeof().
68816 */
68817 case OP_Column: {
68818 #if 0 /* local variables moved into u.ap */
68819 i64 payloadSize64; /* Number of bytes in the record */
68820 int p2; /* column number to retrieve */
68821 VdbeCursor *pC; /* The VDBE cursor */
68822 BtCursor *pCrsr; /* The BTree cursor */
68823 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
@@ -68586,88 +68832,89 @@
68832 u32 offset; /* Offset into the data */
68833 u32 szField; /* Number of bytes in the content of a field */
68834 u32 avail; /* Number of bytes of available data */
68835 u32 t; /* A type code from the record header */
68836 Mem *pReg; /* PseudoTable input register */
68837 #endif /* local variables moved into u.ap */
68838
68839 u.ap.p2 = pOp->p2;
68840 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68841 u.ap.pDest = &aMem[pOp->p3];
68842 memAboutToChange(p, u.ap.pDest);
68843 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68844 u.ap.pC = p->apCsr[pOp->p1];
68845 assert( u.ap.pC!=0 );
68846 assert( u.ap.p2<u.ap.pC->nField );
68847 u.ap.aType = u.ap.pC->aType;
68848 u.ap.aOffset = u.ap.aType + u.ap.pC->nField;
68849 #ifndef SQLITE_OMIT_VIRTUALTABLE
68850 assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
68851 #endif
68852 u.ap.pCrsr = u.ap.pC->pCursor;
68853 assert( u.ap.pCrsr!=0 || u.ap.pC->pseudoTableReg>0 ); /* u.ap.pCrsr NULL on PseudoTables */
68854 assert( u.ap.pCrsr!=0 || u.ap.pC->nullRow ); /* u.ap.pC->nullRow on PseudoTables */
68855
68856 /* If the cursor cache is stale, bring it up-to-date */
68857 rc = sqlite3VdbeCursorMoveto(u.ap.pC);
68858 if( rc ) goto abort_due_to_error;
68859 if( u.ap.pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68860 if( u.ap.pC->nullRow ){
68861 if( u.ap.pCrsr==0 ){
68862 assert( u.ap.pC->pseudoTableReg>0 );
68863 u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg];
68864 if( u.ap.pC->multiPseudo ){
68865 sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem);
68866 Deephemeralize(u.ap.pDest);
68867 goto op_column_out;
68868 }
68869 assert( u.ap.pReg->flags & MEM_Blob );
68870 assert( memIsValid(u.ap.pReg) );
68871 u.ap.pC->payloadSize = u.ap.pC->szRow = u.ap.avail = u.ap.pReg->n;
68872 u.ap.pC->aRow = (u8*)u.ap.pReg->z;
68873 }else{
68874 MemSetTypeFlag(u.ap.pDest, MEM_Null);
68875 goto op_column_out;
68876 }
68877 }else{
68878 assert( u.ap.pCrsr );
68879 if( u.ap.pC->isTable==0 ){
68880 assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68881 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64);
68882 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
68883 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the
68884 ** payload size, so it is impossible for u.ap.payloadSize64 to be
68885 ** larger than 32 bits. */
68886 assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 );
68887 u.ap.pC->aRow = sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail);
68888 u.ap.pC->payloadSize = (u32)u.ap.payloadSize64;
68889 }else{
68890 assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) );
68891 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.pC->payloadSize);
68892 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
68893 u.ap.pC->aRow = sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail);
68894 }
68895 assert( u.ap.avail<=65536 ); /* Maximum page size is 64KiB */
68896 if( u.ap.pC->payloadSize <= (u32)u.ap.avail ){
68897 u.ap.pC->szRow = u.ap.pC->payloadSize;
68898 }else{
68899 u.ap.pC->szRow = u.ap.avail;
68900 }
68901 if( u.ap.pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
68902 goto too_big;
68903 }
68904 }
68905 u.ap.pC->cacheStatus = p->cacheCtr;
68906 u.ap.pC->iHdrOffset = getVarint32(u.ap.pC->aRow, u.ap.offset);
68907 u.ap.pC->nHdrParsed = 0;
68908 u.ap.aOffset[0] = u.ap.offset;
68909 if( u.ap.avail<u.ap.offset ){
68910 /* u.ap.pC->aRow does not have to hold the entire row, but it does at least
68911 ** need to cover the header of the record. If u.ap.pC->aRow does not contain
68912 ** the complete header, then set it to zero, forcing the header to be
68913 ** dynamically allocated. */
68914 u.ap.pC->aRow = 0;
68915 u.ap.pC->szRow = 0;
68916 }
68917
68918 /* Make sure a corrupt database has not given us an oversize header.
68919 ** Do this now to avoid an oversize memory allocation.
68920 **
@@ -68675,154 +68922,154 @@
68922 ** types use so much data space that there can only be 4096 and 32 of
68923 ** them, respectively. So the maximum header length results from a
68924 ** 3-byte type for each of the maximum of 32768 columns plus three
68925 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68926 */
68927 if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){
68928 rc = SQLITE_CORRUPT_BKPT;
68929 goto op_column_error;
68930 }
68931 }
68932
68933 /* Make sure at least the first u.ap.p2+1 entries of the header have been
68934 ** parsed and valid information is in u.ap.aOffset[] and u.ap.aType[].
68935 */
68936 if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
68937 /* If there is more header available for parsing in the record, try
68938 ** to extract additional fields up through the u.ap.p2+1-th field
68939 */
68940 if( u.ap.pC->iHdrOffset<u.ap.aOffset[0] ){
68941 /* Make sure u.ap.zData points to enough of the record to cover the header. */
68942 if( u.ap.pC->aRow==0 ){
68943 memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
68944 rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.aOffset[0],
68945 !u.ap.pC->isTable, &u.ap.sMem);
68946 if( rc!=SQLITE_OK ){
68947 goto op_column_error;
68948 }
68949 u.ap.zData = (u8*)u.ap.sMem.z;
68950 }else{
68951 u.ap.zData = u.ap.pC->aRow;
68952 }
68953
68954 /* Fill in u.ap.aType[u.ap.i] and u.ap.aOffset[u.ap.i] values through the u.ap.p2-th field. */
68955 u.ap.i = u.ap.pC->nHdrParsed;
68956 u.ap.offset = u.ap.aOffset[u.ap.i];
68957 u.ap.zHdr = u.ap.zData + u.ap.pC->iHdrOffset;
68958 u.ap.zEndHdr = u.ap.zData + u.ap.aOffset[0];
68959 assert( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr );
68960 do{
68961 if( u.ap.zHdr[0]<0x80 ){
68962 u.ap.t = u.ap.zHdr[0];
68963 u.ap.zHdr++;
68964 }else{
68965 u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t);
68966 }
68967 u.ap.aType[u.ap.i] = u.ap.t;
68968 u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68969 u.ap.offset += u.ap.szField;
68970 if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */
68971 u.ap.zHdr = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */
68972 break;
68973 }
68974 u.ap.i++;
68975 u.ap.aOffset[u.ap.i] = u.ap.offset;
68976 }while( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr );
68977 u.ap.pC->nHdrParsed = u.ap.i;
68978 u.ap.pC->iHdrOffset = (u32)(u.ap.zHdr - u.ap.zData);
68979 if( u.ap.pC->aRow==0 ){
68980 sqlite3VdbeMemRelease(&u.ap.sMem);
68981 u.ap.sMem.flags = MEM_Null;
68982 }
68983
68984 /* If we have read more header data than was contained in the header,
68985 ** or if the end of the last field appears to be past the end of the
68986 ** record, or if the end of the last field appears to be before the end
68987 ** of the record (when all fields present), then we must be dealing
68988 ** with a corrupt database.
68989 */
68990 if( (u.ap.zHdr > u.ap.zEndHdr)
68991 || (u.ap.offset > u.ap.pC->payloadSize)
68992 || (u.ap.zHdr==u.ap.zEndHdr && u.ap.offset!=u.ap.pC->payloadSize)
68993 ){
68994 rc = SQLITE_CORRUPT_BKPT;
68995 goto op_column_error;
68996 }
68997 }
68998
68999 /* If after trying to extra new entries from the header, nHdrParsed is
69000 ** still not up to u.ap.p2, that means that the record has fewer than u.ap.p2
69001 ** columns. So the result will be either the default value or a NULL.
69002 */
69003 if( u.ap.pC->nHdrParsed<=u.ap.p2 ){
69004 if( pOp->p4type==P4_MEM ){
69005 sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static);
69006 }else{
69007 MemSetTypeFlag(u.ap.pDest, MEM_Null);
69008 }
69009 goto op_column_out;
69010 }
69011 }
69012
69013 /* Extract the content for the u.ap.p2+1-th column. Control can only
69014 ** reach this point if u.ap.aOffset[u.ap.p2], u.ap.aOffset[u.ap.p2+1], and u.ap.aType[u.ap.p2] are
69015 ** all valid.
69016 */
69017 assert( u.ap.p2<u.ap.pC->nHdrParsed );
69018 assert( rc==SQLITE_OK );
69019 if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){
69020 /* This is the common case where the desired content fits on the original
69021 ** page - where the content is not on an overflow page */
69022 VdbeMemRelease(u.ap.pDest);
69023 sqlite3VdbeSerialGet(u.ap.pC->aRow+u.ap.aOffset[u.ap.p2], u.ap.aType[u.ap.p2], u.ap.pDest);
69024 }else{
69025 /* This branch happens only when content is on overflow pages */
69026 u.ap.t = u.ap.aType[u.ap.p2];
69027 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
69028 && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
69029 || (u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t))==0
69030 ){
69031 /* Content is irrelevant for the typeof() function and for
69032 ** the length(X) function if X is a blob. So we might as well use
69033 ** bogus content rather than reading content from disk. NULL works
69034 ** for text and blob and whatever is in the u.ap.payloadSize64 variable
69035 ** will work for everything else. Content is also irrelevant if
69036 ** the content length is 0. */
69037 u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0;
69038 u.ap.sMem.zMalloc = 0;
69039 }else{
69040 memset(&u.ap.sMem, 0, sizeof(u.ap.sMem));
69041 sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest);
69042 rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, !u.ap.pC->isTable,
69043 &u.ap.sMem);
69044 if( rc!=SQLITE_OK ){
69045 goto op_column_error;
69046 }
69047 u.ap.zData = (u8*)u.ap.sMem.z;
69048 }
69049 sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest);
69050 /* If we dynamically allocated space to hold the data (in the
69051 ** sqlite3VdbeMemFromBtree() call above) then transfer control of that
69052 ** dynamically allocated space over to the u.ap.pDest structure.
69053 ** This prevents a memory copy. */
69054 if( u.ap.sMem.zMalloc ){
69055 assert( u.ap.sMem.z==u.ap.sMem.zMalloc );
69056 assert( !(u.ap.pDest->flags & MEM_Dyn) );
69057 assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z );
69058 u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static);
69059 u.ap.pDest->flags |= MEM_Term;
69060 u.ap.pDest->z = u.ap.sMem.z;
69061 u.ap.pDest->zMalloc = u.ap.sMem.zMalloc;
69062 }
69063 }
69064 u.ap.pDest->enc = encoding;
69065
69066 op_column_out:
69067 rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest);
69068 op_column_error:
69069 UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69070 REGISTER_TRACE(pOp->p3, u.ap.pDest);
69071 break;
69072 }
69073
69074 /* Opcode: Affinity P1 P2 * P4 *
69075 ** Synopsis: affinity(r[P1@P2])
@@ -68832,22 +69079,24 @@
69079 ** P4 is a string that is P2 characters long. The nth character of the
69080 ** string indicates the column affinity that should be used for the nth
69081 ** memory cell in the range.
69082 */
69083 case OP_Affinity: {
69084 #if 0 /* local variables moved into u.aq */
69085 const char *zAffinity; /* The affinity to be applied */
69086 char cAff; /* A single character of affinity */
69087 #endif /* local variables moved into u.aq */
69088
69089 u.aq.zAffinity = pOp->p4.z;
69090 assert( u.aq.zAffinity!=0 );
69091 assert( u.aq.zAffinity[pOp->p2]==0 );
69092 pIn1 = &aMem[pOp->p1];
69093 while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){
69094 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
69095 assert( memIsValid(pIn1) );
69096 ExpandBlob(pIn1);
69097 applyAffinity(pIn1, u.aq.cAff, encoding);
69098 pIn1++;
69099 }
69100 break;
69101 }
69102
@@ -68866,10 +69115,11 @@
69115 ** macros defined in sqliteInt.h.
69116 **
69117 ** If P4 is NULL then all index fields have the affinity NONE.
69118 */
69119 case OP_MakeRecord: {
69120 #if 0 /* local variables moved into u.ar */
69121 u8 *zNewRecord; /* A buffer to hold the data for the new record */
69122 Mem *pRec; /* The new record */
69123 u64 nData; /* Number of bytes of data space */
69124 int nHdr; /* Number of bytes of header space */
69125 i64 nByte; /* Data space required for this record */
@@ -68879,123 +69129,106 @@
69129 Mem *pData0; /* First field to be combined into the record */
69130 Mem *pLast; /* Last field of the record */
69131 int nField; /* Number of fields in the record */
69132 char *zAffinity; /* The affinity string for the record */
69133 int file_format; /* File format to use for encoding */
69134 int i; /* Space used in zNewRecord[] */
 
69135 int len; /* Length of a field */
69136 #endif /* local variables moved into u.ar */
69137
69138 /* Assuming the record contains N fields, the record format looks
69139 ** like this:
69140 **
69141 ** ------------------------------------------------------------------------
69142 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 |
69143 ** ------------------------------------------------------------------------
69144 **
69145 ** Data(0) is taken from register P1. Data(1) comes from register P1+1
69146 ** and so froth.
69147 **
69148 ** Each type field is a varint representing the serial type of the
69149 ** corresponding data element (see sqlite3VdbeSerialType()). The
69150 ** hdr-size field is also a varint which is the offset from the beginning
69151 ** of the record to data0.
69152 */
69153 u.ar.nData = 0; /* Number of bytes of data space */
69154 u.ar.nHdr = 0; /* Number of bytes of header space */
69155 u.ar.nZero = 0; /* Number of zero bytes at the end of the record */
69156 u.ar.nField = pOp->p1;
69157 u.ar.zAffinity = pOp->p4.z;
69158 assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 );
69159 u.ar.pData0 = &aMem[u.ar.nField];
69160 u.ar.nField = pOp->p2;
69161 u.ar.pLast = &u.ar.pData0[u.ar.nField-1];
69162 u.ar.file_format = p->minWriteFileFormat;
69163
69164 /* Identify the output register */
69165 assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 );
69166 pOut = &aMem[pOp->p3];
69167 memAboutToChange(p, pOut);
69168
 
 
 
 
 
 
 
 
 
 
69169 /* Loop through the elements that will make up the record to figure
69170 ** out how much space is required for the new record.
69171 */
69172 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69173 assert( memIsValid(u.ar.pRec) );
69174 if( u.ar.zAffinity ){
69175 applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding);
69176 }
69177 if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){
69178 sqlite3VdbeMemExpandBlob(u.ar.pRec);
69179 }
69180 u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69181 u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type);
69182 u.ar.nData += u.ar.len;
69183 u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type);
69184 if( u.ar.pRec->flags & MEM_Zero ){
69185 /* Only pure zero-filled BLOBs can be input to this Opcode.
69186 ** We do not allow blobs with a prefix and a zero-filled tail. */
69187 u.ar.nZero += u.ar.pRec->u.nZero;
69188 }else if( u.ar.len ){
69189 u.ar.nZero = 0;
69190 }
69191 }
69192
69193 /* Add the initial header varint and total the size */
69194 u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr);
69195 if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){
69196 u.ar.nHdr++;
69197 }
69198 u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero;
69199 if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
 
 
 
 
 
 
 
69200 goto too_big;
69201 }
69202
69203 /* Make sure the output register has a buffer large enough to store
69204 ** the new record. The output register (pOp->p3) is not allowed to
69205 ** be one of the input registers (because the following call to
69206 ** sqlite3VdbeMemGrow() could clobber the value before it is used).
69207 */
69208 if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){
69209 goto no_mem;
69210 }
69211 u.ar.zNewRecord = (u8 *)pOut->z;
69212
69213 /* Write the record */
69214 u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr);
69215 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){
69216 u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format);
69217 u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */
69218 }
69219 for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */
69220 u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format);
69221 }
69222 assert( u.ar.i==u.ar.nByte );
 
 
69223
69224 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
69225 pOut->n = (int)u.ar.nByte;
69226 pOut->flags = MEM_Blob | MEM_Dyn;
69227 pOut->xDel = 0;
69228 if( u.ar.nZero ){
69229 pOut->u.nZero = u.ar.nZero;
69230 pOut->flags |= MEM_Zero;
69231 }
69232 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
69233 REGISTER_TRACE(pOp->p3, pOut);
69234 UPDATE_MAX_BLOBSIZE(pOut);
@@ -69008,18 +69241,19 @@
69241 ** Store the number of entries (an integer value) in the table or index
69242 ** opened by cursor P1 in register P2
69243 */
69244 #ifndef SQLITE_OMIT_BTREECOUNT
69245 case OP_Count: { /* out2-prerelease */
69246 #if 0 /* local variables moved into u.as */
69247 i64 nEntry;
69248 BtCursor *pCrsr;
69249 #endif /* local variables moved into u.as */
69250
69251 u.as.pCrsr = p->apCsr[pOp->p1]->pCursor;
69252 assert( u.as.pCrsr );
69253 rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry);
69254 pOut->u.i = u.as.nEntry;
 
69255 break;
69256 }
69257 #endif
69258
69259 /* Opcode: Savepoint P1 * * P4 *
@@ -69027,41 +69261,43 @@
69261 ** Open, release or rollback the savepoint named by parameter P4, depending
69262 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an
69263 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2.
69264 */
69265 case OP_Savepoint: {
69266 #if 0 /* local variables moved into u.at */
69267 int p1; /* Value of P1 operand */
69268 char *zName; /* Name of savepoint */
69269 int nName;
69270 Savepoint *pNew;
69271 Savepoint *pSavepoint;
69272 Savepoint *pTmp;
69273 int iSavepoint;
69274 int ii;
69275 #endif /* local variables moved into u.at */
69276
69277 u.at.p1 = pOp->p1;
69278 u.at.zName = pOp->p4.z;
69279
69280 /* Assert that the u.at.p1 parameter is valid. Also that if there is no open
69281 ** transaction, then there cannot be any savepoints.
69282 */
69283 assert( db->pSavepoint==0 || db->autoCommit==0 );
69284 assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK );
69285 assert( db->pSavepoint || db->isTransactionSavepoint==0 );
69286 assert( checkSavepointCount(db) );
69287 assert( p->bIsReader );
69288
69289 if( u.at.p1==SAVEPOINT_BEGIN ){
69290 if( db->nVdbeWrite>0 ){
69291 /* A new savepoint cannot be created if there are active write
69292 ** statements (i.e. open read/write incremental blob handles).
69293 */
69294 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - "
69295 "SQL statements in progress");
69296 rc = SQLITE_BUSY;
69297 }else{
69298 u.at.nName = sqlite3Strlen30(u.at.zName);
69299
69300 #ifndef SQLITE_OMIT_VIRTUALTABLE
69301 /* This call is Ok even if this savepoint is actually a transaction
69302 ** savepoint (and therefore should not prompt xSavepoint()) callbacks.
69303 ** If this is a transaction savepoint being opened, it is guaranteed
@@ -69071,62 +69307,62 @@
69307 db->nStatement+db->nSavepoint);
69308 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69309 #endif
69310
69311 /* Create a new savepoint structure. */
69312 u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1);
69313 if( u.at.pNew ){
69314 u.at.pNew->zName = (char *)&u.at.pNew[1];
69315 memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1);
69316
69317 /* If there is no open transaction, then mark this as a special
69318 ** "transaction savepoint". */
69319 if( db->autoCommit ){
69320 db->autoCommit = 0;
69321 db->isTransactionSavepoint = 1;
69322 }else{
69323 db->nSavepoint++;
69324 }
69325
69326 /* Link the new savepoint into the database handle's list. */
69327 u.at.pNew->pNext = db->pSavepoint;
69328 db->pSavepoint = u.at.pNew;
69329 u.at.pNew->nDeferredCons = db->nDeferredCons;
69330 u.at.pNew->nDeferredImmCons = db->nDeferredImmCons;
69331 }
69332 }
69333 }else{
69334 u.at.iSavepoint = 0;
69335
69336 /* Find the named savepoint. If there is no such savepoint, then an
69337 ** an error is returned to the user. */
69338 for(
69339 u.at.pSavepoint = db->pSavepoint;
69340 u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName);
69341 u.at.pSavepoint = u.at.pSavepoint->pNext
69342 ){
69343 u.at.iSavepoint++;
69344 }
69345 if( !u.at.pSavepoint ){
69346 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName);
69347 rc = SQLITE_ERROR;
69348 }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){
69349 /* It is not possible to release (commit) a savepoint if there are
69350 ** active write statements.
69351 */
69352 sqlite3SetString(&p->zErrMsg, db,
69353 "cannot release savepoint - SQL statements in progress"
69354 );
69355 rc = SQLITE_BUSY;
69356 }else{
69357
69358 /* Determine whether or not this is a transaction savepoint. If so,
69359 ** and this is a RELEASE command, then the current transaction
69360 ** is committed.
69361 */
69362 int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint;
69363 if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){
69364 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69365 goto vdbe_return;
69366 }
69367 db->autoCommit = 1;
69368 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
@@ -69136,56 +69372,56 @@
69372 goto vdbe_return;
69373 }
69374 db->isTransactionSavepoint = 0;
69375 rc = p->rc;
69376 }else{
69377 u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1;
69378 if( u.at.p1==SAVEPOINT_ROLLBACK ){
69379 for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69380 sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT);
69381 }
69382 }
69383 for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){
69384 rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint);
69385 if( rc!=SQLITE_OK ){
69386 goto abort_due_to_error;
69387 }
69388 }
69389 if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
69390 sqlite3ExpirePreparedStatements(db);
69391 sqlite3ResetAllSchemasOfConnection(db);
69392 db->flags = (db->flags | SQLITE_InternChanges);
69393 }
69394 }
69395
69396 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
69397 ** savepoints nested inside of the savepoint being operated on. */
69398 while( db->pSavepoint!=u.at.pSavepoint ){
69399 u.at.pTmp = db->pSavepoint;
69400 db->pSavepoint = u.at.pTmp->pNext;
69401 sqlite3DbFree(db, u.at.pTmp);
69402 db->nSavepoint--;
69403 }
69404
69405 /* If it is a RELEASE, then destroy the savepoint being operated on
69406 ** too. If it is a ROLLBACK TO, then set the number of deferred
69407 ** constraint violations present in the database to the value stored
69408 ** when the savepoint was created. */
69409 if( u.at.p1==SAVEPOINT_RELEASE ){
69410 assert( u.at.pSavepoint==db->pSavepoint );
69411 db->pSavepoint = u.at.pSavepoint->pNext;
69412 sqlite3DbFree(db, u.at.pSavepoint);
69413 if( !isTransaction ){
69414 db->nSavepoint--;
69415 }
69416 }else{
69417 db->nDeferredCons = u.at.pSavepoint->nDeferredCons;
69418 db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons;
69419 }
69420
69421 if( !isTransaction ){
69422 rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint);
69423 if( rc!=SQLITE_OK ) goto abort_due_to_error;
69424 }
69425 }
69426 }
69427
@@ -69200,52 +69436,54 @@
69436 ** there are active writing VMs or active VMs that use shared cache.
69437 **
69438 ** This instruction causes the VM to halt.
69439 */
69440 case OP_AutoCommit: {
69441 #if 0 /* local variables moved into u.au */
69442 int desiredAutoCommit;
69443 int iRollback;
69444 int turnOnAC;
69445 #endif /* local variables moved into u.au */
69446
69447 u.au.desiredAutoCommit = pOp->p1;
69448 u.au.iRollback = pOp->p2;
69449 u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit;
69450 assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 );
69451 assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 );
69452 assert( db->nVdbeActive>0 ); /* At least this one VM is active */
69453 assert( p->bIsReader );
69454
69455 #if 0
69456 if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){
69457 /* If this instruction implements a ROLLBACK and other VMs are
69458 ** still running, and a transaction is active, return an error indicating
69459 ** that the other VMs must complete first.
69460 */
69461 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - "
69462 "SQL statements in progress");
69463 rc = SQLITE_BUSY;
69464 }else
69465 #endif
69466 if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){
69467 /* If this instruction implements a COMMIT and other VMs are writing
69468 ** return an error indicating that the other VMs must complete first.
69469 */
69470 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - "
69471 "SQL statements in progress");
69472 rc = SQLITE_BUSY;
69473 }else if( u.au.desiredAutoCommit!=db->autoCommit ){
69474 if( u.au.iRollback ){
69475 assert( u.au.desiredAutoCommit==1 );
69476 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
69477 db->autoCommit = 1;
69478 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){
69479 goto vdbe_return;
69480 }else{
69481 db->autoCommit = (u8)u.au.desiredAutoCommit;
69482 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){
69483 p->pc = pc;
69484 db->autoCommit = (u8)(1-u.au.desiredAutoCommit);
69485 p->rc = rc = SQLITE_BUSY;
69486 goto vdbe_return;
69487 }
69488 }
69489 assert( db->nStatement==0 );
@@ -69256,14 +69494,14 @@
69494 rc = SQLITE_ERROR;
69495 }
69496 goto vdbe_return;
69497 }else{
69498 sqlite3SetString(&p->zErrMsg, db,
69499 (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":(
69500 (u.au.iRollback)?"cannot rollback - no transaction is active":
69501 "cannot commit - no transaction is active"));
69502
69503 rc = SQLITE_ERROR;
69504 }
69505 break;
69506 }
69507
@@ -69297,46 +69535,48 @@
69535 ** will automatically commit when the VDBE halts.
69536 **
69537 ** If P2 is zero, then a read-lock is obtained on the database file.
69538 */
69539 case OP_Transaction: {
69540 #if 0 /* local variables moved into u.av */
69541 Btree *pBt;
69542 #endif /* local variables moved into u.av */
69543
69544 assert( p->bIsReader );
69545 assert( p->readOnly==0 || pOp->p2==0 );
69546 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69547 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69548 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
69549 rc = SQLITE_READONLY;
69550 goto abort_due_to_error;
69551 }
69552 u.av.pBt = db->aDb[pOp->p1].pBt;
69553
69554 if( u.av.pBt ){
69555 rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2);
69556 if( rc==SQLITE_BUSY ){
69557 p->pc = pc;
69558 p->rc = rc = SQLITE_BUSY;
69559 goto vdbe_return;
69560 }
69561 if( rc!=SQLITE_OK ){
69562 goto abort_due_to_error;
69563 }
69564
69565 if( pOp->p2 && p->usesStmtJournal
69566 && (db->autoCommit==0 || db->nVdbeRead>1)
69567 ){
69568 assert( sqlite3BtreeIsInTrans(u.av.pBt) );
69569 if( p->iStatement==0 ){
69570 assert( db->nStatement>=0 && db->nSavepoint>=0 );
69571 db->nStatement++;
69572 p->iStatement = db->nSavepoint + db->nStatement;
69573 }
69574
69575 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1);
69576 if( rc==SQLITE_OK ){
69577 rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement);
69578 }
69579
69580 /* Store the current value of the database handles deferred constraint
69581 ** counter. If the statement transaction needs to be rolled back,
69582 ** the value of this counter needs to be restored too. */
@@ -69358,24 +69598,26 @@
69598 ** There must be a read-lock on the database (either a transaction
69599 ** must be started or there must be an open cursor) before
69600 ** executing this instruction.
69601 */
69602 case OP_ReadCookie: { /* out2-prerelease */
69603 #if 0 /* local variables moved into u.aw */
69604 int iMeta;
69605 int iDb;
69606 int iCookie;
69607 #endif /* local variables moved into u.aw */
69608
69609 assert( p->bIsReader );
69610 u.aw.iDb = pOp->p1;
69611 u.aw.iCookie = pOp->p3;
69612 assert( pOp->p3<SQLITE_N_BTREE_META );
69613 assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb );
69614 assert( db->aDb[u.aw.iDb].pBt!=0 );
69615 assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 );
69616
69617 sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta);
69618 pOut->u.i = u.aw.iMeta;
69619 break;
69620 }
69621
69622 /* Opcode: SetCookie P1 P2 P3 * *
69623 **
@@ -69386,29 +69628,31 @@
69628 ** database file used to store temporary tables.
69629 **
69630 ** A transaction must be started before executing this opcode.
69631 */
69632 case OP_SetCookie: { /* in3 */
69633 #if 0 /* local variables moved into u.ax */
69634 Db *pDb;
69635 #endif /* local variables moved into u.ax */
69636 assert( pOp->p2<SQLITE_N_BTREE_META );
69637 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69638 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69639 assert( p->readOnly==0 );
69640 u.ax.pDb = &db->aDb[pOp->p1];
69641 assert( u.ax.pDb->pBt!=0 );
69642 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69643 pIn3 = &aMem[pOp->p3];
69644 sqlite3VdbeMemIntegerify(pIn3);
69645 /* See note about index shifting on OP_ReadCookie */
69646 rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i);
69647 if( pOp->p2==BTREE_SCHEMA_VERSION ){
69648 /* When the schema cookie changes, record the new cookie internally */
69649 u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i;
69650 db->flags |= SQLITE_InternChanges;
69651 }else if( pOp->p2==BTREE_FILE_FORMAT ){
69652 /* Record changes in the file format */
69653 u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i;
69654 }
69655 if( pOp->p1==1 ){
69656 /* Invalidate all prepared statements whenever the TEMP database
69657 ** schema is changed. Ticket #1644 */
69658 sqlite3ExpirePreparedStatements(db);
@@ -69434,42 +69678,44 @@
69678 ** Either a transaction needs to have been started or an OP_Open needs
69679 ** to be executed (to establish a read lock) before this opcode is
69680 ** invoked.
69681 */
69682 case OP_VerifyCookie: {
69683 #if 0 /* local variables moved into u.ay */
69684 int iMeta;
69685 int iGen;
69686 Btree *pBt;
69687 #endif /* local variables moved into u.ay */
69688
69689 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69690 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69691 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69692 assert( p->bIsReader );
69693 u.ay.pBt = db->aDb[pOp->p1].pBt;
69694 if( u.ay.pBt ){
69695 sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta);
69696 u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69697 }else{
69698 u.ay.iGen = u.ay.iMeta = 0;
69699 }
69700 if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){
69701 sqlite3DbFree(db, p->zErrMsg);
69702 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69703 /* If the schema-cookie from the database file matches the cookie
69704 ** stored with the in-memory representation of the schema, do
69705 ** not reload the schema from the database file.
69706 **
69707 ** If virtual-tables are in use, this is not just an optimization.
69708 ** Often, v-tables store their data in other SQLite tables, which
69709 ** are queried from within xNext() and other v-table methods using
69710 ** prepared queries. If such a query is out-of-date, we do not want to
69711 ** discard the database schema, as the user code implementing the
69712 ** v-table would have to be ready for the sqlite3_vtab structure itself
69713 ** to be invalidated whenever sqlite3_step() is called from within
69714 ** a v-table method.
69715 */
69716 if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){
69717 sqlite3ResetOneSchema(db, pOp->p1);
69718 }
69719
69720 p->expired = 1;
69721 rc = SQLITE_SCHEMA;
@@ -69528,18 +69774,20 @@
69774 **
69775 ** See also OpenRead.
69776 */
69777 case OP_OpenRead:
69778 case OP_OpenWrite: {
69779 #if 0 /* local variables moved into u.az */
69780 int nField;
69781 KeyInfo *pKeyInfo;
69782 int p2;
69783 int iDb;
69784 int wrFlag;
69785 Btree *pX;
69786 VdbeCursor *pCur;
69787 Db *pDb;
69788 #endif /* local variables moved into u.az */
69789
69790 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
69791 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
69792 assert( p->bIsReader );
69793 assert( pOp->opcode==OP_OpenRead || p->readOnly==0 );
@@ -69547,74 +69795,74 @@
69795 if( p->expired ){
69796 rc = SQLITE_ABORT;
69797 break;
69798 }
69799
69800 u.az.nField = 0;
69801 u.az.pKeyInfo = 0;
69802 u.az.p2 = pOp->p2;
69803 u.az.iDb = pOp->p3;
69804 assert( u.az.iDb>=0 && u.az.iDb<db->nDb );
69805 assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 );
69806 u.az.pDb = &db->aDb[u.az.iDb];
69807 u.az.pX = u.az.pDb->pBt;
69808 assert( u.az.pX!=0 );
69809 if( pOp->opcode==OP_OpenWrite ){
69810 u.az.wrFlag = 1;
69811 assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) );
69812 if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){
69813 p->minWriteFileFormat = u.az.pDb->pSchema->file_format;
69814 }
69815 }else{
69816 u.az.wrFlag = 0;
69817 }
69818 if( pOp->p5 & OPFLAG_P2ISREG ){
69819 assert( u.az.p2>0 );
69820 assert( u.az.p2<=(p->nMem-p->nCursor) );
69821 pIn2 = &aMem[u.az.p2];
69822 assert( memIsValid(pIn2) );
69823 assert( (pIn2->flags & MEM_Int)!=0 );
69824 sqlite3VdbeMemIntegerify(pIn2);
69825 u.az.p2 = (int)pIn2->u.i;
69826 /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and
69827 ** that opcode will always set the u.az.p2 value to 2 or more or else fail.
69828 ** If there were a failure, the prepared statement would have halted
69829 ** before reaching this instruction. */
69830 if( NEVER(u.az.p2<2) ) {
69831 rc = SQLITE_CORRUPT_BKPT;
69832 goto abort_due_to_error;
69833 }
69834 }
69835 if( pOp->p4type==P4_KEYINFO ){
69836 u.az.pKeyInfo = pOp->p4.pKeyInfo;
69837 assert( u.az.pKeyInfo->enc==ENC(db) );
69838 assert( u.az.pKeyInfo->db==db );
69839 u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
69840 }else if( pOp->p4type==P4_INT32 ){
69841 u.az.nField = pOp->p4.i;
69842 }
69843 assert( pOp->p1>=0 );
69844 assert( u.az.nField>=0 );
69845 testcase( u.az.nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
69846 u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69847 if( u.az.pCur==0 ) goto no_mem;
69848 u.az.pCur->nullRow = 1;
69849 u.az.pCur->isOrdered = 1;
69850 rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
69851 u.az.pCur->pKeyInfo = u.az.pKeyInfo;
69852 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
69853 sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
69854
69855 /* Since it performs no memory allocation or IO, the only value that
69856 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69857 assert( rc==SQLITE_OK );
69858
69859 /* Set the VdbeCursor.isTable variable. Previous versions of
69860 ** SQLite used to check if the root-page flags were sane at this point
69861 ** and report database corruption if they were not, but this check has
69862 ** since moved into the btree layer. */
69863 u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69864 break;
69865 }
69866
69867 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69868 ** Synopsis: nColumn=P2
@@ -69642,53 +69890,55 @@
69890 ** by this opcode will be used for automatically created transient
69891 ** indices in joins.
69892 */
69893 case OP_OpenAutoindex:
69894 case OP_OpenEphemeral: {
69895 #if 0 /* local variables moved into u.ba */
69896 VdbeCursor *pCx;
69897 KeyInfo *pKeyInfo;
69898 #endif /* local variables moved into u.ba */
69899
69900 static const int vfsFlags =
69901 SQLITE_OPEN_READWRITE |
69902 SQLITE_OPEN_CREATE |
69903 SQLITE_OPEN_EXCLUSIVE |
69904 SQLITE_OPEN_DELETEONCLOSE |
69905 SQLITE_OPEN_TRANSIENT_DB;
69906 assert( pOp->p1>=0 );
69907 assert( pOp->p2>=0 );
69908 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69909 if( u.ba.pCx==0 ) goto no_mem;
69910 u.ba.pCx->nullRow = 1;
69911 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
69912 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
69913 if( rc==SQLITE_OK ){
69914 rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1);
69915 }
69916 if( rc==SQLITE_OK ){
69917 /* If a transient index is required, create it by calling
69918 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
69919 ** opening it. If a transient table is required, just use the
69920 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
69921 */
69922 if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
69923 int pgno;
69924 assert( pOp->p4type==P4_KEYINFO );
69925 rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
69926 if( rc==SQLITE_OK ){
69927 assert( pgno==MASTER_ROOT+1 );
69928 assert( u.ba.pKeyInfo->db==db );
69929 assert( u.ba.pKeyInfo->enc==ENC(db) );
69930 u.ba.pCx->pKeyInfo = u.ba.pKeyInfo;
69931 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor);
69932 }
69933 u.ba.pCx->isTable = 0;
69934 }else{
69935 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69936 u.ba.pCx->isTable = 1;
69937 }
69938 }
69939 u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69940 break;
69941 }
69942
69943 /* Opcode: SorterOpen P1 * * P4 *
69944 **
@@ -69695,20 +69945,22 @@
69945 ** This opcode works like OP_OpenEphemeral except that it opens
69946 ** a transient index that is specifically designed to sort large
69947 ** tables using an external merge-sort algorithm.
69948 */
69949 case OP_SorterOpen: {
69950 #if 0 /* local variables moved into u.bb */
69951 VdbeCursor *pCx;
69952 #endif /* local variables moved into u.bb */
69953
69954 assert( pOp->p1>=0 );
69955 assert( pOp->p2>=0 );
69956 u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69957 if( u.bb.pCx==0 ) goto no_mem;
69958 u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69959 assert( u.bb.pCx->pKeyInfo->db==db );
69960 assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69961 rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
69962 break;
69963 }
69964
69965 /* Opcode: OpenPseudo P1 P2 P3 * P5
69966 ** Synopsis: content in r[P2@P3]
@@ -69726,20 +69978,22 @@
69978 **
69979 ** P3 is the number of fields in the records that will be stored by
69980 ** the pseudo-table.
69981 */
69982 case OP_OpenPseudo: {
69983 #if 0 /* local variables moved into u.bc */
69984 VdbeCursor *pCx;
69985 #endif /* local variables moved into u.bc */
69986
69987 assert( pOp->p1>=0 );
69988 assert( pOp->p3>=0 );
69989 u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69990 if( u.bc.pCx==0 ) goto no_mem;
69991 u.bc.pCx->nullRow = 1;
69992 u.bc.pCx->pseudoTableReg = pOp->p2;
69993 u.bc.pCx->isTable = 1;
69994 u.bc.pCx->multiPseudo = pOp->p5;
69995 break;
69996 }
69997
69998 /* Opcode: Close P1 * * * *
69999 **
@@ -69811,37 +70065,39 @@
70065 */
70066 case OP_SeekLt: /* jump, in3 */
70067 case OP_SeekLe: /* jump, in3 */
70068 case OP_SeekGe: /* jump, in3 */
70069 case OP_SeekGt: { /* jump, in3 */
70070 #if 0 /* local variables moved into u.bd */
70071 int res;
70072 int oc;
70073 VdbeCursor *pC;
70074 UnpackedRecord r;
70075 int nField;
70076 i64 iKey; /* The rowid we are to seek to */
70077 #endif /* local variables moved into u.bd */
70078
70079 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70080 assert( pOp->p2!=0 );
70081 u.bd.pC = p->apCsr[pOp->p1];
70082 assert( u.bd.pC!=0 );
70083 assert( u.bd.pC->pseudoTableReg==0 );
70084 assert( OP_SeekLe == OP_SeekLt+1 );
70085 assert( OP_SeekGe == OP_SeekLt+2 );
70086 assert( OP_SeekGt == OP_SeekLt+3 );
70087 assert( u.bd.pC->isOrdered );
70088 assert( u.bd.pC->pCursor!=0 );
70089 u.bd.oc = pOp->opcode;
70090 u.bd.pC->nullRow = 0;
70091 if( u.bd.pC->isTable ){
70092 /* The input value in P3 might be of any type: integer, real, string,
70093 ** blob, or NULL. But it needs to be an integer before we can do
70094 ** the seek, so covert it. */
70095 pIn3 = &aMem[pOp->p3];
70096 applyNumericAffinity(pIn3);
70097 u.bd.iKey = sqlite3VdbeIntValue(pIn3);
70098 u.bd.pC->rowidIsValid = 0;
70099
70100 /* If the P3 value could not be converted into an integer without
70101 ** loss of information, then special processing is required... */
70102 if( (pIn3->flags & MEM_Int)==0 ){
70103 if( (pIn3->flags & MEM_Real)==0 ){
@@ -69849,100 +70105,100 @@
70105 ** then the seek is not possible, so jump to P2 */
70106 pc = pOp->p2 - 1;
70107 break;
70108 }
70109
70110 /* If the approximation u.bd.iKey is larger than the actual real search
70111 ** term, substitute >= for > and < for <=. e.g. if the search term
70112 ** is 4.9 and the integer approximation 5:
70113 **
70114 ** (x > 4.9) -> (x >= 5)
70115 ** (x <= 4.9) -> (x < 5)
70116 */
70117 if( pIn3->r<(double)u.bd.iKey ){
70118 assert( OP_SeekGe==(OP_SeekGt-1) );
70119 assert( OP_SeekLt==(OP_SeekLe-1) );
70120 assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
70121 if( (u.bd.oc & 0x0001)==(OP_SeekGt & 0x0001) ) u.bd.oc--;
70122 }
70123
70124 /* If the approximation u.bd.iKey is smaller than the actual real search
70125 ** term, substitute <= for < and > for >=. */
70126 else if( pIn3->r>(double)u.bd.iKey ){
70127 assert( OP_SeekLe==(OP_SeekLt+1) );
70128 assert( OP_SeekGt==(OP_SeekGe+1) );
70129 assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
70130 if( (u.bd.oc & 0x0001)==(OP_SeekLt & 0x0001) ) u.bd.oc++;
70131 }
70132 }
70133 rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res);
70134 if( rc!=SQLITE_OK ){
70135 goto abort_due_to_error;
70136 }
70137 if( u.bd.res==0 ){
70138 u.bd.pC->rowidIsValid = 1;
70139 u.bd.pC->lastRowid = u.bd.iKey;
70140 }
70141 }else{
70142 u.bd.nField = pOp->p4.i;
70143 assert( pOp->p4type==P4_INT32 );
70144 assert( u.bd.nField>0 );
70145 u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo;
70146 u.bd.r.nField = (u16)u.bd.nField;
70147
70148 /* The next line of code computes as follows, only faster:
70149 ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){
70150 ** u.bd.r.flags = UNPACKED_INCRKEY;
70151 ** }else{
70152 ** u.bd.r.flags = 0;
70153 ** }
70154 */
70155 u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt)));
70156 assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY );
70157 assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY );
70158 assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 );
70159 assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 );
70160
70161 u.bd.r.aMem = &aMem[pOp->p3];
70162 #ifdef SQLITE_DEBUG
70163 { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); }
70164 #endif
70165 ExpandBlob(u.bd.r.aMem);
70166 rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res);
70167 if( rc!=SQLITE_OK ){
70168 goto abort_due_to_error;
70169 }
70170 u.bd.pC->rowidIsValid = 0;
70171 }
70172 u.bd.pC->deferredMoveto = 0;
70173 u.bd.pC->cacheStatus = CACHE_STALE;
70174 #ifdef SQLITE_TEST
70175 sqlite3_search_count++;
70176 #endif
70177 if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt );
70178 if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){
70179 rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res);
70180 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70181 u.bd.pC->rowidIsValid = 0;
70182 }else{
70183 u.bd.res = 0;
70184 }
70185 }else{
70186 assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe );
70187 if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){
70188 rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res);
70189 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70190 u.bd.pC->rowidIsValid = 0;
70191 }else{
70192 /* u.bd.res might be negative because the table is empty. Check to
70193 ** see if this is the case.
70194 */
70195 u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor);
70196 }
70197 }
70198 assert( pOp->p2>0 );
70199 if( u.bd.res ){
70200 pc = pOp->p2 - 1;
70201 }
70202 break;
70203 }
70204
@@ -69955,22 +70211,24 @@
70211 ** This is actually a deferred seek. Nothing actually happens until
70212 ** the cursor is used to read a record. That way, if no reads
70213 ** occur, no unnecessary I/O happens.
70214 */
70215 case OP_Seek: { /* in2 */
70216 #if 0 /* local variables moved into u.be */
70217 VdbeCursor *pC;
70218 #endif /* local variables moved into u.be */
70219
70220 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70221 u.be.pC = p->apCsr[pOp->p1];
70222 assert( u.be.pC!=0 );
70223 assert( u.be.pC->pCursor!=0 );
70224 assert( u.be.pC->isTable );
70225 u.be.pC->nullRow = 0;
70226 pIn2 = &aMem[pOp->p2];
70227 u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2);
70228 u.be.pC->rowidIsValid = 0;
70229 u.be.pC->deferredMoveto = 1;
70230 break;
70231 }
70232
70233
70234 /* Opcode: Found P1 P2 P3 P4 *
@@ -70021,83 +70279,85 @@
70279 ** See also: NotFound, Found, NotExists
70280 */
70281 case OP_NoConflict: /* jump, in3 */
70282 case OP_NotFound: /* jump, in3 */
70283 case OP_Found: { /* jump, in3 */
70284 #if 0 /* local variables moved into u.bf */
70285 int alreadyExists;
70286 int ii;
70287 VdbeCursor *pC;
70288 int res;
70289 char *pFree;
70290 UnpackedRecord *pIdxKey;
70291 UnpackedRecord r;
70292 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
70293 #endif /* local variables moved into u.bf */
70294
70295 #ifdef SQLITE_TEST
70296 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
70297 #endif
70298
70299 u.bf.alreadyExists = 0;
70300 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70301 assert( pOp->p4type==P4_INT32 );
70302 u.bf.pC = p->apCsr[pOp->p1];
70303 assert( u.bf.pC!=0 );
70304 pIn3 = &aMem[pOp->p3];
70305 assert( u.bf.pC->pCursor!=0 );
70306 assert( u.bf.pC->isTable==0 );
 
70307 if( pOp->p4.i>0 ){
70308 u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo;
70309 u.bf.r.nField = (u16)pOp->p4.i;
70310 u.bf.r.aMem = pIn3;
70311 #ifdef SQLITE_DEBUG
70312 {
70313 int i;
70314 for(i=0; i<u.bf.r.nField; i++){
70315 assert( memIsValid(&u.bf.r.aMem[i]) );
70316 if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]);
70317 }
70318 }
70319 #endif
70320 u.bf.r.flags = UNPACKED_PREFIX_MATCH;
70321 u.bf.pIdxKey = &u.bf.r;
70322 }else{
70323 u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70324 u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree
70325 );
70326 if( u.bf.pIdxKey==0 ) goto no_mem;
70327 assert( pIn3->flags & MEM_Blob );
70328 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
70329 sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey);
70330 u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH;
70331 }
70332 if( pOp->opcode==OP_NoConflict ){
70333 /* For the OP_NoConflict opcode, take the jump if any of the
70334 ** input fields are NULL, since any key with a NULL will not
70335 ** conflict */
70336 for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){
70337 if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){
70338 pc = pOp->p2 - 1;
70339 break;
70340 }
70341 }
70342 }
70343 rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res);
70344 if( pOp->p4.i==0 ){
70345 sqlite3DbFree(db, u.bf.pFree);
70346 }
70347 if( rc!=SQLITE_OK ){
70348 break;
70349 }
70350 u.bf.pC->seekResult = u.bf.res;
70351 u.bf.alreadyExists = (u.bf.res==0);
70352 u.bf.pC->nullRow = 1-u.bf.alreadyExists;
70353 u.bf.pC->deferredMoveto = 0;
70354 u.bf.pC->cacheStatus = CACHE_STALE;
70355 if( pOp->opcode==OP_Found ){
70356 if( u.bf.alreadyExists ) pc = pOp->p2 - 1;
70357 }else{
70358 if( !u.bf.alreadyExists ) pc = pOp->p2 - 1;
70359 }
70360 break;
70361 }
70362
70363 /* Opcode: NotExists P1 P2 P3 * *
@@ -70113,37 +70373,39 @@
70373 ** (with arbitrary multi-value keys).
70374 **
70375 ** See also: Found, NotFound, NoConflict
70376 */
70377 case OP_NotExists: { /* jump, in3 */
70378 #if 0 /* local variables moved into u.bg */
70379 VdbeCursor *pC;
70380 BtCursor *pCrsr;
70381 int res;
70382 u64 iKey;
70383 #endif /* local variables moved into u.bg */
70384
70385 pIn3 = &aMem[pOp->p3];
70386 assert( pIn3->flags & MEM_Int );
70387 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70388 u.bg.pC = p->apCsr[pOp->p1];
70389 assert( u.bg.pC!=0 );
70390 assert( u.bg.pC->isTable );
70391 assert( u.bg.pC->pseudoTableReg==0 );
70392 u.bg.pCrsr = u.bg.pC->pCursor;
70393 assert( u.bg.pCrsr!=0 );
70394 u.bg.res = 0;
70395 u.bg.iKey = pIn3->u.i;
70396 rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res);
70397 u.bg.pC->lastRowid = pIn3->u.i;
70398 u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0;
70399 u.bg.pC->nullRow = 0;
70400 u.bg.pC->cacheStatus = CACHE_STALE;
70401 u.bg.pC->deferredMoveto = 0;
70402 if( u.bg.res!=0 ){
70403 pc = pOp->p2 - 1;
70404 assert( u.bg.pC->rowidIsValid==0 );
70405 }
70406 u.bg.pC->seekResult = u.bg.res;
70407 break;
70408 }
70409
70410 /* Opcode: Sequence P1 P2 * * *
70411 ** Synopsis: r[P2]=rowid
@@ -70175,23 +70437,25 @@
70437 ** an SQLITE_FULL error is generated. The P3 register is updated with the '
70438 ** generated record number. This P3 mechanism is used to help implement the
70439 ** AUTOINCREMENT feature.
70440 */
70441 case OP_NewRowid: { /* out2-prerelease */
70442 #if 0 /* local variables moved into u.bh */
70443 i64 v; /* The new rowid */
70444 VdbeCursor *pC; /* Cursor of table to get the new rowid */
70445 int res; /* Result of an sqlite3BtreeLast() */
70446 int cnt; /* Counter to limit the number of searches */
70447 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
70448 VdbeFrame *pFrame; /* Root frame of VDBE */
70449 #endif /* local variables moved into u.bh */
70450
70451 u.bh.v = 0;
70452 u.bh.res = 0;
70453 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70454 u.bh.pC = p->apCsr[pOp->p1];
70455 assert( u.bh.pC!=0 );
70456 if( NEVER(u.bh.pC->pCursor==0) ){
70457 /* The zero initialization above is all that is needed */
70458 }else{
70459 /* The next rowid or record number (different terms for the same
70460 ** thing) is obtained in a two-step algorithm.
70461 **
@@ -70203,11 +70467,11 @@
70467 ** The second algorithm is to select a rowid at random and see if
70468 ** it already exists in the table. If it does not exist, we have
70469 ** succeeded. If the random rowid does exist, we select a new one
70470 ** and try again, up to 100 times.
70471 */
70472 assert( u.bh.pC->isTable );
70473
70474 #ifdef SQLITE_32BIT_ROWID
70475 # define MAX_ROWID 0x7fffffff
70476 #else
70477 /* Some compilers complain about constants of the form 0x7fffffffffffffff.
@@ -70215,101 +70479,101 @@
70479 ** to provide the constant while making all compilers happy.
70480 */
70481 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70482 #endif
70483
70484 if( !u.bh.pC->useRandomRowid ){
70485 u.bh.v = sqlite3BtreeGetCachedRowid(u.bh.pC->pCursor);
70486 if( u.bh.v==0 ){
70487 rc = sqlite3BtreeLast(u.bh.pC->pCursor, &u.bh.res);
70488 if( rc!=SQLITE_OK ){
70489 goto abort_due_to_error;
70490 }
70491 if( u.bh.res ){
70492 u.bh.v = 1; /* IMP: R-61914-48074 */
70493 }else{
70494 assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) );
70495 rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v);
70496 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70497 if( u.bh.v>=MAX_ROWID ){
70498 u.bh.pC->useRandomRowid = 1;
70499 }else{
70500 u.bh.v++; /* IMP: R-29538-34987 */
70501 }
70502 }
70503 }
70504
70505 #ifndef SQLITE_OMIT_AUTOINCREMENT
70506 if( pOp->p3 ){
70507 /* Assert that P3 is a valid memory cell. */
70508 assert( pOp->p3>0 );
70509 if( p->pFrame ){
70510 for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent);
70511 /* Assert that P3 is a valid memory cell. */
70512 assert( pOp->p3<=u.bh.pFrame->nMem );
70513 u.bh.pMem = &u.bh.pFrame->aMem[pOp->p3];
70514 }else{
70515 /* Assert that P3 is a valid memory cell. */
70516 assert( pOp->p3<=(p->nMem-p->nCursor) );
70517 u.bh.pMem = &aMem[pOp->p3];
70518 memAboutToChange(p, u.bh.pMem);
70519 }
70520 assert( memIsValid(u.bh.pMem) );
70521
70522 REGISTER_TRACE(pOp->p3, u.bh.pMem);
70523 sqlite3VdbeMemIntegerify(u.bh.pMem);
70524 assert( (u.bh.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70525 if( u.bh.pMem->u.i==MAX_ROWID || u.bh.pC->useRandomRowid ){
70526 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70527 goto abort_due_to_error;
70528 }
70529 if( u.bh.v<u.bh.pMem->u.i+1 ){
70530 u.bh.v = u.bh.pMem->u.i + 1;
70531 }
70532 u.bh.pMem->u.i = u.bh.v;
70533 }
70534 #endif
70535
70536 sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0);
70537 }
70538 if( u.bh.pC->useRandomRowid ){
70539 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70540 ** largest possible integer (9223372036854775807) then the database
70541 ** engine starts picking positive candidate ROWIDs at random until
70542 ** it finds one that is not previously used. */
70543 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
70544 ** an AUTOINCREMENT table. */
70545 /* on the first attempt, simply do one more than previous */
70546 u.bh.v = lastRowid;
70547 u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70548 u.bh.v++; /* ensure non-zero */
70549 u.bh.cnt = 0;
70550 while( ((rc = sqlite3BtreeMovetoUnpacked(u.bh.pC->pCursor, 0, (u64)u.bh.v,
70551 0, &u.bh.res))==SQLITE_OK)
70552 && (u.bh.res==0)
70553 && (++u.bh.cnt<100)){
70554 /* collision - try another random rowid */
70555 sqlite3_randomness(sizeof(u.bh.v), &u.bh.v);
70556 if( u.bh.cnt<5 ){
70557 /* try "small" random rowids for the initial attempts */
70558 u.bh.v &= 0xffffff;
70559 }else{
70560 u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
70561 }
70562 u.bh.v++; /* ensure non-zero */
70563 }
70564 if( rc==SQLITE_OK && u.bh.res==0 ){
70565 rc = SQLITE_FULL; /* IMP: R-38219-53002 */
70566 goto abort_due_to_error;
70567 }
70568 assert( u.bh.v>0 ); /* EV: R-40812-03570 */
70569 }
70570 u.bh.pC->rowidIsValid = 0;
70571 u.bh.pC->deferredMoveto = 0;
70572 u.bh.pC->cacheStatus = CACHE_STALE;
70573 }
70574 pOut->u.i = u.bh.v;
70575 break;
70576 }
70577
70578 /* Opcode: Insert P1 P2 P3 P4 P5
70579 ** Synopsis: intkey=r[P3] data=r[P2]
@@ -70357,72 +70621,74 @@
70621 ** This works exactly like OP_Insert except that the key is the
70622 ** integer value P3, not the value of the integer stored in register P3.
70623 */
70624 case OP_Insert:
70625 case OP_InsertInt: {
70626 #if 0 /* local variables moved into u.bi */
70627 Mem *pData; /* MEM cell holding data for the record to be inserted */
70628 Mem *pKey; /* MEM cell holding key for the record */
70629 i64 iKey; /* The integer ROWID or key for the record to be inserted */
70630 VdbeCursor *pC; /* Cursor to table into which insert is written */
70631 int nZero; /* Number of zero-bytes to append */
70632 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */
70633 const char *zDb; /* database name - used by the update hook */
70634 const char *zTbl; /* Table name - used by the opdate hook */
70635 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */
70636 #endif /* local variables moved into u.bi */
70637
70638 u.bi.pData = &aMem[pOp->p2];
70639 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70640 assert( memIsValid(u.bi.pData) );
70641 u.bi.pC = p->apCsr[pOp->p1];
70642 assert( u.bi.pC!=0 );
70643 assert( u.bi.pC->pCursor!=0 );
70644 assert( u.bi.pC->pseudoTableReg==0 );
70645 assert( u.bi.pC->isTable );
70646 REGISTER_TRACE(pOp->p2, u.bi.pData);
70647
70648 if( pOp->opcode==OP_Insert ){
70649 u.bi.pKey = &aMem[pOp->p3];
70650 assert( u.bi.pKey->flags & MEM_Int );
70651 assert( memIsValid(u.bi.pKey) );
70652 REGISTER_TRACE(pOp->p3, u.bi.pKey);
70653 u.bi.iKey = u.bi.pKey->u.i;
70654 }else{
70655 assert( pOp->opcode==OP_InsertInt );
70656 u.bi.iKey = pOp->p3;
70657 }
70658
70659 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
70660 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bi.iKey;
70661 if( u.bi.pData->flags & MEM_Null ){
70662 u.bi.pData->z = 0;
70663 u.bi.pData->n = 0;
70664 }else{
70665 assert( u.bi.pData->flags & (MEM_Blob|MEM_Str) );
70666 }
70667 u.bi.seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bi.pC->seekResult : 0);
70668 if( u.bi.pData->flags & MEM_Zero ){
70669 u.bi.nZero = u.bi.pData->u.nZero;
70670 }else{
70671 u.bi.nZero = 0;
70672 }
70673 sqlite3BtreeSetCachedRowid(u.bi.pC->pCursor, 0);
70674 rc = sqlite3BtreeInsert(u.bi.pC->pCursor, 0, u.bi.iKey,
70675 u.bi.pData->z, u.bi.pData->n, u.bi.nZero,
70676 (pOp->p5 & OPFLAG_APPEND)!=0, u.bi.seekResult
70677 );
70678 u.bi.pC->rowidIsValid = 0;
70679 u.bi.pC->deferredMoveto = 0;
70680 u.bi.pC->cacheStatus = CACHE_STALE;
70681
70682 /* Invoke the update-hook if required. */
70683 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){
70684 u.bi.zDb = db->aDb[u.bi.pC->iDb].zName;
70685 u.bi.zTbl = pOp->p4.z;
70686 u.bi.op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
70687 assert( u.bi.pC->isTable );
70688 db->xUpdateCallback(db->pUpdateArg, u.bi.op, u.bi.zDb, u.bi.zTbl, u.bi.iKey);
70689 assert( u.bi.pC->iDb>=0 );
70690 }
70691 break;
70692 }
70693
70694 /* Opcode: Delete P1 P2 * P4 *
@@ -70444,39 +70710,41 @@
70710 ** pointing to. The update hook will be invoked, if it exists.
70711 ** If P4 is not NULL then the P1 cursor must have been positioned
70712 ** using OP_NotFound prior to invoking this opcode.
70713 */
70714 case OP_Delete: {
70715 #if 0 /* local variables moved into u.bj */
70716 i64 iKey;
70717 VdbeCursor *pC;
70718 #endif /* local variables moved into u.bj */
70719
70720 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70721 u.bj.pC = p->apCsr[pOp->p1];
70722 assert( u.bj.pC!=0 );
70723 assert( u.bj.pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */
70724 u.bj.iKey = u.bj.pC->lastRowid; /* Only used for the update hook */
70725
70726 /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or
70727 ** OP_Column on the same table without any intervening operations that
70728 ** might move or invalidate the cursor. Hence cursor u.bj.pC is always pointing
70729 ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation
70730 ** below is always a no-op and cannot fail. We will run it anyhow, though,
70731 ** to guard against future changes to the code generator.
70732 **/
70733 assert( u.bj.pC->deferredMoveto==0 );
70734 rc = sqlite3VdbeCursorMoveto(u.bj.pC);
70735 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70736
70737 sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0);
70738 rc = sqlite3BtreeDelete(u.bj.pC->pCursor);
70739 u.bj.pC->cacheStatus = CACHE_STALE;
70740
70741 /* Invoke the update-hook if required. */
70742 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && u.bj.pC->isTable ){
70743 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE,
70744 db->aDb[u.bj.pC->iDb].zName, pOp->p4.z, u.bj.iKey);
70745 assert( u.bj.pC->iDb>=0 );
70746 }
70747 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
70748 break;
70749 }
70750 /* Opcode: ResetCount * * * * *
@@ -70506,21 +70774,23 @@
70774 **
70775 ** Fall through to next instruction if the two records compare equal to
70776 ** each other. Jump to P2 if they are different.
70777 */
70778 case OP_SorterCompare: {
70779 #if 0 /* local variables moved into u.bk */
70780 VdbeCursor *pC;
70781 int res;
70782 int nIgnore;
70783 #endif /* local variables moved into u.bk */
70784
70785 u.bk.pC = p->apCsr[pOp->p1];
70786 assert( isSorter(u.bk.pC) );
70787 assert( pOp->p4type==P4_INT32 );
70788 pIn3 = &aMem[pOp->p3];
70789 u.bk.nIgnore = pOp->p4.i;
70790 rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res);
70791 if( u.bk.res ){
70792 pc = pOp->p2-1;
70793 }
70794 break;
70795 };
70796
@@ -70528,16 +70798,18 @@
70798 ** Synopsis: r[P2]=data
70799 **
70800 ** Write into register P2 the current sorter data for sorter cursor P1.
70801 */
70802 case OP_SorterData: {
70803 #if 0 /* local variables moved into u.bl */
70804 VdbeCursor *pC;
70805 #endif /* local variables moved into u.bl */
70806
70807 pOut = &aMem[pOp->p2];
70808 u.bl.pC = p->apCsr[pOp->p1];
70809 assert( isSorter(u.bl.pC) );
70810 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
70811 break;
70812 }
70813
70814 /* Opcode: RowData P1 P2 * * *
70815 ** Synopsis: r[P2]=data
@@ -70561,64 +70833,66 @@
70833 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70834 ** of a real table, not a pseudo-table.
70835 */
70836 case OP_RowKey:
70837 case OP_RowData: {
70838 #if 0 /* local variables moved into u.bm */
70839 VdbeCursor *pC;
70840 BtCursor *pCrsr;
70841 u32 n;
70842 i64 n64;
70843 #endif /* local variables moved into u.bm */
70844
70845 pOut = &aMem[pOp->p2];
70846 memAboutToChange(p, pOut);
70847
70848 /* Note that RowKey and RowData are really exactly the same instruction */
70849 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70850 u.bm.pC = p->apCsr[pOp->p1];
70851 assert( isSorter(u.bm.pC)==0 );
70852 assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
70853 assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData );
70854 assert( u.bm.pC!=0 );
70855 assert( u.bm.pC->nullRow==0 );
70856 assert( u.bm.pC->pseudoTableReg==0 );
70857 assert( u.bm.pC->pCursor!=0 );
70858 u.bm.pCrsr = u.bm.pC->pCursor;
70859 assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) );
70860
70861 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or
70862 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate
70863 ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always
70864 ** a no-op and can never fail. But we leave it in place as a safety.
70865 */
70866 assert( u.bm.pC->deferredMoveto==0 );
70867 rc = sqlite3VdbeCursorMoveto(u.bm.pC);
70868 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70869
70870 if( u.bm.pC->isTable==0 ){
70871 assert( !u.bm.pC->isTable );
70872 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
70873 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70874 if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70875 goto too_big;
70876 }
70877 u.bm.n = (u32)u.bm.n64;
70878 }else{
70879 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bm.pCrsr, &u.bm.n);
70880 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
70881 if( u.bm.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
70882 goto too_big;
70883 }
70884 }
70885 if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
70886 goto no_mem;
70887 }
70888 pOut->n = u.bm.n;
70889 MemSetTypeFlag(pOut, MEM_Blob);
70890 if( u.bm.pC->isTable==0 ){
70891 rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70892 }else{
70893 rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70894 }
70895 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
70896 UPDATE_MAX_BLOBSIZE(pOut);
70897 REGISTER_TRACE(pOp->p2, pOut);
70898 break;
@@ -70633,44 +70907,46 @@
70907 ** P1 can be either an ordinary table or a virtual table. There used to
70908 ** be a separate OP_VRowid opcode for use with virtual tables, but this
70909 ** one opcode now works for both table types.
70910 */
70911 case OP_Rowid: { /* out2-prerelease */
70912 #if 0 /* local variables moved into u.bn */
70913 VdbeCursor *pC;
70914 i64 v;
70915 sqlite3_vtab *pVtab;
70916 const sqlite3_module *pModule;
70917 #endif /* local variables moved into u.bn */
70918
70919 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70920 u.bn.pC = p->apCsr[pOp->p1];
70921 assert( u.bn.pC!=0 );
70922 assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow );
70923 if( u.bn.pC->nullRow ){
70924 pOut->flags = MEM_Null;
70925 break;
70926 }else if( u.bn.pC->deferredMoveto ){
70927 u.bn.v = u.bn.pC->movetoTarget;
70928 #ifndef SQLITE_OMIT_VIRTUALTABLE
70929 }else if( u.bn.pC->pVtabCursor ){
70930 u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab;
70931 u.bn.pModule = u.bn.pVtab->pModule;
70932 assert( u.bn.pModule->xRowid );
70933 rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v);
70934 sqlite3VtabImportErrmsg(p, u.bn.pVtab);
70935 #endif /* SQLITE_OMIT_VIRTUALTABLE */
70936 }else{
70937 assert( u.bn.pC->pCursor!=0 );
70938 rc = sqlite3VdbeCursorMoveto(u.bn.pC);
70939 if( rc ) goto abort_due_to_error;
70940 if( u.bn.pC->rowidIsValid ){
70941 u.bn.v = u.bn.pC->lastRowid;
70942 }else{
70943 rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v);
70944 assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */
70945 }
70946 }
70947 pOut->u.i = u.bn.v;
70948 break;
70949 }
70950
70951 /* Opcode: NullRow P1 * * * *
70952 **
@@ -70677,21 +70953,23 @@
70953 ** Move the cursor P1 to a null row. Any OP_Column operations
70954 ** that occur while the cursor is on the null row will always
70955 ** write a NULL.
70956 */
70957 case OP_NullRow: {
70958 #if 0 /* local variables moved into u.bo */
70959 VdbeCursor *pC;
70960 #endif /* local variables moved into u.bo */
70961
70962 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70963 u.bo.pC = p->apCsr[pOp->p1];
70964 assert( u.bo.pC!=0 );
70965 u.bo.pC->nullRow = 1;
70966 u.bo.pC->rowidIsValid = 0;
70967 u.bo.pC->cacheStatus = CACHE_STALE;
70968 assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
70969 if( u.bo.pC->pCursor ){
70970 sqlite3BtreeClearCursor(u.bo.pC->pCursor);
70971 }
70972 break;
70973 }
70974
70975 /* Opcode: Last P1 P2 * * *
@@ -70701,26 +70979,28 @@
70979 ** If the table or index is empty and P2>0, then jump immediately to P2.
70980 ** If P2 is 0 or if the table or index is not empty, fall through
70981 ** to the following instruction.
70982 */
70983 case OP_Last: { /* jump */
70984 #if 0 /* local variables moved into u.bp */
70985 VdbeCursor *pC;
70986 BtCursor *pCrsr;
70987 int res;
70988 #endif /* local variables moved into u.bp */
70989
70990 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70991 u.bp.pC = p->apCsr[pOp->p1];
70992 assert( u.bp.pC!=0 );
70993 u.bp.pCrsr = u.bp.pC->pCursor;
70994 u.bp.res = 0;
70995 assert( u.bp.pCrsr!=0 );
70996 rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res);
70997 u.bp.pC->nullRow = (u8)u.bp.res;
70998 u.bp.pC->deferredMoveto = 0;
70999 u.bp.pC->rowidIsValid = 0;
71000 u.bp.pC->cacheStatus = CACHE_STALE;
71001 if( pOp->p2>0 && u.bp.res ){
71002 pc = pOp->p2 - 1;
71003 }
71004 break;
71005 }
71006
@@ -70753,32 +71033,34 @@
71033 ** If the table or index is empty and P2>0, then jump immediately to P2.
71034 ** If P2 is 0 or if the table or index is not empty, fall through
71035 ** to the following instruction.
71036 */
71037 case OP_Rewind: { /* jump */
71038 #if 0 /* local variables moved into u.bq */
71039 VdbeCursor *pC;
71040 BtCursor *pCrsr;
71041 int res;
71042 #endif /* local variables moved into u.bq */
71043
71044 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71045 u.bq.pC = p->apCsr[pOp->p1];
71046 assert( u.bq.pC!=0 );
71047 assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) );
71048 u.bq.res = 1;
71049 if( isSorter(u.bq.pC) ){
71050 rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
71051 }else{
71052 u.bq.pCrsr = u.bq.pC->pCursor;
71053 assert( u.bq.pCrsr );
71054 rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
71055 u.bq.pC->deferredMoveto = 0;
71056 u.bq.pC->cacheStatus = CACHE_STALE;
71057 u.bq.pC->rowidIsValid = 0;
71058 }
71059 u.bq.pC->nullRow = (u8)u.bq.res;
71060 assert( pOp->p2>0 && pOp->p2<p->nOp );
71061 if( u.bq.res ){
71062 pc = pOp->p2 - 1;
71063 }
71064 break;
71065 }
71066
@@ -70825,47 +71107,49 @@
71107 **
71108 ** This opcode works just like OP_Prev except that if cursor P1 is not
71109 ** open it behaves a no-op.
71110 */
71111 case OP_SorterNext: { /* jump */
71112 #if 0 /* local variables moved into u.br */
71113 VdbeCursor *pC;
71114 int res;
71115 #endif /* local variables moved into u.br */
71116
71117 u.br.pC = p->apCsr[pOp->p1];
71118 assert( isSorter(u.br.pC) );
71119 rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res);
71120 goto next_tail;
71121 case OP_PrevIfOpen: /* jump */
71122 case OP_NextIfOpen: /* jump */
71123 if( p->apCsr[pOp->p1]==0 ) break;
71124 /* Fall through */
71125 case OP_Prev: /* jump */
71126 case OP_Next: /* jump */
71127 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71128 assert( pOp->p5<ArraySize(p->aCounter) );
71129 u.br.pC = p->apCsr[pOp->p1];
71130 assert( u.br.pC!=0 );
71131 assert( u.br.pC->deferredMoveto==0 );
71132 assert( u.br.pC->pCursor );
71133 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
71134 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
71135 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
71136 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
71137 rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res);
71138 next_tail:
71139 u.br.pC->cacheStatus = CACHE_STALE;
71140 if( u.br.res==0 ){
71141 u.br.pC->nullRow = 0;
71142 pc = pOp->p2 - 1;
71143 p->aCounter[pOp->p5]++;
71144 #ifdef SQLITE_TEST
71145 sqlite3_search_count++;
71146 #endif
71147 }else{
71148 u.br.pC->nullRow = 1;
71149 }
71150 u.br.pC->rowidIsValid = 0;
71151 goto check_for_interrupt;
71152 }
71153
71154 /* Opcode: IdxInsert P1 P2 P3 * P5
71155 ** Synopsis: key=r[P2]
@@ -70880,37 +71164,39 @@
71164 ** This instruction only works for indices. The equivalent instruction
71165 ** for tables is OP_Insert.
71166 */
71167 case OP_SorterInsert: /* in2 */
71168 case OP_IdxInsert: { /* in2 */
71169 #if 0 /* local variables moved into u.bs */
71170 VdbeCursor *pC;
71171 BtCursor *pCrsr;
71172 int nKey;
71173 const char *zKey;
71174 #endif /* local variables moved into u.bs */
71175
71176 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71177 u.bs.pC = p->apCsr[pOp->p1];
71178 assert( u.bs.pC!=0 );
71179 assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) );
71180 pIn2 = &aMem[pOp->p2];
71181 assert( pIn2->flags & MEM_Blob );
71182 u.bs.pCrsr = u.bs.pC->pCursor;
71183 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71184 assert( u.bs.pCrsr!=0 );
71185 assert( u.bs.pC->isTable==0 );
71186 rc = ExpandBlob(pIn2);
71187 if( rc==SQLITE_OK ){
71188 if( isSorter(u.bs.pC) ){
71189 rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2);
71190 }else{
71191 u.bs.nKey = pIn2->n;
71192 u.bs.zKey = pIn2->z;
71193 rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3,
71194 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0)
71195 );
71196 assert( u.bs.pC->deferredMoveto==0 );
71197 u.bs.pC->cacheStatus = CACHE_STALE;
71198 }
71199 }
71200 break;
71201 }
71202
@@ -70920,36 +71206,38 @@
71206 ** The content of P3 registers starting at register P2 form
71207 ** an unpacked index key. This opcode removes that entry from the
71208 ** index opened by cursor P1.
71209 */
71210 case OP_IdxDelete: {
71211 #if 0 /* local variables moved into u.bt */
71212 VdbeCursor *pC;
71213 BtCursor *pCrsr;
71214 int res;
71215 UnpackedRecord r;
71216 #endif /* local variables moved into u.bt */
71217
71218 assert( pOp->p3>0 );
71219 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 );
71220 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71221 u.bt.pC = p->apCsr[pOp->p1];
71222 assert( u.bt.pC!=0 );
71223 u.bt.pCrsr = u.bt.pC->pCursor;
71224 assert( u.bt.pCrsr!=0 );
71225 assert( pOp->p5==0 );
71226 u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo;
71227 u.bt.r.nField = (u16)pOp->p3;
71228 u.bt.r.flags = UNPACKED_PREFIX_MATCH;
71229 u.bt.r.aMem = &aMem[pOp->p2];
71230 #ifdef SQLITE_DEBUG
71231 { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); }
71232 #endif
71233 rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res);
71234 if( rc==SQLITE_OK && u.bt.res==0 ){
71235 rc = sqlite3BtreeDelete(u.bt.pCrsr);
71236 }
71237 assert( u.bt.pC->deferredMoveto==0 );
71238 u.bt.pC->cacheStatus = CACHE_STALE;
71239 break;
71240 }
71241
71242 /* Opcode: IdxRowid P1 P2 * * *
71243 ** Synopsis: r[P2]=rowid
@@ -70959,31 +71247,32 @@
71247 ** the rowid of the table entry to which this index entry points.
71248 **
71249 ** See also: Rowid, MakeRecord.
71250 */
71251 case OP_IdxRowid: { /* out2-prerelease */
71252 #if 0 /* local variables moved into u.bu */
71253 BtCursor *pCrsr;
71254 VdbeCursor *pC;
71255 i64 rowid;
71256 #endif /* local variables moved into u.bu */
71257
71258 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71259 u.bu.pC = p->apCsr[pOp->p1];
71260 assert( u.bu.pC!=0 );
71261 u.bu.pCrsr = u.bu.pC->pCursor;
71262 assert( u.bu.pCrsr!=0 );
71263 pOut->flags = MEM_Null;
71264 rc = sqlite3VdbeCursorMoveto(u.bu.pC);
71265 if( NEVER(rc) ) goto abort_due_to_error;
71266 assert( u.bu.pC->deferredMoveto==0 );
71267 assert( u.bu.pC->isTable==0 );
71268 if( !u.bu.pC->nullRow ){
71269 rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid);
 
71270 if( rc!=SQLITE_OK ){
71271 goto abort_due_to_error;
71272 }
71273 pOut->u.i = u.bu.rowid;
71274 pOut->flags = MEM_Int;
71275 }
71276 break;
71277 }
71278
@@ -71015,42 +71304,43 @@
71304 ** If P5 is non-zero then the key value is increased by an epsilon prior
71305 ** to the comparison. This makes the opcode work like IdxLE.
71306 */
71307 case OP_IdxLT: /* jump */
71308 case OP_IdxGE: { /* jump */
71309 #if 0 /* local variables moved into u.bv */
71310 VdbeCursor *pC;
71311 int res;
71312 UnpackedRecord r;
71313 #endif /* local variables moved into u.bv */
71314
71315 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71316 u.bv.pC = p->apCsr[pOp->p1];
71317 assert( u.bv.pC!=0 );
71318 assert( u.bv.pC->isOrdered );
71319 assert( u.bv.pC->pCursor!=0);
71320 assert( u.bv.pC->deferredMoveto==0 );
71321 assert( pOp->p5==0 || pOp->p5==1 );
71322 assert( pOp->p4type==P4_INT32 );
71323 u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo;
71324 u.bv.r.nField = (u16)pOp->p4.i;
71325 if( pOp->p5 ){
71326 u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71327 }else{
71328 u.bv.r.flags = UNPACKED_PREFIX_MATCH;
71329 }
71330 u.bv.r.aMem = &aMem[pOp->p3];
71331 #ifdef SQLITE_DEBUG
71332 { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); }
71333 #endif
71334 rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res);
 
71335 if( pOp->opcode==OP_IdxLT ){
71336 u.bv.res = -u.bv.res;
71337 }else{
71338 assert( pOp->opcode==OP_IdxGE );
71339 u.bv.res++;
71340 }
71341 if( u.bv.res>0 ){
71342 pc = pOp->p2 - 1 ;
71343 }
71344 break;
71345 }
71346
@@ -71073,46 +71363,47 @@
71363 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
71364 **
71365 ** See also: Clear
71366 */
71367 case OP_Destroy: { /* out2-prerelease */
71368 #if 0 /* local variables moved into u.bw */
71369 int iMoved;
71370 int iCnt;
71371 Vdbe *pVdbe;
71372 int iDb;
71373 #endif /* local variables moved into u.bw */
71374
71375 assert( p->readOnly==0 );
71376 #ifndef SQLITE_OMIT_VIRTUALTABLE
71377 u.bw.iCnt = 0;
71378 for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){
71379 if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader
71380 && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0
71381 ){
71382 u.bw.iCnt++;
71383 }
71384 }
71385 #else
71386 u.bw.iCnt = db->nVdbeRead;
71387 #endif
71388 pOut->flags = MEM_Null;
71389 if( u.bw.iCnt>1 ){
71390 rc = SQLITE_LOCKED;
71391 p->errorAction = OE_Abort;
71392 }else{
71393 u.bw.iDb = pOp->p3;
71394 assert( u.bw.iCnt==1 );
71395 assert( (p->btreeMask & (((yDbMask)1)<<u.bw.iDb))!=0 );
71396 rc = sqlite3BtreeDropTable(db->aDb[u.bw.iDb].pBt, pOp->p1, &u.bw.iMoved);
 
71397 pOut->flags = MEM_Int;
71398 pOut->u.i = u.bw.iMoved;
71399 #ifndef SQLITE_OMIT_AUTOVACUUM
71400 if( rc==SQLITE_OK && u.bw.iMoved!=0 ){
71401 sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1);
71402 /* All OP_Destroy operations occur on the same btree */
71403 assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 );
71404 resetSchemaOnFault = u.bw.iDb+1;
71405 }
71406 #endif
71407 }
71408 break;
71409 }
@@ -71134,25 +71425,27 @@
71425 ** also incremented by the number of rows in the table being cleared.
71426 **
71427 ** See also: Destroy
71428 */
71429 case OP_Clear: {
71430 #if 0 /* local variables moved into u.bx */
71431 int nChange;
71432 #endif /* local variables moved into u.bx */
71433
71434 u.bx.nChange = 0;
71435 assert( p->readOnly==0 );
71436 assert( pOp->p1!=1 );
71437 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71438 rc = sqlite3BtreeClearTable(
71439 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0)
71440 );
71441 if( pOp->p3 ){
71442 p->nChange += u.bx.nChange;
71443 if( pOp->p3>0 ){
71444 assert( memIsValid(&aMem[pOp->p3]) );
71445 memAboutToChange(p, &aMem[pOp->p3]);
71446 aMem[pOp->p3].u.i += u.bx.nChange;
71447 }
71448 }
71449 break;
71450 }
71451
@@ -71180,28 +71473,30 @@
71473 **
71474 ** See documentation on OP_CreateTable for additional information.
71475 */
71476 case OP_CreateIndex: /* out2-prerelease */
71477 case OP_CreateTable: { /* out2-prerelease */
71478 #if 0 /* local variables moved into u.by */
71479 int pgno;
71480 int flags;
71481 Db *pDb;
71482 #endif /* local variables moved into u.by */
71483
71484 u.by.pgno = 0;
71485 assert( pOp->p1>=0 && pOp->p1<db->nDb );
71486 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
71487 assert( p->readOnly==0 );
71488 u.by.pDb = &db->aDb[pOp->p1];
71489 assert( u.by.pDb->pBt!=0 );
71490 if( pOp->opcode==OP_CreateTable ){
71491 /* u.by.flags = BTREE_INTKEY; */
71492 u.by.flags = BTREE_INTKEY;
71493 }else{
71494 u.by.flags = BTREE_BLOBKEY;
71495 }
71496 rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags);
71497 pOut->u.i = u.by.pgno;
71498 break;
71499 }
71500
71501 /* Opcode: ParseSchema P1 * * P4 *
71502 **
@@ -71210,54 +71505,56 @@
71505 **
71506 ** This opcode invokes the parser to create a new virtual machine,
71507 ** then runs the new virtual machine. It is thus a re-entrant opcode.
71508 */
71509 case OP_ParseSchema: {
71510 #if 0 /* local variables moved into u.bz */
71511 int iDb;
71512 const char *zMaster;
71513 char *zSql;
71514 InitData initData;
71515 #endif /* local variables moved into u.bz */
71516
71517 /* Any prepared statement that invokes this opcode will hold mutexes
71518 ** on every btree. This is a prerequisite for invoking
71519 ** sqlite3InitCallback().
71520 */
71521 #ifdef SQLITE_DEBUG
71522 for(u.bz.iDb=0; u.bz.iDb<db->nDb; u.bz.iDb++){
71523 assert( u.bz.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bz.iDb].pBt) );
71524 }
71525 #endif
71526
71527 u.bz.iDb = pOp->p1;
71528 assert( u.bz.iDb>=0 && u.bz.iDb<db->nDb );
71529 assert( DbHasProperty(db, u.bz.iDb, DB_SchemaLoaded) );
71530 /* Used to be a conditional */ {
71531 u.bz.zMaster = SCHEMA_TABLE(u.bz.iDb);
71532 u.bz.initData.db = db;
71533 u.bz.initData.iDb = pOp->p1;
71534 u.bz.initData.pzErrMsg = &p->zErrMsg;
71535 u.bz.zSql = sqlite3MPrintf(db,
71536 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
71537 db->aDb[u.bz.iDb].zName, u.bz.zMaster, pOp->p4.z);
71538 if( u.bz.zSql==0 ){
71539 rc = SQLITE_NOMEM;
71540 }else{
71541 assert( db->init.busy==0 );
71542 db->init.busy = 1;
71543 u.bz.initData.rc = SQLITE_OK;
71544 assert( !db->mallocFailed );
71545 rc = sqlite3_exec(db, u.bz.zSql, sqlite3InitCallback, &u.bz.initData, 0);
71546 if( rc==SQLITE_OK ) rc = u.bz.initData.rc;
71547 sqlite3DbFree(db, u.bz.zSql);
71548 db->init.busy = 0;
71549 }
71550 }
71551 if( rc ) sqlite3ResetAllSchemasOfConnection(db);
71552 if( rc==SQLITE_NOMEM ){
71553 goto no_mem;
71554 }
71555 break;
71556 }
71557
71558 #if !defined(SQLITE_OMIT_ANALYZE)
71559 /* Opcode: LoadAnalysis P1 * * * *
71560 **
@@ -71329,44 +71626,46 @@
71626 ** file, not the main database file.
71627 **
71628 ** This opcode is used to implement the integrity_check pragma.
71629 */
71630 case OP_IntegrityCk: {
71631 #if 0 /* local variables moved into u.ca */
71632 int nRoot; /* Number of tables to check. (Number of root pages.) */
71633 int *aRoot; /* Array of rootpage numbers for tables to be checked */
71634 int j; /* Loop counter */
71635 int nErr; /* Number of errors reported */
71636 char *z; /* Text of the error report */
71637 Mem *pnErr; /* Register keeping track of errors remaining */
71638 #endif /* local variables moved into u.ca */
71639
71640 assert( p->bIsReader );
71641 u.ca.nRoot = pOp->p2;
71642 assert( u.ca.nRoot>0 );
71643 u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) );
71644 if( u.ca.aRoot==0 ) goto no_mem;
71645 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
71646 u.ca.pnErr = &aMem[pOp->p3];
71647 assert( (u.ca.pnErr->flags & MEM_Int)!=0 );
71648 assert( (u.ca.pnErr->flags & (MEM_Str|MEM_Blob))==0 );
71649 pIn1 = &aMem[pOp->p1];
71650 for(u.ca.j=0; u.ca.j<u.ca.nRoot; u.ca.j++){
71651 u.ca.aRoot[u.ca.j] = (int)sqlite3VdbeIntValue(&pIn1[u.ca.j]);
71652 }
71653 u.ca.aRoot[u.ca.j] = 0;
71654 assert( pOp->p5<db->nDb );
71655 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 );
71656 u.ca.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.ca.aRoot, u.ca.nRoot,
71657 (int)u.ca.pnErr->u.i, &u.ca.nErr);
71658 sqlite3DbFree(db, u.ca.aRoot);
71659 u.ca.pnErr->u.i -= u.ca.nErr;
71660 sqlite3VdbeMemSetNull(pIn1);
71661 if( u.ca.nErr==0 ){
71662 assert( u.ca.z==0 );
71663 }else if( u.ca.z==0 ){
71664 goto no_mem;
71665 }else{
71666 sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free);
71667 }
71668 UPDATE_MAX_BLOBSIZE(pIn1);
71669 sqlite3VdbeChangeEncoding(pIn1, encoding);
71670 break;
71671 }
@@ -71398,22 +71697,24 @@
71697 ** Extract the smallest value from boolean index P1 and put that value into
71698 ** register P3. Or, if boolean index P1 is initially empty, leave P3
71699 ** unchanged and jump to instruction P2.
71700 */
71701 case OP_RowSetRead: { /* jump, in1, out3 */
71702 #if 0 /* local variables moved into u.cb */
71703 i64 val;
71704 #endif /* local variables moved into u.cb */
71705
71706 pIn1 = &aMem[pOp->p1];
71707 if( (pIn1->flags & MEM_RowSet)==0
71708 || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0
71709 ){
71710 /* The boolean index is empty */
71711 sqlite3VdbeMemSetNull(pIn1);
71712 pc = pOp->p2 - 1;
71713 }else{
71714 /* A value was pulled from the index */
71715 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val);
71716 }
71717 goto check_for_interrupt;
71718 }
71719
71720 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71439,16 +71740,18 @@
71740 ** inserted, there is no need to search to see if the same value was
71741 ** previously inserted as part of set X (only if it was previously
71742 ** inserted as part of some other set).
71743 */
71744 case OP_RowSetTest: { /* jump, in1, in3 */
71745 #if 0 /* local variables moved into u.cc */
71746 int iSet;
71747 int exists;
71748 #endif /* local variables moved into u.cc */
71749
71750 pIn1 = &aMem[pOp->p1];
71751 pIn3 = &aMem[pOp->p3];
71752 u.cc.iSet = pOp->p4.i;
71753 assert( pIn3->flags&MEM_Int );
71754
71755 /* If there is anything other than a rowset object in memory cell P1,
71756 ** delete it now and initialize P1 with an empty rowset
71757 */
@@ -71456,21 +71759,21 @@
71759 sqlite3VdbeMemSetRowSet(pIn1);
71760 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem;
71761 }
71762
71763 assert( pOp->p4type==P4_INT32 );
71764 assert( u.cc.iSet==-1 || u.cc.iSet>=0 );
71765 if( u.cc.iSet ){
71766 u.cc.exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71767 (u8)(u.cc.iSet>=0 ? u.cc.iSet & 0xf : 0xff),
71768 pIn3->u.i);
71769 if( u.cc.exists ){
71770 pc = pOp->p2 - 1;
71771 break;
71772 }
71773 }
71774 if( u.cc.iSet>=0 ){
71775 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i);
71776 }
71777 break;
71778 }
71779
@@ -71489,109 +71792,111 @@
71792 ** memory required by the sub-vdbe at runtime.
71793 **
71794 ** P4 is a pointer to the VM containing the trigger program.
71795 */
71796 case OP_Program: { /* jump */
71797 #if 0 /* local variables moved into u.cd */
71798 int nMem; /* Number of memory registers for sub-program */
71799 int nByte; /* Bytes of runtime space required for sub-program */
71800 Mem *pRt; /* Register to allocate runtime space */
71801 Mem *pMem; /* Used to iterate through memory cells */
71802 Mem *pEnd; /* Last memory cell in new array */
71803 VdbeFrame *pFrame; /* New vdbe frame to execute in */
71804 SubProgram *pProgram; /* Sub-program to execute */
71805 void *t; /* Token identifying trigger */
71806 #endif /* local variables moved into u.cd */
71807
71808 u.cd.pProgram = pOp->p4.pProgram;
71809 u.cd.pRt = &aMem[pOp->p3];
71810 assert( u.cd.pProgram->nOp>0 );
71811
71812 /* If the p5 flag is clear, then recursive invocation of triggers is
71813 ** disabled for backwards compatibility (p5 is set if this sub-program
71814 ** is really a trigger, not a foreign key action, and the flag set
71815 ** and cleared by the "PRAGMA recursive_triggers" command is clear).
71816 **
71817 ** It is recursive invocation of triggers, at the SQL level, that is
71818 ** disabled. In some cases a single trigger may generate more than one
71819 ** SubProgram (if the trigger may be executed with more than one different
71820 ** ON CONFLICT algorithm). SubProgram structures associated with a
71821 ** single trigger all have the same value for the SubProgram.token
71822 ** variable. */
71823 if( pOp->p5 ){
71824 u.cd.t = u.cd.pProgram->token;
71825 for(u.cd.pFrame=p->pFrame; u.cd.pFrame && u.cd.pFrame->token!=u.cd.t; u.cd.pFrame=u.cd.pFrame->pParent);
71826 if( u.cd.pFrame ) break;
71827 }
71828
71829 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){
71830 rc = SQLITE_ERROR;
71831 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion");
71832 break;
71833 }
71834
71835 /* Register u.cd.pRt is used to store the memory required to save the state
71836 ** of the current program, and the memory required at runtime to execute
71837 ** the trigger program. If this trigger has been fired before, then u.cd.pRt
71838 ** is already allocated. Otherwise, it must be initialized. */
71839 if( (u.cd.pRt->flags&MEM_Frame)==0 ){
71840 /* SubProgram.nMem is set to the number of memory cells used by the
71841 ** program stored in SubProgram.aOp. As well as these, one memory
71842 ** cell is required for each cursor used by the program. Set local
71843 ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value.
71844 */
71845 u.cd.nMem = u.cd.pProgram->nMem + u.cd.pProgram->nCsr;
71846 u.cd.nByte = ROUND8(sizeof(VdbeFrame))
71847 + u.cd.nMem * sizeof(Mem)
71848 + u.cd.pProgram->nCsr * sizeof(VdbeCursor *)
71849 + u.cd.pProgram->nOnce * sizeof(u8);
71850 u.cd.pFrame = sqlite3DbMallocZero(db, u.cd.nByte);
71851 if( !u.cd.pFrame ){
71852 goto no_mem;
71853 }
71854 sqlite3VdbeMemRelease(u.cd.pRt);
71855 u.cd.pRt->flags = MEM_Frame;
71856 u.cd.pRt->u.pFrame = u.cd.pFrame;
71857
71858 u.cd.pFrame->v = p;
71859 u.cd.pFrame->nChildMem = u.cd.nMem;
71860 u.cd.pFrame->nChildCsr = u.cd.pProgram->nCsr;
71861 u.cd.pFrame->pc = pc;
71862 u.cd.pFrame->aMem = p->aMem;
71863 u.cd.pFrame->nMem = p->nMem;
71864 u.cd.pFrame->apCsr = p->apCsr;
71865 u.cd.pFrame->nCursor = p->nCursor;
71866 u.cd.pFrame->aOp = p->aOp;
71867 u.cd.pFrame->nOp = p->nOp;
71868 u.cd.pFrame->token = u.cd.pProgram->token;
71869 u.cd.pFrame->aOnceFlag = p->aOnceFlag;
71870 u.cd.pFrame->nOnceFlag = p->nOnceFlag;
71871
71872 u.cd.pEnd = &VdbeFrameMem(u.cd.pFrame)[u.cd.pFrame->nChildMem];
71873 for(u.cd.pMem=VdbeFrameMem(u.cd.pFrame); u.cd.pMem!=u.cd.pEnd; u.cd.pMem++){
71874 u.cd.pMem->flags = MEM_Invalid;
71875 u.cd.pMem->db = db;
71876 }
71877 }else{
71878 u.cd.pFrame = u.cd.pRt->u.pFrame;
71879 assert( u.cd.pProgram->nMem+u.cd.pProgram->nCsr==u.cd.pFrame->nChildMem );
71880 assert( u.cd.pProgram->nCsr==u.cd.pFrame->nChildCsr );
71881 assert( pc==u.cd.pFrame->pc );
71882 }
71883
71884 p->nFrame++;
71885 u.cd.pFrame->pParent = p->pFrame;
71886 u.cd.pFrame->lastRowid = lastRowid;
71887 u.cd.pFrame->nChange = p->nChange;
71888 p->nChange = 0;
71889 p->pFrame = u.cd.pFrame;
71890 p->aMem = aMem = &VdbeFrameMem(u.cd.pFrame)[-1];
71891 p->nMem = u.cd.pFrame->nChildMem;
71892 p->nCursor = (u16)u.cd.pFrame->nChildCsr;
71893 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
71894 p->aOp = aOp = u.cd.pProgram->aOp;
71895 p->nOp = u.cd.pProgram->nOp;
71896 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
71897 p->nOnceFlag = u.cd.pProgram->nOnce;
71898 pc = -1;
71899 memset(p->aOnceFlag, 0, p->nOnceFlag);
71900
71901 break;
71902 }
@@ -71607,15 +71912,17 @@
71912 ** The address of the cell in the parent frame is determined by adding
71913 ** the value of the P1 argument to the value of the P1 argument to the
71914 ** calling OP_Program instruction.
71915 */
71916 case OP_Param: { /* out2-prerelease */
71917 #if 0 /* local variables moved into u.ce */
71918 VdbeFrame *pFrame;
71919 Mem *pIn;
71920 #endif /* local variables moved into u.ce */
71921 u.ce.pFrame = p->pFrame;
71922 u.ce.pIn = &u.ce.pFrame->aMem[pOp->p1 + u.ce.pFrame->aOp[u.ce.pFrame->pc].p1];
71923 sqlite3VdbeMemShallowCopy(pOut, u.ce.pIn, MEM_Ephem);
71924 break;
71925 }
71926
71927 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
71928
@@ -71672,23 +71979,26 @@
71979 **
71980 ** This instruction throws an error if the memory cell is not initially
71981 ** an integer.
71982 */
71983 case OP_MemMax: { /* in2 */
71984 #if 0 /* local variables moved into u.cf */
71985 Mem *pIn1;
71986 VdbeFrame *pFrame;
71987 #endif /* local variables moved into u.cf */
71988 if( p->pFrame ){
71989 for(u.cf.pFrame=p->pFrame; u.cf.pFrame->pParent; u.cf.pFrame=u.cf.pFrame->pParent);
71990 u.cf.pIn1 = &u.cf.pFrame->aMem[pOp->p1];
71991 }else{
71992 u.cf.pIn1 = &aMem[pOp->p1];
71993 }
71994 assert( memIsValid(u.cf.pIn1) );
71995 sqlite3VdbeMemIntegerify(u.cf.pIn1);
71996 pIn2 = &aMem[pOp->p2];
71997 sqlite3VdbeMemIntegerify(pIn2);
71998 if( u.cf.pIn1->u.i<pIn2->u.i){
71999 u.cf.pIn1->u.i = pIn2->u.i;
72000 }
72001 break;
72002 }
72003 #endif /* SQLITE_OMIT_AUTOINCREMENT */
72004
@@ -71755,58 +72065,60 @@
72065 **
72066 ** The P5 arguments are taken from register P2 and its
72067 ** successors.
72068 */
72069 case OP_AggStep: {
72070 #if 0 /* local variables moved into u.cg */
72071 int n;
72072 int i;
72073 Mem *pMem;
72074 Mem *pRec;
72075 sqlite3_context ctx;
72076 sqlite3_value **apVal;
72077 #endif /* local variables moved into u.cg */
72078
72079 u.cg.n = pOp->p5;
72080 assert( u.cg.n>=0 );
72081 u.cg.pRec = &aMem[pOp->p2];
72082 u.cg.apVal = p->apArg;
72083 assert( u.cg.apVal || u.cg.n==0 );
72084 for(u.cg.i=0; u.cg.i<u.cg.n; u.cg.i++, u.cg.pRec++){
72085 assert( memIsValid(u.cg.pRec) );
72086 u.cg.apVal[u.cg.i] = u.cg.pRec;
72087 memAboutToChange(p, u.cg.pRec);
72088 sqlite3VdbeMemStoreType(u.cg.pRec);
72089 }
72090 u.cg.ctx.pFunc = pOp->p4.pFunc;
72091 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72092 u.cg.ctx.pMem = u.cg.pMem = &aMem[pOp->p3];
72093 u.cg.pMem->n++;
72094 u.cg.ctx.s.flags = MEM_Null;
72095 u.cg.ctx.s.z = 0;
72096 u.cg.ctx.s.zMalloc = 0;
72097 u.cg.ctx.s.xDel = 0;
72098 u.cg.ctx.s.db = db;
72099 u.cg.ctx.isError = 0;
72100 u.cg.ctx.pColl = 0;
72101 u.cg.ctx.skipFlag = 0;
72102 if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
72103 assert( pOp>p->aOp );
72104 assert( pOp[-1].p4type==P4_COLLSEQ );
72105 assert( pOp[-1].opcode==OP_CollSeq );
72106 u.cg.ctx.pColl = pOp[-1].p4.pColl;
72107 }
72108 (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */
72109 if( u.cg.ctx.isError ){
72110 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cg.ctx.s));
72111 rc = u.cg.ctx.isError;
72112 }
72113 if( u.cg.ctx.skipFlag ){
72114 assert( pOp[-1].opcode==OP_CollSeq );
72115 u.cg.i = pOp[-1].p1;
72116 if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1);
72117 }
72118
72119 sqlite3VdbeMemRelease(&u.cg.ctx.s);
72120
72121 break;
72122 }
72123
72124 /* Opcode: AggFinal P1 P2 * P4 *
@@ -71821,21 +72133,23 @@
72133 ** functions that can take varying numbers of arguments. The
72134 ** P4 argument is only needed for the degenerate case where
72135 ** the step function was not previously called.
72136 */
72137 case OP_AggFinal: {
72138 #if 0 /* local variables moved into u.ch */
72139 Mem *pMem;
72140 #endif /* local variables moved into u.ch */
72141 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
72142 u.ch.pMem = &aMem[pOp->p1];
72143 assert( (u.ch.pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
72144 rc = sqlite3VdbeMemFinalize(u.ch.pMem, pOp->p4.pFunc);
72145 if( rc ){
72146 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem));
72147 }
72148 sqlite3VdbeChangeEncoding(u.ch.pMem, encoding);
72149 UPDATE_MAX_BLOBSIZE(u.ch.pMem);
72150 if( sqlite3VdbeMemTooBig(u.ch.pMem) ){
72151 goto too_big;
72152 }
72153 break;
72154 }
72155
@@ -71850,29 +72164,31 @@
72164 ** in the WAL that have been checkpointed after the checkpoint
72165 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
72166 ** mem[P3+2] are initialized to -1.
72167 */
72168 case OP_Checkpoint: {
72169 #if 0 /* local variables moved into u.ci */
72170 int i; /* Loop counter */
72171 int aRes[3]; /* Results */
72172 Mem *pMem; /* Write results here */
72173 #endif /* local variables moved into u.ci */
72174
72175 assert( p->readOnly==0 );
72176 u.ci.aRes[0] = 0;
72177 u.ci.aRes[1] = u.ci.aRes[2] = -1;
72178 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
72179 || pOp->p2==SQLITE_CHECKPOINT_FULL
72180 || pOp->p2==SQLITE_CHECKPOINT_RESTART
72181 );
72182 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]);
72183 if( rc==SQLITE_BUSY ){
72184 rc = SQLITE_OK;
72185 u.ci.aRes[0] = 1;
72186 }
72187 for(u.ci.i=0, u.ci.pMem = &aMem[pOp->p3]; u.ci.i<3; u.ci.i++, u.ci.pMem++){
72188 sqlite3VdbeMemSetInt64(u.ci.pMem, (i64)u.ci.aRes[u.ci.i]);
72189 }
72190 break;
72191 };
72192 #endif
72193
72194 #ifndef SQLITE_OMIT_PRAGMA
@@ -71886,96 +72202,98 @@
72202 ** If changing into or out of WAL mode the procedure is more complicated.
72203 **
72204 ** Write a string containing the final journal-mode to register P2.
72205 */
72206 case OP_JournalMode: { /* out2-prerelease */
72207 #if 0 /* local variables moved into u.cj */
72208 Btree *pBt; /* Btree to change journal mode of */
72209 Pager *pPager; /* Pager associated with pBt */
72210 int eNew; /* New journal mode */
72211 int eOld; /* The old journal mode */
72212 #ifndef SQLITE_OMIT_WAL
72213 const char *zFilename; /* Name of database file for pPager */
72214 #endif
72215 #endif /* local variables moved into u.cj */
72216
72217 u.cj.eNew = pOp->p3;
72218 assert( u.cj.eNew==PAGER_JOURNALMODE_DELETE
72219 || u.cj.eNew==PAGER_JOURNALMODE_TRUNCATE
72220 || u.cj.eNew==PAGER_JOURNALMODE_PERSIST
72221 || u.cj.eNew==PAGER_JOURNALMODE_OFF
72222 || u.cj.eNew==PAGER_JOURNALMODE_MEMORY
72223 || u.cj.eNew==PAGER_JOURNALMODE_WAL
72224 || u.cj.eNew==PAGER_JOURNALMODE_QUERY
72225 );
72226 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72227 assert( p->readOnly==0 );
72228
72229 u.cj.pBt = db->aDb[pOp->p1].pBt;
72230 u.cj.pPager = sqlite3BtreePager(u.cj.pBt);
72231 u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager);
72232 if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld;
72233 if( !sqlite3PagerOkToChangeJournalMode(u.cj.pPager) ) u.cj.eNew = u.cj.eOld;
72234
72235 #ifndef SQLITE_OMIT_WAL
72236 u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1);
72237
72238 /* Do not allow a transition to journal_mode=WAL for a database
72239 ** in temporary storage or if the VFS does not support shared memory
72240 */
72241 if( u.cj.eNew==PAGER_JOURNALMODE_WAL
72242 && (sqlite3Strlen30(u.cj.zFilename)==0 /* Temp file */
72243 || !sqlite3PagerWalSupported(u.cj.pPager)) /* No shared-memory support */
72244 ){
72245 u.cj.eNew = u.cj.eOld;
72246 }
72247
72248 if( (u.cj.eNew!=u.cj.eOld)
72249 && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL)
72250 ){
72251 if( !db->autoCommit || db->nVdbeRead>1 ){
72252 rc = SQLITE_ERROR;
72253 sqlite3SetString(&p->zErrMsg, db,
72254 "cannot change %s wal mode from within a transaction",
72255 (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of")
72256 );
72257 break;
72258 }else{
72259
72260 if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){
72261 /* If leaving WAL mode, close the log file. If successful, the call
72262 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log
72263 ** file. An EXCLUSIVE lock may still be held on the database file
72264 ** after a successful return.
72265 */
72266 rc = sqlite3PagerCloseWal(u.cj.pPager);
72267 if( rc==SQLITE_OK ){
72268 sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
72269 }
72270 }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){
72271 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
72272 ** as an intermediate */
72273 sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF);
72274 }
72275
72276 /* Open a transaction on the database file. Regardless of the journal
72277 ** mode, this transaction always uses a rollback journal.
72278 */
72279 assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 );
72280 if( rc==SQLITE_OK ){
72281 rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
72282 }
72283 }
72284 }
72285 #endif /* ifndef SQLITE_OMIT_WAL */
72286
72287 if( rc ){
72288 u.cj.eNew = u.cj.eOld;
72289 }
72290 u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew);
72291
72292 pOut = &aMem[pOp->p2];
72293 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
72294 pOut->z = (char *)sqlite3JournalModename(u.cj.eNew);
72295 pOut->n = sqlite3Strlen30(pOut->z);
72296 pOut->enc = SQLITE_UTF8;
72297 sqlite3VdbeChangeEncoding(pOut, encoding);
72298 break;
72299 };
@@ -72001,17 +72319,19 @@
72319 ** Perform a single step of the incremental vacuum procedure on
72320 ** the P1 database. If the vacuum has finished, jump to instruction
72321 ** P2. Otherwise, fall through to the next instruction.
72322 */
72323 case OP_IncrVacuum: { /* jump */
72324 #if 0 /* local variables moved into u.ck */
72325 Btree *pBt;
72326 #endif /* local variables moved into u.ck */
72327
72328 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72329 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72330 assert( p->readOnly==0 );
72331 u.ck.pBt = db->aDb[pOp->p1].pBt;
72332 rc = sqlite3BtreeIncrVacuum(u.ck.pBt);
72333 if( rc==SQLITE_DONE ){
72334 pc = pOp->p2 - 1;
72335 rc = SQLITE_OK;
72336 }
72337 break;
@@ -72078,14 +72398,16 @@
72398 ** Also, whether or not P4 is set, check that this is not being called from
72399 ** within a callback to a virtual table xSync() method. If it is, the error
72400 ** code will be set to SQLITE_LOCKED.
72401 */
72402 case OP_VBegin: {
72403 #if 0 /* local variables moved into u.cl */
72404 VTable *pVTab;
72405 #endif /* local variables moved into u.cl */
72406 u.cl.pVTab = pOp->p4.pVtab;
72407 rc = sqlite3VtabBegin(db, u.cl.pVTab);
72408 if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab);
72409 break;
72410 }
72411 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72412
72413 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -72120,34 +72442,36 @@
72442 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72443 ** P1 is a cursor number. This opcode opens a cursor to the virtual
72444 ** table and stores that cursor in P1.
72445 */
72446 case OP_VOpen: {
72447 #if 0 /* local variables moved into u.cm */
72448 VdbeCursor *pCur;
72449 sqlite3_vtab_cursor *pVtabCursor;
72450 sqlite3_vtab *pVtab;
72451 sqlite3_module *pModule;
72452 #endif /* local variables moved into u.cm */
72453
72454 assert( p->bIsReader );
72455 u.cm.pCur = 0;
72456 u.cm.pVtabCursor = 0;
72457 u.cm.pVtab = pOp->p4.pVtab->pVtab;
72458 u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule;
72459 assert(u.cm.pVtab && u.cm.pModule);
72460 rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor);
72461 sqlite3VtabImportErrmsg(p, u.cm.pVtab);
72462 if( SQLITE_OK==rc ){
72463 /* Initialize sqlite3_vtab_cursor base class */
72464 u.cm.pVtabCursor->pVtab = u.cm.pVtab;
72465
72466 /* Initialize vdbe cursor object */
72467 u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72468 if( u.cm.pCur ){
72469 u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
72470 }else{
72471 db->mallocFailed = 1;
72472 u.cm.pModule->xClose(u.cm.pVtabCursor);
72473 }
72474 }
72475 break;
72476 }
72477 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72171,10 +72495,11 @@
72495 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
72496 **
72497 ** A jump is made to P2 if the result set after filtering would be empty.
72498 */
72499 case OP_VFilter: { /* jump */
72500 #if 0 /* local variables moved into u.cn */
72501 int nArg;
72502 int iQuery;
72503 const sqlite3_module *pModule;
72504 Mem *pQuery;
72505 Mem *pArgc;
@@ -72182,48 +72507,49 @@
72507 sqlite3_vtab *pVtab;
72508 VdbeCursor *pCur;
72509 int res;
72510 int i;
72511 Mem **apArg;
72512 #endif /* local variables moved into u.cn */
72513
72514 u.cn.pQuery = &aMem[pOp->p3];
72515 u.cn.pArgc = &u.cn.pQuery[1];
72516 u.cn.pCur = p->apCsr[pOp->p1];
72517 assert( memIsValid(u.cn.pQuery) );
72518 REGISTER_TRACE(pOp->p3, u.cn.pQuery);
72519 assert( u.cn.pCur->pVtabCursor );
72520 u.cn.pVtabCursor = u.cn.pCur->pVtabCursor;
72521 u.cn.pVtab = u.cn.pVtabCursor->pVtab;
72522 u.cn.pModule = u.cn.pVtab->pModule;
72523
72524 /* Grab the index number and argc parameters */
72525 assert( (u.cn.pQuery->flags&MEM_Int)!=0 && u.cn.pArgc->flags==MEM_Int );
72526 u.cn.nArg = (int)u.cn.pArgc->u.i;
72527 u.cn.iQuery = (int)u.cn.pQuery->u.i;
72528
72529 /* Invoke the xFilter method */
72530 {
72531 u.cn.res = 0;
72532 u.cn.apArg = p->apArg;
72533 for(u.cn.i = 0; u.cn.i<u.cn.nArg; u.cn.i++){
72534 u.cn.apArg[u.cn.i] = &u.cn.pArgc[u.cn.i+1];
72535 sqlite3VdbeMemStoreType(u.cn.apArg[u.cn.i]);
72536 }
72537
72538 p->inVtabMethod = 1;
72539 rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg);
72540 p->inVtabMethod = 0;
72541 sqlite3VtabImportErrmsg(p, u.cn.pVtab);
72542 if( rc==SQLITE_OK ){
72543 u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor);
72544 }
72545
72546 if( u.cn.res ){
72547 pc = pOp->p2 - 1;
72548 }
72549 }
72550 u.cn.pCur->nullRow = 0;
72551
72552 break;
72553 }
72554 #endif /* SQLITE_OMIT_VIRTUALTABLE */
72555
@@ -72234,53 +72560,55 @@
72560 ** Store the value of the P2-th column of
72561 ** the row of the virtual-table that the
72562 ** P1 cursor is pointing to into register P3.
72563 */
72564 case OP_VColumn: {
72565 #if 0 /* local variables moved into u.co */
72566 sqlite3_vtab *pVtab;
72567 const sqlite3_module *pModule;
72568 Mem *pDest;
72569 sqlite3_context sContext;
72570 #endif /* local variables moved into u.co */
72571
72572 VdbeCursor *pCur = p->apCsr[pOp->p1];
72573 assert( pCur->pVtabCursor );
72574 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
72575 u.co.pDest = &aMem[pOp->p3];
72576 memAboutToChange(p, u.co.pDest);
72577 if( pCur->nullRow ){
72578 sqlite3VdbeMemSetNull(u.co.pDest);
72579 break;
72580 }
72581 u.co.pVtab = pCur->pVtabCursor->pVtab;
72582 u.co.pModule = u.co.pVtab->pModule;
72583 assert( u.co.pModule->xColumn );
72584 memset(&u.co.sContext, 0, sizeof(u.co.sContext));
72585
72586 /* The output cell may already have a buffer allocated. Move
72587 ** the current contents to u.co.sContext.s so in case the user-function
72588 ** can use the already allocated buffer instead of allocating a
72589 ** new one.
72590 */
72591 sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest);
72592 MemSetTypeFlag(&u.co.sContext.s, MEM_Null);
72593
72594 rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2);
72595 sqlite3VtabImportErrmsg(p, u.co.pVtab);
72596 if( u.co.sContext.isError ){
72597 rc = u.co.sContext.isError;
72598 }
72599
72600 /* Copy the result of the function to the P3 register. We
72601 ** do this regardless of whether or not an error occurred to ensure any
72602 ** dynamic allocation in u.co.sContext.s (a Mem struct) is released.
72603 */
72604 sqlite3VdbeChangeEncoding(&u.co.sContext.s, encoding);
72605 sqlite3VdbeMemMove(u.co.pDest, &u.co.sContext.s);
72606 REGISTER_TRACE(pOp->p3, u.co.pDest);
72607 UPDATE_MAX_BLOBSIZE(u.co.pDest);
72608
72609 if( sqlite3VdbeMemTooBig(u.co.pDest) ){
72610 goto too_big;
72611 }
72612 break;
72613 }
72614 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -72291,40 +72619,42 @@
72619 ** Advance virtual table P1 to the next row in its result set and
72620 ** jump to instruction P2. Or, if the virtual table has reached
72621 ** the end of its result set, then fall through to the next instruction.
72622 */
72623 case OP_VNext: { /* jump */
72624 #if 0 /* local variables moved into u.cp */
72625 sqlite3_vtab *pVtab;
72626 const sqlite3_module *pModule;
72627 int res;
72628 VdbeCursor *pCur;
72629 #endif /* local variables moved into u.cp */
72630
72631 u.cp.res = 0;
72632 u.cp.pCur = p->apCsr[pOp->p1];
72633 assert( u.cp.pCur->pVtabCursor );
72634 if( u.cp.pCur->nullRow ){
72635 break;
72636 }
72637 u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab;
72638 u.cp.pModule = u.cp.pVtab->pModule;
72639 assert( u.cp.pModule->xNext );
72640
72641 /* Invoke the xNext() method of the module. There is no way for the
72642 ** underlying implementation to return an error if one occurs during
72643 ** xNext(). Instead, if an error occurs, true is returned (indicating that
72644 ** data is available) and the error code returned when xColumn or
72645 ** some other method is next invoked on the save virtual table cursor.
72646 */
72647 p->inVtabMethod = 1;
72648 rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor);
72649 p->inVtabMethod = 0;
72650 sqlite3VtabImportErrmsg(p, u.cp.pVtab);
72651 if( rc==SQLITE_OK ){
72652 u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor);
72653 }
72654
72655 if( !u.cp.res ){
72656 /* If there is data, jump to P2 */
72657 pc = pOp->p2 - 1;
72658 }
72659 goto check_for_interrupt;
72660 }
@@ -72336,27 +72666,29 @@
72666 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72667 ** This opcode invokes the corresponding xRename method. The value
72668 ** in register P1 is passed as the zName argument to the xRename method.
72669 */
72670 case OP_VRename: {
72671 #if 0 /* local variables moved into u.cq */
72672 sqlite3_vtab *pVtab;
72673 Mem *pName;
72674 #endif /* local variables moved into u.cq */
72675
72676 u.cq.pVtab = pOp->p4.pVtab->pVtab;
72677 u.cq.pName = &aMem[pOp->p1];
72678 assert( u.cq.pVtab->pModule->xRename );
72679 assert( memIsValid(u.cq.pName) );
72680 assert( p->readOnly==0 );
72681 REGISTER_TRACE(pOp->p1, u.cq.pName);
72682 assert( u.cq.pName->flags & MEM_Str );
72683 testcase( u.cq.pName->enc==SQLITE_UTF8 );
72684 testcase( u.cq.pName->enc==SQLITE_UTF16BE );
72685 testcase( u.cq.pName->enc==SQLITE_UTF16LE );
72686 rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8);
72687 if( rc==SQLITE_OK ){
72688 rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z);
72689 sqlite3VtabImportErrmsg(p, u.cq.pVtab);
72690 p->expired = 0;
72691 }
72692 break;
72693 }
72694 #endif
@@ -72385,44 +72717,46 @@
72717 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72718 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72719 ** is set to the value of the rowid for the row just inserted.
72720 */
72721 case OP_VUpdate: {
72722 #if 0 /* local variables moved into u.cr */
72723 sqlite3_vtab *pVtab;
72724 sqlite3_module *pModule;
72725 int nArg;
72726 int i;
72727 sqlite_int64 rowid;
72728 Mem **apArg;
72729 Mem *pX;
72730 #endif /* local variables moved into u.cr */
72731
72732 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
72733 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
72734 );
72735 assert( p->readOnly==0 );
72736 u.cr.pVtab = pOp->p4.pVtab->pVtab;
72737 u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule;
72738 u.cr.nArg = pOp->p2;
72739 assert( pOp->p4type==P4_VTAB );
72740 if( ALWAYS(u.cr.pModule->xUpdate) ){
72741 u8 vtabOnConflict = db->vtabOnConflict;
72742 u.cr.apArg = p->apArg;
72743 u.cr.pX = &aMem[pOp->p3];
72744 for(u.cr.i=0; u.cr.i<u.cr.nArg; u.cr.i++){
72745 assert( memIsValid(u.cr.pX) );
72746 memAboutToChange(p, u.cr.pX);
72747 sqlite3VdbeMemStoreType(u.cr.pX);
72748 u.cr.apArg[u.cr.i] = u.cr.pX;
72749 u.cr.pX++;
72750 }
72751 db->vtabOnConflict = pOp->p5;
72752 rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid);
72753 db->vtabOnConflict = vtabOnConflict;
72754 sqlite3VtabImportErrmsg(p, u.cr.pVtab);
72755 if( rc==SQLITE_OK && pOp->p1 ){
72756 assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) );
72757 db->lastRowid = lastRowid = u.cr.rowid;
72758 }
72759 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
72760 if( pOp->p5==OE_Ignore ){
72761 rc = SQLITE_OK;
72762 }else{
@@ -72478,36 +72812,38 @@
72812 **
72813 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72814 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72815 */
72816 case OP_Trace: {
72817 #if 0 /* local variables moved into u.cs */
72818 char *zTrace;
72819 char *z;
72820 #endif /* local variables moved into u.cs */
72821
72822 if( db->xTrace
72823 && !p->doingRerun
72824 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72825 ){
72826 u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace);
72827 db->xTrace(db->pTraceArg, u.cs.z);
72828 sqlite3DbFree(db, u.cs.z);
72829 }
72830 #ifdef SQLITE_USE_FCNTL_TRACE
72831 u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql);
72832 if( u.cs.zTrace ){
72833 int i;
72834 for(i=0; i<db->nDb; i++){
72835 if( ((1<<i) & p->btreeMask)==0 ) continue;
72836 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace);
72837 }
72838 }
72839 #endif /* SQLITE_USE_FCNTL_TRACE */
72840 #ifdef SQLITE_DEBUG
72841 if( (db->flags & SQLITE_SqlTrace)!=0
72842 && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72843 ){
72844 sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace);
72845 }
72846 #endif /* SQLITE_DEBUG */
72847 break;
72848 }
72849 #endif
@@ -72632,11 +72968,10 @@
72968 rc = SQLITE_INTERRUPT;
72969 p->rc = rc;
72970 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc));
72971 goto vdbe_error_halt;
72972 }
 
72973
72974 /************** End of vdbe.c ************************************************/
72975 /************** Begin file vdbeblob.c ****************************************/
72976 /*
72977 ** 2007 May 1
@@ -72891,11 +73226,11 @@
73226 sqlite3BtreeLeaveAll(db);
73227 goto blob_open_out;
73228 }
73229 }
73230
73231 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db);
73232 assert( pBlob->pStmt || db->mallocFailed );
73233 if( pBlob->pStmt ){
73234 Vdbe *v = (Vdbe *)pBlob->pStmt;
73235 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73236
@@ -76798,29 +77133,20 @@
77133 }
77134 return p;
77135 }
77136
77137 /*
77138 ** Return 1 if an expression must be FALSE in all cases and 0 if the
77139 ** expression might be true. This is an optimization. If is OK to
77140 ** return 0 here even if the expression really is always false (a
77141 ** false negative). But it is a bug to return 1 if the expression
77142 ** might be true in some rare circumstances (a false positive.)
 
 
 
77143 **
77144 ** Note that if the expression is part of conditional for a
77145 ** LEFT JOIN, then we cannot determine at compile-time whether or not
77146 ** is it true or false, so always return 0.
77147 */
 
 
 
 
 
 
77148 static int exprAlwaysFalse(Expr *p){
77149 int v = 0;
77150 if( ExprHasProperty(p, EP_FromJoin) ) return 0;
77151 if( !sqlite3ExprIsInteger(p, &v) ) return 0;
77152 return v==0;
@@ -78454,15 +78780,10 @@
78780 ** added to the column cache after this call are removed when the
78781 ** corresponding pop occurs.
78782 */
78783 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse *pParse){
78784 pParse->iCacheLevel++;
 
 
 
 
 
78785 }
78786
78787 /*
78788 ** Remove from the column cache any entries that were added since the
78789 ** the previous N Push operations. In other words, restore the cache
@@ -78472,15 +78793,10 @@
78793 int i;
78794 struct yColCache *p;
78795 assert( N>0 );
78796 assert( pParse->iCacheLevel>=N );
78797 pParse->iCacheLevel -= N;
 
 
 
 
 
78798 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
78799 if( p->iReg && p->iLevel>pParse->iCacheLevel ){
78800 cacheEntryClear(pParse, p);
78801 p->iReg = 0;
78802 }
@@ -78571,15 +78887,10 @@
78887 */
78888 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){
78889 int i;
78890 struct yColCache *p;
78891
 
 
 
 
 
78892 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
78893 if( p->iReg ){
78894 cacheEntryClear(pParse, p);
78895 p->iReg = 0;
78896 }
@@ -79663,11 +79974,11 @@
79974 sqlite3ExplainPush(pOut);
79975 for(i=0; i<pList->nExpr; i++){
79976 sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
79977 sqlite3ExplainPush(pOut);
79978 sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
79979 sqlite3ExplainPop(pOut);
79980 if( pList->a[i].zName ){
79981 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
79982 }
79983 if( pList->a[i].bSpanIsTab ){
79984 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
@@ -79712,21 +80023,11 @@
80023 if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
80024 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
80025 }else{
80026 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
80027 if( inReg!=target+i ){
80028 sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i);
 
 
 
 
 
 
 
 
 
 
80029 }
80030 }
80031 }
80032 return n;
80033 }
@@ -79813,23 +80114,21 @@
80114 op = pExpr->op;
80115 switch( op ){
80116 case TK_AND: {
80117 int d2 = sqlite3VdbeMakeLabel(v);
80118 testcase( jumpIfNull==0 );
 
80119 sqlite3ExprCachePush(pParse);
80120 sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL);
80121 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
80122 sqlite3VdbeResolveLabel(v, d2);
80123 sqlite3ExprCachePop(pParse, 1);
80124 break;
80125 }
80126 case TK_OR: {
80127 testcase( jumpIfNull==0 );
80128 sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull);
 
80129 sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull);
 
80130 break;
80131 }
80132 case TK_NOT: {
80133 testcase( jumpIfNull==0 );
80134 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
@@ -79900,20 +80199,14 @@
80199 sqlite3VdbeResolveLabel(v, destIfFalse);
80200 break;
80201 }
80202 #endif
80203 default: {
80204 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80205 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
80206 testcase( regFree1==0 );
80207 testcase( jumpIfNull==0 );
 
 
 
 
 
 
80208 break;
80209 }
80210 }
80211 sqlite3ReleaseTempReg(pParse, regFree1);
80212 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -79972,20 +80265,18 @@
80265
80266 switch( pExpr->op ){
80267 case TK_AND: {
80268 testcase( jumpIfNull==0 );
80269 sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull);
 
80270 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
 
80271 break;
80272 }
80273 case TK_OR: {
80274 int d2 = sqlite3VdbeMakeLabel(v);
80275 testcase( jumpIfNull==0 );
 
80276 sqlite3ExprCachePush(pParse);
80277 sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL);
80278 sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull);
80279 sqlite3VdbeResolveLabel(v, d2);
80280 sqlite3ExprCachePop(pParse, 1);
80281 break;
80282 }
@@ -80053,20 +80344,14 @@
80344 }
80345 break;
80346 }
80347 #endif
80348 default: {
80349 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80350 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80351 testcase( regFree1==0 );
80352 testcase( jumpIfNull==0 );
 
 
 
 
 
 
80353 break;
80354 }
80355 }
80356 sqlite3ReleaseTempReg(pParse, regFree1);
80357 sqlite3ReleaseTempReg(pParse, regFree2);
@@ -83162,10 +83447,14 @@
83447 {
83448 int rc = SQLITE_OK;
83449 if( pExpr ){
83450 if( pExpr->op!=TK_ID ){
83451 rc = sqlite3ResolveExprNames(pName, pExpr);
83452 if( rc==SQLITE_OK && !sqlite3ExprIsConstant(pExpr) ){
83453 sqlite3ErrorMsg(pName->pParse, "invalid name: \"%s\"", pExpr->u.zToken);
83454 return SQLITE_ERROR;
83455 }
83456 }else{
83457 pExpr->op = TK_STRING;
83458 }
83459 }
83460 return rc;
@@ -87940,13 +88229,13 @@
88229 sqlite3StrAccumInit(&errMsg, 0, 0, 200);
88230 errMsg.db = pParse->db;
88231 for(j=0; j<pIdx->nKeyCol; j++){
88232 char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
88233 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
88234 sqlite3StrAccumAppend(&errMsg, pTab->zName, -1);
88235 sqlite3StrAccumAppend(&errMsg, ".", 1);
88236 sqlite3StrAccumAppend(&errMsg, zCol, -1);
88237 }
88238 zErr = sqlite3StrAccumFinish(&errMsg);
88239 sqlite3HaltConstraint(pParse,
88240 (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE,
88241 onError, zErr, P4_DYNAMIC, P5_ConstraintUnique);
@@ -88134,13 +88423,12 @@
88423 }
88424 if( pKey ){
88425 assert( sqlite3KeyInfoIsWriteable(pKey) );
88426 for(i=0; i<nCol; i++){
88427 char *zColl = pIdx->azColl[i];
88428 if( NEVER(zColl==0) ) zColl = "BINARY";
88429 pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl);
 
88430 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
88431 }
88432 if( pParse->nErr ){
88433 sqlite3KeyInfoUnref(pKey);
88434 }else{
@@ -88509,10 +88797,11 @@
88797 int bestScore = 0; /* Score of best match */
88798 int h; /* Hash value */
88799
88800 assert( nArg>=(-2) );
88801 assert( nArg>=(-1) || createFlag==0 );
88802 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
88803 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
88804
88805 /* First search for a match amongst the application-defined functions.
88806 */
88807 p = functionSearch(&db->aFunc, h, zName, nName);
@@ -89399,10 +89688,11 @@
89688 Vdbe *v = pParse->pVdbe;
89689 int j;
89690 Table *pTab = pIdx->pTable;
89691 int regBase;
89692 int nCol;
89693 Index *pPk;
89694
89695 if( piPartIdxLabel ){
89696 if( pIdx->pPartIdxWhere ){
89697 *piPartIdxLabel = sqlite3VdbeMakeLabel(v);
89698 pParse->iPartIdxTab = iDataCur;
@@ -89412,25 +89702,32 @@
89702 *piPartIdxLabel = 0;
89703 }
89704 }
89705 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
89706 regBase = sqlite3GetTempRange(pParse, nCol);
89707 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
89708 for(j=0; j<nCol; j++){
89709 i16 idx = pIdx->aiColumn[j];
89710 if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx);
89711 if( idx<0 || idx==pTab->iPKey ){
89712 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j);
89713 }else{
89714 sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j);
89715 sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1);
 
 
 
89716 }
89717 }
89718 if( regOut ){
89719 const char *zAff;
89720 if( pTab->pSelect
89721 || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt)
89722 ){
89723 zAff = 0;
89724 }else{
89725 zAff = sqlite3IndexAffinityStr(v, pIdx);
89726 }
89727 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
89728 sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
89729 }
89730 sqlite3ReleaseTempRange(pParse, regBase, nCol);
89731 return regBase;
89732 }
89733
@@ -89652,36 +89949,10 @@
89949 }
89950 if( nNeedle>nHaystack ) N = 0;
89951 sqlite3_result_int(context, N);
89952 }
89953
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89954 /*
89955 ** Implementation of the substr() function.
89956 **
89957 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
89958 ** p1 is 1-indexed. So substr(x,1,1) returns the first character
@@ -90971,15 +91242,15 @@
91242 nSep = sqlite3_value_bytes(argv[1]);
91243 }else{
91244 zSep = ",";
91245 nSep = 1;
91246 }
91247 sqlite3StrAccumAppend(pAccum, zSep, nSep);
91248 }
91249 zVal = (char*)sqlite3_value_text(argv[0]);
91250 nVal = sqlite3_value_bytes(argv[0]);
91251 sqlite3StrAccumAppend(pAccum, zVal, nVal);
91252 }
91253 }
91254 static void groupConcatFinalize(sqlite3_context *context){
91255 StrAccum *pAccum;
91256 pAccum = sqlite3_aggregate_context(context, 0);
@@ -91108,11 +91379,10 @@
91379 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
91380 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
91381 FUNCTION(instr, 2, 0, 0, instrFunc ),
91382 FUNCTION(substr, 2, 0, 0, substrFunc ),
91383 FUNCTION(substr, 3, 0, 0, substrFunc ),
 
91384 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
91385 FUNCTION(char, -1, 0, 0, charFunc ),
91386 FUNCTION(abs, 1, 0, 0, absFunc ),
91387 #ifndef SQLITE_OMIT_FLOATING_POINT
91388 FUNCTION(round, 1, 0, 0, roundFunc ),
@@ -93779,11 +94049,10 @@
94049 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
94050 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
94051 int ipkTop = 0; /* Top of the rowid change constraint check */
94052 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
94053 u8 isUpdate; /* True if this is an UPDATE operation */
 
94054
94055 isUpdate = regOldData!=0;
94056 db = pParse->db;
94057 v = sqlite3GetVdbe(pParse);
94058 assert( v!=0 );
@@ -94010,13 +94279,11 @@
94279 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
94280 for(i=0; i<pIdx->nColumn; i++){
94281 int iField = pIdx->aiColumn[i];
94282 int x;
94283 if( iField<0 || iField==pTab->iPKey ){
 
94284 x = regNewData;
 
94285 }else{
94286 x = iField + regNewData + 1;
94287 }
94288 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94289 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
@@ -94052,53 +94319,51 @@
94319 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94320 regIdx, pIdx->nKeyCol);
94321
94322 /* Generate code to handle collisions */
94323 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94324 if( HasRowid(pTab) ){
94325 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94326 /* Conflict only if the rowid of the existing index entry
94327 ** is different from old-rowid */
94328 if( isUpdate ){
94329 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94330 }
94331 }else{
94332 int x;
94333 /* Extract the PRIMARY KEY from the end of the index entry and
94334 ** store it in registers regR..regR+nPk-1 */
94335 if( (isUpdate || onError==OE_Replace) && pIdx!=pPk ){
94336 for(i=0; i<pPk->nKeyCol; i++){
94337 x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
94338 sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i);
94339 VdbeComment((v, "%s.%s", pTab->zName,
94340 pTab->aCol[pPk->aiColumn[i]].zName));
94341 }
94342 }
94343 if( isUpdate ){
94344 /* If currently processing the PRIMARY KEY of a WITHOUT ROWID
94345 ** table, only conflict if the new PRIMARY KEY values are actually
94346 ** different from the old.
94347 **
94348 ** For a UNIQUE index, only conflict if the PRIMARY KEY values
94349 ** of the matched index row are different from the original PRIMARY
94350 ** KEY values of this row before the update. */
94351 int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol;
94352 int op = OP_Ne;
94353 int regCmp = (pIdx->autoIndex==2 ? regIdx : regR);
94354
94355 for(i=0; i<pPk->nKeyCol; i++){
94356 char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]);
94357 x = pPk->aiColumn[i];
94358 if( i==(pPk->nKeyCol-1) ){
94359 addrJump = addrUniqueOk;
94360 op = OP_Eq;
94361 }
94362 sqlite3VdbeAddOp4(v, op,
94363 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94364 );
 
 
94365 }
94366 }
94367 }
94368
94369 /* Generate code that executes if the new index entry is not unique */
@@ -98841,15 +99106,11 @@
99106
99107 /*
99108 ** Free all memory allocations in the pParse object
99109 */
99110 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
99111 if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr);
 
 
 
 
99112 }
99113
99114 /*
99115 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
99116 */
@@ -99798,10 +100059,11 @@
100059 }
100060 }else if( eDest!=SRT_Exists ){
100061 /* If the destination is an EXISTS(...) expression, the actual
100062 ** values returned by the SELECT are not required.
100063 */
100064 sqlite3ExprCacheClear(pParse);
100065 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100066 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100067 }
100068 nColumn = nResultCol;
100069
@@ -100764,11 +101026,11 @@
101026 ** If an error occurs, return NULL and leave a message in pParse.
101027 */
101028 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
101029 Vdbe *v = pParse->pVdbe;
101030 if( v==0 ){
101031 v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db);
101032 #ifndef SQLITE_OMIT_TRACE
101033 if( v ){
101034 sqlite3VdbeAddOp0(v, OP_Trace);
101035 }
101036 #endif
@@ -103022,27 +103284,18 @@
103284 */
103285 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
103286 Vdbe *v = pParse->pVdbe;
103287 int i;
103288 struct AggInfo_func *pFunc;
103289 if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){
103290 return;
103291 }
 
 
 
103292 for(i=0; i<pAggInfo->nColumn; i++){
103293 sqlite3VdbeAddOp2(v, OP_Null, 0, pAggInfo->aCol[i].iMem);
103294 }
 
 
 
 
 
 
 
103295 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
103296 sqlite3VdbeAddOp2(v, OP_Null, 0, pFunc->iMem);
103297 if( pFunc->iDistinct>=0 ){
103298 Expr *pE = pFunc->pExpr;
103299 assert( !ExprHasProperty(pE, EP_xIsSelect) );
103300 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
103301 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
@@ -103084,10 +103337,11 @@
103337 int addrHitTest = 0;
103338 struct AggInfo_func *pF;
103339 struct AggInfo_col *pC;
103340
103341 pAggInfo->directMode = 1;
103342 sqlite3ExprCacheClear(pParse);
103343 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
103344 int nArg;
103345 int addrNext = 0;
103346 int regAgg;
103347 ExprList *pList = pF->pExpr->x.pList;
@@ -103616,11 +103870,10 @@
103870 */
103871 memset(&sNC, 0, sizeof(sNC));
103872 sNC.pParse = pParse;
103873 sNC.pSrcList = pTabList;
103874 sNC.pAggInfo = &sAggInfo;
 
103875 sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0;
103876 sAggInfo.pGroupBy = pGroupBy;
103877 sqlite3ExprAnalyzeAggList(&sNC, pEList);
103878 sqlite3ExprAnalyzeAggList(&sNC, pOrderBy);
103879 if( pHaving ){
@@ -103631,11 +103884,10 @@
103884 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
103885 sNC.ncFlags |= NC_InAggFunc;
103886 sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList);
103887 sNC.ncFlags &= ~NC_InAggFunc;
103888 }
 
103889 if( db->mallocFailed ) goto select_end;
103890
103891 /* Processing for aggregates with GROUP BY is very different and
103892 ** much more complex than aggregates without a GROUP BY.
103893 */
@@ -105536,11 +105788,11 @@
105788 pCol->affinity, &pValue);
105789 if( pValue ){
105790 sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM);
105791 }
105792 #ifndef SQLITE_OMIT_FLOATING_POINT
105793 if( iReg>=0 && pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
105794 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
105795 }
105796 #endif
105797 }
105798 }
@@ -105960,14 +106212,14 @@
106212 ** be used eliminates some redundant opcodes.
106213 */
106214 newmask = sqlite3TriggerColmask(
106215 pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError
106216 );
106217 sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);
106218 for(i=0; i<pTab->nCol; i++){
106219 if( i==pTab->iPKey ){
106220 /*sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);*/
106221 }else{
106222 j = aXRef[i];
106223 if( j>=0 ){
106224 sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i);
106225 }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask&(1<<i)) ){
@@ -105977,12 +106229,10 @@
106229 ** a new.* reference in a trigger program.
106230 */
106231 testcase( i==31 );
106232 testcase( i==32 );
106233 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i);
 
 
106234 }
106235 }
106236 }
106237
106238 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
@@ -110731,11 +110981,11 @@
110981 int iTerm, /* Index of this term. First is zero */
110982 const char *zColumn, /* Name of the column */
110983 const char *zOp /* Name of the operator */
110984 ){
110985 if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5);
110986 sqlite3StrAccumAppend(pStr, zColumn, -1);
110987 sqlite3StrAccumAppend(pStr, zOp, 1);
110988 sqlite3StrAccumAppend(pStr, "?", 1);
110989 }
110990
110991 /*
@@ -110777,11 +111027,11 @@
111027 if( i>=nSkip ){
111028 explainAppendTerm(&txt, i, z, "=");
111029 }else{
111030 if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5);
111031 sqlite3StrAccumAppend(&txt, "ANY(", 4);
111032 sqlite3StrAccumAppend(&txt, z, -1);
111033 sqlite3StrAccumAppend(&txt, ")", 1);
111034 }
111035 }
111036
111037 j = i;
@@ -113593,16 +113843,13 @@
113843 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
113844
113845 /* Special case: a WHERE clause that is constant. Evaluate the
113846 ** expression and either jump over all of the code or fall thru.
113847 */
113848 if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){
113849 sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL);
113850 pWhere = 0;
 
 
 
113851 }
113852
113853 /* Special case: No FROM clause
113854 */
113855 if( nTabList==0 ){
@@ -119339,12 +119586,11 @@
119586 }
119587 db->lookaside.pEnd = p;
119588 db->lookaside.bEnabled = 1;
119589 db->lookaside.bMalloced = pBuf==0 ?1:0;
119590 }else{
119591 db->lookaside.pEnd = 0;
 
119592 db->lookaside.bEnabled = 0;
119593 db->lookaside.bMalloced = 0;
119594 }
119595 return SQLITE_OK;
119596 }
@@ -119738,11 +119984,13 @@
119984 }
119985 sqlite3HashClear(&db->aModule);
119986 #endif
119987
119988 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
119989 if( db->pErr ){
119990 sqlite3ValueFree(db->pErr);
119991 }
119992 sqlite3CloseExtensions(db);
119993
119994 db->magic = SQLITE_MAGIC_ERROR;
119995
119996 /* The temp-database schema is allocated differently from the other schema
@@ -119813,11 +120061,12 @@
120061
120062 /*
120063 ** Return a static string containing the name corresponding to the error code
120064 ** specified in the argument.
120065 */
120066 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \
120067 defined(SQLITE_DEBUG_OS_TRACE)
120068 SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
120069 const char *zName = 0;
120070 int i, origRc = rc;
120071 for(i=0; i<2 && zName==0; i++, rc &= 0xff){
120072 switch( rc ){
@@ -119835,11 +120084,10 @@
120084 case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
120085 case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
120086 case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break;
120087 case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break;
120088 case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break;
 
120089 case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
120090 case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
120091 case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break;
120092 case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break;
120093 case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break;
@@ -120120,11 +120368,10 @@
120368 void (*xFinal)(sqlite3_context*),
120369 FuncDestructor *pDestructor
120370 ){
120371 FuncDef *p;
120372 int nName;
 
120373
120374 assert( sqlite3_mutex_held(db->mutex) );
120375 if( zFunctionName==0 ||
120376 (xFunc && (xFinal || xStep)) ||
120377 (!xFunc && (xFinal && !xStep)) ||
@@ -120131,14 +120378,10 @@
120378 (!xFunc && (!xFinal && xStep)) ||
120379 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
120380 (255<(nName = sqlite3Strlen30( zFunctionName))) ){
120381 return SQLITE_MISUSE_BKPT;
120382 }
 
 
 
 
120383
120384 #ifndef SQLITE_OMIT_UTF16
120385 /* If SQLITE_UTF16 is specified as the encoding type, transform this
120386 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
120387 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -120148,14 +120391,14 @@
120391 */
120392 if( enc==SQLITE_UTF16 ){
120393 enc = SQLITE_UTF16NATIVE;
120394 }else if( enc==SQLITE_ANY ){
120395 int rc;
120396 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
120397 pUserData, xFunc, xStep, xFinal, pDestructor);
120398 if( rc==SQLITE_OK ){
120399 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
120400 pUserData, xFunc, xStep, xFinal, pDestructor);
120401 }
120402 if( rc!=SQLITE_OK ){
120403 return rc;
120404 }
@@ -120194,12 +120437,11 @@
120437
120438 if( pDestructor ){
120439 pDestructor->nRef++;
120440 }
120441 p->pDestructor = pDestructor;
120442 p->funcFlags &= SQLITE_FUNC_ENCMASK;
 
120443 p->xFunc = xFunc;
120444 p->xStep = xStep;
120445 p->xFinalize = xFinal;
120446 p->pUserData = pUserData;
120447 p->nArg = (u16)nArg;
@@ -120625,11 +120867,10 @@
120867 }
120868 sqlite3_mutex_enter(db->mutex);
120869 if( db->mallocFailed ){
120870 z = sqlite3ErrStr(SQLITE_NOMEM);
120871 }else{
 
120872 z = (char*)sqlite3_value_text(db->pErr);
120873 assert( !db->mallocFailed );
120874 if( z==0 ){
120875 z = sqlite3ErrStr(db->errCode);
120876 }
@@ -120667,11 +120908,12 @@
120908 if( db->mallocFailed ){
120909 z = (void *)outOfMem;
120910 }else{
120911 z = sqlite3_value_text16(db->pErr);
120912 if( z==0 ){
120913 sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
120914 SQLITE_UTF8, SQLITE_STATIC);
120915 z = sqlite3_value_text16(db->pErr);
120916 }
120917 /* A malloc() may have failed within the call to sqlite3_value_text16()
120918 ** above. If this is the case, then the db->mallocFailed flag needs to
120919 ** be cleared before returning. Do this directly, instead of via
@@ -121380,10 +121622,12 @@
121622 #ifdef SQLITE_ENABLE_RTREE
121623 if( !db->mallocFailed && rc==SQLITE_OK){
121624 rc = sqlite3RtreeInit(db);
121625 }
121626 #endif
121627
121628 sqlite3Error(db, rc, 0);
121629
121630 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
121631 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
121632 ** mode. Doing nothing at all also makes NORMAL the default.
121633 */
@@ -121391,12 +121635,10 @@
121635 db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE;
121636 sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt),
121637 SQLITE_DEFAULT_LOCKING_MODE);
121638 #endif
121639
 
 
121640 /* Enable the lookaside-malloc subsystem */
121641 setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside,
121642 sqlite3GlobalConfig.nLookaside);
121643
121644 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
@@ -121852,11 +122094,11 @@
122094 ** Reset the PRNG back to its uninitialized state. The next call
122095 ** to sqlite3_randomness() will reseed the PRNG using a single call
122096 ** to the xRandomness method of the default VFS.
122097 */
122098 case SQLITE_TESTCTRL_PRNG_RESET: {
122099 sqlite3PrngResetState();
122100 break;
122101 }
122102
122103 /*
122104 ** sqlite3_test_control(BITVEC_TEST, size, program)
@@ -124836,23 +125078,10 @@
125078 char **pzErr /* OUT: sqlite3_malloc'd error message */
125079 ){
125080 return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr);
125081 }
125082
 
 
 
 
 
 
 
 
 
 
 
 
 
125083 /*
125084 ** Implementation of the xBestIndex method for FTS3 tables. There
125085 ** are three possible strategies, in order of preference:
125086 **
125087 ** 1. Direct lookup by rowid or docid.
@@ -124876,24 +125105,11 @@
125105 pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
125106 pInfo->estimatedCost = 5000000;
125107 for(i=0; i<pInfo->nConstraint; i++){
125108 int bDocid; /* True if this constraint is on docid */
125109 struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
125110 if( pCons->usable==0 ) continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
125111
125112 bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
125113
125114 /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
125115 if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
@@ -131750,74 +131966,61 @@
131966 }
131967
131968 /* Step 2 */
131969 switch( z[1] ){
131970 case 'a':
131971 stem(&z, "lanoita", "ate", m_gt_0) ||
131972 stem(&z, "lanoit", "tion", m_gt_0);
 
131973 break;
131974 case 'c':
131975 stem(&z, "icne", "ence", m_gt_0) ||
131976 stem(&z, "icna", "ance", m_gt_0);
 
131977 break;
131978 case 'e':
131979 stem(&z, "rezi", "ize", m_gt_0);
131980 break;
131981 case 'g':
131982 stem(&z, "igol", "log", m_gt_0);
131983 break;
131984 case 'l':
131985 stem(&z, "ilb", "ble", m_gt_0) ||
131986 stem(&z, "illa", "al", m_gt_0) ||
131987 stem(&z, "iltne", "ent", m_gt_0) ||
131988 stem(&z, "ile", "e", m_gt_0) ||
131989 stem(&z, "ilsuo", "ous", m_gt_0);
 
 
131990 break;
131991 case 'o':
131992 stem(&z, "noitazi", "ize", m_gt_0) ||
131993 stem(&z, "noita", "ate", m_gt_0) ||
131994 stem(&z, "rota", "ate", m_gt_0);
 
 
131995 break;
131996 case 's':
131997 stem(&z, "msila", "al", m_gt_0) ||
131998 stem(&z, "ssenevi", "ive", m_gt_0) ||
131999 stem(&z, "ssenluf", "ful", m_gt_0) ||
132000 stem(&z, "ssensuo", "ous", m_gt_0);
 
 
132001 break;
132002 case 't':
132003 stem(&z, "itila", "al", m_gt_0) ||
132004 stem(&z, "itivi", "ive", m_gt_0) ||
132005 stem(&z, "itilib", "ble", m_gt_0);
 
 
132006 break;
132007 }
132008
132009 /* Step 3 */
132010 switch( z[0] ){
132011 case 'e':
132012 stem(&z, "etaci", "ic", m_gt_0) ||
132013 stem(&z, "evita", "", m_gt_0) ||
132014 stem(&z, "ezila", "al", m_gt_0);
 
 
132015 break;
132016 case 'i':
132017 stem(&z, "itici", "ic", m_gt_0);
132018 break;
132019 case 'l':
132020 stem(&z, "laci", "ic", m_gt_0) ||
132021 stem(&z, "luf", "", m_gt_0);
 
132022 break;
132023 case 's':
132024 stem(&z, "ssen", "", m_gt_0);
132025 break;
132026 }
@@ -131854,15 +132057,13 @@
132057 if( z[2]=='a' ){
132058 if( m_gt_1(z+3) ){
132059 z += 3;
132060 }
132061 }else if( z[2]=='e' ){
132062 stem(&z, "tneme", "", m_gt_1) ||
132063 stem(&z, "tnem", "", m_gt_1) ||
132064 stem(&z, "tne", "", m_gt_1);
 
 
132065 }
132066 }
132067 break;
132068 case 'o':
132069 if( z[0]=='u' ){
@@ -131877,13 +132078,12 @@
132078 if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
132079 z += 3;
132080 }
132081 break;
132082 case 't':
132083 stem(&z, "eta", "", m_gt_1) ||
132084 stem(&z, "iti", "", m_gt_1);
 
132085 break;
132086 case 'u':
132087 if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
132088 z += 3;
132089 }
132090
+25 -71
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.8.3"
111
-#define SQLITE_VERSION_NUMBER 3008003
112
-#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
110
+#define SQLITE_VERSION "3.8.2"
111
+#define SQLITE_VERSION_NUMBER 3008002
112
+#define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -489,11 +489,10 @@
489489
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490490
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491491
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492492
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493493
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
494
-#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
495494
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
496495
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
497496
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
498497
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
499498
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -557,12 +556,11 @@
557556
** information is written to disk in the same order as calls
558557
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
559558
** after reboot following a crash or power loss, the only bytes in a
560559
** file that were written at the application level might have changed
561560
** and that adjacent bytes, even bytes within the same sector are
562
-** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
563
-** flag indicate that a file cannot be deleted when open.
561
+** guaranteed to be unchanged.
564562
*/
565563
#define SQLITE_IOCAP_ATOMIC 0x00000001
566564
#define SQLITE_IOCAP_ATOMIC512 0x00000002
567565
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
568566
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -789,33 +787,19 @@
789787
** to the [sqlite3_file] object associated with a particular database
790788
** connection. See the [sqlite3_file_control()] documentation for
791789
** additional information.
792790
**
793791
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
794
-** No longer in use.
795
-**
796
-** <li>[[SQLITE_FCNTL_SYNC]]
797
-** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
798
-** sent to the VFS immediately before the xSync method is invoked on a
799
-** database file descriptor. Or, if the xSync method is not invoked
800
-** because the user has configured SQLite with
801
-** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
802
-** of the xSync method. In most cases, the pointer argument passed with
803
-** this file-control is NULL. However, if the database file is being synced
804
-** as part of a multi-database commit, the argument points to a nul-terminated
805
-** string containing the transactions master-journal file name. VFSes that
806
-** do not need this signal should silently ignore this opcode. Applications
807
-** should not call [sqlite3_file_control()] with this opcode as doing so may
808
-** disrupt the operation of the specialized VFSes that do require it.
809
-**
810
-** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
811
-** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
812
-** and sent to the VFS after a transaction has been committed immediately
813
-** but before the database is unlocked. VFSes that do not need this signal
814
-** should silently ignore this opcode. Applications should not call
815
-** [sqlite3_file_control()] with this opcode as doing so may disrupt the
816
-** operation of the specialized VFSes that do require it.
792
+** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
793
+** SQLite and sent to all VFSes in place of a call to the xSync method
794
+** when the database connection has [PRAGMA synchronous] set to OFF.)^
795
+** Some specialized VFSes need this signal in order to operate correctly
796
+** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
797
+** VFSes do not need this signal and should silently ignore this opcode.
798
+** Applications should not call [sqlite3_file_control()] with this
799
+** opcode as doing so may disrupt the operation of the specialized VFSes
800
+** that do require it.
817801
**
818802
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
819803
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
820804
** retry counts and intervals for certain disk I/O operations for the
821805
** windows [VFS] in order to provide robustness in the presence of
@@ -935,16 +919,10 @@
935919
** This file control is used by some VFS activity tracing [shims].
936920
** The argument is a zero-terminated string. Higher layers in the
937921
** SQLite stack may generate instances of this file control if
938922
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
939923
**
940
-** <li>[[SQLITE_FCNTL_HAS_MOVED]]
941
-** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
942
-** pointer to an integer and it writes a boolean into that integer depending
943
-** on whether or not the file has been renamed, moved, or deleted since it
944
-** was first opened.
945
-**
946924
** </ul>
947925
*/
948926
#define SQLITE_FCNTL_LOCKSTATE 1
949927
#define SQLITE_GET_LOCKPROXYFILE 2
950928
#define SQLITE_SET_LOCKPROXYFILE 3
@@ -961,13 +939,10 @@
961939
#define SQLITE_FCNTL_PRAGMA 14
962940
#define SQLITE_FCNTL_BUSYHANDLER 15
963941
#define SQLITE_FCNTL_TEMPFILENAME 16
964942
#define SQLITE_FCNTL_MMAP_SIZE 18
965943
#define SQLITE_FCNTL_TRACE 19
966
-#define SQLITE_FCNTL_HAS_MOVED 20
967
-#define SQLITE_FCNTL_SYNC 21
968
-#define SQLITE_FCNTL_COMMIT_PHASETWO 22
969944
970945
/*
971946
** CAPI3REF: Mutex Handle
972947
**
973948
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2398,17 +2373,15 @@
23982373
** already uses the largest possible [ROWID]. The PRNG is also used for
23992374
** the build-in random() and randomblob() SQL functions. This interface allows
24002375
** applications to access the same PRNG for other purposes.
24012376
**
24022377
** ^A call to this routine stores N bytes of randomness into buffer P.
2403
-** ^If N is less than one, then P can be a NULL pointer.
24042378
**
2405
-** ^If this routine has not been previously called or if the previous
2406
-** call had N less than one, then the PRNG is seeded using randomness
2407
-** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2408
-** ^If the previous call to this routine had an N of 1 or more then
2409
-** the pseudo-randomness is generated
2379
+** ^The first time this routine is invoked (either internally or by
2380
+** the application) the PRNG is seeded using randomness obtained
2381
+** from the xRandomness method of the default [sqlite3_vfs] object.
2382
+** ^On all subsequent invocations, the pseudo-randomness is generated
24102383
** internally and without recourse to the [sqlite3_vfs] xRandomness
24112384
** method.
24122385
*/
24132386
SQLITE_API void sqlite3_randomness(int N, void *P);
24142387
@@ -3982,28 +3955,19 @@
39823955
** parameter is less than -1 or greater than 127 then the behavior is
39833956
** undefined.
39843957
**
39853958
** ^The fourth parameter, eTextRep, specifies what
39863959
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3987
-** its parameters. The application should set this parameter to
3988
-** [SQLITE_UTF16LE] if the function implementation invokes
3989
-** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
3990
-** implementation invokes [sqlite3_value_text16be()] on an input, or
3991
-** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
3992
-** otherwise. ^The same SQL function may be registered multiple times using
3993
-** different preferred text encodings, with different implementations for
3994
-** each encoding.
3960
+** its parameters. Every SQL function implementation must be able to work
3961
+** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3962
+** more efficient with one encoding than another. ^An application may
3963
+** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3964
+** times with the same function but with different values of eTextRep.
39953965
** ^When multiple implementations of the same function are available, SQLite
39963966
** will pick the one that involves the least amount of data conversion.
3997
-**
3998
-** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
3999
-** to signal that the function will always return the same result given
4000
-** the same inputs within a single SQL statement. Most SQL functions are
4001
-** deterministic. The built-in [random()] SQL function is an example of a
4002
-** function that is not deterministic. The SQLite query planner is able to
4003
-** perform additional optimizations on deterministic functions, so use
4004
-** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
3967
+** If there is only a single implementation which does not care what text
3968
+** encoding is used, then the fourth argument should be [SQLITE_ANY].
40053969
**
40063970
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
40073971
** function can gain access to this pointer using [sqlite3_user_data()].)^
40083972
**
40093973
** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4085,23 +4049,13 @@
40854049
*/
40864050
#define SQLITE_UTF8 1
40874051
#define SQLITE_UTF16LE 2
40884052
#define SQLITE_UTF16BE 3
40894053
#define SQLITE_UTF16 4 /* Use native byte order */
4090
-#define SQLITE_ANY 5 /* Deprecated */
4054
+#define SQLITE_ANY 5 /* sqlite3_create_function only */
40914055
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
40924056
4093
-/*
4094
-** CAPI3REF: Function Flags
4095
-**
4096
-** These constants may be ORed together with the
4097
-** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4098
-** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4099
-** [sqlite3_create_function_v2()].
4100
-*/
4101
-#define SQLITE_DETERMINISTIC 0x800
4102
-
41034057
/*
41044058
** CAPI3REF: Deprecated Functions
41054059
** DEPRECATED
41064060
**
41074061
** These functions are [deprecated]. In order to maintain
41084062
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -489,11 +489,10 @@
489 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
494 #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
495 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
496 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
497 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
498 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
499 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -557,12 +556,11 @@
557 ** information is written to disk in the same order as calls
558 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
559 ** after reboot following a crash or power loss, the only bytes in a
560 ** file that were written at the application level might have changed
561 ** and that adjacent bytes, even bytes within the same sector are
562 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
563 ** flag indicate that a file cannot be deleted when open.
564 */
565 #define SQLITE_IOCAP_ATOMIC 0x00000001
566 #define SQLITE_IOCAP_ATOMIC512 0x00000002
567 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
568 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -789,33 +787,19 @@
789 ** to the [sqlite3_file] object associated with a particular database
790 ** connection. See the [sqlite3_file_control()] documentation for
791 ** additional information.
792 **
793 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
794 ** No longer in use.
795 **
796 ** <li>[[SQLITE_FCNTL_SYNC]]
797 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
798 ** sent to the VFS immediately before the xSync method is invoked on a
799 ** database file descriptor. Or, if the xSync method is not invoked
800 ** because the user has configured SQLite with
801 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
802 ** of the xSync method. In most cases, the pointer argument passed with
803 ** this file-control is NULL. However, if the database file is being synced
804 ** as part of a multi-database commit, the argument points to a nul-terminated
805 ** string containing the transactions master-journal file name. VFSes that
806 ** do not need this signal should silently ignore this opcode. Applications
807 ** should not call [sqlite3_file_control()] with this opcode as doing so may
808 ** disrupt the operation of the specialized VFSes that do require it.
809 **
810 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
811 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
812 ** and sent to the VFS after a transaction has been committed immediately
813 ** but before the database is unlocked. VFSes that do not need this signal
814 ** should silently ignore this opcode. Applications should not call
815 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
816 ** operation of the specialized VFSes that do require it.
817 **
818 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
819 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
820 ** retry counts and intervals for certain disk I/O operations for the
821 ** windows [VFS] in order to provide robustness in the presence of
@@ -935,16 +919,10 @@
935 ** This file control is used by some VFS activity tracing [shims].
936 ** The argument is a zero-terminated string. Higher layers in the
937 ** SQLite stack may generate instances of this file control if
938 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
939 **
940 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
941 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
942 ** pointer to an integer and it writes a boolean into that integer depending
943 ** on whether or not the file has been renamed, moved, or deleted since it
944 ** was first opened.
945 **
946 ** </ul>
947 */
948 #define SQLITE_FCNTL_LOCKSTATE 1
949 #define SQLITE_GET_LOCKPROXYFILE 2
950 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -961,13 +939,10 @@
961 #define SQLITE_FCNTL_PRAGMA 14
962 #define SQLITE_FCNTL_BUSYHANDLER 15
963 #define SQLITE_FCNTL_TEMPFILENAME 16
964 #define SQLITE_FCNTL_MMAP_SIZE 18
965 #define SQLITE_FCNTL_TRACE 19
966 #define SQLITE_FCNTL_HAS_MOVED 20
967 #define SQLITE_FCNTL_SYNC 21
968 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
969
970 /*
971 ** CAPI3REF: Mutex Handle
972 **
973 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2398,17 +2373,15 @@
2398 ** already uses the largest possible [ROWID]. The PRNG is also used for
2399 ** the build-in random() and randomblob() SQL functions. This interface allows
2400 ** applications to access the same PRNG for other purposes.
2401 **
2402 ** ^A call to this routine stores N bytes of randomness into buffer P.
2403 ** ^If N is less than one, then P can be a NULL pointer.
2404 **
2405 ** ^If this routine has not been previously called or if the previous
2406 ** call had N less than one, then the PRNG is seeded using randomness
2407 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2408 ** ^If the previous call to this routine had an N of 1 or more then
2409 ** the pseudo-randomness is generated
2410 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2411 ** method.
2412 */
2413 SQLITE_API void sqlite3_randomness(int N, void *P);
2414
@@ -3982,28 +3955,19 @@
3982 ** parameter is less than -1 or greater than 127 then the behavior is
3983 ** undefined.
3984 **
3985 ** ^The fourth parameter, eTextRep, specifies what
3986 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3987 ** its parameters. The application should set this parameter to
3988 ** [SQLITE_UTF16LE] if the function implementation invokes
3989 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
3990 ** implementation invokes [sqlite3_value_text16be()] on an input, or
3991 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
3992 ** otherwise. ^The same SQL function may be registered multiple times using
3993 ** different preferred text encodings, with different implementations for
3994 ** each encoding.
3995 ** ^When multiple implementations of the same function are available, SQLite
3996 ** will pick the one that involves the least amount of data conversion.
3997 **
3998 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
3999 ** to signal that the function will always return the same result given
4000 ** the same inputs within a single SQL statement. Most SQL functions are
4001 ** deterministic. The built-in [random()] SQL function is an example of a
4002 ** function that is not deterministic. The SQLite query planner is able to
4003 ** perform additional optimizations on deterministic functions, so use
4004 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4005 **
4006 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4007 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4008 **
4009 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4085,23 +4049,13 @@
4085 */
4086 #define SQLITE_UTF8 1
4087 #define SQLITE_UTF16LE 2
4088 #define SQLITE_UTF16BE 3
4089 #define SQLITE_UTF16 4 /* Use native byte order */
4090 #define SQLITE_ANY 5 /* Deprecated */
4091 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4092
4093 /*
4094 ** CAPI3REF: Function Flags
4095 **
4096 ** These constants may be ORed together with the
4097 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4098 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4099 ** [sqlite3_create_function_v2()].
4100 */
4101 #define SQLITE_DETERMINISTIC 0x800
4102
4103 /*
4104 ** CAPI3REF: Deprecated Functions
4105 ** DEPRECATED
4106 **
4107 ** These functions are [deprecated]. In order to maintain
4108
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -489,11 +489,10 @@
489 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
490 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
491 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
492 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
493 #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
 
494 #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
495 #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
496 #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
497 #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
498 #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -557,12 +556,11 @@
556 ** information is written to disk in the same order as calls
557 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
558 ** after reboot following a crash or power loss, the only bytes in a
559 ** file that were written at the application level might have changed
560 ** and that adjacent bytes, even bytes within the same sector are
561 ** guaranteed to be unchanged.
 
562 */
563 #define SQLITE_IOCAP_ATOMIC 0x00000001
564 #define SQLITE_IOCAP_ATOMIC512 0x00000002
565 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
566 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -789,33 +787,19 @@
787 ** to the [sqlite3_file] object associated with a particular database
788 ** connection. See the [sqlite3_file_control()] documentation for
789 ** additional information.
790 **
791 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
792 ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
793 ** SQLite and sent to all VFSes in place of a call to the xSync method
794 ** when the database connection has [PRAGMA synchronous] set to OFF.)^
795 ** Some specialized VFSes need this signal in order to operate correctly
796 ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
797 ** VFSes do not need this signal and should silently ignore this opcode.
798 ** Applications should not call [sqlite3_file_control()] with this
799 ** opcode as doing so may disrupt the operation of the specialized VFSes
800 ** that do require it.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
801 **
802 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
803 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
804 ** retry counts and intervals for certain disk I/O operations for the
805 ** windows [VFS] in order to provide robustness in the presence of
@@ -935,16 +919,10 @@
919 ** This file control is used by some VFS activity tracing [shims].
920 ** The argument is a zero-terminated string. Higher layers in the
921 ** SQLite stack may generate instances of this file control if
922 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
923 **
 
 
 
 
 
 
924 ** </ul>
925 */
926 #define SQLITE_FCNTL_LOCKSTATE 1
927 #define SQLITE_GET_LOCKPROXYFILE 2
928 #define SQLITE_SET_LOCKPROXYFILE 3
@@ -961,13 +939,10 @@
939 #define SQLITE_FCNTL_PRAGMA 14
940 #define SQLITE_FCNTL_BUSYHANDLER 15
941 #define SQLITE_FCNTL_TEMPFILENAME 16
942 #define SQLITE_FCNTL_MMAP_SIZE 18
943 #define SQLITE_FCNTL_TRACE 19
 
 
 
944
945 /*
946 ** CAPI3REF: Mutex Handle
947 **
948 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -2398,17 +2373,15 @@
2373 ** already uses the largest possible [ROWID]. The PRNG is also used for
2374 ** the build-in random() and randomblob() SQL functions. This interface allows
2375 ** applications to access the same PRNG for other purposes.
2376 **
2377 ** ^A call to this routine stores N bytes of randomness into buffer P.
 
2378 **
2379 ** ^The first time this routine is invoked (either internally or by
2380 ** the application) the PRNG is seeded using randomness obtained
2381 ** from the xRandomness method of the default [sqlite3_vfs] object.
2382 ** ^On all subsequent invocations, the pseudo-randomness is generated
 
2383 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2384 ** method.
2385 */
2386 SQLITE_API void sqlite3_randomness(int N, void *P);
2387
@@ -3982,28 +3955,19 @@
3955 ** parameter is less than -1 or greater than 127 then the behavior is
3956 ** undefined.
3957 **
3958 ** ^The fourth parameter, eTextRep, specifies what
3959 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3960 ** its parameters. Every SQL function implementation must be able to work
3961 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3962 ** more efficient with one encoding than another. ^An application may
3963 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3964 ** times with the same function but with different values of eTextRep.
 
 
 
3965 ** ^When multiple implementations of the same function are available, SQLite
3966 ** will pick the one that involves the least amount of data conversion.
3967 ** If there is only a single implementation which does not care what text
3968 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
 
 
 
 
 
 
3969 **
3970 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3971 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3972 **
3973 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4085,23 +4049,13 @@
4049 */
4050 #define SQLITE_UTF8 1
4051 #define SQLITE_UTF16LE 2
4052 #define SQLITE_UTF16BE 3
4053 #define SQLITE_UTF16 4 /* Use native byte order */
4054 #define SQLITE_ANY 5 /* sqlite3_create_function only */
4055 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4056
 
 
 
 
 
 
 
 
 
 
4057 /*
4058 ** CAPI3REF: Deprecated Functions
4059 ** DEPRECATED
4060 **
4061 ** These functions are [deprecated]. In order to maintain
4062

Keyboard Shortcuts

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