Fossil SCM

Update the built-in SQLite to the latest trunk version that fixes a harmless compiler warning.

drh 2023-06-12 18:24 trunk
Commit f8a29b2e208dddd5feab9d536ce01227eb5a58c2d805a2b089e4b9e10e2215b9
2 files changed +641 -320 +35 -20
+641 -320
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.42.0. By combining all the individual C code files into this
3
+** version $VERSION. 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.
@@ -14,10 +14,13 @@
1414
** the text of this file. Search for "Begin file sqlite3.h" to find the start
1515
** of the embedded sqlite3.h header file.) Additional code files may be needed
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
19
+**
20
+** The content in this amalgamation comes from Fossil check-in
21
+** ec4ab327decd6a5ee5e6a53f1489e17e0cd.
1922
*/
2023
#define SQLITE_CORE 1
2124
#define SQLITE_AMALGAMATION 1
2225
#ifndef SQLITE_PRIVATE
2326
# define SQLITE_PRIVATE static
@@ -48,15 +51,15 @@
4851
** NO_TEST - The branches on this line are not
4952
** measured by branch coverage. This is
5053
** used on lines of code that actually
5154
** implement parts of coverage testing.
5255
**
53
-** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
56
+** OPTIMIZATION-IF-TRUE - This branch is allowed to always be false
5457
** and the correct answer is still obtained,
5558
** though perhaps more slowly.
5659
**
57
-** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
60
+** OPTIMIZATION-IF-FALSE - This branch is allowed to always be true
5861
** and the correct answer is still obtained,
5962
** though perhaps more slowly.
6063
**
6164
** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
6265
** that would be harmless and undetectable
@@ -454,13 +457,13 @@
454457
**
455458
** See also: [sqlite3_libversion()],
456459
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
457460
** [sqlite_version()] and [sqlite_source_id()].
458461
*/
459
-#define SQLITE_VERSION "3.42.0"
460
-#define SQLITE_VERSION_NUMBER 3042000
461
-#define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0"
462
+#define SQLITE_VERSION "3.43.0"
463
+#define SQLITE_VERSION_NUMBER 3043000
464
+#define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9"
462465
463466
/*
464467
** CAPI3REF: Run-Time Library Version Numbers
465468
** KEYWORDS: sqlite3_version sqlite3_sourceid
466469
**
@@ -1498,11 +1501,11 @@
14981501
** the database is not a wal-mode db, or if there is no such connection in any
14991502
** other process. This opcode cannot be used to detect transactions opened
15001503
** by clients within the current process, only within other processes.
15011504
**
15021505
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1503
-** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the
1506
+** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
15041507
** [checksum VFS shim] only.
15051508
**
15061509
** <li>[[SQLITE_FCNTL_RESET_CACHE]]
15071510
** If there is currently no transaction open on the database, and the
15081511
** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
@@ -2762,11 +2765,11 @@
27622765
** 3.0.0.
27632766
** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
27642767
** the [VACUUM] command will fail with an obscure error when attempting to
27652768
** process a table with generated columns and a descending index. This is
27662769
** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2767
-** either generated columns or decending indexes.
2770
+** either generated columns or descending indexes.
27682771
** </dd>
27692772
**
27702773
** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
27712774
** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
27722775
** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
@@ -3043,10 +3046,11 @@
30433046
** SQL statements is a no-op and has no effect on SQL statements
30443047
** that are started after the sqlite3_interrupt() call returns.
30453048
**
30463049
** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
30473050
** or not an interrupt is currently in effect for [database connection] D.
3051
+** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
30483052
*/
30493053
SQLITE_API void sqlite3_interrupt(sqlite3*);
30503054
SQLITE_API int sqlite3_is_interrupted(sqlite3*);
30513055
30523056
/*
@@ -3696,12 +3700,14 @@
36963700
** and context pointer P. ^If the X callback is
36973701
** NULL or if the M mask is zero, then tracing is disabled. The
36983702
** M argument should be the bitwise OR-ed combination of
36993703
** zero or more [SQLITE_TRACE] constants.
37003704
**
3701
-** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
3702
-** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
3705
+** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3706
+** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3707
+** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each
3708
+** database connection may have at most one trace callback.
37033709
**
37043710
** ^The X callback is invoked whenever any of the events identified by
37053711
** mask M occur. ^The integer return value from the callback is currently
37063712
** ignored, though this may change in future releases. Callback
37073713
** implementations should return zero to ensure future compatibility.
@@ -4066,11 +4072,11 @@
40664072
**
40674073
** The first parameter to these interfaces (hereafter referred to
40684074
** as F) must be one of:
40694075
** <ul>
40704076
** <li> A database filename pointer created by the SQLite core and
4071
-** passed into the xOpen() method of a VFS implemention, or
4077
+** passed into the xOpen() method of a VFS implementation, or
40724078
** <li> A filename obtained from [sqlite3_db_filename()], or
40734079
** <li> A new filename constructed using [sqlite3_create_filename()].
40744080
** </ul>
40754081
** If the F parameter is not one of the above, then the behavior is
40764082
** undefined and probably undesirable. Older versions of SQLite were
@@ -4179,11 +4185,11 @@
41794185
SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
41804186
41814187
/*
41824188
** CAPI3REF: Create and Destroy VFS Filenames
41834189
**
4184
-** These interfces are provided for use by [VFS shim] implementations and
4190
+** These interfaces are provided for use by [VFS shim] implementations and
41854191
** are not useful outside of that context.
41864192
**
41874193
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
41884194
** database filename D with corresponding journal file J and WAL file W and
41894195
** with N URI parameters key/values pairs in the array P. The result from
@@ -4889,11 +4895,11 @@
48894895
** These three options exist:
48904896
** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
48914897
** with it may be passed. ^It is called to dispose of the BLOB or string even
48924898
** if the call to the bind API fails, except the destructor is not called if
48934899
** the third parameter is a NULL pointer or the fourth parameter is negative.
4894
-** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
4900
+** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
48954901
** the application remains responsible for disposing of the object. ^In this
48964902
** case, the object and the provided pointer to it must remain valid until
48974903
** either the prepared statement is finalized or the same SQL parameter is
48984904
** bound to something else, whichever occurs sooner.
48994905
** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
@@ -5568,18 +5574,30 @@
55685574
** Use [sqlite3_clear_bindings()] to reset the bindings.
55695575
**
55705576
** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
55715577
** back to the beginning of its program.
55725578
**
5573
-** ^If the most recent call to [sqlite3_step(S)] for the
5574
-** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
5575
-** or if [sqlite3_step(S)] has never before been called on S,
5576
-** then [sqlite3_reset(S)] returns [SQLITE_OK].
5579
+** ^The return code from [sqlite3_reset(S)] indicates whether or not
5580
+** the previous evaluation of prepared statement S completed successfully.
5581
+** ^If [sqlite3_step(S)] has never before been called on S or if
5582
+** [sqlite3_step(S)] has not been called since the previous call
5583
+** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return
5584
+** [SQLITE_OK].
55775585
**
55785586
** ^If the most recent call to [sqlite3_step(S)] for the
55795587
** [prepared statement] S indicated an error, then
55805588
** [sqlite3_reset(S)] returns an appropriate [error code].
5589
+** ^The [sqlite3_reset(S)] interface might also return an [error code]
5590
+** if there were no prior errors but the process of resetting
5591
+** the prepared statement caused a new error. ^For example, if an
5592
+** [INSERT] statement with a [RETURNING] clause is only stepped one time,
5593
+** that one call to [sqlite3_step(S)] might return SQLITE_ROW but
5594
+** the overall statement might still fail and the [sqlite3_reset(S)] call
5595
+** might return SQLITE_BUSY if locking constraints prevent the
5596
+** database change from committing. Therefore, it is important that
5597
+** applications check the return code from [sqlite3_reset(S)] even if
5598
+** no prior call to [sqlite3_step(S)] indicated a problem.
55815599
**
55825600
** ^The [sqlite3_reset(S)] interface does not change the values
55835601
** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
55845602
*/
55855603
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
@@ -5792,11 +5810,11 @@
57925810
** <p>
57935811
** The SQLITE_DIRECTONLY flag is recommended for any
57945812
** [application-defined SQL function]
57955813
** that has side-effects or that could potentially leak sensitive information.
57965814
** This will prevent attacks in which an application is tricked
5797
-** into using a database file that has had its schema surreptiously
5815
+** into using a database file that has had its schema surreptitiously
57985816
** modified to invoke the application-defined function in ways that are
57995817
** harmful.
58005818
** <p>
58015819
** Some people say it is good practice to set SQLITE_DIRECTONLY on all
58025820
** [application-defined SQL functions], regardless of whether or not they
@@ -9501,12 +9519,12 @@
95019519
** ^(There may be at most one unlock-notify callback registered by a
95029520
** blocked connection. If sqlite3_unlock_notify() is called when the
95039521
** blocked connection already has a registered unlock-notify callback,
95049522
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
95059523
** called with a NULL pointer as its second argument, then any existing
9506
-** unlock-notify callback is canceled. ^The blocked connections
9507
-** unlock-notify callback may also be canceled by closing the blocked
9524
+** unlock-notify callback is cancelled. ^The blocked connections
9525
+** unlock-notify callback may also be cancelled by closing the blocked
95089526
** connection using [sqlite3_close()].
95099527
**
95109528
** The unlock-notify callback is not reentrant. If an application invokes
95119529
** any sqlite3_xxx API functions from within an unlock-notify callback, a
95129530
** crash or deadlock may be the result.
@@ -9925,11 +9943,11 @@
99259943
** </dd>
99269944
**
99279945
** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
99289946
** <dd>Calls of the form
99299947
** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9930
-** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9948
+** the [xConnect] or [xCreate] methods of a [virtual table] implementation
99319949
** prohibits that virtual table from being used from within triggers and
99329950
** views.
99339951
** </dd>
99349952
**
99359953
** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
@@ -10115,11 +10133,11 @@
1011510133
** ^(A constraint on a virtual table of the form
1011610134
** "[IN operator|column IN (...)]" is
1011710135
** communicated to the xBestIndex method as a
1011810136
** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
1011910137
** this constraint, it must set the corresponding
10120
-** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
10138
+** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under
1012110139
** the usual mode of handling IN operators, SQLite generates [bytecode]
1012210140
** that invokes the [xFilter|xFilter() method] once for each value
1012310141
** on the right-hand side of the IN operator.)^ Thus the virtual table
1012410142
** only sees a single value from the right-hand side of the IN operator
1012510143
** at a time.
@@ -10544,11 +10562,11 @@
1054410562
** triggers; and so forth.
1054510563
**
1054610564
** When the [sqlite3_blob_write()] API is used to update a blob column,
1054710565
** the pre-update hook is invoked with SQLITE_DELETE. This is because the
1054810566
** in this case the new values are not available. In this case, when a
10549
-** callback made with op==SQLITE_DELETE is actuall a write using the
10567
+** callback made with op==SQLITE_DELETE is actually a write using the
1055010568
** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
1055110569
** the index of the column being written. In other cases, where the
1055210570
** pre-update hook is being invoked for some other reason, including a
1055310571
** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
1055410572
**
@@ -13468,11 +13486,11 @@
1346813486
** The maximum number of terms in a compound SELECT statement.
1346913487
** The code generator for compound SELECT statements does one
1347013488
** level of recursion for each term. A stack overflow can result
1347113489
** if the number of terms is too large. In practice, most SQL
1347213490
** never has more than 3 or 4 terms. Use a value of 0 to disable
13473
-** any limit on the number of terms in a compount SELECT.
13491
+** any limit on the number of terms in a compound SELECT.
1347413492
*/
1347513493
#ifndef SQLITE_MAX_COMPOUND_SELECT
1347613494
# define SQLITE_MAX_COMPOUND_SELECT 500
1347713495
#endif
1347813496
@@ -14806,11 +14824,11 @@
1480614824
};
1480714825
1480814826
/*
1480914827
** Name of table that holds the database schema.
1481014828
**
14811
-** The PREFERRED names are used whereever possible. But LEGACY is also
14829
+** The PREFERRED names are used wherever possible. But LEGACY is also
1481214830
** used for backwards compatibility.
1481314831
**
1481414832
** 1. Queries can use either the PREFERRED or the LEGACY names
1481514833
** 2. The sqlite3_set_authorizer() callback uses the LEGACY name
1481614834
** 3. The PRAGMA table_list statement uses the PREFERRED name
@@ -16575,11 +16593,11 @@
1657516593
1657616594
/*
1657716595
** The VdbeCoverage macros are used to set a coverage testing point
1657816596
** for VDBE branch instructions. The coverage testing points are line
1657916597
** numbers in the sqlite3.c source file. VDBE branch coverage testing
16580
-** only works with an amalagmation build. That's ok since a VDBE branch
16598
+** only works with an amalgamation build. That's ok since a VDBE branch
1658116599
** coverage build designed for testing the test suite only. No application
1658216600
** should ever ship with VDBE branch coverage measuring turned on.
1658316601
**
1658416602
** VdbeCoverage(v) // Mark the previously coded instruction
1658516603
** // as a branch
@@ -16593,21 +16611,21 @@
1659316611
** VdbeCoverageNeverNull(v) // Previous three-way branch is only
1659416612
** // taken on the first two ways. The
1659516613
** // NULL option is not possible
1659616614
**
1659716615
** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested
16598
-** // in distingishing equal and not-equal.
16616
+** // in distinguishing equal and not-equal.
1659916617
**
1660016618
** Every VDBE branch operation must be tagged with one of the macros above.
1660116619
** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
1660216620
** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
1660316621
** routine in vdbe.c, alerting the developer to the missed tag.
1660416622
**
1660516623
** During testing, the test application will invoke
1660616624
** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
1660716625
** routine that is invoked as each bytecode branch is taken. The callback
16608
-** contains the sqlite3.c source line number ov the VdbeCoverage macro and
16626
+** contains the sqlite3.c source line number of the VdbeCoverage macro and
1660916627
** flags to indicate whether or not the branch was taken. The test application
1661016628
** is responsible for keeping track of this and reporting byte-code branches
1661116629
** that are never taken.
1661216630
**
1661316631
** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
@@ -16942,11 +16960,11 @@
1694216960
#endif
1694316961
1694416962
/*
1694516963
** Default synchronous levels.
1694616964
**
16947
-** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ
16965
+** Note that (for historical reasons) the PAGER_SYNCHRONOUS_* macros differ
1694816966
** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1.
1694916967
**
1695016968
** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS
1695116969
** OFF 1 0
1695216970
** NORMAL 2 1
@@ -16981,11 +16999,11 @@
1698116999
1698217000
/*
1698317001
** An instance of the following structure stores a database schema.
1698417002
**
1698517003
** Most Schema objects are associated with a Btree. The exception is
16986
-** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
17004
+** the Schema for the TEMP database (sqlite3.aDb[1]) which is free-standing.
1698717005
** In shared cache mode, a single Schema object can be shared by multiple
1698817006
** Btrees that refer to the same underlying BtShared object.
1698917007
**
1699017008
** Schema objects are automatically deallocated when the last Btree that
1699117009
** references them is destroyed. The TEMP Schema is manually freed by
@@ -17092,11 +17110,11 @@
1709217110
u32 nSlot; /* Number of lookaside slots allocated */
1709317111
u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
1709417112
LookasideSlot *pInit; /* List of buffers not previously used */
1709517113
LookasideSlot *pFree; /* List of available buffers */
1709617114
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
17097
- LookasideSlot *pSmallInit; /* List of small buffers not prediously used */
17115
+ LookasideSlot *pSmallInit; /* List of small buffers not previously used */
1709817116
LookasideSlot *pSmallFree; /* List of available small buffers */
1709917117
void *pMiddle; /* First byte past end of full-size buffers and
1710017118
** the first byte of LOOKASIDE_SMALL buffers */
1710117119
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
1710217120
void *pStart; /* First byte of available memory space */
@@ -17109,11 +17127,11 @@
1710917127
1711017128
#define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
1711117129
#define EnableLookaside db->lookaside.bDisable--;\
1711217130
db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
1711317131
17114
-/* Size of the smaller allocations in two-size lookside */
17132
+/* Size of the smaller allocations in two-size lookaside */
1711517133
#ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
1711617134
# define LOOKASIDE_SMALL 0
1711717135
#else
1711817136
# define LOOKASIDE_SMALL 128
1711917137
#endif
@@ -17537,11 +17555,11 @@
1753717555
** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!!
1753817556
** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
1753917557
**
1754017558
** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the
1754117559
** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is
17542
-** used internally and if set means tha the function has side effects.
17560
+** used internally and if set means that the function has side effects.
1754317561
** SQLITE_INNOCUOUS is used by application code and means "not unsafe".
1754417562
** See multiple instances of tag-20230109-1.
1754517563
*/
1754617564
#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
1754717565
#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
@@ -18127,11 +18145,11 @@
1812718145
** to its default value. CASCADE means that a DELETE or UPDATE of the
1812818146
** referenced table row is propagated into the row that holds the
1812918147
** foreign key.
1813018148
**
1813118149
** The OE_Default value is a place holder that means to use whatever
18132
-** conflict resolution algorthm is required from context.
18150
+** conflict resolution algorithm is required from context.
1813318151
**
1813418152
** The following symbolic values are used to record which type
1813518153
** of conflict resolution action to take.
1813618154
*/
1813718155
#define OE_None 0 /* There is no constraint to check */
@@ -18541,11 +18559,11 @@
1854118559
#endif
1854218560
int iTable; /* TK_COLUMN: cursor number of table holding column
1854318561
** TK_REGISTER: register number
1854418562
** TK_TRIGGER: 1 -> new, 0 -> old
1854518563
** EP_Unlikely: 134217728 times likelihood
18546
- ** TK_IN: ephemerial table holding RHS
18564
+ ** TK_IN: ephemeral table holding RHS
1854718565
** TK_SELECT_COLUMN: Number of columns on the LHS
1854818566
** TK_SELECT: 1st register of result vector */
1854918567
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1855018568
** TK_VARIABLE: variable number (always >= 1).
1855118569
** TK_SELECT_COLUMN: column of the result vector */
@@ -18811,11 +18829,11 @@
1881118829
unsigned fromDDL :1; /* Comes from sqlite_schema */
1881218830
unsigned isCte :1; /* This is a CTE */
1881318831
unsigned notCte :1; /* This item may not match a CTE */
1881418832
unsigned isUsing :1; /* u3.pUsing is valid */
1881518833
unsigned isOn :1; /* u3.pOn was once valid and non-NULL */
18816
- unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */
18834
+ unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */
1881718835
unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
1881818836
} fg;
1881918837
int iCursor; /* The VDBE cursor number used to access this table */
1882018838
union {
1882118839
Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
@@ -19657,11 +19675,11 @@
1965719675
#define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
1965819676
1965919677
/* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
1966019678
** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
1966119679
** parameters are for temporary use during development, to help find
19662
-** optimial values for parameters in the query planner. The should not
19680
+** optimal values for parameters in the query planner. The should not
1966319681
** be used on trunk check-ins. They are a temporary mechanism available
1966419682
** for transient development builds only.
1966519683
**
1966619684
** Tuning parameters are numbered starting with 1.
1966719685
*/
@@ -19769,10 +19787,11 @@
1976919787
int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
1977019788
int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
1977119789
void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
1977219790
int walkerDepth; /* Number of subqueries */
1977319791
u16 eCode; /* A small processing code */
19792
+ u16 mWFlags; /* Use-dependent flags */
1977419793
union { /* Extra data for callback */
1977519794
NameContext *pNC; /* Naming context */
1977619795
int n; /* A counter */
1977719796
int iCur; /* A cursor number */
1977819797
SrcList *pSrcList; /* FROM clause */
@@ -20479,11 +20498,11 @@
2047920498
SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, const Token*);
2048020499
SQLITE_PRIVATE int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int);
2048120500
SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*,Expr*,int);
2048220501
SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList*,const ExprList*, int);
2048320502
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int);
20484
-SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
20503
+SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int,int);
2048520504
SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*);
2048620505
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
2048720506
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
2048820507
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
2048920508
SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*);
@@ -23042,11 +23061,11 @@
2304223061
int iNewReg; /* Register for new.* values */
2304323062
int iBlobWrite; /* Value returned by preupdate_blobwrite() */
2304423063
i64 iKey1; /* First key value passed to hook */
2304523064
i64 iKey2; /* Second key value passed to hook */
2304623065
Mem *aNew; /* Array of new.* values */
23047
- Table *pTab; /* Schema object being upated */
23066
+ Table *pTab; /* Schema object being updated */
2304823067
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
2304923068
};
2305023069
2305123070
/*
2305223071
** An instance of this object is used to pass an vector of values into
@@ -24258,10 +24277,29 @@
2425824277
{ 4, "hour", 1.2897e+11, 3600.0 },
2425924278
{ 3, "day", 5373485.0, 86400.0 },
2426024279
{ 5, "month", 176546.0, 2592000.0 },
2426124280
{ 4, "year", 14713.0, 31536000.0 },
2426224281
};
24282
+
24283
+/*
24284
+** If the DateTime p is raw number, try to figure out if it is
24285
+** a julian day number of a unix timestamp. Set the p value
24286
+** appropriately.
24287
+*/
24288
+static void autoAdjustDate(DateTime *p){
24289
+ if( !p->rawS || p->validJD ){
24290
+ p->rawS = 0;
24291
+ }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */
24292
+ && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */
24293
+ ){
24294
+ double r = p->s*1000.0 + 210866760000000.0;
24295
+ clearYMD_HMS_TZ(p);
24296
+ p->iJD = (sqlite3_int64)(r + 0.5);
24297
+ p->validJD = 1;
24298
+ p->rawS = 0;
24299
+ }
24300
+}
2426324301
2426424302
/*
2426524303
** Process a modifier to a date-time stamp. The modifiers are
2426624304
** as follows:
2426724305
**
@@ -24302,23 +24340,12 @@
2430224340
** If rawS is available, then interpret as a julian day number, or
2430324341
** a unix timestamp, depending on its magnitude.
2430424342
*/
2430524343
if( sqlite3_stricmp(z, "auto")==0 ){
2430624344
if( idx>1 ) return 1; /* IMP: R-33611-57934 */
24307
- if( !p->rawS || p->validJD ){
24308
- rc = 0;
24309
- p->rawS = 0;
24310
- }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */
24311
- && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */
24312
- ){
24313
- r = p->s*1000.0 + 210866760000000.0;
24314
- clearYMD_HMS_TZ(p);
24315
- p->iJD = (sqlite3_int64)(r + 0.5);
24316
- p->validJD = 1;
24317
- p->rawS = 0;
24318
- rc = 0;
24319
- }
24345
+ autoAdjustDate(p);
24346
+ rc = 0;
2432024347
}
2432124348
break;
2432224349
}
2432324350
case 'j': {
2432424351
/*
@@ -24480,22 +24507,68 @@
2448024507
case '7':
2448124508
case '8':
2448224509
case '9': {
2448324510
double rRounder;
2448424511
int i;
24485
- for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
24512
+ int Y,M,D,h,m,x;
24513
+ const char *z2 = z;
24514
+ for(n=1; z[n]; n++){
24515
+ if( z[n]==':' ) break;
24516
+ if( sqlite3Isspace(z[n]) ) break;
24517
+ if( z[n]=='-' && n==5 && getDigits(&z[1], "40f", &Y)==1 ) break;
24518
+ }
2448624519
if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){
2448724520
rc = 1;
2448824521
break;
2448924522
}
24490
- if( z[n]==':' ){
24523
+ if( z[n]=='-' ){
24524
+ /* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
24525
+ ** specified number of years, months, and days. MM is limited to
24526
+ ** the range 0-11 and DD is limited to 0-30.
24527
+ */
24528
+ if( z[0]!='+' && z[0]!='-' ) break; /* Must start with +/- */
24529
+ if( NEVER(n!=5) ) break; /* Must be 4-digit YYYY */
24530
+ if( getDigits(&z[1], "40f-20a-20d", &Y, &M, &D)!=3 ) break;
24531
+ if( M>=12 ) break; /* M range 0..11 */
24532
+ if( D>=31 ) break; /* D range 0..30 */
24533
+ computeYMD_HMS(p);
24534
+ p->validJD = 0;
24535
+ if( z[0]=='-' ){
24536
+ p->Y -= Y;
24537
+ p->M -= M;
24538
+ D = -D;
24539
+ }else{
24540
+ p->Y += Y;
24541
+ p->M += M;
24542
+ }
24543
+ x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
24544
+ p->Y += x;
24545
+ p->M -= x*12;
24546
+ computeJD(p);
24547
+ p->validHMS = 0;
24548
+ p->validYMD = 0;
24549
+ p->iJD += (i64)D*86400000;
24550
+ if( z[11]==0 ){
24551
+ rc = 0;
24552
+ break;
24553
+ }
24554
+ if( sqlite3Isspace(z[11])
24555
+ && getDigits(&z[12], "20c:20e", &h, &m)==2
24556
+ ){
24557
+ z2 = &z[12];
24558
+ n = 2;
24559
+ }else{
24560
+ break;
24561
+ }
24562
+ }
24563
+ if( z2[n]==':' ){
2449124564
/* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
2449224565
** specified number of hours, minutes, seconds, and fractional seconds
2449324566
** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
2449424567
** omitted.
2449524568
*/
24496
- const char *z2 = z;
24569
+
2449724570
DateTime tx;
2449824571
sqlite3_int64 day;
2449924572
if( !sqlite3Isdigit(*z2) ) z2++;
2450024573
memset(&tx, 0, sizeof(tx));
2450124574
if( parseHhMmSs(z2, &tx) ) break;
@@ -24526,11 +24599,10 @@
2452624599
&& sqlite3_strnicmp(aXformType[i].zName, z, n)==0
2452724600
&& r>-aXformType[i].rLimit && r<aXformType[i].rLimit
2452824601
){
2452924602
switch( i ){
2453024603
case 4: { /* Special processing to add months */
24531
- int x;
2453224604
assert( strcmp(aXformType[i].zName,"month")==0 );
2453324605
computeYMD_HMS(p);
2453424606
p->M += (int)r;
2453524607
x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
2453624608
p->Y += x;
@@ -24803,11 +24875,11 @@
2480324875
** %J ** julian day number
2480424876
** %m month 01-12
2480524877
** %M minute 00-59
2480624878
** %s seconds since 1970-01-01
2480724879
** %S seconds 00-59
24808
-** %w day of week 0-6 sunday==0
24880
+** %w day of week 0-6 Sunday==0
2480924881
** %W week of year 00-53
2481024882
** %Y year 0000-9999
2481124883
** %% %
2481224884
*/
2481324885
static void strftimeFunc(
@@ -24942,10 +25014,120 @@
2494225014
sqlite3_value **NotUsed2
2494325015
){
2494425016
UNUSED_PARAMETER2(NotUsed, NotUsed2);
2494525017
dateFunc(context, 0, 0);
2494625018
}
25019
+
25020
+/*
25021
+** timediff(DATE1, DATE2)
25022
+**
25023
+** Return the amount of time that must be added to DATE2 in order to
25024
+** convert it into DATE2. The time difference format is:
25025
+**
25026
+** +YYYY-MM-DD HH:MM:SS.SSS
25027
+**
25028
+** The initial "+" becomes "-" if DATE1 occurs before DATE2. For
25029
+** date/time values A and B, the following invariant should hold:
25030
+**
25031
+** datetime(A) == (datetime(B, timediff(A,B))
25032
+**
25033
+** Both DATE arguments must be either a julian day number, or an
25034
+** ISO-8601 string. The unix timestamps are not supported by this
25035
+** routine.
25036
+*/
25037
+static void timediffFunc(
25038
+ sqlite3_context *context,
25039
+ int argc,
25040
+ sqlite3_value **argv
25041
+){
25042
+ char sign;
25043
+ int Y, M;
25044
+ DateTime d1, d2;
25045
+ sqlite3_str sRes;
25046
+ if( isDate(context, 1, argv, &d1) ) return;
25047
+ if( isDate(context, 1, &argv[1], &d2) ) return;
25048
+ computeYMD_HMS(&d1);
25049
+ computeYMD_HMS(&d2);
25050
+ if( d1.iJD>=d2.iJD ){
25051
+ sign = '+';
25052
+ Y = d1.Y - d2.Y;
25053
+ if( Y ){
25054
+ d2.Y = d1.Y;
25055
+ d2.validJD = 0;
25056
+ computeJD(&d2);
25057
+ }
25058
+ M = d1.M - d2.M;
25059
+ if( M<0 ){
25060
+ Y--;
25061
+ M += 12;
25062
+ }
25063
+ if( M!=0 ){
25064
+ d2.M = d1.M;
25065
+ d2.validJD = 0;
25066
+ computeJD(&d2);
25067
+ }
25068
+ if( d1.iJD<d2.iJD ){
25069
+ M--;
25070
+ if( M<0 ){
25071
+ M = 11;
25072
+ Y--;
25073
+ }
25074
+ d2.M--;
25075
+ if( d2.M<1 ){
25076
+ d2.M = 12;
25077
+ d2.Y--;
25078
+ }
25079
+ d2.validJD = 0;
25080
+ computeJD(&d2);
25081
+ }
25082
+ d1.iJD -= d2.iJD;
25083
+ d1.iJD += 148699540800000;
25084
+ }else{
25085
+ sign = '-';
25086
+ Y = d2.Y - d1.Y;
25087
+ if( Y ){
25088
+ d2.Y = d1.Y;
25089
+ d2.validJD = 0;
25090
+ computeJD(&d2);
25091
+ }
25092
+ M = d2.M - d1.M;
25093
+ if( M<0 ){
25094
+ Y--;
25095
+ M += 12;
25096
+ }
25097
+ if( M!=0 ){
25098
+ d2.M = d1.M;
25099
+ d2.validJD = 0;
25100
+ computeJD(&d2);
25101
+ }
25102
+ if( d1.iJD>d2.iJD ){
25103
+ M--;
25104
+ if( M<0 ){
25105
+ M = 11;
25106
+ Y--;
25107
+ }
25108
+ d2.M++;
25109
+ if( d2.M>12 ){
25110
+ d2.M = 1;
25111
+ d2.Y++;
25112
+ }
25113
+ d2.validJD = 0;
25114
+ computeJD(&d2);
25115
+ }
25116
+ d1.iJD = d2.iJD - d1.iJD;
25117
+ d1.iJD += 148699540800000;
25118
+ }
25119
+ d1.validYMD = 0;
25120
+ d1.validHMS = 0;
25121
+ d1.validTZ = 0;
25122
+ computeYMD_HMS(&d1);
25123
+ sqlite3StrAccumInit(&sRes, 0, 0, 0, 100);
25124
+ sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f",
25125
+ sign, Y, M, d1.D-1, d1.h, d1.m, d1.s);
25126
+ sqlite3ResultStrAccum(context, &sRes);
25127
+}
25128
+
2494725129
2494825130
/*
2494925131
** current_timestamp()
2495025132
**
2495125133
** This function returns the same value as datetime('now').
@@ -25017,10 +25199,11 @@
2501725199
PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ),
2501825200
PURE_DATE(date, -1, 0, 0, dateFunc ),
2501925201
PURE_DATE(time, -1, 0, 0, timeFunc ),
2502025202
PURE_DATE(datetime, -1, 0, 0, datetimeFunc ),
2502125203
PURE_DATE(strftime, -1, 0, 0, strftimeFunc ),
25204
+ PURE_DATE(timediff, 2, 0, 0, timediffFunc ),
2502225205
DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
2502325206
DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
2502425207
DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
2502525208
#else
2502625209
STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
@@ -25170,11 +25353,11 @@
2517025353
&& op!=SQLITE_FCNTL_CKPT_START
2517125354
){
2517225355
/* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
2517325356
** is using a regular VFS, it is called after the corresponding
2517425357
** transaction has been committed. Injecting a fault at this point
25175
- ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM
25358
+ ** confuses the test scripts - the COMMIT command returns SQLITE_NOMEM
2517625359
** but the transaction is committed anyway.
2517725360
**
2517825361
** The core must call OsFileControl() though, not OsFileControlHint(),
2517925362
** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
2518025363
** means the commit really has failed and an error should be returned
@@ -25791,11 +25974,11 @@
2579125974
/*
2579225975
** Like free() but works for allocations obtained from sqlite3MemMalloc()
2579325976
** or sqlite3MemRealloc().
2579425977
**
2579525978
** For this low-level routine, we already know that pPrior!=0 since
25796
-** cases where pPrior==0 will have been intecepted and dealt with
25979
+** cases where pPrior==0 will have been intercepted and dealt with
2579725980
** by higher-level routines.
2579825981
*/
2579925982
static void sqlite3MemFree(void *pPrior){
2580025983
#ifdef SQLITE_MALLOCSIZE
2580125984
SQLITE_FREE(pPrior);
@@ -25879,11 +26062,11 @@
2587926062
size_t len;
2588026063
if( _sqliteZone_ ){
2588126064
return SQLITE_OK;
2588226065
}
2588326066
len = sizeof(cpuCount);
25884
- /* One usually wants to use hw.acctivecpu for MT decisions, but not here */
26067
+ /* One usually wants to use hw.activecpu for MT decisions, but not here */
2588526068
sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0);
2588626069
if( cpuCount>1 ){
2588726070
/* defer MT decisions to system malloc */
2588826071
_sqliteZone_ = malloc_default_zone();
2588926072
}else{
@@ -28346,11 +28529,11 @@
2834628529
2834728530
#include <pthread.h>
2834828531
2834928532
/*
2835028533
** The sqlite3_mutex.id, sqlite3_mutex.nRef, and sqlite3_mutex.owner fields
28351
-** are necessary under two condidtions: (1) Debug builds and (2) using
28534
+** are necessary under two conditions: (1) Debug builds and (2) using
2835228535
** home-grown mutexes. Encapsulate these conditions into a single #define.
2835328536
*/
2835428537
#if defined(SQLITE_DEBUG) || defined(SQLITE_HOMEGROWN_RECURSIVE_MUTEX)
2835528538
# define SQLITE_MUTEX_NREF 1
2835628539
#else
@@ -28847,11 +29030,11 @@
2884729030
*/
2884829031
struct sqlite3_mutex {
2884929032
CRITICAL_SECTION mutex; /* Mutex controlling the lock */
2885029033
int id; /* Mutex type */
2885129034
#ifdef SQLITE_DEBUG
28852
- volatile int nRef; /* Number of enterances */
29035
+ volatile int nRef; /* Number of entrances */
2885329036
volatile DWORD owner; /* Thread holding this mutex */
2885429037
volatile LONG trace; /* True to trace changes */
2885529038
#endif
2885629039
};
2885729040
@@ -32228,11 +32411,12 @@
3222832411
const char *azOp[] = {
3222932412
"IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
3223032413
};
3223132414
assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
3223232415
assert( pExpr->pRight );
32233
- assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE );
32416
+ assert( sqlite3ExprSkipCollateAndLikely(pExpr->pRight)->op
32417
+ == TK_TRUEFALSE );
3223432418
x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
3223532419
zUniOp = azOp[x];
3223632420
break;
3223732421
}
3223832422
@@ -33887,11 +34071,11 @@
3388734071
#endif
3388834072
3388934073
/*
3389034074
** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
3389134075
** or to bypass normal error detection during testing in order to let
33892
-** execute proceed futher downstream.
34076
+** execute proceed further downstream.
3389334077
**
3389434078
** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
3389534079
** sqlite3FaultSim() function only returns non-zero during testing.
3389634080
**
3389734081
** During testing, if the test harness has set a fault-sim callback using
@@ -34498,11 +34682,11 @@
3449834682
}
3449934683
3450034684
/* store the result */
3450134685
*pResult = result;
3450234686
34503
- /* return true if number and no extra non-whitespace chracters after */
34687
+ /* return true if number and no extra non-whitespace characters after */
3450434688
if( z==zEnd && nDigit>0 && eValid && eType>0 ){
3450534689
return eType;
3450634690
}else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){
3450734691
return -1;
3450834692
}else{
@@ -34634,11 +34818,11 @@
3463434818
testcase( i==20*incr );
3463534819
if( u>LARGEST_INT64 ){
3463634820
/* This test and assignment is needed only to suppress UB warnings
3463734821
** from clang and -fsanitize=undefined. This test and assignment make
3463834822
** the code a little larger and slower, and no harm comes from omitting
34639
- ** them, but we must appaise the undefined-behavior pharisees. */
34823
+ ** them, but we must appease the undefined-behavior pharisees. */
3464034824
*pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
3464134825
}else if( neg ){
3464234826
*pNum = -(i64)u;
3464334827
}else{
3464434828
*pNum = (i64)u;
@@ -35319,11 +35503,11 @@
3531935503
return 1;
3532035504
}
3532135505
}
3532235506
3532335507
/*
35324
-** Attempt to add, substract, or multiply the 64-bit signed value iB against
35508
+** Attempt to add, subtract, or multiply the 64-bit signed value iB against
3532535509
** the other 64-bit signed integer at *pA and store the result in *pA.
3532635510
** Return 0 on success. Or if the operation would have resulted in an
3532735511
** overflow, leave *pA unchanged and return 1.
3532835512
*/
3532935513
SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
@@ -35632,11 +35816,11 @@
3563235816
*/
3563335817
#ifndef SQLITE_HWTIME_H
3563435818
#define SQLITE_HWTIME_H
3563535819
3563635820
/*
35637
-** The following routine only works on pentium-class (or newer) processors.
35821
+** The following routine only works on Pentium-class (or newer) processors.
3563835822
** It uses the RDTSC opcode to read the cycle count value out of the
3563935823
** processor and returns that value. This can be used for high-res
3564035824
** profiling.
3564135825
*/
3564235826
#if !defined(__STRICT_ANSI__) && \
@@ -35804,11 +35988,11 @@
3580435988
pH->first = pNew;
3580535989
}
3580635990
}
3580735991
3580835992
35809
-/* Resize the hash table so that it cantains "new_size" buckets.
35993
+/* Resize the hash table so that it contains "new_size" buckets.
3581035994
**
3581135995
** The hash table might fail to resize if sqlite3_malloc() fails or
3581235996
** if the new size is the same as the prior size.
3581335997
** Return TRUE if the resize occurs and false if not.
3581435998
*/
@@ -37190,11 +37374,11 @@
3719037374
** skip locking all together.
3719137375
**
3719237376
** This source file is organized into divisions where the logic for various
3719337377
** subfunctions is contained within the appropriate division. PLEASE
3719437378
** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed
37195
-** in the correct division and should be clearly labeled.
37379
+** in the correct division and should be clearly labelled.
3719637380
**
3719737381
** The layout of divisions is as follows:
3719837382
**
3719937383
** * General-purpose declarations and utility functions.
3720037384
** * Unique file ID logic used by VxWorks.
@@ -37777,11 +37961,11 @@
3777737961
#endif
3777837962
}
3777937963
3778037964
/*
3778137965
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
37782
-** "unix" VFSes. Return SQLITE_OK opon successfully updating the
37966
+** "unix" VFSes. Return SQLITE_OK upon successfully updating the
3778337967
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
3778437968
** system call named zName.
3778537969
*/
3778637970
static int unixSetSystemCall(
3778737971
sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
@@ -38299,11 +38483,11 @@
3829938483
** But wait: there are yet more problems with POSIX advisory locks.
3830038484
**
3830138485
** If you close a file descriptor that points to a file that has locks,
3830238486
** all locks on that file that are owned by the current process are
3830338487
** released. To work around this problem, each unixInodeInfo object
38304
-** maintains a count of the number of pending locks on tha inode.
38488
+** maintains a count of the number of pending locks on the inode.
3830538489
** When an attempt is made to close an unixFile, if there are
3830638490
** other unixFile open on the same inode that are holding locks, the call
3830738491
** to close() the file descriptor is deferred until all of the locks clear.
3830838492
** The unixInodeInfo structure keeps a list of file descriptors that need to
3830938493
** be closed and that list is walked (and cleared) when the last lock
@@ -38313,11 +38497,11 @@
3831338497
**
3831438498
** Many older versions of linux use the LinuxThreads library which is
3831538499
** not posix compliant. Under LinuxThreads, a lock created by thread
3831638500
** A cannot be modified or overridden by a different thread B.
3831738501
** Only thread A can modify the lock. Locking behavior is correct
38318
-** if the appliation uses the newer Native Posix Thread Library (NPTL)
38502
+** if the application uses the newer Native Posix Thread Library (NPTL)
3831938503
** on linux - with NPTL a lock created by thread A can override locks
3832038504
** in thread B. But there is no way to know at compile-time which
3832138505
** threading library is being used. So there is no way to know at
3832238506
** compile-time whether or not thread A can override locks on thread B.
3832338507
** One has to do a run-time check to discover the behavior of the
@@ -38515,11 +38699,11 @@
3851538699
static void storeLastErrno(unixFile *pFile, int error){
3851638700
pFile->lastErrno = error;
3851738701
}
3851838702
3851938703
/*
38520
-** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
38704
+** Close all file descriptors accumulated in the unixInodeInfo->pUnused list.
3852138705
*/
3852238706
static void closePendingFds(unixFile *pFile){
3852338707
unixInodeInfo *pInode = pFile->pInode;
3852438708
UnixUnusedFd *p;
3852538709
UnixUnusedFd *pNext;
@@ -38878,19 +39062,19 @@
3887839062
** lock primitives (called read-locks and write-locks below, to avoid
3887939063
** confusion with SQLite lock names). The algorithms are complicated
3888039064
** slightly in order to be compatible with Windows95 systems simultaneously
3888139065
** accessing the same database file, in case that is ever required.
3888239066
**
38883
- ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
39067
+ ** Symbols defined in os.h identify the 'pending byte' and the 'reserved
3888439068
** byte', each single bytes at well known offsets, and the 'shared byte
3888539069
** range', a range of 510 bytes at a well known offset.
3888639070
**
3888739071
** To obtain a SHARED lock, a read-lock is obtained on the 'pending
3888839072
** byte'. If this is successful, 'shared byte range' is read-locked
3888939073
** and the lock on the 'pending byte' released. (Legacy note: When
3889039074
** SQLite was first developed, Windows95 systems were still very common,
38891
- ** and Widnows95 lacks a shared-lock capability. So on Windows95, a
39075
+ ** and Windows95 lacks a shared-lock capability. So on Windows95, a
3889239076
** single randomly selected by from the 'shared byte range' is locked.
3889339077
** Windows95 is now pretty much extinct, but this work-around for the
3889439078
** lack of shared-locks on Windows95 lives on, for backwards
3889539079
** compatibility.)
3889639080
**
@@ -38907,11 +39091,11 @@
3890739091
** If a process that holds a RESERVED lock requests an EXCLUSIVE, then
3890839092
** a PENDING lock is obtained first. A PENDING lock is implemented by
3890939093
** obtaining a write-lock on the 'pending byte'. This ensures that no new
3891039094
** SHARED locks can be obtained, but existing SHARED locks are allowed to
3891139095
** persist. If the call to this function fails to obtain the EXCLUSIVE
38912
- ** lock in this case, it holds the PENDING lock intead. The client may
39096
+ ** lock in this case, it holds the PENDING lock instead. The client may
3891339097
** then re-attempt the EXCLUSIVE lock later on, after existing SHARED
3891439098
** locks have cleared.
3891539099
*/
3891639100
int rc = SQLITE_OK;
3891739101
unixFile *pFile = (unixFile*)id;
@@ -38935,11 +39119,11 @@
3893539119
return SQLITE_OK;
3893639120
}
3893739121
3893839122
/* Make sure the locking sequence is correct.
3893939123
** (1) We never move from unlocked to anything higher than shared lock.
38940
- ** (2) SQLite never explicitly requests a pendig lock.
39124
+ ** (2) SQLite never explicitly requests a pending lock.
3894139125
** (3) A shared lock is always held when a reserve lock is requested.
3894239126
*/
3894339127
assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
3894439128
assert( eFileLock!=PENDING_LOCK );
3894539129
assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
@@ -40153,11 +40337,11 @@
4015340337
return SQLITE_OK;
4015440338
}
4015540339
4015640340
/* Make sure the locking sequence is correct
4015740341
** (1) We never move from unlocked to anything higher than shared lock.
40158
- ** (2) SQLite never explicitly requests a pendig lock.
40342
+ ** (2) SQLite never explicitly requests a pending lock.
4015940343
** (3) A shared lock is always held when a reserve lock is requested.
4016040344
*/
4016140345
assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
4016240346
assert( eFileLock!=PENDING_LOCK );
4016340347
assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
@@ -40269,11 +40453,11 @@
4026940453
** reestablish the shared lock if we can't get the afpUnlock
4027040454
*/
4027140455
if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST +
4027240456
pInode->sharedByte, 1, 0)) ){
4027340457
int failed2 = SQLITE_OK;
40274
- /* now attemmpt to get the exclusive lock range */
40458
+ /* now attempt to get the exclusive lock range */
4027540459
failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST,
4027640460
SHARED_SIZE, 1);
4027740461
if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
4027840462
SHARED_FIRST + pInode->sharedByte, 1, 1)) ){
4027940463
/* Can't reestablish the shared lock. Sqlite can't deal, this is
@@ -40564,11 +40748,11 @@
4056440748
|| offset+amt<=PENDING_BYTE
4056540749
);
4056640750
#endif
4056740751
4056840752
#if SQLITE_MAX_MMAP_SIZE>0
40569
- /* Deal with as much of this read request as possible by transfering
40753
+ /* Deal with as much of this read request as possible by transferring
4057040754
** data from the memory mapping using memcpy(). */
4057140755
if( offset<pFile->mmapSize ){
4057240756
if( offset+amt <= pFile->mmapSize ){
4057340757
memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
4057440758
return SQLITE_OK;
@@ -40716,11 +40900,11 @@
4071640900
}
4071740901
}
4071840902
#endif
4071940903
4072040904
#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
40721
- /* Deal with as much of this write request as possible by transfering
40905
+ /* Deal with as much of this write request as possible by transferring
4072240906
** data from the memory mapping using memcpy(). */
4072340907
if( offset<pFile->mmapSize ){
4072440908
if( offset+amt <= pFile->mmapSize ){
4072540909
memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
4072640910
return SQLITE_OK;
@@ -40838,11 +41022,11 @@
4083841022
#endif
4083941023
4084041024
/* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
4084141025
** no-op. But go ahead and call fstat() to validate the file
4084241026
** descriptor as we need a method to provoke a failure during
40843
- ** coverate testing.
41027
+ ** coverage testing.
4084441028
*/
4084541029
#ifdef SQLITE_NO_SYNC
4084641030
{
4084741031
struct stat buf;
4084841032
rc = osFstat(fd, &buf);
@@ -46478,11 +46662,11 @@
4647846662
4647946663
}; /* End of the overrideable system calls */
4648046664
4648146665
/*
4648246666
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
46483
-** "win32" VFSes. Return SQLITE_OK opon successfully updating the
46667
+** "win32" VFSes. Return SQLITE_OK upon successfully updating the
4648446668
** system call pointer, or SQLITE_NOTFOUND if there is no configurable
4648546669
** system call named zName.
4648646670
*/
4648746671
static int winSetSystemCall(
4648846672
sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
@@ -48058,11 +48242,11 @@
4805848242
OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
4805948243
"offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
4806048244
pFile->h, pBuf, amt, offset, pFile->locktype));
4806148245
4806248246
#if SQLITE_MAX_MMAP_SIZE>0
48063
- /* Deal with as much of this read request as possible by transfering
48247
+ /* Deal with as much of this read request as possible by transferring
4806448248
** data from the memory mapping using memcpy(). */
4806548249
if( offset<pFile->mmapSize ){
4806648250
if( offset+amt <= pFile->mmapSize ){
4806748251
memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
4806848252
OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
@@ -48136,11 +48320,11 @@
4813648320
OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
4813748321
"offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
4813848322
pFile->h, pBuf, amt, offset, pFile->locktype));
4813948323
4814048324
#if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
48141
- /* Deal with as much of this write request as possible by transfering
48325
+ /* Deal with as much of this write request as possible by transferring
4814248326
** data from the memory mapping using memcpy(). */
4814348327
if( offset<pFile->mmapSize ){
4814448328
if( offset+amt <= pFile->mmapSize ){
4814548329
memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
4814648330
OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
@@ -48246,11 +48430,11 @@
4824648430
**
4824748431
** The only feasible work-around is to defer the truncation until after
4824848432
** all references to memory-mapped content are closed. That is doable,
4824948433
** but involves adding a few branches in the common write code path which
4825048434
** could slow down normal operations slightly. Hence, we have decided for
48251
- ** now to simply make trancations a no-op if there are pending reads. We
48435
+ ** now to simply make transactions a no-op if there are pending reads. We
4825248436
** can maybe revisit this decision in the future.
4825348437
*/
4825448438
return SQLITE_OK;
4825548439
}
4825648440
#endif
@@ -48305,11 +48489,11 @@
4830548489
}
4830648490
4830748491
#ifdef SQLITE_TEST
4830848492
/*
4830948493
** Count the number of fullsyncs and normal syncs. This is used to test
48310
-** that syncs and fullsyncs are occuring at the right times.
48494
+** that syncs and fullsyncs are occurring at the right times.
4831148495
*/
4831248496
SQLITE_API int sqlite3_sync_count = 0;
4831348497
SQLITE_API int sqlite3_fullsync_count = 0;
4831448498
#endif
4831548499
@@ -52643,11 +52827,11 @@
5264352827
return SQLITE_OK;
5264452828
}
5264552829
h = BITVEC_HASH(i++);
5264652830
/* if there wasn't a hash collision, and this doesn't */
5264752831
/* completely fill the hash, then just add it without */
52648
- /* worring about sub-dividing and re-hashing. */
52832
+ /* worrying about sub-dividing and re-hashing. */
5264952833
if( !p->u.aHash[h] ){
5265052834
if (p->nSet<(BITVEC_NINT-1)) {
5265152835
goto bitvec_set_end;
5265252836
} else {
5265352837
goto bitvec_set_rehash;
@@ -53140,11 +53324,11 @@
5314053324
/* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
5314153325
** suggested cache size is set to N. */
5314253326
return p->szCache;
5314353327
}else{
5314453328
i64 n;
53145
- /* IMPLEMANTATION-OF: R-59858-46238 If the argument N is negative, then the
53329
+ /* IMPLEMENTATION-OF: R-59858-46238 If the argument N is negative, then the
5314653330
** number of cache pages is adjusted to be a number of pages that would
5314753331
** use approximately abs(N*1024) bytes of memory based on the current
5314853332
** page size. */
5314953333
n = ((-1024*(i64)p->szCache)/(p->szPage+p->szExtra));
5315053334
if( n>1000000000 ) n = 1000000000;
@@ -53628,11 +53812,11 @@
5362853812
}
5362953813
return result.pDirty;
5363053814
}
5363153815
5363253816
/*
53633
-** Sort the list of pages in accending order by pgno. Pages are
53817
+** Sort the list of pages in ascending order by pgno. Pages are
5363453818
** connected by pDirty pointers. The pDirtyPrev pointers are
5363553819
** corrupted by this sort.
5363653820
**
5363753821
** Since there cannot be more than 2^31 distinct pages in a database,
5363853822
** there cannot be more than 31 buckets required by the merge sorter.
@@ -53868,11 +54052,11 @@
5386854052
** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
5386954053
**
5387054054
** If N is positive, then N pages worth of memory are allocated using a single
5387154055
** sqlite3Malloc() call and that memory is used for the first N pages allocated.
5387254056
** Or if N is negative, then -1024*N bytes of memory are allocated and used
53873
-** for as many pages as can be accomodated.
54057
+** for as many pages as can be accommodated.
5387454058
**
5387554059
** Only one of (2) or (3) can be used. Once the memory available to (2) or
5387654060
** (3) is exhausted, subsequent allocations fail over to the general-purpose
5387754061
** memory allocator (1).
5387854062
**
@@ -53902,11 +54086,11 @@
5390254086
** but causes a 2-byte gap in the structure for most architectures (since
5390354087
** pointers must be either 4 or 8-byte aligned). As this structure is located
5390454088
** in memory directly after the associated page data, if the database is
5390554089
** corrupt, code at the b-tree layer may overread the page buffer and
5390654090
** read part of this structure before the corruption is detected. This
53907
-** can cause a valgrind error if the unitialized gap is accessed. Using u16
54091
+** can cause a valgrind error if the uninitialized gap is accessed. Using u16
5390854092
** ensures there is no such gap, and therefore no bytes of uninitialized
5390954093
** memory in the structure.
5391054094
**
5391154095
** The pLruNext and pLruPrev pointers form a double-linked circular list
5391254096
** of all pages that are unpinned. The PGroup.lru element (which should be
@@ -55122,11 +55306,11 @@
5512255306
** until DESTROY.
5512355307
**
5512455308
** The TEST primitive includes a "batch" number. The TEST primitive
5512555309
** will only see elements that were inserted before the last change
5512655310
** in the batch number. In other words, if an INSERT occurs between
55127
-** two TESTs where the TESTs have the same batch nubmer, then the
55311
+** two TESTs where the TESTs have the same batch number, then the
5512855312
** value added by the INSERT will not be visible to the second TEST.
5512955313
** The initial batch number is zero, so if the very first TEST contains
5513055314
** a non-zero batch number, it will see all prior INSERTs.
5513155315
**
5513255316
** No INSERTs may occurs after a SMALLEST. An assertion will fail if
@@ -56045,11 +56229,11 @@
5604556229
** Once it has entered the ERROR state, any attempt to use the pager
5604656230
** to read or write data returns an error. Eventually, once all
5604756231
** outstanding transactions have been abandoned, the pager is able to
5604856232
** transition back to OPEN state, discarding the contents of the
5604956233
** page-cache and any other in-memory state at the same time. Everything
56050
-** is reloaded from disk (and, if necessary, hot-journal rollback peformed)
56234
+** is reloaded from disk (and, if necessary, hot-journal rollback performed)
5605156235
** when a read-transaction is next opened on the pager (transitioning
5605256236
** the pager into READER state). At that point the system has recovered
5605356237
** from the error.
5605456238
**
5605556239
** Specifically, the pager jumps into the ERROR state if:
@@ -57418,11 +57602,11 @@
5741857602
** + N bytes: super-journal filename in utf-8.
5741957603
** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
5742057604
** + 4 bytes: super-journal name checksum.
5742157605
** + 8 bytes: aJournalMagic[].
5742257606
**
57423
-** The super-journal page checksum is the sum of the bytes in thesuper-journal
57607
+** The super-journal page checksum is the sum of the bytes in the super-journal
5742457608
** name, where each byte is interpreted as a signed 8-bit integer.
5742557609
**
5742657610
** If zSuper is a NULL pointer (occurs for a single database transaction),
5742757611
** this call is a no-op.
5742857612
*/
@@ -57471,11 +57655,11 @@
5747157655
){
5747257656
return rc;
5747357657
}
5747457658
pPager->journalOff += (nSuper+20);
5747557659
57476
- /* If the pager is in peristent-journal mode, then the physical
57660
+ /* If the pager is in persistent-journal mode, then the physical
5747757661
** journal-file may extend past the end of the super-journal name
5747857662
** and 8 bytes of magic data just written to the file. This is
5747957663
** dangerous because the code to rollback a hot-journal file
5748057664
** will not be able to find the super-journal name to determine
5748157665
** whether or not the journal is hot.
@@ -57641,11 +57825,11 @@
5764157825
pPager->setSuper = 0;
5764257826
}
5764357827
5764457828
/*
5764557829
** This function is called whenever an IOERR or FULL error that requires
57646
-** the pager to transition into the ERROR state may ahve occurred.
57830
+** the pager to transition into the ERROR state may have occurred.
5764757831
** The first argument is a pointer to the pager structure, the second
5764857832
** the error-code about to be returned by a pager API function. The
5764957833
** value returned is a copy of the second argument to this function.
5765057834
**
5765157835
** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the
@@ -57916,11 +58100,11 @@
5791658100
pager_unlock(pPager);
5791758101
}
5791858102
5791958103
/*
5792058104
** Parameter aData must point to a buffer of pPager->pageSize bytes
57921
-** of data. Compute and return a checksum based ont the contents of the
58105
+** of data. Compute and return a checksum based on the contents of the
5792258106
** page of data and the current value of pPager->cksumInit.
5792358107
**
5792458108
** This is not a real checksum. It is really just the sum of the
5792558109
** random initial value (pPager->cksumInit) and every 200th byte
5792658110
** of the page data, starting with byte offset (pPager->pageSize%200).
@@ -58882,11 +59066,11 @@
5888259066
PgHdr *p; /* For looping over pages */
5888359067
5888459068
assert( pPager->pWal );
5888559069
assert( pList );
5888659070
#ifdef SQLITE_DEBUG
58887
- /* Verify that the page list is in accending order */
59071
+ /* Verify that the page list is in ascending order */
5888859072
for(p=pList; p && p->pDirty; p=p->pDirty){
5888959073
assert( p->pgno < p->pDirty->pgno );
5889059074
}
5889159075
#endif
5889259076
@@ -59013,11 +59197,11 @@
5901359197
}
5901459198
5901559199
#ifndef SQLITE_OMIT_WAL
5901659200
/*
5901759201
** Check if the *-wal file that corresponds to the database opened by pPager
59018
-** exists if the database is not empy, or verify that the *-wal file does
59202
+** exists if the database is not empty, or verify that the *-wal file does
5901959203
** not exist (by deleting it) if the database file is empty.
5902059204
**
5902159205
** If the database is not empty and the *-wal file exists, open the pager
5902259206
** in WAL mode. If the database is empty or if no *-wal file exists and
5902359207
** if no error occurs, make sure Pager.journalMode is not set to
@@ -60765,11 +60949,11 @@
6076560949
return SQLITE_OK;
6076660950
}
6076760951
6076860952
/*
6076960953
** Return the sqlite3_file for the main database given the name
60770
-** of the corresonding WAL or Journal name as passed into
60954
+** of the corresponding WAL or Journal name as passed into
6077160955
** xOpen.
6077260956
*/
6077360957
SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *zName){
6077460958
Pager *pPager;
6077560959
while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
@@ -63050,11 +63234,11 @@
6305063234
6305163235
/* Change the journal mode. */
6305263236
assert( pPager->eState!=PAGER_ERROR );
6305363237
pPager->journalMode = (u8)eMode;
6305463238
63055
- /* When transistioning from TRUNCATE or PERSIST to any other journal
63239
+ /* When transitioning from TRUNCATE or PERSIST to any other journal
6305663240
** mode except WAL, unless the pager is in locking_mode=exclusive mode,
6305763241
** delete the journal file.
6305863242
*/
6305963243
assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
6306063244
assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
@@ -63768,11 +63952,11 @@
6376863952
** of available reader locks and should be at least 3. The default
6376963953
** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5.
6377063954
**
6377163955
** Technically, the various VFSes are free to implement these locks however
6377263956
** they see fit. However, compatibility is encouraged so that VFSes can
63773
-** interoperate. The standard implemention used on both unix and windows
63957
+** interoperate. The standard implementation used on both unix and windows
6377463958
** is for the index number to indicate a byte offset into the
6377563959
** WalCkptInfo.aLock[] array in the wal-index header. In other words, all
6377663960
** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which
6377763961
** should be 120) is the location in the shm file for the first locking
6377863962
** byte.
@@ -63844,11 +64028,11 @@
6384464028
** There is one entry in aReadMark[] for each reader lock. If a reader
6384564029
** holds read-lock K, then the value in aReadMark[K] is no greater than
6384664030
** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff)
6384764031
** for any aReadMark[] means that entry is unused. aReadMark[0] is
6384864032
** a special case; its value is never used and it exists as a place-holder
63849
-** to avoid having to offset aReadMark[] indexs by one. Readers holding
64033
+** to avoid having to offset aReadMark[] indexes by one. Readers holding
6385064034
** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
6385164035
** directly from the database.
6385264036
**
6385364037
** The value of aReadMark[K] may only be changed by a thread that
6385464038
** is holding an exclusive lock on WAL_READ_LOCK(K). Thus, the value of
@@ -64374,19 +64558,19 @@
6437464558
*/
6437564559
if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
6437664560
return 0;
6437764561
}
6437864562
64379
- /* A frame is only valid if the page number is creater than zero.
64563
+ /* A frame is only valid if the page number is greater than zero.
6438064564
*/
6438164565
pgno = sqlite3Get4byte(&aFrame[0]);
6438264566
if( pgno==0 ){
6438364567
return 0;
6438464568
}
6438564569
6438664570
/* A frame is only valid if a checksum of the WAL header,
64387
- ** all prior frams, the first 16 bytes of this frame-header,
64571
+ ** all prior frames, the first 16 bytes of this frame-header,
6438864572
** and the frame-data matches the checksum in the last 8
6438964573
** bytes of this frame-header.
6439064574
*/
6439164575
nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
6439264576
walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
@@ -65076,11 +65260,11 @@
6507665260
}
6507765261
return rc;
6507865262
}
6507965263
6508065264
/*
65081
-** Change the size to which the WAL file is trucated on each reset.
65265
+** Change the size to which the WAL file is truncated on each reset.
6508265266
*/
6508365267
SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){
6508465268
if( pWal ) pWal->mxWalSize = iLimit;
6508565269
}
6508665270
@@ -65775,11 +65959,11 @@
6577565959
sqlite3OsFileControlHint(
6577665960
pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist
6577765961
);
6577865962
if( bPersist!=1 ){
6577965963
/* Try to delete the WAL file if the checkpoint completed and
65780
- ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
65964
+ ** fsynced (rc==SQLITE_OK) and if we are not in persistent-wal
6578165965
** mode (!bPersist) */
6578265966
isDelete = 1;
6578365967
}else if( pWal->mxWalSize>=0 ){
6578465968
/* Try to truncate the WAL file to zero bytes if the checkpoint
6578565969
** completed and fsynced (rc==SQLITE_OK) and we are in persistent
@@ -65842,11 +66026,11 @@
6584266026
** Memory barriers are used to prevent the compiler or the hardware from
6584366027
** reordering the reads and writes. TSAN and similar tools can sometimes
6584466028
** give false-positive warnings about these accesses because the tools do not
6584566029
** account for the double-read and the memory barrier. The use of mutexes
6584666030
** here would be problematic as the memory being accessed is potentially
65847
- ** shared among multiple processes and not all mutex implementions work
66031
+ ** shared among multiple processes and not all mutex implementations work
6584866032
** reliably in that environment.
6584966033
*/
6585066034
aHdr = walIndexHdr(pWal);
6585166035
memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
6585266036
walShmBarrier(pWal);
@@ -67947,11 +68131,11 @@
6794768131
/*
6794868132
** An instance of this object stores information about each a single database
6794968133
** page that has been loaded into memory. The information in this object
6795068134
** is derived from the raw on-disk page content.
6795168135
**
67952
-** As each database page is loaded into memory, the pager allocats an
68136
+** As each database page is loaded into memory, the pager allocates an
6795368137
** instance of this object and zeros the first 8 bytes. (This is the
6795468138
** "extra" information associated with each page of the pager.)
6795568139
**
6795668140
** Access to all fields of this structure is controlled by the mutex
6795768141
** stored in MemPage.pBt->mutex.
@@ -68403,11 +68587,11 @@
6840368587
#define get4byte sqlite3Get4byte
6840468588
#define put4byte sqlite3Put4byte
6840568589
6840668590
/*
6840768591
** get2byteAligned(), unlike get2byte(), requires that its argument point to a
68408
-** two-byte aligned address. get2bytea() is only used for accessing the
68592
+** two-byte aligned address. get2byteAligned() is only used for accessing the
6840968593
** cell addresses in a btree header.
6841068594
*/
6841168595
#if SQLITE_BYTEORDER==4321
6841268596
# define get2byteAligned(x) (*(u16*)(x))
6841368597
#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
@@ -68580,11 +68764,11 @@
6858068764
** against all schemas and we do not want those schemas being
6858168765
** reset out from under us.
6858268766
**
6858368767
** There is a corresponding leave-all procedures.
6858468768
**
68585
-** Enter the mutexes in accending order by BtShared pointer address
68769
+** Enter the mutexes in ascending order by BtShared pointer address
6858668770
** to avoid the possibility of deadlock when two threads with
6858768771
** two or more btrees in common both try to lock all their btrees
6858868772
** at the same instant.
6858968773
*/
6859068774
static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){
@@ -68712,10 +68896,11 @@
6871268896
6871368897
#endif /* ifndef SQLITE_OMIT_SHARED_CACHE */
6871468898
6871568899
/************** End of btmutex.c *********************************************/
6871668900
/************** Begin file btree.c *******************************************/
68901
+
6871768902
/*
6871868903
** 2004 April 6
6871968904
**
6872068905
** The author disclaims copyright to this source code. In place of
6872168906
** a legal notice, here is a blessing:
@@ -70348,11 +70533,11 @@
7034870533
cbrk = usableSize;
7034970534
iCellLast = usableSize - 4;
7035070535
iCellStart = get2byte(&data[hdr+5]);
7035170536
if( nCell>0 ){
7035270537
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
70353
- memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
70538
+ memcpy(temp, data, usableSize);
7035470539
src = temp;
7035570540
for(i=0; i<nCell; i++){
7035670541
u8 *pAddr; /* The i-th cell pointer */
7035770542
pAddr = &data[cellOffset + i*2];
7035870543
pc = get2byte(pAddr);
@@ -70572,11 +70757,11 @@
7057270757
**
7057370758
** Adjacent freeblocks are coalesced.
7057470759
**
7057570760
** Even though the freeblock list was checked by btreeComputeFreeSpace(),
7057670761
** that routine will not detect overlap between cells or freeblocks. Nor
70577
-** does it detect cells or freeblocks that encrouch into the reserved bytes
70762
+** does it detect cells or freeblocks that encroach into the reserved bytes
7057870763
** at the end of the page. So do additional corruption checks inside this
7057970764
** routine and return SQLITE_CORRUPT if any problems are found.
7058070765
*/
7058170766
static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
7058270767
u16 iPtr; /* Address of ptr to next freeblock */
@@ -71175,11 +71360,11 @@
7117571360
/* pPage might not be a btree page; it might be an overflow page
7117671361
** or ptrmap page or a free page. In those cases, the following
7117771362
** call to btreeInitPage() will likely return SQLITE_CORRUPT.
7117871363
** But no harm is done by this. And it is very important that
7117971364
** btreeInitPage() be called on every btree page so we make
71180
- ** the call for every page that comes in for re-initing. */
71365
+ ** the call for every page that comes in for re-initializing. */
7118171366
btreeInitPage(pPage);
7118271367
}
7118371368
}
7118471369
}
7118571370
@@ -71570,11 +71755,11 @@
7157071755
** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
7157171756
** by the various routines that manipulate binary cells. Which
7157271757
** can mean that fillInCell() only initializes the first 2 or 3
7157371758
** bytes of pTmpSpace, but that the first 4 bytes are copied from
7157471759
** it into a database page. This is not actually a problem, but it
71575
- ** does cause a valgrind error when the 1 or 2 bytes of unitialized
71760
+ ** does cause a valgrind error when the 1 or 2 bytes of uninitialized
7157671761
** data is passed to system call write(). So to avoid this error,
7157771762
** zero the first 4 bytes of temp space here.
7157871763
**
7157971764
** Also: Provide four bytes of initialized space before the
7158071765
** beginning of pTmpSpace as an area available to prepend the
@@ -71805,11 +71990,11 @@
7180571990
return n;
7180671991
}
7180771992
7180871993
/*
7180971994
** Return the number of bytes of space at the end of every page that
71810
-** are intentually left unused. This is the "reserved" space that is
71995
+** are intentionally left unused. This is the "reserved" space that is
7181171996
** sometimes used by extensions.
7181271997
**
7181371998
** The value returned is the larger of the current reserve size and
7181471999
** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES.
7181572000
** The amount of reserve can only grow - never shrink.
@@ -72052,11 +72237,10 @@
7205272237
|| pageSize>SQLITE_MAX_PAGE_SIZE
7205372238
|| pageSize<=256
7205472239
){
7205572240
goto page1_init_failed;
7205672241
}
72057
- pBt->btsFlags |= BTS_PAGESIZE_FIXED;
7205872242
assert( (pageSize & 7)==0 );
7205972243
/* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
7206072244
** integer at offset 20 is the number of bytes of space at the end of
7206172245
** each page to reserve for extensions.
7206272246
**
@@ -72072,10 +72256,11 @@
7207272256
** again with the correct page-size.
7207372257
*/
7207472258
releasePageOne(pPage1);
7207572259
pBt->usableSize = usableSize;
7207672260
pBt->pageSize = pageSize;
72261
+ pBt->btsFlags |= BTS_PAGESIZE_FIXED;
7207772262
freeTempSpace(pBt);
7207872263
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
7207972264
pageSize-usableSize);
7208072265
return rc;
7208172266
}
@@ -72091,10 +72276,11 @@
7209172276
** be less than 480. In other words, if the page size is 512, then the
7209272277
** reserved space size cannot exceed 32. */
7209372278
if( usableSize<480 ){
7209472279
goto page1_init_failed;
7209572280
}
72281
+ pBt->btsFlags |= BTS_PAGESIZE_FIXED;
7209672282
pBt->pageSize = pageSize;
7209772283
pBt->usableSize = usableSize;
7209872284
#ifndef SQLITE_OMIT_AUTOVACUUM
7209972285
pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
7210072286
pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
@@ -72269,11 +72455,15 @@
7226972455
** One or the other of the two processes must give way or there can be
7227072456
** no progress. By returning SQLITE_BUSY and not invoking the busy callback
7227172457
** when A already has a read lock, we encourage A to give up and let B
7227272458
** proceed.
7227372459
*/
72274
-SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
72460
+static SQLITE_NOINLINE int btreeBeginTrans(
72461
+ Btree *p, /* The btree in which to start the transaction */
72462
+ int wrflag, /* True to start a write transaction */
72463
+ int *pSchemaVersion /* Put schema version number here, if not NULL */
72464
+){
7227572465
BtShared *pBt = p->pBt;
7227672466
Pager *pPager = pBt->pPager;
7227772467
int rc = SQLITE_OK;
7227872468
7227972469
sqlite3BtreeEnter(p);
@@ -72440,10 +72630,32 @@
7244072630
}
7244172631
7244272632
btreeIntegrity(p);
7244372633
sqlite3BtreeLeave(p);
7244472634
return rc;
72635
+}
72636
+SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
72637
+ BtShared *pBt;
72638
+ if( p->sharable
72639
+ || p->inTrans==TRANS_NONE
72640
+ || (p->inTrans==TRANS_READ && wrflag!=0)
72641
+ ){
72642
+ return btreeBeginTrans(p,wrflag,pSchemaVersion);
72643
+ }
72644
+ pBt = p->pBt;
72645
+ if( pSchemaVersion ){
72646
+ *pSchemaVersion = get4byte(&pBt->pPage1->aData[40]);
72647
+ }
72648
+ if( wrflag ){
72649
+ /* This call makes sure that the pager has the correct number of
72650
+ ** open savepoints. If the second parameter is greater than 0 and
72651
+ ** the sub-journal is not already open, then it will be opened here.
72652
+ */
72653
+ return sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
72654
+ }else{
72655
+ return SQLITE_OK;
72656
+ }
7244572657
}
7244672658
7244772659
#ifndef SQLITE_OMIT_AUTOVACUUM
7244872660
7244972661
/*
@@ -73574,11 +73786,11 @@
7357473786
**
7357573787
** This is an optimization. Everything will still work if this
7357673788
** routine always returns 2147483647 (which is the largest record
7357773789
** that SQLite can handle) or more. But returning a smaller value might
7357873790
** prevent large memory allocations when trying to interpret a
73579
-** corrupt datrabase.
73791
+** corrupt database.
7358073792
**
7358173793
** The current implementation merely returns the size of the underlying
7358273794
** database file.
7358373795
*/
7358473796
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){
@@ -74374,11 +74586,11 @@
7437474586
return SQLITE_OK;
7437574587
}
7437674588
/* If the requested key is one more than the previous key, then
7437774589
** try to get there using sqlite3BtreeNext() rather than a full
7437874590
** binary search. This is an optimization only. The correct answer
74379
- ** is still obtained without this case, only a little more slowely */
74591
+ ** is still obtained without this case, only a little more slowly. */
7438074592
if( pCur->info.nKey+1==intKey ){
7438174593
*pRes = 0;
7438274594
rc = sqlite3BtreeNext(pCur, 0);
7438374595
if( rc==SQLITE_OK ){
7438474596
getCellInfo(pCur);
@@ -75557,11 +75769,11 @@
7555775769
return SQLITE_OK;
7555875770
}
7555975771
7556075772
/* Call xParseCell to compute the size of a cell. If the cell contains
7556175773
** overflow, then invoke cellClearOverflow to clear out that overflow.
75562
-** STore the result code (SQLITE_OK or some error code) in rc.
75774
+** Store the result code (SQLITE_OK or some error code) in rc.
7556375775
**
7556475776
** Implemented as macro to force inlining for performance.
7556575777
*/
7556675778
#define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \
7556775779
pPage->xParseCell(pPage, pCell, &sInfo); \
@@ -76236,11 +76448,11 @@
7623676448
** before returning.
7623776449
**
7623876450
** Finally, argument pBegin points to the byte immediately following the
7623976451
** end of the space required by this page for the cell-pointer area (for
7624076452
** all cells - not just those inserted by the current call). If the content
76241
-** area must be extended to before this point in order to accomodate all
76453
+** area must be extended to before this point in order to accommodate all
7624276454
** cells in apCell[], then the cells do not fit and non-zero is returned.
7624376455
*/
7624476456
static int pageInsertArray(
7624576457
MemPage *pPg, /* Page to add cells to */
7624676458
u8 *pBegin, /* End of cell-pointer array */
@@ -76551,11 +76763,11 @@
7655176763
7655276764
/* If this is an auto-vacuum database, update the pointer map
7655376765
** with entries for the new page, and any pointer from the
7655476766
** cell on the page to an overflow page. If either of these
7655576767
** operations fails, the return code is set, but the contents
76556
- ** of the parent page are still manipulated by thh code below.
76768
+ ** of the parent page are still manipulated by the code below.
7655776769
** That is Ok, at this point the parent page is guaranteed to
7655876770
** be marked as dirty. Returning an error code will cause a
7655976771
** rollback, undoing any changes made to the parent page.
7656076772
*/
7656176773
if( ISAUTOVACUUM(pBt) ){
@@ -77141,11 +77353,11 @@
7714177353
rc = SQLITE_CORRUPT_BKPT;
7714277354
goto balance_cleanup;
7714377355
}
7714477356
}
7714577357
77146
- /* Sanity check: For a non-corrupt database file one of the follwing
77358
+ /* Sanity check: For a non-corrupt database file one of the following
7714777359
** must be true:
7714877360
** (1) We found one or more cells (cntNew[0])>0), or
7714977361
** (2) pPage is a virtual root page. A virtual root page is when
7715077362
** the real root page is page 1 and we are the only child of
7715177363
** that page.
@@ -77758,11 +77970,11 @@
7775877970
int iOffset, /* Offset of first byte to write */
7775977971
int iAmt /* Number of bytes to be written */
7776077972
){
7776177973
int nData = pX->nData - iOffset;
7776277974
if( nData<=0 ){
77763
- /* Overwritting with zeros */
77975
+ /* Overwriting with zeros */
7776477976
int i;
7776577977
for(i=0; i<iAmt && pDest[i]==0; i++){}
7776677978
if( i<iAmt ){
7776777979
int rc = sqlite3PagerWrite(pPage->pDbPage);
7776877980
if( rc ) return rc;
@@ -77794,11 +78006,11 @@
7779478006
** Overwrite the cell that cursor pCur is pointing to with fresh content
7779578007
** contained in pX. In this variant, pCur is pointing to an overflow
7779678008
** cell.
7779778009
*/
7779878010
static SQLITE_NOINLINE int btreeOverwriteOverflowCell(
77799
- BtCursor *pCur, /* Cursor pointing to cell to ovewrite */
78011
+ BtCursor *pCur, /* Cursor pointing to cell to overwrite */
7780078012
const BtreePayload *pX /* Content to write into the cell */
7780178013
){
7780278014
int iOffset; /* Next byte of pX->pData to write */
7780378015
int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
7780478016
int rc; /* Return code */
@@ -78541,11 +78753,11 @@
7854178753
static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){
7854278754
BtShared *pBt = p->pBt;
7854378755
MemPage *pRoot;
7854478756
Pgno pgnoRoot;
7854578757
int rc;
78546
- int ptfFlags; /* Page-type flage for the root page of new table */
78758
+ int ptfFlags; /* Page-type flags for the root page of new table */
7854778759
7854878760
assert( sqlite3BtreeHoldsMutex(p) );
7854978761
assert( pBt->inTransaction==TRANS_WRITE );
7855078762
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
7855178763
@@ -79376,11 +79588,11 @@
7937679588
pBt = pCheck->pBt;
7937779589
usableSize = pBt->usableSize;
7937879590
if( iPage==0 ) return 0;
7937979591
if( checkRef(pCheck, iPage) ) return 0;
7938079592
pCheck->zPfx = "Tree %u page %u: ";
79381
- pCheck->v0 = pCheck->v1 = iPage;
79593
+ pCheck->v1 = iPage;
7938279594
if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
7938379595
checkAppendMsg(pCheck,
7938479596
"unable to get the page. error code=%d", rc);
7938579597
goto end_of_check;
7938679598
}
@@ -79713,10 +79925,11 @@
7971379925
#ifndef SQLITE_OMIT_AUTOVACUUM
7971479926
if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
7971579927
checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
7971679928
}
7971779929
#endif
79930
+ sCheck.v0 = aRoot[i];
7971879931
checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
7971979932
}
7972079933
pBt->db->flags = savedDbFlags;
7972179934
7972279935
/* Make sure every page in the file is referenced
@@ -82256,10 +82469,11 @@
8225682469
if( pRec==0 ) return 0;
8225782470
p->ppRec[0] = pRec;
8225882471
}
8225982472
8226082473
pRec->nField = p->iVal+1;
82474
+ sqlite3VdbeMemSetNull(&pRec->aMem[p->iVal]);
8226182475
return &pRec->aMem[p->iVal];
8226282476
}
8226382477
#else
8226482478
UNUSED_PARAMETER(p);
8226582479
#endif /* defined(SQLITE_ENABLE_STAT4) */
@@ -83652,11 +83866,11 @@
8365283866
assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
8365383867
p->readOnly = 1;
8365483868
p->bIsReader = 0;
8365583869
pOp = &p->aOp[p->nOp-1];
8365683870
assert( p->aOp[0].opcode==OP_Init );
83657
- while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
83871
+ while( 1 /* Loop terminates when it reaches the OP_Init opcode */ ){
8365883872
/* Only JUMP opcodes and the short list of special opcodes in the switch
8365983873
** below need to be considered. The mkopcodeh.tcl generator script groups
8366083874
** all these opcodes together near the front of the opcode list. Skip
8366183875
** any opcode that does not need processing by virtual of the fact that
8366283876
** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -84106,11 +84320,11 @@
8410684320
}
8410784321
8410884322
8410984323
/*
8411084324
** If the input FuncDef structure is ephemeral, then free it. If
84111
-** the FuncDef is not ephermal, then do nothing.
84325
+** the FuncDef is not ephemeral, then do nothing.
8411284326
*/
8411384327
static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
8411484328
assert( db!=0 );
8411584329
if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
8411684330
sqlite3DbNNFreeNN(db, pDef);
@@ -87057,10 +87271,19 @@
8705787271
** sqlite3VdbeSerialTypeLen() in the common case.
8705887272
*/
8705987273
if( d1+(u64)serial_type1+2>(u64)nKey1
8706087274
&& d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)>(u64)nKey1
8706187275
){
87276
+ if( serial_type1>=1
87277
+ && serial_type1<=7
87278
+ && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)<=(u64)nKey1+8
87279
+ && CORRUPT_DB
87280
+ ){
87281
+ return 1; /* corrupt record not detected by
87282
+ ** sqlite3VdbeRecordCompareWithSkip(). Return true
87283
+ ** to avoid firing the assert() */
87284
+ }
8706287285
break;
8706387286
}
8706487287
8706587288
/* Extract the values to be compared.
8706687289
*/
@@ -87500,11 +87723,11 @@
8750087723
serial_type = aKey1[idx1];
8750187724
if( serial_type>=10 ){
8750287725
/* Serial types 12 or greater are strings and blobs (greater than
8750387726
** numbers). Types 10 and 11 are currently "reserved for future
8750487727
** use", so it doesn't really matter what the results of comparing
87505
- ** them to numberic values are. */
87728
+ ** them to numeric values are. */
8750687729
rc = serial_type==10 ? -1 : +1;
8750787730
}else if( serial_type==0 ){
8750887731
rc = -1;
8750987732
}else{
8751087733
sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
@@ -89129,11 +89352,11 @@
8912989352
8913089353
/*
8913189354
** The destructor function for a ValueList object. This needs to be
8913289355
** a separate function, unknowable to the application, to ensure that
8913389356
** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not
89134
-** preceeded by activation of IN processing via sqlite3_vtab_int() do not
89357
+** preceded by activation of IN processing via sqlite3_vtab_int() do not
8913589358
** try to access a fake ValueList object inserted by a hostile extension.
8913689359
*/
8913789360
SQLITE_PRIVATE void sqlite3VdbeValueListFree(void *pToDelete){
8913889361
sqlite3_free(pToDelete);
8913989362
}
@@ -89458,11 +89681,11 @@
8945889681
** sqlite3_column_text()
8945989682
** sqlite3_column_text16()
8946089683
** sqlite3_column_real()
8946189684
** sqlite3_column_bytes()
8946289685
** sqlite3_column_bytes16()
89463
-** sqiite3_column_blob()
89686
+** sqlite3_column_blob()
8946489687
*/
8946589688
static void columnMallocFailure(sqlite3_stmt *pStmt)
8946689689
{
8946789690
/* If malloc() failed during an encoding conversion within an
8946889691
** sqlite3_column_XXX API, then set the return code of the statement to
@@ -89693,11 +89916,11 @@
8969389916
** Routines used to attach values to wildcards in a compiled SQL statement.
8969489917
*/
8969589918
/*
8969689919
** Unbind the value bound to variable i in virtual machine p. This is the
8969789920
** the same as binding a NULL value to the column. If the "i" parameter is
89698
-** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
89921
+** out of range, then SQLITE_RANGE is returned. Otherwise SQLITE_OK.
8969989922
**
8970089923
** A successful evaluation of this routine acquires the mutex on p.
8970189924
** the mutex is released if any kind of error occurs.
8970289925
**
8970389926
** The error code stored in database p->db is overwritten with the return
@@ -91669,12 +91892,12 @@
9166991892
** to the current line should be indented for EXPLAIN output.
9167091893
*/
9167191894
case OP_Goto: { /* jump */
9167291895
9167391896
#ifdef SQLITE_DEBUG
91674
- /* In debuggging mode, when the p5 flags is set on an OP_Goto, that
91675
- ** means we should really jump back to the preceeding OP_ReleaseReg
91897
+ /* In debugging mode, when the p5 flags is set on an OP_Goto, that
91898
+ ** means we should really jump back to the preceding OP_ReleaseReg
9167691899
** instruction. */
9167791900
if( pOp->p5 ){
9167891901
assert( pOp->p2 < (int)(pOp - aOp) );
9167991902
assert( pOp->p2 > 1 );
9168091903
pOp = &aOp[pOp->p2 - 2];
@@ -91878,11 +92101,11 @@
9187892101
** If P4 is not null then it is an error message string.
9187992102
**
9188092103
** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
9188192104
**
9188292105
** 0: (no change)
91883
-** 1: NOT NULL contraint failed: P4
92106
+** 1: NOT NULL constraint failed: P4
9188492107
** 2: UNIQUE constraint failed: P4
9188592108
** 3: CHECK constraint failed: P4
9188692109
** 4: FOREIGN KEY constraint failed: P4
9188792110
**
9188892111
** If P5 is not zero and P4 is NULL, then everything after the ":" is
@@ -95105,11 +95328,11 @@
9510595328
aMem[pOp->p3].n = 0;
9510695329
aMem[pOp->p3].z = "";
9510795330
}
9510895331
pCx = p->apCsr[pOp->p1];
9510995332
if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){
95110
- /* If the ephermeral table is already open and has no duplicates from
95333
+ /* If the ephemeral table is already open and has no duplicates from
9511195334
** OP_OpenDup, then erase all existing content so that the table is
9511295335
** empty again, rather than creating a new table. */
9511395336
assert( pCx->isEphemeral );
9511495337
pCx->seqCount = 0;
9511595338
pCx->cacheStatus = CACHE_STALE;
@@ -95596,19 +95819,19 @@
9559695819
** The This.P5 parameter is a flag that indicates what to do if the
9559795820
** cursor ends up pointing at a valid row that is past the target
9559895821
** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If
9559995822
** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
9560095823
** case occurs when there are no inequality constraints to the right of
95601
-** the IN constraing. The jump to SeekGE.P2 ends the loop. The P5!=0 case
95824
+** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case
9560295825
** occurs when there are inequality constraints to the right of the IN
9560395826
** operator. In that case, the This.P2 will point either directly to or
9560495827
** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for
9560595828
** loop terminate.
9560695829
**
9560795830
** Possible outcomes from this opcode:<ol>
9560895831
**
95609
-** <li> If the cursor is initally not pointed to any valid row, then
95832
+** <li> If the cursor is initially not pointed to any valid row, then
9561095833
** fall through into the subsequent OP_SeekGE opcode.
9561195834
**
9561295835
** <li> If the cursor is left pointing to a row that is before the target
9561395836
** row, even after making as many as This.P1 calls to
9561495837
** sqlite3BtreeNext(), then also fall through into OP_SeekGE.
@@ -98277,11 +98500,11 @@
9827798500
#endif
9827898501
9827998502
/* If this function is inside of a trigger, the register array in aMem[]
9828098503
** might change from one evaluation to the next. The next block of code
9828198504
** checks to see if the register array has changed, and if so it
98282
- ** reinitializes the relavant parts of the sqlite3_context object */
98505
+ ** reinitializes the relevant parts of the sqlite3_context object */
9828398506
if( pCtx->pMem != pMem ){
9828498507
pCtx->pMem = pMem;
9828598508
for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
9828698509
}
9828798510
@@ -99155,11 +99378,11 @@
9915599378
** invocation of this opcode.
9915699379
**
9915799380
** This opcode works exactly like OP_Function. The only difference is in
9915899381
** its name. This opcode is used in places where the function must be
9915999382
** purely non-deterministic. Some built-in date/time functions can be
99160
-** either determinitic of non-deterministic, depending on their arguments.
99383
+** either deterministic of non-deterministic, depending on their arguments.
9916199384
** When those function are used in a non-deterministic way, they will check
9916299385
** to see if they were called using OP_PureFunc instead of OP_Function, and
9916399386
** if they were, they throw an error.
9916499387
**
9916599388
** See also: AggStep, AggFinal, Function
@@ -99173,11 +99396,11 @@
9917399396
pCtx = pOp->p4.pCtx;
9917499397
9917599398
/* If this function is inside of a trigger, the register array in aMem[]
9917699399
** might change from one evaluation to the next. The next block of code
9917799400
** checks to see if the register array has changed, and if so it
99178
- ** reinitializes the relavant parts of the sqlite3_context object */
99401
+ ** reinitializes the relevant parts of the sqlite3_context object */
9917999402
pOut = &aMem[pOp->p3];
9918099403
if( pCtx->pOut != pOut ){
9918199404
pCtx->pVdbe = p;
9918299405
pCtx->pOut = pOut;
9918399406
pCtx->enc = encoding;
@@ -99249,11 +99472,11 @@
9924999472
registerTrace(ii, &aMem[ii]);
9925099473
}
9925199474
printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
9925299475
}
9925399476
#endif
99254
- h %= pIn1->n;
99477
+ h %= (pIn1->n*8);
9925599478
pIn1->z[h/8] |= 1<<(h&7);
9925699479
break;
9925799480
}
9925899481
9925999482
/* Opcode: Filter P1 P2 P3 P4 *
@@ -99285,11 +99508,11 @@
9928599508
registerTrace(ii, &aMem[ii]);
9928699509
}
9928799510
printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
9928899511
}
9928999512
#endif
99290
- h %= pIn1->n;
99513
+ h %= (pIn1->n*8);
9929199514
if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){
9929299515
VdbeBranchTaken(1, 2);
9929399516
p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++;
9929499517
goto jump_to_p2;
9929599518
}else{
@@ -99537,11 +99760,11 @@
9953799760
if( opProperty & OPFLG_OUT3 ){
9953899761
registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
9953999762
}
9954099763
if( opProperty==0xff ){
9954199764
/* Never happens. This code exists to avoid a harmless linkage
99542
- ** warning aboud sqlite3VdbeRegisterDump() being defined but not
99765
+ ** warning about sqlite3VdbeRegisterDump() being defined but not
9954399766
** used. */
9954499767
sqlite3VdbeRegisterDump(p);
9954599768
}
9954699769
}
9954799770
#endif /* SQLITE_DEBUG */
@@ -100255,11 +100478,11 @@
100255100478
** merging two or more level-0 PMAs together creates a level-1 PMA.
100256100479
**
100257100480
** The threshold for the amount of main memory to use before flushing
100258100481
** records to a PMA is roughly the same as the limit configured for the
100259100482
** page-cache of the main database. Specifically, the threshold is set to
100260
-** the value returned by "PRAGMA main.page_size" multipled by
100483
+** the value returned by "PRAGMA main.page_size" multiplied by
100261100484
** that returned by "PRAGMA main.cache_size", in bytes.
100262100485
**
100263100486
** If the sorter is running in single-threaded mode, then all PMAs generated
100264100487
** are appended to a single temporary file. Or, if the sorter is running in
100265100488
** multi-threaded mode then up to (N+1) temporary files may be opened, where
@@ -100278,11 +100501,11 @@
100278100501
** final PMA. So at this point the data is stored in some number of sorted
100279100502
** PMAs within temporary files on disk.
100280100503
**
100281100504
** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the
100282100505
** sorter is running in single-threaded mode, then these PMAs are merged
100283
-** incrementally as keys are retreived from the sorter by the VDBE. The
100506
+** incrementally as keys are retrieved from the sorter by the VDBE. The
100284100507
** MergeEngine object, described in further detail below, performs this
100285100508
** merge.
100286100509
**
100287100510
** Or, if running in multi-threaded mode, then a background thread is
100288100511
** launched to merge the existing PMAs. Once the background thread has
@@ -100441,11 +100664,11 @@
100441100664
** single-threaded operation, there is exactly one instance of this object
100442100665
** and for multi-threaded operation there are two or more instances.
100443100666
**
100444100667
** Essentially, this structure contains all those fields of the VdbeSorter
100445100668
** structure for which each thread requires a separate instance. For example,
100446
-** each thread requries its own UnpackedRecord object to unpack records in
100669
+** each thread requeries its own UnpackedRecord object to unpack records in
100447100670
** as part of comparison operations.
100448100671
**
100449100672
** Before a background thread is launched, variable bDone is set to 0. Then,
100450100673
** right before it exits, the thread itself sets bDone to 1. This is used for
100451100674
** two purposes:
@@ -100513,11 +100736,11 @@
100513100736
/*
100514100737
** An instance of the following object is used to read records out of a
100515100738
** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
100516100739
** aKey might point into aMap or into aBuffer. If neither of those locations
100517100740
** contain a contiguous representation of the key, then aAlloc is allocated
100518
-** and the key is copied into aAlloc and aKey is made to poitn to aAlloc.
100741
+** and the key is copied into aAlloc and aKey is made to point to aAlloc.
100519100742
**
100520100743
** pFd==0 at EOF.
100521100744
*/
100522100745
struct PmaReader {
100523100746
i64 iReadOff; /* Current read offset */
@@ -101884,11 +102107,11 @@
101884102107
** records to disk. If the sorter is running in multi-threaded mode,
101885102108
** round-robin between the first (pSorter->nTask-1) tasks. Except, if
101886102109
** the background thread from a sub-tasks previous turn is still running,
101887102110
** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy,
101888102111
** fall back to using the final sub-task. The first (pSorter->nTask-1)
101889
- ** sub-tasks are prefered as they use background threads - the final
102112
+ ** sub-tasks are preferred as they use background threads - the final
101890102113
** sub-task uses the main thread. */
101891102114
for(i=0; i<nWorker; i++){
101892102115
int iTest = (pSorter->iPrev + i + 1) % nWorker;
101893102116
pTask = &pSorter->aTask[iTest];
101894102117
if( pTask->bDone ){
@@ -102368,11 +102591,11 @@
102368102591
/* eMode is always INCRINIT_NORMAL in single-threaded mode */
102369102592
assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
102370102593
102371102594
rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
102372102595
102373
- /* Set up the required files for pIncr. A multi-theaded IncrMerge object
102596
+ /* Set up the required files for pIncr. A multi-threaded IncrMerge object
102374102597
** requires two temp files to itself, whereas a single-threaded object
102375102598
** only requires a region of pTask->file2. */
102376102599
if( rc==SQLITE_OK ){
102377102600
int mxSz = pIncr->mxSz;
102378102601
#if SQLITE_MAX_WORKER_THREADS>0
@@ -104033,11 +104256,11 @@
104033104256
}while( p!=0 );
104034104257
return WRC_Continue;
104035104258
}
104036104259
104037104260
/* Increase the walkerDepth when entering a subquery, and
104038
-** descrease when leaving the subquery.
104261
+** decrease when leaving the subquery.
104039104262
*/
104040104263
SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){
104041104264
UNUSED_PARAMETER(pSelect);
104042104265
pWalker->walkerDepth++;
104043104266
return WRC_Continue;
@@ -105767,11 +105990,11 @@
105767105990
if( sqlite3ResolveExprNames(pNC, pE) ){
105768105991
return 1;
105769105992
}
105770105993
for(j=0; j<pSelect->pEList->nExpr; j++){
105771105994
if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
105772
- /* Since this expresion is being changed into a reference
105995
+ /* Since this expression is being changed into a reference
105773105996
** to an identical expression in the result set, remove all Window
105774105997
** objects belonging to the expression from the Select.pWin list. */
105775105998
windowRemoveExprFromSelect(pSelect, pE);
105776105999
pItem->u.x.iOrderByCol = j+1;
105777106000
}
@@ -106154,11 +106377,11 @@
106154106377
return WRC_Continue;
106155106378
}
106156106379
106157106380
/*
106158106381
** Resolve all names in all expressions of a SELECT and in all
106159
-** decendents of the SELECT, including compounds off of p->pPrior,
106382
+** descendants of the SELECT, including compounds off of p->pPrior,
106160106383
** subqueries in expressions, and subqueries used as FROM clause
106161106384
** terms.
106162106385
**
106163106386
** See sqlite3ResolveExprNames() for a description of the kinds of
106164106387
** transformations that occur.
@@ -106304,10 +106527,11 @@
106304106527
}
106305106528
#endif
106306106529
if( op==TK_SELECT_COLUMN ){
106307106530
assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
106308106531
assert( pExpr->iColumn < pExpr->iTable );
106532
+ assert( pExpr->iColumn >= 0 );
106309106533
assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
106310106534
return sqlite3ExprAffinity(
106311106535
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
106312106536
);
106313106537
}
@@ -106540,11 +106764,11 @@
106540106764
}
106541106765
106542106766
/*
106543106767
** Return the collation sequence for the expression pExpr. If
106544106768
** there is no defined collating sequence, return a pointer to the
106545
-** defautl collation sequence.
106769
+** default collation sequence.
106546106770
**
106547106771
** See also: sqlite3ExprCollSeq()
106548106772
**
106549106773
** The sqlite3ExprCollSeq() routine works the same except that it
106550106774
** returns NULL if there is no defined collation.
@@ -106670,11 +106894,11 @@
106670106894
}
106671106895
}
106672106896
return pColl;
106673106897
}
106674106898
106675
-/* Expresssion p is a comparison operator. Return a collation sequence
106899
+/* Expression p is a comparison operator. Return a collation sequence
106676106900
** appropriate for the comparison operator.
106677106901
**
106678106902
** This is normally just a wrapper around sqlite3BinaryCompareCollSeq().
106679106903
** However, if the OP_Commuted flag is set, then the order of the operands
106680106904
** is reversed in the sqlite3BinaryCompareCollSeq() call so that the
@@ -107586,11 +107810,11 @@
107586107810
}
107587107811
107588107812
/*
107589107813
** Arrange to cause pExpr to be deleted when the pParse is deleted.
107590107814
** This is similar to sqlite3ExprDelete() except that the delete is
107591
-** deferred untilthe pParse is deleted.
107815
+** deferred until the pParse is deleted.
107592107816
**
107593107817
** The pExpr might be deleted immediately on an OOM error.
107594107818
**
107595107819
** The deferred delete is (currently) implemented by adding the
107596107820
** pExpr to the pParse->pConstExpr list with a register number of 0.
@@ -108428,11 +108652,11 @@
108428108652
/*
108429108653
** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE
108430108654
** and 0 if it is FALSE.
108431108655
*/
108432108656
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
108433
- pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
108657
+ pExpr = sqlite3ExprSkipCollateAndLikely((Expr*)pExpr);
108434108658
assert( pExpr->op==TK_TRUEFALSE );
108435108659
assert( !ExprHasProperty(pExpr, EP_IntValue) );
108436108660
assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
108437108661
|| sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
108438108662
return pExpr->u.zToken[4]==0;
@@ -109021,11 +109245,11 @@
109021109245
**
109022109246
** IN_INDEX_ROWID - The cursor was opened on a database table.
109023109247
** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
109024109248
** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index.
109025109249
** IN_INDEX_EPH - The cursor was opened on a specially created and
109026
-** populated epheremal table.
109250
+** populated ephemeral table.
109027109251
** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
109028109252
** implemented as a sequence of comparisons.
109029109253
**
109030109254
** An existing b-tree might be used if the RHS expression pX is a simple
109031109255
** subquery such as:
@@ -109034,11 +109258,11 @@
109034109258
**
109035109259
** If the RHS of the IN operator is a list or a more complex subquery, then
109036109260
** an ephemeral table might need to be generated from the RHS and then
109037109261
** pX->iTable made to point to the ephemeral table instead of an
109038109262
** existing table. In this case, the creation and initialization of the
109039
-** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
109263
+** ephemeral table might be put inside of a subroutine, the EP_Subrtn flag
109040109264
** will be set on pX and the pX->y.sub fields will be set to show where
109041109265
** the subroutine is coded.
109042109266
**
109043109267
** The inFlags parameter must contain, at a minimum, one of the bits
109044109268
** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
@@ -109046,16 +109270,16 @@
109046109270
** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
109047109271
** be used to loop over all values of the RHS of the IN operator.
109048109272
**
109049109273
** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
109050109274
** through the set members) then the b-tree must not contain duplicates.
109051
-** An epheremal table will be created unless the selected columns are guaranteed
109275
+** An ephemeral table will be created unless the selected columns are guaranteed
109052109276
** to be unique - either because it is an INTEGER PRIMARY KEY or due to
109053109277
** a UNIQUE constraint or index.
109054109278
**
109055109279
** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
109056
-** for fast set membership tests) then an epheremal table must
109280
+** for fast set membership tests) then an ephemeral table must
109057109281
** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
109058109282
** index can be found with the specified <columns> as its left-most.
109059109283
**
109060109284
** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and
109061109285
** if the RHS of the IN operator is a list (not a subquery) then this
@@ -109384,11 +109608,11 @@
109384109608
**
109385109609
** x IN (4,5,11) -- IN operator with list on right-hand side
109386109610
** x IN (SELECT a FROM b) -- IN operator with subquery on the right
109387109611
**
109388109612
** The pExpr parameter is the IN operator. The cursor number for the
109389
-** constructed ephermeral table is returned. The first time the ephemeral
109613
+** constructed ephemeral table is returned. The first time the ephemeral
109390109614
** table is computed, the cursor number is also stored in pExpr->iTable,
109391109615
** however the cursor number returned might not be the same, as it might
109392109616
** have been duplicated using OP_OpenDup.
109393109617
**
109394109618
** If the LHS expression ("x" in the examples) is a column value, or
@@ -110231,11 +110455,11 @@
110231110455
ExprClearProperty(p, EP_Skip);
110232110456
}
110233110457
110234110458
/*
110235110459
** Evaluate an expression (either a vector or a scalar expression) and store
110236
-** the result in continguous temporary registers. Return the index of
110460
+** the result in contiguous temporary registers. Return the index of
110237110461
** the first register used to store the result.
110238110462
**
110239110463
** If the returned result register is a temporary scalar, then also write
110240110464
** that register number into *piFreeable. If the returned result register
110241110465
** is not a temporary or if the expression is a vector set *piFreeable
@@ -110271,11 +110495,11 @@
110271110495
** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5)
110272110496
** so that a subsequent copy will not be merged into this one.
110273110497
*/
110274110498
static void setDoNotMergeFlagOnCopy(Vdbe *v){
110275110499
if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){
110276
- sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
110500
+ sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergeable */
110277110501
}
110278110502
}
110279110503
110280110504
/*
110281110505
** Generate code to implement special SQL functions that are implemented
@@ -110361,17 +110585,17 @@
110361110585
target);
110362110586
break;
110363110587
}
110364110588
110365110589
case INLINEFUNC_implies_nonnull_row: {
110366
- /* REsult of sqlite3ExprImpliesNonNullRow() */
110590
+ /* Result of sqlite3ExprImpliesNonNullRow() */
110367110591
Expr *pA1;
110368110592
assert( nFarg==2 );
110369110593
pA1 = pFarg->a[1].pExpr;
110370110594
if( pA1->op==TK_COLUMN ){
110371110595
sqlite3VdbeAddOp2(v, OP_Integer,
110372
- sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable),
110596
+ sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable,1),
110373110597
target);
110374110598
}else{
110375110599
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
110376110600
}
110377110601
break;
@@ -110543,11 +110767,11 @@
110543110767
int iTab = pExpr->iTable;
110544110768
int iReg;
110545110769
if( ExprHasProperty(pExpr, EP_FixedCol) ){
110546110770
/* This COLUMN expression is really a constant due to WHERE clause
110547110771
** constraints, and that constant is coded by the pExpr->pLeft
110548
- ** expresssion. However, make sure the constant has the correct
110772
+ ** expression. However, make sure the constant has the correct
110549110773
** datatype by applying the Affinity of the table column to the
110550110774
** constant.
110551110775
*/
110552110776
int aff;
110553110777
iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
@@ -111272,11 +111496,11 @@
111272111496
** once. If no functions are involved, then factor the code out and put it at
111273111497
** the end of the prepared statement in the initialization section.
111274111498
**
111275111499
** If regDest>=0 then the result is always stored in that register and the
111276111500
** result is not reusable. If regDest<0 then this routine is free to
111277
-** store the value whereever it wants. The register where the expression
111501
+** store the value wherever it wants. The register where the expression
111278111502
** is stored is returned. When regDest<0, two identical expressions might
111279111503
** code to the same register, if they do not contain function calls and hence
111280111504
** are factored out into the initialization section at the end of the
111281111505
** prepared statement.
111282111506
*/
@@ -112190,11 +112414,11 @@
112190112414
** pE1: x>0 pE2: x==5 Result: false
112191112415
** pE1: x=21 pE2: x=21 OR y=43 Result: true
112192112416
** pE1: x!=123 pE2: x IS NOT NULL Result: true
112193112417
** pE1: x!=?1 pE2: x IS NOT NULL Result: true
112194112418
** pE1: x IS NULL pE2: x IS NOT NULL Result: false
112195
-** pE1: x IS ?2 pE2: x IS NOT NULL Reuslt: false
112419
+** pE1: x IS ?2 pE2: x IS NOT NULL Result: false
112196112420
**
112197112421
** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has
112198112422
** Expr.iTable<0 then assume a table number given by iTab.
112199112423
**
112200112424
** If pParse is not NULL, then the values of bound variables in pE1 are
@@ -112226,68 +112450,108 @@
112226112450
){
112227112451
return 1;
112228112452
}
112229112453
return 0;
112230112454
}
112455
+
112456
+/* This is a helper function to impliesNotNullRow(). In this routine,
112457
+** set pWalker->eCode to one only if *both* of the input expressions
112458
+** separately have the implies-not-null-row property.
112459
+*/
112460
+static void bothImplyNotNullRow(Walker *pWalker, Expr *pE1, Expr *pE2){
112461
+ if( pWalker->eCode==0 ){
112462
+ sqlite3WalkExpr(pWalker, pE1);
112463
+ if( pWalker->eCode ){
112464
+ pWalker->eCode = 0;
112465
+ sqlite3WalkExpr(pWalker, pE2);
112466
+ }
112467
+ }
112468
+}
112231112469
112232112470
/*
112233112471
** This is the Expr node callback for sqlite3ExprImpliesNonNullRow().
112234112472
** If the expression node requires that the table at pWalker->iCur
112235112473
** have one or more non-NULL column, then set pWalker->eCode to 1 and abort.
112474
+**
112475
+** pWalker->mWFlags is non-zero if this inquiry is being undertaking on
112476
+** behalf of a RIGHT JOIN (or FULL JOIN). That makes a difference when
112477
+** evaluating terms in the ON clause of an inner join.
112236112478
**
112237112479
** This routine controls an optimization. False positives (setting
112238112480
** pWalker->eCode to 1 when it should not be) are deadly, but false-negatives
112239112481
** (never setting pWalker->eCode) is a harmless missed optimization.
112240112482
*/
112241112483
static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
112242112484
testcase( pExpr->op==TK_AGG_COLUMN );
112243112485
testcase( pExpr->op==TK_AGG_FUNCTION );
112244112486
if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune;
112487
+ if( ExprHasProperty(pExpr, EP_InnerON) && pWalker->mWFlags ){
112488
+ /* If iCur is used in an inner-join ON clause to the left of a
112489
+ ** RIGHT JOIN, that does *not* mean that the table must be non-null.
112490
+ ** But it is difficult to check for that condition precisely.
112491
+ ** To keep things simple, any use of iCur from any inner-join is
112492
+ ** ignored while attempting to simplify a RIGHT JOIN. */
112493
+ return WRC_Prune;
112494
+ }
112245112495
switch( pExpr->op ){
112246112496
case TK_ISNOT:
112247112497
case TK_ISNULL:
112248112498
case TK_NOTNULL:
112249112499
case TK_IS:
112250
- case TK_OR:
112251112500
case TK_VECTOR:
112252
- case TK_CASE:
112253
- case TK_IN:
112254112501
case TK_FUNCTION:
112255112502
case TK_TRUTH:
112503
+ case TK_CASE:
112256112504
testcase( pExpr->op==TK_ISNOT );
112257112505
testcase( pExpr->op==TK_ISNULL );
112258112506
testcase( pExpr->op==TK_NOTNULL );
112259112507
testcase( pExpr->op==TK_IS );
112260
- testcase( pExpr->op==TK_OR );
112261112508
testcase( pExpr->op==TK_VECTOR );
112262
- testcase( pExpr->op==TK_CASE );
112263
- testcase( pExpr->op==TK_IN );
112264112509
testcase( pExpr->op==TK_FUNCTION );
112265112510
testcase( pExpr->op==TK_TRUTH );
112511
+ testcase( pExpr->op==TK_CASE );
112266112512
return WRC_Prune;
112513
+
112267112514
case TK_COLUMN:
112268112515
if( pWalker->u.iCur==pExpr->iTable ){
112269112516
pWalker->eCode = 1;
112270112517
return WRC_Abort;
112271112518
}
112272112519
return WRC_Prune;
112273112520
112521
+ case TK_OR:
112274112522
case TK_AND:
112275
- if( pWalker->eCode==0 ){
112523
+ /* Both sides of an AND or OR must separately imply non-null-row.
112524
+ ** Consider these cases:
112525
+ ** 1. NOT (x AND y)
112526
+ ** 2. x OR y
112527
+ ** If only one of x or y is non-null-row, then the overall expression
112528
+ ** can be true if the other arm is false (case 1) or true (case 2).
112529
+ */
112530
+ testcase( pExpr->op==TK_OR );
112531
+ testcase( pExpr->op==TK_AND );
112532
+ bothImplyNotNullRow(pWalker, pExpr->pLeft, pExpr->pRight);
112533
+ return WRC_Prune;
112534
+
112535
+ case TK_IN:
112536
+ /* Beware of "x NOT IN ()" and "x NOT IN (SELECT 1 WHERE false)",
112537
+ ** both of which can be true. But apart from these cases, if
112538
+ ** the left-hand side of the IN is NULL then the IN itself will be
112539
+ ** NULL. */
112540
+ if( ExprUseXList(pExpr) && ALWAYS(pExpr->x.pList->nExpr>0) ){
112276112541
sqlite3WalkExpr(pWalker, pExpr->pLeft);
112277
- if( pWalker->eCode ){
112278
- pWalker->eCode = 0;
112279
- sqlite3WalkExpr(pWalker, pExpr->pRight);
112280
- }
112281112542
}
112282112543
return WRC_Prune;
112283112544
112284112545
case TK_BETWEEN:
112285
- if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
112286
- assert( pWalker->eCode );
112287
- return WRC_Abort;
112288
- }
112546
+ /* In "x NOT BETWEEN y AND z" either x must be non-null-row or else
112547
+ ** both y and z must be non-null row */
112548
+ assert( ExprUseXList(pExpr) );
112549
+ assert( pExpr->x.pList->nExpr==2 );
112550
+ sqlite3WalkExpr(pWalker, pExpr->pLeft);
112551
+ bothImplyNotNullRow(pWalker, pExpr->x.pList->a[0].pExpr,
112552
+ pExpr->x.pList->a[1].pExpr);
112289112553
return WRC_Prune;
112290112554
112291112555
/* Virtual tables are allowed to use constraints like x=NULL. So
112292112556
** a term of the form x=y does not prove that y is not null if x
112293112557
** is the column of a virtual table */
@@ -112345,26 +112609,27 @@
112345112609
** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
112346112610
** clause requires that some column of the right table of the LEFT JOIN
112347112611
** be non-NULL, then the LEFT JOIN can be safely converted into an
112348112612
** ordinary join.
112349112613
*/
112350
-SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
112614
+SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab, int isRJ){
112351112615
Walker w;
112352112616
p = sqlite3ExprSkipCollateAndLikely(p);
112353112617
if( p==0 ) return 0;
112354112618
if( p->op==TK_NOTNULL ){
112355112619
p = p->pLeft;
112356112620
}else{
112357112621
while( p->op==TK_AND ){
112358
- if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
112622
+ if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab, isRJ) ) return 1;
112359112623
p = p->pRight;
112360112624
}
112361112625
}
112362112626
w.xExprCallback = impliesNotNullRow;
112363112627
w.xSelectCallback = 0;
112364112628
w.xSelectCallback2 = 0;
112365112629
w.eCode = 0;
112630
+ w.mWFlags = isRJ!=0;
112366112631
w.u.iCur = iTab;
112367112632
sqlite3WalkExpr(&w, p);
112368112633
return w.eCode;
112369112634
}
112370112635
@@ -112421,11 +112686,11 @@
112421112686
sqlite3WalkExpr(&w, pExpr);
112422112687
return !w.eCode;
112423112688
}
112424112689
112425112690
112426
-/* Structure used to pass information throught the Walker in order to
112691
+/* Structure used to pass information throughout the Walker in order to
112427112692
** implement sqlite3ReferencesSrcList().
112428112693
*/
112429112694
struct RefSrcList {
112430112695
sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */
112431112696
SrcList *pRef; /* Looking for references to these tables */
@@ -112637,11 +112902,11 @@
112637112902
/*
112638112903
** Search the AggInfo object for an aCol[] entry that has iTable and iColumn.
112639112904
** Return the index in aCol[] of the entry that describes that column.
112640112905
**
112641112906
** If no prior entry is found, create a new one and return -1. The
112642
-** new column will have an idex of pAggInfo->nColumn-1.
112907
+** new column will have an index of pAggInfo->nColumn-1.
112643112908
*/
112644112909
static void findOrCreateAggInfoColumn(
112645112910
Parse *pParse, /* Parsing context */
112646112911
AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */
112647112912
Expr *pExpr /* Expr describing the column to find or insert */
@@ -112650,10 +112915,11 @@
112650112915
int k;
112651112916
112652112917
assert( pAggInfo->iFirstReg==0 );
112653112918
pCol = pAggInfo->aCol;
112654112919
for(k=0; k<pAggInfo->nColumn; k++, pCol++){
112920
+ if( pCol->pCExpr==pExpr ) return;
112655112921
if( pCol->iTable==pExpr->iTable
112656112922
&& pCol->iColumn==pExpr->iColumn
112657112923
&& pExpr->op!=TK_IF_NULL_ROW
112658112924
){
112659112925
goto fix_up_expr;
@@ -114035,11 +114301,11 @@
114035114301
114036114302
return pBest;
114037114303
}
114038114304
114039114305
/*
114040
-** An error occured while parsing or otherwise processing a database
114306
+** An error occurred while parsing or otherwise processing a database
114041114307
** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an
114042114308
** ALTER TABLE RENAME COLUMN program. The error message emitted by the
114043114309
** sub-routine is currently stored in pParse->zErrMsg. This function
114044114310
** adds context to the error message and then stores it in pCtx.
114045114311
*/
@@ -117141,18 +117407,19 @@
117141117407
pSample = &pIdx->aSample[pIdx->nSample];
117142117408
decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0);
117143117409
decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0);
117144117410
decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0);
117145117411
117146
- /* Take a copy of the sample. Add two 0x00 bytes the end of the buffer.
117412
+ /* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer.
117147117413
** This is in case the sample record is corrupted. In that case, the
117148117414
** sqlite3VdbeRecordCompare() may read up to two varints past the
117149117415
** end of the allocated buffer before it realizes it is dealing with
117150
- ** a corrupt record. Adding the two 0x00 bytes prevents this from causing
117416
+ ** a corrupt record. Or it might try to read a large integer from the
117417
+ ** buffer. In any case, eight 0x00 bytes prevents this from causing
117151117418
** a buffer overread. */
117152117419
pSample->n = sqlite3_column_bytes(pStmt, 4);
117153
- pSample->p = sqlite3DbMallocZero(db, pSample->n + 2);
117420
+ pSample->p = sqlite3DbMallocZero(db, pSample->n + 8);
117154117421
if( pSample->p==0 ){
117155117422
sqlite3_finalize(pStmt);
117156117423
return SQLITE_NOMEM_BKPT;
117157117424
}
117158117425
if( pSample->n ){
@@ -118106,11 +118373,11 @@
118106118373
const char *zArg3
118107118374
){
118108118375
sqlite3 *db = pParse->db;
118109118376
int rc;
118110118377
118111
- /* Don't do any authorization checks if the database is initialising
118378
+ /* Don't do any authorization checks if the database is initializing
118112118379
** or if the parser is being invoked from within sqlite3_declare_vtab.
118113118380
*/
118114118381
assert( !IN_RENAME_OBJECT || db->xAuth==0 );
118115118382
if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){
118116118383
return SQLITE_OK;
@@ -118928,11 +119195,11 @@
118928119195
pCol->colFlags |= COLFLAG_HASCOLL;
118929119196
}
118930119197
}
118931119198
118932119199
/*
118933
-** Return the collating squence name for a column
119200
+** Return the collating sequence name for a column
118934119201
*/
118935119202
SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
118936119203
const char *z;
118937119204
if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
118938119205
z = pCol->zCnName;
@@ -119686,11 +119953,11 @@
119686119953
sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
119687119954
return;
119688119955
}
119689119956
if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName);
119690119957
119691
- /* Because keywords GENERATE ALWAYS can be converted into indentifiers
119958
+ /* Because keywords GENERATE ALWAYS can be converted into identifiers
119692119959
** by the parser, we can sometimes end up with a typename that ends
119693119960
** with "generated always". Check for this case and omit the surplus
119694119961
** text. */
119695119962
if( sType.n>=16
119696119963
&& sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
@@ -119907,11 +120174,11 @@
119907120174
*/
119908120175
SQLITE_PRIVATE void sqlite3AddDefaultValue(
119909120176
Parse *pParse, /* Parsing context */
119910120177
Expr *pExpr, /* The parsed expression of the default value */
119911120178
const char *zStart, /* Start of the default value text */
119912
- const char *zEnd /* First character past end of defaut value text */
120179
+ const char *zEnd /* First character past end of default value text */
119913120180
){
119914120181
Table *p;
119915120182
Column *pCol;
119916120183
sqlite3 *db = pParse->db;
119917120184
p = pParse->pNewTable;
@@ -120255,11 +120522,11 @@
120255120522
** which to write into the output buffer. This function copies the
120256120523
** nul-terminated string pointed to by the third parameter, zSignedIdent,
120257120524
** to the specified offset in the buffer and updates *pIdx to refer
120258120525
** to the first byte after the last byte written before returning.
120259120526
**
120260
-** If the string zSignedIdent consists entirely of alpha-numeric
120527
+** If the string zSignedIdent consists entirely of alphanumeric
120261120528
** characters, does not begin with a digit and is not an SQL keyword,
120262120529
** then it is copied to the output buffer exactly as it is. Otherwise,
120263120530
** it is quoted using double-quotes.
120264120531
*/
120265120532
static void identPut(char *z, int *pIdx, char *zSignedIdent){
@@ -120407,11 +120674,11 @@
120407120674
int i;
120408120675
const Column *aCol = pIdx->pTable->aCol;
120409120676
for(i=0; i<pIdx->nColumn; i++){
120410120677
i16 x = pIdx->aiColumn[i];
120411120678
assert( x<pIdx->pTable->nCol );
120412
- wIndex += x<0 ? 1 : aCol[pIdx->aiColumn[i]].szEst;
120679
+ wIndex += x<0 ? 1 : aCol[x].szEst;
120413120680
}
120414120681
pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
120415120682
}
120416120683
120417120684
/* Return true if column number x is any of the first nCol entries of aiCol[].
@@ -122145,11 +122412,11 @@
122145122412
assert( pName && pName->z );
122146122413
122147122414
#ifndef SQLITE_OMIT_TEMPDB
122148122415
/* If the index name was unqualified, check if the table
122149122416
** is a temp table. If so, set the database to 1. Do not do this
122150
- ** if initialising a database schema.
122417
+ ** if initializing a database schema.
122151122418
*/
122152122419
if( !db->init.busy ){
122153122420
pTab = sqlite3SrcListLookup(pParse, pTblName);
122154122421
if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
122155122422
iDb = 1;
@@ -123802,11 +124069,11 @@
123802124069
sqlite3DbFree(db, pCte);
123803124070
}
123804124071
123805124072
/*
123806124073
** This routine is invoked once per CTE by the parser while parsing a
123807
-** WITH clause. The CTE described by teh third argument is added to
124074
+** WITH clause. The CTE described by the third argument is added to
123808124075
** the WITH clause of the second argument. If the second argument is
123809124076
** NULL, then a new WITH argument is created.
123810124077
*/
123811124078
SQLITE_PRIVATE With *sqlite3WithAdd(
123812124079
Parse *pParse, /* Parsing context */
@@ -124446,10 +124713,11 @@
124446124713
Table *pTab;
124447124714
assert( pItem && pSrc->nSrc>=1 );
124448124715
pTab = sqlite3LocateTableItem(pParse, 0, pItem);
124449124716
sqlite3DeleteTable(pParse->db, pItem->pTab);
124450124717
pItem->pTab = pTab;
124718
+ pItem->fg.notCte = 1;
124451124719
if( pTab ){
124452124720
pTab->nTabRef++;
124453124721
if( pItem->fg.isIndexedBy && sqlite3IndexedByLookup(pParse, pItem) ){
124454124722
pTab = 0;
124455124723
}
@@ -124598,11 +124866,11 @@
124598124866
char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
124599124867
){
124600124868
sqlite3 *db = pParse->db;
124601124869
Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */
124602124870
Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
124603
- ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */
124871
+ ExprList *pEList = NULL; /* Expression list containing only pSelectRowid*/
124604124872
SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */
124605124873
Select *pSelect = NULL; /* Complete SELECT tree */
124606124874
Table *pTab;
124607124875
124608124876
/* Check that there isn't an ORDER BY without a LIMIT clause.
@@ -124636,18 +124904,24 @@
124636124904
pEList = sqlite3ExprListAppend(
124637124905
pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
124638124906
);
124639124907
}else{
124640124908
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
124909
+ assert( pPk!=0 );
124910
+ assert( pPk->nKeyCol>=1 );
124641124911
if( pPk->nKeyCol==1 ){
124642
- const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
124912
+ const char *zName;
124913
+ assert( pPk->aiColumn[0]>=0 && pPk->aiColumn[0]<pTab->nCol );
124914
+ zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
124643124915
pLhs = sqlite3Expr(db, TK_ID, zName);
124644124916
pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
124645124917
}else{
124646124918
int i;
124647124919
for(i=0; i<pPk->nKeyCol; i++){
124648
- Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName);
124920
+ Expr *p;
124921
+ assert( pPk->aiColumn[i]>=0 && pPk->aiColumn[i]<pTab->nCol );
124922
+ p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName);
124649124923
pEList = sqlite3ExprListAppend(pParse, pEList, p);
124650124924
}
124651124925
pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
124652124926
if( pLhs ){
124653124927
pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
@@ -124672,11 +124946,11 @@
124672124946
/* generate the SELECT expression tree. */
124673124947
pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
124674124948
pOrderBy,0,pLimit
124675124949
);
124676124950
124677
- /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
124951
+ /* now generate the new WHERE rowid IN clause for the DELETE/UPDATE */
124678124952
pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
124679124953
sqlite3PExprAddSelect(pParse, pInClause, pSelect);
124680124954
return pInClause;
124681124955
}
124682124956
#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */
@@ -126057,11 +126331,11 @@
126057126331
u8 noCase; /* true to ignore case differences */
126058126332
};
126059126333
126060126334
/*
126061126335
** For LIKE and GLOB matching on EBCDIC machines, assume that every
126062
-** character is exactly one byte in size. Also, provde the Utf8Read()
126336
+** character is exactly one byte in size. Also, provide the Utf8Read()
126063126337
** macro for fast reading of the next character in the common case where
126064126338
** the next character is ASCII.
126065126339
*/
126066126340
#if defined(SQLITE_EBCDIC)
126067126341
# define sqlite3Utf8Read(A) (*((*A)++))
@@ -126290,11 +126564,11 @@
126290126564
#endif
126291126565
126292126566
126293126567
/*
126294126568
** Implementation of the like() SQL function. This function implements
126295
-** the build-in LIKE operator. The first argument to the function is the
126569
+** the built-in LIKE operator. The first argument to the function is the
126296126570
** pattern and the second argument is the string. So, the SQL statements:
126297126571
**
126298126572
** A LIKE B
126299126573
**
126300126574
** is implemented as like(B,A).
@@ -126676,11 +126950,11 @@
126676126950
** two arguments. In both cases the first argument is interpreted as text
126677126951
** a text value containing a set of pairs of hexadecimal digits which are
126678126952
** decoded and returned as a blob.
126679126953
**
126680126954
** If there is only a single argument, then it must consist only of an
126681
-** even number of hexadeximal digits. Otherwise, return NULL.
126955
+** even number of hexadecimal digits. Otherwise, return NULL.
126682126956
**
126683126957
** Or, if there is a second argument, then any character that appears in
126684126958
** the second argument is also allowed to appear between pairs of hexadecimal
126685126959
** digits in the first argument. If any other character appears in the
126686126960
** first argument, or if one of the allowed characters appears between
@@ -127376,11 +127650,11 @@
127376127650
assert( argc==1 || argc==2 );
127377127651
(void)argc; /* Suppress unused parameter warning */
127378127652
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
127379127653
pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
127380127654
/* pGCC is always non-NULL since groupConcatStep() will have always
127381
- ** run frist to initialize it */
127655
+ ** run first to initialize it */
127382127656
if( ALWAYS(pGCC) ){
127383127657
int nVS;
127384127658
/* Must call sqlite3_value_text() to convert the argument into text prior
127385127659
** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
127386127660
(void)sqlite3_value_text(argv[0]);
@@ -129579,11 +129853,11 @@
129579129853
** 'E' REAL
129580129854
**
129581129855
** For STRICT tables:
129582129856
** ------------------
129583129857
**
129584
-** Generate an appropropriate OP_TypeCheck opcode that will verify the
129858
+** Generate an appropriate OP_TypeCheck opcode that will verify the
129585129859
** datatypes against the column definitions in pTab. If iReg==0, that
129586129860
** means an OP_MakeRecord opcode has already been generated and should be
129587129861
** the last opcode generated. The new OP_TypeCheck needs to be inserted
129588129862
** before the OP_MakeRecord. The new OP_TypeCheck should use the same
129589129863
** register set as the OP_MakeRecord. If iReg>0 then register iReg is
@@ -130871,11 +131145,11 @@
130871131145
#define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */
130872131146
130873131147
/* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn().
130874131148
* Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this
130875131149
** expression node references any of the
130876
-** columns that are being modifed by an UPDATE statement.
131150
+** columns that are being modified by an UPDATE statement.
130877131151
*/
130878131152
static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){
130879131153
if( pExpr->op==TK_COLUMN ){
130880131154
assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 );
130881131155
if( pExpr->iColumn>=0 ){
@@ -131094,11 +131368,11 @@
131094131368
int ignoreDest, /* Jump to this label on an OE_Ignore resolution */
131095131369
int *pbMayReplace, /* OUT: Set to true if constraint may cause a replace */
131096131370
int *aiChng, /* column i is unchanged if aiChng[i]<0 */
131097131371
Upsert *pUpsert /* ON CONFLICT clauses, if any. NULL otherwise */
131098131372
){
131099
- Vdbe *v; /* VDBE under constrution */
131373
+ Vdbe *v; /* VDBE under construction */
131100131374
Index *pIdx; /* Pointer to one of the indices */
131101131375
Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */
131102131376
sqlite3 *db; /* Database connection */
131103131377
int i; /* loop counter */
131104131378
int ix; /* Index loop counter */
@@ -131577,11 +131851,11 @@
131577131851
*/
131578131852
for(pIdx = indexIteratorFirst(&sIdxIter, &ix);
131579131853
pIdx;
131580131854
pIdx = indexIteratorNext(&sIdxIter, &ix)
131581131855
){
131582
- int regIdx; /* Range of registers hold conent for pIdx */
131856
+ int regIdx; /* Range of registers holding content for pIdx */
131583131857
int regR; /* Range of registers holding conflicting PK */
131584131858
int iThisCur; /* Cursor for this UNIQUE index */
131585131859
int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
131586131860
int addrConflictCk; /* First opcode in the conflict check logic */
131587131861
@@ -132393,11 +132667,11 @@
132393132667
if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
132394132668
return 0; /* Tables have different CHECK constraints. Ticket #2252 */
132395132669
}
132396132670
#endif
132397132671
#ifndef SQLITE_OMIT_FOREIGN_KEY
132398
- /* Disallow the transfer optimization if the destination table constains
132672
+ /* Disallow the transfer optimization if the destination table contains
132399132673
** any foreign key constraints. This is more restrictive than necessary.
132400132674
** But the main beneficiary of the transfer optimization is the VACUUM
132401132675
** command, and the VACUUM command disables foreign key constraints. So
132402132676
** the extra complication to make this rule less restrictive is probably
132403132677
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
@@ -134026,10 +134300,14 @@
134026134300
**
134027134301
** Later (2023-03-25): Save an extra 6 bytes for the filename suffix.
134028134302
** See https://sqlite.org/forum/forumpost/24083b579d.
134029134303
*/
134030134304
if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found;
134305
+
134306
+ /* Do not allow sqlite3_load_extension() to link to a copy of the
134307
+ ** running application, by passing in an empty filename. */
134308
+ if( nMsg==0 ) goto extension_not_found;
134031134309
134032134310
handle = sqlite3OsDlOpen(pVfs, zFile);
134033134311
#if SQLITE_OS_UNIX || SQLITE_OS_WIN
134034134312
for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
134035134313
char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
@@ -135859,11 +136137,11 @@
135859136137
** PRAGMA cache_spill=BOOLEAN
135860136138
** PRAGMA [schema.]cache_spill=N
135861136139
**
135862136140
** The first form reports the current local setting for the
135863136141
** page cache spill size. The second form turns cache spill on
135864
- ** or off. When turnning cache spill on, the size is set to the
136142
+ ** or off. When turning cache spill on, the size is set to the
135865136143
** current cache_size. The third form sets a spill size that
135866136144
** may be different form the cache size.
135867136145
** If N is positive then that is the
135868136146
** number of pages in the cache. If N is negative, then the
135869136147
** number of pages is adjusted so that the cache uses -N kibibytes
@@ -136637,13 +136915,13 @@
136637136915
** Verify the integrity of the database.
136638136916
**
136639136917
** The "quick_check" is reduced version of
136640136918
** integrity_check designed to detect most database corruption
136641136919
** without the overhead of cross-checking indexes. Quick_check
136642
- ** is linear time wherease integrity_check is O(NlogN).
136920
+ ** is linear time whereas integrity_check is O(NlogN).
136643136921
**
136644
- ** The maximum nubmer of errors is 100 by default. A different default
136922
+ ** The maximum number of errors is 100 by default. A different default
136645136923
** can be specified using a numeric parameter N.
136646136924
**
136647136925
** Or, the parameter N can be the name of a table. In that case, only
136648136926
** the one table named is verified. The freelist is only verified if
136649136927
** the named table is "sqlite_schema" (or one of its aliases).
@@ -137397,11 +137675,11 @@
137397137675
int iTabCur; /* Cursor for a table whose size needs checking */
137398137676
HashElem *k; /* Loop over tables of a schema */
137399137677
Schema *pSchema; /* The current schema */
137400137678
Table *pTab; /* A table in the schema */
137401137679
Index *pIdx; /* An index of the table */
137402
- LogEst szThreshold; /* Size threshold above which reanalysis is needd */
137680
+ LogEst szThreshold; /* Size threshold above which reanalysis needed */
137403137681
char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
137404137682
u32 opMask; /* Mask of operations to perform */
137405137683
137406137684
if( zRight ){
137407137685
opMask = (u32)sqlite3Atoi(zRight);
@@ -138523,11 +138801,11 @@
138523138801
** Add a new cleanup operation to a Parser. The cleanup should happen when
138524138802
** the parser object is destroyed. But, beware: the cleanup might happen
138525138803
** immediately.
138526138804
**
138527138805
** Use this mechanism for uncommon cleanups. There is a higher setup
138528
-** cost for this mechansim (an extra malloc), so it should not be used
138806
+** cost for this mechanism (an extra malloc), so it should not be used
138529138807
** for common cleanups that happen on most calls. But for less
138530138808
** common cleanups, we save a single NULL-pointer comparison in
138531138809
** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
138532138810
**
138533138811
** If a memory allocation error occurs, then the cleanup happens immediately.
@@ -139225,11 +139503,11 @@
139225139503
** NATURAL RIGHT OUTER JT_NATURAL|JT_RIGHT|JT_OUTER
139226139504
** NATURAL FULL - JT_NATURAL|JT_LEFT|JT_RIGHT
139227139505
** NATURAL FULL OUTER JT_NATRUAL|JT_LEFT|JT_RIGHT
139228139506
**
139229139507
** To preserve historical compatibly, SQLite also accepts a variety
139230
-** of other non-standard and in many cases non-sensical join types.
139508
+** of other non-standard and in many cases nonsensical join types.
139231139509
** This routine makes as much sense at it can from the nonsense join
139232139510
** type and returns a result. Examples of accepted nonsense join types
139233139511
** include but are not limited to:
139234139512
**
139235139513
** INNER CROSS JOIN -> same as JOIN
@@ -139496,11 +139774,11 @@
139496139774
u32 joinType;
139497139775
139498139776
if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
139499139777
joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
139500139778
139501
- /* If this is a NATURAL join, synthesize an approprate USING clause
139779
+ /* If this is a NATURAL join, synthesize an appropriate USING clause
139502139780
** to specify which columns should be joined.
139503139781
*/
139504139782
if( pRight->fg.jointype & JT_NATURAL ){
139505139783
IdList *pUsing = 0;
139506139784
if( pRight->fg.isUsing || pRight->u3.pOn ){
@@ -139712,11 +139990,11 @@
139712139990
** (2) All output columns are included in the sort record. In that
139713139991
** case regData==regOrigData.
139714139992
** (3) Some output columns are omitted from the sort record due to
139715139993
** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the
139716139994
** SQLITE_ECEL_OMITREF optimization, or due to the
139717
- ** SortCtx.pDeferredRowLoad optimiation. In any of these cases
139995
+ ** SortCtx.pDeferredRowLoad optimization. In any of these cases
139718139996
** regOrigData is 0 to prevent this routine from trying to copy
139719139997
** values that might not yet exist.
139720139998
*/
139721139999
assert( nData==1 || regData==regOrigData || regOrigData==0 );
139722140000
@@ -139768,11 +140046,11 @@
139768140046
memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
139769140047
sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
139770140048
testcase( pKI->nAllField > pKI->nKeyField+2 );
139771140049
pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
139772140050
pKI->nAllField-pKI->nKeyField-1);
139773
- pOp = 0; /* Ensure pOp not used after sqltie3VdbeAddOp3() */
140051
+ pOp = 0; /* Ensure pOp not used after sqlite3VdbeAddOp3() */
139774140052
addrJmp = sqlite3VdbeCurrentAddr(v);
139775140053
sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
139776140054
pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
139777140055
pSort->regReturn = ++pParse->nMem;
139778140056
sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
@@ -139862,11 +140140,11 @@
139862140140
** the ephemeral cursor and proceed.
139863140141
**
139864140142
** The returned value in this case is a copy of parameter iTab.
139865140143
**
139866140144
** WHERE_DISTINCT_ORDERED:
139867
-** In this case rows are being delivered sorted order. The ephermal
140145
+** In this case rows are being delivered sorted order. The ephemeral
139868140146
** table is not required. Instead, the current set of values
139869140147
** is compared against previous row. If they match, the new row
139870140148
** is not distinct and control jumps to VM address addrRepeat. Otherwise,
139871140149
** the VM program proceeds with processing the new row.
139872140150
**
@@ -141287,11 +141565,11 @@
141287141565
/*
141288141566
** pTab is a transient Table object that represents a subquery of some
141289141567
** kind (maybe a parenthesized subquery in the FROM clause of a larger
141290141568
** query, or a VIEW, or a CTE). This routine computes type information
141291141569
** for that Table object based on the Select object that implements the
141292
-** subquery. For the purposes of this routine, "type infomation" means:
141570
+** subquery. For the purposes of this routine, "type information" means:
141293141571
**
141294141572
** * The datatype name, as it might appear in a CREATE TABLE statement
141295141573
** * Which collating sequence to use for the column
141296141574
** * The affinity of the column
141297141575
*/
@@ -141616,11 +141894,11 @@
141616141894
int iCurrent = 0; /* The Current table */
141617141895
int regCurrent; /* Register holding Current table */
141618141896
int iQueue; /* The Queue table */
141619141897
int iDistinct = 0; /* To ensure unique results if UNION */
141620141898
int eDest = SRT_Fifo; /* How to write to Queue */
141621
- SelectDest destQueue; /* SelectDest targetting the Queue table */
141899
+ SelectDest destQueue; /* SelectDest targeting the Queue table */
141622141900
int i; /* Loop counter */
141623141901
int rc; /* Result code */
141624141902
ExprList *pOrderBy; /* The ORDER BY clause */
141625141903
Expr *pLimit; /* Saved LIMIT and OFFSET */
141626141904
int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
@@ -142216,11 +142494,11 @@
142216142494
}
142217142495
}
142218142496
142219142497
/*
142220142498
** Code an output subroutine for a coroutine implementation of a
142221
-** SELECT statment.
142499
+** SELECT statement.
142222142500
**
142223142501
** The data to be output is contained in pIn->iSdst. There are
142224142502
** pIn->nSdst columns to be output. pDest is where the output should
142225142503
** be sent.
142226142504
**
@@ -142438,11 +142716,11 @@
142438142716
** Jump AltB, AeqB, AgtB
142439142717
** End: ...
142440142718
**
142441142719
** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
142442142720
** actually called using Gosub and they do not Return. EofA and EofB loop
142443
-** until all data is exhausted then jump to the "end" labe. AltB, AeqB,
142721
+** until all data is exhausted then jump to the "end" label. AltB, AeqB,
142444142722
** and AgtB jump to either L2 or to one of EofA or EofB.
142445142723
*/
142446142724
#ifndef SQLITE_OMIT_COMPOUND_SELECT
142447142725
static int multiSelectOrderBy(
142448142726
Parse *pParse, /* Parsing context */
@@ -142475,11 +142753,11 @@
142475142753
int regPrev; /* A range of registers to hold previous output */
142476142754
int savedLimit; /* Saved value of p->iLimit */
142477142755
int savedOffset; /* Saved value of p->iOffset */
142478142756
int labelCmpr; /* Label for the start of the merge algorithm */
142479142757
int labelEnd; /* Label for the end of the overall SELECT stmt */
142480
- int addr1; /* Jump instructions that get retargetted */
142758
+ int addr1; /* Jump instructions that get retargeted */
142481142759
int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
142482142760
KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
142483142761
KeyInfo *pKeyMerge; /* Comparison information for merging rows */
142484142762
sqlite3 *db; /* Database connection */
142485142763
ExprList *pOrderBy; /* The ORDER BY clause */
@@ -142844,15 +143122,18 @@
142844143122
pExpr->op = TK_NULL;
142845143123
}else
142846143124
#endif
142847143125
{
142848143126
Expr *pNew;
142849
- int iColumn = pExpr->iColumn;
142850
- Expr *pCopy = pSubst->pEList->a[iColumn].pExpr;
143127
+ int iColumn;
143128
+ Expr *pCopy;
142851143129
Expr ifNullRow;
143130
+ iColumn = pExpr->iColumn;
143131
+ assert( iColumn>=0 );
142852143132
assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr );
142853143133
assert( pExpr->pRight==0 );
143134
+ pCopy = pSubst->pEList->a[iColumn].pExpr;
142854143135
if( sqlite3ExprIsVector(pCopy) ){
142855143136
sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
142856143137
}else{
142857143138
sqlite3 *db = pSubst->pParse->db;
142858143139
if( pSubst->isOuterJoin
@@ -143197,11 +143478,11 @@
143197143478
** (8) If the subquery uses LIMIT then the outer query may not be a join.
143198143479
**
143199143480
** (9) If the subquery uses LIMIT then the outer query may not be aggregate.
143200143481
**
143201143482
** (**) Restriction (10) was removed from the code on 2005-02-05 but we
143202
-** accidently carried the comment forward until 2014-09-15. Original
143483
+** accidentally carried the comment forward until 2014-09-15. Original
143203143484
** constraint: "If the subquery is aggregate then the outer query
143204143485
** may not use LIMIT."
143205143486
**
143206143487
** (11) The subquery and the outer query may not both have ORDER BY clauses.
143207143488
**
@@ -143471,11 +143752,11 @@
143471143752
pParse->zAuthContext = pSubitem->zName;
143472143753
TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
143473143754
testcase( i==SQLITE_DENY );
143474143755
pParse->zAuthContext = zSavedAuthContext;
143475143756
143476
- /* Delete the transient structures associated with thesubquery */
143757
+ /* Delete the transient structures associated with the subquery */
143477143758
pSub1 = pSubitem->pSelect;
143478143759
sqlite3DbFree(db, pSubitem->zDatabase);
143479143760
sqlite3DbFree(db, pSubitem->zName);
143480143761
sqlite3DbFree(db, pSubitem->zAlias);
143481143762
pSubitem->zDatabase = 0;
@@ -143653,11 +143934,11 @@
143653143934
if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
143654143935
/* At this point, any non-zero iOrderByCol values indicate that the
143655143936
** ORDER BY column expression is identical to the iOrderByCol'th
143656143937
** expression returned by SELECT statement pSub. Since these values
143657143938
** do not necessarily correspond to columns in SELECT statement pParent,
143658
- ** zero them before transfering the ORDER BY clause.
143939
+ ** zero them before transferring the ORDER BY clause.
143659143940
**
143660143941
** Not doing this may cause an error if a subsequent call to this
143661143942
** function attempts to flatten a compound sub-query into pParent
143662143943
** (the only way this can happen is if the compound sub-query is
143663143944
** currently part of pSub->pSrc). See ticket [d11a6e908f]. */
@@ -143713,12 +143994,11 @@
143713143994
for(i=0; i<nSubSrc; i++){
143714143995
recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]);
143715143996
}
143716143997
}
143717143998
143718
- /* Finially, delete what is left of the subquery and return
143719
- ** success.
143999
+ /* Finally, delete what is left of the subquery and return success.
143720144000
*/
143721144001
sqlite3AggInfoPersistWalkerInit(&w, pParse);
143722144002
sqlite3WalkSelect(&w,pSub1);
143723144003
sqlite3SelectDelete(db, pSub1);
143724144004
@@ -143749,11 +144029,11 @@
143749144029
Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
143750144030
};
143751144031
143752144032
/*
143753144033
** Add a new entry to the pConst object. Except, do not add duplicate
143754
-** pColumn entires. Also, do not add if doing so would not be appropriate.
144034
+** pColumn entries. Also, do not add if doing so would not be appropriate.
143755144035
**
143756144036
** The caller guarantees the pColumn is a column and pValue is a constant.
143757144037
** This routine has to do some additional checks before completing the
143758144038
** insert.
143759144039
*/
@@ -143935,11 +144215,11 @@
143935144215
** INSERT INTO t1 VALUES(123,'0123');
143936144216
** SELECT * FROM t1 WHERE a=123 AND b=a;
143937144217
** SELECT * FROM t1 WHERE a=123 AND b=123;
143938144218
**
143939144219
** The two SELECT statements above should return different answers. b=a
143940
-** is alway true because the comparison uses numeric affinity, but b=123
144220
+** is always true because the comparison uses numeric affinity, but b=123
143941144221
** is false because it uses text affinity and '0123' is not the same as '123'.
143942144222
** To work around this, the expression tree is not actually changed from
143943144223
** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol
143944144224
** and the "123" value is hung off of the pLeft pointer. Code generator
143945144225
** routines know to generate the constant "123" instead of looking up the
@@ -144019,11 +144299,11 @@
144019144299
** this may change the results of the window functions.
144020144300
**
144021144301
** At the time this function is called it is guaranteed that
144022144302
**
144023144303
** * the sub-query uses only one distinct window frame, and
144024
-** * that the window frame has a PARTITION BY clase.
144304
+** * that the window frame has a PARTITION BY clause.
144025144305
*/
144026144306
static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){
144027144307
assert( pSubq->pWin->pPartition );
144028144308
assert( (pSubq->selFlags & SF_MultiPart)==0 );
144029144309
assert( pSubq->pPrior==0 );
@@ -145527,11 +145807,11 @@
145527145807
assert( pExpr->iAgg>=0 );
145528145808
pCol = &pAggInfo->aCol[pExpr->iAgg];
145529145809
pExpr->op = TK_AGG_COLUMN;
145530145810
pExpr->iTable = pCol->iTable;
145531145811
pExpr->iColumn = pCol->iColumn;
145532
- ExprClearProperty(pExpr, EP_Skip|EP_Collate);
145812
+ ExprClearProperty(pExpr, EP_Skip|EP_Collate|EP_Unlikely);
145533145813
return WRC_Prune;
145534145814
}
145535145815
145536145816
/*
145537145817
** Convert every pAggInfo->aFunc[].pExpr such that any node within
@@ -145558,11 +145838,11 @@
145558145838
** to calling this routine:
145559145839
**
145560145840
** * The aCol[] and aFunc[] arrays may be modified
145561145841
** * The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used
145562145842
**
145563
-** After clling this routine:
145843
+** After calling this routine:
145564145844
**
145565145845
** * The aCol[] and aFunc[] arrays are fixed
145566145846
** * The AggInfoColumnReg() and AggInfoFuncReg() macros may be used
145567145847
**
145568145848
*/
@@ -146212,26 +146492,63 @@
146212146492
/* The expander should have already created transient Table objects
146213146493
** even for FROM clause elements such as subqueries that do not correspond
146214146494
** to a real table */
146215146495
assert( pTab!=0 );
146216146496
146217
- /* Convert LEFT JOIN into JOIN if there are terms of the right table
146218
- ** of the LEFT JOIN used in the WHERE clause.
146497
+ /* Try to simplify joins:
146498
+ **
146499
+ ** LEFT JOIN -> JOIN
146500
+ ** RIGHT JOIN -> JOIN
146501
+ ** FULL JOIN -> RIGHT JOIN
146502
+ **
146503
+ ** If terms of the i-th table are used in the WHERE clause in such a
146504
+ ** way that the i-th table cannot be the NULL row of a join, then
146505
+ ** perform the appropriate simplification. This is called
146506
+ ** "OUTER JOIN strength reduction" in the SQLite documentation.
146219146507
*/
146220
- if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==JT_LEFT
146221
- && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor)
146508
+ if( (pItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
146509
+ && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor,
146510
+ pItem->fg.jointype & JT_LTORJ)
146222146511
&& OptimizationEnabled(db, SQLITE_SimplifyJoin)
146223146512
){
146224
- TREETRACE(0x1000,pParse,p,
146225
- ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
146226
- pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
146513
+ if( pItem->fg.jointype & JT_LEFT ){
146514
+ if( pItem->fg.jointype & JT_RIGHT ){
146515
+ TREETRACE(0x1000,pParse,p,
146516
+ ("FULL-JOIN simplifies to RIGHT-JOIN on term %d\n",i));
146517
+ pItem->fg.jointype &= ~JT_LEFT;
146518
+ }else{
146519
+ TREETRACE(0x1000,pParse,p,
146520
+ ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
146521
+ pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
146522
+ }
146523
+ }
146524
+ if( pItem->fg.jointype & JT_LTORJ ){
146525
+ for(j=i+1; j<pTabList->nSrc; j++){
146526
+ SrcItem *pI2 = &pTabList->a[j];
146527
+ if( pI2->fg.jointype & JT_RIGHT ){
146528
+ if( pI2->fg.jointype & JT_LEFT ){
146529
+ TREETRACE(0x1000,pParse,p,
146530
+ ("FULL-JOIN simplifies to LEFT-JOIN on term %d\n",j));
146531
+ pI2->fg.jointype &= ~JT_RIGHT;
146532
+ }else{
146533
+ TREETRACE(0x1000,pParse,p,
146534
+ ("RIGHT-JOIN simplifies to JOIN on term %d\n",j));
146535
+ pI2->fg.jointype &= ~(JT_RIGHT|JT_OUTER);
146536
+ }
146537
+ }
146538
+ }
146539
+ for(j=pTabList->nSrc-1; j>=i; j--){
146540
+ pTabList->a[j].fg.jointype &= ~JT_LTORJ;
146541
+ if( pTabList->a[j].fg.jointype & JT_RIGHT ) break;
146542
+ }
146543
+ }
146227146544
assert( pItem->iCursor>=0 );
146228146545
unsetJoinExpr(p->pWhere, pItem->iCursor,
146229146546
pTabList->a[0].fg.jointype & JT_LTORJ);
146230146547
}
146231146548
146232
- /* No futher action if this term of the FROM clause is not a subquery */
146549
+ /* No further action if this term of the FROM clause is not a subquery */
146233146550
if( pSub==0 ) continue;
146234146551
146235146552
/* Catch mismatch in the declared columns of a view and the number of
146236146553
** columns in the SELECT on the RHS */
146237146554
if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -146481,11 +146798,11 @@
146481146798
sqlite3VdbeJumpHere(v, addrTop-1);
146482146799
sqlite3ClearTempRegCache(pParse);
146483146800
}else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){
146484146801
/* This is a CTE for which materialization code has already been
146485146802
** generated. Invoke the subroutine to compute the materialization,
146486
- ** the make the pItem->iCursor be a copy of the ephemerial table that
146803
+ ** the make the pItem->iCursor be a copy of the ephemeral table that
146487146804
** holds the result of the materialization. */
146488146805
CteUse *pCteUse = pItem->u2.pCteUse;
146489146806
sqlite3VdbeAddOp2(v, OP_Gosub, pCteUse->regRtn, pCteUse->addrM9e);
146490146807
if( pItem->iCursor!=pCteUse->iCur ){
146491146808
sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur);
@@ -146864,11 +147181,11 @@
146864147181
/* Processing for aggregates with GROUP BY is very different and
146865147182
** much more complex than aggregates without a GROUP BY.
146866147183
*/
146867147184
if( pGroupBy ){
146868147185
KeyInfo *pKeyInfo; /* Keying information for the group by clause */
146869
- int addr1; /* A-vs-B comparision jump */
147186
+ int addr1; /* A-vs-B comparison jump */
146870147187
int addrOutputRow; /* Start of subroutine that outputs a result row */
146871147188
int regOutputRow; /* Return address register for output subroutine */
146872147189
int addrSetAbort; /* Set the abort flag and return */
146873147190
int addrTopOfLoop; /* Top of the input loop */
146874147191
int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
@@ -149244,11 +149561,11 @@
149244149561
pSrc = sqlite3SrcListDup(db, pTabList, 0);
149245149562
pWhere2 = sqlite3ExprDup(db, pWhere, 0);
149246149563
149247149564
assert( pTabList->nSrc>1 );
149248149565
if( pSrc ){
149249
- pSrc->a[0].fg.notCte = 1;
149566
+ assert( pSrc->a[0].fg.notCte );
149250149567
pSrc->a[0].iCursor = -1;
149251149568
pSrc->a[0].pTab->nTabRef--;
149252149569
pSrc->a[0].pTab = 0;
149253149570
}
149254149571
if( pPk ){
@@ -150231,11 +150548,11 @@
150231150548
const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
150232150549
WhereInfo *pWInfo = 0;
150233150550
int nArg = 2 + pTab->nCol; /* Number of arguments to VUpdate */
150234150551
int regArg; /* First register in VUpdate arg array */
150235150552
int regRec; /* Register in which to assemble record */
150236
- int regRowid; /* Register for ephem table rowid */
150553
+ int regRowid; /* Register for ephemeral table rowid */
150237150554
int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */
150238150555
int aDummy[2]; /* Unused arg for sqlite3WhereOkOnePass() */
150239150556
int eOnePass; /* True to use onepass strategy */
150240150557
int addr; /* Address of OP_OpenEphemeral */
150241150558
@@ -150352,11 +150669,11 @@
150352150669
/* End the virtual table scan */
150353150670
if( pSrc->nSrc==1 ){
150354150671
sqlite3WhereEnd(pWInfo);
150355150672
}
150356150673
150357
- /* Begin scannning through the ephemeral table. */
150674
+ /* Begin scanning through the ephemeral table. */
150358150675
addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v);
150359150676
150360150677
/* Extract arguments from the current row of the ephemeral table and
150361150678
** invoke the VUpdate method. */
150362150679
for(i=0; i<nArg; i++){
@@ -150909,11 +151226,11 @@
150909151226
** can be set to 'off' for this file, as it is not recovered if a crash
150910151227
** occurs anyway. The integrity of the database is maintained by a
150911151228
** (possibly synchronous) transaction opened on the main database before
150912151229
** sqlite3BtreeCopyFile() is called.
150913151230
**
150914
- ** An optimisation would be to use a non-journaled pager.
151231
+ ** An optimization would be to use a non-journaled pager.
150915151232
** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but
150916151233
** that actually made the VACUUM run slower. Very little journalling
150917151234
** actually occurs when doing a vacuum since the vacuum_db is initially
150918151235
** empty. Only the journal header is written. Apparently it takes more
150919151236
** time to parse and run the PRAGMA to turn journalling off than it does
@@ -151598,11 +151915,11 @@
151598151915
/* A slot for the record has already been allocated in the
151599151916
** schema table. We just need to update that slot with all
151600151917
** the information we've collected.
151601151918
**
151602151919
** The VM register number pParse->regRowid holds the rowid of an
151603
- ** entry in the sqlite_schema table tht was created for this vtab
151920
+ ** entry in the sqlite_schema table that was created for this vtab
151604151921
** by sqlite3StartTable().
151605151922
*/
151606151923
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
151607151924
sqlite3NestedParse(pParse,
151608151925
"UPDATE %Q." LEGACY_SCHEMA_TABLE " "
@@ -152342,11 +152659,11 @@
152342152659
** exists when this routine returns or if an attempt to create it failed
152343152660
** and an error message was left in pParse.
152344152661
**
152345152662
** An eponymous virtual table instance is one that is named after its
152346152663
** module, and more importantly, does not require a CREATE VIRTUAL TABLE
152347
-** statement in order to come into existance. Eponymous virtual table
152664
+** statement in order to come into existence. Eponymous virtual table
152348152665
** instances always exist. They cannot be DROP-ed.
152349152666
**
152350152667
** Any virtual table module for which xConnect and xCreate are the same
152351152668
** method can have an eponymous virtual table instance.
152352152669
*/
@@ -152533,11 +152850,11 @@
152533152850
typedef struct WhereMemBlock WhereMemBlock;
152534152851
typedef struct WhereRightJoin WhereRightJoin;
152535152852
152536152853
/*
152537152854
** This object is a header on a block of allocated memory that will be
152538
-** automatically freed when its WInfo oject is destructed.
152855
+** automatically freed when its WInfo object is destructed.
152539152856
*/
152540152857
struct WhereMemBlock {
152541152858
WhereMemBlock *pNext; /* Next block in the chain */
152542152859
u64 sz; /* Bytes of space */
152543152860
};
@@ -152594,11 +152911,11 @@
152594152911
int nIn; /* Number of entries in aInLoop[] */
152595152912
struct InLoop {
152596152913
int iCur; /* The VDBE cursor used by this IN operator */
152597152914
int addrInTop; /* Top of the IN loop */
152598152915
int iBase; /* Base register of multi-key index record */
152599
- int nPrefix; /* Number of prior entires in the key */
152916
+ int nPrefix; /* Number of prior entries in the key */
152600152917
u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
152601152918
} *aInLoop; /* Information about each nested IN operator */
152602152919
} in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
152603152920
Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */
152604152921
} u;
@@ -152844,11 +153161,11 @@
152844153161
u8 op; /* Split operator. TK_AND or TK_OR */
152845153162
u8 hasOr; /* True if any a[].eOperator is WO_OR */
152846153163
int nTerm; /* Number of terms */
152847153164
int nSlot; /* Number of entries in a[] */
152848153165
int nBase; /* Number of terms through the last non-Virtual */
152849
- WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
153166
+ WhereTerm *a; /* Each a[] describes a term of the WHERE clause */
152850153167
#if defined(SQLITE_SMALL_STACK)
152851153168
WhereTerm aStatic[1]; /* Initial static space for a[] */
152852153169
#else
152853153170
WhereTerm aStatic[8]; /* Initial static space for a[] */
152854153171
#endif
@@ -153929,11 +154246,11 @@
153929154246
assert( pIdx!=0 );
153930154247
153931154248
/* Figure out how many memory cells we will need then allocate them.
153932154249
*/
153933154250
regBase = pParse->nMem + 1;
153934
- nReg = pLoop->u.btree.nEq + nExtraReg;
154251
+ nReg = nEq + nExtraReg;
153935154252
pParse->nMem += nReg;
153936154253
153937154254
zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
153938154255
assert( zAff!=0 || pParse->db->mallocFailed );
153939154256
@@ -153976,13 +154293,10 @@
153976154293
regBase = r1;
153977154294
}else{
153978154295
sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
153979154296
}
153980154297
}
153981
- }
153982
- for(j=nSkip; j<nEq; j++){
153983
- pTerm = pLoop->aLTerm[j];
153984154298
if( pTerm->eOperator & WO_IN ){
153985154299
if( pTerm->pExpr->flags & EP_xIsSelect ){
153986154300
/* No affinity ever needs to be (or should be) applied to a value
153987154301
** from the RHS of an "? IN (SELECT ...)" expression. The
153988154302
** sqlite3FindInIndex() routine has already ensured that the
@@ -154121,11 +154435,11 @@
154121154435
** the specified column into the new register, and
154122154436
**
154123154437
** 2) transform the expression node to a TK_REGISTER node that reads
154124154438
** from the newly populated register.
154125154439
**
154126
-** Also, if the node is a TK_COLUMN that does access the table idenified
154440
+** Also, if the node is a TK_COLUMN that does access the table identified
154127154441
** by pCCurHint.iTabCur, and an index is being used (which we will
154128154442
** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into
154129154443
** an access of the index rather than the original table.
154130154444
*/
154131154445
static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){
@@ -154739,11 +155053,11 @@
154739155053
/* TK_LT */ OP_SeekLT,
154740155054
/* TK_GE */ OP_SeekGE
154741155055
};
154742155056
assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
154743155057
assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
154744
- assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
155058
+ assert( TK_GE==TK_GT+3 ); /* ... is correct. */
154745155059
154746155060
assert( (pStart->wtFlags & TERM_VNULL)==0 );
154747155061
testcase( pStart->wtFlags & TERM_VIRTUAL );
154748155062
pX = pStart->pExpr;
154749155063
assert( pX!=0 );
@@ -155919,11 +156233,11 @@
155919156233
*************************************************************************
155920156234
** This module contains C code that generates VDBE code used to process
155921156235
** the WHERE clause of SQL statements.
155922156236
**
155923156237
** This file was originally part of where.c but was split out to improve
155924
-** readability and editabiliity. This file contains utility routines for
156238
+** readability and editability. This file contains utility routines for
155925156239
** analyzing Expr objects in the WHERE clause.
155926156240
*/
155927156241
/* #include "sqliteInt.h" */
155928156242
/* #include "whereInt.h" */
155929156243
@@ -156708,11 +157022,11 @@
156708157022
}
156709157023
if( (chngToIN & sqlite3WhereGetMask(&pWInfo->sMaskSet,
156710157024
pOrTerm->leftCursor))==0 ){
156711157025
/* This term must be of the form t1.a==t2.b where t2 is in the
156712157026
** chngToIN set but t1 is not. This term will be either preceded
156713
- ** or follwed by an inverted copy (t2.b==t1.a). Skip this term
157027
+ ** or followed by an inverted copy (t2.b==t1.a). Skip this term
156714157028
** and use its inversion. */
156715157029
testcase( pOrTerm->wtFlags & TERM_COPIED );
156716157030
testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
156717157031
assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
156718157032
continue;
@@ -156970,12 +157284,12 @@
156970157284
){
156971157285
WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */
156972157286
WhereTerm *pTerm; /* The term to be analyzed */
156973157287
WhereMaskSet *pMaskSet; /* Set of table index masks */
156974157288
Expr *pExpr; /* The expression to be analyzed */
156975
- Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
156976
- Bitmask prereqAll; /* Prerequesites of pExpr */
157289
+ Bitmask prereqLeft; /* Prerequisites of the pExpr->pLeft */
157290
+ Bitmask prereqAll; /* Prerequisites of pExpr */
156977157291
Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
156978157292
Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
156979157293
int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
156980157294
int noCase = 0; /* uppercase equivalent to lowercase */
156981157295
int op; /* Top-level operator. pExpr->op */
@@ -159532,11 +159846,11 @@
159532159846
** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?;
159533159847
**
159534159848
** Value pLoop->nOut is currently set to the estimated number of rows
159535159849
** visited for scanning (a=? AND b=?). This function reduces that estimate
159536159850
** by some factor to account for the (c BETWEEN ? AND ?) expression based
159537
-** on the stat4 data for the index. this scan will be peformed multiple
159851
+** on the stat4 data for the index. this scan will be performed multiple
159538159852
** times (once for each (a,b) combination that matches a=?) is dealt with
159539159853
** by the caller.
159540159854
**
159541159855
** It does this by scanning through all stat4 samples, comparing values
159542159856
** extracted from pLower and pUpper with the corresponding column in each
@@ -160287,11 +160601,11 @@
160287160601
/* whereLoopAddBtree() always generates and inserts the automatic index
160288160602
** case first. Hence compatible candidate WhereLoops never have a larger
160289160603
** rSetup. Call this SETUP-INVARIANT */
160290160604
assert( p->rSetup>=pTemplate->rSetup );
160291160605
160292
- /* Any loop using an appliation-defined index (or PRIMARY KEY or
160606
+ /* Any loop using an application-defined index (or PRIMARY KEY or
160293160607
** UNIQUE constraint) with one or more == constraints is better
160294160608
** than an automatic index. Unless it is a skip-scan. */
160295160609
if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
160296160610
&& (pTemplate->nSkip)==0
160297160611
&& (pTemplate->wsFlags & WHERE_INDEXED)!=0
@@ -160432,11 +160746,11 @@
160432160746
whereLoopInit(p);
160433160747
p->pNextLoop = 0;
160434160748
}else{
160435160749
/* We will be overwriting WhereLoop p[]. But before we do, first
160436160750
** go through the rest of the list and delete any other entries besides
160437
- ** p[] that are also supplated by pTemplate */
160751
+ ** p[] that are also supplanted by pTemplate */
160438160752
WhereLoop **ppTail = &p->pNextLoop;
160439160753
WhereLoop *pToDel;
160440160754
while( *ppTail ){
160441160755
ppTail = whereLoopFindLesser(ppTail, pTemplate);
160442160756
if( ppTail==0 ) break;
@@ -160632,11 +160946,11 @@
160632160946
}
160633160947
return i;
160634160948
}
160635160949
160636160950
/*
160637
-** Adjust the cost C by the costMult facter T. This only occurs if
160951
+** Adjust the cost C by the costMult factor T. This only occurs if
160638160952
** compiled with -DSQLITE_ENABLE_COSTMULT
160639160953
*/
160640160954
#ifdef SQLITE_ENABLE_COSTMULT
160641160955
# define ApplyCostMultiplier(C,T) C += T
160642160956
#else
@@ -160659,11 +160973,11 @@
160659160973
WhereLoopBuilder *pBuilder, /* The WhereLoop factory */
160660160974
SrcItem *pSrc, /* FROM clause term being analyzed */
160661160975
Index *pProbe, /* An index on pSrc */
160662160976
LogEst nInMul /* log(Number of iterations due to IN) */
160663160977
){
160664
- WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */
160978
+ WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyze context */
160665160979
Parse *pParse = pWInfo->pParse; /* Parsing context */
160666160980
sqlite3 *db = pParse->db; /* Database connection malloc context */
160667160981
WhereLoop *pNew; /* Template WhereLoop under construction */
160668160982
WhereTerm *pTerm; /* A WhereTerm under consideration */
160669160983
int opMask; /* Valid operators for constraints */
@@ -160969,11 +161283,11 @@
160969161283
** seek only. Then, if this is a non-covering index, add the cost of
160970161284
** visiting the rows in the main table. */
160971161285
assert( pSrc->pTab->szTabRow>0 );
160972161286
if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){
160973161287
/* The pProbe->szIdxRow is low for an IPK table since the interior
160974
- ** pages are small. Thuse szIdxRow gives a good estimate of seek cost.
161288
+ ** pages are small. Thus szIdxRow gives a good estimate of seek cost.
160975161289
** But the leaf pages are full-size, so pProbe->szIdxRow would badly
160976161290
** under-estimate the scanning cost. */
160977161291
rCostIdx = pNew->nOut + 16;
160978161292
}else{
160979161293
rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
@@ -161314,11 +161628,11 @@
161314161628
** performance of using an index is far better than the worst-case performance
161315161629
** of a full table scan.
161316161630
*/
161317161631
static int whereLoopAddBtree(
161318161632
WhereLoopBuilder *pBuilder, /* WHERE clause information */
161319
- Bitmask mPrereq /* Extra prerequesites for using this table */
161633
+ Bitmask mPrereq /* Extra prerequisites for using this table */
161320161634
){
161321161635
WhereInfo *pWInfo; /* WHERE analysis context */
161322161636
Index *pProbe; /* An index we are evaluating */
161323161637
Index sPk; /* A fake index object for the primary key */
161324161638
LogEst aiRowEstPk[2]; /* The aiRowLogEst[] value for the sPk index */
@@ -161821,11 +162135,11 @@
161821162135
** This routine depends on there being a HiddenIndexInfo structure immediately
161822162136
** following the sqlite3_index_info structure.
161823162137
**
161824162138
** Return a pointer to the collation name:
161825162139
**
161826
-** 1. If there is an explicit COLLATE operator on the constaint, return it.
162140
+** 1. If there is an explicit COLLATE operator on the constraint, return it.
161827162141
**
161828162142
** 2. Else, if the column has an alternative collation, return that.
161829162143
**
161830162144
** 3. Otherwise, return "BINARY".
161831162145
*/
@@ -162885,11 +163199,11 @@
162885163199
aSortCost[isOrdered] = whereSortingCost(
162886163200
pWInfo, nRowEst, nOrderBy, isOrdered
162887163201
);
162888163202
}
162889163203
/* TUNING: Add a small extra penalty (3) to sorting as an
162890
- ** extra encouragment to the query planner to select a plan
163204
+ ** extra encouragement to the query planner to select a plan
162891163205
** where the rows emerge in the correct order without any sorting
162892163206
** required. */
162893163207
rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3;
162894163208
162895163209
WHERETRACE(0x002,
@@ -163593,11 +163907,11 @@
163593163907
** inner loops (or around the "..." if the test occurs within the inner-
163594163908
** most loop)
163595163909
**
163596163910
** OUTER JOINS
163597163911
**
163598
-** An outer join of tables t1 and t2 is conceptally coded as follows:
163912
+** An outer join of tables t1 and t2 is conceptually coded as follows:
163599163913
**
163600163914
** foreach row1 in t1 do
163601163915
** flag = 0
163602163916
** foreach row2 in t2 do
163603163917
** start:
@@ -163748,11 +164062,11 @@
163748164062
}else{
163749164063
/* Assign a bit from the bitmask to every term in the FROM clause.
163750164064
**
163751164065
** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
163752164066
**
163753
- ** The rule of the previous sentence ensures thta if X is the bitmask for
164067
+ ** The rule of the previous sentence ensures that if X is the bitmask for
163754164068
** a table T, then X-1 is the bitmask for all other tables to the left of T.
163755164069
** Knowing the bitmask for all tables to the left of a left join is
163756164070
** important. Ticket #3015.
163757164071
**
163758164072
** Note that bitmasks are created for all pTabList->nSrc tables in
@@ -164729,11 +165043,11 @@
164729165043
** last_value(expr)
164730165044
** nth_value(expr, N)
164731165045
**
164732165046
** These are the same built-in window functions supported by Postgres.
164733165047
** Although the behaviour of aggregate window functions (functions that
164734
-** can be used as either aggregates or window funtions) allows them to
165048
+** can be used as either aggregates or window functions) allows them to
164735165049
** be implemented using an API, built-in window functions are much more
164736165050
** esoteric. Additionally, some window functions (e.g. nth_value())
164737165051
** may only be implemented by caching the entire partition in memory.
164738165052
** As such, some built-in window functions use the same API as aggregate
164739165053
** window functions and some are implemented directly using VDBE
@@ -165259,11 +165573,11 @@
165259165573
** linked list of WINDOW definitions for the current SELECT statement.
165260165574
** Argument pFunc is the function definition just resolved and pWin
165261165575
** is the Window object representing the associated OVER clause. This
165262165576
** function updates the contents of pWin as follows:
165263165577
**
165264
-** * If the OVER clause refered to a named window (as in "max(x) OVER win"),
165578
+** * If the OVER clause referred to a named window (as in "max(x) OVER win"),
165265165579
** search list pList for a matching WINDOW definition, and update pWin
165266165580
** accordingly. If no such WINDOW clause can be found, leave an error
165267165581
** in pParse.
165268165582
**
165269165583
** * If the function is a built-in window function that requires the
@@ -165880,11 +166194,11 @@
165880166194
}
165881166195
return pWin;
165882166196
}
165883166197
165884166198
/*
165885
-** Window *pWin has just been created from a WINDOW clause. Tokne pBase
166199
+** Window *pWin has just been created from a WINDOW clause. Token pBase
165886166200
** is the base window. Earlier windows from the same WINDOW clause are
165887166201
** stored in the linked list starting at pWin->pNextWin. This function
165888166202
** either updates *pWin according to the base specification, or else
165889166203
** leaves an error in pParse.
165890166204
*/
@@ -166186,11 +166500,11 @@
166186166500
** start,current,end
166187166501
** Consider a window-frame similar to the following:
166188166502
**
166189166503
** (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
166190166504
**
166191
-** The windows functions implmentation caches the input rows in a temp
166505
+** The windows functions implementation caches the input rows in a temp
166192166506
** table, sorted by "a, b" (it actually populates the cache lazily, and
166193166507
** aggressively removes rows once they are no longer required, but that's
166194166508
** a mere detail). It keeps three cursors open on the temp table. One
166195166509
** (current) that points to the next row to return to the query engine
166196166510
** once its window function values have been calculated. Another (end)
@@ -167195,11 +167509,11 @@
167195167509
** RETURN_ROW
167196167510
** }
167197167511
**
167198167512
** For the most part, the patterns above are adapted to support UNBOUNDED by
167199167513
** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and
167200
-** CURRENT ROW by assuming that it is equivilent to "0 PRECEDING/FOLLOWING".
167514
+** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING".
167201167515
** This is optimized of course - branches that will never be taken and
167202167516
** conditions that are always true are omitted from the VM code. The only
167203167517
** exceptional case is:
167204167518
**
167205167519
** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING
@@ -167474,11 +167788,11 @@
167474167788
s.eDelete = WINDOW_AGGINVERSE;
167475167789
break;
167476167790
}
167477167791
167478167792
/* Allocate registers for the array of values from the sub-query, the
167479
- ** samve values in record form, and the rowid used to insert said record
167793
+ ** same values in record form, and the rowid used to insert said record
167480167794
** into the ephemeral table. */
167481167795
regNew = pParse->nMem+1;
167482167796
pParse->nMem += nInput;
167483167797
regRecord = ++pParse->nMem;
167484167798
s.regRowid = ++pParse->nMem;
@@ -167715,11 +168029,12 @@
167715168029
#endif /* SQLITE_OMIT_WINDOWFUNC */
167716168030
167717168031
/************** End of window.c **********************************************/
167718168032
/************** Begin file parse.c *******************************************/
167719168033
/* This file is automatically generated by Lemon from input grammar
167720
-** source file "parse.y". */
168034
+** source file "parse.y".
168035
+*/
167721168036
/*
167722168037
** 2001-09-15
167723168038
**
167724168039
** The author disclaims copyright to this source code. In place of
167725168040
** a legal notice, here is a blessing:
@@ -167732,11 +168047,11 @@
167732168047
** This file contains SQLite's SQL parser.
167733168048
**
167734168049
** The canonical source code to this file ("parse.y") is a Lemon grammar
167735168050
** file that specifies the input grammar and actions to take while parsing.
167736168051
** That input file is processed by Lemon to generate a C-language
167737
-** implementation of a parser for the given grammer. You might be reading
168052
+** implementation of a parser for the given grammar. You might be reading
167738168053
** this comment as part of the translated C-code. Edits should be made
167739168054
** to the original parse.y sources.
167740168055
*/
167741168056
167742168057
/* #include "sqliteInt.h" */
@@ -174928,16 +175243,10 @@
174928175243
174929175244
/*
174930175245
** Forward declarations of external module initializer functions
174931175246
** for modules that need them.
174932175247
*/
174933
-#ifdef SQLITE_ENABLE_FTS1
174934
-SQLITE_PRIVATE int sqlite3Fts1Init(sqlite3*);
174935
-#endif
174936
-#ifdef SQLITE_ENABLE_FTS2
174937
-SQLITE_PRIVATE int sqlite3Fts2Init(sqlite3*);
174938
-#endif
174939175248
#ifdef SQLITE_ENABLE_FTS5
174940175249
SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*);
174941175250
#endif
174942175251
#ifdef SQLITE_ENABLE_STMTVTAB
174943175252
SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*);
@@ -174946,16 +175255,10 @@
174946175255
/*
174947175256
** An array of pointers to extension initializer functions for
174948175257
** built-in extensions.
174949175258
*/
174950175259
static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
174951
-#ifdef SQLITE_ENABLE_FTS1
174952
- sqlite3Fts1Init,
174953
-#endif
174954
-#ifdef SQLITE_ENABLE_FTS2
174955
- sqlite3Fts2Init,
174956
-#endif
174957175260
#ifdef SQLITE_ENABLE_FTS3
174958175261
sqlite3Fts3Init,
174959175262
#endif
174960175263
#ifdef SQLITE_ENABLE_FTS5
174961175264
sqlite3Fts5Init,
@@ -178204,11 +178507,11 @@
178204178507
** 2 on off
178205178508
** 1 off on
178206178509
** 0 off off
178207178510
**
178208178511
** Legacy behavior is 3 (double-quoted string literals are allowed anywhere)
178209
-** and so that is the default. But developers are encouranged to use
178512
+** and so that is the default. But developers are encouraged to use
178210178513
** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible.
178211178514
*/
178212178515
#if !defined(SQLITE_DQS)
178213178516
# define SQLITE_DQS 3
178214178517
#endif
@@ -178739,11 +179042,11 @@
178739179042
goto error_out;
178740179043
}
178741179044
178742179045
/* Find the column for which info is requested */
178743179046
if( zColumnName==0 ){
178744
- /* Query for existance of table only */
179047
+ /* Query for existence of table only */
178745179048
}else{
178746179049
for(iCol=0; iCol<pTab->nCol; iCol++){
178747179050
pCol = &pTab->aCol[iCol];
178748179051
if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
178749179052
break;
@@ -179179,11 +179482,11 @@
179179179482
**
179180179483
** Set or clear a flag that indicates that the database file is always well-
179181179484
** formed and never corrupt. This flag is clear by default, indicating that
179182179485
** database files might have arbitrary corruption. Setting the flag during
179183179486
** testing causes certain assert() statements in the code to be activated
179184
- ** that demonstrat invariants on well-formed database files.
179487
+ ** that demonstrate invariants on well-formed database files.
179185179488
*/
179186179489
case SQLITE_TESTCTRL_NEVER_CORRUPT: {
179187179490
sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
179188179491
break;
179189179492
}
@@ -179333,11 +179636,11 @@
179333179636
**
179334179637
** "ptr" is a pointer to a u32.
179335179638
**
179336179639
** op==0 Store the current sqlite3TreeTrace in *ptr
179337179640
** op==1 Set sqlite3TreeTrace to the value *ptr
179338
- ** op==3 Store the current sqlite3WhereTrace in *ptr
179641
+ ** op==2 Store the current sqlite3WhereTrace in *ptr
179339179642
** op==3 Set sqlite3WhereTrace to the value *ptr
179340179643
*/
179341179644
case SQLITE_TESTCTRL_TRACEFLAGS: {
179342179645
int opTrace = va_arg(ap, int);
179343179646
u32 *ptr = va_arg(ap, u32*);
@@ -179669,11 +179972,11 @@
179669179972
#endif /* SQLITE_OMIT_WAL */
179670179973
return rc;
179671179974
}
179672179975
179673179976
/*
179674
-** Open a read-transaction on the snapshot idendified by pSnapshot.
179977
+** Open a read-transaction on the snapshot identified by pSnapshot.
179675179978
*/
179676179979
SQLITE_API int sqlite3_snapshot_open(
179677179980
sqlite3 *db,
179678179981
const char *zDb,
179679179982
sqlite3_snapshot *pSnapshot
@@ -195704,10 +196007,11 @@
195704196007
memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING);
195705196008
}
195706196009
195707196010
for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){
195708196011
NodeReader reader;
196012
+ memset(&reader, 0, sizeof(reader));
195709196013
pNode = &pWriter->aNodeWriter[i];
195710196014
195711196015
if( pNode->block.a){
195712196016
rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n);
195713196017
while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader);
@@ -200348,11 +200652,11 @@
200348200652
}
200349200653
}
200350200654
}
200351200655
200352200656
/*
200353
-** Return a JsonNode and all its descendents as a JSON string.
200657
+** Return a JsonNode and all its descendants as a JSON string.
200354200658
*/
200355200659
static void jsonReturnJson(
200356200660
JsonNode *pNode, /* Node to return */
200357200661
sqlite3_context *pCtx, /* Return value for this function */
200358200662
sqlite3_value **aReplace /* Array of replacement values */
@@ -202420,11 +202724,11 @@
202420202724
UNUSED_PARAMETER(argc);
202421202725
UNUSED_PARAMETER(argv);
202422202726
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
202423202727
#ifdef NEVER
202424202728
/* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
202425
- ** always have been called to initalize it */
202729
+ ** always have been called to initialize it */
202426202730
if( NEVER(!pStr) ) return;
202427202731
#endif
202428202732
z = pStr->zBuf;
202429202733
for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
202430202734
if( c=='"' ){
@@ -205011,11 +205315,24 @@
205011205315
break;
205012205316
}
205013205317
p->pInfo->nCoord = pRtree->nDim2;
205014205318
p->pInfo->anQueue = pCsr->anQueue;
205015205319
p->pInfo->mxLevel = pRtree->iDepth + 1;
205016
- }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
205320
+ }else if( eType==SQLITE_INTEGER ){
205321
+ sqlite3_int64 iVal = sqlite3_value_int64(argv[ii]);
205322
+#ifdef SQLITE_RTREE_INT_ONLY
205323
+ p->u.rValue = iVal;
205324
+#else
205325
+ p->u.rValue = (double)iVal;
205326
+ if( iVal>=((sqlite3_int64)1)<<48
205327
+ || -iVal>=((sqlite3_int64)1)<<48
205328
+ ){
205329
+ if( p->op==RTREE_LT ) p->op = RTREE_LE;
205330
+ if( p->op==RTREE_GT ) p->op = RTREE_GE;
205331
+ }
205332
+#endif
205333
+ }else if( eType==SQLITE_FLOAT ){
205017205334
#ifdef SQLITE_RTREE_INT_ONLY
205018205335
p->u.rValue = sqlite3_value_int64(argv[ii]);
205019205336
#else
205020205337
p->u.rValue = sqlite3_value_double(argv[ii]);
205021205338
#endif
@@ -205142,24 +205459,25 @@
205142205459
if( p->usable
205143205460
&& ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
205144205461
|| p->op==SQLITE_INDEX_CONSTRAINT_MATCH)
205145205462
){
205146205463
u8 op;
205464
+ u8 doOmit = 1;
205147205465
switch( p->op ){
205148
- case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
205149
- case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
205466
+ case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break;
205467
+ case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break;
205150205468
case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
205151
- case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
205469
+ case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break;
205152205470
case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
205153205471
case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break;
205154205472
default: op = 0; break;
205155205473
}
205156205474
if( op ){
205157205475
zIdxStr[iIdx++] = op;
205158205476
zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
205159205477
pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
205160
- pIdxInfo->aConstraintUsage[ii].omit = 1;
205478
+ pIdxInfo->aConstraintUsage[ii].omit = doOmit;
205161205479
}
205162205480
}
205163205481
}
205164205482
205165205483
pIdxInfo->idxNum = 2;
@@ -225250,11 +225568,12 @@
225250225568
#define FTS5_COMMA 13
225251225569
#define FTS5_PLUS 14
225252225570
#define FTS5_STAR 15
225253225571
225254225572
/* This file is automatically generated by Lemon from input grammar
225255
-** source file "fts5parse.y". */
225573
+** source file "fts5parse.y".
225574
+*/
225256225575
/*
225257225576
** 2000-05-29
225258225577
**
225259225578
** The author disclaims copyright to this source code. In place of
225260225579
** a legal notice, here is a blessing:
@@ -237173,11 +237492,11 @@
237173237492
if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
237174237493
fts5DataRelease(pLeaf);
237175237494
pLeaf = 0;
237176237495
}else if( bDetailNone ){
237177237496
break;
237178
- }else if( iNext>=pLeaf->szLeaf || iNext<4 ){
237497
+ }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
237179237498
p->rc = FTS5_CORRUPT;
237180237499
break;
237181237500
}else{
237182237501
int nShift = iNext - 4;
237183237502
int nPg;
@@ -237377,11 +237696,13 @@
237377237696
}else{
237378237697
if( iKey!=1 ){
237379237698
iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
237380237699
}
237381237700
iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
237382
- if( nPrefix2>nPrefix ){
237701
+ if( nPrefix2>pSeg->term.n ){
237702
+ p->rc = FTS5_CORRUPT;
237703
+ }else if( nPrefix2>nPrefix ){
237383237704
memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
237384237705
iOff += (nPrefix2-nPrefix);
237385237706
}
237386237707
memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
237387237708
iOff += nSuffix2;
@@ -242633,11 +242954,11 @@
242633242954
int nArg, /* Number of args */
242634242955
sqlite3_value **apUnused /* Function arguments */
242635242956
){
242636242957
assert( nArg==0 );
242637242958
UNUSED_PARAM2(nArg, apUnused);
242638
- sqlite3_result_text(pCtx, "fts5: 2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0", -1, SQLITE_TRANSIENT);
242959
+ sqlite3_result_text(pCtx, "fts5: 2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9", -1, SQLITE_TRANSIENT);
242639242960
}
242640242961
242641242962
/*
242642242963
** Return true if zName is the extension on one of the shadow tables used
242643242964
** by this module.
242644242965
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.42.0. 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.
@@ -14,10 +14,13 @@
14 ** the text of this file. Search for "Begin file sqlite3.h" to find the start
15 ** of the embedded sqlite3.h header file.) Additional code files may be needed
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
 
 
 
19 */
20 #define SQLITE_CORE 1
21 #define SQLITE_AMALGAMATION 1
22 #ifndef SQLITE_PRIVATE
23 # define SQLITE_PRIVATE static
@@ -48,15 +51,15 @@
48 ** NO_TEST - The branches on this line are not
49 ** measured by branch coverage. This is
50 ** used on lines of code that actually
51 ** implement parts of coverage testing.
52 **
53 ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
54 ** and the correct answer is still obtained,
55 ** though perhaps more slowly.
56 **
57 ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
58 ** and the correct answer is still obtained,
59 ** though perhaps more slowly.
60 **
61 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
62 ** that would be harmless and undetectable
@@ -454,13 +457,13 @@
454 **
455 ** See also: [sqlite3_libversion()],
456 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
457 ** [sqlite_version()] and [sqlite_source_id()].
458 */
459 #define SQLITE_VERSION "3.42.0"
460 #define SQLITE_VERSION_NUMBER 3042000
461 #define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0"
462
463 /*
464 ** CAPI3REF: Run-Time Library Version Numbers
465 ** KEYWORDS: sqlite3_version sqlite3_sourceid
466 **
@@ -1498,11 +1501,11 @@
1498 ** the database is not a wal-mode db, or if there is no such connection in any
1499 ** other process. This opcode cannot be used to detect transactions opened
1500 ** by clients within the current process, only within other processes.
1501 **
1502 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1503 ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the
1504 ** [checksum VFS shim] only.
1505 **
1506 ** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1507 ** If there is currently no transaction open on the database, and the
1508 ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
@@ -2762,11 +2765,11 @@
2762 ** 3.0.0.
2763 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2764 ** the [VACUUM] command will fail with an obscure error when attempting to
2765 ** process a table with generated columns and a descending index. This is
2766 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2767 ** either generated columns or decending indexes.
2768 ** </dd>
2769 **
2770 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2771 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2772 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
@@ -3043,10 +3046,11 @@
3043 ** SQL statements is a no-op and has no effect on SQL statements
3044 ** that are started after the sqlite3_interrupt() call returns.
3045 **
3046 ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
3047 ** or not an interrupt is currently in effect for [database connection] D.
 
3048 */
3049 SQLITE_API void sqlite3_interrupt(sqlite3*);
3050 SQLITE_API int sqlite3_is_interrupted(sqlite3*);
3051
3052 /*
@@ -3696,12 +3700,14 @@
3696 ** and context pointer P. ^If the X callback is
3697 ** NULL or if the M mask is zero, then tracing is disabled. The
3698 ** M argument should be the bitwise OR-ed combination of
3699 ** zero or more [SQLITE_TRACE] constants.
3700 **
3701 ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
3702 ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
 
 
3703 **
3704 ** ^The X callback is invoked whenever any of the events identified by
3705 ** mask M occur. ^The integer return value from the callback is currently
3706 ** ignored, though this may change in future releases. Callback
3707 ** implementations should return zero to ensure future compatibility.
@@ -4066,11 +4072,11 @@
4066 **
4067 ** The first parameter to these interfaces (hereafter referred to
4068 ** as F) must be one of:
4069 ** <ul>
4070 ** <li> A database filename pointer created by the SQLite core and
4071 ** passed into the xOpen() method of a VFS implemention, or
4072 ** <li> A filename obtained from [sqlite3_db_filename()], or
4073 ** <li> A new filename constructed using [sqlite3_create_filename()].
4074 ** </ul>
4075 ** If the F parameter is not one of the above, then the behavior is
4076 ** undefined and probably undesirable. Older versions of SQLite were
@@ -4179,11 +4185,11 @@
4179 SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4180
4181 /*
4182 ** CAPI3REF: Create and Destroy VFS Filenames
4183 **
4184 ** These interfces are provided for use by [VFS shim] implementations and
4185 ** are not useful outside of that context.
4186 **
4187 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4188 ** database filename D with corresponding journal file J and WAL file W and
4189 ** with N URI parameters key/values pairs in the array P. The result from
@@ -4889,11 +4895,11 @@
4889 ** These three options exist:
4890 ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4891 ** with it may be passed. ^It is called to dispose of the BLOB or string even
4892 ** if the call to the bind API fails, except the destructor is not called if
4893 ** the third parameter is a NULL pointer or the fourth parameter is negative.
4894 ** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
4895 ** the application remains responsible for disposing of the object. ^In this
4896 ** case, the object and the provided pointer to it must remain valid until
4897 ** either the prepared statement is finalized or the same SQL parameter is
4898 ** bound to something else, whichever occurs sooner.
4899 ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
@@ -5568,18 +5574,30 @@
5568 ** Use [sqlite3_clear_bindings()] to reset the bindings.
5569 **
5570 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
5571 ** back to the beginning of its program.
5572 **
5573 ** ^If the most recent call to [sqlite3_step(S)] for the
5574 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
5575 ** or if [sqlite3_step(S)] has never before been called on S,
5576 ** then [sqlite3_reset(S)] returns [SQLITE_OK].
 
 
5577 **
5578 ** ^If the most recent call to [sqlite3_step(S)] for the
5579 ** [prepared statement] S indicated an error, then
5580 ** [sqlite3_reset(S)] returns an appropriate [error code].
 
 
 
 
 
 
 
 
 
 
5581 **
5582 ** ^The [sqlite3_reset(S)] interface does not change the values
5583 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
5584 */
5585 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
@@ -5792,11 +5810,11 @@
5792 ** <p>
5793 ** The SQLITE_DIRECTONLY flag is recommended for any
5794 ** [application-defined SQL function]
5795 ** that has side-effects or that could potentially leak sensitive information.
5796 ** This will prevent attacks in which an application is tricked
5797 ** into using a database file that has had its schema surreptiously
5798 ** modified to invoke the application-defined function in ways that are
5799 ** harmful.
5800 ** <p>
5801 ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5802 ** [application-defined SQL functions], regardless of whether or not they
@@ -9501,12 +9519,12 @@
9501 ** ^(There may be at most one unlock-notify callback registered by a
9502 ** blocked connection. If sqlite3_unlock_notify() is called when the
9503 ** blocked connection already has a registered unlock-notify callback,
9504 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9505 ** called with a NULL pointer as its second argument, then any existing
9506 ** unlock-notify callback is canceled. ^The blocked connections
9507 ** unlock-notify callback may also be canceled by closing the blocked
9508 ** connection using [sqlite3_close()].
9509 **
9510 ** The unlock-notify callback is not reentrant. If an application invokes
9511 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9512 ** crash or deadlock may be the result.
@@ -9925,11 +9943,11 @@
9925 ** </dd>
9926 **
9927 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9928 ** <dd>Calls of the form
9929 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9930 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9931 ** prohibits that virtual table from being used from within triggers and
9932 ** views.
9933 ** </dd>
9934 **
9935 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
@@ -10115,11 +10133,11 @@
10115 ** ^(A constraint on a virtual table of the form
10116 ** "[IN operator|column IN (...)]" is
10117 ** communicated to the xBestIndex method as a
10118 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
10119 ** this constraint, it must set the corresponding
10120 ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
10121 ** the usual mode of handling IN operators, SQLite generates [bytecode]
10122 ** that invokes the [xFilter|xFilter() method] once for each value
10123 ** on the right-hand side of the IN operator.)^ Thus the virtual table
10124 ** only sees a single value from the right-hand side of the IN operator
10125 ** at a time.
@@ -10544,11 +10562,11 @@
10544 ** triggers; and so forth.
10545 **
10546 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10547 ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10548 ** in this case the new values are not available. In this case, when a
10549 ** callback made with op==SQLITE_DELETE is actuall a write using the
10550 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10551 ** the index of the column being written. In other cases, where the
10552 ** pre-update hook is being invoked for some other reason, including a
10553 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10554 **
@@ -13468,11 +13486,11 @@
13468 ** The maximum number of terms in a compound SELECT statement.
13469 ** The code generator for compound SELECT statements does one
13470 ** level of recursion for each term. A stack overflow can result
13471 ** if the number of terms is too large. In practice, most SQL
13472 ** never has more than 3 or 4 terms. Use a value of 0 to disable
13473 ** any limit on the number of terms in a compount SELECT.
13474 */
13475 #ifndef SQLITE_MAX_COMPOUND_SELECT
13476 # define SQLITE_MAX_COMPOUND_SELECT 500
13477 #endif
13478
@@ -14806,11 +14824,11 @@
14806 };
14807
14808 /*
14809 ** Name of table that holds the database schema.
14810 **
14811 ** The PREFERRED names are used whereever possible. But LEGACY is also
14812 ** used for backwards compatibility.
14813 **
14814 ** 1. Queries can use either the PREFERRED or the LEGACY names
14815 ** 2. The sqlite3_set_authorizer() callback uses the LEGACY name
14816 ** 3. The PRAGMA table_list statement uses the PREFERRED name
@@ -16575,11 +16593,11 @@
16575
16576 /*
16577 ** The VdbeCoverage macros are used to set a coverage testing point
16578 ** for VDBE branch instructions. The coverage testing points are line
16579 ** numbers in the sqlite3.c source file. VDBE branch coverage testing
16580 ** only works with an amalagmation build. That's ok since a VDBE branch
16581 ** coverage build designed for testing the test suite only. No application
16582 ** should ever ship with VDBE branch coverage measuring turned on.
16583 **
16584 ** VdbeCoverage(v) // Mark the previously coded instruction
16585 ** // as a branch
@@ -16593,21 +16611,21 @@
16593 ** VdbeCoverageNeverNull(v) // Previous three-way branch is only
16594 ** // taken on the first two ways. The
16595 ** // NULL option is not possible
16596 **
16597 ** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested
16598 ** // in distingishing equal and not-equal.
16599 **
16600 ** Every VDBE branch operation must be tagged with one of the macros above.
16601 ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
16602 ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
16603 ** routine in vdbe.c, alerting the developer to the missed tag.
16604 **
16605 ** During testing, the test application will invoke
16606 ** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
16607 ** routine that is invoked as each bytecode branch is taken. The callback
16608 ** contains the sqlite3.c source line number ov the VdbeCoverage macro and
16609 ** flags to indicate whether or not the branch was taken. The test application
16610 ** is responsible for keeping track of this and reporting byte-code branches
16611 ** that are never taken.
16612 **
16613 ** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
@@ -16942,11 +16960,11 @@
16942 #endif
16943
16944 /*
16945 ** Default synchronous levels.
16946 **
16947 ** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ
16948 ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1.
16949 **
16950 ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS
16951 ** OFF 1 0
16952 ** NORMAL 2 1
@@ -16981,11 +16999,11 @@
16981
16982 /*
16983 ** An instance of the following structure stores a database schema.
16984 **
16985 ** Most Schema objects are associated with a Btree. The exception is
16986 ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing.
16987 ** In shared cache mode, a single Schema object can be shared by multiple
16988 ** Btrees that refer to the same underlying BtShared object.
16989 **
16990 ** Schema objects are automatically deallocated when the last Btree that
16991 ** references them is destroyed. The TEMP Schema is manually freed by
@@ -17092,11 +17110,11 @@
17092 u32 nSlot; /* Number of lookaside slots allocated */
17093 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
17094 LookasideSlot *pInit; /* List of buffers not previously used */
17095 LookasideSlot *pFree; /* List of available buffers */
17096 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
17097 LookasideSlot *pSmallInit; /* List of small buffers not prediously used */
17098 LookasideSlot *pSmallFree; /* List of available small buffers */
17099 void *pMiddle; /* First byte past end of full-size buffers and
17100 ** the first byte of LOOKASIDE_SMALL buffers */
17101 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
17102 void *pStart; /* First byte of available memory space */
@@ -17109,11 +17127,11 @@
17109
17110 #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
17111 #define EnableLookaside db->lookaside.bDisable--;\
17112 db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
17113
17114 /* Size of the smaller allocations in two-size lookside */
17115 #ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
17116 # define LOOKASIDE_SMALL 0
17117 #else
17118 # define LOOKASIDE_SMALL 128
17119 #endif
@@ -17537,11 +17555,11 @@
17537 ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!!
17538 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
17539 **
17540 ** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the
17541 ** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is
17542 ** used internally and if set means tha the function has side effects.
17543 ** SQLITE_INNOCUOUS is used by application code and means "not unsafe".
17544 ** See multiple instances of tag-20230109-1.
17545 */
17546 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
17547 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
@@ -18127,11 +18145,11 @@
18127 ** to its default value. CASCADE means that a DELETE or UPDATE of the
18128 ** referenced table row is propagated into the row that holds the
18129 ** foreign key.
18130 **
18131 ** The OE_Default value is a place holder that means to use whatever
18132 ** conflict resolution algorthm is required from context.
18133 **
18134 ** The following symbolic values are used to record which type
18135 ** of conflict resolution action to take.
18136 */
18137 #define OE_None 0 /* There is no constraint to check */
@@ -18541,11 +18559,11 @@
18541 #endif
18542 int iTable; /* TK_COLUMN: cursor number of table holding column
18543 ** TK_REGISTER: register number
18544 ** TK_TRIGGER: 1 -> new, 0 -> old
18545 ** EP_Unlikely: 134217728 times likelihood
18546 ** TK_IN: ephemerial table holding RHS
18547 ** TK_SELECT_COLUMN: Number of columns on the LHS
18548 ** TK_SELECT: 1st register of result vector */
18549 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
18550 ** TK_VARIABLE: variable number (always >= 1).
18551 ** TK_SELECT_COLUMN: column of the result vector */
@@ -18811,11 +18829,11 @@
18811 unsigned fromDDL :1; /* Comes from sqlite_schema */
18812 unsigned isCte :1; /* This is a CTE */
18813 unsigned notCte :1; /* This item may not match a CTE */
18814 unsigned isUsing :1; /* u3.pUsing is valid */
18815 unsigned isOn :1; /* u3.pOn was once valid and non-NULL */
18816 unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */
18817 unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
18818 } fg;
18819 int iCursor; /* The VDBE cursor number used to access this table */
18820 union {
18821 Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
@@ -19657,11 +19675,11 @@
19657 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
19658
19659 /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
19660 ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
19661 ** parameters are for temporary use during development, to help find
19662 ** optimial values for parameters in the query planner. The should not
19663 ** be used on trunk check-ins. They are a temporary mechanism available
19664 ** for transient development builds only.
19665 **
19666 ** Tuning parameters are numbered starting with 1.
19667 */
@@ -19769,10 +19787,11 @@
19769 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
19770 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
19771 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
19772 int walkerDepth; /* Number of subqueries */
19773 u16 eCode; /* A small processing code */
 
19774 union { /* Extra data for callback */
19775 NameContext *pNC; /* Naming context */
19776 int n; /* A counter */
19777 int iCur; /* A cursor number */
19778 SrcList *pSrcList; /* FROM clause */
@@ -20479,11 +20498,11 @@
20479 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, const Token*);
20480 SQLITE_PRIVATE int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int);
20481 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*,Expr*,int);
20482 SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList*,const ExprList*, int);
20483 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int);
20484 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
20485 SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*);
20486 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
20487 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
20488 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
20489 SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*);
@@ -23042,11 +23061,11 @@
23042 int iNewReg; /* Register for new.* values */
23043 int iBlobWrite; /* Value returned by preupdate_blobwrite() */
23044 i64 iKey1; /* First key value passed to hook */
23045 i64 iKey2; /* Second key value passed to hook */
23046 Mem *aNew; /* Array of new.* values */
23047 Table *pTab; /* Schema object being upated */
23048 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
23049 };
23050
23051 /*
23052 ** An instance of this object is used to pass an vector of values into
@@ -24258,10 +24277,29 @@
24258 { 4, "hour", 1.2897e+11, 3600.0 },
24259 { 3, "day", 5373485.0, 86400.0 },
24260 { 5, "month", 176546.0, 2592000.0 },
24261 { 4, "year", 14713.0, 31536000.0 },
24262 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24263
24264 /*
24265 ** Process a modifier to a date-time stamp. The modifiers are
24266 ** as follows:
24267 **
@@ -24302,23 +24340,12 @@
24302 ** If rawS is available, then interpret as a julian day number, or
24303 ** a unix timestamp, depending on its magnitude.
24304 */
24305 if( sqlite3_stricmp(z, "auto")==0 ){
24306 if( idx>1 ) return 1; /* IMP: R-33611-57934 */
24307 if( !p->rawS || p->validJD ){
24308 rc = 0;
24309 p->rawS = 0;
24310 }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */
24311 && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */
24312 ){
24313 r = p->s*1000.0 + 210866760000000.0;
24314 clearYMD_HMS_TZ(p);
24315 p->iJD = (sqlite3_int64)(r + 0.5);
24316 p->validJD = 1;
24317 p->rawS = 0;
24318 rc = 0;
24319 }
24320 }
24321 break;
24322 }
24323 case 'j': {
24324 /*
@@ -24480,22 +24507,68 @@
24480 case '7':
24481 case '8':
24482 case '9': {
24483 double rRounder;
24484 int i;
24485 for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){}
 
 
 
 
 
 
24486 if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){
24487 rc = 1;
24488 break;
24489 }
24490 if( z[n]==':' ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24491 /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
24492 ** specified number of hours, minutes, seconds, and fractional seconds
24493 ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
24494 ** omitted.
24495 */
24496 const char *z2 = z;
24497 DateTime tx;
24498 sqlite3_int64 day;
24499 if( !sqlite3Isdigit(*z2) ) z2++;
24500 memset(&tx, 0, sizeof(tx));
24501 if( parseHhMmSs(z2, &tx) ) break;
@@ -24526,11 +24599,10 @@
24526 && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
24527 && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
24528 ){
24529 switch( i ){
24530 case 4: { /* Special processing to add months */
24531 int x;
24532 assert( strcmp(aXformType[i].zName,"month")==0 );
24533 computeYMD_HMS(p);
24534 p->M += (int)r;
24535 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
24536 p->Y += x;
@@ -24803,11 +24875,11 @@
24803 ** %J ** julian day number
24804 ** %m month 01-12
24805 ** %M minute 00-59
24806 ** %s seconds since 1970-01-01
24807 ** %S seconds 00-59
24808 ** %w day of week 0-6 sunday==0
24809 ** %W week of year 00-53
24810 ** %Y year 0000-9999
24811 ** %% %
24812 */
24813 static void strftimeFunc(
@@ -24942,10 +25014,120 @@
24942 sqlite3_value **NotUsed2
24943 ){
24944 UNUSED_PARAMETER2(NotUsed, NotUsed2);
24945 dateFunc(context, 0, 0);
24946 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24947
24948 /*
24949 ** current_timestamp()
24950 **
24951 ** This function returns the same value as datetime('now').
@@ -25017,10 +25199,11 @@
25017 PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ),
25018 PURE_DATE(date, -1, 0, 0, dateFunc ),
25019 PURE_DATE(time, -1, 0, 0, timeFunc ),
25020 PURE_DATE(datetime, -1, 0, 0, datetimeFunc ),
25021 PURE_DATE(strftime, -1, 0, 0, strftimeFunc ),
 
25022 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
25023 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
25024 DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
25025 #else
25026 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
@@ -25170,11 +25353,11 @@
25170 && op!=SQLITE_FCNTL_CKPT_START
25171 ){
25172 /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
25173 ** is using a regular VFS, it is called after the corresponding
25174 ** transaction has been committed. Injecting a fault at this point
25175 ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM
25176 ** but the transaction is committed anyway.
25177 **
25178 ** The core must call OsFileControl() though, not OsFileControlHint(),
25179 ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
25180 ** means the commit really has failed and an error should be returned
@@ -25791,11 +25974,11 @@
25791 /*
25792 ** Like free() but works for allocations obtained from sqlite3MemMalloc()
25793 ** or sqlite3MemRealloc().
25794 **
25795 ** For this low-level routine, we already know that pPrior!=0 since
25796 ** cases where pPrior==0 will have been intecepted and dealt with
25797 ** by higher-level routines.
25798 */
25799 static void sqlite3MemFree(void *pPrior){
25800 #ifdef SQLITE_MALLOCSIZE
25801 SQLITE_FREE(pPrior);
@@ -25879,11 +26062,11 @@
25879 size_t len;
25880 if( _sqliteZone_ ){
25881 return SQLITE_OK;
25882 }
25883 len = sizeof(cpuCount);
25884 /* One usually wants to use hw.acctivecpu for MT decisions, but not here */
25885 sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0);
25886 if( cpuCount>1 ){
25887 /* defer MT decisions to system malloc */
25888 _sqliteZone_ = malloc_default_zone();
25889 }else{
@@ -28346,11 +28529,11 @@
28346
28347 #include <pthread.h>
28348
28349 /*
28350 ** The sqlite3_mutex.id, sqlite3_mutex.nRef, and sqlite3_mutex.owner fields
28351 ** are necessary under two condidtions: (1) Debug builds and (2) using
28352 ** home-grown mutexes. Encapsulate these conditions into a single #define.
28353 */
28354 #if defined(SQLITE_DEBUG) || defined(SQLITE_HOMEGROWN_RECURSIVE_MUTEX)
28355 # define SQLITE_MUTEX_NREF 1
28356 #else
@@ -28847,11 +29030,11 @@
28847 */
28848 struct sqlite3_mutex {
28849 CRITICAL_SECTION mutex; /* Mutex controlling the lock */
28850 int id; /* Mutex type */
28851 #ifdef SQLITE_DEBUG
28852 volatile int nRef; /* Number of enterances */
28853 volatile DWORD owner; /* Thread holding this mutex */
28854 volatile LONG trace; /* True to trace changes */
28855 #endif
28856 };
28857
@@ -32228,11 +32411,12 @@
32228 const char *azOp[] = {
32229 "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
32230 };
32231 assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
32232 assert( pExpr->pRight );
32233 assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE );
 
32234 x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
32235 zUniOp = azOp[x];
32236 break;
32237 }
32238
@@ -33887,11 +34071,11 @@
33887 #endif
33888
33889 /*
33890 ** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
33891 ** or to bypass normal error detection during testing in order to let
33892 ** execute proceed futher downstream.
33893 **
33894 ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
33895 ** sqlite3FaultSim() function only returns non-zero during testing.
33896 **
33897 ** During testing, if the test harness has set a fault-sim callback using
@@ -34498,11 +34682,11 @@
34498 }
34499
34500 /* store the result */
34501 *pResult = result;
34502
34503 /* return true if number and no extra non-whitespace chracters after */
34504 if( z==zEnd && nDigit>0 && eValid && eType>0 ){
34505 return eType;
34506 }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){
34507 return -1;
34508 }else{
@@ -34634,11 +34818,11 @@
34634 testcase( i==20*incr );
34635 if( u>LARGEST_INT64 ){
34636 /* This test and assignment is needed only to suppress UB warnings
34637 ** from clang and -fsanitize=undefined. This test and assignment make
34638 ** the code a little larger and slower, and no harm comes from omitting
34639 ** them, but we must appaise the undefined-behavior pharisees. */
34640 *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
34641 }else if( neg ){
34642 *pNum = -(i64)u;
34643 }else{
34644 *pNum = (i64)u;
@@ -35319,11 +35503,11 @@
35319 return 1;
35320 }
35321 }
35322
35323 /*
35324 ** Attempt to add, substract, or multiply the 64-bit signed value iB against
35325 ** the other 64-bit signed integer at *pA and store the result in *pA.
35326 ** Return 0 on success. Or if the operation would have resulted in an
35327 ** overflow, leave *pA unchanged and return 1.
35328 */
35329 SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
@@ -35632,11 +35816,11 @@
35632 */
35633 #ifndef SQLITE_HWTIME_H
35634 #define SQLITE_HWTIME_H
35635
35636 /*
35637 ** The following routine only works on pentium-class (or newer) processors.
35638 ** It uses the RDTSC opcode to read the cycle count value out of the
35639 ** processor and returns that value. This can be used for high-res
35640 ** profiling.
35641 */
35642 #if !defined(__STRICT_ANSI__) && \
@@ -35804,11 +35988,11 @@
35804 pH->first = pNew;
35805 }
35806 }
35807
35808
35809 /* Resize the hash table so that it cantains "new_size" buckets.
35810 **
35811 ** The hash table might fail to resize if sqlite3_malloc() fails or
35812 ** if the new size is the same as the prior size.
35813 ** Return TRUE if the resize occurs and false if not.
35814 */
@@ -37190,11 +37374,11 @@
37190 ** skip locking all together.
37191 **
37192 ** This source file is organized into divisions where the logic for various
37193 ** subfunctions is contained within the appropriate division. PLEASE
37194 ** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed
37195 ** in the correct division and should be clearly labeled.
37196 **
37197 ** The layout of divisions is as follows:
37198 **
37199 ** * General-purpose declarations and utility functions.
37200 ** * Unique file ID logic used by VxWorks.
@@ -37777,11 +37961,11 @@
37777 #endif
37778 }
37779
37780 /*
37781 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
37782 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the
37783 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
37784 ** system call named zName.
37785 */
37786 static int unixSetSystemCall(
37787 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
@@ -38299,11 +38483,11 @@
38299 ** But wait: there are yet more problems with POSIX advisory locks.
38300 **
38301 ** If you close a file descriptor that points to a file that has locks,
38302 ** all locks on that file that are owned by the current process are
38303 ** released. To work around this problem, each unixInodeInfo object
38304 ** maintains a count of the number of pending locks on tha inode.
38305 ** When an attempt is made to close an unixFile, if there are
38306 ** other unixFile open on the same inode that are holding locks, the call
38307 ** to close() the file descriptor is deferred until all of the locks clear.
38308 ** The unixInodeInfo structure keeps a list of file descriptors that need to
38309 ** be closed and that list is walked (and cleared) when the last lock
@@ -38313,11 +38497,11 @@
38313 **
38314 ** Many older versions of linux use the LinuxThreads library which is
38315 ** not posix compliant. Under LinuxThreads, a lock created by thread
38316 ** A cannot be modified or overridden by a different thread B.
38317 ** Only thread A can modify the lock. Locking behavior is correct
38318 ** if the appliation uses the newer Native Posix Thread Library (NPTL)
38319 ** on linux - with NPTL a lock created by thread A can override locks
38320 ** in thread B. But there is no way to know at compile-time which
38321 ** threading library is being used. So there is no way to know at
38322 ** compile-time whether or not thread A can override locks on thread B.
38323 ** One has to do a run-time check to discover the behavior of the
@@ -38515,11 +38699,11 @@
38515 static void storeLastErrno(unixFile *pFile, int error){
38516 pFile->lastErrno = error;
38517 }
38518
38519 /*
38520 ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list.
38521 */
38522 static void closePendingFds(unixFile *pFile){
38523 unixInodeInfo *pInode = pFile->pInode;
38524 UnixUnusedFd *p;
38525 UnixUnusedFd *pNext;
@@ -38878,19 +39062,19 @@
38878 ** lock primitives (called read-locks and write-locks below, to avoid
38879 ** confusion with SQLite lock names). The algorithms are complicated
38880 ** slightly in order to be compatible with Windows95 systems simultaneously
38881 ** accessing the same database file, in case that is ever required.
38882 **
38883 ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved
38884 ** byte', each single bytes at well known offsets, and the 'shared byte
38885 ** range', a range of 510 bytes at a well known offset.
38886 **
38887 ** To obtain a SHARED lock, a read-lock is obtained on the 'pending
38888 ** byte'. If this is successful, 'shared byte range' is read-locked
38889 ** and the lock on the 'pending byte' released. (Legacy note: When
38890 ** SQLite was first developed, Windows95 systems were still very common,
38891 ** and Widnows95 lacks a shared-lock capability. So on Windows95, a
38892 ** single randomly selected by from the 'shared byte range' is locked.
38893 ** Windows95 is now pretty much extinct, but this work-around for the
38894 ** lack of shared-locks on Windows95 lives on, for backwards
38895 ** compatibility.)
38896 **
@@ -38907,11 +39091,11 @@
38907 ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then
38908 ** a PENDING lock is obtained first. A PENDING lock is implemented by
38909 ** obtaining a write-lock on the 'pending byte'. This ensures that no new
38910 ** SHARED locks can be obtained, but existing SHARED locks are allowed to
38911 ** persist. If the call to this function fails to obtain the EXCLUSIVE
38912 ** lock in this case, it holds the PENDING lock intead. The client may
38913 ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED
38914 ** locks have cleared.
38915 */
38916 int rc = SQLITE_OK;
38917 unixFile *pFile = (unixFile*)id;
@@ -38935,11 +39119,11 @@
38935 return SQLITE_OK;
38936 }
38937
38938 /* Make sure the locking sequence is correct.
38939 ** (1) We never move from unlocked to anything higher than shared lock.
38940 ** (2) SQLite never explicitly requests a pendig lock.
38941 ** (3) A shared lock is always held when a reserve lock is requested.
38942 */
38943 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
38944 assert( eFileLock!=PENDING_LOCK );
38945 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
@@ -40153,11 +40337,11 @@
40153 return SQLITE_OK;
40154 }
40155
40156 /* Make sure the locking sequence is correct
40157 ** (1) We never move from unlocked to anything higher than shared lock.
40158 ** (2) SQLite never explicitly requests a pendig lock.
40159 ** (3) A shared lock is always held when a reserve lock is requested.
40160 */
40161 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
40162 assert( eFileLock!=PENDING_LOCK );
40163 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
@@ -40269,11 +40453,11 @@
40269 ** reestablish the shared lock if we can't get the afpUnlock
40270 */
40271 if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST +
40272 pInode->sharedByte, 1, 0)) ){
40273 int failed2 = SQLITE_OK;
40274 /* now attemmpt to get the exclusive lock range */
40275 failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST,
40276 SHARED_SIZE, 1);
40277 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
40278 SHARED_FIRST + pInode->sharedByte, 1, 1)) ){
40279 /* Can't reestablish the shared lock. Sqlite can't deal, this is
@@ -40564,11 +40748,11 @@
40564 || offset+amt<=PENDING_BYTE
40565 );
40566 #endif
40567
40568 #if SQLITE_MAX_MMAP_SIZE>0
40569 /* Deal with as much of this read request as possible by transfering
40570 ** data from the memory mapping using memcpy(). */
40571 if( offset<pFile->mmapSize ){
40572 if( offset+amt <= pFile->mmapSize ){
40573 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
40574 return SQLITE_OK;
@@ -40716,11 +40900,11 @@
40716 }
40717 }
40718 #endif
40719
40720 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
40721 /* Deal with as much of this write request as possible by transfering
40722 ** data from the memory mapping using memcpy(). */
40723 if( offset<pFile->mmapSize ){
40724 if( offset+amt <= pFile->mmapSize ){
40725 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
40726 return SQLITE_OK;
@@ -40838,11 +41022,11 @@
40838 #endif
40839
40840 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
40841 ** no-op. But go ahead and call fstat() to validate the file
40842 ** descriptor as we need a method to provoke a failure during
40843 ** coverate testing.
40844 */
40845 #ifdef SQLITE_NO_SYNC
40846 {
40847 struct stat buf;
40848 rc = osFstat(fd, &buf);
@@ -46478,11 +46662,11 @@
46478
46479 }; /* End of the overrideable system calls */
46480
46481 /*
46482 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
46483 ** "win32" VFSes. Return SQLITE_OK opon successfully updating the
46484 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
46485 ** system call named zName.
46486 */
46487 static int winSetSystemCall(
46488 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
@@ -48058,11 +48242,11 @@
48058 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
48059 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
48060 pFile->h, pBuf, amt, offset, pFile->locktype));
48061
48062 #if SQLITE_MAX_MMAP_SIZE>0
48063 /* Deal with as much of this read request as possible by transfering
48064 ** data from the memory mapping using memcpy(). */
48065 if( offset<pFile->mmapSize ){
48066 if( offset+amt <= pFile->mmapSize ){
48067 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
48068 OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
@@ -48136,11 +48320,11 @@
48136 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
48137 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
48138 pFile->h, pBuf, amt, offset, pFile->locktype));
48139
48140 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
48141 /* Deal with as much of this write request as possible by transfering
48142 ** data from the memory mapping using memcpy(). */
48143 if( offset<pFile->mmapSize ){
48144 if( offset+amt <= pFile->mmapSize ){
48145 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
48146 OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
@@ -48246,11 +48430,11 @@
48246 **
48247 ** The only feasible work-around is to defer the truncation until after
48248 ** all references to memory-mapped content are closed. That is doable,
48249 ** but involves adding a few branches in the common write code path which
48250 ** could slow down normal operations slightly. Hence, we have decided for
48251 ** now to simply make trancations a no-op if there are pending reads. We
48252 ** can maybe revisit this decision in the future.
48253 */
48254 return SQLITE_OK;
48255 }
48256 #endif
@@ -48305,11 +48489,11 @@
48305 }
48306
48307 #ifdef SQLITE_TEST
48308 /*
48309 ** Count the number of fullsyncs and normal syncs. This is used to test
48310 ** that syncs and fullsyncs are occuring at the right times.
48311 */
48312 SQLITE_API int sqlite3_sync_count = 0;
48313 SQLITE_API int sqlite3_fullsync_count = 0;
48314 #endif
48315
@@ -52643,11 +52827,11 @@
52643 return SQLITE_OK;
52644 }
52645 h = BITVEC_HASH(i++);
52646 /* if there wasn't a hash collision, and this doesn't */
52647 /* completely fill the hash, then just add it without */
52648 /* worring about sub-dividing and re-hashing. */
52649 if( !p->u.aHash[h] ){
52650 if (p->nSet<(BITVEC_NINT-1)) {
52651 goto bitvec_set_end;
52652 } else {
52653 goto bitvec_set_rehash;
@@ -53140,11 +53324,11 @@
53140 /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
53141 ** suggested cache size is set to N. */
53142 return p->szCache;
53143 }else{
53144 i64 n;
53145 /* IMPLEMANTATION-OF: R-59858-46238 If the argument N is negative, then the
53146 ** number of cache pages is adjusted to be a number of pages that would
53147 ** use approximately abs(N*1024) bytes of memory based on the current
53148 ** page size. */
53149 n = ((-1024*(i64)p->szCache)/(p->szPage+p->szExtra));
53150 if( n>1000000000 ) n = 1000000000;
@@ -53628,11 +53812,11 @@
53628 }
53629 return result.pDirty;
53630 }
53631
53632 /*
53633 ** Sort the list of pages in accending order by pgno. Pages are
53634 ** connected by pDirty pointers. The pDirtyPrev pointers are
53635 ** corrupted by this sort.
53636 **
53637 ** Since there cannot be more than 2^31 distinct pages in a database,
53638 ** there cannot be more than 31 buckets required by the merge sorter.
@@ -53868,11 +54052,11 @@
53868 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
53869 **
53870 ** If N is positive, then N pages worth of memory are allocated using a single
53871 ** sqlite3Malloc() call and that memory is used for the first N pages allocated.
53872 ** Or if N is negative, then -1024*N bytes of memory are allocated and used
53873 ** for as many pages as can be accomodated.
53874 **
53875 ** Only one of (2) or (3) can be used. Once the memory available to (2) or
53876 ** (3) is exhausted, subsequent allocations fail over to the general-purpose
53877 ** memory allocator (1).
53878 **
@@ -53902,11 +54086,11 @@
53902 ** but causes a 2-byte gap in the structure for most architectures (since
53903 ** pointers must be either 4 or 8-byte aligned). As this structure is located
53904 ** in memory directly after the associated page data, if the database is
53905 ** corrupt, code at the b-tree layer may overread the page buffer and
53906 ** read part of this structure before the corruption is detected. This
53907 ** can cause a valgrind error if the unitialized gap is accessed. Using u16
53908 ** ensures there is no such gap, and therefore no bytes of uninitialized
53909 ** memory in the structure.
53910 **
53911 ** The pLruNext and pLruPrev pointers form a double-linked circular list
53912 ** of all pages that are unpinned. The PGroup.lru element (which should be
@@ -55122,11 +55306,11 @@
55122 ** until DESTROY.
55123 **
55124 ** The TEST primitive includes a "batch" number. The TEST primitive
55125 ** will only see elements that were inserted before the last change
55126 ** in the batch number. In other words, if an INSERT occurs between
55127 ** two TESTs where the TESTs have the same batch nubmer, then the
55128 ** value added by the INSERT will not be visible to the second TEST.
55129 ** The initial batch number is zero, so if the very first TEST contains
55130 ** a non-zero batch number, it will see all prior INSERTs.
55131 **
55132 ** No INSERTs may occurs after a SMALLEST. An assertion will fail if
@@ -56045,11 +56229,11 @@
56045 ** Once it has entered the ERROR state, any attempt to use the pager
56046 ** to read or write data returns an error. Eventually, once all
56047 ** outstanding transactions have been abandoned, the pager is able to
56048 ** transition back to OPEN state, discarding the contents of the
56049 ** page-cache and any other in-memory state at the same time. Everything
56050 ** is reloaded from disk (and, if necessary, hot-journal rollback peformed)
56051 ** when a read-transaction is next opened on the pager (transitioning
56052 ** the pager into READER state). At that point the system has recovered
56053 ** from the error.
56054 **
56055 ** Specifically, the pager jumps into the ERROR state if:
@@ -57418,11 +57602,11 @@
57418 ** + N bytes: super-journal filename in utf-8.
57419 ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
57420 ** + 4 bytes: super-journal name checksum.
57421 ** + 8 bytes: aJournalMagic[].
57422 **
57423 ** The super-journal page checksum is the sum of the bytes in thesuper-journal
57424 ** name, where each byte is interpreted as a signed 8-bit integer.
57425 **
57426 ** If zSuper is a NULL pointer (occurs for a single database transaction),
57427 ** this call is a no-op.
57428 */
@@ -57471,11 +57655,11 @@
57471 ){
57472 return rc;
57473 }
57474 pPager->journalOff += (nSuper+20);
57475
57476 /* If the pager is in peristent-journal mode, then the physical
57477 ** journal-file may extend past the end of the super-journal name
57478 ** and 8 bytes of magic data just written to the file. This is
57479 ** dangerous because the code to rollback a hot-journal file
57480 ** will not be able to find the super-journal name to determine
57481 ** whether or not the journal is hot.
@@ -57641,11 +57825,11 @@
57641 pPager->setSuper = 0;
57642 }
57643
57644 /*
57645 ** This function is called whenever an IOERR or FULL error that requires
57646 ** the pager to transition into the ERROR state may ahve occurred.
57647 ** The first argument is a pointer to the pager structure, the second
57648 ** the error-code about to be returned by a pager API function. The
57649 ** value returned is a copy of the second argument to this function.
57650 **
57651 ** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the
@@ -57916,11 +58100,11 @@
57916 pager_unlock(pPager);
57917 }
57918
57919 /*
57920 ** Parameter aData must point to a buffer of pPager->pageSize bytes
57921 ** of data. Compute and return a checksum based ont the contents of the
57922 ** page of data and the current value of pPager->cksumInit.
57923 **
57924 ** This is not a real checksum. It is really just the sum of the
57925 ** random initial value (pPager->cksumInit) and every 200th byte
57926 ** of the page data, starting with byte offset (pPager->pageSize%200).
@@ -58882,11 +59066,11 @@
58882 PgHdr *p; /* For looping over pages */
58883
58884 assert( pPager->pWal );
58885 assert( pList );
58886 #ifdef SQLITE_DEBUG
58887 /* Verify that the page list is in accending order */
58888 for(p=pList; p && p->pDirty; p=p->pDirty){
58889 assert( p->pgno < p->pDirty->pgno );
58890 }
58891 #endif
58892
@@ -59013,11 +59197,11 @@
59013 }
59014
59015 #ifndef SQLITE_OMIT_WAL
59016 /*
59017 ** Check if the *-wal file that corresponds to the database opened by pPager
59018 ** exists if the database is not empy, or verify that the *-wal file does
59019 ** not exist (by deleting it) if the database file is empty.
59020 **
59021 ** If the database is not empty and the *-wal file exists, open the pager
59022 ** in WAL mode. If the database is empty or if no *-wal file exists and
59023 ** if no error occurs, make sure Pager.journalMode is not set to
@@ -60765,11 +60949,11 @@
60765 return SQLITE_OK;
60766 }
60767
60768 /*
60769 ** Return the sqlite3_file for the main database given the name
60770 ** of the corresonding WAL or Journal name as passed into
60771 ** xOpen.
60772 */
60773 SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *zName){
60774 Pager *pPager;
60775 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
@@ -63050,11 +63234,11 @@
63050
63051 /* Change the journal mode. */
63052 assert( pPager->eState!=PAGER_ERROR );
63053 pPager->journalMode = (u8)eMode;
63054
63055 /* When transistioning from TRUNCATE or PERSIST to any other journal
63056 ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
63057 ** delete the journal file.
63058 */
63059 assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
63060 assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
@@ -63768,11 +63952,11 @@
63768 ** of available reader locks and should be at least 3. The default
63769 ** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5.
63770 **
63771 ** Technically, the various VFSes are free to implement these locks however
63772 ** they see fit. However, compatibility is encouraged so that VFSes can
63773 ** interoperate. The standard implemention used on both unix and windows
63774 ** is for the index number to indicate a byte offset into the
63775 ** WalCkptInfo.aLock[] array in the wal-index header. In other words, all
63776 ** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which
63777 ** should be 120) is the location in the shm file for the first locking
63778 ** byte.
@@ -63844,11 +64028,11 @@
63844 ** There is one entry in aReadMark[] for each reader lock. If a reader
63845 ** holds read-lock K, then the value in aReadMark[K] is no greater than
63846 ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff)
63847 ** for any aReadMark[] means that entry is unused. aReadMark[0] is
63848 ** a special case; its value is never used and it exists as a place-holder
63849 ** to avoid having to offset aReadMark[] indexs by one. Readers holding
63850 ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
63851 ** directly from the database.
63852 **
63853 ** The value of aReadMark[K] may only be changed by a thread that
63854 ** is holding an exclusive lock on WAL_READ_LOCK(K). Thus, the value of
@@ -64374,19 +64558,19 @@
64374 */
64375 if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
64376 return 0;
64377 }
64378
64379 /* A frame is only valid if the page number is creater than zero.
64380 */
64381 pgno = sqlite3Get4byte(&aFrame[0]);
64382 if( pgno==0 ){
64383 return 0;
64384 }
64385
64386 /* A frame is only valid if a checksum of the WAL header,
64387 ** all prior frams, the first 16 bytes of this frame-header,
64388 ** and the frame-data matches the checksum in the last 8
64389 ** bytes of this frame-header.
64390 */
64391 nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
64392 walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
@@ -65076,11 +65260,11 @@
65076 }
65077 return rc;
65078 }
65079
65080 /*
65081 ** Change the size to which the WAL file is trucated on each reset.
65082 */
65083 SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){
65084 if( pWal ) pWal->mxWalSize = iLimit;
65085 }
65086
@@ -65775,11 +65959,11 @@
65775 sqlite3OsFileControlHint(
65776 pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist
65777 );
65778 if( bPersist!=1 ){
65779 /* Try to delete the WAL file if the checkpoint completed and
65780 ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
65781 ** mode (!bPersist) */
65782 isDelete = 1;
65783 }else if( pWal->mxWalSize>=0 ){
65784 /* Try to truncate the WAL file to zero bytes if the checkpoint
65785 ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
@@ -65842,11 +66026,11 @@
65842 ** Memory barriers are used to prevent the compiler or the hardware from
65843 ** reordering the reads and writes. TSAN and similar tools can sometimes
65844 ** give false-positive warnings about these accesses because the tools do not
65845 ** account for the double-read and the memory barrier. The use of mutexes
65846 ** here would be problematic as the memory being accessed is potentially
65847 ** shared among multiple processes and not all mutex implementions work
65848 ** reliably in that environment.
65849 */
65850 aHdr = walIndexHdr(pWal);
65851 memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
65852 walShmBarrier(pWal);
@@ -67947,11 +68131,11 @@
67947 /*
67948 ** An instance of this object stores information about each a single database
67949 ** page that has been loaded into memory. The information in this object
67950 ** is derived from the raw on-disk page content.
67951 **
67952 ** As each database page is loaded into memory, the pager allocats an
67953 ** instance of this object and zeros the first 8 bytes. (This is the
67954 ** "extra" information associated with each page of the pager.)
67955 **
67956 ** Access to all fields of this structure is controlled by the mutex
67957 ** stored in MemPage.pBt->mutex.
@@ -68403,11 +68587,11 @@
68403 #define get4byte sqlite3Get4byte
68404 #define put4byte sqlite3Put4byte
68405
68406 /*
68407 ** get2byteAligned(), unlike get2byte(), requires that its argument point to a
68408 ** two-byte aligned address. get2bytea() is only used for accessing the
68409 ** cell addresses in a btree header.
68410 */
68411 #if SQLITE_BYTEORDER==4321
68412 # define get2byteAligned(x) (*(u16*)(x))
68413 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
@@ -68580,11 +68764,11 @@
68580 ** against all schemas and we do not want those schemas being
68581 ** reset out from under us.
68582 **
68583 ** There is a corresponding leave-all procedures.
68584 **
68585 ** Enter the mutexes in accending order by BtShared pointer address
68586 ** to avoid the possibility of deadlock when two threads with
68587 ** two or more btrees in common both try to lock all their btrees
68588 ** at the same instant.
68589 */
68590 static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){
@@ -68712,10 +68896,11 @@
68712
68713 #endif /* ifndef SQLITE_OMIT_SHARED_CACHE */
68714
68715 /************** End of btmutex.c *********************************************/
68716 /************** Begin file btree.c *******************************************/
 
68717 /*
68718 ** 2004 April 6
68719 **
68720 ** The author disclaims copyright to this source code. In place of
68721 ** a legal notice, here is a blessing:
@@ -70348,11 +70533,11 @@
70348 cbrk = usableSize;
70349 iCellLast = usableSize - 4;
70350 iCellStart = get2byte(&data[hdr+5]);
70351 if( nCell>0 ){
70352 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
70353 memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
70354 src = temp;
70355 for(i=0; i<nCell; i++){
70356 u8 *pAddr; /* The i-th cell pointer */
70357 pAddr = &data[cellOffset + i*2];
70358 pc = get2byte(pAddr);
@@ -70572,11 +70757,11 @@
70572 **
70573 ** Adjacent freeblocks are coalesced.
70574 **
70575 ** Even though the freeblock list was checked by btreeComputeFreeSpace(),
70576 ** that routine will not detect overlap between cells or freeblocks. Nor
70577 ** does it detect cells or freeblocks that encrouch into the reserved bytes
70578 ** at the end of the page. So do additional corruption checks inside this
70579 ** routine and return SQLITE_CORRUPT if any problems are found.
70580 */
70581 static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
70582 u16 iPtr; /* Address of ptr to next freeblock */
@@ -71175,11 +71360,11 @@
71175 /* pPage might not be a btree page; it might be an overflow page
71176 ** or ptrmap page or a free page. In those cases, the following
71177 ** call to btreeInitPage() will likely return SQLITE_CORRUPT.
71178 ** But no harm is done by this. And it is very important that
71179 ** btreeInitPage() be called on every btree page so we make
71180 ** the call for every page that comes in for re-initing. */
71181 btreeInitPage(pPage);
71182 }
71183 }
71184 }
71185
@@ -71570,11 +71755,11 @@
71570 ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
71571 ** by the various routines that manipulate binary cells. Which
71572 ** can mean that fillInCell() only initializes the first 2 or 3
71573 ** bytes of pTmpSpace, but that the first 4 bytes are copied from
71574 ** it into a database page. This is not actually a problem, but it
71575 ** does cause a valgrind error when the 1 or 2 bytes of unitialized
71576 ** data is passed to system call write(). So to avoid this error,
71577 ** zero the first 4 bytes of temp space here.
71578 **
71579 ** Also: Provide four bytes of initialized space before the
71580 ** beginning of pTmpSpace as an area available to prepend the
@@ -71805,11 +71990,11 @@
71805 return n;
71806 }
71807
71808 /*
71809 ** Return the number of bytes of space at the end of every page that
71810 ** are intentually left unused. This is the "reserved" space that is
71811 ** sometimes used by extensions.
71812 **
71813 ** The value returned is the larger of the current reserve size and
71814 ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES.
71815 ** The amount of reserve can only grow - never shrink.
@@ -72052,11 +72237,10 @@
72052 || pageSize>SQLITE_MAX_PAGE_SIZE
72053 || pageSize<=256
72054 ){
72055 goto page1_init_failed;
72056 }
72057 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
72058 assert( (pageSize & 7)==0 );
72059 /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
72060 ** integer at offset 20 is the number of bytes of space at the end of
72061 ** each page to reserve for extensions.
72062 **
@@ -72072,10 +72256,11 @@
72072 ** again with the correct page-size.
72073 */
72074 releasePageOne(pPage1);
72075 pBt->usableSize = usableSize;
72076 pBt->pageSize = pageSize;
 
72077 freeTempSpace(pBt);
72078 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
72079 pageSize-usableSize);
72080 return rc;
72081 }
@@ -72091,10 +72276,11 @@
72091 ** be less than 480. In other words, if the page size is 512, then the
72092 ** reserved space size cannot exceed 32. */
72093 if( usableSize<480 ){
72094 goto page1_init_failed;
72095 }
 
72096 pBt->pageSize = pageSize;
72097 pBt->usableSize = usableSize;
72098 #ifndef SQLITE_OMIT_AUTOVACUUM
72099 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
72100 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
@@ -72269,11 +72455,15 @@
72269 ** One or the other of the two processes must give way or there can be
72270 ** no progress. By returning SQLITE_BUSY and not invoking the busy callback
72271 ** when A already has a read lock, we encourage A to give up and let B
72272 ** proceed.
72273 */
72274 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
 
 
 
 
72275 BtShared *pBt = p->pBt;
72276 Pager *pPager = pBt->pPager;
72277 int rc = SQLITE_OK;
72278
72279 sqlite3BtreeEnter(p);
@@ -72440,10 +72630,32 @@
72440 }
72441
72442 btreeIntegrity(p);
72443 sqlite3BtreeLeave(p);
72444 return rc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72445 }
72446
72447 #ifndef SQLITE_OMIT_AUTOVACUUM
72448
72449 /*
@@ -73574,11 +73786,11 @@
73574 **
73575 ** This is an optimization. Everything will still work if this
73576 ** routine always returns 2147483647 (which is the largest record
73577 ** that SQLite can handle) or more. But returning a smaller value might
73578 ** prevent large memory allocations when trying to interpret a
73579 ** corrupt datrabase.
73580 **
73581 ** The current implementation merely returns the size of the underlying
73582 ** database file.
73583 */
73584 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){
@@ -74374,11 +74586,11 @@
74374 return SQLITE_OK;
74375 }
74376 /* If the requested key is one more than the previous key, then
74377 ** try to get there using sqlite3BtreeNext() rather than a full
74378 ** binary search. This is an optimization only. The correct answer
74379 ** is still obtained without this case, only a little more slowely */
74380 if( pCur->info.nKey+1==intKey ){
74381 *pRes = 0;
74382 rc = sqlite3BtreeNext(pCur, 0);
74383 if( rc==SQLITE_OK ){
74384 getCellInfo(pCur);
@@ -75557,11 +75769,11 @@
75557 return SQLITE_OK;
75558 }
75559
75560 /* Call xParseCell to compute the size of a cell. If the cell contains
75561 ** overflow, then invoke cellClearOverflow to clear out that overflow.
75562 ** STore the result code (SQLITE_OK or some error code) in rc.
75563 **
75564 ** Implemented as macro to force inlining for performance.
75565 */
75566 #define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \
75567 pPage->xParseCell(pPage, pCell, &sInfo); \
@@ -76236,11 +76448,11 @@
76236 ** before returning.
76237 **
76238 ** Finally, argument pBegin points to the byte immediately following the
76239 ** end of the space required by this page for the cell-pointer area (for
76240 ** all cells - not just those inserted by the current call). If the content
76241 ** area must be extended to before this point in order to accomodate all
76242 ** cells in apCell[], then the cells do not fit and non-zero is returned.
76243 */
76244 static int pageInsertArray(
76245 MemPage *pPg, /* Page to add cells to */
76246 u8 *pBegin, /* End of cell-pointer array */
@@ -76551,11 +76763,11 @@
76551
76552 /* If this is an auto-vacuum database, update the pointer map
76553 ** with entries for the new page, and any pointer from the
76554 ** cell on the page to an overflow page. If either of these
76555 ** operations fails, the return code is set, but the contents
76556 ** of the parent page are still manipulated by thh code below.
76557 ** That is Ok, at this point the parent page is guaranteed to
76558 ** be marked as dirty. Returning an error code will cause a
76559 ** rollback, undoing any changes made to the parent page.
76560 */
76561 if( ISAUTOVACUUM(pBt) ){
@@ -77141,11 +77353,11 @@
77141 rc = SQLITE_CORRUPT_BKPT;
77142 goto balance_cleanup;
77143 }
77144 }
77145
77146 /* Sanity check: For a non-corrupt database file one of the follwing
77147 ** must be true:
77148 ** (1) We found one or more cells (cntNew[0])>0), or
77149 ** (2) pPage is a virtual root page. A virtual root page is when
77150 ** the real root page is page 1 and we are the only child of
77151 ** that page.
@@ -77758,11 +77970,11 @@
77758 int iOffset, /* Offset of first byte to write */
77759 int iAmt /* Number of bytes to be written */
77760 ){
77761 int nData = pX->nData - iOffset;
77762 if( nData<=0 ){
77763 /* Overwritting with zeros */
77764 int i;
77765 for(i=0; i<iAmt && pDest[i]==0; i++){}
77766 if( i<iAmt ){
77767 int rc = sqlite3PagerWrite(pPage->pDbPage);
77768 if( rc ) return rc;
@@ -77794,11 +78006,11 @@
77794 ** Overwrite the cell that cursor pCur is pointing to with fresh content
77795 ** contained in pX. In this variant, pCur is pointing to an overflow
77796 ** cell.
77797 */
77798 static SQLITE_NOINLINE int btreeOverwriteOverflowCell(
77799 BtCursor *pCur, /* Cursor pointing to cell to ovewrite */
77800 const BtreePayload *pX /* Content to write into the cell */
77801 ){
77802 int iOffset; /* Next byte of pX->pData to write */
77803 int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
77804 int rc; /* Return code */
@@ -78541,11 +78753,11 @@
78541 static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){
78542 BtShared *pBt = p->pBt;
78543 MemPage *pRoot;
78544 Pgno pgnoRoot;
78545 int rc;
78546 int ptfFlags; /* Page-type flage for the root page of new table */
78547
78548 assert( sqlite3BtreeHoldsMutex(p) );
78549 assert( pBt->inTransaction==TRANS_WRITE );
78550 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
78551
@@ -79376,11 +79588,11 @@
79376 pBt = pCheck->pBt;
79377 usableSize = pBt->usableSize;
79378 if( iPage==0 ) return 0;
79379 if( checkRef(pCheck, iPage) ) return 0;
79380 pCheck->zPfx = "Tree %u page %u: ";
79381 pCheck->v0 = pCheck->v1 = iPage;
79382 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
79383 checkAppendMsg(pCheck,
79384 "unable to get the page. error code=%d", rc);
79385 goto end_of_check;
79386 }
@@ -79713,10 +79925,11 @@
79713 #ifndef SQLITE_OMIT_AUTOVACUUM
79714 if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
79715 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
79716 }
79717 #endif
 
79718 checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
79719 }
79720 pBt->db->flags = savedDbFlags;
79721
79722 /* Make sure every page in the file is referenced
@@ -82256,10 +82469,11 @@
82256 if( pRec==0 ) return 0;
82257 p->ppRec[0] = pRec;
82258 }
82259
82260 pRec->nField = p->iVal+1;
 
82261 return &pRec->aMem[p->iVal];
82262 }
82263 #else
82264 UNUSED_PARAMETER(p);
82265 #endif /* defined(SQLITE_ENABLE_STAT4) */
@@ -83652,11 +83866,11 @@
83652 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
83653 p->readOnly = 1;
83654 p->bIsReader = 0;
83655 pOp = &p->aOp[p->nOp-1];
83656 assert( p->aOp[0].opcode==OP_Init );
83657 while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
83658 /* Only JUMP opcodes and the short list of special opcodes in the switch
83659 ** below need to be considered. The mkopcodeh.tcl generator script groups
83660 ** all these opcodes together near the front of the opcode list. Skip
83661 ** any opcode that does not need processing by virtual of the fact that
83662 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -84106,11 +84320,11 @@
84106 }
84107
84108
84109 /*
84110 ** If the input FuncDef structure is ephemeral, then free it. If
84111 ** the FuncDef is not ephermal, then do nothing.
84112 */
84113 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
84114 assert( db!=0 );
84115 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
84116 sqlite3DbNNFreeNN(db, pDef);
@@ -87057,10 +87271,19 @@
87057 ** sqlite3VdbeSerialTypeLen() in the common case.
87058 */
87059 if( d1+(u64)serial_type1+2>(u64)nKey1
87060 && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)>(u64)nKey1
87061 ){
 
 
 
 
 
 
 
 
 
87062 break;
87063 }
87064
87065 /* Extract the values to be compared.
87066 */
@@ -87500,11 +87723,11 @@
87500 serial_type = aKey1[idx1];
87501 if( serial_type>=10 ){
87502 /* Serial types 12 or greater are strings and blobs (greater than
87503 ** numbers). Types 10 and 11 are currently "reserved for future
87504 ** use", so it doesn't really matter what the results of comparing
87505 ** them to numberic values are. */
87506 rc = serial_type==10 ? -1 : +1;
87507 }else if( serial_type==0 ){
87508 rc = -1;
87509 }else{
87510 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
@@ -89129,11 +89352,11 @@
89129
89130 /*
89131 ** The destructor function for a ValueList object. This needs to be
89132 ** a separate function, unknowable to the application, to ensure that
89133 ** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not
89134 ** preceeded by activation of IN processing via sqlite3_vtab_int() do not
89135 ** try to access a fake ValueList object inserted by a hostile extension.
89136 */
89137 SQLITE_PRIVATE void sqlite3VdbeValueListFree(void *pToDelete){
89138 sqlite3_free(pToDelete);
89139 }
@@ -89458,11 +89681,11 @@
89458 ** sqlite3_column_text()
89459 ** sqlite3_column_text16()
89460 ** sqlite3_column_real()
89461 ** sqlite3_column_bytes()
89462 ** sqlite3_column_bytes16()
89463 ** sqiite3_column_blob()
89464 */
89465 static void columnMallocFailure(sqlite3_stmt *pStmt)
89466 {
89467 /* If malloc() failed during an encoding conversion within an
89468 ** sqlite3_column_XXX API, then set the return code of the statement to
@@ -89693,11 +89916,11 @@
89693 ** Routines used to attach values to wildcards in a compiled SQL statement.
89694 */
89695 /*
89696 ** Unbind the value bound to variable i in virtual machine p. This is the
89697 ** the same as binding a NULL value to the column. If the "i" parameter is
89698 ** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
89699 **
89700 ** A successful evaluation of this routine acquires the mutex on p.
89701 ** the mutex is released if any kind of error occurs.
89702 **
89703 ** The error code stored in database p->db is overwritten with the return
@@ -91669,12 +91892,12 @@
91669 ** to the current line should be indented for EXPLAIN output.
91670 */
91671 case OP_Goto: { /* jump */
91672
91673 #ifdef SQLITE_DEBUG
91674 /* In debuggging mode, when the p5 flags is set on an OP_Goto, that
91675 ** means we should really jump back to the preceeding OP_ReleaseReg
91676 ** instruction. */
91677 if( pOp->p5 ){
91678 assert( pOp->p2 < (int)(pOp - aOp) );
91679 assert( pOp->p2 > 1 );
91680 pOp = &aOp[pOp->p2 - 2];
@@ -91878,11 +92101,11 @@
91878 ** If P4 is not null then it is an error message string.
91879 **
91880 ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
91881 **
91882 ** 0: (no change)
91883 ** 1: NOT NULL contraint failed: P4
91884 ** 2: UNIQUE constraint failed: P4
91885 ** 3: CHECK constraint failed: P4
91886 ** 4: FOREIGN KEY constraint failed: P4
91887 **
91888 ** If P5 is not zero and P4 is NULL, then everything after the ":" is
@@ -95105,11 +95328,11 @@
95105 aMem[pOp->p3].n = 0;
95106 aMem[pOp->p3].z = "";
95107 }
95108 pCx = p->apCsr[pOp->p1];
95109 if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){
95110 /* If the ephermeral table is already open and has no duplicates from
95111 ** OP_OpenDup, then erase all existing content so that the table is
95112 ** empty again, rather than creating a new table. */
95113 assert( pCx->isEphemeral );
95114 pCx->seqCount = 0;
95115 pCx->cacheStatus = CACHE_STALE;
@@ -95596,19 +95819,19 @@
95596 ** The This.P5 parameter is a flag that indicates what to do if the
95597 ** cursor ends up pointing at a valid row that is past the target
95598 ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If
95599 ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
95600 ** case occurs when there are no inequality constraints to the right of
95601 ** the IN constraing. The jump to SeekGE.P2 ends the loop. The P5!=0 case
95602 ** occurs when there are inequality constraints to the right of the IN
95603 ** operator. In that case, the This.P2 will point either directly to or
95604 ** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for
95605 ** loop terminate.
95606 **
95607 ** Possible outcomes from this opcode:<ol>
95608 **
95609 ** <li> If the cursor is initally not pointed to any valid row, then
95610 ** fall through into the subsequent OP_SeekGE opcode.
95611 **
95612 ** <li> If the cursor is left pointing to a row that is before the target
95613 ** row, even after making as many as This.P1 calls to
95614 ** sqlite3BtreeNext(), then also fall through into OP_SeekGE.
@@ -98277,11 +98500,11 @@
98277 #endif
98278
98279 /* If this function is inside of a trigger, the register array in aMem[]
98280 ** might change from one evaluation to the next. The next block of code
98281 ** checks to see if the register array has changed, and if so it
98282 ** reinitializes the relavant parts of the sqlite3_context object */
98283 if( pCtx->pMem != pMem ){
98284 pCtx->pMem = pMem;
98285 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
98286 }
98287
@@ -99155,11 +99378,11 @@
99155 ** invocation of this opcode.
99156 **
99157 ** This opcode works exactly like OP_Function. The only difference is in
99158 ** its name. This opcode is used in places where the function must be
99159 ** purely non-deterministic. Some built-in date/time functions can be
99160 ** either determinitic of non-deterministic, depending on their arguments.
99161 ** When those function are used in a non-deterministic way, they will check
99162 ** to see if they were called using OP_PureFunc instead of OP_Function, and
99163 ** if they were, they throw an error.
99164 **
99165 ** See also: AggStep, AggFinal, Function
@@ -99173,11 +99396,11 @@
99173 pCtx = pOp->p4.pCtx;
99174
99175 /* If this function is inside of a trigger, the register array in aMem[]
99176 ** might change from one evaluation to the next. The next block of code
99177 ** checks to see if the register array has changed, and if so it
99178 ** reinitializes the relavant parts of the sqlite3_context object */
99179 pOut = &aMem[pOp->p3];
99180 if( pCtx->pOut != pOut ){
99181 pCtx->pVdbe = p;
99182 pCtx->pOut = pOut;
99183 pCtx->enc = encoding;
@@ -99249,11 +99472,11 @@
99249 registerTrace(ii, &aMem[ii]);
99250 }
99251 printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
99252 }
99253 #endif
99254 h %= pIn1->n;
99255 pIn1->z[h/8] |= 1<<(h&7);
99256 break;
99257 }
99258
99259 /* Opcode: Filter P1 P2 P3 P4 *
@@ -99285,11 +99508,11 @@
99285 registerTrace(ii, &aMem[ii]);
99286 }
99287 printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
99288 }
99289 #endif
99290 h %= pIn1->n;
99291 if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){
99292 VdbeBranchTaken(1, 2);
99293 p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++;
99294 goto jump_to_p2;
99295 }else{
@@ -99537,11 +99760,11 @@
99537 if( opProperty & OPFLG_OUT3 ){
99538 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
99539 }
99540 if( opProperty==0xff ){
99541 /* Never happens. This code exists to avoid a harmless linkage
99542 ** warning aboud sqlite3VdbeRegisterDump() being defined but not
99543 ** used. */
99544 sqlite3VdbeRegisterDump(p);
99545 }
99546 }
99547 #endif /* SQLITE_DEBUG */
@@ -100255,11 +100478,11 @@
100255 ** merging two or more level-0 PMAs together creates a level-1 PMA.
100256 **
100257 ** The threshold for the amount of main memory to use before flushing
100258 ** records to a PMA is roughly the same as the limit configured for the
100259 ** page-cache of the main database. Specifically, the threshold is set to
100260 ** the value returned by "PRAGMA main.page_size" multipled by
100261 ** that returned by "PRAGMA main.cache_size", in bytes.
100262 **
100263 ** If the sorter is running in single-threaded mode, then all PMAs generated
100264 ** are appended to a single temporary file. Or, if the sorter is running in
100265 ** multi-threaded mode then up to (N+1) temporary files may be opened, where
@@ -100278,11 +100501,11 @@
100278 ** final PMA. So at this point the data is stored in some number of sorted
100279 ** PMAs within temporary files on disk.
100280 **
100281 ** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the
100282 ** sorter is running in single-threaded mode, then these PMAs are merged
100283 ** incrementally as keys are retreived from the sorter by the VDBE. The
100284 ** MergeEngine object, described in further detail below, performs this
100285 ** merge.
100286 **
100287 ** Or, if running in multi-threaded mode, then a background thread is
100288 ** launched to merge the existing PMAs. Once the background thread has
@@ -100441,11 +100664,11 @@
100441 ** single-threaded operation, there is exactly one instance of this object
100442 ** and for multi-threaded operation there are two or more instances.
100443 **
100444 ** Essentially, this structure contains all those fields of the VdbeSorter
100445 ** structure for which each thread requires a separate instance. For example,
100446 ** each thread requries its own UnpackedRecord object to unpack records in
100447 ** as part of comparison operations.
100448 **
100449 ** Before a background thread is launched, variable bDone is set to 0. Then,
100450 ** right before it exits, the thread itself sets bDone to 1. This is used for
100451 ** two purposes:
@@ -100513,11 +100736,11 @@
100513 /*
100514 ** An instance of the following object is used to read records out of a
100515 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
100516 ** aKey might point into aMap or into aBuffer. If neither of those locations
100517 ** contain a contiguous representation of the key, then aAlloc is allocated
100518 ** and the key is copied into aAlloc and aKey is made to poitn to aAlloc.
100519 **
100520 ** pFd==0 at EOF.
100521 */
100522 struct PmaReader {
100523 i64 iReadOff; /* Current read offset */
@@ -101884,11 +102107,11 @@
101884 ** records to disk. If the sorter is running in multi-threaded mode,
101885 ** round-robin between the first (pSorter->nTask-1) tasks. Except, if
101886 ** the background thread from a sub-tasks previous turn is still running,
101887 ** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy,
101888 ** fall back to using the final sub-task. The first (pSorter->nTask-1)
101889 ** sub-tasks are prefered as they use background threads - the final
101890 ** sub-task uses the main thread. */
101891 for(i=0; i<nWorker; i++){
101892 int iTest = (pSorter->iPrev + i + 1) % nWorker;
101893 pTask = &pSorter->aTask[iTest];
101894 if( pTask->bDone ){
@@ -102368,11 +102591,11 @@
102368 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
102369 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
102370
102371 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
102372
102373 /* Set up the required files for pIncr. A multi-theaded IncrMerge object
102374 ** requires two temp files to itself, whereas a single-threaded object
102375 ** only requires a region of pTask->file2. */
102376 if( rc==SQLITE_OK ){
102377 int mxSz = pIncr->mxSz;
102378 #if SQLITE_MAX_WORKER_THREADS>0
@@ -104033,11 +104256,11 @@
104033 }while( p!=0 );
104034 return WRC_Continue;
104035 }
104036
104037 /* Increase the walkerDepth when entering a subquery, and
104038 ** descrease when leaving the subquery.
104039 */
104040 SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){
104041 UNUSED_PARAMETER(pSelect);
104042 pWalker->walkerDepth++;
104043 return WRC_Continue;
@@ -105767,11 +105990,11 @@
105767 if( sqlite3ResolveExprNames(pNC, pE) ){
105768 return 1;
105769 }
105770 for(j=0; j<pSelect->pEList->nExpr; j++){
105771 if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
105772 /* Since this expresion is being changed into a reference
105773 ** to an identical expression in the result set, remove all Window
105774 ** objects belonging to the expression from the Select.pWin list. */
105775 windowRemoveExprFromSelect(pSelect, pE);
105776 pItem->u.x.iOrderByCol = j+1;
105777 }
@@ -106154,11 +106377,11 @@
106154 return WRC_Continue;
106155 }
106156
106157 /*
106158 ** Resolve all names in all expressions of a SELECT and in all
106159 ** decendents of the SELECT, including compounds off of p->pPrior,
106160 ** subqueries in expressions, and subqueries used as FROM clause
106161 ** terms.
106162 **
106163 ** See sqlite3ResolveExprNames() for a description of the kinds of
106164 ** transformations that occur.
@@ -106304,10 +106527,11 @@
106304 }
106305 #endif
106306 if( op==TK_SELECT_COLUMN ){
106307 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
106308 assert( pExpr->iColumn < pExpr->iTable );
 
106309 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
106310 return sqlite3ExprAffinity(
106311 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
106312 );
106313 }
@@ -106540,11 +106764,11 @@
106540 }
106541
106542 /*
106543 ** Return the collation sequence for the expression pExpr. If
106544 ** there is no defined collating sequence, return a pointer to the
106545 ** defautl collation sequence.
106546 **
106547 ** See also: sqlite3ExprCollSeq()
106548 **
106549 ** The sqlite3ExprCollSeq() routine works the same except that it
106550 ** returns NULL if there is no defined collation.
@@ -106670,11 +106894,11 @@
106670 }
106671 }
106672 return pColl;
106673 }
106674
106675 /* Expresssion p is a comparison operator. Return a collation sequence
106676 ** appropriate for the comparison operator.
106677 **
106678 ** This is normally just a wrapper around sqlite3BinaryCompareCollSeq().
106679 ** However, if the OP_Commuted flag is set, then the order of the operands
106680 ** is reversed in the sqlite3BinaryCompareCollSeq() call so that the
@@ -107586,11 +107810,11 @@
107586 }
107587
107588 /*
107589 ** Arrange to cause pExpr to be deleted when the pParse is deleted.
107590 ** This is similar to sqlite3ExprDelete() except that the delete is
107591 ** deferred untilthe pParse is deleted.
107592 **
107593 ** The pExpr might be deleted immediately on an OOM error.
107594 **
107595 ** The deferred delete is (currently) implemented by adding the
107596 ** pExpr to the pParse->pConstExpr list with a register number of 0.
@@ -108428,11 +108652,11 @@
108428 /*
108429 ** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE
108430 ** and 0 if it is FALSE.
108431 */
108432 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
108433 pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
108434 assert( pExpr->op==TK_TRUEFALSE );
108435 assert( !ExprHasProperty(pExpr, EP_IntValue) );
108436 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
108437 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
108438 return pExpr->u.zToken[4]==0;
@@ -109021,11 +109245,11 @@
109021 **
109022 ** IN_INDEX_ROWID - The cursor was opened on a database table.
109023 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
109024 ** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index.
109025 ** IN_INDEX_EPH - The cursor was opened on a specially created and
109026 ** populated epheremal table.
109027 ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
109028 ** implemented as a sequence of comparisons.
109029 **
109030 ** An existing b-tree might be used if the RHS expression pX is a simple
109031 ** subquery such as:
@@ -109034,11 +109258,11 @@
109034 **
109035 ** If the RHS of the IN operator is a list or a more complex subquery, then
109036 ** an ephemeral table might need to be generated from the RHS and then
109037 ** pX->iTable made to point to the ephemeral table instead of an
109038 ** existing table. In this case, the creation and initialization of the
109039 ** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
109040 ** will be set on pX and the pX->y.sub fields will be set to show where
109041 ** the subroutine is coded.
109042 **
109043 ** The inFlags parameter must contain, at a minimum, one of the bits
109044 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
@@ -109046,16 +109270,16 @@
109046 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
109047 ** be used to loop over all values of the RHS of the IN operator.
109048 **
109049 ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
109050 ** through the set members) then the b-tree must not contain duplicates.
109051 ** An epheremal table will be created unless the selected columns are guaranteed
109052 ** to be unique - either because it is an INTEGER PRIMARY KEY or due to
109053 ** a UNIQUE constraint or index.
109054 **
109055 ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
109056 ** for fast set membership tests) then an epheremal table must
109057 ** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
109058 ** index can be found with the specified <columns> as its left-most.
109059 **
109060 ** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and
109061 ** if the RHS of the IN operator is a list (not a subquery) then this
@@ -109384,11 +109608,11 @@
109384 **
109385 ** x IN (4,5,11) -- IN operator with list on right-hand side
109386 ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
109387 **
109388 ** The pExpr parameter is the IN operator. The cursor number for the
109389 ** constructed ephermeral table is returned. The first time the ephemeral
109390 ** table is computed, the cursor number is also stored in pExpr->iTable,
109391 ** however the cursor number returned might not be the same, as it might
109392 ** have been duplicated using OP_OpenDup.
109393 **
109394 ** If the LHS expression ("x" in the examples) is a column value, or
@@ -110231,11 +110455,11 @@
110231 ExprClearProperty(p, EP_Skip);
110232 }
110233
110234 /*
110235 ** Evaluate an expression (either a vector or a scalar expression) and store
110236 ** the result in continguous temporary registers. Return the index of
110237 ** the first register used to store the result.
110238 **
110239 ** If the returned result register is a temporary scalar, then also write
110240 ** that register number into *piFreeable. If the returned result register
110241 ** is not a temporary or if the expression is a vector set *piFreeable
@@ -110271,11 +110495,11 @@
110271 ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5)
110272 ** so that a subsequent copy will not be merged into this one.
110273 */
110274 static void setDoNotMergeFlagOnCopy(Vdbe *v){
110275 if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){
110276 sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
110277 }
110278 }
110279
110280 /*
110281 ** Generate code to implement special SQL functions that are implemented
@@ -110361,17 +110585,17 @@
110361 target);
110362 break;
110363 }
110364
110365 case INLINEFUNC_implies_nonnull_row: {
110366 /* REsult of sqlite3ExprImpliesNonNullRow() */
110367 Expr *pA1;
110368 assert( nFarg==2 );
110369 pA1 = pFarg->a[1].pExpr;
110370 if( pA1->op==TK_COLUMN ){
110371 sqlite3VdbeAddOp2(v, OP_Integer,
110372 sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable),
110373 target);
110374 }else{
110375 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
110376 }
110377 break;
@@ -110543,11 +110767,11 @@
110543 int iTab = pExpr->iTable;
110544 int iReg;
110545 if( ExprHasProperty(pExpr, EP_FixedCol) ){
110546 /* This COLUMN expression is really a constant due to WHERE clause
110547 ** constraints, and that constant is coded by the pExpr->pLeft
110548 ** expresssion. However, make sure the constant has the correct
110549 ** datatype by applying the Affinity of the table column to the
110550 ** constant.
110551 */
110552 int aff;
110553 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
@@ -111272,11 +111496,11 @@
111272 ** once. If no functions are involved, then factor the code out and put it at
111273 ** the end of the prepared statement in the initialization section.
111274 **
111275 ** If regDest>=0 then the result is always stored in that register and the
111276 ** result is not reusable. If regDest<0 then this routine is free to
111277 ** store the value whereever it wants. The register where the expression
111278 ** is stored is returned. When regDest<0, two identical expressions might
111279 ** code to the same register, if they do not contain function calls and hence
111280 ** are factored out into the initialization section at the end of the
111281 ** prepared statement.
111282 */
@@ -112190,11 +112414,11 @@
112190 ** pE1: x>0 pE2: x==5 Result: false
112191 ** pE1: x=21 pE2: x=21 OR y=43 Result: true
112192 ** pE1: x!=123 pE2: x IS NOT NULL Result: true
112193 ** pE1: x!=?1 pE2: x IS NOT NULL Result: true
112194 ** pE1: x IS NULL pE2: x IS NOT NULL Result: false
112195 ** pE1: x IS ?2 pE2: x IS NOT NULL Reuslt: false
112196 **
112197 ** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has
112198 ** Expr.iTable<0 then assume a table number given by iTab.
112199 **
112200 ** If pParse is not NULL, then the values of bound variables in pE1 are
@@ -112226,68 +112450,108 @@
112226 ){
112227 return 1;
112228 }
112229 return 0;
112230 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112231
112232 /*
112233 ** This is the Expr node callback for sqlite3ExprImpliesNonNullRow().
112234 ** If the expression node requires that the table at pWalker->iCur
112235 ** have one or more non-NULL column, then set pWalker->eCode to 1 and abort.
 
 
 
 
112236 **
112237 ** This routine controls an optimization. False positives (setting
112238 ** pWalker->eCode to 1 when it should not be) are deadly, but false-negatives
112239 ** (never setting pWalker->eCode) is a harmless missed optimization.
112240 */
112241 static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
112242 testcase( pExpr->op==TK_AGG_COLUMN );
112243 testcase( pExpr->op==TK_AGG_FUNCTION );
112244 if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune;
 
 
 
 
 
 
 
 
112245 switch( pExpr->op ){
112246 case TK_ISNOT:
112247 case TK_ISNULL:
112248 case TK_NOTNULL:
112249 case TK_IS:
112250 case TK_OR:
112251 case TK_VECTOR:
112252 case TK_CASE:
112253 case TK_IN:
112254 case TK_FUNCTION:
112255 case TK_TRUTH:
 
112256 testcase( pExpr->op==TK_ISNOT );
112257 testcase( pExpr->op==TK_ISNULL );
112258 testcase( pExpr->op==TK_NOTNULL );
112259 testcase( pExpr->op==TK_IS );
112260 testcase( pExpr->op==TK_OR );
112261 testcase( pExpr->op==TK_VECTOR );
112262 testcase( pExpr->op==TK_CASE );
112263 testcase( pExpr->op==TK_IN );
112264 testcase( pExpr->op==TK_FUNCTION );
112265 testcase( pExpr->op==TK_TRUTH );
 
112266 return WRC_Prune;
 
112267 case TK_COLUMN:
112268 if( pWalker->u.iCur==pExpr->iTable ){
112269 pWalker->eCode = 1;
112270 return WRC_Abort;
112271 }
112272 return WRC_Prune;
112273
 
112274 case TK_AND:
112275 if( pWalker->eCode==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112276 sqlite3WalkExpr(pWalker, pExpr->pLeft);
112277 if( pWalker->eCode ){
112278 pWalker->eCode = 0;
112279 sqlite3WalkExpr(pWalker, pExpr->pRight);
112280 }
112281 }
112282 return WRC_Prune;
112283
112284 case TK_BETWEEN:
112285 if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
112286 assert( pWalker->eCode );
112287 return WRC_Abort;
112288 }
 
 
 
112289 return WRC_Prune;
112290
112291 /* Virtual tables are allowed to use constraints like x=NULL. So
112292 ** a term of the form x=y does not prove that y is not null if x
112293 ** is the column of a virtual table */
@@ -112345,26 +112609,27 @@
112345 ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
112346 ** clause requires that some column of the right table of the LEFT JOIN
112347 ** be non-NULL, then the LEFT JOIN can be safely converted into an
112348 ** ordinary join.
112349 */
112350 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
112351 Walker w;
112352 p = sqlite3ExprSkipCollateAndLikely(p);
112353 if( p==0 ) return 0;
112354 if( p->op==TK_NOTNULL ){
112355 p = p->pLeft;
112356 }else{
112357 while( p->op==TK_AND ){
112358 if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
112359 p = p->pRight;
112360 }
112361 }
112362 w.xExprCallback = impliesNotNullRow;
112363 w.xSelectCallback = 0;
112364 w.xSelectCallback2 = 0;
112365 w.eCode = 0;
 
112366 w.u.iCur = iTab;
112367 sqlite3WalkExpr(&w, p);
112368 return w.eCode;
112369 }
112370
@@ -112421,11 +112686,11 @@
112421 sqlite3WalkExpr(&w, pExpr);
112422 return !w.eCode;
112423 }
112424
112425
112426 /* Structure used to pass information throught the Walker in order to
112427 ** implement sqlite3ReferencesSrcList().
112428 */
112429 struct RefSrcList {
112430 sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */
112431 SrcList *pRef; /* Looking for references to these tables */
@@ -112637,11 +112902,11 @@
112637 /*
112638 ** Search the AggInfo object for an aCol[] entry that has iTable and iColumn.
112639 ** Return the index in aCol[] of the entry that describes that column.
112640 **
112641 ** If no prior entry is found, create a new one and return -1. The
112642 ** new column will have an idex of pAggInfo->nColumn-1.
112643 */
112644 static void findOrCreateAggInfoColumn(
112645 Parse *pParse, /* Parsing context */
112646 AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */
112647 Expr *pExpr /* Expr describing the column to find or insert */
@@ -112650,10 +112915,11 @@
112650 int k;
112651
112652 assert( pAggInfo->iFirstReg==0 );
112653 pCol = pAggInfo->aCol;
112654 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
 
112655 if( pCol->iTable==pExpr->iTable
112656 && pCol->iColumn==pExpr->iColumn
112657 && pExpr->op!=TK_IF_NULL_ROW
112658 ){
112659 goto fix_up_expr;
@@ -114035,11 +114301,11 @@
114035
114036 return pBest;
114037 }
114038
114039 /*
114040 ** An error occured while parsing or otherwise processing a database
114041 ** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an
114042 ** ALTER TABLE RENAME COLUMN program. The error message emitted by the
114043 ** sub-routine is currently stored in pParse->zErrMsg. This function
114044 ** adds context to the error message and then stores it in pCtx.
114045 */
@@ -117141,18 +117407,19 @@
117141 pSample = &pIdx->aSample[pIdx->nSample];
117142 decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0);
117143 decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0);
117144 decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0);
117145
117146 /* Take a copy of the sample. Add two 0x00 bytes the end of the buffer.
117147 ** This is in case the sample record is corrupted. In that case, the
117148 ** sqlite3VdbeRecordCompare() may read up to two varints past the
117149 ** end of the allocated buffer before it realizes it is dealing with
117150 ** a corrupt record. Adding the two 0x00 bytes prevents this from causing
 
117151 ** a buffer overread. */
117152 pSample->n = sqlite3_column_bytes(pStmt, 4);
117153 pSample->p = sqlite3DbMallocZero(db, pSample->n + 2);
117154 if( pSample->p==0 ){
117155 sqlite3_finalize(pStmt);
117156 return SQLITE_NOMEM_BKPT;
117157 }
117158 if( pSample->n ){
@@ -118106,11 +118373,11 @@
118106 const char *zArg3
118107 ){
118108 sqlite3 *db = pParse->db;
118109 int rc;
118110
118111 /* Don't do any authorization checks if the database is initialising
118112 ** or if the parser is being invoked from within sqlite3_declare_vtab.
118113 */
118114 assert( !IN_RENAME_OBJECT || db->xAuth==0 );
118115 if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){
118116 return SQLITE_OK;
@@ -118928,11 +119195,11 @@
118928 pCol->colFlags |= COLFLAG_HASCOLL;
118929 }
118930 }
118931
118932 /*
118933 ** Return the collating squence name for a column
118934 */
118935 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
118936 const char *z;
118937 if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
118938 z = pCol->zCnName;
@@ -119686,11 +119953,11 @@
119686 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
119687 return;
119688 }
119689 if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName);
119690
119691 /* Because keywords GENERATE ALWAYS can be converted into indentifiers
119692 ** by the parser, we can sometimes end up with a typename that ends
119693 ** with "generated always". Check for this case and omit the surplus
119694 ** text. */
119695 if( sType.n>=16
119696 && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
@@ -119907,11 +120174,11 @@
119907 */
119908 SQLITE_PRIVATE void sqlite3AddDefaultValue(
119909 Parse *pParse, /* Parsing context */
119910 Expr *pExpr, /* The parsed expression of the default value */
119911 const char *zStart, /* Start of the default value text */
119912 const char *zEnd /* First character past end of defaut value text */
119913 ){
119914 Table *p;
119915 Column *pCol;
119916 sqlite3 *db = pParse->db;
119917 p = pParse->pNewTable;
@@ -120255,11 +120522,11 @@
120255 ** which to write into the output buffer. This function copies the
120256 ** nul-terminated string pointed to by the third parameter, zSignedIdent,
120257 ** to the specified offset in the buffer and updates *pIdx to refer
120258 ** to the first byte after the last byte written before returning.
120259 **
120260 ** If the string zSignedIdent consists entirely of alpha-numeric
120261 ** characters, does not begin with a digit and is not an SQL keyword,
120262 ** then it is copied to the output buffer exactly as it is. Otherwise,
120263 ** it is quoted using double-quotes.
120264 */
120265 static void identPut(char *z, int *pIdx, char *zSignedIdent){
@@ -120407,11 +120674,11 @@
120407 int i;
120408 const Column *aCol = pIdx->pTable->aCol;
120409 for(i=0; i<pIdx->nColumn; i++){
120410 i16 x = pIdx->aiColumn[i];
120411 assert( x<pIdx->pTable->nCol );
120412 wIndex += x<0 ? 1 : aCol[pIdx->aiColumn[i]].szEst;
120413 }
120414 pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
120415 }
120416
120417 /* Return true if column number x is any of the first nCol entries of aiCol[].
@@ -122145,11 +122412,11 @@
122145 assert( pName && pName->z );
122146
122147 #ifndef SQLITE_OMIT_TEMPDB
122148 /* If the index name was unqualified, check if the table
122149 ** is a temp table. If so, set the database to 1. Do not do this
122150 ** if initialising a database schema.
122151 */
122152 if( !db->init.busy ){
122153 pTab = sqlite3SrcListLookup(pParse, pTblName);
122154 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
122155 iDb = 1;
@@ -123802,11 +124069,11 @@
123802 sqlite3DbFree(db, pCte);
123803 }
123804
123805 /*
123806 ** This routine is invoked once per CTE by the parser while parsing a
123807 ** WITH clause. The CTE described by teh third argument is added to
123808 ** the WITH clause of the second argument. If the second argument is
123809 ** NULL, then a new WITH argument is created.
123810 */
123811 SQLITE_PRIVATE With *sqlite3WithAdd(
123812 Parse *pParse, /* Parsing context */
@@ -124446,10 +124713,11 @@
124446 Table *pTab;
124447 assert( pItem && pSrc->nSrc>=1 );
124448 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
124449 sqlite3DeleteTable(pParse->db, pItem->pTab);
124450 pItem->pTab = pTab;
 
124451 if( pTab ){
124452 pTab->nTabRef++;
124453 if( pItem->fg.isIndexedBy && sqlite3IndexedByLookup(pParse, pItem) ){
124454 pTab = 0;
124455 }
@@ -124598,11 +124866,11 @@
124598 char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
124599 ){
124600 sqlite3 *db = pParse->db;
124601 Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */
124602 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
124603 ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */
124604 SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */
124605 Select *pSelect = NULL; /* Complete SELECT tree */
124606 Table *pTab;
124607
124608 /* Check that there isn't an ORDER BY without a LIMIT clause.
@@ -124636,18 +124904,24 @@
124636 pEList = sqlite3ExprListAppend(
124637 pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
124638 );
124639 }else{
124640 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
 
 
124641 if( pPk->nKeyCol==1 ){
124642 const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
 
 
124643 pLhs = sqlite3Expr(db, TK_ID, zName);
124644 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
124645 }else{
124646 int i;
124647 for(i=0; i<pPk->nKeyCol; i++){
124648 Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName);
 
 
124649 pEList = sqlite3ExprListAppend(pParse, pEList, p);
124650 }
124651 pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
124652 if( pLhs ){
124653 pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
@@ -124672,11 +124946,11 @@
124672 /* generate the SELECT expression tree. */
124673 pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
124674 pOrderBy,0,pLimit
124675 );
124676
124677 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
124678 pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
124679 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
124680 return pInClause;
124681 }
124682 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */
@@ -126057,11 +126331,11 @@
126057 u8 noCase; /* true to ignore case differences */
126058 };
126059
126060 /*
126061 ** For LIKE and GLOB matching on EBCDIC machines, assume that every
126062 ** character is exactly one byte in size. Also, provde the Utf8Read()
126063 ** macro for fast reading of the next character in the common case where
126064 ** the next character is ASCII.
126065 */
126066 #if defined(SQLITE_EBCDIC)
126067 # define sqlite3Utf8Read(A) (*((*A)++))
@@ -126290,11 +126564,11 @@
126290 #endif
126291
126292
126293 /*
126294 ** Implementation of the like() SQL function. This function implements
126295 ** the build-in LIKE operator. The first argument to the function is the
126296 ** pattern and the second argument is the string. So, the SQL statements:
126297 **
126298 ** A LIKE B
126299 **
126300 ** is implemented as like(B,A).
@@ -126676,11 +126950,11 @@
126676 ** two arguments. In both cases the first argument is interpreted as text
126677 ** a text value containing a set of pairs of hexadecimal digits which are
126678 ** decoded and returned as a blob.
126679 **
126680 ** If there is only a single argument, then it must consist only of an
126681 ** even number of hexadeximal digits. Otherwise, return NULL.
126682 **
126683 ** Or, if there is a second argument, then any character that appears in
126684 ** the second argument is also allowed to appear between pairs of hexadecimal
126685 ** digits in the first argument. If any other character appears in the
126686 ** first argument, or if one of the allowed characters appears between
@@ -127376,11 +127650,11 @@
127376 assert( argc==1 || argc==2 );
127377 (void)argc; /* Suppress unused parameter warning */
127378 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
127379 pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
127380 /* pGCC is always non-NULL since groupConcatStep() will have always
127381 ** run frist to initialize it */
127382 if( ALWAYS(pGCC) ){
127383 int nVS;
127384 /* Must call sqlite3_value_text() to convert the argument into text prior
127385 ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
127386 (void)sqlite3_value_text(argv[0]);
@@ -129579,11 +129853,11 @@
129579 ** 'E' REAL
129580 **
129581 ** For STRICT tables:
129582 ** ------------------
129583 **
129584 ** Generate an appropropriate OP_TypeCheck opcode that will verify the
129585 ** datatypes against the column definitions in pTab. If iReg==0, that
129586 ** means an OP_MakeRecord opcode has already been generated and should be
129587 ** the last opcode generated. The new OP_TypeCheck needs to be inserted
129588 ** before the OP_MakeRecord. The new OP_TypeCheck should use the same
129589 ** register set as the OP_MakeRecord. If iReg>0 then register iReg is
@@ -130871,11 +131145,11 @@
130871 #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */
130872
130873 /* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn().
130874 * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this
130875 ** expression node references any of the
130876 ** columns that are being modifed by an UPDATE statement.
130877 */
130878 static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){
130879 if( pExpr->op==TK_COLUMN ){
130880 assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 );
130881 if( pExpr->iColumn>=0 ){
@@ -131094,11 +131368,11 @@
131094 int ignoreDest, /* Jump to this label on an OE_Ignore resolution */
131095 int *pbMayReplace, /* OUT: Set to true if constraint may cause a replace */
131096 int *aiChng, /* column i is unchanged if aiChng[i]<0 */
131097 Upsert *pUpsert /* ON CONFLICT clauses, if any. NULL otherwise */
131098 ){
131099 Vdbe *v; /* VDBE under constrution */
131100 Index *pIdx; /* Pointer to one of the indices */
131101 Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */
131102 sqlite3 *db; /* Database connection */
131103 int i; /* loop counter */
131104 int ix; /* Index loop counter */
@@ -131577,11 +131851,11 @@
131577 */
131578 for(pIdx = indexIteratorFirst(&sIdxIter, &ix);
131579 pIdx;
131580 pIdx = indexIteratorNext(&sIdxIter, &ix)
131581 ){
131582 int regIdx; /* Range of registers hold conent for pIdx */
131583 int regR; /* Range of registers holding conflicting PK */
131584 int iThisCur; /* Cursor for this UNIQUE index */
131585 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
131586 int addrConflictCk; /* First opcode in the conflict check logic */
131587
@@ -132393,11 +132667,11 @@
132393 if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
132394 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
132395 }
132396 #endif
132397 #ifndef SQLITE_OMIT_FOREIGN_KEY
132398 /* Disallow the transfer optimization if the destination table constains
132399 ** any foreign key constraints. This is more restrictive than necessary.
132400 ** But the main beneficiary of the transfer optimization is the VACUUM
132401 ** command, and the VACUUM command disables foreign key constraints. So
132402 ** the extra complication to make this rule less restrictive is probably
132403 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
@@ -134026,10 +134300,14 @@
134026 **
134027 ** Later (2023-03-25): Save an extra 6 bytes for the filename suffix.
134028 ** See https://sqlite.org/forum/forumpost/24083b579d.
134029 */
134030 if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found;
 
 
 
 
134031
134032 handle = sqlite3OsDlOpen(pVfs, zFile);
134033 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
134034 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
134035 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
@@ -135859,11 +136137,11 @@
135859 ** PRAGMA cache_spill=BOOLEAN
135860 ** PRAGMA [schema.]cache_spill=N
135861 **
135862 ** The first form reports the current local setting for the
135863 ** page cache spill size. The second form turns cache spill on
135864 ** or off. When turnning cache spill on, the size is set to the
135865 ** current cache_size. The third form sets a spill size that
135866 ** may be different form the cache size.
135867 ** If N is positive then that is the
135868 ** number of pages in the cache. If N is negative, then the
135869 ** number of pages is adjusted so that the cache uses -N kibibytes
@@ -136637,13 +136915,13 @@
136637 ** Verify the integrity of the database.
136638 **
136639 ** The "quick_check" is reduced version of
136640 ** integrity_check designed to detect most database corruption
136641 ** without the overhead of cross-checking indexes. Quick_check
136642 ** is linear time wherease integrity_check is O(NlogN).
136643 **
136644 ** The maximum nubmer of errors is 100 by default. A different default
136645 ** can be specified using a numeric parameter N.
136646 **
136647 ** Or, the parameter N can be the name of a table. In that case, only
136648 ** the one table named is verified. The freelist is only verified if
136649 ** the named table is "sqlite_schema" (or one of its aliases).
@@ -137397,11 +137675,11 @@
137397 int iTabCur; /* Cursor for a table whose size needs checking */
137398 HashElem *k; /* Loop over tables of a schema */
137399 Schema *pSchema; /* The current schema */
137400 Table *pTab; /* A table in the schema */
137401 Index *pIdx; /* An index of the table */
137402 LogEst szThreshold; /* Size threshold above which reanalysis is needd */
137403 char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
137404 u32 opMask; /* Mask of operations to perform */
137405
137406 if( zRight ){
137407 opMask = (u32)sqlite3Atoi(zRight);
@@ -138523,11 +138801,11 @@
138523 ** Add a new cleanup operation to a Parser. The cleanup should happen when
138524 ** the parser object is destroyed. But, beware: the cleanup might happen
138525 ** immediately.
138526 **
138527 ** Use this mechanism for uncommon cleanups. There is a higher setup
138528 ** cost for this mechansim (an extra malloc), so it should not be used
138529 ** for common cleanups that happen on most calls. But for less
138530 ** common cleanups, we save a single NULL-pointer comparison in
138531 ** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
138532 **
138533 ** If a memory allocation error occurs, then the cleanup happens immediately.
@@ -139225,11 +139503,11 @@
139225 ** NATURAL RIGHT OUTER JT_NATURAL|JT_RIGHT|JT_OUTER
139226 ** NATURAL FULL - JT_NATURAL|JT_LEFT|JT_RIGHT
139227 ** NATURAL FULL OUTER JT_NATRUAL|JT_LEFT|JT_RIGHT
139228 **
139229 ** To preserve historical compatibly, SQLite also accepts a variety
139230 ** of other non-standard and in many cases non-sensical join types.
139231 ** This routine makes as much sense at it can from the nonsense join
139232 ** type and returns a result. Examples of accepted nonsense join types
139233 ** include but are not limited to:
139234 **
139235 ** INNER CROSS JOIN -> same as JOIN
@@ -139496,11 +139774,11 @@
139496 u32 joinType;
139497
139498 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
139499 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
139500
139501 /* If this is a NATURAL join, synthesize an approprate USING clause
139502 ** to specify which columns should be joined.
139503 */
139504 if( pRight->fg.jointype & JT_NATURAL ){
139505 IdList *pUsing = 0;
139506 if( pRight->fg.isUsing || pRight->u3.pOn ){
@@ -139712,11 +139990,11 @@
139712 ** (2) All output columns are included in the sort record. In that
139713 ** case regData==regOrigData.
139714 ** (3) Some output columns are omitted from the sort record due to
139715 ** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the
139716 ** SQLITE_ECEL_OMITREF optimization, or due to the
139717 ** SortCtx.pDeferredRowLoad optimiation. In any of these cases
139718 ** regOrigData is 0 to prevent this routine from trying to copy
139719 ** values that might not yet exist.
139720 */
139721 assert( nData==1 || regData==regOrigData || regOrigData==0 );
139722
@@ -139768,11 +140046,11 @@
139768 memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
139769 sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
139770 testcase( pKI->nAllField > pKI->nKeyField+2 );
139771 pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
139772 pKI->nAllField-pKI->nKeyField-1);
139773 pOp = 0; /* Ensure pOp not used after sqltie3VdbeAddOp3() */
139774 addrJmp = sqlite3VdbeCurrentAddr(v);
139775 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
139776 pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
139777 pSort->regReturn = ++pParse->nMem;
139778 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
@@ -139862,11 +140140,11 @@
139862 ** the ephemeral cursor and proceed.
139863 **
139864 ** The returned value in this case is a copy of parameter iTab.
139865 **
139866 ** WHERE_DISTINCT_ORDERED:
139867 ** In this case rows are being delivered sorted order. The ephermal
139868 ** table is not required. Instead, the current set of values
139869 ** is compared against previous row. If they match, the new row
139870 ** is not distinct and control jumps to VM address addrRepeat. Otherwise,
139871 ** the VM program proceeds with processing the new row.
139872 **
@@ -141287,11 +141565,11 @@
141287 /*
141288 ** pTab is a transient Table object that represents a subquery of some
141289 ** kind (maybe a parenthesized subquery in the FROM clause of a larger
141290 ** query, or a VIEW, or a CTE). This routine computes type information
141291 ** for that Table object based on the Select object that implements the
141292 ** subquery. For the purposes of this routine, "type infomation" means:
141293 **
141294 ** * The datatype name, as it might appear in a CREATE TABLE statement
141295 ** * Which collating sequence to use for the column
141296 ** * The affinity of the column
141297 */
@@ -141616,11 +141894,11 @@
141616 int iCurrent = 0; /* The Current table */
141617 int regCurrent; /* Register holding Current table */
141618 int iQueue; /* The Queue table */
141619 int iDistinct = 0; /* To ensure unique results if UNION */
141620 int eDest = SRT_Fifo; /* How to write to Queue */
141621 SelectDest destQueue; /* SelectDest targetting the Queue table */
141622 int i; /* Loop counter */
141623 int rc; /* Result code */
141624 ExprList *pOrderBy; /* The ORDER BY clause */
141625 Expr *pLimit; /* Saved LIMIT and OFFSET */
141626 int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
@@ -142216,11 +142494,11 @@
142216 }
142217 }
142218
142219 /*
142220 ** Code an output subroutine for a coroutine implementation of a
142221 ** SELECT statment.
142222 **
142223 ** The data to be output is contained in pIn->iSdst. There are
142224 ** pIn->nSdst columns to be output. pDest is where the output should
142225 ** be sent.
142226 **
@@ -142438,11 +142716,11 @@
142438 ** Jump AltB, AeqB, AgtB
142439 ** End: ...
142440 **
142441 ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
142442 ** actually called using Gosub and they do not Return. EofA and EofB loop
142443 ** until all data is exhausted then jump to the "end" labe. AltB, AeqB,
142444 ** and AgtB jump to either L2 or to one of EofA or EofB.
142445 */
142446 #ifndef SQLITE_OMIT_COMPOUND_SELECT
142447 static int multiSelectOrderBy(
142448 Parse *pParse, /* Parsing context */
@@ -142475,11 +142753,11 @@
142475 int regPrev; /* A range of registers to hold previous output */
142476 int savedLimit; /* Saved value of p->iLimit */
142477 int savedOffset; /* Saved value of p->iOffset */
142478 int labelCmpr; /* Label for the start of the merge algorithm */
142479 int labelEnd; /* Label for the end of the overall SELECT stmt */
142480 int addr1; /* Jump instructions that get retargetted */
142481 int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
142482 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
142483 KeyInfo *pKeyMerge; /* Comparison information for merging rows */
142484 sqlite3 *db; /* Database connection */
142485 ExprList *pOrderBy; /* The ORDER BY clause */
@@ -142844,15 +143122,18 @@
142844 pExpr->op = TK_NULL;
142845 }else
142846 #endif
142847 {
142848 Expr *pNew;
142849 int iColumn = pExpr->iColumn;
142850 Expr *pCopy = pSubst->pEList->a[iColumn].pExpr;
142851 Expr ifNullRow;
 
 
142852 assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr );
142853 assert( pExpr->pRight==0 );
 
142854 if( sqlite3ExprIsVector(pCopy) ){
142855 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
142856 }else{
142857 sqlite3 *db = pSubst->pParse->db;
142858 if( pSubst->isOuterJoin
@@ -143197,11 +143478,11 @@
143197 ** (8) If the subquery uses LIMIT then the outer query may not be a join.
143198 **
143199 ** (9) If the subquery uses LIMIT then the outer query may not be aggregate.
143200 **
143201 ** (**) Restriction (10) was removed from the code on 2005-02-05 but we
143202 ** accidently carried the comment forward until 2014-09-15. Original
143203 ** constraint: "If the subquery is aggregate then the outer query
143204 ** may not use LIMIT."
143205 **
143206 ** (11) The subquery and the outer query may not both have ORDER BY clauses.
143207 **
@@ -143471,11 +143752,11 @@
143471 pParse->zAuthContext = pSubitem->zName;
143472 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
143473 testcase( i==SQLITE_DENY );
143474 pParse->zAuthContext = zSavedAuthContext;
143475
143476 /* Delete the transient structures associated with thesubquery */
143477 pSub1 = pSubitem->pSelect;
143478 sqlite3DbFree(db, pSubitem->zDatabase);
143479 sqlite3DbFree(db, pSubitem->zName);
143480 sqlite3DbFree(db, pSubitem->zAlias);
143481 pSubitem->zDatabase = 0;
@@ -143653,11 +143934,11 @@
143653 if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
143654 /* At this point, any non-zero iOrderByCol values indicate that the
143655 ** ORDER BY column expression is identical to the iOrderByCol'th
143656 ** expression returned by SELECT statement pSub. Since these values
143657 ** do not necessarily correspond to columns in SELECT statement pParent,
143658 ** zero them before transfering the ORDER BY clause.
143659 **
143660 ** Not doing this may cause an error if a subsequent call to this
143661 ** function attempts to flatten a compound sub-query into pParent
143662 ** (the only way this can happen is if the compound sub-query is
143663 ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */
@@ -143713,12 +143994,11 @@
143713 for(i=0; i<nSubSrc; i++){
143714 recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]);
143715 }
143716 }
143717
143718 /* Finially, delete what is left of the subquery and return
143719 ** success.
143720 */
143721 sqlite3AggInfoPersistWalkerInit(&w, pParse);
143722 sqlite3WalkSelect(&w,pSub1);
143723 sqlite3SelectDelete(db, pSub1);
143724
@@ -143749,11 +144029,11 @@
143749 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
143750 };
143751
143752 /*
143753 ** Add a new entry to the pConst object. Except, do not add duplicate
143754 ** pColumn entires. Also, do not add if doing so would not be appropriate.
143755 **
143756 ** The caller guarantees the pColumn is a column and pValue is a constant.
143757 ** This routine has to do some additional checks before completing the
143758 ** insert.
143759 */
@@ -143935,11 +144215,11 @@
143935 ** INSERT INTO t1 VALUES(123,'0123');
143936 ** SELECT * FROM t1 WHERE a=123 AND b=a;
143937 ** SELECT * FROM t1 WHERE a=123 AND b=123;
143938 **
143939 ** The two SELECT statements above should return different answers. b=a
143940 ** is alway true because the comparison uses numeric affinity, but b=123
143941 ** is false because it uses text affinity and '0123' is not the same as '123'.
143942 ** To work around this, the expression tree is not actually changed from
143943 ** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol
143944 ** and the "123" value is hung off of the pLeft pointer. Code generator
143945 ** routines know to generate the constant "123" instead of looking up the
@@ -144019,11 +144299,11 @@
144019 ** this may change the results of the window functions.
144020 **
144021 ** At the time this function is called it is guaranteed that
144022 **
144023 ** * the sub-query uses only one distinct window frame, and
144024 ** * that the window frame has a PARTITION BY clase.
144025 */
144026 static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){
144027 assert( pSubq->pWin->pPartition );
144028 assert( (pSubq->selFlags & SF_MultiPart)==0 );
144029 assert( pSubq->pPrior==0 );
@@ -145527,11 +145807,11 @@
145527 assert( pExpr->iAgg>=0 );
145528 pCol = &pAggInfo->aCol[pExpr->iAgg];
145529 pExpr->op = TK_AGG_COLUMN;
145530 pExpr->iTable = pCol->iTable;
145531 pExpr->iColumn = pCol->iColumn;
145532 ExprClearProperty(pExpr, EP_Skip|EP_Collate);
145533 return WRC_Prune;
145534 }
145535
145536 /*
145537 ** Convert every pAggInfo->aFunc[].pExpr such that any node within
@@ -145558,11 +145838,11 @@
145558 ** to calling this routine:
145559 **
145560 ** * The aCol[] and aFunc[] arrays may be modified
145561 ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used
145562 **
145563 ** After clling this routine:
145564 **
145565 ** * The aCol[] and aFunc[] arrays are fixed
145566 ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may be used
145567 **
145568 */
@@ -146212,26 +146492,63 @@
146212 /* The expander should have already created transient Table objects
146213 ** even for FROM clause elements such as subqueries that do not correspond
146214 ** to a real table */
146215 assert( pTab!=0 );
146216
146217 /* Convert LEFT JOIN into JOIN if there are terms of the right table
146218 ** of the LEFT JOIN used in the WHERE clause.
 
 
 
 
 
 
 
 
146219 */
146220 if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==JT_LEFT
146221 && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor)
 
146222 && OptimizationEnabled(db, SQLITE_SimplifyJoin)
146223 ){
146224 TREETRACE(0x1000,pParse,p,
146225 ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
146226 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146227 assert( pItem->iCursor>=0 );
146228 unsetJoinExpr(p->pWhere, pItem->iCursor,
146229 pTabList->a[0].fg.jointype & JT_LTORJ);
146230 }
146231
146232 /* No futher action if this term of the FROM clause is not a subquery */
146233 if( pSub==0 ) continue;
146234
146235 /* Catch mismatch in the declared columns of a view and the number of
146236 ** columns in the SELECT on the RHS */
146237 if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -146481,11 +146798,11 @@
146481 sqlite3VdbeJumpHere(v, addrTop-1);
146482 sqlite3ClearTempRegCache(pParse);
146483 }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){
146484 /* This is a CTE for which materialization code has already been
146485 ** generated. Invoke the subroutine to compute the materialization,
146486 ** the make the pItem->iCursor be a copy of the ephemerial table that
146487 ** holds the result of the materialization. */
146488 CteUse *pCteUse = pItem->u2.pCteUse;
146489 sqlite3VdbeAddOp2(v, OP_Gosub, pCteUse->regRtn, pCteUse->addrM9e);
146490 if( pItem->iCursor!=pCteUse->iCur ){
146491 sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur);
@@ -146864,11 +147181,11 @@
146864 /* Processing for aggregates with GROUP BY is very different and
146865 ** much more complex than aggregates without a GROUP BY.
146866 */
146867 if( pGroupBy ){
146868 KeyInfo *pKeyInfo; /* Keying information for the group by clause */
146869 int addr1; /* A-vs-B comparision jump */
146870 int addrOutputRow; /* Start of subroutine that outputs a result row */
146871 int regOutputRow; /* Return address register for output subroutine */
146872 int addrSetAbort; /* Set the abort flag and return */
146873 int addrTopOfLoop; /* Top of the input loop */
146874 int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
@@ -149244,11 +149561,11 @@
149244 pSrc = sqlite3SrcListDup(db, pTabList, 0);
149245 pWhere2 = sqlite3ExprDup(db, pWhere, 0);
149246
149247 assert( pTabList->nSrc>1 );
149248 if( pSrc ){
149249 pSrc->a[0].fg.notCte = 1;
149250 pSrc->a[0].iCursor = -1;
149251 pSrc->a[0].pTab->nTabRef--;
149252 pSrc->a[0].pTab = 0;
149253 }
149254 if( pPk ){
@@ -150231,11 +150548,11 @@
150231 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
150232 WhereInfo *pWInfo = 0;
150233 int nArg = 2 + pTab->nCol; /* Number of arguments to VUpdate */
150234 int regArg; /* First register in VUpdate arg array */
150235 int regRec; /* Register in which to assemble record */
150236 int regRowid; /* Register for ephem table rowid */
150237 int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */
150238 int aDummy[2]; /* Unused arg for sqlite3WhereOkOnePass() */
150239 int eOnePass; /* True to use onepass strategy */
150240 int addr; /* Address of OP_OpenEphemeral */
150241
@@ -150352,11 +150669,11 @@
150352 /* End the virtual table scan */
150353 if( pSrc->nSrc==1 ){
150354 sqlite3WhereEnd(pWInfo);
150355 }
150356
150357 /* Begin scannning through the ephemeral table. */
150358 addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v);
150359
150360 /* Extract arguments from the current row of the ephemeral table and
150361 ** invoke the VUpdate method. */
150362 for(i=0; i<nArg; i++){
@@ -150909,11 +151226,11 @@
150909 ** can be set to 'off' for this file, as it is not recovered if a crash
150910 ** occurs anyway. The integrity of the database is maintained by a
150911 ** (possibly synchronous) transaction opened on the main database before
150912 ** sqlite3BtreeCopyFile() is called.
150913 **
150914 ** An optimisation would be to use a non-journaled pager.
150915 ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but
150916 ** that actually made the VACUUM run slower. Very little journalling
150917 ** actually occurs when doing a vacuum since the vacuum_db is initially
150918 ** empty. Only the journal header is written. Apparently it takes more
150919 ** time to parse and run the PRAGMA to turn journalling off than it does
@@ -151598,11 +151915,11 @@
151598 /* A slot for the record has already been allocated in the
151599 ** schema table. We just need to update that slot with all
151600 ** the information we've collected.
151601 **
151602 ** The VM register number pParse->regRowid holds the rowid of an
151603 ** entry in the sqlite_schema table tht was created for this vtab
151604 ** by sqlite3StartTable().
151605 */
151606 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
151607 sqlite3NestedParse(pParse,
151608 "UPDATE %Q." LEGACY_SCHEMA_TABLE " "
@@ -152342,11 +152659,11 @@
152342 ** exists when this routine returns or if an attempt to create it failed
152343 ** and an error message was left in pParse.
152344 **
152345 ** An eponymous virtual table instance is one that is named after its
152346 ** module, and more importantly, does not require a CREATE VIRTUAL TABLE
152347 ** statement in order to come into existance. Eponymous virtual table
152348 ** instances always exist. They cannot be DROP-ed.
152349 **
152350 ** Any virtual table module for which xConnect and xCreate are the same
152351 ** method can have an eponymous virtual table instance.
152352 */
@@ -152533,11 +152850,11 @@
152533 typedef struct WhereMemBlock WhereMemBlock;
152534 typedef struct WhereRightJoin WhereRightJoin;
152535
152536 /*
152537 ** This object is a header on a block of allocated memory that will be
152538 ** automatically freed when its WInfo oject is destructed.
152539 */
152540 struct WhereMemBlock {
152541 WhereMemBlock *pNext; /* Next block in the chain */
152542 u64 sz; /* Bytes of space */
152543 };
@@ -152594,11 +152911,11 @@
152594 int nIn; /* Number of entries in aInLoop[] */
152595 struct InLoop {
152596 int iCur; /* The VDBE cursor used by this IN operator */
152597 int addrInTop; /* Top of the IN loop */
152598 int iBase; /* Base register of multi-key index record */
152599 int nPrefix; /* Number of prior entires in the key */
152600 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
152601 } *aInLoop; /* Information about each nested IN operator */
152602 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
152603 Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */
152604 } u;
@@ -152844,11 +153161,11 @@
152844 u8 op; /* Split operator. TK_AND or TK_OR */
152845 u8 hasOr; /* True if any a[].eOperator is WO_OR */
152846 int nTerm; /* Number of terms */
152847 int nSlot; /* Number of entries in a[] */
152848 int nBase; /* Number of terms through the last non-Virtual */
152849 WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */
152850 #if defined(SQLITE_SMALL_STACK)
152851 WhereTerm aStatic[1]; /* Initial static space for a[] */
152852 #else
152853 WhereTerm aStatic[8]; /* Initial static space for a[] */
152854 #endif
@@ -153929,11 +154246,11 @@
153929 assert( pIdx!=0 );
153930
153931 /* Figure out how many memory cells we will need then allocate them.
153932 */
153933 regBase = pParse->nMem + 1;
153934 nReg = pLoop->u.btree.nEq + nExtraReg;
153935 pParse->nMem += nReg;
153936
153937 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
153938 assert( zAff!=0 || pParse->db->mallocFailed );
153939
@@ -153976,13 +154293,10 @@
153976 regBase = r1;
153977 }else{
153978 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
153979 }
153980 }
153981 }
153982 for(j=nSkip; j<nEq; j++){
153983 pTerm = pLoop->aLTerm[j];
153984 if( pTerm->eOperator & WO_IN ){
153985 if( pTerm->pExpr->flags & EP_xIsSelect ){
153986 /* No affinity ever needs to be (or should be) applied to a value
153987 ** from the RHS of an "? IN (SELECT ...)" expression. The
153988 ** sqlite3FindInIndex() routine has already ensured that the
@@ -154121,11 +154435,11 @@
154121 ** the specified column into the new register, and
154122 **
154123 ** 2) transform the expression node to a TK_REGISTER node that reads
154124 ** from the newly populated register.
154125 **
154126 ** Also, if the node is a TK_COLUMN that does access the table idenified
154127 ** by pCCurHint.iTabCur, and an index is being used (which we will
154128 ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into
154129 ** an access of the index rather than the original table.
154130 */
154131 static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){
@@ -154739,11 +155053,11 @@
154739 /* TK_LT */ OP_SeekLT,
154740 /* TK_GE */ OP_SeekGE
154741 };
154742 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
154743 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
154744 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
154745
154746 assert( (pStart->wtFlags & TERM_VNULL)==0 );
154747 testcase( pStart->wtFlags & TERM_VIRTUAL );
154748 pX = pStart->pExpr;
154749 assert( pX!=0 );
@@ -155919,11 +156233,11 @@
155919 *************************************************************************
155920 ** This module contains C code that generates VDBE code used to process
155921 ** the WHERE clause of SQL statements.
155922 **
155923 ** This file was originally part of where.c but was split out to improve
155924 ** readability and editabiliity. This file contains utility routines for
155925 ** analyzing Expr objects in the WHERE clause.
155926 */
155927 /* #include "sqliteInt.h" */
155928 /* #include "whereInt.h" */
155929
@@ -156708,11 +157022,11 @@
156708 }
156709 if( (chngToIN & sqlite3WhereGetMask(&pWInfo->sMaskSet,
156710 pOrTerm->leftCursor))==0 ){
156711 /* This term must be of the form t1.a==t2.b where t2 is in the
156712 ** chngToIN set but t1 is not. This term will be either preceded
156713 ** or follwed by an inverted copy (t2.b==t1.a). Skip this term
156714 ** and use its inversion. */
156715 testcase( pOrTerm->wtFlags & TERM_COPIED );
156716 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
156717 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
156718 continue;
@@ -156970,12 +157284,12 @@
156970 ){
156971 WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */
156972 WhereTerm *pTerm; /* The term to be analyzed */
156973 WhereMaskSet *pMaskSet; /* Set of table index masks */
156974 Expr *pExpr; /* The expression to be analyzed */
156975 Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
156976 Bitmask prereqAll; /* Prerequesites of pExpr */
156977 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
156978 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
156979 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
156980 int noCase = 0; /* uppercase equivalent to lowercase */
156981 int op; /* Top-level operator. pExpr->op */
@@ -159532,11 +159846,11 @@
159532 ** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?;
159533 **
159534 ** Value pLoop->nOut is currently set to the estimated number of rows
159535 ** visited for scanning (a=? AND b=?). This function reduces that estimate
159536 ** by some factor to account for the (c BETWEEN ? AND ?) expression based
159537 ** on the stat4 data for the index. this scan will be peformed multiple
159538 ** times (once for each (a,b) combination that matches a=?) is dealt with
159539 ** by the caller.
159540 **
159541 ** It does this by scanning through all stat4 samples, comparing values
159542 ** extracted from pLower and pUpper with the corresponding column in each
@@ -160287,11 +160601,11 @@
160287 /* whereLoopAddBtree() always generates and inserts the automatic index
160288 ** case first. Hence compatible candidate WhereLoops never have a larger
160289 ** rSetup. Call this SETUP-INVARIANT */
160290 assert( p->rSetup>=pTemplate->rSetup );
160291
160292 /* Any loop using an appliation-defined index (or PRIMARY KEY or
160293 ** UNIQUE constraint) with one or more == constraints is better
160294 ** than an automatic index. Unless it is a skip-scan. */
160295 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
160296 && (pTemplate->nSkip)==0
160297 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
@@ -160432,11 +160746,11 @@
160432 whereLoopInit(p);
160433 p->pNextLoop = 0;
160434 }else{
160435 /* We will be overwriting WhereLoop p[]. But before we do, first
160436 ** go through the rest of the list and delete any other entries besides
160437 ** p[] that are also supplated by pTemplate */
160438 WhereLoop **ppTail = &p->pNextLoop;
160439 WhereLoop *pToDel;
160440 while( *ppTail ){
160441 ppTail = whereLoopFindLesser(ppTail, pTemplate);
160442 if( ppTail==0 ) break;
@@ -160632,11 +160946,11 @@
160632 }
160633 return i;
160634 }
160635
160636 /*
160637 ** Adjust the cost C by the costMult facter T. This only occurs if
160638 ** compiled with -DSQLITE_ENABLE_COSTMULT
160639 */
160640 #ifdef SQLITE_ENABLE_COSTMULT
160641 # define ApplyCostMultiplier(C,T) C += T
160642 #else
@@ -160659,11 +160973,11 @@
160659 WhereLoopBuilder *pBuilder, /* The WhereLoop factory */
160660 SrcItem *pSrc, /* FROM clause term being analyzed */
160661 Index *pProbe, /* An index on pSrc */
160662 LogEst nInMul /* log(Number of iterations due to IN) */
160663 ){
160664 WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */
160665 Parse *pParse = pWInfo->pParse; /* Parsing context */
160666 sqlite3 *db = pParse->db; /* Database connection malloc context */
160667 WhereLoop *pNew; /* Template WhereLoop under construction */
160668 WhereTerm *pTerm; /* A WhereTerm under consideration */
160669 int opMask; /* Valid operators for constraints */
@@ -160969,11 +161283,11 @@
160969 ** seek only. Then, if this is a non-covering index, add the cost of
160970 ** visiting the rows in the main table. */
160971 assert( pSrc->pTab->szTabRow>0 );
160972 if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){
160973 /* The pProbe->szIdxRow is low for an IPK table since the interior
160974 ** pages are small. Thuse szIdxRow gives a good estimate of seek cost.
160975 ** But the leaf pages are full-size, so pProbe->szIdxRow would badly
160976 ** under-estimate the scanning cost. */
160977 rCostIdx = pNew->nOut + 16;
160978 }else{
160979 rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
@@ -161314,11 +161628,11 @@
161314 ** performance of using an index is far better than the worst-case performance
161315 ** of a full table scan.
161316 */
161317 static int whereLoopAddBtree(
161318 WhereLoopBuilder *pBuilder, /* WHERE clause information */
161319 Bitmask mPrereq /* Extra prerequesites for using this table */
161320 ){
161321 WhereInfo *pWInfo; /* WHERE analysis context */
161322 Index *pProbe; /* An index we are evaluating */
161323 Index sPk; /* A fake index object for the primary key */
161324 LogEst aiRowEstPk[2]; /* The aiRowLogEst[] value for the sPk index */
@@ -161821,11 +162135,11 @@
161821 ** This routine depends on there being a HiddenIndexInfo structure immediately
161822 ** following the sqlite3_index_info structure.
161823 **
161824 ** Return a pointer to the collation name:
161825 **
161826 ** 1. If there is an explicit COLLATE operator on the constaint, return it.
161827 **
161828 ** 2. Else, if the column has an alternative collation, return that.
161829 **
161830 ** 3. Otherwise, return "BINARY".
161831 */
@@ -162885,11 +163199,11 @@
162885 aSortCost[isOrdered] = whereSortingCost(
162886 pWInfo, nRowEst, nOrderBy, isOrdered
162887 );
162888 }
162889 /* TUNING: Add a small extra penalty (3) to sorting as an
162890 ** extra encouragment to the query planner to select a plan
162891 ** where the rows emerge in the correct order without any sorting
162892 ** required. */
162893 rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3;
162894
162895 WHERETRACE(0x002,
@@ -163593,11 +163907,11 @@
163593 ** inner loops (or around the "..." if the test occurs within the inner-
163594 ** most loop)
163595 **
163596 ** OUTER JOINS
163597 **
163598 ** An outer join of tables t1 and t2 is conceptally coded as follows:
163599 **
163600 ** foreach row1 in t1 do
163601 ** flag = 0
163602 ** foreach row2 in t2 do
163603 ** start:
@@ -163748,11 +164062,11 @@
163748 }else{
163749 /* Assign a bit from the bitmask to every term in the FROM clause.
163750 **
163751 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
163752 **
163753 ** The rule of the previous sentence ensures thta if X is the bitmask for
163754 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
163755 ** Knowing the bitmask for all tables to the left of a left join is
163756 ** important. Ticket #3015.
163757 **
163758 ** Note that bitmasks are created for all pTabList->nSrc tables in
@@ -164729,11 +165043,11 @@
164729 ** last_value(expr)
164730 ** nth_value(expr, N)
164731 **
164732 ** These are the same built-in window functions supported by Postgres.
164733 ** Although the behaviour of aggregate window functions (functions that
164734 ** can be used as either aggregates or window funtions) allows them to
164735 ** be implemented using an API, built-in window functions are much more
164736 ** esoteric. Additionally, some window functions (e.g. nth_value())
164737 ** may only be implemented by caching the entire partition in memory.
164738 ** As such, some built-in window functions use the same API as aggregate
164739 ** window functions and some are implemented directly using VDBE
@@ -165259,11 +165573,11 @@
165259 ** linked list of WINDOW definitions for the current SELECT statement.
165260 ** Argument pFunc is the function definition just resolved and pWin
165261 ** is the Window object representing the associated OVER clause. This
165262 ** function updates the contents of pWin as follows:
165263 **
165264 ** * If the OVER clause refered to a named window (as in "max(x) OVER win"),
165265 ** search list pList for a matching WINDOW definition, and update pWin
165266 ** accordingly. If no such WINDOW clause can be found, leave an error
165267 ** in pParse.
165268 **
165269 ** * If the function is a built-in window function that requires the
@@ -165880,11 +166194,11 @@
165880 }
165881 return pWin;
165882 }
165883
165884 /*
165885 ** Window *pWin has just been created from a WINDOW clause. Tokne pBase
165886 ** is the base window. Earlier windows from the same WINDOW clause are
165887 ** stored in the linked list starting at pWin->pNextWin. This function
165888 ** either updates *pWin according to the base specification, or else
165889 ** leaves an error in pParse.
165890 */
@@ -166186,11 +166500,11 @@
166186 ** start,current,end
166187 ** Consider a window-frame similar to the following:
166188 **
166189 ** (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
166190 **
166191 ** The windows functions implmentation caches the input rows in a temp
166192 ** table, sorted by "a, b" (it actually populates the cache lazily, and
166193 ** aggressively removes rows once they are no longer required, but that's
166194 ** a mere detail). It keeps three cursors open on the temp table. One
166195 ** (current) that points to the next row to return to the query engine
166196 ** once its window function values have been calculated. Another (end)
@@ -167195,11 +167509,11 @@
167195 ** RETURN_ROW
167196 ** }
167197 **
167198 ** For the most part, the patterns above are adapted to support UNBOUNDED by
167199 ** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and
167200 ** CURRENT ROW by assuming that it is equivilent to "0 PRECEDING/FOLLOWING".
167201 ** This is optimized of course - branches that will never be taken and
167202 ** conditions that are always true are omitted from the VM code. The only
167203 ** exceptional case is:
167204 **
167205 ** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING
@@ -167474,11 +167788,11 @@
167474 s.eDelete = WINDOW_AGGINVERSE;
167475 break;
167476 }
167477
167478 /* Allocate registers for the array of values from the sub-query, the
167479 ** samve values in record form, and the rowid used to insert said record
167480 ** into the ephemeral table. */
167481 regNew = pParse->nMem+1;
167482 pParse->nMem += nInput;
167483 regRecord = ++pParse->nMem;
167484 s.regRowid = ++pParse->nMem;
@@ -167715,11 +168029,12 @@
167715 #endif /* SQLITE_OMIT_WINDOWFUNC */
167716
167717 /************** End of window.c **********************************************/
167718 /************** Begin file parse.c *******************************************/
167719 /* This file is automatically generated by Lemon from input grammar
167720 ** source file "parse.y". */
 
167721 /*
167722 ** 2001-09-15
167723 **
167724 ** The author disclaims copyright to this source code. In place of
167725 ** a legal notice, here is a blessing:
@@ -167732,11 +168047,11 @@
167732 ** This file contains SQLite's SQL parser.
167733 **
167734 ** The canonical source code to this file ("parse.y") is a Lemon grammar
167735 ** file that specifies the input grammar and actions to take while parsing.
167736 ** That input file is processed by Lemon to generate a C-language
167737 ** implementation of a parser for the given grammer. You might be reading
167738 ** this comment as part of the translated C-code. Edits should be made
167739 ** to the original parse.y sources.
167740 */
167741
167742 /* #include "sqliteInt.h" */
@@ -174928,16 +175243,10 @@
174928
174929 /*
174930 ** Forward declarations of external module initializer functions
174931 ** for modules that need them.
174932 */
174933 #ifdef SQLITE_ENABLE_FTS1
174934 SQLITE_PRIVATE int sqlite3Fts1Init(sqlite3*);
174935 #endif
174936 #ifdef SQLITE_ENABLE_FTS2
174937 SQLITE_PRIVATE int sqlite3Fts2Init(sqlite3*);
174938 #endif
174939 #ifdef SQLITE_ENABLE_FTS5
174940 SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*);
174941 #endif
174942 #ifdef SQLITE_ENABLE_STMTVTAB
174943 SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*);
@@ -174946,16 +175255,10 @@
174946 /*
174947 ** An array of pointers to extension initializer functions for
174948 ** built-in extensions.
174949 */
174950 static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
174951 #ifdef SQLITE_ENABLE_FTS1
174952 sqlite3Fts1Init,
174953 #endif
174954 #ifdef SQLITE_ENABLE_FTS2
174955 sqlite3Fts2Init,
174956 #endif
174957 #ifdef SQLITE_ENABLE_FTS3
174958 sqlite3Fts3Init,
174959 #endif
174960 #ifdef SQLITE_ENABLE_FTS5
174961 sqlite3Fts5Init,
@@ -178204,11 +178507,11 @@
178204 ** 2 on off
178205 ** 1 off on
178206 ** 0 off off
178207 **
178208 ** Legacy behavior is 3 (double-quoted string literals are allowed anywhere)
178209 ** and so that is the default. But developers are encouranged to use
178210 ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible.
178211 */
178212 #if !defined(SQLITE_DQS)
178213 # define SQLITE_DQS 3
178214 #endif
@@ -178739,11 +179042,11 @@
178739 goto error_out;
178740 }
178741
178742 /* Find the column for which info is requested */
178743 if( zColumnName==0 ){
178744 /* Query for existance of table only */
178745 }else{
178746 for(iCol=0; iCol<pTab->nCol; iCol++){
178747 pCol = &pTab->aCol[iCol];
178748 if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
178749 break;
@@ -179179,11 +179482,11 @@
179179 **
179180 ** Set or clear a flag that indicates that the database file is always well-
179181 ** formed and never corrupt. This flag is clear by default, indicating that
179182 ** database files might have arbitrary corruption. Setting the flag during
179183 ** testing causes certain assert() statements in the code to be activated
179184 ** that demonstrat invariants on well-formed database files.
179185 */
179186 case SQLITE_TESTCTRL_NEVER_CORRUPT: {
179187 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
179188 break;
179189 }
@@ -179333,11 +179636,11 @@
179333 **
179334 ** "ptr" is a pointer to a u32.
179335 **
179336 ** op==0 Store the current sqlite3TreeTrace in *ptr
179337 ** op==1 Set sqlite3TreeTrace to the value *ptr
179338 ** op==3 Store the current sqlite3WhereTrace in *ptr
179339 ** op==3 Set sqlite3WhereTrace to the value *ptr
179340 */
179341 case SQLITE_TESTCTRL_TRACEFLAGS: {
179342 int opTrace = va_arg(ap, int);
179343 u32 *ptr = va_arg(ap, u32*);
@@ -179669,11 +179972,11 @@
179669 #endif /* SQLITE_OMIT_WAL */
179670 return rc;
179671 }
179672
179673 /*
179674 ** Open a read-transaction on the snapshot idendified by pSnapshot.
179675 */
179676 SQLITE_API int sqlite3_snapshot_open(
179677 sqlite3 *db,
179678 const char *zDb,
179679 sqlite3_snapshot *pSnapshot
@@ -195704,10 +196007,11 @@
195704 memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING);
195705 }
195706
195707 for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){
195708 NodeReader reader;
 
195709 pNode = &pWriter->aNodeWriter[i];
195710
195711 if( pNode->block.a){
195712 rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n);
195713 while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader);
@@ -200348,11 +200652,11 @@
200348 }
200349 }
200350 }
200351
200352 /*
200353 ** Return a JsonNode and all its descendents as a JSON string.
200354 */
200355 static void jsonReturnJson(
200356 JsonNode *pNode, /* Node to return */
200357 sqlite3_context *pCtx, /* Return value for this function */
200358 sqlite3_value **aReplace /* Array of replacement values */
@@ -202420,11 +202724,11 @@
202420 UNUSED_PARAMETER(argc);
202421 UNUSED_PARAMETER(argv);
202422 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
202423 #ifdef NEVER
202424 /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
202425 ** always have been called to initalize it */
202426 if( NEVER(!pStr) ) return;
202427 #endif
202428 z = pStr->zBuf;
202429 for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
202430 if( c=='"' ){
@@ -205011,11 +205315,24 @@
205011 break;
205012 }
205013 p->pInfo->nCoord = pRtree->nDim2;
205014 p->pInfo->anQueue = pCsr->anQueue;
205015 p->pInfo->mxLevel = pRtree->iDepth + 1;
205016 }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
 
 
 
 
 
 
 
 
 
 
 
 
 
205017 #ifdef SQLITE_RTREE_INT_ONLY
205018 p->u.rValue = sqlite3_value_int64(argv[ii]);
205019 #else
205020 p->u.rValue = sqlite3_value_double(argv[ii]);
205021 #endif
@@ -205142,24 +205459,25 @@
205142 if( p->usable
205143 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
205144 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH)
205145 ){
205146 u8 op;
 
205147 switch( p->op ){
205148 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
205149 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
205150 case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
205151 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
205152 case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
205153 case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break;
205154 default: op = 0; break;
205155 }
205156 if( op ){
205157 zIdxStr[iIdx++] = op;
205158 zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
205159 pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
205160 pIdxInfo->aConstraintUsage[ii].omit = 1;
205161 }
205162 }
205163 }
205164
205165 pIdxInfo->idxNum = 2;
@@ -225250,11 +225568,12 @@
225250 #define FTS5_COMMA 13
225251 #define FTS5_PLUS 14
225252 #define FTS5_STAR 15
225253
225254 /* This file is automatically generated by Lemon from input grammar
225255 ** source file "fts5parse.y". */
 
225256 /*
225257 ** 2000-05-29
225258 **
225259 ** The author disclaims copyright to this source code. In place of
225260 ** a legal notice, here is a blessing:
@@ -237173,11 +237492,11 @@
237173 if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
237174 fts5DataRelease(pLeaf);
237175 pLeaf = 0;
237176 }else if( bDetailNone ){
237177 break;
237178 }else if( iNext>=pLeaf->szLeaf || iNext<4 ){
237179 p->rc = FTS5_CORRUPT;
237180 break;
237181 }else{
237182 int nShift = iNext - 4;
237183 int nPg;
@@ -237377,11 +237696,13 @@
237377 }else{
237378 if( iKey!=1 ){
237379 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
237380 }
237381 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
237382 if( nPrefix2>nPrefix ){
 
 
237383 memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
237384 iOff += (nPrefix2-nPrefix);
237385 }
237386 memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
237387 iOff += nSuffix2;
@@ -242633,11 +242954,11 @@
242633 int nArg, /* Number of args */
242634 sqlite3_value **apUnused /* Function arguments */
242635 ){
242636 assert( nArg==0 );
242637 UNUSED_PARAM2(nArg, apUnused);
242638 sqlite3_result_text(pCtx, "fts5: 2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0", -1, SQLITE_TRANSIENT);
242639 }
242640
242641 /*
242642 ** Return true if zName is the extension on one of the shadow tables used
242643 ** by this module.
242644
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version $VERSION. 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.
@@ -14,10 +14,13 @@
14 ** the text of this file. Search for "Begin file sqlite3.h" to find the start
15 ** of the embedded sqlite3.h header file.) Additional code files may be needed
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** ec4ab327decd6a5ee5e6a53f1489e17e0cd.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -48,15 +51,15 @@
51 ** NO_TEST - The branches on this line are not
52 ** measured by branch coverage. This is
53 ** used on lines of code that actually
54 ** implement parts of coverage testing.
55 **
56 ** OPTIMIZATION-IF-TRUE - This branch is allowed to always be false
57 ** and the correct answer is still obtained,
58 ** though perhaps more slowly.
59 **
60 ** OPTIMIZATION-IF-FALSE - This branch is allowed to always be true
61 ** and the correct answer is still obtained,
62 ** though perhaps more slowly.
63 **
64 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
65 ** that would be harmless and undetectable
@@ -454,13 +457,13 @@
457 **
458 ** See also: [sqlite3_libversion()],
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.43.0"
463 #define SQLITE_VERSION_NUMBER 3043000
464 #define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -1498,11 +1501,11 @@
1501 ** the database is not a wal-mode db, or if there is no such connection in any
1502 ** other process. This opcode cannot be used to detect transactions opened
1503 ** by clients within the current process, only within other processes.
1504 **
1505 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1506 ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
1507 ** [checksum VFS shim] only.
1508 **
1509 ** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1510 ** If there is currently no transaction open on the database, and the
1511 ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
@@ -2762,11 +2765,11 @@
2765 ** 3.0.0.
2766 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2767 ** the [VACUUM] command will fail with an obscure error when attempting to
2768 ** process a table with generated columns and a descending index. This is
2769 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2770 ** either generated columns or descending indexes.
2771 ** </dd>
2772 **
2773 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2774 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2775 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
@@ -3043,10 +3046,11 @@
3046 ** SQL statements is a no-op and has no effect on SQL statements
3047 ** that are started after the sqlite3_interrupt() call returns.
3048 **
3049 ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
3050 ** or not an interrupt is currently in effect for [database connection] D.
3051 ** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
3052 */
3053 SQLITE_API void sqlite3_interrupt(sqlite3*);
3054 SQLITE_API int sqlite3_is_interrupted(sqlite3*);
3055
3056 /*
@@ -3696,12 +3700,14 @@
3700 ** and context pointer P. ^If the X callback is
3701 ** NULL or if the M mask is zero, then tracing is disabled. The
3702 ** M argument should be the bitwise OR-ed combination of
3703 ** zero or more [SQLITE_TRACE] constants.
3704 **
3705 ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3706 ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3707 ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each
3708 ** database connection may have at most one trace callback.
3709 **
3710 ** ^The X callback is invoked whenever any of the events identified by
3711 ** mask M occur. ^The integer return value from the callback is currently
3712 ** ignored, though this may change in future releases. Callback
3713 ** implementations should return zero to ensure future compatibility.
@@ -4066,11 +4072,11 @@
4072 **
4073 ** The first parameter to these interfaces (hereafter referred to
4074 ** as F) must be one of:
4075 ** <ul>
4076 ** <li> A database filename pointer created by the SQLite core and
4077 ** passed into the xOpen() method of a VFS implementation, or
4078 ** <li> A filename obtained from [sqlite3_db_filename()], or
4079 ** <li> A new filename constructed using [sqlite3_create_filename()].
4080 ** </ul>
4081 ** If the F parameter is not one of the above, then the behavior is
4082 ** undefined and probably undesirable. Older versions of SQLite were
@@ -4179,11 +4185,11 @@
4185 SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4186
4187 /*
4188 ** CAPI3REF: Create and Destroy VFS Filenames
4189 **
4190 ** These interfaces are provided for use by [VFS shim] implementations and
4191 ** are not useful outside of that context.
4192 **
4193 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4194 ** database filename D with corresponding journal file J and WAL file W and
4195 ** with N URI parameters key/values pairs in the array P. The result from
@@ -4889,11 +4895,11 @@
4895 ** These three options exist:
4896 ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4897 ** with it may be passed. ^It is called to dispose of the BLOB or string even
4898 ** if the call to the bind API fails, except the destructor is not called if
4899 ** the third parameter is a NULL pointer or the fourth parameter is negative.
4900 ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
4901 ** the application remains responsible for disposing of the object. ^In this
4902 ** case, the object and the provided pointer to it must remain valid until
4903 ** either the prepared statement is finalized or the same SQL parameter is
4904 ** bound to something else, whichever occurs sooner.
4905 ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
@@ -5568,18 +5574,30 @@
5574 ** Use [sqlite3_clear_bindings()] to reset the bindings.
5575 **
5576 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
5577 ** back to the beginning of its program.
5578 **
5579 ** ^The return code from [sqlite3_reset(S)] indicates whether or not
5580 ** the previous evaluation of prepared statement S completed successfully.
5581 ** ^If [sqlite3_step(S)] has never before been called on S or if
5582 ** [sqlite3_step(S)] has not been called since the previous call
5583 ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return
5584 ** [SQLITE_OK].
5585 **
5586 ** ^If the most recent call to [sqlite3_step(S)] for the
5587 ** [prepared statement] S indicated an error, then
5588 ** [sqlite3_reset(S)] returns an appropriate [error code].
5589 ** ^The [sqlite3_reset(S)] interface might also return an [error code]
5590 ** if there were no prior errors but the process of resetting
5591 ** the prepared statement caused a new error. ^For example, if an
5592 ** [INSERT] statement with a [RETURNING] clause is only stepped one time,
5593 ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but
5594 ** the overall statement might still fail and the [sqlite3_reset(S)] call
5595 ** might return SQLITE_BUSY if locking constraints prevent the
5596 ** database change from committing. Therefore, it is important that
5597 ** applications check the return code from [sqlite3_reset(S)] even if
5598 ** no prior call to [sqlite3_step(S)] indicated a problem.
5599 **
5600 ** ^The [sqlite3_reset(S)] interface does not change the values
5601 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
5602 */
5603 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
@@ -5792,11 +5810,11 @@
5810 ** <p>
5811 ** The SQLITE_DIRECTONLY flag is recommended for any
5812 ** [application-defined SQL function]
5813 ** that has side-effects or that could potentially leak sensitive information.
5814 ** This will prevent attacks in which an application is tricked
5815 ** into using a database file that has had its schema surreptitiously
5816 ** modified to invoke the application-defined function in ways that are
5817 ** harmful.
5818 ** <p>
5819 ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5820 ** [application-defined SQL functions], regardless of whether or not they
@@ -9501,12 +9519,12 @@
9519 ** ^(There may be at most one unlock-notify callback registered by a
9520 ** blocked connection. If sqlite3_unlock_notify() is called when the
9521 ** blocked connection already has a registered unlock-notify callback,
9522 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9523 ** called with a NULL pointer as its second argument, then any existing
9524 ** unlock-notify callback is cancelled. ^The blocked connections
9525 ** unlock-notify callback may also be cancelled by closing the blocked
9526 ** connection using [sqlite3_close()].
9527 **
9528 ** The unlock-notify callback is not reentrant. If an application invokes
9529 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9530 ** crash or deadlock may be the result.
@@ -9925,11 +9943,11 @@
9943 ** </dd>
9944 **
9945 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9946 ** <dd>Calls of the form
9947 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9948 ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
9949 ** prohibits that virtual table from being used from within triggers and
9950 ** views.
9951 ** </dd>
9952 **
9953 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
@@ -10115,11 +10133,11 @@
10133 ** ^(A constraint on a virtual table of the form
10134 ** "[IN operator|column IN (...)]" is
10135 ** communicated to the xBestIndex method as a
10136 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
10137 ** this constraint, it must set the corresponding
10138 ** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under
10139 ** the usual mode of handling IN operators, SQLite generates [bytecode]
10140 ** that invokes the [xFilter|xFilter() method] once for each value
10141 ** on the right-hand side of the IN operator.)^ Thus the virtual table
10142 ** only sees a single value from the right-hand side of the IN operator
10143 ** at a time.
@@ -10544,11 +10562,11 @@
10562 ** triggers; and so forth.
10563 **
10564 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10565 ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10566 ** in this case the new values are not available. In this case, when a
10567 ** callback made with op==SQLITE_DELETE is actually a write using the
10568 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10569 ** the index of the column being written. In other cases, where the
10570 ** pre-update hook is being invoked for some other reason, including a
10571 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10572 **
@@ -13468,11 +13486,11 @@
13486 ** The maximum number of terms in a compound SELECT statement.
13487 ** The code generator for compound SELECT statements does one
13488 ** level of recursion for each term. A stack overflow can result
13489 ** if the number of terms is too large. In practice, most SQL
13490 ** never has more than 3 or 4 terms. Use a value of 0 to disable
13491 ** any limit on the number of terms in a compound SELECT.
13492 */
13493 #ifndef SQLITE_MAX_COMPOUND_SELECT
13494 # define SQLITE_MAX_COMPOUND_SELECT 500
13495 #endif
13496
@@ -14806,11 +14824,11 @@
14824 };
14825
14826 /*
14827 ** Name of table that holds the database schema.
14828 **
14829 ** The PREFERRED names are used wherever possible. But LEGACY is also
14830 ** used for backwards compatibility.
14831 **
14832 ** 1. Queries can use either the PREFERRED or the LEGACY names
14833 ** 2. The sqlite3_set_authorizer() callback uses the LEGACY name
14834 ** 3. The PRAGMA table_list statement uses the PREFERRED name
@@ -16575,11 +16593,11 @@
16593
16594 /*
16595 ** The VdbeCoverage macros are used to set a coverage testing point
16596 ** for VDBE branch instructions. The coverage testing points are line
16597 ** numbers in the sqlite3.c source file. VDBE branch coverage testing
16598 ** only works with an amalgamation build. That's ok since a VDBE branch
16599 ** coverage build designed for testing the test suite only. No application
16600 ** should ever ship with VDBE branch coverage measuring turned on.
16601 **
16602 ** VdbeCoverage(v) // Mark the previously coded instruction
16603 ** // as a branch
@@ -16593,21 +16611,21 @@
16611 ** VdbeCoverageNeverNull(v) // Previous three-way branch is only
16612 ** // taken on the first two ways. The
16613 ** // NULL option is not possible
16614 **
16615 ** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested
16616 ** // in distinguishing equal and not-equal.
16617 **
16618 ** Every VDBE branch operation must be tagged with one of the macros above.
16619 ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
16620 ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
16621 ** routine in vdbe.c, alerting the developer to the missed tag.
16622 **
16623 ** During testing, the test application will invoke
16624 ** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
16625 ** routine that is invoked as each bytecode branch is taken. The callback
16626 ** contains the sqlite3.c source line number of the VdbeCoverage macro and
16627 ** flags to indicate whether or not the branch was taken. The test application
16628 ** is responsible for keeping track of this and reporting byte-code branches
16629 ** that are never taken.
16630 **
16631 ** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
@@ -16942,11 +16960,11 @@
16960 #endif
16961
16962 /*
16963 ** Default synchronous levels.
16964 **
16965 ** Note that (for historical reasons) the PAGER_SYNCHRONOUS_* macros differ
16966 ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1.
16967 **
16968 ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS
16969 ** OFF 1 0
16970 ** NORMAL 2 1
@@ -16981,11 +16999,11 @@
16999
17000 /*
17001 ** An instance of the following structure stores a database schema.
17002 **
17003 ** Most Schema objects are associated with a Btree. The exception is
17004 ** the Schema for the TEMP database (sqlite3.aDb[1]) which is free-standing.
17005 ** In shared cache mode, a single Schema object can be shared by multiple
17006 ** Btrees that refer to the same underlying BtShared object.
17007 **
17008 ** Schema objects are automatically deallocated when the last Btree that
17009 ** references them is destroyed. The TEMP Schema is manually freed by
@@ -17092,11 +17110,11 @@
17110 u32 nSlot; /* Number of lookaside slots allocated */
17111 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
17112 LookasideSlot *pInit; /* List of buffers not previously used */
17113 LookasideSlot *pFree; /* List of available buffers */
17114 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
17115 LookasideSlot *pSmallInit; /* List of small buffers not previously used */
17116 LookasideSlot *pSmallFree; /* List of available small buffers */
17117 void *pMiddle; /* First byte past end of full-size buffers and
17118 ** the first byte of LOOKASIDE_SMALL buffers */
17119 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
17120 void *pStart; /* First byte of available memory space */
@@ -17109,11 +17127,11 @@
17127
17128 #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0
17129 #define EnableLookaside db->lookaside.bDisable--;\
17130 db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue
17131
17132 /* Size of the smaller allocations in two-size lookaside */
17133 #ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE
17134 # define LOOKASIDE_SMALL 0
17135 #else
17136 # define LOOKASIDE_SMALL 128
17137 #endif
@@ -17537,11 +17555,11 @@
17555 ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!!
17556 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
17557 **
17558 ** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the
17559 ** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is
17560 ** used internally and if set means that the function has side effects.
17561 ** SQLITE_INNOCUOUS is used by application code and means "not unsafe".
17562 ** See multiple instances of tag-20230109-1.
17563 */
17564 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
17565 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
@@ -18127,11 +18145,11 @@
18145 ** to its default value. CASCADE means that a DELETE or UPDATE of the
18146 ** referenced table row is propagated into the row that holds the
18147 ** foreign key.
18148 **
18149 ** The OE_Default value is a place holder that means to use whatever
18150 ** conflict resolution algorithm is required from context.
18151 **
18152 ** The following symbolic values are used to record which type
18153 ** of conflict resolution action to take.
18154 */
18155 #define OE_None 0 /* There is no constraint to check */
@@ -18541,11 +18559,11 @@
18559 #endif
18560 int iTable; /* TK_COLUMN: cursor number of table holding column
18561 ** TK_REGISTER: register number
18562 ** TK_TRIGGER: 1 -> new, 0 -> old
18563 ** EP_Unlikely: 134217728 times likelihood
18564 ** TK_IN: ephemeral table holding RHS
18565 ** TK_SELECT_COLUMN: Number of columns on the LHS
18566 ** TK_SELECT: 1st register of result vector */
18567 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
18568 ** TK_VARIABLE: variable number (always >= 1).
18569 ** TK_SELECT_COLUMN: column of the result vector */
@@ -18811,11 +18829,11 @@
18829 unsigned fromDDL :1; /* Comes from sqlite_schema */
18830 unsigned isCte :1; /* This is a CTE */
18831 unsigned notCte :1; /* This item may not match a CTE */
18832 unsigned isUsing :1; /* u3.pUsing is valid */
18833 unsigned isOn :1; /* u3.pOn was once valid and non-NULL */
18834 unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */
18835 unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
18836 } fg;
18837 int iCursor; /* The VDBE cursor number used to access this table */
18838 union {
18839 Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
@@ -19657,11 +19675,11 @@
19675 #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */
19676
19677 /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
19678 ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
19679 ** parameters are for temporary use during development, to help find
19680 ** optimal values for parameters in the query planner. The should not
19681 ** be used on trunk check-ins. They are a temporary mechanism available
19682 ** for transient development builds only.
19683 **
19684 ** Tuning parameters are numbered starting with 1.
19685 */
@@ -19769,10 +19787,11 @@
19787 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
19788 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
19789 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
19790 int walkerDepth; /* Number of subqueries */
19791 u16 eCode; /* A small processing code */
19792 u16 mWFlags; /* Use-dependent flags */
19793 union { /* Extra data for callback */
19794 NameContext *pNC; /* Naming context */
19795 int n; /* A counter */
19796 int iCur; /* A cursor number */
19797 SrcList *pSrcList; /* FROM clause */
@@ -20479,11 +20498,11 @@
20498 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, const Token*);
20499 SQLITE_PRIVATE int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int);
20500 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*,Expr*,int);
20501 SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList*,const ExprList*, int);
20502 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int);
20503 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int,int);
20504 SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*);
20505 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
20506 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
20507 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
20508 SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*);
@@ -23042,11 +23061,11 @@
23061 int iNewReg; /* Register for new.* values */
23062 int iBlobWrite; /* Value returned by preupdate_blobwrite() */
23063 i64 iKey1; /* First key value passed to hook */
23064 i64 iKey2; /* Second key value passed to hook */
23065 Mem *aNew; /* Array of new.* values */
23066 Table *pTab; /* Schema object being updated */
23067 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
23068 };
23069
23070 /*
23071 ** An instance of this object is used to pass an vector of values into
@@ -24258,10 +24277,29 @@
24277 { 4, "hour", 1.2897e+11, 3600.0 },
24278 { 3, "day", 5373485.0, 86400.0 },
24279 { 5, "month", 176546.0, 2592000.0 },
24280 { 4, "year", 14713.0, 31536000.0 },
24281 };
24282
24283 /*
24284 ** If the DateTime p is raw number, try to figure out if it is
24285 ** a julian day number of a unix timestamp. Set the p value
24286 ** appropriately.
24287 */
24288 static void autoAdjustDate(DateTime *p){
24289 if( !p->rawS || p->validJD ){
24290 p->rawS = 0;
24291 }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */
24292 && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */
24293 ){
24294 double r = p->s*1000.0 + 210866760000000.0;
24295 clearYMD_HMS_TZ(p);
24296 p->iJD = (sqlite3_int64)(r + 0.5);
24297 p->validJD = 1;
24298 p->rawS = 0;
24299 }
24300 }
24301
24302 /*
24303 ** Process a modifier to a date-time stamp. The modifiers are
24304 ** as follows:
24305 **
@@ -24302,23 +24340,12 @@
24340 ** If rawS is available, then interpret as a julian day number, or
24341 ** a unix timestamp, depending on its magnitude.
24342 */
24343 if( sqlite3_stricmp(z, "auto")==0 ){
24344 if( idx>1 ) return 1; /* IMP: R-33611-57934 */
24345 autoAdjustDate(p);
24346 rc = 0;
 
 
 
 
 
 
 
 
 
 
 
24347 }
24348 break;
24349 }
24350 case 'j': {
24351 /*
@@ -24480,22 +24507,68 @@
24507 case '7':
24508 case '8':
24509 case '9': {
24510 double rRounder;
24511 int i;
24512 int Y,M,D,h,m,x;
24513 const char *z2 = z;
24514 for(n=1; z[n]; n++){
24515 if( z[n]==':' ) break;
24516 if( sqlite3Isspace(z[n]) ) break;
24517 if( z[n]=='-' && n==5 && getDigits(&z[1], "40f", &Y)==1 ) break;
24518 }
24519 if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){
24520 rc = 1;
24521 break;
24522 }
24523 if( z[n]=='-' ){
24524 /* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the
24525 ** specified number of years, months, and days. MM is limited to
24526 ** the range 0-11 and DD is limited to 0-30.
24527 */
24528 if( z[0]!='+' && z[0]!='-' ) break; /* Must start with +/- */
24529 if( NEVER(n!=5) ) break; /* Must be 4-digit YYYY */
24530 if( getDigits(&z[1], "40f-20a-20d", &Y, &M, &D)!=3 ) break;
24531 if( M>=12 ) break; /* M range 0..11 */
24532 if( D>=31 ) break; /* D range 0..30 */
24533 computeYMD_HMS(p);
24534 p->validJD = 0;
24535 if( z[0]=='-' ){
24536 p->Y -= Y;
24537 p->M -= M;
24538 D = -D;
24539 }else{
24540 p->Y += Y;
24541 p->M += M;
24542 }
24543 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
24544 p->Y += x;
24545 p->M -= x*12;
24546 computeJD(p);
24547 p->validHMS = 0;
24548 p->validYMD = 0;
24549 p->iJD += (i64)D*86400000;
24550 if( z[11]==0 ){
24551 rc = 0;
24552 break;
24553 }
24554 if( sqlite3Isspace(z[11])
24555 && getDigits(&z[12], "20c:20e", &h, &m)==2
24556 ){
24557 z2 = &z[12];
24558 n = 2;
24559 }else{
24560 break;
24561 }
24562 }
24563 if( z2[n]==':' ){
24564 /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the
24565 ** specified number of hours, minutes, seconds, and fractional seconds
24566 ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be
24567 ** omitted.
24568 */
24569
24570 DateTime tx;
24571 sqlite3_int64 day;
24572 if( !sqlite3Isdigit(*z2) ) z2++;
24573 memset(&tx, 0, sizeof(tx));
24574 if( parseHhMmSs(z2, &tx) ) break;
@@ -24526,11 +24599,10 @@
24599 && sqlite3_strnicmp(aXformType[i].zName, z, n)==0
24600 && r>-aXformType[i].rLimit && r<aXformType[i].rLimit
24601 ){
24602 switch( i ){
24603 case 4: { /* Special processing to add months */
 
24604 assert( strcmp(aXformType[i].zName,"month")==0 );
24605 computeYMD_HMS(p);
24606 p->M += (int)r;
24607 x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12;
24608 p->Y += x;
@@ -24803,11 +24875,11 @@
24875 ** %J ** julian day number
24876 ** %m month 01-12
24877 ** %M minute 00-59
24878 ** %s seconds since 1970-01-01
24879 ** %S seconds 00-59
24880 ** %w day of week 0-6 Sunday==0
24881 ** %W week of year 00-53
24882 ** %Y year 0000-9999
24883 ** %% %
24884 */
24885 static void strftimeFunc(
@@ -24942,10 +25014,120 @@
25014 sqlite3_value **NotUsed2
25015 ){
25016 UNUSED_PARAMETER2(NotUsed, NotUsed2);
25017 dateFunc(context, 0, 0);
25018 }
25019
25020 /*
25021 ** timediff(DATE1, DATE2)
25022 **
25023 ** Return the amount of time that must be added to DATE2 in order to
25024 ** convert it into DATE2. The time difference format is:
25025 **
25026 ** +YYYY-MM-DD HH:MM:SS.SSS
25027 **
25028 ** The initial "+" becomes "-" if DATE1 occurs before DATE2. For
25029 ** date/time values A and B, the following invariant should hold:
25030 **
25031 ** datetime(A) == (datetime(B, timediff(A,B))
25032 **
25033 ** Both DATE arguments must be either a julian day number, or an
25034 ** ISO-8601 string. The unix timestamps are not supported by this
25035 ** routine.
25036 */
25037 static void timediffFunc(
25038 sqlite3_context *context,
25039 int argc,
25040 sqlite3_value **argv
25041 ){
25042 char sign;
25043 int Y, M;
25044 DateTime d1, d2;
25045 sqlite3_str sRes;
25046 if( isDate(context, 1, argv, &d1) ) return;
25047 if( isDate(context, 1, &argv[1], &d2) ) return;
25048 computeYMD_HMS(&d1);
25049 computeYMD_HMS(&d2);
25050 if( d1.iJD>=d2.iJD ){
25051 sign = '+';
25052 Y = d1.Y - d2.Y;
25053 if( Y ){
25054 d2.Y = d1.Y;
25055 d2.validJD = 0;
25056 computeJD(&d2);
25057 }
25058 M = d1.M - d2.M;
25059 if( M<0 ){
25060 Y--;
25061 M += 12;
25062 }
25063 if( M!=0 ){
25064 d2.M = d1.M;
25065 d2.validJD = 0;
25066 computeJD(&d2);
25067 }
25068 if( d1.iJD<d2.iJD ){
25069 M--;
25070 if( M<0 ){
25071 M = 11;
25072 Y--;
25073 }
25074 d2.M--;
25075 if( d2.M<1 ){
25076 d2.M = 12;
25077 d2.Y--;
25078 }
25079 d2.validJD = 0;
25080 computeJD(&d2);
25081 }
25082 d1.iJD -= d2.iJD;
25083 d1.iJD += 148699540800000;
25084 }else{
25085 sign = '-';
25086 Y = d2.Y - d1.Y;
25087 if( Y ){
25088 d2.Y = d1.Y;
25089 d2.validJD = 0;
25090 computeJD(&d2);
25091 }
25092 M = d2.M - d1.M;
25093 if( M<0 ){
25094 Y--;
25095 M += 12;
25096 }
25097 if( M!=0 ){
25098 d2.M = d1.M;
25099 d2.validJD = 0;
25100 computeJD(&d2);
25101 }
25102 if( d1.iJD>d2.iJD ){
25103 M--;
25104 if( M<0 ){
25105 M = 11;
25106 Y--;
25107 }
25108 d2.M++;
25109 if( d2.M>12 ){
25110 d2.M = 1;
25111 d2.Y++;
25112 }
25113 d2.validJD = 0;
25114 computeJD(&d2);
25115 }
25116 d1.iJD = d2.iJD - d1.iJD;
25117 d1.iJD += 148699540800000;
25118 }
25119 d1.validYMD = 0;
25120 d1.validHMS = 0;
25121 d1.validTZ = 0;
25122 computeYMD_HMS(&d1);
25123 sqlite3StrAccumInit(&sRes, 0, 0, 0, 100);
25124 sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f",
25125 sign, Y, M, d1.D-1, d1.h, d1.m, d1.s);
25126 sqlite3ResultStrAccum(context, &sRes);
25127 }
25128
25129
25130 /*
25131 ** current_timestamp()
25132 **
25133 ** This function returns the same value as datetime('now').
@@ -25017,10 +25199,11 @@
25199 PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ),
25200 PURE_DATE(date, -1, 0, 0, dateFunc ),
25201 PURE_DATE(time, -1, 0, 0, timeFunc ),
25202 PURE_DATE(datetime, -1, 0, 0, datetimeFunc ),
25203 PURE_DATE(strftime, -1, 0, 0, strftimeFunc ),
25204 PURE_DATE(timediff, 2, 0, 0, timediffFunc ),
25205 DFUNCTION(current_time, 0, 0, 0, ctimeFunc ),
25206 DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc),
25207 DFUNCTION(current_date, 0, 0, 0, cdateFunc ),
25208 #else
25209 STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc),
@@ -25170,11 +25353,11 @@
25353 && op!=SQLITE_FCNTL_CKPT_START
25354 ){
25355 /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
25356 ** is using a regular VFS, it is called after the corresponding
25357 ** transaction has been committed. Injecting a fault at this point
25358 ** confuses the test scripts - the COMMIT command returns SQLITE_NOMEM
25359 ** but the transaction is committed anyway.
25360 **
25361 ** The core must call OsFileControl() though, not OsFileControlHint(),
25362 ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
25363 ** means the commit really has failed and an error should be returned
@@ -25791,11 +25974,11 @@
25974 /*
25975 ** Like free() but works for allocations obtained from sqlite3MemMalloc()
25976 ** or sqlite3MemRealloc().
25977 **
25978 ** For this low-level routine, we already know that pPrior!=0 since
25979 ** cases where pPrior==0 will have been intercepted and dealt with
25980 ** by higher-level routines.
25981 */
25982 static void sqlite3MemFree(void *pPrior){
25983 #ifdef SQLITE_MALLOCSIZE
25984 SQLITE_FREE(pPrior);
@@ -25879,11 +26062,11 @@
26062 size_t len;
26063 if( _sqliteZone_ ){
26064 return SQLITE_OK;
26065 }
26066 len = sizeof(cpuCount);
26067 /* One usually wants to use hw.activecpu for MT decisions, but not here */
26068 sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0);
26069 if( cpuCount>1 ){
26070 /* defer MT decisions to system malloc */
26071 _sqliteZone_ = malloc_default_zone();
26072 }else{
@@ -28346,11 +28529,11 @@
28529
28530 #include <pthread.h>
28531
28532 /*
28533 ** The sqlite3_mutex.id, sqlite3_mutex.nRef, and sqlite3_mutex.owner fields
28534 ** are necessary under two conditions: (1) Debug builds and (2) using
28535 ** home-grown mutexes. Encapsulate these conditions into a single #define.
28536 */
28537 #if defined(SQLITE_DEBUG) || defined(SQLITE_HOMEGROWN_RECURSIVE_MUTEX)
28538 # define SQLITE_MUTEX_NREF 1
28539 #else
@@ -28847,11 +29030,11 @@
29030 */
29031 struct sqlite3_mutex {
29032 CRITICAL_SECTION mutex; /* Mutex controlling the lock */
29033 int id; /* Mutex type */
29034 #ifdef SQLITE_DEBUG
29035 volatile int nRef; /* Number of entrances */
29036 volatile DWORD owner; /* Thread holding this mutex */
29037 volatile LONG trace; /* True to trace changes */
29038 #endif
29039 };
29040
@@ -32228,11 +32411,12 @@
32411 const char *azOp[] = {
32412 "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE"
32413 };
32414 assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT );
32415 assert( pExpr->pRight );
32416 assert( sqlite3ExprSkipCollateAndLikely(pExpr->pRight)->op
32417 == TK_TRUEFALSE );
32418 x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight);
32419 zUniOp = azOp[x];
32420 break;
32421 }
32422
@@ -33887,11 +34071,11 @@
34071 #endif
34072
34073 /*
34074 ** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
34075 ** or to bypass normal error detection during testing in order to let
34076 ** execute proceed further downstream.
34077 **
34078 ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
34079 ** sqlite3FaultSim() function only returns non-zero during testing.
34080 **
34081 ** During testing, if the test harness has set a fault-sim callback using
@@ -34498,11 +34682,11 @@
34682 }
34683
34684 /* store the result */
34685 *pResult = result;
34686
34687 /* return true if number and no extra non-whitespace characters after */
34688 if( z==zEnd && nDigit>0 && eValid && eType>0 ){
34689 return eType;
34690 }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){
34691 return -1;
34692 }else{
@@ -34634,11 +34818,11 @@
34818 testcase( i==20*incr );
34819 if( u>LARGEST_INT64 ){
34820 /* This test and assignment is needed only to suppress UB warnings
34821 ** from clang and -fsanitize=undefined. This test and assignment make
34822 ** the code a little larger and slower, and no harm comes from omitting
34823 ** them, but we must appease the undefined-behavior pharisees. */
34824 *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
34825 }else if( neg ){
34826 *pNum = -(i64)u;
34827 }else{
34828 *pNum = (i64)u;
@@ -35319,11 +35503,11 @@
35503 return 1;
35504 }
35505 }
35506
35507 /*
35508 ** Attempt to add, subtract, or multiply the 64-bit signed value iB against
35509 ** the other 64-bit signed integer at *pA and store the result in *pA.
35510 ** Return 0 on success. Or if the operation would have resulted in an
35511 ** overflow, leave *pA unchanged and return 1.
35512 */
35513 SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
@@ -35632,11 +35816,11 @@
35816 */
35817 #ifndef SQLITE_HWTIME_H
35818 #define SQLITE_HWTIME_H
35819
35820 /*
35821 ** The following routine only works on Pentium-class (or newer) processors.
35822 ** It uses the RDTSC opcode to read the cycle count value out of the
35823 ** processor and returns that value. This can be used for high-res
35824 ** profiling.
35825 */
35826 #if !defined(__STRICT_ANSI__) && \
@@ -35804,11 +35988,11 @@
35988 pH->first = pNew;
35989 }
35990 }
35991
35992
35993 /* Resize the hash table so that it contains "new_size" buckets.
35994 **
35995 ** The hash table might fail to resize if sqlite3_malloc() fails or
35996 ** if the new size is the same as the prior size.
35997 ** Return TRUE if the resize occurs and false if not.
35998 */
@@ -37190,11 +37374,11 @@
37374 ** skip locking all together.
37375 **
37376 ** This source file is organized into divisions where the logic for various
37377 ** subfunctions is contained within the appropriate division. PLEASE
37378 ** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed
37379 ** in the correct division and should be clearly labelled.
37380 **
37381 ** The layout of divisions is as follows:
37382 **
37383 ** * General-purpose declarations and utility functions.
37384 ** * Unique file ID logic used by VxWorks.
@@ -37777,11 +37961,11 @@
37961 #endif
37962 }
37963
37964 /*
37965 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
37966 ** "unix" VFSes. Return SQLITE_OK upon successfully updating the
37967 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
37968 ** system call named zName.
37969 */
37970 static int unixSetSystemCall(
37971 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
@@ -38299,11 +38483,11 @@
38483 ** But wait: there are yet more problems with POSIX advisory locks.
38484 **
38485 ** If you close a file descriptor that points to a file that has locks,
38486 ** all locks on that file that are owned by the current process are
38487 ** released. To work around this problem, each unixInodeInfo object
38488 ** maintains a count of the number of pending locks on the inode.
38489 ** When an attempt is made to close an unixFile, if there are
38490 ** other unixFile open on the same inode that are holding locks, the call
38491 ** to close() the file descriptor is deferred until all of the locks clear.
38492 ** The unixInodeInfo structure keeps a list of file descriptors that need to
38493 ** be closed and that list is walked (and cleared) when the last lock
@@ -38313,11 +38497,11 @@
38497 **
38498 ** Many older versions of linux use the LinuxThreads library which is
38499 ** not posix compliant. Under LinuxThreads, a lock created by thread
38500 ** A cannot be modified or overridden by a different thread B.
38501 ** Only thread A can modify the lock. Locking behavior is correct
38502 ** if the application uses the newer Native Posix Thread Library (NPTL)
38503 ** on linux - with NPTL a lock created by thread A can override locks
38504 ** in thread B. But there is no way to know at compile-time which
38505 ** threading library is being used. So there is no way to know at
38506 ** compile-time whether or not thread A can override locks on thread B.
38507 ** One has to do a run-time check to discover the behavior of the
@@ -38515,11 +38699,11 @@
38699 static void storeLastErrno(unixFile *pFile, int error){
38700 pFile->lastErrno = error;
38701 }
38702
38703 /*
38704 ** Close all file descriptors accumulated in the unixInodeInfo->pUnused list.
38705 */
38706 static void closePendingFds(unixFile *pFile){
38707 unixInodeInfo *pInode = pFile->pInode;
38708 UnixUnusedFd *p;
38709 UnixUnusedFd *pNext;
@@ -38878,19 +39062,19 @@
39062 ** lock primitives (called read-locks and write-locks below, to avoid
39063 ** confusion with SQLite lock names). The algorithms are complicated
39064 ** slightly in order to be compatible with Windows95 systems simultaneously
39065 ** accessing the same database file, in case that is ever required.
39066 **
39067 ** Symbols defined in os.h identify the 'pending byte' and the 'reserved
39068 ** byte', each single bytes at well known offsets, and the 'shared byte
39069 ** range', a range of 510 bytes at a well known offset.
39070 **
39071 ** To obtain a SHARED lock, a read-lock is obtained on the 'pending
39072 ** byte'. If this is successful, 'shared byte range' is read-locked
39073 ** and the lock on the 'pending byte' released. (Legacy note: When
39074 ** SQLite was first developed, Windows95 systems were still very common,
39075 ** and Windows95 lacks a shared-lock capability. So on Windows95, a
39076 ** single randomly selected by from the 'shared byte range' is locked.
39077 ** Windows95 is now pretty much extinct, but this work-around for the
39078 ** lack of shared-locks on Windows95 lives on, for backwards
39079 ** compatibility.)
39080 **
@@ -38907,11 +39091,11 @@
39091 ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then
39092 ** a PENDING lock is obtained first. A PENDING lock is implemented by
39093 ** obtaining a write-lock on the 'pending byte'. This ensures that no new
39094 ** SHARED locks can be obtained, but existing SHARED locks are allowed to
39095 ** persist. If the call to this function fails to obtain the EXCLUSIVE
39096 ** lock in this case, it holds the PENDING lock instead. The client may
39097 ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED
39098 ** locks have cleared.
39099 */
39100 int rc = SQLITE_OK;
39101 unixFile *pFile = (unixFile*)id;
@@ -38935,11 +39119,11 @@
39119 return SQLITE_OK;
39120 }
39121
39122 /* Make sure the locking sequence is correct.
39123 ** (1) We never move from unlocked to anything higher than shared lock.
39124 ** (2) SQLite never explicitly requests a pending lock.
39125 ** (3) A shared lock is always held when a reserve lock is requested.
39126 */
39127 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
39128 assert( eFileLock!=PENDING_LOCK );
39129 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
@@ -40153,11 +40337,11 @@
40337 return SQLITE_OK;
40338 }
40339
40340 /* Make sure the locking sequence is correct
40341 ** (1) We never move from unlocked to anything higher than shared lock.
40342 ** (2) SQLite never explicitly requests a pending lock.
40343 ** (3) A shared lock is always held when a reserve lock is requested.
40344 */
40345 assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK );
40346 assert( eFileLock!=PENDING_LOCK );
40347 assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK );
@@ -40269,11 +40453,11 @@
40453 ** reestablish the shared lock if we can't get the afpUnlock
40454 */
40455 if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST +
40456 pInode->sharedByte, 1, 0)) ){
40457 int failed2 = SQLITE_OK;
40458 /* now attempt to get the exclusive lock range */
40459 failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST,
40460 SHARED_SIZE, 1);
40461 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
40462 SHARED_FIRST + pInode->sharedByte, 1, 1)) ){
40463 /* Can't reestablish the shared lock. Sqlite can't deal, this is
@@ -40564,11 +40748,11 @@
40748 || offset+amt<=PENDING_BYTE
40749 );
40750 #endif
40751
40752 #if SQLITE_MAX_MMAP_SIZE>0
40753 /* Deal with as much of this read request as possible by transferring
40754 ** data from the memory mapping using memcpy(). */
40755 if( offset<pFile->mmapSize ){
40756 if( offset+amt <= pFile->mmapSize ){
40757 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
40758 return SQLITE_OK;
@@ -40716,11 +40900,11 @@
40900 }
40901 }
40902 #endif
40903
40904 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
40905 /* Deal with as much of this write request as possible by transferring
40906 ** data from the memory mapping using memcpy(). */
40907 if( offset<pFile->mmapSize ){
40908 if( offset+amt <= pFile->mmapSize ){
40909 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
40910 return SQLITE_OK;
@@ -40838,11 +41022,11 @@
41022 #endif
41023
41024 /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
41025 ** no-op. But go ahead and call fstat() to validate the file
41026 ** descriptor as we need a method to provoke a failure during
41027 ** coverage testing.
41028 */
41029 #ifdef SQLITE_NO_SYNC
41030 {
41031 struct stat buf;
41032 rc = osFstat(fd, &buf);
@@ -46478,11 +46662,11 @@
46662
46663 }; /* End of the overrideable system calls */
46664
46665 /*
46666 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
46667 ** "win32" VFSes. Return SQLITE_OK upon successfully updating the
46668 ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
46669 ** system call named zName.
46670 */
46671 static int winSetSystemCall(
46672 sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */
@@ -48058,11 +48242,11 @@
48242 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
48243 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
48244 pFile->h, pBuf, amt, offset, pFile->locktype));
48245
48246 #if SQLITE_MAX_MMAP_SIZE>0
48247 /* Deal with as much of this read request as possible by transferring
48248 ** data from the memory mapping using memcpy(). */
48249 if( offset<pFile->mmapSize ){
48250 if( offset+amt <= pFile->mmapSize ){
48251 memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
48252 OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
@@ -48136,11 +48320,11 @@
48320 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, "
48321 "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile,
48322 pFile->h, pBuf, amt, offset, pFile->locktype));
48323
48324 #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0
48325 /* Deal with as much of this write request as possible by transferring
48326 ** data from the memory mapping using memcpy(). */
48327 if( offset<pFile->mmapSize ){
48328 if( offset+amt <= pFile->mmapSize ){
48329 memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt);
48330 OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
@@ -48246,11 +48430,11 @@
48430 **
48431 ** The only feasible work-around is to defer the truncation until after
48432 ** all references to memory-mapped content are closed. That is doable,
48433 ** but involves adding a few branches in the common write code path which
48434 ** could slow down normal operations slightly. Hence, we have decided for
48435 ** now to simply make transactions a no-op if there are pending reads. We
48436 ** can maybe revisit this decision in the future.
48437 */
48438 return SQLITE_OK;
48439 }
48440 #endif
@@ -48305,11 +48489,11 @@
48489 }
48490
48491 #ifdef SQLITE_TEST
48492 /*
48493 ** Count the number of fullsyncs and normal syncs. This is used to test
48494 ** that syncs and fullsyncs are occurring at the right times.
48495 */
48496 SQLITE_API int sqlite3_sync_count = 0;
48497 SQLITE_API int sqlite3_fullsync_count = 0;
48498 #endif
48499
@@ -52643,11 +52827,11 @@
52827 return SQLITE_OK;
52828 }
52829 h = BITVEC_HASH(i++);
52830 /* if there wasn't a hash collision, and this doesn't */
52831 /* completely fill the hash, then just add it without */
52832 /* worrying about sub-dividing and re-hashing. */
52833 if( !p->u.aHash[h] ){
52834 if (p->nSet<(BITVEC_NINT-1)) {
52835 goto bitvec_set_end;
52836 } else {
52837 goto bitvec_set_rehash;
@@ -53140,11 +53324,11 @@
53324 /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
53325 ** suggested cache size is set to N. */
53326 return p->szCache;
53327 }else{
53328 i64 n;
53329 /* IMPLEMENTATION-OF: R-59858-46238 If the argument N is negative, then the
53330 ** number of cache pages is adjusted to be a number of pages that would
53331 ** use approximately abs(N*1024) bytes of memory based on the current
53332 ** page size. */
53333 n = ((-1024*(i64)p->szCache)/(p->szPage+p->szExtra));
53334 if( n>1000000000 ) n = 1000000000;
@@ -53628,11 +53812,11 @@
53812 }
53813 return result.pDirty;
53814 }
53815
53816 /*
53817 ** Sort the list of pages in ascending order by pgno. Pages are
53818 ** connected by pDirty pointers. The pDirtyPrev pointers are
53819 ** corrupted by this sort.
53820 **
53821 ** Since there cannot be more than 2^31 distinct pages in a database,
53822 ** there cannot be more than 31 buckets required by the merge sorter.
@@ -53868,11 +54052,11 @@
54052 ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N).
54053 **
54054 ** If N is positive, then N pages worth of memory are allocated using a single
54055 ** sqlite3Malloc() call and that memory is used for the first N pages allocated.
54056 ** Or if N is negative, then -1024*N bytes of memory are allocated and used
54057 ** for as many pages as can be accommodated.
54058 **
54059 ** Only one of (2) or (3) can be used. Once the memory available to (2) or
54060 ** (3) is exhausted, subsequent allocations fail over to the general-purpose
54061 ** memory allocator (1).
54062 **
@@ -53902,11 +54086,11 @@
54086 ** but causes a 2-byte gap in the structure for most architectures (since
54087 ** pointers must be either 4 or 8-byte aligned). As this structure is located
54088 ** in memory directly after the associated page data, if the database is
54089 ** corrupt, code at the b-tree layer may overread the page buffer and
54090 ** read part of this structure before the corruption is detected. This
54091 ** can cause a valgrind error if the uninitialized gap is accessed. Using u16
54092 ** ensures there is no such gap, and therefore no bytes of uninitialized
54093 ** memory in the structure.
54094 **
54095 ** The pLruNext and pLruPrev pointers form a double-linked circular list
54096 ** of all pages that are unpinned. The PGroup.lru element (which should be
@@ -55122,11 +55306,11 @@
55306 ** until DESTROY.
55307 **
55308 ** The TEST primitive includes a "batch" number. The TEST primitive
55309 ** will only see elements that were inserted before the last change
55310 ** in the batch number. In other words, if an INSERT occurs between
55311 ** two TESTs where the TESTs have the same batch number, then the
55312 ** value added by the INSERT will not be visible to the second TEST.
55313 ** The initial batch number is zero, so if the very first TEST contains
55314 ** a non-zero batch number, it will see all prior INSERTs.
55315 **
55316 ** No INSERTs may occurs after a SMALLEST. An assertion will fail if
@@ -56045,11 +56229,11 @@
56229 ** Once it has entered the ERROR state, any attempt to use the pager
56230 ** to read or write data returns an error. Eventually, once all
56231 ** outstanding transactions have been abandoned, the pager is able to
56232 ** transition back to OPEN state, discarding the contents of the
56233 ** page-cache and any other in-memory state at the same time. Everything
56234 ** is reloaded from disk (and, if necessary, hot-journal rollback performed)
56235 ** when a read-transaction is next opened on the pager (transitioning
56236 ** the pager into READER state). At that point the system has recovered
56237 ** from the error.
56238 **
56239 ** Specifically, the pager jumps into the ERROR state if:
@@ -57418,11 +57602,11 @@
57602 ** + N bytes: super-journal filename in utf-8.
57603 ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
57604 ** + 4 bytes: super-journal name checksum.
57605 ** + 8 bytes: aJournalMagic[].
57606 **
57607 ** The super-journal page checksum is the sum of the bytes in the super-journal
57608 ** name, where each byte is interpreted as a signed 8-bit integer.
57609 **
57610 ** If zSuper is a NULL pointer (occurs for a single database transaction),
57611 ** this call is a no-op.
57612 */
@@ -57471,11 +57655,11 @@
57655 ){
57656 return rc;
57657 }
57658 pPager->journalOff += (nSuper+20);
57659
57660 /* If the pager is in persistent-journal mode, then the physical
57661 ** journal-file may extend past the end of the super-journal name
57662 ** and 8 bytes of magic data just written to the file. This is
57663 ** dangerous because the code to rollback a hot-journal file
57664 ** will not be able to find the super-journal name to determine
57665 ** whether or not the journal is hot.
@@ -57641,11 +57825,11 @@
57825 pPager->setSuper = 0;
57826 }
57827
57828 /*
57829 ** This function is called whenever an IOERR or FULL error that requires
57830 ** the pager to transition into the ERROR state may have occurred.
57831 ** The first argument is a pointer to the pager structure, the second
57832 ** the error-code about to be returned by a pager API function. The
57833 ** value returned is a copy of the second argument to this function.
57834 **
57835 ** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the
@@ -57916,11 +58100,11 @@
58100 pager_unlock(pPager);
58101 }
58102
58103 /*
58104 ** Parameter aData must point to a buffer of pPager->pageSize bytes
58105 ** of data. Compute and return a checksum based on the contents of the
58106 ** page of data and the current value of pPager->cksumInit.
58107 **
58108 ** This is not a real checksum. It is really just the sum of the
58109 ** random initial value (pPager->cksumInit) and every 200th byte
58110 ** of the page data, starting with byte offset (pPager->pageSize%200).
@@ -58882,11 +59066,11 @@
59066 PgHdr *p; /* For looping over pages */
59067
59068 assert( pPager->pWal );
59069 assert( pList );
59070 #ifdef SQLITE_DEBUG
59071 /* Verify that the page list is in ascending order */
59072 for(p=pList; p && p->pDirty; p=p->pDirty){
59073 assert( p->pgno < p->pDirty->pgno );
59074 }
59075 #endif
59076
@@ -59013,11 +59197,11 @@
59197 }
59198
59199 #ifndef SQLITE_OMIT_WAL
59200 /*
59201 ** Check if the *-wal file that corresponds to the database opened by pPager
59202 ** exists if the database is not empty, or verify that the *-wal file does
59203 ** not exist (by deleting it) if the database file is empty.
59204 **
59205 ** If the database is not empty and the *-wal file exists, open the pager
59206 ** in WAL mode. If the database is empty or if no *-wal file exists and
59207 ** if no error occurs, make sure Pager.journalMode is not set to
@@ -60765,11 +60949,11 @@
60949 return SQLITE_OK;
60950 }
60951
60952 /*
60953 ** Return the sqlite3_file for the main database given the name
60954 ** of the corresponding WAL or Journal name as passed into
60955 ** xOpen.
60956 */
60957 SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *zName){
60958 Pager *pPager;
60959 while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){
@@ -63050,11 +63234,11 @@
63234
63235 /* Change the journal mode. */
63236 assert( pPager->eState!=PAGER_ERROR );
63237 pPager->journalMode = (u8)eMode;
63238
63239 /* When transitioning from TRUNCATE or PERSIST to any other journal
63240 ** mode except WAL, unless the pager is in locking_mode=exclusive mode,
63241 ** delete the journal file.
63242 */
63243 assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
63244 assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
@@ -63768,11 +63952,11 @@
63952 ** of available reader locks and should be at least 3. The default
63953 ** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5.
63954 **
63955 ** Technically, the various VFSes are free to implement these locks however
63956 ** they see fit. However, compatibility is encouraged so that VFSes can
63957 ** interoperate. The standard implementation used on both unix and windows
63958 ** is for the index number to indicate a byte offset into the
63959 ** WalCkptInfo.aLock[] array in the wal-index header. In other words, all
63960 ** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which
63961 ** should be 120) is the location in the shm file for the first locking
63962 ** byte.
@@ -63844,11 +64028,11 @@
64028 ** There is one entry in aReadMark[] for each reader lock. If a reader
64029 ** holds read-lock K, then the value in aReadMark[K] is no greater than
64030 ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff)
64031 ** for any aReadMark[] means that entry is unused. aReadMark[0] is
64032 ** a special case; its value is never used and it exists as a place-holder
64033 ** to avoid having to offset aReadMark[] indexes by one. Readers holding
64034 ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
64035 ** directly from the database.
64036 **
64037 ** The value of aReadMark[K] may only be changed by a thread that
64038 ** is holding an exclusive lock on WAL_READ_LOCK(K). Thus, the value of
@@ -64374,19 +64558,19 @@
64558 */
64559 if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
64560 return 0;
64561 }
64562
64563 /* A frame is only valid if the page number is greater than zero.
64564 */
64565 pgno = sqlite3Get4byte(&aFrame[0]);
64566 if( pgno==0 ){
64567 return 0;
64568 }
64569
64570 /* A frame is only valid if a checksum of the WAL header,
64571 ** all prior frames, the first 16 bytes of this frame-header,
64572 ** and the frame-data matches the checksum in the last 8
64573 ** bytes of this frame-header.
64574 */
64575 nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
64576 walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
@@ -65076,11 +65260,11 @@
65260 }
65261 return rc;
65262 }
65263
65264 /*
65265 ** Change the size to which the WAL file is truncated on each reset.
65266 */
65267 SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){
65268 if( pWal ) pWal->mxWalSize = iLimit;
65269 }
65270
@@ -65775,11 +65959,11 @@
65959 sqlite3OsFileControlHint(
65960 pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist
65961 );
65962 if( bPersist!=1 ){
65963 /* Try to delete the WAL file if the checkpoint completed and
65964 ** fsynced (rc==SQLITE_OK) and if we are not in persistent-wal
65965 ** mode (!bPersist) */
65966 isDelete = 1;
65967 }else if( pWal->mxWalSize>=0 ){
65968 /* Try to truncate the WAL file to zero bytes if the checkpoint
65969 ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
@@ -65842,11 +66026,11 @@
66026 ** Memory barriers are used to prevent the compiler or the hardware from
66027 ** reordering the reads and writes. TSAN and similar tools can sometimes
66028 ** give false-positive warnings about these accesses because the tools do not
66029 ** account for the double-read and the memory barrier. The use of mutexes
66030 ** here would be problematic as the memory being accessed is potentially
66031 ** shared among multiple processes and not all mutex implementations work
66032 ** reliably in that environment.
66033 */
66034 aHdr = walIndexHdr(pWal);
66035 memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */
66036 walShmBarrier(pWal);
@@ -67947,11 +68131,11 @@
68131 /*
68132 ** An instance of this object stores information about each a single database
68133 ** page that has been loaded into memory. The information in this object
68134 ** is derived from the raw on-disk page content.
68135 **
68136 ** As each database page is loaded into memory, the pager allocates an
68137 ** instance of this object and zeros the first 8 bytes. (This is the
68138 ** "extra" information associated with each page of the pager.)
68139 **
68140 ** Access to all fields of this structure is controlled by the mutex
68141 ** stored in MemPage.pBt->mutex.
@@ -68403,11 +68587,11 @@
68587 #define get4byte sqlite3Get4byte
68588 #define put4byte sqlite3Put4byte
68589
68590 /*
68591 ** get2byteAligned(), unlike get2byte(), requires that its argument point to a
68592 ** two-byte aligned address. get2byteAligned() is only used for accessing the
68593 ** cell addresses in a btree header.
68594 */
68595 #if SQLITE_BYTEORDER==4321
68596 # define get2byteAligned(x) (*(u16*)(x))
68597 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
@@ -68580,11 +68764,11 @@
68764 ** against all schemas and we do not want those schemas being
68765 ** reset out from under us.
68766 **
68767 ** There is a corresponding leave-all procedures.
68768 **
68769 ** Enter the mutexes in ascending order by BtShared pointer address
68770 ** to avoid the possibility of deadlock when two threads with
68771 ** two or more btrees in common both try to lock all their btrees
68772 ** at the same instant.
68773 */
68774 static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){
@@ -68712,10 +68896,11 @@
68896
68897 #endif /* ifndef SQLITE_OMIT_SHARED_CACHE */
68898
68899 /************** End of btmutex.c *********************************************/
68900 /************** Begin file btree.c *******************************************/
68901
68902 /*
68903 ** 2004 April 6
68904 **
68905 ** The author disclaims copyright to this source code. In place of
68906 ** a legal notice, here is a blessing:
@@ -70348,11 +70533,11 @@
70533 cbrk = usableSize;
70534 iCellLast = usableSize - 4;
70535 iCellStart = get2byte(&data[hdr+5]);
70536 if( nCell>0 ){
70537 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
70538 memcpy(temp, data, usableSize);
70539 src = temp;
70540 for(i=0; i<nCell; i++){
70541 u8 *pAddr; /* The i-th cell pointer */
70542 pAddr = &data[cellOffset + i*2];
70543 pc = get2byte(pAddr);
@@ -70572,11 +70757,11 @@
70757 **
70758 ** Adjacent freeblocks are coalesced.
70759 **
70760 ** Even though the freeblock list was checked by btreeComputeFreeSpace(),
70761 ** that routine will not detect overlap between cells or freeblocks. Nor
70762 ** does it detect cells or freeblocks that encroach into the reserved bytes
70763 ** at the end of the page. So do additional corruption checks inside this
70764 ** routine and return SQLITE_CORRUPT if any problems are found.
70765 */
70766 static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
70767 u16 iPtr; /* Address of ptr to next freeblock */
@@ -71175,11 +71360,11 @@
71360 /* pPage might not be a btree page; it might be an overflow page
71361 ** or ptrmap page or a free page. In those cases, the following
71362 ** call to btreeInitPage() will likely return SQLITE_CORRUPT.
71363 ** But no harm is done by this. And it is very important that
71364 ** btreeInitPage() be called on every btree page so we make
71365 ** the call for every page that comes in for re-initializing. */
71366 btreeInitPage(pPage);
71367 }
71368 }
71369 }
71370
@@ -71570,11 +71755,11 @@
71755 ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes
71756 ** by the various routines that manipulate binary cells. Which
71757 ** can mean that fillInCell() only initializes the first 2 or 3
71758 ** bytes of pTmpSpace, but that the first 4 bytes are copied from
71759 ** it into a database page. This is not actually a problem, but it
71760 ** does cause a valgrind error when the 1 or 2 bytes of uninitialized
71761 ** data is passed to system call write(). So to avoid this error,
71762 ** zero the first 4 bytes of temp space here.
71763 **
71764 ** Also: Provide four bytes of initialized space before the
71765 ** beginning of pTmpSpace as an area available to prepend the
@@ -71805,11 +71990,11 @@
71990 return n;
71991 }
71992
71993 /*
71994 ** Return the number of bytes of space at the end of every page that
71995 ** are intentionally left unused. This is the "reserved" space that is
71996 ** sometimes used by extensions.
71997 **
71998 ** The value returned is the larger of the current reserve size and
71999 ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES.
72000 ** The amount of reserve can only grow - never shrink.
@@ -72052,11 +72237,10 @@
72237 || pageSize>SQLITE_MAX_PAGE_SIZE
72238 || pageSize<=256
72239 ){
72240 goto page1_init_failed;
72241 }
 
72242 assert( (pageSize & 7)==0 );
72243 /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
72244 ** integer at offset 20 is the number of bytes of space at the end of
72245 ** each page to reserve for extensions.
72246 **
@@ -72072,10 +72256,11 @@
72256 ** again with the correct page-size.
72257 */
72258 releasePageOne(pPage1);
72259 pBt->usableSize = usableSize;
72260 pBt->pageSize = pageSize;
72261 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
72262 freeTempSpace(pBt);
72263 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
72264 pageSize-usableSize);
72265 return rc;
72266 }
@@ -72091,10 +72276,11 @@
72276 ** be less than 480. In other words, if the page size is 512, then the
72277 ** reserved space size cannot exceed 32. */
72278 if( usableSize<480 ){
72279 goto page1_init_failed;
72280 }
72281 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
72282 pBt->pageSize = pageSize;
72283 pBt->usableSize = usableSize;
72284 #ifndef SQLITE_OMIT_AUTOVACUUM
72285 pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0);
72286 pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0);
@@ -72269,11 +72455,15 @@
72455 ** One or the other of the two processes must give way or there can be
72456 ** no progress. By returning SQLITE_BUSY and not invoking the busy callback
72457 ** when A already has a read lock, we encourage A to give up and let B
72458 ** proceed.
72459 */
72460 static SQLITE_NOINLINE int btreeBeginTrans(
72461 Btree *p, /* The btree in which to start the transaction */
72462 int wrflag, /* True to start a write transaction */
72463 int *pSchemaVersion /* Put schema version number here, if not NULL */
72464 ){
72465 BtShared *pBt = p->pBt;
72466 Pager *pPager = pBt->pPager;
72467 int rc = SQLITE_OK;
72468
72469 sqlite3BtreeEnter(p);
@@ -72440,10 +72630,32 @@
72630 }
72631
72632 btreeIntegrity(p);
72633 sqlite3BtreeLeave(p);
72634 return rc;
72635 }
72636 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){
72637 BtShared *pBt;
72638 if( p->sharable
72639 || p->inTrans==TRANS_NONE
72640 || (p->inTrans==TRANS_READ && wrflag!=0)
72641 ){
72642 return btreeBeginTrans(p,wrflag,pSchemaVersion);
72643 }
72644 pBt = p->pBt;
72645 if( pSchemaVersion ){
72646 *pSchemaVersion = get4byte(&pBt->pPage1->aData[40]);
72647 }
72648 if( wrflag ){
72649 /* This call makes sure that the pager has the correct number of
72650 ** open savepoints. If the second parameter is greater than 0 and
72651 ** the sub-journal is not already open, then it will be opened here.
72652 */
72653 return sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
72654 }else{
72655 return SQLITE_OK;
72656 }
72657 }
72658
72659 #ifndef SQLITE_OMIT_AUTOVACUUM
72660
72661 /*
@@ -73574,11 +73786,11 @@
73786 **
73787 ** This is an optimization. Everything will still work if this
73788 ** routine always returns 2147483647 (which is the largest record
73789 ** that SQLite can handle) or more. But returning a smaller value might
73790 ** prevent large memory allocations when trying to interpret a
73791 ** corrupt database.
73792 **
73793 ** The current implementation merely returns the size of the underlying
73794 ** database file.
73795 */
73796 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){
@@ -74374,11 +74586,11 @@
74586 return SQLITE_OK;
74587 }
74588 /* If the requested key is one more than the previous key, then
74589 ** try to get there using sqlite3BtreeNext() rather than a full
74590 ** binary search. This is an optimization only. The correct answer
74591 ** is still obtained without this case, only a little more slowly. */
74592 if( pCur->info.nKey+1==intKey ){
74593 *pRes = 0;
74594 rc = sqlite3BtreeNext(pCur, 0);
74595 if( rc==SQLITE_OK ){
74596 getCellInfo(pCur);
@@ -75557,11 +75769,11 @@
75769 return SQLITE_OK;
75770 }
75771
75772 /* Call xParseCell to compute the size of a cell. If the cell contains
75773 ** overflow, then invoke cellClearOverflow to clear out that overflow.
75774 ** Store the result code (SQLITE_OK or some error code) in rc.
75775 **
75776 ** Implemented as macro to force inlining for performance.
75777 */
75778 #define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \
75779 pPage->xParseCell(pPage, pCell, &sInfo); \
@@ -76236,11 +76448,11 @@
76448 ** before returning.
76449 **
76450 ** Finally, argument pBegin points to the byte immediately following the
76451 ** end of the space required by this page for the cell-pointer area (for
76452 ** all cells - not just those inserted by the current call). If the content
76453 ** area must be extended to before this point in order to accommodate all
76454 ** cells in apCell[], then the cells do not fit and non-zero is returned.
76455 */
76456 static int pageInsertArray(
76457 MemPage *pPg, /* Page to add cells to */
76458 u8 *pBegin, /* End of cell-pointer array */
@@ -76551,11 +76763,11 @@
76763
76764 /* If this is an auto-vacuum database, update the pointer map
76765 ** with entries for the new page, and any pointer from the
76766 ** cell on the page to an overflow page. If either of these
76767 ** operations fails, the return code is set, but the contents
76768 ** of the parent page are still manipulated by the code below.
76769 ** That is Ok, at this point the parent page is guaranteed to
76770 ** be marked as dirty. Returning an error code will cause a
76771 ** rollback, undoing any changes made to the parent page.
76772 */
76773 if( ISAUTOVACUUM(pBt) ){
@@ -77141,11 +77353,11 @@
77353 rc = SQLITE_CORRUPT_BKPT;
77354 goto balance_cleanup;
77355 }
77356 }
77357
77358 /* Sanity check: For a non-corrupt database file one of the following
77359 ** must be true:
77360 ** (1) We found one or more cells (cntNew[0])>0), or
77361 ** (2) pPage is a virtual root page. A virtual root page is when
77362 ** the real root page is page 1 and we are the only child of
77363 ** that page.
@@ -77758,11 +77970,11 @@
77970 int iOffset, /* Offset of first byte to write */
77971 int iAmt /* Number of bytes to be written */
77972 ){
77973 int nData = pX->nData - iOffset;
77974 if( nData<=0 ){
77975 /* Overwriting with zeros */
77976 int i;
77977 for(i=0; i<iAmt && pDest[i]==0; i++){}
77978 if( i<iAmt ){
77979 int rc = sqlite3PagerWrite(pPage->pDbPage);
77980 if( rc ) return rc;
@@ -77794,11 +78006,11 @@
78006 ** Overwrite the cell that cursor pCur is pointing to with fresh content
78007 ** contained in pX. In this variant, pCur is pointing to an overflow
78008 ** cell.
78009 */
78010 static SQLITE_NOINLINE int btreeOverwriteOverflowCell(
78011 BtCursor *pCur, /* Cursor pointing to cell to overwrite */
78012 const BtreePayload *pX /* Content to write into the cell */
78013 ){
78014 int iOffset; /* Next byte of pX->pData to write */
78015 int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
78016 int rc; /* Return code */
@@ -78541,11 +78753,11 @@
78753 static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){
78754 BtShared *pBt = p->pBt;
78755 MemPage *pRoot;
78756 Pgno pgnoRoot;
78757 int rc;
78758 int ptfFlags; /* Page-type flags for the root page of new table */
78759
78760 assert( sqlite3BtreeHoldsMutex(p) );
78761 assert( pBt->inTransaction==TRANS_WRITE );
78762 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
78763
@@ -79376,11 +79588,11 @@
79588 pBt = pCheck->pBt;
79589 usableSize = pBt->usableSize;
79590 if( iPage==0 ) return 0;
79591 if( checkRef(pCheck, iPage) ) return 0;
79592 pCheck->zPfx = "Tree %u page %u: ";
79593 pCheck->v1 = iPage;
79594 if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
79595 checkAppendMsg(pCheck,
79596 "unable to get the page. error code=%d", rc);
79597 goto end_of_check;
79598 }
@@ -79713,10 +79925,11 @@
79925 #ifndef SQLITE_OMIT_AUTOVACUUM
79926 if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
79927 checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
79928 }
79929 #endif
79930 sCheck.v0 = aRoot[i];
79931 checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
79932 }
79933 pBt->db->flags = savedDbFlags;
79934
79935 /* Make sure every page in the file is referenced
@@ -82256,10 +82469,11 @@
82469 if( pRec==0 ) return 0;
82470 p->ppRec[0] = pRec;
82471 }
82472
82473 pRec->nField = p->iVal+1;
82474 sqlite3VdbeMemSetNull(&pRec->aMem[p->iVal]);
82475 return &pRec->aMem[p->iVal];
82476 }
82477 #else
82478 UNUSED_PARAMETER(p);
82479 #endif /* defined(SQLITE_ENABLE_STAT4) */
@@ -83652,11 +83866,11 @@
83866 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
83867 p->readOnly = 1;
83868 p->bIsReader = 0;
83869 pOp = &p->aOp[p->nOp-1];
83870 assert( p->aOp[0].opcode==OP_Init );
83871 while( 1 /* Loop terminates when it reaches the OP_Init opcode */ ){
83872 /* Only JUMP opcodes and the short list of special opcodes in the switch
83873 ** below need to be considered. The mkopcodeh.tcl generator script groups
83874 ** all these opcodes together near the front of the opcode list. Skip
83875 ** any opcode that does not need processing by virtual of the fact that
83876 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -84106,11 +84320,11 @@
84320 }
84321
84322
84323 /*
84324 ** If the input FuncDef structure is ephemeral, then free it. If
84325 ** the FuncDef is not ephemeral, then do nothing.
84326 */
84327 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
84328 assert( db!=0 );
84329 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
84330 sqlite3DbNNFreeNN(db, pDef);
@@ -87057,10 +87271,19 @@
87271 ** sqlite3VdbeSerialTypeLen() in the common case.
87272 */
87273 if( d1+(u64)serial_type1+2>(u64)nKey1
87274 && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)>(u64)nKey1
87275 ){
87276 if( serial_type1>=1
87277 && serial_type1<=7
87278 && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)<=(u64)nKey1+8
87279 && CORRUPT_DB
87280 ){
87281 return 1; /* corrupt record not detected by
87282 ** sqlite3VdbeRecordCompareWithSkip(). Return true
87283 ** to avoid firing the assert() */
87284 }
87285 break;
87286 }
87287
87288 /* Extract the values to be compared.
87289 */
@@ -87500,11 +87723,11 @@
87723 serial_type = aKey1[idx1];
87724 if( serial_type>=10 ){
87725 /* Serial types 12 or greater are strings and blobs (greater than
87726 ** numbers). Types 10 and 11 are currently "reserved for future
87727 ** use", so it doesn't really matter what the results of comparing
87728 ** them to numeric values are. */
87729 rc = serial_type==10 ? -1 : +1;
87730 }else if( serial_type==0 ){
87731 rc = -1;
87732 }else{
87733 sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1);
@@ -89129,11 +89352,11 @@
89352
89353 /*
89354 ** The destructor function for a ValueList object. This needs to be
89355 ** a separate function, unknowable to the application, to ensure that
89356 ** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not
89357 ** preceded by activation of IN processing via sqlite3_vtab_int() do not
89358 ** try to access a fake ValueList object inserted by a hostile extension.
89359 */
89360 SQLITE_PRIVATE void sqlite3VdbeValueListFree(void *pToDelete){
89361 sqlite3_free(pToDelete);
89362 }
@@ -89458,11 +89681,11 @@
89681 ** sqlite3_column_text()
89682 ** sqlite3_column_text16()
89683 ** sqlite3_column_real()
89684 ** sqlite3_column_bytes()
89685 ** sqlite3_column_bytes16()
89686 ** sqlite3_column_blob()
89687 */
89688 static void columnMallocFailure(sqlite3_stmt *pStmt)
89689 {
89690 /* If malloc() failed during an encoding conversion within an
89691 ** sqlite3_column_XXX API, then set the return code of the statement to
@@ -89693,11 +89916,11 @@
89916 ** Routines used to attach values to wildcards in a compiled SQL statement.
89917 */
89918 /*
89919 ** Unbind the value bound to variable i in virtual machine p. This is the
89920 ** the same as binding a NULL value to the column. If the "i" parameter is
89921 ** out of range, then SQLITE_RANGE is returned. Otherwise SQLITE_OK.
89922 **
89923 ** A successful evaluation of this routine acquires the mutex on p.
89924 ** the mutex is released if any kind of error occurs.
89925 **
89926 ** The error code stored in database p->db is overwritten with the return
@@ -91669,12 +91892,12 @@
91892 ** to the current line should be indented for EXPLAIN output.
91893 */
91894 case OP_Goto: { /* jump */
91895
91896 #ifdef SQLITE_DEBUG
91897 /* In debugging mode, when the p5 flags is set on an OP_Goto, that
91898 ** means we should really jump back to the preceding OP_ReleaseReg
91899 ** instruction. */
91900 if( pOp->p5 ){
91901 assert( pOp->p2 < (int)(pOp - aOp) );
91902 assert( pOp->p2 > 1 );
91903 pOp = &aOp[pOp->p2 - 2];
@@ -91878,11 +92101,11 @@
92101 ** If P4 is not null then it is an error message string.
92102 **
92103 ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string.
92104 **
92105 ** 0: (no change)
92106 ** 1: NOT NULL constraint failed: P4
92107 ** 2: UNIQUE constraint failed: P4
92108 ** 3: CHECK constraint failed: P4
92109 ** 4: FOREIGN KEY constraint failed: P4
92110 **
92111 ** If P5 is not zero and P4 is NULL, then everything after the ":" is
@@ -95105,11 +95328,11 @@
95328 aMem[pOp->p3].n = 0;
95329 aMem[pOp->p3].z = "";
95330 }
95331 pCx = p->apCsr[pOp->p1];
95332 if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){
95333 /* If the ephemeral table is already open and has no duplicates from
95334 ** OP_OpenDup, then erase all existing content so that the table is
95335 ** empty again, rather than creating a new table. */
95336 assert( pCx->isEphemeral );
95337 pCx->seqCount = 0;
95338 pCx->cacheStatus = CACHE_STALE;
@@ -95596,19 +95819,19 @@
95819 ** The This.P5 parameter is a flag that indicates what to do if the
95820 ** cursor ends up pointing at a valid row that is past the target
95821 ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If
95822 ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
95823 ** case occurs when there are no inequality constraints to the right of
95824 ** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case
95825 ** occurs when there are inequality constraints to the right of the IN
95826 ** operator. In that case, the This.P2 will point either directly to or
95827 ** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for
95828 ** loop terminate.
95829 **
95830 ** Possible outcomes from this opcode:<ol>
95831 **
95832 ** <li> If the cursor is initially not pointed to any valid row, then
95833 ** fall through into the subsequent OP_SeekGE opcode.
95834 **
95835 ** <li> If the cursor is left pointing to a row that is before the target
95836 ** row, even after making as many as This.P1 calls to
95837 ** sqlite3BtreeNext(), then also fall through into OP_SeekGE.
@@ -98277,11 +98500,11 @@
98500 #endif
98501
98502 /* If this function is inside of a trigger, the register array in aMem[]
98503 ** might change from one evaluation to the next. The next block of code
98504 ** checks to see if the register array has changed, and if so it
98505 ** reinitializes the relevant parts of the sqlite3_context object */
98506 if( pCtx->pMem != pMem ){
98507 pCtx->pMem = pMem;
98508 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
98509 }
98510
@@ -99155,11 +99378,11 @@
99378 ** invocation of this opcode.
99379 **
99380 ** This opcode works exactly like OP_Function. The only difference is in
99381 ** its name. This opcode is used in places where the function must be
99382 ** purely non-deterministic. Some built-in date/time functions can be
99383 ** either deterministic of non-deterministic, depending on their arguments.
99384 ** When those function are used in a non-deterministic way, they will check
99385 ** to see if they were called using OP_PureFunc instead of OP_Function, and
99386 ** if they were, they throw an error.
99387 **
99388 ** See also: AggStep, AggFinal, Function
@@ -99173,11 +99396,11 @@
99396 pCtx = pOp->p4.pCtx;
99397
99398 /* If this function is inside of a trigger, the register array in aMem[]
99399 ** might change from one evaluation to the next. The next block of code
99400 ** checks to see if the register array has changed, and if so it
99401 ** reinitializes the relevant parts of the sqlite3_context object */
99402 pOut = &aMem[pOp->p3];
99403 if( pCtx->pOut != pOut ){
99404 pCtx->pVdbe = p;
99405 pCtx->pOut = pOut;
99406 pCtx->enc = encoding;
@@ -99249,11 +99472,11 @@
99472 registerTrace(ii, &aMem[ii]);
99473 }
99474 printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
99475 }
99476 #endif
99477 h %= (pIn1->n*8);
99478 pIn1->z[h/8] |= 1<<(h&7);
99479 break;
99480 }
99481
99482 /* Opcode: Filter P1 P2 P3 P4 *
@@ -99285,11 +99508,11 @@
99508 registerTrace(ii, &aMem[ii]);
99509 }
99510 printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n));
99511 }
99512 #endif
99513 h %= (pIn1->n*8);
99514 if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){
99515 VdbeBranchTaken(1, 2);
99516 p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++;
99517 goto jump_to_p2;
99518 }else{
@@ -99537,11 +99760,11 @@
99760 if( opProperty & OPFLG_OUT3 ){
99761 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
99762 }
99763 if( opProperty==0xff ){
99764 /* Never happens. This code exists to avoid a harmless linkage
99765 ** warning about sqlite3VdbeRegisterDump() being defined but not
99766 ** used. */
99767 sqlite3VdbeRegisterDump(p);
99768 }
99769 }
99770 #endif /* SQLITE_DEBUG */
@@ -100255,11 +100478,11 @@
100478 ** merging two or more level-0 PMAs together creates a level-1 PMA.
100479 **
100480 ** The threshold for the amount of main memory to use before flushing
100481 ** records to a PMA is roughly the same as the limit configured for the
100482 ** page-cache of the main database. Specifically, the threshold is set to
100483 ** the value returned by "PRAGMA main.page_size" multiplied by
100484 ** that returned by "PRAGMA main.cache_size", in bytes.
100485 **
100486 ** If the sorter is running in single-threaded mode, then all PMAs generated
100487 ** are appended to a single temporary file. Or, if the sorter is running in
100488 ** multi-threaded mode then up to (N+1) temporary files may be opened, where
@@ -100278,11 +100501,11 @@
100501 ** final PMA. So at this point the data is stored in some number of sorted
100502 ** PMAs within temporary files on disk.
100503 **
100504 ** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the
100505 ** sorter is running in single-threaded mode, then these PMAs are merged
100506 ** incrementally as keys are retrieved from the sorter by the VDBE. The
100507 ** MergeEngine object, described in further detail below, performs this
100508 ** merge.
100509 **
100510 ** Or, if running in multi-threaded mode, then a background thread is
100511 ** launched to merge the existing PMAs. Once the background thread has
@@ -100441,11 +100664,11 @@
100664 ** single-threaded operation, there is exactly one instance of this object
100665 ** and for multi-threaded operation there are two or more instances.
100666 **
100667 ** Essentially, this structure contains all those fields of the VdbeSorter
100668 ** structure for which each thread requires a separate instance. For example,
100669 ** each thread requeries its own UnpackedRecord object to unpack records in
100670 ** as part of comparison operations.
100671 **
100672 ** Before a background thread is launched, variable bDone is set to 0. Then,
100673 ** right before it exits, the thread itself sets bDone to 1. This is used for
100674 ** two purposes:
@@ -100513,11 +100736,11 @@
100736 /*
100737 ** An instance of the following object is used to read records out of a
100738 ** PMA, in sorted order. The next key to be read is cached in nKey/aKey.
100739 ** aKey might point into aMap or into aBuffer. If neither of those locations
100740 ** contain a contiguous representation of the key, then aAlloc is allocated
100741 ** and the key is copied into aAlloc and aKey is made to point to aAlloc.
100742 **
100743 ** pFd==0 at EOF.
100744 */
100745 struct PmaReader {
100746 i64 iReadOff; /* Current read offset */
@@ -101884,11 +102107,11 @@
102107 ** records to disk. If the sorter is running in multi-threaded mode,
102108 ** round-robin between the first (pSorter->nTask-1) tasks. Except, if
102109 ** the background thread from a sub-tasks previous turn is still running,
102110 ** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy,
102111 ** fall back to using the final sub-task. The first (pSorter->nTask-1)
102112 ** sub-tasks are preferred as they use background threads - the final
102113 ** sub-task uses the main thread. */
102114 for(i=0; i<nWorker; i++){
102115 int iTest = (pSorter->iPrev + i + 1) % nWorker;
102116 pTask = &pSorter->aTask[iTest];
102117 if( pTask->bDone ){
@@ -102368,11 +102591,11 @@
102591 /* eMode is always INCRINIT_NORMAL in single-threaded mode */
102592 assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL );
102593
102594 rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode);
102595
102596 /* Set up the required files for pIncr. A multi-threaded IncrMerge object
102597 ** requires two temp files to itself, whereas a single-threaded object
102598 ** only requires a region of pTask->file2. */
102599 if( rc==SQLITE_OK ){
102600 int mxSz = pIncr->mxSz;
102601 #if SQLITE_MAX_WORKER_THREADS>0
@@ -104033,11 +104256,11 @@
104256 }while( p!=0 );
104257 return WRC_Continue;
104258 }
104259
104260 /* Increase the walkerDepth when entering a subquery, and
104261 ** decrease when leaving the subquery.
104262 */
104263 SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){
104264 UNUSED_PARAMETER(pSelect);
104265 pWalker->walkerDepth++;
104266 return WRC_Continue;
@@ -105767,11 +105990,11 @@
105990 if( sqlite3ResolveExprNames(pNC, pE) ){
105991 return 1;
105992 }
105993 for(j=0; j<pSelect->pEList->nExpr; j++){
105994 if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
105995 /* Since this expression is being changed into a reference
105996 ** to an identical expression in the result set, remove all Window
105997 ** objects belonging to the expression from the Select.pWin list. */
105998 windowRemoveExprFromSelect(pSelect, pE);
105999 pItem->u.x.iOrderByCol = j+1;
106000 }
@@ -106154,11 +106377,11 @@
106377 return WRC_Continue;
106378 }
106379
106380 /*
106381 ** Resolve all names in all expressions of a SELECT and in all
106382 ** descendants of the SELECT, including compounds off of p->pPrior,
106383 ** subqueries in expressions, and subqueries used as FROM clause
106384 ** terms.
106385 **
106386 ** See sqlite3ResolveExprNames() for a description of the kinds of
106387 ** transformations that occur.
@@ -106304,10 +106527,11 @@
106527 }
106528 #endif
106529 if( op==TK_SELECT_COLUMN ){
106530 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
106531 assert( pExpr->iColumn < pExpr->iTable );
106532 assert( pExpr->iColumn >= 0 );
106533 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
106534 return sqlite3ExprAffinity(
106535 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
106536 );
106537 }
@@ -106540,11 +106764,11 @@
106764 }
106765
106766 /*
106767 ** Return the collation sequence for the expression pExpr. If
106768 ** there is no defined collating sequence, return a pointer to the
106769 ** default collation sequence.
106770 **
106771 ** See also: sqlite3ExprCollSeq()
106772 **
106773 ** The sqlite3ExprCollSeq() routine works the same except that it
106774 ** returns NULL if there is no defined collation.
@@ -106670,11 +106894,11 @@
106894 }
106895 }
106896 return pColl;
106897 }
106898
106899 /* Expression p is a comparison operator. Return a collation sequence
106900 ** appropriate for the comparison operator.
106901 **
106902 ** This is normally just a wrapper around sqlite3BinaryCompareCollSeq().
106903 ** However, if the OP_Commuted flag is set, then the order of the operands
106904 ** is reversed in the sqlite3BinaryCompareCollSeq() call so that the
@@ -107586,11 +107810,11 @@
107810 }
107811
107812 /*
107813 ** Arrange to cause pExpr to be deleted when the pParse is deleted.
107814 ** This is similar to sqlite3ExprDelete() except that the delete is
107815 ** deferred until the pParse is deleted.
107816 **
107817 ** The pExpr might be deleted immediately on an OOM error.
107818 **
107819 ** The deferred delete is (currently) implemented by adding the
107820 ** pExpr to the pParse->pConstExpr list with a register number of 0.
@@ -108428,11 +108652,11 @@
108652 /*
108653 ** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE
108654 ** and 0 if it is FALSE.
108655 */
108656 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
108657 pExpr = sqlite3ExprSkipCollateAndLikely((Expr*)pExpr);
108658 assert( pExpr->op==TK_TRUEFALSE );
108659 assert( !ExprHasProperty(pExpr, EP_IntValue) );
108660 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
108661 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
108662 return pExpr->u.zToken[4]==0;
@@ -109021,11 +109245,11 @@
109245 **
109246 ** IN_INDEX_ROWID - The cursor was opened on a database table.
109247 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
109248 ** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index.
109249 ** IN_INDEX_EPH - The cursor was opened on a specially created and
109250 ** populated ephemeral table.
109251 ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be
109252 ** implemented as a sequence of comparisons.
109253 **
109254 ** An existing b-tree might be used if the RHS expression pX is a simple
109255 ** subquery such as:
@@ -109034,11 +109258,11 @@
109258 **
109259 ** If the RHS of the IN operator is a list or a more complex subquery, then
109260 ** an ephemeral table might need to be generated from the RHS and then
109261 ** pX->iTable made to point to the ephemeral table instead of an
109262 ** existing table. In this case, the creation and initialization of the
109263 ** ephemeral table might be put inside of a subroutine, the EP_Subrtn flag
109264 ** will be set on pX and the pX->y.sub fields will be set to show where
109265 ** the subroutine is coded.
109266 **
109267 ** The inFlags parameter must contain, at a minimum, one of the bits
109268 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
@@ -109046,16 +109270,16 @@
109270 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
109271 ** be used to loop over all values of the RHS of the IN operator.
109272 **
109273 ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate
109274 ** through the set members) then the b-tree must not contain duplicates.
109275 ** An ephemeral table will be created unless the selected columns are guaranteed
109276 ** to be unique - either because it is an INTEGER PRIMARY KEY or due to
109277 ** a UNIQUE constraint or index.
109278 **
109279 ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used
109280 ** for fast set membership tests) then an ephemeral table must
109281 ** be used unless <columns> is a single INTEGER PRIMARY KEY column or an
109282 ** index can be found with the specified <columns> as its left-most.
109283 **
109284 ** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and
109285 ** if the RHS of the IN operator is a list (not a subquery) then this
@@ -109384,11 +109608,11 @@
109608 **
109609 ** x IN (4,5,11) -- IN operator with list on right-hand side
109610 ** x IN (SELECT a FROM b) -- IN operator with subquery on the right
109611 **
109612 ** The pExpr parameter is the IN operator. The cursor number for the
109613 ** constructed ephemeral table is returned. The first time the ephemeral
109614 ** table is computed, the cursor number is also stored in pExpr->iTable,
109615 ** however the cursor number returned might not be the same, as it might
109616 ** have been duplicated using OP_OpenDup.
109617 **
109618 ** If the LHS expression ("x" in the examples) is a column value, or
@@ -110231,11 +110455,11 @@
110455 ExprClearProperty(p, EP_Skip);
110456 }
110457
110458 /*
110459 ** Evaluate an expression (either a vector or a scalar expression) and store
110460 ** the result in contiguous temporary registers. Return the index of
110461 ** the first register used to store the result.
110462 **
110463 ** If the returned result register is a temporary scalar, then also write
110464 ** that register number into *piFreeable. If the returned result register
110465 ** is not a temporary or if the expression is a vector set *piFreeable
@@ -110271,11 +110495,11 @@
110495 ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5)
110496 ** so that a subsequent copy will not be merged into this one.
110497 */
110498 static void setDoNotMergeFlagOnCopy(Vdbe *v){
110499 if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){
110500 sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergeable */
110501 }
110502 }
110503
110504 /*
110505 ** Generate code to implement special SQL functions that are implemented
@@ -110361,17 +110585,17 @@
110585 target);
110586 break;
110587 }
110588
110589 case INLINEFUNC_implies_nonnull_row: {
110590 /* Result of sqlite3ExprImpliesNonNullRow() */
110591 Expr *pA1;
110592 assert( nFarg==2 );
110593 pA1 = pFarg->a[1].pExpr;
110594 if( pA1->op==TK_COLUMN ){
110595 sqlite3VdbeAddOp2(v, OP_Integer,
110596 sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable,1),
110597 target);
110598 }else{
110599 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
110600 }
110601 break;
@@ -110543,11 +110767,11 @@
110767 int iTab = pExpr->iTable;
110768 int iReg;
110769 if( ExprHasProperty(pExpr, EP_FixedCol) ){
110770 /* This COLUMN expression is really a constant due to WHERE clause
110771 ** constraints, and that constant is coded by the pExpr->pLeft
110772 ** expression. However, make sure the constant has the correct
110773 ** datatype by applying the Affinity of the table column to the
110774 ** constant.
110775 */
110776 int aff;
110777 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
@@ -111272,11 +111496,11 @@
111496 ** once. If no functions are involved, then factor the code out and put it at
111497 ** the end of the prepared statement in the initialization section.
111498 **
111499 ** If regDest>=0 then the result is always stored in that register and the
111500 ** result is not reusable. If regDest<0 then this routine is free to
111501 ** store the value wherever it wants. The register where the expression
111502 ** is stored is returned. When regDest<0, two identical expressions might
111503 ** code to the same register, if they do not contain function calls and hence
111504 ** are factored out into the initialization section at the end of the
111505 ** prepared statement.
111506 */
@@ -112190,11 +112414,11 @@
112414 ** pE1: x>0 pE2: x==5 Result: false
112415 ** pE1: x=21 pE2: x=21 OR y=43 Result: true
112416 ** pE1: x!=123 pE2: x IS NOT NULL Result: true
112417 ** pE1: x!=?1 pE2: x IS NOT NULL Result: true
112418 ** pE1: x IS NULL pE2: x IS NOT NULL Result: false
112419 ** pE1: x IS ?2 pE2: x IS NOT NULL Result: false
112420 **
112421 ** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has
112422 ** Expr.iTable<0 then assume a table number given by iTab.
112423 **
112424 ** If pParse is not NULL, then the values of bound variables in pE1 are
@@ -112226,68 +112450,108 @@
112450 ){
112451 return 1;
112452 }
112453 return 0;
112454 }
112455
112456 /* This is a helper function to impliesNotNullRow(). In this routine,
112457 ** set pWalker->eCode to one only if *both* of the input expressions
112458 ** separately have the implies-not-null-row property.
112459 */
112460 static void bothImplyNotNullRow(Walker *pWalker, Expr *pE1, Expr *pE2){
112461 if( pWalker->eCode==0 ){
112462 sqlite3WalkExpr(pWalker, pE1);
112463 if( pWalker->eCode ){
112464 pWalker->eCode = 0;
112465 sqlite3WalkExpr(pWalker, pE2);
112466 }
112467 }
112468 }
112469
112470 /*
112471 ** This is the Expr node callback for sqlite3ExprImpliesNonNullRow().
112472 ** If the expression node requires that the table at pWalker->iCur
112473 ** have one or more non-NULL column, then set pWalker->eCode to 1 and abort.
112474 **
112475 ** pWalker->mWFlags is non-zero if this inquiry is being undertaking on
112476 ** behalf of a RIGHT JOIN (or FULL JOIN). That makes a difference when
112477 ** evaluating terms in the ON clause of an inner join.
112478 **
112479 ** This routine controls an optimization. False positives (setting
112480 ** pWalker->eCode to 1 when it should not be) are deadly, but false-negatives
112481 ** (never setting pWalker->eCode) is a harmless missed optimization.
112482 */
112483 static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
112484 testcase( pExpr->op==TK_AGG_COLUMN );
112485 testcase( pExpr->op==TK_AGG_FUNCTION );
112486 if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune;
112487 if( ExprHasProperty(pExpr, EP_InnerON) && pWalker->mWFlags ){
112488 /* If iCur is used in an inner-join ON clause to the left of a
112489 ** RIGHT JOIN, that does *not* mean that the table must be non-null.
112490 ** But it is difficult to check for that condition precisely.
112491 ** To keep things simple, any use of iCur from any inner-join is
112492 ** ignored while attempting to simplify a RIGHT JOIN. */
112493 return WRC_Prune;
112494 }
112495 switch( pExpr->op ){
112496 case TK_ISNOT:
112497 case TK_ISNULL:
112498 case TK_NOTNULL:
112499 case TK_IS:
 
112500 case TK_VECTOR:
 
 
112501 case TK_FUNCTION:
112502 case TK_TRUTH:
112503 case TK_CASE:
112504 testcase( pExpr->op==TK_ISNOT );
112505 testcase( pExpr->op==TK_ISNULL );
112506 testcase( pExpr->op==TK_NOTNULL );
112507 testcase( pExpr->op==TK_IS );
 
112508 testcase( pExpr->op==TK_VECTOR );
 
 
112509 testcase( pExpr->op==TK_FUNCTION );
112510 testcase( pExpr->op==TK_TRUTH );
112511 testcase( pExpr->op==TK_CASE );
112512 return WRC_Prune;
112513
112514 case TK_COLUMN:
112515 if( pWalker->u.iCur==pExpr->iTable ){
112516 pWalker->eCode = 1;
112517 return WRC_Abort;
112518 }
112519 return WRC_Prune;
112520
112521 case TK_OR:
112522 case TK_AND:
112523 /* Both sides of an AND or OR must separately imply non-null-row.
112524 ** Consider these cases:
112525 ** 1. NOT (x AND y)
112526 ** 2. x OR y
112527 ** If only one of x or y is non-null-row, then the overall expression
112528 ** can be true if the other arm is false (case 1) or true (case 2).
112529 */
112530 testcase( pExpr->op==TK_OR );
112531 testcase( pExpr->op==TK_AND );
112532 bothImplyNotNullRow(pWalker, pExpr->pLeft, pExpr->pRight);
112533 return WRC_Prune;
112534
112535 case TK_IN:
112536 /* Beware of "x NOT IN ()" and "x NOT IN (SELECT 1 WHERE false)",
112537 ** both of which can be true. But apart from these cases, if
112538 ** the left-hand side of the IN is NULL then the IN itself will be
112539 ** NULL. */
112540 if( ExprUseXList(pExpr) && ALWAYS(pExpr->x.pList->nExpr>0) ){
112541 sqlite3WalkExpr(pWalker, pExpr->pLeft);
 
 
 
 
112542 }
112543 return WRC_Prune;
112544
112545 case TK_BETWEEN:
112546 /* In "x NOT BETWEEN y AND z" either x must be non-null-row or else
112547 ** both y and z must be non-null row */
112548 assert( ExprUseXList(pExpr) );
112549 assert( pExpr->x.pList->nExpr==2 );
112550 sqlite3WalkExpr(pWalker, pExpr->pLeft);
112551 bothImplyNotNullRow(pWalker, pExpr->x.pList->a[0].pExpr,
112552 pExpr->x.pList->a[1].pExpr);
112553 return WRC_Prune;
112554
112555 /* Virtual tables are allowed to use constraints like x=NULL. So
112556 ** a term of the form x=y does not prove that y is not null if x
112557 ** is the column of a virtual table */
@@ -112345,26 +112609,27 @@
112609 ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
112610 ** clause requires that some column of the right table of the LEFT JOIN
112611 ** be non-NULL, then the LEFT JOIN can be safely converted into an
112612 ** ordinary join.
112613 */
112614 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab, int isRJ){
112615 Walker w;
112616 p = sqlite3ExprSkipCollateAndLikely(p);
112617 if( p==0 ) return 0;
112618 if( p->op==TK_NOTNULL ){
112619 p = p->pLeft;
112620 }else{
112621 while( p->op==TK_AND ){
112622 if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab, isRJ) ) return 1;
112623 p = p->pRight;
112624 }
112625 }
112626 w.xExprCallback = impliesNotNullRow;
112627 w.xSelectCallback = 0;
112628 w.xSelectCallback2 = 0;
112629 w.eCode = 0;
112630 w.mWFlags = isRJ!=0;
112631 w.u.iCur = iTab;
112632 sqlite3WalkExpr(&w, p);
112633 return w.eCode;
112634 }
112635
@@ -112421,11 +112686,11 @@
112686 sqlite3WalkExpr(&w, pExpr);
112687 return !w.eCode;
112688 }
112689
112690
112691 /* Structure used to pass information throughout the Walker in order to
112692 ** implement sqlite3ReferencesSrcList().
112693 */
112694 struct RefSrcList {
112695 sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */
112696 SrcList *pRef; /* Looking for references to these tables */
@@ -112637,11 +112902,11 @@
112902 /*
112903 ** Search the AggInfo object for an aCol[] entry that has iTable and iColumn.
112904 ** Return the index in aCol[] of the entry that describes that column.
112905 **
112906 ** If no prior entry is found, create a new one and return -1. The
112907 ** new column will have an index of pAggInfo->nColumn-1.
112908 */
112909 static void findOrCreateAggInfoColumn(
112910 Parse *pParse, /* Parsing context */
112911 AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */
112912 Expr *pExpr /* Expr describing the column to find or insert */
@@ -112650,10 +112915,11 @@
112915 int k;
112916
112917 assert( pAggInfo->iFirstReg==0 );
112918 pCol = pAggInfo->aCol;
112919 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
112920 if( pCol->pCExpr==pExpr ) return;
112921 if( pCol->iTable==pExpr->iTable
112922 && pCol->iColumn==pExpr->iColumn
112923 && pExpr->op!=TK_IF_NULL_ROW
112924 ){
112925 goto fix_up_expr;
@@ -114035,11 +114301,11 @@
114301
114302 return pBest;
114303 }
114304
114305 /*
114306 ** An error occurred while parsing or otherwise processing a database
114307 ** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an
114308 ** ALTER TABLE RENAME COLUMN program. The error message emitted by the
114309 ** sub-routine is currently stored in pParse->zErrMsg. This function
114310 ** adds context to the error message and then stores it in pCtx.
114311 */
@@ -117141,18 +117407,19 @@
117407 pSample = &pIdx->aSample[pIdx->nSample];
117408 decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0);
117409 decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0);
117410 decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0);
117411
117412 /* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer.
117413 ** This is in case the sample record is corrupted. In that case, the
117414 ** sqlite3VdbeRecordCompare() may read up to two varints past the
117415 ** end of the allocated buffer before it realizes it is dealing with
117416 ** a corrupt record. Or it might try to read a large integer from the
117417 ** buffer. In any case, eight 0x00 bytes prevents this from causing
117418 ** a buffer overread. */
117419 pSample->n = sqlite3_column_bytes(pStmt, 4);
117420 pSample->p = sqlite3DbMallocZero(db, pSample->n + 8);
117421 if( pSample->p==0 ){
117422 sqlite3_finalize(pStmt);
117423 return SQLITE_NOMEM_BKPT;
117424 }
117425 if( pSample->n ){
@@ -118106,11 +118373,11 @@
118373 const char *zArg3
118374 ){
118375 sqlite3 *db = pParse->db;
118376 int rc;
118377
118378 /* Don't do any authorization checks if the database is initializing
118379 ** or if the parser is being invoked from within sqlite3_declare_vtab.
118380 */
118381 assert( !IN_RENAME_OBJECT || db->xAuth==0 );
118382 if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){
118383 return SQLITE_OK;
@@ -118928,11 +119195,11 @@
119195 pCol->colFlags |= COLFLAG_HASCOLL;
119196 }
119197 }
119198
119199 /*
119200 ** Return the collating sequence name for a column
119201 */
119202 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){
119203 const char *z;
119204 if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0;
119205 z = pCol->zCnName;
@@ -119686,11 +119953,11 @@
119953 sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
119954 return;
119955 }
119956 if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName);
119957
119958 /* Because keywords GENERATE ALWAYS can be converted into identifiers
119959 ** by the parser, we can sometimes end up with a typename that ends
119960 ** with "generated always". Check for this case and omit the surplus
119961 ** text. */
119962 if( sType.n>=16
119963 && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0
@@ -119907,11 +120174,11 @@
120174 */
120175 SQLITE_PRIVATE void sqlite3AddDefaultValue(
120176 Parse *pParse, /* Parsing context */
120177 Expr *pExpr, /* The parsed expression of the default value */
120178 const char *zStart, /* Start of the default value text */
120179 const char *zEnd /* First character past end of default value text */
120180 ){
120181 Table *p;
120182 Column *pCol;
120183 sqlite3 *db = pParse->db;
120184 p = pParse->pNewTable;
@@ -120255,11 +120522,11 @@
120522 ** which to write into the output buffer. This function copies the
120523 ** nul-terminated string pointed to by the third parameter, zSignedIdent,
120524 ** to the specified offset in the buffer and updates *pIdx to refer
120525 ** to the first byte after the last byte written before returning.
120526 **
120527 ** If the string zSignedIdent consists entirely of alphanumeric
120528 ** characters, does not begin with a digit and is not an SQL keyword,
120529 ** then it is copied to the output buffer exactly as it is. Otherwise,
120530 ** it is quoted using double-quotes.
120531 */
120532 static void identPut(char *z, int *pIdx, char *zSignedIdent){
@@ -120407,11 +120674,11 @@
120674 int i;
120675 const Column *aCol = pIdx->pTable->aCol;
120676 for(i=0; i<pIdx->nColumn; i++){
120677 i16 x = pIdx->aiColumn[i];
120678 assert( x<pIdx->pTable->nCol );
120679 wIndex += x<0 ? 1 : aCol[x].szEst;
120680 }
120681 pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
120682 }
120683
120684 /* Return true if column number x is any of the first nCol entries of aiCol[].
@@ -122145,11 +122412,11 @@
122412 assert( pName && pName->z );
122413
122414 #ifndef SQLITE_OMIT_TEMPDB
122415 /* If the index name was unqualified, check if the table
122416 ** is a temp table. If so, set the database to 1. Do not do this
122417 ** if initializing a database schema.
122418 */
122419 if( !db->init.busy ){
122420 pTab = sqlite3SrcListLookup(pParse, pTblName);
122421 if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){
122422 iDb = 1;
@@ -123802,11 +124069,11 @@
124069 sqlite3DbFree(db, pCte);
124070 }
124071
124072 /*
124073 ** This routine is invoked once per CTE by the parser while parsing a
124074 ** WITH clause. The CTE described by the third argument is added to
124075 ** the WITH clause of the second argument. If the second argument is
124076 ** NULL, then a new WITH argument is created.
124077 */
124078 SQLITE_PRIVATE With *sqlite3WithAdd(
124079 Parse *pParse, /* Parsing context */
@@ -124446,10 +124713,11 @@
124713 Table *pTab;
124714 assert( pItem && pSrc->nSrc>=1 );
124715 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
124716 sqlite3DeleteTable(pParse->db, pItem->pTab);
124717 pItem->pTab = pTab;
124718 pItem->fg.notCte = 1;
124719 if( pTab ){
124720 pTab->nTabRef++;
124721 if( pItem->fg.isIndexedBy && sqlite3IndexedByLookup(pParse, pItem) ){
124722 pTab = 0;
124723 }
@@ -124598,11 +124866,11 @@
124866 char *zStmtType /* Either DELETE or UPDATE. For err msgs. */
124867 ){
124868 sqlite3 *db = pParse->db;
124869 Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */
124870 Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */
124871 ExprList *pEList = NULL; /* Expression list containing only pSelectRowid*/
124872 SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */
124873 Select *pSelect = NULL; /* Complete SELECT tree */
124874 Table *pTab;
124875
124876 /* Check that there isn't an ORDER BY without a LIMIT clause.
@@ -124636,18 +124904,24 @@
124904 pEList = sqlite3ExprListAppend(
124905 pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0)
124906 );
124907 }else{
124908 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
124909 assert( pPk!=0 );
124910 assert( pPk->nKeyCol>=1 );
124911 if( pPk->nKeyCol==1 ){
124912 const char *zName;
124913 assert( pPk->aiColumn[0]>=0 && pPk->aiColumn[0]<pTab->nCol );
124914 zName = pTab->aCol[pPk->aiColumn[0]].zCnName;
124915 pLhs = sqlite3Expr(db, TK_ID, zName);
124916 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName));
124917 }else{
124918 int i;
124919 for(i=0; i<pPk->nKeyCol; i++){
124920 Expr *p;
124921 assert( pPk->aiColumn[i]>=0 && pPk->aiColumn[i]<pTab->nCol );
124922 p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName);
124923 pEList = sqlite3ExprListAppend(pParse, pEList, p);
124924 }
124925 pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
124926 if( pLhs ){
124927 pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0);
@@ -124672,11 +124946,11 @@
124946 /* generate the SELECT expression tree. */
124947 pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0,
124948 pOrderBy,0,pLimit
124949 );
124950
124951 /* now generate the new WHERE rowid IN clause for the DELETE/UPDATE */
124952 pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0);
124953 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
124954 return pInClause;
124955 }
124956 #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */
@@ -126057,11 +126331,11 @@
126331 u8 noCase; /* true to ignore case differences */
126332 };
126333
126334 /*
126335 ** For LIKE and GLOB matching on EBCDIC machines, assume that every
126336 ** character is exactly one byte in size. Also, provide the Utf8Read()
126337 ** macro for fast reading of the next character in the common case where
126338 ** the next character is ASCII.
126339 */
126340 #if defined(SQLITE_EBCDIC)
126341 # define sqlite3Utf8Read(A) (*((*A)++))
@@ -126290,11 +126564,11 @@
126564 #endif
126565
126566
126567 /*
126568 ** Implementation of the like() SQL function. This function implements
126569 ** the built-in LIKE operator. The first argument to the function is the
126570 ** pattern and the second argument is the string. So, the SQL statements:
126571 **
126572 ** A LIKE B
126573 **
126574 ** is implemented as like(B,A).
@@ -126676,11 +126950,11 @@
126950 ** two arguments. In both cases the first argument is interpreted as text
126951 ** a text value containing a set of pairs of hexadecimal digits which are
126952 ** decoded and returned as a blob.
126953 **
126954 ** If there is only a single argument, then it must consist only of an
126955 ** even number of hexadecimal digits. Otherwise, return NULL.
126956 **
126957 ** Or, if there is a second argument, then any character that appears in
126958 ** the second argument is also allowed to appear between pairs of hexadecimal
126959 ** digits in the first argument. If any other character appears in the
126960 ** first argument, or if one of the allowed characters appears between
@@ -127376,11 +127650,11 @@
127650 assert( argc==1 || argc==2 );
127651 (void)argc; /* Suppress unused parameter warning */
127652 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
127653 pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
127654 /* pGCC is always non-NULL since groupConcatStep() will have always
127655 ** run first to initialize it */
127656 if( ALWAYS(pGCC) ){
127657 int nVS;
127658 /* Must call sqlite3_value_text() to convert the argument into text prior
127659 ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
127660 (void)sqlite3_value_text(argv[0]);
@@ -129579,11 +129853,11 @@
129853 ** 'E' REAL
129854 **
129855 ** For STRICT tables:
129856 ** ------------------
129857 **
129858 ** Generate an appropriate OP_TypeCheck opcode that will verify the
129859 ** datatypes against the column definitions in pTab. If iReg==0, that
129860 ** means an OP_MakeRecord opcode has already been generated and should be
129861 ** the last opcode generated. The new OP_TypeCheck needs to be inserted
129862 ** before the OP_MakeRecord. The new OP_TypeCheck should use the same
129863 ** register set as the OP_MakeRecord. If iReg>0 then register iReg is
@@ -130871,11 +131145,11 @@
131145 #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */
131146
131147 /* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn().
131148 * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this
131149 ** expression node references any of the
131150 ** columns that are being modified by an UPDATE statement.
131151 */
131152 static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){
131153 if( pExpr->op==TK_COLUMN ){
131154 assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 );
131155 if( pExpr->iColumn>=0 ){
@@ -131094,11 +131368,11 @@
131368 int ignoreDest, /* Jump to this label on an OE_Ignore resolution */
131369 int *pbMayReplace, /* OUT: Set to true if constraint may cause a replace */
131370 int *aiChng, /* column i is unchanged if aiChng[i]<0 */
131371 Upsert *pUpsert /* ON CONFLICT clauses, if any. NULL otherwise */
131372 ){
131373 Vdbe *v; /* VDBE under construction */
131374 Index *pIdx; /* Pointer to one of the indices */
131375 Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */
131376 sqlite3 *db; /* Database connection */
131377 int i; /* loop counter */
131378 int ix; /* Index loop counter */
@@ -131577,11 +131851,11 @@
131851 */
131852 for(pIdx = indexIteratorFirst(&sIdxIter, &ix);
131853 pIdx;
131854 pIdx = indexIteratorNext(&sIdxIter, &ix)
131855 ){
131856 int regIdx; /* Range of registers holding content for pIdx */
131857 int regR; /* Range of registers holding conflicting PK */
131858 int iThisCur; /* Cursor for this UNIQUE index */
131859 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
131860 int addrConflictCk; /* First opcode in the conflict check logic */
131861
@@ -132393,11 +132667,11 @@
132667 if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
132668 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
132669 }
132670 #endif
132671 #ifndef SQLITE_OMIT_FOREIGN_KEY
132672 /* Disallow the transfer optimization if the destination table contains
132673 ** any foreign key constraints. This is more restrictive than necessary.
132674 ** But the main beneficiary of the transfer optimization is the VACUUM
132675 ** command, and the VACUUM command disables foreign key constraints. So
132676 ** the extra complication to make this rule less restrictive is probably
132677 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
@@ -134026,10 +134300,14 @@
134300 **
134301 ** Later (2023-03-25): Save an extra 6 bytes for the filename suffix.
134302 ** See https://sqlite.org/forum/forumpost/24083b579d.
134303 */
134304 if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found;
134305
134306 /* Do not allow sqlite3_load_extension() to link to a copy of the
134307 ** running application, by passing in an empty filename. */
134308 if( nMsg==0 ) goto extension_not_found;
134309
134310 handle = sqlite3OsDlOpen(pVfs, zFile);
134311 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
134312 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
134313 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
@@ -135859,11 +136137,11 @@
136137 ** PRAGMA cache_spill=BOOLEAN
136138 ** PRAGMA [schema.]cache_spill=N
136139 **
136140 ** The first form reports the current local setting for the
136141 ** page cache spill size. The second form turns cache spill on
136142 ** or off. When turning cache spill on, the size is set to the
136143 ** current cache_size. The third form sets a spill size that
136144 ** may be different form the cache size.
136145 ** If N is positive then that is the
136146 ** number of pages in the cache. If N is negative, then the
136147 ** number of pages is adjusted so that the cache uses -N kibibytes
@@ -136637,13 +136915,13 @@
136915 ** Verify the integrity of the database.
136916 **
136917 ** The "quick_check" is reduced version of
136918 ** integrity_check designed to detect most database corruption
136919 ** without the overhead of cross-checking indexes. Quick_check
136920 ** is linear time whereas integrity_check is O(NlogN).
136921 **
136922 ** The maximum number of errors is 100 by default. A different default
136923 ** can be specified using a numeric parameter N.
136924 **
136925 ** Or, the parameter N can be the name of a table. In that case, only
136926 ** the one table named is verified. The freelist is only verified if
136927 ** the named table is "sqlite_schema" (or one of its aliases).
@@ -137397,11 +137675,11 @@
137675 int iTabCur; /* Cursor for a table whose size needs checking */
137676 HashElem *k; /* Loop over tables of a schema */
137677 Schema *pSchema; /* The current schema */
137678 Table *pTab; /* A table in the schema */
137679 Index *pIdx; /* An index of the table */
137680 LogEst szThreshold; /* Size threshold above which reanalysis needed */
137681 char *zSubSql; /* SQL statement for the OP_SqlExec opcode */
137682 u32 opMask; /* Mask of operations to perform */
137683
137684 if( zRight ){
137685 opMask = (u32)sqlite3Atoi(zRight);
@@ -138523,11 +138801,11 @@
138801 ** Add a new cleanup operation to a Parser. The cleanup should happen when
138802 ** the parser object is destroyed. But, beware: the cleanup might happen
138803 ** immediately.
138804 **
138805 ** Use this mechanism for uncommon cleanups. There is a higher setup
138806 ** cost for this mechanism (an extra malloc), so it should not be used
138807 ** for common cleanups that happen on most calls. But for less
138808 ** common cleanups, we save a single NULL-pointer comparison in
138809 ** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
138810 **
138811 ** If a memory allocation error occurs, then the cleanup happens immediately.
@@ -139225,11 +139503,11 @@
139503 ** NATURAL RIGHT OUTER JT_NATURAL|JT_RIGHT|JT_OUTER
139504 ** NATURAL FULL - JT_NATURAL|JT_LEFT|JT_RIGHT
139505 ** NATURAL FULL OUTER JT_NATRUAL|JT_LEFT|JT_RIGHT
139506 **
139507 ** To preserve historical compatibly, SQLite also accepts a variety
139508 ** of other non-standard and in many cases nonsensical join types.
139509 ** This routine makes as much sense at it can from the nonsense join
139510 ** type and returns a result. Examples of accepted nonsense join types
139511 ** include but are not limited to:
139512 **
139513 ** INNER CROSS JOIN -> same as JOIN
@@ -139496,11 +139774,11 @@
139774 u32 joinType;
139775
139776 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
139777 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
139778
139779 /* If this is a NATURAL join, synthesize an appropriate USING clause
139780 ** to specify which columns should be joined.
139781 */
139782 if( pRight->fg.jointype & JT_NATURAL ){
139783 IdList *pUsing = 0;
139784 if( pRight->fg.isUsing || pRight->u3.pOn ){
@@ -139712,11 +139990,11 @@
139990 ** (2) All output columns are included in the sort record. In that
139991 ** case regData==regOrigData.
139992 ** (3) Some output columns are omitted from the sort record due to
139993 ** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the
139994 ** SQLITE_ECEL_OMITREF optimization, or due to the
139995 ** SortCtx.pDeferredRowLoad optimization. In any of these cases
139996 ** regOrigData is 0 to prevent this routine from trying to copy
139997 ** values that might not yet exist.
139998 */
139999 assert( nData==1 || regData==regOrigData || regOrigData==0 );
140000
@@ -139768,11 +140046,11 @@
140046 memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
140047 sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
140048 testcase( pKI->nAllField > pKI->nKeyField+2 );
140049 pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
140050 pKI->nAllField-pKI->nKeyField-1);
140051 pOp = 0; /* Ensure pOp not used after sqlite3VdbeAddOp3() */
140052 addrJmp = sqlite3VdbeCurrentAddr(v);
140053 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
140054 pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
140055 pSort->regReturn = ++pParse->nMem;
140056 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
@@ -139862,11 +140140,11 @@
140140 ** the ephemeral cursor and proceed.
140141 **
140142 ** The returned value in this case is a copy of parameter iTab.
140143 **
140144 ** WHERE_DISTINCT_ORDERED:
140145 ** In this case rows are being delivered sorted order. The ephemeral
140146 ** table is not required. Instead, the current set of values
140147 ** is compared against previous row. If they match, the new row
140148 ** is not distinct and control jumps to VM address addrRepeat. Otherwise,
140149 ** the VM program proceeds with processing the new row.
140150 **
@@ -141287,11 +141565,11 @@
141565 /*
141566 ** pTab is a transient Table object that represents a subquery of some
141567 ** kind (maybe a parenthesized subquery in the FROM clause of a larger
141568 ** query, or a VIEW, or a CTE). This routine computes type information
141569 ** for that Table object based on the Select object that implements the
141570 ** subquery. For the purposes of this routine, "type information" means:
141571 **
141572 ** * The datatype name, as it might appear in a CREATE TABLE statement
141573 ** * Which collating sequence to use for the column
141574 ** * The affinity of the column
141575 */
@@ -141616,11 +141894,11 @@
141894 int iCurrent = 0; /* The Current table */
141895 int regCurrent; /* Register holding Current table */
141896 int iQueue; /* The Queue table */
141897 int iDistinct = 0; /* To ensure unique results if UNION */
141898 int eDest = SRT_Fifo; /* How to write to Queue */
141899 SelectDest destQueue; /* SelectDest targeting the Queue table */
141900 int i; /* Loop counter */
141901 int rc; /* Result code */
141902 ExprList *pOrderBy; /* The ORDER BY clause */
141903 Expr *pLimit; /* Saved LIMIT and OFFSET */
141904 int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
@@ -142216,11 +142494,11 @@
142494 }
142495 }
142496
142497 /*
142498 ** Code an output subroutine for a coroutine implementation of a
142499 ** SELECT statement.
142500 **
142501 ** The data to be output is contained in pIn->iSdst. There are
142502 ** pIn->nSdst columns to be output. pDest is where the output should
142503 ** be sent.
142504 **
@@ -142438,11 +142716,11 @@
142716 ** Jump AltB, AeqB, AgtB
142717 ** End: ...
142718 **
142719 ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not
142720 ** actually called using Gosub and they do not Return. EofA and EofB loop
142721 ** until all data is exhausted then jump to the "end" label. AltB, AeqB,
142722 ** and AgtB jump to either L2 or to one of EofA or EofB.
142723 */
142724 #ifndef SQLITE_OMIT_COMPOUND_SELECT
142725 static int multiSelectOrderBy(
142726 Parse *pParse, /* Parsing context */
@@ -142475,11 +142753,11 @@
142753 int regPrev; /* A range of registers to hold previous output */
142754 int savedLimit; /* Saved value of p->iLimit */
142755 int savedOffset; /* Saved value of p->iOffset */
142756 int labelCmpr; /* Label for the start of the merge algorithm */
142757 int labelEnd; /* Label for the end of the overall SELECT stmt */
142758 int addr1; /* Jump instructions that get retargeted */
142759 int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */
142760 KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */
142761 KeyInfo *pKeyMerge; /* Comparison information for merging rows */
142762 sqlite3 *db; /* Database connection */
142763 ExprList *pOrderBy; /* The ORDER BY clause */
@@ -142844,15 +143122,18 @@
143122 pExpr->op = TK_NULL;
143123 }else
143124 #endif
143125 {
143126 Expr *pNew;
143127 int iColumn;
143128 Expr *pCopy;
143129 Expr ifNullRow;
143130 iColumn = pExpr->iColumn;
143131 assert( iColumn>=0 );
143132 assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr );
143133 assert( pExpr->pRight==0 );
143134 pCopy = pSubst->pEList->a[iColumn].pExpr;
143135 if( sqlite3ExprIsVector(pCopy) ){
143136 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
143137 }else{
143138 sqlite3 *db = pSubst->pParse->db;
143139 if( pSubst->isOuterJoin
@@ -143197,11 +143478,11 @@
143478 ** (8) If the subquery uses LIMIT then the outer query may not be a join.
143479 **
143480 ** (9) If the subquery uses LIMIT then the outer query may not be aggregate.
143481 **
143482 ** (**) Restriction (10) was removed from the code on 2005-02-05 but we
143483 ** accidentally carried the comment forward until 2014-09-15. Original
143484 ** constraint: "If the subquery is aggregate then the outer query
143485 ** may not use LIMIT."
143486 **
143487 ** (11) The subquery and the outer query may not both have ORDER BY clauses.
143488 **
@@ -143471,11 +143752,11 @@
143752 pParse->zAuthContext = pSubitem->zName;
143753 TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
143754 testcase( i==SQLITE_DENY );
143755 pParse->zAuthContext = zSavedAuthContext;
143756
143757 /* Delete the transient structures associated with the subquery */
143758 pSub1 = pSubitem->pSelect;
143759 sqlite3DbFree(db, pSubitem->zDatabase);
143760 sqlite3DbFree(db, pSubitem->zName);
143761 sqlite3DbFree(db, pSubitem->zAlias);
143762 pSubitem->zDatabase = 0;
@@ -143653,11 +143934,11 @@
143934 if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
143935 /* At this point, any non-zero iOrderByCol values indicate that the
143936 ** ORDER BY column expression is identical to the iOrderByCol'th
143937 ** expression returned by SELECT statement pSub. Since these values
143938 ** do not necessarily correspond to columns in SELECT statement pParent,
143939 ** zero them before transferring the ORDER BY clause.
143940 **
143941 ** Not doing this may cause an error if a subsequent call to this
143942 ** function attempts to flatten a compound sub-query into pParent
143943 ** (the only way this can happen is if the compound sub-query is
143944 ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */
@@ -143713,12 +143994,11 @@
143994 for(i=0; i<nSubSrc; i++){
143995 recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]);
143996 }
143997 }
143998
143999 /* Finally, delete what is left of the subquery and return success.
 
144000 */
144001 sqlite3AggInfoPersistWalkerInit(&w, pParse);
144002 sqlite3WalkSelect(&w,pSub1);
144003 sqlite3SelectDelete(db, pSub1);
144004
@@ -143749,11 +144029,11 @@
144029 Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */
144030 };
144031
144032 /*
144033 ** Add a new entry to the pConst object. Except, do not add duplicate
144034 ** pColumn entries. Also, do not add if doing so would not be appropriate.
144035 **
144036 ** The caller guarantees the pColumn is a column and pValue is a constant.
144037 ** This routine has to do some additional checks before completing the
144038 ** insert.
144039 */
@@ -143935,11 +144215,11 @@
144215 ** INSERT INTO t1 VALUES(123,'0123');
144216 ** SELECT * FROM t1 WHERE a=123 AND b=a;
144217 ** SELECT * FROM t1 WHERE a=123 AND b=123;
144218 **
144219 ** The two SELECT statements above should return different answers. b=a
144220 ** is always true because the comparison uses numeric affinity, but b=123
144221 ** is false because it uses text affinity and '0123' is not the same as '123'.
144222 ** To work around this, the expression tree is not actually changed from
144223 ** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol
144224 ** and the "123" value is hung off of the pLeft pointer. Code generator
144225 ** routines know to generate the constant "123" instead of looking up the
@@ -144019,11 +144299,11 @@
144299 ** this may change the results of the window functions.
144300 **
144301 ** At the time this function is called it is guaranteed that
144302 **
144303 ** * the sub-query uses only one distinct window frame, and
144304 ** * that the window frame has a PARTITION BY clause.
144305 */
144306 static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){
144307 assert( pSubq->pWin->pPartition );
144308 assert( (pSubq->selFlags & SF_MultiPart)==0 );
144309 assert( pSubq->pPrior==0 );
@@ -145527,11 +145807,11 @@
145807 assert( pExpr->iAgg>=0 );
145808 pCol = &pAggInfo->aCol[pExpr->iAgg];
145809 pExpr->op = TK_AGG_COLUMN;
145810 pExpr->iTable = pCol->iTable;
145811 pExpr->iColumn = pCol->iColumn;
145812 ExprClearProperty(pExpr, EP_Skip|EP_Collate|EP_Unlikely);
145813 return WRC_Prune;
145814 }
145815
145816 /*
145817 ** Convert every pAggInfo->aFunc[].pExpr such that any node within
@@ -145558,11 +145838,11 @@
145838 ** to calling this routine:
145839 **
145840 ** * The aCol[] and aFunc[] arrays may be modified
145841 ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used
145842 **
145843 ** After calling this routine:
145844 **
145845 ** * The aCol[] and aFunc[] arrays are fixed
145846 ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may be used
145847 **
145848 */
@@ -146212,26 +146492,63 @@
146492 /* The expander should have already created transient Table objects
146493 ** even for FROM clause elements such as subqueries that do not correspond
146494 ** to a real table */
146495 assert( pTab!=0 );
146496
146497 /* Try to simplify joins:
146498 **
146499 ** LEFT JOIN -> JOIN
146500 ** RIGHT JOIN -> JOIN
146501 ** FULL JOIN -> RIGHT JOIN
146502 **
146503 ** If terms of the i-th table are used in the WHERE clause in such a
146504 ** way that the i-th table cannot be the NULL row of a join, then
146505 ** perform the appropriate simplification. This is called
146506 ** "OUTER JOIN strength reduction" in the SQLite documentation.
146507 */
146508 if( (pItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
146509 && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor,
146510 pItem->fg.jointype & JT_LTORJ)
146511 && OptimizationEnabled(db, SQLITE_SimplifyJoin)
146512 ){
146513 if( pItem->fg.jointype & JT_LEFT ){
146514 if( pItem->fg.jointype & JT_RIGHT ){
146515 TREETRACE(0x1000,pParse,p,
146516 ("FULL-JOIN simplifies to RIGHT-JOIN on term %d\n",i));
146517 pItem->fg.jointype &= ~JT_LEFT;
146518 }else{
146519 TREETRACE(0x1000,pParse,p,
146520 ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
146521 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
146522 }
146523 }
146524 if( pItem->fg.jointype & JT_LTORJ ){
146525 for(j=i+1; j<pTabList->nSrc; j++){
146526 SrcItem *pI2 = &pTabList->a[j];
146527 if( pI2->fg.jointype & JT_RIGHT ){
146528 if( pI2->fg.jointype & JT_LEFT ){
146529 TREETRACE(0x1000,pParse,p,
146530 ("FULL-JOIN simplifies to LEFT-JOIN on term %d\n",j));
146531 pI2->fg.jointype &= ~JT_RIGHT;
146532 }else{
146533 TREETRACE(0x1000,pParse,p,
146534 ("RIGHT-JOIN simplifies to JOIN on term %d\n",j));
146535 pI2->fg.jointype &= ~(JT_RIGHT|JT_OUTER);
146536 }
146537 }
146538 }
146539 for(j=pTabList->nSrc-1; j>=i; j--){
146540 pTabList->a[j].fg.jointype &= ~JT_LTORJ;
146541 if( pTabList->a[j].fg.jointype & JT_RIGHT ) break;
146542 }
146543 }
146544 assert( pItem->iCursor>=0 );
146545 unsetJoinExpr(p->pWhere, pItem->iCursor,
146546 pTabList->a[0].fg.jointype & JT_LTORJ);
146547 }
146548
146549 /* No further action if this term of the FROM clause is not a subquery */
146550 if( pSub==0 ) continue;
146551
146552 /* Catch mismatch in the declared columns of a view and the number of
146553 ** columns in the SELECT on the RHS */
146554 if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -146481,11 +146798,11 @@
146798 sqlite3VdbeJumpHere(v, addrTop-1);
146799 sqlite3ClearTempRegCache(pParse);
146800 }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){
146801 /* This is a CTE for which materialization code has already been
146802 ** generated. Invoke the subroutine to compute the materialization,
146803 ** the make the pItem->iCursor be a copy of the ephemeral table that
146804 ** holds the result of the materialization. */
146805 CteUse *pCteUse = pItem->u2.pCteUse;
146806 sqlite3VdbeAddOp2(v, OP_Gosub, pCteUse->regRtn, pCteUse->addrM9e);
146807 if( pItem->iCursor!=pCteUse->iCur ){
146808 sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur);
@@ -146864,11 +147181,11 @@
147181 /* Processing for aggregates with GROUP BY is very different and
147182 ** much more complex than aggregates without a GROUP BY.
147183 */
147184 if( pGroupBy ){
147185 KeyInfo *pKeyInfo; /* Keying information for the group by clause */
147186 int addr1; /* A-vs-B comparison jump */
147187 int addrOutputRow; /* Start of subroutine that outputs a result row */
147188 int regOutputRow; /* Return address register for output subroutine */
147189 int addrSetAbort; /* Set the abort flag and return */
147190 int addrTopOfLoop; /* Top of the input loop */
147191 int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
@@ -149244,11 +149561,11 @@
149561 pSrc = sqlite3SrcListDup(db, pTabList, 0);
149562 pWhere2 = sqlite3ExprDup(db, pWhere, 0);
149563
149564 assert( pTabList->nSrc>1 );
149565 if( pSrc ){
149566 assert( pSrc->a[0].fg.notCte );
149567 pSrc->a[0].iCursor = -1;
149568 pSrc->a[0].pTab->nTabRef--;
149569 pSrc->a[0].pTab = 0;
149570 }
149571 if( pPk ){
@@ -150231,11 +150548,11 @@
150548 const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
150549 WhereInfo *pWInfo = 0;
150550 int nArg = 2 + pTab->nCol; /* Number of arguments to VUpdate */
150551 int regArg; /* First register in VUpdate arg array */
150552 int regRec; /* Register in which to assemble record */
150553 int regRowid; /* Register for ephemeral table rowid */
150554 int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */
150555 int aDummy[2]; /* Unused arg for sqlite3WhereOkOnePass() */
150556 int eOnePass; /* True to use onepass strategy */
150557 int addr; /* Address of OP_OpenEphemeral */
150558
@@ -150352,11 +150669,11 @@
150669 /* End the virtual table scan */
150670 if( pSrc->nSrc==1 ){
150671 sqlite3WhereEnd(pWInfo);
150672 }
150673
150674 /* Begin scanning through the ephemeral table. */
150675 addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v);
150676
150677 /* Extract arguments from the current row of the ephemeral table and
150678 ** invoke the VUpdate method. */
150679 for(i=0; i<nArg; i++){
@@ -150909,11 +151226,11 @@
151226 ** can be set to 'off' for this file, as it is not recovered if a crash
151227 ** occurs anyway. The integrity of the database is maintained by a
151228 ** (possibly synchronous) transaction opened on the main database before
151229 ** sqlite3BtreeCopyFile() is called.
151230 **
151231 ** An optimization would be to use a non-journaled pager.
151232 ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but
151233 ** that actually made the VACUUM run slower. Very little journalling
151234 ** actually occurs when doing a vacuum since the vacuum_db is initially
151235 ** empty. Only the journal header is written. Apparently it takes more
151236 ** time to parse and run the PRAGMA to turn journalling off than it does
@@ -151598,11 +151915,11 @@
151915 /* A slot for the record has already been allocated in the
151916 ** schema table. We just need to update that slot with all
151917 ** the information we've collected.
151918 **
151919 ** The VM register number pParse->regRowid holds the rowid of an
151920 ** entry in the sqlite_schema table that was created for this vtab
151921 ** by sqlite3StartTable().
151922 */
151923 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
151924 sqlite3NestedParse(pParse,
151925 "UPDATE %Q." LEGACY_SCHEMA_TABLE " "
@@ -152342,11 +152659,11 @@
152659 ** exists when this routine returns or if an attempt to create it failed
152660 ** and an error message was left in pParse.
152661 **
152662 ** An eponymous virtual table instance is one that is named after its
152663 ** module, and more importantly, does not require a CREATE VIRTUAL TABLE
152664 ** statement in order to come into existence. Eponymous virtual table
152665 ** instances always exist. They cannot be DROP-ed.
152666 **
152667 ** Any virtual table module for which xConnect and xCreate are the same
152668 ** method can have an eponymous virtual table instance.
152669 */
@@ -152533,11 +152850,11 @@
152850 typedef struct WhereMemBlock WhereMemBlock;
152851 typedef struct WhereRightJoin WhereRightJoin;
152852
152853 /*
152854 ** This object is a header on a block of allocated memory that will be
152855 ** automatically freed when its WInfo object is destructed.
152856 */
152857 struct WhereMemBlock {
152858 WhereMemBlock *pNext; /* Next block in the chain */
152859 u64 sz; /* Bytes of space */
152860 };
@@ -152594,11 +152911,11 @@
152911 int nIn; /* Number of entries in aInLoop[] */
152912 struct InLoop {
152913 int iCur; /* The VDBE cursor used by this IN operator */
152914 int addrInTop; /* Top of the IN loop */
152915 int iBase; /* Base register of multi-key index record */
152916 int nPrefix; /* Number of prior entries in the key */
152917 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
152918 } *aInLoop; /* Information about each nested IN operator */
152919 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
152920 Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */
152921 } u;
@@ -152844,11 +153161,11 @@
153161 u8 op; /* Split operator. TK_AND or TK_OR */
153162 u8 hasOr; /* True if any a[].eOperator is WO_OR */
153163 int nTerm; /* Number of terms */
153164 int nSlot; /* Number of entries in a[] */
153165 int nBase; /* Number of terms through the last non-Virtual */
153166 WhereTerm *a; /* Each a[] describes a term of the WHERE clause */
153167 #if defined(SQLITE_SMALL_STACK)
153168 WhereTerm aStatic[1]; /* Initial static space for a[] */
153169 #else
153170 WhereTerm aStatic[8]; /* Initial static space for a[] */
153171 #endif
@@ -153929,11 +154246,11 @@
154246 assert( pIdx!=0 );
154247
154248 /* Figure out how many memory cells we will need then allocate them.
154249 */
154250 regBase = pParse->nMem + 1;
154251 nReg = nEq + nExtraReg;
154252 pParse->nMem += nReg;
154253
154254 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
154255 assert( zAff!=0 || pParse->db->mallocFailed );
154256
@@ -153976,13 +154293,10 @@
154293 regBase = r1;
154294 }else{
154295 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
154296 }
154297 }
 
 
 
154298 if( pTerm->eOperator & WO_IN ){
154299 if( pTerm->pExpr->flags & EP_xIsSelect ){
154300 /* No affinity ever needs to be (or should be) applied to a value
154301 ** from the RHS of an "? IN (SELECT ...)" expression. The
154302 ** sqlite3FindInIndex() routine has already ensured that the
@@ -154121,11 +154435,11 @@
154435 ** the specified column into the new register, and
154436 **
154437 ** 2) transform the expression node to a TK_REGISTER node that reads
154438 ** from the newly populated register.
154439 **
154440 ** Also, if the node is a TK_COLUMN that does access the table identified
154441 ** by pCCurHint.iTabCur, and an index is being used (which we will
154442 ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into
154443 ** an access of the index rather than the original table.
154444 */
154445 static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){
@@ -154739,11 +155053,11 @@
155053 /* TK_LT */ OP_SeekLT,
155054 /* TK_GE */ OP_SeekGE
155055 };
155056 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
155057 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
155058 assert( TK_GE==TK_GT+3 ); /* ... is correct. */
155059
155060 assert( (pStart->wtFlags & TERM_VNULL)==0 );
155061 testcase( pStart->wtFlags & TERM_VIRTUAL );
155062 pX = pStart->pExpr;
155063 assert( pX!=0 );
@@ -155919,11 +156233,11 @@
156233 *************************************************************************
156234 ** This module contains C code that generates VDBE code used to process
156235 ** the WHERE clause of SQL statements.
156236 **
156237 ** This file was originally part of where.c but was split out to improve
156238 ** readability and editability. This file contains utility routines for
156239 ** analyzing Expr objects in the WHERE clause.
156240 */
156241 /* #include "sqliteInt.h" */
156242 /* #include "whereInt.h" */
156243
@@ -156708,11 +157022,11 @@
157022 }
157023 if( (chngToIN & sqlite3WhereGetMask(&pWInfo->sMaskSet,
157024 pOrTerm->leftCursor))==0 ){
157025 /* This term must be of the form t1.a==t2.b where t2 is in the
157026 ** chngToIN set but t1 is not. This term will be either preceded
157027 ** or followed by an inverted copy (t2.b==t1.a). Skip this term
157028 ** and use its inversion. */
157029 testcase( pOrTerm->wtFlags & TERM_COPIED );
157030 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
157031 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
157032 continue;
@@ -156970,12 +157284,12 @@
157284 ){
157285 WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */
157286 WhereTerm *pTerm; /* The term to be analyzed */
157287 WhereMaskSet *pMaskSet; /* Set of table index masks */
157288 Expr *pExpr; /* The expression to be analyzed */
157289 Bitmask prereqLeft; /* Prerequisites of the pExpr->pLeft */
157290 Bitmask prereqAll; /* Prerequisites of pExpr */
157291 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
157292 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
157293 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
157294 int noCase = 0; /* uppercase equivalent to lowercase */
157295 int op; /* Top-level operator. pExpr->op */
@@ -159532,11 +159846,11 @@
159846 ** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?;
159847 **
159848 ** Value pLoop->nOut is currently set to the estimated number of rows
159849 ** visited for scanning (a=? AND b=?). This function reduces that estimate
159850 ** by some factor to account for the (c BETWEEN ? AND ?) expression based
159851 ** on the stat4 data for the index. this scan will be performed multiple
159852 ** times (once for each (a,b) combination that matches a=?) is dealt with
159853 ** by the caller.
159854 **
159855 ** It does this by scanning through all stat4 samples, comparing values
159856 ** extracted from pLower and pUpper with the corresponding column in each
@@ -160287,11 +160601,11 @@
160601 /* whereLoopAddBtree() always generates and inserts the automatic index
160602 ** case first. Hence compatible candidate WhereLoops never have a larger
160603 ** rSetup. Call this SETUP-INVARIANT */
160604 assert( p->rSetup>=pTemplate->rSetup );
160605
160606 /* Any loop using an application-defined index (or PRIMARY KEY or
160607 ** UNIQUE constraint) with one or more == constraints is better
160608 ** than an automatic index. Unless it is a skip-scan. */
160609 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
160610 && (pTemplate->nSkip)==0
160611 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
@@ -160432,11 +160746,11 @@
160746 whereLoopInit(p);
160747 p->pNextLoop = 0;
160748 }else{
160749 /* We will be overwriting WhereLoop p[]. But before we do, first
160750 ** go through the rest of the list and delete any other entries besides
160751 ** p[] that are also supplanted by pTemplate */
160752 WhereLoop **ppTail = &p->pNextLoop;
160753 WhereLoop *pToDel;
160754 while( *ppTail ){
160755 ppTail = whereLoopFindLesser(ppTail, pTemplate);
160756 if( ppTail==0 ) break;
@@ -160632,11 +160946,11 @@
160946 }
160947 return i;
160948 }
160949
160950 /*
160951 ** Adjust the cost C by the costMult factor T. This only occurs if
160952 ** compiled with -DSQLITE_ENABLE_COSTMULT
160953 */
160954 #ifdef SQLITE_ENABLE_COSTMULT
160955 # define ApplyCostMultiplier(C,T) C += T
160956 #else
@@ -160659,11 +160973,11 @@
160973 WhereLoopBuilder *pBuilder, /* The WhereLoop factory */
160974 SrcItem *pSrc, /* FROM clause term being analyzed */
160975 Index *pProbe, /* An index on pSrc */
160976 LogEst nInMul /* log(Number of iterations due to IN) */
160977 ){
160978 WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyze context */
160979 Parse *pParse = pWInfo->pParse; /* Parsing context */
160980 sqlite3 *db = pParse->db; /* Database connection malloc context */
160981 WhereLoop *pNew; /* Template WhereLoop under construction */
160982 WhereTerm *pTerm; /* A WhereTerm under consideration */
160983 int opMask; /* Valid operators for constraints */
@@ -160969,11 +161283,11 @@
161283 ** seek only. Then, if this is a non-covering index, add the cost of
161284 ** visiting the rows in the main table. */
161285 assert( pSrc->pTab->szTabRow>0 );
161286 if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){
161287 /* The pProbe->szIdxRow is low for an IPK table since the interior
161288 ** pages are small. Thus szIdxRow gives a good estimate of seek cost.
161289 ** But the leaf pages are full-size, so pProbe->szIdxRow would badly
161290 ** under-estimate the scanning cost. */
161291 rCostIdx = pNew->nOut + 16;
161292 }else{
161293 rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow;
@@ -161314,11 +161628,11 @@
161628 ** performance of using an index is far better than the worst-case performance
161629 ** of a full table scan.
161630 */
161631 static int whereLoopAddBtree(
161632 WhereLoopBuilder *pBuilder, /* WHERE clause information */
161633 Bitmask mPrereq /* Extra prerequisites for using this table */
161634 ){
161635 WhereInfo *pWInfo; /* WHERE analysis context */
161636 Index *pProbe; /* An index we are evaluating */
161637 Index sPk; /* A fake index object for the primary key */
161638 LogEst aiRowEstPk[2]; /* The aiRowLogEst[] value for the sPk index */
@@ -161821,11 +162135,11 @@
162135 ** This routine depends on there being a HiddenIndexInfo structure immediately
162136 ** following the sqlite3_index_info structure.
162137 **
162138 ** Return a pointer to the collation name:
162139 **
162140 ** 1. If there is an explicit COLLATE operator on the constraint, return it.
162141 **
162142 ** 2. Else, if the column has an alternative collation, return that.
162143 **
162144 ** 3. Otherwise, return "BINARY".
162145 */
@@ -162885,11 +163199,11 @@
163199 aSortCost[isOrdered] = whereSortingCost(
163200 pWInfo, nRowEst, nOrderBy, isOrdered
163201 );
163202 }
163203 /* TUNING: Add a small extra penalty (3) to sorting as an
163204 ** extra encouragement to the query planner to select a plan
163205 ** where the rows emerge in the correct order without any sorting
163206 ** required. */
163207 rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3;
163208
163209 WHERETRACE(0x002,
@@ -163593,11 +163907,11 @@
163907 ** inner loops (or around the "..." if the test occurs within the inner-
163908 ** most loop)
163909 **
163910 ** OUTER JOINS
163911 **
163912 ** An outer join of tables t1 and t2 is conceptually coded as follows:
163913 **
163914 ** foreach row1 in t1 do
163915 ** flag = 0
163916 ** foreach row2 in t2 do
163917 ** start:
@@ -163748,11 +164062,11 @@
164062 }else{
164063 /* Assign a bit from the bitmask to every term in the FROM clause.
164064 **
164065 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
164066 **
164067 ** The rule of the previous sentence ensures that if X is the bitmask for
164068 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
164069 ** Knowing the bitmask for all tables to the left of a left join is
164070 ** important. Ticket #3015.
164071 **
164072 ** Note that bitmasks are created for all pTabList->nSrc tables in
@@ -164729,11 +165043,11 @@
165043 ** last_value(expr)
165044 ** nth_value(expr, N)
165045 **
165046 ** These are the same built-in window functions supported by Postgres.
165047 ** Although the behaviour of aggregate window functions (functions that
165048 ** can be used as either aggregates or window functions) allows them to
165049 ** be implemented using an API, built-in window functions are much more
165050 ** esoteric. Additionally, some window functions (e.g. nth_value())
165051 ** may only be implemented by caching the entire partition in memory.
165052 ** As such, some built-in window functions use the same API as aggregate
165053 ** window functions and some are implemented directly using VDBE
@@ -165259,11 +165573,11 @@
165573 ** linked list of WINDOW definitions for the current SELECT statement.
165574 ** Argument pFunc is the function definition just resolved and pWin
165575 ** is the Window object representing the associated OVER clause. This
165576 ** function updates the contents of pWin as follows:
165577 **
165578 ** * If the OVER clause referred to a named window (as in "max(x) OVER win"),
165579 ** search list pList for a matching WINDOW definition, and update pWin
165580 ** accordingly. If no such WINDOW clause can be found, leave an error
165581 ** in pParse.
165582 **
165583 ** * If the function is a built-in window function that requires the
@@ -165880,11 +166194,11 @@
166194 }
166195 return pWin;
166196 }
166197
166198 /*
166199 ** Window *pWin has just been created from a WINDOW clause. Token pBase
166200 ** is the base window. Earlier windows from the same WINDOW clause are
166201 ** stored in the linked list starting at pWin->pNextWin. This function
166202 ** either updates *pWin according to the base specification, or else
166203 ** leaves an error in pParse.
166204 */
@@ -166186,11 +166500,11 @@
166500 ** start,current,end
166501 ** Consider a window-frame similar to the following:
166502 **
166503 ** (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
166504 **
166505 ** The windows functions implementation caches the input rows in a temp
166506 ** table, sorted by "a, b" (it actually populates the cache lazily, and
166507 ** aggressively removes rows once they are no longer required, but that's
166508 ** a mere detail). It keeps three cursors open on the temp table. One
166509 ** (current) that points to the next row to return to the query engine
166510 ** once its window function values have been calculated. Another (end)
@@ -167195,11 +167509,11 @@
167509 ** RETURN_ROW
167510 ** }
167511 **
167512 ** For the most part, the patterns above are adapted to support UNBOUNDED by
167513 ** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and
167514 ** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING".
167515 ** This is optimized of course - branches that will never be taken and
167516 ** conditions that are always true are omitted from the VM code. The only
167517 ** exceptional case is:
167518 **
167519 ** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING
@@ -167474,11 +167788,11 @@
167788 s.eDelete = WINDOW_AGGINVERSE;
167789 break;
167790 }
167791
167792 /* Allocate registers for the array of values from the sub-query, the
167793 ** same values in record form, and the rowid used to insert said record
167794 ** into the ephemeral table. */
167795 regNew = pParse->nMem+1;
167796 pParse->nMem += nInput;
167797 regRecord = ++pParse->nMem;
167798 s.regRowid = ++pParse->nMem;
@@ -167715,11 +168029,12 @@
168029 #endif /* SQLITE_OMIT_WINDOWFUNC */
168030
168031 /************** End of window.c **********************************************/
168032 /************** Begin file parse.c *******************************************/
168033 /* This file is automatically generated by Lemon from input grammar
168034 ** source file "parse.y".
168035 */
168036 /*
168037 ** 2001-09-15
168038 **
168039 ** The author disclaims copyright to this source code. In place of
168040 ** a legal notice, here is a blessing:
@@ -167732,11 +168047,11 @@
168047 ** This file contains SQLite's SQL parser.
168048 **
168049 ** The canonical source code to this file ("parse.y") is a Lemon grammar
168050 ** file that specifies the input grammar and actions to take while parsing.
168051 ** That input file is processed by Lemon to generate a C-language
168052 ** implementation of a parser for the given grammar. You might be reading
168053 ** this comment as part of the translated C-code. Edits should be made
168054 ** to the original parse.y sources.
168055 */
168056
168057 /* #include "sqliteInt.h" */
@@ -174928,16 +175243,10 @@
175243
175244 /*
175245 ** Forward declarations of external module initializer functions
175246 ** for modules that need them.
175247 */
 
 
 
 
 
 
175248 #ifdef SQLITE_ENABLE_FTS5
175249 SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*);
175250 #endif
175251 #ifdef SQLITE_ENABLE_STMTVTAB
175252 SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*);
@@ -174946,16 +175255,10 @@
175255 /*
175256 ** An array of pointers to extension initializer functions for
175257 ** built-in extensions.
175258 */
175259 static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
 
 
 
 
 
 
175260 #ifdef SQLITE_ENABLE_FTS3
175261 sqlite3Fts3Init,
175262 #endif
175263 #ifdef SQLITE_ENABLE_FTS5
175264 sqlite3Fts5Init,
@@ -178204,11 +178507,11 @@
178507 ** 2 on off
178508 ** 1 off on
178509 ** 0 off off
178510 **
178511 ** Legacy behavior is 3 (double-quoted string literals are allowed anywhere)
178512 ** and so that is the default. But developers are encouraged to use
178513 ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible.
178514 */
178515 #if !defined(SQLITE_DQS)
178516 # define SQLITE_DQS 3
178517 #endif
@@ -178739,11 +179042,11 @@
179042 goto error_out;
179043 }
179044
179045 /* Find the column for which info is requested */
179046 if( zColumnName==0 ){
179047 /* Query for existence of table only */
179048 }else{
179049 for(iCol=0; iCol<pTab->nCol; iCol++){
179050 pCol = &pTab->aCol[iCol];
179051 if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
179052 break;
@@ -179179,11 +179482,11 @@
179482 **
179483 ** Set or clear a flag that indicates that the database file is always well-
179484 ** formed and never corrupt. This flag is clear by default, indicating that
179485 ** database files might have arbitrary corruption. Setting the flag during
179486 ** testing causes certain assert() statements in the code to be activated
179487 ** that demonstrate invariants on well-formed database files.
179488 */
179489 case SQLITE_TESTCTRL_NEVER_CORRUPT: {
179490 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
179491 break;
179492 }
@@ -179333,11 +179636,11 @@
179636 **
179637 ** "ptr" is a pointer to a u32.
179638 **
179639 ** op==0 Store the current sqlite3TreeTrace in *ptr
179640 ** op==1 Set sqlite3TreeTrace to the value *ptr
179641 ** op==2 Store the current sqlite3WhereTrace in *ptr
179642 ** op==3 Set sqlite3WhereTrace to the value *ptr
179643 */
179644 case SQLITE_TESTCTRL_TRACEFLAGS: {
179645 int opTrace = va_arg(ap, int);
179646 u32 *ptr = va_arg(ap, u32*);
@@ -179669,11 +179972,11 @@
179972 #endif /* SQLITE_OMIT_WAL */
179973 return rc;
179974 }
179975
179976 /*
179977 ** Open a read-transaction on the snapshot identified by pSnapshot.
179978 */
179979 SQLITE_API int sqlite3_snapshot_open(
179980 sqlite3 *db,
179981 const char *zDb,
179982 sqlite3_snapshot *pSnapshot
@@ -195704,10 +196007,11 @@
196007 memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING);
196008 }
196009
196010 for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){
196011 NodeReader reader;
196012 memset(&reader, 0, sizeof(reader));
196013 pNode = &pWriter->aNodeWriter[i];
196014
196015 if( pNode->block.a){
196016 rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n);
196017 while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader);
@@ -200348,11 +200652,11 @@
200652 }
200653 }
200654 }
200655
200656 /*
200657 ** Return a JsonNode and all its descendants as a JSON string.
200658 */
200659 static void jsonReturnJson(
200660 JsonNode *pNode, /* Node to return */
200661 sqlite3_context *pCtx, /* Return value for this function */
200662 sqlite3_value **aReplace /* Array of replacement values */
@@ -202420,11 +202724,11 @@
202724 UNUSED_PARAMETER(argc);
202725 UNUSED_PARAMETER(argv);
202726 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
202727 #ifdef NEVER
202728 /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
202729 ** always have been called to initialize it */
202730 if( NEVER(!pStr) ) return;
202731 #endif
202732 z = pStr->zBuf;
202733 for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){
202734 if( c=='"' ){
@@ -205011,11 +205315,24 @@
205315 break;
205316 }
205317 p->pInfo->nCoord = pRtree->nDim2;
205318 p->pInfo->anQueue = pCsr->anQueue;
205319 p->pInfo->mxLevel = pRtree->iDepth + 1;
205320 }else if( eType==SQLITE_INTEGER ){
205321 sqlite3_int64 iVal = sqlite3_value_int64(argv[ii]);
205322 #ifdef SQLITE_RTREE_INT_ONLY
205323 p->u.rValue = iVal;
205324 #else
205325 p->u.rValue = (double)iVal;
205326 if( iVal>=((sqlite3_int64)1)<<48
205327 || -iVal>=((sqlite3_int64)1)<<48
205328 ){
205329 if( p->op==RTREE_LT ) p->op = RTREE_LE;
205330 if( p->op==RTREE_GT ) p->op = RTREE_GE;
205331 }
205332 #endif
205333 }else if( eType==SQLITE_FLOAT ){
205334 #ifdef SQLITE_RTREE_INT_ONLY
205335 p->u.rValue = sqlite3_value_int64(argv[ii]);
205336 #else
205337 p->u.rValue = sqlite3_value_double(argv[ii]);
205338 #endif
@@ -205142,24 +205459,25 @@
205459 if( p->usable
205460 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
205461 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH)
205462 ){
205463 u8 op;
205464 u8 doOmit = 1;
205465 switch( p->op ){
205466 case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break;
205467 case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break;
205468 case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
205469 case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break;
205470 case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
205471 case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break;
205472 default: op = 0; break;
205473 }
205474 if( op ){
205475 zIdxStr[iIdx++] = op;
205476 zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
205477 pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
205478 pIdxInfo->aConstraintUsage[ii].omit = doOmit;
205479 }
205480 }
205481 }
205482
205483 pIdxInfo->idxNum = 2;
@@ -225250,11 +225568,12 @@
225568 #define FTS5_COMMA 13
225569 #define FTS5_PLUS 14
225570 #define FTS5_STAR 15
225571
225572 /* This file is automatically generated by Lemon from input grammar
225573 ** source file "fts5parse.y".
225574 */
225575 /*
225576 ** 2000-05-29
225577 **
225578 ** The author disclaims copyright to this source code. In place of
225579 ** a legal notice, here is a blessing:
@@ -237173,11 +237492,11 @@
237492 if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty));
237493 fts5DataRelease(pLeaf);
237494 pLeaf = 0;
237495 }else if( bDetailNone ){
237496 break;
237497 }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){
237498 p->rc = FTS5_CORRUPT;
237499 break;
237500 }else{
237501 int nShift = iNext - 4;
237502 int nPg;
@@ -237377,11 +237696,13 @@
237696 }else{
237697 if( iKey!=1 ){
237698 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix);
237699 }
237700 iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix);
237701 if( nPrefix2>pSeg->term.n ){
237702 p->rc = FTS5_CORRUPT;
237703 }else if( nPrefix2>nPrefix ){
237704 memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix);
237705 iOff += (nPrefix2-nPrefix);
237706 }
237707 memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2);
237708 iOff += nSuffix2;
@@ -242633,11 +242954,11 @@
242954 int nArg, /* Number of args */
242955 sqlite3_value **apUnused /* Function arguments */
242956 ){
242957 assert( nArg==0 );
242958 UNUSED_PARAM2(nArg, apUnused);
242959 sqlite3_result_text(pCtx, "fts5: 2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9", -1, SQLITE_TRANSIENT);
242960 }
242961
242962 /*
242963 ** Return true if zName is the extension on one of the shadow tables used
242964 ** by this module.
242965
+35 -20
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.42.0"
150
-#define SQLITE_VERSION_NUMBER 3042000
151
-#define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0"
149
+#define SQLITE_VERSION "3.43.0"
150
+#define SQLITE_VERSION_NUMBER 3043000
151
+#define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -1188,11 +1188,11 @@
11881188
** the database is not a wal-mode db, or if there is no such connection in any
11891189
** other process. This opcode cannot be used to detect transactions opened
11901190
** by clients within the current process, only within other processes.
11911191
**
11921192
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1193
-** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the
1193
+** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
11941194
** [checksum VFS shim] only.
11951195
**
11961196
** <li>[[SQLITE_FCNTL_RESET_CACHE]]
11971197
** If there is currently no transaction open on the database, and the
11981198
** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
@@ -2452,11 +2452,11 @@
24522452
** 3.0.0.
24532453
** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
24542454
** the [VACUUM] command will fail with an obscure error when attempting to
24552455
** process a table with generated columns and a descending index. This is
24562456
** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2457
-** either generated columns or decending indexes.
2457
+** either generated columns or descending indexes.
24582458
** </dd>
24592459
**
24602460
** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
24612461
** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
24622462
** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
@@ -2733,10 +2733,11 @@
27332733
** SQL statements is a no-op and has no effect on SQL statements
27342734
** that are started after the sqlite3_interrupt() call returns.
27352735
**
27362736
** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
27372737
** or not an interrupt is currently in effect for [database connection] D.
2738
+** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
27382739
*/
27392740
SQLITE_API void sqlite3_interrupt(sqlite3*);
27402741
SQLITE_API int sqlite3_is_interrupted(sqlite3*);
27412742
27422743
/*
@@ -3386,12 +3387,14 @@
33863387
** and context pointer P. ^If the X callback is
33873388
** NULL or if the M mask is zero, then tracing is disabled. The
33883389
** M argument should be the bitwise OR-ed combination of
33893390
** zero or more [SQLITE_TRACE] constants.
33903391
**
3391
-** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
3392
-** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
3392
+** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3393
+** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3394
+** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each
3395
+** database connection may have at most one trace callback.
33933396
**
33943397
** ^The X callback is invoked whenever any of the events identified by
33953398
** mask M occur. ^The integer return value from the callback is currently
33963399
** ignored, though this may change in future releases. Callback
33973400
** implementations should return zero to ensure future compatibility.
@@ -3756,11 +3759,11 @@
37563759
**
37573760
** The first parameter to these interfaces (hereafter referred to
37583761
** as F) must be one of:
37593762
** <ul>
37603763
** <li> A database filename pointer created by the SQLite core and
3761
-** passed into the xOpen() method of a VFS implemention, or
3764
+** passed into the xOpen() method of a VFS implementation, or
37623765
** <li> A filename obtained from [sqlite3_db_filename()], or
37633766
** <li> A new filename constructed using [sqlite3_create_filename()].
37643767
** </ul>
37653768
** If the F parameter is not one of the above, then the behavior is
37663769
** undefined and probably undesirable. Older versions of SQLite were
@@ -3869,11 +3872,11 @@
38693872
SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
38703873
38713874
/*
38723875
** CAPI3REF: Create and Destroy VFS Filenames
38733876
**
3874
-** These interfces are provided for use by [VFS shim] implementations and
3877
+** These interfaces are provided for use by [VFS shim] implementations and
38753878
** are not useful outside of that context.
38763879
**
38773880
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
38783881
** database filename D with corresponding journal file J and WAL file W and
38793882
** with N URI parameters key/values pairs in the array P. The result from
@@ -4579,11 +4582,11 @@
45794582
** These three options exist:
45804583
** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
45814584
** with it may be passed. ^It is called to dispose of the BLOB or string even
45824585
** if the call to the bind API fails, except the destructor is not called if
45834586
** the third parameter is a NULL pointer or the fourth parameter is negative.
4584
-** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
4587
+** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
45854588
** the application remains responsible for disposing of the object. ^In this
45864589
** case, the object and the provided pointer to it must remain valid until
45874590
** either the prepared statement is finalized or the same SQL parameter is
45884591
** bound to something else, whichever occurs sooner.
45894592
** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
@@ -5258,18 +5261,30 @@
52585261
** Use [sqlite3_clear_bindings()] to reset the bindings.
52595262
**
52605263
** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
52615264
** back to the beginning of its program.
52625265
**
5263
-** ^If the most recent call to [sqlite3_step(S)] for the
5264
-** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
5265
-** or if [sqlite3_step(S)] has never before been called on S,
5266
-** then [sqlite3_reset(S)] returns [SQLITE_OK].
5266
+** ^The return code from [sqlite3_reset(S)] indicates whether or not
5267
+** the previous evaluation of prepared statement S completed successfully.
5268
+** ^If [sqlite3_step(S)] has never before been called on S or if
5269
+** [sqlite3_step(S)] has not been called since the previous call
5270
+** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return
5271
+** [SQLITE_OK].
52675272
**
52685273
** ^If the most recent call to [sqlite3_step(S)] for the
52695274
** [prepared statement] S indicated an error, then
52705275
** [sqlite3_reset(S)] returns an appropriate [error code].
5276
+** ^The [sqlite3_reset(S)] interface might also return an [error code]
5277
+** if there were no prior errors but the process of resetting
5278
+** the prepared statement caused a new error. ^For example, if an
5279
+** [INSERT] statement with a [RETURNING] clause is only stepped one time,
5280
+** that one call to [sqlite3_step(S)] might return SQLITE_ROW but
5281
+** the overall statement might still fail and the [sqlite3_reset(S)] call
5282
+** might return SQLITE_BUSY if locking constraints prevent the
5283
+** database change from committing. Therefore, it is important that
5284
+** applications check the return code from [sqlite3_reset(S)] even if
5285
+** no prior call to [sqlite3_step(S)] indicated a problem.
52715286
**
52725287
** ^The [sqlite3_reset(S)] interface does not change the values
52735288
** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
52745289
*/
52755290
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
@@ -5482,11 +5497,11 @@
54825497
** <p>
54835498
** The SQLITE_DIRECTONLY flag is recommended for any
54845499
** [application-defined SQL function]
54855500
** that has side-effects or that could potentially leak sensitive information.
54865501
** This will prevent attacks in which an application is tricked
5487
-** into using a database file that has had its schema surreptiously
5502
+** into using a database file that has had its schema surreptitiously
54885503
** modified to invoke the application-defined function in ways that are
54895504
** harmful.
54905505
** <p>
54915506
** Some people say it is good practice to set SQLITE_DIRECTONLY on all
54925507
** [application-defined SQL functions], regardless of whether or not they
@@ -9191,12 +9206,12 @@
91919206
** ^(There may be at most one unlock-notify callback registered by a
91929207
** blocked connection. If sqlite3_unlock_notify() is called when the
91939208
** blocked connection already has a registered unlock-notify callback,
91949209
** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
91959210
** called with a NULL pointer as its second argument, then any existing
9196
-** unlock-notify callback is canceled. ^The blocked connections
9197
-** unlock-notify callback may also be canceled by closing the blocked
9211
+** unlock-notify callback is cancelled. ^The blocked connections
9212
+** unlock-notify callback may also be cancelled by closing the blocked
91989213
** connection using [sqlite3_close()].
91999214
**
92009215
** The unlock-notify callback is not reentrant. If an application invokes
92019216
** any sqlite3_xxx API functions from within an unlock-notify callback, a
92029217
** crash or deadlock may be the result.
@@ -9615,11 +9630,11 @@
96159630
** </dd>
96169631
**
96179632
** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
96189633
** <dd>Calls of the form
96199634
** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9620
-** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9635
+** the [xConnect] or [xCreate] methods of a [virtual table] implementation
96219636
** prohibits that virtual table from being used from within triggers and
96229637
** views.
96239638
** </dd>
96249639
**
96259640
** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
@@ -9805,11 +9820,11 @@
98059820
** ^(A constraint on a virtual table of the form
98069821
** "[IN operator|column IN (...)]" is
98079822
** communicated to the xBestIndex method as a
98089823
** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
98099824
** this constraint, it must set the corresponding
9810
-** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9825
+** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under
98119826
** the usual mode of handling IN operators, SQLite generates [bytecode]
98129827
** that invokes the [xFilter|xFilter() method] once for each value
98139828
** on the right-hand side of the IN operator.)^ Thus the virtual table
98149829
** only sees a single value from the right-hand side of the IN operator
98159830
** at a time.
@@ -10234,11 +10249,11 @@
1023410249
** triggers; and so forth.
1023510250
**
1023610251
** When the [sqlite3_blob_write()] API is used to update a blob column,
1023710252
** the pre-update hook is invoked with SQLITE_DELETE. This is because the
1023810253
** in this case the new values are not available. In this case, when a
10239
-** callback made with op==SQLITE_DELETE is actuall a write using the
10254
+** callback made with op==SQLITE_DELETE is actually a write using the
1024010255
** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
1024110256
** the index of the column being written. In other cases, where the
1024210257
** pre-update hook is being invoked for some other reason, including a
1024310258
** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
1024410259
**
1024510260
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.42.0"
150 #define SQLITE_VERSION_NUMBER 3042000
151 #define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -1188,11 +1188,11 @@
1188 ** the database is not a wal-mode db, or if there is no such connection in any
1189 ** other process. This opcode cannot be used to detect transactions opened
1190 ** by clients within the current process, only within other processes.
1191 **
1192 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1193 ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the
1194 ** [checksum VFS shim] only.
1195 **
1196 ** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1197 ** If there is currently no transaction open on the database, and the
1198 ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
@@ -2452,11 +2452,11 @@
2452 ** 3.0.0.
2453 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2454 ** the [VACUUM] command will fail with an obscure error when attempting to
2455 ** process a table with generated columns and a descending index. This is
2456 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2457 ** either generated columns or decending indexes.
2458 ** </dd>
2459 **
2460 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2461 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2462 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
@@ -2733,10 +2733,11 @@
2733 ** SQL statements is a no-op and has no effect on SQL statements
2734 ** that are started after the sqlite3_interrupt() call returns.
2735 **
2736 ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2737 ** or not an interrupt is currently in effect for [database connection] D.
 
2738 */
2739 SQLITE_API void sqlite3_interrupt(sqlite3*);
2740 SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2741
2742 /*
@@ -3386,12 +3387,14 @@
3386 ** and context pointer P. ^If the X callback is
3387 ** NULL or if the M mask is zero, then tracing is disabled. The
3388 ** M argument should be the bitwise OR-ed combination of
3389 ** zero or more [SQLITE_TRACE] constants.
3390 **
3391 ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
3392 ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
 
 
3393 **
3394 ** ^The X callback is invoked whenever any of the events identified by
3395 ** mask M occur. ^The integer return value from the callback is currently
3396 ** ignored, though this may change in future releases. Callback
3397 ** implementations should return zero to ensure future compatibility.
@@ -3756,11 +3759,11 @@
3756 **
3757 ** The first parameter to these interfaces (hereafter referred to
3758 ** as F) must be one of:
3759 ** <ul>
3760 ** <li> A database filename pointer created by the SQLite core and
3761 ** passed into the xOpen() method of a VFS implemention, or
3762 ** <li> A filename obtained from [sqlite3_db_filename()], or
3763 ** <li> A new filename constructed using [sqlite3_create_filename()].
3764 ** </ul>
3765 ** If the F parameter is not one of the above, then the behavior is
3766 ** undefined and probably undesirable. Older versions of SQLite were
@@ -3869,11 +3872,11 @@
3869 SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
3870
3871 /*
3872 ** CAPI3REF: Create and Destroy VFS Filenames
3873 **
3874 ** These interfces are provided for use by [VFS shim] implementations and
3875 ** are not useful outside of that context.
3876 **
3877 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
3878 ** database filename D with corresponding journal file J and WAL file W and
3879 ** with N URI parameters key/values pairs in the array P. The result from
@@ -4579,11 +4582,11 @@
4579 ** These three options exist:
4580 ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4581 ** with it may be passed. ^It is called to dispose of the BLOB or string even
4582 ** if the call to the bind API fails, except the destructor is not called if
4583 ** the third parameter is a NULL pointer or the fourth parameter is negative.
4584 ** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
4585 ** the application remains responsible for disposing of the object. ^In this
4586 ** case, the object and the provided pointer to it must remain valid until
4587 ** either the prepared statement is finalized or the same SQL parameter is
4588 ** bound to something else, whichever occurs sooner.
4589 ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
@@ -5258,18 +5261,30 @@
5258 ** Use [sqlite3_clear_bindings()] to reset the bindings.
5259 **
5260 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
5261 ** back to the beginning of its program.
5262 **
5263 ** ^If the most recent call to [sqlite3_step(S)] for the
5264 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
5265 ** or if [sqlite3_step(S)] has never before been called on S,
5266 ** then [sqlite3_reset(S)] returns [SQLITE_OK].
 
 
5267 **
5268 ** ^If the most recent call to [sqlite3_step(S)] for the
5269 ** [prepared statement] S indicated an error, then
5270 ** [sqlite3_reset(S)] returns an appropriate [error code].
 
 
 
 
 
 
 
 
 
 
5271 **
5272 ** ^The [sqlite3_reset(S)] interface does not change the values
5273 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
5274 */
5275 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
@@ -5482,11 +5497,11 @@
5482 ** <p>
5483 ** The SQLITE_DIRECTONLY flag is recommended for any
5484 ** [application-defined SQL function]
5485 ** that has side-effects or that could potentially leak sensitive information.
5486 ** This will prevent attacks in which an application is tricked
5487 ** into using a database file that has had its schema surreptiously
5488 ** modified to invoke the application-defined function in ways that are
5489 ** harmful.
5490 ** <p>
5491 ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5492 ** [application-defined SQL functions], regardless of whether or not they
@@ -9191,12 +9206,12 @@
9191 ** ^(There may be at most one unlock-notify callback registered by a
9192 ** blocked connection. If sqlite3_unlock_notify() is called when the
9193 ** blocked connection already has a registered unlock-notify callback,
9194 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9195 ** called with a NULL pointer as its second argument, then any existing
9196 ** unlock-notify callback is canceled. ^The blocked connections
9197 ** unlock-notify callback may also be canceled by closing the blocked
9198 ** connection using [sqlite3_close()].
9199 **
9200 ** The unlock-notify callback is not reentrant. If an application invokes
9201 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9202 ** crash or deadlock may be the result.
@@ -9615,11 +9630,11 @@
9615 ** </dd>
9616 **
9617 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9618 ** <dd>Calls of the form
9619 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9620 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9621 ** prohibits that virtual table from being used from within triggers and
9622 ** views.
9623 ** </dd>
9624 **
9625 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
@@ -9805,11 +9820,11 @@
9805 ** ^(A constraint on a virtual table of the form
9806 ** "[IN operator|column IN (...)]" is
9807 ** communicated to the xBestIndex method as a
9808 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9809 ** this constraint, it must set the corresponding
9810 ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under
9811 ** the usual mode of handling IN operators, SQLite generates [bytecode]
9812 ** that invokes the [xFilter|xFilter() method] once for each value
9813 ** on the right-hand side of the IN operator.)^ Thus the virtual table
9814 ** only sees a single value from the right-hand side of the IN operator
9815 ** at a time.
@@ -10234,11 +10249,11 @@
10234 ** triggers; and so forth.
10235 **
10236 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10237 ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10238 ** in this case the new values are not available. In this case, when a
10239 ** callback made with op==SQLITE_DELETE is actuall a write using the
10240 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10241 ** the index of the column being written. In other cases, where the
10242 ** pre-update hook is being invoked for some other reason, including a
10243 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10244 **
10245
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.43.0"
150 #define SQLITE_VERSION_NUMBER 3043000
151 #define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -1188,11 +1188,11 @@
1188 ** the database is not a wal-mode db, or if there is no such connection in any
1189 ** other process. This opcode cannot be used to detect transactions opened
1190 ** by clients within the current process, only within other processes.
1191 **
1192 ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1193 ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
1194 ** [checksum VFS shim] only.
1195 **
1196 ** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1197 ** If there is currently no transaction open on the database, and the
1198 ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
@@ -2452,11 +2452,11 @@
2452 ** 3.0.0.
2453 ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2454 ** the [VACUUM] command will fail with an obscure error when attempting to
2455 ** process a table with generated columns and a descending index. This is
2456 ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2457 ** either generated columns or descending indexes.
2458 ** </dd>
2459 **
2460 ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2461 ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2462 ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
@@ -2733,10 +2733,11 @@
2733 ** SQL statements is a no-op and has no effect on SQL statements
2734 ** that are started after the sqlite3_interrupt() call returns.
2735 **
2736 ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2737 ** or not an interrupt is currently in effect for [database connection] D.
2738 ** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
2739 */
2740 SQLITE_API void sqlite3_interrupt(sqlite3*);
2741 SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2742
2743 /*
@@ -3386,12 +3387,14 @@
3387 ** and context pointer P. ^If the X callback is
3388 ** NULL or if the M mask is zero, then tracing is disabled. The
3389 ** M argument should be the bitwise OR-ed combination of
3390 ** zero or more [SQLITE_TRACE] constants.
3391 **
3392 ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3393 ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3394 ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each
3395 ** database connection may have at most one trace callback.
3396 **
3397 ** ^The X callback is invoked whenever any of the events identified by
3398 ** mask M occur. ^The integer return value from the callback is currently
3399 ** ignored, though this may change in future releases. Callback
3400 ** implementations should return zero to ensure future compatibility.
@@ -3756,11 +3759,11 @@
3759 **
3760 ** The first parameter to these interfaces (hereafter referred to
3761 ** as F) must be one of:
3762 ** <ul>
3763 ** <li> A database filename pointer created by the SQLite core and
3764 ** passed into the xOpen() method of a VFS implementation, or
3765 ** <li> A filename obtained from [sqlite3_db_filename()], or
3766 ** <li> A new filename constructed using [sqlite3_create_filename()].
3767 ** </ul>
3768 ** If the F parameter is not one of the above, then the behavior is
3769 ** undefined and probably undesirable. Older versions of SQLite were
@@ -3869,11 +3872,11 @@
3872 SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
3873
3874 /*
3875 ** CAPI3REF: Create and Destroy VFS Filenames
3876 **
3877 ** These interfaces are provided for use by [VFS shim] implementations and
3878 ** are not useful outside of that context.
3879 **
3880 ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
3881 ** database filename D with corresponding journal file J and WAL file W and
3882 ** with N URI parameters key/values pairs in the array P. The result from
@@ -4579,11 +4582,11 @@
4582 ** These three options exist:
4583 ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4584 ** with it may be passed. ^It is called to dispose of the BLOB or string even
4585 ** if the call to the bind API fails, except the destructor is not called if
4586 ** the third parameter is a NULL pointer or the fourth parameter is negative.
4587 ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
4588 ** the application remains responsible for disposing of the object. ^In this
4589 ** case, the object and the provided pointer to it must remain valid until
4590 ** either the prepared statement is finalized or the same SQL parameter is
4591 ** bound to something else, whichever occurs sooner.
4592 ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
@@ -5258,18 +5261,30 @@
5261 ** Use [sqlite3_clear_bindings()] to reset the bindings.
5262 **
5263 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
5264 ** back to the beginning of its program.
5265 **
5266 ** ^The return code from [sqlite3_reset(S)] indicates whether or not
5267 ** the previous evaluation of prepared statement S completed successfully.
5268 ** ^If [sqlite3_step(S)] has never before been called on S or if
5269 ** [sqlite3_step(S)] has not been called since the previous call
5270 ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return
5271 ** [SQLITE_OK].
5272 **
5273 ** ^If the most recent call to [sqlite3_step(S)] for the
5274 ** [prepared statement] S indicated an error, then
5275 ** [sqlite3_reset(S)] returns an appropriate [error code].
5276 ** ^The [sqlite3_reset(S)] interface might also return an [error code]
5277 ** if there were no prior errors but the process of resetting
5278 ** the prepared statement caused a new error. ^For example, if an
5279 ** [INSERT] statement with a [RETURNING] clause is only stepped one time,
5280 ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but
5281 ** the overall statement might still fail and the [sqlite3_reset(S)] call
5282 ** might return SQLITE_BUSY if locking constraints prevent the
5283 ** database change from committing. Therefore, it is important that
5284 ** applications check the return code from [sqlite3_reset(S)] even if
5285 ** no prior call to [sqlite3_step(S)] indicated a problem.
5286 **
5287 ** ^The [sqlite3_reset(S)] interface does not change the values
5288 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
5289 */
5290 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
@@ -5482,11 +5497,11 @@
5497 ** <p>
5498 ** The SQLITE_DIRECTONLY flag is recommended for any
5499 ** [application-defined SQL function]
5500 ** that has side-effects or that could potentially leak sensitive information.
5501 ** This will prevent attacks in which an application is tricked
5502 ** into using a database file that has had its schema surreptitiously
5503 ** modified to invoke the application-defined function in ways that are
5504 ** harmful.
5505 ** <p>
5506 ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5507 ** [application-defined SQL functions], regardless of whether or not they
@@ -9191,12 +9206,12 @@
9206 ** ^(There may be at most one unlock-notify callback registered by a
9207 ** blocked connection. If sqlite3_unlock_notify() is called when the
9208 ** blocked connection already has a registered unlock-notify callback,
9209 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9210 ** called with a NULL pointer as its second argument, then any existing
9211 ** unlock-notify callback is cancelled. ^The blocked connections
9212 ** unlock-notify callback may also be cancelled by closing the blocked
9213 ** connection using [sqlite3_close()].
9214 **
9215 ** The unlock-notify callback is not reentrant. If an application invokes
9216 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9217 ** crash or deadlock may be the result.
@@ -9615,11 +9630,11 @@
9630 ** </dd>
9631 **
9632 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9633 ** <dd>Calls of the form
9634 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9635 ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
9636 ** prohibits that virtual table from being used from within triggers and
9637 ** views.
9638 ** </dd>
9639 **
9640 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
@@ -9805,11 +9820,11 @@
9820 ** ^(A constraint on a virtual table of the form
9821 ** "[IN operator|column IN (...)]" is
9822 ** communicated to the xBestIndex method as a
9823 ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use
9824 ** this constraint, it must set the corresponding
9825 ** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under
9826 ** the usual mode of handling IN operators, SQLite generates [bytecode]
9827 ** that invokes the [xFilter|xFilter() method] once for each value
9828 ** on the right-hand side of the IN operator.)^ Thus the virtual table
9829 ** only sees a single value from the right-hand side of the IN operator
9830 ** at a time.
@@ -10234,11 +10249,11 @@
10249 ** triggers; and so forth.
10250 **
10251 ** When the [sqlite3_blob_write()] API is used to update a blob column,
10252 ** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10253 ** in this case the new values are not available. In this case, when a
10254 ** callback made with op==SQLITE_DELETE is actually a write using the
10255 ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10256 ** the index of the column being written. In other cases, where the
10257 ** pre-update hook is being invoked for some other reason, including a
10258 ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10259 **
10260

Keyboard Shortcuts

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