Fossil SCM

Bring branch up to date with trunk.

andybradford 2022-05-14 14:23 stash-success merge
Commit 393e73cf3ed944e4dfe01fdb9d745a23652cd17721d94454612a59124cb69874
+455 -140
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.39.0"
456456
#define SQLITE_VERSION_NUMBER 3039000
457
-#define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
457
+#define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -15790,12 +15790,14 @@
1579015790
# define sqlite3VdbeVerifyNoMallocRequired(A,B)
1579115791
# define sqlite3VdbeVerifyNoResultRow(A)
1579215792
#endif
1579315793
#if defined(SQLITE_DEBUG)
1579415794
SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
15795
+SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
1579515796
#else
1579615797
# define sqlite3VdbeVerifyAbortable(A,B)
15798
+# define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
1579715799
#endif
1579815800
SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
1579915801
#ifndef SQLITE_OMIT_EXPLAIN
1580015802
SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
1580115803
SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
@@ -17051,10 +17053,12 @@
1705117053
/* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
1705217054
#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
1705317055
#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
1705417056
#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
1705517057
#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17058
+#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17059
+ /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
1705617060
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1705717061
1705817062
/*
1705917063
** Macros for testing whether or not optimizations are enabled or disabled.
1706017064
*/
@@ -17396,10 +17400,11 @@
1739617400
#define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
1739717401
#define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
1739817402
#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
1739917403
#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
1740017404
#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17405
+#define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
1740117406
#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
1740217407
#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
1740317408
1740417409
/*
1740517410
** A "Collating Sequence" is defined by an instance of the following
@@ -18269,17 +18274,22 @@
1826918274
int nExpr; /* Number of expressions on the list */
1827018275
int nAlloc; /* Number of a[] slots allocated */
1827118276
struct ExprList_item { /* For each expression in the list */
1827218277
Expr *pExpr; /* The parse tree for this expression */
1827318278
char *zEName; /* Token associated with this expression */
18274
- u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18275
- unsigned eEName :2; /* Meaning of zEName */
18276
- unsigned done :1; /* A flag to indicate when processing is finished */
18277
- unsigned reusable :1; /* Constant expression is reusable */
18278
- unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18279
- unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18280
- unsigned bUsed: 1; /* This column used in a SF_NestedFrom subquery */
18279
+ struct {
18280
+ u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18281
+ unsigned eEName :2; /* Meaning of zEName */
18282
+ unsigned done :1; /* Indicates when processing is finished */
18283
+ unsigned reusable :1; /* Constant expression is reusable */
18284
+ unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18285
+ unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
18286
+ unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
18287
+ unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
18288
+ unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should
18289
+ ** not be expanded by "*" in parent queries */
18290
+ } fg;
1828118291
union {
1828218292
struct { /* Used by any ExprList other than Parse.pConsExpr */
1828318293
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1828418294
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1828518295
} x;
@@ -19729,10 +19739,11 @@
1972919739
SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
1973019740
SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
1973119741
SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
1973219742
SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
1973319743
SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19744
+SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
1973419745
SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
1973519746
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
1973619747
SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
1973719748
SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
1973819749
SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20022,10 +20033,11 @@
2002220033
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
2002320034
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
2002420035
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
2002520036
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
2002620037
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20038
+SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
2002720039
#ifdef SQLITE_ENABLE_CURSOR_HINTS
2002820040
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
2002920041
#endif
2003020042
SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
2003120043
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -20583,10 +20595,11 @@
2058320595
** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
2058420596
*/
2058520597
#define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
2058620598
#define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
2058720599
#define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
20600
+#define IN_INDEX_REUSE_CUR 0x0008 /* Reuse prior table cursor */
2058820601
SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
2058920602
2059020603
SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
2059120604
SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
2059220605
#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
@@ -30462,12 +30475,18 @@
3046230475
sqlite3_str_append(pAccum, ".", 1);
3046330476
}
3046430477
sqlite3_str_appendall(pAccum, pItem->zName);
3046530478
}else if( pItem->zAlias ){
3046630479
sqlite3_str_appendall(pAccum, pItem->zAlias);
30467
- }else if( ALWAYS(pItem->pSelect) ){
30468
- sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
30480
+ }else{
30481
+ Select *pSel = pItem->pSelect;
30482
+ assert( pSel!=0 );
30483
+ if( pSel->selFlags & SF_NestedFrom ){
30484
+ sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId);
30485
+ }else{
30486
+ sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId);
30487
+ }
3046930488
}
3047030489
length = width = 0;
3047130490
break;
3047230491
}
3047330492
default: {
@@ -31047,10 +31066,57 @@
3104731066
*/
3104831067
static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
3104931068
sqlite3TreeViewPush(&p, moreFollows);
3105031069
sqlite3TreeViewLine(p, "%s", zLabel);
3105131070
}
31071
+
31072
+/*
31073
+** Show a list of Column objects in tree format.
31074
+*/
31075
+SQLITE_PRIVATE void sqlite3TreeViewColumnList(
31076
+ TreeView *pView,
31077
+ const Column *aCol,
31078
+ int nCol,
31079
+ u8 moreToFollow
31080
+){
31081
+ int i;
31082
+ sqlite3TreeViewPush(&pView, moreToFollow);
31083
+ sqlite3TreeViewLine(pView, "COLUMNS");
31084
+ for(i=0; i<nCol; i++){
31085
+ u16 flg = aCol[i].colFlags;
31086
+ int moreToFollow = i<(nCol - 1);
31087
+ sqlite3TreeViewPush(&pView, moreToFollow);
31088
+ sqlite3TreeViewLine(pView, 0);
31089
+ printf(" %s", aCol[i].zCnName);
31090
+ switch( aCol[i].eCType ){
31091
+ case COLTYPE_ANY: printf(" ANY"); break;
31092
+ case COLTYPE_BLOB: printf(" BLOB"); break;
31093
+ case COLTYPE_INT: printf(" INT"); break;
31094
+ case COLTYPE_INTEGER: printf(" INTEGER"); break;
31095
+ case COLTYPE_REAL: printf(" REAL"); break;
31096
+ case COLTYPE_TEXT: printf(" TEXT"); break;
31097
+ case COLTYPE_CUSTOM: {
31098
+ if( flg & COLFLAG_HASTYPE ){
31099
+ const char *z = aCol[i].zCnName;
31100
+ z += strlen(z)+1;
31101
+ printf(" X-%s", z);
31102
+ break;
31103
+ }
31104
+ }
31105
+ }
31106
+ if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY");
31107
+ if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN");
31108
+#ifdef COLFLAG_NOEXPAND
31109
+ if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND");
31110
+#endif
31111
+ if( flg ) printf(" flags=%04x", flg);
31112
+ printf("\n");
31113
+ fflush(stdout);
31114
+ sqlite3TreeViewPop(&pView);
31115
+ }
31116
+ sqlite3TreeViewPop(&pView);
31117
+}
3105231118
3105331119
/*
3105431120
** Generate a human-readable description of a WITH clause.
3105531121
*/
3105631122
SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31077,10 +31143,14 @@
3107731143
sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
3107831144
cSep = ',';
3107931145
}
3108031146
sqlite3_str_appendf(&x, ")");
3108131147
}
31148
+ if( pCte->eM10d!=M10d_Any ){
31149
+ sqlite3_str_appendf(&x, " %sMATERIALIZED",
31150
+ pCte->eM10d==M10d_No ? "NOT " : "");
31151
+ }
3108231152
if( pCte->pUse ){
3108331153
sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
3108431154
pCte->pUse->nUse);
3108531155
}
3108631156
sqlite3StrAccumFinish(&x);
@@ -31099,10 +31169,11 @@
3109931169
int i;
3110031170
if( pSrc==0 ) return;
3110131171
for(i=0; i<pSrc->nSrc; i++){
3110231172
const SrcItem *pItem = &pSrc->a[i];
3110331173
StrAccum x;
31174
+ int n = 0;
3110431175
char zLine[100];
3110531176
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
3110631177
x.printfFlags |= SQLITE_PRINTF_INTERNAL;
3110731178
sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
3110831179
if( pItem->pTab ){
@@ -31127,13 +31198,24 @@
3112731198
if( pItem->fg.isCte ){
3112831199
sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
3112931200
}
3113031201
sqlite3StrAccumFinish(&x);
3113131202
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31203
+ n = 0;
31204
+ if( pItem->pSelect ) n++;
31205
+ if( pItem->fg.isTabFunc ) n++;
31206
+ if( pItem->fg.isUsing ) n++;
31207
+ if( pItem->fg.isUsing ){
31208
+ sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
31209
+ }
3113231210
if( pItem->pSelect ){
31211
+ if( pItem->pTab ){
31212
+ Table *pTab = pItem->pTab;
31213
+ sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31214
+ }
3113331215
assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31134
- sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
31216
+ sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
3113531217
}
3113631218
if( pItem->fg.isTabFunc ){
3113731219
sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
3113831220
}
3113931221
sqlite3TreeViewPop(&pView);
@@ -31296,10 +31378,11 @@
3129631378
/*
3129731379
** Generate a human-readable explanation for a Window object
3129831380
*/
3129931381
SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
3130031382
int nElement = 0;
31383
+ if( pWin==0 ) return;
3130131384
if( pWin->pFilter ){
3130231385
sqlite3TreeViewItem(pView, "FILTER", 1);
3130331386
sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
3130431387
sqlite3TreeViewPop(&pView);
3130531388
}
@@ -31360,10 +31443,11 @@
3136031443
#ifndef SQLITE_OMIT_WINDOWFUNC
3136131444
/*
3136231445
** Generate a human-readable explanation for a Window Function object
3136331446
*/
3136431447
SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31448
+ if( pWin==0 ) return;
3136531449
sqlite3TreeViewPush(&pView, more);
3136631450
sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
3136731451
pWin->pWFunc->zName, pWin->pWFunc->nArg);
3136831452
sqlite3TreeViewWindow(pView, pWin, 0);
3136931453
sqlite3TreeViewPop(&pView);
@@ -31611,11 +31695,21 @@
3161131695
sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
3161231696
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3161331697
break;
3161431698
}
3161531699
case TK_IN: {
31616
- sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
31700
+ sqlite3_str *pStr = sqlite3_str_new(0);
31701
+ char *z;
31702
+ sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags);
31703
+ if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable);
31704
+ if( ExprHasProperty(pExpr, EP_Subrtn) ){
31705
+ sqlite3_str_appendf(pStr, " subrtn(%d,%d)",
31706
+ pExpr->y.sub.regReturn, pExpr->y.sub.iAddr);
31707
+ }
31708
+ z = sqlite3_str_finish(pStr);
31709
+ sqlite3TreeViewLine(pView, z);
31710
+ sqlite3_free(z);
3161731711
sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
3161831712
if( ExprUseXSelect(pExpr) ){
3161931713
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3162031714
}else{
3162131715
sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31762,17 +31856,19 @@
3176231856
if( j || zName ){
3176331857
sqlite3TreeViewPush(&pView, moreToFollow);
3176431858
moreToFollow = 0;
3176531859
sqlite3TreeViewLine(pView, 0);
3176631860
if( zName ){
31767
- switch( pList->a[i].eEName ){
31861
+ switch( pList->a[i].fg.eEName ){
3176831862
default:
3176931863
fprintf(stdout, "AS %s ", zName);
3177031864
break;
3177131865
case ENAME_TAB:
3177231866
fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31773
- if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) ");
31867
+ if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) ");
31868
+ if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) ");
31869
+ if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) ");
3177431870
break;
3177531871
case ENAME_SPAN:
3177631872
fprintf(stdout, "SPAN(\"%s\") ", zName);
3177731873
break;
3177831874
}
@@ -81423,10 +81519,94 @@
8142381519
pParse->nLabel = 0;
8142481520
*pMaxFuncArgs = nMaxArgs;
8142581521
assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
8142681522
}
8142781523
81524
+#ifdef SQLITE_DEBUG
81525
+/*
81526
+** Check to see if a subroutine contains a jump to a location outside of
81527
+** the subroutine. If a jump outside the subroutine is detected, add code
81528
+** that will cause the program to halt with an error message.
81529
+**
81530
+** The subroutine consists of opcodes between iFirst and iLast. Jumps to
81531
+** locations within the subroutine are acceptable. iRetReg is a register
81532
+** that contains the return address. Jumps to outside the range of iFirst
81533
+** through iLast are also acceptable as long as the jump destination is
81534
+** an OP_Return to iReturnAddr.
81535
+**
81536
+** A jump to an unresolved label means that the jump destination will be
81537
+** beyond the current address. That is normally a jump to an early
81538
+** termination and is consider acceptable.
81539
+**
81540
+** This routine only runs during debug builds. The purpose is (of course)
81541
+** to detect invalid escapes out of a subroutine. The OP_Halt opcode
81542
+** is generated rather than an assert() or other error, so that ".eqp full"
81543
+** will still work to show the original bytecode, to aid in debugging.
81544
+*/
81545
+SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(
81546
+ Vdbe *v, /* The byte-code program under construction */
81547
+ int iFirst, /* First opcode of the subroutine */
81548
+ int iLast, /* Last opcode of the subroutine */
81549
+ int iRetReg /* Subroutine return address register */
81550
+){
81551
+ VdbeOp *pOp;
81552
+ Parse *pParse;
81553
+ int i;
81554
+ sqlite3_str *pErr = 0;
81555
+ assert( v!=0 );
81556
+ pParse = v->pParse;
81557
+ assert( pParse!=0 );
81558
+ if( pParse->nErr ) return;
81559
+ assert( iLast>=iFirst );
81560
+ assert( iLast<v->nOp );
81561
+ pOp = &v->aOp[iFirst];
81562
+ for(i=iFirst; i<=iLast; i++, pOp++){
81563
+ if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
81564
+ int iDest = pOp->p2; /* Jump destination */
81565
+ if( iDest==0 ) continue;
81566
+ if( pOp->opcode==OP_Gosub ) continue;
81567
+ if( iDest<0 ){
81568
+ int j = ADDR(iDest);
81569
+ assert( j>=0 );
81570
+ if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
81571
+ continue;
81572
+ }
81573
+ iDest = pParse->aLabel[j];
81574
+ }
81575
+ if( iDest<iFirst || iDest>iLast ){
81576
+ int j = iDest;
81577
+ for(; j<v->nOp; j++){
81578
+ VdbeOp *pX = &v->aOp[j];
81579
+ if( pX->opcode==OP_Return ){
81580
+ if( pX->p1==iRetReg ) break;
81581
+ continue;
81582
+ }
81583
+ if( pX->opcode==OP_Noop ) continue;
81584
+ if( pX->opcode==OP_Explain ) continue;
81585
+ if( pErr==0 ){
81586
+ pErr = sqlite3_str_new(0);
81587
+ }else{
81588
+ sqlite3_str_appendchar(pErr, 1, '\n');
81589
+ }
81590
+ sqlite3_str_appendf(pErr,
81591
+ "Opcode at %d jumps to %d which is outside the "
81592
+ "subroutine at %d..%d",
81593
+ i, iDest, iFirst, iLast);
81594
+ break;
81595
+ }
81596
+ }
81597
+ }
81598
+ }
81599
+ if( pErr ){
81600
+ char *zErr = sqlite3_str_finish(pErr);
81601
+ sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
81602
+ sqlite3_free(zErr);
81603
+ sqlite3MayAbort(pParse);
81604
+ }
81605
+}
81606
+#endif /* SQLITE_DEBUG */
81607
+
8142881608
/*
8142981609
** Return the address of the next instruction to be inserted.
8143081610
*/
8143181611
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
8143281612
assert( p->eVdbeState==VDBE_INIT_STATE );
@@ -89154,10 +89334,12 @@
8915489334
if( pOp->p2==0 ) break;
8915589335
8915689336
/* Most jump operations do a goto to this spot in order to update
8915789337
** the pOp pointer. */
8915889338
jump_to_p2:
89339
+ assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
89340
+ assert( pOp->p2<p->nOp ); /* Jumps must be in range */
8915989341
pOp = &aOp[pOp->p2 - 1];
8916089342
break;
8916189343
}
8916289344
8916389345
/* Opcode: EndCoroutine P1 * * * *
@@ -101365,11 +101547,11 @@
101365101547
const char *zTab,
101366101548
const char *zDb
101367101549
){
101368101550
int n;
101369101551
const char *zSpan;
101370
- if( pItem->eEName!=ENAME_TAB ) return 0;
101552
+ if( pItem->fg.eEName!=ENAME_TAB ) return 0;
101371101553
zSpan = pItem->zEName;
101372101554
for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101373101555
if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101374101556
return 0;
101375101557
}
@@ -101594,12 +101776,13 @@
101594101776
}
101595101777
cnt++;
101596101778
cntTab = 2;
101597101779
pMatch = pItem;
101598101780
pExpr->iColumn = j;
101599
- pEList->a[j].bUsed = 1;
101781
+ pEList->a[j].fg.bUsed = 1;
101600101782
hit = 1;
101783
+ if( pEList->a[j].fg.bUsingTerm ) break;
101601101784
}
101602101785
if( hit || zTab==0 ) continue;
101603101786
}
101604101787
assert( zDb==0 || zTab!=0 );
101605101788
if( zTab ){
@@ -101818,11 +102001,11 @@
101818102001
){
101819102002
pEList = pNC->uNC.pEList;
101820102003
assert( pEList!=0 );
101821102004
for(j=0; j<pEList->nExpr; j++){
101822102005
char *zAs = pEList->a[j].zEName;
101823
- if( pEList->a[j].eEName==ENAME_NAME
102006
+ if( pEList->a[j].fg.eEName==ENAME_NAME
101824102007
&& sqlite3_stricmp(zAs, zCol)==0
101825102008
){
101826102009
Expr *pOrig;
101827102010
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
101828102011
assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102571,11 +102754,11 @@
102571102754
if( pE->op==TK_ID ){
102572102755
const char *zCol;
102573102756
assert( !ExprHasProperty(pE, EP_IntValue) );
102574102757
zCol = pE->u.zToken;
102575102758
for(i=0; i<pEList->nExpr; i++){
102576
- if( pEList->a[i].eEName==ENAME_NAME
102759
+ if( pEList->a[i].fg.eEName==ENAME_NAME
102577102760
&& sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102578102761
){
102579102762
return i+1;
102580102763
}
102581102764
}
@@ -102692,11 +102875,11 @@
102692102875
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102693102876
sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102694102877
return 1;
102695102878
}
102696102879
for(i=0; i<pOrderBy->nExpr; i++){
102697
- pOrderBy->a[i].done = 0;
102880
+ pOrderBy->a[i].fg.done = 0;
102698102881
}
102699102882
pSelect->pNext = 0;
102700102883
while( pSelect->pPrior ){
102701102884
pSelect->pPrior->pNext = pSelect;
102702102885
pSelect = pSelect->pPrior;
@@ -102707,11 +102890,11 @@
102707102890
pEList = pSelect->pEList;
102708102891
assert( pEList!=0 );
102709102892
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102710102893
int iCol = -1;
102711102894
Expr *pE, *pDup;
102712
- if( pItem->done ) continue;
102895
+ if( pItem->fg.done ) continue;
102713102896
pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102714102897
if( NEVER(pE==0) ) continue;
102715102898
if( sqlite3ExprIsInteger(pE, &iCol) ){
102716102899
if( iCol<=0 || iCol>pEList->nExpr ){
102717102900
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102760,19 +102943,19 @@
102760102943
pParent->pLeft = pNew;
102761102944
}
102762102945
sqlite3ExprDelete(db, pE);
102763102946
pItem->u.x.iOrderByCol = (u16)iCol;
102764102947
}
102765
- pItem->done = 1;
102948
+ pItem->fg.done = 1;
102766102949
}else{
102767102950
moreToDo = 1;
102768102951
}
102769102952
}
102770102953
pSelect = pSelect->pNext;
102771102954
}
102772102955
for(i=0; i<pOrderBy->nExpr; i++){
102773
- if( pOrderBy->a[i].done==0 ){
102956
+ if( pOrderBy->a[i].fg.done==0 ){
102774102957
sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102775102958
"column in the result set", i+1);
102776102959
return 1;
102777102960
}
102778102961
}
@@ -104911,10 +105094,11 @@
104911105094
pRet->nCte = p->nCte;
104912105095
for(i=0; i<p->nCte; i++){
104913105096
pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
104914105097
pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
104915105098
pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
105099
+ pRet->a[i].eM10d = p->a[i].eM10d;
104916105100
}
104917105101
}
104918105102
}
104919105103
return pRet;
104920105104
}
@@ -105011,16 +105195,12 @@
105011105195
}
105012105196
pNewExpr->pLeft = pPriorSelectColNew;
105013105197
}
105014105198
}
105015105199
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105016
- pItem->sortFlags = pOldItem->sortFlags;
105017
- pItem->eEName = pOldItem->eEName;
105018
- pItem->done = 0;
105019
- pItem->bNulls = pOldItem->bNulls;
105020
- pItem->bUsed = pOldItem->bUsed;
105021
- pItem->bSorterRef = pOldItem->bSorterRef;
105200
+ pItem->fg = pOldItem->fg;
105201
+ pItem->fg.done = 0;
105022105202
pItem->u = pOldItem->u;
105023105203
}
105024105204
return pNew;
105025105205
}
105026105206
@@ -105316,20 +105496,20 @@
105316105496
|| eNulls==SQLITE_SO_ASC
105317105497
|| eNulls==SQLITE_SO_DESC
105318105498
);
105319105499
105320105500
pItem = &p->a[p->nExpr-1];
105321
- assert( pItem->bNulls==0 );
105501
+ assert( pItem->fg.bNulls==0 );
105322105502
if( iSortOrder==SQLITE_SO_UNDEFINED ){
105323105503
iSortOrder = SQLITE_SO_ASC;
105324105504
}
105325
- pItem->sortFlags = (u8)iSortOrder;
105505
+ pItem->fg.sortFlags = (u8)iSortOrder;
105326105506
105327105507
if( eNulls!=SQLITE_SO_UNDEFINED ){
105328
- pItem->bNulls = 1;
105508
+ pItem->fg.bNulls = 1;
105329105509
if( iSortOrder!=eNulls ){
105330
- pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105510
+ pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
105331105511
}
105332105512
}
105333105513
}
105334105514
105335105515
/*
@@ -105351,11 +105531,11 @@
105351105531
if( pList ){
105352105532
struct ExprList_item *pItem;
105353105533
assert( pList->nExpr>0 );
105354105534
pItem = &pList->a[pList->nExpr-1];
105355105535
assert( pItem->zEName==0 );
105356
- assert( pItem->eEName==ENAME_NAME );
105536
+ assert( pItem->fg.eEName==ENAME_NAME );
105357105537
pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105358105538
if( dequote ){
105359105539
/* If dequote==0, then pName->z does not point to part of a DDL
105360105540
** statement handled by the parser. And so no token need be added
105361105541
** to the token-map. */
@@ -105386,11 +105566,11 @@
105386105566
if( pList ){
105387105567
struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105388105568
assert( pList->nExpr>0 );
105389105569
if( pItem->zEName==0 ){
105390105570
pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105391
- pItem->eEName = ENAME_SPAN;
105571
+ pItem->fg.eEName = ENAME_SPAN;
105392105572
}
105393105573
}
105394105574
}
105395105575
105396105576
/*
@@ -105678,10 +105858,46 @@
105678105858
** table other than iCur.
105679105859
*/
105680105860
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
105681105861
return exprIsConst(p, 3, iCur);
105682105862
}
105863
+
105864
+/*
105865
+** Check pExpr to see if it is an invariant constraint on data source pSrc.
105866
+** This is an optimization. False negatives will perhaps cause slower
105867
+** queries, but false positives will yield incorrect answers. So when in
105868
+** doubt, return 0.
105869
+**
105870
+** To be an invariant constraint, the following must be true:
105871
+**
105872
+** (1) pExpr cannot refer to any table other than pSrc->iCursor.
105873
+**
105874
+** (2) pExpr cannot use subqueries or non-deterministic functions.
105875
+**
105876
+** (3) pSrc cannot be part of the left operand for a RIGHT JOIN.
105877
+** (Is there some way to relax this constraint?)
105878
+**
105879
+** (4) If pSrc is the right operand of a LEFT JOIN, then...
105880
+** (4a) pExpr must come from an ON clause..
105881
+ (4b) and specifically the ON clause associated with the LEFT JOIN.
105882
+**
105883
+** (5) If pSrc is not the right operand of a LEFT JOIN or the left
105884
+** operand of a RIGHT JOIN, then pExpr must be from the WHERE
105885
+** clause, not an ON clause.
105886
+*/
105887
+SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
105888
+ if( pSrc->fg.jointype & JT_LTORJ ){
105889
+ return 0; /* rule (3) */
105890
+ }
105891
+ if( pSrc->fg.jointype & JT_LEFT ){
105892
+ if( !ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (4a) */
105893
+ if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
105894
+ }else{
105895
+ if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (5) */
105896
+ }
105897
+ return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
105898
+}
105683105899
105684105900
105685105901
/*
105686105902
** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
105687105903
*/
@@ -106006,11 +106222,11 @@
106006106222
** The job of this routine is to find or create a b-tree object that can
106007106223
** be used either to test for membership in the RHS set or to iterate through
106008106224
** all members of the RHS set, skipping duplicates.
106009106225
**
106010106226
** A cursor is opened on the b-tree object that is the RHS of the IN operator
106011
-** and pX->iTable is set to the index of that cursor.
106227
+** and the *piTab parameter is set to the index of that cursor.
106012106228
**
106013106229
** The returned value of this function indicates the b-tree type, as follows:
106014106230
**
106015106231
** IN_INDEX_ROWID - The cursor was opened on a database table.
106016106232
** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106026,11 +106242,14 @@
106026106242
** SELECT <column1>, <column2>... FROM <table>
106027106243
**
106028106244
** If the RHS of the IN operator is a list or a more complex subquery, then
106029106245
** an ephemeral table might need to be generated from the RHS and then
106030106246
** pX->iTable made to point to the ephemeral table instead of an
106031
-** existing table.
106247
+** existing table. In this case, the creation and initialization of the
106248
+** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
106249
+** will be set on pX and the pX->y.sub fields will be set to show where
106250
+** the subroutine is coded.
106032106251
**
106033106252
** The inFlags parameter must contain, at a minimum, one of the bits
106034106253
** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106035106254
** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106036106255
** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106087,16 +106306,21 @@
106087106306
int *aiMap, /* Mapping from Index fields to RHS fields */
106088106307
int *piTab /* OUT: index to use */
106089106308
){
106090106309
Select *p; /* SELECT to the right of IN operator */
106091106310
int eType = 0; /* Type of RHS table. IN_INDEX_* */
106092
- int iTab = pParse->nTab++; /* Cursor of the RHS table */
106311
+ int iTab; /* Cursor of the RHS table */
106093106312
int mustBeUnique; /* True if RHS must be unique */
106094106313
Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106095106314
106096106315
assert( pX->op==TK_IN );
106097106316
mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
106317
+ if( pX->iTable && (inFlags & IN_INDEX_REUSE_CUR)!=0 ){
106318
+ iTab = pX->iTable;
106319
+ }else{
106320
+ iTab = pParse->nTab++;
106321
+ }
106098106322
106099106323
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
106100106324
** whether or not the SELECT result contains NULL values, check whether
106101106325
** or not NULL is actually possible (it may not be, for example, due
106102106326
** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106258,10 +106482,12 @@
106258106482
if( eType==0
106259106483
&& (inFlags & IN_INDEX_NOOP_OK)
106260106484
&& ExprUseXList(pX)
106261106485
&& (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106262106486
){
106487
+ pParse->nTab--; /* Back out the allocation of the unused cursor */
106488
+ iTab = -1; /* Cursor is not allocated */
106263106489
eType = IN_INDEX_NOOP;
106264106490
}
106265106491
106266106492
if( eType==0 ){
106267106493
/* Could not find an existing table or index to use as the RHS b-tree.
@@ -106424,11 +106650,13 @@
106424106650
pExpr->x.pSelect->selId));
106425106651
}
106426106652
assert( ExprUseYSub(pExpr) );
106427106653
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106428106654
pExpr->y.sub.iAddr);
106429
- sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106655
+ if( iTab!=pExpr->iTable ){
106656
+ sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106657
+ }
106430106658
sqlite3VdbeJumpHere(v, addrOnce);
106431106659
return;
106432106660
}
106433106661
106434106662
/* Begin coding the subroutine */
@@ -108164,11 +108392,13 @@
108164108392
p = pParse->pConstExpr;
108165108393
if( regDest<0 && p ){
108166108394
struct ExprList_item *pItem;
108167108395
int i;
108168108396
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108169
- if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
108397
+ if( pItem->fg.reusable
108398
+ && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108399
+ ){
108170108400
return pItem->u.iConstExprReg;
108171108401
}
108172108402
}
108173108403
}
108174108404
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108187,11 +108417,11 @@
108187108417
sqlite3VdbeJumpHere(v, addr);
108188108418
}else{
108189108419
p = sqlite3ExprListAppend(pParse, p, pExpr);
108190108420
if( p ){
108191108421
struct ExprList_item *pItem = &p->a[p->nExpr-1];
108192
- pItem->reusable = regDest<0;
108422
+ pItem->fg.reusable = regDest<0;
108193108423
if( regDest<0 ) regDest = ++pParse->nMem;
108194108424
pItem->u.iConstExprReg = regDest;
108195108425
}
108196108426
pParse->pConstExpr = p;
108197108427
}
@@ -108321,11 +108551,11 @@
108321108551
n = pList->nExpr;
108322108552
if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108323108553
for(pItem=pList->a, i=0; i<n; i++, pItem++){
108324108554
Expr *pExpr = pItem->pExpr;
108325108555
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
108326
- if( pItem->bSorterRef ){
108556
+ if( pItem->fg.bSorterRef ){
108327108557
i--;
108328108558
n--;
108329108559
}else
108330108560
#endif
108331108561
if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -108946,11 +109176,11 @@
108946109176
if( pA->nExpr!=pB->nExpr ) return 1;
108947109177
for(i=0; i<pA->nExpr; i++){
108948109178
int res;
108949109179
Expr *pExprA = pA->a[i].pExpr;
108950109180
Expr *pExprB = pB->a[i].pExpr;
108951
- if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
109181
+ if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1;
108952109182
if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
108953109183
}
108954109184
return 0;
108955109185
}
108956109186
@@ -110635,11 +110865,11 @@
110635110865
return WRC_Prune;
110636110866
}
110637110867
if( ALWAYS(p->pEList) ){
110638110868
ExprList *pList = p->pEList;
110639110869
for(i=0; i<pList->nExpr; i++){
110640
- if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110870
+ if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
110641110871
sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110642110872
}
110643110873
}
110644110874
}
110645110875
if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110684,11 +110914,11 @@
110684110914
memset(&sWalker, 0, sizeof(Walker));
110685110915
sWalker.pParse = pParse;
110686110916
sWalker.xExprCallback = renameUnmapExprCb;
110687110917
sqlite3WalkExprList(&sWalker, pEList);
110688110918
for(i=0; i<pEList->nExpr; i++){
110689
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110919
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
110690110920
sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110691110921
}
110692110922
}
110693110923
}
110694110924
}
@@ -110842,11 +111072,11 @@
110842111072
){
110843111073
if( pEList ){
110844111074
int i;
110845111075
for(i=0; i<pEList->nExpr; i++){
110846111076
const char *zName = pEList->a[i].zEName;
110847
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
111077
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
110848111078
&& ALWAYS(zName!=0)
110849111079
&& 0==sqlite3_stricmp(zName, zOld)
110850111080
){
110851111081
renameTokenFind(pParse, pCtx, (const void*)zName);
110852111082
}
@@ -112867,13 +113097,18 @@
112867113097
** * the index contains 100 rows,
112868113098
** * "WHERE a=?" matches 10 rows, and
112869113099
** * "WHERE a=? AND b=?" matches 2 rows.
112870113100
**
112871113101
** If D is the count of distinct values and K is the total number of
112872
- ** rows, then each estimate is computed as:
113102
+ ** rows, then each estimate is usually computed as:
112873113103
**
112874113104
** I = (K+D-1)/D
113105
+ **
113106
+ ** In other words, I is K/D rounded up to the next whole integer.
113107
+ ** However, if I is between 1.0 and 1.1 (in other words if I is
113108
+ ** close to 1.0 but just a little larger) then do not round up but
113109
+ ** instead keep the I value at 1.0.
112875113110
*/
112876113111
sqlite3_str sStat; /* Text of the constructed "stat" line */
112877113112
int i; /* Loop counter */
112878113113
112879113114
sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -112880,10 +113115,11 @@
112880113115
sqlite3_str_appendf(&sStat, "%llu",
112881113116
p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
112882113117
for(i=0; i<p->nKeyCol; i++){
112883113118
u64 nDistinct = p->current.anDLt[i] + 1;
112884113119
u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
113120
+ if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
112885113121
sqlite3_str_appendf(&sStat, " %llu", iVal);
112886113122
assert( p->current.anEq[i] );
112887113123
}
112888113124
sqlite3ResultStrAccum(context, &sStat);
112889113125
}
@@ -115001,13 +115237,11 @@
115001115237
Returning *pReturning = pParse->u1.pReturning;
115002115238
int addrRewind;
115003115239
int i;
115004115240
int reg;
115005115241
115006
- if( NEVER(pReturning->nRetCol==0) ){
115007
- assert( CORRUPT_DB );
115008
- }else{
115242
+ if( pReturning->nRetCol ){
115009115243
sqlite3VdbeAddOp0(v, OP_FkCheck);
115010115244
addrRewind =
115011115245
sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
115012115246
VdbeCoverage(v);
115013115247
reg = pReturning->iRetReg;
@@ -115099,13 +115333,11 @@
115099115333
}
115100115334
}
115101115335
115102115336
if( pParse->bReturning ){
115103115337
Returning *pRet = pParse->u1.pReturning;
115104
- if( NEVER(pRet->nRetCol==0) ){
115105
- assert( CORRUPT_DB );
115106
- }else{
115338
+ if( pRet->nRetCol ){
115107115339
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115108115340
}
115109115341
}
115110115342
115111115343
/* Finally, jump back to the beginning of the executable code. */
@@ -116723,11 +116955,11 @@
116723116955
}
116724116956
pTab->iPKey = iCol;
116725116957
pTab->keyConf = (u8)onError;
116726116958
assert( autoInc==0 || autoInc==1 );
116727116959
pTab->tabFlags |= autoInc*TF_Autoincrement;
116728
- if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116960
+ if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
116729116961
(void)sqlite3HasExplicitNulls(pParse, pList);
116730116962
}else if( autoInc ){
116731116963
#ifndef SQLITE_OMIT_AUTOINCREMENT
116732116964
sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116733116965
"INTEGER PRIMARY KEY");
@@ -117217,11 +117449,11 @@
117217117449
return;
117218117450
}
117219117451
if( IN_RENAME_OBJECT ){
117220117452
sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117221117453
}
117222
- pList->a[0].sortFlags = pParse->iPkSortOrder;
117454
+ pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
117223117455
assert( pParse->pNewTable==pTab );
117224117456
pTab->iPKey = -1;
117225117457
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117226117458
SQLITE_IDXTYPE_PRIMARYKEY);
117227117459
if( pParse->nErr ){
@@ -117888,11 +118120,10 @@
117888118120
*/
117889118121
SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
117890118122
Table *pSelTab; /* A fake table from which we get the result set */
117891118123
Select *pSel; /* Copy of the SELECT that implements the view */
117892118124
int nErr = 0; /* Number of errors encountered */
117893
- int n; /* Temporarily holds the number of cursors assigned */
117894118125
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
117895118126
#ifndef SQLITE_OMIT_VIRTUALTABLE
117896118127
int rc;
117897118128
#endif
117898118129
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -117946,12 +118177,13 @@
117946118177
*/
117947118178
assert( IsView(pTable) );
117948118179
pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
117949118180
if( pSel ){
117950118181
u8 eParseMode = pParse->eParseMode;
118182
+ int nTab = pParse->nTab;
118183
+ int nSelect = pParse->nSelect;
117951118184
pParse->eParseMode = PARSE_MODE_NORMAL;
117952
- n = pParse->nTab;
117953118185
sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
117954118186
pTable->nCol = -1;
117955118187
DisableLookaside;
117956118188
#ifndef SQLITE_OMIT_AUTHORIZATION
117957118189
xAuth = db->xAuth;
@@ -117959,11 +118191,12 @@
117959118191
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117960118192
db->xAuth = xAuth;
117961118193
#else
117962118194
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117963118195
#endif
117964
- pParse->nTab = n;
118196
+ pParse->nTab = nTab;
118197
+ pParse->nSelect = nSelect;
117965118198
if( pSelTab==0 ){
117966118199
pTable->nCol = 0;
117967118200
nErr++;
117968118201
}else if( pTable->pCheck ){
117969118202
/* CREATE VIEW name(arglist) AS ...
@@ -118704,12 +118937,12 @@
118704118937
*/
118705118938
SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118706118939
if( pList ){
118707118940
int i;
118708118941
for(i=0; i<pList->nExpr; i++){
118709
- if( pList->a[i].bNulls ){
118710
- u8 sf = pList->a[i].sortFlags;
118942
+ if( pList->a[i].fg.bNulls ){
118943
+ u8 sf = pList->a[i].fg.sortFlags;
118711118944
sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118712118945
(sf==0 || sf==3) ? "FIRST" : "LAST"
118713118946
);
118714118947
return 1;
118715118948
}
@@ -119058,11 +119291,11 @@
119058119291
if( !zColl ) zColl = sqlite3StrBINARY;
119059119292
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119060119293
goto exit_create_index;
119061119294
}
119062119295
pIndex->azColl[i] = zColl;
119063
- requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119296
+ requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
119064119297
pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119065119298
}
119066119299
119067119300
/* Append the table key to the end of the index. For WITHOUT ROWID
119068119301
** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -130380,15 +130613,23 @@
130380130613
sqlite3_total_changes64,
130381130614
/* Version 3.37.0 and later */
130382130615
sqlite3_autovacuum_pages,
130383130616
/* Version 3.38.0 and later */
130384130617
sqlite3_error_offset,
130618
+#ifndef SQLITE_OMIT_VIRTUALTABLE
130385130619
sqlite3_vtab_rhs_value,
130386130620
sqlite3_vtab_distinct,
130387130621
sqlite3_vtab_in,
130388130622
sqlite3_vtab_in_first,
130389130623
sqlite3_vtab_in_next,
130624
+#else
130625
+ 0,
130626
+ 0,
130627
+ 0,
130628
+ 0,
130629
+ 0,
130630
+#endif
130390130631
/* Version 3.39.0 and later */
130391130632
#ifndef SQLITE_OMIT_DESERIALIZE
130392130633
sqlite3_deserialize,
130393130634
sqlite3_serialize
130394130635
#else
@@ -134828,10 +135069,18 @@
134828135069
db->pParse = pParse;
134829135070
pParse->db = db;
134830135071
if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
134831135072
}
134832135073
135074
+/*
135075
+** Maximum number of times that we will try again to prepare a statement
135076
+** that returns SQLITE_ERROR_RETRY.
135077
+*/
135078
+#ifndef SQLITE_MAX_PREPARE_RETRY
135079
+# define SQLITE_MAX_PREPARE_RETRY 25
135080
+#endif
135081
+
134833135082
/*
134834135083
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
134835135084
*/
134836135085
static int sqlite3Prepare(
134837135086
sqlite3 *db, /* Database handle. */
@@ -135002,11 +135251,11 @@
135002135251
** or encounters a permanent error. A schema problem after one schema
135003135252
** reset is considered a permanent error. */
135004135253
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135005135254
assert( rc==SQLITE_OK || *ppStmt==0 );
135006135255
if( rc==SQLITE_OK || db->mallocFailed ) break;
135007
- }while( rc==SQLITE_ERROR_RETRY
135256
+ }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
135008135257
|| (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135009135258
sqlite3BtreeLeaveAll(db);
135010135259
rc = sqlite3ApiExit(db, rc);
135011135260
assert( (rc&db->errMask)==rc );
135012135261
db->busyHandler.nBusy = 0;
@@ -135553,11 +135802,11 @@
135553135802
ExprList *pResults;
135554135803
assert( pItem->pSelect!=0 );
135555135804
pResults = pItem->pSelect->pEList;
135556135805
assert( pResults!=0 );
135557135806
assert( iCol>=0 && iCol<pResults->nExpr );
135558
- pResults->a[iCol].bUsed = 1;
135807
+ pResults->a[iCol].fg.bUsed = 1;
135559135808
}
135560135809
}
135561135810
135562135811
/*
135563135812
** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136221,11 +136470,11 @@
136221136470
** the row from table t1 is stored instead. Then, as records are extracted from
136222136471
** the sorter to return to the user, the required value of bigblob is
136223136472
** retrieved directly from table t1. If the values are very large, this
136224136473
** can be more efficient than storing them directly in the sorter records.
136225136474
**
136226
-** The ExprList_item.bSorterRef flag is set for each expression in pEList
136475
+** The ExprList_item.fg.bSorterRef flag is set for each expression in pEList
136227136476
** for which the sorter-reference optimization should be enabled.
136228136477
** Additionally, the pSort->aDefer[] array is populated with entries
136229136478
** for all cursors required to evaluate all selected expressions. Finally.
136230136479
** output variable (*ppExtra) is set to an expression list containing
136231136480
** expressions for all extra PK values that should be stored in the
@@ -136281,11 +136530,11 @@
136281136530
pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136282136531
pSort->aDefer[nDefer].nKey = nKey;
136283136532
nDefer++;
136284136533
}
136285136534
}
136286
- pItem->bSorterRef = 1;
136535
+ pItem->fg.bSorterRef = 1;
136287136536
}
136288136537
}
136289136538
}
136290136539
pSort->nDefer = (u8)nDefer;
136291136540
*ppExtra = pExtra;
@@ -136412,11 +136661,11 @@
136412136661
** from the sorter by the optimizations in this branch */
136413136662
pEList = p->pEList;
136414136663
for(i=0; i<pEList->nExpr; i++){
136415136664
if( pEList->a[i].u.x.iOrderByCol>0
136416136665
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136417
- || pEList->a[i].bSorterRef
136666
+ || pEList->a[i].fg.bSorterRef
136418136667
#endif
136419136668
){
136420136669
nResultCol--;
136421136670
regOrig = 0;
136422136671
}
@@ -136774,11 +137023,11 @@
136774137023
pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
136775137024
if( pInfo ){
136776137025
assert( sqlite3KeyInfoIsWriteable(pInfo) );
136777137026
for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
136778137027
pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
136779
- pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
137028
+ pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
136780137029
}
136781137030
}
136782137031
return pInfo;
136783137032
}
136784137033
@@ -136913,11 +137162,11 @@
136913137162
iSortTab = iTab;
136914137163
bSeq = 1;
136915137164
}
136916137165
for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
136917137166
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136918
- if( aOutEx[i].bSorterRef ) continue;
137167
+ if( aOutEx[i].fg.bSorterRef ) continue;
136919137168
#endif
136920137169
if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
136921137170
}
136922137171
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136923137172
if( pSort->nDefer ){
@@ -136950,11 +137199,11 @@
136950137199
sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
136951137200
}
136952137201
#endif
136953137202
for(i=nColumn-1; i>=0; i--){
136954137203
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136955
- if( aOutEx[i].bSorterRef ){
137204
+ if( aOutEx[i].fg.bSorterRef ){
136956137205
sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
136957137206
}else
136958137207
#endif
136959137208
{
136960137209
int iRead;
@@ -137316,11 +137565,11 @@
137316137565
137317137566
assert( p!=0 );
137318137567
assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137319137568
assert( p->op!=TK_COLUMN
137320137569
|| (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137321
- if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137570
+ if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
137322137571
/* An AS clause always takes first priority */
137323137572
char *zName = pEList->a[i].zEName;
137324137573
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137325137574
}else if( srcName && p->op==TK_COLUMN ){
137326137575
char *zCol;
@@ -137402,13 +137651,14 @@
137402137651
*pnCol = nCol;
137403137652
*paCol = aCol;
137404137653
137405137654
for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137406137655
struct ExprList_item *pX = &pEList->a[i];
137656
+ struct ExprList_item *pCollide;
137407137657
/* Get an appropriate name for the column
137408137658
*/
137409
- if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137659
+ if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
137410137660
/* If the column contains an "AS <name>" phrase, use <name> as the name */
137411137661
}else{
137412137662
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137413137663
while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137414137664
pColExpr = pColExpr->pRight;
@@ -137438,11 +137688,14 @@
137438137688
137439137689
/* Make sure the column name is unique. If the name is not unique,
137440137690
** append an integer to the name so that it becomes unique.
137441137691
*/
137442137692
cnt = 0;
137443
- while( zName && sqlite3HashFind(&ht, zName)!=0 ){
137693
+ while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
137694
+ if( pCollide->fg.bUsingTerm ){
137695
+ pCol->colFlags |= COLFLAG_NOEXPAND;
137696
+ }
137444137697
nName = sqlite3Strlen30(zName);
137445137698
if( nName>0 ){
137446137699
for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137447137700
if( zName[j]==':' ) nName = j;
137448137701
}
@@ -137449,12 +137702,15 @@
137449137702
zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137450137703
if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137451137704
}
137452137705
pCol->zCnName = zName;
137453137706
pCol->hName = sqlite3StrIHash(zName);
137707
+ if( pX->fg.bNoExpand ){
137708
+ pCol->colFlags |= COLFLAG_NOEXPAND;
137709
+ }
137454137710
sqlite3ColumnPropertiesFromName(0, pCol);
137455
- if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137711
+ if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
137456137712
sqlite3OomFault(db);
137457137713
}
137458137714
}
137459137715
sqlite3HashClear(&ht);
137460137716
if( db->mallocFailed ){
@@ -137707,11 +137963,11 @@
137707137963
pOrderBy->a[i].pExpr =
137708137964
sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137709137965
}
137710137966
assert( sqlite3KeyInfoIsWriteable(pRet) );
137711137967
pRet->aColl[i] = pColl;
137712
- pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137968
+ pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
137713137969
}
137714137970
}
137715137971
137716137972
return pRet;
137717137973
}
@@ -139375,10 +139631,12 @@
139375139631
** See also (3) for restrictions on LEFT JOIN.
139376139632
**
139377139633
** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139378139634
** is the first element of the parent query.
139379139635
**
139636
+** (28) The subquery is not a MATERIALIZED CTE.
139637
+**
139380139638
**
139381139639
** In this routine, the "p" parameter is a pointer to the outer query.
139382139640
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139383139641
** uses aggregates.
139384139642
**
@@ -139498,10 +139756,13 @@
139498139756
139499139757
assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139500139758
if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139501139759
return 0; /* Restriction (27) */
139502139760
}
139761
+ if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139762
+ return 0; /* (28) */
139763
+ }
139503139764
139504139765
/* Restriction (17): If the sub-query is a compound SELECT, then it must
139505139766
** use only the UNION ALL operator. And none of the simple select queries
139506139767
** that make up the compound SELECT are allowed to be aggregate or distinct
139507139768
** queries.
@@ -139542,10 +139803,11 @@
139542139803
/* Restriction (23) */
139543139804
if( (p->selFlags & SF_Recursive) ) return 0;
139544139805
139545139806
if( pSrc->nSrc>1 ){
139546139807
if( pParse->nSelect>500 ) return 0;
139808
+ if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
139547139809
aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
139548139810
if( aCsrMap ) aCsrMap[0] = pParse->nTab;
139549139811
}
139550139812
}
139551139813
@@ -140170,17 +140432,17 @@
140170140432
*/
140171140433
static int pushDownWhereTerms(
140172140434
Parse *pParse, /* Parse context (for malloc() and error reporting) */
140173140435
Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
140174140436
Expr *pWhere, /* The WHERE clause of the outer query */
140175
- int iCursor, /* Cursor number of the subquery */
140176
- int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
140437
+ SrcItem *pSrc /* The subquery term of the outer FROM clause */
140177140438
){
140178140439
Expr *pNew;
140179140440
int nChng = 0;
140180140441
if( pWhere==0 ) return 0;
140181140442
if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
140443
+ if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0;
140182140444
140183140445
#ifndef SQLITE_OMIT_WINDOWFUNC
140184140446
if( pSubq->pPrior ){
140185140447
Select *pSel;
140186140448
for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -140206,14 +140468,15 @@
140206140468
140207140469
if( pSubq->pLimit!=0 ){
140208140470
return 0; /* restriction (3) */
140209140471
}
140210140472
while( pWhere->op==TK_AND ){
140211
- nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
140212
- iCursor, isLeftJoin);
140473
+ nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
140213140474
pWhere = pWhere->pLeft;
140214140475
}
140476
+
140477
+#if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
140215140478
if( isLeftJoin
140216140479
&& (ExprHasProperty(pWhere,EP_FromJoin)==0
140217140480
|| pWhere->w.iJoin!=iCursor)
140218140481
){
140219140482
return 0; /* restriction (4) */
@@ -140221,20 +140484,22 @@
140221140484
if( ExprHasProperty(pWhere,EP_FromJoin)
140222140485
&& pWhere->w.iJoin!=iCursor
140223140486
){
140224140487
return 0; /* restriction (5) */
140225140488
}
140226
- if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
140489
+#endif
140490
+
140491
+ if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
140227140492
nChng++;
140228140493
pSubq->selFlags |= SF_PushDown;
140229140494
while( pSubq ){
140230140495
SubstContext x;
140231140496
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140232140497
unsetJoinExpr(pNew, -1);
140233140498
x.pParse = pParse;
140234
- x.iTable = iCursor;
140235
- x.iNewTable = iCursor;
140499
+ x.iTable = pSrc->iCursor;
140500
+ x.iNewTable = pSrc->iCursor;
140236140501
x.isOuterJoin = 0;
140237140502
x.pEList = pSubq->pEList;
140238140503
pNew = substExpr(&x, pNew);
140239140504
#ifndef SQLITE_OMIT_WINDOWFUNC
140240140505
if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -140304,11 +140569,11 @@
140304140569
}else{
140305140570
return eRet;
140306140571
}
140307140572
*ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140308140573
assert( pOrderBy!=0 || db->mallocFailed );
140309
- if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140574
+ if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
140310140575
return eRet;
140311140576
}
140312140577
140313140578
/*
140314140579
** The select statement passed as the first argument is an aggregate query.
@@ -140773,11 +141038,11 @@
140773141038
if( pTab==0 ) return SQLITE_NOMEM;
140774141039
pTab->nTabRef = 1;
140775141040
if( pFrom->zAlias ){
140776141041
pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
140777141042
}else{
140778
- pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId);
141043
+ pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
140779141044
}
140780141045
while( pSel->pPrior ){ pSel = pSel->pPrior; }
140781141046
sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
140782141047
pTab->iPKey = -1;
140783141048
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -141011,11 +141276,11 @@
141011141276
/* This particular expression does not need to be expanded.
141012141277
*/
141013141278
pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141014141279
if( pNew ){
141015141280
pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141016
- pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141281
+ pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
141017141282
a[k].zEName = 0;
141018141283
}
141019141284
a[k].pExpr = 0;
141020141285
}else{
141021141286
/* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141026,39 +141291,64 @@
141026141291
assert( pE->pLeft!=0 );
141027141292
assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
141028141293
zTName = pE->pLeft->u.zToken;
141029141294
}
141030141295
for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
141031
- Table *pTab = pFrom->pTab;
141032
- Select *pSub;
141033
- char *zTabName = pFrom->zAlias;
141034
- const char *zSchemaName = 0;
141035
- int iDb;
141036
- if( zTabName==0 ){
141296
+ Table *pTab = pFrom->pTab; /* Table for this data source */
141297
+ ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141298
+ char *zTabName; /* AS name for this data source */
141299
+ const char *zSchemaName = 0; /* Schema name for this data source */
141300
+ int iDb; /* Schema index for this data src */
141301
+ IdList *pUsing; /* USING clause for pFrom[1] */
141302
+
141303
+ if( (zTabName = pFrom->zAlias)==0 ){
141037141304
zTabName = pTab->zName;
141038141305
}
141039141306
if( db->mallocFailed ) break;
141040141307
assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141041141308
if( pFrom->fg.isNestedFrom ){
141042
- pSub = pFrom->pSelect;
141043
- assert( pSub->pEList!=0 );
141044
- assert( pSub->pEList->nExpr==pTab->nCol );
141309
+ assert( pFrom->pSelect!=0 );
141310
+ pNestedFrom = pFrom->pSelect->pEList;
141311
+ assert( pNestedFrom!=0 );
141312
+ assert( pNestedFrom->nExpr==pTab->nCol );
141045141313
}else{
141046
- pSub = 0;
141047141314
if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
141048141315
continue;
141049141316
}
141317
+ pNestedFrom = 0;
141050141318
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141051141319
zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
141320
+ }
141321
+ if( i+1<pTabList->nSrc
141322
+ && pFrom[1].fg.isUsing
141323
+ && (selFlags & SF_NestedFrom)!=0
141324
+ ){
141325
+ int ii;
141326
+ pUsing = pFrom[1].u3.pUsing;
141327
+ for(ii=0; ii<pUsing->nId; ii++){
141328
+ const char *zUName = pUsing->a[ii].zName;
141329
+ pRight = sqlite3Expr(db, TK_ID, zUName);
141330
+ pNew = sqlite3ExprListAppend(pParse, pNew, pRight);
141331
+ if( pNew ){
141332
+ struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
141333
+ assert( pX->zEName==0 );
141334
+ pX->zEName = sqlite3MPrintf(db,"..%s", zUName);
141335
+ pX->fg.eEName = ENAME_TAB;
141336
+ pX->fg.bUsingTerm = 1;
141337
+ }
141338
+ }
141339
+ }else{
141340
+ pUsing = 0;
141052141341
}
141053141342
for(j=0; j<pTab->nCol; j++){
141054141343
char *zName = pTab->aCol[j].zCnName;
141055141344
struct ExprList_item *pX; /* Newly added ExprList term */
141056141345
141057141346
assert( zName );
141058
- if( zTName && pSub
141059
- && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
141347
+ if( zTName
141348
+ && pNestedFrom
141349
+ && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0)==0
141060141350
){
141061141351
continue;
141062141352
}
141063141353
141064141354
/* If a column is marked as 'hidden', omit it from the expanded
@@ -141067,14 +141357,20 @@
141067141357
*/
141068141358
if( (p->selFlags & SF_IncludeHidden)==0
141069141359
&& IsHiddenColumn(&pTab->aCol[j])
141070141360
){
141071141361
continue;
141362
+ }
141363
+ if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141364
+ && zTName==0
141365
+ && (selFlags & (SF_NestedFrom))==0
141366
+ ){
141367
+ continue;
141072141368
}
141073141369
tableSeen = 1;
141074141370
141075
- if( i>0 && zTName==0 ){
141371
+ if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
141076141372
if( pFrom->fg.isUsing
141077141373
&& sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141078141374
){
141079141375
/* In a join with a USING clause, omit columns in the
141080141376
** using clause from the table on the right. */
@@ -141082,10 +141378,11 @@
141082141378
}
141083141379
}
141084141380
pRight = sqlite3Expr(db, TK_ID, zName);
141085141381
if( (pTabList->nSrc>1
141086141382
&& ( (pFrom->fg.jointype & JT_LTORJ)==0
141383
+ || (selFlags & SF_NestedFrom)!=0
141087141384
|| !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141088141385
)
141089141386
)
141090141387
|| IN_RENAME_OBJECT
141091141388
){
@@ -141107,25 +141404,32 @@
141107141404
break; /* OOM */
141108141405
}
141109141406
pX = &pNew->a[pNew->nExpr-1];
141110141407
assert( pX->zEName==0 );
141111141408
if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
141112
- if( pSub ){
141113
- pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName);
141409
+ if( pNestedFrom ){
141410
+ pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
141114141411
testcase( pX->zEName==0 );
141115141412
}else{
141116141413
pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141117141414
zSchemaName, zTabName, zName);
141118141415
testcase( pX->zEName==0 );
141119141416
}
141120
- pX->eEName = ENAME_TAB;
141417
+ pX->fg.eEName = ENAME_TAB;
141418
+ if( (pFrom->fg.isUsing
141419
+ && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
141420
+ || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
141421
+ || (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141422
+ ){
141423
+ pX->fg.bNoExpand = 1;
141424
+ }
141121141425
}else if( longNames ){
141122141426
pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141123
- pX->eEName = ENAME_NAME;
141427
+ pX->fg.eEName = ENAME_NAME;
141124141428
}else{
141125141429
pX->zEName = sqlite3DbStrDup(db, zName);
141126
- pX->eEName = ENAME_NAME;
141430
+ pX->fg.eEName = ENAME_NAME;
141127141431
}
141128141432
}
141129141433
}
141130141434
if( !tableSeen ){
141131141435
if( zTName ){
@@ -142053,13 +142357,11 @@
142053142357
** inside the subquery. This can help the subquery to run more efficiently.
142054142358
*/
142055142359
if( OptimizationEnabled(db, SQLITE_PushDown)
142056142360
&& (pItem->fg.isCte==0
142057142361
|| (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
142058
- && (pItem->fg.jointype & JT_RIGHT)==0
142059
- && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
142060
- (pItem->fg.jointype & JT_OUTER)!=0)
142362
+ && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
142061142363
){
142062142364
#if TREETRACE_ENABLED
142063142365
if( sqlite3TreeTrace & 0x100 ){
142064142366
SELECTTRACE(0x100,pParse,p,
142065142367
("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -142251,17 +142553,17 @@
142251142553
if( pDest->eDest==SRT_EphemTab ){
142252142554
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142253142555
if( p->selFlags & SF_NestedFrom ){
142254142556
/* Delete or NULL-out result columns that will never be used */
142255142557
int ii;
142256
- for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].bUsed==0; ii--){
142558
+ for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
142257142559
sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142258142560
sqlite3DbFree(db, pEList->a[ii].zEName);
142259142561
pEList->nExpr--;
142260142562
}
142261142563
for(ii=0; ii<pEList->nExpr; ii++){
142262
- if( pEList->a[ii].bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142564
+ if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142263142565
}
142264142566
}
142265142567
}
142266142568
142267142569
/* Set the limiter.
@@ -142409,12 +142711,13 @@
142409142711
** ASC or DESC order - only that each group is returned contiguously.
142410142712
** So set the ASC/DESC flags in the GROUP BY to match those in the
142411142713
** ORDER BY to maximize the chances of rows being delivered in an
142412142714
** order that makes the ORDER BY redundant. */
142413142715
for(ii=0; ii<pGroupBy->nExpr; ii++){
142414
- u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142415
- pGroupBy->a[ii].sortFlags = sortFlags;
142716
+ u8 sortFlags;
142717
+ sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
142718
+ pGroupBy->a[ii].fg.sortFlags = sortFlags;
142416142719
}
142417142720
if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142418142721
orderByGrp = 1;
142419142722
}
142420142723
}
@@ -144065,20 +144368,20 @@
144065144368
pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144066144369
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144067144370
if( !db->mallocFailed ){
144068144371
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144069144372
pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144070
- pItem->eEName = ENAME_NAME;
144373
+ pItem->fg.eEName = ENAME_NAME;
144071144374
}
144072144375
}
144073144376
}else{
144074144377
Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144075144378
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144076144379
if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144077144380
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144078144381
pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144079
- pItem->eEName = pList->a[i].eEName;
144382
+ pItem->fg.eEName = pList->a[i].fg.eEName;
144080144383
}
144081144384
}
144082144385
}
144083144386
return pNew;
144084144387
}
@@ -146647,10 +146950,11 @@
146647146950
#endif
146648146951
}
146649146952
146650146953
assert( rc==SQLITE_OK );
146651146954
if( pOut==0 ){
146955
+ nRes = sqlite3BtreeGetRequestedReserve(pTemp);
146652146956
rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146653146957
}
146654146958
146655146959
end_of_vacuum:
146656146960
/* Restore the original value of db->flags */
@@ -148109,10 +148413,11 @@
148109148413
struct WhereRightJoin {
148110148414
int iMatch; /* Cursor used to determine prior matched rows */
148111148415
int regBloom; /* Bloom filter for iRJMatch */
148112148416
int regReturn; /* Return register for the interior subroutine */
148113148417
int addrSubrtn; /* Starting address for the interior subroutine */
148418
+ int endSubrtn; /* The last opcode in the interior subroutine */
148114148419
};
148115148420
148116148421
/*
148117148422
** This object contains information needed to implement a single nested
148118148423
** loop in WHERE clause.
@@ -149300,20 +149605,26 @@
149300149605
149301149606
iTab = 0;
149302149607
if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149303149608
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149304149609
}else{
149305
- sqlite3 *db = pParse->db;
149306
- pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149307
-
149308
- if( !db->mallocFailed ){
149610
+ Expr *pExpr = pTerm->pExpr;
149611
+ if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
149612
+ sqlite3 *db = pParse->db;
149613
+ pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149614
+ if( !db->mallocFailed ){
149615
+ aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149616
+ eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
149617
+ pExpr->iTable = iTab;
149618
+ }
149619
+ sqlite3ExprDelete(db, pX);
149620
+ }else{
149309149621
aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149310
- eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149311
- pTerm->pExpr->iTable = iTab;
149622
+ eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP|IN_INDEX_REUSE_CUR, 0, aiMap,&iTab);
149623
+ iTab = pExpr->iTable;
149312149624
}
149313
- sqlite3ExprDelete(db, pX);
149314
- pX = pTerm->pExpr;
149625
+ pX = pExpr;
149315149626
}
149316149627
149317149628
if( eType==IN_INDEX_INDEX_DESC ){
149318149629
testcase( bRev );
149319149630
bRev = !bRev;
@@ -149936,16 +150247,16 @@
149936150247
** that contains the value of pExpr.
149937150248
*/
149938150249
static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
149939150250
IdxExprTrans *pX = p->u.pIdxTrans;
149940150251
if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
150252
+ pExpr = sqlite3ExprSkipCollate(pExpr);
149941150253
preserveExpr(pX, pExpr);
149942150254
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
149943150255
pExpr->op = TK_COLUMN;
149944150256
pExpr->iTable = pX->iIdxCur;
149945150257
pExpr->iColumn = pX->iIdxCol;
149946
- testcase( ExprHasProperty(pExpr, EP_Skip) );
149947150258
testcase( ExprHasProperty(pExpr, EP_Unlikely) );
149948150259
ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
149949150260
pExpr->y.pTab = 0;
149950150261
return WRC_Prune;
149951150262
}else{
@@ -150095,10 +150406,12 @@
150095150406
if( pLevel->regFilter==0 ) continue;
150096150407
if( pLevel->pWLoop->nSkip ) continue;
150097150408
/* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150098150409
** vvvvv--' pLevel->regFilter if this were true. */
150099150410
if( NEVER(pLoop->prereq & notReady) ) continue;
150411
+ assert( pLevel->addrBrk==0 );
150412
+ pLevel->addrBrk = addrNxt;
150100150413
if( pLoop->wsFlags & WHERE_IPK ){
150101150414
WhereTerm *pTerm = pLoop->aLTerm[0];
150102150415
int regRowid;
150103150416
assert( pTerm!=0 );
150104150417
assert( pTerm->pExpr!=0 );
@@ -150121,10 +150434,11 @@
150121150434
sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150122150435
addrNxt, r1, nEq);
150123150436
VdbeCoverage(pParse->pVdbe);
150124150437
}
150125150438
pLevel->regFilter = 0;
150439
+ pLevel->addrBrk = 0;
150126150440
}
150127150441
}
150128150442
150129150443
/*
150130150444
** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151301,11 +151615,11 @@
151301151615
continue;
151302151616
}
151303151617
pE = pTerm->pExpr;
151304151618
assert( pE!=0 );
151305151619
if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151306
- && !ExprHasProperty(pE,EP_FromJoin)
151620
+ && !ExprHasProperty(pE,EP_FromJoin|EP_InnerJoin)
151307151621
){
151308151622
continue;
151309151623
}
151310151624
151311151625
if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -151508,10 +151822,12 @@
151508151822
SrcList sFrom;
151509151823
Bitmask mAll = 0;
151510151824
int k;
151511151825
151512151826
ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName));
151827
+ sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
151828
+ pRJ->regReturn);
151513151829
for(k=0; k<iLevel; k++){
151514151830
int iIdxCur;
151515151831
mAll |= pWInfo->a[k].pWLoop->maskSelf;
151516151832
sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur);
151517151833
iIdxCur = pWInfo->a[k].iIdxCur;
@@ -153190,11 +153506,11 @@
153190153506
if( pOrderBy ){
153191153507
for(ii=0; ii<pOrderBy->nExpr; ii++){
153192153508
Expr *pExpr = pOrderBy->a[ii].pExpr;
153193153509
if( pExpr->op!=TK_COLUMN ) return;
153194153510
if( pExpr->iTable!=iCsr ) return;
153195
- if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153511
+ if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153196153512
}
153197153513
}
153198153514
153199153515
/* All conditions are met. Add the terms to the where-clause object. */
153200153516
assert( p->pLimit->op==TK_LIMIT );
@@ -153516,11 +153832,11 @@
153516153832
** continuation of the inner-most loop. */
153517153833
return pWInfo->iContinue;
153518153834
}
153519153835
pInner = &pWInfo->a[pWInfo->nLevel-1];
153520153836
assert( pInner->addrNxt!=0 );
153521
- return pInner->addrNxt;
153837
+ return pInner->pRJ ? pWInfo->iContinue : pInner->addrNxt;
153522153838
}
153523153839
153524153840
/*
153525153841
** While generating code for the min/max optimization, after handling
153526153842
** the aggregate-step call to min() or max(), check to see if any
@@ -154246,13 +154562,11 @@
154246154562
Expr *pExpr = pTerm->pExpr;
154247154563
/* Make the automatic index a partial index if there are terms in the
154248154564
** WHERE clause (or the ON clause of a LEFT join) that constrain which
154249154565
** rows of the target table (pSrc) that can be used. */
154250154566
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154251
- && ((pSrc->fg.jointype&(JT_LEFT|JT_LTORJ))==0
154252
- || ExprHasProperty(pExpr,EP_FromJoin))
154253
- && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
154567
+ && sqlite3ExprIsTableConstraint(pExpr, pSrc)
154254154568
){
154255154569
pPartial = sqlite3ExprAnd(pParse, pPartial,
154256154570
sqlite3ExprDup(pParse->db, pExpr, 0));
154257154571
}
154258154572
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -154487,11 +154801,11 @@
154487154801
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
154488154802
pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
154489154803
for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
154490154804
Expr *pExpr = pTerm->pExpr;
154491154805
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154492
- && sqlite3ExprIsTableConstant(pExpr, iCur)
154806
+ && sqlite3ExprIsTableConstraint(pExpr, pItem)
154493154807
){
154494154808
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
154495154809
}
154496154810
}
154497154811
if( pLoop->wsFlags & WHERE_IPK ){
@@ -154622,11 +154936,11 @@
154622154936
if( sqlite3ExprIsConstant(pExpr) ){
154623154937
continue;
154624154938
}
154625154939
154626154940
/* Virtual tables are unable to deal with NULLS FIRST */
154627
- if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154941
+ if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154628154942
154629154943
/* First case - a direct column references without a COLLATE operator */
154630154944
if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154631154945
assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154632154946
continue;
@@ -154734,11 +155048,11 @@
154734155048
if( sqlite3ExprIsConstant(pExpr) ) continue;
154735155049
assert( pExpr->op==TK_COLUMN
154736155050
|| (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154737155051
&& pExpr->iColumn==pExpr->pLeft->iColumn) );
154738155052
pIdxOrderBy[j].iColumn = pExpr->iColumn;
154739
- pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
155053
+ pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
154740155054
j++;
154741155055
}
154742155056
pIdxInfo->nOrderBy = j;
154743155057
154744155058
*pmNoOmit = mNoOmit;
@@ -156252,11 +156566,11 @@
156252156566
/* tag-20191211-001: Do not allow constraints from the WHERE clause to
156253156567
** be used by the right table of a LEFT JOIN nor by the left table of a
156254156568
** RIGHT JOIN. Only constraints in the
156255156569
** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156256156570
if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156257
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156571
+ && !ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin)
156258156572
){
156259156573
continue;
156260156574
}
156261156575
156262156576
if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157560,13 +157874,11 @@
157560157874
pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157561157875
pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157562157876
if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157563157877
/* This condition is true when pItem is the FROM clause term on the
157564157878
** right-hand-side of a OUTER or CROSS JOIN. */
157565
- mPrereq = mPrior;
157566
- }else{
157567
- mPrereq = 0;
157879
+ mPrereq |= mPrior;
157568157880
}
157569157881
#ifndef SQLITE_OMIT_VIRTUALTABLE
157570157882
if( IsVirtual(pItem->pTab) ){
157571157883
SrcItem *p;
157572157884
for(p=&pItem[1]; p<pEnd; p++){
@@ -157873,20 +158185,22 @@
157873158185
}
157874158186
if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
157875158187
/* Make sure the sort order is compatible in an ORDER BY clause.
157876158188
** Sort order is irrelevant for a GROUP BY clause. */
157877158189
if( revSet ){
157878
- if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
158190
+ if( (rev ^ revIdx)
158191
+ != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158192
+ ){
157879158193
isMatch = 0;
157880158194
}
157881158195
}else{
157882
- rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
158196
+ rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
157883158197
if( rev ) *pRevMask |= MASKBIT(iLoop);
157884158198
revSet = 1;
157885158199
}
157886158200
}
157887
- if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
158201
+ if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
157888158202
if( j==pLoop->u.btree.nEq ){
157889158203
pLoop->wsFlags |= WHERE_BIGNULL_SORT;
157890158204
}else{
157891158205
isMatch = 0;
157892158206
}
@@ -159438,10 +159752,11 @@
159438159752
/* Terminate the subroutine that forms the interior of the loop of
159439159753
** the RIGHT JOIN table */
159440159754
WhereRightJoin *pRJ = pLevel->pRJ;
159441159755
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
159442159756
pLevel->addrCont = 0;
159757
+ pRJ->endSubrtn = sqlite3VdbeCurrentAddr(v);
159443159758
sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1);
159444159759
VdbeCoverage(v);
159445159760
assert( pParse->withinRJSubrtn>0 );
159446159761
pParse->withinRJSubrtn--;
159447159762
}
@@ -160645,11 +160960,11 @@
160645160960
pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160646160961
pSub->u.zToken = 0;
160647160962
}
160648160963
}
160649160964
pList = sqlite3ExprListAppend(pParse, pList, pDup);
160650
- if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
160965
+ if( pList ) pList->a[nInit+i].fg.sortFlags = pAppend->a[i].fg.sortFlags;
160651160966
}
160652160967
}
160653160968
return pList;
160654160969
}
160655160970
@@ -161846,11 +162161,11 @@
161846162161
windowReadPeerValues(p, csr1, reg1);
161847162162
windowReadPeerValues(p, csr2, reg2);
161848162163
161849162164
assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
161850162165
assert( pOrderBy && pOrderBy->nExpr==1 );
161851
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
162166
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
161852162167
switch( op ){
161853162168
case OP_Ge: op = OP_Le; break;
161854162169
case OP_Gt: op = OP_Lt; break;
161855162170
default: assert( op==OP_Le ); op = OP_Ge; break;
161856162171
}
@@ -161879,11 +162194,11 @@
161879162194
** }
161880162195
**
161881162196
** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
161882162197
** not taken, control jumps over the comparison operator coded below this
161883162198
** block. */
161884
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
162199
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
161885162200
/* This block runs if reg1 contains a NULL. */
161886162201
int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
161887162202
switch( op ){
161888162203
case OP_Ge:
161889162204
sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -226663,11 +226978,11 @@
226663226978
/* State used by the fts5DataXXX() functions. */
226664226979
sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226665226980
sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226666226981
sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226667226982
sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226668
- sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */
226983
+ sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
226669226984
sqlite3_stmt *pIdxSelect;
226670226985
int nRead; /* Total number of blocks read */
226671226986
226672226987
sqlite3_stmt *pDataVersion;
226673226988
i64 iStructVersion; /* data_version when pStruct read */
@@ -235980,11 +236295,11 @@
235980236295
int nArg, /* Number of args */
235981236296
sqlite3_value **apUnused /* Function arguments */
235982236297
){
235983236298
assert( nArg==0 );
235984236299
UNUSED_PARAM2(nArg, apUnused);
235985
- sqlite3_result_text(pCtx, "fts5: 2022-04-19 15:56:03 b966d52437f08a6759a83a45cafb0d706a8933a8e55dee38ae78166d1a5b3ba4", -1, SQLITE_TRANSIENT);
236300
+ sqlite3_result_text(pCtx, "fts5: 2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527", -1, SQLITE_TRANSIENT);
235986236301
}
235987236302
235988236303
/*
235989236304
** Return true if zName is the extension on one of the shadow tables used
235990236305
** by this module.
235991236306
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -15790,12 +15790,14 @@
15790 # define sqlite3VdbeVerifyNoMallocRequired(A,B)
15791 # define sqlite3VdbeVerifyNoResultRow(A)
15792 #endif
15793 #if defined(SQLITE_DEBUG)
15794 SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
 
15795 #else
15796 # define sqlite3VdbeVerifyAbortable(A,B)
 
15797 #endif
15798 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
15799 #ifndef SQLITE_OMIT_EXPLAIN
15800 SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
15801 SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
@@ -17051,10 +17053,12 @@
17051 /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
17052 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17053 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17054 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17055 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
 
 
17056 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17057
17058 /*
17059 ** Macros for testing whether or not optimizations are enabled or disabled.
17060 */
@@ -17396,10 +17400,11 @@
17396 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
17397 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
17398 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17399 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17400 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
 
17401 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17402 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17403
17404 /*
17405 ** A "Collating Sequence" is defined by an instance of the following
@@ -18269,17 +18274,22 @@
18269 int nExpr; /* Number of expressions on the list */
18270 int nAlloc; /* Number of a[] slots allocated */
18271 struct ExprList_item { /* For each expression in the list */
18272 Expr *pExpr; /* The parse tree for this expression */
18273 char *zEName; /* Token associated with this expression */
18274 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18275 unsigned eEName :2; /* Meaning of zEName */
18276 unsigned done :1; /* A flag to indicate when processing is finished */
18277 unsigned reusable :1; /* Constant expression is reusable */
18278 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18279 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18280 unsigned bUsed: 1; /* This column used in a SF_NestedFrom subquery */
 
 
 
 
 
18281 union {
18282 struct { /* Used by any ExprList other than Parse.pConsExpr */
18283 u16 iOrderByCol; /* For ORDER BY, column number in result set */
18284 u16 iAlias; /* Index into Parse.aAlias[] for zName */
18285 } x;
@@ -19729,10 +19739,11 @@
19729 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19730 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19731 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19732 SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19733 SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
 
19734 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19735 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19736 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19737 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19738 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20022,10 +20033,11 @@
20022 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
20023 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
20024 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
20025 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
20026 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
 
20027 #ifdef SQLITE_ENABLE_CURSOR_HINTS
20028 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
20029 #endif
20030 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
20031 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -20583,10 +20595,11 @@
20583 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
20584 */
20585 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
20586 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
20587 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
 
20588 SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
20589
20590 SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
20591 SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
20592 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
@@ -30462,12 +30475,18 @@
30462 sqlite3_str_append(pAccum, ".", 1);
30463 }
30464 sqlite3_str_appendall(pAccum, pItem->zName);
30465 }else if( pItem->zAlias ){
30466 sqlite3_str_appendall(pAccum, pItem->zAlias);
30467 }else if( ALWAYS(pItem->pSelect) ){
30468 sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
 
 
 
 
 
 
30469 }
30470 length = width = 0;
30471 break;
30472 }
30473 default: {
@@ -31047,10 +31066,57 @@
31047 */
31048 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
31049 sqlite3TreeViewPush(&p, moreFollows);
31050 sqlite3TreeViewLine(p, "%s", zLabel);
31051 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31052
31053 /*
31054 ** Generate a human-readable description of a WITH clause.
31055 */
31056 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31077,10 +31143,14 @@
31077 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
31078 cSep = ',';
31079 }
31080 sqlite3_str_appendf(&x, ")");
31081 }
 
 
 
 
31082 if( pCte->pUse ){
31083 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
31084 pCte->pUse->nUse);
31085 }
31086 sqlite3StrAccumFinish(&x);
@@ -31099,10 +31169,11 @@
31099 int i;
31100 if( pSrc==0 ) return;
31101 for(i=0; i<pSrc->nSrc; i++){
31102 const SrcItem *pItem = &pSrc->a[i];
31103 StrAccum x;
 
31104 char zLine[100];
31105 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
31106 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
31107 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
31108 if( pItem->pTab ){
@@ -31127,13 +31198,24 @@
31127 if( pItem->fg.isCte ){
31128 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31129 }
31130 sqlite3StrAccumFinish(&x);
31131 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
 
 
 
 
 
 
 
31132 if( pItem->pSelect ){
 
 
 
 
31133 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31134 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
31135 }
31136 if( pItem->fg.isTabFunc ){
31137 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31138 }
31139 sqlite3TreeViewPop(&pView);
@@ -31296,10 +31378,11 @@
31296 /*
31297 ** Generate a human-readable explanation for a Window object
31298 */
31299 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31300 int nElement = 0;
 
31301 if( pWin->pFilter ){
31302 sqlite3TreeViewItem(pView, "FILTER", 1);
31303 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31304 sqlite3TreeViewPop(&pView);
31305 }
@@ -31360,10 +31443,11 @@
31360 #ifndef SQLITE_OMIT_WINDOWFUNC
31361 /*
31362 ** Generate a human-readable explanation for a Window Function object
31363 */
31364 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
 
31365 sqlite3TreeViewPush(&pView, more);
31366 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31367 pWin->pWFunc->zName, pWin->pWFunc->nArg);
31368 sqlite3TreeViewWindow(pView, pWin, 0);
31369 sqlite3TreeViewPop(&pView);
@@ -31611,11 +31695,21 @@
31611 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
31612 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31613 break;
31614 }
31615 case TK_IN: {
31616 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
 
 
 
 
 
 
 
 
 
 
31617 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31618 if( ExprUseXSelect(pExpr) ){
31619 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31620 }else{
31621 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31762,17 +31856,19 @@
31762 if( j || zName ){
31763 sqlite3TreeViewPush(&pView, moreToFollow);
31764 moreToFollow = 0;
31765 sqlite3TreeViewLine(pView, 0);
31766 if( zName ){
31767 switch( pList->a[i].eEName ){
31768 default:
31769 fprintf(stdout, "AS %s ", zName);
31770 break;
31771 case ENAME_TAB:
31772 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31773 if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) ");
 
 
31774 break;
31775 case ENAME_SPAN:
31776 fprintf(stdout, "SPAN(\"%s\") ", zName);
31777 break;
31778 }
@@ -81423,10 +81519,94 @@
81423 pParse->nLabel = 0;
81424 *pMaxFuncArgs = nMaxArgs;
81425 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
81426 }
81427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81428 /*
81429 ** Return the address of the next instruction to be inserted.
81430 */
81431 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
81432 assert( p->eVdbeState==VDBE_INIT_STATE );
@@ -89154,10 +89334,12 @@
89154 if( pOp->p2==0 ) break;
89155
89156 /* Most jump operations do a goto to this spot in order to update
89157 ** the pOp pointer. */
89158 jump_to_p2:
 
 
89159 pOp = &aOp[pOp->p2 - 1];
89160 break;
89161 }
89162
89163 /* Opcode: EndCoroutine P1 * * * *
@@ -101365,11 +101547,11 @@
101365 const char *zTab,
101366 const char *zDb
101367 ){
101368 int n;
101369 const char *zSpan;
101370 if( pItem->eEName!=ENAME_TAB ) return 0;
101371 zSpan = pItem->zEName;
101372 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101373 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101374 return 0;
101375 }
@@ -101594,12 +101776,13 @@
101594 }
101595 cnt++;
101596 cntTab = 2;
101597 pMatch = pItem;
101598 pExpr->iColumn = j;
101599 pEList->a[j].bUsed = 1;
101600 hit = 1;
 
101601 }
101602 if( hit || zTab==0 ) continue;
101603 }
101604 assert( zDb==0 || zTab!=0 );
101605 if( zTab ){
@@ -101818,11 +102001,11 @@
101818 ){
101819 pEList = pNC->uNC.pEList;
101820 assert( pEList!=0 );
101821 for(j=0; j<pEList->nExpr; j++){
101822 char *zAs = pEList->a[j].zEName;
101823 if( pEList->a[j].eEName==ENAME_NAME
101824 && sqlite3_stricmp(zAs, zCol)==0
101825 ){
101826 Expr *pOrig;
101827 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
101828 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102571,11 +102754,11 @@
102571 if( pE->op==TK_ID ){
102572 const char *zCol;
102573 assert( !ExprHasProperty(pE, EP_IntValue) );
102574 zCol = pE->u.zToken;
102575 for(i=0; i<pEList->nExpr; i++){
102576 if( pEList->a[i].eEName==ENAME_NAME
102577 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102578 ){
102579 return i+1;
102580 }
102581 }
@@ -102692,11 +102875,11 @@
102692 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102693 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102694 return 1;
102695 }
102696 for(i=0; i<pOrderBy->nExpr; i++){
102697 pOrderBy->a[i].done = 0;
102698 }
102699 pSelect->pNext = 0;
102700 while( pSelect->pPrior ){
102701 pSelect->pPrior->pNext = pSelect;
102702 pSelect = pSelect->pPrior;
@@ -102707,11 +102890,11 @@
102707 pEList = pSelect->pEList;
102708 assert( pEList!=0 );
102709 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102710 int iCol = -1;
102711 Expr *pE, *pDup;
102712 if( pItem->done ) continue;
102713 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102714 if( NEVER(pE==0) ) continue;
102715 if( sqlite3ExprIsInteger(pE, &iCol) ){
102716 if( iCol<=0 || iCol>pEList->nExpr ){
102717 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102760,19 +102943,19 @@
102760 pParent->pLeft = pNew;
102761 }
102762 sqlite3ExprDelete(db, pE);
102763 pItem->u.x.iOrderByCol = (u16)iCol;
102764 }
102765 pItem->done = 1;
102766 }else{
102767 moreToDo = 1;
102768 }
102769 }
102770 pSelect = pSelect->pNext;
102771 }
102772 for(i=0; i<pOrderBy->nExpr; i++){
102773 if( pOrderBy->a[i].done==0 ){
102774 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102775 "column in the result set", i+1);
102776 return 1;
102777 }
102778 }
@@ -104911,10 +105094,11 @@
104911 pRet->nCte = p->nCte;
104912 for(i=0; i<p->nCte; i++){
104913 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
104914 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
104915 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
 
104916 }
104917 }
104918 }
104919 return pRet;
104920 }
@@ -105011,16 +105195,12 @@
105011 }
105012 pNewExpr->pLeft = pPriorSelectColNew;
105013 }
105014 }
105015 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105016 pItem->sortFlags = pOldItem->sortFlags;
105017 pItem->eEName = pOldItem->eEName;
105018 pItem->done = 0;
105019 pItem->bNulls = pOldItem->bNulls;
105020 pItem->bUsed = pOldItem->bUsed;
105021 pItem->bSorterRef = pOldItem->bSorterRef;
105022 pItem->u = pOldItem->u;
105023 }
105024 return pNew;
105025 }
105026
@@ -105316,20 +105496,20 @@
105316 || eNulls==SQLITE_SO_ASC
105317 || eNulls==SQLITE_SO_DESC
105318 );
105319
105320 pItem = &p->a[p->nExpr-1];
105321 assert( pItem->bNulls==0 );
105322 if( iSortOrder==SQLITE_SO_UNDEFINED ){
105323 iSortOrder = SQLITE_SO_ASC;
105324 }
105325 pItem->sortFlags = (u8)iSortOrder;
105326
105327 if( eNulls!=SQLITE_SO_UNDEFINED ){
105328 pItem->bNulls = 1;
105329 if( iSortOrder!=eNulls ){
105330 pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105331 }
105332 }
105333 }
105334
105335 /*
@@ -105351,11 +105531,11 @@
105351 if( pList ){
105352 struct ExprList_item *pItem;
105353 assert( pList->nExpr>0 );
105354 pItem = &pList->a[pList->nExpr-1];
105355 assert( pItem->zEName==0 );
105356 assert( pItem->eEName==ENAME_NAME );
105357 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105358 if( dequote ){
105359 /* If dequote==0, then pName->z does not point to part of a DDL
105360 ** statement handled by the parser. And so no token need be added
105361 ** to the token-map. */
@@ -105386,11 +105566,11 @@
105386 if( pList ){
105387 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105388 assert( pList->nExpr>0 );
105389 if( pItem->zEName==0 ){
105390 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105391 pItem->eEName = ENAME_SPAN;
105392 }
105393 }
105394 }
105395
105396 /*
@@ -105678,10 +105858,46 @@
105678 ** table other than iCur.
105679 */
105680 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
105681 return exprIsConst(p, 3, iCur);
105682 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105683
105684
105685 /*
105686 ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
105687 */
@@ -106006,11 +106222,11 @@
106006 ** The job of this routine is to find or create a b-tree object that can
106007 ** be used either to test for membership in the RHS set or to iterate through
106008 ** all members of the RHS set, skipping duplicates.
106009 **
106010 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
106011 ** and pX->iTable is set to the index of that cursor.
106012 **
106013 ** The returned value of this function indicates the b-tree type, as follows:
106014 **
106015 ** IN_INDEX_ROWID - The cursor was opened on a database table.
106016 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106026,11 +106242,14 @@
106026 ** SELECT <column1>, <column2>... FROM <table>
106027 **
106028 ** If the RHS of the IN operator is a list or a more complex subquery, then
106029 ** an ephemeral table might need to be generated from the RHS and then
106030 ** pX->iTable made to point to the ephemeral table instead of an
106031 ** existing table.
 
 
 
106032 **
106033 ** The inFlags parameter must contain, at a minimum, one of the bits
106034 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106035 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106036 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106087,16 +106306,21 @@
106087 int *aiMap, /* Mapping from Index fields to RHS fields */
106088 int *piTab /* OUT: index to use */
106089 ){
106090 Select *p; /* SELECT to the right of IN operator */
106091 int eType = 0; /* Type of RHS table. IN_INDEX_* */
106092 int iTab = pParse->nTab++; /* Cursor of the RHS table */
106093 int mustBeUnique; /* True if RHS must be unique */
106094 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106095
106096 assert( pX->op==TK_IN );
106097 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
 
 
 
 
 
106098
106099 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
106100 ** whether or not the SELECT result contains NULL values, check whether
106101 ** or not NULL is actually possible (it may not be, for example, due
106102 ** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106258,10 +106482,12 @@
106258 if( eType==0
106259 && (inFlags & IN_INDEX_NOOP_OK)
106260 && ExprUseXList(pX)
106261 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106262 ){
 
 
106263 eType = IN_INDEX_NOOP;
106264 }
106265
106266 if( eType==0 ){
106267 /* Could not find an existing table or index to use as the RHS b-tree.
@@ -106424,11 +106650,13 @@
106424 pExpr->x.pSelect->selId));
106425 }
106426 assert( ExprUseYSub(pExpr) );
106427 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106428 pExpr->y.sub.iAddr);
106429 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
 
 
106430 sqlite3VdbeJumpHere(v, addrOnce);
106431 return;
106432 }
106433
106434 /* Begin coding the subroutine */
@@ -108164,11 +108392,13 @@
108164 p = pParse->pConstExpr;
108165 if( regDest<0 && p ){
108166 struct ExprList_item *pItem;
108167 int i;
108168 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108169 if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
 
 
108170 return pItem->u.iConstExprReg;
108171 }
108172 }
108173 }
108174 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108187,11 +108417,11 @@
108187 sqlite3VdbeJumpHere(v, addr);
108188 }else{
108189 p = sqlite3ExprListAppend(pParse, p, pExpr);
108190 if( p ){
108191 struct ExprList_item *pItem = &p->a[p->nExpr-1];
108192 pItem->reusable = regDest<0;
108193 if( regDest<0 ) regDest = ++pParse->nMem;
108194 pItem->u.iConstExprReg = regDest;
108195 }
108196 pParse->pConstExpr = p;
108197 }
@@ -108321,11 +108551,11 @@
108321 n = pList->nExpr;
108322 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108323 for(pItem=pList->a, i=0; i<n; i++, pItem++){
108324 Expr *pExpr = pItem->pExpr;
108325 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
108326 if( pItem->bSorterRef ){
108327 i--;
108328 n--;
108329 }else
108330 #endif
108331 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -108946,11 +109176,11 @@
108946 if( pA->nExpr!=pB->nExpr ) return 1;
108947 for(i=0; i<pA->nExpr; i++){
108948 int res;
108949 Expr *pExprA = pA->a[i].pExpr;
108950 Expr *pExprB = pB->a[i].pExpr;
108951 if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
108952 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
108953 }
108954 return 0;
108955 }
108956
@@ -110635,11 +110865,11 @@
110635 return WRC_Prune;
110636 }
110637 if( ALWAYS(p->pEList) ){
110638 ExprList *pList = p->pEList;
110639 for(i=0; i<pList->nExpr; i++){
110640 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110641 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110642 }
110643 }
110644 }
110645 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110684,11 +110914,11 @@
110684 memset(&sWalker, 0, sizeof(Walker));
110685 sWalker.pParse = pParse;
110686 sWalker.xExprCallback = renameUnmapExprCb;
110687 sqlite3WalkExprList(&sWalker, pEList);
110688 for(i=0; i<pEList->nExpr; i++){
110689 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110690 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110691 }
110692 }
110693 }
110694 }
@@ -110842,11 +111072,11 @@
110842 ){
110843 if( pEList ){
110844 int i;
110845 for(i=0; i<pEList->nExpr; i++){
110846 const char *zName = pEList->a[i].zEName;
110847 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
110848 && ALWAYS(zName!=0)
110849 && 0==sqlite3_stricmp(zName, zOld)
110850 ){
110851 renameTokenFind(pParse, pCtx, (const void*)zName);
110852 }
@@ -112867,13 +113097,18 @@
112867 ** * the index contains 100 rows,
112868 ** * "WHERE a=?" matches 10 rows, and
112869 ** * "WHERE a=? AND b=?" matches 2 rows.
112870 **
112871 ** If D is the count of distinct values and K is the total number of
112872 ** rows, then each estimate is computed as:
112873 **
112874 ** I = (K+D-1)/D
 
 
 
 
 
112875 */
112876 sqlite3_str sStat; /* Text of the constructed "stat" line */
112877 int i; /* Loop counter */
112878
112879 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -112880,10 +113115,11 @@
112880 sqlite3_str_appendf(&sStat, "%llu",
112881 p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
112882 for(i=0; i<p->nKeyCol; i++){
112883 u64 nDistinct = p->current.anDLt[i] + 1;
112884 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
 
112885 sqlite3_str_appendf(&sStat, " %llu", iVal);
112886 assert( p->current.anEq[i] );
112887 }
112888 sqlite3ResultStrAccum(context, &sStat);
112889 }
@@ -115001,13 +115237,11 @@
115001 Returning *pReturning = pParse->u1.pReturning;
115002 int addrRewind;
115003 int i;
115004 int reg;
115005
115006 if( NEVER(pReturning->nRetCol==0) ){
115007 assert( CORRUPT_DB );
115008 }else{
115009 sqlite3VdbeAddOp0(v, OP_FkCheck);
115010 addrRewind =
115011 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
115012 VdbeCoverage(v);
115013 reg = pReturning->iRetReg;
@@ -115099,13 +115333,11 @@
115099 }
115100 }
115101
115102 if( pParse->bReturning ){
115103 Returning *pRet = pParse->u1.pReturning;
115104 if( NEVER(pRet->nRetCol==0) ){
115105 assert( CORRUPT_DB );
115106 }else{
115107 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115108 }
115109 }
115110
115111 /* Finally, jump back to the beginning of the executable code. */
@@ -116723,11 +116955,11 @@
116723 }
116724 pTab->iPKey = iCol;
116725 pTab->keyConf = (u8)onError;
116726 assert( autoInc==0 || autoInc==1 );
116727 pTab->tabFlags |= autoInc*TF_Autoincrement;
116728 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116729 (void)sqlite3HasExplicitNulls(pParse, pList);
116730 }else if( autoInc ){
116731 #ifndef SQLITE_OMIT_AUTOINCREMENT
116732 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116733 "INTEGER PRIMARY KEY");
@@ -117217,11 +117449,11 @@
117217 return;
117218 }
117219 if( IN_RENAME_OBJECT ){
117220 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117221 }
117222 pList->a[0].sortFlags = pParse->iPkSortOrder;
117223 assert( pParse->pNewTable==pTab );
117224 pTab->iPKey = -1;
117225 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117226 SQLITE_IDXTYPE_PRIMARYKEY);
117227 if( pParse->nErr ){
@@ -117888,11 +118120,10 @@
117888 */
117889 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
117890 Table *pSelTab; /* A fake table from which we get the result set */
117891 Select *pSel; /* Copy of the SELECT that implements the view */
117892 int nErr = 0; /* Number of errors encountered */
117893 int n; /* Temporarily holds the number of cursors assigned */
117894 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
117895 #ifndef SQLITE_OMIT_VIRTUALTABLE
117896 int rc;
117897 #endif
117898 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -117946,12 +118177,13 @@
117946 */
117947 assert( IsView(pTable) );
117948 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
117949 if( pSel ){
117950 u8 eParseMode = pParse->eParseMode;
 
 
117951 pParse->eParseMode = PARSE_MODE_NORMAL;
117952 n = pParse->nTab;
117953 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
117954 pTable->nCol = -1;
117955 DisableLookaside;
117956 #ifndef SQLITE_OMIT_AUTHORIZATION
117957 xAuth = db->xAuth;
@@ -117959,11 +118191,12 @@
117959 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117960 db->xAuth = xAuth;
117961 #else
117962 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117963 #endif
117964 pParse->nTab = n;
 
117965 if( pSelTab==0 ){
117966 pTable->nCol = 0;
117967 nErr++;
117968 }else if( pTable->pCheck ){
117969 /* CREATE VIEW name(arglist) AS ...
@@ -118704,12 +118937,12 @@
118704 */
118705 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118706 if( pList ){
118707 int i;
118708 for(i=0; i<pList->nExpr; i++){
118709 if( pList->a[i].bNulls ){
118710 u8 sf = pList->a[i].sortFlags;
118711 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118712 (sf==0 || sf==3) ? "FIRST" : "LAST"
118713 );
118714 return 1;
118715 }
@@ -119058,11 +119291,11 @@
119058 if( !zColl ) zColl = sqlite3StrBINARY;
119059 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119060 goto exit_create_index;
119061 }
119062 pIndex->azColl[i] = zColl;
119063 requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119064 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119065 }
119066
119067 /* Append the table key to the end of the index. For WITHOUT ROWID
119068 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -130380,15 +130613,23 @@
130380 sqlite3_total_changes64,
130381 /* Version 3.37.0 and later */
130382 sqlite3_autovacuum_pages,
130383 /* Version 3.38.0 and later */
130384 sqlite3_error_offset,
 
130385 sqlite3_vtab_rhs_value,
130386 sqlite3_vtab_distinct,
130387 sqlite3_vtab_in,
130388 sqlite3_vtab_in_first,
130389 sqlite3_vtab_in_next,
 
 
 
 
 
 
 
130390 /* Version 3.39.0 and later */
130391 #ifndef SQLITE_OMIT_DESERIALIZE
130392 sqlite3_deserialize,
130393 sqlite3_serialize
130394 #else
@@ -134828,10 +135069,18 @@
134828 db->pParse = pParse;
134829 pParse->db = db;
134830 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
134831 }
134832
 
 
 
 
 
 
 
 
134833 /*
134834 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
134835 */
134836 static int sqlite3Prepare(
134837 sqlite3 *db, /* Database handle. */
@@ -135002,11 +135251,11 @@
135002 ** or encounters a permanent error. A schema problem after one schema
135003 ** reset is considered a permanent error. */
135004 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135005 assert( rc==SQLITE_OK || *ppStmt==0 );
135006 if( rc==SQLITE_OK || db->mallocFailed ) break;
135007 }while( rc==SQLITE_ERROR_RETRY
135008 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135009 sqlite3BtreeLeaveAll(db);
135010 rc = sqlite3ApiExit(db, rc);
135011 assert( (rc&db->errMask)==rc );
135012 db->busyHandler.nBusy = 0;
@@ -135553,11 +135802,11 @@
135553 ExprList *pResults;
135554 assert( pItem->pSelect!=0 );
135555 pResults = pItem->pSelect->pEList;
135556 assert( pResults!=0 );
135557 assert( iCol>=0 && iCol<pResults->nExpr );
135558 pResults->a[iCol].bUsed = 1;
135559 }
135560 }
135561
135562 /*
135563 ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136221,11 +136470,11 @@
136221 ** the row from table t1 is stored instead. Then, as records are extracted from
136222 ** the sorter to return to the user, the required value of bigblob is
136223 ** retrieved directly from table t1. If the values are very large, this
136224 ** can be more efficient than storing them directly in the sorter records.
136225 **
136226 ** The ExprList_item.bSorterRef flag is set for each expression in pEList
136227 ** for which the sorter-reference optimization should be enabled.
136228 ** Additionally, the pSort->aDefer[] array is populated with entries
136229 ** for all cursors required to evaluate all selected expressions. Finally.
136230 ** output variable (*ppExtra) is set to an expression list containing
136231 ** expressions for all extra PK values that should be stored in the
@@ -136281,11 +136530,11 @@
136281 pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136282 pSort->aDefer[nDefer].nKey = nKey;
136283 nDefer++;
136284 }
136285 }
136286 pItem->bSorterRef = 1;
136287 }
136288 }
136289 }
136290 pSort->nDefer = (u8)nDefer;
136291 *ppExtra = pExtra;
@@ -136412,11 +136661,11 @@
136412 ** from the sorter by the optimizations in this branch */
136413 pEList = p->pEList;
136414 for(i=0; i<pEList->nExpr; i++){
136415 if( pEList->a[i].u.x.iOrderByCol>0
136416 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136417 || pEList->a[i].bSorterRef
136418 #endif
136419 ){
136420 nResultCol--;
136421 regOrig = 0;
136422 }
@@ -136774,11 +137023,11 @@
136774 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
136775 if( pInfo ){
136776 assert( sqlite3KeyInfoIsWriteable(pInfo) );
136777 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
136778 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
136779 pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
136780 }
136781 }
136782 return pInfo;
136783 }
136784
@@ -136913,11 +137162,11 @@
136913 iSortTab = iTab;
136914 bSeq = 1;
136915 }
136916 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
136917 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136918 if( aOutEx[i].bSorterRef ) continue;
136919 #endif
136920 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
136921 }
136922 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136923 if( pSort->nDefer ){
@@ -136950,11 +137199,11 @@
136950 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
136951 }
136952 #endif
136953 for(i=nColumn-1; i>=0; i--){
136954 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136955 if( aOutEx[i].bSorterRef ){
136956 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
136957 }else
136958 #endif
136959 {
136960 int iRead;
@@ -137316,11 +137565,11 @@
137316
137317 assert( p!=0 );
137318 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137319 assert( p->op!=TK_COLUMN
137320 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137321 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137322 /* An AS clause always takes first priority */
137323 char *zName = pEList->a[i].zEName;
137324 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137325 }else if( srcName && p->op==TK_COLUMN ){
137326 char *zCol;
@@ -137402,13 +137651,14 @@
137402 *pnCol = nCol;
137403 *paCol = aCol;
137404
137405 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137406 struct ExprList_item *pX = &pEList->a[i];
 
137407 /* Get an appropriate name for the column
137408 */
137409 if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137410 /* If the column contains an "AS <name>" phrase, use <name> as the name */
137411 }else{
137412 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137413 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137414 pColExpr = pColExpr->pRight;
@@ -137438,11 +137688,14 @@
137438
137439 /* Make sure the column name is unique. If the name is not unique,
137440 ** append an integer to the name so that it becomes unique.
137441 */
137442 cnt = 0;
137443 while( zName && sqlite3HashFind(&ht, zName)!=0 ){
 
 
 
137444 nName = sqlite3Strlen30(zName);
137445 if( nName>0 ){
137446 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137447 if( zName[j]==':' ) nName = j;
137448 }
@@ -137449,12 +137702,15 @@
137449 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137450 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137451 }
137452 pCol->zCnName = zName;
137453 pCol->hName = sqlite3StrIHash(zName);
 
 
 
137454 sqlite3ColumnPropertiesFromName(0, pCol);
137455 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137456 sqlite3OomFault(db);
137457 }
137458 }
137459 sqlite3HashClear(&ht);
137460 if( db->mallocFailed ){
@@ -137707,11 +137963,11 @@
137707 pOrderBy->a[i].pExpr =
137708 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137709 }
137710 assert( sqlite3KeyInfoIsWriteable(pRet) );
137711 pRet->aColl[i] = pColl;
137712 pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137713 }
137714 }
137715
137716 return pRet;
137717 }
@@ -139375,10 +139631,12 @@
139375 ** See also (3) for restrictions on LEFT JOIN.
139376 **
139377 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139378 ** is the first element of the parent query.
139379 **
 
 
139380 **
139381 ** In this routine, the "p" parameter is a pointer to the outer query.
139382 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139383 ** uses aggregates.
139384 **
@@ -139498,10 +139756,13 @@
139498
139499 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139500 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139501 return 0; /* Restriction (27) */
139502 }
 
 
 
139503
139504 /* Restriction (17): If the sub-query is a compound SELECT, then it must
139505 ** use only the UNION ALL operator. And none of the simple select queries
139506 ** that make up the compound SELECT are allowed to be aggregate or distinct
139507 ** queries.
@@ -139542,10 +139803,11 @@
139542 /* Restriction (23) */
139543 if( (p->selFlags & SF_Recursive) ) return 0;
139544
139545 if( pSrc->nSrc>1 ){
139546 if( pParse->nSelect>500 ) return 0;
 
139547 aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
139548 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
139549 }
139550 }
139551
@@ -140170,17 +140432,17 @@
140170 */
140171 static int pushDownWhereTerms(
140172 Parse *pParse, /* Parse context (for malloc() and error reporting) */
140173 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
140174 Expr *pWhere, /* The WHERE clause of the outer query */
140175 int iCursor, /* Cursor number of the subquery */
140176 int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
140177 ){
140178 Expr *pNew;
140179 int nChng = 0;
140180 if( pWhere==0 ) return 0;
140181 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
 
140182
140183 #ifndef SQLITE_OMIT_WINDOWFUNC
140184 if( pSubq->pPrior ){
140185 Select *pSel;
140186 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -140206,14 +140468,15 @@
140206
140207 if( pSubq->pLimit!=0 ){
140208 return 0; /* restriction (3) */
140209 }
140210 while( pWhere->op==TK_AND ){
140211 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
140212 iCursor, isLeftJoin);
140213 pWhere = pWhere->pLeft;
140214 }
 
 
140215 if( isLeftJoin
140216 && (ExprHasProperty(pWhere,EP_FromJoin)==0
140217 || pWhere->w.iJoin!=iCursor)
140218 ){
140219 return 0; /* restriction (4) */
@@ -140221,20 +140484,22 @@
140221 if( ExprHasProperty(pWhere,EP_FromJoin)
140222 && pWhere->w.iJoin!=iCursor
140223 ){
140224 return 0; /* restriction (5) */
140225 }
140226 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
 
 
140227 nChng++;
140228 pSubq->selFlags |= SF_PushDown;
140229 while( pSubq ){
140230 SubstContext x;
140231 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140232 unsetJoinExpr(pNew, -1);
140233 x.pParse = pParse;
140234 x.iTable = iCursor;
140235 x.iNewTable = iCursor;
140236 x.isOuterJoin = 0;
140237 x.pEList = pSubq->pEList;
140238 pNew = substExpr(&x, pNew);
140239 #ifndef SQLITE_OMIT_WINDOWFUNC
140240 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -140304,11 +140569,11 @@
140304 }else{
140305 return eRet;
140306 }
140307 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140308 assert( pOrderBy!=0 || db->mallocFailed );
140309 if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140310 return eRet;
140311 }
140312
140313 /*
140314 ** The select statement passed as the first argument is an aggregate query.
@@ -140773,11 +141038,11 @@
140773 if( pTab==0 ) return SQLITE_NOMEM;
140774 pTab->nTabRef = 1;
140775 if( pFrom->zAlias ){
140776 pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
140777 }else{
140778 pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId);
140779 }
140780 while( pSel->pPrior ){ pSel = pSel->pPrior; }
140781 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
140782 pTab->iPKey = -1;
140783 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -141011,11 +141276,11 @@
141011 /* This particular expression does not need to be expanded.
141012 */
141013 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141014 if( pNew ){
141015 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141016 pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141017 a[k].zEName = 0;
141018 }
141019 a[k].pExpr = 0;
141020 }else{
141021 /* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141026,39 +141291,64 @@
141026 assert( pE->pLeft!=0 );
141027 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
141028 zTName = pE->pLeft->u.zToken;
141029 }
141030 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
141031 Table *pTab = pFrom->pTab;
141032 Select *pSub;
141033 char *zTabName = pFrom->zAlias;
141034 const char *zSchemaName = 0;
141035 int iDb;
141036 if( zTabName==0 ){
 
 
141037 zTabName = pTab->zName;
141038 }
141039 if( db->mallocFailed ) break;
141040 assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141041 if( pFrom->fg.isNestedFrom ){
141042 pSub = pFrom->pSelect;
141043 assert( pSub->pEList!=0 );
141044 assert( pSub->pEList->nExpr==pTab->nCol );
 
141045 }else{
141046 pSub = 0;
141047 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
141048 continue;
141049 }
 
141050 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141051 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141052 }
141053 for(j=0; j<pTab->nCol; j++){
141054 char *zName = pTab->aCol[j].zCnName;
141055 struct ExprList_item *pX; /* Newly added ExprList term */
141056
141057 assert( zName );
141058 if( zTName && pSub
141059 && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
 
141060 ){
141061 continue;
141062 }
141063
141064 /* If a column is marked as 'hidden', omit it from the expanded
@@ -141067,14 +141357,20 @@
141067 */
141068 if( (p->selFlags & SF_IncludeHidden)==0
141069 && IsHiddenColumn(&pTab->aCol[j])
141070 ){
141071 continue;
 
 
 
 
 
 
141072 }
141073 tableSeen = 1;
141074
141075 if( i>0 && zTName==0 ){
141076 if( pFrom->fg.isUsing
141077 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141078 ){
141079 /* In a join with a USING clause, omit columns in the
141080 ** using clause from the table on the right. */
@@ -141082,10 +141378,11 @@
141082 }
141083 }
141084 pRight = sqlite3Expr(db, TK_ID, zName);
141085 if( (pTabList->nSrc>1
141086 && ( (pFrom->fg.jointype & JT_LTORJ)==0
 
141087 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141088 )
141089 )
141090 || IN_RENAME_OBJECT
141091 ){
@@ -141107,25 +141404,32 @@
141107 break; /* OOM */
141108 }
141109 pX = &pNew->a[pNew->nExpr-1];
141110 assert( pX->zEName==0 );
141111 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
141112 if( pSub ){
141113 pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName);
141114 testcase( pX->zEName==0 );
141115 }else{
141116 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141117 zSchemaName, zTabName, zName);
141118 testcase( pX->zEName==0 );
141119 }
141120 pX->eEName = ENAME_TAB;
 
 
 
 
 
 
 
141121 }else if( longNames ){
141122 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141123 pX->eEName = ENAME_NAME;
141124 }else{
141125 pX->zEName = sqlite3DbStrDup(db, zName);
141126 pX->eEName = ENAME_NAME;
141127 }
141128 }
141129 }
141130 if( !tableSeen ){
141131 if( zTName ){
@@ -142053,13 +142357,11 @@
142053 ** inside the subquery. This can help the subquery to run more efficiently.
142054 */
142055 if( OptimizationEnabled(db, SQLITE_PushDown)
142056 && (pItem->fg.isCte==0
142057 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
142058 && (pItem->fg.jointype & JT_RIGHT)==0
142059 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
142060 (pItem->fg.jointype & JT_OUTER)!=0)
142061 ){
142062 #if TREETRACE_ENABLED
142063 if( sqlite3TreeTrace & 0x100 ){
142064 SELECTTRACE(0x100,pParse,p,
142065 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -142251,17 +142553,17 @@
142251 if( pDest->eDest==SRT_EphemTab ){
142252 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142253 if( p->selFlags & SF_NestedFrom ){
142254 /* Delete or NULL-out result columns that will never be used */
142255 int ii;
142256 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].bUsed==0; ii--){
142257 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142258 sqlite3DbFree(db, pEList->a[ii].zEName);
142259 pEList->nExpr--;
142260 }
142261 for(ii=0; ii<pEList->nExpr; ii++){
142262 if( pEList->a[ii].bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142263 }
142264 }
142265 }
142266
142267 /* Set the limiter.
@@ -142409,12 +142711,13 @@
142409 ** ASC or DESC order - only that each group is returned contiguously.
142410 ** So set the ASC/DESC flags in the GROUP BY to match those in the
142411 ** ORDER BY to maximize the chances of rows being delivered in an
142412 ** order that makes the ORDER BY redundant. */
142413 for(ii=0; ii<pGroupBy->nExpr; ii++){
142414 u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142415 pGroupBy->a[ii].sortFlags = sortFlags;
 
142416 }
142417 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142418 orderByGrp = 1;
142419 }
142420 }
@@ -144065,20 +144368,20 @@
144065 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144066 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144067 if( !db->mallocFailed ){
144068 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144069 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144070 pItem->eEName = ENAME_NAME;
144071 }
144072 }
144073 }else{
144074 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144075 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144076 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144077 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144078 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144079 pItem->eEName = pList->a[i].eEName;
144080 }
144081 }
144082 }
144083 return pNew;
144084 }
@@ -146647,10 +146950,11 @@
146647 #endif
146648 }
146649
146650 assert( rc==SQLITE_OK );
146651 if( pOut==0 ){
 
146652 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146653 }
146654
146655 end_of_vacuum:
146656 /* Restore the original value of db->flags */
@@ -148109,10 +148413,11 @@
148109 struct WhereRightJoin {
148110 int iMatch; /* Cursor used to determine prior matched rows */
148111 int regBloom; /* Bloom filter for iRJMatch */
148112 int regReturn; /* Return register for the interior subroutine */
148113 int addrSubrtn; /* Starting address for the interior subroutine */
 
148114 };
148115
148116 /*
148117 ** This object contains information needed to implement a single nested
148118 ** loop in WHERE clause.
@@ -149300,20 +149605,26 @@
149300
149301 iTab = 0;
149302 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149303 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149304 }else{
149305 sqlite3 *db = pParse->db;
149306 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149307
149308 if( !db->mallocFailed ){
 
 
 
 
 
 
 
149309 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149310 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149311 pTerm->pExpr->iTable = iTab;
149312 }
149313 sqlite3ExprDelete(db, pX);
149314 pX = pTerm->pExpr;
149315 }
149316
149317 if( eType==IN_INDEX_INDEX_DESC ){
149318 testcase( bRev );
149319 bRev = !bRev;
@@ -149936,16 +150247,16 @@
149936 ** that contains the value of pExpr.
149937 */
149938 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
149939 IdxExprTrans *pX = p->u.pIdxTrans;
149940 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
 
149941 preserveExpr(pX, pExpr);
149942 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
149943 pExpr->op = TK_COLUMN;
149944 pExpr->iTable = pX->iIdxCur;
149945 pExpr->iColumn = pX->iIdxCol;
149946 testcase( ExprHasProperty(pExpr, EP_Skip) );
149947 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
149948 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
149949 pExpr->y.pTab = 0;
149950 return WRC_Prune;
149951 }else{
@@ -150095,10 +150406,12 @@
150095 if( pLevel->regFilter==0 ) continue;
150096 if( pLevel->pWLoop->nSkip ) continue;
150097 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150098 ** vvvvv--' pLevel->regFilter if this were true. */
150099 if( NEVER(pLoop->prereq & notReady) ) continue;
 
 
150100 if( pLoop->wsFlags & WHERE_IPK ){
150101 WhereTerm *pTerm = pLoop->aLTerm[0];
150102 int regRowid;
150103 assert( pTerm!=0 );
150104 assert( pTerm->pExpr!=0 );
@@ -150121,10 +150434,11 @@
150121 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150122 addrNxt, r1, nEq);
150123 VdbeCoverage(pParse->pVdbe);
150124 }
150125 pLevel->regFilter = 0;
 
150126 }
150127 }
150128
150129 /*
150130 ** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151301,11 +151615,11 @@
151301 continue;
151302 }
151303 pE = pTerm->pExpr;
151304 assert( pE!=0 );
151305 if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151306 && !ExprHasProperty(pE,EP_FromJoin)
151307 ){
151308 continue;
151309 }
151310
151311 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -151508,10 +151822,12 @@
151508 SrcList sFrom;
151509 Bitmask mAll = 0;
151510 int k;
151511
151512 ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName));
 
 
151513 for(k=0; k<iLevel; k++){
151514 int iIdxCur;
151515 mAll |= pWInfo->a[k].pWLoop->maskSelf;
151516 sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur);
151517 iIdxCur = pWInfo->a[k].iIdxCur;
@@ -153190,11 +153506,11 @@
153190 if( pOrderBy ){
153191 for(ii=0; ii<pOrderBy->nExpr; ii++){
153192 Expr *pExpr = pOrderBy->a[ii].pExpr;
153193 if( pExpr->op!=TK_COLUMN ) return;
153194 if( pExpr->iTable!=iCsr ) return;
153195 if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153196 }
153197 }
153198
153199 /* All conditions are met. Add the terms to the where-clause object. */
153200 assert( p->pLimit->op==TK_LIMIT );
@@ -153516,11 +153832,11 @@
153516 ** continuation of the inner-most loop. */
153517 return pWInfo->iContinue;
153518 }
153519 pInner = &pWInfo->a[pWInfo->nLevel-1];
153520 assert( pInner->addrNxt!=0 );
153521 return pInner->addrNxt;
153522 }
153523
153524 /*
153525 ** While generating code for the min/max optimization, after handling
153526 ** the aggregate-step call to min() or max(), check to see if any
@@ -154246,13 +154562,11 @@
154246 Expr *pExpr = pTerm->pExpr;
154247 /* Make the automatic index a partial index if there are terms in the
154248 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
154249 ** rows of the target table (pSrc) that can be used. */
154250 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154251 && ((pSrc->fg.jointype&(JT_LEFT|JT_LTORJ))==0
154252 || ExprHasProperty(pExpr,EP_FromJoin))
154253 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
154254 ){
154255 pPartial = sqlite3ExprAnd(pParse, pPartial,
154256 sqlite3ExprDup(pParse->db, pExpr, 0));
154257 }
154258 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -154487,11 +154801,11 @@
154487 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
154488 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
154489 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
154490 Expr *pExpr = pTerm->pExpr;
154491 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154492 && sqlite3ExprIsTableConstant(pExpr, iCur)
154493 ){
154494 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
154495 }
154496 }
154497 if( pLoop->wsFlags & WHERE_IPK ){
@@ -154622,11 +154936,11 @@
154622 if( sqlite3ExprIsConstant(pExpr) ){
154623 continue;
154624 }
154625
154626 /* Virtual tables are unable to deal with NULLS FIRST */
154627 if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154628
154629 /* First case - a direct column references without a COLLATE operator */
154630 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154631 assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154632 continue;
@@ -154734,11 +155048,11 @@
154734 if( sqlite3ExprIsConstant(pExpr) ) continue;
154735 assert( pExpr->op==TK_COLUMN
154736 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154737 && pExpr->iColumn==pExpr->pLeft->iColumn) );
154738 pIdxOrderBy[j].iColumn = pExpr->iColumn;
154739 pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
154740 j++;
154741 }
154742 pIdxInfo->nOrderBy = j;
154743
154744 *pmNoOmit = mNoOmit;
@@ -156252,11 +156566,11 @@
156252 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156253 ** be used by the right table of a LEFT JOIN nor by the left table of a
156254 ** RIGHT JOIN. Only constraints in the
156255 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156256 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156257 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156258 ){
156259 continue;
156260 }
156261
156262 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157560,13 +157874,11 @@
157560 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157561 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157562 if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157563 /* This condition is true when pItem is the FROM clause term on the
157564 ** right-hand-side of a OUTER or CROSS JOIN. */
157565 mPrereq = mPrior;
157566 }else{
157567 mPrereq = 0;
157568 }
157569 #ifndef SQLITE_OMIT_VIRTUALTABLE
157570 if( IsVirtual(pItem->pTab) ){
157571 SrcItem *p;
157572 for(p=&pItem[1]; p<pEnd; p++){
@@ -157873,20 +158185,22 @@
157873 }
157874 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
157875 /* Make sure the sort order is compatible in an ORDER BY clause.
157876 ** Sort order is irrelevant for a GROUP BY clause. */
157877 if( revSet ){
157878 if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
 
 
157879 isMatch = 0;
157880 }
157881 }else{
157882 rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
157883 if( rev ) *pRevMask |= MASKBIT(iLoop);
157884 revSet = 1;
157885 }
157886 }
157887 if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
157888 if( j==pLoop->u.btree.nEq ){
157889 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
157890 }else{
157891 isMatch = 0;
157892 }
@@ -159438,10 +159752,11 @@
159438 /* Terminate the subroutine that forms the interior of the loop of
159439 ** the RIGHT JOIN table */
159440 WhereRightJoin *pRJ = pLevel->pRJ;
159441 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
159442 pLevel->addrCont = 0;
 
159443 sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1);
159444 VdbeCoverage(v);
159445 assert( pParse->withinRJSubrtn>0 );
159446 pParse->withinRJSubrtn--;
159447 }
@@ -160645,11 +160960,11 @@
160645 pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160646 pSub->u.zToken = 0;
160647 }
160648 }
160649 pList = sqlite3ExprListAppend(pParse, pList, pDup);
160650 if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
160651 }
160652 }
160653 return pList;
160654 }
160655
@@ -161846,11 +162161,11 @@
161846 windowReadPeerValues(p, csr1, reg1);
161847 windowReadPeerValues(p, csr2, reg2);
161848
161849 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
161850 assert( pOrderBy && pOrderBy->nExpr==1 );
161851 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
161852 switch( op ){
161853 case OP_Ge: op = OP_Le; break;
161854 case OP_Gt: op = OP_Lt; break;
161855 default: assert( op==OP_Le ); op = OP_Ge; break;
161856 }
@@ -161879,11 +162194,11 @@
161879 ** }
161880 **
161881 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
161882 ** not taken, control jumps over the comparison operator coded below this
161883 ** block. */
161884 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
161885 /* This block runs if reg1 contains a NULL. */
161886 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
161887 switch( op ){
161888 case OP_Ge:
161889 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -226663,11 +226978,11 @@
226663 /* State used by the fts5DataXXX() functions. */
226664 sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226665 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226666 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226667 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226668 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */
226669 sqlite3_stmt *pIdxSelect;
226670 int nRead; /* Total number of blocks read */
226671
226672 sqlite3_stmt *pDataVersion;
226673 i64 iStructVersion; /* data_version when pStruct read */
@@ -235980,11 +236295,11 @@
235980 int nArg, /* Number of args */
235981 sqlite3_value **apUnused /* Function arguments */
235982 ){
235983 assert( nArg==0 );
235984 UNUSED_PARAM2(nArg, apUnused);
235985 sqlite3_result_text(pCtx, "fts5: 2022-04-19 15:56:03 b966d52437f08a6759a83a45cafb0d706a8933a8e55dee38ae78166d1a5b3ba4", -1, SQLITE_TRANSIENT);
235986 }
235987
235988 /*
235989 ** Return true if zName is the extension on one of the shadow tables used
235990 ** by this module.
235991
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -15790,12 +15790,14 @@
15790 # define sqlite3VdbeVerifyNoMallocRequired(A,B)
15791 # define sqlite3VdbeVerifyNoResultRow(A)
15792 #endif
15793 #if defined(SQLITE_DEBUG)
15794 SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
15795 SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
15796 #else
15797 # define sqlite3VdbeVerifyAbortable(A,B)
15798 # define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
15799 #endif
15800 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
15801 #ifndef SQLITE_OMIT_EXPLAIN
15802 SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
15803 SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
@@ -17051,10 +17053,12 @@
17053 /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
17054 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17055 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17056 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17057 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17058 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17059 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17060 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17061
17062 /*
17063 ** Macros for testing whether or not optimizations are enabled or disabled.
17064 */
@@ -17396,10 +17400,11 @@
17400 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
17401 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
17402 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17403 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17404 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17405 #define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
17406 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17407 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17408
17409 /*
17410 ** A "Collating Sequence" is defined by an instance of the following
@@ -18269,17 +18274,22 @@
18274 int nExpr; /* Number of expressions on the list */
18275 int nAlloc; /* Number of a[] slots allocated */
18276 struct ExprList_item { /* For each expression in the list */
18277 Expr *pExpr; /* The parse tree for this expression */
18278 char *zEName; /* Token associated with this expression */
18279 struct {
18280 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18281 unsigned eEName :2; /* Meaning of zEName */
18282 unsigned done :1; /* Indicates when processing is finished */
18283 unsigned reusable :1; /* Constant expression is reusable */
18284 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18285 unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
18286 unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
18287 unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
18288 unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should
18289 ** not be expanded by "*" in parent queries */
18290 } fg;
18291 union {
18292 struct { /* Used by any ExprList other than Parse.pConsExpr */
18293 u16 iOrderByCol; /* For ORDER BY, column number in result set */
18294 u16 iAlias; /* Index into Parse.aAlias[] for zName */
18295 } x;
@@ -19729,10 +19739,11 @@
19739 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19740 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19741 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19742 SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19743 SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19744 SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
19745 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19746 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19747 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19748 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19749 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20022,10 +20033,11 @@
20033 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
20034 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
20035 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
20036 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
20037 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20038 SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
20039 #ifdef SQLITE_ENABLE_CURSOR_HINTS
20040 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
20041 #endif
20042 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
20043 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -20583,10 +20595,11 @@
20595 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
20596 */
20597 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
20598 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
20599 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
20600 #define IN_INDEX_REUSE_CUR 0x0008 /* Reuse prior table cursor */
20601 SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
20602
20603 SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
20604 SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
20605 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
@@ -30462,12 +30475,18 @@
30475 sqlite3_str_append(pAccum, ".", 1);
30476 }
30477 sqlite3_str_appendall(pAccum, pItem->zName);
30478 }else if( pItem->zAlias ){
30479 sqlite3_str_appendall(pAccum, pItem->zAlias);
30480 }else{
30481 Select *pSel = pItem->pSelect;
30482 assert( pSel!=0 );
30483 if( pSel->selFlags & SF_NestedFrom ){
30484 sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId);
30485 }else{
30486 sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId);
30487 }
30488 }
30489 length = width = 0;
30490 break;
30491 }
30492 default: {
@@ -31047,10 +31066,57 @@
31066 */
31067 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
31068 sqlite3TreeViewPush(&p, moreFollows);
31069 sqlite3TreeViewLine(p, "%s", zLabel);
31070 }
31071
31072 /*
31073 ** Show a list of Column objects in tree format.
31074 */
31075 SQLITE_PRIVATE void sqlite3TreeViewColumnList(
31076 TreeView *pView,
31077 const Column *aCol,
31078 int nCol,
31079 u8 moreToFollow
31080 ){
31081 int i;
31082 sqlite3TreeViewPush(&pView, moreToFollow);
31083 sqlite3TreeViewLine(pView, "COLUMNS");
31084 for(i=0; i<nCol; i++){
31085 u16 flg = aCol[i].colFlags;
31086 int moreToFollow = i<(nCol - 1);
31087 sqlite3TreeViewPush(&pView, moreToFollow);
31088 sqlite3TreeViewLine(pView, 0);
31089 printf(" %s", aCol[i].zCnName);
31090 switch( aCol[i].eCType ){
31091 case COLTYPE_ANY: printf(" ANY"); break;
31092 case COLTYPE_BLOB: printf(" BLOB"); break;
31093 case COLTYPE_INT: printf(" INT"); break;
31094 case COLTYPE_INTEGER: printf(" INTEGER"); break;
31095 case COLTYPE_REAL: printf(" REAL"); break;
31096 case COLTYPE_TEXT: printf(" TEXT"); break;
31097 case COLTYPE_CUSTOM: {
31098 if( flg & COLFLAG_HASTYPE ){
31099 const char *z = aCol[i].zCnName;
31100 z += strlen(z)+1;
31101 printf(" X-%s", z);
31102 break;
31103 }
31104 }
31105 }
31106 if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY");
31107 if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN");
31108 #ifdef COLFLAG_NOEXPAND
31109 if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND");
31110 #endif
31111 if( flg ) printf(" flags=%04x", flg);
31112 printf("\n");
31113 fflush(stdout);
31114 sqlite3TreeViewPop(&pView);
31115 }
31116 sqlite3TreeViewPop(&pView);
31117 }
31118
31119 /*
31120 ** Generate a human-readable description of a WITH clause.
31121 */
31122 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31077,10 +31143,14 @@
31143 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
31144 cSep = ',';
31145 }
31146 sqlite3_str_appendf(&x, ")");
31147 }
31148 if( pCte->eM10d!=M10d_Any ){
31149 sqlite3_str_appendf(&x, " %sMATERIALIZED",
31150 pCte->eM10d==M10d_No ? "NOT " : "");
31151 }
31152 if( pCte->pUse ){
31153 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
31154 pCte->pUse->nUse);
31155 }
31156 sqlite3StrAccumFinish(&x);
@@ -31099,10 +31169,11 @@
31169 int i;
31170 if( pSrc==0 ) return;
31171 for(i=0; i<pSrc->nSrc; i++){
31172 const SrcItem *pItem = &pSrc->a[i];
31173 StrAccum x;
31174 int n = 0;
31175 char zLine[100];
31176 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
31177 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
31178 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
31179 if( pItem->pTab ){
@@ -31127,13 +31198,24 @@
31198 if( pItem->fg.isCte ){
31199 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31200 }
31201 sqlite3StrAccumFinish(&x);
31202 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31203 n = 0;
31204 if( pItem->pSelect ) n++;
31205 if( pItem->fg.isTabFunc ) n++;
31206 if( pItem->fg.isUsing ) n++;
31207 if( pItem->fg.isUsing ){
31208 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
31209 }
31210 if( pItem->pSelect ){
31211 if( pItem->pTab ){
31212 Table *pTab = pItem->pTab;
31213 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31214 }
31215 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31216 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
31217 }
31218 if( pItem->fg.isTabFunc ){
31219 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31220 }
31221 sqlite3TreeViewPop(&pView);
@@ -31296,10 +31378,11 @@
31378 /*
31379 ** Generate a human-readable explanation for a Window object
31380 */
31381 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31382 int nElement = 0;
31383 if( pWin==0 ) return;
31384 if( pWin->pFilter ){
31385 sqlite3TreeViewItem(pView, "FILTER", 1);
31386 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31387 sqlite3TreeViewPop(&pView);
31388 }
@@ -31360,10 +31443,11 @@
31443 #ifndef SQLITE_OMIT_WINDOWFUNC
31444 /*
31445 ** Generate a human-readable explanation for a Window Function object
31446 */
31447 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31448 if( pWin==0 ) return;
31449 sqlite3TreeViewPush(&pView, more);
31450 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31451 pWin->pWFunc->zName, pWin->pWFunc->nArg);
31452 sqlite3TreeViewWindow(pView, pWin, 0);
31453 sqlite3TreeViewPop(&pView);
@@ -31611,11 +31695,21 @@
31695 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
31696 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31697 break;
31698 }
31699 case TK_IN: {
31700 sqlite3_str *pStr = sqlite3_str_new(0);
31701 char *z;
31702 sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags);
31703 if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable);
31704 if( ExprHasProperty(pExpr, EP_Subrtn) ){
31705 sqlite3_str_appendf(pStr, " subrtn(%d,%d)",
31706 pExpr->y.sub.regReturn, pExpr->y.sub.iAddr);
31707 }
31708 z = sqlite3_str_finish(pStr);
31709 sqlite3TreeViewLine(pView, z);
31710 sqlite3_free(z);
31711 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31712 if( ExprUseXSelect(pExpr) ){
31713 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31714 }else{
31715 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31762,17 +31856,19 @@
31856 if( j || zName ){
31857 sqlite3TreeViewPush(&pView, moreToFollow);
31858 moreToFollow = 0;
31859 sqlite3TreeViewLine(pView, 0);
31860 if( zName ){
31861 switch( pList->a[i].fg.eEName ){
31862 default:
31863 fprintf(stdout, "AS %s ", zName);
31864 break;
31865 case ENAME_TAB:
31866 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31867 if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) ");
31868 if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) ");
31869 if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) ");
31870 break;
31871 case ENAME_SPAN:
31872 fprintf(stdout, "SPAN(\"%s\") ", zName);
31873 break;
31874 }
@@ -81423,10 +81519,94 @@
81519 pParse->nLabel = 0;
81520 *pMaxFuncArgs = nMaxArgs;
81521 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
81522 }
81523
81524 #ifdef SQLITE_DEBUG
81525 /*
81526 ** Check to see if a subroutine contains a jump to a location outside of
81527 ** the subroutine. If a jump outside the subroutine is detected, add code
81528 ** that will cause the program to halt with an error message.
81529 **
81530 ** The subroutine consists of opcodes between iFirst and iLast. Jumps to
81531 ** locations within the subroutine are acceptable. iRetReg is a register
81532 ** that contains the return address. Jumps to outside the range of iFirst
81533 ** through iLast are also acceptable as long as the jump destination is
81534 ** an OP_Return to iReturnAddr.
81535 **
81536 ** A jump to an unresolved label means that the jump destination will be
81537 ** beyond the current address. That is normally a jump to an early
81538 ** termination and is consider acceptable.
81539 **
81540 ** This routine only runs during debug builds. The purpose is (of course)
81541 ** to detect invalid escapes out of a subroutine. The OP_Halt opcode
81542 ** is generated rather than an assert() or other error, so that ".eqp full"
81543 ** will still work to show the original bytecode, to aid in debugging.
81544 */
81545 SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(
81546 Vdbe *v, /* The byte-code program under construction */
81547 int iFirst, /* First opcode of the subroutine */
81548 int iLast, /* Last opcode of the subroutine */
81549 int iRetReg /* Subroutine return address register */
81550 ){
81551 VdbeOp *pOp;
81552 Parse *pParse;
81553 int i;
81554 sqlite3_str *pErr = 0;
81555 assert( v!=0 );
81556 pParse = v->pParse;
81557 assert( pParse!=0 );
81558 if( pParse->nErr ) return;
81559 assert( iLast>=iFirst );
81560 assert( iLast<v->nOp );
81561 pOp = &v->aOp[iFirst];
81562 for(i=iFirst; i<=iLast; i++, pOp++){
81563 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
81564 int iDest = pOp->p2; /* Jump destination */
81565 if( iDest==0 ) continue;
81566 if( pOp->opcode==OP_Gosub ) continue;
81567 if( iDest<0 ){
81568 int j = ADDR(iDest);
81569 assert( j>=0 );
81570 if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
81571 continue;
81572 }
81573 iDest = pParse->aLabel[j];
81574 }
81575 if( iDest<iFirst || iDest>iLast ){
81576 int j = iDest;
81577 for(; j<v->nOp; j++){
81578 VdbeOp *pX = &v->aOp[j];
81579 if( pX->opcode==OP_Return ){
81580 if( pX->p1==iRetReg ) break;
81581 continue;
81582 }
81583 if( pX->opcode==OP_Noop ) continue;
81584 if( pX->opcode==OP_Explain ) continue;
81585 if( pErr==0 ){
81586 pErr = sqlite3_str_new(0);
81587 }else{
81588 sqlite3_str_appendchar(pErr, 1, '\n');
81589 }
81590 sqlite3_str_appendf(pErr,
81591 "Opcode at %d jumps to %d which is outside the "
81592 "subroutine at %d..%d",
81593 i, iDest, iFirst, iLast);
81594 break;
81595 }
81596 }
81597 }
81598 }
81599 if( pErr ){
81600 char *zErr = sqlite3_str_finish(pErr);
81601 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
81602 sqlite3_free(zErr);
81603 sqlite3MayAbort(pParse);
81604 }
81605 }
81606 #endif /* SQLITE_DEBUG */
81607
81608 /*
81609 ** Return the address of the next instruction to be inserted.
81610 */
81611 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
81612 assert( p->eVdbeState==VDBE_INIT_STATE );
@@ -89154,10 +89334,12 @@
89334 if( pOp->p2==0 ) break;
89335
89336 /* Most jump operations do a goto to this spot in order to update
89337 ** the pOp pointer. */
89338 jump_to_p2:
89339 assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
89340 assert( pOp->p2<p->nOp ); /* Jumps must be in range */
89341 pOp = &aOp[pOp->p2 - 1];
89342 break;
89343 }
89344
89345 /* Opcode: EndCoroutine P1 * * * *
@@ -101365,11 +101547,11 @@
101547 const char *zTab,
101548 const char *zDb
101549 ){
101550 int n;
101551 const char *zSpan;
101552 if( pItem->fg.eEName!=ENAME_TAB ) return 0;
101553 zSpan = pItem->zEName;
101554 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101555 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101556 return 0;
101557 }
@@ -101594,12 +101776,13 @@
101776 }
101777 cnt++;
101778 cntTab = 2;
101779 pMatch = pItem;
101780 pExpr->iColumn = j;
101781 pEList->a[j].fg.bUsed = 1;
101782 hit = 1;
101783 if( pEList->a[j].fg.bUsingTerm ) break;
101784 }
101785 if( hit || zTab==0 ) continue;
101786 }
101787 assert( zDb==0 || zTab!=0 );
101788 if( zTab ){
@@ -101818,11 +102001,11 @@
102001 ){
102002 pEList = pNC->uNC.pEList;
102003 assert( pEList!=0 );
102004 for(j=0; j<pEList->nExpr; j++){
102005 char *zAs = pEList->a[j].zEName;
102006 if( pEList->a[j].fg.eEName==ENAME_NAME
102007 && sqlite3_stricmp(zAs, zCol)==0
102008 ){
102009 Expr *pOrig;
102010 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
102011 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102571,11 +102754,11 @@
102754 if( pE->op==TK_ID ){
102755 const char *zCol;
102756 assert( !ExprHasProperty(pE, EP_IntValue) );
102757 zCol = pE->u.zToken;
102758 for(i=0; i<pEList->nExpr; i++){
102759 if( pEList->a[i].fg.eEName==ENAME_NAME
102760 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102761 ){
102762 return i+1;
102763 }
102764 }
@@ -102692,11 +102875,11 @@
102875 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102876 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102877 return 1;
102878 }
102879 for(i=0; i<pOrderBy->nExpr; i++){
102880 pOrderBy->a[i].fg.done = 0;
102881 }
102882 pSelect->pNext = 0;
102883 while( pSelect->pPrior ){
102884 pSelect->pPrior->pNext = pSelect;
102885 pSelect = pSelect->pPrior;
@@ -102707,11 +102890,11 @@
102890 pEList = pSelect->pEList;
102891 assert( pEList!=0 );
102892 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102893 int iCol = -1;
102894 Expr *pE, *pDup;
102895 if( pItem->fg.done ) continue;
102896 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102897 if( NEVER(pE==0) ) continue;
102898 if( sqlite3ExprIsInteger(pE, &iCol) ){
102899 if( iCol<=0 || iCol>pEList->nExpr ){
102900 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102760,19 +102943,19 @@
102943 pParent->pLeft = pNew;
102944 }
102945 sqlite3ExprDelete(db, pE);
102946 pItem->u.x.iOrderByCol = (u16)iCol;
102947 }
102948 pItem->fg.done = 1;
102949 }else{
102950 moreToDo = 1;
102951 }
102952 }
102953 pSelect = pSelect->pNext;
102954 }
102955 for(i=0; i<pOrderBy->nExpr; i++){
102956 if( pOrderBy->a[i].fg.done==0 ){
102957 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102958 "column in the result set", i+1);
102959 return 1;
102960 }
102961 }
@@ -104911,10 +105094,11 @@
105094 pRet->nCte = p->nCte;
105095 for(i=0; i<p->nCte; i++){
105096 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
105097 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
105098 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
105099 pRet->a[i].eM10d = p->a[i].eM10d;
105100 }
105101 }
105102 }
105103 return pRet;
105104 }
@@ -105011,16 +105195,12 @@
105195 }
105196 pNewExpr->pLeft = pPriorSelectColNew;
105197 }
105198 }
105199 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105200 pItem->fg = pOldItem->fg;
105201 pItem->fg.done = 0;
 
 
 
 
105202 pItem->u = pOldItem->u;
105203 }
105204 return pNew;
105205 }
105206
@@ -105316,20 +105496,20 @@
105496 || eNulls==SQLITE_SO_ASC
105497 || eNulls==SQLITE_SO_DESC
105498 );
105499
105500 pItem = &p->a[p->nExpr-1];
105501 assert( pItem->fg.bNulls==0 );
105502 if( iSortOrder==SQLITE_SO_UNDEFINED ){
105503 iSortOrder = SQLITE_SO_ASC;
105504 }
105505 pItem->fg.sortFlags = (u8)iSortOrder;
105506
105507 if( eNulls!=SQLITE_SO_UNDEFINED ){
105508 pItem->fg.bNulls = 1;
105509 if( iSortOrder!=eNulls ){
105510 pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
105511 }
105512 }
105513 }
105514
105515 /*
@@ -105351,11 +105531,11 @@
105531 if( pList ){
105532 struct ExprList_item *pItem;
105533 assert( pList->nExpr>0 );
105534 pItem = &pList->a[pList->nExpr-1];
105535 assert( pItem->zEName==0 );
105536 assert( pItem->fg.eEName==ENAME_NAME );
105537 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105538 if( dequote ){
105539 /* If dequote==0, then pName->z does not point to part of a DDL
105540 ** statement handled by the parser. And so no token need be added
105541 ** to the token-map. */
@@ -105386,11 +105566,11 @@
105566 if( pList ){
105567 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105568 assert( pList->nExpr>0 );
105569 if( pItem->zEName==0 ){
105570 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105571 pItem->fg.eEName = ENAME_SPAN;
105572 }
105573 }
105574 }
105575
105576 /*
@@ -105678,10 +105858,46 @@
105858 ** table other than iCur.
105859 */
105860 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
105861 return exprIsConst(p, 3, iCur);
105862 }
105863
105864 /*
105865 ** Check pExpr to see if it is an invariant constraint on data source pSrc.
105866 ** This is an optimization. False negatives will perhaps cause slower
105867 ** queries, but false positives will yield incorrect answers. So when in
105868 ** doubt, return 0.
105869 **
105870 ** To be an invariant constraint, the following must be true:
105871 **
105872 ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
105873 **
105874 ** (2) pExpr cannot use subqueries or non-deterministic functions.
105875 **
105876 ** (3) pSrc cannot be part of the left operand for a RIGHT JOIN.
105877 ** (Is there some way to relax this constraint?)
105878 **
105879 ** (4) If pSrc is the right operand of a LEFT JOIN, then...
105880 ** (4a) pExpr must come from an ON clause..
105881 (4b) and specifically the ON clause associated with the LEFT JOIN.
105882 **
105883 ** (5) If pSrc is not the right operand of a LEFT JOIN or the left
105884 ** operand of a RIGHT JOIN, then pExpr must be from the WHERE
105885 ** clause, not an ON clause.
105886 */
105887 SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
105888 if( pSrc->fg.jointype & JT_LTORJ ){
105889 return 0; /* rule (3) */
105890 }
105891 if( pSrc->fg.jointype & JT_LEFT ){
105892 if( !ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (4a) */
105893 if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
105894 }else{
105895 if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (5) */
105896 }
105897 return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
105898 }
105899
105900
105901 /*
105902 ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
105903 */
@@ -106006,11 +106222,11 @@
106222 ** The job of this routine is to find or create a b-tree object that can
106223 ** be used either to test for membership in the RHS set or to iterate through
106224 ** all members of the RHS set, skipping duplicates.
106225 **
106226 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
106227 ** and the *piTab parameter is set to the index of that cursor.
106228 **
106229 ** The returned value of this function indicates the b-tree type, as follows:
106230 **
106231 ** IN_INDEX_ROWID - The cursor was opened on a database table.
106232 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106026,11 +106242,14 @@
106242 ** SELECT <column1>, <column2>... FROM <table>
106243 **
106244 ** If the RHS of the IN operator is a list or a more complex subquery, then
106245 ** an ephemeral table might need to be generated from the RHS and then
106246 ** pX->iTable made to point to the ephemeral table instead of an
106247 ** existing table. In this case, the creation and initialization of the
106248 ** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
106249 ** will be set on pX and the pX->y.sub fields will be set to show where
106250 ** the subroutine is coded.
106251 **
106252 ** The inFlags parameter must contain, at a minimum, one of the bits
106253 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106254 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106255 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106087,16 +106306,21 @@
106306 int *aiMap, /* Mapping from Index fields to RHS fields */
106307 int *piTab /* OUT: index to use */
106308 ){
106309 Select *p; /* SELECT to the right of IN operator */
106310 int eType = 0; /* Type of RHS table. IN_INDEX_* */
106311 int iTab; /* Cursor of the RHS table */
106312 int mustBeUnique; /* True if RHS must be unique */
106313 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106314
106315 assert( pX->op==TK_IN );
106316 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
106317 if( pX->iTable && (inFlags & IN_INDEX_REUSE_CUR)!=0 ){
106318 iTab = pX->iTable;
106319 }else{
106320 iTab = pParse->nTab++;
106321 }
106322
106323 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
106324 ** whether or not the SELECT result contains NULL values, check whether
106325 ** or not NULL is actually possible (it may not be, for example, due
106326 ** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106258,10 +106482,12 @@
106482 if( eType==0
106483 && (inFlags & IN_INDEX_NOOP_OK)
106484 && ExprUseXList(pX)
106485 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106486 ){
106487 pParse->nTab--; /* Back out the allocation of the unused cursor */
106488 iTab = -1; /* Cursor is not allocated */
106489 eType = IN_INDEX_NOOP;
106490 }
106491
106492 if( eType==0 ){
106493 /* Could not find an existing table or index to use as the RHS b-tree.
@@ -106424,11 +106650,13 @@
106650 pExpr->x.pSelect->selId));
106651 }
106652 assert( ExprUseYSub(pExpr) );
106653 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106654 pExpr->y.sub.iAddr);
106655 if( iTab!=pExpr->iTable ){
106656 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106657 }
106658 sqlite3VdbeJumpHere(v, addrOnce);
106659 return;
106660 }
106661
106662 /* Begin coding the subroutine */
@@ -108164,11 +108392,13 @@
108392 p = pParse->pConstExpr;
108393 if( regDest<0 && p ){
108394 struct ExprList_item *pItem;
108395 int i;
108396 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108397 if( pItem->fg.reusable
108398 && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108399 ){
108400 return pItem->u.iConstExprReg;
108401 }
108402 }
108403 }
108404 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108187,11 +108417,11 @@
108417 sqlite3VdbeJumpHere(v, addr);
108418 }else{
108419 p = sqlite3ExprListAppend(pParse, p, pExpr);
108420 if( p ){
108421 struct ExprList_item *pItem = &p->a[p->nExpr-1];
108422 pItem->fg.reusable = regDest<0;
108423 if( regDest<0 ) regDest = ++pParse->nMem;
108424 pItem->u.iConstExprReg = regDest;
108425 }
108426 pParse->pConstExpr = p;
108427 }
@@ -108321,11 +108551,11 @@
108551 n = pList->nExpr;
108552 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108553 for(pItem=pList->a, i=0; i<n; i++, pItem++){
108554 Expr *pExpr = pItem->pExpr;
108555 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
108556 if( pItem->fg.bSorterRef ){
108557 i--;
108558 n--;
108559 }else
108560 #endif
108561 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -108946,11 +109176,11 @@
109176 if( pA->nExpr!=pB->nExpr ) return 1;
109177 for(i=0; i<pA->nExpr; i++){
109178 int res;
109179 Expr *pExprA = pA->a[i].pExpr;
109180 Expr *pExprB = pB->a[i].pExpr;
109181 if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1;
109182 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
109183 }
109184 return 0;
109185 }
109186
@@ -110635,11 +110865,11 @@
110865 return WRC_Prune;
110866 }
110867 if( ALWAYS(p->pEList) ){
110868 ExprList *pList = p->pEList;
110869 for(i=0; i<pList->nExpr; i++){
110870 if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
110871 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110872 }
110873 }
110874 }
110875 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110684,11 +110914,11 @@
110914 memset(&sWalker, 0, sizeof(Walker));
110915 sWalker.pParse = pParse;
110916 sWalker.xExprCallback = renameUnmapExprCb;
110917 sqlite3WalkExprList(&sWalker, pEList);
110918 for(i=0; i<pEList->nExpr; i++){
110919 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
110920 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110921 }
110922 }
110923 }
110924 }
@@ -110842,11 +111072,11 @@
111072 ){
111073 if( pEList ){
111074 int i;
111075 for(i=0; i<pEList->nExpr; i++){
111076 const char *zName = pEList->a[i].zEName;
111077 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
111078 && ALWAYS(zName!=0)
111079 && 0==sqlite3_stricmp(zName, zOld)
111080 ){
111081 renameTokenFind(pParse, pCtx, (const void*)zName);
111082 }
@@ -112867,13 +113097,18 @@
113097 ** * the index contains 100 rows,
113098 ** * "WHERE a=?" matches 10 rows, and
113099 ** * "WHERE a=? AND b=?" matches 2 rows.
113100 **
113101 ** If D is the count of distinct values and K is the total number of
113102 ** rows, then each estimate is usually computed as:
113103 **
113104 ** I = (K+D-1)/D
113105 **
113106 ** In other words, I is K/D rounded up to the next whole integer.
113107 ** However, if I is between 1.0 and 1.1 (in other words if I is
113108 ** close to 1.0 but just a little larger) then do not round up but
113109 ** instead keep the I value at 1.0.
113110 */
113111 sqlite3_str sStat; /* Text of the constructed "stat" line */
113112 int i; /* Loop counter */
113113
113114 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -112880,10 +113115,11 @@
113115 sqlite3_str_appendf(&sStat, "%llu",
113116 p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
113117 for(i=0; i<p->nKeyCol; i++){
113118 u64 nDistinct = p->current.anDLt[i] + 1;
113119 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
113120 if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
113121 sqlite3_str_appendf(&sStat, " %llu", iVal);
113122 assert( p->current.anEq[i] );
113123 }
113124 sqlite3ResultStrAccum(context, &sStat);
113125 }
@@ -115001,13 +115237,11 @@
115237 Returning *pReturning = pParse->u1.pReturning;
115238 int addrRewind;
115239 int i;
115240 int reg;
115241
115242 if( pReturning->nRetCol ){
 
 
115243 sqlite3VdbeAddOp0(v, OP_FkCheck);
115244 addrRewind =
115245 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
115246 VdbeCoverage(v);
115247 reg = pReturning->iRetReg;
@@ -115099,13 +115333,11 @@
115333 }
115334 }
115335
115336 if( pParse->bReturning ){
115337 Returning *pRet = pParse->u1.pReturning;
115338 if( pRet->nRetCol ){
 
 
115339 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115340 }
115341 }
115342
115343 /* Finally, jump back to the beginning of the executable code. */
@@ -116723,11 +116955,11 @@
116955 }
116956 pTab->iPKey = iCol;
116957 pTab->keyConf = (u8)onError;
116958 assert( autoInc==0 || autoInc==1 );
116959 pTab->tabFlags |= autoInc*TF_Autoincrement;
116960 if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
116961 (void)sqlite3HasExplicitNulls(pParse, pList);
116962 }else if( autoInc ){
116963 #ifndef SQLITE_OMIT_AUTOINCREMENT
116964 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116965 "INTEGER PRIMARY KEY");
@@ -117217,11 +117449,11 @@
117449 return;
117450 }
117451 if( IN_RENAME_OBJECT ){
117452 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117453 }
117454 pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
117455 assert( pParse->pNewTable==pTab );
117456 pTab->iPKey = -1;
117457 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117458 SQLITE_IDXTYPE_PRIMARYKEY);
117459 if( pParse->nErr ){
@@ -117888,11 +118120,10 @@
118120 */
118121 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
118122 Table *pSelTab; /* A fake table from which we get the result set */
118123 Select *pSel; /* Copy of the SELECT that implements the view */
118124 int nErr = 0; /* Number of errors encountered */
 
118125 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
118126 #ifndef SQLITE_OMIT_VIRTUALTABLE
118127 int rc;
118128 #endif
118129 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -117946,12 +118177,13 @@
118177 */
118178 assert( IsView(pTable) );
118179 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
118180 if( pSel ){
118181 u8 eParseMode = pParse->eParseMode;
118182 int nTab = pParse->nTab;
118183 int nSelect = pParse->nSelect;
118184 pParse->eParseMode = PARSE_MODE_NORMAL;
 
118185 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
118186 pTable->nCol = -1;
118187 DisableLookaside;
118188 #ifndef SQLITE_OMIT_AUTHORIZATION
118189 xAuth = db->xAuth;
@@ -117959,11 +118191,12 @@
118191 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
118192 db->xAuth = xAuth;
118193 #else
118194 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
118195 #endif
118196 pParse->nTab = nTab;
118197 pParse->nSelect = nSelect;
118198 if( pSelTab==0 ){
118199 pTable->nCol = 0;
118200 nErr++;
118201 }else if( pTable->pCheck ){
118202 /* CREATE VIEW name(arglist) AS ...
@@ -118704,12 +118937,12 @@
118937 */
118938 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118939 if( pList ){
118940 int i;
118941 for(i=0; i<pList->nExpr; i++){
118942 if( pList->a[i].fg.bNulls ){
118943 u8 sf = pList->a[i].fg.sortFlags;
118944 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118945 (sf==0 || sf==3) ? "FIRST" : "LAST"
118946 );
118947 return 1;
118948 }
@@ -119058,11 +119291,11 @@
119291 if( !zColl ) zColl = sqlite3StrBINARY;
119292 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119293 goto exit_create_index;
119294 }
119295 pIndex->azColl[i] = zColl;
119296 requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
119297 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119298 }
119299
119300 /* Append the table key to the end of the index. For WITHOUT ROWID
119301 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -130380,15 +130613,23 @@
130613 sqlite3_total_changes64,
130614 /* Version 3.37.0 and later */
130615 sqlite3_autovacuum_pages,
130616 /* Version 3.38.0 and later */
130617 sqlite3_error_offset,
130618 #ifndef SQLITE_OMIT_VIRTUALTABLE
130619 sqlite3_vtab_rhs_value,
130620 sqlite3_vtab_distinct,
130621 sqlite3_vtab_in,
130622 sqlite3_vtab_in_first,
130623 sqlite3_vtab_in_next,
130624 #else
130625 0,
130626 0,
130627 0,
130628 0,
130629 0,
130630 #endif
130631 /* Version 3.39.0 and later */
130632 #ifndef SQLITE_OMIT_DESERIALIZE
130633 sqlite3_deserialize,
130634 sqlite3_serialize
130635 #else
@@ -134828,10 +135069,18 @@
135069 db->pParse = pParse;
135070 pParse->db = db;
135071 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
135072 }
135073
135074 /*
135075 ** Maximum number of times that we will try again to prepare a statement
135076 ** that returns SQLITE_ERROR_RETRY.
135077 */
135078 #ifndef SQLITE_MAX_PREPARE_RETRY
135079 # define SQLITE_MAX_PREPARE_RETRY 25
135080 #endif
135081
135082 /*
135083 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
135084 */
135085 static int sqlite3Prepare(
135086 sqlite3 *db, /* Database handle. */
@@ -135002,11 +135251,11 @@
135251 ** or encounters a permanent error. A schema problem after one schema
135252 ** reset is considered a permanent error. */
135253 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135254 assert( rc==SQLITE_OK || *ppStmt==0 );
135255 if( rc==SQLITE_OK || db->mallocFailed ) break;
135256 }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
135257 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135258 sqlite3BtreeLeaveAll(db);
135259 rc = sqlite3ApiExit(db, rc);
135260 assert( (rc&db->errMask)==rc );
135261 db->busyHandler.nBusy = 0;
@@ -135553,11 +135802,11 @@
135802 ExprList *pResults;
135803 assert( pItem->pSelect!=0 );
135804 pResults = pItem->pSelect->pEList;
135805 assert( pResults!=0 );
135806 assert( iCol>=0 && iCol<pResults->nExpr );
135807 pResults->a[iCol].fg.bUsed = 1;
135808 }
135809 }
135810
135811 /*
135812 ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136221,11 +136470,11 @@
136470 ** the row from table t1 is stored instead. Then, as records are extracted from
136471 ** the sorter to return to the user, the required value of bigblob is
136472 ** retrieved directly from table t1. If the values are very large, this
136473 ** can be more efficient than storing them directly in the sorter records.
136474 **
136475 ** The ExprList_item.fg.bSorterRef flag is set for each expression in pEList
136476 ** for which the sorter-reference optimization should be enabled.
136477 ** Additionally, the pSort->aDefer[] array is populated with entries
136478 ** for all cursors required to evaluate all selected expressions. Finally.
136479 ** output variable (*ppExtra) is set to an expression list containing
136480 ** expressions for all extra PK values that should be stored in the
@@ -136281,11 +136530,11 @@
136530 pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136531 pSort->aDefer[nDefer].nKey = nKey;
136532 nDefer++;
136533 }
136534 }
136535 pItem->fg.bSorterRef = 1;
136536 }
136537 }
136538 }
136539 pSort->nDefer = (u8)nDefer;
136540 *ppExtra = pExtra;
@@ -136412,11 +136661,11 @@
136661 ** from the sorter by the optimizations in this branch */
136662 pEList = p->pEList;
136663 for(i=0; i<pEList->nExpr; i++){
136664 if( pEList->a[i].u.x.iOrderByCol>0
136665 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136666 || pEList->a[i].fg.bSorterRef
136667 #endif
136668 ){
136669 nResultCol--;
136670 regOrig = 0;
136671 }
@@ -136774,11 +137023,11 @@
137023 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
137024 if( pInfo ){
137025 assert( sqlite3KeyInfoIsWriteable(pInfo) );
137026 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
137027 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
137028 pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
137029 }
137030 }
137031 return pInfo;
137032 }
137033
@@ -136913,11 +137162,11 @@
137162 iSortTab = iTab;
137163 bSeq = 1;
137164 }
137165 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137166 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137167 if( aOutEx[i].fg.bSorterRef ) continue;
137168 #endif
137169 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
137170 }
137171 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137172 if( pSort->nDefer ){
@@ -136950,11 +137199,11 @@
137199 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
137200 }
137201 #endif
137202 for(i=nColumn-1; i>=0; i--){
137203 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137204 if( aOutEx[i].fg.bSorterRef ){
137205 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
137206 }else
137207 #endif
137208 {
137209 int iRead;
@@ -137316,11 +137565,11 @@
137565
137566 assert( p!=0 );
137567 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137568 assert( p->op!=TK_COLUMN
137569 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137570 if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
137571 /* An AS clause always takes first priority */
137572 char *zName = pEList->a[i].zEName;
137573 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137574 }else if( srcName && p->op==TK_COLUMN ){
137575 char *zCol;
@@ -137402,13 +137651,14 @@
137651 *pnCol = nCol;
137652 *paCol = aCol;
137653
137654 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137655 struct ExprList_item *pX = &pEList->a[i];
137656 struct ExprList_item *pCollide;
137657 /* Get an appropriate name for the column
137658 */
137659 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
137660 /* If the column contains an "AS <name>" phrase, use <name> as the name */
137661 }else{
137662 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137663 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137664 pColExpr = pColExpr->pRight;
@@ -137438,11 +137688,14 @@
137688
137689 /* Make sure the column name is unique. If the name is not unique,
137690 ** append an integer to the name so that it becomes unique.
137691 */
137692 cnt = 0;
137693 while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
137694 if( pCollide->fg.bUsingTerm ){
137695 pCol->colFlags |= COLFLAG_NOEXPAND;
137696 }
137697 nName = sqlite3Strlen30(zName);
137698 if( nName>0 ){
137699 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137700 if( zName[j]==':' ) nName = j;
137701 }
@@ -137449,12 +137702,15 @@
137702 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137703 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137704 }
137705 pCol->zCnName = zName;
137706 pCol->hName = sqlite3StrIHash(zName);
137707 if( pX->fg.bNoExpand ){
137708 pCol->colFlags |= COLFLAG_NOEXPAND;
137709 }
137710 sqlite3ColumnPropertiesFromName(0, pCol);
137711 if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
137712 sqlite3OomFault(db);
137713 }
137714 }
137715 sqlite3HashClear(&ht);
137716 if( db->mallocFailed ){
@@ -137707,11 +137963,11 @@
137963 pOrderBy->a[i].pExpr =
137964 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137965 }
137966 assert( sqlite3KeyInfoIsWriteable(pRet) );
137967 pRet->aColl[i] = pColl;
137968 pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
137969 }
137970 }
137971
137972 return pRet;
137973 }
@@ -139375,10 +139631,12 @@
139631 ** See also (3) for restrictions on LEFT JOIN.
139632 **
139633 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139634 ** is the first element of the parent query.
139635 **
139636 ** (28) The subquery is not a MATERIALIZED CTE.
139637 **
139638 **
139639 ** In this routine, the "p" parameter is a pointer to the outer query.
139640 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139641 ** uses aggregates.
139642 **
@@ -139498,10 +139756,13 @@
139756
139757 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139758 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139759 return 0; /* Restriction (27) */
139760 }
139761 if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139762 return 0; /* (28) */
139763 }
139764
139765 /* Restriction (17): If the sub-query is a compound SELECT, then it must
139766 ** use only the UNION ALL operator. And none of the simple select queries
139767 ** that make up the compound SELECT are allowed to be aggregate or distinct
139768 ** queries.
@@ -139542,10 +139803,11 @@
139803 /* Restriction (23) */
139804 if( (p->selFlags & SF_Recursive) ) return 0;
139805
139806 if( pSrc->nSrc>1 ){
139807 if( pParse->nSelect>500 ) return 0;
139808 if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
139809 aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
139810 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
139811 }
139812 }
139813
@@ -140170,17 +140432,17 @@
140432 */
140433 static int pushDownWhereTerms(
140434 Parse *pParse, /* Parse context (for malloc() and error reporting) */
140435 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
140436 Expr *pWhere, /* The WHERE clause of the outer query */
140437 SrcItem *pSrc /* The subquery term of the outer FROM clause */
 
140438 ){
140439 Expr *pNew;
140440 int nChng = 0;
140441 if( pWhere==0 ) return 0;
140442 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
140443 if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0;
140444
140445 #ifndef SQLITE_OMIT_WINDOWFUNC
140446 if( pSubq->pPrior ){
140447 Select *pSel;
140448 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -140206,14 +140468,15 @@
140468
140469 if( pSubq->pLimit!=0 ){
140470 return 0; /* restriction (3) */
140471 }
140472 while( pWhere->op==TK_AND ){
140473 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
 
140474 pWhere = pWhere->pLeft;
140475 }
140476
140477 #if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
140478 if( isLeftJoin
140479 && (ExprHasProperty(pWhere,EP_FromJoin)==0
140480 || pWhere->w.iJoin!=iCursor)
140481 ){
140482 return 0; /* restriction (4) */
@@ -140221,20 +140484,22 @@
140484 if( ExprHasProperty(pWhere,EP_FromJoin)
140485 && pWhere->w.iJoin!=iCursor
140486 ){
140487 return 0; /* restriction (5) */
140488 }
140489 #endif
140490
140491 if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
140492 nChng++;
140493 pSubq->selFlags |= SF_PushDown;
140494 while( pSubq ){
140495 SubstContext x;
140496 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140497 unsetJoinExpr(pNew, -1);
140498 x.pParse = pParse;
140499 x.iTable = pSrc->iCursor;
140500 x.iNewTable = pSrc->iCursor;
140501 x.isOuterJoin = 0;
140502 x.pEList = pSubq->pEList;
140503 pNew = substExpr(&x, pNew);
140504 #ifndef SQLITE_OMIT_WINDOWFUNC
140505 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -140304,11 +140569,11 @@
140569 }else{
140570 return eRet;
140571 }
140572 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140573 assert( pOrderBy!=0 || db->mallocFailed );
140574 if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
140575 return eRet;
140576 }
140577
140578 /*
140579 ** The select statement passed as the first argument is an aggregate query.
@@ -140773,11 +141038,11 @@
141038 if( pTab==0 ) return SQLITE_NOMEM;
141039 pTab->nTabRef = 1;
141040 if( pFrom->zAlias ){
141041 pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
141042 }else{
141043 pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
141044 }
141045 while( pSel->pPrior ){ pSel = pSel->pPrior; }
141046 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
141047 pTab->iPKey = -1;
141048 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -141011,11 +141276,11 @@
141276 /* This particular expression does not need to be expanded.
141277 */
141278 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141279 if( pNew ){
141280 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141281 pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
141282 a[k].zEName = 0;
141283 }
141284 a[k].pExpr = 0;
141285 }else{
141286 /* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141026,39 +141291,64 @@
141291 assert( pE->pLeft!=0 );
141292 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
141293 zTName = pE->pLeft->u.zToken;
141294 }
141295 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
141296 Table *pTab = pFrom->pTab; /* Table for this data source */
141297 ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141298 char *zTabName; /* AS name for this data source */
141299 const char *zSchemaName = 0; /* Schema name for this data source */
141300 int iDb; /* Schema index for this data src */
141301 IdList *pUsing; /* USING clause for pFrom[1] */
141302
141303 if( (zTabName = pFrom->zAlias)==0 ){
141304 zTabName = pTab->zName;
141305 }
141306 if( db->mallocFailed ) break;
141307 assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141308 if( pFrom->fg.isNestedFrom ){
141309 assert( pFrom->pSelect!=0 );
141310 pNestedFrom = pFrom->pSelect->pEList;
141311 assert( pNestedFrom!=0 );
141312 assert( pNestedFrom->nExpr==pTab->nCol );
141313 }else{
 
141314 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
141315 continue;
141316 }
141317 pNestedFrom = 0;
141318 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141319 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
141320 }
141321 if( i+1<pTabList->nSrc
141322 && pFrom[1].fg.isUsing
141323 && (selFlags & SF_NestedFrom)!=0
141324 ){
141325 int ii;
141326 pUsing = pFrom[1].u3.pUsing;
141327 for(ii=0; ii<pUsing->nId; ii++){
141328 const char *zUName = pUsing->a[ii].zName;
141329 pRight = sqlite3Expr(db, TK_ID, zUName);
141330 pNew = sqlite3ExprListAppend(pParse, pNew, pRight);
141331 if( pNew ){
141332 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
141333 assert( pX->zEName==0 );
141334 pX->zEName = sqlite3MPrintf(db,"..%s", zUName);
141335 pX->fg.eEName = ENAME_TAB;
141336 pX->fg.bUsingTerm = 1;
141337 }
141338 }
141339 }else{
141340 pUsing = 0;
141341 }
141342 for(j=0; j<pTab->nCol; j++){
141343 char *zName = pTab->aCol[j].zCnName;
141344 struct ExprList_item *pX; /* Newly added ExprList term */
141345
141346 assert( zName );
141347 if( zTName
141348 && pNestedFrom
141349 && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0)==0
141350 ){
141351 continue;
141352 }
141353
141354 /* If a column is marked as 'hidden', omit it from the expanded
@@ -141067,14 +141357,20 @@
141357 */
141358 if( (p->selFlags & SF_IncludeHidden)==0
141359 && IsHiddenColumn(&pTab->aCol[j])
141360 ){
141361 continue;
141362 }
141363 if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141364 && zTName==0
141365 && (selFlags & (SF_NestedFrom))==0
141366 ){
141367 continue;
141368 }
141369 tableSeen = 1;
141370
141371 if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
141372 if( pFrom->fg.isUsing
141373 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141374 ){
141375 /* In a join with a USING clause, omit columns in the
141376 ** using clause from the table on the right. */
@@ -141082,10 +141378,11 @@
141378 }
141379 }
141380 pRight = sqlite3Expr(db, TK_ID, zName);
141381 if( (pTabList->nSrc>1
141382 && ( (pFrom->fg.jointype & JT_LTORJ)==0
141383 || (selFlags & SF_NestedFrom)!=0
141384 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141385 )
141386 )
141387 || IN_RENAME_OBJECT
141388 ){
@@ -141107,25 +141404,32 @@
141404 break; /* OOM */
141405 }
141406 pX = &pNew->a[pNew->nExpr-1];
141407 assert( pX->zEName==0 );
141408 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
141409 if( pNestedFrom ){
141410 pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
141411 testcase( pX->zEName==0 );
141412 }else{
141413 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141414 zSchemaName, zTabName, zName);
141415 testcase( pX->zEName==0 );
141416 }
141417 pX->fg.eEName = ENAME_TAB;
141418 if( (pFrom->fg.isUsing
141419 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
141420 || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
141421 || (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141422 ){
141423 pX->fg.bNoExpand = 1;
141424 }
141425 }else if( longNames ){
141426 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141427 pX->fg.eEName = ENAME_NAME;
141428 }else{
141429 pX->zEName = sqlite3DbStrDup(db, zName);
141430 pX->fg.eEName = ENAME_NAME;
141431 }
141432 }
141433 }
141434 if( !tableSeen ){
141435 if( zTName ){
@@ -142053,13 +142357,11 @@
142357 ** inside the subquery. This can help the subquery to run more efficiently.
142358 */
142359 if( OptimizationEnabled(db, SQLITE_PushDown)
142360 && (pItem->fg.isCte==0
142361 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
142362 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
 
 
142363 ){
142364 #if TREETRACE_ENABLED
142365 if( sqlite3TreeTrace & 0x100 ){
142366 SELECTTRACE(0x100,pParse,p,
142367 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -142251,17 +142553,17 @@
142553 if( pDest->eDest==SRT_EphemTab ){
142554 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142555 if( p->selFlags & SF_NestedFrom ){
142556 /* Delete or NULL-out result columns that will never be used */
142557 int ii;
142558 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
142559 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142560 sqlite3DbFree(db, pEList->a[ii].zEName);
142561 pEList->nExpr--;
142562 }
142563 for(ii=0; ii<pEList->nExpr; ii++){
142564 if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142565 }
142566 }
142567 }
142568
142569 /* Set the limiter.
@@ -142409,12 +142711,13 @@
142711 ** ASC or DESC order - only that each group is returned contiguously.
142712 ** So set the ASC/DESC flags in the GROUP BY to match those in the
142713 ** ORDER BY to maximize the chances of rows being delivered in an
142714 ** order that makes the ORDER BY redundant. */
142715 for(ii=0; ii<pGroupBy->nExpr; ii++){
142716 u8 sortFlags;
142717 sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
142718 pGroupBy->a[ii].fg.sortFlags = sortFlags;
142719 }
142720 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142721 orderByGrp = 1;
142722 }
142723 }
@@ -144065,20 +144368,20 @@
144368 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144369 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144370 if( !db->mallocFailed ){
144371 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144372 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144373 pItem->fg.eEName = ENAME_NAME;
144374 }
144375 }
144376 }else{
144377 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144378 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144379 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144380 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144381 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144382 pItem->fg.eEName = pList->a[i].fg.eEName;
144383 }
144384 }
144385 }
144386 return pNew;
144387 }
@@ -146647,10 +146950,11 @@
146950 #endif
146951 }
146952
146953 assert( rc==SQLITE_OK );
146954 if( pOut==0 ){
146955 nRes = sqlite3BtreeGetRequestedReserve(pTemp);
146956 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146957 }
146958
146959 end_of_vacuum:
146960 /* Restore the original value of db->flags */
@@ -148109,10 +148413,11 @@
148413 struct WhereRightJoin {
148414 int iMatch; /* Cursor used to determine prior matched rows */
148415 int regBloom; /* Bloom filter for iRJMatch */
148416 int regReturn; /* Return register for the interior subroutine */
148417 int addrSubrtn; /* Starting address for the interior subroutine */
148418 int endSubrtn; /* The last opcode in the interior subroutine */
148419 };
148420
148421 /*
148422 ** This object contains information needed to implement a single nested
148423 ** loop in WHERE clause.
@@ -149300,20 +149605,26 @@
149605
149606 iTab = 0;
149607 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149608 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149609 }else{
149610 Expr *pExpr = pTerm->pExpr;
149611 if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
149612 sqlite3 *db = pParse->db;
149613 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149614 if( !db->mallocFailed ){
149615 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149616 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
149617 pExpr->iTable = iTab;
149618 }
149619 sqlite3ExprDelete(db, pX);
149620 }else{
149621 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149622 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP|IN_INDEX_REUSE_CUR, 0, aiMap,&iTab);
149623 iTab = pExpr->iTable;
149624 }
149625 pX = pExpr;
 
149626 }
149627
149628 if( eType==IN_INDEX_INDEX_DESC ){
149629 testcase( bRev );
149630 bRev = !bRev;
@@ -149936,16 +150247,16 @@
150247 ** that contains the value of pExpr.
150248 */
150249 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
150250 IdxExprTrans *pX = p->u.pIdxTrans;
150251 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
150252 pExpr = sqlite3ExprSkipCollate(pExpr);
150253 preserveExpr(pX, pExpr);
150254 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
150255 pExpr->op = TK_COLUMN;
150256 pExpr->iTable = pX->iIdxCur;
150257 pExpr->iColumn = pX->iIdxCol;
 
150258 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
150259 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
150260 pExpr->y.pTab = 0;
150261 return WRC_Prune;
150262 }else{
@@ -150095,10 +150406,12 @@
150406 if( pLevel->regFilter==0 ) continue;
150407 if( pLevel->pWLoop->nSkip ) continue;
150408 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150409 ** vvvvv--' pLevel->regFilter if this were true. */
150410 if( NEVER(pLoop->prereq & notReady) ) continue;
150411 assert( pLevel->addrBrk==0 );
150412 pLevel->addrBrk = addrNxt;
150413 if( pLoop->wsFlags & WHERE_IPK ){
150414 WhereTerm *pTerm = pLoop->aLTerm[0];
150415 int regRowid;
150416 assert( pTerm!=0 );
150417 assert( pTerm->pExpr!=0 );
@@ -150121,10 +150434,11 @@
150434 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150435 addrNxt, r1, nEq);
150436 VdbeCoverage(pParse->pVdbe);
150437 }
150438 pLevel->regFilter = 0;
150439 pLevel->addrBrk = 0;
150440 }
150441 }
150442
150443 /*
150444 ** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151301,11 +151615,11 @@
151615 continue;
151616 }
151617 pE = pTerm->pExpr;
151618 assert( pE!=0 );
151619 if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151620 && !ExprHasProperty(pE,EP_FromJoin|EP_InnerJoin)
151621 ){
151622 continue;
151623 }
151624
151625 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -151508,10 +151822,12 @@
151822 SrcList sFrom;
151823 Bitmask mAll = 0;
151824 int k;
151825
151826 ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName));
151827 sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
151828 pRJ->regReturn);
151829 for(k=0; k<iLevel; k++){
151830 int iIdxCur;
151831 mAll |= pWInfo->a[k].pWLoop->maskSelf;
151832 sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur);
151833 iIdxCur = pWInfo->a[k].iIdxCur;
@@ -153190,11 +153506,11 @@
153506 if( pOrderBy ){
153507 for(ii=0; ii<pOrderBy->nExpr; ii++){
153508 Expr *pExpr = pOrderBy->a[ii].pExpr;
153509 if( pExpr->op!=TK_COLUMN ) return;
153510 if( pExpr->iTable!=iCsr ) return;
153511 if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153512 }
153513 }
153514
153515 /* All conditions are met. Add the terms to the where-clause object. */
153516 assert( p->pLimit->op==TK_LIMIT );
@@ -153516,11 +153832,11 @@
153832 ** continuation of the inner-most loop. */
153833 return pWInfo->iContinue;
153834 }
153835 pInner = &pWInfo->a[pWInfo->nLevel-1];
153836 assert( pInner->addrNxt!=0 );
153837 return pInner->pRJ ? pWInfo->iContinue : pInner->addrNxt;
153838 }
153839
153840 /*
153841 ** While generating code for the min/max optimization, after handling
153842 ** the aggregate-step call to min() or max(), check to see if any
@@ -154246,13 +154562,11 @@
154562 Expr *pExpr = pTerm->pExpr;
154563 /* Make the automatic index a partial index if there are terms in the
154564 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
154565 ** rows of the target table (pSrc) that can be used. */
154566 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154567 && sqlite3ExprIsTableConstraint(pExpr, pSrc)
 
 
154568 ){
154569 pPartial = sqlite3ExprAnd(pParse, pPartial,
154570 sqlite3ExprDup(pParse->db, pExpr, 0));
154571 }
154572 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -154487,11 +154801,11 @@
154801 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
154802 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
154803 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
154804 Expr *pExpr = pTerm->pExpr;
154805 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154806 && sqlite3ExprIsTableConstraint(pExpr, pItem)
154807 ){
154808 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
154809 }
154810 }
154811 if( pLoop->wsFlags & WHERE_IPK ){
@@ -154622,11 +154936,11 @@
154936 if( sqlite3ExprIsConstant(pExpr) ){
154937 continue;
154938 }
154939
154940 /* Virtual tables are unable to deal with NULLS FIRST */
154941 if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154942
154943 /* First case - a direct column references without a COLLATE operator */
154944 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154945 assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154946 continue;
@@ -154734,11 +155048,11 @@
155048 if( sqlite3ExprIsConstant(pExpr) ) continue;
155049 assert( pExpr->op==TK_COLUMN
155050 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
155051 && pExpr->iColumn==pExpr->pLeft->iColumn) );
155052 pIdxOrderBy[j].iColumn = pExpr->iColumn;
155053 pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
155054 j++;
155055 }
155056 pIdxInfo->nOrderBy = j;
155057
155058 *pmNoOmit = mNoOmit;
@@ -156252,11 +156566,11 @@
156566 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156567 ** be used by the right table of a LEFT JOIN nor by the left table of a
156568 ** RIGHT JOIN. Only constraints in the
156569 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156570 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156571 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin)
156572 ){
156573 continue;
156574 }
156575
156576 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157560,13 +157874,11 @@
157874 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157875 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157876 if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157877 /* This condition is true when pItem is the FROM clause term on the
157878 ** right-hand-side of a OUTER or CROSS JOIN. */
157879 mPrereq |= mPrior;
 
 
157880 }
157881 #ifndef SQLITE_OMIT_VIRTUALTABLE
157882 if( IsVirtual(pItem->pTab) ){
157883 SrcItem *p;
157884 for(p=&pItem[1]; p<pEnd; p++){
@@ -157873,20 +158185,22 @@
158185 }
158186 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
158187 /* Make sure the sort order is compatible in an ORDER BY clause.
158188 ** Sort order is irrelevant for a GROUP BY clause. */
158189 if( revSet ){
158190 if( (rev ^ revIdx)
158191 != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158192 ){
158193 isMatch = 0;
158194 }
158195 }else{
158196 rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
158197 if( rev ) *pRevMask |= MASKBIT(iLoop);
158198 revSet = 1;
158199 }
158200 }
158201 if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
158202 if( j==pLoop->u.btree.nEq ){
158203 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
158204 }else{
158205 isMatch = 0;
158206 }
@@ -159438,10 +159752,11 @@
159752 /* Terminate the subroutine that forms the interior of the loop of
159753 ** the RIGHT JOIN table */
159754 WhereRightJoin *pRJ = pLevel->pRJ;
159755 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
159756 pLevel->addrCont = 0;
159757 pRJ->endSubrtn = sqlite3VdbeCurrentAddr(v);
159758 sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1);
159759 VdbeCoverage(v);
159760 assert( pParse->withinRJSubrtn>0 );
159761 pParse->withinRJSubrtn--;
159762 }
@@ -160645,11 +160960,11 @@
160960 pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160961 pSub->u.zToken = 0;
160962 }
160963 }
160964 pList = sqlite3ExprListAppend(pParse, pList, pDup);
160965 if( pList ) pList->a[nInit+i].fg.sortFlags = pAppend->a[i].fg.sortFlags;
160966 }
160967 }
160968 return pList;
160969 }
160970
@@ -161846,11 +162161,11 @@
162161 windowReadPeerValues(p, csr1, reg1);
162162 windowReadPeerValues(p, csr2, reg2);
162163
162164 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
162165 assert( pOrderBy && pOrderBy->nExpr==1 );
162166 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
162167 switch( op ){
162168 case OP_Ge: op = OP_Le; break;
162169 case OP_Gt: op = OP_Lt; break;
162170 default: assert( op==OP_Le ); op = OP_Ge; break;
162171 }
@@ -161879,11 +162194,11 @@
162194 ** }
162195 **
162196 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
162197 ** not taken, control jumps over the comparison operator coded below this
162198 ** block. */
162199 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
162200 /* This block runs if reg1 contains a NULL. */
162201 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
162202 switch( op ){
162203 case OP_Ge:
162204 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -226663,11 +226978,11 @@
226978 /* State used by the fts5DataXXX() functions. */
226979 sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226980 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226981 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226982 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226983 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
226984 sqlite3_stmt *pIdxSelect;
226985 int nRead; /* Total number of blocks read */
226986
226987 sqlite3_stmt *pDataVersion;
226988 i64 iStructVersion; /* data_version when pStruct read */
@@ -235980,11 +236295,11 @@
236295 int nArg, /* Number of args */
236296 sqlite3_value **apUnused /* Function arguments */
236297 ){
236298 assert( nArg==0 );
236299 UNUSED_PARAM2(nArg, apUnused);
236300 sqlite3_result_text(pCtx, "fts5: 2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527", -1, SQLITE_TRANSIENT);
236301 }
236302
236303 /*
236304 ** Return true if zName is the extension on one of the shadow tables used
236305 ** by this module.
236306
--- 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.39.0"
150150
#define SQLITE_VERSION_NUMBER 3039000
151
-#define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
151
+#define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- 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.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- 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.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
+3 -1
--- src/add.c
+++ src/add.c
@@ -882,11 +882,13 @@
882882
}
883883
}
884884
db_finalize(&q);
885885
/* show command summary */
886886
fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
887
-
887
+ if(dryRunFlag!=0){
888
+ fossil_print("Dry-run mode: no changes were made.\n");
889
+ }
888890
db_end_transaction(dryRunFlag);
889891
}
890892
891893
/*
892894
** Rename a single file.
893895
--- src/add.c
+++ src/add.c
@@ -882,11 +882,13 @@
882 }
883 }
884 db_finalize(&q);
885 /* show command summary */
886 fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
887
 
 
888 db_end_transaction(dryRunFlag);
889 }
890
891 /*
892 ** Rename a single file.
893
--- src/add.c
+++ src/add.c
@@ -882,11 +882,13 @@
882 }
883 }
884 db_finalize(&q);
885 /* show command summary */
886 fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
887 if(dryRunFlag!=0){
888 fossil_print("Dry-run mode: no changes were made.\n");
889 }
890 db_end_transaction(dryRunFlag);
891 }
892
893 /*
894 ** Rename a single file.
895
+1 -1
--- src/alerts.c
+++ src/alerts.c
@@ -969,11 +969,11 @@
969969
** brackets. Examples: "[fossil-src]", "[sqlite-src]".
970970
*/
971971
/*
972972
** SETTING: email-renew-interval width=16
973973
** If this setting as an integer N that is 14 or greater then email
974
-** notification is suspected for subscriptions that have a "last contact
974
+** notification is suspended for subscriptions that have a "last contact
975975
** time" of more than N days ago. The "last contact time" is recorded
976976
** in the SUBSCRIBER.LASTCONTACT entry of the database. Logging in,
977977
** sending a forum post, editing a wiki page, changing subscription settings
978978
** at /alerts, or visiting /renew all update the last contact time.
979979
** If this setting is not an integer value or is less than 14 or undefined,
980980
--- src/alerts.c
+++ src/alerts.c
@@ -969,11 +969,11 @@
969 ** brackets. Examples: "[fossil-src]", "[sqlite-src]".
970 */
971 /*
972 ** SETTING: email-renew-interval width=16
973 ** If this setting as an integer N that is 14 or greater then email
974 ** notification is suspected for subscriptions that have a "last contact
975 ** time" of more than N days ago. The "last contact time" is recorded
976 ** in the SUBSCRIBER.LASTCONTACT entry of the database. Logging in,
977 ** sending a forum post, editing a wiki page, changing subscription settings
978 ** at /alerts, or visiting /renew all update the last contact time.
979 ** If this setting is not an integer value or is less than 14 or undefined,
980
--- src/alerts.c
+++ src/alerts.c
@@ -969,11 +969,11 @@
969 ** brackets. Examples: "[fossil-src]", "[sqlite-src]".
970 */
971 /*
972 ** SETTING: email-renew-interval width=16
973 ** If this setting as an integer N that is 14 or greater then email
974 ** notification is suspended for subscriptions that have a "last contact
975 ** time" of more than N days ago. The "last contact time" is recorded
976 ** in the SUBSCRIBER.LASTCONTACT entry of the database. Logging in,
977 ** sending a forum post, editing a wiki page, changing subscription settings
978 ** at /alerts, or visiting /renew all update the last contact time.
979 ** If this setting is not an integer value or is less than 14 or undefined,
980
+2 -4
--- src/db.c
+++ src/db.c
@@ -4368,14 +4368,12 @@
43684368
** which will cause the client to avoid generating a delta
43694369
** manifest.
43704370
*/
43714371
/*
43724372
** SETTING: proxy width=32 default=off
4373
-** URL of the HTTP proxy. If undefined or "off" then
4374
-** the "http_proxy" environment variable is consulted.
4375
-** If the http_proxy environment variable is undefined
4376
-** then a direct HTTP connection is used.
4373
+** URL of the HTTP proxy. If "system", the "http_proxy" environment variable is
4374
+** consulted. If undefined or "off", a direct HTTP connection is used.
43774375
*/
43784376
/*
43794377
** SETTING: redirect-to-https default=0 width=-1
43804378
** Specifies whether or not to redirect http:// requests to
43814379
** https:// URIs. A value of 0 (the default) means not to
43824380
--- src/db.c
+++ src/db.c
@@ -4368,14 +4368,12 @@
4368 ** which will cause the client to avoid generating a delta
4369 ** manifest.
4370 */
4371 /*
4372 ** SETTING: proxy width=32 default=off
4373 ** URL of the HTTP proxy. If undefined or "off" then
4374 ** the "http_proxy" environment variable is consulted.
4375 ** If the http_proxy environment variable is undefined
4376 ** then a direct HTTP connection is used.
4377 */
4378 /*
4379 ** SETTING: redirect-to-https default=0 width=-1
4380 ** Specifies whether or not to redirect http:// requests to
4381 ** https:// URIs. A value of 0 (the default) means not to
4382
--- src/db.c
+++ src/db.c
@@ -4368,14 +4368,12 @@
4368 ** which will cause the client to avoid generating a delta
4369 ** manifest.
4370 */
4371 /*
4372 ** SETTING: proxy width=32 default=off
4373 ** URL of the HTTP proxy. If "system", the "http_proxy" environment variable is
4374 ** consulted. If undefined or "off", a direct HTTP connection is used.
 
 
4375 */
4376 /*
4377 ** SETTING: redirect-to-https default=0 width=-1
4378 ** Specifies whether or not to redirect http:// requests to
4379 ** https:// URIs. A value of 0 (the default) means not to
4380
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
11781178
wellknown_notfound:
11791179
fossil_free(zPath);
11801180
webpage_notfound_error(0);
11811181
return;
11821182
}
1183
+
1184
+/*
1185
+** Return the OpenSSL version number being used. Space to hold
1186
+** this name is obtained from fossil_malloc() and should be
1187
+** freed by the caller.
1188
+*/
1189
+char *fossil_openssl_version(void){
1190
+#if defined(FOSSIL_ENABLE_SSL)
1191
+ return mprintf("%s (0x%09x)\n",
1192
+ SSLeay_version(SSLEAY_VERSION), OPENSSL_VERSION_NUMBER);
1193
+#else
1194
+ return mprintf("none");
1195
+#endif
1196
+}
11831197
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
1178 wellknown_notfound:
1179 fossil_free(zPath);
1180 webpage_notfound_error(0);
1181 return;
1182 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1183
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
1178 wellknown_notfound:
1179 fossil_free(zPath);
1180 webpage_notfound_error(0);
1181 return;
1182 }
1183
1184 /*
1185 ** Return the OpenSSL version number being used. Space to hold
1186 ** this name is obtained from fossil_malloc() and should be
1187 ** freed by the caller.
1188 */
1189 char *fossil_openssl_version(void){
1190 #if defined(FOSSIL_ENABLE_SSL)
1191 return mprintf("%s (0x%09x)\n",
1192 SSLeay_version(SSLEAY_VERSION), OPENSSL_VERSION_NUMBER);
1193 #else
1194 return mprintf("none");
1195 #endif
1196 }
1197
+3 -2
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138138
139139
struct Global {
140140
int argc; char **argv; /* Command-line arguments to the program */
141141
char *nameOfExe; /* Full path of executable. */
142142
const char *zErrlog; /* Log errors to this file, if not NULL */
143
- const char *zPhase; /* Phase of operation, for use by the error log */
143
+ const char *zPhase; /* Phase of operation, for use by the error log
144
+ ** and for deriving $canonical_page TH1 variable */
144145
int isConst; /* True if the output is unchanging & cacheable */
145146
const char *zVfsName; /* The VFS to use for database connections */
146147
sqlite3 *db; /* The connection to the databases */
147148
sqlite3 *dbConfig; /* Separate connection for global_config table */
148149
char *zAuxSchema; /* Main repository aux-schema */
@@ -176,11 +177,11 @@
176177
int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
177178
char *zSshCmd; /* SSH command string */
178179
const char *zHttpCmd; /* External program to do HTTP requests */
179180
int fNoSync; /* Do not do an autosync ever. --nosync */
180181
int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
181
- char *zPath; /* Name of webpage being served */
182
+ char *zPath; /* Name of webpage being served (may be NULL) */
182183
char *zExtra; /* Extra path information past the webpage name */
183184
char *zBaseURL; /* Full text of the URL being served */
184185
char *zHttpsURL; /* zBaseURL translated to https: */
185186
char *zTop; /* Parent directory of zPath */
186187
int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
187188
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log */
 
144 int isConst; /* True if the output is unchanging & cacheable */
145 const char *zVfsName; /* The VFS to use for database connections */
146 sqlite3 *db; /* The connection to the databases */
147 sqlite3 *dbConfig; /* Separate connection for global_config table */
148 char *zAuxSchema; /* Main repository aux-schema */
@@ -176,11 +177,11 @@
176 int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
177 char *zSshCmd; /* SSH command string */
178 const char *zHttpCmd; /* External program to do HTTP requests */
179 int fNoSync; /* Do not do an autosync ever. --nosync */
180 int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
181 char *zPath; /* Name of webpage being served */
182 char *zExtra; /* Extra path information past the webpage name */
183 char *zBaseURL; /* Full text of the URL being served */
184 char *zHttpsURL; /* zBaseURL translated to https: */
185 char *zTop; /* Parent directory of zPath */
186 int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
187
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log
144 ** and for deriving $canonical_page TH1 variable */
145 int isConst; /* True if the output is unchanging & cacheable */
146 const char *zVfsName; /* The VFS to use for database connections */
147 sqlite3 *db; /* The connection to the databases */
148 sqlite3 *dbConfig; /* Separate connection for global_config table */
149 char *zAuxSchema; /* Main repository aux-schema */
@@ -176,11 +177,11 @@
177 int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
178 char *zSshCmd; /* SSH command string */
179 const char *zHttpCmd; /* External program to do HTTP requests */
180 int fNoSync; /* Do not do an autosync ever. --nosync */
181 int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
182 char *zPath; /* Name of webpage being served (may be NULL) */
183 char *zExtra; /* Extra path information past the webpage name */
184 char *zBaseURL; /* Full text of the URL being served */
185 char *zHttpsURL; /* zBaseURL translated to https: */
186 char *zTop; /* Parent directory of zPath */
187 int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
188
--- src/schema.c
+++ src/schema.c
@@ -458,10 +458,11 @@
458458
@ CREATE TABLE ticketchng(
459459
@ -- Do not change any column that begins with tkt_
460460
@ tkt_id INTEGER REFERENCES ticket,
461461
@ tkt_rid INTEGER REFERENCES blob,
462462
@ tkt_mtime DATE,
463
+@ tkt_user TEXT,
463464
@ -- Add as many fields as required below this line
464465
@ login TEXT,
465466
@ username TEXT,
466467
@ mimetype TEXT,
467468
@ icomment TEXT
468469
--- src/schema.c
+++ src/schema.c
@@ -458,10 +458,11 @@
458 @ CREATE TABLE ticketchng(
459 @ -- Do not change any column that begins with tkt_
460 @ tkt_id INTEGER REFERENCES ticket,
461 @ tkt_rid INTEGER REFERENCES blob,
462 @ tkt_mtime DATE,
 
463 @ -- Add as many fields as required below this line
464 @ login TEXT,
465 @ username TEXT,
466 @ mimetype TEXT,
467 @ icomment TEXT
468
--- src/schema.c
+++ src/schema.c
@@ -458,10 +458,11 @@
458 @ CREATE TABLE ticketchng(
459 @ -- Do not change any column that begins with tkt_
460 @ tkt_id INTEGER REFERENCES ticket,
461 @ tkt_rid INTEGER REFERENCES blob,
462 @ tkt_mtime DATE,
463 @ tkt_user TEXT,
464 @ -- Add as many fields as required below this line
465 @ login TEXT,
466 @ username TEXT,
467 @ mimetype TEXT,
468 @ icomment TEXT
469
+8
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280280
@ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281281
@ </td></tr>
282282
@ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283283
@ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284284
@ <a href='version?verbose'>(details)</a></td></tr>
285
+ if( g.perm.Admin ){
286
+ const char *zCgi = P("SERVER_SOFTWARE");
287
+ @ <tr><th>OpenSSL&nbsp;Version:</th>
288
+ @ <td>%z(fossil_openssl_version())</td></tr>
289
+ if( zCgi ){
290
+ @ <tr><th>Web&nbsp;Server:</th><td>%s(zCgi)</td></tr>
291
+ }
292
+ }
285293
if( g.eHashPolicy!=HPOLICY_AUTO ){
286294
@ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
287295
@ %s(hpolicy_name())</td></tr>
288296
}else{
289297
@ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
290298
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280 @ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281 @ </td></tr>
282 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283 @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284 @ <a href='version?verbose'>(details)</a></td></tr>
 
 
 
 
 
 
 
 
285 if( g.eHashPolicy!=HPOLICY_AUTO ){
286 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
287 @ %s(hpolicy_name())</td></tr>
288 }else{
289 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
290
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280 @ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281 @ </td></tr>
282 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283 @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284 @ <a href='version?verbose'>(details)</a></td></tr>
285 if( g.perm.Admin ){
286 const char *zCgi = P("SERVER_SOFTWARE");
287 @ <tr><th>OpenSSL&nbsp;Version:</th>
288 @ <td>%z(fossil_openssl_version())</td></tr>
289 if( zCgi ){
290 @ <tr><th>Web&nbsp;Server:</th><td>%s(zCgi)</td></tr>
291 }
292 }
293 if( g.eHashPolicy!=HPOLICY_AUTO ){
294 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
295 @ %s(hpolicy_name())</td></tr>
296 }else{
297 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
298
+11 -2
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647647
** prepended.
648648
*/
649649
static const char zDfltHeader[] =
650650
@ <html>
651651
@ <head>
652
-@ <base href="$baseurl/$current_page" />
653652
@ <meta charset="UTF-8">
653
+@ <base href="$baseurl/$current_page" />
654654
@ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655655
@ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656656
@ <title>$<project_name>: $<title></title>
657657
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658658
@ href="$home/timeline.rss" />
659659
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660660
@ </head>
661
-@ <body class="$current_feature">
661
+@ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662662
;
663663
664664
/*
665665
** Returns the default page header.
666666
*/
@@ -769,10 +769,19 @@
769769
Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770770
Th_Store("home", g.zTop);
771771
Th_Store("index_page", db_get("index-page","/home"));
772772
if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773773
Th_Store("current_page", local_zCurrentPage);
774
+ if( g.zPath ){ /* store the first segment of a path; */
775
+ char *pSlash = strchr(g.zPath,'/');
776
+ if( pSlash ) *pSlash = 0; /* make a temporary cut if necessary */
777
+ Th_Store("requested_page", escape_quotes(g.zPath));
778
+ if( pSlash ) *pSlash = '/';
779
+ }else{
780
+ Th_Store("requested_page", "");
781
+ }
782
+ Th_Store("canonical_page", escape_quotes(g.zPhase+1));
774783
Th_Store("csrf_token", g.zCsrfToken);
775784
Th_Store("release_version", RELEASE_VERSION);
776785
Th_Store("manifest_version", MANIFEST_VERSION);
777786
Th_Store("manifest_date", MANIFEST_DATE);
778787
Th_Store("compiler_name", COMPILER_NAME);
779788
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
652 @ <base href="$baseurl/$current_page" />
653 @ <meta charset="UTF-8">
 
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -769,10 +769,19 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
 
 
 
 
 
 
 
 
 
774 Th_Store("csrf_token", g.zCsrfToken);
775 Th_Store("release_version", RELEASE_VERSION);
776 Th_Store("manifest_version", MANIFEST_VERSION);
777 Th_Store("manifest_date", MANIFEST_DATE);
778 Th_Store("compiler_name", COMPILER_NAME);
779
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
 
652 @ <meta charset="UTF-8">
653 @ <base href="$baseurl/$current_page" />
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -769,10 +769,19 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
774 if( g.zPath ){ /* store the first segment of a path; */
775 char *pSlash = strchr(g.zPath,'/');
776 if( pSlash ) *pSlash = 0; /* make a temporary cut if necessary */
777 Th_Store("requested_page", escape_quotes(g.zPath));
778 if( pSlash ) *pSlash = '/';
779 }else{
780 Th_Store("requested_page", "");
781 }
782 Th_Store("canonical_page", escape_quotes(g.zPhase+1));
783 Th_Store("csrf_token", g.zCsrfToken);
784 Th_Store("release_version", RELEASE_VERSION);
785 Th_Store("manifest_version", MANIFEST_VERSION);
786 Th_Store("manifest_date", MANIFEST_DATE);
787 Th_Store("compiler_name", COMPILER_NAME);
788
+9 -3
--- src/sync.c
+++ src/sync.c
@@ -24,16 +24,22 @@
2424
/*
2525
** Explain what type of sync operation is about to occur
2626
*/
2727
static void sync_explain(unsigned syncFlags){
2828
if( g.url.isAlias ){
29
+ const char *url;
30
+ if( g.url.useProxy ){
31
+ url = g.url.proxyUrlCanonical;
32
+ }else{
33
+ url = g.url.canonical;
34
+ }
2935
if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
30
- fossil_print("Sync with %s\n", g.url.canonical);
36
+ fossil_print("Sync with %s\n", url);
3137
}else if( syncFlags & SYNC_PUSH ){
32
- fossil_print("Push to %s\n", g.url.canonical);
38
+ fossil_print("Push to %s\n", url);
3339
}else if( syncFlags & SYNC_PULL ){
34
- fossil_print("Pull from %s\n", g.url.canonical);
40
+ fossil_print("Pull from %s\n", url);
3541
}
3642
}
3743
}
3844
3945
4046
--- src/sync.c
+++ src/sync.c
@@ -24,16 +24,22 @@
24 /*
25 ** Explain what type of sync operation is about to occur
26 */
27 static void sync_explain(unsigned syncFlags){
28 if( g.url.isAlias ){
 
 
 
 
 
 
29 if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
30 fossil_print("Sync with %s\n", g.url.canonical);
31 }else if( syncFlags & SYNC_PUSH ){
32 fossil_print("Push to %s\n", g.url.canonical);
33 }else if( syncFlags & SYNC_PULL ){
34 fossil_print("Pull from %s\n", g.url.canonical);
35 }
36 }
37 }
38
39
40
--- src/sync.c
+++ src/sync.c
@@ -24,16 +24,22 @@
24 /*
25 ** Explain what type of sync operation is about to occur
26 */
27 static void sync_explain(unsigned syncFlags){
28 if( g.url.isAlias ){
29 const char *url;
30 if( g.url.useProxy ){
31 url = g.url.proxyUrlCanonical;
32 }else{
33 url = g.url.canonical;
34 }
35 if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
36 fossil_print("Sync with %s\n", url);
37 }else if( syncFlags & SYNC_PUSH ){
38 fossil_print("Push to %s\n", url);
39 }else if( syncFlags & SYNC_PULL ){
40 fossil_print("Pull from %s\n", url);
41 }
42 }
43 }
44
45
46
+4 -3
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524524
@ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525525
}else if( zCom[0]==':' ){
526526
@ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527527
@ %h(zCom+1)</a>"
528528
}else{
529
- /* Legacy EVENT table entry that needs to be rebuilt */
530
- @ Changes to a wiki page &rarr; Obsolete EVENT table information.
531
- @ Run "fossil rebuild" on the repository.
529
+ /* Assume this is an attachment message. It _might_ also
530
+ ** be a legacy-format wiki log entry, in which case it
531
+ ** will simply be rendered in the older format. */
532
+ wiki_convert(&comment, 0, WIKI_INLINE);
532533
}
533534
wiki_hyperlink_override(0);
534535
}else{
535536
wiki_convert(&comment, 0, WIKI_INLINE);
536537
}
537538
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524 @ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525 }else if( zCom[0]==':' ){
526 @ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527 @ %h(zCom+1)</a>"
528 }else{
529 /* Legacy EVENT table entry that needs to be rebuilt */
530 @ Changes to a wiki page &rarr; Obsolete EVENT table information.
531 @ Run "fossil rebuild" on the repository.
 
532 }
533 wiki_hyperlink_override(0);
534 }else{
535 wiki_convert(&comment, 0, WIKI_INLINE);
536 }
537
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524 @ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525 }else if( zCom[0]==':' ){
526 @ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527 @ %h(zCom+1)</a>"
528 }else{
529 /* Assume this is an attachment message. It _might_ also
530 ** be a legacy-format wiki log entry, in which case it
531 ** will simply be rendered in the older format. */
532 wiki_convert(&comment, 0, WIKI_INLINE);
533 }
534 wiki_hyperlink_override(0);
535 }else{
536 wiki_convert(&comment, 0, WIKI_INLINE);
537 }
538
+22 -17
--- src/tkt.c
+++ src/tkt.c
@@ -23,11 +23,11 @@
2323
#include <assert.h>
2424
2525
/*
2626
** The list of database user-defined fields in the TICKET table.
2727
** The real table also contains some addition fields for internal
28
-** used. The internal-use fields begin with "tkt_".
28
+** use. The internal-use fields begin with "tkt_".
2929
*/
3030
static int nField = 0;
3131
static struct tktFieldInfo {
3232
char *zName; /* Name of the database field */
3333
char *zValue; /* Value to store */
@@ -39,10 +39,11 @@
3939
#define USEDBY_BOTH 03
4040
static u8 haveTicket = 0; /* True if the TICKET table exists */
4141
static u8 haveTicketCTime = 0; /* True if TICKET.TKT_CTIME exists */
4242
static u8 haveTicketChng = 0; /* True if the TICKETCHNG table exists */
4343
static u8 haveTicketChngRid = 0; /* True if TICKETCHNG.TKT_RID exists */
44
+static u8 haveTicketChngUser = 0;/* True if TICKETCHNG.TKT_USER exists */
4445
4546
/*
4647
** Compare two entries in aField[] for sorting purposes
4748
*/
4849
static int nameCmpr(const void *a, const void *b){
@@ -94,11 +95,15 @@
9495
db_prepare(&q, "PRAGMA table_info(ticketchng)");
9596
while( db_step(&q)==SQLITE_ROW ){
9697
const char *zFieldName = db_column_text(&q, 1);
9798
haveTicketChng = 1;
9899
if( memcmp(zFieldName,"tkt_",4)==0 ){
99
- if( strcmp(zFieldName,"tkt_rid")==0 ) haveTicketChngRid = 1;
100
+ if( strcmp(zFieldName+4,"rid")==0 ){
101
+ haveTicketChngRid = 1; /* tkt_rid */
102
+ }else if( strcmp(zFieldName+4,"user")==0 ){
103
+ haveTicketChngUser = 1; /* tkt_user */
104
+ }
100105
continue;
101106
}
102107
if( (i = fieldId(zFieldName))>=0 ){
103108
aField[i].mUsed |= USEDBY_TICKETCHNG;
104109
continue;
@@ -190,11 +195,13 @@
190195
** Parameter rid is the recordID for the ticket artifact in the BLOB table.
191196
**
192197
** Return the new rowid of the TICKET table entry.
193198
*/
194199
static int ticket_insert(const Manifest *p, int rid, int tktid){
195
- Blob sql1, sql2, sql3;
200
+ Blob sql1; /* update or replace TICKET ... */
201
+ Blob sql2; /* list of TICKETCHNG's fields that are in the manifest */
202
+ Blob sql3; /* list of values which correspond to the previous list */
196203
Stmt q;
197204
int i, j;
198205
char *aUsed;
199206
const char *zMimetype = 0;
200207
@@ -211,31 +218,25 @@
211218
blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)");
212219
}
213220
aUsed = fossil_malloc( nField );
214221
memset(aUsed, 0, nField);
215222
for(i=0; i<p->nField; i++){
216
- const char *zName = p->aField[i].zName;
217
- const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
223
+ const char * const zName = p->aField[i].zName;
224
+ const char * const zBaseName = zName[0]=='+' ? zName+1 : zName;
218225
j = fieldId(zBaseName);
219226
if( j<0 ) continue;
220227
aUsed[j] = 1;
221228
if( aField[j].mUsed & USEDBY_TICKET ){
222
- const char *zUsedByName = zName;
223
- if( zUsedByName[0]=='+' ){
224
- zUsedByName++;
229
+ if( zName[0]=='+' ){
225230
blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q",
226
- zUsedByName, zUsedByName, p->aField[i].zValue);
231
+ zBaseName, zBaseName, p->aField[i].zValue);
227232
}else{
228
- blob_append_sql(&sql1,", \"%w\"=%Q", zUsedByName, p->aField[i].zValue);
233
+ blob_append_sql(&sql1,", \"%w\"=%Q", zBaseName, p->aField[i].zValue);
229234
}
230235
}
231236
if( aField[j].mUsed & USEDBY_TICKETCHNG ){
232
- const char *zUsedByName = zName;
233
- if( zUsedByName[0]=='+' ){
234
- zUsedByName++;
235
- }
236
- blob_append_sql(&sql2, ",\"%w\"", zUsedByName);
237
+ blob_append_sql(&sql2, ",\"%w\"", zBaseName);
237238
blob_append_sql(&sql3, ",%Q", p->aField[i].zValue);
238239
}
239240
if( strcmp(zBaseName,"mimetype")==0 ){
240241
zMimetype = p->aField[i].zValue;
241242
}
@@ -254,16 +255,20 @@
254255
db_prepare(&q, "%s", blob_sql_text(&sql1));
255256
db_bind_double(&q, ":mtime", p->rDate);
256257
db_step(&q);
257258
db_finalize(&q);
258259
blob_reset(&sql1);
259
- if( blob_size(&sql2)>0 || haveTicketChngRid ){
260
+ if( blob_size(&sql2)>0 || haveTicketChngRid || haveTicketChngUser ){
260261
int fromTkt = 0;
261262
if( haveTicketChngRid ){
262
- blob_append(&sql2, ",tkt_rid", -1);
263
+ blob_append_literal(&sql2, ",tkt_rid");
263264
blob_append_sql(&sql3, ",%d", rid);
264265
}
266
+ if( haveTicketChngUser && p->zUser ){
267
+ blob_append_literal(&sql2, ",tkt_user");
268
+ blob_append_sql(&sql3, ",%Q", p->zUser);
269
+ }
265270
for(i=0; i<nField; i++){
266271
if( aUsed[i]==0
267272
&& (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH
268273
){
269274
const char *z = aField[i].zName;
270275
--- src/tkt.c
+++ src/tkt.c
@@ -23,11 +23,11 @@
23 #include <assert.h>
24
25 /*
26 ** The list of database user-defined fields in the TICKET table.
27 ** The real table also contains some addition fields for internal
28 ** used. The internal-use fields begin with "tkt_".
29 */
30 static int nField = 0;
31 static struct tktFieldInfo {
32 char *zName; /* Name of the database field */
33 char *zValue; /* Value to store */
@@ -39,10 +39,11 @@
39 #define USEDBY_BOTH 03
40 static u8 haveTicket = 0; /* True if the TICKET table exists */
41 static u8 haveTicketCTime = 0; /* True if TICKET.TKT_CTIME exists */
42 static u8 haveTicketChng = 0; /* True if the TICKETCHNG table exists */
43 static u8 haveTicketChngRid = 0; /* True if TICKETCHNG.TKT_RID exists */
 
44
45 /*
46 ** Compare two entries in aField[] for sorting purposes
47 */
48 static int nameCmpr(const void *a, const void *b){
@@ -94,11 +95,15 @@
94 db_prepare(&q, "PRAGMA table_info(ticketchng)");
95 while( db_step(&q)==SQLITE_ROW ){
96 const char *zFieldName = db_column_text(&q, 1);
97 haveTicketChng = 1;
98 if( memcmp(zFieldName,"tkt_",4)==0 ){
99 if( strcmp(zFieldName,"tkt_rid")==0 ) haveTicketChngRid = 1;
 
 
 
 
100 continue;
101 }
102 if( (i = fieldId(zFieldName))>=0 ){
103 aField[i].mUsed |= USEDBY_TICKETCHNG;
104 continue;
@@ -190,11 +195,13 @@
190 ** Parameter rid is the recordID for the ticket artifact in the BLOB table.
191 **
192 ** Return the new rowid of the TICKET table entry.
193 */
194 static int ticket_insert(const Manifest *p, int rid, int tktid){
195 Blob sql1, sql2, sql3;
 
 
196 Stmt q;
197 int i, j;
198 char *aUsed;
199 const char *zMimetype = 0;
200
@@ -211,31 +218,25 @@
211 blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)");
212 }
213 aUsed = fossil_malloc( nField );
214 memset(aUsed, 0, nField);
215 for(i=0; i<p->nField; i++){
216 const char *zName = p->aField[i].zName;
217 const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
218 j = fieldId(zBaseName);
219 if( j<0 ) continue;
220 aUsed[j] = 1;
221 if( aField[j].mUsed & USEDBY_TICKET ){
222 const char *zUsedByName = zName;
223 if( zUsedByName[0]=='+' ){
224 zUsedByName++;
225 blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q",
226 zUsedByName, zUsedByName, p->aField[i].zValue);
227 }else{
228 blob_append_sql(&sql1,", \"%w\"=%Q", zUsedByName, p->aField[i].zValue);
229 }
230 }
231 if( aField[j].mUsed & USEDBY_TICKETCHNG ){
232 const char *zUsedByName = zName;
233 if( zUsedByName[0]=='+' ){
234 zUsedByName++;
235 }
236 blob_append_sql(&sql2, ",\"%w\"", zUsedByName);
237 blob_append_sql(&sql3, ",%Q", p->aField[i].zValue);
238 }
239 if( strcmp(zBaseName,"mimetype")==0 ){
240 zMimetype = p->aField[i].zValue;
241 }
@@ -254,16 +255,20 @@
254 db_prepare(&q, "%s", blob_sql_text(&sql1));
255 db_bind_double(&q, ":mtime", p->rDate);
256 db_step(&q);
257 db_finalize(&q);
258 blob_reset(&sql1);
259 if( blob_size(&sql2)>0 || haveTicketChngRid ){
260 int fromTkt = 0;
261 if( haveTicketChngRid ){
262 blob_append(&sql2, ",tkt_rid", -1);
263 blob_append_sql(&sql3, ",%d", rid);
264 }
 
 
 
 
265 for(i=0; i<nField; i++){
266 if( aUsed[i]==0
267 && (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH
268 ){
269 const char *z = aField[i].zName;
270
--- src/tkt.c
+++ src/tkt.c
@@ -23,11 +23,11 @@
23 #include <assert.h>
24
25 /*
26 ** The list of database user-defined fields in the TICKET table.
27 ** The real table also contains some addition fields for internal
28 ** use. The internal-use fields begin with "tkt_".
29 */
30 static int nField = 0;
31 static struct tktFieldInfo {
32 char *zName; /* Name of the database field */
33 char *zValue; /* Value to store */
@@ -39,10 +39,11 @@
39 #define USEDBY_BOTH 03
40 static u8 haveTicket = 0; /* True if the TICKET table exists */
41 static u8 haveTicketCTime = 0; /* True if TICKET.TKT_CTIME exists */
42 static u8 haveTicketChng = 0; /* True if the TICKETCHNG table exists */
43 static u8 haveTicketChngRid = 0; /* True if TICKETCHNG.TKT_RID exists */
44 static u8 haveTicketChngUser = 0;/* True if TICKETCHNG.TKT_USER exists */
45
46 /*
47 ** Compare two entries in aField[] for sorting purposes
48 */
49 static int nameCmpr(const void *a, const void *b){
@@ -94,11 +95,15 @@
95 db_prepare(&q, "PRAGMA table_info(ticketchng)");
96 while( db_step(&q)==SQLITE_ROW ){
97 const char *zFieldName = db_column_text(&q, 1);
98 haveTicketChng = 1;
99 if( memcmp(zFieldName,"tkt_",4)==0 ){
100 if( strcmp(zFieldName+4,"rid")==0 ){
101 haveTicketChngRid = 1; /* tkt_rid */
102 }else if( strcmp(zFieldName+4,"user")==0 ){
103 haveTicketChngUser = 1; /* tkt_user */
104 }
105 continue;
106 }
107 if( (i = fieldId(zFieldName))>=0 ){
108 aField[i].mUsed |= USEDBY_TICKETCHNG;
109 continue;
@@ -190,11 +195,13 @@
195 ** Parameter rid is the recordID for the ticket artifact in the BLOB table.
196 **
197 ** Return the new rowid of the TICKET table entry.
198 */
199 static int ticket_insert(const Manifest *p, int rid, int tktid){
200 Blob sql1; /* update or replace TICKET ... */
201 Blob sql2; /* list of TICKETCHNG's fields that are in the manifest */
202 Blob sql3; /* list of values which correspond to the previous list */
203 Stmt q;
204 int i, j;
205 char *aUsed;
206 const char *zMimetype = 0;
207
@@ -211,31 +218,25 @@
218 blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)");
219 }
220 aUsed = fossil_malloc( nField );
221 memset(aUsed, 0, nField);
222 for(i=0; i<p->nField; i++){
223 const char * const zName = p->aField[i].zName;
224 const char * const zBaseName = zName[0]=='+' ? zName+1 : zName;
225 j = fieldId(zBaseName);
226 if( j<0 ) continue;
227 aUsed[j] = 1;
228 if( aField[j].mUsed & USEDBY_TICKET ){
229 if( zName[0]=='+' ){
 
 
230 blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q",
231 zBaseName, zBaseName, p->aField[i].zValue);
232 }else{
233 blob_append_sql(&sql1,", \"%w\"=%Q", zBaseName, p->aField[i].zValue);
234 }
235 }
236 if( aField[j].mUsed & USEDBY_TICKETCHNG ){
237 blob_append_sql(&sql2, ",\"%w\"", zBaseName);
 
 
 
 
238 blob_append_sql(&sql3, ",%Q", p->aField[i].zValue);
239 }
240 if( strcmp(zBaseName,"mimetype")==0 ){
241 zMimetype = p->aField[i].zValue;
242 }
@@ -254,16 +255,20 @@
255 db_prepare(&q, "%s", blob_sql_text(&sql1));
256 db_bind_double(&q, ":mtime", p->rDate);
257 db_step(&q);
258 db_finalize(&q);
259 blob_reset(&sql1);
260 if( blob_size(&sql2)>0 || haveTicketChngRid || haveTicketChngUser ){
261 int fromTkt = 0;
262 if( haveTicketChngRid ){
263 blob_append_literal(&sql2, ",tkt_rid");
264 blob_append_sql(&sql3, ",%d", rid);
265 }
266 if( haveTicketChngUser && p->zUser ){
267 blob_append_literal(&sql2, ",tkt_user");
268 blob_append_sql(&sql3, ",%Q", p->zUser);
269 }
270 for(i=0; i<nField; i++){
271 if( aUsed[i]==0
272 && (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH
273 ){
274 const char *z = aField[i].zName;
275
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -86,10 +86,11 @@
8686
@ CREATE TABLE ticketchng(
8787
@ -- Do not change any column that begins with tkt_
8888
@ tkt_id INTEGER REFERENCES ticket,
8989
@ tkt_rid INTEGER REFERENCES blob,
9090
@ tkt_mtime DATE,
91
+@ tkt_user TEXT,
9192
@ -- Add as many fields as required below this line
9293
@ login TEXT,
9394
@ username TEXT,
9495
@ mimetype TEXT,
9596
@ icomment TEXT
9697
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -86,10 +86,11 @@
86 @ CREATE TABLE ticketchng(
87 @ -- Do not change any column that begins with tkt_
88 @ tkt_id INTEGER REFERENCES ticket,
89 @ tkt_rid INTEGER REFERENCES blob,
90 @ tkt_mtime DATE,
 
91 @ -- Add as many fields as required below this line
92 @ login TEXT,
93 @ username TEXT,
94 @ mimetype TEXT,
95 @ icomment TEXT
96
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -86,10 +86,11 @@
86 @ CREATE TABLE ticketchng(
87 @ -- Do not change any column that begins with tkt_
88 @ tkt_id INTEGER REFERENCES ticket,
89 @ tkt_rid INTEGER REFERENCES blob,
90 @ tkt_mtime DATE,
91 @ tkt_user TEXT,
92 @ -- Add as many fields as required below this line
93 @ login TEXT,
94 @ username TEXT,
95 @ mimetype TEXT,
96 @ icomment TEXT
97
+12 -4
--- src/url.c
+++ src/url.c
@@ -63,11 +63,12 @@
6363
char *canonical; /* Canonical representation of the URL */
6464
char *proxyAuth; /* Proxy-Authorizer: string */
6565
char *fossil; /* The fossil query parameter on ssh: */
6666
unsigned flags; /* Boolean flags controlling URL processing */
6767
int useProxy; /* Used to remember that a proxy is in use */
68
- char *proxyUrlPath;
68
+ char *proxyUrlPath; /* Remember path when proxy is use */
69
+ char *proxyUrlCanonical; /* Remember canonical path when proxy is use */
6970
int proxyOrigPort; /* Tunneled port number for https through proxy */
7071
};
7172
#endif /* INTERFACE */
7273
7374
@@ -534,11 +535,11 @@
534535
void url_enable_proxy(const char *zMsg){
535536
const char *zProxy;
536537
zProxy = zProxyOpt;
537538
if( zProxy==0 ){
538539
zProxy = db_get("proxy", 0);
539
- if( zProxy==0 || zProxy[0]==0 || is_false(zProxy) ){
540
+ if( fossil_strcmp(zProxy, "system")==0 ){
540541
zProxy = fossil_getenv("http_proxy");
541542
}
542543
}
543544
if( zProxy && zProxy[0] && !is_false(zProxy)
544545
&& !g.url.isSsh && !g.url.isFile ){
@@ -564,10 +565,11 @@
564565
}
565566
g.url.user = zOriginalUser;
566567
g.url.passwd = zOriginalPasswd;
567568
g.url.isHttps = fOriginalIsHttps;
568569
g.url.useProxy = 1;
570
+ g.url.proxyUrlCanonical = zOriginalUrl;;
569571
g.url.proxyUrlPath = zOriginalUrlPath;
570572
g.url.proxyOrigPort = iOriginalPort;
571573
g.url.flags = uOriginalFlags;
572574
}
573575
}
@@ -722,14 +724,20 @@
722724
/*
723725
** Remember the URL and password if requested.
724726
*/
725727
void url_remember(void){
726728
if( g.url.flags & URL_REMEMBER ){
729
+ const char *url;
730
+ if( g.url.useProxy ){
731
+ url = g.url.proxyUrlCanonical;
732
+ }else{
733
+ url = g.url.canonical;
734
+ }
727735
if( g.url.flags & URL_USE_PARENT ){
728
- db_set("parent-project-url", g.url.canonical, 0);
736
+ db_set("parent-project-url", url, 0);
729737
}else{
730
- db_set("last-sync-url", g.url.canonical, 0);
738
+ db_set("last-sync-url", url, 0);
731739
}
732740
if( g.url.user!=0 && g.url.passwd!=0 && ( g.url.flags & URL_REMEMBER_PW ) ){
733741
if( g.url.flags & URL_USE_PARENT ){
734742
db_set("parent-project-pw", obscure(g.url.passwd), 0);
735743
}else{
736744
--- src/url.c
+++ src/url.c
@@ -63,11 +63,12 @@
63 char *canonical; /* Canonical representation of the URL */
64 char *proxyAuth; /* Proxy-Authorizer: string */
65 char *fossil; /* The fossil query parameter on ssh: */
66 unsigned flags; /* Boolean flags controlling URL processing */
67 int useProxy; /* Used to remember that a proxy is in use */
68 char *proxyUrlPath;
 
69 int proxyOrigPort; /* Tunneled port number for https through proxy */
70 };
71 #endif /* INTERFACE */
72
73
@@ -534,11 +535,11 @@
534 void url_enable_proxy(const char *zMsg){
535 const char *zProxy;
536 zProxy = zProxyOpt;
537 if( zProxy==0 ){
538 zProxy = db_get("proxy", 0);
539 if( zProxy==0 || zProxy[0]==0 || is_false(zProxy) ){
540 zProxy = fossil_getenv("http_proxy");
541 }
542 }
543 if( zProxy && zProxy[0] && !is_false(zProxy)
544 && !g.url.isSsh && !g.url.isFile ){
@@ -564,10 +565,11 @@
564 }
565 g.url.user = zOriginalUser;
566 g.url.passwd = zOriginalPasswd;
567 g.url.isHttps = fOriginalIsHttps;
568 g.url.useProxy = 1;
 
569 g.url.proxyUrlPath = zOriginalUrlPath;
570 g.url.proxyOrigPort = iOriginalPort;
571 g.url.flags = uOriginalFlags;
572 }
573 }
@@ -722,14 +724,20 @@
722 /*
723 ** Remember the URL and password if requested.
724 */
725 void url_remember(void){
726 if( g.url.flags & URL_REMEMBER ){
 
 
 
 
 
 
727 if( g.url.flags & URL_USE_PARENT ){
728 db_set("parent-project-url", g.url.canonical, 0);
729 }else{
730 db_set("last-sync-url", g.url.canonical, 0);
731 }
732 if( g.url.user!=0 && g.url.passwd!=0 && ( g.url.flags & URL_REMEMBER_PW ) ){
733 if( g.url.flags & URL_USE_PARENT ){
734 db_set("parent-project-pw", obscure(g.url.passwd), 0);
735 }else{
736
--- src/url.c
+++ src/url.c
@@ -63,11 +63,12 @@
63 char *canonical; /* Canonical representation of the URL */
64 char *proxyAuth; /* Proxy-Authorizer: string */
65 char *fossil; /* The fossil query parameter on ssh: */
66 unsigned flags; /* Boolean flags controlling URL processing */
67 int useProxy; /* Used to remember that a proxy is in use */
68 char *proxyUrlPath; /* Remember path when proxy is use */
69 char *proxyUrlCanonical; /* Remember canonical path when proxy is use */
70 int proxyOrigPort; /* Tunneled port number for https through proxy */
71 };
72 #endif /* INTERFACE */
73
74
@@ -534,11 +535,11 @@
535 void url_enable_proxy(const char *zMsg){
536 const char *zProxy;
537 zProxy = zProxyOpt;
538 if( zProxy==0 ){
539 zProxy = db_get("proxy", 0);
540 if( fossil_strcmp(zProxy, "system")==0 ){
541 zProxy = fossil_getenv("http_proxy");
542 }
543 }
544 if( zProxy && zProxy[0] && !is_false(zProxy)
545 && !g.url.isSsh && !g.url.isFile ){
@@ -564,10 +565,11 @@
565 }
566 g.url.user = zOriginalUser;
567 g.url.passwd = zOriginalPasswd;
568 g.url.isHttps = fOriginalIsHttps;
569 g.url.useProxy = 1;
570 g.url.proxyUrlCanonical = zOriginalUrl;;
571 g.url.proxyUrlPath = zOriginalUrlPath;
572 g.url.proxyOrigPort = iOriginalPort;
573 g.url.flags = uOriginalFlags;
574 }
575 }
@@ -722,14 +724,20 @@
724 /*
725 ** Remember the URL and password if requested.
726 */
727 void url_remember(void){
728 if( g.url.flags & URL_REMEMBER ){
729 const char *url;
730 if( g.url.useProxy ){
731 url = g.url.proxyUrlCanonical;
732 }else{
733 url = g.url.canonical;
734 }
735 if( g.url.flags & URL_USE_PARENT ){
736 db_set("parent-project-url", url, 0);
737 }else{
738 db_set("last-sync-url", url, 0);
739 }
740 if( g.url.user!=0 && g.url.passwd!=0 && ( g.url.flags & URL_REMEMBER_PW ) ){
741 if( g.url.flags & URL_USE_PARENT ){
742 db_set("parent-project-pw", obscure(g.url.passwd), 0);
743 }else{
744
+7
--- src/wiki.c
+++ src/wiki.c
@@ -1917,10 +1917,11 @@
19171917
void wcontent_page(void){
19181918
Stmt q;
19191919
double rNow;
19201920
int showAll = P("all")!=0;
19211921
int showRid = P("showid")!=0;
1922
+ int showCkBr = P("showckbr")!=0;
19221923
19231924
login_check_credentials();
19241925
if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
19251926
style_set_current_feature("wiki");
19261927
style_header("Available Wiki Pages");
@@ -1927,10 +1928,11 @@
19271928
if( showAll ){
19281929
style_submenu_element("Active", "%R/wcontent");
19291930
}else{
19301931
style_submenu_element("All", "%R/wcontent?all=1");
19311932
}
1933
+ style_submenu_checkbox("showckbr", "Show associated wikis", 0, 0);
19321934
wiki_standard_submenu(W_ALL_BUT(W_LIST));
19331935
db_prepare(&q, listAllWikiPages/*works-like:""*/);
19341936
@ <div class="brlist">
19351937
@ <table class='sortable' data-column-types='tKN' data-init-sort='1'>
19361938
@ <thead><tr>
@@ -1954,10 +1956,15 @@
19541956
19551957
if( sqlite3_strglob("checkin/*", zWName)==0 ){
19561958
zWDisplayName = mprintf("%.25s...", zWName);
19571959
}else{
19581960
zWDisplayName = mprintf("%s", zWName);
1961
+ }
1962
+ if( !showCkBr &&
1963
+ (sqlite3_strglob("checkin/*", zWName)==0 ||
1964
+ sqlite3_strglob("branch/*", zWName)==0) ){
1965
+ continue;
19591966
}
19601967
if( wrid==0 ){
19611968
if( !showAll ) continue;
19621969
@ <tr><td data-sortkey="%h(zSort)">\
19631970
@ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
19641971
--- src/wiki.c
+++ src/wiki.c
@@ -1917,10 +1917,11 @@
1917 void wcontent_page(void){
1918 Stmt q;
1919 double rNow;
1920 int showAll = P("all")!=0;
1921 int showRid = P("showid")!=0;
 
1922
1923 login_check_credentials();
1924 if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
1925 style_set_current_feature("wiki");
1926 style_header("Available Wiki Pages");
@@ -1927,10 +1928,11 @@
1927 if( showAll ){
1928 style_submenu_element("Active", "%R/wcontent");
1929 }else{
1930 style_submenu_element("All", "%R/wcontent?all=1");
1931 }
 
1932 wiki_standard_submenu(W_ALL_BUT(W_LIST));
1933 db_prepare(&q, listAllWikiPages/*works-like:""*/);
1934 @ <div class="brlist">
1935 @ <table class='sortable' data-column-types='tKN' data-init-sort='1'>
1936 @ <thead><tr>
@@ -1954,10 +1956,15 @@
1954
1955 if( sqlite3_strglob("checkin/*", zWName)==0 ){
1956 zWDisplayName = mprintf("%.25s...", zWName);
1957 }else{
1958 zWDisplayName = mprintf("%s", zWName);
 
 
 
 
 
1959 }
1960 if( wrid==0 ){
1961 if( !showAll ) continue;
1962 @ <tr><td data-sortkey="%h(zSort)">\
1963 @ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
1964
--- src/wiki.c
+++ src/wiki.c
@@ -1917,10 +1917,11 @@
1917 void wcontent_page(void){
1918 Stmt q;
1919 double rNow;
1920 int showAll = P("all")!=0;
1921 int showRid = P("showid")!=0;
1922 int showCkBr = P("showckbr")!=0;
1923
1924 login_check_credentials();
1925 if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
1926 style_set_current_feature("wiki");
1927 style_header("Available Wiki Pages");
@@ -1927,10 +1928,11 @@
1928 if( showAll ){
1929 style_submenu_element("Active", "%R/wcontent");
1930 }else{
1931 style_submenu_element("All", "%R/wcontent?all=1");
1932 }
1933 style_submenu_checkbox("showckbr", "Show associated wikis", 0, 0);
1934 wiki_standard_submenu(W_ALL_BUT(W_LIST));
1935 db_prepare(&q, listAllWikiPages/*works-like:""*/);
1936 @ <div class="brlist">
1937 @ <table class='sortable' data-column-types='tKN' data-init-sort='1'>
1938 @ <thead><tr>
@@ -1954,10 +1956,15 @@
1956
1957 if( sqlite3_strglob("checkin/*", zWName)==0 ){
1958 zWDisplayName = mprintf("%.25s...", zWName);
1959 }else{
1960 zWDisplayName = mprintf("%s", zWName);
1961 }
1962 if( !showCkBr &&
1963 (sqlite3_strglob("checkin/*", zWName)==0 ||
1964 sqlite3_strglob("branch/*", zWName)==0) ){
1965 continue;
1966 }
1967 if( wrid==0 ){
1968 if( !showAll ) continue;
1969 @ <tr><td data-sortkey="%h(zSort)">\
1970 @ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
1971

Keyboard Shortcuts

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