Fossil SCM

Update the built-in SQLite to the latest 3.34.0 alpha that includes support for the sqlite3_txn_state() interface, with an eye toward using sqlite3_txn_state() to help prevent "busy" errors coming from high-load Fossil servers.

drh 2020-08-26 14:46 trunk
Commit e3ca34cb382aef5e8a6d2f889f0a600b77c5ecba38d0efac61fb62679607ca9e
3 files changed +12 -3 +223 -110 +57 -3
+12 -3
--- src/shell.c
+++ src/shell.c
@@ -18546,13 +18546,20 @@
1854618546
if( nArg!=2 ){
1854718547
raw_printf(stderr, "Usage: .read FILE\n");
1854818548
rc = 1;
1854918549
goto meta_command_exit;
1855018550
}
18551
- if( notNormalFile(azArg[1])
18552
- || (p->in = fopen(azArg[1], "rb"))==0
18553
- ){
18551
+ if( azArg[1][0]=='|' ){
18552
+ p->in = popen(azArg[1]+1, "r");
18553
+ if( p->in==0 ){
18554
+ utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
18555
+ rc = 1;
18556
+ }else{
18557
+ rc = process_input(p);
18558
+ pclose(p->in);
18559
+ }
18560
+ }else if( notNormalFile(azArg[1]) || (p->in = fopen(azArg[1], "rb"))==0 ){
1855418561
utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
1855518562
rc = 1;
1855618563
}else{
1855718564
rc = process_input(p);
1855818565
fclose(p->in);
@@ -20599,10 +20606,12 @@
2059920606
data.mode = MODE_Html;
2060020607
}else if( strcmp(z,"-list")==0 ){
2060120608
data.mode = MODE_List;
2060220609
}else if( strcmp(z,"-quote")==0 ){
2060320610
data.mode = MODE_Quote;
20611
+ sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator, SEP_Comma);
20612
+ sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator, SEP_Row);
2060420613
}else if( strcmp(z,"-line")==0 ){
2060520614
data.mode = MODE_Line;
2060620615
}else if( strcmp(z,"-column")==0 ){
2060720616
data.mode = MODE_Column;
2060820617
}else if( strcmp(z,"-json")==0 ){
2060920618
--- src/shell.c
+++ src/shell.c
@@ -18546,13 +18546,20 @@
18546 if( nArg!=2 ){
18547 raw_printf(stderr, "Usage: .read FILE\n");
18548 rc = 1;
18549 goto meta_command_exit;
18550 }
18551 if( notNormalFile(azArg[1])
18552 || (p->in = fopen(azArg[1], "rb"))==0
18553 ){
 
 
 
 
 
 
 
18554 utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
18555 rc = 1;
18556 }else{
18557 rc = process_input(p);
18558 fclose(p->in);
@@ -20599,10 +20606,12 @@
20599 data.mode = MODE_Html;
20600 }else if( strcmp(z,"-list")==0 ){
20601 data.mode = MODE_List;
20602 }else if( strcmp(z,"-quote")==0 ){
20603 data.mode = MODE_Quote;
 
 
20604 }else if( strcmp(z,"-line")==0 ){
20605 data.mode = MODE_Line;
20606 }else if( strcmp(z,"-column")==0 ){
20607 data.mode = MODE_Column;
20608 }else if( strcmp(z,"-json")==0 ){
20609
--- src/shell.c
+++ src/shell.c
@@ -18546,13 +18546,20 @@
18546 if( nArg!=2 ){
18547 raw_printf(stderr, "Usage: .read FILE\n");
18548 rc = 1;
18549 goto meta_command_exit;
18550 }
18551 if( azArg[1][0]=='|' ){
18552 p->in = popen(azArg[1]+1, "r");
18553 if( p->in==0 ){
18554 utf8_printf(stderr, "Error: cannot open \"%s\"\n", azArg[1]);
18555 rc = 1;
18556 }else{
18557 rc = process_input(p);
18558 pclose(p->in);
18559 }
18560 }else if( notNormalFile(azArg[1]) || (p->in = fopen(azArg[1], "rb"))==0 ){
18561 utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
18562 rc = 1;
18563 }else{
18564 rc = process_input(p);
18565 fclose(p->in);
@@ -20599,10 +20606,12 @@
20606 data.mode = MODE_Html;
20607 }else if( strcmp(z,"-list")==0 ){
20608 data.mode = MODE_List;
20609 }else if( strcmp(z,"-quote")==0 ){
20610 data.mode = MODE_Quote;
20611 sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator, SEP_Comma);
20612 sqlite3_snprintf(sizeof(data.rowSeparator), data.rowSeparator, SEP_Row);
20613 }else if( strcmp(z,"-line")==0 ){
20614 data.mode = MODE_Line;
20615 }else if( strcmp(z,"-column")==0 ){
20616 data.mode = MODE_Column;
20617 }else if( strcmp(z,"-json")==0 ){
20618
+223 -110
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.33.0. By combining all the individual C code files into this
3
+** version 3.34.0. 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.
@@ -1169,13 +1169,13 @@
11691169
**
11701170
** See also: [sqlite3_libversion()],
11711171
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11721172
** [sqlite_version()] and [sqlite_source_id()].
11731173
*/
1174
-#define SQLITE_VERSION "3.33.0"
1175
-#define SQLITE_VERSION_NUMBER 3033000
1176
-#define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f"
1174
+#define SQLITE_VERSION "3.34.0"
1175
+#define SQLITE_VERSION_NUMBER 3034000
1176
+#define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492"
11771177
11781178
/*
11791179
** CAPI3REF: Run-Time Library Version Numbers
11801180
** KEYWORDS: sqlite3_version sqlite3_sourceid
11811181
**
@@ -7232,10 +7232,61 @@
72327232
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
72337233
** the name of a database on connection D.
72347234
*/
72357235
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
72367236
7237
+/*
7238
+** CAPI3REF: Determine the transaction state of a database
7239
+** METHOD: sqlite3
7240
+**
7241
+** ^The sqlite3_txn_state(D,S) interface returns the current
7242
+** [transaction state] of schema S in database connection D. ^If S is NULL,
7243
+** then the highest transaction state of any schema on databse connection D
7244
+** is returned. Transaction states are (in order of lowest to highest):
7245
+** <ol>
7246
+** <li value="0"> SQLITE_TXN_NONE
7247
+** <li value="1"> SQLITE_TXN_READ
7248
+** <li value="2"> SQLITE_TXN_WRITE
7249
+** </ol>
7250
+** ^If the S argument to sqlite3_txn_state(D,S) is in the name of
7251
+** a valid schema, then -1 is returned.
7252
+*/
7253
+SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
7254
+
7255
+/*
7256
+** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
7257
+** KEYWORDS: {transaction state}
7258
+**
7259
+** These constants define the current transaction state of a database file.
7260
+** ^The [sqlite3_txn_state(D,S)] interface returns one of these
7261
+** constants in order to describe the transaction state of schema S
7262
+** in [database connection] D.
7263
+**
7264
+** <dl>
7265
+** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
7266
+** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
7267
+** pending.</dd>
7268
+**
7269
+** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
7270
+** <dd>The SQLITE_TXN_READ state means that the database is currently
7271
+** in a read transaction. Content has been read from the database file
7272
+** but nothing in the database file has changed. The transaction state
7273
+** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
7274
+** no other conflicting concurrent write transactions. The transaction
7275
+** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
7276
+** [COMMIT].</dd>
7277
+**
7278
+** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
7279
+** <dd>The SQLITE_TXN_WRITE state means that the database is currently
7280
+** in a write transaction. Content has been written to the database file
7281
+** but has not yet committed. The transaction state will change to
7282
+** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
7283
+*/
7284
+#define SQLITE_TXN_NONE 0
7285
+#define SQLITE_TXN_READ 1
7286
+#define SQLITE_TXN_WRITE 2
7287
+
72377288
/*
72387289
** CAPI3REF: Find the next prepared statement
72397290
** METHOD: sqlite3
72407291
**
72417292
** ^This interface returns a pointer to the next [prepared statement] after
@@ -10391,10 +10442,11 @@
1039110442
*/
1039210443
SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
1039310444
1039410445
/*
1039510446
** CAPI3REF: Flush caches to disk mid-transaction
10447
+** METHOD: sqlite3
1039610448
**
1039710449
** ^If a write-transaction is open on [database connection] D when the
1039810450
** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
1039910451
** pages in the pager-cache that are not currently in use are written out
1040010452
** to disk. A dirty page may be in use if a database cursor created by an
@@ -10423,10 +10475,11 @@
1042310475
*/
1042410476
SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
1042510477
1042610478
/*
1042710479
** CAPI3REF: The pre-update hook.
10480
+** METHOD: sqlite3
1042810481
**
1042910482
** ^These interfaces are only available if SQLite is compiled using the
1043010483
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
1043110484
**
1043210485
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
@@ -10525,10 +10578,11 @@
1052510578
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
1052610579
#endif
1052710580
1052810581
/*
1052910582
** CAPI3REF: Low-level system error code
10583
+** METHOD: sqlite3
1053010584
**
1053110585
** ^Attempt to return the underlying operating system error code or error
1053210586
** number that caused the most recent I/O error or failure to open a file.
1053310587
** The return value is OS-dependent. For example, on unix systems, after
1053410588
** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
@@ -13295,15 +13349,11 @@
1329513349
1329613350
/*
1329713351
** The maximum depth of an expression tree. This is limited to
1329813352
** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
1329913353
** want to place more severe limits on the complexity of an
13300
-** expression.
13301
-**
13302
-** A value of 0 used to mean that the limit was not enforced.
13303
-** But that is no longer true. The limit is now strictly enforced
13304
-** at all times.
13354
+** expression. A value of 0 means that there is no limit.
1330513355
*/
1330613356
#ifndef SQLITE_MAX_EXPR_DEPTH
1330713357
# define SQLITE_MAX_EXPR_DEPTH 1000
1330813358
#endif
1330913359
@@ -15080,12 +15130,11 @@
1508015130
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
1508115131
SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
1508215132
SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
1508315133
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
1508415134
SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags);
15085
-SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
15086
-SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
15135
+SQLITE_PRIVATE int sqlite3BtreeTxnState(Btree*);
1508715136
SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
1508815137
SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
1508915138
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
1509015139
#ifndef SQLITE_OMIT_SHARED_CACHE
1509115140
SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
@@ -18076,11 +18125,11 @@
1807618125
#define EP_Skip 0x001000 /* Operator does not contribute to affinity */
1807718126
#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
1807818127
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
1807918128
#define EP_Win 0x008000 /* Contains window functions */
1808018129
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
18081
- /* 0x020000 // available for reuse */
18130
+#define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */
1808218131
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
1808318132
#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
1808418133
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
1808518134
#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
1808618135
#define EP_Alias 0x400000 /* Is an alias for a result set column */
@@ -18314,13 +18363,13 @@
1831418363
** the OR optimization */
1831518364
#define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
1831618365
#define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
1831718366
#define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
1831818367
#define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18319
-#define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */
18368
+ /* 0x0400 not currently used */
1832018369
#define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18321
-#define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */
18370
+ /* 0x1000 not currently used */
1832218371
/* 0x2000 not currently used */
1832318372
#define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
1832418373
/* 0x8000 not currently used */
1832518374
1832618375
/* Allowed return values from sqlite3WhereIsDistinct()
@@ -33470,11 +33519,12 @@
3347033519
#ifndef HAVE_GETHOSTUUID
3347133520
# define HAVE_GETHOSTUUID 0
3347233521
# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
3347333522
(__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
3347433523
# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
33475
- && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
33524
+ && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))\
33525
+ && (!defined(TARGET_OS_MACCATALYST) || (TARGET_OS_MACCATALYST==0))
3347633526
# undef HAVE_GETHOSTUUID
3347733527
# define HAVE_GETHOSTUUID 1
3347833528
# else
3347933529
# warning "gethostuuid() is disabled."
3348033530
# endif
@@ -63837,14 +63887,28 @@
6383763887
** Btree.inTrans may take one of the following values.
6383863888
**
6383963889
** If the shared-data extension is enabled, there may be multiple users
6384063890
** of the Btree structure. At most one of these may open a write transaction,
6384163891
** but any number may have active read transactions.
63892
+**
63893
+** These values must match SQLITE_TXN_NONE, SQLITE_TXN_READ, and
63894
+** SQLITE_TXN_WRITE
6384263895
*/
6384363896
#define TRANS_NONE 0
6384463897
#define TRANS_READ 1
6384563898
#define TRANS_WRITE 2
63899
+
63900
+#if TRANS_NONE!=SQLITE_TXN_NONE
63901
+# error wrong numeric code for no-transaction
63902
+#endif
63903
+#if TRANS_READ!=SQLITE_TXN_READ
63904
+# error wrong numeric code for read-transaction
63905
+#endif
63906
+#if TRANS_WRITE!=SQLITE_TXN_WRITE
63907
+# error wrong numeric code for write-transaction
63908
+#endif
63909
+
6384663910
6384763911
/*
6384863912
** An instance of this object represents a single database file.
6384963913
**
6385063914
** A single database file can be in use at the same time by two
@@ -74791,15 +74855,16 @@
7479174855
assert( p->pBt->pPager!=0 );
7479274856
return sqlite3PagerJournalname(p->pBt->pPager);
7479374857
}
7479474858
7479574859
/*
74796
-** Return non-zero if a transaction is active.
74860
+** Return one of SQLITE_TXN_NONE, SQLITE_TXN_READ, or SQLITE_TXN_WRITE
74861
+** to describe the current transaction state of Btree p.
7479774862
*/
74798
-SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *p){
74863
+SQLITE_PRIVATE int sqlite3BtreeTxnState(Btree *p){
7479974864
assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
74800
- return (p && (p->inTrans==TRANS_WRITE));
74865
+ return p ? p->inTrans : 0;
7480174866
}
7480274867
7480374868
#ifndef SQLITE_OMIT_WAL
7480474869
/*
7480574870
** Run a checkpoint on the Btree passed as the first argument.
@@ -74824,18 +74889,12 @@
7482474889
return rc;
7482574890
}
7482674891
#endif
7482774892
7482874893
/*
74829
-** Return non-zero if a read (or write) transaction is active.
74894
+** Return true if there is currently a backup running on Btree p.
7483074895
*/
74831
-SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
74832
- assert( p );
74833
- assert( sqlite3_mutex_held(p->db->mutex) );
74834
- return p->inTrans!=TRANS_NONE;
74835
-}
74836
-
7483774896
SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree *p){
7483874897
assert( p );
7483974898
assert( sqlite3_mutex_held(p->db->mutex) );
7484074899
return p->nBackup!=0;
7484174900
}
@@ -75177,11 +75236,11 @@
7517775236
** second argument. If there is not, return SQLITE_OK. Otherwise, if there
7517875237
** is an open read-transaction, return SQLITE_ERROR and leave an error
7517975238
** message in database handle db.
7518075239
*/
7518175240
static int checkReadTransaction(sqlite3 *db, Btree *p){
75182
- if( sqlite3BtreeIsInReadTrans(p) ){
75241
+ if( sqlite3BtreeTxnState(p)!=SQLITE_TXN_NONE ){
7518375242
sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
7518475243
return SQLITE_ERROR;
7518575244
}
7518675245
return SQLITE_OK;
7518775246
}
@@ -75408,11 +75467,11 @@
7540875467
7540975468
/* If there is no open read-transaction on the source database, open
7541075469
** one now. If a transaction is opened here, then it will be closed
7541175470
** before this function exits.
7541275471
*/
75413
- if( rc==SQLITE_OK && 0==sqlite3BtreeIsInReadTrans(p->pSrc) ){
75472
+ if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){
7541475473
rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
7541575474
bCloseTrans = 1;
7541675475
}
7541775476
7541875477
/* If the destination database has not yet been locked (i.e. if this
@@ -75780,11 +75839,11 @@
7578075839
sqlite3_file *pFd; /* File descriptor for database pTo */
7578175840
sqlite3_backup b;
7578275841
sqlite3BtreeEnter(pTo);
7578375842
sqlite3BtreeEnter(pFrom);
7578475843
75785
- assert( sqlite3BtreeIsInTrans(pTo) );
75844
+ assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
7578675845
pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
7578775846
if( pFd->pMethods ){
7578875847
i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
7578975848
rc = sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
7579075849
if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
@@ -75816,11 +75875,11 @@
7581675875
pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
7581775876
}else{
7581875877
sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
7581975878
}
7582075879
75821
- assert( sqlite3BtreeIsInTrans(pTo)==0 );
75880
+ assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
7582275881
copy_finished:
7582375882
sqlite3BtreeLeave(pFrom);
7582475883
sqlite3BtreeLeave(pTo);
7582575884
return rc;
7582675885
}
@@ -80399,11 +80458,11 @@
8039980458
** one database file has an open write transaction, a super-journal
8040080459
** file is required for an atomic commit.
8040180460
*/
8040280461
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
8040380462
Btree *pBt = db->aDb[i].pBt;
80404
- if( sqlite3BtreeIsInTrans(pBt) ){
80463
+ if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){
8040580464
/* Whether or not a database might need a super-journal depends upon
8040680465
** its journal mode (among other things). This matrix determines which
8040780466
** journal modes use a super-journal and which do not */
8040880467
static const u8 aMJNeeded[] = {
8040980468
/* DELETE */ 1,
@@ -80534,11 +80593,11 @@
8053480593
** still have 'null' as the super-journal pointer, so they will roll
8053580594
** back independently if a failure occurs.
8053680595
*/
8053780596
for(i=0; i<db->nDb; i++){
8053880597
Btree *pBt = db->aDb[i].pBt;
80539
- if( sqlite3BtreeIsInTrans(pBt) ){
80598
+ if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){
8054080599
char const *zFile = sqlite3BtreeGetJournalname(pBt);
8054180600
if( zFile==0 ){
8054280601
continue; /* Ignore TEMP and :memory: databases */
8054380602
}
8054480603
assert( zFile[0]!=0 );
@@ -88871,11 +88930,11 @@
8887188930
8887288931
if( p->usesStmtJournal
8887388932
&& pOp->p2
8887488933
&& (db->autoCommit==0 || db->nVdbeRead>1)
8887588934
){
88876
- assert( sqlite3BtreeIsInTrans(pBt) );
88935
+ assert( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE );
8887788936
if( p->iStatement==0 ){
8887888937
assert( db->nStatement>=0 && db->nSavepoint>=0 );
8887988938
db->nStatement++;
8888088939
p->iStatement = db->nSavepoint + db->nStatement;
8888188940
}
@@ -92363,11 +92422,11 @@
9236392422
}
9236492423
9236592424
/* Open a transaction on the database file. Regardless of the journal
9236692425
** mode, this transaction always uses a rollback journal.
9236792426
*/
92368
- assert( sqlite3BtreeIsInTrans(pBt)==0 );
92427
+ assert( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_WRITE );
9236992428
if( rc==SQLITE_OK ){
9237092429
rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
9237192430
}
9237292431
}
9237392432
}
@@ -98828,11 +98887,11 @@
9882898887
case TK_ISNOT: {
9882998888
Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
9883098889
assert( !ExprHasProperty(pExpr, EP_Reduced) );
9883198890
/* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
9883298891
** and "x IS NOT FALSE". */
98833
- if( pRight && pRight->op==TK_ID ){
98892
+ if( pRight && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){
9883498893
int rc = resolveExprStep(pWalker, pRight);
9883598894
if( rc==WRC_Abort ) return WRC_Abort;
9883698895
if( pRight->op==TK_TRUEFALSE ){
9883798896
pExpr->op2 = pExpr->op;
9883898897
pExpr->op = TK_TRUTH;
@@ -99756,11 +99815,11 @@
9975699815
** SELECT a AS b FROM t1 WHERE b;
9975799816
** SELECT * FROM t1 WHERE (select a from t1);
9975899817
*/
9975999818
SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
9976099819
int op;
99761
- while( ExprHasProperty(pExpr, EP_Skip) ){
99820
+ while( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
9976299821
assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
9976399822
pExpr = pExpr->pLeft;
9976499823
assert( pExpr!=0 );
9976599824
}
9976699825
op = pExpr->op;
@@ -99827,11 +99886,11 @@
9982799886
/*
9982899887
** Skip over any TK_COLLATE operators.
9982999888
*/
9983099889
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
9983199890
while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
99832
- assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
99891
+ assert( pExpr->op==TK_COLLATE );
9983399892
pExpr = pExpr->pLeft;
9983499893
}
9983599894
return pExpr;
9983699895
}
9983799896
@@ -99846,11 +99905,11 @@
9984699905
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
9984799906
assert( pExpr->x.pList->nExpr>0 );
9984899907
assert( pExpr->op==TK_FUNCTION );
9984999908
pExpr = pExpr->x.pList->a[0].pExpr;
9985099909
}else{
99851
- assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
99910
+ assert( pExpr->op==TK_COLLATE );
9985299911
pExpr = pExpr->pLeft;
9985399912
}
9985499913
}
9985599914
return pExpr;
9985699915
}
@@ -100480,10 +100539,11 @@
100480100539
/*
100481100540
** Propagate all EP_Propagate flags from the Expr.x.pList into
100482100541
** Expr.flags.
100483100542
*/
100484100543
SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
100544
+ if( pParse->nErr ) return;
100485100545
if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
100486100546
p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
100487100547
}
100488100548
}
100489100549
#define exprSetHeight(y)
@@ -109785,11 +109845,13 @@
109785109845
}
109786109846
if( i<2 ){
109787109847
sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
109788109848
goto detach_error;
109789109849
}
109790
- if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
109850
+ if( sqlite3BtreeTxnState(pDb->pBt)!=SQLITE_TXN_NONE
109851
+ || sqlite3BtreeIsInBackup(pDb->pBt)
109852
+ ){
109791109853
sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
109792109854
goto detach_error;
109793109855
}
109794109856
109795109857
/* If any TEMP triggers reference the schema being detached, move those
@@ -110445,18 +110507,19 @@
110445110507
int iDb, /* Index of the database containing the table to lock */
110446110508
Pgno iTab, /* Root page number of the table to be locked */
110447110509
u8 isWriteLock, /* True for a write lock */
110448110510
const char *zName /* Name of the table to be locked */
110449110511
){
110450
- Parse *pToplevel = sqlite3ParseToplevel(pParse);
110512
+ Parse *pToplevel;
110451110513
int i;
110452110514
int nBytes;
110453110515
TableLock *p;
110454110516
assert( iDb>=0 );
110455110517
110456110518
if( iDb==1 ) return;
110457110519
if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
110520
+ pToplevel = sqlite3ParseToplevel(pParse);
110458110521
for(i=0; i<pToplevel->nTableLock; i++){
110459110522
p = &pToplevel->aTableLock[i];
110460110523
if( p->iDb==iDb && p->iTab==iTab ){
110461110524
p->isWriteLock = (p->isWriteLock || isWriteLock);
110462110525
return;
@@ -110482,14 +110545,12 @@
110482110545
** Code an OP_TableLock instruction for each table locked by the
110483110546
** statement (configured by calls to sqlite3TableLock()).
110484110547
*/
110485110548
static void codeTableLocks(Parse *pParse){
110486110549
int i;
110487
- Vdbe *pVdbe;
110488
-
110489
- pVdbe = sqlite3GetVdbe(pParse);
110490
- assert( pVdbe!=0 ); /* sqlite3GetVdbe cannot fail: VDBE already allocated */
110550
+ Vdbe *pVdbe = pParse->pVdbe;
110551
+ assert( pVdbe!=0 );
110491110552
110492110553
for(i=0; i<pParse->nTableLock; i++){
110493110554
TableLock *p = &pParse->aTableLock[i];
110494110555
int p1 = p->iDb;
110495110556
sqlite3VdbeAddOp4(pVdbe, OP_TableLock, p1, p->iTab, p->isWriteLock,
@@ -114858,19 +114919,19 @@
114858114919
SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
114859114920
int i;
114860114921
struct SrcList_item *pItem;
114861114922
if( pList==0 ) return;
114862114923
for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
114863
- sqlite3DbFree(db, pItem->zDatabase);
114924
+ if( pItem->zDatabase ) sqlite3DbFreeNN(db, pItem->zDatabase);
114864114925
sqlite3DbFree(db, pItem->zName);
114865
- sqlite3DbFree(db, pItem->zAlias);
114926
+ if( pItem->zAlias ) sqlite3DbFreeNN(db, pItem->zAlias);
114866114927
if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
114867114928
if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
114868114929
sqlite3DeleteTable(db, pItem->pTab);
114869
- sqlite3SelectDelete(db, pItem->pSelect);
114870
- sqlite3ExprDelete(db, pItem->pOn);
114871
- sqlite3IdListDelete(db, pItem->pUsing);
114930
+ if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect);
114931
+ if( pItem->pOn ) sqlite3ExprDelete(db, pItem->pOn);
114932
+ if( pItem->pUsing ) sqlite3IdListDelete(db, pItem->pUsing);
114872114933
}
114873114934
sqlite3DbFreeNN(db, pList);
114874114935
}
114875114936
114876114937
/*
@@ -115127,24 +115188,26 @@
115127115188
** Record the fact that the schema cookie will need to be verified
115128115189
** for database iDb. The code to actually verify the schema cookie
115129115190
** will occur at the end of the top-level VDBE and will be generated
115130115191
** later, by sqlite3FinishCoding().
115131115192
*/
115132
-SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
115133
- Parse *pToplevel = sqlite3ParseToplevel(pParse);
115134
-
115135
- assert( iDb>=0 && iDb<pParse->db->nDb );
115136
- assert( pParse->db->aDb[iDb].pBt!=0 || iDb==1 );
115193
+static void sqlite3CodeVerifySchemaAtToplevel(Parse *pToplevel, int iDb){
115194
+ assert( iDb>=0 && iDb<pToplevel->db->nDb );
115195
+ assert( pToplevel->db->aDb[iDb].pBt!=0 || iDb==1 );
115137115196
assert( iDb<SQLITE_MAX_ATTACHED+2 );
115138
- assert( sqlite3SchemaMutexHeld(pParse->db, iDb, 0) );
115197
+ assert( sqlite3SchemaMutexHeld(pToplevel->db, iDb, 0) );
115139115198
if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
115140115199
DbMaskSet(pToplevel->cookieMask, iDb);
115141115200
if( !OMIT_TEMPDB && iDb==1 ){
115142115201
sqlite3OpenTempDatabase(pToplevel);
115143115202
}
115144115203
}
115145115204
}
115205
+SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
115206
+ sqlite3CodeVerifySchemaAtToplevel(sqlite3ParseToplevel(pParse), iDb);
115207
+}
115208
+
115146115209
115147115210
/*
115148115211
** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
115149115212
** attached database. Otherwise, invoke it for the database named zDb only.
115150115213
*/
@@ -115172,11 +115235,11 @@
115172115235
** can be checked before any changes are made to the database, it is never
115173115236
** necessary to undo a write and the checkpoint should not be set.
115174115237
*/
115175115238
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
115176115239
Parse *pToplevel = sqlite3ParseToplevel(pParse);
115177
- sqlite3CodeVerifySchema(pParse, iDb);
115240
+ sqlite3CodeVerifySchemaAtToplevel(pToplevel, iDb);
115178115241
DbMaskSet(pToplevel->writeMask, iDb);
115179115242
pToplevel->isMultiWrite |= setStatement;
115180115243
}
115181115244
115182115245
/*
@@ -115223,11 +115286,13 @@
115223115286
int onError, /* Constraint type */
115224115287
char *p4, /* Error message */
115225115288
i8 p4type, /* P4_STATIC or P4_TRANSIENT */
115226115289
u8 p5Errmsg /* P5_ErrMsg type */
115227115290
){
115228
- Vdbe *v = sqlite3GetVdbe(pParse);
115291
+ Vdbe *v;
115292
+ assert( pParse->pVdbe!=0 );
115293
+ v = sqlite3GetVdbe(pParse);
115229115294
assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );
115230115295
if( onError==OE_Abort ){
115231115296
sqlite3MayAbort(pParse);
115232115297
}
115233115298
sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
@@ -116504,11 +116569,11 @@
116504116569
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
116505116570
}
116506116571
}else
116507116572
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
116508116573
{
116509
- u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK|WHERE_SEEK_TABLE;
116574
+ u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
116510116575
if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
116511116576
wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
116512116577
if( HasRowid(pTab) ){
116513116578
/* For a rowid table, initialize the RowSet to an empty set */
116514116579
pPk = 0;
@@ -116540,10 +116605,13 @@
116540116605
if( pWInfo==0 ) goto delete_from_cleanup;
116541116606
eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
116542116607
assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
116543116608
assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF );
116544116609
if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse);
116610
+ if( sqlite3WhereUsesDeferredSeek(pWInfo) ){
116611
+ sqlite3VdbeAddOp1(v, OP_FinishSeek, iTabCur);
116612
+ }
116545116613
116546116614
/* Keep track of the number of rows to be deleted */
116547116615
if( memCnt ){
116548116616
sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
116549116617
}
@@ -116574,10 +116642,11 @@
116574116642
memset(aToOpen, 1, nIdx+1);
116575116643
aToOpen[nIdx+1] = 0;
116576116644
if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
116577116645
if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
116578116646
if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
116647
+ addrBypass = sqlite3VdbeMakeLabel(pParse);
116579116648
}else{
116580116649
if( pPk ){
116581116650
/* Add the PK key for this row to the temporary table */
116582116651
iKey = ++pParse->nMem;
116583116652
nKey = 0; /* Zero tells OP_Found to use a composite key */
@@ -116587,17 +116656,10 @@
116587116656
}else{
116588116657
/* Add the rowid of the row to be deleted to the RowSet */
116589116658
nKey = 1; /* OP_DeferredSeek always uses a single rowid */
116590116659
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
116591116660
}
116592
- }
116593
-
116594
- /* If this DELETE cannot use the ONEPASS strategy, this is the
116595
- ** end of the WHERE loop */
116596
- if( eOnePass!=ONEPASS_OFF ){
116597
- addrBypass = sqlite3VdbeMakeLabel(pParse);
116598
- }else{
116599116661
sqlite3WhereEnd(pWInfo);
116600116662
}
116601116663
116602116664
/* Unless this is a view, open cursors for the table we are
116603116665
** deleting from and all its indices. If this is a view, then the
@@ -120583,11 +120645,12 @@
120583120645
Table *pTab, /* The table to be opened */
120584120646
int opcode /* OP_OpenRead or OP_OpenWrite */
120585120647
){
120586120648
Vdbe *v;
120587120649
assert( !IsVirtual(pTab) );
120588
- v = sqlite3GetVdbe(pParse);
120650
+ assert( pParse->pVdbe!=0 );
120651
+ v = pParse->pVdbe;
120589120652
assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
120590120653
sqlite3TableLock(pParse, iDb, pTab->tnum,
120591120654
(opcode==OP_OpenWrite)?1:0, pTab->zName);
120592120655
if( HasRowid(pTab) ){
120593120656
sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
@@ -122082,11 +122145,11 @@
122082122145
Trigger *pTrigger; /* List of DELETE triggers on the table pTab */
122083122146
int nReplaceTrig = 0; /* Number of replace triggers coded */
122084122147
122085122148
isUpdate = regOldData!=0;
122086122149
db = pParse->db;
122087
- v = sqlite3GetVdbe(pParse);
122150
+ v = pParse->pVdbe;
122088122151
assert( v!=0 );
122089122152
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122090122153
nCol = pTab->nCol;
122091122154
122092122155
/* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
@@ -122855,11 +122918,11 @@
122855122918
assert( update_flags==0
122856122919
|| update_flags==OPFLAG_ISUPDATE
122857122920
|| update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
122858122921
);
122859122922
122860
- v = sqlite3GetVdbe(pParse);
122923
+ v = pParse->pVdbe;
122861122924
assert( v!=0 );
122862122925
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122863122926
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
122864122927
/* All REPLACE indexes are at the end of the list */
122865122928
assert( pIdx->onError!=OE_Replace
@@ -122956,11 +123019,11 @@
122956123019
** variables *piDataCur and *piIdxCur uninitialized so that valgrind
122957123020
** can detect if they are used by mistake in the caller. */
122958123021
return 0;
122959123022
}
122960123023
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
122961
- v = sqlite3GetVdbe(pParse);
123024
+ v = pParse->pVdbe;
122962123025
assert( v!=0 );
122963123026
if( iBase<0 ) iBase = pParse->nTab;
122964123027
iDataCur = iBase++;
122965123028
if( piDataCur ) *piDataCur = iDataCur;
122966123029
if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
@@ -125874,11 +125937,13 @@
125874125937
** from default, or when 'file' and the temp_store_directory has changed
125875125938
*/
125876125939
static int invalidateTempStorage(Parse *pParse){
125877125940
sqlite3 *db = pParse->db;
125878125941
if( db->aDb[1].pBt!=0 ){
125879
- if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
125942
+ if( !db->autoCommit
125943
+ || sqlite3BtreeTxnState(db->aDb[1].pBt)!=SQLITE_TXN_NONE
125944
+ ){
125880125945
sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
125881125946
"from within a transaction");
125882125947
return SQLITE_ERROR;
125883125948
}
125884125949
sqlite3BtreeClose(db->aDb[1].pBt);
@@ -128577,11 +128642,11 @@
128577128642
128578128643
/* If there is not already a read-only (or read-write) transaction opened
128579128644
** on the b-tree database, open one now. If a transaction is opened, it
128580128645
** will be closed before this function returns. */
128581128646
sqlite3BtreeEnter(pDb->pBt);
128582
- if( !sqlite3BtreeIsInReadTrans(pDb->pBt) ){
128647
+ if( sqlite3BtreeTxnState(pDb->pBt)==SQLITE_TXN_NONE ){
128583128648
rc = sqlite3BtreeBeginTrans(pDb->pBt, 0, 0);
128584128649
if( rc!=SQLITE_OK ){
128585128650
sqlite3SetString(pzErrMsg, db, sqlite3ErrStr(rc));
128586128651
goto initone_error_out;
128587128652
}
@@ -128820,11 +128885,11 @@
128820128885
if( pBt==0 ) continue;
128821128886
128822128887
/* If there is not already a read-only (or read-write) transaction opened
128823128888
** on the b-tree database, open one now. If a transaction is opened, it
128824128889
** will be closed immediately after reading the meta-value. */
128825
- if( !sqlite3BtreeIsInReadTrans(pBt) ){
128890
+ if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_NONE ){
128826128891
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
128827128892
if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
128828128893
sqlite3OomFault(db);
128829128894
}
128830128895
if( rc!=SQLITE_OK ) return;
@@ -132803,11 +132868,11 @@
132803132868
if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
132804132869
memset(&ifNullRow, 0, sizeof(ifNullRow));
132805132870
ifNullRow.op = TK_IF_NULL_ROW;
132806132871
ifNullRow.pLeft = pCopy;
132807132872
ifNullRow.iTable = pSubst->iNewTable;
132808
- ifNullRow.flags = EP_Skip;
132873
+ ifNullRow.flags = EP_IfNullRow;
132809132874
pCopy = &ifNullRow;
132810132875
}
132811132876
testcase( ExprHasProperty(pCopy, EP_Subquery) );
132812132877
pNew = sqlite3ExprDup(db, pCopy, 0);
132813132878
if( pNew && pSubst->isLeftJoin ){
@@ -138304,11 +138369,11 @@
138304138369
** Do not consider a single-pass strategy for a multi-row update if
138305138370
** there are any triggers or foreign keys to process, or rows may
138306138371
** be deleted as a result of REPLACE conflict handling. Any of these
138307138372
** things might disturb a cursor being used to scan through the table
138308138373
** or index, causing a single-pass approach to malfunction. */
138309
- flags = WHERE_ONEPASS_DESIRED|WHERE_SEEK_UNIQ_TABLE;
138374
+ flags = WHERE_ONEPASS_DESIRED;
138310138375
if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
138311138376
flags |= WHERE_ONEPASS_MULTIROW;
138312138377
}
138313138378
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur);
138314138379
if( pWInfo==0 ) goto update_cleanup;
@@ -139507,12 +139572,12 @@
139507139572
BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
139508139573
BTREE_USER_VERSION, 0, /* Preserve the user version */
139509139574
BTREE_APPLICATION_ID, 0, /* Preserve the application id */
139510139575
};
139511139576
139512
- assert( 1==sqlite3BtreeIsInTrans(pTemp) );
139513
- assert( pOut!=0 || 1==sqlite3BtreeIsInTrans(pMain) );
139577
+ assert( SQLITE_TXN_WRITE==sqlite3BtreeTxnState(pTemp) );
139578
+ assert( pOut!=0 || SQLITE_TXN_WRITE==sqlite3BtreeTxnState(pMain) );
139514139579
139515139580
/* Copy Btree meta values */
139516139581
for(i=0; i<ArraySize(aCopy); i+=2){
139517139582
/* GetMeta() and UpdateMeta() cannot fail in this context because
139518139583
** we already have page 1 loaded into cache and marked dirty. */
@@ -141406,10 +141471,11 @@
141406141471
unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
141407141472
unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
141408141473
unsigned sorted :1; /* True if really sorted (not just grouped) */
141409141474
LogEst nRowOut; /* Estimated number of output rows */
141410141475
int iTop; /* The very beginning of the WHERE loop */
141476
+ int iEndWhere; /* End of the WHERE clause itself */
141411141477
WhereLoop *pLoops; /* List of all WhereLoop objects */
141412141478
WhereExprMod *pExprMods; /* Expression modifications */
141413141479
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
141414141480
WhereClause sWC; /* Decomposition of the WHERE clause */
141415141481
WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
@@ -143275,11 +143341,12 @@
143275143341
nConstraint = nEq;
143276143342
if( pRangeStart ){
143277143343
Expr *pRight = pRangeStart->pExpr->pRight;
143278143344
codeExprOrVector(pParse, pRight, regBase+nEq, nBtm);
143279143345
whereLikeOptimizationStringFixup(v, pLevel, pRangeStart);
143280
- if( (pRangeStart->wtFlags & TERM_VNULL)==0
143346
+ if( !bRev
143347
+ && (pRangeStart->wtFlags & TERM_VNULL)==0
143281143348
&& sqlite3ExprCanBeNull(pRight)
143282143349
){
143283143350
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143284143351
VdbeCoverage(v);
143285143352
}
@@ -143353,11 +143420,12 @@
143353143420
nConstraint = nEq;
143354143421
if( pRangeEnd ){
143355143422
Expr *pRight = pRangeEnd->pExpr->pRight;
143356143423
codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
143357143424
whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
143358
- if( (pRangeEnd->wtFlags & TERM_VNULL)==0
143425
+ if( bRev
143426
+ && (pRangeEnd->wtFlags & TERM_VNULL)==0
143359143427
&& sqlite3ExprCanBeNull(pRight)
143360143428
){
143361143429
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143362143430
VdbeCoverage(v);
143363143431
}
@@ -143429,21 +143497,11 @@
143429143497
omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
143430143498
&& (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
143431143499
if( omitTable ){
143432143500
/* pIdx is a covering index. No need to access the main table. */
143433143501
}else if( HasRowid(pIdx->pTable) ){
143434
- if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)
143435
- || ( (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)!=0
143436
- && (pWInfo->eOnePass==ONEPASS_SINGLE || pLoop->nLTerm==0) )
143437
- ){
143438
- iRowidReg = ++pParse->nMem;
143439
- sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
143440
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
143441
- VdbeCoverage(v);
143442
- }else{
143443
- codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur);
143444
- }
143502
+ codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur);
143445143503
}else if( iCur!=iIdxCur ){
143446143504
Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
143447143505
iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
143448143506
for(j=0; j<pPk->nKeyCol; j++){
143449143507
k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]);
@@ -143566,11 +143624,10 @@
143566143624
int regRowid = 0; /* Register holding rowid */
143567143625
int iLoopBody = sqlite3VdbeMakeLabel(pParse);/* Start of loop body */
143568143626
int iRetInit; /* Address of regReturn init */
143569143627
int untestedTerms = 0; /* Some terms not completely tested */
143570143628
int ii; /* Loop counter */
143571
- u16 wctrlFlags; /* Flags for sub-WHERE clause */
143572143629
Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
143573143630
Table *pTab = pTabItem->pTab;
143574143631
143575143632
pTerm = pLoop->aLTerm[0];
143576143633
assert( pTerm!=0 );
@@ -143667,11 +143724,10 @@
143667143724
143668143725
/* Run a separate WHERE clause for each term of the OR clause. After
143669143726
** eliminating duplicates from other WHERE clauses, the action for each
143670143727
** sub-WHERE clause is to to invoke the main loop body as a subroutine.
143671143728
*/
143672
- wctrlFlags = WHERE_OR_SUBCLAUSE | (pWInfo->wctrlFlags & WHERE_SEEK_TABLE);
143673143729
ExplainQueryPlan((pParse, 1, "MULTI-INDEX OR"));
143674143730
for(ii=0; ii<pOrWc->nTerm; ii++){
143675143731
WhereTerm *pOrTerm = &pOrWc->a[ii];
143676143732
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
143677143733
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
@@ -143686,11 +143742,11 @@
143686143742
}
143687143743
/* Loop through table entries that match term pOrTerm. */
143688143744
ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
143689143745
WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
143690143746
pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
143691
- wctrlFlags, iCovCur);
143747
+ WHERE_OR_SUBCLAUSE, iCovCur);
143692143748
assert( pSubWInfo || pParse->nErr || db->mallocFailed );
143693143749
if( pSubWInfo ){
143694143750
WhereLoop *pSubLoop;
143695143751
int addrExplain = sqlite3WhereExplainOneScan(
143696143752
pParse, pOrTab, &pSubWInfo->a[0], 0
@@ -143783,10 +143839,13 @@
143783143839
){
143784143840
assert( pSubWInfo->a[0].iIdxCur==iCovCur );
143785143841
pCov = pSubLoop->u.btree.pIndex;
143786143842
}else{
143787143843
pCov = 0;
143844
+ }
143845
+ if( sqlite3WhereUsesDeferredSeek(pSubWInfo) ){
143846
+ pWInfo->bDeferredSeek = 1;
143788143847
}
143789143848
143790143849
/* Finish the loop through table entries that match term pOrTerm. */
143791143850
sqlite3WhereEnd(pSubWInfo);
143792143851
ExplainQueryPlanPop(pParse);
@@ -149662,20 +149721,28 @@
149662149721
** sorting cost to:
149663149722
**
149664149723
** cost = (3.0 * N * log(N)) * (Y/X)
149665149724
**
149666149725
** The (Y/X) term is implemented using stack variable rScale
149667
- ** below. */
149726
+ ** below.
149727
+ */
149668149728
LogEst rScale, rSortCost;
149669149729
assert( nOrderBy>0 && 66==sqlite3LogEst(100) );
149670149730
rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
149671149731
rSortCost = nRow + rScale + 16;
149672149732
149673149733
/* Multiple by log(M) where M is the number of output rows.
149674
- ** Use the LIMIT for M if it is smaller */
149734
+ ** Use the LIMIT for M if it is smaller. Or if this sort is for
149735
+ ** a DISTINT operator, M will be the number of distinct output
149736
+ ** rows, so fudge it downwards a bit.
149737
+ */
149675149738
if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
149676149739
nRow = pWInfo->iLimit;
149740
+ }else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
149741
+ /* TUNING: In the sort for a DISTINCT operator, assume that the DISTINCT
149742
+ ** reduces the number of output rows by a factor of 2 */
149743
+ if( nRow>10 ) nRow -= 10; assert( 10==sqlite3LogEst(2) );
149677149744
}
149678149745
rSortCost += estLog(nRow);
149679149746
return rSortCost;
149680149747
}
149681149748
@@ -150855,10 +150922,11 @@
150855150922
}
150856150923
}
150857150924
150858150925
/* Done. */
150859150926
VdbeModuleComment((v, "Begin WHERE-core"));
150927
+ pWInfo->iEndWhere = sqlite3VdbeCurrentAddr(v);
150860150928
return pWInfo;
150861150929
150862150930
/* Jump here if malloc fails */
150863150931
whereBeginError:
150864150932
if( pWInfo ){
@@ -150898,10 +150966,11 @@
150898150966
int i;
150899150967
WhereLevel *pLevel;
150900150968
WhereLoop *pLoop;
150901150969
SrcList *pTabList = pWInfo->pTabList;
150902150970
sqlite3 *db = pParse->db;
150971
+ int iEnd = sqlite3VdbeCurrentAddr(v);
150903150972
150904150973
/* Generate loop termination code.
150905150974
*/
150906150975
VdbeModuleComment((v, "End WHERE-core"));
150907150976
for(i=pWInfo->nLevel-1; i>=0; i--){
@@ -151035,11 +151104,11 @@
151035151104
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
151036151105
151037151106
assert( pWInfo->nLevel<=pTabList->nSrc );
151038151107
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
151039151108
int k, last;
151040
- VdbeOp *pOp;
151109
+ VdbeOp *pOp, *pLastOp;
151041151110
Index *pIdx = 0;
151042151111
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
151043151112
Table *pTab = pTabItem->pTab;
151044151113
assert( pTab!=0 );
151045151114
pLoop = pLevel->pWLoop;
@@ -151093,24 +151162,35 @@
151093151162
pIdx = pLoop->u.btree.pIndex;
151094151163
}else if( pLoop->wsFlags & WHERE_MULTI_OR ){
151095151164
pIdx = pLevel->u.pCovidx;
151096151165
}
151097151166
if( pIdx
151098
- && (pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable))
151099151167
&& !db->mallocFailed
151100151168
){
151101
- last = sqlite3VdbeCurrentAddr(v);
151102
- k = pLevel->addrBody;
151169
+ if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){
151170
+ last = iEnd;
151171
+ }else{
151172
+ last = pWInfo->iEndWhere;
151173
+ }
151174
+ k = pLevel->addrBody + 1;
151103151175
#ifdef SQLITE_DEBUG
151104151176
if( db->flags & SQLITE_VdbeAddopTrace ){
151105151177
printf("TRANSLATE opcodes in range %d..%d\n", k, last-1);
151106151178
}
151179
+ /* Proof that the "+1" on the k value above is safe */
151180
+ pOp = sqlite3VdbeGetOp(v, k - 1);
151181
+ assert( pOp->opcode!=OP_Column || pOp->p1!=pLevel->iTabCur );
151182
+ assert( pOp->opcode!=OP_Rowid || pOp->p1!=pLevel->iTabCur );
151183
+ assert( pOp->opcode!=OP_IfNullRow || pOp->p1!=pLevel->iTabCur );
151107151184
#endif
151108151185
pOp = sqlite3VdbeGetOp(v, k);
151109
- for(; k<last; k++, pOp++){
151110
- if( pOp->p1!=pLevel->iTabCur ) continue;
151111
- if( pOp->opcode==OP_Column
151186
+ pLastOp = pOp + (last - k);
151187
+ assert( pOp<pLastOp );
151188
+ do{
151189
+ if( pOp->p1!=pLevel->iTabCur ){
151190
+ /* no-op */
151191
+ }else if( pOp->opcode==OP_Column
151112151192
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
151113151193
|| pOp->opcode==OP_Offset
151114151194
#endif
151115151195
){
151116151196
int x = pOp->p2;
@@ -151137,11 +151217,14 @@
151137151217
OpcodeRewriteTrace(db, k, pOp);
151138151218
}else if( pOp->opcode==OP_IfNullRow ){
151139151219
pOp->p1 = pLevel->iIdxCur;
151140151220
OpcodeRewriteTrace(db, k, pOp);
151141151221
}
151142
- }
151222
+#ifdef SQLITE_DEBUG
151223
+ k++;
151224
+#endif
151225
+ }while( (++pOp)<pLastOp );
151143151226
#ifdef SQLITE_DEBUG
151144151227
if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
151145151228
#endif
151146151229
}
151147151230
}
@@ -161894,11 +161977,11 @@
161894161977
#endif
161895161978
sqlite3_mutex_enter(db->mutex);
161896161979
sqlite3BtreeEnterAll(db);
161897161980
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
161898161981
Btree *pBt = db->aDb[i].pBt;
161899
- if( pBt && sqlite3BtreeIsInTrans(pBt) ){
161982
+ if( pBt && sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){
161900161983
Pager *pPager = sqlite3BtreePager(pBt);
161901161984
rc = sqlite3PagerFlush(pPager);
161902161985
if( rc==SQLITE_BUSY ){
161903161986
bSeenBusy = 1;
161904161987
rc = SQLITE_OK;
@@ -162237,10 +162320,40 @@
162237162320
*/
162238162321
db->magic = SQLITE_MAGIC_ZOMBIE;
162239162322
sqlite3LeaveMutexAndCloseZombie(db);
162240162323
return SQLITE_OK;
162241162324
}
162325
+
162326
+/*
162327
+** Return the transaction state for a single databse, or the maximum
162328
+** transaction state over all attached databases if zSchema is null.
162329
+*/
162330
+SQLITE_API int sqlite3_txn_state(sqlite3 *db, const char *zSchema){
162331
+ int iDb, nDb;
162332
+ int iTxn = -1;
162333
+#ifdef SQLITE_ENABLE_API_ARMOR
162334
+ if( !sqlite3SafetyCheckOk(db) ){
162335
+ (void)SQLITE_MISUSE_BKPT;
162336
+ return -1;
162337
+ }
162338
+#endif
162339
+ sqlite3_mutex_enter(db->mutex);
162340
+ if( zSchema ){
162341
+ nDb = iDb = sqlite3FindDbName(db, zSchema);
162342
+ if( iDb<0 ) nDb--;
162343
+ }else{
162344
+ iDb = 0;
162345
+ nDb = db->nDb-1;
162346
+ }
162347
+ for(; iDb<=nDb; iDb++){
162348
+ Btree *pBt = db->aDb[iDb].pBt;
162349
+ int x = pBt!=0 ? sqlite3BtreeTxnState(pBt) : SQLITE_TXN_NONE;
162350
+ if( x>iTxn ) iTxn = x;
162351
+ }
162352
+ sqlite3_mutex_leave(db->mutex);
162353
+ return iTxn;
162354
+}
162242162355
162243162356
/*
162244162357
** Two variations on the public interface for closing a database
162245162358
** connection. The sqlite3_close() version returns SQLITE_BUSY and
162246162359
** leaves the connection option if there are unfinalized prepared
@@ -162398,11 +162511,11 @@
162398162511
schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
162399162512
162400162513
for(i=0; i<db->nDb; i++){
162401162514
Btree *p = db->aDb[i].pBt;
162402162515
if( p ){
162403
- if( sqlite3BtreeIsInTrans(p) ){
162516
+ if( sqlite3BtreeTxnState(p)==SQLITE_TXN_WRITE ){
162404162517
inTrans = 1;
162405162518
}
162406162519
sqlite3BtreeRollback(p, tripCode, !schemaChange);
162407162520
}
162408162521
}
@@ -165437,11 +165550,11 @@
165437165550
165438165551
if( db->autoCommit==0 ){
165439165552
int iDb = sqlite3FindDbName(db, zDb);
165440165553
if( iDb==0 || iDb>1 ){
165441165554
Btree *pBt = db->aDb[iDb].pBt;
165442
- if( 0==sqlite3BtreeIsInTrans(pBt) ){
165555
+ if( SQLITE_TXN_WRITE!=sqlite3BtreeTxnState(pBt) ){
165443165556
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
165444165557
if( rc==SQLITE_OK ){
165445165558
rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
165446165559
}
165447165560
}
@@ -165473,14 +165586,14 @@
165473165586
if( db->autoCommit==0 ){
165474165587
int iDb;
165475165588
iDb = sqlite3FindDbName(db, zDb);
165476165589
if( iDb==0 || iDb>1 ){
165477165590
Btree *pBt = db->aDb[iDb].pBt;
165478
- if( sqlite3BtreeIsInTrans(pBt)==0 ){
165591
+ if( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_WRITE ){
165479165592
Pager *pPager = sqlite3BtreePager(pBt);
165480165593
int bUnlock = 0;
165481
- if( sqlite3BtreeIsInReadTrans(pBt) ){
165594
+ if( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_NONE ){
165482165595
if( db->nVdbeActive==0 ){
165483165596
rc = sqlite3PagerSnapshotCheck(pPager, pSnapshot);
165484165597
if( rc==SQLITE_OK ){
165485165598
bUnlock = 1;
165486165599
rc = sqlite3BtreeCommit(pBt);
@@ -165525,11 +165638,11 @@
165525165638
165526165639
sqlite3_mutex_enter(db->mutex);
165527165640
iDb = sqlite3FindDbName(db, zDb);
165528165641
if( iDb==0 || iDb>1 ){
165529165642
Btree *pBt = db->aDb[iDb].pBt;
165530
- if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
165643
+ if( SQLITE_TXN_NONE==sqlite3BtreeTxnState(pBt) ){
165531165644
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
165532165645
if( rc==SQLITE_OK ){
165533165646
rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt));
165534165647
sqlite3BtreeCommit(pBt);
165535165648
}
@@ -225723,11 +225836,11 @@
225723225836
int nArg, /* Number of args */
225724225837
sqlite3_value **apUnused /* Function arguments */
225725225838
){
225726225839
assert( nArg==0 );
225727225840
UNUSED_PARAM2(nArg, apUnused);
225728
- sqlite3_result_text(pCtx, "fts5: 2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f", -1, SQLITE_TRANSIENT);
225841
+ sqlite3_result_text(pCtx, "fts5: 2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492", -1, SQLITE_TRANSIENT);
225729225842
}
225730225843
225731225844
/*
225732225845
** Return true if zName is the extension on one of the shadow tables used
225733225846
** by this module.
@@ -230506,12 +230619,12 @@
230506230619
}
230507230620
#endif /* SQLITE_CORE */
230508230621
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
230509230622
230510230623
/************** End of stmt.c ************************************************/
230511
-#if __LINE__!=230511
230624
+#if __LINE__!=230624
230512230625
#undef SQLITE_SOURCE_ID
230513
-#define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt2"
230626
+#define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36alt2"
230514230627
#endif
230515230628
/* Return the source-id for this library */
230516230629
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
230517230630
/************************** End of sqlite3.c ******************************/
230518230631
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.33.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.
@@ -1169,13 +1169,13 @@
1169 **
1170 ** See also: [sqlite3_libversion()],
1171 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1172 ** [sqlite_version()] and [sqlite_source_id()].
1173 */
1174 #define SQLITE_VERSION "3.33.0"
1175 #define SQLITE_VERSION_NUMBER 3033000
1176 #define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f"
1177
1178 /*
1179 ** CAPI3REF: Run-Time Library Version Numbers
1180 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1181 **
@@ -7232,10 +7232,61 @@
7232 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
7233 ** the name of a database on connection D.
7234 */
7235 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
7236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7237 /*
7238 ** CAPI3REF: Find the next prepared statement
7239 ** METHOD: sqlite3
7240 **
7241 ** ^This interface returns a pointer to the next [prepared statement] after
@@ -10391,10 +10442,11 @@
10391 */
10392 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
10393
10394 /*
10395 ** CAPI3REF: Flush caches to disk mid-transaction
 
10396 **
10397 ** ^If a write-transaction is open on [database connection] D when the
10398 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10399 ** pages in the pager-cache that are not currently in use are written out
10400 ** to disk. A dirty page may be in use if a database cursor created by an
@@ -10423,10 +10475,11 @@
10423 */
10424 SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10425
10426 /*
10427 ** CAPI3REF: The pre-update hook.
 
10428 **
10429 ** ^These interfaces are only available if SQLite is compiled using the
10430 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
10431 **
10432 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
@@ -10525,10 +10578,11 @@
10525 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
10526 #endif
10527
10528 /*
10529 ** CAPI3REF: Low-level system error code
 
10530 **
10531 ** ^Attempt to return the underlying operating system error code or error
10532 ** number that caused the most recent I/O error or failure to open a file.
10533 ** The return value is OS-dependent. For example, on unix systems, after
10534 ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
@@ -13295,15 +13349,11 @@
13295
13296 /*
13297 ** The maximum depth of an expression tree. This is limited to
13298 ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
13299 ** want to place more severe limits on the complexity of an
13300 ** expression.
13301 **
13302 ** A value of 0 used to mean that the limit was not enforced.
13303 ** But that is no longer true. The limit is now strictly enforced
13304 ** at all times.
13305 */
13306 #ifndef SQLITE_MAX_EXPR_DEPTH
13307 # define SQLITE_MAX_EXPR_DEPTH 1000
13308 #endif
13309
@@ -15080,12 +15130,11 @@
15080 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
15081 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
15082 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
15083 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
15084 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags);
15085 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
15086 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
15087 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
15088 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
15089 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
15090 #ifndef SQLITE_OMIT_SHARED_CACHE
15091 SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
@@ -18076,11 +18125,11 @@
18076 #define EP_Skip 0x001000 /* Operator does not contribute to affinity */
18077 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18078 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18079 #define EP_Win 0x008000 /* Contains window functions */
18080 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
18081 /* 0x020000 // available for reuse */
18082 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
18083 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18084 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
18085 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
18086 #define EP_Alias 0x400000 /* Is an alias for a result set column */
@@ -18314,13 +18363,13 @@
18314 ** the OR optimization */
18315 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
18316 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
18317 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
18318 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18319 #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */
18320 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18321 #define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */
18322 /* 0x2000 not currently used */
18323 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
18324 /* 0x8000 not currently used */
18325
18326 /* Allowed return values from sqlite3WhereIsDistinct()
@@ -33470,11 +33519,12 @@
33470 #ifndef HAVE_GETHOSTUUID
33471 # define HAVE_GETHOSTUUID 0
33472 # if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
33473 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
33474 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
33475 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
 
33476 # undef HAVE_GETHOSTUUID
33477 # define HAVE_GETHOSTUUID 1
33478 # else
33479 # warning "gethostuuid() is disabled."
33480 # endif
@@ -63837,14 +63887,28 @@
63837 ** Btree.inTrans may take one of the following values.
63838 **
63839 ** If the shared-data extension is enabled, there may be multiple users
63840 ** of the Btree structure. At most one of these may open a write transaction,
63841 ** but any number may have active read transactions.
 
 
 
63842 */
63843 #define TRANS_NONE 0
63844 #define TRANS_READ 1
63845 #define TRANS_WRITE 2
 
 
 
 
 
 
 
 
 
 
 
63846
63847 /*
63848 ** An instance of this object represents a single database file.
63849 **
63850 ** A single database file can be in use at the same time by two
@@ -74791,15 +74855,16 @@
74791 assert( p->pBt->pPager!=0 );
74792 return sqlite3PagerJournalname(p->pBt->pPager);
74793 }
74794
74795 /*
74796 ** Return non-zero if a transaction is active.
 
74797 */
74798 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *p){
74799 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
74800 return (p && (p->inTrans==TRANS_WRITE));
74801 }
74802
74803 #ifndef SQLITE_OMIT_WAL
74804 /*
74805 ** Run a checkpoint on the Btree passed as the first argument.
@@ -74824,18 +74889,12 @@
74824 return rc;
74825 }
74826 #endif
74827
74828 /*
74829 ** Return non-zero if a read (or write) transaction is active.
74830 */
74831 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
74832 assert( p );
74833 assert( sqlite3_mutex_held(p->db->mutex) );
74834 return p->inTrans!=TRANS_NONE;
74835 }
74836
74837 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree *p){
74838 assert( p );
74839 assert( sqlite3_mutex_held(p->db->mutex) );
74840 return p->nBackup!=0;
74841 }
@@ -75177,11 +75236,11 @@
75177 ** second argument. If there is not, return SQLITE_OK. Otherwise, if there
75178 ** is an open read-transaction, return SQLITE_ERROR and leave an error
75179 ** message in database handle db.
75180 */
75181 static int checkReadTransaction(sqlite3 *db, Btree *p){
75182 if( sqlite3BtreeIsInReadTrans(p) ){
75183 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
75184 return SQLITE_ERROR;
75185 }
75186 return SQLITE_OK;
75187 }
@@ -75408,11 +75467,11 @@
75408
75409 /* If there is no open read-transaction on the source database, open
75410 ** one now. If a transaction is opened here, then it will be closed
75411 ** before this function exits.
75412 */
75413 if( rc==SQLITE_OK && 0==sqlite3BtreeIsInReadTrans(p->pSrc) ){
75414 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
75415 bCloseTrans = 1;
75416 }
75417
75418 /* If the destination database has not yet been locked (i.e. if this
@@ -75780,11 +75839,11 @@
75780 sqlite3_file *pFd; /* File descriptor for database pTo */
75781 sqlite3_backup b;
75782 sqlite3BtreeEnter(pTo);
75783 sqlite3BtreeEnter(pFrom);
75784
75785 assert( sqlite3BtreeIsInTrans(pTo) );
75786 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
75787 if( pFd->pMethods ){
75788 i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
75789 rc = sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
75790 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
@@ -75816,11 +75875,11 @@
75816 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
75817 }else{
75818 sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
75819 }
75820
75821 assert( sqlite3BtreeIsInTrans(pTo)==0 );
75822 copy_finished:
75823 sqlite3BtreeLeave(pFrom);
75824 sqlite3BtreeLeave(pTo);
75825 return rc;
75826 }
@@ -80399,11 +80458,11 @@
80399 ** one database file has an open write transaction, a super-journal
80400 ** file is required for an atomic commit.
80401 */
80402 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80403 Btree *pBt = db->aDb[i].pBt;
80404 if( sqlite3BtreeIsInTrans(pBt) ){
80405 /* Whether or not a database might need a super-journal depends upon
80406 ** its journal mode (among other things). This matrix determines which
80407 ** journal modes use a super-journal and which do not */
80408 static const u8 aMJNeeded[] = {
80409 /* DELETE */ 1,
@@ -80534,11 +80593,11 @@
80534 ** still have 'null' as the super-journal pointer, so they will roll
80535 ** back independently if a failure occurs.
80536 */
80537 for(i=0; i<db->nDb; i++){
80538 Btree *pBt = db->aDb[i].pBt;
80539 if( sqlite3BtreeIsInTrans(pBt) ){
80540 char const *zFile = sqlite3BtreeGetJournalname(pBt);
80541 if( zFile==0 ){
80542 continue; /* Ignore TEMP and :memory: databases */
80543 }
80544 assert( zFile[0]!=0 );
@@ -88871,11 +88930,11 @@
88871
88872 if( p->usesStmtJournal
88873 && pOp->p2
88874 && (db->autoCommit==0 || db->nVdbeRead>1)
88875 ){
88876 assert( sqlite3BtreeIsInTrans(pBt) );
88877 if( p->iStatement==0 ){
88878 assert( db->nStatement>=0 && db->nSavepoint>=0 );
88879 db->nStatement++;
88880 p->iStatement = db->nSavepoint + db->nStatement;
88881 }
@@ -92363,11 +92422,11 @@
92363 }
92364
92365 /* Open a transaction on the database file. Regardless of the journal
92366 ** mode, this transaction always uses a rollback journal.
92367 */
92368 assert( sqlite3BtreeIsInTrans(pBt)==0 );
92369 if( rc==SQLITE_OK ){
92370 rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
92371 }
92372 }
92373 }
@@ -98828,11 +98887,11 @@
98828 case TK_ISNOT: {
98829 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
98830 assert( !ExprHasProperty(pExpr, EP_Reduced) );
98831 /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
98832 ** and "x IS NOT FALSE". */
98833 if( pRight && pRight->op==TK_ID ){
98834 int rc = resolveExprStep(pWalker, pRight);
98835 if( rc==WRC_Abort ) return WRC_Abort;
98836 if( pRight->op==TK_TRUEFALSE ){
98837 pExpr->op2 = pExpr->op;
98838 pExpr->op = TK_TRUTH;
@@ -99756,11 +99815,11 @@
99756 ** SELECT a AS b FROM t1 WHERE b;
99757 ** SELECT * FROM t1 WHERE (select a from t1);
99758 */
99759 SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
99760 int op;
99761 while( ExprHasProperty(pExpr, EP_Skip) ){
99762 assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
99763 pExpr = pExpr->pLeft;
99764 assert( pExpr!=0 );
99765 }
99766 op = pExpr->op;
@@ -99827,11 +99886,11 @@
99827 /*
99828 ** Skip over any TK_COLLATE operators.
99829 */
99830 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
99831 while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
99832 assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
99833 pExpr = pExpr->pLeft;
99834 }
99835 return pExpr;
99836 }
99837
@@ -99846,11 +99905,11 @@
99846 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
99847 assert( pExpr->x.pList->nExpr>0 );
99848 assert( pExpr->op==TK_FUNCTION );
99849 pExpr = pExpr->x.pList->a[0].pExpr;
99850 }else{
99851 assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
99852 pExpr = pExpr->pLeft;
99853 }
99854 }
99855 return pExpr;
99856 }
@@ -100480,10 +100539,11 @@
100480 /*
100481 ** Propagate all EP_Propagate flags from the Expr.x.pList into
100482 ** Expr.flags.
100483 */
100484 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
 
100485 if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
100486 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
100487 }
100488 }
100489 #define exprSetHeight(y)
@@ -109785,11 +109845,13 @@
109785 }
109786 if( i<2 ){
109787 sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
109788 goto detach_error;
109789 }
109790 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
 
 
109791 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
109792 goto detach_error;
109793 }
109794
109795 /* If any TEMP triggers reference the schema being detached, move those
@@ -110445,18 +110507,19 @@
110445 int iDb, /* Index of the database containing the table to lock */
110446 Pgno iTab, /* Root page number of the table to be locked */
110447 u8 isWriteLock, /* True for a write lock */
110448 const char *zName /* Name of the table to be locked */
110449 ){
110450 Parse *pToplevel = sqlite3ParseToplevel(pParse);
110451 int i;
110452 int nBytes;
110453 TableLock *p;
110454 assert( iDb>=0 );
110455
110456 if( iDb==1 ) return;
110457 if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
 
110458 for(i=0; i<pToplevel->nTableLock; i++){
110459 p = &pToplevel->aTableLock[i];
110460 if( p->iDb==iDb && p->iTab==iTab ){
110461 p->isWriteLock = (p->isWriteLock || isWriteLock);
110462 return;
@@ -110482,14 +110545,12 @@
110482 ** Code an OP_TableLock instruction for each table locked by the
110483 ** statement (configured by calls to sqlite3TableLock()).
110484 */
110485 static void codeTableLocks(Parse *pParse){
110486 int i;
110487 Vdbe *pVdbe;
110488
110489 pVdbe = sqlite3GetVdbe(pParse);
110490 assert( pVdbe!=0 ); /* sqlite3GetVdbe cannot fail: VDBE already allocated */
110491
110492 for(i=0; i<pParse->nTableLock; i++){
110493 TableLock *p = &pParse->aTableLock[i];
110494 int p1 = p->iDb;
110495 sqlite3VdbeAddOp4(pVdbe, OP_TableLock, p1, p->iTab, p->isWriteLock,
@@ -114858,19 +114919,19 @@
114858 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
114859 int i;
114860 struct SrcList_item *pItem;
114861 if( pList==0 ) return;
114862 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
114863 sqlite3DbFree(db, pItem->zDatabase);
114864 sqlite3DbFree(db, pItem->zName);
114865 sqlite3DbFree(db, pItem->zAlias);
114866 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
114867 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
114868 sqlite3DeleteTable(db, pItem->pTab);
114869 sqlite3SelectDelete(db, pItem->pSelect);
114870 sqlite3ExprDelete(db, pItem->pOn);
114871 sqlite3IdListDelete(db, pItem->pUsing);
114872 }
114873 sqlite3DbFreeNN(db, pList);
114874 }
114875
114876 /*
@@ -115127,24 +115188,26 @@
115127 ** Record the fact that the schema cookie will need to be verified
115128 ** for database iDb. The code to actually verify the schema cookie
115129 ** will occur at the end of the top-level VDBE and will be generated
115130 ** later, by sqlite3FinishCoding().
115131 */
115132 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
115133 Parse *pToplevel = sqlite3ParseToplevel(pParse);
115134
115135 assert( iDb>=0 && iDb<pParse->db->nDb );
115136 assert( pParse->db->aDb[iDb].pBt!=0 || iDb==1 );
115137 assert( iDb<SQLITE_MAX_ATTACHED+2 );
115138 assert( sqlite3SchemaMutexHeld(pParse->db, iDb, 0) );
115139 if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
115140 DbMaskSet(pToplevel->cookieMask, iDb);
115141 if( !OMIT_TEMPDB && iDb==1 ){
115142 sqlite3OpenTempDatabase(pToplevel);
115143 }
115144 }
115145 }
 
 
 
 
115146
115147 /*
115148 ** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
115149 ** attached database. Otherwise, invoke it for the database named zDb only.
115150 */
@@ -115172,11 +115235,11 @@
115172 ** can be checked before any changes are made to the database, it is never
115173 ** necessary to undo a write and the checkpoint should not be set.
115174 */
115175 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
115176 Parse *pToplevel = sqlite3ParseToplevel(pParse);
115177 sqlite3CodeVerifySchema(pParse, iDb);
115178 DbMaskSet(pToplevel->writeMask, iDb);
115179 pToplevel->isMultiWrite |= setStatement;
115180 }
115181
115182 /*
@@ -115223,11 +115286,13 @@
115223 int onError, /* Constraint type */
115224 char *p4, /* Error message */
115225 i8 p4type, /* P4_STATIC or P4_TRANSIENT */
115226 u8 p5Errmsg /* P5_ErrMsg type */
115227 ){
115228 Vdbe *v = sqlite3GetVdbe(pParse);
 
 
115229 assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );
115230 if( onError==OE_Abort ){
115231 sqlite3MayAbort(pParse);
115232 }
115233 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
@@ -116504,11 +116569,11 @@
116504 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
116505 }
116506 }else
116507 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
116508 {
116509 u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK|WHERE_SEEK_TABLE;
116510 if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
116511 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
116512 if( HasRowid(pTab) ){
116513 /* For a rowid table, initialize the RowSet to an empty set */
116514 pPk = 0;
@@ -116540,10 +116605,13 @@
116540 if( pWInfo==0 ) goto delete_from_cleanup;
116541 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
116542 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
116543 assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF );
116544 if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse);
 
 
 
116545
116546 /* Keep track of the number of rows to be deleted */
116547 if( memCnt ){
116548 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
116549 }
@@ -116574,10 +116642,11 @@
116574 memset(aToOpen, 1, nIdx+1);
116575 aToOpen[nIdx+1] = 0;
116576 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
116577 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
116578 if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
 
116579 }else{
116580 if( pPk ){
116581 /* Add the PK key for this row to the temporary table */
116582 iKey = ++pParse->nMem;
116583 nKey = 0; /* Zero tells OP_Found to use a composite key */
@@ -116587,17 +116656,10 @@
116587 }else{
116588 /* Add the rowid of the row to be deleted to the RowSet */
116589 nKey = 1; /* OP_DeferredSeek always uses a single rowid */
116590 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
116591 }
116592 }
116593
116594 /* If this DELETE cannot use the ONEPASS strategy, this is the
116595 ** end of the WHERE loop */
116596 if( eOnePass!=ONEPASS_OFF ){
116597 addrBypass = sqlite3VdbeMakeLabel(pParse);
116598 }else{
116599 sqlite3WhereEnd(pWInfo);
116600 }
116601
116602 /* Unless this is a view, open cursors for the table we are
116603 ** deleting from and all its indices. If this is a view, then the
@@ -120583,11 +120645,12 @@
120583 Table *pTab, /* The table to be opened */
120584 int opcode /* OP_OpenRead or OP_OpenWrite */
120585 ){
120586 Vdbe *v;
120587 assert( !IsVirtual(pTab) );
120588 v = sqlite3GetVdbe(pParse);
 
120589 assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
120590 sqlite3TableLock(pParse, iDb, pTab->tnum,
120591 (opcode==OP_OpenWrite)?1:0, pTab->zName);
120592 if( HasRowid(pTab) ){
120593 sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
@@ -122082,11 +122145,11 @@
122082 Trigger *pTrigger; /* List of DELETE triggers on the table pTab */
122083 int nReplaceTrig = 0; /* Number of replace triggers coded */
122084
122085 isUpdate = regOldData!=0;
122086 db = pParse->db;
122087 v = sqlite3GetVdbe(pParse);
122088 assert( v!=0 );
122089 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122090 nCol = pTab->nCol;
122091
122092 /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
@@ -122855,11 +122918,11 @@
122855 assert( update_flags==0
122856 || update_flags==OPFLAG_ISUPDATE
122857 || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
122858 );
122859
122860 v = sqlite3GetVdbe(pParse);
122861 assert( v!=0 );
122862 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122863 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
122864 /* All REPLACE indexes are at the end of the list */
122865 assert( pIdx->onError!=OE_Replace
@@ -122956,11 +123019,11 @@
122956 ** variables *piDataCur and *piIdxCur uninitialized so that valgrind
122957 ** can detect if they are used by mistake in the caller. */
122958 return 0;
122959 }
122960 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
122961 v = sqlite3GetVdbe(pParse);
122962 assert( v!=0 );
122963 if( iBase<0 ) iBase = pParse->nTab;
122964 iDataCur = iBase++;
122965 if( piDataCur ) *piDataCur = iDataCur;
122966 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
@@ -125874,11 +125937,13 @@
125874 ** from default, or when 'file' and the temp_store_directory has changed
125875 */
125876 static int invalidateTempStorage(Parse *pParse){
125877 sqlite3 *db = pParse->db;
125878 if( db->aDb[1].pBt!=0 ){
125879 if( !db->autoCommit || sqlite3BtreeIsInReadTrans(db->aDb[1].pBt) ){
 
 
125880 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
125881 "from within a transaction");
125882 return SQLITE_ERROR;
125883 }
125884 sqlite3BtreeClose(db->aDb[1].pBt);
@@ -128577,11 +128642,11 @@
128577
128578 /* If there is not already a read-only (or read-write) transaction opened
128579 ** on the b-tree database, open one now. If a transaction is opened, it
128580 ** will be closed before this function returns. */
128581 sqlite3BtreeEnter(pDb->pBt);
128582 if( !sqlite3BtreeIsInReadTrans(pDb->pBt) ){
128583 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0, 0);
128584 if( rc!=SQLITE_OK ){
128585 sqlite3SetString(pzErrMsg, db, sqlite3ErrStr(rc));
128586 goto initone_error_out;
128587 }
@@ -128820,11 +128885,11 @@
128820 if( pBt==0 ) continue;
128821
128822 /* If there is not already a read-only (or read-write) transaction opened
128823 ** on the b-tree database, open one now. If a transaction is opened, it
128824 ** will be closed immediately after reading the meta-value. */
128825 if( !sqlite3BtreeIsInReadTrans(pBt) ){
128826 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
128827 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
128828 sqlite3OomFault(db);
128829 }
128830 if( rc!=SQLITE_OK ) return;
@@ -132803,11 +132868,11 @@
132803 if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
132804 memset(&ifNullRow, 0, sizeof(ifNullRow));
132805 ifNullRow.op = TK_IF_NULL_ROW;
132806 ifNullRow.pLeft = pCopy;
132807 ifNullRow.iTable = pSubst->iNewTable;
132808 ifNullRow.flags = EP_Skip;
132809 pCopy = &ifNullRow;
132810 }
132811 testcase( ExprHasProperty(pCopy, EP_Subquery) );
132812 pNew = sqlite3ExprDup(db, pCopy, 0);
132813 if( pNew && pSubst->isLeftJoin ){
@@ -138304,11 +138369,11 @@
138304 ** Do not consider a single-pass strategy for a multi-row update if
138305 ** there are any triggers or foreign keys to process, or rows may
138306 ** be deleted as a result of REPLACE conflict handling. Any of these
138307 ** things might disturb a cursor being used to scan through the table
138308 ** or index, causing a single-pass approach to malfunction. */
138309 flags = WHERE_ONEPASS_DESIRED|WHERE_SEEK_UNIQ_TABLE;
138310 if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
138311 flags |= WHERE_ONEPASS_MULTIROW;
138312 }
138313 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur);
138314 if( pWInfo==0 ) goto update_cleanup;
@@ -139507,12 +139572,12 @@
139507 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
139508 BTREE_USER_VERSION, 0, /* Preserve the user version */
139509 BTREE_APPLICATION_ID, 0, /* Preserve the application id */
139510 };
139511
139512 assert( 1==sqlite3BtreeIsInTrans(pTemp) );
139513 assert( pOut!=0 || 1==sqlite3BtreeIsInTrans(pMain) );
139514
139515 /* Copy Btree meta values */
139516 for(i=0; i<ArraySize(aCopy); i+=2){
139517 /* GetMeta() and UpdateMeta() cannot fail in this context because
139518 ** we already have page 1 loaded into cache and marked dirty. */
@@ -141406,10 +141471,11 @@
141406 unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
141407 unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
141408 unsigned sorted :1; /* True if really sorted (not just grouped) */
141409 LogEst nRowOut; /* Estimated number of output rows */
141410 int iTop; /* The very beginning of the WHERE loop */
 
141411 WhereLoop *pLoops; /* List of all WhereLoop objects */
141412 WhereExprMod *pExprMods; /* Expression modifications */
141413 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
141414 WhereClause sWC; /* Decomposition of the WHERE clause */
141415 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
@@ -143275,11 +143341,12 @@
143275 nConstraint = nEq;
143276 if( pRangeStart ){
143277 Expr *pRight = pRangeStart->pExpr->pRight;
143278 codeExprOrVector(pParse, pRight, regBase+nEq, nBtm);
143279 whereLikeOptimizationStringFixup(v, pLevel, pRangeStart);
143280 if( (pRangeStart->wtFlags & TERM_VNULL)==0
 
143281 && sqlite3ExprCanBeNull(pRight)
143282 ){
143283 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143284 VdbeCoverage(v);
143285 }
@@ -143353,11 +143420,12 @@
143353 nConstraint = nEq;
143354 if( pRangeEnd ){
143355 Expr *pRight = pRangeEnd->pExpr->pRight;
143356 codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
143357 whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
143358 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
 
143359 && sqlite3ExprCanBeNull(pRight)
143360 ){
143361 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143362 VdbeCoverage(v);
143363 }
@@ -143429,21 +143497,11 @@
143429 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
143430 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
143431 if( omitTable ){
143432 /* pIdx is a covering index. No need to access the main table. */
143433 }else if( HasRowid(pIdx->pTable) ){
143434 if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)
143435 || ( (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)!=0
143436 && (pWInfo->eOnePass==ONEPASS_SINGLE || pLoop->nLTerm==0) )
143437 ){
143438 iRowidReg = ++pParse->nMem;
143439 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
143440 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
143441 VdbeCoverage(v);
143442 }else{
143443 codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur);
143444 }
143445 }else if( iCur!=iIdxCur ){
143446 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
143447 iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
143448 for(j=0; j<pPk->nKeyCol; j++){
143449 k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]);
@@ -143566,11 +143624,10 @@
143566 int regRowid = 0; /* Register holding rowid */
143567 int iLoopBody = sqlite3VdbeMakeLabel(pParse);/* Start of loop body */
143568 int iRetInit; /* Address of regReturn init */
143569 int untestedTerms = 0; /* Some terms not completely tested */
143570 int ii; /* Loop counter */
143571 u16 wctrlFlags; /* Flags for sub-WHERE clause */
143572 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
143573 Table *pTab = pTabItem->pTab;
143574
143575 pTerm = pLoop->aLTerm[0];
143576 assert( pTerm!=0 );
@@ -143667,11 +143724,10 @@
143667
143668 /* Run a separate WHERE clause for each term of the OR clause. After
143669 ** eliminating duplicates from other WHERE clauses, the action for each
143670 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
143671 */
143672 wctrlFlags = WHERE_OR_SUBCLAUSE | (pWInfo->wctrlFlags & WHERE_SEEK_TABLE);
143673 ExplainQueryPlan((pParse, 1, "MULTI-INDEX OR"));
143674 for(ii=0; ii<pOrWc->nTerm; ii++){
143675 WhereTerm *pOrTerm = &pOrWc->a[ii];
143676 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
143677 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
@@ -143686,11 +143742,11 @@
143686 }
143687 /* Loop through table entries that match term pOrTerm. */
143688 ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
143689 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
143690 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
143691 wctrlFlags, iCovCur);
143692 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
143693 if( pSubWInfo ){
143694 WhereLoop *pSubLoop;
143695 int addrExplain = sqlite3WhereExplainOneScan(
143696 pParse, pOrTab, &pSubWInfo->a[0], 0
@@ -143783,10 +143839,13 @@
143783 ){
143784 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
143785 pCov = pSubLoop->u.btree.pIndex;
143786 }else{
143787 pCov = 0;
 
 
 
143788 }
143789
143790 /* Finish the loop through table entries that match term pOrTerm. */
143791 sqlite3WhereEnd(pSubWInfo);
143792 ExplainQueryPlanPop(pParse);
@@ -149662,20 +149721,28 @@
149662 ** sorting cost to:
149663 **
149664 ** cost = (3.0 * N * log(N)) * (Y/X)
149665 **
149666 ** The (Y/X) term is implemented using stack variable rScale
149667 ** below. */
 
149668 LogEst rScale, rSortCost;
149669 assert( nOrderBy>0 && 66==sqlite3LogEst(100) );
149670 rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
149671 rSortCost = nRow + rScale + 16;
149672
149673 /* Multiple by log(M) where M is the number of output rows.
149674 ** Use the LIMIT for M if it is smaller */
 
 
 
149675 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
149676 nRow = pWInfo->iLimit;
 
 
 
 
149677 }
149678 rSortCost += estLog(nRow);
149679 return rSortCost;
149680 }
149681
@@ -150855,10 +150922,11 @@
150855 }
150856 }
150857
150858 /* Done. */
150859 VdbeModuleComment((v, "Begin WHERE-core"));
 
150860 return pWInfo;
150861
150862 /* Jump here if malloc fails */
150863 whereBeginError:
150864 if( pWInfo ){
@@ -150898,10 +150966,11 @@
150898 int i;
150899 WhereLevel *pLevel;
150900 WhereLoop *pLoop;
150901 SrcList *pTabList = pWInfo->pTabList;
150902 sqlite3 *db = pParse->db;
 
150903
150904 /* Generate loop termination code.
150905 */
150906 VdbeModuleComment((v, "End WHERE-core"));
150907 for(i=pWInfo->nLevel-1; i>=0; i--){
@@ -151035,11 +151104,11 @@
151035 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
151036
151037 assert( pWInfo->nLevel<=pTabList->nSrc );
151038 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
151039 int k, last;
151040 VdbeOp *pOp;
151041 Index *pIdx = 0;
151042 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
151043 Table *pTab = pTabItem->pTab;
151044 assert( pTab!=0 );
151045 pLoop = pLevel->pWLoop;
@@ -151093,24 +151162,35 @@
151093 pIdx = pLoop->u.btree.pIndex;
151094 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
151095 pIdx = pLevel->u.pCovidx;
151096 }
151097 if( pIdx
151098 && (pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable))
151099 && !db->mallocFailed
151100 ){
151101 last = sqlite3VdbeCurrentAddr(v);
151102 k = pLevel->addrBody;
 
 
 
 
151103 #ifdef SQLITE_DEBUG
151104 if( db->flags & SQLITE_VdbeAddopTrace ){
151105 printf("TRANSLATE opcodes in range %d..%d\n", k, last-1);
151106 }
 
 
 
 
 
151107 #endif
151108 pOp = sqlite3VdbeGetOp(v, k);
151109 for(; k<last; k++, pOp++){
151110 if( pOp->p1!=pLevel->iTabCur ) continue;
151111 if( pOp->opcode==OP_Column
 
 
 
151112 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
151113 || pOp->opcode==OP_Offset
151114 #endif
151115 ){
151116 int x = pOp->p2;
@@ -151137,11 +151217,14 @@
151137 OpcodeRewriteTrace(db, k, pOp);
151138 }else if( pOp->opcode==OP_IfNullRow ){
151139 pOp->p1 = pLevel->iIdxCur;
151140 OpcodeRewriteTrace(db, k, pOp);
151141 }
151142 }
 
 
 
151143 #ifdef SQLITE_DEBUG
151144 if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
151145 #endif
151146 }
151147 }
@@ -161894,11 +161977,11 @@
161894 #endif
161895 sqlite3_mutex_enter(db->mutex);
161896 sqlite3BtreeEnterAll(db);
161897 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
161898 Btree *pBt = db->aDb[i].pBt;
161899 if( pBt && sqlite3BtreeIsInTrans(pBt) ){
161900 Pager *pPager = sqlite3BtreePager(pBt);
161901 rc = sqlite3PagerFlush(pPager);
161902 if( rc==SQLITE_BUSY ){
161903 bSeenBusy = 1;
161904 rc = SQLITE_OK;
@@ -162237,10 +162320,40 @@
162237 */
162238 db->magic = SQLITE_MAGIC_ZOMBIE;
162239 sqlite3LeaveMutexAndCloseZombie(db);
162240 return SQLITE_OK;
162241 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162242
162243 /*
162244 ** Two variations on the public interface for closing a database
162245 ** connection. The sqlite3_close() version returns SQLITE_BUSY and
162246 ** leaves the connection option if there are unfinalized prepared
@@ -162398,11 +162511,11 @@
162398 schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
162399
162400 for(i=0; i<db->nDb; i++){
162401 Btree *p = db->aDb[i].pBt;
162402 if( p ){
162403 if( sqlite3BtreeIsInTrans(p) ){
162404 inTrans = 1;
162405 }
162406 sqlite3BtreeRollback(p, tripCode, !schemaChange);
162407 }
162408 }
@@ -165437,11 +165550,11 @@
165437
165438 if( db->autoCommit==0 ){
165439 int iDb = sqlite3FindDbName(db, zDb);
165440 if( iDb==0 || iDb>1 ){
165441 Btree *pBt = db->aDb[iDb].pBt;
165442 if( 0==sqlite3BtreeIsInTrans(pBt) ){
165443 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
165444 if( rc==SQLITE_OK ){
165445 rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
165446 }
165447 }
@@ -165473,14 +165586,14 @@
165473 if( db->autoCommit==0 ){
165474 int iDb;
165475 iDb = sqlite3FindDbName(db, zDb);
165476 if( iDb==0 || iDb>1 ){
165477 Btree *pBt = db->aDb[iDb].pBt;
165478 if( sqlite3BtreeIsInTrans(pBt)==0 ){
165479 Pager *pPager = sqlite3BtreePager(pBt);
165480 int bUnlock = 0;
165481 if( sqlite3BtreeIsInReadTrans(pBt) ){
165482 if( db->nVdbeActive==0 ){
165483 rc = sqlite3PagerSnapshotCheck(pPager, pSnapshot);
165484 if( rc==SQLITE_OK ){
165485 bUnlock = 1;
165486 rc = sqlite3BtreeCommit(pBt);
@@ -165525,11 +165638,11 @@
165525
165526 sqlite3_mutex_enter(db->mutex);
165527 iDb = sqlite3FindDbName(db, zDb);
165528 if( iDb==0 || iDb>1 ){
165529 Btree *pBt = db->aDb[iDb].pBt;
165530 if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
165531 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
165532 if( rc==SQLITE_OK ){
165533 rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt));
165534 sqlite3BtreeCommit(pBt);
165535 }
@@ -225723,11 +225836,11 @@
225723 int nArg, /* Number of args */
225724 sqlite3_value **apUnused /* Function arguments */
225725 ){
225726 assert( nArg==0 );
225727 UNUSED_PARAM2(nArg, apUnused);
225728 sqlite3_result_text(pCtx, "fts5: 2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f", -1, SQLITE_TRANSIENT);
225729 }
225730
225731 /*
225732 ** Return true if zName is the extension on one of the shadow tables used
225733 ** by this module.
@@ -230506,12 +230619,12 @@
230506 }
230507 #endif /* SQLITE_CORE */
230508 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
230509
230510 /************** End of stmt.c ************************************************/
230511 #if __LINE__!=230511
230512 #undef SQLITE_SOURCE_ID
230513 #define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt2"
230514 #endif
230515 /* Return the source-id for this library */
230516 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
230517 /************************** End of sqlite3.c ******************************/
230518
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.34.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.
@@ -1169,13 +1169,13 @@
1169 **
1170 ** See also: [sqlite3_libversion()],
1171 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1172 ** [sqlite_version()] and [sqlite_source_id()].
1173 */
1174 #define SQLITE_VERSION "3.34.0"
1175 #define SQLITE_VERSION_NUMBER 3034000
1176 #define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492"
1177
1178 /*
1179 ** CAPI3REF: Run-Time Library Version Numbers
1180 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1181 **
@@ -7232,10 +7232,61 @@
7232 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
7233 ** the name of a database on connection D.
7234 */
7235 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
7236
7237 /*
7238 ** CAPI3REF: Determine the transaction state of a database
7239 ** METHOD: sqlite3
7240 **
7241 ** ^The sqlite3_txn_state(D,S) interface returns the current
7242 ** [transaction state] of schema S in database connection D. ^If S is NULL,
7243 ** then the highest transaction state of any schema on databse connection D
7244 ** is returned. Transaction states are (in order of lowest to highest):
7245 ** <ol>
7246 ** <li value="0"> SQLITE_TXN_NONE
7247 ** <li value="1"> SQLITE_TXN_READ
7248 ** <li value="2"> SQLITE_TXN_WRITE
7249 ** </ol>
7250 ** ^If the S argument to sqlite3_txn_state(D,S) is in the name of
7251 ** a valid schema, then -1 is returned.
7252 */
7253 SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
7254
7255 /*
7256 ** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
7257 ** KEYWORDS: {transaction state}
7258 **
7259 ** These constants define the current transaction state of a database file.
7260 ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
7261 ** constants in order to describe the transaction state of schema S
7262 ** in [database connection] D.
7263 **
7264 ** <dl>
7265 ** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
7266 ** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
7267 ** pending.</dd>
7268 **
7269 ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
7270 ** <dd>The SQLITE_TXN_READ state means that the database is currently
7271 ** in a read transaction. Content has been read from the database file
7272 ** but nothing in the database file has changed. The transaction state
7273 ** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
7274 ** no other conflicting concurrent write transactions. The transaction
7275 ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
7276 ** [COMMIT].</dd>
7277 **
7278 ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
7279 ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
7280 ** in a write transaction. Content has been written to the database file
7281 ** but has not yet committed. The transaction state will change to
7282 ** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
7283 */
7284 #define SQLITE_TXN_NONE 0
7285 #define SQLITE_TXN_READ 1
7286 #define SQLITE_TXN_WRITE 2
7287
7288 /*
7289 ** CAPI3REF: Find the next prepared statement
7290 ** METHOD: sqlite3
7291 **
7292 ** ^This interface returns a pointer to the next [prepared statement] after
@@ -10391,10 +10442,11 @@
10442 */
10443 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
10444
10445 /*
10446 ** CAPI3REF: Flush caches to disk mid-transaction
10447 ** METHOD: sqlite3
10448 **
10449 ** ^If a write-transaction is open on [database connection] D when the
10450 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
10451 ** pages in the pager-cache that are not currently in use are written out
10452 ** to disk. A dirty page may be in use if a database cursor created by an
@@ -10423,10 +10475,11 @@
10475 */
10476 SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10477
10478 /*
10479 ** CAPI3REF: The pre-update hook.
10480 ** METHOD: sqlite3
10481 **
10482 ** ^These interfaces are only available if SQLite is compiled using the
10483 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
10484 **
10485 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
@@ -10525,10 +10578,11 @@
10578 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
10579 #endif
10580
10581 /*
10582 ** CAPI3REF: Low-level system error code
10583 ** METHOD: sqlite3
10584 **
10585 ** ^Attempt to return the underlying operating system error code or error
10586 ** number that caused the most recent I/O error or failure to open a file.
10587 ** The return value is OS-dependent. For example, on unix systems, after
10588 ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
@@ -13295,15 +13349,11 @@
13349
13350 /*
13351 ** The maximum depth of an expression tree. This is limited to
13352 ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
13353 ** want to place more severe limits on the complexity of an
13354 ** expression. A value of 0 means that there is no limit.
 
 
 
 
13355 */
13356 #ifndef SQLITE_MAX_EXPR_DEPTH
13357 # define SQLITE_MAX_EXPR_DEPTH 1000
13358 #endif
13359
@@ -15080,12 +15130,11 @@
15130 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
15131 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
15132 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
15133 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
15134 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags);
15135 SQLITE_PRIVATE int sqlite3BtreeTxnState(Btree*);
 
15136 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
15137 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
15138 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
15139 #ifndef SQLITE_OMIT_SHARED_CACHE
15140 SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
@@ -18076,11 +18125,11 @@
18125 #define EP_Skip 0x001000 /* Operator does not contribute to affinity */
18126 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18127 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18128 #define EP_Win 0x008000 /* Contains window functions */
18129 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
18130 #define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */
18131 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
18132 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18133 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
18134 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
18135 #define EP_Alias 0x400000 /* Is an alias for a result set column */
@@ -18314,13 +18363,13 @@
18363 ** the OR optimization */
18364 #define WHERE_GROUPBY 0x0040 /* pOrderBy is really a GROUP BY */
18365 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
18366 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
18367 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18368 /* 0x0400 not currently used */
18369 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18370 /* 0x1000 not currently used */
18371 /* 0x2000 not currently used */
18372 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
18373 /* 0x8000 not currently used */
18374
18375 /* Allowed return values from sqlite3WhereIsDistinct()
@@ -33470,11 +33519,12 @@
33519 #ifndef HAVE_GETHOSTUUID
33520 # define HAVE_GETHOSTUUID 0
33521 # if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
33522 (__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
33523 # if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
33524 && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))\
33525 && (!defined(TARGET_OS_MACCATALYST) || (TARGET_OS_MACCATALYST==0))
33526 # undef HAVE_GETHOSTUUID
33527 # define HAVE_GETHOSTUUID 1
33528 # else
33529 # warning "gethostuuid() is disabled."
33530 # endif
@@ -63837,14 +63887,28 @@
63887 ** Btree.inTrans may take one of the following values.
63888 **
63889 ** If the shared-data extension is enabled, there may be multiple users
63890 ** of the Btree structure. At most one of these may open a write transaction,
63891 ** but any number may have active read transactions.
63892 **
63893 ** These values must match SQLITE_TXN_NONE, SQLITE_TXN_READ, and
63894 ** SQLITE_TXN_WRITE
63895 */
63896 #define TRANS_NONE 0
63897 #define TRANS_READ 1
63898 #define TRANS_WRITE 2
63899
63900 #if TRANS_NONE!=SQLITE_TXN_NONE
63901 # error wrong numeric code for no-transaction
63902 #endif
63903 #if TRANS_READ!=SQLITE_TXN_READ
63904 # error wrong numeric code for read-transaction
63905 #endif
63906 #if TRANS_WRITE!=SQLITE_TXN_WRITE
63907 # error wrong numeric code for write-transaction
63908 #endif
63909
63910
63911 /*
63912 ** An instance of this object represents a single database file.
63913 **
63914 ** A single database file can be in use at the same time by two
@@ -74791,15 +74855,16 @@
74855 assert( p->pBt->pPager!=0 );
74856 return sqlite3PagerJournalname(p->pBt->pPager);
74857 }
74858
74859 /*
74860 ** Return one of SQLITE_TXN_NONE, SQLITE_TXN_READ, or SQLITE_TXN_WRITE
74861 ** to describe the current transaction state of Btree p.
74862 */
74863 SQLITE_PRIVATE int sqlite3BtreeTxnState(Btree *p){
74864 assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
74865 return p ? p->inTrans : 0;
74866 }
74867
74868 #ifndef SQLITE_OMIT_WAL
74869 /*
74870 ** Run a checkpoint on the Btree passed as the first argument.
@@ -74824,18 +74889,12 @@
74889 return rc;
74890 }
74891 #endif
74892
74893 /*
74894 ** Return true if there is currently a backup running on Btree p.
74895 */
 
 
 
 
 
 
74896 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree *p){
74897 assert( p );
74898 assert( sqlite3_mutex_held(p->db->mutex) );
74899 return p->nBackup!=0;
74900 }
@@ -75177,11 +75236,11 @@
75236 ** second argument. If there is not, return SQLITE_OK. Otherwise, if there
75237 ** is an open read-transaction, return SQLITE_ERROR and leave an error
75238 ** message in database handle db.
75239 */
75240 static int checkReadTransaction(sqlite3 *db, Btree *p){
75241 if( sqlite3BtreeTxnState(p)!=SQLITE_TXN_NONE ){
75242 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
75243 return SQLITE_ERROR;
75244 }
75245 return SQLITE_OK;
75246 }
@@ -75408,11 +75467,11 @@
75467
75468 /* If there is no open read-transaction on the source database, open
75469 ** one now. If a transaction is opened here, then it will be closed
75470 ** before this function exits.
75471 */
75472 if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){
75473 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
75474 bCloseTrans = 1;
75475 }
75476
75477 /* If the destination database has not yet been locked (i.e. if this
@@ -75780,11 +75839,11 @@
75839 sqlite3_file *pFd; /* File descriptor for database pTo */
75840 sqlite3_backup b;
75841 sqlite3BtreeEnter(pTo);
75842 sqlite3BtreeEnter(pFrom);
75843
75844 assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
75845 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
75846 if( pFd->pMethods ){
75847 i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
75848 rc = sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
75849 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
@@ -75816,11 +75875,11 @@
75875 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
75876 }else{
75877 sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
75878 }
75879
75880 assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
75881 copy_finished:
75882 sqlite3BtreeLeave(pFrom);
75883 sqlite3BtreeLeave(pTo);
75884 return rc;
75885 }
@@ -80399,11 +80458,11 @@
80458 ** one database file has an open write transaction, a super-journal
80459 ** file is required for an atomic commit.
80460 */
80461 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80462 Btree *pBt = db->aDb[i].pBt;
80463 if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){
80464 /* Whether or not a database might need a super-journal depends upon
80465 ** its journal mode (among other things). This matrix determines which
80466 ** journal modes use a super-journal and which do not */
80467 static const u8 aMJNeeded[] = {
80468 /* DELETE */ 1,
@@ -80534,11 +80593,11 @@
80593 ** still have 'null' as the super-journal pointer, so they will roll
80594 ** back independently if a failure occurs.
80595 */
80596 for(i=0; i<db->nDb; i++){
80597 Btree *pBt = db->aDb[i].pBt;
80598 if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){
80599 char const *zFile = sqlite3BtreeGetJournalname(pBt);
80600 if( zFile==0 ){
80601 continue; /* Ignore TEMP and :memory: databases */
80602 }
80603 assert( zFile[0]!=0 );
@@ -88871,11 +88930,11 @@
88930
88931 if( p->usesStmtJournal
88932 && pOp->p2
88933 && (db->autoCommit==0 || db->nVdbeRead>1)
88934 ){
88935 assert( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE );
88936 if( p->iStatement==0 ){
88937 assert( db->nStatement>=0 && db->nSavepoint>=0 );
88938 db->nStatement++;
88939 p->iStatement = db->nSavepoint + db->nStatement;
88940 }
@@ -92363,11 +92422,11 @@
92422 }
92423
92424 /* Open a transaction on the database file. Regardless of the journal
92425 ** mode, this transaction always uses a rollback journal.
92426 */
92427 assert( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_WRITE );
92428 if( rc==SQLITE_OK ){
92429 rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
92430 }
92431 }
92432 }
@@ -98828,11 +98887,11 @@
98887 case TK_ISNOT: {
98888 Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
98889 assert( !ExprHasProperty(pExpr, EP_Reduced) );
98890 /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
98891 ** and "x IS NOT FALSE". */
98892 if( pRight && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){
98893 int rc = resolveExprStep(pWalker, pRight);
98894 if( rc==WRC_Abort ) return WRC_Abort;
98895 if( pRight->op==TK_TRUEFALSE ){
98896 pExpr->op2 = pExpr->op;
98897 pExpr->op = TK_TRUTH;
@@ -99756,11 +99815,11 @@
99815 ** SELECT a AS b FROM t1 WHERE b;
99816 ** SELECT * FROM t1 WHERE (select a from t1);
99817 */
99818 SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
99819 int op;
99820 while( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
99821 assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW );
99822 pExpr = pExpr->pLeft;
99823 assert( pExpr!=0 );
99824 }
99825 op = pExpr->op;
@@ -99827,11 +99886,11 @@
99886 /*
99887 ** Skip over any TK_COLLATE operators.
99888 */
99889 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){
99890 while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
99891 assert( pExpr->op==TK_COLLATE );
99892 pExpr = pExpr->pLeft;
99893 }
99894 return pExpr;
99895 }
99896
@@ -99846,11 +99905,11 @@
99905 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
99906 assert( pExpr->x.pList->nExpr>0 );
99907 assert( pExpr->op==TK_FUNCTION );
99908 pExpr = pExpr->x.pList->a[0].pExpr;
99909 }else{
99910 assert( pExpr->op==TK_COLLATE );
99911 pExpr = pExpr->pLeft;
99912 }
99913 }
99914 return pExpr;
99915 }
@@ -100480,10 +100539,11 @@
100539 /*
100540 ** Propagate all EP_Propagate flags from the Expr.x.pList into
100541 ** Expr.flags.
100542 */
100543 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
100544 if( pParse->nErr ) return;
100545 if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
100546 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
100547 }
100548 }
100549 #define exprSetHeight(y)
@@ -109785,11 +109845,13 @@
109845 }
109846 if( i<2 ){
109847 sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
109848 goto detach_error;
109849 }
109850 if( sqlite3BtreeTxnState(pDb->pBt)!=SQLITE_TXN_NONE
109851 || sqlite3BtreeIsInBackup(pDb->pBt)
109852 ){
109853 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
109854 goto detach_error;
109855 }
109856
109857 /* If any TEMP triggers reference the schema being detached, move those
@@ -110445,18 +110507,19 @@
110507 int iDb, /* Index of the database containing the table to lock */
110508 Pgno iTab, /* Root page number of the table to be locked */
110509 u8 isWriteLock, /* True for a write lock */
110510 const char *zName /* Name of the table to be locked */
110511 ){
110512 Parse *pToplevel;
110513 int i;
110514 int nBytes;
110515 TableLock *p;
110516 assert( iDb>=0 );
110517
110518 if( iDb==1 ) return;
110519 if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
110520 pToplevel = sqlite3ParseToplevel(pParse);
110521 for(i=0; i<pToplevel->nTableLock; i++){
110522 p = &pToplevel->aTableLock[i];
110523 if( p->iDb==iDb && p->iTab==iTab ){
110524 p->isWriteLock = (p->isWriteLock || isWriteLock);
110525 return;
@@ -110482,14 +110545,12 @@
110545 ** Code an OP_TableLock instruction for each table locked by the
110546 ** statement (configured by calls to sqlite3TableLock()).
110547 */
110548 static void codeTableLocks(Parse *pParse){
110549 int i;
110550 Vdbe *pVdbe = pParse->pVdbe;
110551 assert( pVdbe!=0 );
 
 
110552
110553 for(i=0; i<pParse->nTableLock; i++){
110554 TableLock *p = &pParse->aTableLock[i];
110555 int p1 = p->iDb;
110556 sqlite3VdbeAddOp4(pVdbe, OP_TableLock, p1, p->iTab, p->isWriteLock,
@@ -114858,19 +114919,19 @@
114919 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
114920 int i;
114921 struct SrcList_item *pItem;
114922 if( pList==0 ) return;
114923 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
114924 if( pItem->zDatabase ) sqlite3DbFreeNN(db, pItem->zDatabase);
114925 sqlite3DbFree(db, pItem->zName);
114926 if( pItem->zAlias ) sqlite3DbFreeNN(db, pItem->zAlias);
114927 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
114928 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
114929 sqlite3DeleteTable(db, pItem->pTab);
114930 if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect);
114931 if( pItem->pOn ) sqlite3ExprDelete(db, pItem->pOn);
114932 if( pItem->pUsing ) sqlite3IdListDelete(db, pItem->pUsing);
114933 }
114934 sqlite3DbFreeNN(db, pList);
114935 }
114936
114937 /*
@@ -115127,24 +115188,26 @@
115188 ** Record the fact that the schema cookie will need to be verified
115189 ** for database iDb. The code to actually verify the schema cookie
115190 ** will occur at the end of the top-level VDBE and will be generated
115191 ** later, by sqlite3FinishCoding().
115192 */
115193 static void sqlite3CodeVerifySchemaAtToplevel(Parse *pToplevel, int iDb){
115194 assert( iDb>=0 && iDb<pToplevel->db->nDb );
115195 assert( pToplevel->db->aDb[iDb].pBt!=0 || iDb==1 );
 
 
115196 assert( iDb<SQLITE_MAX_ATTACHED+2 );
115197 assert( sqlite3SchemaMutexHeld(pToplevel->db, iDb, 0) );
115198 if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){
115199 DbMaskSet(pToplevel->cookieMask, iDb);
115200 if( !OMIT_TEMPDB && iDb==1 ){
115201 sqlite3OpenTempDatabase(pToplevel);
115202 }
115203 }
115204 }
115205 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
115206 sqlite3CodeVerifySchemaAtToplevel(sqlite3ParseToplevel(pParse), iDb);
115207 }
115208
115209
115210 /*
115211 ** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
115212 ** attached database. Otherwise, invoke it for the database named zDb only.
115213 */
@@ -115172,11 +115235,11 @@
115235 ** can be checked before any changes are made to the database, it is never
115236 ** necessary to undo a write and the checkpoint should not be set.
115237 */
115238 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
115239 Parse *pToplevel = sqlite3ParseToplevel(pParse);
115240 sqlite3CodeVerifySchemaAtToplevel(pToplevel, iDb);
115241 DbMaskSet(pToplevel->writeMask, iDb);
115242 pToplevel->isMultiWrite |= setStatement;
115243 }
115244
115245 /*
@@ -115223,11 +115286,13 @@
115286 int onError, /* Constraint type */
115287 char *p4, /* Error message */
115288 i8 p4type, /* P4_STATIC or P4_TRANSIENT */
115289 u8 p5Errmsg /* P5_ErrMsg type */
115290 ){
115291 Vdbe *v;
115292 assert( pParse->pVdbe!=0 );
115293 v = sqlite3GetVdbe(pParse);
115294 assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested );
115295 if( onError==OE_Abort ){
115296 sqlite3MayAbort(pParse);
115297 }
115298 sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type);
@@ -116504,11 +116569,11 @@
116569 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
116570 }
116571 }else
116572 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
116573 {
116574 u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
116575 if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
116576 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
116577 if( HasRowid(pTab) ){
116578 /* For a rowid table, initialize the RowSet to an empty set */
116579 pPk = 0;
@@ -116540,10 +116605,13 @@
116605 if( pWInfo==0 ) goto delete_from_cleanup;
116606 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
116607 assert( IsVirtual(pTab)==0 || eOnePass!=ONEPASS_MULTI );
116608 assert( IsVirtual(pTab) || bComplex || eOnePass!=ONEPASS_OFF );
116609 if( eOnePass!=ONEPASS_SINGLE ) sqlite3MultiWrite(pParse);
116610 if( sqlite3WhereUsesDeferredSeek(pWInfo) ){
116611 sqlite3VdbeAddOp1(v, OP_FinishSeek, iTabCur);
116612 }
116613
116614 /* Keep track of the number of rows to be deleted */
116615 if( memCnt ){
116616 sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
116617 }
@@ -116574,10 +116642,11 @@
116642 memset(aToOpen, 1, nIdx+1);
116643 aToOpen[nIdx+1] = 0;
116644 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iTabCur] = 0;
116645 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iTabCur] = 0;
116646 if( addrEphOpen ) sqlite3VdbeChangeToNoop(v, addrEphOpen);
116647 addrBypass = sqlite3VdbeMakeLabel(pParse);
116648 }else{
116649 if( pPk ){
116650 /* Add the PK key for this row to the temporary table */
116651 iKey = ++pParse->nMem;
116652 nKey = 0; /* Zero tells OP_Found to use a composite key */
@@ -116587,17 +116656,10 @@
116656 }else{
116657 /* Add the rowid of the row to be deleted to the RowSet */
116658 nKey = 1; /* OP_DeferredSeek always uses a single rowid */
116659 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
116660 }
 
 
 
 
 
 
 
116661 sqlite3WhereEnd(pWInfo);
116662 }
116663
116664 /* Unless this is a view, open cursors for the table we are
116665 ** deleting from and all its indices. If this is a view, then the
@@ -120583,11 +120645,12 @@
120645 Table *pTab, /* The table to be opened */
120646 int opcode /* OP_OpenRead or OP_OpenWrite */
120647 ){
120648 Vdbe *v;
120649 assert( !IsVirtual(pTab) );
120650 assert( pParse->pVdbe!=0 );
120651 v = pParse->pVdbe;
120652 assert( opcode==OP_OpenWrite || opcode==OP_OpenRead );
120653 sqlite3TableLock(pParse, iDb, pTab->tnum,
120654 (opcode==OP_OpenWrite)?1:0, pTab->zName);
120655 if( HasRowid(pTab) ){
120656 sqlite3VdbeAddOp4Int(v, opcode, iCur, pTab->tnum, iDb, pTab->nNVCol);
@@ -122082,11 +122145,11 @@
122145 Trigger *pTrigger; /* List of DELETE triggers on the table pTab */
122146 int nReplaceTrig = 0; /* Number of replace triggers coded */
122147
122148 isUpdate = regOldData!=0;
122149 db = pParse->db;
122150 v = pParse->pVdbe;
122151 assert( v!=0 );
122152 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122153 nCol = pTab->nCol;
122154
122155 /* pPk is the PRIMARY KEY index for WITHOUT ROWID tables and NULL for
@@ -122855,11 +122918,11 @@
122918 assert( update_flags==0
122919 || update_flags==OPFLAG_ISUPDATE
122920 || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
122921 );
122922
122923 v = pParse->pVdbe;
122924 assert( v!=0 );
122925 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
122926 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
122927 /* All REPLACE indexes are at the end of the list */
122928 assert( pIdx->onError!=OE_Replace
@@ -122956,11 +123019,11 @@
123019 ** variables *piDataCur and *piIdxCur uninitialized so that valgrind
123020 ** can detect if they are used by mistake in the caller. */
123021 return 0;
123022 }
123023 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
123024 v = pParse->pVdbe;
123025 assert( v!=0 );
123026 if( iBase<0 ) iBase = pParse->nTab;
123027 iDataCur = iBase++;
123028 if( piDataCur ) *piDataCur = iDataCur;
123029 if( HasRowid(pTab) && (aToOpen==0 || aToOpen[0]) ){
@@ -125874,11 +125937,13 @@
125937 ** from default, or when 'file' and the temp_store_directory has changed
125938 */
125939 static int invalidateTempStorage(Parse *pParse){
125940 sqlite3 *db = pParse->db;
125941 if( db->aDb[1].pBt!=0 ){
125942 if( !db->autoCommit
125943 || sqlite3BtreeTxnState(db->aDb[1].pBt)!=SQLITE_TXN_NONE
125944 ){
125945 sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
125946 "from within a transaction");
125947 return SQLITE_ERROR;
125948 }
125949 sqlite3BtreeClose(db->aDb[1].pBt);
@@ -128577,11 +128642,11 @@
128642
128643 /* If there is not already a read-only (or read-write) transaction opened
128644 ** on the b-tree database, open one now. If a transaction is opened, it
128645 ** will be closed before this function returns. */
128646 sqlite3BtreeEnter(pDb->pBt);
128647 if( sqlite3BtreeTxnState(pDb->pBt)==SQLITE_TXN_NONE ){
128648 rc = sqlite3BtreeBeginTrans(pDb->pBt, 0, 0);
128649 if( rc!=SQLITE_OK ){
128650 sqlite3SetString(pzErrMsg, db, sqlite3ErrStr(rc));
128651 goto initone_error_out;
128652 }
@@ -128820,11 +128885,11 @@
128885 if( pBt==0 ) continue;
128886
128887 /* If there is not already a read-only (or read-write) transaction opened
128888 ** on the b-tree database, open one now. If a transaction is opened, it
128889 ** will be closed immediately after reading the meta-value. */
128890 if( sqlite3BtreeTxnState(pBt)==SQLITE_TXN_NONE ){
128891 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
128892 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
128893 sqlite3OomFault(db);
128894 }
128895 if( rc!=SQLITE_OK ) return;
@@ -132803,11 +132868,11 @@
132868 if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
132869 memset(&ifNullRow, 0, sizeof(ifNullRow));
132870 ifNullRow.op = TK_IF_NULL_ROW;
132871 ifNullRow.pLeft = pCopy;
132872 ifNullRow.iTable = pSubst->iNewTable;
132873 ifNullRow.flags = EP_IfNullRow;
132874 pCopy = &ifNullRow;
132875 }
132876 testcase( ExprHasProperty(pCopy, EP_Subquery) );
132877 pNew = sqlite3ExprDup(db, pCopy, 0);
132878 if( pNew && pSubst->isLeftJoin ){
@@ -138304,11 +138369,11 @@
138369 ** Do not consider a single-pass strategy for a multi-row update if
138370 ** there are any triggers or foreign keys to process, or rows may
138371 ** be deleted as a result of REPLACE conflict handling. Any of these
138372 ** things might disturb a cursor being used to scan through the table
138373 ** or index, causing a single-pass approach to malfunction. */
138374 flags = WHERE_ONEPASS_DESIRED;
138375 if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
138376 flags |= WHERE_ONEPASS_MULTIROW;
138377 }
138378 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags,iIdxCur);
138379 if( pWInfo==0 ) goto update_cleanup;
@@ -139507,12 +139572,12 @@
139572 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
139573 BTREE_USER_VERSION, 0, /* Preserve the user version */
139574 BTREE_APPLICATION_ID, 0, /* Preserve the application id */
139575 };
139576
139577 assert( SQLITE_TXN_WRITE==sqlite3BtreeTxnState(pTemp) );
139578 assert( pOut!=0 || SQLITE_TXN_WRITE==sqlite3BtreeTxnState(pMain) );
139579
139580 /* Copy Btree meta values */
139581 for(i=0; i<ArraySize(aCopy); i+=2){
139582 /* GetMeta() and UpdateMeta() cannot fail in this context because
139583 ** we already have page 1 loaded into cache and marked dirty. */
@@ -141406,10 +141471,11 @@
141471 unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */
141472 unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */
141473 unsigned sorted :1; /* True if really sorted (not just grouped) */
141474 LogEst nRowOut; /* Estimated number of output rows */
141475 int iTop; /* The very beginning of the WHERE loop */
141476 int iEndWhere; /* End of the WHERE clause itself */
141477 WhereLoop *pLoops; /* List of all WhereLoop objects */
141478 WhereExprMod *pExprMods; /* Expression modifications */
141479 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
141480 WhereClause sWC; /* Decomposition of the WHERE clause */
141481 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
@@ -143275,11 +143341,12 @@
143341 nConstraint = nEq;
143342 if( pRangeStart ){
143343 Expr *pRight = pRangeStart->pExpr->pRight;
143344 codeExprOrVector(pParse, pRight, regBase+nEq, nBtm);
143345 whereLikeOptimizationStringFixup(v, pLevel, pRangeStart);
143346 if( !bRev
143347 && (pRangeStart->wtFlags & TERM_VNULL)==0
143348 && sqlite3ExprCanBeNull(pRight)
143349 ){
143350 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143351 VdbeCoverage(v);
143352 }
@@ -143353,11 +143420,12 @@
143420 nConstraint = nEq;
143421 if( pRangeEnd ){
143422 Expr *pRight = pRangeEnd->pExpr->pRight;
143423 codeExprOrVector(pParse, pRight, regBase+nEq, nTop);
143424 whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
143425 if( bRev
143426 && (pRangeEnd->wtFlags & TERM_VNULL)==0
143427 && sqlite3ExprCanBeNull(pRight)
143428 ){
143429 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
143430 VdbeCoverage(v);
143431 }
@@ -143429,21 +143497,11 @@
143497 omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
143498 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0;
143499 if( omitTable ){
143500 /* pIdx is a covering index. No need to access the main table. */
143501 }else if( HasRowid(pIdx->pTable) ){
143502 codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur);
 
 
 
 
 
 
 
 
 
 
143503 }else if( iCur!=iIdxCur ){
143504 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
143505 iRowidReg = sqlite3GetTempRange(pParse, pPk->nKeyCol);
143506 for(j=0; j<pPk->nKeyCol; j++){
143507 k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]);
@@ -143566,11 +143624,10 @@
143624 int regRowid = 0; /* Register holding rowid */
143625 int iLoopBody = sqlite3VdbeMakeLabel(pParse);/* Start of loop body */
143626 int iRetInit; /* Address of regReturn init */
143627 int untestedTerms = 0; /* Some terms not completely tested */
143628 int ii; /* Loop counter */
 
143629 Expr *pAndExpr = 0; /* An ".. AND (...)" expression */
143630 Table *pTab = pTabItem->pTab;
143631
143632 pTerm = pLoop->aLTerm[0];
143633 assert( pTerm!=0 );
@@ -143667,11 +143724,10 @@
143724
143725 /* Run a separate WHERE clause for each term of the OR clause. After
143726 ** eliminating duplicates from other WHERE clauses, the action for each
143727 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
143728 */
 
143729 ExplainQueryPlan((pParse, 1, "MULTI-INDEX OR"));
143730 for(ii=0; ii<pOrWc->nTerm; ii++){
143731 WhereTerm *pOrTerm = &pOrWc->a[ii];
143732 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
143733 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
@@ -143686,11 +143742,11 @@
143742 }
143743 /* Loop through table entries that match term pOrTerm. */
143744 ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
143745 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
143746 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
143747 WHERE_OR_SUBCLAUSE, iCovCur);
143748 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
143749 if( pSubWInfo ){
143750 WhereLoop *pSubLoop;
143751 int addrExplain = sqlite3WhereExplainOneScan(
143752 pParse, pOrTab, &pSubWInfo->a[0], 0
@@ -143783,10 +143839,13 @@
143839 ){
143840 assert( pSubWInfo->a[0].iIdxCur==iCovCur );
143841 pCov = pSubLoop->u.btree.pIndex;
143842 }else{
143843 pCov = 0;
143844 }
143845 if( sqlite3WhereUsesDeferredSeek(pSubWInfo) ){
143846 pWInfo->bDeferredSeek = 1;
143847 }
143848
143849 /* Finish the loop through table entries that match term pOrTerm. */
143850 sqlite3WhereEnd(pSubWInfo);
143851 ExplainQueryPlanPop(pParse);
@@ -149662,20 +149721,28 @@
149721 ** sorting cost to:
149722 **
149723 ** cost = (3.0 * N * log(N)) * (Y/X)
149724 **
149725 ** The (Y/X) term is implemented using stack variable rScale
149726 ** below.
149727 */
149728 LogEst rScale, rSortCost;
149729 assert( nOrderBy>0 && 66==sqlite3LogEst(100) );
149730 rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66;
149731 rSortCost = nRow + rScale + 16;
149732
149733 /* Multiple by log(M) where M is the number of output rows.
149734 ** Use the LIMIT for M if it is smaller. Or if this sort is for
149735 ** a DISTINT operator, M will be the number of distinct output
149736 ** rows, so fudge it downwards a bit.
149737 */
149738 if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit<nRow ){
149739 nRow = pWInfo->iLimit;
149740 }else if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT) ){
149741 /* TUNING: In the sort for a DISTINCT operator, assume that the DISTINCT
149742 ** reduces the number of output rows by a factor of 2 */
149743 if( nRow>10 ) nRow -= 10; assert( 10==sqlite3LogEst(2) );
149744 }
149745 rSortCost += estLog(nRow);
149746 return rSortCost;
149747 }
149748
@@ -150855,10 +150922,11 @@
150922 }
150923 }
150924
150925 /* Done. */
150926 VdbeModuleComment((v, "Begin WHERE-core"));
150927 pWInfo->iEndWhere = sqlite3VdbeCurrentAddr(v);
150928 return pWInfo;
150929
150930 /* Jump here if malloc fails */
150931 whereBeginError:
150932 if( pWInfo ){
@@ -150898,10 +150966,11 @@
150966 int i;
150967 WhereLevel *pLevel;
150968 WhereLoop *pLoop;
150969 SrcList *pTabList = pWInfo->pTabList;
150970 sqlite3 *db = pParse->db;
150971 int iEnd = sqlite3VdbeCurrentAddr(v);
150972
150973 /* Generate loop termination code.
150974 */
150975 VdbeModuleComment((v, "End WHERE-core"));
150976 for(i=pWInfo->nLevel-1; i>=0; i--){
@@ -151035,11 +151104,11 @@
151104 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
151105
151106 assert( pWInfo->nLevel<=pTabList->nSrc );
151107 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
151108 int k, last;
151109 VdbeOp *pOp, *pLastOp;
151110 Index *pIdx = 0;
151111 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
151112 Table *pTab = pTabItem->pTab;
151113 assert( pTab!=0 );
151114 pLoop = pLevel->pWLoop;
@@ -151093,24 +151162,35 @@
151162 pIdx = pLoop->u.btree.pIndex;
151163 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
151164 pIdx = pLevel->u.pCovidx;
151165 }
151166 if( pIdx
 
151167 && !db->mallocFailed
151168 ){
151169 if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){
151170 last = iEnd;
151171 }else{
151172 last = pWInfo->iEndWhere;
151173 }
151174 k = pLevel->addrBody + 1;
151175 #ifdef SQLITE_DEBUG
151176 if( db->flags & SQLITE_VdbeAddopTrace ){
151177 printf("TRANSLATE opcodes in range %d..%d\n", k, last-1);
151178 }
151179 /* Proof that the "+1" on the k value above is safe */
151180 pOp = sqlite3VdbeGetOp(v, k - 1);
151181 assert( pOp->opcode!=OP_Column || pOp->p1!=pLevel->iTabCur );
151182 assert( pOp->opcode!=OP_Rowid || pOp->p1!=pLevel->iTabCur );
151183 assert( pOp->opcode!=OP_IfNullRow || pOp->p1!=pLevel->iTabCur );
151184 #endif
151185 pOp = sqlite3VdbeGetOp(v, k);
151186 pLastOp = pOp + (last - k);
151187 assert( pOp<pLastOp );
151188 do{
151189 if( pOp->p1!=pLevel->iTabCur ){
151190 /* no-op */
151191 }else if( pOp->opcode==OP_Column
151192 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
151193 || pOp->opcode==OP_Offset
151194 #endif
151195 ){
151196 int x = pOp->p2;
@@ -151137,11 +151217,14 @@
151217 OpcodeRewriteTrace(db, k, pOp);
151218 }else if( pOp->opcode==OP_IfNullRow ){
151219 pOp->p1 = pLevel->iIdxCur;
151220 OpcodeRewriteTrace(db, k, pOp);
151221 }
151222 #ifdef SQLITE_DEBUG
151223 k++;
151224 #endif
151225 }while( (++pOp)<pLastOp );
151226 #ifdef SQLITE_DEBUG
151227 if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
151228 #endif
151229 }
151230 }
@@ -161894,11 +161977,11 @@
161977 #endif
161978 sqlite3_mutex_enter(db->mutex);
161979 sqlite3BtreeEnterAll(db);
161980 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
161981 Btree *pBt = db->aDb[i].pBt;
161982 if( pBt && sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){
161983 Pager *pPager = sqlite3BtreePager(pBt);
161984 rc = sqlite3PagerFlush(pPager);
161985 if( rc==SQLITE_BUSY ){
161986 bSeenBusy = 1;
161987 rc = SQLITE_OK;
@@ -162237,10 +162320,40 @@
162320 */
162321 db->magic = SQLITE_MAGIC_ZOMBIE;
162322 sqlite3LeaveMutexAndCloseZombie(db);
162323 return SQLITE_OK;
162324 }
162325
162326 /*
162327 ** Return the transaction state for a single databse, or the maximum
162328 ** transaction state over all attached databases if zSchema is null.
162329 */
162330 SQLITE_API int sqlite3_txn_state(sqlite3 *db, const char *zSchema){
162331 int iDb, nDb;
162332 int iTxn = -1;
162333 #ifdef SQLITE_ENABLE_API_ARMOR
162334 if( !sqlite3SafetyCheckOk(db) ){
162335 (void)SQLITE_MISUSE_BKPT;
162336 return -1;
162337 }
162338 #endif
162339 sqlite3_mutex_enter(db->mutex);
162340 if( zSchema ){
162341 nDb = iDb = sqlite3FindDbName(db, zSchema);
162342 if( iDb<0 ) nDb--;
162343 }else{
162344 iDb = 0;
162345 nDb = db->nDb-1;
162346 }
162347 for(; iDb<=nDb; iDb++){
162348 Btree *pBt = db->aDb[iDb].pBt;
162349 int x = pBt!=0 ? sqlite3BtreeTxnState(pBt) : SQLITE_TXN_NONE;
162350 if( x>iTxn ) iTxn = x;
162351 }
162352 sqlite3_mutex_leave(db->mutex);
162353 return iTxn;
162354 }
162355
162356 /*
162357 ** Two variations on the public interface for closing a database
162358 ** connection. The sqlite3_close() version returns SQLITE_BUSY and
162359 ** leaves the connection option if there are unfinalized prepared
@@ -162398,11 +162511,11 @@
162511 schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
162512
162513 for(i=0; i<db->nDb; i++){
162514 Btree *p = db->aDb[i].pBt;
162515 if( p ){
162516 if( sqlite3BtreeTxnState(p)==SQLITE_TXN_WRITE ){
162517 inTrans = 1;
162518 }
162519 sqlite3BtreeRollback(p, tripCode, !schemaChange);
162520 }
162521 }
@@ -165437,11 +165550,11 @@
165550
165551 if( db->autoCommit==0 ){
165552 int iDb = sqlite3FindDbName(db, zDb);
165553 if( iDb==0 || iDb>1 ){
165554 Btree *pBt = db->aDb[iDb].pBt;
165555 if( SQLITE_TXN_WRITE!=sqlite3BtreeTxnState(pBt) ){
165556 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
165557 if( rc==SQLITE_OK ){
165558 rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
165559 }
165560 }
@@ -165473,14 +165586,14 @@
165586 if( db->autoCommit==0 ){
165587 int iDb;
165588 iDb = sqlite3FindDbName(db, zDb);
165589 if( iDb==0 || iDb>1 ){
165590 Btree *pBt = db->aDb[iDb].pBt;
165591 if( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_WRITE ){
165592 Pager *pPager = sqlite3BtreePager(pBt);
165593 int bUnlock = 0;
165594 if( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_NONE ){
165595 if( db->nVdbeActive==0 ){
165596 rc = sqlite3PagerSnapshotCheck(pPager, pSnapshot);
165597 if( rc==SQLITE_OK ){
165598 bUnlock = 1;
165599 rc = sqlite3BtreeCommit(pBt);
@@ -165525,11 +165638,11 @@
165638
165639 sqlite3_mutex_enter(db->mutex);
165640 iDb = sqlite3FindDbName(db, zDb);
165641 if( iDb==0 || iDb>1 ){
165642 Btree *pBt = db->aDb[iDb].pBt;
165643 if( SQLITE_TXN_NONE==sqlite3BtreeTxnState(pBt) ){
165644 rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
165645 if( rc==SQLITE_OK ){
165646 rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt));
165647 sqlite3BtreeCommit(pBt);
165648 }
@@ -225723,11 +225836,11 @@
225836 int nArg, /* Number of args */
225837 sqlite3_value **apUnused /* Function arguments */
225838 ){
225839 assert( nArg==0 );
225840 UNUSED_PARAM2(nArg, apUnused);
225841 sqlite3_result_text(pCtx, "fts5: 2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492", -1, SQLITE_TRANSIENT);
225842 }
225843
225844 /*
225845 ** Return true if zName is the extension on one of the shadow tables used
225846 ** by this module.
@@ -230506,12 +230619,12 @@
230619 }
230620 #endif /* SQLITE_CORE */
230621 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
230622
230623 /************** End of stmt.c ************************************************/
230624 #if __LINE__!=230624
230625 #undef SQLITE_SOURCE_ID
230626 #define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36alt2"
230627 #endif
230628 /* Return the source-id for this library */
230629 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
230630 /************************** End of sqlite3.c ******************************/
230631
+57 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121121
**
122122
** See also: [sqlite3_libversion()],
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126
-#define SQLITE_VERSION "3.33.0"
127
-#define SQLITE_VERSION_NUMBER 3033000
128
-#define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f"
126
+#define SQLITE_VERSION "3.34.0"
127
+#define SQLITE_VERSION_NUMBER 3034000
128
+#define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -6184,10 +6184,61 @@
61846184
** of connection D is read-only, 0 if it is read/write, or -1 if N is not
61856185
** the name of a database on connection D.
61866186
*/
61876187
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
61886188
6189
+/*
6190
+** CAPI3REF: Determine the transaction state of a database
6191
+** METHOD: sqlite3
6192
+**
6193
+** ^The sqlite3_txn_state(D,S) interface returns the current
6194
+** [transaction state] of schema S in database connection D. ^If S is NULL,
6195
+** then the highest transaction state of any schema on databse connection D
6196
+** is returned. Transaction states are (in order of lowest to highest):
6197
+** <ol>
6198
+** <li value="0"> SQLITE_TXN_NONE
6199
+** <li value="1"> SQLITE_TXN_READ
6200
+** <li value="2"> SQLITE_TXN_WRITE
6201
+** </ol>
6202
+** ^If the S argument to sqlite3_txn_state(D,S) is in the name of
6203
+** a valid schema, then -1 is returned.
6204
+*/
6205
+SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6206
+
6207
+/*
6208
+** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
6209
+** KEYWORDS: {transaction state}
6210
+**
6211
+** These constants define the current transaction state of a database file.
6212
+** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6213
+** constants in order to describe the transaction state of schema S
6214
+** in [database connection] D.
6215
+**
6216
+** <dl>
6217
+** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
6218
+** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
6219
+** pending.</dd>
6220
+**
6221
+** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
6222
+** <dd>The SQLITE_TXN_READ state means that the database is currently
6223
+** in a read transaction. Content has been read from the database file
6224
+** but nothing in the database file has changed. The transaction state
6225
+** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
6226
+** no other conflicting concurrent write transactions. The transaction
6227
+** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
6228
+** [COMMIT].</dd>
6229
+**
6230
+** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
6231
+** <dd>The SQLITE_TXN_WRITE state means that the database is currently
6232
+** in a write transaction. Content has been written to the database file
6233
+** but has not yet committed. The transaction state will change to
6234
+** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
6235
+*/
6236
+#define SQLITE_TXN_NONE 0
6237
+#define SQLITE_TXN_READ 1
6238
+#define SQLITE_TXN_WRITE 2
6239
+
61896240
/*
61906241
** CAPI3REF: Find the next prepared statement
61916242
** METHOD: sqlite3
61926243
**
61936244
** ^This interface returns a pointer to the next [prepared statement] after
@@ -9343,10 +9394,11 @@
93439394
*/
93449395
SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
93459396
93469397
/*
93479398
** CAPI3REF: Flush caches to disk mid-transaction
9399
+** METHOD: sqlite3
93489400
**
93499401
** ^If a write-transaction is open on [database connection] D when the
93509402
** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
93519403
** pages in the pager-cache that are not currently in use are written out
93529404
** to disk. A dirty page may be in use if a database cursor created by an
@@ -9375,10 +9427,11 @@
93759427
*/
93769428
SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
93779429
93789430
/*
93799431
** CAPI3REF: The pre-update hook.
9432
+** METHOD: sqlite3
93809433
**
93819434
** ^These interfaces are only available if SQLite is compiled using the
93829435
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
93839436
**
93849437
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
@@ -9477,10 +9530,11 @@
94779530
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
94789531
#endif
94799532
94809533
/*
94819534
** CAPI3REF: Low-level system error code
9535
+** METHOD: sqlite3
94829536
**
94839537
** ^Attempt to return the underlying operating system error code or error
94849538
** number that caused the most recent I/O error or failure to open a file.
94859539
** The return value is OS-dependent. For example, on unix systems, after
94869540
** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
94879541
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.33.0"
127 #define SQLITE_VERSION_NUMBER 3033000
128 #define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -6184,10 +6184,61 @@
6184 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
6185 ** the name of a database on connection D.
6186 */
6187 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
6188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6189 /*
6190 ** CAPI3REF: Find the next prepared statement
6191 ** METHOD: sqlite3
6192 **
6193 ** ^This interface returns a pointer to the next [prepared statement] after
@@ -9343,10 +9394,11 @@
9343 */
9344 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
9345
9346 /*
9347 ** CAPI3REF: Flush caches to disk mid-transaction
 
9348 **
9349 ** ^If a write-transaction is open on [database connection] D when the
9350 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
9351 ** pages in the pager-cache that are not currently in use are written out
9352 ** to disk. A dirty page may be in use if a database cursor created by an
@@ -9375,10 +9427,11 @@
9375 */
9376 SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
9377
9378 /*
9379 ** CAPI3REF: The pre-update hook.
 
9380 **
9381 ** ^These interfaces are only available if SQLite is compiled using the
9382 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
9383 **
9384 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
@@ -9477,10 +9530,11 @@
9477 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
9478 #endif
9479
9480 /*
9481 ** CAPI3REF: Low-level system error code
 
9482 **
9483 ** ^Attempt to return the underlying operating system error code or error
9484 ** number that caused the most recent I/O error or failure to open a file.
9485 ** The return value is OS-dependent. For example, on unix systems, after
9486 ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
9487
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.34.0"
127 #define SQLITE_VERSION_NUMBER 3034000
128 #define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -6184,10 +6184,61 @@
6184 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
6185 ** the name of a database on connection D.
6186 */
6187 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
6188
6189 /*
6190 ** CAPI3REF: Determine the transaction state of a database
6191 ** METHOD: sqlite3
6192 **
6193 ** ^The sqlite3_txn_state(D,S) interface returns the current
6194 ** [transaction state] of schema S in database connection D. ^If S is NULL,
6195 ** then the highest transaction state of any schema on databse connection D
6196 ** is returned. Transaction states are (in order of lowest to highest):
6197 ** <ol>
6198 ** <li value="0"> SQLITE_TXN_NONE
6199 ** <li value="1"> SQLITE_TXN_READ
6200 ** <li value="2"> SQLITE_TXN_WRITE
6201 ** </ol>
6202 ** ^If the S argument to sqlite3_txn_state(D,S) is in the name of
6203 ** a valid schema, then -1 is returned.
6204 */
6205 SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6206
6207 /*
6208 ** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
6209 ** KEYWORDS: {transaction state}
6210 **
6211 ** These constants define the current transaction state of a database file.
6212 ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6213 ** constants in order to describe the transaction state of schema S
6214 ** in [database connection] D.
6215 **
6216 ** <dl>
6217 ** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
6218 ** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
6219 ** pending.</dd>
6220 **
6221 ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
6222 ** <dd>The SQLITE_TXN_READ state means that the database is currently
6223 ** in a read transaction. Content has been read from the database file
6224 ** but nothing in the database file has changed. The transaction state
6225 ** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
6226 ** no other conflicting concurrent write transactions. The transaction
6227 ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
6228 ** [COMMIT].</dd>
6229 **
6230 ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
6231 ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
6232 ** in a write transaction. Content has been written to the database file
6233 ** but has not yet committed. The transaction state will change to
6234 ** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
6235 */
6236 #define SQLITE_TXN_NONE 0
6237 #define SQLITE_TXN_READ 1
6238 #define SQLITE_TXN_WRITE 2
6239
6240 /*
6241 ** CAPI3REF: Find the next prepared statement
6242 ** METHOD: sqlite3
6243 **
6244 ** ^This interface returns a pointer to the next [prepared statement] after
@@ -9343,10 +9394,11 @@
9394 */
9395 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
9396
9397 /*
9398 ** CAPI3REF: Flush caches to disk mid-transaction
9399 ** METHOD: sqlite3
9400 **
9401 ** ^If a write-transaction is open on [database connection] D when the
9402 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
9403 ** pages in the pager-cache that are not currently in use are written out
9404 ** to disk. A dirty page may be in use if a database cursor created by an
@@ -9375,10 +9427,11 @@
9427 */
9428 SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
9429
9430 /*
9431 ** CAPI3REF: The pre-update hook.
9432 ** METHOD: sqlite3
9433 **
9434 ** ^These interfaces are only available if SQLite is compiled using the
9435 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
9436 **
9437 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
@@ -9477,10 +9530,11 @@
9530 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
9531 #endif
9532
9533 /*
9534 ** CAPI3REF: Low-level system error code
9535 ** METHOD: sqlite3
9536 **
9537 ** ^Attempt to return the underlying operating system error code or error
9538 ** number that caused the most recent I/O error or failure to open a file.
9539 ** The return value is OS-dependent. For example, on unix systems, after
9540 ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
9541

Keyboard Shortcuts

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