Fossil SCM

Update the built-in SQLite to the latest version 3.46.0 prototype.

drh 2024-03-26 15:36 trunk
Commit 452f8e1ffc99c607ef274684bee0592a224b16cbf21ce75b9a7f4ae068521aab
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -30041,10 +30041,11 @@
3004130041
" -multiplex enable the multiplexor VFS\n"
3004230042
#endif
3004330043
" -newline SEP set output row separator. Default: '\\n'\n"
3004430044
" -nofollow refuse to open symbolic links to database files\n"
3004530045
" -nonce STRING set the safe-mode escape nonce\n"
30046
+ " -no-rowid-in-view Disable rowid-in-view using sqlite3_config()\n"
3004630047
" -nullvalue TEXT set text string for NULL values. Default ''\n"
3004730048
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
3004830049
" -pcachetrace trace all page cache operations\n"
3004930050
" -quote set output mode to 'quote'\n"
3005030051
" -readonly open the database read-only\n"
@@ -30331,10 +30332,14 @@
3033130332
** we do the actual processing of arguments later in a second pass.
3033230333
*/
3033330334
stdin_is_interactive = 0;
3033430335
}else if( cli_strcmp(z,"-utf8")==0 ){
3033530336
}else if( cli_strcmp(z,"-no-utf8")==0 ){
30337
+ }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
30338
+ int val = 0;
30339
+ sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW, &val);
30340
+ assert( val==0 );
3033630341
}else if( cli_strcmp(z,"-heap")==0 ){
3033730342
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
3033830343
const char *zSize;
3033930344
sqlite3_int64 szHeap;
3034030345
@@ -30605,10 +30610,12 @@
3060530610
}else if( cli_strcmp(z,"-batch")==0 ){
3060630611
/* already handled */
3060730612
}else if( cli_strcmp(z,"-utf8")==0 ){
3060830613
/* already handled */
3060930614
}else if( cli_strcmp(z,"-no-utf8")==0 ){
30615
+ /* already handled */
30616
+ }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
3061030617
/* already handled */
3061130618
}else if( cli_strcmp(z,"-heap")==0 ){
3061230619
i++;
3061330620
}else if( cli_strcmp(z,"-pagecache")==0 ){
3061430621
i+=2;
3061530622
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -30041,10 +30041,11 @@
30041 " -multiplex enable the multiplexor VFS\n"
30042 #endif
30043 " -newline SEP set output row separator. Default: '\\n'\n"
30044 " -nofollow refuse to open symbolic links to database files\n"
30045 " -nonce STRING set the safe-mode escape nonce\n"
 
30046 " -nullvalue TEXT set text string for NULL values. Default ''\n"
30047 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
30048 " -pcachetrace trace all page cache operations\n"
30049 " -quote set output mode to 'quote'\n"
30050 " -readonly open the database read-only\n"
@@ -30331,10 +30332,14 @@
30331 ** we do the actual processing of arguments later in a second pass.
30332 */
30333 stdin_is_interactive = 0;
30334 }else if( cli_strcmp(z,"-utf8")==0 ){
30335 }else if( cli_strcmp(z,"-no-utf8")==0 ){
 
 
 
 
30336 }else if( cli_strcmp(z,"-heap")==0 ){
30337 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
30338 const char *zSize;
30339 sqlite3_int64 szHeap;
30340
@@ -30605,10 +30610,12 @@
30605 }else if( cli_strcmp(z,"-batch")==0 ){
30606 /* already handled */
30607 }else if( cli_strcmp(z,"-utf8")==0 ){
30608 /* already handled */
30609 }else if( cli_strcmp(z,"-no-utf8")==0 ){
 
 
30610 /* already handled */
30611 }else if( cli_strcmp(z,"-heap")==0 ){
30612 i++;
30613 }else if( cli_strcmp(z,"-pagecache")==0 ){
30614 i+=2;
30615
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -30041,10 +30041,11 @@
30041 " -multiplex enable the multiplexor VFS\n"
30042 #endif
30043 " -newline SEP set output row separator. Default: '\\n'\n"
30044 " -nofollow refuse to open symbolic links to database files\n"
30045 " -nonce STRING set the safe-mode escape nonce\n"
30046 " -no-rowid-in-view Disable rowid-in-view using sqlite3_config()\n"
30047 " -nullvalue TEXT set text string for NULL values. Default ''\n"
30048 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
30049 " -pcachetrace trace all page cache operations\n"
30050 " -quote set output mode to 'quote'\n"
30051 " -readonly open the database read-only\n"
@@ -30331,10 +30332,14 @@
30332 ** we do the actual processing of arguments later in a second pass.
30333 */
30334 stdin_is_interactive = 0;
30335 }else if( cli_strcmp(z,"-utf8")==0 ){
30336 }else if( cli_strcmp(z,"-no-utf8")==0 ){
30337 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
30338 int val = 0;
30339 sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW, &val);
30340 assert( val==0 );
30341 }else if( cli_strcmp(z,"-heap")==0 ){
30342 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
30343 const char *zSize;
30344 sqlite3_int64 szHeap;
30345
@@ -30605,10 +30610,12 @@
30610 }else if( cli_strcmp(z,"-batch")==0 ){
30611 /* already handled */
30612 }else if( cli_strcmp(z,"-utf8")==0 ){
30613 /* already handled */
30614 }else if( cli_strcmp(z,"-no-utf8")==0 ){
30615 /* already handled */
30616 }else if( cli_strcmp(z,"-no-rowid-in-view")==0 ){
30617 /* already handled */
30618 }else if( cli_strcmp(z,"-heap")==0 ){
30619 i++;
30620 }else if( cli_strcmp(z,"-pagecache")==0 ){
30621 i+=2;
30622
+234 -67
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 76fb3a908f45230b956cb659c754e47603e8.
21
+** a49296de0061931badaf3db6b965131a78b1.
2222
*/
2323
#define SQLITE_CORE 1
2424
#define SQLITE_AMALGAMATION 1
2525
#ifndef SQLITE_PRIVATE
2626
# define SQLITE_PRIVATE static
@@ -459,11 +459,11 @@
459459
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460460
** [sqlite_version()] and [sqlite_source_id()].
461461
*/
462462
#define SQLITE_VERSION "3.46.0"
463463
#define SQLITE_VERSION_NUMBER 3046000
464
-#define SQLITE_SOURCE_ID "2024-03-18 18:03:17 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61"
464
+#define SQLITE_SOURCE_ID "2024-03-26 11:14:52 a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3"
465465
466466
/*
467467
** CAPI3REF: Run-Time Library Version Numbers
468468
** KEYWORDS: sqlite3_version sqlite3_sourceid
469469
**
@@ -2454,10 +2454,26 @@
24542454
** size can be adjusted up or down for individual databases using the
24552455
** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
24562456
** configuration setting is never used, then the default maximum is determined
24572457
** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
24582458
** compile-time option is not set, then the default maximum is 1073741824.
2459
+**
2460
+** [[SQLITE_CONFIG_ROWID_IN_VIEW]]
2461
+** <dt>SQLITE_CONFIG_ROWID_IN_VIEW
2462
+** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability
2463
+** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is
2464
+** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability
2465
+** defaults to on. This configuration option queries the current setting or
2466
+** changes the setting to off or on. The argument is a pointer to an integer.
2467
+** If that integer initially holds a value of 1, then the ability for VIEWs to
2468
+** have ROWIDs is activated. If the integer initially holds zero, then the
2469
+** ability is deactivated. Any other initial value for the integer leaves the
2470
+** setting unchanged. After changes, if any, the integer is written with
2471
+** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite
2472
+** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and
2473
+** recommended case) then the integer is always filled with zero, regardless
2474
+** if its initial value.
24592475
** </dl>
24602476
*/
24612477
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
24622478
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
24632479
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2485,10 +2501,11 @@
24852501
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
24862502
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
24872503
#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
24882504
#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
24892505
#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
2506
+#define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */
24902507
24912508
/*
24922509
** CAPI3REF: Database Connection Configuration Options
24932510
**
24942511
** These constants are the available integer configuration options that
@@ -3599,12 +3616,12 @@
35993616
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
36003617
#define SQLITE_COPY 0 /* No longer used */
36013618
#define SQLITE_RECURSIVE 33 /* NULL NULL */
36023619
36033620
/*
3604
-** CAPI3REF: Tracing And Profiling Functions
3605
-** METHOD: sqlite3
3621
+** CAPI3REF: Deprecated Tracing And Profiling Functions
3622
+** DEPRECATED
36063623
**
36073624
** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
36083625
** instead of the routines described here.
36093626
**
36103627
** These routines register callback functions that can be used for
@@ -18438,10 +18455,19 @@
1843818455
1843918456
/* Does the table have a rowid */
1844018457
#define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
1844118458
#define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0)
1844218459
18460
+/* Macro is true if the SQLITE_ALLOW_ROWID_IN_VIEW (mis-)feature is
18461
+** available. By default, this macro is false
18462
+*/
18463
+#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
18464
+# define ViewCanHaveRowid 0
18465
+#else
18466
+# define ViewCanHaveRowid (sqlite3Config.mNoVisibleRowid==0)
18467
+#endif
18468
+
1844318469
/*
1844418470
** Each foreign key constraint is an instance of the following structure.
1844518471
**
1844618472
** A foreign key is associated with two tables. The "from" table is
1844718473
** the table that contains the REFERENCES clause that creates the foreign
@@ -20157,10 +20183,15 @@
2015720183
sqlite3_int64 mxMemdbSize; /* Default max memdb size */
2015820184
#endif
2015920185
#ifndef SQLITE_UNTESTABLE
2016020186
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
2016120187
#endif
20188
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
20189
+ u32 mNoVisibleRowid; /* TF_NoVisibleRowid if the ROWID_IN_VIEW
20190
+ ** feature is disabled. 0 if rowids can
20191
+ ** occur in views. */
20192
+#endif
2016220193
int bLocaltimeFault; /* True to fail localtime() calls */
2016320194
int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */
2016420195
int iOnceResetThreshold; /* When to reset OP_Once counters */
2016520196
u32 szSorterRef; /* Min size in bytes to use sorter-refs */
2016620197
unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
@@ -20615,14 +20646,17 @@
2061520646
2061620647
#ifndef SQLITE_OMIT_FLOATING_POINT
2061720648
# define EXP754 (((u64)0x7ff)<<52)
2061820649
# define MAN754 ((((u64)1)<<52)-1)
2061920650
# define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0)
20651
+# define IsOvfl(X) (((X)&EXP754)==EXP754)
2062020652
SQLITE_PRIVATE int sqlite3IsNaN(double);
20653
+SQLITE_PRIVATE int sqlite3IsOverflow(double);
2062120654
#else
20622
-# define IsNaN(X) 0
20623
-# define sqlite3IsNaN(X) 0
20655
+# define IsNaN(X) 0
20656
+# define sqlite3IsNaN(X) 0
20657
+# define sqlite3IsOVerflow(X) 0
2062420658
#endif
2062520659
2062620660
/*
2062720661
** An instance of the following structure holds information about SQL
2062820662
** functions arguments that are the parameters to the printf() function.
@@ -21853,10 +21887,13 @@
2185321887
#endif
2185421888
#ifdef SQLITE_ALLOW_COVERING_INDEX_SCAN
2185521889
# if SQLITE_ALLOW_COVERING_INDEX_SCAN != 1
2185621890
"ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN),
2185721891
# endif
21892
+#endif
21893
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
21894
+ "ALLOW_ROWID_IN_VIEW",
2185821895
#endif
2185921896
#ifdef SQLITE_ALLOW_URI_AUTHORITY
2186021897
"ALLOW_URI_AUTHORITY",
2186121898
#endif
2186221899
#ifdef SQLITE_ATOMIC_INTRINSICS
@@ -22874,10 +22911,13 @@
2287422911
SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
2287522912
#endif
2287622913
#ifndef SQLITE_UNTESTABLE
2287722914
0, /* xTestCallback */
2287822915
#endif
22916
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
22917
+ 0, /* mNoVisibleRowid. 0 == allow rowid-in-view */
22918
+#endif
2287922919
0, /* bLocaltimeFault */
2288022920
0, /* xAltLocaltime */
2288122921
0x7ffffffe, /* iOnceResetThreshold */
2288222922
SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
2288322923
0, /* iPrngSeed */
@@ -34877,10 +34917,23 @@
3487734917
testcase( rc );
3487834918
return rc;
3487934919
}
3488034920
#endif /* SQLITE_OMIT_FLOATING_POINT */
3488134921
34922
+#ifndef SQLITE_OMIT_FLOATING_POINT
34923
+/*
34924
+** Return true if the floating point value is NaN or +Inf or -Inf.
34925
+*/
34926
+SQLITE_PRIVATE int sqlite3IsOverflow(double x){
34927
+ int rc; /* The value return */
34928
+ u64 y;
34929
+ memcpy(&y,&x,sizeof(y));
34930
+ rc = IsOvfl(y);
34931
+ return rc;
34932
+}
34933
+#endif /* SQLITE_OMIT_FLOATING_POINT */
34934
+
3488234935
/*
3488334936
** Compute a string length that is limited to what can be stored in
3488434937
** lower 30 bits of a 32-bit signed integer.
3488534938
**
3488634939
** The value returned will never be negative. Nor will it ever be greater
@@ -44643,16 +44696,23 @@
4464344696
/* If unable to create a journal because the directory is not
4464444697
** writable, change the error code to indicate that. */
4464544698
rc = SQLITE_READONLY_DIRECTORY;
4464644699
}else if( errno!=EISDIR && isReadWrite ){
4464744700
/* Failed to open the file for read/write access. Try read-only. */
44701
+ UnixUnusedFd *pReadonly = 0;
4464844702
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
4464944703
openFlags &= ~(O_RDWR|O_CREAT);
4465044704
flags |= SQLITE_OPEN_READONLY;
4465144705
openFlags |= O_RDONLY;
4465244706
isReadonly = 1;
44653
- fd = robust_open(zName, openFlags, openMode);
44707
+ pReadonly = findReusableFd(zName, flags);
44708
+ if( pReadonly ){
44709
+ fd = pReadonly->fd;
44710
+ sqlite3_free(pReadonly);
44711
+ }else{
44712
+ fd = robust_open(zName, openFlags, openMode);
44713
+ }
4465444714
}
4465544715
}
4465644716
if( fd<0 ){
4465744717
int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
4465844718
if( rc==SQLITE_OK ) rc = rc2;
@@ -92645,11 +92705,10 @@
9264592705
}
9264692706
return 1;
9264792707
}
9264892708
if( flags & SQLITE_SCANSTAT_COMPLEX ){
9264992709
idx = iScan;
92650
- pScan = &p->aScan[idx];
9265192710
}else{
9265292711
/* If the COMPLEX flag is clear, then this function must ignore any
9265392712
** ScanStatus structures with ScanStatus.addrLoop set to 0. */
9265492713
for(idx=0; idx<p->nScan; idx++){
9265592714
pScan = &p->aScan[idx];
@@ -92658,10 +92717,12 @@
9265892717
if( iScan<0 ) break;
9265992718
}
9266092719
}
9266192720
}
9266292721
if( idx>=p->nScan ) return 1;
92722
+ assert( pScan==0 || pScan==&p->aScan[idx] );
92723
+ pScan = &p->aScan[idx];
9266392724
9266492725
switch( iScanStatusOp ){
9266592726
case SQLITE_SCANSTAT_NLOOP: {
9266692727
if( pScan->addrLoop>0 ){
9266792728
*(sqlite3_int64*)pOut = aOp[pScan->addrLoop].nExec;
@@ -99169,11 +99230,12 @@
9916999230
9917099231
/* Opcode: IfSizeBetween P1 P2 P3 P4 *
9917199232
**
9917299233
** Let N be the approximate number of rows in the table or index
9917399234
** with cursor P1 and let X be 10*log2(N) if N is positive or -1
99174
-** if N is zero. Thus X will be within the range of -1 to 640, inclusive
99235
+** if N is zero.
99236
+**
9917599237
** Jump to P2 if X is in between P3 and P4, inclusive.
9917699238
*/
9917799239
case OP_IfSizeBetween: { /* jump */
9917899240
VdbeCursor *pC;
9917999241
BtCursor *pCrsr;
@@ -99180,12 +99242,12 @@
9918099242
int res;
9918199243
i64 sz;
9918299244
9918399245
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9918499246
assert( pOp->p4type==P4_INT32 );
99185
- assert( pOp->p3>=-1 && pOp->p3<=640 );
99186
- assert( pOp->p4.i>=-1 && pOp->p4.i<=640 );
99247
+ assert( pOp->p3>=-1 && pOp->p3<=640*2 );
99248
+ assert( pOp->p4.i>=-1 && pOp->p4.i<=640*2 );
9918799249
pC = p->apCsr[pOp->p1];
9918899250
assert( pC!=0 );
9918999251
pCrsr = pC->uc.pCursor;
9919099252
assert( pCrsr );
9919199253
rc = sqlite3BtreeFirst(pCrsr, &res);
@@ -107053,12 +107115,41 @@
107053107115
}
107054107116
break;
107055107117
}
107056107118
}
107057107119
if( 0==cnt && VisibleRowid(pTab) ){
107120
+ /* pTab is a potential ROWID match. Keep track of it and match
107121
+ ** the ROWID later if that seems appropriate. (Search for "cntTab"
107122
+ ** to find related code.) Only allow a ROWID match if there is
107123
+ ** a single ROWID match candidate.
107124
+ */
107125
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
107126
+ /* In SQLITE_ALLOW_ROWID_IN_VIEW mode, allow a ROWID match
107127
+ ** if there is a single VIEW candidate or if there is a single
107128
+ ** non-VIEW candidate plus multiple VIEW candidates. In other
107129
+ ** words non-VIEW candidate terms take precedence over VIEWs.
107130
+ */
107131
+ if( cntTab==0
107132
+ || (cntTab==1
107133
+ && ALWAYS(pMatch!=0)
107134
+ && ALWAYS(pMatch->pTab!=0)
107135
+ && (pMatch->pTab->tabFlags & TF_Ephemeral)!=0
107136
+ && (pTab->tabFlags & TF_Ephemeral)==0)
107137
+ ){
107138
+ cntTab = 1;
107139
+ pMatch = pItem;
107140
+ }else{
107141
+ cntTab++;
107142
+ }
107143
+#else
107144
+ /* The (much more common) non-SQLITE_ALLOW_ROWID_IN_VIEW case is
107145
+ ** simpler since we require exactly one candidate, which will
107146
+ ** always be a non-VIEW
107147
+ */
107058107148
cntTab++;
107059107149
pMatch = pItem;
107150
+#endif
107060107151
}
107061107152
}
107062107153
if( pMatch ){
107063107154
pExpr->iTable = pMatch->iCursor;
107064107155
assert( ExprUseYTab(pExpr) );
@@ -107180,17 +107271,17 @@
107180107271
107181107272
/*
107182107273
** Perhaps the name is a reference to the ROWID
107183107274
*/
107184107275
if( cnt==0
107185
- && cntTab==1
107276
+ && cntTab>=1
107186107277
&& pMatch
107187107278
&& (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
107188107279
&& sqlite3IsRowid(zCol)
107189107280
&& ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom)
107190107281
){
107191
- cnt = 1;
107282
+ cnt = cntTab;
107192107283
if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1;
107193107284
pExpr->affExpr = SQLITE_AFF_INTEGER;
107194107285
}
107195107286
107196107287
/*
@@ -110701,19 +110792,20 @@
110701110792
pNewItem->addrFillSub = pOldItem->addrFillSub;
110702110793
pNewItem->regReturn = pOldItem->regReturn;
110703110794
pNewItem->regResult = pOldItem->regResult;
110704110795
if( pNewItem->fg.isIndexedBy ){
110705110796
pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
110797
+ }else if( pNewItem->fg.isTabFunc ){
110798
+ pNewItem->u1.pFuncArg =
110799
+ sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
110800
+ }else{
110801
+ pNewItem->u1.nRow = pOldItem->u1.nRow;
110706110802
}
110707110803
pNewItem->u2 = pOldItem->u2;
110708110804
if( pNewItem->fg.isCte ){
110709110805
pNewItem->u2.pCteUse->nUse++;
110710110806
}
110711
- if( pNewItem->fg.isTabFunc ){
110712
- pNewItem->u1.pFuncArg =
110713
- sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
110714
- }
110715110807
pTab = pNewItem->pTab = pOldItem->pTab;
110716110808
if( pTab ){
110717110809
pTab->nTabRef++;
110718110810
}
110719110811
pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
@@ -111301,13 +111393,15 @@
111301111393
}
111302111394
/* no break */ deliberate_fall_through
111303111395
case TK_IF_NULL_ROW:
111304111396
case TK_REGISTER:
111305111397
case TK_DOT:
111398
+ case TK_RAISE:
111306111399
testcase( pExpr->op==TK_REGISTER );
111307111400
testcase( pExpr->op==TK_IF_NULL_ROW );
111308111401
testcase( pExpr->op==TK_DOT );
111402
+ testcase( pExpr->op==TK_RAISE );
111309111403
pWalker->eCode = 0;
111310111404
return WRC_Abort;
111311111405
case TK_VARIABLE:
111312111406
if( pWalker->eCode==5 ){
111313111407
/* Silently convert bound parameters that appear inside of CREATE
@@ -111628,13 +111722,16 @@
111628111722
case TK_FLOAT:
111629111723
case TK_BLOB:
111630111724
return 0;
111631111725
case TK_COLUMN:
111632111726
assert( ExprUseYTab(p) );
111633
- return ExprHasProperty(p, EP_CanBeNull) ||
111634
- NEVER(p->y.pTab==0) || /* Reference to column of index on expr */
111635
- (p->iColumn>=0
111727
+ return ExprHasProperty(p, EP_CanBeNull)
111728
+ || NEVER(p->y.pTab==0) /* Reference to column of index on expr */
111729
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
111730
+ || (p->iColumn==XN_ROWID && IsView(p->y.pTab))
111731
+#endif
111732
+ || (p->iColumn>=0
111636111733
&& p->y.pTab->aCol!=0 /* Possible due to prior error */
111637111734
&& ALWAYS(p->iColumn<p->y.pTab->nCol)
111638111735
&& p->y.pTab->aCol[p->iColumn].notNull==0);
111639111736
default:
111640111737
return 1;
@@ -118166,11 +118263,16 @@
118166118263
regOut = reg+1+nField;
118167118264
}
118168118265
if( i==pTab->iPKey ){
118169118266
sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
118170118267
}else{
118268
+ char aff = pTab->aCol[i].affinity;
118269
+ if( aff==SQLITE_AFF_REAL ){
118270
+ pTab->aCol[i].affinity = SQLITE_AFF_NUMERIC;
118271
+ }
118171118272
sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
118273
+ pTab->aCol[i].affinity = aff;
118172118274
}
118173118275
nField++;
118174118276
}
118175118277
}
118176118278
if( nField==0 ){
@@ -123952,24 +124054,24 @@
123952124054
int addrTop; /* Top of the co-routine */
123953124055
int regRec; /* A record to be insert into the new table */
123954124056
int regRowid; /* Rowid of the next row to insert */
123955124057
int addrInsLoop; /* Top of the loop for inserting rows */
123956124058
Table *pSelTab; /* A table that describes the SELECT results */
124059
+ int iCsr; /* Write cursor on the new table */
123957124060
123958124061
if( IN_SPECIAL_PARSE ){
123959124062
pParse->rc = SQLITE_ERROR;
123960124063
pParse->nErr++;
123961124064
return;
123962124065
}
124066
+ iCsr = pParse->nTab++;
123963124067
regYield = ++pParse->nMem;
123964124068
regRec = ++pParse->nMem;
123965124069
regRowid = ++pParse->nMem;
123966
- assert(pParse->nTab==1);
123967124070
sqlite3MayAbort(pParse);
123968
- sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
124071
+ sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->regRoot, iDb);
123969124072
sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
123970
- pParse->nTab = 2;
123971124073
addrTop = sqlite3VdbeCurrentAddr(v) + 1;
123972124074
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
123973124075
if( pParse->nErr ) return;
123974124076
pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
123975124077
if( pSelTab==0 ) return;
@@ -123986,15 +124088,15 @@
123986124088
sqlite3VdbeJumpHere(v, addrTop - 1);
123987124089
addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
123988124090
VdbeCoverage(v);
123989124091
sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
123990124092
sqlite3TableAffinity(v, p, 0);
123991
- sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
123992
- sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
124093
+ sqlite3VdbeAddOp2(v, OP_NewRowid, iCsr, regRowid);
124094
+ sqlite3VdbeAddOp3(v, OP_Insert, iCsr, regRec, regRowid);
123993124095
sqlite3VdbeGoto(v, addrInsLoop);
123994124096
sqlite3VdbeJumpHere(v, addrInsLoop);
123995
- sqlite3VdbeAddOp1(v, OP_Close, 1);
124097
+ sqlite3VdbeAddOp1(v, OP_Close, iCsr);
123996124098
}
123997124099
123998124100
/* Compute the complete text of the CREATE statement */
123999124101
if( pSelect ){
124000124102
zStmt = createTableStmt(db, p);
@@ -124130,13 +124232,16 @@
124130124232
124131124233
/* Legacy versions of SQLite allowed the use of the magic "rowid" column
124132124234
** on a view, even though views do not have rowids. The following flag
124133124235
** setting fixes this problem. But the fix can be disabled by compiling
124134124236
** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
124135
- ** depend upon the old buggy behavior. */
124136
-#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
124137
- p->tabFlags |= TF_NoVisibleRowid;
124237
+ ** depend upon the old buggy behavior. The ability can also be toggled
124238
+ ** using sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW,...) */
124239
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
124240
+ p->tabFlags |= sqlite3Config.mNoVisibleRowid; /* Optional. Allow by default */
124241
+#else
124242
+ p->tabFlags |= TF_NoVisibleRowid; /* Never allow rowid in view */
124138124243
#endif
124139124244
124140124245
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
124141124246
iDb = sqlite3SchemaToIndex(db, p->pSchema);
124142124247
sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
@@ -130296,11 +130401,11 @@
130296130401
p = sqlite3_aggregate_context(context, 0);
130297130402
if( p && p->cnt>0 ){
130298130403
if( p->approx ){
130299130404
if( p->ovrfl ){
130300130405
sqlite3_result_error(context,"integer overflow",-1);
130301
- }else if( !sqlite3IsNaN(p->rErr) ){
130406
+ }else if( !sqlite3IsOverflow(p->rErr) ){
130302130407
sqlite3_result_double(context, p->rSum+p->rErr);
130303130408
}else{
130304130409
sqlite3_result_double(context, p->rSum);
130305130410
}
130306130411
}else{
@@ -130313,11 +130418,11 @@
130313130418
p = sqlite3_aggregate_context(context, 0);
130314130419
if( p && p->cnt>0 ){
130315130420
double r;
130316130421
if( p->approx ){
130317130422
r = p->rSum;
130318
- if( !sqlite3IsNaN(p->rErr) ) r += p->rErr;
130423
+ if( !sqlite3IsOverflow(p->rErr) ) r += p->rErr;
130319130424
}else{
130320130425
r = (double)(p->iSum);
130321130426
}
130322130427
sqlite3_result_double(context, r/(double)p->cnt);
130323130428
}
@@ -130327,11 +130432,11 @@
130327130432
double r = 0.0;
130328130433
p = sqlite3_aggregate_context(context, 0);
130329130434
if( p ){
130330130435
if( p->approx ){
130331130436
r = p->rSum;
130332
- if( !sqlite3IsNaN(p->rErr) ) r += p->rErr;
130437
+ if( !sqlite3IsOverflow(p->rErr) ) r += p->rErr;
130333130438
}else{
130334130439
r = (double)(p->iSum);
130335130440
}
130336130441
}
130337130442
sqlite3_result_double(context, r);
@@ -133257,12 +133362,14 @@
133257133362
*/
133258133363
static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){
133259133364
int ii;
133260133365
if( exprListIsConstant(pParse,pRow)==0 ) return 0;
133261133366
for(ii=0; ii<pRow->nExpr; ii++){
133262
- assert( pRow->a[ii].pExpr->affExpr==0 );
133263
- if( 0!=sqlite3ExprAffinity(pRow->a[ii].pExpr) ) return 0;
133367
+ Expr *pExpr = pRow->a[ii].pExpr;
133368
+ assert( pExpr->op!=TK_RAISE );
133369
+ assert( pExpr->affExpr==0 );
133370
+ if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
133264133371
}
133265133372
return 1;
133266133373
133267133374
}
133268133375
@@ -141342,13 +141449,13 @@
141342141449
if( pTab->nHidden==0 ){ return SQLITE_OK; }
141343141450
pConstraint = pIdxInfo->aConstraint;
141344141451
seen[0] = 0;
141345141452
seen[1] = 0;
141346141453
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
141347
- if( pConstraint->usable==0 ) continue;
141454
+ if( pConstraint->iColumn < pTab->iHidden ) continue;
141348141455
if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
141349
- if( pConstraint->iColumn < pTab->iHidden ) continue;
141456
+ if( pConstraint->usable==0 ) return SQLITE_CONSTRAINT;
141350141457
j = pConstraint->iColumn - pTab->iHidden;
141351141458
assert( j < 2 );
141352141459
seen[j] = i+1;
141353141460
}
141354141461
if( seen[0]==0 ){
@@ -141357,16 +141464,17 @@
141357141464
return SQLITE_OK;
141358141465
}
141359141466
j = seen[0]-1;
141360141467
pIdxInfo->aConstraintUsage[j].argvIndex = 1;
141361141468
pIdxInfo->aConstraintUsage[j].omit = 1;
141362
- if( seen[1]==0 ) return SQLITE_OK;
141363141469
pIdxInfo->estimatedCost = (double)20;
141364141470
pIdxInfo->estimatedRows = 20;
141365
- j = seen[1]-1;
141366
- pIdxInfo->aConstraintUsage[j].argvIndex = 2;
141367
- pIdxInfo->aConstraintUsage[j].omit = 1;
141471
+ if( seen[1] ){
141472
+ j = seen[1]-1;
141473
+ pIdxInfo->aConstraintUsage[j].argvIndex = 2;
141474
+ pIdxInfo->aConstraintUsage[j].omit = 1;
141475
+ }
141368141476
return SQLITE_OK;
141369141477
}
141370141478
141371141479
/* Create a new cursor for the pragma virtual table */
141372141480
static int pragmaVtabOpen(sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor){
@@ -144304,13 +144412,20 @@
144304144412
struct ExprList_item *aOutEx = p->pEList->a;
144305144413
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
144306144414
int addrExplain; /* Address of OP_Explain instruction */
144307144415
#endif
144308144416
144309
- ExplainQueryPlan2(addrExplain, (pParse, 0,
144310
- "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat>0?"RIGHT PART OF ":"")
144311
- );
144417
+ nKey = pOrderBy->nExpr - pSort->nOBSat;
144418
+ if( pSort->nOBSat==0 || nKey==1 ){
144419
+ ExplainQueryPlan2(addrExplain, (pParse, 0,
144420
+ "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat?"LAST TERM OF ":""
144421
+ ));
144422
+ }else{
144423
+ ExplainQueryPlan2(addrExplain, (pParse, 0,
144424
+ "USE TEMP B-TREE FOR LAST %d TERMS OF ORDER BY", nKey
144425
+ ));
144426
+ }
144312144427
sqlite3VdbeScanStatusRange(v, addrExplain,pSort->addrPush,pSort->addrPushEnd);
144313144428
sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, pSort->addrPush);
144314144429
144315144430
144316144431
assert( addrBreak<0 );
@@ -144344,11 +144459,10 @@
144344144459
nColumn = 0;
144345144460
}else{
144346144461
regRow = sqlite3GetTempRange(pParse, nColumn);
144347144462
}
144348144463
}
144349
- nKey = pOrderBy->nExpr - pSort->nOBSat;
144350144464
if( pSort->sortFlags & SORTFLAG_UseSorter ){
144351144465
int regSortOut = ++pParse->nMem;
144352144466
iSortTab = pParse->nTab++;
144353144467
if( pSort->labelBkOut ){
144354144468
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
@@ -144584,15 +144698,11 @@
144584144698
/* The "table" is actually a sub-select or a view in the FROM clause
144585144699
** of the SELECT statement. Return the declaration type and origin
144586144700
** data for the result-set column of the sub-select.
144587144701
*/
144588144702
if( iCol<pS->pEList->nExpr
144589
-#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
144590
- && iCol>=0
144591
-#else
144592
- && ALWAYS(iCol>=0)
144593
-#endif
144703
+ && (!ViewCanHaveRowid || iCol>=0)
144594144704
){
144595144705
/* If iCol is less than zero, then the expression requests the
144596144706
** rowid of the sub-select or view. This expression is legal (see
144597144707
** test case misc2.2.2) - it always evaluates to NULL.
144598144708
*/
@@ -147762,10 +147872,14 @@
147762147872
** also restriction (6) in sqlite3ExprIsSingleTableConstraint().
147763147873
**
147764147874
** (10) The inner query is not the right-hand table of a RIGHT JOIN.
147765147875
**
147766147876
** (11) The subquery is not a VALUES clause
147877
+**
147878
+** (12) The WHERE clause is not "rowid ISNULL" or the equivalent. This
147879
+** case only comes up if SQLite is compiled using
147880
+** SQLITE_ALLOW_ROWID_IN_VIEW.
147767147881
**
147768147882
** Return 0 if no changes are made and non-zero if one or more WHERE clause
147769147883
** terms are duplicated into the subquery.
147770147884
*/
147771147885
static int pushDownWhereTerms(
@@ -147870,10 +147984,22 @@
147870147984
}
147871147985
if( ExprHasProperty(pWhere,EP_OuterON)
147872147986
&& pWhere->w.iJoin!=iCursor
147873147987
){
147874147988
return 0; /* restriction (5) */
147989
+ }
147990
+#endif
147991
+
147992
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
147993
+ if( ViewCanHaveRowid && (pWhere->op==TK_ISNULL || pWhere->op==TK_NOTNULL) ){
147994
+ Expr *pLeft = pWhere->pLeft;
147995
+ if( ALWAYS(pLeft)
147996
+ && pLeft->op==TK_COLUMN
147997
+ && pLeft->iColumn < 0
147998
+ ){
147999
+ return 0; /* Restriction (12) */
148000
+ }
147875148001
}
147876148002
#endif
147877148003
147878148004
if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc) ){
147879148005
nChng++;
@@ -148500,16 +148626,18 @@
148500148626
pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
148501148627
}
148502148628
while( pSel->pPrior ){ pSel = pSel->pPrior; }
148503148629
sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
148504148630
pTab->iPKey = -1;
148631
+ pTab->eTabType = TABTYP_VIEW;
148505148632
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
148506148633
#ifndef SQLITE_ALLOW_ROWID_IN_VIEW
148507148634
/* The usual case - do not allow ROWID on a subquery */
148508148635
pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
148509148636
#else
148510
- pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */
148637
+ /* Legacy compatibility mode */
148638
+ pTab->tabFlags |= TF_Ephemeral | sqlite3Config.mNoVisibleRowid;
148511148639
#endif
148512148640
return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
148513148641
}
148514148642
148515148643
@@ -148773,11 +148901,11 @@
148773148901
if( pFrom->fg.isNestedFrom ){
148774148902
assert( pFrom->pSelect!=0 );
148775148903
pNestedFrom = pFrom->pSelect->pEList;
148776148904
assert( pNestedFrom!=0 );
148777148905
assert( pNestedFrom->nExpr==pTab->nCol );
148778
- assert( VisibleRowid(pTab)==0 );
148906
+ assert( VisibleRowid(pTab)==0 || ViewCanHaveRowid );
148779148907
}else{
148780148908
if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
148781148909
continue;
148782148910
}
148783148911
pNestedFrom = 0;
@@ -148805,11 +148933,12 @@
148805148933
}
148806148934
}else{
148807148935
pUsing = 0;
148808148936
}
148809148937
148810
- nAdd = pTab->nCol + (VisibleRowid(pTab) && (selFlags&SF_NestedFrom));
148938
+ nAdd = pTab->nCol;
148939
+ if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++;
148811148940
for(j=0; j<nAdd; j++){
148812148941
const char *zName;
148813148942
struct ExprList_item *pX; /* Newly added ExprList term */
148814148943
148815148944
if( j==pTab->nCol ){
@@ -148887,11 +149016,12 @@
148887149016
break; /* OOM */
148888149017
}
148889149018
pX = &pNew->a[pNew->nExpr-1];
148890149019
assert( pX->zEName==0 );
148891149020
if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
148892
- if( pNestedFrom ){
149021
+ if( pNestedFrom && (!ViewCanHaveRowid || j<pNestedFrom->nExpr) ){
149022
+ assert( j<pNestedFrom->nExpr );
148893149023
pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
148894149024
testcase( pX->zEName==0 );
148895149025
}else{
148896149026
pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
148897149027
zSchemaName, zTabName, zName);
@@ -155837,23 +155967,39 @@
155837155967
VtabCtx *pCtx;
155838155968
int rc = SQLITE_OK;
155839155969
Table *pTab;
155840155970
Parse sParse;
155841155971
int initBusy;
155972
+ int i;
155973
+ const unsigned char *z;
155974
+ static const u8 aKeyword[] = { TK_CREATE, TK_TABLE, 0 };
155842155975
155843155976
#ifdef SQLITE_ENABLE_API_ARMOR
155844155977
if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
155845155978
return SQLITE_MISUSE_BKPT;
155846155979
}
155847155980
#endif
155981
+
155982
+ /* Verify that the first two keywords in the CREATE TABLE statement
155983
+ ** really are "CREATE" and "TABLE". If this is not the case, then
155984
+ ** sqlite3_declare_vtab() is being misused.
155985
+ */
155986
+ z = (const unsigned char*)zCreateTable;
155987
+ for(i=0; aKeyword[i]; i++){
155988
+ int tokenType = 0;
155989
+ do{ z += sqlite3GetToken(z, &tokenType); }while( tokenType==TK_SPACE );
155990
+ if( tokenType!=aKeyword[i] ) return SQLITE_MISUSE_BKPT;
155991
+ }
155992
+
155848155993
sqlite3_mutex_enter(db->mutex);
155849155994
pCtx = db->pVtabCtx;
155850155995
if( !pCtx || pCtx->bDeclared ){
155851155996
sqlite3Error(db, SQLITE_MISUSE_BKPT);
155852155997
sqlite3_mutex_leave(db->mutex);
155853155998
return SQLITE_MISUSE_BKPT;
155854155999
}
156000
+
155855156001
pTab = pCtx->pTab;
155856156002
assert( IsVirtual(pTab) );
155857156003
155858156004
sqlite3ParseObjectInit(&sParse, db);
155859156005
sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
@@ -155863,15 +156009,14 @@
155863156009
** in case a bug arises. */
155864156010
assert( db->init.busy==0 );
155865156011
initBusy = db->init.busy;
155866156012
db->init.busy = 0;
155867156013
sParse.nQueryLoop = 1;
155868
- if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable)
155869
- && ALWAYS(sParse.pNewTable!=0)
155870
- && ALWAYS(!db->mallocFailed)
155871
- && IsOrdinaryTable(sParse.pNewTable)
155872
- ){
156014
+ if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable) ){
156015
+ assert( sParse.pNewTable!=0 );
156016
+ assert( !db->mallocFailed );
156017
+ assert( IsOrdinaryTable(sParse.pNewTable) );
155873156018
assert( sParse.zErrMsg==0 );
155874156019
if( !pTab->aCol ){
155875156020
Table *pNew = sParse.pNewTable;
155876156021
Index *pIdx;
155877156022
pTab->aCol = pNew->aCol;
@@ -162403,13 +162548,17 @@
162403162548
** structure. Used for testing and debugging only. If neither
162404162549
** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
162405162550
** are no-ops.
162406162551
*/
162407162552
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)
162408
-static void whereTraceIndexInfoInputs(sqlite3_index_info *p){
162553
+static void whereTraceIndexInfoInputs(
162554
+ sqlite3_index_info *p, /* The IndexInfo object */
162555
+ Table *pTab /* The TABLE that is the virtual table */
162556
+){
162409162557
int i;
162410162558
if( (sqlite3WhereTrace & 0x10)==0 ) return;
162559
+ sqlite3DebugPrintf("sqlite3_index_info inputs for %s:\n", pTab->zName);
162411162560
for(i=0; i<p->nConstraint; i++){
162412162561
sqlite3DebugPrintf(
162413162562
" constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n",
162414162563
i,
162415162564
p->aConstraint[i].iColumn,
@@ -162423,13 +162572,17 @@
162423162572
i,
162424162573
p->aOrderBy[i].iColumn,
162425162574
p->aOrderBy[i].desc);
162426162575
}
162427162576
}
162428
-static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){
162577
+static void whereTraceIndexInfoOutputs(
162578
+ sqlite3_index_info *p, /* The IndexInfo object */
162579
+ Table *pTab /* The TABLE that is the virtual table */
162580
+){
162429162581
int i;
162430162582
if( (sqlite3WhereTrace & 0x10)==0 ) return;
162583
+ sqlite3DebugPrintf("sqlite3_index_info outputs for %s:\n", pTab->zName);
162431162584
for(i=0; i<p->nConstraint; i++){
162432162585
sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n",
162433162586
i,
162434162587
p->aConstraintUsage[i].argvIndex,
162435162588
p->aConstraintUsage[i].omit);
@@ -162439,12 +162592,12 @@
162439162592
sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
162440162593
sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
162441162594
sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
162442162595
}
162443162596
#else
162444
-#define whereTraceIndexInfoInputs(A)
162445
-#define whereTraceIndexInfoOutputs(A)
162597
+#define whereTraceIndexInfoInputs(A,B)
162598
+#define whereTraceIndexInfoOutputs(A,B)
162446162599
#endif
162447162600
162448162601
/*
162449162602
** We know that pSrc is an operand of an outer join. Return true if
162450162603
** pTerm is a constraint that is compatible with that join.
@@ -162666,11 +162819,11 @@
162666162819
** be a covering index because the index will not be updated if the
162667162820
** original table changes and the index and table cannot both be used
162668162821
** if they go out of sync.
162669162822
*/
162670162823
if( IsView(pTable) ){
162671
- extraCols = ALLBITS;
162824
+ extraCols = ALLBITS & ~idxCols;
162672162825
}else{
162673162826
extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
162674162827
}
162675162828
mxBitCol = MIN(BMS-1,pTable->nCol);
162676162829
testcase( pTable->nCol==BMS-1 );
@@ -163183,15 +163336,15 @@
163183163336
*/
163184163337
static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
163185163338
sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
163186163339
int rc;
163187163340
163188
- whereTraceIndexInfoInputs(p);
163341
+ whereTraceIndexInfoInputs(p, pTab);
163189163342
pParse->db->nSchemaLock++;
163190163343
rc = pVtab->pModule->xBestIndex(pVtab, p);
163191163344
pParse->db->nSchemaLock--;
163192
- whereTraceIndexInfoOutputs(p);
163345
+ whereTraceIndexInfoOutputs(p, pTab);
163193163346
163194163347
if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
163195163348
if( rc==SQLITE_NOMEM ){
163196163349
sqlite3OomFault(pParse->db);
163197163350
}else if( !pVtab->zErrMsg ){
@@ -179894,10 +180047,22 @@
179894180047
case SQLITE_CONFIG_MEMDB_MAXSIZE: {
179895180048
sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
179896180049
break;
179897180050
}
179898180051
#endif /* SQLITE_OMIT_DESERIALIZE */
180052
+
180053
+ case SQLITE_CONFIG_ROWID_IN_VIEW: {
180054
+ int *pVal = va_arg(ap,int*);
180055
+#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
180056
+ if( 0==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid;
180057
+ if( 1==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = 0;
180058
+ *pVal = (sqlite3GlobalConfig.mNoVisibleRowid==0);
180059
+#else
180060
+ *pVal = 0;
180061
+#endif
180062
+ break;
180063
+ }
179899180064
179900180065
default: {
179901180066
rc = SQLITE_ERROR;
179902180067
break;
179903180068
}
@@ -217654,10 +217819,11 @@
217654217819
#if !defined(SQLITE_AMALGAMATION)
217655217820
typedef unsigned int u32;
217656217821
typedef unsigned short u16;
217657217822
typedef unsigned char u8;
217658217823
typedef sqlite3_int64 i64;
217824
+typedef sqlite3_uint64 u64;
217659217825
#endif
217660217826
217661217827
/*
217662217828
** These values must match the values defined in wal.c for the equivalent
217663217829
** locks. These are not magic numbers as they are part of the SQLite file
@@ -218340,10 +218506,11 @@
218340218506
pIter->bCleanup = 0;
218341218507
rc = sqlite3_step(pIter->pTblIter);
218342218508
if( rc!=SQLITE_ROW ){
218343218509
rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
218344218510
pIter->zTbl = 0;
218511
+ pIter->zDataTbl = 0;
218345218512
}else{
218346218513
pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
218347218514
pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
218348218515
rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
218349218516
}
@@ -220434,11 +220601,11 @@
220434220601
if( p->rc==SQLITE_OK ){
220435220602
sqlite3_file *pDb = p->pTargetFd->pReal;
220436220603
u32 volatile *ptr;
220437220604
p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
220438220605
if( p->rc==SQLITE_OK ){
220439
- iRet = ((i64)ptr[10] << 32) + ptr[11];
220606
+ iRet = (i64)(((u64)ptr[10] << 32) + ptr[11]);
220440220607
}
220441220608
}
220442220609
return iRet;
220443220610
}
220444220611
@@ -251802,11 +251969,11 @@
251802251969
int nArg, /* Number of args */
251803251970
sqlite3_value **apUnused /* Function arguments */
251804251971
){
251805251972
assert( nArg==0 );
251806251973
UNUSED_PARAM2(nArg, apUnused);
251807
- sqlite3_result_text(pCtx, "fts5: 2024-03-18 18:03:17 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61", -1, SQLITE_TRANSIENT);
251974
+ sqlite3_result_text(pCtx, "fts5: 2024-03-26 11:14:52 a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3", -1, SQLITE_TRANSIENT);
251808251975
}
251809251976
251810251977
/*
251811251978
** Return true if zName is the extension on one of the shadow tables used
251812251979
** by this module.
251813251980
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 76fb3a908f45230b956cb659c754e47603e8.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -459,11 +459,11 @@
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.46.0"
463 #define SQLITE_VERSION_NUMBER 3046000
464 #define SQLITE_SOURCE_ID "2024-03-18 18:03:17 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -2454,10 +2454,26 @@
2454 ** size can be adjusted up or down for individual databases using the
2455 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
2456 ** configuration setting is never used, then the default maximum is determined
2457 ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
2458 ** compile-time option is not set, then the default maximum is 1073741824.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2459 ** </dl>
2460 */
2461 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2462 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2463 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2485,10 +2501,11 @@
2485 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2486 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2487 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2488 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2489 #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
 
2490
2491 /*
2492 ** CAPI3REF: Database Connection Configuration Options
2493 **
2494 ** These constants are the available integer configuration options that
@@ -3599,12 +3616,12 @@
3599 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3600 #define SQLITE_COPY 0 /* No longer used */
3601 #define SQLITE_RECURSIVE 33 /* NULL NULL */
3602
3603 /*
3604 ** CAPI3REF: Tracing And Profiling Functions
3605 ** METHOD: sqlite3
3606 **
3607 ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3608 ** instead of the routines described here.
3609 **
3610 ** These routines register callback functions that can be used for
@@ -18438,10 +18455,19 @@
18438
18439 /* Does the table have a rowid */
18440 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
18441 #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0)
18442
 
 
 
 
 
 
 
 
 
18443 /*
18444 ** Each foreign key constraint is an instance of the following structure.
18445 **
18446 ** A foreign key is associated with two tables. The "from" table is
18447 ** the table that contains the REFERENCES clause that creates the foreign
@@ -20157,10 +20183,15 @@
20157 sqlite3_int64 mxMemdbSize; /* Default max memdb size */
20158 #endif
20159 #ifndef SQLITE_UNTESTABLE
20160 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
20161 #endif
 
 
 
 
 
20162 int bLocaltimeFault; /* True to fail localtime() calls */
20163 int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */
20164 int iOnceResetThreshold; /* When to reset OP_Once counters */
20165 u32 szSorterRef; /* Min size in bytes to use sorter-refs */
20166 unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
@@ -20615,14 +20646,17 @@
20615
20616 #ifndef SQLITE_OMIT_FLOATING_POINT
20617 # define EXP754 (((u64)0x7ff)<<52)
20618 # define MAN754 ((((u64)1)<<52)-1)
20619 # define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0)
 
20620 SQLITE_PRIVATE int sqlite3IsNaN(double);
 
20621 #else
20622 # define IsNaN(X) 0
20623 # define sqlite3IsNaN(X) 0
 
20624 #endif
20625
20626 /*
20627 ** An instance of the following structure holds information about SQL
20628 ** functions arguments that are the parameters to the printf() function.
@@ -21853,10 +21887,13 @@
21853 #endif
21854 #ifdef SQLITE_ALLOW_COVERING_INDEX_SCAN
21855 # if SQLITE_ALLOW_COVERING_INDEX_SCAN != 1
21856 "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN),
21857 # endif
 
 
 
21858 #endif
21859 #ifdef SQLITE_ALLOW_URI_AUTHORITY
21860 "ALLOW_URI_AUTHORITY",
21861 #endif
21862 #ifdef SQLITE_ATOMIC_INTRINSICS
@@ -22874,10 +22911,13 @@
22874 SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
22875 #endif
22876 #ifndef SQLITE_UNTESTABLE
22877 0, /* xTestCallback */
22878 #endif
 
 
 
22879 0, /* bLocaltimeFault */
22880 0, /* xAltLocaltime */
22881 0x7ffffffe, /* iOnceResetThreshold */
22882 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
22883 0, /* iPrngSeed */
@@ -34877,10 +34917,23 @@
34877 testcase( rc );
34878 return rc;
34879 }
34880 #endif /* SQLITE_OMIT_FLOATING_POINT */
34881
 
 
 
 
 
 
 
 
 
 
 
 
 
34882 /*
34883 ** Compute a string length that is limited to what can be stored in
34884 ** lower 30 bits of a 32-bit signed integer.
34885 **
34886 ** The value returned will never be negative. Nor will it ever be greater
@@ -44643,16 +44696,23 @@
44643 /* If unable to create a journal because the directory is not
44644 ** writable, change the error code to indicate that. */
44645 rc = SQLITE_READONLY_DIRECTORY;
44646 }else if( errno!=EISDIR && isReadWrite ){
44647 /* Failed to open the file for read/write access. Try read-only. */
 
44648 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
44649 openFlags &= ~(O_RDWR|O_CREAT);
44650 flags |= SQLITE_OPEN_READONLY;
44651 openFlags |= O_RDONLY;
44652 isReadonly = 1;
44653 fd = robust_open(zName, openFlags, openMode);
 
 
 
 
 
 
44654 }
44655 }
44656 if( fd<0 ){
44657 int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
44658 if( rc==SQLITE_OK ) rc = rc2;
@@ -92645,11 +92705,10 @@
92645 }
92646 return 1;
92647 }
92648 if( flags & SQLITE_SCANSTAT_COMPLEX ){
92649 idx = iScan;
92650 pScan = &p->aScan[idx];
92651 }else{
92652 /* If the COMPLEX flag is clear, then this function must ignore any
92653 ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
92654 for(idx=0; idx<p->nScan; idx++){
92655 pScan = &p->aScan[idx];
@@ -92658,10 +92717,12 @@
92658 if( iScan<0 ) break;
92659 }
92660 }
92661 }
92662 if( idx>=p->nScan ) return 1;
 
 
92663
92664 switch( iScanStatusOp ){
92665 case SQLITE_SCANSTAT_NLOOP: {
92666 if( pScan->addrLoop>0 ){
92667 *(sqlite3_int64*)pOut = aOp[pScan->addrLoop].nExec;
@@ -99169,11 +99230,12 @@
99169
99170 /* Opcode: IfSizeBetween P1 P2 P3 P4 *
99171 **
99172 ** Let N be the approximate number of rows in the table or index
99173 ** with cursor P1 and let X be 10*log2(N) if N is positive or -1
99174 ** if N is zero. Thus X will be within the range of -1 to 640, inclusive
 
99175 ** Jump to P2 if X is in between P3 and P4, inclusive.
99176 */
99177 case OP_IfSizeBetween: { /* jump */
99178 VdbeCursor *pC;
99179 BtCursor *pCrsr;
@@ -99180,12 +99242,12 @@
99180 int res;
99181 i64 sz;
99182
99183 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99184 assert( pOp->p4type==P4_INT32 );
99185 assert( pOp->p3>=-1 && pOp->p3<=640 );
99186 assert( pOp->p4.i>=-1 && pOp->p4.i<=640 );
99187 pC = p->apCsr[pOp->p1];
99188 assert( pC!=0 );
99189 pCrsr = pC->uc.pCursor;
99190 assert( pCrsr );
99191 rc = sqlite3BtreeFirst(pCrsr, &res);
@@ -107053,12 +107115,41 @@
107053 }
107054 break;
107055 }
107056 }
107057 if( 0==cnt && VisibleRowid(pTab) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107058 cntTab++;
107059 pMatch = pItem;
 
107060 }
107061 }
107062 if( pMatch ){
107063 pExpr->iTable = pMatch->iCursor;
107064 assert( ExprUseYTab(pExpr) );
@@ -107180,17 +107271,17 @@
107180
107181 /*
107182 ** Perhaps the name is a reference to the ROWID
107183 */
107184 if( cnt==0
107185 && cntTab==1
107186 && pMatch
107187 && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
107188 && sqlite3IsRowid(zCol)
107189 && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom)
107190 ){
107191 cnt = 1;
107192 if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1;
107193 pExpr->affExpr = SQLITE_AFF_INTEGER;
107194 }
107195
107196 /*
@@ -110701,19 +110792,20 @@
110701 pNewItem->addrFillSub = pOldItem->addrFillSub;
110702 pNewItem->regReturn = pOldItem->regReturn;
110703 pNewItem->regResult = pOldItem->regResult;
110704 if( pNewItem->fg.isIndexedBy ){
110705 pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
 
 
 
 
 
110706 }
110707 pNewItem->u2 = pOldItem->u2;
110708 if( pNewItem->fg.isCte ){
110709 pNewItem->u2.pCteUse->nUse++;
110710 }
110711 if( pNewItem->fg.isTabFunc ){
110712 pNewItem->u1.pFuncArg =
110713 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
110714 }
110715 pTab = pNewItem->pTab = pOldItem->pTab;
110716 if( pTab ){
110717 pTab->nTabRef++;
110718 }
110719 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
@@ -111301,13 +111393,15 @@
111301 }
111302 /* no break */ deliberate_fall_through
111303 case TK_IF_NULL_ROW:
111304 case TK_REGISTER:
111305 case TK_DOT:
 
111306 testcase( pExpr->op==TK_REGISTER );
111307 testcase( pExpr->op==TK_IF_NULL_ROW );
111308 testcase( pExpr->op==TK_DOT );
 
111309 pWalker->eCode = 0;
111310 return WRC_Abort;
111311 case TK_VARIABLE:
111312 if( pWalker->eCode==5 ){
111313 /* Silently convert bound parameters that appear inside of CREATE
@@ -111628,13 +111722,16 @@
111628 case TK_FLOAT:
111629 case TK_BLOB:
111630 return 0;
111631 case TK_COLUMN:
111632 assert( ExprUseYTab(p) );
111633 return ExprHasProperty(p, EP_CanBeNull) ||
111634 NEVER(p->y.pTab==0) || /* Reference to column of index on expr */
111635 (p->iColumn>=0
 
 
 
111636 && p->y.pTab->aCol!=0 /* Possible due to prior error */
111637 && ALWAYS(p->iColumn<p->y.pTab->nCol)
111638 && p->y.pTab->aCol[p->iColumn].notNull==0);
111639 default:
111640 return 1;
@@ -118166,11 +118263,16 @@
118166 regOut = reg+1+nField;
118167 }
118168 if( i==pTab->iPKey ){
118169 sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
118170 }else{
 
 
 
 
118171 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
 
118172 }
118173 nField++;
118174 }
118175 }
118176 if( nField==0 ){
@@ -123952,24 +124054,24 @@
123952 int addrTop; /* Top of the co-routine */
123953 int regRec; /* A record to be insert into the new table */
123954 int regRowid; /* Rowid of the next row to insert */
123955 int addrInsLoop; /* Top of the loop for inserting rows */
123956 Table *pSelTab; /* A table that describes the SELECT results */
 
123957
123958 if( IN_SPECIAL_PARSE ){
123959 pParse->rc = SQLITE_ERROR;
123960 pParse->nErr++;
123961 return;
123962 }
 
123963 regYield = ++pParse->nMem;
123964 regRec = ++pParse->nMem;
123965 regRowid = ++pParse->nMem;
123966 assert(pParse->nTab==1);
123967 sqlite3MayAbort(pParse);
123968 sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb);
123969 sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
123970 pParse->nTab = 2;
123971 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
123972 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
123973 if( pParse->nErr ) return;
123974 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
123975 if( pSelTab==0 ) return;
@@ -123986,15 +124088,15 @@
123986 sqlite3VdbeJumpHere(v, addrTop - 1);
123987 addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
123988 VdbeCoverage(v);
123989 sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
123990 sqlite3TableAffinity(v, p, 0);
123991 sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid);
123992 sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid);
123993 sqlite3VdbeGoto(v, addrInsLoop);
123994 sqlite3VdbeJumpHere(v, addrInsLoop);
123995 sqlite3VdbeAddOp1(v, OP_Close, 1);
123996 }
123997
123998 /* Compute the complete text of the CREATE statement */
123999 if( pSelect ){
124000 zStmt = createTableStmt(db, p);
@@ -124130,13 +124232,16 @@
124130
124131 /* Legacy versions of SQLite allowed the use of the magic "rowid" column
124132 ** on a view, even though views do not have rowids. The following flag
124133 ** setting fixes this problem. But the fix can be disabled by compiling
124134 ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
124135 ** depend upon the old buggy behavior. */
124136 #ifndef SQLITE_ALLOW_ROWID_IN_VIEW
124137 p->tabFlags |= TF_NoVisibleRowid;
 
 
 
124138 #endif
124139
124140 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
124141 iDb = sqlite3SchemaToIndex(db, p->pSchema);
124142 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
@@ -130296,11 +130401,11 @@
130296 p = sqlite3_aggregate_context(context, 0);
130297 if( p && p->cnt>0 ){
130298 if( p->approx ){
130299 if( p->ovrfl ){
130300 sqlite3_result_error(context,"integer overflow",-1);
130301 }else if( !sqlite3IsNaN(p->rErr) ){
130302 sqlite3_result_double(context, p->rSum+p->rErr);
130303 }else{
130304 sqlite3_result_double(context, p->rSum);
130305 }
130306 }else{
@@ -130313,11 +130418,11 @@
130313 p = sqlite3_aggregate_context(context, 0);
130314 if( p && p->cnt>0 ){
130315 double r;
130316 if( p->approx ){
130317 r = p->rSum;
130318 if( !sqlite3IsNaN(p->rErr) ) r += p->rErr;
130319 }else{
130320 r = (double)(p->iSum);
130321 }
130322 sqlite3_result_double(context, r/(double)p->cnt);
130323 }
@@ -130327,11 +130432,11 @@
130327 double r = 0.0;
130328 p = sqlite3_aggregate_context(context, 0);
130329 if( p ){
130330 if( p->approx ){
130331 r = p->rSum;
130332 if( !sqlite3IsNaN(p->rErr) ) r += p->rErr;
130333 }else{
130334 r = (double)(p->iSum);
130335 }
130336 }
130337 sqlite3_result_double(context, r);
@@ -133257,12 +133362,14 @@
133257 */
133258 static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){
133259 int ii;
133260 if( exprListIsConstant(pParse,pRow)==0 ) return 0;
133261 for(ii=0; ii<pRow->nExpr; ii++){
133262 assert( pRow->a[ii].pExpr->affExpr==0 );
133263 if( 0!=sqlite3ExprAffinity(pRow->a[ii].pExpr) ) return 0;
 
 
133264 }
133265 return 1;
133266
133267 }
133268
@@ -141342,13 +141449,13 @@
141342 if( pTab->nHidden==0 ){ return SQLITE_OK; }
141343 pConstraint = pIdxInfo->aConstraint;
141344 seen[0] = 0;
141345 seen[1] = 0;
141346 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
141347 if( pConstraint->usable==0 ) continue;
141348 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
141349 if( pConstraint->iColumn < pTab->iHidden ) continue;
141350 j = pConstraint->iColumn - pTab->iHidden;
141351 assert( j < 2 );
141352 seen[j] = i+1;
141353 }
141354 if( seen[0]==0 ){
@@ -141357,16 +141464,17 @@
141357 return SQLITE_OK;
141358 }
141359 j = seen[0]-1;
141360 pIdxInfo->aConstraintUsage[j].argvIndex = 1;
141361 pIdxInfo->aConstraintUsage[j].omit = 1;
141362 if( seen[1]==0 ) return SQLITE_OK;
141363 pIdxInfo->estimatedCost = (double)20;
141364 pIdxInfo->estimatedRows = 20;
141365 j = seen[1]-1;
141366 pIdxInfo->aConstraintUsage[j].argvIndex = 2;
141367 pIdxInfo->aConstraintUsage[j].omit = 1;
 
 
141368 return SQLITE_OK;
141369 }
141370
141371 /* Create a new cursor for the pragma virtual table */
141372 static int pragmaVtabOpen(sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor){
@@ -144304,13 +144412,20 @@
144304 struct ExprList_item *aOutEx = p->pEList->a;
144305 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
144306 int addrExplain; /* Address of OP_Explain instruction */
144307 #endif
144308
144309 ExplainQueryPlan2(addrExplain, (pParse, 0,
144310 "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat>0?"RIGHT PART OF ":"")
144311 );
 
 
 
 
 
 
 
144312 sqlite3VdbeScanStatusRange(v, addrExplain,pSort->addrPush,pSort->addrPushEnd);
144313 sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, pSort->addrPush);
144314
144315
144316 assert( addrBreak<0 );
@@ -144344,11 +144459,10 @@
144344 nColumn = 0;
144345 }else{
144346 regRow = sqlite3GetTempRange(pParse, nColumn);
144347 }
144348 }
144349 nKey = pOrderBy->nExpr - pSort->nOBSat;
144350 if( pSort->sortFlags & SORTFLAG_UseSorter ){
144351 int regSortOut = ++pParse->nMem;
144352 iSortTab = pParse->nTab++;
144353 if( pSort->labelBkOut ){
144354 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
@@ -144584,15 +144698,11 @@
144584 /* The "table" is actually a sub-select or a view in the FROM clause
144585 ** of the SELECT statement. Return the declaration type and origin
144586 ** data for the result-set column of the sub-select.
144587 */
144588 if( iCol<pS->pEList->nExpr
144589 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
144590 && iCol>=0
144591 #else
144592 && ALWAYS(iCol>=0)
144593 #endif
144594 ){
144595 /* If iCol is less than zero, then the expression requests the
144596 ** rowid of the sub-select or view. This expression is legal (see
144597 ** test case misc2.2.2) - it always evaluates to NULL.
144598 */
@@ -147762,10 +147872,14 @@
147762 ** also restriction (6) in sqlite3ExprIsSingleTableConstraint().
147763 **
147764 ** (10) The inner query is not the right-hand table of a RIGHT JOIN.
147765 **
147766 ** (11) The subquery is not a VALUES clause
 
 
 
 
147767 **
147768 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
147769 ** terms are duplicated into the subquery.
147770 */
147771 static int pushDownWhereTerms(
@@ -147870,10 +147984,22 @@
147870 }
147871 if( ExprHasProperty(pWhere,EP_OuterON)
147872 && pWhere->w.iJoin!=iCursor
147873 ){
147874 return 0; /* restriction (5) */
 
 
 
 
 
 
 
 
 
 
 
 
147875 }
147876 #endif
147877
147878 if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc) ){
147879 nChng++;
@@ -148500,16 +148626,18 @@
148500 pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
148501 }
148502 while( pSel->pPrior ){ pSel = pSel->pPrior; }
148503 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
148504 pTab->iPKey = -1;
 
148505 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
148506 #ifndef SQLITE_ALLOW_ROWID_IN_VIEW
148507 /* The usual case - do not allow ROWID on a subquery */
148508 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
148509 #else
148510 pTab->tabFlags |= TF_Ephemeral; /* Legacy compatibility mode */
 
148511 #endif
148512 return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
148513 }
148514
148515
@@ -148773,11 +148901,11 @@
148773 if( pFrom->fg.isNestedFrom ){
148774 assert( pFrom->pSelect!=0 );
148775 pNestedFrom = pFrom->pSelect->pEList;
148776 assert( pNestedFrom!=0 );
148777 assert( pNestedFrom->nExpr==pTab->nCol );
148778 assert( VisibleRowid(pTab)==0 );
148779 }else{
148780 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
148781 continue;
148782 }
148783 pNestedFrom = 0;
@@ -148805,11 +148933,12 @@
148805 }
148806 }else{
148807 pUsing = 0;
148808 }
148809
148810 nAdd = pTab->nCol + (VisibleRowid(pTab) && (selFlags&SF_NestedFrom));
 
148811 for(j=0; j<nAdd; j++){
148812 const char *zName;
148813 struct ExprList_item *pX; /* Newly added ExprList term */
148814
148815 if( j==pTab->nCol ){
@@ -148887,11 +149016,12 @@
148887 break; /* OOM */
148888 }
148889 pX = &pNew->a[pNew->nExpr-1];
148890 assert( pX->zEName==0 );
148891 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
148892 if( pNestedFrom ){
 
148893 pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
148894 testcase( pX->zEName==0 );
148895 }else{
148896 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
148897 zSchemaName, zTabName, zName);
@@ -155837,23 +155967,39 @@
155837 VtabCtx *pCtx;
155838 int rc = SQLITE_OK;
155839 Table *pTab;
155840 Parse sParse;
155841 int initBusy;
 
 
 
155842
155843 #ifdef SQLITE_ENABLE_API_ARMOR
155844 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
155845 return SQLITE_MISUSE_BKPT;
155846 }
155847 #endif
 
 
 
 
 
 
 
 
 
 
 
 
155848 sqlite3_mutex_enter(db->mutex);
155849 pCtx = db->pVtabCtx;
155850 if( !pCtx || pCtx->bDeclared ){
155851 sqlite3Error(db, SQLITE_MISUSE_BKPT);
155852 sqlite3_mutex_leave(db->mutex);
155853 return SQLITE_MISUSE_BKPT;
155854 }
 
155855 pTab = pCtx->pTab;
155856 assert( IsVirtual(pTab) );
155857
155858 sqlite3ParseObjectInit(&sParse, db);
155859 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
@@ -155863,15 +156009,14 @@
155863 ** in case a bug arises. */
155864 assert( db->init.busy==0 );
155865 initBusy = db->init.busy;
155866 db->init.busy = 0;
155867 sParse.nQueryLoop = 1;
155868 if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable)
155869 && ALWAYS(sParse.pNewTable!=0)
155870 && ALWAYS(!db->mallocFailed)
155871 && IsOrdinaryTable(sParse.pNewTable)
155872 ){
155873 assert( sParse.zErrMsg==0 );
155874 if( !pTab->aCol ){
155875 Table *pNew = sParse.pNewTable;
155876 Index *pIdx;
155877 pTab->aCol = pNew->aCol;
@@ -162403,13 +162548,17 @@
162403 ** structure. Used for testing and debugging only. If neither
162404 ** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
162405 ** are no-ops.
162406 */
162407 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)
162408 static void whereTraceIndexInfoInputs(sqlite3_index_info *p){
 
 
 
162409 int i;
162410 if( (sqlite3WhereTrace & 0x10)==0 ) return;
 
162411 for(i=0; i<p->nConstraint; i++){
162412 sqlite3DebugPrintf(
162413 " constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n",
162414 i,
162415 p->aConstraint[i].iColumn,
@@ -162423,13 +162572,17 @@
162423 i,
162424 p->aOrderBy[i].iColumn,
162425 p->aOrderBy[i].desc);
162426 }
162427 }
162428 static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){
 
 
 
162429 int i;
162430 if( (sqlite3WhereTrace & 0x10)==0 ) return;
 
162431 for(i=0; i<p->nConstraint; i++){
162432 sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n",
162433 i,
162434 p->aConstraintUsage[i].argvIndex,
162435 p->aConstraintUsage[i].omit);
@@ -162439,12 +162592,12 @@
162439 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
162440 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
162441 sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
162442 }
162443 #else
162444 #define whereTraceIndexInfoInputs(A)
162445 #define whereTraceIndexInfoOutputs(A)
162446 #endif
162447
162448 /*
162449 ** We know that pSrc is an operand of an outer join. Return true if
162450 ** pTerm is a constraint that is compatible with that join.
@@ -162666,11 +162819,11 @@
162666 ** be a covering index because the index will not be updated if the
162667 ** original table changes and the index and table cannot both be used
162668 ** if they go out of sync.
162669 */
162670 if( IsView(pTable) ){
162671 extraCols = ALLBITS;
162672 }else{
162673 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
162674 }
162675 mxBitCol = MIN(BMS-1,pTable->nCol);
162676 testcase( pTable->nCol==BMS-1 );
@@ -163183,15 +163336,15 @@
163183 */
163184 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
163185 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
163186 int rc;
163187
163188 whereTraceIndexInfoInputs(p);
163189 pParse->db->nSchemaLock++;
163190 rc = pVtab->pModule->xBestIndex(pVtab, p);
163191 pParse->db->nSchemaLock--;
163192 whereTraceIndexInfoOutputs(p);
163193
163194 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
163195 if( rc==SQLITE_NOMEM ){
163196 sqlite3OomFault(pParse->db);
163197 }else if( !pVtab->zErrMsg ){
@@ -179894,10 +180047,22 @@
179894 case SQLITE_CONFIG_MEMDB_MAXSIZE: {
179895 sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
179896 break;
179897 }
179898 #endif /* SQLITE_OMIT_DESERIALIZE */
 
 
 
 
 
 
 
 
 
 
 
 
179899
179900 default: {
179901 rc = SQLITE_ERROR;
179902 break;
179903 }
@@ -217654,10 +217819,11 @@
217654 #if !defined(SQLITE_AMALGAMATION)
217655 typedef unsigned int u32;
217656 typedef unsigned short u16;
217657 typedef unsigned char u8;
217658 typedef sqlite3_int64 i64;
 
217659 #endif
217660
217661 /*
217662 ** These values must match the values defined in wal.c for the equivalent
217663 ** locks. These are not magic numbers as they are part of the SQLite file
@@ -218340,10 +218506,11 @@
218340 pIter->bCleanup = 0;
218341 rc = sqlite3_step(pIter->pTblIter);
218342 if( rc!=SQLITE_ROW ){
218343 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
218344 pIter->zTbl = 0;
 
218345 }else{
218346 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
218347 pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
218348 rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
218349 }
@@ -220434,11 +220601,11 @@
220434 if( p->rc==SQLITE_OK ){
220435 sqlite3_file *pDb = p->pTargetFd->pReal;
220436 u32 volatile *ptr;
220437 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
220438 if( p->rc==SQLITE_OK ){
220439 iRet = ((i64)ptr[10] << 32) + ptr[11];
220440 }
220441 }
220442 return iRet;
220443 }
220444
@@ -251802,11 +251969,11 @@
251802 int nArg, /* Number of args */
251803 sqlite3_value **apUnused /* Function arguments */
251804 ){
251805 assert( nArg==0 );
251806 UNUSED_PARAM2(nArg, apUnused);
251807 sqlite3_result_text(pCtx, "fts5: 2024-03-18 18:03:17 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61", -1, SQLITE_TRANSIENT);
251808 }
251809
251810 /*
251811 ** Return true if zName is the extension on one of the shadow tables used
251812 ** by this module.
251813
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** a49296de0061931badaf3db6b965131a78b1.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -459,11 +459,11 @@
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.46.0"
463 #define SQLITE_VERSION_NUMBER 3046000
464 #define SQLITE_SOURCE_ID "2024-03-26 11:14:52 a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -2454,10 +2454,26 @@
2454 ** size can be adjusted up or down for individual databases using the
2455 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
2456 ** configuration setting is never used, then the default maximum is determined
2457 ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
2458 ** compile-time option is not set, then the default maximum is 1073741824.
2459 **
2460 ** [[SQLITE_CONFIG_ROWID_IN_VIEW]]
2461 ** <dt>SQLITE_CONFIG_ROWID_IN_VIEW
2462 ** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability
2463 ** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is
2464 ** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability
2465 ** defaults to on. This configuration option queries the current setting or
2466 ** changes the setting to off or on. The argument is a pointer to an integer.
2467 ** If that integer initially holds a value of 1, then the ability for VIEWs to
2468 ** have ROWIDs is activated. If the integer initially holds zero, then the
2469 ** ability is deactivated. Any other initial value for the integer leaves the
2470 ** setting unchanged. After changes, if any, the integer is written with
2471 ** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite
2472 ** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and
2473 ** recommended case) then the integer is always filled with zero, regardless
2474 ** if its initial value.
2475 ** </dl>
2476 */
2477 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2478 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2479 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2485,10 +2501,11 @@
2501 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2502 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2503 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2504 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2505 #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
2506 #define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */
2507
2508 /*
2509 ** CAPI3REF: Database Connection Configuration Options
2510 **
2511 ** These constants are the available integer configuration options that
@@ -3599,12 +3616,12 @@
3616 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3617 #define SQLITE_COPY 0 /* No longer used */
3618 #define SQLITE_RECURSIVE 33 /* NULL NULL */
3619
3620 /*
3621 ** CAPI3REF: Deprecated Tracing And Profiling Functions
3622 ** DEPRECATED
3623 **
3624 ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3625 ** instead of the routines described here.
3626 **
3627 ** These routines register callback functions that can be used for
@@ -18438,10 +18455,19 @@
18455
18456 /* Does the table have a rowid */
18457 #define HasRowid(X) (((X)->tabFlags & TF_WithoutRowid)==0)
18458 #define VisibleRowid(X) (((X)->tabFlags & TF_NoVisibleRowid)==0)
18459
18460 /* Macro is true if the SQLITE_ALLOW_ROWID_IN_VIEW (mis-)feature is
18461 ** available. By default, this macro is false
18462 */
18463 #ifndef SQLITE_ALLOW_ROWID_IN_VIEW
18464 # define ViewCanHaveRowid 0
18465 #else
18466 # define ViewCanHaveRowid (sqlite3Config.mNoVisibleRowid==0)
18467 #endif
18468
18469 /*
18470 ** Each foreign key constraint is an instance of the following structure.
18471 **
18472 ** A foreign key is associated with two tables. The "from" table is
18473 ** the table that contains the REFERENCES clause that creates the foreign
@@ -20157,10 +20183,15 @@
20183 sqlite3_int64 mxMemdbSize; /* Default max memdb size */
20184 #endif
20185 #ifndef SQLITE_UNTESTABLE
20186 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
20187 #endif
20188 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
20189 u32 mNoVisibleRowid; /* TF_NoVisibleRowid if the ROWID_IN_VIEW
20190 ** feature is disabled. 0 if rowids can
20191 ** occur in views. */
20192 #endif
20193 int bLocaltimeFault; /* True to fail localtime() calls */
20194 int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */
20195 int iOnceResetThreshold; /* When to reset OP_Once counters */
20196 u32 szSorterRef; /* Min size in bytes to use sorter-refs */
20197 unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
@@ -20615,14 +20646,17 @@
20646
20647 #ifndef SQLITE_OMIT_FLOATING_POINT
20648 # define EXP754 (((u64)0x7ff)<<52)
20649 # define MAN754 ((((u64)1)<<52)-1)
20650 # define IsNaN(X) (((X)&EXP754)==EXP754 && ((X)&MAN754)!=0)
20651 # define IsOvfl(X) (((X)&EXP754)==EXP754)
20652 SQLITE_PRIVATE int sqlite3IsNaN(double);
20653 SQLITE_PRIVATE int sqlite3IsOverflow(double);
20654 #else
20655 # define IsNaN(X) 0
20656 # define sqlite3IsNaN(X) 0
20657 # define sqlite3IsOVerflow(X) 0
20658 #endif
20659
20660 /*
20661 ** An instance of the following structure holds information about SQL
20662 ** functions arguments that are the parameters to the printf() function.
@@ -21853,10 +21887,13 @@
21887 #endif
21888 #ifdef SQLITE_ALLOW_COVERING_INDEX_SCAN
21889 # if SQLITE_ALLOW_COVERING_INDEX_SCAN != 1
21890 "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN),
21891 # endif
21892 #endif
21893 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
21894 "ALLOW_ROWID_IN_VIEW",
21895 #endif
21896 #ifdef SQLITE_ALLOW_URI_AUTHORITY
21897 "ALLOW_URI_AUTHORITY",
21898 #endif
21899 #ifdef SQLITE_ATOMIC_INTRINSICS
@@ -22874,10 +22911,13 @@
22911 SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
22912 #endif
22913 #ifndef SQLITE_UNTESTABLE
22914 0, /* xTestCallback */
22915 #endif
22916 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
22917 0, /* mNoVisibleRowid. 0 == allow rowid-in-view */
22918 #endif
22919 0, /* bLocaltimeFault */
22920 0, /* xAltLocaltime */
22921 0x7ffffffe, /* iOnceResetThreshold */
22922 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
22923 0, /* iPrngSeed */
@@ -34877,10 +34917,23 @@
34917 testcase( rc );
34918 return rc;
34919 }
34920 #endif /* SQLITE_OMIT_FLOATING_POINT */
34921
34922 #ifndef SQLITE_OMIT_FLOATING_POINT
34923 /*
34924 ** Return true if the floating point value is NaN or +Inf or -Inf.
34925 */
34926 SQLITE_PRIVATE int sqlite3IsOverflow(double x){
34927 int rc; /* The value return */
34928 u64 y;
34929 memcpy(&y,&x,sizeof(y));
34930 rc = IsOvfl(y);
34931 return rc;
34932 }
34933 #endif /* SQLITE_OMIT_FLOATING_POINT */
34934
34935 /*
34936 ** Compute a string length that is limited to what can be stored in
34937 ** lower 30 bits of a 32-bit signed integer.
34938 **
34939 ** The value returned will never be negative. Nor will it ever be greater
@@ -44643,16 +44696,23 @@
44696 /* If unable to create a journal because the directory is not
44697 ** writable, change the error code to indicate that. */
44698 rc = SQLITE_READONLY_DIRECTORY;
44699 }else if( errno!=EISDIR && isReadWrite ){
44700 /* Failed to open the file for read/write access. Try read-only. */
44701 UnixUnusedFd *pReadonly = 0;
44702 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
44703 openFlags &= ~(O_RDWR|O_CREAT);
44704 flags |= SQLITE_OPEN_READONLY;
44705 openFlags |= O_RDONLY;
44706 isReadonly = 1;
44707 pReadonly = findReusableFd(zName, flags);
44708 if( pReadonly ){
44709 fd = pReadonly->fd;
44710 sqlite3_free(pReadonly);
44711 }else{
44712 fd = robust_open(zName, openFlags, openMode);
44713 }
44714 }
44715 }
44716 if( fd<0 ){
44717 int rc2 = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName);
44718 if( rc==SQLITE_OK ) rc = rc2;
@@ -92645,11 +92705,10 @@
92705 }
92706 return 1;
92707 }
92708 if( flags & SQLITE_SCANSTAT_COMPLEX ){
92709 idx = iScan;
 
92710 }else{
92711 /* If the COMPLEX flag is clear, then this function must ignore any
92712 ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
92713 for(idx=0; idx<p->nScan; idx++){
92714 pScan = &p->aScan[idx];
@@ -92658,10 +92717,12 @@
92717 if( iScan<0 ) break;
92718 }
92719 }
92720 }
92721 if( idx>=p->nScan ) return 1;
92722 assert( pScan==0 || pScan==&p->aScan[idx] );
92723 pScan = &p->aScan[idx];
92724
92725 switch( iScanStatusOp ){
92726 case SQLITE_SCANSTAT_NLOOP: {
92727 if( pScan->addrLoop>0 ){
92728 *(sqlite3_int64*)pOut = aOp[pScan->addrLoop].nExec;
@@ -99169,11 +99230,12 @@
99230
99231 /* Opcode: IfSizeBetween P1 P2 P3 P4 *
99232 **
99233 ** Let N be the approximate number of rows in the table or index
99234 ** with cursor P1 and let X be 10*log2(N) if N is positive or -1
99235 ** if N is zero.
99236 **
99237 ** Jump to P2 if X is in between P3 and P4, inclusive.
99238 */
99239 case OP_IfSizeBetween: { /* jump */
99240 VdbeCursor *pC;
99241 BtCursor *pCrsr;
@@ -99180,12 +99242,12 @@
99242 int res;
99243 i64 sz;
99244
99245 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
99246 assert( pOp->p4type==P4_INT32 );
99247 assert( pOp->p3>=-1 && pOp->p3<=640*2 );
99248 assert( pOp->p4.i>=-1 && pOp->p4.i<=640*2 );
99249 pC = p->apCsr[pOp->p1];
99250 assert( pC!=0 );
99251 pCrsr = pC->uc.pCursor;
99252 assert( pCrsr );
99253 rc = sqlite3BtreeFirst(pCrsr, &res);
@@ -107053,12 +107115,41 @@
107115 }
107116 break;
107117 }
107118 }
107119 if( 0==cnt && VisibleRowid(pTab) ){
107120 /* pTab is a potential ROWID match. Keep track of it and match
107121 ** the ROWID later if that seems appropriate. (Search for "cntTab"
107122 ** to find related code.) Only allow a ROWID match if there is
107123 ** a single ROWID match candidate.
107124 */
107125 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
107126 /* In SQLITE_ALLOW_ROWID_IN_VIEW mode, allow a ROWID match
107127 ** if there is a single VIEW candidate or if there is a single
107128 ** non-VIEW candidate plus multiple VIEW candidates. In other
107129 ** words non-VIEW candidate terms take precedence over VIEWs.
107130 */
107131 if( cntTab==0
107132 || (cntTab==1
107133 && ALWAYS(pMatch!=0)
107134 && ALWAYS(pMatch->pTab!=0)
107135 && (pMatch->pTab->tabFlags & TF_Ephemeral)!=0
107136 && (pTab->tabFlags & TF_Ephemeral)==0)
107137 ){
107138 cntTab = 1;
107139 pMatch = pItem;
107140 }else{
107141 cntTab++;
107142 }
107143 #else
107144 /* The (much more common) non-SQLITE_ALLOW_ROWID_IN_VIEW case is
107145 ** simpler since we require exactly one candidate, which will
107146 ** always be a non-VIEW
107147 */
107148 cntTab++;
107149 pMatch = pItem;
107150 #endif
107151 }
107152 }
107153 if( pMatch ){
107154 pExpr->iTable = pMatch->iCursor;
107155 assert( ExprUseYTab(pExpr) );
@@ -107180,17 +107271,17 @@
107271
107272 /*
107273 ** Perhaps the name is a reference to the ROWID
107274 */
107275 if( cnt==0
107276 && cntTab>=1
107277 && pMatch
107278 && (pNC->ncFlags & (NC_IdxExpr|NC_GenCol))==0
107279 && sqlite3IsRowid(zCol)
107280 && ALWAYS(VisibleRowid(pMatch->pTab) || pMatch->fg.isNestedFrom)
107281 ){
107282 cnt = cntTab;
107283 if( pMatch->fg.isNestedFrom==0 ) pExpr->iColumn = -1;
107284 pExpr->affExpr = SQLITE_AFF_INTEGER;
107285 }
107286
107287 /*
@@ -110701,19 +110792,20 @@
110792 pNewItem->addrFillSub = pOldItem->addrFillSub;
110793 pNewItem->regReturn = pOldItem->regReturn;
110794 pNewItem->regResult = pOldItem->regResult;
110795 if( pNewItem->fg.isIndexedBy ){
110796 pNewItem->u1.zIndexedBy = sqlite3DbStrDup(db, pOldItem->u1.zIndexedBy);
110797 }else if( pNewItem->fg.isTabFunc ){
110798 pNewItem->u1.pFuncArg =
110799 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
110800 }else{
110801 pNewItem->u1.nRow = pOldItem->u1.nRow;
110802 }
110803 pNewItem->u2 = pOldItem->u2;
110804 if( pNewItem->fg.isCte ){
110805 pNewItem->u2.pCteUse->nUse++;
110806 }
 
 
 
 
110807 pTab = pNewItem->pTab = pOldItem->pTab;
110808 if( pTab ){
110809 pTab->nTabRef++;
110810 }
110811 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
@@ -111301,13 +111393,15 @@
111393 }
111394 /* no break */ deliberate_fall_through
111395 case TK_IF_NULL_ROW:
111396 case TK_REGISTER:
111397 case TK_DOT:
111398 case TK_RAISE:
111399 testcase( pExpr->op==TK_REGISTER );
111400 testcase( pExpr->op==TK_IF_NULL_ROW );
111401 testcase( pExpr->op==TK_DOT );
111402 testcase( pExpr->op==TK_RAISE );
111403 pWalker->eCode = 0;
111404 return WRC_Abort;
111405 case TK_VARIABLE:
111406 if( pWalker->eCode==5 ){
111407 /* Silently convert bound parameters that appear inside of CREATE
@@ -111628,13 +111722,16 @@
111722 case TK_FLOAT:
111723 case TK_BLOB:
111724 return 0;
111725 case TK_COLUMN:
111726 assert( ExprUseYTab(p) );
111727 return ExprHasProperty(p, EP_CanBeNull)
111728 || NEVER(p->y.pTab==0) /* Reference to column of index on expr */
111729 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
111730 || (p->iColumn==XN_ROWID && IsView(p->y.pTab))
111731 #endif
111732 || (p->iColumn>=0
111733 && p->y.pTab->aCol!=0 /* Possible due to prior error */
111734 && ALWAYS(p->iColumn<p->y.pTab->nCol)
111735 && p->y.pTab->aCol[p->iColumn].notNull==0);
111736 default:
111737 return 1;
@@ -118166,11 +118263,16 @@
118263 regOut = reg+1+nField;
118264 }
118265 if( i==pTab->iPKey ){
118266 sqlite3VdbeAddOp2(v, OP_Null, 0, regOut);
118267 }else{
118268 char aff = pTab->aCol[i].affinity;
118269 if( aff==SQLITE_AFF_REAL ){
118270 pTab->aCol[i].affinity = SQLITE_AFF_NUMERIC;
118271 }
118272 sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOut);
118273 pTab->aCol[i].affinity = aff;
118274 }
118275 nField++;
118276 }
118277 }
118278 if( nField==0 ){
@@ -123952,24 +124054,24 @@
124054 int addrTop; /* Top of the co-routine */
124055 int regRec; /* A record to be insert into the new table */
124056 int regRowid; /* Rowid of the next row to insert */
124057 int addrInsLoop; /* Top of the loop for inserting rows */
124058 Table *pSelTab; /* A table that describes the SELECT results */
124059 int iCsr; /* Write cursor on the new table */
124060
124061 if( IN_SPECIAL_PARSE ){
124062 pParse->rc = SQLITE_ERROR;
124063 pParse->nErr++;
124064 return;
124065 }
124066 iCsr = pParse->nTab++;
124067 regYield = ++pParse->nMem;
124068 regRec = ++pParse->nMem;
124069 regRowid = ++pParse->nMem;
 
124070 sqlite3MayAbort(pParse);
124071 sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->regRoot, iDb);
124072 sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
 
124073 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
124074 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
124075 if( pParse->nErr ) return;
124076 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
124077 if( pSelTab==0 ) return;
@@ -123986,15 +124088,15 @@
124088 sqlite3VdbeJumpHere(v, addrTop - 1);
124089 addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
124090 VdbeCoverage(v);
124091 sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec);
124092 sqlite3TableAffinity(v, p, 0);
124093 sqlite3VdbeAddOp2(v, OP_NewRowid, iCsr, regRowid);
124094 sqlite3VdbeAddOp3(v, OP_Insert, iCsr, regRec, regRowid);
124095 sqlite3VdbeGoto(v, addrInsLoop);
124096 sqlite3VdbeJumpHere(v, addrInsLoop);
124097 sqlite3VdbeAddOp1(v, OP_Close, iCsr);
124098 }
124099
124100 /* Compute the complete text of the CREATE statement */
124101 if( pSelect ){
124102 zStmt = createTableStmt(db, p);
@@ -124130,13 +124232,16 @@
124232
124233 /* Legacy versions of SQLite allowed the use of the magic "rowid" column
124234 ** on a view, even though views do not have rowids. The following flag
124235 ** setting fixes this problem. But the fix can be disabled by compiling
124236 ** with -DSQLITE_ALLOW_ROWID_IN_VIEW in case there are legacy apps that
124237 ** depend upon the old buggy behavior. The ability can also be toggled
124238 ** using sqlite3_config(SQLITE_CONFIG_ROWID_IN_VIEW,...) */
124239 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
124240 p->tabFlags |= sqlite3Config.mNoVisibleRowid; /* Optional. Allow by default */
124241 #else
124242 p->tabFlags |= TF_NoVisibleRowid; /* Never allow rowid in view */
124243 #endif
124244
124245 sqlite3TwoPartName(pParse, pName1, pName2, &pName);
124246 iDb = sqlite3SchemaToIndex(db, p->pSchema);
124247 sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
@@ -130296,11 +130401,11 @@
130401 p = sqlite3_aggregate_context(context, 0);
130402 if( p && p->cnt>0 ){
130403 if( p->approx ){
130404 if( p->ovrfl ){
130405 sqlite3_result_error(context,"integer overflow",-1);
130406 }else if( !sqlite3IsOverflow(p->rErr) ){
130407 sqlite3_result_double(context, p->rSum+p->rErr);
130408 }else{
130409 sqlite3_result_double(context, p->rSum);
130410 }
130411 }else{
@@ -130313,11 +130418,11 @@
130418 p = sqlite3_aggregate_context(context, 0);
130419 if( p && p->cnt>0 ){
130420 double r;
130421 if( p->approx ){
130422 r = p->rSum;
130423 if( !sqlite3IsOverflow(p->rErr) ) r += p->rErr;
130424 }else{
130425 r = (double)(p->iSum);
130426 }
130427 sqlite3_result_double(context, r/(double)p->cnt);
130428 }
@@ -130327,11 +130432,11 @@
130432 double r = 0.0;
130433 p = sqlite3_aggregate_context(context, 0);
130434 if( p ){
130435 if( p->approx ){
130436 r = p->rSum;
130437 if( !sqlite3IsOverflow(p->rErr) ) r += p->rErr;
130438 }else{
130439 r = (double)(p->iSum);
130440 }
130441 }
130442 sqlite3_result_double(context, r);
@@ -133257,12 +133362,14 @@
133362 */
133363 static int exprListIsNoAffinity(Parse *pParse, ExprList *pRow){
133364 int ii;
133365 if( exprListIsConstant(pParse,pRow)==0 ) return 0;
133366 for(ii=0; ii<pRow->nExpr; ii++){
133367 Expr *pExpr = pRow->a[ii].pExpr;
133368 assert( pExpr->op!=TK_RAISE );
133369 assert( pExpr->affExpr==0 );
133370 if( 0!=sqlite3ExprAffinity(pExpr) ) return 0;
133371 }
133372 return 1;
133373
133374 }
133375
@@ -141342,13 +141449,13 @@
141449 if( pTab->nHidden==0 ){ return SQLITE_OK; }
141450 pConstraint = pIdxInfo->aConstraint;
141451 seen[0] = 0;
141452 seen[1] = 0;
141453 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
141454 if( pConstraint->iColumn < pTab->iHidden ) continue;
141455 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
141456 if( pConstraint->usable==0 ) return SQLITE_CONSTRAINT;
141457 j = pConstraint->iColumn - pTab->iHidden;
141458 assert( j < 2 );
141459 seen[j] = i+1;
141460 }
141461 if( seen[0]==0 ){
@@ -141357,16 +141464,17 @@
141464 return SQLITE_OK;
141465 }
141466 j = seen[0]-1;
141467 pIdxInfo->aConstraintUsage[j].argvIndex = 1;
141468 pIdxInfo->aConstraintUsage[j].omit = 1;
 
141469 pIdxInfo->estimatedCost = (double)20;
141470 pIdxInfo->estimatedRows = 20;
141471 if( seen[1] ){
141472 j = seen[1]-1;
141473 pIdxInfo->aConstraintUsage[j].argvIndex = 2;
141474 pIdxInfo->aConstraintUsage[j].omit = 1;
141475 }
141476 return SQLITE_OK;
141477 }
141478
141479 /* Create a new cursor for the pragma virtual table */
141480 static int pragmaVtabOpen(sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor){
@@ -144304,13 +144412,20 @@
144412 struct ExprList_item *aOutEx = p->pEList->a;
144413 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
144414 int addrExplain; /* Address of OP_Explain instruction */
144415 #endif
144416
144417 nKey = pOrderBy->nExpr - pSort->nOBSat;
144418 if( pSort->nOBSat==0 || nKey==1 ){
144419 ExplainQueryPlan2(addrExplain, (pParse, 0,
144420 "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat?"LAST TERM OF ":""
144421 ));
144422 }else{
144423 ExplainQueryPlan2(addrExplain, (pParse, 0,
144424 "USE TEMP B-TREE FOR LAST %d TERMS OF ORDER BY", nKey
144425 ));
144426 }
144427 sqlite3VdbeScanStatusRange(v, addrExplain,pSort->addrPush,pSort->addrPushEnd);
144428 sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, pSort->addrPush);
144429
144430
144431 assert( addrBreak<0 );
@@ -144344,11 +144459,10 @@
144459 nColumn = 0;
144460 }else{
144461 regRow = sqlite3GetTempRange(pParse, nColumn);
144462 }
144463 }
 
144464 if( pSort->sortFlags & SORTFLAG_UseSorter ){
144465 int regSortOut = ++pParse->nMem;
144466 iSortTab = pParse->nTab++;
144467 if( pSort->labelBkOut ){
144468 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
@@ -144584,15 +144698,11 @@
144698 /* The "table" is actually a sub-select or a view in the FROM clause
144699 ** of the SELECT statement. Return the declaration type and origin
144700 ** data for the result-set column of the sub-select.
144701 */
144702 if( iCol<pS->pEList->nExpr
144703 && (!ViewCanHaveRowid || iCol>=0)
 
 
 
 
144704 ){
144705 /* If iCol is less than zero, then the expression requests the
144706 ** rowid of the sub-select or view. This expression is legal (see
144707 ** test case misc2.2.2) - it always evaluates to NULL.
144708 */
@@ -147762,10 +147872,14 @@
147872 ** also restriction (6) in sqlite3ExprIsSingleTableConstraint().
147873 **
147874 ** (10) The inner query is not the right-hand table of a RIGHT JOIN.
147875 **
147876 ** (11) The subquery is not a VALUES clause
147877 **
147878 ** (12) The WHERE clause is not "rowid ISNULL" or the equivalent. This
147879 ** case only comes up if SQLite is compiled using
147880 ** SQLITE_ALLOW_ROWID_IN_VIEW.
147881 **
147882 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
147883 ** terms are duplicated into the subquery.
147884 */
147885 static int pushDownWhereTerms(
@@ -147870,10 +147984,22 @@
147984 }
147985 if( ExprHasProperty(pWhere,EP_OuterON)
147986 && pWhere->w.iJoin!=iCursor
147987 ){
147988 return 0; /* restriction (5) */
147989 }
147990 #endif
147991
147992 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
147993 if( ViewCanHaveRowid && (pWhere->op==TK_ISNULL || pWhere->op==TK_NOTNULL) ){
147994 Expr *pLeft = pWhere->pLeft;
147995 if( ALWAYS(pLeft)
147996 && pLeft->op==TK_COLUMN
147997 && pLeft->iColumn < 0
147998 ){
147999 return 0; /* Restriction (12) */
148000 }
148001 }
148002 #endif
148003
148004 if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrcList, iSrc) ){
148005 nChng++;
@@ -148500,16 +148626,18 @@
148626 pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
148627 }
148628 while( pSel->pPrior ){ pSel = pSel->pPrior; }
148629 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
148630 pTab->iPKey = -1;
148631 pTab->eTabType = TABTYP_VIEW;
148632 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
148633 #ifndef SQLITE_ALLOW_ROWID_IN_VIEW
148634 /* The usual case - do not allow ROWID on a subquery */
148635 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
148636 #else
148637 /* Legacy compatibility mode */
148638 pTab->tabFlags |= TF_Ephemeral | sqlite3Config.mNoVisibleRowid;
148639 #endif
148640 return pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
148641 }
148642
148643
@@ -148773,11 +148901,11 @@
148901 if( pFrom->fg.isNestedFrom ){
148902 assert( pFrom->pSelect!=0 );
148903 pNestedFrom = pFrom->pSelect->pEList;
148904 assert( pNestedFrom!=0 );
148905 assert( pNestedFrom->nExpr==pTab->nCol );
148906 assert( VisibleRowid(pTab)==0 || ViewCanHaveRowid );
148907 }else{
148908 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
148909 continue;
148910 }
148911 pNestedFrom = 0;
@@ -148805,11 +148933,12 @@
148933 }
148934 }else{
148935 pUsing = 0;
148936 }
148937
148938 nAdd = pTab->nCol;
148939 if( VisibleRowid(pTab) && (selFlags & SF_NestedFrom)!=0 ) nAdd++;
148940 for(j=0; j<nAdd; j++){
148941 const char *zName;
148942 struct ExprList_item *pX; /* Newly added ExprList term */
148943
148944 if( j==pTab->nCol ){
@@ -148887,11 +149016,12 @@
149016 break; /* OOM */
149017 }
149018 pX = &pNew->a[pNew->nExpr-1];
149019 assert( pX->zEName==0 );
149020 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
149021 if( pNestedFrom && (!ViewCanHaveRowid || j<pNestedFrom->nExpr) ){
149022 assert( j<pNestedFrom->nExpr );
149023 pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
149024 testcase( pX->zEName==0 );
149025 }else{
149026 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
149027 zSchemaName, zTabName, zName);
@@ -155837,23 +155967,39 @@
155967 VtabCtx *pCtx;
155968 int rc = SQLITE_OK;
155969 Table *pTab;
155970 Parse sParse;
155971 int initBusy;
155972 int i;
155973 const unsigned char *z;
155974 static const u8 aKeyword[] = { TK_CREATE, TK_TABLE, 0 };
155975
155976 #ifdef SQLITE_ENABLE_API_ARMOR
155977 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
155978 return SQLITE_MISUSE_BKPT;
155979 }
155980 #endif
155981
155982 /* Verify that the first two keywords in the CREATE TABLE statement
155983 ** really are "CREATE" and "TABLE". If this is not the case, then
155984 ** sqlite3_declare_vtab() is being misused.
155985 */
155986 z = (const unsigned char*)zCreateTable;
155987 for(i=0; aKeyword[i]; i++){
155988 int tokenType = 0;
155989 do{ z += sqlite3GetToken(z, &tokenType); }while( tokenType==TK_SPACE );
155990 if( tokenType!=aKeyword[i] ) return SQLITE_MISUSE_BKPT;
155991 }
155992
155993 sqlite3_mutex_enter(db->mutex);
155994 pCtx = db->pVtabCtx;
155995 if( !pCtx || pCtx->bDeclared ){
155996 sqlite3Error(db, SQLITE_MISUSE_BKPT);
155997 sqlite3_mutex_leave(db->mutex);
155998 return SQLITE_MISUSE_BKPT;
155999 }
156000
156001 pTab = pCtx->pTab;
156002 assert( IsVirtual(pTab) );
156003
156004 sqlite3ParseObjectInit(&sParse, db);
156005 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
@@ -155863,15 +156009,14 @@
156009 ** in case a bug arises. */
156010 assert( db->init.busy==0 );
156011 initBusy = db->init.busy;
156012 db->init.busy = 0;
156013 sParse.nQueryLoop = 1;
156014 if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable) ){
156015 assert( sParse.pNewTable!=0 );
156016 assert( !db->mallocFailed );
156017 assert( IsOrdinaryTable(sParse.pNewTable) );
 
156018 assert( sParse.zErrMsg==0 );
156019 if( !pTab->aCol ){
156020 Table *pNew = sParse.pNewTable;
156021 Index *pIdx;
156022 pTab->aCol = pNew->aCol;
@@ -162403,13 +162548,17 @@
162548 ** structure. Used for testing and debugging only. If neither
162549 ** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines
162550 ** are no-ops.
162551 */
162552 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)
162553 static void whereTraceIndexInfoInputs(
162554 sqlite3_index_info *p, /* The IndexInfo object */
162555 Table *pTab /* The TABLE that is the virtual table */
162556 ){
162557 int i;
162558 if( (sqlite3WhereTrace & 0x10)==0 ) return;
162559 sqlite3DebugPrintf("sqlite3_index_info inputs for %s:\n", pTab->zName);
162560 for(i=0; i<p->nConstraint; i++){
162561 sqlite3DebugPrintf(
162562 " constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n",
162563 i,
162564 p->aConstraint[i].iColumn,
@@ -162423,13 +162572,17 @@
162572 i,
162573 p->aOrderBy[i].iColumn,
162574 p->aOrderBy[i].desc);
162575 }
162576 }
162577 static void whereTraceIndexInfoOutputs(
162578 sqlite3_index_info *p, /* The IndexInfo object */
162579 Table *pTab /* The TABLE that is the virtual table */
162580 ){
162581 int i;
162582 if( (sqlite3WhereTrace & 0x10)==0 ) return;
162583 sqlite3DebugPrintf("sqlite3_index_info outputs for %s:\n", pTab->zName);
162584 for(i=0; i<p->nConstraint; i++){
162585 sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n",
162586 i,
162587 p->aConstraintUsage[i].argvIndex,
162588 p->aConstraintUsage[i].omit);
@@ -162439,12 +162592,12 @@
162592 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
162593 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
162594 sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
162595 }
162596 #else
162597 #define whereTraceIndexInfoInputs(A,B)
162598 #define whereTraceIndexInfoOutputs(A,B)
162599 #endif
162600
162601 /*
162602 ** We know that pSrc is an operand of an outer join. Return true if
162603 ** pTerm is a constraint that is compatible with that join.
@@ -162666,11 +162819,11 @@
162819 ** be a covering index because the index will not be updated if the
162820 ** original table changes and the index and table cannot both be used
162821 ** if they go out of sync.
162822 */
162823 if( IsView(pTable) ){
162824 extraCols = ALLBITS & ~idxCols;
162825 }else{
162826 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
162827 }
162828 mxBitCol = MIN(BMS-1,pTable->nCol);
162829 testcase( pTable->nCol==BMS-1 );
@@ -163183,15 +163336,15 @@
163336 */
163337 static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
163338 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
163339 int rc;
163340
163341 whereTraceIndexInfoInputs(p, pTab);
163342 pParse->db->nSchemaLock++;
163343 rc = pVtab->pModule->xBestIndex(pVtab, p);
163344 pParse->db->nSchemaLock--;
163345 whereTraceIndexInfoOutputs(p, pTab);
163346
163347 if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
163348 if( rc==SQLITE_NOMEM ){
163349 sqlite3OomFault(pParse->db);
163350 }else if( !pVtab->zErrMsg ){
@@ -179894,10 +180047,22 @@
180047 case SQLITE_CONFIG_MEMDB_MAXSIZE: {
180048 sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
180049 break;
180050 }
180051 #endif /* SQLITE_OMIT_DESERIALIZE */
180052
180053 case SQLITE_CONFIG_ROWID_IN_VIEW: {
180054 int *pVal = va_arg(ap,int*);
180055 #ifdef SQLITE_ALLOW_ROWID_IN_VIEW
180056 if( 0==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = TF_NoVisibleRowid;
180057 if( 1==*pVal ) sqlite3GlobalConfig.mNoVisibleRowid = 0;
180058 *pVal = (sqlite3GlobalConfig.mNoVisibleRowid==0);
180059 #else
180060 *pVal = 0;
180061 #endif
180062 break;
180063 }
180064
180065 default: {
180066 rc = SQLITE_ERROR;
180067 break;
180068 }
@@ -217654,10 +217819,11 @@
217819 #if !defined(SQLITE_AMALGAMATION)
217820 typedef unsigned int u32;
217821 typedef unsigned short u16;
217822 typedef unsigned char u8;
217823 typedef sqlite3_int64 i64;
217824 typedef sqlite3_uint64 u64;
217825 #endif
217826
217827 /*
217828 ** These values must match the values defined in wal.c for the equivalent
217829 ** locks. These are not magic numbers as they are part of the SQLite file
@@ -218340,10 +218506,11 @@
218506 pIter->bCleanup = 0;
218507 rc = sqlite3_step(pIter->pTblIter);
218508 if( rc!=SQLITE_ROW ){
218509 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
218510 pIter->zTbl = 0;
218511 pIter->zDataTbl = 0;
218512 }else{
218513 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
218514 pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
218515 rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
218516 }
@@ -220434,11 +220601,11 @@
220601 if( p->rc==SQLITE_OK ){
220602 sqlite3_file *pDb = p->pTargetFd->pReal;
220603 u32 volatile *ptr;
220604 p->rc = pDb->pMethods->xShmMap(pDb, 0, 32*1024, 0, (void volatile**)&ptr);
220605 if( p->rc==SQLITE_OK ){
220606 iRet = (i64)(((u64)ptr[10] << 32) + ptr[11]);
220607 }
220608 }
220609 return iRet;
220610 }
220611
@@ -251802,11 +251969,11 @@
251969 int nArg, /* Number of args */
251970 sqlite3_value **apUnused /* Function arguments */
251971 ){
251972 assert( nArg==0 );
251973 UNUSED_PARAM2(nArg, apUnused);
251974 sqlite3_result_text(pCtx, "fts5: 2024-03-26 11:14:52 a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3", -1, SQLITE_TRANSIENT);
251975 }
251976
251977 /*
251978 ** Return true if zName is the extension on one of the shadow tables used
251979 ** by this module.
251980
+20 -3
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.46.0"
150150
#define SQLITE_VERSION_NUMBER 3046000
151
-#define SQLITE_SOURCE_ID "2024-03-18 18:03:17 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61"
151
+#define SQLITE_SOURCE_ID "2024-03-26 11:14:52 a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -2141,10 +2141,26 @@
21412141
** size can be adjusted up or down for individual databases using the
21422142
** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
21432143
** configuration setting is never used, then the default maximum is determined
21442144
** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
21452145
** compile-time option is not set, then the default maximum is 1073741824.
2146
+**
2147
+** [[SQLITE_CONFIG_ROWID_IN_VIEW]]
2148
+** <dt>SQLITE_CONFIG_ROWID_IN_VIEW
2149
+** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability
2150
+** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is
2151
+** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability
2152
+** defaults to on. This configuration option queries the current setting or
2153
+** changes the setting to off or on. The argument is a pointer to an integer.
2154
+** If that integer initially holds a value of 1, then the ability for VIEWs to
2155
+** have ROWIDs is activated. If the integer initially holds zero, then the
2156
+** ability is deactivated. Any other initial value for the integer leaves the
2157
+** setting unchanged. After changes, if any, the integer is written with
2158
+** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite
2159
+** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and
2160
+** recommended case) then the integer is always filled with zero, regardless
2161
+** if its initial value.
21462162
** </dl>
21472163
*/
21482164
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
21492165
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
21502166
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2172,10 +2188,11 @@
21722188
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
21732189
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
21742190
#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
21752191
#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
21762192
#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
2193
+#define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */
21772194
21782195
/*
21792196
** CAPI3REF: Database Connection Configuration Options
21802197
**
21812198
** These constants are the available integer configuration options that
@@ -3286,12 +3303,12 @@
32863303
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
32873304
#define SQLITE_COPY 0 /* No longer used */
32883305
#define SQLITE_RECURSIVE 33 /* NULL NULL */
32893306
32903307
/*
3291
-** CAPI3REF: Tracing And Profiling Functions
3292
-** METHOD: sqlite3
3308
+** CAPI3REF: Deprecated Tracing And Profiling Functions
3309
+** DEPRECATED
32933310
**
32943311
** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
32953312
** instead of the routines described here.
32963313
**
32973314
** These routines register callback functions that can be used for
32983315
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.46.0"
150 #define SQLITE_VERSION_NUMBER 3046000
151 #define SQLITE_SOURCE_ID "2024-03-18 18:03:17 76fb3a908f45230b956cb659c754e47603e80aa72a2aad50d479437a9c013f61"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2141,10 +2141,26 @@
2141 ** size can be adjusted up or down for individual databases using the
2142 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
2143 ** configuration setting is never used, then the default maximum is determined
2144 ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
2145 ** compile-time option is not set, then the default maximum is 1073741824.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2146 ** </dl>
2147 */
2148 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2149 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2150 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2172,10 +2188,11 @@
2172 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2173 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2174 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2175 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2176 #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
 
2177
2178 /*
2179 ** CAPI3REF: Database Connection Configuration Options
2180 **
2181 ** These constants are the available integer configuration options that
@@ -3286,12 +3303,12 @@
3286 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3287 #define SQLITE_COPY 0 /* No longer used */
3288 #define SQLITE_RECURSIVE 33 /* NULL NULL */
3289
3290 /*
3291 ** CAPI3REF: Tracing And Profiling Functions
3292 ** METHOD: sqlite3
3293 **
3294 ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3295 ** instead of the routines described here.
3296 **
3297 ** These routines register callback functions that can be used for
3298
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.46.0"
150 #define SQLITE_VERSION_NUMBER 3046000
151 #define SQLITE_SOURCE_ID "2024-03-26 11:14:52 a49296de0061931badaf3db6b965131a78b1c6c21b1eeb62815ea7adf767d0b3"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -2141,10 +2141,26 @@
2141 ** size can be adjusted up or down for individual databases using the
2142 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
2143 ** configuration setting is never used, then the default maximum is determined
2144 ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
2145 ** compile-time option is not set, then the default maximum is 1073741824.
2146 **
2147 ** [[SQLITE_CONFIG_ROWID_IN_VIEW]]
2148 ** <dt>SQLITE_CONFIG_ROWID_IN_VIEW
2149 ** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability
2150 ** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is
2151 ** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability
2152 ** defaults to on. This configuration option queries the current setting or
2153 ** changes the setting to off or on. The argument is a pointer to an integer.
2154 ** If that integer initially holds a value of 1, then the ability for VIEWs to
2155 ** have ROWIDs is activated. If the integer initially holds zero, then the
2156 ** ability is deactivated. Any other initial value for the integer leaves the
2157 ** setting unchanged. After changes, if any, the integer is written with
2158 ** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite
2159 ** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and
2160 ** recommended case) then the integer is always filled with zero, regardless
2161 ** if its initial value.
2162 ** </dl>
2163 */
2164 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2165 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2166 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2172,10 +2188,11 @@
2188 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2189 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2190 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2191 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2192 #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
2193 #define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */
2194
2195 /*
2196 ** CAPI3REF: Database Connection Configuration Options
2197 **
2198 ** These constants are the available integer configuration options that
@@ -3286,12 +3303,12 @@
3303 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3304 #define SQLITE_COPY 0 /* No longer used */
3305 #define SQLITE_RECURSIVE 33 /* NULL NULL */
3306
3307 /*
3308 ** CAPI3REF: Deprecated Tracing And Profiling Functions
3309 ** DEPRECATED
3310 **
3311 ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3312 ** instead of the routines described here.
3313 **
3314 ** These routines register callback functions that can be used for
3315

Keyboard Shortcuts

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